Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 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.Init.Order.Defs import Mathlib.Order.Monotone.Basic import Mathlib.Order.ULift import Mathlib.Tactic.GCongr.Core #align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # (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} #align le_antisymm' le_antisymm /-! ### 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 Sup α, PartialOrder α where /-- The supremum is an upper bound on the first argument -/ protected le_sup_left : ∀ a b : α, a ≤ a ⊔ b /-- The supremum is an upper bound on the second argument -/ protected le_sup_right : ∀ a b : α, b ≤ a ⊔ b /-- The supremum is the *least* upper bound -/ protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c #align semilattice_sup SemilatticeSup /-- 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*} [Sup α] (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 dsimp; rw [← hbc, ← sup_assoc, hab] le_antisymm a b hab hba := by rwa [← hba, sup_comm] le_sup_left a b := by dsimp; rw [← sup_assoc, sup_idem] le_sup_right a b := by dsimp; rw [sup_comm, sup_assoc, sup_idem] sup_le a b c hac hbc := by dsimp; rwa [sup_assoc, hbc] #align semilattice_sup.mk' SemilatticeSup.mk' instance OrderDual.instSup (α : Type*) [Inf α] : Sup αᵒᵈ := ⟨((· ⊓ ·) : α → α → α)⟩ instance OrderDual.instInf (α : Type*) [Sup α] : Inf αᵒᵈ := ⟨((· ⊔ ·) : α → α → α)⟩ section SemilatticeSup variable [SemilatticeSup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := SemilatticeSup.le_sup_left a b #align le_sup_left le_sup_left #align le_sup_left' le_sup_left @[deprecated (since := "2024-06-04")] alias le_sup_left' := le_sup_left @[simp] theorem le_sup_right : b ≤ a ⊔ b := SemilatticeSup.le_sup_right a b #align le_sup_right le_sup_right #align le_sup_right' le_sup_right @[deprecated (since := "2024-06-04")] alias le_sup_right' := le_sup_right theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left #align le_sup_of_le_left le_sup_of_le_left theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right #align le_sup_of_le_right le_sup_of_le_right theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b := h.trans_le le_sup_left #align lt_sup_of_lt_left lt_sup_of_lt_left theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b := h.trans_le le_sup_right #align lt_sup_of_lt_right lt_sup_of_lt_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := SemilatticeSup.sup_le a b c #align sup_le sup_le @[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₂⟩ #align sup_le_iff sup_le_iff @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans <| by simp [le_rfl] #align sup_eq_left sup_eq_left @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans <| by simp [le_rfl] #align sup_eq_right sup_eq_right @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left #align left_eq_sup left_eq_sup @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right #align right_eq_sup right_eq_sup alias ⟨_, sup_of_le_left⟩ := sup_eq_left #align sup_of_le_left sup_of_le_left alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right #align sup_of_le_right sup_of_le_right #align le_of_sup_eq le_of_sup_eq 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 #align left_lt_sup left_lt_sup @[simp] theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b := le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup #align right_lt_sup right_lt_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 #align left_or_right_lt_sup left_or_right_lt_sup 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 #align le_iff_exists_sup le_iff_exists_sup @[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₂) #align sup_le_sup sup_le_sup @[gcongr] theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup le_rfl h₁ #align sup_le_sup_left sup_le_sup_left @[gcongr] theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ le_rfl #align sup_le_sup_right sup_le_sup_right
Mathlib/Order/Lattice.lean
219
219
theorem sup_idem (a : α) : a ⊔ a = a := by
simp
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Localization.FractionRing #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots open Multiset Finset /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) #align polynomial.roots Polynomial.roots theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by -- porting noteL `‹_›` doesn't work for instance arguments rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl #align polynomial.roots_def Polynomial.roots_def @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl #align polynomial.roots_zero Polynomial.roots_zero theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 #align polynomial.card_roots Polynomial.card_roots theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by by_cases hp0 : p = 0 · simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) #align polynomial.card_roots' Polynomial.card_roots' theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p := calc (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C Polynomial.card_roots_sub_C theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≤ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C' Polynomial.card_roots_sub_C' @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 · simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a #align polynomial.count_roots Polynomial.count_roots @[simp] theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] #align polynomial.mem_roots' Polynomial.mem_roots' theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp #align polynomial.mem_roots Polynomial.mem_roots theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 := (mem_roots'.1 h).1 #align polynomial.ne_zero_of_mem_roots Polynomial.ne_zero_of_mem_roots theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 #align polynomial.is_root_of_mem_roots Polynomial.isRoot_of_mem_roots -- Porting note: added during port. lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by rw [mem_roots w, IsRoot.def, aeval_def, eval₂_eq_eval_map] simp theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) : Z.card ≤ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) #align polynomial.card_le_degree_of_subset_roots Polynomial.card_le_degree_of_subset_roots theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet #align polynomial.finite_set_of_is_root Polynomial.finite_setOf_isRoot theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h #align polynomial.eq_zero_of_infinite_is_root Polynomial.eq_zero_of_infinite_isRoot theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_max_root Polynomial.exists_max_root theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_min_root Polynomial.exists_min_root theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] #align polynomial.eq_of_infinite_eval_eq Polynomial.eq_of_infinite_eval_eq theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] #align polynomial.roots_mul Polynomial.roots_mul theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ #align polynomial.roots.le_of_dvd Polynomial.roots.le_of_dvd theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C' Polynomial.mem_roots_sub_C' theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C Polynomial.mem_roots_sub_C @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_sub_C Polynomial.roots_X_sub_C @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_X Polynomial.roots_X @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) set_option linter.uppercaseLean3 false in #align polynomial.roots_C Polynomial.roots_C @[simp] theorem roots_one : (1 : R[X]).roots = ∅ := roots_C 1 #align polynomial.roots_one Polynomial.roots_one @[simp] theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul Polynomial.roots_C_mul @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] #align polynomial.roots_smul_nonzero Polynomial.roots_smul_nonzero @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] #align polynomial.roots_list_prod Polynomial.roots_list_prod theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L #align polynomial.roots_multiset_prod Polynomial.roots_multiset_prod theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) : s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) #align polynomial.roots_prod Polynomial.roots_prod @[simp] theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by induction' n with n ihn · rw [pow_zero, roots_one, zero_smul, empty_eq_zero] · rcases eq_or_ne p 0 with (rfl | hp) · rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] · rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul] #align polynomial.roots_pow Polynomial.roots_pow theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by rw [roots_pow, roots_X] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_pow Polynomial.roots_X_pow theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) : Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by rw [roots_C_mul _ ha, roots_X_pow] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul_X_pow Polynomial.roots_C_mul_X_pow @[simp] theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha] #align polynomial.roots_monomial Polynomial.roots_monomial theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by apply (roots_prod (fun a => X - C a) s ?_).trans · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a) set_option linter.uppercaseLean3 false in #align polynomial.roots_prod_X_sub_C Polynomial.roots_prod_X_sub_C @[simp] theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by rw [roots_multiset_prod, Multiset.bind_map] · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · rw [Multiset.mem_map] rintro ⟨a, -, h⟩ exact X_sub_C_ne_zero a h set_option linter.uppercaseLean3 false in #align polynomial.roots_multiset_prod_X_sub_C Polynomial.roots_multiset_prod_X_sub_C theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) : Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n := WithBot.coe_le_coe.1 <| calc (Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) := card_roots (X_pow_sub_C_ne_zero hn a) _ = n := degree_X_pow_sub_C hn a set_option linter.uppercaseLean3 false in #align polynomial.card_roots_X_pow_sub_C Polynomial.card_roots_X_pow_sub_C section NthRoots /-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`-/ def nthRoots (n : ℕ) (a : R) : Multiset R := roots ((X : R[X]) ^ n - C a) #align polynomial.nth_roots Polynomial.nthRoots @[simp] theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero] #align polynomial.mem_nth_roots Polynomial.mem_nthRoots @[simp] theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C] #align polynomial.nth_roots_zero Polynomial.nthRoots_zero @[simp] theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) : nthRoots n (0 : R) = Multiset.replicate n 0 := by rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton] theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by classical exact (if hn : n = 0 then if h : (X : R[X]) ^ n - C a = 0 then by simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero] else WithBot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← RingHom.map_sub] exact degree_C_le)) else by rw [← Nat.cast_le (α := WithBot ℕ)] rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a] exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a)) #align polynomial.card_nth_roots Polynomial.card_nthRoots @[simp] theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2), ← not_exists, eq_comm] #align polynomial.nth_roots_two_eq_zero_iff Polynomial.nthRoots_two_eq_zero_iff /-- The multiset `nthRoots ↑n (1 : R)` as a Finset. -/ def nthRootsFinset (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : Finset R := haveI := Classical.decEq R Multiset.toFinset (nthRoots n (1 : R)) #align polynomial.nth_roots_finset Polynomial.nthRootsFinset -- Porting note (#10756): new lemma lemma nthRootsFinset_def (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] [DecidableEq R] : nthRootsFinset n R = Multiset.toFinset (nthRoots n (1 : R)) := by unfold nthRootsFinset convert rfl @[simp] theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) {x : R} : x ∈ nthRootsFinset n R ↔ x ^ (n : ℕ) = 1 := by classical rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h] #align polynomial.mem_nth_roots_finset Polynomial.mem_nthRootsFinset @[simp] theorem nthRootsFinset_zero : nthRootsFinset 0 R = ∅ := by classical simp [nthRootsFinset_def] #align polynomial.nth_roots_finset_zero Polynomial.nthRootsFinset_zero theorem mul_mem_nthRootsFinset {η₁ η₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n R) (hη₂ : η₂ ∈ nthRootsFinset n R) : η₁ * η₂ ∈ nthRootsFinset n R := by cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη₁ | succ n => rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢ rw [mul_pow, hη₁, hη₂, one_mul] theorem ne_zero_of_mem_nthRootsFinset {η : R} (hη : η ∈ nthRootsFinset n R) : η ≠ 0 := by nontriviality R rintro rfl cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη | succ n => rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη exact zero_ne_one hη theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n R := by rw [mem_nthRootsFinset hn, one_pow] end NthRoots theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by classical by_contra hp refine @Fintype.false R _ ?_ exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩ #align polynomial.zero_of_eval_zero Polynomial.zero_of_eval_zero theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by rw [← sub_eq_zero] apply zero_of_eval_zero intro x rw [eval_sub, sub_eq_zero, ext] #align polynomial.funext Polynomial.funext variable [CommRing T] /-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is the multiset of roots of `p` regarded as a polynomial over `S`. -/ noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S := (p.map (algebraMap T S)).roots theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : p.aroots S = (p.map (algebraMap T S)).roots := rfl theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def] theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by rw [mem_aroots', Polynomial.map_ne_zero_iff] exact NoZeroSMulDivisors.algebraMap_injective T S theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) : (p * q).aroots S = p.aroots S + q.aroots S := by suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by rw [aroots_def, Polynomial.map_mul, roots_mul this] rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff (NoZeroSMulDivisors.algebraMap_injective T S)] @[simp] theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S] (r : T) : aroots (X - C r) S = {algebraMap T S r} := by rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C] @[simp] theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] : aroots (X : T[X]) S = {0} := by rw [aroots_def, map_X, roots_X] @[simp] theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by rw [aroots_def, map_C, roots_C] @[simp] theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by rw [← C_0, aroots_C] @[simp] theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).aroots S = 0 := aroots_C 1 @[simp] theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) : (-p).aroots S = p.aroots S := by rw [aroots, Polynomial.map_neg, roots_neg] @[simp] theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) : (C a * p).aroots S = p.aroots S := by rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul] rwa [map_ne_zero_iff] exact NoZeroSMulDivisors.algebraMap_injective T S @[simp] theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) : (a • p).aroots S = p.aroots S := by rw [smul_eq_C_mul, aroots_C_mul _ ha] @[simp] theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : ℕ) : (p ^ n).aroots S = n • p.aroots S := by rw [aroots_def, Polynomial.map_pow, roots_pow] theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : ℕ) : (X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by rw [aroots_pow, aroots_X] theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) : (C a * X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by rw [aroots_C_mul _ ha, aroots_X_pow] @[simp] theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) : (monomial n a).aroots S = n • ({0} : Multiset S) := by rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha] /-- The set of distinct roots of `p` in `S`. If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset where multiple roots have the appropriate multiplicity. -/ def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S := haveI := Classical.decEq S (p.aroots S).toFinset #align polynomial.root_set Polynomial.rootSet theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] : p.rootSet S = (p.aroots S).toFinset := by rw [rootSet] convert rfl #align polynomial.root_set_def Polynomial.rootSet_def @[simp]
Mathlib/Algebra/Polynomial/Roots.lean
515
517
theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = ∅ := by
classical rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Free.Coherence import Mathlib.CategoryTheory.Monoidal.Discrete import Mathlib.CategoryTheory.Monoidal.NaturalTransformation import Mathlib.CategoryTheory.Monoidal.Opposite import Mathlib.Tactic.CategoryTheory.Coherence import Mathlib.CategoryTheory.CommSq #align_import category_theory.monoidal.braided from "leanprover-community/mathlib"@"2efd2423f8d25fa57cf7a179f5d8652ab4d0df44" /-! # Braided and symmetric monoidal categories The basic definitions of braided monoidal categories, and symmetric monoidal categories, as well as braided functors. ## Implementation note We make `BraidedCategory` another typeclass, but then have `SymmetricCategory` extend this. The rationale is that we are not carrying any additional data, just requiring a property. ## Future work * Construct the Drinfeld center of a monoidal category as a braided monoidal category. * Say something about pseudo-natural transformations. ## References * [Pavel Etingof, Shlomo Gelaki, Dmitri Nikshych, Victor Ostrik, *Tensor categories*][egno15] -/ open CategoryTheory MonoidalCategory universe v v₁ v₂ v₃ u u₁ u₂ u₃ namespace CategoryTheory /-- A braided monoidal category is a monoidal category equipped with a braiding isomorphism `β_ X Y : X ⊗ Y ≅ Y ⊗ X` which is natural in both arguments, and also satisfies the two hexagon identities. -/ class BraidedCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] where /-- The braiding natural isomorphism. -/ braiding : ∀ X Y : C, X ⊗ Y ≅ Y ⊗ X braiding_naturality_right : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), X ◁ f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ f ▷ X := by aesop_cat braiding_naturality_left : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ▷ Z ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ Z ◁ f := by aesop_cat /-- The first hexagon identity. -/ hexagon_forward : ∀ X Y Z : C, (α_ X Y Z).hom ≫ (braiding X (Y ⊗ Z)).hom ≫ (α_ Y Z X).hom = ((braiding X Y).hom ▷ Z) ≫ (α_ Y X Z).hom ≫ (Y ◁ (braiding X Z).hom) := by aesop_cat /-- The second hexagon identity. -/ hexagon_reverse : ∀ X Y Z : C, (α_ X Y Z).inv ≫ (braiding (X ⊗ Y) Z).hom ≫ (α_ Z X Y).inv = (X ◁ (braiding Y Z).hom) ≫ (α_ X Z Y).inv ≫ ((braiding X Z).hom ▷ Y) := by aesop_cat #align category_theory.braided_category CategoryTheory.BraidedCategory attribute [reassoc (attr := simp)] BraidedCategory.braiding_naturality_left BraidedCategory.braiding_naturality_right attribute [reassoc] BraidedCategory.hexagon_forward BraidedCategory.hexagon_reverse open Category open MonoidalCategory open BraidedCategory @[inherit_doc] notation "β_" => BraidedCategory.braiding namespace BraidedCategory variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] [BraidedCategory.{v} C] @[simp, reassoc] theorem braiding_tensor_left (X Y Z : C) : (β_ (X ⊗ Y) Z).hom = (α_ X Y Z).hom ≫ X ◁ (β_ Y Z).hom ≫ (α_ X Z Y).inv ≫ (β_ X Z).hom ▷ Y ≫ (α_ Z X Y).hom := by apply (cancel_epi (α_ X Y Z).inv).1 apply (cancel_mono (α_ Z X Y).inv).1 simp [hexagon_reverse] @[simp, reassoc] theorem braiding_tensor_right (X Y Z : C) : (β_ X (Y ⊗ Z)).hom = (α_ X Y Z).inv ≫ (β_ X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫ Y ◁ (β_ X Z).hom ≫ (α_ Y Z X).inv := by apply (cancel_epi (α_ X Y Z).hom).1 apply (cancel_mono (α_ Y Z X).hom).1 simp [hexagon_forward] @[simp, reassoc] theorem braiding_inv_tensor_left (X Y Z : C) : (β_ (X ⊗ Y) Z).inv = (α_ Z X Y).inv ≫ (β_ X Z).inv ▷ Y ≫ (α_ X Z Y).hom ≫ X ◁ (β_ Y Z).inv ≫ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[simp, reassoc] theorem braiding_inv_tensor_right (X Y Z : C) : (β_ X (Y ⊗ Z)).inv = (α_ Y Z X).hom ≫ Y ◁ (β_ X Z).inv ≫ (α_ Y X Z).inv ≫ (β_ X Y).inv ▷ Z ≫ (α_ X Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem braiding_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (f ⊗ g) ≫ (braiding Y Y').hom = (braiding X X').hom ≫ (g ⊗ f) := by rw [tensorHom_def' f g, tensorHom_def g f] simp_rw [Category.assoc, braiding_naturality_left, braiding_naturality_right_assoc] @[reassoc (attr := simp)] theorem braiding_inv_naturality_right (X : C) {Y Z : C} (f : Y ⟶ Z) : X ◁ f ≫ (β_ Z X).inv = (β_ Y X).inv ≫ f ▷ X := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_left f X @[reassoc (attr := simp)] theorem braiding_inv_naturality_left {X Y : C} (f : X ⟶ Y) (Z : C) : f ▷ Z ≫ (β_ Z Y).inv = (β_ Z X).inv ≫ Z ◁ f := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_right Z f @[reassoc (attr := simp)] theorem braiding_inv_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (f ⊗ g) ≫ (β_ Y' Y).inv = (β_ X' X).inv ≫ (g ⊗ f) := CommSq.w <| .vert_inv <| .mk <| braiding_naturality g f @[reassoc] theorem yang_baxter (X Y Z : C) : (α_ X Y Z).inv ≫ (β_ X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫ Y ◁ (β_ X Z).hom ≫ (α_ Y Z X).inv ≫ (β_ Y Z).hom ▷ X ≫ (α_ Z Y X).hom = X ◁ (β_ Y Z).hom ≫ (α_ X Z Y).inv ≫ (β_ X Z).hom ▷ Y ≫ (α_ Z X Y).hom ≫ Z ◁ (β_ X Y).hom := by rw [← braiding_tensor_right_assoc X Y Z, ← cancel_mono (α_ Z Y X).inv] repeat rw [assoc] rw [Iso.hom_inv_id, comp_id, ← braiding_naturality_right, braiding_tensor_right] theorem yang_baxter' (X Y Z : C) : (β_ X Y).hom ▷ Z ⊗≫ Y ◁ (β_ X Z).hom ⊗≫ (β_ Y Z).hom ▷ X = 𝟙 _ ⊗≫ (X ◁ (β_ Y Z).hom ⊗≫ (β_ X Z).hom ▷ Y ⊗≫ Z ◁ (β_ X Y).hom) ⊗≫ 𝟙 _ := by rw [← cancel_epi (α_ X Y Z).inv, ← cancel_mono (α_ Z Y X).hom] convert yang_baxter X Y Z using 1 all_goals coherence theorem yang_baxter_iso (X Y Z : C) : (α_ X Y Z).symm ≪≫ whiskerRightIso (β_ X Y) Z ≪≫ α_ Y X Z ≪≫ whiskerLeftIso Y (β_ X Z) ≪≫ (α_ Y Z X).symm ≪≫ whiskerRightIso (β_ Y Z) X ≪≫ (α_ Z Y X) = whiskerLeftIso X (β_ Y Z) ≪≫ (α_ X Z Y).symm ≪≫ whiskerRightIso (β_ X Z) Y ≪≫ α_ Z X Y ≪≫ whiskerLeftIso Z (β_ X Y) := Iso.ext (yang_baxter X Y Z) theorem hexagon_forward_iso (X Y Z : C) : α_ X Y Z ≪≫ β_ X (Y ⊗ Z) ≪≫ α_ Y Z X = whiskerRightIso (β_ X Y) Z ≪≫ α_ Y X Z ≪≫ whiskerLeftIso Y (β_ X Z) := Iso.ext (hexagon_forward X Y Z) theorem hexagon_reverse_iso (X Y Z : C) : (α_ X Y Z).symm ≪≫ β_ (X ⊗ Y) Z ≪≫ (α_ Z X Y).symm = whiskerLeftIso X (β_ Y Z) ≪≫ (α_ X Z Y).symm ≪≫ whiskerRightIso (β_ X Z) Y := Iso.ext (hexagon_reverse X Y Z) @[reassoc]
Mathlib/CategoryTheory/Monoidal/Braided/Basic.lean
181
184
theorem hexagon_forward_inv (X Y Z : C) : (α_ Y Z X).inv ≫ (β_ X (Y ⊗ Z)).inv ≫ (α_ X Y Z).inv = Y ◁ (β_ X Z).inv ≫ (α_ Y X Z).inv ≫ (β_ X Y).inv ▷ Z := by
simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Operations #align_import data.real.ennreal from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Results about division in extended non-negative reals This file establishes basic properties related to the inversion and division operations on `ℝ≥0∞`. For instance, as a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer exponent. ## Main results A few order isomorphisms are worthy of mention: - `OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ`: The map `x ↦ x⁻¹` as an order isomorphism to the dual. - `orderIsoIicOneBirational : ℝ≥0∞ ≃o Iic (1 : ℝ≥0∞)`: The birational order isomorphism between `ℝ≥0∞` and the unit interval `Set.Iic (1 : ℝ≥0∞)` given by `x ↦ (x⁻¹ + 1)⁻¹` with inverse `x ↦ (x⁻¹ - 1)⁻¹` - `orderIsoIicCoe (a : ℝ≥0) : Iic (a : ℝ≥0∞) ≃o Iic a`: Order isomorphism between an initial interval in `ℝ≥0∞` and an initial interval in `ℝ≥0` given by the identity map. - `orderIsoUnitIntervalBirational : ℝ≥0∞ ≃o Icc (0 : ℝ) 1`: An order isomorphism between the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational` composed with the identity order isomorphism between `Iic (1 : ℝ≥0∞)` and `Icc (0 : ℝ) 1`. -/ open Set NNReal namespace ENNReal noncomputable section Inv variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} protected theorem div_eq_inv_mul : a / b = b⁻¹ * a := by rw [div_eq_mul_inv, mul_comm] #align ennreal.div_eq_inv_mul ENNReal.div_eq_inv_mul @[simp] theorem inv_zero : (0 : ℝ≥0∞)⁻¹ = ∞ := show sInf { b : ℝ≥0∞ | 1 ≤ 0 * b } = ∞ by simp #align ennreal.inv_zero ENNReal.inv_zero @[simp] theorem inv_top : ∞⁻¹ = 0 := bot_unique <| le_of_forall_le_of_dense fun a (h : 0 < a) => sInf_le <| by simp [*, h.ne', top_mul] #align ennreal.inv_top ENNReal.inv_top theorem coe_inv_le : (↑r⁻¹ : ℝ≥0∞) ≤ (↑r)⁻¹ := le_sInf fun b (hb : 1 ≤ ↑r * b) => coe_le_iff.2 <| by rintro b rfl apply NNReal.inv_le_of_le_mul rwa [← coe_mul, ← coe_one, coe_le_coe] at hb #align ennreal.coe_inv_le ENNReal.coe_inv_le @[simp, norm_cast] theorem coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ℝ≥0∞) = (↑r)⁻¹ := coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [← coe_mul, mul_inv_cancel hr, coe_one] #align ennreal.coe_inv ENNReal.coe_inv @[norm_cast] theorem coe_inv_two : ((2⁻¹ : ℝ≥0) : ℝ≥0∞) = 2⁻¹ := by rw [coe_inv _root_.two_ne_zero, coe_two] #align ennreal.coe_inv_two ENNReal.coe_inv_two @[simp, norm_cast] theorem coe_div (hr : r ≠ 0) : (↑(p / r) : ℝ≥0∞) = p / r := by rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr] #align ennreal.coe_div ENNReal.coe_div lemma coe_div_le : ↑(p / r) ≤ (p / r : ℝ≥0∞) := by simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _ theorem div_zero (h : a ≠ 0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h] #align ennreal.div_zero ENNReal.div_zero instance : DivInvOneMonoid ℝ≥0∞ := { inferInstanceAs (DivInvMonoid ℝ≥0∞) with inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one } protected theorem inv_pow : ∀ {a : ℝ≥0∞} {n : ℕ}, (a ^ n)⁻¹ = a⁻¹ ^ n | _, 0 => by simp only [pow_zero, inv_one] | ⊤, n + 1 => by simp [top_pow] | (a : ℝ≥0), n + 1 => by rcases eq_or_ne a 0 with (rfl | ha) · simp [top_pow] · have := pow_ne_zero (n + 1) ha norm_cast rw [inv_pow] #align ennreal.inv_pow ENNReal.inv_pow protected theorem mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a * a⁻¹ = 1 := by lift a to ℝ≥0 using ht norm_cast at h0; norm_cast exact mul_inv_cancel h0 #align ennreal.mul_inv_cancel ENNReal.mul_inv_cancel protected theorem inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 := mul_comm a a⁻¹ ▸ ENNReal.mul_inv_cancel h0 ht #align ennreal.inv_mul_cancel ENNReal.inv_mul_cancel protected theorem div_mul_cancel (h0 : a ≠ 0) (hI : a ≠ ∞) : b / a * a = b := by rw [div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel h0 hI, mul_one] #align ennreal.div_mul_cancel ENNReal.div_mul_cancel protected theorem mul_div_cancel' (h0 : a ≠ 0) (hI : a ≠ ∞) : a * (b / a) = b := by rw [mul_comm, ENNReal.div_mul_cancel h0 hI] #align ennreal.mul_div_cancel' ENNReal.mul_div_cancel' -- Porting note: `simp only [div_eq_mul_inv, mul_comm, mul_assoc]` doesn't work in the following two protected theorem mul_comm_div : a / b * c = a * (c / b) := by simp only [div_eq_mul_inv, mul_right_comm, ← mul_assoc] #align ennreal.mul_comm_div ENNReal.mul_comm_div protected theorem mul_div_right_comm : a * b / c = a / c * b := by simp only [div_eq_mul_inv, mul_right_comm] #align ennreal.mul_div_right_comm ENNReal.mul_div_right_comm instance : InvolutiveInv ℝ≥0∞ where inv_inv a := by by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] @[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one] @[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_inj #align ennreal.inv_eq_top ENNReal.inv_eq_top theorem inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp #align ennreal.inv_ne_top ENNReal.inv_ne_top @[simp] theorem inv_lt_top {x : ℝ≥0∞} : x⁻¹ < ∞ ↔ 0 < x := by simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero] #align ennreal.inv_lt_top ENNReal.inv_lt_top theorem div_lt_top {x y : ℝ≥0∞} (h1 : x ≠ ∞) (h2 : y ≠ 0) : x / y < ∞ := mul_lt_top h1 (inv_ne_top.mpr h2) #align ennreal.div_lt_top ENNReal.div_lt_top @[simp] protected theorem inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ := inv_top ▸ inv_inj #align ennreal.inv_eq_zero ENNReal.inv_eq_zero protected theorem inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp #align ennreal.inv_ne_zero ENNReal.inv_ne_zero protected theorem div_pos (ha : a ≠ 0) (hb : b ≠ ∞) : 0 < a / b := ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb #align ennreal.div_pos ENNReal.div_pos protected theorem mul_inv {a b : ℝ≥0∞} (ha : a ≠ 0 ∨ b ≠ ∞) (hb : a ≠ ∞ ∨ b ≠ 0) : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by induction' b with b · replace ha : a ≠ 0 := ha.neg_resolve_right rfl simp [ha] induction' a with a · replace hb : b ≠ 0 := coe_ne_zero.1 (hb.neg_resolve_left rfl) simp [hb] by_cases h'a : a = 0 · simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne, not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero] by_cases h'b : b = 0 · simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff, mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero] rw [← ENNReal.coe_mul, ← ENNReal.coe_inv, ← ENNReal.coe_inv h'a, ← ENNReal.coe_inv h'b, ← ENNReal.coe_mul, mul_inv_rev, mul_comm] simp [h'a, h'b] #align ennreal.mul_inv ENNReal.mul_inv protected theorem mul_div_mul_left (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) : c * a / (c * b) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', one_mul] #align ennreal.mul_div_mul_left ENNReal.mul_div_mul_left protected theorem mul_div_mul_right (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) : a * c / (b * c) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', mul_one] #align ennreal.mul_div_mul_right ENNReal.mul_div_mul_right protected theorem sub_div (h : 0 < b → b < a → c ≠ 0) : (a - b) / c = a / c - b / c := by simp_rw [div_eq_mul_inv] exact ENNReal.sub_mul (by simpa using h) #align ennreal.sub_div ENNReal.sub_div @[simp] protected theorem inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ := pos_iff_ne_zero.trans ENNReal.inv_ne_zero #align ennreal.inv_pos ENNReal.inv_pos theorem inv_strictAnti : StrictAnti (Inv.inv : ℝ≥0∞ → ℝ≥0∞) := by intro a b h lift a to ℝ≥0 using h.ne_top induction b; · simp rw [coe_lt_coe] at h rcases eq_or_ne a 0 with (rfl | ha); · simp [h] rw [← coe_inv h.ne_bot, ← coe_inv ha, coe_lt_coe] exact NNReal.inv_lt_inv ha h #align ennreal.inv_strict_anti ENNReal.inv_strictAnti @[simp] protected theorem inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a := inv_strictAnti.lt_iff_lt #align ennreal.inv_lt_inv ENNReal.inv_lt_inv theorem inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a b⁻¹ #align ennreal.inv_lt_iff_inv_lt ENNReal.inv_lt_iff_inv_lt theorem lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a⁻¹ b #align ennreal.lt_inv_iff_lt_inv ENNReal.lt_inv_iff_lt_inv @[simp] protected theorem inv_le_inv : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := inv_strictAnti.le_iff_le #align ennreal.inv_le_inv ENNReal.inv_le_inv theorem inv_le_iff_inv_le : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by simpa only [inv_inv] using @ENNReal.inv_le_inv a b⁻¹ #align ennreal.inv_le_iff_inv_le ENNReal.inv_le_iff_inv_le theorem le_inv_iff_le_inv : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_le_inv a⁻¹ b #align ennreal.le_inv_iff_le_inv ENNReal.le_inv_iff_le_inv @[gcongr] protected theorem inv_le_inv' (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := ENNReal.inv_strictAnti.antitone h @[gcongr] protected theorem inv_lt_inv' (h : a < b) : b⁻¹ < a⁻¹ := ENNReal.inv_strictAnti h @[simp] protected theorem inv_le_one : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [inv_le_iff_inv_le, inv_one] #align ennreal.inv_le_one ENNReal.inv_le_one protected theorem one_le_inv : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [le_inv_iff_le_inv, inv_one] #align ennreal.one_le_inv ENNReal.one_le_inv @[simp] protected theorem inv_lt_one : a⁻¹ < 1 ↔ 1 < a := by rw [inv_lt_iff_inv_lt, inv_one] #align ennreal.inv_lt_one ENNReal.inv_lt_one @[simp] protected theorem one_lt_inv : 1 < a⁻¹ ↔ a < 1 := by rw [lt_inv_iff_lt_inv, inv_one] #align ennreal.one_lt_inv ENNReal.one_lt_inv /-- The inverse map `fun x ↦ x⁻¹` is an order isomorphism between `ℝ≥0∞` and its `OrderDual` -/ @[simps! apply] def _root_.OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ where map_rel_iff' := ENNReal.inv_le_inv toEquiv := (Equiv.inv ℝ≥0∞).trans OrderDual.toDual #align order_iso.inv_ennreal OrderIso.invENNReal #align order_iso.inv_ennreal_apply OrderIso.invENNReal_apply @[simp] theorem _root_.OrderIso.invENNReal_symm_apply (a : ℝ≥0∞ᵒᵈ) : OrderIso.invENNReal.symm a = (OrderDual.ofDual a)⁻¹ := rfl #align order_iso.inv_ennreal_symm_apply OrderIso.invENNReal_symm_apply @[simp] theorem div_top : a / ∞ = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero] #align ennreal.div_top ENNReal.div_top -- Porting note: reordered 4 lemmas theorem top_div : ∞ / a = if a = ∞ then 0 else ∞ := by simp [div_eq_mul_inv, top_mul'] #align ennreal.top_div ENNReal.top_div theorem top_div_of_ne_top (h : a ≠ ∞) : ∞ / a = ∞ := by simp [top_div, h] #align ennreal.top_div_of_ne_top ENNReal.top_div_of_ne_top @[simp] theorem top_div_coe : ∞ / p = ∞ := top_div_of_ne_top coe_ne_top #align ennreal.top_div_coe ENNReal.top_div_coe theorem top_div_of_lt_top (h : a < ∞) : ∞ / a = ∞ := top_div_of_ne_top h.ne #align ennreal.top_div_of_lt_top ENNReal.top_div_of_lt_top @[simp] protected theorem zero_div : 0 / a = 0 := zero_mul a⁻¹ #align ennreal.zero_div ENNReal.zero_div theorem div_eq_top : a / b = ∞ ↔ a ≠ 0 ∧ b = 0 ∨ a = ∞ ∧ b ≠ ∞ := by simp [div_eq_mul_inv, ENNReal.mul_eq_top] #align ennreal.div_eq_top ENNReal.div_eq_top protected theorem le_div_iff_mul_le (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) : a ≤ c / b ↔ a * b ≤ c := by induction' b with b · lift c to ℝ≥0 using ht.neg_resolve_left rfl rw [div_top, nonpos_iff_eq_zero] rcases eq_or_ne a 0 with (rfl | ha) <;> simp [*] rcases eq_or_ne b 0 with (rfl | hb) · have hc : c ≠ 0 := h0.neg_resolve_left rfl simp [div_zero hc] · rw [← coe_ne_zero] at hb rw [← ENNReal.mul_le_mul_right hb coe_ne_top, ENNReal.div_mul_cancel hb coe_ne_top] #align ennreal.le_div_iff_mul_le ENNReal.le_div_iff_mul_le protected theorem div_le_iff_le_mul (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) : a / b ≤ c ↔ a ≤ c * b := by suffices a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹ by simpa [div_eq_mul_inv] refine (ENNReal.le_div_iff_mul_le ?_ ?_).symm <;> simpa #align ennreal.div_le_iff_le_mul ENNReal.div_le_iff_le_mul protected theorem lt_div_iff_mul_lt (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) : c < a / b ↔ c * b < a := lt_iff_lt_of_le_iff_le (ENNReal.div_le_iff_le_mul hb0 hbt) #align ennreal.lt_div_iff_mul_lt ENNReal.lt_div_iff_mul_lt theorem div_le_of_le_mul (h : a ≤ b * c) : a / c ≤ b := by by_cases h0 : c = 0 · have : a = 0 := by simpa [h0] using h simp [*] by_cases hinf : c = ∞; · simp [hinf] exact (ENNReal.div_le_iff_le_mul (Or.inl h0) (Or.inl hinf)).2 h #align ennreal.div_le_of_le_mul ENNReal.div_le_of_le_mul theorem div_le_of_le_mul' (h : a ≤ b * c) : a / b ≤ c := div_le_of_le_mul <| mul_comm b c ▸ h #align ennreal.div_le_of_le_mul' ENNReal.div_le_of_le_mul' protected theorem div_self_le_one : a / a ≤ 1 := div_le_of_le_mul <| by rw [one_mul] theorem mul_le_of_le_div (h : a ≤ b / c) : a * c ≤ b := by rw [← inv_inv c] exact div_le_of_le_mul h #align ennreal.mul_le_of_le_div ENNReal.mul_le_of_le_div theorem mul_le_of_le_div' (h : a ≤ b / c) : c * a ≤ b := mul_comm a c ▸ mul_le_of_le_div h #align ennreal.mul_le_of_le_div' ENNReal.mul_le_of_le_div' protected theorem div_lt_iff (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) : c / b < a ↔ c < a * b := lt_iff_lt_of_le_iff_le <| ENNReal.le_div_iff_mul_le h0 ht #align ennreal.div_lt_iff ENNReal.div_lt_iff theorem mul_lt_of_lt_div (h : a < b / c) : a * c < b := by contrapose! h exact ENNReal.div_le_of_le_mul h #align ennreal.mul_lt_of_lt_div ENNReal.mul_lt_of_lt_div theorem mul_lt_of_lt_div' (h : a < b / c) : c * a < b := mul_comm a c ▸ mul_lt_of_lt_div h #align ennreal.mul_lt_of_lt_div' ENNReal.mul_lt_of_lt_div' theorem div_lt_of_lt_mul (h : a < b * c) : a / c < b := mul_lt_of_lt_div <| by rwa [div_eq_mul_inv, inv_inv] theorem div_lt_of_lt_mul' (h : a < b * c) : a / b < c := div_lt_of_lt_mul <| by rwa [mul_comm] theorem inv_le_iff_le_mul (h₁ : b = ∞ → a ≠ 0) (h₂ : a = ∞ → b ≠ 0) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by rw [← one_div, ENNReal.div_le_iff_le_mul, mul_comm] exacts [or_not_of_imp h₁, not_or_of_imp h₂] #align ennreal.inv_le_iff_le_mul ENNReal.inv_le_iff_le_mul @[simp 900] theorem le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 := by rw [← one_div, ENNReal.le_div_iff_mul_le] <;> · right simp #align ennreal.le_inv_iff_mul_le ENNReal.le_inv_iff_mul_le @[gcongr] protected theorem div_le_div (hab : a ≤ b) (hdc : d ≤ c) : a / c ≤ b / d := div_eq_mul_inv b d ▸ div_eq_mul_inv a c ▸ mul_le_mul' hab (ENNReal.inv_le_inv.mpr hdc) #align ennreal.div_le_div ENNReal.div_le_div @[gcongr] protected theorem div_le_div_left (h : a ≤ b) (c : ℝ≥0∞) : c / b ≤ c / a := ENNReal.div_le_div le_rfl h #align ennreal.div_le_div_left ENNReal.div_le_div_left @[gcongr] protected theorem div_le_div_right (h : a ≤ b) (c : ℝ≥0∞) : a / c ≤ b / c := ENNReal.div_le_div h le_rfl #align ennreal.div_le_div_right ENNReal.div_le_div_right protected theorem eq_inv_of_mul_eq_one_left (h : a * b = 1) : a = b⁻¹ := by rw [← mul_one a, ← ENNReal.mul_inv_cancel (right_ne_zero_of_mul_eq_one h), ← mul_assoc, h, one_mul] rintro rfl simp [left_ne_zero_of_mul_eq_one h] at h #align ennreal.eq_inv_of_mul_eq_one_left ENNReal.eq_inv_of_mul_eq_one_left theorem mul_le_iff_le_inv {a b r : ℝ≥0∞} (hr₀ : r ≠ 0) (hr₁ : r ≠ ∞) : r * a ≤ b ↔ a ≤ r⁻¹ * b := by rw [← @ENNReal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, ENNReal.mul_inv_cancel hr₀ hr₁, one_mul] #align ennreal.mul_le_iff_le_inv ENNReal.mul_le_iff_le_inv instance : PosSMulStrictMono ℝ≥0 ℝ≥0∞ where elim _r hr _a _b hab := ENNReal.mul_lt_mul_left' (coe_pos.2 hr).ne' coe_ne_top hab instance : SMulPosMono ℝ≥0 ℝ≥0∞ where elim _r _ _a _b hab := mul_le_mul_right' (coe_le_coe.2 hab) _ #align ennreal.le_inv_smul_iff_of_pos le_inv_smul_iff_of_pos #align ennreal.inv_smul_le_iff_of_pos inv_smul_le_iff_of_pos theorem le_of_forall_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r < x → ↑r ≤ y) : x ≤ y := by refine le_of_forall_ge_of_dense fun r hr => ?_ lift r to ℝ≥0 using ne_top_of_lt hr exact h r hr #align ennreal.le_of_forall_nnreal_lt ENNReal.le_of_forall_nnreal_lt theorem le_of_forall_pos_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, 0 < r → ↑r < x → ↑r ≤ y) : x ≤ y := le_of_forall_nnreal_lt fun r hr => (zero_le r).eq_or_lt.elim (fun h => h ▸ zero_le _) fun h0 => h r h0 hr #align ennreal.le_of_forall_pos_nnreal_lt ENNReal.le_of_forall_pos_nnreal_lt theorem eq_top_of_forall_nnreal_le {x : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r ≤ x) : x = ∞ := top_unique <| le_of_forall_nnreal_lt fun r _ => h r #align ennreal.eq_top_of_forall_nnreal_le ENNReal.eq_top_of_forall_nnreal_le protected theorem add_div : (a + b) / c = a / c + b / c := right_distrib a b c⁻¹ #align ennreal.add_div ENNReal.add_div protected theorem div_add_div_same {a b c : ℝ≥0∞} : a / c + b / c = (a + b) / c := ENNReal.add_div.symm #align ennreal.div_add_div_same ENNReal.div_add_div_same protected theorem div_self (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 := ENNReal.mul_inv_cancel h0 hI #align ennreal.div_self ENNReal.div_self theorem mul_div_le : a * (b / a) ≤ b := mul_le_of_le_div' le_rfl #align ennreal.mul_div_le ENNReal.mul_div_le theorem eq_div_iff (ha : a ≠ 0) (ha' : a ≠ ∞) : b = c / a ↔ a * b = c := ⟨fun h => by rw [h, ENNReal.mul_div_cancel' ha ha'], fun h => by rw [← h, mul_div_assoc, ENNReal.mul_div_cancel' ha ha']⟩ #align ennreal.eq_div_iff ENNReal.eq_div_iff protected theorem div_eq_div_iff (ha : a ≠ 0) (ha' : a ≠ ∞) (hb : b ≠ 0) (hb' : b ≠ ∞) : c / b = d / a ↔ a * c = b * d := by rw [eq_div_iff ha ha'] conv_rhs => rw [eq_comm] rw [← eq_div_iff hb hb', mul_div_assoc, eq_comm] #align ennreal.div_eq_div_iff ENNReal.div_eq_div_iff theorem div_eq_one_iff {a b : ℝ≥0∞} (hb₀ : b ≠ 0) (hb₁ : b ≠ ∞) : a / b = 1 ↔ a = b := ⟨fun h => by rw [← (eq_div_iff hb₀ hb₁).mp h.symm, mul_one], fun h => h.symm ▸ ENNReal.div_self hb₀ hb₁⟩ #align ennreal.div_eq_one_iff ENNReal.div_eq_one_iff theorem inv_two_add_inv_two : (2 : ℝ≥0∞)⁻¹ + 2⁻¹ = 1 := by rw [← two_mul, ← div_eq_mul_inv, ENNReal.div_self two_ne_zero two_ne_top] #align ennreal.inv_two_add_inv_two ENNReal.inv_two_add_inv_two theorem inv_three_add_inv_three : (3 : ℝ≥0∞)⁻¹ + 3⁻¹ + 3⁻¹ = 1 := calc (3 : ℝ≥0∞)⁻¹ + 3⁻¹ + 3⁻¹ = 3 * 3⁻¹ := by ring _ = 1 := ENNReal.mul_inv_cancel (Nat.cast_ne_zero.2 <| by decide) coe_ne_top #align ennreal.inv_three_add_inv_three ENNReal.inv_three_add_inv_three @[simp] protected theorem add_halves (a : ℝ≥0∞) : a / 2 + a / 2 = a := by rw [div_eq_mul_inv, ← mul_add, inv_two_add_inv_two, mul_one] #align ennreal.add_halves ENNReal.add_halves @[simp] theorem add_thirds (a : ℝ≥0∞) : a / 3 + a / 3 + a / 3 = a := by rw [div_eq_mul_inv, ← mul_add, ← mul_add, inv_three_add_inv_three, mul_one] #align ennreal.add_thirds ENNReal.add_thirds @[simp] theorem div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = ∞ := by simp [div_eq_mul_inv] #align ennreal.div_zero_iff ENNReal.div_eq_zero_iff @[simp] theorem div_pos_iff : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ∞ := by simp [pos_iff_ne_zero, not_or] #align ennreal.div_pos_iff ENNReal.div_pos_iff protected theorem half_pos (h : a ≠ 0) : 0 < a / 2 := by simp only [div_pos_iff, ne_eq, h, not_false_eq_true, two_ne_top, and_self] #align ennreal.half_pos ENNReal.half_pos protected theorem one_half_lt_one : (2⁻¹ : ℝ≥0∞) < 1 := ENNReal.inv_lt_one.2 <| one_lt_two #align ennreal.one_half_lt_one ENNReal.one_half_lt_one protected theorem half_lt_self (hz : a ≠ 0) (ht : a ≠ ∞) : a / 2 < a := by lift a to ℝ≥0 using ht rw [coe_ne_zero] at hz rw [← coe_two, ← coe_div, coe_lt_coe] exacts [NNReal.half_lt_self hz, two_ne_zero' _] #align ennreal.half_lt_self ENNReal.half_lt_self protected theorem half_le_self : a / 2 ≤ a := le_add_self.trans_eq <| ENNReal.add_halves _ #align ennreal.half_le_self ENNReal.half_le_self theorem sub_half (h : a ≠ ∞) : a - a / 2 = a / 2 := by lift a to ℝ≥0 using h exact sub_eq_of_add_eq (mul_ne_top coe_ne_top <| by simp) (ENNReal.add_halves a) #align ennreal.sub_half ENNReal.sub_half @[simp] theorem one_sub_inv_two : (1 : ℝ≥0∞) - 2⁻¹ = 2⁻¹ := by simpa only [div_eq_mul_inv, one_mul] using sub_half one_ne_top #align ennreal.one_sub_inv_two ENNReal.one_sub_inv_two /-- The birational order isomorphism between `ℝ≥0∞` and the unit interval `Set.Iic (1 : ℝ≥0∞)`. -/ @[simps! apply_coe] def orderIsoIicOneBirational : ℝ≥0∞ ≃o Iic (1 : ℝ≥0∞) := by refine StrictMono.orderIsoOfRightInverse (fun x => ⟨(x⁻¹ + 1)⁻¹, ENNReal.inv_le_one.2 <| le_add_self⟩) (fun x y hxy => ?_) (fun x => (x.1⁻¹ - 1)⁻¹) fun x => Subtype.ext ?_ · simpa only [Subtype.mk_lt_mk, ENNReal.inv_lt_inv, ENNReal.add_lt_add_iff_right one_ne_top] · have : (1 : ℝ≥0∞) ≤ x.1⁻¹ := ENNReal.one_le_inv.2 x.2 simp only [inv_inv, Subtype.coe_mk, tsub_add_cancel_of_le this] #align ennreal.order_iso_Iic_one_birational ENNReal.orderIsoIicOneBirational @[simp] theorem orderIsoIicOneBirational_symm_apply (x : Iic (1 : ℝ≥0∞)) : orderIsoIicOneBirational.symm x = (x.1⁻¹ - 1)⁻¹ := rfl #align ennreal.order_iso_Iic_one_birational_symm_apply ENNReal.orderIsoIicOneBirational_symm_apply /-- Order isomorphism between an initial interval in `ℝ≥0∞` and an initial interval in `ℝ≥0`. -/ @[simps! apply_coe] def orderIsoIicCoe (a : ℝ≥0) : Iic (a : ℝ≥0∞) ≃o Iic a := OrderIso.symm { toFun := fun x => ⟨x, coe_le_coe.2 x.2⟩ invFun := fun x => ⟨ENNReal.toNNReal x, coe_le_coe.1 <| coe_toNNReal_le_self.trans x.2⟩ left_inv := fun x => Subtype.ext <| toNNReal_coe right_inv := fun x => Subtype.ext <| coe_toNNReal (ne_top_of_le_ne_top coe_ne_top x.2) map_rel_iff' := fun {_ _} => by simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, coe_le_coe, Subtype.coe_le_coe] } #align ennreal.order_iso_Iic_coe ENNReal.orderIsoIicCoe @[simp] theorem orderIsoIicCoe_symm_apply_coe (a : ℝ≥0) (b : Iic a) : ((orderIsoIicCoe a).symm b : ℝ≥0∞) = b := rfl #align ennreal.order_iso_Iic_coe_symm_apply_coe ENNReal.orderIsoIicCoe_symm_apply_coe /-- An order isomorphism between the extended nonnegative real numbers and the unit interval. -/ def orderIsoUnitIntervalBirational : ℝ≥0∞ ≃o Icc (0 : ℝ) 1 := orderIsoIicOneBirational.trans <| (orderIsoIicCoe 1).trans <| (NNReal.orderIsoIccZeroCoe 1).symm #align ennreal.order_iso_unit_interval_birational ENNReal.orderIsoUnitIntervalBirational @[simp] theorem orderIsoUnitIntervalBirational_apply_coe (x : ℝ≥0∞) : (orderIsoUnitIntervalBirational x : ℝ) = (x⁻¹ + 1)⁻¹.toReal := rfl #align ennreal.order_iso_unit_interval_birational_apply_coe ENNReal.orderIsoUnitIntervalBirational_apply_coe theorem exists_inv_nat_lt {a : ℝ≥0∞} (h : a ≠ 0) : ∃ n : ℕ, (n : ℝ≥0∞)⁻¹ < a := inv_inv a ▸ by simp only [ENNReal.inv_lt_inv, ENNReal.exists_nat_gt (inv_ne_top.2 h)] #align ennreal.exists_inv_nat_lt ENNReal.exists_inv_nat_lt theorem exists_nat_pos_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) : ∃ n > 0, b < (n : ℕ) * a := let ⟨n, hn⟩ := ENNReal.exists_nat_gt (div_lt_top hb ha).ne ⟨n, Nat.cast_pos.1 ((zero_le _).trans_lt hn), by rwa [← ENNReal.div_lt_iff (Or.inl ha) (Or.inr hb)]⟩ #align ennreal.exists_nat_pos_mul_gt ENNReal.exists_nat_pos_mul_gt theorem exists_nat_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) : ∃ n : ℕ, b < n * a := (exists_nat_pos_mul_gt ha hb).imp fun _ => And.right #align ennreal.exists_nat_mul_gt ENNReal.exists_nat_mul_gt theorem exists_nat_pos_inv_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) : ∃ n > 0, ((n : ℕ) : ℝ≥0∞)⁻¹ * a < b := by rcases exists_nat_pos_mul_gt hb ha with ⟨n, npos, hn⟩ use n, npos rw [← ENNReal.div_eq_inv_mul] exact div_lt_of_lt_mul' hn #align ennreal.exists_nat_pos_inv_mul_lt ENNReal.exists_nat_pos_inv_mul_lt
Mathlib/Data/ENNReal/Inv.lean
573
576
theorem exists_nnreal_pos_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) : ∃ n > 0, ↑(n : ℝ≥0) * a < b := by
rcases exists_nat_pos_inv_mul_lt ha hb with ⟨n, npos : 0 < n, hn⟩ use (n : ℝ≥0)⁻¹ simp [*, npos.ne', zero_lt_one]
/- 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.MeasureTheory.Integral.FundThmCalculus import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv #align_import analysis.special_functions.integrals from "leanprover-community/mathlib"@"011cafb4a5bc695875d186e245d6b3df03bf6c40" /-! # 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`. See `test/integration.lean` for specific examples. 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 Nat 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 #align interval_integral.interval_integrable_pow intervalIntegral.intervalIntegrable_pow 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 #align interval_integral.interval_integrable_zpow intervalIntegral.intervalIntegrable_zpow /-- 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 #align interval_integral.interval_integrable_rpow intervalIntegral.intervalIntegrable_rpow /-- 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)] #align interval_integral.interval_integrable_rpow' intervalIntegral.intervalIntegrable_rpow' /-- 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 (ContinuousAt.continuousOn 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_iff] 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 ContinuousAt.continuousOn 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_eq_abs, Complex.abs_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] have : Ioc c 0 = Ioo c 0 ∪ {(0 : ℝ)} := by rw [← Ioo_union_Icc_eq_Ioc hc (le_refl 0), ← Icc_def] simp_rw [← le_antisymm_iff, setOf_eq_eq_singleton'] rw [this, 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_eq_abs (_ ^ _), Complex.abs_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 #align interval_integral.interval_integrable_cpow intervalIntegral.intervalIntegrable_cpow /-- 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_eq_abs, Complex.abs_cpow_eq_rpow_re_of_pos hx.1] · exact measurableSet_uIoc · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc refine ContinuousAt.continuousOn 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 #align interval_integral.interval_integrable_cpow' intervalIntegral.intervalIntegrable_cpow' /-- 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.abs_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 #align interval_integral.interval_integrable_id intervalIntegral.intervalIntegrable_id -- @[simp] -- Porting note (#10618): simp can prove this theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) μ a b := continuous_const.intervalIntegrable a b #align interval_integral.interval_integrable_const intervalIntegral.intervalIntegrable_const 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 #align interval_integral.interval_integrable_one_div intervalIntegral.intervalIntegrable_one_div @[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 #align interval_integral.interval_integrable_inv intervalIntegral.intervalIntegrable_inv @[simp] theorem intervalIntegrable_exp : IntervalIntegrable exp μ a b := continuous_exp.intervalIntegrable a b #align interval_integral.interval_integrable_exp intervalIntegral.intervalIntegrable_exp @[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 #align interval_integrable.log IntervalIntegrable.log @[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 #align interval_integral.interval_integrable_log intervalIntegral.intervalIntegrable_log @[simp] theorem intervalIntegrable_sin : IntervalIntegrable sin μ a b := continuous_sin.intervalIntegrable a b #align interval_integral.interval_integrable_sin intervalIntegral.intervalIntegrable_sin @[simp] theorem intervalIntegrable_cos : IntervalIntegrable cos μ a b := continuous_cos.intervalIntegrable a b #align interval_integral.interval_integrable_cos intervalIntegral.intervalIntegrable_cos 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 · continuity · nlinarith #align interval_integral.interval_integrable_one_div_one_add_sq intervalIntegral.intervalIntegrable_one_div_one_add_sq @[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 #align interval_integral.interval_integrable_inv_one_add_sq intervalIntegral.intervalIntegrable_inv_one_add_sq /-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/ -- Porting note (#10618): was @[simp]; -- simpNF says LHS does not simplify when applying lemma on itself 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 #align interval_integral.mul_integral_comp_mul_right intervalIntegral.mul_integral_comp_mul_right -- Porting note (#10618): was @[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 #align interval_integral.mul_integral_comp_mul_left intervalIntegral.mul_integral_comp_mul_left -- Porting note (#10618): was @[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 #align interval_integral.inv_mul_integral_comp_div intervalIntegral.inv_mul_integral_comp_div -- Porting note (#10618): was @[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 #align interval_integral.mul_integral_comp_mul_add intervalIntegral.mul_integral_comp_mul_add -- Porting note (#10618): was @[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 #align interval_integral.mul_integral_comp_add_mul intervalIntegral.mul_integral_comp_add_mul -- Porting note (#10618): was @[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 #align interval_integral.inv_mul_integral_comp_div_add intervalIntegral.inv_mul_integral_comp_div_add -- Porting note (#10618): was @[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 #align interval_integral.inv_mul_integral_comp_add_div intervalIntegral.inv_mul_integral_comp_add_div -- Porting note (#10618): was @[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 #align interval_integral.mul_integral_comp_mul_sub intervalIntegral.mul_integral_comp_mul_sub -- Porting note (#10618): was @[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 #align interval_integral.mul_integral_comp_sub_mul intervalIntegral.mul_integral_comp_sub_mul -- Porting note (#10618): was @[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 #align interval_integral.inv_mul_integral_comp_div_sub intervalIntegral.inv_mul_integral_comp_div_sub -- Porting note (#10618): was @[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 #align interval_integral.inv_mul_integral_comp_sub_div intervalIntegral.inv_mul_integral_comp_sub_div 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 cases' 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 (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 ?_ ?_).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 #align integral_cpow integral_cpow 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] -- Porting note: was `change ... with ...` have : Complex.re = RCLike.re := rfl rw [this, ← integral_re] · rfl refine intervalIntegrable_iff.mp ?_ cases' 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] rfl #align integral_rpow integral_rpow 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 #align integral_zpow integral_zpow @[simp] theorem integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by simpa only [← Int.ofNat_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg) #align integral_pow integral_pow /-- 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_lt hab, ← 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)] #align integral_pow_abs_sub_uIoc integral_pow_abs_sub_uIoc @[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 #align integral_id integral_id -- @[simp] -- Porting note (#10618): simp can prove this theorem integral_one : (∫ _ in a..b, (1 : ℝ)) = b - a := by simp only [mul_one, smul_eq_mul, integral_const] #align integral_one integral_one
Mathlib/Analysis/SpecialFunctions/Integrals.lean
452
452
theorem integral_const_on_unit_interval : ∫ _ in a..a + 1, b = b := by
simp
/- Copyright (c) 2023 Felix Weilacher. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Felix Weilacher, Yury G. Kudryashov, Rémy Degenne -/ import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Data.Set.MemPartition import Mathlib.Order.Filter.CountableSeparatingOn /-! # Countably generated measurable spaces We say a measurable space is countably generated if it can be generated by a countable set of sets. In such a space, we can also build a sequence of finer and finer finite measurable partitions of the space such that the measurable space is generated by the union of all partitions. ## Main definitions * `MeasurableSpace.CountablyGenerated`: class stating that a measurable space is countably generated. * `MeasurableSpace.countableGeneratingSet`: a countable set of sets that generates the σ-algebra. * `MeasurableSpace.countablePartition`: sequences of finer and finer partitions of a countably generated space, defined by taking the `memPartion` of an enumeration of the sets in `countableGeneratingSet`. * `MeasurableSpace.SeparatesPoints` : class stating that a measurable space separates points. ## Main statements * `MeasurableSpace.measurable_equiv_nat_bool_of_countablyGenerated`: if a measurable space is countably generated and separates points, it is measure equivalent to a subset of the Cantor Space `ℕ → Bool` (equipped with the product sigma algebra). * `MeasurableSpace.measurable_injection_nat_bool_of_countablyGenerated`: If a measurable space admits a countable sequence of measurable sets separating points, it admits a measurable injection into the Cantor space `ℕ → Bool` `ℕ → Bool` (equipped with the product sigma algebra). The file also contains measurability results about `memPartition`, from which the properties of `countablePartition` are deduced. -/ open Set MeasureTheory namespace MeasurableSpace variable {α β : Type*} /-- We say a measurable space is countably generated if it can be generated by a countable set of sets. -/ class CountablyGenerated (α : Type*) [m : MeasurableSpace α] : Prop where isCountablyGenerated : ∃ b : Set (Set α), b.Countable ∧ m = generateFrom b #align measurable_space.countably_generated MeasurableSpace.CountablyGenerated /-- A countable set of sets that generate the measurable space. We insert `∅` to ensure it is nonempty. -/ def countableGeneratingSet (α : Type*) [MeasurableSpace α] [h : CountablyGenerated α] : Set (Set α) := insert ∅ h.isCountablyGenerated.choose lemma countable_countableGeneratingSet [MeasurableSpace α] [h : CountablyGenerated α] : Set.Countable (countableGeneratingSet α) := Countable.insert _ h.isCountablyGenerated.choose_spec.1 lemma generateFrom_countableGeneratingSet [m : MeasurableSpace α] [h : CountablyGenerated α] : generateFrom (countableGeneratingSet α) = m := (generateFrom_insert_empty _).trans <| h.isCountablyGenerated.choose_spec.2.symm lemma empty_mem_countableGeneratingSet [MeasurableSpace α] [CountablyGenerated α] : ∅ ∈ countableGeneratingSet α := mem_insert _ _ lemma nonempty_countableGeneratingSet [MeasurableSpace α] [CountablyGenerated α] : Set.Nonempty (countableGeneratingSet α) := ⟨∅, mem_insert _ _⟩ lemma measurableSet_countableGeneratingSet [MeasurableSpace α] [CountablyGenerated α] {s : Set α} (hs : s ∈ countableGeneratingSet α) : MeasurableSet s := by rw [← generateFrom_countableGeneratingSet (α := α)] exact measurableSet_generateFrom hs /-- A countable sequence of sets generating the measurable space. -/ def natGeneratingSequence (α : Type*) [MeasurableSpace α] [CountablyGenerated α] : ℕ → (Set α) := enumerateCountable (countable_countableGeneratingSet (α := α)) ∅ lemma generateFrom_natGeneratingSequence (α : Type*) [m : MeasurableSpace α] [CountablyGenerated α] : generateFrom (range (natGeneratingSequence _)) = m := by rw [natGeneratingSequence, range_enumerateCountable_of_mem _ empty_mem_countableGeneratingSet, generateFrom_countableGeneratingSet] lemma measurableSet_natGeneratingSequence [MeasurableSpace α] [CountablyGenerated α] (n : ℕ) : MeasurableSet (natGeneratingSequence α n) := measurableSet_countableGeneratingSet $ Set.enumerateCountable_mem _ empty_mem_countableGeneratingSet n theorem CountablyGenerated.comap [m : MeasurableSpace β] [h : CountablyGenerated β] (f : α → β) : @CountablyGenerated α (.comap f m) := by rcases h with ⟨⟨b, hbc, rfl⟩⟩ rw [comap_generateFrom] letI := generateFrom (preimage f '' b) exact ⟨_, hbc.image _, rfl⟩ theorem CountablyGenerated.sup {m₁ m₂ : MeasurableSpace β} (h₁ : @CountablyGenerated β m₁) (h₂ : @CountablyGenerated β m₂) : @CountablyGenerated β (m₁ ⊔ m₂) := by rcases h₁ with ⟨⟨b₁, hb₁c, rfl⟩⟩ rcases h₂ with ⟨⟨b₂, hb₂c, rfl⟩⟩ exact @mk _ (_ ⊔ _) ⟨_, hb₁c.union hb₂c, generateFrom_sup_generateFrom⟩ /-- Any measurable space structure on a countable space is countably generated. -/ instance (priority := 100) [MeasurableSpace α] [Countable α] : CountablyGenerated α where isCountablyGenerated := by refine ⟨⋃ y, {measurableAtom y}, countable_iUnion (fun i ↦ countable_singleton _), ?_⟩ refine le_antisymm ?_ (generateFrom_le (by simp [MeasurableSet.measurableAtom_of_countable])) intro s hs have : s = ⋃ y ∈ s, measurableAtom y := by apply Subset.antisymm · intro x hx simpa using ⟨x, hx, by simp⟩ · simp only [iUnion_subset_iff] intro x hx exact measurableAtom_subset hs hx rw [this] apply MeasurableSet.biUnion (to_countable s) (fun x _hx ↦ ?_) apply measurableSet_generateFrom simp instance [MeasurableSpace α] [CountablyGenerated α] {p : α → Prop} : CountablyGenerated { x // p x } := .comap _ instance [MeasurableSpace α] [CountablyGenerated α] [MeasurableSpace β] [CountablyGenerated β] : CountablyGenerated (α × β) := .sup (.comap Prod.fst) (.comap Prod.snd) section SeparatesPoints /-- We say that a measurable space separates points if for any two distinct points, there is a measurable set containing one but not the other. -/ class SeparatesPoints (α : Type*) [m : MeasurableSpace α] : Prop where separates : ∀ x y : α, (∀ s, MeasurableSet s → (x ∈ s → y ∈ s)) → x = y theorem separatesPoints_def [MeasurableSpace α] [hs : SeparatesPoints α] {x y : α} (h : ∀ s, MeasurableSet s → (x ∈ s → y ∈ s)) : x = y := hs.separates _ _ h theorem exists_measurableSet_of_ne [MeasurableSpace α] [SeparatesPoints α] {x y : α} (h : x ≠ y) : ∃ s, MeasurableSet s ∧ x ∈ s ∧ y ∉ s := by contrapose! h exact separatesPoints_def h theorem separatesPoints_iff [MeasurableSpace α] : SeparatesPoints α ↔ ∀ x y : α, (∀ s, MeasurableSet s → (x ∈ s ↔ y ∈ s)) → x = y := ⟨fun h ↦ fun _ _ hxy ↦ h.separates _ _ fun _ hs xs ↦ (hxy _ hs).mp xs, fun h ↦ ⟨fun _ _ hxy ↦ h _ _ fun _ hs ↦ ⟨fun xs ↦ hxy _ hs xs, not_imp_not.mp fun xs ↦ hxy _ hs.compl xs⟩⟩⟩ /-- If the measurable space generated by `S` separates points, then this is witnessed by sets in `S`. -/ theorem separating_of_generateFrom (S : Set (Set α)) [h : @SeparatesPoints α (generateFrom S)] : ∀ x y : α, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y := by letI := generateFrom S intros x y hxy rw [← forall_generateFrom_mem_iff_mem_iff] at hxy exact separatesPoints_def $ fun _ hs ↦ (hxy _ hs).mp theorem SeparatesPoints.mono {m m' : MeasurableSpace α} [hsep : @SeparatesPoints _ m] (h : m ≤ m') : @SeparatesPoints _ m' := @SeparatesPoints.mk _ m' fun _ _ hxy ↦ @SeparatesPoints.separates _ m hsep _ _ fun _ hs ↦ hxy _ (h _ hs) /-- We say that a measurable space is countably separated if there is a countable sequence of measurable sets separating points. -/ class CountablySeparated (α : Type*) [MeasurableSpace α] : Prop where countably_separated : HasCountableSeparatingOn α MeasurableSet univ instance countablySeparated_of_hasCountableSeparatingOn [MeasurableSpace α] [h : HasCountableSeparatingOn α MeasurableSet univ] : CountablySeparated α := ⟨h⟩ instance hasCountableSeparatingOn_of_countablySeparated [MeasurableSpace α] [h : CountablySeparated α] : HasCountableSeparatingOn α MeasurableSet univ := h.countably_separated theorem countablySeparated_def [MeasurableSpace α] : CountablySeparated α ↔ HasCountableSeparatingOn α MeasurableSet univ := ⟨fun h ↦ h.countably_separated, fun h ↦ ⟨h⟩⟩
Mathlib/MeasureTheory/MeasurableSpace/CountablyGenerated.lean
185
189
theorem CountablySeparated.mono {m m' : MeasurableSpace α} [hsep : @CountablySeparated _ m] (h : m ≤ m') : @CountablySeparated _ m' := by
simp_rw [countablySeparated_def] at * rcases hsep with ⟨S, Sct, Smeas, hS⟩ use S, Sct, (fun s hs ↦ h _ <| Smeas _ hs), hS
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Measure.Lebesgue.Complex import Mathlib.MeasureTheory.Integral.DivergenceTheorem import Mathlib.MeasureTheory.Integral.CircleIntegral import Mathlib.Analysis.Calculus.Dslope import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Complex.ReImTopology import Mathlib.Analysis.Calculus.DiffContOnCl import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Data.Real.Cardinality #align_import analysis.complex.cauchy_integral from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Cauchy integral formula In this file we prove the Cauchy-Goursat theorem and the Cauchy integral formula for integrals over circles. Most results are formulated for a function `f : ℂ → E` that takes values in a complex Banach space with second countable topology. ## Main statements In the following theorems, if the name ends with `off_countable`, then the actual theorem assumes differentiability at all but countably many points of the set mentioned below. * `Complex.integral_boundary_rect_of_hasFDerivAt_real_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and *real* differentiable on its interior, then its integral over the boundary of this rectangle is equal to the integral of `I • f' (x + y * I) 1 - f' (x + y * I) I` over the rectangle, where `f' z w : E` is the derivative of `f` at `z` in the direction `w` and `I = Complex.I` is the imaginary unit. * `Complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and is *complex* differentiable on its interior, then its integral over the boundary of this rectangle is equal to zero. * `Complex.circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable`: If a function `f : ℂ → E` is continuous on a closed annulus `{z | r ≤ |z - c| ≤ R}` and is complex differentiable on its interior `{z | r < |z - c| < R}`, then the integrals of `(z - c)⁻¹ • f z` over the outer boundary and over the inner boundary are equal. * `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto`, `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a punctured closed disc `{z | |z - c| ≤ R ∧ z ≠ c}`, is complex differentiable on the corresponding punctured open disc, and tends to `y` as `z → c`, `z ≠ c`, then the integral of `(z - c)⁻¹ • f z` over the circle `|z - c| = R` is equal to `2πiy`. In particular, if `f` is continuous on the whole closed disc and is complex differentiable on the corresponding open disc, then this integral is equal to `2πif(c)`. * `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`, `Complex.two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable` **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable on the corresponding open disc, then for any `w` in the corresponding open disc the integral of `(z - w)⁻¹ • f z` over the boundary of the disc is equal to `2πif(w)`. Two versions of the lemma put the multiplier `2πi` at the different sides of the equality. * `Complex.hasFPowerSeriesOnBall_of_differentiable_off_countable`: If `f : ℂ → E` is continuous on a closed disc of positive radius and is complex differentiable on the corresponding open disc, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.hasFPowerSeriesOnBall`: If `f : ℂ → E` is complex differentiable on a closed disc of positive radius, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.analyticAt`, `Differentiable.analyticAt`: If `f : ℂ → E` is differentiable on a neighborhood of a point, then it is analytic at this point. In particular, if `f : ℂ → E` is differentiable on the whole `ℂ`, then it is analytic at every point `z : ℂ`. * `Differentiable.hasFPowerSeriesOnBall`: If `f : ℂ → E` is differentiable everywhere then the `cauchyPowerSeries f z R` is a formal power series representing `f` at `z` with infinite radius of convergence (this holds for any choice of `0 < R`). ## Implementation details The proof of the Cauchy integral formula in this file is based on a very general version of the divergence theorem, see `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` (a version for functions defined on `Fin (n + 1) → ℝ`), `MeasureTheory.integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le`, and `MeasureTheory.integral2_divergence_prod_of_hasFDerivWithinAt_off_countable` (versions for functions defined on `ℝ × ℝ`). Usually, the divergence theorem is formulated for a $C^1$ smooth function. The theorems formulated above deal with a function that is * continuous on a closed box/rectangle; * differentiable at all but countably many points of its interior; * have divergence integrable over the closed box/rectangle. First, we reformulate the theorem for a *real*-differentiable map `ℂ → E`, and relate the integral of `f` over the boundary of a rectangle in `ℂ` to the integral of the derivative $\frac{\partial f}{\partial \bar z}$ over the interior of this box. In particular, for a *complex* differentiable function, the latter derivative is zero, hence the integral over the boundary of a rectangle is zero. Thus we get the Cauchy-Goursat theorem for a rectangle in `ℂ`. Next, we apply this theorem to the function $F(z)=f(c+e^{z})$ on the rectangle $[\ln r, \ln R]\times [0, 2\pi]$ to prove that $$ \oint_{|z-c|=r}\frac{f(z)\,dz}{z-c}=\oint_{|z-c|=R}\frac{f(z)\,dz}{z-c} $$ provided that `f` is continuous on the closed annulus `r ≤ |z - c| ≤ R` and is complex differentiable on its interior `r < |z - c| < R` (possibly, at all but countably many points). Here and below, we write $\frac{f(z)}{z-c}$ in the documentation while the actual lemmas use `(z - c)⁻¹ • f z` because `f z` belongs to some Banach space over `ℂ` and `f z / (z - c)` is undefined. Taking the limit of this equality as `r` tends to `𝓝[>] 0`, we prove $$ \oint_{|z-c|=R}\frac{f(z)\,dz}{z-c}=2\pi if(c) $$ provided that `f` is continuous on the closed disc `|z - c| ≤ R` and is differentiable at all but countably many points of its interior. This is the Cauchy integral formula for the center of a circle. In particular, if we apply this function to `F z = (z - c) • f z`, then we get $$ \oint_{|z-c|=R} f(z)\,dz=0. $$ In order to deduce the Cauchy integral formula for any point `w`, `|w - c| < R`, we consider the slope function `g : ℂ → E` given by `g z = (z - w)⁻¹ • (f z - f w)` if `z ≠ w` and `g w = f' w`. This function satisfies assumptions of the previous theorem, so we have $$ \oint_{|z-c|=R} \frac{f(z)\,dz}{z-w}=\oint_{|z-c|=R} \frac{f(w)\,dz}{z-w}= \left(\oint_{|z-c|=R} \frac{dz}{z-w}\right)f(w). $$ The latter integral was computed in `circleIntegral.integral_sub_inv_of_mem_ball` and is equal to `2 * π * Complex.I`. There is one more step in the actual proof. Since we allow `f` to be non-differentiable on a countable set `s`, we cannot immediately claim that `g` is continuous at `w` if `w ∈ s`. So, we use the proof outlined in the previous paragraph for `w ∉ s` (see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux`), then use continuity of both sides of the formula and density of `sᶜ` to prove the formula for all points of the open ball, see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`. Finally, we use the properties of the Cauchy integrals established elsewhere (see `hasFPowerSeriesOn_cauchy_integral`) and Cauchy integral formula to prove that the original function is analytic on the open ball. ## Tags Cauchy-Goursat theorem, Cauchy integral formula -/ open TopologicalSpace Set MeasureTheory intervalIntegral Metric Filter Function open scoped Interval Real NNReal ENNReal Topology noncomputable section universe u variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] namespace Complex /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable at all but countably many points of the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_hasFDerivAt_real_off_countable (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := by set e : (ℝ × ℝ) ≃L[ℝ] ℂ := equivRealProdCLM.symm have he : ∀ x y : ℝ, ↑x + ↑y * I = e (x, y) := fun x y => (mk_eq_add_mul_I x y).symm have he₁ : e (1, 0) = 1 := rfl; have he₂ : e (0, 1) = I := rfl simp only [he] at * set F : ℝ × ℝ → E := f ∘ e set F' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E := fun p => (f' (e p)).comp (e : ℝ × ℝ →L[ℝ] ℂ) have hF' : ∀ p : ℝ × ℝ, (-(I • F' p)) (1, 0) + F' p (0, 1) = -(I • f' (e p) 1 - f' (e p) I) := by rintro ⟨x, y⟩ simp only [F', ContinuousLinearMap.neg_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.comp_apply, ContinuousLinearEquiv.coe_coe, he₁, he₂, neg_add_eq_sub, neg_sub] set R : Set (ℝ × ℝ) := [[z.re, w.re]] ×ˢ [[w.im, z.im]] set t : Set (ℝ × ℝ) := e ⁻¹' s rw [uIcc_comm z.im] at Hc Hi; rw [min_comm z.im, max_comm z.im] at Hd have hR : e ⁻¹' ([[z.re, w.re]] ×ℂ [[w.im, z.im]]) = R := rfl have htc : ContinuousOn F R := Hc.comp e.continuousOn hR.ge have htd : ∀ p ∈ Ioo (min z.re w.re) (max z.re w.re) ×ˢ Ioo (min w.im z.im) (max w.im z.im) \ t, HasFDerivAt F (F' p) p := fun p hp => (Hd (e p) hp).comp p e.hasFDerivAt simp_rw [← intervalIntegral.integral_smul, intervalIntegral.integral_symm w.im z.im, ← intervalIntegral.integral_neg, ← hF'] refine (integral2_divergence_prod_of_hasFDerivWithinAt_off_countable (fun p => -(I • F p)) F (fun p => -(I • F' p)) F' z.re w.im w.re z.im t (hs.preimage e.injective) (htc.const_smul _).neg htc (fun p hp => ((htd p hp).const_smul I).neg) htd ?_).symm rw [← (volume_preserving_equiv_real_prod.symm _).integrableOn_comp_preimage (MeasurableEquiv.measurableEmbedding _)] at Hi simpa only [hF'] using Hi.neg #align complex.integral_boundary_rect_of_has_fderiv_at_real_off_countable Complex.integral_boundary_rect_of_hasFDerivAt_real_off_countable /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable on the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_continuousOn_of_hasFDerivAt_real (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im), HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f f' z w ∅ countable_empty Hc (fun x hx => Hd x hx.1) Hi #align complex.integral_boundary_rect_of_continuous_on_of_has_fderiv_at_real Complex.integral_boundary_rect_of_continuousOn_of_hasFDerivAt_real /-- Suppose that a function `f : ℂ → E` is *real* differentiable on a closed rectangle with opposite corners at `z w : ℂ` and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_differentiableOn_real (f : ℂ → E) (z w : ℂ) (Hd : DifferentiableOn ℝ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hi : IntegrableOn (fun z => I • fderiv ℝ f z 1 - fderiv ℝ f z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • fderiv ℝ f (x + y * I) 1 - fderiv ℝ f (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fderiv ℝ f) z w ∅ countable_empty Hd.continuousOn (fun x hx => Hd.hasFDerivAt <| by simpa only [← mem_interior_iff_mem_nhds, interior_reProdIm, uIcc, interior_Icc] using hx.1) Hi #align complex.integral_boundary_rect_of_differentiable_on_real Complex.integral_boundary_rect_of_differentiableOn_real /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable at all but countably many points of the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiable_on_off_countable (f : ℂ → E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, DifferentiableAt ℂ f x) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := by refine (integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fun z => (fderiv ℂ f z).restrictScalars ℝ) z w s hs Hc (fun x hx => (Hd x hx).hasFDerivAt.restrictScalars ℝ) ?_).trans ?_ <;> simp [← ContinuousLinearMap.map_smul] #align complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable Complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable /-- **Cauchy-Goursat theorem for a rectangle**: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable on the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn (f : ℂ → E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : DifferentiableOn ℂ f (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im))) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_differentiable_on_off_countable f z w ∅ countable_empty Hc fun _x hx => Hd.differentiableAt <| (isOpen_Ioo.reProdIm isOpen_Ioo).mem_nhds hx.1 #align complex.integral_boundary_rect_eq_zero_of_continuous_on_of_differentiable_on Complex.integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is complex differentiable on a closed rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiableOn (f : ℂ → E) (z w : ℂ) (H : DifferentiableOn ℂ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn f z w H.continuousOn <| H.mono <| inter_subset_inter (preimage_mono Ioo_subset_Icc_self) (preimage_mono Ioo_subset_Icc_self) #align complex.integral_boundary_rect_eq_zero_of_differentiable_on Complex.integral_boundary_rect_eq_zero_of_differentiableOn /-- If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f z / (z - c)` (formally, `(z - c)⁻¹ • f z`) over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = ∮ z in C(c, r), (z - c)⁻¹ • f z := by /- We apply the previous lemma to `fun z ↦ f (c + exp z)` on the rectangle `[log r, log R] × [0, 2 * π]`. -/ set A := closedBall c R \ ball c r obtain ⟨a, rfl⟩ : ∃ a, Real.exp a = r := ⟨Real.log r, Real.exp_log h0⟩ obtain ⟨b, rfl⟩ : ∃ b, Real.exp b = R := ⟨Real.log R, Real.exp_log (h0.trans_le hle)⟩ rw [Real.exp_le_exp] at hle -- Unfold definition of `circleIntegral` and cancel some terms. suffices (∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp b) θ)) = ∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp a) θ) by simpa only [circleIntegral, add_sub_cancel_left, ofReal_exp, ← exp_add, smul_smul, ← div_eq_mul_inv, mul_div_cancel_left₀ _ (circleMap_ne_center (Real.exp_pos _).ne'), circleMap_sub_center, deriv_circleMap] set R := [[a, b]] ×ℂ [[0, 2 * π]] set g : ℂ → ℂ := (c + exp ·) have hdg : Differentiable ℂ g := differentiable_exp.const_add _ replace hs : (g ⁻¹' s).Countable := (hs.preimage (add_right_injective c)).preimage_cexp have h_maps : MapsTo g R A := by rintro z ⟨h, -⟩; simpa [g, A, dist_eq, abs_exp, hle] using h.symm replace hc : ContinuousOn (f ∘ g) R := hc.comp hdg.continuous.continuousOn h_maps replace hd : ∀ z ∈ Ioo (min a b) (max a b) ×ℂ Ioo (min 0 (2 * π)) (max 0 (2 * π)) \ g ⁻¹' s, DifferentiableAt ℂ (f ∘ g) z := by refine fun z hz => (hd (g z) ⟨?_, hz.2⟩).comp z (hdg _) simpa [g, dist_eq, abs_exp, hle, and_comm] using hz.1.1 simpa [g, circleMap, exp_periodic _, sub_eq_zero, ← exp_add] using integral_boundary_rect_eq_zero_of_differentiable_on_off_countable _ ⟨a, 0⟩ ⟨b, 2 * π⟩ _ hs hc hd #align complex.circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable Complex.circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable /-- **Cauchy-Goursat theorem** for an annulus. If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f` over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = ∮ z in C(c, r), f z := calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z := (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = ∮ z in C(c, r), (z - c)⁻¹ • (z - c) • f z := (circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable h0 hle hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = ∮ z in C(c, r), f z := circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _ #align complex.circle_integral_eq_of_differentiable_on_annulus_off_countable Complex.circleIntegral_eq_of_differentiable_on_annulus_off_countable /-- **Cauchy integral formula** for the value at the center of a disc. If `f` is continuous on a punctured closed disc of radius `R`, is differentiable at all but countably many points of the interior of this disc, and has a limit `y` at the center of the disc, then the integral $\oint_{‖z-c‖=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto {c : ℂ} {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {y : E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ {c})) (hd : ∀ z ∈ (ball c R \ {c}) \ s, DifferentiableAt ℂ f z) (hy : Tendsto f (𝓝[{c}ᶜ] c) (𝓝 y)) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • y := by rw [← sub_eq_zero, ← norm_le_zero_iff] refine le_of_forall_le_of_dense fun ε ε0 => ?_ obtain ⟨δ, δ0, hδ⟩ : ∃ δ > (0 : ℝ), ∀ z ∈ closedBall c δ \ {c}, dist (f z) y < ε / (2 * π) := ((nhdsWithin_hasBasis nhds_basis_closedBall _).tendsto_iff nhds_basis_ball).1 hy _ (div_pos ε0 Real.two_pi_pos) obtain ⟨r, hr0, hrδ, hrR⟩ : ∃ r, 0 < r ∧ r ≤ δ ∧ r ≤ R := ⟨min δ R, lt_min δ0 h0, min_le_left _ _, min_le_right _ _⟩ have hsub : closedBall c R \ ball c r ⊆ closedBall c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_ball_self hr0) have hsub' : ball c R \ closedBall c r ⊆ ball c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_closedBall_self hr0.le) have hzne : ∀ z ∈ sphere c r, z ≠ c := fun z hz => ne_of_mem_of_not_mem hz fun h => hr0.ne' <| dist_self c ▸ Eq.symm h /- The integral `∮ z in C(c, r), f z / (z - c)` does not depend on `0 < r ≤ R` and tends to `2πIy` as `r → 0`. -/ calc ‖(∮ z in C(c, R), (z - c)⁻¹ • f z) - (2 * ↑π * I) • y‖ = ‖(∮ z in C(c, r), (z - c)⁻¹ • f z) - ∮ z in C(c, r), (z - c)⁻¹ • y‖ := by congr 2 · exact circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable hr0 hrR hs (hc.mono hsub) fun z hz => hd z ⟨hsub' hz.1, hz.2⟩ · simp [hr0.ne'] _ = ‖∮ z in C(c, r), (z - c)⁻¹ • (f z - y)‖ := by simp only [smul_sub] have hc' : ContinuousOn (fun z => (z - c)⁻¹) (sphere c r) := (continuousOn_id.sub continuousOn_const).inv₀ fun z hz => sub_ne_zero.2 <| hzne _ hz rw [circleIntegral.integral_sub] <;> refine (hc'.smul ?_).circleIntegrable hr0.le · exact hc.mono <| subset_inter (sphere_subset_closedBall.trans <| closedBall_subset_closedBall hrR) hzne · exact continuousOn_const _ ≤ 2 * π * r * (r⁻¹ * (ε / (2 * π))) := by refine circleIntegral.norm_integral_le_of_norm_le_const hr0.le fun z hz => ?_ specialize hzne z hz rw [mem_sphere, dist_eq_norm] at hz rw [norm_smul, norm_inv, hz, ← dist_eq_norm] refine mul_le_mul_of_nonneg_left (hδ _ ⟨?_, hzne⟩).le (inv_nonneg.2 hr0.le) rwa [mem_closedBall_iff_norm, hz] _ = ε := by field_simp [hr0.ne', Real.two_pi_pos.ne']; ac_rfl #align complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto /-- **Cauchy integral formula** for the value at the center of a disc. If `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • f c := circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto h0 hs (hc.mono diff_subset) (fun z hz => hd z ⟨hz.1.1, hz.2⟩) (hc.continuousAt <| closedBall_mem_nhds _ h0).continuousWithinAt #align complex.circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable /-- **Cauchy-Goursat theorem** for a disk: if `f : ℂ → E` is continuous on a closed disk `{z | ‖z - c‖ ≤ R}` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R}f(z)\,dz$ equals zero. -/
Mathlib/Analysis/Complex/CauchyIntegral.lean
410
421
theorem circleIntegral_eq_zero_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 ≤ R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = 0 := by
rcases h0.eq_or_lt with (rfl | h0); · apply circleIntegral.integral_radius_zero calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z := (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = (2 * ↑π * I : ℂ) • (c - c) • f c := (circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable h0 hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = 0 := by rw [sub_self, zero_smul, smul_zero]
/- 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.Constructions.BorelSpace.Order #align_import measure_theory.function.simple_func from "leanprover-community/mathlib"@"bf6a01357ff5684b1ebcd0f1a13be314fc82c0bf" /-! # Simple functions A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. In this file, we define simple functions and establish their basic properties; and we construct a sequence of simple functions approximating an arbitrary Borel measurable function `f : α → ℝ≥0∞`. The theorem `Measurable.ennreal_induction` shows that in order to prove something for an arbitrary measurable function into `ℝ≥0∞`, it is sufficient to show that the property holds for (multiples of) characteristic functions and is closed under addition and supremum of increasing sequences of functions. -/ noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory variable {α β γ δ : Type*} /-- A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. This structure bundles a function with these properties. -/ structure SimpleFunc.{u, v} (α : Type u) [MeasurableSpace α] (β : Type v) where toFun : α → β measurableSet_fiber' : ∀ x, MeasurableSet (toFun ⁻¹' {x}) finite_range' : (Set.range toFun).Finite #align measure_theory.simple_func MeasureTheory.SimpleFunc #align measure_theory.simple_func.to_fun MeasureTheory.SimpleFunc.toFun #align measure_theory.simple_func.measurable_set_fiber' MeasureTheory.SimpleFunc.measurableSet_fiber' #align measure_theory.simple_func.finite_range' MeasureTheory.SimpleFunc.finite_range' local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section Measurable variable [MeasurableSpace α] attribute [coe] toFun instance instCoeFun : CoeFun (α →ₛ β) fun _ => α → β := ⟨toFun⟩ #align measure_theory.simple_func.has_coe_to_fun MeasureTheory.SimpleFunc.instCoeFun theorem coe_injective ⦃f g : α →ₛ β⦄ (H : (f : α → β) = g) : f = g := by cases f; cases g; congr #align measure_theory.simple_func.coe_injective MeasureTheory.SimpleFunc.coe_injective @[ext] theorem ext {f g : α →ₛ β} (H : ∀ a, f a = g a) : f = g := coe_injective <| funext H #align measure_theory.simple_func.ext MeasureTheory.SimpleFunc.ext theorem finite_range (f : α →ₛ β) : (Set.range f).Finite := f.finite_range' #align measure_theory.simple_func.finite_range MeasureTheory.SimpleFunc.finite_range theorem measurableSet_fiber (f : α →ₛ β) (x : β) : MeasurableSet (f ⁻¹' {x}) := f.measurableSet_fiber' x #align measure_theory.simple_func.measurable_set_fiber MeasureTheory.SimpleFunc.measurableSet_fiber -- @[simp] -- Porting note (#10618): simp can prove this theorem apply_mk (f : α → β) (h h') (x : α) : SimpleFunc.mk f h h' x = f x := rfl #align measure_theory.simple_func.apply_mk MeasureTheory.SimpleFunc.apply_mk /-- Simple function defined on a finite type. -/ def ofFinite [Finite α] [MeasurableSingletonClass α] (f : α → β) : α →ₛ β where toFun := f measurableSet_fiber' x := (toFinite (f ⁻¹' {x})).measurableSet finite_range' := Set.finite_range f @[deprecated (since := "2024-02-05")] alias ofFintype := ofFinite /-- Simple function defined on the empty type. -/ def ofIsEmpty [IsEmpty α] : α →ₛ β := ofFinite isEmptyElim #align measure_theory.simple_func.of_is_empty MeasureTheory.SimpleFunc.ofIsEmpty /-- Range of a simple function `α →ₛ β` as a `Finset β`. -/ protected def range (f : α →ₛ β) : Finset β := f.finite_range.toFinset #align measure_theory.simple_func.range MeasureTheory.SimpleFunc.range @[simp] theorem mem_range {f : α →ₛ β} {b} : b ∈ f.range ↔ b ∈ range f := Finite.mem_toFinset _ #align measure_theory.simple_func.mem_range MeasureTheory.SimpleFunc.mem_range theorem mem_range_self (f : α →ₛ β) (x : α) : f x ∈ f.range := mem_range.2 ⟨x, rfl⟩ #align measure_theory.simple_func.mem_range_self MeasureTheory.SimpleFunc.mem_range_self @[simp] theorem coe_range (f : α →ₛ β) : (↑f.range : Set β) = Set.range f := f.finite_range.coe_toFinset #align measure_theory.simple_func.coe_range MeasureTheory.SimpleFunc.coe_range theorem mem_range_of_measure_ne_zero {f : α →ₛ β} {x : β} {μ : Measure α} (H : μ (f ⁻¹' {x}) ≠ 0) : x ∈ f.range := let ⟨a, ha⟩ := nonempty_of_measure_ne_zero H mem_range.2 ⟨a, ha⟩ #align measure_theory.simple_func.mem_range_of_measure_ne_zero MeasureTheory.SimpleFunc.mem_range_of_measure_ne_zero theorem forall_mem_range {f : α →ₛ β} {p : β → Prop} : (∀ y ∈ f.range, p y) ↔ ∀ x, p (f x) := by simp only [mem_range, Set.forall_mem_range] #align measure_theory.simple_func.forall_mem_range MeasureTheory.SimpleFunc.forall_mem_range theorem exists_range_iff {f : α →ₛ β} {p : β → Prop} : (∃ y ∈ f.range, p y) ↔ ∃ x, p (f x) := by simpa only [mem_range, exists_prop] using Set.exists_range_iff #align measure_theory.simple_func.exists_range_iff MeasureTheory.SimpleFunc.exists_range_iff theorem preimage_eq_empty_iff (f : α →ₛ β) (b : β) : f ⁻¹' {b} = ∅ ↔ b ∉ f.range := preimage_singleton_eq_empty.trans <| not_congr mem_range.symm #align measure_theory.simple_func.preimage_eq_empty_iff MeasureTheory.SimpleFunc.preimage_eq_empty_iff theorem exists_forall_le [Nonempty β] [Preorder β] [IsDirected β (· ≤ ·)] (f : α →ₛ β) : ∃ C, ∀ x, f x ≤ C := f.range.exists_le.imp fun _ => forall_mem_range.1 #align measure_theory.simple_func.exists_forall_le MeasureTheory.SimpleFunc.exists_forall_le /-- Constant function as a `SimpleFunc`. -/ def const (α) {β} [MeasurableSpace α] (b : β) : α →ₛ β := ⟨fun _ => b, fun _ => MeasurableSet.const _, finite_range_const⟩ #align measure_theory.simple_func.const MeasureTheory.SimpleFunc.const instance instInhabited [Inhabited β] : Inhabited (α →ₛ β) := ⟨const _ default⟩ #align measure_theory.simple_func.inhabited MeasureTheory.SimpleFunc.instInhabited theorem const_apply (a : α) (b : β) : (const α b) a = b := rfl #align measure_theory.simple_func.const_apply MeasureTheory.SimpleFunc.const_apply @[simp] theorem coe_const (b : β) : ⇑(const α b) = Function.const α b := rfl #align measure_theory.simple_func.coe_const MeasureTheory.SimpleFunc.coe_const @[simp] theorem range_const (α) [MeasurableSpace α] [Nonempty α] (b : β) : (const α b).range = {b} := Finset.coe_injective <| by simp (config := { unfoldPartialApp := true }) [Function.const] #align measure_theory.simple_func.range_const MeasureTheory.SimpleFunc.range_const theorem range_const_subset (α) [MeasurableSpace α] (b : β) : (const α b).range ⊆ {b} := Finset.coe_subset.1 <| by simp #align measure_theory.simple_func.range_const_subset MeasureTheory.SimpleFunc.range_const_subset theorem simpleFunc_bot {α} (f : @SimpleFunc α ⊥ β) [Nonempty β] : ∃ c, ∀ x, f x = c := by have hf_meas := @SimpleFunc.measurableSet_fiber α _ ⊥ f simp_rw [MeasurableSpace.measurableSet_bot_iff] at hf_meas exact (exists_eq_const_of_preimage_singleton hf_meas).imp fun c hc ↦ congr_fun hc #align measure_theory.simple_func.simple_func_bot MeasureTheory.SimpleFunc.simpleFunc_bot theorem simpleFunc_bot' {α} [Nonempty β] (f : @SimpleFunc α ⊥ β) : ∃ c, f = @SimpleFunc.const α _ ⊥ c := letI : MeasurableSpace α := ⊥; (simpleFunc_bot f).imp fun _ ↦ ext #align measure_theory.simple_func.simple_func_bot' MeasureTheory.SimpleFunc.simpleFunc_bot' theorem measurableSet_cut (r : α → β → Prop) (f : α →ₛ β) (h : ∀ b, MeasurableSet { a | r a b }) : MeasurableSet { a | r a (f a) } := by have : { a | r a (f a) } = ⋃ b ∈ range f, { a | r a b } ∩ f ⁻¹' {b} := by ext a suffices r a (f a) ↔ ∃ i, r a (f i) ∧ f a = f i by simpa exact ⟨fun h => ⟨a, ⟨h, rfl⟩⟩, fun ⟨a', ⟨h', e⟩⟩ => e.symm ▸ h'⟩ rw [this] exact MeasurableSet.biUnion f.finite_range.countable fun b _ => MeasurableSet.inter (h b) (f.measurableSet_fiber _) #align measure_theory.simple_func.measurable_set_cut MeasureTheory.SimpleFunc.measurableSet_cut @[measurability] theorem measurableSet_preimage (f : α →ₛ β) (s) : MeasurableSet (f ⁻¹' s) := measurableSet_cut (fun _ b => b ∈ s) f fun b => MeasurableSet.const (b ∈ s) #align measure_theory.simple_func.measurable_set_preimage MeasureTheory.SimpleFunc.measurableSet_preimage /-- A simple function is measurable -/ @[measurability] protected theorem measurable [MeasurableSpace β] (f : α →ₛ β) : Measurable f := fun s _ => measurableSet_preimage f s #align measure_theory.simple_func.measurable MeasureTheory.SimpleFunc.measurable @[measurability] protected theorem aemeasurable [MeasurableSpace β] {μ : Measure α} (f : α →ₛ β) : AEMeasurable f μ := f.measurable.aemeasurable #align measure_theory.simple_func.ae_measurable MeasureTheory.SimpleFunc.aemeasurable protected theorem sum_measure_preimage_singleton (f : α →ₛ β) {μ : Measure α} (s : Finset β) : (∑ y ∈ s, μ (f ⁻¹' {y})) = μ (f ⁻¹' ↑s) := sum_measure_preimage_singleton _ fun _ _ => f.measurableSet_fiber _ #align measure_theory.simple_func.sum_measure_preimage_singleton MeasureTheory.SimpleFunc.sum_measure_preimage_singleton theorem sum_range_measure_preimage_singleton (f : α →ₛ β) (μ : Measure α) : (∑ y ∈ f.range, μ (f ⁻¹' {y})) = μ univ := by rw [f.sum_measure_preimage_singleton, coe_range, preimage_range] #align measure_theory.simple_func.sum_range_measure_preimage_singleton MeasureTheory.SimpleFunc.sum_range_measure_preimage_singleton /-- If-then-else as a `SimpleFunc`. -/ def piecewise (s : Set α) (hs : MeasurableSet s) (f g : α →ₛ β) : α →ₛ β := ⟨s.piecewise f g, fun _ => letI : MeasurableSpace β := ⊤ f.measurable.piecewise hs g.measurable trivial, (f.finite_range.union g.finite_range).subset range_ite_subset⟩ #align measure_theory.simple_func.piecewise MeasureTheory.SimpleFunc.piecewise @[simp] theorem coe_piecewise {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) : ⇑(piecewise s hs f g) = s.piecewise f g := rfl #align measure_theory.simple_func.coe_piecewise MeasureTheory.SimpleFunc.coe_piecewise theorem piecewise_apply {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) (a) : piecewise s hs f g a = if a ∈ s then f a else g a := rfl #align measure_theory.simple_func.piecewise_apply MeasureTheory.SimpleFunc.piecewise_apply @[simp] theorem piecewise_compl {s : Set α} (hs : MeasurableSet sᶜ) (f g : α →ₛ β) : piecewise sᶜ hs f g = piecewise s hs.of_compl g f := coe_injective <| by set_option tactic.skipAssignedInstances false in simp [hs]; convert Set.piecewise_compl s f g #align measure_theory.simple_func.piecewise_compl MeasureTheory.SimpleFunc.piecewise_compl @[simp] theorem piecewise_univ (f g : α →ₛ β) : piecewise univ MeasurableSet.univ f g = f := coe_injective <| by set_option tactic.skipAssignedInstances false in simp; convert Set.piecewise_univ f g #align measure_theory.simple_func.piecewise_univ MeasureTheory.SimpleFunc.piecewise_univ @[simp] theorem piecewise_empty (f g : α →ₛ β) : piecewise ∅ MeasurableSet.empty f g = g := coe_injective <| by set_option tactic.skipAssignedInstances false in simp; convert Set.piecewise_empty f g #align measure_theory.simple_func.piecewise_empty MeasureTheory.SimpleFunc.piecewise_empty @[simp] theorem piecewise_same (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) : piecewise s hs f f = f := coe_injective <| Set.piecewise_same _ _ theorem support_indicator [Zero β] {s : Set α} (hs : MeasurableSet s) (f : α →ₛ β) : Function.support (f.piecewise s hs (SimpleFunc.const α 0)) = s ∩ Function.support f := Set.support_indicator #align measure_theory.simple_func.support_indicator MeasureTheory.SimpleFunc.support_indicator theorem range_indicator {s : Set α} (hs : MeasurableSet s) (hs_nonempty : s.Nonempty) (hs_ne_univ : s ≠ univ) (x y : β) : (piecewise s hs (const α x) (const α y)).range = {x, y} := by simp only [← Finset.coe_inj, coe_range, coe_piecewise, range_piecewise, coe_const, Finset.coe_insert, Finset.coe_singleton, hs_nonempty.image_const, (nonempty_compl.2 hs_ne_univ).image_const, singleton_union, Function.const] #align measure_theory.simple_func.range_indicator MeasureTheory.SimpleFunc.range_indicator theorem measurable_bind [MeasurableSpace γ] (f : α →ₛ β) (g : β → α → γ) (hg : ∀ b, Measurable (g b)) : Measurable fun a => g (f a) a := fun s hs => f.measurableSet_cut (fun a b => g b a ∈ s) fun b => hg b hs #align measure_theory.simple_func.measurable_bind MeasureTheory.SimpleFunc.measurable_bind /-- If `f : α →ₛ β` is a simple function and `g : β → α →ₛ γ` is a family of simple functions, then `f.bind g` binds the first argument of `g` to `f`. In other words, `f.bind g a = g (f a) a`. -/ def bind (f : α →ₛ β) (g : β → α →ₛ γ) : α →ₛ γ := ⟨fun a => g (f a) a, fun c => f.measurableSet_cut (fun a b => g b a = c) fun b => (g b).measurableSet_preimage {c}, (f.finite_range.biUnion fun b _ => (g b).finite_range).subset <| by rintro _ ⟨a, rfl⟩; simp⟩ #align measure_theory.simple_func.bind MeasureTheory.SimpleFunc.bind @[simp] theorem bind_apply (f : α →ₛ β) (g : β → α →ₛ γ) (a) : f.bind g a = g (f a) a := rfl #align measure_theory.simple_func.bind_apply MeasureTheory.SimpleFunc.bind_apply /-- Given a function `g : β → γ` and a simple function `f : α →ₛ β`, `f.map g` return the simple function `g ∘ f : α →ₛ γ` -/ def map (g : β → γ) (f : α →ₛ β) : α →ₛ γ := bind f (const α ∘ g) #align measure_theory.simple_func.map MeasureTheory.SimpleFunc.map theorem map_apply (g : β → γ) (f : α →ₛ β) (a) : f.map g a = g (f a) := rfl #align measure_theory.simple_func.map_apply MeasureTheory.SimpleFunc.map_apply theorem map_map (g : β → γ) (h : γ → δ) (f : α →ₛ β) : (f.map g).map h = f.map (h ∘ g) := rfl #align measure_theory.simple_func.map_map MeasureTheory.SimpleFunc.map_map @[simp] theorem coe_map (g : β → γ) (f : α →ₛ β) : (f.map g : α → γ) = g ∘ f := rfl #align measure_theory.simple_func.coe_map MeasureTheory.SimpleFunc.coe_map @[simp] theorem range_map [DecidableEq γ] (g : β → γ) (f : α →ₛ β) : (f.map g).range = f.range.image g := Finset.coe_injective <| by simp only [coe_range, coe_map, Finset.coe_image, range_comp] #align measure_theory.simple_func.range_map MeasureTheory.SimpleFunc.range_map @[simp] theorem map_const (g : β → γ) (b : β) : (const α b).map g = const α (g b) := rfl #align measure_theory.simple_func.map_const MeasureTheory.SimpleFunc.map_const theorem map_preimage (f : α →ₛ β) (g : β → γ) (s : Set γ) : f.map g ⁻¹' s = f ⁻¹' ↑(f.range.filter fun b => g b ∈ s) := by simp only [coe_range, sep_mem_eq, coe_map, Finset.coe_filter, ← mem_preimage, inter_comm, preimage_inter_range, ← Finset.mem_coe] exact preimage_comp #align measure_theory.simple_func.map_preimage MeasureTheory.SimpleFunc.map_preimage theorem map_preimage_singleton (f : α →ₛ β) (g : β → γ) (c : γ) : f.map g ⁻¹' {c} = f ⁻¹' ↑(f.range.filter fun b => g b = c) := map_preimage _ _ _ #align measure_theory.simple_func.map_preimage_singleton MeasureTheory.SimpleFunc.map_preimage_singleton /-- Composition of a `SimpleFun` and a measurable function is a `SimpleFunc`. -/ def comp [MeasurableSpace β] (f : β →ₛ γ) (g : α → β) (hgm : Measurable g) : α →ₛ γ where toFun := f ∘ g finite_range' := f.finite_range.subset <| Set.range_comp_subset_range _ _ measurableSet_fiber' z := hgm (f.measurableSet_fiber z) #align measure_theory.simple_func.comp MeasureTheory.SimpleFunc.comp @[simp] theorem coe_comp [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) : ⇑(f.comp g hgm) = f ∘ g := rfl #align measure_theory.simple_func.coe_comp MeasureTheory.SimpleFunc.coe_comp theorem range_comp_subset_range [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) : (f.comp g hgm).range ⊆ f.range := Finset.coe_subset.1 <| by simp only [coe_range, coe_comp, Set.range_comp_subset_range] #align measure_theory.simple_func.range_comp_subset_range MeasureTheory.SimpleFunc.range_comp_subset_range /-- Extend a `SimpleFunc` along a measurable embedding: `f₁.extend g hg f₂` is the function `F : β →ₛ γ` such that `F ∘ g = f₁` and `F y = f₂ y` whenever `y ∉ range g`. -/ def extend [MeasurableSpace β] (f₁ : α →ₛ γ) (g : α → β) (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) : β →ₛ γ where toFun := Function.extend g f₁ f₂ finite_range' := (f₁.finite_range.union <| f₂.finite_range.subset (image_subset_range _ _)).subset (range_extend_subset _ _ _) measurableSet_fiber' := by letI : MeasurableSpace γ := ⊤; haveI : MeasurableSingletonClass γ := ⟨fun _ => trivial⟩ exact fun x => hg.measurable_extend f₁.measurable f₂.measurable (measurableSet_singleton _) #align measure_theory.simple_func.extend MeasureTheory.SimpleFunc.extend @[simp] theorem extend_apply [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) (x : α) : (f₁.extend g hg f₂) (g x) = f₁ x := hg.injective.extend_apply _ _ _ #align measure_theory.simple_func.extend_apply MeasureTheory.SimpleFunc.extend_apply @[simp] theorem extend_apply' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) {y : β} (h : ¬∃ x, g x = y) : (f₁.extend g hg f₂) y = f₂ y := Function.extend_apply' _ _ _ h #align measure_theory.simple_func.extend_apply' MeasureTheory.SimpleFunc.extend_apply' @[simp] theorem extend_comp_eq' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) : f₁.extend g hg f₂ ∘ g = f₁ := funext fun _ => extend_apply _ _ _ _ #align measure_theory.simple_func.extend_comp_eq' MeasureTheory.SimpleFunc.extend_comp_eq' @[simp] theorem extend_comp_eq [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g) (f₂ : β →ₛ γ) : (f₁.extend g hg f₂).comp g hg.measurable = f₁ := coe_injective <| extend_comp_eq' _ hg _ #align measure_theory.simple_func.extend_comp_eq MeasureTheory.SimpleFunc.extend_comp_eq /-- If `f` is a simple function taking values in `β → γ` and `g` is another simple function with the same domain and codomain `β`, then `f.seq g = f a (g a)`. -/ def seq (f : α →ₛ β → γ) (g : α →ₛ β) : α →ₛ γ := f.bind fun f => g.map f #align measure_theory.simple_func.seq MeasureTheory.SimpleFunc.seq @[simp] theorem seq_apply (f : α →ₛ β → γ) (g : α →ₛ β) (a : α) : f.seq g a = f a (g a) := rfl #align measure_theory.simple_func.seq_apply MeasureTheory.SimpleFunc.seq_apply /-- Combine two simple functions `f : α →ₛ β` and `g : α →ₛ β` into `fun a => (f a, g a)`. -/ def pair (f : α →ₛ β) (g : α →ₛ γ) : α →ₛ β × γ := (f.map Prod.mk).seq g #align measure_theory.simple_func.pair MeasureTheory.SimpleFunc.pair @[simp] theorem pair_apply (f : α →ₛ β) (g : α →ₛ γ) (a) : pair f g a = (f a, g a) := rfl #align measure_theory.simple_func.pair_apply MeasureTheory.SimpleFunc.pair_apply theorem pair_preimage (f : α →ₛ β) (g : α →ₛ γ) (s : Set β) (t : Set γ) : pair f g ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl #align measure_theory.simple_func.pair_preimage MeasureTheory.SimpleFunc.pair_preimage -- A special form of `pair_preimage`
Mathlib/MeasureTheory/Function/SimpleFunc.lean
421
424
theorem pair_preimage_singleton (f : α →ₛ β) (g : α →ₛ γ) (b : β) (c : γ) : pair f g ⁻¹' {(b, c)} = f ⁻¹' {b} ∩ g ⁻¹' {c} := by
rw [← singleton_prod_singleton] exact pair_preimage _ _ _ _
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real #align_import analysis.special_functions.pow.nnreal from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Power function on `ℝ≥0` and `ℝ≥0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open scoped Classical open Real NNReal ENNReal ComplexConjugate open Finset Function Set namespace NNReal variable {w x y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/ noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ #align nnreal.rpow NNReal.rpow noncomputable instance : Pow ℝ≥0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y := rfl #align nnreal.rpow_eq_pow NNReal.rpow_eq_pow @[simp, norm_cast] theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y := rfl #align nnreal.coe_rpow NNReal.coe_rpow @[simp] theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ #align nnreal.rpow_zero NNReal.rpow_zero @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 #align nnreal.rpow_eq_zero_iff NNReal.rpow_eq_zero_iff @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h #align nnreal.zero_rpow NNReal.zero_rpow @[simp] theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ #align nnreal.rpow_one NNReal.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ #align nnreal.one_rpow NNReal.one_rpow theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add (pos_iff_ne_zero.2 hx) _ _ #align nnreal.rpow_add NNReal.rpow_add theorem rpow_add' (x : ℝ≥0) {y z : ℝ} (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h #align nnreal.rpow_add' NNReal.rpow_add' /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z #align nnreal.rpow_mul NNReal.rpow_mul theorem rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ #align nnreal.rpow_neg NNReal.rpow_neg theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] #align nnreal.rpow_neg_one NNReal.rpow_neg_one theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub (pos_iff_ne_zero.2 hx) y z #align nnreal.rpow_sub NNReal.rpow_sub theorem rpow_sub' (x : ℝ≥0) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h #align nnreal.rpow_sub' NNReal.rpow_sub' theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] #align nnreal.rpow_inv_rpow_self NNReal.rpow_inv_rpow_self theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] #align nnreal.rpow_self_rpow_inv NNReal.rpow_self_rpow_inv theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y #align nnreal.inv_rpow NNReal.inv_rpow theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z #align nnreal.div_rpow NNReal.div_rpow theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 #align nnreal.sqrt_eq_rpow NNReal.sqrt_eq_rpow @[simp, norm_cast] theorem rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n #align nnreal.rpow_nat_cast NNReal.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] : x ^ (no_index (OfNat.ofNat n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) := rpow_natCast x n theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 #align nnreal.rpow_two NNReal.rpow_two theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 #align nnreal.mul_rpow NNReal.mul_rpow /-- `rpow` as a `MonoidHom`-/ @[simps] def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where toFun := (· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0`-/ theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/ lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/ lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := by lift l to List ℝ≥0 using hl have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊢ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ) (hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] · rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := by induction' s using Quotient.inductionOn with l simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := Real.rpow_le_rpow x.2 h₁ h₂ #align nnreal.rpow_le_rpow NNReal.rpow_le_rpow @[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ h₂ #align nnreal.rpow_lt_rpow NNReal.rpow_lt_rpow theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz #align nnreal.rpow_lt_rpow_iff NNReal.rpow_lt_rpow_iff theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := Real.rpow_le_rpow_iff x.2 y.2 hz #align nnreal.rpow_le_rpow_iff NNReal.rpow_le_rpow_iff theorem le_rpow_one_div_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ (1 / z) ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne'] #align nnreal.le_rpow_one_div_iff NNReal.le_rpow_one_div_iff theorem rpow_one_div_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ (1 / z) ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne'] #align nnreal.rpow_one_div_le_iff NNReal.rpow_one_div_le_iff @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz #align nnreal.rpow_lt_rpow_of_exponent_lt NNReal.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_le hx hyz #align nnreal.rpow_le_rpow_of_exponent_le NNReal.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz #align nnreal.rpow_lt_rpow_of_exponent_gt NNReal.rpow_lt_rpow_of_exponent_gt theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz #align nnreal.rpow_le_rpow_of_exponent_ge NNReal.rpow_le_rpow_of_exponent_ge theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by intro p hp_pos rw [← zero_rpow hp_pos.ne'] exact rpow_lt_rpow hx_pos hp_pos rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg) · exact rpow_pos_of_nonneg hp_pos · simp only [zero_lt_one, rpow_zero] · rw [← neg_neg p, rpow_neg, inv_pos] exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) #align nnreal.rpow_pos NNReal.rpow_pos theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 := Real.rpow_lt_one (coe_nonneg x) hx1 hz #align nnreal.rpow_lt_one NNReal.rpow_lt_one theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := Real.rpow_le_one x.2 hx2 hz #align nnreal.rpow_le_one NNReal.rpow_le_one theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := Real.rpow_lt_one_of_one_lt_of_neg hx hz #align nnreal.rpow_lt_one_of_one_lt_of_neg NNReal.rpow_lt_one_of_one_lt_of_neg theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hx hz #align nnreal.rpow_le_one_of_one_le_of_nonpos NNReal.rpow_le_one_of_one_le_of_nonpos theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := Real.one_lt_rpow hx hz #align nnreal.one_lt_rpow NNReal.one_lt_rpow theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z := Real.one_le_rpow h h₁ #align nnreal.one_le_rpow NNReal.one_le_rpow theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz #align nnreal.one_lt_rpow_of_pos_of_lt_one_of_neg NNReal.one_lt_rpow_of_pos_of_lt_one_of_neg theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z ≤ 0) : 1 ≤ x ^ z := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz #align nnreal.one_le_rpow_of_pos_of_le_one_of_nonpos NNReal.one_le_rpow_of_pos_of_le_one_of_nonpos theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x)) · have : z ≠ 0 := by linarith simp [this] nth_rw 2 [← NNReal.rpow_one x] exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le #align nnreal.rpow_le_self_of_le_one NNReal.rpow_le_self_of_le_one theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x := fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz #align nnreal.rpow_left_injective NNReal.rpow_left_injective theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injective hz).eq_iff #align nnreal.rpow_eq_rpow_iff NNReal.rpow_eq_rpow_iff theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x := fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, _root_.inv_mul_cancel hx, rpow_one]⟩ #align nnreal.rpow_left_surjective NNReal.rpow_left_surjective theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ #align nnreal.rpow_left_bijective NNReal.rpow_left_bijective theorem eq_rpow_one_div_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ (1 / z) ↔ x ^ z = y := by rw [← rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz] #align nnreal.eq_rpow_one_div_iff NNReal.eq_rpow_one_div_iff theorem rpow_one_div_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ (1 / z) = y ↔ x = y ^ z := by rw [← rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz] #align nnreal.rpow_one_div_eq_iff NNReal.rpow_one_div_eq_iff @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancel hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancel hy, rpow_one] theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow] exact Real.pow_rpow_inv_natCast x.2 hn #align nnreal.pow_nat_rpow_nat_inv NNReal.pow_rpow_inv_natCast theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow] exact Real.rpow_inv_natCast_pow x.2 hn #align nnreal.rpow_nat_inv_pow_nat NNReal.rpow_inv_natCast_pow theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_rpow, Real.toNNReal_coe] #align real.to_nnreal_rpow_of_nonneg Real.toNNReal_rpow_of_nonneg theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z := fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z := h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div]; rfl end NNReal namespace ENNReal /-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and `y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and `⊤ ^ x = 1 / 0 ^ x`). -/ noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞ | some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0) | none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0 #align ennreal.rpow ENNReal.rpow noncomputable instance : Pow ℝ≥0∞ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y := rfl #align ennreal.rpow_eq_pow ENNReal.rpow_eq_pow @[simp] theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by cases x <;> · dsimp only [(· ^ ·), Pow.pow, rpow] simp [lt_irrefl] #align ennreal.rpow_zero ENNReal.rpow_zero theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 := rfl #align ennreal.top_rpow_def ENNReal.top_rpow_def @[simp] theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h] #align ennreal.top_rpow_of_pos ENNReal.top_rpow_of_pos @[simp] theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by simp [top_rpow_def, asymm h, ne_of_lt h] #align ennreal.top_rpow_of_neg ENNReal.top_rpow_of_neg @[simp] theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, asymm h, ne_of_gt h] #align ennreal.zero_rpow_of_pos ENNReal.zero_rpow_of_pos @[simp] theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, ne_of_gt h] #align ennreal.zero_rpow_of_neg ENNReal.zero_rpow_of_neg theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H) · simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] · simp [lt_irrefl] · simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] #align ennreal.zero_rpow_def ENNReal.zero_rpow_def @[simp] theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by rw [zero_rpow_def] split_ifs exacts [zero_mul _, one_mul _, top_mul_top] #align ennreal.zero_rpow_mul_self ENNReal.zero_rpow_mul_self @[norm_cast] theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) := by rw [← ENNReal.some_eq_coe] dsimp only [(· ^ ·), Pow.pow, rpow] simp [h] #align ennreal.coe_rpow_of_ne_zero ENNReal.coe_rpow_of_ne_zero @[norm_cast] theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : (x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) := by by_cases hx : x = 0 · rcases le_iff_eq_or_lt.1 h with (H | H) · simp [hx, H.symm] · simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)] · exact coe_rpow_of_ne_zero hx _ #align ennreal.coe_rpow_of_nonneg ENNReal.coe_rpow_of_nonneg theorem coe_rpow_def (x : ℝ≥0) (y : ℝ) : (x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else ↑(x ^ y) := rfl #align ennreal.coe_rpow_def ENNReal.coe_rpow_def @[simp] theorem rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x := by cases x · exact dif_pos zero_lt_one · change ite _ _ _ = _ simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp] exact fun _ => zero_le_one.not_lt #align ennreal.rpow_one ENNReal.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 := by rw [← coe_one, coe_rpow_of_ne_zero one_ne_zero] simp #align ennreal.one_rpow ENNReal.one_rpow @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊤ ∧ y < 0 := by cases' x with x · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] · simp [coe_rpow_of_ne_zero h, h] #align ennreal.rpow_eq_zero_iff ENNReal.rpow_eq_zero_iff lemma rpow_eq_zero_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by simp [hy, hy.not_lt] @[simp] theorem rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = ⊤ ↔ x = 0 ∧ y < 0 ∨ x = ⊤ ∧ 0 < y := by cases' x with x · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] · simp [coe_rpow_of_ne_zero h, h] #align ennreal.rpow_eq_top_iff ENNReal.rpow_eq_top_iff theorem rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ := by simp [rpow_eq_top_iff, hy, asymm hy] #align ennreal.rpow_eq_top_iff_of_pos ENNReal.rpow_eq_top_iff_of_pos lemma rpow_lt_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy] theorem rpow_eq_top_of_nonneg (x : ℝ≥0∞) {y : ℝ} (hy0 : 0 ≤ y) : x ^ y = ⊤ → x = ⊤ := by rw [ENNReal.rpow_eq_top_iff] rintro (h|h) · exfalso rw [lt_iff_not_ge] at h exact h.right hy0 · exact h.left #align ennreal.rpow_eq_top_of_nonneg ENNReal.rpow_eq_top_of_nonneg theorem rpow_ne_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y ≠ ⊤ := mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h #align ennreal.rpow_ne_top_of_nonneg ENNReal.rpow_ne_top_of_nonneg theorem rpow_lt_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y < ⊤ := lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h) #align ennreal.rpow_lt_top_of_nonneg ENNReal.rpow_lt_top_of_nonneg theorem rpow_add {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y + z) = x ^ y * x ^ z := by cases' x with x · exact (h'x rfl).elim have : x ≠ 0 := fun h => by simp [h] at hx simp [coe_rpow_of_ne_zero this, NNReal.rpow_add this] #align ennreal.rpow_add ENNReal.rpow_add theorem rpow_neg (x : ℝ≥0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by cases' x with x · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr] · have A : x ^ y ≠ 0 := by simp [h] simp [coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg] #align ennreal.rpow_neg ENNReal.rpow_neg theorem rpow_sub {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv] #align ennreal.rpow_sub ENNReal.rpow_sub theorem rpow_neg_one (x : ℝ≥0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] #align ennreal.rpow_neg_one ENNReal.rpow_neg_one theorem rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by cases' x with x · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] · have : x ^ y ≠ 0 := by simp [h] simp [coe_rpow_of_ne_zero h, coe_rpow_of_ne_zero this, NNReal.rpow_mul] #align ennreal.rpow_mul ENNReal.rpow_mul @[simp, norm_cast] theorem rpow_natCast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by cases x · cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_pos _)] · simp [coe_rpow_of_nonneg _ (Nat.cast_nonneg n)] #align ennreal.rpow_nat_cast ENNReal.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] lemma rpow_ofNat (x : ℝ≥0∞) (n : ℕ) [n.AtLeastTwo] : x ^ (no_index (OfNat.ofNat n) : ℝ) = x ^ (OfNat.ofNat n) := rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝ≥0∞) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] @[deprecated (since := "2024-04-17")] alias rpow_int_cast := rpow_intCast theorem rpow_two (x : ℝ≥0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 #align ennreal.rpow_two ENNReal.rpow_two theorem mul_rpow_eq_ite (x y : ℝ≥0∞) (z : ℝ) : (x * y) ^ z = if (x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0) ∧ z < 0 then ⊤ else x ^ z * y ^ z := by rcases eq_or_ne z 0 with (rfl | hz); · simp replace hz := hz.lt_or_lt wlog hxy : x ≤ y · convert this y x z hz (le_of_not_le hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm] rcases eq_or_ne x 0 with (rfl | hx0) · induction y <;> cases' hz with hz hz <;> simp [*, hz.not_lt] rcases eq_or_ne y 0 with (rfl | hy0) · exact (hx0 (bot_unique hxy)).elim induction x · cases' hz with hz hz <;> simp [hz, top_unique hxy] induction y · rw [ne_eq, coe_eq_zero] at hx0 cases' hz with hz hz <;> simp [*] simp only [*, false_and_iff, and_false_iff, false_or_iff, if_false] norm_cast at * rw [coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow] norm_cast #align ennreal.mul_rpow_eq_ite ENNReal.mul_rpow_eq_ite theorem mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] #align ennreal.mul_rpow_of_ne_top ENNReal.mul_rpow_of_ne_top @[norm_cast] theorem coe_mul_rpow (x y : ℝ≥0) (z : ℝ) : ((x : ℝ≥0∞) * y) ^ z = (x : ℝ≥0∞) ^ z * (y : ℝ≥0∞) ^ z := mul_rpow_of_ne_top coe_ne_top coe_ne_top z #align ennreal.coe_mul_rpow ENNReal.coe_mul_rpow theorem prod_coe_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) : ∏ i ∈ s, (f i : ℝ≥0∞) ^ r = ((∏ i ∈ s, f i : ℝ≥0) : ℝ≥0∞) ^ r := by induction s using Finset.induction with | empty => simp | insert hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul] theorem mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] #align ennreal.mul_rpow_of_ne_zero ENNReal.mul_rpow_of_ne_zero theorem mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x * y) ^ z = x ^ z * y ^ z := by simp [hz.not_lt, mul_rpow_eq_ite] #align ennreal.mul_rpow_of_nonneg ENNReal.mul_rpow_of_nonneg theorem prod_rpow_of_ne_top {ι} {s : Finset ι} {f : ι → ℝ≥0∞} (hf : ∀ i ∈ s, f i ≠ ∞) (r : ℝ) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by induction s using Finset.induction with | empty => simp | @insert i s hi ih => have h2f : ∀ i ∈ s, f i ≠ ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..] apply prod_lt_top h2f |>.ne theorem prod_rpow_of_nonneg {ι} {s : Finset ι} {f : ι → ℝ≥0∞} {r : ℝ} (hr : 0 ≤ r) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by induction s using Finset.induction with | empty => simp | insert hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr] theorem inv_rpow (x : ℝ≥0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by rcases eq_or_ne y 0 with (rfl | hy); · simp only [rpow_zero, inv_one] replace hy := hy.lt_or_lt rcases eq_or_ne x 0 with (rfl | h0); · cases hy <;> simp [*] rcases eq_or_ne x ⊤ with (rfl | h_top); · cases hy <;> simp [*] apply ENNReal.eq_inv_of_mul_eq_one_left rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top, one_rpow] #align ennreal.inv_rpow ENNReal.inv_rpow theorem div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x / y) ^ z = x ^ z / y ^ z := by rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv] #align ennreal.div_rpow_of_nonneg ENNReal.div_rpow_of_nonneg theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0∞ => x ^ z := by intro x y hxy lift x to ℝ≥0 using ne_top_of_lt hxy rcases eq_or_ne y ∞ with (rfl | hy) · simp only [top_rpow_of_pos h, coe_rpow_of_nonneg _ h.le, coe_lt_top] · lift y to ℝ≥0 using hy simp only [coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe] #align ennreal.strict_mono_rpow_of_pos ENNReal.strictMono_rpow_of_pos theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0∞ => x ^ z := h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone #align ennreal.monotone_rpow_of_nonneg ENNReal.monotone_rpow_of_nonneg /-- Bundles `fun x : ℝ≥0∞ => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝ≥0∞ => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0∞ ≃o ℝ≥0∞ := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] #align ennreal.order_iso_rpow ENNReal.orderIsoRpow theorem orderIsoRpow_symm_apply (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div] rfl #align ennreal.order_iso_rpow_symm_apply ENNReal.orderIsoRpow_symm_apply @[gcongr] theorem rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := monotone_rpow_of_nonneg h₂ h₁ #align ennreal.rpow_le_rpow ENNReal.rpow_le_rpow @[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z := strictMono_rpow_of_pos h₂ h₁ #align ennreal.rpow_lt_rpow ENNReal.rpow_lt_rpow theorem rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := (strictMono_rpow_of_pos hz).le_iff_le #align ennreal.rpow_le_rpow_iff ENNReal.rpow_le_rpow_iff theorem rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := (strictMono_rpow_of_pos hz).lt_iff_lt #align ennreal.rpow_lt_rpow_iff ENNReal.rpow_lt_rpow_iff theorem le_rpow_one_div_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ≤ y ^ (1 / z) ↔ x ^ z ≤ y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @_root_.mul_inv_cancel _ _ z hz.ne'] rw [rpow_mul, ← one_div, @rpow_le_rpow_iff _ _ (1 / z) (by simp [hz])] #align ennreal.le_rpow_one_div_iff ENNReal.le_rpow_one_div_iff theorem lt_rpow_one_div_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x < y ^ (1 / z) ↔ x ^ z < y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @_root_.mul_inv_cancel _ _ z (ne_of_lt hz).symm] rw [rpow_mul, ← one_div, @rpow_lt_rpow_iff _ _ (1 / z) (by simp [hz])] #align ennreal.lt_rpow_one_div_iff ENNReal.lt_rpow_one_div_iff theorem rpow_one_div_le_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ (1 / z) ≤ y ↔ x ≤ y ^ z := by nth_rw 1 [← ENNReal.rpow_one y] nth_rw 2 [← @_root_.mul_inv_cancel _ _ z hz.ne.symm] rw [ENNReal.rpow_mul, ← one_div, ENNReal.rpow_le_rpow_iff (one_div_pos.2 hz)] #align ennreal.rpow_one_div_le_iff ENNReal.rpow_one_div_le_iff theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0∞} {y z : ℝ} (hx : 1 < x) (hx' : x ≠ ⊤) (hyz : y < z) : x ^ y < x ^ z := by lift x to ℝ≥0 using hx' rw [one_lt_coe_iff] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_rpow_of_exponent_lt hx hyz] #align ennreal.rpow_lt_rpow_of_exponent_lt ENNReal.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0∞} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by cases x · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;> linarith · simp only [one_le_coe_iff, some_eq_coe] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_rpow_of_exponent_le hx hyz] #align ennreal.rpow_le_rpow_of_exponent_le ENNReal.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx1 le_top) simp only [coe_lt_one_iff, coe_pos] at hx0 hx1 simp [coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz] #align ennreal.rpow_lt_rpow_of_exponent_gt ENNReal.rpow_lt_rpow_of_exponent_gt theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0∞} {y z : ℝ} (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top) by_cases h : x = 0 · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;> linarith · rw [coe_le_one_iff] at hx1 simp [coe_rpow_of_ne_zero h, NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz] #align ennreal.rpow_le_rpow_of_exponent_ge ENNReal.rpow_le_rpow_of_exponent_ge theorem rpow_le_self_of_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by nth_rw 2 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le #align ennreal.rpow_le_self_of_le_one ENNReal.rpow_le_self_of_le_one theorem le_rpow_self_of_one_le {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (h_one_le : 1 ≤ z) : x ≤ x ^ z := by nth_rw 1 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le #align ennreal.le_rpow_self_of_one_le ENNReal.le_rpow_self_of_one_le theorem rpow_pos_of_nonneg {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≤ p) : 0 < x ^ p := by by_cases hp_zero : p = 0 · simp [hp_zero, zero_lt_one] · rw [← Ne] at hp_zero have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm rw [← zero_rpow_of_pos hp_pos] exact rpow_lt_rpow hx_pos hp_pos #align ennreal.rpow_pos_of_nonneg ENNReal.rpow_pos_of_nonneg theorem rpow_pos {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hx_ne_top : x ≠ ⊤) : 0 < x ^ p := by cases' lt_or_le 0 p with hp_pos hp_nonpos · exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos) · rw [← neg_neg p, rpow_neg, ENNReal.inv_pos] exact rpow_ne_top_of_nonneg (Right.nonneg_neg_iff.mpr hp_nonpos) hx_ne_top #align ennreal.rpow_pos ENNReal.rpow_pos theorem rpow_lt_one {x : ℝ≥0∞} {z : ℝ} (hx : x < 1) (hz : 0 < z) : x ^ z < 1 := by lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx le_top) simp only [coe_lt_one_iff] at hx simp [coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.rpow_lt_one hx hz] #align ennreal.rpow_lt_one ENNReal.rpow_lt_one theorem rpow_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx coe_lt_top) simp only [coe_le_one_iff] at hx simp [coe_rpow_of_nonneg _ hz, NNReal.rpow_le_one hx hz] #align ennreal.rpow_le_one ENNReal.rpow_le_one theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by cases x · simp [top_rpow_of_neg hz, zero_lt_one] · simp only [some_eq_coe, one_lt_coe_iff] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_one_of_one_lt_of_neg hx hz] #align ennreal.rpow_lt_one_of_one_lt_of_neg ENNReal.rpow_lt_one_of_one_lt_of_neg theorem rpow_le_one_of_one_le_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : z < 0) : x ^ z ≤ 1 := by cases x · simp [top_rpow_of_neg hz, zero_lt_one] · simp only [one_le_coe_iff, some_eq_coe] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_one_of_one_le_of_nonpos hx (le_of_lt hz)] #align ennreal.rpow_le_one_of_one_le_of_neg ENNReal.rpow_le_one_of_one_le_of_neg theorem one_lt_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by cases x · simp [top_rpow_of_pos hz] · simp only [some_eq_coe, one_lt_coe_iff] at hx simp [coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_lt_rpow hx hz] #align ennreal.one_lt_rpow ENNReal.one_lt_rpow theorem one_le_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : 0 < z) : 1 ≤ x ^ z := by cases x · simp [top_rpow_of_pos hz] · simp only [one_le_coe_iff, some_eq_coe] at hx simp [coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_le_rpow hx (le_of_lt hz)] #align ennreal.one_le_rpow ENNReal.one_le_rpow theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx2 le_top) simp only [coe_lt_one_iff, coe_pos] at hx1 hx2 ⊢ simp [coe_rpow_of_ne_zero (ne_of_gt hx1), NNReal.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz] #align ennreal.one_lt_rpow_of_pos_of_lt_one_of_neg ENNReal.one_lt_rpow_of_pos_of_lt_one_of_neg theorem one_le_rpow_of_pos_of_le_one_of_neg {x : ℝ≥0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z < 0) : 1 ≤ x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx2 coe_lt_top) simp only [coe_le_one_iff, coe_pos] at hx1 hx2 ⊢ simp [coe_rpow_of_ne_zero (ne_of_gt hx1), NNReal.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 (le_of_lt hz)] #align ennreal.one_le_rpow_of_pos_of_le_one_of_neg ENNReal.one_le_rpow_of_pos_of_le_one_of_neg theorem toNNReal_rpow (x : ℝ≥0∞) (z : ℝ) : x.toNNReal ^ z = (x ^ z).toNNReal := by rcases lt_trichotomy z 0 with (H | H | H) · cases' x with x · simp [H, ne_of_lt] by_cases hx : x = 0 · simp [hx, H, ne_of_lt] · simp [coe_rpow_of_ne_zero hx] · simp [H] · cases x · simp [H, ne_of_gt] simp [coe_rpow_of_nonneg _ (le_of_lt H)] #align ennreal.to_nnreal_rpow ENNReal.toNNReal_rpow theorem toReal_rpow (x : ℝ≥0∞) (z : ℝ) : x.toReal ^ z = (x ^ z).toReal := by rw [ENNReal.toReal, ENNReal.toReal, ← NNReal.coe_rpow, ENNReal.toNNReal_rpow] #align ennreal.to_real_rpow ENNReal.toReal_rpow theorem ofReal_rpow_of_pos {x p : ℝ} (hx_pos : 0 < x) : ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by simp_rw [ENNReal.ofReal] rw [coe_rpow_of_ne_zero, coe_inj, Real.toNNReal_rpow_of_nonneg hx_pos.le] simp [hx_pos] #align ennreal.of_real_rpow_of_pos ENNReal.ofReal_rpow_of_pos
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
879
888
theorem ofReal_rpow_of_nonneg {x p : ℝ} (hx_nonneg : 0 ≤ x) (hp_nonneg : 0 ≤ p) : ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by
by_cases hp0 : p = 0 · simp [hp0] by_cases hx0 : x = 0 · rw [← Ne] at hp0 have hp_pos : 0 < p := lt_of_le_of_ne hp_nonneg hp0.symm simp [hx0, hp_pos, hp_pos.ne.symm] rw [← Ne] at hx0 exact ofReal_rpow_of_pos (hx_nonneg.lt_of_ne hx0.symm)
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Finset.Fold import Mathlib.Algebra.GCDMonoid.Multiset #align_import algebra.gcd_monoid.finset from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" #align_import algebra.gcd_monoid.div from "leanprover-community/mathlib"@"b537794f8409bc9598febb79cd510b1df5f4539d" /-! # GCD and LCM operations on finsets ## Main definitions - `Finset.gcd` - the greatest common denominator of a `Finset` of elements of a `GCDMonoid` - `Finset.lcm` - the least common multiple of a `Finset` of elements of a `GCDMonoid` ## Implementation notes Many of the proofs use the lemmas `gcd_def` and `lcm_def`, which relate `Finset.gcd` and `Finset.lcm` to `Multiset.gcd` and `Multiset.lcm`. TODO: simplify with a tactic and `Data.Finset.Lattice` ## Tags finset, gcd -/ variable {ι α β γ : Type*} namespace Finset open Multiset variable [CancelCommMonoidWithZero α] [NormalizedGCDMonoid α] /-! ### lcm -/ section lcm /-- Least common multiple of a finite set -/ def lcm (s : Finset β) (f : β → α) : α := s.fold GCDMonoid.lcm 1 f #align finset.lcm Finset.lcm variable {s s₁ s₂ : Finset β} {f : β → α} theorem lcm_def : s.lcm f = (s.1.map f).lcm := rfl #align finset.lcm_def Finset.lcm_def @[simp] theorem lcm_empty : (∅ : Finset β).lcm f = 1 := fold_empty #align finset.lcm_empty Finset.lcm_empty @[simp] theorem lcm_dvd_iff {a : α} : s.lcm f ∣ a ↔ ∀ b ∈ s, f b ∣ a := by apply Iff.trans Multiset.lcm_dvd simp only [Multiset.mem_map, and_imp, exists_imp] exact ⟨fun k b hb ↦ k _ _ hb rfl, fun k a' b hb h ↦ h ▸ k _ hb⟩ #align finset.lcm_dvd_iff Finset.lcm_dvd_iff theorem lcm_dvd {a : α} : (∀ b ∈ s, f b ∣ a) → s.lcm f ∣ a := lcm_dvd_iff.2 #align finset.lcm_dvd Finset.lcm_dvd theorem dvd_lcm {b : β} (hb : b ∈ s) : f b ∣ s.lcm f := lcm_dvd_iff.1 dvd_rfl _ hb #align finset.dvd_lcm Finset.dvd_lcm @[simp]
Mathlib/Algebra/GCDMonoid/Finset.lean
77
82
theorem lcm_insert [DecidableEq β] {b : β} : (insert b s : Finset β).lcm f = GCDMonoid.lcm (f b) (s.lcm f) := by
by_cases h : b ∈ s · rw [insert_eq_of_mem h, (lcm_eq_right_iff (f b) (s.lcm f) (Multiset.normalize_lcm (s.1.map f))).2 (dvd_lcm h)] apply fold_insert h
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.Defs import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content #align_import field_theory.ratfunc from "leanprover-community/mathlib"@"bf9bbbcf0c1c1ead18280b0d010e417b10abb1b6" /-! # The field structure of rational functions ## Main definitions Working with rational functions as polynomials: - `RatFunc.instField` provides a field structure You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials: * `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions * `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`, in particular: * `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`. Working with rational functions as fractions: - `RatFunc.num` and `RatFunc.denom` give the numerator and denominator. These values are chosen to be coprime and such that `RatFunc.denom` is monic. Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long as the homomorphism retains the non-zero-divisor property: - `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]` - `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`, where `[CommRing K] [Field L]` - `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`, where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]` This is satisfied by injective homs. We also have lifting homomorphisms of polynomials to other polynomials, with the same condition on retaining the non-zero-divisor property across the map: - `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when `[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]` -/ universe u v noncomputable section open scoped Classical open scoped nonZeroDivisors Polynomial variable {K : Type u} namespace RatFunc section Field variable [CommRing K] /-- The zero rational function. -/ protected irreducible_def zero : RatFunc K := ⟨0⟩ #align ratfunc.zero RatFunc.zero instance : Zero (RatFunc K) := ⟨RatFunc.zero⟩ -- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [zero_def]` -- that does not close the goal theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := by simp only [Zero.zero, OfNat.ofNat, RatFunc.zero] #align ratfunc.of_fraction_ring_zero RatFunc.ofFractionRing_zero /-- Addition of rational functions. -/ protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p + q⟩ #align ratfunc.add RatFunc.add instance : Add (RatFunc K) := ⟨RatFunc.add⟩ -- Porting note: added `HAdd.hAdd`. using `simp?` produces `simp only [add_def]` -- that does not close the goal theorem ofFractionRing_add (p q : FractionRing K[X]) : ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := by simp only [HAdd.hAdd, Add.add, RatFunc.add] #align ratfunc.of_fraction_ring_add RatFunc.ofFractionRing_add /-- Subtraction of rational functions. -/ protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p - q⟩ #align ratfunc.sub RatFunc.sub instance : Sub (RatFunc K) := ⟨RatFunc.sub⟩ -- Porting note: added `HSub.hSub`. using `simp?` produces `simp only [sub_def]` -- that does not close the goal theorem ofFractionRing_sub (p q : FractionRing K[X]) : ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := by simp only [Sub.sub, HSub.hSub, RatFunc.sub] #align ratfunc.of_fraction_ring_sub RatFunc.ofFractionRing_sub /-- Additive inverse of a rational function. -/ protected irreducible_def neg : RatFunc K → RatFunc K | ⟨p⟩ => ⟨-p⟩ #align ratfunc.neg RatFunc.neg instance : Neg (RatFunc K) := ⟨RatFunc.neg⟩ theorem ofFractionRing_neg (p : FractionRing K[X]) : ofFractionRing (-p) = -ofFractionRing p := by simp only [Neg.neg, RatFunc.neg] #align ratfunc.of_fraction_ring_neg RatFunc.ofFractionRing_neg /-- The multiplicative unit of rational functions. -/ protected irreducible_def one : RatFunc K := ⟨1⟩ #align ratfunc.one RatFunc.one instance : One (RatFunc K) := ⟨RatFunc.one⟩ -- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [one_def]` -- that does not close the goal theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := by simp only [One.one, OfNat.ofNat, RatFunc.one] #align ratfunc.of_fraction_ring_one RatFunc.ofFractionRing_one /-- Multiplication of rational functions. -/ protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p * q⟩ #align ratfunc.mul RatFunc.mul instance : Mul (RatFunc K) := ⟨RatFunc.mul⟩ -- Porting note: added `HMul.hMul`. using `simp?` produces `simp only [mul_def]` -- that does not close the goal theorem ofFractionRing_mul (p q : FractionRing K[X]) : ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := by simp only [Mul.mul, HMul.hMul, RatFunc.mul] #align ratfunc.of_fraction_ring_mul RatFunc.ofFractionRing_mul section IsDomain variable [IsDomain K] /-- Division of rational functions. -/ protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p / q⟩ #align ratfunc.div RatFunc.div instance : Div (RatFunc K) := ⟨RatFunc.div⟩ -- Porting note: added `HDiv.hDiv`. using `simp?` produces `simp only [div_def]` -- that does not close the goal theorem ofFractionRing_div (p q : FractionRing K[X]) : ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := by simp only [Div.div, HDiv.hDiv, RatFunc.div] #align ratfunc.of_fraction_ring_div RatFunc.ofFractionRing_div /-- Multiplicative inverse of a rational function. -/ protected irreducible_def inv : RatFunc K → RatFunc K | ⟨p⟩ => ⟨p⁻¹⟩ #align ratfunc.inv RatFunc.inv instance : Inv (RatFunc K) := ⟨RatFunc.inv⟩
Mathlib/FieldTheory/RatFunc/Basic.lean
177
179
theorem ofFractionRing_inv (p : FractionRing K[X]) : ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := by
simp only [Inv.inv, RatFunc.inv]
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.Single #align_import algebra.homology.augment from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Augmentation and truncation of `ℕ`-indexed (co)chain complexes. -/ noncomputable section open CategoryTheory Limits HomologicalComplex universe v u variable {V : Type u} [Category.{v} V] namespace ChainComplex /-- The truncation of an `ℕ`-indexed chain complex, deleting the object at `0` and shifting everything else down. -/ @[simps] def truncate [HasZeroMorphisms V] : ChainComplex V ℕ ⥤ ChainComplex V ℕ where obj C := { X := fun i => C.X (i + 1) d := fun i j => C.d (i + 1) (j + 1) shape := fun i j w => C.shape _ _ <| by simpa } map f := { f := fun i => f.f (i + 1) } #align chain_complex.truncate ChainComplex.truncate /-- There is a canonical chain map from the truncation of a chain map `C` to the "single object" chain complex consisting of the truncated object `C.X 0` in degree 0. The components of this chain map are `C.d 1 0` in degree 0, and zero otherwise. -/ def truncateTo [HasZeroObject V] [HasZeroMorphisms V] (C : ChainComplex V ℕ) : truncate.obj C ⟶ (single₀ V).obj (C.X 0) := (toSingle₀Equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 1 0, by aesop⟩ #align chain_complex.truncate_to ChainComplex.truncateTo -- PROJECT when `V` is abelian (but not generally?) -- `[∀ n, Exact (C.d (n+2) (n+1)) (C.d (n+1) n)] [Epi (C.d 1 0)]` iff `QuasiIso (C.truncate_to)` variable [HasZeroMorphisms V] /-- We can "augment" a chain complex by inserting an arbitrary object in degree zero (shifting everything else up), along with a suitable differential. -/ def augment (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : ChainComplex V ℕ where X | 0 => X | i + 1 => C.X i d | 1, 0 => f | i + 1, j + 1 => C.d i j | _, _ => 0 shape | 1, 0, h => absurd rfl h | i + 2, 0, _ => rfl | 0, _, _ => rfl | i + 1, j + 1, h => by simp only; exact C.shape i j (Nat.succ_ne_succ.1 h) d_comp_d' | _, _, 0, rfl, rfl => w | _, _, k + 1, rfl, rfl => C.d_comp_d _ _ _ #align chain_complex.augment ChainComplex.augment @[simp] theorem augment_X_zero (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : (augment C f w).X 0 = X := rfl set_option linter.uppercaseLean3 false in #align chain_complex.augment_X_zero ChainComplex.augment_X_zero @[simp] theorem augment_X_succ (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) : (augment C f w).X (i + 1) = C.X i := rfl set_option linter.uppercaseLean3 false in #align chain_complex.augment_X_succ ChainComplex.augment_X_succ @[simp] theorem augment_d_one_zero (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : (augment C f w).d 1 0 = f := rfl #align chain_complex.augment_d_one_zero ChainComplex.augment_d_one_zero @[simp] theorem augment_d_succ_succ (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i j : ℕ) : (augment C f w).d (i + 1) (j + 1) = C.d i j := by cases i <;> rfl #align chain_complex.augment_d_succ_succ ChainComplex.augment_d_succ_succ /-- Truncating an augmented chain complex is isomorphic (with components the identity) to the original complex. -/ def truncateAugment (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : truncate.obj (augment C f w) ≅ C where hom := { f := fun i => 𝟙 _ } inv := { f := fun i => 𝟙 _ comm' := fun i j => by cases j <;> · dsimp simp } hom_inv_id := by ext (_ | i) <;> · dsimp simp inv_hom_id := by ext (_ | i) <;> · dsimp simp #align chain_complex.truncate_augment ChainComplex.truncateAugment @[simp] theorem truncateAugment_hom_f (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) : (truncateAugment C f w).hom.f i = 𝟙 (C.X i) := rfl #align chain_complex.truncate_augment_hom_f ChainComplex.truncateAugment_hom_f @[simp] theorem truncateAugment_inv_f (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) : (truncateAugment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) := rfl #align chain_complex.truncate_augment_inv_f ChainComplex.truncateAugment_inv_f @[simp] theorem chainComplex_d_succ_succ_zero (C : ChainComplex V ℕ) (i : ℕ) : C.d (i + 2) 0 = 0 := by rw [C.shape] exact i.succ_succ_ne_one.symm #align chain_complex.chain_complex_d_succ_succ_zero ChainComplex.chainComplex_d_succ_succ_zero /-- Augmenting a truncated complex with the original object and morphism is isomorphic (with components the identity) to the original complex. -/ def augmentTruncate (C : ChainComplex V ℕ) : augment (truncate.obj C) (C.d 1 0) (C.d_comp_d _ _ _) ≅ C where hom := { f := fun | 0 => 𝟙 _ | n+1 => 𝟙 _ comm' := fun i j => by -- Porting note: was an rcases n with (_|_|n) but that was causing issues match i with | 0 | 1 | n+2 => cases' j with j <;> dsimp [augment, truncate] <;> simp } inv := { f := fun | 0 => 𝟙 _ | n+1 => 𝟙 _ comm' := fun i j => by -- Porting note: was an rcases n with (_|_|n) but that was causing issues match i with | 0 | 1 | n+2 => cases' j with j <;> dsimp [augment, truncate] <;> simp } hom_inv_id := by ext i cases i <;> · dsimp simp inv_hom_id := by ext i cases i <;> · dsimp simp #align chain_complex.augment_truncate ChainComplex.augmentTruncate @[simp] theorem augmentTruncate_hom_f_zero (C : ChainComplex V ℕ) : (augmentTruncate C).hom.f 0 = 𝟙 (C.X 0) := rfl #align chain_complex.augment_truncate_hom_f_zero ChainComplex.augmentTruncate_hom_f_zero @[simp] theorem augmentTruncate_hom_f_succ (C : ChainComplex V ℕ) (i : ℕ) : (augmentTruncate C).hom.f (i + 1) = 𝟙 (C.X (i + 1)) := rfl #align chain_complex.augment_truncate_hom_f_succ ChainComplex.augmentTruncate_hom_f_succ @[simp] theorem augmentTruncate_inv_f_zero (C : ChainComplex V ℕ) : (augmentTruncate C).inv.f 0 = 𝟙 (C.X 0) := rfl #align chain_complex.augment_truncate_inv_f_zero ChainComplex.augmentTruncate_inv_f_zero @[simp] theorem augmentTruncate_inv_f_succ (C : ChainComplex V ℕ) (i : ℕ) : (augmentTruncate C).inv.f (i + 1) = 𝟙 (C.X (i + 1)) := rfl #align chain_complex.augment_truncate_inv_f_succ ChainComplex.augmentTruncate_inv_f_succ /-- A chain map from a chain complex to a single object chain complex in degree zero can be reinterpreted as a chain complex. This is the inverse construction of `truncateTo`. -/ def toSingle₀AsComplex [HasZeroObject V] (C : ChainComplex V ℕ) (X : V) (f : C ⟶ (single₀ V).obj X) : ChainComplex V ℕ := let ⟨f, w⟩ := toSingle₀Equiv C X f augment C f w #align chain_complex.to_single₀_as_complex ChainComplex.toSingle₀AsComplex end ChainComplex namespace CochainComplex /-- The truncation of an `ℕ`-indexed cochain complex, deleting the object at `0` and shifting everything else down. -/ @[simps] def truncate [HasZeroMorphisms V] : CochainComplex V ℕ ⥤ CochainComplex V ℕ where obj C := { X := fun i => C.X (i + 1) d := fun i j => C.d (i + 1) (j + 1) shape := fun i j w => by apply C.shape simpa } map f := { f := fun i => f.f (i + 1) } #align cochain_complex.truncate CochainComplex.truncate /-- There is a canonical chain map from the truncation of a cochain complex `C` to the "single object" cochain complex consisting of the truncated object `C.X 0` in degree 0. The components of this chain map are `C.d 0 1` in degree 0, and zero otherwise. -/ def toTruncate [HasZeroObject V] [HasZeroMorphisms V] (C : CochainComplex V ℕ) : (single₀ V).obj (C.X 0) ⟶ truncate.obj C := (fromSingle₀Equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 0 1, by aesop⟩ #align cochain_complex.to_truncate CochainComplex.toTruncate variable [HasZeroMorphisms V] /-- We can "augment" a cochain complex by inserting an arbitrary object in degree zero (shifting everything else up), along with a suitable differential. -/ def augment (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : CochainComplex V ℕ where X | 0 => X | i + 1 => C.X i d | 0, 1 => f | i + 1, j + 1 => C.d i j | _, _ => 0 shape i j s := by simp? at s says simp only [ComplexShape.up_Rel] at s rcases j with (_ | _ | j) <;> cases i <;> try simp · contradiction · rw [C.shape] simp only [ComplexShape.up_Rel] contrapose! s rw [← s] d_comp_d' i j k hij hjk := by rcases k with (_ | _ | k) <;> rcases j with (_ | _ | j) <;> cases i <;> try simp cases k · exact w · rw [C.shape, comp_zero] simp only [Nat.zero_eq, ComplexShape.up_Rel, zero_add] exact (Nat.one_lt_succ_succ _).ne #align cochain_complex.augment CochainComplex.augment @[simp] theorem augment_X_zero (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : (augment C f w).X 0 = X := rfl set_option linter.uppercaseLean3 false in #align cochain_complex.augment_X_zero CochainComplex.augment_X_zero @[simp] theorem augment_X_succ (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) : (augment C f w).X (i + 1) = C.X i := rfl set_option linter.uppercaseLean3 false in #align cochain_complex.augment_X_succ CochainComplex.augment_X_succ @[simp] theorem augment_d_zero_one (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : (augment C f w).d 0 1 = f := rfl #align cochain_complex.augment_d_zero_one CochainComplex.augment_d_zero_one @[simp] theorem augment_d_succ_succ (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i j : ℕ) : (augment C f w).d (i + 1) (j + 1) = C.d i j := rfl #align cochain_complex.augment_d_succ_succ CochainComplex.augment_d_succ_succ /-- Truncating an augmented cochain complex is isomorphic (with components the identity) to the original complex. -/ def truncateAugment (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : truncate.obj (augment C f w) ≅ C where hom := { f := fun i => 𝟙 _ } inv := { f := fun i => 𝟙 _ comm' := fun i j => by cases j <;> · dsimp simp } hom_inv_id := by ext i cases i <;> · dsimp simp inv_hom_id := by ext i cases i <;> · dsimp simp #align cochain_complex.truncate_augment CochainComplex.truncateAugment @[simp] theorem truncateAugment_hom_f (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) : (truncateAugment C f w).hom.f i = 𝟙 (C.X i) := rfl #align cochain_complex.truncate_augment_hom_f CochainComplex.truncateAugment_hom_f @[simp] theorem truncateAugment_inv_f (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) : (truncateAugment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) := rfl #align cochain_complex.truncate_augment_inv_f CochainComplex.truncateAugment_inv_f @[simp]
Mathlib/Algebra/Homology/Augment.lean
325
328
theorem cochainComplex_d_succ_succ_zero (C : CochainComplex V ℕ) (i : ℕ) : C.d 0 (i + 2) = 0 := by
rw [C.shape] simp only [ComplexShape.up_Rel, zero_add] exact (Nat.one_lt_succ_succ _).ne
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots import Mathlib.NumberTheory.NumberField.Discriminant #align_import number_theory.cyclotomic.discriminant from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Discriminant of cyclotomic fields We compute the discriminant of a `p ^ n`-th cyclotomic extension. ## Main results * `IsCyclotomicExtension.discr_odd_prime` : if `p` is an odd prime such that `IsCyclotomicExtension {p} K L` and `Irreducible (cyclotomic p K)`, then `discr K (hζ.powerBasis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2)` for any `hζ : IsPrimitiveRoot ζ p`. -/ universe u v open Algebra Polynomial Nat IsPrimitiveRoot PowerBasis open scoped Polynomial Cyclotomic namespace IsPrimitiveRoot variable {n : ℕ+} {K : Type u} [Field K] [CharZero K] {ζ : K} variable [ce : IsCyclotomicExtension {n} ℚ K] /-- The discriminant of the power basis given by a primitive root of unity `ζ` is the same as the discriminant of the power basis given by `ζ - 1`. -/ theorem discr_zeta_eq_discr_zeta_sub_one (hζ : IsPrimitiveRoot ζ n) : discr ℚ (hζ.powerBasis ℚ).basis = discr ℚ (hζ.subOnePowerBasis ℚ).basis := by haveI : NumberField K := @NumberField.mk _ _ _ (IsCyclotomicExtension.finiteDimensional {n} ℚ K) have H₁ : (aeval (hζ.powerBasis ℚ).gen) (X - 1 : ℤ[X]) = (hζ.subOnePowerBasis ℚ).gen := by simp have H₂ : (aeval (hζ.subOnePowerBasis ℚ).gen) (X + 1 : ℤ[X]) = (hζ.powerBasis ℚ).gen := by simp refine discr_eq_discr_of_toMatrix_coeff_isIntegral _ (fun i j => toMatrix_isIntegral H₁ ?_ ?_ _ _) fun i j => toMatrix_isIntegral H₂ ?_ ?_ _ _ · exact hζ.isIntegral n.pos · refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) (hζ.isIntegral n.pos) · exact (hζ.isIntegral n.pos).sub isIntegral_one · refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) ?_ exact (hζ.isIntegral n.pos).sub isIntegral_one #align is_primitive_root.discr_zeta_eq_discr_zeta_sub_one IsPrimitiveRoot.discr_zeta_eq_discr_zeta_sub_one end IsPrimitiveRoot namespace IsCyclotomicExtension variable {p : ℕ+} {k : ℕ} {K : Type u} {L : Type v} {ζ : L} [Field K] [Field L] variable [Algebra K L] set_option tactic.skipAssignedInstances false in /-- If `p` is a prime and `IsCyclotomicExtension {p ^ (k + 1)} K L`, then the discriminant of `hζ.powerBasis K` is `(-1) ^ ((p ^ (k + 1).totient) / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1))` if `Irreducible (cyclotomic (p ^ (k + 1)) K))`, and `p ^ (k + 1) ≠ 2`. -/ theorem discr_prime_pow_ne_two [IsCyclotomicExtension {p ^ (k + 1)} K L] [hp : Fact (p : ℕ).Prime] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (hk : p ^ (k + 1) ≠ 2) : discr K (hζ.powerBasis K).basis = (-1) ^ ((p ^ (k + 1) : ℕ).totient / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by haveI hne := IsCyclotomicExtension.neZero' (p ^ (k + 1)) K L -- Porting note: these two instances are not automatically synthesised and must be constructed haveI mf : Module.Finite K L := finiteDimensional {p ^ (k + 1)} K L haveI se : IsSeparable K L := (isGalois (p ^ (k + 1)) K L).to_isSeparable rw [discr_powerBasis_eq_norm, finrank L hirr, hζ.powerBasis_gen _, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, PNat.pow_coe, totient_prime_pow hp.out (succ_pos k), Nat.add_one_sub_one] have coe_two : ((2 : ℕ+) : ℕ) = 2 := rfl have hp2 : p = 2 → k ≠ 0 := by rintro rfl rfl exact absurd rfl hk congr 1 · rcases eq_or_ne p 2 with (rfl | hp2) · rcases Nat.exists_eq_succ_of_ne_zero (hp2 rfl) with ⟨k, rfl⟩ rw [coe_two, succ_sub_succ_eq_sub, tsub_zero, mul_one]; simp only [_root_.pow_succ'] rw [mul_assoc, Nat.mul_div_cancel_left _ zero_lt_two, Nat.mul_div_cancel_left _ zero_lt_two] cases k · simp · simp_rw [_root_.pow_succ', (even_two.mul_right _).neg_one_pow, ((even_two.mul_right _).mul_right _).neg_one_pow] · replace hp2 : (p : ℕ) ≠ 2 := by rwa [Ne, ← coe_two, PNat.coe_inj] have hpo : Odd (p : ℕ) := hp.out.odd_of_ne_two hp2 obtain ⟨a, ha⟩ := (hp.out.even_sub_one hp2).two_dvd rw [ha, mul_left_comm, mul_assoc, Nat.mul_div_cancel_left _ two_pos, Nat.mul_div_cancel_left _ two_pos, mul_right_comm, pow_mul, (hpo.pow.mul _).neg_one_pow, pow_mul, hpo.pow.neg_one_pow] refine Nat.Even.sub_odd ?_ (even_two_mul _) odd_one rw [mul_left_comm, ← ha] exact one_le_mul (one_le_pow _ _ hp.1.pos) (succ_le_iff.2 <| tsub_pos_of_lt hp.1.one_lt) · have H := congr_arg (@derivative K _) (cyclotomic_prime_pow_mul_X_pow_sub_one K p k) rw [derivative_mul, derivative_sub, derivative_one, sub_zero, derivative_X_pow, C_eq_natCast, derivative_sub, derivative_one, sub_zero, derivative_X_pow, C_eq_natCast, ← PNat.pow_coe, hζ.minpoly_eq_cyclotomic_of_irreducible hirr] at H replace H := congr_arg (fun P => aeval ζ P) H simp only [aeval_add, aeval_mul, minpoly.aeval, zero_mul, add_zero, aeval_natCast, _root_.map_sub, aeval_one, aeval_X_pow] at H replace H := congr_arg (Algebra.norm K) H have hnorm : (norm K) (ζ ^ (p : ℕ) ^ k - 1) = (p : K) ^ (p : ℕ) ^ k := by by_cases hp : p = 2 · exact mod_cast hζ.norm_pow_sub_one_eq_prime_pow_of_ne_zero hirr le_rfl (hp2 hp) · exact mod_cast hζ.norm_pow_sub_one_of_prime_ne_two hirr le_rfl hp rw [MonoidHom.map_mul, hnorm, MonoidHom.map_mul, ← map_natCast (algebraMap K L), Algebra.norm_algebraMap, finrank L hirr] at H conv_rhs at H => -- Porting note: need to drill down to successfully rewrite the totient enter [1, 2] rw [PNat.pow_coe, ← succ_eq_add_one, totient_prime_pow hp.out (succ_pos k), Nat.sub_one, Nat.pred_succ] rw [← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_pow, hζ.norm_eq_one hk hirr, one_pow, mul_one, PNat.pow_coe, cast_pow, ← pow_mul, ← mul_assoc, mul_comm (k + 1), mul_assoc] at H have := mul_pos (succ_pos k) (tsub_pos_of_lt hp.out.one_lt) rw [← succ_pred_eq_of_pos this, mul_succ, pow_add _ _ ((p : ℕ) ^ k)] at H replace H := (mul_left_inj' fun h => ?_).1 H · simp only [H, mul_comm _ (k + 1)]; norm_cast · -- Porting note: was `replace h := pow_eq_zero h; rw [coe_coe] at h; simpa using hne.1` have := hne.1 rw [PNat.pow_coe, Nat.cast_pow, Ne, pow_eq_zero_iff (by omega)] at this exact absurd (pow_eq_zero h) this #align is_cyclotomic_extension.discr_prime_pow_ne_two IsCyclotomicExtension.discr_prime_pow_ne_two /-- If `p` is a prime and `IsCyclotomicExtension {p ^ (k + 1)} K L`, then the discriminant of `hζ.powerBasis K` is `(-1) ^ (p ^ k * (p - 1) / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1))` if `Irreducible (cyclotomic (p ^ (k + 1)) K))`, and `p ^ (k + 1) ≠ 2`. -/ theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} K L] [hp : Fact (p : ℕ).Prime] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (hk : p ^ (k + 1) ≠ 2) : discr K (hζ.powerBasis K).basis = (-1) ^ ((p : ℕ) ^ k * (p - 1) / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by simpa [totient_prime_pow hp.out (succ_pos k)] using discr_prime_pow_ne_two hζ hirr hk #align is_cyclotomic_extension.discr_prime_pow_ne_two' IsCyclotomicExtension.discr_prime_pow_ne_two' set_option tactic.skipAssignedInstances false in /-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then the discriminant of `hζ.powerBasis K` is `(-1) ^ ((p ^ k).totient / 2) * p ^ (p ^ (k - 1) * ((p - 1) * k - 1))` if `Irreducible (cyclotomic (p ^ k) K))`. Beware that in the cases `p ^ k = 1` and `p ^ k = 2` the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform result. See also `IsCyclotomicExtension.discr_prime_pow_eq_unit_mul_pow`. -/ theorem discr_prime_pow [hcycl : IsCyclotomicExtension {p ^ k} K L] [hp : Fact (p : ℕ).Prime] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) (hirr : Irreducible (cyclotomic (↑(p ^ k) : ℕ) K)) : discr K (hζ.powerBasis K).basis = (-1) ^ ((p ^ k : ℕ).totient / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) := by cases' k with k k · simp only [coe_basis, _root_.pow_zero, powerBasis_gen _ hζ, totient_one, mul_zero, mul_one, show 1 / 2 = 0 by rfl, discr, traceMatrix] have hζone : ζ = 1 := by simpa using hζ rw [hζ.powerBasis_dim _, hζone, ← (algebraMap K L).map_one, minpoly.eq_X_sub_C_of_algebraMap_inj _ (algebraMap K L).injective, natDegree_X_sub_C] simp only [traceMatrix, map_one, one_pow, Matrix.det_unique, traceForm_apply, mul_one] rw [← (algebraMap K L).map_one, trace_algebraMap, finrank _ hirr] norm_num · by_cases hk : p ^ (k + 1) = 2 · have coe_two : 2 = ((2 : ℕ+) : ℕ) := rfl have hp : p = 2 := by rw [← PNat.coe_inj, PNat.pow_coe, ← pow_one 2] at hk replace hk := eq_of_prime_pow_eq (prime_iff.1 hp.out) (prime_iff.1 Nat.prime_two) (succ_pos _) hk rwa [coe_two, PNat.coe_inj] at hk subst hp rw [← PNat.coe_inj, PNat.pow_coe] at hk nth_rw 2 [← pow_one 2] at hk replace hk := Nat.pow_right_injective rfl.le hk rw [add_left_eq_self] at hk subst hk rw [pow_one] at hζ hcycl have : natDegree (minpoly K ζ) = 1 := by rw [hζ.eq_neg_one_of_two_right, show (-1 : L) = algebraMap K L (-1) by simp, minpoly.eq_X_sub_C_of_algebraMap_inj _ (NoZeroSMulDivisors.algebraMap_injective K L)] exact natDegree_X_sub_C (-1) rcases Fin.equiv_iff_eq.2 this with ⟨e⟩ rw [← Algebra.discr_reindex K (hζ.powerBasis K).basis e, coe_basis, powerBasis_gen]; norm_num simp_rw [hζ.eq_neg_one_of_two_right, show (-1 : L) = algebraMap K L (-1) by simp] convert_to (discr K fun i : Fin 1 ↦ (algebraMap K L) (-1) ^ ↑i) = _ · congr ext i simp only [map_neg, map_one, Function.comp_apply, Fin.coe_fin_one, _root_.pow_zero] suffices (e.symm i : ℕ) = 0 by simp [this] rw [← Nat.lt_one_iff] convert (e.symm i).2 rw [this] · simp only [discr, traceMatrix_apply, Matrix.det_unique, Fin.default_eq_zero, Fin.val_zero, _root_.pow_zero, traceForm_apply, mul_one] rw [← (algebraMap K L).map_one, trace_algebraMap, finrank _ hirr]; norm_num · exact discr_prime_pow_ne_two hζ hirr hk #align is_cyclotomic_extension.discr_prime_pow IsCyclotomicExtension.discr_prime_pow set_option tactic.skipAssignedInstances false in /-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then there are `u : ℤˣ` and `n : ℕ` such that the discriminant of `hζ.powerBasis K` is `u * p ^ n`. Often this is enough and less cumbersome to use than `IsCyclotomicExtension.discr_prime_pow`. -/ theorem discr_prime_pow_eq_unit_mul_pow [IsCyclotomicExtension {p ^ k} K L] [hp : Fact (p : ℕ).Prime] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) (hirr : Irreducible (cyclotomic (↑(p ^ k) : ℕ) K)) : ∃ (u : ℤˣ) (n : ℕ), discr K (hζ.powerBasis K).basis = u * p ^ n := by rw [discr_prime_pow hζ hirr] by_cases heven : Even ((p ^ k : ℕ).totient / 2) · exact ⟨1, (p : ℕ) ^ (k - 1) * ((p - 1) * k - 1), by rw [heven.neg_one_pow]; norm_num⟩ · exact ⟨-1, (p : ℕ) ^ (k - 1) * ((p - 1) * k - 1), by rw [(odd_iff_not_even.2 heven).neg_one_pow]; norm_num⟩ #align is_cyclotomic_extension.discr_prime_pow_eq_unit_mul_pow IsCyclotomicExtension.discr_prime_pow_eq_unit_mul_pow /-- If `p` is an odd prime and `IsCyclotomicExtension {p} K L`, then `discr K (hζ.powerBasis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2)` if `Irreducible (cyclotomic p K)`. -/
Mathlib/NumberTheory/Cyclotomic/Discriminant.lean
207
216
theorem discr_odd_prime [IsCyclotomicExtension {p} K L] [hp : Fact (p : ℕ).Prime] (hζ : IsPrimitiveRoot ζ p) (hirr : Irreducible (cyclotomic p K)) (hodd : p ≠ 2) : discr K (hζ.powerBasis K).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by
have : IsCyclotomicExtension {p ^ (0 + 1)} K L := by rw [zero_add, pow_one] infer_instance have hζ' : IsPrimitiveRoot ζ (p ^ (0 + 1) :) := by simpa using hζ convert discr_prime_pow_ne_two hζ' (by simpa [hirr]) (by simp [hodd]) using 2 · rw [zero_add, pow_one, totient_prime hp.out] · rw [_root_.pow_zero, one_mul, zero_add, mul_one, Nat.sub_sub]
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.MeasureTheory.Function.ConditionalExpectation.Unique import Mathlib.MeasureTheory.Function.L2Space #align_import measure_theory.function.conditional_expectation.condexp_L2 from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Conditional expectation in L2 This file contains one step of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. We build the conditional expectation of an `L²` function, as an element of `L²`. This is the orthogonal projection on the subspace of almost everywhere `m`-measurable functions. ## Main definitions * `condexpL2`: Conditional expectation of a function in L2 with respect to a sigma-algebra: it is the orthogonal projection on the subspace `lpMeas`. ## Implementation notes Most of the results in this file are valid for a complete real normed space `F`. However, some lemmas also use `𝕜 : RCLike`: * `condexpL2` is defined only for an `InnerProductSpace` for now, and we use `𝕜` for its field. * results about scalar multiplication are stated not only for `ℝ` but also for `𝕜` if we happen to have `NormedSpace 𝕜 F`. -/ set_option linter.uppercaseLean3 false open TopologicalSpace Filter ContinuousLinearMap open scoped ENNReal Topology MeasureTheory namespace MeasureTheory variable {α E E' F G G' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- E for an inner product space [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E] -- E' for an inner product space on which we compute integrals [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [CompleteSpace E'] [NormedSpace ℝ E'] -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y local notation "⟪" x ", " y "⟫₂" => @inner 𝕜 (α →₂[μ] E) _ x y -- Porting note: the argument `E` of `condexpL2` is not automatically filled in Lean 4. -- To avoid typing `(E := _)` every time it is made explicit. variable (E 𝕜) /-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/ noncomputable def condexpL2 (hm : m ≤ m0) : (α →₂[μ] E) →L[𝕜] lpMeas E 𝕜 m 2 μ := @orthogonalProjection 𝕜 (α →₂[μ] E) _ _ _ (lpMeas E 𝕜 m 2 μ) haveI : Fact (m ≤ m0) := ⟨hm⟩ inferInstance #align measure_theory.condexp_L2 MeasureTheory.condexpL2 variable {E 𝕜} theorem aeStronglyMeasurable'_condexpL2 (hm : m ≤ m0) (f : α →₂[μ] E) : AEStronglyMeasurable' (β := E) m (condexpL2 E 𝕜 hm f) μ := lpMeas.aeStronglyMeasurable' _ #align measure_theory.ae_strongly_measurable'_condexp_L2 MeasureTheory.aeStronglyMeasurable'_condexpL2 theorem integrableOn_condexpL2_of_measure_ne_top (hm : m ≤ m0) (hμs : μ s ≠ ∞) (f : α →₂[μ] E) : IntegrableOn (E := E) (condexpL2 E 𝕜 hm f) s μ := integrableOn_Lp_of_measure_ne_top (condexpL2 E 𝕜 hm f : α →₂[μ] E) fact_one_le_two_ennreal.elim hμs #align measure_theory.integrable_on_condexp_L2_of_measure_ne_top MeasureTheory.integrableOn_condexpL2_of_measure_ne_top theorem integrable_condexpL2_of_isFiniteMeasure (hm : m ≤ m0) [IsFiniteMeasure μ] {f : α →₂[μ] E} : Integrable (β := E) (condexpL2 E 𝕜 hm f) μ := integrableOn_univ.mp <| integrableOn_condexpL2_of_measure_ne_top hm (measure_ne_top _ _) f #align measure_theory.integrable_condexp_L2_of_is_finite_measure MeasureTheory.integrable_condexpL2_of_isFiniteMeasure theorem norm_condexpL2_le_one (hm : m ≤ m0) : ‖@condexpL2 α E 𝕜 _ _ _ _ _ _ μ hm‖ ≤ 1 := haveI : Fact (m ≤ m0) := ⟨hm⟩ orthogonalProjection_norm_le _ #align measure_theory.norm_condexp_L2_le_one MeasureTheory.norm_condexpL2_le_one theorem norm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖condexpL2 E 𝕜 hm f‖ ≤ ‖f‖ := ((@condexpL2 _ E 𝕜 _ _ _ _ _ _ μ hm).le_opNorm f).trans (mul_le_of_le_one_left (norm_nonneg _) (norm_condexpL2_le_one hm)) #align measure_theory.norm_condexp_L2_le MeasureTheory.norm_condexpL2_le theorem snorm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : snorm (F := E) (condexpL2 E 𝕜 hm f) 2 μ ≤ snorm f 2 μ := by rw [lpMeas_coe, ← ENNReal.toReal_le_toReal (Lp.snorm_ne_top _) (Lp.snorm_ne_top _), ← Lp.norm_def, ← Lp.norm_def, Submodule.norm_coe] exact norm_condexpL2_le hm f #align measure_theory.snorm_condexp_L2_le MeasureTheory.snorm_condexpL2_le theorem norm_condexpL2_coe_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖(condexpL2 E 𝕜 hm f : α →₂[μ] E)‖ ≤ ‖f‖ := by rw [Lp.norm_def, Lp.norm_def, ← lpMeas_coe] refine (ENNReal.toReal_le_toReal ?_ (Lp.snorm_ne_top _)).mpr (snorm_condexpL2_le hm f) exact Lp.snorm_ne_top _ #align measure_theory.norm_condexp_L2_coe_le MeasureTheory.norm_condexpL2_coe_le theorem inner_condexpL2_left_eq_right (hm : m ≤ m0) {f g : α →₂[μ] E} : ⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, (condexpL2 E 𝕜 hm g : α →₂[μ] E)⟫₂ := haveI : Fact (m ≤ m0) := ⟨hm⟩ inner_orthogonalProjection_left_eq_right _ f g #align measure_theory.inner_condexp_L2_left_eq_right MeasureTheory.inner_condexpL2_left_eq_right theorem condexpL2_indicator_of_measurable (hm : m ≤ m0) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (c : E) : (condexpL2 E 𝕜 hm (indicatorConstLp 2 (hm s hs) hμs c) : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := by rw [condexpL2] haveI : Fact (m ≤ m0) := ⟨hm⟩ have h_mem : indicatorConstLp 2 (hm s hs) hμs c ∈ lpMeas E 𝕜 m 2 μ := mem_lpMeas_indicatorConstLp hm hs hμs let ind := (⟨indicatorConstLp 2 (hm s hs) hμs c, h_mem⟩ : lpMeas E 𝕜 m 2 μ) have h_coe_ind : (ind : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := rfl have h_orth_mem := orthogonalProjection_mem_subspace_eq_self ind rw [← h_coe_ind, h_orth_mem] #align measure_theory.condexp_L2_indicator_of_measurable MeasureTheory.condexpL2_indicator_of_measurable theorem inner_condexpL2_eq_inner_fun (hm : m ≤ m0) (f g : α →₂[μ] E) (hg : AEStronglyMeasurable' m g μ) : ⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, g⟫₂ := by symm rw [← sub_eq_zero, ← inner_sub_left, condexpL2] simp only [mem_lpMeas_iff_aeStronglyMeasurable'.mpr hg, orthogonalProjection_inner_eq_zero f g] #align measure_theory.inner_condexp_L2_eq_inner_fun MeasureTheory.inner_condexpL2_eq_inner_fun section Real variable {hm : m ≤ m0} theorem integral_condexpL2_eq_of_fin_meas_real (f : Lp 𝕜 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = ∫ x in s, f x ∂μ := by rw [← L2.inner_indicatorConstLp_one (𝕜 := 𝕜) (hm s hs) hμs f] have h_eq_inner : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = inner (indicatorConstLp 2 (hm s hs) hμs (1 : 𝕜)) (condexpL2 𝕜 𝕜 hm f) := by rw [L2.inner_indicatorConstLp_one (hm s hs) hμs] rw [h_eq_inner, ← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable hm hs hμs] #align measure_theory.integral_condexp_L2_eq_of_fin_meas_real MeasureTheory.integral_condexpL2_eq_of_fin_meas_real theorem lintegral_nnnorm_condexpL2_le (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (f : Lp ℝ 2 μ) : ∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ ≤ ∫⁻ x in s, ‖f x‖₊ ∂μ := by let h_meas := lpMeas.aeStronglyMeasurable' (condexpL2 ℝ ℝ hm f) let g := h_meas.choose have hg_meas : StronglyMeasurable[m] g := h_meas.choose_spec.1 have hg_eq : g =ᵐ[μ] condexpL2 ℝ ℝ hm f := h_meas.choose_spec.2.symm have hg_eq_restrict : g =ᵐ[μ.restrict s] condexpL2 ℝ ℝ hm f := ae_restrict_of_ae hg_eq have hg_nnnorm_eq : (fun x => (‖g x‖₊ : ℝ≥0∞)) =ᵐ[μ.restrict s] fun x => (‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ : ℝ≥0∞) := by refine hg_eq_restrict.mono fun x hx => ?_ dsimp only simp_rw [hx] rw [lintegral_congr_ae hg_nnnorm_eq.symm] refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm (Lp.stronglyMeasurable f) ?_ ?_ ?_ ?_ hs hμs · exact integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs · exact hg_meas · rw [IntegrableOn, integrable_congr hg_eq_restrict] exact integrableOn_condexpL2_of_measure_ne_top hm hμs f · intro t ht hμt rw [← integral_condexpL2_eq_of_fin_meas_real f ht hμt.ne] exact setIntegral_congr_ae (hm t ht) (hg_eq.mono fun x hx _ => hx) #align measure_theory.lintegral_nnnorm_condexp_L2_le MeasureTheory.lintegral_nnnorm_condexpL2_le theorem condexpL2_ae_eq_zero_of_ae_eq_zero (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) {f : Lp ℝ 2 μ} (hf : f =ᵐ[μ.restrict s] 0) : condexpL2 ℝ ℝ hm f =ᵐ[μ.restrict s] (0 : α → ℝ) := by suffices h_nnnorm_eq_zero : ∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ = 0 by rw [lintegral_eq_zero_iff] at h_nnnorm_eq_zero · refine h_nnnorm_eq_zero.mono fun x hx => ?_ dsimp only at hx rw [Pi.zero_apply] at hx ⊢ · rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] at hx · refine Measurable.coe_nnreal_ennreal (Measurable.nnnorm ?_) rw [lpMeas_coe] exact (Lp.stronglyMeasurable _).measurable refine le_antisymm ?_ (zero_le _) refine (lintegral_nnnorm_condexpL2_le hs hμs f).trans (le_of_eq ?_) rw [lintegral_eq_zero_iff] · refine hf.mono fun x hx => ?_ dsimp only rw [hx] simp · exact (Lp.stronglyMeasurable _).ennnorm #align measure_theory.condexp_L2_ae_eq_zero_of_ae_eq_zero MeasureTheory.condexpL2_ae_eq_zero_of_ae_eq_zero theorem lintegral_nnnorm_condexpL2_indicator_le_real (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ ≤ μ (s ∩ t) := by refine (lintegral_nnnorm_condexpL2_le ht hμt _).trans (le_of_eq ?_) have h_eq : ∫⁻ x in t, ‖(indicatorConstLp 2 hs hμs (1 : ℝ)) x‖₊ ∂μ = ∫⁻ x in t, s.indicator (fun _ => (1 : ℝ≥0∞)) x ∂μ := by refine lintegral_congr_ae (ae_restrict_of_ae ?_) refine (@indicatorConstLp_coeFn _ _ _ 2 _ _ _ hs hμs (1 : ℝ)).mono fun x hx => ?_ dsimp only rw [hx] classical simp_rw [Set.indicator_apply] split_ifs <;> simp rw [h_eq, lintegral_indicator _ hs, lintegral_const, Measure.restrict_restrict hs] simp only [one_mul, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply] #align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le_real MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le_real end Real /-- `condexpL2` commutes with taking inner products with constants. See the lemma `condexpL2_comp_continuousLinearMap` for a more general result about commuting with continuous linear maps. -/ theorem condexpL2_const_inner (hm : m ≤ m0) (f : Lp E 2 μ) (c : E) : condexpL2 𝕜 𝕜 hm (((Lp.memℒp f).const_inner c).toLp fun a => ⟪c, f a⟫) =ᵐ[μ] fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ := by rw [lpMeas_coe] have h_mem_Lp : Memℒp (fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫) 2 μ := by refine Memℒp.const_inner _ ?_; rw [lpMeas_coe]; exact Lp.memℒp _ have h_eq : h_mem_Lp.toLp _ =ᵐ[μ] fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ := h_mem_Lp.coeFn_toLp refine EventuallyEq.trans ?_ h_eq refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜 hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) ?_ ?_ ?_ ?_ · intro s _ hμs rw [IntegrableOn, integrable_congr (ae_restrict_of_ae h_eq)] exact (integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _).const_inner _ · intro s hs hμs rw [← lpMeas_coe, integral_condexpL2_eq_of_fin_meas_real _ hs hμs.ne, integral_congr_ae (ae_restrict_of_ae h_eq), lpMeas_coe, ← L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 (↑(condexpL2 E 𝕜 hm f)) (hm s hs) c hμs.ne, ← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable _ hs, L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 f (hm s hs) c hμs.ne, setIntegral_congr_ae (hm s hs) ((Memℒp.coeFn_toLp ((Lp.memℒp f).const_inner c)).mono fun x hx _ => hx)] · rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _ · refine AEStronglyMeasurable'.congr ?_ h_eq.symm exact (lpMeas.aeStronglyMeasurable' _).const_inner _ #align measure_theory.condexp_L2_const_inner MeasureTheory.condexpL2_const_inner /-- `condexpL2` verifies the equality of integrals defining the conditional expectation. -/ theorem integral_condexpL2_eq (hm : m ≤ m0) (f : Lp E' 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 E' 𝕜 hm f : α → E') x ∂μ = ∫ x in s, f x ∂μ := by rw [← sub_eq_zero, lpMeas_coe, ← integral_sub' (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs) (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)] refine integral_eq_zero_of_forall_integral_inner_eq_zero 𝕜 _ ?_ ?_ · rw [integrable_congr (ae_restrict_of_ae (Lp.coeFn_sub (↑(condexpL2 E' 𝕜 hm f)) f).symm)] exact integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs intro c simp_rw [Pi.sub_apply, inner_sub_right] rw [integral_sub ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c) ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c)] have h_ae_eq_f := Memℒp.coeFn_toLp (E := 𝕜) ((Lp.memℒp f).const_inner c) rw [← lpMeas_coe, sub_eq_zero, ← setIntegral_congr_ae (hm s hs) ((condexpL2_const_inner hm f c).mono fun x hx _ => hx), ← setIntegral_congr_ae (hm s hs) (h_ae_eq_f.mono fun x hx _ => hx)] exact integral_condexpL2_eq_of_fin_meas_real _ hs hμs #align measure_theory.integral_condexp_L2_eq MeasureTheory.integral_condexpL2_eq variable {E'' 𝕜' : Type*} [RCLike 𝕜'] [NormedAddCommGroup E''] [InnerProductSpace 𝕜' E''] [CompleteSpace E''] [NormedSpace ℝ E''] variable (𝕜 𝕜') theorem condexpL2_comp_continuousLinearMap (hm : m ≤ m0) (T : E' →L[ℝ] E'') (f : α →₂[μ] E') : (condexpL2 E'' 𝕜' hm (T.compLp f) : α →₂[μ] E'') =ᵐ[μ] T.compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E') := by refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜' hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) (fun s _ hμs => integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne) ?_ ?_ ?_ · intro s hs hμs rw [T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne), ← lpMeas_coe, ← lpMeas_coe, integral_condexpL2_eq hm f hs hμs.ne, integral_condexpL2_eq hm (T.compLp f) hs hμs.ne, T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs.ne)] · rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _ · have h_coe := T.coeFn_compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E') rw [← EventuallyEq] at h_coe refine AEStronglyMeasurable'.congr ?_ h_coe.symm exact (lpMeas.aeStronglyMeasurable' (condexpL2 E' 𝕜 hm f)).continuous_comp T.continuous #align measure_theory.condexp_L2_comp_continuous_linear_map MeasureTheory.condexpL2_comp_continuousLinearMap variable {𝕜 𝕜'} section CondexpL2Indicator variable (𝕜) theorem condexpL2_indicator_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) =ᵐ[μ] fun a => (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ)) : α → ℝ) a • x := by rw [indicatorConstLp_eq_toSpanSingleton_compLp hs hμs x] have h_comp := condexpL2_comp_continuousLinearMap ℝ 𝕜 hm (toSpanSingleton ℝ x) (indicatorConstLp 2 hs hμs (1 : ℝ)) rw [← lpMeas_coe] at h_comp refine h_comp.trans ?_ exact (toSpanSingleton ℝ x).coeFn_compLp _ #align measure_theory.condexp_L2_indicator_ae_eq_smul MeasureTheory.condexpL2_indicator_ae_eq_smul theorem condexpL2_indicator_eq_toSpanSingleton_comp (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α →₂[μ] E') = (toSpanSingleton ℝ x).compLp (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) := by ext1 rw [← lpMeas_coe] refine (condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).trans ?_ have h_comp := (toSpanSingleton ℝ x).coeFn_compLp (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α →₂[μ] ℝ) rw [← EventuallyEq] at h_comp refine EventuallyEq.trans ?_ h_comp.symm filter_upwards with y using rfl #align measure_theory.condexp_L2_indicator_eq_to_span_singleton_comp MeasureTheory.condexpL2_indicator_eq_toSpanSingleton_comp variable {𝕜} theorem set_lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ (s ∩ t) * ‖x‖₊ := calc ∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ = ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ := set_lintegral_congr_fun (hm t ht) ((condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).mono fun a ha _ => by rw [ha]) _ = (∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by simp_rw [nnnorm_smul, ENNReal.coe_mul] rw [lintegral_mul_const, lpMeas_coe] exact (Lp.stronglyMeasurable _).ennnorm _ ≤ μ (s ∩ t) * ‖x‖₊ := mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs hμs ht hμt) _ #align measure_theory.set_lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.set_lintegral_nnnorm_condexpL2_indicator_le theorem lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) ?_ fun t ht hμt => ?_ · rw [lpMeas_coe] exact (Lp.aestronglyMeasurable _).ennnorm refine (set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le /-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set with finite measure is integrable. -/
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL2.lean
367
376
theorem integrable_condexpL2_indicator (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : Integrable (β := E') (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x)) μ := by
refine integrable_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) (ENNReal.mul_lt_top hμs ENNReal.coe_ne_top) ?_ ?_ · rw [lpMeas_coe]; exact Lp.aestronglyMeasurable _ · refine fun t ht hμt => (set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Tactic.Ring import Mathlib.Data.PNat.Prime #align_import data.pnat.xgcd from "leanprover-community/mathlib"@"6afc9b06856ad973f6a2619e3e8a0a8d537a58f2" /-! # Euclidean algorithm for ℕ This file sets up a version of the Euclidean algorithm that only works with natural numbers. Given `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold: * `a = (w + x) d` * `b = (y + z) d` * `w * z = x * y + 1` `d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime. This story is closely related to the structure of SL₂(ℕ) (as a free monoid on two generators) and the theory of continued fractions. ## Main declarations * `XgcdType`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp` `zp`, `ap`, `bp` are the variables getting changed through the algorithm. * `IsSpecial`: States `wp * zp = x * y + 1` * `IsReduced`: States `ap = a ∧ bp = b` ## Notes See `Nat.Xgcd` for a very similar algorithm allowing values in `ℤ`. -/ open Nat namespace PNat /-- A term of `XgcdType` is a system of six naturals. They should be thought of as representing the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] together with the vector [a, b] = [ap + 1, bp + 1]. -/ structure XgcdType where /-- `wp` is a variable which changes through the algorithm. -/ wp : ℕ /-- `x` satisfies `a / d = w + x` at the final step. -/ x : ℕ /-- `y` satisfies `b / d = z + y` at the final step. -/ y : ℕ /-- `zp` is a variable which changes through the algorithm. -/ zp : ℕ /-- `ap` is a variable which changes through the algorithm. -/ ap : ℕ /-- `bp` is a variable which changes through the algorithm. -/ bp : ℕ deriving Inhabited #align pnat.xgcd_type PNat.XgcdType namespace XgcdType variable (u : XgcdType) instance : SizeOf XgcdType := ⟨fun u => u.bp⟩ /-- The `Repr` instance converts terms to strings in a way that reflects the matrix/vector interpretation as above. -/ instance : Repr XgcdType where reprPrec | g, _ => s!"[[[{repr (g.wp + 1)}, {repr g.x}], \ [{repr g.y}, {repr (g.zp + 1)}]], \ [{repr (g.ap + 1)}, {repr (g.bp + 1)}]]" /-- Another `mk` using ℕ and ℕ+ -/ def mk' (w : ℕ+) (x : ℕ) (y : ℕ) (z : ℕ+) (a : ℕ+) (b : ℕ+) : XgcdType := mk w.val.pred x y z.val.pred a.val.pred b.val.pred #align pnat.xgcd_type.mk' PNat.XgcdType.mk' /-- `w = wp + 1` -/ def w : ℕ+ := succPNat u.wp #align pnat.xgcd_type.w PNat.XgcdType.w /-- `z = zp + 1` -/ def z : ℕ+ := succPNat u.zp #align pnat.xgcd_type.z PNat.XgcdType.z /-- `a = ap + 1` -/ def a : ℕ+ := succPNat u.ap #align pnat.xgcd_type.a PNat.XgcdType.a /-- `b = bp + 1` -/ def b : ℕ+ := succPNat u.bp #align pnat.xgcd_type.b PNat.XgcdType.b /-- `r = a % b`: remainder -/ def r : ℕ := (u.ap + 1) % (u.bp + 1) #align pnat.xgcd_type.r PNat.XgcdType.r /-- `q = ap / bp`: quotient -/ def q : ℕ := (u.ap + 1) / (u.bp + 1) #align pnat.xgcd_type.q PNat.XgcdType.q /-- `qp = q - 1` -/ def qp : ℕ := u.q - 1 #align pnat.xgcd_type.qp PNat.XgcdType.qp /-- The map `v` gives the product of the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] and the vector [a, b] = [ap + 1, bp + 1]. The map `vp` gives [sp, tp] such that v = [sp + 1, tp + 1]. -/ def vp : ℕ × ℕ := ⟨u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp, u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp⟩ #align pnat.xgcd_type.vp PNat.XgcdType.vp /-- `v = [sp + 1, tp + 1]`, check `vp` -/ def v : ℕ × ℕ := ⟨u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.b⟩ #align pnat.xgcd_type.v PNat.XgcdType.v /-- `succ₂ [t.1, t.2] = [t.1.succ, t.2.succ]` -/ def succ₂ (t : ℕ × ℕ) : ℕ × ℕ := ⟨t.1.succ, t.2.succ⟩ #align pnat.xgcd_type.succ₂ PNat.XgcdType.succ₂ theorem v_eq_succ_vp : u.v = succ₂ u.vp := by ext <;> dsimp [v, vp, w, z, a, b, succ₂] <;> ring_nf #align pnat.xgcd_type.v_eq_succ_vp PNat.XgcdType.v_eq_succ_vp /-- `IsSpecial` holds if the matrix has determinant one. -/ def IsSpecial : Prop := u.wp + u.zp + u.wp * u.zp = u.x * u.y #align pnat.xgcd_type.is_special PNat.XgcdType.IsSpecial /-- `IsSpecial'` is an alternative of `IsSpecial`. -/ def IsSpecial' : Prop := u.w * u.z = succPNat (u.x * u.y) #align pnat.xgcd_type.is_special' PNat.XgcdType.IsSpecial' theorem isSpecial_iff : u.IsSpecial ↔ u.IsSpecial' := by dsimp [IsSpecial, IsSpecial'] let ⟨wp, x, y, zp, ap, bp⟩ := u constructor <;> intro h <;> simp [w, z, succPNat] at * <;> simp only [← coe_inj, mul_coe, mk_coe] at * · simp_all [← h, Nat.mul, Nat.succ_eq_add_one]; ring · simp [Nat.succ_eq_add_one, Nat.mul_add, Nat.add_mul, ← Nat.add_assoc] at h; rw [← h]; ring -- Porting note: Old code has been removed as it was much more longer. #align pnat.xgcd_type.is_special_iff PNat.XgcdType.isSpecial_iff /-- `IsReduced` holds if the two entries in the vector are the same. The reduction algorithm will produce a system with this property, whose product vector is the same as for the original system. -/ def IsReduced : Prop := u.ap = u.bp #align pnat.xgcd_type.is_reduced PNat.XgcdType.IsReduced /-- `IsReduced'` is an alternative of `IsReduced`. -/ def IsReduced' : Prop := u.a = u.b #align pnat.xgcd_type.is_reduced' PNat.XgcdType.IsReduced' theorem isReduced_iff : u.IsReduced ↔ u.IsReduced' := succPNat_inj.symm #align pnat.xgcd_type.is_reduced_iff PNat.XgcdType.isReduced_iff /-- `flip` flips the placement of variables during the algorithm. -/ def flip : XgcdType where wp := u.zp x := u.y y := u.x zp := u.wp ap := u.bp bp := u.ap #align pnat.xgcd_type.flip PNat.XgcdType.flip @[simp] theorem flip_w : (flip u).w = u.z := rfl #align pnat.xgcd_type.flip_w PNat.XgcdType.flip_w @[simp] theorem flip_x : (flip u).x = u.y := rfl #align pnat.xgcd_type.flip_x PNat.XgcdType.flip_x @[simp] theorem flip_y : (flip u).y = u.x := rfl #align pnat.xgcd_type.flip_y PNat.XgcdType.flip_y @[simp] theorem flip_z : (flip u).z = u.w := rfl #align pnat.xgcd_type.flip_z PNat.XgcdType.flip_z @[simp] theorem flip_a : (flip u).a = u.b := rfl #align pnat.xgcd_type.flip_a PNat.XgcdType.flip_a @[simp] theorem flip_b : (flip u).b = u.a := rfl #align pnat.xgcd_type.flip_b PNat.XgcdType.flip_b theorem flip_isReduced : (flip u).IsReduced ↔ u.IsReduced := by dsimp [IsReduced, flip] constructor <;> intro h <;> exact h.symm #align pnat.xgcd_type.flip_is_reduced PNat.XgcdType.flip_isReduced theorem flip_isSpecial : (flip u).IsSpecial ↔ u.IsSpecial := by dsimp [IsSpecial, flip] rw [mul_comm u.x, mul_comm u.zp, add_comm u.zp] #align pnat.xgcd_type.flip_is_special PNat.XgcdType.flip_isSpecial theorem flip_v : (flip u).v = u.v.swap := by dsimp [v] ext · simp only ring · simp only ring #align pnat.xgcd_type.flip_v PNat.XgcdType.flip_v /-- Properties of division with remainder for a / b. -/ theorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 := Nat.mod_add_div (u.ap + 1) (u.bp + 1) #align pnat.xgcd_type.rq_eq PNat.XgcdType.rq_eq
Mathlib/Data/PNat/Xgcd.lean
241
246
theorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 := by
by_cases hq : u.q = 0 · let h := u.rq_eq rw [hr, hq, mul_zero, add_zero] at h cases h · exact (Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hq)).symm
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.Group.ConjFinite import Mathlib.GroupTheory.Abelianization import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.GroupTheory.GroupAction.Quotient import Mathlib.GroupTheory.Index import Mathlib.GroupTheory.SpecificGroups.Dihedral import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Qify #align_import group_theory.commuting_probability from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Commuting Probability This file introduces the commuting probability of finite groups. ## Main definitions * `commProb`: The commuting probability of a finite type with a multiplication operation. ## Todo * Neumann's theorem. -/ noncomputable section open scoped Classical open Fintype variable (M : Type*) [Mul M] /-- The commuting probability of a finite type with a multiplication operation. -/ def commProb : ℚ := Nat.card { p : M × M // Commute p.1 p.2 } / (Nat.card M : ℚ) ^ 2 #align comm_prob commProb theorem commProb_def : commProb M = Nat.card { p : M × M // Commute p.1 p.2 } / (Nat.card M : ℚ) ^ 2 := rfl #align comm_prob_def commProb_def theorem commProb_prod (M' : Type*) [Mul M'] : commProb (M × M') = commProb M * commProb M' := by simp_rw [commProb_def, div_mul_div_comm, Nat.card_prod, Nat.cast_mul, mul_pow, ← Nat.cast_mul, ← Nat.card_prod, Commute, SemiconjBy, Prod.ext_iff] congr 2 exact Nat.card_congr ⟨fun x => ⟨⟨⟨x.1.1.1, x.1.2.1⟩, x.2.1⟩, ⟨⟨x.1.1.2, x.1.2.2⟩, x.2.2⟩⟩, fun x => ⟨⟨⟨x.1.1.1, x.2.1.1⟩, ⟨x.1.1.2, x.2.1.2⟩⟩, ⟨x.1.2, x.2.2⟩⟩, fun x => rfl, fun x => rfl⟩ theorem commProb_pi {α : Type*} (i : α → Type*) [Fintype α] [∀ a, Mul (i a)] : commProb (∀ a, i a) = ∏ a, commProb (i a) := by simp_rw [commProb_def, Finset.prod_div_distrib, Finset.prod_pow, ← Nat.cast_prod, ← Nat.card_pi, Commute, SemiconjBy, Function.funext_iff] congr 2 exact Nat.card_congr ⟨fun x a => ⟨⟨x.1.1 a, x.1.2 a⟩, x.2 a⟩, fun x => ⟨⟨fun a => (x a).1.1, fun a => (x a).1.2⟩, fun a => (x a).2⟩, fun x => rfl, fun x => rfl⟩ theorem commProb_function {α β : Type*} [Fintype α] [Mul β] : commProb (α → β) = (commProb β) ^ Fintype.card α := by rw [commProb_pi, Finset.prod_const, Finset.card_univ] @[simp] theorem commProb_eq_zero_of_infinite [Infinite M] : commProb M = 0 := div_eq_zero_iff.2 (Or.inl (Nat.cast_eq_zero.2 Nat.card_eq_zero_of_infinite)) variable [Finite M] theorem commProb_pos [h : Nonempty M] : 0 < commProb M := h.elim fun x ↦ div_pos (Nat.cast_pos.mpr (Finite.card_pos_iff.mpr ⟨⟨(x, x), rfl⟩⟩)) (pow_pos (Nat.cast_pos.mpr Finite.card_pos) 2) #align comm_prob_pos commProb_pos
Mathlib/GroupTheory/CommutingProbability.lean
78
81
theorem commProb_le_one : commProb M ≤ 1 := by
refine div_le_one_of_le ?_ (sq_nonneg (Nat.card M : ℚ)) rw [← Nat.cast_pow, Nat.cast_le, sq, ← Nat.card_prod] apply Finite.card_subtype_le
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Group.Even import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.Group.Commute.Units import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Ring.Units #align_import algebra.associated from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Associated, prime, and irreducible elements. In this file we define the predicate `Prime p` saying that an element of a commutative monoid with zero is prime. Namely, `Prime p` means that `p` isn't zero, it isn't a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`; In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`, however this is not true in general. We also define an equivalence relation `Associated` saying that two elements of a monoid differ by a multiplication by a unit. Then we show that the quotient type `Associates` is a monoid and prove basic properties of this quotient. -/ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section Prime variable [CommMonoidWithZero α] /-- An element `p` of a commutative monoid with zero (e.g., a ring) is called *prime*, if it's not zero, not a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`. -/ def Prime (p : α) : Prop := p ≠ 0 ∧ ¬IsUnit p ∧ ∀ a b, p ∣ a * b → p ∣ a ∨ p ∣ b #align prime Prime namespace Prime variable {p : α} (hp : Prime p) theorem ne_zero : p ≠ 0 := hp.1 #align prime.ne_zero Prime.ne_zero theorem not_unit : ¬IsUnit p := hp.2.1 #align prime.not_unit Prime.not_unit theorem not_dvd_one : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align prime.not_dvd_one Prime.not_dvd_one theorem ne_one : p ≠ 1 := fun h => hp.2.1 (h.symm ▸ isUnit_one) #align prime.ne_one Prime.ne_one theorem dvd_or_dvd (hp : Prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := hp.2.2 a b h #align prime.dvd_or_dvd Prime.dvd_or_dvd theorem dvd_mul {a b : α} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b := ⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩ theorem isPrimal (hp : Prime p) : IsPrimal p := fun _a _b dvd ↦ (hp.dvd_or_dvd dvd).elim (fun h ↦ ⟨p, 1, h, one_dvd _, (mul_one p).symm⟩) fun h ↦ ⟨1, p, one_dvd _, h, (one_mul p).symm⟩ theorem not_dvd_mul {a b : α} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b := hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩ theorem dvd_of_dvd_pow (hp : Prime p) {a : α} {n : ℕ} (h : p ∣ a ^ n) : p ∣ a := by induction' n with n ih · rw [pow_zero] at h have := isUnit_of_dvd_one h have := not_unit hp contradiction rw [pow_succ'] at h cases' dvd_or_dvd hp h with dvd_a dvd_pow · assumption exact ih dvd_pow #align prime.dvd_of_dvd_pow Prime.dvd_of_dvd_pow theorem dvd_pow_iff_dvd {a : α} {n : ℕ} (hn : n ≠ 0) : p ∣ a ^ n ↔ p ∣ a := ⟨hp.dvd_of_dvd_pow, (dvd_pow · hn)⟩ end Prime @[simp] theorem not_prime_zero : ¬Prime (0 : α) := fun h => h.ne_zero rfl #align not_prime_zero not_prime_zero @[simp] theorem not_prime_one : ¬Prime (1 : α) := fun h => h.not_unit isUnit_one #align not_prime_one not_prime_one section Map variable [CommMonoidWithZero β] {F : Type*} {G : Type*} [FunLike F α β] variable [MonoidWithZeroHomClass F α β] [FunLike G β α] [MulHomClass G β α] variable (f : F) (g : G) {p : α} theorem comap_prime (hinv : ∀ a, g (f a : β) = a) (hp : Prime (f p)) : Prime p := ⟨fun h => hp.1 <| by simp [h], fun h => hp.2.1 <| h.map f, fun a b h => by refine (hp.2.2 (f a) (f b) <| by convert map_dvd f h simp).imp ?_ ?_ <;> · intro h convert ← map_dvd g h <;> apply hinv⟩ #align comap_prime comap_prime theorem MulEquiv.prime_iff (e : α ≃* β) : Prime p ↔ Prime (e p) := ⟨fun h => (comap_prime e.symm e fun a => by simp) <| (e.symm_apply_apply p).substr h, comap_prime e e.symm fun a => by simp⟩ #align mul_equiv.prime_iff MulEquiv.prime_iff end Map end Prime theorem Prime.left_dvd_or_dvd_right_of_dvd_mul [CancelCommMonoidWithZero α] {p : α} (hp : Prime p) {a b : α} : a ∣ p * b → p ∣ a ∨ a ∣ b := by rintro ⟨c, hc⟩ rcases hp.2.2 a c (hc ▸ dvd_mul_right _ _) with (h | ⟨x, rfl⟩) · exact Or.inl h · rw [mul_left_comm, mul_right_inj' hp.ne_zero] at hc exact Or.inr (hc.symm ▸ dvd_mul_right _ _) #align prime.left_dvd_or_dvd_right_of_dvd_mul Prime.left_dvd_or_dvd_right_of_dvd_mul theorem Prime.pow_dvd_of_dvd_mul_left [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ a) (h' : p ^ n ∣ a * b) : p ^ n ∣ b := by induction' n with n ih · rw [pow_zero] exact one_dvd b · obtain ⟨c, rfl⟩ := ih (dvd_trans (pow_dvd_pow p n.le_succ) h') rw [pow_succ] apply mul_dvd_mul_left _ ((hp.dvd_or_dvd _).resolve_left h) rwa [← mul_dvd_mul_iff_left (pow_ne_zero n hp.ne_zero), ← pow_succ, mul_left_comm] #align prime.pow_dvd_of_dvd_mul_left Prime.pow_dvd_of_dvd_mul_left theorem Prime.pow_dvd_of_dvd_mul_right [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ b) (h' : p ^ n ∣ a * b) : p ^ n ∣ a := by rw [mul_comm] at h' exact hp.pow_dvd_of_dvd_mul_left n h h' #align prime.pow_dvd_of_dvd_mul_right Prime.pow_dvd_of_dvd_mul_right
Mathlib/Algebra/Associated.lean
154
170
theorem Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd [CancelCommMonoidWithZero α] {p a b : α} {n : ℕ} (hp : Prime p) (hpow : p ^ n.succ ∣ a ^ n.succ * b ^ n) (hb : ¬p ^ 2 ∣ b) : p ∣ a := by
-- Suppose `p ∣ b`, write `b = p * x` and `hy : a ^ n.succ * b ^ n = p ^ n.succ * y`. cases' hp.dvd_or_dvd ((dvd_pow_self p (Nat.succ_ne_zero n)).trans hpow) with H hbdiv · exact hp.dvd_of_dvd_pow H obtain ⟨x, rfl⟩ := hp.dvd_of_dvd_pow hbdiv obtain ⟨y, hy⟩ := hpow -- Then we can divide out a common factor of `p ^ n` from the equation `hy`. have : a ^ n.succ * x ^ n = p * y := by refine mul_left_cancel₀ (pow_ne_zero n hp.ne_zero) ?_ rw [← mul_assoc _ p, ← pow_succ, ← hy, mul_pow, ← mul_assoc (a ^ n.succ), mul_comm _ (p ^ n), mul_assoc] -- So `p ∣ a` (and we're done) or `p ∣ x`, which can't be the case since it implies `p^2 ∣ b`. refine hp.dvd_of_dvd_pow ((hp.dvd_or_dvd ⟨_, this⟩).resolve_right fun hdvdx => hb ?_) obtain ⟨z, rfl⟩ := hp.dvd_of_dvd_pow hdvdx rw [pow_two, ← mul_assoc] exact dvd_mul_right _ _
/- 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.Topology.Order.MonotoneContinuity import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.Instances.NNReal import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Order.T5 #align_import topology.instances.ennreal from "leanprover-community/mathlib"@"ec4b2eeb50364487f80421c0b4c41328a611f30d" /-! # Topology on extended non-negative reals -/ noncomputable section open Set Filter Metric Function open scoped Classical Topology ENNReal NNReal Filter variable {α : Type*} {β : Type*} {γ : Type*} namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞} section TopologicalSpace open TopologicalSpace /-- Topology on `ℝ≥0∞`. Note: this is different from the `EMetricSpace` topology. The `EMetricSpace` topology has `IsOpen {∞}`, while this topology doesn't have singleton elements. -/ instance : TopologicalSpace ℝ≥0∞ := Preorder.topology ℝ≥0∞ instance : OrderTopology ℝ≥0∞ := ⟨rfl⟩ -- short-circuit type class inference instance : T2Space ℝ≥0∞ := inferInstance instance : T5Space ℝ≥0∞ := inferInstance instance : T4Space ℝ≥0∞ := inferInstance instance : SecondCountableTopology ℝ≥0∞ := orderIsoUnitIntervalBirational.toHomeomorph.embedding.secondCountableTopology instance : MetrizableSpace ENNReal := orderIsoUnitIntervalBirational.toHomeomorph.embedding.metrizableSpace theorem embedding_coe : Embedding ((↑) : ℝ≥0 → ℝ≥0∞) := coe_strictMono.embedding_of_ordConnected <| by rw [range_coe']; exact ordConnected_Iio #align ennreal.embedding_coe ENNReal.embedding_coe theorem isOpen_ne_top : IsOpen { a : ℝ≥0∞ | a ≠ ∞ } := isOpen_ne #align ennreal.is_open_ne_top ENNReal.isOpen_ne_top theorem isOpen_Ico_zero : IsOpen (Ico 0 b) := by rw [ENNReal.Ico_eq_Iio] exact isOpen_Iio #align ennreal.is_open_Ico_zero ENNReal.isOpen_Ico_zero theorem openEmbedding_coe : OpenEmbedding ((↑) : ℝ≥0 → ℝ≥0∞) := ⟨embedding_coe, by rw [range_coe']; exact isOpen_Iio⟩ #align ennreal.open_embedding_coe ENNReal.openEmbedding_coe theorem coe_range_mem_nhds : range ((↑) : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) := IsOpen.mem_nhds openEmbedding_coe.isOpen_range <| mem_range_self _ #align ennreal.coe_range_mem_nhds ENNReal.coe_range_mem_nhds @[norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {a : ℝ≥0} : Tendsto (fun a => (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm #align ennreal.tendsto_coe ENNReal.tendsto_coe theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ≥0∞) := embedding_coe.continuous #align ennreal.continuous_coe ENNReal.continuous_coe theorem continuous_coe_iff {α} [TopologicalSpace α] {f : α → ℝ≥0} : (Continuous fun a => (f a : ℝ≥0∞)) ↔ Continuous f := embedding_coe.continuous_iff.symm #align ennreal.continuous_coe_iff ENNReal.continuous_coe_iff theorem nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map (↑) := (openEmbedding_coe.map_nhds_eq r).symm #align ennreal.nhds_coe ENNReal.nhds_coe theorem tendsto_nhds_coe_iff {α : Type*} {l : Filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} : Tendsto f (𝓝 ↑x) l ↔ Tendsto (f ∘ (↑) : ℝ≥0 → α) (𝓝 x) l := by rw [nhds_coe, tendsto_map'_iff] #align ennreal.tendsto_nhds_coe_iff ENNReal.tendsto_nhds_coe_iff theorem continuousAt_coe_iff {α : Type*} [TopologicalSpace α] {x : ℝ≥0} {f : ℝ≥0∞ → α} : ContinuousAt f ↑x ↔ ContinuousAt (f ∘ (↑) : ℝ≥0 → α) x := tendsto_nhds_coe_iff #align ennreal.continuous_at_coe_iff ENNReal.continuousAt_coe_iff theorem nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map fun p : ℝ≥0 × ℝ≥0 => (↑p.1, ↑p.2) := ((openEmbedding_coe.prod openEmbedding_coe).map_nhds_eq (r, p)).symm #align ennreal.nhds_coe_coe ENNReal.nhds_coe_coe theorem continuous_ofReal : Continuous ENNReal.ofReal := (continuous_coe_iff.2 continuous_id).comp continuous_real_toNNReal #align ennreal.continuous_of_real ENNReal.continuous_ofReal theorem tendsto_ofReal {f : Filter α} {m : α → ℝ} {a : ℝ} (h : Tendsto m f (𝓝 a)) : Tendsto (fun a => ENNReal.ofReal (m a)) f (𝓝 (ENNReal.ofReal a)) := (continuous_ofReal.tendsto a).comp h #align ennreal.tendsto_of_real ENNReal.tendsto_ofReal theorem tendsto_toNNReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toNNReal (𝓝 a) (𝓝 a.toNNReal) := by lift a to ℝ≥0 using ha rw [nhds_coe, tendsto_map'_iff] exact tendsto_id #align ennreal.tendsto_to_nnreal ENNReal.tendsto_toNNReal theorem eventuallyEq_of_toReal_eventuallyEq {l : Filter α} {f g : α → ℝ≥0∞} (hfi : ∀ᶠ x in l, f x ≠ ∞) (hgi : ∀ᶠ x in l, g x ≠ ∞) (hfg : (fun x => (f x).toReal) =ᶠ[l] fun x => (g x).toReal) : f =ᶠ[l] g := by filter_upwards [hfi, hgi, hfg] with _ hfx hgx _ rwa [← ENNReal.toReal_eq_toReal hfx hgx] #align ennreal.eventually_eq_of_to_real_eventually_eq ENNReal.eventuallyEq_of_toReal_eventuallyEq theorem continuousOn_toNNReal : ContinuousOn ENNReal.toNNReal { a | a ≠ ∞ } := fun _a ha => ContinuousAt.continuousWithinAt (tendsto_toNNReal ha) #align ennreal.continuous_on_to_nnreal ENNReal.continuousOn_toNNReal theorem tendsto_toReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toReal (𝓝 a) (𝓝 a.toReal) := NNReal.tendsto_coe.2 <| tendsto_toNNReal ha #align ennreal.tendsto_to_real ENNReal.tendsto_toReal lemma continuousOn_toReal : ContinuousOn ENNReal.toReal { a | a ≠ ∞ } := NNReal.continuous_coe.comp_continuousOn continuousOn_toNNReal lemma continuousAt_toReal (hx : x ≠ ∞) : ContinuousAt ENNReal.toReal x := continuousOn_toReal.continuousAt (isOpen_ne_top.mem_nhds_iff.mpr hx) /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def neTopHomeomorphNNReal : { a | a ≠ ∞ } ≃ₜ ℝ≥0 where toEquiv := neTopEquivNNReal continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toNNReal continuous_invFun := continuous_coe.subtype_mk _ #align ennreal.ne_top_homeomorph_nnreal ENNReal.neTopHomeomorphNNReal /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def ltTopHomeomorphNNReal : { a | a < ∞ } ≃ₜ ℝ≥0 := by refine (Homeomorph.setCongr ?_).trans neTopHomeomorphNNReal simp only [mem_setOf_eq, lt_top_iff_ne_top] #align ennreal.lt_top_homeomorph_nnreal ENNReal.ltTopHomeomorphNNReal theorem nhds_top : 𝓝 ∞ = ⨅ (a) (_ : a ≠ ∞), 𝓟 (Ioi a) := nhds_top_order.trans <| by simp [lt_top_iff_ne_top, Ioi] #align ennreal.nhds_top ENNReal.nhds_top theorem nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi ↑r) := nhds_top.trans <| iInf_ne_top _ #align ennreal.nhds_top' ENNReal.nhds_top' theorem nhds_top_basis : (𝓝 ∞).HasBasis (fun a => a < ∞) fun a => Ioi a := _root_.nhds_top_basis #align ennreal.nhds_top_basis ENNReal.nhds_top_basis theorem tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a := by simp only [nhds_top', tendsto_iInf, tendsto_principal, mem_Ioi] #align ennreal.tendsto_nhds_top_iff_nnreal ENNReal.tendsto_nhds_top_iff_nnreal theorem tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a := tendsto_nhds_top_iff_nnreal.trans ⟨fun h n => by simpa only [ENNReal.coe_natCast] using h n, fun h x => let ⟨n, hn⟩ := exists_nat_gt x (h n).mono fun y => lt_trans <| by rwa [← ENNReal.coe_natCast, coe_lt_coe]⟩ #align ennreal.tendsto_nhds_top_iff_nat ENNReal.tendsto_nhds_top_iff_nat theorem tendsto_nhds_top {m : α → ℝ≥0∞} {f : Filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : Tendsto m f (𝓝 ∞) := tendsto_nhds_top_iff_nat.2 h #align ennreal.tendsto_nhds_top ENNReal.tendsto_nhds_top theorem tendsto_nat_nhds_top : Tendsto (fun n : ℕ => ↑n) atTop (𝓝 ∞) := tendsto_nhds_top fun n => mem_atTop_sets.2 ⟨n + 1, fun _m hm => mem_setOf.2 <| Nat.cast_lt.2 <| Nat.lt_of_succ_le hm⟩ #align ennreal.tendsto_nat_nhds_top ENNReal.tendsto_nat_nhds_top @[simp, norm_cast] theorem tendsto_coe_nhds_top {f : α → ℝ≥0} {l : Filter α} : Tendsto (fun x => (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ Tendsto f l atTop := by rw [tendsto_nhds_top_iff_nnreal, atTop_basis_Ioi.tendsto_right_iff]; simp #align ennreal.tendsto_coe_nhds_top ENNReal.tendsto_coe_nhds_top theorem tendsto_ofReal_atTop : Tendsto ENNReal.ofReal atTop (𝓝 ∞) := tendsto_coe_nhds_top.2 tendsto_real_toNNReal_atTop #align ennreal.tendsto_of_real_at_top ENNReal.tendsto_ofReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅ (a) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp [pos_iff_ne_zero, Iio] #align ennreal.nhds_zero ENNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) fun a => Iio a := nhds_bot_basis #align ennreal.nhds_zero_basis ENNReal.nhds_zero_basis theorem nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) Iic := nhds_bot_basis_Iic #align ennreal.nhds_zero_basis_Iic ENNReal.nhds_zero_basis_Iic -- Porting note (#11215): TODO: add a TC for `≠ ∞`? @[instance] theorem nhdsWithin_Ioi_coe_neBot {r : ℝ≥0} : (𝓝[>] (r : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_self_neBot' ⟨∞, ENNReal.coe_lt_top⟩ #align ennreal.nhds_within_Ioi_coe_ne_bot ENNReal.nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_zero_neBot : (𝓝[>] (0 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot #align ennreal.nhds_within_Ioi_zero_ne_bot ENNReal.nhdsWithin_Ioi_zero_neBot @[instance] theorem nhdsWithin_Ioi_one_neBot : (𝓝[>] (1 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_nat_neBot (n : ℕ) : (𝓝[>] (n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_ofNat_nebot (n : ℕ) [n.AtLeastTwo] : (𝓝[>] (OfNat.ofNat n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Iio_neBot [NeZero x] : (𝓝[<] x).NeBot := nhdsWithin_Iio_self_neBot' ⟨0, NeZero.pos x⟩ /-- Closed intervals `Set.Icc (x - ε) (x + ε)`, `ε ≠ 0`, form a basis of neighborhoods of an extended nonnegative real number `x ≠ ∞`. We use `Set.Icc` instead of `Set.Ioo` because this way the statement works for `x = 0`. -/ theorem hasBasis_nhds_of_ne_top' (xt : x ≠ ∞) : (𝓝 x).HasBasis (· ≠ 0) (fun ε => Icc (x - ε) (x + ε)) := by rcases (zero_le x).eq_or_gt with rfl | x0 · simp_rw [zero_tsub, zero_add, ← bot_eq_zero, Icc_bot, ← bot_lt_iff_ne_bot] exact nhds_bot_basis_Iic · refine (nhds_basis_Ioo' ⟨_, x0⟩ ⟨_, xt.lt_top⟩).to_hasBasis ?_ fun ε ε0 => ?_ · rintro ⟨a, b⟩ ⟨ha, hb⟩ rcases exists_between (tsub_pos_of_lt ha) with ⟨ε, ε0, hε⟩ rcases lt_iff_exists_add_pos_lt.1 hb with ⟨δ, δ0, hδ⟩ refine ⟨min ε δ, (lt_min ε0 (coe_pos.2 δ0)).ne', Icc_subset_Ioo ?_ ?_⟩ · exact lt_tsub_comm.2 ((min_le_left _ _).trans_lt hε) · exact (add_le_add_left (min_le_right _ _) _).trans_lt hδ · exact ⟨(x - ε, x + ε), ⟨ENNReal.sub_lt_self xt x0.ne' ε0, lt_add_right xt ε0⟩, Ioo_subset_Icc_self⟩ theorem hasBasis_nhds_of_ne_top (xt : x ≠ ∞) : (𝓝 x).HasBasis (0 < ·) (fun ε => Icc (x - ε) (x + ε)) := by simpa only [pos_iff_ne_zero] using hasBasis_nhds_of_ne_top' xt theorem Icc_mem_nhds (xt : x ≠ ∞) (ε0 : ε ≠ 0) : Icc (x - ε) (x + ε) ∈ 𝓝 x := (hasBasis_nhds_of_ne_top' xt).mem_of_mem ε0 #align ennreal.Icc_mem_nhds ENNReal.Icc_mem_nhds theorem nhds_of_ne_top (xt : x ≠ ∞) : 𝓝 x = ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) := (hasBasis_nhds_of_ne_top xt).eq_biInf #align ennreal.nhds_of_ne_top ENNReal.nhds_of_ne_top theorem biInf_le_nhds : ∀ x : ℝ≥0∞, ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) ≤ 𝓝 x | ∞ => iInf₂_le_of_le 1 one_pos <| by simpa only [← coe_one, top_sub_coe, top_add, Icc_self, principal_singleton] using pure_le_nhds _ | (x : ℝ≥0) => (nhds_of_ne_top coe_ne_top).ge -- Porting note (#10756): new lemma protected theorem tendsto_nhds_of_Icc {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε)) : Tendsto u f (𝓝 a) := by refine Tendsto.mono_right ?_ (biInf_le_nhds _) simpa only [tendsto_iInf, tendsto_principal] /-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_iInf, tendsto_principal] #align ennreal.tendsto_nhds ENNReal.tendsto_nhds protected theorem tendsto_nhds_zero {f : Filter α} {u : α → ℝ≥0∞} : Tendsto u f (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ≤ ε := nhds_zero_basis_Iic.tendsto_right_iff #align ennreal.tendsto_nhds_zero ENNReal.tendsto_nhds_zero protected theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto f atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ∈ Icc (a - ε) (a + ε) := .trans (atTop_basis.tendsto_iff (hasBasis_nhds_of_ne_top ha)) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top ENNReal.tendsto_atTop instance : ContinuousAdd ℝ≥0∞ := by refine ⟨continuous_iff_continuousAt.2 ?_⟩ rintro ⟨_ | a, b⟩ · exact tendsto_nhds_top_mono' continuousAt_fst fun p => le_add_right le_rfl rcases b with (_ | b) · exact tendsto_nhds_top_mono' continuousAt_snd fun p => le_add_left le_rfl simp only [ContinuousAt, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (· ∘ ·), tendsto_coe, tendsto_add] protected theorem tendsto_atTop_zero [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} : Tendsto f atTop (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε := .trans (atTop_basis.tendsto_iff nhds_zero_basis_Iic) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top_zero ENNReal.tendsto_atTop_zero theorem tendsto_sub : ∀ {a b : ℝ≥0∞}, (a ≠ ∞ ∨ b ≠ ∞) → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) (𝓝 (a, b)) (𝓝 (a - b)) | ∞, ∞, h => by simp only [ne_eq, not_true_eq_false, or_self] at h | ∞, (b : ℝ≥0), _ => by rw [top_sub_coe, tendsto_nhds_top_iff_nnreal] refine fun x => ((lt_mem_nhds <| @coe_lt_top (b + 1 + x)).prod_nhds (ge_mem_nhds <| coe_lt_coe.2 <| lt_add_one b)).mono fun y hy => ?_ rw [lt_tsub_iff_left] calc y.2 + x ≤ ↑(b + 1) + x := add_le_add_right hy.2 _ _ < y.1 := hy.1 | (a : ℝ≥0), ∞, _ => by rw [sub_top] refine (tendsto_pure.2 ?_).mono_right (pure_le_nhds _) exact ((gt_mem_nhds <| coe_lt_coe.2 <| lt_add_one a).prod_nhds (lt_mem_nhds <| @coe_lt_top (a + 1))).mono fun x hx => tsub_eq_zero_iff_le.2 (hx.1.trans hx.2).le | (a : ℝ≥0), (b : ℝ≥0), _ => by simp only [nhds_coe_coe, tendsto_map'_iff, ← ENNReal.coe_sub, (· ∘ ·), tendsto_coe] exact continuous_sub.tendsto (a, b) #align ennreal.tendsto_sub ENNReal.tendsto_sub protected theorem Tendsto.sub {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (hmb : Tendsto mb f (𝓝 b)) (h : a ≠ ∞ ∨ b ≠ ∞) : Tendsto (fun a => ma a - mb a) f (𝓝 (a - b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a - b)) from Tendsto.comp (ENNReal.tendsto_sub h) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.sub ENNReal.Tendsto.sub protected theorem tendsto_mul (ha : a ≠ 0 ∨ b ≠ ∞) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := by have ht : ∀ b : ℝ≥0∞, b ≠ 0 → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (∞, b)) (𝓝 ∞) := fun b hb => by refine tendsto_nhds_top_iff_nnreal.2 fun n => ?_ rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩ have : ∀ᶠ c : ℝ≥0∞ × ℝ≥0∞ in 𝓝 (∞, b), ↑n / ↑ε < c.1 ∧ ↑ε < c.2 := (lt_mem_nhds <| div_lt_top coe_ne_top hε.ne').prod_nhds (lt_mem_nhds hεb) refine this.mono fun c hc => ?_ exact (ENNReal.div_mul_cancel hε.ne' coe_ne_top).symm.trans_lt (mul_lt_mul hc.1 hc.2) induction a with | top => simp only [ne_eq, or_false, not_true_eq_false] at hb; simp [ht b hb, top_mul hb] | coe a => induction b with | top => simp only [ne_eq, or_false, not_true_eq_false] at ha simpa [(· ∘ ·), mul_comm, mul_top ha] using (ht a ha).comp (continuous_swap.tendsto (ofNNReal a, ∞)) | coe b => simp only [nhds_coe_coe, ← coe_mul, tendsto_coe, tendsto_map'_iff, (· ∘ ·), tendsto_mul] #align ennreal.tendsto_mul ENNReal.tendsto_mul protected theorem Tendsto.mul {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun a => ma a * mb a) f (𝓝 (a * b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a * b)) from Tendsto.comp (ENNReal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.mul ENNReal.Tendsto.mul theorem _root_.ContinuousOn.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₁ : ∀ x ∈ s, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x ∈ s, g x ≠ 0 ∨ f x ≠ ∞) : ContinuousOn (fun x => f x * g x) s := fun x hx => ENNReal.Tendsto.mul (hf x hx) (h₁ x hx) (hg x hx) (h₂ x hx) #align continuous_on.ennreal_mul ContinuousOn.ennreal_mul theorem _root_.Continuous.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} (hf : Continuous f) (hg : Continuous g) (h₁ : ∀ x, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x, g x ≠ 0 ∨ f x ≠ ∞) : Continuous fun x => f x * g x := continuous_iff_continuousAt.2 fun x => ENNReal.Tendsto.mul hf.continuousAt (h₁ x) hg.continuousAt (h₂ x) #align continuous.ennreal_mul Continuous.ennreal_mul protected theorem Tendsto.const_mul {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun b => a * m b) f (𝓝 (a * b)) := by_cases (fun (this : a = 0) => by simp [this, tendsto_const_nhds]) fun ha : a ≠ 0 => ENNReal.Tendsto.mul tendsto_const_nhds (Or.inl ha) hm hb #align ennreal.tendsto.const_mul ENNReal.Tendsto.const_mul protected theorem Tendsto.mul_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) : Tendsto (fun x => m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ENNReal.Tendsto.const_mul hm ha #align ennreal.tendsto.mul_const ENNReal.Tendsto.mul_const theorem tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : Filter α} {a : ι → ℝ≥0∞} (s : Finset ι) (h : ∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞) : Tendsto (fun b => ∏ c ∈ s, f c b) x (𝓝 (∏ c ∈ s, a c)) := by induction' s using Finset.induction with a s has IH · simp [tendsto_const_nhds] simp only [Finset.prod_insert has] apply Tendsto.mul (h _ (Finset.mem_insert_self _ _)) · right exact (prod_lt_top fun i hi => h' _ (Finset.mem_insert_of_mem hi)).ne · exact IH (fun i hi => h _ (Finset.mem_insert_of_mem hi)) fun i hi => h' _ (Finset.mem_insert_of_mem hi) · exact Or.inr (h' _ (Finset.mem_insert_self _ _)) #align ennreal.tendsto_finset_prod_of_ne_top ENNReal.tendsto_finset_prod_of_ne_top protected theorem continuousAt_const_mul {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (a * ·) b := Tendsto.const_mul tendsto_id h.symm #align ennreal.continuous_at_const_mul ENNReal.continuousAt_const_mul protected theorem continuousAt_mul_const {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (fun x => x * a) b := Tendsto.mul_const tendsto_id h.symm #align ennreal.continuous_at_mul_const ENNReal.continuousAt_mul_const protected theorem continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous (a * ·) := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_const_mul (Or.inl ha) #align ennreal.continuous_const_mul ENNReal.continuous_const_mul protected theorem continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous fun x => x * a := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_mul_const (Or.inl ha) #align ennreal.continuous_mul_const ENNReal.continuous_mul_const protected theorem continuous_div_const (c : ℝ≥0∞) (c_ne_zero : c ≠ 0) : Continuous fun x : ℝ≥0∞ => x / c := by simp_rw [div_eq_mul_inv, continuous_iff_continuousAt] intro x exact ENNReal.continuousAt_mul_const (Or.intro_left _ (inv_ne_top.mpr c_ne_zero)) #align ennreal.continuous_div_const ENNReal.continuous_div_const @[continuity] theorem continuous_pow (n : ℕ) : Continuous fun a : ℝ≥0∞ => a ^ n := by induction' n with n IH · simp [continuous_const] simp_rw [pow_add, pow_one, continuous_iff_continuousAt] intro x refine ENNReal.Tendsto.mul (IH.tendsto _) ?_ tendsto_id ?_ <;> by_cases H : x = 0 · simp only [H, zero_ne_top, Ne, or_true_iff, not_false_iff] · exact Or.inl fun h => H (pow_eq_zero h) · simp only [H, pow_eq_top_iff, zero_ne_top, false_or_iff, eq_self_iff_true, not_true, Ne, not_false_iff, false_and_iff] · simp only [H, true_or_iff, Ne, not_false_iff] #align ennreal.continuous_pow ENNReal.continuous_pow theorem continuousOn_sub : ContinuousOn (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) { p : ℝ≥0∞ × ℝ≥0∞ | p ≠ ⟨∞, ∞⟩ } := by rw [ContinuousOn] rintro ⟨x, y⟩ hp simp only [Ne, Set.mem_setOf_eq, Prod.mk.inj_iff] at hp exact tendsto_nhdsWithin_of_tendsto_nhds (tendsto_sub (not_and_or.mp hp)) #align ennreal.continuous_on_sub ENNReal.continuousOn_sub theorem continuous_sub_left {a : ℝ≥0∞} (a_ne_top : a ≠ ∞) : Continuous (a - ·) := by change Continuous (Function.uncurry Sub.sub ∘ (a, ·)) refine continuousOn_sub.comp_continuous (Continuous.Prod.mk a) fun x => ?_ simp only [a_ne_top, Ne, mem_setOf_eq, Prod.mk.inj_iff, false_and_iff, not_false_iff] #align ennreal.continuous_sub_left ENNReal.continuous_sub_left theorem continuous_nnreal_sub {a : ℝ≥0} : Continuous fun x : ℝ≥0∞ => (a : ℝ≥0∞) - x := continuous_sub_left coe_ne_top #align ennreal.continuous_nnreal_sub ENNReal.continuous_nnreal_sub theorem continuousOn_sub_left (a : ℝ≥0∞) : ContinuousOn (a - ·) { x : ℝ≥0∞ | x ≠ ∞ } := by rw [show (fun x => a - x) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨a, x⟩ by rfl] apply ContinuousOn.comp continuousOn_sub (Continuous.continuousOn (Continuous.Prod.mk a)) rintro _ h (_ | _) exact h none_eq_top #align ennreal.continuous_on_sub_left ENNReal.continuousOn_sub_left theorem continuous_sub_right (a : ℝ≥0∞) : Continuous fun x : ℝ≥0∞ => x - a := by by_cases a_infty : a = ∞ · simp [a_infty, continuous_const] · rw [show (fun x => x - a) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨x, a⟩ by rfl] apply ContinuousOn.comp_continuous continuousOn_sub (continuous_id'.prod_mk continuous_const) intro x simp only [a_infty, Ne, mem_setOf_eq, Prod.mk.inj_iff, and_false_iff, not_false_iff] #align ennreal.continuous_sub_right ENNReal.continuous_sub_right protected theorem Tendsto.pow {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} {n : ℕ} (hm : Tendsto m f (𝓝 a)) : Tendsto (fun x => m x ^ n) f (𝓝 (a ^ n)) := ((continuous_pow n).tendsto a).comp hm #align ennreal.tendsto.pow ENNReal.Tendsto.pow theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := by have : Tendsto (· * x) (𝓝[<] 1) (𝓝 (1 * x)) := (ENNReal.continuousAt_mul_const (Or.inr one_ne_zero)).mono_left inf_le_left rw [one_mul] at this exact le_of_tendsto this (eventually_nhdsWithin_iff.2 <| eventually_of_forall h) #align ennreal.le_of_forall_lt_one_mul_le ENNReal.le_of_forall_lt_one_mul_le theorem iInf_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, a * f i = a * ⨅ i, f i := by by_cases H : a = ∞ ∧ ⨅ i, f i = 0 · rcases h H.1 H.2 with ⟨i, hi⟩ rw [H.2, mul_zero, ← bot_eq_zero, iInf_eq_bot] exact fun b hb => ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ · rw [not_and_or] at H cases isEmpty_or_nonempty ι · rw [iInf_of_empty, iInf_of_empty, mul_top] exact mt h0 (not_nonempty_iff.2 ‹_›) · exact (ENNReal.mul_left_mono.map_iInf_of_continuousAt' (ENNReal.continuousAt_const_mul H)).symm #align ennreal.infi_mul_left' ENNReal.iInf_mul_left' theorem iInf_mul_left {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, a * f i = a * ⨅ i, f i := iInf_mul_left' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_left ENNReal.iInf_mul_left theorem iInf_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, f i * a = (⨅ i, f i) * a := by simpa only [mul_comm a] using iInf_mul_left' h h0 #align ennreal.infi_mul_right' ENNReal.iInf_mul_right' theorem iInf_mul_right {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, f i * a = (⨅ i, f i) * a := iInf_mul_right' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_right ENNReal.iInf_mul_right theorem inv_map_iInf {ι : Sort*} {x : ι → ℝ≥0∞} : (iInf x)⁻¹ = ⨆ i, (x i)⁻¹ := OrderIso.invENNReal.map_iInf x #align ennreal.inv_map_infi ENNReal.inv_map_iInf theorem inv_map_iSup {ι : Sort*} {x : ι → ℝ≥0∞} : (iSup x)⁻¹ = ⨅ i, (x i)⁻¹ := OrderIso.invENNReal.map_iSup x #align ennreal.inv_map_supr ENNReal.inv_map_iSup theorem inv_limsup {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (limsup x l)⁻¹ = liminf (fun i => (x i)⁻¹) l := OrderIso.invENNReal.limsup_apply #align ennreal.inv_limsup ENNReal.inv_limsup theorem inv_liminf {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (liminf x l)⁻¹ = limsup (fun i => (x i)⁻¹) l := OrderIso.invENNReal.liminf_apply #align ennreal.inv_liminf ENNReal.inv_liminf instance : ContinuousInv ℝ≥0∞ := ⟨OrderIso.invENNReal.continuous⟩ @[simp] -- Porting note (#11215): TODO: generalize to `[InvolutiveInv _] [ContinuousInv _]` protected theorem tendsto_inv_iff {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} : Tendsto (fun x => (m x)⁻¹) f (𝓝 a⁻¹) ↔ Tendsto m f (𝓝 a) := ⟨fun h => by simpa only [inv_inv] using Tendsto.inv h, Tendsto.inv⟩ #align ennreal.tendsto_inv_iff ENNReal.tendsto_inv_iff protected theorem Tendsto.div {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun a => ma a / mb a) f (𝓝 (a / b)) := by apply Tendsto.mul hma _ (ENNReal.tendsto_inv_iff.2 hmb) _ <;> simp [ha, hb] #align ennreal.tendsto.div ENNReal.Tendsto.div protected theorem Tendsto.const_div {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun b => a / m b) f (𝓝 (a / b)) := by apply Tendsto.const_mul (ENNReal.tendsto_inv_iff.2 hm) simp [hb] #align ennreal.tendsto.const_div ENNReal.Tendsto.const_div protected theorem Tendsto.div_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : Tendsto (fun x => m x / b) f (𝓝 (a / b)) := by apply Tendsto.mul_const hm simp [ha] #align ennreal.tendsto.div_const ENNReal.Tendsto.div_const protected theorem tendsto_inv_nat_nhds_zero : Tendsto (fun n : ℕ => (n : ℝ≥0∞)⁻¹) atTop (𝓝 0) := ENNReal.inv_top ▸ ENNReal.tendsto_inv_iff.2 tendsto_nat_nhds_top #align ennreal.tendsto_inv_nat_nhds_zero ENNReal.tendsto_inv_nat_nhds_zero theorem iSup_add {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : iSup s + a = ⨆ b, s b + a := Monotone.map_iSup_of_continuousAt' (continuousAt_id.add continuousAt_const) <| monotone_id.add monotone_const #align ennreal.supr_add ENNReal.iSup_add theorem biSup_add' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (⨆ (i) (_ : p i), f i) + a = ⨆ (i) (_ : p i), f i + a := by haveI : Nonempty { i // p i } := nonempty_subtype.2 h simp only [iSup_subtype', iSup_add] #align ennreal.bsupr_add' ENNReal.biSup_add' theorem add_biSup' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (a + ⨆ (i) (_ : p i), f i) = ⨆ (i) (_ : p i), a + f i := by simp only [add_comm a, biSup_add' h] #align ennreal.add_bsupr' ENNReal.add_biSup' theorem biSup_add {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a := biSup_add' hs #align ennreal.bsupr_add ENNReal.biSup_add theorem add_biSup {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (a + ⨆ i ∈ s, f i) = ⨆ i ∈ s, a + f i := add_biSup' hs #align ennreal.add_bsupr ENNReal.add_biSup theorem sSup_add {s : Set ℝ≥0∞} (hs : s.Nonempty) : sSup s + a = ⨆ b ∈ s, b + a := by rw [sSup_eq_iSup, biSup_add hs] #align ennreal.Sup_add ENNReal.sSup_add theorem add_iSup {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : a + iSup s = ⨆ b, a + s b := by rw [add_comm, iSup_add]; simp [add_comm] #align ennreal.add_supr ENNReal.add_iSup theorem iSup_add_iSup_le {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i j, f i + g j ≤ a) : iSup f + iSup g ≤ a := by simp_rw [iSup_add, add_iSup]; exact iSup₂_le h #align ennreal.supr_add_supr_le ENNReal.iSup_add_iSup_le theorem biSup_add_biSup_le' {ι ι'} {p : ι → Prop} {q : ι' → Prop} (hp : ∃ i, p i) (hq : ∃ j, q j) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i, p i → ∀ j, q j → f i + g j ≤ a) : ((⨆ (i) (_ : p i), f i) + ⨆ (j) (_ : q j), g j) ≤ a := by simp_rw [biSup_add' hp, add_biSup' hq] exact iSup₂_le fun i hi => iSup₂_le (h i hi) #align ennreal.bsupr_add_bsupr_le' ENNReal.biSup_add_biSup_le' theorem biSup_add_biSup_le {ι ι'} {s : Set ι} {t : Set ι'} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i ∈ s, ∀ j ∈ t, f i + g j ≤ a) : ((⨆ i ∈ s, f i) + ⨆ j ∈ t, g j) ≤ a := biSup_add_biSup_le' hs ht h #align ennreal.bsupr_add_bsupr_le ENNReal.biSup_add_biSup_le
Mathlib/Topology/Instances/ENNReal.lean
621
628
theorem iSup_add_iSup {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀ i j, ∃ k, f i + g j ≤ f k + g k) : iSup f + iSup g = ⨆ a, f a + g a := by
cases isEmpty_or_nonempty ι · simp only [iSup_of_empty, bot_eq_zero, zero_add] · refine le_antisymm ?_ (iSup_le fun a => add_le_add (le_iSup _ _) (le_iSup _ _)) refine iSup_add_iSup_le fun i j => ?_ rcases h i j with ⟨k, hk⟩ exact le_iSup_of_le k hk
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Topology.Order.ProjIcc #align_import analysis.special_functions.trigonometric.inverse from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Inverse trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function. (This is delayed as it is easier to set up after developing complex trigonometric functions.) Basic inequalities on trigonometric functions. -/ noncomputable section open scoped Classical open Topology Filter open Set Filter open Real namespace Real variable {x y : ℝ} /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ -- @[pp_nodot] Porting note: not implemented noncomputable def arcsin : ℝ → ℝ := Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm #align real.arcsin Real.arcsin theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := Subtype.coe_prop _ #align real.arcsin_mem_Icc Real.arcsin_mem_Icc @[simp] theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by rw [arcsin, range_comp Subtype.val] simp [Icc] #align real.range_arcsin Real.range_arcsin theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 #align real.arcsin_le_pi_div_two Real.arcsin_le_pi_div_two theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 #align real.neg_pi_div_two_le_arcsin Real.neg_pi_div_two_le_arcsin theorem arcsin_projIcc (x : ℝ) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend, Function.comp_apply] #align real.arcsin_proj_Icc Real.arcsin_projIcc theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩) #align real.sin_arcsin' Real.sin_arcsin' theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ #align real.sin_arcsin Real.sin_arcsin theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] #align real.arcsin_sin' Real.arcsin_sin' theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ #align real.arcsin_sin Real.arcsin_sin theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) := (Subtype.strictMono_coe _).comp_strictMonoOn <| sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _ #align real.strict_mono_on_arcsin Real.strictMonoOn_arcsin theorem monotone_arcsin : Monotone arcsin := (Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _ #align real.monotone_arcsin Real.monotone_arcsin theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) := strictMonoOn_arcsin.injOn #align real.inj_on_arcsin Real.injOn_arcsin theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ #align real.arcsin_inj Real.arcsin_inj @[continuity] theorem continuous_arcsin : Continuous arcsin := continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend' #align real.continuous_arcsin Real.continuous_arcsin theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x := continuous_arcsin.continuousAt #align real.continuous_at_arcsin Real.continuousAt_arcsin theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := by subst y exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) #align real.arcsin_eq_of_sin_eq Real.arcsin_eq_of_sin_eq @[simp] theorem arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ #align real.arcsin_zero Real.arcsin_zero @[simp] theorem arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) #align real.arcsin_one Real.arcsin_one theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one] #align real.arcsin_of_one_le Real.arcsin_of_one_le theorem arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <| left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) #align real.arcsin_neg_one Real.arcsin_neg_one theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one] #align real.arcsin_of_le_neg_one Real.arcsin_of_le_neg_one @[simp] theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by rcases le_total x (-1) with hx₁ | hx₁ · rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] rcases le_total 1 x with hx₂ | hx₂ · rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] refine arcsin_eq_of_sin_eq ?_ ?_ · rw [sin_neg, sin_arcsin hx₁ hx₂] · exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ #align real.arcsin_neg Real.arcsin_neg theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] #align real.arcsin_le_iff_le_sin Real.arcsin_le_iff_le_sin theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rcases le_total x (-1) with hx₁ | hx₁ · simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] cases' lt_or_le 1 x with hx₂ hx₂ · simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy) #align real.arcsin_le_iff_le_sin' Real.arcsin_le_iff_le_sin'
Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean
162
166
theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≤ arcsin y ↔ sin x ≤ y := by
rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Scott Morrison -/ import Mathlib.LinearAlgebra.LinearIndependent #align_import linear_algebra.dimension from "leanprover-community/mathlib"@"47a5f8186becdbc826190ced4312f8199f9db6a5" /-! # Dimension of modules and vector spaces ## Main definitions * The rank of a module is defined as `Module.rank : Cardinal`. This is defined as the supremum of the cardinalities of linearly independent subsets. ## Main statements * `LinearMap.rank_le_of_injective`: the source of an injective linear map has dimension at most that of the target. * `LinearMap.rank_le_of_surjective`: the target of a surjective linear map has dimension at most that of that source. ## Implementation notes Many theorems in this file are not universe-generic when they relate dimensions in different universes. They should be as general as they can be without inserting `lift`s. The types `M`, `M'`, ... all live in different universes, and `M₁`, `M₂`, ... all live in the same universe. -/ noncomputable section universe w w' u u' v v' variable {R : Type u} {R' : Type u'} {M M₁ : Type v} {M' : Type v'} open Cardinal Submodule Function Set section Module section variable [Semiring R] [AddCommMonoid M] [Module R M] variable (R M) /-- The rank of a module, defined as a term of type `Cardinal`. We define this as the supremum of the cardinalities of linearly independent subsets. For a free module over any ring satisfying the strong rank condition (e.g. left-noetherian rings, commutative rings, and in particular division rings and fields), this is the same as the dimension of the space (i.e. the cardinality of any basis). In particular this agrees with the usual notion of the dimension of a vector space. -/ protected irreducible_def Module.rank : Cardinal := ⨆ ι : { s : Set M // LinearIndependent R ((↑) : s → M) }, (#ι.1) #align module.rank Module.rank theorem rank_le_card : Module.rank R M ≤ #M := (Module.rank_def _ _).trans_le (ciSup_le' fun _ ↦ mk_set_le _) lemma nonempty_linearIndependent_set : Nonempty {s : Set M // LinearIndependent R ((↑) : s → M)} := ⟨⟨∅, linearIndependent_empty _ _⟩⟩ end variable [Ring R] [Ring R'] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] [Module R' M'] [Module R' M₁] namespace LinearIndependent variable [Nontrivial R] theorem cardinal_lift_le_rank {ι : Type w} {v : ι → M} (hv : LinearIndependent R v) : Cardinal.lift.{v} #ι ≤ Cardinal.lift.{w} (Module.rank R M) := by rw [Module.rank] refine le_trans ?_ (lift_le.mpr <| le_ciSup (bddAbove_range.{v, v} _) ⟨_, hv.coe_range⟩) exact lift_mk_le'.mpr ⟨(Equiv.ofInjective _ hv.injective).toEmbedding⟩ #align cardinal_lift_le_rank_of_linear_independent LinearIndependent.cardinal_lift_le_rank #align cardinal_lift_le_rank_of_linear_independent' LinearIndependent.cardinal_lift_le_rank lemma aleph0_le_rank {ι : Type w} [Infinite ι] {v : ι → M} (hv : LinearIndependent R v) : ℵ₀ ≤ Module.rank R M := aleph0_le_lift.mp <| (aleph0_le_lift.mpr <| aleph0_le_mk ι).trans hv.cardinal_lift_le_rank theorem cardinal_le_rank {ι : Type v} {v : ι → M} (hv : LinearIndependent R v) : #ι ≤ Module.rank R M := by simpa using hv.cardinal_lift_le_rank #align cardinal_le_rank_of_linear_independent LinearIndependent.cardinal_le_rank theorem cardinal_le_rank' {s : Set M} (hs : LinearIndependent R (fun x => x : s → M)) : #s ≤ Module.rank R M := hs.cardinal_le_rank #align cardinal_le_rank_of_linear_independent' LinearIndependent.cardinal_le_rank' end LinearIndependent @[deprecated (since := "2023-12-27")] alias cardinal_lift_le_rank_of_linearIndependent := LinearIndependent.cardinal_lift_le_rank @[deprecated (since := "2023-12-27")] alias cardinal_lift_le_rank_of_linearIndependent' := LinearIndependent.cardinal_lift_le_rank @[deprecated (since := "2023-12-27")] alias cardinal_le_rank_of_linearIndependent := LinearIndependent.cardinal_le_rank @[deprecated (since := "2023-12-27")] alias cardinal_le_rank_of_linearIndependent' := LinearIndependent.cardinal_le_rank' section SurjectiveInjective section Module /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map which sends non-zero elements to non-zero elements, `j : M →+ M'` is an injective group homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_injective_injective (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : Injective j) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : lift.{v'} (Module.rank R M) ≤ lift.{v} (Module.rank R' M') := by simp_rw [Module.rank, lift_iSup (bddAbove_range.{v', v'} _), lift_iSup (bddAbove_range.{v, v} _)] exact ciSup_mono' (bddAbove_range.{v', v} _) fun ⟨s, h⟩ ↦ ⟨⟨j '' s, (h.map_of_injective_injective i j hi (fun _ _ ↦ hj <| by rwa [j.map_zero]) hc).image⟩, lift_mk_le'.mpr ⟨(Equiv.Set.image j s hj).toEmbedding⟩⟩ /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero, `j : M →+ M'` is an injective group homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_surjective_injective (i : ZeroHom R R') (j : M →+ M') (hi : Surjective i) (hj : Injective j) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : lift.{v'} (Module.rank R M) ≤ lift.{v} (Module.rank R' M') := by obtain ⟨i', hi'⟩ := hi.hasRightInverse refine lift_rank_le_of_injective_injective i' j (fun _ h ↦ ?_) hj fun r m ↦ ?_ · apply_fun i at h rwa [hi', i.map_zero] at h rw [hc (i' r) m, hi'] /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a bijective map which maps zero to zero, `j : M ≃+ M'` is a group isomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearEquiv.lift_rank_eq`. -/ theorem lift_rank_eq_of_equiv_equiv (i : ZeroHom R R') (j : M ≃+ M') (hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : lift.{v'} (Module.rank R M) = lift.{v} (Module.rank R' M') := (lift_rank_le_of_surjective_injective i j hi.2 j.injective hc).antisymm <| lift_rank_le_of_injective_injective i j.symm (fun _ _ ↦ hi.1 <| by rwa [i.map_zero]) j.symm.injective fun _ _ ↦ j.symm_apply_eq.2 <| by erw [hc, j.apply_symm_apply] /-- The same-universe version of `lift_rank_le_of_injective_injective`. -/ theorem rank_le_of_injective_injective (i : R' → R) (j : M →+ M₁) (hi : ∀ r, i r = 0 → r = 0) (hj : Injective j) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : Module.rank R M ≤ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc /-- The same-universe version of `lift_rank_le_of_surjective_injective`. -/ theorem rank_le_of_surjective_injective (i : ZeroHom R R') (j : M →+ M₁) (hi : Surjective i) (hj : Injective j) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : Module.rank R M ≤ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc /-- The same-universe version of `lift_rank_eq_of_equiv_equiv`. -/ theorem rank_eq_of_equiv_equiv (i : ZeroHom R R') (j : M ≃+ M₁) (hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : Module.rank R M = Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hi hc end Module namespace Algebra variable {R : Type w} {S : Type v} [CommRing R] [Ring S] [Algebra R S] {R' : Type w'} {S' : Type v'} [CommRing R'] [Ring S'] [Algebra R' S'] /-- If `S / R` and `S' / R'` are algebras, `i : R' →+* R` and `j : S →+* S'` are injective ring homomorphisms, such that `R' → R → S → S'` and `R' → S'` commute, then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/ theorem lift_rank_le_of_injective_injective (i : R' →+* R) (j : S →+* S') (hi : Injective i) (hj : Injective j) (hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') : lift.{v'} (Module.rank R S) ≤ lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_le_of_injective_injective i j (fun _ _ ↦ hi <| by rwa [i.map_zero]) hj fun r _ ↦ ?_ have := congr($hc r) simp only [RingHom.coe_comp, comp_apply] at this simp_rw [smul_def, AddMonoidHom.coe_coe, map_mul, this] /-- If `S / R` and `S' / R'` are algebras, `i : R →+* R'` is a surjective ring homomorphism, `j : S →+* S'` is an injective ring homomorphism, such that `R → R' → S'` and `R → S → S'` commute, then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/ theorem lift_rank_le_of_surjective_injective (i : R →+* R') (j : S →+* S') (hi : Surjective i) (hj : Injective j) (hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) : lift.{v'} (Module.rank R S) ≤ lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_le_of_surjective_injective i j hi hj fun r _ ↦ ?_ have := congr($hc r) simp only [RingHom.coe_comp, comp_apply] at this simp only [smul_def, AddMonoidHom.coe_coe, map_mul, ZeroHom.coe_coe, this] /-- If `S / R` and `S' / R'` are algebras, `i : R ≃+* R'` and `j : S ≃+* S'` are ring isomorphisms, such that `R → R' → S'` and `R → S → S'` commute, then the rank of `S / R` is equal to the rank of `S' / R'`. -/ theorem lift_rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S') (hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) : lift.{v'} (Module.rank R S) = lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_eq_of_equiv_equiv i j i.bijective fun r _ ↦ ?_ have := congr($hc r) simp only [RingEquiv.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, comp_apply] at this simp only [smul_def, RingEquiv.coe_toAddEquiv, map_mul, ZeroHom.coe_coe, this] variable {S' : Type v} [CommRing R'] [Ring S'] [Algebra R' S'] /-- The same-universe version of `Algebra.lift_rank_le_of_injective_injective`. -/ theorem rank_le_of_injective_injective (i : R' →+* R) (j : S →+* S') (hi : Injective i) (hj : Injective j) (hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') : Module.rank R S ≤ Module.rank R' S' := by simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc /-- The same-universe version of `Algebra.lift_rank_le_of_surjective_injective`. -/ theorem rank_le_of_surjective_injective (i : R →+* R') (j : S →+* S') (hi : Surjective i) (hj : Injective j) (hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) : Module.rank R S ≤ Module.rank R' S' := by simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc /-- The same-universe version of `Algebra.lift_rank_eq_of_equiv_equiv`. -/ theorem rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S') (hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) : Module.rank R S = Module.rank R' S' := by simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hc end Algebra end SurjectiveInjective section theorem LinearMap.lift_rank_le_of_injective (f : M →ₗ[R] M') (i : Injective f) : Cardinal.lift.{v'} (Module.rank R M) ≤ Cardinal.lift.{v} (Module.rank R M') := lift_rank_le_of_injective_injective (RingHom.id R) f (fun _ h ↦ h) i f.map_smul #align linear_map.lift_rank_le_of_injective LinearMap.lift_rank_le_of_injective theorem LinearMap.rank_le_of_injective (f : M →ₗ[R] M₁) (i : Injective f) : Module.rank R M ≤ Module.rank R M₁ := Cardinal.lift_le.1 (f.lift_rank_le_of_injective i) #align linear_map.rank_le_of_injective LinearMap.rank_le_of_injective /-- The rank of the range of a linear map is at most the rank of the source. -/ -- The proof is: a free submodule of the range lifts to a free submodule of the -- source, by arbitrarily lifting a basis. theorem lift_rank_range_le (f : M →ₗ[R] M') : Cardinal.lift.{v} (Module.rank R (LinearMap.range f)) ≤ Cardinal.lift.{v'} (Module.rank R M) := by simp only [Module.rank_def] rw [Cardinal.lift_iSup (Cardinal.bddAbove_range.{v', v'} _)] apply ciSup_le' rintro ⟨s, li⟩ apply le_trans swap · apply Cardinal.lift_le.mpr refine le_ciSup (Cardinal.bddAbove_range.{v, v} _) ⟨rangeSplitting f '' s, ?_⟩ apply LinearIndependent.of_comp f.rangeRestrict convert li.comp (Equiv.Set.rangeSplittingImageEquiv f s) (Equiv.injective _) using 1 · exact (Cardinal.lift_mk_eq'.mpr ⟨Equiv.Set.rangeSplittingImageEquiv f s⟩).ge #align lift_rank_range_le lift_rank_range_le theorem rank_range_le (f : M →ₗ[R] M₁) : Module.rank R (LinearMap.range f) ≤ Module.rank R M := by simpa using lift_rank_range_le f #align rank_range_le rank_range_le theorem lift_rank_map_le (f : M →ₗ[R] M') (p : Submodule R M) : Cardinal.lift.{v} (Module.rank R (p.map f)) ≤ Cardinal.lift.{v'} (Module.rank R p) := by have h := lift_rank_range_le (f.comp (Submodule.subtype p)) rwa [LinearMap.range_comp, range_subtype] at h #align lift_rank_map_le lift_rank_map_le theorem rank_map_le (f : M →ₗ[R] M₁) (p : Submodule R M) : Module.rank R (p.map f) ≤ Module.rank R p := by simpa using lift_rank_map_le f p #align rank_map_le rank_map_le theorem rank_le_of_submodule (s t : Submodule R M) (h : s ≤ t) : Module.rank R s ≤ Module.rank R t := (Submodule.inclusion h).rank_le_of_injective fun ⟨x, _⟩ ⟨y, _⟩ eq => Subtype.eq <| show x = y from Subtype.ext_iff_val.1 eq #align rank_le_of_submodule rank_le_of_submodule /-- Two linearly equivalent vector spaces have the same dimension, a version with different universes. -/
Mathlib/LinearAlgebra/Dimension/Basic.lean
296
300
theorem LinearEquiv.lift_rank_eq (f : M ≃ₗ[R] M') : Cardinal.lift.{v'} (Module.rank R M) = Cardinal.lift.{v} (Module.rank R M') := by
apply le_antisymm · exact f.toLinearMap.lift_rank_le_of_injective f.injective · exact f.symm.toLinearMap.lift_rank_le_of_injective f.symm.injective
/- Copyright (c) 2020 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.GCDMonoid.Multiset import Mathlib.Combinatorics.Enumerative.Partition import Mathlib.Data.List.Rotate import Mathlib.GroupTheory.Perm.Cycle.Factors import Mathlib.GroupTheory.Perm.Closure import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Tactic.NormNum.GCD #align_import group_theory.perm.cycle.type from "leanprover-community/mathlib"@"47adfab39a11a072db552f47594bf8ed2cf8a722" /-! # Cycle Types In this file we define the cycle type of a permutation. ## Main definitions - `Equiv.Perm.cycleType σ` where `σ` is a permutation of a `Fintype` - `Equiv.Perm.partition σ` where `σ` is a permutation of a `Fintype` ## Main results - `sum_cycleType` : The sum of `σ.cycleType` equals `σ.support.card` - `lcm_cycleType` : The lcm of `σ.cycleType` equals `orderOf σ` - `isConj_iff_cycleType_eq` : Two permutations are conjugate if and only if they have the same cycle type. - `exists_prime_orderOf_dvd_card`: For every prime `p` dividing the order of a finite group `G` there exists an element of order `p` in `G`. This is known as Cauchy's theorem. -/ namespace Equiv.Perm open Equiv List Multiset variable {α : Type*} [Fintype α] section CycleType variable [DecidableEq α] /-- The cycle type of a permutation -/ def cycleType (σ : Perm α) : Multiset ℕ := σ.cycleFactorsFinset.1.map (Finset.card ∘ support) #align equiv.perm.cycle_type Equiv.Perm.cycleType theorem cycleType_def (σ : Perm α) : σ.cycleType = σ.cycleFactorsFinset.1.map (Finset.card ∘ support) := rfl #align equiv.perm.cycle_type_def Equiv.Perm.cycleType_def theorem cycleType_eq' {σ : Perm α} (s : Finset (Perm α)) (h1 : ∀ f : Perm α, f ∈ s → f.IsCycle) (h2 : (s : Set (Perm α)).Pairwise Disjoint) (h0 : s.noncommProd id (h2.imp fun _ _ => Disjoint.commute) = σ) : σ.cycleType = s.1.map (Finset.card ∘ support) := by rw [cycleType_def] congr rw [cycleFactorsFinset_eq_finset] exact ⟨h1, h2, h0⟩ #align equiv.perm.cycle_type_eq' Equiv.Perm.cycleType_eq' theorem cycleType_eq {σ : Perm α} (l : List (Perm α)) (h0 : l.prod = σ) (h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) : σ.cycleType = l.map (Finset.card ∘ support) := by have hl : l.Nodup := nodup_of_pairwise_disjoint_cycles h1 h2 rw [cycleType_eq' l.toFinset] · simp [List.dedup_eq_self.mpr hl, (· ∘ ·)] · simpa using h1 · simpa [hl] using h2 · simp [hl, h0] #align equiv.perm.cycle_type_eq Equiv.Perm.cycleType_eq @[simp] -- Porting note: new attr theorem cycleType_eq_zero {σ : Perm α} : σ.cycleType = 0 ↔ σ = 1 := by simp [cycleType_def, cycleFactorsFinset_eq_empty_iff] #align equiv.perm.cycle_type_eq_zero Equiv.Perm.cycleType_eq_zero @[simp] -- Porting note: new attr theorem cycleType_one : (1 : Perm α).cycleType = 0 := cycleType_eq_zero.2 rfl #align equiv.perm.cycle_type_one Equiv.Perm.cycleType_one theorem card_cycleType_eq_zero {σ : Perm α} : Multiset.card σ.cycleType = 0 ↔ σ = 1 := by rw [card_eq_zero, cycleType_eq_zero] #align equiv.perm.card_cycle_type_eq_zero Equiv.Perm.card_cycleType_eq_zero theorem card_cycleType_pos {σ : Perm α} : 0 < Multiset.card σ.cycleType ↔ σ ≠ 1 := pos_iff_ne_zero.trans card_cycleType_eq_zero.not theorem two_le_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 2 ≤ n := by simp only [cycleType_def, ← Finset.mem_def, Function.comp_apply, Multiset.mem_map, mem_cycleFactorsFinset_iff] at h obtain ⟨_, ⟨hc, -⟩, rfl⟩ := h exact hc.two_le_card_support #align equiv.perm.two_le_of_mem_cycle_type Equiv.Perm.two_le_of_mem_cycleType theorem one_lt_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 1 < n := two_le_of_mem_cycleType h #align equiv.perm.one_lt_of_mem_cycle_type Equiv.Perm.one_lt_of_mem_cycleType theorem IsCycle.cycleType {σ : Perm α} (hσ : IsCycle σ) : σ.cycleType = [σ.support.card] := cycleType_eq [σ] (mul_one σ) (fun _τ hτ => (congr_arg IsCycle (List.mem_singleton.mp hτ)).mpr hσ) (List.pairwise_singleton Disjoint σ) #align equiv.perm.is_cycle.cycle_type Equiv.Perm.IsCycle.cycleType theorem card_cycleType_eq_one {σ : Perm α} : Multiset.card σ.cycleType = 1 ↔ σ.IsCycle := by rw [card_eq_one] simp_rw [cycleType_def, Multiset.map_eq_singleton, ← Finset.singleton_val, Finset.val_inj, cycleFactorsFinset_eq_singleton_iff] constructor · rintro ⟨_, _, ⟨h, -⟩, -⟩ exact h · intro h use σ.support.card, σ simp [h] #align equiv.perm.card_cycle_type_eq_one Equiv.Perm.card_cycleType_eq_one theorem Disjoint.cycleType {σ τ : Perm α} (h : Disjoint σ τ) : (σ * τ).cycleType = σ.cycleType + τ.cycleType := by rw [cycleType_def, cycleType_def, cycleType_def, h.cycleFactorsFinset_mul_eq_union, ← Multiset.map_add, Finset.union_val, Multiset.add_eq_union_iff_disjoint.mpr _] exact Finset.disjoint_val.2 h.disjoint_cycleFactorsFinset #align equiv.perm.disjoint.cycle_type Equiv.Perm.Disjoint.cycleType @[simp] -- Porting note: new attr theorem cycleType_inv (σ : Perm α) : σ⁻¹.cycleType = σ.cycleType := cycle_induction_on (P := fun τ : Perm α => τ⁻¹.cycleType = τ.cycleType) σ rfl (fun σ hσ => by simp only [hσ.cycleType, hσ.inv.cycleType, support_inv]) fun σ τ hστ _ hσ hτ => by simp only [mul_inv_rev, hστ.cycleType, hστ.symm.inv_left.inv_right.cycleType, hσ, hτ, add_comm] #align equiv.perm.cycle_type_inv Equiv.Perm.cycleType_inv @[simp] -- Porting note: new attr theorem cycleType_conj {σ τ : Perm α} : (τ * σ * τ⁻¹).cycleType = σ.cycleType := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => rw [hσ.cycleType, hσ.conj.cycleType, card_support_conj] | induction_disjoint σ π hd _ hσ hπ => rw [← conj_mul, hd.cycleType, (hd.conj _).cycleType, hσ, hπ] #align equiv.perm.cycle_type_conj Equiv.Perm.cycleType_conj theorem sum_cycleType (σ : Perm α) : σ.cycleType.sum = σ.support.card := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => rw [hσ.cycleType, sum_coe, List.sum_singleton] | induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, sum_add, hσ, hτ, hd.card_support_mul] #align equiv.perm.sum_cycle_type Equiv.Perm.sum_cycleType theorem sign_of_cycleType' (σ : Perm α) : sign σ = (σ.cycleType.map fun n => -(-1 : ℤˣ) ^ n).prod := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => simp [hσ.cycleType, hσ.sign] | induction_disjoint σ τ hd _ hσ hτ => simp [hσ, hτ, hd.cycleType] #align equiv.perm.sign_of_cycle_type' Equiv.Perm.sign_of_cycleType' theorem sign_of_cycleType (f : Perm α) : sign f = (-1 : ℤˣ) ^ (f.cycleType.sum + Multiset.card f.cycleType) := by rw [sign_of_cycleType'] induction' f.cycleType using Multiset.induction_on with a s ihs · rfl · rw [Multiset.map_cons, Multiset.prod_cons, Multiset.sum_cons, Multiset.card_cons, ihs] simp only [pow_add, pow_one, mul_neg_one, neg_mul, mul_neg, mul_assoc, mul_one] #align equiv.perm.sign_of_cycle_type Equiv.Perm.sign_of_cycleType @[simp] -- Porting note: new attr theorem lcm_cycleType (σ : Perm α) : σ.cycleType.lcm = orderOf σ := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => simp [hσ.cycleType, hσ.orderOf] | induction_disjoint σ τ hd _ hσ hτ => simp [hd.cycleType, hd.orderOf, lcm_eq_nat_lcm, hσ, hτ] #align equiv.perm.lcm_cycle_type Equiv.Perm.lcm_cycleType theorem dvd_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : n ∣ orderOf σ := by rw [← lcm_cycleType] exact dvd_lcm h #align equiv.perm.dvd_of_mem_cycle_type Equiv.Perm.dvd_of_mem_cycleType theorem orderOf_cycleOf_dvd_orderOf (f : Perm α) (x : α) : orderOf (cycleOf f x) ∣ orderOf f := by by_cases hx : f x = x · rw [← cycleOf_eq_one_iff] at hx simp [hx] · refine dvd_of_mem_cycleType ?_ rw [cycleType, Multiset.mem_map] refine ⟨f.cycleOf x, ?_, ?_⟩ · rwa [← Finset.mem_def, cycleOf_mem_cycleFactorsFinset_iff, mem_support] · simp [(isCycle_cycleOf _ hx).orderOf] #align equiv.perm.order_of_cycle_of_dvd_order_of Equiv.Perm.orderOf_cycleOf_dvd_orderOf theorem two_dvd_card_support {σ : Perm α} (hσ : σ ^ 2 = 1) : 2 ∣ σ.support.card := (congr_arg (Dvd.dvd 2) σ.sum_cycleType).mp (Multiset.dvd_sum fun n hn => by rw [_root_.le_antisymm (Nat.le_of_dvd zero_lt_two <| (dvd_of_mem_cycleType hn).trans <| orderOf_dvd_of_pow_eq_one hσ) (two_le_of_mem_cycleType hn)]) #align equiv.perm.two_dvd_card_support Equiv.Perm.two_dvd_card_support theorem cycleType_prime_order {σ : Perm α} (hσ : (orderOf σ).Prime) : ∃ n : ℕ, σ.cycleType = Multiset.replicate (n + 1) (orderOf σ) := by refine ⟨Multiset.card σ.cycleType - 1, eq_replicate.2 ⟨?_, fun n hn ↦ ?_⟩⟩ · rw [tsub_add_cancel_of_le] rw [Nat.succ_le_iff, card_cycleType_pos, Ne, ← orderOf_eq_one_iff] exact hσ.ne_one · exact (hσ.eq_one_or_self_of_dvd n (dvd_of_mem_cycleType hn)).resolve_left (one_lt_of_mem_cycleType hn).ne' #align equiv.perm.cycle_type_prime_order Equiv.Perm.cycleType_prime_order theorem isCycle_of_prime_order {σ : Perm α} (h1 : (orderOf σ).Prime) (h2 : σ.support.card < 2 * orderOf σ) : σ.IsCycle := by obtain ⟨n, hn⟩ := cycleType_prime_order h1 rw [← σ.sum_cycleType, hn, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id, mul_lt_mul_right (orderOf_pos σ), Nat.succ_lt_succ_iff, Nat.lt_succ_iff, Nat.le_zero] at h2 rw [← card_cycleType_eq_one, hn, card_replicate, h2] #align equiv.perm.is_cycle_of_prime_order Equiv.Perm.isCycle_of_prime_order theorem cycleType_le_of_mem_cycleFactorsFinset {f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) : f.cycleType ≤ g.cycleType := by have hf' := mem_cycleFactorsFinset_iff.1 hf rw [cycleType_def, cycleType_def, hf'.left.cycleFactorsFinset_eq_singleton] refine map_le_map ?_ simpa only [Finset.singleton_val, singleton_le, Finset.mem_val] using hf #align equiv.perm.cycle_type_le_of_mem_cycle_factors_finset Equiv.Perm.cycleType_le_of_mem_cycleFactorsFinset theorem cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub {f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) : (g * f⁻¹).cycleType = g.cycleType - f.cycleType := add_right_cancel (b := f.cycleType) <| by rw [← (disjoint_mul_inv_of_mem_cycleFactorsFinset hf).cycleType, inv_mul_cancel_right, tsub_add_cancel_of_le (cycleType_le_of_mem_cycleFactorsFinset hf)] #align equiv.perm.cycle_type_mul_mem_cycle_factors_finset_eq_sub Equiv.Perm.cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub theorem isConj_of_cycleType_eq {σ τ : Perm α} (h : cycleType σ = cycleType τ) : IsConj σ τ := by induction σ using cycle_induction_on generalizing τ with | base_one => rw [cycleType_one, eq_comm, cycleType_eq_zero] at h rw [h] | base_cycles σ hσ => have hτ := card_cycleType_eq_one.2 hσ rw [h, card_cycleType_eq_one] at hτ apply hσ.isConj hτ rw [hσ.cycleType, hτ.cycleType, coe_eq_coe, List.singleton_perm] at h exact List.singleton_injective h | induction_disjoint σ π hd hc hσ hπ => rw [hd.cycleType] at h have h' : σ.support.card ∈ τ.cycleType := by simp [← h, hc.cycleType] obtain ⟨σ', hσ'l, hσ'⟩ := Multiset.mem_map.mp h' have key : IsConj (σ' * τ * σ'⁻¹) τ := (isConj_iff.2 ⟨σ', rfl⟩).symm refine IsConj.trans ?_ key rw [mul_assoc] have hs : σ.cycleType = σ'.cycleType := by rw [← Finset.mem_def, mem_cycleFactorsFinset_iff] at hσ'l rw [hc.cycleType, ← hσ', hσ'l.left.cycleType]; rfl refine hd.isConj_mul (hσ hs) (hπ ?_) ?_ · rw [cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub, ← h, add_comm, hs, add_tsub_cancel_right] rwa [Finset.mem_def] · exact (disjoint_mul_inv_of_mem_cycleFactorsFinset hσ'l).symm #align equiv.perm.is_conj_of_cycle_type_eq Equiv.Perm.isConj_of_cycleType_eq theorem isConj_iff_cycleType_eq {σ τ : Perm α} : IsConj σ τ ↔ σ.cycleType = τ.cycleType := ⟨fun h => by obtain ⟨π, rfl⟩ := isConj_iff.1 h rw [cycleType_conj], isConj_of_cycleType_eq⟩ #align equiv.perm.is_conj_iff_cycle_type_eq Equiv.Perm.isConj_iff_cycleType_eq @[simp] theorem cycleType_extendDomain {β : Type*} [Fintype β] [DecidableEq β] {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) {g : Perm α} : cycleType (g.extendDomain f) = cycleType g := by induction g using cycle_induction_on with | base_one => rw [extendDomain_one, cycleType_one, cycleType_one] | base_cycles σ hσ => rw [(hσ.extendDomain f).cycleType, hσ.cycleType, card_support_extend_domain] | induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, ← extendDomain_mul, (hd.extendDomain f).cycleType, hσ, hτ] #align equiv.perm.cycle_type_extend_domain Equiv.Perm.cycleType_extendDomain theorem cycleType_ofSubtype {p : α → Prop} [DecidablePred p] {g : Perm (Subtype p)} : cycleType (ofSubtype g) = cycleType g := cycleType_extendDomain (Equiv.refl (Subtype p)) #align equiv.perm.cycle_type_of_subtype Equiv.Perm.cycleType_ofSubtype theorem mem_cycleType_iff {n : ℕ} {σ : Perm α} : n ∈ cycleType σ ↔ ∃ c τ, σ = c * τ ∧ Disjoint c τ ∧ IsCycle c ∧ c.support.card = n := by constructor · intro h obtain ⟨l, rfl, hlc, hld⟩ := truncCycleFactors σ rw [cycleType_eq _ rfl hlc hld, Multiset.mem_coe, List.mem_map] at h obtain ⟨c, cl, rfl⟩ := h rw [(List.perm_cons_erase cl).pairwise_iff @(Disjoint.symmetric)] at hld refine ⟨c, (l.erase c).prod, ?_, ?_, hlc _ cl, rfl⟩ · rw [← List.prod_cons, (List.perm_cons_erase cl).symm.prod_eq' (hld.imp Disjoint.commute)] · exact disjoint_prod_right _ fun g => List.rel_of_pairwise_cons hld · rintro ⟨c, t, rfl, hd, hc, rfl⟩ simp [hd.cycleType, hc.cycleType] #align equiv.perm.mem_cycle_type_iff Equiv.Perm.mem_cycleType_iff theorem le_card_support_of_mem_cycleType {n : ℕ} {σ : Perm α} (h : n ∈ cycleType σ) : n ≤ σ.support.card := (le_sum_of_mem h).trans (le_of_eq σ.sum_cycleType) #align equiv.perm.le_card_support_of_mem_cycle_type Equiv.Perm.le_card_support_of_mem_cycleType theorem cycleType_of_card_le_mem_cycleType_add_two {n : ℕ} {g : Perm α} (hn2 : Fintype.card α < n + 2) (hng : n ∈ g.cycleType) : g.cycleType = {n} := by obtain ⟨c, g', rfl, hd, hc, rfl⟩ := mem_cycleType_iff.1 hng suffices g'1 : g' = 1 by rw [hd.cycleType, hc.cycleType, coe_singleton, g'1, cycleType_one, add_zero] contrapose! hn2 with g'1 apply le_trans _ (c * g').support.card_le_univ rw [hd.card_support_mul] exact add_le_add_left (two_le_card_support_of_ne_one g'1) _ #align equiv.perm.cycle_type_of_card_le_mem_cycle_type_add_two Equiv.Perm.cycleType_of_card_le_mem_cycleType_add_two end CycleType theorem card_compl_support_modEq [DecidableEq α] {p n : ℕ} [hp : Fact p.Prime] {σ : Perm α} (hσ : σ ^ p ^ n = 1) : σ.supportᶜ.card ≡ Fintype.card α [MOD p] := by rw [Nat.modEq_iff_dvd', ← Finset.card_compl, compl_compl, ← sum_cycleType] · refine Multiset.dvd_sum fun k hk => ?_ obtain ⟨m, -, hm⟩ := (Nat.dvd_prime_pow hp.out).mp (orderOf_dvd_of_pow_eq_one hσ) obtain ⟨l, -, rfl⟩ := (Nat.dvd_prime_pow hp.out).mp ((congr_arg _ hm).mp (dvd_of_mem_cycleType hk)) exact dvd_pow_self _ fun h => (one_lt_of_mem_cycleType hk).ne <| by rw [h, pow_zero] · exact Finset.card_le_univ _ #align equiv.perm.card_compl_support_modeq Equiv.Perm.card_compl_support_modEq open Function in /-- The number of fixed points of a `p ^ n`-th root of the identity function over a finite set and the set's cardinality have the same residue modulo `p`, where `p` is a prime. -/ theorem card_fixedPoints_modEq [DecidableEq α] {f : Function.End α} {p n : ℕ} [hp : Fact p.Prime] (hf : f ^ p ^ n = 1) : Fintype.card α ≡ Fintype.card f.fixedPoints [MOD p] := by let σ : α ≃ α := ⟨f, f ^ (p ^ n - 1), leftInverse_iff_comp.mpr ((pow_sub_mul_pow f (Nat.one_le_pow n p hp.out.pos)).trans hf), leftInverse_iff_comp.mpr ((pow_mul_pow_sub f (Nat.one_le_pow n p hp.out.pos)).trans hf)⟩ have hσ : σ ^ p ^ n = 1 := by rw [DFunLike.ext'_iff, coe_pow] exact (hom_coe_pow (fun g : Function.End α ↦ g) rfl (fun g h ↦ rfl) f (p ^ n)).symm.trans hf suffices Fintype.card f.fixedPoints = (support σ)ᶜ.card from this ▸ (card_compl_support_modEq hσ).symm suffices f.fixedPoints = (support σ)ᶜ by simp only [this]; apply Fintype.card_coe simp [σ, Set.ext_iff, IsFixedPt] theorem exists_fixed_point_of_prime {p n : ℕ} [hp : Fact p.Prime] (hα : ¬p ∣ Fintype.card α) {σ : Perm α} (hσ : σ ^ p ^ n = 1) : ∃ a : α, σ a = a := by classical contrapose! hα simp_rw [← mem_support, ← Finset.eq_univ_iff_forall] at hα exact Nat.modEq_zero_iff_dvd.1 ((congr_arg _ (Finset.card_eq_zero.2 (compl_eq_bot.2 hα))).mp (card_compl_support_modEq hσ).symm) #align equiv.perm.exists_fixed_point_of_prime Equiv.Perm.exists_fixed_point_of_prime theorem exists_fixed_point_of_prime' {p n : ℕ} [hp : Fact p.Prime] (hα : p ∣ Fintype.card α) {σ : Perm α} (hσ : σ ^ p ^ n = 1) {a : α} (ha : σ a = a) : ∃ b : α, σ b = b ∧ b ≠ a := by classical have h : ∀ b : α, b ∈ σ.supportᶜ ↔ σ b = b := fun b => by rw [Finset.mem_compl, mem_support, Classical.not_not] obtain ⟨b, hb1, hb2⟩ := Finset.exists_ne_of_one_lt_card (hp.out.one_lt.trans_le (Nat.le_of_dvd (Finset.card_pos.mpr ⟨a, (h a).mpr ha⟩) (Nat.modEq_zero_iff_dvd.mp ((card_compl_support_modEq hσ).trans (Nat.modEq_zero_iff_dvd.mpr hα))))) a exact ⟨b, (h b).mp hb1, hb2⟩ #align equiv.perm.exists_fixed_point_of_prime' Equiv.Perm.exists_fixed_point_of_prime' theorem isCycle_of_prime_order' {σ : Perm α} (h1 : (orderOf σ).Prime) (h2 : Fintype.card α < 2 * orderOf σ) : σ.IsCycle := by classical exact isCycle_of_prime_order h1 (lt_of_le_of_lt σ.support.card_le_univ h2) #align equiv.perm.is_cycle_of_prime_order' Equiv.Perm.isCycle_of_prime_order' theorem isCycle_of_prime_order'' {σ : Perm α} (h1 : (Fintype.card α).Prime) (h2 : orderOf σ = Fintype.card α) : σ.IsCycle := isCycle_of_prime_order' ((congr_arg Nat.Prime h2).mpr h1) <| by rw [← one_mul (Fintype.card α), ← h2, mul_lt_mul_right (orderOf_pos σ)] exact one_lt_two #align equiv.perm.is_cycle_of_prime_order'' Equiv.Perm.isCycle_of_prime_order'' section Cauchy variable (G : Type*) [Group G] (n : ℕ) /-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/ def vectorsProdEqOne : Set (Vector G n) := { v | v.toList.prod = 1 } #align equiv.perm.vectors_prod_eq_one Equiv.Perm.vectorsProdEqOne namespace VectorsProdEqOne theorem mem_iff {n : ℕ} (v : Vector G n) : v ∈ vectorsProdEqOne G n ↔ v.toList.prod = 1 := Iff.rfl #align equiv.perm.vectors_prod_eq_one.mem_iff Equiv.Perm.VectorsProdEqOne.mem_iff theorem zero_eq : vectorsProdEqOne G 0 = {Vector.nil} := Set.eq_singleton_iff_unique_mem.mpr ⟨Eq.refl (1 : G), fun v _ => v.eq_nil⟩ #align equiv.perm.vectors_prod_eq_one.zero_eq Equiv.Perm.VectorsProdEqOne.zero_eq theorem one_eq : vectorsProdEqOne G 1 = {Vector.nil.cons 1} := by simp_rw [Set.eq_singleton_iff_unique_mem, mem_iff, Vector.toList_singleton, List.prod_singleton, Vector.head_cons, true_and] exact fun v hv => v.cons_head_tail.symm.trans (congr_arg₂ Vector.cons hv v.tail.eq_nil) #align equiv.perm.vectors_prod_eq_one.one_eq Equiv.Perm.VectorsProdEqOne.one_eq instance zeroUnique : Unique (vectorsProdEqOne G 0) := by rw [zero_eq] exact Set.uniqueSingleton Vector.nil #align equiv.perm.vectors_prod_eq_one.zero_unique Equiv.Perm.VectorsProdEqOne.zeroUnique instance oneUnique : Unique (vectorsProdEqOne G 1) := by rw [one_eq] exact Set.uniqueSingleton (Vector.nil.cons 1) #align equiv.perm.vectors_prod_eq_one.one_unique Equiv.Perm.VectorsProdEqOne.oneUnique /-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`, by appending the inverse of the product of `v`. -/ @[simps] def vectorEquiv : Vector G n ≃ vectorsProdEqOne G (n + 1) where toFun v := ⟨v.toList.prod⁻¹ ::ᵥ v, by rw [mem_iff, Vector.toList_cons, List.prod_cons, inv_mul_self]⟩ invFun v := v.1.tail left_inv v := v.tail_cons v.toList.prod⁻¹ right_inv v := Subtype.ext <| calc v.1.tail.toList.prod⁻¹ ::ᵥ v.1.tail = v.1.head ::ᵥ v.1.tail := congr_arg (· ::ᵥ v.1.tail) <| Eq.symm <| eq_inv_of_mul_eq_one_left <| by rw [← List.prod_cons, ← Vector.toList_cons, v.1.cons_head_tail] exact v.2 _ = v.1 := v.1.cons_head_tail #align equiv.perm.vectors_prod_eq_one.vector_equiv Equiv.Perm.VectorsProdEqOne.vectorEquiv /-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`, by deleting the last entry of `v`. -/ def equivVector : ∀ n, vectorsProdEqOne G n ≃ Vector G (n - 1) | 0 => (equivOfUnique (vectorsProdEqOne G 0) (vectorsProdEqOne G 1)).trans (vectorEquiv G 0).symm | (n + 1) => (vectorEquiv G n).symm #align equiv.perm.vectors_prod_eq_one.equiv_vector Equiv.Perm.VectorsProdEqOne.equivVector instance [Fintype G] : Fintype (vectorsProdEqOne G n) := Fintype.ofEquiv (Vector G (n - 1)) (equivVector G n).symm theorem card [Fintype G] : Fintype.card (vectorsProdEqOne G n) = Fintype.card G ^ (n - 1) := (Fintype.card_congr (equivVector G n)).trans (card_vector (n - 1)) #align equiv.perm.vectors_prod_eq_one.card Equiv.Perm.VectorsProdEqOne.card variable {G n} {g : G} variable (v : vectorsProdEqOne G n) (j k : ℕ) /-- Rotate a vector whose product is 1. -/ def rotate : vectorsProdEqOne G n := ⟨⟨_, (v.1.1.length_rotate k).trans v.1.2⟩, List.prod_rotate_eq_one_of_prod_eq_one v.2 k⟩ #align equiv.perm.vectors_prod_eq_one.rotate Equiv.Perm.VectorsProdEqOne.rotate theorem rotate_zero : rotate v 0 = v := Subtype.ext (Subtype.ext v.1.1.rotate_zero) #align equiv.perm.vectors_prod_eq_one.rotate_zero Equiv.Perm.VectorsProdEqOne.rotate_zero theorem rotate_rotate : rotate (rotate v j) k = rotate v (j + k) := Subtype.ext (Subtype.ext (v.1.1.rotate_rotate j k)) #align equiv.perm.vectors_prod_eq_one.rotate_rotate Equiv.Perm.VectorsProdEqOne.rotate_rotate theorem rotate_length : rotate v n = v := Subtype.ext (Subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length)) #align equiv.perm.vectors_prod_eq_one.rotate_length Equiv.Perm.VectorsProdEqOne.rotate_length end VectorsProdEqOne /-- For every prime `p` dividing the order of a finite group `G` there exists an element of order `p` in `G`. This is known as Cauchy's theorem. -/ theorem _root_.exists_prime_orderOf_dvd_card {G : Type*} [Group G] [Fintype G] (p : ℕ) [hp : Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, orderOf x = p := by have hp' : p - 1 ≠ 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_lt hp.out.one_lt) have Scard := calc p ∣ Fintype.card G ^ (p - 1) := hdvd.trans (dvd_pow (dvd_refl _) hp') _ = Fintype.card (vectorsProdEqOne G p) := (VectorsProdEqOne.card G p).symm let f : ℕ → vectorsProdEqOne G p → vectorsProdEqOne G p := fun k v => VectorsProdEqOne.rotate v k have hf1 : ∀ v, f 0 v = v := VectorsProdEqOne.rotate_zero have hf2 : ∀ j k v, f k (f j v) = f (j + k) v := fun j k v => VectorsProdEqOne.rotate_rotate v j k have hf3 : ∀ v, f p v = v := VectorsProdEqOne.rotate_length let σ := Equiv.mk (f 1) (f (p - 1)) (fun s => by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3]) fun s => by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3] have hσ : ∀ k v, (σ ^ k) v = f k v := fun k => Nat.rec (fun v => (hf1 v).symm) (fun k hk v => by rw [pow_succ, Perm.mul_apply, hk (σ v), Nat.succ_eq_one_add, ← hf2 1 k] simp only [σ, coe_fn_mk]) k replace hσ : σ ^ p ^ 1 = 1 := Perm.ext fun v => by rw [pow_one, hσ, hf3, one_apply] let v₀ : vectorsProdEqOne G p := ⟨Vector.replicate p 1, (List.prod_replicate p 1).trans (one_pow p)⟩ have hv₀ : σ v₀ = v₀ := Subtype.ext (Subtype.ext (List.rotate_replicate (1 : G) p 1)) obtain ⟨v, hv1, hv2⟩ := exists_fixed_point_of_prime' Scard hσ hv₀ refine Exists.imp (fun g hg => orderOf_eq_prime ?_ fun hg' => hv2 ?_) (List.rotate_one_eq_self_iff_eq_replicate.mp (Subtype.ext_iff.mp (Subtype.ext_iff.mp hv1))) · rw [← List.prod_replicate, ← v.1.2, ← hg, show v.val.val.prod = 1 from v.2] · rw [Subtype.ext_iff_val, Subtype.ext_iff_val, hg, hg', v.1.2] simp only [v₀, Vector.replicate] #align exists_prime_order_of_dvd_card exists_prime_orderOf_dvd_card /-- For every prime `p` dividing the order of a finite additive group `G` there exists an element of order `p` in `G`. This is the additive version of Cauchy's theorem. -/ theorem _root_.exists_prime_addOrderOf_dvd_card {G : Type*} [AddGroup G] [Fintype G] (p : ℕ) [hp : Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, addOrderOf x = p := @exists_prime_orderOf_dvd_card (Multiplicative G) _ _ _ _ (by convert hdvd) #align exists_prime_add_order_of_dvd_card exists_prime_addOrderOf_dvd_card attribute [to_additive existing] exists_prime_orderOf_dvd_card end Cauchy theorem subgroup_eq_top_of_swap_mem [DecidableEq α] {H : Subgroup (Perm α)} [d : DecidablePred (· ∈ H)] {τ : Perm α} (h0 : (Fintype.card α).Prime) (h1 : Fintype.card α ∣ Fintype.card H) (h2 : τ ∈ H) (h3 : IsSwap τ) : H = ⊤ := by haveI : Fact (Fintype.card α).Prime := ⟨h0⟩ obtain ⟨σ, hσ⟩ := exists_prime_orderOf_dvd_card (Fintype.card α) h1 have hσ1 : orderOf (σ : Perm α) = Fintype.card α := (Subgroup.orderOf_coe σ).trans hσ have hσ2 : IsCycle ↑σ := isCycle_of_prime_order'' h0 hσ1 have hσ3 : (σ : Perm α).support = ⊤ := Finset.eq_univ_of_card (σ : Perm α).support (hσ2.orderOf.symm.trans hσ1) have hσ4 : Subgroup.closure {↑σ, τ} = ⊤ := closure_prime_cycle_swap h0 hσ2 hσ3 h3 rw [eq_top_iff, ← hσ4, Subgroup.closure_le, Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨Subtype.mem σ, h2⟩ #align equiv.perm.subgroup_eq_top_of_swap_mem Equiv.Perm.subgroup_eq_top_of_swap_mem section Partition variable [DecidableEq α] /-- The partition corresponding to a permutation -/ def partition (σ : Perm α) : (Fintype.card α).Partition where parts := σ.cycleType + Multiset.replicate (Fintype.card α - σ.support.card) 1 parts_pos {n hn} := by cases' mem_add.mp hn with hn hn · exact zero_lt_one.trans (one_lt_of_mem_cycleType hn) · exact lt_of_lt_of_le zero_lt_one (ge_of_eq (Multiset.eq_of_mem_replicate hn)) parts_sum := by rw [sum_add, sum_cycleType, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id, mul_one, add_tsub_cancel_of_le σ.support.card_le_univ] #align equiv.perm.partition Equiv.Perm.partition theorem parts_partition {σ : Perm α} : σ.partition.parts = σ.cycleType + Multiset.replicate (Fintype.card α - σ.support.card) 1 := rfl #align equiv.perm.parts_partition Equiv.Perm.parts_partition theorem filter_parts_partition_eq_cycleType {σ : Perm α} : ((partition σ).parts.filter fun n => 2 ≤ n) = σ.cycleType := by rw [parts_partition, filter_add, Multiset.filter_eq_self.2 fun _ => two_le_of_mem_cycleType, Multiset.filter_eq_nil.2 fun a h => ?_, add_zero] rw [Multiset.eq_of_mem_replicate h] decide #align equiv.perm.filter_parts_partition_eq_cycle_type Equiv.Perm.filter_parts_partition_eq_cycleType theorem partition_eq_of_isConj {σ τ : Perm α} : IsConj σ τ ↔ σ.partition = τ.partition := by rw [isConj_iff_cycleType_eq] refine ⟨fun h => ?_, fun h => ?_⟩ · rw [Nat.Partition.ext_iff, parts_partition, parts_partition, ← sum_cycleType, ← sum_cycleType, h] · rw [← filter_parts_partition_eq_cycleType, ← filter_parts_partition_eq_cycleType, h] #align equiv.perm.partition_eq_of_is_conj Equiv.Perm.partition_eq_of_isConj end Partition /-! ### 3-cycles -/ /-- A three-cycle is a cycle of length 3. -/ def IsThreeCycle [DecidableEq α] (σ : Perm α) : Prop := σ.cycleType = {3} #align equiv.perm.is_three_cycle Equiv.Perm.IsThreeCycle namespace IsThreeCycle variable [DecidableEq α] {σ : Perm α} theorem cycleType (h : IsThreeCycle σ) : σ.cycleType = {3} := h #align equiv.perm.is_three_cycle.cycle_type Equiv.Perm.IsThreeCycle.cycleType theorem card_support (h : IsThreeCycle σ) : σ.support.card = 3 := by rw [← sum_cycleType, h.cycleType, Multiset.sum_singleton] #align equiv.perm.is_three_cycle.card_support Equiv.Perm.IsThreeCycle.card_support theorem _root_.card_support_eq_three_iff : σ.support.card = 3 ↔ σ.IsThreeCycle := by refine ⟨fun h => ?_, IsThreeCycle.card_support⟩ by_cases h0 : σ.cycleType = 0 · rw [← sum_cycleType, h0, sum_zero] at h exact (ne_of_lt zero_lt_three h).elim obtain ⟨n, hn⟩ := exists_mem_of_ne_zero h0 by_cases h1 : σ.cycleType.erase n = 0 · rw [← sum_cycleType, ← cons_erase hn, h1, cons_zero, Multiset.sum_singleton] at h rw [IsThreeCycle, ← cons_erase hn, h1, h, ← cons_zero] obtain ⟨m, hm⟩ := exists_mem_of_ne_zero h1 rw [← sum_cycleType, ← cons_erase hn, ← cons_erase hm, Multiset.sum_cons, Multiset.sum_cons] at h have : ∀ {k}, 2 ≤ m → 2 ≤ n → n + (m + k) = 3 → False := by omega cases this (two_le_of_mem_cycleType (mem_of_mem_erase hm)) (two_le_of_mem_cycleType hn) h #align card_support_eq_three_iff card_support_eq_three_iff theorem isCycle (h : IsThreeCycle σ) : IsCycle σ := by rw [← card_cycleType_eq_one, h.cycleType, card_singleton] #align equiv.perm.is_three_cycle.is_cycle Equiv.Perm.IsThreeCycle.isCycle theorem sign (h : IsThreeCycle σ) : sign σ = 1 := by rw [Equiv.Perm.sign_of_cycleType, h.cycleType] rfl #align equiv.perm.is_three_cycle.sign Equiv.Perm.IsThreeCycle.sign theorem inv {f : Perm α} (h : IsThreeCycle f) : IsThreeCycle f⁻¹ := by rwa [IsThreeCycle, cycleType_inv] #align equiv.perm.is_three_cycle.inv Equiv.Perm.IsThreeCycle.inv @[simp] theorem inv_iff {f : Perm α} : IsThreeCycle f⁻¹ ↔ IsThreeCycle f := ⟨by rw [← inv_inv f] apply inv, inv⟩ #align equiv.perm.is_three_cycle.inv_iff Equiv.Perm.IsThreeCycle.inv_iff theorem orderOf {g : Perm α} (ht : IsThreeCycle g) : orderOf g = 3 := by rw [← lcm_cycleType, ht.cycleType, Multiset.lcm_singleton, normalize_eq] #align equiv.perm.is_three_cycle.order_of Equiv.Perm.IsThreeCycle.orderOf theorem isThreeCycle_sq {g : Perm α} (ht : IsThreeCycle g) : IsThreeCycle (g * g) := by rw [← pow_two, ← card_support_eq_three_iff, support_pow_coprime, ht.card_support] rw [ht.orderOf] norm_num #align equiv.perm.is_three_cycle.is_three_cycle_sq Equiv.Perm.IsThreeCycle.isThreeCycle_sq end IsThreeCycle section variable [DecidableEq α]
Mathlib/GroupTheory/Perm/Cycle/Type.lean
644
660
theorem isThreeCycle_swap_mul_swap_same {a b c : α} (ab : a ≠ b) (ac : a ≠ c) (bc : b ≠ c) : IsThreeCycle (swap a b * swap a c) := by
suffices h : support (swap a b * swap a c) = {a, b, c} by rw [← card_support_eq_three_iff, h] simp [ab, ac, bc] apply le_antisymm ((support_mul_le _ _).trans fun x => _) fun x hx => ?_ · simp [ab, ac, bc] · simp only [Finset.mem_insert, Finset.mem_singleton] at hx rw [mem_support] simp only [Perm.coe_mul, Function.comp_apply, Ne] obtain rfl | rfl | rfl := hx · rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm] exact ac.symm · rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right] exact ab · rw [swap_apply_right, swap_apply_left] exact bc
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp #align_import analysis.calculus.fderiv.add from "leanprover-community/mathlib"@"e3fb84046afd187b710170887195d50bada934ee" /-! # Additive operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] /-! ### Derivative of a function multiplied by a constant -/ @[fun_prop] theorem HasStrictFDerivAt.const_smul (h : HasStrictFDerivAt f f' x) (c : R) : HasStrictFDerivAt (fun x => c • f x) (c • f') x := (c • (1 : F →L[𝕜] F)).hasStrictFDerivAt.comp x h #align has_strict_fderiv_at.const_smul HasStrictFDerivAt.const_smul theorem HasFDerivAtFilter.const_smul (h : HasFDerivAtFilter f f' x L) (c : R) : HasFDerivAtFilter (fun x => c • f x) (c • f') x L := (c • (1 : F →L[𝕜] F)).hasFDerivAtFilter.comp x h tendsto_map #align has_fderiv_at_filter.const_smul HasFDerivAtFilter.const_smul @[fun_prop] nonrec theorem HasFDerivWithinAt.const_smul (h : HasFDerivWithinAt f f' s x) (c : R) : HasFDerivWithinAt (fun x => c • f x) (c • f') s x := h.const_smul c #align has_fderiv_within_at.const_smul HasFDerivWithinAt.const_smul @[fun_prop] nonrec theorem HasFDerivAt.const_smul (h : HasFDerivAt f f' x) (c : R) : HasFDerivAt (fun x => c • f x) (c • f') x := h.const_smul c #align has_fderiv_at.const_smul HasFDerivAt.const_smul @[fun_prop] theorem DifferentiableWithinAt.const_smul (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : DifferentiableWithinAt 𝕜 (fun y => c • f y) s x := (h.hasFDerivWithinAt.const_smul c).differentiableWithinAt #align differentiable_within_at.const_smul DifferentiableWithinAt.const_smul @[fun_prop] theorem DifferentiableAt.const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : DifferentiableAt 𝕜 (fun y => c • f y) x := (h.hasFDerivAt.const_smul c).differentiableAt #align differentiable_at.const_smul DifferentiableAt.const_smul @[fun_prop] theorem DifferentiableOn.const_smul (h : DifferentiableOn 𝕜 f s) (c : R) : DifferentiableOn 𝕜 (fun y => c • f y) s := fun x hx => (h x hx).const_smul c #align differentiable_on.const_smul DifferentiableOn.const_smul @[fun_prop] theorem Differentiable.const_smul (h : Differentiable 𝕜 f) (c : R) : Differentiable 𝕜 fun y => c • f y := fun x => (h x).const_smul c #align differentiable.const_smul Differentiable.const_smul theorem fderivWithin_const_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (fun y => c • f y) s x = c • fderivWithin 𝕜 f s x := (h.hasFDerivWithinAt.const_smul c).fderivWithin hxs #align fderiv_within_const_smul fderivWithin_const_smul theorem fderiv_const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (fun y => c • f y) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv #align fderiv_const_smul fderiv_const_smul end ConstSMul section Add /-! ### Derivative of the sum of two functions -/ @[fun_prop] nonrec theorem HasStrictFDerivAt.add (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => f y + g y) (f' + g') x := (hf.add hg).congr_left fun y => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel #align has_strict_fderiv_at.add HasStrictFDerivAt.add theorem HasFDerivAtFilter.add (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun y => f y + g y) (f' + g') x L := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun _ => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel #align has_fderiv_at_filter.add HasFDerivAtFilter.add @[fun_prop] nonrec theorem HasFDerivWithinAt.add (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg #align has_fderiv_within_at.add HasFDerivWithinAt.add @[fun_prop] nonrec theorem HasFDerivAt.add (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg #align has_fderiv_at.add HasFDerivAt.add @[fun_prop] theorem DifferentiableWithinAt.add (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y + g y) s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.add DifferentiableWithinAt.add @[simp, fun_prop] theorem DifferentiableAt.add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x := (hf.hasFDerivAt.add hg.hasFDerivAt).differentiableAt #align differentiable_at.add DifferentiableAt.add @[fun_prop] theorem DifferentiableOn.add (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s := fun x hx => (hf x hx).add (hg x hx) #align differentiable_on.add DifferentiableOn.add @[simp, fun_prop] theorem Differentiable.add (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y + g y := fun x => (hf x).add (hg x) #align differentiable.add Differentiable.add theorem fderivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y + g y) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_add fderivWithin_add theorem fderiv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.hasFDerivAt.add hg.hasFDerivAt).fderiv #align fderiv_add fderiv_add @[fun_prop] theorem HasStrictFDerivAt.add_const (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun y => f y + c) f' x := add_zero f' ▸ hf.add (hasStrictFDerivAt_const _ _) #align has_strict_fderiv_at.add_const HasStrictFDerivAt.add_const theorem HasFDerivAtFilter.add_const (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun y => f y + c) f' x L := add_zero f' ▸ hf.add (hasFDerivAtFilter_const _ _ _) #align has_fderiv_at_filter.add_const HasFDerivAtFilter.add_const @[fun_prop] nonrec theorem HasFDerivWithinAt.add_const (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun y => f y + c) f' s x := hf.add_const c #align has_fderiv_within_at.add_const HasFDerivWithinAt.add_const @[fun_prop] nonrec theorem HasFDerivAt.add_const (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => f x + c) f' x := hf.add_const c #align has_fderiv_at.add_const HasFDerivAt.add_const @[fun_prop] theorem DifferentiableWithinAt.add_const (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y + c) s x := (hf.hasFDerivWithinAt.add_const c).differentiableWithinAt #align differentiable_within_at.add_const DifferentiableWithinAt.add_const @[simp] theorem differentiableWithinAt_add_const_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y + c) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ #align differentiable_within_at_add_const_iff differentiableWithinAt_add_const_iff @[fun_prop] theorem DifferentiableAt.add_const (hf : DifferentiableAt 𝕜 f x) (c : F) : DifferentiableAt 𝕜 (fun y => f y + c) x := (hf.hasFDerivAt.add_const c).differentiableAt #align differentiable_at.add_const DifferentiableAt.add_const @[simp] theorem differentiableAt_add_const_iff (c : F) : DifferentiableAt 𝕜 (fun y => f y + c) x ↔ DifferentiableAt 𝕜 f x := ⟨fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ #align differentiable_at_add_const_iff differentiableAt_add_const_iff @[fun_prop] theorem DifferentiableOn.add_const (hf : DifferentiableOn 𝕜 f s) (c : F) : DifferentiableOn 𝕜 (fun y => f y + c) s := fun x hx => (hf x hx).add_const c #align differentiable_on.add_const DifferentiableOn.add_const @[simp] theorem differentiableOn_add_const_iff (c : F) : DifferentiableOn 𝕜 (fun y => f y + c) s ↔ DifferentiableOn 𝕜 f s := ⟨fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ #align differentiable_on_add_const_iff differentiableOn_add_const_iff @[fun_prop] theorem Differentiable.add_const (hf : Differentiable 𝕜 f) (c : F) : Differentiable 𝕜 fun y => f y + c := fun x => (hf x).add_const c #align differentiable.add_const Differentiable.add_const @[simp] theorem differentiable_add_const_iff (c : F) : (Differentiable 𝕜 fun y => f y + c) ↔ Differentiable 𝕜 f := ⟨fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ #align differentiable_add_const_iff differentiable_add_const_iff theorem fderivWithin_add_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : fderivWithin 𝕜 (fun y => f y + c) s x = fderivWithin 𝕜 f s x := if hf : DifferentiableWithinAt 𝕜 f s x then (hf.hasFDerivWithinAt.add_const c).fderivWithin hxs else by rw [fderivWithin_zero_of_not_differentiableWithinAt hf, fderivWithin_zero_of_not_differentiableWithinAt] simpa #align fderiv_within_add_const fderivWithin_add_const theorem fderiv_add_const (c : F) : fderiv 𝕜 (fun y => f y + c) x = fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_add_const uniqueDiffWithinAt_univ] #align fderiv_add_const fderiv_add_const @[fun_prop] theorem HasStrictFDerivAt.const_add (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun y => c + f y) f' x := zero_add f' ▸ (hasStrictFDerivAt_const _ _).add hf #align has_strict_fderiv_at.const_add HasStrictFDerivAt.const_add theorem HasFDerivAtFilter.const_add (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun y => c + f y) f' x L := zero_add f' ▸ (hasFDerivAtFilter_const _ _ _).add hf #align has_fderiv_at_filter.const_add HasFDerivAtFilter.const_add @[fun_prop] nonrec theorem HasFDerivWithinAt.const_add (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun y => c + f y) f' s x := hf.const_add c #align has_fderiv_within_at.const_add HasFDerivWithinAt.const_add @[fun_prop] nonrec theorem HasFDerivAt.const_add (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => c + f x) f' x := hf.const_add c #align has_fderiv_at.const_add HasFDerivAt.const_add @[fun_prop] theorem DifferentiableWithinAt.const_add (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x := (hf.hasFDerivWithinAt.const_add c).differentiableWithinAt #align differentiable_within_at.const_add DifferentiableWithinAt.const_add @[simp] theorem differentiableWithinAt_const_add_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ #align differentiable_within_at_const_add_iff differentiableWithinAt_const_add_iff @[fun_prop] theorem DifferentiableAt.const_add (hf : DifferentiableAt 𝕜 f x) (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x := (hf.hasFDerivAt.const_add c).differentiableAt #align differentiable_at.const_add DifferentiableAt.const_add @[simp] theorem differentiableAt_const_add_iff (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x ↔ DifferentiableAt 𝕜 f x := ⟨fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ #align differentiable_at_const_add_iff differentiableAt_const_add_iff @[fun_prop] theorem DifferentiableOn.const_add (hf : DifferentiableOn 𝕜 f s) (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s := fun x hx => (hf x hx).const_add c #align differentiable_on.const_add DifferentiableOn.const_add @[simp] theorem differentiableOn_const_add_iff (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s ↔ DifferentiableOn 𝕜 f s := ⟨fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ #align differentiable_on_const_add_iff differentiableOn_const_add_iff @[fun_prop] theorem Differentiable.const_add (hf : Differentiable 𝕜 f) (c : F) : Differentiable 𝕜 fun y => c + f y := fun x => (hf x).const_add c #align differentiable.const_add Differentiable.const_add @[simp] theorem differentiable_const_add_iff (c : F) : (Differentiable 𝕜 fun y => c + f y) ↔ Differentiable 𝕜 f := ⟨fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ #align differentiable_const_add_iff differentiable_const_add_iff theorem fderivWithin_const_add (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : fderivWithin 𝕜 (fun y => c + f y) s x = fderivWithin 𝕜 f s x := by simpa only [add_comm] using fderivWithin_add_const hxs c #align fderiv_within_const_add fderivWithin_const_add theorem fderiv_const_add (c : F) : fderiv 𝕜 (fun y => c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const] #align fderiv_const_add fderiv_const_add end Add section Sum /-! ### Derivative of a finite sum of functions -/ variable {ι : Type*} {u : Finset ι} {A : ι → E → F} {A' : ι → E →L[𝕜] F} @[fun_prop] theorem HasStrictFDerivAt.sum (h : ∀ i ∈ u, HasStrictFDerivAt (A i) (A' i) x) : HasStrictFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by dsimp [HasStrictFDerivAt] at * convert IsLittleO.sum h simp [Finset.sum_sub_distrib, ContinuousLinearMap.sum_apply] #align has_strict_fderiv_at.sum HasStrictFDerivAt.sum theorem HasFDerivAtFilter.sum (h : ∀ i ∈ u, HasFDerivAtFilter (A i) (A' i) x L) : HasFDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by simp only [hasFDerivAtFilter_iff_isLittleO] at * convert IsLittleO.sum h simp [ContinuousLinearMap.sum_apply] #align has_fderiv_at_filter.sum HasFDerivAtFilter.sum @[fun_prop] theorem HasFDerivWithinAt.sum (h : ∀ i ∈ u, HasFDerivWithinAt (A i) (A' i) s x) : HasFDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x := HasFDerivAtFilter.sum h #align has_fderiv_within_at.sum HasFDerivWithinAt.sum @[fun_prop] theorem HasFDerivAt.sum (h : ∀ i ∈ u, HasFDerivAt (A i) (A' i) x) : HasFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := HasFDerivAtFilter.sum h #align has_fderiv_at.sum HasFDerivAt.sum @[fun_prop] theorem DifferentiableWithinAt.sum (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : DifferentiableWithinAt 𝕜 (fun y => ∑ i ∈ u, A i y) s x := HasFDerivWithinAt.differentiableWithinAt <| HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt #align differentiable_within_at.sum DifferentiableWithinAt.sum @[simp, fun_prop] theorem DifferentiableAt.sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : DifferentiableAt 𝕜 (fun y => ∑ i ∈ u, A i y) x := HasFDerivAt.differentiableAt <| HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt #align differentiable_at.sum DifferentiableAt.sum @[fun_prop] theorem DifferentiableOn.sum (h : ∀ i ∈ u, DifferentiableOn 𝕜 (A i) s) : DifferentiableOn 𝕜 (fun y => ∑ i ∈ u, A i y) s := fun x hx => DifferentiableWithinAt.sum fun i hi => h i hi x hx #align differentiable_on.sum DifferentiableOn.sum @[simp, fun_prop] theorem Differentiable.sum (h : ∀ i ∈ u, Differentiable 𝕜 (A i)) : Differentiable 𝕜 fun y => ∑ i ∈ u, A i y := fun x => DifferentiableAt.sum fun i hi => h i hi x #align differentiable.sum Differentiable.sum theorem fderivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : fderivWithin 𝕜 (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, fderivWithin 𝕜 (A i) s x := (HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_sum fderivWithin_sum theorem fderiv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : fderiv 𝕜 (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, fderiv 𝕜 (A i) x := (HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt).fderiv #align fderiv_sum fderiv_sum end Sum section Neg /-! ### Derivative of the negative of a function -/ @[fun_prop] theorem HasStrictFDerivAt.neg (h : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => -f x) (-f') x := (-1 : F →L[𝕜] F).hasStrictFDerivAt.comp x h #align has_strict_fderiv_at.neg HasStrictFDerivAt.neg theorem HasFDerivAtFilter.neg (h : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter (fun x => -f x) (-f') x L := (-1 : F →L[𝕜] F).hasFDerivAtFilter.comp x h tendsto_map #align has_fderiv_at_filter.neg HasFDerivAtFilter.neg @[fun_prop] nonrec theorem HasFDerivWithinAt.neg (h : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => -f x) (-f') s x := h.neg #align has_fderiv_within_at.neg HasFDerivWithinAt.neg @[fun_prop] nonrec theorem HasFDerivAt.neg (h : HasFDerivAt f f' x) : HasFDerivAt (fun x => -f x) (-f') x := h.neg #align has_fderiv_at.neg HasFDerivAt.neg @[fun_prop] theorem DifferentiableWithinAt.neg (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => -f y) s x := h.hasFDerivWithinAt.neg.differentiableWithinAt #align differentiable_within_at.neg DifferentiableWithinAt.neg @[simp] theorem differentiableWithinAt_neg_iff : DifferentiableWithinAt 𝕜 (fun y => -f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ #align differentiable_within_at_neg_iff differentiableWithinAt_neg_iff @[fun_prop] theorem DifferentiableAt.neg (h : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => -f y) x := h.hasFDerivAt.neg.differentiableAt #align differentiable_at.neg DifferentiableAt.neg @[simp] theorem differentiableAt_neg_iff : DifferentiableAt 𝕜 (fun y => -f y) x ↔ DifferentiableAt 𝕜 f x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ #align differentiable_at_neg_iff differentiableAt_neg_iff @[fun_prop] theorem DifferentiableOn.neg (h : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => -f y) s := fun x hx => (h x hx).neg #align differentiable_on.neg DifferentiableOn.neg @[simp] theorem differentiableOn_neg_iff : DifferentiableOn 𝕜 (fun y => -f y) s ↔ DifferentiableOn 𝕜 f s := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ #align differentiable_on_neg_iff differentiableOn_neg_iff @[fun_prop] theorem Differentiable.neg (h : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => -f y := fun x => (h x).neg #align differentiable.neg Differentiable.neg @[simp] theorem differentiable_neg_iff : (Differentiable 𝕜 fun y => -f y) ↔ Differentiable 𝕜 f := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ #align differentiable_neg_iff differentiable_neg_iff theorem fderivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun y => -f y) s x = -fderivWithin 𝕜 f s x := if h : DifferentiableWithinAt 𝕜 f s x then h.hasFDerivWithinAt.neg.fderivWithin hxs else by rw [fderivWithin_zero_of_not_differentiableWithinAt h, fderivWithin_zero_of_not_differentiableWithinAt, neg_zero] simpa #align fderiv_within_neg fderivWithin_neg @[simp] theorem fderiv_neg : fderiv 𝕜 (fun y => -f y) x = -fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_neg uniqueDiffWithinAt_univ] #align fderiv_neg fderiv_neg end Neg section Sub /-! ### Derivative of the difference of two functions -/ @[fun_prop] theorem HasStrictFDerivAt.sub (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun x => f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_strict_fderiv_at.sub HasStrictFDerivAt.sub theorem HasFDerivAtFilter.sub (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun x => f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_fderiv_at_filter.sub HasFDerivAtFilter.sub @[fun_prop] nonrec theorem HasFDerivWithinAt.sub (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun x => f x - g x) (f' - g') s x := hf.sub hg #align has_fderiv_within_at.sub HasFDerivWithinAt.sub @[fun_prop] nonrec theorem HasFDerivAt.sub (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x - g x) (f' - g') x := hf.sub hg #align has_fderiv_at.sub HasFDerivAt.sub @[fun_prop] theorem DifferentiableWithinAt.sub (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y - g y) s x := (hf.hasFDerivWithinAt.sub hg.hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.sub DifferentiableWithinAt.sub @[simp, fun_prop] theorem DifferentiableAt.sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y - g y) x := (hf.hasFDerivAt.sub hg.hasFDerivAt).differentiableAt #align differentiable_at.sub DifferentiableAt.sub @[fun_prop] theorem DifferentiableOn.sub (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y - g y) s := fun x hx => (hf x hx).sub (hg x hx) #align differentiable_on.sub DifferentiableOn.sub @[simp, fun_prop] theorem Differentiable.sub (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y - g y := fun x => (hf x).sub (hg x) #align differentiable.sub Differentiable.sub theorem fderivWithin_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y - g y) s x = fderivWithin 𝕜 f s x - fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.sub hg.hasFDerivWithinAt).fderivWithin hxs #align fderiv_within_sub fderivWithin_sub theorem fderiv_sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x := (hf.hasFDerivAt.sub hg.hasFDerivAt).fderiv #align fderiv_sub fderiv_sub @[fun_prop] theorem HasStrictFDerivAt.sub_const (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun x => f x - c) f' x := by simpa only [sub_eq_add_neg] using hf.add_const (-c) #align has_strict_fderiv_at.sub_const HasStrictFDerivAt.sub_const theorem HasFDerivAtFilter.sub_const (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun x => f x - c) f' x L := by simpa only [sub_eq_add_neg] using hf.add_const (-c) #align has_fderiv_at_filter.sub_const HasFDerivAtFilter.sub_const @[fun_prop] nonrec theorem HasFDerivWithinAt.sub_const (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun x => f x - c) f' s x := hf.sub_const c #align has_fderiv_within_at.sub_const HasFDerivWithinAt.sub_const @[fun_prop] nonrec theorem HasFDerivAt.sub_const (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => f x - c) f' x := hf.sub_const c #align has_fderiv_at.sub_const HasFDerivAt.sub_const @[fun_prop] theorem hasStrictFDerivAt_sub_const {x : F} (c : F) : HasStrictFDerivAt (· - c) (id 𝕜 F) x := (hasStrictFDerivAt_id x).sub_const c @[fun_prop] theorem hasFDerivAt_sub_const {x : F} (c : F) : HasFDerivAt (· - c) (id 𝕜 F) x := (hasFDerivAt_id x).sub_const c @[fun_prop] theorem DifferentiableWithinAt.sub_const (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y - c) s x := (hf.hasFDerivWithinAt.sub_const c).differentiableWithinAt #align differentiable_within_at.sub_const DifferentiableWithinAt.sub_const @[simp] theorem differentiableWithinAt_sub_const_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y - c) s x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [sub_eq_add_neg, differentiableWithinAt_add_const_iff] #align differentiable_within_at_sub_const_iff differentiableWithinAt_sub_const_iff @[fun_prop] theorem DifferentiableAt.sub_const (hf : DifferentiableAt 𝕜 f x) (c : F) : DifferentiableAt 𝕜 (fun y => f y - c) x := (hf.hasFDerivAt.sub_const c).differentiableAt #align differentiable_at.sub_const DifferentiableAt.sub_const @[simp] theorem differentiableAt_sub_const_iff (c : F) : DifferentiableAt 𝕜 (fun y => f y - c) x ↔ DifferentiableAt 𝕜 f x := by simp only [sub_eq_add_neg, differentiableAt_add_const_iff] #align differentiable_at_sub_const_iff differentiableAt_sub_const_iff @[fun_prop] theorem DifferentiableOn.sub_const (hf : DifferentiableOn 𝕜 f s) (c : F) : DifferentiableOn 𝕜 (fun y => f y - c) s := fun x hx => (hf x hx).sub_const c #align differentiable_on.sub_const DifferentiableOn.sub_const @[simp] theorem differentiableOn_sub_const_iff (c : F) : DifferentiableOn 𝕜 (fun y => f y - c) s ↔ DifferentiableOn 𝕜 f s := by simp only [sub_eq_add_neg, differentiableOn_add_const_iff] #align differentiable_on_sub_const_iff differentiableOn_sub_const_iff @[fun_prop] theorem Differentiable.sub_const (hf : Differentiable 𝕜 f) (c : F) : Differentiable 𝕜 fun y => f y - c := fun x => (hf x).sub_const c #align differentiable.sub_const Differentiable.sub_const @[simp] theorem differentiable_sub_const_iff (c : F) : (Differentiable 𝕜 fun y => f y - c) ↔ Differentiable 𝕜 f := by simp only [sub_eq_add_neg, differentiable_add_const_iff] #align differentiable_sub_const_iff differentiable_sub_const_iff theorem fderivWithin_sub_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : fderivWithin 𝕜 (fun y => f y - c) s x = fderivWithin 𝕜 f s x := by simp only [sub_eq_add_neg, fderivWithin_add_const hxs] #align fderiv_within_sub_const fderivWithin_sub_const theorem fderiv_sub_const (c : F) : fderiv 𝕜 (fun y => f y - c) x = fderiv 𝕜 f x := by simp only [sub_eq_add_neg, fderiv_add_const] #align fderiv_sub_const fderiv_sub_const @[fun_prop] theorem HasStrictFDerivAt.const_sub (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun x => c - f x) (-f') x := by simpa only [sub_eq_add_neg] using hf.neg.const_add c #align has_strict_fderiv_at.const_sub HasStrictFDerivAt.const_sub theorem HasFDerivAtFilter.const_sub (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun x => c - f x) (-f') x L := by simpa only [sub_eq_add_neg] using hf.neg.const_add c #align has_fderiv_at_filter.const_sub HasFDerivAtFilter.const_sub @[fun_prop] nonrec theorem HasFDerivWithinAt.const_sub (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun x => c - f x) (-f') s x := hf.const_sub c #align has_fderiv_within_at.const_sub HasFDerivWithinAt.const_sub @[fun_prop] nonrec theorem HasFDerivAt.const_sub (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => c - f x) (-f') x := hf.const_sub c #align has_fderiv_at.const_sub HasFDerivAt.const_sub @[fun_prop] theorem DifferentiableWithinAt.const_sub (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => c - f y) s x := (hf.hasFDerivWithinAt.const_sub c).differentiableWithinAt #align differentiable_within_at.const_sub DifferentiableWithinAt.const_sub @[simp]
Mathlib/Analysis/Calculus/FDeriv/Add.lean
671
673
theorem differentiableWithinAt_const_sub_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c - f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp [sub_eq_add_neg]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn -/ import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Finsupp.Defs import Mathlib.Data.Nat.Cast.Order import Mathlib.Data.Set.Countable import Mathlib.Logic.Small.Set import Mathlib.Order.SuccPred.CompleteLinearOrder import Mathlib.SetTheory.Cardinal.SchroederBernstein #align_import set_theory.cardinal.basic from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8" /-! # Cardinal Numbers We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity. ## Main definitions * `Cardinal` is the type of cardinal numbers (in a given universe). * `Cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale `Cardinal`. * Addition `c₁ + c₂` is defined by `Cardinal.add_def α β : #α + #β = #(α ⊕ β)`. * Multiplication `c₁ * c₂` is defined by `Cardinal.mul_def : #α * #β = #(α × β)`. * The order `c₁ ≤ c₂` is defined by `Cardinal.le_def α β : #α ≤ #β ↔ Nonempty (α ↪ β)`. * Exponentiation `c₁ ^ c₂` is defined by `Cardinal.power_def α β : #α ^ #β = #(β → α)`. * `Cardinal.isLimit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`. * `Cardinal.aleph0` or `ℵ₀` is the cardinality of `ℕ`. This definition is universe polymorphic: `Cardinal.aleph0.{u} : Cardinal.{u}` (contrast with `ℕ : Type`, which lives in a specific universe). In some cases the universe level has to be given explicitly. * `Cardinal.sum` is the sum of an indexed family of cardinals, i.e. the cardinality of the corresponding sigma type. * `Cardinal.prod` is the product of an indexed family of cardinals, i.e. the cardinality of the corresponding pi type. * `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`. ## Main instances * Cardinals form a `CanonicallyOrderedCommSemiring` with the aforementioned sum and product. * Cardinals form a `SuccOrder`. Use `Order.succ c` for the smallest cardinal greater than `c`. * The less than relation on cardinals forms a well-order. * Cardinals form a `ConditionallyCompleteLinearOrderBot`. Bounded sets for cardinals in universe `u` are precisely the sets indexed by some type in universe `u`, see `Cardinal.bddAbove_iff_small`. One can use `sSup` for the cardinal supremum, and `sInf` for the minimum of a set of cardinals. ## Main Statements * Cantor's theorem: `Cardinal.cantor c : c < 2 ^ c`. * König's theorem: `Cardinal.sum_lt_prod` ## Implementation notes * There is a type of cardinal numbers in every universe level: `Cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`. The operation `Cardinal.lift` lifts cardinal numbers to a higher level. * Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file `Mathlib/SetTheory/Cardinal/Ordinal.lean`. * There is an instance `Pow Cardinal`, but this will only fire if Lean already knows that both the base and the exponent live in the same universe. As a workaround, you can add ``` local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _ ``` to a file. This notation will work even if Lean doesn't know yet that the base and the exponent live in the same universe (but no exponents in other types can be used). (Porting note: This last point might need to be updated.) ## References * <https://en.wikipedia.org/wiki/Cardinal_number> ## Tags cardinal number, cardinal arithmetic, cardinal exponentiation, aleph, Cantor's theorem, König's theorem, Konig's theorem -/ assert_not_exists Field assert_not_exists Module open scoped Classical open Function Set Order noncomputable section universe u v w variable {α β : Type u} /-- The equivalence relation on types given by equivalence (bijective correspondence) of types. Quotienting by this equivalence relation gives the cardinal numbers. -/ instance Cardinal.isEquivalent : Setoid (Type u) where r α β := Nonempty (α ≃ β) iseqv := ⟨ fun α => ⟨Equiv.refl α⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩ #align cardinal.is_equivalent Cardinal.isEquivalent /-- `Cardinal.{u}` is the type of cardinal numbers in `Type u`, defined as the quotient of `Type u` by existence of an equivalence (a bijection with explicit inverse). -/ @[pp_with_univ] def Cardinal : Type (u + 1) := Quotient Cardinal.isEquivalent #align cardinal Cardinal namespace Cardinal /-- The cardinal number of a type -/ def mk : Type u → Cardinal := Quotient.mk' #align cardinal.mk Cardinal.mk @[inherit_doc] scoped prefix:max "#" => Cardinal.mk instance canLiftCardinalType : CanLift Cardinal.{u} (Type u) mk fun _ => True := ⟨fun c _ => Quot.inductionOn c fun α => ⟨α, rfl⟩⟩ #align cardinal.can_lift_cardinal_Type Cardinal.canLiftCardinalType @[elab_as_elim] theorem inductionOn {p : Cardinal → Prop} (c : Cardinal) (h : ∀ α, p #α) : p c := Quotient.inductionOn c h #align cardinal.induction_on Cardinal.inductionOn @[elab_as_elim] theorem inductionOn₂ {p : Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal) (h : ∀ α β, p #α #β) : p c₁ c₂ := Quotient.inductionOn₂ c₁ c₂ h #align cardinal.induction_on₂ Cardinal.inductionOn₂ @[elab_as_elim] theorem inductionOn₃ {p : Cardinal → Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal) (c₃ : Cardinal) (h : ∀ α β γ, p #α #β #γ) : p c₁ c₂ c₃ := Quotient.inductionOn₃ c₁ c₂ c₃ h #align cardinal.induction_on₃ Cardinal.inductionOn₃ protected theorem eq : #α = #β ↔ Nonempty (α ≃ β) := Quotient.eq' #align cardinal.eq Cardinal.eq @[simp] theorem mk'_def (α : Type u) : @Eq Cardinal ⟦α⟧ #α := rfl #align cardinal.mk_def Cardinal.mk'_def @[simp] theorem mk_out (c : Cardinal) : #c.out = c := Quotient.out_eq _ #align cardinal.mk_out Cardinal.mk_out /-- The representative of the cardinal of a type is equivalent to the original type. -/ def outMkEquiv {α : Type v} : (#α).out ≃ α := Nonempty.some <| Cardinal.eq.mp (by simp) #align cardinal.out_mk_equiv Cardinal.outMkEquiv theorem mk_congr (e : α ≃ β) : #α = #β := Quot.sound ⟨e⟩ #align cardinal.mk_congr Cardinal.mk_congr alias _root_.Equiv.cardinal_eq := mk_congr #align equiv.cardinal_eq Equiv.cardinal_eq /-- Lift a function between `Type*`s to a function between `Cardinal`s. -/ def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) : Cardinal.{u} → Cardinal.{v} := Quotient.map f fun α β ⟨e⟩ => ⟨hf α β e⟩ #align cardinal.map Cardinal.map @[simp] theorem map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) : map f hf #α = #(f α) := rfl #align cardinal.map_mk Cardinal.map_mk /-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `Cardinal`s. -/ def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) : Cardinal.{u} → Cardinal.{v} → Cardinal.{w} := Quotient.map₂ f fun α β ⟨e₁⟩ γ δ ⟨e₂⟩ => ⟨hf α β γ δ e₁ e₂⟩ #align cardinal.map₂ Cardinal.map₂ /-- The universe lift operation on cardinals. You can specify the universes explicitly with `lift.{u v} : Cardinal.{v} → Cardinal.{max v u}` -/ @[pp_with_univ] def lift (c : Cardinal.{v}) : Cardinal.{max v u} := map ULift.{u, v} (fun _ _ e => Equiv.ulift.trans <| e.trans Equiv.ulift.symm) c #align cardinal.lift Cardinal.lift @[simp] theorem mk_uLift (α) : #(ULift.{v, u} α) = lift.{v} #α := rfl #align cardinal.mk_ulift Cardinal.mk_uLift -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- `lift.{max u v, u}` equals `lift.{v, u}`. -/ @[simp, nolint simpNF] theorem lift_umax : lift.{max u v, u} = lift.{v, u} := funext fun a => inductionOn a fun _ => (Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq #align cardinal.lift_umax Cardinal.lift_umax -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- `lift.{max v u, u}` equals `lift.{v, u}`. -/ @[simp, nolint simpNF] theorem lift_umax' : lift.{max v u, u} = lift.{v, u} := lift_umax #align cardinal.lift_umax' Cardinal.lift_umax' -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- A cardinal lifted to a lower or equal universe equals itself. -/ @[simp, nolint simpNF] theorem lift_id' (a : Cardinal.{max u v}) : lift.{u} a = a := inductionOn a fun _ => mk_congr Equiv.ulift #align cardinal.lift_id' Cardinal.lift_id' /-- A cardinal lifted to the same universe equals itself. -/ @[simp] theorem lift_id (a : Cardinal) : lift.{u, u} a = a := lift_id'.{u, u} a #align cardinal.lift_id Cardinal.lift_id /-- A cardinal lifted to the zero universe equals itself. -/ -- porting note (#10618): simp can prove this -- @[simp] theorem lift_uzero (a : Cardinal.{u}) : lift.{0} a = a := lift_id'.{0, u} a #align cardinal.lift_uzero Cardinal.lift_uzero @[simp] theorem lift_lift.{u_1} (a : Cardinal.{u_1}) : lift.{w} (lift.{v} a) = lift.{max v w} a := inductionOn a fun _ => (Equiv.ulift.trans <| Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq #align cardinal.lift_lift Cardinal.lift_lift /-- We define the order on cardinal numbers by `#α ≤ #β` if and only if there exists an embedding (injective function) from α to β. -/ instance : LE Cardinal.{u} := ⟨fun q₁ q₂ => Quotient.liftOn₂ q₁ q₂ (fun α β => Nonempty <| α ↪ β) fun _ _ _ _ ⟨e₁⟩ ⟨e₂⟩ => propext ⟨fun ⟨e⟩ => ⟨e.congr e₁ e₂⟩, fun ⟨e⟩ => ⟨e.congr e₁.symm e₂.symm⟩⟩⟩ instance partialOrder : PartialOrder Cardinal.{u} where le := (· ≤ ·) le_refl := by rintro ⟨α⟩ exact ⟨Embedding.refl _⟩ le_trans := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩ exact ⟨e₁.trans e₂⟩ le_antisymm := by rintro ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩ exact Quotient.sound (e₁.antisymm e₂) instance linearOrder : LinearOrder Cardinal.{u} := { Cardinal.partialOrder with le_total := by rintro ⟨α⟩ ⟨β⟩ apply Embedding.total decidableLE := Classical.decRel _ } theorem le_def (α β : Type u) : #α ≤ #β ↔ Nonempty (α ↪ β) := Iff.rfl #align cardinal.le_def Cardinal.le_def theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : Injective f) : #α ≤ #β := ⟨⟨f, hf⟩⟩ #align cardinal.mk_le_of_injective Cardinal.mk_le_of_injective theorem _root_.Function.Embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β := ⟨f⟩ #align function.embedding.cardinal_le Function.Embedding.cardinal_le theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : Surjective f) : #β ≤ #α := ⟨Embedding.ofSurjective f hf⟩ #align cardinal.mk_le_of_surjective Cardinal.mk_le_of_surjective theorem le_mk_iff_exists_set {c : Cardinal} {α : Type u} : c ≤ #α ↔ ∃ p : Set α, #p = c := ⟨inductionOn c fun _ ⟨⟨f, hf⟩⟩ => ⟨Set.range f, (Equiv.ofInjective f hf).cardinal_eq.symm⟩, fun ⟨_, e⟩ => e ▸ ⟨⟨Subtype.val, fun _ _ => Subtype.eq⟩⟩⟩ #align cardinal.le_mk_iff_exists_set Cardinal.le_mk_iff_exists_set theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(Subtype p) ≤ #α := ⟨Embedding.subtype p⟩ #align cardinal.mk_subtype_le Cardinal.mk_subtype_le theorem mk_set_le (s : Set α) : #s ≤ #α := mk_subtype_le s #align cardinal.mk_set_le Cardinal.mk_set_le @[simp] lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by rw [← mk_uLift, Cardinal.eq] constructor let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x) have : Function.Bijective f := ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective)) exact Equiv.ofBijective f this theorem out_embedding {c c' : Cardinal} : c ≤ c' ↔ Nonempty (c.out ↪ c'.out) := by trans · rw [← Quotient.out_eq c, ← Quotient.out_eq c'] · rw [mk'_def, mk'_def, le_def] #align cardinal.out_embedding Cardinal.out_embedding theorem lift_mk_le {α : Type v} {β : Type w} : lift.{max u w} #α ≤ lift.{max u v} #β ↔ Nonempty (α ↪ β) := ⟨fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift Equiv.ulift f⟩, fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift.symm Equiv.ulift.symm f⟩⟩ #align cardinal.lift_mk_le Cardinal.lift_mk_le /-- A variant of `Cardinal.lift_mk_le` with specialized universes. Because Lean often can not realize it should use this specialization itself, we provide this statement separately so you don't have to solve the specialization problem either. -/ theorem lift_mk_le' {α : Type u} {β : Type v} : lift.{v} #α ≤ lift.{u} #β ↔ Nonempty (α ↪ β) := lift_mk_le.{0} #align cardinal.lift_mk_le' Cardinal.lift_mk_le' theorem lift_mk_eq {α : Type u} {β : Type v} : lift.{max v w} #α = lift.{max u w} #β ↔ Nonempty (α ≃ β) := Quotient.eq'.trans ⟨fun ⟨f⟩ => ⟨Equiv.ulift.symm.trans <| f.trans Equiv.ulift⟩, fun ⟨f⟩ => ⟨Equiv.ulift.trans <| f.trans Equiv.ulift.symm⟩⟩ #align cardinal.lift_mk_eq Cardinal.lift_mk_eq /-- A variant of `Cardinal.lift_mk_eq` with specialized universes. Because Lean often can not realize it should use this specialization itself, we provide this statement separately so you don't have to solve the specialization problem either. -/ theorem lift_mk_eq' {α : Type u} {β : Type v} : lift.{v} #α = lift.{u} #β ↔ Nonempty (α ≃ β) := lift_mk_eq.{u, v, 0} #align cardinal.lift_mk_eq' Cardinal.lift_mk_eq' @[simp] theorem lift_le {a b : Cardinal.{v}} : lift.{u, v} a ≤ lift.{u, v} b ↔ a ≤ b := inductionOn₂ a b fun α β => by rw [← lift_umax] exact lift_mk_le.{u} #align cardinal.lift_le Cardinal.lift_le -- Porting note: changed `simps` to `simps!` because the linter told to do so. /-- `Cardinal.lift` as an `OrderEmbedding`. -/ @[simps! (config := .asFn)] def liftOrderEmbedding : Cardinal.{v} ↪o Cardinal.{max v u} := OrderEmbedding.ofMapLEIff lift.{u, v} fun _ _ => lift_le #align cardinal.lift_order_embedding Cardinal.liftOrderEmbedding theorem lift_injective : Injective lift.{u, v} := liftOrderEmbedding.injective #align cardinal.lift_injective Cardinal.lift_injective @[simp] theorem lift_inj {a b : Cardinal.{u}} : lift.{v, u} a = lift.{v, u} b ↔ a = b := lift_injective.eq_iff #align cardinal.lift_inj Cardinal.lift_inj @[simp] theorem lift_lt {a b : Cardinal.{u}} : lift.{v, u} a < lift.{v, u} b ↔ a < b := liftOrderEmbedding.lt_iff_lt #align cardinal.lift_lt Cardinal.lift_lt theorem lift_strictMono : StrictMono lift := fun _ _ => lift_lt.2 #align cardinal.lift_strict_mono Cardinal.lift_strictMono theorem lift_monotone : Monotone lift := lift_strictMono.monotone #align cardinal.lift_monotone Cardinal.lift_monotone instance : Zero Cardinal.{u} := -- `PEmpty` might be more canonical, but this is convenient for defeq with natCast ⟨lift #(Fin 0)⟩ instance : Inhabited Cardinal.{u} := ⟨0⟩ @[simp] theorem mk_eq_zero (α : Type u) [IsEmpty α] : #α = 0 := (Equiv.equivOfIsEmpty α (ULift (Fin 0))).cardinal_eq #align cardinal.mk_eq_zero Cardinal.mk_eq_zero @[simp] theorem lift_zero : lift 0 = 0 := mk_eq_zero _ #align cardinal.lift_zero Cardinal.lift_zero @[simp] theorem lift_eq_zero {a : Cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 := lift_injective.eq_iff' lift_zero #align cardinal.lift_eq_zero Cardinal.lift_eq_zero theorem mk_eq_zero_iff {α : Type u} : #α = 0 ↔ IsEmpty α := ⟨fun e => let ⟨h⟩ := Quotient.exact e h.isEmpty, @mk_eq_zero α⟩ #align cardinal.mk_eq_zero_iff Cardinal.mk_eq_zero_iff theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ Nonempty α := (not_iff_not.2 mk_eq_zero_iff).trans not_isEmpty_iff #align cardinal.mk_ne_zero_iff Cardinal.mk_ne_zero_iff @[simp] theorem mk_ne_zero (α : Type u) [Nonempty α] : #α ≠ 0 := mk_ne_zero_iff.2 ‹_› #align cardinal.mk_ne_zero Cardinal.mk_ne_zero instance : One Cardinal.{u} := -- `PUnit` might be more canonical, but this is convenient for defeq with natCast ⟨lift #(Fin 1)⟩ instance : Nontrivial Cardinal.{u} := ⟨⟨1, 0, mk_ne_zero _⟩⟩ theorem mk_eq_one (α : Type u) [Unique α] : #α = 1 := (Equiv.equivOfUnique α (ULift (Fin 1))).cardinal_eq #align cardinal.mk_eq_one Cardinal.mk_eq_one theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α := ⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ => ⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩ #align cardinal.le_one_iff_subsingleton Cardinal.le_one_iff_subsingleton @[simp] theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton := le_one_iff_subsingleton.trans s.subsingleton_coe #align cardinal.mk_le_one_iff_set_subsingleton Cardinal.mk_le_one_iff_set_subsingleton alias ⟨_, _root_.Set.Subsingleton.cardinal_mk_le_one⟩ := mk_le_one_iff_set_subsingleton #align set.subsingleton.cardinal_mk_le_one Set.Subsingleton.cardinal_mk_le_one instance : Add Cardinal.{u} := ⟨map₂ Sum fun _ _ _ _ => Equiv.sumCongr⟩ theorem add_def (α β : Type u) : #α + #β = #(Sum α β) := rfl #align cardinal.add_def Cardinal.add_def instance : NatCast Cardinal.{u} := ⟨fun n => lift #(Fin n)⟩ @[simp] theorem mk_sum (α : Type u) (β : Type v) : #(α ⊕ β) = lift.{v, u} #α + lift.{u, v} #β := mk_congr (Equiv.ulift.symm.sumCongr Equiv.ulift.symm) #align cardinal.mk_sum Cardinal.mk_sum @[simp] theorem mk_option {α : Type u} : #(Option α) = #α + 1 := by rw [(Equiv.optionEquivSumPUnit.{u, u} α).cardinal_eq, mk_sum, mk_eq_one PUnit, lift_id, lift_id] #align cardinal.mk_option Cardinal.mk_option @[simp] theorem mk_psum (α : Type u) (β : Type v) : #(PSum α β) = lift.{v} #α + lift.{u} #β := (mk_congr (Equiv.psumEquivSum α β)).trans (mk_sum α β) #align cardinal.mk_psum Cardinal.mk_psum @[simp] theorem mk_fintype (α : Type u) [h : Fintype α] : #α = Fintype.card α := mk_congr (Fintype.equivOfCardEq (by simp)) protected theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by change #(ULift.{u} (Fin (n+1))) = # (ULift.{u} (Fin n)) + 1 rw [← mk_option, mk_fintype, mk_fintype] simp only [Fintype.card_ulift, Fintype.card_fin, Fintype.card_option] instance : Mul Cardinal.{u} := ⟨map₂ Prod fun _ _ _ _ => Equiv.prodCongr⟩ theorem mul_def (α β : Type u) : #α * #β = #(α × β) := rfl #align cardinal.mul_def Cardinal.mul_def @[simp] theorem mk_prod (α : Type u) (β : Type v) : #(α × β) = lift.{v, u} #α * lift.{u, v} #β := mk_congr (Equiv.ulift.symm.prodCongr Equiv.ulift.symm) #align cardinal.mk_prod Cardinal.mk_prod private theorem mul_comm' (a b : Cardinal.{u}) : a * b = b * a := inductionOn₂ a b fun α β => mk_congr <| Equiv.prodComm α β /-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/ instance instPowCardinal : Pow Cardinal.{u} Cardinal.{u} := ⟨map₂ (fun α β => β → α) fun _ _ _ _ e₁ e₂ => e₂.arrowCongr e₁⟩ theorem power_def (α β : Type u) : #α ^ #β = #(β → α) := rfl #align cardinal.power_def Cardinal.power_def theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = (lift.{u} #β^lift.{v} #α) := mk_congr (Equiv.ulift.symm.arrowCongr Equiv.ulift.symm) #align cardinal.mk_arrow Cardinal.mk_arrow @[simp] theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = lift.{v} a ^ lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.ulift.arrowCongr Equiv.ulift).symm #align cardinal.lift_power Cardinal.lift_power @[simp] theorem power_zero {a : Cardinal} : a ^ (0 : Cardinal) = 1 := inductionOn a fun _ => mk_eq_one _ #align cardinal.power_zero Cardinal.power_zero @[simp] theorem power_one {a : Cardinal.{u}} : a ^ (1 : Cardinal) = a := inductionOn a fun α => mk_congr (Equiv.funUnique (ULift.{u} (Fin 1)) α) #align cardinal.power_one Cardinal.power_one theorem power_add {a b c : Cardinal} : a ^ (b + c) = a ^ b * a ^ c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumArrowEquivProdArrow β γ α #align cardinal.power_add Cardinal.power_add instance commSemiring : CommSemiring Cardinal.{u} where zero := 0 one := 1 add := (· + ·) mul := (· * ·) zero_add a := inductionOn a fun α => mk_congr <| Equiv.emptySum (ULift (Fin 0)) α add_zero a := inductionOn a fun α => mk_congr <| Equiv.sumEmpty α (ULift (Fin 0)) add_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumAssoc α β γ add_comm a b := inductionOn₂ a b fun α β => mk_congr <| Equiv.sumComm α β zero_mul a := inductionOn a fun α => mk_eq_zero _ mul_zero a := inductionOn a fun α => mk_eq_zero _ one_mul a := inductionOn a fun α => mk_congr <| Equiv.uniqueProd α (ULift (Fin 1)) mul_one a := inductionOn a fun α => mk_congr <| Equiv.prodUnique α (ULift (Fin 1)) mul_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodAssoc α β γ mul_comm := mul_comm' left_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodSumDistrib α β γ right_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumProdDistrib α β γ nsmul := nsmulRec npow n c := c ^ (n : Cardinal) npow_zero := @power_zero npow_succ n c := show c ^ (↑(n + 1) : Cardinal) = c ^ (↑n : Cardinal) * c by rw [Cardinal.cast_succ, power_add, power_one, mul_comm'] natCast := (fun n => lift.{u} #(Fin n) : ℕ → Cardinal.{u}) natCast_zero := rfl natCast_succ := Cardinal.cast_succ /-! Porting note (#11229): Deprecated section. Remove. -/ section deprecated set_option linter.deprecated false @[deprecated (since := "2023-02-11")] theorem power_bit0 (a b : Cardinal) : a ^ bit0 b = a ^ b * a ^ b := power_add #align cardinal.power_bit0 Cardinal.power_bit0 @[deprecated (since := "2023-02-11")] theorem power_bit1 (a b : Cardinal) : a ^ bit1 b = a ^ b * a ^ b * a := by rw [bit1, ← power_bit0, power_add, power_one] #align cardinal.power_bit1 Cardinal.power_bit1 end deprecated @[simp] theorem one_power {a : Cardinal} : (1 : Cardinal) ^ a = 1 := inductionOn a fun _ => mk_eq_one _ #align cardinal.one_power Cardinal.one_power -- porting note (#10618): simp can prove this -- @[simp] theorem mk_bool : #Bool = 2 := by simp #align cardinal.mk_bool Cardinal.mk_bool -- porting note (#10618): simp can prove this -- @[simp] theorem mk_Prop : #Prop = 2 := by simp #align cardinal.mk_Prop Cardinal.mk_Prop @[simp] theorem zero_power {a : Cardinal} : a ≠ 0 → (0 : Cardinal) ^ a = 0 := inductionOn a fun _ heq => mk_eq_zero_iff.2 <| isEmpty_pi.2 <| let ⟨a⟩ := mk_ne_zero_iff.1 heq ⟨a, inferInstance⟩ #align cardinal.zero_power Cardinal.zero_power theorem power_ne_zero {a : Cardinal} (b : Cardinal) : a ≠ 0 → a ^ b ≠ 0 := inductionOn₂ a b fun _ _ h => let ⟨a⟩ := mk_ne_zero_iff.1 h mk_ne_zero_iff.2 ⟨fun _ => a⟩ #align cardinal.power_ne_zero Cardinal.power_ne_zero theorem mul_power {a b c : Cardinal} : (a * b) ^ c = a ^ c * b ^ c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.arrowProdEquivProdArrow α β γ #align cardinal.mul_power Cardinal.mul_power theorem power_mul {a b c : Cardinal} : a ^ (b * c) = (a ^ b) ^ c := by rw [mul_comm b c] exact inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.curry γ β α #align cardinal.power_mul Cardinal.power_mul @[simp] theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : a ^ (↑n : Cardinal.{u}) = a ^ n := rfl #align cardinal.pow_cast_right Cardinal.pow_cast_right @[simp] theorem lift_one : lift 1 = 1 := mk_eq_one _ #align cardinal.lift_one Cardinal.lift_one @[simp] theorem lift_eq_one {a : Cardinal.{v}} : lift.{u} a = 1 ↔ a = 1 := lift_injective.eq_iff' lift_one @[simp] theorem lift_add (a b : Cardinal.{u}) : lift.{v} (a + b) = lift.{v} a + lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.sumCongr Equiv.ulift Equiv.ulift).symm #align cardinal.lift_add Cardinal.lift_add @[simp] theorem lift_mul (a b : Cardinal.{u}) : lift.{v} (a * b) = lift.{v} a * lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.prodCongr Equiv.ulift Equiv.ulift).symm #align cardinal.lift_mul Cardinal.lift_mul /-! Porting note (#11229): Deprecated section. Remove. -/ section deprecated set_option linter.deprecated false @[simp, deprecated (since := "2023-02-11")] theorem lift_bit0 (a : Cardinal) : lift.{v} (bit0 a) = bit0 (lift.{v} a) := lift_add a a #align cardinal.lift_bit0 Cardinal.lift_bit0 @[simp, deprecated (since := "2023-02-11")] theorem lift_bit1 (a : Cardinal) : lift.{v} (bit1 a) = bit1 (lift.{v} a) := by simp [bit1] #align cardinal.lift_bit1 Cardinal.lift_bit1 end deprecated -- Porting note: Proof used to be simp, needed to remind simp that 1 + 1 = 2 theorem lift_two : lift.{u, v} 2 = 2 := by simp [← one_add_one_eq_two] #align cardinal.lift_two Cardinal.lift_two @[simp] theorem mk_set {α : Type u} : #(Set α) = 2 ^ #α := by simp [← one_add_one_eq_two, Set, mk_arrow] #align cardinal.mk_set Cardinal.mk_set /-- A variant of `Cardinal.mk_set` expressed in terms of a `Set` instead of a `Type`. -/ @[simp] theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = 2 ^ #(↥s) := (mk_congr (Equiv.Set.powerset s)).trans mk_set #align cardinal.mk_powerset Cardinal.mk_powerset theorem lift_two_power (a : Cardinal) : lift.{v} (2 ^ a) = 2 ^ lift.{v} a := by simp [← one_add_one_eq_two] #align cardinal.lift_two_power Cardinal.lift_two_power section OrderProperties open Sum protected theorem zero_le : ∀ a : Cardinal, 0 ≤ a := by rintro ⟨α⟩ exact ⟨Embedding.ofIsEmpty⟩ #align cardinal.zero_le Cardinal.zero_le private theorem add_le_add' : ∀ {a b c d : Cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sumMap e₂⟩ -- #align cardinal.add_le_add' Cardinal.add_le_add' instance add_covariantClass : CovariantClass Cardinal Cardinal (· + ·) (· ≤ ·) := ⟨fun _ _ _ => add_le_add' le_rfl⟩ #align cardinal.add_covariant_class Cardinal.add_covariantClass instance add_swap_covariantClass : CovariantClass Cardinal Cardinal (swap (· + ·)) (· ≤ ·) := ⟨fun _ _ _ h => add_le_add' h le_rfl⟩ #align cardinal.add_swap_covariant_class Cardinal.add_swap_covariantClass instance canonicallyOrderedCommSemiring : CanonicallyOrderedCommSemiring Cardinal.{u} := { Cardinal.commSemiring, Cardinal.partialOrder with bot := 0 bot_le := Cardinal.zero_le add_le_add_left := fun a b => add_le_add_left exists_add_of_le := fun {a b} => inductionOn₂ a b fun α β ⟨⟨f, hf⟩⟩ => have : Sum α ((range f)ᶜ : Set β) ≃ β := (Equiv.sumCongr (Equiv.ofInjective f hf) (Equiv.refl _)).trans <| Equiv.Set.sumCompl (range f) ⟨#(↥(range f)ᶜ), mk_congr this.symm⟩ le_self_add := fun a b => (add_zero a).ge.trans <| add_le_add_left (Cardinal.zero_le _) _ eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} => inductionOn₂ a b fun α β => by simpa only [mul_def, mk_eq_zero_iff, isEmpty_prod] using id } instance : CanonicallyLinearOrderedAddCommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring, Cardinal.linearOrder with } -- Computable instance to prevent a non-computable one being found via the one above instance : CanonicallyOrderedAddCommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } instance : LinearOrderedCommMonoidWithZero Cardinal.{u} := { Cardinal.commSemiring, Cardinal.linearOrder with mul_le_mul_left := @mul_le_mul_left' _ _ _ _ zero_le_one := zero_le _ } -- Computable instance to prevent a non-computable one being found via the one above instance : CommMonoidWithZero Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } -- Porting note: new -- Computable instance to prevent a non-computable one being found via the one above instance : CommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } theorem zero_power_le (c : Cardinal.{u}) : (0 : Cardinal.{u}) ^ c ≤ 1 := by by_cases h : c = 0 · rw [h, power_zero] · rw [zero_power h] apply zero_le #align cardinal.zero_power_le Cardinal.zero_power_le theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩ let ⟨a⟩ := mk_ne_zero_iff.1 hα exact ⟨@Function.Embedding.arrowCongrLeft _ _ _ ⟨a⟩ e⟩ #align cardinal.power_le_power_left Cardinal.power_le_power_left theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ a ^ b := by rcases eq_or_ne a 0 with (rfl | ha) · exact zero_le _ · convert power_le_power_left ha hb exact power_one.symm #align cardinal.self_le_power Cardinal.self_le_power /-- **Cantor's theorem** -/
Mathlib/SetTheory/Cardinal/Basic.lean
736
741
theorem cantor (a : Cardinal.{u}) : a < 2 ^ a := by
induction' a using Cardinal.inductionOn with α rw [← mk_set] refine ⟨⟨⟨singleton, fun a b => singleton_eq_singleton_iff.1⟩⟩, ?_⟩ rintro ⟨⟨f, hf⟩⟩ exact cantor_injective f hf
/- Copyright (c) 2021 Stuart Presnell. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stuart Presnell -/ import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Data.Nat.PrimeFin import Mathlib.NumberTheory.Padics.PadicVal import Mathlib.Order.Interval.Finset.Nat #align_import data.nat.factorization.basic from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Prime factorizations `n.factorization` is the finitely supported function `ℕ →₀ ℕ` mapping each prime factor of `n` to its multiplicity in `n`. For example, since 2000 = 2^4 * 5^3, * `factorization 2000 2` is 4 * `factorization 2000 5` is 3 * `factorization 2000 k` is 0 for all other `k : ℕ`. ## TODO * As discussed in this Zulip thread: https://leanprover.zulipchat.com/#narrow/stream/217875/topic/Multiplicity.20in.20the.20naturals We have lots of disparate ways of talking about the multiplicity of a prime in a natural number, including `factors.count`, `padicValNat`, `multiplicity`, and the material in `Data/PNat/Factors`. Move some of this material to this file, prove results about the relationships between these definitions, and (where appropriate) choose a uniform canonical way of expressing these ideas. * Moreover, the results here should be generalised to an arbitrary unique factorization monoid with a normalization function, and then deduplicated. The basics of this have been started in `RingTheory/UniqueFactorizationDomain`. * Extend the inductions to any `NormalizationMonoid` with unique factorization. -/ -- Workaround for lean4#2038 attribute [-instance] instBEqNat open Nat Finset List Finsupp namespace Nat variable {a b m n p : ℕ} /-- `n.factorization` is the finitely supported function `ℕ →₀ ℕ` mapping each prime factor of `n` to its multiplicity in `n`. -/ def factorization (n : ℕ) : ℕ →₀ ℕ where support := n.primeFactors toFun p := if p.Prime then padicValNat p n else 0 mem_support_toFun := by simp [not_or]; aesop #align nat.factorization Nat.factorization /-- The support of `n.factorization` is exactly `n.primeFactors`. -/ @[simp] lemma support_factorization (n : ℕ) : (factorization n).support = n.primeFactors := rfl theorem factorization_def (n : ℕ) {p : ℕ} (pp : p.Prime) : n.factorization p = padicValNat p n := by simpa [factorization] using absurd pp #align nat.factorization_def Nat.factorization_def /-- We can write both `n.factorization p` and `n.factors.count p` to represent the power of `p` in the factorization of `n`: we declare the former to be the simp-normal form. -/ @[simp] theorem factors_count_eq {n p : ℕ} : n.factors.count p = n.factorization p := by rcases n.eq_zero_or_pos with (rfl | hn0) · simp [factorization, count] if pp : p.Prime then ?_ else rw [count_eq_zero_of_not_mem (mt prime_of_mem_factors pp)] simp [factorization, pp] simp only [factorization_def _ pp] apply _root_.le_antisymm · rw [le_padicValNat_iff_replicate_subperm_factors pp hn0.ne'] exact List.le_count_iff_replicate_sublist.mp le_rfl |>.subperm · rw [← lt_add_one_iff, lt_iff_not_ge, ge_iff_le, le_padicValNat_iff_replicate_subperm_factors pp hn0.ne'] intro h have := h.count_le p simp at this #align nat.factors_count_eq Nat.factors_count_eq theorem factorization_eq_factors_multiset (n : ℕ) : n.factorization = Multiset.toFinsupp (n.factors : Multiset ℕ) := by ext p simp #align nat.factorization_eq_factors_multiset Nat.factorization_eq_factors_multiset theorem multiplicity_eq_factorization {n p : ℕ} (pp : p.Prime) (hn : n ≠ 0) : multiplicity p n = n.factorization p := by simp [factorization, pp, padicValNat_def' pp.ne_one hn.bot_lt] #align nat.multiplicity_eq_factorization Nat.multiplicity_eq_factorization /-! ### Basic facts about factorization -/ @[simp] theorem factorization_prod_pow_eq_self {n : ℕ} (hn : n ≠ 0) : n.factorization.prod (· ^ ·) = n := by rw [factorization_eq_factors_multiset n] simp only [← prod_toMultiset, factorization, Multiset.prod_coe, Multiset.toFinsupp_toMultiset] exact prod_factors hn #align nat.factorization_prod_pow_eq_self Nat.factorization_prod_pow_eq_self theorem eq_of_factorization_eq {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : ℕ, a.factorization p = b.factorization p) : a = b := eq_of_perm_factors ha hb (by simpa only [List.perm_iff_count, factors_count_eq] using h) #align nat.eq_of_factorization_eq Nat.eq_of_factorization_eq /-- Every nonzero natural number has a unique prime factorization -/ theorem factorization_inj : Set.InjOn factorization { x : ℕ | x ≠ 0 } := fun a ha b hb h => eq_of_factorization_eq ha hb fun p => by simp [h] #align nat.factorization_inj Nat.factorization_inj @[simp] theorem factorization_zero : factorization 0 = 0 := by ext; simp [factorization] #align nat.factorization_zero Nat.factorization_zero @[simp] theorem factorization_one : factorization 1 = 0 := by ext; simp [factorization] #align nat.factorization_one Nat.factorization_one #noalign nat.support_factorization #align nat.factor_iff_mem_factorization Nat.mem_primeFactors_iff_mem_factors #align nat.prime_of_mem_factorization Nat.prime_of_mem_primeFactors #align nat.pos_of_mem_factorization Nat.pos_of_mem_primeFactors #align nat.le_of_mem_factorization Nat.le_of_mem_primeFactors /-! ## Lemmas characterising when `n.factorization p = 0` -/ theorem factorization_eq_zero_iff (n p : ℕ) : n.factorization p = 0 ↔ ¬p.Prime ∨ ¬p ∣ n ∨ n = 0 := by simp_rw [← not_mem_support_iff, support_factorization, mem_primeFactors, not_and_or, not_ne_iff] #align nat.factorization_eq_zero_iff Nat.factorization_eq_zero_iff @[simp] theorem factorization_eq_zero_of_non_prime (n : ℕ) {p : ℕ} (hp : ¬p.Prime) : n.factorization p = 0 := by simp [factorization_eq_zero_iff, hp] #align nat.factorization_eq_zero_of_non_prime Nat.factorization_eq_zero_of_non_prime theorem factorization_eq_zero_of_not_dvd {n p : ℕ} (h : ¬p ∣ n) : n.factorization p = 0 := by simp [factorization_eq_zero_iff, h] #align nat.factorization_eq_zero_of_not_dvd Nat.factorization_eq_zero_of_not_dvd theorem factorization_eq_zero_of_lt {n p : ℕ} (h : n < p) : n.factorization p = 0 := Finsupp.not_mem_support_iff.mp (mt le_of_mem_primeFactors (not_le_of_lt h)) #align nat.factorization_eq_zero_of_lt Nat.factorization_eq_zero_of_lt @[simp] theorem factorization_zero_right (n : ℕ) : n.factorization 0 = 0 := factorization_eq_zero_of_non_prime _ not_prime_zero #align nat.factorization_zero_right Nat.factorization_zero_right @[simp] theorem factorization_one_right (n : ℕ) : n.factorization 1 = 0 := factorization_eq_zero_of_non_prime _ not_prime_one #align nat.factorization_one_right Nat.factorization_one_right theorem dvd_of_factorization_pos {n p : ℕ} (hn : n.factorization p ≠ 0) : p ∣ n := dvd_of_mem_factors <| mem_primeFactors_iff_mem_factors.1 <| mem_support_iff.2 hn #align nat.dvd_of_factorization_pos Nat.dvd_of_factorization_pos theorem Prime.factorization_pos_of_dvd {n p : ℕ} (hp : p.Prime) (hn : n ≠ 0) (h : p ∣ n) : 0 < n.factorization p := by rwa [← factors_count_eq, count_pos_iff_mem, mem_factors_iff_dvd hn hp] #align nat.prime.factorization_pos_of_dvd Nat.Prime.factorization_pos_of_dvd theorem factorization_eq_zero_of_remainder {p r : ℕ} (i : ℕ) (hr : ¬p ∣ r) : (p * i + r).factorization p = 0 := by apply factorization_eq_zero_of_not_dvd rwa [← Nat.dvd_add_iff_right (Dvd.intro i rfl)] #align nat.factorization_eq_zero_of_remainder Nat.factorization_eq_zero_of_remainder theorem factorization_eq_zero_iff_remainder {p r : ℕ} (i : ℕ) (pp : p.Prime) (hr0 : r ≠ 0) : ¬p ∣ r ↔ (p * i + r).factorization p = 0 := by refine ⟨factorization_eq_zero_of_remainder i, fun h => ?_⟩ rw [factorization_eq_zero_iff] at h contrapose! h refine ⟨pp, ?_, ?_⟩ · rwa [← Nat.dvd_add_iff_right (dvd_mul_right p i)] · contrapose! hr0 exact (add_eq_zero_iff.mp hr0).2 #align nat.factorization_eq_zero_iff_remainder Nat.factorization_eq_zero_iff_remainder /-- The only numbers with empty prime factorization are `0` and `1` -/ theorem factorization_eq_zero_iff' (n : ℕ) : n.factorization = 0 ↔ n = 0 ∨ n = 1 := by rw [factorization_eq_factors_multiset n] simp [factorization, AddEquiv.map_eq_zero_iff, Multiset.coe_eq_zero] #align nat.factorization_eq_zero_iff' Nat.factorization_eq_zero_iff' /-! ## Lemmas about factorizations of products and powers -/ /-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/ @[simp] theorem factorization_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) : (a * b).factorization = a.factorization + b.factorization := by ext p simp only [add_apply, ← factors_count_eq, perm_iff_count.mp (perm_factors_mul ha hb) p, count_append] #align nat.factorization_mul Nat.factorization_mul #align nat.factorization_mul_support Nat.primeFactors_mul /-- A product over `n.factorization` can be written as a product over `n.primeFactors`; -/ lemma prod_factorization_eq_prod_primeFactors {β : Type*} [CommMonoid β] (f : ℕ → ℕ → β) : n.factorization.prod f = ∏ p ∈ n.primeFactors, f p (n.factorization p) := rfl #align nat.prod_factorization_eq_prod_factors Nat.prod_factorization_eq_prod_primeFactors /-- A product over `n.primeFactors` can be written as a product over `n.factorization`; -/ lemma prod_primeFactors_prod_factorization {β : Type*} [CommMonoid β] (f : ℕ → β) : ∏ p ∈ n.primeFactors, f p = n.factorization.prod (fun p _ ↦ f p) := rfl /-- For any `p : ℕ` and any function `g : α → ℕ` that's non-zero on `S : Finset α`, the power of `p` in `S.prod g` equals the sum over `x ∈ S` of the powers of `p` in `g x`. Generalises `factorization_mul`, which is the special case where `S.card = 2` and `g = id`. -/ theorem factorization_prod {α : Type*} {S : Finset α} {g : α → ℕ} (hS : ∀ x ∈ S, g x ≠ 0) : (S.prod g).factorization = S.sum fun x => (g x).factorization := by classical ext p refine Finset.induction_on' S ?_ ?_ · simp · intro x T hxS hTS hxT IH have hT : T.prod g ≠ 0 := prod_ne_zero_iff.mpr fun x hx => hS x (hTS hx) simp [prod_insert hxT, sum_insert hxT, ← IH, factorization_mul (hS x hxS) hT] #align nat.factorization_prod Nat.factorization_prod /-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/ @[simp] theorem factorization_pow (n k : ℕ) : factorization (n ^ k) = k • n.factorization := by induction' k with k ih; · simp rcases eq_or_ne n 0 with (rfl | hn) · simp rw [Nat.pow_succ, mul_comm, factorization_mul hn (pow_ne_zero _ hn), ih, add_smul, one_smul, add_comm] #align nat.factorization_pow Nat.factorization_pow /-! ## Lemmas about factorizations of primes and prime powers -/ /-- The only prime factor of prime `p` is `p` itself, with multiplicity `1` -/ @[simp] protected theorem Prime.factorization {p : ℕ} (hp : Prime p) : p.factorization = single p 1 := by ext q rw [← factors_count_eq, factors_prime hp, single_apply, count_singleton', if_congr eq_comm] <;> rfl #align nat.prime.factorization Nat.Prime.factorization /-- The multiplicity of prime `p` in `p` is `1` -/ @[simp] theorem Prime.factorization_self {p : ℕ} (hp : Prime p) : p.factorization p = 1 := by simp [hp] #align nat.prime.factorization_self Nat.Prime.factorization_self /-- For prime `p` the only prime factor of `p^k` is `p` with multiplicity `k` -/ theorem Prime.factorization_pow {p k : ℕ} (hp : Prime p) : (p ^ k).factorization = single p k := by simp [hp] #align nat.prime.factorization_pow Nat.Prime.factorization_pow /-- If the factorization of `n` contains just one number `p` then `n` is a power of `p` -/ theorem eq_pow_of_factorization_eq_single {n p k : ℕ} (hn : n ≠ 0) (h : n.factorization = Finsupp.single p k) : n = p ^ k := by -- Porting note: explicitly added `Finsupp.prod_single_index` rw [← Nat.factorization_prod_pow_eq_self hn, h, Finsupp.prod_single_index] simp #align nat.eq_pow_of_factorization_eq_single Nat.eq_pow_of_factorization_eq_single /-- The only prime factor of prime `p` is `p` itself. -/ theorem Prime.eq_of_factorization_pos {p q : ℕ} (hp : Prime p) (h : p.factorization q ≠ 0) : p = q := by simpa [hp.factorization, single_apply] using h #align nat.prime.eq_of_factorization_pos Nat.Prime.eq_of_factorization_pos /-! ### Equivalence between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/ /-- Any Finsupp `f : ℕ →₀ ℕ` whose support is in the primes is equal to the factorization of the product `∏ (a : ℕ) ∈ f.support, a ^ f a`. -/ theorem prod_pow_factorization_eq_self {f : ℕ →₀ ℕ} (hf : ∀ p : ℕ, p ∈ f.support → Prime p) : (f.prod (· ^ ·)).factorization = f := by have h : ∀ x : ℕ, x ∈ f.support → x ^ f x ≠ 0 := fun p hp => pow_ne_zero _ (Prime.ne_zero (hf p hp)) simp only [Finsupp.prod, factorization_prod h] conv => rhs rw [(sum_single f).symm] exact sum_congr rfl fun p hp => Prime.factorization_pow (hf p hp) #align nat.prod_pow_factorization_eq_self Nat.prod_pow_factorization_eq_self theorem eq_factorization_iff {n : ℕ} {f : ℕ →₀ ℕ} (hn : n ≠ 0) (hf : ∀ p ∈ f.support, Prime p) : f = n.factorization ↔ f.prod (· ^ ·) = n := ⟨fun h => by rw [h, factorization_prod_pow_eq_self hn], fun h => by rw [← h, prod_pow_factorization_eq_self hf]⟩ #align nat.eq_factorization_iff Nat.eq_factorization_iff /-- The equiv between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/ def factorizationEquiv : ℕ+ ≃ { f : ℕ →₀ ℕ | ∀ p ∈ f.support, Prime p } where toFun := fun ⟨n, _⟩ => ⟨n.factorization, fun _ => prime_of_mem_primeFactors⟩ invFun := fun ⟨f, hf⟩ => ⟨f.prod _, prod_pow_pos_of_zero_not_mem_support fun H => not_prime_zero (hf 0 H)⟩ left_inv := fun ⟨_, hx⟩ => Subtype.ext <| factorization_prod_pow_eq_self hx.ne.symm right_inv := fun ⟨_, hf⟩ => Subtype.ext <| prod_pow_factorization_eq_self hf #align nat.factorization_equiv Nat.factorizationEquiv theorem factorizationEquiv_apply (n : ℕ+) : (factorizationEquiv n).1 = n.1.factorization := by cases n rfl #align nat.factorization_equiv_apply Nat.factorizationEquiv_apply theorem factorizationEquiv_inv_apply {f : ℕ →₀ ℕ} (hf : ∀ p ∈ f.support, Prime p) : (factorizationEquiv.symm ⟨f, hf⟩).1 = f.prod (· ^ ·) := rfl #align nat.factorization_equiv_inv_apply Nat.factorizationEquiv_inv_apply /-! ### Generalisation of the "even part" and "odd part" of a natural number We introduce the notations `ord_proj[p] n` for the largest power of the prime `p` that divides `n` and `ord_compl[p] n` for the complementary part. The `ord` naming comes from the $p$-adic order/valuation of a number, and `proj` and `compl` are for the projection and complementary projection. The term `n.factorization p` is the $p$-adic order itself. For example, `ord_proj[2] n` is the even part of `n` and `ord_compl[2] n` is the odd part. -/ -- Porting note: Lean 4 thinks we need `HPow` without this set_option quotPrecheck false in notation "ord_proj[" p "] " n:arg => p ^ Nat.factorization n p notation "ord_compl[" p "] " n:arg => n / ord_proj[p] n @[simp] theorem ord_proj_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ord_proj[p] n = 1 := by simp [factorization_eq_zero_of_non_prime n hp] #align nat.ord_proj_of_not_prime Nat.ord_proj_of_not_prime @[simp] theorem ord_compl_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ord_compl[p] n = n := by simp [factorization_eq_zero_of_non_prime n hp] #align nat.ord_compl_of_not_prime Nat.ord_compl_of_not_prime theorem ord_proj_dvd (n p : ℕ) : ord_proj[p] n ∣ n := by if hp : p.Prime then ?_ else simp [hp] rw [← factors_count_eq] apply dvd_of_factors_subperm (pow_ne_zero _ hp.ne_zero) rw [hp.factors_pow, List.subperm_ext_iff] intro q hq simp [List.eq_of_mem_replicate hq] #align nat.ord_proj_dvd Nat.ord_proj_dvd theorem ord_compl_dvd (n p : ℕ) : ord_compl[p] n ∣ n := div_dvd_of_dvd (ord_proj_dvd n p) #align nat.ord_compl_dvd Nat.ord_compl_dvd theorem ord_proj_pos (n p : ℕ) : 0 < ord_proj[p] n := by if pp : p.Prime then simp [pow_pos pp.pos] else simp [pp] #align nat.ord_proj_pos Nat.ord_proj_pos theorem ord_proj_le {n : ℕ} (p : ℕ) (hn : n ≠ 0) : ord_proj[p] n ≤ n := le_of_dvd hn.bot_lt (Nat.ord_proj_dvd n p) #align nat.ord_proj_le Nat.ord_proj_le theorem ord_compl_pos {n : ℕ} (p : ℕ) (hn : n ≠ 0) : 0 < ord_compl[p] n := by if pp : p.Prime then exact Nat.div_pos (ord_proj_le p hn) (ord_proj_pos n p) else simpa [Nat.factorization_eq_zero_of_non_prime n pp] using hn.bot_lt #align nat.ord_compl_pos Nat.ord_compl_pos theorem ord_compl_le (n p : ℕ) : ord_compl[p] n ≤ n := Nat.div_le_self _ _ #align nat.ord_compl_le Nat.ord_compl_le theorem ord_proj_mul_ord_compl_eq_self (n p : ℕ) : ord_proj[p] n * ord_compl[p] n = n := Nat.mul_div_cancel' (ord_proj_dvd n p) #align nat.ord_proj_mul_ord_compl_eq_self Nat.ord_proj_mul_ord_compl_eq_self theorem ord_proj_mul {a b : ℕ} (p : ℕ) (ha : a ≠ 0) (hb : b ≠ 0) : ord_proj[p] (a * b) = ord_proj[p] a * ord_proj[p] b := by simp [factorization_mul ha hb, pow_add] #align nat.ord_proj_mul Nat.ord_proj_mul theorem ord_compl_mul (a b p : ℕ) : ord_compl[p] (a * b) = ord_compl[p] a * ord_compl[p] b := by if ha : a = 0 then simp [ha] else if hb : b = 0 then simp [hb] else simp only [ord_proj_mul p ha hb] rw [div_mul_div_comm (ord_proj_dvd a p) (ord_proj_dvd b p)] #align nat.ord_compl_mul Nat.ord_compl_mul /-! ### Factorization and divisibility -/ #align nat.dvd_of_mem_factorization Nat.dvd_of_mem_primeFactors /-- A crude upper bound on `n.factorization p` -/ theorem factorization_lt {n : ℕ} (p : ℕ) (hn : n ≠ 0) : n.factorization p < n := by by_cases pp : p.Prime · exact (pow_lt_pow_iff_right pp.one_lt).1 <| (ord_proj_le p hn).trans_lt <| lt_pow_self pp.one_lt _ · simpa only [factorization_eq_zero_of_non_prime n pp] using hn.bot_lt #align nat.factorization_lt Nat.factorization_lt /-- An upper bound on `n.factorization p` -/ theorem factorization_le_of_le_pow {n p b : ℕ} (hb : n ≤ p ^ b) : n.factorization p ≤ b := by if hn : n = 0 then simp [hn] else if pp : p.Prime then exact (pow_le_pow_iff_right pp.one_lt).1 ((ord_proj_le p hn).trans hb) else simp [factorization_eq_zero_of_non_prime n pp] #align nat.factorization_le_of_le_pow Nat.factorization_le_of_le_pow theorem factorization_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) : d.factorization ≤ n.factorization ↔ d ∣ n := by constructor · intro hdn set K := n.factorization - d.factorization with hK use K.prod (· ^ ·) rw [← factorization_prod_pow_eq_self hn, ← factorization_prod_pow_eq_self hd, ← Finsupp.prod_add_index' pow_zero pow_add, hK, add_tsub_cancel_of_le hdn] · rintro ⟨c, rfl⟩ rw [factorization_mul hd (right_ne_zero_of_mul hn)] simp #align nat.factorization_le_iff_dvd Nat.factorization_le_iff_dvd theorem factorization_prime_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) : (∀ p : ℕ, p.Prime → d.factorization p ≤ n.factorization p) ↔ d ∣ n := by rw [← factorization_le_iff_dvd hd hn] refine ⟨fun h p => (em p.Prime).elim (h p) fun hp => ?_, fun h p _ => h p⟩ simp_rw [factorization_eq_zero_of_non_prime _ hp] rfl #align nat.factorization_prime_le_iff_dvd Nat.factorization_prime_le_iff_dvd theorem pow_succ_factorization_not_dvd {n p : ℕ} (hn : n ≠ 0) (hp : p.Prime) : ¬p ^ (n.factorization p + 1) ∣ n := by intro h rw [← factorization_le_iff_dvd (pow_pos hp.pos _).ne' hn] at h simpa [hp.factorization] using h p #align nat.pow_succ_factorization_not_dvd Nat.pow_succ_factorization_not_dvd theorem factorization_le_factorization_mul_left {a b : ℕ} (hb : b ≠ 0) : a.factorization ≤ (a * b).factorization := by rcases eq_or_ne a 0 with (rfl | ha) · simp rw [factorization_le_iff_dvd ha <| mul_ne_zero ha hb] exact Dvd.intro b rfl #align nat.factorization_le_factorization_mul_left Nat.factorization_le_factorization_mul_left
Mathlib/Data/Nat/Factorization/Basic.lean
445
448
theorem factorization_le_factorization_mul_right {a b : ℕ} (ha : a ≠ 0) : b.factorization ≤ (a * b).factorization := by
rw [mul_comm] apply factorization_le_factorization_mul_left ha
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Data.Finset.Sort #align_import data.polynomial.basic from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Theory of univariate polynomials This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds a semiring structure on it, and gives basic definitions that are expanded in other files in this directory. ## Main definitions * `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map. * `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism. * `X` is the polynomial `X`, i.e., `monomial 1 1`. * `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied to coefficients of the polynomial `p`. * `p.erase n` is the polynomial `p` in which one removes the `c X^n` term. There are often two natural variants of lemmas involving sums, depending on whether one acts on the polynomials, or on the function. The naming convention is that one adds `index` when acting on the polynomials. For instance, * `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`; * `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`. * Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`. ## Implementation Polynomials are defined using `R[ℕ]`, where `R` is a semiring. The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity `X * p = p * X`. The relationship to `R[ℕ]` is through a structure to make polynomials irreducible from the point of view of the kernel. Most operations are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two exceptions that we make semireducible: * The zero polynomial, so that its coefficients are definitionally equal to `0`. * The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds. The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should in general not be used once the basic API for polynomials is constructed. -/ set_option linter.uppercaseLean3 false noncomputable section /-- `Polynomial R` is the type of univariate polynomials over `R`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ structure Polynomial (R : Type*) [Semiring R] where ofFinsupp :: toFinsupp : AddMonoidAlgebra R ℕ #align polynomial Polynomial #align polynomial.of_finsupp Polynomial.ofFinsupp #align polynomial.to_finsupp Polynomial.toFinsupp @[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R open AddMonoidAlgebra open Finsupp hiding single open Function hiding Commute open Polynomial namespace Polynomial universe u variable {R : Type u} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} theorem forall_iff_forall_finsupp (P : R[X] → Prop) : (∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ := ⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩ #align polynomial.forall_iff_forall_finsupp Polynomial.forall_iff_forall_finsupp theorem exists_iff_exists_finsupp (P : R[X] → Prop) : (∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ := ⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩ #align polynomial.exists_iff_exists_finsupp Polynomial.exists_iff_exists_finsupp @[simp] theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl #align polynomial.eta Polynomial.eta /-! ### Conversions to and from `AddMonoidAlgebra` Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping it, we have to copy across all the arithmetic operators manually, along with the lemmas about how they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`. -/ section AddMonoidAlgebra private irreducible_def add : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X] | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ instance zero : Zero R[X] := ⟨⟨0⟩⟩ #align polynomial.has_zero Polynomial.zero instance one : One R[X] := ⟨⟨1⟩⟩ #align polynomial.one Polynomial.one instance add' : Add R[X] := ⟨add⟩ #align polynomial.has_add Polynomial.add' instance neg' {R : Type u} [Ring R] : Neg R[X] := ⟨neg⟩ #align polynomial.has_neg Polynomial.neg' instance sub {R : Type u} [Ring R] : Sub R[X] := ⟨fun a b => a + -b⟩ #align polynomial.has_sub Polynomial.sub instance mul' : Mul R[X] := ⟨mul⟩ #align polynomial.has_mul Polynomial.mul' -- If the private definitions are accidentally exposed, simplify them away. @[simp] theorem add_eq_add : add p q = p + q := rfl @[simp] theorem mul_eq_mul : mul p q = p * q := rfl instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where smul r p := ⟨r • p.toFinsupp⟩ smul_zero a := congr_arg ofFinsupp (smul_zero a) #align polynomial.smul_zero_class Polynomial.smulZeroClass -- to avoid a bug in the `ring` tactic instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p #align polynomial.has_pow Polynomial.pow @[simp] theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 := rfl #align polynomial.of_finsupp_zero Polynomial.ofFinsupp_zero @[simp] theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 := rfl #align polynomial.of_finsupp_one Polynomial.ofFinsupp_one @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add_def] #align polynomial.of_finsupp_add Polynomial.ofFinsupp_add @[simp] theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ := show _ = neg _ by rw [neg_def] #align polynomial.of_finsupp_neg Polynomial.ofFinsupp_neg @[simp]
Mathlib/Algebra/Polynomial/Basic.lean
178
180
theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by
rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg] rfl
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov, Yaël Dillies -/ import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Analysis.Convex.Star import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace #align_import analysis.convex.basic from "leanprover-community/mathlib"@"92bd7b1ffeb306a89f450bee126ddd8a284c259d" /-! # Convex sets and functions in vector spaces In a 𝕜-vector space, we define the following objects and properties. * `Convex 𝕜 s`: A set `s` is convex if for any two points `x y ∈ s` it includes `segment 𝕜 x y`. * `stdSimplex 𝕜 ι`: The standard simplex in `ι → 𝕜` (currently requires `Fintype ι`). It is the intersection of the positive quadrant with the hyperplane `s.sum = 1`. We also provide various equivalent versions of the definitions above, prove that some specific sets are convex. ## TODO Generalize all this file to affine spaces. -/ variable {𝕜 E F β : Type*} open LinearMap Set open scoped Convex Pointwise /-! ### Convexity of sets -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (s : Set E) {x : E} /-- Convexity of sets. -/ def Convex : Prop := ∀ ⦃x : E⦄, x ∈ s → StarConvex 𝕜 x s #align convex Convex variable {𝕜 s} theorem Convex.starConvex (hs : Convex 𝕜 s) (hx : x ∈ s) : StarConvex 𝕜 x s := hs hx #align convex.star_convex Convex.starConvex theorem convex_iff_segment_subset : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s := forall₂_congr fun _ _ => starConvex_iff_segment_subset #align convex_iff_segment_subset convex_iff_segment_subset theorem Convex.segment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : [x -[𝕜] y] ⊆ s := convex_iff_segment_subset.1 h hx hy #align convex.segment_subset Convex.segment_subset theorem Convex.openSegment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s := (openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hx hy) #align convex.open_segment_subset Convex.openSegment_subset /-- Alternative definition of set convexity, in terms of pointwise set operations. -/ theorem convex_iff_pointwise_add_subset : Convex 𝕜 s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s := Iff.intro (by rintro hA a b ha hb hab w ⟨au, ⟨u, hu, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩ exact hA hu hv ha hb hab) fun h x hx y hy a b ha hb hab => (h ha hb hab) (Set.add_mem_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩) #align convex_iff_pointwise_add_subset convex_iff_pointwise_add_subset alias ⟨Convex.set_combo_subset, _⟩ := convex_iff_pointwise_add_subset #align convex.set_combo_subset Convex.set_combo_subset theorem convex_empty : Convex 𝕜 (∅ : Set E) := fun _ => False.elim #align convex_empty convex_empty theorem convex_univ : Convex 𝕜 (Set.univ : Set E) := fun _ _ => starConvex_univ _ #align convex_univ convex_univ theorem Convex.inter {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s ∩ t) := fun _ hx => (hs hx.1).inter (ht hx.2) #align convex.inter Convex.inter theorem convex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, Convex 𝕜 s) : Convex 𝕜 (⋂₀ S) := fun _ hx => starConvex_sInter fun _ hs => h _ hs <| hx _ hs #align convex_sInter convex_sInter theorem convex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, Convex 𝕜 (s i)) : Convex 𝕜 (⋂ i, s i) := sInter_range s ▸ convex_sInter <| forall_mem_range.2 h #align convex_Inter convex_iInter theorem convex_iInter₂ {ι : Sort*} {κ : ι → Sort*} {s : ∀ i, κ i → Set E} (h : ∀ i j, Convex 𝕜 (s i j)) : Convex 𝕜 (⋂ (i) (j), s i j) := convex_iInter fun i => convex_iInter <| h i #align convex_Inter₂ convex_iInter₂ theorem Convex.prod {s : Set E} {t : Set F} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s ×ˢ t) := fun _ hx => (hs hx.1).prod (ht hx.2) #align convex.prod Convex.prod theorem convex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)] {s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → Convex 𝕜 (t i)) : Convex 𝕜 (s.pi t) := fun _ hx => starConvex_pi fun _ hi => ht hi <| hx _ hi #align convex_pi convex_pi theorem Directed.convex_iUnion {ι : Sort*} {s : ι → Set E} (hdir : Directed (· ⊆ ·) s) (hc : ∀ ⦃i : ι⦄, Convex 𝕜 (s i)) : Convex 𝕜 (⋃ i, s i) := by rintro x hx y hy a b ha hb hab rw [mem_iUnion] at hx hy ⊢ obtain ⟨i, hx⟩ := hx obtain ⟨j, hy⟩ := hy obtain ⟨k, hik, hjk⟩ := hdir i j exact ⟨k, hc (hik hx) (hjk hy) ha hb hab⟩ #align directed.convex_Union Directed.convex_iUnion theorem DirectedOn.convex_sUnion {c : Set (Set E)} (hdir : DirectedOn (· ⊆ ·) c) (hc : ∀ ⦃A : Set E⦄, A ∈ c → Convex 𝕜 A) : Convex 𝕜 (⋃₀ c) := by rw [sUnion_eq_iUnion] exact (directedOn_iff_directed.1 hdir).convex_iUnion fun A => hc A.2 #align directed_on.convex_sUnion DirectedOn.convex_sUnion end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {s : Set E} {x : E} theorem convex_iff_openSegment_subset : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s := forall₂_congr fun _ => starConvex_iff_openSegment_subset #align convex_iff_open_segment_subset convex_iff_openSegment_subset theorem convex_iff_forall_pos : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := forall₂_congr fun _ => starConvex_iff_forall_pos #align convex_iff_forall_pos convex_iff_forall_pos theorem convex_iff_pairwise_pos : Convex 𝕜 s ↔ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine convex_iff_forall_pos.trans ⟨fun h x hx y hy _ => h hx hy, ?_⟩ intro h x hx y hy a b ha hb hab obtain rfl | hxy := eq_or_ne x y · rwa [Convex.combo_self hab] · exact h hx hy hxy ha hb hab #align convex_iff_pairwise_pos convex_iff_pairwise_pos theorem Convex.starConvex_iff (hs : Convex 𝕜 s) (h : s.Nonempty) : StarConvex 𝕜 x s ↔ x ∈ s := ⟨fun hxs => hxs.mem h, hs.starConvex⟩ #align convex.star_convex_iff Convex.starConvex_iff protected theorem Set.Subsingleton.convex {s : Set E} (h : s.Subsingleton) : Convex 𝕜 s := convex_iff_pairwise_pos.mpr (h.pairwise _) #align set.subsingleton.convex Set.Subsingleton.convex theorem convex_singleton (c : E) : Convex 𝕜 ({c} : Set E) := subsingleton_singleton.convex #align convex_singleton convex_singleton theorem convex_zero : Convex 𝕜 (0 : Set E) := convex_singleton _ #align convex_zero convex_zero theorem convex_segment (x y : E) : Convex 𝕜 [x -[𝕜] y] := by rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ a b ha hb hab refine ⟨a * ap + b * aq, a * bp + b * bq, add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq), add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), ?_, ?_⟩ · rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab] · simp_rw [add_smul, mul_smul, smul_add] exact add_add_add_comm _ _ _ _ #align convex_segment convex_segment theorem Convex.linear_image (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ a b ha hb hab exact ⟨a • x + b • y, hs hx hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩ #align convex.linear_image Convex.linear_image theorem Convex.is_linear_image (hs : Convex 𝕜 s) {f : E → F} (hf : IsLinearMap 𝕜 f) : Convex 𝕜 (f '' s) := hs.linear_image <| hf.mk' f #align convex.is_linear_image Convex.is_linear_image theorem Convex.linear_preimage {s : Set F} (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f ⁻¹' s) := by intro x hx y hy a b ha hb hab rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hx hy ha hb hab #align convex.linear_preimage Convex.linear_preimage theorem Convex.is_linear_preimage {s : Set F} (hs : Convex 𝕜 s) {f : E → F} (hf : IsLinearMap 𝕜 f) : Convex 𝕜 (f ⁻¹' s) := hs.linear_preimage <| hf.mk' f #align convex.is_linear_preimage Convex.is_linear_preimage theorem Convex.add {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s + t) := by rw [← add_image_prod] exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add #align convex.add Convex.add variable (𝕜 E) /-- The convex sets form an additive submonoid under pointwise addition. -/ def convexAddSubmonoid : AddSubmonoid (Set E) where carrier := {s : Set E | Convex 𝕜 s} zero_mem' := convex_zero add_mem' := Convex.add #align convex_add_submonoid convexAddSubmonoid @[simp, norm_cast] theorem coe_convexAddSubmonoid : ↑(convexAddSubmonoid 𝕜 E) = {s : Set E | Convex 𝕜 s} := rfl #align coe_convex_add_submonoid coe_convexAddSubmonoid variable {𝕜 E} @[simp] theorem mem_convexAddSubmonoid {s : Set E} : s ∈ convexAddSubmonoid 𝕜 E ↔ Convex 𝕜 s := Iff.rfl #align mem_convex_add_submonoid mem_convexAddSubmonoid theorem convex_list_sum {l : List (Set E)} (h : ∀ i ∈ l, Convex 𝕜 i) : Convex 𝕜 l.sum := (convexAddSubmonoid 𝕜 E).list_sum_mem h #align convex_list_sum convex_list_sum theorem convex_multiset_sum {s : Multiset (Set E)} (h : ∀ i ∈ s, Convex 𝕜 i) : Convex 𝕜 s.sum := (convexAddSubmonoid 𝕜 E).multiset_sum_mem _ h #align convex_multiset_sum convex_multiset_sum theorem convex_sum {ι} {s : Finset ι} (t : ι → Set E) (h : ∀ i ∈ s, Convex 𝕜 (t i)) : Convex 𝕜 (∑ i ∈ s, t i) := (convexAddSubmonoid 𝕜 E).sum_mem h #align convex_sum convex_sum theorem Convex.vadd (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 (z +ᵥ s) := by simp_rw [← image_vadd, vadd_eq_add, ← singleton_add] exact (convex_singleton _).add hs #align convex.vadd Convex.vadd theorem Convex.translate (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => z + x) '' s) := hs.vadd _ #align convex.translate Convex.translate /-- The translation of a convex set is also convex. -/ theorem Convex.translate_preimage_right (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => z + x) ⁻¹' s) := by intro x hx y hy a b ha hb hab have h := hs hx hy ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] at h #align convex.translate_preimage_right Convex.translate_preimage_right /-- The translation of a convex set is also convex. -/ theorem Convex.translate_preimage_left (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => x + z) ⁻¹' s) := by simpa only [add_comm] using hs.translate_preimage_right z #align convex.translate_preimage_left Convex.translate_preimage_left section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_Iic (r : β) : Convex 𝕜 (Iic r) := fun x hx y hy a b ha hb hab => calc a • x + b • y ≤ a • r + b • r := add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb) _ = r := Convex.combo_self hab _ #align convex_Iic convex_Iic theorem convex_Ici (r : β) : Convex 𝕜 (Ici r) := @convex_Iic 𝕜 βᵒᵈ _ _ _ _ r #align convex_Ici convex_Ici theorem convex_Icc (r s : β) : Convex 𝕜 (Icc r s) := Ici_inter_Iic.subst ((convex_Ici r).inter <| convex_Iic s) #align convex_Icc convex_Icc theorem convex_halfspace_le {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w ≤ r } := (convex_Iic r).is_linear_preimage h #align convex_halfspace_le convex_halfspace_le theorem convex_halfspace_ge {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r ≤ f w } := (convex_Ici r).is_linear_preimage h #align convex_halfspace_ge convex_halfspace_ge theorem convex_hyperplane {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w = r } := by simp_rw [le_antisymm_iff] exact (convex_halfspace_le h r).inter (convex_halfspace_ge h r) #align convex_hyperplane convex_hyperplane end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_Iio (r : β) : Convex 𝕜 (Iio r) := by intro x hx y hy a b ha hb hab obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [zero_smul, zero_add, hab, one_smul] rw [mem_Iio] at hx hy calc a • x + b • y < a • r + b • r := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx ha') (smul_le_smul_of_nonneg_left hy.le hb) _ = r := Convex.combo_self hab _ #align convex_Iio convex_Iio theorem convex_Ioi (r : β) : Convex 𝕜 (Ioi r) := @convex_Iio 𝕜 βᵒᵈ _ _ _ _ r #align convex_Ioi convex_Ioi theorem convex_Ioo (r s : β) : Convex 𝕜 (Ioo r s) := Ioi_inter_Iio.subst ((convex_Ioi r).inter <| convex_Iio s) #align convex_Ioo convex_Ioo theorem convex_Ico (r s : β) : Convex 𝕜 (Ico r s) := Ici_inter_Iio.subst ((convex_Ici r).inter <| convex_Iio s) #align convex_Ico convex_Ico theorem convex_Ioc (r s : β) : Convex 𝕜 (Ioc r s) := Ioi_inter_Iic.subst ((convex_Ioi r).inter <| convex_Iic s) #align convex_Ioc convex_Ioc theorem convex_halfspace_lt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w < r } := (convex_Iio r).is_linear_preimage h #align convex_halfspace_lt convex_halfspace_lt theorem convex_halfspace_gt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r < f w } := (convex_Ioi r).is_linear_preimage h #align convex_halfspace_gt convex_halfspace_gt end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_uIcc (r s : β) : Convex 𝕜 (uIcc r s) := convex_Icc _ _ #align convex_uIcc convex_uIcc end LinearOrderedAddCommMonoid end Module end AddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid E] [OrderedAddCommMonoid β] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} {f : E → β} theorem MonotoneOn.convex_le (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy _ _ ha hb hab => ⟨hs hx.1 hy.1 ha hb hab, (hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans (max_rec' { x | f x ≤ r } hx.2 hy.2)⟩ #align monotone_on.convex_le MonotoneOn.convex_le theorem MonotoneOn.convex_lt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := fun x hx y hy _ _ ha hb hab => ⟨hs hx.1 hy.1 ha hb hab, (hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans_lt (max_rec' { x | f x < r } hx.2 hy.2)⟩ #align monotone_on.convex_lt MonotoneOn.convex_lt theorem MonotoneOn.convex_ge (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := @MonotoneOn.convex_le 𝕜 Eᵒᵈ βᵒᵈ _ _ _ _ _ _ _ hf.dual hs r #align monotone_on.convex_ge MonotoneOn.convex_ge theorem MonotoneOn.convex_gt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := @MonotoneOn.convex_lt 𝕜 Eᵒᵈ βᵒᵈ _ _ _ _ _ _ _ hf.dual hs r #align monotone_on.convex_gt MonotoneOn.convex_gt theorem AntitoneOn.convex_le (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := @MonotoneOn.convex_ge 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_le AntitoneOn.convex_le theorem AntitoneOn.convex_lt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := @MonotoneOn.convex_gt 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_lt AntitoneOn.convex_lt theorem AntitoneOn.convex_ge (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := @MonotoneOn.convex_le 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_ge AntitoneOn.convex_ge theorem AntitoneOn.convex_gt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := @MonotoneOn.convex_lt 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_gt AntitoneOn.convex_gt theorem Monotone.convex_le (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) #align monotone.convex_le Monotone.convex_le theorem Monotone.convex_lt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) #align monotone.convex_lt Monotone.convex_lt theorem Monotone.convex_ge (hf : Monotone f) (r : β) : Convex 𝕜 { x | r ≤ f x } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_ge convex_univ r) #align monotone.convex_ge Monotone.convex_ge theorem Monotone.convex_gt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) #align monotone.convex_gt Monotone.convex_gt theorem Antitone.convex_le (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_le convex_univ r) #align antitone.convex_le Antitone.convex_le theorem Antitone.convex_lt (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x < r } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_lt convex_univ r) #align antitone.convex_lt Antitone.convex_lt theorem Antitone.convex_ge (hf : Antitone f) (r : β) : Convex 𝕜 { x | r ≤ f x } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_ge convex_univ r) #align antitone.convex_ge Antitone.convex_ge theorem Antitone.convex_gt (hf : Antitone f) (r : β) : Convex 𝕜 { x | r < f x } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_gt convex_univ r) #align antitone.convex_gt Antitone.convex_gt end LinearOrderedAddCommMonoid end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E} theorem Convex.smul (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 (c • s) := hs.linear_image (LinearMap.lsmul _ _ c) #align convex.smul Convex.smul theorem Convex.smul_preimage (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 ((fun z => c • z) ⁻¹' s) := hs.linear_preimage (LinearMap.lsmul _ _ c) #align convex.smul_preimage Convex.smul_preimage theorem Convex.affinity (hs : Convex 𝕜 s) (z : E) (c : 𝕜) : Convex 𝕜 ((fun x => z + c • x) '' s) := by simpa only [← image_smul, ← image_vadd, image_image] using (hs.smul c).vadd z #align convex.affinity Convex.affinity end AddCommMonoid end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring 𝕜] [AddCommGroup E] [Module 𝕜 E] theorem convex_openSegment (a b : E) : Convex 𝕜 (openSegment 𝕜 a b) := by rw [convex_iff_openSegment_subset] rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ z ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨a * ap + b * aq, a * bp + b * bq, by positivity, by positivity, ?_, ?_⟩ · rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab] · simp_rw [add_smul, mul_smul, smul_add, add_add_add_comm] #align convex_open_segment convex_openSegment end StrictOrderedCommSemiring section OrderedRing variable [OrderedRing 𝕜] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s t : Set E} @[simp] theorem convex_vadd (a : E) : Convex 𝕜 (a +ᵥ s) ↔ Convex 𝕜 s := ⟨fun h ↦ by simpa using h.vadd (-a), fun h ↦ h.vadd _⟩ theorem Convex.add_smul_mem (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • y ∈ s := by have h : x + t • y = (1 - t) • x + t • (x + y) := by rw [smul_add, ← add_assoc, ← add_smul, sub_add_cancel, one_smul] rw [h] exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _) #align convex.add_smul_mem Convex.add_smul_mem theorem Convex.smul_mem_of_zero_mem (hs : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : t • x ∈ s := by simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht #align convex.smul_mem_of_zero_mem Convex.smul_mem_of_zero_mem theorem Convex.mapsTo_lineMap (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : MapsTo (AffineMap.lineMap x y) (Icc (0 : 𝕜) 1) s := by simpa only [mapsTo', segment_eq_image_lineMap] using h.segment_subset hx hy theorem Convex.lineMap_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜} (ht : t ∈ Icc 0 1) : AffineMap.lineMap x y t ∈ s := h.mapsTo_lineMap hx hy ht theorem Convex.add_smul_sub_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • (y - x) ∈ s := by rw [add_comm] exact h.lineMap_mem hx hy ht #align convex.add_smul_sub_mem Convex.add_smul_sub_mem /-- Affine subspaces are convex. -/ theorem AffineSubspace.convex (Q : AffineSubspace 𝕜 E) : Convex 𝕜 (Q : Set E) := fun x hx y hy a b _ _ hab ↦ by simpa [Convex.combo_eq_smul_sub_add hab] using Q.2 _ hy hx hx #align affine_subspace.convex AffineSubspace.convex /-- The preimage of a convex set under an affine map is convex. -/ theorem Convex.affine_preimage (f : E →ᵃ[𝕜] F) {s : Set F} (hs : Convex 𝕜 s) : Convex 𝕜 (f ⁻¹' s) := fun _ hx => (hs hx).affine_preimage _ #align convex.affine_preimage Convex.affine_preimage /-- The image of a convex set under an affine map is convex. -/ theorem Convex.affine_image (f : E →ᵃ[𝕜] F) (hs : Convex 𝕜 s) : Convex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ exact (hs hx).affine_image _ #align convex.affine_image Convex.affine_image theorem Convex.neg (hs : Convex 𝕜 s) : Convex 𝕜 (-s) := hs.is_linear_preimage IsLinearMap.isLinearMap_neg #align convex.neg Convex.neg theorem Convex.sub (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s - t) := by rw [sub_eq_add_neg] exact hs.add ht.neg #align convex.sub Convex.sub end AddCommGroup end OrderedRing section LinearOrderedRing variable [LinearOrderedRing 𝕜] [AddCommMonoid E] theorem Convex_subadditive_le [SMul 𝕜 E] {f : E → 𝕜} (hf1 : ∀ x y, f (x + y) ≤ (f x) + (f y)) (hf2 : ∀ ⦃c⦄ x, 0 ≤ c → f (c • x) ≤ c * f x) (B : 𝕜) : Convex 𝕜 { x | f x ≤ B } := by rw [convex_iff_segment_subset] rintro x hx y hy z ⟨a, b, ha, hb, hs, rfl⟩ calc _ ≤ a • (f x) + b • (f y) := le_trans (hf1 _ _) (add_le_add (hf2 x ha) (hf2 y hb)) _ ≤ a • B + b • B := add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb) _ ≤ B := by rw [← add_smul, hs, one_smul] end LinearOrderedRing section LinearOrderedField variable [LinearOrderedField 𝕜] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E} /-- Alternative definition of set convexity, using division. -/ theorem convex_iff_div : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s := forall₂_congr fun _ _ => starConvex_iff_div #align convex_iff_div convex_iff_div theorem Convex.mem_smul_of_zero_mem (h : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) {t : 𝕜} (ht : 1 ≤ t) : x ∈ t • s := by rw [mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne'] exact h.smul_mem_of_zero_mem zero_mem hx ⟨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one ht⟩ #align convex.mem_smul_of_zero_mem Convex.mem_smul_of_zero_mem theorem Convex.exists_mem_add_smul_eq (h : Convex 𝕜 s) {x y : E} {p q : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (hp : 0 ≤ p) (hq : 0 ≤ q) : ∃ z ∈ s, (p + q) • z = p • x + q • y := by rcases _root_.em (p = 0 ∧ q = 0) with (⟨rfl, rfl⟩ | hpq) · use x, hx simp · replace hpq : 0 < p + q := (add_nonneg hp hq).lt_of_ne' (mt (add_eq_zero_iff' hp hq).1 hpq) refine ⟨_, convex_iff_div.1 h hx hy hp hq hpq, ?_⟩ simp only [smul_add, smul_smul, mul_div_cancel₀ _ hpq.ne'] theorem Convex.add_smul (h_conv : Convex 𝕜 s) {p q : 𝕜} (hp : 0 ≤ p) (hq : 0 ≤ q) : (p + q) • s = p • s + q • s := (add_smul_subset _ _ _).antisymm <| by rintro _ ⟨_, ⟨v₁, h₁, rfl⟩, _, ⟨v₂, h₂, rfl⟩, rfl⟩ exact h_conv.exists_mem_add_smul_eq h₁ h₂ hp hq #align convex.add_smul Convex.add_smul end AddCommGroup end LinearOrderedField /-! #### Convex sets in an ordered space Relates `Convex` and `OrdConnected`. -/ section
Mathlib/Analysis/Convex/Basic.lean
621
627
theorem Set.OrdConnected.convex_of_chain [OrderedSemiring 𝕜] [OrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} (hs : s.OrdConnected) (h : IsChain (· ≤ ·) s) : Convex 𝕜 s := by
refine convex_iff_segment_subset.mpr fun x hx y hy => ?_ obtain hxy | hyx := h.total hx hy · exact (segment_subset_Icc hxy).trans (hs.out hx hy) · rw [segment_symm] exact (segment_subset_Icc hyx).trans (hs.out hy hx)
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Group.Even import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.Group.Commute.Units import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Ring.Units #align_import algebra.associated from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Associated, prime, and irreducible elements. In this file we define the predicate `Prime p` saying that an element of a commutative monoid with zero is prime. Namely, `Prime p` means that `p` isn't zero, it isn't a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`; In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`, however this is not true in general. We also define an equivalence relation `Associated` saying that two elements of a monoid differ by a multiplication by a unit. Then we show that the quotient type `Associates` is a monoid and prove basic properties of this quotient. -/ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section Prime variable [CommMonoidWithZero α] /-- An element `p` of a commutative monoid with zero (e.g., a ring) is called *prime*, if it's not zero, not a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`. -/ def Prime (p : α) : Prop := p ≠ 0 ∧ ¬IsUnit p ∧ ∀ a b, p ∣ a * b → p ∣ a ∨ p ∣ b #align prime Prime namespace Prime variable {p : α} (hp : Prime p) theorem ne_zero : p ≠ 0 := hp.1 #align prime.ne_zero Prime.ne_zero theorem not_unit : ¬IsUnit p := hp.2.1 #align prime.not_unit Prime.not_unit theorem not_dvd_one : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align prime.not_dvd_one Prime.not_dvd_one theorem ne_one : p ≠ 1 := fun h => hp.2.1 (h.symm ▸ isUnit_one) #align prime.ne_one Prime.ne_one theorem dvd_or_dvd (hp : Prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := hp.2.2 a b h #align prime.dvd_or_dvd Prime.dvd_or_dvd theorem dvd_mul {a b : α} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b := ⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩ theorem isPrimal (hp : Prime p) : IsPrimal p := fun _a _b dvd ↦ (hp.dvd_or_dvd dvd).elim (fun h ↦ ⟨p, 1, h, one_dvd _, (mul_one p).symm⟩) fun h ↦ ⟨1, p, one_dvd _, h, (one_mul p).symm⟩ theorem not_dvd_mul {a b : α} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b := hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩ theorem dvd_of_dvd_pow (hp : Prime p) {a : α} {n : ℕ} (h : p ∣ a ^ n) : p ∣ a := by induction' n with n ih · rw [pow_zero] at h have := isUnit_of_dvd_one h have := not_unit hp contradiction rw [pow_succ'] at h cases' dvd_or_dvd hp h with dvd_a dvd_pow · assumption exact ih dvd_pow #align prime.dvd_of_dvd_pow Prime.dvd_of_dvd_pow theorem dvd_pow_iff_dvd {a : α} {n : ℕ} (hn : n ≠ 0) : p ∣ a ^ n ↔ p ∣ a := ⟨hp.dvd_of_dvd_pow, (dvd_pow · hn)⟩ end Prime @[simp] theorem not_prime_zero : ¬Prime (0 : α) := fun h => h.ne_zero rfl #align not_prime_zero not_prime_zero @[simp] theorem not_prime_one : ¬Prime (1 : α) := fun h => h.not_unit isUnit_one #align not_prime_one not_prime_one section Map variable [CommMonoidWithZero β] {F : Type*} {G : Type*} [FunLike F α β] variable [MonoidWithZeroHomClass F α β] [FunLike G β α] [MulHomClass G β α] variable (f : F) (g : G) {p : α} theorem comap_prime (hinv : ∀ a, g (f a : β) = a) (hp : Prime (f p)) : Prime p := ⟨fun h => hp.1 <| by simp [h], fun h => hp.2.1 <| h.map f, fun a b h => by refine (hp.2.2 (f a) (f b) <| by convert map_dvd f h simp).imp ?_ ?_ <;> · intro h convert ← map_dvd g h <;> apply hinv⟩ #align comap_prime comap_prime theorem MulEquiv.prime_iff (e : α ≃* β) : Prime p ↔ Prime (e p) := ⟨fun h => (comap_prime e.symm e fun a => by simp) <| (e.symm_apply_apply p).substr h, comap_prime e e.symm fun a => by simp⟩ #align mul_equiv.prime_iff MulEquiv.prime_iff end Map end Prime theorem Prime.left_dvd_or_dvd_right_of_dvd_mul [CancelCommMonoidWithZero α] {p : α} (hp : Prime p) {a b : α} : a ∣ p * b → p ∣ a ∨ a ∣ b := by rintro ⟨c, hc⟩ rcases hp.2.2 a c (hc ▸ dvd_mul_right _ _) with (h | ⟨x, rfl⟩) · exact Or.inl h · rw [mul_left_comm, mul_right_inj' hp.ne_zero] at hc exact Or.inr (hc.symm ▸ dvd_mul_right _ _) #align prime.left_dvd_or_dvd_right_of_dvd_mul Prime.left_dvd_or_dvd_right_of_dvd_mul theorem Prime.pow_dvd_of_dvd_mul_left [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ a) (h' : p ^ n ∣ a * b) : p ^ n ∣ b := by induction' n with n ih · rw [pow_zero] exact one_dvd b · obtain ⟨c, rfl⟩ := ih (dvd_trans (pow_dvd_pow p n.le_succ) h') rw [pow_succ] apply mul_dvd_mul_left _ ((hp.dvd_or_dvd _).resolve_left h) rwa [← mul_dvd_mul_iff_left (pow_ne_zero n hp.ne_zero), ← pow_succ, mul_left_comm] #align prime.pow_dvd_of_dvd_mul_left Prime.pow_dvd_of_dvd_mul_left theorem Prime.pow_dvd_of_dvd_mul_right [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ b) (h' : p ^ n ∣ a * b) : p ^ n ∣ a := by rw [mul_comm] at h' exact hp.pow_dvd_of_dvd_mul_left n h h' #align prime.pow_dvd_of_dvd_mul_right Prime.pow_dvd_of_dvd_mul_right theorem Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd [CancelCommMonoidWithZero α] {p a b : α} {n : ℕ} (hp : Prime p) (hpow : p ^ n.succ ∣ a ^ n.succ * b ^ n) (hb : ¬p ^ 2 ∣ b) : p ∣ a := by -- Suppose `p ∣ b`, write `b = p * x` and `hy : a ^ n.succ * b ^ n = p ^ n.succ * y`. cases' hp.dvd_or_dvd ((dvd_pow_self p (Nat.succ_ne_zero n)).trans hpow) with H hbdiv · exact hp.dvd_of_dvd_pow H obtain ⟨x, rfl⟩ := hp.dvd_of_dvd_pow hbdiv obtain ⟨y, hy⟩ := hpow -- Then we can divide out a common factor of `p ^ n` from the equation `hy`. have : a ^ n.succ * x ^ n = p * y := by refine mul_left_cancel₀ (pow_ne_zero n hp.ne_zero) ?_ rw [← mul_assoc _ p, ← pow_succ, ← hy, mul_pow, ← mul_assoc (a ^ n.succ), mul_comm _ (p ^ n), mul_assoc] -- So `p ∣ a` (and we're done) or `p ∣ x`, which can't be the case since it implies `p^2 ∣ b`. refine hp.dvd_of_dvd_pow ((hp.dvd_or_dvd ⟨_, this⟩).resolve_right fun hdvdx => hb ?_) obtain ⟨z, rfl⟩ := hp.dvd_of_dvd_pow hdvdx rw [pow_two, ← mul_assoc] exact dvd_mul_right _ _ #align prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd theorem prime_pow_succ_dvd_mul {α : Type*} [CancelCommMonoidWithZero α] {p x y : α} (h : Prime p) {i : ℕ} (hxy : p ^ (i + 1) ∣ x * y) : p ^ (i + 1) ∣ x ∨ p ∣ y := by rw [or_iff_not_imp_right] intro hy induction' i with i ih generalizing x · rw [pow_one] at hxy ⊢ exact (h.dvd_or_dvd hxy).resolve_right hy rw [pow_succ'] at hxy ⊢ obtain ⟨x', rfl⟩ := (h.dvd_or_dvd (dvd_of_mul_right_dvd hxy)).resolve_right hy rw [mul_assoc] at hxy exact mul_dvd_mul_left p (ih ((mul_dvd_mul_iff_left h.ne_zero).mp hxy)) #align prime_pow_succ_dvd_mul prime_pow_succ_dvd_mul /-- `Irreducible p` states that `p` is non-unit and only factors into units. We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a monoid allows us to reuse irreducible for associated elements. -/ structure Irreducible [Monoid α] (p : α) : Prop where /-- `p` is not a unit -/ not_unit : ¬IsUnit p /-- if `p` factors then one factor is a unit -/ isUnit_or_isUnit' : ∀ a b, p = a * b → IsUnit a ∨ IsUnit b #align irreducible Irreducible namespace Irreducible theorem not_dvd_one [CommMonoid α] {p : α} (hp : Irreducible p) : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align irreducible.not_dvd_one Irreducible.not_dvd_one theorem isUnit_or_isUnit [Monoid α] {p : α} (hp : Irreducible p) {a b : α} (h : p = a * b) : IsUnit a ∨ IsUnit b := hp.isUnit_or_isUnit' a b h #align irreducible.is_unit_or_is_unit Irreducible.isUnit_or_isUnit end Irreducible theorem irreducible_iff [Monoid α] {p : α} : Irreducible p ↔ ¬IsUnit p ∧ ∀ a b, p = a * b → IsUnit a ∨ IsUnit b := ⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩ #align irreducible_iff irreducible_iff @[simp] theorem not_irreducible_one [Monoid α] : ¬Irreducible (1 : α) := by simp [irreducible_iff] #align not_irreducible_one not_irreducible_one theorem Irreducible.ne_one [Monoid α] : ∀ {p : α}, Irreducible p → p ≠ 1 | _, hp, rfl => not_irreducible_one hp #align irreducible.ne_one Irreducible.ne_one @[simp] theorem not_irreducible_zero [MonoidWithZero α] : ¬Irreducible (0 : α) | ⟨hn0, h⟩ => have : IsUnit (0 : α) ∨ IsUnit (0 : α) := h 0 0 (mul_zero 0).symm this.elim hn0 hn0 #align not_irreducible_zero not_irreducible_zero theorem Irreducible.ne_zero [MonoidWithZero α] : ∀ {p : α}, Irreducible p → p ≠ 0 | _, hp, rfl => not_irreducible_zero hp #align irreducible.ne_zero Irreducible.ne_zero theorem of_irreducible_mul {α} [Monoid α] {x y : α} : Irreducible (x * y) → IsUnit x ∨ IsUnit y | ⟨_, h⟩ => h _ _ rfl #align of_irreducible_mul of_irreducible_mul theorem not_irreducible_pow {α} [Monoid α] {x : α} {n : ℕ} (hn : n ≠ 1) : ¬ Irreducible (x ^ n) := by cases n with | zero => simp | succ n => intro ⟨h₁, h₂⟩ have := h₂ _ _ (pow_succ _ _) rw [isUnit_pow_iff (Nat.succ_ne_succ.mp hn), or_self] at this exact h₁ (this.pow _) #noalign of_irreducible_pow theorem irreducible_or_factor {α} [Monoid α] (x : α) (h : ¬IsUnit x) : Irreducible x ∨ ∃ a b, ¬IsUnit a ∧ ¬IsUnit b ∧ a * b = x := by haveI := Classical.dec refine or_iff_not_imp_right.2 fun H => ?_ simp? [h, irreducible_iff] at H ⊢ says simp only [exists_and_left, not_exists, not_and, irreducible_iff, h, not_false_eq_true, true_and] at H ⊢ refine fun a b h => by_contradiction fun o => ?_ simp? [not_or] at o says simp only [not_or] at o exact H _ o.1 _ o.2 h.symm #align irreducible_or_factor irreducible_or_factor /-- If `p` and `q` are irreducible, then `p ∣ q` implies `q ∣ p`. -/ theorem Irreducible.dvd_symm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) : p ∣ q → q ∣ p := by rintro ⟨q', rfl⟩ rw [IsUnit.mul_right_dvd (Or.resolve_left (of_irreducible_mul hq) hp.not_unit)] #align irreducible.dvd_symm Irreducible.dvd_symm theorem Irreducible.dvd_comm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) : p ∣ q ↔ q ∣ p := ⟨hp.dvd_symm hq, hq.dvd_symm hp⟩ #align irreducible.dvd_comm Irreducible.dvd_comm section variable [Monoid α] theorem irreducible_units_mul (a : αˣ) (b : α) : Irreducible (↑a * b) ↔ Irreducible b := by simp only [irreducible_iff, Units.isUnit_units_mul, and_congr_right_iff] refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩ · rw [← a.isUnit_units_mul] apply h rw [mul_assoc, ← HAB] · rw [← a⁻¹.isUnit_units_mul] apply h rw [mul_assoc, ← HAB, Units.inv_mul_cancel_left] #align irreducible_units_mul irreducible_units_mul theorem irreducible_isUnit_mul {a b : α} (h : IsUnit a) : Irreducible (a * b) ↔ Irreducible b := let ⟨a, ha⟩ := h ha ▸ irreducible_units_mul a b #align irreducible_is_unit_mul irreducible_isUnit_mul theorem irreducible_mul_units (a : αˣ) (b : α) : Irreducible (b * ↑a) ↔ Irreducible b := by simp only [irreducible_iff, Units.isUnit_mul_units, and_congr_right_iff] refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩ · rw [← Units.isUnit_mul_units B a] apply h rw [← mul_assoc, ← HAB] · rw [← Units.isUnit_mul_units B a⁻¹] apply h rw [← mul_assoc, ← HAB, Units.mul_inv_cancel_right] #align irreducible_mul_units irreducible_mul_units theorem irreducible_mul_isUnit {a b : α} (h : IsUnit a) : Irreducible (b * a) ↔ Irreducible b := let ⟨a, ha⟩ := h ha ▸ irreducible_mul_units a b #align irreducible_mul_is_unit irreducible_mul_isUnit theorem irreducible_mul_iff {a b : α} : Irreducible (a * b) ↔ Irreducible a ∧ IsUnit b ∨ Irreducible b ∧ IsUnit a := by constructor · refine fun h => Or.imp (fun h' => ⟨?_, h'⟩) (fun h' => ⟨?_, h'⟩) (h.isUnit_or_isUnit rfl).symm · rwa [irreducible_mul_isUnit h'] at h · rwa [irreducible_isUnit_mul h'] at h · rintro (⟨ha, hb⟩ | ⟨hb, ha⟩) · rwa [irreducible_mul_isUnit hb] · rwa [irreducible_isUnit_mul ha] #align irreducible_mul_iff irreducible_mul_iff end section CommMonoid variable [CommMonoid α] {a : α} theorem Irreducible.not_square (ha : Irreducible a) : ¬IsSquare a := by rw [isSquare_iff_exists_sq] rintro ⟨b, rfl⟩ exact not_irreducible_pow (by decide) ha #align irreducible.not_square Irreducible.not_square theorem IsSquare.not_irreducible (ha : IsSquare a) : ¬Irreducible a := fun h => h.not_square ha #align is_square.not_irreducible IsSquare.not_irreducible end CommMonoid section CommMonoidWithZero variable [CommMonoidWithZero α] theorem Irreducible.prime_of_isPrimal {a : α} (irr : Irreducible a) (primal : IsPrimal a) : Prime a := ⟨irr.ne_zero, irr.not_unit, fun a b dvd ↦ by obtain ⟨d₁, d₂, h₁, h₂, rfl⟩ := primal dvd exact (of_irreducible_mul irr).symm.imp (·.mul_right_dvd.mpr h₁) (·.mul_left_dvd.mpr h₂)⟩ theorem Irreducible.prime [DecompositionMonoid α] {a : α} (irr : Irreducible a) : Prime a := irr.prime_of_isPrimal (DecompositionMonoid.primal a) end CommMonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero α] {a p : α} protected theorem Prime.irreducible (hp : Prime p) : Irreducible p := ⟨hp.not_unit, fun a b ↦ by rintro rfl exact (hp.dvd_or_dvd dvd_rfl).symm.imp (isUnit_of_dvd_one <| (mul_dvd_mul_iff_right <| right_ne_zero_of_mul hp.ne_zero).mp <| dvd_mul_of_dvd_right · _) (isUnit_of_dvd_one <| (mul_dvd_mul_iff_left <| left_ne_zero_of_mul hp.ne_zero).mp <| dvd_mul_of_dvd_left · _)⟩ #align prime.irreducible Prime.irreducible theorem irreducible_iff_prime [DecompositionMonoid α] {a : α} : Irreducible a ↔ Prime a := ⟨Irreducible.prime, Prime.irreducible⟩ theorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul (hp : Prime p) {a b : α} {k l : ℕ} : p ^ k ∣ a → p ^ l ∣ b → p ^ (k + l + 1) ∣ a * b → p ^ (k + 1) ∣ a ∨ p ^ (l + 1) ∣ b := fun ⟨x, hx⟩ ⟨y, hy⟩ ⟨z, hz⟩ => have h : p ^ (k + l) * (x * y) = p ^ (k + l) * (p * z) := by simpa [mul_comm, pow_add, hx, hy, mul_assoc, mul_left_comm] using hz have hp0 : p ^ (k + l) ≠ 0 := pow_ne_zero _ hp.ne_zero have hpd : p ∣ x * y := ⟨z, by rwa [mul_right_inj' hp0] at h⟩ (hp.dvd_or_dvd hpd).elim (fun ⟨d, hd⟩ => Or.inl ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩) fun ⟨d, hd⟩ => Or.inr ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩ #align succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul theorem Prime.not_square (hp : Prime p) : ¬IsSquare p := hp.irreducible.not_square #align prime.not_square Prime.not_square theorem IsSquare.not_prime (ha : IsSquare a) : ¬Prime a := fun h => h.not_square ha #align is_square.not_prime IsSquare.not_prime theorem not_prime_pow {n : ℕ} (hn : n ≠ 1) : ¬Prime (a ^ n) := fun hp => not_irreducible_pow hn hp.irreducible #align pow_not_prime not_prime_pow end CancelCommMonoidWithZero /-- Two elements of a `Monoid` are `Associated` if one of them is another one multiplied by a unit on the right. -/ def Associated [Monoid α] (x y : α) : Prop := ∃ u : αˣ, x * u = y #align associated Associated /-- Notation for two elements of a monoid are associated, i.e. if one of them is another one multiplied by a unit on the right. -/ local infixl:50 " ~ᵤ " => Associated namespace Associated @[refl] protected theorem refl [Monoid α] (x : α) : x ~ᵤ x := ⟨1, by simp⟩ #align associated.refl Associated.refl protected theorem rfl [Monoid α] {x : α} : x ~ᵤ x := .refl x instance [Monoid α] : IsRefl α Associated := ⟨Associated.refl⟩ @[symm] protected theorem symm [Monoid α] : ∀ {x y : α}, x ~ᵤ y → y ~ᵤ x | x, _, ⟨u, rfl⟩ => ⟨u⁻¹, by rw [mul_assoc, Units.mul_inv, mul_one]⟩ #align associated.symm Associated.symm instance [Monoid α] : IsSymm α Associated := ⟨fun _ _ => Associated.symm⟩ protected theorem comm [Monoid α] {x y : α} : x ~ᵤ y ↔ y ~ᵤ x := ⟨Associated.symm, Associated.symm⟩ #align associated.comm Associated.comm @[trans] protected theorem trans [Monoid α] : ∀ {x y z : α}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z | x, _, _, ⟨u, rfl⟩, ⟨v, rfl⟩ => ⟨u * v, by rw [Units.val_mul, mul_assoc]⟩ #align associated.trans Associated.trans instance [Monoid α] : IsTrans α Associated := ⟨fun _ _ _ => Associated.trans⟩ /-- The setoid of the relation `x ~ᵤ y` iff there is a unit `u` such that `x * u = y` -/ protected def setoid (α : Type*) [Monoid α] : Setoid α where r := Associated iseqv := ⟨Associated.refl, Associated.symm, Associated.trans⟩ #align associated.setoid Associated.setoid theorem map {M N : Type*} [Monoid M] [Monoid N] {F : Type*} [FunLike F M N] [MonoidHomClass F M N] (f : F) {x y : M} (ha : Associated x y) : Associated (f x) (f y) := by obtain ⟨u, ha⟩ := ha exact ⟨Units.map f u, by rw [← ha, map_mul, Units.coe_map, MonoidHom.coe_coe]⟩ end Associated attribute [local instance] Associated.setoid theorem unit_associated_one [Monoid α] {u : αˣ} : (u : α) ~ᵤ 1 := ⟨u⁻¹, Units.mul_inv u⟩ #align unit_associated_one unit_associated_one @[simp] theorem associated_one_iff_isUnit [Monoid α] {a : α} : (a : α) ~ᵤ 1 ↔ IsUnit a := Iff.intro (fun h => let ⟨c, h⟩ := h.symm h ▸ ⟨c, (one_mul _).symm⟩) fun ⟨c, h⟩ => Associated.symm ⟨c, by simp [h]⟩ #align associated_one_iff_is_unit associated_one_iff_isUnit @[simp] theorem associated_zero_iff_eq_zero [MonoidWithZero α] (a : α) : a ~ᵤ 0 ↔ a = 0 := Iff.intro (fun h => by let ⟨u, h⟩ := h.symm simpa using h.symm) fun h => h ▸ Associated.refl a #align associated_zero_iff_eq_zero associated_zero_iff_eq_zero theorem associated_one_of_mul_eq_one [CommMonoid α] {a : α} (b : α) (hab : a * b = 1) : a ~ᵤ 1 := show (Units.mkOfMulEqOne a b hab : α) ~ᵤ 1 from unit_associated_one #align associated_one_of_mul_eq_one associated_one_of_mul_eq_one theorem associated_one_of_associated_mul_one [CommMonoid α] {a b : α} : a * b ~ᵤ 1 → a ~ᵤ 1 | ⟨u, h⟩ => associated_one_of_mul_eq_one (b * u) <| by simpa [mul_assoc] using h #align associated_one_of_associated_mul_one associated_one_of_associated_mul_one theorem associated_mul_unit_left {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) : Associated (a * u) a := let ⟨u', hu⟩ := hu ⟨u'⁻¹, hu ▸ Units.mul_inv_cancel_right _ _⟩ #align associated_mul_unit_left associated_mul_unit_left theorem associated_unit_mul_left {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) : Associated (u * a) a := by rw [mul_comm] exact associated_mul_unit_left _ _ hu #align associated_unit_mul_left associated_unit_mul_left theorem associated_mul_unit_right {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) : Associated a (a * u) := (associated_mul_unit_left a u hu).symm #align associated_mul_unit_right associated_mul_unit_right theorem associated_unit_mul_right {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) : Associated a (u * a) := (associated_unit_mul_left a u hu).symm #align associated_unit_mul_right associated_unit_mul_right theorem associated_mul_isUnit_left_iff {β : Type*} [Monoid β] {a u b : β} (hu : IsUnit u) : Associated (a * u) b ↔ Associated a b := ⟨(associated_mul_unit_right _ _ hu).trans, (associated_mul_unit_left _ _ hu).trans⟩ #align associated_mul_is_unit_left_iff associated_mul_isUnit_left_iff theorem associated_isUnit_mul_left_iff {β : Type*} [CommMonoid β] {u a b : β} (hu : IsUnit u) : Associated (u * a) b ↔ Associated a b := by rw [mul_comm] exact associated_mul_isUnit_left_iff hu #align associated_is_unit_mul_left_iff associated_isUnit_mul_left_iff theorem associated_mul_isUnit_right_iff {β : Type*} [Monoid β] {a b u : β} (hu : IsUnit u) : Associated a (b * u) ↔ Associated a b := Associated.comm.trans <| (associated_mul_isUnit_left_iff hu).trans Associated.comm #align associated_mul_is_unit_right_iff associated_mul_isUnit_right_iff theorem associated_isUnit_mul_right_iff {β : Type*} [CommMonoid β] {a u b : β} (hu : IsUnit u) : Associated a (u * b) ↔ Associated a b := Associated.comm.trans <| (associated_isUnit_mul_left_iff hu).trans Associated.comm #align associated_is_unit_mul_right_iff associated_isUnit_mul_right_iff @[simp] theorem associated_mul_unit_left_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} : Associated (a * u) b ↔ Associated a b := associated_mul_isUnit_left_iff u.isUnit #align associated_mul_unit_left_iff associated_mul_unit_left_iff @[simp] theorem associated_unit_mul_left_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} : Associated (↑u * a) b ↔ Associated a b := associated_isUnit_mul_left_iff u.isUnit #align associated_unit_mul_left_iff associated_unit_mul_left_iff @[simp] theorem associated_mul_unit_right_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} : Associated a (b * u) ↔ Associated a b := associated_mul_isUnit_right_iff u.isUnit #align associated_mul_unit_right_iff associated_mul_unit_right_iff @[simp] theorem associated_unit_mul_right_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} : Associated a (↑u * b) ↔ Associated a b := associated_isUnit_mul_right_iff u.isUnit #align associated_unit_mul_right_iff associated_unit_mul_right_iff theorem Associated.mul_left [Monoid α] (a : α) {b c : α} (h : b ~ᵤ c) : a * b ~ᵤ a * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_assoc _ _ _⟩ #align associated.mul_left Associated.mul_left theorem Associated.mul_right [CommMonoid α] {a b : α} (h : a ~ᵤ b) (c : α) : a * c ~ᵤ b * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_right_comm _ _ _⟩ #align associated.mul_right Associated.mul_right theorem Associated.mul_mul [CommMonoid α] {a₁ a₂ b₁ b₂ : α} (h₁ : a₁ ~ᵤ b₁) (h₂ : a₂ ~ᵤ b₂) : a₁ * a₂ ~ᵤ b₁ * b₂ := (h₁.mul_right _).trans (h₂.mul_left _) #align associated.mul_mul Associated.mul_mul theorem Associated.pow_pow [CommMonoid α] {a b : α} {n : ℕ} (h : a ~ᵤ b) : a ^ n ~ᵤ b ^ n := by induction' n with n ih · simp [Associated.refl] convert h.mul_mul ih <;> rw [pow_succ'] #align associated.pow_pow Associated.pow_pow protected theorem Associated.dvd [Monoid α] {a b : α} : a ~ᵤ b → a ∣ b := fun ⟨u, hu⟩ => ⟨u, hu.symm⟩ #align associated.dvd Associated.dvd protected theorem Associated.dvd' [Monoid α] {a b : α} (h : a ~ᵤ b) : b ∣ a := h.symm.dvd protected theorem Associated.dvd_dvd [Monoid α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a := ⟨h.dvd, h.symm.dvd⟩ #align associated.dvd_dvd Associated.dvd_dvd theorem associated_of_dvd_dvd [CancelMonoidWithZero α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b := by rcases hab with ⟨c, rfl⟩ rcases hba with ⟨d, a_eq⟩ by_cases ha0 : a = 0 · simp_all have hac0 : a * c ≠ 0 := by intro con rw [con, zero_mul] at a_eq apply ha0 a_eq have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hcd : c * d = 1 := mul_left_cancel₀ ha0 this have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hdc : d * c = 1 := mul_left_cancel₀ hac0 this exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩ #align associated_of_dvd_dvd associated_of_dvd_dvd theorem dvd_dvd_iff_associated [CancelMonoidWithZero α] {a b : α} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b := ⟨fun ⟨h1, h2⟩ => associated_of_dvd_dvd h1 h2, Associated.dvd_dvd⟩ #align dvd_dvd_iff_associated dvd_dvd_iff_associated instance [CancelMonoidWithZero α] [DecidableRel ((· ∣ ·) : α → α → Prop)] : DecidableRel ((· ~ᵤ ·) : α → α → Prop) := fun _ _ => decidable_of_iff _ dvd_dvd_iff_associated theorem Associated.dvd_iff_dvd_left [Monoid α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.mul_right_dvd.symm #align associated.dvd_iff_dvd_left Associated.dvd_iff_dvd_left theorem Associated.dvd_iff_dvd_right [Monoid α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.dvd_mul_right.symm #align associated.dvd_iff_dvd_right Associated.dvd_iff_dvd_right theorem Associated.eq_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a = 0 ↔ b = 0 := by obtain ⟨u, rfl⟩ := h rw [← Units.eq_mul_inv_iff_mul_eq, zero_mul] #align associated.eq_zero_iff Associated.eq_zero_iff theorem Associated.ne_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 := not_congr h.eq_zero_iff #align associated.ne_zero_iff Associated.ne_zero_iff theorem Associated.neg_left [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated (-a) b := let ⟨u, hu⟩ := h; ⟨-u, by simp [hu]⟩ theorem Associated.neg_right [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated a (-b) := h.symm.neg_left.symm theorem Associated.neg_neg [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated (-a) (-b) := h.neg_left.neg_right protected theorem Associated.prime [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) (hp : Prime p) : Prime q := ⟨h.ne_zero_iff.1 hp.ne_zero, let ⟨u, hu⟩ := h ⟨fun ⟨v, hv⟩ => hp.not_unit ⟨v * u⁻¹, by simp [hv, hu.symm]⟩, hu ▸ by simp only [IsUnit.mul_iff, Units.isUnit, and_true, IsUnit.mul_right_dvd] intro a b exact hp.dvd_or_dvd⟩⟩ #align associated.prime Associated.prime theorem prime_mul_iff [CancelCommMonoidWithZero α] {x y : α} : Prime (x * y) ↔ (Prime x ∧ IsUnit y) ∨ (IsUnit x ∧ Prime y) := by refine ⟨fun h ↦ ?_, ?_⟩ · rcases of_irreducible_mul h.irreducible with hx | hy · exact Or.inr ⟨hx, (associated_unit_mul_left y x hx).prime h⟩ · exact Or.inl ⟨(associated_mul_unit_left x y hy).prime h, hy⟩ · rintro (⟨hx, hy⟩ | ⟨hx, hy⟩) · exact (associated_mul_unit_left x y hy).symm.prime hx · exact (associated_unit_mul_right y x hx).prime hy @[simp] lemma prime_pow_iff [CancelCommMonoidWithZero α] {p : α} {n : ℕ} : Prime (p ^ n) ↔ Prime p ∧ n = 1 := by refine ⟨fun hp ↦ ?_, fun ⟨hp, hn⟩ ↦ by simpa [hn]⟩ suffices n = 1 by aesop cases' n with n · simp at hp · rw [Nat.succ.injEq] rw [pow_succ', prime_mul_iff] at hp rcases hp with ⟨hp, hpn⟩ | ⟨hp, hpn⟩ · by_contra contra rw [isUnit_pow_iff contra] at hpn exact hp.not_unit hpn · exfalso exact hpn.not_unit (hp.pow n) theorem Irreducible.dvd_iff [Monoid α] {x y : α} (hx : Irreducible x) : y ∣ x ↔ IsUnit y ∨ Associated x y := by constructor · rintro ⟨z, hz⟩ obtain (h|h) := hx.isUnit_or_isUnit hz · exact Or.inl h · rw [hz] exact Or.inr (associated_mul_unit_left _ _ h) · rintro (hy|h) · exact hy.dvd · exact h.symm.dvd theorem Irreducible.associated_of_dvd [Monoid α] {p q : α} (p_irr : Irreducible p) (q_irr : Irreducible q) (dvd : p ∣ q) : Associated p q := ((q_irr.dvd_iff.mp dvd).resolve_left p_irr.not_unit).symm #align irreducible.associated_of_dvd Irreducible.associated_of_dvdₓ theorem Irreducible.dvd_irreducible_iff_associated [Monoid α] {p q : α} (pp : Irreducible p) (qp : Irreducible q) : p ∣ q ↔ Associated p q := ⟨Irreducible.associated_of_dvd pp qp, Associated.dvd⟩ #align irreducible.dvd_irreducible_iff_associated Irreducible.dvd_irreducible_iff_associated theorem Prime.associated_of_dvd [CancelCommMonoidWithZero α] {p q : α} (p_prime : Prime p) (q_prime : Prime q) (dvd : p ∣ q) : Associated p q := p_prime.irreducible.associated_of_dvd q_prime.irreducible dvd #align prime.associated_of_dvd Prime.associated_of_dvd theorem Prime.dvd_prime_iff_associated [CancelCommMonoidWithZero α] {p q : α} (pp : Prime p) (qp : Prime q) : p ∣ q ↔ Associated p q := pp.irreducible.dvd_irreducible_iff_associated qp.irreducible #align prime.dvd_prime_iff_associated Prime.dvd_prime_iff_associated theorem Associated.prime_iff [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) : Prime p ↔ Prime q := ⟨h.prime, h.symm.prime⟩ #align associated.prime_iff Associated.prime_iff protected theorem Associated.isUnit [Monoid α] {a b : α} (h : a ~ᵤ b) : IsUnit a → IsUnit b := let ⟨u, hu⟩ := h fun ⟨v, hv⟩ => ⟨v * u, by simp [hv, hu.symm]⟩ #align associated.is_unit Associated.isUnit theorem Associated.isUnit_iff [Monoid α] {a b : α} (h : a ~ᵤ b) : IsUnit a ↔ IsUnit b := ⟨h.isUnit, h.symm.isUnit⟩ #align associated.is_unit_iff Associated.isUnit_iff theorem Irreducible.isUnit_iff_not_associated_of_dvd [Monoid α] {x y : α} (hx : Irreducible x) (hy : y ∣ x) : IsUnit y ↔ ¬ Associated x y := ⟨fun hy hxy => hx.1 (hxy.symm.isUnit hy), (hx.dvd_iff.mp hy).resolve_right⟩ protected theorem Associated.irreducible [Monoid α] {p q : α} (h : p ~ᵤ q) (hp : Irreducible p) : Irreducible q := ⟨mt h.symm.isUnit hp.1, let ⟨u, hu⟩ := h fun a b hab => have hpab : p = a * (b * (u⁻¹ : αˣ)) := calc p = p * u * (u⁻¹ : αˣ) := by simp _ = _ := by rw [hu]; simp [hab, mul_assoc] (hp.isUnit_or_isUnit hpab).elim Or.inl fun ⟨v, hv⟩ => Or.inr ⟨v * u, by simp [hv]⟩⟩ #align associated.irreducible Associated.irreducible protected theorem Associated.irreducible_iff [Monoid α] {p q : α} (h : p ~ᵤ q) : Irreducible p ↔ Irreducible q := ⟨h.irreducible, h.symm.irreducible⟩ #align associated.irreducible_iff Associated.irreducible_iff theorem Associated.of_mul_left [CancelCommMonoidWithZero α] {a b c d : α} (h : a * b ~ᵤ c * d) (h₁ : a ~ᵤ c) (ha : a ≠ 0) : b ~ᵤ d := let ⟨u, hu⟩ := h let ⟨v, hv⟩ := Associated.symm h₁ ⟨u * (v : αˣ), mul_left_cancel₀ ha (by rw [← hv, mul_assoc c (v : α) d, mul_left_comm c, ← hu] simp [hv.symm, mul_assoc, mul_comm, mul_left_comm])⟩ #align associated.of_mul_left Associated.of_mul_left theorem Associated.of_mul_right [CancelCommMonoidWithZero α] {a b c d : α} : a * b ~ᵤ c * d → b ~ᵤ d → b ≠ 0 → a ~ᵤ c := by rw [mul_comm a, mul_comm c]; exact Associated.of_mul_left #align associated.of_mul_right Associated.of_mul_right theorem Associated.of_pow_associated_of_prime [CancelCommMonoidWithZero α] {p₁ p₂ : α} {k₁ k₂ : ℕ} (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := by have : p₁ ∣ p₂ ^ k₂ := by rw [← h.dvd_iff_dvd_right] apply dvd_pow_self _ hk₁.ne' rw [← hp₁.dvd_prime_iff_associated hp₂] exact hp₁.dvd_of_dvd_pow this #align associated.of_pow_associated_of_prime Associated.of_pow_associated_of_prime theorem Associated.of_pow_associated_of_prime' [CancelCommMonoidWithZero α] {p₁ p₂ : α} {k₁ k₂ : ℕ} (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₂ : 0 < k₂) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := (h.symm.of_pow_associated_of_prime hp₂ hp₁ hk₂).symm #align associated.of_pow_associated_of_prime' Associated.of_pow_associated_of_prime' /-- See also `Irreducible.coprime_iff_not_dvd`. -/ lemma Irreducible.isRelPrime_iff_not_dvd [Monoid α] {p n : α} (hp : Irreducible p) : IsRelPrime p n ↔ ¬ p ∣ n := by refine ⟨fun h contra ↦ hp.not_unit (h dvd_rfl contra), fun hpn d hdp hdn ↦ ?_⟩ contrapose! hpn suffices Associated p d from this.dvd.trans hdn exact (hp.dvd_iff.mp hdp).resolve_left hpn lemma Irreducible.dvd_or_isRelPrime [Monoid α] {p n : α} (hp : Irreducible p) : p ∣ n ∨ IsRelPrime p n := Classical.or_iff_not_imp_left.mpr hp.isRelPrime_iff_not_dvd.2 section UniqueUnits variable [Monoid α] [Unique αˣ] theorem associated_iff_eq {x y : α} : x ~ᵤ y ↔ x = y := by constructor · rintro ⟨c, rfl⟩ rw [units_eq_one c, Units.val_one, mul_one] · rintro rfl rfl #align associated_iff_eq associated_iff_eq theorem associated_eq_eq : (Associated : α → α → Prop) = Eq := by ext rw [associated_iff_eq] #align associated_eq_eq associated_eq_eq theorem prime_dvd_prime_iff_eq {M : Type*} [CancelCommMonoidWithZero M] [Unique Mˣ] {p q : M} (pp : Prime p) (qp : Prime q) : p ∣ q ↔ p = q := by rw [pp.dvd_prime_iff_associated qp, ← associated_eq_eq] #align prime_dvd_prime_iff_eq prime_dvd_prime_iff_eq end UniqueUnits section UniqueUnits₀ variable {R : Type*} [CancelCommMonoidWithZero R] [Unique Rˣ] {p₁ p₂ : R} {k₁ k₂ : ℕ} theorem eq_of_prime_pow_eq (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by rw [← associated_iff_eq] at h ⊢ apply h.of_pow_associated_of_prime hp₁ hp₂ hk₁ #align eq_of_prime_pow_eq eq_of_prime_pow_eq theorem eq_of_prime_pow_eq' (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₂) (h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by rw [← associated_iff_eq] at h ⊢ apply h.of_pow_associated_of_prime' hp₁ hp₂ hk₁ #align eq_of_prime_pow_eq' eq_of_prime_pow_eq' end UniqueUnits₀ /-- The quotient of a monoid by the `Associated` relation. Two elements `x` and `y` are associated iff there is a unit `u` such that `x * u = y`. There is a natural monoid structure on `Associates α`. -/ abbrev Associates (α : Type*) [Monoid α] : Type _ := Quotient (Associated.setoid α) #align associates Associates namespace Associates open Associated /-- The canonical quotient map from a monoid `α` into the `Associates` of `α` -/ protected abbrev mk {α : Type*} [Monoid α] (a : α) : Associates α := ⟦a⟧ #align associates.mk Associates.mk instance [Monoid α] : Inhabited (Associates α) := ⟨⟦1⟧⟩ theorem mk_eq_mk_iff_associated [Monoid α] {a b : α} : Associates.mk a = Associates.mk b ↔ a ~ᵤ b := Iff.intro Quotient.exact Quot.sound #align associates.mk_eq_mk_iff_associated Associates.mk_eq_mk_iff_associated theorem quotient_mk_eq_mk [Monoid α] (a : α) : ⟦a⟧ = Associates.mk a := rfl #align associates.quotient_mk_eq_mk Associates.quotient_mk_eq_mk theorem quot_mk_eq_mk [Monoid α] (a : α) : Quot.mk Setoid.r a = Associates.mk a := rfl #align associates.quot_mk_eq_mk Associates.quot_mk_eq_mk @[simp] theorem quot_out [Monoid α] (a : Associates α) : Associates.mk (Quot.out a) = a := by rw [← quot_mk_eq_mk, Quot.out_eq] #align associates.quot_out Associates.quot_outₓ theorem mk_quot_out [Monoid α] (a : α) : Quot.out (Associates.mk a) ~ᵤ a := by rw [← Associates.mk_eq_mk_iff_associated, Associates.quot_out] theorem forall_associated [Monoid α] {p : Associates α → Prop} : (∀ a, p a) ↔ ∀ a, p (Associates.mk a) := Iff.intro (fun h _ => h _) fun h a => Quotient.inductionOn a h #align associates.forall_associated Associates.forall_associated theorem mk_surjective [Monoid α] : Function.Surjective (@Associates.mk α _) := forall_associated.2 fun a => ⟨a, rfl⟩ #align associates.mk_surjective Associates.mk_surjective instance [Monoid α] : One (Associates α) := ⟨⟦1⟧⟩ @[simp] theorem mk_one [Monoid α] : Associates.mk (1 : α) = 1 := rfl #align associates.mk_one Associates.mk_one theorem one_eq_mk_one [Monoid α] : (1 : Associates α) = Associates.mk 1 := rfl #align associates.one_eq_mk_one Associates.one_eq_mk_one @[simp] theorem mk_eq_one [Monoid α] {a : α} : Associates.mk a = 1 ↔ IsUnit a := by rw [← mk_one, mk_eq_mk_iff_associated, associated_one_iff_isUnit] instance [Monoid α] : Bot (Associates α) := ⟨1⟩ theorem bot_eq_one [Monoid α] : (⊥ : Associates α) = 1 := rfl #align associates.bot_eq_one Associates.bot_eq_one theorem exists_rep [Monoid α] (a : Associates α) : ∃ a0 : α, Associates.mk a0 = a := Quot.exists_rep a #align associates.exists_rep Associates.exists_rep instance [Monoid α] [Subsingleton α] : Unique (Associates α) where default := 1 uniq := forall_associated.2 fun _ ↦ mk_eq_one.2 <| isUnit_of_subsingleton _ theorem mk_injective [Monoid α] [Unique (Units α)] : Function.Injective (@Associates.mk α _) := fun _ _ h => associated_iff_eq.mp (Associates.mk_eq_mk_iff_associated.mp h) #align associates.mk_injective Associates.mk_injective section CommMonoid variable [CommMonoid α] instance instMul : Mul (Associates α) := ⟨Quotient.map₂ (· * ·) fun _ _ h₁ _ _ h₂ ↦ h₁.mul_mul h₂⟩ theorem mk_mul_mk {x y : α} : Associates.mk x * Associates.mk y = Associates.mk (x * y) := rfl #align associates.mk_mul_mk Associates.mk_mul_mk instance instCommMonoid : CommMonoid (Associates α) where one := 1 mul := (· * ·) mul_one a' := Quotient.inductionOn a' fun a => show ⟦a * 1⟧ = ⟦a⟧ by simp one_mul a' := Quotient.inductionOn a' fun a => show ⟦1 * a⟧ = ⟦a⟧ by simp mul_assoc a' b' c' := Quotient.inductionOn₃ a' b' c' fun a b c => show ⟦a * b * c⟧ = ⟦a * (b * c)⟧ by rw [mul_assoc] mul_comm a' b' := Quotient.inductionOn₂ a' b' fun a b => show ⟦a * b⟧ = ⟦b * a⟧ by rw [mul_comm] instance instPreorder : Preorder (Associates α) where le := Dvd.dvd le_refl := dvd_refl le_trans a b c := dvd_trans /-- `Associates.mk` as a `MonoidHom`. -/ protected def mkMonoidHom : α →* Associates α where toFun := Associates.mk map_one' := mk_one map_mul' _ _ := mk_mul_mk #align associates.mk_monoid_hom Associates.mkMonoidHom @[simp] theorem mkMonoidHom_apply (a : α) : Associates.mkMonoidHom a = Associates.mk a := rfl #align associates.mk_monoid_hom_apply Associates.mkMonoidHom_apply theorem associated_map_mk {f : Associates α →* α} (hinv : Function.RightInverse f Associates.mk) (a : α) : a ~ᵤ f (Associates.mk a) := Associates.mk_eq_mk_iff_associated.1 (hinv (Associates.mk a)).symm #align associates.associated_map_mk Associates.associated_map_mk theorem mk_pow (a : α) (n : ℕ) : Associates.mk (a ^ n) = Associates.mk a ^ n := by induction n <;> simp [*, pow_succ, Associates.mk_mul_mk.symm] #align associates.mk_pow Associates.mk_pow theorem dvd_eq_le : ((· ∣ ·) : Associates α → Associates α → Prop) = (· ≤ ·) := rfl #align associates.dvd_eq_le Associates.dvd_eq_le theorem mul_eq_one_iff {x y : Associates α} : x * y = 1 ↔ x = 1 ∧ y = 1 := Iff.intro (Quotient.inductionOn₂ x y fun a b h => have : a * b ~ᵤ 1 := Quotient.exact h ⟨Quotient.sound <| associated_one_of_associated_mul_one this, Quotient.sound <| associated_one_of_associated_mul_one <| by rwa [mul_comm] at this⟩) (by simp (config := { contextual := true })) #align associates.mul_eq_one_iff Associates.mul_eq_one_iff theorem units_eq_one (u : (Associates α)ˣ) : u = 1 := Units.ext (mul_eq_one_iff.1 u.val_inv).1 #align associates.units_eq_one Associates.units_eq_one instance uniqueUnits : Unique (Associates α)ˣ where default := 1 uniq := Associates.units_eq_one #align associates.unique_units Associates.uniqueUnits @[simp] theorem coe_unit_eq_one (u : (Associates α)ˣ) : (u : Associates α) = 1 := by simp [eq_iff_true_of_subsingleton] #align associates.coe_unit_eq_one Associates.coe_unit_eq_one theorem isUnit_iff_eq_one (a : Associates α) : IsUnit a ↔ a = 1 := Iff.intro (fun ⟨_, h⟩ => h ▸ coe_unit_eq_one _) fun h => h.symm ▸ isUnit_one #align associates.is_unit_iff_eq_one Associates.isUnit_iff_eq_one theorem isUnit_iff_eq_bot {a : Associates α} : IsUnit a ↔ a = ⊥ := by rw [Associates.isUnit_iff_eq_one, bot_eq_one] #align associates.is_unit_iff_eq_bot Associates.isUnit_iff_eq_bot theorem isUnit_mk {a : α} : IsUnit (Associates.mk a) ↔ IsUnit a := calc IsUnit (Associates.mk a) ↔ a ~ᵤ 1 := by rw [isUnit_iff_eq_one, one_eq_mk_one, mk_eq_mk_iff_associated] _ ↔ IsUnit a := associated_one_iff_isUnit #align associates.is_unit_mk Associates.isUnit_mk section Order theorem mul_mono {a b c d : Associates α} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := let ⟨x, hx⟩ := h₁ let ⟨y, hy⟩ := h₂ ⟨x * y, by simp [hx, hy, mul_comm, mul_assoc, mul_left_comm]⟩ #align associates.mul_mono Associates.mul_mono theorem one_le {a : Associates α} : 1 ≤ a := Dvd.intro _ (one_mul a) #align associates.one_le Associates.one_le theorem le_mul_right {a b : Associates α} : a ≤ a * b := ⟨b, rfl⟩ #align associates.le_mul_right Associates.le_mul_right theorem le_mul_left {a b : Associates α} : a ≤ b * a := by rw [mul_comm]; exact le_mul_right #align associates.le_mul_left Associates.le_mul_left instance instOrderBot : OrderBot (Associates α) where bot := 1 bot_le _ := one_le end Order @[simp] theorem mk_dvd_mk {a b : α} : Associates.mk a ∣ Associates.mk b ↔ a ∣ b := by simp only [dvd_def, mk_surjective.exists, mk_mul_mk, mk_eq_mk_iff_associated, Associated.comm (x := b)] constructor · rintro ⟨x, u, rfl⟩ exact ⟨_, mul_assoc ..⟩ · rintro ⟨c, rfl⟩ use c #align associates.mk_dvd_mk Associates.mk_dvd_mk theorem dvd_of_mk_le_mk {a b : α} : Associates.mk a ≤ Associates.mk b → a ∣ b := mk_dvd_mk.mp #align associates.dvd_of_mk_le_mk Associates.dvd_of_mk_le_mk theorem mk_le_mk_of_dvd {a b : α} : a ∣ b → Associates.mk a ≤ Associates.mk b := mk_dvd_mk.mpr #align associates.mk_le_mk_of_dvd Associates.mk_le_mk_of_dvd theorem mk_le_mk_iff_dvd {a b : α} : Associates.mk a ≤ Associates.mk b ↔ a ∣ b := mk_dvd_mk #align associates.mk_le_mk_iff_dvd_iff Associates.mk_le_mk_iff_dvd @[deprecated (since := "2024-03-16")] alias mk_le_mk_iff_dvd_iff := mk_le_mk_iff_dvd @[simp] theorem isPrimal_mk {a : α} : IsPrimal (Associates.mk a) ↔ IsPrimal a := by simp_rw [IsPrimal, forall_associated, mk_surjective.exists, mk_mul_mk, mk_dvd_mk] constructor <;> intro h b c dvd <;> obtain ⟨a₁, a₂, h₁, h₂, eq⟩ := @h b c dvd · obtain ⟨u, rfl⟩ := mk_eq_mk_iff_associated.mp eq.symm exact ⟨a₁, a₂ * u, h₁, Units.mul_right_dvd.mpr h₂, mul_assoc _ _ _⟩ · exact ⟨a₁, a₂, h₁, h₂, congr_arg _ eq⟩ @[deprecated (since := "2024-03-16")] alias isPrimal_iff := isPrimal_mk @[simp]
Mathlib/Algebra/Associated.lean
1,056
1,057
theorem decompositionMonoid_iff : DecompositionMonoid (Associates α) ↔ DecompositionMonoid α := by
simp_rw [_root_.decompositionMonoid_iff, forall_associated, isPrimal_mk]
/- Copyright (c) 2022 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johanes Hölzl, Patrick Massot, Yury Kudryashov, Kevin Wilson, Heather Macbeth -/ import Mathlib.Order.Filter.Basic #align_import order.filter.prod from "leanprover-community/mathlib"@"d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce" /-! # Product and coproduct filters In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and `Filter.Tendsto Prod.snd l g`. ## Implementation details The product filter cannot be defined using the monad structure on filters. For example: ```lean F := do {x ← seq, y ← top, return (x, y)} G := do {y ← top, x ← seq, return (x, y)} ``` hence: ```lean s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s ``` Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`. As product filter we want to have `F` as result. ## Notations * `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`. -/ open Set open Filter namespace Filter variable {α β γ δ : Type*} {ι : Sort*} section Prod variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β} /-- Product of filters. This is the filter generated by cartesian products of elements of the component filters. -/ protected def prod (f : Filter α) (g : Filter β) : Filter (α × β) := f.comap Prod.fst ⊓ g.comap Prod.snd #align filter.prod Filter.prod instance instSProd : SProd (Filter α) (Filter β) (Filter (α × β)) where sprod := Filter.prod theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g := inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht) #align filter.prod_mem_prod Filter.prod_mem_prod theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by simp only [SProd.sprod, Filter.prod] constructor · rintro ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, rfl⟩ exact ⟨s₁, hs₁, s₂, hs₂, fun p ⟨h, h'⟩ => ⟨hts₁ h, hts₂ h'⟩⟩ · rintro ⟨t₁, ht₁, t₂, ht₂, h⟩ exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h #align filter.mem_prod_iff Filter.mem_prod_iff @[simp] theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g := ⟨fun h => let ⟨_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h (prod_subset_prod_iff.1 H).elim (fun ⟨hs's, ht't⟩ => ⟨mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h => h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e => absurd ht'e (nonempty_of_mem ht').ne_empty, fun h => prod_mem_prod h.1 h.2⟩ #align filter.prod_mem_prod_iff Filter.prod_mem_prod_iff theorem mem_prod_principal {s : Set (α × β)} : s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by rw [← @exists_mem_subset_iff _ f, mem_prod_iff] refine exists_congr fun u => Iff.rfl.and ⟨?_, fun h => ⟨t, mem_principal_self t, ?_⟩⟩ · rintro ⟨v, v_in, hv⟩ a a_in b b_in exact hv (mk_mem_prod a_in <| v_in b_in) · rintro ⟨x, y⟩ ⟨hx, hy⟩ exact h hx y hy #align filter.mem_prod_principal Filter.mem_prod_principal theorem mem_prod_top {s : Set (α × β)} : s ∈ f ×ˢ (⊤ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by rw [← principal_univ, mem_prod_principal] simp only [mem_univ, forall_true_left] #align filter.mem_prod_top Filter.mem_prod_top
Mathlib/Order/Filter/Prod.lean
101
104
theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} : (∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by
rw [eventually_iff, eventually_iff, mem_prod_principal] simp only [mem_setOf_eq]
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.RingQuot import Mathlib.LinearAlgebra.TensorAlgebra.Basic #align_import algebra.lie.universal_enveloping from "leanprover-community/mathlib"@"32b08ef840dd25ca2e47e035c5da03ce16d2dc3c" /-! # Universal enveloping algebra Given a commutative ring `R` and a Lie algebra `L` over `R`, we construct the universal enveloping algebra of `L`, together with its universal property. ## Main definitions * `UniversalEnvelopingAlgebra`: the universal enveloping algebra, endowed with an `R`-algebra structure. * `UniversalEnvelopingAlgebra.ι`: the Lie algebra morphism from `L` to its universal enveloping algebra. * `UniversalEnvelopingAlgebra.lift`: given an associative algebra `A`, together with a Lie algebra morphism `f : L →ₗ⁅R⁆ A`, `lift R L f : UniversalEnvelopingAlgebra R L →ₐ[R] A` is the unique morphism of algebras through which `f` factors. * `UniversalEnvelopingAlgebra.ι_comp_lift`: states that the lift of a morphism is indeed part of a factorisation. * `UniversalEnvelopingAlgebra.lift_unique`: states that lifts of morphisms are indeed unique. * `UniversalEnvelopingAlgebra.hom_ext`: a restatement of `lift_unique` as an extensionality lemma. ## Tags lie algebra, universal enveloping algebra, tensor algebra -/ universe u₁ u₂ u₃ variable (R : Type u₁) (L : Type u₂) variable [CommRing R] [LieRing L] [LieAlgebra R L] local notation "ιₜ" => TensorAlgebra.ι R namespace UniversalEnvelopingAlgebra /-- The quotient by the ideal generated by this relation is the universal enveloping algebra. Note that we have avoided using the more natural expression: | lie_compat (x y : L) : rel (ιₜ ⁅x, y⁆) ⁅ιₜ x, ιₜ y⁆ so that our construction needs only the semiring structure of the tensor algebra. -/ inductive Rel : TensorAlgebra R L → TensorAlgebra R L → Prop | lie_compat (x y : L) : Rel (ιₜ ⁅x, y⁆ + ιₜ y * ιₜ x) (ιₜ x * ιₜ y) #align universal_enveloping_algebra.rel UniversalEnvelopingAlgebra.Rel end UniversalEnvelopingAlgebra /-- The universal enveloping algebra of a Lie algebra. -/ def UniversalEnvelopingAlgebra := RingQuot (UniversalEnvelopingAlgebra.Rel R L) #align universal_enveloping_algebra UniversalEnvelopingAlgebra namespace UniversalEnvelopingAlgebra -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020): the next three -- instances were derived automatically in mathlib3. instance instInhabited : Inhabited (UniversalEnvelopingAlgebra R L) := inferInstanceAs (Inhabited (RingQuot (UniversalEnvelopingAlgebra.Rel R L))) #align universal_enveloping_algebra.inhabited UniversalEnvelopingAlgebra.instInhabited instance instRing : Ring (UniversalEnvelopingAlgebra R L) := inferInstanceAs (Ring (RingQuot (UniversalEnvelopingAlgebra.Rel R L))) #align universal_enveloping_algebra.ring UniversalEnvelopingAlgebra.instRing instance instAlgebra : Algebra R (UniversalEnvelopingAlgebra R L) := inferInstanceAs (Algebra R (RingQuot (UniversalEnvelopingAlgebra.Rel R L))) #align universal_enveloping_algebra.algebra UniversalEnvelopingAlgebra.instAlgebra /-- The quotient map from the tensor algebra to the universal enveloping algebra as a morphism of associative algebras. -/ def mkAlgHom : TensorAlgebra R L →ₐ[R] UniversalEnvelopingAlgebra R L := RingQuot.mkAlgHom R (Rel R L) #align universal_enveloping_algebra.mk_alg_hom UniversalEnvelopingAlgebra.mkAlgHom variable {L} /-- The natural Lie algebra morphism from a Lie algebra to its universal enveloping algebra. -/ @[simps!] -- Porting note (#11445): added def ι : L →ₗ⁅R⁆ UniversalEnvelopingAlgebra R L := { (mkAlgHom R L).toLinearMap.comp ιₜ with map_lie' := fun {x y} => by suffices mkAlgHom R L (ιₜ ⁅x, y⁆ + ιₜ y * ιₜ x) = mkAlgHom R L (ιₜ x * ιₜ y) by rw [AlgHom.map_mul] at this; simp [LieRing.of_associative_ring_bracket, ← this] exact RingQuot.mkAlgHom_rel _ (Rel.lie_compat x y) } #align universal_enveloping_algebra.ι UniversalEnvelopingAlgebra.ι variable {A : Type u₃} [Ring A] [Algebra R A] (f : L →ₗ⁅R⁆ A) /-- The universal property of the universal enveloping algebra: Lie algebra morphisms into associative algebras lift to associative algebra morphisms from the universal enveloping algebra. -/ def lift : (L →ₗ⁅R⁆ A) ≃ (UniversalEnvelopingAlgebra R L →ₐ[R] A) where toFun f := RingQuot.liftAlgHom R ⟨TensorAlgebra.lift R (f : L →ₗ[R] A), by intro a b h; induction' h with x y simp only [LieRing.of_associative_ring_bracket, map_add, TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap, LieHom.map_lie, map_mul, sub_add_cancel]⟩ invFun F := (F : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R) left_inv f := by ext -- Porting note: was -- simp only [ι, mkAlgHom, TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap, -- LinearMap.toFun_eq_coe, LinearMap.coe_comp, LieHom.coe_comp, AlgHom.coe_toLieHom, -- LieHom.coe_mk, Function.comp_apply, AlgHom.toLinearMap_apply, -- RingQuot.liftAlgHom_mkAlgHom_apply] simp only [LieHom.coe_comp, Function.comp_apply, AlgHom.coe_toLieHom, UniversalEnvelopingAlgebra.ι_apply, mkAlgHom] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [RingQuot.liftAlgHom_mkAlgHom_apply] simp only [TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap] right_inv F := by apply RingQuot.ringQuot_ext' ext -- Porting note: was -- simp only [ι, mkAlgHom, TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap, -- LinearMap.toFun_eq_coe, LinearMap.coe_comp, LieHom.coe_linearMap_comp, -- AlgHom.comp_toLinearMap, Function.comp_apply, AlgHom.toLinearMap_apply, -- RingQuot.liftAlgHom_mkAlgHom_apply, AlgHom.coe_toLieHom, LieHom.coe_mk] -- extra `rfl` after leanprover/lean4#2644 simp [mkAlgHom]; rfl #align universal_enveloping_algebra.lift UniversalEnvelopingAlgebra.lift @[simp] theorem lift_symm_apply (F : UniversalEnvelopingAlgebra R L →ₐ[R] A) : (lift R).symm F = (F : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R) := rfl #align universal_enveloping_algebra.lift_symm_apply UniversalEnvelopingAlgebra.lift_symm_apply @[simp] theorem ι_comp_lift : lift R f ∘ ι R = f := funext <| LieHom.ext_iff.mp <| (lift R).symm_apply_apply f #align universal_enveloping_algebra.ι_comp_lift UniversalEnvelopingAlgebra.ι_comp_lift -- Porting note: moved `@[simp]` to the next theorem (LHS simplifies) theorem lift_ι_apply (x : L) : lift R f (ι R x) = f x := by rw [← Function.comp_apply (f := lift R f) (g := ι R) (x := x), ι_comp_lift] #align universal_enveloping_algebra.lift_ι_apply UniversalEnvelopingAlgebra.lift_ι_apply @[simp] theorem lift_ι_apply' (x : L) : lift R f ((UniversalEnvelopingAlgebra.mkAlgHom R L) (ιₜ x)) = f x := by simpa using lift_ι_apply R f x theorem lift_unique (g : UniversalEnvelopingAlgebra R L →ₐ[R] A) : g ∘ ι R = f ↔ g = lift R f := by refine Iff.trans ?_ (lift R).symm_apply_eq constructor <;> · intro h; ext; simp [← h] #align universal_enveloping_algebra.lift_unique UniversalEnvelopingAlgebra.lift_unique /-- See note [partially-applied ext lemmas]. -/ @[ext]
Mathlib/Algebra/Lie/UniversalEnveloping.lean
164
170
theorem hom_ext {g₁ g₂ : UniversalEnvelopingAlgebra R L →ₐ[R] A} (h : (g₁ : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R) = (g₂ : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R)) : g₁ = g₂ := have h' : (lift R).symm g₁ = (lift R).symm g₂ := by
ext; simp [h] (lift R).symm.injective h'
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.MeanValue #align_import analysis.calculus.extend_deriv from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Extending differentiability to the boundary We investigate how differentiable functions inside a set extend to differentiable functions on the boundary. For this, it suffices that the function and its derivative admit limits there. A general version of this statement is given in `has_fderiv_at_boundary_of_tendsto_fderiv`. One-dimensional versions, in which one wants to obtain differentiability at the left endpoint or the right endpoint of an interval, are given in `has_deriv_at_interval_left_endpoint_of_tendsto_deriv` and `has_deriv_at_interval_right_endpoint_of_tendsto_deriv`. These versions are formulated in terms of the one-dimensional derivative `deriv ℝ f`. -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Filter Set Metric ContinuousLinearMap open scoped Topology attribute [local mono] Set.prod_mono /-- If a function `f` is differentiable in a convex open set and continuous on its closure, and its derivative converges to a limit `f'` at a point on the boundary, then `f` is differentiable there with derivative `f'`. -/ theorem has_fderiv_at_boundary_of_tendsto_fderiv {f : E → F} {s : Set E} {x : E} {f' : E →L[ℝ] F} (f_diff : DifferentiableOn ℝ f s) (s_conv : Convex ℝ s) (s_open : IsOpen s) (f_cont : ∀ y ∈ closure s, ContinuousWithinAt f s y) (h : Tendsto (fun y => fderiv ℝ f y) (𝓝[s] x) (𝓝 f')) : HasFDerivWithinAt f f' (closure s) x := by classical -- one can assume without loss of generality that `x` belongs to the closure of `s`, as the -- statement is empty otherwise by_cases hx : x ∉ closure s · rw [← closure_closure] at hx; exact hasFDerivWithinAt_of_nmem_closure hx push_neg at hx rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, Asymptotics.isLittleO_iff] /- One needs to show that `‖f y - f x - f' (y - x)‖ ≤ ε ‖y - x‖` for `y` close to `x` in `closure s`, where `ε` is an arbitrary positive constant. By continuity of the functions, it suffices to prove this for nearby points inside `s`. In a neighborhood of `x`, the derivative of `f` is arbitrarily close to `f'` by assumption. The mean value inequality completes the proof. -/ intro ε ε_pos obtain ⟨δ, δ_pos, hδ⟩ : ∃ δ > 0, ∀ y ∈ s, dist y x < δ → ‖fderiv ℝ f y - f'‖ < ε := by simpa [dist_zero_right] using tendsto_nhdsWithin_nhds.1 h ε ε_pos set B := ball x δ suffices ∀ y ∈ B ∩ closure s, ‖f y - f x - (f' y - f' x)‖ ≤ ε * ‖y - x‖ from mem_nhdsWithin_iff.2 ⟨δ, δ_pos, fun y hy => by simpa using this y hy⟩ suffices ∀ p : E × E, p ∈ closure ((B ∩ s) ×ˢ (B ∩ s)) → ‖f p.2 - f p.1 - (f' p.2 - f' p.1)‖ ≤ ε * ‖p.2 - p.1‖ by rw [closure_prod_eq] at this intro y y_in apply this ⟨x, y⟩ have : B ∩ closure s ⊆ closure (B ∩ s) := isOpen_ball.inter_closure exact ⟨this ⟨mem_ball_self δ_pos, hx⟩, this y_in⟩ have key : ∀ p : E × E, p ∈ (B ∩ s) ×ˢ (B ∩ s) → ‖f p.2 - f p.1 - (f' p.2 - f' p.1)‖ ≤ ε * ‖p.2 - p.1‖ := by rintro ⟨u, v⟩ ⟨u_in, v_in⟩ have conv : Convex ℝ (B ∩ s) := (convex_ball _ _).inter s_conv have diff : DifferentiableOn ℝ f (B ∩ s) := f_diff.mono inter_subset_right have bound : ∀ z ∈ B ∩ s, ‖fderivWithin ℝ f (B ∩ s) z - f'‖ ≤ ε := by intro z z_in have h := hδ z have : fderivWithin ℝ f (B ∩ s) z = fderiv ℝ f z := by have op : IsOpen (B ∩ s) := isOpen_ball.inter s_open rw [DifferentiableAt.fderivWithin _ (op.uniqueDiffOn z z_in)] exact (diff z z_in).differentiableAt (IsOpen.mem_nhds op z_in) rw [← this] at h exact le_of_lt (h z_in.2 z_in.1) simpa using conv.norm_image_sub_le_of_norm_fderivWithin_le' diff bound u_in v_in rintro ⟨u, v⟩ uv_in have f_cont' : ∀ y ∈ closure s, ContinuousWithinAt (f - ⇑f') s y := by intro y y_in exact Tendsto.sub (f_cont y y_in) f'.cont.continuousWithinAt refine ContinuousWithinAt.closure_le uv_in ?_ ?_ key all_goals -- common start for both continuity proofs have : (B ∩ s) ×ˢ (B ∩ s) ⊆ s ×ˢ s := by mono <;> exact inter_subset_right obtain ⟨u_in, v_in⟩ : u ∈ closure s ∧ v ∈ closure s := by simpa [closure_prod_eq] using closure_mono this uv_in apply ContinuousWithinAt.mono _ this simp only [ContinuousWithinAt] · rw [nhdsWithin_prod_eq] have : ∀ u v, f v - f u - (f' v - f' u) = f v - f' v - (f u - f' u) := by intros; abel simp only [this] exact Tendsto.comp continuous_norm.continuousAt ((Tendsto.comp (f_cont' v v_in) tendsto_snd).sub <| Tendsto.comp (f_cont' u u_in) tendsto_fst) · apply tendsto_nhdsWithin_of_tendsto_nhds rw [nhds_prod_eq] exact tendsto_const_nhds.mul (Tendsto.comp continuous_norm.continuousAt <| tendsto_snd.sub tendsto_fst) #align has_fderiv_at_boundary_of_tendsto_fderiv has_fderiv_at_boundary_of_tendsto_fderiv /-- If a function is differentiable on the right of a point `a : ℝ`, continuous at `a`, and its derivative also converges at `a`, then `f` is differentiable on the right at `a`. -/ theorem has_deriv_at_interval_left_endpoint_of_tendsto_deriv {s : Set ℝ} {e : E} {a : ℝ} {f : ℝ → E} (f_diff : DifferentiableOn ℝ f s) (f_lim : ContinuousWithinAt f s a) (hs : s ∈ 𝓝[>] a) (f_lim' : Tendsto (fun x => deriv f x) (𝓝[>] a) (𝓝 e)) : HasDerivWithinAt f e (Ici a) a := by /- This is a specialization of `has_fderiv_at_boundary_of_tendsto_fderiv`. To be in the setting of this theorem, we need to work on an open interval with closure contained in `s ∪ {a}`, that we call `t = (a, b)`. Then, we check all the assumptions of this theorem and we apply it. -/ obtain ⟨b, ab : a < b, sab : Ioc a b ⊆ s⟩ := mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.1 hs let t := Ioo a b have ts : t ⊆ s := Subset.trans Ioo_subset_Ioc_self sab have t_diff : DifferentiableOn ℝ f t := f_diff.mono ts have t_conv : Convex ℝ t := convex_Ioo a b have t_open : IsOpen t := isOpen_Ioo have t_closure : closure t = Icc a b := closure_Ioo ab.ne have t_cont : ∀ y ∈ closure t, ContinuousWithinAt f t y := by rw [t_closure] intro y hy by_cases h : y = a · rw [h]; exact f_lim.mono ts · have : y ∈ s := sab ⟨lt_of_le_of_ne hy.1 (Ne.symm h), hy.2⟩ exact (f_diff.continuousOn y this).mono ts have t_diff' : Tendsto (fun x => fderiv ℝ f x) (𝓝[t] a) (𝓝 (smulRight (1 : ℝ →L[ℝ] ℝ) e)) := by simp only [deriv_fderiv.symm] exact Tendsto.comp (isBoundedBilinearMap_smulRight : IsBoundedBilinearMap ℝ _).continuous_right.continuousAt (tendsto_nhdsWithin_mono_left Ioo_subset_Ioi_self f_lim') -- now we can apply `has_fderiv_at_boundary_of_differentiable` have : HasDerivWithinAt f e (Icc a b) a := by rw [hasDerivWithinAt_iff_hasFDerivWithinAt, ← t_closure] exact has_fderiv_at_boundary_of_tendsto_fderiv t_diff t_conv t_open t_cont t_diff' exact this.mono_of_mem (Icc_mem_nhdsWithin_Ici <| left_mem_Ico.2 ab) #align has_deriv_at_interval_left_endpoint_of_tendsto_deriv has_deriv_at_interval_left_endpoint_of_tendsto_deriv /-- If a function is differentiable on the left of a point `a : ℝ`, continuous at `a`, and its derivative also converges at `a`, then `f` is differentiable on the left at `a`. -/ theorem has_deriv_at_interval_right_endpoint_of_tendsto_deriv {s : Set ℝ} {e : E} {a : ℝ} {f : ℝ → E} (f_diff : DifferentiableOn ℝ f s) (f_lim : ContinuousWithinAt f s a) (hs : s ∈ 𝓝[<] a) (f_lim' : Tendsto (fun x => deriv f x) (𝓝[<] a) (𝓝 e)) : HasDerivWithinAt f e (Iic a) a := by /- This is a specialization of `has_fderiv_at_boundary_of_differentiable`. To be in the setting of this theorem, we need to work on an open interval with closure contained in `s ∪ {a}`, that we call `t = (b, a)`. Then, we check all the assumptions of this theorem and we apply it. -/ obtain ⟨b, ba, sab⟩ : ∃ b ∈ Iio a, Ico b a ⊆ s := mem_nhdsWithin_Iio_iff_exists_Ico_subset.1 hs let t := Ioo b a have ts : t ⊆ s := Subset.trans Ioo_subset_Ico_self sab have t_diff : DifferentiableOn ℝ f t := f_diff.mono ts have t_conv : Convex ℝ t := convex_Ioo b a have t_open : IsOpen t := isOpen_Ioo have t_closure : closure t = Icc b a := closure_Ioo (ne_of_lt ba) have t_cont : ∀ y ∈ closure t, ContinuousWithinAt f t y := by rw [t_closure] intro y hy by_cases h : y = a · rw [h]; exact f_lim.mono ts · have : y ∈ s := sab ⟨hy.1, lt_of_le_of_ne hy.2 h⟩ exact (f_diff.continuousOn y this).mono ts have t_diff' : Tendsto (fun x => fderiv ℝ f x) (𝓝[t] a) (𝓝 (smulRight (1 : ℝ →L[ℝ] ℝ) e)) := by simp only [deriv_fderiv.symm] exact Tendsto.comp (isBoundedBilinearMap_smulRight : IsBoundedBilinearMap ℝ _).continuous_right.continuousAt (tendsto_nhdsWithin_mono_left Ioo_subset_Iio_self f_lim') -- now we can apply `has_fderiv_at_boundary_of_differentiable` have : HasDerivWithinAt f e (Icc b a) a := by rw [hasDerivWithinAt_iff_hasFDerivWithinAt, ← t_closure] exact has_fderiv_at_boundary_of_tendsto_fderiv t_diff t_conv t_open t_cont t_diff' exact this.mono_of_mem (Icc_mem_nhdsWithin_Iic <| right_mem_Ioc.2 ba) #align has_deriv_at_interval_right_endpoint_of_tendsto_deriv has_deriv_at_interval_right_endpoint_of_tendsto_deriv /-- If a real function `f` has a derivative `g` everywhere but at a point, and `f` and `g` are continuous at this point, then `g` is also the derivative of `f` at this point. -/
Mathlib/Analysis/Calculus/FDeriv/Extend.lean
180
209
theorem hasDerivAt_of_hasDerivAt_of_ne {f g : ℝ → E} {x : ℝ} (f_diff : ∀ y ≠ x, HasDerivAt f (g y) y) (hf : ContinuousAt f x) (hg : ContinuousAt g x) : HasDerivAt f (g x) x := by
have A : HasDerivWithinAt f (g x) (Ici x) x := by have diff : DifferentiableOn ℝ f (Ioi x) := fun y hy => (f_diff y (ne_of_gt hy)).differentiableAt.differentiableWithinAt -- next line is the nontrivial bit of this proof, appealing to differentiability -- extension results. apply has_deriv_at_interval_left_endpoint_of_tendsto_deriv diff hf.continuousWithinAt self_mem_nhdsWithin have : Tendsto g (𝓝[>] x) (𝓝 (g x)) := tendsto_inf_left hg apply this.congr' _ apply mem_of_superset self_mem_nhdsWithin fun y hy => _ intros y hy exact (f_diff y (ne_of_gt hy)).deriv.symm have B : HasDerivWithinAt f (g x) (Iic x) x := by have diff : DifferentiableOn ℝ f (Iio x) := fun y hy => (f_diff y (ne_of_lt hy)).differentiableAt.differentiableWithinAt -- next line is the nontrivial bit of this proof, appealing to differentiability -- extension results. apply has_deriv_at_interval_right_endpoint_of_tendsto_deriv diff hf.continuousWithinAt self_mem_nhdsWithin have : Tendsto g (𝓝[<] x) (𝓝 (g x)) := tendsto_inf_left hg apply this.congr' _ apply mem_of_superset self_mem_nhdsWithin fun y hy => _ intros y hy exact (f_diff y (ne_of_lt hy)).deriv.symm simpa using B.union A
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Associated import Mathlib.Algebra.Ring.Regular import Mathlib.Tactic.Common #align_import algebra.gcd_monoid.basic from "leanprover-community/mathlib"@"550b58538991c8977703fdeb7c9d51a5aa27df11" /-! # Monoids with normalization functions, `gcd`, and `lcm` This file defines extra structures on `CancelCommMonoidWithZero`s, including `IsDomain`s. ## Main Definitions * `NormalizationMonoid` * `GCDMonoid` * `NormalizedGCDMonoid` * `gcdMonoid_of_gcd`, `gcdMonoid_of_exists_gcd`, `normalizedGCDMonoid_of_gcd`, `normalizedGCDMonoid_of_exists_gcd` * `gcdMonoid_of_lcm`, `gcdMonoid_of_exists_lcm`, `normalizedGCDMonoid_of_lcm`, `normalizedGCDMonoid_of_exists_lcm` For the `NormalizedGCDMonoid` instances on `ℕ` and `ℤ`, see `Mathlib.Algebra.GCDMonoid.Nat`. ## Implementation Notes * `NormalizationMonoid` is defined by assigning to each element a `normUnit` such that multiplying by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This definition as currently implemented does casework on `0`. * `GCDMonoid` contains the definitions of `gcd` and `lcm` with the usual properties. They are both determined up to a unit. * `NormalizedGCDMonoid` extends `NormalizationMonoid`, so the `gcd` and `lcm` are always normalized. This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains, and monoids without zero. * `gcdMonoid_of_gcd` and `normalizedGCDMonoid_of_gcd` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `gcd` and its properties. * `gcdMonoid_of_exists_gcd` and `normalizedGCDMonoid_of_exists_gcd` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `gcd`. * `gcdMonoid_of_lcm` and `normalizedGCDMonoid_of_lcm` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `lcm` and its properties. * `gcdMonoid_of_exists_lcm` and `normalizedGCDMonoid_of_exists_lcm` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `lcm`. ## TODO * Port GCD facts about nats, definition of coprime * Generalize normalization monoids to commutative (cancellative) monoids with or without zero ## Tags divisibility, gcd, lcm, normalize -/ variable {α : Type*} -- Porting note: mathlib3 had a `@[protect_proj]` here, but adding `protected` to all the fields -- adds unnecessary clutter to later code /-- Normalization monoid: multiplying with `normUnit` gives a normal form for associated elements. -/ class NormalizationMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- `normUnit` assigns to each element of the monoid a unit of the monoid. -/ normUnit : α → αˣ /-- The proposition that `normUnit` maps `0` to the identity. -/ normUnit_zero : normUnit 0 = 1 /-- The proposition that `normUnit` respects multiplication of non-zero elements. -/ normUnit_mul : ∀ {a b}, a ≠ 0 → b ≠ 0 → normUnit (a * b) = normUnit a * normUnit b /-- The proposition that `normUnit` maps units to their inverses. -/ normUnit_coe_units : ∀ u : αˣ, normUnit u = u⁻¹ #align normalization_monoid NormalizationMonoid export NormalizationMonoid (normUnit normUnit_zero normUnit_mul normUnit_coe_units) attribute [simp] normUnit_coe_units normUnit_zero normUnit_mul section NormalizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] @[simp] theorem normUnit_one : normUnit (1 : α) = 1 := normUnit_coe_units 1 #align norm_unit_one normUnit_one -- Porting note (#11083): quite slow. Improve performance? /-- Chooses an element of each associate class, by multiplying by `normUnit` -/ def normalize : α →*₀ α where toFun x := x * normUnit x map_zero' := by simp only [normUnit_zero] exact mul_one (0:α) map_one' := by dsimp only; rw [normUnit_one, one_mul]; rfl map_mul' x y := (by_cases fun hx : x = 0 => by dsimp only; rw [hx, zero_mul, zero_mul, zero_mul]) fun hx => (by_cases fun hy : y = 0 => by dsimp only; rw [hy, mul_zero, zero_mul, mul_zero]) fun hy => by simp only [normUnit_mul hx hy, Units.val_mul]; simp only [mul_assoc, mul_left_comm y] #align normalize normalize theorem associated_normalize (x : α) : Associated x (normalize x) := ⟨_, rfl⟩ #align associated_normalize associated_normalize theorem normalize_associated (x : α) : Associated (normalize x) x := (associated_normalize _).symm #align normalize_associated normalize_associated theorem associated_normalize_iff {x y : α} : Associated x (normalize y) ↔ Associated x y := ⟨fun h => h.trans (normalize_associated y), fun h => h.trans (associated_normalize y)⟩ #align associated_normalize_iff associated_normalize_iff theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Associated x y := ⟨fun h => (associated_normalize _).trans h, fun h => (normalize_associated _).trans h⟩ #align normalize_associated_iff normalize_associated_iff theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x := Associates.mk_eq_mk_iff_associated.2 (normalize_associated _) #align associates.mk_normalize Associates.mk_normalize @[simp] theorem normalize_apply (x : α) : normalize x = x * normUnit x := rfl #align normalize_apply normalize_apply -- Porting note (#10618): `simp` can prove this -- @[simp] theorem normalize_zero : normalize (0 : α) = 0 := normalize.map_zero #align normalize_zero normalize_zero -- Porting note (#10618): `simp` can prove this -- @[simp] theorem normalize_one : normalize (1 : α) = 1 := normalize.map_one #align normalize_one normalize_one theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp #align normalize_coe_units normalize_coe_units theorem normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 := ⟨fun hx => (associated_zero_iff_eq_zero x).1 <| hx ▸ associated_normalize _, by rintro rfl; exact normalize_zero⟩ #align normalize_eq_zero normalize_eq_zero theorem normalize_eq_one {x : α} : normalize x = 1 ↔ IsUnit x := ⟨fun hx => isUnit_iff_exists_inv.2 ⟨_, hx⟩, fun ⟨u, hu⟩ => hu ▸ normalize_coe_units u⟩ #align normalize_eq_one normalize_eq_one -- Porting note (#11083): quite slow. Improve performance? @[simp] theorem normUnit_mul_normUnit (a : α) : normUnit (a * normUnit a) = 1 := by nontriviality α using Subsingleton.elim a 0 obtain rfl | h := eq_or_ne a 0 · rw [normUnit_zero, zero_mul, normUnit_zero] · rw [normUnit_mul h (Units.ne_zero _), normUnit_coe_units, mul_inv_eq_one] #align norm_unit_mul_norm_unit normUnit_mul_normUnit theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp #align normalize_idem normalize_idem theorem normalize_eq_normalize {a b : α} (hab : a ∣ b) (hba : b ∣ a) : normalize a = normalize b := by nontriviality α rcases associated_of_dvd_dvd hab hba with ⟨u, rfl⟩ refine by_cases (by rintro rfl; simp only [zero_mul]) fun ha : a ≠ 0 => ?_ suffices a * ↑(normUnit a) = a * ↑u * ↑(normUnit a) * ↑u⁻¹ by simpa only [normalize_apply, mul_assoc, normUnit_mul ha u.ne_zero, normUnit_coe_units] calc a * ↑(normUnit a) = a * ↑(normUnit a) * ↑u * ↑u⁻¹ := (Units.mul_inv_cancel_right _ _).symm _ = a * ↑u * ↑(normUnit a) * ↑u⁻¹ := by rw [mul_right_comm a] #align normalize_eq_normalize normalize_eq_normalize theorem normalize_eq_normalize_iff {x y : α} : normalize x = normalize y ↔ x ∣ y ∧ y ∣ x := ⟨fun h => ⟨Units.dvd_mul_right.1 ⟨_, h.symm⟩, Units.dvd_mul_right.1 ⟨_, h⟩⟩, fun ⟨hxy, hyx⟩ => normalize_eq_normalize hxy hyx⟩ #align normalize_eq_normalize_iff normalize_eq_normalize_iff theorem dvd_antisymm_of_normalize_eq {a b : α} (ha : normalize a = a) (hb : normalize b = b) (hab : a ∣ b) (hba : b ∣ a) : a = b := ha ▸ hb ▸ normalize_eq_normalize hab hba #align dvd_antisymm_of_normalize_eq dvd_antisymm_of_normalize_eq theorem Associated.eq_of_normalized {a b : α} (h : Associated a b) (ha : normalize a = a) (hb : normalize b = b) : a = b := dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd' --can be proven by simp theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b := Units.dvd_mul_right #align dvd_normalize_iff dvd_normalize_iff --can be proven by simp theorem normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b := Units.mul_right_dvd #align normalize_dvd_iff normalize_dvd_iff end NormalizationMonoid namespace Associates variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] /-- Maps an element of `Associates` back to the normalized element of its associate class -/ protected def out : Associates α → α := (Quotient.lift (normalize : α → α)) fun a _ ⟨_, hu⟩ => hu ▸ normalize_eq_normalize ⟨_, rfl⟩ (Units.mul_right_dvd.2 <| dvd_refl a) #align associates.out Associates.out @[simp] theorem out_mk (a : α) : (Associates.mk a).out = normalize a := rfl #align associates.out_mk Associates.out_mk @[simp] theorem out_one : (1 : Associates α).out = 1 := normalize_one #align associates.out_one Associates.out_one theorem out_mul (a b : Associates α) : (a * b).out = a.out * b.out := Quotient.inductionOn₂ a b fun _ _ => by simp only [Associates.quotient_mk_eq_mk, out_mk, mk_mul_mk, normalize.map_mul] #align associates.out_mul Associates.out_mul theorem dvd_out_iff (a : α) (b : Associates α) : a ∣ b.out ↔ Associates.mk a ≤ b := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] #align associates.dvd_out_iff Associates.dvd_out_iff theorem out_dvd_iff (a : α) (b : Associates α) : b.out ∣ a ↔ b ≤ Associates.mk a := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] #align associates.out_dvd_iff Associates.out_dvd_iff @[simp] theorem out_top : (⊤ : Associates α).out = 0 := normalize_zero #align associates.out_top Associates.out_top -- Porting note: lower priority to avoid linter complaints about simp-normal form @[simp 1100] theorem normalize_out (a : Associates α) : normalize a.out = a.out := Quotient.inductionOn a normalize_idem #align associates.normalize_out Associates.normalize_out @[simp] theorem mk_out (a : Associates α) : Associates.mk a.out = a := Quotient.inductionOn a mk_normalize #align associates.mk_out Associates.mk_out theorem out_injective : Function.Injective (Associates.out : _ → α) := Function.LeftInverse.injective mk_out #align associates.out_injective Associates.out_injective end Associates -- Porting note: mathlib3 had a `@[protect_proj]` here, but adding `protected` to all the fields -- adds unnecessary clutter to later code /-- GCD monoid: a `CancelCommMonoidWithZero` with `gcd` (greatest common divisor) and `lcm` (least common multiple) operations, determined up to a unit. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class GCDMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- The greatest common divisor between two elements. -/ gcd : α → α → α /-- The least common multiple between two elements. -/ lcm : α → α → α /-- The GCD is a divisor of the first element. -/ gcd_dvd_left : ∀ a b, gcd a b ∣ a /-- The GCD is a divisor of the second element. -/ gcd_dvd_right : ∀ a b, gcd a b ∣ b /-- Any common divisor of both elements is a divisor of the GCD. -/ dvd_gcd : ∀ {a b c}, a ∣ c → a ∣ b → a ∣ gcd c b /-- The product of two elements is `Associated` with the product of their GCD and LCM. -/ gcd_mul_lcm : ∀ a b, Associated (gcd a b * lcm a b) (a * b) /-- `0` is left-absorbing. -/ lcm_zero_left : ∀ a, lcm 0 a = 0 /-- `0` is right-absorbing. -/ lcm_zero_right : ∀ a, lcm a 0 = 0 #align gcd_monoid GCDMonoid /-- Normalized GCD monoid: a `CancelCommMonoidWithZero` with normalization and `gcd` (greatest common divisor) and `lcm` (least common multiple) operations. In this setting `gcd` and `lcm` form a bounded lattice on the associated elements where `gcd` is the infimum, `lcm` is the supremum, `1` is bottom, and `0` is top. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class NormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] extends NormalizationMonoid α, GCDMonoid α where /-- The GCD is normalized to itself. -/ normalize_gcd : ∀ a b, normalize (gcd a b) = gcd a b /-- The LCM is normalized to itself. -/ normalize_lcm : ∀ a b, normalize (lcm a b) = lcm a b #align normalized_gcd_monoid NormalizedGCDMonoid export GCDMonoid (gcd lcm gcd_dvd_left gcd_dvd_right dvd_gcd lcm_zero_left lcm_zero_right) attribute [simp] lcm_zero_left lcm_zero_right section GCDMonoid variable [CancelCommMonoidWithZero α] instance [NormalizationMonoid α] : Nonempty (NormalizationMonoid α) := ⟨‹_›⟩ instance [GCDMonoid α] : Nonempty (GCDMonoid α) := ⟨‹_›⟩ instance [NormalizedGCDMonoid α] : Nonempty (NormalizedGCDMonoid α) := ⟨‹_›⟩ instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (NormalizationMonoid α) := h.elim fun _ ↦ inferInstance instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (GCDMonoid α) := h.elim fun _ ↦ inferInstance theorem gcd_isUnit_iff_isRelPrime [GCDMonoid α] {a b : α} : IsUnit (gcd a b) ↔ IsRelPrime a b := ⟨fun h _ ha hb ↦ isUnit_of_dvd_unit (dvd_gcd ha hb) h, (· (gcd_dvd_left a b) (gcd_dvd_right a b))⟩ -- Porting note: lower priority to avoid linter complaints about simp-normal form @[simp 1100] theorem normalize_gcd [NormalizedGCDMonoid α] : ∀ a b : α, normalize (gcd a b) = gcd a b := NormalizedGCDMonoid.normalize_gcd #align normalize_gcd normalize_gcd theorem gcd_mul_lcm [GCDMonoid α] : ∀ a b : α, Associated (gcd a b * lcm a b) (a * b) := GCDMonoid.gcd_mul_lcm #align gcd_mul_lcm gcd_mul_lcm section GCD theorem dvd_gcd_iff [GCDMonoid α] (a b c : α) : a ∣ gcd b c ↔ a ∣ b ∧ a ∣ c := Iff.intro (fun h => ⟨h.trans (gcd_dvd_left _ _), h.trans (gcd_dvd_right _ _)⟩) fun ⟨hab, hac⟩ => dvd_gcd hab hac #align dvd_gcd_iff dvd_gcd_iff theorem gcd_comm [NormalizedGCDMonoid α] (a b : α) : gcd a b = gcd b a := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) #align gcd_comm gcd_comm theorem gcd_comm' [GCDMonoid α] (a b : α) : Associated (gcd a b) (gcd b a) := associated_of_dvd_dvd (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) #align gcd_comm' gcd_comm' theorem gcd_assoc [NormalizedGCDMonoid α] (m n k : α) : gcd (gcd m n) k = gcd m (gcd n k) := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) #align gcd_assoc gcd_assoc theorem gcd_assoc' [GCDMonoid α] (m n k : α) : Associated (gcd (gcd m n) k) (gcd m (gcd n k)) := associated_of_dvd_dvd (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) #align gcd_assoc' gcd_assoc' instance [NormalizedGCDMonoid α] : Std.Commutative (α := α) gcd where comm := gcd_comm instance [NormalizedGCDMonoid α] : Std.Associative (α := α) gcd where assoc := gcd_assoc theorem gcd_eq_normalize [NormalizedGCDMonoid α] {a b c : α} (habc : gcd a b ∣ c) (hcab : c ∣ gcd a b) : gcd a b = normalize c := normalize_gcd a b ▸ normalize_eq_normalize habc hcab #align gcd_eq_normalize gcd_eq_normalize @[simp] theorem gcd_zero_left [NormalizedGCDMonoid α] (a : α) : gcd 0 a = normalize a := gcd_eq_normalize (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) #align gcd_zero_left gcd_zero_left theorem gcd_zero_left' [GCDMonoid α] (a : α) : Associated (gcd 0 a) a := associated_of_dvd_dvd (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) #align gcd_zero_left' gcd_zero_left' @[simp] theorem gcd_zero_right [NormalizedGCDMonoid α] (a : α) : gcd a 0 = normalize a := gcd_eq_normalize (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) #align gcd_zero_right gcd_zero_right theorem gcd_zero_right' [GCDMonoid α] (a : α) : Associated (gcd a 0) a := associated_of_dvd_dvd (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) #align gcd_zero_right' gcd_zero_right' @[simp] theorem gcd_eq_zero_iff [GCDMonoid α] (a b : α) : gcd a b = 0 ↔ a = 0 ∧ b = 0 := Iff.intro (fun h => by let ⟨ca, ha⟩ := gcd_dvd_left a b let ⟨cb, hb⟩ := gcd_dvd_right a b rw [h, zero_mul] at ha hb exact ⟨ha, hb⟩) fun ⟨ha, hb⟩ => by rw [ha, hb, ← zero_dvd_iff] apply dvd_gcd <;> rfl #align gcd_eq_zero_iff gcd_eq_zero_iff @[simp] theorem gcd_one_left [NormalizedGCDMonoid α] (a : α) : gcd 1 a = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_left _ _) (one_dvd _) #align gcd_one_left gcd_one_left @[simp] theorem isUnit_gcd_one_left [GCDMonoid α] (a : α) : IsUnit (gcd 1 a) := isUnit_of_dvd_one (gcd_dvd_left _ _) theorem gcd_one_left' [GCDMonoid α] (a : α) : Associated (gcd 1 a) 1 := by simp #align gcd_one_left' gcd_one_left' @[simp] theorem gcd_one_right [NormalizedGCDMonoid α] (a : α) : gcd a 1 = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_right _ _) (one_dvd _) #align gcd_one_right gcd_one_right @[simp] theorem isUnit_gcd_one_right [GCDMonoid α] (a : α) : IsUnit (gcd a 1) := isUnit_of_dvd_one (gcd_dvd_right _ _) theorem gcd_one_right' [GCDMonoid α] (a : α) : Associated (gcd a 1) 1 := by simp #align gcd_one_right' gcd_one_right' theorem gcd_dvd_gcd [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : gcd a c ∣ gcd b d := dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd) #align gcd_dvd_gcd gcd_dvd_gcd protected theorem Associated.gcd [GCDMonoid α] {a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) : Associated (gcd a₁ b₁) (gcd a₂ b₂) := associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.dvd' hb.dvd') @[simp] theorem gcd_same [NormalizedGCDMonoid α] (a : α) : gcd a a = normalize a := gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a)) #align gcd_same gcd_same @[simp] theorem gcd_mul_left [NormalizedGCDMonoid α] (a b c : α) : gcd (a * b) (a * c) = normalize a * gcd b c := (by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero])) fun ha : a ≠ 0 => suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) gcd_eq_normalize (eq.symm ▸ mul_dvd_mul_left a (show d ∣ gcd b c from dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _) ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _))) (dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _)) #align gcd_mul_left gcd_mul_left theorem gcd_mul_left' [GCDMonoid α] (a b c : α) : Associated (gcd (a * b) (a * c)) (a * gcd b c) := by obtain rfl | ha := eq_or_ne a 0 · simp only [zero_mul, gcd_zero_left'] obtain ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) apply associated_of_dvd_dvd · rw [eq] apply mul_dvd_mul_left exact dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _) ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _) · exact dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _) #align gcd_mul_left' gcd_mul_left' @[simp] theorem gcd_mul_right [NormalizedGCDMonoid α] (a b c : α) : gcd (b * a) (c * a) = gcd b c * normalize a := by simp only [mul_comm, gcd_mul_left] #align gcd_mul_right gcd_mul_right @[simp] theorem gcd_mul_right' [GCDMonoid α] (a b c : α) : Associated (gcd (b * a) (c * a)) (gcd b c * a) := by simp only [mul_comm, gcd_mul_left'] #align gcd_mul_right' gcd_mul_right' theorem gcd_eq_left_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize a = a) : gcd a b = a ↔ a ∣ b := (Iff.intro fun eq => eq ▸ gcd_dvd_right _ _) fun hab => dvd_antisymm_of_normalize_eq (normalize_gcd _ _) h (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) hab) #align gcd_eq_left_iff gcd_eq_left_iff theorem gcd_eq_right_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize b = b) : gcd a b = b ↔ b ∣ a := by simpa only [gcd_comm a b] using gcd_eq_left_iff b a h #align gcd_eq_right_iff gcd_eq_right_iff theorem gcd_dvd_gcd_mul_left [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (k * m) n := gcd_dvd_gcd (dvd_mul_left _ _) dvd_rfl #align gcd_dvd_gcd_mul_left gcd_dvd_gcd_mul_left theorem gcd_dvd_gcd_mul_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (m * k) n := gcd_dvd_gcd (dvd_mul_right _ _) dvd_rfl #align gcd_dvd_gcd_mul_right gcd_dvd_gcd_mul_right theorem gcd_dvd_gcd_mul_left_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (k * n) := gcd_dvd_gcd dvd_rfl (dvd_mul_left _ _) #align gcd_dvd_gcd_mul_left_right gcd_dvd_gcd_mul_left_right theorem gcd_dvd_gcd_mul_right_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (n * k) := gcd_dvd_gcd dvd_rfl (dvd_mul_right _ _) #align gcd_dvd_gcd_mul_right_right gcd_dvd_gcd_mul_right_right theorem Associated.gcd_eq_left [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : gcd m k = gcd n k := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd h.dvd dvd_rfl) (gcd_dvd_gcd h.symm.dvd dvd_rfl) #align associated.gcd_eq_left Associated.gcd_eq_left theorem Associated.gcd_eq_right [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : gcd k m = gcd k n := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd dvd_rfl h.dvd) (gcd_dvd_gcd dvd_rfl h.symm.dvd) #align associated.gcd_eq_right Associated.gcd_eq_right theorem dvd_gcd_mul_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ gcd k m * n := (dvd_gcd (dvd_mul_right _ n) H).trans (gcd_mul_right' n k m).dvd #align dvd_gcd_mul_of_dvd_mul dvd_gcd_mul_of_dvd_mul theorem dvd_gcd_mul_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ gcd k m * n ↔ k ∣ m * n := ⟨fun h => h.trans (mul_dvd_mul (gcd_dvd_right k m) dvd_rfl), dvd_gcd_mul_of_dvd_mul⟩ theorem dvd_mul_gcd_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ m * gcd k n := by rw [mul_comm] at H ⊢ exact dvd_gcd_mul_of_dvd_mul H #align dvd_mul_gcd_of_dvd_mul dvd_mul_gcd_of_dvd_mul theorem dvd_mul_gcd_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ m * gcd k n ↔ k ∣ m * n := ⟨fun h => h.trans (mul_dvd_mul dvd_rfl (gcd_dvd_right k n)), dvd_mul_gcd_of_dvd_mul⟩ /-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. Note: In general, this representation is highly non-unique. See `Nat.prodDvdAndDvdOfDvdProd` for a constructive version on `ℕ`. -/ instance [h : Nonempty (GCDMonoid α)] : DecompositionMonoid α where primal k m n H := by cases h by_cases h0 : gcd k m = 0 · rw [gcd_eq_zero_iff] at h0 rcases h0 with ⟨rfl, rfl⟩ exact ⟨0, n, dvd_refl 0, dvd_refl n, by simp⟩ · obtain ⟨a, ha⟩ := gcd_dvd_left k m refine ⟨gcd k m, a, gcd_dvd_right _ _, ?_, ha⟩ rw [← mul_dvd_mul_iff_left h0, ← ha] exact dvd_gcd_mul_of_dvd_mul H theorem gcd_mul_dvd_mul_gcd [GCDMonoid α] (k m n : α) : gcd k (m * n) ∣ gcd k m * gcd k n := by obtain ⟨m', n', hm', hn', h⟩ := exists_dvd_and_dvd_of_dvd_mul (gcd_dvd_right k (m * n)) replace h : gcd k (m * n) = m' * n' := h rw [h] have hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _ apply mul_dvd_mul · have hm'k : m' ∣ k := (dvd_mul_right m' n').trans hm'n' exact dvd_gcd hm'k hm' · have hn'k : n' ∣ k := (dvd_mul_left n' m').trans hm'n' exact dvd_gcd hn'k hn' #align gcd_mul_dvd_mul_gcd gcd_mul_dvd_mul_gcd theorem gcd_pow_right_dvd_pow_gcd [GCDMonoid α] {a b : α} {k : ℕ} : gcd a (b ^ k) ∣ gcd a b ^ k := by by_cases hg : gcd a b = 0 · rw [gcd_eq_zero_iff] at hg rcases hg with ⟨rfl, rfl⟩ exact (gcd_zero_left' (0 ^ k : α)).dvd.trans (pow_dvd_pow_of_dvd (gcd_zero_left' (0 : α)).symm.dvd _) · induction' k with k hk · rw [pow_zero, pow_zero] exact (gcd_one_right' a).dvd rw [pow_succ', pow_succ'] trans gcd a b * gcd a (b ^ k) · exact gcd_mul_dvd_mul_gcd a b (b ^ k) · exact (mul_dvd_mul_iff_left hg).mpr hk #align gcd_pow_right_dvd_pow_gcd gcd_pow_right_dvd_pow_gcd theorem gcd_pow_left_dvd_pow_gcd [GCDMonoid α] {a b : α} {k : ℕ} : gcd (a ^ k) b ∣ gcd a b ^ k := calc gcd (a ^ k) b ∣ gcd b (a ^ k) := (gcd_comm' _ _).dvd _ ∣ gcd b a ^ k := gcd_pow_right_dvd_pow_gcd _ ∣ gcd a b ^ k := pow_dvd_pow_of_dvd (gcd_comm' _ _).dvd _ #align gcd_pow_left_dvd_pow_gcd gcd_pow_left_dvd_pow_gcd theorem pow_dvd_of_mul_eq_pow [GCDMonoid α] {a b c d₁ d₂ : α} (ha : a ≠ 0) (hab : IsUnit (gcd a b)) {k : ℕ} (h : a * b = c ^ k) (hc : c = d₁ * d₂) (hd₁ : d₁ ∣ a) : d₁ ^ k ≠ 0 ∧ d₁ ^ k ∣ a := by have h1 : IsUnit (gcd (d₁ ^ k) b) := by apply isUnit_of_dvd_one trans gcd d₁ b ^ k · exact gcd_pow_left_dvd_pow_gcd · apply IsUnit.dvd apply IsUnit.pow apply isUnit_of_dvd_one apply dvd_trans _ hab.dvd apply gcd_dvd_gcd hd₁ (dvd_refl b) have h2 : d₁ ^ k ∣ a * b := by use d₂ ^ k rw [h, hc] exact mul_pow d₁ d₂ k rw [mul_comm] at h2 have h3 : d₁ ^ k ∣ a := by apply (dvd_gcd_mul_of_dvd_mul h2).trans rw [h1.mul_left_dvd] have h4 : d₁ ^ k ≠ 0 := by intro hdk rw [hdk] at h3 apply absurd (zero_dvd_iff.mp h3) ha exact ⟨h4, h3⟩ #align pow_dvd_of_mul_eq_pow pow_dvd_of_mul_eq_pow theorem exists_associated_pow_of_mul_eq_pow [GCDMonoid α] {a b c : α} (hab : IsUnit (gcd a b)) {k : ℕ} (h : a * b = c ^ k) : ∃ d : α, Associated (d ^ k) a := by cases subsingleton_or_nontrivial α · use 0 rw [Subsingleton.elim a (0 ^ k)] by_cases ha : a = 0 · use 0 obtain rfl | hk := eq_or_ne k 0 · simp [ha] at h · rw [ha, zero_pow hk] by_cases hb : b = 0 · use 1 rw [one_pow] apply (associated_one_iff_isUnit.mpr hab).symm.trans rw [hb] exact gcd_zero_right' a obtain rfl | hk := k.eq_zero_or_pos · use 1 rw [pow_zero] at h ⊢ use Units.mkOfMulEqOne _ _ h rw [Units.val_mkOfMulEqOne, one_mul] have hc : c ∣ a * b := by rw [h] exact dvd_pow_self _ hk.ne' obtain ⟨d₁, d₂, hd₁, hd₂, hc⟩ := exists_dvd_and_dvd_of_dvd_mul hc use d₁ obtain ⟨h0₁, ⟨a', ha'⟩⟩ := pow_dvd_of_mul_eq_pow ha hab h hc hd₁ rw [mul_comm] at h hc rw [(gcd_comm' a b).isUnit_iff] at hab obtain ⟨h0₂, ⟨b', hb'⟩⟩ := pow_dvd_of_mul_eq_pow hb hab h hc hd₂ rw [ha', hb', hc, mul_pow] at h have h' : a' * b' = 1 := by apply (mul_right_inj' h0₁).mp rw [mul_one] apply (mul_right_inj' h0₂).mp rw [← h] rw [mul_assoc, mul_comm a', ← mul_assoc _ b', ← mul_assoc b', mul_comm b'] use Units.mkOfMulEqOne _ _ h' rw [Units.val_mkOfMulEqOne, ha'] #align exists_associated_pow_of_mul_eq_pow exists_associated_pow_of_mul_eq_pow theorem exists_eq_pow_of_mul_eq_pow [GCDMonoid α] [Unique αˣ] {a b c : α} (hab : IsUnit (gcd a b)) {k : ℕ} (h : a * b = c ^ k) : ∃ d : α, a = d ^ k := let ⟨d, hd⟩ := exists_associated_pow_of_mul_eq_pow hab h ⟨d, (associated_iff_eq.mp hd).symm⟩ #align exists_eq_pow_of_mul_eq_pow exists_eq_pow_of_mul_eq_pow theorem gcd_greatest {α : Type*} [CancelCommMonoidWithZero α] [NormalizedGCDMonoid α] {a b d : α} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : α, e ∣ a → e ∣ b → e ∣ d) : GCDMonoid.gcd a b = normalize d := haveI h := hd _ (GCDMonoid.gcd_dvd_left a b) (GCDMonoid.gcd_dvd_right a b) gcd_eq_normalize h (GCDMonoid.dvd_gcd hda hdb) #align gcd_greatest gcd_greatest theorem gcd_greatest_associated {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] {a b d : α} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : α, e ∣ a → e ∣ b → e ∣ d) : Associated d (GCDMonoid.gcd a b) := haveI h := hd _ (GCDMonoid.gcd_dvd_left a b) (GCDMonoid.gcd_dvd_right a b) associated_of_dvd_dvd (GCDMonoid.dvd_gcd hda hdb) h #align gcd_greatest_associated gcd_greatest_associated theorem isUnit_gcd_of_eq_mul_gcd {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] {x y x' y' : α} (ex : x = gcd x y * x') (ey : y = gcd x y * y') (h : gcd x y ≠ 0) : IsUnit (gcd x' y') := by rw [← associated_one_iff_isUnit] refine Associated.of_mul_left ?_ (Associated.refl <| gcd x y) h convert (gcd_mul_left' (gcd x y) x' y').symm using 1 rw [← ex, ← ey, mul_one] #align is_unit_gcd_of_eq_mul_gcd isUnit_gcd_of_eq_mul_gcd theorem extract_gcd {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] (x y : α) : ∃ x' y', x = gcd x y * x' ∧ y = gcd x y * y' ∧ IsUnit (gcd x' y') := by by_cases h : gcd x y = 0 · obtain ⟨rfl, rfl⟩ := (gcd_eq_zero_iff x y).1 h simp_rw [← associated_one_iff_isUnit] exact ⟨1, 1, by rw [h, zero_mul], by rw [h, zero_mul], gcd_one_left' 1⟩ obtain ⟨x', ex⟩ := gcd_dvd_left x y obtain ⟨y', ey⟩ := gcd_dvd_right x y exact ⟨x', y', ex, ey, isUnit_gcd_of_eq_mul_gcd ex ey h⟩ #align extract_gcd extract_gcd theorem associated_gcd_left_iff [GCDMonoid α] {x y : α} : Associated x (gcd x y) ↔ x ∣ y := ⟨fun hx => hx.dvd.trans (gcd_dvd_right x y), fun hxy => associated_of_dvd_dvd (dvd_gcd dvd_rfl hxy) (gcd_dvd_left x y)⟩ theorem associated_gcd_right_iff [GCDMonoid α] {x y : α} : Associated y (gcd x y) ↔ y ∣ x := ⟨fun hx => hx.dvd.trans (gcd_dvd_left x y), fun hxy => associated_of_dvd_dvd (dvd_gcd hxy dvd_rfl) (gcd_dvd_right x y)⟩ theorem Irreducible.isUnit_gcd_iff [GCDMonoid α] {x y : α} (hx : Irreducible x) : IsUnit (gcd x y) ↔ ¬(x ∣ y) := by rw [hx.isUnit_iff_not_associated_of_dvd (gcd_dvd_left x y), not_iff_not, associated_gcd_left_iff] theorem Irreducible.gcd_eq_one_iff [NormalizedGCDMonoid α] {x y : α} (hx : Irreducible x) : gcd x y = 1 ↔ ¬(x ∣ y) := by rw [← hx.isUnit_gcd_iff, ← normalize_eq_one, NormalizedGCDMonoid.normalize_gcd] section Neg variable [HasDistribNeg α] lemma gcd_neg' [GCDMonoid α] {a b : α} : Associated (gcd a (-b)) (gcd a b) := Associated.gcd .rfl (.neg_left .rfl) lemma gcd_neg [NormalizedGCDMonoid α] {a b : α} : gcd a (-b) = gcd a b := gcd_neg'.eq_of_normalized (normalize_gcd _ _) (normalize_gcd _ _) lemma neg_gcd' [GCDMonoid α] {a b : α} : Associated (gcd (-a) b) (gcd a b) := Associated.gcd (.neg_left .rfl) .rfl lemma neg_gcd [NormalizedGCDMonoid α] {a b : α} : gcd (-a) b = gcd a b := neg_gcd'.eq_of_normalized (normalize_gcd _ _) (normalize_gcd _ _) end Neg end GCD section LCM theorem lcm_dvd_iff [GCDMonoid α] {a b c : α} : lcm a b ∣ c ↔ a ∣ c ∧ b ∣ c := by by_cases h : a = 0 ∨ b = 0 · rcases h with (rfl | rfl) <;> simp (config := { contextual := true }) only [iff_def, lcm_zero_left, lcm_zero_right, zero_dvd_iff, dvd_zero, eq_self_iff_true, and_true_iff, imp_true_iff] · obtain ⟨h1, h2⟩ := not_or.1 h have h : gcd a b ≠ 0 := fun H => h1 ((gcd_eq_zero_iff _ _).1 H).1 rw [← mul_dvd_mul_iff_left h, (gcd_mul_lcm a b).dvd_iff_dvd_left, ← (gcd_mul_right' c a b).dvd_iff_dvd_right, dvd_gcd_iff, mul_comm b c, mul_dvd_mul_iff_left h1, mul_dvd_mul_iff_right h2, and_comm] #align lcm_dvd_iff lcm_dvd_iff theorem dvd_lcm_left [GCDMonoid α] (a b : α) : a ∣ lcm a b := (lcm_dvd_iff.1 (dvd_refl (lcm a b))).1 #align dvd_lcm_left dvd_lcm_left theorem dvd_lcm_right [GCDMonoid α] (a b : α) : b ∣ lcm a b := (lcm_dvd_iff.1 (dvd_refl (lcm a b))).2 #align dvd_lcm_right dvd_lcm_right theorem lcm_dvd [GCDMonoid α] {a b c : α} (hab : a ∣ b) (hcb : c ∣ b) : lcm a c ∣ b := lcm_dvd_iff.2 ⟨hab, hcb⟩ #align lcm_dvd lcm_dvd @[simp] theorem lcm_eq_zero_iff [GCDMonoid α] (a b : α) : lcm a b = 0 ↔ a = 0 ∨ b = 0 := Iff.intro (fun h : lcm a b = 0 => by have : Associated (a * b) 0 := (gcd_mul_lcm a b).symm.trans <| by rw [h, mul_zero] rwa [← mul_eq_zero, ← associated_zero_iff_eq_zero]) (by rintro (rfl | rfl) <;> [apply lcm_zero_left; apply lcm_zero_right]) #align lcm_eq_zero_iff lcm_eq_zero_iff -- Porting note: lower priority to avoid linter complaints about simp-normal form @[simp 1100] theorem normalize_lcm [NormalizedGCDMonoid α] (a b : α) : normalize (lcm a b) = lcm a b := NormalizedGCDMonoid.normalize_lcm a b #align normalize_lcm normalize_lcm theorem lcm_comm [NormalizedGCDMonoid α] (a b : α) : lcm a b = lcm b a := dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _) (lcm_dvd (dvd_lcm_right _ _) (dvd_lcm_left _ _)) (lcm_dvd (dvd_lcm_right _ _) (dvd_lcm_left _ _)) #align lcm_comm lcm_comm theorem lcm_comm' [GCDMonoid α] (a b : α) : Associated (lcm a b) (lcm b a) := associated_of_dvd_dvd (lcm_dvd (dvd_lcm_right _ _) (dvd_lcm_left _ _)) (lcm_dvd (dvd_lcm_right _ _) (dvd_lcm_left _ _)) #align lcm_comm' lcm_comm' theorem lcm_assoc [NormalizedGCDMonoid α] (m n k : α) : lcm (lcm m n) k = lcm m (lcm n k) := dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _) (lcm_dvd (lcm_dvd (dvd_lcm_left _ _) ((dvd_lcm_left _ _).trans (dvd_lcm_right _ _))) ((dvd_lcm_right _ _).trans (dvd_lcm_right _ _))) (lcm_dvd ((dvd_lcm_left _ _).trans (dvd_lcm_left _ _)) (lcm_dvd ((dvd_lcm_right _ _).trans (dvd_lcm_left _ _)) (dvd_lcm_right _ _))) #align lcm_assoc lcm_assoc theorem lcm_assoc' [GCDMonoid α] (m n k : α) : Associated (lcm (lcm m n) k) (lcm m (lcm n k)) := associated_of_dvd_dvd (lcm_dvd (lcm_dvd (dvd_lcm_left _ _) ((dvd_lcm_left _ _).trans (dvd_lcm_right _ _))) ((dvd_lcm_right _ _).trans (dvd_lcm_right _ _))) (lcm_dvd ((dvd_lcm_left _ _).trans (dvd_lcm_left _ _)) (lcm_dvd ((dvd_lcm_right _ _).trans (dvd_lcm_left _ _)) (dvd_lcm_right _ _))) #align lcm_assoc' lcm_assoc' instance [NormalizedGCDMonoid α] : Std.Commutative (α := α) lcm where comm := lcm_comm instance [NormalizedGCDMonoid α] : Std.Associative (α := α) lcm where assoc := lcm_assoc theorem lcm_eq_normalize [NormalizedGCDMonoid α] {a b c : α} (habc : lcm a b ∣ c) (hcab : c ∣ lcm a b) : lcm a b = normalize c := normalize_lcm a b ▸ normalize_eq_normalize habc hcab #align lcm_eq_normalize lcm_eq_normalize theorem lcm_dvd_lcm [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : lcm a c ∣ lcm b d := lcm_dvd (hab.trans (dvd_lcm_left _ _)) (hcd.trans (dvd_lcm_right _ _)) #align lcm_dvd_lcm lcm_dvd_lcm protected theorem Associated.lcm [GCDMonoid α] {a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) : Associated (lcm a₁ b₁) (lcm a₂ b₂) := associated_of_dvd_dvd (lcm_dvd_lcm ha.dvd hb.dvd) (lcm_dvd_lcm ha.dvd' hb.dvd') @[simp] theorem lcm_units_coe_left [NormalizedGCDMonoid α] (u : αˣ) (a : α) : lcm (↑u) a = normalize a := lcm_eq_normalize (lcm_dvd Units.coe_dvd dvd_rfl) (dvd_lcm_right _ _) #align lcm_units_coe_left lcm_units_coe_left @[simp] theorem lcm_units_coe_right [NormalizedGCDMonoid α] (a : α) (u : αˣ) : lcm a ↑u = normalize a := (lcm_comm a u).trans <| lcm_units_coe_left _ _ #align lcm_units_coe_right lcm_units_coe_right @[simp] theorem lcm_one_left [NormalizedGCDMonoid α] (a : α) : lcm 1 a = normalize a := lcm_units_coe_left 1 a #align lcm_one_left lcm_one_left @[simp] theorem lcm_one_right [NormalizedGCDMonoid α] (a : α) : lcm a 1 = normalize a := lcm_units_coe_right a 1 #align lcm_one_right lcm_one_right @[simp] theorem lcm_same [NormalizedGCDMonoid α] (a : α) : lcm a a = normalize a := lcm_eq_normalize (lcm_dvd dvd_rfl dvd_rfl) (dvd_lcm_left _ _) #align lcm_same lcm_same @[simp] theorem lcm_eq_one_iff [NormalizedGCDMonoid α] (a b : α) : lcm a b = 1 ↔ a ∣ 1 ∧ b ∣ 1 := Iff.intro (fun eq => eq ▸ ⟨dvd_lcm_left _ _, dvd_lcm_right _ _⟩) fun ⟨⟨c, hc⟩, ⟨d, hd⟩⟩ => show lcm (Units.mkOfMulEqOne a c hc.symm : α) (Units.mkOfMulEqOne b d hd.symm) = 1 by rw [lcm_units_coe_left, normalize_coe_units] #align lcm_eq_one_iff lcm_eq_one_iff @[simp] theorem lcm_mul_left [NormalizedGCDMonoid α] (a b c : α) : lcm (a * b) (a * c) = normalize a * lcm b c := (by_cases (by rintro rfl; simp only [zero_mul, lcm_zero_left, normalize_zero])) fun ha : a ≠ 0 => suffices lcm (a * b) (a * c) = normalize (a * lcm b c) by simpa have : a ∣ lcm (a * b) (a * c) := (dvd_mul_right _ _).trans (dvd_lcm_left _ _) let ⟨d, eq⟩ := this lcm_eq_normalize (lcm_dvd (mul_dvd_mul_left a (dvd_lcm_left _ _)) (mul_dvd_mul_left a (dvd_lcm_right _ _))) (eq.symm ▸ (mul_dvd_mul_left a <| lcm_dvd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ dvd_lcm_left _ _) ((mul_dvd_mul_iff_left ha).1 <| eq ▸ dvd_lcm_right _ _))) #align lcm_mul_left lcm_mul_left @[simp] theorem lcm_mul_right [NormalizedGCDMonoid α] (a b c : α) : lcm (b * a) (c * a) = lcm b c * normalize a := by simp only [mul_comm, lcm_mul_left] #align lcm_mul_right lcm_mul_right theorem lcm_eq_left_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize a = a) : lcm a b = a ↔ b ∣ a := (Iff.intro fun eq => eq ▸ dvd_lcm_right _ _) fun hab => dvd_antisymm_of_normalize_eq (normalize_lcm _ _) h (lcm_dvd (dvd_refl a) hab) (dvd_lcm_left _ _) #align lcm_eq_left_iff lcm_eq_left_iff theorem lcm_eq_right_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize b = b) : lcm a b = b ↔ a ∣ b := by simpa only [lcm_comm b a] using lcm_eq_left_iff b a h #align lcm_eq_right_iff lcm_eq_right_iff theorem lcm_dvd_lcm_mul_left [GCDMonoid α] (m n k : α) : lcm m n ∣ lcm (k * m) n := lcm_dvd_lcm (dvd_mul_left _ _) dvd_rfl #align lcm_dvd_lcm_mul_left lcm_dvd_lcm_mul_left theorem lcm_dvd_lcm_mul_right [GCDMonoid α] (m n k : α) : lcm m n ∣ lcm (m * k) n := lcm_dvd_lcm (dvd_mul_right _ _) dvd_rfl #align lcm_dvd_lcm_mul_right lcm_dvd_lcm_mul_right theorem lcm_dvd_lcm_mul_left_right [GCDMonoid α] (m n k : α) : lcm m n ∣ lcm m (k * n) := lcm_dvd_lcm dvd_rfl (dvd_mul_left _ _) #align lcm_dvd_lcm_mul_left_right lcm_dvd_lcm_mul_left_right theorem lcm_dvd_lcm_mul_right_right [GCDMonoid α] (m n k : α) : lcm m n ∣ lcm m (n * k) := lcm_dvd_lcm dvd_rfl (dvd_mul_right _ _) #align lcm_dvd_lcm_mul_right_right lcm_dvd_lcm_mul_right_right theorem lcm_eq_of_associated_left [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : lcm m k = lcm n k := dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _) (lcm_dvd_lcm h.dvd dvd_rfl) (lcm_dvd_lcm h.symm.dvd dvd_rfl) #align lcm_eq_of_associated_left lcm_eq_of_associated_left theorem lcm_eq_of_associated_right [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : lcm k m = lcm k n := dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _) (lcm_dvd_lcm dvd_rfl h.dvd) (lcm_dvd_lcm dvd_rfl h.symm.dvd) #align lcm_eq_of_associated_right lcm_eq_of_associated_right end LCM @[deprecated (since := "2024-02-12")] alias GCDMonoid.prime_of_irreducible := Irreducible.prime #align gcd_monoid.prime_of_irreducible Irreducible.prime @[deprecated (since := "2024-02-12")] alias GCDMonoid.irreducible_iff_prime := irreducible_iff_prime #align gcd_monoid.irreducible_iff_prime irreducible_iff_prime end GCDMonoid section UniqueUnit variable [CancelCommMonoidWithZero α] [Unique αˣ] -- see Note [lower instance priority] instance (priority := 100) normalizationMonoidOfUniqueUnits : NormalizationMonoid α where normUnit _ := 1 normUnit_zero := rfl normUnit_mul _ _ := (mul_one 1).symm normUnit_coe_units _ := Subsingleton.elim _ _ #align normalization_monoid_of_unique_units normalizationMonoidOfUniqueUnits instance uniqueNormalizationMonoidOfUniqueUnits : Unique (NormalizationMonoid α) where default := normalizationMonoidOfUniqueUnits uniq := fun ⟨u, _, _, _⟩ => by congr; simp [eq_iff_true_of_subsingleton] #align unique_normalization_monoid_of_unique_units uniqueNormalizationMonoidOfUniqueUnits instance subsingleton_gcdMonoid_of_unique_units : Subsingleton (GCDMonoid α) := ⟨fun g₁ g₂ => by have hgcd : g₁.gcd = g₂.gcd := by ext a b refine associated_iff_eq.mp (associated_of_dvd_dvd ?_ ?_) -- Porting note: Lean4 seems to need help specifying `g₁` and `g₂` · exact dvd_gcd (@gcd_dvd_left _ _ g₁ _ _) (@gcd_dvd_right _ _ g₁ _ _) · exact @dvd_gcd _ _ g₁ _ _ _ (@gcd_dvd_left _ _ g₂ _ _) (@gcd_dvd_right _ _ g₂ _ _) have hlcm : g₁.lcm = g₂.lcm := by ext a b -- Porting note: Lean4 seems to need help specifying `g₁` and `g₂` refine associated_iff_eq.mp (associated_of_dvd_dvd ?_ ?_) · exact (@lcm_dvd_iff _ _ g₁ ..).mpr ⟨@dvd_lcm_left _ _ g₂ _ _, @dvd_lcm_right _ _ g₂ _ _⟩ · exact lcm_dvd_iff.mpr ⟨@dvd_lcm_left _ _ g₁ _ _, @dvd_lcm_right _ _ g₁ _ _⟩ cases g₁ cases g₂ dsimp only at hgcd hlcm simp only [hgcd, hlcm]⟩ #align subsingleton_gcd_monoid_of_unique_units subsingleton_gcdMonoid_of_unique_units instance subsingleton_normalizedGCDMonoid_of_unique_units : Subsingleton (NormalizedGCDMonoid α) := ⟨by intro a b cases' a with a_norm a_gcd cases' b with b_norm b_gcd have := Subsingleton.elim a_gcd b_gcd subst this have := Subsingleton.elim a_norm b_norm subst this rfl⟩ #align subsingleton_normalized_gcd_monoid_of_unique_units subsingleton_normalizedGCDMonoid_of_unique_units @[simp] theorem normUnit_eq_one (x : α) : normUnit x = 1 := rfl #align norm_unit_eq_one normUnit_eq_one -- Porting note (#10618): `simp` can prove this -- @[simp] theorem normalize_eq (x : α) : normalize x = x := mul_one x #align normalize_eq normalize_eq /-- If a monoid's only unit is `1`, then it is isomorphic to its associates. -/ @[simps] def associatesEquivOfUniqueUnits : Associates α ≃* α where toFun := Associates.out invFun := Associates.mk left_inv := Associates.mk_out right_inv _ := (Associates.out_mk _).trans <| normalize_eq _ map_mul' := Associates.out_mul #align associates_equiv_of_unique_units associatesEquivOfUniqueUnits #align associates_equiv_of_unique_units_symm_apply associatesEquivOfUniqueUnits_symm_apply #align associates_equiv_of_unique_units_apply associatesEquivOfUniqueUnits_apply end UniqueUnit section IsDomain variable [CommRing α] [IsDomain α] [NormalizedGCDMonoid α] theorem gcd_eq_of_dvd_sub_right {a b c : α} (h : a ∣ b - c) : gcd a b = gcd a c := by apply dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) <;> rw [dvd_gcd_iff] <;> refine ⟨gcd_dvd_left _ _, ?_⟩ · rcases h with ⟨d, hd⟩ rcases gcd_dvd_right a b with ⟨e, he⟩ rcases gcd_dvd_left a b with ⟨f, hf⟩ use e - f * d rw [mul_sub, ← he, ← mul_assoc, ← hf, ← hd, sub_sub_cancel] · rcases h with ⟨d, hd⟩ rcases gcd_dvd_right a c with ⟨e, he⟩ rcases gcd_dvd_left a c with ⟨f, hf⟩ use e + f * d rw [mul_add, ← he, ← mul_assoc, ← hf, ← hd, ← add_sub_assoc, add_comm c b, add_sub_cancel_right] #align gcd_eq_of_dvd_sub_right gcd_eq_of_dvd_sub_right
Mathlib/Algebra/GCDMonoid/Basic.lean
1,024
1,025
theorem gcd_eq_of_dvd_sub_left {a b c : α} (h : a ∣ b - c) : gcd b a = gcd c a := by
rw [gcd_comm _ a, gcd_comm _ a, gcd_eq_of_dvd_sub_right h]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.GroupTheory.MonoidLocalization import Mathlib.RingTheory.Ideal.Basic import Mathlib.GroupTheory.GroupAction.Ring #align_import ring_theory.localization.basic from "leanprover-community/mathlib"@"b69c9a770ecf37eb21f7b8cf4fa00de3b62694ec" /-! # Localizations of commutative rings We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`. (The converse is a consequence of 1.) In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q] variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P) ``` ## Main definitions * `IsLocalization (M : Submonoid R) (S : Type*)` is a typeclass expressing that `S` is a localization of `R` at `M`, i.e. the canonical map `algebraMap R S : R →+* S` is a localization map (satisfying the above properties). * `IsLocalization.mk' S` is a surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹` * `IsLocalization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R` which maps elements of `M` to invertible elements of the codomain. * `IsLocalization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements of `M` to elements of `T` * `IsLocalization.ringEquivOfRingEquiv`: if `R` and `P` are isomorphic by an isomorphism sending `M` to `T`, then `S` and `Q` are isomorphic * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Main results * `Localization M S`, a construction of the localization as a quotient type, defined in `GroupTheory.MonoidLocalization`, has `CommRing`, `Algebra R` and `IsLocalization M` instances if `R` is a ring. `Localization.Away`, `Localization.AtPrime` and `FractionRing` are abbreviations for `Localization`s and have their corresponding `IsLocalization` instances ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`, we can ensure the localization map commutes nicely with other `algebraMap`s. To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the corresponding proof for the underlying `CommMonoid` localization map `IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization` and the namespace `Submonoid.LocalizationMap`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → Localization M` equals the surjection `LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[Field K]` instead of just `[CommRing K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ open Function section CommSemiring variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] /-- The typeclass `IsLocalization (M : Submonoid R) S` where `S` is an `R`-algebra expresses that `S` is isomorphic to the localization of `R` at `M`. -/ @[mk_iff] class IsLocalization : Prop where -- Porting note: add ' to fields, and made new versions of these with either `S` or `M` explicit. /-- Everything in the image of `algebraMap` is a unit -/ map_units' : ∀ y : M, IsUnit (algebraMap R S y) /-- The `algebraMap` is surjective -/ surj' : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1 /-- The kernel of `algebraMap` is contained in the annihilator of `M`; it is then equal to the annihilator by `map_units'` -/ exists_of_eq : ∀ {x y}, algebraMap R S x = algebraMap R S y → ∃ c : M, ↑c * x = ↑c * y #align is_localization IsLocalization variable {M} namespace IsLocalization section IsLocalization variable [IsLocalization M S] section @[inherit_doc IsLocalization.map_units'] theorem map_units : ∀ y : M, IsUnit (algebraMap R S y) := IsLocalization.map_units' variable (M) {S} @[inherit_doc IsLocalization.surj'] theorem surj : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1 := IsLocalization.surj' variable (S) @[inherit_doc IsLocalization.exists_of_eq] theorem eq_iff_exists {x y} : algebraMap R S x = algebraMap R S y ↔ ∃ c : M, ↑c * x = ↑c * y := Iff.intro IsLocalization.exists_of_eq fun ⟨c, h⟩ ↦ by apply_fun algebraMap R S at h rw [map_mul, map_mul] at h exact (IsLocalization.map_units S c).mul_right_inj.mp h variable {S} theorem of_le (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ r ∈ N, IsUnit (algebraMap R S r)) : IsLocalization N S where map_units' r := h₂ r r.2 surj' s := have ⟨⟨x, y, hy⟩, H⟩ := IsLocalization.surj M s ⟨⟨x, y, h₁ hy⟩, H⟩ exists_of_eq {x y} := by rw [IsLocalization.eq_iff_exists M] rintro ⟨c, hc⟩ exact ⟨⟨c, h₁ c.2⟩, hc⟩ #align is_localization.of_le IsLocalization.of_le variable (S) /-- `IsLocalization.toLocalizationWithZeroMap M S` shows `S` is the monoid localization of `R` at `M`. -/ @[simps] def toLocalizationWithZeroMap : Submonoid.LocalizationWithZeroMap M S where __ := algebraMap R S toFun := algebraMap R S map_units' := IsLocalization.map_units _ surj' := IsLocalization.surj _ exists_of_eq _ _ := IsLocalization.exists_of_eq #align is_localization.to_localization_with_zero_map IsLocalization.toLocalizationWithZeroMap /-- `IsLocalization.toLocalizationMap M S` shows `S` is the monoid localization of `R` at `M`. -/ abbrev toLocalizationMap : Submonoid.LocalizationMap M S := (toLocalizationWithZeroMap M S).toLocalizationMap #align is_localization.to_localization_map IsLocalization.toLocalizationMap @[simp] theorem toLocalizationMap_toMap : (toLocalizationMap M S).toMap = (algebraMap R S : R →*₀ S) := rfl #align is_localization.to_localization_map_to_map IsLocalization.toLocalizationMap_toMap theorem toLocalizationMap_toMap_apply (x) : (toLocalizationMap M S).toMap x = algebraMap R S x := rfl #align is_localization.to_localization_map_to_map_apply IsLocalization.toLocalizationMap_toMap_apply theorem surj₂ : ∀ z w : S, ∃ z' w' : R, ∃ d : M, (z * algebraMap R S d = algebraMap R S z') ∧ (w * algebraMap R S d = algebraMap R S w') := (toLocalizationMap M S).surj₂ end variable (M) {S} /-- Given a localization map `f : M →* N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/ noncomputable def sec (z : S) : R × M := Classical.choose <| IsLocalization.surj _ z #align is_localization.sec IsLocalization.sec @[simp] theorem toLocalizationMap_sec : (toLocalizationMap M S).sec = sec M := rfl #align is_localization.to_localization_map_sec IsLocalization.toLocalizationMap_sec /-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x` (so this lemma is true by definition). -/ theorem sec_spec (z : S) : z * algebraMap R S (IsLocalization.sec M z).2 = algebraMap R S (IsLocalization.sec M z).1 := Classical.choose_spec <| IsLocalization.surj _ z #align is_localization.sec_spec IsLocalization.sec_spec /-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/ theorem sec_spec' (z : S) : algebraMap R S (IsLocalization.sec M z).1 = algebraMap R S (IsLocalization.sec M z).2 * z := by rw [mul_comm, sec_spec] #align is_localization.sec_spec' IsLocalization.sec_spec' variable {M} /-- If `M` contains `0` then the localization at `M` is trivial. -/ theorem subsingleton (h : 0 ∈ M) : Subsingleton S := (toLocalizationMap M S).subsingleton h theorem map_right_cancel {x y} {c : M} (h : algebraMap R S (c * x) = algebraMap R S (c * y)) : algebraMap R S x = algebraMap R S y := (toLocalizationMap M S).map_right_cancel h #align is_localization.map_right_cancel IsLocalization.map_right_cancel theorem map_left_cancel {x y} {c : M} (h : algebraMap R S (x * c) = algebraMap R S (y * c)) : algebraMap R S x = algebraMap R S y := (toLocalizationMap M S).map_left_cancel h #align is_localization.map_left_cancel IsLocalization.map_left_cancel theorem eq_zero_of_fst_eq_zero {z x} {y : M} (h : z * algebraMap R S y = algebraMap R S x) (hx : x = 0) : z = 0 := by rw [hx, (algebraMap R S).map_zero] at h exact (IsUnit.mul_left_eq_zero (IsLocalization.map_units S y)).1 h #align is_localization.eq_zero_of_fst_eq_zero IsLocalization.eq_zero_of_fst_eq_zero variable (M S) theorem map_eq_zero_iff (r : R) : algebraMap R S r = 0 ↔ ∃ m : M, ↑m * r = 0 := by constructor · intro h obtain ⟨m, hm⟩ := (IsLocalization.eq_iff_exists M S).mp ((algebraMap R S).map_zero.trans h.symm) exact ⟨m, by simpa using hm.symm⟩ · rintro ⟨m, hm⟩ rw [← (IsLocalization.map_units S m).mul_right_inj, mul_zero, ← RingHom.map_mul, hm, RingHom.map_zero] #align is_localization.map_eq_zero_iff IsLocalization.map_eq_zero_iff variable {M} /-- `IsLocalization.mk' S` is the surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹`. -/ noncomputable def mk' (x : R) (y : M) : S := (toLocalizationMap M S).mk' x y #align is_localization.mk' IsLocalization.mk' @[simp] theorem mk'_sec (z : S) : mk' S (IsLocalization.sec M z).1 (IsLocalization.sec M z).2 = z := (toLocalizationMap M S).mk'_sec _ #align is_localization.mk'_sec IsLocalization.mk'_sec theorem mk'_mul (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * x₂) (y₁ * y₂) = mk' S x₁ y₁ * mk' S x₂ y₂ := (toLocalizationMap M S).mk'_mul _ _ _ _ #align is_localization.mk'_mul IsLocalization.mk'_mul theorem mk'_one (x) : mk' S x (1 : M) = algebraMap R S x := (toLocalizationMap M S).mk'_one _ #align is_localization.mk'_one IsLocalization.mk'_one @[simp] theorem mk'_spec (x) (y : M) : mk' S x y * algebraMap R S y = algebraMap R S x := (toLocalizationMap M S).mk'_spec _ _ #align is_localization.mk'_spec IsLocalization.mk'_spec @[simp] theorem mk'_spec' (x) (y : M) : algebraMap R S y * mk' S x y = algebraMap R S x := (toLocalizationMap M S).mk'_spec' _ _ #align is_localization.mk'_spec' IsLocalization.mk'_spec' @[simp] theorem mk'_spec_mk (x) (y : R) (hy : y ∈ M) : mk' S x ⟨y, hy⟩ * algebraMap R S y = algebraMap R S x := mk'_spec S x ⟨y, hy⟩ #align is_localization.mk'_spec_mk IsLocalization.mk'_spec_mk @[simp] theorem mk'_spec'_mk (x) (y : R) (hy : y ∈ M) : algebraMap R S y * mk' S x ⟨y, hy⟩ = algebraMap R S x := mk'_spec' S x ⟨y, hy⟩ #align is_localization.mk'_spec'_mk IsLocalization.mk'_spec'_mk variable {S} theorem eq_mk'_iff_mul_eq {x} {y : M} {z} : z = mk' S x y ↔ z * algebraMap R S y = algebraMap R S x := (toLocalizationMap M S).eq_mk'_iff_mul_eq #align is_localization.eq_mk'_iff_mul_eq IsLocalization.eq_mk'_iff_mul_eq theorem mk'_eq_iff_eq_mul {x} {y : M} {z} : mk' S x y = z ↔ algebraMap R S x = z * algebraMap R S y := (toLocalizationMap M S).mk'_eq_iff_eq_mul #align is_localization.mk'_eq_iff_eq_mul IsLocalization.mk'_eq_iff_eq_mul theorem mk'_add_eq_iff_add_mul_eq_mul {x} {y : M} {z₁ z₂} : mk' S x y + z₁ = z₂ ↔ algebraMap R S x + z₁ * algebraMap R S y = z₂ * algebraMap R S y := by rw [← mk'_spec S x y, ← IsUnit.mul_left_inj (IsLocalization.map_units S y), right_distrib] #align is_localization.mk'_add_eq_iff_add_mul_eq_mul IsLocalization.mk'_add_eq_iff_add_mul_eq_mul variable (M) theorem mk'_surjective (z : S) : ∃ (x : _) (y : M), mk' S x y = z := let ⟨r, hr⟩ := IsLocalization.surj _ z ⟨r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symm⟩ #align is_localization.mk'_surjective IsLocalization.mk'_surjective variable (S) /-- The localization of a `Fintype` is a `Fintype`. Cannot be an instance. -/ noncomputable def fintype' [Fintype R] : Fintype S := have := Classical.propDecidable Fintype.ofSurjective (Function.uncurry <| IsLocalization.mk' S) fun a => Prod.exists'.mpr <| IsLocalization.mk'_surjective M a #align is_localization.fintype' IsLocalization.fintype' variable {M S} /-- Localizing at a submonoid with 0 inside it leads to the trivial ring. -/ def uniqueOfZeroMem (h : (0 : R) ∈ M) : Unique S := uniqueOfZeroEqOne <| by simpa using IsLocalization.map_units S ⟨0, h⟩ #align is_localization.unique_of_zero_mem IsLocalization.uniqueOfZeroMem theorem mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (y₂ * x₁) = algebraMap R S (y₁ * x₂) := (toLocalizationMap M S).mk'_eq_iff_eq #align is_localization.mk'_eq_iff_eq IsLocalization.mk'_eq_iff_eq theorem mk'_eq_iff_eq' {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (x₁ * y₂) = algebraMap R S (x₂ * y₁) := (toLocalizationMap M S).mk'_eq_iff_eq' #align is_localization.mk'_eq_iff_eq' IsLocalization.mk'_eq_iff_eq' theorem mk'_mem_iff {x} {y : M} {I : Ideal S} : mk' S x y ∈ I ↔ algebraMap R S x ∈ I := by constructor <;> intro h · rw [← mk'_spec S x y, mul_comm] exact I.mul_mem_left ((algebraMap R S) y) h · rw [← mk'_spec S x y] at h obtain ⟨b, hb⟩ := isUnit_iff_exists_inv.1 (map_units S y) have := I.mul_mem_left b h rwa [mul_comm, mul_assoc, hb, mul_one] at this #align is_localization.mk'_mem_iff IsLocalization.mk'_mem_iff protected theorem eq {a₁ b₁} {a₂ b₂ : M} : mk' S a₁ a₂ = mk' S b₁ b₂ ↔ ∃ c : M, ↑c * (↑b₂ * a₁) = c * (a₂ * b₁) := (toLocalizationMap M S).eq #align is_localization.eq IsLocalization.eq theorem mk'_eq_zero_iff (x : R) (s : M) : mk' S x s = 0 ↔ ∃ m : M, ↑m * x = 0 := by rw [← (map_units S s).mul_left_inj, mk'_spec, zero_mul, map_eq_zero_iff M] #align is_localization.mk'_eq_zero_iff IsLocalization.mk'_eq_zero_iff @[simp] theorem mk'_zero (s : M) : IsLocalization.mk' S 0 s = 0 := by rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, zero_mul, map_zero] #align is_localization.mk'_zero IsLocalization.mk'_zero theorem ne_zero_of_mk'_ne_zero {x : R} {y : M} (hxy : IsLocalization.mk' S x y ≠ 0) : x ≠ 0 := by rintro rfl exact hxy (IsLocalization.mk'_zero _) #align is_localization.ne_zero_of_mk'_ne_zero IsLocalization.ne_zero_of_mk'_ne_zero section Ext variable [Algebra R P] [IsLocalization M P] theorem eq_iff_eq {x y} : algebraMap R S x = algebraMap R S y ↔ algebraMap R P x = algebraMap R P y := (toLocalizationMap M S).eq_iff_eq (toLocalizationMap M P) #align is_localization.eq_iff_eq IsLocalization.eq_iff_eq theorem mk'_eq_iff_mk'_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ mk' P x₁ y₁ = mk' P x₂ y₂ := (toLocalizationMap M S).mk'_eq_iff_mk'_eq (toLocalizationMap M P) #align is_localization.mk'_eq_iff_mk'_eq IsLocalization.mk'_eq_iff_mk'_eq theorem mk'_eq_of_eq {a₁ b₁ : R} {a₂ b₂ : M} (H : ↑a₂ * b₁ = ↑b₂ * a₁) : mk' S a₁ a₂ = mk' S b₁ b₂ := (toLocalizationMap M S).mk'_eq_of_eq H #align is_localization.mk'_eq_of_eq IsLocalization.mk'_eq_of_eq theorem mk'_eq_of_eq' {a₁ b₁ : R} {a₂ b₂ : M} (H : b₁ * ↑a₂ = a₁ * ↑b₂) : mk' S a₁ a₂ = mk' S b₁ b₂ := (toLocalizationMap M S).mk'_eq_of_eq' H #align is_localization.mk'_eq_of_eq' IsLocalization.mk'_eq_of_eq' theorem mk'_cancel (a : R) (b c : M) : mk' S (a * c) (b * c) = mk' S a b := (toLocalizationMap M S).mk'_cancel _ _ _ variable (S) @[simp] theorem mk'_self {x : R} (hx : x ∈ M) : mk' S x ⟨x, hx⟩ = 1 := (toLocalizationMap M S).mk'_self _ hx #align is_localization.mk'_self IsLocalization.mk'_self @[simp] theorem mk'_self' {x : M} : mk' S (x : R) x = 1 := (toLocalizationMap M S).mk'_self' _ #align is_localization.mk'_self' IsLocalization.mk'_self' theorem mk'_self'' {x : M} : mk' S x.1 x = 1 := mk'_self' _ #align is_localization.mk'_self'' IsLocalization.mk'_self'' end Ext theorem mul_mk'_eq_mk'_of_mul (x y : R) (z : M) : (algebraMap R S) x * mk' S y z = mk' S (x * y) z := (toLocalizationMap M S).mul_mk'_eq_mk'_of_mul _ _ _ #align is_localization.mul_mk'_eq_mk'_of_mul IsLocalization.mul_mk'_eq_mk'_of_mul theorem mk'_eq_mul_mk'_one (x : R) (y : M) : mk' S x y = (algebraMap R S) x * mk' S 1 y := ((toLocalizationMap M S).mul_mk'_one_eq_mk' _ _).symm #align is_localization.mk'_eq_mul_mk'_one IsLocalization.mk'_eq_mul_mk'_one @[simp] theorem mk'_mul_cancel_left (x : R) (y : M) : mk' S (y * x : R) y = (algebraMap R S) x := (toLocalizationMap M S).mk'_mul_cancel_left _ _ #align is_localization.mk'_mul_cancel_left IsLocalization.mk'_mul_cancel_left theorem mk'_mul_cancel_right (x : R) (y : M) : mk' S (x * y) y = (algebraMap R S) x := (toLocalizationMap M S).mk'_mul_cancel_right _ _ #align is_localization.mk'_mul_cancel_right IsLocalization.mk'_mul_cancel_right @[simp] theorem mk'_mul_mk'_eq_one (x y : M) : mk' S (x : R) y * mk' S (y : R) x = 1 := by rw [← mk'_mul, mul_comm]; exact mk'_self _ _ #align is_localization.mk'_mul_mk'_eq_one IsLocalization.mk'_mul_mk'_eq_one theorem mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x ∈ M) : mk' S x y * mk' S (y : R) ⟨x, h⟩ = 1 := mk'_mul_mk'_eq_one ⟨x, h⟩ _ #align is_localization.mk'_mul_mk'_eq_one' IsLocalization.mk'_mul_mk'_eq_one' theorem smul_mk' (x y : R) (m : M) : x • mk' S y m = mk' S (x * y) m := by nth_rw 2 [← one_mul m] rw [mk'_mul, mk'_one, Algebra.smul_def] @[simp] theorem smul_mk'_one (x : R) (m : M) : x • mk' S 1 m = mk' S x m := by rw [smul_mk', mul_one] @[simp] lemma smul_mk'_self {m : M} {r : R} : (m : R) • mk' S r m = algebraMap R S r := by rw [smul_mk', mk'_mul_cancel_left] @[simps] instance invertible_mk'_one (s : M) : Invertible (IsLocalization.mk' S (1 : R) s) where invOf := algebraMap R S s invOf_mul_self := by simp mul_invOf_self := by simp section variable (M) theorem isUnit_comp (j : S →+* P) (y : M) : IsUnit (j.comp (algebraMap R S) y) := (toLocalizationMap M S).isUnit_comp j.toMonoidHom _ #align is_localization.is_unit_comp IsLocalization.isUnit_comp end /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →+* P` such that `g(M) ⊆ Units P`, `f x = f y → g x = g y` for all `x y : R`. -/ theorem eq_of_eq {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) {x y} (h : (algebraMap R S) x = (algebraMap R S) y) : g x = g y := Submonoid.LocalizationMap.eq_of_eq (toLocalizationMap M S) (g := g.toMonoidHom) hg h #align is_localization.eq_of_eq IsLocalization.eq_of_eq theorem mk'_add (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * y₂ + x₂ * y₁) (y₁ * y₂) = mk' S x₁ y₁ + mk' S x₂ y₂ := mk'_eq_iff_eq_mul.2 <| Eq.symm (by rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul, mul_comm (_ * _), ← mul_assoc, add_comm, ← map_mul, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul] simp only [map_add, Submonoid.coe_mul, map_mul] ring) #align is_localization.mk'_add IsLocalization.mk'_add theorem mul_add_inv_left {g : R →+* P} (h : ∀ y : M, IsUnit (g y)) (y : M) (w z₁ z₂ : P) : w * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) h y)⁻¹ + z₁ = z₂ ↔ w + g y * z₁ = g y * z₂ := by rw [mul_comm, ← one_mul z₁, ← Units.inv_mul (IsUnit.liftRight (g.toMonoidHom.restrict M) h y), mul_assoc, ← mul_add, Units.inv_mul_eq_iff_eq_mul, Units.inv_mul_cancel_left, IsUnit.coe_liftRight] simp [RingHom.toMonoidHom_eq_coe, MonoidHom.restrict_apply] #align is_localization.mul_add_inv_left IsLocalization.mul_add_inv_left theorem lift_spec_mul_add {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) (z w w' v) : ((toLocalizationWithZeroMap M S).lift g.toMonoidWithZeroHom hg) z * w + w' = v ↔ g ((toLocalizationMap M S).sec z).1 * w + g ((toLocalizationMap M S).sec z).2 * w' = g ((toLocalizationMap M S).sec z).2 * v := by erw [mul_comm, ← mul_assoc, mul_add_inv_left hg, mul_comm] rfl #align is_localization.lift_spec_mul_add IsLocalization.lift_spec_mul_add /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` sending `z : S` to `g x * (g y)⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) : S →+* P := { Submonoid.LocalizationWithZeroMap.lift (toLocalizationWithZeroMap M S) g.toMonoidWithZeroHom hg with map_add' := by intro x y erw [(toLocalizationMap M S).lift_spec, mul_add, mul_comm, eq_comm, lift_spec_mul_add, add_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, lift_spec_mul_add] simp_rw [← mul_assoc] show g _ * g _ * g _ + g _ * g _ * g _ = g _ * g _ * g _ simp_rw [← map_mul g, ← map_add g] apply eq_of_eq (S := S) hg simp only [sec_spec', toLocalizationMap_sec, map_add, map_mul] ring } #align is_localization.lift IsLocalization.lift variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : R, y ∈ M`. -/ theorem lift_mk' (x y) : lift hg (mk' S x y) = g x * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) hg y)⁻¹ := (toLocalizationMap M S).lift_mk' _ _ _ #align is_localization.lift_mk' IsLocalization.lift_mk' theorem lift_mk'_spec (x v) (y : M) : lift hg (mk' S x y) = v ↔ g x = g y * v := (toLocalizationMap M S).lift_mk'_spec _ _ _ _ #align is_localization.lift_mk'_spec IsLocalization.lift_mk'_spec @[simp] theorem lift_eq (x : R) : lift hg ((algebraMap R S) x) = g x := (toLocalizationMap M S).lift_eq _ _ #align is_localization.lift_eq IsLocalization.lift_eq theorem lift_eq_iff {x y : R × M} : lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) := (toLocalizationMap M S).lift_eq_iff _ #align is_localization.lift_eq_iff IsLocalization.lift_eq_iff @[simp] theorem lift_comp : (lift hg).comp (algebraMap R S) = g := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_comp _ #align is_localization.lift_comp IsLocalization.lift_comp @[simp] theorem lift_of_comp (j : S →+* P) : lift (isUnit_comp M j) = j := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_of_comp j.toMonoidHom #align is_localization.lift_of_comp IsLocalization.lift_of_comp variable (M) /-- See note [partially-applied ext lemmas] -/ theorem monoidHom_ext ⦃j k : S →* P⦄ (h : j.comp (algebraMap R S : R →* S) = k.comp (algebraMap R S)) : j = k := Submonoid.LocalizationMap.epic_of_localizationMap (toLocalizationMap M S) <| DFunLike.congr_fun h #align is_localization.monoid_hom_ext IsLocalization.monoidHom_ext /-- See note [partially-applied ext lemmas] -/ theorem ringHom_ext ⦃j k : S →+* P⦄ (h : j.comp (algebraMap R S) = k.comp (algebraMap R S)) : j = k := RingHom.coe_monoidHom_injective <| monoidHom_ext M <| MonoidHom.ext <| RingHom.congr_fun h #align is_localization.ring_hom_ext IsLocalization.ringHom_ext /- This is not an instance because the submonoid `M` would become a metavariable in typeclass search. -/ theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) := ⟨fun f g => AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩ #align is_localization.alg_hom_subsingleton IsLocalization.algHom_subsingleton /-- To show `j` and `k` agree on the whole localization, it suffices to show they agree on the image of the base ring, if they preserve `1` and `*`. -/ protected theorem ext (j k : S → P) (hj1 : j 1 = 1) (hk1 : k 1 = 1) (hjm : ∀ a b, j (a * b) = j a * j b) (hkm : ∀ a b, k (a * b) = k a * k b) (h : ∀ a, j (algebraMap R S a) = k (algebraMap R S a)) : j = k := let j' : MonoidHom S P := { toFun := j, map_one' := hj1, map_mul' := hjm } let k' : MonoidHom S P := { toFun := k, map_one' := hk1, map_mul' := hkm } have : j' = k' := monoidHom_ext M (MonoidHom.ext h) show j'.toFun = k'.toFun by rw [this] #align is_localization.ext IsLocalization.ext variable {M} theorem lift_unique {j : S →+* P} (hj : ∀ x, j ((algebraMap R S) x) = g x) : lift hg = j := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| Submonoid.LocalizationMap.lift_unique (toLocalizationMap M S) (g := g.toMonoidHom) hg (j := j.toMonoidHom) hj #align is_localization.lift_unique IsLocalization.lift_unique @[simp] theorem lift_id (x) : lift (map_units S : ∀ _ : M, IsUnit _) x = x := (toLocalizationMap M S).lift_id _ #align is_localization.lift_id IsLocalization.lift_id theorem lift_surjective_iff : Surjective (lift hg : S → P) ↔ ∀ v : P, ∃ x : R × M, v * g x.2 = g x.1 := (toLocalizationMap M S).lift_surjective_iff hg #align is_localization.lift_surjective_iff IsLocalization.lift_surjective_iff theorem lift_injective_iff : Injective (lift hg : S → P) ↔ ∀ x y, algebraMap R S x = algebraMap R S y ↔ g x = g y := (toLocalizationMap M S).lift_injective_iff hg #align is_localization.lift_injective_iff IsLocalization.lift_injective_iff section Map variable {T : Submonoid P} {Q : Type*} [CommSemiring Q] (hy : M ≤ T.comap g) variable [Algebra P Q] [IsLocalization T Q] section variable (Q) /-- Map a homomorphism `g : R →+* P` to `S →+* Q`, where `S` and `Q` are localizations of `R` and `P` at `M` and `T` respectively, such that `g(M) ⊆ T`. We send `z : S` to `algebraMap P Q (g x) * (algebraMap P Q (g y))⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def map (g : R →+* P) (hy : M ≤ T.comap g) : S →+* Q := lift (M := M) (g := (algebraMap P Q).comp g) fun y => map_units _ ⟨g y, hy y.2⟩ #align is_localization.map IsLocalization.map end -- Porting note: added `simp` attribute, since it proves very similar lemmas marked `simp` @[simp] theorem map_eq (x) : map Q g hy ((algebraMap R S) x) = algebraMap P Q (g x) := lift_eq (fun y => map_units _ ⟨g y, hy y.2⟩) x #align is_localization.map_eq IsLocalization.map_eq @[simp] theorem map_comp : (map Q g hy).comp (algebraMap R S) = (algebraMap P Q).comp g := lift_comp fun y => map_units _ ⟨g y, hy y.2⟩ #align is_localization.map_comp IsLocalization.map_comp theorem map_mk' (x) (y : M) : map Q g hy (mk' S x y) = mk' Q (g x) ⟨g y, hy y.2⟩ := Submonoid.LocalizationMap.map_mk' (toLocalizationMap M S) (g := g.toMonoidHom) (fun y => hy y.2) (k := toLocalizationMap T Q) .. #align is_localization.map_mk' IsLocalization.map_mk' -- Porting note (#10756): new theorem @[simp] theorem map_id_mk' {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] (x) (y : M) : map Q (RingHom.id R) (le_refl M) (mk' S x y) = mk' Q x y := map_mk' .. @[simp] theorem map_id (z : S) (h : M ≤ M.comap (RingHom.id R) := le_refl M) : map S (RingHom.id _) h z = z := lift_id _ #align is_localization.map_id IsLocalization.map_id theorem map_unique (j : S →+* Q) (hj : ∀ x : R, j (algebraMap R S x) = algebraMap P Q (g x)) : map Q g hy = j := lift_unique (fun y => map_units _ ⟨g y, hy y.2⟩) hj #align is_localization.map_unique IsLocalization.map_unique /-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ theorem map_comp_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W] [IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) : (map W l hl).comp (map Q g hy : S →+* _) = map W (l.comp g) fun _ hx => hl (hy hx) := RingHom.ext fun x => Submonoid.LocalizationMap.map_map (P := P) (toLocalizationMap M S) (fun y => hy y.2) (toLocalizationMap U W) (fun w => hl w.2) x #align is_localization.map_comp_map IsLocalization.map_comp_map /-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ theorem map_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W] [IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) (x : S) : map W l hl (map Q g hy x) = map W (l.comp g) (fun x hx => hl (hy hx)) x := by rw [← map_comp_map (Q := Q) hy hl]; rfl #align is_localization.map_map IsLocalization.map_map theorem map_smul (x : S) (z : R) : map Q g hy (z • x : S) = g z • map Q g hy x := by rw [Algebra.smul_def, Algebra.smul_def, RingHom.map_mul, map_eq] #align is_localization.map_smul IsLocalization.map_smul section variable (S Q) /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M, T` respectively, an isomorphism `j : R ≃+* P` such that `j(M) = T` induces an isomorphism of localizations `S ≃+* Q`. -/ @[simps] noncomputable def ringEquivOfRingEquiv (h : R ≃+* P) (H : M.map h.toMonoidHom = T) : S ≃+* Q := have H' : T.map h.symm.toMonoidHom = M := by rw [← M.map_id, ← H, Submonoid.map_map] congr ext apply h.symm_apply_apply { map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) with toFun := map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) invFun := map S (h.symm : P →+* R) (T.le_comap_of_map_le (le_of_eq H')) left_inv := fun x => by rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply] simp right_inv := fun x => by rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply] simp } #align is_localization.ring_equiv_of_ring_equiv IsLocalization.ringEquivOfRingEquiv end theorem ringEquivOfRingEquiv_eq_map {j : R ≃+* P} (H : M.map j.toMonoidHom = T) : (ringEquivOfRingEquiv S Q j H : S →+* Q) = map Q (j : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl #align is_localization.ring_equiv_of_ring_equiv_eq_map IsLocalization.ringEquivOfRingEquiv_eq_map -- Porting note (#10618): removed `simp`, `simp` can prove it theorem ringEquivOfRingEquiv_eq {j : R ≃+* P} (H : M.map j.toMonoidHom = T) (x) : ringEquivOfRingEquiv S Q j H ((algebraMap R S) x) = algebraMap P Q (j x) := by simp #align is_localization.ring_equiv_of_ring_equiv_eq IsLocalization.ringEquivOfRingEquiv_eq theorem ringEquivOfRingEquiv_mk' {j : R ≃+* P} (H : M.map j.toMonoidHom = T) (x : R) (y : M) : ringEquivOfRingEquiv S Q j H (mk' S x y) = mk' Q (j x) ⟨j y, show j y ∈ T from H ▸ Set.mem_image_of_mem j y.2⟩ := by simp [map_mk'] #align is_localization.ring_equiv_of_ring_equiv_mk' IsLocalization.ringEquivOfRingEquiv_mk' end Map section AlgEquiv variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] section variable (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps!] noncomputable def algEquiv : S ≃ₐ[R] Q := { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with commutes' := ringEquivOfRingEquiv_eq _ } #align is_localization.alg_equiv IsLocalization.algEquiv end -- Porting note (#10618): removed `simp`, `simp` can prove it theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by simp #align is_localization.alg_equiv_mk' IsLocalization.algEquiv_mk' -- Porting note (#10618): removed `simp`, `simp` can prove it theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp #align is_localization.alg_equiv_symm_mk' IsLocalization.algEquiv_symm_mk' end AlgEquiv section at_units lemma at_units {R : Type*} [CommSemiring R] (S : Submonoid R) (hS : S ≤ IsUnit.submonoid R) : IsLocalization S R where map_units' y := hS y.prop surj' := fun s ↦ ⟨⟨s, 1⟩, by simp⟩ exists_of_eq := fun {x y} (e : x = y) ↦ ⟨1, e ▸ rfl⟩ variable (R M) /-- The localization at a module of units is isomorphic to the ring. -/ noncomputable def atUnits (H : M ≤ IsUnit.submonoid R) : R ≃ₐ[R] S := by refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩ · intro x y hxy obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy obtain ⟨u, hu⟩ := H c.prop rwa [← hu, Units.mul_right_inj] at eq · intro y obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y obtain ⟨u, hu⟩ := H s.prop use x * u.inv dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks] rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul] simp #align is_localization.at_units IsLocalization.atUnits end at_units section variable (M S) (Q : Type*) [CommSemiring Q] [Algebra P Q] /-- Injectivity of a map descends to the map induced on localizations. -/ theorem map_injective_of_injective (h : Function.Injective g) [IsLocalization (M.map g) Q] : Function.Injective (map Q g M.le_comap_map : S → Q) := (toLocalizationMap M S).map_injective_of_injective h (toLocalizationMap (M.map g) Q) end end IsLocalization section variable (M) {S} theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) : IsLocalization M P := by constructor · intro y convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom exact (h.commutes y).symm · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y) apply_fun (show S → P from h) at e simp only [h.map_mul, h.apply_symm_apply, h.commutes] at e exact ⟨⟨x, s⟩, e⟩ · intro x y rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes] exact id #align is_localization.is_localization_of_alg_equiv IsLocalization.isLocalization_of_algEquiv theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) : IsLocalization M S ↔ IsLocalization M P := ⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩ #align is_localization.is_localization_iff_of_alg_equiv IsLocalization.isLocalization_iff_of_algEquiv theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) : IsLocalization M S ↔ haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P := letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl } #align is_localization.is_localization_iff_of_ring_equiv IsLocalization.isLocalization_iff_of_ringEquiv variable (S) theorem isLocalization_of_base_ringEquiv [IsLocalization M S] (h : R ≃+* P) : haveI := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra IsLocalization (M.map h.toMonoidHom) S := by letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra constructor · rintro ⟨_, ⟨y, hy, rfl⟩⟩ convert IsLocalization.map_units S ⟨y, hy⟩ dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply] exact congr_arg _ (h.symm_apply_apply _) · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M y refine ⟨⟨h x, _, _, s.prop, rfl⟩, ?_⟩ dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply] at e ⊢ convert e <;> exact h.symm_apply_apply _ · intro x y rw [RingHom.algebraMap_toAlgebra, RingHom.comp_apply, RingHom.comp_apply, IsLocalization.eq_iff_exists M S] simp_rw [← h.toEquiv.apply_eq_iff_eq] change (∃ c : M, h (c * h.symm x) = h (c * h.symm y)) → _ simp only [RingEquiv.apply_symm_apply, RingEquiv.map_mul] exact fun ⟨c, e⟩ ↦ ⟨⟨_, _, c.prop, rfl⟩, e⟩ #align is_localization.is_localization_of_base_ring_equiv IsLocalization.isLocalization_of_base_ringEquiv theorem isLocalization_iff_of_base_ringEquiv (h : R ≃+* P) : IsLocalization M S ↔ haveI := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra IsLocalization (M.map h.toMonoidHom) S := by letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra refine ⟨fun _ => isLocalization_of_base_ringEquiv M S h, ?_⟩ intro H convert isLocalization_of_base_ringEquiv (Submonoid.map (RingEquiv.toMonoidHom h) M) S h.symm · erw [Submonoid.map_equiv_eq_comap_symm, Submonoid.comap_map_eq_of_injective] exact h.toEquiv.injective rw [RingHom.algebraMap_toAlgebra, RingHom.comp_assoc] simp only [RingHom.comp_id, RingEquiv.symm_symm, RingEquiv.symm_toRingHom_comp_toRingHom] apply Algebra.algebra_ext intro r rw [RingHom.algebraMap_toAlgebra] #align is_localization.is_localization_iff_of_base_ring_equiv IsLocalization.isLocalization_iff_of_base_ringEquiv end variable (M) theorem nonZeroDivisors_le_comap [IsLocalization M S] : nonZeroDivisors R ≤ (nonZeroDivisors S).comap (algebraMap R S) := by rintro a ha b (e : b * algebraMap R S a = 0) obtain ⟨x, s, rfl⟩ := mk'_surjective M b rw [← @mk'_one R _ M, ← mk'_mul, ← (algebraMap R S).map_zero, ← @mk'_one R _ M, IsLocalization.eq] at e obtain ⟨c, e⟩ := e rw [mul_zero, mul_zero, Submonoid.coe_one, one_mul, ← mul_assoc] at e rw [mk'_eq_zero_iff] exact ⟨c, ha _ e⟩ #align is_localization.non_zero_divisors_le_comap IsLocalization.nonZeroDivisors_le_comap theorem map_nonZeroDivisors_le [IsLocalization M S] : (nonZeroDivisors R).map (algebraMap R S) ≤ nonZeroDivisors S := Submonoid.map_le_iff_le_comap.mpr (nonZeroDivisors_le_comap M S) #align is_localization.map_non_zero_divisors_le IsLocalization.map_nonZeroDivisors_le end IsLocalization namespace Localization open IsLocalization /-! ### Constructing a localization at a given submonoid -/ section instance instUniqueLocalization [Subsingleton R] : Unique (Localization M) where uniq a := show a = mk 1 1 from Localization.induction_on a fun _ => by congr <;> apply Subsingleton.elim /-- Addition in a ring localization is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨b * c + d * a, b * d⟩`. Should not be confused with `AddLocalization.add`, which is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨a + c, b + d⟩`. -/ protected irreducible_def add (z w : Localization M) : Localization M := Localization.liftOn₂ z w (fun a b c d => mk ((b : R) * c + d * a) (b * d)) fun {a a' b b' c c' d d'} h1 h2 => mk_eq_mk_iff.2 (by rw [r_eq_r'] at h1 h2 ⊢ cases' h1 with t₅ ht₅ cases' h2 with t₆ ht₆ use t₅ * t₆ dsimp only calc ↑t₅ * ↑t₆ * (↑b' * ↑d' * ((b : R) * c + d * a)) _ = t₆ * (d' * c) * (t₅ * (b' * b)) + t₅ * (b' * a) * (t₆ * (d' * d)) := by ring _ = t₅ * t₆ * (b * d * (b' * c' + d' * a')) := by rw [ht₆, ht₅]; ring ) #align localization.add Localization.add instance : Add (Localization M) := ⟨Localization.add⟩ theorem add_mk (a b c d) : (mk a b : Localization M) + mk c d = mk ((b : R) * c + (d : R) * a) (b * d) := by show Localization.add (mk a b) (mk c d) = mk _ _ simp [Localization.add_def] #align localization.add_mk Localization.add_mk theorem add_mk_self (a b c) : (mk a b : Localization M) + mk c b = mk (a + c) b := by rw [add_mk, mk_eq_mk_iff, r_eq_r'] refine (r' M).symm ⟨1, ?_⟩ simp only [Submonoid.coe_one, Submonoid.coe_mul] ring #align localization.add_mk_self Localization.add_mk_self local macro "localization_tac" : tactic => `(tactic| { intros simp only [add_mk, Localization.mk_mul, ← Localization.mk_zero 1] refine mk_eq_mk_iff.mpr (r_of_eq ?_) simp only [Submonoid.coe_mul] ring }) instance : CommSemiring (Localization M) := { (show CommMonoidWithZero (Localization M) by infer_instance) with add := (· + ·) nsmul := (· • ·) nsmul_zero := fun x => Localization.induction_on x fun x => by simp only [smul_mk, zero_nsmul, mk_zero] nsmul_succ := fun n x => Localization.induction_on x fun x => by simp only [smul_mk, succ_nsmul, add_mk_self] add_assoc := fun m n k => Localization.induction_on₃ m n k (by localization_tac) zero_add := fun y => Localization.induction_on y (by localization_tac) add_zero := fun y => Localization.induction_on y (by localization_tac) add_comm := fun y z => Localization.induction_on₂ z y (by localization_tac) left_distrib := fun m n k => Localization.induction_on₃ m n k (by localization_tac) right_distrib := fun m n k => Localization.induction_on₃ m n k (by localization_tac) } /-- For any given denominator `b : M`, the map `a ↦ a / b` is an `AddMonoidHom` from `R` to `Localization M`-/ @[simps] def mkAddMonoidHom (b : M) : R →+ Localization M where toFun a := mk a b map_zero' := mk_zero _ map_add' _ _ := (add_mk_self _ _ _).symm #align localization.mk_add_monoid_hom Localization.mkAddMonoidHom theorem mk_sum {ι : Type*} (f : ι → R) (s : Finset ι) (b : M) : mk (∑ i ∈ s, f i) b = ∑ i ∈ s, mk (f i) b := map_sum (mkAddMonoidHom b) f s #align localization.mk_sum Localization.mk_sum theorem mk_list_sum (l : List R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum := map_list_sum (mkAddMonoidHom b) l #align localization.mk_list_sum Localization.mk_list_sum theorem mk_multiset_sum (l : Multiset R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum := (mkAddMonoidHom b).map_multiset_sum l #align localization.mk_multiset_sum Localization.mk_multiset_sum instance {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] : DistribMulAction S (Localization M) where smul_zero s := by simp only [← Localization.mk_zero 1, Localization.smul_mk, smul_zero] smul_add s x y := Localization.induction_on₂ x y <| Prod.rec fun r₁ x₁ => Prod.rec fun r₂ x₂ => by simp only [Localization.smul_mk, Localization.add_mk, smul_add, mul_comm _ (s • _), mul_comm _ r₁, mul_comm _ r₂, smul_mul_assoc] instance {S : Type*} [Semiring S] [MulSemiringAction S R] [IsScalarTower S R R] : MulSemiringAction S (Localization M) := { inferInstanceAs (MulDistribMulAction S (Localization M)), inferInstanceAs (DistribMulAction S (Localization M)) with } instance {S : Type*} [Semiring S] [Module S R] [IsScalarTower S R R] : Module S (Localization M) := { inferInstanceAs (DistribMulAction S (Localization M)) with zero_smul := Localization.ind <| Prod.rec <| by intros simp only [Localization.smul_mk, zero_smul, mk_zero] add_smul := fun s₁ s₂ => Localization.ind <| Prod.rec <| by intros simp only [Localization.smul_mk, add_smul, add_mk_self] } instance algebra {S : Type*} [CommSemiring S] [Algebra S R] : Algebra S (Localization M) where toRingHom := RingHom.comp { Localization.monoidOf M with toFun := (monoidOf M).toMap map_zero' := by rw [← mk_zero (1 : M), mk_one_eq_monoidOf_mk] map_add' := fun x y => by simp only [← mk_one_eq_monoidOf_mk, add_mk, Submonoid.coe_one, one_mul, add_comm] } (algebraMap S R) smul_def' s := Localization.ind <| Prod.rec <| by intro r x dsimp simp only [← mk_one_eq_monoidOf_mk, mk_mul, Localization.smul_mk, one_mul, Algebra.smul_def] commutes' s := Localization.ind <| Prod.rec <| by intro r x dsimp simp only [← mk_one_eq_monoidOf_mk, mk_mul, Localization.smul_mk, one_mul, mul_one, Algebra.commutes] instance isLocalization : IsLocalization M (Localization M) where map_units' := (Localization.monoidOf M).map_units surj' := (Localization.monoidOf M).surj exists_of_eq := (Localization.monoidOf M).eq_iff_exists.mp end @[simp] theorem toLocalizationMap_eq_monoidOf : toLocalizationMap M (Localization M) = monoidOf M := rfl #align localization.to_localization_map_eq_monoid_of Localization.toLocalizationMap_eq_monoidOf theorem monoidOf_eq_algebraMap (x) : (monoidOf M).toMap x = algebraMap R (Localization M) x := rfl #align localization.monoid_of_eq_algebra_map Localization.monoidOf_eq_algebraMap theorem mk_one_eq_algebraMap (x) : mk x 1 = algebraMap R (Localization M) x := rfl #align localization.mk_one_eq_algebra_map Localization.mk_one_eq_algebraMap theorem mk_eq_mk'_apply (x y) : mk x y = IsLocalization.mk' (Localization M) x y := by rw [mk_eq_monoidOf_mk'_apply, mk', toLocalizationMap_eq_monoidOf] #align localization.mk_eq_mk'_apply Localization.mk_eq_mk'_apply -- Porting note: removed `simp`. Left hand side can be simplified; not clear what normal form should --be. theorem mk_eq_mk' : (mk : R → M → Localization M) = IsLocalization.mk' (Localization M) := mk_eq_monoidOf_mk' #align localization.mk_eq_mk' Localization.mk_eq_mk' theorem mk_algebraMap {A : Type*} [CommSemiring A] [Algebra A R] (m : A) : mk (algebraMap A R m) 1 = algebraMap A (Localization M) m := by rw [mk_eq_mk', mk'_eq_iff_eq_mul, Submonoid.coe_one, map_one, mul_one]; rfl #align localization.mk_algebra_map Localization.mk_algebraMap
Mathlib/RingTheory/Localization/Basic.lean
1,095
1,096
theorem mk_natCast (m : ℕ) : (mk m 1 : Localization M) = m := by
simpa using mk_algebraMap (R := R) (A := ℕ) _
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.PurelyInseparable import Mathlib.FieldTheory.PerfectClosure /-! # `IsPerfectClosure` predicate This file contains `IsPerfectClosure` which asserts that `L` is a perfect closure of `K` under a ring homomorphism `i : K →+* L`, as well as its basic properties. ## Main definitions - `pNilradical`: given a natural number `p`, the `p`-nilradical of a ring is defined to be the nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1` (`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that `x ^ p ^ n = 0` for some `n` (`mem_pNilradical`). - `IsPRadical`: a ring homomorphism `i : K →+* L` of characteristic `p` rings is called `p`-radical, if or any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`, and the kernel of `i` is contained in the `p`-nilradical of `K`. A generalization of purely inseparable extension for fields. - `IsPerfectClosure`: if `i : K →+* L` is `p`-radical ring homomorphism, then it makes `L` a perfect closure of `K`, if `L` is perfect. Our definition makes it synonymous to `IsPRadical` if `PerfectRing L p` is present. A caveat is that you need to write `[PerfectRing L p] [IsPerfectClosure i p]`. This is similar to `PerfectRing` which has `ExpChar` as a prerequisite. - `PerfectRing.lift`: if a `p`-radical ring homomorphism `K →+* L` is given, `M` is a perfect ring, then any ring homomorphism `K →+* M` can be lifted to `L →+* M`. This is similar to `IsAlgClosed.lift` and `IsSepClosed.lift`. - `PerfectRing.liftEquiv`: `K →+* M` is one-to-one correspondence to `L →+* M`, given by `PerfectRing.lift`. This is a generalization to `PerfectClosure.lift`. - `IsPerfectClosure.equiv`: perfect closures of a ring are isomorphic. ## Main results - `IsPRadical.trans`: composition of `p`-radical ring homomorphisms is also `p`-radical. - `PerfectClosure.isPRadical`: the absolute perfect closure `PerfectClosure` is a `p`-radical extension over the base ring, in particular, it is a perfect closure of the base ring. - `IsPRadical.isPurelyInseparable`, `IsPurelyInseparable.isPRadical`: `p`-radical and purely inseparable are equivalent for fields. - The (relative) perfect closure `perfectClosure` is a perfect closure (inferred from `IsPurelyInseparable.isPRadical` automatically by Lean). ## Tags perfect ring, perfect closure, purely inseparable -/ open scoped Classical Polynomial open FiniteDimensional Polynomial IntermediateField Field noncomputable section /-- Given a natural number `p`, the `p`-nilradical of a ring is defined to be the nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1` (`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that `x ^ p ^ n = 0` for some `n` (`mem_pNilradical`). -/ def pNilradical (R : Type*) [CommSemiring R] (p : ℕ) : Ideal R := if 1 < p then nilradical R else ⊥ theorem pNilradical_le_nilradical {R : Type*} [CommSemiring R] {p : ℕ} : pNilradical R p ≤ nilradical R := by by_cases hp : 1 < p · rw [pNilradical, if_pos hp] simp_rw [pNilradical, if_neg hp, bot_le] theorem pNilradical_eq_nilradical {R : Type*} [CommSemiring R] {p : ℕ} (hp : 1 < p) : pNilradical R p = nilradical R := by rw [pNilradical, if_pos hp] theorem pNilradical_eq_bot {R : Type*} [CommSemiring R] {p : ℕ} (hp : ¬ 1 < p) : pNilradical R p = ⊥ := by rw [pNilradical, if_neg hp] theorem pNilradical_eq_bot' {R : Type*} [CommSemiring R] {p : ℕ} (hp : p ≤ 1) : pNilradical R p = ⊥ := pNilradical_eq_bot (not_lt.2 hp) theorem pNilradical_prime {R : Type*} [CommSemiring R] {p : ℕ} (hp : p.Prime) : pNilradical R p = nilradical R := pNilradical_eq_nilradical hp.one_lt theorem pNilradical_one {R : Type*} [CommSemiring R] : pNilradical R 1 = ⊥ := pNilradical_eq_bot' rfl.le theorem mem_pNilradical {R : Type*} [CommSemiring R] {p : ℕ} {x : R} : x ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = 0 := by by_cases hp : 1 < p · rw [pNilradical_eq_nilradical hp] refine ⟨fun ⟨n, h⟩ ↦ ⟨n, ?_⟩, fun ⟨n, h⟩ ↦ ⟨p ^ n, h⟩⟩ rw [← Nat.sub_add_cancel ((Nat.lt_pow_self hp n).le), pow_add, h, mul_zero] rw [pNilradical_eq_bot hp, Ideal.mem_bot] refine ⟨fun h ↦ ⟨0, by rw [pow_zero, pow_one, h]⟩, fun ⟨n, h⟩ ↦ ?_⟩ rcases Nat.le_one_iff_eq_zero_or_eq_one.1 (not_lt.1 hp) with hp | hp · by_cases hn : n = 0 · rwa [hn, pow_zero, pow_one] at h rw [hp, zero_pow hn, pow_zero] at h haveI := subsingleton_of_zero_eq_one h.symm exact Subsingleton.elim _ _ rwa [hp, one_pow, pow_one] at h theorem sub_mem_pNilradical_iff_pow_expChar_pow_eq {R : Type*} [CommRing R] {p : ℕ} [ExpChar R p] {x y : R} : x - y ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = y ^ p ^ n := by simp_rw [mem_pNilradical, sub_pow_expChar_pow, sub_eq_zero] theorem pow_expChar_pow_inj_of_pNilradical_eq_bot (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p] (h : pNilradical R p = ⊥) (n : ℕ) : Function.Injective fun x : R ↦ x ^ p ^ n := fun _ _ H ↦ sub_eq_zero.1 <| Ideal.mem_bot.1 <| h ▸ sub_mem_pNilradical_iff_pow_expChar_pow_eq.2 ⟨n, H⟩ theorem pNilradical_eq_bot_of_frobenius_inj (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p] (h : Function.Injective (frobenius R p)) : pNilradical R p = ⊥ := bot_unique fun x ↦ by rw [mem_pNilradical, Ideal.mem_bot] exact fun ⟨n, _⟩ ↦ h.iterate n (by rwa [← coe_iterateFrobenius, map_zero]) theorem PerfectRing.pNilradical_eq_bot (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p] [PerfectRing R p] : pNilradical R p = ⊥ := pNilradical_eq_bot_of_frobenius_inj R p (injective_frobenius R p) section IsPerfectClosure variable {K L M N : Type*} section CommSemiring variable [CommSemiring K] [CommSemiring L] [CommSemiring M] (i : K →+* L) (j : K →+* M) (f : L →+* M) (p : ℕ) [ExpChar K p] [ExpChar L p] [ExpChar M p] /-- If `i : K →+* L` is a ring homomorphism of characteristic `p` rings, then it is called `p`-radical if the following conditions are satisfied: - For any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`. - The kernel of `i` is contained in the `p`-nilradical of `K`. It is a generalization of purely inseparable extension for fields. -/ @[mk_iff] class IsPRadical : Prop where pow_mem' : ∀ x : L, ∃ (n : ℕ) (y : K), i y = x ^ p ^ n ker_le' : RingHom.ker i ≤ pNilradical K p theorem IsPRadical.pow_mem [IsPRadical i p] (x : L) : ∃ (n : ℕ) (y : K), i y = x ^ p ^ n := pow_mem' x theorem IsPRadical.ker_le [IsPRadical i p] : RingHom.ker i ≤ pNilradical K p := ker_le' theorem IsPRadical.comap_pNilradical [IsPRadical i p] : (pNilradical L p).comap i = pNilradical K p := by refine le_antisymm (fun x h ↦ mem_pNilradical.2 ?_) (fun x h ↦ ?_) · obtain ⟨n, h⟩ := mem_pNilradical.1 <| Ideal.mem_comap.1 h obtain ⟨m, h⟩ := mem_pNilradical.1 <| ker_le i p ((map_pow i x _).symm ▸ h) exact ⟨n + m, by rwa [pow_add, pow_mul]⟩ simp only [Ideal.mem_comap, mem_pNilradical] at h ⊢ obtain ⟨n, h⟩ := h exact ⟨n, by simpa only [map_pow, map_zero] using congr(i $h)⟩ variable (K) in instance IsPRadical.of_id : IsPRadical (RingHom.id K) p where pow_mem' x := ⟨0, x, by simp⟩ ker_le' x h := by convert Ideal.zero_mem _ /-- Composition of `p`-radical ring homomorphisms is also `p`-radical. -/ theorem IsPRadical.trans [IsPRadical i p] [IsPRadical f p] : IsPRadical (f.comp i) p where pow_mem' x := by obtain ⟨n, y, hy⟩ := pow_mem f p x obtain ⟨m, z, hz⟩ := pow_mem i p y exact ⟨n + m, z, by rw [RingHom.comp_apply, hz, map_pow, hy, pow_add, pow_mul]⟩ ker_le' x h := by rw [RingHom.mem_ker, RingHom.comp_apply, ← RingHom.mem_ker] at h simpa only [← Ideal.mem_comap, comap_pNilradical] using ker_le f p h /-- If `i : K →+* L` is a `p`-radical ring homomorphism, then it makes `L` a perfect closure of `K`, if `L` is perfect. In this case the kernel of `i` is equal to the `p`-nilradical of `K` (see `IsPerfectClosure.ker_eq`). Our definition makes it synonymous to `IsPRadical` if `PerfectRing L p` is present. A caveat is that you need to write `[PerfectRing L p] [IsPerfectClosure i p]`. This is similar to `PerfectRing` which has `ExpChar` as a prerequisite. -/ @[nolint unusedArguments] abbrev IsPerfectClosure [PerfectRing L p] := IsPRadical i p /-- If `i : K →+* L` is a ring homomorphism of exponential characteristic `p` rings, such that `L` is perfect, then the `p`-nilradical of `K` is contained in the kernel of `i`. -/ theorem RingHom.pNilradical_le_ker_of_perfectRing [PerfectRing L p] : pNilradical K p ≤ RingHom.ker i := fun x h ↦ by obtain ⟨n, h⟩ := mem_pNilradical.1 h replace h := congr((iterateFrobeniusEquiv L p n).symm (i $h)) rwa [map_pow, ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply, map_zero, map_zero] at h theorem IsPerfectClosure.ker_eq [PerfectRing L p] [IsPerfectClosure i p] : RingHom.ker i = pNilradical K p := IsPRadical.ker_le'.antisymm (i.pNilradical_le_ker_of_perfectRing p) namespace PerfectRing /- NOTE: To define `PerfectRing.lift_aux`, only the `IsPRadical.pow_mem` is required, but not `IsPRadical.ker_le`. But in order to use typeclass, here we require the whole `IsPRadical`. -/ variable [PerfectRing M p] [IsPRadical i p] theorem lift_aux (x : L) : ∃ y : ℕ × K, i y.2 = x ^ p ^ y.1 := by obtain ⟨n, y, h⟩ := IsPRadical.pow_mem i p x exact ⟨(n, y), h⟩ /-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that `i` is `p`-radical (in fact only the `IsPRadical.pow_mem` is required) and `M` is a perfect ring, then one can define a map `L → M` which maps an element `x` of `L` to `y ^ (p ^ -n)` if `x ^ (p ^ n)` is equal to some element `y` of `K`. -/ def liftAux (x : L) : M := (iterateFrobeniusEquiv M p (Classical.choose (lift_aux i p x)).1).symm (j (Classical.choose (lift_aux i p x)).2) @[simp] theorem liftAux_self_apply [PerfectRing L p] (x : L) : liftAux i i p x = x := by rw [liftAux, Classical.choose_spec (lift_aux i p x), ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply] @[simp] theorem liftAux_self [PerfectRing L p] : liftAux i i p = id := funext (liftAux_self_apply i p) @[simp] theorem liftAux_id_apply (x : K) : liftAux (RingHom.id K) j p x = j x := by have := RingHom.id_apply _ ▸ Classical.choose_spec (lift_aux (RingHom.id K) p x) rw [liftAux, this, map_pow, ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply] @[simp] theorem liftAux_id : liftAux (RingHom.id K) j p = j := funext (liftAux_id_apply j p) end PerfectRing end CommSemiring section CommRing variable [CommRing K] [CommRing L] [CommRing M] [CommRing N] (i : K →+* L) (j : K →+* M) (k : K →+* N) (f : L →+* M) (g : L →+* N) (p : ℕ) [ExpChar K p] [ExpChar L p] [ExpChar M p] [ExpChar N p] namespace IsPRadical /-- If `i : K →+* L` is `p`-radical, then for any ring `M` of exponential charactistic `p` whose `p`-nilradical is zero, the map `(L →+* M) → (K →+* M)` induced by `i` is injective. -/ theorem injective_comp_of_pNilradical_eq_bot [IsPRadical i p] (h : pNilradical M p = ⊥) : Function.Injective fun f : L →+* M ↦ f.comp i := fun f g heq ↦ by ext x obtain ⟨n, y, hx⟩ := IsPRadical.pow_mem i p x apply_fun _ using pow_expChar_pow_inj_of_pNilradical_eq_bot M p h n simpa only [← map_pow, ← hx] using congr($(heq) y) variable (M) /-- If `i : K →+* L` is `p`-radical, then for any reduced ring `M` of exponential charactistic `p`, the map `(L →+* M) → (K →+* M)` induced by `i` is injective. A special case of `IsPRadical.injective_comp_of_pNilradical_eq_bot` and a generalization of `IsPurelyInseparable.injective_comp_algebraMap`. -/ theorem injective_comp [IsPRadical i p] [IsReduced M] : Function.Injective fun f : L →+* M ↦ f.comp i := injective_comp_of_pNilradical_eq_bot i p <| bot_unique <| pNilradical_le_nilradical.trans (nilradical_eq_zero M).le /-- If `i : K →+* L` is `p`-radical, then for any perfect ring `M` of exponential charactistic `p`, the map `(L →+* M) → (K →+* M)` induced by `i` is injective. A special case of `IsPRadical.injective_comp_of_pNilradical_eq_bot`. -/ theorem injective_comp_of_perfect [IsPRadical i p] [PerfectRing M p] : Function.Injective fun f : L →+* M ↦ f.comp i := injective_comp_of_pNilradical_eq_bot i p (PerfectRing.pNilradical_eq_bot M p) end IsPRadical namespace PerfectRing variable [PerfectRing M p] [IsPRadical i p] /-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that `i` is `p`-radical, and `M` is a perfect ring, then `PerfectRing.liftAux` is well-defined. -/ theorem liftAux_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) : liftAux i j p x = (iterateFrobeniusEquiv M p n).symm (j y) := by rw [liftAux] have h' := Classical.choose_spec (lift_aux i p x) set n' := (Classical.choose (lift_aux i p x)).1 replace h := congr($(h.symm) ^ p ^ n') rw [← pow_mul, mul_comm, pow_mul, ← h', ← map_pow, ← map_pow, ← sub_eq_zero, ← map_sub, ← RingHom.mem_ker] at h obtain ⟨m, h⟩ := mem_pNilradical.1 (IsPRadical.ker_le i p h) refine (iterateFrobeniusEquiv M p (m + n + n')).injective ?_ conv_lhs => rw [iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply] rw [add_assoc, add_comm n n', ← add_assoc, iterateFrobeniusEquiv_add_apply (m := m + n'), RingEquiv.apply_symm_apply, iterateFrobeniusEquiv_def, iterateFrobeniusEquiv_def, ← sub_eq_zero, ← map_pow, ← map_pow, ← map_sub, add_comm m, add_comm m, pow_add, pow_mul, pow_add, pow_mul, ← sub_pow_expChar_pow, h, map_zero] /-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that `i` is `p`-radical, and `M` is a perfect ring, then `PerfectRing.liftAux` is a ring homomorphism. This is similar to `IsAlgClosed.lift` and `IsSepClosed.lift`. -/ def lift : L →+* M where toFun := liftAux i j p map_one' := by simp [liftAux_apply i j p 1 0 1 (by rw [one_pow, map_one])] map_mul' x1 x2 := by obtain ⟨n1, y1, h1⟩ := IsPRadical.pow_mem i p x1 obtain ⟨n2, y2, h2⟩ := IsPRadical.pow_mem i p x2 simp only; rw [liftAux_apply i j p _ _ _ h1, liftAux_apply i j p _ _ _ h2, liftAux_apply i j p (x1 * x2) (n1 + n2) (y1 ^ p ^ n2 * y2 ^ p ^ n1) (by rw [map_mul, map_pow, map_pow, h1, h2, ← pow_mul, ← pow_add, ← pow_mul, ← pow_add, add_comm n2, mul_pow]), map_mul, map_pow, map_pow, map_mul, ← iterateFrobeniusEquiv_def] nth_rw 1 [iterateFrobeniusEquiv_symm_add_apply] rw [RingEquiv.symm_apply_apply, add_comm n1, iterateFrobeniusEquiv_symm_add_apply, ← iterateFrobeniusEquiv_def, RingEquiv.symm_apply_apply] map_zero' := by simp [liftAux_apply i j p 0 0 0 (by rw [pow_zero, pow_one, map_zero])] map_add' x1 x2 := by obtain ⟨n1, y1, h1⟩ := IsPRadical.pow_mem i p x1 obtain ⟨n2, y2, h2⟩ := IsPRadical.pow_mem i p x2 simp only; rw [liftAux_apply i j p _ _ _ h1, liftAux_apply i j p _ _ _ h2, liftAux_apply i j p (x1 + x2) (n1 + n2) (y1 ^ p ^ n2 + y2 ^ p ^ n1) (by rw [map_add, map_pow, map_pow, h1, h2, ← pow_mul, ← pow_add, ← pow_mul, ← pow_add, add_comm n2, add_pow_expChar_pow]), map_add, map_pow, map_pow, map_add, ← iterateFrobeniusEquiv_def] nth_rw 1 [iterateFrobeniusEquiv_symm_add_apply] rw [RingEquiv.symm_apply_apply, add_comm n1, iterateFrobeniusEquiv_symm_add_apply, ← iterateFrobeniusEquiv_def, RingEquiv.symm_apply_apply] theorem lift_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) : lift i j p x = (iterateFrobeniusEquiv M p n).symm (j y) := liftAux_apply i j p _ _ _ h @[simp] theorem lift_comp_apply (x : K) : lift i j p (i x) = j x := by rw [lift_apply i j p _ 0 x (by rw [pow_zero, pow_one]), iterateFrobeniusEquiv_zero]; rfl @[simp] theorem lift_comp : (lift i j p).comp i = j := RingHom.ext (lift_comp_apply i j p) theorem lift_self_apply [PerfectRing L p] (x : L) : lift i i p x = x := liftAux_self_apply i p x @[simp] theorem lift_self [PerfectRing L p] : lift i i p = RingHom.id L := RingHom.ext (liftAux_self_apply i p) theorem lift_id_apply (x : K) : lift (RingHom.id K) j p x = j x := liftAux_id_apply j p x @[simp] theorem lift_id : lift (RingHom.id K) j p = j := RingHom.ext (liftAux_id_apply j p) @[simp] theorem comp_lift : lift i (f.comp i) p = f := IsPRadical.injective_comp_of_perfect _ i p (lift_comp i _ p) theorem comp_lift_apply (x : L) : lift i (f.comp i) p x = f x := congr($(comp_lift i f p) x) variable (M) in /-- If `i : K →+* L` is a homomorphisms of characteristic `p` rings, such that `i` is `p`-radical, and `M` is a perfect ring of characteristic `p`, then `K →+* M` is one-to-one correspondence to `L →+* M`, given by `PerfectRing.lift`. This is a generalization to `PerfectClosure.lift`. -/ def liftEquiv : (K →+* M) ≃ (L →+* M) where toFun j := lift i j p invFun f := f.comp i left_inv f := lift_comp i f p right_inv f := comp_lift i f p theorem liftEquiv_apply : liftEquiv M i p j = lift i j p := rfl theorem liftEquiv_symm_apply : (liftEquiv M i p).symm f = f.comp i := rfl theorem liftEquiv_id_apply : liftEquiv M (RingHom.id K) p j = j := lift_id j p @[simp] theorem liftEquiv_id : liftEquiv M (RingHom.id K) p = Equiv.refl _ := Equiv.ext (liftEquiv_id_apply · p) section comp variable [PerfectRing N p] [IsPRadical j p] @[simp] theorem lift_comp_lift : (lift j k p).comp (lift i j p) = lift i k p := IsPRadical.injective_comp_of_perfect _ i p (by ext; simp) @[simp] theorem lift_comp_lift_apply (x : L) : lift j k p (lift i j p x) = lift i k p x := congr($(lift_comp_lift i j k p) x) theorem lift_comp_lift_apply_eq_self [PerfectRing L p] (x : L) : lift j i p (lift i j p x) = x := by rw [lift_comp_lift_apply, lift_self_apply] theorem lift_comp_lift_eq_id [PerfectRing L p] : (lift j i p).comp (lift i j p) = RingHom.id L := RingHom.ext (lift_comp_lift_apply_eq_self i j p) end comp section liftEquiv_comp variable [IsPRadical g p] [IsPRadical (g.comp i) p] @[simp] theorem lift_lift : lift g (lift i j p) p = lift (g.comp i) j p := by refine IsPRadical.injective_comp_of_perfect _ (g.comp i) p ?_ simp_rw [← RingHom.comp_assoc _ _ (lift g _ p), lift_comp] theorem lift_lift_apply (x : N) : lift g (lift i j p) p x = lift (g.comp i) j p x := congr($(lift_lift i j g p) x) @[simp] theorem liftEquiv_comp_apply : liftEquiv M g p (liftEquiv M i p j) = liftEquiv M (g.comp i) p j := lift_lift i j g p @[simp] theorem liftEquiv_trans : (liftEquiv M i p).trans (liftEquiv M g p) = liftEquiv M (g.comp i) p := Equiv.ext (liftEquiv_comp_apply i · g p) end liftEquiv_comp end PerfectRing namespace IsPerfectClosure variable [PerfectRing L p] [IsPerfectClosure i p] [PerfectRing M p] [IsPerfectClosure j p] /-- If `L` and `M` are both perfect closures of `K`, then there is a ring isomorphism `L ≃+* M`. This is similar to `IsAlgClosure.equiv` and `IsSepClosure.equiv`. -/ def equiv : L ≃+* M where __ := PerfectRing.lift i j p invFun := PerfectRing.liftAux j i p left_inv := PerfectRing.lift_comp_lift_apply_eq_self i j p right_inv := PerfectRing.lift_comp_lift_apply_eq_self j i p theorem equiv_toRingHom : (equiv i j p).toRingHom = PerfectRing.lift i j p := rfl @[simp] theorem equiv_symm : (equiv i j p).symm = equiv j i p := rfl theorem equiv_symm_toRingHom : (equiv i j p).symm.toRingHom = PerfectRing.lift j i p := rfl theorem equiv_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) : equiv i j p x = (iterateFrobeniusEquiv M p n).symm (j y) := PerfectRing.liftAux_apply i j p _ _ _ h
Mathlib/FieldTheory/IsPerfectClosure.lean
457
459
theorem equiv_symm_apply (x : M) (n : ℕ) (y : K) (h : j y = x ^ p ^ n) : (equiv i j p).symm x = (iterateFrobeniusEquiv L p n).symm (i y) := by
rw [equiv_symm, equiv_apply j i p _ _ _ h]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Data.ENat.Lattice import Mathlib.Data.Part import Mathlib.Tactic.NormNum #align_import data.nat.part_enat from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8" /-! # Natural numbers with infinity The natural numbers and an extra `top` element `⊤`. This implementation uses `Part ℕ` as an implementation. Use `ℕ∞` instead unless you care about computability. ## Main definitions The following instances are defined: * `OrderedAddCommMonoid PartENat` * `CanonicallyOrderedAddCommMonoid PartENat` * `CompleteLinearOrder PartENat` There is no additive analogue of `MonoidWithZero`; if there were then `PartENat` could be an `AddMonoidWithTop`. * `toWithTop` : the map from `PartENat` to `ℕ∞`, with theorems that it plays well with `+` and `≤`. * `withTopAddEquiv : PartENat ≃+ ℕ∞` * `withTopOrderIso : PartENat ≃o ℕ∞` ## Implementation details `PartENat` is defined to be `Part ℕ`. `+` and `≤` are defined on `PartENat`, but there is an issue with `*` because it's not clear what `0 * ⊤` should be. `mul` is hence left undefined. Similarly `⊤ - ⊤` is ambiguous so there is no `-` defined on `PartENat`. Before the `open scoped Classical` line, various proofs are made with decidability assumptions. This can cause issues -- see for example the non-simp lemma `toWithTopZero` proved by `rfl`, followed by `@[simp] lemma toWithTopZero'` whose proof uses `convert`. ## Tags PartENat, ℕ∞ -/ open Part hiding some /-- Type of natural numbers with infinity (`⊤`) -/ def PartENat : Type := Part ℕ #align part_enat PartENat namespace PartENat /-- The computable embedding `ℕ → PartENat`. This coincides with the coercion `coe : ℕ → PartENat`, see `PartENat.some_eq_natCast`. -/ @[coe] def some : ℕ → PartENat := Part.some #align part_enat.some PartENat.some instance : Zero PartENat := ⟨some 0⟩ instance : Inhabited PartENat := ⟨0⟩ instance : One PartENat := ⟨some 1⟩ instance : Add PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => get x h.1 + get y h.2⟩⟩ instance (n : ℕ) : Decidable (some n).Dom := isTrue trivial @[simp] theorem dom_some (x : ℕ) : (some x).Dom := trivial #align part_enat.dom_some PartENat.dom_some instance addCommMonoid : AddCommMonoid PartENat where add := (· + ·) zero := 0 add_comm x y := Part.ext' and_comm fun _ _ => add_comm _ _ zero_add x := Part.ext' (true_and_iff _) fun _ _ => zero_add _ add_zero x := Part.ext' (and_true_iff _) fun _ _ => add_zero _ add_assoc x y z := Part.ext' and_assoc fun _ _ => add_assoc _ _ _ nsmul := nsmulRec instance : AddCommMonoidWithOne PartENat := { PartENat.addCommMonoid with one := 1 natCast := some natCast_zero := rfl natCast_succ := fun _ => Part.ext' (true_and_iff _).symm fun _ _ => rfl } theorem some_eq_natCast (n : ℕ) : some n = n := rfl #align part_enat.some_eq_coe PartENat.some_eq_natCast instance : CharZero PartENat where cast_injective := Part.some_injective /-- Alias of `Nat.cast_inj` specialized to `PartENat` --/ theorem natCast_inj {x y : ℕ} : (x : PartENat) = y ↔ x = y := Nat.cast_inj #align part_enat.coe_inj PartENat.natCast_inj @[simp] theorem dom_natCast (x : ℕ) : (x : PartENat).Dom := trivial #align part_enat.dom_coe PartENat.dom_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem dom_ofNat (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)).Dom := trivial @[simp] theorem dom_zero : (0 : PartENat).Dom := trivial @[simp] theorem dom_one : (1 : PartENat).Dom := trivial instance : CanLift PartENat ℕ (↑) Dom := ⟨fun n hn => ⟨n.get hn, Part.some_get _⟩⟩ instance : LE PartENat := ⟨fun x y => ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy⟩ instance : Top PartENat := ⟨none⟩ instance : Bot PartENat := ⟨0⟩ instance : Sup PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => x.get h.1 ⊔ y.get h.2⟩⟩ theorem le_def (x y : PartENat) : x ≤ y ↔ ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy := Iff.rfl #align part_enat.le_def PartENat.le_def @[elab_as_elim] protected theorem casesOn' {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P (some n)) → P a := Part.induction_on #align part_enat.cases_on' PartENat.casesOn' @[elab_as_elim] protected theorem casesOn {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P n) → P a := by exact PartENat.casesOn' #align part_enat.cases_on PartENat.casesOn -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem top_add (x : PartENat) : ⊤ + x = ⊤ := Part.ext' (false_and_iff _) fun h => h.left.elim #align part_enat.top_add PartENat.top_add -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem add_top (x : PartENat) : x + ⊤ = ⊤ := by rw [add_comm, top_add] #align part_enat.add_top PartENat.add_top @[simp] theorem natCast_get {x : PartENat} (h : x.Dom) : (x.get h : PartENat) = x := by exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl #align part_enat.coe_get PartENat.natCast_get @[simp, norm_cast] theorem get_natCast' (x : ℕ) (h : (x : PartENat).Dom) : get (x : PartENat) h = x := by rw [← natCast_inj, natCast_get] #align part_enat.get_coe' PartENat.get_natCast' theorem get_natCast {x : ℕ} : get (x : PartENat) (dom_natCast x) = x := get_natCast' _ _ #align part_enat.get_coe PartENat.get_natCast theorem coe_add_get {x : ℕ} {y : PartENat} (h : ((x : PartENat) + y).Dom) : get ((x : PartENat) + y) h = x + get y h.2 := by rfl #align part_enat.coe_add_get PartENat.coe_add_get @[simp] theorem get_add {x y : PartENat} (h : (x + y).Dom) : get (x + y) h = x.get h.1 + y.get h.2 := rfl #align part_enat.get_add PartENat.get_add @[simp] theorem get_zero (h : (0 : PartENat).Dom) : (0 : PartENat).get h = 0 := rfl #align part_enat.get_zero PartENat.get_zero @[simp] theorem get_one (h : (1 : PartENat).Dom) : (1 : PartENat).get h = 1 := rfl #align part_enat.get_one PartENat.get_one -- See note [no_index around OfNat.ofNat] @[simp] theorem get_ofNat' (x : ℕ) [x.AtLeastTwo] (h : (no_index (OfNat.ofNat x : PartENat)).Dom) : Part.get (no_index (OfNat.ofNat x : PartENat)) h = (no_index (OfNat.ofNat x)) := get_natCast' x h nonrec theorem get_eq_iff_eq_some {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = some b := get_eq_iff_eq_some #align part_enat.get_eq_iff_eq_some PartENat.get_eq_iff_eq_some theorem get_eq_iff_eq_coe {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = b := by rw [get_eq_iff_eq_some] rfl #align part_enat.get_eq_iff_eq_coe PartENat.get_eq_iff_eq_coe theorem dom_of_le_of_dom {x y : PartENat} : x ≤ y → y.Dom → x.Dom := fun ⟨h, _⟩ => h #align part_enat.dom_of_le_of_dom PartENat.dom_of_le_of_dom theorem dom_of_le_some {x : PartENat} {y : ℕ} (h : x ≤ some y) : x.Dom := dom_of_le_of_dom h trivial #align part_enat.dom_of_le_some PartENat.dom_of_le_some theorem dom_of_le_natCast {x : PartENat} {y : ℕ} (h : x ≤ y) : x.Dom := by exact dom_of_le_some h #align part_enat.dom_of_le_coe PartENat.dom_of_le_natCast instance decidableLe (x y : PartENat) [Decidable x.Dom] [Decidable y.Dom] : Decidable (x ≤ y) := if hx : x.Dom then decidable_of_decidable_of_iff (by rw [le_def]) else if hy : y.Dom then isFalse fun h => hx <| dom_of_le_of_dom h hy else isTrue ⟨fun h => (hy h).elim, fun h => (hy h).elim⟩ #align part_enat.decidable_le PartENat.decidableLe -- Porting note: Removed. Use `Nat.castAddMonoidHom` instead. #noalign part_enat.coe_hom #noalign part_enat.coe_coe_hom instance partialOrder : PartialOrder PartENat where le := (· ≤ ·) le_refl _ := ⟨id, fun _ => le_rfl⟩ le_trans := fun _ _ _ ⟨hxy₁, hxy₂⟩ ⟨hyz₁, hyz₂⟩ => ⟨hxy₁ ∘ hyz₁, fun _ => le_trans (hxy₂ _) (hyz₂ _)⟩ lt_iff_le_not_le _ _ := Iff.rfl le_antisymm := fun _ _ ⟨hxy₁, hxy₂⟩ ⟨hyx₁, hyx₂⟩ => Part.ext' ⟨hyx₁, hxy₁⟩ fun _ _ => le_antisymm (hxy₂ _) (hyx₂ _) theorem lt_def (x y : PartENat) : x < y ↔ ∃ hx : x.Dom, ∀ hy : y.Dom, x.get hx < y.get hy := by rw [lt_iff_le_not_le, le_def, le_def, not_exists] constructor · rintro ⟨⟨hyx, H⟩, h⟩ by_cases hx : x.Dom · use hx intro hy specialize H hy specialize h fun _ => hy rw [not_forall] at h cases' h with hx' h rw [not_le] at h exact h · specialize h fun hx' => (hx hx').elim rw [not_forall] at h cases' h with hx' h exact (hx hx').elim · rintro ⟨hx, H⟩ exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩ #align part_enat.lt_def PartENat.lt_def noncomputable instance orderedAddCommMonoid : OrderedAddCommMonoid PartENat := { PartENat.partialOrder, PartENat.addCommMonoid with add_le_add_left := fun a b ⟨h₁, h₂⟩ c => PartENat.casesOn c (by simp [top_add]) fun c => ⟨fun h => And.intro (dom_natCast _) (h₁ h.2), fun h => by simpa only [coe_add_get] using add_le_add_left (h₂ _) c⟩ } instance semilatticeSup : SemilatticeSup PartENat := { PartENat.partialOrder with sup := (· ⊔ ·) le_sup_left := fun _ _ => ⟨And.left, fun _ => le_sup_left⟩ le_sup_right := fun _ _ => ⟨And.right, fun _ => le_sup_right⟩ sup_le := fun _ _ _ ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ => ⟨fun hz => ⟨hx₁ hz, hy₁ hz⟩, fun _ => sup_le (hx₂ _) (hy₂ _)⟩ } #align part_enat.semilattice_sup PartENat.semilatticeSup instance orderBot : OrderBot PartENat where bot := ⊥ bot_le _ := ⟨fun _ => trivial, fun _ => Nat.zero_le _⟩ #align part_enat.order_bot PartENat.orderBot instance orderTop : OrderTop PartENat where top := ⊤ le_top _ := ⟨fun h => False.elim h, fun hy => False.elim hy⟩ #align part_enat.order_top PartENat.orderTop instance : ZeroLEOneClass PartENat where zero_le_one := bot_le /-- Alias of `Nat.cast_le` specialized to `PartENat` --/ theorem coe_le_coe {x y : ℕ} : (x : PartENat) ≤ y ↔ x ≤ y := Nat.cast_le #align part_enat.coe_le_coe PartENat.coe_le_coe /-- Alias of `Nat.cast_lt` specialized to `PartENat` --/ theorem coe_lt_coe {x y : ℕ} : (x : PartENat) < y ↔ x < y := Nat.cast_lt #align part_enat.coe_lt_coe PartENat.coe_lt_coe @[simp] theorem get_le_get {x y : PartENat} {hx : x.Dom} {hy : y.Dom} : x.get hx ≤ y.get hy ↔ x ≤ y := by conv => lhs rw [← coe_le_coe, natCast_get, natCast_get] #align part_enat.get_le_get PartENat.get_le_get theorem le_coe_iff (x : PartENat) (n : ℕ) : x ≤ n ↔ ∃ h : x.Dom, x.get h ≤ n := by show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n simp only [forall_prop_of_true, dom_natCast, get_natCast'] #align part_enat.le_coe_iff PartENat.le_coe_iff theorem lt_coe_iff (x : PartENat) (n : ℕ) : x < n ↔ ∃ h : x.Dom, x.get h < n := by simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast] #align part_enat.lt_coe_iff PartENat.lt_coe_iff theorem coe_le_iff (n : ℕ) (x : PartENat) : (n : PartENat) ≤ x ↔ ∀ h : x.Dom, n ≤ x.get h := by rw [← some_eq_natCast] simp only [le_def, exists_prop_of_true, dom_some, forall_true_iff] rfl #align part_enat.coe_le_iff PartENat.coe_le_iff theorem coe_lt_iff (n : ℕ) (x : PartENat) : (n : PartENat) < x ↔ ∀ h : x.Dom, n < x.get h := by rw [← some_eq_natCast] simp only [lt_def, exists_prop_of_true, dom_some, forall_true_iff] rfl #align part_enat.coe_lt_iff PartENat.coe_lt_iff nonrec theorem eq_zero_iff {x : PartENat} : x = 0 ↔ x ≤ 0 := eq_bot_iff #align part_enat.eq_zero_iff PartENat.eq_zero_iff theorem ne_zero_iff {x : PartENat} : x ≠ 0 ↔ ⊥ < x := bot_lt_iff_ne_bot.symm #align part_enat.ne_zero_iff PartENat.ne_zero_iff theorem dom_of_lt {x y : PartENat} : x < y → x.Dom := PartENat.casesOn x not_top_lt fun _ _ => dom_natCast _ #align part_enat.dom_of_lt PartENat.dom_of_lt theorem top_eq_none : (⊤ : PartENat) = Part.none := rfl #align part_enat.top_eq_none PartENat.top_eq_none @[simp] theorem natCast_lt_top (x : ℕ) : (x : PartENat) < ⊤ := Ne.lt_top fun h => absurd (congr_arg Dom h) <| by simp only [dom_natCast]; exact true_ne_false #align part_enat.coe_lt_top PartENat.natCast_lt_top @[simp] theorem zero_lt_top : (0 : PartENat) < ⊤ := natCast_lt_top 0 @[simp] theorem one_lt_top : (1 : PartENat) < ⊤ := natCast_lt_top 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_lt_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) < ⊤ := natCast_lt_top x @[simp] theorem natCast_ne_top (x : ℕ) : (x : PartENat) ≠ ⊤ := ne_of_lt (natCast_lt_top x) #align part_enat.coe_ne_top PartENat.natCast_ne_top @[simp] theorem zero_ne_top : (0 : PartENat) ≠ ⊤ := natCast_ne_top 0 @[simp] theorem one_ne_top : (1 : PartENat) ≠ ⊤ := natCast_ne_top 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_ne_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) ≠ ⊤ := natCast_ne_top x theorem not_isMax_natCast (x : ℕ) : ¬IsMax (x : PartENat) := not_isMax_of_lt (natCast_lt_top x) #align part_enat.not_is_max_coe PartENat.not_isMax_natCast theorem ne_top_iff {x : PartENat} : x ≠ ⊤ ↔ ∃ n : ℕ, x = n := by simpa only [← some_eq_natCast] using Part.ne_none_iff #align part_enat.ne_top_iff PartENat.ne_top_iff theorem ne_top_iff_dom {x : PartENat} : x ≠ ⊤ ↔ x.Dom := by classical exact not_iff_comm.1 Part.eq_none_iff'.symm #align part_enat.ne_top_iff_dom PartENat.ne_top_iff_dom theorem not_dom_iff_eq_top {x : PartENat} : ¬x.Dom ↔ x = ⊤ := Iff.not_left ne_top_iff_dom.symm #align part_enat.not_dom_iff_eq_top PartENat.not_dom_iff_eq_top theorem ne_top_of_lt {x y : PartENat} (h : x < y) : x ≠ ⊤ := ne_of_lt <| lt_of_lt_of_le h le_top #align part_enat.ne_top_of_lt PartENat.ne_top_of_lt theorem eq_top_iff_forall_lt (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) < x := by constructor · rintro rfl n exact natCast_lt_top _ · contrapose! rw [ne_top_iff] rintro ⟨n, rfl⟩ exact ⟨n, irrefl _⟩ #align part_enat.eq_top_iff_forall_lt PartENat.eq_top_iff_forall_lt theorem eq_top_iff_forall_le (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) ≤ x := (eq_top_iff_forall_lt x).trans ⟨fun h n => (h n).le, fun h n => lt_of_lt_of_le (coe_lt_coe.mpr n.lt_succ_self) (h (n + 1))⟩ #align part_enat.eq_top_iff_forall_le PartENat.eq_top_iff_forall_le theorem pos_iff_one_le {x : PartENat} : 0 < x ↔ 1 ≤ x := PartENat.casesOn x (by simp only [iff_true_iff, le_top, natCast_lt_top, ← @Nat.cast_zero PartENat]) fun n => by rw [← Nat.cast_zero, ← Nat.cast_one, PartENat.coe_lt_coe, PartENat.coe_le_coe] rfl #align part_enat.pos_iff_one_le PartENat.pos_iff_one_le instance isTotal : IsTotal PartENat (· ≤ ·) where total x y := PartENat.casesOn (P := fun z => z ≤ y ∨ y ≤ z) x (Or.inr le_top) (PartENat.casesOn y (fun _ => Or.inl le_top) fun x y => (le_total x y).elim (Or.inr ∘ coe_le_coe.2) (Or.inl ∘ coe_le_coe.2)) noncomputable instance linearOrder : LinearOrder PartENat := { PartENat.partialOrder with le_total := IsTotal.total decidableLE := Classical.decRel _ max := (· ⊔ ·) -- Porting note: was `max_def := @sup_eq_maxDefault _ _ (id _) _ }` max_def := fun a b => by change (fun a b => a ⊔ b) a b = _ rw [@sup_eq_maxDefault PartENat _ (id _) _] rfl } instance boundedOrder : BoundedOrder PartENat := { PartENat.orderTop, PartENat.orderBot with } noncomputable instance lattice : Lattice PartENat := { PartENat.semilatticeSup with inf := min inf_le_left := min_le_left inf_le_right := min_le_right le_inf := fun _ _ _ => le_min } noncomputable instance : CanonicallyOrderedAddCommMonoid PartENat := { PartENat.semilatticeSup, PartENat.orderBot, PartENat.orderedAddCommMonoid with le_self_add := fun a b => PartENat.casesOn b (le_top.trans_eq (add_top _).symm) fun b => PartENat.casesOn a (top_add _).ge fun a => (coe_le_coe.2 le_self_add).trans_eq (Nat.cast_add _ _) exists_add_of_le := fun {a b} => PartENat.casesOn b (fun _ => ⟨⊤, (add_top _).symm⟩) fun b => PartENat.casesOn a (fun h => ((natCast_lt_top _).not_le h).elim) fun a h => ⟨(b - a : ℕ), by rw [← Nat.cast_add, natCast_inj, add_comm, tsub_add_cancel_of_le (coe_le_coe.1 h)]⟩ } theorem eq_natCast_sub_of_add_eq_natCast {x y : PartENat} {n : ℕ} (h : x + y = n) : x = ↑(n - y.get (dom_of_le_natCast ((le_add_left le_rfl).trans_eq h))) := by lift x to ℕ using dom_of_le_natCast ((le_add_right le_rfl).trans_eq h) lift y to ℕ using dom_of_le_natCast ((le_add_left le_rfl).trans_eq h) rw [← Nat.cast_add, natCast_inj] at h rw [get_natCast, natCast_inj, eq_tsub_of_add_eq h] #align part_enat.eq_coe_sub_of_add_eq_coe PartENat.eq_natCast_sub_of_add_eq_natCast protected theorem add_lt_add_right {x y z : PartENat} (h : x < y) (hz : z ≠ ⊤) : x + z < y + z := by rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ rcases ne_top_iff.mp hz with ⟨k, rfl⟩ induction' y using PartENat.casesOn with n · rw [top_add] -- Porting note: was apply_mod_cast natCast_lt_top norm_cast; apply natCast_lt_top norm_cast at h -- Porting note: was `apply_mod_cast add_lt_add_right h` norm_cast; apply add_lt_add_right h #align part_enat.add_lt_add_right PartENat.add_lt_add_right protected theorem add_lt_add_iff_right {x y z : PartENat} (hz : z ≠ ⊤) : x + z < y + z ↔ x < y := ⟨lt_of_add_lt_add_right, fun h => PartENat.add_lt_add_right h hz⟩ #align part_enat.add_lt_add_iff_right PartENat.add_lt_add_iff_right protected theorem add_lt_add_iff_left {x y z : PartENat} (hz : z ≠ ⊤) : z + x < z + y ↔ x < y := by rw [add_comm z, add_comm z, PartENat.add_lt_add_iff_right hz] #align part_enat.add_lt_add_iff_left PartENat.add_lt_add_iff_left protected theorem lt_add_iff_pos_right {x y : PartENat} (hx : x ≠ ⊤) : x < x + y ↔ 0 < y := by conv_rhs => rw [← PartENat.add_lt_add_iff_left hx] rw [add_zero] #align part_enat.lt_add_iff_pos_right PartENat.lt_add_iff_pos_right theorem lt_add_one {x : PartENat} (hx : x ≠ ⊤) : x < x + 1 := by rw [PartENat.lt_add_iff_pos_right hx] norm_cast #align part_enat.lt_add_one PartENat.lt_add_one theorem le_of_lt_add_one {x y : PartENat} (h : x < y + 1) : x ≤ y := by induction' y using PartENat.casesOn with n · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ -- Porting note: was `apply_mod_cast Nat.le_of_lt_succ; apply_mod_cast h` norm_cast; apply Nat.le_of_lt_succ; norm_cast at h #align part_enat.le_of_lt_add_one PartENat.le_of_lt_add_one theorem add_one_le_of_lt {x y : PartENat} (h : x < y) : x + 1 ≤ y := by induction' y using PartENat.casesOn with n · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ -- Porting note: was `apply_mod_cast Nat.succ_le_of_lt; apply_mod_cast h` norm_cast; apply Nat.succ_le_of_lt; norm_cast at h #align part_enat.add_one_le_of_lt PartENat.add_one_le_of_lt theorem add_one_le_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x + 1 ≤ y ↔ x < y := by refine ⟨fun h => ?_, add_one_le_of_lt⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction' y using PartENat.casesOn with n · apply natCast_lt_top -- Porting note: was `apply_mod_cast Nat.lt_of_succ_le; apply_mod_cast h` norm_cast; apply Nat.lt_of_succ_le; norm_cast at h #align part_enat.add_one_le_iff_lt PartENat.add_one_le_iff_lt theorem coe_succ_le_iff {n : ℕ} {e : PartENat} : ↑n.succ ≤ e ↔ ↑n < e := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, add_one_le_iff_lt (natCast_ne_top n)] #align part_enat.coe_succ_le_succ_iff PartENat.coe_succ_le_iff theorem lt_add_one_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x < y + 1 ↔ x ≤ y := by refine ⟨le_of_lt_add_one, fun h => ?_⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction' y using PartENat.casesOn with n · rw [top_add] apply natCast_lt_top -- Porting note: was `apply_mod_cast Nat.lt_succ_of_le; apply_mod_cast h` norm_cast; apply Nat.lt_succ_of_le; norm_cast at h #align part_enat.lt_add_one_iff_lt PartENat.lt_add_one_iff_lt lemma lt_coe_succ_iff_le {x : PartENat} {n : ℕ} (hx : x ≠ ⊤) : x < n.succ ↔ x ≤ n := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, lt_add_one_iff_lt hx] #align part_enat.lt_coe_succ_iff_le PartENat.lt_coe_succ_iff_le theorem add_eq_top_iff {a b : PartENat} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [top_add, add_top] simp only [← Nat.cast_add, PartENat.natCast_ne_top, forall_const, not_false_eq_true] #align part_enat.add_eq_top_iff PartENat.add_eq_top_iff protected theorem add_right_cancel_iff {a b c : PartENat} (hc : c ≠ ⊤) : a + c = b + c ↔ a = b := by rcases ne_top_iff.1 hc with ⟨c, rfl⟩ refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat), top_add] simp only [← Nat.cast_add, add_left_cancel_iff, PartENat.natCast_inj, add_comm, forall_const] #align part_enat.add_right_cancel_iff PartENat.add_right_cancel_iff protected theorem add_left_cancel_iff {a b c : PartENat} (ha : a ≠ ⊤) : a + b = a + c ↔ b = c := by rw [add_comm a, add_comm a, PartENat.add_right_cancel_iff ha] #align part_enat.add_left_cancel_iff PartENat.add_left_cancel_iff section WithTop /-- Computably converts a `PartENat` to a `ℕ∞`. -/ def toWithTop (x : PartENat) [Decidable x.Dom] : ℕ∞ := x.toOption #align part_enat.to_with_top PartENat.toWithTop theorem toWithTop_top : have : Decidable (⊤ : PartENat).Dom := Part.noneDecidable toWithTop ⊤ = ⊤ := rfl #align part_enat.to_with_top_top PartENat.toWithTop_top @[simp] theorem toWithTop_top' {h : Decidable (⊤ : PartENat).Dom} : toWithTop ⊤ = ⊤ := by convert toWithTop_top #align part_enat.to_with_top_top' PartENat.toWithTop_top' theorem toWithTop_zero : have : Decidable (0 : PartENat).Dom := someDecidable 0 toWithTop 0 = 0 := rfl #align part_enat.to_with_top_zero PartENat.toWithTop_zero @[simp] theorem toWithTop_zero' {h : Decidable (0 : PartENat).Dom} : toWithTop 0 = 0 := by convert toWithTop_zero #align part_enat.to_with_top_zero' PartENat.toWithTop_zero' theorem toWithTop_one : have : Decidable (1 : PartENat).Dom := someDecidable 1 toWithTop 1 = 1 := rfl @[simp] theorem toWithTop_one' {h : Decidable (1 : PartENat).Dom} : toWithTop 1 = 1 := by convert toWithTop_one theorem toWithTop_some (n : ℕ) : toWithTop (some n) = n := rfl #align part_enat.to_with_top_some PartENat.toWithTop_some theorem toWithTop_natCast (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop n = n := by simp only [← toWithTop_some] congr #align part_enat.to_with_top_coe PartENat.toWithTop_natCast @[simp]
Mathlib/Data/Nat/PartENat.lean
628
630
theorem toWithTop_natCast' (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop (n : PartENat) = n := by
rw [toWithTop_natCast n]
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic #align_import order.symm_diff from "leanprover-community/mathlib"@"6eb334bd8f3433d5b08ba156b8ec3e6af47e1904" /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a ∆ b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ open Function OrderDual variable {ι α β : Type*} {π : ι → Type*} /-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/ def symmDiff [Sup α] [SDiff α] (a b : α) : α := a \ b ⊔ b \ a #align symm_diff symmDiff /-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Inf α] [HImp α] (a b : α) : α := (b ⇨ a) ⊓ (a ⇨ b) #align bihimp bihimp /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " ∆ " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Sup α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a := rfl #align symm_diff_def symmDiff_def theorem bihimp_def [Inf α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) := rfl #align bihimp_def bihimp_def theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q := rfl #align symm_diff_eq_xor symmDiff_eq_Xor' @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := (iff_iff_implies_and_implies _ _).symm.trans Iff.comm #align bihimp_iff_iff bihimp_iff_iff @[simp] theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide #align bool.symm_diff_eq_bxor Bool.symmDiff_eq_xor section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] (a b c d : α) @[simp] theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b := rfl #align to_dual_symm_diff toDual_symmDiff @[simp] theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b := rfl #align of_dual_bihimp ofDual_bihimp theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm] #align symm_diff_comm symmDiff_comm instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) := ⟨symmDiff_comm⟩ #align symm_diff_is_comm symmDiff_isCommutative @[simp] theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self] #align symm_diff_self symmDiff_self @[simp] theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] #align symm_diff_bot symmDiff_bot @[simp] theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot] #align bot_symm_diff bot_symmDiff @[simp] theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] #align symm_diff_eq_bot symmDiff_eq_bot theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] #align symm_diff_of_le symmDiff_of_le theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] #align symm_diff_of_ge symmDiff_of_ge theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb #align symm_diff_le symmDiff_le theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] #align symm_diff_le_iff symmDiff_le_iff @[simp] theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b := sup_le_sup sdiff_le sdiff_le #align symm_diff_le_sup symmDiff_le_sup theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff] #align symm_diff_eq_sup_sdiff_inf symmDiff_eq_sup_sdiff_inf theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] #align disjoint.symm_diff_eq_sup Disjoint.symmDiff_eq_sup theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] #align symm_diff_sdiff symmDiff_sdiff @[simp] theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by rw [symmDiff_sdiff] simp [symmDiff] #align symm_diff_sdiff_inf symmDiff_sdiff_inf @[simp] theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) #align symm_diff_sdiff_eq_sup symmDiff_sdiff_eq_sup @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] #align sdiff_symm_diff_eq_sup sdiff_symmDiff_eq_sup @[simp] theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) · rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup · rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup #align symm_diff_sup_inf symmDiff_sup_inf @[simp] theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf] #align inf_sup_symm_diff inf_sup_symmDiff @[simp] theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] #align symm_diff_symm_diff_inf symmDiff_symmDiff_inf @[simp] theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] #align inf_symm_diff_symm_diff inf_symmDiff_symmDiff theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] #align symm_diff_triangle symmDiff_triangle
Mathlib/Order/SymmDiff.lean
218
219
theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by
convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot]
/- 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.Order.MinMax import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.Says #align_import data.set.intervals.basic from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # 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]`. This file contains these definitions, and basic facts on inclusion, intersection, difference of intervals (where the precise statements may depend on the properties of the order, in particular for some statements it should be `LinearOrder` or `DenselyOrdered`). TODO: This is just the beginning; a lot of rules are missing -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} /-- Left-open right-open interval -/ def Ioo (a b : α) := { x | a < x ∧ x < b } #align set.Ioo Set.Ioo /-- Left-closed right-open interval -/ def Ico (a b : α) := { x | a ≤ x ∧ x < b } #align set.Ico Set.Ico /-- Left-infinite right-open interval -/ def Iio (a : α) := { x | x < a } #align set.Iio Set.Iio /-- Left-closed right-closed interval -/ def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b } #align set.Icc Set.Icc /-- Left-infinite right-closed interval -/ def Iic (b : α) := { x | x ≤ b } #align set.Iic Set.Iic /-- Left-open right-closed interval -/ def Ioc (a b : α) := { x | a < x ∧ x ≤ b } #align set.Ioc Set.Ioc /-- Left-closed right-infinite interval -/ def Ici (a : α) := { x | a ≤ x } #align set.Ici Set.Ici /-- Left-open right-infinite interval -/ def Ioi (a : α) := { x | a < x } #align set.Ioi Set.Ioi theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl #align set.Ioo_def Set.Ioo_def theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl #align set.Ico_def Set.Ico_def theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl #align set.Iio_def Set.Iio_def theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl #align set.Icc_def Set.Icc_def theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl #align set.Iic_def Set.Iic_def theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl #align set.Ioc_def Set.Ioc_def theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl #align set.Ici_def Set.Ici_def theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl #align set.Ioi_def Set.Ioi_def @[simp] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl #align set.mem_Ioo Set.mem_Ioo @[simp] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl #align set.mem_Ico Set.mem_Ico @[simp] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl #align set.mem_Iio Set.mem_Iio @[simp] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl #align set.mem_Icc Set.mem_Icc @[simp] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl #align set.mem_Iic Set.mem_Iic @[simp] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl #align set.mem_Ioc Set.mem_Ioc @[simp] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl #align set.mem_Ici Set.mem_Ici @[simp] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl #align set.mem_Ioi Set.mem_Ioi instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption #align set.decidable_mem_Ioo Set.decidableMemIoo instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption #align set.decidable_mem_Ico Set.decidableMemIco instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption #align set.decidable_mem_Iio Set.decidableMemIio instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption #align set.decidable_mem_Icc Set.decidableMemIcc instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption #align set.decidable_mem_Iic Set.decidableMemIic instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption #align set.decidable_mem_Ioc Set.decidableMemIoc instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption #align set.decidable_mem_Ici Set.decidableMemIci instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption #align set.decidable_mem_Ioi Set.decidableMemIoi -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioo Set.left_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] #align set.left_mem_Ico Set.left_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.left_mem_Icc Set.left_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioc Set.left_mem_Ioc theorem left_mem_Ici : a ∈ Ici a := by simp #align set.left_mem_Ici Set.left_mem_Ici -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ioo Set.right_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ico Set.right_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.right_mem_Icc Set.right_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] #align set.right_mem_Ioc Set.right_mem_Ioc theorem right_mem_Iic : a ∈ Iic a := by simp #align set.right_mem_Iic Set.right_mem_Iic @[simp] theorem dual_Ici : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl #align set.dual_Ici Set.dual_Ici @[simp] theorem dual_Iic : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl #align set.dual_Iic Set.dual_Iic @[simp] theorem dual_Ioi : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl #align set.dual_Ioi Set.dual_Ioi @[simp] theorem dual_Iio : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl #align set.dual_Iio Set.dual_Iio @[simp] theorem dual_Icc : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm #align set.dual_Icc Set.dual_Icc @[simp] theorem dual_Ioc : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm #align set.dual_Ioc Set.dual_Ioc @[simp] theorem dual_Ico : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm #align set.dual_Ico Set.dual_Ico @[simp] theorem dual_Ioo : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm #align set.dual_Ioo Set.dual_Ioo @[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⟩⟩ #align set.nonempty_Icc Set.nonempty_Icc @[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⟩⟩ #align set.nonempty_Ico Set.nonempty_Ico @[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⟩⟩ #align set.nonempty_Ioc Set.nonempty_Ioc @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ #align set.nonempty_Ici Set.nonempty_Ici @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ #align set.nonempty_Iic Set.nonempty_Iic @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ #align set.nonempty_Ioo Set.nonempty_Ioo @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a #align set.nonempty_Ioi Set.nonempty_Ioi @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a #align set.nonempty_Iio Set.nonempty_Iio theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) #align set.nonempty_Icc_subtype Set.nonempty_Icc_subtype theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) #align set.nonempty_Ico_subtype Set.nonempty_Ico_subtype theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) #align set.nonempty_Ioc_subtype Set.nonempty_Ioc_subtype /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici #align set.nonempty_Ici_subtype Set.nonempty_Ici_subtype /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic #align set.nonempty_Iic_subtype Set.nonempty_Iic_subtype theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) #align set.nonempty_Ioo_subtype Set.nonempty_Ioo_subtype /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi #align set.nonempty_Ioi_subtype Set.nonempty_Ioi_subtype /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio #align set.nonempty_Iio_subtype Set.nonempty_Iio_subtype instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Icc_eq_empty Set.Icc_eq_empty @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) #align set.Ico_eq_empty Set.Ico_eq_empty @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) #align set.Ioc_eq_empty Set.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Ioo_eq_empty Set.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align set.Icc_eq_empty_of_lt Set.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align set.Ico_eq_empty_of_le Set.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align set.Ioc_eq_empty_of_le Set.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align set.Ioo_eq_empty_of_le Set.Ioo_eq_empty_of_le -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align set.Ico_self Set.Ico_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align set.Ioc_self Set.Ioc_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align set.Ioo_self Set.Ioo_self theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ #align set.Ici_subset_Ici Set.Ici_subset_Ici @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ #align set.Iic_subset_Iic Set.Iic_subset_Iic @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ #align set.Ici_subset_Ioi Set.Ici_subset_Ioi theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ #align set.Iic_subset_Iio Set.Iic_subset_Iio @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ #align set.Ioo_subset_Ioo Set.Ioo_subset_Ioo @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align set.Ioo_subset_Ioo_left Set.Ioo_subset_Ioo_left @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align set.Ioo_subset_Ioo_right Set.Ioo_subset_Ioo_right @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ #align set.Ico_subset_Ico Set.Ico_subset_Ico @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align set.Ico_subset_Ico_left Set.Ico_subset_Ico_left @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align set.Ico_subset_Ico_right Set.Ico_subset_Ico_right @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ #align set.Icc_subset_Icc Set.Icc_subset_Icc @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align set.Icc_subset_Icc_left Set.Icc_subset_Icc_left @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align set.Icc_subset_Icc_right Set.Icc_subset_Icc_right theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ #align set.Icc_subset_Ioo Set.Icc_subset_Ioo theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left #align set.Icc_subset_Ici_self Set.Icc_subset_Ici_self theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right #align set.Icc_subset_Iic_self Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right #align set.Ioc_subset_Iic_self Set.Ioc_subset_Iic_self @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ #align set.Ioc_subset_Ioc Set.Ioc_subset_Ioc @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align set.Ioc_subset_Ioc_left Set.Ioc_subset_Ioc_left @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align set.Ioc_subset_Ioc_right Set.Ioc_subset_Ioc_right theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le #align set.Ico_subset_Ioo_left Set.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h #align set.Ioc_subset_Ioo_right Set.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ #align set.Icc_subset_Ico_right Set.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt #align set.Ioo_subset_Ico_self Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt #align set.Ioo_subset_Ioc_self Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt #align set.Ico_subset_Icc_self Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt #align set.Ioc_subset_Icc_self Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self #align set.Ioo_subset_Icc_self Set.Ioo_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right #align set.Ico_subset_Iio_self Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right #align set.Ioo_subset_Iio_self Set.Ioo_subset_Iio_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left #align set.Ioc_subset_Ioi_self Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left #align set.Ioo_subset_Ioi_self Set.Ioo_subset_Ioi_self theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx #align set.Ioi_subset_Ici_self Set.Ioi_subset_Ici_self theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx #align set.Iio_subset_Iic_self Set.Iio_subset_Iic_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left #align set.Ico_subset_Ici_self Set.Ico_subset_Ici_self theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ #align set.Ioi_ssubset_Ici_self Set.Ioi_ssubset_Ici_self theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ #align set.Iio_ssubset_Iic_self Set.Iio_ssubset_Iic_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Icc_iff Set.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ioo_iff Set.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ico_iff Set.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Ioc_iff Set.Icc_subset_Ioc_iff theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ #align set.Icc_subset_Iio_iff Set.Icc_subset_Iio_iff theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ #align set.Icc_subset_Ioi_iff Set.Icc_subset_Ioi_iff theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ #align set.Icc_subset_Iic_iff Set.Icc_subset_Iic_iff theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ #align set.Icc_subset_Ici_iff Set.Icc_subset_Ici_iff theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ #align set.Icc_ssubset_Icc_left Set.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ #align set.Icc_ssubset_Icc_right Set.Icc_ssubset_Icc_right /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx #align set.Ioi_subset_Ioi Set.Ioi_subset_Ioi /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self #align set.Ioi_subset_Ici Set.Ioi_subset_Ici /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h #align set.Iio_subset_Iio Set.Iio_subset_Iio /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self #align set.Iio_subset_Iic Set.Iio_subset_Iic theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl #align set.Ici_inter_Iic Set.Ici_inter_Iic theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl #align set.Ici_inter_Iio Set.Ici_inter_Iio theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl #align set.Ioi_inter_Iic Set.Ioi_inter_Iic theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl #align set.Ioi_inter_Iio Set.Ioi_inter_Iio theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ #align set.Iic_inter_Ici Set.Iic_inter_Ici theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ #align set.Iio_inter_Ici Set.Iio_inter_Ici theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ #align set.Iic_inter_Ioi Set.Iic_inter_Ioi theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ #align set.Iio_inter_Ioi Set.Iio_inter_Ioi theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h #align set.mem_Icc_of_Ioo Set.mem_Icc_of_Ioo theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h #align set.mem_Ico_of_Ioo Set.mem_Ico_of_Ioo theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h #align set.mem_Ioc_of_Ioo Set.mem_Ioc_of_Ioo theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h #align set.mem_Icc_of_Ico Set.mem_Icc_of_Ico theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h #align set.mem_Icc_of_Ioc Set.mem_Icc_of_Ioc theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h #align set.mem_Ici_of_Ioi Set.mem_Ici_of_Ioi theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h #align set.mem_Iic_of_Iio Set.mem_Iic_of_Iio theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] #align set.Icc_eq_empty_iff Set.Icc_eq_empty_iff theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] #align set.Ico_eq_empty_iff Set.Ico_eq_empty_iff theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] #align set.Ioc_eq_empty_iff Set.Ioc_eq_empty_iff theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] #align set.Ioo_eq_empty_iff Set.Ioo_eq_empty_iff theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h #align is_top.Iic_eq IsTop.Iic_eq theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h #align is_bot.Ici_eq IsBot.Ici_eq theorem _root_.IsMax.Ioi_eq (h : IsMax a) : Ioi a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_max.Ioi_eq IsMax.Ioi_eq theorem _root_.IsMin.Iio_eq (h : IsMin a) : Iio a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_min.Iio_eq IsMin.Iio_eq theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ #align set.Iic_inter_Ioc_of_le Set.Iic_inter_Ioc_of_le theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1 #align set.not_mem_Icc_of_lt Set.not_mem_Icc_of_lt theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2 #align set.not_mem_Icc_of_gt Set.not_mem_Icc_of_gt theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1 #align set.not_mem_Ico_of_lt Set.not_mem_Ico_of_lt theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2 #align set.not_mem_Ioc_of_gt Set.not_mem_Ioc_of_gt -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _ #align set.not_mem_Ioi_self Set.not_mem_Ioi_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _ #align set.not_mem_Iio_self Set.not_mem_Iio_self theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioc_of_le Set.not_mem_Ioc_of_le theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ico_of_ge Set.not_mem_Ico_of_ge theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioo_of_le Set.not_mem_Ioo_of_le theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ioo_of_ge Set.not_mem_Ioo_of_ge end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] #align set.Icc_self Set.Icc_self instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h.subst <| left_mem_Icc.2 hab, eq_of_mem_singleton <| h.subst <| right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ #align set.Icc_eq_singleton_iff Set.Icc_eq_singleton_iff lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) #align set.subsingleton_Icc_of_ge Set.subsingleton_Icc_of_ge @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [ge_iff_le, gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] #align set.Icc_diff_left Set.Icc_diff_left @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] #align set.Icc_diff_right Set.Icc_diff_right @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] #align set.Ico_diff_left Set.Ico_diff_left @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] #align set.Ioc_diff_right Set.Ioc_diff_right @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] #align set.Icc_diff_both Set.Icc_diff_both @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] #align set.Ici_diff_left Set.Ici_diff_left @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] #align set.Iic_diff_right Set.Iic_diff_right @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] #align set.Ico_diff_Ioo_same Set.Ico_diff_Ioo_same @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] #align set.Ioc_diff_Ioo_same Set.Ioc_diff_Ioo_same @[simp] theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] #align set.Icc_diff_Ico_same Set.Icc_diff_Ico_same @[simp] theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] #align set.Icc_diff_Ioc_same Set.Icc_diff_Ioc_same @[simp] theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h] #align set.Icc_diff_Ioo_same Set.Icc_diff_Ioo_same @[simp] theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)] #align set.Ici_diff_Ioi_same Set.Ici_diff_Ioi_same @[simp] theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)] #align set.Iic_diff_Iio_same Set.Iic_diff_Iio_same -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioi_union_left : Ioi a ∪ {a} = Ici a := ext fun x => by simp [eq_comm, le_iff_eq_or_lt] #align set.Ioi_union_left Set.Ioi_union_left -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Iio_union_right : Iio a ∪ {a} = Iic a := ext fun _ => le_iff_lt_or_eq.symm #align set.Iio_union_right Set.Iio_union_right theorem Ioo_union_left (hab : a < b) : Ioo a b ∪ {a} = Ico a b := by rw [← Ico_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)] #align set.Ioo_union_left Set.Ioo_union_left theorem Ioo_union_right (hab : a < b) : Ioo a b ∪ {b} = Ioc a b := by simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual #align set.Ioo_union_right Set.Ioo_union_right theorem Ioo_union_both (h : a ≤ b) : Ioo a b ∪ {a, b} = Icc a b := by have : (Icc a b \ {a, b}) ∪ {a, b} = Icc a b := diff_union_of_subset fun | x, .inl rfl => left_mem_Icc.mpr h | x, .inr rfl => right_mem_Icc.mpr h rw [← this, Icc_diff_both] theorem Ioc_union_left (hab : a ≤ b) : Ioc a b ∪ {a} = Icc a b := by rw [← Icc_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)] #align set.Ioc_union_left Set.Ioc_union_left theorem Ico_union_right (hab : a ≤ b) : Ico a b ∪ {b} = Icc a b := by simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual #align set.Ico_union_right Set.Ico_union_right @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [insert_eq, union_comm, Ico_union_right h] #align set.Ico_insert_right Set.Ico_insert_right @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [insert_eq, union_comm, Ioc_union_left h] #align set.Ioc_insert_left Set.Ioc_insert_left @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [insert_eq, union_comm, Ioo_union_left h] #align set.Ioo_insert_left Set.Ioo_insert_left @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [insert_eq, union_comm, Ioo_union_right h] #align set.Ioo_insert_right Set.Ioo_insert_right @[simp] theorem Iio_insert : insert a (Iio a) = Iic a := ext fun _ => le_iff_eq_or_lt.symm #align set.Iio_insert Set.Iio_insert @[simp] theorem Ioi_insert : insert a (Ioi a) = Ici a := ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm #align set.Ioi_insert Set.Ioi_insert theorem mem_Ici_Ioi_of_subset_of_subset {s : Set α} (ho : Ioi a ⊆ s) (hc : s ⊆ Ici a) : s ∈ ({Ici a, Ioi a} : Set (Set α)) := by_cases (fun h : a ∈ s => Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*]) fun h => Or.inr <| Subset.antisymm (fun x hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm ▸ hx) ho #align set.mem_Ici_Ioi_of_subset_of_subset Set.mem_Ici_Ioi_of_subset_of_subset theorem mem_Iic_Iio_of_subset_of_subset {s : Set α} (ho : Iio a ⊆ s) (hc : s ⊆ Iic a) : s ∈ ({Iic a, Iio a} : Set (Set α)) := @mem_Ici_Ioi_of_subset_of_subset αᵒᵈ _ a s ho hc #align set.mem_Iic_Iio_of_subset_of_subset Set.mem_Iic_Iio_of_subset_of_subset theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set α} (ho : Ioo a b ⊆ s) (hc : s ⊆ Icc a b) : s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set α)) := by classical by_cases ha : a ∈ s <;> by_cases hb : b ∈ s · refine Or.inl (Subset.antisymm hc ?_) rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_right] exact subset_diff_singleton hc hb · rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho · refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_left] exact subset_diff_singleton hc ha · rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho rw [← Ico_diff_left, ← Icc_diff_right] apply_rules [subset_diff_singleton] #align set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset Set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset theorem eq_left_or_mem_Ioo_of_mem_Ico {x : α} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => ⟨h, hmem.2⟩ #align set.eq_left_or_mem_Ioo_of_mem_Ico Set.eq_left_or_mem_Ioo_of_mem_Ico theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : α} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b := hmem.2.eq_or_lt.imp_right <| And.intro hmem.1 #align set.eq_right_or_mem_Ioo_of_mem_Ioc Set.eq_right_or_mem_Ioo_of_mem_Ioc theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : α} (hmem : x ∈ Icc a b) : x = a ∨ x = b ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩ #align set.eq_endpoints_or_mem_Ioo_of_mem_Icc Set.eq_endpoints_or_mem_Ioo_of_mem_Icc theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} := eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩ #align is_max.Ici_eq IsMax.Ici_eq theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} := h.toDual.Ici_eq #align is_min.Iic_eq IsMin.Iic_eq theorem Ici_injective : Injective (Ici : α → Set α) := fun _ _ => eq_of_forall_ge_iff ∘ Set.ext_iff.1 #align set.Ici_injective Set.Ici_injective theorem Iic_injective : Injective (Iic : α → Set α) := fun _ _ => eq_of_forall_le_iff ∘ Set.ext_iff.1 #align set.Iic_injective Set.Iic_injective theorem Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff #align set.Ici_inj Set.Ici_inj theorem Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff #align set.Iic_inj Set.Iic_inj end PartialOrder section OrderTop @[simp] theorem Ici_top [PartialOrder α] [OrderTop α] : Ici (⊤ : α) = {⊤} := isMax_top.Ici_eq #align set.Ici_top Set.Ici_top variable [Preorder α] [OrderTop α] {a : α} @[simp] theorem Ioi_top : Ioi (⊤ : α) = ∅ := isMax_top.Ioi_eq #align set.Ioi_top Set.Ioi_top @[simp] theorem Iic_top : Iic (⊤ : α) = univ := isTop_top.Iic_eq #align set.Iic_top Set.Iic_top @[simp] theorem Icc_top : Icc a ⊤ = Ici a := by simp [← Ici_inter_Iic] #align set.Icc_top Set.Icc_top @[simp] theorem Ioc_top : Ioc a ⊤ = Ioi a := by simp [← Ioi_inter_Iic] #align set.Ioc_top Set.Ioc_top end OrderTop section OrderBot @[simp] theorem Iic_bot [PartialOrder α] [OrderBot α] : Iic (⊥ : α) = {⊥} := isMin_bot.Iic_eq #align set.Iic_bot Set.Iic_bot variable [Preorder α] [OrderBot α] {a : α} @[simp] theorem Iio_bot : Iio (⊥ : α) = ∅ := isMin_bot.Iio_eq #align set.Iio_bot Set.Iio_bot @[simp] theorem Ici_bot : Ici (⊥ : α) = univ := isBot_bot.Ici_eq #align set.Ici_bot Set.Ici_bot @[simp] theorem Icc_bot : Icc ⊥ a = Iic a := by simp [← Ici_inter_Iic] #align set.Icc_bot Set.Icc_bot @[simp] theorem Ico_bot : Ico ⊥ a = Iio a := by simp [← Ici_inter_Iio] #align set.Ico_bot Set.Ico_bot end OrderBot theorem Icc_bot_top [PartialOrder α] [BoundedOrder α] : Icc (⊥ : α) ⊤ = univ := by simp #align set.Icc_bot_top Set.Icc_bot_top section LinearOrder variable [LinearOrder α] {a a₁ a₂ b b₁ b₂ c d : α} theorem not_mem_Ici : c ∉ Ici a ↔ c < a := not_le #align set.not_mem_Ici Set.not_mem_Ici theorem not_mem_Iic : c ∉ Iic b ↔ b < c := not_le #align set.not_mem_Iic Set.not_mem_Iic theorem not_mem_Ioi : c ∉ Ioi a ↔ c ≤ a := not_lt #align set.not_mem_Ioi Set.not_mem_Ioi theorem not_mem_Iio : c ∉ Iio b ↔ b ≤ c := not_lt #align set.not_mem_Iio Set.not_mem_Iio @[simp] theorem compl_Iic : (Iic a)ᶜ = Ioi a := ext fun _ => not_le #align set.compl_Iic Set.compl_Iic @[simp] theorem compl_Ici : (Ici a)ᶜ = Iio a := ext fun _ => not_le #align set.compl_Ici Set.compl_Ici @[simp] theorem compl_Iio : (Iio a)ᶜ = Ici a := ext fun _ => not_lt #align set.compl_Iio Set.compl_Iio @[simp] theorem compl_Ioi : (Ioi a)ᶜ = Iic a := ext fun _ => not_lt #align set.compl_Ioi Set.compl_Ioi @[simp] theorem Ici_diff_Ici : Ici a \ Ici b = Ico a b := by rw [diff_eq, compl_Ici, Ici_inter_Iio] #align set.Ici_diff_Ici Set.Ici_diff_Ici @[simp] theorem Ici_diff_Ioi : Ici a \ Ioi b = Icc a b := by rw [diff_eq, compl_Ioi, Ici_inter_Iic] #align set.Ici_diff_Ioi Set.Ici_diff_Ioi @[simp] theorem Ioi_diff_Ioi : Ioi a \ Ioi b = Ioc a b := by rw [diff_eq, compl_Ioi, Ioi_inter_Iic] #align set.Ioi_diff_Ioi Set.Ioi_diff_Ioi @[simp] theorem Ioi_diff_Ici : Ioi a \ Ici b = Ioo a b := by rw [diff_eq, compl_Ici, Ioi_inter_Iio] #align set.Ioi_diff_Ici Set.Ioi_diff_Ici @[simp] theorem Iic_diff_Iic : Iic b \ Iic a = Ioc a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic] #align set.Iic_diff_Iic Set.Iic_diff_Iic @[simp] theorem Iio_diff_Iic : Iio b \ Iic a = Ioo a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio] #align set.Iio_diff_Iic Set.Iio_diff_Iic @[simp] theorem Iic_diff_Iio : Iic b \ Iio a = Icc a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic] #align set.Iic_diff_Iio Set.Iic_diff_Iio @[simp] theorem Iio_diff_Iio : Iio b \ Iio a = Ico a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio] #align set.Iio_diff_Iio Set.Iio_diff_Iio theorem Ioi_injective : Injective (Ioi : α → Set α) := fun _ _ => eq_of_forall_gt_iff ∘ Set.ext_iff.1 #align set.Ioi_injective Set.Ioi_injective theorem Iio_injective : Injective (Iio : α → Set α) := fun _ _ => eq_of_forall_lt_iff ∘ Set.ext_iff.1 #align set.Iio_injective Set.Iio_injective theorem Ioi_inj : Ioi a = Ioi b ↔ a = b := Ioi_injective.eq_iff #align set.Ioi_inj Set.Ioi_inj theorem Iio_inj : Iio a = Iio b ↔ a = b := Iio_injective.eq_iff #align set.Iio_inj Set.Iio_inj theorem Ico_subset_Ico_iff (h₁ : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => have : a₂ ≤ a₁ ∧ a₁ < b₂ := h ⟨le_rfl, h₁⟩ ⟨this.1, le_of_not_lt fun h' => lt_irrefl b₂ (h ⟨this.2.le, h'⟩).2⟩, fun ⟨h₁, h₂⟩ => Ico_subset_Ico h₁ h₂⟩ #align set.Ico_subset_Ico_iff Set.Ico_subset_Ico_iff theorem Ioc_subset_Ioc_iff (h₁ : a₁ < b₁) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ b₁ ≤ b₂ ∧ a₂ ≤ a₁ := by convert @Ico_subset_Ico_iff αᵒᵈ _ b₁ b₂ a₁ a₂ h₁ using 2 <;> exact (@dual_Ico α _ _ _).symm #align set.Ioc_subset_Ioc_iff Set.Ioc_subset_Ioc_iff theorem Ioo_subset_Ioo_iff [DenselyOrdered α] (h₁ : a₁ < b₁) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => by rcases exists_between h₁ with ⟨x, xa, xb⟩ constructor <;> refine le_of_not_lt fun h' => ?_ · have ab := (h ⟨xa, xb⟩).1.trans xb exact lt_irrefl _ (h ⟨h', ab⟩).1 · have ab := xa.trans (h ⟨xa, xb⟩).2 exact lt_irrefl _ (h ⟨ab, h'⟩).2, fun ⟨h₁, h₂⟩ => Ioo_subset_Ioo h₁ h₂⟩ #align set.Ioo_subset_Ioo_iff Set.Ioo_subset_Ioo_iff theorem Ico_eq_Ico_iff (h : a₁ < b₁ ∨ a₂ < b₂) : Ico a₁ b₁ = Ico a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := ⟨fun e => by simp only [Subset.antisymm_iff] at e simp only [le_antisymm_iff] cases' h with h h <;> simp only [gt_iff_lt, not_lt, ge_iff_le, Ico_subset_Ico_iff h] at e <;> [ rcases e with ⟨⟨h₁, h₂⟩, e'⟩; rcases e with ⟨e', ⟨h₁, h₂⟩⟩ ] <;> -- Porting note: restore `tauto` have hab := (Ico_subset_Ico_iff <| h₁.trans_lt <| h.trans_le h₂).1 e' <;> [ exact ⟨⟨hab.left, h₁⟩, ⟨h₂, hab.right⟩⟩; exact ⟨⟨h₁, hab.left⟩, ⟨hab.right, h₂⟩⟩ ], fun ⟨h₁, h₂⟩ => by rw [h₁, h₂]⟩ #align set.Ico_eq_Ico_iff Set.Ico_eq_Ico_iff lemma Ici_eq_singleton_iff_isTop {x : α} : (Ici x = {x}) ↔ IsTop x := by refine ⟨fun h y ↦ ?_, fun h ↦ by ext y; simp [(h y).ge_iff_eq]⟩ by_contra! H have : y ∈ Ici x := H.le rw [h, mem_singleton_iff] at this exact lt_irrefl y (this.le.trans_lt H) open scoped Classical @[simp] theorem Ioi_subset_Ioi_iff : Ioi b ⊆ Ioi a ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Ioi_subset_Ioi h⟩ by_contra ba exact lt_irrefl _ (h (not_le.mp ba)) #align set.Ioi_subset_Ioi_iff Set.Ioi_subset_Ioi_iff @[simp] theorem Ioi_subset_Ici_iff [DenselyOrdered α] : Ioi b ⊆ Ici a ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Ioi_subset_Ici h⟩ by_contra ba obtain ⟨c, bc, ca⟩ : ∃ c, b < c ∧ c < a := exists_between (not_le.mp ba) exact lt_irrefl _ (ca.trans_le (h bc)) #align set.Ioi_subset_Ici_iff Set.Ioi_subset_Ici_iff @[simp] theorem Iio_subset_Iio_iff : Iio a ⊆ Iio b ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Iio_subset_Iio h⟩ by_contra ab exact lt_irrefl _ (h (not_le.mp ab)) #align set.Iio_subset_Iio_iff Set.Iio_subset_Iio_iff @[simp] theorem Iio_subset_Iic_iff [DenselyOrdered α] : Iio a ⊆ Iic b ↔ a ≤ b := by rw [← diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt] #align set.Iio_subset_Iic_iff Set.Iio_subset_Iic_iff /-! ### Unions of adjacent intervals -/ /-! #### Two infinite intervals -/ theorem Iic_union_Ioi_of_le (h : a ≤ b) : Iic b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.lt_or_le x).symm #align set.Iic_union_Ioi_of_le Set.Iic_union_Ioi_of_le theorem Iio_union_Ici_of_le (h : a ≤ b) : Iio b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.le_or_lt x).symm #align set.Iio_union_Ici_of_le Set.Iio_union_Ici_of_le theorem Iic_union_Ici_of_le (h : a ≤ b) : Iic b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.le_or_le x).symm #align set.Iic_union_Ici_of_le Set.Iic_union_Ici_of_le theorem Iio_union_Ioi_of_lt (h : a < b) : Iio b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.lt_or_lt x).symm #align set.Iio_union_Ioi_of_lt Set.Iio_union_Ioi_of_lt @[simp] theorem Iic_union_Ici : Iic a ∪ Ici a = univ := Iic_union_Ici_of_le le_rfl #align set.Iic_union_Ici Set.Iic_union_Ici @[simp] theorem Iio_union_Ici : Iio a ∪ Ici a = univ := Iio_union_Ici_of_le le_rfl #align set.Iio_union_Ici Set.Iio_union_Ici @[simp] theorem Iic_union_Ioi : Iic a ∪ Ioi a = univ := Iic_union_Ioi_of_le le_rfl #align set.Iic_union_Ioi Set.Iic_union_Ioi @[simp] theorem Iio_union_Ioi : Iio a ∪ Ioi a = {a}ᶜ := ext fun _ => lt_or_lt_iff_ne #align set.Iio_union_Ioi Set.Iio_union_Ioi /-! #### A finite and an infinite interval -/ theorem Ioo_union_Ioi' (h₁ : c < b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by ext1 x simp_rw [mem_union, mem_Ioo, mem_Ioi, min_lt_iff] by_cases hc : c < x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x < b := (le_of_not_gt hc).trans_lt h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ioo_union_Ioi' Set.Ioo_union_Ioi' theorem Ioo_union_Ioi (h : c < max a b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ioo_union_Ioi' h · rw [min_comm] simp [*, min_eq_left_of_lt] #align set.Ioo_union_Ioi Set.Ioo_union_Ioi theorem Ioi_subset_Ioo_union_Ici : Ioi a ⊆ Ioo a b ∪ Ici b := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ioi_subset_Ioo_union_Ici Set.Ioi_subset_Ioo_union_Ici @[simp] theorem Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b ∪ Ici b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioo_union_Ici #align set.Ioo_union_Ici_eq_Ioi Set.Ioo_union_Ici_eq_Ioi theorem Ici_subset_Ico_union_Ici : Ici a ⊆ Ico a b ∪ Ici b := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ici_subset_Ico_union_Ici Set.Ici_subset_Ico_union_Ici @[simp] theorem Ico_union_Ici_eq_Ici (h : a ≤ b) : Ico a b ∪ Ici b = Ici a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Ico_union_Ici #align set.Ico_union_Ici_eq_Ici Set.Ico_union_Ici_eq_Ici theorem Ico_union_Ici' (h₁ : c ≤ b) : Ico a b ∪ Ici c = Ici (min a c) := by ext1 x simp_rw [mem_union, mem_Ico, mem_Ici, min_le_iff] by_cases hc : c ≤ x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x < b := (lt_of_not_ge hc).trans_le h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ico_union_Ici' Set.Ico_union_Ici' theorem Ico_union_Ici (h : c ≤ max a b) : Ico a b ∪ Ici c = Ici (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ico_union_Ici' h · simp [*] #align set.Ico_union_Ici Set.Ico_union_Ici theorem Ioi_subset_Ioc_union_Ioi : Ioi a ⊆ Ioc a b ∪ Ioi b := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ioi_subset_Ioc_union_Ioi Set.Ioi_subset_Ioc_union_Ioi @[simp] theorem Ioc_union_Ioi_eq_Ioi (h : a ≤ b) : Ioc a b ∪ Ioi b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_lt) Ioi_subset_Ioc_union_Ioi #align set.Ioc_union_Ioi_eq_Ioi Set.Ioc_union_Ioi_eq_Ioi theorem Ioc_union_Ioi' (h₁ : c ≤ b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by ext1 x simp_rw [mem_union, mem_Ioc, mem_Ioi, min_lt_iff] by_cases hc : c < x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_gt hc).trans h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ioc_union_Ioi' Set.Ioc_union_Ioi'
Mathlib/Order/Interval/Set/Basic.lean
1,351
1,354
theorem Ioc_union_Ioi (h : c ≤ max a b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by
rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ioc_union_Ioi' h · simp [*]
/- 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 #align_import analysis.convex.gauge from "leanprover-community/mathlib"@"373b03b5b9d0486534edbe94747f23cb3712f93d" /-! # 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 F : 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 } #align gauge gauge variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl #align gauge_def gauge_def /-- 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' _ _ #align gauge_def' gauge_def' 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⟩ #align absorbent.gauge_set_nonempty Absorbent.gauge_set_nonempty 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⟩ #align gauge_mono gauge_mono 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⟩ #align exists_lt_of_gauge_lt exists_lt_of_gauge_lt /-- 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] #align gauge_zero gauge_zero @[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 #align gauge_zero' gauge_zero' @[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] #align gauge_empty gauge_empty 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'] #align gauge_of_subset_zero gauge_of_subset_zero /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg _ fun _ hx => hx.1.le #align gauge_nonneg gauge_nonneg 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] #align gauge_neg gauge_neg theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] #align gauge_neg_set_neg gauge_neg_set_neg theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] #align gauge_neg_set_eq_gauge_neg gauge_neg_set_eq_gauge_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⟩ #align gauge_le_of_mem gauge_le_of_mem 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ε) _) #align gauge_le_eq gauge_le_eq 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₁⟩ #align gauge_lt_eq' gauge_lt_eq' 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₁⟩ #align gauge_lt_eq gauge_lt_eq 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 #align gauge_lt_one_subset_self gauge_lt_one_subset_self 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] #align gauge_le_one_of_mem gauge_le_one_of_mem /-- 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 #align gauge_add_le gauge_add_le theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem #align self_subset_gauge_le_one self_subset_gauge_le_one 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 _ · -- Porting note: `convert` needed help convert convex_empty (𝕜 := ℝ) (E := E) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx #align convex.gauge_le Convex.gauge_le theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun x hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) #align balanced.star_convex Balanced.starConvex 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'] #align le_gauge_of_not_mem le_gauge_of_not_mem 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] #align one_le_gauge_of_not_mem one_le_gauge_of_not_mem section LinearOrderedField variable {α : Type*} [LinearOrderedField α] [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 #align gauge_smul_of_nonneg gauge_smul_of_nonneg 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] #align gauge_smul_left_of_nonneg gauge_smul_left_of_nonneg 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 #align gauge_smul_left gauge_smul_left 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] #align gauge_norm_smul gauge_norm_smul /-- 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] #align gauge_smul gauge_smul 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 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_sub_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_nhdsWithin_Iio' one_pos] intro 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₁ #align interior_subset_gauge_lt_one interior_subset_gauge_lt_one 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 #align gauge_lt_one_eq_self_of_open gauge_lt_one_eq_self_of_isOpen -- Porting note: droped unneeded assumptions 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] #align gauge_lt_one_of_mem_of_open gauge_lt_one_of_mem_of_isOpenₓ -- Porting note: droped unneeded assumptions
Mathlib/Analysis/Convex/Gauge.lean
404
409
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
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.GaloisConnection import Mathlib.Data.Set.Lattice import Mathlib.Tactic.AdaptationNote #align_import data.rel from "leanprover-community/mathlib"@"706d88f2b8fdfeb0b22796433d7a6c1a010af9f2" /-! # Relations This file defines bundled relations. A relation between `α` and `β` is a function `α → β → Prop`. Relations are also known as set-valued functions, or partial multifunctions. ## Main declarations * `Rel α β`: Relation between `α` and `β`. * `Rel.inv`: `r.inv` is the `Rel β α` obtained by swapping the arguments of `r`. * `Rel.dom`: Domain of a relation. `x ∈ r.dom` iff there exists `y` such that `r x y`. * `Rel.codom`: Codomain, aka range, of a relation. `y ∈ r.codom` iff there exists `x` such that `r x y`. * `Rel.comp`: Relation composition. Note that the arguments order follows the `CategoryTheory/` one, so `r.comp s x z ↔ ∃ y, r x y ∧ s y z`. * `Rel.image`: Image of a set under a relation. `r.image s` is the set of `f x` over all `x ∈ s`. * `Rel.preimage`: Preimage of a set under a relation. Note that `r.preimage = r.inv.image`. * `Rel.core`: Core of a set. For `s : Set β`, `r.core s` is the set of `x : α` such that all `y` related to `x` are in `s`. * `Rel.restrict_domain`: Domain-restriction of a relation to a subtype. * `Function.graph`: Graph of a function as a relation. ## TODOs The `Rel.comp` function uses the notation `r • s`, rather than the more common `r ∘ s` for things named `comp`. This is because the latter is already used for function composition, and causes a clash. A better notation should be found, perhaps a variant of `r ∘r s` or `r; s`. -/ variable {α β γ : Type*} /-- A relation on `α` and `β`, aka a set-valued function, aka a partial multifunction -/ def Rel (α β : Type*) := α → β → Prop -- deriving CompleteLattice, Inhabited #align rel Rel -- Porting note: `deriving` above doesn't work. instance : CompleteLattice (Rel α β) := show CompleteLattice (α → β → Prop) from inferInstance instance : Inhabited (Rel α β) := show Inhabited (α → β → Prop) from inferInstance namespace Rel variable (r : Rel α β) -- Porting note: required for later theorems. @[ext] theorem ext {r s : Rel α β} : (∀ a, r a = s a) → r = s := funext /-- The inverse relation : `r.inv x y ↔ r y x`. Note that this is *not* a groupoid inverse. -/ def inv : Rel β α := flip r #align rel.inv Rel.inv theorem inv_def (x : α) (y : β) : r.inv y x ↔ r x y := Iff.rfl #align rel.inv_def Rel.inv_def theorem inv_inv : inv (inv r) = r := by ext x y rfl #align rel.inv_inv Rel.inv_inv /-- Domain of a relation -/ def dom := { x | ∃ y, r x y } #align rel.dom Rel.dom theorem dom_mono {r s : Rel α β} (h : r ≤ s) : dom r ⊆ dom s := fun a ⟨b, hx⟩ => ⟨b, h a b hx⟩ #align rel.dom_mono Rel.dom_mono /-- Codomain aka range of a relation -/ def codom := { y | ∃ x, r x y } #align rel.codom Rel.codom theorem codom_inv : r.inv.codom = r.dom := by ext x rfl #align rel.codom_inv Rel.codom_inv theorem dom_inv : r.inv.dom = r.codom := by ext x rfl #align rel.dom_inv Rel.dom_inv /-- Composition of relation; note that it follows the `CategoryTheory/` order of arguments. -/ def comp (r : Rel α β) (s : Rel β γ) : Rel α γ := fun x z => ∃ y, r x y ∧ s y z #align rel.comp Rel.comp -- Porting note: the original `∘` syntax can't be overloaded here, lean considers it ambiguous. /-- Local syntax for composition of relations. -/ local infixr:90 " • " => Rel.comp theorem comp_assoc {δ : Type*} (r : Rel α β) (s : Rel β γ) (t : Rel γ δ) : (r • s) • t = r • (s • t) := by unfold comp; ext (x w); constructor · rintro ⟨z, ⟨y, rxy, syz⟩, tzw⟩; exact ⟨y, rxy, z, syz, tzw⟩ · rintro ⟨y, rxy, z, syz, tzw⟩; exact ⟨z, ⟨y, rxy, syz⟩, tzw⟩ #align rel.comp_assoc Rel.comp_assoc @[simp] theorem comp_right_id (r : Rel α β) : r • @Eq β = r := by unfold comp ext y simp #align rel.comp_right_id Rel.comp_right_id @[simp] theorem comp_left_id (r : Rel α β) : @Eq α • r = r := by unfold comp ext x simp #align rel.comp_left_id Rel.comp_left_id @[simp] theorem comp_right_bot (r : Rel α β) : r • (⊥ : Rel β γ) = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_left_bot (r : Rel α β) : (⊥ : Rel γ α) • r = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_right_top (r : Rel α β) : r • (⊤ : Rel β γ) = fun x _ ↦ x ∈ r.dom := by ext x z simp [comp, Top.top, dom] @[simp] theorem comp_left_top (r : Rel α β) : (⊤ : Rel γ α) • r = fun _ y ↦ y ∈ r.codom := by ext x z simp [comp, Top.top, codom] theorem inv_id : inv (@Eq α) = @Eq α := by ext x y constructor <;> apply Eq.symm #align rel.inv_id Rel.inv_id theorem inv_comp (r : Rel α β) (s : Rel β γ) : inv (r • s) = inv s • inv r := by ext x z simp [comp, inv, flip, and_comm] #align rel.inv_comp Rel.inv_comp @[simp]
Mathlib/Data/Rel.lean
156
158
theorem inv_bot : (⊥ : Rel α β).inv = (⊥ : Rel β α) := by
#adaptation_note /-- nightly-2024-03-16: simp was `simp [Bot.bot, inv, flip]` -/ simp [Bot.bot, inv, Function.flip_def]
/- Copyright (c) 2022 Dagur Tómas Ásgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Tómas Ásgeirsson, Leonardo de Moura -/ import Mathlib.Data.Set.Basic #align_import data.set.bool_indicator from "leanprover-community/mathlib"@"fc2ed6f838ce7c9b7c7171e58d78eaf7b438fb0e" /-! # Indicator function valued in bool See also `Set.indicator` and `Set.piecewise`. -/ open Bool namespace Set variable {α : Type*} (s : Set α) /-- `boolIndicator` maps `x` to `true` if `x ∈ s`, else to `false` -/ noncomputable def boolIndicator (x : α) := @ite _ (x ∈ s) (Classical.propDecidable _) true false #align set.bool_indicator Set.boolIndicator theorem mem_iff_boolIndicator (x : α) : x ∈ s ↔ s.boolIndicator x = true := by unfold boolIndicator split_ifs with h <;> simp [h] #align set.mem_iff_bool_indicator Set.mem_iff_boolIndicator
Mathlib/Data/Set/BoolIndicator.lean
32
34
theorem not_mem_iff_boolIndicator (x : α) : x ∉ s ↔ s.boolIndicator x = false := by
unfold boolIndicator split_ifs with h <;> simp [h]
/- Copyright (c) 2024 Etienne Marion. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Etienne Marion -/ import Mathlib.MeasureTheory.SetSemiring /-! # Algebra of sets in this file we define the notion of algebra of sets ang give its basic properties. An algebra of sets is a family of sets containing the empty set and closed by complement and binary union. It is therefore similar to a `σ`-algebra, except that it is not necessarily closed by countable unions. We also define the algebra of sets generated by a family of sets ang give its basic properties, and we prove that it is countable when it is generated by a countable family. We prove that the `σ`-algebra generated by a family of sets `𝒜` is the same as the one generated by the algebra of sets generated by `𝒜`. ## Main definitions * `MeasureTheory.IsSetAlgebra`: property of being an algebra of sets. * `MeasureTheory.generateSetAlgebra`: the algebra of sets generated by a family of sets. ## Main statements * `MeasureTheory.mem_generateSetAlgebra_elim`: If a set `s` belongs to the algebra of sets generated by `𝒜`, then it can be written as a finite union of finite intersections of sets which are in `𝒜` or have their complement in `𝒜`. * `MeasureTheory.countable_generateSetAlgebra`: If a family of sets is countable then so is the algebra of sets generated by it. ## References * <https://en.wikipedia.org/wiki/Field_of_sets> ## Tags algebra of sets, generated algebra of sets -/ open MeasurableSpace Set namespace MeasureTheory variable {α : Type*} {𝒜 : Set (Set α)} {s t : Set α} /-! ### Definition and basic properties of an algebra of sets -/ /-- An algebra of sets is a family of sets containing the empty set and closed by complement and union. Consequently it is also closed by difference (see `IsSetAlgebra.diff_mem`) and intersection (see `IsSetAlgebra.inter_mem`). -/ structure IsSetAlgebra (𝒜 : Set (Set α)) : Prop where empty_mem : ∅ ∈ 𝒜 compl_mem : ∀ ⦃s⦄, s ∈ 𝒜 → sᶜ ∈ 𝒜 union_mem : ∀ ⦃s t⦄, s ∈ 𝒜 → t ∈ 𝒜 → s ∪ t ∈ 𝒜 namespace IsSetAlgebra /-- An algebra of sets contains the whole set. -/ theorem univ_mem (h𝒜 : IsSetAlgebra 𝒜) : univ ∈ 𝒜 := compl_empty ▸ h𝒜.compl_mem h𝒜.empty_mem /-- An algebra of sets is closed by intersection. -/ theorem inter_mem (h𝒜 : IsSetAlgebra 𝒜) (s_mem : s ∈ 𝒜) (t_mem : t ∈ 𝒜) : s ∩ t ∈ 𝒜 := inter_eq_compl_compl_union_compl .. ▸ h𝒜.compl_mem (h𝒜.union_mem (h𝒜.compl_mem s_mem) (h𝒜.compl_mem t_mem)) /-- An algebra of sets is closed by difference. -/ theorem diff_mem (h𝒜 : IsSetAlgebra 𝒜) (s_mem : s ∈ 𝒜) (t_mem : t ∈ 𝒜) : s \ t ∈ 𝒜 := h𝒜.inter_mem s_mem (h𝒜.compl_mem t_mem) /-- An algebra of sets is a ring of sets. -/ theorem isSetRing (h𝒜 : IsSetAlgebra 𝒜) : IsSetRing 𝒜 where empty_mem := h𝒜.empty_mem union_mem := h𝒜.union_mem diff_mem := fun _ _ ↦ h𝒜.diff_mem /-- An algebra of sets is closed by finite unions. -/ theorem biUnion_mem {ι : Type*} (h𝒜 : IsSetAlgebra 𝒜) {s : ι → Set α} (S : Finset ι) (hs : ∀ i ∈ S, s i ∈ 𝒜) : ⋃ i ∈ S, s i ∈ 𝒜 := h𝒜.isSetRing.biUnion_mem S hs /-- An algebra of sets is closed by finite intersections. -/ theorem biInter_mem {ι : Type*} (h𝒜 : IsSetAlgebra 𝒜) {s : ι → Set α} (S : Finset ι) (hs : ∀ i ∈ S, s i ∈ 𝒜) : ⋂ i ∈ S, s i ∈ 𝒜 := by by_cases h : S = ∅ · rw [h, ← Finset.set_biInter_coe, Finset.coe_empty, biInter_empty] exact h𝒜.univ_mem · rw [← ne_eq, ← Finset.nonempty_iff_ne_empty] at h exact h𝒜.isSetRing.biInter_mem S h hs end IsSetAlgebra section generateSetAlgebra /-! ### Definition and properties of the algebra of sets generated by some family -/ /-- `generateSetAlgebra 𝒜` is the smallest algebra of sets containing `𝒜`. -/ inductive generateSetAlgebra {α : Type*} (𝒜 : Set (Set α)) : Set (Set α) | base (s : Set α) (s_mem : s ∈ 𝒜) : generateSetAlgebra 𝒜 s | empty : generateSetAlgebra 𝒜 ∅ | compl (s : Set α) (hs : generateSetAlgebra 𝒜 s) : generateSetAlgebra 𝒜 sᶜ | union (s t : Set α) (hs : generateSetAlgebra 𝒜 s) (ht : generateSetAlgebra 𝒜 t) : generateSetAlgebra 𝒜 (s ∪ t) /-- The algebra of sets generated by a family of sets is an algebra of sets. -/ theorem isSetAlgebra_generateSetAlgebra : IsSetAlgebra (generateSetAlgebra 𝒜) where empty_mem := generateSetAlgebra.empty compl_mem := fun _ hs ↦ generateSetAlgebra.compl _ hs union_mem := fun _ _ hs ht ↦ generateSetAlgebra.union _ _ hs ht /-- The algebra of sets generated by `𝒜` contains `𝒜`. -/ theorem self_subset_generateSetAlgebra : 𝒜 ⊆ generateSetAlgebra 𝒜 := fun _ ↦ generateSetAlgebra.base _ /-- The measurable space generated by a family of sets `𝒜` is the same as the one generated by the algebra of sets generated by `𝒜`. -/ @[simp] theorem generateFrom_generateSetAlgebra_eq : generateFrom (generateSetAlgebra 𝒜) = generateFrom 𝒜 := by refine le_antisymm (fun s ms ↦ ?_) (generateFrom_mono self_subset_generateSetAlgebra) refine @generateFrom_induction _ _ (generateSetAlgebra 𝒜) (fun t ht ↦ ?_) (@MeasurableSet.empty _ (generateFrom 𝒜)) (fun t ↦ MeasurableSet.compl) (fun f hf ↦ MeasurableSet.iUnion hf) s ms induction ht with | base u u_mem => exact measurableSet_generateFrom u_mem | empty => exact @MeasurableSet.empty _ (generateFrom 𝒜) | compl u _ mu => exact mu.compl | union u v _ _ mu mv => exact MeasurableSet.union mu mv /-- If a family of sets `𝒜` is contained in `ℬ`, then the algebra of sets generated by `𝒜` is contained in the one generated by `ℬ`. -/ theorem generateSetAlgebra_mono {ℬ : Set (Set α)} (h : 𝒜 ⊆ ℬ) : generateSetAlgebra 𝒜 ⊆ generateSetAlgebra ℬ := by intro s hs induction hs with | base t t_mem => exact self_subset_generateSetAlgebra (h t_mem) | empty => exact isSetAlgebra_generateSetAlgebra.empty_mem | compl t _ t_mem => exact isSetAlgebra_generateSetAlgebra.compl_mem t_mem | union t u _ _ t_mem u_mem => exact isSetAlgebra_generateSetAlgebra.union_mem t_mem u_mem namespace IsSetAlgebra /-- If a family of sets `𝒜` is contained in an algebra of sets `ℬ`, then so is the algebra of sets generated by `𝒜`. -/ theorem generateSetAlgebra_subset {ℬ : Set (Set α)} (h : 𝒜 ⊆ ℬ) (hℬ : IsSetAlgebra ℬ) : generateSetAlgebra 𝒜 ⊆ ℬ := by intro s hs induction hs with | base t t_mem => exact h t_mem | empty => exact hℬ.empty_mem | compl t _ t_mem => exact hℬ.compl_mem t_mem | union t u _ _ t_mem u_mem => exact hℬ.union_mem t_mem u_mem /-- If `𝒜` is an algebra of sets, then it contains the algebra generated by itself. -/ theorem generateSetAlgebra_subset_self (h𝒜 : IsSetAlgebra 𝒜) : generateSetAlgebra 𝒜 ⊆ 𝒜 := h𝒜.generateSetAlgebra_subset subset_rfl /-- If `𝒜` is an algebra of sets, then it is equal to the algebra generated by itself. -/ theorem generateSetAlgebra_eq (h𝒜 : IsSetAlgebra 𝒜) : generateSetAlgebra 𝒜 = 𝒜 := Subset.antisymm h𝒜.generateSetAlgebra_subset_self self_subset_generateSetAlgebra end IsSetAlgebra /-- If a set belongs to the algebra of sets generated by `𝒜` then it can be written as a finite union of finite intersections of sets which are in `𝒜` or have their complement in `𝒜`. -/
Mathlib/MeasureTheory/SetAlgebra.lean
172
212
theorem mem_generateSetAlgebra_elim (s_mem : s ∈ generateSetAlgebra 𝒜) : ∃ A : Set (Set (Set α)), A.Finite ∧ (∀ a ∈ A, a.Finite) ∧ (∀ᵉ (a ∈ A) (t ∈ a), t ∈ 𝒜 ∨ tᶜ ∈ 𝒜) ∧ s = ⋃ a ∈ A, ⋂ t ∈ a, t := by
induction s_mem with | base u u_mem => refine ⟨{{u}}, finite_singleton {u}, fun a ha ↦ eq_of_mem_singleton ha ▸ finite_singleton u, fun a ha t ht ↦ ?_, by simp⟩ rw [eq_of_mem_singleton ha, ha, eq_of_mem_singleton ht, ht] at * exact Or.inl u_mem | empty => exact ⟨∅, finite_empty, fun _ h ↦ (not_mem_empty _ h).elim, fun _ ha _ _ ↦ (not_mem_empty _ ha).elim, by simp⟩ | compl u _ u_ind => rcases u_ind with ⟨A, A_fin, mem_A, hA, u_eq⟩ have := finite_coe_iff.2 A_fin have := fun a : A ↦ finite_coe_iff.2 <| mem_A a.1 a.2 refine ⟨{{(f a).1ᶜ | a : A} | f : (Π a : A, ↑a)}, finite_coe_iff.1 inferInstance, fun a ⟨f, hf⟩ ↦ hf ▸ finite_coe_iff.1 inferInstance, fun a ha t ht ↦ ?_, ?_⟩ · rcases ha with ⟨f, rfl⟩ rcases ht with ⟨a, rfl⟩ rw [compl_compl, or_comm] exact hA a.1 a.2 (f a).1 (f a).2 · ext x simp only [u_eq, compl_iUnion, compl_iInter, mem_iInter, mem_iUnion, mem_compl_iff, exists_prop, Subtype.exists, mem_setOf_eq, iUnion_exists, iUnion_iUnion_eq', iInter_exists] constructor <;> intro hx · choose f hf using hx exact ⟨fun ⟨a, ha⟩ ↦ ⟨f a ha, (hf a ha).1⟩, fun _ a ha h ↦ by rw [← h]; exact (hf a ha).2⟩ · rcases hx with ⟨f, hf⟩ exact fun a ha ↦ ⟨f ⟨a, ha⟩, (f ⟨a, ha⟩).2, hf (f ⟨a, ha⟩)ᶜ a ha rfl⟩ | union u v _ _ u_ind v_ind => rcases u_ind with ⟨Au, Au_fin, mem_Au, hAu, u_eq⟩ rcases v_ind with ⟨Av, Av_fin, mem_Av, hAv, v_eq⟩ refine ⟨Au ∪ Av, Au_fin.union Av_fin, ?_, ?_, by rw [u_eq, v_eq, ← biUnion_union]⟩ · rintro a (ha | ha) · exact mem_Au a ha · exact mem_Av a ha · rintro a (ha | ha) t ht · exact hAu a ha t ht · exact hAv a ha t ht
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Eric Wieser -/ import Mathlib.Analysis.NormedSpace.PiLp import Mathlib.Analysis.InnerProductSpace.PiL2 #align_import analysis.matrix from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Matrices as a normed space In this file we provide the following non-instances for norms on matrices: * The elementwise norm: * `Matrix.seminormedAddCommGroup` * `Matrix.normedAddCommGroup` * `Matrix.normedSpace` * `Matrix.boundedSMul` * The Frobenius norm: * `Matrix.frobeniusSeminormedAddCommGroup` * `Matrix.frobeniusNormedAddCommGroup` * `Matrix.frobeniusNormedSpace` * `Matrix.frobeniusNormedRing` * `Matrix.frobeniusNormedAlgebra` * `Matrix.frobeniusBoundedSMul` * The $L^\infty$ operator norm: * `Matrix.linftyOpSeminormedAddCommGroup` * `Matrix.linftyOpNormedAddCommGroup` * `Matrix.linftyOpNormedSpace` * `Matrix.linftyOpBoundedSMul` * `Matrix.linftyOpNonUnitalSemiNormedRing` * `Matrix.linftyOpSemiNormedRing` * `Matrix.linftyOpNonUnitalNormedRing` * `Matrix.linftyOpNormedRing` * `Matrix.linftyOpNormedAlgebra` These are not declared as instances because there are several natural choices for defining the norm of a matrix. The norm induced by the identification of `Matrix m n 𝕜` with `EuclideanSpace n 𝕜 →L[𝕜] EuclideanSpace m 𝕜` (i.e., the ℓ² operator norm) can be found in `Analysis.NormedSpace.Star.Matrix`. It is separated to avoid extraneous imports in this file. -/ noncomputable section open scoped NNReal Matrix namespace Matrix variable {R l m n α β : Type*} [Fintype l] [Fintype m] [Fintype n] /-! ### The elementwise supremum norm -/ section LinfLinf section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β] /-- Seminormed group instance (using sup norm of sup norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def seminormedAddCommGroup : SeminormedAddCommGroup (Matrix m n α) := Pi.seminormedAddCommGroup #align matrix.seminormed_add_comm_group Matrix.seminormedAddCommGroup attribute [local instance] Matrix.seminormedAddCommGroup -- Porting note (#10756): new theorem (along with all the uses of this lemma below) theorem norm_def (A : Matrix m n α) : ‖A‖ = ‖fun i j => A i j‖ := rfl /-- The norm of a matrix is the sup of the sup of the nnnorm of the entries -/ lemma norm_eq_sup_sup_nnnorm (A : Matrix m n α) : ‖A‖ = Finset.sup Finset.univ fun i ↦ Finset.sup Finset.univ fun j ↦ ‖A i j‖₊ := by simp_rw [Matrix.norm_def, Pi.norm_def, Pi.nnnorm_def] -- Porting note (#10756): new theorem (along with all the uses of this lemma below) theorem nnnorm_def (A : Matrix m n α) : ‖A‖₊ = ‖fun i j => A i j‖₊ := rfl theorem norm_le_iff {r : ℝ} (hr : 0 ≤ r) {A : Matrix m n α} : ‖A‖ ≤ r ↔ ∀ i j, ‖A i j‖ ≤ r := by simp_rw [norm_def, pi_norm_le_iff_of_nonneg hr] #align matrix.norm_le_iff Matrix.norm_le_iff theorem nnnorm_le_iff {r : ℝ≥0} {A : Matrix m n α} : ‖A‖₊ ≤ r ↔ ∀ i j, ‖A i j‖₊ ≤ r := by simp_rw [nnnorm_def, pi_nnnorm_le_iff] #align matrix.nnnorm_le_iff Matrix.nnnorm_le_iff theorem norm_lt_iff {r : ℝ} (hr : 0 < r) {A : Matrix m n α} : ‖A‖ < r ↔ ∀ i j, ‖A i j‖ < r := by simp_rw [norm_def, pi_norm_lt_iff hr] #align matrix.norm_lt_iff Matrix.norm_lt_iff theorem nnnorm_lt_iff {r : ℝ≥0} (hr : 0 < r) {A : Matrix m n α} : ‖A‖₊ < r ↔ ∀ i j, ‖A i j‖₊ < r := by simp_rw [nnnorm_def, pi_nnnorm_lt_iff hr] #align matrix.nnnorm_lt_iff Matrix.nnnorm_lt_iff theorem norm_entry_le_entrywise_sup_norm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖ ≤ ‖A‖ := (norm_le_pi_norm (A i) j).trans (norm_le_pi_norm A i) #align matrix.norm_entry_le_entrywise_sup_norm Matrix.norm_entry_le_entrywise_sup_norm theorem nnnorm_entry_le_entrywise_sup_nnnorm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖₊ ≤ ‖A‖₊ := (nnnorm_le_pi_nnnorm (A i) j).trans (nnnorm_le_pi_nnnorm A i) #align matrix.nnnorm_entry_le_entrywise_sup_nnnorm Matrix.nnnorm_entry_le_entrywise_sup_nnnorm @[simp] theorem nnnorm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖₊ = ‖a‖₊) : ‖A.map f‖₊ = ‖A‖₊ := by simp only [nnnorm_def, Pi.nnnorm_def, Matrix.map_apply, hf] #align matrix.nnnorm_map_eq Matrix.nnnorm_map_eq @[simp] theorem norm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖ = ‖a‖) : ‖A.map f‖ = ‖A‖ := (congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_map_eq A f fun a => Subtype.ext <| hf a : _) #align matrix.norm_map_eq Matrix.norm_map_eq @[simp] theorem nnnorm_transpose (A : Matrix m n α) : ‖Aᵀ‖₊ = ‖A‖₊ := Finset.sup_comm _ _ _ #align matrix.nnnorm_transpose Matrix.nnnorm_transpose @[simp] theorem norm_transpose (A : Matrix m n α) : ‖Aᵀ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_transpose A #align matrix.norm_transpose Matrix.norm_transpose @[simp] theorem nnnorm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖₊ = ‖A‖₊ := (nnnorm_map_eq _ _ nnnorm_star).trans A.nnnorm_transpose #align matrix.nnnorm_conj_transpose Matrix.nnnorm_conjTranspose @[simp] theorem norm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_conjTranspose A #align matrix.norm_conj_transpose Matrix.norm_conjTranspose instance [StarAddMonoid α] [NormedStarGroup α] : NormedStarGroup (Matrix m m α) := ⟨norm_conjTranspose⟩ @[simp] theorem nnnorm_col (v : m → α) : ‖col v‖₊ = ‖v‖₊ := by simp [nnnorm_def, Pi.nnnorm_def] #align matrix.nnnorm_col Matrix.nnnorm_col @[simp] theorem norm_col (v : m → α) : ‖col v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_col v #align matrix.norm_col Matrix.norm_col @[simp] theorem nnnorm_row (v : n → α) : ‖row v‖₊ = ‖v‖₊ := by simp [nnnorm_def, Pi.nnnorm_def] #align matrix.nnnorm_row Matrix.nnnorm_row @[simp] theorem norm_row (v : n → α) : ‖row v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_row v #align matrix.norm_row Matrix.norm_row @[simp] theorem nnnorm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖₊ = ‖v‖₊ := by simp_rw [nnnorm_def, Pi.nnnorm_def] congr 1 with i : 1 refine le_antisymm (Finset.sup_le fun j hj => ?_) ?_ · obtain rfl | hij := eq_or_ne i j · rw [diagonal_apply_eq] · rw [diagonal_apply_ne _ hij, nnnorm_zero] exact zero_le _ · refine Eq.trans_le ?_ (Finset.le_sup (Finset.mem_univ i)) rw [diagonal_apply_eq] #align matrix.nnnorm_diagonal Matrix.nnnorm_diagonal @[simp] theorem norm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_diagonal v #align matrix.norm_diagonal Matrix.norm_diagonal /-- Note this is safe as an instance as it carries no data. -/ -- Porting note: not yet implemented: `@[nolint fails_quickly]` instance [Nonempty n] [DecidableEq n] [One α] [NormOneClass α] : NormOneClass (Matrix n n α) := ⟨(norm_diagonal _).trans <| norm_one⟩ end SeminormedAddCommGroup /-- Normed group instance (using sup norm of sup norm) for matrices over a normed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def normedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := Pi.normedAddCommGroup #align matrix.normed_add_comm_group Matrix.normedAddCommGroup section NormedSpace attribute [local instance] Matrix.seminormedAddCommGroup /-- This applies to the sup norm of sup norm. -/ protected theorem boundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [BoundedSMul R α] : BoundedSMul R (Matrix m n α) := Pi.instBoundedSMul variable [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] /-- Normed space instance (using sup norm of sup norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def normedSpace : NormedSpace R (Matrix m n α) := Pi.normedSpace #align matrix.normed_space Matrix.normedSpace end NormedSpace end LinfLinf /-! ### The $L_\infty$ operator norm This section defines the matrix norm $\|A\|_\infty = \operatorname{sup}_i (\sum_j \|A_{ij}\|)$. Note that this is equivalent to the operator norm, considering $A$ as a linear map between two $L^\infty$ spaces. -/ section LinftyOp /-- Seminormed group instance (using sup norm of L1 norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpSeminormedAddCommGroup [SeminormedAddCommGroup α] : SeminormedAddCommGroup (Matrix m n α) := (by infer_instance : SeminormedAddCommGroup (m → PiLp 1 fun j : n => α)) #align matrix.linfty_op_seminormed_add_comm_group Matrix.linftyOpSeminormedAddCommGroup /-- Normed group instance (using sup norm of L1 norm) for matrices over a normed ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := (by infer_instance : NormedAddCommGroup (m → PiLp 1 fun j : n => α)) #align matrix.linfty_op_normed_add_comm_group Matrix.linftyOpNormedAddCommGroup /-- This applies to the sup norm of L1 norm. -/ @[local instance] protected theorem linftyOpBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [BoundedSMul R α] : BoundedSMul R (Matrix m n α) := (by infer_instance : BoundedSMul R (m → PiLp 1 fun j : n => α)) /-- Normed space instance (using sup norm of L1 norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedSpace [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] : NormedSpace R (Matrix m n α) := (by infer_instance : NormedSpace R (m → PiLp 1 fun j : n => α)) #align matrix.linfty_op_normed_space Matrix.linftyOpNormedSpace section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] theorem linfty_opNorm_def (A : Matrix m n α) : ‖A‖ = ((Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ : ℝ≥0) := by -- Porting note: added change ‖fun i => (WithLp.equiv 1 _).symm (A i)‖ = _ simp [Pi.norm_def, PiLp.nnnorm_eq_sum ENNReal.one_ne_top] #align matrix.linfty_op_norm_def Matrix.linfty_opNorm_def @[deprecated (since := "2024-02-02")] alias linfty_op_norm_def := linfty_opNorm_def theorem linfty_opNNNorm_def (A : Matrix m n α) : ‖A‖₊ = (Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ := Subtype.ext <| linfty_opNorm_def A #align matrix.linfty_op_nnnorm_def Matrix.linfty_opNNNorm_def @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_def := linfty_opNNNorm_def @[simp, nolint simpNF] -- Porting note: linter times out theorem linfty_opNNNorm_col (v : m → α) : ‖col v‖₊ = ‖v‖₊ := by rw [linfty_opNNNorm_def, Pi.nnnorm_def] simp #align matrix.linfty_op_nnnorm_col Matrix.linfty_opNNNorm_col @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_col := linfty_opNNNorm_col @[simp] theorem linfty_opNorm_col (v : m → α) : ‖col v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_col v #align matrix.linfty_op_norm_col Matrix.linfty_opNorm_col @[deprecated (since := "2024-02-02")] alias linfty_op_norm_col := linfty_opNorm_col @[simp] theorem linfty_opNNNorm_row (v : n → α) : ‖row v‖₊ = ∑ i, ‖v i‖₊ := by simp [linfty_opNNNorm_def] #align matrix.linfty_op_nnnorm_row Matrix.linfty_opNNNorm_row @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_row := linfty_opNNNorm_row @[simp] theorem linfty_opNorm_row (v : n → α) : ‖row v‖ = ∑ i, ‖v i‖ := (congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_row v).trans <| by simp [NNReal.coe_sum] #align matrix.linfty_op_norm_row Matrix.linfty_opNorm_row @[deprecated (since := "2024-02-02")] alias linfty_op_norm_row := linfty_opNorm_row @[simp] theorem linfty_opNNNorm_diagonal [DecidableEq m] (v : m → α) : ‖diagonal v‖₊ = ‖v‖₊ := by rw [linfty_opNNNorm_def, Pi.nnnorm_def] congr 1 with i : 1 refine (Finset.sum_eq_single_of_mem _ (Finset.mem_univ i) fun j _hj hij => ?_).trans ?_ · rw [diagonal_apply_ne' _ hij, nnnorm_zero] · rw [diagonal_apply_eq] #align matrix.linfty_op_nnnorm_diagonal Matrix.linfty_opNNNorm_diagonal @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_diagonal := linfty_opNNNorm_diagonal @[simp] theorem linfty_opNorm_diagonal [DecidableEq m] (v : m → α) : ‖diagonal v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_diagonal v #align matrix.linfty_op_norm_diagonal Matrix.linfty_opNorm_diagonal @[deprecated (since := "2024-02-02")] alias linfty_op_norm_diagonal := linfty_opNorm_diagonal end SeminormedAddCommGroup section NonUnitalSeminormedRing variable [NonUnitalSeminormedRing α] theorem linfty_opNNNorm_mul (A : Matrix l m α) (B : Matrix m n α) : ‖A * B‖₊ ≤ ‖A‖₊ * ‖B‖₊ := by simp_rw [linfty_opNNNorm_def, Matrix.mul_apply] calc (Finset.univ.sup fun i => ∑ k, ‖∑ j, A i j * B j k‖₊) ≤ Finset.univ.sup fun i => ∑ k, ∑ j, ‖A i j‖₊ * ‖B j k‖₊ := Finset.sup_mono_fun fun i _hi => Finset.sum_le_sum fun k _hk => nnnorm_sum_le_of_le _ fun j _hj => nnnorm_mul_le _ _ _ = Finset.univ.sup fun i => ∑ j, ‖A i j‖₊ * ∑ k, ‖B j k‖₊ := by simp_rw [@Finset.sum_comm m, Finset.mul_sum] _ ≤ Finset.univ.sup fun i => ∑ j, ‖A i j‖₊ * Finset.univ.sup fun i => ∑ j, ‖B i j‖₊ := by refine Finset.sup_mono_fun fun i _hi => ?_ gcongr with j hj exact Finset.le_sup (f := fun i ↦ ∑ k : n, ‖B i k‖₊) hj _ ≤ (Finset.univ.sup fun i => ∑ j, ‖A i j‖₊) * Finset.univ.sup fun i => ∑ j, ‖B i j‖₊ := by simp_rw [← Finset.sum_mul, ← NNReal.finset_sup_mul] rfl #align matrix.linfty_op_nnnorm_mul Matrix.linfty_opNNNorm_mul @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_mul := linfty_opNNNorm_mul theorem linfty_opNorm_mul (A : Matrix l m α) (B : Matrix m n α) : ‖A * B‖ ≤ ‖A‖ * ‖B‖ := linfty_opNNNorm_mul _ _ #align matrix.linfty_op_norm_mul Matrix.linfty_opNorm_mul @[deprecated (since := "2024-02-02")] alias linfty_op_norm_mul := linfty_opNorm_mul theorem linfty_opNNNorm_mulVec (A : Matrix l m α) (v : m → α) : ‖A *ᵥ v‖₊ ≤ ‖A‖₊ * ‖v‖₊ := by rw [← linfty_opNNNorm_col (A *ᵥ v), ← linfty_opNNNorm_col v] exact linfty_opNNNorm_mul A (col v) #align matrix.linfty_op_nnnorm_mul_vec Matrix.linfty_opNNNorm_mulVec @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_mulVec := linfty_opNNNorm_mulVec theorem linfty_opNorm_mulVec (A : Matrix l m α) (v : m → α) : ‖A *ᵥ v‖ ≤ ‖A‖ * ‖v‖ := linfty_opNNNorm_mulVec _ _ #align matrix.linfty_op_norm_mul_vec Matrix.linfty_opNorm_mulVec @[deprecated (since := "2024-02-02")] alias linfty_op_norm_mulVec := linfty_opNorm_mulVec end NonUnitalSeminormedRing /-- Seminormed non-unital ring instance (using sup norm of L1 norm) for matrices over a semi normed non-unital ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNonUnitalSemiNormedRing [NonUnitalSeminormedRing α] : NonUnitalSeminormedRing (Matrix n n α) := { Matrix.linftyOpSeminormedAddCommGroup, Matrix.instNonUnitalRing with norm_mul := linfty_opNorm_mul } #align matrix.linfty_op_non_unital_semi_normed_ring Matrix.linftyOpNonUnitalSemiNormedRing /-- The `L₁-L∞` norm preserves one on non-empty matrices. Note this is safe as an instance, as it carries no data. -/ instance linfty_opNormOneClass [SeminormedRing α] [NormOneClass α] [DecidableEq n] [Nonempty n] : NormOneClass (Matrix n n α) where norm_one := (linfty_opNorm_diagonal _).trans norm_one #align matrix.linfty_op_norm_one_class Matrix.linfty_opNormOneClass /-- Seminormed ring instance (using sup norm of L1 norm) for matrices over a semi normed ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpSemiNormedRing [SeminormedRing α] [DecidableEq n] : SeminormedRing (Matrix n n α) := { Matrix.linftyOpNonUnitalSemiNormedRing, Matrix.instRing with } #align matrix.linfty_op_semi_normed_ring Matrix.linftyOpSemiNormedRing /-- Normed non-unital ring instance (using sup norm of L1 norm) for matrices over a normed non-unital ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNonUnitalNormedRing [NonUnitalNormedRing α] : NonUnitalNormedRing (Matrix n n α) := { Matrix.linftyOpNonUnitalSemiNormedRing with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align matrix.linfty_op_non_unital_normed_ring Matrix.linftyOpNonUnitalNormedRing /-- Normed ring instance (using sup norm of L1 norm) for matrices over a normed ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedRing [NormedRing α] [DecidableEq n] : NormedRing (Matrix n n α) := { Matrix.linftyOpSemiNormedRing with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align matrix.linfty_op_normed_ring Matrix.linftyOpNormedRing /-- Normed algebra instance (using sup norm of L1 norm) for matrices over a normed algebra. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedAlgebra [NormedField R] [SeminormedRing α] [NormedAlgebra R α] [DecidableEq n] : NormedAlgebra R (Matrix n n α) := { Matrix.linftyOpNormedSpace, Matrix.instAlgebra with } #align matrix.linfty_op_normed_algebra Matrix.linftyOpNormedAlgebra section variable [NormedDivisionRing α] [NormedAlgebra ℝ α] [CompleteSpace α] /-- Auxiliary construction; an element of norm 1 such that `a * unitOf a = ‖a‖`. -/ private def unitOf (a : α) : α := by classical exact if a = 0 then 1 else ‖a‖ • a⁻¹ private theorem norm_unitOf (a : α) : ‖unitOf a‖₊ = 1 := by rw [unitOf] split_ifs with h · simp · rw [← nnnorm_eq_zero] at h rw [nnnorm_smul, nnnorm_inv, nnnorm_norm, mul_inv_cancel h] set_option tactic.skipAssignedInstances false in private theorem mul_unitOf (a : α) : a * unitOf a = algebraMap _ _ (‖a‖₊ : ℝ) := by simp [unitOf] split_ifs with h · simp [h] · rw [mul_smul_comm, mul_inv_cancel h, Algebra.algebraMap_eq_smul_one] end /-! For a matrix over a field, the norm defined in this section agrees with the operator norm on `ContinuousLinearMap`s between function types (which have the infinity norm). -/ section variable [NontriviallyNormedField α] [NormedAlgebra ℝ α] lemma linfty_opNNNorm_eq_opNNNorm (A : Matrix m n α) : ‖A‖₊ = ‖ContinuousLinearMap.mk (Matrix.mulVecLin A)‖₊ := by rw [ContinuousLinearMap.opNNNorm_eq_of_bounds _ (linfty_opNNNorm_mulVec _) fun N hN => ?_] rw [linfty_opNNNorm_def] refine Finset.sup_le fun i _ => ?_ cases isEmpty_or_nonempty n · simp classical let x : n → α := fun j => unitOf (A i j) have hxn : ‖x‖₊ = 1 := by simp_rw [x, Pi.nnnorm_def, norm_unitOf, Finset.sup_const Finset.univ_nonempty] specialize hN x rw [hxn, mul_one, Pi.nnnorm_def, Finset.sup_le_iff] at hN replace hN := hN i (Finset.mem_univ _) dsimp [mulVec, dotProduct] at hN simp_rw [x, mul_unitOf, ← map_sum, nnnorm_algebraMap, ← NNReal.coe_sum, NNReal.nnnorm_eq, nnnorm_one, mul_one] at hN exact hN @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_eq_op_nnnorm := linfty_opNNNorm_eq_opNNNorm lemma linfty_opNorm_eq_opNorm (A : Matrix m n α) : ‖A‖ = ‖ContinuousLinearMap.mk (Matrix.mulVecLin A)‖ := congr_arg NNReal.toReal (linfty_opNNNorm_eq_opNNNorm A) @[deprecated (since := "2024-02-02")] alias linfty_op_norm_eq_op_norm := linfty_opNorm_eq_opNorm variable [DecidableEq n] @[simp] lemma linfty_opNNNorm_toMatrix (f : (n → α) →L[α] (m → α)) : ‖LinearMap.toMatrix' (↑f : (n → α) →ₗ[α] (m → α))‖₊ = ‖f‖₊ := by rw [linfty_opNNNorm_eq_opNNNorm] simp only [← toLin'_apply', toLin'_toMatrix'] @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_toMatrix := linfty_opNNNorm_toMatrix @[simp] lemma linfty_opNorm_toMatrix (f : (n → α) →L[α] (m → α)) : ‖LinearMap.toMatrix' (↑f : (n → α) →ₗ[α] (m → α))‖ = ‖f‖ := congr_arg NNReal.toReal (linfty_opNNNorm_toMatrix f) @[deprecated (since := "2024-02-02")] alias linfty_op_norm_toMatrix := linfty_opNorm_toMatrix end end LinftyOp /-! ### The Frobenius norm This is defined as $\|A\| = \sqrt{\sum_{i,j} \|A_{ij}\|^2}$. When the matrix is over the real or complex numbers, this norm is submultiplicative. -/ section frobenius open scoped Matrix /-- Seminormed group instance (using frobenius norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] def frobeniusSeminormedAddCommGroup [SeminormedAddCommGroup α] : SeminormedAddCommGroup (Matrix m n α) := inferInstanceAs (SeminormedAddCommGroup (PiLp 2 fun _i : m => PiLp 2 fun _j : n => α)) #align matrix.frobenius_seminormed_add_comm_group Matrix.frobeniusSeminormedAddCommGroup /-- Normed group instance (using frobenius norm) for matrices over a normed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] def frobeniusNormedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := (by infer_instance : NormedAddCommGroup (PiLp 2 fun i : m => PiLp 2 fun j : n => α)) #align matrix.frobenius_normed_add_comm_group Matrix.frobeniusNormedAddCommGroup /-- This applies to the frobenius norm. -/ @[local instance] theorem frobeniusBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [BoundedSMul R α] : BoundedSMul R (Matrix m n α) := (by infer_instance : BoundedSMul R (PiLp 2 fun i : m => PiLp 2 fun j : n => α)) /-- Normed space instance (using frobenius norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] def frobeniusNormedSpace [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] : NormedSpace R (Matrix m n α) := (by infer_instance : NormedSpace R (PiLp 2 fun i : m => PiLp 2 fun j : n => α)) #align matrix.frobenius_normed_space Matrix.frobeniusNormedSpace section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β] theorem frobenius_nnnorm_def (A : Matrix m n α) : ‖A‖₊ = (∑ i, ∑ j, ‖A i j‖₊ ^ (2 : ℝ)) ^ (1 / 2 : ℝ) := by -- Porting note: added, along with `WithLp.equiv_symm_pi_apply` below change ‖(WithLp.equiv 2 _).symm fun i => (WithLp.equiv 2 _).symm fun j => A i j‖₊ = _ simp_rw [PiLp.nnnorm_eq_of_L2, NNReal.sq_sqrt, NNReal.sqrt_eq_rpow, NNReal.rpow_two, WithLp.equiv_symm_pi_apply] #align matrix.frobenius_nnnorm_def Matrix.frobenius_nnnorm_def theorem frobenius_norm_def (A : Matrix m n α) : ‖A‖ = (∑ i, ∑ j, ‖A i j‖ ^ (2 : ℝ)) ^ (1 / 2 : ℝ) := (congr_arg ((↑) : ℝ≥0 → ℝ) (frobenius_nnnorm_def A)).trans <| by simp [NNReal.coe_sum] #align matrix.frobenius_norm_def Matrix.frobenius_norm_def @[simp] theorem frobenius_nnnorm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖₊ = ‖a‖₊) : ‖A.map f‖₊ = ‖A‖₊ := by simp_rw [frobenius_nnnorm_def, Matrix.map_apply, hf] #align matrix.frobenius_nnnorm_map_eq Matrix.frobenius_nnnorm_map_eq @[simp] theorem frobenius_norm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖ = ‖a‖) : ‖A.map f‖ = ‖A‖ := (congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_map_eq A f fun a => Subtype.ext <| hf a : _) #align matrix.frobenius_norm_map_eq Matrix.frobenius_norm_map_eq @[simp] theorem frobenius_nnnorm_transpose (A : Matrix m n α) : ‖Aᵀ‖₊ = ‖A‖₊ := by rw [frobenius_nnnorm_def, frobenius_nnnorm_def, Finset.sum_comm] simp_rw [Matrix.transpose_apply] -- Porting note: added #align matrix.frobenius_nnnorm_transpose Matrix.frobenius_nnnorm_transpose @[simp] theorem frobenius_norm_transpose (A : Matrix m n α) : ‖Aᵀ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_transpose A #align matrix.frobenius_norm_transpose Matrix.frobenius_norm_transpose @[simp] theorem frobenius_nnnorm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖₊ = ‖A‖₊ := (frobenius_nnnorm_map_eq _ _ nnnorm_star).trans A.frobenius_nnnorm_transpose #align matrix.frobenius_nnnorm_conj_transpose Matrix.frobenius_nnnorm_conjTranspose @[simp] theorem frobenius_norm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_conjTranspose A #align matrix.frobenius_norm_conj_transpose Matrix.frobenius_norm_conjTranspose instance frobenius_normedStarGroup [StarAddMonoid α] [NormedStarGroup α] : NormedStarGroup (Matrix m m α) := ⟨frobenius_norm_conjTranspose⟩ #align matrix.frobenius_normed_star_group Matrix.frobenius_normedStarGroup @[simp] theorem frobenius_norm_row (v : m → α) : ‖row v‖ = ‖(WithLp.equiv 2 _).symm v‖ := by rw [frobenius_norm_def, Fintype.sum_unique, PiLp.norm_eq_of_L2, Real.sqrt_eq_rpow] simp only [row_apply, Real.rpow_two, WithLp.equiv_symm_pi_apply] #align matrix.frobenius_norm_row Matrix.frobenius_norm_row @[simp] theorem frobenius_nnnorm_row (v : m → α) : ‖row v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ := Subtype.ext <| frobenius_norm_row v #align matrix.frobenius_nnnorm_row Matrix.frobenius_nnnorm_row @[simp] theorem frobenius_norm_col (v : n → α) : ‖col v‖ = ‖(WithLp.equiv 2 _).symm v‖ := by simp_rw [frobenius_norm_def, Fintype.sum_unique, PiLp.norm_eq_of_L2, Real.sqrt_eq_rpow] simp only [col_apply, Real.rpow_two, WithLp.equiv_symm_pi_apply] #align matrix.frobenius_norm_col Matrix.frobenius_norm_col @[simp] theorem frobenius_nnnorm_col (v : n → α) : ‖col v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ := Subtype.ext <| frobenius_norm_col v #align matrix.frobenius_nnnorm_col Matrix.frobenius_nnnorm_col @[simp]
Mathlib/Analysis/Matrix.lean
635
646
theorem frobenius_nnnorm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ := by
simp_rw [frobenius_nnnorm_def, ← Finset.sum_product', Finset.univ_product_univ, PiLp.nnnorm_eq_of_L2] let s := (Finset.univ : Finset n).map ⟨fun i : n => (i, i), fun i j h => congr_arg Prod.fst h⟩ rw [← Finset.sum_subset (Finset.subset_univ s) fun i _hi his => ?_] · rw [Finset.sum_map, NNReal.sqrt_eq_rpow] dsimp simp_rw [diagonal_apply_eq, NNReal.rpow_two] · suffices i.1 ≠ i.2 by rw [diagonal_apply_ne _ this, nnnorm_zero, NNReal.zero_rpow two_ne_zero] intro h exact Finset.mem_map.not.mp his ⟨i.1, Finset.mem_univ _, Prod.ext rfl h⟩
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Topology.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/ theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩ #align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] : ∃ x : X, IsOpen ({x} : Set X) := let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _) univ_nonempty isOpen_univ ⟨x, h⟩ #align exists_open_singleton_of_fintype exists_open_singleton_of_finite theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X := ⟨fun _ _ h => hf <| (h.map hf').eq⟩ #align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y} (hf : Embedding f) : T0Space X := t0Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t0_space Embedding.t0Space instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) := embedding_subtype_val.t0Space #align subtype.t0_space Subtype.t0Space theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or] #align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) := ⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩ instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T0Space (X i)] : T0Space (∀ i, X i) := ⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩ #align pi.t0_space Pi.instT0Space instance ULift.instT0Space [T0Space X] : T0Space (ULift X) := embedding_uLift_down.t0Space theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) : T0Space X := by refine ⟨fun x y hxy => ?_⟩ rcases h x y hxy with ⟨s, hxs, hys, hs⟩ lift x to s using hxs; lift y to s using hys rw [← subtype_inseparable_iff] at hxy exact congr_arg Subtype.val hxy.eq #align t0_space.of_cover T0Space.of_cover theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X := T0Space.of_cover fun x _ hxy => let ⟨s, hxs, hso, hs⟩ := h x ⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩ #align t0_space.of_open_cover T0Space.of_open_cover /-- A topological space is called an R₀ space, if `Specializes` relation is symmetric. In other words, given two points `x y : X`, if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/ @[mk_iff] class R0Space (X : Type u) [TopologicalSpace X] : Prop where /-- In an R₀ space, the `Specializes` relation is symmetric. -/ specializes_symmetric : Symmetric (Specializes : X → X → Prop) export R0Space (specializes_symmetric) section R0Space variable [R0Space X] {x y : X} /-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/ theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h #align specializes.symm Specializes.symm /-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/ theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩ #align specializes_comm specializes_comm /-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/ theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y := ⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩ #align specializes_iff_inseparable specializes_iff_inseparable /-- In an R₀ space, `Specializes` implies `Inseparable`. -/ alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where specializes_symmetric a b := by simpa only [← hf.specializes_iff] using Specializes.symm instance {p : X → Prop} : R0Space {x // p x} := inducing_subtype_val.r0Space instance [TopologicalSpace Y] [R0Space Y] : R0Space (X × Y) where specializes_symmetric _ _ h := h.fst.symm.prod h.snd.symm instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R0Space (X i)] : R0Space (∀ i, X i) where specializes_symmetric _ _ h := specializes_pi.2 fun i ↦ (specializes_pi.1 h i).symm /-- In an R₀ space, the closure of a singleton is a compact set. -/ theorem isCompact_closure_singleton : IsCompact (closure {x}) := by refine isCompact_of_finite_subcover fun U hUo hxU ↦ ?_ obtain ⟨i, hi⟩ : ∃ i, x ∈ U i := mem_iUnion.1 <| hxU <| subset_closure rfl refine ⟨{i}, fun y hy ↦ ?_⟩ rw [← specializes_iff_mem_closure, specializes_comm] at hy simpa using hy.mem_open (hUo i) hi theorem Filter.coclosedCompact_le_cofinite : coclosedCompact X ≤ cofinite := le_cofinite_iff_compl_singleton_mem.2 fun _ ↦ compl_mem_coclosedCompact.2 isCompact_closure_singleton #align filter.coclosed_compact_le_cofinite Filter.coclosedCompact_le_cofinite variable (X) /-- In an R₀ space, relatively compact sets form a bornology. Its cobounded filter is `Filter.coclosedCompact`. See also `Bornology.inCompact` the bornology of sets contained in a compact set. -/ def Bornology.relativelyCompact : Bornology X where cobounded' := Filter.coclosedCompact X le_cofinite' := Filter.coclosedCompact_le_cofinite #align bornology.relatively_compact Bornology.relativelyCompact variable {X} theorem Bornology.relativelyCompact.isBounded_iff {s : Set X} : @Bornology.IsBounded _ (Bornology.relativelyCompact X) s ↔ IsCompact (closure s) := compl_mem_coclosedCompact #align bornology.relatively_compact.is_bounded_iff Bornology.relativelyCompact.isBounded_iff /-- In an R₀ space, the closure of a finite set is a compact set. -/ theorem Set.Finite.isCompact_closure {s : Set X} (hs : s.Finite) : IsCompact (closure s) := let _ : Bornology X := .relativelyCompact X Bornology.relativelyCompact.isBounded_iff.1 hs.isBounded end R0Space /-- A T₁ space, also known as a Fréchet space, is a topological space where every singleton set is closed. Equivalently, for every pair `x ≠ y`, there is an open set containing `x` and not `y`. -/ class T1Space (X : Type u) [TopologicalSpace X] : Prop where /-- A singleton in a T₁ space is a closed set. -/ t1 : ∀ x, IsClosed ({x} : Set X) #align t1_space T1Space theorem isClosed_singleton [T1Space X] {x : X} : IsClosed ({x} : Set X) := T1Space.t1 x #align is_closed_singleton isClosed_singleton theorem isOpen_compl_singleton [T1Space X] {x : X} : IsOpen ({x}ᶜ : Set X) := isClosed_singleton.isOpen_compl #align is_open_compl_singleton isOpen_compl_singleton theorem isOpen_ne [T1Space X] {x : X} : IsOpen { y | y ≠ x } := isOpen_compl_singleton #align is_open_ne isOpen_ne @[to_additive] theorem Continuous.isOpen_mulSupport [T1Space X] [One X] [TopologicalSpace Y] {f : Y → X} (hf : Continuous f) : IsOpen (mulSupport f) := isOpen_ne.preimage hf #align continuous.is_open_mul_support Continuous.isOpen_mulSupport #align continuous.is_open_support Continuous.isOpen_support theorem Ne.nhdsWithin_compl_singleton [T1Space X] {x y : X} (h : x ≠ y) : 𝓝[{y}ᶜ] x = 𝓝 x := isOpen_ne.nhdsWithin_eq h #align ne.nhds_within_compl_singleton Ne.nhdsWithin_compl_singleton theorem Ne.nhdsWithin_diff_singleton [T1Space X] {x y : X} (h : x ≠ y) (s : Set X) : 𝓝[s \ {y}] x = 𝓝[s] x := by rw [diff_eq, inter_comm, nhdsWithin_inter_of_mem] exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h) #align ne.nhds_within_diff_singleton Ne.nhdsWithin_diff_singleton lemma nhdsWithin_compl_singleton_le [T1Space X] (x y : X) : 𝓝[{x}ᶜ] x ≤ 𝓝[{y}ᶜ] x := by rcases eq_or_ne x y with rfl|hy · exact Eq.le rfl · rw [Ne.nhdsWithin_compl_singleton hy] exact nhdsWithin_le_nhds theorem isOpen_setOf_eventually_nhdsWithin [T1Space X] {p : X → Prop} : IsOpen { x | ∀ᶠ y in 𝓝[≠] x, p y } := by refine isOpen_iff_mem_nhds.mpr fun a ha => ?_ filter_upwards [eventually_nhds_nhdsWithin.mpr ha] with b hb rcases eq_or_ne a b with rfl | h · exact hb · rw [h.symm.nhdsWithin_compl_singleton] at hb exact hb.filter_mono nhdsWithin_le_nhds #align is_open_set_of_eventually_nhds_within isOpen_setOf_eventually_nhdsWithin protected theorem Set.Finite.isClosed [T1Space X] {s : Set X} (hs : Set.Finite s) : IsClosed s := by rw [← biUnion_of_singleton s] exact hs.isClosed_biUnion fun i _ => isClosed_singleton #align set.finite.is_closed Set.Finite.isClosed theorem TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne [T1Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} (h : x ≠ y) : ∃ a ∈ b, x ∈ a ∧ y ∉ a := by rcases hb.isOpen_iff.1 isOpen_ne x h with ⟨a, ab, xa, ha⟩ exact ⟨a, ab, xa, fun h => ha h rfl⟩ #align topological_space.is_topological_basis.exists_mem_of_ne TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne protected theorem Finset.isClosed [T1Space X] (s : Finset X) : IsClosed (s : Set X) := s.finite_toSet.isClosed #align finset.is_closed Finset.isClosed theorem t1Space_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [T1Space X, ∀ x, IsClosed ({ x } : Set X), ∀ x, IsOpen ({ x }ᶜ : Set X), Continuous (@CofiniteTopology.of X), ∀ ⦃x y : X⦄, x ≠ y → {y}ᶜ ∈ 𝓝 x, ∀ ⦃x y : X⦄, x ≠ y → ∃ s ∈ 𝓝 x, y ∉ s, ∀ ⦃x y : X⦄, x ≠ y → ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U, ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y), ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y), ∀ ⦃x y : X⦄, x ⤳ y → x = y] := by tfae_have 1 ↔ 2 · exact ⟨fun h => h.1, fun h => ⟨h⟩⟩ tfae_have 2 ↔ 3 · simp only [isOpen_compl_iff] tfae_have 5 ↔ 3 · refine forall_swap.trans ?_ simp only [isOpen_iff_mem_nhds, mem_compl_iff, mem_singleton_iff] tfae_have 5 ↔ 6 · simp only [← subset_compl_singleton_iff, exists_mem_subset_iff] tfae_have 5 ↔ 7 · simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and_assoc, and_left_comm] tfae_have 5 ↔ 8 · simp only [← principal_singleton, disjoint_principal_right] tfae_have 8 ↔ 9 · exact forall_swap.trans (by simp only [disjoint_comm, ne_comm]) tfae_have 1 → 4 · simp only [continuous_def, CofiniteTopology.isOpen_iff'] rintro H s (rfl | hs) exacts [isOpen_empty, compl_compl s ▸ (@Set.Finite.isClosed _ _ H _ hs).isOpen_compl] tfae_have 4 → 2 · exact fun h x => (CofiniteTopology.isClosed_iff.2 <| Or.inr (finite_singleton _)).preimage h tfae_have 2 ↔ 10 · simp only [← closure_subset_iff_isClosed, specializes_iff_mem_closure, subset_def, mem_singleton_iff, eq_comm] tfae_finish #align t1_space_tfae t1Space_TFAE theorem t1Space_iff_continuous_cofinite_of : T1Space X ↔ Continuous (@CofiniteTopology.of X) := (t1Space_TFAE X).out 0 3 #align t1_space_iff_continuous_cofinite_of t1Space_iff_continuous_cofinite_of theorem CofiniteTopology.continuous_of [T1Space X] : Continuous (@CofiniteTopology.of X) := t1Space_iff_continuous_cofinite_of.mp ‹_› #align cofinite_topology.continuous_of CofiniteTopology.continuous_of theorem t1Space_iff_exists_open : T1Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U := (t1Space_TFAE X).out 0 6 #align t1_space_iff_exists_open t1Space_iff_exists_open theorem t1Space_iff_disjoint_pure_nhds : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y) := (t1Space_TFAE X).out 0 8 #align t1_space_iff_disjoint_pure_nhds t1Space_iff_disjoint_pure_nhds theorem t1Space_iff_disjoint_nhds_pure : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y) := (t1Space_TFAE X).out 0 7 #align t1_space_iff_disjoint_nhds_pure t1Space_iff_disjoint_nhds_pure theorem t1Space_iff_specializes_imp_eq : T1Space X ↔ ∀ ⦃x y : X⦄, x ⤳ y → x = y := (t1Space_TFAE X).out 0 9 #align t1_space_iff_specializes_imp_eq t1Space_iff_specializes_imp_eq theorem disjoint_pure_nhds [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (pure x) (𝓝 y) := t1Space_iff_disjoint_pure_nhds.mp ‹_› h #align disjoint_pure_nhds disjoint_pure_nhds theorem disjoint_nhds_pure [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (𝓝 x) (pure y) := t1Space_iff_disjoint_nhds_pure.mp ‹_› h #align disjoint_nhds_pure disjoint_nhds_pure theorem Specializes.eq [T1Space X] {x y : X} (h : x ⤳ y) : x = y := t1Space_iff_specializes_imp_eq.1 ‹_› h #align specializes.eq Specializes.eq theorem specializes_iff_eq [T1Space X] {x y : X} : x ⤳ y ↔ x = y := ⟨Specializes.eq, fun h => h ▸ specializes_rfl⟩ #align specializes_iff_eq specializes_iff_eq @[simp] theorem specializes_eq_eq [T1Space X] : (· ⤳ ·) = @Eq X := funext₂ fun _ _ => propext specializes_iff_eq #align specializes_eq_eq specializes_eq_eq @[simp] theorem pure_le_nhds_iff [T1Space X] {a b : X} : pure a ≤ 𝓝 b ↔ a = b := specializes_iff_pure.symm.trans specializes_iff_eq #align pure_le_nhds_iff pure_le_nhds_iff @[simp] theorem nhds_le_nhds_iff [T1Space X] {a b : X} : 𝓝 a ≤ 𝓝 b ↔ a = b := specializes_iff_eq #align nhds_le_nhds_iff nhds_le_nhds_iff instance (priority := 100) [T1Space X] : R0Space X where specializes_symmetric _ _ := by rw [specializes_iff_eq, specializes_iff_eq]; exact Eq.symm instance : T1Space (CofiniteTopology X) := t1Space_iff_continuous_cofinite_of.mpr continuous_id theorem t1Space_antitone : Antitone (@T1Space X) := fun a _ h _ => @T1Space.mk _ a fun x => (T1Space.t1 x).mono h #align t1_space_antitone t1Space_antitone theorem continuousWithinAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousWithinAt (Function.update f x y) s x' ↔ ContinuousWithinAt f s x' := EventuallyEq.congr_continuousWithinAt (mem_nhdsWithin_of_mem_nhds <| mem_of_superset (isOpen_ne.mem_nhds hne) fun _y' hy' => Function.update_noteq hy' _ _) (Function.update_noteq hne _ _) #align continuous_within_at_update_of_ne continuousWithinAt_update_of_ne theorem continuousAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousAt (Function.update f x y) x' ↔ ContinuousAt f x' := by simp only [← continuousWithinAt_univ, continuousWithinAt_update_of_ne hne] #align continuous_at_update_of_ne continuousAt_update_of_ne theorem continuousOn_update_iff [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x : X} {y : Y} : ContinuousOn (Function.update f x y) s ↔ ContinuousOn f (s \ {x}) ∧ (x ∈ s → Tendsto f (𝓝[s \ {x}] x) (𝓝 y)) := by rw [ContinuousOn, ← and_forall_ne x, and_comm] refine and_congr ⟨fun H z hz => ?_, fun H z hzx hzs => ?_⟩ (forall_congr' fun _ => ?_) · specialize H z hz.2 hz.1 rw [continuousWithinAt_update_of_ne hz.2] at H exact H.mono diff_subset · rw [continuousWithinAt_update_of_ne hzx] refine (H z ⟨hzs, hzx⟩).mono_of_mem (inter_mem_nhdsWithin _ ?_) exact isOpen_ne.mem_nhds hzx · exact continuousWithinAt_update_same #align continuous_on_update_iff continuousOn_update_iff theorem t1Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T1Space Y] : T1Space X := t1Space_iff_specializes_imp_eq.2 fun _ _ h => hf (h.map hf').eq #align t1_space_of_injective_of_continuous t1Space_of_injective_of_continuous protected theorem Embedding.t1Space [TopologicalSpace Y] [T1Space Y] {f : X → Y} (hf : Embedding f) : T1Space X := t1Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t1_space Embedding.t1Space instance Subtype.t1Space {X : Type u} [TopologicalSpace X] [T1Space X] {p : X → Prop} : T1Space (Subtype p) := embedding_subtype_val.t1Space #align subtype.t1_space Subtype.t1Space instance [TopologicalSpace Y] [T1Space X] [T1Space Y] : T1Space (X × Y) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ isClosed_singleton.prod isClosed_singleton⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T1Space (X i)] : T1Space (∀ i, X i) := ⟨fun f => univ_pi_singleton f ▸ isClosed_set_pi fun _ _ => isClosed_singleton⟩ instance ULift.instT1Space [T1Space X] : T1Space (ULift X) := embedding_uLift_down.t1Space -- see Note [lower instance priority] instance (priority := 100) TotallyDisconnectedSpace.t1Space [h: TotallyDisconnectedSpace X] : T1Space X := by rw [((t1Space_TFAE X).out 0 1 :)] intro x rw [← totallyDisconnectedSpace_iff_connectedComponent_singleton.mp h x] exact isClosed_connectedComponent -- see Note [lower instance priority] instance (priority := 100) T1Space.t0Space [T1Space X] : T0Space X := ⟨fun _ _ h => h.specializes.eq⟩ #align t1_space.t0_space T1Space.t0Space @[simp] theorem compl_singleton_mem_nhds_iff [T1Space X] {x y : X} : {x}ᶜ ∈ 𝓝 y ↔ y ≠ x := isOpen_compl_singleton.mem_nhds_iff #align compl_singleton_mem_nhds_iff compl_singleton_mem_nhds_iff theorem compl_singleton_mem_nhds [T1Space X] {x y : X} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds_iff.mpr h #align compl_singleton_mem_nhds compl_singleton_mem_nhds @[simp] theorem closure_singleton [T1Space X] {x : X} : closure ({x} : Set X) = {x} := isClosed_singleton.closure_eq #align closure_singleton closure_singleton -- Porting note (#11215): TODO: the proof was `hs.induction_on (by simp) fun x => by simp` theorem Set.Subsingleton.closure [T1Space X] {s : Set X} (hs : s.Subsingleton) : (closure s).Subsingleton := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) <;> simp #align set.subsingleton.closure Set.Subsingleton.closure @[simp] theorem subsingleton_closure [T1Space X] {s : Set X} : (closure s).Subsingleton ↔ s.Subsingleton := ⟨fun h => h.anti subset_closure, fun h => h.closure⟩ #align subsingleton_closure subsingleton_closure theorem isClosedMap_const {X Y} [TopologicalSpace X] [TopologicalSpace Y] [T1Space Y] {y : Y} : IsClosedMap (Function.const X y) := IsClosedMap.of_nonempty fun s _ h2s => by simp_rw [const, h2s.image_const, isClosed_singleton] #align is_closed_map_const isClosedMap_const theorem nhdsWithin_insert_of_ne [T1Space X] {x y : X} {s : Set X} (hxy : x ≠ y) : 𝓝[insert y s] x = 𝓝[s] x := by refine le_antisymm (Filter.le_def.2 fun t ht => ?_) (nhdsWithin_mono x <| subset_insert y s) obtain ⟨o, ho, hxo, host⟩ := mem_nhdsWithin.mp ht refine mem_nhdsWithin.mpr ⟨o \ {y}, ho.sdiff isClosed_singleton, ⟨hxo, hxy⟩, ?_⟩ rw [inter_insert_of_not_mem <| not_mem_diff_of_mem (mem_singleton y)] exact (inter_subset_inter diff_subset Subset.rfl).trans host #align nhds_within_insert_of_ne nhdsWithin_insert_of_ne /-- If `t` is a subset of `s`, except for one point, then `insert x s` is a neighborhood of `x` within `t`. -/ theorem insert_mem_nhdsWithin_of_subset_insert [T1Space X] {x y : X} {s t : Set X} (hu : t ⊆ insert y s) : insert x s ∈ 𝓝[t] x := by rcases eq_or_ne x y with (rfl | h) · exact mem_of_superset self_mem_nhdsWithin hu refine nhdsWithin_mono x hu ?_ rw [nhdsWithin_insert_of_ne h] exact mem_of_superset self_mem_nhdsWithin (subset_insert x s) #align insert_mem_nhds_within_of_subset_insert insert_mem_nhdsWithin_of_subset_insert @[simp] theorem ker_nhds [T1Space X] (x : X) : (𝓝 x).ker = {x} := by simp [ker_nhds_eq_specializes] theorem biInter_basis_nhds [T1Space X] {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X} (h : (𝓝 x).HasBasis p s) : ⋂ (i) (_ : p i), s i = {x} := by rw [← h.ker, ker_nhds] #align bInter_basis_nhds biInter_basis_nhds @[simp] theorem compl_singleton_mem_nhdsSet_iff [T1Space X] {x : X} {s : Set X} : {x}ᶜ ∈ 𝓝ˢ s ↔ x ∉ s := by rw [isOpen_compl_singleton.mem_nhdsSet, subset_compl_singleton_iff] #align compl_singleton_mem_nhds_set_iff compl_singleton_mem_nhdsSet_iff @[simp] theorem nhdsSet_le_iff [T1Space X] {s t : Set X} : 𝓝ˢ s ≤ 𝓝ˢ t ↔ s ⊆ t := by refine ⟨?_, fun h => monotone_nhdsSet h⟩ simp_rw [Filter.le_def]; intro h x hx specialize h {x}ᶜ simp_rw [compl_singleton_mem_nhdsSet_iff] at h by_contra hxt exact h hxt hx #align nhds_set_le_iff nhdsSet_le_iff @[simp] theorem nhdsSet_inj_iff [T1Space X] {s t : Set X} : 𝓝ˢ s = 𝓝ˢ t ↔ s = t := by simp_rw [le_antisymm_iff] exact and_congr nhdsSet_le_iff nhdsSet_le_iff #align nhds_set_inj_iff nhdsSet_inj_iff theorem injective_nhdsSet [T1Space X] : Function.Injective (𝓝ˢ : Set X → Filter X) := fun _ _ hst => nhdsSet_inj_iff.mp hst #align injective_nhds_set injective_nhdsSet theorem strictMono_nhdsSet [T1Space X] : StrictMono (𝓝ˢ : Set X → Filter X) := monotone_nhdsSet.strictMono_of_injective injective_nhdsSet #align strict_mono_nhds_set strictMono_nhdsSet @[simp] theorem nhds_le_nhdsSet_iff [T1Space X] {s : Set X} {x : X} : 𝓝 x ≤ 𝓝ˢ s ↔ x ∈ s := by rw [← nhdsSet_singleton, nhdsSet_le_iff, singleton_subset_iff] #align nhds_le_nhds_set_iff nhds_le_nhdsSet_iff /-- Removing a non-isolated point from a dense set, one still obtains a dense set. -/ theorem Dense.diff_singleton [T1Space X] {s : Set X} (hs : Dense s) (x : X) [NeBot (𝓝[≠] x)] : Dense (s \ {x}) := hs.inter_of_isOpen_right (dense_compl_singleton x) isOpen_compl_singleton #align dense.diff_singleton Dense.diff_singleton /-- Removing a finset from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finset [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) (t : Finset X) : Dense (s \ t) := by induction t using Finset.induction_on with | empty => simpa using hs | insert _ ih => rw [Finset.coe_insert, ← union_singleton, ← diff_diff] exact ih.diff_singleton _ #align dense.diff_finset Dense.diff_finset /-- Removing a finite set from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finite [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) {t : Set X} (ht : t.Finite) : Dense (s \ t) := by convert hs.diff_finset ht.toFinset exact (Finite.coe_toFinset _).symm #align dense.diff_finite Dense.diff_finite /-- If a function to a `T1Space` tends to some limit `y` at some point `x`, then necessarily `y = f x`. -/ theorem eq_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : f x = y := by_contra fun hfa : f x ≠ y => have fact₁ : {f x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds hfa.symm have fact₂ : Tendsto f (pure x) (𝓝 y) := h.comp (tendsto_id'.2 <| pure_le_nhds x) fact₂ fact₁ (Eq.refl <| f x) #align eq_of_tendsto_nhds eq_of_tendsto_nhds theorem Filter.Tendsto.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {l : Filter X} {b₁ b₂ : Y} (hg : Tendsto g l (𝓝 b₁)) (hb : b₁ ≠ b₂) : ∀ᶠ z in l, g z ≠ b₂ := hg.eventually (isOpen_compl_singleton.eventually_mem hb) #align filter.tendsto.eventually_ne Filter.Tendsto.eventually_ne theorem ContinuousAt.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {x : X} {y : Y} (hg1 : ContinuousAt g x) (hg2 : g x ≠ y) : ∀ᶠ z in 𝓝 x, g z ≠ y := hg1.tendsto.eventually_ne hg2 #align continuous_at.eventually_ne ContinuousAt.eventually_ne theorem eventually_ne_nhds [T1Space X] {a b : X} (h : a ≠ b) : ∀ᶠ x in 𝓝 a, x ≠ b := IsOpen.eventually_mem isOpen_ne h theorem eventually_ne_nhdsWithin [T1Space X] {a b : X} {s : Set X} (h : a ≠ b) : ∀ᶠ x in 𝓝[s] a, x ≠ b := Filter.Eventually.filter_mono nhdsWithin_le_nhds <| eventually_ne_nhds h /-- To prove a function to a `T1Space` is continuous at some point `x`, it suffices to prove that `f` admits *some* limit at `x`. -/ theorem continuousAt_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : ContinuousAt f x := by rwa [ContinuousAt, eq_of_tendsto_nhds h] #align continuous_at_of_tendsto_nhds continuousAt_of_tendsto_nhds @[simp] theorem tendsto_const_nhds_iff [T1Space X] {l : Filter Y} [NeBot l] {c d : X} : Tendsto (fun _ => c) l (𝓝 d) ↔ c = d := by simp_rw [Tendsto, Filter.map_const, pure_le_nhds_iff] #align tendsto_const_nhds_iff tendsto_const_nhds_iff /-- A point with a finite neighborhood has to be isolated. -/ theorem isOpen_singleton_of_finite_mem_nhds [T1Space X] (x : X) {s : Set X} (hs : s ∈ 𝓝 x) (hsf : s.Finite) : IsOpen ({x} : Set X) := by have A : {x} ⊆ s := by simp only [singleton_subset_iff, mem_of_mem_nhds hs] have B : IsClosed (s \ {x}) := (hsf.subset diff_subset).isClosed have C : (s \ {x})ᶜ ∈ 𝓝 x := B.isOpen_compl.mem_nhds fun h => h.2 rfl have D : {x} ∈ 𝓝 x := by simpa only [← diff_eq, diff_diff_cancel_left A] using inter_mem hs C rwa [← mem_interior_iff_mem_nhds, ← singleton_subset_iff, subset_interior_iff_isOpen] at D #align is_open_singleton_of_finite_mem_nhds isOpen_singleton_of_finite_mem_nhds /-- If the punctured neighborhoods of a point form a nontrivial filter, then any neighborhood is infinite. -/ theorem infinite_of_mem_nhds {X} [TopologicalSpace X] [T1Space X] (x : X) [hx : NeBot (𝓝[≠] x)] {s : Set X} (hs : s ∈ 𝓝 x) : Set.Infinite s := by refine fun hsf => hx.1 ?_ rw [← isOpen_singleton_iff_punctured_nhds] exact isOpen_singleton_of_finite_mem_nhds x hs hsf #align infinite_of_mem_nhds infinite_of_mem_nhds theorem discrete_of_t1_of_finite [T1Space X] [Finite X] : DiscreteTopology X := by apply singletons_open_iff_discrete.mp intro x rw [← isClosed_compl_iff] exact (Set.toFinite _).isClosed #align discrete_of_t1_of_finite discrete_of_t1_of_finite theorem PreconnectedSpace.trivial_of_discrete [PreconnectedSpace X] [DiscreteTopology X] : Subsingleton X := by rw [← not_nontrivial_iff_subsingleton] rintro ⟨x, y, hxy⟩ rw [Ne, ← mem_singleton_iff, (isClopen_discrete _).eq_univ <| singleton_nonempty y] at hxy exact hxy (mem_univ x) #align preconnected_space.trivial_of_discrete PreconnectedSpace.trivial_of_discrete theorem IsPreconnected.infinite_of_nontrivial [T1Space X] {s : Set X} (h : IsPreconnected s) (hs : s.Nontrivial) : s.Infinite := by refine mt (fun hf => (subsingleton_coe s).mp ?_) (not_subsingleton_iff.mpr hs) haveI := @discrete_of_t1_of_finite s _ _ hf.to_subtype exact @PreconnectedSpace.trivial_of_discrete _ _ (Subtype.preconnectedSpace h) _ #align is_preconnected.infinite_of_nontrivial IsPreconnected.infinite_of_nontrivial theorem ConnectedSpace.infinite [ConnectedSpace X] [Nontrivial X] [T1Space X] : Infinite X := infinite_univ_iff.mp <| isPreconnected_univ.infinite_of_nontrivial nontrivial_univ #align connected_space.infinite ConnectedSpace.infinite /-- A non-trivial connected T1 space has no isolated points. -/ instance (priority := 100) ConnectedSpace.neBot_nhdsWithin_compl_of_nontrivial_of_t1space [ConnectedSpace X] [Nontrivial X] [T1Space X] (x : X) : NeBot (𝓝[≠] x) := by by_contra contra rw [not_neBot, ← isOpen_singleton_iff_punctured_nhds] at contra replace contra := nonempty_inter isOpen_compl_singleton contra (compl_union_self _) (Set.nonempty_compl_of_nontrivial _) (singleton_nonempty _) simp [compl_inter_self {x}] at contra theorem SeparationQuotient.t1Space_iff : T1Space (SeparationQuotient X) ↔ R0Space X := by rw [r0Space_iff, ((t1Space_TFAE (SeparationQuotient X)).out 0 9 :)] constructor · intro h x y xspecy rw [← Inducing.specializes_iff inducing_mk, h xspecy] at * · rintro h ⟨x⟩ ⟨y⟩ sxspecsy have xspecy : x ⤳ y := (Inducing.specializes_iff inducing_mk).mp sxspecsy have yspecx : y ⤳ x := h xspecy erw [mk_eq_mk, inseparable_iff_specializes_and] exact ⟨xspecy, yspecx⟩ theorem singleton_mem_nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : {x} ∈ 𝓝[s] x := by have : ({⟨x, hx⟩} : Set s) ∈ 𝓝 (⟨x, hx⟩ : s) := by simp [nhds_discrete] simpa only [nhdsWithin_eq_map_subtype_coe hx, image_singleton] using @image_mem_map _ _ _ ((↑) : s → X) _ this #align singleton_mem_nhds_within_of_mem_discrete singleton_mem_nhdsWithin_of_mem_discrete /-- The neighbourhoods filter of `x` within `s`, under the discrete topology, is equal to the pure `x` filter (which is the principal filter at the singleton `{x}`.) -/ theorem nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : 𝓝[s] x = pure x := le_antisymm (le_pure_iff.2 <| singleton_mem_nhdsWithin_of_mem_discrete hx) (pure_le_nhdsWithin hx) #align nhds_within_of_mem_discrete nhdsWithin_of_mem_discrete theorem Filter.HasBasis.exists_inter_eq_singleton_of_mem_discrete {ι : Type*} {p : ι → Prop} {t : ι → Set X} {s : Set X} [DiscreteTopology s] {x : X} (hb : (𝓝 x).HasBasis p t) (hx : x ∈ s) : ∃ i, p i ∧ t i ∩ s = {x} := by rcases (nhdsWithin_hasBasis hb s).mem_iff.1 (singleton_mem_nhdsWithin_of_mem_discrete hx) with ⟨i, hi, hix⟩ exact ⟨i, hi, hix.antisymm <| singleton_subset_iff.2 ⟨mem_of_mem_nhds <| hb.mem_of_mem hi, hx⟩⟩ #align filter.has_basis.exists_inter_eq_singleton_of_mem_discrete Filter.HasBasis.exists_inter_eq_singleton_of_mem_discrete /-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood that only meets `s` at `x`. -/ theorem nhds_inter_eq_singleton_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U ∈ 𝓝 x, U ∩ s = {x} := by simpa using (𝓝 x).basis_sets.exists_inter_eq_singleton_of_mem_discrete hx #align nhds_inter_eq_singleton_of_mem_discrete nhds_inter_eq_singleton_of_mem_discrete /-- Let `x` be a point in a discrete subset `s` of a topological space, then there exists an open set that only meets `s` at `x`. -/ theorem isOpen_inter_eq_singleton_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U : Set X, IsOpen U ∧ U ∩ s = {x} := by obtain ⟨U, hU_nhds, hU_inter⟩ := nhds_inter_eq_singleton_of_mem_discrete hx obtain ⟨t, ht_sub, ht_open, ht_x⟩ := mem_nhds_iff.mp hU_nhds refine ⟨t, ht_open, Set.Subset.antisymm ?_ ?_⟩ · exact hU_inter ▸ Set.inter_subset_inter_left s ht_sub · rw [Set.subset_inter_iff, Set.singleton_subset_iff, Set.singleton_subset_iff] exact ⟨ht_x, hx⟩ /-- For point `x` in a discrete subset `s` of a topological space, there is a set `U` such that 1. `U` is a punctured neighborhood of `x` (ie. `U ∪ {x}` is a neighbourhood of `x`), 2. `U` is disjoint from `s`. -/ theorem disjoint_nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U ∈ 𝓝[≠] x, Disjoint U s := let ⟨V, h, h'⟩ := nhds_inter_eq_singleton_of_mem_discrete hx ⟨{x}ᶜ ∩ V, inter_mem_nhdsWithin _ h, disjoint_iff_inter_eq_empty.mpr (by rw [inter_assoc, h', compl_inter_self])⟩ #align disjoint_nhds_within_of_mem_discrete disjoint_nhdsWithin_of_mem_discrete /-- Let `X` be a topological space and let `s, t ⊆ X` be two subsets. If there is an inclusion `t ⊆ s`, then the topological space structure on `t` induced by `X` is the same as the one obtained by the induced topological space structure on `s`. Use `embedding_inclusion` instead. -/ @[deprecated embedding_inclusion (since := "2023-02-02")] theorem TopologicalSpace.subset_trans {s t : Set X} (ts : t ⊆ s) : (instTopologicalSpaceSubtype : TopologicalSpace t) = (instTopologicalSpaceSubtype : TopologicalSpace s).induced (Set.inclusion ts) := (embedding_inclusion ts).induced #align topological_space.subset_trans TopologicalSpace.subset_trans /-! ### R₁ (preregular) spaces -/ section R1Space /-- A topological space is called a *preregular* (a.k.a. R₁) space, if any two topologically distinguishable points have disjoint neighbourhoods. -/ @[mk_iff r1Space_iff_specializes_or_disjoint_nhds] class R1Space (X : Type*) [TopologicalSpace X] : Prop where specializes_or_disjoint_nhds (x y : X) : Specializes x y ∨ Disjoint (𝓝 x) (𝓝 y) export R1Space (specializes_or_disjoint_nhds) variable [R1Space X] {x y : X} instance (priority := 100) : R0Space X where specializes_symmetric _ _ h := (specializes_or_disjoint_nhds _ _).resolve_right <| fun hd ↦ h.not_disjoint hd.symm theorem disjoint_nhds_nhds_iff_not_specializes : Disjoint (𝓝 x) (𝓝 y) ↔ ¬x ⤳ y := ⟨fun hd hspec ↦ hspec.not_disjoint hd, (specializes_or_disjoint_nhds _ _).resolve_left⟩ #align disjoint_nhds_nhds_iff_not_specializes disjoint_nhds_nhds_iff_not_specializes theorem specializes_iff_not_disjoint : x ⤳ y ↔ ¬Disjoint (𝓝 x) (𝓝 y) := disjoint_nhds_nhds_iff_not_specializes.not_left.symm theorem disjoint_nhds_nhds_iff_not_inseparable : Disjoint (𝓝 x) (𝓝 y) ↔ ¬Inseparable x y := by rw [disjoint_nhds_nhds_iff_not_specializes, specializes_iff_inseparable] theorem r1Space_iff_inseparable_or_disjoint_nhds {X : Type*} [TopologicalSpace X]: R1Space X ↔ ∀ x y : X, Inseparable x y ∨ Disjoint (𝓝 x) (𝓝 y) := ⟨fun _h x y ↦ (specializes_or_disjoint_nhds x y).imp_left Specializes.inseparable, fun h ↦ ⟨fun x y ↦ (h x y).imp_left Inseparable.specializes⟩⟩ theorem isClosed_setOf_specializes : IsClosed { p : X × X | p.1 ⤳ p.2 } := by simp only [← isOpen_compl_iff, compl_setOf, ← disjoint_nhds_nhds_iff_not_specializes, isOpen_setOf_disjoint_nhds_nhds] #align is_closed_set_of_specializes isClosed_setOf_specializes theorem isClosed_setOf_inseparable : IsClosed { p : X × X | Inseparable p.1 p.2 } := by simp only [← specializes_iff_inseparable, isClosed_setOf_specializes] #align is_closed_set_of_inseparable isClosed_setOf_inseparable /-- In an R₁ space, a point belongs to the closure of a compact set `K` if and only if it is topologically inseparable from some point of `K`. -/ theorem IsCompact.mem_closure_iff_exists_inseparable {K : Set X} (hK : IsCompact K) : y ∈ closure K ↔ ∃ x ∈ K, Inseparable x y := by refine ⟨fun hy ↦ ?_, fun ⟨x, hxK, hxy⟩ ↦ (hxy.mem_closed_iff isClosed_closure).1 <| subset_closure hxK⟩ contrapose! hy have : Disjoint (𝓝 y) (𝓝ˢ K) := hK.disjoint_nhdsSet_right.2 fun x hx ↦ (disjoint_nhds_nhds_iff_not_inseparable.2 (hy x hx)).symm simpa only [disjoint_iff, not_mem_closure_iff_nhdsWithin_eq_bot] using this.mono_right principal_le_nhdsSet theorem IsCompact.closure_eq_biUnion_inseparable {K : Set X} (hK : IsCompact K) : closure K = ⋃ x ∈ K, {y | Inseparable x y} := by ext; simp [hK.mem_closure_iff_exists_inseparable] /-- In an R₁ space, the closure of a compact set is the union of the closures of its points. -/ theorem IsCompact.closure_eq_biUnion_closure_singleton {K : Set X} (hK : IsCompact K) : closure K = ⋃ x ∈ K, closure {x} := by simp only [hK.closure_eq_biUnion_inseparable, ← specializes_iff_inseparable, specializes_iff_mem_closure, setOf_mem_eq] /-- In an R₁ space, if a compact set `K` is contained in an open set `U`, then its closure is also contained in `U`. -/ theorem IsCompact.closure_subset_of_isOpen {K : Set X} (hK : IsCompact K) {U : Set X} (hU : IsOpen U) (hKU : K ⊆ U) : closure K ⊆ U := by rw [hK.closure_eq_biUnion_inseparable, iUnion₂_subset_iff] exact fun x hx y hxy ↦ (hxy.mem_open_iff hU).1 (hKU hx) /-- The closure of a compact set in an R₁ space is a compact set. -/ protected theorem IsCompact.closure {K : Set X} (hK : IsCompact K) : IsCompact (closure K) := by refine isCompact_of_finite_subcover fun U hUo hKU ↦ ?_ rcases hK.elim_finite_subcover U hUo (subset_closure.trans hKU) with ⟨t, ht⟩ exact ⟨t, hK.closure_subset_of_isOpen (isOpen_biUnion fun _ _ ↦ hUo _) ht⟩ theorem IsCompact.closure_of_subset {s K : Set X} (hK : IsCompact K) (h : s ⊆ K) : IsCompact (closure s) := hK.closure.of_isClosed_subset isClosed_closure (closure_mono h) #align is_compact_closure_of_subset_compact IsCompact.closure_of_subset @[deprecated (since := "2024-01-28")] alias isCompact_closure_of_subset_compact := IsCompact.closure_of_subset @[simp] theorem exists_isCompact_superset_iff {s : Set X} : (∃ K, IsCompact K ∧ s ⊆ K) ↔ IsCompact (closure s) := ⟨fun ⟨_K, hK, hsK⟩ => hK.closure_of_subset hsK, fun h => ⟨closure s, h, subset_closure⟩⟩ #align exists_compact_superset_iff exists_isCompact_superset_iff @[deprecated (since := "2024-01-28")] alias exists_compact_superset_iff := exists_isCompact_superset_iff /-- If `K` and `L` are disjoint compact sets in an R₁ topological space and `L` is also closed, then `K` and `L` have disjoint neighborhoods. -/ theorem SeparatedNhds.of_isCompact_isCompact_isClosed {K L : Set X} (hK : IsCompact K) (hL : IsCompact L) (h'L : IsClosed L) (hd : Disjoint K L) : SeparatedNhds K L := by simp_rw [separatedNhds_iff_disjoint, hK.disjoint_nhdsSet_left, hL.disjoint_nhdsSet_right, disjoint_nhds_nhds_iff_not_inseparable] intro x hx y hy h exact absurd ((h.mem_closed_iff h'L).2 hy) <| disjoint_left.1 hd hx @[deprecated (since := "2024-01-28")] alias separatedNhds_of_isCompact_isCompact_isClosed := SeparatedNhds.of_isCompact_isCompact_isClosed /-- If a compact set is covered by two open sets, then we can cover it by two compact subsets. -/ theorem IsCompact.binary_compact_cover {K U V : Set X} (hK : IsCompact K) (hU : IsOpen U) (hV : IsOpen V) (h2K : K ⊆ U ∪ V) : ∃ K₁ K₂ : Set X, IsCompact K₁ ∧ IsCompact K₂ ∧ K₁ ⊆ U ∧ K₂ ⊆ V ∧ K = K₁ ∪ K₂ := by have hK' : IsCompact (closure K) := hK.closure have : SeparatedNhds (closure K \ U) (closure K \ V) := by apply SeparatedNhds.of_isCompact_isCompact_isClosed (hK'.diff hU) (hK'.diff hV) (isClosed_closure.sdiff hV) rw [disjoint_iff_inter_eq_empty, diff_inter_diff, diff_eq_empty] exact hK.closure_subset_of_isOpen (hU.union hV) h2K have : SeparatedNhds (K \ U) (K \ V) := this.mono (diff_subset_diff_left (subset_closure)) (diff_subset_diff_left (subset_closure)) rcases this with ⟨O₁, O₂, h1O₁, h1O₂, h2O₁, h2O₂, hO⟩ exact ⟨K \ O₁, K \ O₂, hK.diff h1O₁, hK.diff h1O₂, diff_subset_comm.mp h2O₁, diff_subset_comm.mp h2O₂, by rw [← diff_inter, hO.inter_eq, diff_empty]⟩ #align is_compact.binary_compact_cover IsCompact.binary_compact_cover /-- For every finite open cover `Uᵢ` of a compact set, there exists a compact cover `Kᵢ ⊆ Uᵢ`. -/ theorem IsCompact.finite_compact_cover {s : Set X} (hs : IsCompact s) {ι : Type*} (t : Finset ι) (U : ι → Set X) (hU : ∀ i ∈ t, IsOpen (U i)) (hsC : s ⊆ ⋃ i ∈ t, U i) : ∃ K : ι → Set X, (∀ i, IsCompact (K i)) ∧ (∀ i, K i ⊆ U i) ∧ s = ⋃ i ∈ t, K i := by induction' t using Finset.induction with x t hx ih generalizing U s · refine ⟨fun _ => ∅, fun _ => isCompact_empty, fun i => empty_subset _, ?_⟩ simpa only [subset_empty_iff, Finset.not_mem_empty, iUnion_false, iUnion_empty] using hsC simp only [Finset.set_biUnion_insert] at hsC simp only [Finset.forall_mem_insert] at hU have hU' : ∀ i ∈ t, IsOpen (U i) := fun i hi => hU.2 i hi rcases hs.binary_compact_cover hU.1 (isOpen_biUnion hU') hsC with ⟨K₁, K₂, h1K₁, h1K₂, h2K₁, h2K₂, hK⟩ rcases ih h1K₂ U hU' h2K₂ with ⟨K, h1K, h2K, h3K⟩ refine ⟨update K x K₁, ?_, ?_, ?_⟩ · intro i rcases eq_or_ne i x with rfl | hi · simp only [update_same, h1K₁] · simp only [update_noteq hi, h1K] · intro i rcases eq_or_ne i x with rfl | hi · simp only [update_same, h2K₁] · simp only [update_noteq hi, h2K] · simp only [Finset.set_biUnion_insert_update _ hx, hK, h3K] #align is_compact.finite_compact_cover IsCompact.finite_compact_cover theorem R1Space.of_continuous_specializes_imp [TopologicalSpace Y] {f : Y → X} (hc : Continuous f) (hspec : ∀ x y, f x ⤳ f y → x ⤳ y) : R1Space Y where specializes_or_disjoint_nhds x y := (specializes_or_disjoint_nhds (f x) (f y)).imp (hspec x y) <| ((hc.tendsto _).disjoint · (hc.tendsto _)) theorem Inducing.r1Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R1Space Y := .of_continuous_specializes_imp hf.continuous fun _ _ ↦ hf.specializes_iff.1 protected theorem R1Space.induced (f : Y → X) : @R1Space Y (.induced f ‹_›) := @Inducing.r1Space _ _ _ _ (.induced f _) f (inducing_induced f) instance (p : X → Prop) : R1Space (Subtype p) := .induced _ protected theorem R1Space.sInf {X : Type*} {T : Set (TopologicalSpace X)} (hT : ∀ t ∈ T, @R1Space X t) : @R1Space X (sInf T) := by let _ := sInf T refine ⟨fun x y ↦ ?_⟩ simp only [Specializes, nhds_sInf] rcases em (∃ t ∈ T, Disjoint (@nhds X t x) (@nhds X t y)) with ⟨t, htT, htd⟩ | hTd · exact .inr <| htd.mono (iInf₂_le t htT) (iInf₂_le t htT) · push_neg at hTd exact .inl <| iInf₂_mono fun t ht ↦ ((hT t ht).1 x y).resolve_right (hTd t ht) protected theorem R1Space.iInf {ι X : Type*} {t : ι → TopologicalSpace X} (ht : ∀ i, @R1Space X (t i)) : @R1Space X (iInf t) := .sInf <| forall_mem_range.2 ht protected theorem R1Space.inf {X : Type*} {t₁ t₂ : TopologicalSpace X} (h₁ : @R1Space X t₁) (h₂ : @R1Space X t₂) : @R1Space X (t₁ ⊓ t₂) := by rw [inf_eq_iInf] apply R1Space.iInf simp [*] instance [TopologicalSpace Y] [R1Space Y] : R1Space (X × Y) := .inf (.induced _) (.induced _) instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R1Space (X i)] : R1Space (∀ i, X i) := .iInf fun _ ↦ .induced _ theorem exists_mem_nhds_isCompact_mapsTo_of_isCompact_mem_nhds {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [R1Space Y] {f : X → Y} {x : X} {K : Set X} {s : Set Y} (hf : Continuous f) (hs : s ∈ 𝓝 (f x)) (hKc : IsCompact K) (hKx : K ∈ 𝓝 x) : ∃ K ∈ 𝓝 x, IsCompact K ∧ MapsTo f K s := by have hc : IsCompact (f '' K \ interior s) := (hKc.image hf).diff isOpen_interior obtain ⟨U, V, Uo, Vo, hxU, hV, hd⟩ : SeparatedNhds {f x} (f '' K \ interior s) := by simp_rw [separatedNhds_iff_disjoint, nhdsSet_singleton, hc.disjoint_nhdsSet_right, disjoint_nhds_nhds_iff_not_inseparable] rintro y ⟨-, hys⟩ hxy refine hys <| (hxy.mem_open_iff isOpen_interior).1 ?_ rwa [mem_interior_iff_mem_nhds] refine ⟨K \ f ⁻¹' V, diff_mem hKx ?_, hKc.diff <| Vo.preimage hf, fun y hy ↦ ?_⟩ · filter_upwards [hf.continuousAt <| Uo.mem_nhds (hxU rfl)] with x hx using Set.disjoint_left.1 hd hx · by_contra hys exact hy.2 (hV ⟨mem_image_of_mem _ hy.1, not_mem_subset interior_subset hys⟩) instance (priority := 900) {X Y : Type*} [TopologicalSpace X] [WeaklyLocallyCompactSpace X] [TopologicalSpace Y] [R1Space Y] : LocallyCompactPair X Y where exists_mem_nhds_isCompact_mapsTo hf hs := let ⟨_K, hKc, hKx⟩ := exists_compact_mem_nhds _ exists_mem_nhds_isCompact_mapsTo_of_isCompact_mem_nhds hf hs hKc hKx /-- If a point in an R₁ space has a compact neighborhood, then it has a basis of compact closed neighborhoods. -/ theorem IsCompact.isCompact_isClosed_basis_nhds {x : X} {L : Set X} (hLc : IsCompact L) (hxL : L ∈ 𝓝 x) : (𝓝 x).HasBasis (fun K ↦ K ∈ 𝓝 x ∧ IsCompact K ∧ IsClosed K) (·) := hasBasis_self.2 fun _U hU ↦ let ⟨K, hKx, hKc, hKU⟩ := exists_mem_nhds_isCompact_mapsTo_of_isCompact_mem_nhds continuous_id (interior_mem_nhds.2 hU) hLc hxL ⟨closure K, mem_of_superset hKx subset_closure, ⟨hKc.closure, isClosed_closure⟩, (hKc.closure_subset_of_isOpen isOpen_interior hKU).trans interior_subset⟩ /-- In an R₁ space, the filters `coclosedCompact` and `cocompact` are equal. -/ @[simp] theorem Filter.coclosedCompact_eq_cocompact : coclosedCompact X = cocompact X := by refine le_antisymm ?_ cocompact_le_coclosedCompact rw [hasBasis_coclosedCompact.le_basis_iff hasBasis_cocompact] exact fun K hK ↦ ⟨closure K, ⟨isClosed_closure, hK.closure⟩, compl_subset_compl.2 subset_closure⟩ #align filter.coclosed_compact_eq_cocompact Filter.coclosedCompact_eq_cocompact /-- In an R₁ space, the bornologies `relativelyCompact` and `inCompact` are equal. -/ @[simp] theorem Bornology.relativelyCompact_eq_inCompact : Bornology.relativelyCompact X = Bornology.inCompact X := Bornology.ext _ _ Filter.coclosedCompact_eq_cocompact #align bornology.relatively_compact_eq_in_compact Bornology.relativelyCompact_eq_inCompact /-! ### Lemmas about a weakly locally compact R₁ space In fact, a space with these properties is locally compact and regular. Some lemmas are formulated using the latter assumptions below. -/ variable [WeaklyLocallyCompactSpace X] /-- In a (weakly) locally compact R₁ space, compact closed neighborhoods of a point `x` form a basis of neighborhoods of `x`. -/ theorem isCompact_isClosed_basis_nhds (x : X) : (𝓝 x).HasBasis (fun K => K ∈ 𝓝 x ∧ IsCompact K ∧ IsClosed K) (·) := let ⟨_L, hLc, hLx⟩ := exists_compact_mem_nhds x hLc.isCompact_isClosed_basis_nhds hLx /-- In a (weakly) locally compact R₁ space, each point admits a compact closed neighborhood. -/ theorem exists_mem_nhds_isCompact_isClosed (x : X) : ∃ K ∈ 𝓝 x, IsCompact K ∧ IsClosed K := (isCompact_isClosed_basis_nhds x).ex_mem -- see Note [lower instance priority] /-- A weakly locally compact R₁ space is locally compact. -/ instance (priority := 80) WeaklyLocallyCompactSpace.locallyCompactSpace : LocallyCompactSpace X := .of_hasBasis isCompact_isClosed_basis_nhds fun _ _ ⟨_, h, _⟩ ↦ h #align locally_compact_of_compact_nhds WeaklyLocallyCompactSpace.locallyCompactSpace /-- In a weakly locally compact R₁ space, every compact set has an open neighborhood with compact closure. -/ theorem exists_isOpen_superset_and_isCompact_closure {K : Set X} (hK : IsCompact K) : ∃ V, IsOpen V ∧ K ⊆ V ∧ IsCompact (closure V) := by rcases exists_compact_superset hK with ⟨K', hK', hKK'⟩ exact ⟨interior K', isOpen_interior, hKK', hK'.closure_of_subset interior_subset⟩ #align exists_open_superset_and_is_compact_closure exists_isOpen_superset_and_isCompact_closure @[deprecated (since := "2024-01-28")] alias exists_open_superset_and_isCompact_closure := exists_isOpen_superset_and_isCompact_closure /-- In a weakly locally compact R₁ space, every point has an open neighborhood with compact closure. -/ theorem exists_isOpen_mem_isCompact_closure (x : X) : ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ IsCompact (closure U) := by simpa only [singleton_subset_iff] using exists_isOpen_superset_and_isCompact_closure isCompact_singleton #align exists_open_with_compact_closure exists_isOpen_mem_isCompact_closure @[deprecated (since := "2024-01-28")] alias exists_open_with_compact_closure := exists_isOpen_mem_isCompact_closure end R1Space /-- A T₂ space, also known as a Hausdorff space, is one in which for every `x ≠ y` there exists disjoint open sets around `x` and `y`. This is the most widely used of the separation axioms. -/ @[mk_iff] class T2Space (X : Type u) [TopologicalSpace X] : Prop where /-- Every two points in a Hausdorff space admit disjoint open neighbourhoods. -/ t2 : Pairwise fun x y => ∃ u v : Set X, IsOpen u ∧ IsOpen v ∧ x ∈ u ∧ y ∈ v ∧ Disjoint u v #align t2_space T2Space /-- Two different points can be separated by open sets. -/ theorem t2_separation [T2Space X] {x y : X} (h : x ≠ y) : ∃ u v : Set X, IsOpen u ∧ IsOpen v ∧ x ∈ u ∧ y ∈ v ∧ Disjoint u v := T2Space.t2 h #align t2_separation t2_separation -- todo: use this as a definition? theorem t2Space_iff_disjoint_nhds : T2Space X ↔ Pairwise fun x y : X => Disjoint (𝓝 x) (𝓝 y) := by refine (t2Space_iff X).trans (forall₃_congr fun x y _ => ?_) simp only [(nhds_basis_opens x).disjoint_iff (nhds_basis_opens y), exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align t2_space_iff_disjoint_nhds t2Space_iff_disjoint_nhds @[simp] theorem disjoint_nhds_nhds [T2Space X] {x y : X} : Disjoint (𝓝 x) (𝓝 y) ↔ x ≠ y := ⟨fun hd he => by simp [he, nhds_neBot.ne] at hd, (t2Space_iff_disjoint_nhds.mp ‹_› ·)⟩ #align disjoint_nhds_nhds disjoint_nhds_nhds theorem pairwise_disjoint_nhds [T2Space X] : Pairwise (Disjoint on (𝓝 : X → Filter X)) := fun _ _ => disjoint_nhds_nhds.2 #align pairwise_disjoint_nhds pairwise_disjoint_nhds protected theorem Set.pairwiseDisjoint_nhds [T2Space X] (s : Set X) : s.PairwiseDisjoint 𝓝 := pairwise_disjoint_nhds.set_pairwise s #align set.pairwise_disjoint_nhds Set.pairwiseDisjoint_nhds /-- Points of a finite set can be separated by open sets from each other. -/ theorem Set.Finite.t2_separation [T2Space X] {s : Set X} (hs : s.Finite) : ∃ U : X → Set X, (∀ x, x ∈ U x ∧ IsOpen (U x)) ∧ s.PairwiseDisjoint U := s.pairwiseDisjoint_nhds.exists_mem_filter_basis hs nhds_basis_opens #align set.finite.t2_separation Set.Finite.t2_separation -- see Note [lower instance priority] instance (priority := 100) T2Space.t1Space [T2Space X] : T1Space X := t1Space_iff_disjoint_pure_nhds.mpr fun _ _ hne => (disjoint_nhds_nhds.2 hne).mono_left <| pure_le_nhds _ #align t2_space.t1_space T2Space.t1Space -- see Note [lower instance priority] instance (priority := 100) T2Space.r1Space [T2Space X] : R1Space X := ⟨fun x y ↦ (eq_or_ne x y).imp specializes_of_eq disjoint_nhds_nhds.2⟩ theorem SeparationQuotient.t2Space_iff : T2Space (SeparationQuotient X) ↔ R1Space X := by simp only [t2Space_iff_disjoint_nhds, Pairwise, surjective_mk.forall₂, ne_eq, mk_eq_mk, r1Space_iff_inseparable_or_disjoint_nhds, ← disjoint_comap_iff surjective_mk, comap_mk_nhds_mk, ← or_iff_not_imp_left] instance SeparationQuotient.t2Space [R1Space X] : T2Space (SeparationQuotient X) := t2Space_iff.2 ‹_› instance (priority := 80) [R1Space X] [T0Space X] : T2Space X := t2Space_iff_disjoint_nhds.2 fun _x _y hne ↦ disjoint_nhds_nhds_iff_not_inseparable.2 fun hxy ↦ hne hxy.eq theorem R1Space.t2Space_iff_t0Space [R1Space X] : T2Space X ↔ T0Space X := by constructor <;> intro <;> infer_instance /-- A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. -/ theorem t2_iff_nhds : T2Space X ↔ ∀ {x y : X}, NeBot (𝓝 x ⊓ 𝓝 y) → x = y := by simp only [t2Space_iff_disjoint_nhds, disjoint_iff, neBot_iff, Ne, not_imp_comm, Pairwise] #align t2_iff_nhds t2_iff_nhds theorem eq_of_nhds_neBot [T2Space X] {x y : X} (h : NeBot (𝓝 x ⊓ 𝓝 y)) : x = y := t2_iff_nhds.mp ‹_› h #align eq_of_nhds_ne_bot eq_of_nhds_neBot theorem t2Space_iff_nhds : T2Space X ↔ Pairwise fun x y : X => ∃ U ∈ 𝓝 x, ∃ V ∈ 𝓝 y, Disjoint U V := by simp only [t2Space_iff_disjoint_nhds, Filter.disjoint_iff, Pairwise] #align t2_space_iff_nhds t2Space_iff_nhds theorem t2_separation_nhds [T2Space X] {x y : X} (h : x ≠ y) : ∃ u v, u ∈ 𝓝 x ∧ v ∈ 𝓝 y ∧ Disjoint u v := let ⟨u, v, open_u, open_v, x_in, y_in, huv⟩ := t2_separation h ⟨u, v, open_u.mem_nhds x_in, open_v.mem_nhds y_in, huv⟩ #align t2_separation_nhds t2_separation_nhds theorem t2_separation_compact_nhds [LocallyCompactSpace X] [T2Space X] {x y : X} (h : x ≠ y) : ∃ u v, u ∈ 𝓝 x ∧ v ∈ 𝓝 y ∧ IsCompact u ∧ IsCompact v ∧ Disjoint u v := by simpa only [exists_prop, ← exists_and_left, and_comm, and_assoc, and_left_comm] using ((compact_basis_nhds x).disjoint_iff (compact_basis_nhds y)).1 (disjoint_nhds_nhds.2 h) #align t2_separation_compact_nhds t2_separation_compact_nhds theorem t2_iff_ultrafilter : T2Space X ↔ ∀ {x y : X} (f : Ultrafilter X), ↑f ≤ 𝓝 x → ↑f ≤ 𝓝 y → x = y := t2_iff_nhds.trans <| by simp only [← exists_ultrafilter_iff, and_imp, le_inf_iff, exists_imp] #align t2_iff_ultrafilter t2_iff_ultrafilter theorem t2_iff_isClosed_diagonal : T2Space X ↔ IsClosed (diagonal X) := by simp only [t2Space_iff_disjoint_nhds, ← isOpen_compl_iff, isOpen_iff_mem_nhds, Prod.forall, nhds_prod_eq, compl_diagonal_mem_prod, mem_compl_iff, mem_diagonal_iff, Pairwise] #align t2_iff_is_closed_diagonal t2_iff_isClosed_diagonal theorem isClosed_diagonal [T2Space X] : IsClosed (diagonal X) := t2_iff_isClosed_diagonal.mp ‹_› #align is_closed_diagonal isClosed_diagonal -- Porting note: 2 lemmas moved below theorem tendsto_nhds_unique [T2Space X] {f : Y → X} {l : Filter Y} {a b : X} [NeBot l] (ha : Tendsto f l (𝓝 a)) (hb : Tendsto f l (𝓝 b)) : a = b := eq_of_nhds_neBot <| neBot_of_le <| le_inf ha hb #align tendsto_nhds_unique tendsto_nhds_unique theorem tendsto_nhds_unique' [T2Space X] {f : Y → X} {l : Filter Y} {a b : X} (_ : NeBot l) (ha : Tendsto f l (𝓝 a)) (hb : Tendsto f l (𝓝 b)) : a = b := eq_of_nhds_neBot <| neBot_of_le <| le_inf ha hb #align tendsto_nhds_unique' tendsto_nhds_unique' theorem tendsto_nhds_unique_of_eventuallyEq [T2Space X] {f g : Y → X} {l : Filter Y} {a b : X} [NeBot l] (ha : Tendsto f l (𝓝 a)) (hb : Tendsto g l (𝓝 b)) (hfg : f =ᶠ[l] g) : a = b := tendsto_nhds_unique (ha.congr' hfg) hb #align tendsto_nhds_unique_of_eventually_eq tendsto_nhds_unique_of_eventuallyEq theorem tendsto_nhds_unique_of_frequently_eq [T2Space X] {f g : Y → X} {l : Filter Y} {a b : X} (ha : Tendsto f l (𝓝 a)) (hb : Tendsto g l (𝓝 b)) (hfg : ∃ᶠ x in l, f x = g x) : a = b := have : ∃ᶠ z : X × X in 𝓝 (a, b), z.1 = z.2 := (ha.prod_mk_nhds hb).frequently hfg not_not.1 fun hne => this (isClosed_diagonal.isOpen_compl.mem_nhds hne) #align tendsto_nhds_unique_of_frequently_eq tendsto_nhds_unique_of_frequently_eq /-- If `s` and `t` are compact sets in a T₂ space, then the set neighborhoods filter of `s ∩ t` is the infimum of set neighborhoods filters for `s` and `t`. For general sets, only the `≤` inequality holds, see `nhdsSet_inter_le`. -/ theorem IsCompact.nhdsSet_inter_eq [T2Space X] {s t : Set X} (hs : IsCompact s) (ht : IsCompact t) : 𝓝ˢ (s ∩ t) = 𝓝ˢ s ⊓ 𝓝ˢ t := by refine le_antisymm (nhdsSet_inter_le _ _) ?_ simp_rw [hs.nhdsSet_inf_eq_biSup, ht.inf_nhdsSet_eq_biSup, nhdsSet, sSup_image] refine iSup₂_le fun x hxs ↦ iSup₂_le fun y hyt ↦ ?_ rcases eq_or_ne x y with (rfl|hne) · exact le_iSup₂_of_le x ⟨hxs, hyt⟩ (inf_idem _).le · exact (disjoint_nhds_nhds.mpr hne).eq_bot ▸ bot_le /-- If a function `f` is - injective on a compact set `s`; - continuous at every point of this set; - injective on a neighborhood of each point of this set, then it is injective on a neighborhood of this set. -/
Mathlib/Topology/Separation.lean
1,438
1,450
theorem Set.InjOn.exists_mem_nhdsSet {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} {s : Set X} (inj : InjOn f s) (sc : IsCompact s) (fc : ∀ x ∈ s, ContinuousAt f x) (loc : ∀ x ∈ s, ∃ u ∈ 𝓝 x, InjOn f u) : ∃ t ∈ 𝓝ˢ s, InjOn f t := by
have : ∀ x ∈ s ×ˢ s, ∀ᶠ y in 𝓝 x, f y.1 = f y.2 → y.1 = y.2 := fun (x, y) ⟨hx, hy⟩ ↦ by rcases eq_or_ne x y with rfl | hne · rcases loc x hx with ⟨u, hu, hf⟩ exact Filter.mem_of_superset (prod_mem_nhds hu hu) <| forall_prod_set.2 hf · suffices ∀ᶠ z in 𝓝 (x, y), f z.1 ≠ f z.2 from this.mono fun _ hne h ↦ absurd h hne refine (fc x hx).prod_map' (fc y hy) <| isClosed_diagonal.isOpen_compl.mem_nhds ?_ exact inj.ne hx hy hne rw [← eventually_nhdsSet_iff_forall, sc.nhdsSet_prod_eq sc] at this exact eventually_prod_self_iff.1 this
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel, Bhavik Mehta, Andrew Yang, Emily Riehl -/ import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts #align_import category_theory.limits.shapes.pullbacks from "leanprover-community/mathlib"@"7316286ff2942aa14e540add9058c6b0aa1c8070" /-! # Pullbacks We define a category `WalkingCospan` (resp. `WalkingSpan`), which is the index category for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g` and `span f g` construct functors from the walking (co)span, hitting the given morphisms. We define `pullback f g` and `pushout f g` as limits and colimits of such functors. ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits -- attribute [local tidy] tactic.case_bash Porting note: no tidy, no local /-- The type of objects for the diagram indexing a pullback, defined as a special case of `WidePullbackShape`. -/ abbrev WalkingCospan : Type := WidePullbackShape WalkingPair #align category_theory.limits.walking_cospan CategoryTheory.Limits.WalkingCospan /-- The left point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.left : WalkingCospan := some WalkingPair.left #align category_theory.limits.walking_cospan.left CategoryTheory.Limits.WalkingCospan.left /-- The right point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.right : WalkingCospan := some WalkingPair.right #align category_theory.limits.walking_cospan.right CategoryTheory.Limits.WalkingCospan.right /-- The central point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.one : WalkingCospan := none #align category_theory.limits.walking_cospan.one CategoryTheory.Limits.WalkingCospan.one /-- The type of objects for the diagram indexing a pushout, defined as a special case of `WidePushoutShape`. -/ abbrev WalkingSpan : Type := WidePushoutShape WalkingPair #align category_theory.limits.walking_span CategoryTheory.Limits.WalkingSpan /-- The left point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.left : WalkingSpan := some WalkingPair.left #align category_theory.limits.walking_span.left CategoryTheory.Limits.WalkingSpan.left /-- The right point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.right : WalkingSpan := some WalkingPair.right #align category_theory.limits.walking_span.right CategoryTheory.Limits.WalkingSpan.right /-- The central point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.zero : WalkingSpan := none #align category_theory.limits.walking_span.zero CategoryTheory.Limits.WalkingSpan.zero namespace WalkingCospan /-- The type of arrows for the diagram indexing a pullback. -/ abbrev Hom : WalkingCospan → WalkingCospan → Type := WidePullbackShape.Hom #align category_theory.limits.walking_cospan.hom CategoryTheory.Limits.WalkingCospan.Hom /-- The left arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inl : left ⟶ one := WidePullbackShape.Hom.term _ #align category_theory.limits.walking_cospan.hom.inl CategoryTheory.Limits.WalkingCospan.Hom.inl /-- The right arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inr : right ⟶ one := WidePullbackShape.Hom.term _ #align category_theory.limits.walking_cospan.hom.inr CategoryTheory.Limits.WalkingCospan.Hom.inr /-- The identity arrows of the walking cospan. -/ @[match_pattern] abbrev Hom.id (X : WalkingCospan) : X ⟶ X := WidePullbackShape.Hom.id X #align category_theory.limits.walking_cospan.hom.id CategoryTheory.Limits.WalkingCospan.Hom.id instance (X Y : WalkingCospan) : Subsingleton (X ⟶ Y) := by constructor; intros; simp [eq_iff_true_of_subsingleton] end WalkingCospan namespace WalkingSpan /-- The type of arrows for the diagram indexing a pushout. -/ abbrev Hom : WalkingSpan → WalkingSpan → Type := WidePushoutShape.Hom #align category_theory.limits.walking_span.hom CategoryTheory.Limits.WalkingSpan.Hom /-- The left arrow of the walking span. -/ @[match_pattern] abbrev Hom.fst : zero ⟶ left := WidePushoutShape.Hom.init _ #align category_theory.limits.walking_span.hom.fst CategoryTheory.Limits.WalkingSpan.Hom.fst /-- The right arrow of the walking span. -/ @[match_pattern] abbrev Hom.snd : zero ⟶ right := WidePushoutShape.Hom.init _ #align category_theory.limits.walking_span.hom.snd CategoryTheory.Limits.WalkingSpan.Hom.snd /-- The identity arrows of the walking span. -/ @[match_pattern] abbrev Hom.id (X : WalkingSpan) : X ⟶ X := WidePushoutShape.Hom.id X #align category_theory.limits.walking_span.hom.id CategoryTheory.Limits.WalkingSpan.Hom.id instance (X Y : WalkingSpan) : Subsingleton (X ⟶ Y) := by constructor; intros a b; simp [eq_iff_true_of_subsingleton] end WalkingSpan open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] /-- To construct an isomorphism of cones over the walking cospan, it suffices to construct an isomorphism of the cone points and check it commutes with the legs to `left` and `right`. -/ def WalkingCospan.ext {F : WalkingCospan ⥤ C} {s t : Cone F} (i : s.pt ≅ t.pt) (w₁ : s.π.app WalkingCospan.left = i.hom ≫ t.π.app WalkingCospan.left) (w₂ : s.π.app WalkingCospan.right = i.hom ≫ t.π.app WalkingCospan.right) : s ≅ t := by apply Cones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.π.naturality WalkingCospan.Hom.inl dsimp at h₁ simp only [Category.id_comp] at h₁ have h₂ := t.π.naturality WalkingCospan.Hom.inl dsimp at h₂ simp only [Category.id_comp] at h₂ simp_rw [h₂, ← Category.assoc, ← w₁, ← h₁] · exact w₁ · exact w₂ #align category_theory.limits.walking_cospan.ext CategoryTheory.Limits.WalkingCospan.ext /-- To construct an isomorphism of cocones over the walking span, it suffices to construct an isomorphism of the cocone points and check it commutes with the legs from `left` and `right`. -/ def WalkingSpan.ext {F : WalkingSpan ⥤ C} {s t : Cocone F} (i : s.pt ≅ t.pt) (w₁ : s.ι.app WalkingCospan.left ≫ i.hom = t.ι.app WalkingCospan.left) (w₂ : s.ι.app WalkingCospan.right ≫ i.hom = t.ι.app WalkingCospan.right) : s ≅ t := by apply Cocones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.ι.naturality WalkingSpan.Hom.fst dsimp at h₁ simp only [Category.comp_id] at h₁ have h₂ := t.ι.naturality WalkingSpan.Hom.fst dsimp at h₂ simp only [Category.comp_id] at h₂ simp_rw [← h₁, Category.assoc, w₁, h₂] · exact w₁ · exact w₂ #align category_theory.limits.walking_span.ext CategoryTheory.Limits.WalkingSpan.ext /-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/ def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : WalkingCospan ⥤ C := WidePullbackShape.wideCospan Z (fun j => WalkingPair.casesOn j X Y) fun j => WalkingPair.casesOn j f g #align category_theory.limits.cospan CategoryTheory.Limits.cospan /-- `span f g` is the functor from the walking span hitting `f` and `g`. -/ def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : WalkingSpan ⥤ C := WidePushoutShape.wideSpan X (fun j => WalkingPair.casesOn j Y Z) fun j => WalkingPair.casesOn j f g #align category_theory.limits.span CategoryTheory.Limits.span @[simp] theorem cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.left = X := rfl #align category_theory.limits.cospan_left CategoryTheory.Limits.cospan_left @[simp] theorem span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.left = Y := rfl #align category_theory.limits.span_left CategoryTheory.Limits.span_left @[simp] theorem cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.right = Y := rfl #align category_theory.limits.cospan_right CategoryTheory.Limits.cospan_right @[simp] theorem span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.right = Z := rfl #align category_theory.limits.span_right CategoryTheory.Limits.span_right @[simp] theorem cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.one = Z := rfl #align category_theory.limits.cospan_one CategoryTheory.Limits.cospan_one @[simp] theorem span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.zero = X := rfl #align category_theory.limits.span_zero CategoryTheory.Limits.span_zero @[simp] theorem cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inl = f := rfl #align category_theory.limits.cospan_map_inl CategoryTheory.Limits.cospan_map_inl @[simp] theorem span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.fst = f := rfl #align category_theory.limits.span_map_fst CategoryTheory.Limits.span_map_fst @[simp] theorem cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inr = g := rfl #align category_theory.limits.cospan_map_inr CategoryTheory.Limits.cospan_map_inr @[simp] theorem span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.snd = g := rfl #align category_theory.limits.span_map_snd CategoryTheory.Limits.span_map_snd theorem cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : WalkingCospan) : (cospan f g).map (WalkingCospan.Hom.id w) = 𝟙 _ := rfl #align category_theory.limits.cospan_map_id CategoryTheory.Limits.cospan_map_id theorem span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : WalkingSpan) : (span f g).map (WalkingSpan.Hom.id w) = 𝟙 _ := rfl #align category_theory.limits.span_map_id CategoryTheory.Limits.span_map_id /-- Every diagram indexing a pullback is naturally isomorphic (actually, equal) to a `cospan` -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] def diagramIsoCospan (F : WalkingCospan ⥤ C) : F ≅ cospan (F.map inl) (F.map inr) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.diagram_iso_cospan CategoryTheory.Limits.diagramIsoCospan /-- Every diagram indexing a pushout is naturally isomorphic (actually, equal) to a `span` -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] def diagramIsoSpan (F : WalkingSpan ⥤ C) : F ≅ span (F.map fst) (F.map snd) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.diagram_iso_span CategoryTheory.Limits.diagramIsoSpan variable {D : Type u₂} [Category.{v₂} D] /-- A functor applied to a cospan is a cospan. -/ def cospanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : cospan f g ⋙ F ≅ cospan (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.cospan_comp_iso CategoryTheory.Limits.cospanCompIso section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) @[simp] theorem cospanCompIso_app_left : (cospanCompIso F f g).app WalkingCospan.left = Iso.refl _ := rfl #align category_theory.limits.cospan_comp_iso_app_left CategoryTheory.Limits.cospanCompIso_app_left @[simp] theorem cospanCompIso_app_right : (cospanCompIso F f g).app WalkingCospan.right = Iso.refl _ := rfl #align category_theory.limits.cospan_comp_iso_app_right CategoryTheory.Limits.cospanCompIso_app_right @[simp] theorem cospanCompIso_app_one : (cospanCompIso F f g).app WalkingCospan.one = Iso.refl _ := rfl #align category_theory.limits.cospan_comp_iso_app_one CategoryTheory.Limits.cospanCompIso_app_one @[simp] theorem cospanCompIso_hom_app_left : (cospanCompIso F f g).hom.app WalkingCospan.left = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_hom_app_left CategoryTheory.Limits.cospanCompIso_hom_app_left @[simp] theorem cospanCompIso_hom_app_right : (cospanCompIso F f g).hom.app WalkingCospan.right = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_hom_app_right CategoryTheory.Limits.cospanCompIso_hom_app_right @[simp] theorem cospanCompIso_hom_app_one : (cospanCompIso F f g).hom.app WalkingCospan.one = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_hom_app_one CategoryTheory.Limits.cospanCompIso_hom_app_one @[simp] theorem cospanCompIso_inv_app_left : (cospanCompIso F f g).inv.app WalkingCospan.left = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_inv_app_left CategoryTheory.Limits.cospanCompIso_inv_app_left @[simp] theorem cospanCompIso_inv_app_right : (cospanCompIso F f g).inv.app WalkingCospan.right = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_inv_app_right CategoryTheory.Limits.cospanCompIso_inv_app_right @[simp] theorem cospanCompIso_inv_app_one : (cospanCompIso F f g).inv.app WalkingCospan.one = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_inv_app_one CategoryTheory.Limits.cospanCompIso_inv_app_one end /-- A functor applied to a span is a span. -/ def spanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : span f g ⋙ F ≅ span (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.span_comp_iso CategoryTheory.Limits.spanCompIso section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) @[simp] theorem spanCompIso_app_left : (spanCompIso F f g).app WalkingSpan.left = Iso.refl _ := rfl #align category_theory.limits.span_comp_iso_app_left CategoryTheory.Limits.spanCompIso_app_left @[simp] theorem spanCompIso_app_right : (spanCompIso F f g).app WalkingSpan.right = Iso.refl _ := rfl #align category_theory.limits.span_comp_iso_app_right CategoryTheory.Limits.spanCompIso_app_right @[simp] theorem spanCompIso_app_zero : (spanCompIso F f g).app WalkingSpan.zero = Iso.refl _ := rfl #align category_theory.limits.span_comp_iso_app_zero CategoryTheory.Limits.spanCompIso_app_zero @[simp] theorem spanCompIso_hom_app_left : (spanCompIso F f g).hom.app WalkingSpan.left = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_hom_app_left CategoryTheory.Limits.spanCompIso_hom_app_left @[simp] theorem spanCompIso_hom_app_right : (spanCompIso F f g).hom.app WalkingSpan.right = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_hom_app_right CategoryTheory.Limits.spanCompIso_hom_app_right @[simp] theorem spanCompIso_hom_app_zero : (spanCompIso F f g).hom.app WalkingSpan.zero = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_hom_app_zero CategoryTheory.Limits.spanCompIso_hom_app_zero @[simp] theorem spanCompIso_inv_app_left : (spanCompIso F f g).inv.app WalkingSpan.left = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_inv_app_left CategoryTheory.Limits.spanCompIso_inv_app_left @[simp] theorem spanCompIso_inv_app_right : (spanCompIso F f g).inv.app WalkingSpan.right = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_inv_app_right CategoryTheory.Limits.spanCompIso_inv_app_right @[simp] theorem spanCompIso_inv_app_zero : (spanCompIso F f g).inv.app WalkingSpan.zero = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_inv_app_zero CategoryTheory.Limits.spanCompIso_inv_app_zero end section variable {X Y Z X' Y' Z' : C} (iX : X ≅ X') (iY : Y ≅ Y') (iZ : Z ≅ Z') section variable {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} /-- Construct an isomorphism of cospans from components. -/ def cospanExt (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) : cospan f g ≅ cospan f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iZ, iX, iY]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp [wf, wg]) #align category_theory.limits.cospan_ext CategoryTheory.Limits.cospanExt variable (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem cospanExt_app_left : (cospanExt iX iY iZ wf wg).app WalkingCospan.left = iX := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_app_left CategoryTheory.Limits.cospanExt_app_left @[simp] theorem cospanExt_app_right : (cospanExt iX iY iZ wf wg).app WalkingCospan.right = iY := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_app_right CategoryTheory.Limits.cospanExt_app_right @[simp] theorem cospanExt_app_one : (cospanExt iX iY iZ wf wg).app WalkingCospan.one = iZ := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_app_one CategoryTheory.Limits.cospanExt_app_one @[simp] theorem cospanExt_hom_app_left : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.left = iX.hom := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_hom_app_left CategoryTheory.Limits.cospanExt_hom_app_left @[simp] theorem cospanExt_hom_app_right : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.right = iY.hom := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_hom_app_right CategoryTheory.Limits.cospanExt_hom_app_right @[simp] theorem cospanExt_hom_app_one : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.one = iZ.hom := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_hom_app_one CategoryTheory.Limits.cospanExt_hom_app_one @[simp] theorem cospanExt_inv_app_left : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.left = iX.inv := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_inv_app_left CategoryTheory.Limits.cospanExt_inv_app_left @[simp] theorem cospanExt_inv_app_right : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.right = iY.inv := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_inv_app_right CategoryTheory.Limits.cospanExt_inv_app_right @[simp] theorem cospanExt_inv_app_one : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.one = iZ.inv := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_inv_app_one CategoryTheory.Limits.cospanExt_inv_app_one end section variable {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'} /-- Construct an isomorphism of spans from components. -/ def spanExt (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) : span f g ≅ span f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iX, iY, iZ]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp [wf, wg]) #align category_theory.limits.span_ext CategoryTheory.Limits.spanExt variable (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem spanExt_app_left : (spanExt iX iY iZ wf wg).app WalkingSpan.left = iY := by dsimp [spanExt] #align category_theory.limits.span_ext_app_left CategoryTheory.Limits.spanExt_app_left @[simp] theorem spanExt_app_right : (spanExt iX iY iZ wf wg).app WalkingSpan.right = iZ := by dsimp [spanExt] #align category_theory.limits.span_ext_app_right CategoryTheory.Limits.spanExt_app_right @[simp] theorem spanExt_app_one : (spanExt iX iY iZ wf wg).app WalkingSpan.zero = iX := by dsimp [spanExt] #align category_theory.limits.span_ext_app_one CategoryTheory.Limits.spanExt_app_one @[simp] theorem spanExt_hom_app_left : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.left = iY.hom := by dsimp [spanExt] #align category_theory.limits.span_ext_hom_app_left CategoryTheory.Limits.spanExt_hom_app_left @[simp] theorem spanExt_hom_app_right : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.right = iZ.hom := by dsimp [spanExt] #align category_theory.limits.span_ext_hom_app_right CategoryTheory.Limits.spanExt_hom_app_right @[simp] theorem spanExt_hom_app_zero : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.zero = iX.hom := by dsimp [spanExt] #align category_theory.limits.span_ext_hom_app_zero CategoryTheory.Limits.spanExt_hom_app_zero @[simp] theorem spanExt_inv_app_left : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.left = iY.inv := by dsimp [spanExt] #align category_theory.limits.span_ext_inv_app_left CategoryTheory.Limits.spanExt_inv_app_left @[simp] theorem spanExt_inv_app_right : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.right = iZ.inv := by dsimp [spanExt] #align category_theory.limits.span_ext_inv_app_right CategoryTheory.Limits.spanExt_inv_app_right @[simp] theorem spanExt_inv_app_zero : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.zero = iX.inv := by dsimp [spanExt] #align category_theory.limits.span_ext_inv_app_zero CategoryTheory.Limits.spanExt_inv_app_zero end end variable {W X Y Z : C} /-- A pullback cone is just a cone on the cospan formed by two morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`. -/ abbrev PullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) := Cone (cospan f g) #align category_theory.limits.pullback_cone CategoryTheory.Limits.PullbackCone namespace PullbackCone variable {f : X ⟶ Z} {g : Y ⟶ Z} /-- The first projection of a pullback cone. -/ abbrev fst (t : PullbackCone f g) : t.pt ⟶ X := t.π.app WalkingCospan.left #align category_theory.limits.pullback_cone.fst CategoryTheory.Limits.PullbackCone.fst /-- The second projection of a pullback cone. -/ abbrev snd (t : PullbackCone f g) : t.pt ⟶ Y := t.π.app WalkingCospan.right #align category_theory.limits.pullback_cone.snd CategoryTheory.Limits.PullbackCone.snd @[simp] theorem π_app_left (c : PullbackCone f g) : c.π.app WalkingCospan.left = c.fst := rfl #align category_theory.limits.pullback_cone.π_app_left CategoryTheory.Limits.PullbackCone.π_app_left @[simp] theorem π_app_right (c : PullbackCone f g) : c.π.app WalkingCospan.right = c.snd := rfl #align category_theory.limits.pullback_cone.π_app_right CategoryTheory.Limits.PullbackCone.π_app_right @[simp] theorem condition_one (t : PullbackCone f g) : t.π.app WalkingCospan.one = t.fst ≫ f := by have w := t.π.naturality WalkingCospan.Hom.inl dsimp at w; simpa using w #align category_theory.limits.pullback_cone.condition_one CategoryTheory.Limits.PullbackCone.condition_one /-- This is a slightly more convenient method to verify that a pullback cone is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : PullbackCone f g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ t.pt) (fac_left : ∀ s : PullbackCone f g, lift s ≫ t.fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ t.snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ t.pt) (_ : ∀ j : WalkingCospan, m ≫ t.π.app j = s.π.app j), m = lift s) : IsLimit t := { lift fac := fun s j => Option.casesOn j (by rw [← s.w inl, ← t.w inl, ← Category.assoc] congr exact fac_left s) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } #align category_theory.limits.pullback_cone.is_limit_aux CategoryTheory.Limits.PullbackCone.isLimitAux /-- This is another convenient method to verify that a pullback cone is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def isLimitAux' (t : PullbackCone f g) (create : ∀ s : PullbackCone f g, { l // l ≫ t.fst = s.fst ∧ l ≫ t.snd = s.snd ∧ ∀ {m}, m ≫ t.fst = s.fst → m ≫ t.snd = s.snd → m = l }) : Limits.IsLimit t := PullbackCone.isLimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pullback_cone.is_limit_aux' CategoryTheory.Limits.PullbackCone.isLimitAux' /-- A pullback cone on `f` and `g` is determined by morphisms `fst : W ⟶ X` and `snd : W ⟶ Y` such that `fst ≫ f = snd ≫ g`. -/ @[simps] def mk {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : PullbackCone f g where pt := W π := { app := fun j => Option.casesOn j (fst ≫ f) fun j' => WalkingPair.casesOn j' fst snd naturality := by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) j <;> cases j <;> dsimp <;> simp [eq] } #align category_theory.limits.pullback_cone.mk CategoryTheory.Limits.PullbackCone.mk @[simp] theorem mk_π_app_left {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.left = fst := rfl #align category_theory.limits.pullback_cone.mk_π_app_left CategoryTheory.Limits.PullbackCone.mk_π_app_left @[simp] theorem mk_π_app_right {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.right = snd := rfl #align category_theory.limits.pullback_cone.mk_π_app_right CategoryTheory.Limits.PullbackCone.mk_π_app_right @[simp] theorem mk_π_app_one {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.one = fst ≫ f := rfl #align category_theory.limits.pullback_cone.mk_π_app_one CategoryTheory.Limits.PullbackCone.mk_π_app_one @[simp] theorem mk_fst {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).fst = fst := rfl #align category_theory.limits.pullback_cone.mk_fst CategoryTheory.Limits.PullbackCone.mk_fst @[simp] theorem mk_snd {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).snd = snd := rfl #align category_theory.limits.pullback_cone.mk_snd CategoryTheory.Limits.PullbackCone.mk_snd @[reassoc] theorem condition (t : PullbackCone f g) : fst t ≫ f = snd t ≫ g := (t.w inl).trans (t.w inr).symm #align category_theory.limits.pullback_cone.condition CategoryTheory.Limits.PullbackCone.condition /-- To check whether a morphism is equalized by the maps of a pullback cone, it suffices to check it for `fst t` and `snd t` -/ theorem equalizer_ext (t : PullbackCone f g) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : ∀ j : WalkingCospan, k ≫ t.π.app j = l ≫ t.π.app j | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w inl, reassoc_of% h₀] #align category_theory.limits.pullback_cone.equalizer_ext CategoryTheory.Limits.PullbackCone.equalizer_ext theorem IsLimit.hom_ext {t : PullbackCone f g} (ht : IsLimit t) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : k = l := ht.hom_ext <| equalizer_ext _ h₀ h₁ #align category_theory.limits.pullback_cone.is_limit.hom_ext CategoryTheory.Limits.PullbackCone.IsLimit.hom_ext theorem mono_snd_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono f] : Mono t.snd := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht ?_ i⟩ rw [← cancel_mono f, Category.assoc, Category.assoc, condition] have := congrArg (· ≫ g) i; dsimp at this rwa [Category.assoc, Category.assoc] at this #align category_theory.limits.pullback_cone.mono_snd_of_is_pullback_of_mono CategoryTheory.Limits.PullbackCone.mono_snd_of_is_pullback_of_mono theorem mono_fst_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono g] : Mono t.fst := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht i ?_⟩ rw [← cancel_mono g, Category.assoc, Category.assoc, ← condition] have := congrArg (· ≫ f) i; dsimp at this rwa [Category.assoc, Category.assoc] at this #align category_theory.limits.pullback_cone.mono_fst_of_is_pullback_of_mono CategoryTheory.Limits.PullbackCone.mono_fst_of_is_pullback_of_mono /-- To construct an isomorphism of pullback cones, it suffices to construct an isomorphism of the cone points and check it commutes with `fst` and `snd`. -/ def ext {s t : PullbackCone f g} (i : s.pt ≅ t.pt) (w₁ : s.fst = i.hom ≫ t.fst) (w₂ : s.snd = i.hom ≫ t.snd) : s ≅ t := WalkingCospan.ext i w₁ w₂ #align category_theory.limits.pullback_cone.ext CategoryTheory.Limits.PullbackCone.ext -- Porting note: `IsLimit.lift` and the two following simp lemmas were introduced to ease the port /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we get `l : W ⟶ t.pt`, which satisfies `l ≫ fst t = h` and `l ≫ snd t = k`, see `IsLimit.lift_fst` and `IsLimit.lift_snd`. -/ def IsLimit.lift {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ t.pt := ht.lift <| PullbackCone.mk _ _ w @[reassoc (attr := simp)] lemma IsLimit.lift_fst {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ fst t = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsLimit.lift_snd {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ snd t = k := ht.fac _ _ /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we have `l : W ⟶ t.pt` satisfying `l ≫ fst t = h` and `l ≫ snd t = k`. -/ def IsLimit.lift' {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ t.pt // l ≫ fst t = h ∧ l ≫ snd t = k } := ⟨IsLimit.lift ht h k w, by simp⟩ #align category_theory.limits.pullback_cone.is_limit.lift' CategoryTheory.Limits.PullbackCone.IsLimit.lift' /-- This is a more convenient formulation to show that a `PullbackCone` constructed using `PullbackCone.mk` is a limit cone. -/ def IsLimit.mk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (eq : fst ≫ f = snd ≫ g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ W) (fac_left : ∀ s : PullbackCone f g, lift s ≫ fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (mk fst snd eq) := isLimitAux _ lift fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pullback_cone.is_limit.mk CategoryTheory.Limits.PullbackCone.IsLimit.mk section Flip variable (t : PullbackCone f g) /-- The pullback cone obtained by flipping `fst` and `snd`. -/ def flip : PullbackCone g f := PullbackCone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_fst : t.flip.fst = t.snd := rfl @[simp] lemma flip_snd : t.flip.snd = t.fst := rfl /-- Flipping a pullback cone twice gives an isomorphic cone. -/ def flipFlipIso : t.flip.flip ≅ t := PullbackCone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pullback square is a pullback square. -/ def flipIsLimit (ht : IsLimit t) : IsLimit t.flip := IsLimit.mk _ (fun s => ht.lift s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsLimit.hom_ext ht all_goals aesop_cat) /-- A square is a pullback square if its flip is. -/ def isLimitOfFlip (ht : IsLimit t.flip) : IsLimit t := IsLimit.ofIsoLimit (flipIsLimit ht) t.flipFlipIso #align category_theory.limits.pullback_cone.flip_is_limit CategoryTheory.Limits.PullbackCone.isLimitOfFlip end Flip /-- The pullback cone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a limit if `f` is a mono. The converse is shown in `mono_of_pullback_is_id`. -/ def isLimitMkIdId (f : X ⟶ Y) [Mono f] : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f) := IsLimit.mk _ (fun s => s.fst) (fun s => Category.comp_id _) (fun s => by rw [← cancel_mono f, Category.comp_id, s.condition]) fun s m m₁ _ => by simpa using m₁ #align category_theory.limits.pullback_cone.is_limit_mk_id_id CategoryTheory.Limits.PullbackCone.isLimitMkIdId /-- `f` is a mono if the pullback cone `(𝟙 X, 𝟙 X)` is a limit for the pair `(f, f)`. The converse is given in `PullbackCone.is_id_of_mono`. -/ theorem mono_of_isLimitMkIdId (f : X ⟶ Y) (t : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f)) : Mono f := ⟨fun {Z} g h eq => by rcases PullbackCone.IsLimit.lift' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ #align category_theory.limits.pullback_cone.mono_of_is_limit_mk_id_id CategoryTheory.Limits.PullbackCone.mono_of_isLimitMkIdId /-- Suppose `f` and `g` are two morphisms with a common codomain and `s` is a limit cone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through a monomorphism `h` via `x` and `y`, respectively. Then `s` is also a limit cone over the diagram formed by `x` and `y`. -/ def isLimitOfFactors (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ Z) [Mono h] (x : X ⟶ W) (y : Y ⟶ W) (hxh : x ≫ h = f) (hyh : y ≫ h = g) (s : PullbackCone f g) (hs : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ x = s.snd ≫ y from (cancel_mono h).1 <| by simp only [Category.assoc, hxh, hyh, s.condition])) := PullbackCone.isLimitAux' _ fun t => have : fst t ≫ x ≫ h = snd t ≫ y ≫ h := by -- Porting note: reassoc workaround rw [← Category.assoc, ← Category.assoc] apply congrArg (· ≫ h) t.condition ⟨hs.lift (PullbackCone.mk t.fst t.snd <| by rw [← hxh, ← hyh, this]), ⟨hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right, fun hr hr' => by apply PullbackCone.IsLimit.hom_ext hs <;> simp only [PullbackCone.mk_fst, PullbackCone.mk_snd] at hr hr' ⊢ <;> simp only [hr, hr'] <;> symm exacts [hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right]⟩⟩ #align category_theory.limits.pullback_cone.is_limit_of_factors CategoryTheory.Limits.PullbackCone.isLimitOfFactors /-- If `W` is the pullback of `f, g`, it is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/ def isLimitOfCompMono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] (s : PullbackCone f g) (H : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ f ≫ i = s.snd ≫ g ≫ i by rw [← Category.assoc, ← Category.assoc, s.condition])) := by apply PullbackCone.isLimitAux' intro s rcases PullbackCone.IsLimit.lift' H s.fst s.snd ((cancel_mono i).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PullbackCone.IsLimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _) #align category_theory.limits.pullback_cone.is_limit_of_comp_mono CategoryTheory.Limits.PullbackCone.isLimitOfCompMono end PullbackCone /-- A pushout cocone is just a cocone on the span formed by two morphisms `f : X ⟶ Y` and `g : X ⟶ Z`. -/ abbrev PushoutCocone (f : X ⟶ Y) (g : X ⟶ Z) := Cocone (span f g) #align category_theory.limits.pushout_cocone CategoryTheory.Limits.PushoutCocone namespace PushoutCocone variable {f : X ⟶ Y} {g : X ⟶ Z} /-- The first inclusion of a pushout cocone. -/ abbrev inl (t : PushoutCocone f g) : Y ⟶ t.pt := t.ι.app WalkingSpan.left #align category_theory.limits.pushout_cocone.inl CategoryTheory.Limits.PushoutCocone.inl /-- The second inclusion of a pushout cocone. -/ abbrev inr (t : PushoutCocone f g) : Z ⟶ t.pt := t.ι.app WalkingSpan.right #align category_theory.limits.pushout_cocone.inr CategoryTheory.Limits.PushoutCocone.inr @[simp] theorem ι_app_left (c : PushoutCocone f g) : c.ι.app WalkingSpan.left = c.inl := rfl #align category_theory.limits.pushout_cocone.ι_app_left CategoryTheory.Limits.PushoutCocone.ι_app_left @[simp] theorem ι_app_right (c : PushoutCocone f g) : c.ι.app WalkingSpan.right = c.inr := rfl #align category_theory.limits.pushout_cocone.ι_app_right CategoryTheory.Limits.PushoutCocone.ι_app_right @[simp] theorem condition_zero (t : PushoutCocone f g) : t.ι.app WalkingSpan.zero = f ≫ t.inl := by have w := t.ι.naturality WalkingSpan.Hom.fst dsimp at w; simpa using w.symm #align category_theory.limits.pushout_cocone.condition_zero CategoryTheory.Limits.PushoutCocone.condition_zero /-- This is a slightly more convenient method to verify that a pushout cocone is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def isColimitAux (t : PushoutCocone f g) (desc : ∀ s : PushoutCocone f g, t.pt ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, t.inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, t.inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : t.pt ⟶ s.pt) (_ : ∀ j : WalkingSpan, t.ι.app j ≫ m = s.ι.app j), m = desc s) : IsColimit t := { desc fac := fun s j => Option.casesOn j (by simp [← s.w fst, ← t.w fst, fac_left s]) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } #align category_theory.limits.pushout_cocone.is_colimit_aux CategoryTheory.Limits.PushoutCocone.isColimitAux /-- This is another convenient method to verify that a pushout cocone is a colimit cocone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def isColimitAux' (t : PushoutCocone f g) (create : ∀ s : PushoutCocone f g, { l // t.inl ≫ l = s.inl ∧ t.inr ≫ l = s.inr ∧ ∀ {m}, t.inl ≫ m = s.inl → t.inr ≫ m = s.inr → m = l }) : IsColimit t := isColimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pushout_cocone.is_colimit_aux' CategoryTheory.Limits.PushoutCocone.isColimitAux' /-- A pushout cocone on `f` and `g` is determined by morphisms `inl : Y ⟶ W` and `inr : Z ⟶ W` such that `f ≫ inl = g ↠ inr`. -/ @[simps] def mk {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : PushoutCocone f g where pt := W ι := { app := fun j => Option.casesOn j (f ≫ inl) fun j' => WalkingPair.casesOn j' inl inr naturality := by rintro (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) <;> intro f <;> cases f <;> dsimp <;> aesop } #align category_theory.limits.pushout_cocone.mk CategoryTheory.Limits.PushoutCocone.mk @[simp] theorem mk_ι_app_left {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.left = inl := rfl #align category_theory.limits.pushout_cocone.mk_ι_app_left CategoryTheory.Limits.PushoutCocone.mk_ι_app_left @[simp] theorem mk_ι_app_right {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.right = inr := rfl #align category_theory.limits.pushout_cocone.mk_ι_app_right CategoryTheory.Limits.PushoutCocone.mk_ι_app_right @[simp] theorem mk_ι_app_zero {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.zero = f ≫ inl := rfl #align category_theory.limits.pushout_cocone.mk_ι_app_zero CategoryTheory.Limits.PushoutCocone.mk_ι_app_zero @[simp] theorem mk_inl {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inl = inl := rfl #align category_theory.limits.pushout_cocone.mk_inl CategoryTheory.Limits.PushoutCocone.mk_inl @[simp] theorem mk_inr {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inr = inr := rfl #align category_theory.limits.pushout_cocone.mk_inr CategoryTheory.Limits.PushoutCocone.mk_inr @[reassoc] theorem condition (t : PushoutCocone f g) : f ≫ inl t = g ≫ inr t := (t.w fst).trans (t.w snd).symm #align category_theory.limits.pushout_cocone.condition CategoryTheory.Limits.PushoutCocone.condition /-- To check whether a morphism is coequalized by the maps of a pushout cocone, it suffices to check it for `inl t` and `inr t` -/ theorem coequalizer_ext (t : PushoutCocone f g) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : ∀ j : WalkingSpan, t.ι.app j ≫ k = t.ι.app j ≫ l | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w fst, Category.assoc, Category.assoc, h₀] #align category_theory.limits.pushout_cocone.coequalizer_ext CategoryTheory.Limits.PushoutCocone.coequalizer_ext theorem IsColimit.hom_ext {t : PushoutCocone f g} (ht : IsColimit t) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : k = l := ht.hom_ext <| coequalizer_ext _ h₀ h₁ #align category_theory.limits.pushout_cocone.is_colimit.hom_ext CategoryTheory.Limits.PushoutCocone.IsColimit.hom_ext -- Porting note: `IsColimit.desc` and the two following simp lemmas were introduced to ease the port /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`, see `IsColimit.inl_desc` and `IsColimit.inr_desc`-/ def IsColimit.desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : t.pt ⟶ W := ht.desc (PushoutCocone.mk _ _ w) @[reassoc (attr := simp)] lemma IsColimit.inl_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inl t ≫ IsColimit.desc ht h k w = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsColimit.inr_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inr t ≫ IsColimit.desc ht h k w = k := ht.fac _ _ /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`. -/ def IsColimit.desc' {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : t.pt ⟶ W // inl t ≫ l = h ∧ inr t ≫ l = k } := ⟨IsColimit.desc ht h k w, by simp⟩ #align category_theory.limits.pushout_cocone.is_colimit.desc' CategoryTheory.Limits.PushoutCocone.IsColimit.desc' theorem epi_inr_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi f] : Epi t.inr := ⟨fun {W} h k i => IsColimit.hom_ext ht (by simp [← cancel_epi f, t.condition_assoc, i]) i⟩ #align category_theory.limits.pushout_cocone.epi_inr_of_is_pushout_of_epi CategoryTheory.Limits.PushoutCocone.epi_inr_of_is_pushout_of_epi theorem epi_inl_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi g] : Epi t.inl := ⟨fun {W} h k i => IsColimit.hom_ext ht i (by simp [← cancel_epi g, ← t.condition_assoc, i])⟩ #align category_theory.limits.pushout_cocone.epi_inl_of_is_pushout_of_epi CategoryTheory.Limits.PushoutCocone.epi_inl_of_is_pushout_of_epi /-- To construct an isomorphism of pushout cocones, it suffices to construct an isomorphism of the cocone points and check it commutes with `inl` and `inr`. -/ def ext {s t : PushoutCocone f g} (i : s.pt ≅ t.pt) (w₁ : s.inl ≫ i.hom = t.inl) (w₂ : s.inr ≫ i.hom = t.inr) : s ≅ t := WalkingSpan.ext i w₁ w₂ #align category_theory.limits.pushout_cocone.ext CategoryTheory.Limits.PushoutCocone.ext /-- This is a more convenient formulation to show that a `PushoutCocone` constructed using `PushoutCocone.mk` is a colimit cocone. -/ def IsColimit.mk {W : C} {inl : Y ⟶ W} {inr : Z ⟶ W} (eq : f ≫ inl = g ≫ inr) (desc : ∀ s : PushoutCocone f g, W ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (mk inl inr eq) := isColimitAux _ desc fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pushout_cocone.is_colimit.mk CategoryTheory.Limits.PushoutCocone.IsColimit.mk section Flip variable (t : PushoutCocone f g) /-- The pushout cocone obtained by flipping `inl` and `inr`. -/ def flip : PushoutCocone g f := PushoutCocone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_inl : t.flip.inl = t.inr := rfl @[simp] lemma flip_inr : t.flip.inr = t.inl := rfl /-- Flipping a pushout cocone twice gives an isomorphic cocone. -/ def flipFlipIso : t.flip.flip ≅ t := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pushout square is a pushout square. -/ def flipIsColimit (ht : IsColimit t) : IsColimit t.flip := IsColimit.mk _ (fun s => ht.desc s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsColimit.hom_ext ht all_goals aesop_cat) /-- A square is a pushout square if its flip is. -/ def isColimitOfFlip (ht : IsColimit t.flip) : IsColimit t := IsColimit.ofIsoColimit (flipIsColimit ht) t.flipFlipIso #align category_theory.limits.pushout_cocone.flip_is_colimit CategoryTheory.Limits.PushoutCocone.isColimitOfFlip end Flip /-- The pushout cocone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a colimit if `f` is an epi. The converse is shown in `epi_of_isColimit_mk_id_id`. -/ def isColimitMkIdId (f : X ⟶ Y) [Epi f] : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f) := IsColimit.mk _ (fun s => s.inl) (fun s => Category.id_comp _) (fun s => by rw [← cancel_epi f, Category.id_comp, s.condition]) fun s m m₁ _ => by simpa using m₁ #align category_theory.limits.pushout_cocone.is_colimit_mk_id_id CategoryTheory.Limits.PushoutCocone.isColimitMkIdId /-- `f` is an epi if the pushout cocone `(𝟙 X, 𝟙 X)` is a colimit for the pair `(f, f)`. The converse is given in `PushoutCocone.isColimitMkIdId`. -/ theorem epi_of_isColimitMkIdId (f : X ⟶ Y) (t : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f)) : Epi f := ⟨fun {Z} g h eq => by rcases PushoutCocone.IsColimit.desc' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ #align category_theory.limits.pushout_cocone.epi_of_is_colimit_mk_id_id CategoryTheory.Limits.PushoutCocone.epi_of_isColimitMkIdId /-- Suppose `f` and `g` are two morphisms with a common domain and `s` is a colimit cocone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through an epimorphism `h` via `x` and `y`, respectively. Then `s` is also a colimit cocone over the diagram formed by `x` and `y`. -/ def isColimitOfFactors (f : X ⟶ Y) (g : X ⟶ Z) (h : X ⟶ W) [Epi h] (x : W ⟶ Y) (y : W ⟶ Z) (hhx : h ≫ x = f) (hhy : h ≫ y = g) (s : PushoutCocone f g) (hs : IsColimit s) : have reassoc₁ : h ≫ x ≫ inl s = f ≫ inl s := by -- Porting note: working around reassoc rw [← Category.assoc]; apply congrArg (· ≫ inl s) hhx have reassoc₂ : h ≫ y ≫ inr s = g ≫ inr s := by rw [← Category.assoc]; apply congrArg (· ≫ inr s) hhy IsColimit (PushoutCocone.mk _ _ (show x ≫ s.inl = y ≫ s.inr from (cancel_epi h).1 <| by rw [reassoc₁, reassoc₂, s.condition])) := PushoutCocone.isColimitAux' _ fun t => ⟨hs.desc (PushoutCocone.mk t.inl t.inr <| by rw [← hhx, ← hhy, Category.assoc, Category.assoc, t.condition]), ⟨hs.fac _ WalkingSpan.left, hs.fac _ WalkingSpan.right, fun hr hr' => by apply PushoutCocone.IsColimit.hom_ext hs; · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr, hr'] symm exact hs.fac _ WalkingSpan.left · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr, hr'] symm exact hs.fac _ WalkingSpan.right⟩⟩ #align category_theory.limits.pushout_cocone.is_colimit_of_factors CategoryTheory.Limits.PushoutCocone.isColimitOfFactors /-- If `W` is the pushout of `f, g`, it is also the pushout of `h ≫ f, h ≫ g` for any epi `h`. -/ def isColimitOfEpiComp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] (s : PushoutCocone f g) (H : IsColimit s) : IsColimit (PushoutCocone.mk _ _ (show (h ≫ f) ≫ s.inl = (h ≫ g) ≫ s.inr by rw [Category.assoc, Category.assoc, s.condition])) := by apply PushoutCocone.isColimitAux' intro s rcases PushoutCocone.IsColimit.desc' H s.inl s.inr ((cancel_epi h).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PushoutCocone.IsColimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _) #align category_theory.limits.pushout_cocone.is_colimit_of_epi_comp CategoryTheory.Limits.PushoutCocone.isColimitOfEpiComp end PushoutCocone /-- This is a helper construction that can be useful when verifying that a category has all pullbacks. Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a pullback cone on `F.map inl` and `F.map inr`, we get a cone on `F`. If you're thinking about using this, have a look at `hasPullbacks_of_hasLimit_cospan`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cone.ofPullbackCone {F : WalkingCospan ⥤ C} (t : PullbackCone (F.map inl) (F.map inr)) : Cone F where pt := t.pt π := t.π ≫ (diagramIsoCospan F).inv #align category_theory.limits.cone.of_pullback_cone CategoryTheory.Limits.Cone.ofPullbackCone /-- This is a helper construction that can be useful when verifying that a category has all pushout. Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a pushout cocone on `F.map fst` and `F.map snd`, we get a cocone on `F`. If you're thinking about using this, have a look at `hasPushouts_of_hasColimit_span`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cocone.ofPushoutCocone {F : WalkingSpan ⥤ C} (t : PushoutCocone (F.map fst) (F.map snd)) : Cocone F where pt := t.pt ι := (diagramIsoSpan F).hom ≫ t.ι #align category_theory.limits.cocone.of_pushout_cocone CategoryTheory.Limits.Cocone.ofPushoutCocone /-- Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a cone on `F`, we get a pullback cone on `F.map inl` and `F.map inr`. -/ @[simps] def PullbackCone.ofCone {F : WalkingCospan ⥤ C} (t : Cone F) : PullbackCone (F.map inl) (F.map inr) where pt := t.pt π := t.π ≫ (diagramIsoCospan F).hom #align category_theory.limits.pullback_cone.of_cone CategoryTheory.Limits.PullbackCone.ofCone /-- A diagram `WalkingCospan ⥤ C` is isomorphic to some `PullbackCone.mk` after composing with `diagramIsoCospan`. -/ @[simps!] def PullbackCone.isoMk {F : WalkingCospan ⥤ C} (t : Cone F) : (Cones.postcompose (diagramIsoCospan.{v} _).hom).obj t ≅ PullbackCone.mk (t.π.app WalkingCospan.left) (t.π.app WalkingCospan.right) ((t.π.naturality inl).symm.trans (t.π.naturality inr : _)) := Cones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> · dsimp simp #align category_theory.limits.pullback_cone.iso_mk CategoryTheory.Limits.PullbackCone.isoMk /-- Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a cocone on `F`, we get a pushout cocone on `F.map fst` and `F.map snd`. -/ @[simps] def PushoutCocone.ofCocone {F : WalkingSpan ⥤ C} (t : Cocone F) : PushoutCocone (F.map fst) (F.map snd) where pt := t.pt ι := (diagramIsoSpan F).inv ≫ t.ι #align category_theory.limits.pushout_cocone.of_cocone CategoryTheory.Limits.PushoutCocone.ofCocone /-- A diagram `WalkingSpan ⥤ C` is isomorphic to some `PushoutCocone.mk` after composing with `diagramIsoSpan`. -/ @[simps!] def PushoutCocone.isoMk {F : WalkingSpan ⥤ C} (t : Cocone F) : (Cocones.precompose (diagramIsoSpan.{v} _).inv).obj t ≅ PushoutCocone.mk (t.ι.app WalkingSpan.left) (t.ι.app WalkingSpan.right) ((t.ι.naturality fst).trans (t.ι.naturality snd).symm) := Cocones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> · dsimp simp #align category_theory.limits.pushout_cocone.iso_mk CategoryTheory.Limits.PushoutCocone.isoMk /-- `HasPullback f g` represents a particular choice of limiting cone for the pair of morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`. -/ abbrev HasPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) := HasLimit (cospan f g) #align category_theory.limits.has_pullback CategoryTheory.Limits.HasPullback /-- `HasPushout f g` represents a particular choice of colimiting cocone for the pair of morphisms `f : X ⟶ Y` and `g : X ⟶ Z`. -/ abbrev HasPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) := HasColimit (span f g) #align category_theory.limits.has_pushout CategoryTheory.Limits.HasPushout /-- `pullback f g` computes the pullback of a pair of morphisms with the same target. -/ abbrev pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] := limit (cospan f g) #align category_theory.limits.pullback CategoryTheory.Limits.pullback /-- `pushout f g` computes the pushout of a pair of morphisms with the same source. -/ abbrev pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] := colimit (span f g) #align category_theory.limits.pushout CategoryTheory.Limits.pushout /-- The first projection of the pullback of `f` and `g`. -/ abbrev pullback.fst {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback f g ⟶ X := limit.π (cospan f g) WalkingCospan.left #align category_theory.limits.pullback.fst CategoryTheory.Limits.pullback.fst /-- The second projection of the pullback of `f` and `g`. -/ abbrev pullback.snd {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback f g ⟶ Y := limit.π (cospan f g) WalkingCospan.right #align category_theory.limits.pullback.snd CategoryTheory.Limits.pullback.snd /-- The first inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inl {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : Y ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.left #align category_theory.limits.pushout.inl CategoryTheory.Limits.pushout.inl /-- The second inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inr {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : Z ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.right #align category_theory.limits.pushout.inr CategoryTheory.Limits.pushout.inr /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `pullback.lift : W ⟶ pullback f g`. -/ abbrev pullback.lift {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ pullback f g := limit.lift _ (PullbackCone.mk h k w) #align category_theory.limits.pullback.lift CategoryTheory.Limits.pullback.lift /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `pushout.desc : pushout f g ⟶ W`. -/ abbrev pushout.desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout f g ⟶ W := colimit.desc _ (PushoutCocone.mk h k w) #align category_theory.limits.pushout.desc CategoryTheory.Limits.pushout.desc @[simp] theorem PullbackCone.fst_colimit_cocone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.fst (limit.cone (cospan f g)) = pullback.fst := rfl #align category_theory.limits.pullback_cone.fst_colimit_cocone CategoryTheory.Limits.PullbackCone.fst_colimit_cocone @[simp] theorem PullbackCone.snd_colimit_cocone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.snd (limit.cone (cospan f g)) = pullback.snd := rfl #align category_theory.limits.pullback_cone.snd_colimit_cocone CategoryTheory.Limits.PullbackCone.snd_colimit_cocone -- Porting note (#10618): simp can prove this; removed simp theorem PushoutCocone.inl_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inl (colimit.cocone (span f g)) = pushout.inl := rfl #align category_theory.limits.pushout_cocone.inl_colimit_cocone CategoryTheory.Limits.PushoutCocone.inl_colimit_cocone -- Porting note (#10618): simp can prove this; removed simp theorem PushoutCocone.inr_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inr (colimit.cocone (span f g)) = pushout.inr := rfl #align category_theory.limits.pushout_cocone.inr_colimit_cocone CategoryTheory.Limits.PushoutCocone.inr_colimit_cocone -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pullback.lift_fst {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.fst = h := limit.lift_π _ _ #align category_theory.limits.pullback.lift_fst CategoryTheory.Limits.pullback.lift_fst -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pullback.lift_snd {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.snd = k := limit.lift_π _ _ #align category_theory.limits.pullback.lift_snd CategoryTheory.Limits.pullback.lift_snd -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pushout.inl_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inl ≫ pushout.desc h k w = h := colimit.ι_desc _ _ #align category_theory.limits.pushout.inl_desc CategoryTheory.Limits.pushout.inl_desc -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pushout.inr_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inr ≫ pushout.desc h k w = k := colimit.ι_desc _ _ #align category_theory.limits.pushout.inr_desc CategoryTheory.Limits.pushout.inr_desc /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `l : W ⟶ pullback f g` such that `l ≫ pullback.fst = h` and `l ≫ pullback.snd = k`. -/ def pullback.lift' {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ pullback f g // l ≫ pullback.fst = h ∧ l ≫ pullback.snd = k } := ⟨pullback.lift h k w, pullback.lift_fst _ _ _, pullback.lift_snd _ _ _⟩ #align category_theory.limits.pullback.lift' CategoryTheory.Limits.pullback.lift' /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `l : pushout f g ⟶ W` such that `pushout.inl ≫ l = h` and `pushout.inr ≫ l = k`. -/ def pullback.desc' {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : pushout f g ⟶ W // pushout.inl ≫ l = h ∧ pushout.inr ≫ l = k } := ⟨pushout.desc h k w, pushout.inl_desc _ _ _, pushout.inr_desc _ _ _⟩ #align category_theory.limits.pullback.desc' CategoryTheory.Limits.pullback.desc' @[reassoc] theorem pullback.condition {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : (pullback.fst : pullback f g ⟶ X) ≫ f = pullback.snd ≫ g := PullbackCone.condition _ #align category_theory.limits.pullback.condition CategoryTheory.Limits.pullback.condition @[reassoc] theorem pushout.condition {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : f ≫ (pushout.inl : Y ⟶ pushout f g) = g ≫ pushout.inr := PushoutCocone.condition _ #align category_theory.limits.pushout.condition CategoryTheory.Limits.pushout.condition /-- Given such a diagram, then there is a natural morphism `W ×ₛ X ⟶ Y ×ₜ Z`. W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z -/ abbrev pullback.map {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : pullback f₁ f₂ ⟶ pullback g₁ g₂ := pullback.lift (pullback.fst ≫ i₁) (pullback.snd ≫ i₂) (by simp [← eq₁, ← eq₂, pullback.condition_assoc]) #align category_theory.limits.pullback.map CategoryTheory.Limits.pullback.map /-- The canonical map `X ×ₛ Y ⟶ X ×ₜ Y` given `S ⟶ T`. -/ abbrev pullback.mapDesc {X Y S T : C} (f : X ⟶ S) (g : Y ⟶ S) (i : S ⟶ T) [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] : pullback f g ⟶ pullback (f ≫ i) (g ≫ i) := pullback.map f g (f ≫ i) (g ≫ i) (𝟙 _) (𝟙 _) i (Category.id_comp _).symm (Category.id_comp _).symm #align category_theory.limits.pullback.map_desc CategoryTheory.Limits.pullback.mapDesc /-- Given such a diagram, then there is a natural morphism `W ⨿ₛ X ⟶ Y ⨿ₜ Z`. W ⟶ Y ↗ ↗ S ⟶ T ↘ ↘ X ⟶ Z -/ abbrev pushout.map {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) : pushout f₁ f₂ ⟶ pushout g₁ g₂ := pushout.desc (i₁ ≫ pushout.inl) (i₂ ≫ pushout.inr) (by simp only [← Category.assoc, eq₁, eq₂] simp [pushout.condition]) #align category_theory.limits.pushout.map CategoryTheory.Limits.pushout.map /-- The canonical map `X ⨿ₛ Y ⟶ X ⨿ₜ Y` given `S ⟶ T`. -/ abbrev pushout.mapLift {X Y S T : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] : pushout (i ≫ f) (i ≫ g) ⟶ pushout f g := pushout.map (i ≫ f) (i ≫ g) f g (𝟙 _) (𝟙 _) i (Category.comp_id _) (Category.comp_id _) #align category_theory.limits.pushout.map_lift CategoryTheory.Limits.pushout.mapLift /-- Two morphisms into a pullback are equal if their compositions with the pullback morphisms are equal -/ @[ext 1100] theorem pullback.hom_ext {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] {W : C} {k l : W ⟶ pullback f g} (h₀ : k ≫ pullback.fst = l ≫ pullback.fst) (h₁ : k ≫ pullback.snd = l ≫ pullback.snd) : k = l := limit.hom_ext <| PullbackCone.equalizer_ext _ h₀ h₁ #align category_theory.limits.pullback.hom_ext CategoryTheory.Limits.pullback.hom_ext /-- The pullback cone built from the pullback projections is a pullback. -/ def pullbackIsPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsLimit (PullbackCone.mk (pullback.fst : pullback f g ⟶ _) pullback.snd pullback.condition) := PullbackCone.IsLimit.mk _ (fun s => pullback.lift s.fst s.snd s.condition) (by simp) (by simp) (by aesop_cat) #align category_theory.limits.pullback_is_pullback CategoryTheory.Limits.pullbackIsPullback /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.fst_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono g] : Mono (pullback.fst : pullback f g ⟶ X) := PullbackCone.mono_fst_of_is_pullback_of_mono (limit.isLimit _) #align category_theory.limits.pullback.fst_of_mono CategoryTheory.Limits.pullback.fst_of_mono /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.snd_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono f] : Mono (pullback.snd : pullback f g ⟶ Y) := PullbackCone.mono_snd_of_is_pullback_of_mono (limit.isLimit _) #align category_theory.limits.pullback.snd_of_mono CategoryTheory.Limits.pullback.snd_of_mono /-- The map `X ×[Z] Y ⟶ X × Y` is mono. -/ instance mono_pullback_to_prod {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasBinaryProduct X Y] : Mono (prod.lift pullback.fst pullback.snd : pullback f g ⟶ _) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => f ≫ prod.fst) h · simpa using congrArg (fun f => f ≫ prod.snd) h⟩ #align category_theory.limits.mono_pullback_to_prod CategoryTheory.Limits.mono_pullback_to_prod /-- Two morphisms out of a pushout are equal if their compositions with the pushout morphisms are equal -/ @[ext 1100] theorem pushout.hom_ext {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] {W : C} {k l : pushout f g ⟶ W} (h₀ : pushout.inl ≫ k = pushout.inl ≫ l) (h₁ : pushout.inr ≫ k = pushout.inr ≫ l) : k = l := colimit.hom_ext <| PushoutCocone.coequalizer_ext _ h₀ h₁ #align category_theory.limits.pushout.hom_ext CategoryTheory.Limits.pushout.hom_ext /-- The pushout cocone built from the pushout coprojections is a pushout. -/ def pushoutIsPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : IsColimit (PushoutCocone.mk (pushout.inl : _ ⟶ pushout f g) pushout.inr pushout.condition) := PushoutCocone.IsColimit.mk _ (fun s => pushout.desc s.inl s.inr s.condition) (by simp) (by simp) (by aesop_cat) #align category_theory.limits.pushout_is_pushout CategoryTheory.Limits.pushoutIsPushout /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inl_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi g] : Epi (pushout.inl : Y ⟶ pushout f g) := PushoutCocone.epi_inl_of_is_pushout_of_epi (colimit.isColimit _) #align category_theory.limits.pushout.inl_of_epi CategoryTheory.Limits.pushout.inl_of_epi /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inr_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi f] : Epi (pushout.inr : Z ⟶ pushout f g) := PushoutCocone.epi_inr_of_is_pushout_of_epi (colimit.isColimit _) #align category_theory.limits.pushout.inr_of_epi CategoryTheory.Limits.pushout.inr_of_epi /-- The map `X ⨿ Y ⟶ X ⨿[Z] Y` is epi. -/ instance epi_coprod_to_pushout {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasBinaryCoproduct Y Z] : Epi (coprod.desc pushout.inl pushout.inr : _ ⟶ pushout f g) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => coprod.inl ≫ f) h · simpa using congrArg (fun f => coprod.inr ≫ f) h⟩ #align category_theory.limits.epi_coprod_to_pushout CategoryTheory.Limits.epi_coprod_to_pushout instance pullback.map_isIso {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pullback.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · aesop_cat · aesop_cat #align category_theory.limits.pullback.map_is_iso CategoryTheory.Limits.pullback.map_isIso /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pullback f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pullback.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : pullback f₁ g₁ ≅ pullback f₂ g₂ := asIso <| pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) #align category_theory.limits.pullback.congr_hom CategoryTheory.Limits.pullback.congrHom @[simp] theorem pullback.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : (pullback.congrHom h₁ h₂).inv = pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext · erw [pullback.lift_fst] rw [Iso.inv_comp_eq] erw [pullback.lift_fst_assoc] rw [Category.comp_id, Category.comp_id] · erw [pullback.lift_snd] rw [Iso.inv_comp_eq] erw [pullback.lift_snd_assoc] rw [Category.comp_id, Category.comp_id] #align category_theory.limits.pullback.congr_hom_inv CategoryTheory.Limits.pullback.congrHom_inv instance pushout.map_isIso {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pushout.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pushout.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · aesop_cat · aesop_cat #align category_theory.limits.pushout.map_is_iso CategoryTheory.Limits.pushout.map_isIso theorem pullback.mapDesc_comp {X Y S T S' : C} (f : X ⟶ T) (g : Y ⟶ T) (i : T ⟶ S) (i' : S ⟶ S') [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] [HasPullback (f ≫ i ≫ i') (g ≫ i ≫ i')] [HasPullback ((f ≫ i) ≫ i') ((g ≫ i) ≫ i')] : pullback.mapDesc f g (i ≫ i') = pullback.mapDesc f g i ≫ pullback.mapDesc _ _ i' ≫ (pullback.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom := by aesop_cat #align category_theory.limits.pullback.map_desc_comp CategoryTheory.Limits.pullback.mapDesc_comp /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pushout f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pushout.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : pushout f₁ g₁ ≅ pushout f₂ g₂ := asIso <| pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) #align category_theory.limits.pushout.congr_hom CategoryTheory.Limits.pushout.congrHom @[simp] theorem pushout.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : (pushout.congrHom h₁ h₂).inv = pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext · erw [pushout.inl_desc] rw [Iso.comp_inv_eq, Category.id_comp] erw [pushout.inl_desc] rw [Category.id_comp] · erw [pushout.inr_desc] rw [Iso.comp_inv_eq, Category.id_comp] erw [pushout.inr_desc] rw [Category.id_comp] #align category_theory.limits.pushout.congr_hom_inv CategoryTheory.Limits.pushout.congrHom_inv theorem pushout.mapLift_comp {X Y S T S' : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) (i' : S' ⟶ S) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] [HasPushout (i' ≫ i ≫ f) (i' ≫ i ≫ g)] [HasPushout ((i' ≫ i) ≫ f) ((i' ≫ i) ≫ g)] : pushout.mapLift f g (i' ≫ i) = (pushout.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom ≫ pushout.mapLift _ _ i' ≫ pushout.mapLift f g i := by aesop_cat #align category_theory.limits.pushout.map_lift_comp CategoryTheory.Limits.pushout.mapLift_comp section variable (G : C ⥤ D) /-- The comparison morphism for the pullback of `f,g`. This is an isomorphism iff `G` preserves the pullback of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : G.obj (pullback f g) ⟶ pullback (G.map f) (G.map g) := pullback.lift (G.map pullback.fst) (G.map pullback.snd) (by simp only [← G.map_comp, pullback.condition]) #align category_theory.limits.pullback_comparison CategoryTheory.Limits.pullbackComparison @[reassoc (attr := simp)] theorem pullbackComparison_comp_fst (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.fst = G.map pullback.fst := pullback.lift_fst _ _ _ #align category_theory.limits.pullback_comparison_comp_fst CategoryTheory.Limits.pullbackComparison_comp_fst @[reassoc (attr := simp)] theorem pullbackComparison_comp_snd (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.snd = G.map pullback.snd := pullback.lift_snd _ _ _ #align category_theory.limits.pullback_comparison_comp_snd CategoryTheory.Limits.pullbackComparison_comp_snd @[reassoc (attr := simp)] theorem map_lift_pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] {W : C} {h : W ⟶ X} {k : W ⟶ Y} (w : h ≫ f = k ≫ g) : G.map (pullback.lift _ _ w) ≫ pullbackComparison G f g = pullback.lift (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] #align category_theory.limits.map_lift_pullback_comparison CategoryTheory.Limits.map_lift_pullbackComparison /-- The comparison morphism for the pushout of `f,g`. This is an isomorphism iff `G` preserves the pushout of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout (G.map f) (G.map g) ⟶ G.obj (pushout f g) := pushout.desc (G.map pushout.inl) (G.map pushout.inr) (by simp only [← G.map_comp, pushout.condition]) #align category_theory.limits.pushout_comparison CategoryTheory.Limits.pushoutComparison @[reassoc (attr := simp)] theorem inl_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inl ≫ pushoutComparison G f g = G.map pushout.inl := pushout.inl_desc _ _ _ #align category_theory.limits.inl_comp_pushout_comparison CategoryTheory.Limits.inl_comp_pushoutComparison @[reassoc (attr := simp)] theorem inr_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inr ≫ pushoutComparison G f g = G.map pushout.inr := pushout.inr_desc _ _ _ #align category_theory.limits.inr_comp_pushout_comparison CategoryTheory.Limits.inr_comp_pushoutComparison @[reassoc (attr := simp)] theorem pushoutComparison_map_desc (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] {W : C} {h : Y ⟶ W} {k : Z ⟶ W} (w : f ≫ h = g ≫ k) : pushoutComparison G f g ≫ G.map (pushout.desc _ _ w) = pushout.desc (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] #align category_theory.limits.pushout_comparison_map_desc CategoryTheory.Limits.pushoutComparison_map_desc end section PullbackSymmetry open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPullback_symmetry [HasPullback f g] : HasPullback g f := ⟨⟨⟨_, PullbackCone.flipIsLimit (pullbackIsPullback f g)⟩⟩⟩ #align category_theory.limits.has_pullback_symmetry CategoryTheory.Limits.hasPullback_symmetry attribute [local instance] hasPullback_symmetry /-- The isomorphism `X ×[Z] Y ≅ Y ×[Z] X`. -/ def pullbackSymmetry [HasPullback f g] : pullback f g ≅ pullback g f := IsLimit.conePointUniqueUpToIso (PullbackCone.flipIsLimit (pullbackIsPullback f g)) (limit.isLimit _) #align category_theory.limits.pullback_symmetry CategoryTheory.Limits.pullbackSymmetry @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_fst [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.fst = pullback.snd := by simp [pullbackSymmetry] #align category_theory.limits.pullback_symmetry_hom_comp_fst CategoryTheory.Limits.pullbackSymmetry_hom_comp_fst @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_snd [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.snd = pullback.fst := by simp [pullbackSymmetry] #align category_theory.limits.pullback_symmetry_hom_comp_snd CategoryTheory.Limits.pullbackSymmetry_hom_comp_snd @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_fst [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.fst = pullback.snd := by simp [Iso.inv_comp_eq] #align category_theory.limits.pullback_symmetry_inv_comp_fst CategoryTheory.Limits.pullbackSymmetry_inv_comp_fst @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_snd [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.snd = pullback.fst := by simp [Iso.inv_comp_eq] #align category_theory.limits.pullback_symmetry_inv_comp_snd CategoryTheory.Limits.pullbackSymmetry_inv_comp_snd end PullbackSymmetry section PushoutSymmetry open WalkingCospan variable (f : X ⟶ Y) (g : X ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPushout_symmetry [HasPushout f g] : HasPushout g f := ⟨⟨⟨_, PushoutCocone.flipIsColimit (pushoutIsPushout f g)⟩⟩⟩ #align category_theory.limits.has_pushout_symmetry CategoryTheory.Limits.hasPushout_symmetry attribute [local instance] hasPushout_symmetry /-- The isomorphism `Y ⨿[X] Z ≅ Z ⨿[X] Y`. -/ def pushoutSymmetry [HasPushout f g] : pushout f g ≅ pushout g f := IsColimit.coconePointUniqueUpToIso (PushoutCocone.flipIsColimit (pushoutIsPushout f g)) (colimit.isColimit _) #align category_theory.limits.pushout_symmetry CategoryTheory.Limits.pushoutSymmetry @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inl ≫ (pushoutSymmetry f g).hom = pushout.inr := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ #align category_theory.limits.inl_comp_pushout_symmetry_hom CategoryTheory.Limits.inl_comp_pushoutSymmetry_hom @[reassoc (attr := simp)] theorem inr_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inr ≫ (pushoutSymmetry f g).hom = pushout.inl := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ #align category_theory.limits.inr_comp_pushout_symmetry_hom CategoryTheory.Limits.inr_comp_pushoutSymmetry_hom @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inl ≫ (pushoutSymmetry f g).inv = pushout.inr := by simp [Iso.comp_inv_eq] #align category_theory.limits.inl_comp_pushout_symmetry_inv CategoryTheory.Limits.inl_comp_pushoutSymmetry_inv @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/Shapes/Pullbacks.lean
1,613
1,614
theorem inr_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inr ≫ (pushoutSymmetry f g).inv = pushout.inl := by
simp [Iso.comp_inv_eq]
/- Copyright (c) 2020 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Halting import Mathlib.Computability.TuringMachine import Mathlib.Data.Num.Lemmas import Mathlib.Tactic.DeriveFintype #align_import computability.tm_to_partrec from "leanprover-community/mathlib"@"6155d4351090a6fad236e3d2e4e0e4e7342668e8" /-! # Modelling partial recursive functions using Turing machines This file defines a simplified basis for partial recursive functions, and a `Turing.TM2` model Turing machine for evaluating these functions. This amounts to a constructive proof that every `Partrec` function can be evaluated by a Turing machine. ## Main definitions * `ToPartrec.Code`: a simplified basis for partial recursive functions, valued in `List ℕ →. List ℕ`. * `ToPartrec.Code.eval`: semantics for a `ToPartrec.Code` program * `PartrecToTM2.tr`: A TM2 turing machine which can evaluate `code` programs -/ open Function (update) open Relation namespace Turing /-! ## A simplified basis for partrec This section constructs the type `Code`, which is a data type of programs with `List ℕ` input and output, with enough expressivity to write any partial recursive function. The primitives are: * `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`. * `succ` returns the successor of the head of the input, defaulting to zero if there is no head: * `succ [] = [1]` * `succ (n :: v) = [n + 1]` * `tail` returns the tail of the input * `tail [] = []` * `tail (n :: v) = v` * `cons f fs` calls `f` and `fs` on the input and conses the results: * `cons f fs v = (f v).head :: fs v` * `comp f g` calls `f` on the output of `g`: * `comp f g v = f (g v)` * `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or a successor (similar to `Nat.casesOn`). * `case f g [] = f []` * `case f g (0 :: v) = f v` * `case f g (n+1 :: v) = g (n :: v)` * `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f` again or finish: * `fix f v = []` if `f v = []` * `fix f v = w` if `f v = 0 :: w` * `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded) This basis is convenient because it is closer to the Turing machine model - the key operations are splitting and merging of lists of unknown length, while the messy `n`-ary composition operation from the traditional basis for partial recursive functions is absent - but it retains a compositional semantics. The first step in transitioning to Turing machines is to make a sequential evaluator for this basis, which we take up in the next section. -/ namespace ToPartrec /-- The type of codes for primitive recursive functions. Unlike `Nat.Partrec.Code`, this uses a set of operations on `List ℕ`. See `Code.eval` for a description of the behavior of the primitives. -/ inductive Code | zero' | succ | tail | cons : Code → Code → Code | comp : Code → Code → Code | case : Code → Code → Code | fix : Code → Code deriving DecidableEq, Inhabited #align turing.to_partrec.code Turing.ToPartrec.Code #align turing.to_partrec.code.zero' Turing.ToPartrec.Code.zero' #align turing.to_partrec.code.succ Turing.ToPartrec.Code.succ #align turing.to_partrec.code.tail Turing.ToPartrec.Code.tail #align turing.to_partrec.code.cons Turing.ToPartrec.Code.cons #align turing.to_partrec.code.comp Turing.ToPartrec.Code.comp #align turing.to_partrec.code.case Turing.ToPartrec.Code.case #align turing.to_partrec.code.fix Turing.ToPartrec.Code.fix /-- The semantics of the `Code` primitives, as partial functions `List ℕ →. List ℕ`. By convention we functions that return a single result return a singleton `[n]`, or in some cases `n :: v` where `v` will be ignored by a subsequent function. * `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`. * `succ` returns the successor of the head of the input, defaulting to zero if there is no head: * `succ [] = [1]` * `succ (n :: v) = [n + 1]` * `tail` returns the tail of the input * `tail [] = []` * `tail (n :: v) = v` * `cons f fs` calls `f` and `fs` on the input and conses the results: * `cons f fs v = (f v).head :: fs v` * `comp f g` calls `f` on the output of `g`: * `comp f g v = f (g v)` * `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or a successor (similar to `Nat.casesOn`). * `case f g [] = f []` * `case f g (0 :: v) = f v` * `case f g (n+1 :: v) = g (n :: v)` * `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f` again or finish: * `fix f v = []` if `f v = []` * `fix f v = w` if `f v = 0 :: w` * `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded) -/ def Code.eval : Code → List ℕ →. List ℕ | Code.zero' => fun v => pure (0 :: v) | Code.succ => fun v => pure [v.headI.succ] | Code.tail => fun v => pure v.tail | Code.cons f fs => fun v => do let n ← Code.eval f v let ns ← Code.eval fs v pure (n.headI :: ns) | Code.comp f g => fun v => g.eval v >>= f.eval | Code.case f g => fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail) | Code.fix f => PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail #align turing.to_partrec.code.eval Turing.ToPartrec.Code.eval namespace Code /- Porting note: The equation lemma of `eval` is too strong; it simplifies terms like the LHS of `pred_eval`. Even `eqns` can't fix this. We removed `simp` attr from `eval` and prepare new simp lemmas for `eval`. -/ @[simp] theorem zero'_eval : zero'.eval = fun v => pure (0 :: v) := by simp [eval] @[simp] theorem succ_eval : succ.eval = fun v => pure [v.headI.succ] := by simp [eval] @[simp] theorem tail_eval : tail.eval = fun v => pure v.tail := by simp [eval] @[simp] theorem cons_eval (f fs) : (cons f fs).eval = fun v => do { let n ← Code.eval f v let ns ← Code.eval fs v pure (n.headI :: ns) } := by simp [eval] @[simp] theorem comp_eval (f g) : (comp f g).eval = fun v => g.eval v >>= f.eval := by simp [eval] @[simp] theorem case_eval (f g) : (case f g).eval = fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail) := by simp [eval] @[simp] theorem fix_eval (f) : (fix f).eval = PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail := by simp [eval] /-- `nil` is the constant nil function: `nil v = []`. -/ def nil : Code := tail.comp succ #align turing.to_partrec.code.nil Turing.ToPartrec.Code.nil @[simp] theorem nil_eval (v) : nil.eval v = pure [] := by simp [nil] #align turing.to_partrec.code.nil_eval Turing.ToPartrec.Code.nil_eval /-- `id` is the identity function: `id v = v`. -/ def id : Code := tail.comp zero' #align turing.to_partrec.code.id Turing.ToPartrec.Code.id @[simp] theorem id_eval (v) : id.eval v = pure v := by simp [id] #align turing.to_partrec.code.id_eval Turing.ToPartrec.Code.id_eval /-- `head` gets the head of the input list: `head [] = [0]`, `head (n :: v) = [n]`. -/ def head : Code := cons id nil #align turing.to_partrec.code.head Turing.ToPartrec.Code.head @[simp] theorem head_eval (v) : head.eval v = pure [v.headI] := by simp [head] #align turing.to_partrec.code.head_eval Turing.ToPartrec.Code.head_eval /-- `zero` is the constant zero function: `zero v = [0]`. -/ def zero : Code := cons zero' nil #align turing.to_partrec.code.zero Turing.ToPartrec.Code.zero @[simp] theorem zero_eval (v) : zero.eval v = pure [0] := by simp [zero] #align turing.to_partrec.code.zero_eval Turing.ToPartrec.Code.zero_eval /-- `pred` returns the predecessor of the head of the input: `pred [] = [0]`, `pred (0 :: v) = [0]`, `pred (n+1 :: v) = [n]`. -/ def pred : Code := case zero head #align turing.to_partrec.code.pred Turing.ToPartrec.Code.pred @[simp] theorem pred_eval (v) : pred.eval v = pure [v.headI.pred] := by simp [pred]; cases v.headI <;> simp #align turing.to_partrec.code.pred_eval Turing.ToPartrec.Code.pred_eval /-- `rfind f` performs the function of the `rfind` primitive of partial recursive functions. `rfind f v` returns the smallest `n` such that `(f (n :: v)).head = 0`. It is implemented as: rfind f v = pred (fix (fun (n::v) => f (n::v) :: n+1 :: v) (0 :: v)) The idea is that the initial state is `0 :: v`, and the `fix` keeps `n :: v` as its internal state; it calls `f (n :: v)` as the exit test and `n+1 :: v` as the next state. At the end we get `n+1 :: v` where `n` is the desired output, and `pred (n+1 :: v) = [n]` returns the result. -/ def rfind (f : Code) : Code := comp pred <| comp (fix <| cons f <| cons succ tail) zero' #align turing.to_partrec.code.rfind Turing.ToPartrec.Code.rfind /-- `prec f g` implements the `prec` (primitive recursion) operation of partial recursive functions. `prec f g` evaluates as: * `prec f g [] = [f []]` * `prec f g (0 :: v) = [f v]` * `prec f g (n+1 :: v) = [g (n :: prec f g (n :: v) :: v)]` It is implemented as: G (a :: b :: IH :: v) = (b :: a+1 :: b-1 :: g (a :: IH :: v) :: v) F (0 :: f_v :: v) = (f_v :: v) F (n+1 :: f_v :: v) = (fix G (0 :: n :: f_v :: v)).tail.tail prec f g (a :: v) = [(F (a :: f v :: v)).head] Because `fix` always evaluates its body at least once, we must special case the `0` case to avoid calling `g` more times than necessary (which could be bad if `g` diverges). If the input is `0 :: v`, then `F (0 :: f v :: v) = (f v :: v)` so we return `[f v]`. If the input is `n+1 :: v`, we evaluate the function from the bottom up, with initial state `0 :: n :: f v :: v`. The first number counts up, providing arguments for the applications to `g`, while the second number counts down, providing the exit condition (this is the initial `b` in the return value of `G`, which is stripped by `fix`). After the `fix` is complete, the final state is `n :: 0 :: res :: v` where `res` is the desired result, and the rest reduces this to `[res]`. -/ def prec (f g : Code) : Code := let G := cons tail <| cons succ <| cons (comp pred tail) <| cons (comp g <| cons id <| comp tail tail) <| comp tail <| comp tail tail let F := case id <| comp (comp (comp tail tail) (fix G)) zero' cons (comp F (cons head <| cons (comp f tail) tail)) nil #align turing.to_partrec.code.prec Turing.ToPartrec.Code.prec attribute [-simp] Part.bind_eq_bind Part.map_eq_map Part.pure_eq_some theorem exists_code.comp {m n} {f : Vector ℕ n →. ℕ} {g : Fin n → Vector ℕ m →. ℕ} (hf : ∃ c : Code, ∀ v : Vector ℕ n, c.eval v.1 = pure <$> f v) (hg : ∀ i, ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = pure <$> g i v) : ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = pure <$> ((Vector.mOfFn fun i => g i v) >>= f) := by rsuffices ⟨cg, hg⟩ : ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = Subtype.val <$> Vector.mOfFn fun i => g i v · obtain ⟨cf, hf⟩ := hf exact ⟨cf.comp cg, fun v => by simp [hg, hf, map_bind, seq_bind_eq, Function.comp] rfl⟩ clear hf f; induction' n with n IH · exact ⟨nil, fun v => by simp [Vector.mOfFn, Bind.bind]; rfl⟩ · obtain ⟨cg, hg₁⟩ := hg 0 obtain ⟨cl, hl⟩ := IH fun i => hg i.succ exact ⟨cons cg cl, fun v => by simp [Vector.mOfFn, hg₁, map_bind, seq_bind_eq, bind_assoc, (· ∘ ·), hl] rfl⟩ #align turing.to_partrec.code.exists_code.comp Turing.ToPartrec.Code.exists_code.comp theorem exists_code {n} {f : Vector ℕ n →. ℕ} (hf : Nat.Partrec' f) : ∃ c : Code, ∀ v : Vector ℕ n, c.eval v.1 = pure <$> f v := by induction hf with | prim hf => induction hf with | zero => exact ⟨zero', fun ⟨[], _⟩ => rfl⟩ | succ => exact ⟨succ, fun ⟨[v], _⟩ => rfl⟩ | get i => refine Fin.succRec (fun n => ?_) (fun n i IH => ?_) i · exact ⟨head, fun ⟨List.cons a as, _⟩ => by simp [Bind.bind]; rfl⟩ · obtain ⟨c, h⟩ := IH exact ⟨c.comp tail, fun v => by simpa [← Vector.get_tail, Bind.bind] using h v.tail⟩ | comp g hf hg IHf IHg => simpa [Part.bind_eq_bind] using exists_code.comp IHf IHg | @prec n f g _ _ IHf IHg => obtain ⟨cf, hf⟩ := IHf obtain ⟨cg, hg⟩ := IHg simp only [Part.map_eq_map, Part.map_some, PFun.coe_val] at hf hg refine ⟨prec cf cg, fun v => ?_⟩ rw [← v.cons_head_tail] specialize hf v.tail replace hg := fun a b => hg (a ::ᵥ b ::ᵥ v.tail) simp only [Vector.cons_val, Vector.tail_val] at hf hg simp only [Part.map_eq_map, Part.map_some, Vector.cons_val, Vector.tail_cons, Vector.head_cons, PFun.coe_val, Vector.tail_val] simp only [← Part.pure_eq_some] at hf hg ⊢ induction' v.head with n _ <;> simp [prec, hf, Part.bind_assoc, ← Part.bind_some_eq_map, Part.bind_some, show ∀ x, pure x = [x] from fun _ => rfl, Bind.bind, Functor.map] suffices ∀ a b, a + b = n → (n.succ :: 0 :: g (n ::ᵥ Nat.rec (f v.tail) (fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)) n ::ᵥ v.tail) :: v.val.tail : List ℕ) ∈ PFun.fix (fun v : List ℕ => Part.bind (cg.eval (v.headI :: v.tail.tail)) (fun x => Part.some (if v.tail.headI = 0 then Sum.inl (v.headI.succ :: v.tail.headI.pred :: x.headI :: v.tail.tail.tail : List ℕ) else Sum.inr (v.headI.succ :: v.tail.headI.pred :: x.headI :: v.tail.tail.tail)))) (a :: b :: Nat.rec (f v.tail) (fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)) a :: v.val.tail) by erw [Part.eq_some_iff.2 (this 0 n (zero_add n))] simp only [List.headI, Part.bind_some, List.tail_cons] intro a b e induction' b with b IH generalizing a · refine PFun.mem_fix_iff.2 (Or.inl <| Part.eq_some_iff.1 ?_) simp only [hg, ← e, Part.bind_some, List.tail_cons, pure] rfl · refine PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, IH (a + 1) (by rwa [add_right_comm])⟩) simp only [hg, eval, Part.bind_some, Nat.rec_add_one, List.tail_nil, List.tail_cons, pure] exact Part.mem_some_iff.2 rfl | comp g _ _ IHf IHg => exact exists_code.comp IHf IHg | @rfind n f _ IHf => obtain ⟨cf, hf⟩ := IHf; refine ⟨rfind cf, fun v => ?_⟩ replace hf := fun a => hf (a ::ᵥ v) simp only [Part.map_eq_map, Part.map_some, Vector.cons_val, PFun.coe_val, show ∀ x, pure x = [x] from fun _ => rfl] at hf ⊢ refine Part.ext fun x => ?_ simp only [rfind, Part.bind_eq_bind, Part.pure_eq_some, Part.map_eq_map, Part.bind_some, exists_prop, cons_eval, comp_eval, fix_eval, tail_eval, succ_eval, zero'_eval, List.headI_nil, List.headI_cons, pred_eval, Part.map_some, false_eq_decide_iff, Part.mem_bind_iff, List.length, Part.mem_map_iff, Nat.mem_rfind, List.tail_nil, List.tail_cons, true_eq_decide_iff, Part.mem_some_iff, Part.map_bind] constructor · rintro ⟨v', h1, rfl⟩ suffices ∀ v₁ : List ℕ, v' ∈ PFun.fix (fun v => (cf.eval v).bind fun y => Part.some <| if y.headI = 0 then Sum.inl (v.headI.succ :: v.tail) else Sum.inr (v.headI.succ :: v.tail)) v₁ → ∀ n, (v₁ = n :: v.val) → (∀ m < n, ¬f (m ::ᵥ v) = 0) → ∃ a : ℕ, (f (a ::ᵥ v) = 0 ∧ ∀ {m : ℕ}, m < a → ¬f (m ::ᵥ v) = 0) ∧ [a] = [v'.headI.pred] by exact this _ h1 0 rfl (by rintro _ ⟨⟩) clear h1 intro v₀ h1 refine PFun.fixInduction h1 fun v₁ h2 IH => ?_ clear h1 rintro n rfl hm have := PFun.mem_fix_iff.1 h2 simp only [hf, Part.bind_some] at this split_ifs at this with h · simp only [List.headI_nil, List.headI_cons, exists_false, or_false_iff, Part.mem_some_iff, List.tail_cons, false_and_iff, Sum.inl.injEq] at this subst this exact ⟨_, ⟨h, @(hm)⟩, rfl⟩ · refine IH (n.succ::v.val) (by simp_all) _ rfl fun m h' => ?_ obtain h | rfl := Nat.lt_succ_iff_lt_or_eq.1 h' exacts [hm _ h, h] · rintro ⟨n, ⟨hn, hm⟩, rfl⟩ refine ⟨n.succ::v.1, ?_, rfl⟩ have : (n.succ::v.1 : List ℕ) ∈ PFun.fix (fun v => (cf.eval v).bind fun y => Part.some <| if y.headI = 0 then Sum.inl (v.headI.succ :: v.tail) else Sum.inr (v.headI.succ :: v.tail)) (n::v.val) := PFun.mem_fix_iff.2 (Or.inl (by simp [hf, hn])) generalize (n.succ :: v.1 : List ℕ) = w at this ⊢ clear hn induction' n with n IH · exact this refine IH (fun {m} h' => hm (Nat.lt_succ_of_lt h')) (PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, this⟩)) simp only [hf, hm n.lt_succ_self, Part.bind_some, List.headI, eq_self_iff_true, if_false, Part.mem_some_iff, and_self_iff, List.tail_cons] #align turing.to_partrec.code.exists_code Turing.ToPartrec.Code.exists_code end Code /-! ## From compositional semantics to sequential semantics Our initial sequential model is designed to be as similar as possible to the compositional semantics in terms of its primitives, but it is a sequential semantics, meaning that rather than defining an `eval c : List ℕ →. List ℕ` function for each program, defined by recursion on programs, we have a type `Cfg` with a step function `step : Cfg → Option cfg` that provides a deterministic evaluation order. In order to do this, we introduce the notion of a *continuation*, which can be viewed as a `Code` with a hole in it where evaluation is currently taking place. Continuations can be assigned a `List ℕ →. List ℕ` semantics as well, with the interpretation being that given a `List ℕ` result returned from the code in the hole, the remainder of the program will evaluate to a `List ℕ` final value. The continuations are: * `halt`: the empty continuation: the hole is the whole program, whatever is returned is the final result. In our notation this is just `_`. * `cons₁ fs v k`: evaluating the first part of a `cons`, that is `k (_ :: fs v)`, where `k` is the outer continuation. * `cons₂ ns k`: evaluating the second part of a `cons`: `k (ns.headI :: _)`. (Technically we don't need to hold on to all of `ns` here since we are already committed to taking the head, but this is more regular.) * `comp f k`: evaluating the first part of a composition: `k (f _)`. * `fix f k`: waiting for the result of `f` in a `fix f` expression: `k (if _.headI = 0 then _.tail else fix f (_.tail))` The type `Cfg` of evaluation states is: * `ret k v`: we have received a result, and are now evaluating the continuation `k` with result `v`; that is, `k v` where `k` is ready to evaluate. * `halt v`: we are done and the result is `v`. The main theorem of this section is that for each code `c`, the state `stepNormal c halt v` steps to `v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ /-- The type of continuations, built up during evaluation of a `Code` expression. -/ inductive Cont | halt | cons₁ : Code → List ℕ → Cont → Cont | cons₂ : List ℕ → Cont → Cont | comp : Code → Cont → Cont | fix : Code → Cont → Cont deriving Inhabited #align turing.to_partrec.cont Turing.ToPartrec.Cont #align turing.to_partrec.cont.halt Turing.ToPartrec.Cont.halt #align turing.to_partrec.cont.cons₁ Turing.ToPartrec.Cont.cons₁ #align turing.to_partrec.cont.cons₂ Turing.ToPartrec.Cont.cons₂ #align turing.to_partrec.cont.comp Turing.ToPartrec.Cont.comp #align turing.to_partrec.cont.fix Turing.ToPartrec.Cont.fix /-- The semantics of a continuation. -/ def Cont.eval : Cont → List ℕ →. List ℕ | Cont.halt => pure | Cont.cons₁ fs as k => fun v => do let ns ← Code.eval fs as Cont.eval k (v.headI :: ns) | Cont.cons₂ ns k => fun v => Cont.eval k (ns.headI :: v) | Cont.comp f k => fun v => Code.eval f v >>= Cont.eval k | Cont.fix f k => fun v => if v.headI = 0 then k.eval v.tail else f.fix.eval v.tail >>= k.eval #align turing.to_partrec.cont.eval Turing.ToPartrec.Cont.eval /-- The set of configurations of the machine: * `halt v`: The machine is about to stop and `v : List ℕ` is the result. * `ret k v`: The machine is about to pass `v : List ℕ` to continuation `k : cont`. We don't have a state corresponding to normal evaluation because these are evaluated immediately to a `ret` "in zero steps" using the `stepNormal` function. -/ inductive Cfg | halt : List ℕ → Cfg | ret : Cont → List ℕ → Cfg deriving Inhabited #align turing.to_partrec.cfg Turing.ToPartrec.Cfg #align turing.to_partrec.cfg.halt Turing.ToPartrec.Cfg.halt #align turing.to_partrec.cfg.ret Turing.ToPartrec.Cfg.ret /-- Evaluating `c : Code` in a continuation `k : Cont` and input `v : List ℕ`. This goes by recursion on `c`, building an augmented continuation and a value to pass to it. * `zero' v = 0 :: v` evaluates immediately, so we return it to the parent continuation * `succ v = [v.headI.succ]` evaluates immediately, so we return it to the parent continuation * `tail v = v.tail` evaluates immediately, so we return it to the parent continuation * `cons f fs v = (f v).headI :: fs v` requires two sub-evaluations, so we evaluate `f v` in the continuation `k (_.headI :: fs v)` (called `Cont.cons₁ fs v k`) * `comp f g v = f (g v)` requires two sub-evaluations, so we evaluate `g v` in the continuation `k (f _)` (called `Cont.comp f k`) * `case f g v = v.head.casesOn (f v.tail) (fun n => g (n :: v.tail))` has the information needed to evaluate the case statement, so we do that and transition to either `f v` or `g (n :: v.tail)`. * `fix f v = let v' := f v; if v'.headI = 0 then k v'.tail else fix f v'.tail` needs to first evaluate `f v`, so we do that and leave the rest for the continuation (called `Cont.fix f k`) -/ def stepNormal : Code → Cont → List ℕ → Cfg | Code.zero' => fun k v => Cfg.ret k (0::v) | Code.succ => fun k v => Cfg.ret k [v.headI.succ] | Code.tail => fun k v => Cfg.ret k v.tail | Code.cons f fs => fun k v => stepNormal f (Cont.cons₁ fs v k) v | Code.comp f g => fun k v => stepNormal g (Cont.comp f k) v | Code.case f g => fun k v => v.headI.rec (stepNormal f k v.tail) fun y _ => stepNormal g k (y::v.tail) | Code.fix f => fun k v => stepNormal f (Cont.fix f k) v #align turing.to_partrec.step_normal Turing.ToPartrec.stepNormal /-- Evaluating a continuation `k : Cont` on input `v : List ℕ`. This is the second part of evaluation, when we receive results from continuations built by `stepNormal`. * `Cont.halt v = v`, so we are done and transition to the `Cfg.halt v` state * `Cont.cons₁ fs as k v = k (v.headI :: fs as)`, so we evaluate `fs as` now with the continuation `k (v.headI :: _)` (called `cons₂ v k`). * `Cont.cons₂ ns k v = k (ns.headI :: v)`, where we now have everything we need to evaluate `ns.headI :: v`, so we return it to `k`. * `Cont.comp f k v = k (f v)`, so we call `f v` with `k` as the continuation. * `Cont.fix f k v = k (if v.headI = 0 then k v.tail else fix f v.tail)`, where `v` is a value, so we evaluate the if statement and either call `k` with `v.tail`, or call `fix f v` with `k` as the continuation (which immediately calls `f` with `Cont.fix f k` as the continuation). -/ def stepRet : Cont → List ℕ → Cfg | Cont.halt, v => Cfg.halt v | Cont.cons₁ fs as k, v => stepNormal fs (Cont.cons₂ v k) as | Cont.cons₂ ns k, v => stepRet k (ns.headI :: v) | Cont.comp f k, v => stepNormal f k v | Cont.fix f k, v => if v.headI = 0 then stepRet k v.tail else stepNormal f (Cont.fix f k) v.tail #align turing.to_partrec.step_ret Turing.ToPartrec.stepRet /-- If we are not done (in `Cfg.halt` state), then we must be still stuck on a continuation, so this main loop calls `stepRet` with the new continuation. The overall `step` function transitions from one `Cfg` to another, only halting at the `Cfg.halt` state. -/ def step : Cfg → Option Cfg | Cfg.halt _ => none | Cfg.ret k v => some (stepRet k v) #align turing.to_partrec.step Turing.ToPartrec.step /-- In order to extract a compositional semantics from the sequential execution behavior of configurations, we observe that continuations have a monoid structure, with `Cont.halt` as the unit and `Cont.then` as the multiplication. `Cont.then k₁ k₂` runs `k₁` until it halts, and then takes the result of `k₁` and passes it to `k₂`. We will not prove it is associative (although it is), but we are instead interested in the associativity law `k₂ (eval c k₁) = eval c (k₁.then k₂)`. This holds at both the sequential and compositional levels, and allows us to express running a machine without the ambient continuation and relate it to the original machine's evaluation steps. In the literature this is usually where one uses Turing machines embedded inside other Turing machines, but this approach allows us to avoid changing the ambient type `Cfg` in the middle of the recursion. -/ def Cont.then : Cont → Cont → Cont | Cont.halt => fun k' => k' | Cont.cons₁ fs as k => fun k' => Cont.cons₁ fs as (k.then k') | Cont.cons₂ ns k => fun k' => Cont.cons₂ ns (k.then k') | Cont.comp f k => fun k' => Cont.comp f (k.then k') | Cont.fix f k => fun k' => Cont.fix f (k.then k') #align turing.to_partrec.cont.then Turing.ToPartrec.Cont.then theorem Cont.then_eval {k k' : Cont} {v} : (k.then k').eval v = k.eval v >>= k'.eval := by induction' k with _ _ _ _ _ _ _ _ _ k_ih _ _ k_ih generalizing v <;> simp only [Cont.eval, Cont.then, bind_assoc, pure_bind, *] · simp only [← k_ih] · split_ifs <;> [rfl; simp only [← k_ih, bind_assoc]] #align turing.to_partrec.cont.then_eval Turing.ToPartrec.Cont.then_eval /-- The `then k` function is a "configuration homomorphism". Its operation on states is to append `k` to the continuation of a `Cfg.ret` state, and to run `k` on `v` if we are in the `Cfg.halt v` state. -/ def Cfg.then : Cfg → Cont → Cfg | Cfg.halt v => fun k' => stepRet k' v | Cfg.ret k v => fun k' => Cfg.ret (k.then k') v #align turing.to_partrec.cfg.then Turing.ToPartrec.Cfg.then /-- The `stepNormal` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state. -/ theorem stepNormal_then (c) (k k' : Cont) (v) : stepNormal c (k.then k') v = (stepNormal c k v).then k' := by induction c generalizing k v with simp only [Cont.then, stepNormal, *] | cons c c' ih _ => rw [← ih, Cont.then] | comp c c' _ ih' => rw [← ih', Cont.then] | case => cases v.headI <;> simp only [Nat.rec_zero] | fix c ih => rw [← ih, Cont.then] | _ => simp only [Cfg.then] #align turing.to_partrec.step_normal_then Turing.ToPartrec.stepNormal_then /-- The `stepRet` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state. -/ theorem stepRet_then {k k' : Cont} {v} : stepRet (k.then k') v = (stepRet k v).then k' := by induction k generalizing v with simp only [Cont.then, stepRet, *] | cons₁ => rw [← stepNormal_then] rfl | comp => rw [← stepNormal_then] | fix _ _ k_ih => split_ifs · rw [← k_ih] · rw [← stepNormal_then] rfl | _ => simp only [Cfg.then] #align turing.to_partrec.step_ret_then Turing.ToPartrec.stepRet_then /-- This is a temporary definition, because we will prove in `code_is_ok` that it always holds. It asserts that `c` is semantically correct; that is, for any `k` and `v`, `eval (stepNormal c k v) = eval (Cfg.ret k (Code.eval c v))`, as an equality of partial values (so one diverges iff the other does). In particular, we can let `k = Cont.halt`, and then this asserts that `stepNormal c Cont.halt v` evaluates to `Cfg.halt (Code.eval c v)`. -/ def Code.Ok (c : Code) := ∀ k v, Turing.eval step (stepNormal c k v) = Code.eval c v >>= fun v => Turing.eval step (Cfg.ret k v) #align turing.to_partrec.code.ok Turing.ToPartrec.Code.Ok theorem Code.Ok.zero {c} (h : Code.Ok c) {v} : Turing.eval step (stepNormal c Cont.halt v) = Cfg.halt <$> Code.eval c v := by rw [h, ← bind_pure_comp]; congr; funext v exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.single rfl, rfl⟩) #align turing.to_partrec.code.ok.zero Turing.ToPartrec.Code.Ok.zero theorem stepNormal.is_ret (c k v) : ∃ k' v', stepNormal c k v = Cfg.ret k' v' := by induction c generalizing k v with | cons _f fs IHf _IHfs => apply IHf | comp f _g _IHf IHg => apply IHg | case f g IHf IHg => rw [stepNormal] simp only [] cases v.headI <;> [apply IHf; apply IHg] | fix f IHf => apply IHf | _ => exact ⟨_, _, rfl⟩ #align turing.to_partrec.step_normal.is_ret Turing.ToPartrec.stepNormal.is_ret theorem cont_eval_fix {f k v} (fok : Code.Ok f) : Turing.eval step (stepNormal f (Cont.fix f k) v) = f.fix.eval v >>= fun v => Turing.eval step (Cfg.ret k v) := by refine Part.ext fun x => ?_ simp only [Part.bind_eq_bind, Part.mem_bind_iff] constructor · suffices ∀ c, x ∈ eval step c → ∀ v c', c = Cfg.then c' (Cont.fix f k) → Reaches step (stepNormal f Cont.halt v) c' → ∃ v₁ ∈ f.eval v, ∃ v₂ ∈ if List.headI v₁ = 0 then pure v₁.tail else f.fix.eval v₁.tail, x ∈ eval step (Cfg.ret k v₂) by intro h obtain ⟨v₁, hv₁, v₂, hv₂, h₃⟩ := this _ h _ _ (stepNormal_then _ Cont.halt _ _) ReflTransGen.refl refine ⟨v₂, PFun.mem_fix_iff.2 ?_, h₃⟩ simp only [Part.eq_some_iff.2 hv₁, Part.map_some] split_ifs at hv₂ ⊢ · rw [Part.mem_some_iff.1 hv₂] exact Or.inl (Part.mem_some _) · exact Or.inr ⟨_, Part.mem_some _, hv₂⟩ refine fun c he => evalInduction he fun y h IH => ?_ rintro v (⟨v'⟩ | ⟨k', v'⟩) rfl hr <;> rw [Cfg.then] at h IH <;> simp only [] at h IH · have := mem_eval.2 ⟨hr, rfl⟩ rw [fok, Part.bind_eq_bind, Part.mem_bind_iff] at this obtain ⟨v'', h₁, h₂⟩ := this rw [reaches_eval] at h₂ swap · exact ReflTransGen.single rfl cases Part.mem_unique h₂ (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩) refine ⟨v', h₁, ?_⟩ rw [stepRet] at h revert h by_cases he : v'.headI = 0 <;> simp only [exists_prop, if_pos, if_false, he] <;> intro h · refine ⟨_, Part.mem_some _, ?_⟩ rw [reaches_eval] · exact h exact ReflTransGen.single rfl · obtain ⟨k₀, v₀, e₀⟩ := stepNormal.is_ret f Cont.halt v'.tail have e₁ := stepNormal_then f Cont.halt (Cont.fix f k) v'.tail rw [e₀, Cont.then, Cfg.then] at e₁ simp only [] at e₁ obtain ⟨v₁, hv₁, v₂, hv₂, h₃⟩ := IH (stepRet (k₀.then (Cont.fix f k)) v₀) (by rw [stepRet, if_neg he, e₁]; rfl) v'.tail _ stepRet_then (by apply ReflTransGen.single; rw [e₀]; rfl) refine ⟨_, PFun.mem_fix_iff.2 ?_, h₃⟩ simp only [Part.eq_some_iff.2 hv₁, Part.map_some, Part.mem_some_iff] split_ifs at hv₂ ⊢ <;> [exact Or.inl (congr_arg Sum.inl (Part.mem_some_iff.1 hv₂)); exact Or.inr ⟨_, rfl, hv₂⟩] · exact IH _ rfl _ _ stepRet_then (ReflTransGen.tail hr rfl) · rintro ⟨v', he, hr⟩ rw [reaches_eval] at hr swap · exact ReflTransGen.single rfl refine PFun.fixInduction he fun v (he : v' ∈ f.fix.eval v) IH => ?_ rw [fok, Part.bind_eq_bind, Part.mem_bind_iff] obtain he | ⟨v'', he₁', _⟩ := PFun.mem_fix_iff.1 he · obtain ⟨v', he₁, he₂⟩ := (Part.mem_map_iff _).1 he split_ifs at he₂ with h; cases he₂ refine ⟨_, he₁, ?_⟩ rw [reaches_eval] swap · exact ReflTransGen.single rfl rwa [stepRet, if_pos h] · obtain ⟨v₁, he₁, he₂⟩ := (Part.mem_map_iff _).1 he₁' split_ifs at he₂ with h; cases he₂ clear he₁' refine ⟨_, he₁, ?_⟩ rw [reaches_eval] swap · exact ReflTransGen.single rfl rw [stepRet, if_neg h] exact IH v₁.tail ((Part.mem_map_iff _).2 ⟨_, he₁, if_neg h⟩) #align turing.to_partrec.cont_eval_fix Turing.ToPartrec.cont_eval_fix theorem code_is_ok (c) : Code.Ok c := by induction c with (intro k v; rw [stepNormal]) | cons f fs IHf IHfs => rw [Code.eval, IHf] simp only [bind_assoc, Cont.eval, pure_bind]; congr; funext v rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IHfs]; congr; funext v' refine Eq.trans (b := eval step (stepRet (Cont.cons₂ v k) v')) ?_ (Eq.symm ?_) <;> exact reaches_eval (ReflTransGen.single rfl) | comp f g IHf IHg => rw [Code.eval, IHg] simp only [bind_assoc, Cont.eval, pure_bind]; congr; funext v rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IHf] | case f g IHf IHg => simp only [Code.eval] cases v.headI <;> simp only [Nat.rec_zero, Part.bind_eq_bind] <;> [apply IHf; apply IHg] | fix f IHf => rw [cont_eval_fix IHf] | _ => simp only [Code.eval, pure_bind] #align turing.to_partrec.code_is_ok Turing.ToPartrec.code_is_ok theorem stepNormal_eval (c v) : eval step (stepNormal c Cont.halt v) = Cfg.halt <$> c.eval v := (code_is_ok c).zero #align turing.to_partrec.step_normal_eval Turing.ToPartrec.stepNormal_eval theorem stepRet_eval {k v} : eval step (stepRet k v) = Cfg.halt <$> k.eval v := by induction k generalizing v with | halt => simp only [mem_eval, Cont.eval, map_pure] exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩) | cons₁ fs as k IH => rw [Cont.eval, stepRet, code_is_ok] simp only [← bind_pure_comp, bind_assoc]; congr; funext v' rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IH, bind_pure_comp] | cons₂ ns k IH => rw [Cont.eval, stepRet]; exact IH | comp f k IH => rw [Cont.eval, stepRet, code_is_ok] simp only [← bind_pure_comp, bind_assoc]; congr; funext v' rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [IH, bind_pure_comp] | fix f k IH => rw [Cont.eval, stepRet]; simp only [bind_pure_comp] split_ifs; · exact IH simp only [← bind_pure_comp, bind_assoc, cont_eval_fix (code_is_ok _)] congr; funext; rw [bind_pure_comp, ← IH] exact reaches_eval (ReflTransGen.single rfl) #align turing.to_partrec.step_ret_eval Turing.ToPartrec.stepRet_eval end ToPartrec /-! ## Simulating sequentialized partial recursive functions in TM2 At this point we have a sequential model of partial recursive functions: the `Cfg` type and `step : Cfg → Option Cfg` function from the previous section. The key feature of this model is that it does a finite amount of computation (in fact, an amount which is statically bounded by the size of the program) between each step, and no individual step can diverge (unlike the compositional semantics, where every sub-part of the computation is potentially divergent). So we can utilize the same techniques as in the other TM simulations in `Computability.TuringMachine` to prove that each step corresponds to a finite number of steps in a lower level model. (We don't prove it here, but in anticipation of the complexity class P, the simulation is actually polynomial-time as well.) The target model is `Turing.TM2`, which has a fixed finite set of stacks, a bit of local storage, with programs selected from a potentially infinite (but finitely accessible) set of program positions, or labels `Λ`, each of which executes a finite sequence of basic stack commands. For this program we will need four stacks, each on an alphabet `Γ'` like so: inductive Γ' | consₗ | cons | bit0 | bit1 We represent a number as a bit sequence, lists of numbers by putting `cons` after each element, and lists of lists of natural numbers by putting `consₗ` after each list. For example: 0 ~> [] 1 ~> [bit1] 6 ~> [bit0, bit1, bit1] [1, 2] ~> [bit1, cons, bit0, bit1, cons] [[], [1, 2]] ~> [consₗ, bit1, cons, bit0, bit1, cons, consₗ] The four stacks are `main`, `rev`, `aux`, `stack`. In normal mode, `main` contains the input to the current program (a `List ℕ`) and `stack` contains data (a `List (List ℕ)`) associated to the current continuation, and in `ret` mode `main` contains the value that is being passed to the continuation and `stack` contains the data for the continuation. The `rev` and `aux` stacks are usually empty; `rev` is used to store reversed data when e.g. moving a value from one stack to another, while `aux` is used as a temporary for a `main`/`stack` swap that happens during `cons₁` evaluation. The only local store we need is `Option Γ'`, which stores the result of the last pop operation. (Most of our working data are natural numbers, which are too large to fit in the local store.) The continuations from the previous section are data-carrying, containing all the values that have been computed and are awaiting other arguments. In order to have only a finite number of continuations appear in the program so that they can be used in machine states, we separate the data part (anything with type `List ℕ`) from the `Cont` type, producing a `Cont'` type that lacks this information. The data is kept on the `stack` stack. Because we want to have subroutines for e.g. moving an entire stack to another place, we use an infinite inductive type `Λ'` so that we can execute a program and then return to do something else without having to define too many different kinds of intermediate states. (We must nevertheless prove that only finitely many labels are accessible.) The labels are: * `move p k₁ k₂ q`: move elements from stack `k₁` to `k₂` while `p` holds of the value being moved. The last element, that fails `p`, is placed in neither stack but left in the local store. At the end of the operation, `k₂` will have the elements of `k₁` in reverse order. Then do `q`. * `clear p k q`: delete elements from stack `k` until `p` is true. Like `move`, the last element is left in the local storage. Then do `q`. * `copy q`: Move all elements from `rev` to both `main` and `stack` (in reverse order), then do `q`. That is, it takes `(a, b, c, d)` to `(b.reverse ++ a, [], c, b.reverse ++ d)`. * `push k f q`: push `f s`, where `s` is the local store, to stack `k`, then do `q`. This is a duplicate of the `push` instruction that is part of the TM2 model, but by having a subroutine just for this purpose we can build up programs to execute inside a `goto` statement, where we have the flexibility to be general recursive. * `read (f : Option Γ' → Λ')`: go to state `f s` where `s` is the local store. Again this is only here for convenience. * `succ q`: perform a successor operation. Assuming `[n]` is encoded on `main` before, `[n+1]` will be on main after. This implements successor for binary natural numbers. * `pred q₁ q₂`: perform a predecessor operation or `case` statement. If `[]` is encoded on `main` before, then we transition to `q₁` with `[]` on main; if `(0 :: v)` is on `main` before then `v` will be on `main` after and we transition to `q₁`; and if `(n+1 :: v)` is on `main` before then `n :: v` will be on `main` after and we transition to `q₂`. * `ret k`: call continuation `k`. Each continuation has its own interpretation of the data in `stack` and sets up the data for the next continuation. * `ret (cons₁ fs k)`: `v :: KData` on `stack` and `ns` on `main`, and the next step expects `v` on `main` and `ns :: KData` on `stack`. So we have to do a little dance here with six reverse-moves using the `aux` stack to perform a three-point swap, each of which involves two reversals. * `ret (cons₂ k)`: `ns :: KData` is on `stack` and `v` is on `main`, and we have to put `ns.headI :: v` on `main` and `KData` on `stack`. This is done using the `head` subroutine. * `ret (fix f k)`: This stores no data, so we just check if `main` starts with `0` and if so, remove it and call `k`, otherwise `clear` the first value and call `f`. * `ret halt`: the stack is empty, and `main` has the output. Do nothing and halt. In addition to these basic states, we define some additional subroutines that are used in the above: * `push'`, `peek'`, `pop'` are special versions of the builtins that use the local store to supply inputs and outputs. * `unrev`: special case `move false rev main` to move everything from `rev` back to `main`. Used as a cleanup operation in several functions. * `moveExcl p k₁ k₂ q`: same as `move` but pushes the last value read back onto the source stack. * `move₂ p k₁ k₂ q`: double `move`, so that the result comes out in the right order at the target stack. Implemented as `moveExcl p k rev; move false rev k₂`. Assumes that neither `k₁` nor `k₂` is `rev` and `rev` is initially empty. * `head k q`: get the first natural number from stack `k` and reverse-move it to `rev`, then clear the rest of the list at `k` and then `unrev` to reverse-move the head value to `main`. This is used with `k = main` to implement regular `head`, i.e. if `v` is on `main` before then `[v.headI]` will be on `main` after; and also with `k = stack` for the `cons` operation, which has `v` on `main` and `ns :: KData` on `stack`, and results in `KData` on `stack` and `ns.headI :: v` on `main`. * `trNormal` is the main entry point, defining states that perform a given `code` computation. It mostly just dispatches to functions written above. The main theorem of this section is `tr_eval`, which asserts that for each that for each code `c`, the state `init c v` steps to `halt v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ set_option linter.uppercaseLean3 false namespace PartrecToTM2 section open ToPartrec /-- The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `ℕ` values as lists of binary digits, `cons` is used to separate `List ℕ` values, and `consₗ` is used to separate `List (List ℕ)` values. See the section documentation. -/ inductive Γ' | consₗ | cons | bit0 | bit1 deriving DecidableEq, Inhabited, Fintype #align turing.partrec_to_TM2.Γ' Turing.PartrecToTM2.Γ' #align turing.partrec_to_TM2.Γ'.Cons Turing.PartrecToTM2.Γ'.consₗ #align turing.partrec_to_TM2.Γ'.cons Turing.PartrecToTM2.Γ'.cons #align turing.partrec_to_TM2.Γ'.bit0 Turing.PartrecToTM2.Γ'.bit0 #align turing.partrec_to_TM2.Γ'.bit1 Turing.PartrecToTM2.Γ'.bit1 /-- The four stacks used by the program. `main` is used to store the input value in `trNormal` mode and the output value in `Λ'.ret` mode, while `stack` is used to keep all the data for the continuations. `rev` is used to store reversed lists when transferring values between stacks, and `aux` is only used once in `cons₁`. See the section documentation. -/ inductive K' | main | rev | aux | stack deriving DecidableEq, Inhabited #align turing.partrec_to_TM2.K' Turing.PartrecToTM2.K' #align turing.partrec_to_TM2.K'.main Turing.PartrecToTM2.K'.main #align turing.partrec_to_TM2.K'.rev Turing.PartrecToTM2.K'.rev #align turing.partrec_to_TM2.K'.aux Turing.PartrecToTM2.K'.aux #align turing.partrec_to_TM2.K'.stack Turing.PartrecToTM2.K'.stack open K' /-- Continuations as in `ToPartrec.Cont` but with the data removed. This is done because we want the set of all continuations in the program to be finite (so that it can ultimately be encoded into the finite state machine of a Turing machine), but a continuation can handle a potentially infinite number of data values during execution. -/ inductive Cont' | halt | cons₁ : Code → Cont' → Cont' | cons₂ : Cont' → Cont' | comp : Code → Cont' → Cont' | fix : Code → Cont' → Cont' deriving DecidableEq, Inhabited #align turing.partrec_to_TM2.cont' Turing.PartrecToTM2.Cont' #align turing.partrec_to_TM2.cont'.halt Turing.PartrecToTM2.Cont'.halt #align turing.partrec_to_TM2.cont'.cons₁ Turing.PartrecToTM2.Cont'.cons₁ #align turing.partrec_to_TM2.cont'.cons₂ Turing.PartrecToTM2.Cont'.cons₂ #align turing.partrec_to_TM2.cont'.comp Turing.PartrecToTM2.Cont'.comp #align turing.partrec_to_TM2.cont'.fix Turing.PartrecToTM2.Cont'.fix /-- The set of program positions. We make extensive use of inductive types here to let us describe "subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where `q` is another label. In order to prevent this from resulting in an infinite number of distinct accessible states, we are careful to be non-recursive (although loops are okay). See the section documentation for a description of all the programs. -/ inductive Λ' | move (p : Γ' → Bool) (k₁ k₂ : K') (q : Λ') | clear (p : Γ' → Bool) (k : K') (q : Λ') | copy (q : Λ') | push (k : K') (s : Option Γ' → Option Γ') (q : Λ') | read (f : Option Γ' → Λ') | succ (q : Λ') | pred (q₁ q₂ : Λ') | ret (k : Cont') #align turing.partrec_to_TM2.Λ' Turing.PartrecToTM2.Λ' #align turing.partrec_to_TM2.Λ'.move Turing.PartrecToTM2.Λ'.move #align turing.partrec_to_TM2.Λ'.clear Turing.PartrecToTM2.Λ'.clear #align turing.partrec_to_TM2.Λ'.copy Turing.PartrecToTM2.Λ'.copy #align turing.partrec_to_TM2.Λ'.push Turing.PartrecToTM2.Λ'.push #align turing.partrec_to_TM2.Λ'.read Turing.PartrecToTM2.Λ'.read #align turing.partrec_to_TM2.Λ'.succ Turing.PartrecToTM2.Λ'.succ #align turing.partrec_to_TM2.Λ'.pred Turing.PartrecToTM2.Λ'.pred #align turing.partrec_to_TM2.Λ'.ret Turing.PartrecToTM2.Λ'.ret -- Porting note: `Turing.PartrecToTM2.Λ'.rec` is noncomputable in Lean4, so we make it computable. compile_inductive% Code compile_inductive% Cont' compile_inductive% K' compile_inductive% Λ' instance Λ'.instInhabited : Inhabited Λ' := ⟨Λ'.ret Cont'.halt⟩ #align turing.partrec_to_TM2.Λ'.inhabited Turing.PartrecToTM2.Λ'.instInhabited instance Λ'.instDecidableEq : DecidableEq Λ' := fun a b => by induction a generalizing b <;> cases b <;> first | apply Decidable.isFalse; rintro ⟨⟨⟩⟩; done | exact decidable_of_iff' _ (by simp [Function.funext_iff]; rfl) #align turing.partrec_to_TM2.Λ'.decidable_eq Turing.PartrecToTM2.Λ'.instDecidableEq /-- The type of TM2 statements used by this machine. -/ def Stmt' := TM2.Stmt (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited #align turing.partrec_to_TM2.stmt' Turing.PartrecToTM2.Stmt' /-- The type of TM2 configurations used by this machine. -/ def Cfg' := TM2.Cfg (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited #align turing.partrec_to_TM2.cfg' Turing.PartrecToTM2.Cfg' open TM2.Stmt /-- A predicate that detects the end of a natural number, either `Γ'.cons` or `Γ'.consₗ` (or implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`. -/ @[simp] def natEnd : Γ' → Bool | Γ'.consₗ => true | Γ'.cons => true | _ => false #align turing.partrec_to_TM2.nat_end Turing.PartrecToTM2.natEnd /-- Pop a value from the stack and place the result in local store. -/ @[simp] def pop' (k : K') : Stmt' → Stmt' := pop k fun _ v => v #align turing.partrec_to_TM2.pop' Turing.PartrecToTM2.pop' /-- Peek a value from the stack and place the result in local store. -/ @[simp] def peek' (k : K') : Stmt' → Stmt' := peek k fun _ v => v #align turing.partrec_to_TM2.peek' Turing.PartrecToTM2.peek' /-- Push the value in the local store to the given stack. -/ @[simp] def push' (k : K') : Stmt' → Stmt' := push k fun x => x.iget #align turing.partrec_to_TM2.push' Turing.PartrecToTM2.push' /-- Move everything from the `rev` stack to the `main` stack (reversed). -/ def unrev := Λ'.move (fun _ => false) rev main #align turing.partrec_to_TM2.unrev Turing.PartrecToTM2.unrev /-- Move elements from `k₁` to `k₂` while `p` holds, with the last element being left on `k₁`. -/ def moveExcl (p k₁ k₂ q) := Λ'.move p k₁ k₂ <| Λ'.push k₁ id q #align turing.partrec_to_TM2.move_excl Turing.PartrecToTM2.moveExcl /-- Move elements from `k₁` to `k₂` without reversion, by performing a double move via the `rev` stack. -/ def move₂ (p k₁ k₂ q) := moveExcl p k₁ rev <| Λ'.move (fun _ => false) rev k₂ q #align turing.partrec_to_TM2.move₂ Turing.PartrecToTM2.move₂ /-- Assuming `trList v` is on the front of stack `k`, remove it, and push `v.headI` onto `main`. See the section documentation. -/ def head (k : K') (q : Λ') : Λ' := Λ'.move natEnd k rev <| (Λ'.push rev fun _ => some Γ'.cons) <| Λ'.read fun s => (if s = some Γ'.consₗ then id else Λ'.clear (fun x => x = Γ'.consₗ) k) <| unrev q #align turing.partrec_to_TM2.head Turing.PartrecToTM2.head /-- The program that evaluates code `c` with continuation `k`. This expects an initial state where `trList v` is on `main`, `trContStack k` is on `stack`, and `aux` and `rev` are empty. See the section documentation for details. -/ @[simp] def trNormal : Code → Cont' → Λ' | Code.zero', k => (Λ'.push main fun _ => some Γ'.cons) <| Λ'.ret k | Code.succ, k => head main <| Λ'.succ <| Λ'.ret k | Code.tail, k => Λ'.clear natEnd main <| Λ'.ret k | Code.cons f fs, k => (Λ'.push stack fun _ => some Γ'.consₗ) <| Λ'.move (fun _ => false) main rev <| Λ'.copy <| trNormal f (Cont'.cons₁ fs k) | Code.comp f g, k => trNormal g (Cont'.comp f k) | Code.case f g, k => Λ'.pred (trNormal f k) (trNormal g k) | Code.fix f, k => trNormal f (Cont'.fix f k) #align turing.partrec_to_TM2.tr_normal Turing.PartrecToTM2.trNormal /-- The main program. See the section documentation for details. -/ def tr : Λ' → Stmt' | Λ'.move p k₁ k₂ q => pop' k₁ <| branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q) | Λ'.push k f q => branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) | Λ'.read q => goto q | Λ'.clear p k q => pop' k <| branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q) | Λ'.copy q => pop' rev <| branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q) | Λ'.succ q => pop' main <| branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) | Λ'.pred q₁ q₂ => pop' main <| branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂)) | Λ'.ret (Cont'.cons₁ fs k) => goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) | Λ'.ret (Cont'.cons₂ k) => goto fun _ => head stack <| Λ'.ret k | Λ'.ret (Cont'.comp f k) => goto fun _ => trNormal f k | Λ'.ret (Cont'.fix f k) => pop' main <| goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k) | Λ'.ret Cont'.halt => (load fun _ => none) <| halt #align turing.partrec_to_TM2.tr Turing.PartrecToTM2.tr /- Porting note: The equation lemma of `tr` simplifies to `match` structures. To prevent this, we replace equation lemmas of `tr`. -/ theorem tr_move (p k₁ k₂ q) : tr (Λ'.move p k₁ k₂ q) = pop' k₁ (branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q)) := rfl theorem tr_push (k f q) : tr (Λ'.push k f q) = branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) := rfl theorem tr_read (q) : tr (Λ'.read q) = goto q := rfl theorem tr_clear (p k q) : tr (Λ'.clear p k q) = pop' k (branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q)) := rfl theorem tr_copy (q) : tr (Λ'.copy q) = pop' rev (branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q)) := rfl theorem tr_succ (q) : tr (Λ'.succ q) = pop' main (branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q)) := rfl theorem tr_pred (q₁ q₂) : tr (Λ'.pred q₁ q₂) = pop' main (branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂))) := rfl theorem tr_ret_cons₁ (fs k) : tr (Λ'.ret (Cont'.cons₁ fs k)) = goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) := rfl theorem tr_ret_cons₂ (k) : tr (Λ'.ret (Cont'.cons₂ k)) = goto fun _ => head stack <| Λ'.ret k := rfl theorem tr_ret_comp (f k) : tr (Λ'.ret (Cont'.comp f k)) = goto fun _ => trNormal f k := rfl theorem tr_ret_fix (f k) : tr (Λ'.ret (Cont'.fix f k)) = pop' main (goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) := rfl theorem tr_ret_halt : tr (Λ'.ret Cont'.halt) = (load fun _ => none) halt := rfl attribute [eqns tr_move tr_push tr_read tr_clear tr_copy tr_succ tr_pred tr_ret_cons₁ tr_ret_cons₂ tr_ret_comp tr_ret_fix tr_ret_halt] tr attribute [simp] tr /-- Translating a `Cont` continuation to a `Cont'` continuation simply entails dropping all the data. This data is instead encoded in `trContStack` in the configuration. -/ def trCont : Cont → Cont' | Cont.halt => Cont'.halt | Cont.cons₁ c _ k => Cont'.cons₁ c (trCont k) | Cont.cons₂ _ k => Cont'.cons₂ (trCont k) | Cont.comp c k => Cont'.comp c (trCont k) | Cont.fix c k => Cont'.fix c (trCont k) #align turing.partrec_to_TM2.tr_cont Turing.PartrecToTM2.trCont /-- We use `PosNum` to define the translation of binary natural numbers. A natural number is represented as a little-endian list of `bit0` and `bit1` elements: 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] In particular, this representation guarantees no trailing `bit0`'s at the end of the list. -/ def trPosNum : PosNum → List Γ' | PosNum.one => [Γ'.bit1] | PosNum.bit0 n => Γ'.bit0 :: trPosNum n | PosNum.bit1 n => Γ'.bit1 :: trPosNum n #align turing.partrec_to_TM2.tr_pos_num Turing.PartrecToTM2.trPosNum /-- We use `Num` to define the translation of binary natural numbers. Positive numbers are translated using `trPosNum`, and `trNum 0 = []`. So there are never any trailing `bit0`'s in a translated `Num`. 0 = [] 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] -/ def trNum : Num → List Γ' | Num.zero => [] | Num.pos n => trPosNum n #align turing.partrec_to_TM2.tr_num Turing.PartrecToTM2.trNum /-- Because we use binary encoding, we define `trNat` in terms of `trNum`, using `Num`, which are binary natural numbers. (We could also use `Nat.binaryRecOn`, but `Num` and `PosNum` make for easy inductions.) -/ def trNat (n : ℕ) : List Γ' := trNum n #align turing.partrec_to_TM2.tr_nat Turing.PartrecToTM2.trNat @[simp] theorem trNat_zero : trNat 0 = [] := by rw [trNat, Nat.cast_zero]; rfl #align turing.partrec_to_TM2.tr_nat_zero Turing.PartrecToTM2.trNat_zero theorem trNat_default : trNat default = [] := trNat_zero #align turing.partrec_to_TM2.tr_nat_default Turing.PartrecToTM2.trNat_default /-- Lists are translated with a `cons` after each encoded number. For example: [] = [] [0] = [cons] [1] = [bit1, cons] [6, 0] = [bit0, bit1, bit1, cons, cons] -/ @[simp] def trList : List ℕ → List Γ' | [] => [] | n::ns => trNat n ++ Γ'.cons :: trList ns #align turing.partrec_to_TM2.tr_list Turing.PartrecToTM2.trList /-- Lists of lists are translated with a `consₗ` after each encoded list. For example: [] = [] [[]] = [consₗ] [[], []] = [consₗ, consₗ] [[0]] = [cons, consₗ] [[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, consₗ, cons, consₗ] -/ @[simp] def trLList : List (List ℕ) → List Γ' | [] => [] | l::ls => trList l ++ Γ'.consₗ :: trLList ls #align turing.partrec_to_TM2.tr_llist Turing.PartrecToTM2.trLList /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ @[simp] def contStack : Cont → List (List ℕ) | Cont.halt => [] | Cont.cons₁ _ ns k => ns :: contStack k | Cont.cons₂ ns k => ns :: contStack k | Cont.comp _ k => contStack k | Cont.fix _ k => contStack k #align turing.partrec_to_TM2.cont_stack Turing.PartrecToTM2.contStack /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ def trContStack (k : Cont) := trLList (contStack k) #align turing.partrec_to_TM2.tr_cont_stack Turing.PartrecToTM2.trContStack /-- This is the nondependent eliminator for `K'`, but we use it specifically here in order to represent the stack data as four lists rather than as a function `K' → List Γ'`, because this makes rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated after an `update` to one of the components. -/ def K'.elim (a b c d : List Γ') : K' → List Γ' | K'.main => a | K'.rev => b | K'.aux => c | K'.stack => d #align turing.partrec_to_TM2.K'.elim Turing.PartrecToTM2.K'.elim -- The equation lemma of `elim` simplifies to `match` structures. theorem K'.elim_main (a b c d) : K'.elim a b c d K'.main = a := rfl theorem K'.elim_rev (a b c d) : K'.elim a b c d K'.rev = b := rfl theorem K'.elim_aux (a b c d) : K'.elim a b c d K'.aux = c := rfl theorem K'.elim_stack (a b c d) : K'.elim a b c d K'.stack = d := rfl attribute [simp] K'.elim @[simp] theorem K'.elim_update_main {a b c d a'} : update (K'.elim a b c d) main a' = K'.elim a' b c d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_main Turing.PartrecToTM2.K'.elim_update_main @[simp] theorem K'.elim_update_rev {a b c d b'} : update (K'.elim a b c d) rev b' = K'.elim a b' c d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_rev Turing.PartrecToTM2.K'.elim_update_rev @[simp] theorem K'.elim_update_aux {a b c d c'} : update (K'.elim a b c d) aux c' = K'.elim a b c' d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_aux Turing.PartrecToTM2.K'.elim_update_aux @[simp] theorem K'.elim_update_stack {a b c d d'} : update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_stack Turing.PartrecToTM2.K'.elim_update_stack /-- The halting state corresponding to a `List ℕ` output value. -/ def halt (v : List ℕ) : Cfg' := ⟨none, none, K'.elim (trList v) [] [] []⟩ #align turing.partrec_to_TM2.halt Turing.PartrecToTM2.halt /-- The `Cfg` states map to `Cfg'` states almost one to one, except that in normal operation the local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly clear it in the halt state so that there is exactly one configuration corresponding to output `v`. -/ def TrCfg : Cfg → Cfg' → Prop | Cfg.ret k v, c' => ∃ s, c' = ⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ | Cfg.halt v, c' => c' = halt v #align turing.partrec_to_TM2.tr_cfg Turing.PartrecToTM2.TrCfg /-- This could be a general list definition, but it is also somewhat specialized to this application. `splitAtPred p L` will search `L` for the first element satisfying `p`. If it is found, say `L = l₁ ++ a :: l₂` where `a` satisfies `p` but `l₁` does not, then it returns `(l₁, some a, l₂)`. Otherwise, if there is no such element, it returns `(L, none, [])`. -/ def splitAtPred {α} (p : α → Bool) : List α → List α × Option α × List α | [] => ([], none, []) | a :: as => cond (p a) ([], some a, as) <| let ⟨l₁, o, l₂⟩ := splitAtPred p as ⟨a::l₁, o, l₂⟩ #align turing.partrec_to_TM2.split_at_pred Turing.PartrecToTM2.splitAtPred theorem splitAtPred_eq {α} (p : α → Bool) : ∀ L l₁ o l₂, (∀ x ∈ l₁, p x = false) → Option.elim' (L = l₁ ∧ l₂ = []) (fun a => p a = true ∧ L = l₁ ++ a::l₂) o → splitAtPred p L = (l₁, o, l₂) | [], _, none, _, _, ⟨rfl, rfl⟩ => rfl | [], l₁, some o, l₂, _, ⟨_, h₃⟩ => by simp at h₃ | a :: L, l₁, o, l₂, h₁, h₂ => by rw [splitAtPred] have IH := splitAtPred_eq p L cases' o with o · cases' l₁ with a' l₁ <;> rcases h₂ with ⟨⟨⟩, rfl⟩ rw [h₁ a (List.Mem.head _), cond, IH L none [] _ ⟨rfl, rfl⟩] exact fun x h => h₁ x (List.Mem.tail _ h) · cases' l₁ with a' l₁ <;> rcases h₂ with ⟨h₂, ⟨⟩⟩ · rw [h₂, cond] rw [h₁ a (List.Mem.head _), cond, IH l₁ (some o) l₂ _ ⟨h₂, _⟩] <;> try rfl exact fun x h => h₁ x (List.Mem.tail _ h) #align turing.partrec_to_TM2.split_at_pred_eq Turing.PartrecToTM2.splitAtPred_eq theorem splitAtPred_false {α} (L : List α) : splitAtPred (fun _ => false) L = (L, none, []) := splitAtPred_eq _ _ _ _ _ (fun _ _ => rfl) ⟨rfl, rfl⟩ #align turing.partrec_to_TM2.split_at_pred_ff Turing.PartrecToTM2.splitAtPred_false theorem move_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ k₂) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.move p k₁ k₂ q), s, S⟩ ⟨some q, o, update (update S k₁ L₂) k₂ (L₁.reverseAux (S k₂))⟩ := by induction' L₁ with a L₁ IH generalizing S s · rw [(_ : [].reverseAux _ = _), Function.update_eq_self] swap · rw [Function.update_noteq h₁.symm, List.reverseAux_nil] refine TransGen.head' rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim, ne_eq] revert e; cases' S k₁ with a Sk <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons, Option.iget_some] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and] at e ⊢ simp only [e] rfl · refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim, ne_eq, List.reverseAux_cons] cases' e₁ : S k₁ with a' Sk <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, ne_eq, cond_false] convert @IH _ (update (update S k₁ Sk) k₂ (a :: S k₂)) _ using 2 <;> simp [Function.update_noteq, h₁, h₁.symm, e₃, List.reverseAux] simp [Function.update_comm h₁.symm] #align turing.partrec_to_TM2.move_ok Turing.PartrecToTM2.move_ok theorem unrev_ok {q s} {S : K' → List Γ'} : Reaches₁ (TM2.step tr) ⟨some (unrev q), s, S⟩ ⟨some q, none, update (update S rev []) main (List.reverseAux (S rev) (S main))⟩ := move_ok (by decide) <| splitAtPred_false _ #align turing.partrec_to_TM2.unrev_ok Turing.PartrecToTM2.unrev_ok theorem move₂_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ rev ∧ k₂ ≠ rev ∧ k₁ ≠ k₂) (h₂ : S rev = []) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (move₂ p k₁ k₂ q), s, S⟩ ⟨some q, none, update (update S k₁ (o.elim id List.cons L₂)) k₂ (L₁ ++ S k₂)⟩ := by refine (move_ok h₁.1 e).trans (TransGen.head rfl ?_) simp only [TM2.step, Option.mem_def, TM2.stepAux, id_eq, ne_eq, Option.elim] cases o <;> simp only [Option.elim, id] · simp only [TM2.stepAux, Option.isSome, cond_false] convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [Function.update_comm h₁.1, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_noteq h₁.2.2.symm, Function.update_noteq h₁.2.1, Function.update_noteq h₁.1.symm, List.reverseAux_eq, h₂, Function.update_same, List.append_nil, List.reverse_reverse] · simp only [TM2.stepAux, Option.isSome, cond_true] convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [h₂, Function.update_comm h₁.1, List.reverseAux_eq, Function.update_same, List.append_nil, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_noteq h₁.1.symm, Function.update_noteq h₁.2.2.symm, Function.update_noteq h₁.2.1, Function.update_same, List.reverse_reverse] #align turing.partrec_to_TM2.move₂_ok Turing.PartrecToTM2.move₂_ok theorem clear_ok {p k q s L₁ o L₂} {S : K' → List Γ'} (e : splitAtPred p (S k) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.clear p k q), s, S⟩ ⟨some q, o, update S k L₂⟩ := by induction' L₁ with a L₁ IH generalizing S s · refine TransGen.head' rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim] revert e; cases' S k with a Sk <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and] at e ⊢ rcases e with ⟨e₁, e₂⟩ rw [e₁, e₂] · refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim] cases' e₁ : S k with a' Sk <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, cond_false] convert @IH _ (update S k Sk) _ using 2 <;> simp [e₃] #align turing.partrec_to_TM2.clear_ok Turing.PartrecToTM2.clear_ok theorem copy_ok (q s a b c d) : Reaches₁ (TM2.step tr) ⟨some (Λ'.copy q), s, K'.elim a b c d⟩ ⟨some q, none, K'.elim (List.reverseAux b a) [] c (List.reverseAux b d)⟩ := by induction' b with x b IH generalizing a d s · refine TransGen.single ?_ simp refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_rev, List.head?_cons, Option.isSome_some, List.tail_cons, elim_update_rev, ne_eq, Function.update_noteq, elim_main, elim_update_main, elim_stack, elim_update_stack, cond_true, List.reverseAux_cons] exact IH _ _ _ #align turing.partrec_to_TM2.copy_ok Turing.PartrecToTM2.copy_ok theorem trPosNum_natEnd : ∀ (n), ∀ x ∈ trPosNum n, natEnd x = false | PosNum.one, _, List.Mem.head _ => rfl | PosNum.bit0 _, _, List.Mem.head _ => rfl | PosNum.bit0 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h | PosNum.bit1 _, _, List.Mem.head _ => rfl | PosNum.bit1 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h #align turing.partrec_to_TM2.tr_pos_num_nat_end Turing.PartrecToTM2.trPosNum_natEnd theorem trNum_natEnd : ∀ (n), ∀ x ∈ trNum n, natEnd x = false | Num.pos n, x, h => trPosNum_natEnd n x h #align turing.partrec_to_TM2.tr_num_nat_end Turing.PartrecToTM2.trNum_natEnd theorem trNat_natEnd (n) : ∀ x ∈ trNat n, natEnd x = false := trNum_natEnd _ #align turing.partrec_to_TM2.tr_nat_nat_end Turing.PartrecToTM2.trNat_natEnd theorem trList_ne_consₗ : ∀ (l), ∀ x ∈ trList l, x ≠ Γ'.consₗ | a :: l, x, h => by simp [trList] at h obtain h | rfl | h := h · rintro rfl cases trNat_natEnd _ _ h · rintro ⟨⟩ · exact trList_ne_consₗ l _ h #align turing.partrec_to_TM2.tr_list_ne_Cons Turing.PartrecToTM2.trList_ne_consₗ theorem head_main_ok {q s L} {c d : List Γ'} : Reaches₁ (TM2.step tr) ⟨some (head main q), s, K'.elim (trList L) [] c d⟩ ⟨some q, none, K'.elim (trList [L.headI]) [] c d⟩ := by let o : Option Γ' := List.casesOn L none fun _ _ => some Γ'.cons refine (move_ok (by decide) (splitAtPred_eq _ _ (trNat L.headI) o (trList L.tail) (trNat_natEnd _) ?_)).trans (TransGen.head rfl (TransGen.head rfl ?_)) · cases L <;> simp [o] simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_update_main, elim_rev, elim_update_rev, Function.update_same, trList] rw [if_neg (show o ≠ some Γ'.consₗ by cases L <;> simp [o])] refine (clear_ok (splitAtPred_eq _ _ _ none [] ?_ ⟨rfl, rfl⟩)).trans ?_ · exact fun x h => Bool.decide_false (trList_ne_consₗ _ _ h) convert unrev_ok using 2; simp [List.reverseAux_eq] #align turing.partrec_to_TM2.head_main_ok Turing.PartrecToTM2.head_main_ok theorem head_stack_ok {q s L₁ L₂ L₃} : Reaches₁ (TM2.step tr) ⟨some (head stack q), s, K'.elim (trList L₁) [] [] (trList L₂ ++ Γ'.consₗ :: L₃)⟩ ⟨some q, none, K'.elim (trList (L₂.headI :: L₁)) [] [] L₃⟩ := by cases' L₂ with a L₂ · refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ [] (some Γ'.consₗ) L₃ (by rintro _ ⟨⟩) ⟨rfl, rfl⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_true, id_eq, trList, List.nil_append, elim_update_stack, elim_rev, List.reverseAux_nil, elim_update_rev, Function.update_same, List.headI_nil, trNat_default] convert unrev_ok using 2 simp · refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ (trNat a) (some Γ'.cons) (trList L₂ ++ Γ'.consₗ :: L₃) (trNat_natEnd _) ⟨rfl, by simp⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_false, trList, List.append_assoc, List.cons_append, elim_update_stack, elim_rev, elim_update_rev, Function.update_same, List.headI_cons] refine TransGen.trans (clear_ok (splitAtPred_eq _ _ (trList L₂) (some Γ'.consₗ) L₃ (fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)) ⟨rfl, by simp⟩)) ?_ convert unrev_ok using 2 simp [List.reverseAux_eq] #align turing.partrec_to_TM2.head_stack_ok Turing.PartrecToTM2.head_stack_ok theorem succ_ok {q s n} {c d : List Γ'} : Reaches₁ (TM2.step tr) ⟨some (Λ'.succ q), s, K'.elim (trList [n]) [] c d⟩ ⟨some q, none, K'.elim (trList [n.succ]) [] c d⟩ := by simp only [TM2.step, trList, trNat.eq_1, Nat.cast_succ, Num.add_one] cases' (n : Num) with a · refine TransGen.head rfl ?_ simp only [Option.mem_def, TM2.stepAux, elim_main, decide_False, elim_update_main, ne_eq, Function.update_noteq, elim_rev, elim_update_rev, decide_True, Function.update_same, cond_true, cond_false] convert unrev_ok using 1 simp only [elim_update_rev, elim_rev, elim_main, List.reverseAux_nil, elim_update_main] rfl simp only [trNum, Num.succ, Num.succ'] suffices ∀ l₁, ∃ l₁' l₂' s', List.reverseAux l₁ (trPosNum a.succ) = List.reverseAux l₁' l₂' ∧ Reaches₁ (TM2.step tr) ⟨some q.succ, s, K'.elim (trPosNum a ++ [Γ'.cons]) l₁ c d⟩ ⟨some (unrev q), s', K'.elim (l₂' ++ [Γ'.cons]) l₁' c d⟩ by obtain ⟨l₁', l₂', s', e, h⟩ := this [] simp? [List.reverseAux] at e says simp only [List.reverseAux] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m _ generalizing s <;> intro l₁ · refine ⟨Γ'.bit0 :: l₁, [Γ'.bit1], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum] · obtain ⟨l₁', l₂', s', e, h⟩ := IH (Γ'.bit0 :: l₁) refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩ simp [PosNum.succ, trPosNum] rfl · refine ⟨l₁, _, some Γ'.bit0, rfl, TransGen.single ?_⟩ simp only [TM2.step, TM2.stepAux, elim_main, elim_update_main, ne_eq, Function.update_noteq, elim_rev, elim_update_rev, Function.update_same, Option.mem_def, Option.some.injEq] rfl #align turing.partrec_to_TM2.succ_ok Turing.PartrecToTM2.succ_ok
Mathlib/Computability/TMToPartrec.lean
1,545
1,588
theorem pred_ok (q₁ q₂ s v) (c d : List Γ') : ∃ s', Reaches₁ (TM2.step tr) ⟨some (Λ'.pred q₁ q₂), s, K'.elim (trList v) [] c d⟩ (v.headI.rec ⟨some q₁, s', K'.elim (trList v.tail) [] c d⟩ fun n _ => ⟨some q₂, s', K'.elim (trList (n::v.tail)) [] c d⟩) := by
rcases v with (_ | ⟨_ | n, v⟩) · refine ⟨none, TransGen.single ?_⟩ simp · refine ⟨some Γ'.cons, TransGen.single ?_⟩ simp refine ⟨none, ?_⟩ simp only [TM2.step, trList, trNat.eq_1, trNum, Nat.cast_succ, Num.add_one, Num.succ, List.tail_cons, List.headI_cons] cases' (n : Num) with a · simp [trPosNum, trNum, show Num.zero.succ' = PosNum.one from rfl] refine TransGen.head rfl ?_ simp only [Option.mem_def, TM2.stepAux, elim_main, List.head?_cons, Option.some.injEq, decide_False, List.tail_cons, elim_update_main, ne_eq, Function.update_noteq, elim_rev, elim_update_rev, natEnd, Function.update_same, cond_true, cond_false] convert unrev_ok using 2 simp simp only [Num.succ'] suffices ∀ l₁, ∃ l₁' l₂' s', List.reverseAux l₁ (trPosNum a) = List.reverseAux l₁' l₂' ∧ Reaches₁ (TM2.step tr) ⟨some (q₁.pred q₂), s, K'.elim (trPosNum a.succ ++ Γ'.cons :: trList v) l₁ c d⟩ ⟨some (unrev q₂), s', K'.elim (l₂' ++ Γ'.cons :: trList v) l₁' c d⟩ by obtain ⟨l₁', l₂', s', e, h⟩ := this [] simp only [List.reverseAux] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m IH generalizing s <;> intro l₁ · refine ⟨Γ'.bit1::l₁, [], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum, show PosNum.one.succ = PosNum.one.bit0 from rfl] · obtain ⟨l₁', l₂', s', e, h⟩ := IH (some Γ'.bit0) (Γ'.bit1 :: l₁) refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩ simp rfl · obtain ⟨a, l, e, h⟩ : ∃ a l, (trPosNum m = a::l) ∧ natEnd a = false := by cases m <;> refine ⟨_, _, rfl, rfl⟩ refine ⟨Γ'.bit0 :: l₁, _, some a, rfl, TransGen.single ?_⟩ simp [trPosNum, PosNum.succ, e, h, show some Γ'.bit1 ≠ some Γ'.bit0 by decide, Option.iget, -natEnd] rfl
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Algebra.Group.Int import Mathlib.Data.Int.Lemmas import Mathlib.Data.Set.Subsingleton import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Order.GaloisConnection import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity #align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c" /-! # Floor and ceil ## Summary We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. ## Main Definitions * `FloorSemiring`: An ordered semiring with natural-valued floor and ceil. * `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`. * `Nat.ceil a`: Least natural `n` such that `a ≤ n`. * `FloorRing`: A linearly ordered ring with integer-valued floor and ceil. * `Int.floor a`: Greatest integer `z` such that `z ≤ a`. * `Int.ceil a`: Least integer `z` such that `a ≤ z`. * `Int.fract a`: Fractional part of `a`, defined as `a - floor a`. * `round a`: Nearest integer to `a`. It rounds halves towards infinity. ## Notations * `⌊a⌋₊` is `Nat.floor a`. * `⌈a⌉₊` is `Nat.ceil a`. * `⌊a⌋` is `Int.floor a`. * `⌈a⌉` is `Int.ceil a`. The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation for `nnnorm`. ## TODO `LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in many lemmas. ## Tags rounding, floor, ceil -/ open Set variable {F α β : Type*} /-! ### Floor semiring -/ /-- A `FloorSemiring` is an ordered semiring over `α` with a function `floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`. Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/ class FloorSemiring (α) [OrderedSemiring α] where /-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/ floor : α → ℕ /-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/ ceil : α → ℕ /-- `FloorSemiring.floor` of a negative element is zero. -/ floor_of_neg {a : α} (ha : a < 0) : floor a = 0 /-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is smaller than `a`. -/ gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a /-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/ gc_ceil : GaloisConnection ceil (↑) #align floor_semiring FloorSemiring instance : FloorSemiring ℕ where floor := id ceil := id floor_of_neg ha := (Nat.not_lt_zero _ ha).elim gc_floor _ := by rw [Nat.cast_id] rfl gc_ceil n a := by rw [Nat.cast_id] rfl namespace Nat section OrderedSemiring variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} /-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/ def floor : α → ℕ := FloorSemiring.floor #align nat.floor Nat.floor /-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/ def ceil : α → ℕ := FloorSemiring.ceil #align nat.ceil Nat.ceil @[simp] theorem floor_nat : (Nat.floor : ℕ → ℕ) = id := rfl #align nat.floor_nat Nat.floor_nat @[simp] theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id := rfl #align nat.ceil_nat Nat.ceil_nat @[inherit_doc] notation "⌊" a "⌋₊" => Nat.floor a @[inherit_doc] notation "⌈" a "⌉₊" => Nat.ceil a end OrderedSemiring section LinearOrderedSemiring variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := FloorSemiring.gc_floor ha #align nat.le_floor_iff Nat.le_floor_iff theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ := (le_floor_iff <| n.cast_nonneg.trans h).2 h #align nat.le_floor Nat.le_floor theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff ha #align nat.floor_lt Nat.floor_lt theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 := (floor_lt ha).trans <| by rw [Nat.cast_one] #align nat.floor_lt_one Nat.floor_lt_one theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n := lt_of_not_le fun h' => (le_floor h').not_lt h #align nat.lt_of_floor_lt Nat.lt_of_floor_lt theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h #align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a := (le_floor_iff ha).1 le_rfl #align nat.floor_le Nat.floor_le theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ := lt_of_floor_lt <| Nat.lt_succ_self _ #align nat.lt_succ_floor Nat.lt_succ_floor theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a #align nat.lt_floor_add_one Nat.lt_floor_add_one @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n := eq_of_forall_le_iff fun a => by rw [le_floor_iff, Nat.cast_le] exact n.cast_nonneg #align nat.floor_coe Nat.floor_natCast @[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast] #align nat.floor_zero Nat.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast] #align nat.floor_one Nat.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n := Nat.floor_natCast _ theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 := ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by rintro rfl exact floor_zero #align nat.floor_of_nonpos Nat.floor_of_nonpos theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact le_floor ((floor_le ha).trans h) #align nat.floor_mono Nat.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact iff_of_false (Nat.pos_of_ne_zero hn).not_le (not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn) · exact le_floor_iff ha #align nat.le_floor_iff' Nat.le_floor_iff' @[simp] theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x := mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero #align nat.one_le_floor_iff Nat.one_le_floor_iff theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff' hn #align nat.floor_lt' Nat.floor_lt' theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero` rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one] #align nat.floor_pos Nat.floor_pos theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a := (le_or_lt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h #align nat.pos_of_floor_pos Nat.pos_of_floor_pos theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a := (Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le #align nat.lt_of_lt_floor Nat.lt_of_lt_floor theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n := le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h #align nat.floor_le_of_le Nat.floor_le_of_le theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 := floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm #align nat.floor_le_one_of_le_one Nat.floor_le_one_of_le_one @[simp] theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by rw [← lt_one_iff, ← @cast_one α] exact floor_lt' Nat.one_ne_zero #align nat.floor_eq_zero Nat.floor_eq_zero theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff Nat.floor_eq_iff theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff' Nat.floor_eq_iff' theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ => (floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩ #align nat.floor_eq_on_Ico Nat.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), (⌊a⌋₊ : α) = n := fun x hx => mod_cast floor_eq_on_Ico n x hx #align nat.floor_eq_on_Ico' Nat.floor_eq_on_Ico' @[simp] theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 := ext fun _ => floor_eq_zero #align nat.preimage_floor_zero Nat.preimage_floor_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(n:α)` theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (floor : α → ℕ) ⁻¹' {n} = Ico (n:α) (n + 1) := ext fun _ => floor_eq_iff' hn #align nat.preimage_floor_of_ne_zero Nat.preimage_floor_of_ne_zero /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) := FloorSemiring.gc_ceil #align nat.gc_ceil_coe Nat.gc_ceil_coe @[simp] theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n := gc_ceil_coe _ _ #align nat.ceil_le Nat.ceil_le theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align nat.lt_ceil Nat.lt_ceil -- porting note (#10618): simp can prove this -- @[simp] theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by rw [← Nat.lt_ceil, Nat.add_one_le_iff] #align nat.add_one_le_ceil_iff Nat.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero] #align nat.one_le_ceil_iff Nat.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by rw [ceil_le, Nat.cast_add, Nat.cast_one] exact (lt_floor_add_one a).le #align nat.ceil_le_floor_add_one Nat.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ := ceil_le.1 le_rfl #align nat.le_ceil Nat.le_ceil @[simp] theorem ceil_intCast {α : Type*} [LinearOrderedRing α] [FloorSemiring α] (z : ℤ) : ⌈(z : α)⌉₊ = z.toNat := eq_of_forall_ge_iff fun a => by simp only [ceil_le, Int.toNat_le] norm_cast #align nat.ceil_int_cast Nat.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le] #align nat.ceil_nat_cast Nat.ceil_natCast theorem ceil_mono : Monotone (ceil : α → ℕ) := gc_ceil_coe.monotone_l #align nat.ceil_mono Nat.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉₊ ≤ ⌈y⌉₊ := ceil_mono @[simp] theorem ceil_zero : ⌈(0 : α)⌉₊ = 0 := by rw [← Nat.cast_zero, ceil_natCast] #align nat.ceil_zero Nat.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [← Nat.cast_one, ceil_natCast] #align nat.ceil_one Nat.ceil_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈no_index (OfNat.ofNat n : α)⌉₊ = n := ceil_natCast n @[simp] theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero] #align nat.ceil_eq_zero Nat.ceil_eq_zero @[simp] theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align nat.ceil_pos Nat.ceil_pos theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n := (le_ceil a).trans_lt (Nat.cast_lt.2 h) #align nat.lt_of_ceil_lt Nat.lt_of_ceil_lt theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n := (le_ceil a).trans (Nat.cast_le.2 h) #align nat.le_of_ceil_le Nat.le_of_ceil_le theorem floor_le_ceil (a : α) : ⌊a⌋₊ ≤ ⌈a⌉₊ := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact cast_le.1 ((floor_le ha).trans <| le_ceil _) #align nat.floor_le_ceil Nat.floor_le_ceil theorem floor_lt_ceil_of_lt_of_pos {a b : α} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := by rcases le_or_lt 0 a with (ha | ha) · rw [floor_lt ha] exact h.trans_le (le_ceil _) · rwa [floor_of_nonpos ha.le, lt_ceil, Nat.cast_zero] #align nat.floor_lt_ceil_of_lt_of_pos Nat.floor_lt_ceil_of_lt_of_pos theorem ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by rw [← ceil_le, ← not_le, ← ceil_le, not_le, tsub_lt_iff_right (Nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.ceil_eq_iff Nat.ceil_eq_iff @[simp] theorem preimage_ceil_zero : (Nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 := ext fun _ => ceil_eq_zero #align nat.preimage_ceil_zero Nat.preimage_ceil_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(↑(n - 1))` theorem preimage_ceil_of_ne_zero (hn : n ≠ 0) : (Nat.ceil : α → ℕ) ⁻¹' {n} = Ioc (↑(n - 1) : α) n := ext fun _ => ceil_eq_iff hn #align nat.preimage_ceil_of_ne_zero Nat.preimage_ceil_of_ne_zero /-! #### Intervals -/ -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioo {a b : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by ext simp [floor_lt, lt_ceil, ha] #align nat.preimage_Ioo Nat.preimage_Ioo -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ico {a b : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉₊ ⌈b⌉₊ := by ext simp [ceil_le, lt_ceil] #align nat.preimage_Ico Nat.preimage_Ico -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioc {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by ext simp [floor_lt, le_floor_iff, hb, ha] #align nat.preimage_Ioc Nat.preimage_Ioc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Icc {a b : α} (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉₊ ⌊b⌋₊ := by ext simp [ceil_le, hb, le_floor_iff] #align nat.preimage_Icc Nat.preimage_Icc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioi {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋₊ := by ext simp [floor_lt, ha] #align nat.preimage_Ioi Nat.preimage_Ioi -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ici {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉₊ := by ext simp [ceil_le] #align nat.preimage_Ici Nat.preimage_Ici -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iio {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉₊ := by ext simp [lt_ceil] #align nat.preimage_Iio Nat.preimage_Iio -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iic {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋₊ := by ext simp [le_floor_iff, ha] #align nat.preimage_Iic Nat.preimage_Iic theorem floor_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n := eq_of_forall_le_iff fun b => by rw [le_floor_iff (add_nonneg ha n.cast_nonneg)] obtain hb | hb := le_total n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_le_add_iff_right, add_le_add_iff_right, le_floor_iff ha] · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_left_comm _ b, add_left_comm _ (b : α)] refine iff_of_true ?_ le_self_add exact le_add_of_nonneg_right <| ha.trans <| le_add_of_nonneg_right d.cast_nonneg #align nat.floor_add_nat Nat.floor_add_nat theorem floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by -- Porting note: broken `convert floor_add_nat ha 1` rw [← cast_one, floor_add_nat ha 1] #align nat.floor_add_one Nat.floor_add_one -- See note [no_index around OfNat.ofNat] theorem floor_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ + OfNat.ofNat n := floor_add_nat ha n @[simp] theorem floor_sub_nat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) : ⌊a - n⌋₊ = ⌊a⌋₊ - n := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub] rcases le_total a n with h | h · rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le] exact Nat.cast_le.1 ((Nat.floor_le ha).trans h) · rw [eq_tsub_iff_add_eq_of_le (le_floor h), ← floor_add_nat _, tsub_add_cancel_of_le h] exact le_tsub_of_add_le_left ((add_zero _).trans_le h) #align nat.floor_sub_nat Nat.floor_sub_nat @[simp] theorem floor_sub_one [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) : ⌊a - 1⌋₊ = ⌊a⌋₊ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ - OfNat.ofNat n := floor_sub_nat a n theorem ceil_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n := eq_of_forall_ge_iff fun b => by rw [← not_lt, ← not_lt, not_iff_not, lt_ceil] obtain hb | hb := le_or_lt n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_lt_add_iff_right, add_lt_add_iff_right, lt_ceil] · exact iff_of_true (lt_add_of_nonneg_of_lt ha <| cast_lt.2 hb) (Nat.lt_add_left _ hb) #align nat.ceil_add_nat Nat.ceil_add_nat theorem ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by -- Porting note: broken `convert ceil_add_nat ha 1` rw [cast_one.symm, ceil_add_nat ha 1] #align nat.ceil_add_one Nat.ceil_add_one -- See note [no_index around OfNat.ofNat] theorem ceil_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉₊ = ⌈a⌉₊ + OfNat.ofNat n := ceil_add_nat ha n theorem ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : α) < a + 1 := lt_ceil.1 <| (Nat.lt_succ_self _).trans_le (ceil_add_one ha).ge #align nat.ceil_lt_add_one Nat.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := by rw [ceil_le, Nat.cast_add] exact _root_.add_le_add (le_ceil _) (le_ceil _) #align nat.ceil_add_le Nat.ceil_add_le end LinearOrderedSemiring section LinearOrderedRing variable [LinearOrderedRing α] [FloorSemiring α] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋₊ := sub_lt_iff_lt_add.2 <| lt_floor_add_one a #align nat.sub_one_lt_floor Nat.sub_one_lt_floor end LinearOrderedRing section LinearOrderedSemifield variable [LinearOrderedSemifield α] [FloorSemiring α] -- TODO: should these lemmas be `simp`? `norm_cast`? theorem floor_div_nat (a : α) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := by rcases le_total a 0 with ha | ha · rw [floor_of_nonpos, floor_of_nonpos ha] · simp apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg obtain rfl | hn := n.eq_zero_or_pos · rw [cast_zero, div_zero, Nat.div_zero, floor_zero] refine (floor_eq_iff ?_).2 ?_ · exact div_nonneg ha n.cast_nonneg constructor · exact cast_div_le.trans (div_le_div_of_nonneg_right (floor_le ha) n.cast_nonneg) rw [div_lt_iff, add_mul, one_mul, ← cast_mul, ← cast_add, ← floor_lt ha] · exact lt_div_mul_add hn · exact cast_pos.2 hn #align nat.floor_div_nat Nat.floor_div_nat -- See note [no_index around OfNat.ofNat] theorem floor_div_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a / (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ / OfNat.ofNat n := floor_div_nat a n /-- Natural division is the floor of field division. -/ theorem floor_div_eq_div (m n : ℕ) : ⌊(m : α) / n⌋₊ = m / n := by convert floor_div_nat (m : α) n rw [m.floor_natCast] #align nat.floor_div_eq_div Nat.floor_div_eq_div end LinearOrderedSemifield end Nat /-- There exists at most one `FloorSemiring` structure on a linear ordered semiring. -/ theorem subsingleton_floorSemiring {α} [LinearOrderedSemiring α] : Subsingleton (FloorSemiring α) := by refine ⟨fun H₁ H₂ => ?_⟩ have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil.l_unique H₂.gc_ceil) fun n => rfl have : H₁.floor = H₂.floor := by ext a cases' lt_or_le a 0 with h h · rw [H₁.floor_of_neg, H₂.floor_of_neg] <;> exact h · refine eq_of_forall_le_iff fun n => ?_ rw [H₁.gc_floor, H₂.gc_floor] <;> exact h cases H₁ cases H₂ congr #align subsingleton_floor_semiring subsingleton_floorSemiring /-! ### Floor rings -/ /-- A `FloorRing` is a linear ordered ring over `α` with a function `floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`. -/ class FloorRing (α) [LinearOrderedRing α] where /-- `FloorRing.floor a` computes the greatest integer `z` such that `(z : α) ≤ a`. -/ floor : α → ℤ /-- `FloorRing.ceil a` computes the least integer `z` such that `a ≤ (z : α)`. -/ ceil : α → ℤ /-- `FloorRing.ceil` is the upper adjoint of the coercion `↑ : ℤ → α`. -/ gc_coe_floor : GaloisConnection (↑) floor /-- `FloorRing.ceil` is the lower adjoint of the coercion `↑ : ℤ → α`. -/ gc_ceil_coe : GaloisConnection ceil (↑) #align floor_ring FloorRing instance : FloorRing ℤ where floor := id ceil := id gc_coe_floor a b := by rw [Int.cast_id] rfl gc_ceil_coe a b := by rw [Int.cast_id] rfl /-- A `FloorRing` constructor from the `floor` function alone. -/ def FloorRing.ofFloor (α) [LinearOrderedRing α] (floor : α → ℤ) (gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α := { floor ceil := fun a => -floor (-a) gc_coe_floor gc_ceil_coe := fun a z => by rw [neg_le, ← gc_coe_floor, Int.cast_neg, neg_le_neg_iff] } #align floor_ring.of_floor FloorRing.ofFloor /-- A `FloorRing` constructor from the `ceil` function alone. -/ def FloorRing.ofCeil (α) [LinearOrderedRing α] (ceil : α → ℤ) (gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α := { floor := fun a => -ceil (-a) ceil gc_coe_floor := fun a z => by rw [le_neg, gc_ceil_coe, Int.cast_neg, neg_le_neg_iff] gc_ceil_coe } #align floor_ring.of_ceil FloorRing.ofCeil namespace Int variable [LinearOrderedRing α] [FloorRing α] {z : ℤ} {a : α} /-- `Int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/ def floor : α → ℤ := FloorRing.floor #align int.floor Int.floor /-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/ def ceil : α → ℤ := FloorRing.ceil #align int.ceil Int.ceil /-- `Int.fract a`, the fractional part of `a`, is `a` minus its floor. -/ def fract (a : α) : α := a - floor a #align int.fract Int.fract @[simp] theorem floor_int : (Int.floor : ℤ → ℤ) = id := rfl #align int.floor_int Int.floor_int @[simp] theorem ceil_int : (Int.ceil : ℤ → ℤ) = id := rfl #align int.ceil_int Int.ceil_int @[simp] theorem fract_int : (Int.fract : ℤ → ℤ) = 0 := funext fun x => by simp [fract] #align int.fract_int Int.fract_int @[inherit_doc] notation "⌊" a "⌋" => Int.floor a @[inherit_doc] notation "⌈" a "⌉" => Int.ceil a -- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there. @[simp] theorem floorRing_floor_eq : @FloorRing.floor = @Int.floor := rfl #align int.floor_ring_floor_eq Int.floorRing_floor_eq @[simp] theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil := rfl #align int.floor_ring_ceil_eq Int.floorRing_ceil_eq /-! #### Floor -/ theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor := FloorRing.gc_coe_floor #align int.gc_coe_floor Int.gc_coe_floor theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a := (gc_coe_floor z a).symm #align int.le_floor Int.le_floor theorem floor_lt : ⌊a⌋ < z ↔ a < z := lt_iff_lt_of_le_iff_le le_floor #align int.floor_lt Int.floor_lt theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a := gc_coe_floor.l_u_le a #align int.floor_le Int.floor_le theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero] #align int.floor_nonneg Int.floor_nonneg @[simp] theorem floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, le_sub_one_iff] #align int.floor_le_sub_one_iff Int.floor_le_sub_one_iff @[simp] theorem floor_le_neg_one_iff : ⌊a⌋ ≤ -1 ↔ a < 0 := by rw [← zero_sub (1 : ℤ), floor_le_sub_one_iff, cast_zero] #align int.floor_le_neg_one_iff Int.floor_le_neg_one_iff theorem floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by rw [← @cast_le α, Int.cast_zero] exact (floor_le a).trans ha #align int.floor_nonpos Int.floor_nonpos theorem lt_succ_floor (a : α) : a < ⌊a⌋.succ := floor_lt.1 <| Int.lt_succ_self _ #align int.lt_succ_floor Int.lt_succ_floor @[simp] theorem lt_floor_add_one (a : α) : a < ⌊a⌋ + 1 := by simpa only [Int.succ, Int.cast_add, Int.cast_one] using lt_succ_floor a #align int.lt_floor_add_one Int.lt_floor_add_one @[simp] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ := sub_lt_iff_lt_add.2 (lt_floor_add_one a) #align int.sub_one_lt_floor Int.sub_one_lt_floor @[simp] theorem floor_intCast (z : ℤ) : ⌊(z : α)⌋ = z := eq_of_forall_le_iff fun a => by rw [le_floor, Int.cast_le] #align int.floor_int_cast Int.floor_intCast @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋ = n := eq_of_forall_le_iff fun a => by rw [le_floor, ← cast_natCast, cast_le] #align int.floor_nat_cast Int.floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_intCast] #align int.floor_zero Int.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_intCast] #align int.floor_one Int.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊(no_index (OfNat.ofNat n : α))⌋ = n := floor_natCast n @[mono] theorem floor_mono : Monotone (floor : α → ℤ) := gc_coe_floor.monotone_u #align int.floor_mono Int.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋ ≤ ⌊y⌋ := floor_mono theorem floor_pos : 0 < ⌊a⌋ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor` rw [Int.lt_iff_add_one_le, zero_add, le_floor, cast_one] #align int.floor_pos Int.floor_pos @[simp] theorem floor_add_int (a : α) (z : ℤ) : ⌊a + z⌋ = ⌊a⌋ + z := eq_of_forall_le_iff fun a => by rw [le_floor, ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, Int.cast_sub] #align int.floor_add_int Int.floor_add_int @[simp] theorem floor_add_one (a : α) : ⌊a + 1⌋ = ⌊a⌋ + 1 := by -- Porting note: broken `convert floor_add_int a 1` rw [← cast_one, floor_add_int] #align int.floor_add_one Int.floor_add_one theorem le_floor_add (a b : α) : ⌊a⌋ + ⌊b⌋ ≤ ⌊a + b⌋ := by rw [le_floor, Int.cast_add] exact add_le_add (floor_le _) (floor_le _) #align int.le_floor_add Int.le_floor_add theorem le_floor_add_floor (a b : α) : ⌊a + b⌋ - 1 ≤ ⌊a⌋ + ⌊b⌋ := by rw [← sub_le_iff_le_add, le_floor, Int.cast_sub, sub_le_comm, Int.cast_sub, Int.cast_one] refine le_trans ?_ (sub_one_lt_floor _).le rw [sub_le_iff_le_add', ← add_sub_assoc, sub_le_sub_iff_right] exact floor_le _ #align int.le_floor_add_floor Int.le_floor_add_floor @[simp] theorem floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by simpa only [add_comm] using floor_add_int a z #align int.floor_int_add Int.floor_int_add @[simp] theorem floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by rw [← Int.cast_natCast, floor_add_int] #align int.floor_add_nat Int.floor_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ + OfNat.ofNat n := floor_add_nat a n @[simp] theorem floor_nat_add (n : ℕ) (a : α) : ⌊↑n + a⌋ = n + ⌊a⌋ := by rw [← Int.cast_natCast, floor_int_add] #align int.floor_nat_add Int.floor_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : ⌊(no_index (OfNat.ofNat n)) + a⌋ = OfNat.ofNat n + ⌊a⌋ := floor_nat_add n a @[simp] theorem floor_sub_int (a : α) (z : ℤ) : ⌊a - z⌋ = ⌊a⌋ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _) #align int.floor_sub_int Int.floor_sub_int @[simp] theorem floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by rw [← Int.cast_natCast, floor_sub_int] #align int.floor_sub_nat Int.floor_sub_nat @[simp] theorem floor_sub_one (a : α) : ⌊a - 1⌋ = ⌊a⌋ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ - OfNat.ofNat n := floor_sub_nat a n theorem abs_sub_lt_one_of_floor_eq_floor {α : Type*} [LinearOrderedCommRing α] [FloorRing α] {a b : α} (h : ⌊a⌋ = ⌊b⌋) : |a - b| < 1 := by have : a < ⌊a⌋ + 1 := lt_floor_add_one a have : b < ⌊b⌋ + 1 := lt_floor_add_one b have : (⌊a⌋ : α) = ⌊b⌋ := Int.cast_inj.2 h have : (⌊a⌋ : α) ≤ a := floor_le a have : (⌊b⌋ : α) ≤ b := floor_le b exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩ #align int.abs_sub_lt_one_of_floor_eq_floor Int.abs_sub_lt_one_of_floor_eq_floor theorem floor_eq_iff : ⌊a⌋ = z ↔ ↑z ≤ a ∧ a < z + 1 := by rw [le_antisymm_iff, le_floor, ← Int.lt_add_one_iff, floor_lt, Int.cast_add, Int.cast_one, and_comm] #align int.floor_eq_iff Int.floor_eq_iff @[simp] theorem floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff] #align int.floor_eq_zero_iff Int.floor_eq_zero_iff theorem floor_eq_on_Ico (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), ⌊a⌋ = n := fun _ ⟨h₀, h₁⟩ => floor_eq_iff.mpr ⟨h₀, h₁⟩ #align int.floor_eq_on_Ico Int.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), (⌊a⌋ : α) = n := fun a ha => congr_arg _ <| floor_eq_on_Ico n a ha #align int.floor_eq_on_Ico' Int.floor_eq_on_Ico' -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` @[simp] theorem preimage_floor_singleton (m : ℤ) : (floor : α → ℤ) ⁻¹' {m} = Ico (m : α) (m + 1) := ext fun _ => floor_eq_iff #align int.preimage_floor_singleton Int.preimage_floor_singleton /-! #### Fractional part -/ @[simp] theorem self_sub_floor (a : α) : a - ⌊a⌋ = fract a := rfl #align int.self_sub_floor Int.self_sub_floor @[simp] theorem floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a := add_sub_cancel _ _ #align int.floor_add_fract Int.floor_add_fract @[simp] theorem fract_add_floor (a : α) : fract a + ⌊a⌋ = a := sub_add_cancel _ _ #align int.fract_add_floor Int.fract_add_floor @[simp] theorem fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_int Int.fract_add_int @[simp] theorem fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_nat Int.fract_add_nat @[simp] theorem fract_add_one (a : α) : fract (a + 1) = fract a := mod_cast fract_add_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a + (no_index (OfNat.ofNat n))) = fract a := fract_add_nat a n @[simp] theorem fract_int_add (m : ℤ) (a : α) : fract (↑m + a) = fract a := by rw [add_comm, fract_add_int] #align int.fract_int_add Int.fract_int_add @[simp] theorem fract_nat_add (n : ℕ) (a : α) : fract (↑n + a) = fract a := by rw [add_comm, fract_add_nat] @[simp] theorem fract_one_add (a : α) : fract (1 + a) = fract a := mod_cast fract_nat_add 1 a -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : fract ((no_index (OfNat.ofNat n)) + a) = fract a := fract_nat_add n a @[simp] theorem fract_sub_int (a : α) (m : ℤ) : fract (a - m) = fract a := by rw [fract] simp #align int.fract_sub_int Int.fract_sub_int @[simp] theorem fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by rw [fract] simp #align int.fract_sub_nat Int.fract_sub_nat @[simp] theorem fract_sub_one (a : α) : fract (a - 1) = fract a := mod_cast fract_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a - (no_index (OfNat.ofNat n))) = fract a := fract_sub_nat a n -- Was a duplicate lemma under a bad name #align int.fract_int_nat Int.fract_int_add theorem fract_add_le (a b : α) : fract (a + b) ≤ fract a + fract b := by rw [fract, fract, fract, sub_add_sub_comm, sub_le_sub_iff_left, ← Int.cast_add, Int.cast_le] exact le_floor_add _ _ #align int.fract_add_le Int.fract_add_le theorem fract_add_fract_le (a b : α) : fract a + fract b ≤ fract (a + b) + 1 := by rw [fract, fract, fract, sub_add_sub_comm, sub_add, sub_le_sub_iff_left] exact mod_cast le_floor_add_floor a b #align int.fract_add_fract_le Int.fract_add_fract_le @[simp] theorem self_sub_fract (a : α) : a - fract a = ⌊a⌋ := sub_sub_cancel _ _ #align int.self_sub_fract Int.self_sub_fract @[simp] theorem fract_sub_self (a : α) : fract a - a = -⌊a⌋ := sub_sub_cancel_left _ _ #align int.fract_sub_self Int.fract_sub_self @[simp] theorem fract_nonneg (a : α) : 0 ≤ fract a := sub_nonneg.2 <| floor_le _ #align int.fract_nonneg Int.fract_nonneg /-- The fractional part of `a` is positive if and only if `a ≠ ⌊a⌋`. -/ lemma fract_pos : 0 < fract a ↔ a ≠ ⌊a⌋ := (fract_nonneg a).lt_iff_ne.trans <| ne_comm.trans sub_ne_zero #align int.fract_pos Int.fract_pos theorem fract_lt_one (a : α) : fract a < 1 := sub_lt_comm.1 <| sub_one_lt_floor _ #align int.fract_lt_one Int.fract_lt_one @[simp] theorem fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self] #align int.fract_zero Int.fract_zero @[simp] theorem fract_one : fract (1 : α) = 0 := by simp [fract] #align int.fract_one Int.fract_one theorem abs_fract : |fract a| = fract a := abs_eq_self.mpr <| fract_nonneg a #align int.abs_fract Int.abs_fract @[simp] theorem abs_one_sub_fract : |1 - fract a| = 1 - fract a := abs_eq_self.mpr <| sub_nonneg.mpr (fract_lt_one a).le #align int.abs_one_sub_fract Int.abs_one_sub_fract @[simp] theorem fract_intCast (z : ℤ) : fract (z : α) = 0 := by unfold fract rw [floor_intCast] exact sub_self _ #align int.fract_int_cast Int.fract_intCast @[simp] theorem fract_natCast (n : ℕ) : fract (n : α) = 0 := by simp [fract] #align int.fract_nat_cast Int.fract_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat (n : ℕ) [n.AtLeastTwo] : fract ((no_index (OfNat.ofNat n)) : α) = 0 := fract_natCast n -- porting note (#10618): simp can prove this -- @[simp] theorem fract_floor (a : α) : fract (⌊a⌋ : α) = 0 := fract_intCast _ #align int.fract_floor Int.fract_floor @[simp] theorem floor_fract (a : α) : ⌊fract a⌋ = 0 := by rw [floor_eq_iff, Int.cast_zero, zero_add]; exact ⟨fract_nonneg _, fract_lt_one _⟩ #align int.floor_fract Int.floor_fract theorem fract_eq_iff {a b : α} : fract a = b ↔ 0 ≤ b ∧ b < 1 ∧ ∃ z : ℤ, a - b = z := ⟨fun h => by rw [← h] exact ⟨fract_nonneg _, fract_lt_one _, ⟨⌊a⌋, sub_sub_cancel _ _⟩⟩, by rintro ⟨h₀, h₁, z, hz⟩ rw [← self_sub_floor, eq_comm, eq_sub_iff_add_eq, add_comm, ← eq_sub_iff_add_eq, hz, Int.cast_inj, floor_eq_iff, ← hz] constructor <;> simpa [sub_eq_add_neg, add_assoc] ⟩ #align int.fract_eq_iff Int.fract_eq_iff theorem fract_eq_fract {a b : α} : fract a = fract b ↔ ∃ z : ℤ, a - b = z := ⟨fun h => ⟨⌊a⌋ - ⌊b⌋, by unfold fract at h; rw [Int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h]⟩, by rintro ⟨z, hz⟩ refine fract_eq_iff.2 ⟨fract_nonneg _, fract_lt_one _, z + ⌊b⌋, ?_⟩ rw [eq_add_of_sub_eq hz, add_comm, Int.cast_add] exact add_sub_sub_cancel _ _ _⟩ #align int.fract_eq_fract Int.fract_eq_fract @[simp] theorem fract_eq_self {a : α} : fract a = a ↔ 0 ≤ a ∧ a < 1 := fract_eq_iff.trans <| and_assoc.symm.trans <| and_iff_left ⟨0, by simp⟩ #align int.fract_eq_self Int.fract_eq_self @[simp] theorem fract_fract (a : α) : fract (fract a) = fract a := fract_eq_self.2 ⟨fract_nonneg _, fract_lt_one _⟩ #align int.fract_fract Int.fract_fract theorem fract_add (a b : α) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z := ⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by unfold fract simp only [sub_eq_add_neg, neg_add_rev, neg_neg, cast_add, cast_neg] abel⟩ #align int.fract_add Int.fract_add theorem fract_neg {x : α} (hx : fract x ≠ 0) : fract (-x) = 1 - fract x := by rw [fract_eq_iff] constructor · rw [le_sub_iff_add_le, zero_add] exact (fract_lt_one x).le refine ⟨sub_lt_self _ (lt_of_le_of_ne' (fract_nonneg x) hx), -⌊x⌋ - 1, ?_⟩ simp only [sub_sub_eq_add_sub, cast_sub, cast_neg, cast_one, sub_left_inj] conv in -x => rw [← floor_add_fract x] simp [-floor_add_fract] #align int.fract_neg Int.fract_neg @[simp] theorem fract_neg_eq_zero {x : α} : fract (-x) = 0 ↔ fract x = 0 := by simp only [fract_eq_iff, le_refl, zero_lt_one, tsub_zero, true_and_iff] constructor <;> rintro ⟨z, hz⟩ <;> use -z <;> simp [← hz] #align int.fract_neg_eq_zero Int.fract_neg_eq_zero theorem fract_mul_nat (a : α) (b : ℕ) : ∃ z : ℤ, fract a * b - fract (a * b) = z := by induction' b with c hc · use 0; simp · rcases hc with ⟨z, hz⟩ rw [Nat.cast_add, mul_add, mul_add, Nat.cast_one, mul_one, mul_one] rcases fract_add (a * c) a with ⟨y, hy⟩ use z - y rw [Int.cast_sub, ← hz, ← hy] abel #align int.fract_mul_nat Int.fract_mul_nat -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` theorem preimage_fract (s : Set α) : fract ⁻¹' s = ⋃ m : ℤ, (fun x => x - (m:α)) ⁻¹' (s ∩ Ico (0 : α) 1) := by ext x simp only [mem_preimage, mem_iUnion, mem_inter_iff] refine ⟨fun h => ⟨⌊x⌋, h, fract_nonneg x, fract_lt_one x⟩, ?_⟩ rintro ⟨m, hms, hm0, hm1⟩ obtain rfl : ⌊x⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 hm0, sub_lt_iff_lt_add'.1 hm1⟩ exact hms #align int.preimage_fract Int.preimage_fract theorem image_fract (s : Set α) : fract '' s = ⋃ m : ℤ, (fun x : α => x - m) '' s ∩ Ico 0 1 := by ext x simp only [mem_image, mem_inter_iff, mem_iUnion]; constructor · rintro ⟨y, hy, rfl⟩ exact ⟨⌊y⌋, ⟨y, hy, rfl⟩, fract_nonneg y, fract_lt_one y⟩ · rintro ⟨m, ⟨y, hys, rfl⟩, h0, h1⟩ obtain rfl : ⌊y⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 h0, sub_lt_iff_lt_add'.1 h1⟩ exact ⟨y, hys, rfl⟩ #align int.image_fract Int.image_fract section LinearOrderedField variable {k : Type*} [LinearOrderedField k] [FloorRing k] {b : k} theorem fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b / a) * a ∈ Ico 0 a := ⟨(mul_nonneg_iff_of_pos_right ha).2 (fract_nonneg (b / a)), (mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b / a))⟩ #align int.fract_div_mul_self_mem_Ico Int.fract_div_mul_self_mem_Ico theorem fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a ≠ 0) : fract (b / a) * a + ⌊b / a⌋ • a = b := by rw [zsmul_eq_mul, ← add_mul, fract_add_floor, div_mul_cancel₀ b ha] #align int.fract_div_mul_self_add_zsmul_eq Int.fract_div_mul_self_add_zsmul_eq theorem sub_floor_div_mul_nonneg (a : k) (hb : 0 < b) : 0 ≤ a - ⌊a / b⌋ * b := sub_nonneg_of_le <| (le_div_iff hb).1 <| floor_le _ #align int.sub_floor_div_mul_nonneg Int.sub_floor_div_mul_nonneg theorem sub_floor_div_mul_lt (a : k) (hb : 0 < b) : a - ⌊a / b⌋ * b < b := sub_lt_iff_lt_add.2 <| by -- Porting note: `← one_add_mul` worked in mathlib3 without the argument rw [← one_add_mul _ b, ← div_lt_iff hb, add_comm] exact lt_floor_add_one _ #align int.sub_floor_div_mul_lt Int.sub_floor_div_mul_lt theorem fract_div_natCast_eq_div_natCast_mod {m n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp have hn' : 0 < (n : k) := by norm_cast refine fract_eq_iff.mpr ⟨?_, ?_, m / n, ?_⟩ · positivity · simpa only [div_lt_one hn', Nat.cast_lt] using m.mod_lt hn · rw [sub_eq_iff_eq_add', ← mul_right_inj' hn'.ne', mul_div_cancel₀ _ hn'.ne', mul_add, mul_div_cancel₀ _ hn'.ne'] norm_cast rw [← Nat.cast_add, Nat.mod_add_div m n] #align int.fract_div_nat_cast_eq_div_nat_cast_mod Int.fract_div_natCast_eq_div_natCast_mod -- TODO Generalise this to allow `n : ℤ` using `Int.fmod` instead of `Int.mod`. theorem fract_div_intCast_eq_div_intCast_mod {m : ℤ} {n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp replace hn : 0 < (n : k) := by norm_cast have : ∀ {l : ℤ}, 0 ≤ l → fract ((l : k) / n) = ↑(l % n) / n := by intros l hl obtain ⟨l₀, rfl | rfl⟩ := l.eq_nat_or_neg · rw [cast_natCast, ← natCast_mod, cast_natCast, fract_div_natCast_eq_div_natCast_mod] · rw [Right.nonneg_neg_iff, natCast_nonpos_iff] at hl simp [hl, zero_mod] obtain ⟨m₀, rfl | rfl⟩ := m.eq_nat_or_neg · exact this (ofNat_nonneg m₀) let q := ⌈↑m₀ / (n : k)⌉ let m₁ := q * ↑n - (↑m₀ : ℤ) have hm₁ : 0 ≤ m₁ := by simpa [m₁, ← @cast_le k, ← div_le_iff hn] using FloorRing.gc_ceil_coe.le_u_l _ calc fract ((Int.cast (-(m₀ : ℤ)) : k) / (n : k)) -- Porting note: the `rw [cast_neg, cast_natCast]` was `push_cast` = fract (-(m₀ : k) / n) := by rw [cast_neg, cast_natCast] _ = fract ((m₁ : k) / n) := ?_ _ = Int.cast (m₁ % (n : ℤ)) / Nat.cast n := this hm₁ _ = Int.cast (-(↑m₀ : ℤ) % ↑n) / Nat.cast n := ?_ · rw [← fract_int_add q, ← mul_div_cancel_right₀ (q : k) hn.ne', ← add_div, ← sub_eq_add_neg] -- Porting note: the `simp` was `push_cast` simp [m₁] · congr 2 change (q * ↑n - (↑m₀ : ℤ)) % ↑n = _ rw [sub_eq_add_neg, add_comm (q * ↑n), add_mul_emod_self] #align int.fract_div_int_cast_eq_div_int_cast_mod Int.fract_div_intCast_eq_div_intCast_mod end LinearOrderedField /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection ceil ((↑) : ℤ → α) := FloorRing.gc_ceil_coe #align int.gc_ceil_coe Int.gc_ceil_coe theorem ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z := gc_ceil_coe a z #align int.ceil_le Int.ceil_le theorem floor_neg : ⌊-a⌋ = -⌈a⌉ := eq_of_forall_le_iff fun z => by rw [le_neg, ceil_le, le_floor, Int.cast_neg, le_neg] #align int.floor_neg Int.floor_neg theorem ceil_neg : ⌈-a⌉ = -⌊a⌋ := eq_of_forall_ge_iff fun z => by rw [neg_le, ceil_le, le_floor, Int.cast_neg, neg_le] #align int.ceil_neg Int.ceil_neg theorem lt_ceil : z < ⌈a⌉ ↔ (z : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align int.lt_ceil Int.lt_ceil @[simp] theorem add_one_le_ceil_iff : z + 1 ≤ ⌈a⌉ ↔ (z : α) < a := by rw [← lt_ceil, add_one_le_iff] #align int.add_one_le_ceil_iff Int.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉ ↔ 0 < a := by rw [← zero_add (1 : ℤ), add_one_le_ceil_iff, cast_zero] #align int.one_le_ceil_iff Int.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉ ≤ ⌊a⌋ + 1 := by rw [ceil_le, Int.cast_add, Int.cast_one] exact (lt_floor_add_one a).le #align int.ceil_le_floor_add_one Int.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉ := gc_ceil_coe.le_u_l a #align int.le_ceil Int.le_ceil @[simp] theorem ceil_intCast (z : ℤ) : ⌈(z : α)⌉ = z := eq_of_forall_ge_iff fun a => by rw [ceil_le, Int.cast_le] #align int.ceil_int_cast Int.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, ← cast_natCast, cast_le] #align int.ceil_nat_cast Int.ceil_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈(no_index (OfNat.ofNat n : α))⌉ = n := ceil_natCast n theorem ceil_mono : Monotone (ceil : α → ℤ) := gc_ceil_coe.monotone_l #align int.ceil_mono Int.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉ ≤ ⌈y⌉ := ceil_mono @[simp] theorem ceil_add_int (a : α) (z : ℤ) : ⌈a + z⌉ = ⌈a⌉ + z := by rw [← neg_inj, neg_add', ← floor_neg, ← floor_neg, neg_add', floor_sub_int] #align int.ceil_add_int Int.ceil_add_int @[simp] theorem ceil_add_nat (a : α) (n : ℕ) : ⌈a + n⌉ = ⌈a⌉ + n := by rw [← Int.cast_natCast, ceil_add_int] #align int.ceil_add_nat Int.ceil_add_nat @[simp] theorem ceil_add_one (a : α) : ⌈a + 1⌉ = ⌈a⌉ + 1 := by -- Porting note: broken `convert ceil_add_int a (1 : ℤ)` rw [← ceil_add_int a (1 : ℤ), cast_one] #align int.ceil_add_one Int.ceil_add_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ + OfNat.ofNat n := ceil_add_nat a n @[simp] theorem ceil_sub_int (a : α) (z : ℤ) : ⌈a - z⌉ = ⌈a⌉ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (ceil_add_int _ _) #align int.ceil_sub_int Int.ceil_sub_int @[simp] theorem ceil_sub_nat (a : α) (n : ℕ) : ⌈a - n⌉ = ⌈a⌉ - n := by convert ceil_sub_int a n using 1 simp #align int.ceil_sub_nat Int.ceil_sub_nat @[simp] theorem ceil_sub_one (a : α) : ⌈a - 1⌉ = ⌈a⌉ - 1 := by rw [eq_sub_iff_add_eq, ← ceil_add_one, sub_add_cancel] #align int.ceil_sub_one Int.ceil_sub_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌈a - (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ - OfNat.ofNat n := ceil_sub_nat a n theorem ceil_lt_add_one (a : α) : (⌈a⌉ : α) < a + 1 := by rw [← lt_ceil, ← Int.cast_one, ceil_add_int] apply lt_add_one #align int.ceil_lt_add_one Int.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉ ≤ ⌈a⌉ + ⌈b⌉ := by rw [ceil_le, Int.cast_add] exact add_le_add (le_ceil _) (le_ceil _) #align int.ceil_add_le Int.ceil_add_le theorem ceil_add_ceil_le (a b : α) : ⌈a⌉ + ⌈b⌉ ≤ ⌈a + b⌉ + 1 := by rw [← le_sub_iff_add_le, ceil_le, Int.cast_sub, Int.cast_add, Int.cast_one, le_sub_comm] refine (ceil_lt_add_one _).le.trans ?_ rw [le_sub_iff_add_le', ← add_assoc, add_le_add_iff_right] exact le_ceil _ #align int.ceil_add_ceil_le Int.ceil_add_ceil_le @[simp] theorem ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align int.ceil_pos Int.ceil_pos @[simp] theorem ceil_zero : ⌈(0 : α)⌉ = 0 := by rw [← cast_zero, ceil_intCast] #align int.ceil_zero Int.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉ = 1 := by rw [← cast_one, ceil_intCast] #align int.ceil_one Int.ceil_one theorem ceil_nonneg (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a) #align int.ceil_nonneg Int.ceil_nonneg theorem ceil_eq_iff : ⌈a⌉ = z ↔ ↑z - 1 < a ∧ a ≤ z := by rw [← ceil_le, ← Int.cast_one, ← Int.cast_sub, ← lt_ceil, Int.sub_one_lt_iff, le_antisymm_iff, and_comm] #align int.ceil_eq_iff Int.ceil_eq_iff @[simp] theorem ceil_eq_zero_iff : ⌈a⌉ = 0 ↔ a ∈ Ioc (-1 : α) 0 := by simp [ceil_eq_iff] #align int.ceil_eq_zero_iff Int.ceil_eq_zero_iff theorem ceil_eq_on_Ioc (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, ⌈a⌉ = z := fun _ ⟨h₀, h₁⟩ => ceil_eq_iff.mpr ⟨h₀, h₁⟩ #align int.ceil_eq_on_Ioc Int.ceil_eq_on_Ioc theorem ceil_eq_on_Ioc' (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, (⌈a⌉ : α) = z := fun a ha => mod_cast ceil_eq_on_Ioc z a ha #align int.ceil_eq_on_Ioc' Int.ceil_eq_on_Ioc' theorem floor_le_ceil (a : α) : ⌊a⌋ ≤ ⌈a⌉ := cast_le.1 <| (floor_le _).trans <| le_ceil _ #align int.floor_le_ceil Int.floor_le_ceil theorem floor_lt_ceil_of_lt {a b : α} (h : a < b) : ⌊a⌋ < ⌈b⌉ := cast_lt.1 <| (floor_le a).trans_lt <| h.trans_le <| le_ceil b #align int.floor_lt_ceil_of_lt Int.floor_lt_ceil_of_lt -- Porting note: in mathlib3 there was no need for the type annotation in `(m : α)` @[simp] theorem preimage_ceil_singleton (m : ℤ) : (ceil : α → ℤ) ⁻¹' {m} = Ioc ((m : α) - 1) m := ext fun _ => ceil_eq_iff #align int.preimage_ceil_singleton Int.preimage_ceil_singleton theorem fract_eq_zero_or_add_one_sub_ceil (a : α) : fract a = 0 ∨ fract a = a + 1 - (⌈a⌉ : α) := by rcases eq_or_ne (fract a) 0 with ha | ha · exact Or.inl ha right suffices (⌈a⌉ : α) = ⌊a⌋ + 1 by rw [this, ← self_sub_fract] abel norm_cast rw [ceil_eq_iff] refine ⟨?_, _root_.le_of_lt <| by simp⟩ rw [cast_add, cast_one, add_tsub_cancel_right, ← self_sub_fract a, sub_lt_self_iff] exact ha.symm.lt_of_le (fract_nonneg a) #align int.fract_eq_zero_or_add_one_sub_ceil Int.fract_eq_zero_or_add_one_sub_ceil theorem ceil_eq_add_one_sub_fract (ha : fract a ≠ 0) : (⌈a⌉ : α) = a + 1 - fract a := by rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)] abel #align int.ceil_eq_add_one_sub_fract Int.ceil_eq_add_one_sub_fract theorem ceil_sub_self_eq (ha : fract a ≠ 0) : (⌈a⌉ : α) - a = 1 - fract a := by rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)] abel #align int.ceil_sub_self_eq Int.ceil_sub_self_eq /-! #### Intervals -/ @[simp] theorem preimage_Ioo {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋ ⌈b⌉ := by ext simp [floor_lt, lt_ceil] #align int.preimage_Ioo Int.preimage_Ioo @[simp] theorem preimage_Ico {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉ ⌈b⌉ := by ext simp [ceil_le, lt_ceil] #align int.preimage_Ico Int.preimage_Ico @[simp] theorem preimage_Ioc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋ ⌊b⌋ := by ext simp [floor_lt, le_floor] #align int.preimage_Ioc Int.preimage_Ioc @[simp] theorem preimage_Icc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉ ⌊b⌋ := by ext simp [ceil_le, le_floor] #align int.preimage_Icc Int.preimage_Icc @[simp] theorem preimage_Ioi : ((↑) : ℤ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋ := by ext simp [floor_lt] #align int.preimage_Ioi Int.preimage_Ioi @[simp] theorem preimage_Ici : ((↑) : ℤ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉ := by ext simp [ceil_le] #align int.preimage_Ici Int.preimage_Ici @[simp] theorem preimage_Iio : ((↑) : ℤ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉ := by ext simp [lt_ceil] #align int.preimage_Iio Int.preimage_Iio @[simp] theorem preimage_Iic : ((↑) : ℤ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋ := by ext simp [le_floor] #align int.preimage_Iic Int.preimage_Iic end Int open Int /-! ### Round -/ section round section LinearOrderedRing variable [LinearOrderedRing α] [FloorRing α] /-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/ def round (x : α) : ℤ := if 2 * fract x < 1 then ⌊x⌋ else ⌈x⌉ #align round round @[simp] theorem round_zero : round (0 : α) = 0 := by simp [round] #align round_zero round_zero @[simp] theorem round_one : round (1 : α) = 1 := by simp [round] #align round_one round_one @[simp] theorem round_natCast (n : ℕ) : round (n : α) = n := by simp [round] #align round_nat_cast round_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem round_ofNat (n : ℕ) [n.AtLeastTwo] : round (no_index (OfNat.ofNat n : α)) = n := round_natCast n @[simp] theorem round_intCast (n : ℤ) : round (n : α) = n := by simp [round] #align round_int_cast round_intCast @[simp] theorem round_add_int (x : α) (y : ℤ) : round (x + y) = round x + y := by rw [round, round, Int.fract_add_int, Int.floor_add_int, Int.ceil_add_int, ← apply_ite₂, ite_self] #align round_add_int round_add_int @[simp] theorem round_add_one (a : α) : round (a + 1) = round a + 1 := by -- Porting note: broken `convert round_add_int a 1` rw [← round_add_int a 1, cast_one] #align round_add_one round_add_one @[simp] theorem round_sub_int (x : α) (y : ℤ) : round (x - y) = round x - y := by rw [sub_eq_add_neg] norm_cast rw [round_add_int, sub_eq_add_neg] #align round_sub_int round_sub_int @[simp] theorem round_sub_one (a : α) : round (a - 1) = round a - 1 := by -- Porting note: broken `convert round_sub_int a 1` rw [← round_sub_int a 1, cast_one] #align round_sub_one round_sub_one @[simp] theorem round_add_nat (x : α) (y : ℕ) : round (x + y) = round x + y := mod_cast round_add_int x y #align round_add_nat round_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem round_add_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] : round (x + (no_index (OfNat.ofNat n))) = round x + OfNat.ofNat n := round_add_nat x n @[simp] theorem round_sub_nat (x : α) (y : ℕ) : round (x - y) = round x - y := mod_cast round_sub_int x y #align round_sub_nat round_sub_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem round_sub_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] : round (x - (no_index (OfNat.ofNat n))) = round x - OfNat.ofNat n := round_sub_nat x n @[simp] theorem round_int_add (x : α) (y : ℤ) : round ((y : α) + x) = y + round x := by rw [add_comm, round_add_int, add_comm] #align round_int_add round_int_add @[simp] theorem round_nat_add (x : α) (y : ℕ) : round ((y : α) + x) = y + round x := by rw [add_comm, round_add_nat, add_comm] #align round_nat_add round_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem round_ofNat_add (n : ℕ) [n.AtLeastTwo] (x : α) : round ((no_index (OfNat.ofNat n)) + x) = OfNat.ofNat n + round x := round_nat_add x n theorem abs_sub_round_eq_min (x : α) : |x - round x| = min (fract x) (1 - fract x) := by simp_rw [round, min_def_lt, two_mul, ← lt_tsub_iff_left] cases' lt_or_ge (fract x) (1 - fract x) with hx hx · rw [if_pos hx, if_pos hx, self_sub_floor, abs_fract] · have : 0 < fract x := by replace hx : 0 < fract x + fract x := lt_of_lt_of_le zero_lt_one (tsub_le_iff_left.mp hx) simpa only [← two_mul, mul_pos_iff_of_pos_left, zero_lt_two] using hx rw [if_neg (not_lt.mpr hx), if_neg (not_lt.mpr hx), abs_sub_comm, ceil_sub_self_eq this.ne.symm, abs_one_sub_fract] #align abs_sub_round_eq_min abs_sub_round_eq_min theorem round_le (x : α) (z : ℤ) : |x - round x| ≤ |x - z| := by rw [abs_sub_round_eq_min, min_le_iff] rcases le_or_lt (z : α) x with (hx | hx) <;> [left; right] · conv_rhs => rw [abs_eq_self.mpr (sub_nonneg.mpr hx), ← fract_add_floor x, add_sub_assoc] simpa only [le_add_iff_nonneg_right, sub_nonneg, cast_le] using le_floor.mpr hx · rw [abs_eq_neg_self.mpr (sub_neg.mpr hx).le] conv_rhs => rw [← fract_add_floor x] rw [add_sub_assoc, add_comm, neg_add, neg_sub, le_add_neg_iff_add_le, sub_add_cancel, le_sub_comm] norm_cast exact floor_le_sub_one_iff.mpr hx #align round_le round_le end LinearOrderedRing section LinearOrderedField variable [LinearOrderedField α] [FloorRing α] theorem round_eq (x : α) : round x = ⌊x + 1 / 2⌋ := by simp_rw [round, (by simp only [lt_div_iff', two_pos] : 2 * fract x < 1 ↔ fract x < 1 / 2)] cases' lt_or_le (fract x) (1 / 2) with hx hx · conv_rhs => rw [← fract_add_floor x, add_assoc, add_left_comm, floor_int_add] rw [if_pos hx, self_eq_add_right, floor_eq_iff, cast_zero, zero_add] constructor · linarith [fract_nonneg x] · linarith · have : ⌊fract x + 1 / 2⌋ = 1 := by rw [floor_eq_iff] constructor · norm_num linarith · norm_num linarith [fract_lt_one x] rw [if_neg (not_lt.mpr hx), ← fract_add_floor x, add_assoc, add_left_comm, floor_int_add, ceil_add_int, add_comm _ ⌊x⌋, add_right_inj, ceil_eq_iff, this, cast_one, sub_self] constructor · linarith · linarith [fract_lt_one x] #align round_eq round_eq @[simp] theorem round_two_inv : round (2⁻¹ : α) = 1 := by simp only [round_eq, ← one_div, add_halves', floor_one] #align round_two_inv round_two_inv @[simp] theorem round_neg_two_inv : round (-2⁻¹ : α) = 0 := by simp only [round_eq, ← one_div, add_left_neg, floor_zero] #align round_neg_two_inv round_neg_two_inv @[simp] theorem round_eq_zero_iff {x : α} : round x = 0 ↔ x ∈ Ico (-(1 / 2)) ((1 : α) / 2) := by rw [round_eq, floor_eq_zero_iff, add_mem_Ico_iff_left] norm_num #align round_eq_zero_iff round_eq_zero_iff theorem abs_sub_round (x : α) : |x - round x| ≤ 1 / 2 := by rw [round_eq, abs_sub_le_iff] have := floor_le (x + 1 / 2) have := lt_floor_add_one (x + 1 / 2) constructor <;> linarith #align abs_sub_round abs_sub_round theorem abs_sub_round_div_natCast_eq {m n : ℕ} : |(m : α) / n - round ((m : α) / n)| = ↑(min (m % n) (n - m % n)) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp have hn' : 0 < (n : α) := by norm_cast rw [abs_sub_round_eq_min, Nat.cast_min, ← min_div_div_right hn'.le, fract_div_natCast_eq_div_natCast_mod, Nat.cast_sub (m.mod_lt hn).le, sub_div, div_self hn'.ne'] #align abs_sub_round_div_nat_cast_eq abs_sub_round_div_natCast_eq end LinearOrderedField end round namespace Nat variable [LinearOrderedSemiring α] [LinearOrderedSemiring β] [FloorSemiring α] [FloorSemiring β] variable [FunLike F α β] [RingHomClass F α β] {a : α} {b : β} theorem floor_congr (h : ∀ n : ℕ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋₊ = ⌊b⌋₊ := by have h₀ : 0 ≤ a ↔ 0 ≤ b := by simpa only [cast_zero] using h 0 obtain ha | ha := lt_or_le a 0 · rw [floor_of_nonpos ha.le, floor_of_nonpos (le_of_not_le <| h₀.not.mp ha.not_le)] exact (le_floor <| (h _).1 <| floor_le ha).antisymm (le_floor <| (h _).2 <| floor_le <| h₀.1 ha) #align nat.floor_congr Nat.floor_congr theorem ceil_congr (h : ∀ n : ℕ, a ≤ n ↔ b ≤ n) : ⌈a⌉₊ = ⌈b⌉₊ := (ceil_le.2 <| (h _).2 <| le_ceil _).antisymm <| ceil_le.2 <| (h _).1 <| le_ceil _ #align nat.ceil_congr Nat.ceil_congr theorem map_floor (f : F) (hf : StrictMono f) (a : α) : ⌊f a⌋₊ = ⌊a⌋₊ := floor_congr fun n => by rw [← map_natCast f, hf.le_iff_le] #align nat.map_floor Nat.map_floor theorem map_ceil (f : F) (hf : StrictMono f) (a : α) : ⌈f a⌉₊ = ⌈a⌉₊ := ceil_congr fun n => by rw [← map_natCast f, hf.le_iff_le] #align nat.map_ceil Nat.map_ceil end Nat namespace Int variable [LinearOrderedRing α] [LinearOrderedRing β] [FloorRing α] [FloorRing β] variable [FunLike F α β] [RingHomClass F α β] {a : α} {b : β} theorem floor_congr (h : ∀ n : ℤ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋ = ⌊b⌋ := (le_floor.2 <| (h _).1 <| floor_le _).antisymm <| le_floor.2 <| (h _).2 <| floor_le _ #align int.floor_congr Int.floor_congr theorem ceil_congr (h : ∀ n : ℤ, a ≤ n ↔ b ≤ n) : ⌈a⌉ = ⌈b⌉ := (ceil_le.2 <| (h _).2 <| le_ceil _).antisymm <| ceil_le.2 <| (h _).1 <| le_ceil _ #align int.ceil_congr Int.ceil_congr theorem map_floor (f : F) (hf : StrictMono f) (a : α) : ⌊f a⌋ = ⌊a⌋ := floor_congr fun n => by rw [← map_intCast f, hf.le_iff_le] #align int.map_floor Int.map_floor theorem map_ceil (f : F) (hf : StrictMono f) (a : α) : ⌈f a⌉ = ⌈a⌉ := ceil_congr fun n => by rw [← map_intCast f, hf.le_iff_le] #align int.map_ceil Int.map_ceil theorem map_fract (f : F) (hf : StrictMono f) (a : α) : fract (f a) = f (fract a) := by simp_rw [fract, map_sub, map_intCast, map_floor _ hf] #align int.map_fract Int.map_fract end Int namespace Int variable [LinearOrderedField α] [LinearOrderedField β] [FloorRing α] [FloorRing β] variable [FunLike F α β] [RingHomClass F α β] {a : α} {b : β} theorem map_round (f : F) (hf : StrictMono f) (a : α) : round (f a) = round a := by have H : f 2 = 2 := map_natCast f 2 simp_rw [round_eq, ← map_floor _ hf, map_add, one_div, map_inv₀, H] -- Porting note: was -- simp_rw [round_eq, ← map_floor _ hf, map_add, one_div, map_inv₀, map_bit0, map_one] -- Would have thought that `map_natCast` would replace `map_bit0, map_one` but seems not #align int.map_round Int.map_round end Int section FloorRingToSemiring variable [LinearOrderedRing α] [FloorRing α] /-! #### A floor ring as a floor semiring -/ -- see Note [lower instance priority] instance (priority := 100) FloorRing.toFloorSemiring : FloorSemiring α where floor a := ⌊a⌋.toNat ceil a := ⌈a⌉.toNat floor_of_neg {a} ha := Int.toNat_of_nonpos (Int.floor_nonpos ha.le) gc_floor {a n} ha := by rw [Int.le_toNat (Int.floor_nonneg.2 ha), Int.le_floor, Int.cast_natCast] gc_ceil a n := by rw [Int.toNat_le, Int.ceil_le, Int.cast_natCast] #align floor_ring.to_floor_semiring FloorRing.toFloorSemiring theorem Int.floor_toNat (a : α) : ⌊a⌋.toNat = ⌊a⌋₊ := rfl #align int.floor_to_nat Int.floor_toNat theorem Int.ceil_toNat (a : α) : ⌈a⌉.toNat = ⌈a⌉₊ := rfl #align int.ceil_to_nat Int.ceil_toNat @[simp] theorem Nat.floor_int : (Nat.floor : ℤ → ℕ) = Int.toNat := rfl #align nat.floor_int Nat.floor_int @[simp] theorem Nat.ceil_int : (Nat.ceil : ℤ → ℕ) = Int.toNat := rfl #align nat.ceil_int Nat.ceil_int variable {a : α} theorem Int.ofNat_floor_eq_floor (ha : 0 ≤ a) : (⌊a⌋₊ : ℤ) = ⌊a⌋ := by rw [← Int.floor_toNat, Int.toNat_of_nonneg (Int.floor_nonneg.2 ha)] #align nat.cast_floor_eq_int_floor Int.ofNat_floor_eq_floor theorem Int.ofNat_ceil_eq_ceil (ha : 0 ≤ a) : (⌈a⌉₊ : ℤ) = ⌈a⌉ := by rw [← Int.ceil_toNat, Int.toNat_of_nonneg (Int.ceil_nonneg ha)] #align nat.cast_ceil_eq_int_ceil Int.ofNat_ceil_eq_ceil theorem natCast_floor_eq_intCast_floor (ha : 0 ≤ a) : (⌊a⌋₊ : α) = ⌊a⌋ := by rw [← Int.ofNat_floor_eq_floor ha, Int.cast_natCast] #align nat.cast_floor_eq_cast_int_floor natCast_floor_eq_intCast_floor
Mathlib/Algebra/Order/Floor.lean
1,740
1,741
theorem natCast_ceil_eq_intCast_ceil (ha : 0 ≤ a) : (⌈a⌉₊ : α) = ⌈a⌉ := by
rw [← Int.ofNat_ceil_eq_ceil ha, Int.cast_natCast]
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.Algebra.Subalgebra.Pointwise import Mathlib.AlgebraicGeometry.PrimeSpectrum.Maximal import Mathlib.AlgebraicGeometry.PrimeSpectrum.Noetherian import Mathlib.RingTheory.ChainOfDivisors import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Operations #align_import ring_theory.dedekind_domain.ideal from "leanprover-community/mathlib"@"2bbc7e3884ba234309d2a43b19144105a753292e" /-! # Dedekind domains and ideals In this file, we show a ring is a Dedekind domain iff all fractional ideals are invertible. Then we prove some results on the unique factorization monoid structure of the ideals. ## Main definitions - `IsDedekindDomainInv` alternatively defines a Dedekind domain as an integral domain where every nonzero fractional ideal is invertible. - `isDedekindDomainInv_iff` shows that this does note depend on the choice of field of fractions. - `IsDedekindDomain.HeightOneSpectrum` defines the type of nonzero prime ideals of `R`. ## Main results: - `isDedekindDomain_iff_isDedekindDomainInv` - `Ideal.uniqueFactorizationMonoid` ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. Often, definitions assume that Dedekind domains are not fields. We found it more practical to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial section Inverse namespace FractionalIdeal variable {R₁ : Type*} [CommRing R₁] [IsDomain R₁] [Algebra R₁ K] [IsFractionRing R₁ K] variable {I J : FractionalIdeal R₁⁰ K} noncomputable instance : Inv (FractionalIdeal R₁⁰ K) := ⟨fun I => 1 / I⟩ theorem inv_eq : I⁻¹ = 1 / I := rfl #align fractional_ideal.inv_eq FractionalIdeal.inv_eq theorem inv_zero' : (0 : FractionalIdeal R₁⁰ K)⁻¹ = 0 := div_zero #align fractional_ideal.inv_zero' FractionalIdeal.inv_zero' theorem inv_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : J⁻¹ = ⟨(1 : FractionalIdeal R₁⁰ K) / J, fractional_div_of_nonzero h⟩ := div_nonzero h #align fractional_ideal.inv_nonzero FractionalIdeal.inv_nonzero theorem coe_inv_of_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : (↑J⁻¹ : Submodule R₁ K) = IsLocalization.coeSubmodule K ⊤ / (J : Submodule R₁ K) := by simp_rw [inv_nonzero _ h, coe_one, coe_mk, IsLocalization.coeSubmodule_top] #align fractional_ideal.coe_inv_of_nonzero FractionalIdeal.coe_inv_of_nonzero variable {K} theorem mem_inv_iff (hI : I ≠ 0) {x : K} : x ∈ I⁻¹ ↔ ∀ y ∈ I, x * y ∈ (1 : FractionalIdeal R₁⁰ K) := mem_div_iff_of_nonzero hI #align fractional_ideal.mem_inv_iff FractionalIdeal.mem_inv_iff theorem inv_anti_mono (hI : I ≠ 0) (hJ : J ≠ 0) (hIJ : I ≤ J) : J⁻¹ ≤ I⁻¹ := by -- Porting note: in Lean3, introducing `x` would just give `x ∈ J⁻¹ → x ∈ I⁻¹`, but -- in Lean4, it goes all the way down to the subtypes intro x simp only [val_eq_coe, mem_coe, mem_inv_iff hJ, mem_inv_iff hI] exact fun h y hy => h y (hIJ hy) #align fractional_ideal.inv_anti_mono FractionalIdeal.inv_anti_mono theorem le_self_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * I⁻¹ := le_self_mul_one_div hI #align fractional_ideal.le_self_mul_inv FractionalIdeal.le_self_mul_inv variable (K) theorem coe_ideal_le_self_mul_inv (I : Ideal R₁) : (I : FractionalIdeal R₁⁰ K) ≤ I * (I : FractionalIdeal R₁⁰ K)⁻¹ := le_self_mul_inv coeIdeal_le_one #align fractional_ideal.coe_ideal_le_self_mul_inv FractionalIdeal.coe_ideal_le_self_mul_inv /-- `I⁻¹` is the inverse of `I` if `I` has an inverse. -/ theorem right_inverse_eq (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = I⁻¹ := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hx hy #align fractional_ideal.right_inverse_eq FractionalIdeal.right_inverse_eq theorem mul_inv_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨I⁻¹, h⟩, fun ⟨J, hJ⟩ => by rwa [← right_inverse_eq K I J hJ]⟩ #align fractional_ideal.mul_inv_cancel_iff FractionalIdeal.mul_inv_cancel_iff theorem mul_inv_cancel_iff_isUnit {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ IsUnit I := (mul_inv_cancel_iff K).trans isUnit_iff_exists_inv.symm #align fractional_ideal.mul_inv_cancel_iff_is_unit FractionalIdeal.mul_inv_cancel_iff_isUnit variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] theorem map_inv (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : I⁻¹.map (h : K →ₐ[R₁] K') = (I.map h)⁻¹ := by rw [inv_eq, map_div, map_one, inv_eq] #align fractional_ideal.map_inv FractionalIdeal.map_inv open Submodule Submodule.IsPrincipal @[simp] theorem spanSingleton_inv (x : K) : (spanSingleton R₁⁰ x)⁻¹ = spanSingleton _ x⁻¹ := one_div_spanSingleton x #align fractional_ideal.span_singleton_inv FractionalIdeal.spanSingleton_inv -- @[simp] -- Porting note: not in simpNF form theorem spanSingleton_div_spanSingleton (x y : K) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ y = spanSingleton R₁⁰ (x / y) := by rw [div_spanSingleton, mul_comm, spanSingleton_mul_spanSingleton, div_eq_mul_inv] #align fractional_ideal.span_singleton_div_span_singleton FractionalIdeal.spanSingleton_div_spanSingleton theorem spanSingleton_div_self {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ x = 1 := by rw [spanSingleton_div_spanSingleton, div_self hx, spanSingleton_one] #align fractional_ideal.span_singleton_div_self FractionalIdeal.spanSingleton_div_self theorem coe_ideal_span_singleton_div_self {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) / Ideal.span ({x} : Set R₁) = 1 := by rw [coeIdeal_span_singleton, spanSingleton_div_self K <| (map_ne_zero_iff _ <| NoZeroSMulDivisors.algebraMap_injective R₁ K).mpr hx] #align fractional_ideal.coe_ideal_span_singleton_div_self FractionalIdeal.coe_ideal_span_singleton_div_self theorem spanSingleton_mul_inv {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x * (spanSingleton R₁⁰ x)⁻¹ = 1 := by rw [spanSingleton_inv, spanSingleton_mul_spanSingleton, mul_inv_cancel hx, spanSingleton_one] #align fractional_ideal.span_singleton_mul_inv FractionalIdeal.spanSingleton_mul_inv theorem coe_ideal_span_singleton_mul_inv {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) * (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ = 1 := by rw [coeIdeal_span_singleton, spanSingleton_mul_inv K <| (map_ne_zero_iff _ <| NoZeroSMulDivisors.algebraMap_injective R₁ K).mpr hx] #align fractional_ideal.coe_ideal_span_singleton_mul_inv FractionalIdeal.coe_ideal_span_singleton_mul_inv theorem spanSingleton_inv_mul {x : K} (hx : x ≠ 0) : (spanSingleton R₁⁰ x)⁻¹ * spanSingleton R₁⁰ x = 1 := by rw [mul_comm, spanSingleton_mul_inv K hx] #align fractional_ideal.span_singleton_inv_mul FractionalIdeal.spanSingleton_inv_mul theorem coe_ideal_span_singleton_inv_mul {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ * Ideal.span ({x} : Set R₁) = 1 := by rw [mul_comm, coe_ideal_span_singleton_mul_inv K hx] #align fractional_ideal.coe_ideal_span_singleton_inv_mul FractionalIdeal.coe_ideal_span_singleton_inv_mul theorem mul_generator_self_inv {R₁ : Type*} [CommRing R₁] [Algebra R₁ K] [IsLocalization R₁⁰ K] (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := by -- Rewrite only the `I` that appears alone. conv_lhs => congr; rw [eq_spanSingleton_of_principal I] rw [spanSingleton_mul_spanSingleton, mul_inv_cancel, spanSingleton_one] intro generator_I_eq_zero apply h rw [eq_spanSingleton_of_principal I, generator_I_eq_zero, spanSingleton_zero] #align fractional_ideal.mul_generator_self_inv FractionalIdeal.mul_generator_self_inv theorem invertible_of_principal (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * I⁻¹ = 1 := mul_div_self_cancel_iff.mpr ⟨spanSingleton _ (generator (I : Submodule R₁ K))⁻¹, mul_generator_self_inv _ I h⟩ #align fractional_ideal.invertible_of_principal FractionalIdeal.invertible_of_principal theorem invertible_iff_generator_nonzero (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] : I * I⁻¹ = 1 ↔ generator (I : Submodule R₁ K) ≠ 0 := by constructor · intro hI hg apply ne_zero_of_mul_eq_one _ _ hI rw [eq_spanSingleton_of_principal I, hg, spanSingleton_zero] · intro hg apply invertible_of_principal rw [eq_spanSingleton_of_principal I] intro hI have := mem_spanSingleton_self R₁⁰ (generator (I : Submodule R₁ K)) rw [hI, mem_zero_iff] at this contradiction #align fractional_ideal.invertible_iff_generator_nonzero FractionalIdeal.invertible_iff_generator_nonzero theorem isPrincipal_inv (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : Submodule.IsPrincipal I⁻¹.1 := by rw [val_eq_coe, isPrincipal_iff] use (generator (I : Submodule R₁ K))⁻¹ have hI : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := mul_generator_self_inv _ I h exact (right_inverse_eq _ I (spanSingleton _ (generator (I : Submodule R₁ K))⁻¹) hI).symm #align fractional_ideal.is_principal_inv FractionalIdeal.isPrincipal_inv noncomputable instance : InvOneClass (FractionalIdeal R₁⁰ K) := { inv_one := div_one } end FractionalIdeal section IsDedekindDomainInv variable [IsDomain A] /-- A Dedekind domain is an integral domain such that every fractional ideal has an inverse. This is equivalent to `IsDedekindDomain`. In particular we provide a `fractional_ideal.comm_group_with_zero` instance, assuming `IsDedekindDomain A`, which implies `IsDedekindDomainInv`. For **integral** ideals, `IsDedekindDomain`(`_inv`) implies only `Ideal.cancelCommMonoidWithZero`. -/ def IsDedekindDomainInv : Prop := ∀ I ≠ (⊥ : FractionalIdeal A⁰ (FractionRing A)), I * I⁻¹ = 1 #align is_dedekind_domain_inv IsDedekindDomainInv open FractionalIdeal variable {R A K} theorem isDedekindDomainInv_iff [Algebra A K] [IsFractionRing A K] : IsDedekindDomainInv A ↔ ∀ I ≠ (⊥ : FractionalIdeal A⁰ K), I * I⁻¹ = 1 := by let h : FractionalIdeal A⁰ (FractionRing A) ≃+* FractionalIdeal A⁰ K := FractionalIdeal.mapEquiv (FractionRing.algEquiv A K) refine h.toEquiv.forall_congr (fun {x} => ?_) rw [← h.toEquiv.apply_eq_iff_eq] simp [h, IsDedekindDomainInv] #align is_dedekind_domain_inv_iff isDedekindDomainInv_iff theorem FractionalIdeal.adjoinIntegral_eq_one_of_isUnit [Algebra A K] [IsFractionRing A K] (x : K) (hx : IsIntegral A x) (hI : IsUnit (adjoinIntegral A⁰ x hx)) : adjoinIntegral A⁰ x hx = 1 := by set I := adjoinIntegral A⁰ x hx have mul_self : I * I = I := by apply coeToSubmodule_injective; simp [I] convert congr_arg (· * I⁻¹) mul_self <;> simp only [(mul_inv_cancel_iff_isUnit K).mpr hI, mul_assoc, mul_one] #align fractional_ideal.adjoin_integral_eq_one_of_is_unit FractionalIdeal.adjoinIntegral_eq_one_of_isUnit namespace IsDedekindDomainInv variable [Algebra A K] [IsFractionRing A K] (h : IsDedekindDomainInv A) theorem mul_inv_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I * I⁻¹ = 1 := isDedekindDomainInv_iff.mp h I hI #align is_dedekind_domain_inv.mul_inv_eq_one IsDedekindDomainInv.mul_inv_eq_one theorem inv_mul_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I⁻¹ * I = 1 := (mul_comm _ _).trans (h.mul_inv_eq_one hI) #align is_dedekind_domain_inv.inv_mul_eq_one IsDedekindDomainInv.inv_mul_eq_one protected theorem isUnit {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : IsUnit I := isUnit_of_mul_eq_one _ _ (h.mul_inv_eq_one hI) #align is_dedekind_domain_inv.is_unit IsDedekindDomainInv.isUnit theorem isNoetherianRing : IsNoetherianRing A := by refine isNoetherianRing_iff.mpr ⟨fun I : Ideal A => ?_⟩ by_cases hI : I = ⊥ · rw [hI]; apply Submodule.fg_bot have hI : (I : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hI exact I.fg_of_isUnit (IsFractionRing.injective A (FractionRing A)) (h.isUnit hI) #align is_dedekind_domain_inv.is_noetherian_ring IsDedekindDomainInv.isNoetherianRing theorem integrallyClosed : IsIntegrallyClosed A := by -- It suffices to show that for integral `x`, -- `A[x]` (which is a fractional ideal) is in fact equal to `A`. refine (isIntegrallyClosed_iff (FractionRing A)).mpr (fun {x hx} => ?_) rw [← Set.mem_range, ← Algebra.mem_bot, ← Subalgebra.mem_toSubmodule, Algebra.toSubmodule_bot, Submodule.one_eq_span, ← coe_spanSingleton A⁰ (1 : FractionRing A), spanSingleton_one, ← FractionalIdeal.adjoinIntegral_eq_one_of_isUnit x hx (h.isUnit _)] · exact mem_adjoinIntegral_self A⁰ x hx · exact fun h => one_ne_zero (eq_zero_iff.mp h 1 (Algebra.adjoin A {x}).one_mem) #align is_dedekind_domain_inv.integrally_closed IsDedekindDomainInv.integrallyClosed open Ring theorem dimensionLEOne : DimensionLEOne A := ⟨by -- We're going to show that `P` is maximal because any (maximal) ideal `M` -- that is strictly larger would be `⊤`. rintro P P_ne hP refine Ideal.isMaximal_def.mpr ⟨hP.ne_top, fun M hM => ?_⟩ -- We may assume `P` and `M` (as fractional ideals) are nonzero. have P'_ne : (P : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr P_ne have M'_ne : (M : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hM.ne_bot -- In particular, we'll show `M⁻¹ * P ≤ P` suffices (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ P by rw [eq_top_iff, ← coeIdeal_le_coeIdeal (FractionRing A), coeIdeal_top] calc (1 : FractionalIdeal A⁰ (FractionRing A)) = _ * _ * _ := ?_ _ ≤ _ * _ := mul_right_mono ((P : FractionalIdeal A⁰ (FractionRing A))⁻¹ * M : FractionalIdeal A⁰ (FractionRing A)) this _ = M := ?_ · rw [mul_assoc, ← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne, one_mul, h.inv_mul_eq_one M'_ne] · rw [← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne, one_mul] -- Suppose we have `x ∈ M⁻¹ * P`, then in fact `x = algebraMap _ _ y` for some `y`. intro x hx have le_one : (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ 1 := by rw [← h.inv_mul_eq_one M'_ne] exact mul_left_mono _ ((coeIdeal_le_coeIdeal (FractionRing A)).mpr hM.le) obtain ⟨y, _hy, rfl⟩ := (mem_coeIdeal _).mp (le_one hx) -- Since `M` is strictly greater than `P`, let `z ∈ M \ P`. obtain ⟨z, hzM, hzp⟩ := SetLike.exists_of_lt hM -- We have `z * y ∈ M * (M⁻¹ * P) = P`. have zy_mem := mul_mem_mul (mem_coeIdeal_of_mem A⁰ hzM) hx rw [← RingHom.map_mul, ← mul_assoc, h.mul_inv_eq_one M'_ne, one_mul] at zy_mem obtain ⟨zy, hzy, zy_eq⟩ := (mem_coeIdeal A⁰).mp zy_mem rw [IsFractionRing.injective A (FractionRing A) zy_eq] at hzy -- But `P` is a prime ideal, so `z ∉ P` implies `y ∈ P`, as desired. exact mem_coeIdeal_of_mem A⁰ (Or.resolve_left (hP.mem_or_mem hzy) hzp)⟩ #align is_dedekind_domain_inv.dimension_le_one IsDedekindDomainInv.dimensionLEOne /-- Showing one side of the equivalence between the definitions `IsDedekindDomainInv` and `IsDedekindDomain` of Dedekind domains. -/ theorem isDedekindDomain : IsDedekindDomain A := { h.isNoetherianRing, h.dimensionLEOne, h.integrallyClosed with } #align is_dedekind_domain_inv.is_dedekind_domain IsDedekindDomainInv.isDedekindDomain end IsDedekindDomainInv end IsDedekindDomainInv variable [Algebra A K] [IsFractionRing A K] variable {A K} theorem one_mem_inv_coe_ideal [IsDomain A] {I : Ideal A} (hI : I ≠ ⊥) : (1 : K) ∈ (I : FractionalIdeal A⁰ K)⁻¹ := by rw [FractionalIdeal.mem_inv_iff (FractionalIdeal.coeIdeal_ne_zero.mpr hI)] intro y hy rw [one_mul] exact FractionalIdeal.coeIdeal_le_one hy -- #align fractional_ideal.one_mem_inv_coe_ideal FractionalIdeal.one_mem_inv_coe_ideal /-- Specialization of `exists_primeSpectrum_prod_le_and_ne_bot_of_domain` to Dedekind domains: Let `I : Ideal A` be a nonzero ideal, where `A` is a Dedekind domain that is not a field. Then `exists_primeSpectrum_prod_le_and_ne_bot_of_domain` states we can find a product of prime ideals that is contained within `I`. This lemma extends that result by making the product minimal: let `M` be a maximal ideal that contains `I`, then the product including `M` is contained within `I` and the product excluding `M` is not contained within `I`. -/ theorem exists_multiset_prod_cons_le_and_prod_not_le [IsDedekindDomain A] (hNF : ¬IsField A) {I M : Ideal A} (hI0 : I ≠ ⊥) (hIM : I ≤ M) [hM : M.IsMaximal] : ∃ Z : Multiset (PrimeSpectrum A), (M ::ₘ Z.map PrimeSpectrum.asIdeal).prod ≤ I ∧ ¬Multiset.prod (Z.map PrimeSpectrum.asIdeal) ≤ I := by -- Let `Z` be a minimal set of prime ideals such that their product is contained in `J`. obtain ⟨Z₀, hZ₀⟩ := PrimeSpectrum.exists_primeSpectrum_prod_le_and_ne_bot_of_domain hNF hI0 obtain ⟨Z, ⟨hZI, hprodZ⟩, h_eraseZ⟩ := wellFounded_lt.has_min {Z | (Z.map PrimeSpectrum.asIdeal).prod ≤ I ∧ (Z.map PrimeSpectrum.asIdeal).prod ≠ ⊥} ⟨Z₀, hZ₀.1, hZ₀.2⟩ obtain ⟨_, hPZ', hPM⟩ := hM.isPrime.multiset_prod_le.mp (hZI.trans hIM) -- Then in fact there is a `P ∈ Z` with `P ≤ M`. obtain ⟨P, hPZ, rfl⟩ := Multiset.mem_map.mp hPZ' classical have := Multiset.map_erase PrimeSpectrum.asIdeal PrimeSpectrum.ext P Z obtain ⟨hP0, hZP0⟩ : P.asIdeal ≠ ⊥ ∧ ((Z.erase P).map PrimeSpectrum.asIdeal).prod ≠ ⊥ := by rwa [Ne, ← Multiset.cons_erase hPZ', Multiset.prod_cons, Ideal.mul_eq_bot, not_or, ← this] at hprodZ -- By maximality of `P` and `M`, we have that `P ≤ M` implies `P = M`. have hPM' := (P.IsPrime.isMaximal hP0).eq_of_le hM.ne_top hPM subst hPM' -- By minimality of `Z`, erasing `P` from `Z` is exactly what we need. refine ⟨Z.erase P, ?_, ?_⟩ · convert hZI rw [this, Multiset.cons_erase hPZ'] · refine fun h => h_eraseZ (Z.erase P) ⟨h, ?_⟩ (Multiset.erase_lt.mpr hPZ) exact hZP0 #align exists_multiset_prod_cons_le_and_prod_not_le exists_multiset_prod_cons_le_and_prod_not_le namespace FractionalIdeal open Ideal lemma not_inv_le_one_of_ne_bot [IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) : ¬(I⁻¹ : FractionalIdeal A⁰ K) ≤ 1 := by have hNF : ¬IsField A := fun h ↦ letI := h.toField; (eq_bot_or_eq_top I).elim hI0 hI1 wlog hM : I.IsMaximal generalizing I · rcases I.exists_le_maximal hI1 with ⟨M, hmax, hIM⟩ have hMbot : M ≠ ⊥ := (M.bot_lt_of_maximal hNF).ne' refine mt (le_trans <| inv_anti_mono ?_ ?_ ?_) (this hMbot hmax.ne_top hmax) <;> simpa only [coeIdeal_ne_zero, coeIdeal_le_coeIdeal] have hI0 : ⊥ < I := I.bot_lt_of_maximal hNF obtain ⟨⟨a, haI⟩, ha0⟩ := Submodule.nonzero_mem_of_bot_lt hI0 replace ha0 : a ≠ 0 := Subtype.coe_injective.ne ha0 let J : Ideal A := Ideal.span {a} have hJ0 : J ≠ ⊥ := mt Ideal.span_singleton_eq_bot.mp ha0 have hJI : J ≤ I := I.span_singleton_le_iff_mem.2 haI -- Then we can find a product of prime (hence maximal) ideals contained in `J`, -- such that removing element `M` from the product is not contained in `J`. obtain ⟨Z, hle, hnle⟩ := exists_multiset_prod_cons_le_and_prod_not_le hNF hJ0 hJI -- Choose an element `b` of the product that is not in `J`. obtain ⟨b, hbZ, hbJ⟩ := SetLike.not_le_iff_exists.mp hnle have hnz_fa : algebraMap A K a ≠ 0 := mt ((injective_iff_map_eq_zero _).mp (IsFractionRing.injective A K) a) ha0 -- Then `b a⁻¹ : K` is in `M⁻¹` but not in `1`. refine Set.not_subset.2 ⟨algebraMap A K b * (algebraMap A K a)⁻¹, (mem_inv_iff ?_).mpr ?_, ?_⟩ · exact coeIdeal_ne_zero.mpr hI0.ne' · rintro y₀ hy₀ obtain ⟨y, h_Iy, rfl⟩ := (mem_coeIdeal _).mp hy₀ rw [mul_comm, ← mul_assoc, ← RingHom.map_mul] have h_yb : y * b ∈ J := by apply hle rw [Multiset.prod_cons] exact Submodule.smul_mem_smul h_Iy hbZ rw [Ideal.mem_span_singleton'] at h_yb rcases h_yb with ⟨c, hc⟩ rw [← hc, RingHom.map_mul, mul_assoc, mul_inv_cancel hnz_fa, mul_one] apply coe_mem_one · refine mt (mem_one_iff _).mp ?_ rintro ⟨x', h₂_abs⟩ rw [← div_eq_mul_inv, eq_div_iff_mul_eq hnz_fa, ← RingHom.map_mul] at h₂_abs have := Ideal.mem_span_singleton'.mpr ⟨x', IsFractionRing.injective A K h₂_abs⟩ contradiction theorem exists_not_mem_one_of_ne_bot [IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) : ∃ x ∈ (I⁻¹ : FractionalIdeal A⁰ K), x ∉ (1 : FractionalIdeal A⁰ K) := Set.not_subset.1 <| not_inv_le_one_of_ne_bot hI0 hI1 #align fractional_ideal.exists_not_mem_one_of_ne_bot FractionalIdeal.exists_not_mem_one_of_ne_bot theorem mul_inv_cancel_of_le_one [h : IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥) (hI : (I * (I : FractionalIdeal A⁰ K)⁻¹)⁻¹ ≤ 1) : I * (I : FractionalIdeal A⁰ K)⁻¹ = 1 := by -- We'll show a contradiction with `exists_not_mem_one_of_ne_bot`: -- `J⁻¹ = (I * I⁻¹)⁻¹` cannot have an element `x ∉ 1`, so it must equal `1`. obtain ⟨J, hJ⟩ : ∃ J : Ideal A, (J : FractionalIdeal A⁰ K) = I * (I : FractionalIdeal A⁰ K)⁻¹ := le_one_iff_exists_coeIdeal.mp mul_one_div_le_one by_cases hJ0 : J = ⊥ · subst hJ0 refine absurd ?_ hI0 rw [eq_bot_iff, ← coeIdeal_le_coeIdeal K, hJ] exact coe_ideal_le_self_mul_inv K I by_cases hJ1 : J = ⊤ · rw [← hJ, hJ1, coeIdeal_top] exact (not_inv_le_one_of_ne_bot (K := K) hJ0 hJ1 (hJ ▸ hI)).elim #align fractional_ideal.mul_inv_cancel_of_le_one FractionalIdeal.mul_inv_cancel_of_le_one /-- Nonzero integral ideals in a Dedekind domain are invertible. We will use this to show that nonzero fractional ideals are invertible, and finally conclude that fractional ideals in a Dedekind domain form a group with zero. -/ theorem coe_ideal_mul_inv [h : IsDedekindDomain A] (I : Ideal A) (hI0 : I ≠ ⊥) : I * (I : FractionalIdeal A⁰ K)⁻¹ = 1 := by -- We'll show `1 ≤ J⁻¹ = (I * I⁻¹)⁻¹ ≤ 1`. apply mul_inv_cancel_of_le_one hI0 by_cases hJ0 : I * (I : FractionalIdeal A⁰ K)⁻¹ = 0 · rw [hJ0, inv_zero']; exact zero_le _ intro x hx -- In particular, we'll show all `x ∈ J⁻¹` are integral. suffices x ∈ integralClosure A K by rwa [IsIntegrallyClosed.integralClosure_eq_bot, Algebra.mem_bot, Set.mem_range, ← mem_one_iff] at this -- For that, we'll find a subalgebra that is f.g. as a module and contains `x`. -- `A` is a noetherian ring, so we just need to find a subalgebra between `{x}` and `I⁻¹`. rw [mem_integralClosure_iff_mem_fg] have x_mul_mem : ∀ b ∈ (I⁻¹ : FractionalIdeal A⁰ K), x * b ∈ (I⁻¹ : FractionalIdeal A⁰ K) := by intro b hb rw [mem_inv_iff (coeIdeal_ne_zero.mpr hI0)] dsimp only at hx rw [val_eq_coe, mem_coe, mem_inv_iff hJ0] at hx simp only [mul_assoc, mul_comm b] at hx ⊢ intro y hy exact hx _ (mul_mem_mul hy hb) -- It turns out the subalgebra consisting of all `p(x)` for `p : A[X]` works. refine ⟨AlgHom.range (Polynomial.aeval x : A[X] →ₐ[A] K), isNoetherian_submodule.mp (isNoetherian (I : FractionalIdeal A⁰ K)⁻¹) _ fun y hy => ?_, ⟨Polynomial.X, Polynomial.aeval_X x⟩⟩ obtain ⟨p, rfl⟩ := (AlgHom.mem_range _).mp hy rw [Polynomial.aeval_eq_sum_range] refine Submodule.sum_mem _ fun i hi => Submodule.smul_mem _ _ ?_ clear hi induction' i with i ih · rw [pow_zero]; exact one_mem_inv_coe_ideal hI0 · show x ^ i.succ ∈ (I⁻¹ : FractionalIdeal A⁰ K) rw [pow_succ']; exact x_mul_mem _ ih #align fractional_ideal.coe_ideal_mul_inv FractionalIdeal.coe_ideal_mul_inv /-- Nonzero fractional ideals in a Dedekind domain are units. This is also available as `_root_.mul_inv_cancel`, using the `Semifield` instance defined below. -/ protected theorem mul_inv_cancel [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hne : I ≠ 0) : I * I⁻¹ = 1 := by obtain ⟨a, J, ha, hJ⟩ : ∃ (a : A) (aI : Ideal A), a ≠ 0 ∧ I = spanSingleton A⁰ (algebraMap A K a)⁻¹ * aI := exists_eq_spanSingleton_mul I suffices h₂ : I * (spanSingleton A⁰ (algebraMap _ _ a) * (J : FractionalIdeal A⁰ K)⁻¹) = 1 by rw [mul_inv_cancel_iff] exact ⟨spanSingleton A⁰ (algebraMap _ _ a) * (J : FractionalIdeal A⁰ K)⁻¹, h₂⟩ subst hJ rw [mul_assoc, mul_left_comm (J : FractionalIdeal A⁰ K), coe_ideal_mul_inv, mul_one, spanSingleton_mul_spanSingleton, inv_mul_cancel, spanSingleton_one] · exact mt ((injective_iff_map_eq_zero (algebraMap A K)).mp (IsFractionRing.injective A K) _) ha · exact coeIdeal_ne_zero.mp (right_ne_zero_of_mul hne) #align fractional_ideal.mul_inv_cancel FractionalIdeal.mul_inv_cancel theorem mul_right_le_iff [IsDedekindDomain A] {J : FractionalIdeal A⁰ K} (hJ : J ≠ 0) : ∀ {I I'}, I * J ≤ I' * J ↔ I ≤ I' := by intro I I' constructor · intro h convert mul_right_mono J⁻¹ h <;> dsimp only <;> rw [mul_assoc, FractionalIdeal.mul_inv_cancel hJ, mul_one] · exact fun h => mul_right_mono J h #align fractional_ideal.mul_right_le_iff FractionalIdeal.mul_right_le_iff theorem mul_left_le_iff [IsDedekindDomain A] {J : FractionalIdeal A⁰ K} (hJ : J ≠ 0) {I I'} : J * I ≤ J * I' ↔ I ≤ I' := by convert mul_right_le_iff hJ using 1; simp only [mul_comm] #align fractional_ideal.mul_left_le_iff FractionalIdeal.mul_left_le_iff theorem mul_right_strictMono [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : StrictMono (· * I) := strictMono_of_le_iff_le fun _ _ => (mul_right_le_iff hI).symm #align fractional_ideal.mul_right_strict_mono FractionalIdeal.mul_right_strictMono theorem mul_left_strictMono [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : StrictMono (I * ·) := strictMono_of_le_iff_le fun _ _ => (mul_left_le_iff hI).symm #align fractional_ideal.mul_left_strict_mono FractionalIdeal.mul_left_strictMono /-- This is also available as `_root_.div_eq_mul_inv`, using the `Semifield` instance defined below. -/ protected theorem div_eq_mul_inv [IsDedekindDomain A] (I J : FractionalIdeal A⁰ K) : I / J = I * J⁻¹ := by by_cases hJ : J = 0 · rw [hJ, div_zero, inv_zero', mul_zero] refine le_antisymm ((mul_right_le_iff hJ).mp ?_) ((le_div_iff_mul_le hJ).mpr ?_) · rw [mul_assoc, mul_comm J⁻¹, FractionalIdeal.mul_inv_cancel hJ, mul_one, mul_le] intro x hx y hy rw [mem_div_iff_of_nonzero hJ] at hx exact hx y hy rw [mul_assoc, mul_comm J⁻¹, FractionalIdeal.mul_inv_cancel hJ, mul_one] #align fractional_ideal.div_eq_mul_inv FractionalIdeal.div_eq_mul_inv end FractionalIdeal /-- `IsDedekindDomain` and `IsDedekindDomainInv` are equivalent ways to express that an integral domain is a Dedekind domain. -/ theorem isDedekindDomain_iff_isDedekindDomainInv [IsDomain A] : IsDedekindDomain A ↔ IsDedekindDomainInv A := ⟨fun _h _I hI => FractionalIdeal.mul_inv_cancel hI, fun h => h.isDedekindDomain⟩ #align is_dedekind_domain_iff_is_dedekind_domain_inv isDedekindDomain_iff_isDedekindDomainInv end Inverse section IsDedekindDomain variable {R A} variable [IsDedekindDomain A] [Algebra A K] [IsFractionRing A K] open FractionalIdeal open Ideal noncomputable instance FractionalIdeal.semifield : Semifield (FractionalIdeal A⁰ K) where __ := coeIdeal_injective.nontrivial inv_zero := inv_zero' _ div_eq_mul_inv := FractionalIdeal.div_eq_mul_inv mul_inv_cancel _ := FractionalIdeal.mul_inv_cancel nnqsmul := _ #align fractional_ideal.semifield FractionalIdeal.semifield /-- Fractional ideals have cancellative multiplication in a Dedekind domain. Although this instance is a direct consequence of the instance `FractionalIdeal.semifield`, we define this instance to provide a computable alternative. -/ instance FractionalIdeal.cancelCommMonoidWithZero : CancelCommMonoidWithZero (FractionalIdeal A⁰ K) where __ : CommSemiring (FractionalIdeal A⁰ K) := inferInstance #align fractional_ideal.cancel_comm_monoid_with_zero FractionalIdeal.cancelCommMonoidWithZero instance Ideal.cancelCommMonoidWithZero : CancelCommMonoidWithZero (Ideal A) := { Function.Injective.cancelCommMonoidWithZero (coeIdealHom A⁰ (FractionRing A)) coeIdeal_injective (RingHom.map_zero _) (RingHom.map_one _) (RingHom.map_mul _) (RingHom.map_pow _) with } #align ideal.cancel_comm_monoid_with_zero Ideal.cancelCommMonoidWithZero -- Porting note: Lean can infer all it needs by itself instance Ideal.isDomain : IsDomain (Ideal A) := { } #align ideal.is_domain Ideal.isDomain /-- For ideals in a Dedekind domain, to divide is to contain. -/ theorem Ideal.dvd_iff_le {I J : Ideal A} : I ∣ J ↔ J ≤ I := ⟨Ideal.le_of_dvd, fun h => by by_cases hI : I = ⊥ · have hJ : J = ⊥ := by rwa [hI, ← eq_bot_iff] at h rw [hI, hJ] have hI' : (I : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hI have : (I : FractionalIdeal A⁰ (FractionRing A))⁻¹ * J ≤ 1 := le_trans (mul_left_mono (↑I)⁻¹ ((coeIdeal_le_coeIdeal _).mpr h)) (le_of_eq (inv_mul_cancel hI')) obtain ⟨H, hH⟩ := le_one_iff_exists_coeIdeal.mp this use H refine coeIdeal_injective (show (J : FractionalIdeal A⁰ (FractionRing A)) = ↑(I * H) from ?_) rw [coeIdeal_mul, hH, ← mul_assoc, mul_inv_cancel hI', one_mul]⟩ #align ideal.dvd_iff_le Ideal.dvd_iff_le theorem Ideal.dvdNotUnit_iff_lt {I J : Ideal A} : DvdNotUnit I J ↔ J < I := ⟨fun ⟨hI, H, hunit, hmul⟩ => lt_of_le_of_ne (Ideal.dvd_iff_le.mp ⟨H, hmul⟩) (mt (fun h => have : H = 1 := mul_left_cancel₀ hI (by rw [← hmul, h, mul_one]) show IsUnit H from this.symm ▸ isUnit_one) hunit), fun h => dvdNotUnit_of_dvd_of_not_dvd (Ideal.dvd_iff_le.mpr (le_of_lt h)) (mt Ideal.dvd_iff_le.mp (not_le_of_lt h))⟩ #align ideal.dvd_not_unit_iff_lt Ideal.dvdNotUnit_iff_lt instance : WfDvdMonoid (Ideal A) where wellFounded_dvdNotUnit := by have : WellFounded ((· > ·) : Ideal A → Ideal A → Prop) := isNoetherian_iff_wellFounded.mp (isNoetherianRing_iff.mp IsDedekindRing.toIsNoetherian) convert this ext rw [Ideal.dvdNotUnit_iff_lt] instance Ideal.uniqueFactorizationMonoid : UniqueFactorizationMonoid (Ideal A) := { irreducible_iff_prime := by intro P exact ⟨fun hirr => ⟨hirr.ne_zero, hirr.not_unit, fun I J => by have : P.IsMaximal := by refine ⟨⟨mt Ideal.isUnit_iff.mpr hirr.not_unit, ?_⟩⟩ intro J hJ obtain ⟨_J_ne, H, hunit, P_eq⟩ := Ideal.dvdNotUnit_iff_lt.mpr hJ exact Ideal.isUnit_iff.mp ((hirr.isUnit_or_isUnit P_eq).resolve_right hunit) rw [Ideal.dvd_iff_le, Ideal.dvd_iff_le, Ideal.dvd_iff_le, SetLike.le_def, SetLike.le_def, SetLike.le_def] contrapose! rintro ⟨⟨x, x_mem, x_not_mem⟩, ⟨y, y_mem, y_not_mem⟩⟩ exact ⟨x * y, Ideal.mul_mem_mul x_mem y_mem, mt this.isPrime.mem_or_mem (not_or_of_not x_not_mem y_not_mem)⟩⟩, Prime.irreducible⟩ } #align ideal.unique_factorization_monoid Ideal.uniqueFactorizationMonoid instance Ideal.normalizationMonoid : NormalizationMonoid (Ideal A) := normalizationMonoidOfUniqueUnits #align ideal.normalization_monoid Ideal.normalizationMonoid @[simp] theorem Ideal.dvd_span_singleton {I : Ideal A} {x : A} : I ∣ Ideal.span {x} ↔ x ∈ I := Ideal.dvd_iff_le.trans (Ideal.span_le.trans Set.singleton_subset_iff) #align ideal.dvd_span_singleton Ideal.dvd_span_singleton theorem Ideal.isPrime_of_prime {P : Ideal A} (h : Prime P) : IsPrime P := by refine ⟨?_, fun hxy => ?_⟩ · rintro rfl rw [← Ideal.one_eq_top] at h exact h.not_unit isUnit_one · simp only [← Ideal.dvd_span_singleton, ← Ideal.span_singleton_mul_span_singleton] at hxy ⊢ exact h.dvd_or_dvd hxy #align ideal.is_prime_of_prime Ideal.isPrime_of_prime theorem Ideal.prime_of_isPrime {P : Ideal A} (hP : P ≠ ⊥) (h : IsPrime P) : Prime P := by refine ⟨hP, mt Ideal.isUnit_iff.mp h.ne_top, fun I J hIJ => ?_⟩ simpa only [Ideal.dvd_iff_le] using h.mul_le.mp (Ideal.le_of_dvd hIJ) #align ideal.prime_of_is_prime Ideal.prime_of_isPrime /-- In a Dedekind domain, the (nonzero) prime elements of the monoid with zero `Ideal A` are exactly the prime ideals. -/ theorem Ideal.prime_iff_isPrime {P : Ideal A} (hP : P ≠ ⊥) : Prime P ↔ IsPrime P := ⟨Ideal.isPrime_of_prime, Ideal.prime_of_isPrime hP⟩ #align ideal.prime_iff_is_prime Ideal.prime_iff_isPrime /-- In a Dedekind domain, the prime ideals are the zero ideal together with the prime elements of the monoid with zero `Ideal A`. -/ theorem Ideal.isPrime_iff_bot_or_prime {P : Ideal A} : IsPrime P ↔ P = ⊥ ∨ Prime P := ⟨fun hp => (eq_or_ne P ⊥).imp_right fun hp0 => Ideal.prime_of_isPrime hp0 hp, fun hp => hp.elim (fun h => h.symm ▸ Ideal.bot_prime) Ideal.isPrime_of_prime⟩ #align ideal.is_prime_iff_bot_or_prime Ideal.isPrime_iff_bot_or_prime @[simp] theorem Ideal.prime_span_singleton_iff {a : A} : Prime (Ideal.span {a}) ↔ Prime a := by rcases eq_or_ne a 0 with rfl | ha · rw [Set.singleton_zero, span_zero, ← Ideal.zero_eq_bot, ← not_iff_not] simp only [not_prime_zero, not_false_eq_true] · have ha' : span {a} ≠ ⊥ := by simpa only [ne_eq, span_singleton_eq_bot] using ha rw [Ideal.prime_iff_isPrime ha', Ideal.span_singleton_prime ha] open Submodule.IsPrincipal in theorem Ideal.prime_generator_of_prime {P : Ideal A} (h : Prime P) [P.IsPrincipal] : Prime (generator P) := have : Ideal.IsPrime P := Ideal.isPrime_of_prime h prime_generator_of_isPrime _ h.ne_zero open UniqueFactorizationMonoid in nonrec theorem Ideal.mem_normalizedFactors_iff {p I : Ideal A} (hI : I ≠ ⊥) : p ∈ normalizedFactors I ↔ p.IsPrime ∧ I ≤ p := by rw [← Ideal.dvd_iff_le] by_cases hp : p = 0 · rw [← zero_eq_bot] at hI simp only [hp, zero_not_mem_normalizedFactors, zero_dvd_iff, hI, false_iff, not_and, not_false_eq_true, implies_true] · rwa [mem_normalizedFactors_iff hI, prime_iff_isPrime] theorem Ideal.pow_right_strictAnti (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) : StrictAnti (I ^ · : ℕ → Ideal A) := strictAnti_nat_of_succ_lt fun e => Ideal.dvdNotUnit_iff_lt.mp ⟨pow_ne_zero _ hI0, I, mt isUnit_iff.mp hI1, pow_succ I e⟩ #align ideal.strict_anti_pow Ideal.pow_right_strictAnti theorem Ideal.pow_lt_self (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) (he : 2 ≤ e) : I ^ e < I := by convert I.pow_right_strictAnti hI0 hI1 he dsimp only rw [pow_one] #align ideal.pow_lt_self Ideal.pow_lt_self theorem Ideal.exists_mem_pow_not_mem_pow_succ (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) : ∃ x ∈ I ^ e, x ∉ I ^ (e + 1) := SetLike.exists_of_lt (I.pow_right_strictAnti hI0 hI1 e.lt_succ_self) #align ideal.exists_mem_pow_not_mem_pow_succ Ideal.exists_mem_pow_not_mem_pow_succ open UniqueFactorizationMonoid theorem Ideal.eq_prime_pow_of_succ_lt_of_le {P I : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥) {i : ℕ} (hlt : P ^ (i + 1) < I) (hle : I ≤ P ^ i) : I = P ^ i := by refine le_antisymm hle ?_ have P_prime' := Ideal.prime_of_isPrime hP P_prime have h1 : I ≠ ⊥ := (lt_of_le_of_lt bot_le hlt).ne' have := pow_ne_zero i hP have h3 := pow_ne_zero (i + 1) hP rw [← Ideal.dvdNotUnit_iff_lt, dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors h1 h3, normalizedFactors_pow, normalizedFactors_irreducible P_prime'.irreducible, Multiset.nsmul_singleton, Multiset.lt_replicate_succ] at hlt rw [← Ideal.dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors, normalizedFactors_pow, normalizedFactors_irreducible P_prime'.irreducible, Multiset.nsmul_singleton] all_goals assumption #align ideal.eq_prime_pow_of_succ_lt_of_le Ideal.eq_prime_pow_of_succ_lt_of_le theorem Ideal.pow_succ_lt_pow {P : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥) (i : ℕ) : P ^ (i + 1) < P ^ i := lt_of_le_of_ne (Ideal.pow_le_pow_right (Nat.le_succ _)) (mt (pow_eq_pow_iff hP (mt Ideal.isUnit_iff.mp P_prime.ne_top)).mp i.succ_ne_self) #align ideal.pow_succ_lt_pow Ideal.pow_succ_lt_pow theorem Associates.le_singleton_iff (x : A) (n : ℕ) (I : Ideal A) : Associates.mk I ^ n ≤ Associates.mk (Ideal.span {x}) ↔ x ∈ I ^ n := by simp_rw [← Associates.dvd_eq_le, ← Associates.mk_pow, Associates.mk_dvd_mk, Ideal.dvd_span_singleton] #align associates.le_singleton_iff Associates.le_singleton_iff variable {K} lemma FractionalIdeal.le_inv_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) : I ≤ J⁻¹ ↔ J ≤ I⁻¹ := by rw [inv_eq, inv_eq, le_div_iff_mul_le hI, le_div_iff_mul_le hJ, mul_comm] lemma FractionalIdeal.inv_le_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) : I⁻¹ ≤ J ↔ J⁻¹ ≤ I := by simpa using le_inv_comm (A := A) (K := K) (inv_ne_zero hI) (inv_ne_zero hJ) open FractionalIdeal /-- Strengthening of `IsLocalization.exist_integer_multiples`: Let `J ≠ ⊤` be an ideal in a Dedekind domain `A`, and `f ≠ 0` a finite collection of elements of `K = Frac(A)`, then we can multiply the elements of `f` by some `a : K` to find a collection of elements of `A` that is not completely contained in `J`. -/ theorem Ideal.exist_integer_multiples_not_mem {J : Ideal A} (hJ : J ≠ ⊤) {ι : Type*} (s : Finset ι) (f : ι → K) {j} (hjs : j ∈ s) (hjf : f j ≠ 0) : ∃ a : K, (∀ i ∈ s, IsLocalization.IsInteger A (a * f i)) ∧ ∃ i ∈ s, a * f i ∉ (J : FractionalIdeal A⁰ K) := by -- Consider the fractional ideal `I` spanned by the `f`s. let I : FractionalIdeal A⁰ K := spanFinset A s f have hI0 : I ≠ 0 := spanFinset_ne_zero.mpr ⟨j, hjs, hjf⟩ -- We claim the multiplier `a` we're looking for is in `I⁻¹ \ (J / I)`. suffices ↑J / I < I⁻¹ by obtain ⟨_, a, hI, hpI⟩ := SetLike.lt_iff_le_and_exists.mp this rw [mem_inv_iff hI0] at hI refine ⟨a, fun i hi => ?_, ?_⟩ -- By definition, `a ∈ I⁻¹` multiplies elements of `I` into elements of `1`, -- in other words, `a * f i` is an integer. · exact (mem_one_iff _).mp (hI (f i) (Submodule.subset_span (Set.mem_image_of_mem f hi))) · contrapose! hpI -- And if all `a`-multiples of `I` are an element of `J`, -- then `a` is actually an element of `J / I`, contradiction. refine (mem_div_iff_of_nonzero hI0).mpr fun y hy => Submodule.span_induction hy ?_ ?_ ?_ ?_ · rintro _ ⟨i, hi, rfl⟩; exact hpI i hi · rw [mul_zero]; exact Submodule.zero_mem _ · intro x y hx hy; rw [mul_add]; exact Submodule.add_mem _ hx hy · intro b x hx; rw [mul_smul_comm]; exact Submodule.smul_mem _ b hx -- To show the inclusion of `J / I` into `I⁻¹ = 1 / I`, note that `J < I`. calc ↑J / I = ↑J * I⁻¹ := div_eq_mul_inv (↑J) I _ < 1 * I⁻¹ := mul_right_strictMono (inv_ne_zero hI0) ?_ _ = I⁻¹ := one_mul _ rw [← coeIdeal_top] -- And multiplying by `I⁻¹` is indeed strictly monotone. exact strictMono_of_le_iff_le (fun _ _ => (coeIdeal_le_coeIdeal K).symm) (lt_top_iff_ne_top.mpr hJ) #align ideal.exist_integer_multiples_not_mem Ideal.exist_integer_multiples_not_mem section Gcd namespace Ideal /-! ### GCD and LCM of ideals in a Dedekind domain We show that the gcd of two ideals in a Dedekind domain is just their supremum, and the lcm is their infimum, and use this to instantiate `NormalizedGCDMonoid (Ideal A)`. -/ @[simp] theorem sup_mul_inf (I J : Ideal A) : (I ⊔ J) * (I ⊓ J) = I * J := by letI := UniqueFactorizationMonoid.toNormalizedGCDMonoid (Ideal A) have hgcd : gcd I J = I ⊔ J := by rw [gcd_eq_normalize _ _, normalize_eq] · rw [dvd_iff_le, sup_le_iff, ← dvd_iff_le, ← dvd_iff_le] exact ⟨gcd_dvd_left _ _, gcd_dvd_right _ _⟩ · rw [dvd_gcd_iff, dvd_iff_le, dvd_iff_le] simp have hlcm : lcm I J = I ⊓ J := by rw [lcm_eq_normalize _ _, normalize_eq] · rw [lcm_dvd_iff, dvd_iff_le, dvd_iff_le] simp · rw [dvd_iff_le, le_inf_iff, ← dvd_iff_le, ← dvd_iff_le] exact ⟨dvd_lcm_left _ _, dvd_lcm_right _ _⟩ rw [← hgcd, ← hlcm, associated_iff_eq.mp (gcd_mul_lcm _ _)] #align ideal.sup_mul_inf Ideal.sup_mul_inf /-- Ideals in a Dedekind domain have gcd and lcm operators that (trivially) are compatible with the normalization operator. -/ instance : NormalizedGCDMonoid (Ideal A) := { Ideal.normalizationMonoid with gcd := (· ⊔ ·) gcd_dvd_left := fun _ _ => by simpa only [dvd_iff_le] using le_sup_left gcd_dvd_right := fun _ _ => by simpa only [dvd_iff_le] using le_sup_right dvd_gcd := by simp only [dvd_iff_le] exact fun h1 h2 => @sup_le (Ideal A) _ _ _ _ h1 h2 lcm := (· ⊓ ·) lcm_zero_left := fun _ => by simp only [zero_eq_bot, bot_inf_eq] lcm_zero_right := fun _ => by simp only [zero_eq_bot, inf_bot_eq] gcd_mul_lcm := fun _ _ => by rw [associated_iff_eq, sup_mul_inf] normalize_gcd := fun _ _ => normalize_eq _ normalize_lcm := fun _ _ => normalize_eq _ } -- In fact, any lawful gcd and lcm would equal sup and inf respectively. @[simp] theorem gcd_eq_sup (I J : Ideal A) : gcd I J = I ⊔ J := rfl #align ideal.gcd_eq_sup Ideal.gcd_eq_sup @[simp] theorem lcm_eq_inf (I J : Ideal A) : lcm I J = I ⊓ J := rfl #align ideal.lcm_eq_inf Ideal.lcm_eq_inf theorem isCoprime_iff_gcd {I J : Ideal A} : IsCoprime I J ↔ gcd I J = 1 := by rw [Ideal.isCoprime_iff_codisjoint, codisjoint_iff, one_eq_top, gcd_eq_sup] theorem factors_span_eq {p : K[X]} : factors (span {p}) = (factors p).map (fun q ↦ span {q}) := by rcases eq_or_ne p 0 with rfl | hp; · simpa [Set.singleton_zero] using normalizedFactors_zero have : ∀ q ∈ (factors p).map (fun q ↦ span {q}), Prime q := fun q hq ↦ by obtain ⟨r, hr, rfl⟩ := Multiset.mem_map.mp hq exact prime_span_singleton_iff.mpr <| prime_of_factor r hr rw [← span_singleton_eq_span_singleton.mpr (factors_prod hp), ← multiset_prod_span_singleton, factors_eq_normalizedFactors, normalizedFactors_prod_of_prime this] end Ideal end Gcd end IsDedekindDomain section IsDedekindDomain variable {T : Type*} [CommRing T] [IsDedekindDomain T] {I J : Ideal T} open scoped Classical open Multiset UniqueFactorizationMonoid Ideal theorem prod_normalizedFactors_eq_self (hI : I ≠ ⊥) : (normalizedFactors I).prod = I := associated_iff_eq.1 (normalizedFactors_prod hI) #align prod_normalized_factors_eq_self prod_normalizedFactors_eq_self theorem count_le_of_ideal_ge {I J : Ideal T} (h : I ≤ J) (hI : I ≠ ⊥) (K : Ideal T) : count K (normalizedFactors J) ≤ count K (normalizedFactors I) := le_iff_count.1 ((dvd_iff_normalizedFactors_le_normalizedFactors (ne_bot_of_le_ne_bot hI h) hI).1 (dvd_iff_le.2 h)) _ #align count_le_of_ideal_ge count_le_of_ideal_ge theorem sup_eq_prod_inf_factors (hI : I ≠ ⊥) (hJ : J ≠ ⊥) : I ⊔ J = (normalizedFactors I ∩ normalizedFactors J).prod := by have H : normalizedFactors (normalizedFactors I ∩ normalizedFactors J).prod = normalizedFactors I ∩ normalizedFactors J := by apply normalizedFactors_prod_of_prime intro p hp rw [mem_inter] at hp exact prime_of_normalized_factor p hp.left have := Multiset.prod_ne_zero_of_prime (normalizedFactors I ∩ normalizedFactors J) fun _ h => prime_of_normalized_factor _ (Multiset.mem_inter.1 h).1 apply le_antisymm · rw [sup_le_iff, ← dvd_iff_le, ← dvd_iff_le] constructor · rw [dvd_iff_normalizedFactors_le_normalizedFactors this hI, H] exact inf_le_left · rw [dvd_iff_normalizedFactors_le_normalizedFactors this hJ, H] exact inf_le_right · rw [← dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors, normalizedFactors_prod_of_prime, le_iff_count] · intro a rw [Multiset.count_inter] exact le_min (count_le_of_ideal_ge le_sup_left hI a) (count_le_of_ideal_ge le_sup_right hJ a) · intro p hp rw [mem_inter] at hp exact prime_of_normalized_factor p hp.left · exact ne_bot_of_le_ne_bot hI le_sup_left · exact this #align sup_eq_prod_inf_factors sup_eq_prod_inf_factors theorem irreducible_pow_sup (hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ) : J ^ n ⊔ I = J ^ min ((normalizedFactors I).count J) n := by rw [sup_eq_prod_inf_factors (pow_ne_zero n hJ.ne_zero) hI, min_comm, normalizedFactors_of_irreducible_pow hJ, normalize_eq J, replicate_inter, prod_replicate] #align irreducible_pow_sup irreducible_pow_sup theorem irreducible_pow_sup_of_le (hJ : Irreducible J) (n : ℕ) (hn : ↑n ≤ multiplicity J I) : J ^ n ⊔ I = J ^ n := by by_cases hI : I = ⊥ · simp_all rw [irreducible_pow_sup hI hJ, min_eq_right] rwa [multiplicity_eq_count_normalizedFactors hJ hI, PartENat.coe_le_coe, normalize_eq J] at hn #align irreducible_pow_sup_of_le irreducible_pow_sup_of_le theorem irreducible_pow_sup_of_ge (hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ) (hn : multiplicity J I ≤ n) : J ^ n ⊔ I = J ^ (multiplicity J I).get (PartENat.dom_of_le_natCast hn) := by rw [irreducible_pow_sup hI hJ, min_eq_left] · congr rw [← PartENat.natCast_inj, PartENat.natCast_get, multiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J] · rwa [multiplicity_eq_count_normalizedFactors hJ hI, PartENat.coe_le_coe, normalize_eq J] at hn #align irreducible_pow_sup_of_ge irreducible_pow_sup_of_ge end IsDedekindDomain /-! ### Height one spectrum of a Dedekind domain If `R` is a Dedekind domain of Krull dimension 1, the maximal ideals of `R` are exactly its nonzero prime ideals. We define `HeightOneSpectrum` and provide lemmas to recover the facts that prime ideals of height one are prime and irreducible. -/ namespace IsDedekindDomain variable [IsDedekindDomain R] /-- The height one prime spectrum of a Dedekind domain `R` is the type of nonzero prime ideals of `R`. Note that this equals the maximal spectrum if `R` has Krull dimension 1. -/ -- Porting note(#5171): removed `has_nonempty_instance`, linter doesn't exist yet @[ext, nolint unusedArguments] structure HeightOneSpectrum where asIdeal : Ideal R isPrime : asIdeal.IsPrime ne_bot : asIdeal ≠ ⊥ #align is_dedekind_domain.height_one_spectrum IsDedekindDomain.HeightOneSpectrum attribute [instance] HeightOneSpectrum.isPrime variable (v : HeightOneSpectrum R) {R} namespace HeightOneSpectrum instance isMaximal : v.asIdeal.IsMaximal := v.isPrime.isMaximal v.ne_bot #align is_dedekind_domain.height_one_spectrum.is_maximal IsDedekindDomain.HeightOneSpectrum.isMaximal theorem prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime #align is_dedekind_domain.height_one_spectrum.prime IsDedekindDomain.HeightOneSpectrum.prime theorem irreducible : Irreducible v.asIdeal := UniqueFactorizationMonoid.irreducible_iff_prime.mpr v.prime #align is_dedekind_domain.height_one_spectrum.irreducible IsDedekindDomain.HeightOneSpectrum.irreducible theorem associates_irreducible : Irreducible <| Associates.mk v.asIdeal := Associates.irreducible_mk.mpr v.irreducible #align is_dedekind_domain.height_one_spectrum.associates_irreducible IsDedekindDomain.HeightOneSpectrum.associates_irreducible /-- An equivalence between the height one and maximal spectra for rings of Krull dimension 1. -/ def equivMaximalSpectrum (hR : ¬IsField R) : HeightOneSpectrum R ≃ MaximalSpectrum R where toFun v := ⟨v.asIdeal, v.isPrime.isMaximal v.ne_bot⟩ invFun v := ⟨v.asIdeal, v.IsMaximal.isPrime, Ring.ne_bot_of_isMaximal_of_not_isField v.IsMaximal hR⟩ left_inv := fun ⟨_, _, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl #align is_dedekind_domain.height_one_spectrum.equiv_maximal_spectrum IsDedekindDomain.HeightOneSpectrum.equivMaximalSpectrum variable (R) /-- A Dedekind domain is equal to the intersection of its localizations at all its height one non-zero prime ideals viewed as subalgebras of its field of fractions. -/ theorem iInf_localization_eq_bot [Algebra R K] [hK : IsFractionRing R K] : (⨅ v : HeightOneSpectrum R, Localization.subalgebra.ofField K _ v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by ext x rw [Algebra.mem_iInf] constructor on_goal 1 => by_cases hR : IsField R · rcases Function.bijective_iff_has_inverse.mp (IsField.localization_map_bijective (Rₘ := K) (flip nonZeroDivisors.ne_zero rfl : 0 ∉ R⁰) hR) with ⟨algebra_map_inv, _, algebra_map_right_inv⟩ exact fun _ => Algebra.mem_bot.mpr ⟨algebra_map_inv x, algebra_map_right_inv x⟩ all_goals rw [← MaximalSpectrum.iInf_localization_eq_bot, Algebra.mem_iInf] · exact fun hx ⟨v, hv⟩ => hx ((equivMaximalSpectrum hR).symm ⟨v, hv⟩) · exact fun hx ⟨v, hv, hbot⟩ => hx ⟨v, hv.isMaximal hbot⟩ #align is_dedekind_domain.height_one_spectrum.infi_localization_eq_bot IsDedekindDomain.HeightOneSpectrum.iInf_localization_eq_bot end HeightOneSpectrum end IsDedekindDomain section open Ideal variable {R A} variable [IsDedekindDomain A] {I : Ideal R} {J : Ideal A} /-- The map from ideals of `R` dividing `I` to the ideals of `A` dividing `J` induced by a homomorphism `f : R/I →+* A/J` -/ @[simps] -- Porting note: use `Subtype` instead of `Set` to make linter happy def idealFactorsFunOfQuotHom {f : R ⧸ I →+* A ⧸ J} (hf : Function.Surjective f) : {p : Ideal R // p ∣ I} →o {p : Ideal A // p ∣ J} where toFun X := ⟨comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)), by have : RingHom.ker (Ideal.Quotient.mk J) ≤ comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)) := ker_le_comap (Ideal.Quotient.mk J) rw [mk_ker] at this exact dvd_iff_le.mpr this⟩ monotone' := by rintro ⟨X, hX⟩ ⟨Y, hY⟩ h rw [← Subtype.coe_le_coe, Subtype.coe_mk, Subtype.coe_mk] at h ⊢ rw [Subtype.coe_mk, comap_le_comap_iff_of_surjective (Ideal.Quotient.mk J) Quotient.mk_surjective, map_le_iff_le_comap, Subtype.coe_mk, comap_map_of_surjective _ hf (map (Ideal.Quotient.mk I) Y)] suffices map (Ideal.Quotient.mk I) X ≤ map (Ideal.Quotient.mk I) Y by exact le_sup_of_le_left this rwa [map_le_iff_le_comap, comap_map_of_surjective (Ideal.Quotient.mk I) Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot, mk_ker, sup_eq_left.mpr <| le_of_dvd hY] #align ideal_factors_fun_of_quot_hom idealFactorsFunOfQuotHom #align ideal_factors_fun_of_quot_hom_coe_coe idealFactorsFunOfQuotHom_coe_coe @[simp] theorem idealFactorsFunOfQuotHom_id : idealFactorsFunOfQuotHom (RingHom.id (A ⧸ J)).surjective = OrderHom.id := OrderHom.ext _ _ (funext fun X => by simp only [idealFactorsFunOfQuotHom, map_id, OrderHom.coe_mk, OrderHom.id_coe, id, comap_map_of_surjective (Ideal.Quotient.mk J) Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot (Ideal.Quotient.mk J), mk_ker, sup_eq_left.mpr (dvd_iff_le.mp X.prop), Subtype.coe_eta]) #align ideal_factors_fun_of_quot_hom_id idealFactorsFunOfQuotHom_id variable {B : Type*} [CommRing B] [IsDedekindDomain B] {L : Ideal B} theorem idealFactorsFunOfQuotHom_comp {f : R ⧸ I →+* A ⧸ J} {g : A ⧸ J →+* B ⧸ L} (hf : Function.Surjective f) (hg : Function.Surjective g) : (idealFactorsFunOfQuotHom hg).comp (idealFactorsFunOfQuotHom hf) = idealFactorsFunOfQuotHom (show Function.Surjective (g.comp f) from hg.comp hf) := by refine OrderHom.ext _ _ (funext fun x => ?_) rw [idealFactorsFunOfQuotHom, idealFactorsFunOfQuotHom, OrderHom.comp_coe, OrderHom.coe_mk, OrderHom.coe_mk, Function.comp_apply, idealFactorsFunOfQuotHom, OrderHom.coe_mk, Subtype.mk_eq_mk, Subtype.coe_mk, map_comap_of_surjective (Ideal.Quotient.mk J) Quotient.mk_surjective, map_map] #align ideal_factors_fun_of_quot_hom_comp idealFactorsFunOfQuotHom_comp variable [IsDedekindDomain R] (f : R ⧸ I ≃+* A ⧸ J) /-- The bijection between ideals of `R` dividing `I` and the ideals of `A` dividing `J` induced by an isomorphism `f : R/I ≅ A/J`. -/ -- @[simps] -- Porting note: simpNF complains about the lemmas generated by simps def idealFactorsEquivOfQuotEquiv : { p : Ideal R | p ∣ I } ≃o { p : Ideal A | p ∣ J } := by have f_surj : Function.Surjective (f : R ⧸ I →+* A ⧸ J) := f.surjective have fsym_surj : Function.Surjective (f.symm : A ⧸ J →+* R ⧸ I) := f.symm.surjective refine OrderIso.ofHomInv (idealFactorsFunOfQuotHom f_surj) (idealFactorsFunOfQuotHom fsym_surj) ?_ ?_ · have := idealFactorsFunOfQuotHom_comp fsym_surj f_surj simp only [RingEquiv.comp_symm, idealFactorsFunOfQuotHom_id] at this rw [← this, OrderHom.coe_eq, OrderHom.coe_eq] · have := idealFactorsFunOfQuotHom_comp f_surj fsym_surj simp only [RingEquiv.symm_comp, idealFactorsFunOfQuotHom_id] at this rw [← this, OrderHom.coe_eq, OrderHom.coe_eq] #align ideal_factors_equiv_of_quot_equiv idealFactorsEquivOfQuotEquiv theorem idealFactorsEquivOfQuotEquiv_symm : (idealFactorsEquivOfQuotEquiv f).symm = idealFactorsEquivOfQuotEquiv f.symm := rfl #align ideal_factors_equiv_of_quot_equiv_symm idealFactorsEquivOfQuotEquiv_symm theorem idealFactorsEquivOfQuotEquiv_is_dvd_iso {L M : Ideal R} (hL : L ∣ I) (hM : M ∣ I) : (idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ : Ideal A) ∣ idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ↔ L ∣ M := by suffices idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ≤ idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ ↔ (⟨M, hM⟩ : { p : Ideal R | p ∣ I }) ≤ ⟨L, hL⟩ by rw [dvd_iff_le, dvd_iff_le, Subtype.coe_le_coe, this, Subtype.mk_le_mk] exact (idealFactorsEquivOfQuotEquiv f).le_iff_le #align ideal_factors_equiv_of_quot_equiv_is_dvd_iso idealFactorsEquivOfQuotEquiv_is_dvd_iso open UniqueFactorizationMonoid variable [DecidableEq (Ideal R)] [DecidableEq (Ideal A)] theorem idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors (hJ : J ≠ ⊥) {L : Ideal R} (hL : L ∈ normalizedFactors I) : ↑(idealFactorsEquivOfQuotEquiv f ⟨L, dvd_of_mem_normalizedFactors hL⟩) ∈ normalizedFactors J := by have hI : I ≠ ⊥ := by intro hI rw [hI, bot_eq_zero, normalizedFactors_zero, ← Multiset.empty_eq_zero] at hL exact Finset.not_mem_empty _ hL refine mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors hI hJ hL (d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_ rintro ⟨l, hl⟩ ⟨l', hl'⟩ rw [Subtype.coe_mk, Subtype.coe_mk] apply idealFactorsEquivOfQuotEquiv_is_dvd_iso f #align ideal_factors_equiv_of_quot_equiv_mem_normalized_factors_of_mem_normalized_factors idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors /-- The bijection between the sets of normalized factors of I and J induced by a ring isomorphism `f : R/I ≅ A/J`. -/ -- @[simps apply] -- Porting note: simpNF complains about the lemmas generated by simps def normalizedFactorsEquivOfQuotEquiv (hI : I ≠ ⊥) (hJ : J ≠ ⊥) : { L : Ideal R | L ∈ normalizedFactors I } ≃ { M : Ideal A | M ∈ normalizedFactors J } where toFun j := ⟨idealFactorsEquivOfQuotEquiv f ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩, idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f hJ j.prop⟩ invFun j := ⟨(idealFactorsEquivOfQuotEquiv f).symm ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩, by rw [idealFactorsEquivOfQuotEquiv_symm] exact idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f.symm hI j.prop⟩ left_inv := fun ⟨j, hj⟩ => by simp right_inv := fun ⟨j, hj⟩ => by simp -- This used to be the end of the proof before leanprover/lean4#2644 erw [OrderIso.apply_symm_apply] #align normalized_factors_equiv_of_quot_equiv normalizedFactorsEquivOfQuotEquiv @[simp] theorem normalizedFactorsEquivOfQuotEquiv_symm (hI : I ≠ ⊥) (hJ : J ≠ ⊥) : (normalizedFactorsEquivOfQuotEquiv f hI hJ).symm = normalizedFactorsEquivOfQuotEquiv f.symm hJ hI := rfl #align normalized_factors_equiv_of_quot_equiv_symm normalizedFactorsEquivOfQuotEquiv_symm variable [DecidableRel ((· ∣ ·) : Ideal R → Ideal R → Prop)] variable [DecidableRel ((· ∣ ·) : Ideal A → Ideal A → Prop)] /-- The map `normalizedFactorsEquivOfQuotEquiv` preserves multiplicities. -/
Mathlib/RingTheory/DedekindDomain/Ideal.lean
1,188
1,194
theorem normalizedFactorsEquivOfQuotEquiv_multiplicity_eq_multiplicity (hI : I ≠ ⊥) (hJ : J ≠ ⊥) (L : Ideal R) (hL : L ∈ normalizedFactors I) : multiplicity (↑(normalizedFactorsEquivOfQuotEquiv f hI hJ ⟨L, hL⟩)) J = multiplicity L I := by
rw [normalizedFactorsEquivOfQuotEquiv, Equiv.coe_fn_mk, Subtype.coe_mk] refine multiplicity_factor_dvd_iso_eq_multiplicity_of_mem_normalizedFactors hI hJ hL (d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_ exact fun ⟨l, hl⟩ ⟨l', hl'⟩ => idealFactorsEquivOfQuotEquiv_is_dvd_iso f hl hl'
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.BigOperators.NatAntidiagonal import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Nat.Choose.Sum import Mathlib.RingTheory.PowerSeries.Basic #align_import ring_theory.power_series.well_known from "leanprover-community/mathlib"@"8199f6717c150a7fe91c4534175f4cf99725978f" /-! # Definition of well-known power series In this file we define the following power series: * `PowerSeries.invUnitsSub`: given `u : Rˣ`, this is the series for `1 / (u - x)`. It is given by `∑ n, x ^ n /ₚ u ^ (n + 1)`. * `PowerSeries.invOneSubPow`: given a commutative ring `S` and a number `d : ℕ`, `PowerSeries.invOneSubPow d : S⟦X⟧ˣ` is the power series `∑ n, Nat.choose (d + n) d` whose multiplicative inverse is `(1 - X) ^ (d + 1)`. * `PowerSeries.sin`, `PowerSeries.cos`, `PowerSeries.exp` : power series for sin, cosine, and exponential functions. -/ namespace PowerSeries section Ring variable {R S : Type*} [Ring R] [Ring S] /-- The power series for `1 / (u - x)`. -/ def invUnitsSub (u : Rˣ) : PowerSeries R := mk fun n => 1 /ₚ u ^ (n + 1) #align power_series.inv_units_sub PowerSeries.invUnitsSub @[simp] theorem coeff_invUnitsSub (u : Rˣ) (n : ℕ) : coeff R n (invUnitsSub u) = 1 /ₚ u ^ (n + 1) := coeff_mk _ _ #align power_series.coeff_inv_units_sub PowerSeries.coeff_invUnitsSub @[simp] theorem constantCoeff_invUnitsSub (u : Rˣ) : constantCoeff R (invUnitsSub u) = 1 /ₚ u := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_invUnitsSub, zero_add, pow_one] #align power_series.constant_coeff_inv_units_sub PowerSeries.constantCoeff_invUnitsSub @[simp] theorem invUnitsSub_mul_X (u : Rˣ) : invUnitsSub u * X = invUnitsSub u * C R u - 1 := by ext (_ | n) · simp · simp [n.succ_ne_zero, pow_succ'] set_option linter.uppercaseLean3 false in #align power_series.inv_units_sub_mul_X PowerSeries.invUnitsSub_mul_X @[simp] theorem invUnitsSub_mul_sub (u : Rˣ) : invUnitsSub u * (C R u - X) = 1 := by simp [mul_sub, sub_sub_cancel] #align power_series.inv_units_sub_mul_sub PowerSeries.invUnitsSub_mul_sub theorem map_invUnitsSub (f : R →+* S) (u : Rˣ) : map f (invUnitsSub u) = invUnitsSub (Units.map (f : R →* S) u) := by ext simp only [← map_pow, coeff_map, coeff_invUnitsSub, one_divp] rfl #align power_series.map_inv_units_sub PowerSeries.map_invUnitsSub end Ring section invOneSubPow variable {S : Type*} [CommRing S] (d : ℕ) /-- (1 + X + X^2 + ...) * (1 - X) = 1. Note that the power series `1 + X + X^2 + ...` is written as `mk 1` where `1` is the constant function so that `mk 1` is the power series with all coefficients equal to one. -/ theorem mk_one_mul_one_sub_eq_one : (mk 1 : S⟦X⟧) * (1 - X) = 1 := by rw [mul_comm, ext_iff] intro n cases n with | zero => simp | succ n => simp [sub_mul] /-- Note that `mk 1` is the constant function `1` so the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `(1 + X + X^2 + ... : S⟦X⟧) ^ (d + 1)` is equal to the power series `mk fun n => Nat.choose (d + n) d : S⟦X⟧`. -/ theorem mk_one_pow_eq_mk_choose_add : (mk 1 : S⟦X⟧) ^ (d + 1) = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := by induction d with | zero => ext; simp | succ d hd => ext n rw [pow_add, hd, pow_one, mul_comm, coeff_mul] simp_rw [coeff_mk, Pi.one_apply, one_mul] norm_cast rw [Finset.sum_antidiagonal_choose_add, ← Nat.choose_succ_succ, Nat.succ_eq_add_one, add_right_comm] /-- The power series `mk fun n => Nat.choose (d + n) d`, whose multiplicative inverse is `(1 - X) ^ (d + 1)`. -/ noncomputable def invOneSubPow : S⟦X⟧ˣ where val := mk fun n => Nat.choose (d + n) d inv := (1 - X) ^ (d + 1) val_inv := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mk_one_mul_one_sub_eq_one, one_pow] inv_val := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mul_comm, mk_one_mul_one_sub_eq_one, one_pow] theorem invOneSubPow_val_eq_mk_choose_add : (invOneSubPow d).val = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := rfl theorem invOneSubPow_val_zero_eq_invUnitSub_one : (invOneSubPow 0).val = invUnitsSub (1 : Sˣ) := by simp [invOneSubPow, invUnitsSub] /-- The theorem `PowerSeries.mk_one_mul_one_sub_eq_one` implies that `1 - X` is a unit in `S⟦X⟧` whose inverse is the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `PowerSeries.invOneSubPow d` is equal to `(1 - X)⁻¹ ^ (d + 1)`. -/ theorem invOneSubPow_eq_inv_one_sub_pow : invOneSubPow d = (Units.mkOfMulEqOne (1 - X) (mk 1 : S⟦X⟧) <| Eq.trans (mul_comm _ _) mk_one_mul_one_sub_eq_one)⁻¹ ^ (d + 1) := by rw [inv_pow] exact (DivisionMonoid.inv_eq_of_mul _ (invOneSubPow d) <| by rw [← Units.val_eq_one, Units.val_mul, Units.val_pow_eq_pow_val] exact (invOneSubPow d).inv_val).symm theorem invOneSubPow_inv_eq_one_sub_pow : (invOneSubPow d).inv = (1 - X : S⟦X⟧) ^ (d + 1) := rfl end invOneSubPow section Field variable (A A' : Type*) [Ring A] [Ring A'] [Algebra ℚ A] [Algebra ℚ A'] open Nat /-- Power series for the exponential function at zero. -/ def exp : PowerSeries A := mk fun n => algebraMap ℚ A (1 / n !) #align power_series.exp PowerSeries.exp /-- Power series for the sine function at zero. -/ def sin : PowerSeries A := mk fun n => if Even n then 0 else algebraMap ℚ A ((-1) ^ (n / 2) / n !) #align power_series.sin PowerSeries.sin /-- Power series for the cosine function at zero. -/ def cos : PowerSeries A := mk fun n => if Even n then algebraMap ℚ A ((-1) ^ (n / 2) / n !) else 0 #align power_series.cos PowerSeries.cos variable {A A'} [Ring A] [Ring A'] [Algebra ℚ A] [Algebra ℚ A'] (n : ℕ) (f : A →+* A') @[simp] theorem coeff_exp : coeff A n (exp A) = algebraMap ℚ A (1 / n !) := coeff_mk _ _ #align power_series.coeff_exp PowerSeries.coeff_exp @[simp] theorem constantCoeff_exp : constantCoeff A (exp A) = 1 := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_exp] simp #align power_series.constant_coeff_exp PowerSeries.constantCoeff_exp set_option linter.deprecated false in @[simp]
Mathlib/RingTheory/PowerSeries/WellKnown.lean
181
182
theorem coeff_sin_bit0 : coeff A (bit0 n) (sin A) = 0 := by
rw [sin, coeff_mk, if_pos (even_bit0 n)]
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.InvariantBasisNumber #align_import linear_algebra.dimension from "leanprover-community/mathlib"@"47a5f8186becdbc826190ced4312f8199f9db6a5" /-! # Lemmas about rank and finrank in rings satisfying strong rank condition. ## Main statements For modules over rings satisfying the rank condition * `Basis.le_span`: the cardinality of a basis is bounded by the cardinality of any spanning set For modules over rings satisfying the strong rank condition * `linearIndependent_le_span`: For any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. * `linearIndependent_le_basis`: If `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. For modules over rings with invariant basis number (including all commutative rings and all noetherian rings) * `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same cardinality. -/ noncomputable section universe u v w w' variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M] variable {ι : Type w} {ι' : Type w'} open Cardinal Basis Submodule Function Set attribute [local instance] nontrivial_of_invariantBasisNumber section InvariantBasisNumber variable [InvariantBasisNumber R] /-- The dimension theorem: if `v` and `v'` are two bases, their index types have the same cardinalities. -/ theorem mk_eq_mk_of_basis (v : Basis ι R M) (v' : Basis ι' R M) : Cardinal.lift.{w'} #ι = Cardinal.lift.{w} #ι' := by classical haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite ι · -- `v` is a finite basis, so by `basis_finite_of_finite_spans` so is `v'`. -- haveI : Finite (range v) := Set.finite_range v haveI := basis_finite_of_finite_spans _ (Set.finite_range v) v.span_eq v' cases nonempty_fintype ι' -- We clean up a little: rw [Cardinal.mk_fintype, Cardinal.mk_fintype] simp only [Cardinal.lift_natCast, Cardinal.natCast_inj] -- Now we can use invariant basis number to show they have the same cardinality. apply card_eq_of_linearEquiv R exact (Finsupp.linearEquivFunOnFinite R R ι).symm.trans v.repr.symm ≪≫ₗ v'.repr ≪≫ₗ Finsupp.linearEquivFunOnFinite R R ι' · -- `v` is an infinite basis, -- so by `infinite_basis_le_maximal_linearIndependent`, `v'` is at least as big, -- and then applying `infinite_basis_le_maximal_linearIndependent` again -- we see they have the same cardinality. have w₁ := infinite_basis_le_maximal_linearIndependent' v _ v'.linearIndependent v'.maximal rcases Cardinal.lift_mk_le'.mp w₁ with ⟨f⟩ haveI : Infinite ι' := Infinite.of_injective f f.2 have w₂ := infinite_basis_le_maximal_linearIndependent' v' _ v.linearIndependent v.maximal exact le_antisymm w₁ w₂ #align mk_eq_mk_of_basis mk_eq_mk_of_basis /-- Given two bases indexed by `ι` and `ι'` of an `R`-module, where `R` satisfies the invariant basis number property, an equiv `ι ≃ ι'`. -/ def Basis.indexEquiv (v : Basis ι R M) (v' : Basis ι' R M) : ι ≃ ι' := (Cardinal.lift_mk_eq'.1 <| mk_eq_mk_of_basis v v').some #align basis.index_equiv Basis.indexEquiv theorem mk_eq_mk_of_basis' {ι' : Type w} (v : Basis ι R M) (v' : Basis ι' R M) : #ι = #ι' := Cardinal.lift_inj.1 <| mk_eq_mk_of_basis v v' #align mk_eq_mk_of_basis' mk_eq_mk_of_basis' end InvariantBasisNumber section RankCondition variable [RankCondition R] /-- An auxiliary lemma for `Basis.le_span`. If `R` satisfies the rank condition, then for any finite basis `b : Basis ι R M`, and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem Basis.le_span'' {ι : Type*} [Fintype ι] (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : Fintype.card ι ≤ Fintype.card w := by -- We construct a surjective linear map `(w → R) →ₗ[R] (ι → R)`, -- by expressing a linear combination in `w` as a linear combination in `ι`. fapply card_le_of_surjective' R · exact b.repr.toLinearMap.comp (Finsupp.total w M R (↑)) · apply Surjective.comp (g := b.repr.toLinearMap) · apply LinearEquiv.surjective rw [← LinearMap.range_eq_top, Finsupp.range_total] simpa using s #align basis.le_span'' Basis.le_span'' /-- Another auxiliary lemma for `Basis.le_span`, which does not require assuming the basis is finite, but still assumes we have a finite spanning set. -/ theorem basis_le_span' {ι : Type*} (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by haveI := nontrivial_of_invariantBasisNumber R haveI := basis_finite_of_finite_spans w (toFinite _) s b cases nonempty_fintype ι rw [Cardinal.mk_fintype ι] simp only [Cardinal.natCast_le] exact Basis.le_span'' b s #align basis_le_span' basis_le_span' -- Note that if `R` satisfies the strong rank condition, -- this also follows from `linearIndependent_le_span` below. /-- If `R` satisfies the rank condition, then the cardinality of any basis is bounded by the cardinality of any spanning set. -/ theorem Basis.le_span {J : Set M} (v : Basis ι R M) (hJ : span R J = ⊤) : #(range v) ≤ #J := by haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite J · rw [← Cardinal.lift_le, Cardinal.mk_range_eq_of_injective v.injective, Cardinal.mk_fintype J] convert Cardinal.lift_le.{v}.2 (basis_le_span' v hJ) simp · let S : J → Set ι := fun j => ↑(v.repr j).support let S' : J → Set M := fun j => v '' S j have hs : range v ⊆ ⋃ j, S' j := by intro b hb rcases mem_range.1 hb with ⟨i, hi⟩ have : span R J ≤ comap v.repr.toLinearMap (Finsupp.supported R R (⋃ j, S j)) := span_le.2 fun j hj x hx => ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩ rw [hJ] at this replace : v.repr (v i) ∈ Finsupp.supported R R (⋃ j, S j) := this trivial rw [v.repr_self, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ one_ne_zero] at this · subst b rcases mem_iUnion.1 (this (Finset.mem_singleton_self _)) with ⟨j, hj⟩ exact mem_iUnion.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ refine le_of_not_lt fun IJ => ?_ suffices #(⋃ j, S' j) < #(range v) by exact not_le_of_lt this ⟨Set.embeddingOfSubset _ _ hs⟩ refine lt_of_le_of_lt (le_trans Cardinal.mk_iUnion_le_sum_mk (Cardinal.sum_le_sum _ (fun _ => ℵ₀) ?_)) ?_ · exact fun j => (Cardinal.lt_aleph0_of_finite _).le · simpa #align basis.le_span Basis.le_span end RankCondition section StrongRankCondition variable [StrongRankCondition R] open Submodule -- An auxiliary lemma for `linearIndependent_le_span'`, -- with the additional assumption that the linearly independent family is finite. theorem linearIndependent_le_span_aux' {ι : Type*} [Fintype ι] (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : Fintype.card ι ≤ Fintype.card w := by -- We construct an injective linear map `(ι → R) →ₗ[R] (w → R)`, -- by thinking of `f : ι → R` as a linear combination of the finite family `v`, -- and expressing that (using the axiom of choice) as a linear combination over `w`. -- We can do this linearly by constructing the map on a basis. fapply card_le_of_injective' R · apply Finsupp.total exact fun i => Span.repr R w ⟨v i, s (mem_range_self i)⟩ · intro f g h apply_fun Finsupp.total w M R (↑) at h simp only [Finsupp.total_total, Submodule.coe_mk, Span.finsupp_total_repr] at h rw [← sub_eq_zero, ← LinearMap.map_sub] at h exact sub_eq_zero.mp (linearIndependent_iff.mp i _ h) #align linear_independent_le_span_aux' linearIndependent_le_span_aux' /-- If `R` satisfies the strong rank condition, then any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, is itself finite. -/ lemma LinearIndependent.finite_of_le_span_finite {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Finite w] (s : range v ≤ span R w) : Finite ι := letI := Fintype.ofFinite w Fintype.finite <| fintypeOfFinsetCardLe (Fintype.card w) fun t => by let v' := fun x : (t : Set ι) => v x have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have s' : range v' ≤ span R w := (range_comp_subset_range _ _).trans s simpa using linearIndependent_le_span_aux' v' i' w s' #align linear_independent_fintype_of_le_span_fintype LinearIndependent.finite_of_le_span_finite /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span' {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : #ι ≤ Fintype.card w := by haveI : Finite ι := i.finite_of_le_span_finite v w s letI := Fintype.ofFinite ι rw [Cardinal.mk_fintype] simp only [Cardinal.natCast_le] exact linearIndependent_le_span_aux' v i w s #align linear_independent_le_span' linearIndependent_le_span' /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by apply linearIndependent_le_span' v i w rw [s] exact le_top #align linear_independent_le_span linearIndependent_le_span /-- A version of `linearIndependent_le_span` for `Finset`. -/ theorem linearIndependent_le_span_finset {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Finset M) (s : span R (w : Set M) = ⊤) : #ι ≤ w.card := by simpa only [Finset.coe_sort_coe, Fintype.card_coe] using linearIndependent_le_span v i w s #align linear_independent_le_span_finset linearIndependent_le_span_finset /-- An auxiliary lemma for `linearIndependent_le_basis`: we handle the case where the basis `b` is infinite. -/ theorem linearIndependent_le_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≤ #ι := by classical by_contra h rw [not_le, ← Cardinal.mk_finset_of_infinite ι] at h let Φ := fun k : κ => (b.repr (v k)).support obtain ⟨s, w : Infinite ↑(Φ ⁻¹' {s})⟩ := Cardinal.exists_infinite_fiber Φ h (by infer_instance) let v' := fun k : Φ ⁻¹' {s} => v k have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have w' : Finite (Φ ⁻¹' {s}) := by apply i'.finite_of_le_span_finite v' (s.image b) rintro m ⟨⟨p, ⟨rfl⟩⟩, rfl⟩ simp only [SetLike.mem_coe, Subtype.coe_mk, Finset.coe_image] apply Basis.mem_span_repr_support exact w.false #align linear_independent_le_infinite_basis linearIndependent_le_infinite_basis /-- Over any ring `R` satisfying the strong rank condition, if `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. -/
Mathlib/LinearAlgebra/Dimension/StrongRankCondition.lean
266
276
theorem linearIndependent_le_basis {ι : Type w} (b : Basis ι R M) {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≤ #ι := by
classical -- We split into cases depending on whether `ι` is infinite. cases fintypeOrInfinite ι · rw [Cardinal.mk_fintype ι] -- When `ι` is finite, we have `linearIndependent_le_span`, haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R rw [Fintype.card_congr (Equiv.ofInjective b b.injective)] exact linearIndependent_le_span v i (range b) b.span_eq · -- and otherwise we have `linearIndependent_le_infinite_basis`. exact linearIndependent_le_infinite_basis b v i
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Ring.Action.Basic import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Algebra.Ring.InjSurj import Mathlib.GroupTheory.Congruence.Basic #align_import ring_theory.congruence from "leanprover-community/mathlib"@"2f39bcbc98f8255490f8d4562762c9467694c809" /-! # Congruence relations on rings This file defines congruence relations on rings, which extend `Con` and `AddCon` on monoids and additive monoids. Most of the time you likely want to use the `Ideal.Quotient` API that is built on top of this. ## Main Definitions * `RingCon R`: the type of congruence relations respecting `+` and `*`. * `RingConGen r`: the inductively defined smallest ring congruence relation containing a given binary relation. ## TODO * Use this for `RingQuot` too. * Copy across more API from `Con` and `AddCon` in `GroupTheory/Congruence.lean`. -/ /-- A congruence relation on a type with an addition and multiplication is an equivalence relation which preserves both. -/ structure RingCon (R : Type*) [Add R] [Mul R] extends Con R, AddCon R where #align ring_con RingCon /-- The induced multiplicative congruence from a `RingCon`. -/ add_decl_doc RingCon.toCon /-- The induced additive congruence from a `RingCon`. -/ add_decl_doc RingCon.toAddCon variable {α R : Type*} /-- The inductively defined smallest ring congruence relation containing a given binary relation. -/ inductive RingConGen.Rel [Add R] [Mul R] (r : R → R → Prop) : R → R → Prop | of : ∀ x y, r x y → RingConGen.Rel r x y | refl : ∀ x, RingConGen.Rel r x x | symm : ∀ {x y}, RingConGen.Rel r x y → RingConGen.Rel r y x | trans : ∀ {x y z}, RingConGen.Rel r x y → RingConGen.Rel r y z → RingConGen.Rel r x z | add : ∀ {w x y z}, RingConGen.Rel r w x → RingConGen.Rel r y z → RingConGen.Rel r (w + y) (x + z) | mul : ∀ {w x y z}, RingConGen.Rel r w x → RingConGen.Rel r y z → RingConGen.Rel r (w * y) (x * z) #align ring_con_gen.rel RingConGen.Rel /-- The inductively defined smallest ring congruence relation containing a given binary relation. -/ def ringConGen [Add R] [Mul R] (r : R → R → Prop) : RingCon R where r := RingConGen.Rel r iseqv := ⟨RingConGen.Rel.refl, @RingConGen.Rel.symm _ _ _ _, @RingConGen.Rel.trans _ _ _ _⟩ add' := RingConGen.Rel.add mul' := RingConGen.Rel.mul #align ring_con_gen ringConGen namespace RingCon section Basic variable [Add R] [Mul R] (c : RingCon R) -- Porting note: upgrade to `FunLike` /-- A coercion from a congruence relation to its underlying binary relation. -/ instance : FunLike (RingCon R) R (R → Prop) := { coe := fun c => c.r, coe_injective' := fun x y h => by rcases x with ⟨⟨x, _⟩, _⟩ rcases y with ⟨⟨y, _⟩, _⟩ congr! rw [Setoid.ext_iff,(show x.Rel = y.Rel from h)] simp} theorem rel_eq_coe : c.r = c := rfl #align ring_con.rel_eq_coe RingCon.rel_eq_coe @[simp] theorem toCon_coe_eq_coe : (c.toCon : R → R → Prop) = c := rfl protected theorem refl (x) : c x x := c.refl' x #align ring_con.refl RingCon.refl protected theorem symm {x y} : c x y → c y x := c.symm' #align ring_con.symm RingCon.symm protected theorem trans {x y z} : c x y → c y z → c x z := c.trans' #align ring_con.trans RingCon.trans protected theorem add {w x y z} : c w x → c y z → c (w + y) (x + z) := c.add' #align ring_con.add RingCon.add protected theorem mul {w x y z} : c w x → c y z → c (w * y) (x * z) := c.mul' #align ring_con.mul RingCon.mul instance : Inhabited (RingCon R) := ⟨ringConGen EmptyRelation⟩ @[simp] theorem rel_mk {s : Con R} {h a b} : RingCon.mk s h a b ↔ s a b := Iff.rfl /-- The map sending a congruence relation to its underlying binary relation is injective. -/ theorem ext' {c d : RingCon R} (H : ⇑c = ⇑d) : c = d := DFunLike.coe_injective H /-- Extensionality rule for congruence relations. -/ theorem ext {c d : RingCon R} (H : ∀ x y, c x y ↔ d x y) : c = d := ext' <| by ext; apply H end Basic section Quotient section Basic variable [Add R] [Mul R] (c : RingCon R) /-- Defining the quotient by a congruence relation of a type with addition and multiplication. -/ protected def Quotient := Quotient c.toSetoid #align ring_con.quotient RingCon.Quotient variable {c} /-- The morphism into the quotient by a congruence relation -/ @[coe] def toQuotient (r : R) : c.Quotient := @Quotient.mk'' _ c.toSetoid r variable (c) /-- Coercion from a type with addition and multiplication to its quotient by a congruence relation. See Note [use has_coe_t]. -/ instance : CoeTC R c.Quotient := ⟨toQuotient⟩ -- Lower the priority since it unifies with any quotient type. /-- The quotient by a decidable congruence relation has decidable equality. -/ instance (priority := 500) [_d : ∀ a b, Decidable (c a b)] : DecidableEq c.Quotient := inferInstanceAs (DecidableEq (Quotient c.toSetoid)) @[simp] theorem quot_mk_eq_coe (x : R) : Quot.mk c x = (x : c.Quotient) := rfl #align ring_con.quot_mk_eq_coe RingCon.quot_mk_eq_coe /-- Two elements are related by a congruence relation `c` iff they are represented by the same element of the quotient by `c`. -/ @[simp] protected theorem eq {a b : R} : (a : c.Quotient) = (b : c.Quotient) ↔ c a b := Quotient.eq'' #align ring_con.eq RingCon.eq end Basic /-! ### Basic notation The basic algebraic notation, `0`, `1`, `+`, `*`, `-`, `^`, descend naturally under the quotient -/ section Data section add_mul variable [Add R] [Mul R] (c : RingCon R) instance : Add c.Quotient := inferInstanceAs (Add c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_add (x y : R) : (↑(x + y) : c.Quotient) = ↑x + ↑y := rfl #align ring_con.coe_add RingCon.coe_add instance : Mul c.Quotient := inferInstanceAs (Mul c.toCon.Quotient) @[simp, norm_cast] theorem coe_mul (x y : R) : (↑(x * y) : c.Quotient) = ↑x * ↑y := rfl #align ring_con.coe_mul RingCon.coe_mul end add_mul section Zero variable [AddZeroClass R] [Mul R] (c : RingCon R) instance : Zero c.Quotient := inferInstanceAs (Zero c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_zero : (↑(0 : R) : c.Quotient) = 0 := rfl #align ring_con.coe_zero RingCon.coe_zero end Zero section One variable [Add R] [MulOneClass R] (c : RingCon R) instance : One c.Quotient := inferInstanceAs (One c.toCon.Quotient) @[simp, norm_cast] theorem coe_one : (↑(1 : R) : c.Quotient) = 1 := rfl #align ring_con.coe_one RingCon.coe_one end One section SMul variable [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] (c : RingCon R) instance : SMul α c.Quotient := inferInstanceAs (SMul α c.toCon.Quotient) @[simp, norm_cast] theorem coe_smul (a : α) (x : R) : (↑(a • x) : c.Quotient) = a • (x : c.Quotient) := rfl #align ring_con.coe_smul RingCon.coe_smul end SMul section NegSubZSMul variable [AddGroup R] [Mul R] (c : RingCon R) instance : Neg c.Quotient := inferInstanceAs (Neg c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_neg (x : R) : (↑(-x) : c.Quotient) = -x := rfl #align ring_con.coe_neg RingCon.coe_neg instance : Sub c.Quotient := inferInstanceAs (Sub c.toAddCon.Quotient) @[simp, norm_cast] theorem coe_sub (x y : R) : (↑(x - y) : c.Quotient) = x - y := rfl #align ring_con.coe_sub RingCon.coe_sub instance hasZSMul : SMul ℤ c.Quotient := inferInstanceAs (SMul ℤ c.toAddCon.Quotient) #align ring_con.has_zsmul RingCon.hasZSMul @[simp, norm_cast] theorem coe_zsmul (z : ℤ) (x : R) : (↑(z • x) : c.Quotient) = z • (x : c.Quotient) := rfl #align ring_con.coe_zsmul RingCon.coe_zsmul end NegSubZSMul section NSMul variable [AddMonoid R] [Mul R] (c : RingCon R) instance hasNSMul : SMul ℕ c.Quotient := inferInstanceAs (SMul ℕ c.toAddCon.Quotient) #align ring_con.has_nsmul RingCon.hasNSMul @[simp, norm_cast] theorem coe_nsmul (n : ℕ) (x : R) : (↑(n • x) : c.Quotient) = n • (x : c.Quotient) := rfl #align ring_con.coe_nsmul RingCon.coe_nsmul end NSMul section Pow variable [Add R] [Monoid R] (c : RingCon R) instance : Pow c.Quotient ℕ := inferInstanceAs (Pow c.toCon.Quotient ℕ) @[simp, norm_cast] theorem coe_pow (x : R) (n : ℕ) : (↑(x ^ n) : c.Quotient) = (x : c.Quotient) ^ n := rfl #align ring_con.coe_pow RingCon.coe_pow end Pow section NatCast variable [AddMonoidWithOne R] [Mul R] (c : RingCon R) instance : NatCast c.Quotient := ⟨fun n => ↑(n : R)⟩ @[simp, norm_cast] theorem coe_natCast (n : ℕ) : (↑(n : R) : c.Quotient) = n := rfl #align ring_con.coe_nat_cast RingCon.coe_natCast @[deprecated (since := "2024-04-17")] alias coe_nat_cast := coe_natCast end NatCast section IntCast variable [AddGroupWithOne R] [Mul R] (c : RingCon R) instance : IntCast c.Quotient := ⟨fun z => ↑(z : R)⟩ @[simp, norm_cast] theorem coe_intCast (n : ℕ) : (↑(n : R) : c.Quotient) = n := rfl #align ring_con.coe_int_cast RingCon.coe_intCast @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast end IntCast instance [Inhabited R] [Add R] [Mul R] (c : RingCon R) : Inhabited c.Quotient := ⟨↑(default : R)⟩ end Data /-! ### Algebraic structure The operations above on the quotient by `c : RingCon R` preserve the algebraic structure of `R`. -/ section Algebraic instance [NonUnitalNonAssocSemiring R] (c : RingCon R) : NonUnitalNonAssocSemiring c.Quotient := Function.Surjective.nonUnitalNonAssocSemiring _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [NonAssocSemiring R] (c : RingCon R) : NonAssocSemiring c.Quotient := Function.Surjective.nonAssocSemiring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [NonUnitalSemiring R] (c : RingCon R) : NonUnitalSemiring c.Quotient := Function.Surjective.nonUnitalSemiring _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [Semiring R] (c : RingCon R) : Semiring c.Quotient := Function.Surjective.semiring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [CommSemiring R] (c : RingCon R) : CommSemiring c.Quotient := Function.Surjective.commSemiring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [NonUnitalNonAssocRing R] (c : RingCon R) : NonUnitalNonAssocRing c.Quotient := Function.Surjective.nonUnitalNonAssocRing _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [NonAssocRing R] (c : RingCon R) : NonAssocRing c.Quotient := Function.Surjective.nonAssocRing _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl instance [NonUnitalRing R] (c : RingCon R) : NonUnitalRing c.Quotient := Function.Surjective.nonUnitalRing _ Quotient.surjective_Quotient_mk'' rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [Ring R] (c : RingCon R) : Ring c.Quotient := Function.Surjective.ring _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl instance [CommRing R] (c : RingCon R) : CommRing c.Quotient := Function.Surjective.commRing _ Quotient.surjective_Quotient_mk'' rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl instance isScalarTower_right [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] (c : RingCon R) : IsScalarTower α c.Quotient c.Quotient where smul_assoc _ := Quotient.ind₂' fun _ _ => congr_arg Quotient.mk'' <| smul_mul_assoc _ _ _ #align ring_con.is_scalar_tower_right RingCon.isScalarTower_right instance smulCommClass [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] [SMulCommClass α R R] (c : RingCon R) : SMulCommClass α c.Quotient c.Quotient where smul_comm _ := Quotient.ind₂' fun _ _ => congr_arg Quotient.mk'' <| (mul_smul_comm _ _ _).symm #align ring_con.smul_comm_class RingCon.smulCommClass instance smulCommClass' [Add R] [MulOneClass R] [SMul α R] [IsScalarTower α R R] [SMulCommClass R α R] (c : RingCon R) : SMulCommClass c.Quotient α c.Quotient := haveI := SMulCommClass.symm R α R SMulCommClass.symm _ _ _ #align ring_con.smul_comm_class' RingCon.smulCommClass' instance [Monoid α] [NonAssocSemiring R] [DistribMulAction α R] [IsScalarTower α R R] (c : RingCon R) : DistribMulAction α c.Quotient := { c.toCon.mulAction with smul_zero := fun _ => congr_arg toQuotient <| smul_zero _ smul_add := fun _ => Quotient.ind₂' fun _ _ => congr_arg toQuotient <| smul_add _ _ _ } instance [Monoid α] [Semiring R] [MulSemiringAction α R] [IsScalarTower α R R] (c : RingCon R) : MulSemiringAction α c.Quotient := { smul_one := fun _ => congr_arg toQuotient <| smul_one _ smul_mul := fun _ => Quotient.ind₂' fun _ _ => congr_arg toQuotient <| MulSemiringAction.smul_mul _ _ _ } end Algebraic /-- The natural homomorphism from a ring to its quotient by a congruence relation. -/ def mk' [NonAssocSemiring R] (c : RingCon R) : R →+* c.Quotient where toFun := toQuotient map_zero' := rfl map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl #align ring_con.mk' RingCon.mk' end Quotient /-! ### Lattice structure The API in this section is copied from `Mathlib/GroupTheory/Congruence.lean` -/ section Lattice variable [Add R] [Mul R] /-- For congruence relations `c, d` on a type `M` with multiplication and addition, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`. -/ instance : LE (RingCon R) where le c d := ∀ ⦃x y⦄, c x y → d x y /-- Definition of `≤` for congruence relations. -/ theorem le_def {c d : RingCon R} : c ≤ d ↔ ∀ {x y}, c x y → d x y := Iff.rfl /-- The infimum of a set of congruence relations on a given type with multiplication and addition. -/ instance : InfSet (RingCon R) where sInf S := { r := fun x y => ∀ c : RingCon R, c ∈ S → c x y iseqv := ⟨fun x c _hc => c.refl x, fun h c hc => c.symm <| h c hc, fun h1 h2 c hc => c.trans (h1 c hc) <| h2 c hc⟩ add' := fun h1 h2 c hc => c.add (h1 c hc) <| h2 c hc mul' := fun h1 h2 c hc => c.mul (h1 c hc) <| h2 c hc } /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation. -/ theorem sInf_toSetoid (S : Set (RingCon R)) : (sInf S).toSetoid = sInf ((·.toSetoid) '' S) := Setoid.ext' fun x y => ⟨fun h r ⟨c, hS, hr⟩ => by rw [← hr]; exact h c hS, fun h c hS => h c.toSetoid ⟨c, hS, rfl⟩⟩ /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation. -/ @[simp, norm_cast] theorem coe_sInf (S : Set (RingCon R)) : ⇑(sInf S) = sInf ((⇑) '' S) := by ext; simp only [sInf_image, iInf_apply, iInf_Prop_eq]; rfl @[simp, norm_cast]
Mathlib/RingTheory/Congruence.lean
470
471
theorem coe_iInf {ι : Sort*} (f : ι → RingCon R) : ⇑(iInf f) = ⨅ i, ⇑(f i) := by
rw [iInf, coe_sInf, ← Set.range_comp, sInf_range, Function.comp]
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Basic import Mathlib.Topology.MetricSpace.Thickening import Mathlib.Topology.MetricSpace.IsometricSMul #align_import analysis.normed.group.pointwise from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328" /-! # Properties of pointwise addition of sets in normed groups We explore the relationships between pointwise addition of sets in normed groups, and the norm. Notably, we show that the sum of bounded sets remain bounded. -/ open Metric Set Pointwise Topology variable {E : Type*} section SeminormedGroup variable [SeminormedGroup E] {ε δ : ℝ} {s t : Set E} {x y : E} -- note: we can't use `LipschitzOnWith.isBounded_image2` here without adding `[IsometricSMul E E]` @[to_additive] theorem Bornology.IsBounded.mul (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s * t) := by obtain ⟨Rs, hRs⟩ : ∃ R, ∀ x ∈ s, ‖x‖ ≤ R := hs.exists_norm_le' obtain ⟨Rt, hRt⟩ : ∃ R, ∀ x ∈ t, ‖x‖ ≤ R := ht.exists_norm_le' refine isBounded_iff_forall_norm_le'.2 ⟨Rs + Rt, ?_⟩ rintro z ⟨x, hx, y, hy, rfl⟩ exact norm_mul_le_of_le (hRs x hx) (hRt y hy) #align metric.bounded.mul Bornology.IsBounded.mul #align metric.bounded.add Bornology.IsBounded.add @[to_additive] theorem Bornology.IsBounded.of_mul (hst : IsBounded (s * t)) : IsBounded s ∨ IsBounded t := AntilipschitzWith.isBounded_of_image2_left _ (fun x => (isometry_mul_right x).antilipschitz) hst #align metric.bounded.of_mul Bornology.IsBounded.of_mul #align metric.bounded.of_add Bornology.IsBounded.of_add @[to_additive] theorem Bornology.IsBounded.inv : IsBounded s → IsBounded s⁻¹ := by simp_rw [isBounded_iff_forall_norm_le', ← image_inv, forall_mem_image, norm_inv'] exact id #align metric.bounded.inv Bornology.IsBounded.inv #align metric.bounded.neg Bornology.IsBounded.neg @[to_additive] theorem Bornology.IsBounded.div (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s / t) := div_eq_mul_inv s t ▸ hs.mul ht.inv #align metric.bounded.div Bornology.IsBounded.div #align metric.bounded.sub Bornology.IsBounded.sub end SeminormedGroup section SeminormedCommGroup variable [SeminormedCommGroup E] {ε δ : ℝ} {s t : Set E} {x y : E} section EMetric open EMetric @[to_additive (attr := simp)] theorem infEdist_inv_inv (x : E) (s : Set E) : infEdist x⁻¹ s⁻¹ = infEdist x s := by rw [← image_inv, infEdist_image isometry_inv] #align inf_edist_inv_inv infEdist_inv_inv #align inf_edist_neg_neg infEdist_neg_neg @[to_additive] theorem infEdist_inv (x : E) (s : Set E) : infEdist x⁻¹ s = infEdist x s⁻¹ := by rw [← infEdist_inv_inv, inv_inv] #align inf_edist_inv infEdist_inv #align inf_edist_neg infEdist_neg @[to_additive] theorem ediam_mul_le (x y : Set E) : EMetric.diam (x * y) ≤ EMetric.diam x + EMetric.diam y := (LipschitzOnWith.ediam_image2_le (· * ·) _ _ (fun _ _ => (isometry_mul_right _).lipschitz.lipschitzOnWith _) fun _ _ => (isometry_mul_left _).lipschitz.lipschitzOnWith _).trans_eq <| by simp only [ENNReal.coe_one, one_mul] #align ediam_mul_le ediam_mul_le #align ediam_add_le ediam_add_le end EMetric variable (ε δ s t x y) @[to_additive (attr := simp)] theorem inv_thickening : (thickening δ s)⁻¹ = thickening δ s⁻¹ := by simp_rw [thickening, ← infEdist_inv] rfl #align inv_thickening inv_thickening #align neg_thickening neg_thickening @[to_additive (attr := simp)] theorem inv_cthickening : (cthickening δ s)⁻¹ = cthickening δ s⁻¹ := by simp_rw [cthickening, ← infEdist_inv] rfl #align inv_cthickening inv_cthickening #align neg_cthickening neg_cthickening @[to_additive (attr := simp)] theorem inv_ball : (ball x δ)⁻¹ = ball x⁻¹ δ := (IsometryEquiv.inv E).preimage_ball x δ #align inv_ball inv_ball #align neg_ball neg_ball @[to_additive (attr := simp)] theorem inv_closedBall : (closedBall x δ)⁻¹ = closedBall x⁻¹ δ := (IsometryEquiv.inv E).preimage_closedBall x δ #align inv_closed_ball inv_closedBall #align neg_closed_ball neg_closedBall @[to_additive] theorem singleton_mul_ball : {x} * ball y δ = ball (x * y) δ := by simp only [preimage_mul_ball, image_mul_left, singleton_mul, div_inv_eq_mul, mul_comm y x] #align singleton_mul_ball singleton_mul_ball #align singleton_add_ball singleton_add_ball @[to_additive] theorem singleton_div_ball : {x} / ball y δ = ball (x / y) δ := by simp_rw [div_eq_mul_inv, inv_ball, singleton_mul_ball] #align singleton_div_ball singleton_div_ball #align singleton_sub_ball singleton_sub_ball @[to_additive] theorem ball_mul_singleton : ball x δ * {y} = ball (x * y) δ := by rw [mul_comm, singleton_mul_ball, mul_comm y] #align ball_mul_singleton ball_mul_singleton #align ball_add_singleton ball_add_singleton @[to_additive] theorem ball_div_singleton : ball x δ / {y} = ball (x / y) δ := by simp_rw [div_eq_mul_inv, inv_singleton, ball_mul_singleton] #align ball_div_singleton ball_div_singleton #align ball_sub_singleton ball_sub_singleton @[to_additive] theorem singleton_mul_ball_one : {x} * ball 1 δ = ball x δ := by simp #align singleton_mul_ball_one singleton_mul_ball_one #align singleton_add_ball_zero singleton_add_ball_zero @[to_additive] theorem singleton_div_ball_one : {x} / ball 1 δ = ball x δ := by rw [singleton_div_ball, div_one] #align singleton_div_ball_one singleton_div_ball_one #align singleton_sub_ball_zero singleton_sub_ball_zero @[to_additive] theorem ball_one_mul_singleton : ball 1 δ * {x} = ball x δ := by simp [ball_mul_singleton] #align ball_one_mul_singleton ball_one_mul_singleton #align ball_zero_add_singleton ball_zero_add_singleton @[to_additive] theorem ball_one_div_singleton : ball 1 δ / {x} = ball x⁻¹ δ := by rw [ball_div_singleton, one_div] #align ball_one_div_singleton ball_one_div_singleton #align ball_zero_sub_singleton ball_zero_sub_singleton @[to_additive] theorem smul_ball_one : x • ball (1 : E) δ = ball x δ := by rw [smul_ball, smul_eq_mul, mul_one] #align smul_ball_one smul_ball_one #align vadd_ball_zero vadd_ball_zero @[to_additive (attr := simp 1100)] theorem singleton_mul_closedBall : {x} * closedBall y δ = closedBall (x * y) δ := by simp_rw [singleton_mul, ← smul_eq_mul, image_smul, smul_closedBall] #align singleton_mul_closed_ball singleton_mul_closedBall #align singleton_add_closed_ball singleton_add_closedBall @[to_additive (attr := simp 1100)] theorem singleton_div_closedBall : {x} / closedBall y δ = closedBall (x / y) δ := by simp_rw [div_eq_mul_inv, inv_closedBall, singleton_mul_closedBall] #align singleton_div_closed_ball singleton_div_closedBall #align singleton_sub_closed_ball singleton_sub_closedBall @[to_additive (attr := simp 1100)] theorem closedBall_mul_singleton : closedBall x δ * {y} = closedBall (x * y) δ := by simp [mul_comm _ {y}, mul_comm y] #align closed_ball_mul_singleton closedBall_mul_singleton #align closed_ball_add_singleton closedBall_add_singleton @[to_additive (attr := simp 1100)] theorem closedBall_div_singleton : closedBall x δ / {y} = closedBall (x / y) δ := by simp [div_eq_mul_inv] #align closed_ball_div_singleton closedBall_div_singleton #align closed_ball_sub_singleton closedBall_sub_singleton @[to_additive] theorem singleton_mul_closedBall_one : {x} * closedBall 1 δ = closedBall x δ := by simp #align singleton_mul_closed_ball_one singleton_mul_closedBall_one #align singleton_add_closed_ball_zero singleton_add_closedBall_zero @[to_additive] theorem singleton_div_closedBall_one : {x} / closedBall 1 δ = closedBall x δ := by rw [singleton_div_closedBall, div_one] #align singleton_div_closed_ball_one singleton_div_closedBall_one #align singleton_sub_closed_ball_zero singleton_sub_closedBall_zero @[to_additive] theorem closedBall_one_mul_singleton : closedBall 1 δ * {x} = closedBall x δ := by simp #align closed_ball_one_mul_singleton closedBall_one_mul_singleton #align closed_ball_zero_add_singleton closedBall_zero_add_singleton @[to_additive] theorem closedBall_one_div_singleton : closedBall 1 δ / {x} = closedBall x⁻¹ δ := by simp #align closed_ball_one_div_singleton closedBall_one_div_singleton #align closed_ball_zero_sub_singleton closedBall_zero_sub_singleton @[to_additive (attr := simp 1100)] theorem smul_closedBall_one : x • closedBall (1 : E) δ = closedBall x δ := by simp #align smul_closed_ball_one smul_closedBall_one #align vadd_closed_ball_zero vadd_closedBall_zero @[to_additive] theorem mul_ball_one : s * ball 1 δ = thickening δ s := by rw [thickening_eq_biUnion_ball] convert iUnion₂_mul (fun x (_ : x ∈ s) => {x}) (ball (1 : E) δ) · exact s.biUnion_of_singleton.symm ext x simp_rw [singleton_mul_ball, mul_one] #align mul_ball_one mul_ball_one #align add_ball_zero add_ball_zero @[to_additive] theorem div_ball_one : s / ball 1 δ = thickening δ s := by simp [div_eq_mul_inv, mul_ball_one] #align div_ball_one div_ball_one #align sub_ball_zero sub_ball_zero @[to_additive] theorem ball_mul_one : ball 1 δ * s = thickening δ s := by rw [mul_comm, mul_ball_one] #align ball_mul_one ball_mul_one #align ball_add_zero ball_add_zero @[to_additive] theorem ball_div_one : ball 1 δ / s = thickening δ s⁻¹ := by simp [div_eq_mul_inv, ball_mul_one] #align ball_div_one ball_div_one #align ball_sub_zero ball_sub_zero @[to_additive (attr := simp)] theorem mul_ball : s * ball x δ = x • thickening δ s := by rw [← smul_ball_one, mul_smul_comm, mul_ball_one] #align mul_ball mul_ball #align add_ball add_ball @[to_additive (attr := simp)] theorem div_ball : s / ball x δ = x⁻¹ • thickening δ s := by simp [div_eq_mul_inv] #align div_ball div_ball #align sub_ball sub_ball @[to_additive (attr := simp)] theorem ball_mul : ball x δ * s = x • thickening δ s := by rw [mul_comm, mul_ball] #align ball_mul ball_mul #align ball_add ball_add @[to_additive (attr := simp)] theorem ball_div : ball x δ / s = x • thickening δ s⁻¹ := by simp [div_eq_mul_inv] #align ball_div ball_div #align ball_sub ball_sub variable {ε δ s t x y} @[to_additive] theorem IsCompact.mul_closedBall_one (hs : IsCompact s) (hδ : 0 ≤ δ) : s * closedBall (1 : E) δ = cthickening δ s := by rw [hs.cthickening_eq_biUnion_closedBall hδ] ext x simp only [mem_mul, dist_eq_norm_div, exists_prop, mem_iUnion, mem_closedBall, exists_and_left, mem_closedBall_one_iff, ← eq_div_iff_mul_eq'', div_one, exists_eq_right] #align is_compact.mul_closed_ball_one IsCompact.mul_closedBall_one #align is_compact.add_closed_ball_zero IsCompact.add_closedBall_zero @[to_additive] theorem IsCompact.div_closedBall_one (hs : IsCompact s) (hδ : 0 ≤ δ) : s / closedBall 1 δ = cthickening δ s := by simp [div_eq_mul_inv, hs.mul_closedBall_one hδ] #align is_compact.div_closed_ball_one IsCompact.div_closedBall_one #align is_compact.sub_closed_ball_zero IsCompact.sub_closedBall_zero @[to_additive] theorem IsCompact.closedBall_one_mul (hs : IsCompact s) (hδ : 0 ≤ δ) : closedBall 1 δ * s = cthickening δ s := by rw [mul_comm, hs.mul_closedBall_one hδ] #align is_compact.closed_ball_one_mul IsCompact.closedBall_one_mul #align is_compact.closed_ball_zero_add IsCompact.closedBall_zero_add @[to_additive]
Mathlib/Analysis/Normed/Group/Pointwise.lean
291
293
theorem IsCompact.closedBall_one_div (hs : IsCompact s) (hδ : 0 ≤ δ) : closedBall 1 δ / s = cthickening δ s⁻¹ := by
simp [div_eq_mul_inv, mul_comm, hs.inv.mul_closedBall_one hδ]
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov, Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Constructions.BorelSpace.Order import Mathlib.Topology.Order.LeftRightLim #align_import measure_theory.measure.stieltjes from "leanprover-community/mathlib"@"20d5763051978e9bc6428578ed070445df6a18b3" /-! # Stieltjes measures on the real line Consider a function `f : ℝ → ℝ` which is monotone and right-continuous. Then one can define a corresponding measure, giving mass `f b - f a` to the interval `(a, b]`. ## Main definitions * `StieltjesFunction` is a structure containing a function from `ℝ → ℝ`, together with the assertions that it is monotone and right-continuous. To `f : StieltjesFunction`, one associates a Borel measure `f.measure`. * `f.measure_Ioc` asserts that `f.measure (Ioc a b) = ofReal (f b - f a)` * `f.measure_Ioo` asserts that `f.measure (Ioo a b) = ofReal (leftLim f b - f a)`. * `f.measure_Icc` and `f.measure_Ico` are analogous. -/ noncomputable section open scoped Classical open Set Filter Function ENNReal NNReal Topology MeasureTheory open ENNReal (ofReal) /-! ### Basic properties of Stieltjes functions -/ /-- Bundled monotone right-continuous real functions, used to construct Stieltjes measures. -/ structure StieltjesFunction where toFun : ℝ → ℝ mono' : Monotone toFun right_continuous' : ∀ x, ContinuousWithinAt toFun (Ici x) x #align stieltjes_function StieltjesFunction #align stieltjes_function.to_fun StieltjesFunction.toFun #align stieltjes_function.mono' StieltjesFunction.mono' #align stieltjes_function.right_continuous' StieltjesFunction.right_continuous' namespace StieltjesFunction attribute [coe] toFun instance instCoeFun : CoeFun StieltjesFunction fun _ => ℝ → ℝ := ⟨toFun⟩ #align stieltjes_function.has_coe_to_fun StieltjesFunction.instCoeFun initialize_simps_projections StieltjesFunction (toFun → apply) @[ext] lemma ext {f g : StieltjesFunction} (h : ∀ x, f x = g x) : f = g := by exact (StieltjesFunction.mk.injEq ..).mpr (funext (by exact h)) variable (f : StieltjesFunction) theorem mono : Monotone f := f.mono' #align stieltjes_function.mono StieltjesFunction.mono theorem right_continuous (x : ℝ) : ContinuousWithinAt f (Ici x) x := f.right_continuous' x #align stieltjes_function.right_continuous StieltjesFunction.right_continuous theorem rightLim_eq (f : StieltjesFunction) (x : ℝ) : Function.rightLim f x = f x := by rw [← f.mono.continuousWithinAt_Ioi_iff_rightLim_eq, continuousWithinAt_Ioi_iff_Ici] exact f.right_continuous' x #align stieltjes_function.right_lim_eq StieltjesFunction.rightLim_eq theorem iInf_Ioi_eq (f : StieltjesFunction) (x : ℝ) : ⨅ r : Ioi x, f r = f x := by suffices Function.rightLim f x = ⨅ r : Ioi x, f r by rw [← this, f.rightLim_eq] rw [f.mono.rightLim_eq_sInf, sInf_image'] rw [← neBot_iff] infer_instance #align stieltjes_function.infi_Ioi_eq StieltjesFunction.iInf_Ioi_eq theorem iInf_rat_gt_eq (f : StieltjesFunction) (x : ℝ) : ⨅ r : { r' : ℚ // x < r' }, f r = f x := by rw [← iInf_Ioi_eq f x] refine (Real.iInf_Ioi_eq_iInf_rat_gt _ ?_ f.mono).symm refine ⟨f x, fun y => ?_⟩ rintro ⟨y, hy_mem, rfl⟩ exact f.mono (le_of_lt hy_mem) #align stieltjes_function.infi_rat_gt_eq StieltjesFunction.iInf_rat_gt_eq /-- The identity of `ℝ` as a Stieltjes function, used to construct Lebesgue measure. -/ @[simps] protected def id : StieltjesFunction where toFun := id mono' _ _ := id right_continuous' _ := continuousWithinAt_id #align stieltjes_function.id StieltjesFunction.id #align stieltjes_function.id_apply StieltjesFunction.id_apply @[simp] theorem id_leftLim (x : ℝ) : leftLim StieltjesFunction.id x = x := tendsto_nhds_unique (StieltjesFunction.id.mono.tendsto_leftLim x) <| continuousAt_id.tendsto.mono_left nhdsWithin_le_nhds #align stieltjes_function.id_left_lim StieltjesFunction.id_leftLim instance instInhabited : Inhabited StieltjesFunction := ⟨StieltjesFunction.id⟩ #align stieltjes_function.inhabited StieltjesFunction.instInhabited /-- If a function `f : ℝ → ℝ` is monotone, then the function mapping `x` to the right limit of `f` at `x` is a Stieltjes function, i.e., it is monotone and right-continuous. -/ noncomputable def _root_.Monotone.stieltjesFunction {f : ℝ → ℝ} (hf : Monotone f) : StieltjesFunction where toFun := rightLim f mono' x y hxy := hf.rightLim hxy right_continuous' := by intro x s hs obtain ⟨l, u, hlu, lus⟩ : ∃ l u : ℝ, rightLim f x ∈ Ioo l u ∧ Ioo l u ⊆ s := mem_nhds_iff_exists_Ioo_subset.1 hs obtain ⟨y, xy, h'y⟩ : ∃ (y : ℝ), x < y ∧ Ioc x y ⊆ f ⁻¹' Ioo l u := mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.1 (hf.tendsto_rightLim x (Ioo_mem_nhds hlu.1 hlu.2)) change ∀ᶠ y in 𝓝[≥] x, rightLim f y ∈ s filter_upwards [Ico_mem_nhdsWithin_Ici ⟨le_refl x, xy⟩] with z hz apply lus refine ⟨hlu.1.trans_le (hf.rightLim hz.1), ?_⟩ obtain ⟨a, za, ay⟩ : ∃ a : ℝ, z < a ∧ a < y := exists_between hz.2 calc rightLim f z ≤ f a := hf.rightLim_le za _ < u := (h'y ⟨hz.1.trans_lt za, ay.le⟩).2 #align monotone.stieltjes_function Monotone.stieltjesFunction theorem _root_.Monotone.stieltjesFunction_eq {f : ℝ → ℝ} (hf : Monotone f) (x : ℝ) : hf.stieltjesFunction x = rightLim f x := rfl #align monotone.stieltjes_function_eq Monotone.stieltjesFunction_eq theorem countable_leftLim_ne (f : StieltjesFunction) : Set.Countable { x | leftLim f x ≠ f x } := by refine Countable.mono ?_ f.mono.countable_not_continuousAt intro x hx h'x apply hx exact tendsto_nhds_unique (f.mono.tendsto_leftLim x) (h'x.tendsto.mono_left nhdsWithin_le_nhds) #align stieltjes_function.countable_left_lim_ne StieltjesFunction.countable_leftLim_ne /-! ### The outer measure associated to a Stieltjes function -/ /-- Length of an interval. This is the largest monotone function which correctly measures all intervals. -/ def length (s : Set ℝ) : ℝ≥0∞ := ⨅ (a) (b) (_ : s ⊆ Ioc a b), ofReal (f b - f a) #align stieltjes_function.length StieltjesFunction.length @[simp] theorem length_empty : f.length ∅ = 0 := nonpos_iff_eq_zero.1 <| iInf_le_of_le 0 <| iInf_le_of_le 0 <| by simp #align stieltjes_function.length_empty StieltjesFunction.length_empty @[simp] theorem length_Ioc (a b : ℝ) : f.length (Ioc a b) = ofReal (f b - f a) := by refine le_antisymm (iInf_le_of_le a <| iInf₂_le b Subset.rfl) (le_iInf fun a' => le_iInf fun b' => le_iInf fun h => ENNReal.coe_le_coe.2 ?_) rcases le_or_lt b a with ab | ab · rw [Real.toNNReal_of_nonpos (sub_nonpos.2 (f.mono ab))] apply zero_le cases' (Ioc_subset_Ioc_iff ab).1 h with h₁ h₂ exact Real.toNNReal_le_toNNReal (sub_le_sub (f.mono h₁) (f.mono h₂)) #align stieltjes_function.length_Ioc StieltjesFunction.length_Ioc theorem length_mono {s₁ s₂ : Set ℝ} (h : s₁ ⊆ s₂) : f.length s₁ ≤ f.length s₂ := iInf_mono fun _ => biInf_mono fun _ => h.trans #align stieltjes_function.length_mono StieltjesFunction.length_mono open MeasureTheory /-- The Stieltjes outer measure associated to a Stieltjes function. -/ protected def outer : OuterMeasure ℝ := OuterMeasure.ofFunction f.length f.length_empty #align stieltjes_function.outer StieltjesFunction.outer theorem outer_le_length (s : Set ℝ) : f.outer s ≤ f.length s := OuterMeasure.ofFunction_le _ #align stieltjes_function.outer_le_length StieltjesFunction.outer_le_length /-- If a compact interval `[a, b]` is covered by a union of open interval `(c i, d i)`, then `f b - f a ≤ ∑ f (d i) - f (c i)`. This is an auxiliary technical statement to prove the same statement for half-open intervals, the point of the current statement being that one can use compactness to reduce it to a finite sum, and argue by induction on the size of the covering set. -/ theorem length_subadditive_Icc_Ioo {a b : ℝ} {c d : ℕ → ℝ} (ss : Icc a b ⊆ ⋃ i, Ioo (c i) (d i)) : ofReal (f b - f a) ≤ ∑' i, ofReal (f (d i) - f (c i)) := by suffices ∀ (s : Finset ℕ) (b), Icc a b ⊆ (⋃ i ∈ (s : Set ℕ), Ioo (c i) (d i)) → (ofReal (f b - f a) : ℝ≥0∞) ≤ ∑ i ∈ s, ofReal (f (d i) - f (c i)) by rcases isCompact_Icc.elim_finite_subcover_image (fun (i : ℕ) (_ : i ∈ univ) => @isOpen_Ioo _ _ _ _ (c i) (d i)) (by simpa using ss) with ⟨s, _, hf, hs⟩ have e : ⋃ i ∈ (hf.toFinset : Set ℕ), Ioo (c i) (d i) = ⋃ i ∈ s, Ioo (c i) (d i) := by simp only [ext_iff, exists_prop, Finset.set_biUnion_coe, mem_iUnion, forall_const, iff_self_iff, Finite.mem_toFinset] rw [ENNReal.tsum_eq_iSup_sum] refine le_trans ?_ (le_iSup _ hf.toFinset) exact this hf.toFinset _ (by simpa only [e] ) clear ss b refine fun s => Finset.strongInductionOn s fun s IH b cv => ?_ rcases le_total b a with ab | ab · rw [ENNReal.ofReal_eq_zero.2 (sub_nonpos.2 (f.mono ab))] exact zero_le _ have := cv ⟨ab, le_rfl⟩ simp only [Finset.mem_coe, gt_iff_lt, not_lt, ge_iff_le, mem_iUnion, mem_Ioo, exists_and_left, exists_prop] at this rcases this with ⟨i, cb, is, bd⟩ rw [← Finset.insert_erase is] at cv ⊢ rw [Finset.coe_insert, biUnion_insert] at cv rw [Finset.sum_insert (Finset.not_mem_erase _ _)] refine le_trans ?_ (add_le_add_left (IH _ (Finset.erase_ssubset is) (c i) ?_) _) · refine le_trans (ENNReal.ofReal_le_ofReal ?_) ENNReal.ofReal_add_le rw [sub_add_sub_cancel] exact sub_le_sub_right (f.mono bd.le) _ · rintro x ⟨h₁, h₂⟩ exact (cv ⟨h₁, le_trans h₂ (le_of_lt cb)⟩).resolve_left (mt And.left (not_lt_of_le h₂)) #align stieltjes_function.length_subadditive_Icc_Ioo StieltjesFunction.length_subadditive_Icc_Ioo @[simp] theorem outer_Ioc (a b : ℝ) : f.outer (Ioc a b) = ofReal (f b - f a) := by /- It suffices to show that, if `(a, b]` is covered by sets `s i`, then `f b - f a` is bounded by `∑ f.length (s i) + ε`. The difficulty is that `f.length` is expressed in terms of half-open intervals, while we would like to have a compact interval covered by open intervals to use compactness and finite sums, as provided by `length_subadditive_Icc_Ioo`. The trick is to use the right-continuity of `f`. If `a'` is close enough to `a` on its right, then `[a', b]` is still covered by the sets `s i` and moreover `f b - f a'` is very close to `f b - f a` (up to `ε/2`). Also, by definition one can cover `s i` by a half-closed interval `(p i, q i]` with `f`-length very close to that of `s i` (within a suitably small `ε' i`, say). If one moves `q i` very slightly to the right, then the `f`-length will change very little by right continuity, and we will get an open interval `(p i, q' i)` covering `s i` with `f (q' i) - f (p i)` within `ε' i` of the `f`-length of `s i`. -/ refine le_antisymm (by rw [← f.length_Ioc] apply outer_le_length) (le_iInf₂ fun s hs => ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_) let δ := ε / 2 have δpos : 0 < (δ : ℝ≥0∞) := by simpa [δ] using εpos.ne' rcases ENNReal.exists_pos_sum_of_countable δpos.ne' ℕ with ⟨ε', ε'0, hε⟩ obtain ⟨a', ha', aa'⟩ : ∃ a', f a' - f a < δ ∧ a < a' := by have A : ContinuousWithinAt (fun r => f r - f a) (Ioi a) a := by refine ContinuousWithinAt.sub ?_ continuousWithinAt_const exact (f.right_continuous a).mono Ioi_subset_Ici_self have B : f a - f a < δ := by rwa [sub_self, NNReal.coe_pos, ← ENNReal.coe_pos] exact (((tendsto_order.1 A).2 _ B).and self_mem_nhdsWithin).exists have : ∀ i, ∃ p : ℝ × ℝ, s i ⊆ Ioo p.1 p.2 ∧ (ofReal (f p.2 - f p.1) : ℝ≥0∞) < f.length (s i) + ε' i := by intro i have hl := ENNReal.lt_add_right ((ENNReal.le_tsum i).trans_lt h).ne (ENNReal.coe_ne_zero.2 (ε'0 i).ne') conv at hl => lhs rw [length] simp only [iInf_lt_iff, exists_prop] at hl rcases hl with ⟨p, q', spq, hq'⟩ have : ContinuousWithinAt (fun r => ofReal (f r - f p)) (Ioi q') q' := by apply ENNReal.continuous_ofReal.continuousAt.comp_continuousWithinAt refine ContinuousWithinAt.sub ?_ continuousWithinAt_const exact (f.right_continuous q').mono Ioi_subset_Ici_self rcases (((tendsto_order.1 this).2 _ hq').and self_mem_nhdsWithin).exists with ⟨q, hq, q'q⟩ exact ⟨⟨p, q⟩, spq.trans (Ioc_subset_Ioo_right q'q), hq⟩ choose g hg using this have I_subset : Icc a' b ⊆ ⋃ i, Ioo (g i).1 (g i).2 := calc Icc a' b ⊆ Ioc a b := fun x hx => ⟨aa'.trans_le hx.1, hx.2⟩ _ ⊆ ⋃ i, s i := hs _ ⊆ ⋃ i, Ioo (g i).1 (g i).2 := iUnion_mono fun i => (hg i).1 calc ofReal (f b - f a) = ofReal (f b - f a' + (f a' - f a)) := by rw [sub_add_sub_cancel] _ ≤ ofReal (f b - f a') + ofReal (f a' - f a) := ENNReal.ofReal_add_le _ ≤ ∑' i, ofReal (f (g i).2 - f (g i).1) + ofReal δ := (add_le_add (f.length_subadditive_Icc_Ioo I_subset) (ENNReal.ofReal_le_ofReal ha'.le)) _ ≤ ∑' i, (f.length (s i) + ε' i) + δ := (add_le_add (ENNReal.tsum_le_tsum fun i => (hg i).2.le) (by simp only [ENNReal.ofReal_coe_nnreal, le_rfl])) _ = ∑' i, f.length (s i) + ∑' i, (ε' i : ℝ≥0∞) + δ := by rw [ENNReal.tsum_add] _ ≤ ∑' i, f.length (s i) + δ + δ := add_le_add (add_le_add le_rfl hε.le) le_rfl _ = ∑' i : ℕ, f.length (s i) + ε := by simp [δ, add_assoc, ENNReal.add_halves] #align stieltjes_function.outer_Ioc StieltjesFunction.outer_Ioc theorem measurableSet_Ioi {c : ℝ} : MeasurableSet[f.outer.caratheodory] (Ioi c) := by refine OuterMeasure.ofFunction_caratheodory fun t => ?_ refine le_iInf fun a => le_iInf fun b => le_iInf fun h => ?_ refine le_trans (add_le_add (f.length_mono <| inter_subset_inter_left _ h) (f.length_mono <| diff_subset_diff_left h)) ?_ rcases le_total a c with hac | hac <;> rcases le_total b c with hbc | hbc · simp only [Ioc_inter_Ioi, f.length_Ioc, hac, _root_.sup_eq_max, hbc, le_refl, Ioc_eq_empty, max_eq_right, min_eq_left, Ioc_diff_Ioi, f.length_empty, zero_add, not_lt] · simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right, _root_.sup_eq_max, ← ENNReal.ofReal_add, f.mono hac, f.mono hbc, sub_nonneg, sub_add_sub_cancel, le_refl, max_eq_right] · simp only [hbc, le_refl, Ioc_eq_empty, Ioc_inter_Ioi, min_eq_left, Ioc_diff_Ioi, f.length_empty, zero_add, or_true_iff, le_sup_iff, f.length_Ioc, not_lt] · simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right, _root_.sup_eq_max, le_refl, Ioc_eq_empty, add_zero, max_eq_left, f.length_empty, not_lt] #align stieltjes_function.measurable_set_Ioi StieltjesFunction.measurableSet_Ioi theorem outer_trim : f.outer.trim = f.outer := by refine le_antisymm (fun s => ?_) (OuterMeasure.le_trim _) rw [OuterMeasure.trim_eq_iInf] refine le_iInf fun t => le_iInf fun ht => ENNReal.le_of_forall_pos_le_add fun ε ε0 h => ?_ rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 ε0).ne' ℕ with ⟨ε', ε'0, hε⟩ refine le_trans ?_ (add_le_add_left (le_of_lt hε) _) rw [← ENNReal.tsum_add] choose g hg using show ∀ i, ∃ s, t i ⊆ s ∧ MeasurableSet s ∧ f.outer s ≤ f.length (t i) + ofReal (ε' i) by intro i have hl := ENNReal.lt_add_right ((ENNReal.le_tsum i).trans_lt h).ne (ENNReal.coe_pos.2 (ε'0 i)).ne' conv at hl => lhs rw [length] simp only [iInf_lt_iff] at hl rcases hl with ⟨a, b, h₁, h₂⟩ rw [← f.outer_Ioc] at h₂ exact ⟨_, h₁, measurableSet_Ioc, le_of_lt <| by simpa using h₂⟩ simp only [ofReal_coe_nnreal] at hg apply iInf_le_of_le (iUnion g) _ apply iInf_le_of_le (ht.trans <| iUnion_mono fun i => (hg i).1) _ apply iInf_le_of_le (MeasurableSet.iUnion fun i => (hg i).2.1) _ exact le_trans (measure_iUnion_le _) (ENNReal.tsum_le_tsum fun i => (hg i).2.2) #align stieltjes_function.outer_trim StieltjesFunction.outer_trim theorem borel_le_measurable : borel ℝ ≤ f.outer.caratheodory := by rw [borel_eq_generateFrom_Ioi] refine MeasurableSpace.generateFrom_le ?_ simp (config := { contextual := true }) [f.measurableSet_Ioi] #align stieltjes_function.borel_le_measurable StieltjesFunction.borel_le_measurable /-! ### The measure associated to a Stieltjes function -/ /-- The measure associated to a Stieltjes function, giving mass `f b - f a` to the interval `(a, b]`. -/ protected irreducible_def measure : Measure ℝ where toOuterMeasure := f.outer m_iUnion _s hs := f.outer.iUnion_eq_of_caratheodory fun i => f.borel_le_measurable _ (hs i) trim_le := f.outer_trim.le #align stieltjes_function.measure StieltjesFunction.measure @[simp] theorem measure_Ioc (a b : ℝ) : f.measure (Ioc a b) = ofReal (f b - f a) := by rw [StieltjesFunction.measure] exact f.outer_Ioc a b #align stieltjes_function.measure_Ioc StieltjesFunction.measure_Ioc #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. -/ @[simp, nolint simpNF]
Mathlib/MeasureTheory/Measure/Stieltjes.lean
360
383
theorem measure_singleton (a : ℝ) : f.measure {a} = ofReal (f a - leftLim f a) := by
obtain ⟨u, u_mono, u_lt_a, u_lim⟩ : ∃ u : ℕ → ℝ, StrictMono u ∧ (∀ n : ℕ, u n < a) ∧ Tendsto u atTop (𝓝 a) := exists_seq_strictMono_tendsto a have A : {a} = ⋂ n, Ioc (u n) a := by refine Subset.antisymm (fun x hx => by simp [mem_singleton_iff.1 hx, u_lt_a]) fun x hx => ?_ simp? at hx says simp only [mem_iInter, mem_Ioc] at hx have : a ≤ x := le_of_tendsto' u_lim fun n => (hx n).1.le simp [le_antisymm this (hx 0).2] have L1 : Tendsto (fun n => f.measure (Ioc (u n) a)) atTop (𝓝 (f.measure {a})) := by rw [A] refine tendsto_measure_iInter (fun n => measurableSet_Ioc) (fun m n hmn => ?_) ?_ · exact Ioc_subset_Ioc (u_mono.monotone hmn) le_rfl · exact ⟨0, by simpa only [measure_Ioc] using ENNReal.ofReal_ne_top⟩ have L2 : Tendsto (fun n => f.measure (Ioc (u n) a)) atTop (𝓝 (ofReal (f a - leftLim f a))) := by simp only [measure_Ioc] have : Tendsto (fun n => f (u n)) atTop (𝓝 (leftLim f a)) := by apply (f.mono.tendsto_leftLim a).comp exact tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ u_lim (eventually_of_forall fun n => u_lt_a n) exact ENNReal.continuous_ofReal.continuousAt.tendsto.comp (tendsto_const_nhds.sub this) exact tendsto_nhds_unique L1 L2
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Scott Morrison, Ainsley Pahljina -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Nat import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.OrderOfElement import Mathlib.RingTheory.Fintype import Mathlib.Tactic.IntervalCases #align_import number_theory.lucas_lehmer from "leanprover-community/mathlib"@"10b4e499f43088dd3bb7b5796184ad5216648ab1" /-! # 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 Scott 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. -/ /-- The Mersenne numbers, 2^p - 1. -/ def mersenne (p : ℕ) : ℕ := 2 ^ p - 1 #align mersenne mersenne 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] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0) #align mersenne_pos mersenne_pos 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_of_one_le (by norm_num) k #align succ_mersenne succ_mersenne 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 #align lucas_lehmer.s LucasLehmer.s /-- 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 #align lucas_lehmer.s_zmod LucasLehmer.sZMod /-- 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) #align lucas_lehmer.s_mod LucasLehmer.sMod 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' #align lucas_lehmer.mersenne_int_ne_zero LucasLehmer.mersenne_int_ne_zero 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 #align lucas_lehmer.s_mod_nonneg LucasLehmer.sMod_nonneg theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod] #align lucas_lehmer.s_mod_mod LucasLehmer.sMod_mod theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by rw [← sMod_mod] refine (Int.emod_lt _ (mersenne_int_ne_zero p hp)).trans_eq ?_ exact abs_of_nonneg (mersenne_int_pos hp).le #align lucas_lehmer.s_mod_lt LucasLehmer.sMod_lt theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by induction' i with i ih · dsimp [s, sZMod] norm_num · push_cast [s, sZMod, ih]; rfl #align lucas_lehmer.s_zmod_eq_s LucasLehmer.sZMod_eq_s -- 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 #align lucas_lehmer.int.coe_nat_pow_pred LucasLehmer.Int.natCast_pow_pred @[deprecated (since := "2024-05-25")] alias Int.coe_nat_pow_pred := Int.natCast_pow_pred theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) := Int.natCast_pow_pred 2 p (by decide) #align lucas_lehmer.int.coe_nat_two_pow_pred LucasLehmer.Int.coe_nat_two_pow_pred
Mathlib/NumberTheory/LucasLehmer.lean
173
174
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
/- Copyright (c) 2014 Robert Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Lewis, Leonardo de Moura, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.Field.Defs import Mathlib.Tactic.Common #align_import algebra.field.defs from "leanprover-community/mathlib"@"2651125b48fc5c170ab1111afd0817c903b1fc6c" /-! # `IsField` predicate Predicate on a (semi)ring that it is a (semi)field, i.e. that the multiplication is commutative, that it has more than one element and that all non-zero elements have a multiplicative inverse. In contrast to `Field`, which contains the data of a function associating to an element of the field its multiplicative inverse, this predicate only assumes the existence and can therefore more easily be used to e.g. transfer along ring isomorphisms. -/ universe u section IsField /-- A predicate to express that a (semi)ring is a (semi)field. This is mainly useful because such a predicate does not contain data, and can therefore be easily transported along ring isomorphisms. Additionally, this is useful when trying to prove that a particular ring structure extends to a (semi)field. -/ structure IsField (R : Type u) [Semiring R] : Prop where /-- For a semiring to be a field, it must have two distinct elements. -/ exists_pair_ne : ∃ x y : R, x ≠ y /-- Fields are commutative. -/ mul_comm : ∀ x y : R, x * y = y * x /-- Nonzero elements have multiplicative inverses. -/ mul_inv_cancel : ∀ {a : R}, a ≠ 0 → ∃ b, a * b = 1 #align is_field IsField /-- Transferring from `Semifield` to `IsField`. -/ theorem Semifield.toIsField (R : Type u) [Semifield R] : IsField R where __ := ‹Semifield R› mul_inv_cancel {a} ha := ⟨a⁻¹, mul_inv_cancel ha⟩ #align semifield.to_is_field Semifield.toIsField /-- Transferring from `Field` to `IsField`. -/ theorem Field.toIsField (R : Type u) [Field R] : IsField R := Semifield.toIsField _ #align field.to_is_field Field.toIsField @[simp] theorem IsField.nontrivial {R : Type u} [Semiring R] (h : IsField R) : Nontrivial R := ⟨h.exists_pair_ne⟩ #align is_field.nontrivial IsField.nontrivial @[simp] theorem not_isField_of_subsingleton (R : Type u) [Semiring R] [Subsingleton R] : ¬IsField R := fun h => let ⟨_, _, h⟩ := h.exists_pair_ne h (Subsingleton.elim _ _) #align not_is_field_of_subsingleton not_isField_of_subsingleton open scoped Classical /-- Transferring from `IsField` to `Semifield`. -/ noncomputable def IsField.toSemifield {R : Type u} [Semiring R] (h : IsField R) : Semifield R where __ := ‹Semiring R› __ := h inv a := if ha : a = 0 then 0 else Classical.choose (h.mul_inv_cancel ha) inv_zero := dif_pos rfl mul_inv_cancel a ha := by convert Classical.choose_spec (h.mul_inv_cancel ha); exact dif_neg ha nnqsmul := _ #align is_field.to_semifield IsField.toSemifield /-- Transferring from `IsField` to `Field`. -/ noncomputable def IsField.toField {R : Type u} [Ring R] (h : IsField R) : Field R := { ‹Ring R›, IsField.toSemifield h with qsmul := _ } #align is_field.to_field IsField.toField /-- For each field, and for each nonzero element of said field, there is a unique inverse. Since `IsField` doesn't remember the data of an `inv` function and as such, a lemma that there is a unique inverse could be useful. -/
Mathlib/Algebra/Field/IsField.lean
84
93
theorem uniq_inv_of_isField (R : Type u) [Ring R] (hf : IsField R) : ∀ x : R, x ≠ 0 → ∃! y : R, x * y = 1 := by
intro x hx apply exists_unique_of_exists_of_unique · exact hf.mul_inv_cancel hx · intro y z hxy hxz calc y = y * (x * z) := by rw [hxz, mul_one] _ = x * y * z := by rw [← mul_assoc, hf.mul_comm y x] _ = z := by rw [hxy, one_mul]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.MeasureTheory.Function.LpOrder #align_import measure_theory.function.l1_space from "leanprover-community/mathlib"@"ccdbfb6e5614667af5aa3ab2d50885e0ef44a46f" /-! # Integrable functions and `L¹` space In the first part of this file, the predicate `Integrable` is defined and basic properties of integrable functions are proved. Such a predicate is already available under the name `Memℒp 1`. We give a direct definition which is easier to use, and show that it is equivalent to `Memℒp 1` In the second part, we establish an API between `Integrable` and the space `L¹` of equivalence classes of integrable functions, already defined as a special case of `L^p` spaces for `p = 1`. ## Notation * `α →₁[μ] β` is the type of `L¹` space, where `α` is a `MeasureSpace` and `β` is a `NormedAddCommGroup` with a `SecondCountableTopology`. `f : α →ₘ β` is a "function" in `L¹`. In comments, `[f]` is also used to denote an `L¹` function. `₁` can be typed as `\1`. ## Main definitions * Let `f : α → β` be a function, where `α` is a `MeasureSpace` and `β` a `NormedAddCommGroup`. Then `HasFiniteIntegral f` means `(∫⁻ a, ‖f a‖₊) < ∞`. * If `β` is moreover a `MeasurableSpace` then `f` is called `Integrable` if `f` is `Measurable` and `HasFiniteIntegral f` holds. ## Implementation notes To prove something for an arbitrary integrable function, a useful theorem is `Integrable.induction` in the file `SetIntegral`. ## Tags integrable, function space, l1 -/ noncomputable section open scoped Classical open Topology ENNReal MeasureTheory NNReal open Set Filter TopologicalSpace ENNReal EMetric MeasureTheory variable {α β γ δ : Type*} {m : MeasurableSpace α} {μ ν : Measure α} [MeasurableSpace δ] variable [NormedAddCommGroup β] variable [NormedAddCommGroup γ] namespace MeasureTheory /-! ### Some results about the Lebesgue integral involving a normed group -/ theorem lintegral_nnnorm_eq_lintegral_edist (f : α → β) : ∫⁻ a, ‖f a‖₊ ∂μ = ∫⁻ a, edist (f a) 0 ∂μ := by simp only [edist_eq_coe_nnnorm] #align measure_theory.lintegral_nnnorm_eq_lintegral_edist MeasureTheory.lintegral_nnnorm_eq_lintegral_edist theorem lintegral_norm_eq_lintegral_edist (f : α → β) : ∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ = ∫⁻ a, edist (f a) 0 ∂μ := by simp only [ofReal_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm] #align measure_theory.lintegral_norm_eq_lintegral_edist MeasureTheory.lintegral_norm_eq_lintegral_edist theorem lintegral_edist_triangle {f g h : α → β} (hf : AEStronglyMeasurable f μ) (hh : AEStronglyMeasurable h μ) : (∫⁻ a, edist (f a) (g a) ∂μ) ≤ (∫⁻ a, edist (f a) (h a) ∂μ) + ∫⁻ a, edist (g a) (h a) ∂μ := by rw [← lintegral_add_left' (hf.edist hh)] refine lintegral_mono fun a => ?_ apply edist_triangle_right #align measure_theory.lintegral_edist_triangle MeasureTheory.lintegral_edist_triangle theorem lintegral_nnnorm_zero : (∫⁻ _ : α, ‖(0 : β)‖₊ ∂μ) = 0 := by simp #align measure_theory.lintegral_nnnorm_zero MeasureTheory.lintegral_nnnorm_zero theorem lintegral_nnnorm_add_left {f : α → β} (hf : AEStronglyMeasurable f μ) (g : α → γ) : ∫⁻ a, ‖f a‖₊ + ‖g a‖₊ ∂μ = (∫⁻ a, ‖f a‖₊ ∂μ) + ∫⁻ a, ‖g a‖₊ ∂μ := lintegral_add_left' hf.ennnorm _ #align measure_theory.lintegral_nnnorm_add_left MeasureTheory.lintegral_nnnorm_add_left theorem lintegral_nnnorm_add_right (f : α → β) {g : α → γ} (hg : AEStronglyMeasurable g μ) : ∫⁻ a, ‖f a‖₊ + ‖g a‖₊ ∂μ = (∫⁻ a, ‖f a‖₊ ∂μ) + ∫⁻ a, ‖g a‖₊ ∂μ := lintegral_add_right' _ hg.ennnorm #align measure_theory.lintegral_nnnorm_add_right MeasureTheory.lintegral_nnnorm_add_right theorem lintegral_nnnorm_neg {f : α → β} : (∫⁻ a, ‖(-f) a‖₊ ∂μ) = ∫⁻ a, ‖f a‖₊ ∂μ := by simp only [Pi.neg_apply, nnnorm_neg] #align measure_theory.lintegral_nnnorm_neg MeasureTheory.lintegral_nnnorm_neg /-! ### The predicate `HasFiniteIntegral` -/ /-- `HasFiniteIntegral f μ` means that the integral `∫⁻ a, ‖f a‖ ∂μ` is finite. `HasFiniteIntegral f` means `HasFiniteIntegral f volume`. -/ def HasFiniteIntegral {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := (∫⁻ a, ‖f a‖₊ ∂μ) < ∞ #align measure_theory.has_finite_integral MeasureTheory.HasFiniteIntegral theorem hasFiniteIntegral_def {_ : MeasurableSpace α} (f : α → β) (μ : Measure α) : HasFiniteIntegral f μ ↔ ((∫⁻ a, ‖f a‖₊ ∂μ) < ∞) := Iff.rfl theorem hasFiniteIntegral_iff_norm (f : α → β) : HasFiniteIntegral f μ ↔ (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) < ∞ := by simp only [HasFiniteIntegral, ofReal_norm_eq_coe_nnnorm] #align measure_theory.has_finite_integral_iff_norm MeasureTheory.hasFiniteIntegral_iff_norm theorem hasFiniteIntegral_iff_edist (f : α → β) : HasFiniteIntegral f μ ↔ (∫⁻ a, edist (f a) 0 ∂μ) < ∞ := by simp only [hasFiniteIntegral_iff_norm, edist_dist, dist_zero_right] #align measure_theory.has_finite_integral_iff_edist MeasureTheory.hasFiniteIntegral_iff_edist theorem hasFiniteIntegral_iff_ofReal {f : α → ℝ} (h : 0 ≤ᵐ[μ] f) : HasFiniteIntegral f μ ↔ (∫⁻ a, ENNReal.ofReal (f a) ∂μ) < ∞ := by rw [HasFiniteIntegral, lintegral_nnnorm_eq_of_ae_nonneg h] #align measure_theory.has_finite_integral_iff_of_real MeasureTheory.hasFiniteIntegral_iff_ofReal theorem hasFiniteIntegral_iff_ofNNReal {f : α → ℝ≥0} : HasFiniteIntegral (fun x => (f x : ℝ)) μ ↔ (∫⁻ a, f a ∂μ) < ∞ := by simp [hasFiniteIntegral_iff_norm] #align measure_theory.has_finite_integral_iff_of_nnreal MeasureTheory.hasFiniteIntegral_iff_ofNNReal theorem HasFiniteIntegral.mono {f : α → β} {g : α → γ} (hg : HasFiniteIntegral g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ ≤ ‖g a‖) : HasFiniteIntegral f μ := by simp only [hasFiniteIntegral_iff_norm] at * calc (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) ≤ ∫⁻ a : α, ENNReal.ofReal ‖g a‖ ∂μ := lintegral_mono_ae (h.mono fun a h => ofReal_le_ofReal h) _ < ∞ := hg #align measure_theory.has_finite_integral.mono MeasureTheory.HasFiniteIntegral.mono theorem HasFiniteIntegral.mono' {f : α → β} {g : α → ℝ} (hg : HasFiniteIntegral g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ ≤ g a) : HasFiniteIntegral f μ := hg.mono <| h.mono fun _x hx => le_trans hx (le_abs_self _) #align measure_theory.has_finite_integral.mono' MeasureTheory.HasFiniteIntegral.mono' theorem HasFiniteIntegral.congr' {f : α → β} {g : α → γ} (hf : HasFiniteIntegral f μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : HasFiniteIntegral g μ := hf.mono <| EventuallyEq.le <| EventuallyEq.symm h #align measure_theory.has_finite_integral.congr' MeasureTheory.HasFiniteIntegral.congr' theorem hasFiniteIntegral_congr' {f : α → β} {g : α → γ} (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : HasFiniteIntegral f μ ↔ HasFiniteIntegral g μ := ⟨fun hf => hf.congr' h, fun hg => hg.congr' <| EventuallyEq.symm h⟩ #align measure_theory.has_finite_integral_congr' MeasureTheory.hasFiniteIntegral_congr' theorem HasFiniteIntegral.congr {f g : α → β} (hf : HasFiniteIntegral f μ) (h : f =ᵐ[μ] g) : HasFiniteIntegral g μ := hf.congr' <| h.fun_comp norm #align measure_theory.has_finite_integral.congr MeasureTheory.HasFiniteIntegral.congr theorem hasFiniteIntegral_congr {f g : α → β} (h : f =ᵐ[μ] g) : HasFiniteIntegral f μ ↔ HasFiniteIntegral g μ := hasFiniteIntegral_congr' <| h.fun_comp norm #align measure_theory.has_finite_integral_congr MeasureTheory.hasFiniteIntegral_congr theorem hasFiniteIntegral_const_iff {c : β} : HasFiniteIntegral (fun _ : α => c) μ ↔ c = 0 ∨ μ univ < ∞ := by simp [HasFiniteIntegral, lintegral_const, lt_top_iff_ne_top, ENNReal.mul_eq_top, or_iff_not_imp_left] #align measure_theory.has_finite_integral_const_iff MeasureTheory.hasFiniteIntegral_const_iff theorem hasFiniteIntegral_const [IsFiniteMeasure μ] (c : β) : HasFiniteIntegral (fun _ : α => c) μ := hasFiniteIntegral_const_iff.2 (Or.inr <| measure_lt_top _ _) #align measure_theory.has_finite_integral_const MeasureTheory.hasFiniteIntegral_const theorem hasFiniteIntegral_of_bounded [IsFiniteMeasure μ] {f : α → β} {C : ℝ} (hC : ∀ᵐ a ∂μ, ‖f a‖ ≤ C) : HasFiniteIntegral f μ := (hasFiniteIntegral_const C).mono' hC #align measure_theory.has_finite_integral_of_bounded MeasureTheory.hasFiniteIntegral_of_bounded theorem HasFiniteIntegral.of_finite [Finite α] [IsFiniteMeasure μ] {f : α → β} : HasFiniteIntegral f μ := let ⟨_⟩ := nonempty_fintype α hasFiniteIntegral_of_bounded <| ae_of_all μ <| norm_le_pi_norm f @[deprecated (since := "2024-02-05")] alias hasFiniteIntegral_of_fintype := HasFiniteIntegral.of_finite theorem HasFiniteIntegral.mono_measure {f : α → β} (h : HasFiniteIntegral f ν) (hμ : μ ≤ ν) : HasFiniteIntegral f μ := lt_of_le_of_lt (lintegral_mono' hμ le_rfl) h #align measure_theory.has_finite_integral.mono_measure MeasureTheory.HasFiniteIntegral.mono_measure theorem HasFiniteIntegral.add_measure {f : α → β} (hμ : HasFiniteIntegral f μ) (hν : HasFiniteIntegral f ν) : HasFiniteIntegral f (μ + ν) := by simp only [HasFiniteIntegral, lintegral_add_measure] at * exact add_lt_top.2 ⟨hμ, hν⟩ #align measure_theory.has_finite_integral.add_measure MeasureTheory.HasFiniteIntegral.add_measure theorem HasFiniteIntegral.left_of_add_measure {f : α → β} (h : HasFiniteIntegral f (μ + ν)) : HasFiniteIntegral f μ := h.mono_measure <| Measure.le_add_right <| le_rfl #align measure_theory.has_finite_integral.left_of_add_measure MeasureTheory.HasFiniteIntegral.left_of_add_measure theorem HasFiniteIntegral.right_of_add_measure {f : α → β} (h : HasFiniteIntegral f (μ + ν)) : HasFiniteIntegral f ν := h.mono_measure <| Measure.le_add_left <| le_rfl #align measure_theory.has_finite_integral.right_of_add_measure MeasureTheory.HasFiniteIntegral.right_of_add_measure @[simp] theorem hasFiniteIntegral_add_measure {f : α → β} : HasFiniteIntegral f (μ + ν) ↔ HasFiniteIntegral f μ ∧ HasFiniteIntegral f ν := ⟨fun h => ⟨h.left_of_add_measure, h.right_of_add_measure⟩, fun h => h.1.add_measure h.2⟩ #align measure_theory.has_finite_integral_add_measure MeasureTheory.hasFiniteIntegral_add_measure theorem HasFiniteIntegral.smul_measure {f : α → β} (h : HasFiniteIntegral f μ) {c : ℝ≥0∞} (hc : c ≠ ∞) : HasFiniteIntegral f (c • μ) := by simp only [HasFiniteIntegral, lintegral_smul_measure] at * exact mul_lt_top hc h.ne #align measure_theory.has_finite_integral.smul_measure MeasureTheory.HasFiniteIntegral.smul_measure @[simp] theorem hasFiniteIntegral_zero_measure {m : MeasurableSpace α} (f : α → β) : HasFiniteIntegral f (0 : Measure α) := by simp only [HasFiniteIntegral, lintegral_zero_measure, zero_lt_top] #align measure_theory.has_finite_integral_zero_measure MeasureTheory.hasFiniteIntegral_zero_measure variable (α β μ) @[simp] theorem hasFiniteIntegral_zero : HasFiniteIntegral (fun _ : α => (0 : β)) μ := by simp [HasFiniteIntegral] #align measure_theory.has_finite_integral_zero MeasureTheory.hasFiniteIntegral_zero variable {α β μ} theorem HasFiniteIntegral.neg {f : α → β} (hfi : HasFiniteIntegral f μ) : HasFiniteIntegral (-f) μ := by simpa [HasFiniteIntegral] using hfi #align measure_theory.has_finite_integral.neg MeasureTheory.HasFiniteIntegral.neg @[simp] theorem hasFiniteIntegral_neg_iff {f : α → β} : HasFiniteIntegral (-f) μ ↔ HasFiniteIntegral f μ := ⟨fun h => neg_neg f ▸ h.neg, HasFiniteIntegral.neg⟩ #align measure_theory.has_finite_integral_neg_iff MeasureTheory.hasFiniteIntegral_neg_iff theorem HasFiniteIntegral.norm {f : α → β} (hfi : HasFiniteIntegral f μ) : HasFiniteIntegral (fun a => ‖f a‖) μ := by have eq : (fun a => (nnnorm ‖f a‖ : ℝ≥0∞)) = fun a => (‖f a‖₊ : ℝ≥0∞) := by funext rw [nnnorm_norm] rwa [HasFiniteIntegral, eq] #align measure_theory.has_finite_integral.norm MeasureTheory.HasFiniteIntegral.norm theorem hasFiniteIntegral_norm_iff (f : α → β) : HasFiniteIntegral (fun a => ‖f a‖) μ ↔ HasFiniteIntegral f μ := hasFiniteIntegral_congr' <| eventually_of_forall fun x => norm_norm (f x) #align measure_theory.has_finite_integral_norm_iff MeasureTheory.hasFiniteIntegral_norm_iff theorem hasFiniteIntegral_toReal_of_lintegral_ne_top {f : α → ℝ≥0∞} (hf : (∫⁻ x, f x ∂μ) ≠ ∞) : HasFiniteIntegral (fun x => (f x).toReal) μ := by have : ∀ x, (‖(f x).toReal‖₊ : ℝ≥0∞) = ENNReal.ofNNReal ⟨(f x).toReal, ENNReal.toReal_nonneg⟩ := by intro x rw [Real.nnnorm_of_nonneg] simp_rw [HasFiniteIntegral, this] refine lt_of_le_of_lt (lintegral_mono fun x => ?_) (lt_top_iff_ne_top.2 hf) by_cases hfx : f x = ∞ · simp [hfx] · lift f x to ℝ≥0 using hfx with fx h simp [← h, ← NNReal.coe_le_coe] #align measure_theory.has_finite_integral_to_real_of_lintegral_ne_top MeasureTheory.hasFiniteIntegral_toReal_of_lintegral_ne_top theorem isFiniteMeasure_withDensity_ofReal {f : α → ℝ} (hfi : HasFiniteIntegral f μ) : IsFiniteMeasure (μ.withDensity fun x => ENNReal.ofReal <| f x) := by refine isFiniteMeasure_withDensity ((lintegral_mono fun x => ?_).trans_lt hfi).ne exact Real.ofReal_le_ennnorm (f x) #align measure_theory.is_finite_measure_with_density_of_real MeasureTheory.isFiniteMeasure_withDensity_ofReal section DominatedConvergence variable {F : ℕ → α → β} {f : α → β} {bound : α → ℝ} theorem all_ae_ofReal_F_le_bound (h : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) : ∀ n, ∀ᵐ a ∂μ, ENNReal.ofReal ‖F n a‖ ≤ ENNReal.ofReal (bound a) := fun n => (h n).mono fun _ h => ENNReal.ofReal_le_ofReal h set_option linter.uppercaseLean3 false in #align measure_theory.all_ae_of_real_F_le_bound MeasureTheory.all_ae_ofReal_F_le_bound theorem all_ae_tendsto_ofReal_norm (h : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop <| 𝓝 <| f a) : ∀ᵐ a ∂μ, Tendsto (fun n => ENNReal.ofReal ‖F n a‖) atTop <| 𝓝 <| ENNReal.ofReal ‖f a‖ := h.mono fun _ h => tendsto_ofReal <| Tendsto.comp (Continuous.tendsto continuous_norm _) h #align measure_theory.all_ae_tendsto_of_real_norm MeasureTheory.all_ae_tendsto_ofReal_norm theorem all_ae_ofReal_f_le_bound (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : ∀ᵐ a ∂μ, ENNReal.ofReal ‖f a‖ ≤ ENNReal.ofReal (bound a) := by have F_le_bound := all_ae_ofReal_F_le_bound h_bound rw [← ae_all_iff] at F_le_bound apply F_le_bound.mp ((all_ae_tendsto_ofReal_norm h_lim).mono _) intro a tendsto_norm F_le_bound exact le_of_tendsto' tendsto_norm F_le_bound #align measure_theory.all_ae_of_real_f_le_bound MeasureTheory.all_ae_ofReal_f_le_bound theorem hasFiniteIntegral_of_dominated_convergence {F : ℕ → α → β} {f : α → β} {bound : α → ℝ} (bound_hasFiniteIntegral : HasFiniteIntegral bound μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : HasFiniteIntegral f μ := by /- `‖F n a‖ ≤ bound a` and `‖F n a‖ --> ‖f a‖` implies `‖f a‖ ≤ bound a`, and so `∫ ‖f‖ ≤ ∫ bound < ∞` since `bound` is has_finite_integral -/ rw [hasFiniteIntegral_iff_norm] calc (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) ≤ ∫⁻ a, ENNReal.ofReal (bound a) ∂μ := lintegral_mono_ae <| all_ae_ofReal_f_le_bound h_bound h_lim _ < ∞ := by rw [← hasFiniteIntegral_iff_ofReal] · exact bound_hasFiniteIntegral exact (h_bound 0).mono fun a h => le_trans (norm_nonneg _) h #align measure_theory.has_finite_integral_of_dominated_convergence MeasureTheory.hasFiniteIntegral_of_dominated_convergence theorem tendsto_lintegral_norm_of_dominated_convergence {F : ℕ → α → β} {f : α → β} {bound : α → ℝ} (F_measurable : ∀ n, AEStronglyMeasurable (F n) μ) (bound_hasFiniteIntegral : HasFiniteIntegral bound μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, ENNReal.ofReal ‖F n a - f a‖ ∂μ) atTop (𝓝 0) := by have f_measurable : AEStronglyMeasurable f μ := aestronglyMeasurable_of_tendsto_ae _ F_measurable h_lim let b a := 2 * ENNReal.ofReal (bound a) /- `‖F n a‖ ≤ bound a` and `F n a --> f a` implies `‖f a‖ ≤ bound a`, and thus by the triangle inequality, have `‖F n a - f a‖ ≤ 2 * (bound a)`. -/ have hb : ∀ n, ∀ᵐ a ∂μ, ENNReal.ofReal ‖F n a - f a‖ ≤ b a := by intro n filter_upwards [all_ae_ofReal_F_le_bound h_bound n, all_ae_ofReal_f_le_bound h_bound h_lim] with a h₁ h₂ calc ENNReal.ofReal ‖F n a - f a‖ ≤ ENNReal.ofReal ‖F n a‖ + ENNReal.ofReal ‖f a‖ := by rw [← ENNReal.ofReal_add] · apply ofReal_le_ofReal apply norm_sub_le · exact norm_nonneg _ · exact norm_nonneg _ _ ≤ ENNReal.ofReal (bound a) + ENNReal.ofReal (bound a) := add_le_add h₁ h₂ _ = b a := by rw [← two_mul] -- On the other hand, `F n a --> f a` implies that `‖F n a - f a‖ --> 0` have h : ∀ᵐ a ∂μ, Tendsto (fun n => ENNReal.ofReal ‖F n a - f a‖) atTop (𝓝 0) := by rw [← ENNReal.ofReal_zero] refine h_lim.mono fun a h => (continuous_ofReal.tendsto _).comp ?_ rwa [← tendsto_iff_norm_sub_tendsto_zero] /- Therefore, by the dominated convergence theorem for nonnegative integration, have ` ∫ ‖f a - F n a‖ --> 0 ` -/ suffices Tendsto (fun n => ∫⁻ a, ENNReal.ofReal ‖F n a - f a‖ ∂μ) atTop (𝓝 (∫⁻ _ : α, 0 ∂μ)) by rwa [lintegral_zero] at this -- Using the dominated convergence theorem. refine tendsto_lintegral_of_dominated_convergence' _ ?_ hb ?_ ?_ -- Show `fun a => ‖f a - F n a‖` is almost everywhere measurable for all `n` · exact fun n => measurable_ofReal.comp_aemeasurable ((F_measurable n).sub f_measurable).norm.aemeasurable -- Show `2 * bound` `HasFiniteIntegral` · rw [hasFiniteIntegral_iff_ofReal] at bound_hasFiniteIntegral · calc ∫⁻ a, b a ∂μ = 2 * ∫⁻ a, ENNReal.ofReal (bound a) ∂μ := by rw [lintegral_const_mul'] exact coe_ne_top _ ≠ ∞ := mul_ne_top coe_ne_top bound_hasFiniteIntegral.ne filter_upwards [h_bound 0] with _ h using le_trans (norm_nonneg _) h -- Show `‖f a - F n a‖ --> 0` · exact h #align measure_theory.tendsto_lintegral_norm_of_dominated_convergence MeasureTheory.tendsto_lintegral_norm_of_dominated_convergence end DominatedConvergence section PosPart /-! Lemmas used for defining the positive part of an `L¹` function -/ theorem HasFiniteIntegral.max_zero {f : α → ℝ} (hf : HasFiniteIntegral f μ) : HasFiniteIntegral (fun a => max (f a) 0) μ := hf.mono <| eventually_of_forall fun x => by simp [abs_le, le_abs_self] #align measure_theory.has_finite_integral.max_zero MeasureTheory.HasFiniteIntegral.max_zero theorem HasFiniteIntegral.min_zero {f : α → ℝ} (hf : HasFiniteIntegral f μ) : HasFiniteIntegral (fun a => min (f a) 0) μ := hf.mono <| eventually_of_forall fun x => by simpa [abs_le] using neg_abs_le _ #align measure_theory.has_finite_integral.min_zero MeasureTheory.HasFiniteIntegral.min_zero end PosPart section NormedSpace variable {𝕜 : Type*} theorem HasFiniteIntegral.smul [NormedAddCommGroup 𝕜] [SMulZeroClass 𝕜 β] [BoundedSMul 𝕜 β] (c : 𝕜) {f : α → β} : HasFiniteIntegral f μ → HasFiniteIntegral (c • f) μ := by simp only [HasFiniteIntegral]; intro hfi calc (∫⁻ a : α, ‖c • f a‖₊ ∂μ) ≤ ∫⁻ a : α, ‖c‖₊ * ‖f a‖₊ ∂μ := by refine lintegral_mono ?_ intro i -- After leanprover/lean4#2734, we need to do beta reduction `exact mod_cast` beta_reduce exact mod_cast (nnnorm_smul_le c (f i)) _ < ∞ := by rw [lintegral_const_mul'] exacts [mul_lt_top coe_ne_top hfi.ne, coe_ne_top] #align measure_theory.has_finite_integral.smul MeasureTheory.HasFiniteIntegral.smul theorem hasFiniteIntegral_smul_iff [NormedRing 𝕜] [MulActionWithZero 𝕜 β] [BoundedSMul 𝕜 β] {c : 𝕜} (hc : IsUnit c) (f : α → β) : HasFiniteIntegral (c • f) μ ↔ HasFiniteIntegral f μ := by obtain ⟨c, rfl⟩ := hc constructor · intro h simpa only [smul_smul, Units.inv_mul, one_smul] using h.smul ((c⁻¹ : 𝕜ˣ) : 𝕜) exact HasFiniteIntegral.smul _ #align measure_theory.has_finite_integral_smul_iff MeasureTheory.hasFiniteIntegral_smul_iff theorem HasFiniteIntegral.const_mul [NormedRing 𝕜] {f : α → 𝕜} (h : HasFiniteIntegral f μ) (c : 𝕜) : HasFiniteIntegral (fun x => c * f x) μ := h.smul c #align measure_theory.has_finite_integral.const_mul MeasureTheory.HasFiniteIntegral.const_mul theorem HasFiniteIntegral.mul_const [NormedRing 𝕜] {f : α → 𝕜} (h : HasFiniteIntegral f μ) (c : 𝕜) : HasFiniteIntegral (fun x => f x * c) μ := h.smul (MulOpposite.op c) #align measure_theory.has_finite_integral.mul_const MeasureTheory.HasFiniteIntegral.mul_const end NormedSpace /-! ### The predicate `Integrable` -/ -- variable [MeasurableSpace β] [MeasurableSpace γ] [MeasurableSpace δ] /-- `Integrable f μ` means that `f` is measurable and that the integral `∫⁻ a, ‖f a‖ ∂μ` is finite. `Integrable f` means `Integrable f volume`. -/ def Integrable {α} {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := AEStronglyMeasurable f μ ∧ HasFiniteIntegral f μ #align measure_theory.integrable MeasureTheory.Integrable theorem memℒp_one_iff_integrable {f : α → β} : Memℒp f 1 μ ↔ Integrable f μ := by simp_rw [Integrable, HasFiniteIntegral, Memℒp, snorm_one_eq_lintegral_nnnorm] #align measure_theory.mem_ℒp_one_iff_integrable MeasureTheory.memℒp_one_iff_integrable theorem Integrable.aestronglyMeasurable {f : α → β} (hf : Integrable f μ) : AEStronglyMeasurable f μ := hf.1 #align measure_theory.integrable.ae_strongly_measurable MeasureTheory.Integrable.aestronglyMeasurable theorem Integrable.aemeasurable [MeasurableSpace β] [BorelSpace β] {f : α → β} (hf : Integrable f μ) : AEMeasurable f μ := hf.aestronglyMeasurable.aemeasurable #align measure_theory.integrable.ae_measurable MeasureTheory.Integrable.aemeasurable theorem Integrable.hasFiniteIntegral {f : α → β} (hf : Integrable f μ) : HasFiniteIntegral f μ := hf.2 #align measure_theory.integrable.has_finite_integral MeasureTheory.Integrable.hasFiniteIntegral theorem Integrable.mono {f : α → β} {g : α → γ} (hg : Integrable g μ) (hf : AEStronglyMeasurable f μ) (h : ∀ᵐ a ∂μ, ‖f a‖ ≤ ‖g a‖) : Integrable f μ := ⟨hf, hg.hasFiniteIntegral.mono h⟩ #align measure_theory.integrable.mono MeasureTheory.Integrable.mono theorem Integrable.mono' {f : α → β} {g : α → ℝ} (hg : Integrable g μ) (hf : AEStronglyMeasurable f μ) (h : ∀ᵐ a ∂μ, ‖f a‖ ≤ g a) : Integrable f μ := ⟨hf, hg.hasFiniteIntegral.mono' h⟩ #align measure_theory.integrable.mono' MeasureTheory.Integrable.mono' theorem Integrable.congr' {f : α → β} {g : α → γ} (hf : Integrable f μ) (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : Integrable g μ := ⟨hg, hf.hasFiniteIntegral.congr' h⟩ #align measure_theory.integrable.congr' MeasureTheory.Integrable.congr' theorem integrable_congr' {f : α → β} {g : α → γ} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : Integrable f μ ↔ Integrable g μ := ⟨fun h2f => h2f.congr' hg h, fun h2g => h2g.congr' hf <| EventuallyEq.symm h⟩ #align measure_theory.integrable_congr' MeasureTheory.integrable_congr' theorem Integrable.congr {f g : α → β} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : Integrable g μ := ⟨hf.1.congr h, hf.2.congr h⟩ #align measure_theory.integrable.congr MeasureTheory.Integrable.congr theorem integrable_congr {f g : α → β} (h : f =ᵐ[μ] g) : Integrable f μ ↔ Integrable g μ := ⟨fun hf => hf.congr h, fun hg => hg.congr h.symm⟩ #align measure_theory.integrable_congr MeasureTheory.integrable_congr theorem integrable_const_iff {c : β} : Integrable (fun _ : α => c) μ ↔ c = 0 ∨ μ univ < ∞ := by have : AEStronglyMeasurable (fun _ : α => c) μ := aestronglyMeasurable_const rw [Integrable, and_iff_right this, hasFiniteIntegral_const_iff] #align measure_theory.integrable_const_iff MeasureTheory.integrable_const_iff @[simp] theorem integrable_const [IsFiniteMeasure μ] (c : β) : Integrable (fun _ : α => c) μ := integrable_const_iff.2 <| Or.inr <| measure_lt_top _ _ #align measure_theory.integrable_const MeasureTheory.integrable_const @[simp] theorem Integrable.of_finite [Finite α] [MeasurableSpace α] [MeasurableSingletonClass α] (μ : Measure α) [IsFiniteMeasure μ] (f : α → β) : Integrable (fun a ↦ f a) μ := ⟨(StronglyMeasurable.of_finite f).aestronglyMeasurable, .of_finite⟩ @[deprecated (since := "2024-02-05")] alias integrable_of_fintype := Integrable.of_finite theorem Memℒp.integrable_norm_rpow {f : α → β} {p : ℝ≥0∞} (hf : Memℒp f p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : Integrable (fun x : α => ‖f x‖ ^ p.toReal) μ := by rw [← memℒp_one_iff_integrable] exact hf.norm_rpow hp_ne_zero hp_ne_top #align measure_theory.mem_ℒp.integrable_norm_rpow MeasureTheory.Memℒp.integrable_norm_rpow theorem Memℒp.integrable_norm_rpow' [IsFiniteMeasure μ] {f : α → β} {p : ℝ≥0∞} (hf : Memℒp f p μ) : Integrable (fun x : α => ‖f x‖ ^ p.toReal) μ := by by_cases h_zero : p = 0 · simp [h_zero, integrable_const] by_cases h_top : p = ∞ · simp [h_top, integrable_const] exact hf.integrable_norm_rpow h_zero h_top #align measure_theory.mem_ℒp.integrable_norm_rpow' MeasureTheory.Memℒp.integrable_norm_rpow' theorem Integrable.mono_measure {f : α → β} (h : Integrable f ν) (hμ : μ ≤ ν) : Integrable f μ := ⟨h.aestronglyMeasurable.mono_measure hμ, h.hasFiniteIntegral.mono_measure hμ⟩ #align measure_theory.integrable.mono_measure MeasureTheory.Integrable.mono_measure theorem Integrable.of_measure_le_smul {μ' : Measure α} (c : ℝ≥0∞) (hc : c ≠ ∞) (hμ'_le : μ' ≤ c • μ) {f : α → β} (hf : Integrable f μ) : Integrable f μ' := by rw [← memℒp_one_iff_integrable] at hf ⊢ exact hf.of_measure_le_smul c hc hμ'_le #align measure_theory.integrable.of_measure_le_smul MeasureTheory.Integrable.of_measure_le_smul theorem Integrable.add_measure {f : α → β} (hμ : Integrable f μ) (hν : Integrable f ν) : Integrable f (μ + ν) := by simp_rw [← memℒp_one_iff_integrable] at hμ hν ⊢ refine ⟨hμ.aestronglyMeasurable.add_measure hν.aestronglyMeasurable, ?_⟩ rw [snorm_one_add_measure, ENNReal.add_lt_top] exact ⟨hμ.snorm_lt_top, hν.snorm_lt_top⟩ #align measure_theory.integrable.add_measure MeasureTheory.Integrable.add_measure theorem Integrable.left_of_add_measure {f : α → β} (h : Integrable f (μ + ν)) : Integrable f μ := by rw [← memℒp_one_iff_integrable] at h ⊢ exact h.left_of_add_measure #align measure_theory.integrable.left_of_add_measure MeasureTheory.Integrable.left_of_add_measure theorem Integrable.right_of_add_measure {f : α → β} (h : Integrable f (μ + ν)) : Integrable f ν := by rw [← memℒp_one_iff_integrable] at h ⊢ exact h.right_of_add_measure #align measure_theory.integrable.right_of_add_measure MeasureTheory.Integrable.right_of_add_measure @[simp] theorem integrable_add_measure {f : α → β} : Integrable f (μ + ν) ↔ Integrable f μ ∧ Integrable f ν := ⟨fun h => ⟨h.left_of_add_measure, h.right_of_add_measure⟩, fun h => h.1.add_measure h.2⟩ #align measure_theory.integrable_add_measure MeasureTheory.integrable_add_measure @[simp] theorem integrable_zero_measure {_ : MeasurableSpace α} {f : α → β} : Integrable f (0 : Measure α) := ⟨aestronglyMeasurable_zero_measure f, hasFiniteIntegral_zero_measure f⟩ #align measure_theory.integrable_zero_measure MeasureTheory.integrable_zero_measure theorem integrable_finset_sum_measure {ι} {m : MeasurableSpace α} {f : α → β} {μ : ι → Measure α} {s : Finset ι} : Integrable f (∑ i ∈ s, μ i) ↔ ∀ i ∈ s, Integrable f (μ i) := by induction s using Finset.induction_on <;> simp [*] #align measure_theory.integrable_finset_sum_measure MeasureTheory.integrable_finset_sum_measure theorem Integrable.smul_measure {f : α → β} (h : Integrable f μ) {c : ℝ≥0∞} (hc : c ≠ ∞) : Integrable f (c • μ) := by rw [← memℒp_one_iff_integrable] at h ⊢ exact h.smul_measure hc #align measure_theory.integrable.smul_measure MeasureTheory.Integrable.smul_measure
Mathlib/MeasureTheory/Function/L1Space.lean
572
575
theorem Integrable.smul_measure_nnreal {f : α → β} (h : Integrable f μ) {c : ℝ≥0} : Integrable f (c • μ) := by
apply h.smul_measure simp
/- 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.FieldTheory.Finite.Polynomial import Mathlib.NumberTheory.Basic import Mathlib.RingTheory.WittVector.WittPolynomial #align_import ring_theory.witt_vector.structure_polynomial from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Witt structure polynomials In this file we prove the main theorem that makes the whole theory of Witt vectors work. Briefly, consider a polynomial `Φ : MvPolynomial idx ℤ` over the integers, with polynomials variables indexed by an arbitrary type `idx`. Then there exists a unique family of polynomials `φ : ℕ → MvPolynomial (idx × ℕ) Φ` such that for all `n : ℕ` we have (`wittStructureInt_existsUnique`) ``` bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℤ n))) Φ ``` In other words: evaluating the `n`-th Witt polynomial on the family `φ` is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials. N.b.: As far as we know, these polynomials do not have a name in the literature, so we have decided to call them the “Witt structure polynomials”. See `wittStructureInt`. ## Special cases With the main result of this file in place, we apply it to certain special polynomials. For example, by taking `Φ = X tt + X ff` resp. `Φ = X tt * X ff` we obtain families of polynomials `witt_add` resp. `witt_mul` (with type `ℕ → MvPolynomial (Bool × ℕ) ℤ`) that will be used in later files to define the addition and multiplication on the ring of Witt vectors. ## Outline of the proof The proof of `wittStructureInt_existsUnique` is rather technical, and takes up most of this file. We start by proving the analogous version for polynomials with rational coefficients, instead of integer coefficients. In this case, the solution is rather easy, since the Witt polynomials form a faithful change of coordinates in the polynomial ring `MvPolynomial ℕ ℚ`. We therefore obtain a family of polynomials `wittStructureRat Φ` for every `Φ : MvPolynomial idx ℚ`. If `Φ` has integer coefficients, then the polynomials `wittStructureRat Φ n` do so as well. Proving this claim is the essential core of this file, and culminates in `map_wittStructureInt`, which proves that upon mapping the coefficients of `wittStructureInt Φ n` from the integers to the rationals, one obtains `wittStructureRat Φ n`. Ultimately, the proof of `map_wittStructureInt` relies on ``` dvd_sub_pow_of_dvd_sub {R : Type*} [CommRing R] {p : ℕ} {a b : R} : (p : R) ∣ a - b → ∀ (k : ℕ), (p : R) ^ (k + 1) ∣ a ^ p ^ k - b ^ p ^ k ``` ## Main results * `wittStructureRat Φ`: the family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℚ` associated with `Φ : MvPolynomial idx ℚ` and satisfying the property explained above. * `wittStructureRat_prop`: the proof that `wittStructureRat` indeed satisfies the property. * `wittStructureInt Φ`: the family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℤ` associated with `Φ : MvPolynomial idx ℤ` and satisfying the property explained above. * `map_wittStructureInt`: the proof that the integral polynomials `with_structure_int Φ` are equal to `wittStructureRat Φ` when mapped to polynomials with rational coefficients. * `wittStructureInt_prop`: the proof that `wittStructureInt` indeed satisfies the property. * Five families of polynomials that will be used to define the ring structure on the ring of Witt vectors: - `WittVector.wittZero` - `WittVector.wittOne` - `WittVector.wittAdd` - `WittVector.wittMul` - `WittVector.wittNeg` (We also define `WittVector.wittSub`, and later we will prove that it describes subtraction, which is defined as `fun a b ↦ a + -b`. See `WittVector.sub_coeff` for this proof.) ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ open MvPolynomial Set open Finset (range) open Finsupp (single) -- This lemma reduces a bundled morphism to a "mere" function, -- and consequently the simplifier cannot use a lot of powerful simp-lemmas. -- We disable this locally, and probably it should be disabled globally in mathlib. attribute [-simp] coe_eval₂Hom variable {p : ℕ} {R : Type*} {idx : Type*} [CommRing R] open scoped Witt section PPrime variable (p) [hp : Fact p.Prime] -- Notation with ring of coefficients explicit set_option quotPrecheck false in @[inherit_doc] scoped[Witt] notation "W_" => wittPolynomial p -- Notation with ring of coefficients implicit set_option quotPrecheck false in @[inherit_doc] scoped[Witt] notation "W" => wittPolynomial p _ /-- `wittStructureRat Φ` is a family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℚ` that are uniquely characterised by the property that ``` bind₁ (wittStructureRat p Φ) (wittPolynomial p ℚ n) = bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℚ n))) Φ ``` In other words: evaluating the `n`-th Witt polynomial on the family `wittStructureRat Φ` is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials. See `wittStructureRat_prop` for this property, and `wittStructureRat_existsUnique` for the fact that `wittStructureRat` gives the unique family of polynomials with this property. These polynomials turn out to have integral coefficients, but it requires some effort to show this. See `wittStructureInt` for the version with integral coefficients, and `map_wittStructureInt` for the fact that it is equal to `wittStructureRat` when mapped to polynomials over the rationals. -/ noncomputable def wittStructureRat (Φ : MvPolynomial idx ℚ) (n : ℕ) : MvPolynomial (idx × ℕ) ℚ := bind₁ (fun k => bind₁ (fun i => rename (Prod.mk i) (W_ ℚ k)) Φ) (xInTermsOfW p ℚ n) #align witt_structure_rat wittStructureRat theorem wittStructureRat_prop (Φ : MvPolynomial idx ℚ) (n : ℕ) : bind₁ (wittStructureRat p Φ) (W_ ℚ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ := calc bind₁ (wittStructureRat p Φ) (W_ ℚ n) = bind₁ (fun k => bind₁ (fun i => (rename (Prod.mk i)) (W_ ℚ k)) Φ) (bind₁ (xInTermsOfW p ℚ) (W_ ℚ n)) := by rw [bind₁_bind₁]; exact eval₂Hom_congr (RingHom.ext_rat _ _) rfl rfl _ = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ := by rw [bind₁_xInTermsOfW_wittPolynomial p _ n, bind₁_X_right] #align witt_structure_rat_prop wittStructureRat_prop theorem wittStructureRat_existsUnique (Φ : MvPolynomial idx ℚ) : ∃! φ : ℕ → MvPolynomial (idx × ℕ) ℚ, ∀ n : ℕ, bind₁ φ (W_ ℚ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ := by refine ⟨wittStructureRat p Φ, ?_, ?_⟩ · intro n; apply wittStructureRat_prop · intro φ H funext n rw [show φ n = bind₁ φ (bind₁ (W_ ℚ) (xInTermsOfW p ℚ n)) by rw [bind₁_wittPolynomial_xInTermsOfW p, bind₁_X_right]] rw [bind₁_bind₁] exact eval₂Hom_congr (RingHom.ext_rat _ _) (funext H) rfl #align witt_structure_rat_exists_unique wittStructureRat_existsUnique theorem wittStructureRat_rec_aux (Φ : MvPolynomial idx ℚ) (n : ℕ) : wittStructureRat p Φ n * C ((p : ℚ) ^ n) = bind₁ (fun b => rename (fun i => (b, i)) (W_ ℚ n)) Φ - ∑ i ∈ range n, C ((p : ℚ) ^ i) * wittStructureRat p Φ i ^ p ^ (n - i) := by have := xInTermsOfW_aux p ℚ n replace := congr_arg (bind₁ fun k : ℕ => bind₁ (fun i => rename (Prod.mk i) (W_ ℚ k)) Φ) this rw [AlgHom.map_mul, bind₁_C_right] at this rw [wittStructureRat, this]; clear this conv_lhs => simp only [AlgHom.map_sub, bind₁_X_right] rw [sub_right_inj] simp only [AlgHom.map_sum, AlgHom.map_mul, bind₁_C_right, AlgHom.map_pow] rfl #align witt_structure_rat_rec_aux wittStructureRat_rec_aux /-- Write `wittStructureRat p φ n` in terms of `wittStructureRat p φ i` for `i < n`. -/ theorem wittStructureRat_rec (Φ : MvPolynomial idx ℚ) (n : ℕ) : wittStructureRat p Φ n = C (1 / (p : ℚ) ^ n) * (bind₁ (fun b => rename (fun i => (b, i)) (W_ ℚ n)) Φ - ∑ i ∈ range n, C ((p : ℚ) ^ i) * wittStructureRat p Φ i ^ p ^ (n - i)) := by calc wittStructureRat p Φ n = C (1 / (p : ℚ) ^ n) * (wittStructureRat p Φ n * C ((p : ℚ) ^ n)) := ?_ _ = _ := by rw [wittStructureRat_rec_aux] rw [mul_left_comm, ← C_mul, div_mul_cancel₀, C_1, mul_one] exact pow_ne_zero _ (Nat.cast_ne_zero.2 hp.1.ne_zero) #align witt_structure_rat_rec wittStructureRat_rec /-- `wittStructureInt Φ` is a family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℤ` that are uniquely characterised by the property that ``` bind₁ (wittStructureInt p Φ) (wittPolynomial p ℤ n) = bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℤ n))) Φ ``` In other words: evaluating the `n`-th Witt polynomial on the family `wittStructureInt Φ` is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials. See `wittStructureInt_prop` for this property, and `wittStructureInt_existsUnique` for the fact that `wittStructureInt` gives the unique family of polynomials with this property. -/ noncomputable def wittStructureInt (Φ : MvPolynomial idx ℤ) (n : ℕ) : MvPolynomial (idx × ℕ) ℤ := Finsupp.mapRange Rat.num (Rat.num_intCast 0) (wittStructureRat p (map (Int.castRingHom ℚ) Φ) n) #align witt_structure_int wittStructureInt variable {p} theorem bind₁_rename_expand_wittPolynomial (Φ : MvPolynomial idx ℤ) (n : ℕ) (IH : ∀ m : ℕ, m < n + 1 → map (Int.castRingHom ℚ) (wittStructureInt p Φ m) = wittStructureRat p (map (Int.castRingHom ℚ) Φ) m) : bind₁ (fun b => rename (fun i => (b, i)) (expand p (W_ ℤ n))) Φ = bind₁ (fun i => expand p (wittStructureInt p Φ i)) (W_ ℤ n) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [map_bind₁, map_rename, map_expand, rename_expand, map_wittPolynomial] have key := (wittStructureRat_prop p (map (Int.castRingHom ℚ) Φ) n).symm apply_fun expand p at key simp only [expand_bind₁] at key rw [key]; clear key apply eval₂Hom_congr' rfl _ rfl rintro i hi - rw [wittPolynomial_vars, Finset.mem_range] at hi simp only [IH i hi] #align bind₁_rename_expand_witt_polynomial bind₁_rename_expand_wittPolynomial theorem C_p_pow_dvd_bind₁_rename_wittPolynomial_sub_sum (Φ : MvPolynomial idx ℤ) (n : ℕ) (IH : ∀ m : ℕ, m < n → map (Int.castRingHom ℚ) (wittStructureInt p Φ m) = wittStructureRat p (map (Int.castRingHom ℚ) Φ) m) : (C ((p ^ n :) : ℤ) : MvPolynomial (idx × ℕ) ℤ) ∣ bind₁ (fun b : idx => rename (fun i => (b, i)) (wittPolynomial p ℤ n)) Φ - ∑ i ∈ range n, C ((p : ℤ) ^ i) * wittStructureInt p Φ i ^ p ^ (n - i) := by cases' n with n · simp only [isUnit_one, Int.ofNat_zero, Int.ofNat_succ, zero_add, pow_zero, C_1, IsUnit.dvd, Nat.cast_one, Nat.zero_eq] -- prepare a useful equation for rewriting have key := bind₁_rename_expand_wittPolynomial Φ n IH apply_fun map (Int.castRingHom (ZMod (p ^ (n + 1)))) at key conv_lhs at key => simp only [map_bind₁, map_rename, map_expand, map_wittPolynomial] -- clean up and massage rw [C_dvd_iff_zmod, RingHom.map_sub, sub_eq_zero, map_bind₁] simp only [map_rename, map_wittPolynomial, wittPolynomial_zmod_self] rw [key]; clear key IH rw [bind₁, aeval_wittPolynomial, map_sum, map_sum, Finset.sum_congr rfl] intro k hk rw [Finset.mem_range, Nat.lt_succ_iff] at hk -- Porting note (#11083): was much slower -- simp only [← sub_eq_zero, ← RingHom.map_sub, ← C_dvd_iff_zmod, C_eq_coe_nat, ← mul_sub, ← -- Nat.cast_pow] rw [← sub_eq_zero, ← RingHom.map_sub, ← C_dvd_iff_zmod, C_eq_coe_nat, ← Nat.cast_pow, ← Nat.cast_pow, C_eq_coe_nat, ← mul_sub] have : p ^ (n + 1) = p ^ k * p ^ (n - k + 1) := by rw [← pow_add, ← add_assoc]; congr 2; rw [add_comm, ← tsub_eq_iff_eq_add_of_le hk] rw [this] rw [Nat.cast_mul, Nat.cast_pow, Nat.cast_pow] apply mul_dvd_mul_left ((p : MvPolynomial (idx × ℕ) ℤ) ^ k) rw [show p ^ (n + 1 - k) = p * p ^ (n - k) by rw [← pow_succ', ← tsub_add_eq_add_tsub hk]] rw [pow_mul] -- the machine! apply dvd_sub_pow_of_dvd_sub rw [← C_eq_coe_nat, C_dvd_iff_zmod, RingHom.map_sub, sub_eq_zero, map_expand, RingHom.map_pow, MvPolynomial.expand_zmod] set_option linter.uppercaseLean3 false in #align C_p_pow_dvd_bind₁_rename_witt_polynomial_sub_sum C_p_pow_dvd_bind₁_rename_wittPolynomial_sub_sum variable (p) @[simp] theorem map_wittStructureInt (Φ : MvPolynomial idx ℤ) (n : ℕ) : map (Int.castRingHom ℚ) (wittStructureInt p Φ n) = wittStructureRat p (map (Int.castRingHom ℚ) Φ) n := by induction n using Nat.strong_induction_on with | h n IH => ?_ rw [wittStructureInt, map_mapRange_eq_iff, Int.coe_castRingHom] intro c rw [wittStructureRat_rec, coeff_C_mul, mul_comm, mul_div_assoc', mul_one] have sum_induction_steps : map (Int.castRingHom ℚ) (∑ i ∈ range n, C ((p : ℤ) ^ i) * wittStructureInt p Φ i ^ p ^ (n - i)) = ∑ i ∈ range n, C ((p : ℚ) ^ i) * wittStructureRat p (map (Int.castRingHom ℚ) Φ) i ^ p ^ (n - i) := by rw [map_sum] apply Finset.sum_congr rfl intro i hi rw [Finset.mem_range] at hi simp only [IH i hi, RingHom.map_mul, RingHom.map_pow, map_C] rfl simp only [← sum_induction_steps, ← map_wittPolynomial p (Int.castRingHom ℚ), ← map_rename, ← map_bind₁, ← RingHom.map_sub, coeff_map] rw [show (p : ℚ) ^ n = ((↑(p ^ n) : ℤ) : ℚ) by norm_cast] rw [← Rat.den_eq_one_iff, eq_intCast, Rat.den_div_intCast_eq_one_iff] swap; · exact mod_cast pow_ne_zero n hp.1.ne_zero revert c; rw [← C_dvd_iff_dvd_coeff] exact C_p_pow_dvd_bind₁_rename_wittPolynomial_sub_sum Φ n IH #align map_witt_structure_int map_wittStructureInt theorem wittStructureInt_prop (Φ : MvPolynomial idx ℤ) (n) : bind₁ (wittStructureInt p Φ) (wittPolynomial p ℤ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℤ n)) Φ := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective have := wittStructureRat_prop p (map (Int.castRingHom ℚ) Φ) n simpa only [map_bind₁, ← eval₂Hom_map_hom, eval₂Hom_C_left, map_rename, map_wittPolynomial, AlgHom.coe_toRingHom, map_wittStructureInt] #align witt_structure_int_prop wittStructureInt_prop theorem eq_wittStructureInt (Φ : MvPolynomial idx ℤ) (φ : ℕ → MvPolynomial (idx × ℕ) ℤ) (h : ∀ n, bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℤ n)) Φ) : φ = wittStructureInt p Φ := by funext k apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective rw [map_wittStructureInt] -- Porting note: was `refine' congr_fun _ k` revert k refine congr_fun ?_ apply ExistsUnique.unique (wittStructureRat_existsUnique p (map (Int.castRingHom ℚ) Φ)) · intro n specialize h n apply_fun map (Int.castRingHom ℚ) at h simpa only [map_bind₁, ← eval₂Hom_map_hom, eval₂Hom_C_left, map_rename, map_wittPolynomial, AlgHom.coe_toRingHom] using h · intro n; apply wittStructureRat_prop #align eq_witt_structure_int eq_wittStructureInt theorem wittStructureInt_existsUnique (Φ : MvPolynomial idx ℤ) : ∃! φ : ℕ → MvPolynomial (idx × ℕ) ℤ, ∀ n : ℕ, bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i : idx => rename (Prod.mk i) (W_ ℤ n)) Φ := ⟨wittStructureInt p Φ, wittStructureInt_prop _ _, eq_wittStructureInt _ _⟩ #align witt_structure_int_exists_unique wittStructureInt_existsUnique theorem witt_structure_prop (Φ : MvPolynomial idx ℤ) (n) : aeval (fun i => map (Int.castRingHom R) (wittStructureInt p Φ i)) (wittPolynomial p ℤ n) = aeval (fun i => rename (Prod.mk i) (W n)) Φ := by convert congr_arg (map (Int.castRingHom R)) (wittStructureInt_prop p Φ n) using 1 <;> rw [hom_bind₁] <;> apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl · rfl · simp only [map_rename, map_wittPolynomial] #align witt_structure_prop witt_structure_prop theorem wittStructureInt_rename {σ : Type*} (Φ : MvPolynomial idx ℤ) (f : idx → σ) (n : ℕ) : wittStructureInt p (rename f Φ) n = rename (Prod.map f id) (wittStructureInt p Φ n) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [map_rename, map_wittStructureInt, wittStructureRat, rename_bind₁, rename_rename, bind₁_rename] rfl #align witt_structure_int_rename wittStructureInt_rename @[simp] theorem constantCoeff_wittStructureRat_zero (Φ : MvPolynomial idx ℚ) : constantCoeff (wittStructureRat p Φ 0) = constantCoeff Φ := by simp only [wittStructureRat, bind₁, map_aeval, xInTermsOfW_zero, constantCoeff_rename, constantCoeff_wittPolynomial, aeval_X, constantCoeff_comp_algebraMap, eval₂Hom_zero'_apply, RingHom.id_apply] #align constant_coeff_witt_structure_rat_zero constantCoeff_wittStructureRat_zero theorem constantCoeff_wittStructureRat (Φ : MvPolynomial idx ℚ) (h : constantCoeff Φ = 0) (n : ℕ) : constantCoeff (wittStructureRat p Φ n) = 0 := by simp only [wittStructureRat, eval₂Hom_zero'_apply, h, bind₁, map_aeval, constantCoeff_rename, constantCoeff_wittPolynomial, constantCoeff_comp_algebraMap, RingHom.id_apply, constantCoeff_xInTermsOfW] #align constant_coeff_witt_structure_rat constantCoeff_wittStructureRat @[simp] theorem constantCoeff_wittStructureInt_zero (Φ : MvPolynomial idx ℤ) : constantCoeff (wittStructureInt p Φ 0) = constantCoeff Φ := by have inj : Function.Injective (Int.castRingHom ℚ) := by intro m n; exact Int.cast_inj.mp apply inj rw [← constantCoeff_map, map_wittStructureInt, constantCoeff_wittStructureRat_zero, constantCoeff_map] #align constant_coeff_witt_structure_int_zero constantCoeff_wittStructureInt_zero theorem constantCoeff_wittStructureInt (Φ : MvPolynomial idx ℤ) (h : constantCoeff Φ = 0) (n : ℕ) : constantCoeff (wittStructureInt p Φ n) = 0 := by have inj : Function.Injective (Int.castRingHom ℚ) := by intro m n; exact Int.cast_inj.mp apply inj rw [← constantCoeff_map, map_wittStructureInt, constantCoeff_wittStructureRat, RingHom.map_zero] rw [constantCoeff_map, h, RingHom.map_zero] #align constant_coeff_witt_structure_int constantCoeff_wittStructureInt variable (R) -- we could relax the fintype on `idx`, but then we need to cast from finset to set. -- for our applications `idx` is always finite.
Mathlib/RingTheory/WittVector/StructurePolynomial.lean
389
400
theorem wittStructureRat_vars [Fintype idx] (Φ : MvPolynomial idx ℚ) (n : ℕ) : (wittStructureRat p Φ n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) := by
rw [wittStructureRat] intro x hx simp only [Finset.mem_product, true_and_iff, Finset.mem_univ, Finset.mem_range] obtain ⟨k, hk, hx'⟩ := mem_vars_bind₁ _ _ hx obtain ⟨i, -, hx''⟩ := mem_vars_bind₁ _ _ hx' obtain ⟨j, hj, rfl⟩ := mem_vars_rename _ _ hx'' rw [wittPolynomial_vars, Finset.mem_range] at hj replace hk := xInTermsOfW_vars_subset p _ hk rw [Finset.mem_range] at hk exact lt_of_lt_of_le hj hk
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Reid Barton -/ import Mathlib.Data.TypeMax import Mathlib.Logic.UnivLE import Mathlib.CategoryTheory.Limits.Shapes.Images #align_import category_theory.limits.types from "leanprover-community/mathlib"@"4aa2a2e17940311e47007f087c9df229e7f12942" /-! # Limits in the category of types. We show that the category of types has all (co)limits, by providing the usual concrete models. Next, we prove the category of types has categorical images, and that these agree with the range of a function. Finally, we give the natural isomorphism between cones on `F` with cone point `X` and the type `lim Hom(X, F·)`, and similarly the natural isomorphism between cocones on `F` with cocone point `X` and the type `lim Hom(F·, X)`. -/ open CategoryTheory CategoryTheory.Limits universe v u w namespace CategoryTheory.Limits namespace Types section limit_characterization variable {J : Type v} [Category.{w} J] {F : J ⥤ Type u} /-- Given a section of a functor F into `Type*`, construct a cone over F with `PUnit` as the cone point. -/ def coneOfSection {s} (hs : s ∈ F.sections) : Cone F where pt := PUnit π := { app := fun j _ ↦ s j, naturality := fun i j f ↦ by ext; exact (hs f).symm } /-- Given a cone over a functor F into `Type*` and an element in the cone point, construct a section of F. -/ def sectionOfCone (c : Cone F) (x : c.pt) : F.sections := ⟨fun j ↦ c.π.app j x, fun f ↦ congr_fun (c.π.naturality f).symm x⟩ theorem isLimit_iff (c : Cone F) : Nonempty (IsLimit c) ↔ ∀ s ∈ F.sections, ∃! x : c.pt, ∀ j, c.π.app j x = s j := by refine ⟨fun ⟨t⟩ s hs ↦ ?_, fun h ↦ ⟨?_⟩⟩ · let cs := coneOfSection hs exact ⟨t.lift cs ⟨⟩, fun j ↦ congr_fun (t.fac cs j) ⟨⟩, fun x hx ↦ congr_fun (t.uniq cs (fun _ ↦ x) fun j ↦ funext fun _ ↦ hx j) ⟨⟩⟩ · choose x hx using fun c y ↦ h _ (sectionOfCone c y).2 exact ⟨x, fun c j ↦ funext fun y ↦ (hx c y).1 j, fun c f hf ↦ funext fun y ↦ (hx c y).2 (f y) (fun j ↦ congr_fun (hf j) y)⟩ theorem isLimit_iff_bijective_sectionOfCone (c : Cone F) : Nonempty (IsLimit c) ↔ (Types.sectionOfCone c).Bijective := by simp_rw [isLimit_iff, Function.bijective_iff_existsUnique, Subtype.forall, F.sections_ext_iff, sectionOfCone] /-- The equivalence between a limiting cone of `F` in `Type u` and the "concrete" definition as the sections of `F`. -/ noncomputable def isLimitEquivSections {c : Cone F} (t : IsLimit c) : c.pt ≃ F.sections where toFun := sectionOfCone c invFun s := t.lift (coneOfSection s.2) ⟨⟩ left_inv x := (congr_fun (t.uniq (coneOfSection _) (fun _ ↦ x) fun _ ↦ rfl) ⟨⟩).symm right_inv s := Subtype.ext (funext fun j ↦ congr_fun (t.fac (coneOfSection s.2) j) ⟨⟩) #align category_theory.limits.types.is_limit_equiv_sections CategoryTheory.Limits.Types.isLimitEquivSections @[simp] theorem isLimitEquivSections_apply {c : Cone F} (t : IsLimit c) (j : J) (x : c.pt) : (isLimitEquivSections t x : ∀ j, F.obj j) j = c.π.app j x := rfl #align category_theory.limits.types.is_limit_equiv_sections_apply CategoryTheory.Limits.Types.isLimitEquivSections_apply @[simp] theorem isLimitEquivSections_symm_apply {c : Cone F} (t : IsLimit c) (x : F.sections) (j : J) : c.π.app j ((isLimitEquivSections t).symm x) = (x : ∀ j, F.obj j) j := by conv_rhs => rw [← (isLimitEquivSections t).right_inv x] rfl #align category_theory.limits.types.is_limit_equiv_sections_symm_apply CategoryTheory.Limits.Types.isLimitEquivSections_symm_apply end limit_characterization variable {J : Type v} [Category.{w} J] /-! We now provide two distinct implementations in the category of types. The first, in the `CategoryTheory.Limits.Types.Small` namespace, assumes `Small.{u} J` and constructs `J`-indexed limits in `Type u`. The second, in the `CategoryTheory.Limits.Types.TypeMax` namespace constructs limits for functors `F : J ⥤ TypeMax.{v, u}`, for `J : Type v`. This construction is slightly nicer, as the limit is definitionally just `F.sections`, rather than `Shrink F.sections`, which makes an arbitrary choice of `u`-small representative. Hopefully we might be able to entirely remove the `TypeMax` constructions, but for now they are useful glue for the later parts of the library. -/ namespace Small variable (F : J ⥤ Type u) section variable [Small.{u} F.sections] /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone : Cone F where pt := Shrink F.sections π := { app := fun j u => ((equivShrink F.sections).symm u).val j naturality := fun j j' f => by funext x simp } @[ext] lemma limitCone_pt_ext {x y : (limitCone F).pt} (w : (equivShrink F.sections).symm x = (equivShrink F.sections).symm y) : x = y := by aesop /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit : IsLimit (limitCone.{v, u} F) where lift s v := equivShrink F.sections { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by ext x j simpa using congr_fun (w j) x end end Small theorem hasLimit_iff_small_sections (F : J ⥤ Type u): HasLimit F ↔ Small.{u} F.sections := ⟨fun _ => .mk ⟨_, ⟨(Equiv.ofBijective _ ((isLimit_iff_bijective_sectionOfCone (limit.cone F)).mp ⟨limit.isLimit _⟩)).symm⟩⟩, fun _ => ⟨_, Small.limitConeIsLimit F⟩⟩ -- TODO: If `UnivLE` works out well, we will eventually want to deprecate these -- definitions, and probably as a first step put them in namespace or otherwise rename them. section TypeMax /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone (F : J ⥤ TypeMax.{v, u}) : Cone F where pt := F.sections π := { app := fun j u => u.val j naturality := fun j j' f => by funext x simp } #align category_theory.limits.types.limit_cone CategoryTheory.Limits.Types.limitCone /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit (F : J ⥤ TypeMax.{v, u}) : IsLimit (limitCone F) where lift s v := { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by funext x apply Subtype.ext funext j exact congr_fun (w j) x #align category_theory.limits.types.limit_cone_is_limit CategoryTheory.Limits.Types.limitConeIsLimit end TypeMax /-! The results in this section have a `UnivLE.{v, u}` hypothesis, but as they only use the constructions from the `CategoryTheory.Limits.Types.UnivLE` namespace in their definitions (rather than their statements), we leave them in the main `CategoryTheory.Limits.Types` namespace. -/ section UnivLE open UnivLE instance hasLimit [Small.{u} J] (F : J ⥤ Type u) : HasLimit F := (hasLimit_iff_small_sections F).mpr inferInstance instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J (Type u) where /-- The category of types has all limits. More specifically, when `UnivLE.{v, u}`, the category `Type u` has all `v`-small limits. See <https://stacks.math.columbia.edu/tag/002U>. -/ instance (priority := 1300) hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} (Type u) where has_limits_of_shape _ := { } #align category_theory.limits.types.has_limits_of_size CategoryTheory.Limits.Types.hasLimitsOfSize variable (F : J ⥤ Type u) [HasLimit F] /-- The equivalence between the abstract limit of `F` in `TypeMax.{v, u}` and the "concrete" definition as the sections of `F`. -/ noncomputable def limitEquivSections : limit F ≃ F.sections := isLimitEquivSections (limit.isLimit F) #align category_theory.limits.types.limit_equiv_sections CategoryTheory.Limits.Types.limitEquivSections @[simp] theorem limitEquivSections_apply (x : limit F) (j : J) : ((limitEquivSections F) x : ∀ j, F.obj j) j = limit.π F j x := isLimitEquivSections_apply _ _ _ #align category_theory.limits.types.limit_equiv_sections_apply CategoryTheory.Limits.Types.limitEquivSections_apply @[simp] theorem limitEquivSections_symm_apply (x : F.sections) (j : J) : limit.π F j ((limitEquivSections F).symm x) = (x : ∀ j, F.obj j) j := isLimitEquivSections_symm_apply _ _ _ #align category_theory.limits.types.limit_equiv_sections_symm_apply CategoryTheory.Limits.Types.limitEquivSections_symm_apply -- Porting note: `limitEquivSections_symm_apply'` was removed because the linter -- complains it is unnecessary --@[simp] --theorem limitEquivSections_symm_apply' (F : J ⥤ Type v) (x : F.sections) (j : J) : -- limit.π F j ((limitEquivSections.{v, v} F).symm x) = (x : ∀ j, F.obj j) j := -- isLimitEquivSections_symm_apply _ _ _ --#align category_theory.limits.types.limit_equiv_sections_symm_apply' CategoryTheory.Limits.Types.limitEquivSections_symm_apply' -- Porting note (#11182): removed @[ext] /-- Construct a term of `limit F : Type u` from a family of terms `x : Π j, F.obj j` which are "coherent": `∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j'`. -/ noncomputable def Limit.mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') : limit F := (limitEquivSections F).symm ⟨x, h _ _⟩ #align category_theory.limits.types.limit.mk CategoryTheory.Limits.Types.Limit.mk @[simp] theorem Limit.π_mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') (j) : limit.π F j (Limit.mk F x h) = x j := by dsimp [Limit.mk] simp #align category_theory.limits.types.limit.π_mk CategoryTheory.Limits.Types.Limit.π_mk -- Porting note: `Limit.π_mk'` was removed because the linter complains it is unnecessary --@[simp] --theorem Limit.π_mk' (F : J ⥤ Type v) (x : ∀ j, F.obj j) -- (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') (j) : -- limit.π F j (Limit.mk.{v, v} F x h) = x j := by -- dsimp [Limit.mk] -- simp --#align category_theory.limits.types.limit.π_mk' CategoryTheory.Limits.Types.Limit.π_mk' -- PROJECT: prove this for concrete categories where the forgetful functor preserves limits @[ext] theorem limit_ext (x y : limit F) (w : ∀ j, limit.π F j x = limit.π F j y) : x = y := by apply (limitEquivSections F).injective ext j simp [w j] #align category_theory.limits.types.limit_ext CategoryTheory.Limits.Types.limit_ext @[ext] theorem limit_ext' (F : J ⥤ Type v) (x y : limit F) (w : ∀ j, limit.π F j x = limit.π F j y) : x = y := limit_ext F x y w #align category_theory.limits.types.limit_ext' CategoryTheory.Limits.Types.limit_ext' theorem limit_ext_iff (x y : limit F) : x = y ↔ ∀ j, limit.π F j x = limit.π F j y := ⟨fun t _ => t ▸ rfl, limit_ext _ _ _⟩ #align category_theory.limits.types.limit_ext_iff CategoryTheory.Limits.Types.limit_ext_iff theorem limit_ext_iff' (F : J ⥤ Type v) (x y : limit F) : x = y ↔ ∀ j, limit.π F j x = limit.π F j y := ⟨fun t _ => t ▸ rfl, limit_ext' _ _ _⟩ #align category_theory.limits.types.limit_ext_iff' CategoryTheory.Limits.Types.limit_ext_iff' -- TODO: are there other limits lemmas that should have `_apply` versions? -- Can we generate these like with `@[reassoc]`? -- PROJECT: prove these for any concrete category where the forgetful functor preserves limits? -- Porting note (#11119): @[simp] was removed because the linter said it was useless --@[simp] variable {F} in theorem Limit.w_apply {j j' : J} {x : limit F} (f : j ⟶ j') : F.map f (limit.π F j x) = limit.π F j' x := congr_fun (limit.w F f) x #align category_theory.limits.types.limit.w_apply CategoryTheory.Limits.Types.Limit.w_apply -- Porting note (#11119): @[simp] was removed because the linter said it was useless theorem Limit.lift_π_apply (s : Cone F) (j : J) (x : s.pt) : limit.π F j (limit.lift F s x) = s.π.app j x := congr_fun (limit.lift_π s j) x #align category_theory.limits.types.limit.lift_π_apply CategoryTheory.Limits.Types.Limit.lift_π_apply -- Porting note (#11119): @[simp] was removed because the linter said it was useless theorem Limit.map_π_apply {F G : J ⥤ Type u} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) (x : limit F) : limit.π G j (limMap α x) = α.app j (limit.π F j x) := congr_fun (limMap_π α j) x #align category_theory.limits.types.limit.map_π_apply CategoryTheory.Limits.Types.Limit.map_π_apply @[simp] theorem Limit.w_apply' {F : J ⥤ Type v} {j j' : J} {x : limit F} (f : j ⟶ j') : F.map f (limit.π F j x) = limit.π F j' x := congr_fun (limit.w F f) x #align category_theory.limits.types.limit.w_apply' CategoryTheory.Limits.Types.Limit.w_apply' @[simp] theorem Limit.lift_π_apply' (F : J ⥤ Type v) (s : Cone F) (j : J) (x : s.pt) : limit.π F j (limit.lift F s x) = s.π.app j x := congr_fun (limit.lift_π s j) x #align category_theory.limits.types.limit.lift_π_apply' CategoryTheory.Limits.Types.Limit.lift_π_apply' @[simp] theorem Limit.map_π_apply' {F G : J ⥤ Type v} (α : F ⟶ G) (j : J) (x : limit F) : limit.π G j (limMap α x) = α.app j (limit.π F j x) := congr_fun (limMap_π α j) x #align category_theory.limits.types.limit.map_π_apply' CategoryTheory.Limits.Types.Limit.map_π_apply' end UnivLE /-! In this section we verify that instances are available as expected. -/ section instances example : HasLimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (TypeMax.{w, v}) := inferInstance example : HasLimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (Type max v w) := inferInstance example : HasLimitsOfSize.{0, 0, v, v+1} (Type v) := inferInstance example : HasLimitsOfSize.{v, v, v, v+1} (Type v) := inferInstance example [UnivLE.{v, u}] : HasLimitsOfSize.{v, v, u, u+1} (Type u) := inferInstance end instances /-- The relation defining the quotient type which implements the colimit of a functor `F : J ⥤ Type u`. See `CategoryTheory.Limits.Types.Quot`. -/ def Quot.Rel (F : J ⥤ Type u) : (Σ j, F.obj j) → (Σ j, F.obj j) → Prop := fun p p' => ∃ f : p.1 ⟶ p'.1, p'.2 = F.map f p.2 -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- A quotient type implementing the colimit of a functor `F : J ⥤ Type u`, as pairs `⟨j, x⟩` where `x : F.obj j`, modulo the equivalence relation generated by `⟨j, x⟩ ~ ⟨j', x'⟩` whenever there is a morphism `f : j ⟶ j'` so `F.map f x = x'`. -/ def Quot (F : J ⥤ Type u) : Type (max v u) := _root_.Quot (Quot.Rel F) instance [Small.{u} J] (F : J ⥤ Type u) : Small.{u} (Quot F) := small_of_surjective (surjective_quot_mk _) /-- Inclusion into the quotient type implementing the colimit. -/ def Quot.ι (F : J ⥤ Type u) (j : J) : F.obj j → Quot F := fun x => Quot.mk _ ⟨j, x⟩ lemma Quot.jointly_surjective {F : J ⥤ Type u} (x : Quot F) : ∃ j y, x = Quot.ι F j y := Quot.ind (β := fun x => ∃ j y, x = Quot.ι F j y) (fun ⟨j, y⟩ => ⟨j, y, rfl⟩) x section variable {F : J ⥤ Type u} (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 : Quot F → c.pt := Quot.lift (fun x => c.ι.app x.1 x.2) <| by rintro ⟨j, x⟩ ⟨j', _⟩ ⟨φ : j ⟶ j', rfl : _ = F.map φ x⟩ exact congr_fun (c.ι.naturality φ).symm x @[simp] lemma Quot.ι_desc (j : J) (x : F.obj j) : Quot.desc c (Quot.ι F j x) = c.ι.app j x := rfl @[simp] lemma Quot.map_ι {j j' : J} {f : j ⟶ j'} (x : F.obj j) : Quot.ι F j' (F.map f x) = Quot.ι F j x := (Quot.sound ⟨f, rfl⟩).symm /-- (implementation detail) A function `Quot F → α` induces a cocone on `F` as long as the universes work out. -/ @[simps] def toCocone {α : Type u} (f : Quot F → α) : Cocone F where pt := α ι := { app := fun j => f ∘ Quot.ι F j } lemma Quot.desc_toCocone_desc {α : Type u} (f : Quot F → α) (hc : IsColimit c) (x : Quot F) : hc.desc (toCocone f) (Quot.desc c x) = f x := by obtain ⟨j, y, rfl⟩ := Quot.jointly_surjective x simpa using congrFun (hc.fac _ j) y theorem isColimit_iff_bijective_desc : Nonempty (IsColimit c) ↔ (Quot.desc c).Bijective := by classical refine ⟨?_, ?_⟩ · refine fun ⟨hc⟩ => ⟨fun x y h => ?_, fun x => ?_⟩ · let f : Quot F → ULift.{u} Bool := fun z => ULift.up (x = z) suffices f x = f y by simpa [f] using this rw [← Quot.desc_toCocone_desc c f hc x, h, Quot.desc_toCocone_desc] · let f₁ : c.pt ⟶ ULift.{u} Bool := fun _ => ULift.up true let f₂ : c.pt ⟶ ULift.{u} Bool := fun x => ULift.up (∃ a, Quot.desc c a = x) suffices f₁ = f₂ by simpa [f₁, f₂] using congrFun this x refine hc.hom_ext fun j => funext fun x => ?_ simpa [f₁, f₂] using ⟨Quot.ι F j x, by simp⟩ · refine fun h => ⟨?_⟩ let e := Equiv.ofBijective _ h have h : ∀ j x, e.symm (c.ι.app j x) = Quot.ι F j x := fun j x => e.injective (Equiv.ofBijective_apply_symm_apply _ _ _) exact { desc := fun s => Quot.desc s ∘ e.symm fac := fun s j => by ext x simp [h] uniq := fun s m hm => by ext x obtain ⟨x, rfl⟩ := e.surjective x obtain ⟨j, x, rfl⟩ := Quot.jointly_surjective x rw [← h, Equiv.apply_symm_apply] simpa [h] using congrFun (hm j) x } end /-- (internal implementation) the colimit cocone of a functor, implemented as a quotient of a sigma type -/ @[simps] noncomputable def colimitCocone (F : J ⥤ Type u) [Small.{u} (Quot F)] : Cocone F where pt := Shrink (Quot F) ι := { app := fun j x => equivShrink.{u} _ (Quot.mk _ ⟨j, x⟩) naturality := fun _ _ f => funext fun _ => congrArg _ (Quot.sound ⟨f, rfl⟩).symm } @[simp]
Mathlib/CategoryTheory/Limits/Types.lean
442
445
theorem Quot.desc_colimitCocone (F : J ⥤ Type u) [Small.{u} (Quot F)] : Quot.desc (colimitCocone F) = equivShrink.{u} (Quot F) := by
ext ⟨j, x⟩ rfl
/- 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.Limits.Shapes.SplitCoequalizer import Mathlib.CategoryTheory.Limits.Preserves.Basic #align_import category_theory.limits.preserves.shapes.equalizers from "leanprover-community/mathlib"@"4698e35ca56a0d4fa53aa5639c3364e0a77f4eba" /-! # Preserving (co)equalizers Constructions to relate the notions of preserving (co)equalizers and reflecting (co)equalizers to concrete (co)forks. In particular, we show that `equalizerComparison f g G` is an isomorphism iff `G` preserves the limit of the parallel pair `f,g`, as well as the dual result. -/ noncomputable section universe w v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) namespace CategoryTheory.Limits section Equalizers variable {X Y Z : C} {f g : X ⟶ Y} {h : Z ⟶ X} (w : h ≫ f = h ≫ g) /-- The map of a fork is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `Fork.ofι` with `Functor.mapCone`. -/ def isLimitMapConeForkEquiv : IsLimit (G.mapCone (Fork.ofι h w)) ≃ IsLimit (Fork.ofι (G.map h) (by simp only [← G.map_comp, w]) : Fork (G.map f) (G.map g)) := (IsLimit.postcomposeHomEquiv (diagramIsoParallelPair _) _).symm.trans (IsLimit.equivIsoLimit (Fork.ext (Iso.refl _) (by simp [Fork.ι]))) #align category_theory.limits.is_limit_map_cone_fork_equiv CategoryTheory.Limits.isLimitMapConeForkEquiv /-- The property of preserving equalizers expressed in terms of forks. -/ def isLimitForkMapOfIsLimit [PreservesLimit (parallelPair f g) G] (l : IsLimit (Fork.ofι h w)) : IsLimit (Fork.ofι (G.map h) (by simp only [← G.map_comp, w]) : Fork (G.map f) (G.map g)) := isLimitMapConeForkEquiv G w (PreservesLimit.preserves l) #align category_theory.limits.is_limit_fork_map_of_is_limit CategoryTheory.Limits.isLimitForkMapOfIsLimit /-- The property of reflecting equalizers expressed in terms of forks. -/ def isLimitOfIsLimitForkMap [ReflectsLimit (parallelPair f g) G] (l : IsLimit (Fork.ofι (G.map h) (by simp only [← G.map_comp, w]) : Fork (G.map f) (G.map g))) : IsLimit (Fork.ofι h w) := ReflectsLimit.reflects ((isLimitMapConeForkEquiv G w).symm l) #align category_theory.limits.is_limit_of_is_limit_fork_map CategoryTheory.Limits.isLimitOfIsLimitForkMap variable (f g) [HasEqualizer f g] /-- If `G` preserves equalizers and `C` has them, then the fork constructed of the mapped morphisms of a fork is a limit. -/ def isLimitOfHasEqualizerOfPreservesLimit [PreservesLimit (parallelPair f g) G] : IsLimit (Fork.ofι (G.map (equalizer.ι f g)) (by simp only [← G.map_comp]; rw [equalizer.condition]) : Fork (G.map f) (G.map g)) := isLimitForkMapOfIsLimit G _ (equalizerIsEqualizer f g) #align category_theory.limits.is_limit_of_has_equalizer_of_preserves_limit CategoryTheory.Limits.isLimitOfHasEqualizerOfPreservesLimit variable [HasEqualizer (G.map f) (G.map g)] /-- If the equalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the equalizer of `(f,g)`. -/ def PreservesEqualizer.ofIsoComparison [i : IsIso (equalizerComparison f g G)] : PreservesLimit (parallelPair f g) G := by apply preservesLimitOfPreservesLimitCone (equalizerIsEqualizer f g) apply (isLimitMapConeForkEquiv _ _).symm _ refine @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (parallelPair (G.map f) (G.map g))) ?_ apply i #align category_theory.limits.preserves_equalizer.of_iso_comparison CategoryTheory.Limits.PreservesEqualizer.ofIsoComparison variable [PreservesLimit (parallelPair f g) G] /-- If `G` preserves the equalizer of `(f,g)`, then the equalizer comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesEqualizer.iso : G.obj (equalizer f g) ≅ equalizer (G.map f) (G.map g) := IsLimit.conePointUniqueUpToIso (isLimitOfHasEqualizerOfPreservesLimit G f g) (limit.isLimit _) #align category_theory.limits.preserves_equalizer.iso CategoryTheory.Limits.PreservesEqualizer.iso @[simp] theorem PreservesEqualizer.iso_hom : (PreservesEqualizer.iso G f g).hom = equalizerComparison f g G := rfl #align category_theory.limits.preserves_equalizer.iso_hom CategoryTheory.Limits.PreservesEqualizer.iso_hom @[simp] theorem PreservesEqualizer.iso_inv_ι : (PreservesEqualizer.iso G f g).inv ≫ G.map (equalizer.ι f g) = equalizer.ι (G.map f) (G.map g) := by rw [← Iso.cancel_iso_hom_left (PreservesEqualizer.iso G f g), ← Category.assoc, Iso.hom_inv_id] simp instance : IsIso (equalizerComparison f g G) := by rw [← PreservesEqualizer.iso_hom] infer_instance end Equalizers section Coequalizers variable {X Y Z : C} {f g : X ⟶ Y} {h : Y ⟶ Z} (w : f ≫ h = g ≫ h) /-- The map of a cofork is a colimit iff the cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `Cofork.ofπ` with `Functor.mapCocone`. -/ def isColimitMapCoconeCoforkEquiv : IsColimit (G.mapCocone (Cofork.ofπ h w)) ≃ IsColimit (Cofork.ofπ (G.map h) (by simp only [← G.map_comp, w]) : Cofork (G.map f) (G.map g)) := (IsColimit.precomposeInvEquiv (diagramIsoParallelPair _) _).symm.trans <| IsColimit.equivIsoColimit <| Cofork.ext (Iso.refl _) <| by dsimp only [Cofork.π, Cofork.ofπ_ι_app] dsimp; rw [Category.comp_id, Category.id_comp] #align category_theory.limits.is_colimit_map_cocone_cofork_equiv CategoryTheory.Limits.isColimitMapCoconeCoforkEquiv /-- The property of preserving coequalizers expressed in terms of coforks. -/ def isColimitCoforkMapOfIsColimit [PreservesColimit (parallelPair f g) G] (l : IsColimit (Cofork.ofπ h w)) : IsColimit (Cofork.ofπ (G.map h) (by simp only [← G.map_comp, w]) : Cofork (G.map f) (G.map g)) := isColimitMapCoconeCoforkEquiv G w (PreservesColimit.preserves l) #align category_theory.limits.is_colimit_cofork_map_of_is_colimit CategoryTheory.Limits.isColimitCoforkMapOfIsColimit /-- The property of reflecting coequalizers expressed in terms of coforks. -/ def isColimitOfIsColimitCoforkMap [ReflectsColimit (parallelPair f g) G] (l : IsColimit (Cofork.ofπ (G.map h) (by simp only [← G.map_comp, w]) : Cofork (G.map f) (G.map g))) : IsColimit (Cofork.ofπ h w) := ReflectsColimit.reflects ((isColimitMapCoconeCoforkEquiv G w).symm l) #align category_theory.limits.is_colimit_of_is_colimit_cofork_map CategoryTheory.Limits.isColimitOfIsColimitCoforkMap variable (f g) [HasCoequalizer f g] /-- If `G` preserves coequalizers and `C` has them, then the cofork constructed of the mapped morphisms of a cofork is a colimit. -/ def isColimitOfHasCoequalizerOfPreservesColimit [PreservesColimit (parallelPair f g) G] : IsColimit (Cofork.ofπ (G.map (coequalizer.π f g)) (by simp only [← G.map_comp]; rw [coequalizer.condition]) : Cofork (G.map f) (G.map g)) := isColimitCoforkMapOfIsColimit G _ (coequalizerIsCoequalizer f g) #align category_theory.limits.is_colimit_of_has_coequalizer_of_preserves_colimit CategoryTheory.Limits.isColimitOfHasCoequalizerOfPreservesColimit variable [HasCoequalizer (G.map f) (G.map g)] /-- If the coequalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the coequalizer of `(f,g)`. -/ def ofIsoComparison [i : IsIso (coequalizerComparison f g G)] : PreservesColimit (parallelPair f g) G := by apply preservesColimitOfPreservesColimitCocone (coequalizerIsCoequalizer f g) apply (isColimitMapCoconeCoforkEquiv _ _).symm _ refine @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (parallelPair (G.map f) (G.map g))) ?_ apply i #align category_theory.limits.of_iso_comparison CategoryTheory.Limits.ofIsoComparison variable [PreservesColimit (parallelPair f g) G] /-- If `G` preserves the coequalizer of `(f,g)`, then the coequalizer comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesCoequalizer.iso : coequalizer (G.map f) (G.map g) ≅ G.obj (coequalizer f g) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitOfHasCoequalizerOfPreservesColimit G f g) #align category_theory.limits.preserves_coequalizer.iso CategoryTheory.Limits.PreservesCoequalizer.iso @[simp] theorem PreservesCoequalizer.iso_hom : (PreservesCoequalizer.iso G f g).hom = coequalizerComparison f g G := rfl #align category_theory.limits.preserves_coequalizer.iso_hom CategoryTheory.Limits.PreservesCoequalizer.iso_hom instance : IsIso (coequalizerComparison f g G) := by rw [← PreservesCoequalizer.iso_hom] infer_instance instance map_π_epi : Epi (G.map (coequalizer.π f g)) := ⟨fun {W} h k => by rw [← ι_comp_coequalizerComparison] haveI : Epi (coequalizer.π (G.map f) (G.map g) ≫ coequalizerComparison f g G) := by apply epi_comp apply (cancel_epi _).1⟩ #align category_theory.limits.map_π_epi CategoryTheory.Limits.map_π_epi @[reassoc]
Mathlib/CategoryTheory/Limits/Preserves/Shapes/Equalizers.lean
207
211
theorem map_π_preserves_coequalizer_inv : G.map (coequalizer.π f g) ≫ (PreservesCoequalizer.iso G f g).inv = coequalizer.π (G.map f) (G.map g) := by
rw [← ι_comp_coequalizerComparison_assoc, ← PreservesCoequalizer.iso_hom, Iso.hom_inv_id, comp_id]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn -/ import Mathlib.Data.Sum.Order import Mathlib.Order.InitialSeg import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Tactic.PPWithUniv #align_import set_theory.ordinal.basic from "leanprover-community/mathlib"@"8ea5598db6caeddde6cb734aa179cc2408dbd345" /-! # Ordinals Ordinals are defined as equivalences of well-ordered sets under order isomorphism. They are endowed with a total order, where an ordinal is smaller than another one if it embeds into it as an initial segment (or, equivalently, in any way). This total order is well founded. ## Main definitions * `Ordinal`: the type of ordinals (in a given universe) * `Ordinal.type r`: given a well-founded order `r`, this is the corresponding ordinal * `Ordinal.typein r a`: given a well-founded order `r` on a type `α`, and `a : α`, the ordinal corresponding to all elements smaller than `a`. * `enum r o h`: given a well-order `r` on a type `α`, and an ordinal `o` strictly smaller than the ordinal corresponding to `r` (this is the assumption `h`), returns the `o`-th element of `α`. In other words, the elements of `α` can be enumerated using ordinals up to `type r`. * `Ordinal.card o`: the cardinality of an ordinal `o`. * `Ordinal.lift` lifts an ordinal in universe `u` to an ordinal in universe `max u v`. For a version registering additionally that this is an initial segment embedding, see `Ordinal.lift.initialSeg`. For a version registering that it is a principal segment embedding if `u < v`, see `Ordinal.lift.principalSeg`. * `Ordinal.omega` or `ω` is the order type of `ℕ`. This definition is universe polymorphic: `Ordinal.omega.{u} : Ordinal.{u}` (contrast with `ℕ : Type`, which lives in a specific universe). In some cases the universe level has to be given explicitly. * `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that every element of `o₁` is smaller than every element of `o₂`. The main properties of addition (and the other operations on ordinals) are stated and proved in `Mathlib/SetTheory/Ordinal/Arithmetic.lean`. Here, we only introduce it and prove its basic properties to deduce the fact that the order on ordinals is total (and well founded). * `succ o` is the successor of the ordinal `o`. * `Cardinal.ord c`: when `c` is a cardinal, `ord c` is the smallest ordinal with this cardinality. It is the canonical way to represent a cardinal with an ordinal. A conditionally complete linear order with bot structure is registered on ordinals, where `⊥` is `0`, the ordinal corresponding to the empty type, and `Inf` is the minimum for nonempty sets and `0` for the empty set by convention. ## Notations * `ω` is a notation for the first infinite ordinal in the locale `Ordinal`. -/ assert_not_exists Module assert_not_exists Field noncomputable section open Function Cardinal Set Equiv Order open scoped Classical open Cardinal InitialSeg universe u v w variable {α : Type u} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Well order on an arbitrary type -/ section WellOrderingThm -- Porting note: `parameter` does not work -- parameter {σ : Type u} variable {σ : Type u} open Function theorem nonempty_embedding_to_cardinal : Nonempty (σ ↪ Cardinal.{u}) := (Embedding.total _ _).resolve_left fun ⟨⟨f, hf⟩⟩ => let g : σ → Cardinal.{u} := invFun f let ⟨x, (hx : g x = 2 ^ sum g)⟩ := invFun_surjective hf (2 ^ sum g) have : g x ≤ sum g := le_sum.{u, u} g x not_le_of_gt (by rw [hx]; exact cantor _) this #align nonempty_embedding_to_cardinal nonempty_embedding_to_cardinal /-- An embedding of any type to the set of cardinals. -/ def embeddingToCardinal : σ ↪ Cardinal.{u} := Classical.choice nonempty_embedding_to_cardinal #align embedding_to_cardinal embeddingToCardinal /-- Any type can be endowed with a well order, obtained by pulling back the well order over cardinals by some embedding. -/ def WellOrderingRel : σ → σ → Prop := embeddingToCardinal ⁻¹'o (· < ·) #align well_ordering_rel WellOrderingRel instance WellOrderingRel.isWellOrder : IsWellOrder σ WellOrderingRel := (RelEmbedding.preimage _ _).isWellOrder #align well_ordering_rel.is_well_order WellOrderingRel.isWellOrder instance IsWellOrder.subtype_nonempty : Nonempty { r // IsWellOrder σ r } := ⟨⟨WellOrderingRel, inferInstance⟩⟩ #align is_well_order.subtype_nonempty IsWellOrder.subtype_nonempty end WellOrderingThm /-! ### Definition of ordinals -/ /-- Bundled structure registering a well order on a type. Ordinals will be defined as a quotient of this type. -/ structure WellOrder : Type (u + 1) where /-- The underlying type of the order. -/ α : Type u /-- The underlying relation of the order. -/ r : α → α → Prop /-- The proposition that `r` is a well-ordering for `α`. -/ wo : IsWellOrder α r set_option linter.uppercaseLean3 false in #align Well_order WellOrder attribute [instance] WellOrder.wo namespace WellOrder instance inhabited : Inhabited WellOrder := ⟨⟨PEmpty, _, inferInstanceAs (IsWellOrder PEmpty EmptyRelation)⟩⟩ @[simp] theorem eta (o : WellOrder) : mk o.α o.r o.wo = o := by cases o rfl set_option linter.uppercaseLean3 false in #align Well_order.eta WellOrder.eta end WellOrder /-- Equivalence relation on well orders on arbitrary types in universe `u`, given by order isomorphism. -/ instance Ordinal.isEquivalent : Setoid WellOrder where r := fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≃r s) iseqv := ⟨fun _ => ⟨RelIso.refl _⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩ #align ordinal.is_equivalent Ordinal.isEquivalent /-- `Ordinal.{u}` is the type of well orders in `Type u`, up to order isomorphism. -/ @[pp_with_univ] def Ordinal : Type (u + 1) := Quotient Ordinal.isEquivalent #align ordinal Ordinal instance hasWellFoundedOut (o : Ordinal) : WellFoundedRelation o.out.α := ⟨o.out.r, o.out.wo.wf⟩ #align has_well_founded_out hasWellFoundedOut instance linearOrderOut (o : Ordinal) : LinearOrder o.out.α := IsWellOrder.linearOrder o.out.r #align linear_order_out linearOrderOut instance isWellOrder_out_lt (o : Ordinal) : IsWellOrder o.out.α (· < ·) := o.out.wo #align is_well_order_out_lt isWellOrder_out_lt namespace Ordinal /-! ### Basic properties of the order type -/ /-- The order type of a well order is an ordinal. -/ def type (r : α → α → Prop) [wo : IsWellOrder α r] : Ordinal := ⟦⟨α, r, wo⟩⟧ #align ordinal.type Ordinal.type instance zero : Zero Ordinal := ⟨type <| @EmptyRelation PEmpty⟩ instance inhabited : Inhabited Ordinal := ⟨0⟩ instance one : One Ordinal := ⟨type <| @EmptyRelation PUnit⟩ /-- The order type of an element inside a well order. For the embedding as a principal segment, see `typein.principalSeg`. -/ def typein (r : α → α → Prop) [IsWellOrder α r] (a : α) : Ordinal := type (Subrel r { b | r b a }) #align ordinal.typein Ordinal.typein @[simp] theorem type_def' (w : WellOrder) : ⟦w⟧ = type w.r := by cases w rfl #align ordinal.type_def' Ordinal.type_def' @[simp, nolint simpNF] -- Porting note (#10675): dsimp can not prove this theorem type_def (r) [wo : IsWellOrder α r] : (⟦⟨α, r, wo⟩⟧ : Ordinal) = type r := by rfl #align ordinal.type_def Ordinal.type_def @[simp] theorem type_out (o : Ordinal) : Ordinal.type o.out.r = o := by rw [Ordinal.type, WellOrder.eta, Quotient.out_eq] #align ordinal.type_out Ordinal.type_out theorem type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r = type s ↔ Nonempty (r ≃r s) := Quotient.eq' #align ordinal.type_eq Ordinal.type_eq theorem _root_.RelIso.ordinal_type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ≃r s) : type r = type s := type_eq.2 ⟨h⟩ #align rel_iso.ordinal_type_eq RelIso.ordinal_type_eq @[simp] theorem type_lt (o : Ordinal) : type ((· < ·) : o.out.α → o.out.α → Prop) = o := (type_def' _).symm.trans <| Quotient.out_eq o #align ordinal.type_lt Ordinal.type_lt theorem type_eq_zero_of_empty (r) [IsWellOrder α r] [IsEmpty α] : type r = 0 := (RelIso.relIsoOfIsEmpty r _).ordinal_type_eq #align ordinal.type_eq_zero_of_empty Ordinal.type_eq_zero_of_empty @[simp] theorem type_eq_zero_iff_isEmpty [IsWellOrder α r] : type r = 0 ↔ IsEmpty α := ⟨fun h => let ⟨s⟩ := type_eq.1 h s.toEquiv.isEmpty, @type_eq_zero_of_empty α r _⟩ #align ordinal.type_eq_zero_iff_is_empty Ordinal.type_eq_zero_iff_isEmpty theorem type_ne_zero_iff_nonempty [IsWellOrder α r] : type r ≠ 0 ↔ Nonempty α := by simp #align ordinal.type_ne_zero_iff_nonempty Ordinal.type_ne_zero_iff_nonempty theorem type_ne_zero_of_nonempty (r) [IsWellOrder α r] [h : Nonempty α] : type r ≠ 0 := type_ne_zero_iff_nonempty.2 h #align ordinal.type_ne_zero_of_nonempty Ordinal.type_ne_zero_of_nonempty theorem type_pEmpty : type (@EmptyRelation PEmpty) = 0 := rfl #align ordinal.type_pempty Ordinal.type_pEmpty theorem type_empty : type (@EmptyRelation Empty) = 0 := type_eq_zero_of_empty _ #align ordinal.type_empty Ordinal.type_empty theorem type_eq_one_of_unique (r) [IsWellOrder α r] [Unique α] : type r = 1 := (RelIso.relIsoOfUniqueOfIrrefl r _).ordinal_type_eq #align ordinal.type_eq_one_of_unique Ordinal.type_eq_one_of_unique @[simp] theorem type_eq_one_iff_unique [IsWellOrder α r] : type r = 1 ↔ Nonempty (Unique α) := ⟨fun h => let ⟨s⟩ := type_eq.1 h ⟨s.toEquiv.unique⟩, fun ⟨h⟩ => @type_eq_one_of_unique α r _ h⟩ #align ordinal.type_eq_one_iff_unique Ordinal.type_eq_one_iff_unique theorem type_pUnit : type (@EmptyRelation PUnit) = 1 := rfl #align ordinal.type_punit Ordinal.type_pUnit theorem type_unit : type (@EmptyRelation Unit) = 1 := rfl #align ordinal.type_unit Ordinal.type_unit @[simp] theorem out_empty_iff_eq_zero {o : Ordinal} : IsEmpty o.out.α ↔ o = 0 := by rw [← @type_eq_zero_iff_isEmpty o.out.α (· < ·), type_lt] #align ordinal.out_empty_iff_eq_zero Ordinal.out_empty_iff_eq_zero theorem eq_zero_of_out_empty (o : Ordinal) [h : IsEmpty o.out.α] : o = 0 := out_empty_iff_eq_zero.1 h #align ordinal.eq_zero_of_out_empty Ordinal.eq_zero_of_out_empty instance isEmpty_out_zero : IsEmpty (0 : Ordinal).out.α := out_empty_iff_eq_zero.2 rfl #align ordinal.is_empty_out_zero Ordinal.isEmpty_out_zero @[simp] theorem out_nonempty_iff_ne_zero {o : Ordinal} : Nonempty o.out.α ↔ o ≠ 0 := by rw [← @type_ne_zero_iff_nonempty o.out.α (· < ·), type_lt] #align ordinal.out_nonempty_iff_ne_zero Ordinal.out_nonempty_iff_ne_zero theorem ne_zero_of_out_nonempty (o : Ordinal) [h : Nonempty o.out.α] : o ≠ 0 := out_nonempty_iff_ne_zero.1 h #align ordinal.ne_zero_of_out_nonempty Ordinal.ne_zero_of_out_nonempty protected theorem one_ne_zero : (1 : Ordinal) ≠ 0 := type_ne_zero_of_nonempty _ #align ordinal.one_ne_zero Ordinal.one_ne_zero instance nontrivial : Nontrivial Ordinal.{u} := ⟨⟨1, 0, Ordinal.one_ne_zero⟩⟩ --@[simp] -- Porting note: not in simp nf, added aux lemma below theorem type_preimage {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : type (f ⁻¹'o r) = type r := (RelIso.preimage f r).ordinal_type_eq #align ordinal.type_preimage Ordinal.type_preimage @[simp, nolint simpNF] -- `simpNF` incorrectly complains the LHS doesn't simplify. theorem type_preimage_aux {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : @type _ (fun x y => r (f x) (f y)) (inferInstanceAs (IsWellOrder β (↑f ⁻¹'o r))) = type r := by convert (RelIso.preimage f r).ordinal_type_eq @[elab_as_elim] theorem inductionOn {C : Ordinal → Prop} (o : Ordinal) (H : ∀ (α r) [IsWellOrder α r], C (type r)) : C o := Quot.inductionOn o fun ⟨α, r, wo⟩ => @H α r wo #align ordinal.induction_on Ordinal.inductionOn /-! ### The order on ordinals -/ /-- For `Ordinal`: * less-equal is defined such that well orders `r` and `s` satisfy `type r ≤ type s` if there exists a function embedding `r` as an *initial* segment of `s`. * less-than is defined such that well orders `r` and `s` satisfy `type r < type s` if there exists a function embedding `r` as a *principal* segment of `s`. -/ instance partialOrder : PartialOrder Ordinal where le a b := Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≼i s)) fun _ _ _ _ ⟨f⟩ ⟨g⟩ => propext ⟨fun ⟨h⟩ => ⟨(InitialSeg.ofIso f.symm).trans <| h.trans (InitialSeg.ofIso g)⟩, fun ⟨h⟩ => ⟨(InitialSeg.ofIso f).trans <| h.trans (InitialSeg.ofIso g.symm)⟩⟩ lt a b := Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≺i s)) fun _ _ _ _ ⟨f⟩ ⟨g⟩ => propext ⟨fun ⟨h⟩ => ⟨PrincipalSeg.equivLT f.symm <| h.ltLe (InitialSeg.ofIso g)⟩, fun ⟨h⟩ => ⟨PrincipalSeg.equivLT f <| h.ltLe (InitialSeg.ofIso g.symm)⟩⟩ le_refl := Quot.ind fun ⟨_, _, _⟩ => ⟨InitialSeg.refl _⟩ le_trans a b c := Quotient.inductionOn₃ a b c fun _ _ _ ⟨f⟩ ⟨g⟩ => ⟨f.trans g⟩ lt_iff_le_not_le a b := Quotient.inductionOn₂ a b fun _ _ => ⟨fun ⟨f⟩ => ⟨⟨f⟩, fun ⟨g⟩ => (f.ltLe g).irrefl⟩, fun ⟨⟨f⟩, h⟩ => Sum.recOn f.ltOrEq (fun g => ⟨g⟩) fun g => (h ⟨InitialSeg.ofIso g.symm⟩).elim⟩ le_antisymm a b := Quotient.inductionOn₂ a b fun _ _ ⟨h₁⟩ ⟨h₂⟩ => Quot.sound ⟨InitialSeg.antisymm h₁ h₂⟩ theorem type_le_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ≼i s) := Iff.rfl #align ordinal.type_le_iff Ordinal.type_le_iff theorem type_le_iff' {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ↪r s) := ⟨fun ⟨f⟩ => ⟨f⟩, fun ⟨f⟩ => ⟨f.collapse⟩⟩ #align ordinal.type_le_iff' Ordinal.type_le_iff' theorem _root_.InitialSeg.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ≼i s) : type r ≤ type s := ⟨h⟩ #align initial_seg.ordinal_type_le InitialSeg.ordinal_type_le theorem _root_.RelEmbedding.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ↪r s) : type r ≤ type s := ⟨h.collapse⟩ #align rel_embedding.ordinal_type_le RelEmbedding.ordinal_type_le @[simp] theorem type_lt_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r < type s ↔ Nonempty (r ≺i s) := Iff.rfl #align ordinal.type_lt_iff Ordinal.type_lt_iff theorem _root_.PrincipalSeg.ordinal_type_lt {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ≺i s) : type r < type s := ⟨h⟩ #align principal_seg.ordinal_type_lt PrincipalSeg.ordinal_type_lt @[simp] protected theorem zero_le (o : Ordinal) : 0 ≤ o := inductionOn o fun _ r _ => (InitialSeg.ofIsEmpty _ r).ordinal_type_le #align ordinal.zero_le Ordinal.zero_le instance orderBot : OrderBot Ordinal where bot := 0 bot_le := Ordinal.zero_le @[simp] theorem bot_eq_zero : (⊥ : Ordinal) = 0 := rfl #align ordinal.bot_eq_zero Ordinal.bot_eq_zero @[simp] protected theorem le_zero {o : Ordinal} : o ≤ 0 ↔ o = 0 := le_bot_iff #align ordinal.le_zero Ordinal.le_zero protected theorem pos_iff_ne_zero {o : Ordinal} : 0 < o ↔ o ≠ 0 := bot_lt_iff_ne_bot #align ordinal.pos_iff_ne_zero Ordinal.pos_iff_ne_zero protected theorem not_lt_zero (o : Ordinal) : ¬o < 0 := not_lt_bot #align ordinal.not_lt_zero Ordinal.not_lt_zero theorem eq_zero_or_pos : ∀ a : Ordinal, a = 0 ∨ 0 < a := eq_bot_or_bot_lt #align ordinal.eq_zero_or_pos Ordinal.eq_zero_or_pos instance zeroLEOneClass : ZeroLEOneClass Ordinal := ⟨Ordinal.zero_le _⟩ instance NeZero.one : NeZero (1 : Ordinal) := ⟨Ordinal.one_ne_zero⟩ #align ordinal.ne_zero.one Ordinal.NeZero.one /-- Given two ordinals `α ≤ β`, then `initialSegOut α β` is the initial segment embedding of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/ def initialSegOut {α β : Ordinal} (h : α ≤ β) : InitialSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by change α.out.r ≼i β.out.r rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h cases Quotient.out α; cases Quotient.out β; exact Classical.choice #align ordinal.initial_seg_out Ordinal.initialSegOut /-- Given two ordinals `α < β`, then `principalSegOut α β` is the principal segment embedding of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/ def principalSegOut {α β : Ordinal} (h : α < β) : PrincipalSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by change α.out.r ≺i β.out.r rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h cases Quotient.out α; cases Quotient.out β; exact Classical.choice #align ordinal.principal_seg_out Ordinal.principalSegOut theorem typein_lt_type (r : α → α → Prop) [IsWellOrder α r] (a : α) : typein r a < type r := ⟨PrincipalSeg.ofElement _ _⟩ #align ordinal.typein_lt_type Ordinal.typein_lt_type theorem typein_lt_self {o : Ordinal} (i : o.out.α) : @typein _ (· < ·) (isWellOrder_out_lt _) i < o := by simp_rw [← type_lt o] apply typein_lt_type #align ordinal.typein_lt_self Ordinal.typein_lt_self @[simp] theorem typein_top {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≺i s) : typein s f.top = type r := Eq.symm <| Quot.sound ⟨RelIso.ofSurjective (RelEmbedding.codRestrict _ f f.lt_top) fun ⟨a, h⟩ => by rcases f.down.1 h with ⟨b, rfl⟩; exact ⟨b, rfl⟩⟩ #align ordinal.typein_top Ordinal.typein_top @[simp] theorem typein_apply {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≼i s) (a : α) : Ordinal.typein s (f a) = Ordinal.typein r a := Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.codRestrict _ ((Subrel.relEmbedding _ _).trans f) fun ⟨x, h⟩ => by rw [RelEmbedding.trans_apply]; exact f.toRelEmbedding.map_rel_iff.2 h) fun ⟨y, h⟩ => by rcases f.init h with ⟨a, rfl⟩ exact ⟨⟨a, f.toRelEmbedding.map_rel_iff.1 h⟩, Subtype.eq <| RelEmbedding.trans_apply _ _ _⟩⟩ #align ordinal.typein_apply Ordinal.typein_apply @[simp] theorem typein_lt_typein (r : α → α → Prop) [IsWellOrder α r] {a b : α} : typein r a < typein r b ↔ r a b := ⟨fun ⟨f⟩ => by have : f.top.1 = a := by let f' := PrincipalSeg.ofElement r a let g' := f.trans (PrincipalSeg.ofElement r b) have : g'.top = f'.top := by rw [Subsingleton.elim f' g'] exact this rw [← this] exact f.top.2, fun h => ⟨PrincipalSeg.codRestrict _ (PrincipalSeg.ofElement r a) (fun x => @trans _ r _ _ _ _ x.2 h) h⟩⟩ #align ordinal.typein_lt_typein Ordinal.typein_lt_typein theorem typein_surj (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) : ∃ a, typein r a = o := inductionOn o (fun _ _ _ ⟨f⟩ => ⟨f.top, typein_top _⟩) h #align ordinal.typein_surj Ordinal.typein_surj theorem typein_injective (r : α → α → Prop) [IsWellOrder α r] : Injective (typein r) := injective_of_increasing r (· < ·) (typein r) (typein_lt_typein r).2 #align ordinal.typein_injective Ordinal.typein_injective @[simp] theorem typein_inj (r : α → α → Prop) [IsWellOrder α r] {a b} : typein r a = typein r b ↔ a = b := (typein_injective r).eq_iff #align ordinal.typein_inj Ordinal.typein_inj /-- Principal segment version of the `typein` function, embedding a well order into ordinals as a principal segment. -/ def typein.principalSeg {α : Type u} (r : α → α → Prop) [IsWellOrder α r] : @PrincipalSeg α Ordinal.{u} r (· < ·) := ⟨⟨⟨typein r, typein_injective r⟩, typein_lt_typein r⟩, type r, fun _ ↦ ⟨typein_surj r, fun ⟨a, h⟩ ↦ h ▸ typein_lt_type r a⟩⟩ #align ordinal.typein.principal_seg Ordinal.typein.principalSeg @[simp] theorem typein.principalSeg_coe (r : α → α → Prop) [IsWellOrder α r] : (typein.principalSeg r : α → Ordinal) = typein r := rfl #align ordinal.typein.principal_seg_coe Ordinal.typein.principalSeg_coe /-! ### Enumerating elements in a well-order with ordinals. -/ /-- `enum r o h` is the `o`-th element of `α` ordered by `r`. That is, `enum` maps an initial segment of the ordinals, those less than the order type of `r`, to the elements of `α`. -/ def enum (r : α → α → Prop) [IsWellOrder α r] (o) (h : o < type r) : α := (typein.principalSeg r).subrelIso ⟨o, h⟩ @[simp] theorem typein_enum (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) : typein r (enum r o h) = o := (typein.principalSeg r).apply_subrelIso _ #align ordinal.typein_enum Ordinal.typein_enum theorem enum_type {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : s ≺i r) {h : type s < type r} : enum r (type s) h = f.top := (typein.principalSeg r).injective <| (typein_enum _ _).trans (typein_top _).symm #align ordinal.enum_type Ordinal.enum_type @[simp] theorem enum_typein (r : α → α → Prop) [IsWellOrder α r] (a : α) : enum r (typein r a) (typein_lt_type r a) = a := enum_type (PrincipalSeg.ofElement r a) #align ordinal.enum_typein Ordinal.enum_typein theorem enum_lt_enum {r : α → α → Prop} [IsWellOrder α r] {o₁ o₂ : Ordinal} (h₁ : o₁ < type r) (h₂ : o₂ < type r) : r (enum r o₁ h₁) (enum r o₂ h₂) ↔ o₁ < o₂ := by rw [← typein_lt_typein r, typein_enum, typein_enum] #align ordinal.enum_lt_enum Ordinal.enum_lt_enum theorem relIso_enum' {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) (o : Ordinal) : ∀ (hr : o < type r) (hs : o < type s), f (enum r o hr) = enum s o hs := by refine inductionOn o ?_; rintro γ t wo ⟨g⟩ ⟨h⟩ rw [enum_type g, enum_type (PrincipalSeg.ltEquiv g f)]; rfl #align ordinal.rel_iso_enum' Ordinal.relIso_enum' theorem relIso_enum {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) (o : Ordinal) (hr : o < type r) : f (enum r o hr) = enum s o (by convert hr using 1 apply Quotient.sound exact ⟨f.symm⟩) := relIso_enum' _ _ _ _ #align ordinal.rel_iso_enum Ordinal.relIso_enum theorem lt_wf : @WellFounded Ordinal (· < ·) := /- wellFounded_iff_wellFounded_subrel.mpr (·.induction_on fun ⟨_, r, wo⟩ ↦ RelHomClass.wellFounded (typein.principalSeg r).subrelIso wo.wf) -/ ⟨fun a => inductionOn a fun α r wo => suffices ∀ a, Acc (· < ·) (typein r a) from ⟨_, fun o h => let ⟨a, e⟩ := typein_surj r h e ▸ this a⟩ fun a => Acc.recOn (wo.wf.apply a) fun x _ IH => ⟨_, fun o h => by rcases typein_surj r (lt_trans h (typein_lt_type r _)) with ⟨b, rfl⟩ exact IH _ ((typein_lt_typein r).1 h)⟩⟩ #align ordinal.lt_wf Ordinal.lt_wf instance wellFoundedRelation : WellFoundedRelation Ordinal := ⟨(· < ·), lt_wf⟩ /-- Reformulation of well founded induction on ordinals as a lemma that works with the `induction` tactic, as in `induction i using Ordinal.induction with | h i IH => ?_`. -/ theorem induction {p : Ordinal.{u} → Prop} (i : Ordinal.{u}) (h : ∀ j, (∀ k, k < j → p k) → p j) : p i := lt_wf.induction i h #align ordinal.induction Ordinal.induction /-! ### Cardinality of ordinals -/ /-- The cardinal of an ordinal is the cardinality of any type on which a relation with that order type is defined. -/ def card : Ordinal → Cardinal := Quotient.map WellOrder.α fun _ _ ⟨e⟩ => ⟨e.toEquiv⟩ #align ordinal.card Ordinal.card @[simp] theorem card_type (r : α → α → Prop) [IsWellOrder α r] : card (type r) = #α := rfl #align ordinal.card_type Ordinal.card_type -- Porting note: nolint, simpNF linter falsely claims the lemma never applies @[simp, nolint simpNF] theorem card_typein {r : α → α → Prop} [IsWellOrder α r] (x : α) : #{ y // r y x } = (typein r x).card := rfl #align ordinal.card_typein Ordinal.card_typein theorem card_le_card {o₁ o₂ : Ordinal} : o₁ ≤ o₂ → card o₁ ≤ card o₂ := inductionOn o₁ fun _ _ _ => inductionOn o₂ fun _ _ _ ⟨⟨⟨f, _⟩, _⟩⟩ => ⟨f⟩ #align ordinal.card_le_card Ordinal.card_le_card @[simp] theorem card_zero : card 0 = 0 := mk_eq_zero _ #align ordinal.card_zero Ordinal.card_zero @[simp] theorem card_one : card 1 = 1 := mk_eq_one _ #align ordinal.card_one Ordinal.card_one /-! ### Lifting ordinals to a higher universe -/ -- Porting note: Needed to add universe hint .{u} below /-- The universe lift operation for ordinals, which embeds `Ordinal.{u}` as a proper initial segment of `Ordinal.{v}` for `v > u`. For the initial segment version, see `lift.initialSeg`. -/ @[pp_with_univ] def lift (o : Ordinal.{v}) : Ordinal.{max v u} := Quotient.liftOn o (fun w => type <| ULift.down.{u} ⁻¹'o w.r) fun ⟨_, r, _⟩ ⟨_, s, _⟩ ⟨f⟩ => Quot.sound ⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩ #align ordinal.lift Ordinal.lift -- Porting note: Needed to add universe hints ULift.down.{v,u} below -- @[simp] -- Porting note: Not in simpnf, added aux lemma below theorem type_uLift (r : α → α → Prop) [IsWellOrder α r] : type (ULift.down.{v,u} ⁻¹'o r) = lift.{v} (type r) := by simp (config := { unfoldPartialApp := true }) rfl #align ordinal.type_ulift Ordinal.type_uLift -- Porting note: simpNF linter falsely claims that this never applies @[simp, nolint simpNF] theorem type_uLift_aux (r : α → α → Prop) [IsWellOrder α r] : @type.{max v u} _ (fun x y => r (ULift.down.{v,u} x) (ULift.down.{v,u} y)) (inferInstanceAs (IsWellOrder (ULift α) (ULift.down ⁻¹'o r))) = lift.{v} (type r) := rfl theorem _root_.RelIso.ordinal_lift_type_eq {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) : lift.{v} (type r) = lift.{u} (type s) := ((RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm).ordinal_type_eq #align rel_iso.ordinal_lift_type_eq RelIso.ordinal_lift_type_eq -- @[simp] theorem type_lift_preimage {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : lift.{u} (type (f ⁻¹'o r)) = lift.{v} (type r) := (RelIso.preimage f r).ordinal_lift_type_eq #align ordinal.type_lift_preimage Ordinal.type_lift_preimage @[simp, nolint simpNF] theorem type_lift_preimage_aux {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : lift.{u} (@type _ (fun x y => r (f x) (f y)) (inferInstanceAs (IsWellOrder β (f ⁻¹'o r)))) = lift.{v} (type r) := (RelIso.preimage f r).ordinal_lift_type_eq /-- `lift.{max u v, u}` equals `lift.{v, u}`. -/ -- @[simp] -- Porting note: simp lemma never applies, tested theorem lift_umax : lift.{max u v, u} = lift.{v, u} := funext fun a => inductionOn a fun _ r _ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift r).trans (RelIso.preimage Equiv.ulift r).symm⟩ #align ordinal.lift_umax Ordinal.lift_umax /-- `lift.{max v u, u}` equals `lift.{v, u}`. -/ -- @[simp] -- Porting note: simp lemma never applies, tested theorem lift_umax' : lift.{max v u, u} = lift.{v, u} := lift_umax #align ordinal.lift_umax' Ordinal.lift_umax' /-- An ordinal lifted to a lower or equal universe equals itself. -/ -- @[simp] -- Porting note: simp lemma never applies, tested theorem lift_id' (a : Ordinal) : lift a = a := inductionOn a fun _ r _ => Quotient.sound ⟨RelIso.preimage Equiv.ulift r⟩ #align ordinal.lift_id' Ordinal.lift_id' /-- An ordinal lifted to the same universe equals itself. -/ @[simp] theorem lift_id : ∀ a, lift.{u, u} a = a := lift_id'.{u, u} #align ordinal.lift_id Ordinal.lift_id /-- An ordinal lifted to the zero universe equals itself. -/ @[simp] theorem lift_uzero (a : Ordinal.{u}) : lift.{0} a = a := lift_id' a #align ordinal.lift_uzero Ordinal.lift_uzero @[simp] theorem lift_lift (a : Ordinal) : lift.{w} (lift.{v} a) = lift.{max v w} a := inductionOn a fun _ _ _ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans <| (RelIso.preimage Equiv.ulift _).trans (RelIso.preimage Equiv.ulift _).symm⟩ #align ordinal.lift_lift Ordinal.lift_lift theorem lift_type_le {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] : lift.{max v w} (type r) ≤ lift.{max u w} (type s) ↔ Nonempty (r ≼i s) := ⟨fun ⟨f⟩ => ⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r).symm).trans <| f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩, fun ⟨f⟩ => ⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r)).trans <| f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩ #align ordinal.lift_type_le Ordinal.lift_type_le theorem lift_type_eq {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] : lift.{max v w} (type r) = lift.{max u w} (type s) ↔ Nonempty (r ≃r s) := Quotient.eq'.trans ⟨fun ⟨f⟩ => ⟨(RelIso.preimage Equiv.ulift r).symm.trans <| f.trans (RelIso.preimage Equiv.ulift s)⟩, fun ⟨f⟩ => ⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩⟩ #align ordinal.lift_type_eq Ordinal.lift_type_eq theorem lift_type_lt {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] : lift.{max v w} (type r) < lift.{max u w} (type s) ↔ Nonempty (r ≺i s) := by haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max v w} α ⁻¹'o r) r (RelIso.preimage Equiv.ulift.{max v w} r) _ haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max u w} β ⁻¹'o s) s (RelIso.preimage Equiv.ulift.{max u w} s) _ exact ⟨fun ⟨f⟩ => ⟨(f.equivLT (RelIso.preimage Equiv.ulift r).symm).ltLe (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩, fun ⟨f⟩ => ⟨(f.equivLT (RelIso.preimage Equiv.ulift r)).ltLe (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩ #align ordinal.lift_type_lt Ordinal.lift_type_lt @[simp] theorem lift_le {a b : Ordinal} : lift.{u,v} a ≤ lift.{u,v} b ↔ a ≤ b := inductionOn a fun α r _ => inductionOn b fun β s _ => by rw [← lift_umax] exact lift_type_le.{_,_,u} #align ordinal.lift_le Ordinal.lift_le @[simp] theorem lift_inj {a b : Ordinal} : lift.{u,v} a = lift.{u,v} b ↔ a = b := by simp only [le_antisymm_iff, lift_le] #align ordinal.lift_inj Ordinal.lift_inj @[simp] theorem lift_lt {a b : Ordinal} : lift.{u,v} a < lift.{u,v} b ↔ a < b := by simp only [lt_iff_le_not_le, lift_le] #align ordinal.lift_lt Ordinal.lift_lt @[simp] theorem lift_zero : lift 0 = 0 := type_eq_zero_of_empty _ #align ordinal.lift_zero Ordinal.lift_zero @[simp] theorem lift_one : lift 1 = 1 := type_eq_one_of_unique _ #align ordinal.lift_one Ordinal.lift_one @[simp] theorem lift_card (a) : Cardinal.lift.{u,v} (card a)= card (lift.{u,v} a) := inductionOn a fun _ _ _ => rfl #align ordinal.lift_card Ordinal.lift_card theorem lift_down' {a : Cardinal.{u}} {b : Ordinal.{max u v}} (h : card.{max u v} b ≤ Cardinal.lift.{v,u} a) : ∃ a', lift.{v,u} a' = b := let ⟨c, e⟩ := Cardinal.lift_down h Cardinal.inductionOn c (fun α => inductionOn b fun β s _ e' => by rw [card_type, ← Cardinal.lift_id'.{max u v, u} #β, ← Cardinal.lift_umax.{u, v}, lift_mk_eq.{u, max u v, max u v}] at e' cases' e' with f have g := RelIso.preimage f s haveI := (g : f ⁻¹'o s ↪r s).isWellOrder have := lift_type_eq.{u, max u v, max u v}.2 ⟨g⟩ rw [lift_id, lift_umax.{u, v}] at this exact ⟨_, this⟩) e #align ordinal.lift_down' Ordinal.lift_down' theorem lift_down {a : Ordinal.{u}} {b : Ordinal.{max u v}} (h : b ≤ lift.{v,u} a) : ∃ a', lift.{v,u} a' = b := @lift_down' (card a) _ (by rw [lift_card]; exact card_le_card h) #align ordinal.lift_down Ordinal.lift_down theorem le_lift_iff {a : Ordinal.{u}} {b : Ordinal.{max u v}} : b ≤ lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' ≤ a := ⟨fun h => let ⟨a', e⟩ := lift_down h ⟨a', e, lift_le.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩ #align ordinal.le_lift_iff Ordinal.le_lift_iff theorem lt_lift_iff {a : Ordinal.{u}} {b : Ordinal.{max u v}} : b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a := ⟨fun h => let ⟨a', e⟩ := lift_down (le_of_lt h) ⟨a', e, lift_lt.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩ #align ordinal.lt_lift_iff Ordinal.lt_lift_iff /-- Initial segment version of the lift operation on ordinals, embedding `ordinal.{u}` in `ordinal.{v}` as an initial segment when `u ≤ v`. -/ def lift.initialSeg : @InitialSeg Ordinal.{u} Ordinal.{max u v} (· < ·) (· < ·) := ⟨⟨⟨lift.{v}, fun _ _ => lift_inj.1⟩, lift_lt⟩, fun _ _ h => lift_down (le_of_lt h)⟩ #align ordinal.lift.initial_seg Ordinal.lift.initialSeg @[simp] theorem lift.initialSeg_coe : (lift.initialSeg.{u,v} : Ordinal → Ordinal) = lift.{v,u} := rfl #align ordinal.lift.initial_seg_coe Ordinal.lift.initialSeg_coe /-! ### The first infinite ordinal `omega` -/ /-- `ω` is the first infinite ordinal, defined as the order type of `ℕ`. -/ def omega : Ordinal.{u} := lift <| @type ℕ (· < ·) _ #align ordinal.omega Ordinal.omega @[inherit_doc] scoped notation "ω" => Ordinal.omega /-- Note that the presence of this lemma makes `simp [omega]` form a loop. -/ @[simp] theorem type_nat_lt : @type ℕ (· < ·) _ = ω := (lift_id _).symm #align ordinal.type_nat_lt Ordinal.type_nat_lt @[simp] theorem card_omega : card ω = ℵ₀ := rfl #align ordinal.card_omega Ordinal.card_omega @[simp] theorem lift_omega : lift ω = ω := lift_lift _ #align ordinal.lift_omega Ordinal.lift_omega /-! ### Definition and first properties of addition on ordinals In this paragraph, we introduce the addition on ordinals, and prove just enough properties to deduce that the order on ordinals is total (and therefore well-founded). Further properties of the addition, together with properties of the other operations, are proved in `Mathlib/SetTheory/Ordinal/Arithmetic.lean`. -/ /-- `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that every element of `o₁` is smaller than every element of `o₂`. -/ instance add : Add Ordinal.{u} := ⟨fun o₁ o₂ => Quotient.liftOn₂ o₁ o₂ (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => type (Sum.Lex r s)) fun _ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.sumLexCongr f g⟩⟩ instance addMonoidWithOne : AddMonoidWithOne Ordinal.{u} where add := (· + ·) zero := 0 one := 1 zero_add o := inductionOn o fun α r _ => Eq.symm <| Quotient.sound ⟨⟨(emptySum PEmpty α).symm, Sum.lex_inr_inr⟩⟩ add_zero o := inductionOn o fun α r _ => Eq.symm <| Quotient.sound ⟨⟨(sumEmpty α PEmpty).symm, Sum.lex_inl_inl⟩⟩ add_assoc o₁ o₂ o₃ := Quotient.inductionOn₃ o₁ o₂ o₃ fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Quot.sound ⟨⟨sumAssoc _ _ _, by intros a b rcases a with (⟨a | a⟩ | a) <;> rcases b with (⟨b | b⟩ | b) <;> simp only [sumAssoc_apply_inl_inl, sumAssoc_apply_inl_inr, sumAssoc_apply_inr, Sum.lex_inl_inl, Sum.lex_inr_inr, Sum.Lex.sep, Sum.lex_inr_inl]⟩⟩ nsmul := nsmulRec @[simp] theorem card_add (o₁ o₂ : Ordinal) : card (o₁ + o₂) = card o₁ + card o₂ := inductionOn o₁ fun _ __ => inductionOn o₂ fun _ _ _ => rfl #align ordinal.card_add Ordinal.card_add @[simp] theorem type_sum_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r] [IsWellOrder β s] : type (Sum.Lex r s) = type r + type s := rfl #align ordinal.type_sum_lex Ordinal.type_sum_lex @[simp] theorem card_nat (n : ℕ) : card.{u} n = n := by induction n <;> [simp; simp only [card_add, card_one, Nat.cast_succ, *]] #align ordinal.card_nat Ordinal.card_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem card_ofNat (n : ℕ) [n.AtLeastTwo] : card.{u} (no_index (OfNat.ofNat n)) = OfNat.ofNat n := card_nat n -- Porting note: Rewritten proof of elim, previous version was difficult to debug instance add_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) where elim := fun c a b h => by revert h c refine inductionOn a (fun α₁ r₁ _ ↦ ?_) refine inductionOn b (fun α₂ r₂ _ ↦ ?_) rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩ refine inductionOn c (fun β s _ ↦ ?_) refine ⟨⟨⟨(Embedding.refl.{u+1} _).sumMap f, ?_⟩, ?_⟩⟩ · intros a b match a, b with | Sum.inl a, Sum.inl b => exact Sum.lex_inl_inl.trans Sum.lex_inl_inl.symm | Sum.inl a, Sum.inr b => apply iff_of_true <;> apply Sum.Lex.sep | Sum.inr a, Sum.inl b => apply iff_of_false <;> exact Sum.lex_inr_inl | Sum.inr a, Sum.inr b => exact Sum.lex_inr_inr.trans <| fo.trans Sum.lex_inr_inr.symm · intros a b H match a, b, H with | _, Sum.inl b, _ => exact ⟨Sum.inl b, rfl⟩ | Sum.inl a, Sum.inr b, H => exact (Sum.lex_inr_inl H).elim | Sum.inr a, Sum.inr b, H => let ⟨w, h⟩ := fi _ _ (Sum.lex_inr_inr.1 H) exact ⟨Sum.inr w, congr_arg Sum.inr h⟩ #align ordinal.add_covariant_class_le Ordinal.add_covariantClass_le -- Porting note: Rewritten proof of elim, previous version was difficult to debug instance add_swap_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· ≤ ·) where elim := fun c a b h => by revert h c refine inductionOn a (fun α₁ r₁ _ ↦ ?_) refine inductionOn b (fun α₂ r₂ _ ↦ ?_) rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩ refine inductionOn c (fun β s _ ↦ ?_) exact @RelEmbedding.ordinal_type_le _ _ (Sum.Lex r₁ s) (Sum.Lex r₂ s) _ _ ⟨f.sumMap (Embedding.refl _), by intro a b constructor <;> intro H · cases' a with a a <;> cases' b with b b <;> cases H <;> constructor <;> [rwa [← fo]; assumption] · cases H <;> constructor <;> [rwa [fo]; assumption]⟩ #align ordinal.add_swap_covariant_class_le Ordinal.add_swap_covariantClass_le theorem le_add_right (a b : Ordinal) : a ≤ a + b := by simpa only [add_zero] using add_le_add_left (Ordinal.zero_le b) a #align ordinal.le_add_right Ordinal.le_add_right theorem le_add_left (a b : Ordinal) : a ≤ b + a := by simpa only [zero_add] using add_le_add_right (Ordinal.zero_le b) a #align ordinal.le_add_left Ordinal.le_add_left instance linearOrder : LinearOrder Ordinal := {inferInstanceAs (PartialOrder Ordinal) with le_total := fun a b => match lt_or_eq_of_le (le_add_left b a), lt_or_eq_of_le (le_add_right a b) with | Or.inr h, _ => by rw [h]; exact Or.inl (le_add_right _ _) | _, Or.inr h => by rw [h]; exact Or.inr (le_add_left _ _) | Or.inl h₁, Or.inl h₂ => by revert h₁ h₂ refine inductionOn a ?_ intro α₁ r₁ _ refine inductionOn b ?_ intro α₂ r₂ _ ⟨f⟩ ⟨g⟩ rw [← typein_top f, ← typein_top g, le_iff_lt_or_eq, le_iff_lt_or_eq, typein_lt_typein, typein_lt_typein] rcases trichotomous_of (Sum.Lex r₁ r₂) g.top f.top with (h | h | h) <;> [exact Or.inl (Or.inl h); (left; right; rw [h]); exact Or.inr (Or.inl h)] decidableLE := Classical.decRel _ } instance wellFoundedLT : WellFoundedLT Ordinal := ⟨lt_wf⟩ instance isWellOrder : IsWellOrder Ordinal (· < ·) where instance : ConditionallyCompleteLinearOrderBot Ordinal := IsWellOrder.conditionallyCompleteLinearOrderBot _ theorem max_zero_left : ∀ a : Ordinal, max 0 a = a := max_bot_left #align ordinal.max_zero_left Ordinal.max_zero_left theorem max_zero_right : ∀ a : Ordinal, max a 0 = a := max_bot_right #align ordinal.max_zero_right Ordinal.max_zero_right @[simp] theorem max_eq_zero {a b : Ordinal} : max a b = 0 ↔ a = 0 ∧ b = 0 := max_eq_bot #align ordinal.max_eq_zero Ordinal.max_eq_zero @[simp] theorem sInf_empty : sInf (∅ : Set Ordinal) = 0 := dif_neg Set.not_nonempty_empty #align ordinal.Inf_empty Ordinal.sInf_empty /-! ### Successor order properties -/ private theorem succ_le_iff' {a b : Ordinal} : a + 1 ≤ b ↔ a < b := ⟨lt_of_lt_of_le (inductionOn a fun α r _ => ⟨⟨⟨⟨fun x => Sum.inl x, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩, Sum.inr PUnit.unit, fun b => Sum.recOn b (fun x => ⟨fun _ => ⟨x, rfl⟩, fun _ => Sum.Lex.sep _ _⟩) fun x => Sum.lex_inr_inr.trans ⟨False.elim, fun ⟨x, H⟩ => Sum.inl_ne_inr H⟩⟩⟩), inductionOn a fun α r hr => inductionOn b fun β s hs ⟨⟨f, t, hf⟩⟩ => by haveI := hs refine ⟨⟨RelEmbedding.ofMonotone (Sum.rec f fun _ => t) (fun a b ↦ ?_), fun a b ↦ ?_⟩⟩ · rcases a with (a | _) <;> rcases b with (b | _) · simpa only [Sum.lex_inl_inl] using f.map_rel_iff.2 · intro rw [hf] exact ⟨_, rfl⟩ · exact False.elim ∘ Sum.lex_inr_inl · exact False.elim ∘ Sum.lex_inr_inr.1 · rcases a with (a | _) · intro h have := @PrincipalSeg.init _ _ _ _ _ ⟨f, t, hf⟩ _ _ h cases' this with w h exact ⟨Sum.inl w, h⟩ · intro h cases' (hf b).1 h with w h exact ⟨Sum.inl w, h⟩⟩ instance noMaxOrder : NoMaxOrder Ordinal := ⟨fun _ => ⟨_, succ_le_iff'.1 le_rfl⟩⟩ instance succOrder : SuccOrder Ordinal.{u} := SuccOrder.ofSuccLeIff (fun o => o + 1) succ_le_iff' @[simp] theorem add_one_eq_succ (o : Ordinal) : o + 1 = succ o := rfl #align ordinal.add_one_eq_succ Ordinal.add_one_eq_succ @[simp] theorem succ_zero : succ (0 : Ordinal) = 1 := zero_add 1 #align ordinal.succ_zero Ordinal.succ_zero -- Porting note: Proof used to be rfl @[simp] theorem succ_one : succ (1 : Ordinal) = 2 := by congr; simp only [Nat.unaryCast, zero_add] #align ordinal.succ_one Ordinal.succ_one theorem add_succ (o₁ o₂ : Ordinal) : o₁ + succ o₂ = succ (o₁ + o₂) := (add_assoc _ _ _).symm #align ordinal.add_succ Ordinal.add_succ theorem one_le_iff_pos {o : Ordinal} : 1 ≤ o ↔ 0 < o := by rw [← succ_zero, succ_le_iff] #align ordinal.one_le_iff_pos Ordinal.one_le_iff_pos theorem one_le_iff_ne_zero {o : Ordinal} : 1 ≤ o ↔ o ≠ 0 := by rw [one_le_iff_pos, Ordinal.pos_iff_ne_zero] #align ordinal.one_le_iff_ne_zero Ordinal.one_le_iff_ne_zero theorem succ_pos (o : Ordinal) : 0 < succ o := bot_lt_succ o #align ordinal.succ_pos Ordinal.succ_pos theorem succ_ne_zero (o : Ordinal) : succ o ≠ 0 := ne_of_gt <| succ_pos o #align ordinal.succ_ne_zero Ordinal.succ_ne_zero @[simp] theorem lt_one_iff_zero {a : Ordinal} : a < 1 ↔ a = 0 := by simpa using @lt_succ_bot_iff _ _ _ a _ _ #align ordinal.lt_one_iff_zero Ordinal.lt_one_iff_zero theorem le_one_iff {a : Ordinal} : a ≤ 1 ↔ a = 0 ∨ a = 1 := by simpa using @le_succ_bot_iff _ _ _ a _ #align ordinal.le_one_iff Ordinal.le_one_iff @[simp] theorem card_succ (o : Ordinal) : card (succ o) = card o + 1 := by simp only [← add_one_eq_succ, card_add, card_one] #align ordinal.card_succ Ordinal.card_succ theorem natCast_succ (n : ℕ) : ↑n.succ = succ (n : Ordinal) := rfl #align ordinal.nat_cast_succ Ordinal.natCast_succ @[deprecated (since := "2024-04-17")] alias nat_cast_succ := natCast_succ instance uniqueIioOne : Unique (Iio (1 : Ordinal)) where default := ⟨0, by simp⟩ uniq a := Subtype.ext <| lt_one_iff_zero.1 a.2 #align ordinal.unique_Iio_one Ordinal.uniqueIioOne instance uniqueOutOne : Unique (1 : Ordinal).out.α where default := enum (· < ·) 0 (by simp) uniq a := by unfold default rw [← @enum_typein _ (· < ·) (isWellOrder_out_lt _) a] congr rw [← lt_one_iff_zero] apply typein_lt_self #align ordinal.unique_out_one Ordinal.uniqueOutOne theorem one_out_eq (x : (1 : Ordinal).out.α) : x = enum (· < ·) 0 (by simp) := Unique.eq_default x #align ordinal.one_out_eq Ordinal.one_out_eq /-! ### Extra properties of typein and enum -/ @[simp] theorem typein_one_out (x : (1 : Ordinal).out.α) : @typein _ (· < ·) (isWellOrder_out_lt _) x = 0 := by rw [one_out_eq x, typein_enum] #align ordinal.typein_one_out Ordinal.typein_one_out @[simp] theorem typein_le_typein (r : α → α → Prop) [IsWellOrder α r] {x x' : α} : typein r x ≤ typein r x' ↔ ¬r x' x := by rw [← not_lt, typein_lt_typein] #align ordinal.typein_le_typein Ordinal.typein_le_typein -- @[simp] -- Porting note (#10618): simp can prove this theorem typein_le_typein' (o : Ordinal) {x x' : o.out.α} : @typein _ (· < ·) (isWellOrder_out_lt _) x ≤ @typein _ (· < ·) (isWellOrder_out_lt _) x' ↔ x ≤ x' := by rw [typein_le_typein] exact not_lt #align ordinal.typein_le_typein' Ordinal.typein_le_typein' -- Porting note: added nolint, simpnf linter falsely claims it never applies @[simp, nolint simpNF] theorem enum_le_enum (r : α → α → Prop) [IsWellOrder α r] {o o' : Ordinal} (ho : o < type r) (ho' : o' < type r) : ¬r (enum r o' ho') (enum r o ho) ↔ o ≤ o' := by rw [← @not_lt _ _ o' o, enum_lt_enum ho'] #align ordinal.enum_le_enum Ordinal.enum_le_enum @[simp] theorem enum_le_enum' (a : Ordinal) {o o' : Ordinal} (ho : o < type (· < ·)) (ho' : o' < type (· < ·)) : enum (· < ·) o ho ≤ @enum a.out.α (· < ·) _ o' ho' ↔ o ≤ o' := by rw [← @enum_le_enum _ (· < ·) (isWellOrder_out_lt _), ← not_lt] #align ordinal.enum_le_enum' Ordinal.enum_le_enum' theorem enum_zero_le {r : α → α → Prop} [IsWellOrder α r] (h0 : 0 < type r) (a : α) : ¬r a (enum r 0 h0) := by rw [← enum_typein r a, enum_le_enum r] apply Ordinal.zero_le #align ordinal.enum_zero_le Ordinal.enum_zero_le theorem enum_zero_le' {o : Ordinal} (h0 : 0 < o) (a : o.out.α) : @enum o.out.α (· < ·) _ 0 (by rwa [type_lt]) ≤ a := by rw [← not_lt] apply enum_zero_le #align ordinal.enum_zero_le' Ordinal.enum_zero_le' theorem le_enum_succ {o : Ordinal} (a : (succ o).out.α) : a ≤ @enum (succ o).out.α (· < ·) _ o (by rw [type_lt] exact lt_succ o) := by rw [← @enum_typein _ (· < ·) (isWellOrder_out_lt _) a, enum_le_enum', ← lt_succ_iff] apply typein_lt_self #align ordinal.le_enum_succ Ordinal.le_enum_succ @[simp] theorem enum_inj {r : α → α → Prop} [IsWellOrder α r] {o₁ o₂ : Ordinal} (h₁ : o₁ < type r) (h₂ : o₂ < type r) : enum r o₁ h₁ = enum r o₂ h₂ ↔ o₁ = o₂ := (typein.principalSeg r).subrelIso.injective.eq_iff.trans Subtype.mk_eq_mk #align ordinal.enum_inj Ordinal.enum_inj -- TODO: Can we remove this definition and just use `(typein.principalSeg r).subrelIso` directly? /-- A well order `r` is order isomorphic to the set of ordinals smaller than `type r`. -/ @[simps] def enumIso (r : α → α → Prop) [IsWellOrder α r] : Subrel (· < ·) (· < type r) ≃r r := { (typein.principalSeg r).subrelIso with toFun := fun x ↦ enum r x.1 x.2 invFun := fun x ↦ ⟨typein r x, typein_lt_type r x⟩ } #align ordinal.enum_iso Ordinal.enumIso /-- The order isomorphism between ordinals less than `o` and `o.out.α`. -/ @[simps!] noncomputable def enumIsoOut (o : Ordinal) : Set.Iio o ≃o o.out.α where toFun x := enum (· < ·) x.1 <| by rw [type_lt] exact x.2 invFun x := ⟨@typein _ (· < ·) (isWellOrder_out_lt _) x, typein_lt_self x⟩ left_inv := fun ⟨o', h⟩ => Subtype.ext_val (typein_enum _ _) right_inv h := enum_typein _ _ map_rel_iff' := by rintro ⟨a, _⟩ ⟨b, _⟩ apply enum_le_enum' #align ordinal.enum_iso_out Ordinal.enumIsoOut /-- `o.out.α` is an `OrderBot` whenever `0 < o`. -/ def outOrderBotOfPos {o : Ordinal} (ho : 0 < o) : OrderBot o.out.α where bot_le := enum_zero_le' ho #align ordinal.out_order_bot_of_pos Ordinal.outOrderBotOfPos theorem enum_zero_eq_bot {o : Ordinal} (ho : 0 < o) : enum (· < ·) 0 (by rwa [type_lt]) = haveI H := outOrderBotOfPos ho ⊥ := rfl #align ordinal.enum_zero_eq_bot Ordinal.enum_zero_eq_bot /-! ### Universal ordinal -/ -- intended to be used with explicit universe parameters /-- `univ.{u v}` is the order type of the ordinals of `Type u` as a member of `Ordinal.{v}` (when `u < v`). It is an inaccessible cardinal. -/ @[pp_with_univ, nolint checkUnivs] def univ : Ordinal.{max (u + 1) v} := lift.{v, u + 1} (@type Ordinal (· < ·) _) #align ordinal.univ Ordinal.univ theorem univ_id : univ.{u, u + 1} = @type Ordinal (· < ·) _ := lift_id _ #align ordinal.univ_id Ordinal.univ_id @[simp] theorem lift_univ : lift.{w} univ.{u, v} = univ.{u, max v w} := lift_lift _ #align ordinal.lift_univ Ordinal.lift_univ theorem univ_umax : univ.{u, max (u + 1) v} = univ.{u, v} := congr_fun lift_umax _ #align ordinal.univ_umax Ordinal.univ_umax /-- Principal segment version of the lift operation on ordinals, embedding `ordinal.{u}` in `ordinal.{v}` as a principal segment when `u < v`. -/ def lift.principalSeg : @PrincipalSeg Ordinal.{u} Ordinal.{max (u + 1) v} (· < ·) (· < ·) := ⟨↑lift.initialSeg.{u, max (u + 1) v}, univ.{u, v}, by refine fun b => inductionOn b ?_; intro β s _ rw [univ, ← lift_umax]; constructor <;> intro h · rw [← lift_id (type s)] at h ⊢ cases' lift_type_lt.{_,_,v}.1 h with f cases' f with f a hf exists a revert hf -- Porting note: apply inductionOn does not work, refine does refine inductionOn a ?_ intro α r _ hf refine lift_type_eq.{u, max (u + 1) v, max (u + 1) v}.2 ⟨(RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ ?_) ?_).symm⟩ · exact fun b => enum r (f b) ((hf _).2 ⟨_, rfl⟩) · refine fun a b h => (typein_lt_typein r).1 ?_ rw [typein_enum, typein_enum] exact f.map_rel_iff.2 h · intro a' cases' (hf _).1 (typein_lt_type _ a') with b e exists b simp only [RelEmbedding.ofMonotone_coe] simp [e] · cases' h with a e rw [← e] refine inductionOn a ?_ intro α r _ exact lift_type_lt.{u, u + 1, max (u + 1) v}.2 ⟨typein.principalSeg r⟩⟩ #align ordinal.lift.principal_seg Ordinal.lift.principalSeg @[simp] theorem lift.principalSeg_coe : (lift.principalSeg.{u, v} : Ordinal → Ordinal) = lift.{max (u + 1) v} := rfl #align ordinal.lift.principal_seg_coe Ordinal.lift.principalSeg_coe -- Porting note: Added universe hints below @[simp] theorem lift.principalSeg_top : (lift.principalSeg.{u,v}).top = univ.{u,v} := rfl #align ordinal.lift.principal_seg_top Ordinal.lift.principalSeg_top theorem lift.principalSeg_top' : lift.principalSeg.{u, u + 1}.top = @type Ordinal (· < ·) _ := by simp only [lift.principalSeg_top, univ_id] #align ordinal.lift.principal_seg_top' Ordinal.lift.principalSeg_top' end Ordinal /-! ### Representing a cardinal with an ordinal -/ namespace Cardinal open Ordinal @[simp] theorem mk_ordinal_out (o : Ordinal) : #o.out.α = o.card := (Ordinal.card_type _).symm.trans <| by rw [Ordinal.type_lt] #align cardinal.mk_ordinal_out Cardinal.mk_ordinal_out /-- The ordinal corresponding to a cardinal `c` is the least ordinal whose cardinal is `c`. For the order-embedding version, see `ord.order_embedding`. -/ def ord (c : Cardinal) : Ordinal := let F := fun α : Type u => ⨅ r : { r // IsWellOrder α r }, @type α r.1 r.2 Quot.liftOn c F (by suffices ∀ {α β}, α ≈ β → F α ≤ F β from fun α β h => (this h).antisymm (this (Setoid.symm h)) rintro α β ⟨f⟩ refine le_ciInf_iff'.2 fun i => ?_ haveI := @RelEmbedding.isWellOrder _ _ (f ⁻¹'o i.1) _ (↑(RelIso.preimage f i.1)) i.2 exact (ciInf_le' _ (Subtype.mk (f ⁻¹'o i.val) (@RelEmbedding.isWellOrder _ _ _ _ (↑(RelIso.preimage f i.1)) i.2))).trans_eq (Quot.sound ⟨RelIso.preimage f i.1⟩)) #align cardinal.ord Cardinal.ord theorem ord_eq_Inf (α : Type u) : ord #α = ⨅ r : { r // IsWellOrder α r }, @type α r.1 r.2 := rfl #align cardinal.ord_eq_Inf Cardinal.ord_eq_Inf theorem ord_eq (α) : ∃ (r : α → α → Prop) (wo : IsWellOrder α r), ord #α = @type α r wo := let ⟨r, wo⟩ := ciInf_mem fun r : { r // IsWellOrder α r } => @type α r.1 r.2 ⟨r.1, r.2, wo.symm⟩ #align cardinal.ord_eq Cardinal.ord_eq theorem ord_le_type (r : α → α → Prop) [h : IsWellOrder α r] : ord #α ≤ type r := ciInf_le' _ (Subtype.mk r h) #align cardinal.ord_le_type Cardinal.ord_le_type theorem ord_le {c o} : ord c ≤ o ↔ c ≤ o.card := inductionOn c fun α => Ordinal.inductionOn o fun β s _ => by let ⟨r, _, e⟩ := ord_eq α simp only [card_type]; constructor <;> intro h · rw [e] at h exact let ⟨f⟩ := h ⟨f.toEmbedding⟩ · cases' h with f have g := RelEmbedding.preimage f s haveI := RelEmbedding.isWellOrder g exact le_trans (ord_le_type _) g.ordinal_type_le #align cardinal.ord_le Cardinal.ord_le theorem gc_ord_card : GaloisConnection ord card := fun _ _ => ord_le #align cardinal.gc_ord_card Cardinal.gc_ord_card theorem lt_ord {c o} : o < ord c ↔ o.card < c := gc_ord_card.lt_iff_lt #align cardinal.lt_ord Cardinal.lt_ord @[simp] theorem card_ord (c) : (ord c).card = c := Quotient.inductionOn c fun α => by let ⟨r, _, e⟩ := ord_eq α -- Porting note: cardinal.mk_def is now Cardinal.mk'_def, not sure why simp only [mk'_def, e, card_type] #align cardinal.card_ord Cardinal.card_ord /-- Galois coinsertion between `Cardinal.ord` and `Ordinal.card`. -/ def gciOrdCard : GaloisCoinsertion ord card := gc_ord_card.toGaloisCoinsertion fun c => c.card_ord.le #align cardinal.gci_ord_card Cardinal.gciOrdCard theorem ord_card_le (o : Ordinal) : o.card.ord ≤ o := gc_ord_card.l_u_le _ #align cardinal.ord_card_le Cardinal.ord_card_le theorem lt_ord_succ_card (o : Ordinal) : o < (succ o.card).ord := lt_ord.2 <| lt_succ _ #align cardinal.lt_ord_succ_card Cardinal.lt_ord_succ_card theorem card_le_iff {o : Ordinal} {c : Cardinal} : o.card ≤ c ↔ o < (succ c).ord := by rw [lt_ord, lt_succ_iff] /-- A variation on `Cardinal.lt_ord` using `≤`: If `o` is no greater than the initial ordinal of cardinality `c`, then its cardinal is no greater than `c`. The converse, however, is false (for instance, `o = ω+1` and `c = ℵ₀`). -/ lemma card_le_of_le_ord {o : Ordinal} {c : Cardinal} (ho : o ≤ c.ord) : o.card ≤ c := by rw [← card_ord c]; exact Ordinal.card_le_card ho @[mono] theorem ord_strictMono : StrictMono ord := gciOrdCard.strictMono_l #align cardinal.ord_strict_mono Cardinal.ord_strictMono @[mono] theorem ord_mono : Monotone ord := gc_ord_card.monotone_l #align cardinal.ord_mono Cardinal.ord_mono @[simp] theorem ord_le_ord {c₁ c₂} : ord c₁ ≤ ord c₂ ↔ c₁ ≤ c₂ := gciOrdCard.l_le_l_iff #align cardinal.ord_le_ord Cardinal.ord_le_ord @[simp] theorem ord_lt_ord {c₁ c₂} : ord c₁ < ord c₂ ↔ c₁ < c₂ := ord_strictMono.lt_iff_lt #align cardinal.ord_lt_ord Cardinal.ord_lt_ord @[simp] theorem ord_zero : ord 0 = 0 := gc_ord_card.l_bot #align cardinal.ord_zero Cardinal.ord_zero @[simp] theorem ord_nat (n : ℕ) : ord n = n := (ord_le.2 (card_nat n).ge).antisymm (by induction' n with n IH · apply Ordinal.zero_le · exact succ_le_of_lt (IH.trans_lt <| ord_lt_ord.2 <| natCast_lt.2 (Nat.lt_succ_self n))) #align cardinal.ord_nat Cardinal.ord_nat @[simp] theorem ord_one : ord 1 = 1 := by simpa using ord_nat 1 #align cardinal.ord_one Cardinal.ord_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ord_ofNat (n : ℕ) [n.AtLeastTwo] : ord (no_index (OfNat.ofNat n)) = OfNat.ofNat n := ord_nat n @[simp] theorem lift_ord (c) : Ordinal.lift.{u,v} (ord c) = ord (lift.{u,v} c) := by refine le_antisymm (le_of_forall_lt fun a ha => ?_) ?_ · rcases Ordinal.lt_lift_iff.1 ha with ⟨a, rfl, _⟩ rwa [lt_ord, ← lift_card, lift_lt, ← lt_ord, ← Ordinal.lift_lt] · rw [ord_le, ← lift_card, card_ord] #align cardinal.lift_ord Cardinal.lift_ord theorem mk_ord_out (c : Cardinal) : #c.ord.out.α = c := by simp #align cardinal.mk_ord_out Cardinal.mk_ord_out theorem card_typein_lt (r : α → α → Prop) [IsWellOrder α r] (x : α) (h : ord #α = type r) : card (typein r x) < #α := by rw [← lt_ord, h] apply typein_lt_type #align cardinal.card_typein_lt Cardinal.card_typein_lt theorem card_typein_out_lt (c : Cardinal) (x : c.ord.out.α) : card (@typein _ (· < ·) (isWellOrder_out_lt _) x) < c := by rw [← lt_ord] apply typein_lt_self #align cardinal.card_typein_out_lt Cardinal.card_typein_out_lt theorem mk_Iio_ord_out_α {c : Cardinal} (i : c.ord.out.α) : #(Iio i) < c := card_typein_out_lt c i theorem ord_injective : Injective ord := by intro c c' h rw [← card_ord c, ← card_ord c', h] #align cardinal.ord_injective Cardinal.ord_injective /-- The ordinal corresponding to a cardinal `c` is the least ordinal whose cardinal is `c`. This is the order-embedding version. For the regular function, see `ord`. -/ def ord.orderEmbedding : Cardinal ↪o Ordinal := RelEmbedding.orderEmbeddingOfLTEmbedding (RelEmbedding.ofMonotone Cardinal.ord fun _ _ => Cardinal.ord_lt_ord.2) #align cardinal.ord.order_embedding Cardinal.ord.orderEmbedding @[simp] theorem ord.orderEmbedding_coe : (ord.orderEmbedding : Cardinal → Ordinal) = ord := rfl #align cardinal.ord.order_embedding_coe Cardinal.ord.orderEmbedding_coe -- intended to be used with explicit universe parameters /-- The cardinal `univ` is the cardinality of ordinal `univ`, or equivalently the cardinal of `Ordinal.{u}`, or `Cardinal.{u}`, as an element of `Cardinal.{v}` (when `u < v`). -/ @[pp_with_univ, nolint checkUnivs] def univ := lift.{v, u + 1} #Ordinal #align cardinal.univ Cardinal.univ theorem univ_id : univ.{u, u + 1} = #Ordinal := lift_id _ #align cardinal.univ_id Cardinal.univ_id @[simp] theorem lift_univ : lift.{w} univ.{u, v} = univ.{u, max v w} := lift_lift _ #align cardinal.lift_univ Cardinal.lift_univ theorem univ_umax : univ.{u, max (u + 1) v} = univ.{u, v} := congr_fun lift_umax _ #align cardinal.univ_umax Cardinal.univ_umax theorem lift_lt_univ (c : Cardinal) : lift.{u + 1, u} c < univ.{u, u + 1} := by simpa only [lift.principalSeg_coe, lift_ord, lift_succ, ord_le, succ_le_iff] using le_of_lt (lift.principalSeg.{u, u + 1}.lt_top (succ c).ord) #align cardinal.lift_lt_univ Cardinal.lift_lt_univ theorem lift_lt_univ' (c : Cardinal) : lift.{max (u + 1) v, u} c < univ.{u, v} := by have := lift_lt.{_, max (u+1) v}.2 (lift_lt_univ c) rw [lift_lift, lift_univ, univ_umax.{u,v}] at this exact this #align cardinal.lift_lt_univ' Cardinal.lift_lt_univ' @[simp] theorem ord_univ : ord univ.{u, v} = Ordinal.univ.{u, v} := by refine le_antisymm (ord_card_le _) <| le_of_forall_lt fun o h => lt_ord.2 ?_ have := lift.principalSeg.{u, v}.down.1 (by simpa only [lift.principalSeg_coe] using h) rcases this with ⟨o, h'⟩ rw [← h', lift.principalSeg_coe, ← lift_card] apply lift_lt_univ' #align cardinal.ord_univ Cardinal.ord_univ theorem lt_univ {c} : c < univ.{u, u + 1} ↔ ∃ c', c = lift.{u + 1, u} c' := ⟨fun h => by have := ord_lt_ord.2 h rw [ord_univ] at this cases' lift.principalSeg.{u, u + 1}.down.1 (by simpa only [lift.principalSeg_top] ) with o e have := card_ord c rw [← e, lift.principalSeg_coe, ← lift_card] at this exact ⟨_, this.symm⟩, fun ⟨c', e⟩ => e.symm ▸ lift_lt_univ _⟩ #align cardinal.lt_univ Cardinal.lt_univ theorem lt_univ' {c} : c < univ.{u, v} ↔ ∃ c', c = lift.{max (u + 1) v, u} c' := ⟨fun h => by let ⟨a, e, h'⟩ := lt_lift_iff.1 h rw [← univ_id] at h' rcases lt_univ.{u}.1 h' with ⟨c', rfl⟩ exact ⟨c', by simp only [e.symm, lift_lift]⟩, fun ⟨c', e⟩ => e.symm ▸ lift_lt_univ' _⟩ #align cardinal.lt_univ' Cardinal.lt_univ' theorem small_iff_lift_mk_lt_univ {α : Type u} : Small.{v} α ↔ Cardinal.lift.{v+1,_} #α < univ.{v, max u (v + 1)} := by rw [lt_univ'] constructor · rintro ⟨β, e⟩ exact ⟨#β, lift_mk_eq.{u, _, v + 1}.2 e⟩ · rintro ⟨c, hc⟩ exact ⟨⟨c.out, lift_mk_eq.{u, _, v + 1}.1 (hc.trans (congr rfl c.mk_out.symm))⟩⟩ #align cardinal.small_iff_lift_mk_lt_univ Cardinal.small_iff_lift_mk_lt_univ end Cardinal namespace Ordinal @[simp] theorem card_univ : card univ.{u,v} = Cardinal.univ.{u,v} := rfl #align ordinal.card_univ Ordinal.card_univ @[simp] theorem nat_le_card {o} {n : ℕ} : (n : Cardinal) ≤ card o ↔ (n : Ordinal) ≤ o := by rw [← Cardinal.ord_le, Cardinal.ord_nat] #align ordinal.nat_le_card Ordinal.nat_le_card @[simp] theorem one_le_card {o} : 1 ≤ card o ↔ 1 ≤ o := by simpa using nat_le_card (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_le_card {o} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) ≤ card o ↔ (OfNat.ofNat n : Ordinal) ≤ o := nat_le_card @[simp] theorem nat_lt_card {o} {n : ℕ} : (n : Cardinal) < card o ↔ (n : Ordinal) < o := by rw [← succ_le_iff, ← succ_le_iff, ← nat_succ, nat_le_card] rfl #align ordinal.nat_lt_card Ordinal.nat_lt_card @[simp] theorem zero_lt_card {o} : 0 < card o ↔ 0 < o := by simpa using nat_lt_card (n := 0) @[simp] theorem one_lt_card {o} : 1 < card o ↔ 1 < o := by simpa using nat_lt_card (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_lt_card {o} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) < card o ↔ (OfNat.ofNat n : Ordinal) < o := nat_lt_card @[simp] theorem card_lt_nat {o} {n : ℕ} : card o < n ↔ o < n := lt_iff_lt_of_le_iff_le nat_le_card #align ordinal.card_lt_nat Ordinal.card_lt_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem card_lt_ofNat {o} {n : ℕ} [n.AtLeastTwo] : card o < (no_index (OfNat.ofNat n)) ↔ o < OfNat.ofNat n := card_lt_nat @[simp] theorem card_le_nat {o} {n : ℕ} : card o ≤ n ↔ o ≤ n := le_iff_le_iff_lt_iff_lt.2 nat_lt_card #align ordinal.card_le_nat Ordinal.card_le_nat @[simp]
Mathlib/SetTheory/Ordinal/Basic.lean
1,607
1,608
theorem card_le_one {o} : card o ≤ 1 ↔ o ≤ 1 := by
simpa using card_le_nat (n := 1)
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Data.Finsupp.Defs #align_import data.finsupp.ne_locus from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # Locus of unequal values of finitely supported functions Let `α N` be two Types, assume that `N` has a `0` and let `f g : α →₀ N` be finitely supported functions. ## Main definition * `Finsupp.neLocus f g : Finset α`, the finite subset of `α` where `f` and `g` differ. In the case in which `N` is an additive group, `Finsupp.neLocus f g` coincides with `Finsupp.support (f - g)`. -/ variable {α M N P : Type*} namespace Finsupp variable [DecidableEq α] section NHasZero variable [DecidableEq N] [Zero N] (f g : α →₀ N) /-- Given two finitely supported functions `f g : α →₀ N`, `Finsupp.neLocus f g` is the `Finset` where `f` and `g` differ. This generalizes `(f - g).support` to situations without subtraction. -/ def neLocus (f g : α →₀ N) : Finset α := (f.support ∪ g.support).filter fun x => f x ≠ g x #align finsupp.ne_locus Finsupp.neLocus @[simp] theorem mem_neLocus {f g : α →₀ N} {a : α} : a ∈ f.neLocus g ↔ f a ≠ g a := by simpa only [neLocus, Finset.mem_filter, Finset.mem_union, mem_support_iff, and_iff_right_iff_imp] using Ne.ne_or_ne _ #align finsupp.mem_ne_locus Finsupp.mem_neLocus theorem not_mem_neLocus {f g : α →₀ N} {a : α} : a ∉ f.neLocus g ↔ f a = g a := mem_neLocus.not.trans not_ne_iff #align finsupp.not_mem_ne_locus Finsupp.not_mem_neLocus @[simp] theorem coe_neLocus : ↑(f.neLocus g) = { x | f x ≠ g x } := by ext exact mem_neLocus #align finsupp.coe_ne_locus Finsupp.coe_neLocus @[simp] theorem neLocus_eq_empty {f g : α →₀ N} : f.neLocus g = ∅ ↔ f = g := ⟨fun h => ext fun a => not_not.mp (mem_neLocus.not.mp (Finset.eq_empty_iff_forall_not_mem.mp h a)), fun h => h ▸ by simp only [neLocus, Ne, eq_self_iff_true, not_true, Finset.filter_False]⟩ #align finsupp.ne_locus_eq_empty Finsupp.neLocus_eq_empty @[simp] theorem nonempty_neLocus_iff {f g : α →₀ N} : (f.neLocus g).Nonempty ↔ f ≠ g := Finset.nonempty_iff_ne_empty.trans neLocus_eq_empty.not #align finsupp.nonempty_ne_locus_iff Finsupp.nonempty_neLocus_iff theorem neLocus_comm : f.neLocus g = g.neLocus f := by simp_rw [neLocus, Finset.union_comm, ne_comm] #align finsupp.ne_locus_comm Finsupp.neLocus_comm @[simp] theorem neLocus_zero_right : f.neLocus 0 = f.support := by ext rw [mem_neLocus, mem_support_iff, coe_zero, Pi.zero_apply] #align finsupp.ne_locus_zero_right Finsupp.neLocus_zero_right @[simp] theorem neLocus_zero_left : (0 : α →₀ N).neLocus f = f.support := (neLocus_comm _ _).trans (neLocus_zero_right _) #align finsupp.ne_locus_zero_left Finsupp.neLocus_zero_left end NHasZero section NeLocusAndMaps theorem subset_mapRange_neLocus [DecidableEq N] [Zero N] [DecidableEq M] [Zero M] (f g : α →₀ N) {F : N → M} (F0 : F 0 = 0) : (f.mapRange F F0).neLocus (g.mapRange F F0) ⊆ f.neLocus g := fun x => by simpa only [mem_neLocus, mapRange_apply, not_imp_not] using congr_arg F #align finsupp.subset_map_range_ne_locus Finsupp.subset_mapRange_neLocus theorem zipWith_neLocus_eq_left [DecidableEq N] [Zero M] [DecidableEq P] [Zero P] [Zero N] {F : M → N → P} (F0 : F 0 0 = 0) (f : α →₀ M) (g₁ g₂ : α →₀ N) (hF : ∀ f, Function.Injective fun g => F f g) : (zipWith F F0 f g₁).neLocus (zipWith F F0 f g₂) = g₁.neLocus g₂ := by ext simpa only [mem_neLocus] using (hF _).ne_iff #align finsupp.zip_with_ne_locus_eq_left Finsupp.zipWith_neLocus_eq_left theorem zipWith_neLocus_eq_right [DecidableEq M] [Zero M] [DecidableEq P] [Zero P] [Zero N] {F : M → N → P} (F0 : F 0 0 = 0) (f₁ f₂ : α →₀ M) (g : α →₀ N) (hF : ∀ g, Function.Injective fun f => F f g) : (zipWith F F0 f₁ g).neLocus (zipWith F F0 f₂ g) = f₁.neLocus f₂ := by ext simpa only [mem_neLocus] using (hF _).ne_iff #align finsupp.zip_with_ne_locus_eq_right Finsupp.zipWith_neLocus_eq_right theorem mapRange_neLocus_eq [DecidableEq N] [DecidableEq M] [Zero M] [Zero N] (f g : α →₀ N) {F : N → M} (F0 : F 0 = 0) (hF : Function.Injective F) : (f.mapRange F F0).neLocus (g.mapRange F F0) = f.neLocus g := by ext simpa only [mem_neLocus] using hF.ne_iff #align finsupp.map_range_ne_locus_eq Finsupp.mapRange_neLocus_eq end NeLocusAndMaps variable [DecidableEq N] @[simp] theorem neLocus_add_left [AddLeftCancelMonoid N] (f g h : α →₀ N) : (f + g).neLocus (f + h) = g.neLocus h := zipWith_neLocus_eq_left _ _ _ _ add_right_injective #align finsupp.ne_locus_add_left Finsupp.neLocus_add_left @[simp] theorem neLocus_add_right [AddRightCancelMonoid N] (f g h : α →₀ N) : (f + h).neLocus (g + h) = f.neLocus g := zipWith_neLocus_eq_right _ _ _ _ add_left_injective #align finsupp.ne_locus_add_right Finsupp.neLocus_add_right section AddGroup variable [AddGroup N] (f f₁ f₂ g g₁ g₂ : α →₀ N) @[simp] theorem neLocus_neg_neg : neLocus (-f) (-g) = f.neLocus g := mapRange_neLocus_eq _ _ neg_zero neg_injective #align finsupp.ne_locus_neg_neg Finsupp.neLocus_neg_neg theorem neLocus_neg : neLocus (-f) g = f.neLocus (-g) := by rw [← neLocus_neg_neg, neg_neg] #align finsupp.ne_locus_neg Finsupp.neLocus_neg theorem neLocus_eq_support_sub : f.neLocus g = (f - g).support := by rw [← neLocus_add_right _ _ (-g), add_right_neg, neLocus_zero_right, sub_eq_add_neg] #align finsupp.ne_locus_eq_support_sub Finsupp.neLocus_eq_support_sub @[simp]
Mathlib/Data/Finsupp/NeLocus.lean
149
150
theorem neLocus_sub_left : neLocus (f - g₁) (f - g₂) = neLocus g₁ g₂ := by
simp only [sub_eq_add_neg, neLocus_add_left, neLocus_neg_neg]
/- 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.Topology.Algebra.InfiniteSum.Basic import Mathlib.Topology.Algebra.UniformGroup /-! # Infinite sums and products in topological groups Lemmas on topological sums in groups (as opposed to monoids). -/ noncomputable section open Filter Finset Function open scoped Topology variable {α β γ δ : Type*} section TopologicalGroup variable [CommGroup α] [TopologicalSpace α] [TopologicalGroup α] variable {f g : β → α} {a a₁ a₂ : α} -- `by simpa using` speeds up elaboration. Why? @[to_additive] theorem HasProd.inv (h : HasProd f a) : HasProd (fun b ↦ (f b)⁻¹) a⁻¹ := by simpa only using h.map (MonoidHom.id α)⁻¹ continuous_inv #align has_sum.neg HasSum.neg @[to_additive] theorem Multipliable.inv (hf : Multipliable f) : Multipliable fun b ↦ (f b)⁻¹ := hf.hasProd.inv.multipliable #align summable.neg Summable.neg @[to_additive] theorem Multipliable.of_inv (hf : Multipliable fun b ↦ (f b)⁻¹) : Multipliable f := by simpa only [inv_inv] using hf.inv #align summable.of_neg Summable.of_neg @[to_additive] theorem multipliable_inv_iff : (Multipliable fun b ↦ (f b)⁻¹) ↔ Multipliable f := ⟨Multipliable.of_inv, Multipliable.inv⟩ #align summable_neg_iff summable_neg_iff @[to_additive] theorem HasProd.div (hf : HasProd f a₁) (hg : HasProd g a₂) : HasProd (fun b ↦ f b / g b) (a₁ / a₂) := by simp only [div_eq_mul_inv] exact hf.mul hg.inv #align has_sum.sub HasSum.sub @[to_additive] theorem Multipliable.div (hf : Multipliable f) (hg : Multipliable g) : Multipliable fun b ↦ f b / g b := (hf.hasProd.div hg.hasProd).multipliable #align summable.sub Summable.sub @[to_additive] theorem Multipliable.trans_div (hg : Multipliable g) (hfg : Multipliable fun b ↦ f b / g b) : Multipliable f := by simpa only [div_mul_cancel] using hfg.mul hg #align summable.trans_sub Summable.trans_sub @[to_additive] theorem multipliable_iff_of_multipliable_div (hfg : Multipliable fun b ↦ f b / g b) : Multipliable f ↔ Multipliable g := ⟨fun hf ↦ hf.trans_div <| by simpa only [inv_div] using hfg.inv, fun hg ↦ hg.trans_div hfg⟩ #align summable_iff_of_summable_sub summable_iff_of_summable_sub @[to_additive] theorem HasProd.update (hf : HasProd f a₁) (b : β) [DecidableEq β] (a : α) : HasProd (update f b a) (a / f b * a₁) := by convert (hasProd_ite_eq b (a / f b)).mul hf with b' by_cases h : b' = b · rw [h, update_same] simp [eq_self_iff_true, if_true, sub_add_cancel] · simp only [h, update_noteq, if_false, Ne, one_mul, not_false_iff] #align has_sum.update HasSum.update @[to_additive] theorem Multipliable.update (hf : Multipliable f) (b : β) [DecidableEq β] (a : α) : Multipliable (update f b a) := (hf.hasProd.update b a).multipliable #align summable.update Summable.update @[to_additive] theorem HasProd.hasProd_compl_iff {s : Set β} (hf : HasProd (f ∘ (↑) : s → α) a₁) : HasProd (f ∘ (↑) : ↑sᶜ → α) a₂ ↔ HasProd f (a₁ * a₂) := by refine ⟨fun h ↦ hf.mul_compl h, fun h ↦ ?_⟩ rw [hasProd_subtype_iff_mulIndicator] at hf ⊢ rw [Set.mulIndicator_compl] simpa only [div_eq_mul_inv, mul_inv_cancel_comm] using h.div hf #align has_sum.has_sum_compl_iff HasSum.hasSum_compl_iff @[to_additive] theorem HasProd.hasProd_iff_compl {s : Set β} (hf : HasProd (f ∘ (↑) : s → α) a₁) : HasProd f a₂ ↔ HasProd (f ∘ (↑) : ↑sᶜ → α) (a₂ / a₁) := Iff.symm <| hf.hasProd_compl_iff.trans <| by rw [mul_div_cancel] #align has_sum.has_sum_iff_compl HasSum.hasSum_iff_compl @[to_additive] theorem Multipliable.multipliable_compl_iff {s : Set β} (hf : Multipliable (f ∘ (↑) : s → α)) : Multipliable (f ∘ (↑) : ↑sᶜ → α) ↔ Multipliable f where mp := fun ⟨_, ha⟩ ↦ (hf.hasProd.hasProd_compl_iff.1 ha).multipliable mpr := fun ⟨_, ha⟩ ↦ (hf.hasProd.hasProd_iff_compl.1 ha).multipliable #align summable.summable_compl_iff Summable.summable_compl_iff @[to_additive] protected theorem Finset.hasProd_compl_iff (s : Finset β) : HasProd (fun x : { x // x ∉ s } ↦ f x) a ↔ HasProd f (a * ∏ i ∈ s, f i) := (s.hasProd f).hasProd_compl_iff.trans <| by rw [mul_comm] #align finset.has_sum_compl_iff Finset.hasSum_compl_iff @[to_additive] protected theorem Finset.hasProd_iff_compl (s : Finset β) : HasProd f a ↔ HasProd (fun x : { x // x ∉ s } ↦ f x) (a / ∏ i ∈ s, f i) := (s.hasProd f).hasProd_iff_compl #align finset.has_sum_iff_compl Finset.hasSum_iff_compl @[to_additive] protected theorem Finset.multipliable_compl_iff (s : Finset β) : (Multipliable fun x : { x // x ∉ s } ↦ f x) ↔ Multipliable f := (s.multipliable f).multipliable_compl_iff #align finset.summable_compl_iff Finset.summable_compl_iff @[to_additive] theorem Set.Finite.multipliable_compl_iff {s : Set β} (hs : s.Finite) : Multipliable (f ∘ (↑) : ↑sᶜ → α) ↔ Multipliable f := (hs.multipliable f).multipliable_compl_iff #align set.finite.summable_compl_iff Set.Finite.summable_compl_iff @[to_additive] theorem hasProd_ite_div_hasProd [DecidableEq β] (hf : HasProd f a) (b : β) : HasProd (fun n ↦ ite (n = b) 1 (f n)) (a / f b) := by convert hf.update b 1 using 1 · ext n rw [Function.update_apply] · rw [div_mul_eq_mul_div, one_mul] #align has_sum_ite_sub_has_sum hasSum_ite_sub_hasSum section tprod variable [T2Space α] @[to_additive] theorem tprod_inv : ∏' b, (f b)⁻¹ = (∏' b, f b)⁻¹ := by by_cases hf : Multipliable f · exact hf.hasProd.inv.tprod_eq · simp [tprod_eq_one_of_not_multipliable hf, tprod_eq_one_of_not_multipliable (mt Multipliable.of_inv hf)] #align tsum_neg tsum_neg @[to_additive] theorem tprod_div (hf : Multipliable f) (hg : Multipliable g) : ∏' b, (f b / g b) = (∏' b, f b) / ∏' b, g b := (hf.hasProd.div hg.hasProd).tprod_eq #align tsum_sub tsum_sub @[to_additive] theorem prod_mul_tprod_compl {s : Finset β} (hf : Multipliable f) : (∏ x ∈ s, f x) * ∏' x : ↑(s : Set β)ᶜ, f x = ∏' x, f x := ((s.hasProd f).mul_compl (s.multipliable_compl_iff.2 hf).hasProd).tprod_eq.symm #align sum_add_tsum_compl sum_add_tsum_compl /-- Let `f : β → α` be a multipliable function and let `b ∈ β` be an index. Lemma `tprod_eq_mul_tprod_ite` writes `∏ n, f n` as `f b` times the product of the remaining terms. -/ @[to_additive "Let `f : β → α` be a summable function and let `b ∈ β` be an index. Lemma `tsum_eq_add_tsum_ite` writes `Σ' n, f n` as `f b` plus the sum of the remaining terms."] theorem tprod_eq_mul_tprod_ite [DecidableEq β] (hf : Multipliable f) (b : β) : ∏' n, f n = f b * ∏' n, ite (n = b) 1 (f n) := by rw [(hasProd_ite_div_hasProd hf.hasProd b).tprod_eq] exact (mul_div_cancel _ _).symm #align tsum_eq_add_tsum_ite tsum_eq_add_tsum_ite end tprod end TopologicalGroup section UniformGroup variable [CommGroup α] [UniformSpace α] /-- The **Cauchy criterion** for infinite products, also known as the **Cauchy convergence test** -/ @[to_additive "The **Cauchy criterion** for infinite sums, also known as the **Cauchy convergence test**"] theorem multipliable_iff_cauchySeq_finset [CompleteSpace α] {f : β → α} : Multipliable f ↔ CauchySeq fun s : Finset β ↦ ∏ b ∈ s, f b := by classical exact cauchy_map_iff_exists_tendsto.symm #align summable_iff_cauchy_seq_finset summable_iff_cauchySeq_finset variable [UniformGroup α] {f g : β → α} {a a₁ a₂ : α} @[to_additive] theorem cauchySeq_finset_iff_prod_vanishing : (CauchySeq fun s : Finset β ↦ ∏ b ∈ s, f b) ↔ ∀ e ∈ 𝓝 (1 : α), ∃ s : Finset β, ∀ t, Disjoint t s → (∏ b ∈ t, f b) ∈ e := by classical simp only [CauchySeq, cauchy_map_iff, and_iff_right atTop_neBot, prod_atTop_atTop_eq, uniformity_eq_comap_nhds_one α, tendsto_comap_iff, (· ∘ ·), atTop_neBot, true_and] rw [tendsto_atTop'] constructor · intro h e he obtain ⟨⟨s₁, s₂⟩, h⟩ := h e he use s₁ ∪ s₂ intro t ht specialize h (s₁ ∪ s₂, s₁ ∪ s₂ ∪ t) ⟨le_sup_left, le_sup_of_le_left le_sup_right⟩ simpa only [Finset.prod_union ht.symm, mul_div_cancel_left] using h · rintro h e he rcases exists_nhds_split_inv he with ⟨d, hd, hde⟩ rcases h d hd with ⟨s, h⟩ use (s, s) rintro ⟨t₁, t₂⟩ ⟨ht₁, ht₂⟩ have : ((∏ b ∈ t₂, f b) / ∏ b ∈ t₁, f b) = (∏ b ∈ t₂ \ s, f b) / ∏ b ∈ t₁ \ s, f b := by rw [← Finset.prod_sdiff ht₁, ← Finset.prod_sdiff ht₂, mul_div_mul_right_eq_div] simp only [this] exact hde _ (h _ Finset.sdiff_disjoint) _ (h _ Finset.sdiff_disjoint) #align cauchy_seq_finset_iff_vanishing cauchySeq_finset_iff_sum_vanishing @[to_additive] theorem cauchySeq_finset_iff_tprod_vanishing : (CauchySeq fun s : Finset β ↦ ∏ b ∈ s, f b) ↔ ∀ e ∈ 𝓝 (1 : α), ∃ s : Finset β, ∀ t : Set β, Disjoint t s → (∏' b : t, f b) ∈ e := by simp_rw [cauchySeq_finset_iff_prod_vanishing, Set.disjoint_left, disjoint_left] refine ⟨fun vanish e he ↦ ?_, fun vanish e he ↦ ?_⟩ · obtain ⟨o, ho, o_closed, oe⟩ := exists_mem_nhds_isClosed_subset he obtain ⟨s, hs⟩ := vanish o ho refine ⟨s, fun t hts ↦ oe ?_⟩ by_cases ht : Multipliable fun a : t ↦ f a · classical refine o_closed.mem_of_tendsto ht.hasProd (eventually_of_forall fun t' ↦ ?_) rw [← prod_subtype_map_embedding fun _ _ ↦ by rfl] apply hs simp_rw [Finset.mem_map] rintro _ ⟨b, -, rfl⟩ exact hts b.prop · exact tprod_eq_one_of_not_multipliable ht ▸ mem_of_mem_nhds ho · obtain ⟨s, hs⟩ := vanish _ he exact ⟨s, fun t hts ↦ (t.tprod_subtype f).symm ▸ hs _ hts⟩ variable [CompleteSpace α] @[to_additive] theorem multipliable_iff_vanishing : Multipliable f ↔ ∀ e ∈ 𝓝 (1 : α), ∃ s : Finset β, ∀ t, Disjoint t s → (∏ b ∈ t, f b) ∈ e := by rw [multipliable_iff_cauchySeq_finset, cauchySeq_finset_iff_prod_vanishing] #align summable_iff_vanishing summable_iff_vanishing @[to_additive] theorem multipliable_iff_tprod_vanishing : Multipliable f ↔ ∀ e ∈ 𝓝 (1 : α), ∃ s : Finset β, ∀ t : Set β, Disjoint t s → (∏' b : t, f b) ∈ e := by rw [multipliable_iff_cauchySeq_finset, cauchySeq_finset_iff_tprod_vanishing] -- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` @[to_additive] theorem Multipliable.multipliable_of_eq_one_or_self (hf : Multipliable f) (h : ∀ b, g b = 1 ∨ g b = f b) : Multipliable g := by classical exact multipliable_iff_vanishing.2 fun e he ↦ let ⟨s, hs⟩ := multipliable_iff_vanishing.1 hf e he ⟨s, fun t ht ↦ have eq : ∏ b ∈ t.filter fun b ↦ g b = f b, f b = ∏ b ∈ t, g b := calc ∏ b ∈ t.filter fun b ↦ g b = f b, f b = ∏ b ∈ t.filter fun b ↦ g b = f b, g b := Finset.prod_congr rfl fun b hb ↦ (Finset.mem_filter.1 hb).2.symm _ = ∏ b ∈ t, g b := by {refine Finset.prod_subset (Finset.filter_subset _ _) ?_ intro b hbt hb simp only [Finset.mem_filter, and_iff_right hbt] at hb exact (h b).resolve_right hb} eq ▸ hs _ <| Finset.disjoint_of_subset_left (Finset.filter_subset _ _) ht⟩ #align summable.summable_of_eq_zero_or_self Summable.summable_of_eq_zero_or_self @[to_additive] protected theorem Multipliable.mulIndicator (hf : Multipliable f) (s : Set β) : Multipliable (s.mulIndicator f) := hf.multipliable_of_eq_one_or_self <| Set.mulIndicator_eq_one_or_self _ _ #align summable.indicator Summable.indicator @[to_additive] theorem Multipliable.comp_injective {i : γ → β} (hf : Multipliable f) (hi : Injective i) : Multipliable (f ∘ i) := by simpa only [Set.mulIndicator_range_comp] using (hi.multipliable_iff (fun x hx ↦ Set.mulIndicator_of_not_mem hx _)).2 (hf.mulIndicator (Set.range i)) #align summable.comp_injective Summable.comp_injective @[to_additive] theorem Multipliable.subtype (hf : Multipliable f) (s : Set β) : Multipliable (f ∘ (↑) : s → α) := hf.comp_injective Subtype.coe_injective #align summable.subtype Summable.subtype @[to_additive] theorem multipliable_subtype_and_compl {s : Set β} : ((Multipliable fun x : s ↦ f x) ∧ Multipliable fun x : ↑sᶜ ↦ f x) ↔ Multipliable f := ⟨and_imp.2 Multipliable.mul_compl, fun h ↦ ⟨h.subtype s, h.subtype sᶜ⟩⟩ #align summable_subtype_and_compl summable_subtype_and_compl @[to_additive] theorem tprod_subtype_mul_tprod_subtype_compl [T2Space α] {f : β → α} (hf : Multipliable f) (s : Set β) : (∏' x : s, f x) * ∏' x : ↑sᶜ, f x = ∏' x, f x := ((hf.subtype s).hasProd.mul_compl (hf.subtype { x | x ∉ s }).hasProd).unique hf.hasProd #align tsum_subtype_add_tsum_subtype_compl tsum_subtype_add_tsum_subtype_compl @[to_additive] theorem prod_mul_tprod_subtype_compl [T2Space α] {f : β → α} (hf : Multipliable f) (s : Finset β) : (∏ x ∈ s, f x) * ∏' x : { x // x ∉ s }, f x = ∏' x, f x := by rw [← tprod_subtype_mul_tprod_subtype_compl hf s] simp only [Finset.tprod_subtype', mul_right_inj] rfl #align sum_add_tsum_subtype_compl sum_add_tsum_subtype_compl end UniformGroup section TopologicalGroup variable {G : Type*} [TopologicalSpace G] [CommGroup G] [TopologicalGroup G] {f : α → G} @[to_additive] theorem Multipliable.vanishing (hf : Multipliable f) ⦃e : Set G⦄ (he : e ∈ 𝓝 (1 : G)) : ∃ s : Finset α, ∀ t, Disjoint t s → (∏ k ∈ t, f k) ∈ e := by classical letI : UniformSpace G := TopologicalGroup.toUniformSpace G have : UniformGroup G := comm_topologicalGroup_is_uniform exact cauchySeq_finset_iff_prod_vanishing.1 hf.hasProd.cauchySeq e he #align summable.vanishing Summable.vanishing @[to_additive] theorem Multipliable.tprod_vanishing (hf : Multipliable f) ⦃e : Set G⦄ (he : e ∈ 𝓝 1) : ∃ s : Finset α, ∀ t : Set α, Disjoint t s → (∏' b : t, f b) ∈ e := by classical letI : UniformSpace G := TopologicalGroup.toUniformSpace G have : UniformGroup G := comm_topologicalGroup_is_uniform exact cauchySeq_finset_iff_tprod_vanishing.1 hf.hasProd.cauchySeq e he /-- The product over the complement of a finset tends to `1` when the finset grows to cover the whole space. This does not need a multipliability assumption, as otherwise all such products are one. -/ @[to_additive "The sum over the complement of a finset tends to `0` when the finset grows to cover the whole space. This does not need a summability assumption, as otherwise all such sums are zero."]
Mathlib/Topology/Algebra/InfiniteSum/Group.lean
347
356
theorem tendsto_tprod_compl_atTop_one (f : α → G) : Tendsto (fun s : Finset α ↦ ∏' a : { x // x ∉ s }, f a) atTop (𝓝 1) := by
classical by_cases H : Multipliable f · intro e he obtain ⟨s, hs⟩ := H.tprod_vanishing he rw [Filter.mem_map, mem_atTop_sets] exact ⟨s, fun t hts ↦ hs _ <| Set.disjoint_left.mpr fun a ha has ↦ ha (hts has)⟩ · refine tendsto_const_nhds.congr fun _ ↦ (tprod_eq_one_of_not_multipliable ?_).symm rwa [Finset.multipliable_compl_iff]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Scott Morrison, Ainsley Pahljina -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Nat import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.OrderOfElement import Mathlib.RingTheory.Fintype import Mathlib.Tactic.IntervalCases #align_import number_theory.lucas_lehmer from "leanprover-community/mathlib"@"10b4e499f43088dd3bb7b5796184ad5216648ab1" /-! # 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 Scott 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. -/ /-- The Mersenne numbers, 2^p - 1. -/ def mersenne (p : ℕ) : ℕ := 2 ^ p - 1 #align mersenne mersenne 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] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0) #align mersenne_pos mersenne_pos 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_of_one_le (by norm_num) k #align succ_mersenne succ_mersenne 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 #align lucas_lehmer.s LucasLehmer.s /-- 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 #align lucas_lehmer.s_zmod LucasLehmer.sZMod /-- 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) #align lucas_lehmer.s_mod LucasLehmer.sMod 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' #align lucas_lehmer.mersenne_int_ne_zero LucasLehmer.mersenne_int_ne_zero 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 #align lucas_lehmer.s_mod_nonneg LucasLehmer.sMod_nonneg theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod] #align lucas_lehmer.s_mod_mod LucasLehmer.sMod_mod theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by rw [← sMod_mod] refine (Int.emod_lt _ (mersenne_int_ne_zero p hp)).trans_eq ?_ exact abs_of_nonneg (mersenne_int_pos hp).le #align lucas_lehmer.s_mod_lt LucasLehmer.sMod_lt theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by induction' i with i ih · dsimp [s, sZMod] norm_num · push_cast [s, sZMod, ih]; rfl #align lucas_lehmer.s_zmod_eq_s LucasLehmer.sZMod_eq_s -- 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 #align lucas_lehmer.int.coe_nat_pow_pred LucasLehmer.Int.natCast_pow_pred @[deprecated (since := "2024-05-25")] alias Int.coe_nat_pow_pred := Int.natCast_pow_pred theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) := Int.natCast_pow_pred 2 p (by decide) #align lucas_lehmer.int.coe_nat_two_pow_pred LucasLehmer.Int.coe_nat_two_pow_pred 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 #align lucas_lehmer.s_zmod_eq_s_mod LucasLehmer.sZMod_eq_sMod /-- 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) #align lucas_lehmer.lucas_lehmer_residue LucasLehmer.lucasLehmerResidue theorem residue_eq_zero_iff_sMod_eq_zero (p : ℕ) (w : 1 < p) : lucasLehmerResidue p = 0 ↔ sMod p (p - 2) = 0 := by dsimp [lucasLehmerResidue] rw [sZMod_eq_sMod p] constructor · -- We want to use that fact that `0 ≤ s_mod p (p-2) < 2^p - 1` -- and `lucas_lehmer_residue p = 0 → 2^p - 1 ∣ s_mod p (p-2)`. intro h simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says simp only [ZMod.intCast_zmod_eq_zero_iff_dvd, gt_iff_lt, ofNat_pos, pow_pos, cast_pred, cast_pow, cast_ofNat] at h apply Int.eq_zero_of_dvd_of_nonneg_of_lt _ _ h <;> clear h · exact sMod_nonneg _ (by positivity) _ · exact sMod_lt _ (by positivity) _ · intro h rw [h] simp #align lucas_lehmer.residue_eq_zero_iff_s_mod_eq_zero LucasLehmer.residue_eq_zero_iff_sMod_eq_zero /-- **Lucas-Lehmer Test**: a Mersenne number `2^p-1` is prime if and only if the Lucas-Lehmer residue `s p (p-2) % (2^p - 1)` is zero. -/ def LucasLehmerTest (p : ℕ) : Prop := lucasLehmerResidue p = 0 #align lucas_lehmer.lucas_lehmer_test LucasLehmer.LucasLehmerTest -- Porting note: We have a fast `norm_num` extension, and we would rather use that than accidentally -- have `simp` use `decide`! /- instance : DecidablePred LucasLehmerTest := inferInstanceAs (DecidablePred (lucasLehmerResidue · = 0)) -/ /-- `q` is defined as the minimum factor of `mersenne p`, bundled as an `ℕ+`. -/ def q (p : ℕ) : ℕ+ := ⟨Nat.minFac (mersenne p), Nat.minFac_pos (mersenne p)⟩ #align lucas_lehmer.q LucasLehmer.q -- It would be nice to define this as (ℤ/qℤ)[x] / (x^2 - 3), -- obtaining the ring structure for free, -- but that seems to be more trouble than it's worth; -- if it were easy to make the definition, -- cardinality calculations would be somewhat more involved, too. /-- We construct the ring `X q` as ℤ/qℤ + √3 ℤ/qℤ. -/ def X (q : ℕ+) : Type := ZMod q × ZMod q set_option linter.uppercaseLean3 false in #align lucas_lehmer.X LucasLehmer.X namespace X variable {q : ℕ+} instance : Inhabited (X q) := inferInstanceAs (Inhabited (ZMod q × ZMod q)) instance : Fintype (X q) := inferInstanceAs (Fintype (ZMod q × ZMod q)) instance : DecidableEq (X q) := inferInstanceAs (DecidableEq (ZMod q × ZMod q)) instance : AddCommGroup (X q) := inferInstanceAs (AddCommGroup (ZMod q × ZMod q)) @[ext] theorem ext {x y : X q} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := by cases x; cases y; congr set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.ext LucasLehmer.X.ext @[simp] theorem zero_fst : (0 : X q).1 = 0 := rfl @[simp] theorem zero_snd : (0 : X q).2 = 0 := rfl @[simp] theorem add_fst (x y : X q) : (x + y).1 = x.1 + y.1 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.add_fst LucasLehmer.X.add_fst @[simp] theorem add_snd (x y : X q) : (x + y).2 = x.2 + y.2 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.add_snd LucasLehmer.X.add_snd @[simp] theorem neg_fst (x : X q) : (-x).1 = -x.1 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.neg_fst LucasLehmer.X.neg_fst @[simp] theorem neg_snd (x : X q) : (-x).2 = -x.2 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.neg_snd LucasLehmer.X.neg_snd instance : Mul (X q) where mul x y := (x.1 * y.1 + 3 * x.2 * y.2, x.1 * y.2 + x.2 * y.1) @[simp] theorem mul_fst (x y : X q) : (x * y).1 = x.1 * y.1 + 3 * x.2 * y.2 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.mul_fst LucasLehmer.X.mul_fst @[simp] theorem mul_snd (x y : X q) : (x * y).2 = x.1 * y.2 + x.2 * y.1 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.mul_snd LucasLehmer.X.mul_snd instance : One (X q) where one := ⟨1, 0⟩ @[simp] theorem one_fst : (1 : X q).1 = 1 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.one_fst LucasLehmer.X.one_fst @[simp] theorem one_snd : (1 : X q).2 = 0 := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.one_snd LucasLehmer.X.one_snd #noalign lucas_lehmer.X.bit0_fst #noalign lucas_lehmer.X.bit0_snd #noalign lucas_lehmer.X.bit1_fst #noalign lucas_lehmer.X.bit1_snd instance : Monoid (X q) := { inferInstanceAs (Mul (X q)), inferInstanceAs (One (X q)) with mul_assoc := fun x y z => by ext <;> dsimp <;> ring one_mul := fun x => by ext <;> simp mul_one := fun x => by ext <;> simp } instance : NatCast (X q) where natCast := fun n => ⟨n, 0⟩ @[simp] theorem fst_natCast (n : ℕ) : (n : X q).fst = (n : ZMod q) := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.nat_coe_fst LucasLehmer.X.fst_natCast @[simp] theorem snd_natCast (n : ℕ) : (n : X q).snd = (0 : ZMod q) := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.nat_coe_snd LucasLehmer.X.snd_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_fst (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : X q).fst = OfNat.ofNat n := rfl -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_snd (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : X q).snd = 0 := rfl instance : AddGroupWithOne (X q) := { inferInstanceAs (Monoid (X q)), inferInstanceAs (AddCommGroup (X q)), inferInstanceAs (NatCast (X q)) with natCast_zero := by ext <;> simp natCast_succ := fun _ ↦ by ext <;> simp intCast := fun n => ⟨n, 0⟩ intCast_ofNat := fun n => by ext <;> simp intCast_negSucc := fun n => by ext <;> simp } theorem left_distrib (x y z : X q) : x * (y + z) = x * y + x * z := by ext <;> dsimp <;> ring set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.left_distrib LucasLehmer.X.left_distrib theorem right_distrib (x y z : X q) : (x + y) * z = x * z + y * z := by ext <;> dsimp <;> ring set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.right_distrib LucasLehmer.X.right_distrib instance : Ring (X q) := { inferInstanceAs (AddGroupWithOne (X q)), inferInstanceAs (AddCommGroup (X q)), inferInstanceAs (Monoid (X q)) with left_distrib := left_distrib right_distrib := right_distrib mul_zero := fun _ ↦ by ext <;> simp zero_mul := fun _ ↦ by ext <;> simp } instance : CommRing (X q) := { inferInstanceAs (Ring (X q)) with mul_comm := fun _ _ ↦ by ext <;> dsimp <;> ring } instance [Fact (1 < (q : ℕ))] : Nontrivial (X q) := ⟨⟨0, 1, ne_of_apply_ne Prod.fst zero_ne_one⟩⟩ @[simp] theorem fst_intCast (n : ℤ) : (n : X q).fst = (n : ZMod q) := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.int_coe_fst LucasLehmer.X.fst_intCast @[simp] theorem snd_intCast (n : ℤ) : (n : X q).snd = (0 : ZMod q) := rfl set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.int_coe_snd LucasLehmer.X.snd_intCast @[deprecated (since := "2024-05-25")] alias nat_coe_fst := fst_natCast @[deprecated (since := "2024-05-25")] alias nat_coe_snd := snd_natCast @[deprecated (since := "2024-05-25")] alias int_coe_fst := fst_intCast @[deprecated (since := "2024-05-25")] alias int_coe_snd := snd_intCast @[norm_cast] theorem coe_mul (n m : ℤ) : ((n * m : ℤ) : X q) = (n : X q) * (m : X q) := by ext <;> simp set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.coe_mul LucasLehmer.X.coe_mul @[norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ) : X q) = (n : X q) := by ext <;> simp set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.coe_nat LucasLehmer.X.coe_natCast @[deprecated (since := "2024-04-05")] alias coe_nat := coe_natCast /-- The cardinality of `X` is `q^2`. -/ theorem card_eq : Fintype.card (X q) = q ^ 2 := by dsimp [X] rw [Fintype.card_prod, ZMod.card q, sq] set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.X_card LucasLehmer.X.card_eq /-- There are strictly fewer than `q^2` units, since `0` is not a unit. -/ nonrec theorem card_units_lt (w : 1 < q) : Fintype.card (X q)ˣ < q ^ 2 := by have : Fact (1 < (q : ℕ)) := ⟨w⟩ convert card_units_lt (X q) rw [card_eq] set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.units_card LucasLehmer.X.card_units_lt /-- We define `ω = 2 + √3`. -/ def ω : X q := (2, 1) set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.ω LucasLehmer.X.ω /-- We define `ωb = 2 - √3`, which is the inverse of `ω`. -/ def ωb : X q := (2, -1) set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.ωb LucasLehmer.X.ωb theorem ω_mul_ωb (q : ℕ+) : (ω : X q) * ωb = 1 := by dsimp [ω, ωb] ext <;> simp; ring set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.ω_mul_ωb LucasLehmer.X.ω_mul_ωb theorem ωb_mul_ω (q : ℕ+) : (ωb : X q) * ω = 1 := by rw [mul_comm, ω_mul_ωb] set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.ωb_mul_ω LucasLehmer.X.ωb_mul_ω /-- A closed form for the recurrence relation. -/ theorem closed_form (i : ℕ) : (s i : X q) = (ω : X q) ^ 2 ^ i + (ωb : X q) ^ 2 ^ i := by induction' i with i ih · dsimp [s, ω, ωb] ext <;> norm_num · calc (s (i + 1) : X q) = (s i ^ 2 - 2 : ℤ) := rfl _ = (s i : X q) ^ 2 - 2 := by push_cast; rfl _ = (ω ^ 2 ^ i + ωb ^ 2 ^ i) ^ 2 - 2 := by rw [ih] _ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 + 2 * (ωb ^ 2 ^ i * ω ^ 2 ^ i) - 2 := by ring _ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 := by rw [← mul_pow ωb ω, ωb_mul_ω, one_pow, mul_one, add_sub_cancel_right] _ = ω ^ 2 ^ (i + 1) + ωb ^ 2 ^ (i + 1) := by rw [← pow_mul, ← pow_mul, _root_.pow_succ] set_option linter.uppercaseLean3 false in #align lucas_lehmer.X.closed_form LucasLehmer.X.closed_form end X open X /-! Here and below, we introduce `p' = p - 2`, in order to avoid using subtraction in `ℕ`. -/ /-- If `1 < p`, then `q p`, the smallest prime factor of `mersenne p`, is more than 2. -/ theorem two_lt_q (p' : ℕ) : 2 < q (p' + 2) := by refine (minFac_prime (one_lt_mersenne.2 ?_).ne').two_le.lt_of_ne' ?_ · exact le_add_left _ _ · rw [Ne, minFac_eq_two_iff, mersenne, Nat.pow_succ'] exact Nat.two_not_dvd_two_mul_sub_one Nat.one_le_two_pow #align lucas_lehmer.two_lt_q LucasLehmer.two_lt_q theorem ω_pow_formula (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : ∃ k : ℤ, (ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) = k * mersenne (p' + 2) * (ω : X (q (p' + 2))) ^ 2 ^ p' - 1 := by dsimp [lucasLehmerResidue] at h rw [sZMod_eq_s p'] at h simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says simp only [add_tsub_cancel_right, ZMod.intCast_zmod_eq_zero_iff_dvd, gt_iff_lt, ofNat_pos, pow_pos, cast_pred, cast_pow, cast_ofNat] at h cases' h with k h use k replace h := congr_arg (fun n : ℤ => (n : X (q (p' + 2)))) h -- coercion from ℤ to X q dsimp at h rw [closed_form] at h replace h := congr_arg (fun x => ω ^ 2 ^ p' * x) h dsimp at h have t : 2 ^ p' + 2 ^ p' = 2 ^ (p' + 1) := by ring rw [mul_add, ← pow_add ω, t, ← mul_pow ω ωb (2 ^ p'), ω_mul_ωb, one_pow] at h rw [mul_comm, coe_mul] at h rw [mul_comm _ (k : X (q (p' + 2)))] at h replace h := eq_sub_of_add_eq h have : 1 ≤ 2 ^ (p' + 2) := Nat.one_le_pow _ _ (by decide) exact mod_cast h #align lucas_lehmer.ω_pow_formula LucasLehmer.ω_pow_formula /-- `q` is the minimum factor of `mersenne p`, so `M p = 0` in `X q`. -/ theorem mersenne_coe_X (p : ℕ) : (mersenne p : X (q p)) = 0 := by ext <;> simp [mersenne, q, ZMod.natCast_zmod_eq_zero_iff_dvd, -pow_pos] apply Nat.minFac_dvd set_option linter.uppercaseLean3 false in #align lucas_lehmer.mersenne_coe_X LucasLehmer.mersenne_coe_X theorem ω_pow_eq_neg_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : (ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) = -1 := by cases' ω_pow_formula p' h with k w rw [mersenne_coe_X] at w simpa using w #align lucas_lehmer.ω_pow_eq_neg_one LucasLehmer.ω_pow_eq_neg_one
Mathlib/NumberTheory/LucasLehmer.lean
504
510
theorem ω_pow_eq_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : (ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = 1 := calc (ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = (ω ^ 2 ^ (p' + 1)) ^ 2 := by
rw [← pow_mul, ← Nat.pow_succ] _ = (-1) ^ 2 := by rw [ω_pow_eq_neg_one p' h] _ = 1 := by simp
/- Copyright (c) 2022 Moritz Firsching. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Firsching, Fabian Kruse, Nikolas Kuhn -/ import Mathlib.Analysis.PSeries import Mathlib.Data.Real.Pi.Wallis import Mathlib.Tactic.AdaptationNote #align_import analysis.special_functions.stirling from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # Stirling's formula This file proves Stirling's formula for the factorial. It states that $n!$ grows asymptotically like $\sqrt{2\pi n}(\frac{n}{e})^n$. ## Proof outline The proof follows: <https://proofwiki.org/wiki/Stirling%27s_Formula>. We proceed in two parts. **Part 1**: We consider the sequence $a_n$ of fractions $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$ and prove that this sequence converges to a real, positive number $a$. For this the two main ingredients are - taking the logarithm of the sequence and - using the series expansion of $\log(1 + x)$. **Part 2**: We use the fact that the series defined in part 1 converges against a real number $a$ and prove that $a = \sqrt{\pi}$. Here the main ingredient is the convergence of Wallis' product formula for `π`. -/ open scoped Topology Real Nat Asymptotics open Finset Filter Nat Real namespace Stirling /-! ### Part 1 https://proofwiki.org/wiki/Stirling%27s_Formula#Part_1 -/ /-- Define `stirlingSeq n` as $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$. Stirling's formula states that this sequence has limit $\sqrt(π)$. -/ noncomputable def stirlingSeq (n : ℕ) : ℝ := n ! / (√(2 * n : ℝ) * (n / exp 1) ^ n) #align stirling.stirling_seq Stirling.stirlingSeq @[simp] theorem stirlingSeq_zero : stirlingSeq 0 = 0 := by rw [stirlingSeq, cast_zero, mul_zero, Real.sqrt_zero, zero_mul, div_zero] #align stirling.stirling_seq_zero Stirling.stirlingSeq_zero @[simp] theorem stirlingSeq_one : stirlingSeq 1 = exp 1 / √2 := by rw [stirlingSeq, pow_one, factorial_one, cast_one, mul_one, mul_one_div, one_div_div] #align stirling.stirling_seq_one Stirling.stirlingSeq_one theorem log_stirlingSeq_formula (n : ℕ) : log (stirlingSeq n) = Real.log n ! - 1 / 2 * Real.log (2 * n) - n * log (n / exp 1) := by cases n · simp · rw [stirlingSeq, log_div, log_mul, sqrt_eq_rpow, log_rpow, Real.log_pow, tsub_tsub] <;> positivity -- Porting note: generalized from `n.succ` to `n` #align stirling.log_stirling_seq_formula Stirling.log_stirlingSeq_formulaₓ /-- The sequence `log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))` has the series expansion `∑ 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))` -/ theorem log_stirlingSeq_diff_hasSum (m : ℕ) : HasSum (fun k : ℕ => (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ ↑(k + 1)) (log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))) := by let f (k : ℕ) := (1 : ℝ) / (2 * k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k change HasSum (fun k => f (k + 1)) _ rw [hasSum_nat_add_iff] convert (hasSum_log_one_add_inv m.cast_add_one_pos).mul_left ((↑(m + 1) : ℝ) + 1 / 2) using 1 · ext k dsimp only [f] rw [← pow_mul, pow_add] push_cast field_simp ring · have h : ∀ x ≠ (0 : ℝ), 1 + x⁻¹ = (x + 1) / x := fun x hx ↦ by field_simp [hx] simp (disch := positivity) only [log_stirlingSeq_formula, log_div, log_mul, log_exp, factorial_succ, cast_mul, cast_succ, cast_zero, range_one, sum_singleton, h] ring #align stirling.log_stirling_seq_diff_has_sum Stirling.log_stirlingSeq_diff_hasSum /-- The sequence `log ∘ stirlingSeq ∘ succ` is monotone decreasing -/ theorem log_stirlingSeq'_antitone : Antitone (Real.log ∘ stirlingSeq ∘ succ) := antitone_nat_of_succ_le fun n => sub_nonneg.mp <| (log_stirlingSeq_diff_hasSum n).nonneg fun m => by positivity #align stirling.log_stirling_seq'_antitone Stirling.log_stirlingSeq'_antitone /-- We have a bound for successive elements in the sequence `log (stirlingSeq k)`. -/
Mathlib/Analysis/SpecialFunctions/Stirling.lean
104
120
theorem log_stirlingSeq_diff_le_geo_sum (n : ℕ) : log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≤ ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) := by
have h_nonneg : (0 : ℝ) ≤ ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 := sq_nonneg _ have g : HasSum (fun k : ℕ => (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1)) (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2)) := by have := (hasSum_geometric_of_lt_one h_nonneg ?_).mul_left (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) · simp_rw [← _root_.pow_succ'] at this exact this rw [one_div, inv_pow] exact inv_lt_one (one_lt_pow ((lt_add_iff_pos_left 1).mpr <| by positivity) two_ne_zero) have hab (k : ℕ) : (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) ≤ (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) := by refine mul_le_of_le_one_left (pow_nonneg h_nonneg ↑(k + 1)) ?_ rw [one_div] exact inv_le_one (le_add_of_nonneg_left <| by positivity) exact hasSum_le hab (log_stirlingSeq_diff_hasSum n) g
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.OuterMeasure.Caratheodory /-! # Induced Outer Measure We can extend a function defined on a subset of `Set α` to an outer measure. The underlying function is called `extend`, and the measure it induces is called `inducedOuterMeasure`. Some lemmas below are proven twice, once in the general case, and one where the function `m` is only defined on measurable sets (i.e. when `P = MeasurableSet`). In the latter cases, we can remove some hypotheses in the statement. The general version has the same name, but with a prime at the end. ## Tags outer measure -/ #align_import measure_theory.measure.outer_measure from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" noncomputable section open Set Function Filter open scoped Classical NNReal Topology ENNReal namespace MeasureTheory open OuterMeasure section Extend variable {α : Type*} {P : α → Prop} variable (m : ∀ s : α, P s → ℝ≥0∞) /-- We can trivially extend a function defined on a subclass of objects (with codomain `ℝ≥0∞`) to all objects by defining it to be `∞` on the objects not in the class. -/ def extend (s : α) : ℝ≥0∞ := ⨅ h : P s, m s h #align measure_theory.extend MeasureTheory.extend theorem extend_eq {s : α} (h : P s) : extend m s = m s h := by simp [extend, h] #align measure_theory.extend_eq MeasureTheory.extend_eq theorem extend_eq_top {s : α} (h : ¬P s) : extend m s = ∞ := by simp [extend, h] #align measure_theory.extend_eq_top MeasureTheory.extend_eq_top theorem smul_extend {R} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] {c : R} (hc : c ≠ 0) : c • extend m = extend fun s h => c • m s h := by ext1 s dsimp [extend] by_cases h : P s · simp [h] · simp [h, ENNReal.smul_top, hc] #align measure_theory.smul_extend MeasureTheory.smul_extend
Mathlib/MeasureTheory/OuterMeasure/Induced.lean
65
68
theorem le_extend {s : α} (h : P s) : m s h ≤ extend m s := by
simp only [extend, le_iInf_iff] intro rfl
/- 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.Nat.Defs import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common #align_import data.fin.basic from "leanprover-community/mathlib"@"3a2b5524a138b5d0b818b858b516d4ac8a484b03" /-! # 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`. * `Fin.succRec` : Define `C n i` by induction on `i : Fin n` interpreted as `(0 : Fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple. * `Fin.succRecOn` : same as `Fin.succRec` but `i : Fin n` is the first argument; * `Fin.induction` : Define `C i` by induction on `i : Fin (n + 1)`, separating into the `Nat`-like base cases of `C 0` and `C (i.succ)`. * `Fin.inductionOn` : same as `Fin.induction` but with `i : Fin (n + 1)` as the first argument. * `Fin.cases` : define `f : Π i : Fin n.succ, C i` by separately handling the cases `i = 0` and `i = Fin.succ j`, `j : Fin n`, defined using `Fin.induction`. * `Fin.reverseInduction`: reverse induction on `i : Fin (n + 1)`; given `C (Fin.last n)` and `∀ i : Fin n, C (Fin.succ i) → C (Fin.castSucc i)`, constructs all values `C i` by going down; * `Fin.lastCases`: define `f : Π i, Fin (n + 1), C i` by separately handling the cases `i = Fin.last n` and `i = Fin.castSucc j`, a special case of `Fin.reverseInduction`; * `Fin.addCases`: define a function on `Fin (m + n)` by separately handling the cases `Fin.castAdd n i` and `Fin.natAdd m i`; * `Fin.succAboveCases`: given `i : Fin (n + 1)`, define a function on `Fin (n + 1)` by separately handling the cases `j = i` and `j = Fin.succAbove i k`, same as `Fin.insertNth` but marked as eliminator and works for `Sort*`. -- Porting note: this is in another file ### 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.ofNat'`: given a positive number `n` (deduced from `[NeZero n]`), `Fin.ofNat' i` is `i % n` interpreted as an element of `Fin n`; * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; ### Misc definitions * `Fin.revPerm : Equiv.Perm (Fin n)` : `Fin.rev` as an `Equiv.Perm`, the antitone involution given by `i ↦ n-(i+1)` -/ assert_not_exists Monoid universe u v open Fin Nat Function /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 #align fin_zero_elim finZeroElim namespace Fin 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 _) #align fin.elim0' Fin.elim0 variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff #align fin.fin_to_nat Fin.coeToNat theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n #align fin.val_injective Fin.val_injective /-- 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 #align fin.prop Fin.prop #align fin.is_lt Fin.is_lt #align fin.pos Fin.pos #align fin.pos_iff_nonempty Fin.pos_iff_nonempty section Order variable {a b c : Fin n} protected lemma lt_of_le_of_lt : a ≤ b → b < c → a < c := Nat.lt_of_le_of_lt protected lemma lt_of_lt_of_le : a < b → b ≤ c → a < c := Nat.lt_of_lt_of_le protected lemma le_rfl : a ≤ a := Nat.le_refl _ protected lemma lt_iff_le_and_ne : a < b ↔ a ≤ b ∧ a ≠ b := by rw [← val_ne_iff]; exact Nat.lt_iff_le_and_ne protected lemma lt_or_lt_of_ne (h : a ≠ b) : a < b ∨ b < a := Nat.lt_or_lt_of_ne $ val_ne_iff.2 h protected lemma lt_or_le (a b : Fin n) : a < b ∨ b ≤ a := Nat.lt_or_ge _ _ protected lemma le_or_lt (a b : Fin n) : a ≤ b ∨ b < a := (b.lt_or_le a).symm protected lemma le_of_eq (hab : a = b) : a ≤ b := Nat.le_of_eq $ congr_arg val hab protected lemma ge_of_eq (hab : a = b) : b ≤ a := Fin.le_of_eq hab.symm protected lemma eq_or_lt_of_le : a ≤ b → a = b ∨ a < b := by rw [ext_iff]; exact Nat.eq_or_lt_of_le protected lemma lt_or_eq_of_le : a ≤ b → a < b ∨ a = b := by rw [ext_iff]; exact Nat.lt_or_eq_of_le end Order 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 #align fin.equiv_subtype Fin.equivSubtype #align fin.equiv_subtype_symm_apply Fin.equivSubtype_symm_apply #align fin.equiv_subtype_apply Fin.equivSubtype_apply section coe /-! ### coercions and constructions -/ #align fin.eta Fin.eta #align fin.ext Fin.ext #align fin.ext_iff Fin.ext_iff #align fin.coe_injective Fin.val_injective theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := ext_iff.symm #align fin.coe_eq_coe Fin.val_eq_val @[deprecated ext_iff (since := "2024-02-20")] theorem eq_iff_veq (a b : Fin n) : a = b ↔ a.1 = b.1 := ext_iff #align fin.eq_iff_veq Fin.eq_iff_veq theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := ext_iff.not #align fin.ne_iff_vne Fin.ne_iff_vne -- Porting note: I'm not sure if this comment still applies. -- built-in reduction doesn't always work @[simp, nolint simpNF] theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := ext_iff #align fin.mk_eq_mk Fin.mk_eq_mk #align fin.mk.inj_iff Fin.mk.inj_iff #align fin.mk_val Fin.val_mk #align fin.eq_mk_iff_coe_eq Fin.eq_mk_iff_val_eq #align fin.coe_mk Fin.val_mk #align fin.mk_coe Fin.mk_val -- syntactic tautologies now #noalign fin.coe_eq_val #noalign fin.val_eq_coe /-- 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 [Function.funext_iff] #align fin.heq_fun_iff Fin.heq_fun_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 [Function.funext_iff] 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] #align fin.heq_ext_iff Fin.heq_ext_iff #align fin.exists_iff Fin.exists_iff #align fin.forall_iff Fin.forall_iff end coe section Order /-! ### order -/ #align fin.is_le Fin.is_le #align fin.is_le' Fin.is_le' #align fin.lt_iff_coe_lt_coe Fin.lt_iff_val_lt_val theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl #align fin.le_iff_coe_le_coe Fin.le_iff_val_le_val #align fin.mk_lt_of_lt_coe Fin.mk_lt_of_lt_val #align fin.mk_le_of_le_coe Fin.mk_le_of_le_val /-- `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 #align fin.coe_fin_lt Fin.val_fin_lt /-- `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 #align fin.coe_fin_le Fin.val_fin_le #align fin.mk_le_mk Fin.mk_le_mk #align fin.mk_lt_mk Fin.mk_lt_mk -- @[simp] -- Porting note (#10618): simp can prove this theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp #align fin.min_coe Fin.min_val -- @[simp] -- Porting note (#10618): simp can prove this theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp #align fin.max_coe Fin.max_val /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ #align fin.coe_embedding Fin.valEmbedding @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl #align fin.equiv_subtype_symm_trans_val_embedding Fin.equivSubtype_symm_trans_valEmbedding /-- 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 → ℕ) /-- Given a positive `n`, `Fin.ofNat' i` is `i % n` as an element of `Fin n`. -/ def ofNat'' [NeZero n] (i : ℕ) : Fin n := ⟨i % n, mod_lt _ n.pos_of_neZero⟩ #align fin.of_nat' Fin.ofNat''ₓ -- Porting note: `Fin.ofNat'` conflicts with something in core (there the hypothesis is `n > 0`), -- so for now we make this double-prime `''`. This is also the reason for the dubious translation. instance {n : ℕ} [NeZero n] : Zero (Fin n) := ⟨ofNat'' 0⟩ instance {n : ℕ} [NeZero n] : One (Fin n) := ⟨ofNat'' 1⟩ #align fin.coe_zero Fin.val_zero /-- The `Fin.val_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem val_zero' (n : ℕ) [NeZero n] : ((0 : Fin n) : ℕ) = 0 := rfl #align fin.val_zero' Fin.val_zero' #align fin.mk_zero Fin.mk_zero /-- 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 #align fin.zero_le Fin.zero_le' #align fin.zero_lt_one Fin.zero_lt_one #align fin.not_lt_zero Fin.not_lt_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_fin_lt, val_zero', Nat.pos_iff_ne_zero, Ne, Ne, ext_iff, val_zero'] #align fin.pos_iff_ne_zero Fin.pos_iff_ne_zero' #align fin.eq_zero_or_eq_succ Fin.eq_zero_or_eq_succ #align fin.eq_succ_of_ne_zero Fin.eq_succ_of_ne_zero @[simp] lemma cast_eq_self (a : Fin n) : cast rfl a = a := rfl theorem rev_involutive : Involutive (rev : Fin n → Fin n) := fun i => ext <| by dsimp only [rev] rw [← Nat.sub_sub, Nat.sub_sub_self (Nat.add_one_le_iff.2 i.is_lt), Nat.add_sub_cancel_right] #align fin.rev_involutive Fin.rev_involutive /-- `Fin.rev` as an `Equiv.Perm`, the antitone involution `Fin n → Fin n` given by `i ↦ n-(i+1)`. -/ @[simps! apply symm_apply] def revPerm : Equiv.Perm (Fin n) := Involutive.toPerm rev rev_involutive #align fin.rev Fin.revPerm #align fin.coe_rev Fin.val_revₓ theorem rev_injective : Injective (@rev n) := rev_involutive.injective #align fin.rev_injective Fin.rev_injective theorem rev_surjective : Surjective (@rev n) := rev_involutive.surjective #align fin.rev_surjective Fin.rev_surjective theorem rev_bijective : Bijective (@rev n) := rev_involutive.bijective #align fin.rev_bijective Fin.rev_bijective #align fin.rev_inj Fin.rev_injₓ #align fin.rev_rev Fin.rev_revₓ @[simp] theorem revPerm_symm : (@revPerm n).symm = revPerm := rfl #align fin.rev_symm Fin.revPerm_symm #align fin.rev_eq Fin.rev_eqₓ #align fin.rev_le_rev Fin.rev_le_revₓ #align fin.rev_lt_rev Fin.rev_lt_revₓ theorem cast_rev (i : Fin n) (h : n = m) : cast h i.rev = (i.cast h).rev := by subst h; simp theorem rev_eq_iff {i j : Fin n} : rev i = j ↔ i = rev j := by rw [← rev_inj, rev_rev] theorem rev_ne_iff {i j : Fin n} : rev i ≠ j ↔ i ≠ rev j := rev_eq_iff.not theorem rev_lt_iff {i j : Fin n} : rev i < j ↔ rev j < i := by rw [← rev_lt_rev, rev_rev] theorem rev_le_iff {i j : Fin n} : rev i ≤ j ↔ rev j ≤ i := by rw [← rev_le_rev, rev_rev] theorem lt_rev_iff {i j : Fin n} : i < rev j ↔ j < rev i := by rw [← rev_lt_rev, rev_rev] theorem le_rev_iff {i j : Fin n} : i ≤ rev j ↔ j ≤ rev i := by rw [← rev_le_rev, rev_rev] #align fin.last Fin.last #align fin.coe_last Fin.val_last -- Porting note: this is now syntactically equal to `val_last` #align fin.last_val Fin.val_last #align fin.le_last Fin.le_last #align fin.last_pos Fin.last_pos #align fin.eq_last_of_not_lt Fin.eq_last_of_not_lt theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero theorem one_lt_last [NeZero n] : 1 < last (n + 1) := Nat.lt_add_left_iff_pos.2 n.pos_of_neZero end Order section Add /-! ### addition, numerals, and coercion from Nat -/ #align fin.val_one Fin.val_one #align fin.coe_one Fin.val_one @[simp] theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n := rfl #align fin.coe_one' Fin.val_one' -- Porting note: Delete this lemma after porting theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) := rfl #align fin.one_val Fin.val_one'' #align fin.mk_one Fin.mk_one 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 [← Nat.one_eq_succ_zero, Fin.nontrivial, not_nontrivial, Nat.succ_le_iff] -- Porting note: here and in the next lemma, had to use `← Nat.one_eq_succ_zero`. #align fin.nontrivial_iff_two_le Fin.nontrivial_iff_two_le #align fin.subsingleton_iff_le_one Fin.subsingleton_iff_le_one section Monoid -- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance protected theorem add_zero [NeZero n] (k : Fin n) : k + 0 = k := by simp only [add_def, val_zero', Nat.add_zero, mod_eq_of_lt (is_lt k)] #align fin.add_zero Fin.add_zero -- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance protected theorem zero_add [NeZero n] (k : Fin n) : 0 + k = k := by simp [ext_iff, add_def, mod_eq_of_lt (is_lt k)] #align fin.zero_add Fin.zero_add instance {a : ℕ} [NeZero n] : OfNat (Fin n) a where ofNat := Fin.ofNat' a n.pos_of_neZero instance inhabited (n : ℕ) [NeZero n] : Inhabited (Fin n) := ⟨0⟩ 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 #align fin.default_eq_zero Fin.default_eq_zero section from_ad_hoc @[simp] lemma ofNat'_zero {h : 0 < n} [NeZero n] : (Fin.ofNat' 0 h : Fin n) = 0 := rfl @[simp] lemma ofNat'_one {h : 0 < n} [NeZero n] : (Fin.ofNat' 1 h : Fin n) = 1 := rfl end from_ad_hoc instance instNatCast [NeZero n] : NatCast (Fin n) where natCast n := Fin.ofNat'' n lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl end Monoid #align fin.val_add Fin.val_add #align fin.coe_add Fin.val_add 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)] #align fin.coe_add_eq_ite Fin.val_add_eq_ite section deprecated set_option linter.deprecated false @[deprecated] theorem val_bit0 {n : ℕ} (k : Fin n) : ((bit0 k : Fin n) : ℕ) = bit0 (k : ℕ) % n := by cases k rfl #align fin.coe_bit0 Fin.val_bit0 @[deprecated] theorem val_bit1 {n : ℕ} [NeZero n] (k : Fin n) : ((bit1 k : Fin n) : ℕ) = bit1 (k : ℕ) % n := by cases n; · cases' k with k h cases k · show _ % _ = _ simp at h cases' h with _ h simp [bit1, Fin.val_bit0, Fin.val_add, Fin.val_one] #align fin.coe_bit1 Fin.val_bit1 end deprecated #align fin.coe_add_one_of_lt Fin.val_add_one_of_lt #align fin.last_add_one Fin.last_add_one #align fin.coe_add_one Fin.val_add_one section Bit set_option linter.deprecated false @[simp, deprecated] theorem mk_bit0 {m n : ℕ} (h : bit0 m < n) : (⟨bit0 m, h⟩ : Fin n) = (bit0 ⟨m, (Nat.le_add_right m m).trans_lt h⟩ : Fin _) := eq_of_val_eq (Nat.mod_eq_of_lt h).symm #align fin.mk_bit0 Fin.mk_bit0 @[simp, deprecated] theorem mk_bit1 {m n : ℕ} [NeZero n] (h : bit1 m < n) : (⟨bit1 m, h⟩ : Fin n) = (bit1 ⟨m, (Nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ : Fin _) := by ext simp only [bit1, bit0] at h simp only [bit1, bit0, val_add, val_one', ← Nat.add_mod, Nat.mod_eq_of_lt h] #align fin.mk_bit1 Fin.mk_bit1 end Bit #align fin.val_two Fin.val_two --- Porting note: syntactically the same as the above #align fin.coe_two Fin.val_two section OfNatCoe @[simp] theorem ofNat''_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : (Fin.ofNat'' a : Fin n) = a := rfl #align fin.of_nat_eq_coe Fin.ofNat''_eq_cast @[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl @[deprecated (since := "2024-04-17")] alias val_nat_cast := val_natCast -- Porting note: is this the right name for things involving `Nat.cast`? /-- 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 #align fin.coe_val_of_lt Fin.val_cast_of_lt /-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results in the same value. -/ @[simp] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := ext <| val_cast_of_lt a.isLt #align fin.coe_val_eq_self Fin.cast_val_eq_self -- Porting note: this is syntactically the same as `val_cast_of_lt` #align fin.coe_coe_of_lt Fin.val_cast_of_lt -- Porting note: this is syntactically the same as `cast_val_of_lt` #align fin.coe_coe_eq_self Fin.cast_val_eq_self @[simp] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp @[deprecated (since := "2024-04-17")] alias nat_cast_self := natCast_self @[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by simp [ext_iff, Nat.dvd_iff_mod_eq_zero] @[deprecated (since := "2024-04-17")] alias nat_cast_eq_zero := natCast_eq_zero @[simp] theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp #align fin.coe_nat_eq_last Fin.natCast_eq_last @[deprecated (since := "2024-05-04")] alias cast_nat_eq_last := natCast_eq_last theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by rw [Fin.natCast_eq_last] exact Fin.le_last i #align fin.le_coe_last Fin.le_val_last 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 #align fin.add_one_pos Fin.add_one_pos #align fin.one_pos Fin.one_pos #align fin.zero_ne_one Fin.zero_ne_one @[simp] theorem one_eq_zero_iff [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by obtain _ | _ | n := n <;> simp [Fin.ext_iff] #align fin.one_eq_zero_iff Fin.one_eq_zero_iff @[simp] theorem zero_eq_one_iff [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by rw [eq_comm, one_eq_zero_iff] #align fin.zero_eq_one_iff Fin.zero_eq_one_iff end Add section Succ /-! ### succ and casts into larger Fin types -/ #align fin.coe_succ Fin.val_succ #align fin.succ_pos Fin.succ_pos lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [ext_iff] #align fin.succ_injective Fin.succ_injective /-- `Fin.succ` as an `Embedding` -/ def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where toFun := succ inj' := succ_injective _ @[simp] theorem val_succEmb : ⇑(succEmb n) = Fin.succ := rfl #align fin.succ_le_succ_iff Fin.succ_le_succ_iff #align fin.succ_lt_succ_iff Fin.succ_lt_succ_iff @[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⟩)⟩ #align fin.exists_succ_eq_iff Fin.exists_succ_eq theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x := exists_succ_eq.mpr h #align fin.succ_inj Fin.succ_inj #align fin.succ_ne_zero Fin.succ_ne_zero @[simp] theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl #align fin.succ_zero_eq_one Fin.succ_zero_eq_one' 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' #align fin.succ_zero_eq_one' Fin.succ_zero_eq_one /-- 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 #align fin.succ_one_eq_two Fin.succ_one_eq_two' -- Version of `succ_one_eq_two` to be used by `dsimp`. -- Note the `'` swapped around due to a move to std4. #align fin.succ_one_eq_two' Fin.succ_one_eq_two #align fin.succ_mk Fin.succ_mk #align fin.mk_succ_pos Fin.mk_succ_pos #align fin.one_lt_succ_succ Fin.one_lt_succ_succ #align fin.add_one_lt_iff Fin.add_one_lt_iff #align fin.add_one_le_iff Fin.add_one_le_iff #align fin.last_le_iff Fin.last_le_iff #align fin.lt_add_one_iff Fin.lt_add_one_iff /-- 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 _⟩ #align fin.le_zero_iff Fin.le_zero_iff' #align fin.succ_succ_ne_one Fin.succ_succ_ne_one #align fin.cast_lt Fin.castLT #align fin.coe_cast_lt Fin.coe_castLT #align fin.cast_lt_mk Fin.castLT_mk -- Move to Batteries? @[simp] theorem cast_refl {n : Nat} (h : n = n) : Fin.cast h = id := rfl -- 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 [ext_iff] @[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [ext_iff] attribute [simp] castSucc_inj lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) := fun a b hab ↦ ext (by have := congr_arg val hab; exact this) lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _ lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _ #align fin.cast_succ_injective Fin.castSucc_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 #align fin.coe_cast_le Fin.coe_castLE #align fin.cast_le_mk Fin.castLE_mk #align fin.cast_le_zero Fin.castLE_zero /- 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). -/ assert_not_exists Fintype 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 => cases' h with e 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 _⟩⟩ #align fin.equiv_iff_eq Fin.equiv_iff_eq @[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⟩, Fin.ext rfl⟩⟩ #align fin.range_cast_le Fin.range_castLE @[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 _ _) #align fin.coe_of_injective_cast_le_symm Fin.coe_of_injective_castLE_symm #align fin.cast_le_succ Fin.castLE_succ #align fin.cast_le_cast_le Fin.castLE_castLE #align fin.cast_le_comp_cast_le Fin.castLE_comp_castLE theorem leftInverse_cast (eq : n = m) : LeftInverse (cast eq.symm) (cast eq) := fun _ => rfl theorem rightInverse_cast (eq : n = m) : RightInverse (cast eq.symm) (cast eq) := fun _ => rfl theorem cast_le_cast (eq : n = m) {a b : Fin n} : cast eq a ≤ cast eq b ↔ 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 := cast eq invFun := cast eq.symm left_inv := leftInverse_cast eq right_inv := rightInverse_cast eq #align fin_congr finCongr @[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl #align fin_congr_apply_mk finCongr_apply_mk @[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 #align fin_congr_symm finCongr_symm @[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl #align fin_congr_apply_coe finCongr_apply_coe lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl #align fin_congr_symm_apply_coe finCongr_symm_apply_coe /-- 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 #align fin.coe_cast Fin.coe_castₓ @[simp] theorem cast_zero {n' : ℕ} [NeZero n] {h : n = n'} : cast h (0 : Fin n) = by { haveI : NeZero n' := by {rw [← h]; infer_instance}; exact 0} := ext rfl #align fin.cast_zero Fin.cast_zero #align fin.cast_last Fin.cast_lastₓ #align fin.cast_mk Fin.cast_mkₓ #align fin.cast_trans Fin.cast_transₓ #align fin.cast_le_of_eq Fin.castLE_of_eq /-- 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) : (cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by subst h ext rfl #align fin.cast_eq_cast Fin.cast_eq_cast /-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ @[simps! apply] def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m) #align fin.coe_cast_add Fin.coe_castAdd #align fin.cast_add_zero Fin.castAdd_zeroₓ #align fin.cast_add_lt Fin.castAdd_lt #align fin.cast_add_mk Fin.castAdd_mk #align fin.cast_add_cast_lt Fin.castAdd_castLT #align fin.cast_lt_cast_add Fin.castLT_castAdd #align fin.cast_add_cast Fin.castAdd_castₓ #align fin.cast_cast_add_left Fin.cast_castAdd_leftₓ #align fin.cast_cast_add_right Fin.cast_castAdd_rightₓ #align fin.cast_add_cast_add Fin.castAdd_castAdd #align fin.cast_succ_eq Fin.cast_succ_eqₓ #align fin.succ_cast_eq Fin.succ_cast_eqₓ /-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ @[simps! apply] def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _ @[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl #align fin.coe_cast_succ Fin.coe_castSucc #align fin.cast_succ_mk Fin.castSucc_mk #align fin.cast_cast_succ Fin.cast_castSuccₓ #align fin.cast_succ_lt_succ Fin.castSucc_lt_succ #align fin.le_cast_succ_iff Fin.le_castSucc_iff #align fin.cast_succ_lt_iff_succ_le Fin.castSucc_lt_iff_succ_le #align fin.succ_last Fin.succ_last #align fin.succ_eq_last_succ Fin.succ_eq_last_succ #align fin.cast_succ_cast_lt Fin.castSucc_castLT #align fin.cast_lt_cast_succ Fin.castLT_castSucc #align fin.cast_succ_lt_cast_succ_iff Fin.castSucc_lt_castSucc_iff @[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := Iff.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 #align fin.succ_above_lt_gt Fin.castSucc_lt_or_lt_succ @[deprecated] alias succAbove_lt_gt := castSucc_lt_or_lt_succ 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 exists_castSucc_eq_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) : ∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h #align fin.cast_succ_inj Fin.castSucc_inj #align fin.cast_succ_lt_last Fin.castSucc_lt_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⟩) 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 := ext rfl #align fin.cast_succ_zero Fin.castSucc_zero' #align fin.cast_succ_one Fin.castSucc_one /-- `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. -/ theorem castSucc_pos' [NeZero n] {i : Fin n} (h : 0 < i) : 0 < castSucc i := by simpa [lt_iff_val_lt_val] using h #align fin.cast_succ_pos Fin.castSucc_pos' /-- 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 #align fin.cast_succ_eq_zero_iff Fin.castSucc_eq_zero_iff' /-- 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 #align fin.cast_succ_ne_zero_iff Fin.castSucc_ne_zero_iff 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, 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 a 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, ext_iff] exact ((le_last _).trans_lt' h).ne #align fin.cast_succ_fin_succ Fin.castSucc_fin_succ @[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) #align fin.coe_eq_cast_succ Fin.coe_eq_castSucc 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] #align fin.coe_succ_eq_succ Fin.coeSucc_eq_succ #align fin.lt_succ Fin.lt_succ @[simp] theorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) = ({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega) #align fin.range_cast_succ Fin.range_castSucc @[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 _ _) #align fin.coe_of_injective_cast_succ_symm Fin.coe_of_injective_castSucc_symm #align fin.succ_cast_succ Fin.succ_castSucc /-- `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 [ext_iff] #align fin.coe_add_nat Fin.coe_addNat #align fin.add_nat_one Fin.addNat_one #align fin.le_coe_add_nat Fin.le_coe_addNat #align fin.add_nat_mk Fin.addNat_mk #align fin.cast_add_nat_zero Fin.cast_addNat_zeroₓ #align fin.add_nat_cast Fin.addNat_castₓ #align fin.cast_add_nat_left Fin.cast_addNat_leftₓ #align fin.cast_add_nat_right Fin.cast_addNat_rightₓ /-- `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 [ext_iff] #align fin.coe_nat_add Fin.coe_natAdd #align fin.nat_add_mk Fin.natAdd_mk #align fin.le_coe_nat_add Fin.le_coe_natAdd #align fin.nat_add_zero Fin.natAdd_zeroₓ #align fin.nat_add_cast Fin.natAdd_castₓ #align fin.cast_nat_add_right Fin.cast_natAdd_rightₓ #align fin.cast_nat_add_left Fin.cast_natAdd_leftₓ #align fin.cast_add_nat_add Fin.castAdd_natAddₓ #align fin.nat_add_cast_add Fin.natAdd_castAddₓ #align fin.nat_add_nat_add Fin.natAdd_natAddₓ #align fin.cast_nat_add_zero Fin.cast_natAdd_zeroₓ #align fin.cast_nat_add Fin.cast_natAddₓ #align fin.cast_add_nat Fin.cast_addNatₓ #align fin.nat_add_last Fin.natAdd_last #align fin.nat_add_cast_succ Fin.natAdd_castSucc end Succ section Pred /-! ### pred -/ #align fin.pred Fin.pred #align fin.coe_pred Fin.coe_pred #align fin.succ_pred Fin.succ_pred #align fin.pred_succ Fin.pred_succ #align fin.pred_eq_iff_eq_succ Fin.pred_eq_iff_eq_succ #align fin.pred_mk_succ Fin.pred_mk_succ #align fin.pred_mk Fin.pred_mk #align fin.pred_le_pred_iff Fin.pred_le_pred_iff #align fin.pred_lt_pred_iff Fin.pred_lt_pred_iff #align fin.pred_inj Fin.pred_inj #align fin.pred_one Fin.pred_one #align fin.pred_add_one Fin.pred_add_one #align fin.sub_nat Fin.subNat #align fin.coe_sub_nat Fin.coe_subNat #align fin.sub_nat_mk Fin.subNat_mk #align fin.pred_cast_succ_succ Fin.pred_castSucc_succ #align fin.add_nat_sub_nat Fin.addNat_subNat #align fin.sub_nat_add_nat Fin.subNat_addNat #align fin.nat_add_sub_nat_cast Fin.natAdd_subNat_castₓ 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 := 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' := a.castSucc_ne_zero_iff.mpr ha) : (a.pred ha).castSucc = (castSucc a).pred ha' := rfl #align fin.cast_succ_pred_eq_pred_cast_succ Fin.castSucc_pred_eq_pred_castSucc theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) : (a.pred ha).castSucc + 1 = a := by cases' a using cases with a · 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]
Mathlib/Data/Fin/Basic.lean
1,148
1,150
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]
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bhavik Mehta -/ import Mathlib.CategoryTheory.Adjunction.Reflective import Mathlib.Topology.StoneCech import Mathlib.CategoryTheory.Monad.Limits import Mathlib.Topology.UrysohnsLemma import Mathlib.Topology.Category.TopCat.Limits.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.CategoryTheory.Elementwise #align_import topology.category.CompHaus.basic from "leanprover-community/mathlib"@"178a32653e369dce2da68dc6b2694e385d484ef1" /-! # The category of Compact Hausdorff Spaces We construct the category of compact Hausdorff spaces. The type of compact Hausdorff spaces is denoted `CompHaus`, and it is endowed with a category instance making it a full subcategory of `TopCat`. The fully faithful functor `CompHaus ⥤ TopCat` is denoted `compHausToTop`. **Note:** The file `Topology/Category/Compactum.lean` provides the equivalence between `Compactum`, which is defined as the category of algebras for the ultrafilter monad, and `CompHaus`. `CompactumToCompHaus` is the functor from `Compactum` to `CompHaus` which is proven to be an equivalence of categories in `CompactumToCompHaus.isEquivalence`. See `topology/category/Compactum.lean` for a more detailed discussion where these definitions are introduced. -/ universe v u -- This was a global instance prior to #13170. We may experiment with removing it. attribute [local instance] CategoryTheory.ConcreteCategory.instFunLike open CategoryTheory /-- The type of Compact Hausdorff topological spaces. -/ structure CompHaus where /-- The underlying topological space of an object of `CompHaus`. -/ toTop : TopCat -- Porting note: Renamed field. /-- The underlying topological space is compact. -/ [is_compact : CompactSpace toTop] /-- The underlying topological space is T2. -/ [is_hausdorff : T2Space toTop] set_option linter.uppercaseLean3 false in #align CompHaus CompHaus namespace CompHaus instance : Inhabited CompHaus := ⟨{ toTop := { α := PEmpty } }⟩ instance : CoeSort CompHaus Type* := ⟨fun X => X.toTop⟩ instance {X : CompHaus} : CompactSpace X := X.is_compact instance {X : CompHaus} : T2Space X := X.is_hausdorff instance category : Category CompHaus := InducedCategory.category toTop set_option linter.uppercaseLean3 false in #align CompHaus.category CompHaus.category instance concreteCategory : ConcreteCategory CompHaus := InducedCategory.concreteCategory _ set_option linter.uppercaseLean3 false in #align CompHaus.concrete_category CompHaus.concreteCategory /- -- Porting note: This is now a syntactic tautology. @[simp] theorem coe_toTop {X : CompHaus} : (X.toTop : Type*) = X := rfl set_option linter.uppercaseLean3 false in #align CompHaus.coe_to_Top CompHaus.coe_toTop -/ variable (X : Type*) [TopologicalSpace X] [CompactSpace X] [T2Space X] /-- A constructor for objects of the category `CompHaus`, taking a type, and bundling the compact Hausdorff topology found by typeclass inference. -/ def of : CompHaus where toTop := TopCat.of X is_compact := ‹_› is_hausdorff := ‹_› set_option linter.uppercaseLean3 false in #align CompHaus.of CompHaus.of @[simp] theorem coe_of : (CompHaus.of X : Type _) = X := rfl set_option linter.uppercaseLean3 false in #align CompHaus.coe_of CompHaus.coe_of -- Porting note (#10754): Adding instance instance (X : CompHaus.{u}) : TopologicalSpace ((forget CompHaus).obj X) := show TopologicalSpace X.toTop from inferInstance -- Porting note (#10754): Adding instance instance (X : CompHaus.{u}) : CompactSpace ((forget CompHaus).obj X) := show CompactSpace X.toTop from inferInstance -- Porting note (#10754): Adding instance instance (X : CompHaus.{u}) : T2Space ((forget CompHaus).obj X) := show T2Space X.toTop from inferInstance /-- Any continuous function on compact Hausdorff spaces is a closed map. -/ theorem isClosedMap {X Y : CompHaus.{u}} (f : X ⟶ Y) : IsClosedMap f := fun _ hC => (hC.isCompact.image f.continuous).isClosed set_option linter.uppercaseLean3 false in #align CompHaus.is_closed_map CompHaus.isClosedMap /-- Any continuous bijection of compact Hausdorff spaces is an isomorphism. -/ theorem isIso_of_bijective {X Y : CompHaus.{u}} (f : X ⟶ Y) (bij : Function.Bijective f) : IsIso f := by let E := Equiv.ofBijective _ bij have hE : Continuous E.symm := by rw [continuous_iff_isClosed] intro S hS rw [← E.image_eq_preimage] exact isClosedMap f S hS refine ⟨⟨⟨E.symm, hE⟩, ?_, ?_⟩⟩ · ext x apply E.symm_apply_apply · ext x apply E.apply_symm_apply set_option linter.uppercaseLean3 false in #align CompHaus.is_iso_of_bijective CompHaus.isIso_of_bijective /-- Any continuous bijection of compact Hausdorff spaces induces an isomorphism. -/ noncomputable def isoOfBijective {X Y : CompHaus.{u}} (f : X ⟶ Y) (bij : Function.Bijective f) : X ≅ Y := letI := isIso_of_bijective _ bij asIso f set_option linter.uppercaseLean3 false in #align CompHaus.iso_of_bijective CompHaus.isoOfBijective /-- Construct an isomorphism from a homeomorphism. -/ @[simps hom inv] def isoOfHomeo {X Y : CompHaus.{u}} (f : X ≃ₜ Y) : X ≅ Y where hom := ⟨f, f.continuous⟩ inv := ⟨f.symm, f.symm.continuous⟩ hom_inv_id := by ext x exact f.symm_apply_apply x inv_hom_id := by ext x exact f.apply_symm_apply x /-- Construct a homeomorphism from an isomorphism. -/ @[simps] def homeoOfIso {X Y : CompHaus.{u}} (f : X ≅ Y) : X ≃ₜ Y where toFun := f.hom invFun := f.inv left_inv x := by simp right_inv x := by simp continuous_toFun := f.hom.continuous continuous_invFun := f.inv.continuous /-- The equivalence between isomorphisms in `CompHaus` and homeomorphisms of topological spaces. -/ @[simps] def isoEquivHomeo {X Y : CompHaus.{u}} : (X ≅ Y) ≃ (X ≃ₜ Y) where toFun := homeoOfIso invFun := isoOfHomeo left_inv f := by ext rfl right_inv f := by ext rfl end CompHaus /-- The fully faithful embedding of `CompHaus` in `TopCat`. -/ -- Porting note: `semireducible` -> `.default`. @[simps (config := { rhsMd := .default })] def compHausToTop : CompHaus.{u} ⥤ TopCat.{u} := inducedFunctor _ -- deriving Full, Faithful -- Porting note: deriving fails, adding manually. set_option linter.uppercaseLean3 false in #align CompHaus_to_Top compHausToTop instance : compHausToTop.Full := show (inducedFunctor _).Full from inferInstance instance : compHausToTop.Faithful := show (inducedFunctor _).Faithful from inferInstance -- Porting note (#10754): Adding instance instance (X : CompHaus) : CompactSpace (compHausToTop.obj X) := show CompactSpace X.toTop from inferInstance -- Porting note (#10754): Adding instance instance (X : CompHaus) : T2Space (compHausToTop.obj X) := show T2Space X.toTop from inferInstance instance CompHaus.forget_reflectsIsomorphisms : (forget CompHaus.{u}).ReflectsIsomorphisms := ⟨by intro A B f hf; exact CompHaus.isIso_of_bijective _ ((isIso_iff_bijective f).mp hf)⟩ set_option linter.uppercaseLean3 false in #align CompHaus.forget_reflects_isomorphisms CompHaus.forget_reflectsIsomorphisms /-- (Implementation) The object part of the compactification functor from topological spaces to compact Hausdorff spaces. -/ @[simps!] def stoneCechObj (X : TopCat) : CompHaus := CompHaus.of (StoneCech X) set_option linter.uppercaseLean3 false in #align StoneCech_obj stoneCechObj /-- (Implementation) The bijection of homsets to establish the reflective adjunction of compact Hausdorff spaces in topological spaces. -/ noncomputable def stoneCechEquivalence (X : TopCat.{u}) (Y : CompHaus.{u}) : (stoneCechObj X ⟶ Y) ≃ (X ⟶ compHausToTop.obj Y) where toFun f := { toFun := f ∘ stoneCechUnit continuous_toFun := f.2.comp (@continuous_stoneCechUnit X _) } invFun f := { toFun := stoneCechExtend f.2 continuous_toFun := continuous_stoneCechExtend f.2 } left_inv := by rintro ⟨f : StoneCech X ⟶ Y, hf : Continuous f⟩ -- Porting note: `ext` fails. apply ContinuousMap.ext intro (x : StoneCech X) refine congr_fun ?_ x apply Continuous.ext_on denseRange_stoneCechUnit (continuous_stoneCechExtend _) hf · rintro _ ⟨y, rfl⟩ apply congr_fun (stoneCechExtend_extends (hf.comp _)) y apply continuous_stoneCechUnit right_inv := by rintro ⟨f : (X : Type _) ⟶ Y, hf : Continuous f⟩ -- Porting note: `ext` fails. apply ContinuousMap.ext intro exact congr_fun (stoneCechExtend_extends hf) _ #align stone_cech_equivalence stoneCechEquivalence /-- The Stone-Cech compactification functor from topological spaces to compact Hausdorff spaces, left adjoint to the inclusion functor. -/ noncomputable def topToCompHaus : TopCat.{u} ⥤ CompHaus.{u} := Adjunction.leftAdjointOfEquiv stoneCechEquivalence.{u} fun _ _ _ _ _ => rfl set_option linter.uppercaseLean3 false in #align Top_to_CompHaus topToCompHaus theorem topToCompHaus_obj (X : TopCat) : ↥(topToCompHaus.obj X) = StoneCech X := rfl set_option linter.uppercaseLean3 false in #align Top_to_CompHaus_obj topToCompHaus_obj /-- The category of compact Hausdorff spaces is reflective in the category of topological spaces. -/ noncomputable instance compHausToTop.reflective : Reflective compHausToTop where L := topToCompHaus adj := Adjunction.adjunctionOfEquivLeft _ _ set_option linter.uppercaseLean3 false in #align CompHaus_to_Top.reflective compHausToTop.reflective noncomputable instance compHausToTop.createsLimits : CreatesLimits compHausToTop := monadicCreatesLimits _ set_option linter.uppercaseLean3 false in #align CompHaus_to_Top.creates_limits compHausToTop.createsLimits instance CompHaus.hasLimits : Limits.HasLimits CompHaus := hasLimits_of_hasLimits_createsLimits compHausToTop set_option linter.uppercaseLean3 false in #align CompHaus.has_limits CompHaus.hasLimits instance CompHaus.hasColimits : Limits.HasColimits CompHaus := hasColimits_of_reflective compHausToTop set_option linter.uppercaseLean3 false in #align CompHaus.has_colimits CompHaus.hasColimits namespace CompHaus /-- An explicit limit cone for a functor `F : J ⥤ CompHaus`, defined in terms of `TopCat.limitCone`. -/ def limitCone {J : Type v} [SmallCategory J] (F : J ⥤ CompHaus.{max v u}) : Limits.Cone F := letI FF : J ⥤ TopCat := F ⋙ compHausToTop { pt := { toTop := (TopCat.limitCone FF).pt is_compact := by show CompactSpace { u : ∀ j, F.obj j | ∀ {i j : J} (f : i ⟶ j), (F.map f) (u i) = u j } rw [← isCompact_iff_compactSpace] apply IsClosed.isCompact have : { u : ∀ j, F.obj j | ∀ {i j : J} (f : i ⟶ j), F.map f (u i) = u j } = ⋂ (i : J) (j : J) (f : i ⟶ j), { u | F.map f (u i) = u j } := by ext1 simp only [Set.mem_iInter, Set.mem_setOf_eq] rw [this] apply isClosed_iInter intro i apply isClosed_iInter intro j apply isClosed_iInter intro f apply isClosed_eq · exact (ContinuousMap.continuous (F.map f)).comp (continuous_apply i) · exact continuous_apply j is_hausdorff := show T2Space { u : ∀ j, F.obj j | ∀ {i j : J} (f : i ⟶ j), (F.map f) (u i) = u j } from inferInstance } π := { app := fun j => (TopCat.limitCone FF).π.app j naturality := by intro _ _ f ext ⟨x, hx⟩ simp only [comp_apply, Functor.const_obj_map, id_apply] exact (hx f).symm } } set_option linter.uppercaseLean3 false in #align CompHaus.limit_cone CompHaus.limitCone /-- The limit cone `CompHaus.limitCone F` is indeed a limit cone. -/ def limitConeIsLimit {J : Type v} [SmallCategory J] (F : J ⥤ CompHaus.{max v u}) : Limits.IsLimit.{v} (limitCone.{v,u} F) := letI FF : J ⥤ TopCat := F ⋙ compHausToTop { lift := fun S => (TopCat.limitConeIsLimit FF).lift (compHausToTop.mapCone S) fac := fun S => (TopCat.limitConeIsLimit FF).fac (compHausToTop.mapCone S) uniq := fun S => (TopCat.limitConeIsLimit FF).uniq (compHausToTop.mapCone S) } set_option linter.uppercaseLean3 false in #align CompHaus.limit_cone_is_limit CompHaus.limitConeIsLimit theorem epi_iff_surjective {X Y : CompHaus.{u}} (f : X ⟶ Y) : Epi f ↔ Function.Surjective f := by constructor · dsimp [Function.Surjective] contrapose! rintro ⟨y, hy⟩ hf let C := Set.range f have hC : IsClosed C := (isCompact_range f.continuous).isClosed let D := ({y} : Set Y) have hD : IsClosed D := isClosed_singleton have hCD : Disjoint C D := by rw [Set.disjoint_singleton_right] rintro ⟨y', hy'⟩ exact hy y' hy' obtain ⟨φ, hφ0, hφ1, hφ01⟩ := exists_continuous_zero_one_of_isClosed hC hD hCD haveI : CompactSpace (ULift.{u} <| Set.Icc (0 : ℝ) 1) := Homeomorph.ulift.symm.compactSpace haveI : T2Space (ULift.{u} <| Set.Icc (0 : ℝ) 1) := Homeomorph.ulift.symm.t2Space let Z := of (ULift.{u} <| Set.Icc (0 : ℝ) 1) let g : Y ⟶ Z := ⟨fun y' => ⟨⟨φ y', hφ01 y'⟩⟩, continuous_uLift_up.comp (φ.continuous.subtype_mk fun y' => hφ01 y')⟩ let h : Y ⟶ Z := ⟨fun _ => ⟨⟨0, Set.left_mem_Icc.mpr zero_le_one⟩⟩, continuous_const⟩ have H : h = g := by rw [← cancel_epi f] ext x -- Porting note: `ext` doesn't apply these two lemmas. apply ULift.ext apply Subtype.ext dsimp -- Porting note: This `change` is not ideal. -- I think lean is having issues understanding when a `ContinuousMap` should be considered -- as a morphism. -- TODO(?): Make morphisms in `CompHaus` (and other topological categories) -- into a one-field-structure. change 0 = φ (f x) simp only [hφ0 (Set.mem_range_self x), Pi.zero_apply] apply_fun fun e => (e y).down.1 at H dsimp [Z] at H change 0 = φ y at H simp only [hφ1 (Set.mem_singleton y), Pi.one_apply] at H exact zero_ne_one H · rw [← CategoryTheory.epi_iff_surjective] apply (forget CompHaus).epi_of_epi_map set_option linter.uppercaseLean3 false in #align CompHaus.epi_iff_surjective CompHaus.epi_iff_surjective
Mathlib/Topology/Category/CompHaus/Basic.lean
380
392
theorem mono_iff_injective {X Y : CompHaus.{u}} (f : X ⟶ Y) : Mono f ↔ Function.Injective f := by
constructor · intro hf x₁ x₂ h let g₁ : of PUnit ⟶ X := ⟨fun _ => x₁, continuous_const⟩ let g₂ : of PUnit ⟶ X := ⟨fun _ => x₂, continuous_const⟩ have : g₁ ≫ f = g₂ ≫ f := by ext exact h rw [cancel_mono] at this apply_fun fun e => e PUnit.unit at this exact this · rw [← CategoryTheory.mono_iff_injective] apply (forget CompHaus).mono_of_mono_map
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Batteries.Control.ForInStep.Lemmas import Batteries.Data.List.Basic import Batteries.Tactic.Init import Batteries.Tactic.Alias namespace List open Nat /-! ### mem -/ @[simp] theorem mem_toArray {a : α} {l : List α} : a ∈ l.toArray ↔ a ∈ l := by simp [Array.mem_def] /-! ### drop -/ @[simp] theorem drop_one : ∀ l : List α, drop 1 l = tail l | [] | _ :: _ => rfl /-! ### zipWith -/ theorem zipWith_distrib_tail : (zipWith f l l').tail = zipWith f l.tail l'.tail := by rw [← drop_one]; simp [zipWith_distrib_drop] /-! ### List subset -/ theorem subset_def {l₁ l₂ : List α} : l₁ ⊆ l₂ ↔ ∀ {a : α}, a ∈ l₁ → a ∈ l₂ := .rfl @[simp] theorem nil_subset (l : List α) : [] ⊆ l := nofun @[simp] theorem Subset.refl (l : List α) : l ⊆ l := fun _ i => i theorem Subset.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ ⊆ l₂) (h₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ := fun _ i => h₂ (h₁ i) instance : Trans (Membership.mem : α → List α → Prop) Subset Membership.mem := ⟨fun h₁ h₂ => h₂ h₁⟩ instance : Trans (Subset : List α → List α → Prop) Subset Subset := ⟨Subset.trans⟩ @[simp] theorem subset_cons (a : α) (l : List α) : l ⊆ a :: l := fun _ => Mem.tail _ theorem subset_of_cons_subset {a : α} {l₁ l₂ : List α} : a :: l₁ ⊆ l₂ → l₁ ⊆ l₂ := fun s _ i => s (mem_cons_of_mem _ i) theorem subset_cons_of_subset (a : α) {l₁ l₂ : List α} : l₁ ⊆ l₂ → l₁ ⊆ a :: l₂ := fun s _ i => .tail _ (s i) theorem cons_subset_cons {l₁ l₂ : List α} (a : α) (s : l₁ ⊆ l₂) : a :: l₁ ⊆ a :: l₂ := fun _ => by simp only [mem_cons]; exact Or.imp_right (@s _) @[simp] theorem subset_append_left (l₁ l₂ : List α) : l₁ ⊆ l₁ ++ l₂ := fun _ => mem_append_left _ @[simp] theorem subset_append_right (l₁ l₂ : List α) : l₂ ⊆ l₁ ++ l₂ := fun _ => mem_append_right _ theorem subset_append_of_subset_left (l₂ : List α) : l ⊆ l₁ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_left _ _ theorem subset_append_of_subset_right (l₁ : List α) : l ⊆ l₂ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_right _ _ @[simp] theorem cons_subset : a :: l ⊆ m ↔ a ∈ m ∧ l ⊆ m := by simp only [subset_def, mem_cons, or_imp, forall_and, forall_eq] @[simp] theorem append_subset {l₁ l₂ l : List α} : l₁ ++ l₂ ⊆ l ↔ l₁ ⊆ l ∧ l₂ ⊆ l := by simp [subset_def, or_imp, forall_and] theorem subset_nil {l : List α} : l ⊆ [] ↔ l = [] := ⟨fun h => match l with | [] => rfl | _::_ => (nomatch h (.head ..)), fun | rfl => Subset.refl _⟩ theorem map_subset {l₁ l₂ : List α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ := fun x => by simp only [mem_map]; exact .imp fun a => .imp_left (@H _) /-! ### sublists -/ @[simp] theorem nil_sublist : ∀ l : List α, [] <+ l | [] => .slnil | a :: l => (nil_sublist l).cons a @[simp] theorem Sublist.refl : ∀ l : List α, l <+ l | [] => .slnil | a :: l => (Sublist.refl l).cons₂ a theorem Sublist.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ <+ l₂) (h₂ : l₂ <+ l₃) : l₁ <+ l₃ := by induction h₂ generalizing l₁ with | slnil => exact h₁ | cons _ _ IH => exact (IH h₁).cons _ | @cons₂ l₂ _ a _ IH => generalize e : a :: l₂ = l₂' match e ▸ h₁ with | .slnil => apply nil_sublist | .cons a' h₁' => cases e; apply (IH h₁').cons | .cons₂ a' h₁' => cases e; apply (IH h₁').cons₂ instance : Trans (@Sublist α) Sublist Sublist := ⟨Sublist.trans⟩ @[simp] theorem sublist_cons (a : α) (l : List α) : l <+ a :: l := (Sublist.refl l).cons _ theorem sublist_of_cons_sublist : a :: l₁ <+ l₂ → l₁ <+ l₂ := (sublist_cons a l₁).trans @[simp] theorem sublist_append_left : ∀ l₁ l₂ : List α, l₁ <+ l₁ ++ l₂ | [], _ => nil_sublist _ | _ :: l₁, l₂ => (sublist_append_left l₁ l₂).cons₂ _ @[simp] theorem sublist_append_right : ∀ l₁ l₂ : List α, l₂ <+ l₁ ++ l₂ | [], _ => Sublist.refl _ | _ :: l₁, l₂ => (sublist_append_right l₁ l₂).cons _ theorem sublist_append_of_sublist_left (s : l <+ l₁) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_left .. theorem sublist_append_of_sublist_right (s : l <+ l₂) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_right .. @[simp] theorem cons_sublist_cons : a :: l₁ <+ a :: l₂ ↔ l₁ <+ l₂ := ⟨fun | .cons _ s => sublist_of_cons_sublist s | .cons₂ _ s => s, .cons₂ _⟩ @[simp] theorem append_sublist_append_left : ∀ l, l ++ l₁ <+ l ++ l₂ ↔ l₁ <+ l₂ | [] => Iff.rfl | _ :: l => cons_sublist_cons.trans (append_sublist_append_left l) theorem Sublist.append_left : l₁ <+ l₂ → ∀ l, l ++ l₁ <+ l ++ l₂ := fun h l => (append_sublist_append_left l).mpr h theorem Sublist.append_right : l₁ <+ l₂ → ∀ l, l₁ ++ l <+ l₂ ++ l | .slnil, _ => Sublist.refl _ | .cons _ h, _ => (h.append_right _).cons _ | .cons₂ _ h, _ => (h.append_right _).cons₂ _ theorem sublist_or_mem_of_sublist (h : l <+ l₁ ++ a :: l₂) : l <+ l₁ ++ l₂ ∨ a ∈ l := by induction l₁ generalizing l with | nil => match h with | .cons _ h => exact .inl h | .cons₂ _ h => exact .inr (.head ..) | cons b l₁ IH => match h with | .cons _ h => exact (IH h).imp_left (Sublist.cons _) | .cons₂ _ h => exact (IH h).imp (Sublist.cons₂ _) (.tail _) theorem Sublist.reverse : l₁ <+ l₂ → l₁.reverse <+ l₂.reverse | .slnil => Sublist.refl _ | .cons _ h => by rw [reverse_cons]; exact sublist_append_of_sublist_left h.reverse | .cons₂ _ h => by rw [reverse_cons, reverse_cons]; exact h.reverse.append_right _ @[simp] theorem reverse_sublist : l₁.reverse <+ l₂.reverse ↔ l₁ <+ l₂ := ⟨fun h => l₁.reverse_reverse ▸ l₂.reverse_reverse ▸ h.reverse, Sublist.reverse⟩ @[simp] theorem append_sublist_append_right (l) : l₁ ++ l <+ l₂ ++ l ↔ l₁ <+ l₂ := ⟨fun h => by have := h.reverse simp only [reverse_append, append_sublist_append_left, reverse_sublist] at this exact this, fun h => h.append_right l⟩ theorem Sublist.append (hl : l₁ <+ l₂) (hr : r₁ <+ r₂) : l₁ ++ r₁ <+ l₂ ++ r₂ := (hl.append_right _).trans ((append_sublist_append_left _).2 hr) theorem Sublist.subset : l₁ <+ l₂ → l₁ ⊆ l₂ | .slnil, _, h => h | .cons _ s, _, h => .tail _ (s.subset h) | .cons₂ .., _, .head .. => .head .. | .cons₂ _ s, _, .tail _ h => .tail _ (s.subset h) instance : Trans (@Sublist α) Subset Subset := ⟨fun h₁ h₂ => trans h₁.subset h₂⟩ instance : Trans Subset (@Sublist α) Subset := ⟨fun h₁ h₂ => trans h₁ h₂.subset⟩ instance : Trans (Membership.mem : α → List α → Prop) Sublist Membership.mem := ⟨fun h₁ h₂ => h₂.subset h₁⟩ theorem Sublist.length_le : l₁ <+ l₂ → length l₁ ≤ length l₂ | .slnil => Nat.le_refl 0 | .cons _l s => le_succ_of_le (length_le s) | .cons₂ _ s => succ_le_succ (length_le s) @[simp] theorem sublist_nil {l : List α} : l <+ [] ↔ l = [] := ⟨fun s => subset_nil.1 s.subset, fun H => H ▸ Sublist.refl _⟩ theorem Sublist.eq_of_length : l₁ <+ l₂ → length l₁ = length l₂ → l₁ = l₂ | .slnil, _ => rfl | .cons a s, h => nomatch Nat.not_lt.2 s.length_le (h ▸ lt_succ_self _) | .cons₂ a s, h => by rw [s.eq_of_length (succ.inj h)] theorem Sublist.eq_of_length_le (s : l₁ <+ l₂) (h : length l₂ ≤ length l₁) : l₁ = l₂ := s.eq_of_length <| Nat.le_antisymm s.length_le h @[simp] theorem singleton_sublist {a : α} {l} : [a] <+ l ↔ a ∈ l := by refine ⟨fun h => h.subset (mem_singleton_self _), fun h => ?_⟩ obtain ⟨_, _, rfl⟩ := append_of_mem h exact ((nil_sublist _).cons₂ _).trans (sublist_append_right ..) @[simp] theorem replicate_sublist_replicate {m n} (a : α) : replicate m a <+ replicate n a ↔ m ≤ n := by refine ⟨fun h => ?_, fun h => ?_⟩ · have := h.length_le; simp only [length_replicate] at this ⊢; exact this · induction h with | refl => apply Sublist.refl | step => simp [*, replicate, Sublist.cons] theorem isSublist_iff_sublist [BEq α] [LawfulBEq α] {l₁ l₂ : List α} : l₁.isSublist l₂ ↔ l₁ <+ l₂ := by cases l₁ <;> cases l₂ <;> simp [isSublist] case cons.cons hd₁ tl₁ hd₂ tl₂ => if h_eq : hd₁ = hd₂ then simp [h_eq, cons_sublist_cons, isSublist_iff_sublist] else simp only [beq_iff_eq, h_eq] constructor · intro h_sub apply Sublist.cons exact isSublist_iff_sublist.mp h_sub · intro h_sub cases h_sub case cons h_sub => exact isSublist_iff_sublist.mpr h_sub case cons₂ => contradiction instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ <+ l₂) := decidable_of_iff (l₁.isSublist l₂) isSublist_iff_sublist /-! ### tail -/ theorem tail_eq_tailD (l) : @tail α l = tailD l [] := by cases l <;> rfl theorem tail_eq_tail? (l) : @tail α l = (tail? l).getD [] := by simp [tail_eq_tailD] /-! ### next? -/ @[simp] theorem next?_nil : @next? α [] = none := rfl @[simp] theorem next?_cons (a l) : @next? α (a :: l) = some (a, l) := rfl /-! ### get? -/ theorem get_eq_iff : List.get l n = x ↔ l.get? n.1 = some x := by simp [get?_eq_some] theorem get?_inj (h₀ : i < xs.length) (h₁ : Nodup xs) (h₂ : xs.get? i = xs.get? j) : i = j := by induction xs generalizing i j with | nil => cases h₀ | cons x xs ih => match i, j with | 0, 0 => rfl | i+1, j+1 => simp; cases h₁ with | cons ha h₁ => exact ih (Nat.lt_of_succ_lt_succ h₀) h₁ h₂ | i+1, 0 => ?_ | 0, j+1 => ?_ all_goals simp at h₂ cases h₁; rename_i h' h have := h x ?_ rfl; cases this rw [mem_iff_get?] exact ⟨_, h₂⟩; exact ⟨_ , h₂.symm⟩ /-! ### drop -/ theorem tail_drop (l : List α) (n : Nat) : (l.drop n).tail = l.drop (n + 1) := by induction l generalizing n with | nil => simp | cons hd tl hl => cases n · simp · simp [hl] /-! ### modifyNth -/ @[simp] theorem modifyNth_nil (f : α → α) (n) : [].modifyNth f n = [] := by cases n <;> rfl @[simp] theorem modifyNth_zero_cons (f : α → α) (a : α) (l : List α) : (a :: l).modifyNth f 0 = f a :: l := rfl @[simp] theorem modifyNth_succ_cons (f : α → α) (a : α) (l : List α) (n) : (a :: l).modifyNth f (n + 1) = a :: l.modifyNth f n := by rfl theorem modifyNthTail_id : ∀ n (l : List α), l.modifyNthTail id n = l | 0, _ => rfl | _+1, [] => rfl | n+1, a :: l => congrArg (cons a) (modifyNthTail_id n l) theorem eraseIdx_eq_modifyNthTail : ∀ n (l : List α), eraseIdx l n = modifyNthTail tail n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, a :: l => congrArg (cons _) (eraseIdx_eq_modifyNthTail _ _) @[deprecated] alias removeNth_eq_nth_tail := eraseIdx_eq_modifyNthTail theorem get?_modifyNth (f : α → α) : ∀ n (l : List α) m, (modifyNth f n l).get? m = (fun a => if n = m then f a else a) <$> l.get? m | n, l, 0 => by cases l <;> cases n <;> rfl | n, [], _+1 => by cases n <;> rfl | 0, _ :: l, m+1 => by cases h : l.get? m <;> simp [h, modifyNth, m.succ_ne_zero.symm] | n+1, a :: l, m+1 => (get?_modifyNth f n l m).trans <| by cases h' : l.get? m <;> by_cases h : n = m <;> simp [h, if_pos, if_neg, Option.map, mt Nat.succ.inj, not_false_iff, h'] theorem modifyNthTail_length (f : List α → List α) (H : ∀ l, length (f l) = length l) : ∀ n l, length (modifyNthTail f n l) = length l | 0, _ => H _ | _+1, [] => rfl | _+1, _ :: _ => congrArg (·+1) (modifyNthTail_length _ H _ _) theorem modifyNthTail_add (f : List α → List α) (n) (l₁ l₂ : List α) : modifyNthTail f (l₁.length + n) (l₁ ++ l₂) = l₁ ++ modifyNthTail f n l₂ := by induction l₁ <;> simp [*, Nat.succ_add] theorem exists_of_modifyNthTail (f : List α → List α) {n} {l : List α} (h : n ≤ l.length) : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n ∧ modifyNthTail f n l = l₁ ++ f l₂ := have ⟨_, _, eq, hl⟩ : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n := ⟨_, _, (take_append_drop n l).symm, length_take_of_le h⟩ ⟨_, _, eq, hl, hl ▸ eq ▸ modifyNthTail_add (n := 0) ..⟩ @[simp] theorem modify_get?_length (f : α → α) : ∀ n l, length (modifyNth f n l) = length l := modifyNthTail_length _ fun l => by cases l <;> rfl @[simp] theorem get?_modifyNth_eq (f : α → α) (n) (l : List α) : (modifyNth f n l).get? n = f <$> l.get? n := by simp only [get?_modifyNth, if_pos] @[simp] theorem get?_modifyNth_ne (f : α → α) {m n} (l : List α) (h : m ≠ n) : (modifyNth f m l).get? n = l.get? n := by simp only [get?_modifyNth, if_neg h, id_map'] theorem exists_of_modifyNth (f : α → α) {n} {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ modifyNth f n l = l₁ ++ f a :: l₂ := match exists_of_modifyNthTail _ (Nat.le_of_lt h) with | ⟨_, _::_, eq, hl, H⟩ => ⟨_, _, _, eq, hl, H⟩ | ⟨_, [], eq, hl, _⟩ => nomatch Nat.ne_of_gt h (eq ▸ append_nil _ ▸ hl) theorem modifyNthTail_eq_take_drop (f : List α → List α) (H : f [] = []) : ∀ n l, modifyNthTail f n l = take n l ++ f (drop n l) | 0, _ => rfl | _ + 1, [] => H.symm | n + 1, b :: l => congrArg (cons b) (modifyNthTail_eq_take_drop f H n l) theorem modifyNth_eq_take_drop (f : α → α) : ∀ n l, modifyNth f n l = take n l ++ modifyHead f (drop n l) := modifyNthTail_eq_take_drop _ rfl theorem modifyNth_eq_take_cons_drop (f : α → α) {n l} (h) : modifyNth f n l = take n l ++ f (get l ⟨n, h⟩) :: drop (n + 1) l := by rw [modifyNth_eq_take_drop, drop_eq_get_cons h]; rfl /-! ### set -/ theorem set_eq_modifyNth (a : α) : ∀ n (l : List α), set l n a = modifyNth (fun _ => a) n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => congrArg (cons _) (set_eq_modifyNth _ _ _)
.lake/packages/batteries/Batteries/Data/List/Lemmas.lean
361
363
theorem set_eq_take_cons_drop (a : α) {n l} (h : n < length l) : set l n a = take n l ++ a :: drop (n + 1) l := by
rw [set_eq_modifyNth, modifyNth_eq_take_cons_drop _ h]
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.BilinearForm.TensorProduct import Mathlib.LinearAlgebra.QuadraticForm.Basic /-! # The quadratic form on a tensor product ## Main definitions * `QuadraticForm.tensorDistrib (Q₁ ⊗ₜ Q₂)`: the quadratic form on `M₁ ⊗ M₂` constructed by applying `Q₁` on `M₁` and `Q₂` on `M₂`. This construction is not available in characteristic two. -/ universe uR uA uM₁ uM₂ variable {R : Type uR} {A : Type uA} {M₁ : Type uM₁} {M₂ : Type uM₂} open TensorProduct open LinearMap (BilinForm) namespace QuadraticForm section CommRing variable [CommRing R] [CommRing A] variable [AddCommGroup M₁] [AddCommGroup M₂] variable [Algebra R A] [Module R M₁] [Module A M₁] variable [SMulCommClass R A M₁] [SMulCommClass A R M₁] [IsScalarTower R A M₁] variable [Module R M₂] [Invertible (2 : R)] variable (R A) in /-- The tensor product of two quadratic forms injects into quadratic forms on tensor products. Note this is heterobasic; the quadratic form on the left can take values in a larger ring than the one on the right. -/ -- `noncomputable` is a performance workaround for mathlib4#7103 noncomputable def tensorDistrib : QuadraticForm A M₁ ⊗[R] QuadraticForm R M₂ →ₗ[A] QuadraticForm A (M₁ ⊗[R] M₂) := letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm -- while `letI`s would produce a better term than `let`, they would make this already-slow -- definition even slower. let toQ := BilinForm.toQuadraticFormLinearMap A A (M₁ ⊗[R] M₂) let tmulB := BilinForm.tensorDistrib R A (M₁ := M₁) (M₂ := M₂) let toB := AlgebraTensorModule.map (QuadraticForm.associated : QuadraticForm A M₁ →ₗ[A] BilinForm A M₁) (QuadraticForm.associated : QuadraticForm R M₂ →ₗ[R] BilinForm R M₂) toQ ∘ₗ tmulB ∘ₗ toB -- TODO: make the RHS `MulOpposite.op (Q₂ m₂) • Q₁ m₁` so that this has a nicer defeq for -- `R = A` of `Q₁ m₁ * Q₂ m₂`. @[simp] theorem tensorDistrib_tmul (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) (m₁ : M₁) (m₂ : M₂) : tensorDistrib R A (Q₁ ⊗ₜ Q₂) (m₁ ⊗ₜ m₂) = Q₂ m₂ • Q₁ m₁ := letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm (BilinForm.tensorDistrib_tmul _ _ _ _ _ _).trans <| congr_arg₂ _ (associated_eq_self_apply _ _ _) (associated_eq_self_apply _ _ _) /-- The tensor product of two quadratic forms, a shorthand for dot notation. -/ -- `noncomputable` is a performance workaround for mathlib4#7103 protected noncomputable abbrev tmul (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) : QuadraticForm A (M₁ ⊗[R] M₂) := tensorDistrib R A (Q₁ ⊗ₜ[R] Q₂) theorem associated_tmul [Invertible (2 : A)] (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) : associated (R := A) (Q₁.tmul Q₂) = (associated (R := A) Q₁).tmul (associated (R := R) Q₂) := by rw [QuadraticForm.tmul, tensorDistrib, BilinForm.tmul] dsimp have : Subsingleton (Invertible (2 : A)) := inferInstance convert associated_left_inverse A ((associated_isSymm A Q₁).tmul (associated_isSymm R Q₂)) theorem polarBilin_tmul [Invertible (2 : A)] (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) : polarBilin (Q₁.tmul Q₂) = ⅟(2 : A) • (polarBilin Q₁).tmul (polarBilin Q₂) := by simp_rw [← two_nsmul_associated A, ← two_nsmul_associated R, BilinForm.tmul, tmul_smul, ← smul_tmul', map_nsmul, associated_tmul] rw [smul_comm (_ : A) (_ : ℕ), ← smul_assoc, two_smul _ (_ : A), invOf_two_add_invOf_two, one_smul] variable (A) in /-- The base change of a quadratic form. -/ -- `noncomputable` is a performance workaround for mathlib4#7103 protected noncomputable def baseChange (Q : QuadraticForm R M₂) : QuadraticForm A (A ⊗[R] M₂) := QuadraticForm.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (QuadraticForm.sq (R := A)) Q @[simp] theorem baseChange_tmul (Q : QuadraticForm R M₂) (a : A) (m₂ : M₂) : Q.baseChange A (a ⊗ₜ m₂) = Q m₂ • (a * a) := tensorDistrib_tmul _ _ _ _
Mathlib/LinearAlgebra/QuadraticForm/TensorProduct.lean
95
99
theorem associated_baseChange [Invertible (2 : A)] (Q : QuadraticForm R M₂) : associated (R := A) (Q.baseChange A) = (associated (R := R) Q).baseChange A := by
dsimp only [QuadraticForm.baseChange, LinearMap.baseChange] rw [associated_tmul (QuadraticForm.sq (R := A)) Q, associated_sq] exact rfl
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Data.DFinsupp.Basic #align_import algebra.direct_sum.basic from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # Direct sum This file defines the direct sum of abelian groups, indexed by a discrete type. ## Notation `⨁ i, β i` is the n-ary direct sum `DirectSum`. This notation is in the `DirectSum` locale, accessible after `open DirectSum`. ## References * https://en.wikipedia.org/wiki/Direct_sum -/ open Function universe u v w u₁ variable (ι : Type v) [dec_ι : DecidableEq ι] (β : ι → Type w) /-- `DirectSum ι β` is the direct sum of a family of additive commutative monoids `β i`. Note: `open DirectSum` will enable the notation `⨁ i, β i` for `DirectSum ι β`. -/ def DirectSum [∀ i, AddCommMonoid (β i)] : Type _ := -- Porting note: Failed to synthesize -- Π₀ i, β i deriving AddCommMonoid, Inhabited -- See https://github.com/leanprover-community/mathlib4/issues/5020 Π₀ i, β i #align direct_sum DirectSum -- Porting note (#10754): Added inhabited instance manually instance [∀ i, AddCommMonoid (β i)] : Inhabited (DirectSum ι β) := inferInstanceAs (Inhabited (Π₀ i, β i)) -- Porting note (#10754): Added addCommMonoid instance manually instance [∀ i, AddCommMonoid (β i)] : AddCommMonoid (DirectSum ι β) := inferInstanceAs (AddCommMonoid (Π₀ i, β i)) instance [∀ i, AddCommMonoid (β i)] : DFunLike (DirectSum ι β) _ fun i : ι => β i := inferInstanceAs (DFunLike (Π₀ i, β i) _ _) instance [∀ i, AddCommMonoid (β i)] : CoeFun (DirectSum ι β) fun _ => ∀ i : ι, β i := inferInstanceAs (CoeFun (Π₀ i, β i) fun _ => ∀ i : ι, β i) /-- `⨁ i, f i` is notation for `DirectSum _ f` and equals the direct sum of `fun i ↦ f i`. Taking the direct sum over multiple arguments is possible, e.g. `⨁ (i) (j), f i j`. -/ scoped[DirectSum] notation3 "⨁ "(...)", "r:(scoped f => DirectSum _ f) => r -- Porting note: The below recreates some of the lean3 notation, not fully yet -- section -- open Batteries.ExtendedBinder -- syntax (name := bigdirectsum) "⨁ " extBinders ", " term : term -- macro_rules (kind := bigdirectsum) -- | `(⨁ $_:ident, $y:ident → $z:ident) => `(DirectSum _ (fun $y ↦ $z)) -- | `(⨁ $x:ident, $p) => `(DirectSum _ (fun $x ↦ $p)) -- | `(⨁ $_:ident : $t:ident, $p) => `(DirectSum _ (fun $t ↦ $p)) -- | `(⨁ ($x:ident) ($y:ident), $p) => `(DirectSum _ (fun $x ↦ fun $y ↦ $p)) -- end instance [∀ i, AddCommMonoid (β i)] [∀ i, DecidableEq (β i)] : DecidableEq (DirectSum ι β) := inferInstanceAs <| DecidableEq (Π₀ i, β i) namespace DirectSum variable {ι} section AddCommGroup variable [∀ i, AddCommGroup (β i)] instance : AddCommGroup (DirectSum ι β) := inferInstanceAs (AddCommGroup (Π₀ i, β i)) variable {β} @[simp] theorem sub_apply (g₁ g₂ : ⨁ i, β i) (i : ι) : (g₁ - g₂) i = g₁ i - g₂ i := rfl #align direct_sum.sub_apply DirectSum.sub_apply end AddCommGroup variable [∀ i, AddCommMonoid (β i)] @[simp] theorem zero_apply (i : ι) : (0 : ⨁ i, β i) i = 0 := rfl #align direct_sum.zero_apply DirectSum.zero_apply variable {β} @[simp] theorem add_apply (g₁ g₂ : ⨁ i, β i) (i : ι) : (g₁ + g₂) i = g₁ i + g₂ i := rfl #align direct_sum.add_apply DirectSum.add_apply variable (β) /-- `mk β s x` is the element of `⨁ i, β i` that is zero outside `s` and has coefficient `x i` for `i` in `s`. -/ def mk (s : Finset ι) : (∀ i : (↑s : Set ι), β i.1) →+ ⨁ i, β i where toFun := DFinsupp.mk s map_add' _ _ := DFinsupp.mk_add map_zero' := DFinsupp.mk_zero #align direct_sum.mk DirectSum.mk /-- `of i` is the natural inclusion map from `β i` to `⨁ i, β i`. -/ def of (i : ι) : β i →+ ⨁ i, β i := DFinsupp.singleAddHom β i #align direct_sum.of DirectSum.of @[simp] theorem of_eq_same (i : ι) (x : β i) : (of _ i x) i = x := DFinsupp.single_eq_same #align direct_sum.of_eq_same DirectSum.of_eq_same theorem of_eq_of_ne (i j : ι) (x : β i) (h : i ≠ j) : (of _ i x) j = 0 := DFinsupp.single_eq_of_ne h #align direct_sum.of_eq_of_ne DirectSum.of_eq_of_ne lemma of_apply {i : ι} (j : ι) (x : β i) : of β i x j = if h : i = j then Eq.recOn h x else 0 := DFinsupp.single_apply @[simp] theorem support_zero [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] : (0 : ⨁ i, β i).support = ∅ := DFinsupp.support_zero #align direct_sum.support_zero DirectSum.support_zero @[simp] theorem support_of [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] (i : ι) (x : β i) (h : x ≠ 0) : (of _ i x).support = {i} := DFinsupp.support_single_ne_zero h #align direct_sum.support_of DirectSum.support_of theorem support_of_subset [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] {i : ι} {b : β i} : (of _ i b).support ⊆ {i} := DFinsupp.support_single_subset #align direct_sum.support_of_subset DirectSum.support_of_subset theorem sum_support_of [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] (x : ⨁ i, β i) : (∑ i ∈ x.support, of β i (x i)) = x := DFinsupp.sum_single #align direct_sum.sum_support_of DirectSum.sum_support_of
Mathlib/Algebra/DirectSum/Basic.lean
155
159
theorem sum_univ_of [Fintype ι] (x : ⨁ i, β i) : ∑ i ∈ Finset.univ, of β i (x i) = x := by
apply DFinsupp.ext (fun i ↦ ?_) rw [DFinsupp.finset_sum_apply] simp [of_apply]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Polynomial.Module.AEval #align_import data.polynomial.module from "leanprover-community/mathlib"@"63417e01fbc711beaf25fa73b6edb395c0cfddd0" /-! # Polynomial module In this file, we define the polynomial module for an `R`-module `M`, i.e. the `R[X]`-module `M[X]`. This is defined as a type alias `PolynomialModule R M := ℕ →₀ M`, since there might be different module structures on `ℕ →₀ M` of interest. See the docstring of `PolynomialModule` for details. -/ universe u v open Polynomial BigOperators /-- The `R[X]`-module `M[X]` for an `R`-module `M`. This is isomorphic (as an `R`-module) to `M[X]` when `M` is a ring. We require all the module instances `Module S (PolynomialModule R M)` to factor through `R` except `Module R[X] (PolynomialModule R M)`. In this constraint, we have the following instances for example : - `R` acts on `PolynomialModule R R[X]` - `R[X]` acts on `PolynomialModule R R[X]` as `R[Y]` acting on `R[X][Y]` - `R` acts on `PolynomialModule R[X] R[X]` - `R[X]` acts on `PolynomialModule R[X] R[X]` as `R[X]` acting on `R[X][Y]` - `R[X][X]` acts on `PolynomialModule R[X] R[X]` as `R[X][Y]` acting on itself This is also the reason why `R` is included in the alias, or else there will be two different instances of `Module R[X] (PolynomialModule R[X])`. See https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2315065.20polynomial.20modules for the full discussion. -/ @[nolint unusedArguments] def PolynomialModule (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] := ℕ →₀ M #align polynomial_module PolynomialModule variable (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R) -- Porting note: stated instead of deriving noncomputable instance : Inhabited (PolynomialModule R M) := Finsupp.instInhabited noncomputable instance : AddCommGroup (PolynomialModule R M) := Finsupp.instAddCommGroup variable {M} variable {S : Type*} [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] namespace PolynomialModule /-- This is required to have the `IsScalarTower S R M` instance to avoid diamonds. -/ @[nolint unusedArguments] noncomputable instance : Module S (PolynomialModule R M) := Finsupp.module ℕ M instance instFunLike : FunLike (PolynomialModule R M) ℕ M := Finsupp.instFunLike instance : CoeFun (PolynomialModule R M) fun _ => ℕ → M := Finsupp.instCoeFun theorem zero_apply (i : ℕ) : (0 : PolynomialModule R M) i = 0 := Finsupp.zero_apply theorem add_apply (g₁ g₂ : PolynomialModule R M) (a : ℕ) : (g₁ + g₂) a = g₁ a + g₂ a := Finsupp.add_apply g₁ g₂ a /-- The monomial `m * x ^ i`. This is defeq to `Finsupp.singleAddHom`, and is redefined here so that it has the desired type signature. -/ noncomputable def single (i : ℕ) : M →+ PolynomialModule R M := Finsupp.singleAddHom i #align polynomial_module.single PolynomialModule.single theorem single_apply (i : ℕ) (m : M) (n : ℕ) : single R i m n = ite (i = n) m 0 := Finsupp.single_apply #align polynomial_module.single_apply PolynomialModule.single_apply /-- `PolynomialModule.single` as a linear map. -/ noncomputable def lsingle (i : ℕ) : M →ₗ[R] PolynomialModule R M := Finsupp.lsingle i #align polynomial_module.lsingle PolynomialModule.lsingle theorem lsingle_apply (i : ℕ) (m : M) (n : ℕ) : lsingle R i m n = ite (i = n) m 0 := Finsupp.single_apply #align polynomial_module.lsingle_apply PolynomialModule.lsingle_apply theorem single_smul (i : ℕ) (r : R) (m : M) : single R i (r • m) = r • single R i m := (lsingle R i).map_smul r m #align polynomial_module.single_smul PolynomialModule.single_smul variable {R} theorem induction_linear {P : PolynomialModule R M → Prop} (f : PolynomialModule R M) (h0 : P 0) (hadd : ∀ f g, P f → P g → P (f + g)) (hsingle : ∀ a b, P (single R a b)) : P f := Finsupp.induction_linear f h0 hadd hsingle #align polynomial_module.induction_linear PolynomialModule.induction_linear noncomputable instance polynomialModule : Module R[X] (PolynomialModule R M) := inferInstanceAs (Module R[X] (Module.AEval' (Finsupp.lmapDomain M R Nat.succ))) #align polynomial_module.polynomial_module PolynomialModule.polynomialModule lemma smul_def (f : R[X]) (m : PolynomialModule R M) : f • m = aeval (Finsupp.lmapDomain M R Nat.succ) f m := by rfl instance (M : Type u) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower S R M] : IsScalarTower S R (PolynomialModule R M) := Finsupp.isScalarTower _ _ instance isScalarTower' (M : Type u) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower S R M] : IsScalarTower S R[X] (PolynomialModule R M) := by haveI : IsScalarTower R R[X] (PolynomialModule R M) := inferInstanceAs <| IsScalarTower R R[X] <| Module.AEval' <| Finsupp.lmapDomain M R Nat.succ constructor intro x y z rw [← @IsScalarTower.algebraMap_smul S R, ← @IsScalarTower.algebraMap_smul S R, smul_assoc] #align polynomial_module.is_scalar_tower' PolynomialModule.isScalarTower' @[simp]
Mathlib/Algebra/Polynomial/Module/Basic.lean
123
135
theorem monomial_smul_single (i : ℕ) (r : R) (j : ℕ) (m : M) : monomial i r • single R j m = single R (i + j) (r • m) := by
simp only [LinearMap.mul_apply, Polynomial.aeval_monomial, LinearMap.pow_apply, Module.algebraMap_end_apply, smul_def] induction i generalizing r j m with | zero => rw [Function.iterate_zero, zero_add] exact Finsupp.smul_single r j m | succ n hn => rw [Function.iterate_succ, Function.comp_apply, add_assoc, ← hn] congr 2 rw [Nat.one_add] exact Finsupp.mapDomain_single
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn, Mario Carneiro, Martin Dvorak -/ import Mathlib.Data.List.Basic #align_import data.list.join from "leanprover-community/mathlib"@"18a5306c091183ac90884daa9373fa3b178e8607" /-! # Join of a list of lists This file proves basic properties of `List.join`, which concatenates a list of lists. It is defined in `Init.Data.List.Basic`. -/ -- Make sure we don't import algebra assert_not_exists Monoid variable {α β : Type*} namespace List attribute [simp] join -- Porting note (#10618): simp can prove this -- @[simp] theorem join_singleton (l : List α) : [l].join = l := by rw [join, join, append_nil] #align list.join_singleton List.join_singleton @[simp] theorem join_eq_nil : ∀ {L : List (List α)}, join L = [] ↔ ∀ l ∈ L, l = [] | [] => iff_of_true rfl (forall_mem_nil _) | l :: L => by simp only [join, append_eq_nil, join_eq_nil, forall_mem_cons] #align list.join_eq_nil List.join_eq_nil @[simp] theorem join_append (L₁ L₂ : List (List α)) : join (L₁ ++ L₂) = join L₁ ++ join L₂ := by induction L₁ · rfl · simp [*] #align list.join_append List.join_append theorem join_concat (L : List (List α)) (l : List α) : join (L.concat l) = join L ++ l := by simp #align list.join_concat List.join_concat @[simp] theorem join_filter_not_isEmpty : ∀ {L : List (List α)}, join (L.filter fun l => !l.isEmpty) = L.join | [] => rfl | [] :: L => by simp [join_filter_not_isEmpty (L := L), isEmpty_iff_eq_nil] | (a :: l) :: L => by simp [join_filter_not_isEmpty (L := L)] #align list.join_filter_empty_eq_ff List.join_filter_not_isEmpty @[deprecated (since := "2024-02-25")] alias join_filter_isEmpty_eq_false := join_filter_not_isEmpty @[simp] theorem join_filter_ne_nil [DecidablePred fun l : List α => l ≠ []] {L : List (List α)} : join (L.filter fun l => l ≠ []) = L.join := by simp [join_filter_not_isEmpty, ← isEmpty_iff_eq_nil] #align list.join_filter_ne_nil List.join_filter_ne_nil theorem join_join (l : List (List (List α))) : l.join.join = (l.map join).join := by induction l <;> simp [*] #align list.join_join List.join_join /-- See `List.length_join` for the corresponding statement using `List.sum`. -/ lemma length_join' (L : List (List α)) : length (join L) = Nat.sum (map length L) := by induction L <;> [rfl; simp only [*, join, map, Nat.sum_cons, length_append]] /-- See `List.countP_join` for the corresponding statement using `List.sum`. -/ lemma countP_join' (p : α → Bool) : ∀ L : List (List α), countP p L.join = Nat.sum (L.map (countP p)) | [] => rfl | a :: l => by rw [join, countP_append, map_cons, Nat.sum_cons, countP_join' _ l] /-- See `List.count_join` for the corresponding statement using `List.sum`. -/ lemma count_join' [BEq α] (L : List (List α)) (a : α) : L.join.count a = Nat.sum (L.map (count a)) := countP_join' _ _ /-- See `List.length_bind` for the corresponding statement using `List.sum`. -/ lemma length_bind' (l : List α) (f : α → List β) : length (l.bind f) = Nat.sum (map (length ∘ f) l) := by rw [List.bind, length_join', map_map] /-- See `List.countP_bind` for the corresponding statement using `List.sum`. -/ lemma countP_bind' (p : β → Bool) (l : List α) (f : α → List β) : countP p (l.bind f) = Nat.sum (map (countP p ∘ f) l) := by rw [List.bind, countP_join', map_map] /-- See `List.count_bind` for the corresponding statement using `List.sum`. -/ lemma count_bind' [BEq β] (l : List α) (f : α → List β) (x : β) : count x (l.bind f) = Nat.sum (map (count x ∘ f) l) := countP_bind' _ _ _ @[simp] theorem bind_eq_nil {l : List α} {f : α → List β} : List.bind l f = [] ↔ ∀ x ∈ l, f x = [] := join_eq_nil.trans <| by simp only [mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] #align list.bind_eq_nil List.bind_eq_nil /-- In a join, taking the first elements up to an index which is the sum of the lengths of the first `i` sublists, is the same as taking the join of the first `i` sublists. See `List.take_sum_join` for the corresponding statement using `List.sum`. -/ theorem take_sum_join' (L : List (List α)) (i : ℕ) : L.join.take (Nat.sum ((L.map length).take i)) = (L.take i).join := by induction L generalizing i · simp · cases i <;> simp [take_append, *] /-- In a join, dropping all the elements up to an index which is the sum of the lengths of the first `i` sublists, is the same as taking the join after dropping the first `i` sublists. See `List.drop_sum_join` for the corresponding statement using `List.sum`. -/ theorem drop_sum_join' (L : List (List α)) (i : ℕ) : L.join.drop (Nat.sum ((L.map length).take i)) = (L.drop i).join := by induction L generalizing i · simp · cases i <;> simp [drop_append, *] /-- Taking only the first `i+1` elements in a list, and then dropping the first `i` ones, one is left with a list of length `1` made of the `i`-th element of the original list. -/ theorem drop_take_succ_eq_cons_get (L : List α) (i : Fin L.length) : (L.take (i + 1)).drop i = [get L i] := by induction' L with head tail ih · exact (Nat.not_succ_le_zero i i.isLt).elim rcases i with ⟨_ | i, hi⟩ · simp · simpa using ih ⟨i, Nat.lt_of_succ_lt_succ hi⟩ set_option linter.deprecated false in /-- Taking only the first `i+1` elements in a list, and then dropping the first `i` ones, one is left with a list of length `1` made of the `i`-th element of the original list. -/ @[deprecated drop_take_succ_eq_cons_get (since := "2023-01-10")] theorem drop_take_succ_eq_cons_nthLe (L : List α) {i : ℕ} (hi : i < L.length) : (L.take (i + 1)).drop i = [nthLe L i hi] := by induction' L with head tail generalizing i · simp only [length] at hi exact (Nat.not_succ_le_zero i hi).elim cases' i with i hi · simp rfl have : i < tail.length := by simpa using hi simp [*] rfl #align list.drop_take_succ_eq_cons_nth_le List.drop_take_succ_eq_cons_nthLe /-- In a join of sublists, taking the slice between the indices `A` and `B - 1` gives back the original sublist of index `i` if `A` is the sum of the lengths of sublists of index `< i`, and `B` is the sum of the lengths of sublists of index `≤ i`. See `List.drop_take_succ_join_eq_get` for the corresponding statement using `List.sum`. -/ theorem drop_take_succ_join_eq_get' (L : List (List α)) (i : Fin L.length) : (L.join.take (Nat.sum ((L.map length).take (i + 1)))).drop (Nat.sum ((L.map length).take i)) = get L i := by have : (L.map length).take i = ((L.take (i + 1)).map length).take i := by simp [map_take, take_take, Nat.min_eq_left] simp only [this, length_map, take_sum_join', drop_sum_join', drop_take_succ_eq_cons_get, join, append_nil] #noalign list.drop_take_succ_join_eq_nth_le #noalign list.sum_take_map_length_lt1 #noalign list.sum_take_map_length_lt2 #noalign list.nth_le_join /-- Two lists of sublists are equal iff their joins coincide, as well as the lengths of the sublists. -/ theorem eq_iff_join_eq (L L' : List (List α)) : L = L' ↔ L.join = L'.join ∧ map length L = map length L' := by refine ⟨fun H => by simp [H], ?_⟩ rintro ⟨join_eq, length_eq⟩ apply ext_get · have : length (map length L) = length (map length L') := by rw [length_eq] simpa using this · intro n h₁ h₂ rw [← drop_take_succ_join_eq_get', ← drop_take_succ_join_eq_get', join_eq, length_eq] #align list.eq_iff_join_eq List.eq_iff_join_eq theorem join_drop_length_sub_one {L : List (List α)} (h : L ≠ []) : (L.drop (L.length - 1)).join = L.getLast h := by induction L using List.reverseRecOn · cases h rfl · simp #align list.join_drop_length_sub_one List.join_drop_length_sub_one /-- We can rebracket `x ++ (l₁ ++ x) ++ (l₂ ++ x) ++ ... ++ (lₙ ++ x)` to `(x ++ l₁) ++ (x ++ l₂) ++ ... ++ (x ++ lₙ) ++ x` where `L = [l₁, l₂, ..., lₙ]`. -/
Mathlib/Data/List/Join.lean
188
192
theorem append_join_map_append (L : List (List α)) (x : List α) : x ++ (L.map (· ++ x)).join = (L.map (x ++ ·)).join ++ x := by
induction' L with _ _ ih · rw [map_nil, join, append_nil, map_nil, join, nil_append] · rw [map_cons, join, map_cons, join, append_assoc, ih, append_assoc, append_assoc]
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.PropInstances #align_import order.heyting.basic from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # Heyting algebras This file defines Heyting, co-Heyting and bi-Heyting algebras. A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that `a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`. Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬` such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`. Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras. From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean algebras model classical logic. Heyting algebras are the order theoretic equivalent of cartesian-closed categories. ## Main declarations * `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation). * `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement). * `HeytingAlgebra`: Heyting algebra. * `CoheytingAlgebra`: Co-Heyting algebra. * `BiheytingAlgebra`: bi-Heyting algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] ## Tags Heyting, Brouwer, algebra, implication, negation, intuitionistic -/ open Function OrderDual universe u variable {ι α β : Type*} /-! ### Notation -/ section variable (α β) instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) := ⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩ instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) := ⟨fun a => (¬a.1, ¬a.2)⟩ instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) := ⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩ instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) := ⟨fun a => (a.1ᶜ, a.2ᶜ)⟩ end @[simp] theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 := rfl #align fst_himp fst_himp @[simp] theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 := rfl #align snd_himp snd_himp @[simp] theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 := rfl #align fst_hnot fst_hnot @[simp] theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 := rfl #align snd_hnot snd_hnot @[simp] theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 := rfl #align fst_sdiff fst_sdiff @[simp] theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 := rfl #align snd_sdiff snd_sdiff @[simp] theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ := rfl #align fst_compl fst_compl @[simp] theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ := rfl #align snd_compl snd_compl namespace Pi variable {π : ι → Type*} instance [∀ i, HImp (π i)] : HImp (∀ i, π i) := ⟨fun a b i => a i ⇨ b i⟩ instance [∀ i, HNot (π i)] : HNot (∀ i, π i) := ⟨fun a i => ¬a i⟩ theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i := rfl #align pi.himp_def Pi.himp_def theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i := rfl #align pi.hnot_def Pi.hnot_def @[simp] theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i := rfl #align pi.himp_apply Pi.himp_apply @[simp] theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i := rfl #align pi.hnot_apply Pi.hnot_apply end Pi /-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called Heyting implication such that `a ⇨` is right adjoint to `a ⊓`. This generalizes `HeytingAlgebra` by not requiring a bottom element. -/ class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where /-- `a ⇨` is right adjoint to `a ⊓` -/ le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c #align generalized_heyting_algebra GeneralizedHeytingAlgebra #align generalized_heyting_algebra.to_order_top GeneralizedHeytingAlgebra.toOrderTop /-- A generalized co-Heyting algebra is a lattice with an additional binary difference operation `\` such that `\ a` is right adjoint to `⊔ a`. This generalizes `CoheytingAlgebra` by not requiring a top element. -/ class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where /-- `\ a` is right adjoint to `⊔ a` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c #align generalized_coheyting_algebra GeneralizedCoheytingAlgebra #align generalized_coheyting_algebra.to_order_bot GeneralizedCoheytingAlgebra.toOrderBot /-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting implication such that `a ⇨` is right adjoint to `a ⊓`. -/ class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where /-- `a ⇨` is right adjoint to `a ⊓` -/ himp_bot (a : α) : a ⇨ ⊥ = aᶜ #align heyting_algebra HeytingAlgebra /-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\` such that `\ a` is right adjoint to `⊔ a`. -/ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a #align coheyting_algebra CoheytingAlgebra /-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/ class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where /-- `\ a` is right adjoint to `⊔ a` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a #align biheyting_algebra BiheytingAlgebra -- See note [lower instance priority] attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot -- See note [lower instance priority] instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α := { bot_le := ‹HeytingAlgebra α›.bot_le } --#align heyting_algebra.to_bounded_order HeytingAlgebra.toBoundedOrder -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α := { ‹CoheytingAlgebra α› with } #align coheyting_algebra.to_bounded_order CoheytingAlgebra.toBoundedOrder -- See note [lower instance priority] instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] : CoheytingAlgebra α := { ‹BiheytingAlgebra α› with } #align biheyting_algebra.to_coheyting_algebra BiheytingAlgebra.toCoheytingAlgebra -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α) (le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with himp, compl := fun a => himp a ⊥, le_himp_iff, himp_bot := fun a => rfl } #align heyting_algebra.of_himp HeytingAlgebra.ofHImp -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/ abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α) (le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where himp := (compl · ⊔ ·) compl := compl le_himp_iff := le_himp_iff himp_bot _ := sup_bot_eq _ #align heyting_algebra.of_compl HeytingAlgebra.ofCompl -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/ abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α) (sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with sdiff, hnot := fun a => sdiff ⊤ a, sdiff_le_iff, top_sdiff := fun a => rfl } #align coheyting_algebra.of_sdiff CoheytingAlgebra.ofSDiff -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/ abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α) (sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where sdiff a b := a ⊓ hnot b hnot := hnot sdiff_le_iff := sdiff_le_iff top_sdiff _ := top_inf_eq _ #align coheyting_algebra.of_hnot CoheytingAlgebra.ofHNot /-! In this section, we'll give interpretations of these results in the Heyting algebra model of intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and", `⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are the same in this logic. See also `Prop.heytingAlgebra`. -/ section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] {a b c d : α} /-- `p → q → r ↔ p ∧ q → r` -/ @[simp] theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c := GeneralizedHeytingAlgebra.le_himp_iff _ _ _ #align le_himp_iff le_himp_iff /-- `p → q → r ↔ q ∧ p → r` -/ theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm] #align le_himp_iff' le_himp_iff' /-- `p → q → r ↔ q → p → r` -/ theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff'] #align le_himp_comm le_himp_comm /-- `p → q → p` -/ theorem le_himp : a ≤ b ⇨ a := le_himp_iff.2 inf_le_left #align le_himp le_himp /-- `p → p → q ↔ p → q` -/ theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem] #align le_himp_iff_left le_himp_iff_left /-- `p → p` -/ @[simp] theorem himp_self : a ⇨ a = ⊤ := top_le_iff.1 <| le_himp_iff.2 inf_le_right #align himp_self himp_self /-- `(p → q) ∧ p → q` -/ theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b := le_himp_iff.1 le_rfl #align himp_inf_le himp_inf_le /-- `p ∧ (p → q) → q` -/ theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff] #align inf_himp_le inf_himp_le /-- `p ∧ (p → q) ↔ p ∧ q` -/ @[simp] theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b := le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp #align inf_himp inf_himp /-- `(p → q) ∧ p ↔ q ∧ p` -/ @[simp] theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm] #align himp_inf_self himp_inf_self /-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic: an implication holds iff the conclusion follows from the hypothesis. -/ @[simp] theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq] #align himp_eq_top_iff himp_eq_top_iff /-- `p → true`, `true → p ↔ p` -/ @[simp] theorem himp_top : a ⇨ ⊤ = ⊤ := himp_eq_top_iff.2 le_top #align himp_top himp_top @[simp] theorem top_himp : ⊤ ⇨ a = a := eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq] #align top_himp top_himp /-- `p → q → r ↔ p ∧ q → r` -/ theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc] #align himp_himp himp_himp /-- `(q → r) → (p → q) → q → r` -/ theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc] exact inf_le_left #align himp_le_himp_himp_himp himp_le_himp_himp_himp @[simp] theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by simpa using @himp_le_himp_himp_himp /-- `p → q → r ↔ q → p → r` -/ theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm] #align himp_left_comm himp_left_comm @[simp] theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem] #align himp_idem himp_idem theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff] #align himp_inf_distrib himp_inf_distrib theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) := eq_of_forall_le_iff fun d => by rw [le_inf_iff, le_himp_comm, sup_le_iff] simp_rw [le_himp_comm] #align sup_himp_distrib sup_himp_distrib theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b := le_himp_iff.2 <| himp_inf_le.trans h #align himp_le_himp_left himp_le_himp_left theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c := le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le #align himp_le_himp_right himp_le_himp_right theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d := (himp_le_himp_right hab).trans <| himp_le_himp_left hcd #align himp_le_himp himp_le_himp @[simp]
Mathlib/Order/Heyting/Basic.lean
366
367
theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by
rw [sup_himp_distrib, himp_self, top_inf_eq]
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.FixedPoint #align_import set_theory.ordinal.principal from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7" /-! ### Principal ordinals We define principal or indecomposable ordinals, and we prove the standard properties about them. ### Main definitions and results * `Principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and any other typically excluded edge cases for simplicity. * `unbounded_principal`: Principal ordinals are unbounded. * `principal_add_iff_zero_or_omega_opow`: The main characterization theorem for additive principal ordinals. * `principal_mul_iff_le_two_or_omega_opow_opow`: The main characterization theorem for multiplicative principal ordinals. ### Todo * Prove that exponential principal ordinals are 0, 1, 2, ω, or epsilon numbers, i.e. fixed points of `fun x ↦ ω ^ x`. -/ universe u v w noncomputable section open Order namespace Ordinal -- Porting note: commented out, doesn't seem necessary --local infixr:0 "^" => @pow Ordinal Ordinal Ordinal.hasPow /-! ### Principal ordinals -/ /-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of ordinals less than it is closed under that operation. In standard mathematical usage, this term is almost exclusively used for additive and multiplicative principal ordinals. For simplicity, we break usual convention and regard 0 as principal. -/ def Principal (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Prop := ∀ ⦃a b⦄, a < o → b < o → op a b < o #align ordinal.principal Ordinal.Principal theorem principal_iff_principal_swap {op : Ordinal → Ordinal → Ordinal} {o : Ordinal} : Principal op o ↔ Principal (Function.swap op) o := by constructor <;> exact fun h a b ha hb => h hb ha #align ordinal.principal_iff_principal_swap Ordinal.principal_iff_principal_swap theorem principal_zero {op : Ordinal → Ordinal → Ordinal} : Principal op 0 := fun a _ h => (Ordinal.not_lt_zero a h).elim #align ordinal.principal_zero Ordinal.principal_zero @[simp] theorem principal_one_iff {op : Ordinal → Ordinal → Ordinal} : Principal op 1 ↔ op 0 0 = 0 := by refine ⟨fun h => ?_, fun h a b ha hb => ?_⟩ · rw [← lt_one_iff_zero] exact h zero_lt_one zero_lt_one · rwa [lt_one_iff_zero, ha, hb] at * #align ordinal.principal_one_iff Ordinal.principal_one_iff theorem Principal.iterate_lt {op : Ordinal → Ordinal → Ordinal} {a o : Ordinal} (hao : a < o) (ho : Principal op o) (n : ℕ) : (op a)^[n] a < o := by induction' n with n hn · rwa [Function.iterate_zero] · rw [Function.iterate_succ'] exact ho hao hn #align ordinal.principal.iterate_lt Ordinal.Principal.iterate_lt theorem op_eq_self_of_principal {op : Ordinal → Ordinal → Ordinal} {a o : Ordinal.{u}} (hao : a < o) (H : IsNormal (op a)) (ho : Principal op o) (ho' : IsLimit o) : op a o = o := by refine le_antisymm ?_ (H.self_le _) rw [← IsNormal.bsup_eq.{u, u} H ho', bsup_le_iff] exact fun b hbo => (ho hao hbo).le #align ordinal.op_eq_self_of_principal Ordinal.op_eq_self_of_principal theorem nfp_le_of_principal {op : Ordinal → Ordinal → Ordinal} {a o : Ordinal} (hao : a < o) (ho : Principal op o) : nfp (op a) a ≤ o := nfp_le fun n => (ho.iterate_lt hao n).le #align ordinal.nfp_le_of_principal Ordinal.nfp_le_of_principal /-! ### Principal ordinals are unbounded -/ #adaptation_note /-- 2024-04-23 After https://github.com/leanprover/lean4/pull/3965, we need to write `lt_blsub₂.{u}` twice below, where previously the universe annotation was not necessary. This appears to be correct behaviour, as `lt_blsub₂.{0}` also works. -/ theorem principal_nfp_blsub₂ (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Principal op (nfp (fun o' => blsub₂.{u, u, u} o' o' (@fun a _ b _ => op a b)) o) := fun a b ha hb => by rw [lt_nfp] at * cases' ha with m hm cases' hb with n hn cases' le_total ((fun o' => blsub₂.{u, u, u} o' o' (@fun a _ b _ => op a b))^[m] o) ((fun o' => blsub₂.{u, u, u} o' o' (@fun a _ b _ => op a b))^[n] o) with h h · use n + 1 rw [Function.iterate_succ'] exact lt_blsub₂.{u} (@fun a _ b _ => op a b) (hm.trans_le h) hn · use m + 1 rw [Function.iterate_succ'] exact lt_blsub₂.{u} (@fun a _ b _ => op a b) hm (hn.trans_le h) #align ordinal.principal_nfp_blsub₂ Ordinal.principal_nfp_blsub₂ theorem unbounded_principal (op : Ordinal → Ordinal → Ordinal) : Set.Unbounded (· < ·) { o | Principal op o } := fun o => ⟨_, principal_nfp_blsub₂ op o, (le_nfp _ o).not_lt⟩ #align ordinal.unbounded_principal Ordinal.unbounded_principal /-! #### Additive principal ordinals -/ theorem principal_add_one : Principal (· + ·) 1 := principal_one_iff.2 <| zero_add 0 #align ordinal.principal_add_one Ordinal.principal_add_one theorem principal_add_of_le_one {o : Ordinal} (ho : o ≤ 1) : Principal (· + ·) o := by rcases le_one_iff.1 ho with (rfl | rfl) · exact principal_zero · exact principal_add_one #align ordinal.principal_add_of_le_one Ordinal.principal_add_of_le_one theorem principal_add_isLimit {o : Ordinal} (ho₁ : 1 < o) (ho : Principal (· + ·) o) : o.IsLimit := by refine ⟨fun ho₀ => ?_, fun a hao => ?_⟩ · rw [ho₀] at ho₁ exact not_lt_of_gt zero_lt_one ho₁ · rcases eq_or_ne a 0 with ha | ha · rw [ha, succ_zero] exact ho₁ · refine lt_of_le_of_lt ?_ (ho hao hao) rwa [← add_one_eq_succ, add_le_add_iff_left, one_le_iff_ne_zero] #align ordinal.principal_add_is_limit Ordinal.principal_add_isLimit
Mathlib/SetTheory/Ordinal/Principal.lean
143
153
theorem principal_add_iff_add_left_eq_self {o : Ordinal} : Principal (· + ·) o ↔ ∀ a < o, a + o = o := by
refine ⟨fun ho a hao => ?_, fun h a b hao hbo => ?_⟩ · cases' lt_or_le 1 o with ho₁ ho₁ · exact op_eq_self_of_principal hao (add_isNormal a) ho (principal_add_isLimit ho₁ ho) · rcases le_one_iff.1 ho₁ with (rfl | rfl) · exact (Ordinal.not_lt_zero a hao).elim · rw [lt_one_iff_zero] at hao rw [hao, zero_add] · rw [← h a hao] exact (add_isNormal a).strictMono hbo
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import Mathlib.Analysis.Analytic.IsolatedZeros import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.Analysis.Complex.AbsMax #align_import analysis.complex.open_mapping from "leanprover-community/mathlib"@"f9dd3204df14a0749cd456fac1e6849dfe7d2b88" /-! # The open mapping theorem for holomorphic functions This file proves the open mapping theorem for holomorphic functions, namely that an analytic function on a preconnected set of the complex plane is either constant or open. The main step is to show a local version of the theorem that states that if `f` is analytic at a point `z₀`, then either it is constant in a neighborhood of `z₀` or it maps any neighborhood of `z₀` to a neighborhood of its image `f z₀`. The results extend in higher dimension to `g : E → ℂ`. The proof of the local version on `ℂ` goes through two main steps: first, assuming that the function is not constant around `z₀`, use the isolated zero principle to show that `‖f z‖` is bounded below on a small `sphere z₀ r` around `z₀`, and then use the maximum principle applied to the auxiliary function `(fun z ↦ ‖f z - v‖)` to show that any `v` close enough to `f z₀` is in `f '' ball z₀ r`. That second step is implemented in `DiffContOnCl.ball_subset_image_closedBall`. ## Main results * `AnalyticAt.eventually_constant_or_nhds_le_map_nhds` is the local version of the open mapping theorem around a point; * `AnalyticOn.is_constant_or_isOpen` is the open mapping theorem on a connected open set. -/ open Set Filter Metric Complex open scoped Topology variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {U : Set E} {f : ℂ → ℂ} {g : E → ℂ} {z₀ w : ℂ} {ε r m : ℝ} /-- If the modulus of a holomorphic function `f` is bounded below by `ε` on a circle, then its range contains a disk of radius `ε / 2`. -/ theorem DiffContOnCl.ball_subset_image_closedBall (h : DiffContOnCl ℂ f (ball z₀ r)) (hr : 0 < r) (hf : ∀ z ∈ sphere z₀ r, ε ≤ ‖f z - f z₀‖) (hz₀ : ∃ᶠ z in 𝓝 z₀, f z ≠ f z₀) : ball (f z₀) (ε / 2) ⊆ f '' closedBall z₀ r := by /- This is a direct application of the maximum principle. Pick `v` close to `f z₀`, and look at the function `fun z ↦ ‖f z - v‖`: it is bounded below on the circle, and takes a small value at `z₀` so it is not constant on the disk, which implies that its infimum is equal to `0` and hence that `v` is in the range of `f`. -/ rintro v hv have h1 : DiffContOnCl ℂ (fun z => f z - v) (ball z₀ r) := h.sub_const v have h2 : ContinuousOn (fun z => ‖f z - v‖) (closedBall z₀ r) := continuous_norm.comp_continuousOn (closure_ball z₀ hr.ne.symm ▸ h1.continuousOn) have h3 : AnalyticOn ℂ f (ball z₀ r) := h.differentiableOn.analyticOn isOpen_ball have h4 : ∀ z ∈ sphere z₀ r, ε / 2 ≤ ‖f z - v‖ := fun z hz => by linarith [hf z hz, show ‖v - f z₀‖ < ε / 2 from mem_ball.mp hv, norm_sub_sub_norm_sub_le_norm_sub (f z) v (f z₀)] have h5 : ‖f z₀ - v‖ < ε / 2 := by simpa [← dist_eq_norm, dist_comm] using mem_ball.mp hv obtain ⟨z, hz1, hz2⟩ : ∃ z ∈ ball z₀ r, IsLocalMin (fun z => ‖f z - v‖) z := exists_isLocalMin_mem_ball h2 (mem_closedBall_self hr.le) fun z hz => h5.trans_le (h4 z hz) refine ⟨z, ball_subset_closedBall hz1, sub_eq_zero.mp ?_⟩ have h6 := h1.differentiableOn.eventually_differentiableAt (isOpen_ball.mem_nhds hz1) refine (eventually_eq_or_eq_zero_of_isLocalMin_norm h6 hz2).resolve_left fun key => ?_ have h7 : ∀ᶠ w in 𝓝 z, f w = f z := by filter_upwards [key] with h; field_simp replace h7 : ∃ᶠ w in 𝓝[≠] z, f w = f z := (h7.filter_mono nhdsWithin_le_nhds).frequently have h8 : IsPreconnected (ball z₀ r) := (convex_ball z₀ r).isPreconnected have h9 := h3.eqOn_of_preconnected_of_frequently_eq analyticOn_const h8 hz1 h7 have h10 : f z = f z₀ := (h9 (mem_ball_self hr)).symm exact not_eventually.mpr hz₀ (mem_of_superset (ball_mem_nhds z₀ hr) (h10 ▸ h9)) #align diff_cont_on_cl.ball_subset_image_closed_ball DiffContOnCl.ball_subset_image_closedBall /-- A function `f : ℂ → ℂ` which is analytic at a point `z₀` is either constant in a neighborhood of `z₀`, or behaves locally like an open function (in the sense that the image of every neighborhood of `z₀` is a neighborhood of `f z₀`, as in `isOpenMap_iff_nhds_le`). For a function `f : E → ℂ` the same result holds, see `AnalyticAt.eventually_constant_or_nhds_le_map_nhds`. -/
Mathlib/Analysis/Complex/OpenMapping.lean
77
106
theorem AnalyticAt.eventually_constant_or_nhds_le_map_nhds_aux (hf : AnalyticAt ℂ f z₀) : (∀ᶠ z in 𝓝 z₀, f z = f z₀) ∨ 𝓝 (f z₀) ≤ map f (𝓝 z₀) := by
/- The function `f` is analytic in a neighborhood of `z₀`; by the isolated zeros principle, if `f` is not constant in a neighborhood of `z₀`, then it is nonzero, and therefore bounded below, on every small enough circle around `z₀` and then `DiffContOnCl.ball_subset_image_closedBall` provides an explicit ball centered at `f z₀` contained in the range of `f`. -/ refine or_iff_not_imp_left.mpr fun h => ?_ refine (nhds_basis_ball.le_basis_iff (nhds_basis_closedBall.map f)).mpr fun R hR => ?_ have h1 := (hf.eventually_eq_or_eventually_ne analyticAt_const).resolve_left h have h2 : ∀ᶠ z in 𝓝 z₀, AnalyticAt ℂ f z := (isOpen_analyticAt ℂ f).eventually_mem hf obtain ⟨ρ, hρ, h3, h4⟩ : ∃ ρ > 0, AnalyticOn ℂ f (closedBall z₀ ρ) ∧ ∀ z ∈ closedBall z₀ ρ, z ≠ z₀ → f z ≠ f z₀ := by simpa only [setOf_and, subset_inter_iff] using nhds_basis_closedBall.mem_iff.mp (h2.and (eventually_nhdsWithin_iff.mp h1)) replace h3 : DiffContOnCl ℂ f (ball z₀ ρ) := ⟨h3.differentiableOn.mono ball_subset_closedBall, (closure_ball z₀ hρ.lt.ne.symm).symm ▸ h3.continuousOn⟩ let r := ρ ⊓ R have hr : 0 < r := lt_inf_iff.mpr ⟨hρ, hR⟩ have h5 : closedBall z₀ r ⊆ closedBall z₀ ρ := closedBall_subset_closedBall inf_le_left have h6 : DiffContOnCl ℂ f (ball z₀ r) := h3.mono (ball_subset_ball inf_le_left) have h7 : ∀ z ∈ sphere z₀ r, f z ≠ f z₀ := fun z hz => h4 z (h5 (sphere_subset_closedBall hz)) (ne_of_mem_sphere hz hr.ne.symm) have h8 : (sphere z₀ r).Nonempty := NormedSpace.sphere_nonempty.mpr hr.le have h9 : ContinuousOn (fun x => ‖f x - f z₀‖) (sphere z₀ r) := continuous_norm.comp_continuousOn ((h6.sub_const (f z₀)).continuousOn_ball.mono sphere_subset_closedBall) obtain ⟨x, hx, hfx⟩ := (isCompact_sphere z₀ r).exists_isMinOn h8 h9 refine ⟨‖f x - f z₀‖ / 2, half_pos (norm_sub_pos_iff.mpr (h7 x hx)), ?_⟩ exact (h6.ball_subset_image_closedBall hr (fun z hz => hfx hz) (not_eventually.mp h)).trans (image_subset f (closedBall_subset_closedBall inf_le_right))
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Tactic.Positivity.Core import Mathlib.Algebra.Ring.NegOnePow #align_import analysis.special_functions.trigonometric.basic from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # Trigonometric functions ## Main definitions This file contains the definition of `π`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open scoped Classical open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 continuity #align complex.continuous_sin Complex.continuous_sin @[fun_prop] theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s := continuous_sin.continuousOn #align complex.continuous_on_sin Complex.continuousOn_sin @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 continuity #align complex.continuous_cos Complex.continuous_cos @[fun_prop] theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s := continuous_cos.continuousOn #align complex.continuous_on_cos Complex.continuousOn_cos @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 continuity #align complex.continuous_sinh Complex.continuous_sinh @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 continuity #align complex.continuous_cosh Complex.continuous_cosh end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) #align real.continuous_sin Real.continuous_sin @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn #align real.continuous_on_sin Real.continuousOn_sin @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) #align real.continuous_cos Real.continuous_cos @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn #align real.continuous_on_cos Real.continuousOn_cos @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) #align real.continuous_sinh Real.continuous_sinh @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) #align real.continuous_cosh Real.continuous_cosh end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ #align real.exists_cos_eq_zero Real.exists_cos_eq_zero /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero #align real.pi Real.pi @[inherit_doc] scoped notation "π" => Real.pi @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 #align real.cos_pi_div_two Real.cos_pi_div_two theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 #align real.one_le_pi_div_two Real.one_le_pi_div_two theorem pi_div_two_le_two : π / 2 ≤ 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 #align real.pi_div_two_le_two Real.pi_div_two_le_two theorem two_le_pi : (2 : ℝ) ≤ π := (div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) #align real.two_le_pi Real.two_le_pi theorem pi_le_four : π ≤ 4 := (div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1 (calc π / 2 ≤ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) #align real.pi_le_four Real.pi_le_four theorem pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi #align real.pi_pos Real.pi_pos theorem pi_nonneg : 0 ≤ π := pi_pos.le theorem pi_ne_zero : π ≠ 0 := pi_pos.ne' #align real.pi_ne_zero Real.pi_ne_zero theorem pi_div_two_pos : 0 < π / 2 := half_pos pi_pos #align real.pi_div_two_pos Real.pi_div_two_pos theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos] #align real.two_pi_pos Real.two_pi_pos end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `π` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `π` considered as a nonnegative real. -/ noncomputable def pi : ℝ≥0 := ⟨π, Real.pi_pos.le⟩ #align nnreal.pi NNReal.pi @[simp] theorem coe_real_pi : (pi : ℝ) = π := rfl #align nnreal.coe_real_pi NNReal.coe_real_pi theorem pi_pos : 0 < pi := mod_cast Real.pi_pos #align nnreal.pi_pos NNReal.pi_pos theorem pi_ne_zero : pi ≠ 0 := pi_pos.ne' #align nnreal.pi_ne_zero NNReal.pi_ne_zero end NNReal namespace Real open Real @[simp] theorem sin_pi : sin π = 0 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp #align real.sin_pi Real.sin_pi @[simp] theorem cos_pi : cos π = -1 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num #align real.cos_pi Real.cos_pi @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] #align real.sin_two_pi Real.sin_two_pi @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] #align real.cos_two_pi Real.cos_two_pi theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] #align real.sin_antiperiodic Real.sin_antiperiodic theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul #align real.sin_periodic Real.sin_periodic @[simp] theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x := sin_antiperiodic x #align real.sin_add_pi Real.sin_add_pi @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := sin_periodic x #align real.sin_add_two_pi Real.sin_add_two_pi @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x #align real.sin_sub_pi Real.sin_sub_pi @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x #align real.sin_sub_two_pi Real.sin_sub_two_pi @[simp] theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' #align real.sin_pi_sub Real.sin_pi_sub @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' #align real.sin_two_pi_sub Real.sin_two_pi_sub @[simp] theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n #align real.sin_nat_mul_pi Real.sin_nat_mul_pi @[simp] theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n #align real.sin_int_mul_pi Real.sin_int_mul_pi @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x #align real.sin_add_nat_mul_two_pi Real.sin_add_nat_mul_two_pi @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x #align real.sin_add_int_mul_two_pi Real.sin_add_int_mul_two_pi @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n #align real.sin_sub_nat_mul_two_pi Real.sin_sub_nat_mul_two_pi @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n #align real.sin_sub_int_mul_two_pi Real.sin_sub_int_mul_two_pi @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n #align real.sin_nat_mul_two_pi_sub Real.sin_nat_mul_two_pi_sub @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n #align real.sin_int_mul_two_pi_sub Real.sin_int_mul_two_pi_sub theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x := n.coe_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x := n.coe_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.coe_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] #align real.cos_antiperiodic Real.cos_antiperiodic theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul #align real.cos_periodic Real.cos_periodic @[simp] theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x := cos_antiperiodic x #align real.cos_add_pi Real.cos_add_pi @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := cos_periodic x #align real.cos_add_two_pi Real.cos_add_two_pi @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x #align real.cos_sub_pi Real.cos_sub_pi @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x #align real.cos_sub_two_pi Real.cos_sub_two_pi @[simp] theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' #align real.cos_pi_sub Real.cos_pi_sub @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' #align real.cos_two_pi_sub Real.cos_two_pi_sub @[simp] theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero #align real.cos_nat_mul_two_pi Real.cos_nat_mul_two_pi @[simp] theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero #align real.cos_int_mul_two_pi Real.cos_int_mul_two_pi @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x #align real.cos_add_nat_mul_two_pi Real.cos_add_nat_mul_two_pi @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x #align real.cos_add_int_mul_two_pi Real.cos_add_int_mul_two_pi @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n #align real.cos_sub_nat_mul_two_pi Real.cos_sub_nat_mul_two_pi @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n #align real.cos_sub_int_mul_two_pi Real.cos_sub_int_mul_two_pi @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.nat_mul_sub_eq n #align real.cos_nat_mul_two_pi_sub Real.cos_nat_mul_two_pi_sub @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.int_mul_sub_eq n #align real.cos_int_mul_two_pi_sub Real.cos_int_mul_two_pi_sub theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x := n.coe_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x := n.coe_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x := n.coe_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x := cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic #align real.cos_nat_mul_two_pi_add_pi Real.cos_nat_mul_two_pi_add_pi -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic #align real.cos_int_mul_two_pi_add_pi Real.cos_int_mul_two_pi_add_pi -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic #align real.cos_nat_mul_two_pi_sub_pi Real.cos_nat_mul_two_pi_sub_pi -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic #align real.cos_int_mul_two_pi_sub_pi Real.cos_int_mul_two_pi_sub_pi theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : π - x ≤ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this #align real.sin_pos_of_pos_of_lt_pi Real.sin_pos_of_pos_of_lt_pi theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 #align real.sin_pos_of_mem_Ioo Real.sin_pos_of_mem_Ioo theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) #align real.sin_nonneg_of_mem_Icc Real.sin_nonneg_of_mem_Icc theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ #align real.sin_nonneg_of_nonneg_of_le_pi Real.sin_nonneg_of_nonneg_of_le_pi theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) #align real.sin_neg_of_neg_of_neg_pi_lt Real.sin_neg_of_neg_of_neg_pi_lt theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) #align real.sin_nonpos_of_nonnpos_of_neg_pi_le Real.sin_nonpos_of_nonnpos_of_neg_pi_le @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) this.resolve_right fun h => show ¬(0 : ℝ) < -1 by norm_num <| h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) #align real.sin_pi_div_two Real.sin_pi_div_two theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] #align real.sin_add_pi_div_two Real.sin_add_pi_div_two theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] #align real.sin_sub_pi_div_two Real.sin_sub_pi_div_two theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] #align real.sin_pi_div_two_sub Real.sin_pi_div_two_sub theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] #align real.cos_add_pi_div_two Real.cos_add_pi_div_two theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] #align real.cos_sub_pi_div_two Real.cos_sub_pi_div_two theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] #align real.cos_pi_div_two_sub Real.cos_pi_div_two_sub theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ #align real.cos_pos_of_mem_Ioo Real.cos_pos_of_mem_Ioo theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ #align real.cos_nonneg_of_mem_Icc Real.cos_nonneg_of_mem_Icc theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : 0 ≤ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ #align real.cos_nonneg_of_neg_pi_div_two_le_of_le Real.cos_nonneg_of_neg_pi_div_two_le_of_le theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ #align real.cos_neg_of_pi_div_two_lt_of_lt Real.cos_neg_of_pi_div_two_lt_of_lt theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ #align real.cos_nonpos_of_pi_div_two_le_of_le Real.cos_nonpos_of_pi_div_two_le_of_le theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] #align real.sin_eq_sqrt_one_sub_cos_sq Real.sin_eq_sqrt_one_sub_cos_sq theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] #align real.cos_eq_sqrt_one_sub_sin_sq Real.cos_eq_sqrt_one_sub_sin_sq lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) : sin (x / 2) = sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) : sin (x / 2) = -sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨fun h => by contrapose! h cases h.lt_or_lt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne', fun h => by simp [h]⟩ #align real.sin_eq_zero_iff_of_lt_of_lt Real.sin_eq_zero_iff_of_lt_of_lt theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨fun h => ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟨n, hn⟩ => hn ▸ sin_int_mul_pi _⟩ #align real.sin_eq_zero_iff Real.sin_eq_zero_iff theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] #align real.sin_ne_zero_iff Real.sin_ne_zero_iff theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ #align real.sin_eq_zero_iff_cos_eq Real.sin_eq_zero_iff_cos_eq theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨fun h => let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟨n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel ((Int.dvd_iff_emod_eq_zero _ _).2 hn0)]) fun hn1 => by rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟨n, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩ #align real.cos_eq_one_iff Real.cos_eq_one_iff theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨fun h => by rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hx₂ obtain rfl : n = 0 := le_antisymm (by omega) (by omega) simp, fun h => by simp [h]⟩ #align real.cos_eq_one_iff_of_lt_of_lt Real.cos_eq_one_iff_of_lt_of_lt theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith positivity #align real.sin_lt_sin_of_lt_of_le_pi_div_two Real.sin_lt_sin_of_lt_of_le_pi_div_two theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy #align real.strict_mono_on_sin Real.strictMonoOn_sin theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith #align real.cos_lt_cos_of_nonneg_of_le_pi Real.cos_lt_cos_of_nonneg_of_le_pi theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy #align real.cos_lt_cos_of_nonneg_of_le_pi_div_two Real.cos_lt_cos_of_nonneg_of_le_pi_div_two theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy #align real.strict_anti_on_cos Real.strictAntiOn_cos theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy #align real.cos_le_cos_of_nonneg_of_le_pi Real.cos_le_cos_of_nonneg_of_le_pi theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy #align real.sin_le_sin_of_le_of_le_pi_div_two Real.sin_le_sin_of_le_of_le_pi_div_two theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) := strictMonoOn_sin.injOn #align real.inj_on_sin Real.injOn_sin theorem injOn_cos : InjOn cos (Icc 0 π) := strictAntiOn_cos.injOn #align real.inj_on_cos Real.injOn_cos theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn #align real.surj_on_sin Real.surjOn_sin theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn #align real.surj_on_cos Real.surjOn_cos theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ #align real.sin_mem_Icc Real.sin_mem_Icc theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ #align real.cos_mem_Icc Real.cos_mem_Icc theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x #align real.maps_to_sin Real.mapsTo_sin theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x #align real.maps_to_cos Real.mapsTo_cos theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩ #align real.bij_on_sin Real.bijOn_sin theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) := ⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩ #align real.bij_on_cos Real.bijOn_cos @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range #align real.range_cos Real.range_cos @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range #align real.range_sin Real.range_sin theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by norm_num) #align real.range_cos_infinite Real.range_cos_infinite theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by norm_num) #align real.range_sin_infinite Real.range_sin_infinite section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) #align real.sqrt_two_add_series Real.sqrtTwoAddSeries theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp #align real.sqrt_two_add_series_zero Real.sqrtTwoAddSeries_zero theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp #align real.sqrt_two_add_series_one Real.sqrtTwoAddSeries_one theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp #align real.sqrt_two_add_series_two Real.sqrtTwoAddSeries_two theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ #align real.sqrt_two_add_series_zero_nonneg Real.sqrtTwoAddSeries_zero_nonneg theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ #align real.sqrt_two_add_series_nonneg Real.sqrtTwoAddSeries_nonneg theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2 | 0 => by norm_num | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] · refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num · exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) #align real.sqrt_two_add_series_lt_two Real.sqrtTwoAddSeries_lt_two theorem sqrtTwoAddSeries_succ (x : ℝ) : ∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] #align real.sqrt_two_add_series_succ Real.sqrtTwoAddSeries_succ theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) : ∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) #align real.sqrt_two_add_series_monotone_left Real.sqrtTwoAddSeries_monotone_left @[simp] theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow one_lt_two n.succ_ne_zero have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A have C : 0 < π / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] #align real.cos_pi_over_two_pow Real.cos_pi_over_two_pow theorem sin_sq_pi_over_two_pow (n : ℕ) : sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] #align real.sin_sq_pi_over_two_pow Real.sin_sq_pi_over_two_pow theorem sin_sq_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] · congr · norm_num · norm_num · exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _) #align real.sin_sq_pi_over_two_pow_succ Real.sin_sq_pi_over_two_pow_succ @[simp] theorem sin_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_sq_eq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] · congr <;> norm_num · rw [sub_nonneg] exact (sqrtTwoAddSeries_lt_two _).le refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two · positivity · exact div_le_self pi_pos.le <| one_le_pow_of_one_le one_le_two _ #align real.sin_pi_over_two_pow_succ Real.sin_pi_over_two_pow_succ @[simp] theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by trans cos (π / 2 ^ 2) · congr norm_num · simp #align real.cos_pi_div_four Real.cos_pi_div_four @[simp] theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by trans sin (π / 2 ^ 2) · congr norm_num · simp #align real.sin_pi_div_four Real.sin_pi_div_four @[simp] theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by trans cos (π / 2 ^ 3) · congr norm_num · simp #align real.cos_pi_div_eight Real.cos_pi_div_eight @[simp] theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by trans sin (π / 2 ^ 3) · congr norm_num · simp #align real.sin_pi_div_eight Real.sin_pi_div_eight @[simp] theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by trans cos (π / 2 ^ 4) · congr norm_num · simp #align real.cos_pi_div_sixteen Real.cos_pi_div_sixteen @[simp] theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by trans sin (π / 2 ^ 4) · congr norm_num · simp #align real.sin_pi_div_sixteen Real.sin_pi_div_sixteen @[simp] theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by trans cos (π / 2 ^ 5) · congr norm_num · simp #align real.cos_pi_div_thirty_two Real.cos_pi_div_thirty_two @[simp] theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by trans sin (π / 2 ^ 5) · congr norm_num · simp #align real.sin_pi_div_thirty_two Real.sin_pi_div_thirty_two -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `π / 3` is `1 / 2`. -/ @[simp] theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by have : cos (3 * (π / 3)) = cos π := by congr 1 ring linarith [cos_pi, cos_three_mul (π / 3)] cases' mul_eq_zero.mp h₁ with h h · linarith [pow_eq_zero h] · have : cos π < cos (π / 3) := by refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos] linarith [cos_pi] #align real.cos_pi_div_three Real.cos_pi_div_three /-- The cosine of `π / 6` is `√3 / 2`. -/ @[simp] theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div, ← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos] #align real.cos_pi_div_six Real.cos_pi_div_six /-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := by rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num #align real.sq_cos_pi_div_six Real.sq_cos_pi_div_six /-- The sine of `π / 6` is `1 / 2`. -/ @[simp] theorem sin_pi_div_six : sin (π / 6) = 1 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_three] congr ring #align real.sin_pi_div_six Real.sin_pi_div_six /-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := by rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] congr ring #align real.sq_sin_pi_div_three Real.sq_sin_pi_div_three /-- The sine of `π / 3` is `√3 / 2`. -/ @[simp] theorem sin_pi_div_three : sin (π / 3) = √3 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_six] congr ring #align real.sin_pi_div_three Real.sin_pi_div_three end CosDivSq /-- `Real.sin` as an `OrderIso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/ def sinOrderIso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1 : ℝ) 1 := (strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq #align real.sin_order_iso Real.sinOrderIso @[simp] theorem coe_sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : (sinOrderIso x : ℝ) = sin x := rfl #align real.coe_sin_order_iso_apply Real.coe_sinOrderIso_apply theorem sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ := rfl #align real.sin_order_iso_apply Real.sinOrderIso_apply @[simp] theorem tan_pi_div_four : tan (π / 4) = 1 := by rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] have h : √2 / 2 > 0 := by positivity exact div_self (ne_of_gt h) #align real.tan_pi_div_four Real.tan_pi_div_four @[simp] theorem tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos] #align real.tan_pi_div_two Real.tan_pi_div_two @[simp] theorem tan_pi_div_six : tan (π / 6) = 1 / sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six] ring @[simp] theorem tan_pi_div_three : tan (π / 3) = sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three] ring theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw [tan_eq_sin_div_cos] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) #align real.tan_pos_of_pos_of_lt_pi_div_two Real.tan_pos_of_pos_of_lt_pi_div_two theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos] | Or.inr hx0, _ => by simp [hx0.symm] #align real.tan_nonneg_of_nonneg_of_le_pi_div_two Real.tan_nonneg_of_nonneg_of_le_pi_div_two theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) #align real.tan_neg_of_neg_of_pi_div_two_lt Real.tan_neg_of_neg_of_pi_div_two_lt theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 := neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) #align real.tan_nonpos_of_nonpos_of_neg_pi_div_two_le Real.tan_nonpos_of_nonpos_of_neg_pi_div_two_le theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(π / 2)) (π / 2)) := by rintro x hx y hy hlt rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, div_lt_div_iff (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub] exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2] #align real.strict_mono_on_tan Real.strictMonoOn_tan theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := strictMonoOn_tan ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩ hxy #align real.tan_lt_tan_of_lt_of_lt_pi_div_two Real.tan_lt_tan_of_lt_of_lt_pi_div_two theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hy₂ hxy #align real.tan_lt_tan_of_nonneg_of_lt_pi_div_two Real.tan_lt_tan_of_nonneg_of_lt_pi_div_two theorem injOn_tan : InjOn tan (Ioo (-(π / 2)) (π / 2)) := strictMonoOn_tan.injOn #align real.inj_on_tan Real.injOn_tan theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := injOn_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy #align real.tan_inj_of_lt_of_lt_pi_div_two Real.tan_inj_of_lt_of_lt_pi_div_two theorem tan_periodic : Function.Periodic tan π := by simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic #align real.tan_periodic Real.tan_periodic -- Porting note (#10756): added theorem @[simp] theorem tan_pi : tan π = 0 := by rw [tan_periodic.eq, tan_zero] theorem tan_add_pi (x : ℝ) : tan (x + π) = tan x := tan_periodic x #align real.tan_add_pi Real.tan_add_pi theorem tan_sub_pi (x : ℝ) : tan (x - π) = tan x := tan_periodic.sub_eq x #align real.tan_sub_pi Real.tan_sub_pi theorem tan_pi_sub (x : ℝ) : tan (π - x) = -tan x := tan_neg x ▸ tan_periodic.sub_eq' #align real.tan_pi_sub Real.tan_pi_sub theorem tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] #align real.tan_pi_div_two_sub Real.tan_pi_div_two_sub theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.nat_mul_eq n #align real.tan_nat_mul_pi Real.tan_nat_mul_pi theorem tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.int_mul_eq n #align real.tan_int_mul_pi Real.tan_int_mul_pi theorem tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x := tan_periodic.nat_mul n x #align real.tan_add_nat_mul_pi Real.tan_add_nat_mul_pi theorem tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x := tan_periodic.int_mul n x #align real.tan_add_int_mul_pi Real.tan_add_int_mul_pi theorem tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x := tan_periodic.sub_nat_mul_eq n #align real.tan_sub_nat_mul_pi Real.tan_sub_nat_mul_pi theorem tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x := tan_periodic.sub_int_mul_eq n #align real.tan_sub_int_mul_pi Real.tan_sub_int_mul_pi theorem tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.nat_mul_sub_eq n #align real.tan_nat_mul_pi_sub Real.tan_nat_mul_pi_sub theorem tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.int_mul_sub_eq n #align real.tan_int_mul_pi_sub Real.tan_int_mul_pi_sub theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (π / 2)) (𝓝 1) := by convert continuous_sin.continuousWithinAt.tendsto simp #align real.tendsto_sin_pi_div_two Real.tendsto_sin_pi_div_two theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (π / 2)) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsWithin_Iio (right_mem_Ioc.mpr (neg_lt_self pi_div_two_pos))] with x hx using cos_pos_of_mem_Ioo hx #align real.tendsto_cos_pi_div_two Real.tendsto_cos_pi_div_two theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (π / 2)) atTop := by convert tendsto_cos_pi_div_two.inv_tendsto_zero.atTop_mul zero_lt_one tendsto_sin_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] #align real.tendsto_tan_pi_div_two Real.tendsto_tan_pi_div_two theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(π / 2))) (𝓝 (-1)) := by convert continuous_sin.continuousWithinAt.tendsto using 2 simp #align real.tendsto_sin_neg_pi_div_two Real.tendsto_sin_neg_pi_div_two theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(π / 2))) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsWithin_Ioi (left_mem_Ico.mpr (neg_lt_self pi_div_two_pos))] with x hx using cos_pos_of_mem_Ioo hx #align real.tendsto_cos_neg_pi_div_two Real.tendsto_cos_neg_pi_div_two theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(π / 2))) atBot := by convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.atTop_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] #align real.tendsto_tan_neg_pi_div_two Real.tendsto_tan_neg_pi_div_two end Real namespace Complex open Real
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
1,119
1,121
theorem sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 := by
rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.LinearAlgebra.Matrix.BilinearForm import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.Vandermonde import Mathlib.LinearAlgebra.Trace import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.PrimitiveElement import Mathlib.FieldTheory.Galois import Mathlib.RingTheory.PowerBasis import Mathlib.FieldTheory.Minpoly.MinpolyDiv #align_import ring_theory.trace from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Trace for (finite) ring extensions. Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`, the trace of the linear map given by multiplying by `s` gives information about the roots of the minimal polynomial of `s` over `R`. ## Main definitions * `Algebra.trace R S x`: the trace of an element `s` of an `R`-algebra `S` * `Algebra.traceForm R S`: bilinear form sending `x`, `y` to the trace of `x * y` * `Algebra.traceMatrix R b`: the matrix whose `(i j)`-th element is the trace of `b i * b j`. * `Algebra.embeddingsMatrix A C b : Matrix κ (B →ₐ[A] C) C` is the matrix whose `(i, σ)` coefficient is `σ (b i)`. * `Algebra.embeddingsMatrixReindex A C b e : Matrix κ κ C` is the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : B →ₐ[A] C` is the embedding corresponding to `j : κ` given by a bijection `e : κ ≃ (B →ₐ[A] C)`. ## Main results * `trace_algebraMap_of_basis`, `trace_algebraMap`: if `x : K`, then `Tr_{L/K} x = [L : K] x` * `trace_trace_of_basis`, `trace_trace`: `Tr_{L/K} (Tr_{F/L} x) = Tr_{F/K} x` * `trace_eq_sum_roots`: the trace of `x : K(x)` is the sum of all conjugate roots of `x` * `trace_eq_sum_embeddings`: the trace of `x : K(x)` is the sum of all embeddings of `x` into an algebraically closed field * `traceForm_nondegenerate`: the trace form over a separable extension is a nondegenerate bilinear form * `traceForm_dualBasis_powerBasis_eq`: The dual basis of a powerbasis `{1, x, x²...}` under the trace form is `aᵢ / f'(x)`, with `f` being the minpoly of `x` and `f / (X - x) = ∑ aᵢxⁱ`. ## Implementation notes Typically, the trace is defined specifically for finite field extensions. The definition is as general as possible and the assumption that we have fields or that the extension is finite is added to the lemmas as needed. We only define the trace for left multiplication (`Algebra.leftMulMatrix`, i.e. `LinearMap.mulLeft`). For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway. ## References * https://en.wikipedia.org/wiki/Field_trace -/ universe u v w z variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] variable [Algebra R S] [Algebra R T] variable {K L : Type*} [Field K] [Field L] [Algebra K L] variable {ι κ : Type w} [Fintype ι] open FiniteDimensional open LinearMap (BilinForm) open LinearMap open Matrix open scoped Matrix namespace Algebra variable (b : Basis ι R S) variable (R S) /-- The trace of an element `s` of an `R`-algebra is the trace of `(s * ·)`, as an `R`-linear map. -/ noncomputable def trace : S →ₗ[R] R := (LinearMap.trace R S).comp (lmul R S).toLinearMap #align algebra.trace Algebra.trace variable {S} -- Not a `simp` lemma since there are more interesting ways to rewrite `trace R S x`, -- for example `trace_trace` theorem trace_apply (x) : trace R S x = LinearMap.trace R S (lmul R S x) := rfl #align algebra.trace_apply Algebra.trace_apply theorem trace_eq_zero_of_not_exists_basis (h : ¬∃ s : Finset S, Nonempty (Basis s R S)) : trace R S = 0 := by ext s; simp [trace_apply, LinearMap.trace, h] #align algebra.trace_eq_zero_of_not_exists_basis Algebra.trace_eq_zero_of_not_exists_basis variable {R} -- Can't be a `simp` lemma because it depends on a choice of basis theorem trace_eq_matrix_trace [DecidableEq ι] (b : Basis ι R S) (s : S) : trace R S s = Matrix.trace (Algebra.leftMulMatrix b s) := by rw [trace_apply, LinearMap.trace_eq_matrix_trace _ b, ← toMatrix_lmul_eq]; rfl #align algebra.trace_eq_matrix_trace Algebra.trace_eq_matrix_trace /-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. -/ theorem trace_algebraMap_of_basis (x : R) : trace R S (algebraMap R S x) = Fintype.card ι • x := by haveI := Classical.decEq ι rw [trace_apply, LinearMap.trace_eq_matrix_trace R b, Matrix.trace] convert Finset.sum_const x simp [-coe_lmul_eq_mul] #align algebra.trace_algebra_map_of_basis Algebra.trace_algebraMap_of_basis /-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. (If `L` is not finite-dimensional over `K`, then `trace` and `finrank` return `0`.) -/ @[simp] theorem trace_algebraMap (x : K) : trace K L (algebraMap K L x) = finrank K L • x := by by_cases H : ∃ s : Finset L, Nonempty (Basis s K L) · rw [trace_algebraMap_of_basis H.choose_spec.some, finrank_eq_card_basis H.choose_spec.some] · simp [trace_eq_zero_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis_finset H] #align algebra.trace_algebra_map Algebra.trace_algebraMap theorem trace_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι] [Finite κ] (b : Basis ι R S) (c : Basis κ S T) (x : T) : trace R S (trace S T x) = trace R T x := by haveI := Classical.decEq ι haveI := Classical.decEq κ cases nonempty_fintype ι cases nonempty_fintype κ rw [trace_eq_matrix_trace (b.smul c), trace_eq_matrix_trace b, trace_eq_matrix_trace c, Matrix.trace, Matrix.trace, Matrix.trace, ← Finset.univ_product_univ, Finset.sum_product] refine Finset.sum_congr rfl fun i _ ↦ ?_ simp only [AlgHom.map_sum, smul_leftMulMatrix, Finset.sum_apply, Matrix.diag, Finset.sum_apply i (Finset.univ : Finset κ) fun y => leftMulMatrix b (leftMulMatrix c x y y)] #align algebra.trace_trace_of_basis Algebra.trace_trace_of_basis theorem trace_comp_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι] [Finite κ] (b : Basis ι R S) (c : Basis κ S T) : (trace R S).comp ((trace S T).restrictScalars R) = trace R T := by ext rw [LinearMap.comp_apply, LinearMap.restrictScalars_apply, trace_trace_of_basis b c] #align algebra.trace_comp_trace_of_basis Algebra.trace_comp_trace_of_basis @[simp] theorem trace_trace [Algebra K T] [Algebra L T] [IsScalarTower K L T] [FiniteDimensional K L] [FiniteDimensional L T] (x : T) : trace K L (trace L T x) = trace K T x := trace_trace_of_basis (Basis.ofVectorSpace K L) (Basis.ofVectorSpace L T) x #align algebra.trace_trace Algebra.trace_trace @[simp] theorem trace_comp_trace [Algebra K T] [Algebra L T] [IsScalarTower K L T] [FiniteDimensional K L] [FiniteDimensional L T] : (trace K L).comp ((trace L T).restrictScalars K) = trace K T := by ext; rw [LinearMap.comp_apply, LinearMap.restrictScalars_apply, trace_trace] #align algebra.trace_comp_trace Algebra.trace_comp_trace @[simp] theorem trace_prod_apply [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T] (x : S × T) : trace R (S × T) x = trace R S x.fst + trace R T x.snd := by nontriviality R let f := (lmul R S).toLinearMap.prodMap (lmul R T).toLinearMap have : (lmul R (S × T)).toLinearMap = (prodMapLinear R S T S T R).comp f := LinearMap.ext₂ Prod.mul_def simp_rw [trace, this] exact trace_prodMap' _ _ #align algebra.trace_prod_apply Algebra.trace_prod_apply theorem trace_prod [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T] : trace R (S × T) = (trace R S).coprod (trace R T) := LinearMap.ext fun p => by rw [coprod_apply, trace_prod_apply] #align algebra.trace_prod Algebra.trace_prod section TraceForm variable (R S) /-- The `traceForm` maps `x y : S` to the trace of `x * y`. It is a symmetric bilinear form and is nondegenerate if the extension is separable. -/ noncomputable def traceForm : BilinForm R S := LinearMap.compr₂ (lmul R S).toLinearMap (trace R S) #align algebra.trace_form Algebra.traceForm variable {S} -- This is a nicer lemma than the one produced by `@[simps] def traceForm`. @[simp] theorem traceForm_apply (x y : S) : traceForm R S x y = trace R S (x * y) := rfl #align algebra.trace_form_apply Algebra.traceForm_apply theorem traceForm_isSymm : (traceForm R S).IsSymm := fun _ _ => congr_arg (trace R S) (mul_comm _ _) #align algebra.trace_form_is_symm Algebra.traceForm_isSymm theorem traceForm_toMatrix [DecidableEq ι] (i j) : BilinForm.toMatrix b (traceForm R S) i j = trace R S (b i * b j) := by rw [BilinForm.toMatrix_apply, traceForm_apply] #align algebra.trace_form_to_matrix Algebra.traceForm_toMatrix theorem traceForm_toMatrix_powerBasis (h : PowerBasis R S) : BilinForm.toMatrix h.basis (traceForm R S) = of fun i j => trace R S (h.gen ^ (i.1 + j.1)) := by ext; rw [traceForm_toMatrix, of_apply, pow_add, h.basis_eq_pow, h.basis_eq_pow] #align algebra.trace_form_to_matrix_power_basis Algebra.traceForm_toMatrix_powerBasis end TraceForm end Algebra section EqSumRoots open Algebra Polynomial variable {F : Type*} [Field F] variable [Algebra K S] [Algebra K F] /-- Given `pb : PowerBasis K S`, the trace of `pb.gen` is `-(minpoly K pb.gen).nextCoeff`. -/ theorem PowerBasis.trace_gen_eq_nextCoeff_minpoly [Nontrivial S] (pb : PowerBasis K S) : Algebra.trace K S pb.gen = -(minpoly K pb.gen).nextCoeff := by have d_pos : 0 < pb.dim := PowerBasis.dim_pos pb have d_pos' : 0 < (minpoly K pb.gen).natDegree := by simpa haveI : Nonempty (Fin pb.dim) := ⟨⟨0, d_pos⟩⟩ rw [trace_eq_matrix_trace pb.basis, trace_eq_neg_charpoly_coeff, charpoly_leftMulMatrix, ← pb.natDegree_minpoly, Fintype.card_fin, ← nextCoeff_of_natDegree_pos d_pos'] #align power_basis.trace_gen_eq_next_coeff_minpoly PowerBasis.trace_gen_eq_nextCoeff_minpoly /-- Given `pb : PowerBasis K S`, then the trace of `pb.gen` is `((minpoly K pb.gen).aroots F).sum`. -/ theorem PowerBasis.trace_gen_eq_sum_roots [Nontrivial S] (pb : PowerBasis K S) (hf : (minpoly K pb.gen).Splits (algebraMap K F)) : algebraMap K F (trace K S pb.gen) = ((minpoly K pb.gen).aroots F).sum := by rw [PowerBasis.trace_gen_eq_nextCoeff_minpoly, RingHom.map_neg, ← nextCoeff_map (algebraMap K F).injective, sum_roots_eq_nextCoeff_of_monic_of_split ((minpoly.monic (PowerBasis.isIntegral_gen _)).map _) ((splits_id_iff_splits _).2 hf), neg_neg] #align power_basis.trace_gen_eq_sum_roots PowerBasis.trace_gen_eq_sum_roots namespace IntermediateField.AdjoinSimple open IntermediateField theorem trace_gen_eq_zero {x : L} (hx : ¬IsIntegral K x) : Algebra.trace K K⟮x⟯ (AdjoinSimple.gen K x) = 0 := by rw [trace_eq_zero_of_not_exists_basis, LinearMap.zero_apply] contrapose! hx obtain ⟨s, ⟨b⟩⟩ := hx refine .of_mem_of_fg K⟮x⟯.toSubalgebra ?_ x ?_ · exact (Submodule.fg_iff_finiteDimensional _).mpr (FiniteDimensional.of_fintype_basis b) · exact subset_adjoin K _ (Set.mem_singleton x) #align intermediate_field.adjoin_simple.trace_gen_eq_zero IntermediateField.AdjoinSimple.trace_gen_eq_zero
Mathlib/RingTheory/Trace.lean
262
271
theorem trace_gen_eq_sum_roots (x : L) (hf : (minpoly K x).Splits (algebraMap K F)) : algebraMap K F (trace K K⟮x⟯ (AdjoinSimple.gen K x)) = ((minpoly K x).aroots F).sum := by
have injKxL := (algebraMap K⟮x⟯ L).injective by_cases hx : IsIntegral K x; swap · simp [minpoly.eq_zero hx, trace_gen_eq_zero hx, aroots_def] rw [← adjoin.powerBasis_gen hx, (adjoin.powerBasis hx).trace_gen_eq_sum_roots] <;> rw [adjoin.powerBasis_gen hx, ← minpoly.algebraMap_eq injKxL] <;> try simp only [AdjoinSimple.algebraMap_gen _ _] exact hf
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Order.BigOperators.Group.Multiset import Mathlib.Tactic.NormNum.Basic import Mathlib.Tactic.Positivity.Core #align_import algebra.big_operators.order from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Big operators on a finset in ordered groups This file contains the results concerning the interaction of multiset big operators with ordered groups/monoids. -/ open Function variable {ι α β M N G k R : Type*} namespace Finset section OrderedCommMonoid variable [CommMonoid M] [OrderedCommMonoid N] /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map submultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∏ x ∈ s, g x) ≤ ∏ x ∈ s, f (g x)`. -/ @[to_additive le_sum_nonempty_of_subadditive_on_pred] theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y)) (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by refine le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ ?_ ?_) ?_ · simp [hs_nonempty.ne_empty] · exact Multiset.forall_mem_map_iff.mpr hs rw [Multiset.map_map] rfl #align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred #align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred /-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let `f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let `g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive_on_pred /-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/ @[to_additive le_sum_nonempty_of_subadditive] theorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y) {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y) (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial #align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative #align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive /-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a nonempty finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/ add_decl_doc le_sum_nonempty_of_subadditive /-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/ @[to_additive le_sum_of_subadditive_on_pred] theorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1) (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y)) (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by rcases eq_empty_or_nonempty s with (rfl | hs_nonempty) · simp [h_one] · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs #align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred #align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred /-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map such that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then `f (∑ x ∈ s, g x) ≤ ∑ x ∈ s, f (g x)`. -/ add_decl_doc le_sum_of_subadditive_on_pred /-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/ @[to_additive le_sum_of_subadditive] theorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1) (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by refine le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) ?_ rw [Multiset.map_map] rfl #align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative #align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive /-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`, `i ∈ s`, is a finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/ add_decl_doc le_sum_of_subadditive variable {f g : ι → N} {s t : Finset ι} /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `∏ i ∈ s, f i ≤ ∏ i ∈ s, g i`. -/ @[to_additive sum_le_sum] theorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i ∈ s, f i ≤ ∏ i ∈ s, g i := Multiset.prod_map_le_prod_map f g h #align finset.prod_le_prod' Finset.prod_le_prod' #align finset.sum_le_sum Finset.sum_le_sum /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `∑ i ∈ s, f i ≤ ∑ i ∈ s, g i`. -/ add_decl_doc sum_le_sum /-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or equal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`. This is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient for the `gcongr` tactic. -/ @[to_additive (attr := gcongr) GCongr.sum_le_sum] theorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g := s.prod_le_prod' h /-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than or equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`. This is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient for the `gcongr` tactic. -/ add_decl_doc GCongr.sum_le_sum @[to_additive sum_nonneg] theorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i := le_trans (by rw [prod_const_one]) (prod_le_prod' h) #align finset.one_le_prod' Finset.one_le_prod' #align finset.sum_nonneg Finset.sum_nonneg @[to_additive Finset.sum_nonneg'] theorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i := Finset.one_le_prod' fun i _ ↦ h i #align finset.one_le_prod'' Finset.one_le_prod'' #align finset.sum_nonneg' Finset.sum_nonneg' @[to_additive sum_nonpos] theorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i ∈ s, f i ≤ 1 := (prod_le_prod' h).trans_eq (by rw [prod_const_one]) #align finset.prod_le_one' Finset.prod_le_one' #align finset.sum_nonpos Finset.sum_nonpos @[to_additive sum_le_sum_of_subset_of_nonneg] theorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) : ∏ i ∈ s, f i ≤ ∏ i ∈ t, f i := by classical calc ∏ i ∈ s, f i ≤ (∏ i ∈ t \ s, f i) * ∏ i ∈ s, f i := le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp] _ = ∏ i ∈ t \ s ∪ s, f i := (prod_union sdiff_disjoint).symm _ = ∏ i ∈ t, f i := by rw [sdiff_union_of_subset h] #align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le' #align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg @[to_additive sum_mono_set_of_nonneg] theorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x ∈ s, f x := fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x #align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le' #align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg @[to_additive sum_le_univ_sum_of_nonneg] theorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) : ∏ x ∈ s, f x ≤ ∏ x, f x := prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a #align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le' #align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg -- Porting note (#11215): TODO -- The two next lemmas give the same lemma in additive version @[to_additive sum_eq_zero_iff_of_nonneg] theorem prod_eq_one_iff_of_one_le' : (∀ i ∈ s, 1 ≤ f i) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by classical refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_ intro a s ha ih H have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this), forall_mem_insert, ih this] #align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le' #align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg @[to_additive sum_eq_zero_iff_of_nonpos] theorem prod_eq_one_iff_of_le_one' : (∀ i ∈ s, f i ≤ 1) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _ #align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one' @[to_additive single_le_sum] theorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x ∈ s, f x := calc f a = ∏ i ∈ {a}, f i := (prod_singleton _ _).symm _ ≤ ∏ i ∈ s, f i := prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi #align finset.single_le_prod' Finset.single_le_prod' #align finset.single_le_sum Finset.single_le_sum @[to_additive] lemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) : f i * f j ≤ ∏ k ∈ s, f k := calc f i * f j = ∏ k ∈ .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton] _ ≤ ∏ k ∈ s, f k := by refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk simp [cons_subset, *] @[to_additive sum_le_card_nsmul] theorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) : s.prod f ≤ n ^ s.card := by refine (Multiset.prod_le_pow_card (s.val.map f) n ?_).trans ?_ · simpa using h · simp #align finset.prod_le_pow_card Finset.prod_le_pow_card #align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul @[to_additive card_nsmul_le_sum] theorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) : n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h #align finset.pow_card_le_prod Finset.pow_card_le_prod #align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum theorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ) (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n := card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h #align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul variable {ι' : Type*} [DecidableEq ι'] -- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t) @[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg] theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N} (h : ∀ y ∉ t, (1 : N) ≤ ∏ x ∈ s.filter fun x ↦ g x = y, f x) : (∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x) ≤ ∏ x ∈ s, f x := calc (∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x) ≤ ∏ y ∈ t ∪ s.image g, ∏ x ∈ s.filter fun x ↦ g x = y, f x := prod_le_prod_of_subset_of_one_le' subset_union_left fun y _ ↦ h y _ = ∏ x ∈ s, f x := prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _ #align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' #align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg -- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t) @[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos] theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N} (h : ∀ y ∉ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x ≤ 1) : ∏ x ∈ s, f x ≤ ∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f x := @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h #align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' #align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos end OrderedCommMonoid theorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) : |∑ i ∈ s, f i| ≤ ∑ i ∈ s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f #align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι} (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg hf)] #align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι} (hf : ∀ i, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by rw [abs_of_nonneg (Finset.sum_nonneg' hf)] #align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg' section Pigeonhole variable [DecidableEq β] theorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β} (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * t.card := calc s.card = ∑ a ∈ t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf _ ≤ ∑ _a ∈ t, n := sum_le_sum hn _ = _ := by simp [mul_comm] #align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to theorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ) (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card := card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.card_le_mul_card_image Finset.card_le_mul_card_image theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β} (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) : n * t.card ≤ s.card := calc n * t.card = ∑ _a ∈ t, n := by simp [mul_comm] _ ≤ ∑ a ∈ t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf] #align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to theorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ) (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card := mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn #align finset.mul_card_image_le_card Finset.mul_card_image_le_card end Pigeonhole section DoubleCounting variable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ} /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) : (∑ t ∈ B, (s ∩ t).card) ≤ s.card * n := by refine le_trans ?_ (s.sum_le_card_nsmul _ _ h) simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.sum_card_inter_le Finset.sum_card_inter_le /-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n` times how many they are. -/ theorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) : ∑ s ∈ B, s.card ≤ Fintype.card α * n := calc ∑ s ∈ B, s.card = ∑ s ∈ B, (univ ∩ s).card := by simp_rw [univ_inter] _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a #align finset.sum_card_le Finset.sum_card_le /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/ theorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) : s.card * n ≤ ∑ t ∈ B, (s ∩ t).card := by apply (s.card_nsmul_le_sum _ _ h).trans simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter] exact sum_comm.le #align finset.le_sum_card_inter Finset.le_sum_card_inter /-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n` times how many they are. -/
Mathlib/Algebra/Order/BigOperators/Group/Finset.lean
344
348
theorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) : Fintype.card α * n ≤ ∑ s ∈ B, s.card := calc Fintype.card α * n ≤ ∑ s ∈ B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a _ = ∑ s ∈ B, s.card := by
simp_rw [univ_inter]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Finset.Sort import Mathlib.Data.Set.Subsingleton #align_import combinatorics.composition from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Compositions A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks. This notion is closely related to that of a partition of `n`, but in a composition of `n` the order of the `iⱼ`s matters. We implement two different structures covering these two viewpoints on compositions. The first one, made of a list of positive integers summing to `n`, is the main one and is called `Composition n`. The second one is useful for combinatorial arguments (for instance to show that the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}` containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost points of each block. The main API is built on `Composition n`, and we provide an equivalence between the two types. ## Main functions * `c : Composition n` is a structure, made of a list of integers which are all positive and add up to `n`. * `composition_card` states that the cardinality of `Composition n` is exactly `2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is nat subtraction). Let `c : Composition n` be a composition of `n`. Then * `c.blocks` is the list of blocks in `c`. * `c.length` is the number of blocks in the composition. * `c.blocks_fun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on `Fin c.length`. This is the main object when using compositions to understand the composition of analytic functions. * `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.; * `c.embedding i : Fin (c.blocks_fun i) → Fin n` is the increasing embedding of the `i`-th block in `Fin n`; * `c.index j`, for `j : Fin n`, is the index of the block containing `j`. * `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`. * `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`. Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition of `n`. * `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the blocks of `c`. * `join_splitWrtComposition` states that splitting a list and then joining it gives back the original list. * `joinSplitWrtComposition_join` states that joining a list of lists, and then splitting it back according to the right composition, gives back the original list of lists. We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`. `c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries` and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not make sense in the edge case `n = 0`, while the previous description works in all cases). The elements of this set (other than `n`) correspond to leftmost points of blocks. Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n` from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that `CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)` (see `compositionAsSet_card` and `composition_card`). ## Implementation details The main motivation for this structure and its API is in the construction of the composition of formal multilinear series, and the proof that the composition of analytic functions is analytic. The representation of a composition as a list is very handy as lists are very flexible and already have a well-developed API. ## Tags Composition, partition ## References <https://en.wikipedia.org/wiki/Composition_(combinatorics)> -/ open List variable {n : ℕ} /-- A composition of `n` is a list of positive integers summing to `n`. -/ @[ext] structure Composition (n : ℕ) where /-- List of positive integers summing to `n`-/ blocks : List ℕ /-- Proof of positivity for `blocks`-/ blocks_pos : ∀ {i}, i ∈ blocks → 0 < i /-- Proof that `blocks` sums to `n`-/ blocks_sum : blocks.sum = n #align composition Composition /-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure `CompositionAsSet n`. -/ @[ext] structure CompositionAsSet (n : ℕ) where /-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}`-/ boundaries : Finset (Fin n.succ) /-- Proof that `0` is a member of `boundaries`-/ zero_mem : (0 : Fin n.succ) ∈ boundaries /-- Last element of the composition-/ getLast_mem : Fin.last n ∈ boundaries #align composition_as_set CompositionAsSet instance {n : ℕ} : Inhabited (CompositionAsSet n) := ⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩ /-! ### Compositions A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. -/ namespace Composition variable (c : Composition n) instance (n : ℕ) : ToString (Composition n) := ⟨fun c => toString c.blocks⟩ /-- The length of a composition, i.e., the number of blocks in the composition. -/ abbrev length : ℕ := c.blocks.length #align composition.length Composition.length theorem blocks_length : c.blocks.length = c.length := rfl #align composition.blocks_length Composition.blocks_length /-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic functions using compositions, this is the main player. -/ def blocksFun : Fin c.length → ℕ := c.blocks.get #align composition.blocks_fun Composition.blocksFun theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks := ofFn_get _ #align composition.of_fn_blocks_fun Composition.ofFn_blocksFun theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn] #align composition.sum_blocks_fun Composition.sum_blocksFun theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks := get_mem _ _ _ #align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks @[simp] theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i := c.blocks_pos h #align composition.one_le_blocks Composition.one_le_blocks @[simp] theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks.get ⟨i, h⟩ := c.one_le_blocks (get_mem (blocks c) i h) #align composition.one_le_blocks' Composition.one_le_blocks' @[simp] theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks.get ⟨i, h⟩ := c.one_le_blocks' h #align composition.blocks_pos' Composition.blocks_pos' theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i := c.one_le_blocks (c.blocksFun_mem_blocks i) #align composition.one_le_blocks_fun Composition.one_le_blocksFun theorem length_le : c.length ≤ n := by conv_rhs => rw [← c.blocks_sum] exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi #align composition.length_le Composition.length_le theorem length_pos_of_pos (h : 0 < n) : 0 < c.length := by apply length_pos_of_sum_pos convert h exact c.blocks_sum #align composition.length_pos_of_pos Composition.length_pos_of_pos /-- The sum of the sizes of the blocks in a composition up to `i`. -/ def sizeUpTo (i : ℕ) : ℕ := (c.blocks.take i).sum #align composition.size_up_to Composition.sizeUpTo @[simp] theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo] #align composition.size_up_to_zero Composition.sizeUpTo_zero theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by dsimp [sizeUpTo] convert c.blocks_sum exact take_all_of_le h #align composition.size_up_to_of_length_le Composition.sizeUpTo_ofLength_le @[simp] theorem sizeUpTo_length : c.sizeUpTo c.length = n := c.sizeUpTo_ofLength_le c.length le_rfl #align composition.size_up_to_length Composition.sizeUpTo_length theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i] exact Nat.le_add_right _ _ #align composition.size_up_to_le Composition.sizeUpTo_le theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) : c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks.get ⟨i, h⟩ := by simp only [sizeUpTo] rw [sum_take_succ _ _ h] #align composition.size_up_to_succ Composition.sizeUpTo_succ theorem sizeUpTo_succ' (i : Fin c.length) : c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i := c.sizeUpTo_succ i.2 #align composition.size_up_to_succ' Composition.sizeUpTo_succ' theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by rw [c.sizeUpTo_succ h] simp #align composition.size_up_to_strict_mono Composition.sizeUpTo_strict_mono theorem monotone_sizeUpTo : Monotone c.sizeUpTo := monotone_sum_take _ #align composition.monotone_size_up_to Composition.monotone_sizeUpTo /-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundary : Fin (c.length + 1) ↪o Fin (n + 1) := (OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <| Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi #align composition.boundary Composition.boundary @[simp] theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff] #align composition.boundary_zero Composition.boundary_zero @[simp] theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by simp [boundary, Fin.ext_iff] #align composition.boundary_last Composition.boundary_last /-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundaries : Finset (Fin (n + 1)) := Finset.univ.map c.boundary.toEmbedding #align composition.boundaries Composition.boundaries theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries] #align composition.card_boundaries_eq_succ_length Composition.card_boundaries_eq_succ_length /-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost point of each block, and adding a virtual point at the right of the last block. -/ def toCompositionAsSet : CompositionAsSet n where boundaries := c.boundaries zero_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨0, And.intro True.intro rfl⟩ getLast_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩ #align composition.to_composition_as_set Composition.toCompositionAsSet /-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is exactly `c.boundary`. -/ theorem orderEmbOfFin_boundaries : c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by refine (Finset.orderEmbOfFin_unique' _ ?_).symm exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _) #align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries /-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocks_fun i)`) into `Fin n` at the relevant position. -/ def embedding (i : Fin c.length) : Fin (c.blocksFun i) ↪o Fin n := (Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <| calc c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ _).symm _ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2 _ = n := c.sizeUpTo_length #align composition.embedding Composition.embedding @[simp] theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) : (c.embedding i j : ℕ) = c.sizeUpTo i + j := rfl #align composition.coe_embedding Composition.coe_embedding /-- `index_exists` asserts there is some `i` with `j < c.size_up_to (i+1)`. In the next definition `index` we use `Nat.find` to produce the minimal such index. -/ theorem index_exists {j : ℕ} (h : j < n) : ∃ i : ℕ, j < c.sizeUpTo (i + 1) ∧ i < c.length := by have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩ have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos simp [this, h] #align composition.index_exists Composition.index_exists /-- `c.index j` is the index of the block in the composition `c` containing `j`. -/ def index (j : Fin n) : Fin c.length := ⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩ #align composition.index Composition.index theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ := (Nat.find_spec (c.index_exists j.2)).1 #align composition.lt_size_up_to_index_succ Composition.lt_sizeUpTo_index_succ theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≤ j := by by_contra H set i := c.index j push_neg at H have i_pos : (0 : ℕ) < i := by by_contra! i_pos revert H simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero] let i₁ := (i : ℕ).pred have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos) have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos have := Nat.find_min (c.index_exists j.2) i₁_lt_i simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this exact Nat.lt_le_asymm H this #align composition.size_up_to_index_le Composition.sizeUpTo_index_le /-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with `Fin (c.blocks_fun (c.index j))` through the canonical increasing bijection. -/ def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) := ⟨j - c.sizeUpTo (c.index j), by rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ'] · exact lt_sizeUpTo_index_succ _ _ · exact sizeUpTo_index_le _ _⟩ #align composition.inv_embedding Composition.invEmbedding @[simp] theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) := rfl #align composition.coe_inv_embedding Composition.coe_invEmbedding theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by rw [Fin.ext_iff] apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j) #align composition.embedding_comp_inv Composition.embedding_comp_inv theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} : j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≤ j ∧ (j : ℕ) < c.sizeUpTo (i : ℕ).succ := by constructor · intro h rcases Set.mem_range.2 h with ⟨k, hk⟩ rw [Fin.ext_iff] at hk dsimp at hk rw [← hk] simp [sizeUpTo_succ', k.is_lt] · intro h apply Set.mem_range.2 refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩ · rw [tsub_lt_iff_left, ← sizeUpTo_succ'] · exact h.2 · exact h.1 · rw [Fin.ext_iff] exact add_tsub_cancel_of_le h.1 #align composition.mem_range_embedding_iff Composition.mem_range_embedding_iff /-- The embeddings of different blocks of a composition are disjoint. -/ theorem disjoint_range {i₁ i₂ : Fin c.length} (h : i₁ ≠ i₂) : Disjoint (Set.range (c.embedding i₁)) (Set.range (c.embedding i₂)) := by classical wlog h' : i₁ < i₂ · exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm by_contra d obtain ⟨x, hx₁, hx₂⟩ : ∃ x : Fin n, x ∈ Set.range (c.embedding i₁) ∧ x ∈ Set.range (c.embedding i₂) := Set.not_disjoint_iff.1 d have A : (i₁ : ℕ).succ ≤ i₂ := Nat.succ_le_of_lt h' apply lt_irrefl (x : ℕ) calc (x : ℕ) < c.sizeUpTo (i₁ : ℕ).succ := (c.mem_range_embedding_iff.1 hx₁).2 _ ≤ c.sizeUpTo (i₂ : ℕ) := monotone_sum_take _ A _ ≤ x := (c.mem_range_embedding_iff.1 hx₂).1 #align composition.disjoint_range Composition.disjoint_range theorem mem_range_embedding (j : Fin n) : j ∈ Set.range (c.embedding (c.index j)) := by have : c.embedding (c.index j) (c.invEmbedding j) ∈ Set.range (c.embedding (c.index j)) := Set.mem_range_self _ rwa [c.embedding_comp_inv j] at this #align composition.mem_range_embedding Composition.mem_range_embedding theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} : j ∈ Set.range (c.embedding i) ↔ i = c.index j := by constructor · rw [← not_imp_not] intro h exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j) · intro h rw [h] exact c.mem_range_embedding j #align composition.mem_range_embedding_iff' Composition.mem_range_embedding_iff' theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) : c.index (c.embedding i j) = i := by symm rw [← mem_range_embedding_iff'] apply Set.mem_range_self #align composition.index_embedding Composition.index_embedding theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) : (c.invEmbedding (c.embedding i j) : ℕ) = j := by simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left] #align composition.inv_embedding_comp Composition.invEmbedding_comp /-- Equivalence between the disjoint union of the blocks (each of them seen as `Fin (c.blocks_fun i)`) with `Fin n`. -/ def blocksFinEquiv : (Σi : Fin c.length, Fin (c.blocksFun i)) ≃ Fin n where toFun x := c.embedding x.1 x.2 invFun j := ⟨c.index j, c.invEmbedding j⟩ left_inv x := by rcases x with ⟨i, y⟩ dsimp congr; · exact c.index_embedding _ _ rw [Fin.heq_ext_iff] · exact c.invEmbedding_comp _ _ · rw [c.index_embedding] right_inv j := c.embedding_comp_inv j #align composition.blocks_fin_equiv Composition.blocksFinEquiv theorem blocksFun_congr {n₁ n₂ : ℕ} (c₁ : Composition n₁) (c₂ : Composition n₂) (i₁ : Fin c₁.length) (i₂ : Fin c₂.length) (hn : n₁ = n₂) (hc : c₁.blocks = c₂.blocks) (hi : (i₁ : ℕ) = i₂) : c₁.blocksFun i₁ = c₂.blocksFun i₂ := by cases hn rw [← Composition.ext_iff] at hc cases hc congr rwa [Fin.ext_iff] #align composition.blocks_fun_congr Composition.blocksFun_congr /-- Two compositions (possibly of different integers) coincide if and only if they have the same sequence of blocks. -/ theorem sigma_eq_iff_blocks_eq {c : Σn, Composition n} {c' : Σn, Composition n} : c = c' ↔ c.2.blocks = c'.2.blocks := by refine ⟨fun H => by rw [H], fun H => ?_⟩ rcases c with ⟨n, c⟩ rcases c' with ⟨n', c'⟩ have : n = n' := by rw [← c.blocks_sum, ← c'.blocks_sum, H] induction this congr ext1 exact H #align composition.sigma_eq_iff_blocks_eq Composition.sigma_eq_iff_blocks_eq /-! ### The composition `Composition.ones` -/ /-- The composition made of blocks all of size `1`. -/ def ones (n : ℕ) : Composition n := ⟨replicate n (1 : ℕ), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp⟩ #align composition.ones Composition.ones instance {n : ℕ} : Inhabited (Composition n) := ⟨Composition.ones n⟩ @[simp] theorem ones_length (n : ℕ) : (ones n).length = n := List.length_replicate n 1 #align composition.ones_length Composition.ones_length @[simp] theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) := rfl #align composition.ones_blocks Composition.ones_blocks @[simp] theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by simp only [blocksFun, ones, blocks, i.2, List.get_replicate] #align composition.ones_blocks_fun Composition.ones_blocksFun @[simp] theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by simp [sizeUpTo, ones_blocks, take_replicate] #align composition.ones_size_up_to Composition.ones_sizeUpTo @[simp] theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) : (ones n).embedding i ⟨0, h⟩ = ⟨i, lt_of_lt_of_le i.2 (ones n).length_le⟩ := by ext simpa using i.2.le #align composition.ones_embedding Composition.ones_embedding theorem eq_ones_iff {c : Composition n} : c = ones n ↔ ∀ i ∈ c.blocks, i = 1 := by constructor · rintro rfl exact fun i => eq_of_mem_replicate · intro H ext1 have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H have : c.blocks.length = n := by conv_rhs => rw [← c.blocks_sum, A] simp rw [A, this, ones_blocks] #align composition.eq_ones_iff Composition.eq_ones_iff theorem ne_ones_iff {c : Composition n} : c ≠ ones n ↔ ∃ i ∈ c.blocks, 1 < i := by refine (not_congr eq_ones_iff).trans ?_ have : ∀ j ∈ c.blocks, j = 1 ↔ j ≤ 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj] simp (config := { contextual := true }) [this] #align composition.ne_ones_iff Composition.ne_ones_iff theorem eq_ones_iff_length {c : Composition n} : c = ones n ↔ c.length = n := by constructor · rintro rfl exact ones_length n · contrapose intro H length_n apply lt_irrefl n calc n = ∑ i : Fin c.length, 1 := by simp [length_n] _ < ∑ i : Fin c.length, c.blocksFun i := by { obtain ⟨i, hi, i_blocks⟩ : ∃ i ∈ c.blocks, 1 < i := ne_ones_iff.1 H rw [← ofFn_blocksFun, mem_ofFn c.blocksFun, Set.mem_range] at hi obtain ⟨j : Fin c.length, hj : c.blocksFun j = i⟩ := hi rw [← hj] at i_blocks exact Finset.sum_lt_sum (fun i _ => one_le_blocksFun c i) ⟨j, Finset.mem_univ _, i_blocks⟩ } _ = n := c.sum_blocksFun #align composition.eq_ones_iff_length Composition.eq_ones_iff_length theorem eq_ones_iff_le_length {c : Composition n} : c = ones n ↔ n ≤ c.length := by simp [eq_ones_iff_length, le_antisymm_iff, c.length_le] #align composition.eq_ones_iff_le_length Composition.eq_ones_iff_le_length /-! ### The composition `Composition.single` -/ /-- The composition made of a single block of size `n`. -/ def single (n : ℕ) (h : 0 < n) : Composition n := ⟨[n], by simp [h], by simp⟩ #align composition.single Composition.single @[simp] theorem single_length {n : ℕ} (h : 0 < n) : (single n h).length = 1 := rfl #align composition.single_length Composition.single_length @[simp] theorem single_blocks {n : ℕ} (h : 0 < n) : (single n h).blocks = [n] := rfl #align composition.single_blocks Composition.single_blocks @[simp] theorem single_blocksFun {n : ℕ} (h : 0 < n) (i : Fin (single n h).length) : (single n h).blocksFun i = n := by simp [blocksFun, single, blocks, i.2] #align composition.single_blocks_fun Composition.single_blocksFun @[simp] theorem single_embedding {n : ℕ} (h : 0 < n) (i : Fin n) : ((single n h).embedding (0 : Fin 1)) i = i := by ext simp #align composition.single_embedding Composition.single_embedding
Mathlib/Combinatorics/Enumerative/Composition.lean
577
588
theorem eq_single_iff_length {n : ℕ} (h : 0 < n) {c : Composition n} : c = single n h ↔ c.length = 1 := by
constructor · intro H rw [H] exact single_length h · intro H ext1 have A : c.blocks.length = 1 := H ▸ c.blocks_length have B : c.blocks.sum = n := c.blocks_sum rw [eq_cons_of_length_one A] at B ⊢ simpa [single_blocks] using B
/- 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.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Measure.MutuallySingular import Mathlib.MeasureTheory.Measure.Count import Mathlib.Topology.IndicatorConstPointwise import Mathlib.MeasureTheory.Constructions.BorelSpace.Real #align_import measure_theory.integral.lebesgue from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Lower Lebesgue integral for `ℝ≥0∞`-valued functions We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function. ## Notation We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`. * `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`; * `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure `volume` on `α`; * `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`; * `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`. -/ assert_not_exists NormedSpace set_option autoImplicit true noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc variable {α β γ δ : Type*} section Lintegral open SimpleFunc variable {m : MeasurableSpace α} {μ ν : Measure α} /-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/ irreducible_def lintegral {_ : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ := ⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ #align measure_theory.lintegral MeasureTheory.lintegral /-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫⁻ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = f.lintegral μ := by rw [MeasureTheory.lintegral] exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl) (le_iSup₂_of_le f le_rfl le_rfl) #align measure_theory.simple_func.lintegral_eq_lintegral MeasureTheory.SimpleFunc.lintegral_eq_lintegral @[mono] theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by rw [lintegral, lintegral] exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩ #align measure_theory.lintegral_mono' MeasureTheory.lintegral_mono' -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn' ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) (h2 : μ ≤ ν) : lintegral μ f ≤ lintegral ν g := lintegral_mono' h2 hfg theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono' (le_refl μ) hfg #align measure_theory.lintegral_mono MeasureTheory.lintegral_mono -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : lintegral μ f ≤ lintegral μ g := lintegral_mono hfg theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a) #align measure_theory.lintegral_mono_nnreal MeasureTheory.lintegral_mono_nnreal theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) : ⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by apply le_antisymm · exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i · rw [lintegral] refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_ exact le_of_eq (i.lintegral_eq_lintegral _).symm #align measure_theory.supr_lintegral_measurable_le_eq_lintegral MeasureTheory.iSup_lintegral_measurable_le_eq_lintegral theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set MeasureTheory.lintegral_mono_set theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set' MeasureTheory.lintegral_mono_set' theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) := lintegral_mono #align measure_theory.monotone_lintegral MeasureTheory.monotone_lintegral @[simp] theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const] rfl #align measure_theory.lintegral_const MeasureTheory.lintegral_const theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp #align measure_theory.lintegral_zero MeasureTheory.lintegral_zero theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 := lintegral_zero #align measure_theory.lintegral_zero_fun MeasureTheory.lintegral_zero_fun -- @[simp] -- Porting note (#10618): simp can prove this theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul] #align measure_theory.lintegral_one MeasureTheory.lintegral_one theorem set_lintegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by rw [lintegral_const, Measure.restrict_apply_univ] #align measure_theory.set_lintegral_const MeasureTheory.set_lintegral_const theorem set_lintegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [set_lintegral_const, one_mul] #align measure_theory.set_lintegral_one MeasureTheory.set_lintegral_one theorem set_lintegral_const_lt_top [IsFiniteMeasure μ] (s : Set α) {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _ in s, c ∂μ < ∞ := by rw [lintegral_const] exact ENNReal.mul_lt_top hc (measure_ne_top (μ.restrict s) univ) #align measure_theory.set_lintegral_const_lt_top MeasureTheory.set_lintegral_const_lt_top theorem lintegral_const_lt_top [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _, c ∂μ < ∞ := by simpa only [Measure.restrict_univ] using set_lintegral_const_lt_top (univ : Set α) hc #align measure_theory.lintegral_const_lt_top MeasureTheory.lintegral_const_lt_top section variable (μ) /-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same integral. -/ theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) : ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀ · exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩ rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩ have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by intro n simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using (hLf n).2 choose g hgm hgf hLg using this refine ⟨fun x => ⨆ n, g n x, measurable_iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩ · refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_ exact le_iSup (fun n => g n x) n · exact lintegral_mono fun x => iSup_le fun n => hgf n x #align measure_theory.exists_measurable_le_lintegral_eq MeasureTheory.exists_measurable_le_lintegral_eq end /-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions `φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take functions `φ : α →ₛ ℝ≥0`. -/ theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = ⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by rw [lintegral] refine le_antisymm (iSup₂_le fun φ hφ => ?_) (iSup_mono' fun φ => ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩) by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞ · let ψ := φ.map ENNReal.toNNReal replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x) exact le_iSup_of_le (φ.map ENNReal.toNNReal) (le_iSup_of_le this (ge_of_eq <| lintegral_congr h)) · have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_nmem.1 h refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_) obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb) use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞}) simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const, ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast, restrict_const_lintegral] refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩ simp only [mem_preimage, mem_singleton_iff] at hx simp only [hx, le_top] #align measure_theory.lintegral_eq_nnreal MeasureTheory.lintegral_eq_nnreal theorem exists_simpleFunc_forall_lintegral_sub_lt_of_pos {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ φ : α →ₛ ℝ≥0, (∀ x, ↑(φ x) ≤ f x) ∧ ∀ ψ : α →ₛ ℝ≥0, (∀ x, ↑(ψ x) ≤ f x) → (map (↑) (ψ - φ)).lintegral μ < ε := by rw [lintegral_eq_nnreal] at h have := ENNReal.lt_add_right h hε erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => zero_le _⟩] simp_rw [lt_iSup_iff, iSup_lt_iff, iSup_le_iff] at this rcases this with ⟨φ, hle : ∀ x, ↑(φ x) ≤ f x, b, hbφ, hb⟩ refine ⟨φ, hle, fun ψ hψ => ?_⟩ have : (map (↑) φ).lintegral μ ≠ ∞ := ne_top_of_le_ne_top h (by exact le_iSup₂ (α := ℝ≥0∞) φ hle) rw [← ENNReal.add_lt_add_iff_left this, ← add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine (hb _ fun x => le_trans ?_ (max_le (hle x) (hψ x))).trans_lt hbφ norm_cast simp only [add_apply, sub_apply, add_tsub_eq_max] rfl #align measure_theory.exists_simple_func_forall_lintegral_sub_lt_of_pos MeasureTheory.exists_simpleFunc_forall_lintegral_sub_lt_of_pos theorem iSup_lintegral_le {ι : Sort*} (f : ι → α → ℝ≥0∞) : ⨆ i, ∫⁻ a, f i a ∂μ ≤ ∫⁻ a, ⨆ i, f i a ∂μ := by simp only [← iSup_apply] exact (monotone_lintegral μ).le_map_iSup #align measure_theory.supr_lintegral_le MeasureTheory.iSup_lintegral_le theorem iSup₂_lintegral_le {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ⨆ (i) (j), ∫⁻ a, f i j a ∂μ ≤ ∫⁻ a, ⨆ (i) (j), f i j a ∂μ := by convert (monotone_lintegral μ).le_map_iSup₂ f with a simp only [iSup_apply] #align measure_theory.supr₂_lintegral_le MeasureTheory.iSup₂_lintegral_le theorem le_iInf_lintegral {ι : Sort*} (f : ι → α → ℝ≥0∞) : ∫⁻ a, ⨅ i, f i a ∂μ ≤ ⨅ i, ∫⁻ a, f i a ∂μ := by simp only [← iInf_apply] exact (monotone_lintegral μ).map_iInf_le #align measure_theory.le_infi_lintegral MeasureTheory.le_iInf_lintegral theorem le_iInf₂_lintegral {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ∫⁻ a, ⨅ (i) (h : ι' i), f i h a ∂μ ≤ ⨅ (i) (h : ι' i), ∫⁻ a, f i h a ∂μ := by convert (monotone_lintegral μ).map_iInf₂_le f with a simp only [iInf_apply] #align measure_theory.le_infi₂_lintegral MeasureTheory.le_iInf₂_lintegral theorem lintegral_mono_ae {f g : α → ℝ≥0∞} (h : ∀ᵐ a ∂μ, f a ≤ g a) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_superset_of_null h with ⟨t, hts, ht, ht0⟩ have : ∀ᵐ x ∂μ, x ∉ t := measure_zero_iff_ae_nmem.1 ht0 rw [lintegral, lintegral] refine iSup_le fun s => iSup_le fun hfs => le_iSup_of_le (s.restrict tᶜ) <| le_iSup_of_le ?_ ?_ · intro a by_cases h : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, h, not_true, not_false_eq_true, indicator_of_not_mem, zero_le, not_false_eq_true, indicator_of_mem] exact le_trans (hfs a) (_root_.by_contradiction fun hnfg => h (hts hnfg)) · refine le_of_eq (SimpleFunc.lintegral_congr <| this.mono fun a hnt => ?_) by_cases hat : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, hat, not_true, not_false_eq_true, indicator_of_not_mem, not_false_eq_true, indicator_of_mem] exact (hnt hat).elim #align measure_theory.lintegral_mono_ae MeasureTheory.lintegral_mono_ae theorem set_lintegral_mono_ae {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff <| measurableSet_le hf hg).2 hfg #align measure_theory.set_lintegral_mono_ae MeasureTheory.set_lintegral_mono_ae theorem set_lintegral_mono {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae hf hg (ae_of_all _ hfg) #align measure_theory.set_lintegral_mono MeasureTheory.set_lintegral_mono theorem set_lintegral_mono_ae' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff' hs).2 hfg theorem set_lintegral_mono' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae' hs (ae_of_all _ hfg) theorem set_lintegral_le_lintegral (s : Set α) (f : α → ℝ≥0∞) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl theorem lintegral_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := le_antisymm (lintegral_mono_ae <| h.le) (lintegral_mono_ae <| h.symm.le) #align measure_theory.lintegral_congr_ae MeasureTheory.lintegral_congr_ae theorem lintegral_congr {f g : α → ℝ≥0∞} (h : ∀ a, f a = g a) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by simp only [h] #align measure_theory.lintegral_congr MeasureTheory.lintegral_congr theorem set_lintegral_congr {f : α → ℝ≥0∞} {s t : Set α} (h : s =ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := by rw [Measure.restrict_congr_set h] #align measure_theory.set_lintegral_congr MeasureTheory.set_lintegral_congr theorem set_lintegral_congr_fun {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := by rw [lintegral_congr_ae] rw [EventuallyEq] rwa [ae_restrict_iff' hs] #align measure_theory.set_lintegral_congr_fun MeasureTheory.set_lintegral_congr_fun theorem lintegral_ofReal_le_lintegral_nnnorm (f : α → ℝ) : ∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [← ofReal_norm_eq_coe_nnnorm] refine lintegral_mono fun x => ENNReal.ofReal_le_ofReal ?_ rw [Real.norm_eq_abs] exact le_abs_self (f x) #align measure_theory.lintegral_of_real_le_lintegral_nnnorm MeasureTheory.lintegral_ofReal_le_lintegral_nnnorm theorem lintegral_nnnorm_eq_of_ae_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ᵐ[μ] f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by apply lintegral_congr_ae filter_upwards [h_nonneg] with x hx rw [Real.nnnorm_of_nonneg hx, ENNReal.ofReal_eq_coe_nnreal hx] #align measure_theory.lintegral_nnnorm_eq_of_ae_nonneg MeasureTheory.lintegral_nnnorm_eq_of_ae_nonneg theorem lintegral_nnnorm_eq_of_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := lintegral_nnnorm_eq_of_ae_nonneg (Filter.eventually_of_forall h_nonneg) #align measure_theory.lintegral_nnnorm_eq_of_nonneg MeasureTheory.lintegral_nnnorm_eq_of_nonneg /-- **Monotone convergence theorem** -- sometimes called **Beppo-Levi convergence**. See `lintegral_iSup_directed` for a more general form. -/ theorem lintegral_iSup {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : Monotone f) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by set c : ℝ≥0 → ℝ≥0∞ := (↑) set F := fun a : α => ⨆ n, f n a refine le_antisymm ?_ (iSup_lintegral_le _) rw [lintegral_eq_nnreal] refine iSup_le fun s => iSup_le fun hsf => ?_ refine ENNReal.le_of_forall_lt_one_mul_le fun a ha => ?_ rcases ENNReal.lt_iff_exists_coe.1 ha with ⟨r, rfl, _⟩ have ha : r < 1 := ENNReal.coe_lt_coe.1 ha let rs := s.map fun a => r * a have eq_rs : rs.map c = (const α r : α →ₛ ℝ≥0∞) * map c s := rfl have eq : ∀ p, rs.map c ⁻¹' {p} = ⋃ n, rs.map c ⁻¹' {p} ∩ { a | p ≤ f n a } := by intro p rw [← inter_iUnion]; nth_rw 1 [← inter_univ (map c rs ⁻¹' {p})] refine Set.ext fun x => and_congr_right fun hx => true_iff_iff.2 ?_ by_cases p_eq : p = 0 · simp [p_eq] simp only [coe_map, mem_preimage, Function.comp_apply, mem_singleton_iff] at hx subst hx have : r * s x ≠ 0 := by rwa [Ne, ← ENNReal.coe_eq_zero] have : s x ≠ 0 := right_ne_zero_of_mul this have : (rs.map c) x < ⨆ n : ℕ, f n x := by refine lt_of_lt_of_le (ENNReal.coe_lt_coe.2 ?_) (hsf x) suffices r * s x < 1 * s x by simpa exact mul_lt_mul_of_pos_right ha (pos_iff_ne_zero.2 this) rcases lt_iSup_iff.1 this with ⟨i, hi⟩ exact mem_iUnion.2 ⟨i, le_of_lt hi⟩ have mono : ∀ r : ℝ≥0∞, Monotone fun n => rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a } := by intro r i j h refine inter_subset_inter_right _ ?_ simp_rw [subset_def, mem_setOf] intro x hx exact le_trans hx (h_mono h x) have h_meas : ∀ n, MeasurableSet {a : α | map c rs a ≤ f n a} := fun n => measurableSet_le (SimpleFunc.measurable _) (hf n) calc (r : ℝ≥0∞) * (s.map c).lintegral μ = ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r}) := by rw [← const_mul_lintegral, eq_rs, SimpleFunc.lintegral] _ = ∑ r ∈ (rs.map c).range, r * μ (⋃ n, rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by simp only [(eq _).symm] _ = ∑ r ∈ (rs.map c).range, ⨆ n, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := (Finset.sum_congr rfl fun x _ => by rw [measure_iUnion_eq_iSup (mono x).directed_le, ENNReal.mul_iSup]) _ = ⨆ n, ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by refine ENNReal.finset_sum_iSup_nat fun p i j h ↦ ?_ gcongr _ * μ ?_ exact mono p h _ ≤ ⨆ n : ℕ, ((rs.map c).restrict { a | (rs.map c) a ≤ f n a }).lintegral μ := by gcongr with n rw [restrict_lintegral _ (h_meas n)] refine le_of_eq (Finset.sum_congr rfl fun r _ => ?_) congr 2 with a refine and_congr_right ?_ simp (config := { contextual := true }) _ ≤ ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [← SimpleFunc.lintegral_eq_lintegral] gcongr with n a simp only [map_apply] at h_meas simp only [coe_map, restrict_apply _ (h_meas _), (· ∘ ·)] exact indicator_apply_le id #align measure_theory.lintegral_supr MeasureTheory.lintegral_iSup /-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence. Version with ae_measurable functions. -/ theorem lintegral_iSup' {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iSup_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Monotone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_mono have h_ae_seq_mono : Monotone (aeSeq hf p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet hf p · exact aeSeq.prop_of_mem_aeSeqSet hf hx hnm · simp only [aeSeq, hx, if_false, le_rfl] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] simp_rw [iSup_apply] rw [lintegral_iSup (aeSeq.measurable hf p) h_ae_seq_mono] congr with n exact lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae hf hp n) #align measure_theory.lintegral_supr' MeasureTheory.lintegral_iSup' /-- Monotone convergence theorem expressed with limits -/ theorem lintegral_tendsto_of_tendsto_of_monotone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 <| F x)) : Tendsto (fun n => ∫⁻ x, f n x ∂μ) atTop (𝓝 <| ∫⁻ x, F x ∂μ) := by have : Monotone fun n => ∫⁻ x, f n x ∂μ := fun i j hij => lintegral_mono_ae (h_mono.mono fun x hx => hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨆ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iSup this rw [← lintegral_iSup' hf h_mono] refine lintegral_congr_ae ?_ filter_upwards [h_mono, h_tendsto] with _ hx_mono hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iSup hx_mono) #align measure_theory.lintegral_tendsto_of_tendsto_of_monotone MeasureTheory.lintegral_tendsto_of_tendsto_of_monotone theorem lintegral_eq_iSup_eapprox_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = ⨆ n, (eapprox f n).lintegral μ := calc ∫⁻ a, f a ∂μ = ∫⁻ a, ⨆ n, (eapprox f n : α → ℝ≥0∞) a ∂μ := by congr; ext a; rw [iSup_eapprox_apply f hf] _ = ⨆ n, ∫⁻ a, (eapprox f n : α → ℝ≥0∞) a ∂μ := by apply lintegral_iSup · measurability · intro i j h exact monotone_eapprox f h _ = ⨆ n, (eapprox f n).lintegral μ := by congr; ext n; rw [(eapprox f n).lintegral_eq_lintegral] #align measure_theory.lintegral_eq_supr_eapprox_lintegral MeasureTheory.lintegral_eq_iSup_eapprox_lintegral /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. This lemma states this fact in terms of `ε` and `δ`. -/ theorem exists_pos_set_lintegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ δ > 0, ∀ s, μ s < δ → ∫⁻ x in s, f x ∂μ < ε := by rcases exists_between (pos_iff_ne_zero.mpr hε) with ⟨ε₂, hε₂0, hε₂ε⟩ rcases exists_between hε₂0 with ⟨ε₁, hε₁0, hε₁₂⟩ rcases exists_simpleFunc_forall_lintegral_sub_lt_of_pos h hε₁0.ne' with ⟨φ, _, hφ⟩ rcases φ.exists_forall_le with ⟨C, hC⟩ use (ε₂ - ε₁) / C, ENNReal.div_pos_iff.2 ⟨(tsub_pos_iff_lt.2 hε₁₂).ne', ENNReal.coe_ne_top⟩ refine fun s hs => lt_of_le_of_lt ?_ hε₂ε simp only [lintegral_eq_nnreal, iSup_le_iff] intro ψ hψ calc (map (↑) ψ).lintegral (μ.restrict s) ≤ (map (↑) φ).lintegral (μ.restrict s) + (map (↑) (ψ - φ)).lintegral (μ.restrict s) := by rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine SimpleFunc.lintegral_mono (fun x => ?_) le_rfl simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add, SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)] _ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by gcongr refine le_trans ?_ (hφ _ hψ).le exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self _ ≤ (SimpleFunc.const α (C : ℝ≥0∞)).lintegral (μ.restrict s) + ε₁ := by gcongr exact SimpleFunc.lintegral_mono (fun x ↦ ENNReal.coe_le_coe.2 (hC x)) le_rfl _ = C * μ s + ε₁ := by simp only [← SimpleFunc.lintegral_eq_lintegral, coe_const, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, Function.const] _ ≤ C * ((ε₂ - ε₁) / C) + ε₁ := by gcongr _ ≤ ε₂ - ε₁ + ε₁ := by gcongr; apply mul_div_le _ = ε₂ := tsub_add_cancel_of_le hε₁₂.le #align measure_theory.exists_pos_set_lintegral_lt_of_measure_lt MeasureTheory.exists_pos_set_lintegral_lt_of_measure_lt /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem tendsto_set_lintegral_zero {ι} {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {l : Filter ι} {s : ι → Set α} (hl : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫⁻ x in s i, f x ∂μ) l (𝓝 0) := by simp only [ENNReal.nhds_zero, tendsto_iInf, tendsto_principal, mem_Iio, ← pos_iff_ne_zero] at hl ⊢ intro ε ε0 rcases exists_pos_set_lintegral_lt_of_measure_lt h ε0.ne' with ⟨δ, δ0, hδ⟩ exact (hl δ δ0).mono fun i => hδ _ #align measure_theory.tendsto_set_lintegral_zero MeasureTheory.tendsto_set_lintegral_zero /-- The sum of the lower Lebesgue integrals of two functions is less than or equal to the integral of their sum. The other inequality needs one of these functions to be (a.e.-)measurable. -/ theorem le_lintegral_add (f g : α → ℝ≥0∞) : ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ ≤ ∫⁻ a, f a + g a ∂μ := by simp only [lintegral] refine ENNReal.biSup_add_biSup_le' (p := fun h : α →ₛ ℝ≥0∞ => h ≤ f) (q := fun h : α →ₛ ℝ≥0∞ => h ≤ g) ⟨0, zero_le f⟩ ⟨0, zero_le g⟩ fun f' hf' g' hg' => ?_ exact le_iSup₂_of_le (f' + g') (add_le_add hf' hg') (add_lintegral _ _).ge #align measure_theory.le_lintegral_add MeasureTheory.le_lintegral_add -- Use stronger lemmas `lintegral_add_left`/`lintegral_add_right` instead theorem lintegral_add_aux {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, (⨆ n, (eapprox f n : α → ℝ≥0∞) a) + ⨆ n, (eapprox g n : α → ℝ≥0∞) a ∂μ := by simp only [iSup_eapprox_apply, hf, hg] _ = ∫⁻ a, ⨆ n, (eapprox f n + eapprox g n : α → ℝ≥0∞) a ∂μ := by congr; funext a rw [ENNReal.iSup_add_iSup_of_monotone] · simp only [Pi.add_apply] · intro i j h exact monotone_eapprox _ h a · intro i j h exact monotone_eapprox _ h a _ = ⨆ n, (eapprox f n).lintegral μ + (eapprox g n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.add_lintegral, ← SimpleFunc.lintegral_eq_lintegral] simp only [Pi.add_apply, SimpleFunc.coe_add] · measurability · intro i j h a dsimp gcongr <;> exact monotone_eapprox _ h _ _ = (⨆ n, (eapprox f n).lintegral μ) + ⨆ n, (eapprox g n).lintegral μ := by refine (ENNReal.iSup_add_iSup_of_monotone ?_ ?_).symm <;> · intro i j h exact SimpleFunc.lintegral_mono (monotone_eapprox _ h) le_rfl _ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral hg] #align measure_theory.lintegral_add_aux MeasureTheory.lintegral_add_aux /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `f` is integrable, see also `MeasureTheory.lintegral_add_right` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by refine le_antisymm ?_ (le_lintegral_add _ _) rcases exists_measurable_le_lintegral_eq μ fun a => f a + g a with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, φ a ∂μ := hφ_eq _ ≤ ∫⁻ a, f a + (φ a - f a) ∂μ := lintegral_mono fun a => le_add_tsub _ = ∫⁻ a, f a ∂μ + ∫⁻ a, φ a - f a ∂μ := lintegral_add_aux hf (hφm.sub hf) _ ≤ ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := add_le_add_left (lintegral_mono fun a => tsub_le_iff_left.2 <| hφ_le a) _ #align measure_theory.lintegral_add_left MeasureTheory.lintegral_add_left theorem lintegral_add_left' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_congr_ae hf.ae_eq_mk, ← lintegral_add_left hf.measurable_mk, lintegral_congr_ae (hf.ae_eq_mk.add (ae_eq_refl g))] #align measure_theory.lintegral_add_left' MeasureTheory.lintegral_add_left' theorem lintegral_add_right' (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by simpa only [add_comm] using lintegral_add_left' hg f #align measure_theory.lintegral_add_right' MeasureTheory.lintegral_add_right' /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `g` is integrable, see also `MeasureTheory.lintegral_add_left` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := lintegral_add_right' f hg.aemeasurable #align measure_theory.lintegral_add_right MeasureTheory.lintegral_add_right @[simp] theorem lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂c • μ = c * ∫⁻ a, f a ∂μ := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_smul, ENNReal.mul_iSup, smul_eq_mul] #align measure_theory.lintegral_smul_measure MeasureTheory.lintegral_smul_measure lemma set_lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂(c • μ) = c * ∫⁻ a in s, f a ∂μ := by rw [Measure.restrict_smul, lintegral_smul_measure] @[simp] theorem lintegral_sum_measure {m : MeasurableSpace α} {ι} (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂Measure.sum μ = ∑' i, ∫⁻ a, f a ∂μ i := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_sum, ENNReal.tsum_eq_iSup_sum] rw [iSup_comm] congr; funext s induction' s using Finset.induction_on with i s hi hs · simp simp only [Finset.sum_insert hi, ← hs] refine (ENNReal.iSup_add_iSup ?_).symm intro φ ψ exact ⟨⟨φ ⊔ ψ, fun x => sup_le (φ.2 x) (ψ.2 x)⟩, add_le_add (SimpleFunc.lintegral_mono le_sup_left le_rfl) (Finset.sum_le_sum fun j _ => SimpleFunc.lintegral_mono le_sup_right le_rfl)⟩ #align measure_theory.lintegral_sum_measure MeasureTheory.lintegral_sum_measure theorem hasSum_lintegral_measure {ι} {_ : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : ι → Measure α) : HasSum (fun i => ∫⁻ a, f a ∂μ i) (∫⁻ a, f a ∂Measure.sum μ) := (lintegral_sum_measure f μ).symm ▸ ENNReal.summable.hasSum #align measure_theory.has_sum_lintegral_measure MeasureTheory.hasSum_lintegral_measure @[simp] theorem lintegral_add_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ ν : Measure α) : ∫⁻ a, f a ∂(μ + ν) = ∫⁻ a, f a ∂μ + ∫⁻ a, f a ∂ν := by simpa [tsum_fintype] using lintegral_sum_measure f fun b => cond b μ ν #align measure_theory.lintegral_add_measure MeasureTheory.lintegral_add_measure @[simp] theorem lintegral_finset_sum_measure {ι} {m : MeasurableSpace α} (s : Finset ι) (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫⁻ a, f a ∂μ i := by rw [← Measure.sum_coe_finset, lintegral_sum_measure, ← Finset.tsum_subtype'] simp only [Finset.coe_sort_coe] #align measure_theory.lintegral_finset_sum_measure MeasureTheory.lintegral_finset_sum_measure @[simp] theorem lintegral_zero_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂(0 : Measure α) = 0 := by simp [lintegral] #align measure_theory.lintegral_zero_measure MeasureTheory.lintegral_zero_measure @[simp] theorem lintegral_of_isEmpty {α} [MeasurableSpace α] [IsEmpty α] (μ : Measure α) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = 0 := by have : Subsingleton (Measure α) := inferInstance convert lintegral_zero_measure f theorem set_lintegral_empty (f : α → ℝ≥0∞) : ∫⁻ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, lintegral_zero_measure] #align measure_theory.set_lintegral_empty MeasureTheory.set_lintegral_empty theorem set_lintegral_univ (f : α → ℝ≥0∞) : ∫⁻ x in univ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [Measure.restrict_univ] #align measure_theory.set_lintegral_univ MeasureTheory.set_lintegral_univ theorem set_lintegral_measure_zero (s : Set α) (f : α → ℝ≥0∞) (hs' : μ s = 0) : ∫⁻ x in s, f x ∂μ = 0 := by convert lintegral_zero_measure _ exact Measure.restrict_eq_zero.2 hs' #align measure_theory.set_lintegral_measure_zero MeasureTheory.set_lintegral_measure_zero theorem lintegral_finset_sum' (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, AEMeasurable (f b) μ) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := by induction' s using Finset.induction_on with a s has ih · simp · simp only [Finset.sum_insert has] rw [Finset.forall_mem_insert] at hf rw [lintegral_add_left' hf.1, ih hf.2] #align measure_theory.lintegral_finset_sum' MeasureTheory.lintegral_finset_sum' theorem lintegral_finset_sum (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, Measurable (f b)) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := lintegral_finset_sum' s fun b hb => (hf b hb).aemeasurable #align measure_theory.lintegral_finset_sum MeasureTheory.lintegral_finset_sum @[simp] theorem lintegral_const_mul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := calc ∫⁻ a, r * f a ∂μ = ∫⁻ a, ⨆ n, (const α r * eapprox f n) a ∂μ := by congr funext a rw [← iSup_eapprox_apply f hf, ENNReal.mul_iSup] simp _ = ⨆ n, r * (eapprox f n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.const_mul_lintegral, ← SimpleFunc.lintegral_eq_lintegral] · intro n exact SimpleFunc.measurable _ · intro i j h a exact mul_le_mul_left' (monotone_eapprox _ h _) _ _ = r * ∫⁻ a, f a ∂μ := by rw [← ENNReal.mul_iSup, lintegral_eq_iSup_eapprox_lintegral hf] #align measure_theory.lintegral_const_mul MeasureTheory.lintegral_const_mul theorem lintegral_const_mul'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by have A : ∫⁻ a, f a ∂μ = ∫⁻ a, hf.mk f a ∂μ := lintegral_congr_ae hf.ae_eq_mk have B : ∫⁻ a, r * f a ∂μ = ∫⁻ a, r * hf.mk f a ∂μ := lintegral_congr_ae (EventuallyEq.fun_comp hf.ae_eq_mk _) rw [A, B, lintegral_const_mul _ hf.measurable_mk] #align measure_theory.lintegral_const_mul'' MeasureTheory.lintegral_const_mul'' theorem lintegral_const_mul_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : r * ∫⁻ a, f a ∂μ ≤ ∫⁻ a, r * f a ∂μ := by rw [lintegral, ENNReal.mul_iSup] refine iSup_le fun s => ?_ rw [ENNReal.mul_iSup, iSup_le_iff] intro hs rw [← SimpleFunc.const_mul_lintegral, lintegral] refine le_iSup_of_le (const α r * s) (le_iSup_of_le (fun x => ?_) le_rfl) exact mul_le_mul_left' (hs x) _ #align measure_theory.lintegral_const_mul_le MeasureTheory.lintegral_const_mul_le theorem lintegral_const_mul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by by_cases h : r = 0 · simp [h] apply le_antisymm _ (lintegral_const_mul_le r f) have rinv : r * r⁻¹ = 1 := ENNReal.mul_inv_cancel h hr have rinv' : r⁻¹ * r = 1 := by rw [mul_comm] exact rinv have := lintegral_const_mul_le (μ := μ) r⁻¹ fun x => r * f x simp? [(mul_assoc _ _ _).symm, rinv'] at this says simp only [(mul_assoc _ _ _).symm, rinv', one_mul] at this simpa [(mul_assoc _ _ _).symm, rinv] using mul_le_mul_left' this r #align measure_theory.lintegral_const_mul' MeasureTheory.lintegral_const_mul' theorem lintegral_mul_const (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul r hf] #align measure_theory.lintegral_mul_const MeasureTheory.lintegral_mul_const theorem lintegral_mul_const'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul'' r hf] #align measure_theory.lintegral_mul_const'' MeasureTheory.lintegral_mul_const'' theorem lintegral_mul_const_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (∫⁻ a, f a ∂μ) * r ≤ ∫⁻ a, f a * r ∂μ := by simp_rw [mul_comm, lintegral_const_mul_le r f] #align measure_theory.lintegral_mul_const_le MeasureTheory.lintegral_mul_const_le theorem lintegral_mul_const' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul' r f hr] #align measure_theory.lintegral_mul_const' MeasureTheory.lintegral_mul_const' /- A double integral of a product where each factor contains only one variable is a product of integrals -/ theorem lintegral_lintegral_mul {β} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g ν) : ∫⁻ x, ∫⁻ y, f x * g y ∂ν ∂μ = (∫⁻ x, f x ∂μ) * ∫⁻ y, g y ∂ν := by simp [lintegral_const_mul'' _ hg, lintegral_mul_const'' _ hf] #align measure_theory.lintegral_lintegral_mul MeasureTheory.lintegral_lintegral_mul -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₁ {f f' : α → β} (h : f =ᵐ[μ] f') (g : β → ℝ≥0∞) : ∫⁻ a, g (f a) ∂μ = ∫⁻ a, g (f' a) ∂μ := lintegral_congr_ae <| h.mono fun a h => by dsimp only; rw [h] #align measure_theory.lintegral_rw₁ MeasureTheory.lintegral_rw₁ -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₂ {f₁ f₁' : α → β} {f₂ f₂' : α → γ} (h₁ : f₁ =ᵐ[μ] f₁') (h₂ : f₂ =ᵐ[μ] f₂') (g : β → γ → ℝ≥0∞) : ∫⁻ a, g (f₁ a) (f₂ a) ∂μ = ∫⁻ a, g (f₁' a) (f₂' a) ∂μ := lintegral_congr_ae <| h₁.mp <| h₂.mono fun _ h₂ h₁ => by dsimp only; rw [h₁, h₂] #align measure_theory.lintegral_rw₂ MeasureTheory.lintegral_rw₂ theorem lintegral_indicator_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a, s.indicator f a ∂μ ≤ ∫⁻ a in s, f a ∂μ := by simp only [lintegral] apply iSup_le (fun g ↦ (iSup_le (fun hg ↦ ?_))) have : g ≤ f := hg.trans (indicator_le_self s f) refine le_iSup_of_le g (le_iSup_of_le this (le_of_eq ?_)) rw [lintegral_restrict, SimpleFunc.lintegral] congr with t by_cases H : t = 0 · simp [H] congr with x simp only [mem_preimage, mem_singleton_iff, mem_inter_iff, iff_self_and] rintro rfl contrapose! H simpa [H] using hg x @[simp] theorem lintegral_indicator (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by apply le_antisymm (lintegral_indicator_le f s) simp only [lintegral, ← restrict_lintegral_eq_lintegral_restrict _ hs, iSup_subtype'] refine iSup_mono' (Subtype.forall.2 fun φ hφ => ?_) refine ⟨⟨φ.restrict s, fun x => ?_⟩, le_rfl⟩ simp [hφ x, hs, indicator_le_indicator] #align measure_theory.lintegral_indicator MeasureTheory.lintegral_indicator theorem lintegral_indicator₀ (f : α → ℝ≥0∞) {s : Set α} (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by rw [← lintegral_congr_ae (indicator_ae_eq_of_ae_eq_set hs.toMeasurable_ae_eq), lintegral_indicator _ (measurableSet_toMeasurable _ _), Measure.restrict_congr_set hs.toMeasurable_ae_eq] #align measure_theory.lintegral_indicator₀ MeasureTheory.lintegral_indicator₀ theorem lintegral_indicator_const_le (s : Set α) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ ≤ c * μ s := (lintegral_indicator_le _ _).trans (set_lintegral_const s c).le theorem lintegral_indicator_const₀ {s : Set α} (hs : NullMeasurableSet s μ) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := by rw [lintegral_indicator₀ _ hs, set_lintegral_const] theorem lintegral_indicator_const {s : Set α} (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := lintegral_indicator_const₀ hs.nullMeasurableSet c #align measure_theory.lintegral_indicator_const MeasureTheory.lintegral_indicator_const theorem set_lintegral_eq_const {f : α → ℝ≥0∞} (hf : Measurable f) (r : ℝ≥0∞) : ∫⁻ x in { x | f x = r }, f x ∂μ = r * μ { x | f x = r } := by have : ∀ᵐ x ∂μ, x ∈ { x | f x = r } → f x = r := ae_of_all μ fun _ hx => hx rw [set_lintegral_congr_fun _ this] · rw [lintegral_const, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter] · exact hf (measurableSet_singleton r) #align measure_theory.set_lintegral_eq_const MeasureTheory.set_lintegral_eq_const theorem lintegral_indicator_one_le (s : Set α) : ∫⁻ a, s.indicator 1 a ∂μ ≤ μ s := (lintegral_indicator_const_le _ _).trans <| (one_mul _).le @[simp] theorem lintegral_indicator_one₀ (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const₀ hs _).trans <| one_mul _ @[simp] theorem lintegral_indicator_one (hs : MeasurableSet s) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const hs _).trans <| one_mul _ #align measure_theory.lintegral_indicator_one MeasureTheory.lintegral_indicator_one /-- A version of **Markov's inequality** for two functions. It doesn't follow from the standard Markov's inequality because we only assume measurability of `g`, not `f`. -/ theorem lintegral_add_mul_meas_add_le_le_lintegral {f g : α → ℝ≥0∞} (hle : f ≤ᵐ[μ] g) (hg : AEMeasurable g μ) (ε : ℝ≥0∞) : ∫⁻ a, f a ∂μ + ε * μ { x | f x + ε ≤ g x } ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_le_lintegral_eq μ f with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ x, f x ∂μ + ε * μ { x | f x + ε ≤ g x } = ∫⁻ x, φ x ∂μ + ε * μ { x | f x + ε ≤ g x } := by rw [hφ_eq] _ ≤ ∫⁻ x, φ x ∂μ + ε * μ { x | φ x + ε ≤ g x } := by gcongr exact fun x => (add_le_add_right (hφ_le _) _).trans _ = ∫⁻ x, φ x + indicator { x | φ x + ε ≤ g x } (fun _ => ε) x ∂μ := by rw [lintegral_add_left hφm, lintegral_indicator₀, set_lintegral_const] exact measurableSet_le (hφm.nullMeasurable.measurable'.add_const _) hg.nullMeasurable _ ≤ ∫⁻ x, g x ∂μ := lintegral_mono_ae (hle.mono fun x hx₁ => ?_) simp only [indicator_apply]; split_ifs with hx₂ exacts [hx₂, (add_zero _).trans_le <| (hφ_le x).trans hx₁] #align measure_theory.lintegral_add_mul_meas_add_le_le_lintegral MeasureTheory.lintegral_add_mul_meas_add_le_le_lintegral /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem mul_meas_ge_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := by simpa only [lintegral_zero, zero_add] using lintegral_add_mul_meas_add_le_le_lintegral (ae_of_all _ fun x => zero_le (f x)) hf ε #align measure_theory.mul_meas_ge_le_lintegral₀ MeasureTheory.mul_meas_ge_le_lintegral₀ /-- **Markov's inequality** also known as **Chebyshev's first inequality**. For a version assuming `AEMeasurable`, see `mul_meas_ge_le_lintegral₀`. -/ theorem mul_meas_ge_le_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := mul_meas_ge_le_lintegral₀ hf.aemeasurable ε #align measure_theory.mul_meas_ge_le_lintegral MeasureTheory.mul_meas_ge_le_lintegral lemma meas_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {s : Set α} (hs : ∀ x ∈ s, 1 ≤ f x) : μ s ≤ ∫⁻ a, f a ∂μ := by apply le_trans _ (mul_meas_ge_le_lintegral₀ hf 1) rw [one_mul] exact measure_mono hs lemma lintegral_le_meas {s : Set α} {f : α → ℝ≥0∞} (hf : ∀ a, f a ≤ 1) (h'f : ∀ a ∈ sᶜ, f a = 0) : ∫⁻ a, f a ∂μ ≤ μ s := by apply (lintegral_mono (fun x ↦ ?_)).trans (lintegral_indicator_one_le s) by_cases hx : x ∈ s · simpa [hx] using hf x · simpa [hx] using h'f x hx theorem lintegral_eq_top_of_measure_eq_top_ne_zero {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hμf : μ {x | f x = ∞} ≠ 0) : ∫⁻ x, f x ∂μ = ∞ := eq_top_iff.mpr <| calc ∞ = ∞ * μ { x | ∞ ≤ f x } := by simp [mul_eq_top, hμf] _ ≤ ∫⁻ x, f x ∂μ := mul_meas_ge_le_lintegral₀ hf ∞ #align measure_theory.lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.lintegral_eq_top_of_measure_eq_top_ne_zero theorem setLintegral_eq_top_of_measure_eq_top_ne_zero (hf : AEMeasurable f (μ.restrict s)) (hμf : μ ({x ∈ s | f x = ∞}) ≠ 0) : ∫⁻ x in s, f x ∂μ = ∞ := lintegral_eq_top_of_measure_eq_top_ne_zero hf <| mt (eq_bot_mono <| by rw [← setOf_inter_eq_sep]; exact Measure.le_restrict_apply _ _) hμf #align measure_theory.set_lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.setLintegral_eq_top_of_measure_eq_top_ne_zero theorem measure_eq_top_of_lintegral_ne_top (hf : AEMeasurable f μ) (hμf : ∫⁻ x, f x ∂μ ≠ ∞) : μ {x | f x = ∞} = 0 := of_not_not fun h => hμf <| lintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_lintegral_ne_top MeasureTheory.measure_eq_top_of_lintegral_ne_top theorem measure_eq_top_of_setLintegral_ne_top (hf : AEMeasurable f (μ.restrict s)) (hμf : ∫⁻ x in s, f x ∂μ ≠ ∞) : μ ({x ∈ s | f x = ∞}) = 0 := of_not_not fun h => hμf <| setLintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_set_lintegral_ne_top MeasureTheory.measure_eq_top_of_setLintegral_ne_top /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem meas_ge_le_lintegral_div {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) (hε' : ε ≠ ∞) : μ { x | ε ≤ f x } ≤ (∫⁻ a, f a ∂μ) / ε := (ENNReal.le_div_iff_mul_le (Or.inl hε) (Or.inl hε')).2 <| by rw [mul_comm] exact mul_meas_ge_le_lintegral₀ hf ε #align measure_theory.meas_ge_le_lintegral_div MeasureTheory.meas_ge_le_lintegral_div theorem ae_eq_of_ae_le_of_lintegral_le {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) (hf : ∫⁻ x, f x ∂μ ≠ ∞) (hg : AEMeasurable g μ) (hgf : ∫⁻ x, g x ∂μ ≤ ∫⁻ x, f x ∂μ) : f =ᵐ[μ] g := by have : ∀ n : ℕ, ∀ᵐ x ∂μ, g x < f x + (n : ℝ≥0∞)⁻¹ := by intro n simp only [ae_iff, not_lt] have : ∫⁻ x, f x ∂μ + (↑n)⁻¹ * μ { x : α | f x + (n : ℝ≥0∞)⁻¹ ≤ g x } ≤ ∫⁻ x, f x ∂μ := (lintegral_add_mul_meas_add_le_le_lintegral hfg hg n⁻¹).trans hgf rw [(ENNReal.cancel_of_ne hf).add_le_iff_nonpos_right, nonpos_iff_eq_zero, mul_eq_zero] at this exact this.resolve_left (ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _)) refine hfg.mp ((ae_all_iff.2 this).mono fun x hlt hle => hle.antisymm ?_) suffices Tendsto (fun n : ℕ => f x + (n : ℝ≥0∞)⁻¹) atTop (𝓝 (f x)) from ge_of_tendsto' this fun i => (hlt i).le simpa only [inv_top, add_zero] using tendsto_const_nhds.add (ENNReal.tendsto_inv_iff.2 ENNReal.tendsto_nat_nhds_top) #align measure_theory.ae_eq_of_ae_le_of_lintegral_le MeasureTheory.ae_eq_of_ae_le_of_lintegral_le @[simp] theorem lintegral_eq_zero_iff' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := have : ∫⁻ _ : α, 0 ∂μ ≠ ∞ := by simp [lintegral_zero, zero_ne_top] ⟨fun h => (ae_eq_of_ae_le_of_lintegral_le (ae_of_all _ <| zero_le f) this hf (h.trans lintegral_zero.symm).le).symm, fun h => (lintegral_congr_ae h).trans lintegral_zero⟩ #align measure_theory.lintegral_eq_zero_iff' MeasureTheory.lintegral_eq_zero_iff' @[simp] theorem lintegral_eq_zero_iff {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := lintegral_eq_zero_iff' hf.aemeasurable #align measure_theory.lintegral_eq_zero_iff MeasureTheory.lintegral_eq_zero_iff theorem lintegral_pos_iff_support {f : α → ℝ≥0∞} (hf : Measurable f) : (0 < ∫⁻ a, f a ∂μ) ↔ 0 < μ (Function.support f) := by simp [pos_iff_ne_zero, hf, Filter.EventuallyEq, ae_iff, Function.support] #align measure_theory.lintegral_pos_iff_support MeasureTheory.lintegral_pos_iff_support theorem setLintegral_pos_iff {f : α → ℝ≥0∞} (hf : Measurable f) {s : Set α} : 0 < ∫⁻ a in s, f a ∂μ ↔ 0 < μ (Function.support f ∩ s) := by rw [lintegral_pos_iff_support hf, Measure.restrict_apply (measurableSet_support hf)] /-- Weaker version of the monotone convergence theorem-/ theorem lintegral_iSup_ae {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f n.succ a) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by let ⟨s, hs⟩ := exists_measurable_superset_of_null (ae_iff.1 (ae_all_iff.2 h_mono)) let g n a := if a ∈ s then 0 else f n a have g_eq_f : ∀ᵐ a ∂μ, ∀ n, g n a = f n a := (measure_zero_iff_ae_nmem.1 hs.2.2).mono fun a ha n => if_neg ha calc ∫⁻ a, ⨆ n, f n a ∂μ = ∫⁻ a, ⨆ n, g n a ∂μ := lintegral_congr_ae <| g_eq_f.mono fun a ha => by simp only [ha] _ = ⨆ n, ∫⁻ a, g n a ∂μ := (lintegral_iSup (fun n => measurable_const.piecewise hs.2.1 (hf n)) (monotone_nat_of_le_succ fun n a => ?_)) _ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [lintegral_congr_ae (g_eq_f.mono fun _a ha => ha _)] simp only [g] split_ifs with h · rfl · have := Set.not_mem_subset hs.1 h simp only [not_forall, not_le, mem_setOf_eq, not_exists, not_lt] at this exact this n #align measure_theory.lintegral_supr_ae MeasureTheory.lintegral_iSup_ae theorem lintegral_sub' {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := by refine ENNReal.eq_sub_of_add_eq hg_fin ?_ rw [← lintegral_add_right' _ hg] exact lintegral_congr_ae (h_le.mono fun x hx => tsub_add_cancel_of_le hx) #align measure_theory.lintegral_sub' MeasureTheory.lintegral_sub' theorem lintegral_sub {f g : α → ℝ≥0∞} (hg : Measurable g) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := lintegral_sub' hg.aemeasurable hg_fin h_le #align measure_theory.lintegral_sub MeasureTheory.lintegral_sub theorem lintegral_sub_le' (f g : α → ℝ≥0∞) (hf : AEMeasurable f μ) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := by rw [tsub_le_iff_right] by_cases hfi : ∫⁻ x, f x ∂μ = ∞ · rw [hfi, add_top] exact le_top · rw [← lintegral_add_right' _ hf] gcongr exact le_tsub_add #align measure_theory.lintegral_sub_le' MeasureTheory.lintegral_sub_le' theorem lintegral_sub_le (f g : α → ℝ≥0∞) (hf : Measurable f) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := lintegral_sub_le' f g hf.aemeasurable #align measure_theory.lintegral_sub_le MeasureTheory.lintegral_sub_le theorem lintegral_strict_mono_of_ae_le_of_frequently_ae_lt {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) (h : ∃ᵐ x ∂μ, f x ≠ g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by contrapose! h simp only [not_frequently, Ne, Classical.not_not] exact ae_eq_of_ae_le_of_lintegral_le h_le hfi hg h #align measure_theory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt MeasureTheory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt theorem lintegral_strict_mono_of_ae_le_of_ae_lt_on {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) {s : Set α} (hμs : μ s ≠ 0) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := lintegral_strict_mono_of_ae_le_of_frequently_ae_lt hg hfi h_le <| ((frequently_ae_mem_iff.2 hμs).and_eventually h).mono fun _x hx => (hx.2 hx.1).ne #align measure_theory.lintegral_strict_mono_of_ae_le_of_ae_lt_on MeasureTheory.lintegral_strict_mono_of_ae_le_of_ae_lt_on theorem lintegral_strict_mono {f g : α → ℝ≥0∞} (hμ : μ ≠ 0) (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by rw [Ne, ← Measure.measure_univ_eq_zero] at hμ refine lintegral_strict_mono_of_ae_le_of_ae_lt_on hg hfi (ae_le_of_ae_lt h) hμ ?_ simpa using h #align measure_theory.lintegral_strict_mono MeasureTheory.lintegral_strict_mono theorem set_lintegral_strict_mono {f g : α → ℝ≥0∞} {s : Set α} (hsm : MeasurableSet s) (hs : μ s ≠ 0) (hg : Measurable g) (hfi : ∫⁻ x in s, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x in s, f x ∂μ < ∫⁻ x in s, g x ∂μ := lintegral_strict_mono (by simp [hs]) hg.aemeasurable hfi ((ae_restrict_iff' hsm).mpr h) #align measure_theory.set_lintegral_strict_mono MeasureTheory.set_lintegral_strict_mono /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf_ae {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_mono : ∀ n : ℕ, f n.succ ≤ᵐ[μ] f n) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := have fn_le_f0 : ∫⁻ a, ⨅ n, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := lintegral_mono fun a => iInf_le_of_le 0 le_rfl have fn_le_f0' : ⨅ n, ∫⁻ a, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := iInf_le_of_le 0 le_rfl (ENNReal.sub_right_inj h_fin fn_le_f0 fn_le_f0').1 <| show ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ from calc ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a - ⨅ n, f n a ∂μ := (lintegral_sub (measurable_iInf h_meas) (ne_top_of_le_ne_top h_fin <| lintegral_mono fun a => iInf_le _ _) (ae_of_all _ fun a => iInf_le _ _)).symm _ = ∫⁻ a, ⨆ n, f 0 a - f n a ∂μ := congr rfl (funext fun a => ENNReal.sub_iInf) _ = ⨆ n, ∫⁻ a, f 0 a - f n a ∂μ := (lintegral_iSup_ae (fun n => (h_meas 0).sub (h_meas n)) fun n => (h_mono n).mono fun a ha => tsub_le_tsub le_rfl ha) _ = ⨆ n, ∫⁻ a, f 0 a ∂μ - ∫⁻ a, f n a ∂μ := (have h_mono : ∀ᵐ a ∂μ, ∀ n : ℕ, f n.succ a ≤ f n a := ae_all_iff.2 h_mono have h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f 0 a := fun n => h_mono.mono fun a h => by induction' n with n ih · exact le_rfl · exact le_trans (h n) ih congr_arg iSup <| funext fun n => lintegral_sub (h_meas _) (ne_top_of_le_ne_top h_fin <| lintegral_mono_ae <| h_mono n) (h_mono n)) _ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ := ENNReal.sub_iInf.symm #align measure_theory.lintegral_infi_ae MeasureTheory.lintegral_iInf_ae /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_anti : Antitone f) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := lintegral_iInf_ae h_meas (fun n => ae_of_all _ <| h_anti n.le_succ) h_fin #align measure_theory.lintegral_infi MeasureTheory.lintegral_iInf theorem lintegral_iInf' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a)) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iInf_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Antitone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_anti have h_ae_seq_mono : Antitone (aeSeq h_meas p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet h_meas p · exact aeSeq.prop_of_mem_aeSeqSet h_meas hx hnm · simp only [aeSeq, hx, if_false] exact le_rfl rw [lintegral_congr_ae (aeSeq.iInf h_meas hp).symm] simp_rw [iInf_apply] rw [lintegral_iInf (aeSeq.measurable h_meas p) h_ae_seq_mono] · congr exact funext fun n ↦ lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp n) · rwa [lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp 0)] /-- Monotone convergence for an infimum over a directed family and indexed by a countable type -/ theorem lintegral_iInf_directed_of_measurable {mα : MeasurableSpace α} [Countable β] {f : β → α → ℝ≥0∞} {μ : Measure α} (hμ : μ ≠ 0) (hf : ∀ b, Measurable (f b)) (hf_int : ∀ b, ∫⁻ a, f b a ∂μ ≠ ∞) (h_directed : Directed (· ≥ ·) f) : ∫⁻ a, ⨅ b, f b a ∂μ = ⨅ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp only [iInf_of_empty, lintegral_const, ENNReal.top_mul (Measure.measure_univ_ne_zero.mpr hμ)] inhabit β have : ∀ a, ⨅ b, f b a = ⨅ n, f (h_directed.sequence f n) a := by refine fun a => le_antisymm (le_iInf fun n => iInf_le _ _) (le_iInf fun b => iInf_le_of_le (Encodable.encode b + 1) ?_) exact h_directed.sequence_le b a -- Porting note: used `∘` below to deal with its reduced reducibility calc ∫⁻ a, ⨅ b, f b a ∂μ _ = ∫⁻ a, ⨅ n, (f ∘ h_directed.sequence f) n a ∂μ := by simp only [this, Function.comp_apply] _ = ⨅ n, ∫⁻ a, (f ∘ h_directed.sequence f) n a ∂μ := by rw [lintegral_iInf ?_ h_directed.sequence_anti] · exact hf_int _ · exact fun n => hf _ _ = ⨅ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (le_iInf fun b => ?_) (le_iInf fun n => ?_) · exact iInf_le_of_le (Encodable.encode b + 1) (lintegral_mono <| h_directed.sequence_le b) · exact iInf_le (fun b => ∫⁻ a, f b a ∂μ) _ #align lintegral_infi_directed_of_measurable MeasureTheory.lintegral_iInf_directed_of_measurable /-- Known as Fatou's lemma, version with `AEMeasurable` functions -/ theorem lintegral_liminf_le' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := calc ∫⁻ a, liminf (fun n => f n a) atTop ∂μ = ∫⁻ a, ⨆ n : ℕ, ⨅ i ≥ n, f i a ∂μ := by simp only [liminf_eq_iSup_iInf_of_nat] _ = ⨆ n : ℕ, ∫⁻ a, ⨅ i ≥ n, f i a ∂μ := (lintegral_iSup' (fun n => aemeasurable_biInf _ (to_countable _) (fun i _ ↦ h_meas i)) (ae_of_all μ fun a n m hnm => iInf_le_iInf_of_subset fun i hi => le_trans hnm hi)) _ ≤ ⨆ n : ℕ, ⨅ i ≥ n, ∫⁻ a, f i a ∂μ := iSup_mono fun n => le_iInf₂_lintegral _ _ = atTop.liminf fun n => ∫⁻ a, f n a ∂μ := Filter.liminf_eq_iSup_iInf_of_nat.symm #align measure_theory.lintegral_liminf_le' MeasureTheory.lintegral_liminf_le' /-- Known as Fatou's lemma -/ theorem lintegral_liminf_le {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := lintegral_liminf_le' fun n => (h_meas n).aemeasurable #align measure_theory.lintegral_liminf_le MeasureTheory.lintegral_liminf_le theorem limsup_lintegral_le {f : ℕ → α → ℝ≥0∞} {g : α → ℝ≥0∞} (hf_meas : ∀ n, Measurable (f n)) (h_bound : ∀ n, f n ≤ᵐ[μ] g) (h_fin : ∫⁻ a, g a ∂μ ≠ ∞) : limsup (fun n => ∫⁻ a, f n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := calc limsup (fun n => ∫⁻ a, f n a ∂μ) atTop = ⨅ n : ℕ, ⨆ i ≥ n, ∫⁻ a, f i a ∂μ := limsup_eq_iInf_iSup_of_nat _ ≤ ⨅ n : ℕ, ∫⁻ a, ⨆ i ≥ n, f i a ∂μ := iInf_mono fun n => iSup₂_lintegral_le _ _ = ∫⁻ a, ⨅ n : ℕ, ⨆ i ≥ n, f i a ∂μ := by refine (lintegral_iInf ?_ ?_ ?_).symm · intro n exact measurable_biSup _ (to_countable _) (fun i _ ↦ hf_meas i) · intro n m hnm a exact iSup_le_iSup_of_subset fun i hi => le_trans hnm hi · refine ne_top_of_le_ne_top h_fin (lintegral_mono_ae ?_) refine (ae_all_iff.2 h_bound).mono fun n hn => ?_ exact iSup_le fun i => iSup_le fun _ => hn i _ = ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := by simp only [limsup_eq_iInf_iSup_of_nat] #align measure_theory.limsup_lintegral_le MeasureTheory.limsup_lintegral_le /-- Dominated convergence theorem for nonnegative functions -/ theorem tendsto_lintegral_of_dominated_convergence {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, Measurable (F n)) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := tendsto_of_le_liminf_of_limsup_le (calc ∫⁻ a, f a ∂μ = ∫⁻ a, liminf (fun n : ℕ => F n a) atTop ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.liminf_eq.symm _ ≤ liminf (fun n => ∫⁻ a, F n a ∂μ) atTop := lintegral_liminf_le hF_meas ) (calc limsup (fun n : ℕ => ∫⁻ a, F n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => F n a) atTop ∂μ := limsup_lintegral_le hF_meas h_bound h_fin _ = ∫⁻ a, f a ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.limsup_eq ) #align measure_theory.tendsto_lintegral_of_dominated_convergence MeasureTheory.tendsto_lintegral_of_dominated_convergence /-- Dominated convergence theorem for nonnegative functions which are just almost everywhere measurable. -/ theorem tendsto_lintegral_of_dominated_convergence' {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, AEMeasurable (F n) μ) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := by have : ∀ n, ∫⁻ a, F n a ∂μ = ∫⁻ a, (hF_meas n).mk (F n) a ∂μ := fun n => lintegral_congr_ae (hF_meas n).ae_eq_mk simp_rw [this] apply tendsto_lintegral_of_dominated_convergence bound (fun n => (hF_meas n).measurable_mk) _ h_fin · have : ∀ n, ∀ᵐ a ∂μ, (hF_meas n).mk (F n) a = F n a := fun n => (hF_meas n).ae_eq_mk.symm have : ∀ᵐ a ∂μ, ∀ n, (hF_meas n).mk (F n) a = F n a := ae_all_iff.mpr this filter_upwards [this, h_lim] with a H H' simp_rw [H] exact H' · intro n filter_upwards [h_bound n, (hF_meas n).ae_eq_mk] with a H H' rwa [H'] at H #align measure_theory.tendsto_lintegral_of_dominated_convergence' MeasureTheory.tendsto_lintegral_of_dominated_convergence' /-- Dominated convergence theorem for filters with a countable basis -/ theorem tendsto_lintegral_filter_of_dominated_convergence {ι} {l : Filter ι} [l.IsCountablyGenerated] {F : ι → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ᶠ n in l, Measurable (F n)) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, F n a ≤ bound a) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) l (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) l (𝓝 <| ∫⁻ a, f a ∂μ) := by rw [tendsto_iff_seq_tendsto] intro x xl have hxl := by rw [tendsto_atTop'] at xl exact xl have h := inter_mem hF_meas h_bound replace h := hxl _ h rcases h with ⟨k, h⟩ rw [← tendsto_add_atTop_iff_nat k] refine tendsto_lintegral_of_dominated_convergence ?_ ?_ ?_ ?_ ?_ · exact bound · intro refine (h _ ?_).1 exact Nat.le_add_left _ _ · intro refine (h _ ?_).2 exact Nat.le_add_left _ _ · assumption · refine h_lim.mono fun a h_lim => ?_ apply @Tendsto.comp _ _ _ (fun n => x (n + k)) fun n => F n a · assumption rw [tendsto_add_atTop_iff_nat] assumption #align measure_theory.tendsto_lintegral_filter_of_dominated_convergence MeasureTheory.tendsto_lintegral_filter_of_dominated_convergence theorem lintegral_tendsto_of_tendsto_of_antitone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ x ∂μ, Antitone fun n ↦ f n x) (h0 : ∫⁻ a, f 0 a ∂μ ≠ ∞) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) : Tendsto (fun n ↦ ∫⁻ x, f n x ∂μ) atTop (𝓝 (∫⁻ x, F x ∂μ)) := by have : Antitone fun n ↦ ∫⁻ x, f n x ∂μ := fun i j hij ↦ lintegral_mono_ae (h_anti.mono fun x hx ↦ hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨅ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iInf this rw [← lintegral_iInf' hf h_anti h0] refine lintegral_congr_ae ?_ filter_upwards [h_anti, h_tendsto] with _ hx_anti hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iInf hx_anti) section open Encodable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type -/ theorem lintegral_iSup_directed_of_measurable [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, Measurable (f b)) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp [iSup_of_empty] inhabit β have : ∀ a, ⨆ b, f b a = ⨆ n, f (h_directed.sequence f n) a := by intro a refine le_antisymm (iSup_le fun b => ?_) (iSup_le fun n => le_iSup (fun n => f n a) _) exact le_iSup_of_le (encode b + 1) (h_directed.le_sequence b a) calc ∫⁻ a, ⨆ b, f b a ∂μ = ∫⁻ a, ⨆ n, f (h_directed.sequence f n) a ∂μ := by simp only [this] _ = ⨆ n, ∫⁻ a, f (h_directed.sequence f n) a ∂μ := (lintegral_iSup (fun n => hf _) h_directed.sequence_mono) _ = ⨆ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (iSup_le fun n => ?_) (iSup_le fun b => ?_) · exact le_iSup (fun b => ∫⁻ a, f b a ∂μ) _ · exact le_iSup_of_le (encode b + 1) (lintegral_mono <| h_directed.le_sequence b) #align measure_theory.lintegral_supr_directed_of_measurable MeasureTheory.lintegral_iSup_directed_of_measurable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type. -/ theorem lintegral_iSup_directed [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, AEMeasurable (f b) μ) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by simp_rw [← iSup_apply] let p : α → (β → ENNReal) → Prop := fun x f' => Directed LE.le f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := by filter_upwards [] with x i j obtain ⟨z, hz₁, hz₂⟩ := h_directed i j exact ⟨z, hz₁ x, hz₂ x⟩ have h_ae_seq_directed : Directed LE.le (aeSeq hf p) := by intro b₁ b₂ obtain ⟨z, hz₁, hz₂⟩ := h_directed b₁ b₂ refine ⟨z, ?_, ?_⟩ <;> · intro x by_cases hx : x ∈ aeSeqSet hf p · repeat rw [aeSeq.aeSeq_eq_fun_of_mem_aeSeqSet hf hx] apply_rules [hz₁, hz₂] · simp only [aeSeq, hx, if_false] exact le_rfl convert lintegral_iSup_directed_of_measurable (aeSeq.measurable hf p) h_ae_seq_directed using 1 · simp_rw [← iSup_apply] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] · congr 1 ext1 b rw [lintegral_congr_ae] apply EventuallyEq.symm exact aeSeq.aeSeq_n_eq_fun_n_ae hf hp _ #align measure_theory.lintegral_supr_directed MeasureTheory.lintegral_iSup_directed end theorem lintegral_tsum [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ i, AEMeasurable (f i) μ) : ∫⁻ a, ∑' i, f i a ∂μ = ∑' i, ∫⁻ a, f i a ∂μ := by simp only [ENNReal.tsum_eq_iSup_sum] rw [lintegral_iSup_directed] · simp [lintegral_finset_sum' _ fun i _ => hf i] · intro b exact Finset.aemeasurable_sum _ fun i _ => hf i · intro s t use s ∪ t constructor · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_left · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_right #align measure_theory.lintegral_tsum MeasureTheory.lintegral_tsum open Measure theorem lintegral_iUnion₀ [Countable β] {s : β → Set α} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := by simp only [Measure.restrict_iUnion_ae hd hm, lintegral_sum_measure] #align measure_theory.lintegral_Union₀ MeasureTheory.lintegral_iUnion₀ theorem lintegral_iUnion [Countable β] {s : β → Set α} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := lintegral_iUnion₀ (fun i => (hm i).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_Union MeasureTheory.lintegral_iUnion theorem lintegral_biUnion₀ {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, NullMeasurableSet (s i) μ) (hd : t.Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, lintegral_iUnion₀ (SetCoe.forall'.1 hm) (hd.subtype _ _)] #align measure_theory.lintegral_bUnion₀ MeasureTheory.lintegral_biUnion₀ theorem lintegral_biUnion {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, MeasurableSet (s i)) (hd : t.PairwiseDisjoint s) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := lintegral_biUnion₀ ht (fun i hi => (hm i hi).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_bUnion MeasureTheory.lintegral_biUnion theorem lintegral_biUnion_finset₀ {s : Finset β} {t : β → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on t)) (hm : ∀ b ∈ s, NullMeasurableSet (t b) μ) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := by simp only [← Finset.mem_coe, lintegral_biUnion₀ s.countable_toSet hm hd, ← Finset.tsum_subtype'] #align measure_theory.lintegral_bUnion_finset₀ MeasureTheory.lintegral_biUnion_finset₀ theorem lintegral_biUnion_finset {s : Finset β} {t : β → Set α} (hd : Set.PairwiseDisjoint (↑s) t) (hm : ∀ b ∈ s, MeasurableSet (t b)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := lintegral_biUnion_finset₀ hd.aedisjoint (fun b hb => (hm b hb).nullMeasurableSet) f #align measure_theory.lintegral_bUnion_finset MeasureTheory.lintegral_biUnion_finset theorem lintegral_iUnion_le [Countable β] (s : β → Set α) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ ≤ ∑' i, ∫⁻ a in s i, f a ∂μ := by rw [← lintegral_sum_measure] exact lintegral_mono' restrict_iUnion_le le_rfl #align measure_theory.lintegral_Union_le MeasureTheory.lintegral_iUnion_le theorem lintegral_union {f : α → ℝ≥0∞} {A B : Set α} (hB : MeasurableSet B) (hAB : Disjoint A B) : ∫⁻ a in A ∪ B, f a ∂μ = ∫⁻ a in A, f a ∂μ + ∫⁻ a in B, f a ∂μ := by rw [restrict_union hAB hB, lintegral_add_measure] #align measure_theory.lintegral_union MeasureTheory.lintegral_union theorem lintegral_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∫⁻ a in s ∪ t, f a ∂μ ≤ ∫⁻ a in s, f a ∂μ + ∫⁻ a in t, f a ∂μ := by rw [← lintegral_add_measure] exact lintegral_mono' (restrict_union_le _ _) le_rfl theorem lintegral_inter_add_diff {B : Set α} (f : α → ℝ≥0∞) (A : Set α) (hB : MeasurableSet B) : ∫⁻ x in A ∩ B, f x ∂μ + ∫⁻ x in A \ B, f x ∂μ = ∫⁻ x in A, f x ∂μ := by rw [← lintegral_add_measure, restrict_inter_add_diff _ hB] #align measure_theory.lintegral_inter_add_diff MeasureTheory.lintegral_inter_add_diff theorem lintegral_add_compl (f : α → ℝ≥0∞) {A : Set α} (hA : MeasurableSet A) : ∫⁻ x in A, f x ∂μ + ∫⁻ x in Aᶜ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [← lintegral_add_measure, Measure.restrict_add_restrict_compl hA] #align measure_theory.lintegral_add_compl MeasureTheory.lintegral_add_compl theorem lintegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ x, max (f x) (g x) ∂μ = ∫⁻ x in { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in { x | g x < f x }, f x ∂μ := by have hm : MeasurableSet { x | f x ≤ g x } := measurableSet_le hf hg rw [← lintegral_add_compl (fun x => max (f x) (g x)) hm] simp only [← compl_setOf, ← not_le] refine congr_arg₂ (· + ·) (set_lintegral_congr_fun hm ?_) (set_lintegral_congr_fun hm.compl ?_) exacts [ae_of_all _ fun x => max_eq_right (a := f x) (b := g x), ae_of_all _ fun x (hx : ¬ f x ≤ g x) => max_eq_left (not_le.1 hx).le] #align measure_theory.lintegral_max MeasureTheory.lintegral_max theorem set_lintegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (s : Set α) : ∫⁻ x in s, max (f x) (g x) ∂μ = ∫⁻ x in s ∩ { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in s ∩ { x | g x < f x }, f x ∂μ := by rw [lintegral_max hf hg, restrict_restrict, restrict_restrict, inter_comm s, inter_comm s] exacts [measurableSet_lt hg hf, measurableSet_le hf hg] #align measure_theory.set_lintegral_max MeasureTheory.set_lintegral_max theorem lintegral_map {mβ : MeasurableSpace β} {f : β → ℝ≥0∞} {g : α → β} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := by erw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral (hf.comp hg)] congr with n : 1 convert SimpleFunc.lintegral_map _ hg ext1 x; simp only [eapprox_comp hf hg, coe_comp] #align measure_theory.lintegral_map MeasureTheory.lintegral_map theorem lintegral_map' {mβ : MeasurableSpace β} {f : β → ℝ≥0∞} {g : α → β} (hf : AEMeasurable f (Measure.map g μ)) (hg : AEMeasurable g μ) : ∫⁻ a, f a ∂Measure.map g μ = ∫⁻ a, f (g a) ∂μ := calc ∫⁻ a, f a ∂Measure.map g μ = ∫⁻ a, hf.mk f a ∂Measure.map g μ := lintegral_congr_ae hf.ae_eq_mk _ = ∫⁻ a, hf.mk f a ∂Measure.map (hg.mk g) μ := by congr 1 exact Measure.map_congr hg.ae_eq_mk _ = ∫⁻ a, hf.mk f (hg.mk g a) ∂μ := lintegral_map hf.measurable_mk hg.measurable_mk _ = ∫⁻ a, hf.mk f (g a) ∂μ := lintegral_congr_ae <| hg.ae_eq_mk.symm.fun_comp _ _ = ∫⁻ a, f (g a) ∂μ := lintegral_congr_ae (ae_eq_comp hg hf.ae_eq_mk.symm) #align measure_theory.lintegral_map' MeasureTheory.lintegral_map' theorem lintegral_map_le {mβ : MeasurableSpace β} (f : β → ℝ≥0∞) {g : α → β} (hg : Measurable g) : ∫⁻ a, f a ∂Measure.map g μ ≤ ∫⁻ a, f (g a) ∂μ := by rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral] refine iSup₂_le fun i hi => iSup_le fun h'i => ?_ refine le_iSup₂_of_le (i ∘ g) (hi.comp hg) ?_ exact le_iSup_of_le (fun x => h'i (g x)) (le_of_eq (lintegral_map hi hg)) #align measure_theory.lintegral_map_le MeasureTheory.lintegral_map_le theorem lintegral_comp [MeasurableSpace β] {f : β → ℝ≥0∞} {g : α → β} (hf : Measurable f) (hg : Measurable g) : lintegral μ (f ∘ g) = ∫⁻ a, f a ∂map g μ := (lintegral_map hf hg).symm #align measure_theory.lintegral_comp MeasureTheory.lintegral_comp theorem set_lintegral_map [MeasurableSpace β] {f : β → ℝ≥0∞} {g : α → β} {s : Set β} (hs : MeasurableSet s) (hf : Measurable f) (hg : Measurable g) : ∫⁻ y in s, f y ∂map g μ = ∫⁻ x in g ⁻¹' s, f (g x) ∂μ := by rw [restrict_map hg hs, lintegral_map hf hg] #align measure_theory.set_lintegral_map MeasureTheory.set_lintegral_map theorem lintegral_indicator_const_comp {mβ : MeasurableSpace β} {f : α → β} {s : Set β} (hf : Measurable f) (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) (f a) ∂μ = c * μ (f ⁻¹' s) := by erw [lintegral_comp (measurable_const.indicator hs) hf, lintegral_indicator_const hs, Measure.map_apply hf hs] #align measure_theory.lintegral_indicator_const_comp MeasureTheory.lintegral_indicator_const_comp /-- If `g : α → β` is a measurable embedding and `f : β → ℝ≥0∞` is any function (not necessarily measurable), then `∫⁻ a, f a ∂(map g μ) = ∫⁻ a, f (g a) ∂μ`. Compare with `lintegral_map` which applies to any measurable `g : α → β` but requires that `f` is measurable as well. -/ theorem _root_.MeasurableEmbedding.lintegral_map [MeasurableSpace β] {g : α → β} (hg : MeasurableEmbedding g) (f : β → ℝ≥0∞) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := by rw [lintegral, lintegral] refine le_antisymm (iSup₂_le fun f₀ hf₀ => ?_) (iSup₂_le fun f₀ hf₀ => ?_) · rw [SimpleFunc.lintegral_map _ hg.measurable] have : (f₀.comp g hg.measurable : α → ℝ≥0∞) ≤ f ∘ g := fun x => hf₀ (g x) exact le_iSup_of_le (comp f₀ g hg.measurable) (by exact le_iSup (α := ℝ≥0∞) _ this) · rw [← f₀.extend_comp_eq hg (const _ 0), ← SimpleFunc.lintegral_map, ← SimpleFunc.lintegral_eq_lintegral, ← lintegral] refine lintegral_mono_ae (hg.ae_map_iff.2 <| eventually_of_forall fun x => ?_) exact (extend_apply _ _ _ _).trans_le (hf₀ _) #align measurable_embedding.lintegral_map MeasurableEmbedding.lintegral_map /-- The `lintegral` transforms appropriately under a measurable equivalence `g : α ≃ᵐ β`. (Compare `lintegral_map`, which applies to a wider class of functions `g : α → β`, but requires measurability of the function being integrated.) -/ theorem lintegral_map_equiv [MeasurableSpace β] (f : β → ℝ≥0∞) (g : α ≃ᵐ β) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := g.measurableEmbedding.lintegral_map f #align measure_theory.lintegral_map_equiv MeasureTheory.lintegral_map_equiv protected theorem MeasurePreserving.lintegral_map_equiv [MeasurableSpace β] {ν : Measure β} (f : β → ℝ≥0∞) (g : α ≃ᵐ β) (hg : MeasurePreserving g μ ν) : ∫⁻ a, f a ∂ν = ∫⁻ a, f (g a) ∂μ := by rw [← MeasureTheory.lintegral_map_equiv f g, hg.map_eq] theorem MeasurePreserving.lintegral_comp {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) {f : β → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f (g a) ∂μ = ∫⁻ b, f b ∂ν := by rw [← hg.map_eq, lintegral_map hf hg.measurable] #align measure_theory.measure_preserving.lintegral_comp MeasureTheory.MeasurePreserving.lintegral_comp theorem MeasurePreserving.lintegral_comp_emb {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) (hge : MeasurableEmbedding g) (f : β → ℝ≥0∞) : ∫⁻ a, f (g a) ∂μ = ∫⁻ b, f b ∂ν := by rw [← hg.map_eq, hge.lintegral_map] #align measure_theory.measure_preserving.lintegral_comp_emb MeasureTheory.MeasurePreserving.lintegral_comp_emb theorem MeasurePreserving.set_lintegral_comp_preimage {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) {s : Set β} (hs : MeasurableSet s) {f : β → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a in g ⁻¹' s, f (g a) ∂μ = ∫⁻ b in s, f b ∂ν := by rw [← hg.map_eq, set_lintegral_map hs hf hg.measurable] #align measure_theory.measure_preserving.set_lintegral_comp_preimage MeasureTheory.MeasurePreserving.set_lintegral_comp_preimage theorem MeasurePreserving.set_lintegral_comp_preimage_emb {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) (hge : MeasurableEmbedding g) (f : β → ℝ≥0∞) (s : Set β) : ∫⁻ a in g ⁻¹' s, f (g a) ∂μ = ∫⁻ b in s, f b ∂ν := by rw [← hg.map_eq, hge.restrict_map, hge.lintegral_map] #align measure_theory.measure_preserving.set_lintegral_comp_preimage_emb MeasureTheory.MeasurePreserving.set_lintegral_comp_preimage_emb theorem MeasurePreserving.set_lintegral_comp_emb {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) (hge : MeasurableEmbedding g) (f : β → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f (g a) ∂μ = ∫⁻ b in g '' s, f b ∂ν := by rw [← hg.set_lintegral_comp_preimage_emb hge, preimage_image_eq _ hge.injective] #align measure_theory.measure_preserving.set_lintegral_comp_emb MeasureTheory.MeasurePreserving.set_lintegral_comp_emb theorem lintegral_subtype_comap {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : ∫⁻ x : s, f x ∂(μ.comap (↑)) = ∫⁻ x in s, f x ∂μ := by rw [← (MeasurableEmbedding.subtype_coe hs).lintegral_map, map_comap_subtype_coe hs] theorem set_lintegral_subtype {s : Set α} (hs : MeasurableSet s) (t : Set s) (f : α → ℝ≥0∞) : ∫⁻ x in t, f x ∂(μ.comap (↑)) = ∫⁻ x in (↑) '' t, f x ∂μ := by rw [(MeasurableEmbedding.subtype_coe hs).restrict_comap, lintegral_subtype_comap hs, restrict_restrict hs, inter_eq_right.2 (Subtype.coe_image_subset _ _)] section DiracAndCount variable [MeasurableSpace α] theorem lintegral_dirac' (a : α) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂dirac a = f a := by simp [lintegral_congr_ae (ae_eq_dirac' hf)] #align measure_theory.lintegral_dirac' MeasureTheory.lintegral_dirac' theorem lintegral_dirac [MeasurableSingletonClass α] (a : α) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂dirac a = f a := by simp [lintegral_congr_ae (ae_eq_dirac f)] #align measure_theory.lintegral_dirac MeasureTheory.lintegral_dirac theorem set_lintegral_dirac' {a : α} {f : α → ℝ≥0∞} (hf : Measurable f) {s : Set α} (hs : MeasurableSet s) [Decidable (a ∈ s)] : ∫⁻ x in s, f x ∂Measure.dirac a = if a ∈ s then f a else 0 := by rw [restrict_dirac' hs] split_ifs · exact lintegral_dirac' _ hf · exact lintegral_zero_measure _ #align measure_theory.set_lintegral_dirac' MeasureTheory.set_lintegral_dirac' theorem set_lintegral_dirac {a : α} (f : α → ℝ≥0∞) (s : Set α) [MeasurableSingletonClass α] [Decidable (a ∈ s)] : ∫⁻ x in s, f x ∂Measure.dirac a = if a ∈ s then f a else 0 := by rw [restrict_dirac] split_ifs · exact lintegral_dirac _ _ · exact lintegral_zero_measure _ #align measure_theory.set_lintegral_dirac MeasureTheory.set_lintegral_dirac theorem lintegral_count' {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂count = ∑' a, f a := by rw [count, lintegral_sum_measure] congr exact funext fun a => lintegral_dirac' a hf #align measure_theory.lintegral_count' MeasureTheory.lintegral_count' theorem lintegral_count [MeasurableSingletonClass α] (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂count = ∑' a, f a := by rw [count, lintegral_sum_measure] congr exact funext fun a => lintegral_dirac a f #align measure_theory.lintegral_count MeasureTheory.lintegral_count theorem _root_.ENNReal.tsum_const_eq [MeasurableSingletonClass α] (c : ℝ≥0∞) : ∑' _ : α, c = c * Measure.count (univ : Set α) := by rw [← lintegral_count, lintegral_const] #align ennreal.tsum_const_eq ENNReal.tsum_const_eq /-- Markov's inequality for the counting measure with hypothesis using `tsum` in `ℝ≥0∞`. -/ theorem _root_.ENNReal.count_const_le_le_of_tsum_le [MeasurableSingletonClass α] {a : α → ℝ≥0∞} (a_mble : Measurable a) {c : ℝ≥0∞} (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) (ε_ne_top : ε ≠ ∞) : Measure.count { i : α | ε ≤ a i } ≤ c / ε := by rw [← lintegral_count] at tsum_le_c apply (MeasureTheory.meas_ge_le_lintegral_div a_mble.aemeasurable ε_ne_zero ε_ne_top).trans exact ENNReal.div_le_div tsum_le_c rfl.le #align ennreal.count_const_le_le_of_tsum_le ENNReal.count_const_le_le_of_tsum_le /-- Markov's inequality for counting measure with hypothesis using `tsum` in `ℝ≥0`. -/ theorem _root_.NNReal.count_const_le_le_of_tsum_le [MeasurableSingletonClass α] {a : α → ℝ≥0} (a_mble : Measurable a) (a_summable : Summable a) {c : ℝ≥0} (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0} (ε_ne_zero : ε ≠ 0) : Measure.count { i : α | ε ≤ a i } ≤ c / ε := by rw [show (fun i => ε ≤ a i) = fun i => (ε : ℝ≥0∞) ≤ ((↑) ∘ a) i by funext i simp only [ENNReal.coe_le_coe, Function.comp]] apply ENNReal.count_const_le_le_of_tsum_le (measurable_coe_nnreal_ennreal.comp a_mble) _ (mod_cast ε_ne_zero) (@ENNReal.coe_ne_top ε) convert ENNReal.coe_le_coe.mpr tsum_le_c simp_rw [Function.comp_apply] rw [ENNReal.tsum_coe_eq a_summable.hasSum] #align nnreal.count_const_le_le_of_tsum_le NNReal.count_const_le_le_of_tsum_le end DiracAndCount section Countable /-! ### Lebesgue integral over finite and countable types and sets -/ theorem lintegral_countable' [Countable α] [MeasurableSingletonClass α] (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂μ = ∑' a, f a * μ {a} := by conv_lhs => rw [← sum_smul_dirac μ, lintegral_sum_measure] congr 1 with a : 1 rw [lintegral_smul_measure, lintegral_dirac, mul_comm] #align measure_theory.lintegral_countable' MeasureTheory.lintegral_countable' theorem lintegral_singleton' {f : α → ℝ≥0∞} (hf : Measurable f) (a : α) : ∫⁻ x in {a}, f x ∂μ = f a * μ {a} := by simp only [restrict_singleton, lintegral_smul_measure, lintegral_dirac' _ hf, mul_comm] #align measure_theory.lintegral_singleton' MeasureTheory.lintegral_singleton' theorem lintegral_singleton [MeasurableSingletonClass α] (f : α → ℝ≥0∞) (a : α) : ∫⁻ x in {a}, f x ∂μ = f a * μ {a} := by simp only [restrict_singleton, lintegral_smul_measure, lintegral_dirac, mul_comm] #align measure_theory.lintegral_singleton MeasureTheory.lintegral_singleton theorem lintegral_countable [MeasurableSingletonClass α] (f : α → ℝ≥0∞) {s : Set α} (hs : s.Countable) : ∫⁻ a in s, f a ∂μ = ∑' a : s, f a * μ {(a : α)} := calc ∫⁻ a in s, f a ∂μ = ∫⁻ a in ⋃ x ∈ s, {x}, f a ∂μ := by rw [biUnion_of_singleton] _ = ∑' a : s, ∫⁻ x in {(a : α)}, f x ∂μ := (lintegral_biUnion hs (fun _ _ => measurableSet_singleton _) (pairwiseDisjoint_fiber id s) _) _ = ∑' a : s, f a * μ {(a : α)} := by simp only [lintegral_singleton] #align measure_theory.lintegral_countable MeasureTheory.lintegral_countable theorem lintegral_insert [MeasurableSingletonClass α] {a : α} {s : Set α} (h : a ∉ s) (f : α → ℝ≥0∞) : ∫⁻ x in insert a s, f x ∂μ = f a * μ {a} + ∫⁻ x in s, f x ∂μ := by rw [← union_singleton, lintegral_union (measurableSet_singleton a), lintegral_singleton, add_comm] rwa [disjoint_singleton_right] #align measure_theory.lintegral_insert MeasureTheory.lintegral_insert theorem lintegral_finset [MeasurableSingletonClass α] (s : Finset α) (f : α → ℝ≥0∞) : ∫⁻ x in s, f x ∂μ = ∑ x ∈ s, f x * μ {x} := by simp only [lintegral_countable _ s.countable_toSet, ← Finset.tsum_subtype'] #align measure_theory.lintegral_finset MeasureTheory.lintegral_finset theorem lintegral_fintype [MeasurableSingletonClass α] [Fintype α] (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑ x, f x * μ {x} := by rw [← lintegral_finset, Finset.coe_univ, Measure.restrict_univ] #align measure_theory.lintegral_fintype MeasureTheory.lintegral_fintype theorem lintegral_unique [Unique α] (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = f default * μ univ := calc ∫⁻ x, f x ∂μ = ∫⁻ _, f default ∂μ := lintegral_congr <| Unique.forall_iff.2 rfl _ = f default * μ univ := lintegral_const _ #align measure_theory.lintegral_unique MeasureTheory.lintegral_unique end Countable
Mathlib/MeasureTheory/Integral/Lebesgue.lean
1,629
1,639
theorem ae_lt_top {f : α → ℝ≥0∞} (hf : Measurable f) (h2f : ∫⁻ x, f x ∂μ ≠ ∞) : ∀ᵐ x ∂μ, f x < ∞ := by
simp_rw [ae_iff, ENNReal.not_lt_top] by_contra h apply h2f.lt_top.not_le have : (f ⁻¹' {∞}).indicator ⊤ ≤ f := by intro x by_cases hx : x ∈ f ⁻¹' {∞} <;> [simpa [indicator_of_mem hx]; simp [indicator_of_not_mem hx]] convert lintegral_mono this rw [lintegral_indicator _ (hf (measurableSet_singleton ∞))] simp [ENNReal.top_mul', preimage, h]
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Int.Bitwise import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Symmetric #align_import linear_algebra.matrix.zpow from "leanprover-community/mathlib"@"03fda9112aa6708947da13944a19310684bfdfcb" /-! # Integer powers of square matrices In this file, we define integer power of matrices, relying on the nonsingular inverse definition for negative powers. ## Implementation details The main definition is a direct recursive call on the integer inductive type, as provided by the `DivInvMonoid.Pow` default implementation. The lemma names are taken from `Algebra.GroupWithZero.Power`. ## Tags matrix inverse, matrix powers -/ open Matrix namespace Matrix variable {n' : Type*} [DecidableEq n'] [Fintype n'] {R : Type*} [CommRing R] local notation "M" => Matrix n' n' R noncomputable instance : DivInvMonoid M := { show Monoid M by infer_instance, show Inv M by infer_instance with } section NatPow @[simp] theorem inv_pow' (A : M) (n : ℕ) : A⁻¹ ^ n = (A ^ n)⁻¹ := by induction' n with n ih · simp · rw [pow_succ A, mul_inv_rev, ← ih, ← pow_succ'] #align matrix.inv_pow' Matrix.inv_pow' theorem pow_sub' (A : M) {m n : ℕ} (ha : IsUnit A.det) (h : n ≤ m) : A ^ (m - n) = A ^ m * (A ^ n)⁻¹ := by rw [← tsub_add_cancel_of_le h, pow_add, Matrix.mul_assoc, mul_nonsing_inv, tsub_add_cancel_of_le h, Matrix.mul_one] simpa using ha.pow n #align matrix.pow_sub' Matrix.pow_sub' theorem pow_inv_comm' (A : M) (m n : ℕ) : A⁻¹ ^ m * A ^ n = A ^ n * A⁻¹ ^ m := by induction' n with n IH generalizing m · simp cases' m with m m · simp rcases nonsing_inv_cancel_or_zero A with (⟨h, h'⟩ | h) · calc A⁻¹ ^ (m + 1) * A ^ (n + 1) = A⁻¹ ^ m * (A⁻¹ * A) * A ^ n := by simp only [pow_succ A⁻¹, pow_succ' A, Matrix.mul_assoc] _ = A ^ n * A⁻¹ ^ m := by simp only [h, Matrix.mul_one, Matrix.one_mul, IH m] _ = A ^ n * (A * A⁻¹) * A⁻¹ ^ m := by simp only [h', Matrix.mul_one, Matrix.one_mul] _ = A ^ (n + 1) * A⁻¹ ^ (m + 1) := by simp only [pow_succ A, pow_succ' A⁻¹, Matrix.mul_assoc] · simp [h] #align matrix.pow_inv_comm' Matrix.pow_inv_comm' end NatPow section ZPow open Int @[simp] theorem one_zpow : ∀ n : ℤ, (1 : M) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | -[n+1] => by rw [zpow_negSucc, one_pow, inv_one] #align matrix.one_zpow Matrix.one_zpow theorem zero_zpow : ∀ z : ℤ, z ≠ 0 → (0 : M) ^ z = 0 | (n : ℕ), h => by rw [zpow_natCast, zero_pow] exact mod_cast h | -[n+1], _ => by simp [zero_pow n.succ_ne_zero] #align matrix.zero_zpow Matrix.zero_zpow theorem zero_zpow_eq (n : ℤ) : (0 : M) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, zpow_zero] · rw [zero_zpow _ h] #align matrix.zero_zpow_eq Matrix.zero_zpow_eq theorem inv_zpow (A : M) : ∀ n : ℤ, A⁻¹ ^ n = (A ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow'] | -[n+1] => by rw [zpow_negSucc, zpow_negSucc, inv_pow'] #align matrix.inv_zpow Matrix.inv_zpow @[simp] theorem zpow_neg_one (A : M) : A ^ (-1 : ℤ) = A⁻¹ := by convert DivInvMonoid.zpow_neg' 0 A simp only [zpow_one, Int.ofNat_zero, Int.ofNat_succ, zpow_eq_pow, zero_add] #align matrix.zpow_neg_one Matrix.zpow_neg_one #align matrix.zpow_coe_nat zpow_natCast @[simp] theorem zpow_neg_natCast (A : M) (n : ℕ) : A ^ (-n : ℤ) = (A ^ n)⁻¹ := by cases n · simp · exact DivInvMonoid.zpow_neg' _ _ #align matrix.zpow_neg_coe_nat Matrix.zpow_neg_natCast @[deprecated (since := "2024-04-05")] alias zpow_neg_coe_nat := zpow_neg_natCast theorem _root_.IsUnit.det_zpow {A : M} (h : IsUnit A.det) (n : ℤ) : IsUnit (A ^ n).det := by cases' n with n n · simpa using h.pow n · simpa using h.pow n.succ #align is_unit.det_zpow IsUnit.det_zpow theorem isUnit_det_zpow_iff {A : M} {z : ℤ} : IsUnit (A ^ z).det ↔ IsUnit A.det ∨ z = 0 := by induction' z using Int.induction_on with z _ z _ · simp · rw [← Int.ofNat_succ, zpow_natCast, det_pow, isUnit_pow_succ_iff, ← Int.ofNat_zero, Int.ofNat_inj] simp · rw [← neg_add', ← Int.ofNat_succ, zpow_neg_natCast, isUnit_nonsing_inv_det_iff, det_pow, isUnit_pow_succ_iff, neg_eq_zero, ← Int.ofNat_zero, Int.ofNat_inj] simp #align matrix.is_unit_det_zpow_iff Matrix.isUnit_det_zpow_iff theorem zpow_neg {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (-n) = (A ^ n)⁻¹ | (n : ℕ) => zpow_neg_natCast _ _ | -[n+1] => by rw [zpow_negSucc, neg_negSucc, zpow_natCast, nonsing_inv_nonsing_inv] rw [det_pow] exact h.pow _ #align matrix.zpow_neg Matrix.zpow_neg theorem inv_zpow' {A : M} (h : IsUnit A.det) (n : ℤ) : A⁻¹ ^ n = A ^ (-n) := by rw [zpow_neg h, inv_zpow] #align matrix.inv_zpow' Matrix.inv_zpow' theorem zpow_add_one {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (n + 1) = A ^ n * A | (n : ℕ) => by simp only [← Nat.cast_succ, pow_succ, zpow_natCast] | -[n+1] => calc A ^ (-(n + 1) + 1 : ℤ) = (A ^ n)⁻¹ := by rw [neg_add, neg_add_cancel_right, zpow_neg h, zpow_natCast] _ = (A * A ^ n)⁻¹ * A := by rw [mul_inv_rev, Matrix.mul_assoc, nonsing_inv_mul _ h, Matrix.mul_one] _ = A ^ (-(n + 1 : ℤ)) * A := by rw [zpow_neg h, ← Int.ofNat_succ, zpow_natCast, pow_succ'] #align matrix.zpow_add_one Matrix.zpow_add_one theorem zpow_sub_one {A : M} (h : IsUnit A.det) (n : ℤ) : A ^ (n - 1) = A ^ n * A⁻¹ := calc A ^ (n - 1) = A ^ (n - 1) * A * A⁻¹ := by rw [mul_assoc, mul_nonsing_inv _ h, mul_one] _ = A ^ n * A⁻¹ := by rw [← zpow_add_one h, sub_add_cancel] #align matrix.zpow_sub_one Matrix.zpow_sub_one theorem zpow_add {A : M} (ha : IsUnit A.det) (m n : ℤ) : A ^ (m + n) = A ^ m * A ^ n := by induction n using Int.induction_on with | hz => simp | hp n ihn => simp only [← add_assoc, zpow_add_one ha, ihn, mul_assoc] | hn n ihn => rw [zpow_sub_one ha, ← mul_assoc, ← ihn, ← zpow_sub_one ha, add_sub_assoc] #align matrix.zpow_add Matrix.zpow_add theorem zpow_add_of_nonpos {A : M} {m n : ℤ} (hm : m ≤ 0) (hn : n ≤ 0) : A ^ (m + n) = A ^ m * A ^ n := by rcases nonsing_inv_cancel_or_zero A with (⟨h, _⟩ | h) · exact zpow_add (isUnit_det_of_left_inverse h) m n · obtain ⟨k, rfl⟩ := exists_eq_neg_ofNat hm obtain ⟨l, rfl⟩ := exists_eq_neg_ofNat hn simp_rw [← neg_add, ← Int.ofNat_add, zpow_neg_natCast, ← inv_pow', h, pow_add] #align matrix.zpow_add_of_nonpos Matrix.zpow_add_of_nonpos
Mathlib/LinearAlgebra/Matrix/ZPow.lean
184
188
theorem zpow_add_of_nonneg {A : M} {m n : ℤ} (hm : 0 ≤ m) (hn : 0 ≤ n) : A ^ (m + n) = A ^ m * A ^ n := by
obtain ⟨k, rfl⟩ := eq_ofNat_of_zero_le hm obtain ⟨l, rfl⟩ := eq_ofNat_of_zero_le hn rw [← Int.ofNat_add, zpow_natCast, zpow_natCast, zpow_natCast, pow_add]
/- 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.Analysis.SpecialFunctions.Trigonometric.Arctan import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine #align_import geometry.euclidean.angle.unoriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Right-angled triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. ## 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/Pythagorean_theorem -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- Pythagorean theorem, if-and-only-if vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y #align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two /-- Pythagorean theorem, vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h #align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq' /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y #align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two /-- Pythagorean theorem, subtracting vectors, vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h #align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq' /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_add_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by rw [angle, inner_add_right, h, add_zero, real_inner_self_eq_norm_mul_norm] by_cases hx : ‖x‖ = 0; · simp [hx] rw [div_mul_eq_div_div, mul_self_div_self] #align inner_product_geometry.angle_add_eq_arccos_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_add_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hxy : ‖x + y‖ ^ 2 ≠ 0 := by rw [pow_two, norm_add_sq_eq_norm_sq_add_norm_sq_real h, ne_comm] refine ne_of_lt ?_ rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_eq_arcsin (div_nonneg (norm_nonneg _) (norm_nonneg _)), div_pow, one_sub_div hxy] nth_rw 1 [pow_two] rw [norm_add_sq_eq_norm_sq_add_norm_sq_real h, pow_two, add_sub_cancel_left, ← pow_two, ← div_pow, Real.sqrt_sq (div_nonneg (norm_nonneg _) (norm_nonneg _))] #align inner_product_geometry.angle_add_eq_arcsin_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_add_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by rw [angle_add_eq_arcsin_of_inner_eq_zero h (Or.inl h0), Real.arctan_eq_arcsin, ← div_mul_eq_div_div, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] nth_rw 3 [← Real.sqrt_sq (norm_nonneg x)] rw_mod_cast [← Real.sqrt_mul (sq_nonneg _), div_pow, pow_two, pow_two, mul_add, mul_one, mul_div, mul_comm (‖x‖ * ‖x‖), ← mul_div, div_self (mul_self_pos.2 (norm_ne_zero_iff.2 h0)).ne', mul_one] #align inner_product_geometry.angle_add_eq_arctan_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_add_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x + y) := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_pos, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] by_cases hx : x = 0; · simp [hx] rw [div_lt_one (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 hx)) (mul_self_nonneg _))), Real.lt_sqrt (norm_nonneg _), pow_two] simpa [hx] using h0 #align inner_product_geometry.angle_add_pos_of_inner_eq_zero InnerProductGeometry.angle_add_pos_of_inner_eq_zero /-- An angle in a right-angled triangle is at most `π / 2`. -/ theorem angle_add_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) ≤ π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_le_pi_div_two] exact div_nonneg (norm_nonneg _) (norm_nonneg _) #align inner_product_geometry.angle_add_le_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_le_pi_div_two_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/ theorem angle_add_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) < π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_lt_pi_div_two, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] exact div_pos (norm_pos_iff.2 h0) (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _))) #align inner_product_geometry.angle_add_lt_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_lt_pi_div_two_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) = ‖x‖ / ‖x + y‖ := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.cos_arccos (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_right (mul_self_nonneg _) #align inner_product_geometry.cos_angle_add_of_inner_eq_zero InnerProductGeometry.cos_angle_add_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x + y)) = ‖y‖ / ‖x + y‖ := by rw [angle_add_eq_arcsin_of_inner_eq_zero h h0, Real.sin_arcsin (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_left (mul_self_nonneg _) #align inner_product_geometry.sin_angle_add_of_inner_eq_zero InnerProductGeometry.sin_angle_add_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.tan (angle x (x + y)) = ‖y‖ / ‖x‖ := by by_cases h0 : x = 0; · simp [h0] rw [angle_add_eq_arctan_of_inner_eq_zero h h0, Real.tan_arctan] #align inner_product_geometry.tan_angle_add_of_inner_eq_zero InnerProductGeometry.tan_angle_add_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) * ‖x + y‖ = ‖x‖ := by rw [cos_angle_add_of_inner_eq_zero h] by_cases hxy : ‖x + y‖ = 0 · have h' := norm_add_sq_eq_norm_sq_add_norm_sq_real h rw [hxy, zero_mul, eq_comm, add_eq_zero_iff' (mul_self_nonneg ‖x‖) (mul_self_nonneg ‖y‖), mul_self_eq_zero] at h' simp [h'.1] · exact div_mul_cancel₀ _ hxy #align inner_product_geometry.cos_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.sin (angle x (x + y)) * ‖x + y‖ = ‖y‖ := by by_cases h0 : x = 0 ∧ y = 0; · simp [h0] rw [not_and_or] at h0 rw [sin_angle_add_of_inner_eq_zero h h0, div_mul_cancel₀] rw [← mul_self_ne_zero, norm_add_sq_eq_norm_sq_add_norm_sq_real h] refine (ne_of_lt ?_).symm rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) #align inner_product_geometry.sin_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : Real.tan (angle x (x + y)) * ‖x‖ = ‖y‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) <;> simp [h0] #align inner_product_geometry.tan_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : ‖x‖ / Real.cos (angle x (x + y)) = ‖x + y‖ := by rw [cos_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] · simp [h0] #align inner_product_geometry.norm_div_cos_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.sin (angle x (x + y)) = ‖x + y‖ := by rcases h0 with (h0 | h0); · simp [h0] rw [sin_angle_add_of_inner_eq_zero h (Or.inr h0), div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] #align inner_product_geometry.norm_div_sin_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.tan (angle x (x + y)) = ‖x‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · simp [h0] · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] #align inner_product_geometry.norm_div_tan_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem angle_sub_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) = Real.arccos (‖x‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arccos_of_inner_eq_zero h] #align inner_product_geometry.angle_sub_eq_arccos_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem angle_sub_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x - y) = Real.arcsin (‖y‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, angle_add_eq_arcsin_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.angle_sub_eq_arcsin_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem angle_sub_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) = Real.arctan (‖y‖ / ‖x‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arctan_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.angle_sub_eq_arctan_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is positive, version subtracting vectors. -/ theorem angle_sub_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x - y) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg] exact angle_add_pos_of_inner_eq_zero h h0 #align inner_product_geometry.angle_sub_pos_of_inner_eq_zero InnerProductGeometry.angle_sub_pos_of_inner_eq_zero /-- An angle in a right-angled triangle is at most `π / 2`, version subtracting vectors. -/ theorem angle_sub_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) ≤ π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_le_pi_div_two_of_inner_eq_zero h #align inner_product_geometry.angle_sub_le_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_sub_le_pi_div_two_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`, version subtracting vectors. -/ theorem angle_sub_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) < π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_lt_pi_div_two_of_inner_eq_zero h h0 #align inner_product_geometry.angle_sub_lt_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_sub_lt_pi_div_two_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x - y)) = ‖x‖ / ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, cos_angle_add_of_inner_eq_zero h] #align inner_product_geometry.cos_angle_sub_of_inner_eq_zero InnerProductGeometry.cos_angle_sub_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem sin_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x - y)) = ‖y‖ / ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, sin_angle_add_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.sin_angle_sub_of_inner_eq_zero InnerProductGeometry.sin_angle_sub_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem tan_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.tan (angle x (x - y)) = ‖y‖ / ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, tan_angle_add_of_inner_eq_zero h, norm_neg] #align inner_product_geometry.tan_angle_sub_of_inner_eq_zero InnerProductGeometry.tan_angle_sub_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ theorem cos_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x - y)) * ‖x - y‖ = ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, cos_angle_add_mul_norm_of_inner_eq_zero h] #align inner_product_geometry.cos_angle_sub_mul_norm_of_inner_eq_zero InnerProductGeometry.cos_angle_sub_mul_norm_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ theorem sin_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.sin (angle x (x - y)) * ‖x - y‖ = ‖y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, sin_angle_add_mul_norm_of_inner_eq_zero h, norm_neg] #align inner_product_geometry.sin_angle_sub_mul_norm_of_inner_eq_zero InnerProductGeometry.sin_angle_sub_mul_norm_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ theorem tan_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : Real.tan (angle x (x - y)) * ‖x‖ = ‖y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_eq_zero] at h0 rw [sub_eq_add_neg, tan_angle_add_mul_norm_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.tan_angle_sub_mul_norm_of_inner_eq_zero InnerProductGeometry.tan_angle_sub_mul_norm_of_inner_eq_zero /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_cos_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : ‖x‖ / Real.cos (angle x (x - y)) = ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_eq_zero] at h0 rw [sub_eq_add_neg, norm_div_cos_angle_add_of_inner_eq_zero h h0] #align inner_product_geometry.norm_div_cos_angle_sub_of_inner_eq_zero InnerProductGeometry.norm_div_cos_angle_sub_of_inner_eq_zero /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_sin_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.sin (angle x (x - y)) = ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg, ← norm_neg, norm_div_sin_angle_add_of_inner_eq_zero h h0] #align inner_product_geometry.norm_div_sin_angle_sub_of_inner_eq_zero InnerProductGeometry.norm_div_sin_angle_sub_of_inner_eq_zero /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ theorem norm_div_tan_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.tan (angle x (x - y)) = ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg, ← norm_neg, norm_div_tan_angle_add_of_inner_eq_zero h h0] #align inner_product_geometry.norm_div_tan_angle_sub_of_inner_eq_zero InnerProductGeometry.norm_div_tan_angle_sub_of_inner_eq_zero end InnerProductGeometry namespace EuclideanGeometry open InnerProductGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- **Pythagorean theorem**, if-and-only-if angle-at-point form. -/ theorem dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two (p1 p2 p3 : P) : dist p1 p3 * dist p1 p3 = dist p1 p2 * dist p1 p2 + dist p3 p2 * dist p3 p2 ↔ ∠ p1 p2 p3 = π / 2 := by erw [dist_comm p3 p2, dist_eq_norm_vsub V p1 p3, dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p2 p3, ← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two, vsub_sub_vsub_cancel_right p1, ← neg_vsub_eq_vsub_rev p2 p3, norm_neg] #align euclidean_geometry.dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two EuclideanGeometry.dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_eq_arccos_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : ∠ p₂ p₃ p₁ = Real.arccos (dist p₃ p₂ / dist p₁ p₃) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arccos_of_inner_eq_zero h] #align euclidean_geometry.angle_eq_arccos_of_angle_eq_pi_div_two EuclideanGeometry.angle_eq_arccos_of_angle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_eq_arcsin_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ ≠ p₂) : ∠ p₂ p₃ p₁ = Real.arcsin (dist p₁ p₂ / dist p₁ p₃) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, @ne_comm _ p₃, ← @vsub_ne_zero V _ _ _ p₂, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arcsin_of_inner_eq_zero h h0] #align euclidean_geometry.angle_eq_arcsin_of_angle_eq_pi_div_two EuclideanGeometry.angle_eq_arcsin_of_angle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_eq_arctan_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₃ ≠ p₂) : ∠ p₂ p₃ p₁ = Real.arctan (dist p₁ p₂ / dist p₃ p₂) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arctan_of_inner_eq_zero h h0] #align euclidean_geometry.angle_eq_arctan_of_angle_eq_pi_div_two EuclideanGeometry.angle_eq_arctan_of_angle_eq_pi_div_two /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_pos_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ = p₂) : 0 < ∠ p₂ p₃ p₁ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, eq_comm, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_pos_of_inner_eq_zero h h0 #align euclidean_geometry.angle_pos_of_angle_eq_pi_div_two EuclideanGeometry.angle_pos_of_angle_eq_pi_div_two /-- An angle in a right-angled triangle is at most `π / 2`. -/ theorem angle_le_pi_div_two_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : ∠ p₂ p₃ p₁ ≤ π / 2 := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_le_pi_div_two_of_inner_eq_zero h #align euclidean_geometry.angle_le_pi_div_two_of_angle_eq_pi_div_two EuclideanGeometry.angle_le_pi_div_two_of_angle_eq_pi_div_two /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/ theorem angle_lt_pi_div_two_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₃ ≠ p₂) : ∠ p₂ p₃ p₁ < π / 2 := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V] at h0 rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_lt_pi_div_two_of_inner_eq_zero h h0 #align euclidean_geometry.angle_lt_pi_div_two_of_angle_eq_pi_div_two EuclideanGeometry.angle_lt_pi_div_two_of_angle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.cos (∠ p₂ p₃ p₁) = dist p₃ p₂ / dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, cos_angle_add_of_inner_eq_zero h] #align euclidean_geometry.cos_angle_of_angle_eq_pi_div_two EuclideanGeometry.cos_angle_of_angle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ ≠ p₂) : Real.sin (∠ p₂ p₃ p₁) = dist p₁ p₂ / dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, @ne_comm _ p₃, ← @vsub_ne_zero V _ _ _ p₂, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, sin_angle_add_of_inner_eq_zero h h0] #align euclidean_geometry.sin_angle_of_angle_eq_pi_div_two EuclideanGeometry.sin_angle_of_angle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.tan (∠ p₂ p₃ p₁) = dist p₁ p₂ / dist p₃ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, tan_angle_add_of_inner_eq_zero h] #align euclidean_geometry.tan_angle_of_angle_eq_pi_div_two EuclideanGeometry.tan_angle_of_angle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.cos (∠ p₂ p₃ p₁) * dist p₁ p₃ = dist p₃ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, cos_angle_add_mul_norm_of_inner_eq_zero h] #align euclidean_geometry.cos_angle_mul_dist_of_angle_eq_pi_div_two EuclideanGeometry.cos_angle_mul_dist_of_angle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.sin (∠ p₂ p₃ p₁) * dist p₁ p₃ = dist p₁ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, sin_angle_add_mul_norm_of_inner_eq_zero h] #align euclidean_geometry.sin_angle_mul_dist_of_angle_eq_pi_div_two EuclideanGeometry.sin_angle_mul_dist_of_angle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ = p₂ ∨ p₃ ≠ p₂) : Real.tan (∠ p₂ p₃ p₁) * dist p₃ p₂ = dist p₁ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, tan_angle_add_mul_norm_of_inner_eq_zero h h0] #align euclidean_geometry.tan_angle_mul_dist_of_angle_eq_pi_div_two EuclideanGeometry.tan_angle_mul_dist_of_angle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/
Mathlib/Geometry/Euclidean/Angle/Unoriented/RightAngle.lean
487
493
theorem dist_div_cos_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ = p₂ ∨ p₃ ≠ p₂) : dist p₃ p₂ / Real.cos (∠ p₂ p₃ p₁) = dist p₁ p₃ := by
rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, norm_div_cos_angle_add_of_inner_eq_zero h h0]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth -/ import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.MeasureTheory.Measure.Haar.Quotient import Mathlib.MeasureTheory.Constructions.Polish import Mathlib.MeasureTheory.Integral.IntervalIntegral import Mathlib.Topology.Algebra.Order.Floor #align_import measure_theory.integral.periodic from "leanprover-community/mathlib"@"9f55d0d4363ae59948c33864cbc52e0b12e0e8ce" /-! # Integrals of periodic functions In this file we prove that the half-open interval `Ioc t (t + T)` in `ℝ` is a fundamental domain of the action of the subgroup `ℤ ∙ T` on `ℝ`. A consequence is `AddCircle.measurePreserving_mk`: the covering map from `ℝ` to the "additive circle" `ℝ ⧸ (ℤ ∙ T)` is measure-preserving, with respect to the restriction of Lebesgue measure to `Ioc t (t + T)` (upstairs) and with respect to Haar measure (downstairs). Another consequence (`Function.Periodic.intervalIntegral_add_eq` and related declarations) is that `∫ x in t..t + T, f x = ∫ x in s..s + T, f x` for any (not necessarily measurable) function with period `T`. -/ open Set Function MeasureTheory MeasureTheory.Measure TopologicalSpace AddSubgroup intervalIntegral open scoped MeasureTheory NNReal ENNReal @[measurability] protected theorem AddCircle.measurable_mk' {a : ℝ} : Measurable (β := AddCircle a) ((↑) : ℝ → AddCircle a) := Continuous.measurable <| AddCircle.continuous_mk' a #align add_circle.measurable_mk' AddCircle.measurable_mk' theorem isAddFundamentalDomain_Ioc {T : ℝ} (hT : 0 < T) (t : ℝ) (μ : Measure ℝ := by volume_tac) : IsAddFundamentalDomain (AddSubgroup.zmultiples T) (Ioc t (t + T)) μ := by refine IsAddFundamentalDomain.mk' measurableSet_Ioc.nullMeasurableSet fun x => ?_ have : Bijective (codRestrict (fun n : ℤ => n • T) (AddSubgroup.zmultiples T) _) := (Equiv.ofInjective (fun n : ℤ => n • T) (zsmul_strictMono_left hT).injective).bijective refine this.existsUnique_iff.2 ?_ simpa only [add_comm x] using existsUnique_add_zsmul_mem_Ioc hT x t #align is_add_fundamental_domain_Ioc isAddFundamentalDomain_Ioc theorem isAddFundamentalDomain_Ioc' {T : ℝ} (hT : 0 < T) (t : ℝ) (μ : Measure ℝ := by volume_tac) : IsAddFundamentalDomain (AddSubgroup.op <| .zmultiples T) (Ioc t (t + T)) μ := by refine IsAddFundamentalDomain.mk' measurableSet_Ioc.nullMeasurableSet fun x => ?_ have : Bijective (codRestrict (fun n : ℤ => n • T) (AddSubgroup.zmultiples T) _) := (Equiv.ofInjective (fun n : ℤ => n • T) (zsmul_strictMono_left hT).injective).bijective refine (AddSubgroup.equivOp _).bijective.comp this |>.existsUnique_iff.2 ?_ simpa using existsUnique_add_zsmul_mem_Ioc hT x t #align is_add_fundamental_domain_Ioc' isAddFundamentalDomain_Ioc' namespace AddCircle variable (T : ℝ) [hT : Fact (0 < T)] /-- Equip the "additive circle" `ℝ ⧸ (ℤ ∙ T)` with, as a standard measure, the Haar measure of total mass `T` -/ noncomputable instance measureSpace : MeasureSpace (AddCircle T) := { QuotientAddGroup.measurableSpace _ with volume := ENNReal.ofReal T • addHaarMeasure ⊤ } #align add_circle.measure_space AddCircle.measureSpace #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. -/ @[simp, nolint simpNF] protected theorem measure_univ : volume (Set.univ : Set (AddCircle T)) = ENNReal.ofReal T := by dsimp [volume] rw [← PositiveCompacts.coe_top] simp [addHaarMeasure_self (G := AddCircle T), -PositiveCompacts.coe_top] #align add_circle.measure_univ AddCircle.measure_univ instance : IsAddHaarMeasure (volume : Measure (AddCircle T)) := IsAddHaarMeasure.smul _ (by simp [hT.out]) ENNReal.ofReal_ne_top instance isFiniteMeasure : IsFiniteMeasure (volume : Measure (AddCircle T)) where measure_univ_lt_top := by simp #align add_circle.is_finite_measure AddCircle.isFiniteMeasure instance : HasAddFundamentalDomain (AddSubgroup.op <| .zmultiples T) ℝ where ExistsIsAddFundamentalDomain := ⟨Ioc 0 (0 + T), isAddFundamentalDomain_Ioc' Fact.out 0⟩ instance : AddQuotientMeasureEqMeasurePreimage volume (volume : Measure (AddCircle T)) := by apply MeasureTheory.leftInvariantIsAddQuotientMeasureEqMeasurePreimage simp [(isAddFundamentalDomain_Ioc' hT.out 0).covolume_eq_volume, AddCircle.measure_univ] /-- The covering map from `ℝ` to the "additive circle" `ℝ ⧸ (ℤ ∙ T)` is measure-preserving, considered with respect to the standard measure (defined to be the Haar measure of total mass `T`) on the additive circle, and with respect to the restriction of Lebsegue measure on `ℝ` to an interval (t, t + T]. -/ protected theorem measurePreserving_mk (t : ℝ) : MeasurePreserving (β := AddCircle T) ((↑) : ℝ → AddCircle T) (volume.restrict (Ioc t (t + T))) := measurePreserving_quotientAddGroup_mk_of_AddQuotientMeasureEqMeasurePreimage volume (𝓕 := Ioc t (t+T)) (isAddFundamentalDomain_Ioc' hT.out _) _ #align add_circle.measure_preserving_mk AddCircle.measurePreserving_mk lemma add_projection_respects_measure (t : ℝ) {U : Set (AddCircle T)} (meas_U : MeasurableSet U) : volume U = volume (QuotientAddGroup.mk ⁻¹' U ∩ (Ioc t (t + T))) := (isAddFundamentalDomain_Ioc' hT.out _).addProjection_respects_measure_apply (volume : Measure (AddCircle T)) meas_U
Mathlib/MeasureTheory/Integral/Periodic.lean
107
124
theorem volume_closedBall {x : AddCircle T} (ε : ℝ) : volume (Metric.closedBall x ε) = ENNReal.ofReal (min T (2 * ε)) := by
have hT' : |T| = T := abs_eq_self.mpr hT.out.le let I := Ioc (-(T / 2)) (T / 2) have h₁ : ε < T / 2 → Metric.closedBall (0 : ℝ) ε ∩ I = Metric.closedBall (0 : ℝ) ε := by intro hε rw [inter_eq_left, Real.closedBall_eq_Icc, zero_sub, zero_add] rintro y ⟨hy₁, hy₂⟩; constructor <;> linarith have h₂ : (↑) ⁻¹' Metric.closedBall (0 : AddCircle T) ε ∩ I = if ε < T / 2 then Metric.closedBall (0 : ℝ) ε else I := by conv_rhs => rw [← if_ctx_congr (Iff.rfl : ε < T / 2 ↔ ε < T / 2) h₁ fun _ => rfl, ← hT'] apply coe_real_preimage_closedBall_inter_eq simpa only [hT', Real.closedBall_eq_Icc, zero_add, zero_sub] using Ioc_subset_Icc_self rw [addHaar_closedBall_center, add_projection_respects_measure T (-(T/2)) measurableSet_closedBall, (by linarith : -(T / 2) + T = T / 2), h₂] by_cases hε : ε < T / 2 · simp [hε, min_eq_right (by linarith : 2 * ε ≤ T)] · simp [I, hε, min_eq_left (by linarith : T ≤ 2 * ε)]
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Function.AEEqFun.DomAct import Mathlib.MeasureTheory.Function.LpSpace /-! # Action of `Mᵈᵐᵃ` on `Lᵖ` spaces In this file we define action of `Mᵈᵐᵃ` on `MeasureTheory.Lp E p μ` If `f : α → E` is a function representing an equivalence class in `Lᵖ(α, E)`, `M` acts on `α`, and `c : M`, then `(.mk c : Mᵈᵐᵃ) • [f]` is represented by the function `a ↦ f (c • a)`. We also prove basic properties of this action. -/ set_option autoImplicit true open MeasureTheory Filter open scoped ENNReal namespace DomMulAct variable {M N α E : Type*} [MeasurableSpace M] [MeasurableSpace N] [MeasurableSpace α] [NormedAddCommGroup E] {μ : MeasureTheory.Measure α} {p : ℝ≥0∞} section SMul variable [SMul M α] [SMulInvariantMeasure M α μ] [MeasurableSMul M α] @[to_additive] instance : SMul Mᵈᵐᵃ (Lp E p μ) where smul c f := Lp.compMeasurePreserving (mk.symm c • ·) (measurePreserving_smul _ _) f @[to_additive (attr := simp)] theorem smul_Lp_val (c : Mᵈᵐᵃ) (f : Lp E p μ) : (c • f).1 = c • f.1 := rfl @[to_additive] theorem smul_Lp_ae_eq (c : Mᵈᵐᵃ) (f : Lp E p μ) : c • f =ᵐ[μ] (f <| mk.symm c • ·) := Lp.coeFn_compMeasurePreserving _ _ @[to_additive] theorem mk_smul_toLp (c : M) {f : α → E} (hf : Memℒp f p μ) : mk c • hf.toLp f = (hf.comp_measurePreserving <| measurePreserving_smul c μ).toLp (f <| c • ·) := rfl @[to_additive (attr := simp)] theorem smul_Lp_const [IsFiniteMeasure μ] (c : Mᵈᵐᵃ) (a : E) : c • Lp.const p μ a = Lp.const p μ a := rfl instance [SMul N α] [SMulCommClass M N α] [SMulInvariantMeasure N α μ] [MeasurableSMul N α] : SMulCommClass Mᵈᵐᵃ Nᵈᵐᵃ (Lp E p μ) := Subtype.val_injective.smulCommClass (fun _ _ ↦ rfl) fun _ _ ↦ rfl instance [NormedRing 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E] : SMulCommClass Mᵈᵐᵃ 𝕜 (Lp E p μ) := Subtype.val_injective.smulCommClass (fun _ _ ↦ rfl) fun _ _ ↦ rfl instance [NormedRing 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E] : SMulCommClass 𝕜 Mᵈᵐᵃ (Lp E p μ) := .symm _ _ _ -- We don't have a typeclass for additive versions of the next few lemmas -- Should we add `AddDistribAddAction` with `to_additive` both from `MulDistribMulAction` -- and `DistribMulAction`? @[to_additive] theorem smul_Lp_add (c : Mᵈᵐᵃ) : ∀ f g : Lp E p μ, c • (f + g) = c • f + c • g := by rintro ⟨⟨⟩, _⟩ ⟨⟨⟩, _⟩; rfl attribute [simp] DomAddAct.vadd_Lp_add @[to_additive (attr := simp 1001)] theorem smul_Lp_zero (c : Mᵈᵐᵃ) : c • (0 : Lp E p μ) = 0 := rfl @[to_additive] theorem smul_Lp_neg (c : Mᵈᵐᵃ) (f : Lp E p μ) : c • (-f) = -(c • f) := by rcases f with ⟨⟨_⟩, _⟩; rfl @[to_additive]
Mathlib/MeasureTheory/Function/LpSpace/DomAct/Basic.lean
82
83
theorem smul_Lp_sub (c : Mᵈᵐᵃ) : ∀ f g : Lp E p μ, c • (f - g) = c • f - c • g := by
rintro ⟨⟨⟩, _⟩ ⟨⟨⟩, _⟩; rfl
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison -/ import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.List.InsertNth import Mathlib.Logic.Relation import Mathlib.Logic.Small.Defs import Mathlib.Order.GameAdd #align_import set_theory.game.pgame from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Combinatorial (pre-)games. The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We construct "pregames", define an ordering and arithmetic operations on them, then show that the operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`. The surreal numbers will be built as a quotient of a subtype of pregames. A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor takes two types (thought of as indexing the possible moves for the players Left and Right), and a pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting game after making a move). Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`. ## Conway induction By construction, the induction principle for pregames is exactly "Conway induction". That is, to prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove that for every pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds for `g`. While it is often convenient to work "by induction" on pregames, in some situations this becomes awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`, `SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`. There is a relation `PGame.Subsequent p q`, saying that `p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance `WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying on this relation. ## Order properties Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won by Left as the second player. It turns out to be quite convenient to define various relations on top of these. We define the "less or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won by the first player. Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and `lf_def` give a recursive characterisation of each relation in terms of themselves two moves later. The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves. Later, games will be defined as the quotient by the `≈` relation; that is to say, the `Antisymmetrization` of `SetTheory.PGame`. ## Algebraic structures We next turn to defining the operations necessary to make games into a commutative additive group. Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR + y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$. The order structures interact in the expected way with addition, so we have ``` theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry ``` We show that these operations respect the equivalence relation, and hence descend to games. At the level of games, these operations satisfy all the laws of a commutative group. To prove the necessary equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`. ## Future work * The theory of dominated and reversible positions, and unique normal form for short games. * Analysis of basic domineering positions. * Hex. * Temperature. * The development of surreal numbers, based on this development of combinatorial games, is still quite incomplete. ## References The material here is all drawn from * [Conway, *On numbers and games*][conway2001] An interested reader may like to formalise some of the material from * [Andreas Blass, *A game semantics for linear logic*][MR1167694] * [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997] -/ set_option autoImplicit true namespace SetTheory open Function Relation -- We'd like to be able to use multi-character auto-implicits in this file. set_option relaxedAutoImplicit true /-! ### Pre-game moves -/ /-- The type of pre-games, before we have quotiented by equivalence (`PGame.Setoid`). In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a pre-game is built inductively from two families of pre-games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. -/ inductive PGame : Type (u + 1) | mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame #align pgame SetTheory.PGame compile_inductive% PGame namespace PGame /-- The indexing type for allowable moves by Left. -/ def LeftMoves : PGame → Type u | mk l _ _ _ => l #align pgame.left_moves SetTheory.PGame.LeftMoves /-- The indexing type for allowable moves by Right. -/ def RightMoves : PGame → Type u | mk _ r _ _ => r #align pgame.right_moves SetTheory.PGame.RightMoves /-- The new game after Left makes an allowed move. -/ def moveLeft : ∀ g : PGame, LeftMoves g → PGame | mk _l _ L _ => L #align pgame.move_left SetTheory.PGame.moveLeft /-- The new game after Right makes an allowed move. -/ def moveRight : ∀ g : PGame, RightMoves g → PGame | mk _ _r _ R => R #align pgame.move_right SetTheory.PGame.moveRight @[simp] theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl := rfl #align pgame.left_moves_mk SetTheory.PGame.leftMoves_mk @[simp] theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL := rfl #align pgame.move_left_mk SetTheory.PGame.moveLeft_mk @[simp] theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr := rfl #align pgame.right_moves_mk SetTheory.PGame.rightMoves_mk @[simp] theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR := rfl #align pgame.move_right_mk SetTheory.PGame.moveRight_mk -- TODO define this at the level of games, as well, and perhaps also for finsets of games. /-- Construct a pre-game from list of pre-games describing the available moves for Left and Right. -/ def ofLists (L R : List PGame.{u}) : PGame.{u} := mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L.get i.down) fun j ↦ R.get j.down #align pgame.of_lists SetTheory.PGame.ofLists theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) := rfl #align pgame.left_moves_of_lists SetTheory.PGame.leftMoves_ofLists theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) := rfl #align pgame.right_moves_of_lists SetTheory.PGame.rightMoves_ofLists /-- Converts a number into a left move for `ofLists`. -/ def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves := ((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_left_moves SetTheory.PGame.toOfListsLeftMoves /-- Converts a number into a right move for `ofLists`. -/ def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves := ((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_right_moves SetTheory.PGame.toOfListsRightMoves theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) : (ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i := rfl #align pgame.of_lists_move_left SetTheory.PGame.ofLists_moveLeft @[simp] theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) : (ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) := rfl #align pgame.of_lists_move_left' SetTheory.PGame.ofLists_moveLeft' theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) : (ofLists L R).moveRight (toOfListsRightMoves i) = R.get i := rfl #align pgame.of_lists_move_right SetTheory.PGame.ofLists_moveRight @[simp] theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) : (ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) := rfl #align pgame.of_lists_move_right' SetTheory.PGame.ofLists_moveRight' /-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`. Both this and `PGame.recOn` describe Conway induction on games. -/ @[elab_as_elim] def moveRecOn {C : PGame → Sort*} (x : PGame) (IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x := x.recOn fun yl yr yL yR => IH (mk yl yr yL yR) #align pgame.move_rec_on SetTheory.PGame.moveRecOn /-- `IsOption x y` means that `x` is either a left or right option for `y`. -/ @[mk_iff] inductive IsOption : PGame → PGame → Prop | moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x | moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x #align pgame.is_option SetTheory.PGame.IsOption theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : (xL i).IsOption (mk xl xr xL xR) := @IsOption.moveLeft (mk _ _ _ _) i #align pgame.is_option.mk_left SetTheory.PGame.IsOption.mk_left theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) : (xR i).IsOption (mk xl xr xL xR) := @IsOption.moveRight (mk _ _ _ _) i #align pgame.is_option.mk_right SetTheory.PGame.IsOption.mk_right theorem wf_isOption : WellFounded IsOption := ⟨fun x => moveRecOn x fun x IHl IHr => Acc.intro x fun y h => by induction' h with _ i _ j · exact IHl i · exact IHr j⟩ #align pgame.wf_is_option SetTheory.PGame.wf_isOption /-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from `y`. It is the transitive closure of `IsOption`. -/ def Subsequent : PGame → PGame → Prop := TransGen IsOption #align pgame.subsequent SetTheory.PGame.Subsequent instance : IsTrans _ Subsequent := inferInstanceAs <| IsTrans _ (TransGen _) @[trans] theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z := TransGen.trans #align pgame.subsequent.trans SetTheory.PGame.Subsequent.trans theorem wf_subsequent : WellFounded Subsequent := wf_isOption.transGen #align pgame.wf_subsequent SetTheory.PGame.wf_subsequent instance : WellFoundedRelation PGame := ⟨_, wf_subsequent⟩ @[simp] theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x := TransGen.single (IsOption.moveLeft i) #align pgame.subsequent.move_left SetTheory.PGame.Subsequent.moveLeft @[simp] theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x := TransGen.single (IsOption.moveRight j) #align pgame.subsequent.move_right SetTheory.PGame.Subsequent.moveRight @[simp] theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : Subsequent (xL i) (mk xl xr xL xR) := @Subsequent.moveLeft (mk _ _ _ _) i #align pgame.subsequent.mk_left SetTheory.PGame.Subsequent.mk_left @[simp] theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) : Subsequent (xR j) (mk xl xr xL xR) := @Subsequent.moveRight (mk _ _ _ _) j #align pgame.subsequent.mk_right SetTheory.PGame.Subsequent.mk_right /-- Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs of definitions using well-founded recursion on `PGame`. -/ macro "pgame_wf_tac" : tactic => `(tactic| solve_by_elim (config := { maxDepth := 8 }) [Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right, Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right, Subsequent.trans] ) -- Register some consequences of pgame_wf_tac as simp-lemmas for convenience -- (which are applied by default for WF goals) -- This is different from mk_right from the POV of the simplifier, -- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency. @[simp] theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) : Subsequent (xR j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac -- Porting note: linter claims these lemmas don't simplify? open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right' moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right /-! ### Basic pre-games -/ /-- The pre-game `Zero` is defined by `0 = { | }`. -/ instance : Zero PGame := ⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩ @[simp] theorem zero_leftMoves : LeftMoves 0 = PEmpty := rfl #align pgame.zero_left_moves SetTheory.PGame.zero_leftMoves @[simp] theorem zero_rightMoves : RightMoves 0 = PEmpty := rfl #align pgame.zero_right_moves SetTheory.PGame.zero_rightMoves instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_left_moves SetTheory.PGame.isEmpty_zero_leftMoves instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_right_moves SetTheory.PGame.isEmpty_zero_rightMoves instance : Inhabited PGame := ⟨0⟩ /-- The pre-game `One` is defined by `1 = { 0 | }`. -/ instance instOnePGame : One PGame := ⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩ @[simp] theorem one_leftMoves : LeftMoves 1 = PUnit := rfl #align pgame.one_left_moves SetTheory.PGame.one_leftMoves @[simp] theorem one_moveLeft (x) : moveLeft 1 x = 0 := rfl #align pgame.one_move_left SetTheory.PGame.one_moveLeft @[simp] theorem one_rightMoves : RightMoves 1 = PEmpty := rfl #align pgame.one_right_moves SetTheory.PGame.one_rightMoves instance uniqueOneLeftMoves : Unique (LeftMoves 1) := PUnit.unique #align pgame.unique_one_left_moves SetTheory.PGame.uniqueOneLeftMoves instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) := instIsEmptyPEmpty #align pgame.is_empty_one_right_moves SetTheory.PGame.isEmpty_one_rightMoves /-! ### Pre-game order relations -/ /-- The less or equal relation on pre-games. If `0 ≤ x`, then Left can win `x` as the second player. -/ instance le : LE PGame := ⟨Sym2.GameAdd.fix wf_isOption fun x y le => (∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧ ∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩ /-- The less or fuzzy relation on pre-games. If `0 ⧏ x`, then Left can win `x` as the first player. -/ def LF (x y : PGame) : Prop := ¬y ≤ x #align pgame.lf SetTheory.PGame.LF @[inherit_doc] scoped infixl:50 " ⧏ " => PGame.LF @[simp] protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x := Iff.rfl #align pgame.not_le SetTheory.PGame.not_le @[simp] theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x := Classical.not_not #align pgame.not_lf SetTheory.PGame.not_lf theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x := not_lf.2 #align has_le.le.not_gf LE.le.not_gf theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x := id #align pgame.lf.not_ge SetTheory.PGame.LF.not_ge /-- Definition of `x ≤ y` on pre-games, in terms of `⧏`. The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to moves by Right. -/ theorem le_iff_forall_lf {x y : PGame} : x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by unfold LE.le le simp only rw [Sym2.GameAdd.fix_eq] rfl #align pgame.le_iff_forall_lf SetTheory.PGame.le_iff_forall_lf /-- Definition of `x ≤ y` on pre-games built using the constructor. -/ @[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j := le_iff_forall_lf #align pgame.mk_le_mk SetTheory.PGame.mk_le_mk theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) : x ≤ y := le_iff_forall_lf.2 ⟨h₁, h₂⟩ #align pgame.le_of_forall_lf SetTheory.PGame.le_of_forall_lf /-- Definition of `x ⧏ y` on pre-games, in terms of `≤`. The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to moves by Right. -/ theorem lf_iff_exists_le {x y : PGame} : x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [LF, le_iff_forall_lf, not_and_or] simp #align pgame.lf_iff_exists_le SetTheory.PGame.lf_iff_exists_le /-- Definition of `x ⧏ y` on pre-games built using the constructor. -/ @[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR := lf_iff_exists_le #align pgame.mk_lf_mk SetTheory.PGame.mk_lf_mk theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by rw [← PGame.not_le] apply em #align pgame.le_or_gf SetTheory.PGame.le_or_gf theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y := (le_iff_forall_lf.1 h).1 i #align pgame.move_left_lf_of_le SetTheory.PGame.moveLeft_lf_of_le alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le #align has_le.le.move_left_lf LE.le.moveLeft_lf theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j := (le_iff_forall_lf.1 h).2 j #align pgame.lf_move_right_of_le SetTheory.PGame.lf_moveRight_of_le alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le #align has_le.le.lf_move_right LE.le.lf_moveRight theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y := lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩ #align pgame.lf_of_move_right_le SetTheory.PGame.lf_of_moveRight_le theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y := lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩ #align pgame.lf_of_le_move_left SetTheory.PGame.lf_of_le_moveLeft theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y := moveLeft_lf_of_le #align pgame.lf_of_le_mk SetTheory.PGame.lf_of_le_mk theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j := lf_moveRight_of_le #align pgame.lf_of_mk_le SetTheory.PGame.lf_of_mk_le theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y := @lf_of_moveRight_le (mk _ _ _ _) y j #align pgame.mk_lf_of_le SetTheory.PGame.mk_lf_of_le theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR := @lf_of_le_moveLeft x (mk _ _ _ _) i #align pgame.lf_mk_of_le SetTheory.PGame.lf_mk_of_le /- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic reorderings. This auxiliary lemma is used during said induction. -/ private theorem le_trans_aux {x y z : PGame} (h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i) (h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i) fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j instance : Preorder PGame := { PGame.le with le_refl := fun x => by induction' x with _ _ _ _ IHl IHr exact le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i) le_trans := by suffices ∀ {x y z : PGame}, (x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from fun x y z => this.1 intro x y z induction' x with xl xr xL xR IHxl IHxr generalizing y z induction' y with yl yr yL yR IHyl IHyr generalizing z induction' z with zl zr zL zR IHzl IHzr exact ⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2, le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1, le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩ lt := fun x y => x ≤ y ∧ x ⧏ y } theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y := Iff.rfl #align pgame.lt_iff_le_and_lf SetTheory.PGame.lt_iff_le_and_lf theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩ #align pgame.lt_of_le_of_lf SetTheory.PGame.lt_of_le_of_lf theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y := h.2 #align pgame.lf_of_lt SetTheory.PGame.lf_of_lt alias _root_.LT.lt.lf := lf_of_lt #align has_lt.lt.lf LT.lt.lf theorem lf_irrefl (x : PGame) : ¬x ⧏ x := le_rfl.not_gf #align pgame.lf_irrefl SetTheory.PGame.lf_irrefl instance : IsIrrefl _ (· ⧏ ·) := ⟨lf_irrefl⟩ @[trans] theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by rw [← PGame.not_le] at h₂ ⊢ exact fun h₃ => h₂ (h₃.trans h₁) #align pgame.lf_of_le_of_lf SetTheory.PGame.lf_of_le_of_lf -- Porting note (#10754): added instance instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩ @[trans] theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by rw [← PGame.not_le] at h₁ ⊢ exact fun h₃ => h₁ (h₂.trans h₃) #align pgame.lf_of_lf_of_le SetTheory.PGame.lf_of_lf_of_le -- Porting note (#10754): added instance instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩ alias _root_.LE.le.trans_lf := lf_of_le_of_lf #align has_le.le.trans_lf LE.le.trans_lf alias LF.trans_le := lf_of_lf_of_le #align pgame.lf.trans_le SetTheory.PGame.LF.trans_le @[trans] theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z := h₁.le.trans_lf h₂ #align pgame.lf_of_lt_of_lf SetTheory.PGame.lf_of_lt_of_lf @[trans] theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z := h₁.trans_le h₂.le #align pgame.lf_of_lf_of_lt SetTheory.PGame.lf_of_lf_of_lt alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf #align has_lt.lt.trans_lf LT.lt.trans_lf alias LF.trans_lt := lf_of_lf_of_lt #align pgame.lf.trans_lt SetTheory.PGame.LF.trans_lt theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x := le_rfl.moveLeft_lf #align pgame.move_left_lf SetTheory.PGame.moveLeft_lf theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j := le_rfl.lf_moveRight #align pgame.lf_move_right SetTheory.PGame.lf_moveRight theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR := @moveLeft_lf (mk _ _ _ _) i #align pgame.lf_mk SetTheory.PGame.lf_mk theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j := @lf_moveRight (mk _ _ _ _) j #align pgame.mk_lf SetTheory.PGame.mk_lf /-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is preferred over `⧏`. -/ theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) : x ≤ y := le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf #align pgame.le_of_forall_lt SetTheory.PGame.le_of_forall_lt /-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/ theorem le_def {x y : PGame} : x ≤ y ↔ (∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧ ∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by rw [le_iff_forall_lf] conv => lhs simp only [lf_iff_exists_le] #align pgame.le_def SetTheory.PGame.le_def /-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/ theorem lf_def {x y : PGame} : x ⧏ y ↔ (∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by rw [lf_iff_exists_le] conv => lhs simp only [le_iff_forall_lf] #align pgame.lf_def SetTheory.PGame.lf_def /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/ theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by rw [le_iff_forall_lf] simp #align pgame.zero_le_lf SetTheory.PGame.zero_le_lf /-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/ theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by rw [le_iff_forall_lf] simp #align pgame.le_zero_lf SetTheory.PGame.le_zero_lf /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/ theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by rw [lf_iff_exists_le] simp #align pgame.zero_lf_le SetTheory.PGame.zero_lf_le /-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/ theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by rw [lf_iff_exists_le] simp #align pgame.lf_zero_le SetTheory.PGame.lf_zero_le /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/
Mathlib/SetTheory/Game/PGame.lean
671
673
theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by
rw [le_def] simp
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Group.Subsemigroup.Operations import Mathlib.Algebra.Group.Nat import Mathlib.GroupTheory.GroupAction.Defs #align_import group_theory.submonoid.operations from "leanprover-community/mathlib"@"cf8e77c636317b059a8ce20807a29cf3772a0640" /-! # Operations on `Submonoid`s In this file we define various operations on `Submonoid`s and `MonoidHom`s. ## Main definitions ### Conversion between multiplicative and additive definitions * `Submonoid.toAddSubmonoid`, `Submonoid.toAddSubmonoid'`, `AddSubmonoid.toSubmonoid`, `AddSubmonoid.toSubmonoid'`: convert between multiplicative and additive submonoids of `M`, `Multiplicative M`, and `Additive M`. These are stated as `OrderIso`s. ### (Commutative) monoid structure on a submonoid * `Submonoid.toMonoid`, `Submonoid.toCommMonoid`: a submonoid inherits a (commutative) monoid structure. ### Group actions by submonoids * `Submonoid.MulAction`, `Submonoid.DistribMulAction`: a submonoid inherits (distributive) multiplicative actions. ### Operations on submonoids * `Submonoid.comap`: preimage of a submonoid under a monoid homomorphism as a submonoid of the domain; * `Submonoid.map`: image of a submonoid under a monoid homomorphism as a submonoid of the codomain; * `Submonoid.prod`: product of two submonoids `s : Submonoid M` and `t : Submonoid N` as a submonoid of `M × N`; ### Monoid homomorphisms between submonoid * `Submonoid.subtype`: embedding of a submonoid into the ambient monoid. * `Submonoid.inclusion`: given two submonoids `S`, `T` such that `S ≤ T`, `S.inclusion T` is the inclusion of `S` into `T` as a monoid homomorphism; * `MulEquiv.submonoidCongr`: converts a proof of `S = T` into a monoid isomorphism between `S` and `T`. * `Submonoid.prodEquiv`: monoid isomorphism between `s.prod t` and `s × t`; ### Operations on `MonoidHom`s * `MonoidHom.mrange`: range of a monoid homomorphism as a submonoid of the codomain; * `MonoidHom.mker`: kernel of a monoid homomorphism as a submonoid of the domain; * `MonoidHom.restrict`: restrict a monoid homomorphism to a submonoid; * `MonoidHom.codRestrict`: restrict the codomain of a monoid homomorphism to a submonoid; * `MonoidHom.mrangeRestrict`: restrict a monoid homomorphism to its range; ## Tags submonoid, range, product, map, comap -/ assert_not_exists MonoidWithZero variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass P] (S : Submonoid M) /-! ### Conversion to/from `Additive`/`Multiplicative` -/ section /-- Submonoids of monoid `M` are isomorphic to additive submonoids of `Additive M`. -/ @[simps] def Submonoid.toAddSubmonoid : Submonoid M ≃o AddSubmonoid (Additive M) where toFun S := { carrier := Additive.toMul ⁻¹' S zero_mem' := S.one_mem' add_mem' := fun ha hb => S.mul_mem' ha hb } invFun S := { carrier := Additive.ofMul ⁻¹' S one_mem' := S.zero_mem' mul_mem' := fun ha hb => S.add_mem' ha hb} left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align submonoid.to_add_submonoid Submonoid.toAddSubmonoid #align submonoid.to_add_submonoid_symm_apply_coe Submonoid.toAddSubmonoid_symm_apply_coe #align submonoid.to_add_submonoid_apply_coe Submonoid.toAddSubmonoid_apply_coe /-- Additive submonoids of an additive monoid `Additive M` are isomorphic to submonoids of `M`. -/ abbrev AddSubmonoid.toSubmonoid' : AddSubmonoid (Additive M) ≃o Submonoid M := Submonoid.toAddSubmonoid.symm #align add_submonoid.to_submonoid' AddSubmonoid.toSubmonoid' theorem Submonoid.toAddSubmonoid_closure (S : Set M) : Submonoid.toAddSubmonoid (Submonoid.closure S) = AddSubmonoid.closure (Additive.toMul ⁻¹' S) := le_antisymm (Submonoid.toAddSubmonoid.le_symm_apply.1 <| Submonoid.closure_le.2 (AddSubmonoid.subset_closure (M := Additive M))) (AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := M)) #align submonoid.to_add_submonoid_closure Submonoid.toAddSubmonoid_closure theorem AddSubmonoid.toSubmonoid'_closure (S : Set (Additive M)) : AddSubmonoid.toSubmonoid' (AddSubmonoid.closure S) = Submonoid.closure (Multiplicative.ofAdd ⁻¹' S) := le_antisymm (AddSubmonoid.toSubmonoid'.le_symm_apply.1 <| AddSubmonoid.closure_le.2 (Submonoid.subset_closure (M := M))) (Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := Additive M)) #align add_submonoid.to_submonoid'_closure AddSubmonoid.toSubmonoid'_closure end section variable {A : Type*} [AddZeroClass A] /-- Additive submonoids of an additive monoid `A` are isomorphic to multiplicative submonoids of `Multiplicative A`. -/ @[simps] def AddSubmonoid.toSubmonoid : AddSubmonoid A ≃o Submonoid (Multiplicative A) where toFun S := { carrier := Multiplicative.toAdd ⁻¹' S one_mem' := S.zero_mem' mul_mem' := fun ha hb => S.add_mem' ha hb } invFun S := { carrier := Multiplicative.ofAdd ⁻¹' S zero_mem' := S.one_mem' add_mem' := fun ha hb => S.mul_mem' ha hb} left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align add_submonoid.to_submonoid AddSubmonoid.toSubmonoid #align add_submonoid.to_submonoid_symm_apply_coe AddSubmonoid.toSubmonoid_symm_apply_coe #align add_submonoid.to_submonoid_apply_coe AddSubmonoid.toSubmonoid_apply_coe /-- Submonoids of a monoid `Multiplicative A` are isomorphic to additive submonoids of `A`. -/ abbrev Submonoid.toAddSubmonoid' : Submonoid (Multiplicative A) ≃o AddSubmonoid A := AddSubmonoid.toSubmonoid.symm #align submonoid.to_add_submonoid' Submonoid.toAddSubmonoid' theorem AddSubmonoid.toSubmonoid_closure (S : Set A) : (AddSubmonoid.toSubmonoid) (AddSubmonoid.closure S) = Submonoid.closure (Multiplicative.toAdd ⁻¹' S) := le_antisymm (AddSubmonoid.toSubmonoid.to_galoisConnection.l_le <| AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A)) (Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A)) #align add_submonoid.to_submonoid_closure AddSubmonoid.toSubmonoid_closure theorem Submonoid.toAddSubmonoid'_closure (S : Set (Multiplicative A)) : Submonoid.toAddSubmonoid' (Submonoid.closure S) = AddSubmonoid.closure (Additive.ofMul ⁻¹' S) := le_antisymm (Submonoid.toAddSubmonoid'.to_galoisConnection.l_le <| Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A)) (AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A)) #align submonoid.to_add_submonoid'_closure Submonoid.toAddSubmonoid'_closure end namespace Submonoid variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N] open Set /-! ### `comap` and `map` -/ /-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/ @[to_additive "The preimage of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`."] def comap (f : F) (S : Submonoid N) : Submonoid M where carrier := f ⁻¹' S one_mem' := show f 1 ∈ S by rw [map_one]; exact S.one_mem mul_mem' ha hb := show f (_ * _) ∈ S by rw [map_mul]; exact S.mul_mem ha hb #align submonoid.comap Submonoid.comap #align add_submonoid.comap AddSubmonoid.comap @[to_additive (attr := simp)] theorem coe_comap (S : Submonoid N) (f : F) : (S.comap f : Set M) = f ⁻¹' S := rfl #align submonoid.coe_comap Submonoid.coe_comap #align add_submonoid.coe_comap AddSubmonoid.coe_comap @[to_additive (attr := simp)] theorem mem_comap {S : Submonoid N} {f : F} {x : M} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl #align submonoid.mem_comap Submonoid.mem_comap #align add_submonoid.mem_comap AddSubmonoid.mem_comap @[to_additive] theorem comap_comap (S : Submonoid P) (g : N →* P) (f : M →* N) : (S.comap g).comap f = S.comap (g.comp f) := rfl #align submonoid.comap_comap Submonoid.comap_comap #align add_submonoid.comap_comap AddSubmonoid.comap_comap @[to_additive (attr := simp)] theorem comap_id (S : Submonoid P) : S.comap (MonoidHom.id P) = S := ext (by simp) #align submonoid.comap_id Submonoid.comap_id #align add_submonoid.comap_id AddSubmonoid.comap_id /-- The image of a submonoid along a monoid homomorphism is a submonoid. -/ @[to_additive "The image of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`."] def map (f : F) (S : Submonoid M) : Submonoid N where carrier := f '' S one_mem' := ⟨1, S.one_mem, map_one f⟩ mul_mem' := by rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩; exact ⟨x * y, S.mul_mem hx hy, by rw [map_mul]⟩ #align submonoid.map Submonoid.map #align add_submonoid.map AddSubmonoid.map @[to_additive (attr := simp)] theorem coe_map (f : F) (S : Submonoid M) : (S.map f : Set N) = f '' S := rfl #align submonoid.coe_map Submonoid.coe_map #align add_submonoid.coe_map AddSubmonoid.coe_map @[to_additive (attr := simp)] theorem mem_map {f : F} {S : Submonoid M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Iff.rfl #align submonoid.mem_map Submonoid.mem_map #align add_submonoid.mem_map AddSubmonoid.mem_map @[to_additive] theorem mem_map_of_mem (f : F) {S : Submonoid M} {x : M} (hx : x ∈ S) : f x ∈ S.map f := mem_image_of_mem f hx #align submonoid.mem_map_of_mem Submonoid.mem_map_of_mem #align add_submonoid.mem_map_of_mem AddSubmonoid.mem_map_of_mem @[to_additive] theorem apply_coe_mem_map (f : F) (S : Submonoid M) (x : S) : f x ∈ S.map f := mem_map_of_mem f x.2 #align submonoid.apply_coe_mem_map Submonoid.apply_coe_mem_map #align add_submonoid.apply_coe_mem_map AddSubmonoid.apply_coe_mem_map @[to_additive] theorem map_map (g : N →* P) (f : M →* N) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ #align submonoid.map_map Submonoid.map_map #align add_submonoid.map_map AddSubmonoid.map_map -- The simpNF linter says that the LHS can be simplified via `Submonoid.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[to_additive (attr := simp 1100, nolint simpNF)] theorem mem_map_iff_mem {f : F} (hf : Function.Injective f) {S : Submonoid M} {x : M} : f x ∈ S.map f ↔ x ∈ S := hf.mem_set_image #align submonoid.mem_map_iff_mem Submonoid.mem_map_iff_mem #align add_submonoid.mem_map_iff_mem AddSubmonoid.mem_map_iff_mem @[to_additive] theorem map_le_iff_le_comap {f : F} {S : Submonoid M} {T : Submonoid N} : S.map f ≤ T ↔ S ≤ T.comap f := image_subset_iff #align submonoid.map_le_iff_le_comap Submonoid.map_le_iff_le_comap #align add_submonoid.map_le_iff_le_comap AddSubmonoid.map_le_iff_le_comap @[to_additive] theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align submonoid.gc_map_comap Submonoid.gc_map_comap #align add_submonoid.gc_map_comap AddSubmonoid.gc_map_comap @[to_additive] theorem map_le_of_le_comap {T : Submonoid N} {f : F} : S ≤ T.comap f → S.map f ≤ T := (gc_map_comap f).l_le #align submonoid.map_le_of_le_comap Submonoid.map_le_of_le_comap #align add_submonoid.map_le_of_le_comap AddSubmonoid.map_le_of_le_comap @[to_additive] theorem le_comap_of_map_le {T : Submonoid N} {f : F} : S.map f ≤ T → S ≤ T.comap f := (gc_map_comap f).le_u #align submonoid.le_comap_of_map_le Submonoid.le_comap_of_map_le #align add_submonoid.le_comap_of_map_le AddSubmonoid.le_comap_of_map_le @[to_additive] theorem le_comap_map {f : F} : S ≤ (S.map f).comap f := (gc_map_comap f).le_u_l _ #align submonoid.le_comap_map Submonoid.le_comap_map #align add_submonoid.le_comap_map AddSubmonoid.le_comap_map @[to_additive] theorem map_comap_le {S : Submonoid N} {f : F} : (S.comap f).map f ≤ S := (gc_map_comap f).l_u_le _ #align submonoid.map_comap_le Submonoid.map_comap_le #align add_submonoid.map_comap_le AddSubmonoid.map_comap_le @[to_additive] theorem monotone_map {f : F} : Monotone (map f) := (gc_map_comap f).monotone_l #align submonoid.monotone_map Submonoid.monotone_map #align add_submonoid.monotone_map AddSubmonoid.monotone_map @[to_additive] theorem monotone_comap {f : F} : Monotone (comap f) := (gc_map_comap f).monotone_u #align submonoid.monotone_comap Submonoid.monotone_comap #align add_submonoid.monotone_comap AddSubmonoid.monotone_comap @[to_additive (attr := simp)] theorem map_comap_map {f : F} : ((S.map f).comap f).map f = S.map f := (gc_map_comap f).l_u_l_eq_l _ #align submonoid.map_comap_map Submonoid.map_comap_map #align add_submonoid.map_comap_map AddSubmonoid.map_comap_map @[to_additive (attr := simp)] theorem comap_map_comap {S : Submonoid N} {f : F} : ((S.comap f).map f).comap f = S.comap f := (gc_map_comap f).u_l_u_eq_u _ #align submonoid.comap_map_comap Submonoid.comap_map_comap #align add_submonoid.comap_map_comap AddSubmonoid.comap_map_comap @[to_additive] theorem map_sup (S T : Submonoid M) (f : F) : (S ⊔ T).map f = S.map f ⊔ T.map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup #align submonoid.map_sup Submonoid.map_sup #align add_submonoid.map_sup AddSubmonoid.map_sup @[to_additive] theorem map_iSup {ι : Sort*} (f : F) (s : ι → Submonoid M) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup #align submonoid.map_supr Submonoid.map_iSup #align add_submonoid.map_supr AddSubmonoid.map_iSup @[to_additive] theorem comap_inf (S T : Submonoid N) (f : F) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_inf #align submonoid.comap_inf Submonoid.comap_inf #align add_submonoid.comap_inf AddSubmonoid.comap_inf @[to_additive] theorem comap_iInf {ι : Sort*} (f : F) (s : ι → Submonoid N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf #align submonoid.comap_infi Submonoid.comap_iInf #align add_submonoid.comap_infi AddSubmonoid.comap_iInf @[to_additive (attr := simp)] theorem map_bot (f : F) : (⊥ : Submonoid M).map f = ⊥ := (gc_map_comap f).l_bot #align submonoid.map_bot Submonoid.map_bot #align add_submonoid.map_bot AddSubmonoid.map_bot @[to_additive (attr := simp)] theorem comap_top (f : F) : (⊤ : Submonoid N).comap f = ⊤ := (gc_map_comap f).u_top #align submonoid.comap_top Submonoid.comap_top #align add_submonoid.comap_top AddSubmonoid.comap_top @[to_additive (attr := simp)] theorem map_id (S : Submonoid M) : S.map (MonoidHom.id M) = S := ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩ #align submonoid.map_id Submonoid.map_id #align add_submonoid.map_id AddSubmonoid.map_id section GaloisCoinsertion variable {ι : Type*} {f : F} (hf : Function.Injective f) /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/ @[to_additive " `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. "] def gciMapComap : GaloisCoinsertion (map f) (comap f) := (gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff] #align submonoid.gci_map_comap Submonoid.gciMapComap #align add_submonoid.gci_map_comap AddSubmonoid.gciMapComap @[to_additive] theorem comap_map_eq_of_injective (S : Submonoid M) : (S.map f).comap f = S := (gciMapComap hf).u_l_eq _ #align submonoid.comap_map_eq_of_injective Submonoid.comap_map_eq_of_injective #align add_submonoid.comap_map_eq_of_injective AddSubmonoid.comap_map_eq_of_injective @[to_additive] theorem comap_surjective_of_injective : Function.Surjective (comap f) := (gciMapComap hf).u_surjective #align submonoid.comap_surjective_of_injective Submonoid.comap_surjective_of_injective #align add_submonoid.comap_surjective_of_injective AddSubmonoid.comap_surjective_of_injective @[to_additive] theorem map_injective_of_injective : Function.Injective (map f) := (gciMapComap hf).l_injective #align submonoid.map_injective_of_injective Submonoid.map_injective_of_injective #align add_submonoid.map_injective_of_injective AddSubmonoid.map_injective_of_injective @[to_additive] theorem comap_inf_map_of_injective (S T : Submonoid M) : (S.map f ⊓ T.map f).comap f = S ⊓ T := (gciMapComap hf).u_inf_l _ _ #align submonoid.comap_inf_map_of_injective Submonoid.comap_inf_map_of_injective #align add_submonoid.comap_inf_map_of_injective AddSubmonoid.comap_inf_map_of_injective @[to_additive] theorem comap_iInf_map_of_injective (S : ι → Submonoid M) : (⨅ i, (S i).map f).comap f = iInf S := (gciMapComap hf).u_iInf_l _ #align submonoid.comap_infi_map_of_injective Submonoid.comap_iInf_map_of_injective #align add_submonoid.comap_infi_map_of_injective AddSubmonoid.comap_iInf_map_of_injective @[to_additive] theorem comap_sup_map_of_injective (S T : Submonoid M) : (S.map f ⊔ T.map f).comap f = S ⊔ T := (gciMapComap hf).u_sup_l _ _ #align submonoid.comap_sup_map_of_injective Submonoid.comap_sup_map_of_injective #align add_submonoid.comap_sup_map_of_injective AddSubmonoid.comap_sup_map_of_injective @[to_additive] theorem comap_iSup_map_of_injective (S : ι → Submonoid M) : (⨆ i, (S i).map f).comap f = iSup S := (gciMapComap hf).u_iSup_l _ #align submonoid.comap_supr_map_of_injective Submonoid.comap_iSup_map_of_injective #align add_submonoid.comap_supr_map_of_injective AddSubmonoid.comap_iSup_map_of_injective @[to_additive] theorem map_le_map_iff_of_injective {S T : Submonoid M} : S.map f ≤ T.map f ↔ S ≤ T := (gciMapComap hf).l_le_l_iff #align submonoid.map_le_map_iff_of_injective Submonoid.map_le_map_iff_of_injective #align add_submonoid.map_le_map_iff_of_injective AddSubmonoid.map_le_map_iff_of_injective @[to_additive] theorem map_strictMono_of_injective : StrictMono (map f) := (gciMapComap hf).strictMono_l #align submonoid.map_strict_mono_of_injective Submonoid.map_strictMono_of_injective #align add_submonoid.map_strict_mono_of_injective AddSubmonoid.map_strictMono_of_injective end GaloisCoinsertion section GaloisInsertion variable {ι : Type*} {f : F} (hf : Function.Surjective f) /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/ @[to_additive " `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. "] def giMapComap : GaloisInsertion (map f) (comap f) := (gc_map_comap f).toGaloisInsertion fun S x h => let ⟨y, hy⟩ := hf x mem_map.2 ⟨y, by simp [hy, h]⟩ #align submonoid.gi_map_comap Submonoid.giMapComap #align add_submonoid.gi_map_comap AddSubmonoid.giMapComap @[to_additive] theorem map_comap_eq_of_surjective (S : Submonoid N) : (S.comap f).map f = S := (giMapComap hf).l_u_eq _ #align submonoid.map_comap_eq_of_surjective Submonoid.map_comap_eq_of_surjective #align add_submonoid.map_comap_eq_of_surjective AddSubmonoid.map_comap_eq_of_surjective @[to_additive] theorem map_surjective_of_surjective : Function.Surjective (map f) := (giMapComap hf).l_surjective #align submonoid.map_surjective_of_surjective Submonoid.map_surjective_of_surjective #align add_submonoid.map_surjective_of_surjective AddSubmonoid.map_surjective_of_surjective @[to_additive] theorem comap_injective_of_surjective : Function.Injective (comap f) := (giMapComap hf).u_injective #align submonoid.comap_injective_of_surjective Submonoid.comap_injective_of_surjective #align add_submonoid.comap_injective_of_surjective AddSubmonoid.comap_injective_of_surjective @[to_additive] theorem map_inf_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T := (giMapComap hf).l_inf_u _ _ #align submonoid.map_inf_comap_of_surjective Submonoid.map_inf_comap_of_surjective #align add_submonoid.map_inf_comap_of_surjective AddSubmonoid.map_inf_comap_of_surjective @[to_additive] theorem map_iInf_comap_of_surjective (S : ι → Submonoid N) : (⨅ i, (S i).comap f).map f = iInf S := (giMapComap hf).l_iInf_u _ #align submonoid.map_infi_comap_of_surjective Submonoid.map_iInf_comap_of_surjective #align add_submonoid.map_infi_comap_of_surjective AddSubmonoid.map_iInf_comap_of_surjective @[to_additive] theorem map_sup_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T := (giMapComap hf).l_sup_u _ _ #align submonoid.map_sup_comap_of_surjective Submonoid.map_sup_comap_of_surjective #align add_submonoid.map_sup_comap_of_surjective AddSubmonoid.map_sup_comap_of_surjective @[to_additive] theorem map_iSup_comap_of_surjective (S : ι → Submonoid N) : (⨆ i, (S i).comap f).map f = iSup S := (giMapComap hf).l_iSup_u _ #align submonoid.map_supr_comap_of_surjective Submonoid.map_iSup_comap_of_surjective #align add_submonoid.map_supr_comap_of_surjective AddSubmonoid.map_iSup_comap_of_surjective @[to_additive] theorem comap_le_comap_iff_of_surjective {S T : Submonoid N} : S.comap f ≤ T.comap f ↔ S ≤ T := (giMapComap hf).u_le_u_iff #align submonoid.comap_le_comap_iff_of_surjective Submonoid.comap_le_comap_iff_of_surjective #align add_submonoid.comap_le_comap_iff_of_surjective AddSubmonoid.comap_le_comap_iff_of_surjective @[to_additive] theorem comap_strictMono_of_surjective : StrictMono (comap f) := (giMapComap hf).strictMono_u #align submonoid.comap_strict_mono_of_surjective Submonoid.comap_strictMono_of_surjective #align add_submonoid.comap_strict_mono_of_surjective AddSubmonoid.comap_strictMono_of_surjective end GaloisInsertion end Submonoid namespace OneMemClass variable {A M₁ : Type*} [SetLike A M₁] [One M₁] [hA : OneMemClass A M₁] (S' : A) /-- A submonoid of a monoid inherits a 1. -/ @[to_additive "An `AddSubmonoid` of an `AddMonoid` inherits a zero."] instance one : One S' := ⟨⟨1, OneMemClass.one_mem S'⟩⟩ #align one_mem_class.has_one OneMemClass.one #align zero_mem_class.has_zero ZeroMemClass.zero @[to_additive (attr := simp, norm_cast)] theorem coe_one : ((1 : S') : M₁) = 1 := rfl #align one_mem_class.coe_one OneMemClass.coe_one #align zero_mem_class.coe_zero ZeroMemClass.coe_zero variable {S'} @[to_additive (attr := simp, norm_cast)] theorem coe_eq_one {x : S'} : (↑x : M₁) = 1 ↔ x = 1 := (Subtype.ext_iff.symm : (x : M₁) = (1 : S') ↔ x = 1) #align one_mem_class.coe_eq_one OneMemClass.coe_eq_one #align zero_mem_class.coe_eq_zero ZeroMemClass.coe_eq_zero variable (S') @[to_additive] theorem one_def : (1 : S') = ⟨1, OneMemClass.one_mem S'⟩ := rfl #align one_mem_class.one_def OneMemClass.one_def #align zero_mem_class.zero_def ZeroMemClass.zero_def end OneMemClass variable {A : Type*} [SetLike A M] [hA : SubmonoidClass A M] (S' : A) /-- An `AddSubmonoid` of an `AddMonoid` inherits a scalar multiplication. -/ instance AddSubmonoidClass.nSMul {M} [AddMonoid M] {A : Type*} [SetLike A M] [AddSubmonoidClass A M] (S : A) : SMul ℕ S := ⟨fun n a => ⟨n • a.1, nsmul_mem a.2 n⟩⟩ #align add_submonoid_class.has_nsmul AddSubmonoidClass.nSMul namespace SubmonoidClass /-- A submonoid of a monoid inherits a power operator. -/ instance nPow {M} [Monoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] (S : A) : Pow S ℕ := ⟨fun a n => ⟨a.1 ^ n, pow_mem a.2 n⟩⟩ #align submonoid_class.has_pow SubmonoidClass.nPow attribute [to_additive existing nSMul] nPow @[to_additive (attr := simp, norm_cast)] theorem coe_pow {M} [Monoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] {S : A} (x : S) (n : ℕ) : ↑(x ^ n) = (x : M) ^ n := rfl #align submonoid_class.coe_pow SubmonoidClass.coe_pow #align add_submonoid_class.coe_nsmul AddSubmonoidClass.coe_nsmul @[to_additive (attr := simp)] theorem mk_pow {M} [Monoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] {S : A} (x : M) (hx : x ∈ S) (n : ℕ) : (⟨x, hx⟩ : S) ^ n = ⟨x ^ n, pow_mem hx n⟩ := rfl #align submonoid_class.mk_pow SubmonoidClass.mk_pow #align add_submonoid_class.mk_nsmul AddSubmonoidClass.mk_nsmul -- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`. /-- A submonoid of a unital magma inherits a unital magma structure. -/ @[to_additive "An `AddSubmonoid` of a unital additive magma inherits a unital additive magma structure."] instance (priority := 75) toMulOneClass {M : Type*} [MulOneClass M] {A : Type*} [SetLike A M] [SubmonoidClass A M] (S : A) : MulOneClass S := Subtype.coe_injective.mulOneClass (↑) rfl (fun _ _ => rfl) #align submonoid_class.to_mul_one_class SubmonoidClass.toMulOneClass #align add_submonoid_class.to_add_zero_class AddSubmonoidClass.toAddZeroClass -- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`. /-- A submonoid of a monoid inherits a monoid structure. -/ @[to_additive "An `AddSubmonoid` of an `AddMonoid` inherits an `AddMonoid` structure."] instance (priority := 75) toMonoid {M : Type*} [Monoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] (S : A) : Monoid S := Subtype.coe_injective.monoid (↑) rfl (fun _ _ => rfl) (fun _ _ => rfl) #align submonoid_class.to_monoid SubmonoidClass.toMonoid #align add_submonoid_class.to_add_monoid AddSubmonoidClass.toAddMonoid -- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`. /-- A submonoid of a `CommMonoid` is a `CommMonoid`. -/ @[to_additive "An `AddSubmonoid` of an `AddCommMonoid` is an `AddCommMonoid`."] instance (priority := 75) toCommMonoid {M} [CommMonoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] (S : A) : CommMonoid S := Subtype.coe_injective.commMonoid (↑) rfl (fun _ _ => rfl) fun _ _ => rfl #align submonoid_class.to_comm_monoid SubmonoidClass.toCommMonoid #align add_submonoid_class.to_add_comm_monoid AddSubmonoidClass.toAddCommMonoid /-- The natural monoid hom from a submonoid of monoid `M` to `M`. -/ @[to_additive "The natural monoid hom from an `AddSubmonoid` of `AddMonoid` `M` to `M`."] def subtype : S' →* M where toFun := Subtype.val; map_one' := rfl; map_mul' _ _ := by simp #align submonoid_class.subtype SubmonoidClass.subtype #align add_submonoid_class.subtype AddSubmonoidClass.subtype @[to_additive (attr := simp)] theorem coe_subtype : (SubmonoidClass.subtype S' : S' → M) = Subtype.val := rfl #align submonoid_class.coe_subtype SubmonoidClass.coe_subtype #align add_submonoid_class.coe_subtype AddSubmonoidClass.coe_subtype end SubmonoidClass namespace Submonoid /-- A submonoid of a monoid inherits a multiplication. -/ @[to_additive "An `AddSubmonoid` of an `AddMonoid` inherits an addition."] instance mul : Mul S := ⟨fun a b => ⟨a.1 * b.1, S.mul_mem a.2 b.2⟩⟩ #align submonoid.has_mul Submonoid.mul #align add_submonoid.has_add AddSubmonoid.add /-- A submonoid of a monoid inherits a 1. -/ @[to_additive "An `AddSubmonoid` of an `AddMonoid` inherits a zero."] instance one : One S := ⟨⟨_, S.one_mem⟩⟩ #align submonoid.has_one Submonoid.one #align add_submonoid.has_zero AddSubmonoid.zero @[to_additive (attr := simp, norm_cast)] theorem coe_mul (x y : S) : (↑(x * y) : M) = ↑x * ↑y := rfl #align submonoid.coe_mul Submonoid.coe_mul #align add_submonoid.coe_add AddSubmonoid.coe_add @[to_additive (attr := simp, norm_cast)] theorem coe_one : ((1 : S) : M) = 1 := rfl #align submonoid.coe_one Submonoid.coe_one #align add_submonoid.coe_zero AddSubmonoid.coe_zero @[to_additive (attr := simp)] lemma mk_eq_one {a : M} {ha} : (⟨a, ha⟩ : S) = 1 ↔ a = 1 := by simp [← SetLike.coe_eq_coe] @[to_additive (attr := simp)] theorem mk_mul_mk (x y : M) (hx : x ∈ S) (hy : y ∈ S) : (⟨x, hx⟩ : S) * ⟨y, hy⟩ = ⟨x * y, S.mul_mem hx hy⟩ := rfl #align submonoid.mk_mul_mk Submonoid.mk_mul_mk #align add_submonoid.mk_add_mk AddSubmonoid.mk_add_mk @[to_additive] theorem mul_def (x y : S) : x * y = ⟨x * y, S.mul_mem x.2 y.2⟩ := rfl #align submonoid.mul_def Submonoid.mul_def #align add_submonoid.add_def AddSubmonoid.add_def @[to_additive] theorem one_def : (1 : S) = ⟨1, S.one_mem⟩ := rfl #align submonoid.one_def Submonoid.one_def #align add_submonoid.zero_def AddSubmonoid.zero_def /-- A submonoid of a unital magma inherits a unital magma structure. -/ @[to_additive "An `AddSubmonoid` of a unital additive magma inherits a unital additive magma structure."] instance toMulOneClass {M : Type*} [MulOneClass M] (S : Submonoid M) : MulOneClass S := Subtype.coe_injective.mulOneClass (↑) rfl fun _ _ => rfl #align submonoid.to_mul_one_class Submonoid.toMulOneClass #align add_submonoid.to_add_zero_class AddSubmonoid.toAddZeroClass @[to_additive] protected theorem pow_mem {M : Type*} [Monoid M] (S : Submonoid M) {x : M} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S := pow_mem hx n #align submonoid.pow_mem Submonoid.pow_mem #align add_submonoid.nsmul_mem AddSubmonoid.nsmul_mem -- Porting note: coe_pow removed, syntactic tautology #noalign submonoid.coe_pow #noalign add_submonoid.coe_smul /-- A submonoid of a monoid inherits a monoid structure. -/ @[to_additive "An `AddSubmonoid` of an `AddMonoid` inherits an `AddMonoid` structure."] instance toMonoid {M : Type*} [Monoid M] (S : Submonoid M) : Monoid S := Subtype.coe_injective.monoid (↑) rfl (fun _ _ => rfl) fun _ _ => rfl #align submonoid.to_monoid Submonoid.toMonoid #align add_submonoid.to_add_monoid AddSubmonoid.toAddMonoid /-- A submonoid of a `CommMonoid` is a `CommMonoid`. -/ @[to_additive "An `AddSubmonoid` of an `AddCommMonoid` is an `AddCommMonoid`."] instance toCommMonoid {M} [CommMonoid M] (S : Submonoid M) : CommMonoid S := Subtype.coe_injective.commMonoid (↑) rfl (fun _ _ => rfl) fun _ _ => rfl #align submonoid.to_comm_monoid Submonoid.toCommMonoid #align add_submonoid.to_add_comm_monoid AddSubmonoid.toAddCommMonoid /-- The natural monoid hom from a submonoid of monoid `M` to `M`. -/ @[to_additive "The natural monoid hom from an `AddSubmonoid` of `AddMonoid` `M` to `M`."] def subtype : S →* M where toFun := Subtype.val; map_one' := rfl; map_mul' _ _ := by simp #align submonoid.subtype Submonoid.subtype #align add_submonoid.subtype AddSubmonoid.subtype @[to_additive (attr := simp)] theorem coe_subtype : ⇑S.subtype = Subtype.val := rfl #align submonoid.coe_subtype Submonoid.coe_subtype #align add_submonoid.coe_subtype AddSubmonoid.coe_subtype /-- The top submonoid is isomorphic to the monoid. -/ @[to_additive (attr := simps) "The top additive submonoid is isomorphic to the additive monoid."] def topEquiv : (⊤ : Submonoid M) ≃* M where toFun x := x invFun x := ⟨x, mem_top x⟩ left_inv x := x.eta _ right_inv _ := rfl map_mul' _ _ := rfl #align submonoid.top_equiv Submonoid.topEquiv #align add_submonoid.top_equiv AddSubmonoid.topEquiv #align submonoid.top_equiv_apply Submonoid.topEquiv_apply #align submonoid.top_equiv_symm_apply_coe Submonoid.topEquiv_symm_apply_coe @[to_additive (attr := simp)] theorem topEquiv_toMonoidHom : ((topEquiv : _ ≃* M) : _ →* M) = (⊤ : Submonoid M).subtype := rfl #align submonoid.top_equiv_to_monoid_hom Submonoid.topEquiv_toMonoidHom #align add_submonoid.top_equiv_to_add_monoid_hom AddSubmonoid.topEquiv_toAddMonoidHom /-- A subgroup is isomorphic to its image under an injective function. If you have an isomorphism, use `MulEquiv.submonoidMap` for better definitional equalities. -/ @[to_additive "An additive subgroup is isomorphic to its image under an injective function. If you have an isomorphism, use `AddEquiv.addSubmonoidMap` for better definitional equalities."] noncomputable def equivMapOfInjective (f : M →* N) (hf : Function.Injective f) : S ≃* S.map f := { Equiv.Set.image f S hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) } #align submonoid.equiv_map_of_injective Submonoid.equivMapOfInjective #align add_submonoid.equiv_map_of_injective AddSubmonoid.equivMapOfInjective @[to_additive (attr := simp)] theorem coe_equivMapOfInjective_apply (f : M →* N) (hf : Function.Injective f) (x : S) : (equivMapOfInjective S f hf x : N) = f x := rfl #align submonoid.coe_equiv_map_of_injective_apply Submonoid.coe_equivMapOfInjective_apply #align add_submonoid.coe_equiv_map_of_injective_apply AddSubmonoid.coe_equivMapOfInjective_apply @[to_additive (attr := simp)] theorem closure_closure_coe_preimage {s : Set M} : closure (((↑) : closure s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x => Subtype.recOn x fun x hx _ => by refine closure_induction' (p := fun y hy ↦ ⟨y, hy⟩ ∈ closure (((↑) : closure s → M) ⁻¹' s)) (fun g hg => subset_closure hg) ?_ (fun g₁ g₂ hg₁ hg₂ => ?_) hx · exact Submonoid.one_mem _ · exact Submonoid.mul_mem _ #align submonoid.closure_closure_coe_preimage Submonoid.closure_closure_coe_preimage #align add_submonoid.closure_closure_coe_preimage AddSubmonoid.closure_closure_coe_preimage /-- Given submonoids `s`, `t` of monoids `M`, `N` respectively, `s × t` as a submonoid of `M × N`. -/ @[to_additive prod "Given `AddSubmonoid`s `s`, `t` of `AddMonoid`s `A`, `B` respectively, `s × t` as an `AddSubmonoid` of `A × B`."] def prod (s : Submonoid M) (t : Submonoid N) : Submonoid (M × N) where carrier := s ×ˢ t one_mem' := ⟨s.one_mem, t.one_mem⟩ mul_mem' hp hq := ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ #align submonoid.prod Submonoid.prod #align add_submonoid.prod AddSubmonoid.prod @[to_additive coe_prod] theorem coe_prod (s : Submonoid M) (t : Submonoid N) : (s.prod t : Set (M × N)) = (s : Set M) ×ˢ (t : Set N) := rfl #align submonoid.coe_prod Submonoid.coe_prod #align add_submonoid.coe_prod AddSubmonoid.coe_prod @[to_additive mem_prod] theorem mem_prod {s : Submonoid M} {t : Submonoid N} {p : M × N} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl #align submonoid.mem_prod Submonoid.mem_prod #align add_submonoid.mem_prod AddSubmonoid.mem_prod @[to_additive prod_mono] theorem prod_mono {s₁ s₂ : Submonoid M} {t₁ t₂ : Submonoid N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht #align submonoid.prod_mono Submonoid.prod_mono #align add_submonoid.prod_mono AddSubmonoid.prod_mono @[to_additive prod_top] theorem prod_top (s : Submonoid M) : s.prod (⊤ : Submonoid N) = s.comap (MonoidHom.fst M N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] #align submonoid.prod_top Submonoid.prod_top #align add_submonoid.prod_top AddSubmonoid.prod_top @[to_additive top_prod] theorem top_prod (s : Submonoid N) : (⊤ : Submonoid M).prod s = s.comap (MonoidHom.snd M N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] #align submonoid.top_prod Submonoid.top_prod #align add_submonoid.top_prod AddSubmonoid.top_prod @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Submonoid M).prod (⊤ : Submonoid N) = ⊤ := (top_prod _).trans <| comap_top _ #align submonoid.top_prod_top Submonoid.top_prod_top #align add_submonoid.top_prod_top AddSubmonoid.top_prod_top @[to_additive bot_prod_bot] theorem bot_prod_bot : (⊥ : Submonoid M).prod (⊥ : Submonoid N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod, Prod.one_eq_mk] #align submonoid.bot_prod_bot Submonoid.bot_prod_bot -- Porting note: to_additive translated the name incorrectly in mathlib 3. #align add_submonoid.bot_sum_bot AddSubmonoid.bot_prod_bot /-- The product of submonoids is isomorphic to their product as monoids. -/ @[to_additive prodEquiv "The product of additive submonoids is isomorphic to their product as additive monoids"] def prodEquiv (s : Submonoid M) (t : Submonoid N) : s.prod t ≃* s × t := { (Equiv.Set.prod (s : Set M) (t : Set N)) with map_mul' := fun _ _ => rfl } #align submonoid.prod_equiv Submonoid.prodEquiv #align add_submonoid.prod_equiv AddSubmonoid.prodEquiv open MonoidHom @[to_additive] theorem map_inl (s : Submonoid M) : s.map (inl M N) = s.prod ⊥ := ext fun p => ⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨hx, Set.mem_singleton 1⟩, fun ⟨hps, hp1⟩ => ⟨p.1, hps, Prod.ext rfl <| (Set.eq_of_mem_singleton hp1).symm⟩⟩ #align submonoid.map_inl Submonoid.map_inl #align add_submonoid.map_inl AddSubmonoid.map_inl @[to_additive] theorem map_inr (s : Submonoid N) : s.map (inr M N) = prod ⊥ s := ext fun p => ⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨Set.mem_singleton 1, hx⟩, fun ⟨hp1, hps⟩ => ⟨p.2, hps, Prod.ext (Set.eq_of_mem_singleton hp1).symm rfl⟩⟩ #align submonoid.map_inr Submonoid.map_inr #align add_submonoid.map_inr AddSubmonoid.map_inr @[to_additive (attr := simp) prod_bot_sup_bot_prod] theorem prod_bot_sup_bot_prod (s : Submonoid M) (t : Submonoid N) : (prod s ⊥) ⊔ (prod ⊥ t) = prod s t := (le_antisymm (sup_le (prod_mono (le_refl s) bot_le) (prod_mono bot_le (le_refl t)))) fun p hp => Prod.fst_mul_snd p ▸ mul_mem ((le_sup_left : prod s ⊥ ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨hp.1, Set.mem_singleton 1⟩) ((le_sup_right : prod ⊥ t ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨Set.mem_singleton 1, hp.2⟩) #align submonoid.prod_bot_sup_bot_prod Submonoid.prod_bot_sup_bot_prod #align add_submonoid.prod_bot_sup_bot_prod AddSubmonoid.prod_bot_sup_bot_prod @[to_additive] theorem mem_map_equiv {f : M ≃* N} {K : Submonoid M} {x : N} : x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K := Set.mem_image_equiv #align submonoid.mem_map_equiv Submonoid.mem_map_equiv #align add_submonoid.mem_map_equiv AddSubmonoid.mem_map_equiv @[to_additive] theorem map_equiv_eq_comap_symm (f : M ≃* N) (K : Submonoid M) : K.map f.toMonoidHom = K.comap f.symm.toMonoidHom := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) #align submonoid.map_equiv_eq_comap_symm Submonoid.map_equiv_eq_comap_symm #align add_submonoid.map_equiv_eq_comap_symm AddSubmonoid.map_equiv_eq_comap_symm @[to_additive] theorem comap_equiv_eq_map_symm (f : N ≃* M) (K : Submonoid M) : K.comap f = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm #align submonoid.comap_equiv_eq_map_symm Submonoid.comap_equiv_eq_map_symm #align add_submonoid.comap_equiv_eq_map_symm AddSubmonoid.comap_equiv_eq_map_symm @[to_additive (attr := simp)] theorem map_equiv_top (f : M ≃* N) : (⊤ : Submonoid M).map f = ⊤ := SetLike.coe_injective <| Set.image_univ.trans f.surjective.range_eq #align submonoid.map_equiv_top Submonoid.map_equiv_top #align add_submonoid.map_equiv_top AddSubmonoid.map_equiv_top @[to_additive le_prod_iff] theorem le_prod_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} : u ≤ s.prod t ↔ u.map (fst M N) ≤ s ∧ u.map (snd M N) ≤ t := by constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩ #align submonoid.le_prod_iff Submonoid.le_prod_iff #align add_submonoid.le_prod_iff AddSubmonoid.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} : s.prod t ≤ u ↔ s.map (inl M N) ≤ u ∧ t.map (inr M N) ≤ u := by constructor · intro h constructor · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨hx, Submonoid.one_mem _⟩ · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨Submonoid.one_mem _, hx⟩ · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩ have h1' : inl M N x1 ∈ u := by apply hH simpa using h1 have h2' : inr M N x2 ∈ u := by apply hK simpa using h2 simpa using Submonoid.mul_mem _ h1' h2' #align submonoid.prod_le_iff Submonoid.prod_le_iff #align add_submonoid.prod_le_iff AddSubmonoid.prod_le_iff end Submonoid namespace MonoidHom variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N] open Submonoid library_note "range copy pattern"/-- For many categories (monoids, modules, rings, ...) the set-theoretic image of a morphism `f` is a subobject of the codomain. When this is the case, it is useful to define the range of a morphism in such a way that the underlying carrier set of the range subobject is definitionally `Set.range f`. In particular this means that the types `↥(Set.range f)` and `↥f.range` are interchangeable without proof obligations. A convenient candidate definition for range which is mathematically correct is `map ⊤ f`, just as `Set.range` could have been defined as `f '' Set.univ`. However, this lacks the desired definitional convenience, in that it both does not match `Set.range`, and that it introduces a redundant `x ∈ ⊤` term which clutters proofs. In such a case one may resort to the `copy` pattern. A `copy` function converts the definitional problem for the carrier set of a subobject into a one-off propositional proof obligation which one discharges while writing the definition of the definitionally convenient range (the parameter `hs` in the example below). A good example is the case of a morphism of monoids. A convenient definition for `MonoidHom.mrange` would be `(⊤ : Submonoid M).map f`. However since this lacks the required definitional convenience, we first define `Submonoid.copy` as follows: ```lean protected def copy (S : Submonoid M) (s : Set M) (hs : s = S) : Submonoid M := { carrier := s, one_mem' := hs.symm ▸ S.one_mem', mul_mem' := hs.symm ▸ S.mul_mem' } ``` and then finally define: ```lean def mrange (f : M →* N) : Submonoid N := ((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm ``` -/ /-- The range of a monoid homomorphism is a submonoid. See Note [range copy pattern]. -/ @[to_additive "The range of an `AddMonoidHom` is an `AddSubmonoid`."] def mrange (f : F) : Submonoid N := ((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm #align monoid_hom.mrange MonoidHom.mrange #align add_monoid_hom.mrange AddMonoidHom.mrange @[to_additive (attr := simp)] theorem coe_mrange (f : F) : (mrange f : Set N) = Set.range f := rfl #align monoid_hom.coe_mrange MonoidHom.coe_mrange #align add_monoid_hom.coe_mrange AddMonoidHom.coe_mrange @[to_additive (attr := simp)] theorem mem_mrange {f : F} {y : N} : y ∈ mrange f ↔ ∃ x, f x = y := Iff.rfl #align monoid_hom.mem_mrange MonoidHom.mem_mrange #align add_monoid_hom.mem_mrange AddMonoidHom.mem_mrange @[to_additive] theorem mrange_eq_map (f : F) : mrange f = (⊤ : Submonoid M).map f := Submonoid.copy_eq _ #align monoid_hom.mrange_eq_map MonoidHom.mrange_eq_map #align add_monoid_hom.mrange_eq_map AddMonoidHom.mrange_eq_map @[to_additive (attr := simp)] theorem mrange_id : mrange (MonoidHom.id M) = ⊤ := by simp [mrange_eq_map] @[to_additive] theorem map_mrange (g : N →* P) (f : M →* N) : f.mrange.map g = mrange (comp g f) := by simpa only [mrange_eq_map] using (⊤ : Submonoid M).map_map g f #align monoid_hom.map_mrange MonoidHom.map_mrange #align add_monoid_hom.map_mrange AddMonoidHom.map_mrange @[to_additive] theorem mrange_top_iff_surjective {f : F} : mrange f = (⊤ : Submonoid N) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_mrange, coe_top]) Set.range_iff_surjective #align monoid_hom.mrange_top_iff_surjective MonoidHom.mrange_top_iff_surjective #align add_monoid_hom.mrange_top_iff_surjective AddMonoidHom.mrange_top_iff_surjective /-- The range of a surjective monoid hom is the whole of the codomain. -/ @[to_additive (attr := simp) "The range of a surjective `AddMonoid` hom is the whole of the codomain."] theorem mrange_top_of_surjective (f : F) (hf : Function.Surjective f) : mrange f = (⊤ : Submonoid N) := mrange_top_iff_surjective.2 hf #align monoid_hom.mrange_top_of_surjective MonoidHom.mrange_top_of_surjective #align add_monoid_hom.mrange_top_of_surjective AddMonoidHom.mrange_top_of_surjective @[to_additive] theorem mclosure_preimage_le (f : F) (s : Set N) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx #align monoid_hom.mclosure_preimage_le MonoidHom.mclosure_preimage_le #align add_monoid_hom.mclosure_preimage_le AddMonoidHom.mclosure_preimage_le /-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated by the image of the set. -/ @[to_additive "The image under an `AddMonoid` hom of the `AddSubmonoid` generated by a set equals the `AddSubmonoid` generated by the image of the set."] theorem map_mclosure (f : F) (s : Set M) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 <| le_trans (closure_mono <| Set.subset_preimage_image _ _) (mclosure_preimage_le _ _)) (closure_le.2 <| Set.image_subset _ subset_closure) #align monoid_hom.map_mclosure MonoidHom.map_mclosure #align add_monoid_hom.map_mclosure AddMonoidHom.map_mclosure @[to_additive (attr := simp)] theorem mclosure_range (f : F) : closure (Set.range f) = mrange f := by rw [← Set.image_univ, ← map_mclosure, mrange_eq_map, closure_univ] /-- Restriction of a monoid hom to a submonoid of the domain. -/ @[to_additive "Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the domain."] def restrict {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M] (f : M →* N) (s : S) : s →* N := f.comp (SubmonoidClass.subtype _) #align monoid_hom.restrict MonoidHom.restrict #align add_monoid_hom.restrict AddMonoidHom.restrict @[to_additive (attr := simp)] theorem restrict_apply {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M] (f : M →* N) (s : S) (x : s) : f.restrict s x = f x := rfl #align monoid_hom.restrict_apply MonoidHom.restrict_apply #align add_monoid_hom.restrict_apply AddMonoidHom.restrict_apply @[to_additive (attr := simp)] theorem restrict_mrange (f : M →* N) : mrange (f.restrict S) = S.map f := by simp [SetLike.ext_iff] #align monoid_hom.restrict_mrange MonoidHom.restrict_mrange #align add_monoid_hom.restrict_mrange AddMonoidHom.restrict_mrange /-- Restriction of a monoid hom to a submonoid of the codomain. -/ @[to_additive (attr := simps apply) "Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the codomain."] def codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : M →* N) (s : S) (h : ∀ x, f x ∈ s) : M →* s where toFun n := ⟨f n, h n⟩ map_one' := Subtype.eq f.map_one map_mul' x y := Subtype.eq (f.map_mul x y) #align monoid_hom.cod_restrict MonoidHom.codRestrict #align add_monoid_hom.cod_restrict AddMonoidHom.codRestrict #align monoid_hom.cod_restrict_apply MonoidHom.codRestrict_apply /-- Restriction of a monoid hom to its range interpreted as a submonoid. -/ @[to_additive "Restriction of an `AddMonoid` hom to its range interpreted as a submonoid."] def mrangeRestrict {N} [MulOneClass N] (f : M →* N) : M →* (mrange f) := (f.codRestrict (mrange f)) fun x => ⟨x, rfl⟩ #align monoid_hom.mrange_restrict MonoidHom.mrangeRestrict #align add_monoid_hom.mrange_restrict AddMonoidHom.mrangeRestrict @[to_additive (attr := simp)] theorem coe_mrangeRestrict {N} [MulOneClass N] (f : M →* N) (x : M) : (f.mrangeRestrict x : N) = f x := rfl #align monoid_hom.coe_mrange_restrict MonoidHom.coe_mrangeRestrict #align add_monoid_hom.coe_mrange_restrict AddMonoidHom.coe_mrangeRestrict @[to_additive] theorem mrangeRestrict_surjective (f : M →* N) : Function.Surjective f.mrangeRestrict := fun ⟨_, ⟨x, rfl⟩⟩ => ⟨x, rfl⟩ #align monoid_hom.mrange_restrict_surjective MonoidHom.mrangeRestrict_surjective #align add_monoid_hom.mrange_restrict_surjective AddMonoidHom.mrangeRestrict_surjective /-- The multiplicative kernel of a monoid hom is the submonoid of elements `x : G` such that `f x = 1` -/ @[to_additive "The additive kernel of an `AddMonoid` hom is the `AddSubmonoid` of elements such that `f x = 0`"] def mker (f : F) : Submonoid M := (⊥ : Submonoid N).comap f #align monoid_hom.mker MonoidHom.mker #align add_monoid_hom.mker AddMonoidHom.mker @[to_additive] theorem mem_mker (f : F) {x : M} : x ∈ mker f ↔ f x = 1 := Iff.rfl #align monoid_hom.mem_mker MonoidHom.mem_mker #align add_monoid_hom.mem_mker AddMonoidHom.mem_mker @[to_additive] theorem coe_mker (f : F) : (mker f : Set M) = (f : M → N) ⁻¹' {1} := rfl #align monoid_hom.coe_mker MonoidHom.coe_mker #align add_monoid_hom.coe_mker AddMonoidHom.coe_mker @[to_additive] instance decidableMemMker [DecidableEq N] (f : F) : DecidablePred (· ∈ mker f) := fun x => decidable_of_iff (f x = 1) (mem_mker f) #align monoid_hom.decidable_mem_mker MonoidHom.decidableMemMker #align add_monoid_hom.decidable_mem_mker AddMonoidHom.decidableMemMker @[to_additive] theorem comap_mker (g : N →* P) (f : M →* N) : g.mker.comap f = mker (comp g f) := rfl #align monoid_hom.comap_mker MonoidHom.comap_mker #align add_monoid_hom.comap_mker AddMonoidHom.comap_mker @[to_additive (attr := simp)] theorem comap_bot' (f : F) : (⊥ : Submonoid N).comap f = mker f := rfl #align monoid_hom.comap_bot' MonoidHom.comap_bot' #align add_monoid_hom.comap_bot' AddMonoidHom.comap_bot' @[to_additive (attr := simp)] theorem restrict_mker (f : M →* N) : mker (f.restrict S) = f.mker.comap S.subtype := rfl #align monoid_hom.restrict_mker MonoidHom.restrict_mker #align add_monoid_hom.restrict_mker AddMonoidHom.restrict_mker @[to_additive] theorem mrangeRestrict_mker (f : M →* N) : mker (mrangeRestrict f) = mker f := by ext x change (⟨f x, _⟩ : mrange f) = ⟨1, _⟩ ↔ f x = 1 simp #align monoid_hom.range_restrict_mker MonoidHom.mrangeRestrict_mker #align add_monoid_hom.range_restrict_mker AddMonoidHom.mrangeRestrict_mker @[to_additive (attr := simp)] theorem mker_one : mker (1 : M →* N) = ⊤ := by ext simp [mem_mker] #align monoid_hom.mker_one MonoidHom.mker_one #align add_monoid_hom.mker_zero AddMonoidHom.mker_zero @[to_additive prod_map_comap_prod'] theorem prod_map_comap_prod' {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N'] (f : M →* N) (g : M' →* N') (S : Submonoid N) (S' : Submonoid N') : (S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ #align monoid_hom.prod_map_comap_prod' MonoidHom.prod_map_comap_prod' -- Porting note: to_additive translated the name incorrectly in mathlib 3. #align add_monoid_hom.sum_map_comap_sum' AddMonoidHom.prod_map_comap_prod' @[to_additive mker_prod_map] theorem mker_prod_map {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N'] (f : M →* N) (g : M' →* N') : mker (prodMap f g) = f.mker.prod (mker g) := by rw [← comap_bot', ← comap_bot', ← comap_bot', ← prod_map_comap_prod', bot_prod_bot] #align monoid_hom.mker_prod_map MonoidHom.mker_prod_map -- Porting note: to_additive translated the name incorrectly in mathlib 3. #align add_monoid_hom.mker_sum_map AddMonoidHom.mker_prod_map @[to_additive (attr := simp)] theorem mker_inl : mker (inl M N) = ⊥ := by ext x simp [mem_mker] #align monoid_hom.mker_inl MonoidHom.mker_inl #align add_monoid_hom.mker_inl AddMonoidHom.mker_inl @[to_additive (attr := simp)] theorem mker_inr : mker (inr M N) = ⊥ := by ext x simp [mem_mker] #align monoid_hom.mker_inr MonoidHom.mker_inr #align add_monoid_hom.mker_inr AddMonoidHom.mker_inr @[to_additive (attr := simp)] lemma mker_fst : mker (fst M N) = .prod ⊥ ⊤ := SetLike.ext fun _ => (and_true_iff _).symm @[to_additive (attr := simp)] lemma mker_snd : mker (snd M N) = .prod ⊤ ⊥ := SetLike.ext fun _ => (true_and_iff _).symm /-- The `MonoidHom` from the preimage of a submonoid to itself. -/ @[to_additive (attr := simps) "the `AddMonoidHom` from the preimage of an additive submonoid to itself."] def submonoidComap (f : M →* N) (N' : Submonoid N) : N'.comap f →* N' where toFun x := ⟨f x, x.2⟩ map_one' := Subtype.eq f.map_one map_mul' x y := Subtype.eq (f.map_mul x y) #align monoid_hom.submonoid_comap MonoidHom.submonoidComap #align add_monoid_hom.add_submonoid_comap AddMonoidHom.addSubmonoidComap #align monoid_hom.submonoid_comap_apply_coe MonoidHom.submonoidComap_apply_coe #align add_monoid_hom.submonoid_comap_apply_coe AddMonoidHom.addSubmonoidComap_apply_coe /-- The `MonoidHom` from a submonoid to its image. See `MulEquiv.SubmonoidMap` for a variant for `MulEquiv`s. -/ @[to_additive (attr := simps) "the `AddMonoidHom` from an additive submonoid to its image. See `AddEquiv.AddSubmonoidMap` for a variant for `AddEquiv`s."] def submonoidMap (f : M →* N) (M' : Submonoid M) : M' →* M'.map f where toFun x := ⟨f x, ⟨x, x.2, rfl⟩⟩ map_one' := Subtype.eq <| f.map_one map_mul' x y := Subtype.eq <| f.map_mul x y #align monoid_hom.submonoid_map MonoidHom.submonoidMap #align add_monoid_hom.add_submonoid_map AddMonoidHom.addSubmonoidMap #align monoid_hom.submonoid_map_apply_coe MonoidHom.submonoidMap_apply_coe #align add_monoid_hom.submonoid_map_apply_coe AddMonoidHom.addSubmonoidMap_apply_coe @[to_additive] theorem submonoidMap_surjective (f : M →* N) (M' : Submonoid M) : Function.Surjective (f.submonoidMap M') := by rintro ⟨_, x, hx, rfl⟩ exact ⟨⟨x, hx⟩, rfl⟩ #align monoid_hom.submonoid_map_surjective MonoidHom.submonoidMap_surjective #align add_monoid_hom.add_submonoid_map_surjective AddMonoidHom.addSubmonoidMap_surjective end MonoidHom namespace Submonoid open MonoidHom @[to_additive]
Mathlib/Algebra/Group/Submonoid/Operations.lean
1,225
1,225
theorem mrange_inl : mrange (inl M N) = prod ⊤ ⊥ := by
simpa only [mrange_eq_map] using map_inl ⊤
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov -/ import Mathlib.Algebra.Algebra.Basic import Mathlib.Algebra.BigOperators.Finsupp #align_import algebra.algebra.hom from "leanprover-community/mathlib"@"e97cf15cd1aec9bd5c193b2ffac5a6dc9118912b" /-! # Homomorphisms of `R`-algebras This file defines bundled homomorphisms of `R`-algebras. ## Main definitions * `AlgHom R A B`: the type of `R`-algebra morphisms from `A` to `B`. * `Algebra.ofId R A : R →ₐ[R] A`: the canonical map from `R` to `A`, as an `AlgHom`. ## Notations * `A →ₐ[R] B` : `R`-algebra homomorphism from `A` to `B`. -/ universe u v w u₁ v₁ /-- Defining the homomorphism in the category R-Alg. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): linter not ported yet structure AlgHom (R : Type u) (A : Type v) (B : Type w) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] extends RingHom A B where commutes' : ∀ r : R, toFun (algebraMap R A r) = algebraMap R B r #align alg_hom AlgHom /-- Reinterpret an `AlgHom` as a `RingHom` -/ add_decl_doc AlgHom.toRingHom @[inherit_doc AlgHom] infixr:25 " →ₐ " => AlgHom _ @[inherit_doc] notation:25 A " →ₐ[" R "] " B => AlgHom R A B /-- `AlgHomClass F R A B` asserts `F` is a type of bundled algebra homomorphisms from `A` to `B`. -/ class AlgHomClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [FunLike F A B] extends RingHomClass F A B : Prop where commutes : ∀ (f : F) (r : R), f (algebraMap R A r) = algebraMap R B r #align alg_hom_class AlgHomClass -- Porting note: `dangerousInstance` linter has become smarter about `outParam`s -- attribute [nolint dangerousInstance] AlgHomClass.toRingHomClass -- Porting note (#10618): simp can prove this -- attribute [simp] AlgHomClass.commutes namespace AlgHomClass variable {R A B F : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [FunLike F A B] -- see Note [lower instance priority] instance (priority := 100) linearMapClass [AlgHomClass F R A B] : LinearMapClass F R A B := { ‹AlgHomClass F R A B› with map_smulₛₗ := fun f r x => by simp only [Algebra.smul_def, map_mul, commutes, RingHom.id_apply] } #align alg_hom_class.linear_map_class AlgHomClass.linearMapClass -- Porting note (#11445): A new definition underlying a coercion `↑`. /-- Turn an element of a type `F` satisfying `AlgHomClass F α β` into an actual `AlgHom`. This is declared as the default coercion from `F` to `α →+* β`. -/ @[coe] def toAlgHom {F : Type*} [FunLike F A B] [AlgHomClass F R A B] (f : F) : A →ₐ[R] B where __ := (f : A →+* B) toFun := f commutes' := AlgHomClass.commutes f instance coeTC {F : Type*} [FunLike F A B] [AlgHomClass F R A B] : CoeTC F (A →ₐ[R] B) := ⟨AlgHomClass.toAlgHom⟩ #align alg_hom_class.alg_hom.has_coe_t AlgHomClass.coeTC end AlgHomClass namespace AlgHom variable {R : Type u} {A : Type v} {B : Type w} {C : Type u₁} {D : Type v₁} section Semiring variable [CommSemiring R] [Semiring A] [Semiring B] [Semiring C] [Semiring D] variable [Algebra R A] [Algebra R B] [Algebra R C] [Algebra R D] -- Porting note: we don't port specialized `CoeFun` instances if there is `DFunLike` instead #noalign alg_hom.has_coe_to_fun instance funLike : FunLike (A →ₐ[R] B) A B where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨⟨⟨_, _⟩, _⟩, _, _⟩, _⟩ rcases g with ⟨⟨⟨⟨_, _⟩, _⟩, _, _⟩, _⟩ congr -- Porting note: This instance is moved. instance algHomClass : AlgHomClass (A →ₐ[R] B) R A B where map_add f := f.map_add' map_zero f := f.map_zero' map_mul f := f.map_mul' map_one f := f.map_one' commutes f := f.commutes' #align alg_hom.alg_hom_class AlgHom.algHomClass /-- See Note [custom simps projection] -/ def Simps.apply {R : Type u} {α : Type v} {β : Type w} [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] (f : α →ₐ[R] β) : α → β := f initialize_simps_projections AlgHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [AlgHomClass F R A B] (f : F) : ⇑(f : A →ₐ[R] B) = f := rfl #align alg_hom.coe_coe AlgHom.coe_coe @[simp] theorem toFun_eq_coe (f : A →ₐ[R] B) : f.toFun = f := rfl #align alg_hom.to_fun_eq_coe AlgHom.toFun_eq_coe #noalign alg_hom.coe_ring_hom -- Porting note (#11445): A new definition underlying a coercion `↑`. @[coe] def toMonoidHom' (f : A →ₐ[R] B) : A →* B := (f : A →+* B) instance coeOutMonoidHom : CoeOut (A →ₐ[R] B) (A →* B) := ⟨AlgHom.toMonoidHom'⟩ #align alg_hom.coe_monoid_hom AlgHom.coeOutMonoidHom -- Porting note (#11445): A new definition underlying a coercion `↑`. @[coe] def toAddMonoidHom' (f : A →ₐ[R] B) : A →+ B := (f : A →+* B) instance coeOutAddMonoidHom : CoeOut (A →ₐ[R] B) (A →+ B) := ⟨AlgHom.toAddMonoidHom'⟩ #align alg_hom.coe_add_monoid_hom AlgHom.coeOutAddMonoidHom -- Porting note: Lean 3: `@[simp, norm_cast] coe_mk` -- Lean 4: `@[simp] coe_mk` & `@[norm_cast] coe_mks` @[simp] theorem coe_mk {f : A →+* B} (h) : ((⟨f, h⟩ : A →ₐ[R] B) : A → B) = f := rfl @[norm_cast] theorem coe_mks {f : A → B} (h₁ h₂ h₃ h₄ h₅) : ⇑(⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩ : A →ₐ[R] B) = f := rfl #align alg_hom.coe_mk AlgHom.coe_mks -- Porting note: This theorem is new. @[simp, norm_cast] theorem coe_ringHom_mk {f : A →+* B} (h) : ((⟨f, h⟩ : A →ₐ[R] B) : A →+* B) = f := rfl -- make the coercion the simp-normal form @[simp] theorem toRingHom_eq_coe (f : A →ₐ[R] B) : f.toRingHom = f := rfl #align alg_hom.to_ring_hom_eq_coe AlgHom.toRingHom_eq_coe @[simp, norm_cast] theorem coe_toRingHom (f : A →ₐ[R] B) : ⇑(f : A →+* B) = f := rfl #align alg_hom.coe_to_ring_hom AlgHom.coe_toRingHom @[simp, norm_cast] theorem coe_toMonoidHom (f : A →ₐ[R] B) : ⇑(f : A →* B) = f := rfl #align alg_hom.coe_to_monoid_hom AlgHom.coe_toMonoidHom @[simp, norm_cast] theorem coe_toAddMonoidHom (f : A →ₐ[R] B) : ⇑(f : A →+ B) = f := rfl #align alg_hom.coe_to_add_monoid_hom AlgHom.coe_toAddMonoidHom variable (φ : A →ₐ[R] B) theorem coe_fn_injective : @Function.Injective (A →ₐ[R] B) (A → B) (↑) := DFunLike.coe_injective #align alg_hom.coe_fn_injective AlgHom.coe_fn_injective theorem coe_fn_inj {φ₁ φ₂ : A →ₐ[R] B} : (φ₁ : A → B) = φ₂ ↔ φ₁ = φ₂ := DFunLike.coe_fn_eq #align alg_hom.coe_fn_inj AlgHom.coe_fn_inj theorem coe_ringHom_injective : Function.Injective ((↑) : (A →ₐ[R] B) → A →+* B) := fun φ₁ φ₂ H => coe_fn_injective <| show ((φ₁ : A →+* B) : A → B) = ((φ₂ : A →+* B) : A → B) from congr_arg _ H #align alg_hom.coe_ring_hom_injective AlgHom.coe_ringHom_injective theorem coe_monoidHom_injective : Function.Injective ((↑) : (A →ₐ[R] B) → A →* B) := RingHom.coe_monoidHom_injective.comp coe_ringHom_injective #align alg_hom.coe_monoid_hom_injective AlgHom.coe_monoidHom_injective theorem coe_addMonoidHom_injective : Function.Injective ((↑) : (A →ₐ[R] B) → A →+ B) := RingHom.coe_addMonoidHom_injective.comp coe_ringHom_injective #align alg_hom.coe_add_monoid_hom_injective AlgHom.coe_addMonoidHom_injective protected theorem congr_fun {φ₁ φ₂ : A →ₐ[R] B} (H : φ₁ = φ₂) (x : A) : φ₁ x = φ₂ x := DFunLike.congr_fun H x #align alg_hom.congr_fun AlgHom.congr_fun protected theorem congr_arg (φ : A →ₐ[R] B) {x y : A} (h : x = y) : φ x = φ y := DFunLike.congr_arg φ h #align alg_hom.congr_arg AlgHom.congr_arg @[ext] theorem ext {φ₁ φ₂ : A →ₐ[R] B} (H : ∀ x, φ₁ x = φ₂ x) : φ₁ = φ₂ := DFunLike.ext _ _ H #align alg_hom.ext AlgHom.ext theorem ext_iff {φ₁ φ₂ : A →ₐ[R] B} : φ₁ = φ₂ ↔ ∀ x, φ₁ x = φ₂ x := DFunLike.ext_iff #align alg_hom.ext_iff AlgHom.ext_iff @[simp] theorem mk_coe {f : A →ₐ[R] B} (h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩ : A →ₐ[R] B) = f := ext fun _ => rfl #align alg_hom.mk_coe AlgHom.mk_coe @[simp] theorem commutes (r : R) : φ (algebraMap R A r) = algebraMap R B r := φ.commutes' r #align alg_hom.commutes AlgHom.commutes theorem comp_algebraMap : (φ : A →+* B).comp (algebraMap R A) = algebraMap R B := RingHom.ext <| φ.commutes #align alg_hom.comp_algebra_map AlgHom.comp_algebraMap protected theorem map_add (r s : A) : φ (r + s) = φ r + φ s := map_add _ _ _ #align alg_hom.map_add AlgHom.map_add protected theorem map_zero : φ 0 = 0 := map_zero _ #align alg_hom.map_zero AlgHom.map_zero protected theorem map_mul (x y) : φ (x * y) = φ x * φ y := map_mul _ _ _ #align alg_hom.map_mul AlgHom.map_mul protected theorem map_one : φ 1 = 1 := map_one _ #align alg_hom.map_one AlgHom.map_one protected theorem map_pow (x : A) (n : ℕ) : φ (x ^ n) = φ x ^ n := map_pow _ _ _ #align alg_hom.map_pow AlgHom.map_pow -- @[simp] -- Porting note (#10618): simp can prove this protected theorem map_smul (r : R) (x : A) : φ (r • x) = r • φ x := map_smul _ _ _ #align alg_hom.map_smul AlgHom.map_smul protected theorem map_sum {ι : Type*} (f : ι → A) (s : Finset ι) : φ (∑ x ∈ s, f x) = ∑ x ∈ s, φ (f x) := map_sum _ _ _ #align alg_hom.map_sum AlgHom.map_sum protected theorem map_finsupp_sum {α : Type*} [Zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A) : φ (f.sum g) = f.sum fun i a => φ (g i a) := map_finsupp_sum _ _ _ #align alg_hom.map_finsupp_sum AlgHom.map_finsupp_sum #noalign alg_hom.map_bit0 #noalign alg_hom.map_bit1 /-- If a `RingHom` is `R`-linear, then it is an `AlgHom`. -/ def mk' (f : A →+* B) (h : ∀ (c : R) (x), f (c • x) = c • f x) : A →ₐ[R] B := { f with toFun := f commutes' := fun c => by simp only [Algebra.algebraMap_eq_smul_one, h, f.map_one] } #align alg_hom.mk' AlgHom.mk' @[simp] theorem coe_mk' (f : A →+* B) (h : ∀ (c : R) (x), f (c • x) = c • f x) : ⇑(mk' f h) = f := rfl #align alg_hom.coe_mk' AlgHom.coe_mk' section variable (R A) /-- Identity map as an `AlgHom`. -/ protected def id : A →ₐ[R] A := { RingHom.id A with commutes' := fun _ => rfl } #align alg_hom.id AlgHom.id @[simp] theorem coe_id : ⇑(AlgHom.id R A) = id := rfl #align alg_hom.coe_id AlgHom.coe_id @[simp] theorem id_toRingHom : (AlgHom.id R A : A →+* A) = RingHom.id _ := rfl #align alg_hom.id_to_ring_hom AlgHom.id_toRingHom end theorem id_apply (p : A) : AlgHom.id R A p = p := rfl #align alg_hom.id_apply AlgHom.id_apply /-- Composition of algebra homeomorphisms. -/ def comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : A →ₐ[R] C := { φ₁.toRingHom.comp ↑φ₂ with commutes' := fun r : R => by rw [← φ₁.commutes, ← φ₂.commutes]; rfl } #align alg_hom.comp AlgHom.comp @[simp] theorem coe_comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : ⇑(φ₁.comp φ₂) = φ₁ ∘ φ₂ := rfl #align alg_hom.coe_comp AlgHom.coe_comp theorem comp_apply (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) (p : A) : φ₁.comp φ₂ p = φ₁ (φ₂ p) := rfl #align alg_hom.comp_apply AlgHom.comp_apply theorem comp_toRingHom (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : (φ₁.comp φ₂ : A →+* C) = (φ₁ : B →+* C).comp ↑φ₂ := rfl #align alg_hom.comp_to_ring_hom AlgHom.comp_toRingHom @[simp] theorem comp_id : φ.comp (AlgHom.id R A) = φ := ext fun _x => rfl #align alg_hom.comp_id AlgHom.comp_id @[simp] theorem id_comp : (AlgHom.id R B).comp φ = φ := ext fun _x => rfl #align alg_hom.id_comp AlgHom.id_comp theorem comp_assoc (φ₁ : C →ₐ[R] D) (φ₂ : B →ₐ[R] C) (φ₃ : A →ₐ[R] B) : (φ₁.comp φ₂).comp φ₃ = φ₁.comp (φ₂.comp φ₃) := ext fun _x => rfl #align alg_hom.comp_assoc AlgHom.comp_assoc /-- R-Alg ⥤ R-Mod -/ def toLinearMap : A →ₗ[R] B where toFun := φ map_add' := map_add _ map_smul' := map_smul _ #align alg_hom.to_linear_map AlgHom.toLinearMap @[simp] theorem toLinearMap_apply (p : A) : φ.toLinearMap p = φ p := rfl #align alg_hom.to_linear_map_apply AlgHom.toLinearMap_apply theorem toLinearMap_injective : Function.Injective (toLinearMap : _ → A →ₗ[R] B) := fun _φ₁ _φ₂ h => ext <| LinearMap.congr_fun h #align alg_hom.to_linear_map_injective AlgHom.toLinearMap_injective @[simp] theorem comp_toLinearMap (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).toLinearMap = g.toLinearMap.comp f.toLinearMap := rfl #align alg_hom.comp_to_linear_map AlgHom.comp_toLinearMap @[simp] theorem toLinearMap_id : toLinearMap (AlgHom.id R A) = LinearMap.id := LinearMap.ext fun _ => rfl #align alg_hom.to_linear_map_id AlgHom.toLinearMap_id /-- Promote a `LinearMap` to an `AlgHom` by supplying proofs about the behavior on `1` and `*`. -/ @[simps] def ofLinearMap (f : A →ₗ[R] B) (map_one : f 1 = 1) (map_mul : ∀ x y, f (x * y) = f x * f y) : A →ₐ[R] B := { f.toAddMonoidHom with toFun := f map_one' := map_one map_mul' := map_mul commutes' := fun c => by simp only [Algebra.algebraMap_eq_smul_one, f.map_smul, map_one] } #align alg_hom.of_linear_map AlgHom.ofLinearMap @[simp] theorem ofLinearMap_toLinearMap (map_one) (map_mul) : ofLinearMap φ.toLinearMap map_one map_mul = φ := by ext rfl #align alg_hom.of_linear_map_to_linear_map AlgHom.ofLinearMap_toLinearMap @[simp]
Mathlib/Algebra/Algebra/Hom.lean
395
398
theorem toLinearMap_ofLinearMap (f : A →ₗ[R] B) (map_one) (map_mul) : toLinearMap (ofLinearMap f map_one map_mul) = f := by
ext rfl
/- Copyright (c) 2020 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis, Eric Wieser -/ import Mathlib.GroupTheory.Congruence.Basic import Mathlib.LinearAlgebra.Basic import Mathlib.LinearAlgebra.Multilinear.TensorProduct import Mathlib.Tactic.AdaptationNote #align_import linear_algebra.pi_tensor_product from "leanprover-community/mathlib"@"ce11c3c2a285bbe6937e26d9792fda4e51f3fe1a" /-! # Tensor product of an indexed family of modules over commutative semirings We define the tensor product of an indexed family `s : ι → Type*` of modules over commutative semirings. We denote this space by `⨂[R] i, s i` and define it as `FreeAddMonoid (R × Π i, s i)` quotiented by the appropriate equivalence relation. The treatment follows very closely that of the binary tensor product in `LinearAlgebra/TensorProduct.lean`. ## Main definitions * `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor product of all the `s i`'s. This is denoted by `⨂[R] i, s i`. * `tprod R f` with `f : Π i, s i` is the tensor product of the vectors `f i` over all `i : ι`. This is bundled as a multilinear map from `Π i, s i` to `⨂[R] i, s i`. * `liftAddHom` constructs an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a function `φ : (R × Π i, s i) → F` with the appropriate properties. * `lift φ` with `φ : MultilinearMap R s E` is the corresponding linear map `(⨂[R] i, s i) →ₗ[R] E`. This is bundled as a linear equivalence. * `PiTensorProduct.reindex e` re-indexes the components of `⨂[R] i : ι, M` along `e : ι ≃ ι₂`. * `PiTensorProduct.tmulEquiv` equivalence between a `TensorProduct` of `PiTensorProduct`s and a single `PiTensorProduct`. ## Notations * `⨂[R] i, s i` is defined as localized notation in locale `TensorProduct`. * `⨂ₜ[R] i, f i` with `f : ∀ i, s i` is defined globally as the tensor product of all the `f i`'s. ## Implementation notes * We define it via `FreeAddMonoid (R × Π i, s i)` with the `R` representing a "hidden" tensor factor, rather than `FreeAddMonoid (Π i, s i)` to ensure that, if `ι` is an empty type, the space is isomorphic to the base ring `R`. * We have not restricted the index type `ι` to be a `Fintype`, as nothing we do here strictly requires it. However, problems may arise in the case where `ι` is infinite; use at your own caution. * Instead of requiring `DecidableEq ι` as an argument to `PiTensorProduct` itself, we include it as an argument in the constructors of the relation. A decidability instance still has to come from somewhere due to the use of `Function.update`, but this hides it from the downstream user. See the implementation notes for `MultilinearMap` for an extended discussion of this choice. ## TODO * Define tensor powers, symmetric subspace, etc. * API for the various ways `ι` can be split into subsets; connect this with the binary tensor product. * Include connection with holors. * Port more of the API from the binary tensor product over to this case. ## Tags multilinear, tensor, tensor product -/ suppress_compilation open Function section Semiring variable {ι ι₂ ι₃ : Type*} variable {R : Type*} [CommSemiring R] variable {R₁ R₂ : Type*} variable {s : ι → Type*} [∀ i, AddCommMonoid (s i)] [∀ i, Module R (s i)] variable {M : Type*} [AddCommMonoid M] [Module R M] variable {E : Type*} [AddCommMonoid E] [Module R E] variable {F : Type*} [AddCommMonoid F] namespace PiTensorProduct variable (R) (s) /-- The relation on `FreeAddMonoid (R × Π i, s i)` that generates a congruence whose quotient is the tensor product. -/ inductive Eqv : FreeAddMonoid (R × Π i, s i) → FreeAddMonoid (R × Π i, s i) → Prop | of_zero : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), Eqv (FreeAddMonoid.of (r, f)) 0 | of_zero_scalar : ∀ f : Π i, s i, Eqv (FreeAddMonoid.of (0, f)) 0 | of_add : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i), Eqv (FreeAddMonoid.of (r, update f i m₁) + FreeAddMonoid.of (r, update f i m₂)) (FreeAddMonoid.of (r, update f i (m₁ + m₂))) | of_add_scalar : ∀ (r r' : R) (f : Π i, s i), Eqv (FreeAddMonoid.of (r, f) + FreeAddMonoid.of (r', f)) (FreeAddMonoid.of (r + r', f)) | of_smul : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (r' : R), Eqv (FreeAddMonoid.of (r, update f i (r' • f i))) (FreeAddMonoid.of (r' * r, f)) | add_comm : ∀ x y, Eqv (x + y) (y + x) #align pi_tensor_product.eqv PiTensorProduct.Eqv end PiTensorProduct variable (R) (s) /-- `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor product of all the `s i`'s. This is denoted by `⨂[R] i, s i`. -/ def PiTensorProduct : Type _ := (addConGen (PiTensorProduct.Eqv R s)).Quotient #align pi_tensor_product PiTensorProduct variable {R} unsuppress_compilation in /-- This enables the notation `⨂[R] i : ι, s i` for the pi tensor product `PiTensorProduct`, given an indexed family of types `s : ι → Type*`. -/ scoped[TensorProduct] notation3:100"⨂["R"] "(...)", "r:(scoped f => PiTensorProduct R f) => r open TensorProduct namespace PiTensorProduct section Module instance : AddCommMonoid (⨂[R] i, s i) := { (addConGen (PiTensorProduct.Eqv R s)).addMonoid with add_comm := fun x y ↦ AddCon.induction_on₂ x y fun _ _ ↦ Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ } instance : Inhabited (⨂[R] i, s i) := ⟨0⟩ variable (R) {s} /-- `tprodCoeff R r f` with `r : R` and `f : Π i, s i` is the tensor product of the vectors `f i` over all `i : ι`, multiplied by the coefficient `r`. Note that this is meant as an auxiliary definition for this file alone, and that one should use `tprod` defined below for most purposes. -/ def tprodCoeff (r : R) (f : Π i, s i) : ⨂[R] i, s i := AddCon.mk' _ <| FreeAddMonoid.of (r, f) #align pi_tensor_product.tprod_coeff PiTensorProduct.tprodCoeff variable {R} theorem zero_tprodCoeff (f : Π i, s i) : tprodCoeff R 0 f = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_scalar _ #align pi_tensor_product.zero_tprod_coeff PiTensorProduct.zero_tprodCoeff theorem zero_tprodCoeff' (z : R) (f : Π i, s i) (i : ι) (hf : f i = 0) : tprodCoeff R z f = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero _ _ i hf #align pi_tensor_product.zero_tprod_coeff' PiTensorProduct.zero_tprodCoeff' theorem add_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i) : tprodCoeff R z (update f i m₁) + tprodCoeff R z (update f i m₂) = tprodCoeff R z (update f i (m₁ + m₂)) := Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add _ z f i m₁ m₂) #align pi_tensor_product.add_tprod_coeff PiTensorProduct.add_tprodCoeff theorem add_tprodCoeff' (z₁ z₂ : R) (f : Π i, s i) : tprodCoeff R z₁ f + tprodCoeff R z₂ f = tprodCoeff R (z₁ + z₂) f := Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add_scalar z₁ z₂ f) #align pi_tensor_product.add_tprod_coeff' PiTensorProduct.add_tprodCoeff' theorem smul_tprodCoeff_aux [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R) : tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r * z) f := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _ _ _ #align pi_tensor_product.smul_tprod_coeff_aux PiTensorProduct.smul_tprodCoeff_aux theorem smul_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R₁) [SMul R₁ R] [IsScalarTower R₁ R R] [SMul R₁ (s i)] [IsScalarTower R₁ R (s i)] : tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r • z) f := by have h₁ : r • z = r • (1 : R) * z := by rw [smul_mul_assoc, one_mul] have h₂ : r • f i = (r • (1 : R)) • f i := (smul_one_smul _ _ _).symm rw [h₁, h₂] exact smul_tprodCoeff_aux z f i _ #align pi_tensor_product.smul_tprod_coeff PiTensorProduct.smul_tprodCoeff /-- Construct an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a function `φ : (R × Π i, s i) → F` with the appropriate properties. -/ def liftAddHom (φ : (R × Π i, s i) → F) (C0 : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), φ (r, f) = 0) (C0' : ∀ f : Π i, s i, φ (0, f) = 0) (C_add : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i), φ (r, update f i m₁) + φ (r, update f i m₂) = φ (r, update f i (m₁ + m₂))) (C_add_scalar : ∀ (r r' : R) (f : Π i, s i), φ (r, f) + φ (r', f) = φ (r + r', f)) (C_smul : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (r' : R), φ (r, update f i (r' • f i)) = φ (r' * r, f)) : (⨂[R] i, s i) →+ F := (addConGen (PiTensorProduct.Eqv R s)).lift (FreeAddMonoid.lift φ) <| AddCon.addConGen_le fun x y hxy ↦ match hxy with | Eqv.of_zero r' f i hf => (AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0 r' f i hf] | Eqv.of_zero_scalar f => (AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0'] | Eqv.of_add inst z f i m₁ m₂ => (AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_add inst] | Eqv.of_add_scalar z₁ z₂ f => (AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C_add_scalar] | Eqv.of_smul inst z f i r' => (AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_smul inst] | Eqv.add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [AddMonoidHom.map_add, add_comm] #align pi_tensor_product.lift_add_hom PiTensorProduct.liftAddHom /-- Induct using `tprodCoeff` -/ @[elab_as_elim] protected theorem induction_on' {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i) (tprodCoeff : ∀ (r : R) (f : Π i, s i), motive (tprodCoeff R r f)) (add : ∀ x y, motive x → motive y → motive (x + y)) : motive z := by have C0 : motive 0 := by have h₁ := tprodCoeff 0 0 rwa [zero_tprodCoeff] at h₁ refine AddCon.induction_on z fun x ↦ FreeAddMonoid.recOn x C0 ?_ simp_rw [AddCon.coe_add] refine fun f y ih ↦ add _ _ ?_ ih convert tprodCoeff f.1 f.2 #align pi_tensor_product.induction_on' PiTensorProduct.induction_on' section DistribMulAction variable [Monoid R₁] [DistribMulAction R₁ R] [SMulCommClass R₁ R R] variable [Monoid R₂] [DistribMulAction R₂ R] [SMulCommClass R₂ R R] -- Most of the time we want the instance below this one, which is easier for typeclass resolution -- to find. instance hasSMul' : SMul R₁ (⨂[R] i, s i) := ⟨fun r ↦ liftAddHom (fun f : R × Π i, s i ↦ tprodCoeff R (r • f.1) f.2) (fun r' f i hf ↦ by simp_rw [zero_tprodCoeff' _ f i hf]) (fun f ↦ by simp [zero_tprodCoeff]) (fun r' f i m₁ m₂ ↦ by simp [add_tprodCoeff]) (fun r' r'' f ↦ by simp [add_tprodCoeff', mul_add]) fun z f i r' ↦ by simp [smul_tprodCoeff, mul_smul_comm]⟩ #align pi_tensor_product.has_smul' PiTensorProduct.hasSMul' instance : SMul R (⨂[R] i, s i) := PiTensorProduct.hasSMul' theorem smul_tprodCoeff' (r : R₁) (z : R) (f : Π i, s i) : r • tprodCoeff R z f = tprodCoeff R (r • z) f := rfl #align pi_tensor_product.smul_tprod_coeff' PiTensorProduct.smul_tprodCoeff' protected theorem smul_add (r : R₁) (x y : ⨂[R] i, s i) : r • (x + y) = r • x + r • y := AddMonoidHom.map_add _ _ _ #align pi_tensor_product.smul_add PiTensorProduct.smul_add instance distribMulAction' : DistribMulAction R₁ (⨂[R] i, s i) where smul := (· • ·) smul_add r x y := AddMonoidHom.map_add _ _ _ mul_smul r r' x := PiTensorProduct.induction_on' x (fun {r'' f} ↦ by simp [smul_tprodCoeff', smul_smul]) fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy] one_smul x := PiTensorProduct.induction_on' x (fun {r f} ↦ by rw [smul_tprodCoeff', one_smul]) fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy] smul_zero r := AddMonoidHom.map_zero _ #align pi_tensor_product.distrib_mul_action' PiTensorProduct.distribMulAction' instance smulCommClass' [SMulCommClass R₁ R₂ R] : SMulCommClass R₁ R₂ (⨂[R] i, s i) := ⟨fun {r' r''} x ↦ PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_comm]) fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩ #align pi_tensor_product.smul_comm_class' PiTensorProduct.smulCommClass' instance isScalarTower' [SMul R₁ R₂] [IsScalarTower R₁ R₂ R] : IsScalarTower R₁ R₂ (⨂[R] i, s i) := ⟨fun {r' r''} x ↦ PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_assoc]) fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩ #align pi_tensor_product.is_scalar_tower' PiTensorProduct.isScalarTower' end DistribMulAction -- Most of the time we want the instance below this one, which is easier for typeclass resolution -- to find. instance module' [Semiring R₁] [Module R₁ R] [SMulCommClass R₁ R R] : Module R₁ (⨂[R] i, s i) := { PiTensorProduct.distribMulAction' with add_smul := fun r r' x ↦ PiTensorProduct.induction_on' x (fun {r f} ↦ by simp_rw [smul_tprodCoeff', add_smul, add_tprodCoeff']) fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_add_add_comm] zero_smul := fun x ↦ PiTensorProduct.induction_on' x (fun {r f} ↦ by simp_rw [smul_tprodCoeff', zero_smul, zero_tprodCoeff]) fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_zero] } #align pi_tensor_product.module' PiTensorProduct.module' -- shortcut instances instance : Module R (⨂[R] i, s i) := PiTensorProduct.module' instance : SMulCommClass R R (⨂[R] i, s i) := PiTensorProduct.smulCommClass' instance : IsScalarTower R R (⨂[R] i, s i) := PiTensorProduct.isScalarTower' variable (R) /-- The canonical `MultilinearMap R s (⨂[R] i, s i)`. `tprod R fun i => f i` has notation `⨂ₜ[R] i, f i`. -/ def tprod : MultilinearMap R s (⨂[R] i, s i) where toFun := tprodCoeff R 1 map_add' {_ f} i x y := (add_tprodCoeff (1 : R) f i x y).symm map_smul' {_ f} i r x := by rw [smul_tprodCoeff', ← smul_tprodCoeff (1 : R) _ i, update_idem, update_same] #align pi_tensor_product.tprod PiTensorProduct.tprod variable {R} unsuppress_compilation in @[inherit_doc tprod] notation3:100 "⨂ₜ["R"] "(...)", "r:(scoped f => tprod R f) => r -- Porting note (#10756): new theorem theorem tprod_eq_tprodCoeff_one : ⇑(tprod R : MultilinearMap R s (⨂[R] i, s i)) = tprodCoeff R 1 := rfl @[simp] theorem tprodCoeff_eq_smul_tprod (z : R) (f : Π i, s i) : tprodCoeff R z f = z • tprod R f := by have : z = z • (1 : R) := by simp only [mul_one, Algebra.id.smul_eq_mul] conv_lhs => rw [this] rfl #align pi_tensor_product.tprod_coeff_eq_smul_tprod PiTensorProduct.tprodCoeff_eq_smul_tprod /-- The image of an element `p` of `FreeAddMonoid (R × Π i, s i)` in the `PiTensorProduct` is equal to the sum of `a • ⨂ₜ[R] i, m i` over all the entries `(a, m)` of `p`. -/ lemma _root_.FreeAddMonoid.toPiTensorProduct (p : FreeAddMonoid (R × Π i, s i)) : AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p = List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p) := by match p with | [] => rw [List.map_nil, List.sum_nil]; rfl | x :: ps => rw [List.map_cons, List.sum_cons, ← List.singleton_append, ← toPiTensorProduct ps, ← tprodCoeff_eq_smul_tprod]; rfl /-- The set of lifts of an element `x` of `⨂[R] i, s i` in `FreeAddMonoid (R × Π i, s i)`. -/ def lifts (x : ⨂[R] i, s i) : Set (FreeAddMonoid (R × Π i, s i)) := {p | AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p = x} /-- An element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i` if and only if `x` is equal to to the sum of `a • ⨂ₜ[R] i, m i` over all the entries `(a, m)` of `p`. -/ lemma mem_lifts_iff (x : ⨂[R] i, s i) (p : FreeAddMonoid (R × Π i, s i)) : p ∈ lifts x ↔ List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p) = x := by simp only [lifts, Set.mem_setOf_eq, FreeAddMonoid.toPiTensorProduct] /-- Every element of `⨂[R] i, s i` has a lift in `FreeAddMonoid (R × Π i, s i)`. -/ lemma nonempty_lifts (x : ⨂[R] i, s i) : Set.Nonempty (lifts x) := by existsi @Quotient.out _ (addConGen (PiTensorProduct.Eqv R s)).toSetoid x simp only [lifts, Set.mem_setOf_eq] rw [← AddCon.quot_mk_eq_coe] erw [Quot.out_eq] /-- The empty list lifts the element `0` of `⨂[R] i, s i`. -/ lemma lifts_zero : 0 ∈ lifts (0 : ⨂[R] i, s i) := by rw [mem_lifts_iff]; erw [List.map_nil]; rw [List.sum_nil] /-- If elements `p,q` of `FreeAddMonoid (R × Π i, s i)` lift elements `x,y` of `⨂[R] i, s i` respectively, then `p + q` lifts `x + y`. -/ lemma lifts_add {x y : ⨂[R] i, s i} {p q : FreeAddMonoid (R × Π i, s i)} (hp : p ∈ lifts x) (hq : q ∈ lifts y): p + q ∈ lifts (x + y) := by simp only [lifts, Set.mem_setOf_eq, AddCon.coe_add] rw [hp, hq] /-- If an element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i`, and if `a` is an element of `R`, then the list obtained by multiplying the first entry of each element of `p` by `a` lifts `a • x`. -/ lemma lifts_smul {x : ⨂[R] i, s i} {p : FreeAddMonoid (R × Π i, s i)} (h : p ∈ lifts x) (a : R) : List.map (fun (y : R × Π i, s i) ↦ (a * y.1, y.2)) p ∈ lifts (a • x) := by rw [mem_lifts_iff] at h ⊢ rw [← List.comp_map, ← h, List.smul_sum, ← List.comp_map] congr 2 ext _ simp only [comp_apply, smul_smul] /-- Induct using scaled versions of `PiTensorProduct.tprod`. -/ @[elab_as_elim] protected theorem induction_on {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i) (smul_tprod : ∀ (r : R) (f : Π i, s i), motive (r • tprod R f)) (add : ∀ x y, motive x → motive y → motive (x + y)) : motive z := by simp_rw [← tprodCoeff_eq_smul_tprod] at smul_tprod exact PiTensorProduct.induction_on' z smul_tprod add #align pi_tensor_product.induction_on PiTensorProduct.induction_on @[ext] theorem ext {φ₁ φ₂ : (⨂[R] i, s i) →ₗ[R] E} (H : φ₁.compMultilinearMap (tprod R) = φ₂.compMultilinearMap (tprod R)) : φ₁ = φ₂ := by refine LinearMap.ext ?_ refine fun z ↦ PiTensorProduct.induction_on' z ?_ fun {x y} hx hy ↦ by rw [φ₁.map_add, φ₂.map_add, hx, hy] · intro r f rw [tprodCoeff_eq_smul_tprod, φ₁.map_smul, φ₂.map_smul] apply _root_.congr_arg exact MultilinearMap.congr_fun H f #align pi_tensor_product.ext PiTensorProduct.ext /-- The pure tensors (i.e. the elements of the image of `PiTensorProduct.tprod`) span the tensor product. -/ theorem span_tprod_eq_top : Submodule.span R (Set.range (tprod R)) = (⊤ : Submodule R (⨂[R] i, s i)) := Submodule.eq_top_iff'.mpr fun t ↦ t.induction_on (fun _ _ ↦ Submodule.smul_mem _ _ (Submodule.subset_span (by simp only [Set.mem_range, exists_apply_eq_apply]))) (fun _ _ hx hy ↦ Submodule.add_mem _ hx hy) end Module section Multilinear open MultilinearMap variable {s} section lift /-- Auxiliary function to constructing a linear map `(⨂[R] i, s i) → E` given a `MultilinearMap R s E` with the property that its composition with the canonical `MultilinearMap R s (⨂[R] i, s i)` is the given multilinear map. -/ def liftAux (φ : MultilinearMap R s E) : (⨂[R] i, s i) →+ E := liftAddHom (fun p : R × Π i, s i ↦ p.1 • φ p.2) (fun z f i hf ↦ by simp_rw [map_coord_zero φ i hf, smul_zero]) (fun f ↦ by simp_rw [zero_smul]) (fun z f i m₁ m₂ ↦ by simp_rw [← smul_add, φ.map_add]) (fun z₁ z₂ f ↦ by rw [← add_smul]) fun z f i r ↦ by simp [φ.map_smul, smul_smul, mul_comm] #align pi_tensor_product.lift_aux PiTensorProduct.liftAux
Mathlib/LinearAlgebra/PiTensorProduct.lean
433
446
theorem liftAux_tprod (φ : MultilinearMap R s E) (f : Π i, s i) : liftAux φ (tprod R f) = φ f := by
simp only [liftAux, liftAddHom, tprod_eq_tprodCoeff_one, tprodCoeff, AddCon.coe_mk'] -- The end of this proof was very different before leanprover/lean4#2644: -- rw [FreeAddMonoid.of, FreeAddMonoid.ofList, Equiv.refl_apply, AddCon.lift_coe] -- dsimp [FreeAddMonoid.lift, FreeAddMonoid.sumAux] -- show _ • _ = _ -- rw [one_smul] erw [AddCon.lift_coe] erw [FreeAddMonoid.of] dsimp [FreeAddMonoid.ofList] rw [← one_smul R (φ f)] erw [Equiv.refl_apply] convert one_smul R (φ f) simp
/- Copyright (c) 2022 Joachim Breitner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joachim Breitner -/ import Mathlib.GroupTheory.OrderOfElement import Mathlib.Data.Finset.NoncommProd import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Order.SupIndep #align_import group_theory.noncomm_pi_coprod from "leanprover-community/mathlib"@"6f9f36364eae3f42368b04858fd66d6d9ae730d8" /-! # Canonical homomorphism from a finite family of monoids This file defines the construction of the canonical homomorphism from a family of monoids. Given a family of morphisms `ϕ i : N i →* M` for each `i : ι` where elements in the images of different morphisms commute, we obtain a canonical morphism `MonoidHom.noncommPiCoprod : (Π i, N i) →* M` that coincides with `ϕ` ## Main definitions * `MonoidHom.noncommPiCoprod : (Π i, N i) →* M` is the main homomorphism * `Subgroup.noncommPiCoprod : (Π i, H i) →* G` is the specialization to `H i : Subgroup G` and the subgroup embedding. ## Main theorems * `MonoidHom.noncommPiCoprod` coincides with `ϕ i` when restricted to `N i` * `MonoidHom.noncommPiCoprod_mrange`: The range of `MonoidHom.noncommPiCoprod` is `⨆ (i : ι), (ϕ i).mrange` * `MonoidHom.noncommPiCoprod_range`: The range of `MonoidHom.noncommPiCoprod` is `⨆ (i : ι), (ϕ i).range` * `Subgroup.noncommPiCoprod_range`: The range of `Subgroup.noncommPiCoprod` is `⨆ (i : ι), H i`. * `MonoidHom.injective_noncommPiCoprod_of_independent`: in the case of groups, `pi_hom.hom` is injective if the `ϕ` are injective and the ranges of the `ϕ` are independent. * `MonoidHom.independent_range_of_coprime_order`: If the `N i` have coprime orders, then the ranges of the `ϕ` are independent. * `Subgroup.independent_of_coprime_order`: If commuting normal subgroups `H i` have coprime orders, they are independent. -/ namespace Subgroup variable {G : Type*} [Group G] /-- `Finset.noncommProd` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `Subgroup.disjoint_iff_mul_eq_one`. -/ @[to_additive "`Finset.noncommSum` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `AddSubgroup.disjoint_iff_add_eq_zero`. "]
Mathlib/GroupTheory/NoncommPiCoprod.lean
55
78
theorem eq_one_of_noncommProd_eq_one_of_independent {ι : Type*} (s : Finset ι) (f : ι → G) (comm) (K : ι → Subgroup G) (hind : CompleteLattice.Independent K) (hmem : ∀ x ∈ s, f x ∈ K x) (heq1 : s.noncommProd f comm = 1) : ∀ i ∈ s, f i = 1 := by
classical revert heq1 induction' s using Finset.induction_on with i s hnmem ih · simp · have hcomm := comm.mono (Finset.coe_subset.2 <| Finset.subset_insert _ _) simp only [Finset.forall_mem_insert] at hmem have hmem_bsupr : s.noncommProd f hcomm ∈ ⨆ i ∈ (s : Set ι), K i := by refine Subgroup.noncommProd_mem _ _ ?_ intro x hx have : K x ≤ ⨆ i ∈ (s : Set ι), K i := le_iSup₂ (f := fun i _ => K i) x hx exact this (hmem.2 x hx) intro heq1 rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ hnmem] at heq1 have hnmem' : i ∉ (s : Set ι) := by simpa obtain ⟨heq1i : f i = 1, heq1S : s.noncommProd f _ = 1⟩ := Subgroup.disjoint_iff_mul_eq_one.mp (hind.disjoint_biSup hnmem') hmem.1 hmem_bsupr heq1 intro i h simp only [Finset.mem_insert] at h rcases h with (rfl | h) · exact heq1i · refine ih hcomm hmem.2 heq1S _ h
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain import Mathlib.Algebra.CharP.Reduced import Mathlib.Tactic.ApplyFun #align_import field_theory.finite.basic from "leanprover-community/mathlib"@"12a85fac627bea918960da036049d611b1a3ee43" /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≤ natDegree p * (univ.image fun x => eval x p).card := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = (p - C a).roots.toFinset.card := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≤ _ := card_roots_sub_C' hp) #align finite_field.card_image_polynomial_eval FiniteField.card_image_polynomial_eval /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices ¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_self]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card) <| calc 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card ≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * (univ.image fun x : R => eval x f).card + natDegree (-g) * (univ.image fun x : R => eval x (-g)).card := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card := by rw [card_union_of_disjoint hd]; simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] #align finite_field.exists_root_sum_quadratic FiniteField.exists_root_sum_quadratic end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] : ∏ x : Kˣ, x = (-1 : Kˣ) := by classical have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp (config := { contextual := true }) [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one] #align finite_field.prod_univ_units_id_eq_neg_one FiniteField.prod_univ_units_id_eq_neg_one set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : Kˣ) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_one] /-- The sum of a nontrivial subgroup of the units of a field is zero. -/ theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) : ∑ x : G, (x.val : K) = 0 := by rw [Subgroup.ne_bot_iff_exists_ne_one] at hg rcases hg with ⟨a, ha⟩ -- The action of a on G as an embedding let a_mul_emb : G ↪ G := mulLeftEmbedding a -- ... and leaves G unchanged have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp -- Therefore the sum of x over a G is the sum of a x over G have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K) -- ... and the former is the sum of x over G. -- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x simp only [a_mul_emb, h_unchanged, Function.Embedding.coeFn_mk, Function.Embedding.toFun_eq_coe, mulLeftEmbedding_apply, Submonoid.coe_mul, Subgroup.coe_toSubmonoid, Units.val_mul, ← Finset.mul_sum] at h_sum_map -- thus one of (a - 1) or ∑ G, x is zero have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self] apply Or.resolve_left hzero contrapose! ha ext rwa [← sub_eq_zero] /-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/ @[simp] theorem sum_subgroup_units [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] : ∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by by_cases G_bot : G = ⊥ · subst G_bot simp only [ite_true, Subgroup.mem_bot, Fintype.card_ofSubsingleton, Nat.cast_ite, Nat.cast_one, Nat.cast_zero, univ_unique, Set.default_coe_singleton, sum_singleton, Units.val_one] · simp only [G_bot, ite_false] exact sum_subgroup_units_eq_zero G_bot @[simp] theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) : ∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by nontriviality K have := NoZeroDivisors.to_isDomain K rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩ rw [Finset.sum_eq_multiset_sum] have h_multiset_map : Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) = Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by simp_rw [← mul_pow] have as_comp : (fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k) = (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by funext x simp only [Function.comp_apply, Submonoid.coe_mul, Subgroup.coe_toSubmonoid, Units.val_mul] rw [as_comp, ← Multiset.map_map] congr rw [eq_comm] exact Multiset.map_univ_val_equiv (Equiv.mulRight a) have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum = (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by rw [h_multiset_map] rw [Multiset.sum_map_mul_right] at h_multiset_map_sum have hzero : (((a : Kˣ) : K) ^ k - 1 : K) * (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self] rw [mul_eq_zero] at hzero refine hzero.resolve_left fun h => ha ?_ ext rw [← sub_eq_zero] simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h] section variable [GroupWithZero K] [Fintype K] theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by calc a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by rw [Units.val_pow_eq_pow_val, Units.val_mk0] _ = 1 := by classical rw [← Fintype.card_units, pow_card_eq_one] rfl #align finite_field.pow_card_sub_one_eq_one FiniteField.pow_card_sub_one_eq_one theorem pow_card (a : K) : a ^ q = a := by by_cases h : a = 0; · rw [h]; apply zero_pow Fintype.card_ne_zero rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one, pow_card_sub_one_eq_one a h, one_mul] #align finite_field.pow_card FiniteField.pow_card
Mathlib/FieldTheory/Finite/Basic.lean
232
235
theorem pow_card_pow (n : ℕ) (a : K) : a ^ q ^ n = a := by
induction' n with n ih · simp · simp [pow_succ, pow_mul, ih, pow_card]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Algebra.Group.Int import Mathlib.Data.Int.Lemmas import Mathlib.Data.Set.Subsingleton import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Order.GaloisConnection import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity #align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c" /-! # Floor and ceil ## Summary We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. ## Main Definitions * `FloorSemiring`: An ordered semiring with natural-valued floor and ceil. * `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`. * `Nat.ceil a`: Least natural `n` such that `a ≤ n`. * `FloorRing`: A linearly ordered ring with integer-valued floor and ceil. * `Int.floor a`: Greatest integer `z` such that `z ≤ a`. * `Int.ceil a`: Least integer `z` such that `a ≤ z`. * `Int.fract a`: Fractional part of `a`, defined as `a - floor a`. * `round a`: Nearest integer to `a`. It rounds halves towards infinity. ## Notations * `⌊a⌋₊` is `Nat.floor a`. * `⌈a⌉₊` is `Nat.ceil a`. * `⌊a⌋` is `Int.floor a`. * `⌈a⌉` is `Int.ceil a`. The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation for `nnnorm`. ## TODO `LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in many lemmas. ## Tags rounding, floor, ceil -/ open Set variable {F α β : Type*} /-! ### Floor semiring -/ /-- A `FloorSemiring` is an ordered semiring over `α` with a function `floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`. Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/ class FloorSemiring (α) [OrderedSemiring α] where /-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/ floor : α → ℕ /-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/ ceil : α → ℕ /-- `FloorSemiring.floor` of a negative element is zero. -/ floor_of_neg {a : α} (ha : a < 0) : floor a = 0 /-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is smaller than `a`. -/ gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a /-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/ gc_ceil : GaloisConnection ceil (↑) #align floor_semiring FloorSemiring instance : FloorSemiring ℕ where floor := id ceil := id floor_of_neg ha := (Nat.not_lt_zero _ ha).elim gc_floor _ := by rw [Nat.cast_id] rfl gc_ceil n a := by rw [Nat.cast_id] rfl namespace Nat section OrderedSemiring variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} /-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/ def floor : α → ℕ := FloorSemiring.floor #align nat.floor Nat.floor /-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/ def ceil : α → ℕ := FloorSemiring.ceil #align nat.ceil Nat.ceil @[simp] theorem floor_nat : (Nat.floor : ℕ → ℕ) = id := rfl #align nat.floor_nat Nat.floor_nat @[simp] theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id := rfl #align nat.ceil_nat Nat.ceil_nat @[inherit_doc] notation "⌊" a "⌋₊" => Nat.floor a @[inherit_doc] notation "⌈" a "⌉₊" => Nat.ceil a end OrderedSemiring section LinearOrderedSemiring variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := FloorSemiring.gc_floor ha #align nat.le_floor_iff Nat.le_floor_iff theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ := (le_floor_iff <| n.cast_nonneg.trans h).2 h #align nat.le_floor Nat.le_floor theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff ha #align nat.floor_lt Nat.floor_lt theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 := (floor_lt ha).trans <| by rw [Nat.cast_one] #align nat.floor_lt_one Nat.floor_lt_one theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n := lt_of_not_le fun h' => (le_floor h').not_lt h #align nat.lt_of_floor_lt Nat.lt_of_floor_lt theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h #align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a := (le_floor_iff ha).1 le_rfl #align nat.floor_le Nat.floor_le theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ := lt_of_floor_lt <| Nat.lt_succ_self _ #align nat.lt_succ_floor Nat.lt_succ_floor theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a #align nat.lt_floor_add_one Nat.lt_floor_add_one @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n := eq_of_forall_le_iff fun a => by rw [le_floor_iff, Nat.cast_le] exact n.cast_nonneg #align nat.floor_coe Nat.floor_natCast @[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast] #align nat.floor_zero Nat.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast] #align nat.floor_one Nat.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n := Nat.floor_natCast _ theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 := ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by rintro rfl exact floor_zero #align nat.floor_of_nonpos Nat.floor_of_nonpos theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact le_floor ((floor_le ha).trans h) #align nat.floor_mono Nat.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact iff_of_false (Nat.pos_of_ne_zero hn).not_le (not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn) · exact le_floor_iff ha #align nat.le_floor_iff' Nat.le_floor_iff' @[simp] theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x := mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero #align nat.one_le_floor_iff Nat.one_le_floor_iff theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff' hn #align nat.floor_lt' Nat.floor_lt' theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero` rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one] #align nat.floor_pos Nat.floor_pos theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a := (le_or_lt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h #align nat.pos_of_floor_pos Nat.pos_of_floor_pos theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a := (Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le #align nat.lt_of_lt_floor Nat.lt_of_lt_floor theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n := le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h #align nat.floor_le_of_le Nat.floor_le_of_le theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 := floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm #align nat.floor_le_one_of_le_one Nat.floor_le_one_of_le_one @[simp] theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by rw [← lt_one_iff, ← @cast_one α] exact floor_lt' Nat.one_ne_zero #align nat.floor_eq_zero Nat.floor_eq_zero theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff Nat.floor_eq_iff theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff' Nat.floor_eq_iff' theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ => (floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩ #align nat.floor_eq_on_Ico Nat.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), (⌊a⌋₊ : α) = n := fun x hx => mod_cast floor_eq_on_Ico n x hx #align nat.floor_eq_on_Ico' Nat.floor_eq_on_Ico' @[simp] theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 := ext fun _ => floor_eq_zero #align nat.preimage_floor_zero Nat.preimage_floor_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(n:α)` theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (floor : α → ℕ) ⁻¹' {n} = Ico (n:α) (n + 1) := ext fun _ => floor_eq_iff' hn #align nat.preimage_floor_of_ne_zero Nat.preimage_floor_of_ne_zero /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) := FloorSemiring.gc_ceil #align nat.gc_ceil_coe Nat.gc_ceil_coe @[simp] theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n := gc_ceil_coe _ _ #align nat.ceil_le Nat.ceil_le theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align nat.lt_ceil Nat.lt_ceil -- porting note (#10618): simp can prove this -- @[simp] theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by rw [← Nat.lt_ceil, Nat.add_one_le_iff] #align nat.add_one_le_ceil_iff Nat.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero] #align nat.one_le_ceil_iff Nat.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by rw [ceil_le, Nat.cast_add, Nat.cast_one] exact (lt_floor_add_one a).le #align nat.ceil_le_floor_add_one Nat.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ := ceil_le.1 le_rfl #align nat.le_ceil Nat.le_ceil @[simp] theorem ceil_intCast {α : Type*} [LinearOrderedRing α] [FloorSemiring α] (z : ℤ) : ⌈(z : α)⌉₊ = z.toNat := eq_of_forall_ge_iff fun a => by simp only [ceil_le, Int.toNat_le] norm_cast #align nat.ceil_int_cast Nat.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le] #align nat.ceil_nat_cast Nat.ceil_natCast theorem ceil_mono : Monotone (ceil : α → ℕ) := gc_ceil_coe.monotone_l #align nat.ceil_mono Nat.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉₊ ≤ ⌈y⌉₊ := ceil_mono @[simp] theorem ceil_zero : ⌈(0 : α)⌉₊ = 0 := by rw [← Nat.cast_zero, ceil_natCast] #align nat.ceil_zero Nat.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [← Nat.cast_one, ceil_natCast] #align nat.ceil_one Nat.ceil_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈no_index (OfNat.ofNat n : α)⌉₊ = n := ceil_natCast n @[simp] theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero] #align nat.ceil_eq_zero Nat.ceil_eq_zero @[simp] theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align nat.ceil_pos Nat.ceil_pos theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n := (le_ceil a).trans_lt (Nat.cast_lt.2 h) #align nat.lt_of_ceil_lt Nat.lt_of_ceil_lt theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n := (le_ceil a).trans (Nat.cast_le.2 h) #align nat.le_of_ceil_le Nat.le_of_ceil_le theorem floor_le_ceil (a : α) : ⌊a⌋₊ ≤ ⌈a⌉₊ := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact cast_le.1 ((floor_le ha).trans <| le_ceil _) #align nat.floor_le_ceil Nat.floor_le_ceil theorem floor_lt_ceil_of_lt_of_pos {a b : α} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := by rcases le_or_lt 0 a with (ha | ha) · rw [floor_lt ha] exact h.trans_le (le_ceil _) · rwa [floor_of_nonpos ha.le, lt_ceil, Nat.cast_zero] #align nat.floor_lt_ceil_of_lt_of_pos Nat.floor_lt_ceil_of_lt_of_pos theorem ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by rw [← ceil_le, ← not_le, ← ceil_le, not_le, tsub_lt_iff_right (Nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.ceil_eq_iff Nat.ceil_eq_iff @[simp] theorem preimage_ceil_zero : (Nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 := ext fun _ => ceil_eq_zero #align nat.preimage_ceil_zero Nat.preimage_ceil_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(↑(n - 1))` theorem preimage_ceil_of_ne_zero (hn : n ≠ 0) : (Nat.ceil : α → ℕ) ⁻¹' {n} = Ioc (↑(n - 1) : α) n := ext fun _ => ceil_eq_iff hn #align nat.preimage_ceil_of_ne_zero Nat.preimage_ceil_of_ne_zero /-! #### Intervals -/ -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioo {a b : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by ext simp [floor_lt, lt_ceil, ha] #align nat.preimage_Ioo Nat.preimage_Ioo -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ico {a b : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉₊ ⌈b⌉₊ := by ext simp [ceil_le, lt_ceil] #align nat.preimage_Ico Nat.preimage_Ico -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioc {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by ext simp [floor_lt, le_floor_iff, hb, ha] #align nat.preimage_Ioc Nat.preimage_Ioc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Icc {a b : α} (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉₊ ⌊b⌋₊ := by ext simp [ceil_le, hb, le_floor_iff] #align nat.preimage_Icc Nat.preimage_Icc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioi {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋₊ := by ext simp [floor_lt, ha] #align nat.preimage_Ioi Nat.preimage_Ioi -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ici {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉₊ := by ext simp [ceil_le] #align nat.preimage_Ici Nat.preimage_Ici -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iio {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉₊ := by ext simp [lt_ceil] #align nat.preimage_Iio Nat.preimage_Iio -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iic {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋₊ := by ext simp [le_floor_iff, ha] #align nat.preimage_Iic Nat.preimage_Iic theorem floor_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n := eq_of_forall_le_iff fun b => by rw [le_floor_iff (add_nonneg ha n.cast_nonneg)] obtain hb | hb := le_total n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_le_add_iff_right, add_le_add_iff_right, le_floor_iff ha] · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_left_comm _ b, add_left_comm _ (b : α)] refine iff_of_true ?_ le_self_add exact le_add_of_nonneg_right <| ha.trans <| le_add_of_nonneg_right d.cast_nonneg #align nat.floor_add_nat Nat.floor_add_nat theorem floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by -- Porting note: broken `convert floor_add_nat ha 1` rw [← cast_one, floor_add_nat ha 1] #align nat.floor_add_one Nat.floor_add_one -- See note [no_index around OfNat.ofNat] theorem floor_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ + OfNat.ofNat n := floor_add_nat ha n @[simp] theorem floor_sub_nat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) : ⌊a - n⌋₊ = ⌊a⌋₊ - n := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub] rcases le_total a n with h | h · rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le] exact Nat.cast_le.1 ((Nat.floor_le ha).trans h) · rw [eq_tsub_iff_add_eq_of_le (le_floor h), ← floor_add_nat _, tsub_add_cancel_of_le h] exact le_tsub_of_add_le_left ((add_zero _).trans_le h) #align nat.floor_sub_nat Nat.floor_sub_nat @[simp] theorem floor_sub_one [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) : ⌊a - 1⌋₊ = ⌊a⌋₊ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ - OfNat.ofNat n := floor_sub_nat a n theorem ceil_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n := eq_of_forall_ge_iff fun b => by rw [← not_lt, ← not_lt, not_iff_not, lt_ceil] obtain hb | hb := le_or_lt n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_lt_add_iff_right, add_lt_add_iff_right, lt_ceil] · exact iff_of_true (lt_add_of_nonneg_of_lt ha <| cast_lt.2 hb) (Nat.lt_add_left _ hb) #align nat.ceil_add_nat Nat.ceil_add_nat theorem ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by -- Porting note: broken `convert ceil_add_nat ha 1` rw [cast_one.symm, ceil_add_nat ha 1] #align nat.ceil_add_one Nat.ceil_add_one -- See note [no_index around OfNat.ofNat] theorem ceil_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉₊ = ⌈a⌉₊ + OfNat.ofNat n := ceil_add_nat ha n theorem ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : α) < a + 1 := lt_ceil.1 <| (Nat.lt_succ_self _).trans_le (ceil_add_one ha).ge #align nat.ceil_lt_add_one Nat.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := by rw [ceil_le, Nat.cast_add] exact _root_.add_le_add (le_ceil _) (le_ceil _) #align nat.ceil_add_le Nat.ceil_add_le end LinearOrderedSemiring section LinearOrderedRing variable [LinearOrderedRing α] [FloorSemiring α] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋₊ := sub_lt_iff_lt_add.2 <| lt_floor_add_one a #align nat.sub_one_lt_floor Nat.sub_one_lt_floor end LinearOrderedRing section LinearOrderedSemifield variable [LinearOrderedSemifield α] [FloorSemiring α] -- TODO: should these lemmas be `simp`? `norm_cast`? theorem floor_div_nat (a : α) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := by rcases le_total a 0 with ha | ha · rw [floor_of_nonpos, floor_of_nonpos ha] · simp apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg obtain rfl | hn := n.eq_zero_or_pos · rw [cast_zero, div_zero, Nat.div_zero, floor_zero] refine (floor_eq_iff ?_).2 ?_ · exact div_nonneg ha n.cast_nonneg constructor · exact cast_div_le.trans (div_le_div_of_nonneg_right (floor_le ha) n.cast_nonneg) rw [div_lt_iff, add_mul, one_mul, ← cast_mul, ← cast_add, ← floor_lt ha] · exact lt_div_mul_add hn · exact cast_pos.2 hn #align nat.floor_div_nat Nat.floor_div_nat -- See note [no_index around OfNat.ofNat] theorem floor_div_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a / (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ / OfNat.ofNat n := floor_div_nat a n /-- Natural division is the floor of field division. -/ theorem floor_div_eq_div (m n : ℕ) : ⌊(m : α) / n⌋₊ = m / n := by convert floor_div_nat (m : α) n rw [m.floor_natCast] #align nat.floor_div_eq_div Nat.floor_div_eq_div end LinearOrderedSemifield end Nat /-- There exists at most one `FloorSemiring` structure on a linear ordered semiring. -/ theorem subsingleton_floorSemiring {α} [LinearOrderedSemiring α] : Subsingleton (FloorSemiring α) := by refine ⟨fun H₁ H₂ => ?_⟩ have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil.l_unique H₂.gc_ceil) fun n => rfl have : H₁.floor = H₂.floor := by ext a cases' lt_or_le a 0 with h h · rw [H₁.floor_of_neg, H₂.floor_of_neg] <;> exact h · refine eq_of_forall_le_iff fun n => ?_ rw [H₁.gc_floor, H₂.gc_floor] <;> exact h cases H₁ cases H₂ congr #align subsingleton_floor_semiring subsingleton_floorSemiring /-! ### Floor rings -/ /-- A `FloorRing` is a linear ordered ring over `α` with a function `floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`. -/ class FloorRing (α) [LinearOrderedRing α] where /-- `FloorRing.floor a` computes the greatest integer `z` such that `(z : α) ≤ a`. -/ floor : α → ℤ /-- `FloorRing.ceil a` computes the least integer `z` such that `a ≤ (z : α)`. -/ ceil : α → ℤ /-- `FloorRing.ceil` is the upper adjoint of the coercion `↑ : ℤ → α`. -/ gc_coe_floor : GaloisConnection (↑) floor /-- `FloorRing.ceil` is the lower adjoint of the coercion `↑ : ℤ → α`. -/ gc_ceil_coe : GaloisConnection ceil (↑) #align floor_ring FloorRing instance : FloorRing ℤ where floor := id ceil := id gc_coe_floor a b := by rw [Int.cast_id] rfl gc_ceil_coe a b := by rw [Int.cast_id] rfl /-- A `FloorRing` constructor from the `floor` function alone. -/ def FloorRing.ofFloor (α) [LinearOrderedRing α] (floor : α → ℤ) (gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α := { floor ceil := fun a => -floor (-a) gc_coe_floor gc_ceil_coe := fun a z => by rw [neg_le, ← gc_coe_floor, Int.cast_neg, neg_le_neg_iff] } #align floor_ring.of_floor FloorRing.ofFloor /-- A `FloorRing` constructor from the `ceil` function alone. -/ def FloorRing.ofCeil (α) [LinearOrderedRing α] (ceil : α → ℤ) (gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α := { floor := fun a => -ceil (-a) ceil gc_coe_floor := fun a z => by rw [le_neg, gc_ceil_coe, Int.cast_neg, neg_le_neg_iff] gc_ceil_coe } #align floor_ring.of_ceil FloorRing.ofCeil namespace Int variable [LinearOrderedRing α] [FloorRing α] {z : ℤ} {a : α} /-- `Int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/ def floor : α → ℤ := FloorRing.floor #align int.floor Int.floor /-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/ def ceil : α → ℤ := FloorRing.ceil #align int.ceil Int.ceil /-- `Int.fract a`, the fractional part of `a`, is `a` minus its floor. -/ def fract (a : α) : α := a - floor a #align int.fract Int.fract @[simp] theorem floor_int : (Int.floor : ℤ → ℤ) = id := rfl #align int.floor_int Int.floor_int @[simp] theorem ceil_int : (Int.ceil : ℤ → ℤ) = id := rfl #align int.ceil_int Int.ceil_int @[simp] theorem fract_int : (Int.fract : ℤ → ℤ) = 0 := funext fun x => by simp [fract] #align int.fract_int Int.fract_int @[inherit_doc] notation "⌊" a "⌋" => Int.floor a @[inherit_doc] notation "⌈" a "⌉" => Int.ceil a -- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there. @[simp] theorem floorRing_floor_eq : @FloorRing.floor = @Int.floor := rfl #align int.floor_ring_floor_eq Int.floorRing_floor_eq @[simp] theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil := rfl #align int.floor_ring_ceil_eq Int.floorRing_ceil_eq /-! #### Floor -/ theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor := FloorRing.gc_coe_floor #align int.gc_coe_floor Int.gc_coe_floor theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a := (gc_coe_floor z a).symm #align int.le_floor Int.le_floor theorem floor_lt : ⌊a⌋ < z ↔ a < z := lt_iff_lt_of_le_iff_le le_floor #align int.floor_lt Int.floor_lt theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a := gc_coe_floor.l_u_le a #align int.floor_le Int.floor_le theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero] #align int.floor_nonneg Int.floor_nonneg @[simp] theorem floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, le_sub_one_iff] #align int.floor_le_sub_one_iff Int.floor_le_sub_one_iff @[simp] theorem floor_le_neg_one_iff : ⌊a⌋ ≤ -1 ↔ a < 0 := by rw [← zero_sub (1 : ℤ), floor_le_sub_one_iff, cast_zero] #align int.floor_le_neg_one_iff Int.floor_le_neg_one_iff theorem floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by rw [← @cast_le α, Int.cast_zero] exact (floor_le a).trans ha #align int.floor_nonpos Int.floor_nonpos theorem lt_succ_floor (a : α) : a < ⌊a⌋.succ := floor_lt.1 <| Int.lt_succ_self _ #align int.lt_succ_floor Int.lt_succ_floor @[simp] theorem lt_floor_add_one (a : α) : a < ⌊a⌋ + 1 := by simpa only [Int.succ, Int.cast_add, Int.cast_one] using lt_succ_floor a #align int.lt_floor_add_one Int.lt_floor_add_one @[simp] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ := sub_lt_iff_lt_add.2 (lt_floor_add_one a) #align int.sub_one_lt_floor Int.sub_one_lt_floor @[simp] theorem floor_intCast (z : ℤ) : ⌊(z : α)⌋ = z := eq_of_forall_le_iff fun a => by rw [le_floor, Int.cast_le] #align int.floor_int_cast Int.floor_intCast @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋ = n := eq_of_forall_le_iff fun a => by rw [le_floor, ← cast_natCast, cast_le] #align int.floor_nat_cast Int.floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_intCast] #align int.floor_zero Int.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_intCast] #align int.floor_one Int.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊(no_index (OfNat.ofNat n : α))⌋ = n := floor_natCast n @[mono] theorem floor_mono : Monotone (floor : α → ℤ) := gc_coe_floor.monotone_u #align int.floor_mono Int.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋ ≤ ⌊y⌋ := floor_mono theorem floor_pos : 0 < ⌊a⌋ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor` rw [Int.lt_iff_add_one_le, zero_add, le_floor, cast_one] #align int.floor_pos Int.floor_pos @[simp] theorem floor_add_int (a : α) (z : ℤ) : ⌊a + z⌋ = ⌊a⌋ + z := eq_of_forall_le_iff fun a => by rw [le_floor, ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, Int.cast_sub] #align int.floor_add_int Int.floor_add_int @[simp] theorem floor_add_one (a : α) : ⌊a + 1⌋ = ⌊a⌋ + 1 := by -- Porting note: broken `convert floor_add_int a 1` rw [← cast_one, floor_add_int] #align int.floor_add_one Int.floor_add_one theorem le_floor_add (a b : α) : ⌊a⌋ + ⌊b⌋ ≤ ⌊a + b⌋ := by rw [le_floor, Int.cast_add] exact add_le_add (floor_le _) (floor_le _) #align int.le_floor_add Int.le_floor_add theorem le_floor_add_floor (a b : α) : ⌊a + b⌋ - 1 ≤ ⌊a⌋ + ⌊b⌋ := by rw [← sub_le_iff_le_add, le_floor, Int.cast_sub, sub_le_comm, Int.cast_sub, Int.cast_one] refine le_trans ?_ (sub_one_lt_floor _).le rw [sub_le_iff_le_add', ← add_sub_assoc, sub_le_sub_iff_right] exact floor_le _ #align int.le_floor_add_floor Int.le_floor_add_floor @[simp] theorem floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by simpa only [add_comm] using floor_add_int a z #align int.floor_int_add Int.floor_int_add @[simp] theorem floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by rw [← Int.cast_natCast, floor_add_int] #align int.floor_add_nat Int.floor_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ + OfNat.ofNat n := floor_add_nat a n @[simp] theorem floor_nat_add (n : ℕ) (a : α) : ⌊↑n + a⌋ = n + ⌊a⌋ := by rw [← Int.cast_natCast, floor_int_add] #align int.floor_nat_add Int.floor_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : ⌊(no_index (OfNat.ofNat n)) + a⌋ = OfNat.ofNat n + ⌊a⌋ := floor_nat_add n a @[simp] theorem floor_sub_int (a : α) (z : ℤ) : ⌊a - z⌋ = ⌊a⌋ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _) #align int.floor_sub_int Int.floor_sub_int @[simp] theorem floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by rw [← Int.cast_natCast, floor_sub_int] #align int.floor_sub_nat Int.floor_sub_nat @[simp] theorem floor_sub_one (a : α) : ⌊a - 1⌋ = ⌊a⌋ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ - OfNat.ofNat n := floor_sub_nat a n theorem abs_sub_lt_one_of_floor_eq_floor {α : Type*} [LinearOrderedCommRing α] [FloorRing α] {a b : α} (h : ⌊a⌋ = ⌊b⌋) : |a - b| < 1 := by have : a < ⌊a⌋ + 1 := lt_floor_add_one a have : b < ⌊b⌋ + 1 := lt_floor_add_one b have : (⌊a⌋ : α) = ⌊b⌋ := Int.cast_inj.2 h have : (⌊a⌋ : α) ≤ a := floor_le a have : (⌊b⌋ : α) ≤ b := floor_le b exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩ #align int.abs_sub_lt_one_of_floor_eq_floor Int.abs_sub_lt_one_of_floor_eq_floor theorem floor_eq_iff : ⌊a⌋ = z ↔ ↑z ≤ a ∧ a < z + 1 := by rw [le_antisymm_iff, le_floor, ← Int.lt_add_one_iff, floor_lt, Int.cast_add, Int.cast_one, and_comm] #align int.floor_eq_iff Int.floor_eq_iff @[simp] theorem floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff] #align int.floor_eq_zero_iff Int.floor_eq_zero_iff theorem floor_eq_on_Ico (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), ⌊a⌋ = n := fun _ ⟨h₀, h₁⟩ => floor_eq_iff.mpr ⟨h₀, h₁⟩ #align int.floor_eq_on_Ico Int.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), (⌊a⌋ : α) = n := fun a ha => congr_arg _ <| floor_eq_on_Ico n a ha #align int.floor_eq_on_Ico' Int.floor_eq_on_Ico' -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` @[simp] theorem preimage_floor_singleton (m : ℤ) : (floor : α → ℤ) ⁻¹' {m} = Ico (m : α) (m + 1) := ext fun _ => floor_eq_iff #align int.preimage_floor_singleton Int.preimage_floor_singleton /-! #### Fractional part -/ @[simp] theorem self_sub_floor (a : α) : a - ⌊a⌋ = fract a := rfl #align int.self_sub_floor Int.self_sub_floor @[simp] theorem floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a := add_sub_cancel _ _ #align int.floor_add_fract Int.floor_add_fract @[simp] theorem fract_add_floor (a : α) : fract a + ⌊a⌋ = a := sub_add_cancel _ _ #align int.fract_add_floor Int.fract_add_floor @[simp] theorem fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_int Int.fract_add_int @[simp] theorem fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_nat Int.fract_add_nat @[simp] theorem fract_add_one (a : α) : fract (a + 1) = fract a := mod_cast fract_add_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a + (no_index (OfNat.ofNat n))) = fract a := fract_add_nat a n @[simp] theorem fract_int_add (m : ℤ) (a : α) : fract (↑m + a) = fract a := by rw [add_comm, fract_add_int] #align int.fract_int_add Int.fract_int_add @[simp] theorem fract_nat_add (n : ℕ) (a : α) : fract (↑n + a) = fract a := by rw [add_comm, fract_add_nat] @[simp] theorem fract_one_add (a : α) : fract (1 + a) = fract a := mod_cast fract_nat_add 1 a -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : fract ((no_index (OfNat.ofNat n)) + a) = fract a := fract_nat_add n a @[simp] theorem fract_sub_int (a : α) (m : ℤ) : fract (a - m) = fract a := by rw [fract] simp #align int.fract_sub_int Int.fract_sub_int @[simp] theorem fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by rw [fract] simp #align int.fract_sub_nat Int.fract_sub_nat @[simp] theorem fract_sub_one (a : α) : fract (a - 1) = fract a := mod_cast fract_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a - (no_index (OfNat.ofNat n))) = fract a := fract_sub_nat a n -- Was a duplicate lemma under a bad name #align int.fract_int_nat Int.fract_int_add theorem fract_add_le (a b : α) : fract (a + b) ≤ fract a + fract b := by rw [fract, fract, fract, sub_add_sub_comm, sub_le_sub_iff_left, ← Int.cast_add, Int.cast_le] exact le_floor_add _ _ #align int.fract_add_le Int.fract_add_le theorem fract_add_fract_le (a b : α) : fract a + fract b ≤ fract (a + b) + 1 := by rw [fract, fract, fract, sub_add_sub_comm, sub_add, sub_le_sub_iff_left] exact mod_cast le_floor_add_floor a b #align int.fract_add_fract_le Int.fract_add_fract_le @[simp] theorem self_sub_fract (a : α) : a - fract a = ⌊a⌋ := sub_sub_cancel _ _ #align int.self_sub_fract Int.self_sub_fract @[simp] theorem fract_sub_self (a : α) : fract a - a = -⌊a⌋ := sub_sub_cancel_left _ _ #align int.fract_sub_self Int.fract_sub_self @[simp] theorem fract_nonneg (a : α) : 0 ≤ fract a := sub_nonneg.2 <| floor_le _ #align int.fract_nonneg Int.fract_nonneg /-- The fractional part of `a` is positive if and only if `a ≠ ⌊a⌋`. -/ lemma fract_pos : 0 < fract a ↔ a ≠ ⌊a⌋ := (fract_nonneg a).lt_iff_ne.trans <| ne_comm.trans sub_ne_zero #align int.fract_pos Int.fract_pos theorem fract_lt_one (a : α) : fract a < 1 := sub_lt_comm.1 <| sub_one_lt_floor _ #align int.fract_lt_one Int.fract_lt_one @[simp] theorem fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self] #align int.fract_zero Int.fract_zero @[simp] theorem fract_one : fract (1 : α) = 0 := by simp [fract] #align int.fract_one Int.fract_one theorem abs_fract : |fract a| = fract a := abs_eq_self.mpr <| fract_nonneg a #align int.abs_fract Int.abs_fract @[simp] theorem abs_one_sub_fract : |1 - fract a| = 1 - fract a := abs_eq_self.mpr <| sub_nonneg.mpr (fract_lt_one a).le #align int.abs_one_sub_fract Int.abs_one_sub_fract @[simp]
Mathlib/Algebra/Order/Floor.lean
1,005
1,008
theorem fract_intCast (z : ℤ) : fract (z : α) = 0 := by
unfold fract rw [floor_intCast] exact sub_self _
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FormalMultilinearSeries import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Logic.Equiv.Fin import Mathlib.Topology.Algebra.InfiniteSum.Module #align_import analysis.analytic.basic from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Analytic functions A function is analytic in one dimension around `0` if it can be written as a converging power series `Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not always possible in nonzero characteristic (in characteristic 2, the previous example has no symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition, and we only require the existence of a converging series. The general framework is important to say that the exponential map on bounded operators on a Banach space is analytic, as well as the inverse on invertible operators. ## Main definitions Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n` for `n : ℕ`. * `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially. * `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `‖p n‖ * r ^ n` is bounded above, then `r ≤ p.radius`; * `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.isLittleO_one_of_lt_radius`, `p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then `‖p n‖ * r ^ n` tends to zero exponentially; * `p.lt_radius_of_isBigO`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then `r < p.radius`; * `p.partialSum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`. * `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`. Additionally, let `f` be a function from `E` to `F`. * `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`, `f (x + y) = ∑'_n pₙ yⁿ`. * `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds `HasFPowerSeriesOnBall f p x r`. * `AnalyticAt 𝕜 f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`. * `AnalyticOn 𝕜 f s`: the function `f` is analytic at every point of `s`. We develop the basic properties of these notions, notably: * If a function admits a power series, it is continuous (see `HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and `AnalyticAt.continuousAt`). * In a complete space, the sum of a formal power series with positive radius is well defined on the disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`. * If a function admits a power series in a ball, then it is analytic at any point `y` of this ball, and the power series there can be expressed in terms of the initial power series `p` as `p.changeOrigin y`. See `HasFPowerSeriesOnBall.changeOrigin`. It follows in particular that the set of points at which a given function is analytic is open, see `isOpen_analyticAt`. ## Implementation details We only introduce the radius of convergence of a power series, as `p.radius`. For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent) notion, describing the polydisk of convergence. This notion is more specific, and not necessary to build the general theory. We do not define it here. -/ noncomputable section variable {𝕜 E F G : Type*} open scoped Classical open Topology NNReal Filter ENNReal open Set Filter Asymptotics namespace FormalMultilinearSeries variable [Ring 𝕜] [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] variable [TopologicalSpace E] [TopologicalSpace F] variable [TopologicalAddGroup E] [TopologicalAddGroup F] variable [ContinuousConstSMul 𝕜 E] [ContinuousConstSMul 𝕜 F] /-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A priori, it only behaves well when `‖x‖ < p.radius`. -/ protected def sum (p : FormalMultilinearSeries 𝕜 E F) (x : E) : F := ∑' n : ℕ, p n fun _ => x #align formal_multilinear_series.sum FormalMultilinearSeries.sum /-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum `Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/ def partialSum (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) (x : E) : F := ∑ k ∈ Finset.range n, p k fun _ : Fin k => x #align formal_multilinear_series.partial_sum FormalMultilinearSeries.partialSum /-- The partial sums of a formal multilinear series are continuous. -/ theorem partialSum_continuous (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : Continuous (p.partialSum n) := by unfold partialSum -- Porting note: added continuity #align formal_multilinear_series.partial_sum_continuous FormalMultilinearSeries.partialSum_continuous end FormalMultilinearSeries /-! ### The radius of a formal multilinear series -/ variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] namespace FormalMultilinearSeries variable (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} /-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ` converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these definitions are *not* equivalent in general. -/ def radius (p : FormalMultilinearSeries 𝕜 E F) : ℝ≥0∞ := ⨆ (r : ℝ≥0) (C : ℝ) (_ : ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C), (r : ℝ≥0∞) #align formal_multilinear_series.radius FormalMultilinearSeries.radius /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖ * (r : ℝ) ^ n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ℝ≥0∞)) h #align formal_multilinear_series.le_radius_of_bound FormalMultilinearSeries.le_radius_of_bound /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖₊ * r ^ n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := p.le_radius_of_bound C fun n => mod_cast h n #align formal_multilinear_series.le_radius_of_bound_nnreal FormalMultilinearSeries.le_radius_of_bound_nnreal /-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_isBigO (h : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : ↑r ≤ p.radius := Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC => p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n) set_option linter.uppercaseLean3 false in #align formal_multilinear_series.le_radius_of_is_O FormalMultilinearSeries.le_radius_of_isBigO theorem le_radius_of_eventually_le (C) (h : ∀ᶠ n in atTop, ‖p n‖ * (r : ℝ) ^ n ≤ C) : ↑r ≤ p.radius := p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa #align formal_multilinear_series.le_radius_of_eventually_le FormalMultilinearSeries.le_radius_of_eventually_le theorem le_radius_of_summable_nnnorm (h : Summable fun n => ‖p n‖₊ * r ^ n) : ↑r ≤ p.radius := p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) fun _ => le_tsum' h _ #align formal_multilinear_series.le_radius_of_summable_nnnorm FormalMultilinearSeries.le_radius_of_summable_nnnorm theorem le_radius_of_summable (h : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius := p.le_radius_of_summable_nnnorm <| by simp only [← coe_nnnorm] at h exact mod_cast h #align formal_multilinear_series.le_radius_of_summable FormalMultilinearSeries.le_radius_of_summable theorem radius_eq_top_of_forall_nnreal_isBigO (h : ∀ r : ℝ≥0, (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : p.radius = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_isBigO (h r) set_option linter.uppercaseLean3 false in #align formal_multilinear_series.radius_eq_top_of_forall_nnreal_is_O FormalMultilinearSeries.radius_eq_top_of_forall_nnreal_isBigO theorem radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in atTop, p n = 0) : p.radius = ∞ := p.radius_eq_top_of_forall_nnreal_isBigO fun r => (isBigO_zero _ _).congr' (h.mono fun n hn => by simp [hn]) EventuallyEq.rfl #align formal_multilinear_series.radius_eq_top_of_eventually_eq_zero FormalMultilinearSeries.radius_eq_top_of_eventually_eq_zero theorem radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) : p.radius = ∞ := p.radius_eq_top_of_eventually_eq_zero <| mem_atTop_sets.2 ⟨n, fun _ hk => tsub_add_cancel_of_le hk ▸ hn _⟩ #align formal_multilinear_series.radius_eq_top_of_forall_image_add_eq_zero FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero @[simp] theorem constFormalMultilinearSeries_radius {v : F} : (constFormalMultilinearSeries 𝕜 E v).radius = ⊤ := (constFormalMultilinearSeries 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1 (by simp [constFormalMultilinearSeries]) #align formal_multilinear_series.const_formal_multilinear_series_radius FormalMultilinearSeries.constFormalMultilinearSeries_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/ theorem isLittleO_of_lt_radius (h : ↑r < p.radius) : ∃ a ∈ Ioo (0 : ℝ) 1, (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (a ^ ·) := by have := (TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4 rw [this] -- Porting note: was -- rw [(TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4] simp only [radius, lt_iSup_iff] at h rcases h with ⟨t, C, hC, rt⟩ rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at rt have : 0 < (t : ℝ) := r.coe_nonneg.trans_lt rt rw [← div_lt_one this] at rt refine ⟨_, rt, C, Or.inr zero_lt_one, fun n => ?_⟩ calc |‖p n‖ * (r : ℝ) ^ n| = ‖p n‖ * (t : ℝ) ^ n * (r / t : ℝ) ^ n := by field_simp [mul_right_comm, abs_mul] _ ≤ C * (r / t : ℝ) ^ n := by gcongr; apply hC #align formal_multilinear_series.is_o_of_lt_radius FormalMultilinearSeries.isLittleO_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/ theorem isLittleO_one_of_lt_radius (h : ↑r < p.radius) : (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (fun _ => 1 : ℕ → ℝ) := let ⟨_, ha, hp⟩ := p.isLittleO_of_lt_radius h hp.trans <| (isLittleO_pow_pow_of_lt_left ha.1.le ha.2).congr (fun _ => rfl) one_pow #align formal_multilinear_series.is_o_one_of_lt_radius FormalMultilinearSeries.isLittleO_one_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/ theorem norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C * a ^ n := by -- Porting note: moved out of `rcases` have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 5).mp (p.isLittleO_of_lt_radius h) rcases this with ⟨a, ha, C, hC, H⟩ exact ⟨a, ha, C, hC, fun n => (le_abs_self _).trans (H n)⟩ #align formal_multilinear_series.norm_mul_pow_le_mul_pow_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_mul_pow_of_lt_radius /-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/ theorem lt_radius_of_isBigO (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1) (hp : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] (a ^ ·)) : ↑r < p.radius := by -- Porting note: moved out of `rcases` have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 2 5) rcases this.mp ⟨a, ha, hp⟩ with ⟨a, ha, C, hC, hp⟩ rw [← pos_iff_ne_zero, ← NNReal.coe_pos] at h₀ lift a to ℝ≥0 using ha.1.le have : (r : ℝ) < r / a := by simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2 norm_cast at this rw [← ENNReal.coe_lt_coe] at this refine this.trans_le (p.le_radius_of_bound C fun n => ?_) rw [NNReal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)] exact (le_abs_self _).trans (hp n) set_option linter.uppercaseLean3 false in #align formal_multilinear_series.lt_radius_of_is_O FormalMultilinearSeries.lt_radius_of_isBigO /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem norm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C := let ⟨_, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h ⟨C, hC, fun n => (h n).trans <| mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩ #align formal_multilinear_series.norm_mul_pow_le_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem norm_le_div_pow_of_pos_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / (r : ℝ) ^ n := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h ⟨C, hC, fun n => Iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩ #align formal_multilinear_series.norm_le_div_pow_of_pos_of_lt_radius FormalMultilinearSeries.norm_le_div_pow_of_pos_of_lt_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem nnnorm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r ^ n ≤ C := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h ⟨⟨C, hC.lt.le⟩, hC, mod_cast hp⟩ #align formal_multilinear_series.nnnorm_mul_pow_le_of_lt_radius FormalMultilinearSeries.nnnorm_mul_pow_le_of_lt_radius theorem le_radius_of_tendsto (p : FormalMultilinearSeries 𝕜 E F) {l : ℝ} (h : Tendsto (fun n => ‖p n‖ * (r : ℝ) ^ n) atTop (𝓝 l)) : ↑r ≤ p.radius := p.le_radius_of_isBigO (h.isBigO_one _) #align formal_multilinear_series.le_radius_of_tendsto FormalMultilinearSeries.le_radius_of_tendsto theorem le_radius_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F) (hs : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius := p.le_radius_of_tendsto hs.tendsto_atTop_zero #align formal_multilinear_series.le_radius_of_summable_norm FormalMultilinearSeries.le_radius_of_summable_norm theorem not_summable_norm_of_radius_lt_nnnorm (p : FormalMultilinearSeries 𝕜 E F) {x : E} (h : p.radius < ‖x‖₊) : ¬Summable fun n => ‖p n‖ * ‖x‖ ^ n := fun hs => not_le_of_lt h (p.le_radius_of_summable_norm hs) #align formal_multilinear_series.not_summable_norm_of_radius_lt_nnnorm FormalMultilinearSeries.not_summable_norm_of_radius_lt_nnnorm theorem summable_norm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : Summable fun n : ℕ => ‖p n‖ * (r : ℝ) ^ n := by obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h exact .of_nonneg_of_le (fun n => mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _)) hp ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) #align formal_multilinear_series.summable_norm_mul_pow FormalMultilinearSeries.summable_norm_mul_pow theorem summable_norm_apply (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => ‖p n fun _ => x‖ := by rw [mem_emetric_ball_zero_iff] at hx refine .of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ ((p n).le_opNorm _).trans_eq ?_) (p.summable_norm_mul_pow hx) simp #align formal_multilinear_series.summable_norm_apply FormalMultilinearSeries.summable_norm_apply theorem summable_nnnorm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : Summable fun n : ℕ => ‖p n‖₊ * r ^ n := by rw [← NNReal.summable_coe] push_cast exact p.summable_norm_mul_pow h #align formal_multilinear_series.summable_nnnorm_mul_pow FormalMultilinearSeries.summable_nnnorm_mul_pow protected theorem summable [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => p n fun _ => x := (p.summable_norm_apply hx).of_norm #align formal_multilinear_series.summable FormalMultilinearSeries.summable theorem radius_eq_top_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F) (hs : ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : p.radius = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_summable_norm (hs r) #align formal_multilinear_series.radius_eq_top_of_summable_norm FormalMultilinearSeries.radius_eq_top_of_summable_norm theorem radius_eq_top_iff_summable_norm (p : FormalMultilinearSeries 𝕜 E F) : p.radius = ∞ ↔ ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n := by constructor · intro h r obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius (show (r : ℝ≥0∞) < p.radius from h.symm ▸ ENNReal.coe_lt_top) refine .of_norm_bounded (fun n ↦ (C : ℝ) * a ^ n) ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) fun n ↦ ?_ specialize hp n rwa [Real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n))] · exact p.radius_eq_top_of_summable_norm #align formal_multilinear_series.radius_eq_top_iff_summable_norm FormalMultilinearSeries.radius_eq_top_iff_summable_norm /-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/ theorem le_mul_pow_of_radius_pos (p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) : ∃ (C r : _) (hC : 0 < C) (_ : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n := by rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩ have rpos : 0 < (r : ℝ) := by simp [ENNReal.coe_pos.1 r0] rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩ refine ⟨C, r⁻¹, Cpos, by simp only [inv_pos, rpos], fun n => ?_⟩ -- Porting note: was `convert` rw [inv_pow, ← div_eq_mul_inv] exact hCp n #align formal_multilinear_series.le_mul_pow_of_radius_pos FormalMultilinearSeries.le_mul_pow_of_radius_pos /-- The radius of the sum of two formal series is at least the minimum of their two radii. -/ theorem min_radius_le_radius_add (p q : FormalMultilinearSeries 𝕜 E F) : min p.radius q.radius ≤ (p + q).radius := by refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_ rw [lt_min_iff] at hr have := ((p.isLittleO_one_of_lt_radius hr.1).add (q.isLittleO_one_of_lt_radius hr.2)).isBigO refine (p + q).le_radius_of_isBigO ((isBigO_of_le _ fun n => ?_).trans this) rw [← add_mul, norm_mul, norm_mul, norm_norm] exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _) #align formal_multilinear_series.min_radius_le_radius_add FormalMultilinearSeries.min_radius_le_radius_add @[simp] theorem radius_neg (p : FormalMultilinearSeries 𝕜 E F) : (-p).radius = p.radius := by simp only [radius, neg_apply, norm_neg] #align formal_multilinear_series.radius_neg FormalMultilinearSeries.radius_neg protected theorem hasSum [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : HasSum (fun n : ℕ => p n fun _ => x) (p.sum x) := (p.summable hx).hasSum #align formal_multilinear_series.has_sum FormalMultilinearSeries.hasSum theorem radius_le_radius_continuousLinearMap_comp (p : FormalMultilinearSeries 𝕜 E F) (f : F →L[𝕜] G) : p.radius ≤ (f.compFormalMultilinearSeries p).radius := by refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_ apply le_radius_of_isBigO apply (IsBigO.trans_isLittleO _ (p.isLittleO_one_of_lt_radius hr)).isBigO refine IsBigO.mul (@IsBigOWith.isBigO _ _ _ _ _ ‖f‖ _ _ _ ?_) (isBigO_refl _ _) refine IsBigOWith.of_bound (eventually_of_forall fun n => ?_) simpa only [norm_norm] using f.norm_compContinuousMultilinearMap_le (p n) #align formal_multilinear_series.radius_le_radius_continuous_linear_map_comp FormalMultilinearSeries.radius_le_radius_continuousLinearMap_comp end FormalMultilinearSeries /-! ### Expanding a function as a power series -/ section variable {f g : E → F} {p pf pg : FormalMultilinearSeries 𝕜 E F} {x : E} {r r' : ℝ≥0∞} /-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `‖y‖ < r`. -/ structure HasFPowerSeriesOnBall (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) (r : ℝ≥0∞) : Prop where r_le : r ≤ p.radius r_pos : 0 < r hasSum : ∀ {y}, y ∈ EMetric.ball (0 : E) r → HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) #align has_fpower_series_on_ball HasFPowerSeriesOnBall /-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/ def HasFPowerSeriesAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) := ∃ r, HasFPowerSeriesOnBall f p x r #align has_fpower_series_at HasFPowerSeriesAt variable (𝕜) /-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power series expansion around `x`. -/ def AnalyticAt (f : E → F) (x : E) := ∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesAt f p x #align analytic_at AnalyticAt /-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around every point of `s`. -/ def AnalyticOn (f : E → F) (s : Set E) := ∀ x, x ∈ s → AnalyticAt 𝕜 f x #align analytic_on AnalyticOn variable {𝕜} theorem HasFPowerSeriesOnBall.hasFPowerSeriesAt (hf : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesAt f p x := ⟨r, hf⟩ #align has_fpower_series_on_ball.has_fpower_series_at HasFPowerSeriesOnBall.hasFPowerSeriesAt theorem HasFPowerSeriesAt.analyticAt (hf : HasFPowerSeriesAt f p x) : AnalyticAt 𝕜 f x := ⟨p, hf⟩ #align has_fpower_series_at.analytic_at HasFPowerSeriesAt.analyticAt theorem HasFPowerSeriesOnBall.analyticAt (hf : HasFPowerSeriesOnBall f p x r) : AnalyticAt 𝕜 f x := hf.hasFPowerSeriesAt.analyticAt #align has_fpower_series_on_ball.analytic_at HasFPowerSeriesOnBall.analyticAt theorem HasFPowerSeriesOnBall.congr (hf : HasFPowerSeriesOnBall f p x r) (hg : EqOn f g (EMetric.ball x r)) : HasFPowerSeriesOnBall g p x r := { r_le := hf.r_le r_pos := hf.r_pos hasSum := fun {y} hy => by convert hf.hasSum hy using 1 apply hg.symm simpa [edist_eq_coe_nnnorm_sub] using hy } #align has_fpower_series_on_ball.congr HasFPowerSeriesOnBall.congr /-- If a function `f` has a power series `p` around `x`, then the function `z ↦ f (z - y)` has the same power series around `x + y`. -/ theorem HasFPowerSeriesOnBall.comp_sub (hf : HasFPowerSeriesOnBall f p x r) (y : E) : HasFPowerSeriesOnBall (fun z => f (z - y)) p (x + y) r := { r_le := hf.r_le r_pos := hf.r_pos hasSum := fun {z} hz => by convert hf.hasSum hz using 2 abel } #align has_fpower_series_on_ball.comp_sub HasFPowerSeriesOnBall.comp_sub theorem HasFPowerSeriesOnBall.hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) {y : E} (hy : y ∈ EMetric.ball x r) : HasSum (fun n : ℕ => p n fun _ => y - x) (f y) := by have : y - x ∈ EMetric.ball (0 : E) r := by simpa [edist_eq_coe_nnnorm_sub] using hy simpa only [add_sub_cancel] using hf.hasSum this #align has_fpower_series_on_ball.has_sum_sub HasFPowerSeriesOnBall.hasSum_sub theorem HasFPowerSeriesOnBall.radius_pos (hf : HasFPowerSeriesOnBall f p x r) : 0 < p.radius := lt_of_lt_of_le hf.r_pos hf.r_le #align has_fpower_series_on_ball.radius_pos HasFPowerSeriesOnBall.radius_pos theorem HasFPowerSeriesAt.radius_pos (hf : HasFPowerSeriesAt f p x) : 0 < p.radius := let ⟨_, hr⟩ := hf hr.radius_pos #align has_fpower_series_at.radius_pos HasFPowerSeriesAt.radius_pos theorem HasFPowerSeriesOnBall.mono (hf : HasFPowerSeriesOnBall f p x r) (r'_pos : 0 < r') (hr : r' ≤ r) : HasFPowerSeriesOnBall f p x r' := ⟨le_trans hr hf.1, r'_pos, fun hy => hf.hasSum (EMetric.ball_subset_ball hr hy)⟩ #align has_fpower_series_on_ball.mono HasFPowerSeriesOnBall.mono theorem HasFPowerSeriesAt.congr (hf : HasFPowerSeriesAt f p x) (hg : f =ᶠ[𝓝 x] g) : HasFPowerSeriesAt g p x := by rcases hf with ⟨r₁, h₁⟩ rcases EMetric.mem_nhds_iff.mp hg with ⟨r₂, h₂pos, h₂⟩ exact ⟨min r₁ r₂, (h₁.mono (lt_min h₁.r_pos h₂pos) inf_le_left).congr fun y hy => h₂ (EMetric.ball_subset_ball inf_le_right hy)⟩ #align has_fpower_series_at.congr HasFPowerSeriesAt.congr protected theorem HasFPowerSeriesAt.eventually (hf : HasFPowerSeriesAt f p x) : ∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, HasFPowerSeriesOnBall f p x r := let ⟨_, hr⟩ := hf mem_of_superset (Ioo_mem_nhdsWithin_Ioi (left_mem_Ico.2 hr.r_pos)) fun _ hr' => hr.mono hr'.1 hr'.2.le #align has_fpower_series_at.eventually HasFPowerSeriesAt.eventually theorem HasFPowerSeriesOnBall.eventually_hasSum (hf : HasFPowerSeriesOnBall f p x r) : ∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) := by filter_upwards [EMetric.ball_mem_nhds (0 : E) hf.r_pos] using fun _ => hf.hasSum #align has_fpower_series_on_ball.eventually_has_sum HasFPowerSeriesOnBall.eventually_hasSum theorem HasFPowerSeriesAt.eventually_hasSum (hf : HasFPowerSeriesAt f p x) : ∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) := let ⟨_, hr⟩ := hf hr.eventually_hasSum #align has_fpower_series_at.eventually_has_sum HasFPowerSeriesAt.eventually_hasSum theorem HasFPowerSeriesOnBall.eventually_hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) : ∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) := by filter_upwards [EMetric.ball_mem_nhds x hf.r_pos] with y using hf.hasSum_sub #align has_fpower_series_on_ball.eventually_has_sum_sub HasFPowerSeriesOnBall.eventually_hasSum_sub theorem HasFPowerSeriesAt.eventually_hasSum_sub (hf : HasFPowerSeriesAt f p x) : ∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) := let ⟨_, hr⟩ := hf hr.eventually_hasSum_sub #align has_fpower_series_at.eventually_has_sum_sub HasFPowerSeriesAt.eventually_hasSum_sub theorem HasFPowerSeriesOnBall.eventually_eq_zero (hf : HasFPowerSeriesOnBall f (0 : FormalMultilinearSeries 𝕜 E F) x r) : ∀ᶠ z in 𝓝 x, f z = 0 := by filter_upwards [hf.eventually_hasSum_sub] with z hz using hz.unique hasSum_zero #align has_fpower_series_on_ball.eventually_eq_zero HasFPowerSeriesOnBall.eventually_eq_zero theorem HasFPowerSeriesAt.eventually_eq_zero (hf : HasFPowerSeriesAt f (0 : FormalMultilinearSeries 𝕜 E F) x) : ∀ᶠ z in 𝓝 x, f z = 0 := let ⟨_, hr⟩ := hf hr.eventually_eq_zero #align has_fpower_series_at.eventually_eq_zero HasFPowerSeriesAt.eventually_eq_zero theorem hasFPowerSeriesOnBall_const {c : F} {e : E} : HasFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e ⊤ := by refine ⟨by simp, WithTop.zero_lt_top, fun _ => hasSum_single 0 fun n hn => ?_⟩ simp [constFormalMultilinearSeries_apply hn] #align has_fpower_series_on_ball_const hasFPowerSeriesOnBall_const theorem hasFPowerSeriesAt_const {c : F} {e : E} : HasFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e := ⟨⊤, hasFPowerSeriesOnBall_const⟩ #align has_fpower_series_at_const hasFPowerSeriesAt_const theorem analyticAt_const {v : F} : AnalyticAt 𝕜 (fun _ => v) x := ⟨constFormalMultilinearSeries 𝕜 E v, hasFPowerSeriesAt_const⟩ #align analytic_at_const analyticAt_const theorem analyticOn_const {v : F} {s : Set E} : AnalyticOn 𝕜 (fun _ => v) s := fun _ _ => analyticAt_const #align analytic_on_const analyticOn_const theorem HasFPowerSeriesOnBall.add (hf : HasFPowerSeriesOnBall f pf x r) (hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f + g) (pf + pg) x r := { r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg) r_pos := hf.r_pos hasSum := fun hy => (hf.hasSum hy).add (hg.hasSum hy) } #align has_fpower_series_on_ball.add HasFPowerSeriesOnBall.add theorem HasFPowerSeriesAt.add (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) : HasFPowerSeriesAt (f + g) (pf + pg) x := by rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩ exact ⟨r, hr.1.add hr.2⟩ #align has_fpower_series_at.add HasFPowerSeriesAt.add theorem AnalyticAt.congr (hf : AnalyticAt 𝕜 f x) (hg : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 g x := let ⟨_, hpf⟩ := hf (hpf.congr hg).analyticAt theorem analyticAt_congr (h : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 f x ↔ AnalyticAt 𝕜 g x := ⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩ theorem AnalyticAt.add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f + g) x := let ⟨_, hpf⟩ := hf let ⟨_, hqf⟩ := hg (hpf.add hqf).analyticAt #align analytic_at.add AnalyticAt.add theorem HasFPowerSeriesOnBall.neg (hf : HasFPowerSeriesOnBall f pf x r) : HasFPowerSeriesOnBall (-f) (-pf) x r := { r_le := by rw [pf.radius_neg] exact hf.r_le r_pos := hf.r_pos hasSum := fun hy => (hf.hasSum hy).neg } #align has_fpower_series_on_ball.neg HasFPowerSeriesOnBall.neg theorem HasFPowerSeriesAt.neg (hf : HasFPowerSeriesAt f pf x) : HasFPowerSeriesAt (-f) (-pf) x := let ⟨_, hrf⟩ := hf hrf.neg.hasFPowerSeriesAt #align has_fpower_series_at.neg HasFPowerSeriesAt.neg theorem AnalyticAt.neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (-f) x := let ⟨_, hpf⟩ := hf hpf.neg.analyticAt #align analytic_at.neg AnalyticAt.neg theorem HasFPowerSeriesOnBall.sub (hf : HasFPowerSeriesOnBall f pf x r) (hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f - g) (pf - pg) x r := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_fpower_series_on_ball.sub HasFPowerSeriesOnBall.sub theorem HasFPowerSeriesAt.sub (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) : HasFPowerSeriesAt (f - g) (pf - pg) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_fpower_series_at.sub HasFPowerSeriesAt.sub theorem AnalyticAt.sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f - g) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align analytic_at.sub AnalyticAt.sub theorem AnalyticOn.mono {s t : Set E} (hf : AnalyticOn 𝕜 f t) (hst : s ⊆ t) : AnalyticOn 𝕜 f s := fun z hz => hf z (hst hz) #align analytic_on.mono AnalyticOn.mono theorem AnalyticOn.congr' {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : f =ᶠ[𝓝ˢ s] g) : AnalyticOn 𝕜 g s := fun z hz => (hf z hz).congr (mem_nhdsSet_iff_forall.mp hg z hz) theorem analyticOn_congr' {s : Set E} (h : f =ᶠ[𝓝ˢ s] g) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s := ⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩ theorem AnalyticOn.congr {s : Set E} (hs : IsOpen s) (hf : AnalyticOn 𝕜 f s) (hg : s.EqOn f g) : AnalyticOn 𝕜 g s := hf.congr' <| mem_nhdsSet_iff_forall.mpr (fun _ hz => eventuallyEq_iff_exists_mem.mpr ⟨s, hs.mem_nhds hz, hg⟩) theorem analyticOn_congr {s : Set E} (hs : IsOpen s) (h : s.EqOn f g) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩ theorem AnalyticOn.add {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) : AnalyticOn 𝕜 (f + g) s := fun z hz => (hf z hz).add (hg z hz) #align analytic_on.add AnalyticOn.add theorem AnalyticOn.sub {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) : AnalyticOn 𝕜 (f - g) s := fun z hz => (hf z hz).sub (hg z hz) #align analytic_on.sub AnalyticOn.sub theorem HasFPowerSeriesOnBall.coeff_zero (hf : HasFPowerSeriesOnBall f pf x r) (v : Fin 0 → E) : pf 0 v = f x := by have v_eq : v = fun i => 0 := Subsingleton.elim _ _ have zero_mem : (0 : E) ∈ EMetric.ball (0 : E) r := by simp [hf.r_pos] have : ∀ i, i ≠ 0 → (pf i fun j => 0) = 0 := by intro i hi have : 0 < i := pos_iff_ne_zero.2 hi exact ContinuousMultilinearMap.map_coord_zero _ (⟨0, this⟩ : Fin i) rfl have A := (hf.hasSum zero_mem).unique (hasSum_single _ this) simpa [v_eq] using A.symm #align has_fpower_series_on_ball.coeff_zero HasFPowerSeriesOnBall.coeff_zero theorem HasFPowerSeriesAt.coeff_zero (hf : HasFPowerSeriesAt f pf x) (v : Fin 0 → E) : pf 0 v = f x := let ⟨_, hrf⟩ := hf hrf.coeff_zero v #align has_fpower_series_at.coeff_zero HasFPowerSeriesAt.coeff_zero /-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the power series `g ∘ p` on the same ball. -/ theorem ContinuousLinearMap.comp_hasFPowerSeriesOnBall (g : F →L[𝕜] G) (h : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesOnBall (g ∘ f) (g.compFormalMultilinearSeries p) x r := { r_le := h.r_le.trans (p.radius_le_radius_continuousLinearMap_comp _) r_pos := h.r_pos hasSum := fun hy => by simpa only [ContinuousLinearMap.compFormalMultilinearSeries_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, Function.comp_apply] using g.hasSum (h.hasSum hy) } #align continuous_linear_map.comp_has_fpower_series_on_ball ContinuousLinearMap.comp_hasFPowerSeriesOnBall /-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic on `s`. -/ theorem ContinuousLinearMap.comp_analyticOn {s : Set E} (g : F →L[𝕜] G) (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (g ∘ f) s := by rintro x hx rcases h x hx with ⟨p, r, hp⟩ exact ⟨g.compFormalMultilinearSeries p, r, g.comp_hasFPowerSeriesOnBall hp⟩ #align continuous_linear_map.comp_analytic_on ContinuousLinearMap.comp_analyticOn /-- If a function admits a power series expansion, then it is exponentially close to the partial sums of this power series on strict subdisks of the disk of convergence. This version provides an upper estimate that decreases both in `‖y‖` and `n`. See also `HasFPowerSeriesOnBall.uniform_geometric_approx` for a weaker version. -/ theorem HasFPowerSeriesOnBall.uniform_geometric_approx' {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := by obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n := p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le) refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), fun y hy n => ?_⟩ have yr' : ‖y‖ < r' := by rw [ball_zero_eq] at hy exact hy have hr'0 : 0 < (r' : ℝ) := (norm_nonneg _).trans_lt yr' have : y ∈ EMetric.ball (0 : E) r := by refine mem_emetric_ball_zero_iff.2 (lt_trans ?_ h) exact mod_cast yr' rw [norm_sub_rev, ← mul_div_right_comm] have ya : a * (‖y‖ / ↑r') ≤ a := mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg) suffices ‖p.partialSum n y - f (x + y)‖ ≤ C * (a * (‖y‖ / r')) ^ n / (1 - a * (‖y‖ / r')) by refine this.trans ?_ have : 0 < a := ha.1 gcongr apply_rules [sub_pos.2, ha.2] apply norm_sub_le_of_geometric_bound_of_hasSum (ya.trans_lt ha.2) _ (hf.hasSum this) intro n calc ‖(p n) fun _ : Fin n => y‖ _ ≤ ‖p n‖ * ∏ _i : Fin n, ‖y‖ := ContinuousMultilinearMap.le_opNorm _ _ _ = ‖p n‖ * (r' : ℝ) ^ n * (‖y‖ / r') ^ n := by field_simp [mul_right_comm] _ ≤ C * a ^ n * (‖y‖ / r') ^ n := by gcongr ?_ * _; apply hp _ ≤ C * (a * (‖y‖ / r')) ^ n := by rw [mul_pow, mul_assoc] #align has_fpower_series_on_ball.uniform_geometric_approx' HasFPowerSeriesOnBall.uniform_geometric_approx' /-- If a function admits a power series expansion, then it is exponentially close to the partial sums of this power series on strict subdisks of the disk of convergence. -/ theorem HasFPowerSeriesOnBall.uniform_geometric_approx {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := by obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := hf.uniform_geometric_approx' h refine ⟨a, ha, C, hC, fun y hy n => (hp y hy n).trans ?_⟩ have yr' : ‖y‖ < r' := by rwa [ball_zero_eq] at hy have := ha.1.le -- needed to discharge a side goal on the next line gcongr exact mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg) #align has_fpower_series_on_ball.uniform_geometric_approx HasFPowerSeriesOnBall.uniform_geometric_approx /-- Taylor formula for an analytic function, `IsBigO` version. -/ theorem HasFPowerSeriesAt.isBigO_sub_partialSum_pow (hf : HasFPowerSeriesAt f p x) (n : ℕ) : (fun y : E => f (x + y) - p.partialSum n y) =O[𝓝 0] fun y => ‖y‖ ^ n := by rcases hf with ⟨r, hf⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩ obtain ⟨a, -, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := hf.uniform_geometric_approx' h refine isBigO_iff.2 ⟨C * (a / r') ^ n, ?_⟩ replace r'0 : 0 < (r' : ℝ) := mod_cast r'0 filter_upwards [Metric.ball_mem_nhds (0 : E) r'0] with y hy simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n set_option linter.uppercaseLean3 false in #align has_fpower_series_at.is_O_sub_partial_sum_pow HasFPowerSeriesAt.isBigO_sub_partialSum_pow /-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by `C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. This lemma formulates this property using `IsBigO` and `Filter.principal` on `E × E`. -/ theorem HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal (hf : HasFPowerSeriesOnBall f p x r) (hr : r' < r) : (fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓟 (EMetric.ball (x, x) r')] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ := by lift r' to ℝ≥0 using ne_top_of_lt hr rcases (zero_le r').eq_or_lt with (rfl | hr'0) · simp only [isBigO_bot, EMetric.ball_zero, principal_empty, ENNReal.coe_zero] obtain ⟨a, ha, C, hC : 0 < C, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n : ℕ, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n := p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le) simp only [← le_div_iff (pow_pos (NNReal.coe_pos.2 hr'0) _)] at hp set L : E × E → ℝ := fun y => C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * (a / (1 - a) ^ 2 + 2 / (1 - a)) have hL : ∀ y ∈ EMetric.ball (x, x) r', ‖f y.1 - f y.2 - p 1 fun _ => y.1 - y.2‖ ≤ L y := by intro y hy' have hy : y ∈ EMetric.ball x r ×ˢ EMetric.ball x r := by rw [EMetric.ball_prod_same] exact EMetric.ball_subset_ball hr.le hy' set A : ℕ → F := fun n => (p n fun _ => y.1 - x) - p n fun _ => y.2 - x have hA : HasSum (fun n => A (n + 2)) (f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) := by convert (hasSum_nat_add_iff' 2).2 ((hf.hasSum_sub hy.1).sub (hf.hasSum_sub hy.2)) using 1 rw [Finset.sum_range_succ, Finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self, zero_add, ← Subsingleton.pi_single_eq (0 : Fin 1) (y.1 - x), Pi.single, ← Subsingleton.pi_single_eq (0 : Fin 1) (y.2 - x), Pi.single, ← (p 1).map_sub, ← Pi.single, Subsingleton.pi_single_eq, sub_sub_sub_cancel_right] rw [EMetric.mem_ball, edist_eq_coe_nnnorm_sub, ENNReal.coe_lt_coe] at hy' set B : ℕ → ℝ := fun n => C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * ((n + 2) * a ^ n) have hAB : ∀ n, ‖A (n + 2)‖ ≤ B n := fun n => calc ‖A (n + 2)‖ ≤ ‖p (n + 2)‖ * ↑(n + 2) * ‖y - (x, x)‖ ^ (n + 1) * ‖y.1 - y.2‖ := by -- Porting note: `pi_norm_const` was `pi_norm_const (_ : E)` simpa only [Fintype.card_fin, pi_norm_const, Prod.norm_def, Pi.sub_def, Prod.fst_sub, Prod.snd_sub, sub_sub_sub_cancel_right] using (p <| n + 2).norm_image_sub_le (fun _ => y.1 - x) fun _ => y.2 - x _ = ‖p (n + 2)‖ * ‖y - (x, x)‖ ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by rw [pow_succ ‖y - (x, x)‖] ring -- Porting note: the two `↑` in `↑r'` are new, without them, Lean fails to synthesize -- instances `HDiv ℝ ℝ≥0 ?m` or `HMul ℝ ℝ≥0 ?m` _ ≤ C * a ^ (n + 2) / ↑r' ^ (n + 2) * ↑r' ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by have : 0 < a := ha.1 gcongr · apply hp · apply hy'.le _ = B n := by field_simp [B, pow_succ] simp only [mul_assoc, mul_comm, mul_left_comm] have hBL : HasSum B (L y) := by apply HasSum.mul_left simp only [add_mul] have : ‖a‖ < 1 := by simp only [Real.norm_eq_abs, abs_of_pos ha.1, ha.2] rw [div_eq_mul_inv, div_eq_mul_inv] exact (hasSum_coe_mul_geometric_of_norm_lt_one this).add -- Porting note: was `convert`! ((hasSum_geometric_of_norm_lt_one this).mul_left 2) exact hA.norm_le_of_bounded hBL hAB suffices L =O[𝓟 (EMetric.ball (x, x) r')] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ by refine (IsBigO.of_bound 1 (eventually_principal.2 fun y hy => ?_)).trans this rw [one_mul] exact (hL y hy).trans (le_abs_self _) simp_rw [L, mul_right_comm _ (_ * _)] exact (isBigO_refl _ _).const_mul_left _ set_option linter.uppercaseLean3 false in #align has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal /-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by `C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. -/ theorem HasFPowerSeriesOnBall.image_sub_sub_deriv_le (hf : HasFPowerSeriesOnBall f p x r) (hr : r' < r) : ∃ C, ∀ᵉ (y ∈ EMetric.ball x r') (z ∈ EMetric.ball x r'), ‖f y - f z - p 1 fun _ => y - z‖ ≤ C * max ‖y - x‖ ‖z - x‖ * ‖y - z‖ := by simpa only [isBigO_principal, mul_assoc, norm_mul, norm_norm, Prod.forall, EMetric.mem_ball, Prod.edist_eq, max_lt_iff, and_imp, @forall_swap (_ < _) E] using hf.isBigO_image_sub_image_sub_deriv_principal hr #align has_fpower_series_on_ball.image_sub_sub_deriv_le HasFPowerSeriesOnBall.image_sub_sub_deriv_le /-- If `f` has formal power series `∑ n, pₙ` at `x`, then `f y - f z - p 1 (fun _ ↦ y - z) = O(‖(y, z) - (x, x)‖ * ‖y - z‖)` as `(y, z) → (x, x)`. In particular, `f` is strictly differentiable at `x`. -/ theorem HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub (hf : HasFPowerSeriesAt f p x) : (fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓝 (x, x)] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ := by rcases hf with ⟨r, hf⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩ refine (hf.isBigO_image_sub_image_sub_deriv_principal h).mono ?_ exact le_principal_iff.2 (EMetric.ball_mem_nhds _ r'0) set_option linter.uppercaseLean3 false in #align has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub /-- If a function admits a power series expansion at `x`, then it is the uniform limit of the partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)` is the uniform limit of `p.partialSum n y` there. -/ theorem HasFPowerSeriesOnBall.tendstoUniformlyOn {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : TendstoUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop (Metric.ball (0 : E) r') := by obtain ⟨a, ha, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := hf.uniform_geometric_approx h refine Metric.tendstoUniformlyOn_iff.2 fun ε εpos => ?_ have L : Tendsto (fun n => (C : ℝ) * a ^ n) atTop (𝓝 ((C : ℝ) * 0)) := tendsto_const_nhds.mul (tendsto_pow_atTop_nhds_zero_of_lt_one ha.1.le ha.2) rw [mul_zero] at L refine (L.eventually (gt_mem_nhds εpos)).mono fun n hn y hy => ?_ rw [dist_eq_norm] exact (hp y hy n).trans_lt hn #align has_fpower_series_on_ball.tendsto_uniformly_on HasFPowerSeriesOnBall.tendstoUniformlyOn /-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of the partial sums of this power series on the disk of convergence, i.e., `f (x + y)` is the locally uniform limit of `p.partialSum n y` there. -/ theorem HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn (hf : HasFPowerSeriesOnBall f p x r) : TendstoLocallyUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop (EMetric.ball (0 : E) r) := by intro u hu x hx rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩ have : EMetric.ball (0 : E) r' ∈ 𝓝 x := IsOpen.mem_nhds EMetric.isOpen_ball xr' refine ⟨EMetric.ball (0 : E) r', mem_nhdsWithin_of_mem_nhds this, ?_⟩ simpa [Metric.emetric_ball_nnreal] using hf.tendstoUniformlyOn hr' u hu #align has_fpower_series_on_ball.tendsto_locally_uniformly_on HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn /-- If a function admits a power series expansion at `x`, then it is the uniform limit of the partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y` is the uniform limit of `p.partialSum n (y - x)` there. -/ theorem HasFPowerSeriesOnBall.tendstoUniformlyOn' {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) : TendstoUniformlyOn (fun n y => p.partialSum n (y - x)) f atTop (Metric.ball (x : E) r') := by convert (hf.tendstoUniformlyOn h).comp fun y => y - x using 1 · simp [(· ∘ ·)] · ext z simp [dist_eq_norm] #align has_fpower_series_on_ball.tendsto_uniformly_on' HasFPowerSeriesOnBall.tendstoUniformlyOn' /-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of the partial sums of this power series on the disk of convergence, i.e., `f y` is the locally uniform limit of `p.partialSum n (y - x)` there. -/ theorem HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn' (hf : HasFPowerSeriesOnBall f p x r) : TendstoLocallyUniformlyOn (fun n y => p.partialSum n (y - x)) f atTop (EMetric.ball (x : E) r) := by have A : ContinuousOn (fun y : E => y - x) (EMetric.ball (x : E) r) := (continuous_id.sub continuous_const).continuousOn convert hf.tendstoLocallyUniformlyOn.comp (fun y : E => y - x) _ A using 1 · ext z simp · intro z simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] #align has_fpower_series_on_ball.tendsto_locally_uniformly_on' HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn' /-- If a function admits a power series expansion on a disk, then it is continuous there. -/ protected theorem HasFPowerSeriesOnBall.continuousOn (hf : HasFPowerSeriesOnBall f p x r) : ContinuousOn f (EMetric.ball x r) := hf.tendstoLocallyUniformlyOn'.continuousOn <| eventually_of_forall fun n => ((p.partialSum_continuous n).comp (continuous_id.sub continuous_const)).continuousOn #align has_fpower_series_on_ball.continuous_on HasFPowerSeriesOnBall.continuousOn protected theorem HasFPowerSeriesAt.continuousAt (hf : HasFPowerSeriesAt f p x) : ContinuousAt f x := let ⟨_, hr⟩ := hf hr.continuousOn.continuousAt (EMetric.ball_mem_nhds x hr.r_pos) #align has_fpower_series_at.continuous_at HasFPowerSeriesAt.continuousAt protected theorem AnalyticAt.continuousAt (hf : AnalyticAt 𝕜 f x) : ContinuousAt f x := let ⟨_, hp⟩ := hf hp.continuousAt #align analytic_at.continuous_at AnalyticAt.continuousAt protected theorem AnalyticOn.continuousOn {s : Set E} (hf : AnalyticOn 𝕜 f s) : ContinuousOn f s := fun x hx => (hf x hx).continuousAt.continuousWithinAt #align analytic_on.continuous_on AnalyticOn.continuousOn /-- Analytic everywhere implies continuous -/ theorem AnalyticOn.continuous {f : E → F} (fa : AnalyticOn 𝕜 f univ) : Continuous f := by rw [continuous_iff_continuousOn_univ]; exact fa.continuousOn /-- In a complete space, the sum of a converging power series `p` admits `p` as a power series. This is not totally obvious as we need to check the convergence of the series. -/ protected theorem FormalMultilinearSeries.hasFPowerSeriesOnBall [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) : HasFPowerSeriesOnBall p.sum p 0 p.radius := { r_le := le_rfl r_pos := h hasSum := fun hy => by rw [zero_add] exact p.hasSum hy } #align formal_multilinear_series.has_fpower_series_on_ball FormalMultilinearSeries.hasFPowerSeriesOnBall theorem HasFPowerSeriesOnBall.sum (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : y ∈ EMetric.ball (0 : E) r) : f (x + y) = p.sum y := (h.hasSum hy).tsum_eq.symm #align has_fpower_series_on_ball.sum HasFPowerSeriesOnBall.sum /-- The sum of a converging power series is continuous in its disk of convergence. -/ protected theorem FormalMultilinearSeries.continuousOn [CompleteSpace F] : ContinuousOn p.sum (EMetric.ball 0 p.radius) := by rcases (zero_le p.radius).eq_or_lt with h | h · simp [← h, continuousOn_empty] · exact (p.hasFPowerSeriesOnBall h).continuousOn #align formal_multilinear_series.continuous_on FormalMultilinearSeries.continuousOn end /-! ### Uniqueness of power series If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is, for any `n : ℕ` and `y : E`, `p₁ n (fun i ↦ y) = p₂ n (fun i ↦ y)`. In the one-dimensional case, when `f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by `ContinuousMultilinearMap.mkPiRing`, and hence are determined completely by the value of `p₁ n (fun i ↦ 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be transferred to the other. -/ section Uniqueness open ContinuousMultilinearMap
Mathlib/Analysis/Analytic/Basic.lean
949
998
theorem Asymptotics.IsBigO.continuousMultilinearMap_apply_eq_zero {n : ℕ} {p : E[×n]→L[𝕜] F} (h : (fun y => p fun _ => y) =O[𝓝 0] fun y => ‖y‖ ^ (n + 1)) (y : E) : (p fun _ => y) = 0 := by
obtain ⟨c, c_pos, hc⟩ := h.exists_pos obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (isBigOWith_iff.mp hc) obtain ⟨δ, δ_pos, δε⟩ := (Metric.isOpen_iff.mp t_open) 0 z_mem clear h hc z_mem cases' n with n · exact norm_eq_zero.mp (by -- Porting note: the symmetric difference of the `simpa only` sets: -- added `Nat.zero_eq, zero_add, pow_one` -- removed `zero_pow, Ne.def, Nat.one_ne_zero, not_false_iff` simpa only [Nat.zero_eq, fin0_apply_norm, norm_eq_zero, norm_zero, zero_add, pow_one, mul_zero, norm_le_zero_iff] using ht 0 (δε (Metric.mem_ball_self δ_pos))) · refine Or.elim (Classical.em (y = 0)) (fun hy => by simpa only [hy] using p.map_zero) fun hy => ?_ replace hy := norm_pos_iff.mpr hy refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add fun ε ε_pos => ?_) (norm_nonneg _)) have h₀ := _root_.mul_pos c_pos (pow_pos hy (n.succ + 1)) obtain ⟨k, k_pos, k_norm⟩ := NormedField.exists_norm_lt 𝕜 (lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀))) have h₁ : ‖k • y‖ < δ := by rw [norm_smul] exact inv_mul_cancel_right₀ hy.ne.symm δ ▸ mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_left _ _)) hy have h₂ := calc ‖p fun _ => k • y‖ ≤ c * ‖k • y‖ ^ (n.succ + 1) := by -- Porting note: now Lean wants `_root_.` simpa only [norm_pow, _root_.norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁)) --simpa only [norm_pow, norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁)) _ = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by -- Porting note: added `Nat.succ_eq_add_one` since otherwise `ring` does not conclude. simp only [norm_smul, mul_pow, Nat.succ_eq_add_one] -- Porting note: removed `rw [pow_succ]`, since it now becomes superfluous. ring have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε := inv_mul_cancel_right₀ h₀.ne.symm ε ▸ mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀ calc ‖p fun _ => y‖ = ‖k⁻¹ ^ n.succ‖ * ‖p fun _ => k • y‖ := by simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos), norm_smul, Finset.prod_const, Finset.card_fin] using congr_arg norm (p.map_smul_univ (fun _ : Fin n.succ => k⁻¹) fun _ : Fin n.succ => k • y) _ ≤ ‖k⁻¹ ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))) := by gcongr _ = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by rw [← mul_assoc] simp [norm_mul, mul_pow] _ ≤ 0 + ε := by rw [inv_mul_cancel (norm_pos_iff.mp k_pos)] simpa using h₃.le
/- 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.Geometry.Euclidean.Sphere.Basic import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.DeriveFintype #align_import geometry.euclidean.circumcenter from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Circumcenter and circumradius This file proves some lemmas on points equidistant from a set of points, and defines the circumradius and circumcenter of a simplex. There are also some definitions for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. ## Main definitions * `circumcenter` and `circumradius` are the circumcenter and circumradius of a simplex. ## References * https://en.wikipedia.org/wiki/Circumscribed_circle -/ noncomputable section open scoped Classical open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] open AffineSubspace /-- `p` is equidistant from two points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p1 p2 : P} (p3 : P) (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : dist p1 p3 = dist p2 p3 ↔ dist p1 (orthogonalProjection s p3) = dist p2 (orthogonalProjection s p3) := by rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, ← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp1, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp2] simp #align euclidean_geometry.dist_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_eq_iff_dist_orthogonalProjection_eq /-- `p` is equidistant from a set of points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_set_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (Set.Pairwise ps fun p1 p2 => dist p1 p = dist p2 p) ↔ Set.Pairwise ps fun p1 p2 => dist p1 (orthogonalProjection s p) = dist p2 (orthogonalProjection s p) := ⟨fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).1 (h hp1 hp2 hne), fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).2 (h hp1 hp2 hne)⟩ #align euclidean_geometry.dist_set_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_set_eq_iff_dist_orthogonalProjection_eq /-- There exists `r` such that `p` has distance `r` from all the points of a set of points in `s` if and only if there exists (possibly different) `r` such that its `orthogonalProjection` has that distance from all the points in that set. -/ theorem exists_dist_eq_iff_exists_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (∃ r, ∀ p1 ∈ ps, dist p1 p = r) ↔ ∃ r, ∀ p1 ∈ ps, dist p1 ↑(orthogonalProjection s p) = r := by have h := dist_set_eq_iff_dist_orthogonalProjection_eq hps p simp_rw [Set.pairwise_eq_iff_exists_eq] at h exact h #align euclidean_geometry.exists_dist_eq_iff_exists_dist_orthogonal_projection_eq EuclideanGeometry.exists_dist_eq_iff_exists_dist_orthogonalProjection_eq /-- The induction step for the existence and uniqueness of the circumcenter. Given a nonempty set of points in a nonempty affine subspace whose direction is complete, such that there is a unique (circumcenter, circumradius) pair for those points in that subspace, and a point `p` not in that subspace, there is a unique (circumcenter, circumradius) pair for the set with `p` added, in the span of the subspace with `p` added. -/ theorem existsUnique_dist_eq_of_insert {s : AffineSubspace ℝ P} [HasOrthogonalProjection s.direction] {ps : Set P} (hnps : ps.Nonempty) {p : P} (hps : ps ⊆ s) (hp : p ∉ s) (hu : ∃! cs : Sphere P, cs.center ∈ s ∧ ps ⊆ (cs : Set P)) : ∃! cs₂ : Sphere P, cs₂.center ∈ affineSpan ℝ (insert p (s : Set P)) ∧ insert p ps ⊆ (cs₂ : Set P) := by haveI : Nonempty s := Set.Nonempty.to_subtype (hnps.mono hps) rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩ simp only at hcc hcr hcccru let x := dist cc (orthogonalProjection s p) let y := dist p (orthogonalProjection s p) have hy0 : y ≠ 0 := dist_orthogonalProjection_ne_zero_of_not_mem hp let ycc₂ := (x * x + y * y - cr * cr) / (2 * y) let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonalProjection s p : V) +ᵥ cc let cr₂ := √(cr * cr + ycc₂ * ycc₂) use ⟨cc₂, cr₂⟩ simp (config := { zeta := false, proj := false }) only have hpo : p = (1 : ℝ) • (p -ᵥ orthogonalProjection s p : V) +ᵥ (orthogonalProjection s p : P) := by simp constructor · constructor · refine vadd_mem_of_mem_direction ?_ (mem_affineSpan ℝ (Set.mem_insert_of_mem _ hcc)) rw [direction_affineSpan] exact Submodule.smul_mem _ _ (vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (orthogonalProjection_mem _))) · intro p1 hp1 rw [Sphere.mem_coe, mem_sphere, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] cases' hp1 with hp1 hp1 · rw [hp1] rw [hpo, dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), ← dist_eq_norm_vsub V p, dist_comm _ cc] field_simp [ycc₂, hy0] ring · rw [dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp1), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc, Subtype.coe_mk, dist_of_mem_subset_mk_sphere hp1 hcr, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V, Real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel₀ _ hy0, abs_mul_abs_self] · rintro ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩ simp only at hcc₃ hcr₃ obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ : ∃ r : ℝ, ∃ p0 ∈ s, cc₃ = r • (p -ᵥ ↑((orthogonalProjection s) p)) +ᵥ p0 := by rwa [mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hcc₃ have hcr₃' : ∃ r, ∀ p1 ∈ ps, dist p1 cc₃ = r := ⟨cr₃, fun p1 hp1 => dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp1) hcr₃⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq hps cc₃, hcc₃'', orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃'] at hcr₃' cases' hcr₃' with cr₃' hcr₃' have hu := hcccru ⟨cc₃', cr₃'⟩ simp only at hu replace hu := hu ⟨hcc₃', hcr₃'⟩ -- Porting note: was -- cases' hu with hucc hucr -- substs hucc hucr cases' hu have hcr₃val : cr₃ = √(cr * cr + t₃ * y * (t₃ * y)) := by cases' hnps with p0 hp0 have h' : ↑(⟨cc, hcc₃'⟩ : s) = cc := rfl rw [← dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp0) hcr₃, hcc₃'', ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)), dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp0), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃', h', dist_of_mem_subset_mk_sphere hp0 hcr, dist_eq_norm_vsub V _ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V p, Real.norm_eq_abs, ← mul_assoc, mul_comm _ |t₃|, ← mul_assoc, abs_mul_abs_self] ring replace hcr₃ := dist_of_mem_subset_mk_sphere (Set.mem_insert _ _) hcr₃ rw [hpo, hcc₃'', hcr₃val, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc₃' _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), dist_comm, ← dist_eq_norm_vsub V p, Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃ change x * x + _ * (y * y) = _ at hcr₃ rw [show x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y) by ring, add_left_inj] at hcr₃ have ht₃ : t₃ = ycc₂ / y := by field_simp [ycc₂, ← hcr₃, hy0] subst ht₃ change cc₃ = cc₂ at hcc₃'' congr rw [hcr₃val] congr 2 field_simp [hy0] #align euclidean_geometry.exists_unique_dist_eq_of_insert EuclideanGeometry.existsUnique_dist_eq_of_insert /-- Given a finite nonempty affinely independent family of points, there is a unique (circumcenter, circumradius) pair for those points in the affine subspace they span. -/ theorem _root_.AffineIndependent.existsUnique_dist_eq {ι : Type*} [hne : Nonempty ι] [Finite ι] {p : ι → P} (ha : AffineIndependent ℝ p) : ∃! cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range p) ∧ Set.range p ⊆ (cs : Set P) := by cases nonempty_fintype ι induction' hn : Fintype.card ι with m hm generalizing ι · exfalso have h := Fintype.card_pos_iff.2 hne rw [hn] at h exact lt_irrefl 0 h · cases' m with m · rw [Fintype.card_eq_one_iff] at hn cases' hn with i hi haveI : Unique ι := ⟨⟨i⟩, hi⟩ use ⟨p i, 0⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] constructor · simp_rw [hi default, Set.singleton_subset_iff] exact ⟨⟨⟩, by simp only [Metric.sphere_zero, Set.mem_singleton_iff]⟩ · rintro ⟨cc, cr⟩ simp only rintro ⟨rfl, hdist⟩ simp? [Set.singleton_subset_iff] at hdist says simp only [Set.singleton_subset_iff, Metric.mem_sphere, dist_self] at hdist rw [hi default, hdist] · have i := hne.some let ι2 := { x // x ≠ i } have hc : Fintype.card ι2 = m + 1 := by rw [Fintype.card_of_subtype (Finset.univ.filter fun x => x ≠ i)] · rw [Finset.filter_not] -- Porting note: removed `simp_rw [eq_comm]` and used `filter_eq'` instead of `filter_eq` rw [Finset.filter_eq' _ i, if_pos (Finset.mem_univ _), Finset.card_sdiff (Finset.subset_univ _), Finset.card_singleton, Finset.card_univ, hn] simp · simp haveI : Nonempty ι2 := Fintype.card_pos_iff.1 (hc.symm ▸ Nat.zero_lt_succ _) have ha2 : AffineIndependent ℝ fun i2 : ι2 => p i2 := ha.subtype _ replace hm := hm ha2 _ hc have hr : Set.range p = insert (p i) (Set.range fun i2 : ι2 => p i2) := by change _ = insert _ (Set.range fun i2 : { x | x ≠ i } => p i2) rw [← Set.image_eq_range, ← Set.image_univ, ← Set.image_insert_eq] congr with j simp [Classical.em] rw [hr, ← affineSpan_insert_affineSpan] refine existsUnique_dist_eq_of_insert (Set.range_nonempty _) (subset_spanPoints ℝ _) ?_ hm convert ha.not_mem_affineSpan_diff i Set.univ change (Set.range fun i2 : { x | x ≠ i } => p i2) = _ rw [← Set.image_eq_range] congr with j simp #align affine_independent.exists_unique_dist_eq AffineIndependent.existsUnique_dist_eq end EuclideanGeometry namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The circumsphere of a simplex. -/ def circumsphere {n : ℕ} (s : Simplex ℝ P n) : Sphere P := s.independent.existsUnique_dist_eq.choose #align affine.simplex.circumsphere Affine.Simplex.circumsphere /-- The property satisfied by the circumsphere. -/ theorem circumsphere_unique_dist_eq {n : ℕ} (s : Simplex ℝ P n) : (s.circumsphere.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ s.circumsphere) ∧ ∀ cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ cs → cs = s.circumsphere := s.independent.existsUnique_dist_eq.choose_spec #align affine.simplex.circumsphere_unique_dist_eq Affine.Simplex.circumsphere_unique_dist_eq /-- The circumcenter of a simplex. -/ def circumcenter {n : ℕ} (s : Simplex ℝ P n) : P := s.circumsphere.center #align affine.simplex.circumcenter Affine.Simplex.circumcenter /-- The circumradius of a simplex. -/ def circumradius {n : ℕ} (s : Simplex ℝ P n) : ℝ := s.circumsphere.radius #align affine.simplex.circumradius Affine.Simplex.circumradius /-- The center of the circumsphere is the circumcenter. -/ @[simp] theorem circumsphere_center {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.center = s.circumcenter := rfl #align affine.simplex.circumsphere_center Affine.Simplex.circumsphere_center /-- The radius of the circumsphere is the circumradius. -/ @[simp] theorem circumsphere_radius {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.radius = s.circumradius := rfl #align affine.simplex.circumsphere_radius Affine.Simplex.circumsphere_radius /-- The circumcenter lies in the affine span. -/ theorem circumcenter_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter ∈ affineSpan ℝ (Set.range s.points) := s.circumsphere_unique_dist_eq.1.1 #align affine.simplex.circumcenter_mem_affine_span Affine.Simplex.circumcenter_mem_affineSpan /-- All points have distance from the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : dist (s.points i) s.circumcenter = s.circumradius := dist_of_mem_subset_sphere (Set.mem_range_self _) s.circumsphere_unique_dist_eq.1.2 #align affine.simplex.dist_circumcenter_eq_circumradius Affine.Simplex.dist_circumcenter_eq_circumradius /-- All points lie in the circumsphere. -/ theorem mem_circumsphere {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ∈ s.circumsphere := s.dist_circumcenter_eq_circumradius i #align affine.simplex.mem_circumsphere Affine.Simplex.mem_circumsphere /-- All points have distance to the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius' {n : ℕ} (s : Simplex ℝ P n) : ∀ i, dist s.circumcenter (s.points i) = s.circumradius := by intro i rw [dist_comm] exact dist_circumcenter_eq_circumradius _ _ #align affine.simplex.dist_circumcenter_eq_circumradius' Affine.Simplex.dist_circumcenter_eq_circumradius' /-- Given a point in the affine span from which all the points are equidistant, that point is the circumcenter. -/ theorem eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : p = s.circumcenter := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.1 #align affine.simplex.eq_circumcenter_of_dist_eq Affine.Simplex.eq_circumcenter_of_dist_eq /-- Given a point in the affine span from which all the points are equidistant, that distance is the circumradius. -/ theorem eq_circumradius_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : r = s.circumradius := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h exact h.2 #align affine.simplex.eq_circumradius_of_dist_eq Affine.Simplex.eq_circumradius_of_dist_eq /-- The circumradius is non-negative. -/ theorem circumradius_nonneg {n : ℕ} (s : Simplex ℝ P n) : 0 ≤ s.circumradius := s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg #align affine.simplex.circumradius_nonneg Affine.Simplex.circumradius_nonneg /-- The circumradius of a simplex with at least two points is positive. -/ theorem circumradius_pos {n : ℕ} (s : Simplex ℝ P (n + 1)) : 0 < s.circumradius := by refine lt_of_le_of_ne s.circumradius_nonneg ?_ intro h have hr := s.dist_circumcenter_eq_circumradius simp_rw [← h, dist_eq_zero] at hr have h01 := s.independent.injective.ne (by simp : (0 : Fin (n + 2)) ≠ 1) simp [hr] at h01 #align affine.simplex.circumradius_pos Affine.Simplex.circumradius_pos /-- The circumcenter of a 0-simplex equals its unique point. -/ theorem circumcenter_eq_point (s : Simplex ℝ P 0) (i : Fin 1) : s.circumcenter = s.points i := by have h := s.circumcenter_mem_affineSpan have : Unique (Fin 1) := ⟨⟨0, by decide⟩, fun a => by simp only [Fin.eq_zero]⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] at h rw [h] congr simp only [eq_iff_true_of_subsingleton] #align affine.simplex.circumcenter_eq_point Affine.Simplex.circumcenter_eq_point /-- The circumcenter of a 1-simplex equals its centroid. -/ theorem circumcenter_eq_centroid (s : Simplex ℝ P 1) : s.circumcenter = Finset.univ.centroid ℝ s.points := by have hr : Set.Pairwise Set.univ fun i j : Fin 2 => dist (s.points i) (Finset.univ.centroid ℝ s.points) = dist (s.points j) (Finset.univ.centroid ℝ s.points) := by intro i hi j hj hij rw [Finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i), dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ← one_smul ℝ (s.points i -ᵥ s.points 0), ← one_smul ℝ (s.points j -ᵥ s.points 0)] fin_cases i <;> fin_cases j <;> simp [-one_smul, ← sub_smul] <;> norm_num rw [Set.pairwise_eq_iff_exists_eq] at hr cases' hr with r hr exact (s.eq_circumcenter_of_dist_eq (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (Finset.card_fin 2)) fun i => hr i (Set.mem_univ _)).symm #align affine.simplex.circumcenter_eq_centroid Affine.Simplex.circumcenter_eq_centroid /-- Reindexing a simplex along an `Equiv` of index types does not change the circumsphere. -/ @[simp] theorem circumsphere_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumsphere = s.circumsphere := by refine s.circumsphere_unique_dist_eq.2 _ ⟨?_, ?_⟩ <;> rw [← s.reindex_range_points e] · exact (s.reindex e).circumsphere_unique_dist_eq.1.1 · exact (s.reindex e).circumsphere_unique_dist_eq.1.2 #align affine.simplex.circumsphere_reindex Affine.Simplex.circumsphere_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumcenter. -/ @[simp] theorem circumcenter_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumcenter = s.circumcenter := by simp_rw [circumcenter, circumsphere_reindex] #align affine.simplex.circumcenter_reindex Affine.Simplex.circumcenter_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumradius. -/ @[simp] theorem circumradius_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumradius = s.circumradius := by simp_rw [circumradius, circumsphere_reindex] #align affine.simplex.circumradius_reindex Affine.Simplex.circumradius_reindex attribute [local instance] AffineSubspace.toAddTorsor /-- The orthogonal projection of a point `p` onto the hyperplane spanned by the simplex's points. -/ def orthogonalProjectionSpan {n : ℕ} (s : Simplex ℝ P n) : P →ᵃ[ℝ] affineSpan ℝ (Set.range s.points) := orthogonalProjection (affineSpan ℝ (Set.range s.points)) #align affine.simplex.orthogonal_projection_span Affine.Simplex.orthogonalProjectionSpan /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ theorem orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (r : ℝ) (hp : p1 ∈ affineSpan ℝ (Set.range s.points)) : s.orthogonalProjectionSpan (r • (p2 -ᵥ s.orthogonalProjectionSpan p2 : V) +ᵥ p1) = ⟨p1, hp⟩ := EuclideanGeometry.orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ #align affine.simplex.orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} {r₁ : ℝ} (s : Simplex ℝ P n) {p p₁o : P} (hp₁o : p₁o ∈ affineSpan ℝ (Set.range s.points)) : ↑(s.orthogonalProjectionSpan (r₁ • (p -ᵥ ↑(s.orthogonalProjectionSpan p)) +ᵥ p₁o)) = p₁o := congrArg ((↑) : _ → P) (orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ hp₁o) #align affine.simplex.coe_orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (hp1 : p1 ∈ affineSpan ℝ (Set.range s.points)) : dist p1 p2 * dist p1 p2 = dist p1 (s.orthogonalProjectionSpan p2) * dist p1 (s.orthogonalProjectionSpan p2) + dist p2 (s.orthogonalProjectionSpan p2) * dist p2 (s.orthogonalProjectionSpan p2) := by rw [PseudoMetricSpace.dist_comm p2 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V _ p2, ← vsub_add_vsub_cancel p1 (s.orthogonalProjectionSpan p2) p2, norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact Submodule.inner_right_of_mem_orthogonal (vsub_orthogonalProjection_mem_direction p2 hp1) (orthogonalProjection_vsub_mem_direction_orthogonal _ p2) #align affine.simplex.dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq Affine.Simplex.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq theorem dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : Simplex ℝ P n) {p₁ : P} (h₁ : ∀ i : Fin (n + 1), dist (s.points i) p₁ = r) (h₁' : ↑(s.orthogonalProjectionSpan p₁) = s.circumcenter) (h : s.points 0 ∈ affineSpan ℝ (Set.range s.points)) : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := by rw [dist_comm, ← h₁ 0, s.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₁ h] simp only [h₁', dist_comm p₁, add_sub_cancel_left, Simplex.dist_circumcenter_eq_circumradius] #align affine.simplex.dist_circumcenter_sq_eq_sq_sub_circumradius Affine.Simplex.dist_circumcenter_sq_eq_sq_sub_circumradius /-- If there exists a distance that a point has from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := by change ∃ r : ℝ, ∀ i, (fun x => dist x p = r) (s.points i) at hr have hr : ∃ (r : ℝ), ∀ (a : P), a ∈ Set.range (fun (i : Fin (n + 1)) => s.points i) → dist a p = r := by cases' hr with r hr use r refine Set.forall_mem_range.mpr ?_ exact hr rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq (subset_affineSpan ℝ _) p] at hr cases' hr with r hr exact s.eq_circumcenter_of_dist_eq (orthogonalProjection_mem p) fun i => hr _ (Set.mem_range_self i) #align affine.simplex.orthogonal_projection_eq_circumcenter_of_exists_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_exists_dist_eq /-- If a point has the same distance from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := s.orthogonalProjection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩ #align affine.simplex.orthogonal_projection_eq_circumcenter_of_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_dist_eq /-- The orthogonal projection of the circumcenter onto a face is the circumcenter of that face. -/
Mathlib/Geometry/Euclidean/Circumcenter.lean
487
493
theorem orthogonalProjection_circumcenter {n : ℕ} (s : Simplex ℝ P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : ↑((s.face h).orthogonalProjectionSpan s.circumcenter) = (s.face h).circumcenter := haveI hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r := by
use s.circumradius simp [face_points] orthogonalProjection_eq_circumcenter_of_exists_dist_eq _ hr
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Yaël Dillies -/ import Mathlib.Data.Nat.Defs import Mathlib.Order.Interval.Set.Basic import Mathlib.Tactic.Monotonicity.Attr #align_import data.nat.log from "leanprover-community/mathlib"@"3e00d81bdcbf77c8188bbd18f5524ddc3ed8cac6" /-! # Natural number logarithms This file defines two `ℕ`-valued analogs of the logarithm of `n` with base `b`: * `log b n`: Lower logarithm, or floor **log**. Greatest `k` such that `b^k ≤ n`. * `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n ≤ b^k`. These are interesting because, for `1 < b`, `Nat.log b` and `Nat.clog b` are respectively right and left adjoints of `Nat.pow b`. See `pow_le_iff_le_log` and `le_pow_iff_clog_le`. -/ namespace Nat /-! ### Floor logarithm -/ /-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : ℕ` such that `b^k ≤ n`, so if `b^k = n`, it returns exactly `k`. -/ --@[pp_nodot] porting note: unknown attribute def log (b : ℕ) : ℕ → ℕ | n => if h : b ≤ n ∧ 1 < b then log b (n / b) + 1 else 0 decreasing_by -- putting this in the def triggers the `unusedHavesSuffices` linter: -- https://github.com/leanprover-community/batteries/issues/428 have : n / b < n := div_lt_self ((Nat.zero_lt_one.trans h.2).trans_le h.1) h.2 decreasing_trivial #align nat.log Nat.log @[simp] theorem log_eq_zero_iff {b n : ℕ} : log b n = 0 ↔ n < b ∨ b ≤ 1 := by rw [log, dite_eq_right_iff] simp only [Nat.add_eq_zero_iff, Nat.one_ne_zero, and_false, imp_false, not_and_or, not_le, not_lt] #align nat.log_eq_zero_iff Nat.log_eq_zero_iff theorem log_of_lt {b n : ℕ} (hb : n < b) : log b n = 0 := log_eq_zero_iff.2 (Or.inl hb) #align nat.log_of_lt Nat.log_of_lt theorem log_of_left_le_one {b : ℕ} (hb : b ≤ 1) (n) : log b n = 0 := log_eq_zero_iff.2 (Or.inr hb) #align nat.log_of_left_le_one Nat.log_of_left_le_one @[simp] theorem log_pos_iff {b n : ℕ} : 0 < log b n ↔ b ≤ n ∧ 1 < b := by rw [Nat.pos_iff_ne_zero, Ne, log_eq_zero_iff, not_or, not_lt, not_le] #align nat.log_pos_iff Nat.log_pos_iff theorem log_pos {b n : ℕ} (hb : 1 < b) (hbn : b ≤ n) : 0 < log b n := log_pos_iff.2 ⟨hbn, hb⟩ #align nat.log_pos Nat.log_pos theorem log_of_one_lt_of_le {b n : ℕ} (h : 1 < b) (hn : b ≤ n) : log b n = log b (n / b) + 1 := by rw [log] exact if_pos ⟨hn, h⟩ #align nat.log_of_one_lt_of_le Nat.log_of_one_lt_of_le @[simp] lemma log_zero_left : ∀ n, log 0 n = 0 := log_of_left_le_one $ Nat.zero_le _ #align nat.log_zero_left Nat.log_zero_left @[simp] theorem log_zero_right (b : ℕ) : log b 0 = 0 := log_eq_zero_iff.2 (le_total 1 b) #align nat.log_zero_right Nat.log_zero_right @[simp] theorem log_one_left : ∀ n, log 1 n = 0 := log_of_left_le_one le_rfl #align nat.log_one_left Nat.log_one_left @[simp] theorem log_one_right (b : ℕ) : log b 1 = 0 := log_eq_zero_iff.2 (lt_or_le _ _) #align nat.log_one_right Nat.log_one_right /-- `pow b` and `log b` (almost) form a Galois connection. See also `Nat.pow_le_of_le_log` and `Nat.le_log_of_pow_le` for individual implications under weaker assumptions. -/ theorem pow_le_iff_le_log {b : ℕ} (hb : 1 < b) {x y : ℕ} (hy : y ≠ 0) : b ^ x ≤ y ↔ x ≤ log b y := by induction' y using Nat.strong_induction_on with y ih generalizing x cases x with | zero => dsimp; omega | succ x => rw [log]; split_ifs with h · have b_pos : 0 < b := lt_of_succ_lt hb rw [Nat.add_le_add_iff_right, ← ih (y / b) (div_lt_self (Nat.pos_iff_ne_zero.2 hy) hb) (Nat.div_pos h.1 b_pos).ne', le_div_iff_mul_le b_pos, pow_succ', Nat.mul_comm] · exact iff_of_false (fun hby => h ⟨(le_self_pow x.succ_ne_zero _).trans hby, hb⟩) (not_succ_le_zero _) #align nat.pow_le_iff_le_log Nat.pow_le_iff_le_log theorem lt_pow_iff_log_lt {b : ℕ} (hb : 1 < b) {x y : ℕ} (hy : y ≠ 0) : y < b ^ x ↔ log b y < x := lt_iff_lt_of_le_iff_le (pow_le_iff_le_log hb hy) #align nat.lt_pow_iff_log_lt Nat.lt_pow_iff_log_lt theorem pow_le_of_le_log {b x y : ℕ} (hy : y ≠ 0) (h : x ≤ log b y) : b ^ x ≤ y := by refine (le_or_lt b 1).elim (fun hb => ?_) fun hb => (pow_le_iff_le_log hb hy).2 h rw [log_of_left_le_one hb, Nat.le_zero] at h rwa [h, Nat.pow_zero, one_le_iff_ne_zero] #align nat.pow_le_of_le_log Nat.pow_le_of_le_log theorem le_log_of_pow_le {b x y : ℕ} (hb : 1 < b) (h : b ^ x ≤ y) : x ≤ log b y := by rcases ne_or_eq y 0 with (hy | rfl) exacts [(pow_le_iff_le_log hb hy).1 h, (h.not_lt (Nat.pow_pos (Nat.zero_lt_one.trans hb))).elim] #align nat.le_log_of_pow_le Nat.le_log_of_pow_le theorem pow_log_le_self (b : ℕ) {x : ℕ} (hx : x ≠ 0) : b ^ log b x ≤ x := pow_le_of_le_log hx le_rfl #align nat.pow_log_le_self Nat.pow_log_le_self theorem log_lt_of_lt_pow {b x y : ℕ} (hy : y ≠ 0) : y < b ^ x → log b y < x := lt_imp_lt_of_le_imp_le (pow_le_of_le_log hy) #align nat.log_lt_of_lt_pow Nat.log_lt_of_lt_pow theorem lt_pow_of_log_lt {b x y : ℕ} (hb : 1 < b) : log b y < x → y < b ^ x := lt_imp_lt_of_le_imp_le (le_log_of_pow_le hb) #align nat.lt_pow_of_log_lt Nat.lt_pow_of_log_lt theorem lt_pow_succ_log_self {b : ℕ} (hb : 1 < b) (x : ℕ) : x < b ^ (log b x).succ := lt_pow_of_log_lt hb (lt_succ_self _) #align nat.lt_pow_succ_log_self Nat.lt_pow_succ_log_self theorem log_eq_iff {b m n : ℕ} (h : m ≠ 0 ∨ 1 < b ∧ n ≠ 0) : log b n = m ↔ b ^ m ≤ n ∧ n < b ^ (m + 1) := by rcases em (1 < b ∧ n ≠ 0) with (⟨hb, hn⟩ | hbn) · rw [le_antisymm_iff, ← Nat.lt_succ_iff, ← pow_le_iff_le_log, ← lt_pow_iff_log_lt, and_comm] <;> assumption have hm : m ≠ 0 := h.resolve_right hbn rw [not_and_or, not_lt, Ne, not_not] at hbn rcases hbn with (hb | rfl) · obtain rfl | rfl := le_one_iff_eq_zero_or_eq_one.1 hb any_goals simp only [ne_eq, zero_eq, reduceSucc, lt_self_iff_false, not_lt_zero, false_and, or_false] at h simp [h, eq_comm (a := 0), Nat.zero_pow (Nat.pos_iff_ne_zero.2 _)] <;> omega · simp [@eq_comm _ 0, hm] #align nat.log_eq_iff Nat.log_eq_iff theorem log_eq_of_pow_le_of_lt_pow {b m n : ℕ} (h₁ : b ^ m ≤ n) (h₂ : n < b ^ (m + 1)) : log b n = m := by rcases eq_or_ne m 0 with (rfl | hm) · rw [Nat.pow_one] at h₂ exact log_of_lt h₂ · exact (log_eq_iff (Or.inl hm)).2 ⟨h₁, h₂⟩ #align nat.log_eq_of_pow_le_of_lt_pow Nat.log_eq_of_pow_le_of_lt_pow theorem log_pow {b : ℕ} (hb : 1 < b) (x : ℕ) : log b (b ^ x) = x := log_eq_of_pow_le_of_lt_pow le_rfl (Nat.pow_lt_pow_right hb x.lt_succ_self) #align nat.log_pow Nat.log_pow theorem log_eq_one_iff' {b n : ℕ} : log b n = 1 ↔ b ≤ n ∧ n < b * b := by rw [log_eq_iff (Or.inl Nat.one_ne_zero), Nat.pow_add, Nat.pow_one] #align nat.log_eq_one_iff' Nat.log_eq_one_iff' theorem log_eq_one_iff {b n : ℕ} : log b n = 1 ↔ n < b * b ∧ 1 < b ∧ b ≤ n := log_eq_one_iff'.trans ⟨fun h => ⟨h.2, lt_mul_self_iff.1 (h.1.trans_lt h.2), h.1⟩, fun h => ⟨h.2.2, h.1⟩⟩ #align nat.log_eq_one_iff Nat.log_eq_one_iff theorem log_mul_base {b n : ℕ} (hb : 1 < b) (hn : n ≠ 0) : log b (n * b) = log b n + 1 := by apply log_eq_of_pow_le_of_lt_pow <;> rw [pow_succ', Nat.mul_comm b] exacts [Nat.mul_le_mul_right _ (pow_log_le_self _ hn), (Nat.mul_lt_mul_right (Nat.zero_lt_one.trans hb)).2 (lt_pow_succ_log_self hb _)] #align nat.log_mul_base Nat.log_mul_base theorem pow_log_le_add_one (b : ℕ) : ∀ x, b ^ log b x ≤ x + 1 | 0 => by rw [log_zero_right, Nat.pow_zero] | x + 1 => (pow_log_le_self b x.succ_ne_zero).trans (x + 1).le_succ #align nat.pow_log_le_add_one Nat.pow_log_le_add_one theorem log_monotone {b : ℕ} : Monotone (log b) := by refine monotone_nat_of_le_succ fun n => ?_ rcases le_or_lt b 1 with hb | hb · rw [log_of_left_le_one hb] exact zero_le _ · exact le_log_of_pow_le hb (pow_log_le_add_one _ _) #align nat.log_monotone Nat.log_monotone @[mono] theorem log_mono_right {b n m : ℕ} (h : n ≤ m) : log b n ≤ log b m := log_monotone h #align nat.log_mono_right Nat.log_mono_right @[mono] theorem log_anti_left {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : log b n ≤ log c n := by rcases eq_or_ne n 0 with (rfl | hn); · rw [log_zero_right, log_zero_right] apply le_log_of_pow_le hc calc c ^ log b n ≤ b ^ log b n := Nat.pow_le_pow_left hb _ _ ≤ n := pow_log_le_self _ hn #align nat.log_anti_left Nat.log_anti_left theorem log_antitone_left {n : ℕ} : AntitoneOn (fun b => log b n) (Set.Ioi 1) := fun _ hc _ _ hb => log_anti_left (Set.mem_Iio.1 hc) hb #align nat.log_antitone_left Nat.log_antitone_left @[simp] theorem log_div_base (b n : ℕ) : log b (n / b) = log b n - 1 := by rcases le_or_lt b 1 with hb | hb · rw [log_of_left_le_one hb, log_of_left_le_one hb, Nat.zero_sub] cases' lt_or_le n b with h h · rw [div_eq_of_lt h, log_of_lt h, log_zero_right] rw [log_of_one_lt_of_le hb h, Nat.add_sub_cancel_right] #align nat.log_div_base Nat.log_div_base @[simp] theorem log_div_mul_self (b n : ℕ) : log b (n / b * b) = log b n := by rcases le_or_lt b 1 with hb | hb · rw [log_of_left_le_one hb, log_of_left_le_one hb] cases' lt_or_le n b with h h · rw [div_eq_of_lt h, Nat.zero_mul, log_zero_right, log_of_lt h] rw [log_mul_base hb (Nat.div_pos h (by omega)).ne', log_div_base, Nat.sub_add_cancel (succ_le_iff.2 <| log_pos hb h)] #align nat.log_div_mul_self Nat.log_div_mul_self theorem add_pred_div_lt {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : (n + b - 1) / b < n := by rw [div_lt_iff_lt_mul (by omega), ← succ_le_iff, ← pred_eq_sub_one, succ_pred_eq_of_pos (by omega)] exact Nat.add_le_mul hn hb -- Porting note: Was private in mathlib 3 -- #align nat.add_pred_div_lt Nat.add_pred_div_lt /-! ### Ceil logarithm -/ /-- `clog b n`, is the upper logarithm of natural number `n` in base `b`. It returns the smallest `k : ℕ` such that `n ≤ b^k`, so if `b^k = n`, it returns exactly `k`. -/ --@[pp_nodot] def clog (b : ℕ) : ℕ → ℕ | n => if h : 1 < b ∧ 1 < n then clog b ((n + b - 1) / b) + 1 else 0 decreasing_by -- putting this in the def triggers the `unusedHavesSuffices` linter: -- https://github.com/leanprover-community/batteries/issues/428 have : (n + b - 1) / b < n := add_pred_div_lt h.1 h.2 decreasing_trivial #align nat.clog Nat.clog theorem clog_of_left_le_one {b : ℕ} (hb : b ≤ 1) (n : ℕ) : clog b n = 0 := by rw [clog, dif_neg fun h : 1 < b ∧ 1 < n => h.1.not_le hb] #align nat.clog_of_left_le_one Nat.clog_of_left_le_one theorem clog_of_right_le_one {n : ℕ} (hn : n ≤ 1) (b : ℕ) : clog b n = 0 := by rw [clog, dif_neg fun h : 1 < b ∧ 1 < n => h.2.not_le hn] #align nat.clog_of_right_le_one Nat.clog_of_right_le_one @[simp] lemma clog_zero_left (n : ℕ) : clog 0 n = 0 := clog_of_left_le_one (Nat.zero_le _) _ #align nat.clog_zero_left Nat.clog_zero_left @[simp] lemma clog_zero_right (b : ℕ) : clog b 0 = 0 := clog_of_right_le_one (Nat.zero_le _) _ #align nat.clog_zero_right Nat.clog_zero_right @[simp] theorem clog_one_left (n : ℕ) : clog 1 n = 0 := clog_of_left_le_one le_rfl _ #align nat.clog_one_left Nat.clog_one_left @[simp] theorem clog_one_right (b : ℕ) : clog b 1 = 0 := clog_of_right_le_one le_rfl _ #align nat.clog_one_right Nat.clog_one_right theorem clog_of_two_le {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : clog b n = clog b ((n + b - 1) / b) + 1 := by rw [clog, dif_pos (⟨hb, hn⟩ : 1 < b ∧ 1 < n)] #align nat.clog_of_two_le Nat.clog_of_two_le theorem clog_pos {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : 0 < clog b n := by rw [clog_of_two_le hb hn] exact zero_lt_succ _ #align nat.clog_pos Nat.clog_pos theorem clog_eq_one {b n : ℕ} (hn : 2 ≤ n) (h : n ≤ b) : clog b n = 1 := by rw [clog_of_two_le (hn.trans h) hn, clog_of_right_le_one] rw [← Nat.lt_succ_iff, Nat.div_lt_iff_lt_mul] <;> omega #align nat.clog_eq_one Nat.clog_eq_one /-- `clog b` and `pow b` form a Galois connection. -/ theorem le_pow_iff_clog_le {b : ℕ} (hb : 1 < b) {x y : ℕ} : x ≤ b ^ y ↔ clog b x ≤ y := by induction' x using Nat.strong_induction_on with x ih generalizing y cases y · rw [Nat.pow_zero] refine ⟨fun h => (clog_of_right_le_one h b).le, ?_⟩ simp_rw [← not_lt] contrapose! exact clog_pos hb have b_pos : 0 < b := zero_lt_of_lt hb rw [clog]; split_ifs with h · rw [Nat.add_le_add_iff_right, ← ih ((x + b - 1) / b) (add_pred_div_lt hb h.2), Nat.div_le_iff_le_mul_add_pred b_pos, Nat.mul_comm b, ← Nat.pow_succ, Nat.add_sub_assoc (Nat.succ_le_of_lt b_pos), Nat.add_le_add_iff_right] · exact iff_of_true ((not_lt.1 (not_and.1 h hb)).trans <| succ_le_of_lt <| Nat.pow_pos b_pos) (zero_le _) #align nat.le_pow_iff_clog_le Nat.le_pow_iff_clog_le theorem pow_lt_iff_lt_clog {b : ℕ} (hb : 1 < b) {x y : ℕ} : b ^ y < x ↔ y < clog b x := lt_iff_lt_of_le_iff_le (le_pow_iff_clog_le hb) #align nat.pow_lt_iff_lt_clog Nat.pow_lt_iff_lt_clog theorem clog_pow (b x : ℕ) (hb : 1 < b) : clog b (b ^ x) = x := eq_of_forall_ge_iff fun z ↦ by rw [← le_pow_iff_clog_le hb, Nat.pow_le_pow_iff_right hb] #align nat.clog_pow Nat.clog_pow theorem pow_pred_clog_lt_self {b : ℕ} (hb : 1 < b) {x : ℕ} (hx : 1 < x) : b ^ (clog b x).pred < x := by rw [← not_le, le_pow_iff_clog_le hb, not_le] exact pred_lt (clog_pos hb hx).ne' #align nat.pow_pred_clog_lt_self Nat.pow_pred_clog_lt_self theorem le_pow_clog {b : ℕ} (hb : 1 < b) (x : ℕ) : x ≤ b ^ clog b x := (le_pow_iff_clog_le hb).2 le_rfl #align nat.le_pow_clog Nat.le_pow_clog @[mono] theorem clog_mono_right (b : ℕ) {n m : ℕ} (h : n ≤ m) : clog b n ≤ clog b m := by rcases le_or_lt b 1 with hb | hb · rw [clog_of_left_le_one hb] exact zero_le _ · rw [← le_pow_iff_clog_le hb] exact h.trans (le_pow_clog hb _) #align nat.clog_mono_right Nat.clog_mono_right @[mono]
Mathlib/Data/Nat/Log.lean
335
339
theorem clog_anti_left {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : clog b n ≤ clog c n := by
rw [← le_pow_iff_clog_le (lt_of_lt_of_le hc hb)] calc n ≤ c ^ clog c n := le_pow_clog hc _ _ ≤ b ^ clog c n := Nat.pow_le_pow_left hb _
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Floris van Doorn, Gabriel Ebner, Yury Kudryashov -/ import Mathlib.Order.ConditionallyCompleteLattice.Finset import Mathlib.Order.Interval.Finset.Nat #align_import data.nat.lattice from "leanprover-community/mathlib"@"52fa514ec337dd970d71d8de8d0fd68b455a1e54" /-! # Conditionally complete linear order structure on `ℕ` In this file we * define a `ConditionallyCompleteLinearOrderBot` structure on `ℕ`; * prove a few lemmas about `iSup`/`iInf`/`Set.iUnion`/`Set.iInter` and natural numbers. -/ assert_not_exists MonoidWithZero open Set namespace Nat open scoped Classical noncomputable instance : InfSet ℕ := ⟨fun s ↦ if h : ∃ n, n ∈ s then @Nat.find (fun n ↦ n ∈ s) _ h else 0⟩ noncomputable instance : SupSet ℕ := ⟨fun s ↦ if h : ∃ n, ∀ a ∈ s, a ≤ n then @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h else 0⟩ theorem sInf_def {s : Set ℕ} (h : s.Nonempty) : sInf s = @Nat.find (fun n ↦ n ∈ s) _ h := dif_pos _ #align nat.Inf_def Nat.sInf_def theorem sSup_def {s : Set ℕ} (h : ∃ n, ∀ a ∈ s, a ≤ n) : sSup s = @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h := dif_pos _ #align nat.Sup_def Nat.sSup_def theorem _root_.Set.Infinite.Nat.sSup_eq_zero {s : Set ℕ} (h : s.Infinite) : sSup s = 0 := dif_neg fun ⟨n, hn⟩ ↦ let ⟨k, hks, hk⟩ := h.exists_gt n (hn k hks).not_lt hk #align set.infinite.nat.Sup_eq_zero Set.Infinite.Nat.sSup_eq_zero @[simp] theorem sInf_eq_zero {s : Set ℕ} : sInf s = 0 ↔ 0 ∈ s ∨ s = ∅ := by cases eq_empty_or_nonempty s with | inl h => subst h simp only [or_true_iff, eq_self_iff_true, iff_true_iff, iInf, InfSet.sInf, mem_empty_iff_false, exists_false, dif_neg, not_false_iff] | inr h => simp only [h.ne_empty, or_false_iff, Nat.sInf_def, h, Nat.find_eq_zero] #align nat.Inf_eq_zero Nat.sInf_eq_zero @[simp] theorem sInf_empty : sInf ∅ = 0 := by rw [sInf_eq_zero] right rfl #align nat.Inf_empty Nat.sInf_empty @[simp] theorem iInf_of_empty {ι : Sort*} [IsEmpty ι] (f : ι → ℕ) : iInf f = 0 := by rw [iInf_of_isEmpty, sInf_empty] #align nat.infi_of_empty Nat.iInf_of_empty /-- This combines `Nat.iInf_of_empty` with `ciInf_const`. -/ @[simp] lemma iInf_const_zero {ι : Sort*} : ⨅ i : ι, 0 = 0 := (isEmpty_or_nonempty ι).elim (fun h ↦ by simp) fun h ↦ sInf_eq_zero.2 <| by simp theorem sInf_mem {s : Set ℕ} (h : s.Nonempty) : sInf s ∈ s := by rw [Nat.sInf_def h] exact Nat.find_spec h #align nat.Inf_mem Nat.sInf_mem theorem not_mem_of_lt_sInf {s : Set ℕ} {m : ℕ} (hm : m < sInf s) : m ∉ s := by cases eq_empty_or_nonempty s with | inl h => subst h; apply not_mem_empty | inr h => rw [Nat.sInf_def h] at hm; exact Nat.find_min h hm #align nat.not_mem_of_lt_Inf Nat.not_mem_of_lt_sInf protected theorem sInf_le {s : Set ℕ} {m : ℕ} (hm : m ∈ s) : sInf s ≤ m := by rw [Nat.sInf_def ⟨m, hm⟩] exact Nat.find_min' ⟨m, hm⟩ hm #align nat.Inf_le Nat.sInf_le theorem nonempty_of_pos_sInf {s : Set ℕ} (h : 0 < sInf s) : s.Nonempty := by by_contra contra rw [Set.not_nonempty_iff_eq_empty] at contra have h' : sInf s ≠ 0 := ne_of_gt h apply h' rw [Nat.sInf_eq_zero] right assumption #align nat.nonempty_of_pos_Inf Nat.nonempty_of_pos_sInf theorem nonempty_of_sInf_eq_succ {s : Set ℕ} {k : ℕ} (h : sInf s = k + 1) : s.Nonempty := nonempty_of_pos_sInf (h.symm ▸ succ_pos k : sInf s > 0) #align nat.nonempty_of_Inf_eq_succ Nat.nonempty_of_sInf_eq_succ theorem eq_Ici_of_nonempty_of_upward_closed {s : Set ℕ} (hs : s.Nonempty) (hs' : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s) : s = Ici (sInf s) := ext fun n ↦ ⟨fun H ↦ Nat.sInf_le H, fun H ↦ hs' (sInf s) n H (sInf_mem hs)⟩ #align nat.eq_Ici_of_nonempty_of_upward_closed Nat.eq_Ici_of_nonempty_of_upward_closed
Mathlib/Data/Nat/Lattice.lean
110
120
theorem sInf_upward_closed_eq_succ_iff {s : Set ℕ} (hs : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s) (k : ℕ) : sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s := by
constructor · intro H rw [eq_Ici_of_nonempty_of_upward_closed (nonempty_of_sInf_eq_succ _) hs, H, mem_Ici, mem_Ici] · exact ⟨le_rfl, k.not_succ_le_self⟩; · exact k · assumption · rintro ⟨H, H'⟩ rw [sInf_def (⟨_, H⟩ : s.Nonempty), find_eq_iff] exact ⟨H, fun n hnk hns ↦ H' <| hs n k (Nat.lt_succ_iff.mp hnk) hns⟩
/- 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, Mario Carneiro -/ import Batteries.Tactic.Alias import Batteries.Data.List.Init.Attach import Batteries.Data.List.Pairwise -- Adaptation note: nightly-2024-03-18. We should be able to remove this after nightly-2024-03-19. import Lean.Elab.Tactic.Rfl /-! # List Permutations This file introduces the `List.Perm` relation, which is true if two lists are permutations of one another. ## Notation The notation `~` is used for permutation equivalence. -/ open Nat namespace List open Perm (swap) @[simp, refl] protected theorem Perm.refl : ∀ l : List α, l ~ l | [] => .nil | x :: xs => (Perm.refl xs).cons x protected theorem Perm.rfl {l : List α} : l ~ l := .refl _ theorem Perm.of_eq (h : l₁ = l₂) : l₁ ~ l₂ := h ▸ .rfl protected theorem Perm.symm {l₁ l₂ : List α} (h : l₁ ~ l₂) : l₂ ~ l₁ := by induction h with | nil => exact nil | cons _ _ ih => exact cons _ ih | swap => exact swap .. | trans _ _ ih₁ ih₂ => exact trans ih₂ ih₁ theorem perm_comm {l₁ l₂ : List α} : l₁ ~ l₂ ↔ l₂ ~ l₁ := ⟨Perm.symm, Perm.symm⟩ theorem Perm.swap' (x y : α) {l₁ l₂ : List α} (p : l₁ ~ l₂) : y :: x :: l₁ ~ x :: y :: l₂ := (swap ..).trans <| p.cons _ |>.cons _ /-- Similar to `Perm.recOn`, but the `swap` case is generalized to `Perm.swap'`, where the tail of the lists are not necessarily the same. -/ @[elab_as_elim] theorem Perm.recOnSwap' {motive : (l₁ : List α) → (l₂ : List α) → l₁ ~ l₂ → Prop} {l₁ l₂ : List α} (p : l₁ ~ l₂) (nil : motive [] [] .nil) (cons : ∀ x {l₁ l₂}, (h : l₁ ~ l₂) → motive l₁ l₂ h → motive (x :: l₁) (x :: l₂) (.cons x h)) (swap' : ∀ x y {l₁ l₂}, (h : l₁ ~ l₂) → motive l₁ l₂ h → motive (y :: x :: l₁) (x :: y :: l₂) (.swap' _ _ h)) (trans : ∀ {l₁ l₂ l₃}, (h₁ : l₁ ~ l₂) → (h₂ : l₂ ~ l₃) → motive l₁ l₂ h₁ → motive l₂ l₃ h₂ → motive l₁ l₃ (.trans h₁ h₂)) : motive l₁ l₂ p := have motive_refl l : motive l l (.refl l) := List.recOn l nil fun x xs ih => cons x (.refl xs) ih Perm.recOn p nil cons (fun x y l => swap' x y (.refl l) (motive_refl l)) trans theorem Perm.eqv (α) : Equivalence (@Perm α) := ⟨.refl, .symm, .trans⟩ instance isSetoid (α) : Setoid (List α) := .mk Perm (Perm.eqv α) theorem Perm.mem_iff {a : α} {l₁ l₂ : List α} (p : l₁ ~ l₂) : a ∈ l₁ ↔ a ∈ l₂ := by induction p with | nil => rfl | cons _ _ ih => simp only [mem_cons, ih] | swap => simp only [mem_cons, or_left_comm] | trans _ _ ih₁ ih₂ => simp only [ih₁, ih₂] theorem Perm.subset {l₁ l₂ : List α} (p : l₁ ~ l₂) : l₁ ⊆ l₂ := fun _ => p.mem_iff.mp
.lake/packages/batteries/Batteries/Data/List/Perm.lean
78
83
theorem Perm.append_right {l₁ l₂ : List α} (t₁ : List α) (p : l₁ ~ l₂) : l₁ ++ t₁ ~ l₂ ++ t₁ := by
induction p with | nil => rfl | cons _ _ ih => exact cons _ ih | swap => exact swap .. | trans _ _ ih₁ ih₂ => exact trans ih₁ ih₂
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johan Commelin -/ import Mathlib.RingTheory.IntegralClosure #align_import field_theory.minpoly.basic from "leanprover-community/mathlib"@"df0098f0db291900600f32070f6abb3e178be2ba" /-! # Minimal polynomials This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`, under the assumption that x is integral over `A`, and derives some basic properties such as irreducibility under the assumption `B` is a domain. -/ open scoped Classical open Polynomial Set Function variable {A B B' : Type*} section MinPolyDef variable (A) [CommRing A] [Ring B] [Algebra A B] /-- Suppose `x : B`, where `B` is an `A`-algebra. The minimal polynomial `minpoly A x` of `x` is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root, if such exists (`IsIntegral A x`) or zero otherwise. For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then the minimal polynomial of `f` is `minpoly 𝕜 f`. -/ noncomputable def minpoly (x : B) : A[X] := if hx : IsIntegral A x then degree_lt_wf.min _ hx else 0 #align minpoly minpoly end MinPolyDef namespace minpoly section Ring variable [CommRing A] [Ring B] [Ring B'] [Algebra A B] [Algebra A B'] variable {x : B} /-- A minimal polynomial is monic. -/ theorem monic (hx : IsIntegral A x) : Monic (minpoly A x) := by delta minpoly rw [dif_pos hx] exact (degree_lt_wf.min_mem _ hx).1 #align minpoly.monic minpoly.monic /-- A minimal polynomial is nonzero. -/ theorem ne_zero [Nontrivial A] (hx : IsIntegral A x) : minpoly A x ≠ 0 := (monic hx).ne_zero #align minpoly.ne_zero minpoly.ne_zero theorem eq_zero (hx : ¬IsIntegral A x) : minpoly A x = 0 := dif_neg hx #align minpoly.eq_zero minpoly.eq_zero theorem algHom_eq (f : B →ₐ[A] B') (hf : Function.Injective f) (x : B) : minpoly A (f x) = minpoly A x := by refine dif_ctx_congr (isIntegral_algHom_iff _ hf) (fun _ => ?_) fun _ => rfl simp_rw [← Polynomial.aeval_def, aeval_algHom, AlgHom.comp_apply, _root_.map_eq_zero_iff f hf] #align minpoly.minpoly_alg_hom minpoly.algHom_eq theorem algebraMap_eq {B} [CommRing B] [Algebra A B] [Algebra B B'] [IsScalarTower A B B'] (h : Function.Injective (algebraMap B B')) (x : B) : minpoly A (algebraMap B B' x) = minpoly A x := algHom_eq (IsScalarTower.toAlgHom A B B') h x @[simp] theorem algEquiv_eq (f : B ≃ₐ[A] B') (x : B) : minpoly A (f x) = minpoly A x := algHom_eq (f : B →ₐ[A] B') f.injective x #align minpoly.minpoly_alg_equiv minpoly.algEquiv_eq variable (A x) /-- An element is a root of its minimal polynomial. -/ @[simp] theorem aeval : aeval x (minpoly A x) = 0 := by delta minpoly split_ifs with hx · exact (degree_lt_wf.min_mem _ hx).2 · exact aeval_zero _ #align minpoly.aeval minpoly.aeval /-- Given any `f : B →ₐ[A] B'` and any `x : L`, the minimal polynomial of `x` vanishes at `f x`. -/ @[simp] theorem aeval_algHom (f : B →ₐ[A] B') (x : B) : (Polynomial.aeval (f x)) (minpoly A x) = 0 := by rw [Polynomial.aeval_algHom, AlgHom.coe_comp, comp_apply, aeval, map_zero] /-- A minimal polynomial is not `1`. -/
Mathlib/FieldTheory/Minpoly/Basic.lean
100
103
theorem ne_one [Nontrivial B] : minpoly A x ≠ 1 := by
intro h refine (one_ne_zero : (1 : B) ≠ 0) ?_ simpa using congr_arg (Polynomial.aeval x) h
/- Copyright (c) 2020 Kevin Buzzard, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.Preadditive.FunctorCategory import Mathlib.CategoryTheory.Sites.SheafOfTypes import Mathlib.CategoryTheory.Sites.EqualizerSheafCondition #align_import category_theory.sites.sheaf from "leanprover-community/mathlib"@"2efd2423f8d25fa57cf7a179f5d8652ab4d0df44" /-! # Sheaves taking values in a category If C is a category with a Grothendieck topology, we define the notion of a sheaf taking values in an arbitrary category `A`. We follow the definition in https://stacks.math.columbia.edu/tag/00VR, noting that the presheaf of sets "defined above" can be seen in the comments between tags 00VQ and 00VR on the page <https://stacks.math.columbia.edu/tag/00VL>. The advantage of this definition is that we need no assumptions whatsoever on `A` other than the assumption that the morphisms in `C` and `A` live in the same universe. * An `A`-valued presheaf `P : Cᵒᵖ ⥤ A` is defined to be a sheaf (for the topology `J`) iff for every `E : A`, the type-valued presheaves of sets given by sending `U : Cᵒᵖ` to `Hom_{A}(E, P U)` are all sheaves of sets, see `CategoryTheory.Presheaf.IsSheaf`. * When `A = Type`, this recovers the basic definition of sheaves of sets, see `CategoryTheory.isSheaf_iff_isSheaf_of_type`. * A alternate definition in terms of limits, unconditionally equivalent to the original one: see `CategoryTheory.Presheaf.isSheaf_iff_isLimit`. * An alternate definition when `C` is small, has pullbacks and `A` has products is given by an equalizer condition `CategoryTheory.Presheaf.IsSheaf'`. This is equivalent to the earlier definition, shown in `CategoryTheory.Presheaf.isSheaf_iff_isSheaf'`. * When `A = Type`, this is *definitionally* equal to the equalizer condition for presieves in `CategoryTheory.Sites.SheafOfTypes`. * When `A` has limits and there is a functor `s : A ⥤ Type` which is faithful, reflects isomorphisms and preserves limits, then `P : Cᵒᵖ ⥤ A` is a sheaf iff the underlying presheaf of types `P ⋙ s : Cᵒᵖ ⥤ Type` is a sheaf (`CategoryTheory.Presheaf.isSheaf_iff_isSheaf_forget`). Cf https://stacks.math.columbia.edu/tag/0073, which is a weaker version of this statement (it's only over spaces, not sites) and https://stacks.math.columbia.edu/tag/00YR (a), which additionally assumes filtered colimits. ## Implementation notes Occasionally we need to take a limit in `A` of a collection of morphisms of `C` indexed by a collection of objects in `C`. This turns out to force the morphisms of `A` to be in a sufficiently large universe. Rather than use `UnivLE` we prove some results for a category `A'` instead, whose morphism universe of `A'` is defined to be `max u₁ v₁`, where `u₁, v₁` are the universes for `C`. Perhaps after we get better at handling universe inequalities this can be changed. -/ universe w v₁ v₂ v₃ u₁ u₂ u₃ noncomputable section namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presheaf variable {C : Type u₁} [Category.{v₁} C] variable {A : Type u₂} [Category.{v₂} A] variable (J : GrothendieckTopology C) -- We follow https://stacks.math.columbia.edu/tag/00VL definition 00VR /-- A sheaf of A is a presheaf P : Cᵒᵖ => A such that for every E : A, the presheaf of types given by sending U : C to Hom_{A}(E, P U) is a sheaf of types. https://stacks.math.columbia.edu/tag/00VR -/ def IsSheaf (P : Cᵒᵖ ⥤ A) : Prop := ∀ E : A, Presieve.IsSheaf J (P ⋙ coyoneda.obj (op E)) #align category_theory.presheaf.is_sheaf CategoryTheory.Presheaf.IsSheaf attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike in /-- Condition that a presheaf with values in a concrete category is separated for a Grothendieck topology. -/ def IsSeparated (P : Cᵒᵖ ⥤ A) [ConcreteCategory A] : Prop := ∀ (X : C) (S : Sieve X) (_ : S ∈ J X) (x y : P.obj (op X)), (∀ (Y : C) (f : Y ⟶ X) (_ : S f), P.map f.op x = P.map f.op y) → x = y section LimitSheafCondition open Presieve Presieve.FamilyOfElements Limits variable (P : Cᵒᵖ ⥤ A) {X : C} (S : Sieve X) (R : Presieve X) (E : Aᵒᵖ) /-- Given a sieve `S` on `X : C`, a presheaf `P : Cᵒᵖ ⥤ A`, and an object `E` of `A`, the cones over the natural diagram `S.arrows.diagram.op ⋙ P` associated to `S` and `P` with cone point `E` are in 1-1 correspondence with sieve_compatible family of elements for the sieve `S` and the presheaf of types `Hom (E, P -)`. -/ @[simps] def conesEquivSieveCompatibleFamily : (S.arrows.diagram.op ⋙ P).cones.obj E ≃ { x : FamilyOfElements (P ⋙ coyoneda.obj E) (S : Presieve X) // x.SieveCompatible } where toFun π := ⟨fun Y f h => π.app (op ⟨Over.mk f, h⟩), fun X Y f g hf => by apply (id_comp _).symm.trans dsimp exact π.naturality (Quiver.Hom.op (Over.homMk _ (by rfl)))⟩ invFun x := { app := fun f => x.1 f.unop.1.hom f.unop.2 naturality := fun f f' g => by refine Eq.trans ?_ (x.2 f.unop.1.hom g.unop.left f.unop.2) dsimp rw [id_comp] convert rfl rw [Over.w] } left_inv π := rfl right_inv x := rfl #align category_theory.presheaf.cones_equiv_sieve_compatible_family CategoryTheory.Presheaf.conesEquivSieveCompatibleFamily -- These lemmas have always been bad (#7657), but leanprover/lean4#2644 made `simp` start noticing attribute [nolint simpNF] CategoryTheory.Presheaf.conesEquivSieveCompatibleFamily_apply_coe CategoryTheory.Presheaf.conesEquivSieveCompatibleFamily_symm_apply_app variable {P S E} {x : FamilyOfElements (P ⋙ coyoneda.obj E) S.arrows} (hx : SieveCompatible x) /-- The cone corresponding to a sieve_compatible family of elements, dot notation enabled. -/ @[simp] def _root_.CategoryTheory.Presieve.FamilyOfElements.SieveCompatible.cone : Cone (S.arrows.diagram.op ⋙ P) where pt := E.unop π := (conesEquivSieveCompatibleFamily P S E).invFun ⟨x, hx⟩ #align category_theory.presieve.family_of_elements.sieve_compatible.cone CategoryTheory.Presieve.FamilyOfElements.SieveCompatible.cone /-- Cone morphisms from the cone corresponding to a sieve_compatible family to the natural cone associated to a sieve `S` and a presheaf `P` are in 1-1 correspondence with amalgamations of the family. -/ def homEquivAmalgamation : (hx.cone ⟶ P.mapCone S.arrows.cocone.op) ≃ { t // x.IsAmalgamation t } where toFun l := ⟨l.hom, fun _ f hf => l.w (op ⟨Over.mk f, hf⟩)⟩ invFun t := ⟨t.1, fun f => t.2 f.unop.1.hom f.unop.2⟩ left_inv _ := rfl right_inv _ := rfl #align category_theory.presheaf.hom_equiv_amalgamation CategoryTheory.Presheaf.homEquivAmalgamation variable (P S) /-- Given sieve `S` and presheaf `P : Cᵒᵖ ⥤ A`, their natural associated cone is a limit cone iff `Hom (E, P -)` is a sheaf of types for the sieve `S` and all `E : A`. -/ theorem isLimit_iff_isSheafFor : Nonempty (IsLimit (P.mapCone S.arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSheafFor (P ⋙ coyoneda.obj E) S.arrows := by dsimp [IsSheafFor]; simp_rw [compatible_iff_sieveCompatible] rw [((Cone.isLimitEquivIsTerminal _).trans (isTerminalEquivUnique _ _)).nonempty_congr] rw [Classical.nonempty_pi]; constructor · intro hu E x hx specialize hu hx.cone erw [(homEquivAmalgamation hx).uniqueCongr.nonempty_congr] at hu exact (unique_subtype_iff_exists_unique _).1 hu · rintro h ⟨E, π⟩ let eqv := conesEquivSieveCompatibleFamily P S (op E) rw [← eqv.left_inv π] erw [(homEquivAmalgamation (eqv π).2).uniqueCongr.nonempty_congr] rw [unique_subtype_iff_exists_unique] exact h _ _ (eqv π).2 #align category_theory.presheaf.is_limit_iff_is_sheaf_for CategoryTheory.Presheaf.isLimit_iff_isSheafFor /-- Given sieve `S` and presheaf `P : Cᵒᵖ ⥤ A`, their natural associated cone admits at most one morphism from every cone in the same category (i.e. over the same diagram), iff `Hom (E, P -)`is separated for the sieve `S` and all `E : A`. -/ theorem subsingleton_iff_isSeparatedFor : (∀ c, Subsingleton (c ⟶ P.mapCone S.arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSeparatedFor (P ⋙ coyoneda.obj E) S.arrows := by constructor · intro hs E x t₁ t₂ h₁ h₂ have hx := is_compatible_of_exists_amalgamation x ⟨t₁, h₁⟩ rw [compatible_iff_sieveCompatible] at hx specialize hs hx.cone rcases hs with ⟨hs⟩ simpa only [Subtype.mk.injEq] using (show Subtype.mk t₁ h₁ = ⟨t₂, h₂⟩ from (homEquivAmalgamation hx).symm.injective (hs _ _)) · rintro h ⟨E, π⟩ let eqv := conesEquivSieveCompatibleFamily P S (op E) constructor rw [← eqv.left_inv π] intro f₁ f₂ let eqv' := homEquivAmalgamation (eqv π).2 apply eqv'.injective ext apply h _ (eqv π).1 <;> exact (eqv' _).2 #align category_theory.presheaf.subsingleton_iff_is_separated_for CategoryTheory.Presheaf.subsingleton_iff_isSeparatedFor /-- A presheaf `P` is a sheaf for the Grothendieck topology `J` iff for every covering sieve `S` of `J`, the natural cone associated to `P` and `S` is a limit cone. -/ theorem isSheaf_iff_isLimit : IsSheaf J P ↔ ∀ ⦃X : C⦄ (S : Sieve X), S ∈ J X → Nonempty (IsLimit (P.mapCone S.arrows.cocone.op)) := ⟨fun h _ S hS => (isLimit_iff_isSheafFor P S).2 fun E => h E.unop S hS, fun h E _ S hS => (isLimit_iff_isSheafFor P S).1 (h S hS) (op E)⟩ #align category_theory.presheaf.is_sheaf_iff_is_limit CategoryTheory.Presheaf.isSheaf_iff_isLimit /-- A presheaf `P` is separated for the Grothendieck topology `J` iff for every covering sieve `S` of `J`, the natural cone associated to `P` and `S` admits at most one morphism from every cone in the same category. -/ theorem isSeparated_iff_subsingleton : (∀ E : A, Presieve.IsSeparated J (P ⋙ coyoneda.obj (op E))) ↔ ∀ ⦃X : C⦄ (S : Sieve X), S ∈ J X → ∀ c, Subsingleton (c ⟶ P.mapCone S.arrows.cocone.op) := ⟨fun h _ S hS => (subsingleton_iff_isSeparatedFor P S).2 fun E => h E.unop S hS, fun h E _ S hS => (subsingleton_iff_isSeparatedFor P S).1 (h S hS) (op E)⟩ #align category_theory.presheaf.is_separated_iff_subsingleton CategoryTheory.Presheaf.isSeparated_iff_subsingleton /-- Given presieve `R` and presheaf `P : Cᵒᵖ ⥤ A`, the natural cone associated to `P` and the sieve `Sieve.generate R` generated by `R` is a limit cone iff `Hom (E, P -)` is a sheaf of types for the presieve `R` and all `E : A`. -/ theorem isLimit_iff_isSheafFor_presieve : Nonempty (IsLimit (P.mapCone (generate R).arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSheafFor (P ⋙ coyoneda.obj E) R := (isLimit_iff_isSheafFor P _).trans (forall_congr' fun _ => (isSheafFor_iff_generate _).symm) #align category_theory.presheaf.is_limit_iff_is_sheaf_for_presieve CategoryTheory.Presheaf.isLimit_iff_isSheafFor_presieve /-- A presheaf `P` is a sheaf for the Grothendieck topology generated by a pretopology `K` iff for every covering presieve `R` of `K`, the natural cone associated to `P` and `Sieve.generate R` is a limit cone. -/ theorem isSheaf_iff_isLimit_pretopology [HasPullbacks C] (K : Pretopology C) : IsSheaf (K.toGrothendieck C) P ↔ ∀ ⦃X : C⦄ (R : Presieve X), R ∈ K X → Nonempty (IsLimit (P.mapCone (generate R).arrows.cocone.op)) := by dsimp [IsSheaf] simp_rw [isSheaf_pretopology] exact ⟨fun h X R hR => (isLimit_iff_isSheafFor_presieve P R).2 fun E => h E.unop R hR, fun h E X R hR => (isLimit_iff_isSheafFor_presieve P R).1 (h R hR) (op E)⟩ #align category_theory.presheaf.is_sheaf_iff_is_limit_pretopology CategoryTheory.Presheaf.isSheaf_iff_isLimit_pretopology end LimitSheafCondition variable {J} /-- This is a wrapper around `Presieve.IsSheafFor.amalgamate` to be used below. If `P`s a sheaf, `S` is a cover of `X`, and `x` is a collection of morphisms from `E` to `P` evaluated at terms in the cover which are compatible, then we can amalgamate the `x`s to obtain a single morphism `E ⟶ P.obj (op X)`. -/ def IsSheaf.amalgamate {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (x : ∀ I : S.Arrow, E ⟶ P.obj (op I.Y)) (hx : ∀ I : S.Relation, x I.fst ≫ P.map I.g₁.op = x I.snd ≫ P.map I.g₂.op) : E ⟶ P.obj (op X) := (hP _ _ S.condition).amalgamate (fun Y f hf => x ⟨Y, f, hf⟩) fun Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ w => hx ⟨Y₁, Y₂, Z, g₁, g₂, f₁, f₂, h₁, h₂, w⟩ #align category_theory.presheaf.is_sheaf.amalgamate CategoryTheory.Presheaf.IsSheaf.amalgamate @[reassoc (attr := simp)] theorem IsSheaf.amalgamate_map {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (x : ∀ I : S.Arrow, E ⟶ P.obj (op I.Y)) (hx : ∀ I : S.Relation, x I.fst ≫ P.map I.g₁.op = x I.snd ≫ P.map I.g₂.op) (I : S.Arrow) : hP.amalgamate S x hx ≫ P.map I.f.op = x _ := by rcases I with ⟨Y, f, hf⟩ apply @Presieve.IsSheafFor.valid_glue _ _ _ _ _ _ (hP _ _ S.condition) (fun Y f hf => x ⟨Y, f, hf⟩) (fun Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ w => hx ⟨Y₁, Y₂, Z, g₁, g₂, f₁, f₂, h₁, h₂, w⟩) f hf #align category_theory.presheaf.is_sheaf.amalgamate_map CategoryTheory.Presheaf.IsSheaf.amalgamate_map theorem IsSheaf.hom_ext {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (e₁ e₂ : E ⟶ P.obj (op X)) (h : ∀ I : S.Arrow, e₁ ≫ P.map I.f.op = e₂ ≫ P.map I.f.op) : e₁ = e₂ := (hP _ _ S.condition).isSeparatedFor.ext fun Y f hf => h ⟨Y, f, hf⟩ #align category_theory.presheaf.is_sheaf.hom_ext CategoryTheory.Presheaf.IsSheaf.hom_ext lemma IsSheaf.hom_ext_ofArrows {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) {I : Type*} {S : C} {X : I → C} (f : ∀ i, X i ⟶ S) (hf : Sieve.ofArrows _ f ∈ J S) {E : A} {x y : E ⟶ P.obj (op S)} (h : ∀ i, x ≫ P.map (f i).op = y ≫ P.map (f i).op) : x = y := by apply hP.hom_ext ⟨_, hf⟩ rintro ⟨Z, _, _, g, _, ⟨i⟩, rfl⟩ dsimp rw [P.map_comp, reassoc_of% (h i)] section variable {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) {I : Type*} {S : C} {X : I → C} (f : ∀ i, X i ⟶ S) (hf : Sieve.ofArrows _ f ∈ J S) {E : A} (x : ∀ i, E ⟶ P.obj (op (X i))) (hx : ∀ ⦃W : C⦄ ⦃i j : I⦄ (a : W ⟶ X i) (b : W ⟶ X j), a ≫ f i = b ≫ f j → x i ≫ P.map a.op = x j ≫ P.map b.op) lemma IsSheaf.exists_unique_amalgamation_ofArrows : ∃! (g : E ⟶ P.obj (op S)), ∀ (i : I), g ≫ P.map (f i).op = x i := (Presieve.isSheafFor_arrows_iff _ _).1 ((Presieve.isSheafFor_iff_generate _).2 (hP E _ hf)) x (fun _ _ _ _ _ w => hx _ _ w) /-- If `P : Cᵒᵖ ⥤ A` is a sheaf and `f i : X i ⟶ S` is a covering family, then a morphism `E ⟶ P.obj (op S)` can be constructed from a compatible family of morphisms `x : E ⟶ P.obj (op (X i))`. -/ def IsSheaf.amalgamateOfArrows : E ⟶ P.obj (op S) := (hP.exists_unique_amalgamation_ofArrows f hf x hx).choose @[reassoc (attr := simp)] lemma IsSheaf.amalgamateOfArrows_map (i : I) : hP.amalgamateOfArrows f hf x hx ≫ P.map (f i).op = x i := (hP.exists_unique_amalgamation_ofArrows f hf x hx).choose_spec.1 i end theorem isSheaf_of_iso_iff {P P' : Cᵒᵖ ⥤ A} (e : P ≅ P') : IsSheaf J P ↔ IsSheaf J P' := forall_congr' fun _ => ⟨Presieve.isSheaf_iso J (isoWhiskerRight e _), Presieve.isSheaf_iso J (isoWhiskerRight e.symm _)⟩ #align category_theory.presheaf.is_sheaf_of_iso_iff CategoryTheory.Presheaf.isSheaf_of_iso_iff variable (J) theorem isSheaf_of_isTerminal {X : A} (hX : IsTerminal X) : Presheaf.IsSheaf J ((CategoryTheory.Functor.const _).obj X) := fun _ _ _ _ _ _ => ⟨hX.from _, fun _ _ _ => hX.hom_ext _ _, fun _ _ => hX.hom_ext _ _⟩ #align category_theory.presheaf.is_sheaf_of_is_terminal CategoryTheory.Presheaf.isSheaf_of_isTerminal end Presheaf variable {C : Type u₁} [Category.{v₁} C] variable (J : GrothendieckTopology C) variable (A : Type u₂) [Category.{v₂} A] /-- The category of sheaves taking values in `A` on a grothendieck topology. -/ structure Sheaf where /-- the underlying presheaf -/ val : Cᵒᵖ ⥤ A /-- the condition that the presheaf is a sheaf -/ cond : Presheaf.IsSheaf J val set_option linter.uppercaseLean3 false in #align category_theory.Sheaf CategoryTheory.Sheaf namespace Sheaf variable {J A} /-- Morphisms between sheaves are just morphisms of presheaves. -/ @[ext] structure Hom (X Y : Sheaf J A) where /-- a morphism between the underlying presheaves -/ val : X.val ⟶ Y.val set_option linter.uppercaseLean3 false in #align category_theory.Sheaf.hom CategoryTheory.Sheaf.Hom @[simps id_val comp_val] instance instCategorySheaf : Category (Sheaf J A) where Hom := Hom id _ := ⟨𝟙 _⟩ comp f g := ⟨f.val ≫ g.val⟩ id_comp _ := Hom.ext _ _ <| id_comp _ comp_id _ := Hom.ext _ _ <| comp_id _ assoc _ _ _ := Hom.ext _ _ <| assoc _ _ _ -- Let's make the inhabited linter happy.../sips instance (X : Sheaf J A) : Inhabited (Hom X X) := ⟨𝟙 X⟩ -- Porting note: added because `Sheaf.Hom.ext` was not triggered automatically @[ext] lemma hom_ext {X Y : Sheaf J A} (x y : X ⟶ Y) (h : x.val = y.val) : x = y := Sheaf.Hom.ext _ _ h end Sheaf /-- The inclusion functor from sheaves to presheaves. -/ @[simps] def sheafToPresheaf : Sheaf J A ⥤ Cᵒᵖ ⥤ A where obj := Sheaf.val map f := f.val map_id _ := rfl map_comp _ _ := rfl set_option linter.uppercaseLean3 false in #align category_theory.Sheaf_to_presheaf CategoryTheory.sheafToPresheaf /-- The sections of a sheaf (i.e. evaluation as a presheaf on `C`). -/ abbrev sheafSections : Cᵒᵖ ⥤ Sheaf J A ⥤ A := (sheafToPresheaf J A).flip /-- The functor `Sheaf J A ⥤ Cᵒᵖ ⥤ A` is fully faithful. -/ @[simps] def fullyFaithfulSheafToPresheaf : (sheafToPresheaf J A).FullyFaithful where preimage f := ⟨f⟩ variable {J A} in /-- The bijection `(X ⟶ Y) ≃ (X.val ⟶ Y.val)` when `X` and `Y` are sheaves. -/ abbrev Sheaf.homEquiv {X Y : Sheaf J A} : (X ⟶ Y) ≃ (X.val ⟶ Y.val) := (fullyFaithfulSheafToPresheaf J A).homEquiv instance : (sheafToPresheaf J A).Full := (fullyFaithfulSheafToPresheaf J A).full instance : (sheafToPresheaf J A).Faithful := (fullyFaithfulSheafToPresheaf J A).faithful /-- This is stated as a lemma to prevent class search from forming a loop since a sheaf morphism is monic if and only if it is monic as a presheaf morphism (under suitable assumption). -/ theorem Sheaf.Hom.mono_of_presheaf_mono {F G : Sheaf J A} (f : F ⟶ G) [h : Mono f.1] : Mono f := (sheafToPresheaf J A).mono_of_mono_map h set_option linter.uppercaseLean3 false in #align category_theory.Sheaf.hom.mono_of_presheaf_mono CategoryTheory.Sheaf.Hom.mono_of_presheaf_mono instance Sheaf.Hom.epi_of_presheaf_epi {F G : Sheaf J A} (f : F ⟶ G) [h : Epi f.1] : Epi f := (sheafToPresheaf J A).epi_of_epi_map h set_option linter.uppercaseLean3 false in #align category_theory.Sheaf.hom.epi_of_presheaf_epi CategoryTheory.Sheaf.Hom.epi_of_presheaf_epi /-- The sheaf of sections guaranteed by the sheaf condition. -/ @[simps] def sheafOver {A : Type u₂} [Category.{v₂} A] {J : GrothendieckTopology C} (ℱ : Sheaf J A) (E : A) : SheafOfTypes J := ⟨ℱ.val ⋙ coyoneda.obj (op E), ℱ.cond E⟩ #align category_theory.sheaf_over CategoryTheory.sheafOver theorem isSheaf_iff_isSheaf_of_type (P : Cᵒᵖ ⥤ Type w) : Presheaf.IsSheaf J P ↔ Presieve.IsSheaf J P := by constructor · intro hP refine Presieve.isSheaf_iso J ?_ (hP PUnit) exact isoWhiskerLeft _ Coyoneda.punitIso ≪≫ P.rightUnitor · intro hP X Y S hS z hz refine ⟨fun x => (hP S hS).amalgamate (fun Z f hf => z f hf x) ?_, ?_, ?_⟩ · intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ h exact congr_fun (hz g₁ g₂ hf₁ hf₂ h) x · intro Z f hf funext x apply Presieve.IsSheafFor.valid_glue · intro y hy funext x apply (hP S hS).isSeparatedFor.ext intro Y' f hf rw [Presieve.IsSheafFor.valid_glue _ _ _ hf, ← hy _ hf] rfl #align category_theory.is_sheaf_iff_is_sheaf_of_type CategoryTheory.isSheaf_iff_isSheaf_of_type variable {J} in lemma Presheaf.IsSheaf.isSheafFor {P : Cᵒᵖ ⥤ Type w} (hP : Presheaf.IsSheaf J P) {X : C} (S : Sieve X) (hS : S ∈ J X) : Presieve.IsSheafFor P S.arrows := by rw [isSheaf_iff_isSheaf_of_type] at hP exact hP S hS /-- The category of sheaves taking values in Type is the same as the category of set-valued sheaves. -/ @[simps] def sheafEquivSheafOfTypes : Sheaf J (Type w) ≌ SheafOfTypes J where functor := { obj := fun S => ⟨S.val, (isSheaf_iff_isSheaf_of_type _ _).1 S.2⟩ map := fun f => ⟨f.val⟩ } inverse := { obj := fun S => ⟨S.val, (isSheaf_iff_isSheaf_of_type _ _).2 S.2⟩ map := fun f => ⟨f.val⟩ } unitIso := NatIso.ofComponents fun X => Iso.refl _ counitIso := NatIso.ofComponents fun X => Iso.refl _ set_option linter.uppercaseLean3 false in #align category_theory.Sheaf_equiv_SheafOfTypes CategoryTheory.sheafEquivSheafOfTypes instance : Inhabited (Sheaf (⊥ : GrothendieckTopology C) (Type w)) := ⟨(sheafEquivSheafOfTypes _).inverse.obj default⟩ variable {J} {A} /-- If the empty sieve is a cover of `X`, then `F(X)` is terminal. -/ def Sheaf.isTerminalOfBotCover (F : Sheaf J A) (X : C) (H : ⊥ ∈ J X) : IsTerminal (F.1.obj (op X)) := by refine @IsTerminal.ofUnique _ _ _ ?_ intro Y choose t h using F.2 Y _ H (by tauto) (by tauto) exact ⟨⟨t⟩, fun a => h.2 a (by tauto)⟩ set_option linter.uppercaseLean3 false in #align category_theory.Sheaf.is_terminal_of_bot_cover CategoryTheory.Sheaf.isTerminalOfBotCover section Preadditive open Preadditive variable [Preadditive A] {P Q : Sheaf J A} instance sheafHomHasZSMul : SMul ℤ (P ⟶ Q) where smul n f := Sheaf.Hom.mk { app := fun U => n • f.1.app U naturality := fun U V i => by induction' n using Int.induction_on with n ih n ih · simp only [zero_smul, comp_zero, zero_comp] · simpa only [add_zsmul, one_zsmul, comp_add, NatTrans.naturality, add_comp, add_left_inj] · simpa only [sub_smul, one_zsmul, comp_sub, NatTrans.naturality, sub_comp, sub_left_inj] using ih } set_option linter.uppercaseLean3 false in #align category_theory.Sheaf_hom_has_zsmul CategoryTheory.sheafHomHasZSMul instance : Sub (P ⟶ Q) where sub f g := Sheaf.Hom.mk <| f.1 - g.1 instance : Neg (P ⟶ Q) where neg f := Sheaf.Hom.mk <| -f.1 instance sheafHomHasNSMul : SMul ℕ (P ⟶ Q) where smul n f := Sheaf.Hom.mk { app := fun U => n • f.1.app U naturality := fun U V i => by induction' n with n ih · simp only [zero_smul, comp_zero, zero_comp, Nat.zero_eq] · simp only [Nat.succ_eq_add_one, add_smul, ih, one_nsmul, comp_add, NatTrans.naturality, add_comp] } set_option linter.uppercaseLean3 false in #align category_theory.Sheaf_hom_has_nsmul CategoryTheory.sheafHomHasNSMul instance : Zero (P ⟶ Q) where zero := Sheaf.Hom.mk 0 instance : Add (P ⟶ Q) where add f g := Sheaf.Hom.mk <| f.1 + g.1 @[simp] theorem Sheaf.Hom.add_app (f g : P ⟶ Q) (U) : (f + g).1.app U = f.1.app U + g.1.app U := rfl set_option linter.uppercaseLean3 false in #align category_theory.Sheaf.hom.add_app CategoryTheory.Sheaf.Hom.add_app instance Sheaf.Hom.addCommGroup : AddCommGroup (P ⟶ Q) := Function.Injective.addCommGroup (fun f : Sheaf.Hom P Q => f.1) (fun _ _ h => Sheaf.Hom.ext _ _ h) rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => by aesop_cat) (fun _ _ => by aesop_cat) instance : Preadditive (Sheaf J A) where homGroup P Q := Sheaf.Hom.addCommGroup end Preadditive end CategoryTheory namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presheaf -- Under here is the equalizer story, which is equivalent if A has products (and doesn't -- make sense otherwise). It's described in https://stacks.math.columbia.edu/tag/00VL, -- between 00VQ and 00VR. variable {C : Type u₁} [Category.{v₁} C] -- `A` is a general category; `A'` is a variant where the morphisms live in a large enough -- universe to guarantee that we can take limits in A of things coming from C. -- I would have liked to use something like `UnivLE.{max v₁ u₁, v₂}` as a hypothesis on -- `A`'s morphism universe rather than introducing `A'` but I can't get it to work. -- So, for now, results which need max v₁ u₁ ≤ v₂ are just stated for `A'` and `P' : Cᵒᵖ ⥤ A'` -- instead. variable {A : Type u₂} [Category.{v₂} A] variable {A' : Type u₂} [Category.{max v₁ u₁} A'] variable {B : Type u₃} [Category.{v₃} B] variable (J : GrothendieckTopology C) variable {U : C} (R : Presieve U) variable (P : Cᵒᵖ ⥤ A) (P' : Cᵒᵖ ⥤ A') section MultiequalizerConditions /-- When `P` is a sheaf and `S` is a cover, the associated multifork is a limit. -/ def isLimitOfIsSheaf {X : C} (S : J.Cover X) (hP : IsSheaf J P) : IsLimit (S.multifork P) where lift := fun E : Multifork _ => hP.amalgamate S (fun I => E.ι _) fun I => E.condition _ fac := by rintro (E : Multifork _) (a | b) · apply hP.amalgamate_map · rw [← E.w (WalkingMulticospan.Hom.fst b), ← (S.multifork P).w (WalkingMulticospan.Hom.fst b), ← assoc] congr 1 apply hP.amalgamate_map uniq := by rintro (E : Multifork _) m hm apply hP.hom_ext S intro I erw [hm (WalkingMulticospan.left I)] symm apply hP.amalgamate_map #align category_theory.presheaf.is_limit_of_is_sheaf CategoryTheory.Presheaf.isLimitOfIsSheaf theorem isSheaf_iff_multifork : IsSheaf J P ↔ ∀ (X : C) (S : J.Cover X), Nonempty (IsLimit (S.multifork P)) := by refine ⟨fun hP X S => ⟨isLimitOfIsSheaf _ _ _ hP⟩, ?_⟩ intro h E X S hS x hx let T : J.Cover X := ⟨S, hS⟩ obtain ⟨hh⟩ := h _ T let K : Multifork (T.index P) := Multifork.ofι _ E (fun I => x I.f I.hf) fun I => hx _ _ _ _ I.w use hh.lift K dsimp; constructor · intro Y f hf apply hh.fac K (WalkingMulticospan.left ⟨Y, f, hf⟩) · intro e he apply hh.uniq K rintro (a | b) · apply he · rw [← K.w (WalkingMulticospan.Hom.fst b), ← (T.multifork P).w (WalkingMulticospan.Hom.fst b), ← assoc] congr 1 apply he #align category_theory.presheaf.is_sheaf_iff_multifork CategoryTheory.Presheaf.isSheaf_iff_multifork theorem isSheaf_iff_multiequalizer [∀ (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] : IsSheaf J P ↔ ∀ (X : C) (S : J.Cover X), IsIso (S.toMultiequalizer P) := by rw [isSheaf_iff_multifork] refine forall₂_congr fun X S => ⟨?_, ?_⟩ · rintro ⟨h⟩ let e : P.obj (op X) ≅ multiequalizer (S.index P) := h.conePointUniqueUpToIso (limit.isLimit _) exact (inferInstance : IsIso e.hom) · intro h refine ⟨IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext ?_ ?_)⟩ · apply (@asIso _ _ _ _ _ h).symm · intro a symm erw [IsIso.inv_comp_eq] dsimp simp #align category_theory.presheaf.is_sheaf_iff_multiequalizer CategoryTheory.Presheaf.isSheaf_iff_multiequalizer end MultiequalizerConditions section variable [HasProducts.{max u₁ v₁} A] variable [HasProducts.{max u₁ v₁} A'] /-- The middle object of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of <https://stacks.math.columbia.edu/tag/00VM>. -/ def firstObj : A := ∏ᶜ fun f : ΣV, { f : V ⟶ U // R f } => P.obj (op f.1) #align category_theory.presheaf.first_obj CategoryTheory.Presheaf.firstObj /-- The left morphism of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of <https://stacks.math.columbia.edu/tag/00VM>. -/ def forkMap : P.obj (op U) ⟶ firstObj R P := Pi.lift fun f => P.map f.2.1.op #align category_theory.presheaf.fork_map CategoryTheory.Presheaf.forkMap variable [HasPullbacks C] /-- The rightmost object of the fork diagram of https://stacks.math.columbia.edu/tag/00VM, which contains the data used to check a family of elements for a presieve is compatible. -/ def secondObj : A := ∏ᶜ fun fg : (ΣV, { f : V ⟶ U // R f }) × ΣW, { g : W ⟶ U // R g } => P.obj (op (pullback fg.1.2.1 fg.2.2.1)) #align category_theory.presheaf.second_obj CategoryTheory.Presheaf.secondObj /-- The map `pr₀*` of <https://stacks.math.columbia.edu/tag/00VM>. -/ def firstMap : firstObj R P ⟶ secondObj R P := Pi.lift fun _ => Pi.π _ _ ≫ P.map pullback.fst.op #align category_theory.presheaf.first_map CategoryTheory.Presheaf.firstMap /-- The map `pr₁*` of <https://stacks.math.columbia.edu/tag/00VM>. -/ def secondMap : firstObj R P ⟶ secondObj R P := Pi.lift fun _ => Pi.π _ _ ≫ P.map pullback.snd.op #align category_theory.presheaf.second_map CategoryTheory.Presheaf.secondMap theorem w : forkMap R P ≫ firstMap R P = forkMap R P ≫ secondMap R P := by apply limit.hom_ext rintro ⟨⟨Y, f, hf⟩, ⟨Z, g, hg⟩⟩ simp only [firstMap, secondMap, forkMap, limit.lift_π, limit.lift_π_assoc, assoc, Fan.mk_π_app, Subtype.coe_mk] rw [← P.map_comp, ← op_comp, pullback.condition] simp #align category_theory.presheaf.w CategoryTheory.Presheaf.w /-- An alternative definition of the sheaf condition in terms of equalizers. This is shown to be equivalent in `CategoryTheory.Presheaf.isSheaf_iff_isSheaf'`. -/ def IsSheaf' (P : Cᵒᵖ ⥤ A) : Prop := ∀ (U : C) (R : Presieve U) (_ : generate R ∈ J U), Nonempty (IsLimit (Fork.ofι _ (w R P))) #align category_theory.presheaf.is_sheaf' CategoryTheory.Presheaf.IsSheaf' -- Again I wonder whether `UnivLE` can somehow be used to allow `s` to take -- values in a more general universe. /-- (Implementation). An auxiliary lemma to convert between sheaf conditions. -/ def isSheafForIsSheafFor' (P : Cᵒᵖ ⥤ A) (s : A ⥤ Type max v₁ u₁) [∀ J, PreservesLimitsOfShape (Discrete.{max v₁ u₁} J) s] (U : C) (R : Presieve U) : IsLimit (s.mapCone (Fork.ofι _ (w R P))) ≃ IsLimit (Fork.ofι _ (Equalizer.Presieve.w (P ⋙ s) R)) := by apply Equiv.trans (isLimitMapConeForkEquiv _ _) _ apply (IsLimit.postcomposeHomEquiv _ _).symm.trans (IsLimit.equivIsoLimit _) · apply NatIso.ofComponents _ _ · rintro (_ | _) · apply PreservesProduct.iso s · apply PreservesProduct.iso s · rintro _ _ (_ | _) · refine limit.hom_ext (fun j => ?_) dsimp [Equalizer.Presieve.firstMap, firstMap] simp only [limit.lift_π, map_lift_piComparison, assoc, Fan.mk_π_app, Functor.map_comp] rw [piComparison_comp_π_assoc] · refine limit.hom_ext (fun j => ?_) dsimp [Equalizer.Presieve.secondMap, secondMap] simp only [limit.lift_π, map_lift_piComparison, assoc, Fan.mk_π_app, Functor.map_comp] rw [piComparison_comp_π_assoc] · dsimp simp · refine Fork.ext (Iso.refl _) ?_ dsimp [Equalizer.forkMap, forkMap] simp [Fork.ι] #align category_theory.presheaf.is_sheaf_for_is_sheaf_for' CategoryTheory.Presheaf.isSheafForIsSheafFor' -- Remark : this lemma uses `A'` not `A`; `A'` is `A` but with a universe -- restriction. Can it be generalised? /-- The equalizer definition of a sheaf given by `isSheaf'` is equivalent to `isSheaf`. -/ theorem isSheaf_iff_isSheaf' : IsSheaf J P' ↔ IsSheaf' J P' := by constructor · intro h U R hR refine ⟨?_⟩ apply coyonedaJointlyReflectsLimits intro X have q : Presieve.IsSheafFor (P' ⋙ coyoneda.obj X) _ := h X.unop _ hR rw [← Presieve.isSheafFor_iff_generate] at q rw [Equalizer.Presieve.sheaf_condition] at q replace q := Classical.choice q apply (isSheafForIsSheafFor' _ _ _ _).symm q · intro h U X S hS rw [Equalizer.Presieve.sheaf_condition] refine ⟨?_⟩ refine isSheafForIsSheafFor' _ _ _ _ ?_ letI := preservesSmallestLimitsOfPreservesLimits (coyoneda.obj (op U)) apply isLimitOfPreserves apply Classical.choice (h _ S.arrows _) simpa #align category_theory.presheaf.is_sheaf_iff_is_sheaf' CategoryTheory.Presheaf.isSheaf_iff_isSheaf' end section Concrete
Mathlib/CategoryTheory/Sites/Sheaf.lean
723
726
theorem isSheaf_of_isSheaf_comp (s : A ⥤ B) [ReflectsLimitsOfSize.{v₁, max v₁ u₁} s] (h : IsSheaf J (P ⋙ s)) : IsSheaf J P := by
rw [isSheaf_iff_isLimit] at h ⊢ exact fun X S hS ↦ (h S hS).map fun t ↦ isLimitOfReflects s t
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Data.NNRat.Defs /-! # Casting lemmas for non-negative rational numbers involving sums and products -/ variable {ι α : Type*} namespace NNRat @[norm_cast] theorem coe_list_sum (l : List ℚ≥0) : (l.sum : ℚ) = (l.map (↑)).sum := map_list_sum coeHom _ #align nnrat.coe_list_sum NNRat.coe_list_sum @[norm_cast] theorem coe_list_prod (l : List ℚ≥0) : (l.prod : ℚ) = (l.map (↑)).prod := map_list_prod coeHom _ #align nnrat.coe_list_prod NNRat.coe_list_prod @[norm_cast] theorem coe_multiset_sum (s : Multiset ℚ≥0) : (s.sum : ℚ) = (s.map (↑)).sum := map_multiset_sum coeHom _ #align nnrat.coe_multiset_sum NNRat.coe_multiset_sum @[norm_cast] theorem coe_multiset_prod (s : Multiset ℚ≥0) : (s.prod : ℚ) = (s.map (↑)).prod := map_multiset_prod coeHom _ #align nnrat.coe_multiset_prod NNRat.coe_multiset_prod @[norm_cast] theorem coe_sum {s : Finset α} {f : α → ℚ≥0} : ↑(∑ a ∈ s, f a) = ∑ a ∈ s, (f a : ℚ) := map_sum coeHom _ _ #align nnrat.coe_sum NNRat.coe_sum theorem toNNRat_sum_of_nonneg {s : Finset α} {f : α → ℚ} (hf : ∀ a, a ∈ s → 0 ≤ f a) : (∑ a ∈ s, f a).toNNRat = ∑ a ∈ s, (f a).toNNRat := by rw [← coe_inj, coe_sum, Rat.coe_toNNRat _ (Finset.sum_nonneg hf)] exact Finset.sum_congr rfl fun x hxs ↦ by rw [Rat.coe_toNNRat _ (hf x hxs)] #align nnrat.to_nnrat_sum_of_nonneg NNRat.toNNRat_sum_of_nonneg @[norm_cast] theorem coe_prod {s : Finset α} {f : α → ℚ≥0} : ↑(∏ a ∈ s, f a) = ∏ a ∈ s, (f a : ℚ) := map_prod coeHom _ _ #align nnrat.coe_prod NNRat.coe_prod
Mathlib/Data/NNRat/BigOperators.lean
52
55
theorem toNNRat_prod_of_nonneg {s : Finset α} {f : α → ℚ} (hf : ∀ a ∈ s, 0 ≤ f a) : (∏ a ∈ s, f a).toNNRat = ∏ a ∈ s, (f a).toNNRat := by
rw [← coe_inj, coe_prod, Rat.coe_toNNRat _ (Finset.prod_nonneg hf)] exact Finset.prod_congr rfl fun x hxs ↦ by rw [Rat.coe_toNNRat _ (hf x hxs)]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Set.Finite import Mathlib.Data.Countable.Basic import Mathlib.Logic.Equiv.List import Mathlib.Data.Set.Subsingleton #align_import data.set.countable from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # Countable sets In this file we define `Set.Countable s` as `Countable s` and prove basic properties of this definition. Note that this definition does not provide a computable encoding. For a noncomputable conversion to `Encodable s`, use `Set.Countable.nonempty_encodable`. ## Keywords sets, countable set -/ noncomputable section open scoped Classical open Function Set Encodable universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} namespace Set /-- A set `s` is countable if the corresponding subtype is countable, i.e., there exists an injective map `f : s → ℕ`. Note that this is an abbreviation, so `hs : Set.Countable s` in the proof context is the same as an instance `Countable s`. For a constructive version, see `Encodable`. -/ protected def Countable (s : Set α) : Prop := Countable s #align set.countable Set.Countable @[simp] theorem countable_coe_iff {s : Set α} : Countable s ↔ s.Countable := .rfl #align set.countable_coe_iff Set.countable_coe_iff /-- Prove `Set.Countable` from a `Countable` instance on the subtype. -/ theorem to_countable (s : Set α) [Countable s] : s.Countable := ‹_› #align set.to_countable Set.to_countable /-- Restate `Set.Countable` as a `Countable` instance. -/ alias ⟨_root_.Countable.to_set, Countable.to_subtype⟩ := countable_coe_iff #align countable.to_set Countable.to_set #align set.countable.to_subtype Set.Countable.to_subtype protected theorem countable_iff_exists_injective {s : Set α} : s.Countable ↔ ∃ f : s → ℕ, Injective f := countable_iff_exists_injective s #align set.countable_iff_exists_injective Set.countable_iff_exists_injective /-- A set `s : Set α` is countable if and only if there exists a function `α → ℕ` injective on `s`. -/ theorem countable_iff_exists_injOn {s : Set α} : s.Countable ↔ ∃ f : α → ℕ, InjOn f s := Set.countable_iff_exists_injective.trans exists_injOn_iff_injective.symm #align set.countable_iff_exists_inj_on Set.countable_iff_exists_injOn theorem countable_iff_nonempty_encodable {s : Set α} : s.Countable ↔ Nonempty (Encodable s) := Encodable.nonempty_encodable.symm alias ⟨Countable.nonempty_encodable, _⟩ := countable_iff_nonempty_encodable /-- Convert `Set.Countable s` to `Encodable s` (noncomputable). -/ protected def Countable.toEncodable {s : Set α} (hs : s.Countable) : Encodable s := Classical.choice hs.nonempty_encodable #align set.countable.to_encodable Set.Countable.toEncodable section Enumerate /-- Noncomputably enumerate elements in a set. The `default` value is used to extend the domain to all of `ℕ`. -/ def enumerateCountable {s : Set α} (h : s.Countable) (default : α) : ℕ → α := fun n => match @Encodable.decode s h.toEncodable n with | some y => y | none => default #align set.enumerate_countable Set.enumerateCountable theorem subset_range_enumerate {s : Set α} (h : s.Countable) (default : α) : s ⊆ range (enumerateCountable h default) := fun x hx => ⟨@Encodable.encode s h.toEncodable ⟨x, hx⟩, by letI := h.toEncodable simp [enumerateCountable, Encodable.encodek]⟩ #align set.subset_range_enumerate Set.subset_range_enumerate lemma range_enumerateCountable_subset {s : Set α} (h : s.Countable) (default : α) : range (enumerateCountable h default) ⊆ insert default s := by refine range_subset_iff.mpr (fun n ↦ ?_) rw [enumerateCountable] match @decode s (Countable.toEncodable h) n with | none => exact mem_insert _ _ | some val => simp lemma range_enumerateCountable_of_mem {s : Set α} (h : s.Countable) {default : α} (h_mem : default ∈ s) : range (enumerateCountable h default) = s := subset_antisymm ((range_enumerateCountable_subset h _).trans_eq (insert_eq_of_mem h_mem)) (subset_range_enumerate h default) lemma enumerateCountable_mem {s : Set α} (h : s.Countable) {default : α} (h_mem : default ∈ s) (n : ℕ) : enumerateCountable h default n ∈ s := by conv_rhs => rw [← range_enumerateCountable_of_mem h h_mem] exact mem_range_self n end Enumerate theorem Countable.mono {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) (hs : s₂.Countable) : s₁.Countable := have := hs.to_subtype; (inclusion_injective h).countable #align set.countable.mono Set.Countable.mono theorem countable_range [Countable ι] (f : ι → β) : (range f).Countable := surjective_onto_range.countable.to_set #align set.countable_range Set.countable_range theorem countable_iff_exists_subset_range [Nonempty α] {s : Set α} : s.Countable ↔ ∃ f : ℕ → α, s ⊆ range f := ⟨fun h => by inhabit α exact ⟨enumerateCountable h default, subset_range_enumerate _ _⟩, fun ⟨f, hsf⟩ => (countable_range f).mono hsf⟩ #align set.countable_iff_exists_subset_range Set.countable_iff_exists_subset_range /-- A non-empty set is countable iff there exists a surjection from the natural numbers onto the subtype induced by the set. -/ protected theorem countable_iff_exists_surjective {s : Set α} (hs : s.Nonempty) : s.Countable ↔ ∃ f : ℕ → s, Surjective f := @countable_iff_exists_surjective s hs.to_subtype #align set.countable_iff_exists_surjective Set.countable_iff_exists_surjective alias ⟨Countable.exists_surjective, _⟩ := Set.countable_iff_exists_surjective #align set.countable.exists_surjective Set.Countable.exists_surjective theorem countable_univ [Countable α] : (univ : Set α).Countable := to_countable univ #align set.countable_univ Set.countable_univ theorem countable_univ_iff : (univ : Set α).Countable ↔ Countable α := countable_coe_iff.symm.trans (Equiv.Set.univ _).countable_iff /-- If `s : Set α` is a nonempty countable set, then there exists a map `f : ℕ → α` such that `s = range f`. -/ theorem Countable.exists_eq_range {s : Set α} (hc : s.Countable) (hs : s.Nonempty) : ∃ f : ℕ → α, s = range f := by rcases hc.exists_surjective hs with ⟨f, hf⟩ refine ⟨(↑) ∘ f, ?_⟩ rw [hf.range_comp, Subtype.range_coe] #align set.countable.exists_eq_range Set.Countable.exists_eq_range @[simp] theorem countable_empty : (∅ : Set α).Countable := to_countable _ #align set.countable_empty Set.countable_empty @[simp] theorem countable_singleton (a : α) : ({a} : Set α).Countable := to_countable _ #align set.countable_singleton Set.countable_singleton theorem Countable.image {s : Set α} (hs : s.Countable) (f : α → β) : (f '' s).Countable := by rw [image_eq_range] have := hs.to_subtype apply countable_range #align set.countable.image Set.Countable.image theorem MapsTo.countable_of_injOn {s : Set α} {t : Set β} {f : α → β} (hf : MapsTo f s t) (hf' : InjOn f s) (ht : t.Countable) : s.Countable := have := ht.to_subtype have : Injective (hf.restrict f s t) := (injOn_iff_injective.1 hf').codRestrict _ this.countable #align set.maps_to.countable_of_inj_on Set.MapsTo.countable_of_injOn theorem Countable.preimage_of_injOn {s : Set β} (hs : s.Countable) {f : α → β} (hf : InjOn f (f ⁻¹' s)) : (f ⁻¹' s).Countable := (mapsTo_preimage f s).countable_of_injOn hf hs #align set.countable.preimage_of_inj_on Set.Countable.preimage_of_injOn protected theorem Countable.preimage {s : Set β} (hs : s.Countable) {f : α → β} (hf : Injective f) : (f ⁻¹' s).Countable := hs.preimage_of_injOn hf.injOn #align set.countable.preimage Set.Countable.preimage theorem exists_seq_iSup_eq_top_iff_countable [CompleteLattice α] {p : α → Prop} (h : ∃ x, p x) : (∃ s : ℕ → α, (∀ n, p (s n)) ∧ ⨆ n, s n = ⊤) ↔ ∃ S : Set α, S.Countable ∧ (∀ s ∈ S, p s) ∧ sSup S = ⊤ := by constructor · rintro ⟨s, hps, hs⟩ refine ⟨range s, countable_range s, forall_mem_range.2 hps, ?_⟩ rwa [sSup_range] · rintro ⟨S, hSc, hps, hS⟩ rcases eq_empty_or_nonempty S with (rfl | hne) · rw [sSup_empty] at hS haveI := subsingleton_of_bot_eq_top hS rcases h with ⟨x, hx⟩ exact ⟨fun _ => x, fun _ => hx, Subsingleton.elim _ _⟩ · rcases (Set.countable_iff_exists_surjective hne).1 hSc with ⟨s, hs⟩ refine ⟨fun n => s n, fun n => hps _ (s n).coe_prop, ?_⟩ rwa [hs.iSup_comp, ← sSup_eq_iSup'] #align set.exists_seq_supr_eq_top_iff_countable Set.exists_seq_iSup_eq_top_iff_countable theorem exists_seq_cover_iff_countable {p : Set α → Prop} (h : ∃ s, p s) : (∃ s : ℕ → Set α, (∀ n, p (s n)) ∧ ⋃ n, s n = univ) ↔ ∃ S : Set (Set α), S.Countable ∧ (∀ s ∈ S, p s) ∧ ⋃₀ S = univ := exists_seq_iSup_eq_top_iff_countable h #align set.exists_seq_cover_iff_countable Set.exists_seq_cover_iff_countable theorem countable_of_injective_of_countable_image {s : Set α} {f : α → β} (hf : InjOn f s) (hs : (f '' s).Countable) : s.Countable := (mapsTo_image _ _).countable_of_injOn hf hs #align set.countable_of_injective_of_countable_image Set.countable_of_injective_of_countable_image theorem countable_iUnion {t : ι → Set α} [Countable ι] (ht : ∀ i, (t i).Countable) : (⋃ i, t i).Countable := by have := fun i ↦ (ht i).to_subtype rw [iUnion_eq_range_psigma] apply countable_range #align set.countable_Union Set.countable_iUnion @[simp] theorem countable_iUnion_iff [Countable ι] {t : ι → Set α} : (⋃ i, t i).Countable ↔ ∀ i, (t i).Countable := ⟨fun h _ => h.mono <| subset_iUnion _ _, countable_iUnion⟩ #align set.countable_Union_iff Set.countable_iUnion_iff theorem Countable.biUnion_iff {s : Set α} {t : ∀ a ∈ s, Set β} (hs : s.Countable) : (⋃ a ∈ s, t a ‹_›).Countable ↔ ∀ a (ha : a ∈ s), (t a ha).Countable := by have := hs.to_subtype rw [biUnion_eq_iUnion, countable_iUnion_iff, SetCoe.forall'] #align set.countable.bUnion_iff Set.Countable.biUnion_iff
Mathlib/Data/Set/Countable.lean
241
242
theorem Countable.sUnion_iff {s : Set (Set α)} (hs : s.Countable) : (⋃₀ s).Countable ↔ ∀ a ∈ s, a.Countable := by
rw [sUnion_eq_biUnion, hs.biUnion_iff]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Defs import Mathlib.Data.Int.Defs import Mathlib.Logic.Function.Basic import Mathlib.Tactic.Cases import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs #align_import algebra.group.basic from "leanprover-community/mathlib"@"a07d750983b94c530ab69a726862c2ab6802b38c" /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered open Function universe u variable {α β G M : Type*} section ite variable [Pow α β] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section IsLeftCancelMul variable [Mul G] [IsLeftCancelMul G] @[to_additive] theorem mul_right_injective (a : G) : Injective (a * ·) := fun _ _ ↦ mul_left_cancel #align mul_right_injective mul_right_injective #align add_right_injective add_right_injective @[to_additive (attr := simp)] theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c := (mul_right_injective a).eq_iff #align mul_right_inj mul_right_inj #align add_right_inj add_right_inj @[to_additive] theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c := (mul_right_injective a).ne_iff #align mul_ne_mul_right mul_ne_mul_right #align add_ne_add_right add_ne_add_right end IsLeftCancelMul section IsRightCancelMul variable [Mul G] [IsRightCancelMul G] @[to_additive] theorem mul_left_injective (a : G) : Function.Injective (· * a) := fun _ _ ↦ mul_right_cancel #align mul_left_injective mul_left_injective #align add_left_injective add_left_injective @[to_additive (attr := simp)] theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c := (mul_left_injective a).eq_iff #align mul_left_inj mul_left_inj #align add_left_inj add_left_inj @[to_additive] theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c := (mul_left_injective a).ne_iff #align mul_ne_mul_left mul_ne_mul_left #align add_ne_add_left add_ne_add_left end IsRightCancelMul section Semigroup variable [Semigroup α] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩ #align semigroup.to_is_associative Semigroup.to_isAssociative #align add_semigroup.to_is_associative AddSemigroup.to_isAssociative /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by ext z simp [mul_assoc] #align comp_mul_left comp_mul_left #align comp_add_left comp_add_left /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by ext z simp [mul_assoc] #align comp_mul_right comp_mul_right #align comp_add_right comp_add_right end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩ #align comm_semigroup.to_is_commutative CommMagma.to_isCommutative #align add_comm_semigroup.to_is_commutative AddCommMagma.to_isCommutative section MulOneClass variable {M : Type u} [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h:P <;> simp [h] #align ite_mul_one ite_mul_one #align ite_add_zero ite_add_zero @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h:P <;> simp [h] #align ite_one_mul ite_one_mul #align ite_zero_add ite_zero_add @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) #align eq_one_iff_eq_one_of_mul_eq_one eq_one_iff_eq_one_of_mul_eq_one #align eq_zero_iff_eq_zero_of_add_eq_zero eq_zero_iff_eq_zero_of_add_eq_zero @[to_additive] theorem one_mul_eq_id : ((1 : M) * ·) = id := funext one_mul #align one_mul_eq_id one_mul_eq_id #align zero_add_eq_id zero_add_eq_id @[to_additive] theorem mul_one_eq_id : (· * (1 : M)) = id := funext mul_one #align mul_one_eq_id mul_one_eq_id #align add_zero_eq_id add_zero_eq_id end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm : ∀ a b c : G, a * (b * c) = b * (a * c) := left_comm Mul.mul mul_comm mul_assoc #align mul_left_comm mul_left_comm #align add_left_comm add_left_comm @[to_additive] theorem mul_right_comm : ∀ a b c : G, a * b * c = a * c * b := right_comm Mul.mul mul_comm mul_assoc #align mul_right_comm mul_right_comm #align add_right_comm add_right_comm @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] #align mul_mul_mul_comm mul_mul_mul_comm #align add_add_add_comm add_add_add_comm @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] #align mul_rotate mul_rotate #align add_rotate add_rotate @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] #align mul_rotate' mul_rotate' #align add_rotate' add_rotate' end CommSemigroup section AddCommSemigroup set_option linter.deprecated false variable {M : Type u} [AddCommSemigroup M] theorem bit0_add (a b : M) : bit0 (a + b) = bit0 a + bit0 b := add_add_add_comm _ _ _ _ #align bit0_add bit0_add theorem bit1_add [One M] (a b : M) : bit1 (a + b) = bit0 a + bit1 b := (congr_arg (· + (1 : M)) <| bit0_add a b : _).trans (add_assoc _ _ _) #align bit1_add bit1_add theorem bit1_add' [One M] (a b : M) : bit1 (a + b) = bit1 a + bit0 b := by rw [add_comm, bit1_add, add_comm] #align bit1_add' bit1_add' end AddCommSemigroup section AddMonoid set_option linter.deprecated false variable {M : Type u} [AddMonoid M] {a b c : M} @[simp] theorem bit0_zero : bit0 (0 : M) = 0 := add_zero _ #align bit0_zero bit0_zero @[simp] theorem bit1_zero [One M] : bit1 (0 : M) = 1 := by rw [bit1, bit0_zero, zero_add] #align bit1_zero bit1_zero end AddMonoid attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b c : M} {m n : ℕ} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] #align pow_boole pow_boole @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] #align pow_mul_pow_sub pow_mul_pow_sub #align nsmul_add_sub_nsmul nsmul_add_sub_nsmul @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] #align pow_sub_mul_pow pow_sub_mul_pow #align sub_nsmul_nsmul_add sub_nsmul_nsmul_add @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel $ Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel $ Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"] lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] #align pow_eq_pow_mod pow_eq_pow_mod #align nsmul_eq_mod_nsmul nsmul_eq_mod_nsmul @[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] #align pow_mul_pow_eq_one pow_mul_pow_eq_one #align nsmul_add_nsmul_eq_zero nsmul_add_nsmul_eq_zero end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz #align inv_unique inv_unique #align neg_unique neg_unique @[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] #align mul_pow mul_pow #align nsmul_add nsmul_add end CommMonoid section LeftCancelMonoid variable {M : Type u} [LeftCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_right_eq_self : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff #align mul_right_eq_self mul_right_eq_self #align add_right_eq_self add_right_eq_self @[to_additive (attr := simp)] theorem self_eq_mul_right : a = a * b ↔ b = 1 := eq_comm.trans mul_right_eq_self #align self_eq_mul_right self_eq_mul_right #align self_eq_add_right self_eq_add_right @[to_additive] theorem mul_right_ne_self : a * b ≠ a ↔ b ≠ 1 := mul_right_eq_self.not #align mul_right_ne_self mul_right_ne_self #align add_right_ne_self add_right_ne_self @[to_additive] theorem self_ne_mul_right : a ≠ a * b ↔ b ≠ 1 := self_eq_mul_right.not #align self_ne_mul_right self_ne_mul_right #align self_ne_add_right self_ne_add_right end LeftCancelMonoid section RightCancelMonoid variable {M : Type u} [RightCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_left_eq_self : a * b = b ↔ a = 1 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 := mul_right_cancel_iff #align mul_left_eq_self mul_left_eq_self #align add_left_eq_self add_left_eq_self @[to_additive (attr := simp)] theorem self_eq_mul_left : b = a * b ↔ a = 1 := eq_comm.trans mul_left_eq_self #align self_eq_mul_left self_eq_mul_left #align self_eq_add_left self_eq_add_left @[to_additive] theorem mul_left_ne_self : a * b ≠ b ↔ a ≠ 1 := mul_left_eq_self.not #align mul_left_ne_self mul_left_ne_self #align add_left_ne_self add_left_ne_self @[to_additive] theorem self_ne_mul_left : b ≠ a * b ↔ a ≠ 1 := self_eq_mul_left.not #align self_ne_mul_left self_ne_mul_left #align self_ne_add_left self_ne_add_left end RightCancelMonoid section CancelCommMonoid variable [CancelCommMonoid α] {a b c d : α} @[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop @[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop end CancelCommMonoid section InvolutiveInv variable [InvolutiveInv G] {a b : G} @[to_additive (attr := simp)] theorem inv_involutive : Function.Involutive (Inv.inv : G → G) := inv_inv #align inv_involutive inv_involutive #align neg_involutive neg_involutive @[to_additive (attr := simp)] theorem inv_surjective : Function.Surjective (Inv.inv : G → G) := inv_involutive.surjective #align inv_surjective inv_surjective #align neg_surjective neg_surjective @[to_additive] theorem inv_injective : Function.Injective (Inv.inv : G → G) := inv_involutive.injective #align inv_injective inv_injective #align neg_injective neg_injective @[to_additive (attr := simp)] theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b := inv_injective.eq_iff #align inv_inj inv_inj #align neg_inj neg_inj @[to_additive] theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ := ⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩ #align inv_eq_iff_eq_inv inv_eq_iff_eq_inv #align neg_eq_iff_eq_neg neg_eq_iff_eq_neg variable (G) @[to_additive] theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G := inv_involutive.comp_self #align inv_comp_inv inv_comp_inv #align neg_comp_neg neg_comp_neg @[to_additive] theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv #align left_inverse_inv leftInverse_inv #align left_inverse_neg leftInverse_neg @[to_additive] theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv #align right_inverse_inv rightInverse_inv #align right_inverse_neg rightInverse_neg end InvolutiveInv section DivInvMonoid variable [DivInvMonoid G] {a b c : G} @[to_additive, field_simps] -- The attributes are out of order on purpose theorem inv_eq_one_div (x : G) : x⁻¹ = 1 / x := by rw [div_eq_mul_inv, one_mul] #align inv_eq_one_div inv_eq_one_div #align neg_eq_zero_sub neg_eq_zero_sub @[to_additive] theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by rw [div_eq_mul_inv, one_mul, div_eq_mul_inv] #align mul_one_div mul_one_div #align add_zero_sub add_zero_sub @[to_additive] theorem mul_div_assoc (a b c : G) : a * b / c = a * (b / c) := by rw [div_eq_mul_inv, div_eq_mul_inv, mul_assoc _ _ _] #align mul_div_assoc mul_div_assoc #align add_sub_assoc add_sub_assoc @[to_additive, field_simps] -- The attributes are out of order on purpose theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c := (mul_div_assoc _ _ _).symm #align mul_div_assoc' mul_div_assoc' #align add_sub_assoc' add_sub_assoc' @[to_additive (attr := simp)] theorem one_div (a : G) : 1 / a = a⁻¹ := (inv_eq_one_div a).symm #align one_div one_div #align zero_sub zero_sub @[to_additive] theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv] #align mul_div mul_div #align add_sub add_sub @[to_additive] theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div] #align div_eq_mul_one_div div_eq_mul_one_div #align sub_eq_add_zero_sub sub_eq_add_zero_sub end DivInvMonoid section DivInvOneMonoid variable [DivInvOneMonoid G] @[to_additive (attr := simp)] theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv] #align div_one div_one #align sub_zero sub_zero @[to_additive] theorem one_div_one : (1 : G) / 1 = 1 := div_one _ #align one_div_one one_div_one #align zero_sub_zero zero_sub_zero end DivInvOneMonoid section DivisionMonoid variable [DivisionMonoid α] {a b c d : α} attribute [local simp] mul_assoc div_eq_mul_inv @[to_additive] theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ := (inv_eq_of_mul_eq_one_right h).symm #align eq_inv_of_mul_eq_one_right eq_inv_of_mul_eq_one_right #align eq_neg_of_add_eq_zero_right eq_neg_of_add_eq_zero_right @[to_additive] theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_left h, one_div] #align eq_one_div_of_mul_eq_one_left eq_one_div_of_mul_eq_one_left #align eq_zero_sub_of_add_eq_zero_left eq_zero_sub_of_add_eq_zero_left @[to_additive] theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_right h, one_div] #align eq_one_div_of_mul_eq_one_right eq_one_div_of_mul_eq_one_right #align eq_zero_sub_of_add_eq_zero_right eq_zero_sub_of_add_eq_zero_right @[to_additive] theorem eq_of_div_eq_one (h : a / b = 1) : a = b := inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv] #align eq_of_div_eq_one eq_of_div_eq_one #align eq_of_sub_eq_zero eq_of_sub_eq_zero lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 := mt eq_of_div_eq_one #align div_ne_one_of_ne div_ne_one_of_ne #align sub_ne_zero_of_ne sub_ne_zero_of_ne variable (a b c) @[to_additive] theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp #align one_div_mul_one_div_rev one_div_mul_one_div_rev #align zero_sub_add_zero_sub_rev zero_sub_add_zero_sub_rev @[to_additive] theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp #align inv_div_left inv_div_left #align neg_sub_left neg_sub_left @[to_additive (attr := simp)] theorem inv_div : (a / b)⁻¹ = b / a := by simp #align inv_div inv_div #align neg_sub neg_sub @[to_additive] theorem one_div_div : 1 / (a / b) = b / a := by simp #align one_div_div one_div_div #align zero_sub_sub zero_sub_sub @[to_additive] theorem one_div_one_div : 1 / (1 / a) = a := by simp #align one_div_one_div one_div_one_div #align zero_sub_zero_sub zero_sub_zero_sub @[to_additive] theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c := inv_inj.symm.trans <| by simp only [inv_div] @[to_additive SubtractionMonoid.toSubNegZeroMonoid] instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α := { DivisionMonoid.toDivInvMonoid with inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm } @[to_additive (attr := simp)] lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹ | 0 => by rw [pow_zero, pow_zero, inv_one] | n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev] #align inv_pow inv_pow #align neg_nsmul neg_nsmul -- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`. @[to_additive zsmul_zero, simp] lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | .negSucc n => by rw [zpow_negSucc, one_pow, inv_one] #align one_zpow one_zpow #align zsmul_zero zsmul_zero @[to_additive (attr := simp) neg_zsmul] lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹ | (n + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _ | 0 => by change a ^ (0 : ℤ) = (a ^ (0 : ℤ))⁻¹ simp | Int.negSucc n => by rw [zpow_negSucc, inv_inv, ← zpow_natCast] rfl #align zpow_neg zpow_neg #align neg_zsmul neg_zsmul @[to_additive neg_one_zsmul_add] lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by simp only [zpow_neg, zpow_one, mul_inv_rev] #align mul_zpow_neg_one mul_zpow_neg_one #align neg_one_zsmul_add neg_one_zsmul_add @[to_additive zsmul_neg] lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow] | .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow] #align inv_zpow inv_zpow #align zsmul_neg zsmul_neg @[to_additive (attr := simp) zsmul_neg'] lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg] #align inv_zpow' inv_zpow' #align zsmul_neg' zsmul_neg' @[to_additive nsmul_zero_sub] lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow] #align one_div_pow one_div_pow #align nsmul_zero_sub nsmul_zero_sub @[to_additive zsmul_zero_sub] lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow] #align one_div_zpow one_div_zpow #align zsmul_zero_sub zsmul_zero_sub variable {a b c} @[to_additive (attr := simp)] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := inv_injective.eq_iff' inv_one #align inv_eq_one inv_eq_one #align neg_eq_zero neg_eq_zero @[to_additive (attr := simp)] theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 := eq_comm.trans inv_eq_one #align one_eq_inv one_eq_inv #align zero_eq_neg zero_eq_neg @[to_additive] theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 := inv_eq_one.not #align inv_ne_one inv_ne_one #align neg_ne_zero neg_ne_zero @[to_additive] theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by rw [← one_div_one_div a, h, one_div_one_div] #align eq_of_one_div_eq_one_div eq_of_one_div_eq_one_div #align eq_of_zero_sub_eq_zero_sub eq_of_zero_sub_eq_zero_sub -- Note that `mul_zsmul` and `zpow_mul` have the primes swapped -- when additivised since their argument order, -- and therefore the more "natural" choice of lemma, is reversed. @[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n | (m : ℕ), (n : ℕ) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast] rfl | (m : ℕ), .negSucc n => by rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj, ← zpow_natCast] | .negSucc m, (n : ℕ) => by rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow, inv_inj, ← zpow_natCast] | .negSucc m, .negSucc n => by rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ← zpow_natCast] rfl #align zpow_mul zpow_mul #align mul_zsmul' mul_zsmul' @[to_additive mul_zsmul] lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul] #align zpow_mul' zpow_mul' #align mul_zsmul mul_zsmul #noalign zpow_bit0 #noalign bit0_zsmul #noalign zpow_bit0' #noalign bit0_zsmul' #noalign zpow_bit1 #noalign bit1_zsmul variable (a b c) @[to_additive, field_simps] -- The attributes are out of order on purpose theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp #align div_div_eq_mul_div div_div_eq_mul_div #align sub_sub_eq_add_sub sub_sub_eq_add_sub @[to_additive (attr := simp)] theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp #align div_inv_eq_mul div_inv_eq_mul #align sub_neg_eq_add sub_neg_eq_add @[to_additive] theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv] #align div_mul_eq_div_div_swap div_mul_eq_div_div_swap #align sub_add_eq_sub_sub_swap sub_add_eq_sub_sub_swap end DivisionMonoid section SubtractionMonoid set_option linter.deprecated false lemma bit0_neg [SubtractionMonoid α] (a : α) : bit0 (-a) = -bit0 a := (neg_add_rev _ _).symm #align bit0_neg bit0_neg end SubtractionMonoid section DivisionCommMonoid variable [DivisionCommMonoid α] (a b c d : α) attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive neg_add] theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp #align mul_inv mul_inv #align neg_add neg_add @[to_additive] theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp #align inv_div' inv_div' #align neg_sub' neg_sub' @[to_additive] theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp #align div_eq_inv_mul div_eq_inv_mul #align sub_eq_neg_add sub_eq_neg_add @[to_additive] theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp #align inv_mul_eq_div inv_mul_eq_div #align neg_add_eq_sub neg_add_eq_sub @[to_additive] theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp #align inv_mul' inv_mul' #align neg_add' neg_add' @[to_additive] theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp #align inv_div_inv inv_div_inv #align neg_sub_neg neg_sub_neg @[to_additive] theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp #align inv_inv_div_inv inv_inv_div_inv #align neg_neg_sub_neg neg_neg_sub_neg @[to_additive] theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp #align one_div_mul_one_div one_div_mul_one_div #align zero_sub_add_zero_sub zero_sub_add_zero_sub @[to_additive] theorem div_right_comm : a / b / c = a / c / b := by simp #align div_right_comm div_right_comm #align sub_right_comm sub_right_comm @[to_additive, field_simps] theorem div_div : a / b / c = a / (b * c) := by simp #align div_div div_div #align sub_sub sub_sub @[to_additive] theorem div_mul : a / b * c = a / (b / c) := by simp #align div_mul div_mul #align sub_add sub_add @[to_additive] theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp #align mul_div_left_comm mul_div_left_comm #align add_sub_left_comm add_sub_left_comm @[to_additive] theorem mul_div_right_comm : a * b / c = a / c * b := by simp #align mul_div_right_comm mul_div_right_comm #align add_sub_right_comm add_sub_right_comm @[to_additive] theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp #align div_mul_eq_div_div div_mul_eq_div_div #align sub_add_eq_sub_sub sub_add_eq_sub_sub @[to_additive, field_simps] theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp #align div_mul_eq_mul_div div_mul_eq_mul_div #align sub_add_eq_add_sub sub_add_eq_add_sub @[to_additive] theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp @[to_additive] theorem mul_comm_div : a / b * c = a * (c / b) := by simp #align mul_comm_div mul_comm_div #align add_comm_sub add_comm_sub @[to_additive] theorem div_mul_comm : a / b * c = c / b * a := by simp #align div_mul_comm div_mul_comm #align sub_add_comm sub_add_comm @[to_additive] theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp #align div_mul_eq_div_mul_one_div div_mul_eq_div_mul_one_div #align sub_add_eq_sub_add_zero_sub sub_add_eq_sub_add_zero_sub @[to_additive] theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp #align div_div_div_eq div_div_div_eq #align sub_sub_sub_eq sub_sub_sub_eq @[to_additive] theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp #align div_div_div_comm div_div_div_comm #align sub_sub_sub_comm sub_sub_sub_comm @[to_additive] theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp #align div_mul_div_comm div_mul_div_comm #align sub_add_sub_comm sub_add_sub_comm @[to_additive] theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp #align mul_div_mul_comm mul_div_mul_comm #align add_sub_add_comm add_sub_add_comm @[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n | (n : ℕ) => by simp_rw [zpow_natCast, mul_pow] | .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow] #align mul_zpow mul_zpow #align zsmul_add zsmul_add @[to_additive (attr := simp) nsmul_sub] lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_pow, inv_pow] #align div_pow div_pow #align nsmul_sub nsmul_sub @[to_additive (attr := simp) zsmul_sub] lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_zpow, inv_zpow] #align div_zpow div_zpow #align zsmul_sub zsmul_sub end DivisionCommMonoid section Group variable [Group G] {a b c d : G} {n : ℤ} @[to_additive (attr := simp)] theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_left_eq_self] #align div_eq_inv_self div_eq_inv_self #align sub_eq_neg_self sub_eq_neg_self @[to_additive] theorem mul_left_surjective (a : G) : Surjective (a * ·) := fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩ #align mul_left_surjective mul_left_surjective #align add_left_surjective add_left_surjective @[to_additive] theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦ ⟨x * a⁻¹, inv_mul_cancel_right x a⟩ #align mul_right_surjective mul_right_surjective #align add_right_surjective add_right_surjective @[to_additive] theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm] #align eq_mul_inv_of_mul_eq eq_mul_inv_of_mul_eq #align eq_add_neg_of_add_eq eq_add_neg_of_add_eq @[to_additive] theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm] #align eq_inv_mul_of_mul_eq eq_inv_mul_of_mul_eq #align eq_neg_add_of_add_eq eq_neg_add_of_add_eq @[to_additive] theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h] #align inv_mul_eq_of_eq_mul inv_mul_eq_of_eq_mul #align neg_add_eq_of_eq_add neg_add_eq_of_eq_add @[to_additive] theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h] #align mul_inv_eq_of_eq_mul mul_inv_eq_of_eq_mul #align add_neg_eq_of_eq_add add_neg_eq_of_eq_add @[to_additive] theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm] #align eq_mul_of_mul_inv_eq eq_mul_of_mul_inv_eq #align eq_add_of_add_neg_eq eq_add_of_add_neg_eq @[to_additive] theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left] #align eq_mul_of_inv_mul_eq eq_mul_of_inv_mul_eq #align eq_add_of_neg_add_eq eq_add_of_neg_add_eq @[to_additive] theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left] #align mul_eq_of_eq_inv_mul mul_eq_of_eq_inv_mul #align add_eq_of_eq_neg_add add_eq_of_eq_neg_add @[to_additive] theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h] #align mul_eq_of_eq_mul_inv mul_eq_of_eq_mul_inv #align add_eq_of_eq_add_neg add_eq_of_eq_add_neg @[to_additive] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := ⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, mul_left_inv]⟩ #align mul_eq_one_iff_eq_inv mul_eq_one_iff_eq_inv #align add_eq_zero_iff_eq_neg add_eq_zero_iff_eq_neg @[to_additive] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv] #align mul_eq_one_iff_inv_eq mul_eq_one_iff_inv_eq #align add_eq_zero_iff_neg_eq add_eq_zero_iff_neg_eq @[to_additive] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm #align eq_inv_iff_mul_eq_one eq_inv_iff_mul_eq_one #align eq_neg_iff_add_eq_zero eq_neg_iff_add_eq_zero @[to_additive] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm #align inv_eq_iff_mul_eq_one inv_eq_iff_mul_eq_one #align neg_eq_iff_add_eq_zero neg_eq_iff_add_eq_zero @[to_additive] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩ #align eq_mul_inv_iff_mul_eq eq_mul_inv_iff_mul_eq #align eq_add_neg_iff_add_eq eq_add_neg_iff_add_eq @[to_additive] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩ #align eq_inv_mul_iff_mul_eq eq_inv_mul_iff_mul_eq #align eq_neg_add_iff_add_eq eq_neg_add_iff_add_eq @[to_additive] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩ #align inv_mul_eq_iff_eq_mul inv_mul_eq_iff_eq_mul #align neg_add_eq_iff_eq_add neg_add_eq_iff_eq_add @[to_additive] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩ #align mul_inv_eq_iff_eq_mul mul_inv_eq_iff_eq_mul #align add_neg_eq_iff_eq_add add_neg_eq_iff_eq_add @[to_additive] theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] #align mul_inv_eq_one mul_inv_eq_one #align add_neg_eq_zero add_neg_eq_zero @[to_additive] theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj] #align inv_mul_eq_one inv_mul_eq_one #align neg_add_eq_zero neg_add_eq_zero @[to_additive (attr := simp)] theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by rw [mul_inv_eq_one, mul_right_eq_self] @[to_additive] theorem div_left_injective : Function.Injective fun a ↦ a / b := by -- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`. simp only [div_eq_mul_inv] exact fun a a' h ↦ mul_left_injective b⁻¹ h #align div_left_injective div_left_injective #align sub_left_injective sub_left_injective @[to_additive] theorem div_right_injective : Function.Injective fun a ↦ b / a := by -- FIXME see above simp only [div_eq_mul_inv] exact fun a a' h ↦ inv_injective (mul_right_injective b h) #align div_right_injective div_right_injective #align sub_right_injective sub_right_injective @[to_additive (attr := simp)] theorem div_mul_cancel (a b : G) : a / b * b = a := by rw [div_eq_mul_inv, inv_mul_cancel_right a b] #align div_mul_cancel' div_mul_cancel #align sub_add_cancel sub_add_cancel @[to_additive (attr := simp) sub_self] theorem div_self' (a : G) : a / a = 1 := by rw [div_eq_mul_inv, mul_right_inv a] #align div_self' div_self' #align sub_self sub_self @[to_additive (attr := simp)] theorem mul_div_cancel_right (a b : G) : a * b / b = a := by rw [div_eq_mul_inv, mul_inv_cancel_right a b] #align mul_div_cancel'' mul_div_cancel_right #align add_sub_cancel add_sub_cancel_right @[to_additive (attr := simp)] lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right] #align div_mul_cancel''' div_mul_cancel_right #align sub_add_cancel'' sub_add_cancel_right @[to_additive (attr := simp)]
Mathlib/Algebra/Group/Basic.lean
1,020
1,021
theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by
rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right]
/- 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.Order.Interval.Finset.Nat import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding #align_import topology.metric_space.emetric_space from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328" /-! # Extended metric spaces This file is devoted to the definition and study of `EMetricSpace`s, i.e., metric spaces in which the distance is allowed to take the value ∞. This extended distance is called `edist`, and takes values in `ℝ≥0∞`. Many definitions and theorems expected on emetric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. The class `EMetricSpace` therefore extends `UniformSpace` (and `TopologicalSpace`). Since a lot of elementary properties don't require `eq_of_edist_eq_zero` we start setting up the theory of `PseudoEMetricSpace`, where we don't require `edist x y = 0 → x = y` and we specialize to `EMetricSpace` at the end. -/ open Set Filter Classical open scoped Uniformity Topology Filter NNReal ENNReal Pointwise universe u v w variable {α : Type u} {β : Type v} {X : Type*} /-- Characterizing uniformities associated to a (generalized) distance function `D` in terms of the elements of the uniformity. -/ theorem uniformity_dist_of_mem_uniformity [LinearOrder β] {U : Filter (α × α)} (z : β) (D : α → α → β) (H : ∀ s, s ∈ U ↔ ∃ ε > z, ∀ {a b : α}, D a b < ε → (a, b) ∈ s) : U = ⨅ ε > z, 𝓟 { p : α × α | D p.1 p.2 < ε } := HasBasis.eq_biInf ⟨fun s => by simp only [H, subset_def, Prod.forall, mem_setOf]⟩ #align uniformity_dist_of_mem_uniformity uniformity_dist_of_mem_uniformity /-- `EDist α` means that `α` is equipped with an extended distance. -/ @[ext] class EDist (α : Type*) where edist : α → α → ℝ≥0∞ #align has_edist EDist export EDist (edist) /-- Creating a uniform space from an extended distance. -/ def uniformSpaceOfEDist (edist : α → α → ℝ≥0∞) (edist_self : ∀ x : α, edist x x = 0) (edist_comm : ∀ x y : α, edist x y = edist y x) (edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z) : UniformSpace α := .ofFun edist edist_self edist_comm edist_triangle fun ε ε0 => ⟨ε / 2, ENNReal.half_pos ε0.ne', fun _ h₁ _ h₂ => (ENNReal.add_lt_add h₁ h₂).trans_eq (ENNReal.add_halves _)⟩ #align uniform_space_of_edist uniformSpaceOfEDist -- the uniform structure is embedded in the emetric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- Extended (pseudo) metric spaces, with an extended distance `edist` possibly taking the value ∞ Each pseudo_emetric space induces a canonical `UniformSpace` and hence a canonical `TopologicalSpace`. This is enforced in the type class definition, by extending the `UniformSpace` structure. When instantiating a `PseudoEMetricSpace` structure, the uniformity fields are not necessary, they will be filled in by default. There is a default value for the uniformity, that can be substituted in cases of interest, for instance when instantiating a `PseudoEMetricSpace` structure on a product. Continuity of `edist` is proved in `Topology.Instances.ENNReal` -/ class PseudoEMetricSpace (α : Type u) extends EDist α : Type u where edist_self : ∀ x : α, edist x x = 0 edist_comm : ∀ x y : α, edist x y = edist y x edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z toUniformSpace : UniformSpace α := uniformSpaceOfEDist edist edist_self edist_comm edist_triangle uniformity_edist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } := by rfl #align pseudo_emetric_space PseudoEMetricSpace attribute [instance] PseudoEMetricSpace.toUniformSpace /- Pseudoemetric spaces are less common than metric spaces. Therefore, we work in a dedicated namespace, while notions associated to metric spaces are mostly in the root namespace. -/ /-- Two pseudo emetric space structures with the same edistance function coincide. -/ @[ext] protected theorem PseudoEMetricSpace.ext {α : Type*} {m m' : PseudoEMetricSpace α} (h : m.toEDist = m'.toEDist) : m = m' := by cases' m with ed _ _ _ U hU cases' m' with ed' _ _ _ U' hU' congr 1 exact UniformSpace.ext (((show ed = ed' from h) ▸ hU).trans hU'.symm) variable [PseudoEMetricSpace α] export PseudoEMetricSpace (edist_self edist_comm edist_triangle) attribute [simp] edist_self /-- Triangle inequality for the extended distance -/ theorem edist_triangle_left (x y z : α) : edist x y ≤ edist z x + edist z y := by rw [edist_comm z]; apply edist_triangle #align edist_triangle_left edist_triangle_left theorem edist_triangle_right (x y z : α) : edist x y ≤ edist x z + edist y z := by rw [edist_comm y]; apply edist_triangle #align edist_triangle_right edist_triangle_right theorem edist_congr_right {x y z : α} (h : edist x y = 0) : edist x z = edist y z := by apply le_antisymm · rw [← zero_add (edist y z), ← h] apply edist_triangle · rw [edist_comm] at h rw [← zero_add (edist x z), ← h] apply edist_triangle #align edist_congr_right edist_congr_right theorem edist_congr_left {x y z : α} (h : edist x y = 0) : edist z x = edist z y := by rw [edist_comm z x, edist_comm z y] apply edist_congr_right h #align edist_congr_left edist_congr_left -- new theorem theorem edist_congr {w x y z : α} (hl : edist w x = 0) (hr : edist y z = 0) : edist w y = edist x z := (edist_congr_right hl).trans (edist_congr_left hr) theorem edist_triangle4 (x y z t : α) : edist x t ≤ edist x y + edist y z + edist z t := calc edist x t ≤ edist x z + edist z t := edist_triangle x z t _ ≤ edist x y + edist y z + edist z t := add_le_add_right (edist_triangle x y z) _ #align edist_triangle4 edist_triangle4 /-- 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 } #align edist_le_Ico_sum_edist edist_le_Ico_sum_edist /-- 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) #align edist_le_range_sum_edist edist_le_range_sum_edist /-- 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 #align edist_le_Ico_sum_of_edist_le edist_le_Ico_sum_of_edist_le /-- 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 #align edist_le_range_sum_of_edist_le edist_le_range_sum_of_edist_le /-- Reformulation of the uniform structure in terms of the extended distance -/ theorem uniformity_pseudoedist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } := PseudoEMetricSpace.uniformity_edist #align uniformity_pseudoedist uniformity_pseudoedist theorem uniformSpace_edist : ‹PseudoEMetricSpace α›.toUniformSpace = uniformSpaceOfEDist edist edist_self edist_comm edist_triangle := UniformSpace.ext uniformity_pseudoedist #align uniform_space_edist uniformSpace_edist theorem uniformity_basis_edist : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 < ε } := (@uniformSpace_edist α _).symm ▸ UniformSpace.hasBasis_ofFun ⟨1, one_pos⟩ _ _ _ _ _ #align uniformity_basis_edist uniformity_basis_edist /-- Characterization of the elements of the uniformity in terms of the extended distance -/ theorem mem_uniformity_edist {s : Set (α × α)} : s ∈ 𝓤 α ↔ ∃ ε > 0, ∀ {a b : α}, edist a b < ε → (a, b) ∈ s := uniformity_basis_edist.mem_uniformity_iff #align mem_uniformity_edist mem_uniformity_edist /-- Given `f : β → ℝ≥0∞`, 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_edist`, `uniformity_basis_edist'`, `uniformity_basis_edist_nnreal`, and `uniformity_basis_edist_inv_nat`. -/ protected theorem EMetric.mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | edist p.1 p.2 < f x } := by refine ⟨fun s => uniformity_basis_edist.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.out H⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, H⟩ #align emetric.mk_uniformity_basis EMetric.mk_uniformity_basis /-- Given `f : β → ℝ≥0∞`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then closed `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_edist_le` and `uniformity_basis_edist_le'`. -/ protected theorem EMetric.mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | edist p.1 p.2 ≤ f x } := by refine ⟨fun s => uniformity_basis_edist.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.out H) hε'.2⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, fun x hx => H (le_of_lt hx.out)⟩ #align emetric.mk_uniformity_basis_le EMetric.mk_uniformity_basis_le theorem uniformity_basis_edist_le : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => id) fun ε ε₀ => ⟨ε, ε₀, le_refl ε⟩ #align uniformity_basis_edist_le uniformity_basis_edist_le theorem uniformity_basis_edist' (ε' : ℝ≥0∞) (hε' : 0 < ε') : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => ε ∈ Ioo 0 ε') fun ε => { p : α × α | edist p.1 p.2 < ε } := EMetric.mk_uniformity_basis (fun _ => And.left) fun ε ε₀ => let ⟨δ, hδ⟩ := exists_between hε' ⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩ #align uniformity_basis_edist' uniformity_basis_edist' theorem uniformity_basis_edist_le' (ε' : ℝ≥0∞) (hε' : 0 < ε') : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => ε ∈ Ioo 0 ε') fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => And.left) fun ε ε₀ => let ⟨δ, hδ⟩ := exists_between hε' ⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩ #align uniformity_basis_edist_le' uniformity_basis_edist_le' theorem uniformity_basis_edist_nnreal : (𝓤 α).HasBasis (fun ε : ℝ≥0 => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 < ε } := EMetric.mk_uniformity_basis (fun _ => ENNReal.coe_pos.2) fun _ε ε₀ => let ⟨δ, hδ⟩ := ENNReal.lt_iff_exists_nnreal_btwn.1 ε₀ ⟨δ, ENNReal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩ #align uniformity_basis_edist_nnreal uniformity_basis_edist_nnreal theorem uniformity_basis_edist_nnreal_le : (𝓤 α).HasBasis (fun ε : ℝ≥0 => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => ENNReal.coe_pos.2) fun _ε ε₀ => let ⟨δ, hδ⟩ := ENNReal.lt_iff_exists_nnreal_btwn.1 ε₀ ⟨δ, ENNReal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩ #align uniformity_basis_edist_nnreal_le uniformity_basis_edist_nnreal_le theorem uniformity_basis_edist_inv_nat : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | edist p.1 p.2 < (↑n)⁻¹ } := EMetric.mk_uniformity_basis (fun n _ ↦ ENNReal.inv_pos.2 <| ENNReal.natCast_ne_top n) fun _ε ε₀ ↦ let ⟨n, hn⟩ := ENNReal.exists_inv_nat_lt (ne_of_gt ε₀) ⟨n, trivial, le_of_lt hn⟩ #align uniformity_basis_edist_inv_nat uniformity_basis_edist_inv_nat theorem uniformity_basis_edist_inv_two_pow : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | edist p.1 p.2 < 2⁻¹ ^ n } := EMetric.mk_uniformity_basis (fun _ _ => ENNReal.pow_pos (ENNReal.inv_pos.2 ENNReal.two_ne_top) _) fun _ε ε₀ => let ⟨n, hn⟩ := ENNReal.exists_inv_two_pow_lt (ne_of_gt ε₀) ⟨n, trivial, le_of_lt hn⟩ #align uniformity_basis_edist_inv_two_pow uniformity_basis_edist_inv_two_pow /-- Fixed size neighborhoods of the diagonal belong to the uniform structure -/ theorem edist_mem_uniformity {ε : ℝ≥0∞} (ε0 : 0 < ε) : { p : α × α | edist p.1 p.2 < ε } ∈ 𝓤 α := mem_uniformity_edist.2 ⟨ε, ε0, id⟩ #align edist_mem_uniformity edist_mem_uniformity namespace EMetric instance (priority := 900) instIsCountablyGeneratedUniformity : IsCountablyGenerated (𝓤 α) := isCountablyGenerated_of_seq ⟨_, uniformity_basis_edist_inv_nat.eq_iInf⟩ -- Porting note: changed explicit/implicit /-- ε-δ characterization of uniform continuity on a set for pseudoemetric spaces -/ theorem uniformContinuousOn_iff [PseudoEMetricSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ {a}, a ∈ s → ∀ {b}, b ∈ s → edist a b < δ → edist (f a) (f b) < ε := uniformity_basis_edist.uniformContinuousOn_iff uniformity_basis_edist #align emetric.uniform_continuous_on_iff EMetric.uniformContinuousOn_iff /-- ε-δ characterization of uniform continuity on pseudoemetric spaces -/ theorem uniformContinuous_iff [PseudoEMetricSpace β] {f : α → β} : UniformContinuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε := uniformity_basis_edist.uniformContinuous_iff uniformity_basis_edist #align emetric.uniform_continuous_iff EMetric.uniformContinuous_iff -- Porting note (#10756): new lemma theorem uniformInducing_iff [PseudoEMetricSpace β] {f : α → β} : UniformInducing f ↔ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := uniformInducing_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 uniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} : UniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := (uniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and uniformInducing_iff #align emetric.uniform_embedding_iff EMetric.uniformEmbedding_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 `UniformInducing` map. TODO: generalize? -/ theorem controlled_of_uniformEmbedding [PseudoEMetricSpace β] {f : α → β} (h : UniformEmbedding 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, (uniformEmbedding_iff.1 h).2.2⟩ #align emetric.controlled_of_uniform_embedding EMetric.controlled_of_uniformEmbedding /-- ε-δ 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 #align emetric.cauchy_iff EMetric.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 #align emetric.complete_of_convergent_controlled_sequences EMetric.complete_of_convergent_controlled_sequences /-- 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 #align emetric.complete_of_cauchy_seq_tendsto EMetric.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)⟩ #align emetric.tendsto_locally_uniformly_on_iff EMetric.tendstoLocallyUniformlyOn_iff /-- 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) #align emetric.tendsto_uniformly_on_iff EMetric.tendstoUniformlyOn_iff /-- 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] #align emetric.tendsto_locally_uniformly_iff EMetric.tendstoLocallyUniformly_iff /-- 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] #align emetric.tendsto_uniformly_iff EMetric.tendstoUniformly_iff end EMetric open EMetric /-- Auxiliary function to replace the uniformity on a pseudoemetric space with a uniformity which is equal to the original one, but maybe not defeq. This is useful if one wants to construct a pseudoemetric space with a specified uniformity. See Note [forgetful inheritance] explaining why having definitionally the right uniformity is often important. -/ def PseudoEMetricSpace.replaceUniformity {α} [U : UniformSpace α] (m : PseudoEMetricSpace α) (H : 𝓤[U] = 𝓤[PseudoEMetricSpace.toUniformSpace]) : PseudoEMetricSpace α where edist := @edist _ m.toEDist edist_self := edist_self edist_comm := edist_comm edist_triangle := edist_triangle toUniformSpace := U uniformity_edist := H.trans (@PseudoEMetricSpace.uniformity_edist α _) #align pseudo_emetric_space.replace_uniformity PseudoEMetricSpace.replaceUniformity /-- The extended pseudometric induced by a function taking values in a pseudoemetric space. -/ def PseudoEMetricSpace.induced {α β} (f : α → β) (m : PseudoEMetricSpace β) : PseudoEMetricSpace α where edist x y := edist (f x) (f y) edist_self _ := edist_self _ edist_comm _ _ := edist_comm _ _ edist_triangle _ _ _ := edist_triangle _ _ _ toUniformSpace := UniformSpace.comap f m.toUniformSpace uniformity_edist := (uniformity_basis_edist.comap (Prod.map f f)).eq_biInf #align pseudo_emetric_space.induced PseudoEMetricSpace.induced /-- Pseudoemetric space instance on subsets of pseudoemetric spaces -/ instance {α : Type*} {p : α → Prop} [PseudoEMetricSpace α] : PseudoEMetricSpace (Subtype p) := PseudoEMetricSpace.induced Subtype.val ‹_› /-- The extended pseudodistance on a subset of a pseudoemetric space is the restriction of the original pseudodistance, by definition -/ theorem Subtype.edist_eq {p : α → Prop} (x y : Subtype p) : edist x y = edist (x : α) y := rfl #align subtype.edist_eq Subtype.edist_eq namespace MulOpposite /-- Pseudoemetric space instance on the multiplicative opposite of a pseudoemetric space. -/ @[to_additive "Pseudoemetric space instance on the additive opposite of a pseudoemetric space."] instance {α : Type*} [PseudoEMetricSpace α] : PseudoEMetricSpace αᵐᵒᵖ := PseudoEMetricSpace.induced unop ‹_› @[to_additive] theorem edist_unop (x y : αᵐᵒᵖ) : edist (unop x) (unop y) = edist x y := rfl #align mul_opposite.edist_unop MulOpposite.edist_unop #align add_opposite.edist_unop AddOpposite.edist_unop @[to_additive] theorem edist_op (x y : α) : edist (op x) (op y) = edist x y := rfl #align mul_opposite.edist_op MulOpposite.edist_op #align add_opposite.edist_op AddOpposite.edist_op end MulOpposite section ULift instance : PseudoEMetricSpace (ULift α) := PseudoEMetricSpace.induced ULift.down ‹_› theorem ULift.edist_eq (x y : ULift α) : edist x y = edist x.down y.down := rfl #align ulift.edist_eq ULift.edist_eq @[simp] theorem ULift.edist_up_up (x y : α) : edist (ULift.up x) (ULift.up y) = edist x y := rfl #align ulift.edist_up_up ULift.edist_up_up end ULift /-- The product of two pseudoemetric spaces, with the max distance, is an extended pseudometric 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.pseudoEMetricSpaceMax [PseudoEMetricSpace β] : PseudoEMetricSpace (α × β) where edist x y := edist x.1 y.1 ⊔ edist x.2 y.2 edist_self x := by simp edist_comm x y := by simp [edist_comm] edist_triangle x y z := max_le (le_trans (edist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _))) (le_trans (edist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))) uniformity_edist := uniformity_prod.trans <| by simp [PseudoEMetricSpace.uniformity_edist, ← iInf_inf_eq, setOf_and] toUniformSpace := inferInstance #align prod.pseudo_emetric_space_max Prod.pseudoEMetricSpaceMax theorem Prod.edist_eq [PseudoEMetricSpace β] (x y : α × β) : edist x y = max (edist x.1 y.1) (edist x.2 y.2) := rfl #align prod.edist_eq Prod.edist_eq section Pi open Finset variable {π : β → Type*} [Fintype β] -- Porting note: reordered instances instance [∀ b, EDist (π b)] : EDist (∀ b, π b) where edist f g := Finset.sup univ fun b => edist (f b) (g b) theorem edist_pi_def [∀ b, EDist (π b)] (f g : ∀ b, π b) : edist f g = Finset.sup univ fun b => edist (f b) (g b) := rfl #align edist_pi_def edist_pi_def theorem edist_le_pi_edist [∀ b, EDist (π b)] (f g : ∀ b, π b) (b : β) : edist (f b) (g b) ≤ edist f g := le_sup (f := fun b => edist (f b) (g b)) (Finset.mem_univ b) #align edist_le_pi_edist edist_le_pi_edist theorem edist_pi_le_iff [∀ b, EDist (π b)] {f g : ∀ b, π b} {d : ℝ≥0∞} : edist f g ≤ d ↔ ∀ b, edist (f b) (g b) ≤ d := Finset.sup_le_iff.trans <| by simp only [Finset.mem_univ, forall_const] #align edist_pi_le_iff edist_pi_le_iff theorem edist_pi_const_le (a b : α) : (edist (fun _ : β => a) fun _ => b) ≤ edist a b := edist_pi_le_iff.2 fun _ => le_rfl #align edist_pi_const_le edist_pi_const_le @[simp] theorem edist_pi_const [Nonempty β] (a b : α) : (edist (fun _ : β => a) fun _ => b) = edist a b := Finset.sup_const univ_nonempty (edist a b) #align edist_pi_const edist_pi_const /-- The product of a finite number of pseudoemetric spaces, with the max distance, is still a pseudoemetric space. This construction would also work for infinite products, but it would not give rise to the product topology. Hence, we only formalize it in the good situation of finitely many spaces. -/ instance pseudoEMetricSpacePi [∀ b, PseudoEMetricSpace (π b)] : PseudoEMetricSpace (∀ b, π b) where edist_self f := bot_unique <| Finset.sup_le <| by simp edist_comm f g := by simp [edist_pi_def, edist_comm] edist_triangle f g h := edist_pi_le_iff.2 fun b => le_trans (edist_triangle _ (g b) _) (add_le_add (edist_le_pi_edist _ _ _) (edist_le_pi_edist _ _ _)) toUniformSpace := Pi.uniformSpace _ uniformity_edist := by simp only [Pi.uniformity, PseudoEMetricSpace.uniformity_edist, comap_iInf, gt_iff_lt, preimage_setOf_eq, comap_principal, edist_pi_def] rw [iInf_comm]; congr; funext ε rw [iInf_comm]; congr; funext εpos simp [setOf_forall, εpos] #align pseudo_emetric_space_pi pseudoEMetricSpacePi end Pi namespace EMetric variable {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : Set α} /-- `EMetric.ball x ε` is the set of all points `y` with `edist y x < ε` -/ def ball (x : α) (ε : ℝ≥0∞) : Set α := { y | edist y x < ε } #align emetric.ball EMetric.ball @[simp] theorem mem_ball : y ∈ ball x ε ↔ edist y x < ε := Iff.rfl #align emetric.mem_ball EMetric.mem_ball theorem mem_ball' : y ∈ ball x ε ↔ edist x y < ε := by rw [edist_comm, mem_ball] #align emetric.mem_ball' EMetric.mem_ball' /-- `EMetric.closedBall x ε` is the set of all points `y` with `edist y x ≤ ε` -/ def closedBall (x : α) (ε : ℝ≥0∞) := { y | edist y x ≤ ε } #align emetric.closed_ball EMetric.closedBall @[simp] theorem mem_closedBall : y ∈ closedBall x ε ↔ edist y x ≤ ε := Iff.rfl #align emetric.mem_closed_ball EMetric.mem_closedBall
Mathlib/Topology/EMetricSpace/Basic.lean
560
560
theorem mem_closedBall' : y ∈ closedBall x ε ↔ edist x y ≤ ε := by
rw [edist_comm, mem_closedBall]