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) 2014 Robert Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core #align_import algebra.order.field.basic from "leanprover-community/mathlib"@"84771a9f5f0bd5e5d6218811556508ddf476dcbd" /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ι α β : Type*} section LinearOrderedSemifield variable [LinearOrderedSemifield α] {a b c d e : α} {m n : ℤ} /-- `Equiv.mulLeft₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulLeft₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulLeft₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_left ha } #align order_iso.mul_left₀ OrderIso.mulLeft₀ #align order_iso.mul_left₀_symm_apply OrderIso.mulLeft₀_symm_apply #align order_iso.mul_left₀_apply OrderIso.mulLeft₀_apply /-- `Equiv.mulRight₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulRight₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulRight₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_right ha } #align order_iso.mul_right₀ OrderIso.mulRight₀ #align order_iso.mul_right₀_symm_apply OrderIso.mulRight₀_symm_apply #align order_iso.mul_right₀_apply OrderIso.mulRight₀_apply /-! ### Relating one division with another term. -/ theorem le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc).symm _ ≤ b * (1 / c) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ #align le_div_iff le_div_iff theorem le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b := by rw [mul_comm, le_div_iff hc] #align le_div_iff' le_div_iff' theorem div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b := ⟨fun h => calc a = a / b * b := by rw [div_mul_cancel₀ _ (ne_of_lt hb).symm] _ ≤ c * b := mul_le_mul_of_nonneg_right h hb.le , fun h => calc a / b = a * (1 / b) := div_eq_mul_one_div a b _ ≤ c * b * (1 / b) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le _ = c * b / b := (div_eq_mul_one_div (c * b) b).symm _ = c := by refine (div_eq_iff (ne_of_gt hb)).mpr rfl ⟩ #align div_le_iff div_le_iff theorem div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c := by rw [mul_comm, div_le_iff hb] #align div_le_iff' div_le_iff' lemma div_le_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b ≤ c ↔ a / c ≤ b := by rw [div_le_iff hb, div_le_iff' hc] theorem lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b := lt_iff_lt_of_le_iff_le <| div_le_iff hc #align lt_div_iff lt_div_iff theorem lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by rw [mul_comm, lt_div_iff hc] #align lt_div_iff' lt_div_iff' theorem div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c := lt_iff_lt_of_le_iff_le (le_div_iff hc) #align div_lt_iff div_lt_iff theorem div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a := by rw [mul_comm, div_lt_iff hc] #align div_lt_iff' div_lt_iff' lemma div_lt_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b < c ↔ a / c < b := by rw [div_lt_iff hb, div_lt_iff' hc] theorem inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_le_iff' h #align inv_mul_le_iff inv_mul_le_iff theorem inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b := by rw [inv_mul_le_iff h, mul_comm] #align inv_mul_le_iff' inv_mul_le_iff' theorem mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [mul_comm, inv_mul_le_iff h] #align mul_inv_le_iff mul_inv_le_iff theorem mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b := by rw [mul_comm, inv_mul_le_iff' h] #align mul_inv_le_iff' mul_inv_le_iff' theorem div_self_le_one (a : α) : a / a ≤ 1 := if h : a = 0 then by simp [h] else by simp [h] #align div_self_le_one div_self_le_one theorem inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_lt_iff' h #align inv_mul_lt_iff inv_mul_lt_iff theorem inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b := by rw [inv_mul_lt_iff h, mul_comm] #align inv_mul_lt_iff' inv_mul_lt_iff' theorem mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c := by rw [mul_comm, inv_mul_lt_iff h] #align mul_inv_lt_iff mul_inv_lt_iff theorem mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b := by rw [mul_comm, inv_mul_lt_iff' h] #align mul_inv_lt_iff' mul_inv_lt_iff' theorem inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a := by rw [inv_eq_one_div] exact div_le_iff ha #align inv_pos_le_iff_one_le_mul inv_pos_le_iff_one_le_mul theorem inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by rw [inv_eq_one_div] exact div_le_iff' ha #align inv_pos_le_iff_one_le_mul' inv_pos_le_iff_one_le_mul' theorem inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a⁻¹ < b ↔ 1 < b * a := by rw [inv_eq_one_div] exact div_lt_iff ha #align inv_pos_lt_iff_one_lt_mul inv_pos_lt_iff_one_lt_mul theorem inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a⁻¹ < b ↔ 1 < a * b := by rw [inv_eq_one_div] exact div_lt_iff' ha #align inv_pos_lt_iff_one_lt_mul' inv_pos_lt_iff_one_lt_mul' /-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/ theorem div_le_of_nonneg_of_le_mul (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ c := by rcases eq_or_lt_of_le hb with (rfl | hb') · simp only [div_zero, hc] · rwa [div_le_iff hb'] #align div_le_of_nonneg_of_le_mul div_le_of_nonneg_of_le_mul /-- One direction of `div_le_iff` where `c` is allowed to be `0` (but `b` must be nonnegative) -/ lemma mul_le_of_nonneg_of_le_div (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ b / c) : a * c ≤ b := by obtain rfl | hc := hc.eq_or_lt · simpa using hb · rwa [le_div_iff hc] at h #align mul_le_of_nonneg_of_le_div mul_le_of_nonneg_of_le_div theorem div_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a / b ≤ 1 := div_le_of_nonneg_of_le_mul hb zero_le_one <| by rwa [one_mul] #align div_le_one_of_le div_le_one_of_le lemma mul_inv_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a * b⁻¹ ≤ 1 := by simpa only [← div_eq_mul_inv] using div_le_one_of_le h hb lemma inv_mul_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : b⁻¹ * a ≤ 1 := by simpa only [← div_eq_inv_mul] using div_le_one_of_le h hb /-! ### Bi-implications of inequalities using inversions -/ @[gcongr] theorem inv_le_inv_of_le (ha : 0 < a) (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := by rwa [← one_div a, le_div_iff' ha, ← div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul] #align inv_le_inv_of_le inv_le_inv_of_le /-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/ theorem inv_le_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul] #align inv_le_inv inv_le_inv /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ ≤ b ↔ b⁻¹ ≤ a`. See also `inv_le_of_inv_le` for a one-sided implication with one fewer assumption. -/ theorem inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv hb (inv_pos.2 ha), inv_inv] #align inv_le inv_le theorem inv_le_of_inv_le (ha : 0 < a) (h : a⁻¹ ≤ b) : b⁻¹ ≤ a := (inv_le ha ((inv_pos.2 ha).trans_le h)).1 h #align inv_le_of_inv_le inv_le_of_inv_le theorem le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv (inv_pos.2 hb) ha, inv_inv] #align le_inv le_inv /-- See `inv_lt_inv_of_lt` for the implication from right-to-left with one fewer assumption. -/ theorem inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv hb ha) #align inv_lt_inv inv_lt_inv @[gcongr] theorem inv_lt_inv_of_lt (hb : 0 < b) (h : b < a) : a⁻¹ < b⁻¹ := (inv_lt_inv (hb.trans h) hb).2 h #align inv_lt_inv_of_lt inv_lt_inv_of_lt /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ < b ↔ b⁻¹ < a`. See also `inv_lt_of_inv_lt` for a one-sided implication with one fewer assumption. -/ theorem inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv hb ha) #align inv_lt inv_lt theorem inv_lt_of_inv_lt (ha : 0 < a) (h : a⁻¹ < b) : b⁻¹ < a := (inv_lt ha ((inv_pos.2 ha).trans h)).1 h #align inv_lt_of_inv_lt inv_lt_of_inv_lt theorem lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le hb ha) #align lt_inv lt_inv theorem inv_lt_one (ha : 1 < a) : a⁻¹ < 1 := by rwa [inv_lt (zero_lt_one.trans ha) zero_lt_one, inv_one] #align inv_lt_one inv_lt_one theorem one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ := by rwa [lt_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_lt_inv one_lt_inv theorem inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 := by rwa [inv_le (zero_lt_one.trans_le ha) zero_lt_one, inv_one] #align inv_le_one inv_le_one theorem one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ := by rwa [le_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_le_inv one_le_inv theorem inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a := ⟨fun h₁ => inv_inv a ▸ one_lt_inv (inv_pos.2 h₀) h₁, inv_lt_one⟩ #align inv_lt_one_iff_of_pos inv_lt_one_iff_of_pos theorem inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 1 < a := by rcases le_or_lt a 0 with ha | ha · simp [ha, (inv_nonpos.2 ha).trans_lt zero_lt_one] · simp only [ha.not_le, false_or_iff, inv_lt_one_iff_of_pos ha] #align inv_lt_one_iff inv_lt_one_iff theorem one_lt_inv_iff : 1 < a⁻¹ ↔ 0 < a ∧ a < 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans h), inv_inv a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩ #align one_lt_inv_iff one_lt_inv_iff theorem inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ a := by rcases em (a = 1) with (rfl | ha) · simp [le_rfl] · simp only [Ne.le_iff_lt (Ne.symm ha), Ne.le_iff_lt (mt inv_eq_one.1 ha), inv_lt_one_iff] #align inv_le_one_iff inv_le_one_iff theorem one_le_inv_iff : 1 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans_le h), inv_inv a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩ #align one_le_inv_iff one_le_inv_iff /-! ### Relating two divisions. -/ @[mono, gcongr] lemma div_le_div_of_nonneg_right (hab : a ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonneg_right hab (one_div_nonneg.2 hc) #align div_le_div_of_le_of_nonneg div_le_div_of_nonneg_right @[gcongr] lemma div_lt_div_of_pos_right (h : a < b) (hc : 0 < c) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_pos_right h (one_div_pos.2 hc) #align div_lt_div_of_lt div_lt_div_of_pos_right -- Not a `mono` lemma b/c `div_le_div` is strictly more general @[gcongr] lemma div_le_div_of_nonneg_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ a / c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha #align div_le_div_of_le_left div_le_div_of_nonneg_left @[gcongr] lemma div_lt_div_of_pos_left (ha : 0 < a) (hc : 0 < c) (h : c < b) : a / b < a / c := by simpa only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv (hc.trans h) hc] #align div_lt_div_of_lt_left div_lt_div_of_pos_left -- 2024-02-16 @[deprecated] alias div_le_div_of_le_of_nonneg := div_le_div_of_nonneg_right @[deprecated] alias div_lt_div_of_lt := div_lt_div_of_pos_right @[deprecated] alias div_le_div_of_le_left := div_le_div_of_nonneg_left @[deprecated] alias div_lt_div_of_lt_left := div_lt_div_of_pos_left @[deprecated div_le_div_of_nonneg_right (since := "2024-02-16")] lemma div_le_div_of_le (hc : 0 ≤ c) (hab : a ≤ b) : a / c ≤ b / c := div_le_div_of_nonneg_right hab hc #align div_le_div_of_le div_le_div_of_le theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := ⟨le_imp_le_of_lt_imp_lt fun hab ↦ div_lt_div_of_pos_right hab hc, fun hab ↦ div_le_div_of_nonneg_right hab hc.le⟩ #align div_le_div_right div_le_div_right theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := lt_iff_lt_of_le_iff_le <| div_le_div_right hc #align div_lt_div_right div_lt_div_right theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := by simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc] #align div_lt_div_left div_lt_div_left theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b := le_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb) #align div_le_div_left div_le_div_left theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := by rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0] #align div_lt_div_iff div_lt_div_iff theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := by rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0] #align div_le_div_iff div_le_div_iff @[mono, gcongr] theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := by rw [div_le_div_iff (hd.trans_le hbd) hd] exact mul_le_mul hac hbd hd.le hc #align div_le_div div_le_div @[gcongr] theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0) #align div_lt_div div_lt_div theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0) #align div_lt_div' div_lt_div' /-! ### Relating one division and involving `1` -/ theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb #align div_le_self div_le_self theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb #align div_lt_self div_lt_self theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁ #align le_div_self le_div_self theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff hb, one_mul] #align one_le_div one_le_div theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff hb, one_mul] #align div_le_one div_le_one theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff hb, one_mul] #align one_lt_div one_lt_div theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff hb, one_mul] #align div_lt_one div_lt_one theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le ha hb #align one_div_le one_div_le theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt ha hb #align one_div_lt one_div_lt theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv ha hb #align le_one_div le_one_div theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv ha hb #align lt_one_div lt_one_div /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by simpa using inv_le_inv_of_le ha h #align one_div_le_one_div_of_le one_div_le_one_div_of_le theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iff' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] #align one_div_lt_one_div_of_lt one_div_lt_one_div_of_lt theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h #align le_of_one_div_le_one_div le_of_one_div_le_one_div theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h #align lt_of_one_div_lt_one_div lt_of_one_div_lt_one_div /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a := div_le_div_left zero_lt_one ha hb #align one_div_le_one_div one_div_le_one_div /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_left zero_lt_one ha hb #align one_div_lt_one_div one_div_lt_one_div theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] #align one_lt_one_div one_lt_one_div theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] #align one_le_one_div one_le_one_div /-! ### Results about halving. The equalities also hold in semifields of characteristic `0`. -/ /- TODO: Unify `add_halves` and `add_halves'` into a single lemma about `DivisionSemiring` + `CharZero` -/ theorem add_halves (a : α) : a / 2 + a / 2 = a := by rw [div_add_div_same, ← two_mul, mul_div_cancel_left₀ a two_ne_zero] #align add_halves add_halves -- TODO: Generalize to `DivisionSemiring` theorem add_self_div_two (a : α) : (a + a) / 2 = a := by rw [← mul_two, mul_div_cancel_right₀ a two_ne_zero] #align add_self_div_two add_self_div_two theorem half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two #align half_pos half_pos theorem one_half_pos : (0 : α) < 1 / 2 := half_pos zero_lt_one #align one_half_pos one_half_pos @[simp] theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by rw [div_le_iff (zero_lt_two' α), mul_two, le_add_iff_nonneg_left] #align half_le_self_iff half_le_self_iff @[simp] theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by rw [div_lt_iff (zero_lt_two' α), mul_two, lt_add_iff_pos_left] #align half_lt_self_iff half_lt_self_iff alias ⟨_, half_le_self⟩ := half_le_self_iff #align half_le_self half_le_self alias ⟨_, half_lt_self⟩ := half_lt_self_iff #align half_lt_self half_lt_self alias div_two_lt_of_pos := half_lt_self #align div_two_lt_of_pos div_two_lt_of_pos theorem one_half_lt_one : (1 / 2 : α) < 1 := half_lt_self zero_lt_one #align one_half_lt_one one_half_lt_one theorem two_inv_lt_one : (2⁻¹ : α) < 1 := (one_div _).symm.trans_lt one_half_lt_one #align two_inv_lt_one two_inv_lt_one theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff, mul_two] #align left_lt_add_div_two left_lt_add_div_two theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff, mul_two] #align add_div_two_lt_right add_div_two_lt_right theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three, mul_div_cancel_left₀ a three_ne_zero] /-! ### Miscellaneous lemmas -/ @[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos] @[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)] theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by rw [← mul_div_assoc] at h rwa [mul_comm b, ← div_le_iff hc] #align mul_le_mul_of_mul_div_le mul_le_mul_of_mul_div_le theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) : a / (b * e) ≤ c / (d * e) := by rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div] exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) #align div_mul_le_div_mul_of_div_le_div div_mul_le_div_mul_of_div_le_div theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one)) refine ⟨a / max (b + 1) 1, this, ?_⟩ rw [← lt_div_iff this, div_div_cancel' h.ne'] exact lt_max_iff.2 (Or.inl <| lt_add_one _) #align exists_pos_mul_lt exists_pos_mul_lt theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a := let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b; ⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff hc₀]⟩ #align exists_pos_lt_mul exists_pos_lt_mul lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) := fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) := fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α} (hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf #align monotone.div_const Monotone.div_const theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α} (hc : 0 < c) : StrictMono fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) #align strict_mono.div_const StrictMono.div_const -- see Note [lower instance priority] instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where dense a₁ a₂ h := ⟨(a₁ + a₂) / 2, calc a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm _ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two , calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two _ = a₂ := add_self_div_two a₂ ⟩ #align linear_ordered_field.to_densely_ordered LinearOrderedSemiField.toDenselyOrdered theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c := (monotone_div_right_of_nonneg hc).map_min.symm #align min_div_div_right min_div_div_right theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c := (monotone_div_right_of_nonneg hc).map_max.symm #align max_div_div_right max_div_div_right theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) := fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy #align one_div_strict_anti_on one_div_strictAntiOn theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : 1 / a ^ n ≤ 1 / a ^ m := by refine (one_div_le_one_div ?_ ?_).mpr (pow_le_pow_right a1 mn) <;> exact pow_pos (zero_lt_one.trans_le a1) _ #align one_div_pow_le_one_div_pow_of_le one_div_pow_le_one_div_pow_of_le theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : 1 / a ^ n < 1 / a ^ m := by refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right a1 mn) <;> exact pow_pos (zero_lt_one.trans a1) _ #align one_div_pow_lt_one_div_pow_of_lt one_div_pow_lt_one_div_pow_of_lt theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_le_one_div_pow_of_le a1 #align one_div_pow_anti one_div_pow_anti theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_lt_one_div_pow_of_lt a1 #align one_div_pow_strict_anti one_div_pow_strictAnti theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy => (inv_lt_inv hy hx).2 xy #align inv_strict_anti_on inv_strictAntiOn theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp #align inv_pow_le_inv_pow_of_le inv_pow_le_inv_pow_of_le theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp #align inv_pow_lt_inv_pow_of_lt inv_pow_lt_inv_pow_of_lt theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_le_inv_pow_of_le a1 #align inv_pow_anti inv_pow_anti theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_lt_inv_pow_of_lt a1 #align inv_pow_strict_anti inv_pow_strictAnti /-! ### Results about `IsGLB` -/ theorem IsGLB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) · exact (OrderIso.mulLeft₀ _ ha).isGLB_image'.2 hs · simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isGLB_singleton #align is_glb.mul_left IsGLB.mul_left theorem IsGLB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha #align is_glb.mul_right IsGLB.mul_right end LinearOrderedSemifield section variable [LinearOrderedField α] {a b c d : α} {n : ℤ} /-! ### Lemmas about pos, nonneg, nonpos, neg -/ theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero] #align div_pos_iff div_pos_iff theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff] #align div_neg_iff div_neg_iff theorem div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by simp [division_def, mul_nonneg_iff] #align div_nonneg_iff div_nonneg_iff theorem div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by simp [division_def, mul_nonpos_iff] #align div_nonpos_iff div_nonpos_iff theorem div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b := div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩ #align div_nonneg_of_nonpos div_nonneg_of_nonpos theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b := div_pos_iff.2 <| Or.inr ⟨ha, hb⟩ #align div_pos_of_neg_of_neg div_pos_of_neg_of_neg theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 := div_neg_iff.2 <| Or.inr ⟨ha, hb⟩ #align div_neg_of_neg_of_pos div_neg_of_neg_of_pos theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 := div_neg_iff.2 <| Or.inl ⟨ha, hb⟩ #align div_neg_of_pos_of_neg div_neg_of_pos_of_neg /-! ### Relating one division with another term -/ theorem div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc) _ ≥ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ #align div_le_iff_of_neg div_le_iff_of_neg theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by rw [mul_comm, div_le_iff_of_neg hc] #align div_le_iff_of_neg' div_le_iff_of_neg' theorem le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iff (neg_pos.2 hc), neg_mul] #align le_div_iff_of_neg le_div_iff_of_neg theorem le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by rw [mul_comm, le_div_iff_of_neg hc] #align le_div_iff_of_neg' le_div_iff_of_neg' theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b := lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc #align div_lt_iff_of_neg div_lt_iff_of_neg theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by rw [mul_comm, div_lt_iff_of_neg hc] #align div_lt_iff_of_neg' div_lt_iff_of_neg' theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c := lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc #align lt_div_iff_of_neg lt_div_iff_of_neg theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by rw [mul_comm, lt_div_iff_of_neg hc] #align lt_div_iff_of_neg' lt_div_iff_of_neg' theorem div_le_one_of_ge (h : b ≤ a) (hb : b ≤ 0) : a / b ≤ 1 := by simpa only [neg_div_neg_eq] using div_le_one_of_le (neg_le_neg h) (neg_nonneg_of_nonpos hb) #align div_le_one_of_ge div_le_one_of_ge /-! ### Bi-implications of inequalities using inversions -/ theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul] #align inv_le_inv_of_neg inv_le_inv_of_neg theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv] #align inv_le_of_neg inv_le_of_neg theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv] #align le_inv_of_neg le_inv_of_neg theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha) #align inv_lt_inv_of_neg inv_lt_inv_of_neg theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha) #align inv_lt_of_neg inv_lt_of_neg theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha) #align lt_inv_of_neg lt_inv_of_neg /-! ### Monotonicity results involving inversion -/ theorem sub_inv_antitoneOn_Ioi : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Iio : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Icc_right (ha : c < a) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem sub_inv_antitoneOn_Icc_left (ha : b < c) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem inv_antitoneOn_Ioi : AntitoneOn (fun x:α ↦ x⁻¹) (Set.Ioi 0) := by convert sub_inv_antitoneOn_Ioi exact (sub_zero _).symm theorem inv_antitoneOn_Iio : AntitoneOn (fun x:α ↦ x⁻¹) (Set.Iio 0) := by convert sub_inv_antitoneOn_Iio exact (sub_zero _).symm theorem inv_antitoneOn_Icc_right (ha : 0 < a) : AntitoneOn (fun x:α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_right ha exact (sub_zero _).symm theorem inv_antitoneOn_Icc_left (hb : b < 0) : AntitoneOn (fun x:α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_left hb exact (sub_zero _).symm /-! ### Relating two divisions -/ theorem div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc) #align div_le_div_of_nonpos_of_le div_le_div_of_nonpos_of_le theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc) #align div_lt_div_of_neg_of_lt div_lt_div_of_neg_of_lt theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a := ⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩ #align div_le_div_right_of_neg div_le_div_right_of_neg theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a := lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc #align div_lt_div_right_of_neg div_lt_div_right_of_neg /-! ### Relating one division and involving `1` -/ theorem one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b := by rw [le_div_iff_of_neg hb, one_mul] #align one_le_div_of_neg one_le_div_of_neg theorem div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a := by rw [div_le_iff_of_neg hb, one_mul] #align div_le_one_of_neg div_le_one_of_neg theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul] #align one_lt_div_of_neg one_lt_div_of_neg theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul] #align div_lt_one_of_neg div_lt_one_of_neg theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le_of_neg ha hb #align one_div_le_of_neg one_div_le_of_neg theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_of_neg ha hb #align one_div_lt_of_neg one_div_lt_of_neg theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_of_neg ha hb #align le_one_div_of_neg le_one_div_of_neg theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_of_neg ha hb #align lt_one_div_of_neg lt_one_div_of_neg theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_lt_div_of_neg] · simp [lt_irrefl, zero_le_one] · simp [hb, hb.not_lt, one_lt_div] #align one_lt_div_iff one_lt_div_iff theorem one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_le_div_of_neg] · simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] · simp [hb, hb.not_lt, one_le_div] #align one_le_div_iff one_le_div_iff theorem div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] · simp [zero_lt_one] · simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] #align div_lt_one_iff div_lt_one_iff theorem div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] · simp [zero_le_one] · simp [hb, hb.not_lt, div_le_one, hb.ne.symm] #align div_le_one_iff div_le_one_iff /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a := by rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)] #align one_div_le_one_div_of_neg_of_le one_div_le_one_div_of_neg_of_le theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)] #align one_div_lt_one_div_of_neg_of_lt one_div_lt_one_div_of_neg_of_lt theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h #align le_of_neg_of_one_div_le_one_div le_of_neg_of_one_div_le_one_div theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h #align lt_of_neg_of_one_div_lt_one_div lt_of_neg_of_one_div_lt_one_div /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a := by simpa [one_div] using inv_le_inv_of_neg ha hb #align one_div_le_one_div_of_neg one_div_le_one_div_of_neg /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a := lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha) #align one_div_lt_one_div_of_neg one_div_lt_one_div_of_neg theorem one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 := suffices 1 / a < 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_lt_one_div_of_neg_of_lt h1 h2 #align one_div_lt_neg_one one_div_lt_neg_one theorem one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≤ a) : 1 / a ≤ -1 := suffices 1 / a ≤ 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_le_one_div_of_neg_of_le h1 h2 #align one_div_le_neg_one one_div_le_neg_one /-! ### Results about halving -/ theorem sub_self_div_two (a : α) : a - a / 2 = a / 2 := by suffices a / 2 + a / 2 - a / 2 = a / 2 by rwa [add_halves] at this rw [add_sub_cancel_right] #align sub_self_div_two sub_self_div_two theorem div_two_sub_self (a : α) : a / 2 - a = -(a / 2) := by suffices a / 2 - (a / 2 + a / 2) = -(a / 2) by rwa [add_halves] at this rw [sub_add_eq_sub_sub, sub_self, zero_sub] #align div_two_sub_self div_two_sub_self theorem add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := by rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b / 2), ← add_assoc, ← sub_eq_add_neg, ← lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_right (zero_lt_two' α)] #align add_sub_div_two_lt add_sub_div_two_lt /-- An inequality involving `2`. -/ theorem sub_one_div_inv_le_two (a2 : 2 ≤ a) : (1 - 1 / a)⁻¹ ≤ 2 := by -- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a` refine (inv_le_inv_of_le (inv_pos.2 <| zero_lt_two' α) ?_).trans_eq (inv_inv (2 : α)) -- move `1 / a` to the left and `2⁻¹` to the right. rw [le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le] -- take inverses on both sides and use the assumption `2 ≤ a`. convert (one_div a).le.trans (inv_le_inv_of_le zero_lt_two a2) using 1 -- show `1 - 1 / 2 = 1 / 2`. rw [sub_eq_iff_eq_add, ← two_mul, mul_inv_cancel two_ne_zero] #align sub_one_div_inv_le_two sub_one_div_inv_le_two /-! ### Results about `IsLUB` -/ -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) : IsLUB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) · exact (OrderIso.mulLeft₀ _ ha).isLUB_image'.2 hs · simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isLUB_singleton #align is_lub.mul_left IsLUB.mul_left -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) : IsLUB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha #align is_lub.mul_right IsLUB.mul_right /-! ### Miscellaneous lemmas -/
Mathlib/Algebra/Order/Field/Basic.lean
952
954
theorem mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) : (a * d - b * c) / (c * d) < 0 ↔ a / c < b / d := by
rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero]
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Geißer, Michael Stoll -/ import Mathlib.Tactic.Qify import Mathlib.Data.ZMod.Basic import Mathlib.NumberTheory.DiophantineApproximation import Mathlib.NumberTheory.Zsqrtd.Basic #align_import number_theory.pell from "leanprover-community/mathlib"@"7ad820c4997738e2f542f8a20f32911f52020e26" /-! # Pell's Equation *Pell's Equation* is the equation $x^2 - d y^2 = 1$, where $d$ is a positive integer that is not a square, and one is interested in solutions in integers $x$ and $y$. In this file, we aim at providing all of the essential theory of Pell's Equation for general $d$ (as opposed to the contents of `NumberTheory.PellMatiyasevic`, which is specific to the case $d = a^2 - 1$ for some $a > 1$). We begin by defining a type `Pell.Solution₁ d` for solutions of the equation, show that it has a natural structure as an abelian group, and prove some basic properties. We then prove the following **Theorem.** Let $d$ be a positive integer that is not a square. Then the equation $x^2 - d y^2 = 1$ has a nontrivial (i.e., with $y \ne 0$) solution in integers. See `Pell.exists_of_not_isSquare` and `Pell.Solution₁.exists_nontrivial_of_not_isSquare`. We then define the *fundamental solution* to be the solution with smallest $x$ among all solutions satisfying $x > 1$ and $y > 0$. We show that every solution is a power (in the sense of the group structure mentioned above) of the fundamental solution up to a (common) sign, see `Pell.IsFundamental.eq_zpow_or_neg_zpow`, and that a (positive) solution has this property if and only if it is fundamental, see `Pell.pos_generator_iff_fundamental`. ## References * [K. Ireland, M. Rosen, *A classical introduction to modern number theory* (Section 17.5)][IrelandRosen1990] ## Tags Pell's equation ## TODO * Extend to `x ^ 2 - d * y ^ 2 = -1` and further generalizations. * Connect solutions to the continued fraction expansion of `√d`. -/ namespace Pell /-! ### Group structure of the solution set We define a structure of a commutative multiplicative group with distributive negation on the set of all solutions to the Pell equation `x^2 - d*y^2 = 1`. The type of such solutions is `Pell.Solution₁ d`. It corresponds to a pair of integers `x` and `y` and a proof that `(x, y)` is indeed a solution. The multiplication is given by `(x, y) * (x', y') = (x*y' + d*y*y', x*y' + y*x')`. This is obtained by mapping `(x, y)` to `x + y*√d` and multiplying the results. In fact, we define `Pell.Solution₁ d` to be `↥(unitary (ℤ√d))` and transport the "commutative group with distributive negation" structure from `↥(unitary (ℤ√d))`. We then set up an API for `Pell.Solution₁ d`. -/ open Zsqrtd /-- An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if it is contained in the submonoid of unitary elements. TODO: merge this result with `Pell.isPell_iff_mem_unitary`. -/ theorem is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} : a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary (ℤ√d) := by rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc] #align pell.is_pell_solution_iff_mem_unitary Pell.is_pell_solution_iff_mem_unitary -- We use `solution₁ d` to allow for a more general structure `solution d m` that -- encodes solutions to `x^2 - d*y^2 = m` to be added later. /-- `Pell.Solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`. We define this in terms of elements of `ℤ√d` of norm one. -/ def Solution₁ (d : ℤ) : Type := ↥(unitary (ℤ√d)) #align pell.solution₁ Pell.Solution₁ namespace Solution₁ variable {d : ℤ} -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020): manual deriving instance instCommGroup : CommGroup (Solution₁ d) := inferInstanceAs (CommGroup (unitary (ℤ√d))) #align pell.solution₁.comm_group Pell.Solution₁.instCommGroup instance instHasDistribNeg : HasDistribNeg (Solution₁ d) := inferInstanceAs (HasDistribNeg (unitary (ℤ√d))) #align pell.solution₁.has_distrib_neg Pell.Solution₁.instHasDistribNeg instance instInhabited : Inhabited (Solution₁ d) := inferInstanceAs (Inhabited (unitary (ℤ√d))) #align pell.solution₁.inhabited Pell.Solution₁.instInhabited instance : Coe (Solution₁ d) (ℤ√d) where coe := Subtype.val /-- The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/ protected def x (a : Solution₁ d) : ℤ := (a : ℤ√d).re #align pell.solution₁.x Pell.Solution₁.x /-- The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/ protected def y (a : Solution₁ d) : ℤ := (a : ℤ√d).im #align pell.solution₁.y Pell.Solution₁.y /-- The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1` -/ theorem prop (a : Solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 := is_pell_solution_iff_mem_unitary.mpr a.property #align pell.solution₁.prop Pell.Solution₁.prop /-- An alternative form of the equation, suitable for rewriting `x^2`. -/ theorem prop_x (a : Solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by rw [← a.prop]; ring #align pell.solution₁.prop_x Pell.Solution₁.prop_x /-- An alternative form of the equation, suitable for rewriting `d * y^2`. -/ theorem prop_y (a : Solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by rw [← a.prop]; ring #align pell.solution₁.prop_y Pell.Solution₁.prop_y /-- Two solutions are equal if their `x` and `y` components are equal. -/ @[ext] theorem ext {a b : Solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b := Subtype.ext <| Zsqrtd.ext _ _ hx hy #align pell.solution₁.ext Pell.Solution₁.ext /-- Construct a solution from `x`, `y` and a proof that the equation is satisfied. -/ def mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : Solution₁ d where val := ⟨x, y⟩ property := is_pell_solution_iff_mem_unitary.mp prop #align pell.solution₁.mk Pell.Solution₁.mk @[simp] theorem x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x := rfl #align pell.solution₁.x_mk Pell.Solution₁.x_mk @[simp] theorem y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y := rfl #align pell.solution₁.y_mk Pell.Solution₁.y_mk @[simp] theorem coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x, y⟩ := Zsqrtd.ext _ _ (x_mk x y prop) (y_mk x y prop) #align pell.solution₁.coe_mk Pell.Solution₁.coe_mk @[simp] theorem x_one : (1 : Solution₁ d).x = 1 := rfl #align pell.solution₁.x_one Pell.Solution₁.x_one @[simp] theorem y_one : (1 : Solution₁ d).y = 0 := rfl #align pell.solution₁.y_one Pell.Solution₁.y_one @[simp] theorem x_mul (a b : Solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by rw [← mul_assoc] rfl #align pell.solution₁.x_mul Pell.Solution₁.x_mul @[simp] theorem y_mul (a b : Solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x := rfl #align pell.solution₁.y_mul Pell.Solution₁.y_mul @[simp] theorem x_inv (a : Solution₁ d) : a⁻¹.x = a.x := rfl #align pell.solution₁.x_inv Pell.Solution₁.x_inv @[simp] theorem y_inv (a : Solution₁ d) : a⁻¹.y = -a.y := rfl #align pell.solution₁.y_inv Pell.Solution₁.y_inv @[simp] theorem x_neg (a : Solution₁ d) : (-a).x = -a.x := rfl #align pell.solution₁.x_neg Pell.Solution₁.x_neg @[simp] theorem y_neg (a : Solution₁ d) : (-a).y = -a.y := rfl #align pell.solution₁.y_neg Pell.Solution₁.y_neg /-- When `d` is negative, then `x` or `y` must be zero in a solution. -/ theorem eq_zero_of_d_neg (h₀ : d < 0) (a : Solution₁ d) : a.x = 0 ∨ a.y = 0 := by have h := a.prop contrapose! h have h1 := sq_pos_of_ne_zero h.1 have h2 := sq_pos_of_ne_zero h.2 nlinarith #align pell.solution₁.eq_zero_of_d_neg Pell.Solution₁.eq_zero_of_d_neg /-- A solution has `x ≠ 0`. -/ theorem x_ne_zero (h₀ : 0 ≤ d) (a : Solution₁ d) : a.x ≠ 0 := by intro hx have h : 0 ≤ d * a.y ^ 2 := mul_nonneg h₀ (sq_nonneg _) rw [a.prop_y, hx, sq, zero_mul, zero_sub] at h exact not_le.mpr (neg_one_lt_zero : (-1 : ℤ) < 0) h #align pell.solution₁.x_ne_zero Pell.Solution₁.x_ne_zero /-- A solution with `x > 1` must have `y ≠ 0`. -/ theorem y_ne_zero_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : a.y ≠ 0 := by intro hy have prop := a.prop rw [hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero] at prop exact lt_irrefl _ (((one_lt_sq_iff <| zero_le_one.trans ha.le).mpr ha).trans_eq prop) #align pell.solution₁.y_ne_zero_of_one_lt_x Pell.Solution₁.y_ne_zero_of_one_lt_x /-- If a solution has `x > 1`, then `d` is positive. -/ theorem d_pos_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : 0 < d := by refine pos_of_mul_pos_left ?_ (sq_nonneg a.y) rw [a.prop_y, sub_pos] exact one_lt_pow ha two_ne_zero #align pell.solution₁.d_pos_of_one_lt_x Pell.Solution₁.d_pos_of_one_lt_x /-- If a solution has `x > 1`, then `d` is not a square. -/ theorem d_nonsquare_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : ¬IsSquare d := by have hp := a.prop rintro ⟨b, rfl⟩ simp_rw [← sq, ← mul_pow, sq_sub_sq, Int.mul_eq_one_iff_eq_one_or_neg_one] at hp rcases hp with (⟨hp₁, hp₂⟩ | ⟨hp₁, hp₂⟩) <;> omega #align pell.solution₁.d_nonsquare_of_one_lt_x Pell.Solution₁.d_nonsquare_of_one_lt_x /-- A solution with `x = 1` is trivial. -/ theorem eq_one_of_x_eq_one (h₀ : d ≠ 0) {a : Solution₁ d} (ha : a.x = 1) : a = 1 := by have prop := a.prop_y rw [ha, one_pow, sub_self, mul_eq_zero, or_iff_right h₀, sq_eq_zero_iff] at prop exact ext ha prop #align pell.solution₁.eq_one_of_x_eq_one Pell.Solution₁.eq_one_of_x_eq_one /-- A solution is `1` or `-1` if and only if `y = 0`. -/ theorem eq_one_or_neg_one_iff_y_eq_zero {a : Solution₁ d} : a = 1 ∨ a = -1 ↔ a.y = 0 := by refine ⟨fun H => H.elim (fun h => by simp [h]) fun h => by simp [h], fun H => ?_⟩ have prop := a.prop rw [H, sq (0 : ℤ), mul_zero, mul_zero, sub_zero, sq_eq_one_iff] at prop exact prop.imp (fun h => ext h H) fun h => ext h H #align pell.solution₁.eq_one_or_neg_one_iff_y_eq_zero Pell.Solution₁.eq_one_or_neg_one_iff_y_eq_zero /-- The set of solutions with `x > 0` is closed under multiplication. -/ theorem x_mul_pos {a b : Solution₁ d} (ha : 0 < a.x) (hb : 0 < b.x) : 0 < (a * b).x := by simp only [x_mul] refine neg_lt_iff_pos_add'.mp (abs_lt.mp ?_).1 rw [← abs_of_pos ha, ← abs_of_pos hb, ← abs_mul, ← sq_lt_sq, mul_pow a.x, a.prop_x, b.prop_x, ← sub_pos] ring_nf rcases le_or_lt 0 d with h | h · positivity · rw [(eq_zero_of_d_neg h a).resolve_left ha.ne', (eq_zero_of_d_neg h b).resolve_left hb.ne'] -- Porting note: was -- rw [zero_pow two_ne_zero, zero_add, zero_mul, zero_add] -- exact one_pos -- but this relied on the exact output of `ring_nf` simp #align pell.solution₁.x_mul_pos Pell.Solution₁.x_mul_pos /-- The set of solutions with `x` and `y` positive is closed under multiplication. -/ theorem y_mul_pos {a b : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (hbx : 0 < b.x) (hby : 0 < b.y) : 0 < (a * b).y := by simp only [y_mul] positivity #align pell.solution₁.y_mul_pos Pell.Solution₁.y_mul_pos /-- If `(x, y)` is a solution with `x` positive, then all its powers with natural exponents have positive `x`. -/ theorem x_pow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℕ) : 0 < (a ^ n).x := by induction' n with n ih · simp only [Nat.zero_eq, pow_zero, x_one, zero_lt_one] · rw [pow_succ] exact x_mul_pos ih hax #align pell.solution₁.x_pow_pos Pell.Solution₁.x_pow_pos /-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive natural exponents have positive `y`. -/ theorem y_pow_succ_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℕ) : 0 < (a ^ n.succ).y := by induction' n with n ih · simp only [Nat.zero_eq, ← Nat.one_eq_succ_zero, hay, pow_one] · rw [pow_succ'] exact y_mul_pos hax hay (x_pow_pos hax _) ih #align pell.solution₁.y_pow_succ_pos Pell.Solution₁.y_pow_succ_pos /-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive exponents have positive `y`. -/ theorem y_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) {n : ℤ} (hn : 0 < n) : 0 < (a ^ n).y := by lift n to ℕ using hn.le norm_cast at hn ⊢ rw [← Nat.succ_pred_eq_of_pos hn] exact y_pow_succ_pos hax hay _ #align pell.solution₁.y_zpow_pos Pell.Solution₁.y_zpow_pos /-- If `(x, y)` is a solution with `x` positive, then all its powers have positive `x`. -/ theorem x_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℤ) : 0 < (a ^ n).x := by cases n with | ofNat n => rw [Int.ofNat_eq_coe, zpow_natCast] exact x_pow_pos hax n | negSucc n => rw [zpow_negSucc] exact x_pow_pos hax (n + 1) #align pell.solution₁.x_zpow_pos Pell.Solution₁.x_zpow_pos /-- If `(x, y)` is a solution with `x` and `y` positive, then the `y` component of any power has the same sign as the exponent. -/ theorem sign_y_zpow_eq_sign_of_x_pos_of_y_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℤ) : (a ^ n).y.sign = n.sign := by rcases n with ((_ | n) | n) · rfl · rw [Int.ofNat_eq_coe, zpow_natCast] exact Int.sign_eq_one_of_pos (y_pow_succ_pos hax hay n) · rw [zpow_negSucc] exact Int.sign_eq_neg_one_of_neg (neg_neg_of_pos (y_pow_succ_pos hax hay n)) #align pell.solution₁.sign_y_zpow_eq_sign_of_x_pos_of_y_pos Pell.Solution₁.sign_y_zpow_eq_sign_of_x_pos_of_y_pos /-- If `a` is any solution, then one of `a`, `a⁻¹`, `-a`, `-a⁻¹` has positive `x` and nonnegative `y`. -/ theorem exists_pos_variant (h₀ : 0 < d) (a : Solution₁ d) : ∃ b : Solution₁ d, 0 < b.x ∧ 0 ≤ b.y ∧ a ∈ ({b, b⁻¹, -b, -b⁻¹} : Set (Solution₁ d)) := by refine (lt_or_gt_of_ne (a.x_ne_zero h₀.le)).elim ((le_total 0 a.y).elim (fun hy hx => ⟨-a⁻¹, ?_, ?_, ?_⟩) fun hy hx => ⟨-a, ?_, ?_, ?_⟩) ((le_total 0 a.y).elim (fun hy hx => ⟨a, hx, hy, ?_⟩) fun hy hx => ⟨a⁻¹, hx, ?_, ?_⟩) <;> simp only [neg_neg, inv_inv, neg_inv, Set.mem_insert_iff, Set.mem_singleton_iff, true_or_iff, eq_self_iff_true, x_neg, x_inv, y_neg, y_inv, neg_pos, neg_nonneg, or_true_iff] <;> assumption #align pell.solution₁.exists_pos_variant Pell.Solution₁.exists_pos_variant end Solution₁ section Existence /-! ### Existence of nontrivial solutions -/ variable {d : ℤ} open Set Real /-- If `d` is a positive integer that is not a square, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`. -/ theorem exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0 := by let ξ : ℝ := √d have hξ : Irrational ξ := by refine irrational_nrt_of_notint_nrt 2 d (sq_sqrt <| Int.cast_nonneg.mpr h₀.le) ?_ two_pos rintro ⟨x, hx⟩ refine hd ⟨x, @Int.cast_injective ℝ _ _ d (x * x) ?_⟩ rw [← sq_sqrt <| Int.cast_nonneg.mpr h₀.le, Int.cast_mul, ← hx, sq] obtain ⟨M, hM₁⟩ := exists_int_gt (2 * |ξ| + 1) have hM : {q : ℚ | |q.1 ^ 2 - d * (q.2 : ℤ) ^ 2| < M}.Infinite := by refine Infinite.mono (fun q h => ?_) (infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational hξ) have h0 : 0 < (q.2 : ℝ) ^ 2 := pow_pos (Nat.cast_pos.mpr q.pos) 2 have h1 : (q.num : ℝ) / (q.den : ℝ) = q := mod_cast q.num_div_den rw [mem_setOf, abs_sub_comm, ← @Int.cast_lt ℝ, ← div_lt_div_right (abs_pos_of_pos h0)] push_cast rw [← abs_div, abs_sq, sub_div, mul_div_cancel_right₀ _ h0.ne', ← div_pow, h1, ← sq_sqrt (Int.cast_pos.mpr h₀).le, sq_sub_sq, abs_mul, ← mul_one_div] refine mul_lt_mul'' (((abs_add ξ q).trans ?_).trans_lt hM₁) h (abs_nonneg _) (abs_nonneg _) rw [two_mul, add_assoc, add_le_add_iff_left, ← sub_le_iff_le_add'] rw [mem_setOf, abs_sub_comm] at h refine (abs_sub_abs_le_abs_sub (q : ℝ) ξ).trans (h.le.trans ?_) rw [div_le_one h0, one_le_sq_iff_one_le_abs, Nat.abs_cast, Nat.one_le_cast] exact q.pos obtain ⟨m, hm⟩ : ∃ m : ℤ, {q : ℚ | q.1 ^ 2 - d * (q.den : ℤ) ^ 2 = m}.Infinite := by contrapose! hM simp only [not_infinite] at hM ⊢ refine (congr_arg _ (ext fun x => ?_)).mp (Finite.biUnion (finite_Ioo (-M) M) fun m _ => hM m) simp only [abs_lt, mem_setOf, mem_Ioo, mem_iUnion, exists_prop, exists_eq_right'] have hm₀ : m ≠ 0 := by rintro rfl obtain ⟨q, hq⟩ := hm.nonempty rw [mem_setOf, sub_eq_zero, mul_comm] at hq obtain ⟨a, ha⟩ := (Int.pow_dvd_pow_iff two_ne_zero).mp ⟨d, hq⟩ rw [ha, mul_pow, mul_right_inj' (pow_pos (Int.natCast_pos.mpr q.pos) 2).ne'] at hq exact hd ⟨a, sq a ▸ hq.symm⟩ haveI := neZero_iff.mpr (Int.natAbs_ne_zero.mpr hm₀) let f : ℚ → ZMod m.natAbs × ZMod m.natAbs := fun q => (q.num, q.den) obtain ⟨q₁, h₁ : q₁.num ^ 2 - d * (q₁.den : ℤ) ^ 2 = m, q₂, h₂ : q₂.num ^ 2 - d * (q₂.den : ℤ) ^ 2 = m, hne, hqf⟩ := hm.exists_ne_map_eq_of_mapsTo (mapsTo_univ f _) finite_univ obtain ⟨hq1 : (q₁.num : ZMod m.natAbs) = q₂.num, hq2 : (q₁.den : ZMod m.natAbs) = q₂.den⟩ := Prod.ext_iff.mp hqf have hd₁ : m ∣ q₁.num * q₂.num - d * (q₁.den * q₂.den) := by rw [← Int.natAbs_dvd, ← ZMod.intCast_zmod_eq_zero_iff_dvd] push_cast rw [hq1, hq2, ← sq, ← sq] norm_cast rw [ZMod.intCast_zmod_eq_zero_iff_dvd, Int.natAbs_dvd, Nat.cast_pow, ← h₂] have hd₂ : m ∣ q₁.num * q₂.den - q₂.num * q₁.den := by rw [← Int.natAbs_dvd, ← ZMod.intCast_eq_intCast_iff_dvd_sub] push_cast rw [hq1, hq2] replace hm₀ : (m : ℚ) ≠ 0 := Int.cast_ne_zero.mpr hm₀ refine ⟨(q₁.num * q₂.num - d * (q₁.den * q₂.den)) / m, (q₁.num * q₂.den - q₂.num * q₁.den) / m, ?_, ?_⟩ · qify [hd₁, hd₂] field_simp [hm₀] norm_cast conv_rhs => rw [sq] congr · rw [← h₁] · rw [← h₂] push_cast ring · qify [hd₂] refine div_ne_zero_iff.mpr ⟨?_, hm₀⟩ exact mod_cast mt sub_eq_zero.mp (mt Rat.eq_iff_mul_eq_mul.mpr hne) #align pell.exists_of_not_is_square Pell.exists_of_not_isSquare /-- If `d` is a positive integer, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1` if and only if `d` is not a square. -/ theorem exists_iff_not_isSquare (h₀ : 0 < d) : (∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0) ↔ ¬IsSquare d := by refine ⟨?_, exists_of_not_isSquare h₀⟩ rintro ⟨x, y, hxy, hy⟩ ⟨a, rfl⟩ rw [← sq, ← mul_pow, sq_sub_sq] at hxy simpa [hy, mul_self_pos.mp h₀, sub_eq_add_neg, eq_neg_self_iff] using Int.eq_of_mul_eq_one hxy #align pell.exists_iff_not_is_square Pell.exists_iff_not_isSquare namespace Solution₁ /-- If `d` is a positive integer that is not a square, then there exists a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`. -/ theorem exists_nontrivial_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, a ≠ 1 ∧ a ≠ -1 := by obtain ⟨x, y, prop, hy⟩ := exists_of_not_isSquare h₀ hd refine ⟨mk x y prop, fun H => ?_, fun H => ?_⟩ <;> apply_fun Solution₁.y at H <;> simp [hy] at H #align pell.solution₁.exists_nontrivial_of_not_is_square Pell.Solution₁.exists_nontrivial_of_not_isSquare /-- If `d` is a positive integer that is not a square, then there exists a solution to the Pell equation `x^2 - d*y^2 = 1` with `x > 1` and `y > 0`. -/ theorem exists_pos_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, 1 < a.x ∧ 0 < a.y := by obtain ⟨x, y, h, hy⟩ := exists_of_not_isSquare h₀ hd refine ⟨mk |x| |y| (by rwa [sq_abs, sq_abs]), ?_, abs_pos.mpr hy⟩ rw [x_mk, ← one_lt_sq_iff_one_lt_abs, eq_add_of_sub_eq h, lt_add_iff_pos_right] exact mul_pos h₀ (sq_pos_of_ne_zero hy) #align pell.solution₁.exists_pos_of_not_is_square Pell.Solution₁.exists_pos_of_not_isSquare end Solution₁ end Existence /-! ### Fundamental solutions We define the notion of a *fundamental solution* of Pell's equation and show that it exists and is unique (when `d` is positive and non-square) and generates the group of solutions up to sign. -/ variable {d : ℤ} /-- We define a solution to be *fundamental* if it has `x > 1` and `y > 0` and its `x` is the smallest possible among solutions with `x > 1`. -/ def IsFundamental (a : Solution₁ d) : Prop := 1 < a.x ∧ 0 < a.y ∧ ∀ {b : Solution₁ d}, 1 < b.x → a.x ≤ b.x #align pell.is_fundamental Pell.IsFundamental namespace IsFundamental open Solution₁ /-- A fundamental solution has positive `x`. -/ theorem x_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < a.x := zero_lt_one.trans h.1 #align pell.is_fundamental.x_pos Pell.IsFundamental.x_pos /-- If a fundamental solution exists, then `d` must be positive. -/ theorem d_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < d := d_pos_of_one_lt_x h.1 #align pell.is_fundamental.d_pos Pell.IsFundamental.d_pos /-- If a fundamental solution exists, then `d` must be a non-square. -/ theorem d_nonsquare {a : Solution₁ d} (h : IsFundamental a) : ¬IsSquare d := d_nonsquare_of_one_lt_x h.1 #align pell.is_fundamental.d_nonsquare Pell.IsFundamental.d_nonsquare /-- If there is a fundamental solution, it is unique. -/ theorem subsingleton {a b : Solution₁ d} (ha : IsFundamental a) (hb : IsFundamental b) : a = b := by have hx := le_antisymm (ha.2.2 hb.1) (hb.2.2 ha.1) refine Solution₁.ext hx ?_ have : d * a.y ^ 2 = d * b.y ^ 2 := by rw [a.prop_y, b.prop_y, hx] exact (sq_eq_sq ha.2.1.le hb.2.1.le).mp (Int.eq_of_mul_eq_mul_left ha.d_pos.ne' this) #align pell.is_fundamental.subsingleton Pell.IsFundamental.subsingleton /-- If `d` is positive and not a square, then a fundamental solution exists. -/ theorem exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) : ∃ a : Solution₁ d, IsFundamental a := by obtain ⟨a, ha₁, ha₂⟩ := exists_pos_of_not_isSquare h₀ hd -- convert to `x : ℕ` to be able to use `Nat.find` have P : ∃ x' : ℕ, 1 < x' ∧ ∃ y' : ℤ, 0 < y' ∧ (x' : ℤ) ^ 2 - d * y' ^ 2 = 1 := by have hax := a.prop lift a.x to ℕ using by positivity with ax norm_cast at ha₁ exact ⟨ax, ha₁, a.y, ha₂, hax⟩ classical -- to avoid having to show that the predicate is decidable let x₁ := Nat.find P obtain ⟨hx, y₁, hy₀, hy₁⟩ := Nat.find_spec P refine ⟨mk x₁ y₁ hy₁, by rw [x_mk]; exact mod_cast hx, hy₀, fun {b} hb => ?_⟩ rw [x_mk] have hb' := (Int.toNat_of_nonneg <| zero_le_one.trans hb.le).symm have hb'' := hb rw [hb'] at hb ⊢ norm_cast at hb ⊢ refine Nat.find_min' P ⟨hb, |b.y|, abs_pos.mpr <| y_ne_zero_of_one_lt_x hb'', ?_⟩ rw [← hb', sq_abs] exact b.prop #align pell.is_fundamental.exists_of_not_is_square Pell.IsFundamental.exists_of_not_isSquare /-- The map sending an integer `n` to the `y`-coordinate of `a^n` for a fundamental solution `a` is stritcly increasing. -/ theorem y_strictMono {a : Solution₁ d} (h : IsFundamental a) : StrictMono fun n : ℤ => (a ^ n).y := by have H : ∀ n : ℤ, 0 ≤ n → (a ^ n).y < (a ^ (n + 1)).y := by intro n hn rw [← sub_pos, zpow_add, zpow_one, y_mul, add_sub_assoc] rw [show (a ^ n).y * a.x - (a ^ n).y = (a ^ n).y * (a.x - 1) by ring] refine add_pos_of_pos_of_nonneg (mul_pos (x_zpow_pos h.x_pos _) h.2.1) (mul_nonneg ?_ (by rw [sub_nonneg]; exact h.1.le)) rcases hn.eq_or_lt with (rfl | hn) · simp only [zpow_zero, y_one, le_refl] · exact (y_zpow_pos h.x_pos h.2.1 hn).le refine strictMono_int_of_lt_succ fun n => ?_ rcases le_or_lt 0 n with hn | hn · exact H n hn · let m : ℤ := -n - 1 have hm : n = -m - 1 := by simp only [m, neg_sub, sub_neg_eq_add, add_tsub_cancel_left] rw [hm, sub_add_cancel, ← neg_add', zpow_neg, zpow_neg, y_inv, y_inv, neg_lt_neg_iff] exact H _ (by omega) #align pell.is_fundamental.y_strict_mono Pell.IsFundamental.y_strictMono /-- If `a` is a fundamental solution, then `(a^m).y < (a^n).y` if and only if `m < n`. -/ theorem zpow_y_lt_iff_lt {a : Solution₁ d} (h : IsFundamental a) (m n : ℤ) : (a ^ m).y < (a ^ n).y ↔ m < n := by refine ⟨fun H => ?_, fun H => h.y_strictMono H⟩ contrapose! H exact h.y_strictMono.monotone H #align pell.is_fundamental.zpow_y_lt_iff_lt Pell.IsFundamental.zpow_y_lt_iff_lt /-- The `n`th power of a fundamental solution is trivial if and only if `n = 0`. -/ theorem zpow_eq_one_iff {a : Solution₁ d} (h : IsFundamental a) (n : ℤ) : a ^ n = 1 ↔ n = 0 := by rw [← zpow_zero a] exact ⟨fun H => h.y_strictMono.injective (congr_arg Solution₁.y H), fun H => H ▸ rfl⟩ #align pell.is_fundamental.zpow_eq_one_iff Pell.IsFundamental.zpow_eq_one_iff /-- A power of a fundamental solution is never equal to the negative of a power of this fundamental solution. -/ theorem zpow_ne_neg_zpow {a : Solution₁ d} (h : IsFundamental a) {n n' : ℤ} : a ^ n ≠ -a ^ n' := by intro hf apply_fun Solution₁.x at hf have H := x_zpow_pos h.x_pos n rw [hf, x_neg, lt_neg, neg_zero] at H exact lt_irrefl _ ((x_zpow_pos h.x_pos n').trans H) #align pell.is_fundamental.zpow_ne_neg_zpow Pell.IsFundamental.zpow_ne_neg_zpow /-- The `x`-coordinate of a fundamental solution is a lower bound for the `x`-coordinate of any positive solution. -/ theorem x_le_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) : a₁.x ≤ a.x := h.2.2 hax #align pell.is_fundamental.x_le_x Pell.IsFundamental.x_le_x /-- The `y`-coordinate of a fundamental solution is a lower bound for the `y`-coordinate of any positive solution. -/ theorem y_le_y {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a₁.y ≤ a.y := by have H : d * (a₁.y ^ 2 - a.y ^ 2) = a₁.x ^ 2 - a.x ^ 2 := by rw [a.prop_x, a₁.prop_x]; ring rw [← abs_of_pos hay, ← abs_of_pos h.2.1, ← sq_le_sq, ← mul_le_mul_left h.d_pos, ← sub_nonpos, ← mul_sub, H, sub_nonpos, sq_le_sq, abs_of_pos (zero_lt_one.trans h.1), abs_of_pos (zero_lt_one.trans hax)] exact h.x_le_x hax #align pell.is_fundamental.y_le_y Pell.IsFundamental.y_le_y -- helper lemma for the next three results theorem x_mul_y_le_y_mul_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a.x * a₁.y ≤ a.y * a₁.x := by rw [← abs_of_pos <| zero_lt_one.trans hax, ← abs_of_pos hay, ← abs_of_pos h.x_pos, ← abs_of_pos h.2.1, ← abs_mul, ← abs_mul, ← sq_le_sq, mul_pow, mul_pow, a.prop_x, a₁.prop_x, ← sub_nonneg] ring_nf rw [sub_nonneg, sq_le_sq, abs_of_pos hay, abs_of_pos h.2.1] exact h.y_le_y hax hay #align pell.is_fundamental.x_mul_y_le_y_mul_x Pell.IsFundamental.x_mul_y_le_y_mul_x /-- If we multiply a positive solution with the inverse of a fundamental solution, the `y`-coordinate remains nonnegative. -/ theorem mul_inv_y_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 ≤ (a * a₁⁻¹).y := by simpa only [y_inv, mul_neg, y_mul, le_neg_add_iff_add_le, add_zero] using h.x_mul_y_le_y_mul_x hax hay #align pell.is_fundamental.mul_inv_y_nonneg Pell.IsFundamental.mul_inv_y_nonneg /-- If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate stays positive. -/ theorem mul_inv_x_pos {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 < (a * a₁⁻¹).x := by simp only [x_mul, x_inv, y_inv, mul_neg, lt_add_neg_iff_add_lt, zero_add] refine (mul_lt_mul_left <| zero_lt_one.trans hax).mp ?_ rw [(by ring : a.x * (d * (a.y * a₁.y)) = d * a.y * (a.x * a₁.y))] refine ((mul_le_mul_left <| mul_pos h.d_pos hay).mpr <| x_mul_y_le_y_mul_x h hax hay).trans_lt ?_ rw [← mul_assoc, mul_assoc d, ← sq, a.prop_y, ← sub_pos] ring_nf exact zero_lt_one.trans h.1 #align pell.is_fundamental.mul_inv_x_pos Pell.IsFundamental.mul_inv_x_pos /-- If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate decreases. -/ theorem mul_inv_x_lt_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : (a * a₁⁻¹).x < a.x := by simp only [x_mul, x_inv, y_inv, mul_neg, add_neg_lt_iff_le_add'] refine (mul_lt_mul_left h.2.1).mp ?_ rw [(by ring : a₁.y * (a.x * a₁.x) = a.x * a₁.y * a₁.x)] refine ((mul_le_mul_right <| zero_lt_one.trans h.1).mpr <| x_mul_y_le_y_mul_x h hax hay).trans_lt ?_ rw [mul_assoc, ← sq, a₁.prop_x, ← sub_neg] -- Porting note: was `ring_nf` suffices a.y - a.x * a₁.y < 0 by convert this using 1; ring rw [sub_neg, ← abs_of_pos hay, ← abs_of_pos h.2.1, ← abs_of_pos <| zero_lt_one.trans hax, ← abs_mul, ← sq_lt_sq, mul_pow, a.prop_x] calc a.y ^ 2 = 1 * a.y ^ 2 := (one_mul _).symm _ ≤ d * a.y ^ 2 := (mul_le_mul_right <| sq_pos_of_pos hay).mpr h.d_pos _ < d * a.y ^ 2 + 1 := lt_add_one _ _ = (1 + d * a.y ^ 2) * 1 := by rw [add_comm, mul_one] _ ≤ (1 + d * a.y ^ 2) * a₁.y ^ 2 := (mul_le_mul_left (by have := h.d_pos; positivity)).mpr (sq_pos_of_pos h.2.1) #align pell.is_fundamental.mul_inv_x_lt_x Pell.IsFundamental.mul_inv_x_lt_x /-- Any nonnegative solution is a power with nonnegative exponent of a fundamental solution. -/ theorem eq_pow_of_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 ≤ a.y) : ∃ n : ℕ, a = a₁ ^ n := by lift a.x to ℕ using hax.le with ax hax' -- Porting note: added clear hax induction' ax using Nat.strong_induction_on with x ih generalizing a rcases hay.eq_or_lt with hy | hy · -- case 1: `a = 1` refine ⟨0, ?_⟩ simp only [pow_zero] ext <;> simp only [x_one, y_one] · have prop := a.prop rw [← hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero, sq_eq_one_iff] at prop refine prop.resolve_right fun hf => ?_ have := (hax.trans_eq hax').le.trans_eq hf norm_num at this · exact hy.symm · -- case 2: `a ≥ a₁` have hx₁ : 1 < a.x := by nlinarith [a.prop, h.d_pos] have hxx₁ := h.mul_inv_x_pos hx₁ hy have hxx₂ := h.mul_inv_x_lt_x hx₁ hy have hyy := h.mul_inv_y_nonneg hx₁ hy lift (a * a₁⁻¹).x to ℕ using hxx₁.le with x' hx' -- Porting note: `ih` has its arguments in a different order compared to lean 3. obtain ⟨n, hn⟩ := ih x' (mod_cast hxx₂.trans_eq hax'.symm) hyy hx' hxx₁ exact ⟨n + 1, by rw [pow_succ', ← hn, mul_comm a, ← mul_assoc, mul_inv_self, one_mul]⟩ #align pell.is_fundamental.eq_pow_of_nonneg Pell.IsFundamental.eq_pow_of_nonneg /-- Every solution is, up to a sign, a power of a given fundamental solution. -/
Mathlib/NumberTheory/Pell.lean
691
701
theorem eq_zpow_or_neg_zpow {a₁ : Solution₁ d} (h : IsFundamental a₁) (a : Solution₁ d) : ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := by
obtain ⟨b, hbx, hby, hb⟩ := exists_pos_variant h.d_pos a obtain ⟨n, hn⟩ := h.eq_pow_of_nonneg hbx hby rcases hb with (rfl | rfl | rfl | hb) · exact ⟨n, Or.inl (mod_cast hn)⟩ · exact ⟨-n, Or.inl (by simp [hn])⟩ · exact ⟨n, Or.inr (by simp [hn])⟩ · rw [Set.mem_singleton_iff] at hb rw [hb] exact ⟨-n, Or.inr (by simp [hn])⟩
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Order.Archimedean import Mathlib.Order.Filter.AtTopBot import Mathlib.Tactic.GCongr #align_import order.filter.archimedean from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # `Filter.atTop` filter and archimedean (semi)rings/fields In this file we prove that for a linear ordered archimedean semiring `R` and a function `f : α → ℕ`, the function `Nat.cast ∘ f : α → R` tends to `Filter.atTop` along a filter `l` if and only if so does `f`. We also prove that `Nat.cast : ℕ → R` tends to `Filter.atTop` along `Filter.atTop`, as well as version of these two results for `ℤ` (and a ring `R`) and `ℚ` (and a field `R`). -/ variable {α R : Type*} open Filter Set Function @[simp] theorem Nat.comap_cast_atTop [StrictOrderedSemiring R] [Archimedean R] : comap ((↑) : ℕ → R) atTop = atTop := comap_embedding_atTop (fun _ _ => Nat.cast_le) exists_nat_ge #align nat.comap_coe_at_top Nat.comap_cast_atTop theorem tendsto_natCast_atTop_iff [StrictOrderedSemiring R] [Archimedean R] {f : α → ℕ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := tendsto_atTop_embedding (fun _ _ => Nat.cast_le) exists_nat_ge #align tendsto_coe_nat_at_top_iff tendsto_natCast_atTop_iff @[deprecated (since := "2024-04-17")] alias tendsto_nat_cast_atTop_iff := tendsto_natCast_atTop_iff theorem tendsto_natCast_atTop_atTop [OrderedSemiring R] [Archimedean R] : Tendsto ((↑) : ℕ → R) atTop atTop := Nat.mono_cast.tendsto_atTop_atTop exists_nat_ge #align tendsto_coe_nat_at_top_at_top tendsto_natCast_atTop_atTop @[deprecated (since := "2024-04-17")] alias tendsto_nat_cast_atTop_atTop := tendsto_natCast_atTop_atTop theorem Filter.Eventually.natCast_atTop [OrderedSemiring R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x:R) in atTop, p x) : ∀ᶠ (n:ℕ) in atTop, p n := tendsto_natCast_atTop_atTop.eventually h @[deprecated (since := "2024-04-17")] alias Filter.Eventually.nat_cast_atTop := Filter.Eventually.natCast_atTop @[simp] theorem Int.comap_cast_atTop [StrictOrderedRing R] [Archimedean R] : comap ((↑) : ℤ → R) atTop = atTop := comap_embedding_atTop (fun _ _ => Int.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge r; ⟨n, mod_cast hn⟩ #align int.comap_coe_at_top Int.comap_cast_atTop @[simp] theorem Int.comap_cast_atBot [StrictOrderedRing R] [Archimedean R] : comap ((↑) : ℤ → R) atBot = atBot := comap_embedding_atBot (fun _ _ => Int.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge (-r) ⟨-n, by simpa [neg_le] using hn⟩ #align int.comap_coe_at_bot Int.comap_cast_atBot theorem tendsto_intCast_atTop_iff [StrictOrderedRing R] [Archimedean R] {f : α → ℤ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := by rw [← @Int.comap_cast_atTop R, tendsto_comap_iff]; rfl #align tendsto_coe_int_at_top_iff tendsto_intCast_atTop_iff @[deprecated (since := "2024-04-17")] alias tendsto_int_cast_atTop_iff := tendsto_intCast_atTop_iff theorem tendsto_intCast_atBot_iff [StrictOrderedRing R] [Archimedean R] {f : α → ℤ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atBot ↔ Tendsto f l atBot := by rw [← @Int.comap_cast_atBot R, tendsto_comap_iff]; rfl #align tendsto_coe_int_at_bot_iff tendsto_intCast_atBot_iff @[deprecated (since := "2024-04-17")] alias tendsto_int_cast_atBot_iff := tendsto_intCast_atBot_iff theorem tendsto_intCast_atTop_atTop [StrictOrderedRing R] [Archimedean R] : Tendsto ((↑) : ℤ → R) atTop atTop := tendsto_intCast_atTop_iff.2 tendsto_id #align tendsto_coe_int_at_top_at_top tendsto_intCast_atTop_atTop @[deprecated (since := "2024-04-17")] alias tendsto_int_cast_atTop_atTop := tendsto_intCast_atTop_atTop theorem Filter.Eventually.intCast_atTop [StrictOrderedRing R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x:R) in atTop, p x) : ∀ᶠ (n:ℤ) in atTop, p n := by rw [← Int.comap_cast_atTop (R := R)]; exact h.comap _ @[deprecated (since := "2024-04-17")] alias Filter.Eventually.int_cast_atTop := Filter.Eventually.intCast_atTop theorem Filter.Eventually.intCast_atBot [StrictOrderedRing R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x:R) in atBot, p x) : ∀ᶠ (n:ℤ) in atBot, p n := by rw [← Int.comap_cast_atBot (R := R)]; exact h.comap _ @[deprecated (since := "2024-04-17")] alias Filter.Eventually.int_cast_atBot := Filter.Eventually.intCast_atBot @[simp] theorem Rat.comap_cast_atTop [LinearOrderedField R] [Archimedean R] : comap ((↑) : ℚ → R) atTop = atTop := comap_embedding_atTop (fun _ _ => Rat.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge r; ⟨n, by simpa⟩ #align rat.comap_coe_at_top Rat.comap_cast_atTop @[simp] theorem Rat.comap_cast_atBot [LinearOrderedField R] [Archimedean R] : comap ((↑) : ℚ → R) atBot = atBot := comap_embedding_atBot (fun _ _ => Rat.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge (-r) ⟨-n, by simpa [neg_le]⟩ #align rat.comap_coe_at_bot Rat.comap_cast_atBot theorem tendsto_ratCast_atTop_iff [LinearOrderedField R] [Archimedean R] {f : α → ℚ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := by rw [← @Rat.comap_cast_atTop R, tendsto_comap_iff]; rfl #align tendsto_coe_rat_at_top_iff tendsto_ratCast_atTop_iff @[deprecated (since := "2024-04-17")] alias tendsto_rat_cast_atTop_iff := tendsto_ratCast_atTop_iff theorem tendsto_ratCast_atBot_iff [LinearOrderedField R] [Archimedean R] {f : α → ℚ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atBot ↔ Tendsto f l atBot := by rw [← @Rat.comap_cast_atBot R, tendsto_comap_iff]; rfl #align tendsto_coe_rat_at_bot_iff tendsto_ratCast_atBot_iff @[deprecated (since := "2024-04-17")] alias tendsto_rat_cast_atBot_iff := tendsto_ratCast_atBot_iff theorem Filter.Eventually.ratCast_atTop [LinearOrderedField R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x:R) in atTop, p x) : ∀ᶠ (n:ℚ) in atTop, p n := by rw [← Rat.comap_cast_atTop (R := R)]; exact h.comap _ @[deprecated (since := "2024-04-17")] alias Filter.Eventually.rat_cast_atTop := Filter.Eventually.ratCast_atTop theorem Filter.Eventually.ratCast_atBot [LinearOrderedField R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x:R) in atBot, p x) : ∀ᶠ (n:ℚ) in atBot, p n := by rw [← Rat.comap_cast_atBot (R := R)]; exact h.comap _ @[deprecated (since := "2024-04-17")] alias Filter.Eventually.rat_cast_atBot := Filter.Eventually.ratCast_atBot -- Porting note (#10756): new lemma theorem atTop_hasAntitoneBasis_of_archimedean [OrderedSemiring R] [Archimedean R] : (atTop : Filter R).HasAntitoneBasis fun n : ℕ => Ici n := hasAntitoneBasis_atTop.comp_mono Nat.mono_cast tendsto_natCast_atTop_atTop theorem atTop_hasCountableBasis_of_archimedean [StrictOrderedSemiring R] [Archimedean R] : (atTop : Filter R).HasCountableBasis (fun _ : ℕ => True) fun n => Ici n := ⟨atTop_hasAntitoneBasis_of_archimedean.1, to_countable _⟩ #align at_top_countable_basis_of_archimedean atTop_hasCountableBasis_of_archimedean -- Porting note (#11215): TODO: generalize to a `StrictOrderedRing` theorem atBot_hasCountableBasis_of_archimedean [LinearOrderedRing R] [Archimedean R] : (atBot : Filter R).HasCountableBasis (fun _ : ℤ => True) fun m => Iic m := { countable := to_countable _ toHasBasis := atBot_basis.to_hasBasis (fun x _ => let ⟨m, hm⟩ := exists_int_lt x; ⟨m, trivial, Iic_subset_Iic.2 hm.le⟩) fun m _ => ⟨m, trivial, Subset.rfl⟩ } #align at_bot_countable_basis_of_archimedean atBot_hasCountableBasis_of_archimedean instance (priority := 100) atTop_isCountablyGenerated_of_archimedean [StrictOrderedSemiring R] [Archimedean R] : (atTop : Filter R).IsCountablyGenerated := atTop_hasCountableBasis_of_archimedean.isCountablyGenerated #align at_top_countably_generated_of_archimedean atTop_isCountablyGenerated_of_archimedean instance (priority := 100) atBot_isCountablyGenerated_of_archimedean [LinearOrderedRing R] [Archimedean R] : (atBot : Filter R).IsCountablyGenerated := atBot_hasCountableBasis_of_archimedean.isCountablyGenerated #align at_bot_countably_generated_of_archimedean atBot_isCountablyGenerated_of_archimedean namespace Filter variable {l : Filter α} {f : α → R} {r : R} section LinearOrderedSemiring variable [LinearOrderedSemiring R] [Archimedean R] /-- If a function tends to infinity along a filter, then this function multiplied by a positive constant (on the left) also tends to infinity. The archimedean assumption is convenient to get a statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is given in `Filter.Tendsto.const_mul_atTop`). -/ theorem Tendsto.const_mul_atTop' (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => r * f x) l atTop := by refine tendsto_atTop.2 fun b => ?_ obtain ⟨n : ℕ, hn : 1 ≤ n • r⟩ := Archimedean.arch 1 hr rw [nsmul_eq_mul'] at hn filter_upwards [tendsto_atTop.1 hf (n * max b 0)] with x hx calc b ≤ 1 * max b 0 := by { rw [one_mul] exact le_max_left _ _ } _ ≤ r * n * max b 0 := by gcongr _ = r * (n * max b 0) := by rw [mul_assoc] _ ≤ r * f x := by gcongr #align filter.tendsto.const_mul_at_top' Filter.Tendsto.const_mul_atTop' /-- If a function tends to infinity along a filter, then this function multiplied by a positive constant (on the right) also tends to infinity. The archimedean assumption is convenient to get a statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is given in `Filter.Tendsto.atTop_mul_const`). -/ theorem Tendsto.atTop_mul_const' (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atTop := by refine tendsto_atTop.2 fun b => ?_ obtain ⟨n : ℕ, hn : 1 ≤ n • r⟩ := Archimedean.arch 1 hr have hn' : 1 ≤ (n : R) * r := by rwa [nsmul_eq_mul] at hn filter_upwards [tendsto_atTop.1 hf (max b 0 * n)] with x hx calc b ≤ max b 0 * 1 := by { rw [mul_one] exact le_max_left _ _ } _ ≤ max b 0 * (n * r) := by gcongr _ = max b 0 * n * r := by rw [mul_assoc] _ ≤ f x * r := by gcongr #align filter.tendsto.at_top_mul_const' Filter.Tendsto.atTop_mul_const' end LinearOrderedSemiring section LinearOrderedRing variable [LinearOrderedRing R] [Archimedean R] /-- See also `Filter.Tendsto.atTop_mul_const_of_neg` for a version of this lemma for `LinearOrderedField`s which does not require the `Archimedean` assumption. -/ theorem Tendsto.atTop_mul_const_of_neg' (hr : r < 0) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atBot := by simpa only [tendsto_neg_atTop_iff, mul_neg] using hf.atTop_mul_const' (neg_pos.mpr hr) #align filter.tendsto.at_top_mul_neg_const' Filter.Tendsto.atTop_mul_const_of_neg' /-- See also `Filter.Tendsto.atBot_mul_const` for a version of this lemma for `LinearOrderedField`s which does not require the `Archimedean` assumption. -/ theorem Tendsto.atBot_mul_const' (hr : 0 < r) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atBot := by simp only [← tendsto_neg_atTop_iff, ← neg_mul] at hf ⊢ exact hf.atTop_mul_const' hr #align filter.tendsto.at_bot_mul_const' Filter.Tendsto.atBot_mul_const' /-- See also `Filter.Tendsto.atBot_mul_const_of_neg` for a version of this lemma for `LinearOrderedField`s which does not require the `Archimedean` assumption. -/ theorem Tendsto.atBot_mul_const_of_neg' (hr : r < 0) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atTop := by simpa only [mul_neg, tendsto_neg_atBot_iff] using hf.atBot_mul_const' (neg_pos.2 hr) #align filter.tendsto.at_bot_mul_neg_const' Filter.Tendsto.atBot_mul_const_of_neg' @[deprecated (since := "2024-05-06")] alias Tendsto.atTop_mul_neg_const' := Tendsto.atTop_mul_const_of_neg' @[deprecated (since := "2024-05-06")] alias Tendsto.atBot_mul_neg_const' := Tendsto.atBot_mul_const_of_neg' end LinearOrderedRing section LinearOrderedCancelAddCommMonoid variable [LinearOrderedCancelAddCommMonoid R] [Archimedean R]
Mathlib/Order/Filter/Archimedean.lean
267
271
theorem Tendsto.atTop_nsmul_const {f : α → ℕ} (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => f x • r) l atTop := by
refine tendsto_atTop.mpr fun s => ?_ obtain ⟨n : ℕ, hn : s ≤ n • r⟩ := Archimedean.arch s hr exact (tendsto_atTop.mp hf n).mono fun a ha => hn.trans (nsmul_le_nsmul_left hr.le ha)
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Integral.IntegrableOn #align_import measure_theory.function.locally_integrable from "leanprover-community/mathlib"@"08a4542bec7242a5c60f179e4e49de8c0d677b1b" /-! # Locally integrable functions A function is called *locally integrable* (`MeasureTheory.LocallyIntegrable`) if it is integrable on a neighborhood of every point. More generally, it is *locally integrable on `s`* if it is locally integrable on a neighbourhood within `s` of any point of `s`. This file contains properties of locally integrable functions, and integrability results on compact sets. ## Main statements * `Continuous.locallyIntegrable`: A continuous function is locally integrable. * `ContinuousOn.locallyIntegrableOn`: A function which is continuous on `s` is locally integrable on `s`. -/ open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Bornology open scoped Topology Interval ENNReal variable {X Y E F R : Type*} [MeasurableSpace X] [TopologicalSpace X] variable [MeasurableSpace Y] [TopologicalSpace Y] variable [NormedAddCommGroup E] [NormedAddCommGroup F] {f g : X → E} {μ : Measure X} {s : Set X} namespace MeasureTheory section LocallyIntegrableOn /-- A function `f : X → E` is *locally integrable on s*, for `s ⊆ X`, if for every `x ∈ s` there is a neighbourhood of `x` within `s` on which `f` is integrable. (Note this is, in general, strictly weaker than local integrability with respect to `μ.restrict s`.) -/ def LocallyIntegrableOn (f : X → E) (s : Set X) (μ : Measure X := by volume_tac) : Prop := ∀ x : X, x ∈ s → IntegrableAtFilter f (𝓝[s] x) μ #align measure_theory.locally_integrable_on MeasureTheory.LocallyIntegrableOn theorem LocallyIntegrableOn.mono_set (hf : LocallyIntegrableOn f s μ) {t : Set X} (hst : t ⊆ s) : LocallyIntegrableOn f t μ := fun x hx => (hf x <| hst hx).filter_mono (nhdsWithin_mono x hst) #align measure_theory.locally_integrable_on.mono MeasureTheory.LocallyIntegrableOn.mono_set theorem LocallyIntegrableOn.norm (hf : LocallyIntegrableOn f s μ) : LocallyIntegrableOn (fun x => ‖f x‖) s μ := fun t ht => let ⟨U, hU_nhd, hU_int⟩ := hf t ht ⟨U, hU_nhd, hU_int.norm⟩ #align measure_theory.locally_integrable_on.norm MeasureTheory.LocallyIntegrableOn.norm theorem LocallyIntegrableOn.mono (hf : LocallyIntegrableOn f s μ) {g : X → F} (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ x ∂μ, ‖g x‖ ≤ ‖f x‖) : LocallyIntegrableOn g s μ := by intro x hx rcases hf x hx with ⟨t, t_mem, ht⟩ exact ⟨t, t_mem, Integrable.mono ht hg.restrict (ae_restrict_of_ae h)⟩ theorem IntegrableOn.locallyIntegrableOn (hf : IntegrableOn f s μ) : LocallyIntegrableOn f s μ := fun _ _ => ⟨s, self_mem_nhdsWithin, hf⟩ #align measure_theory.integrable_on.locally_integrable_on MeasureTheory.IntegrableOn.locallyIntegrableOn /-- If a function is locally integrable on a compact set, then it is integrable on that set. -/ theorem LocallyIntegrableOn.integrableOn_isCompact (hf : LocallyIntegrableOn f s μ) (hs : IsCompact s) : IntegrableOn f s μ := IsCompact.induction_on hs integrableOn_empty (fun _u _v huv hv => hv.mono_set huv) (fun _u _v hu hv => integrableOn_union.mpr ⟨hu, hv⟩) hf #align measure_theory.locally_integrable_on.integrable_on_is_compact MeasureTheory.LocallyIntegrableOn.integrableOn_isCompact theorem LocallyIntegrableOn.integrableOn_compact_subset (hf : LocallyIntegrableOn f s μ) {t : Set X} (hst : t ⊆ s) (ht : IsCompact t) : IntegrableOn f t μ := (hf.mono_set hst).integrableOn_isCompact ht #align measure_theory.locally_integrable_on.integrable_on_compact_subset MeasureTheory.LocallyIntegrableOn.integrableOn_compact_subset /-- If a function `f` is locally integrable on a set `s` in a second countable topological space, then there exist countably many open sets `u` covering `s` such that `f` is integrable on each set `u ∩ s`. -/ theorem LocallyIntegrableOn.exists_countable_integrableOn [SecondCountableTopology X] (hf : LocallyIntegrableOn f s μ) : ∃ T : Set (Set X), T.Countable ∧ (∀ u ∈ T, IsOpen u) ∧ (s ⊆ ⋃ u ∈ T, u) ∧ (∀ u ∈ T, IntegrableOn f (u ∩ s) μ) := by have : ∀ x : s, ∃ u, IsOpen u ∧ x.1 ∈ u ∧ IntegrableOn f (u ∩ s) μ := by rintro ⟨x, hx⟩ rcases hf x hx with ⟨t, ht, h't⟩ rcases mem_nhdsWithin.1 ht with ⟨u, u_open, x_mem, u_sub⟩ exact ⟨u, u_open, x_mem, h't.mono_set u_sub⟩ choose u u_open xu hu using this obtain ⟨T, T_count, hT⟩ : ∃ T : Set s, T.Countable ∧ s ⊆ ⋃ i ∈ T, u i := by have : s ⊆ ⋃ x : s, u x := fun y hy => mem_iUnion_of_mem ⟨y, hy⟩ (xu ⟨y, hy⟩) obtain ⟨T, hT_count, hT_un⟩ := isOpen_iUnion_countable u u_open exact ⟨T, hT_count, by rwa [hT_un]⟩ refine ⟨u '' T, T_count.image _, ?_, by rwa [biUnion_image], ?_⟩ · rintro v ⟨w, -, rfl⟩ exact u_open _ · rintro v ⟨w, -, rfl⟩ exact hu _ /-- If a function `f` is locally integrable on a set `s` in a second countable topological space, then there exists a sequence of open sets `u n` covering `s` such that `f` is integrable on each set `u n ∩ s`. -/ theorem LocallyIntegrableOn.exists_nat_integrableOn [SecondCountableTopology X] (hf : LocallyIntegrableOn f s μ) : ∃ u : ℕ → Set X, (∀ n, IsOpen (u n)) ∧ (s ⊆ ⋃ n, u n) ∧ (∀ n, IntegrableOn f (u n ∩ s) μ) := by rcases hf.exists_countable_integrableOn with ⟨T, T_count, T_open, sT, hT⟩ let T' : Set (Set X) := insert ∅ T have T'_count : T'.Countable := Countable.insert ∅ T_count have T'_ne : T'.Nonempty := by simp only [T', insert_nonempty] rcases T'_count.exists_eq_range T'_ne with ⟨u, hu⟩ refine ⟨u, ?_, ?_, ?_⟩ · intro n have : u n ∈ T' := by rw [hu]; exact mem_range_self n rcases mem_insert_iff.1 this with h|h · rw [h] exact isOpen_empty · exact T_open _ h · intro x hx obtain ⟨v, hv, h'v⟩ : ∃ v, v ∈ T ∧ x ∈ v := by simpa only [mem_iUnion, exists_prop] using sT hx have : v ∈ range u := by rw [← hu]; exact subset_insert ∅ T hv obtain ⟨n, rfl⟩ : ∃ n, u n = v := by simpa only [mem_range] using this exact mem_iUnion_of_mem _ h'v · intro n have : u n ∈ T' := by rw [hu]; exact mem_range_self n rcases mem_insert_iff.1 this with h|h · simp only [h, empty_inter, integrableOn_empty] · exact hT _ h theorem LocallyIntegrableOn.aestronglyMeasurable [SecondCountableTopology X] (hf : LocallyIntegrableOn f s μ) : AEStronglyMeasurable f (μ.restrict s) := by rcases hf.exists_nat_integrableOn with ⟨u, -, su, hu⟩ have : s = ⋃ n, u n ∩ s := by rw [← iUnion_inter]; exact (inter_eq_right.mpr su).symm rw [this, aestronglyMeasurable_iUnion_iff] exact fun i : ℕ => (hu i).aestronglyMeasurable #align measure_theory.locally_integrable_on.ae_strongly_measurable MeasureTheory.LocallyIntegrableOn.aestronglyMeasurable /-- If `s` is either open, or closed, then `f` is locally integrable on `s` iff it is integrable on every compact subset contained in `s`. -/ theorem locallyIntegrableOn_iff [LocallyCompactSpace X] [T2Space X] (hs : IsClosed s ∨ IsOpen s) : LocallyIntegrableOn f s μ ↔ ∀ (k : Set X), k ⊆ s → (IsCompact k → IntegrableOn f k μ) := by -- The correct condition is that `s` be *locally closed*, i.e. for every `x ∈ s` there is some -- `U ∈ 𝓝 x` such that `U ∩ s` is closed. But mathlib doesn't have locally closed sets yet. refine ⟨fun hf k hk => hf.integrableOn_compact_subset hk, fun hf x hx => ?_⟩ cases hs with | inl hs => exact let ⟨K, hK, h2K⟩ := exists_compact_mem_nhds x ⟨_, inter_mem_nhdsWithin s h2K, hf _ inter_subset_left (hK.of_isClosed_subset (hs.inter hK.isClosed) inter_subset_right)⟩ | inr hs => obtain ⟨K, hK, h2K, h3K⟩ := exists_compact_subset hs hx refine ⟨K, ?_, hf K h3K hK⟩ simpa only [IsOpen.nhdsWithin_eq hs hx, interior_eq_nhds'] using h2K #align measure_theory.locally_integrable_on_iff MeasureTheory.locallyIntegrableOn_iff protected theorem LocallyIntegrableOn.add (hf : LocallyIntegrableOn f s μ) (hg : LocallyIntegrableOn g s μ) : LocallyIntegrableOn (f + g) s μ := fun x hx ↦ (hf x hx).add (hg x hx) protected theorem LocallyIntegrableOn.sub (hf : LocallyIntegrableOn f s μ) (hg : LocallyIntegrableOn g s μ) : LocallyIntegrableOn (f - g) s μ := fun x hx ↦ (hf x hx).sub (hg x hx) protected theorem LocallyIntegrableOn.neg (hf : LocallyIntegrableOn f s μ) : LocallyIntegrableOn (-f) s μ := fun x hx ↦ (hf x hx).neg end LocallyIntegrableOn /-- A function `f : X → E` is *locally integrable* if it is integrable on a neighborhood of every point. In particular, it is integrable on all compact sets, see `LocallyIntegrable.integrableOn_isCompact`. -/ def LocallyIntegrable (f : X → E) (μ : Measure X := by volume_tac) : Prop := ∀ x : X, IntegrableAtFilter f (𝓝 x) μ #align measure_theory.locally_integrable MeasureTheory.LocallyIntegrable theorem locallyIntegrable_comap (hs : MeasurableSet s) : LocallyIntegrable (fun x : s ↦ f x) (μ.comap Subtype.val) ↔ LocallyIntegrableOn f s μ := by simp_rw [LocallyIntegrableOn, Subtype.forall', ← map_nhds_subtype_val] exact forall_congr' fun _ ↦ (MeasurableEmbedding.subtype_coe hs).integrableAtFilter_iff_comap.symm theorem locallyIntegrableOn_univ : LocallyIntegrableOn f univ μ ↔ LocallyIntegrable f μ := by simp only [LocallyIntegrableOn, nhdsWithin_univ, mem_univ, true_imp_iff]; rfl #align measure_theory.locally_integrable_on_univ MeasureTheory.locallyIntegrableOn_univ theorem LocallyIntegrable.locallyIntegrableOn (hf : LocallyIntegrable f μ) (s : Set X) : LocallyIntegrableOn f s μ := fun x _ => (hf x).filter_mono nhdsWithin_le_nhds #align measure_theory.locally_integrable.locally_integrable_on MeasureTheory.LocallyIntegrable.locallyIntegrableOn theorem Integrable.locallyIntegrable (hf : Integrable f μ) : LocallyIntegrable f μ := fun _ => hf.integrableAtFilter _ #align measure_theory.integrable.locally_integrable MeasureTheory.Integrable.locallyIntegrable theorem LocallyIntegrable.mono (hf : LocallyIntegrable f μ) {g : X → F} (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ x ∂μ, ‖g x‖ ≤ ‖f x‖) : LocallyIntegrable g μ := by rw [← locallyIntegrableOn_univ] at hf ⊢ exact hf.mono hg h /-- If `f` is locally integrable with respect to `μ.restrict s`, it is locally integrable on `s`. (See `locallyIntegrableOn_iff_locallyIntegrable_restrict` for an iff statement when `s` is closed.) -/ theorem locallyIntegrableOn_of_locallyIntegrable_restrict [OpensMeasurableSpace X] (hf : LocallyIntegrable f (μ.restrict s)) : LocallyIntegrableOn f s μ := by intro x _ obtain ⟨t, ht_mem, ht_int⟩ := hf x obtain ⟨u, hu_sub, hu_o, hu_mem⟩ := mem_nhds_iff.mp ht_mem refine ⟨_, inter_mem_nhdsWithin s (hu_o.mem_nhds hu_mem), ?_⟩ simpa only [IntegrableOn, Measure.restrict_restrict hu_o.measurableSet, inter_comm] using ht_int.mono_set hu_sub #align measure_theory.locally_integrable_on_of_locally_integrable_restrict MeasureTheory.locallyIntegrableOn_of_locallyIntegrable_restrict /-- If `s` is closed, being locally integrable on `s` wrt `μ` is equivalent to being locally integrable with respect to `μ.restrict s`. For the one-way implication without assuming `s` closed, see `locallyIntegrableOn_of_locallyIntegrable_restrict`. -/ theorem locallyIntegrableOn_iff_locallyIntegrable_restrict [OpensMeasurableSpace X] (hs : IsClosed s) : LocallyIntegrableOn f s μ ↔ LocallyIntegrable f (μ.restrict s) := by refine ⟨fun hf x => ?_, locallyIntegrableOn_of_locallyIntegrable_restrict⟩ by_cases h : x ∈ s · obtain ⟨t, ht_nhds, ht_int⟩ := hf x h obtain ⟨u, hu_o, hu_x, hu_sub⟩ := mem_nhdsWithin.mp ht_nhds refine ⟨u, hu_o.mem_nhds hu_x, ?_⟩ rw [IntegrableOn, restrict_restrict hu_o.measurableSet] exact ht_int.mono_set hu_sub · rw [← isOpen_compl_iff] at hs refine ⟨sᶜ, hs.mem_nhds h, ?_⟩ rw [IntegrableOn, restrict_restrict, inter_comm, inter_compl_self, ← IntegrableOn] exacts [integrableOn_empty, hs.measurableSet] #align measure_theory.locally_integrable_on_iff_locally_integrable_restrict MeasureTheory.locallyIntegrableOn_iff_locallyIntegrable_restrict /-- If a function is locally integrable, then it is integrable on any compact set. -/ theorem LocallyIntegrable.integrableOn_isCompact {k : Set X} (hf : LocallyIntegrable f μ) (hk : IsCompact k) : IntegrableOn f k μ := (hf.locallyIntegrableOn k).integrableOn_isCompact hk #align measure_theory.locally_integrable.integrable_on_is_compact MeasureTheory.LocallyIntegrable.integrableOn_isCompact /-- If a function is locally integrable, then it is integrable on an open neighborhood of any compact set. -/ theorem LocallyIntegrable.integrableOn_nhds_isCompact (hf : LocallyIntegrable f μ) {k : Set X} (hk : IsCompact k) : ∃ u, IsOpen u ∧ k ⊆ u ∧ IntegrableOn f u μ := by refine IsCompact.induction_on hk ?_ ?_ ?_ ?_ · refine ⟨∅, isOpen_empty, Subset.rfl, integrableOn_empty⟩ · rintro s t hst ⟨u, u_open, tu, hu⟩ exact ⟨u, u_open, hst.trans tu, hu⟩ · rintro s t ⟨u, u_open, su, hu⟩ ⟨v, v_open, tv, hv⟩ exact ⟨u ∪ v, u_open.union v_open, union_subset_union su tv, hu.union hv⟩ · intro x _ rcases hf x with ⟨u, ux, hu⟩ rcases mem_nhds_iff.1 ux with ⟨v, vu, v_open, xv⟩ exact ⟨v, nhdsWithin_le_nhds (v_open.mem_nhds xv), v, v_open, Subset.rfl, hu.mono_set vu⟩ #align measure_theory.locally_integrable.integrable_on_nhds_is_compact MeasureTheory.LocallyIntegrable.integrableOn_nhds_isCompact theorem locallyIntegrable_iff [LocallyCompactSpace X] : LocallyIntegrable f μ ↔ ∀ k : Set X, IsCompact k → IntegrableOn f k μ := ⟨fun hf _k hk => hf.integrableOn_isCompact hk, fun hf x => let ⟨K, hK, h2K⟩ := exists_compact_mem_nhds x ⟨K, h2K, hf K hK⟩⟩ #align measure_theory.locally_integrable_iff MeasureTheory.locallyIntegrable_iff theorem LocallyIntegrable.aestronglyMeasurable [SecondCountableTopology X] (hf : LocallyIntegrable f μ) : AEStronglyMeasurable f μ := by simpa only [restrict_univ] using (locallyIntegrableOn_univ.mpr hf).aestronglyMeasurable #align measure_theory.locally_integrable.ae_strongly_measurable MeasureTheory.LocallyIntegrable.aestronglyMeasurable /-- If a function is locally integrable in a second countable topological space, then there exists a sequence of open sets covering the space on which it is integrable. -/ theorem LocallyIntegrable.exists_nat_integrableOn [SecondCountableTopology X] (hf : LocallyIntegrable f μ) : ∃ u : ℕ → Set X, (∀ n, IsOpen (u n)) ∧ ((⋃ n, u n) = univ) ∧ (∀ n, IntegrableOn f (u n) μ) := by rcases (hf.locallyIntegrableOn univ).exists_nat_integrableOn with ⟨u, u_open, u_union, hu⟩ refine ⟨u, u_open, eq_univ_of_univ_subset u_union, fun n ↦ ?_⟩ simpa only [inter_univ] using hu n theorem Memℒp.locallyIntegrable [IsLocallyFiniteMeasure μ] {f : X → E} {p : ℝ≥0∞} (hf : Memℒp f p μ) (hp : 1 ≤ p) : LocallyIntegrable f μ := by intro x rcases μ.finiteAt_nhds x with ⟨U, hU, h'U⟩ have : Fact (μ U < ⊤) := ⟨h'U⟩ refine ⟨U, hU, ?_⟩ rw [IntegrableOn, ← memℒp_one_iff_integrable] apply (hf.restrict U).memℒp_of_exponent_le hp theorem locallyIntegrable_const [IsLocallyFiniteMeasure μ] (c : E) : LocallyIntegrable (fun _ => c) μ := (memℒp_top_const c).locallyIntegrable le_top #align measure_theory.locally_integrable_const MeasureTheory.locallyIntegrable_const theorem locallyIntegrableOn_const [IsLocallyFiniteMeasure μ] (c : E) : LocallyIntegrableOn (fun _ => c) s μ := (locallyIntegrable_const c).locallyIntegrableOn s #align measure_theory.locally_integrable_on_const MeasureTheory.locallyIntegrableOn_const theorem locallyIntegrable_zero : LocallyIntegrable (fun _ ↦ (0 : E)) μ := (integrable_zero X E μ).locallyIntegrable theorem locallyIntegrableOn_zero : LocallyIntegrableOn (fun _ ↦ (0 : E)) s μ := locallyIntegrable_zero.locallyIntegrableOn s theorem LocallyIntegrable.indicator (hf : LocallyIntegrable f μ) {s : Set X} (hs : MeasurableSet s) : LocallyIntegrable (s.indicator f) μ := by intro x rcases hf x with ⟨U, hU, h'U⟩ exact ⟨U, hU, h'U.indicator hs⟩ #align measure_theory.locally_integrable.indicator MeasureTheory.LocallyIntegrable.indicator theorem locallyIntegrable_map_homeomorph [BorelSpace X] [BorelSpace Y] (e : X ≃ₜ Y) {f : Y → E} {μ : Measure X} : LocallyIntegrable f (Measure.map e μ) ↔ LocallyIntegrable (f ∘ e) μ := by refine ⟨fun h x => ?_, fun h x => ?_⟩ · rcases h (e x) with ⟨U, hU, h'U⟩ refine ⟨e ⁻¹' U, e.continuous.continuousAt.preimage_mem_nhds hU, ?_⟩ exact (integrableOn_map_equiv e.toMeasurableEquiv).1 h'U · rcases h (e.symm x) with ⟨U, hU, h'U⟩ refine ⟨e.symm ⁻¹' U, e.symm.continuous.continuousAt.preimage_mem_nhds hU, ?_⟩ apply (integrableOn_map_equiv e.toMeasurableEquiv).2 simp only [Homeomorph.toMeasurableEquiv_coe] convert h'U ext x simp only [mem_preimage, Homeomorph.symm_apply_apply] #align measure_theory.locally_integrable_map_homeomorph MeasureTheory.locallyIntegrable_map_homeomorph protected theorem LocallyIntegrable.add (hf : LocallyIntegrable f μ) (hg : LocallyIntegrable g μ) : LocallyIntegrable (f + g) μ := fun x ↦ (hf x).add (hg x) protected theorem LocallyIntegrable.sub (hf : LocallyIntegrable f μ) (hg : LocallyIntegrable g μ) : LocallyIntegrable (f - g) μ := fun x ↦ (hf x).sub (hg x) protected theorem LocallyIntegrable.neg (hf : LocallyIntegrable f μ) : LocallyIntegrable (-f) μ := fun x ↦ (hf x).neg protected theorem LocallyIntegrable.smul {𝕜 : Type*} [NormedAddCommGroup 𝕜] [SMulZeroClass 𝕜 E] [BoundedSMul 𝕜 E] (hf : LocallyIntegrable f μ) (c : 𝕜) : LocallyIntegrable (c • f) μ := fun x ↦ (hf x).smul c theorem locallyIntegrable_finset_sum' {ι} (s : Finset ι) {f : ι → X → E} (hf : ∀ i ∈ s, LocallyIntegrable (f i) μ) : LocallyIntegrable (∑ i ∈ s, f i) μ := Finset.sum_induction f (fun g => LocallyIntegrable g μ) (fun _ _ => LocallyIntegrable.add) locallyIntegrable_zero hf theorem locallyIntegrable_finset_sum {ι} (s : Finset ι) {f : ι → X → E} (hf : ∀ i ∈ s, LocallyIntegrable (f i) μ) : LocallyIntegrable (fun a ↦ ∑ i ∈ s, f i a) μ := by simpa only [← Finset.sum_apply] using locallyIntegrable_finset_sum' s hf /-- If `f` is locally integrable and `g` is continuous with compact support, then `g • f` is integrable. -/ theorem LocallyIntegrable.integrable_smul_left_of_hasCompactSupport [NormedSpace ℝ E] [OpensMeasurableSpace X] [T2Space X] (hf : LocallyIntegrable f μ) {g : X → ℝ} (hg : Continuous g) (h'g : HasCompactSupport g) : Integrable (fun x ↦ g x • f x) μ := by let K := tsupport g have hK : IsCompact K := h'g have : K.indicator (fun x ↦ g x • f x) = (fun x ↦ g x • f x) := by apply indicator_eq_self.2 apply support_subset_iff'.2 intros x hx simp [image_eq_zero_of_nmem_tsupport hx] rw [← this, indicator_smul] apply Integrable.smul_of_top_right · rw [integrable_indicator_iff hK.measurableSet] exact hf.integrableOn_isCompact hK · exact hg.memℒp_top_of_hasCompactSupport h'g μ /-- If `f` is locally integrable and `g` is continuous with compact support, then `f • g` is integrable. -/ theorem LocallyIntegrable.integrable_smul_right_of_hasCompactSupport [NormedSpace ℝ E] [OpensMeasurableSpace X] [T2Space X] {f : X → ℝ} (hf : LocallyIntegrable f μ) {g : X → E} (hg : Continuous g) (h'g : HasCompactSupport g) : Integrable (fun x ↦ f x • g x) μ := by let K := tsupport g have hK : IsCompact K := h'g have : K.indicator (fun x ↦ f x • g x) = (fun x ↦ f x • g x) := by apply indicator_eq_self.2 apply support_subset_iff'.2 intros x hx simp [image_eq_zero_of_nmem_tsupport hx] rw [← this, indicator_smul_left] apply Integrable.smul_of_top_left · rw [integrable_indicator_iff hK.measurableSet] exact hf.integrableOn_isCompact hK · exact hg.memℒp_top_of_hasCompactSupport h'g μ open Filter theorem integrable_iff_integrableAtFilter_cocompact : Integrable f μ ↔ (IntegrableAtFilter f (cocompact X) μ ∧ LocallyIntegrable f μ) := by refine ⟨fun hf ↦ ⟨hf.integrableAtFilter _, hf.locallyIntegrable⟩, fun ⟨⟨s, hsc, hs⟩, hloc⟩ ↦ ?_⟩ obtain ⟨t, htc, ht⟩ := mem_cocompact'.mp hsc rewrite [← integrableOn_univ, ← compl_union_self s, integrableOn_union] exact ⟨(hloc.integrableOn_isCompact htc).mono ht le_rfl, hs⟩ theorem integrable_iff_integrableAtFilter_atBot_atTop [LinearOrder X] [CompactIccSpace X] : Integrable f μ ↔ (IntegrableAtFilter f atBot μ ∧ IntegrableAtFilter f atTop μ) ∧ LocallyIntegrable f μ := by constructor · exact fun hf ↦ ⟨⟨hf.integrableAtFilter _, hf.integrableAtFilter _⟩, hf.locallyIntegrable⟩ · refine fun h ↦ integrable_iff_integrableAtFilter_cocompact.mpr ⟨?_, h.2⟩ exact (IntegrableAtFilter.sup_iff.mpr h.1).filter_mono cocompact_le_atBot_atTop theorem integrable_iff_integrableAtFilter_atBot [LinearOrder X] [OrderTop X] [CompactIccSpace X] : Integrable f μ ↔ IntegrableAtFilter f atBot μ ∧ LocallyIntegrable f μ := by constructor · exact fun hf ↦ ⟨hf.integrableAtFilter _, hf.locallyIntegrable⟩ · refine fun h ↦ integrable_iff_integrableAtFilter_cocompact.mpr ⟨?_, h.2⟩ exact h.1.filter_mono cocompact_le_atBot theorem integrable_iff_integrableAtFilter_atTop [LinearOrder X] [OrderBot X] [CompactIccSpace X] : Integrable f μ ↔ IntegrableAtFilter f atTop μ ∧ LocallyIntegrable f μ := integrable_iff_integrableAtFilter_atBot (X := Xᵒᵈ) variable {a : X} theorem integrableOn_Iic_iff_integrableAtFilter_atBot [LinearOrder X] [CompactIccSpace X] : IntegrableOn f (Iic a) μ ↔ IntegrableAtFilter f atBot μ ∧ LocallyIntegrableOn f (Iic a) μ := by refine ⟨fun h ↦ ⟨⟨Iic a, Iic_mem_atBot a, h⟩, h.locallyIntegrableOn⟩, fun ⟨⟨s, hsl, hs⟩, h⟩ ↦ ?_⟩ haveI : Nonempty X := Nonempty.intro a obtain ⟨a', ha'⟩ := mem_atBot_sets.mp hsl refine (integrableOn_union.mpr ⟨hs.mono ha' le_rfl, ?_⟩).mono Iic_subset_Iic_union_Icc le_rfl exact h.integrableOn_compact_subset Icc_subset_Iic_self isCompact_Icc theorem integrableOn_Ici_iff_integrableAtFilter_atTop [LinearOrder X] [CompactIccSpace X] : IntegrableOn f (Ici a) μ ↔ IntegrableAtFilter f atTop μ ∧ LocallyIntegrableOn f (Ici a) μ := integrableOn_Iic_iff_integrableAtFilter_atBot (X := Xᵒᵈ)
Mathlib/MeasureTheory/Function/LocallyIntegrable.lean
425
436
theorem integrableOn_Iio_iff_integrableAtFilter_atBot_nhdsWithin [LinearOrder X] [CompactIccSpace X] [NoMinOrder X] [OrderTopology X] : IntegrableOn f (Iio a) μ ↔ IntegrableAtFilter f atBot μ ∧ IntegrableAtFilter f (𝓝[<] a) μ ∧ LocallyIntegrableOn f (Iio a) μ := by
constructor · intro h exact ⟨⟨Iio a, Iio_mem_atBot a, h⟩, ⟨Iio a, self_mem_nhdsWithin, h⟩, h.locallyIntegrableOn⟩ · intro ⟨hbot, ⟨s, hsl, hs⟩, hlocal⟩ obtain ⟨s', ⟨hs'_mono, hs'⟩⟩ := mem_nhdsWithin_Iio_iff_exists_Ioo_subset.mp hsl refine (integrableOn_union.mpr ⟨?_, hs.mono hs' le_rfl⟩).mono Iio_subset_Iic_union_Ioo le_rfl exact integrableOn_Iic_iff_integrableAtFilter_atBot.mpr ⟨hbot, hlocal.mono_set (Iic_subset_Iio.mpr hs'_mono)⟩
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.Topology.MetricSpace.HausdorffDistance #align_import topology.metric_space.hausdorff_distance from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Thickenings in pseudo-metric spaces ## Main definitions * `Metric.thickening δ s`, the open thickening by radius `δ` of a set `s` in a pseudo emetric space. * `Metric.cthickening δ s`, the closed thickening by radius `δ` of a set `s` in a pseudo emetric space. ## Main results * `Disjoint.exists_thickenings`: two disjoint sets admit disjoint thickenings * `Disjoint.exists_cthickenings`: two disjoint sets admit disjoint closed thickenings * `IsCompact.exists_cthickening_subset_open`: if `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. * `Metric.hasBasis_nhdsSet_cthickening`: the `cthickening`s of a compact set `K` form a basis of the neighbourhoods of `K` * `Metric.closure_eq_iInter_cthickening'`: the closure of a set equals the intersection of its closed thickenings of positive radii accumulating at zero. The same holds for open thickenings. * `IsCompact.cthickening_eq_biUnion_closedBall`: if `s` is compact, `cthickening δ s` is the union of `closedBall`s of radius `δ` around `x : E`. -/ noncomputable section open NNReal ENNReal Topology Set Filter Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace Metric section Thickening variable [PseudoEMetricSpace α] {δ : ℝ} {s : Set α} {x : α} open EMetric /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at distance less than `δ` from some point of `E`. -/ def thickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E < ENNReal.ofReal δ } #align metric.thickening Metric.thickening theorem mem_thickening_iff_infEdist_lt : x ∈ thickening δ s ↔ infEdist x s < ENNReal.ofReal δ := Iff.rfl #align metric.mem_thickening_iff_inf_edist_lt Metric.mem_thickening_iff_infEdist_lt /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the (open) `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_thickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.thickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [thickening, mem_setOf_eq, not_lt] exact (ENNReal.ofReal_le_ofReal hδ.le).trans ε_lt.le /-- The (open) thickening equals the preimage of an open interval under `EMetric.infEdist`. -/ theorem thickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : thickening δ E = (infEdist · E) ⁻¹' Iio (ENNReal.ofReal δ) := rfl #align metric.thickening_eq_preimage_inf_edist Metric.thickening_eq_preimage_infEdist /-- The (open) thickening is an open set. -/ theorem isOpen_thickening {δ : ℝ} {E : Set α} : IsOpen (thickening δ E) := Continuous.isOpen_preimage continuous_infEdist _ isOpen_Iio #align metric.is_open_thickening Metric.isOpen_thickening /-- The (open) thickening of the empty set is empty. -/ @[simp] theorem thickening_empty (δ : ℝ) : thickening δ (∅ : Set α) = ∅ := by simp only [thickening, setOf_false, infEdist_empty, not_top_lt] #align metric.thickening_empty Metric.thickening_empty theorem thickening_of_nonpos (hδ : δ ≤ 0) (s : Set α) : thickening δ s = ∅ := eq_empty_of_forall_not_mem fun _ => ((ENNReal.ofReal_of_nonpos hδ).trans_le bot_le).not_lt #align metric.thickening_of_nonpos Metric.thickening_of_nonpos /-- The (open) thickening `Metric.thickening δ E` of a fixed subset `E` is an increasing function of the thickening radius `δ`. -/ theorem thickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickening δ₁ E ⊆ thickening δ₂ E := preimage_mono (Iio_subset_Iio (ENNReal.ofReal_le_ofReal hle)) #align metric.thickening_mono Metric.thickening_mono /-- The (open) thickening `Metric.thickening δ E` with a fixed thickening radius `δ` is an increasing function of the subset `E`. -/ theorem thickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) : thickening δ E₁ ⊆ thickening δ E₂ := fun _ hx => lt_of_le_of_lt (infEdist_anti h) hx #align metric.thickening_subset_of_subset Metric.thickening_subset_of_subset theorem mem_thickening_iff_exists_edist_lt {δ : ℝ} (E : Set α) (x : α) : x ∈ thickening δ E ↔ ∃ z ∈ E, edist x z < ENNReal.ofReal δ := infEdist_lt_iff #align metric.mem_thickening_iff_exists_edist_lt Metric.mem_thickening_iff_exists_edist_lt /-- The frontier of the (open) thickening of a set is contained in an `EMetric.infEdist` level set. -/ theorem frontier_thickening_subset (E : Set α) {δ : ℝ} : frontier (thickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } := frontier_lt_subset_eq continuous_infEdist continuous_const #align metric.frontier_thickening_subset Metric.frontier_thickening_subset theorem frontier_thickening_disjoint (A : Set α) : Pairwise (Disjoint on fun r : ℝ => frontier (thickening r A)) := by refine (pairwise_disjoint_on _).2 fun r₁ r₂ hr => ?_ rcases le_total r₁ 0 with h₁ | h₁ · simp [thickening_of_nonpos h₁] refine ((disjoint_singleton.2 fun h => hr.ne ?_).preimage _).mono (frontier_thickening_subset _) (frontier_thickening_subset _) apply_fun ENNReal.toReal at h rwa [ENNReal.toReal_ofReal h₁, ENNReal.toReal_ofReal (h₁.trans hr.le)] at h #align metric.frontier_thickening_disjoint Metric.frontier_thickening_disjoint /-- Any set is contained in the complement of the δ-thickening of the complement of its δ-thickening. -/ lemma subset_compl_thickening_compl_thickening_self (δ : ℝ) (E : Set α) : E ⊆ (thickening δ (thickening δ E)ᶜ)ᶜ := by intro x x_in_E simp only [thickening, mem_compl_iff, mem_setOf_eq, not_lt] apply EMetric.le_infEdist.mpr fun y hy ↦ ?_ simp only [mem_compl_iff, mem_setOf_eq, not_lt] at hy simpa only [edist_comm] using le_trans hy <| EMetric.infEdist_le_edist_of_mem x_in_E /-- The δ-thickening of the complement of the δ-thickening of a set is contained in the complement of the set. -/ lemma thickening_compl_thickening_self_subset_compl (δ : ℝ) (E : Set α) : thickening δ (thickening δ E)ᶜ ⊆ Eᶜ := by apply compl_subset_compl.mp simpa only [compl_compl] using subset_compl_thickening_compl_thickening_self δ E variable {X : Type u} [PseudoMetricSpace X] -- Porting note (#10756): new lemma theorem mem_thickening_iff_infDist_lt {E : Set X} {x : X} (h : E.Nonempty) : x ∈ thickening δ E ↔ infDist x E < δ := lt_ofReal_iff_toReal_lt (infEdist_ne_top h) /-- A point in a metric space belongs to the (open) `δ`-thickening of a subset `E` if and only if it is at distance less than `δ` from some point of `E`. -/ theorem mem_thickening_iff {E : Set X} {x : X} : x ∈ thickening δ E ↔ ∃ z ∈ E, dist x z < δ := by have key_iff : ∀ z : X, edist x z < ENNReal.ofReal δ ↔ dist x z < δ := fun z ↦ by rw [dist_edist, lt_ofReal_iff_toReal_lt (edist_ne_top _ _)] simp_rw [mem_thickening_iff_exists_edist_lt, key_iff] #align metric.mem_thickening_iff Metric.mem_thickening_iff @[simp] theorem thickening_singleton (δ : ℝ) (x : X) : thickening δ ({x} : Set X) = ball x δ := by ext simp [mem_thickening_iff] #align metric.thickening_singleton Metric.thickening_singleton theorem ball_subset_thickening {x : X} {E : Set X} (hx : x ∈ E) (δ : ℝ) : ball x δ ⊆ thickening δ E := Subset.trans (by simp [Subset.rfl]) (thickening_subset_of_subset δ <| singleton_subset_iff.mpr hx) #align metric.ball_subset_thickening Metric.ball_subset_thickening /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a metric space equals the union of balls of radius `δ` centered at points of `E`. -/ theorem thickening_eq_biUnion_ball {δ : ℝ} {E : Set X} : thickening δ E = ⋃ x ∈ E, ball x δ := by ext x simp only [mem_iUnion₂, exists_prop] exact mem_thickening_iff #align metric.thickening_eq_bUnion_ball Metric.thickening_eq_biUnion_ball protected theorem _root_.Bornology.IsBounded.thickening {δ : ℝ} {E : Set X} (h : IsBounded E) : IsBounded (thickening δ E) := by rcases E.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · simp · refine (isBounded_iff_subset_closedBall x).2 ⟨δ + diam E, fun y hy ↦ ?_⟩ calc dist y x ≤ infDist y E + diam E := dist_le_infDist_add_diam (x := y) h hx _ ≤ δ + diam E := add_le_add_right ((mem_thickening_iff_infDist_lt ⟨x, hx⟩).1 hy).le _ #align metric.bounded.thickening Bornology.IsBounded.thickening end Thickening section Cthickening variable [PseudoEMetricSpace α] {δ ε : ℝ} {s t : Set α} {x : α} open EMetric /-- The closed `δ`-thickening `Metric.cthickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at infimum distance at most `δ` from `E`. -/ def cthickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E ≤ ENNReal.ofReal δ } #align metric.cthickening Metric.cthickening @[simp] theorem mem_cthickening_iff : x ∈ cthickening δ s ↔ infEdist x s ≤ ENNReal.ofReal δ := Iff.rfl #align metric.mem_cthickening_iff Metric.mem_cthickening_iff /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the closed `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_cthickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.cthickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [cthickening, mem_setOf_eq, not_le] exact ((ofReal_lt_ofReal_iff ε_pos).mpr hδ).trans ε_lt theorem mem_cthickening_of_edist_le (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : edist x y ≤ ENNReal.ofReal δ) : x ∈ cthickening δ E := (infEdist_le_edist_of_mem h).trans h' #align metric.mem_cthickening_of_edist_le Metric.mem_cthickening_of_edist_le theorem mem_cthickening_of_dist_le {α : Type*} [PseudoMetricSpace α] (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : dist x y ≤ δ) : x ∈ cthickening δ E := by apply mem_cthickening_of_edist_le x y δ E h rw [edist_dist] exact ENNReal.ofReal_le_ofReal h' #align metric.mem_cthickening_of_dist_le Metric.mem_cthickening_of_dist_le theorem cthickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : cthickening δ E = (fun x => infEdist x E) ⁻¹' Iic (ENNReal.ofReal δ) := rfl #align metric.cthickening_eq_preimage_inf_edist Metric.cthickening_eq_preimage_infEdist /-- The closed thickening is a closed set. -/ theorem isClosed_cthickening {δ : ℝ} {E : Set α} : IsClosed (cthickening δ E) := IsClosed.preimage continuous_infEdist isClosed_Iic #align metric.is_closed_cthickening Metric.isClosed_cthickening /-- The closed thickening of the empty set is empty. -/ @[simp] theorem cthickening_empty (δ : ℝ) : cthickening δ (∅ : Set α) = ∅ := by simp only [cthickening, ENNReal.ofReal_ne_top, setOf_false, infEdist_empty, top_le_iff] #align metric.cthickening_empty Metric.cthickening_empty theorem cthickening_of_nonpos {δ : ℝ} (hδ : δ ≤ 0) (E : Set α) : cthickening δ E = closure E := by ext x simp [mem_closure_iff_infEdist_zero, cthickening, ENNReal.ofReal_eq_zero.2 hδ] #align metric.cthickening_of_nonpos Metric.cthickening_of_nonpos /-- The closed thickening with radius zero is the closure of the set. -/ @[simp] theorem cthickening_zero (E : Set α) : cthickening 0 E = closure E := cthickening_of_nonpos le_rfl E #align metric.cthickening_zero Metric.cthickening_zero theorem cthickening_max_zero (δ : ℝ) (E : Set α) : cthickening (max 0 δ) E = cthickening δ E := by cases le_total δ 0 <;> simp [cthickening_of_nonpos, *] #align metric.cthickening_max_zero Metric.cthickening_max_zero /-- The closed thickening `Metric.cthickening δ E` of a fixed subset `E` is an increasing function of the thickening radius `δ`. -/ theorem cthickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : cthickening δ₁ E ⊆ cthickening δ₂ E := preimage_mono (Iic_subset_Iic.mpr (ENNReal.ofReal_le_ofReal hle)) #align metric.cthickening_mono Metric.cthickening_mono @[simp] theorem cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) {δ : ℝ} (hδ : 0 ≤ δ) : cthickening δ ({x} : Set α) = closedBall x δ := by ext y simp [cthickening, edist_dist, ENNReal.ofReal_le_ofReal_iff hδ] #align metric.cthickening_singleton Metric.cthickening_singleton theorem closedBall_subset_cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) (δ : ℝ) : closedBall x δ ⊆ cthickening δ ({x} : Set α) := by rcases lt_or_le δ 0 with (hδ | hδ) · simp only [closedBall_eq_empty.mpr hδ, empty_subset] · simp only [cthickening_singleton x hδ, Subset.rfl] #align metric.closed_ball_subset_cthickening_singleton Metric.closedBall_subset_cthickening_singleton /-- The closed thickening `Metric.cthickening δ E` with a fixed thickening radius `δ` is an increasing function of the subset `E`. -/ theorem cthickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) : cthickening δ E₁ ⊆ cthickening δ E₂ := fun _ hx => le_trans (infEdist_anti h) hx #align metric.cthickening_subset_of_subset Metric.cthickening_subset_of_subset theorem cthickening_subset_thickening {δ₁ : ℝ≥0} {δ₂ : ℝ} (hlt : (δ₁ : ℝ) < δ₂) (E : Set α) : cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx => hx.out.trans_lt ((ENNReal.ofReal_lt_ofReal_iff (lt_of_le_of_lt δ₁.prop hlt)).mpr hlt) #align metric.cthickening_subset_thickening Metric.cthickening_subset_thickening /-- The closed thickening `Metric.cthickening δ₁ E` is contained in the open thickening `Metric.thickening δ₂ E` if the radius of the latter is positive and larger. -/ theorem cthickening_subset_thickening' {δ₁ δ₂ : ℝ} (δ₂_pos : 0 < δ₂) (hlt : δ₁ < δ₂) (E : Set α) : cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx => lt_of_le_of_lt hx.out ((ENNReal.ofReal_lt_ofReal_iff δ₂_pos).mpr hlt) #align metric.cthickening_subset_thickening' Metric.cthickening_subset_thickening' /-- The open thickening `Metric.thickening δ E` is contained in the closed thickening `Metric.cthickening δ E` with the same radius. -/ theorem thickening_subset_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ cthickening δ E := by intro x hx rw [thickening, mem_setOf_eq] at hx exact hx.le #align metric.thickening_subset_cthickening Metric.thickening_subset_cthickening theorem thickening_subset_cthickening_of_le {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickening δ₁ E ⊆ cthickening δ₂ E := (thickening_subset_cthickening δ₁ E).trans (cthickening_mono hle E) #align metric.thickening_subset_cthickening_of_le Metric.thickening_subset_cthickening_of_le theorem _root_.Bornology.IsBounded.cthickening {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α} (h : IsBounded E) : IsBounded (cthickening δ E) := by have : IsBounded (thickening (max (δ + 1) 1) E) := h.thickening apply this.subset exact cthickening_subset_thickening' (zero_lt_one.trans_le (le_max_right _ _)) ((lt_add_one _).trans_le (le_max_left _ _)) _ #align metric.bounded.cthickening Bornology.IsBounded.cthickening protected theorem _root_.IsCompact.cthickening {α : Type*} [PseudoMetricSpace α] [ProperSpace α] {s : Set α} (hs : IsCompact s) {r : ℝ} : IsCompact (cthickening r s) := isCompact_of_isClosed_isBounded isClosed_cthickening hs.isBounded.cthickening theorem thickening_subset_interior_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ interior (cthickening δ E) := (subset_interior_iff_isOpen.mpr isOpen_thickening).trans (interior_mono (thickening_subset_cthickening δ E)) #align metric.thickening_subset_interior_cthickening Metric.thickening_subset_interior_cthickening theorem closure_thickening_subset_cthickening (δ : ℝ) (E : Set α) : closure (thickening δ E) ⊆ cthickening δ E := (closure_mono (thickening_subset_cthickening δ E)).trans isClosed_cthickening.closure_subset #align metric.closure_thickening_subset_cthickening Metric.closure_thickening_subset_cthickening /-- The closed thickening of a set contains the closure of the set. -/ theorem closure_subset_cthickening (δ : ℝ) (E : Set α) : closure E ⊆ cthickening δ E := by rw [← cthickening_of_nonpos (min_le_right δ 0)] exact cthickening_mono (min_le_left δ 0) E #align metric.closure_subset_cthickening Metric.closure_subset_cthickening /-- The (open) thickening of a set contains the closure of the set. -/ theorem closure_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : closure E ⊆ thickening δ E := by rw [← cthickening_zero] exact cthickening_subset_thickening' δ_pos δ_pos E #align metric.closure_subset_thickening Metric.closure_subset_thickening /-- A set is contained in its own (open) thickening. -/ theorem self_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : E ⊆ thickening δ E := (@subset_closure _ E).trans (closure_subset_thickening δ_pos E) #align metric.self_subset_thickening Metric.self_subset_thickening /-- A set is contained in its own closed thickening. -/ theorem self_subset_cthickening {δ : ℝ} (E : Set α) : E ⊆ cthickening δ E := subset_closure.trans (closure_subset_cthickening δ E) #align metric.self_subset_cthickening Metric.self_subset_cthickening theorem thickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : thickening δ E ∈ 𝓝ˢ E := isOpen_thickening.mem_nhdsSet.2 <| self_subset_thickening hδ E #align metric.thickening_mem_nhds_set Metric.thickening_mem_nhdsSet theorem cthickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : cthickening δ E ∈ 𝓝ˢ E := mem_of_superset (thickening_mem_nhdsSet E hδ) (thickening_subset_cthickening _ _) #align metric.cthickening_mem_nhds_set Metric.cthickening_mem_nhdsSet @[simp] theorem thickening_union (δ : ℝ) (s t : Set α) : thickening δ (s ∪ t) = thickening δ s ∪ thickening δ t := by simp_rw [thickening, infEdist_union, inf_eq_min, min_lt_iff, setOf_or] #align metric.thickening_union Metric.thickening_union @[simp] theorem cthickening_union (δ : ℝ) (s t : Set α) : cthickening δ (s ∪ t) = cthickening δ s ∪ cthickening δ t := by simp_rw [cthickening, infEdist_union, inf_eq_min, min_le_iff, setOf_or] #align metric.cthickening_union Metric.cthickening_union @[simp] theorem thickening_iUnion (δ : ℝ) (f : ι → Set α) : thickening δ (⋃ i, f i) = ⋃ i, thickening δ (f i) := by simp_rw [thickening, infEdist_iUnion, iInf_lt_iff, setOf_exists] #align metric.thickening_Union Metric.thickening_iUnion lemma thickening_biUnion {ι : Type*} (δ : ℝ) (f : ι → Set α) (I : Set ι) : thickening δ (⋃ i ∈ I, f i) = ⋃ i ∈ I, thickening δ (f i) := by simp only [thickening_iUnion] theorem ediam_cthickening_le (ε : ℝ≥0) : EMetric.diam (cthickening ε s) ≤ EMetric.diam s + 2 * ε := by refine diam_le fun x hx y hy => ENNReal.le_of_forall_pos_le_add fun δ hδ _ => ?_ rw [mem_cthickening_iff, ENNReal.ofReal_coe_nnreal] at hx hy have hε : (ε : ℝ≥0∞) < ε + δ := ENNReal.coe_lt_coe.2 (lt_add_of_pos_right _ hδ) replace hx := hx.trans_lt hε obtain ⟨x', hx', hxx'⟩ := infEdist_lt_iff.mp hx calc edist x y ≤ edist x x' + edist y x' := edist_triangle_right _ _ _ _ ≤ ε + δ + (infEdist y s + EMetric.diam s) := add_le_add hxx'.le (edist_le_infEdist_add_ediam hx') _ ≤ ε + δ + (ε + EMetric.diam s) := add_le_add_left (add_le_add_right hy _) _ _ = _ := by rw [two_mul]; ac_rfl #align metric.ediam_cthickening_le Metric.ediam_cthickening_le theorem ediam_thickening_le (ε : ℝ≥0) : EMetric.diam (thickening ε s) ≤ EMetric.diam s + 2 * ε := (EMetric.diam_mono <| thickening_subset_cthickening _ _).trans <| ediam_cthickening_le _ #align metric.ediam_thickening_le Metric.ediam_thickening_le theorem diam_cthickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) : diam (cthickening ε s) ≤ diam s + 2 * ε := by lift ε to ℝ≥0 using hε refine (toReal_le_add' (ediam_cthickening_le _) ?_ ?_).trans_eq ?_ · exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono (self_subset_cthickening _) · simp [mul_eq_top] · simp [diam] #align metric.diam_cthickening_le Metric.diam_cthickening_le theorem diam_thickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) : diam (thickening ε s) ≤ diam s + 2 * ε := by by_cases hs : IsBounded s · exact (diam_mono (thickening_subset_cthickening _ _) hs.cthickening).trans (diam_cthickening_le _ hε) obtain rfl | hε := hε.eq_or_lt · simp [thickening_of_nonpos, diam_nonneg] · rw [diam_eq_zero_of_unbounded (mt (IsBounded.subset · <| self_subset_thickening hε _) hs)] positivity #align metric.diam_thickening_le Metric.diam_thickening_le @[simp] theorem thickening_closure : thickening δ (closure s) = thickening δ s := by simp_rw [thickening, infEdist_closure] #align metric.thickening_closure Metric.thickening_closure @[simp] theorem cthickening_closure : cthickening δ (closure s) = cthickening δ s := by simp_rw [cthickening, infEdist_closure] #align metric.cthickening_closure Metric.cthickening_closure open ENNReal theorem _root_.Disjoint.exists_thickenings (hst : Disjoint s t) (hs : IsCompact s) (ht : IsClosed t) : ∃ δ, 0 < δ ∧ Disjoint (thickening δ s) (thickening δ t) := by obtain ⟨r, hr, h⟩ := exists_pos_forall_lt_edist hs ht hst refine ⟨r / 2, half_pos (NNReal.coe_pos.2 hr), ?_⟩ rw [disjoint_iff_inf_le] rintro z ⟨hzs, hzt⟩ rw [mem_thickening_iff_exists_edist_lt] at hzs hzt rw [← NNReal.coe_two, ← NNReal.coe_div, ENNReal.ofReal_coe_nnreal] at hzs hzt obtain ⟨x, hx, hzx⟩ := hzs obtain ⟨y, hy, hzy⟩ := hzt refine (h x hx y hy).not_le ?_ calc edist x y ≤ edist z x + edist z y := edist_triangle_left _ _ _ _ ≤ ↑(r / 2) + ↑(r / 2) := add_le_add hzx.le hzy.le _ = r := by rw [← ENNReal.coe_add, add_halves] #align disjoint.exists_thickenings Disjoint.exists_thickenings theorem _root_.Disjoint.exists_cthickenings (hst : Disjoint s t) (hs : IsCompact s) (ht : IsClosed t) : ∃ δ, 0 < δ ∧ Disjoint (cthickening δ s) (cthickening δ t) := by obtain ⟨δ, hδ, h⟩ := hst.exists_thickenings hs ht refine ⟨δ / 2, half_pos hδ, h.mono ?_ ?_⟩ <;> exact cthickening_subset_thickening' hδ (half_lt_self hδ) _ #align disjoint.exists_cthickenings Disjoint.exists_cthickenings /-- If `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. -/ theorem _root_.IsCompact.exists_cthickening_subset_open (hs : IsCompact s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ δ, 0 < δ ∧ cthickening δ s ⊆ t := (hst.disjoint_compl_right.exists_cthickenings hs ht.isClosed_compl).imp fun _ h => ⟨h.1, disjoint_compl_right_iff_subset.1 <| h.2.mono_right <| self_subset_cthickening _⟩ #align is_compact.exists_cthickening_subset_open IsCompact.exists_cthickening_subset_open theorem _root_.IsCompact.exists_isCompact_cthickening [LocallyCompactSpace α] (hs : IsCompact s) : ∃ δ, 0 < δ ∧ IsCompact (cthickening δ s) := by rcases exists_compact_superset hs with ⟨K, K_compact, hK⟩ rcases hs.exists_cthickening_subset_open isOpen_interior hK with ⟨δ, δpos, hδ⟩ refine ⟨δ, δpos, ?_⟩ exact K_compact.of_isClosed_subset isClosed_cthickening (hδ.trans interior_subset) theorem _root_.IsCompact.exists_thickening_subset_open (hs : IsCompact s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ δ, 0 < δ ∧ thickening δ s ⊆ t := let ⟨δ, h₀, hδ⟩ := hs.exists_cthickening_subset_open ht hst ⟨δ, h₀, (thickening_subset_cthickening _ _).trans hδ⟩ #align is_compact.exists_thickening_subset_open IsCompact.exists_thickening_subset_open theorem hasBasis_nhdsSet_thickening {K : Set α} (hK : IsCompact K) : (𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => thickening δ K := (hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_thickening_subset_open hU.1 hU.2) fun _ => thickening_mem_nhdsSet K #align metric.has_basis_nhds_set_thickening Metric.hasBasis_nhdsSet_thickening theorem hasBasis_nhdsSet_cthickening {K : Set α} (hK : IsCompact K) : (𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => cthickening δ K := (hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_cthickening_subset_open hU.1 hU.2) fun _ => cthickening_mem_nhdsSet K #align metric.has_basis_nhds_set_cthickening Metric.hasBasis_nhdsSet_cthickening theorem cthickening_eq_iInter_cthickening' {δ : ℝ} (s : Set ℝ) (hsδ : s ⊆ Ioi δ) (hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) : cthickening δ E = ⋂ ε ∈ s, cthickening ε E := by apply Subset.antisymm · exact subset_iInter₂ fun _ hε => cthickening_mono (le_of_lt (hsδ hε)) E · unfold cthickening intro x hx simp only [mem_iInter, mem_setOf_eq] at * apply ENNReal.le_of_forall_pos_le_add intro η η_pos _ rcases hs (δ + η) (lt_add_of_pos_right _ (NNReal.coe_pos.mpr η_pos)) with ⟨ε, ⟨hsε, hε⟩⟩ apply ((hx ε hsε).trans (ENNReal.ofReal_le_ofReal hε.2)).trans rw [ENNReal.coe_nnreal_eq η] exact ENNReal.ofReal_add_le #align metric.cthickening_eq_Inter_cthickening' Metric.cthickening_eq_iInter_cthickening' theorem cthickening_eq_iInter_cthickening {δ : ℝ} (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), cthickening ε E := by apply cthickening_eq_iInter_cthickening' (Ioi δ) rfl.subset simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self] exact fun _ hε => nonempty_Ioc.mpr hε #align metric.cthickening_eq_Inter_cthickening Metric.cthickening_eq_iInter_cthickening theorem cthickening_eq_iInter_thickening' {δ : ℝ} (δ_nn : 0 ≤ δ) (s : Set ℝ) (hsδ : s ⊆ Ioi δ) (hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) : cthickening δ E = ⋂ ε ∈ s, thickening ε E := by refine (subset_iInter₂ fun ε hε => ?_).antisymm ?_ · obtain ⟨ε', -, hε'⟩ := hs ε (hsδ hε) have ss := cthickening_subset_thickening' (lt_of_le_of_lt δ_nn hε'.1) hε'.1 E exact ss.trans (thickening_mono hε'.2 E) · rw [cthickening_eq_iInter_cthickening' s hsδ hs E] exact iInter₂_mono fun ε _ => thickening_subset_cthickening ε E #align metric.cthickening_eq_Inter_thickening' Metric.cthickening_eq_iInter_thickening' theorem cthickening_eq_iInter_thickening {δ : ℝ} (δ_nn : 0 ≤ δ) (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), thickening ε E := by apply cthickening_eq_iInter_thickening' δ_nn (Ioi δ) rfl.subset simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self] exact fun _ hε => nonempty_Ioc.mpr hε #align metric.cthickening_eq_Inter_thickening Metric.cthickening_eq_iInter_thickening theorem cthickening_eq_iInter_thickening'' (δ : ℝ) (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : max 0 δ < ε), thickening ε E := by rw [← cthickening_max_zero, cthickening_eq_iInter_thickening] exact le_max_left _ _ #align metric.cthickening_eq_Inter_thickening'' Metric.cthickening_eq_iInter_thickening'' /-- The closure of a set equals the intersection of its closed thickenings of positive radii accumulating at zero. -/ theorem closure_eq_iInter_cthickening' (E : Set α) (s : Set ℝ) (hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, cthickening δ E := by by_cases hs₀ : s ⊆ Ioi 0 · rw [← cthickening_zero] apply cthickening_eq_iInter_cthickening' _ hs₀ hs obtain ⟨δ, hδs, δ_nonpos⟩ := not_subset.mp hs₀ rw [Set.mem_Ioi, not_lt] at δ_nonpos apply Subset.antisymm · exact subset_iInter₂ fun ε _ => closure_subset_cthickening ε E · rw [← cthickening_of_nonpos δ_nonpos E] exact biInter_subset_of_mem hδs #align metric.closure_eq_Inter_cthickening' Metric.closure_eq_iInter_cthickening' /-- The closure of a set equals the intersection of its closed thickenings of positive radii. -/ theorem closure_eq_iInter_cthickening (E : Set α) : closure E = ⋂ (δ : ℝ) (_ : 0 < δ), cthickening δ E := by rw [← cthickening_zero] exact cthickening_eq_iInter_cthickening E #align metric.closure_eq_Inter_cthickening Metric.closure_eq_iInter_cthickening /-- The closure of a set equals the intersection of its open thickenings of positive radii accumulating at zero. -/ theorem closure_eq_iInter_thickening' (E : Set α) (s : Set ℝ) (hs₀ : s ⊆ Ioi 0) (hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, thickening δ E := by rw [← cthickening_zero] apply cthickening_eq_iInter_thickening' le_rfl _ hs₀ hs #align metric.closure_eq_Inter_thickening' Metric.closure_eq_iInter_thickening' /-- The closure of a set equals the intersection of its (open) thickenings of positive radii. -/ theorem closure_eq_iInter_thickening (E : Set α) : closure E = ⋂ (δ : ℝ) (_ : 0 < δ), thickening δ E := by rw [← cthickening_zero] exact cthickening_eq_iInter_thickening rfl.ge E #align metric.closure_eq_Inter_thickening Metric.closure_eq_iInter_thickening /-- The frontier of the closed thickening of a set is contained in an `EMetric.infEdist` level set. -/ theorem frontier_cthickening_subset (E : Set α) {δ : ℝ} : frontier (cthickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } := frontier_le_subset_eq continuous_infEdist continuous_const #align metric.frontier_cthickening_subset Metric.frontier_cthickening_subset /-- The closed ball of radius `δ` centered at a point of `E` is included in the closed thickening of `E`. -/ theorem closedBall_subset_cthickening {α : Type*} [PseudoMetricSpace α] {x : α} {E : Set α} (hx : x ∈ E) (δ : ℝ) : closedBall x δ ⊆ cthickening δ E := by refine (closedBall_subset_cthickening_singleton _ _).trans (cthickening_subset_of_subset _ ?_) simpa using hx #align metric.closed_ball_subset_cthickening Metric.closedBall_subset_cthickening theorem cthickening_subset_iUnion_closedBall_of_lt {α : Type*} [PseudoMetricSpace α] (E : Set α) {δ δ' : ℝ} (hδ₀ : 0 < δ') (hδδ' : δ < δ') : cthickening δ E ⊆ ⋃ x ∈ E, closedBall x δ' := by refine (cthickening_subset_thickening' hδ₀ hδδ' E).trans fun x hx => ?_ obtain ⟨y, hy₁, hy₂⟩ := mem_thickening_iff.mp hx exact mem_iUnion₂.mpr ⟨y, hy₁, hy₂.le⟩ #align metric.cthickening_subset_Union_closed_ball_of_lt Metric.cthickening_subset_iUnion_closedBall_of_lt /-- The closed thickening of a compact set `E` is the union of the balls `Metric.closedBall x δ` over `x ∈ E`. See also `Metric.cthickening_eq_biUnion_closedBall`. -/ theorem _root_.IsCompact.cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α} (hE : IsCompact E) (hδ : 0 ≤ δ) : cthickening δ E = ⋃ x ∈ E, closedBall x δ := by rcases eq_empty_or_nonempty E with (rfl | hne) · simp only [cthickening_empty, biUnion_empty] refine Subset.antisymm (fun x hx ↦ ?_) (iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _) obtain ⟨y, yE, hy⟩ : ∃ y ∈ E, infEdist x E = edist x y := hE.exists_infEdist_eq_edist hne _ have D1 : edist x y ≤ ENNReal.ofReal δ := (le_of_eq hy.symm).trans hx have D2 : dist x y ≤ δ := by rw [edist_dist] at D1 exact (ENNReal.ofReal_le_ofReal_iff hδ).1 D1 exact mem_biUnion yE D2 #align is_compact.cthickening_eq_bUnion_closed_ball IsCompact.cthickening_eq_biUnion_closedBall
Mathlib/Topology/MetricSpace/Thickening.lean
620
632
theorem cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α] [ProperSpace α] (E : Set α) (hδ : 0 ≤ δ) : cthickening δ E = ⋃ x ∈ closure E, closedBall x δ := by
rcases eq_empty_or_nonempty E with (rfl | hne) · simp only [cthickening_empty, biUnion_empty, closure_empty] rw [← cthickening_closure] refine Subset.antisymm (fun x hx ↦ ?_) (iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _) obtain ⟨y, yE, hy⟩ : ∃ y ∈ closure E, infDist x (closure E) = dist x y := isClosed_closure.exists_infDist_eq_dist (closure_nonempty_iff.mpr hne) x replace hy : dist x y ≤ δ := (ENNReal.ofReal_le_ofReal_iff hδ).mp (((congr_arg ENNReal.ofReal hy.symm).le.trans ENNReal.ofReal_toReal_le).trans hx) exact mem_biUnion yE hy
/- 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, Yury Kudryashov -/ import Mathlib.Order.Filter.Interval import Mathlib.Order.Interval.Set.Pi import Mathlib.Tactic.TFAE import Mathlib.Tactic.NormNum import Mathlib.Topology.Order.LeftRight import Mathlib.Topology.Order.OrderClosed #align_import topology.order.basic from "leanprover-community/mathlib"@"3efd324a3a31eaa40c9d5bfc669c4fafee5f9423" /-! # Theory of topology on ordered spaces ## Main definitions The order topology on an ordered space is the topology generated by all open intervals (or equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `Preorder.topology α`. However, we do *not* register it as an instance (as many existing ordered types already have topologies, which would be equal but not definitionally equal to `Preorder.topology α`). Instead, we introduce a class `OrderTopology α` (which is a `Prop`, also known as a mixin) saying that on the type `α` having already a topological space structure and a preorder structure, the topological structure is equal to the order topology. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`OrderClosedTopology` vs `OrderTopology`, `Preorder` vs `PartialOrder` vs `LinearOrder` etc) see their statements. * `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`. * `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem, sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h` both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`. ## Implementation notes We do _not_ register the order topology as an instance on a preorder (or even on a linear order). Indeed, on many such spaces, a topology has already been constructed in a different way (think of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`), and is in general not defeq to the one generated by the intervals. We make it available as a definition `Preorder.topology α` though, that can be registered as an instance when necessary, or for specific types. -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) universe u v w variable {α : Type u} {β : Type v} {γ : Type w} -- Porting note (#11215): TODO: define `Preorder.topology` before `OrderTopology` and reuse the def /-- The order topology on an ordered type is the topology generated by open intervals. We register it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed. We define it as a mixin. If you want to introduce the order topology on a preorder, use `Preorder.topology`. -/ class OrderTopology (α : Type*) [t : TopologicalSpace α] [Preorder α] : Prop where /-- The topology is generated by open intervals `Set.Ioi _` and `Set.Iio _`. -/ topology_eq_generate_intervals : t = generateFrom { s | ∃ a, s = Ioi a ∨ s = Iio a } #align order_topology OrderTopology /-- (Order) topology on a partial order `α` generated by the subbase of open intervals `(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an instance as many ordered sets are already endowed with the same topology, most often in a non-defeq way though. Register as a local instance when necessary. -/ def Preorder.topology (α : Type*) [Preorder α] : TopologicalSpace α := generateFrom { s : Set α | ∃ a : α, s = { b : α | a < b } ∨ s = { b : α | b < a } } #align preorder.topology Preorder.topology section OrderTopology section Preorder variable [TopologicalSpace α] [Preorder α] [t : OrderTopology α] instance : OrderTopology αᵒᵈ := ⟨by convert OrderTopology.topology_eq_generate_intervals (α := α) using 6 apply or_comm⟩ theorem isOpen_iff_generate_intervals {s : Set α} : IsOpen s ↔ GenerateOpen { s | ∃ a, s = Ioi a ∨ s = Iio a } s := by rw [t.topology_eq_generate_intervals]; rfl #align is_open_iff_generate_intervals isOpen_iff_generate_intervals theorem isOpen_lt' (a : α) : IsOpen { b : α | a < b } := isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inl rfl⟩ #align is_open_lt' isOpen_lt' theorem isOpen_gt' (a : α) : IsOpen { b : α | b < a } := isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inr rfl⟩ #align is_open_gt' isOpen_gt' theorem lt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a < x := (isOpen_lt' _).mem_nhds h #align lt_mem_nhds lt_mem_nhds theorem le_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x := (lt_mem_nhds h).mono fun _ => le_of_lt #align le_mem_nhds le_mem_nhds theorem gt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b := (isOpen_gt' _).mem_nhds h #align gt_mem_nhds gt_mem_nhds theorem ge_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := (gt_mem_nhds h).mono fun _ => le_of_lt #align ge_mem_nhds ge_mem_nhds theorem nhds_eq_order (a : α) : 𝓝 a = (⨅ b ∈ Iio a, 𝓟 (Ioi b)) ⊓ ⨅ b ∈ Ioi a, 𝓟 (Iio b) := by rw [t.topology_eq_generate_intervals, nhds_generateFrom] simp_rw [mem_setOf_eq, @and_comm (a ∈ _), exists_or, or_and_right, iInf_or, iInf_and, iInf_exists, iInf_inf_eq, iInf_comm (ι := Set α), iInf_iInf_eq_left, mem_Ioi, mem_Iio] #align nhds_eq_order nhds_eq_order theorem tendsto_order {f : β → α} {a : α} {x : Filter β} : Tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ ∀ a' > a, ∀ᶠ b in x, f b < a' := by simp only [nhds_eq_order a, tendsto_inf, tendsto_iInf, tendsto_principal]; rfl #align tendsto_order tendsto_order instance tendstoIccClassNhds (a : α) : TendstoIxxClass Icc (𝓝 a) (𝓝 a) := by simp only [nhds_eq_order, iInf_subtype'] refine ((hasBasis_iInf_principal_finite _).inf (hasBasis_iInf_principal_finite _)).tendstoIxxClass fun s _ => ?_ refine ((ordConnected_biInter ?_).inter (ordConnected_biInter ?_)).out <;> intro _ _ exacts [ordConnected_Ioi, ordConnected_Iio] #align tendsto_Icc_class_nhds tendstoIccClassNhds instance tendstoIcoClassNhds (a : α) : TendstoIxxClass Ico (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self #align tendsto_Ico_class_nhds tendstoIcoClassNhds instance tendstoIocClassNhds (a : α) : TendstoIxxClass Ioc (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self #align tendsto_Ioc_class_nhds tendstoIocClassNhds instance tendstoIooClassNhds (a : α) : TendstoIxxClass Ioo (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self #align tendsto_Ioo_class_nhds tendstoIooClassNhds /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold eventually for the filter. -/ theorem tendsto_of_tendsto_of_tendsto_of_le_of_le' {f g h : β → α} {b : Filter β} {a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : ∀ᶠ b in b, g b ≤ f b) (hfh : ∀ᶠ b in b, f b ≤ h b) : Tendsto f b (𝓝 a) := (hg.Icc hh).of_smallSets <| hgf.and hfh #align tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_of_tendsto_of_tendsto_of_le_of_le' /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold everywhere. -/ theorem tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : Filter β} {a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) : Tendsto f b (𝓝 a) := tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh (eventually_of_forall hgf) (eventually_of_forall hfh) #align tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_of_tendsto_of_tendsto_of_le_of_le theorem nhds_order_unbounded {a : α} (hu : ∃ u, a < u) (hl : ∃ l, l < a) : 𝓝 a = ⨅ (l) (_ : l < a) (u) (_ : a < u), 𝓟 (Ioo l u) := by simp only [nhds_eq_order, ← inf_biInf, ← biInf_inf, *, ← inf_principal, ← Ioi_inter_Iio]; rfl #align nhds_order_unbounded nhds_order_unbounded theorem tendsto_order_unbounded {f : β → α} {a : α} {x : Filter β} (hu : ∃ u, a < u) (hl : ∃ l, l < a) (h : ∀ l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) : Tendsto f x (𝓝 a) := by simp only [nhds_order_unbounded hu hl, tendsto_iInf, tendsto_principal] exact fun l hl u => h l u hl #align tendsto_order_unbounded tendsto_order_unbounded end Preorder instance tendstoIxxNhdsWithin {α : Type*} [TopologicalSpace α] (a : α) {s t : Set α} {Ixx} [TendstoIxxClass Ixx (𝓝 a) (𝓝 a)] [TendstoIxxClass Ixx (𝓟 s) (𝓟 t)] : TendstoIxxClass Ixx (𝓝[s] a) (𝓝[t] a) := Filter.tendstoIxxClass_inf #align tendsto_Ixx_nhds_within tendstoIxxNhdsWithin instance tendstoIccClassNhdsPi {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] [∀ i, TopologicalSpace (α i)] [∀ i, OrderTopology (α i)] (f : ∀ i, α i) : TendstoIxxClass Icc (𝓝 f) (𝓝 f) := by constructor conv in (𝓝 f).smallSets => rw [nhds_pi, Filter.pi] simp only [smallSets_iInf, smallSets_comap_eq_comap_image, tendsto_iInf, tendsto_comap_iff] intro i have : Tendsto (fun g : ∀ i, α i => g i) (𝓝 f) (𝓝 (f i)) := (continuous_apply i).tendsto f refine (this.comp tendsto_fst).Icc (this.comp tendsto_snd) |>.smallSets_mono ?_ filter_upwards [] using fun ⟨f, g⟩ ↦ image_subset_iff.mpr fun p hp ↦ ⟨hp.1 i, hp.2 i⟩ #align tendsto_Icc_class_nhds_pi tendstoIccClassNhdsPi -- Porting note (#10756): new lemma theorem induced_topology_le_preorder [Preorder α] [Preorder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y) : induced f ‹TopologicalSpace β› ≤ Preorder.topology α := by let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩ refine le_of_nhds_le_nhds fun x => ?_ simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal, Ioi, Iio, ← hf] refine inf_le_inf (le_iInf₂ fun a ha => ?_) (le_iInf₂ fun a ha => ?_) exacts [iInf₂_le (f a) ha, iInf₂_le (f a) ha] -- Porting note (#10756): new lemma theorem induced_topology_eq_preorder [Preorder α] [Preorder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a b x}, b < f a → ¬(b < f x) → ∃ y, y < a ∧ b ≤ f y) (H₂ : ∀ {a b x}, f a < b → ¬(f x < b) → ∃ y, a < y ∧ f y ≤ b) : induced f ‹TopologicalSpace β› = Preorder.topology α := by let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩ refine le_antisymm (induced_topology_le_preorder hf) ?_ refine le_of_nhds_le_nhds fun a => ?_ simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal] refine inf_le_inf (le_iInf₂ fun b hb => ?_) (le_iInf₂ fun b hb => ?_) · rcases em (∃ x, ¬(b < f x)) with (⟨x, hx⟩ | hb) · rcases H₁ hb hx with ⟨y, hya, hyb⟩ exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => hyb.trans_lt (hf.2 hz)) · push_neg at hb exact le_principal_iff.2 (univ_mem' hb) · rcases em (∃ x, ¬(f x < b)) with (⟨x, hx⟩ | hb) · rcases H₂ hb hx with ⟨y, hya, hyb⟩ exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => (hf.2 hz).trans_le hyb) · push_neg at hb exact le_principal_iff.2 (univ_mem' hb) theorem induced_orderTopology' {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β] [Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) : @OrderTopology _ (induced f ta) _ := let _ := induced f ta ⟨induced_topology_eq_preorder hf (fun h _ => H₁ h) (fun h _ => H₂ h)⟩ #align induced_order_topology' induced_orderTopology' theorem induced_orderTopology {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β] [Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @OrderTopology _ (induced f ta) _ := induced_orderTopology' f (hf) (fun xa => let ⟨b, xb, ba⟩ := H xa; ⟨b, hf.1 ba, le_of_lt xb⟩) fun ax => let ⟨b, ab, bx⟩ := H ax; ⟨b, hf.1 ab, le_of_lt bx⟩ #align induced_order_topology induced_orderTopology /-- The topology induced by a strictly monotone function with order-connected range is the preorder topology. -/ nonrec theorem StrictMono.induced_topology_eq_preorder {α β : Type*} [LinearOrder α] [LinearOrder β] [t : TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : StrictMono f) (hc : OrdConnected (range f)) : t.induced f = Preorder.topology α := by refine induced_topology_eq_preorder hf.lt_iff_lt (fun h₁ h₂ => ?_) fun h₁ h₂ => ?_ · rcases hc.out (mem_range_self _) (mem_range_self _) ⟨not_lt.1 h₂, h₁.le⟩ with ⟨y, rfl⟩ exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩ · rcases hc.out (mem_range_self _) (mem_range_self _) ⟨h₁.le, not_lt.1 h₂⟩ with ⟨y, rfl⟩ exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩ /-- A strictly monotone function between linear orders with order topology is a topological embedding provided that the range of `f` is order-connected. -/ theorem StrictMono.embedding_of_ordConnected {α β : Type*} [LinearOrder α] [LinearOrder β] [TopologicalSpace α] [h : OrderTopology α] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : StrictMono f) (hc : OrdConnected (range f)) : Embedding f := ⟨⟨h.1.trans <| Eq.symm <| hf.induced_topology_eq_preorder hc⟩, hf.injective⟩ /-- On a `Set.OrdConnected` subset of a linear order, the order topology for the restriction of the order is the same as the restriction to the subset of the order topology. -/ instance orderTopology_of_ordConnected {α : Type u} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {t : Set α} [ht : OrdConnected t] : OrderTopology t := ⟨(Subtype.strictMono_coe t).induced_topology_eq_preorder <| by rwa [← @Subtype.range_val _ t] at ht⟩ #align order_topology_of_ord_connected orderTopology_of_ordConnected theorem nhdsWithin_Ici_eq'' [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) : 𝓝[≥] a = (⨅ (u) (_ : a < u), 𝓟 (Iio u)) ⊓ 𝓟 (Ici a) := by rw [nhdsWithin, nhds_eq_order] refine le_antisymm (inf_le_inf_right _ inf_le_right) (le_inf (le_inf ?_ inf_le_left) inf_le_right) exact inf_le_right.trans (le_iInf₂ fun l hl => principal_mono.2 <| Ici_subset_Ioi.2 hl) #align nhds_within_Ici_eq'' nhdsWithin_Ici_eq'' theorem nhdsWithin_Iic_eq'' [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) : 𝓝[≤] a = (⨅ l < a, 𝓟 (Ioi l)) ⊓ 𝓟 (Iic a) := nhdsWithin_Ici_eq'' (toDual a) #align nhds_within_Iic_eq'' nhdsWithin_Iic_eq'' theorem nhdsWithin_Ici_eq' [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α} (ha : ∃ u, a < u) : 𝓝[≥] a = ⨅ (u) (_ : a < u), 𝓟 (Ico a u) := by simp only [nhdsWithin_Ici_eq'', biInf_inf ha, inf_principal, Iio_inter_Ici] #align nhds_within_Ici_eq' nhdsWithin_Ici_eq' theorem nhdsWithin_Iic_eq' [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α} (ha : ∃ l, l < a) : 𝓝[≤] a = ⨅ l < a, 𝓟 (Ioc l a) := by simp only [nhdsWithin_Iic_eq'', biInf_inf ha, inf_principal, Ioi_inter_Iic] #align nhds_within_Iic_eq' nhdsWithin_Iic_eq' theorem nhdsWithin_Ici_basis' [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α} (ha : ∃ u, a < u) : (𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u := (nhdsWithin_Ici_eq' ha).symm ▸ hasBasis_biInf_principal (fun b hb c hc => ⟨min b c, lt_min hb hc, Ico_subset_Ico_right (min_le_left _ _), Ico_subset_Ico_right (min_le_right _ _)⟩) ha #align nhds_within_Ici_basis' nhdsWithin_Ici_basis' theorem nhdsWithin_Iic_basis' [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α} (ha : ∃ l, l < a) : (𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a := by convert nhdsWithin_Ici_basis' (α := αᵒᵈ) ha using 2 exact dual_Ico.symm #align nhds_within_Iic_basis' nhdsWithin_Iic_basis' theorem nhdsWithin_Ici_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMaxOrder α] (a : α) : (𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u := nhdsWithin_Ici_basis' (exists_gt a) #align nhds_within_Ici_basis nhdsWithin_Ici_basis theorem nhdsWithin_Iic_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMinOrder α] (a : α) : (𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a := nhdsWithin_Iic_basis' (exists_lt a) #align nhds_within_Iic_basis nhdsWithin_Iic_basis theorem nhds_top_order [TopologicalSpace α] [Preorder α] [OrderTop α] [OrderTopology α] : 𝓝 (⊤ : α) = ⨅ (l) (h₂ : l < ⊤), 𝓟 (Ioi l) := by simp [nhds_eq_order (⊤ : α)] #align nhds_top_order nhds_top_order theorem nhds_bot_order [TopologicalSpace α] [Preorder α] [OrderBot α] [OrderTopology α] : 𝓝 (⊥ : α) = ⨅ (l) (h₂ : ⊥ < l), 𝓟 (Iio l) := by simp [nhds_eq_order (⊥ : α)] #align nhds_bot_order nhds_bot_order theorem nhds_top_basis [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α] [Nontrivial α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) fun a : α => Ioi a := by have : ∃ x : α, x < ⊤ := (exists_ne ⊤).imp fun x hx => hx.lt_top simpa only [Iic_top, nhdsWithin_univ, Ioc_top] using nhdsWithin_Iic_basis' this #align nhds_top_basis nhds_top_basis theorem nhds_bot_basis [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α] [Nontrivial α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) fun a : α => Iio a := nhds_top_basis (α := αᵒᵈ) #align nhds_bot_basis nhds_bot_basis theorem nhds_top_basis_Ici [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α] [Nontrivial α] [DenselyOrdered α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) Ici := nhds_top_basis.to_hasBasis (fun _a ha => let ⟨b, hab, hb⟩ := exists_between ha; ⟨b, hb, Ici_subset_Ioi.mpr hab⟩) fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩ #align nhds_top_basis_Ici nhds_top_basis_Ici theorem nhds_bot_basis_Iic [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α] [Nontrivial α] [DenselyOrdered α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) Iic := nhds_top_basis_Ici (α := αᵒᵈ) #align nhds_bot_basis_Iic nhds_bot_basis_Iic theorem tendsto_nhds_top_mono [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) : Tendsto g l (𝓝 ⊤) := by simp only [nhds_top_order, tendsto_iInf, tendsto_principal] at hf ⊢ intro x hx filter_upwards [hf x hx, hg] with _ using lt_of_lt_of_le #align tendsto_nhds_top_mono tendsto_nhds_top_mono theorem tendsto_nhds_bot_mono [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) : Tendsto g l (𝓝 ⊥) := tendsto_nhds_top_mono (β := βᵒᵈ) hf hg #align tendsto_nhds_bot_mono tendsto_nhds_bot_mono theorem tendsto_nhds_top_mono' [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ g) : Tendsto g l (𝓝 ⊤) := tendsto_nhds_top_mono hf (eventually_of_forall hg) #align tendsto_nhds_top_mono' tendsto_nhds_top_mono' theorem tendsto_nhds_bot_mono' [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ f) : Tendsto g l (𝓝 ⊥) := tendsto_nhds_bot_mono hf (eventually_of_forall hg) #align tendsto_nhds_bot_mono' tendsto_nhds_bot_mono' section LinearOrder variable [TopologicalSpace α] [LinearOrder α] section OrderTopology variable [OrderTopology α] theorem order_separated {a₁ a₂ : α} (h : a₁ < a₂) : ∃ u v : Set α, IsOpen u ∧ IsOpen v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ ∀ b₁ ∈ u, ∀ b₂ ∈ v, b₁ < b₂ := let ⟨x, hx, y, hy, h⟩ := h.exists_disjoint_Iio_Ioi ⟨Iio x, Ioi y, isOpen_gt' _, isOpen_lt' _, hx, hy, h⟩ #align order_separated order_separated -- see Note [lower instance priority] instance (priority := 100) OrderTopology.to_orderClosedTopology : OrderClosedTopology α where isClosed_le' := isOpen_compl_iff.1 <| isOpen_prod_iff.mpr fun a₁ a₂ (h : ¬a₁ ≤ a₂) => have h : a₂ < a₁ := lt_of_not_ge h let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h ⟨v, u, hv, hu, ha₂, ha₁, fun ⟨b₁, b₂⟩ ⟨h₁, h₂⟩ => not_le_of_gt <| h b₂ h₂ b₁ h₁⟩ #align order_topology.to_order_closed_topology OrderTopology.to_orderClosedTopology theorem exists_Ioc_subset_of_mem_nhds {a : α} {s : Set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) : ∃ l < a, Ioc l a ⊆ s := (nhdsWithin_Iic_basis' h).mem_iff.mp (nhdsWithin_le_nhds hs) #align exists_Ioc_subset_of_mem_nhds exists_Ioc_subset_of_mem_nhds theorem exists_Ioc_subset_of_mem_nhds' {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {l : α} (hl : l < a) : ∃ l' ∈ Ico l a, Ioc l' a ⊆ s := let ⟨l', hl'a, hl's⟩ := exists_Ioc_subset_of_mem_nhds hs ⟨l, hl⟩ ⟨max l l', ⟨le_max_left _ _, max_lt hl hl'a⟩, (Ioc_subset_Ioc_left <| le_max_right _ _).trans hl's⟩ #align exists_Ioc_subset_of_mem_nhds' exists_Ioc_subset_of_mem_nhds' theorem exists_Ico_subset_of_mem_nhds' {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {u : α} (hu : a < u) : ∃ u' ∈ Ioc a u, Ico a u' ⊆ s := by simpa only [OrderDual.exists, exists_prop, dual_Ico, dual_Ioc] using exists_Ioc_subset_of_mem_nhds' (show ofDual ⁻¹' s ∈ 𝓝 (toDual a) from hs) hu.dual #align exists_Ico_subset_of_mem_nhds' exists_Ico_subset_of_mem_nhds' theorem exists_Ico_subset_of_mem_nhds {a : α} {s : Set α} (hs : s ∈ 𝓝 a) (h : ∃ u, a < u) : ∃ u, a < u ∧ Ico a u ⊆ s := let ⟨_l', hl'⟩ := h; let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' ⟨l, hl.1.1, hl.2⟩ #align exists_Ico_subset_of_mem_nhds exists_Ico_subset_of_mem_nhds theorem exists_Icc_mem_subset_of_mem_nhdsWithin_Ici {a : α} {s : Set α} (hs : s ∈ 𝓝[≥] a) : ∃ b, a ≤ b ∧ Icc a b ∈ 𝓝[≥] a ∧ Icc a b ⊆ s := by rcases (em (IsMax a)).imp_right not_isMax_iff.mp with (ha | ha) · use a simpa [ha.Ici_eq] using hs · rcases (nhdsWithin_Ici_basis' ha).mem_iff.mp hs with ⟨b, hab, hbs⟩ rcases eq_empty_or_nonempty (Ioo a b) with (H | ⟨c, hac, hcb⟩) · have : Ico a b = Icc a a := by rw [← Icc_union_Ioo_eq_Ico le_rfl hab, H, union_empty] exact ⟨a, le_rfl, this ▸ ⟨Ico_mem_nhdsWithin_Ici' hab, hbs⟩⟩ · refine ⟨c, hac.le, Icc_mem_nhdsWithin_Ici' hac, ?_⟩ exact (Icc_subset_Ico_right hcb).trans hbs #align exists_Icc_mem_subset_of_mem_nhds_within_Ici exists_Icc_mem_subset_of_mem_nhdsWithin_Ici theorem exists_Icc_mem_subset_of_mem_nhdsWithin_Iic {a : α} {s : Set α} (hs : s ∈ 𝓝[≤] a) : ∃ b ≤ a, Icc b a ∈ 𝓝[≤] a ∧ Icc b a ⊆ s := by simpa only [dual_Icc, toDual.surjective.exists] using exists_Icc_mem_subset_of_mem_nhdsWithin_Ici (α := αᵒᵈ) (a := toDual a) hs #align exists_Icc_mem_subset_of_mem_nhds_within_Iic exists_Icc_mem_subset_of_mem_nhdsWithin_Iic theorem exists_Icc_mem_subset_of_mem_nhds {a : α} {s : Set α} (hs : s ∈ 𝓝 a) : ∃ b c, a ∈ Icc b c ∧ Icc b c ∈ 𝓝 a ∧ Icc b c ⊆ s := by rcases exists_Icc_mem_subset_of_mem_nhdsWithin_Iic (nhdsWithin_le_nhds hs) with ⟨b, hba, hb_nhds, hbs⟩ rcases exists_Icc_mem_subset_of_mem_nhdsWithin_Ici (nhdsWithin_le_nhds hs) with ⟨c, hac, hc_nhds, hcs⟩ refine ⟨b, c, ⟨hba, hac⟩, ?_⟩ rw [← Icc_union_Icc_eq_Icc hba hac, ← nhds_left_sup_nhds_right] exact ⟨union_mem_sup hb_nhds hc_nhds, union_subset hbs hcs⟩ #align exists_Icc_mem_subset_of_mem_nhds exists_Icc_mem_subset_of_mem_nhds theorem IsOpen.exists_Ioo_subset [Nontrivial α] {s : Set α} (hs : IsOpen s) (h : s.Nonempty) : ∃ a b, a < b ∧ Ioo a b ⊆ s := by obtain ⟨x, hx⟩ : ∃ x, x ∈ s := h obtain ⟨y, hy⟩ : ∃ y, y ≠ x := exists_ne x rcases lt_trichotomy x y with (H | rfl | H) · obtain ⟨u, xu, hu⟩ : ∃ u, x < u ∧ Ico x u ⊆ s := exists_Ico_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩ exact ⟨x, u, xu, Ioo_subset_Ico_self.trans hu⟩ · exact (hy rfl).elim · obtain ⟨l, lx, hl⟩ : ∃ l, l < x ∧ Ioc l x ⊆ s := exists_Ioc_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩ exact ⟨l, x, lx, Ioo_subset_Ioc_self.trans hl⟩ #align is_open.exists_Ioo_subset IsOpen.exists_Ioo_subset theorem dense_of_exists_between [Nontrivial α] {s : Set α} (h : ∀ ⦃a b⦄, a < b → ∃ c ∈ s, a < c ∧ c < b) : Dense s := by refine dense_iff_inter_open.2 fun U U_open U_nonempty => ?_ obtain ⟨a, b, hab, H⟩ : ∃ a b : α, a < b ∧ Ioo a b ⊆ U := U_open.exists_Ioo_subset U_nonempty obtain ⟨x, xs, hx⟩ : ∃ x ∈ s, a < x ∧ x < b := h hab exact ⟨x, ⟨H hx, xs⟩⟩ #align dense_of_exists_between dense_of_exists_between /-- A set in a nontrivial densely linear ordered type is dense in the sense of topology if and only if for any `a < b` there exists `c ∈ s`, `a < c < b`. Each implication requires less typeclass assumptions. -/ theorem dense_iff_exists_between [DenselyOrdered α] [Nontrivial α] {s : Set α} : Dense s ↔ ∀ a b, a < b → ∃ c ∈ s, a < c ∧ c < b := ⟨fun h _ _ hab => h.exists_between hab, dense_of_exists_between⟩ #align dense_iff_exists_between dense_iff_exists_between /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`, provided `a` is neither a bottom element nor a top element. -/ theorem mem_nhds_iff_exists_Ioo_subset' {a : α} {s : Set α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : s ∈ 𝓝 a ↔ ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := by constructor · intro h rcases exists_Ico_subset_of_mem_nhds h hu with ⟨u, au, hu⟩ rcases exists_Ioc_subset_of_mem_nhds h hl with ⟨l, la, hl⟩ exact ⟨l, u, ⟨la, au⟩, Ioc_union_Ico_eq_Ioo la au ▸ union_subset hl hu⟩ · rintro ⟨l, u, ha, h⟩ apply mem_of_superset (Ioo_mem_nhds ha.1 ha.2) h #align mem_nhds_iff_exists_Ioo_subset' mem_nhds_iff_exists_Ioo_subset' /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`. -/ theorem mem_nhds_iff_exists_Ioo_subset [NoMaxOrder α] [NoMinOrder α] {a : α} {s : Set α} : s ∈ 𝓝 a ↔ ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := mem_nhds_iff_exists_Ioo_subset' (exists_lt a) (exists_gt a) #align mem_nhds_iff_exists_Ioo_subset mem_nhds_iff_exists_Ioo_subset theorem nhds_basis_Ioo' {a : α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : (𝓝 a).HasBasis (fun b : α × α => b.1 < a ∧ a < b.2) fun b => Ioo b.1 b.2 := ⟨fun s => (mem_nhds_iff_exists_Ioo_subset' hl hu).trans <| by simp⟩ #align nhds_basis_Ioo' nhds_basis_Ioo' theorem nhds_basis_Ioo [NoMaxOrder α] [NoMinOrder α] (a : α) : (𝓝 a).HasBasis (fun b : α × α => b.1 < a ∧ a < b.2) fun b => Ioo b.1 b.2 := nhds_basis_Ioo' (exists_lt a) (exists_gt a) #align nhds_basis_Ioo nhds_basis_Ioo theorem Filter.Eventually.exists_Ioo_subset [NoMaxOrder α] [NoMinOrder α] {a : α} {p : α → Prop} (hp : ∀ᶠ x in 𝓝 a, p x) : ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ { x | p x } := mem_nhds_iff_exists_Ioo_subset.1 hp #align filter.eventually.exists_Ioo_subset Filter.Eventually.exists_Ioo_subset theorem Dense.topology_eq_generateFrom [DenselyOrdered α] {s : Set α} (hs : Dense s) : ‹TopologicalSpace α› = .generateFrom (Ioi '' s ∪ Iio '' s) := by refine (OrderTopology.topology_eq_generate_intervals (α := α)).trans ?_ refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_) · simp only [union_subset_iff, image_subset_iff] exact ⟨fun a _ ↦ ⟨a, .inl rfl⟩, fun a _ ↦ ⟨a, .inr rfl⟩⟩ · rintro _ ⟨a, rfl | rfl⟩ · rw [hs.Ioi_eq_biUnion] let _ := generateFrom (Ioi '' s ∪ Iio '' s) exact isOpen_iUnion fun x ↦ isOpen_iUnion fun h ↦ .basic _ <| .inl <| mem_image_of_mem _ h.1 · rw [hs.Iio_eq_biUnion] let _ := generateFrom (Ioi '' s ∪ Iio '' s) exact isOpen_iUnion fun x ↦ isOpen_iUnion fun h ↦ .basic _ <| .inr <| mem_image_of_mem _ h.1 @[deprecated OrderBot.atBot_eq (since := "2024-02-14")]
Mathlib/Topology/Order/Basic.lean
532
534
theorem atBot_le_nhds_bot [OrderBot α] : (atBot : Filter α) ≤ 𝓝 ⊥ := by
rw [OrderBot.atBot_eq] apply pure_le_nhds
/- 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.Polynomial.Derivative import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.EuclideanDomain #align_import data.polynomial.field_division from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821" /-! # Theory of univariate polynomials This file starts looking like the ring theory of $R[X]$ -/ noncomputable section open Polynomial namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ} section CommRing variable [CommRing R] theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero (p : R[X]) (t : R) (hnezero : derivative p ≠ 0) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := (le_rootMultiplicity_iff hnezero).2 <| pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t) theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors {p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t) (hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) : (derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · simp only [h, map_zero, rootMultiplicity_zero] obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t set m := p.rootMultiplicity t have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt have hndvd : ¬(X - C t) ^ m ∣ derivative p := by rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _), derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc, dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)] rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢ rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd] have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _) exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm]) (rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero) theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ} (hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t := dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans (pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t) open Finset in theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} : (derivative^[p.rootMultiplicity t] p).eval t = (p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by set m := p.rootMultiplicity t with hm conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm] rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)] · rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self, eval_natCast, nsmul_eq_mul]; rfl · intro b hb hb0 rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow, Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self, zero_pow hb0, smul_zero, zero_mul, smul_zero] theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by by_contra! h' replace hroot := hroot _ h' simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h' rw [hq, mul_mem_nonZeroDivisors] at hnzd rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot clear hroot induction' n with n ih · simp only [Nat.zero_eq, Nat.factorial_zero, Nat.cast_one] exact Submonoid.one_mem _ · rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors] exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩ theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t := lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h (by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _) theorem one_lt_rootMultiplicity_iff_isRoot {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h] refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩ obtain (_|_|m) := m exacts [h0, h1, by omega] end CommRing section IsDomain variable [CommRing R] [IsDomain R] theorem one_lt_rootMultiplicity_iff_isRoot_gcd [GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff] theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) : p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · rw [h, map_zero, rootMultiplicity_zero] exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <| mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne' #align polynomial.derivative_root_multiplicity_of_root Polynomial.derivative_rootMultiplicity_of_root theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by by_cases h : p.IsRoot t · exact (derivative_rootMultiplicity_of_root h).symm.le · rw [rootMultiplicity_eq_zero h, zero_tsub] exact zero_le _ #align polynomial.root_multiplicity_sub_one_le_derivative_root_multiplicity Polynomial.rootMultiplicity_sub_one_le_derivative_rootMultiplicity theorem lt_rootMultiplicity_of_isRoot_iterate_derivative [CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) : n < p.rootMultiplicity t := lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <| mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| Nat.factorial_ne_zero n theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative [CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩ section NormalizationMonoid variable [NormalizationMonoid R] instance instNormalizationMonoid : NormalizationMonoid R[X] where normUnit p := ⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by rw [← RingHom.map_mul, Units.mul_inv, C_1], by rw [← RingHom.map_mul, Units.inv_mul, C_1]⟩ normUnit_zero := Units.ext (by simp) normUnit_mul hp0 hq0 := Units.ext (by dsimp rw [Ne, ← leadingCoeff_eq_zero] at * rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul]) normUnit_coe_units u := Units.ext (by dsimp rw [← mul_one u⁻¹, Units.val_mul, Units.eq_inv_mul_iff_mul_eq] rcases Polynomial.isUnit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩ rw [← h2, leadingCoeff_C, normUnit_coe_units, ← C_mul, Units.mul_inv, C_1] rfl) @[simp] theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by simp [normUnit] #align polynomial.coe_norm_unit Polynomial.coe_normUnit theorem leadingCoeff_normalize (p : R[X]) : leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp #align polynomial.leading_coeff_normalize Polynomial.leadingCoeff_normalize theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one, Units.val_one, Polynomial.C.map_one, mul_one] #align polynomial.monic.normalize_eq_self Polynomial.Monic.normalize_eq_self theorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero] #align polynomial.roots_normalize Polynomial.roots_normalize theorem normUnit_X : normUnit (X : Polynomial R) = 1 := by have := coe_normUnit (R := R) (p := X) rwa [leadingCoeff_X, normUnit_one, Units.val_one, map_one, Units.val_eq_one] at this theorem X_eq_normalize : (X : Polynomial R) = normalize X := by simp only [normalize_apply, normUnit_X, Units.val_one, mul_one] end NormalizationMonoid end IsDomain section DivisionRing variable [DivisionRing R] {p q : R[X]} theorem degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬IsUnit p) : 0 < degree p := lt_of_not_ge fun h => by rw [eq_C_of_degree_le_zero h] at hp0 hp exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0)))) #align polynomial.degree_pos_of_ne_zero_of_nonunit Polynomial.degree_pos_of_ne_zero_of_nonunit @[simp] theorem map_eq_zero [Semiring S] [Nontrivial S] (f : R →+* S) : p.map f = 0 ↔ p = 0 := by simp only [Polynomial.ext_iff] congr! simp [map_eq_zero, coeff_map, coeff_zero] #align polynomial.map_eq_zero Polynomial.map_eq_zero theorem map_ne_zero [Semiring S] [Nontrivial S] {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 := mt (map_eq_zero f).1 hp #align polynomial.map_ne_zero Polynomial.map_ne_zero @[simp] theorem degree_map [Semiring S] [Nontrivial S] (p : R[X]) (f : R →+* S) : degree (p.map f) = degree p := p.degree_map_eq_of_injective f.injective #align polynomial.degree_map Polynomial.degree_map @[simp] theorem natDegree_map [Semiring S] [Nontrivial S] (f : R →+* S) : natDegree (p.map f) = natDegree p := natDegree_eq_of_degree_eq (degree_map _ f) #align polynomial.nat_degree_map Polynomial.natDegree_map @[simp] theorem leadingCoeff_map [Semiring S] [Nontrivial S] (f : R →+* S) : leadingCoeff (p.map f) = f (leadingCoeff p) := by simp only [← coeff_natDegree, coeff_map f, natDegree_map] #align polynomial.leading_coeff_map Polynomial.leadingCoeff_map theorem monic_map_iff [Semiring S] [Nontrivial S] {f : R →+* S} {p : R[X]} : (p.map f).Monic ↔ p.Monic := by rw [Monic, leadingCoeff_map, ← f.map_one, Function.Injective.eq_iff f.injective, Monic] #align polynomial.monic_map_iff Polynomial.monic_map_iff end DivisionRing section Field variable [Field R] {p q : R[X]} theorem isUnit_iff_degree_eq_zero : IsUnit p ↔ degree p = 0 := ⟨degree_eq_zero_of_isUnit, fun h => have : degree p ≤ 0 := by simp [*, le_refl] have hc : coeff p 0 ≠ 0 := fun hc => by rw [eq_C_of_degree_le_zero this, hc] at h; simp only [map_zero] at h; contradiction isUnit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, by conv in p => rw [eq_C_of_degree_le_zero this] rw [← C_mul, _root_.mul_inv_cancel hc, C_1]⟩⟩ #align polynomial.is_unit_iff_degree_eq_zero Polynomial.isUnit_iff_degree_eq_zero /-- Division of polynomials. See `Polynomial.divByMonic` for more details. -/ def div (p q : R[X]) := C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) #align polynomial.div Polynomial.div /-- Remainder of polynomial division. See `Polynomial.modByMonic` for more details. -/ def mod (p q : R[X]) := p %ₘ (q * C (leadingCoeff q)⁻¹) #align polynomial.mod Polynomial.mod private theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p := by by_cases h : q = 0 · simp only [h, zero_mul, mod, modByMonic_zero, zero_add] · conv => rhs rw [← modByMonic_add_div p (monic_mul_leadingCoeff_inv h)] rw [div, mod, add_comm, mul_assoc] private theorem remainder_lt_aux (p : R[X]) (hq : q ≠ 0) : degree (mod p q) < degree q := by rw [← degree_mul_leadingCoeff_inv q hq] exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq) instance : Div R[X] := ⟨div⟩ instance : Mod R[X] := ⟨mod⟩ theorem div_def : p / q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) := rfl #align polynomial.div_def Polynomial.div_def theorem mod_def : p % q = p %ₘ (q * C (leadingCoeff q)⁻¹) := rfl #align polynomial.mod_def Polynomial.mod_def theorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %ₘ q = p % q := show p %ₘ q = p %ₘ (q * C (leadingCoeff q)⁻¹) by simp only [Monic.def.1 hq, inv_one, mul_one, C_1] #align polynomial.mod_by_monic_eq_mod Polynomial.modByMonic_eq_mod theorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /ₘ q = p / q := show p /ₘ q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) by simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one] #align polynomial.div_by_monic_eq_div Polynomial.divByMonic_eq_div theorem mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) := modByMonic_eq_mod p (monic_X_sub_C a) ▸ modByMonic_X_sub_C_eq_C_eval _ _ set_option linter.uppercaseLean3 false in #align polynomial.mod_X_sub_C_eq_C_eval Polynomial.mod_X_sub_C_eq_C_eval theorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p ↔ IsRoot p a := divByMonic_eq_div p (monic_X_sub_C a) ▸ mul_divByMonic_eq_iff_isRoot #align polynomial.mul_div_eq_iff_is_root Polynomial.mul_div_eq_iff_isRoot instance instEuclideanDomain : EuclideanDomain R[X] := { Polynomial.commRing, Polynomial.nontrivial with quotient := (· / ·) quotient_zero := by simp [div_def] remainder := (· % ·) r := _ r_wellFounded := degree_lt_wf quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux remainder_lt := fun p q hq => remainder_lt_aux _ hq mul_left_not_lt := fun p q hq => not_lt_of_ge (degree_le_mul_left _ hq) } theorem mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q := ⟨fun h => h ▸ EuclideanDomain.mod_lt _ hq0, fun h => by classical have : ¬degree (q * C (leadingCoeff q)⁻¹) ≤ degree p := not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0] rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)] unfold divModByMonicAux dsimp simp only [this, false_and_iff, if_false]⟩ #align polynomial.mod_eq_self_iff Polynomial.mod_eq_self_iff theorem div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q := ⟨fun h => by have := EuclideanDomain.div_add_mod p q; rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this, fun h => by have hlt : degree p < degree (q * C (leadingCoeff q)⁻¹) := by rwa [degree_mul_leadingCoeff_inv q hq0] have hm : Monic (q * C (leadingCoeff q)⁻¹) := monic_mul_leadingCoeff_inv hq0 rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, mul_zero]⟩ #align polynomial.div_eq_zero_iff Polynomial.div_eq_zero_iff theorem degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) : degree q + degree (p / q) = degree p := by have : degree (p % q) < degree (q * (p / q)) := calc degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0 _ ≤ _ := degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)) conv_rhs => rw [← EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul] #align polynomial.degree_add_div Polynomial.degree_add_div theorem degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p := by by_cases hq : q = 0 · simp [hq] · rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _ #align polynomial.degree_div_le Polynomial.degree_div_le theorem degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := by have hq0 : q ≠ 0 := fun hq0 => by simp [hq0] at hq rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0]; exact degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp (by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq) #align polynomial.degree_div_lt Polynomial.degree_div_lt theorem isUnit_map [Field k] (f : R →+* k) : IsUnit (p.map f) ↔ IsUnit p := by simp_rw [isUnit_iff_degree_eq_zero, degree_map] #align polynomial.is_unit_map Polynomial.isUnit_map theorem map_div [Field k] (f : R →+* k) : (p / q).map f = p.map f / q.map f := by if hq0 : q = 0 then simp [hq0] else rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0), Polynomial.map_mul, map_C, leadingCoeff_map, map_inv₀] #align polynomial.map_div Polynomial.map_div theorem map_mod [Field k] (f : R →+* k) : (p % q).map f = p.map f % q.map f := by by_cases hq0 : q = 0 · simp [hq0] · rw [mod_def, mod_def, leadingCoeff_map f, ← map_inv₀ f, ← map_C f, ← Polynomial.map_mul f, map_modByMonic f (monic_mul_leadingCoeff_inv hq0)] #align polynomial.map_mod Polynomial.map_mod section open EuclideanDomain theorem gcd_map [Field k] [DecidableEq R] [DecidableEq k] (f : R →+* k) : gcd (p.map f) (q.map f) = (gcd p q).map f := GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left]) fun x y _ ih => by rw [gcd_val, ← map_mod, ih, ← gcd_val] #align polynomial.gcd_map Polynomial.gcd_map end theorem eval₂_gcd_eq_zero [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hf : f.eval₂ ϕ α = 0) (hg : g.eval₂ ϕ α = 0) : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 := by rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval₂_add, Polynomial.eval₂_mul, Polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add] #align polynomial.eval₂_gcd_eq_zero Polynomial.eval₂_gcd_eq_zero theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R} (hf : f.eval α = 0) (hg : g.eval α = 0) : (EuclideanDomain.gcd f g).eval α = 0 := eval₂_gcd_eq_zero hf hg #align polynomial.eval_gcd_eq_zero Polynomial.eval_gcd_eq_zero theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by cases' EuclideanDomain.gcd_dvd_left f g with p hp rw [hp, Polynomial.eval₂_mul, hα, zero_mul] #align polynomial.root_left_of_root_gcd Polynomial.root_left_of_root_gcd theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by cases' EuclideanDomain.gcd_dvd_right f g with p hp rw [hp, Polynomial.eval₂_mul, hα, zero_mul] #align polynomial.root_right_of_root_gcd Polynomial.root_right_of_root_gcd theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 ↔ f.eval₂ ϕ α = 0 ∧ g.eval₂ ϕ α = 0 := ⟨fun h => ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, fun h => eval₂_gcd_eq_zero h.1 h.2⟩ #align polynomial.root_gcd_iff_root_left_right Polynomial.root_gcd_iff_root_left_right theorem isRoot_gcd_iff_isRoot_left_right [DecidableEq R] {f g : R[X]} {α : R} : (EuclideanDomain.gcd f g).IsRoot α ↔ f.IsRoot α ∧ g.IsRoot α := root_gcd_iff_root_left_right #align polynomial.is_root_gcd_iff_is_root_left_right Polynomial.isRoot_gcd_iff_isRoot_left_right theorem isCoprime_map [Field k] (f : R →+* k) : IsCoprime (p.map f) (q.map f) ↔ IsCoprime p q := by classical rw [← EuclideanDomain.gcd_isUnit_iff, ← EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map] #align polynomial.is_coprime_map Polynomial.isCoprime_map theorem mem_roots_map [CommRing k] [IsDomain k] {f : R →+* k} {x : k} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map] #align polynomial.mem_roots_map Polynomial.mem_roots_map theorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : (monomial n a).rootSet S = {0} := by classical rw [rootSet, aroots_monomial ha, Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton] #align polynomial.root_set_monomial Polynomial.rootSet_monomial theorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : rootSet (C a * X ^ n) S = {0} := by rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha] set_option linter.uppercaseLean3 false in #align polynomial.root_set_C_mul_X_pow Polynomial.rootSet_C_mul_X_pow theorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) : (X ^ n : R[X]).rootSet S = {0} := by rw [← one_mul (X ^ n : R[X]), ← C_1, rootSet_C_mul_X_pow hn] exact one_ne_zero set_option linter.uppercaseLean3 false in #align polynomial.root_set_X_pow Polynomial.rootSet_X_pow theorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {ι : Type*} (f : ι → R[X]) (s : Finset ι) (h : s.prod f ≠ 0) : (s.prod f).rootSet S = ⋃ i ∈ s, (f i).rootSet S := by classical simp only [rootSet, aroots, ← Finset.mem_coe] rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_biUnion] rwa [← Polynomial.map_prod, Ne, map_eq_zero] #align polynomial.root_set_prod Polynomial.rootSet_prod theorem exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, IsRoot p x := ⟨-(p.coeff 0 / p.coeff 1), by have : p.coeff 1 ≠ 0 := by have h' := natDegree_eq_of_degree_eq_some h change natDegree p = 1 at h'; rw [← h'] exact mt leadingCoeff_eq_zero.1 fun h0 => by simp [h0] at h conv in p => rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1 by rw [h])] simp [IsRoot, mul_div_cancel₀ _ this]⟩ #align polynomial.exists_root_of_degree_eq_one Polynomial.exists_root_of_degree_eq_one theorem coeff_inv_units (u : R[X]ˣ) (n : ℕ) : ((↑u : R[X]).coeff n)⁻¹ = (↑u⁻¹ : R[X]).coeff n := by rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹), coeff_C, coeff_C, inv_eq_one_div] split_ifs · rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero, coeff_zero_eq_eval_zero, ← eval_mul, ← Units.val_mul, inv_mul_self] simp · simp #align polynomial.coeff_inv_units Polynomial.coeff_inv_units theorem monic_normalize [DecidableEq R] (hp0 : p ≠ 0) : Monic (normalize p) := by rw [Ne, ← leadingCoeff_eq_zero, ← Ne, ← isUnit_iff_ne_zero] at hp0 rw [Monic, leadingCoeff_normalize, normalize_eq_one] apply hp0 #align polynomial.monic_normalize Polynomial.monic_normalize
Mathlib/Algebra/Polynomial/FieldDivision.lean
528
535
theorem leadingCoeff_div (hpq : q.degree ≤ p.degree) : (p / q).leadingCoeff = p.leadingCoeff / q.leadingCoeff := by
by_cases hq : q = 0 · simp [hq] rw [div_def, leadingCoeff_mul, leadingCoeff_C, leadingCoeff_divByMonic_of_monic (monic_mul_leadingCoeff_inv hq) _, mul_comm, div_eq_mul_inv] rwa [degree_mul_leadingCoeff_inv q hq]
/- Copyright (c) 2020 Zhangir Azerbayev. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Zhangir Azerbayev -/ import Mathlib.GroupTheory.Perm.Sign import Mathlib.Data.Fintype.Perm import Mathlib.LinearAlgebra.Multilinear.Basis #align_import linear_algebra.alternating from "leanprover-community/mathlib"@"0c1d80f5a86b36c1db32e021e8d19ae7809d5b79" /-! # Alternating Maps We construct the bundled function `AlternatingMap`, which extends `MultilinearMap` with all the arguments of the same type. ## Main definitions * `AlternatingMap R M N ι` is the space of `R`-linear alternating maps from `ι → M` to `N`. * `f.map_eq_zero_of_eq` expresses that `f` is zero when two inputs are equal. * `f.map_swap` expresses that `f` is negated when two inputs are swapped. * `f.map_perm` expresses how `f` varies by a sign change under a permutation of its inputs. * An `AddCommMonoid`, `AddCommGroup`, and `Module` structure over `AlternatingMap`s that matches the definitions over `MultilinearMap`s. * `MultilinearMap.domDomCongr`, for permuting the elements within a family. * `MultilinearMap.alternatization`, which makes an alternating map out of a non-alternating one. * `AlternatingMap.curryLeft`, for binding the leftmost argument of an alternating map indexed by `Fin n.succ`. ## Implementation notes `AlternatingMap` is defined in terms of `map_eq_zero_of_eq`, as this is easier to work with than using `map_swap` as a definition, and does not require `Neg N`. `AlternatingMap`s are provided with a coercion to `MultilinearMap`, along with a set of `norm_cast` lemmas that act on the algebraic structure: * `AlternatingMap.coe_add` * `AlternatingMap.coe_zero` * `AlternatingMap.coe_sub` * `AlternatingMap.coe_neg` * `AlternatingMap.coe_smul` -/ -- semiring / add_comm_monoid variable {R : Type*} [Semiring R] variable {M : Type*} [AddCommMonoid M] [Module R M] variable {N : Type*} [AddCommMonoid N] [Module R N] variable {P : Type*} [AddCommMonoid P] [Module R P] -- semiring / add_comm_group variable {M' : Type*} [AddCommGroup M'] [Module R M'] variable {N' : Type*} [AddCommGroup N'] [Module R N'] variable {ι ι' ι'' : Type*} section variable (R M N ι) /-- An alternating map from `ι → M` to `N`, denoted `M [⋀^ι]→ₗ[R] N`, is a multilinear map that vanishes when two of its arguments are equal. -/ structure AlternatingMap extends MultilinearMap R (fun _ : ι => M) N where /-- The map is alternating: if `v` has two equal coordinates, then `f v = 0`. -/ map_eq_zero_of_eq' : ∀ (v : ι → M) (i j : ι), v i = v j → i ≠ j → toFun v = 0 #align alternating_map AlternatingMap @[inherit_doc] notation M " [⋀^" ι "]→ₗ[" R "] " N:100 => AlternatingMap R M N ι end /-- The multilinear map associated to an alternating map -/ add_decl_doc AlternatingMap.toMultilinearMap namespace AlternatingMap variable (f f' : M [⋀^ι]→ₗ[R] N) variable (g g₂ : M [⋀^ι]→ₗ[R] N') variable (g' : M' [⋀^ι]→ₗ[R] N') variable (v : ι → M) (v' : ι → M') open Function /-! Basic coercion simp lemmas, largely copied from `RingHom` and `MultilinearMap` -/ section Coercions instance instFunLike : FunLike (M [⋀^ι]→ₗ[R] N) (ι → M) N where coe f := f.toFun coe_injective' := fun f g h ↦ by rcases f with ⟨⟨_, _, _⟩, _⟩ rcases g with ⟨⟨_, _, _⟩, _⟩ congr #align alternating_map.fun_like AlternatingMap.instFunLike -- shortcut instance instance coeFun : CoeFun (M [⋀^ι]→ₗ[R] N) fun _ => (ι → M) → N := ⟨DFunLike.coe⟩ #align alternating_map.has_coe_to_fun AlternatingMap.coeFun initialize_simps_projections AlternatingMap (toFun → apply) @[simp] theorem toFun_eq_coe : f.toFun = f := rfl #align alternating_map.to_fun_eq_coe AlternatingMap.toFun_eq_coe -- Porting note: changed statement to reflect new `mk` signature @[simp] theorem coe_mk (f : MultilinearMap R (fun _ : ι => M) N) (h) : ⇑(⟨f, h⟩ : M [⋀^ι]→ₗ[R] N) = f := rfl #align alternating_map.coe_mk AlternatingMap.coe_mkₓ theorem congr_fun {f g : M [⋀^ι]→ₗ[R] N} (h : f = g) (x : ι → M) : f x = g x := congr_arg (fun h : M [⋀^ι]→ₗ[R] N => h x) h #align alternating_map.congr_fun AlternatingMap.congr_fun theorem congr_arg (f : M [⋀^ι]→ₗ[R] N) {x y : ι → M} (h : x = y) : f x = f y := _root_.congr_arg (fun x : ι → M => f x) h #align alternating_map.congr_arg AlternatingMap.congr_arg theorem coe_injective : Injective ((↑) : M [⋀^ι]→ₗ[R] N → (ι → M) → N) := DFunLike.coe_injective #align alternating_map.coe_injective AlternatingMap.coe_injective @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem coe_inj {f g : M [⋀^ι]→ₗ[R] N} : (f : (ι → M) → N) = g ↔ f = g := coe_injective.eq_iff #align alternating_map.coe_inj AlternatingMap.coe_inj @[ext] theorem ext {f f' : M [⋀^ι]→ₗ[R] N} (H : ∀ x, f x = f' x) : f = f' := DFunLike.ext _ _ H #align alternating_map.ext AlternatingMap.ext theorem ext_iff {f g : M [⋀^ι]→ₗ[R] N} : f = g ↔ ∀ x, f x = g x := ⟨fun h _ => h ▸ rfl, fun h => ext h⟩ #align alternating_map.ext_iff AlternatingMap.ext_iff attribute [coe] AlternatingMap.toMultilinearMap instance coe : Coe (M [⋀^ι]→ₗ[R] N) (MultilinearMap R (fun _ : ι => M) N) := ⟨fun x => x.toMultilinearMap⟩ #align alternating_map.multilinear_map.has_coe AlternatingMap.coe @[simp, norm_cast] theorem coe_multilinearMap : ⇑(f : MultilinearMap R (fun _ : ι => M) N) = f := rfl #align alternating_map.coe_multilinear_map AlternatingMap.coe_multilinearMap theorem coe_multilinearMap_injective : Function.Injective ((↑) : M [⋀^ι]→ₗ[R] N → MultilinearMap R (fun _ : ι => M) N) := fun _ _ h => ext <| MultilinearMap.congr_fun h #align alternating_map.coe_multilinear_map_injective AlternatingMap.coe_multilinearMap_injective #noalign alternating_map.to_multilinear_map_eq_coe -- Porting note: changed statement to reflect new `mk` signature. -- Porting note: removed `simp` -- @[simp] theorem coe_multilinearMap_mk (f : (ι → M) → N) (h₁ h₂ h₃) : ((⟨⟨f, h₁, h₂⟩, h₃⟩ : M [⋀^ι]→ₗ[R] N) : MultilinearMap R (fun _ : ι => M) N) = ⟨f, @h₁, @h₂⟩ := by simp #align alternating_map.coe_multilinear_map_mk AlternatingMap.coe_multilinearMap_mk end Coercions /-! ### Simp-normal forms of the structure fields These are expressed in terms of `⇑f` instead of `f.toFun`. -/ @[simp] theorem map_add [DecidableEq ι] (i : ι) (x y : M) : f (update v i (x + y)) = f (update v i x) + f (update v i y) := f.toMultilinearMap.map_add' v i x y #align alternating_map.map_add AlternatingMap.map_add @[simp] theorem map_sub [DecidableEq ι] (i : ι) (x y : M') : g' (update v' i (x - y)) = g' (update v' i x) - g' (update v' i y) := g'.toMultilinearMap.map_sub v' i x y #align alternating_map.map_sub AlternatingMap.map_sub @[simp] theorem map_neg [DecidableEq ι] (i : ι) (x : M') : g' (update v' i (-x)) = -g' (update v' i x) := g'.toMultilinearMap.map_neg v' i x #align alternating_map.map_neg AlternatingMap.map_neg @[simp] theorem map_smul [DecidableEq ι] (i : ι) (r : R) (x : M) : f (update v i (r • x)) = r • f (update v i x) := f.toMultilinearMap.map_smul' v i r x #align alternating_map.map_smul AlternatingMap.map_smul @[simp] theorem map_eq_zero_of_eq (v : ι → M) {i j : ι} (h : v i = v j) (hij : i ≠ j) : f v = 0 := f.map_eq_zero_of_eq' v i j h hij #align alternating_map.map_eq_zero_of_eq AlternatingMap.map_eq_zero_of_eq theorem map_coord_zero {m : ι → M} (i : ι) (h : m i = 0) : f m = 0 := f.toMultilinearMap.map_coord_zero i h #align alternating_map.map_coord_zero AlternatingMap.map_coord_zero @[simp] theorem map_update_zero [DecidableEq ι] (m : ι → M) (i : ι) : f (update m i 0) = 0 := f.toMultilinearMap.map_update_zero m i #align alternating_map.map_update_zero AlternatingMap.map_update_zero @[simp] theorem map_zero [Nonempty ι] : f 0 = 0 := f.toMultilinearMap.map_zero #align alternating_map.map_zero AlternatingMap.map_zero theorem map_eq_zero_of_not_injective (v : ι → M) (hv : ¬Function.Injective v) : f v = 0 := by rw [Function.Injective] at hv push_neg at hv rcases hv with ⟨i₁, i₂, heq, hne⟩ exact f.map_eq_zero_of_eq v heq hne #align alternating_map.map_eq_zero_of_not_injective AlternatingMap.map_eq_zero_of_not_injective /-! ### Algebraic structure inherited from `MultilinearMap` `AlternatingMap` carries the same `AddCommMonoid`, `AddCommGroup`, and `Module` structure as `MultilinearMap` -/ section SMul variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N] instance smul : SMul S (M [⋀^ι]→ₗ[R] N) := ⟨fun c f => { c • (f : MultilinearMap R (fun _ : ι => M) N) with map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij] }⟩ #align alternating_map.has_smul AlternatingMap.smul @[simp] theorem smul_apply (c : S) (m : ι → M) : (c • f) m = c • f m := rfl #align alternating_map.smul_apply AlternatingMap.smul_apply @[norm_cast] theorem coe_smul (c : S) : ↑(c • f) = c • (f : MultilinearMap R (fun _ : ι => M) N) := rfl #align alternating_map.coe_smul AlternatingMap.coe_smul theorem coeFn_smul (c : S) (f : M [⋀^ι]→ₗ[R] N) : ⇑(c • f) = c • ⇑f := rfl #align alternating_map.coe_fn_smul AlternatingMap.coeFn_smul instance isCentralScalar [DistribMulAction Sᵐᵒᵖ N] [IsCentralScalar S N] : IsCentralScalar S (M [⋀^ι]→ₗ[R] N) := ⟨fun _ _ => ext fun _ => op_smul_eq_smul _ _⟩ #align alternating_map.is_central_scalar AlternatingMap.isCentralScalar end SMul /-- The cartesian product of two alternating maps, as an alternating map. -/ @[simps!] def prod (f : M [⋀^ι]→ₗ[R] N) (g : M [⋀^ι]→ₗ[R] P) : M [⋀^ι]→ₗ[R] (N × P) := { f.toMultilinearMap.prod g.toMultilinearMap with map_eq_zero_of_eq' := fun _ _ _ h hne => Prod.ext (f.map_eq_zero_of_eq _ h hne) (g.map_eq_zero_of_eq _ h hne) } #align alternating_map.prod AlternatingMap.prod #align alternating_map.prod_apply AlternatingMap.prod_apply @[simp] theorem coe_prod (f : M [⋀^ι]→ₗ[R] N) (g : M [⋀^ι]→ₗ[R] P) : (f.prod g : MultilinearMap R (fun _ : ι => M) (N × P)) = MultilinearMap.prod f g := rfl #align alternating_map.coe_prod AlternatingMap.coe_prod /-- Combine a family of alternating maps with the same domain and codomains `N i` into an alternating map taking values in the space of functions `Π i, N i`. -/ @[simps!] def pi {ι' : Type*} {N : ι' → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] (f : ∀ i, M [⋀^ι]→ₗ[R] N i) : M [⋀^ι]→ₗ[R] (∀ i, N i) := { MultilinearMap.pi fun a => (f a).toMultilinearMap with map_eq_zero_of_eq' := fun _ _ _ h hne => funext fun a => (f a).map_eq_zero_of_eq _ h hne } #align alternating_map.pi AlternatingMap.pi #align alternating_map.pi_apply AlternatingMap.pi_apply @[simp] theorem coe_pi {ι' : Type*} {N : ι' → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] (f : ∀ i, M [⋀^ι]→ₗ[R] N i) : (pi f : MultilinearMap R (fun _ : ι => M) (∀ i, N i)) = MultilinearMap.pi fun a => f a := rfl #align alternating_map.coe_pi AlternatingMap.coe_pi /-- Given an alternating `R`-multilinear map `f` taking values in `R`, `f.smul_right z` is the map sending `m` to `f m • z`. -/ @[simps!] def smulRight {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) : M₁ [⋀^ι]→ₗ[R] M₂ := { f.toMultilinearMap.smulRight z with map_eq_zero_of_eq' := fun v i j h hne => by simp [f.map_eq_zero_of_eq v h hne] } #align alternating_map.smul_right AlternatingMap.smulRight #align alternating_map.smul_right_apply AlternatingMap.smulRight_apply @[simp] theorem coe_smulRight {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) : (f.smulRight z : MultilinearMap R (fun _ : ι => M₁) M₂) = MultilinearMap.smulRight f z := rfl #align alternating_map.coe_smul_right AlternatingMap.coe_smulRight instance add : Add (M [⋀^ι]→ₗ[R] N) := ⟨fun a b => { (a + b : MultilinearMap R (fun _ : ι => M) N) with map_eq_zero_of_eq' := fun v i j h hij => by simp [a.map_eq_zero_of_eq v h hij, b.map_eq_zero_of_eq v h hij] }⟩ #align alternating_map.has_add AlternatingMap.add @[simp] theorem add_apply : (f + f') v = f v + f' v := rfl #align alternating_map.add_apply AlternatingMap.add_apply @[norm_cast] theorem coe_add : (↑(f + f') : MultilinearMap R (fun _ : ι => M) N) = f + f' := rfl #align alternating_map.coe_add AlternatingMap.coe_add instance zero : Zero (M [⋀^ι]→ₗ[R] N) := ⟨{ (0 : MultilinearMap R (fun _ : ι => M) N) with map_eq_zero_of_eq' := fun v i j _ _ => by simp }⟩ #align alternating_map.has_zero AlternatingMap.zero @[simp] theorem zero_apply : (0 : M [⋀^ι]→ₗ[R] N) v = 0 := rfl #align alternating_map.zero_apply AlternatingMap.zero_apply @[norm_cast] theorem coe_zero : ((0 : M [⋀^ι]→ₗ[R] N) : MultilinearMap R (fun _ : ι => M) N) = 0 := rfl #align alternating_map.coe_zero AlternatingMap.coe_zero @[simp] theorem mk_zero : mk (0 : MultilinearMap R (fun _ : ι ↦ M) N) (0 : M [⋀^ι]→ₗ[R] N).2 = 0 := rfl instance inhabited : Inhabited (M [⋀^ι]→ₗ[R] N) := ⟨0⟩ #align alternating_map.inhabited AlternatingMap.inhabited instance addCommMonoid : AddCommMonoid (M [⋀^ι]→ₗ[R] N) := coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => coeFn_smul _ _ #align alternating_map.add_comm_monoid AlternatingMap.addCommMonoid instance neg : Neg (M [⋀^ι]→ₗ[R] N') := ⟨fun f => { -(f : MultilinearMap R (fun _ : ι => M) N') with map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij] }⟩ #align alternating_map.has_neg AlternatingMap.neg @[simp] theorem neg_apply (m : ι → M) : (-g) m = -g m := rfl #align alternating_map.neg_apply AlternatingMap.neg_apply @[norm_cast] theorem coe_neg : ((-g : M [⋀^ι]→ₗ[R] N') : MultilinearMap R (fun _ : ι => M) N') = -g := rfl #align alternating_map.coe_neg AlternatingMap.coe_neg instance sub : Sub (M [⋀^ι]→ₗ[R] N') := ⟨fun f g => { (f - g : MultilinearMap R (fun _ : ι => M) N') with map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij, g.map_eq_zero_of_eq v h hij] }⟩ #align alternating_map.has_sub AlternatingMap.sub @[simp] theorem sub_apply (m : ι → M) : (g - g₂) m = g m - g₂ m := rfl #align alternating_map.sub_apply AlternatingMap.sub_apply @[norm_cast] theorem coe_sub : (↑(g - g₂) : MultilinearMap R (fun _ : ι => M) N') = g - g₂ := rfl #align alternating_map.coe_sub AlternatingMap.coe_sub instance addCommGroup : AddCommGroup (M [⋀^ι]→ₗ[R] N') := coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => coeFn_smul _ _) fun _ _ => coeFn_smul _ _ #align alternating_map.add_comm_group AlternatingMap.addCommGroup section DistribMulAction variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N] instance distribMulAction : DistribMulAction S (M [⋀^ι]→ₗ[R] N) where one_smul _ := ext fun _ => one_smul _ _ mul_smul _ _ _ := ext fun _ => mul_smul _ _ _ smul_zero _ := ext fun _ => smul_zero _ smul_add _ _ _ := ext fun _ => smul_add _ _ _ #align alternating_map.distrib_mul_action AlternatingMap.distribMulAction end DistribMulAction section Module variable {S : Type*} [Semiring S] [Module S N] [SMulCommClass R S N] /-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise addition and scalar multiplication. -/ instance module : Module S (M [⋀^ι]→ₗ[R] N) where add_smul _ _ _ := ext fun _ => add_smul _ _ _ zero_smul _ := ext fun _ => zero_smul _ _ #align alternating_map.module AlternatingMap.module instance noZeroSMulDivisors [NoZeroSMulDivisors S N] : NoZeroSMulDivisors S (M [⋀^ι]→ₗ[R] N) := coe_injective.noZeroSMulDivisors _ rfl coeFn_smul #align alternating_map.no_zero_smul_divisors AlternatingMap.noZeroSMulDivisors end Module section variable (R M N) /-- The natural equivalence between linear maps from `M` to `N` and `1`-multilinear alternating maps from `M` to `N`. -/ @[simps!] def ofSubsingleton [Subsingleton ι] (i : ι) : (M →ₗ[R] N) ≃ (M [⋀^ι]→ₗ[R] N) where toFun f := ⟨MultilinearMap.ofSubsingleton R M N i f, fun _ _ _ _ ↦ absurd (Subsingleton.elim _ _)⟩ invFun f := (MultilinearMap.ofSubsingleton R M N i).symm f left_inv _ := rfl right_inv _ := coe_multilinearMap_injective <| (MultilinearMap.ofSubsingleton R M N i).apply_symm_apply _ #align alternating_map.of_subsingleton AlternatingMap.ofSubsingleton #align alternating_map.of_subsingleton_apply AlternatingMap.ofSubsingleton_apply_apply variable (ι) {N} /-- The constant map is alternating when `ι` is empty. -/ @[simps (config := .asFn)] def constOfIsEmpty [IsEmpty ι] (m : N) : M [⋀^ι]→ₗ[R] N := { MultilinearMap.constOfIsEmpty R _ m with toFun := Function.const _ m map_eq_zero_of_eq' := fun _ => isEmptyElim } #align alternating_map.const_of_is_empty AlternatingMap.constOfIsEmpty #align alternating_map.const_of_is_empty_apply AlternatingMap.constOfIsEmpty_apply end /-- Restrict the codomain of an alternating map to a submodule. -/ @[simps] def codRestrict (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N) (h : ∀ v, f v ∈ p) : M [⋀^ι]→ₗ[R] p := { f.toMultilinearMap.codRestrict p h with toFun := fun v => ⟨f v, h v⟩ map_eq_zero_of_eq' := fun _ _ _ hv hij => Subtype.ext <| map_eq_zero_of_eq _ _ hv hij } #align alternating_map.cod_restrict AlternatingMap.codRestrict #align alternating_map.cod_restrict_apply_coe AlternatingMap.codRestrict_apply_coe end AlternatingMap /-! ### Composition with linear maps -/ namespace LinearMap variable {N₂ : Type*} [AddCommMonoid N₂] [Module R N₂] /-- Composing an alternating map with a linear map on the left gives again an alternating map. -/ def compAlternatingMap (g : N →ₗ[R] N₂) : (M [⋀^ι]→ₗ[R] N) →+ (M [⋀^ι]→ₗ[R] N₂) where toFun f := { g.compMultilinearMap (f : MultilinearMap R (fun _ : ι => M) N) with map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij] } map_zero' := by ext simp map_add' a b := by ext simp #align linear_map.comp_alternating_map LinearMap.compAlternatingMap @[simp] theorem coe_compAlternatingMap (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) : ⇑(g.compAlternatingMap f) = g ∘ f := rfl #align linear_map.coe_comp_alternating_map LinearMap.coe_compAlternatingMap @[simp] theorem compAlternatingMap_apply (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) (m : ι → M) : g.compAlternatingMap f m = g (f m) := rfl #align linear_map.comp_alternating_map_apply LinearMap.compAlternatingMap_apply theorem smulRight_eq_comp {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) : f.smulRight z = (LinearMap.id.smulRight z).compAlternatingMap f := rfl #align linear_map.smul_right_eq_comp LinearMap.smulRight_eq_comp @[simp] theorem subtype_compAlternatingMap_codRestrict (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N) (h) : p.subtype.compAlternatingMap (f.codRestrict p h) = f := AlternatingMap.ext fun _ => rfl #align linear_map.subtype_comp_alternating_map_cod_restrict LinearMap.subtype_compAlternatingMap_codRestrict @[simp] theorem compAlternatingMap_codRestrict (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N₂) (h) : (g.codRestrict p h).compAlternatingMap f = (g.compAlternatingMap f).codRestrict p fun v => h (f v) := AlternatingMap.ext fun _ => rfl #align linear_map.comp_alternating_map_cod_restrict LinearMap.compAlternatingMap_codRestrict end LinearMap namespace AlternatingMap variable {M₂ : Type*} [AddCommMonoid M₂] [Module R M₂] variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] /-- Composing an alternating map with the same linear map on each argument gives again an alternating map. -/ def compLinearMap (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) : M₂ [⋀^ι]→ₗ[R] N := { (f : MultilinearMap R (fun _ : ι => M) N).compLinearMap fun _ => g with map_eq_zero_of_eq' := fun _ _ _ h hij => f.map_eq_zero_of_eq _ (LinearMap.congr_arg h) hij } #align alternating_map.comp_linear_map AlternatingMap.compLinearMap theorem coe_compLinearMap (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) : ⇑(f.compLinearMap g) = f ∘ (g ∘ ·) := rfl #align alternating_map.coe_comp_linear_map AlternatingMap.coe_compLinearMap @[simp] theorem compLinearMap_apply (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) (v : ι → M₂) : f.compLinearMap g v = f fun i => g (v i) := rfl #align alternating_map.comp_linear_map_apply AlternatingMap.compLinearMap_apply /-- Composing an alternating map twice with the same linear map in each argument is the same as composing with their composition. -/ theorem compLinearMap_assoc (f : M [⋀^ι]→ₗ[R] N) (g₁ : M₂ →ₗ[R] M) (g₂ : M₃ →ₗ[R] M₂) : (f.compLinearMap g₁).compLinearMap g₂ = f.compLinearMap (g₁ ∘ₗ g₂) := rfl #align alternating_map.comp_linear_map_assoc AlternatingMap.compLinearMap_assoc @[simp] theorem zero_compLinearMap (g : M₂ →ₗ[R] M) : (0 : M [⋀^ι]→ₗ[R] N).compLinearMap g = 0 := by ext simp only [compLinearMap_apply, zero_apply] #align alternating_map.zero_comp_linear_map AlternatingMap.zero_compLinearMap @[simp] theorem add_compLinearMap (f₁ f₂ : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) : (f₁ + f₂).compLinearMap g = f₁.compLinearMap g + f₂.compLinearMap g := by ext simp only [compLinearMap_apply, add_apply] #align alternating_map.add_comp_linear_map AlternatingMap.add_compLinearMap @[simp] theorem compLinearMap_zero [Nonempty ι] (f : M [⋀^ι]→ₗ[R] N) : f.compLinearMap (0 : M₂ →ₗ[R] M) = 0 := by ext -- Porting note: Was `simp_rw [.., ← Pi.zero_def, map_zero, zero_apply]`. simp_rw [compLinearMap_apply, LinearMap.zero_apply, ← Pi.zero_def, zero_apply] exact map_zero f #align alternating_map.comp_linear_map_zero AlternatingMap.compLinearMap_zero /-- Composing an alternating map with the identity linear map in each argument. -/ @[simp] theorem compLinearMap_id (f : M [⋀^ι]→ₗ[R] N) : f.compLinearMap LinearMap.id = f := ext fun _ => rfl #align alternating_map.comp_linear_map_id AlternatingMap.compLinearMap_id /-- Composing with a surjective linear map is injective. -/ theorem compLinearMap_injective (f : M₂ →ₗ[R] M) (hf : Function.Surjective f) : Function.Injective fun g : M [⋀^ι]→ₗ[R] N => g.compLinearMap f := fun g₁ g₂ h => ext fun x => by simpa [Function.surjInv_eq hf] using ext_iff.mp h (Function.surjInv hf ∘ x) #align alternating_map.comp_linear_map_injective AlternatingMap.compLinearMap_injective theorem compLinearMap_inj (f : M₂ →ₗ[R] M) (hf : Function.Surjective f) (g₁ g₂ : M [⋀^ι]→ₗ[R] N) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ := (compLinearMap_injective _ hf).eq_iff #align alternating_map.comp_linear_map_inj AlternatingMap.compLinearMap_inj section DomLcongr variable (ι R N) variable (S : Type*) [Semiring S] [Module S N] [SMulCommClass R S N] /-- Construct a linear equivalence between maps from a linear equivalence between domains. -/ @[simps apply] def domLCongr (e : M ≃ₗ[R] M₂) : M [⋀^ι]→ₗ[R] N ≃ₗ[S] (M₂ [⋀^ι]→ₗ[R] N) where toFun f := f.compLinearMap e.symm invFun g := g.compLinearMap e map_add' _ _ := rfl map_smul' _ _ := rfl left_inv f := AlternatingMap.ext fun _ => f.congr_arg <| funext fun _ => e.symm_apply_apply _ right_inv f := AlternatingMap.ext fun _ => f.congr_arg <| funext fun _ => e.apply_symm_apply _ #align alternating_map.dom_lcongr AlternatingMap.domLCongr #align alternating_map.dom_lcongr_apply AlternatingMap.domLCongr_apply @[simp] theorem domLCongr_refl : domLCongr R N ι S (LinearEquiv.refl R M) = LinearEquiv.refl S _ := LinearEquiv.ext fun _ => AlternatingMap.ext fun _ => rfl #align alternating_map.dom_lcongr_refl AlternatingMap.domLCongr_refl @[simp] theorem domLCongr_symm (e : M ≃ₗ[R] M₂) : (domLCongr R N ι S e).symm = domLCongr R N ι S e.symm := rfl #align alternating_map.dom_lcongr_symm AlternatingMap.domLCongr_symm theorem domLCongr_trans (e : M ≃ₗ[R] M₂) (f : M₂ ≃ₗ[R] M₃) : (domLCongr R N ι S e).trans (domLCongr R N ι S f) = domLCongr R N ι S (e.trans f) := rfl #align alternating_map.dom_lcongr_trans AlternatingMap.domLCongr_trans end DomLcongr /-- Composing an alternating map with the same linear equiv on each argument gives the zero map if and only if the alternating map is the zero map. -/ @[simp] theorem compLinearEquiv_eq_zero_iff (f : M [⋀^ι]→ₗ[R] N) (g : M₂ ≃ₗ[R] M) : f.compLinearMap (g : M₂ →ₗ[R] M) = 0 ↔ f = 0 := (domLCongr R N ι ℕ g.symm).map_eq_zero_iff #align alternating_map.comp_linear_equiv_eq_zero_iff AlternatingMap.compLinearEquiv_eq_zero_iff variable (f f' : M [⋀^ι]→ₗ[R] N) variable (g g₂ : M [⋀^ι]→ₗ[R] N') variable (g' : M' [⋀^ι]→ₗ[R] N') variable (v : ι → M) (v' : ι → M') open Function /-! ### Other lemmas from `MultilinearMap` -/ section theorem map_update_sum {α : Type*} [DecidableEq ι] (t : Finset α) (i : ι) (g : α → M) (m : ι → M) : f (update m i (∑ a ∈ t, g a)) = ∑ a ∈ t, f (update m i (g a)) := f.toMultilinearMap.map_update_sum t i g m #align alternating_map.map_update_sum AlternatingMap.map_update_sum end /-! ### Theorems specific to alternating maps Various properties of reordered and repeated inputs which follow from `AlternatingMap.map_eq_zero_of_eq`. -/ theorem map_update_self [DecidableEq ι] {i j : ι} (hij : i ≠ j) : f (Function.update v i (v j)) = 0 := f.map_eq_zero_of_eq _ (by rw [Function.update_same, Function.update_noteq hij.symm]) hij #align alternating_map.map_update_self AlternatingMap.map_update_self theorem map_update_update [DecidableEq ι] {i j : ι} (hij : i ≠ j) (m : M) : f (Function.update (Function.update v i m) j m) = 0 := f.map_eq_zero_of_eq _ (by rw [Function.update_same, Function.update_noteq hij, Function.update_same]) hij #align alternating_map.map_update_update AlternatingMap.map_update_update
Mathlib/LinearAlgebra/Alternating/Basic.lean
678
683
theorem map_swap_add [DecidableEq ι] {i j : ι} (hij : i ≠ j) : f (v ∘ Equiv.swap i j) + f v = 0 := by
rw [Equiv.comp_swap_eq_update] convert f.map_update_update v hij (v i + v j) simp [f.map_update_self _ hij, f.map_update_self _ hij.symm, Function.update_comm hij (v i + v j) (v _) v, Function.update_comm hij.symm (v i) (v i) v]
/- 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, Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Associated import Mathlib.Algebra.GCDMonoid.Basic import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.Factors import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.Multiplicity #align_import ring_theory.unique_factorization_domain from "leanprover-community/mathlib"@"570e9f4877079b3a923135b3027ac3be8695ab8c" /-! # Unique factorization ## Main Definitions * `WfDvdMonoid` holds for `Monoid`s for which a strict divisibility relation is well-founded. * `UniqueFactorizationMonoid` holds for `WfDvdMonoid`s where `Irreducible` is equivalent to `Prime` ## To do * set up the complete lattice structure on `FactorSet`. -/ variable {α : Type*} local infixl:50 " ~ᵤ " => Associated /-- Well-foundedness of the strict version of |, which is equivalent to the descending chain condition on divisibility and to the ascending chain condition on principal ideals in an integral domain. -/ class WfDvdMonoid (α : Type*) [CommMonoidWithZero α] : Prop where wellFounded_dvdNotUnit : WellFounded (@DvdNotUnit α _) #align wf_dvd_monoid WfDvdMonoid export WfDvdMonoid (wellFounded_dvdNotUnit) -- see Note [lower instance priority] instance (priority := 100) IsNoetherianRing.wfDvdMonoid [CommRing α] [IsDomain α] [IsNoetherianRing α] : WfDvdMonoid α := ⟨by convert InvImage.wf (fun a => Ideal.span ({a} : Set α)) (wellFounded_submodule_gt _ _) ext exact Ideal.span_singleton_lt_span_singleton.symm⟩ #align is_noetherian_ring.wf_dvd_monoid IsNoetherianRing.wfDvdMonoid namespace WfDvdMonoid variable [CommMonoidWithZero α] open Associates Nat theorem of_wfDvdMonoid_associates (_ : WfDvdMonoid (Associates α)) : WfDvdMonoid α := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).2 wellFounded_dvdNotUnit⟩ #align wf_dvd_monoid.of_wf_dvd_monoid_associates WfDvdMonoid.of_wfDvdMonoid_associates variable [WfDvdMonoid α] instance wfDvdMonoid_associates : WfDvdMonoid (Associates α) := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).1 wellFounded_dvdNotUnit⟩ #align wf_dvd_monoid.wf_dvd_monoid_associates WfDvdMonoid.wfDvdMonoid_associates theorem wellFounded_associates : WellFounded ((· < ·) : Associates α → Associates α → Prop) := Subrelation.wf dvdNotUnit_of_lt wellFounded_dvdNotUnit #align wf_dvd_monoid.well_founded_associates WfDvdMonoid.wellFounded_associates -- Porting note: elab_as_elim can only be global and cannot be changed on an imported decl -- attribute [local elab_as_elim] WellFounded.fix theorem exists_irreducible_factor {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : ∃ i, Irreducible i ∧ i ∣ a := let ⟨b, hs, hr⟩ := wellFounded_dvdNotUnit.has_min { b | b ∣ a ∧ ¬IsUnit b } ⟨a, dvd_rfl, ha⟩ ⟨b, ⟨hs.2, fun c d he => let h := dvd_trans ⟨d, he⟩ hs.1 or_iff_not_imp_left.2 fun hc => of_not_not fun hd => hr c ⟨h, hc⟩ ⟨ne_zero_of_dvd_ne_zero ha0 h, d, hd, he⟩⟩, hs.1⟩ #align wf_dvd_monoid.exists_irreducible_factor WfDvdMonoid.exists_irreducible_factor @[elab_as_elim] theorem induction_on_irreducible {P : α → Prop} (a : α) (h0 : P 0) (hu : ∀ u : α, IsUnit u → P u) (hi : ∀ a i : α, a ≠ 0 → Irreducible i → P a → P (i * a)) : P a := haveI := Classical.dec wellFounded_dvdNotUnit.fix (fun a ih => if ha0 : a = 0 then ha0.substr h0 else if hau : IsUnit a then hu a hau else let ⟨i, hii, b, hb⟩ := exists_irreducible_factor hau ha0 let hb0 : b ≠ 0 := ne_zero_of_dvd_ne_zero ha0 ⟨i, mul_comm i b ▸ hb⟩ hb.symm ▸ hi b i hb0 hii <| ih b ⟨hb0, i, hii.1, mul_comm i b ▸ hb⟩) a #align wf_dvd_monoid.induction_on_irreducible WfDvdMonoid.induction_on_irreducible theorem exists_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ Associated f.prod a := induction_on_irreducible a (fun h => (h rfl).elim) (fun u hu _ => ⟨0, fun _ h => False.elim (Multiset.not_mem_zero _ h), hu.unit, one_mul _⟩) fun a i ha0 hi ih _ => let ⟨s, hs⟩ := ih ha0 ⟨i ::ₘ s, fun b H => (Multiset.mem_cons.1 H).elim (fun h => h.symm ▸ hi) (hs.1 b), by rw [s.prod_cons i] exact hs.2.mul_left i⟩ #align wf_dvd_monoid.exists_factors WfDvdMonoid.exists_factors theorem not_unit_iff_exists_factors_eq (a : α) (hn0 : a ≠ 0) : ¬IsUnit a ↔ ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod = a ∧ f ≠ ∅ := ⟨fun hnu => by obtain ⟨f, hi, u, rfl⟩ := exists_factors a hn0 obtain ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero fun h : f = 0 => hnu <| by simp [h] classical refine ⟨(f.erase b).cons (b * u), fun a ha => ?_, ?_, Multiset.cons_ne_zero⟩ · obtain rfl | ha := Multiset.mem_cons.1 ha exacts [Associated.irreducible ⟨u, rfl⟩ (hi b h), hi a (Multiset.mem_of_mem_erase ha)] · rw [Multiset.prod_cons, mul_comm b, mul_assoc, Multiset.prod_erase h, mul_comm], fun ⟨f, hi, he, hne⟩ => let ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero hne not_isUnit_of_not_isUnit_dvd (hi b h).not_unit <| he ▸ Multiset.dvd_prod h⟩ #align wf_dvd_monoid.not_unit_iff_exists_factors_eq WfDvdMonoid.not_unit_iff_exists_factors_eq theorem isRelPrime_of_no_irreducible_factors {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z : α, Irreducible z → z ∣ x → ¬z ∣ y) : IsRelPrime x y := isRelPrime_of_no_nonunits_factors nonzero fun _z znu znz zx zy ↦ have ⟨i, h1, h2⟩ := exists_irreducible_factor znu znz H i h1 (h2.trans zx) (h2.trans zy) end WfDvdMonoid theorem WfDvdMonoid.of_wellFounded_associates [CancelCommMonoidWithZero α] (h : WellFounded ((· < ·) : Associates α → Associates α → Prop)) : WfDvdMonoid α := WfDvdMonoid.of_wfDvdMonoid_associates ⟨by convert h ext exact Associates.dvdNotUnit_iff_lt⟩ #align wf_dvd_monoid.of_well_founded_associates WfDvdMonoid.of_wellFounded_associates theorem WfDvdMonoid.iff_wellFounded_associates [CancelCommMonoidWithZero α] : WfDvdMonoid α ↔ WellFounded ((· < ·) : Associates α → Associates α → Prop) := ⟨by apply WfDvdMonoid.wellFounded_associates, WfDvdMonoid.of_wellFounded_associates⟩ #align wf_dvd_monoid.iff_well_founded_associates WfDvdMonoid.iff_wellFounded_associates theorem WfDvdMonoid.max_power_factor' [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : ¬IsUnit x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := by obtain ⟨a, ⟨n, rfl⟩, hm⟩ := wellFounded_dvdNotUnit.has_min {a | ∃ n, x ^ n * a = a₀} ⟨a₀, 0, by rw [pow_zero, one_mul]⟩ refine ⟨n, a, ?_, rfl⟩; rintro ⟨d, rfl⟩ exact hm d ⟨n + 1, by rw [pow_succ, mul_assoc]⟩ ⟨(right_ne_zero_of_mul <| right_ne_zero_of_mul h), x, hx, mul_comm _ _⟩ theorem WfDvdMonoid.max_power_factor [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := max_power_factor' h hx.not_unit theorem multiplicity.finite_of_not_isUnit [CancelCommMonoidWithZero α] [WfDvdMonoid α] {a b : α} (ha : ¬IsUnit a) (hb : b ≠ 0) : multiplicity.Finite a b := by obtain ⟨n, c, ndvd, rfl⟩ := WfDvdMonoid.max_power_factor' hb ha exact ⟨n, by rwa [pow_succ, mul_dvd_mul_iff_left (left_ne_zero_of_mul hb)]⟩ section Prio -- set_option default_priority 100 -- see Note [default priority] /-- unique factorization monoids. These are defined as `CancelCommMonoidWithZero`s with well-founded strict divisibility relations, but this is equivalent to more familiar definitions: Each element (except zero) is uniquely represented as a multiset of irreducible factors. Uniqueness is only up to associated elements. Each element (except zero) is non-uniquely represented as a multiset of prime factors. To define a UFD using the definition in terms of multisets of irreducible factors, use the definition `of_exists_unique_irreducible_factors` To define a UFD using the definition in terms of multisets of prime factors, use the definition `of_exists_prime_factors` -/ class UniqueFactorizationMonoid (α : Type*) [CancelCommMonoidWithZero α] extends WfDvdMonoid α : Prop where protected irreducible_iff_prime : ∀ {a : α}, Irreducible a ↔ Prime a #align unique_factorization_monoid UniqueFactorizationMonoid /-- Can't be an instance because it would cause a loop `ufm → WfDvdMonoid → ufm → ...`. -/ theorem ufm_of_decomposition_of_wfDvdMonoid [CancelCommMonoidWithZero α] [WfDvdMonoid α] [DecompositionMonoid α] : UniqueFactorizationMonoid α := { ‹WfDvdMonoid α› with irreducible_iff_prime := irreducible_iff_prime } #align ufm_of_gcd_of_wf_dvd_monoid ufm_of_decomposition_of_wfDvdMonoid @[deprecated] alias ufm_of_gcd_of_wfDvdMonoid := ufm_of_decomposition_of_wfDvdMonoid instance Associates.ufm [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : UniqueFactorizationMonoid (Associates α) := { (WfDvdMonoid.wfDvdMonoid_associates : WfDvdMonoid (Associates α)) with irreducible_iff_prime := by rw [← Associates.irreducible_iff_prime_iff] apply UniqueFactorizationMonoid.irreducible_iff_prime } #align associates.ufm Associates.ufm end Prio namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem exists_prime_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] apply WfDvdMonoid.exists_factors a #align unique_factorization_monoid.exists_prime_factors UniqueFactorizationMonoid.exists_prime_factors instance : DecompositionMonoid α where primal a := by obtain rfl | ha := eq_or_ne a 0; · exact isPrimal_zero obtain ⟨f, hf, u, rfl⟩ := exists_prime_factors a ha exact ((Submonoid.isPrimal α).multiset_prod_mem f (hf · ·|>.isPrimal)).mul u.isUnit.isPrimal lemma exists_prime_iff : (∃ (p : α), Prime p) ↔ ∃ (x : α), x ≠ 0 ∧ ¬ IsUnit x := by refine ⟨fun ⟨p, hp⟩ ↦ ⟨p, hp.ne_zero, hp.not_unit⟩, fun ⟨x, hx₀, hxu⟩ ↦ ?_⟩ obtain ⟨f, hf, -⟩ := WfDvdMonoid.exists_irreducible_factor hxu hx₀ exact ⟨f, UniqueFactorizationMonoid.irreducible_iff_prime.mp hf⟩ @[elab_as_elim] theorem induction_on_prime {P : α → Prop} (a : α) (h₁ : P 0) (h₂ : ∀ x : α, IsUnit x → P x) (h₃ : ∀ a p : α, a ≠ 0 → Prime p → P a → P (p * a)) : P a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] at h₃ exact WfDvdMonoid.induction_on_irreducible a h₁ h₂ h₃ #align unique_factorization_monoid.induction_on_prime UniqueFactorizationMonoid.induction_on_prime end UniqueFactorizationMonoid theorem prime_factors_unique [CancelCommMonoidWithZero α] : ∀ {f g : Multiset α}, (∀ x ∈ f, Prime x) → (∀ x ∈ g, Prime x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g := by classical intro f induction' f using Multiset.induction_on with p f ih · intros g _ hg h exact Multiset.rel_zero_left.2 <| Multiset.eq_zero_of_forall_not_mem fun x hx => have : IsUnit g.prod := by simpa [associated_one_iff_isUnit] using h.symm (hg x hx).not_unit <| isUnit_iff_dvd_one.2 <| (Multiset.dvd_prod hx).trans (isUnit_iff_dvd_one.1 this) · intros g hf hg hfg let ⟨b, hbg, hb⟩ := (exists_associated_mem_of_dvd_prod (hf p (by simp)) fun q hq => hg _ hq) <| hfg.dvd_iff_dvd_right.1 (show p ∣ (p ::ₘ f).prod by simp) haveI := Classical.decEq α rw [← Multiset.cons_erase hbg] exact Multiset.Rel.cons hb (ih (fun q hq => hf _ (by simp [hq])) (fun {q} (hq : q ∈ g.erase b) => hg q (Multiset.mem_of_mem_erase hq)) (Associated.of_mul_left (by rwa [← Multiset.prod_cons, ← Multiset.prod_cons, Multiset.cons_erase hbg]) hb (hf p (by simp)).ne_zero)) #align prime_factors_unique prime_factors_unique namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem factors_unique {f g : Multiset α} (hf : ∀ x ∈ f, Irreducible x) (hg : ∀ x ∈ g, Irreducible x) (h : f.prod ~ᵤ g.prod) : Multiset.Rel Associated f g := prime_factors_unique (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hf x hx)) (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hg x hx)) h #align unique_factorization_monoid.factors_unique UniqueFactorizationMonoid.factors_unique end UniqueFactorizationMonoid /-- If an irreducible has a prime factorization, then it is an associate of one of its prime factors. -/ theorem prime_factors_irreducible [CancelCommMonoidWithZero α] {a : α} {f : Multiset α} (ha : Irreducible a) (pfa : (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) : ∃ p, a ~ᵤ p ∧ f = {p} := by haveI := Classical.decEq α refine @Multiset.induction_on _ (fun g => (g.prod ~ᵤ a) → (∀ b ∈ g, Prime b) → ∃ p, a ~ᵤ p ∧ g = {p}) f ?_ ?_ pfa.2 pfa.1 · intro h; exact (ha.not_unit (associated_one_iff_isUnit.1 (Associated.symm h))).elim · rintro p s _ ⟨u, hu⟩ hs use p have hs0 : s = 0 := by by_contra hs0 obtain ⟨q, hq⟩ := Multiset.exists_mem_of_ne_zero hs0 apply (hs q (by simp [hq])).2.1 refine (ha.isUnit_or_isUnit (?_ : _ = p * ↑u * (s.erase q).prod * _)).resolve_left ?_ · rw [mul_right_comm _ _ q, mul_assoc, ← Multiset.prod_cons, Multiset.cons_erase hq, ← hu, mul_comm, mul_comm p _, mul_assoc] simp apply mt isUnit_of_mul_isUnit_left (mt isUnit_of_mul_isUnit_left _) apply (hs p (Multiset.mem_cons_self _ _)).2.1 simp only [mul_one, Multiset.prod_cons, Multiset.prod_zero, hs0] at * exact ⟨Associated.symm ⟨u, hu⟩, rfl⟩ #align prime_factors_irreducible prime_factors_irreducible section ExistsPrimeFactors variable [CancelCommMonoidWithZero α] variable (pf : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) theorem WfDvdMonoid.of_exists_prime_factors : WfDvdMonoid α := ⟨by classical refine RelHomClass.wellFounded (RelHom.mk ?_ ?_ : (DvdNotUnit : α → α → Prop) →r ((· < ·) : ℕ∞ → ℕ∞ → Prop)) wellFounded_lt · intro a by_cases h : a = 0 · exact ⊤ exact ↑(Multiset.card (Classical.choose (pf a h))) rintro a b ⟨ane0, ⟨c, hc, b_eq⟩⟩ rw [dif_neg ane0] by_cases h : b = 0 · simp [h, lt_top_iff_ne_top] · rw [dif_neg h] erw [WithTop.coe_lt_coe] have cne0 : c ≠ 0 := by refine mt (fun con => ?_) h rw [b_eq, con, mul_zero] calc Multiset.card (Classical.choose (pf a ane0)) < _ + Multiset.card (Classical.choose (pf c cne0)) := lt_add_of_pos_right _ (Multiset.card_pos.mpr fun con => hc (associated_one_iff_isUnit.mp ?_)) _ = Multiset.card (Classical.choose (pf a ane0) + Classical.choose (pf c cne0)) := (Multiset.card_add _ _).symm _ = Multiset.card (Classical.choose (pf b h)) := Multiset.card_eq_card_of_rel (prime_factors_unique ?_ (Classical.choose_spec (pf _ h)).1 ?_) · convert (Classical.choose_spec (pf c cne0)).2.symm rw [con, Multiset.prod_zero] · intro x hadd rw [Multiset.mem_add] at hadd cases' hadd with h h <;> apply (Classical.choose_spec (pf _ _)).1 _ h <;> assumption · rw [Multiset.prod_add] trans a * c · apply Associated.mul_mul <;> apply (Classical.choose_spec (pf _ _)).2 <;> assumption · rw [← b_eq] apply (Classical.choose_spec (pf _ _)).2.symm; assumption⟩ #align wf_dvd_monoid.of_exists_prime_factors WfDvdMonoid.of_exists_prime_factors theorem irreducible_iff_prime_of_exists_prime_factors {p : α} : Irreducible p ↔ Prime p := by by_cases hp0 : p = 0 · simp [hp0] refine ⟨fun h => ?_, Prime.irreducible⟩ obtain ⟨f, hf⟩ := pf p hp0 obtain ⟨q, hq, rfl⟩ := prime_factors_irreducible h hf rw [hq.prime_iff] exact hf.1 q (Multiset.mem_singleton_self _) #align irreducible_iff_prime_of_exists_prime_factors irreducible_iff_prime_of_exists_prime_factors theorem UniqueFactorizationMonoid.of_exists_prime_factors : UniqueFactorizationMonoid α := { WfDvdMonoid.of_exists_prime_factors pf with irreducible_iff_prime := irreducible_iff_prime_of_exists_prime_factors pf } #align unique_factorization_monoid.of_exists_prime_factors UniqueFactorizationMonoid.of_exists_prime_factors end ExistsPrimeFactors theorem UniqueFactorizationMonoid.iff_exists_prime_factors [CancelCommMonoidWithZero α] : UniqueFactorizationMonoid α ↔ ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := ⟨fun h => @UniqueFactorizationMonoid.exists_prime_factors _ _ h, UniqueFactorizationMonoid.of_exists_prime_factors⟩ #align unique_factorization_monoid.iff_exists_prime_factors UniqueFactorizationMonoid.iff_exists_prime_factors section variable {β : Type*} [CancelCommMonoidWithZero α] [CancelCommMonoidWithZero β] theorem MulEquiv.uniqueFactorizationMonoid (e : α ≃* β) (hα : UniqueFactorizationMonoid α) : UniqueFactorizationMonoid β := by rw [UniqueFactorizationMonoid.iff_exists_prime_factors] at hα ⊢ intro a ha obtain ⟨w, hp, u, h⟩ := hα (e.symm a) fun h => ha <| by convert← map_zero e simp [← h] exact ⟨w.map e, fun b hb => let ⟨c, hc, he⟩ := Multiset.mem_map.1 hb he ▸ e.prime_iff.1 (hp c hc), Units.map e.toMonoidHom u, by erw [Multiset.prod_hom, ← e.map_mul, h] simp⟩ #align mul_equiv.unique_factorization_monoid MulEquiv.uniqueFactorizationMonoid theorem MulEquiv.uniqueFactorizationMonoid_iff (e : α ≃* β) : UniqueFactorizationMonoid α ↔ UniqueFactorizationMonoid β := ⟨e.uniqueFactorizationMonoid, e.symm.uniqueFactorizationMonoid⟩ #align mul_equiv.unique_factorization_monoid_iff MulEquiv.uniqueFactorizationMonoid_iff end theorem irreducible_iff_prime_of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) (p : α) : Irreducible p ↔ Prime p := letI := Classical.decEq α ⟨ fun hpi => ⟨hpi.ne_zero, hpi.1, fun a b ⟨x, hx⟩ => if hab0 : a * b = 0 then (eq_zero_or_eq_zero_of_mul_eq_zero hab0).elim (fun ha0 => by simp [ha0]) fun hb0 => by simp [hb0] else by have hx0 : x ≠ 0 := fun hx0 => by simp_all have ha0 : a ≠ 0 := left_ne_zero_of_mul hab0 have hb0 : b ≠ 0 := right_ne_zero_of_mul hab0 cases' eif x hx0 with fx hfx cases' eif a ha0 with fa hfa cases' eif b hb0 with fb hfb have h : Multiset.Rel Associated (p ::ₘ fx) (fa + fb) := by apply uif · exact fun i hi => (Multiset.mem_cons.1 hi).elim (fun hip => hip.symm ▸ hpi) (hfx.1 _) · exact fun i hi => (Multiset.mem_add.1 hi).elim (hfa.1 _) (hfb.1 _) calc Multiset.prod (p ::ₘ fx) ~ᵤ a * b := by rw [hx, Multiset.prod_cons]; exact hfx.2.mul_left _ _ ~ᵤ fa.prod * fb.prod := hfa.2.symm.mul_mul hfb.2.symm _ = _ := by rw [Multiset.prod_add] exact let ⟨q, hqf, hq⟩ := Multiset.exists_mem_of_rel_of_mem h (Multiset.mem_cons_self p _) (Multiset.mem_add.1 hqf).elim (fun hqa => Or.inl <| hq.dvd_iff_dvd_left.2 <| hfa.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqa)) fun hqb => Or.inr <| hq.dvd_iff_dvd_left.2 <| hfb.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqb)⟩, Prime.irreducible⟩ #align irreducible_iff_prime_of_exists_unique_irreducible_factors irreducible_iff_prime_of_exists_unique_irreducible_factors theorem UniqueFactorizationMonoid.of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) : UniqueFactorizationMonoid α := UniqueFactorizationMonoid.of_exists_prime_factors (by convert eif using 7 simp_rw [irreducible_iff_prime_of_exists_unique_irreducible_factors eif uif]) #align unique_factorization_monoid.of_exists_unique_irreducible_factors UniqueFactorizationMonoid.of_exists_unique_irreducible_factors namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] variable [UniqueFactorizationMonoid α] open Classical in /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def factors (a : α) : Multiset α := if h : a = 0 then 0 else Classical.choose (UniqueFactorizationMonoid.exists_prime_factors a h) #align unique_factorization_monoid.factors UniqueFactorizationMonoid.factors theorem factors_prod {a : α} (ane0 : a ≠ 0) : Associated (factors a).prod a := by rw [factors, dif_neg ane0] exact (Classical.choose_spec (exists_prime_factors a ane0)).2 #align unique_factorization_monoid.factors_prod UniqueFactorizationMonoid.factors_prod @[simp] theorem factors_zero : factors (0 : α) = 0 := by simp [factors] #align unique_factorization_monoid.factors_zero UniqueFactorizationMonoid.factors_zero theorem ne_zero_of_mem_factors {p a : α} (h : p ∈ factors a) : a ≠ 0 := by rintro rfl simp at h #align unique_factorization_monoid.ne_zero_of_mem_factors UniqueFactorizationMonoid.ne_zero_of_mem_factors theorem dvd_of_mem_factors {p a : α} (h : p ∈ factors a) : p ∣ a := dvd_trans (Multiset.dvd_prod h) (Associated.dvd (factors_prod (ne_zero_of_mem_factors h))) #align unique_factorization_monoid.dvd_of_mem_factors UniqueFactorizationMonoid.dvd_of_mem_factors theorem prime_of_factor {a : α} (x : α) (hx : x ∈ factors a) : Prime x := by have ane0 := ne_zero_of_mem_factors hx rw [factors, dif_neg ane0] at hx exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 x hx #align unique_factorization_monoid.prime_of_factor UniqueFactorizationMonoid.prime_of_factor theorem irreducible_of_factor {a : α} : ∀ x : α, x ∈ factors a → Irreducible x := fun x h => (prime_of_factor x h).irreducible #align unique_factorization_monoid.irreducible_of_factor UniqueFactorizationMonoid.irreducible_of_factor @[simp] theorem factors_one : factors (1 : α) = 0 := by nontriviality α using factors rw [← Multiset.rel_zero_right] refine factors_unique irreducible_of_factor (fun x hx => (Multiset.not_mem_zero x hx).elim) ?_ rw [Multiset.prod_zero] exact factors_prod one_ne_zero #align unique_factorization_monoid.factors_one UniqueFactorizationMonoid.factors_one theorem exists_mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ factors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ factors b) (factors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_factor _)) irreducible_of_factor (Associated.symm <| calc Multiset.prod (factors a) ~ᵤ a := factors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ factors b) := by rw [Multiset.prod_cons]; exact (factors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) #align unique_factorization_monoid.exists_mem_factors_of_dvd UniqueFactorizationMonoid.exists_mem_factors_of_dvd theorem exists_mem_factors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ factors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_factors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ #align unique_factorization_monoid.exists_mem_factors UniqueFactorizationMonoid.exists_mem_factors open Classical in theorem factors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : Multiset.Rel Associated (factors (x * y)) (factors x + factors y) := by refine factors_unique irreducible_of_factor (fun a ha => (Multiset.mem_add.mp ha).by_cases (irreducible_of_factor _) (irreducible_of_factor _)) ((factors_prod (mul_ne_zero hx hy)).trans ?_) rw [Multiset.prod_add] exact (Associated.mul_mul (factors_prod hx) (factors_prod hy)).symm #align unique_factorization_monoid.factors_mul UniqueFactorizationMonoid.factors_mul theorem factors_pow {x : α} (n : ℕ) : Multiset.Rel Associated (factors (x ^ n)) (n • factors x) := by match n with | 0 => rw [zero_smul, pow_zero, factors_one, Multiset.rel_zero_right] | n+1 => by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] · rw [pow_succ', succ_nsmul'] refine Multiset.Rel.trans _ (factors_mul h0 (pow_ne_zero n h0)) ?_ refine Multiset.Rel.add ?_ <| factors_pow n exact Multiset.rel_refl_of_refl_on fun y _ => Associated.refl _ #align unique_factorization_monoid.factors_pow UniqueFactorizationMonoid.factors_pow @[simp] theorem factors_pos (x : α) (hx : x ≠ 0) : 0 < factors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_factors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_factors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) #align unique_factorization_monoid.factors_pos UniqueFactorizationMonoid.factors_pos open Multiset in theorem factors_pow_count_prod [DecidableEq α] {x : α} (hx : x ≠ 0) : (∏ p ∈ (factors x).toFinset, p ^ (factors x).count p) ~ᵤ x := calc _ = prod (∑ a ∈ toFinset (factors x), count a (factors x) • {a}) := by simp only [prod_sum, prod_nsmul, prod_singleton] _ = prod (factors x) := by rw [toFinset_sum_count_nsmul_eq (factors x)] _ ~ᵤ x := factors_prod hx end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] variable [UniqueFactorizationMonoid α] /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def normalizedFactors (a : α) : Multiset α := Multiset.map normalize <| factors a #align unique_factorization_monoid.normalized_factors UniqueFactorizationMonoid.normalizedFactors /-- An arbitrary choice of factors of `x : M` is exactly the (unique) normalized set of factors, if `M` has a trivial group of units. -/ @[simp] theorem factors_eq_normalizedFactors {M : Type*} [CancelCommMonoidWithZero M] [UniqueFactorizationMonoid M] [Unique Mˣ] (x : M) : factors x = normalizedFactors x := by unfold normalizedFactors convert (Multiset.map_id (factors x)).symm ext p exact normalize_eq p #align unique_factorization_monoid.factors_eq_normalized_factors UniqueFactorizationMonoid.factors_eq_normalizedFactors theorem normalizedFactors_prod {a : α} (ane0 : a ≠ 0) : Associated (normalizedFactors a).prod a := by rw [normalizedFactors, factors, dif_neg ane0] refine Associated.trans ?_ (Classical.choose_spec (exists_prime_factors a ane0)).2 rw [← Associates.mk_eq_mk_iff_associated, ← Associates.prod_mk, ← Associates.prod_mk, Multiset.map_map] congr 2 ext rw [Function.comp_apply, Associates.mk_normalize] #align unique_factorization_monoid.normalized_factors_prod UniqueFactorizationMonoid.normalizedFactors_prod theorem prime_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Prime x := by rw [normalizedFactors, factors] split_ifs with ane0; · simp intro x hx; rcases Multiset.mem_map.1 hx with ⟨y, ⟨hy, rfl⟩⟩ rw [(normalize_associated _).prime_iff] exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 y hy #align unique_factorization_monoid.prime_of_normalized_factor UniqueFactorizationMonoid.prime_of_normalized_factor theorem irreducible_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Irreducible x := fun x h => (prime_of_normalized_factor x h).irreducible #align unique_factorization_monoid.irreducible_of_normalized_factor UniqueFactorizationMonoid.irreducible_of_normalized_factor theorem normalize_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → normalize x = x := by rw [normalizedFactors, factors] split_ifs with h; · simp intro x hx obtain ⟨y, _, rfl⟩ := Multiset.mem_map.1 hx apply normalize_idem #align unique_factorization_monoid.normalize_normalized_factor UniqueFactorizationMonoid.normalize_normalized_factor theorem normalizedFactors_irreducible {a : α} (ha : Irreducible a) : normalizedFactors a = {normalize a} := by obtain ⟨p, a_assoc, hp⟩ := prime_factors_irreducible ha ⟨prime_of_normalized_factor, normalizedFactors_prod ha.ne_zero⟩ have p_mem : p ∈ normalizedFactors a := by rw [hp] exact Multiset.mem_singleton_self _ convert hp rwa [← normalize_normalized_factor p p_mem, normalize_eq_normalize_iff, dvd_dvd_iff_associated] #align unique_factorization_monoid.normalized_factors_irreducible UniqueFactorizationMonoid.normalizedFactors_irreducible theorem normalizedFactors_eq_of_dvd (a : α) : ∀ᵉ (p ∈ normalizedFactors a) (q ∈ normalizedFactors a), p ∣ q → p = q := by intro p hp q hq hdvd convert normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) <;> apply (normalize_normalized_factor _ ‹_›).symm #align unique_factorization_monoid.normalized_factors_eq_of_dvd UniqueFactorizationMonoid.normalizedFactors_eq_of_dvd theorem exists_mem_normalizedFactors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ normalizedFactors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ normalizedFactors b) (normalizedFactors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_normalized_factor _)) irreducible_of_normalized_factor (Associated.symm <| calc Multiset.prod (normalizedFactors a) ~ᵤ a := normalizedFactors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ normalizedFactors b) := by rw [Multiset.prod_cons] exact (normalizedFactors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) #align unique_factorization_monoid.exists_mem_normalized_factors_of_dvd UniqueFactorizationMonoid.exists_mem_normalizedFactors_of_dvd theorem exists_mem_normalizedFactors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ normalizedFactors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_normalizedFactors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ #align unique_factorization_monoid.exists_mem_normalized_factors UniqueFactorizationMonoid.exists_mem_normalizedFactors @[simp] theorem normalizedFactors_zero : normalizedFactors (0 : α) = 0 := by simp [normalizedFactors, factors] #align unique_factorization_monoid.normalized_factors_zero UniqueFactorizationMonoid.normalizedFactors_zero @[simp] theorem normalizedFactors_one : normalizedFactors (1 : α) = 0 := by cases' subsingleton_or_nontrivial α with h h · dsimp [normalizedFactors, factors] simp [Subsingleton.elim (1:α) 0] · rw [← Multiset.rel_zero_right] apply factors_unique irreducible_of_normalized_factor · intro x hx exfalso apply Multiset.not_mem_zero x hx · apply normalizedFactors_prod one_ne_zero #align unique_factorization_monoid.normalized_factors_one UniqueFactorizationMonoid.normalizedFactors_one @[simp] theorem normalizedFactors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : normalizedFactors (x * y) = normalizedFactors x + normalizedFactors y := by have h : (normalize : α → α) = Associates.out ∘ Associates.mk := by ext rw [Function.comp_apply, Associates.out_mk] rw [← Multiset.map_id' (normalizedFactors (x * y)), ← Multiset.map_id' (normalizedFactors x), ← Multiset.map_id' (normalizedFactors y), ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_add, h, ← Multiset.map_map Associates.out, eq_comm, ← Multiset.map_map Associates.out] refine congr rfl ?_ apply Multiset.map_mk_eq_map_mk_of_rel apply factors_unique · intro x hx rcases Multiset.mem_add.1 hx with (hx | hx) <;> exact irreducible_of_normalized_factor x hx · exact irreducible_of_normalized_factor · rw [Multiset.prod_add] exact ((normalizedFactors_prod hx).mul_mul (normalizedFactors_prod hy)).trans (normalizedFactors_prod (mul_ne_zero hx hy)).symm #align unique_factorization_monoid.normalized_factors_mul UniqueFactorizationMonoid.normalizedFactors_mul @[simp] theorem normalizedFactors_pow {x : α} (n : ℕ) : normalizedFactors (x ^ n) = n • normalizedFactors x := by induction' n with n ih · simp by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] rw [pow_succ', succ_nsmul', normalizedFactors_mul h0 (pow_ne_zero _ h0), ih] #align unique_factorization_monoid.normalized_factors_pow UniqueFactorizationMonoid.normalizedFactors_pow theorem _root_.Irreducible.normalizedFactors_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [UniqueFactorizationMonoid.normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] #align irreducible.normalized_factors_pow Irreducible.normalizedFactors_pow theorem normalizedFactors_prod_eq (s : Multiset α) (hs : ∀ a ∈ s, Irreducible a) : normalizedFactors s.prod = s.map normalize := by induction' s using Multiset.induction with a s ih · rw [Multiset.prod_zero, normalizedFactors_one, Multiset.map_zero] · have ia := hs a (Multiset.mem_cons_self a _) have ib := fun b h => hs b (Multiset.mem_cons_of_mem h) obtain rfl | ⟨b, hb⟩ := s.empty_or_exists_mem · rw [Multiset.cons_zero, Multiset.prod_singleton, Multiset.map_singleton, normalizedFactors_irreducible ia] haveI := nontrivial_of_ne b 0 (ib b hb).ne_zero rw [Multiset.prod_cons, Multiset.map_cons, normalizedFactors_mul ia.ne_zero (Multiset.prod_ne_zero fun h => (ib 0 h).ne_zero rfl), normalizedFactors_irreducible ia, ih ib, Multiset.singleton_add] #align unique_factorization_monoid.normalized_factors_prod_eq UniqueFactorizationMonoid.normalizedFactors_prod_eq theorem dvd_iff_normalizedFactors_le_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ∣ y ↔ normalizedFactors x ≤ normalizedFactors y := by constructor · rintro ⟨c, rfl⟩ simp [hx, right_ne_zero_of_mul hy] · rw [← (normalizedFactors_prod hx).dvd_iff_dvd_left, ← (normalizedFactors_prod hy).dvd_iff_dvd_right] apply Multiset.prod_dvd_prod_of_le #align unique_factorization_monoid.dvd_iff_normalized_factors_le_normalized_factors UniqueFactorizationMonoid.dvd_iff_normalizedFactors_le_normalizedFactors theorem associated_iff_normalizedFactors_eq_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ~ᵤ y ↔ normalizedFactors x = normalizedFactors y := by refine ⟨fun h => ?_, fun h => (normalizedFactors_prod hx).symm.trans (_root_.trans (by rw [h]) (normalizedFactors_prod hy))⟩ apply le_antisymm <;> rw [← dvd_iff_normalizedFactors_le_normalizedFactors] all_goals simp [*, h.dvd, h.symm.dvd] #align unique_factorization_monoid.associated_iff_normalized_factors_eq_normalized_factors UniqueFactorizationMonoid.associated_iff_normalizedFactors_eq_normalizedFactors theorem normalizedFactors_of_irreducible_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] #align unique_factorization_monoid.normalized_factors_of_irreducible_pow UniqueFactorizationMonoid.normalizedFactors_of_irreducible_pow theorem zero_not_mem_normalizedFactors (x : α) : (0 : α) ∉ normalizedFactors x := fun h => Prime.ne_zero (prime_of_normalized_factor _ h) rfl #align unique_factorization_monoid.zero_not_mem_normalized_factors UniqueFactorizationMonoid.zero_not_mem_normalizedFactors theorem dvd_of_mem_normalizedFactors {a p : α} (H : p ∈ normalizedFactors a) : p ∣ a := by by_cases hcases : a = 0 · rw [hcases] exact dvd_zero p · exact dvd_trans (Multiset.dvd_prod H) (Associated.dvd (normalizedFactors_prod hcases)) #align unique_factorization_monoid.dvd_of_mem_normalized_factors UniqueFactorizationMonoid.dvd_of_mem_normalizedFactors theorem mem_normalizedFactors_iff [Unique αˣ] {p x : α} (hx : x ≠ 0) : p ∈ normalizedFactors x ↔ Prime p ∧ p ∣ x := by constructor · intro h exact ⟨prime_of_normalized_factor p h, dvd_of_mem_normalizedFactors h⟩ · rintro ⟨hprime, hdvd⟩ obtain ⟨q, hqmem, hqeq⟩ := exists_mem_normalizedFactors_of_dvd hx hprime.irreducible hdvd rw [associated_iff_eq] at hqeq exact hqeq ▸ hqmem theorem exists_associated_prime_pow_of_unique_normalized_factor {p r : α} (h : ∀ {m}, m ∈ normalizedFactors r → m = p) (hr : r ≠ 0) : ∃ i : ℕ, Associated (p ^ i) r := by use Multiset.card.toFun (normalizedFactors r) have := UniqueFactorizationMonoid.normalizedFactors_prod hr rwa [Multiset.eq_replicate_of_mem fun b => h, Multiset.prod_replicate] at this #align unique_factorization_monoid.exists_associated_prime_pow_of_unique_normalized_factor UniqueFactorizationMonoid.exists_associated_prime_pow_of_unique_normalized_factor theorem normalizedFactors_prod_of_prime [Nontrivial α] [Unique αˣ] {m : Multiset α} (h : ∀ p ∈ m, Prime p) : normalizedFactors m.prod = m := by simpa only [← Multiset.rel_eq, ← associated_eq_eq] using prime_factors_unique prime_of_normalized_factor h (normalizedFactors_prod (m.prod_ne_zero_of_prime h)) #align unique_factorization_monoid.normalized_factors_prod_of_prime UniqueFactorizationMonoid.normalizedFactors_prod_of_prime theorem mem_normalizedFactors_eq_of_associated {a b c : α} (ha : a ∈ normalizedFactors c) (hb : b ∈ normalizedFactors c) (h : Associated a b) : a = b := by rw [← normalize_normalized_factor a ha, ← normalize_normalized_factor b hb, normalize_eq_normalize_iff] exact Associated.dvd_dvd h #align unique_factorization_monoid.mem_normalized_factors_eq_of_associated UniqueFactorizationMonoid.mem_normalizedFactors_eq_of_associated @[simp] theorem normalizedFactors_pos (x : α) (hx : x ≠ 0) : 0 < normalizedFactors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_normalized_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_normalizedFactors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_normalizedFactors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) #align unique_factorization_monoid.normalized_factors_pos UniqueFactorizationMonoid.normalizedFactors_pos theorem dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : DvdNotUnit x y ↔ normalizedFactors x < normalizedFactors y := by constructor · rintro ⟨_, c, hc, rfl⟩ simp only [hx, right_ne_zero_of_mul hy, normalizedFactors_mul, Ne, not_false_iff, lt_add_iff_pos_right, normalizedFactors_pos, hc] · intro h exact dvdNotUnit_of_dvd_of_not_dvd ((dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mpr h.le) (mt (dvd_iff_normalizedFactors_le_normalizedFactors hy hx).mp h.not_le) #align unique_factorization_monoid.dvd_not_unit_iff_normalized_factors_lt_normalized_factors UniqueFactorizationMonoid.dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors theorem normalizedFactors_multiset_prod (s : Multiset α) (hs : 0 ∉ s) : normalizedFactors (s.prod) = (s.map normalizedFactors).sum := by cases subsingleton_or_nontrivial α · obtain rfl : s = 0 := by apply Multiset.eq_zero_of_forall_not_mem intro _ convert hs simp induction s using Multiset.induction with | empty => simp | cons _ _ IH => rw [Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons, normalizedFactors_mul, IH] · exact fun h ↦ hs (Multiset.mem_cons_of_mem h) · exact fun h ↦ hs (h ▸ Multiset.mem_cons_self _ _) · apply Multiset.prod_ne_zero exact fun h ↦ hs (Multiset.mem_cons_of_mem h) end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid open scoped Classical open Multiset Associates variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] /-- Noncomputably defines a `normalizationMonoid` structure on a `UniqueFactorizationMonoid`. -/ protected noncomputable def normalizationMonoid : NormalizationMonoid α := normalizationMonoidOfMonoidHomRightInverse { toFun := fun a : Associates α => if a = 0 then 0 else ((normalizedFactors a).map (Classical.choose mk_surjective.hasRightInverse : Associates α → α)).prod map_one' := by nontriviality α; simp map_mul' := fun x y => by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] simp [hx, hy] } (by intro x dsimp by_cases hx : x = 0 · simp [hx] have h : Associates.mkMonoidHom ∘ Classical.choose mk_surjective.hasRightInverse = (id : Associates α → Associates α) := by ext x rw [Function.comp_apply, mkMonoidHom_apply, Classical.choose_spec mk_surjective.hasRightInverse x] rfl rw [if_neg hx, ← mkMonoidHom_apply, MonoidHom.map_multiset_prod, map_map, h, map_id, ← associated_iff_eq] apply normalizedFactors_prod hx) #align unique_factorization_monoid.normalization_monoid UniqueFactorizationMonoid.normalizationMonoid end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable {R : Type*} [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R] theorem isRelPrime_iff_no_prime_factors {a b : R} (ha : a ≠ 0) : IsRelPrime a b ↔ ∀ ⦃d⦄, d ∣ a → d ∣ b → ¬Prime d := ⟨fun h _ ha hb ↦ (·.not_unit <| h ha hb), fun h ↦ WfDvdMonoid.isRelPrime_of_no_irreducible_factors (ha ·.1) fun _ irr ha hb ↦ h ha hb (UniqueFactorizationMonoid.irreducible_iff_prime.mp irr)⟩ #align unique_factorization_monoid.no_factors_of_no_prime_factors UniqueFactorizationMonoid.isRelPrime_iff_no_prime_factors /-- Euclid's lemma: if `a ∣ b * c` and `a` and `c` have no common prime factors, `a ∣ b`. Compare `IsCoprime.dvd_of_dvd_mul_left`. -/ theorem dvd_of_dvd_mul_left_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (h : ∀ ⦃d⦄, d ∣ a → d ∣ c → ¬Prime d) : a ∣ b * c → a ∣ b := ((isRelPrime_iff_no_prime_factors ha).mpr h).dvd_of_dvd_mul_right #align unique_factorization_monoid.dvd_of_dvd_mul_left_of_no_prime_factors UniqueFactorizationMonoid.dvd_of_dvd_mul_left_of_no_prime_factors /-- Euclid's lemma: if `a ∣ b * c` and `a` and `b` have no common prime factors, `a ∣ c`. Compare `IsCoprime.dvd_of_dvd_mul_right`. -/ theorem dvd_of_dvd_mul_right_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (no_factors : ∀ {d}, d ∣ a → d ∣ b → ¬Prime d) : a ∣ b * c → a ∣ c := by simpa [mul_comm b c] using dvd_of_dvd_mul_left_of_no_prime_factors ha @no_factors #align unique_factorization_monoid.dvd_of_dvd_mul_right_of_no_prime_factors UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors /-- If `a ≠ 0, b` are elements of a unique factorization domain, then dividing out their common factor `c'` gives `a'` and `b'` with no factors in common. -/ theorem exists_reduced_factors : ∀ a ≠ (0 : R), ∀ b, ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := by intro a refine induction_on_prime a ?_ ?_ ?_ · intros contradiction · intro a a_unit _ b use a, b, 1 constructor · intro p p_dvd_a _ exact isUnit_of_dvd_unit p_dvd_a a_unit · simp · intro a p a_ne_zero p_prime ih_a pa_ne_zero b by_cases h : p ∣ b · rcases h with ⟨b, rfl⟩ obtain ⟨a', b', c', no_factor, ha', hb'⟩ := ih_a a_ne_zero b refine ⟨a', b', p * c', @no_factor, ?_, ?_⟩ · rw [mul_assoc, ha'] · rw [mul_assoc, hb'] · obtain ⟨a', b', c', coprime, rfl, rfl⟩ := ih_a a_ne_zero b refine ⟨p * a', b', c', ?_, mul_left_comm _ _ _, rfl⟩ intro q q_dvd_pa' q_dvd_b' cases' p_prime.left_dvd_or_dvd_right_of_dvd_mul q_dvd_pa' with p_dvd_q q_dvd_a' · have : p ∣ c' * b' := dvd_mul_of_dvd_right (p_dvd_q.trans q_dvd_b') _ contradiction exact coprime q_dvd_a' q_dvd_b' #align unique_factorization_monoid.exists_reduced_factors UniqueFactorizationMonoid.exists_reduced_factors theorem exists_reduced_factors' (a b : R) (hb : b ≠ 0) : ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := let ⟨b', a', c', no_factor, hb, ha⟩ := exists_reduced_factors b hb a ⟨a', b', c', fun _ hpb hpa => no_factor hpa hpb, ha, hb⟩ #align unique_factorization_monoid.exists_reduced_factors' UniqueFactorizationMonoid.exists_reduced_factors' theorem pow_right_injective {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) : Function.Injective (a ^ · : ℕ → R) := by letI := Classical.decEq R intro i j hij letI : Nontrivial R := ⟨⟨a, 0, ha0⟩⟩ letI : NormalizationMonoid R := UniqueFactorizationMonoid.normalizationMonoid obtain ⟨p', hp', dvd'⟩ := WfDvdMonoid.exists_irreducible_factor ha1 ha0 obtain ⟨p, mem, _⟩ := exists_mem_normalizedFactors_of_dvd ha0 hp' dvd' have := congr_arg (fun x => Multiset.count p (normalizedFactors x)) hij simp only [normalizedFactors_pow, Multiset.count_nsmul] at this exact mul_right_cancel₀ (Multiset.count_ne_zero.mpr mem) this #align unique_factorization_monoid.pow_right_injective UniqueFactorizationMonoid.pow_right_injective theorem pow_eq_pow_iff {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) {i j : ℕ} : a ^ i = a ^ j ↔ i = j := (pow_right_injective ha0 ha1).eq_iff #align unique_factorization_monoid.pow_eq_pow_iff UniqueFactorizationMonoid.pow_eq_pow_iff section multiplicity variable [NormalizationMonoid R] variable [DecidableRel (Dvd.dvd : R → R → Prop)] open multiplicity Multiset theorem le_multiplicity_iff_replicate_le_normalizedFactors {a b : R} {n : ℕ} (ha : Irreducible a) (hb : b ≠ 0) : ↑n ≤ multiplicity a b ↔ replicate n (normalize a) ≤ normalizedFactors b := by rw [← pow_dvd_iff_le_multiplicity] revert b induction' n with n ih; · simp intro b hb constructor · rintro ⟨c, rfl⟩ rw [Ne, pow_succ', mul_assoc, mul_eq_zero, not_or] at hb rw [pow_succ', mul_assoc, normalizedFactors_mul hb.1 hb.2, replicate_succ, normalizedFactors_irreducible ha, singleton_add, cons_le_cons_iff, ← ih hb.2] apply Dvd.intro _ rfl · rw [Multiset.le_iff_exists_add] rintro ⟨u, hu⟩ rw [← (normalizedFactors_prod hb).dvd_iff_dvd_right, hu, prod_add, prod_replicate] exact (Associated.pow_pow <| associated_normalize a).dvd.trans (Dvd.intro u.prod rfl) #align unique_factorization_monoid.le_multiplicity_iff_replicate_le_normalized_factors UniqueFactorizationMonoid.le_multiplicity_iff_replicate_le_normalizedFactors /-- The multiplicity of an irreducible factor of a nonzero element is exactly the number of times the normalized factor occurs in the `normalizedFactors`. See also `count_normalizedFactors_eq` which expands the definition of `multiplicity` to produce a specification for `count (normalizedFactors _) _`.. -/ theorem multiplicity_eq_count_normalizedFactors [DecidableEq R] {a b : R} (ha : Irreducible a) (hb : b ≠ 0) : multiplicity a b = (normalizedFactors b).count (normalize a) := by apply le_antisymm · apply PartENat.le_of_lt_add_one rw [← Nat.cast_one, ← Nat.cast_add, lt_iff_not_ge, ge_iff_le, le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] simp rw [le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] #align unique_factorization_monoid.multiplicity_eq_count_normalized_factors UniqueFactorizationMonoid.multiplicity_eq_count_normalizedFactors /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq [DecidableEq R] {p x : R} (hp : Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by letI : DecidableRel ((· ∣ ·) : R → R → Prop) := fun _ _ => Classical.propDecidable _ by_cases hx0 : x = 0 · simp [hx0] at hlt rw [← PartENat.natCast_inj] convert (multiplicity_eq_count_normalizedFactors hp hx0).symm · exact hnorm.symm exact (multiplicity.eq_coe_iff.mpr ⟨hle, hlt⟩).symm #align unique_factorization_monoid.count_normalized_factors_eq UniqueFactorizationMonoid.count_normalizedFactors_eq /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. This is a slightly more general version of `UniqueFactorizationMonoid.count_normalizedFactors_eq` that allows `p = 0`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq' [DecidableEq R] {p x : R} (hp : p = 0 ∨ Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by rcases hp with (rfl | hp) · cases n · exact count_eq_zero.2 (zero_not_mem_normalizedFactors _) · rw [zero_pow (Nat.succ_ne_zero _)] at hle hlt exact absurd hle hlt · exact count_normalizedFactors_eq hp hnorm hle hlt #align unique_factorization_monoid.count_normalized_factors_eq' UniqueFactorizationMonoid.count_normalizedFactors_eq' /-- Deprecated. Use `WfDvdMonoid.max_power_factor` instead. -/ @[deprecated WfDvdMonoid.max_power_factor] theorem max_power_factor {a₀ x : R} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ n : ℕ, ∃ a : R, ¬x ∣ a ∧ a₀ = x ^ n * a := WfDvdMonoid.max_power_factor h hx #align unique_factorization_monoid.max_power_factor UniqueFactorizationMonoid.max_power_factor end multiplicity section Multiplicative variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] variable {β : Type*} [CancelCommMonoidWithZero β] theorem prime_pow_coprime_prod_of_coprime_insert [DecidableEq α] {s : Finset α} (i : α → ℕ) (p : α) (hps : p ∉ s) (is_prime : ∀ q ∈ insert p s, Prime q) (is_coprime : ∀ᵉ (q ∈ insert p s) (q' ∈ insert p s), q ∣ q' → q = q') : IsRelPrime (p ^ i p) (∏ p' ∈ s, p' ^ i p') := by have hp := is_prime _ (Finset.mem_insert_self _ _) refine (isRelPrime_iff_no_prime_factors <| pow_ne_zero _ hp.ne_zero).mpr ?_ intro d hdp hdprod hd apply hps replace hdp := hd.dvd_of_dvd_pow hdp obtain ⟨q, q_mem', hdq⟩ := hd.exists_mem_multiset_dvd hdprod obtain ⟨q, q_mem, rfl⟩ := Multiset.mem_map.mp q_mem' replace hdq := hd.dvd_of_dvd_pow hdq have : p ∣ q := dvd_trans (hd.irreducible.dvd_symm hp.irreducible hdp) hdq convert q_mem rw [Finset.mem_val, is_coprime _ (Finset.mem_insert_self p s) _ (Finset.mem_insert_of_mem q_mem) this] #align unique_factorization_monoid.prime_pow_coprime_prod_of_coprime_insert UniqueFactorizationMonoid.prime_pow_coprime_prod_of_coprime_insert /-- If `P` holds for units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on a product of powers of distinct primes. -/ -- @[elab_as_elim] Porting note: commented out theorem induction_on_prime_power {P : α → Prop} (s : Finset α) (i : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P (∏ p ∈ s, p ^ i p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p f' hpf' ih · simpa using h1 isUnit_one rw [Finset.prod_insert hpf'] exact hcp (prime_pow_coprime_prod_of_coprime_insert i p hpf' is_prime is_coprime) (hpr (i p) (is_prime _ (Finset.mem_insert_self _ _))) (ih (fun q hq => is_prime _ (Finset.mem_insert_of_mem hq)) fun q hq q' hq' => is_coprime _ (Finset.mem_insert_of_mem hq) _ (Finset.mem_insert_of_mem hq')) #align unique_factorization_monoid.induction_on_prime_power UniqueFactorizationMonoid.induction_on_prime_power /-- If `P` holds for `0`, units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on all `a : α`. -/ @[elab_as_elim] theorem induction_on_coprime {P : α → Prop} (a : α) (h0 : P 0) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P a := by letI := Classical.decEq α have P_of_associated : ∀ {x y}, Associated x y → P x → P y := by rintro x y ⟨u, rfl⟩ hx exact hcp (fun p _ hpx => isUnit_of_dvd_unit hpx u.isUnit) hx (h1 u.isUnit) by_cases ha0 : a = 0 · rwa [ha0] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid refine P_of_associated (normalizedFactors_prod ha0) ?_ rw [← (normalizedFactors a).map_id, Finset.prod_multiset_map_count] refine induction_on_prime_power _ _ ?_ ?_ @h1 @hpr @hcp <;> simp only [Multiset.mem_toFinset] · apply prime_of_normalized_factor · apply normalizedFactors_eq_of_dvd #align unique_factorization_monoid.induction_on_coprime UniqueFactorizationMonoid.induction_on_coprime /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative on all products of primes. -/ -- @[elab_as_elim] Porting note: commented out theorem multiplicative_prime_power {f : α → β} (s : Finset α) (i j : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (∏ p ∈ s, p ^ (i p + j p)) = f (∏ p ∈ s, p ^ i p) * f (∏ p ∈ s, p ^ j p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p s hps ih · simpa using h1 isUnit_one have hpr_p := is_prime _ (Finset.mem_insert_self _ _) have hpr_s : ∀ p ∈ s, Prime p := fun p hp => is_prime _ (Finset.mem_insert_of_mem hp) have hcp_p := fun i => prime_pow_coprime_prod_of_coprime_insert i p hps is_prime is_coprime have hcp_s : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q := fun p hp q hq => is_coprime p (Finset.mem_insert_of_mem hp) q (Finset.mem_insert_of_mem hq) rw [Finset.prod_insert hps, Finset.prod_insert hps, Finset.prod_insert hps, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p (fun p => i p + j p)), hpr _ hpr_p, ih hpr_s hcp_s, pow_add, mul_assoc, mul_left_comm (f p ^ j p), mul_assoc] #align unique_factorization_monoid.multiplicative_prime_power UniqueFactorizationMonoid.multiplicative_prime_power /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative everywhere. -/ theorem multiplicative_of_coprime (f : α → β) (a b : α) (h0 : f 0 = 0) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (a * b) = f a * f b := by letI := Classical.decEq α by_cases ha0 : a = 0 · rw [ha0, zero_mul, h0, zero_mul] by_cases hb0 : b = 0 · rw [hb0, mul_zero, h0, mul_zero] by_cases hf1 : f 1 = 0 · calc f (a * b) = f (a * b * 1) := by rw [mul_one] _ = 0 := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f (b * 1) := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f b := by rw [mul_one] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid suffices f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ ((normalizedFactors a).count p + (normalizedFactors b).count p)) = f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors a).count p) * f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors b).count p) by obtain ⟨ua, a_eq⟩ := normalizedFactors_prod ha0 obtain ⟨ub, b_eq⟩ := normalizedFactors_prod hb0 rw [← a_eq, ← b_eq, mul_right_comm (Multiset.prod (normalizedFactors a)) ua (Multiset.prod (normalizedFactors b) * ub), h1 ua.isUnit, h1 ub.isUnit, h1 ua.isUnit, ← mul_assoc, h1 ub.isUnit, mul_right_comm _ (f ua), ← mul_assoc] congr rw [← (normalizedFactors a).map_id, ← (normalizedFactors b).map_id, Finset.prod_multiset_map_count, Finset.prod_multiset_map_count, Finset.prod_subset (Finset.subset_union_left (s₂:=(normalizedFactors b).toFinset)), Finset.prod_subset (Finset.subset_union_right (s₂:=(normalizedFactors b).toFinset)), ← Finset.prod_mul_distrib] · simp_rw [id, ← pow_add, this] all_goals simp only [Multiset.mem_toFinset] · intro p _ hpb simp [hpb] · intro p _ hpa simp [hpa] refine multiplicative_prime_power _ _ _ ?_ ?_ @h1 @hpr @hcp all_goals simp only [Multiset.mem_toFinset, Finset.mem_union] · rintro p (hpa | hpb) <;> apply prime_of_normalized_factor <;> assumption · rintro p (hp | hp) q (hq | hq) hdvd <;> rw [← normalize_normalized_factor _ hp, ← normalize_normalized_factor _ hq] <;> exact normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) #align unique_factorization_monoid.multiplicative_of_coprime UniqueFactorizationMonoid.multiplicative_of_coprime end Multiplicative end UniqueFactorizationMonoid namespace Associates open UniqueFactorizationMonoid Associated Multiset variable [CancelCommMonoidWithZero α] /-- `FactorSet α` representation elements of unique factorization domain as multisets. `Multiset α` produced by `normalizedFactors` are only unique up to associated elements, while the multisets in `FactorSet α` are unique by equality and restricted to irreducible elements. This gives us a representation of each element as a unique multisets (or the added ⊤ for 0), which has a complete lattice structure. Infimum is the greatest common divisor and supremum is the least common multiple. -/ abbrev FactorSet.{u} (α : Type u) [CancelCommMonoidWithZero α] : Type u := WithTop (Multiset { a : Associates α // Irreducible a }) #align associates.factor_set Associates.FactorSet attribute [local instance] Associated.setoid theorem FactorSet.coe_add {a b : Multiset { a : Associates α // Irreducible a }} : (↑(a + b) : FactorSet α) = a + b := by norm_cast #align associates.factor_set.coe_add Associates.FactorSet.coe_add theorem FactorSet.sup_add_inf_eq_add [DecidableEq (Associates α)] : ∀ a b : FactorSet α, a ⊔ b + a ⊓ b = a + b | ⊤, b => show ⊤ ⊔ b + ⊤ ⊓ b = ⊤ + b by simp | a, ⊤ => show a ⊔ ⊤ + a ⊓ ⊤ = a + ⊤ by simp | WithTop.some a, WithTop.some b => show (a : FactorSet α) ⊔ b + (a : FactorSet α) ⊓ b = a + b by rw [← WithTop.coe_sup, ← WithTop.coe_inf, ← WithTop.coe_add, ← WithTop.coe_add, WithTop.coe_eq_coe] exact Multiset.union_add_inter _ _ #align associates.factor_set.sup_add_inf_eq_add Associates.FactorSet.sup_add_inf_eq_add /-- Evaluates the product of a `FactorSet` to be the product of the corresponding multiset, or `0` if there is none. -/ def FactorSet.prod : FactorSet α → Associates α | ⊤ => 0 | WithTop.some s => (s.map (↑)).prod #align associates.factor_set.prod Associates.FactorSet.prod @[simp] theorem prod_top : (⊤ : FactorSet α).prod = 0 := rfl #align associates.prod_top Associates.prod_top @[simp] theorem prod_coe {s : Multiset { a : Associates α // Irreducible a }} : FactorSet.prod (s : FactorSet α) = (s.map (↑)).prod := rfl #align associates.prod_coe Associates.prod_coe @[simp] theorem prod_add : ∀ a b : FactorSet α, (a + b).prod = a.prod * b.prod | ⊤, b => show (⊤ + b).prod = (⊤ : FactorSet α).prod * b.prod by simp | a, ⊤ => show (a + ⊤).prod = a.prod * (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b => by rw [← FactorSet.coe_add, prod_coe, prod_coe, prod_coe, Multiset.map_add, Multiset.prod_add] #align associates.prod_add Associates.prod_add @[gcongr] theorem prod_mono : ∀ {a b : FactorSet α}, a ≤ b → a.prod ≤ b.prod | ⊤, b, h => by have : b = ⊤ := top_unique h rw [this, prod_top] | a, ⊤, _ => show a.prod ≤ (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b, h => prod_le_prod <| Multiset.map_le_map <| WithTop.coe_le_coe.1 <| h #align associates.prod_mono Associates.prod_mono theorem FactorSet.prod_eq_zero_iff [Nontrivial α] (p : FactorSet α) : p.prod = 0 ↔ p = ⊤ := by unfold FactorSet at p induction p -- TODO: `induction_eliminator` doesn't work with `abbrev` · simp only [iff_self_iff, eq_self_iff_true, Associates.prod_top] · rw [prod_coe, Multiset.prod_eq_zero_iff, Multiset.mem_map, eq_false WithTop.coe_ne_top, iff_false_iff, not_exists] exact fun a => not_and_of_not_right _ a.prop.ne_zero #align associates.factor_set.prod_eq_zero_iff Associates.FactorSet.prod_eq_zero_iff section count variable [DecidableEq (Associates α)] /-- `bcount p s` is the multiplicity of `p` in the FactorSet `s` (with bundled `p`)-/ def bcount (p : { a : Associates α // Irreducible a }) : FactorSet α → ℕ | ⊤ => 0 | WithTop.some s => s.count p #align associates.bcount Associates.bcount variable [∀ p : Associates α, Decidable (Irreducible p)] {p : Associates α} /-- `count p s` is the multiplicity of the irreducible `p` in the FactorSet `s`. If `p` is not irreducible, `count p s` is defined to be `0`. -/ def count (p : Associates α) : FactorSet α → ℕ := if hp : Irreducible p then bcount ⟨p, hp⟩ else 0 #align associates.count Associates.count @[simp] theorem count_some (hp : Irreducible p) (s : Multiset _) : count p (WithTop.some s) = s.count ⟨p, hp⟩ := by simp only [count, dif_pos hp, bcount] #align associates.count_some Associates.count_some @[simp] theorem count_zero (hp : Irreducible p) : count p (0 : FactorSet α) = 0 := by simp only [count, dif_pos hp, bcount, Multiset.count_zero] #align associates.count_zero Associates.count_zero theorem count_reducible (hp : ¬Irreducible p) : count p = 0 := dif_neg hp #align associates.count_reducible Associates.count_reducible end count section Mem /-- membership in a FactorSet (bundled version) -/ def BfactorSetMem : { a : Associates α // Irreducible a } → FactorSet α → Prop | _, ⊤ => True | p, some l => p ∈ l #align associates.bfactor_set_mem Associates.BfactorSetMem /-- `FactorSetMem p s` is the predicate that the irreducible `p` is a member of `s : FactorSet α`. If `p` is not irreducible, `p` is not a member of any `FactorSet`. -/ def FactorSetMem (p : Associates α) (s : FactorSet α) : Prop := letI : Decidable (Irreducible p) := Classical.dec _ if hp : Irreducible p then BfactorSetMem ⟨p, hp⟩ s else False #align associates.factor_set_mem Associates.FactorSetMem instance : Membership (Associates α) (FactorSet α) := ⟨FactorSetMem⟩ @[simp] theorem factorSetMem_eq_mem (p : Associates α) (s : FactorSet α) : FactorSetMem p s = (p ∈ s) := rfl #align associates.factor_set_mem_eq_mem Associates.factorSetMem_eq_mem theorem mem_factorSet_top {p : Associates α} {hp : Irreducible p} : p ∈ (⊤ : FactorSet α) := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; exact trivial #align associates.mem_factor_set_top Associates.mem_factorSet_top theorem mem_factorSet_some {p : Associates α} {hp : Irreducible p} {l : Multiset { a : Associates α // Irreducible a }} : p ∈ (l : FactorSet α) ↔ Subtype.mk p hp ∈ l := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; rfl #align associates.mem_factor_set_some Associates.mem_factorSet_some theorem reducible_not_mem_factorSet {p : Associates α} (hp : ¬Irreducible p) (s : FactorSet α) : ¬p ∈ s := fun h ↦ by rwa [← factorSetMem_eq_mem, FactorSetMem, dif_neg hp] at h #align associates.reducible_not_mem_factor_set Associates.reducible_not_mem_factorSet theorem irreducible_of_mem_factorSet {p : Associates α} {s : FactorSet α} (h : p ∈ s) : Irreducible p := by_contra fun hp ↦ reducible_not_mem_factorSet hp s h end Mem variable [UniqueFactorizationMonoid α] theorem unique' {p q : Multiset (Associates α)} : (∀ a ∈ p, Irreducible a) → (∀ a ∈ q, Irreducible a) → p.prod = q.prod → p = q := by apply Multiset.induction_on_multiset_quot p apply Multiset.induction_on_multiset_quot q intro s t hs ht eq refine Multiset.map_mk_eq_map_mk_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ ?_) · exact fun a ha => irreducible_mk.1 <| hs _ <| Multiset.mem_map_of_mem _ ha · exact fun a ha => irreducible_mk.1 <| ht _ <| Multiset.mem_map_of_mem _ ha have eq' : (Quot.mk Setoid.r : α → Associates α) = Associates.mk := funext quot_mk_eq_mk rwa [eq', prod_mk, prod_mk, mk_eq_mk_iff_associated] at eq #align associates.unique' Associates.unique' theorem FactorSet.unique [Nontrivial α] {p q : FactorSet α} (h : p.prod = q.prod) : p = q := by -- TODO: `induction_eliminator` doesn't work with `abbrev` unfold FactorSet at p q induction p <;> induction q · rfl · rw [eq_comm, ← FactorSet.prod_eq_zero_iff, ← h, Associates.prod_top] · rw [← FactorSet.prod_eq_zero_iff, h, Associates.prod_top] · congr 1 rw [← Multiset.map_eq_map Subtype.coe_injective] apply unique' _ _ h <;> · intro a ha obtain ⟨⟨a', irred⟩, -, rfl⟩ := Multiset.mem_map.mp ha rwa [Subtype.coe_mk] #align associates.factor_set.unique Associates.FactorSet.unique theorem prod_le_prod_iff_le [Nontrivial α] {p q : Multiset (Associates α)} (hp : ∀ a ∈ p, Irreducible a) (hq : ∀ a ∈ q, Irreducible a) : p.prod ≤ q.prod ↔ p ≤ q := by refine ⟨?_, prod_le_prod⟩ rintro ⟨c, eqc⟩ refine Multiset.le_iff_exists_add.2 ⟨factors c, unique' hq (fun x hx ↦ ?_) ?_⟩ · obtain h | h := Multiset.mem_add.1 hx · exact hp x h · exact irreducible_of_factor _ h · rw [eqc, Multiset.prod_add] congr refine associated_iff_eq.mp (factors_prod fun hc => ?_).symm refine not_irreducible_zero (hq _ ?_) rw [← prod_eq_zero_iff, eqc, hc, mul_zero] #align associates.prod_le_prod_iff_le Associates.prod_le_prod_iff_le /-- This returns the multiset of irreducible factors as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors' (a : α) : Multiset { a : Associates α // Irreducible a } := (factors a).pmap (fun a ha => ⟨Associates.mk a, irreducible_mk.2 ha⟩) irreducible_of_factor #align associates.factors' Associates.factors' @[simp] theorem map_subtype_coe_factors' {a : α} : (factors' a).map (↑) = (factors a).map Associates.mk := by simp [factors', Multiset.map_pmap, Multiset.pmap_eq_map] #align associates.map_subtype_coe_factors' Associates.map_subtype_coe_factors' theorem factors'_cong {a b : α} (h : a ~ᵤ b) : factors' a = factors' b := by obtain rfl | hb := eq_or_ne b 0 · rw [associated_zero_iff_eq_zero] at h rw [h] have ha : a ≠ 0 := by contrapose! hb with ha rw [← associated_zero_iff_eq_zero, ← ha] exact h.symm rw [← Multiset.map_eq_map Subtype.coe_injective, map_subtype_coe_factors', map_subtype_coe_factors', ← rel_associated_iff_map_eq_map] exact factors_unique irreducible_of_factor irreducible_of_factor ((factors_prod ha).trans <| h.trans <| (factors_prod hb).symm) #align associates.factors'_cong Associates.factors'_cong /-- This returns the multiset of irreducible factors of an associate as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors (a : Associates α) : FactorSet α := by classical refine if h : a = 0 then ⊤ else Quotient.hrecOn a (fun x _ => factors' x) ?_ h intro a b hab apply Function.hfunext · have : a ~ᵤ 0 ↔ b ~ᵤ 0 := Iff.intro (fun ha0 => hab.symm.trans ha0) fun hb0 => hab.trans hb0 simp only [associated_zero_iff_eq_zero] at this simp only [quotient_mk_eq_mk, this, mk_eq_zero] exact fun ha hb _ => heq_of_eq <| congr_arg some <| factors'_cong hab #align associates.factors Associates.factors @[simp] theorem factors_zero : (0 : Associates α).factors = ⊤ := dif_pos rfl #align associates.factors_0 Associates.factors_zero @[deprecated (since := "2024-03-16")] alias factors_0 := factors_zero @[simp] theorem factors_mk (a : α) (h : a ≠ 0) : (Associates.mk a).factors = factors' a := by classical apply dif_neg apply mt mk_eq_zero.1 h #align associates.factors_mk Associates.factors_mk @[simp] theorem factors_prod (a : Associates α) : a.factors.prod = a := by rcases Associates.mk_surjective a with ⟨a, rfl⟩ rcases eq_or_ne a 0 with rfl | ha · simp · simp [ha, prod_mk, mk_eq_mk_iff_associated, UniqueFactorizationMonoid.factors_prod, -Quotient.eq] #align associates.factors_prod Associates.factors_prod @[simp] theorem prod_factors [Nontrivial α] (s : FactorSet α) : s.prod.factors = s := FactorSet.unique <| factors_prod _ #align associates.prod_factors Associates.prod_factors @[nontriviality] theorem factors_subsingleton [Subsingleton α] {a : Associates α} : a.factors = ⊤ := by have : Subsingleton (Associates α) := inferInstance convert factors_zero #align associates.factors_subsingleton Associates.factors_subsingleton theorem factors_eq_top_iff_zero {a : Associates α} : a.factors = ⊤ ↔ a = 0 := by nontriviality α exact ⟨fun h ↦ by rwa [← factors_prod a, FactorSet.prod_eq_zero_iff], fun h ↦ h ▸ factors_zero⟩ #align associates.factors_eq_none_iff_zero Associates.factors_eq_top_iff_zero @[deprecated] alias factors_eq_none_iff_zero := factors_eq_top_iff_zero theorem factors_eq_some_iff_ne_zero {a : Associates α} : (∃ s : Multiset { p : Associates α // Irreducible p }, a.factors = s) ↔ a ≠ 0 := by simp_rw [@eq_comm _ a.factors, ← WithTop.ne_top_iff_exists] exact factors_eq_top_iff_zero.not #align associates.factors_eq_some_iff_ne_zero Associates.factors_eq_some_iff_ne_zero theorem eq_of_factors_eq_factors {a b : Associates α} (h : a.factors = b.factors) : a = b := by have : a.factors.prod = b.factors.prod := by rw [h] rwa [factors_prod, factors_prod] at this #align associates.eq_of_factors_eq_factors Associates.eq_of_factors_eq_factors theorem eq_of_prod_eq_prod [Nontrivial α] {a b : FactorSet α} (h : a.prod = b.prod) : a = b := by have : a.prod.factors = b.prod.factors := by rw [h] rwa [prod_factors, prod_factors] at this #align associates.eq_of_prod_eq_prod Associates.eq_of_prod_eq_prod @[simp] theorem factors_mul (a b : Associates α) : (a * b).factors = a.factors + b.factors := by nontriviality α refine eq_of_prod_eq_prod <| eq_of_factors_eq_factors ?_ rw [prod_add, factors_prod, factors_prod, factors_prod] #align associates.factors_mul Associates.factors_mul @[gcongr] theorem factors_mono : ∀ {a b : Associates α}, a ≤ b → a.factors ≤ b.factors | s, t, ⟨d, eq⟩ => by rw [eq, factors_mul]; exact le_add_of_nonneg_right bot_le #align associates.factors_mono Associates.factors_mono @[simp] theorem factors_le {a b : Associates α} : a.factors ≤ b.factors ↔ a ≤ b := by refine ⟨fun h ↦ ?_, factors_mono⟩ have : a.factors.prod ≤ b.factors.prod := prod_mono h rwa [factors_prod, factors_prod] at this #align associates.factors_le Associates.factors_le section count variable [DecidableEq (Associates α)] [∀ p : Associates α, Decidable (Irreducible p)] theorem eq_factors_of_eq_counts {a b : Associates α} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : Associates α, Irreducible p → p.count a.factors = p.count b.factors) : a.factors = b.factors := by obtain ⟨sa, h_sa⟩ := factors_eq_some_iff_ne_zero.mpr ha obtain ⟨sb, h_sb⟩ := factors_eq_some_iff_ne_zero.mpr hb rw [h_sa, h_sb] at h ⊢ rw [WithTop.coe_eq_coe] have h_count : ∀ (p : Associates α) (hp : Irreducible p), sa.count ⟨p, hp⟩ = sb.count ⟨p, hp⟩ := by intro p hp rw [← count_some, ← count_some, h p hp] apply Multiset.toFinsupp.injective ext ⟨p, hp⟩ rw [Multiset.toFinsupp_apply, Multiset.toFinsupp_apply, h_count p hp] #align associates.eq_factors_of_eq_counts Associates.eq_factors_of_eq_counts theorem eq_of_eq_counts {a b : Associates α} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : Associates α, Irreducible p → p.count a.factors = p.count b.factors) : a = b := eq_of_factors_eq_factors (eq_factors_of_eq_counts ha hb h) #align associates.eq_of_eq_counts Associates.eq_of_eq_counts theorem count_le_count_of_factors_le {a b p : Associates α} (hb : b ≠ 0) (hp : Irreducible p) (h : a.factors ≤ b.factors) : p.count a.factors ≤ p.count b.factors := by by_cases ha : a = 0 · simp_all obtain ⟨sa, h_sa⟩ := factors_eq_some_iff_ne_zero.mpr ha obtain ⟨sb, h_sb⟩ := factors_eq_some_iff_ne_zero.mpr hb rw [h_sa, h_sb] at h ⊢ rw [count_some hp, count_some hp]; rw [WithTop.coe_le_coe] at h exact Multiset.count_le_of_le _ h #align associates.count_le_count_of_factors_le Associates.count_le_count_of_factors_le theorem count_le_count_of_le {a b p : Associates α} (hb : b ≠ 0) (hp : Irreducible p) (h : a ≤ b) : p.count a.factors ≤ p.count b.factors := count_le_count_of_factors_le hb hp <| factors_mono h #align associates.count_le_count_of_le Associates.count_le_count_of_le end count theorem prod_le [Nontrivial α] {a b : FactorSet α} : a.prod ≤ b.prod ↔ a ≤ b := by refine ⟨fun h ↦ ?_, prod_mono⟩ have : a.prod.factors ≤ b.prod.factors := factors_mono h rwa [prod_factors, prod_factors] at this #align associates.prod_le Associates.prod_le open Classical in noncomputable instance : Sup (Associates α) := ⟨fun a b => (a.factors ⊔ b.factors).prod⟩ open Classical in noncomputable instance : Inf (Associates α) := ⟨fun a b => (a.factors ⊓ b.factors).prod⟩ open Classical in noncomputable instance : Lattice (Associates α) := { Associates.instPartialOrder with sup := (· ⊔ ·) inf := (· ⊓ ·) sup_le := fun _ _ c hac hbc => factors_prod c ▸ prod_mono (sup_le (factors_mono hac) (factors_mono hbc)) le_sup_left := fun a _ => le_trans (le_of_eq (factors_prod a).symm) <| prod_mono <| le_sup_left le_sup_right := fun _ b => le_trans (le_of_eq (factors_prod b).symm) <| prod_mono <| le_sup_right le_inf := fun a _ _ hac hbc => factors_prod a ▸ prod_mono (le_inf (factors_mono hac) (factors_mono hbc)) inf_le_left := fun a _ => le_trans (prod_mono inf_le_left) (le_of_eq (factors_prod a)) inf_le_right := fun _ b => le_trans (prod_mono inf_le_right) (le_of_eq (factors_prod b)) } open Classical in theorem sup_mul_inf (a b : Associates α) : (a ⊔ b) * (a ⊓ b) = a * b := show (a.factors ⊔ b.factors).prod * (a.factors ⊓ b.factors).prod = a * b by nontriviality α refine eq_of_factors_eq_factors ?_ rw [← prod_add, prod_factors, factors_mul, FactorSet.sup_add_inf_eq_add] #align associates.sup_mul_inf Associates.sup_mul_inf theorem dvd_of_mem_factors {a p : Associates α} (hm : p ∈ factors a) : p ∣ a := by rcases eq_or_ne a 0 with rfl | ha0 · exact dvd_zero p obtain ⟨a0, nza, ha'⟩ := exists_non_zero_rep ha0 rw [← Associates.factors_prod a] rw [← ha', factors_mk a0 nza] at hm ⊢ rw [prod_coe] apply Multiset.dvd_prod; apply Multiset.mem_map.mpr exact ⟨⟨p, irreducible_of_mem_factorSet hm⟩, mem_factorSet_some.mp hm, rfl⟩ #align associates.dvd_of_mem_factors Associates.dvd_of_mem_factors theorem dvd_of_mem_factors' {a : α} {p : Associates α} {hp : Irreducible p} {hz : a ≠ 0} (h_mem : Subtype.mk p hp ∈ factors' a) : p ∣ Associates.mk a := by haveI := Classical.decEq (Associates α) apply dvd_of_mem_factors rw [factors_mk _ hz] apply mem_factorSet_some.2 h_mem #align associates.dvd_of_mem_factors' Associates.dvd_of_mem_factors' theorem mem_factors'_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) (hd : p ∣ a) : Subtype.mk (Associates.mk p) (irreducible_mk.2 hp) ∈ factors' a := by obtain ⟨q, hq, hpq⟩ := exists_mem_factors_of_dvd ha0 hp hd apply Multiset.mem_pmap.mpr; use q; use hq exact Subtype.eq (Eq.symm (mk_eq_mk_iff_associated.mpr hpq)) #align associates.mem_factors'_of_dvd Associates.mem_factors'_of_dvd theorem mem_factors'_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : Subtype.mk (Associates.mk p) (irreducible_mk.2 hp) ∈ factors' a ↔ p ∣ a := by constructor · rw [← mk_dvd_mk] apply dvd_of_mem_factors' apply ha0 · apply mem_factors'_of_dvd ha0 hp #align associates.mem_factors'_iff_dvd Associates.mem_factors'_iff_dvd theorem mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) (hd : p ∣ a) : Associates.mk p ∈ factors (Associates.mk a) := by rw [factors_mk _ ha0] exact mem_factorSet_some.mpr (mem_factors'_of_dvd ha0 hp hd) #align associates.mem_factors_of_dvd Associates.mem_factors_of_dvd theorem mem_factors_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : Associates.mk p ∈ factors (Associates.mk a) ↔ p ∣ a := by constructor · rw [← mk_dvd_mk] apply dvd_of_mem_factors · apply mem_factors_of_dvd ha0 hp #align associates.mem_factors_iff_dvd Associates.mem_factors_iff_dvd open Classical in theorem exists_prime_dvd_of_not_inf_one {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) (h : Associates.mk a ⊓ Associates.mk b ≠ 1) : ∃ p : α, Prime p ∧ p ∣ a ∧ p ∣ b := by have hz : factors (Associates.mk a) ⊓ factors (Associates.mk b) ≠ 0 := by contrapose! h with hf change (factors (Associates.mk a) ⊓ factors (Associates.mk b)).prod = 1 rw [hf] exact Multiset.prod_zero rw [factors_mk a ha, factors_mk b hb, ← WithTop.coe_inf] at hz obtain ⟨⟨p0, p0_irr⟩, p0_mem⟩ := Multiset.exists_mem_of_ne_zero ((mt WithTop.coe_eq_coe.mpr) hz) rw [Multiset.inf_eq_inter] at p0_mem obtain ⟨p, rfl⟩ : ∃ p, Associates.mk p = p0 := Quot.exists_rep p0 refine ⟨p, ?_, ?_, ?_⟩ · rw [← UniqueFactorizationMonoid.irreducible_iff_prime, ← irreducible_mk] exact p0_irr · apply dvd_of_mk_le_mk apply dvd_of_mem_factors' (Multiset.mem_inter.mp p0_mem).left apply ha · apply dvd_of_mk_le_mk apply dvd_of_mem_factors' (Multiset.mem_inter.mp p0_mem).right apply hb #align associates.exists_prime_dvd_of_not_inf_one Associates.exists_prime_dvd_of_not_inf_one theorem coprime_iff_inf_one {a b : α} (ha0 : a ≠ 0) (hb0 : b ≠ 0) : Associates.mk a ⊓ Associates.mk b = 1 ↔ ∀ {d : α}, d ∣ a → d ∣ b → ¬Prime d := by constructor · intro hg p ha hb hp refine (Associates.prime_mk.mpr hp).not_unit (isUnit_of_dvd_one ?_) rw [← hg] exact le_inf (mk_le_mk_of_dvd ha) (mk_le_mk_of_dvd hb) · contrapose intro hg hc obtain ⟨p, hp, hpa, hpb⟩ := exists_prime_dvd_of_not_inf_one ha0 hb0 hg exact hc hpa hpb hp #align associates.coprime_iff_inf_one Associates.coprime_iff_inf_one theorem factors_self [Nontrivial α] {p : Associates α} (hp : Irreducible p) : p.factors = WithTop.some {⟨p, hp⟩} := eq_of_prod_eq_prod (by rw [factors_prod, FactorSet.prod]; dsimp; rw [prod_singleton]) #align associates.factors_self Associates.factors_self theorem factors_prime_pow [Nontrivial α] {p : Associates α} (hp : Irreducible p) (k : ℕ) : factors (p ^ k) = WithTop.some (Multiset.replicate k ⟨p, hp⟩) := eq_of_prod_eq_prod (by rw [Associates.factors_prod, FactorSet.prod] dsimp; rw [Multiset.map_replicate, Multiset.prod_replicate, Subtype.coe_mk]) #align associates.factors_prime_pow Associates.factors_prime_pow theorem prime_pow_le_iff_le_bcount [DecidableEq (Associates α)] {m p : Associates α} (h₁ : m ≠ 0) (h₂ : Irreducible p) {k : ℕ} : p ^ k ≤ m ↔ k ≤ bcount ⟨p, h₂⟩ m.factors := by rcases Associates.exists_non_zero_rep h₁ with ⟨m, hm, rfl⟩ have := nontrivial_of_ne _ _ hm rw [bcount, factors_mk, Multiset.le_count_iff_replicate_le, ← factors_le, factors_prime_pow, factors_mk, WithTop.coe_le_coe] <;> assumption section count variable [DecidableEq (Associates α)] [∀ p : Associates α, Decidable (Irreducible p)] theorem prime_pow_dvd_iff_le {m p : Associates α} (h₁ : m ≠ 0) (h₂ : Irreducible p) {k : ℕ} : p ^ k ≤ m ↔ k ≤ count p m.factors := by rw [count, dif_pos h₂, prime_pow_le_iff_le_bcount h₁] #align associates.prime_pow_dvd_iff_le Associates.prime_pow_dvd_iff_le theorem le_of_count_ne_zero {m p : Associates α} (h0 : m ≠ 0) (hp : Irreducible p) : count p m.factors ≠ 0 → p ≤ m := by nontriviality α rw [← pos_iff_ne_zero] intro h rw [← pow_one p] apply (prime_pow_dvd_iff_le h0 hp).2 simpa only #align associates.le_of_count_ne_zero Associates.le_of_count_ne_zero theorem count_ne_zero_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : (Associates.mk p).count (Associates.mk a).factors ≠ 0 ↔ p ∣ a := by nontriviality α rw [← Associates.mk_le_mk_iff_dvd] refine ⟨fun h => Associates.le_of_count_ne_zero (Associates.mk_ne_zero.mpr ha0) (Associates.irreducible_mk.mpr hp) h, fun h => ?_⟩ rw [← pow_one (Associates.mk p), Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero.mpr ha0) (Associates.irreducible_mk.mpr hp)] at h exact (zero_lt_one.trans_le h).ne' #align associates.count_ne_zero_iff_dvd Associates.count_ne_zero_iff_dvd theorem count_self [Nontrivial α] [DecidableEq (Associates α)] {p : Associates α} (hp : Irreducible p) : p.count p.factors = 1 := by simp [factors_self hp, Associates.count_some hp] #align associates.count_self Associates.count_self theorem count_eq_zero_of_ne [DecidableEq (Associates α)] {p q : Associates α} (hp : Irreducible p) (hq : Irreducible q) (h : p ≠ q) : p.count q.factors = 0 := not_ne_iff.mp fun h' ↦ h <| associated_iff_eq.mp <| hp.associated_of_dvd hq <| le_of_count_ne_zero hq.ne_zero hp h' #align associates.count_eq_zero_of_ne Associates.count_eq_zero_of_ne theorem count_mul [DecidableEq (Associates α)] {a : Associates α} (ha : a ≠ 0) {b : Associates α} (hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) : count p (factors (a * b)) = count p a.factors + count p b.factors := by obtain ⟨a0, nza, rfl⟩ := exists_non_zero_rep ha obtain ⟨b0, nzb, rfl⟩ := exists_non_zero_rep hb rw [factors_mul, factors_mk a0 nza, factors_mk b0 nzb, ← FactorSet.coe_add, count_some hp, Multiset.count_add, count_some hp, count_some hp] #align associates.count_mul Associates.count_mul theorem count_of_coprime [DecidableEq (Associates α)] {a : Associates α} (ha : a ≠ 0) {b : Associates α} (hb : b ≠ 0) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {p : Associates α} (hp : Irreducible p) : count p a.factors = 0 ∨ count p b.factors = 0 := by rw [or_iff_not_imp_left, ← Ne] intro hca contrapose! hab with hcb exact ⟨p, le_of_count_ne_zero ha hp hca, le_of_count_ne_zero hb hp hcb, UniqueFactorizationMonoid.irreducible_iff_prime.mp hp⟩ #align associates.count_of_coprime Associates.count_of_coprime theorem count_mul_of_coprime [DecidableEq (Associates α)] {a : Associates α} {b : Associates α} (hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) : count p a.factors = 0 ∨ count p a.factors = count p (a * b).factors := by by_cases ha : a = 0 · simp [ha] cases' count_of_coprime ha hb hab hp with hz hb0; · tauto apply Or.intro_right rw [count_mul ha hb hp, hb0, add_zero] #align associates.count_mul_of_coprime Associates.count_mul_of_coprime theorem count_mul_of_coprime' [DecidableEq (Associates α)] {a b : Associates α} {p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) : count p (a * b).factors = count p a.factors ∨ count p (a * b).factors = count p b.factors := by by_cases ha : a = 0 · simp [ha] by_cases hb : b = 0 · simp [hb] rw [count_mul ha hb hp] cases' count_of_coprime ha hb hab hp with ha0 hb0 · apply Or.intro_right rw [ha0, zero_add] · apply Or.intro_left rw [hb0, add_zero] #align associates.count_mul_of_coprime' Associates.count_mul_of_coprime' theorem dvd_count_of_dvd_count_mul [DecidableEq (Associates α)] {a b : Associates α} (hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {k : ℕ} (habk : k ∣ count p (a * b).factors) : k ∣ count p a.factors := by by_cases ha : a = 0 · simpa [*] using habk cases' count_of_coprime ha hb hab hp with hz h · rw [hz] exact dvd_zero k · rw [count_mul ha hb hp, h] at habk exact habk #align associates.dvd_count_of_dvd_count_mul Associates.dvd_count_of_dvd_count_mul @[simp] theorem factors_one [Nontrivial α] : factors (1 : Associates α) = 0 := by apply eq_of_prod_eq_prod rw [Associates.factors_prod] exact Multiset.prod_zero #align associates.factors_one Associates.factors_one @[simp] theorem pow_factors [Nontrivial α] {a : Associates α} {k : ℕ} : (a ^ k).factors = k • a.factors := by induction' k with n h · rw [zero_nsmul, pow_zero] exact factors_one · rw [pow_succ, succ_nsmul, factors_mul, h] #align associates.pow_factors Associates.pow_factors theorem count_pow [Nontrivial α] [DecidableEq (Associates α)] {a : Associates α} (ha : a ≠ 0) {p : Associates α} (hp : Irreducible p) (k : ℕ) : count p (a ^ k).factors = k * count p a.factors := by induction' k with n h · rw [pow_zero, factors_one, zero_mul, count_zero hp] · rw [pow_succ', count_mul ha (pow_ne_zero _ ha) hp, h] ring #align associates.count_pow Associates.count_pow theorem dvd_count_pow [Nontrivial α] [DecidableEq (Associates α)] {a : Associates α} (ha : a ≠ 0) {p : Associates α} (hp : Irreducible p) (k : ℕ) : k ∣ count p (a ^ k).factors := by rw [count_pow ha hp] apply dvd_mul_right #align associates.dvd_count_pow Associates.dvd_count_pow theorem is_pow_of_dvd_count [DecidableEq (Associates α)] {a : Associates α} (ha : a ≠ 0) {k : ℕ} (hk : ∀ p : Associates α, Irreducible p → k ∣ count p a.factors) : ∃ b : Associates α, a = b ^ k := by nontriviality α obtain ⟨a0, hz, rfl⟩ := exists_non_zero_rep ha rw [factors_mk a0 hz] at hk have hk' : ∀ p, p ∈ factors' a0 → k ∣ (factors' a0).count p := by rintro p - have pp : p = ⟨p.val, p.2⟩ := by simp only [Subtype.coe_eta] rw [pp, ← count_some p.2] exact hk p.val p.2 obtain ⟨u, hu⟩ := Multiset.exists_smul_of_dvd_count _ hk' use FactorSet.prod (u : FactorSet α) apply eq_of_factors_eq_factors rw [pow_factors, prod_factors, factors_mk a0 hz, hu] exact WithBot.coe_nsmul u k #align associates.is_pow_of_dvd_count Associates.is_pow_of_dvd_count /-- The only divisors of prime powers are prime powers. See `eq_pow_find_of_dvd_irreducible_pow` for an explicit expression as a p-power (without using `count`). -/ theorem eq_pow_count_factors_of_dvd_pow [DecidableEq (Associates α)] {p a : Associates α} (hp : Irreducible p) {n : ℕ} (h : a ∣ p ^ n) : a = p ^ p.count a.factors := by nontriviality α have hph := pow_ne_zero n hp.ne_zero have ha := ne_zero_of_dvd_ne_zero hph h apply eq_of_eq_counts ha (pow_ne_zero _ hp.ne_zero) have eq_zero_of_ne : ∀ q : Associates α, Irreducible q → q ≠ p → _ = 0 := fun q hq h' => Nat.eq_zero_of_le_zero <| by convert count_le_count_of_le hph hq h symm rw [count_pow hp.ne_zero hq, count_eq_zero_of_ne hq hp h', mul_zero] intro q hq rw [count_pow hp.ne_zero hq] by_cases h : q = p · rw [h, count_self hp, mul_one] · rw [count_eq_zero_of_ne hq hp h, mul_zero, eq_zero_of_ne q hq h] #align associates.eq_pow_count_factors_of_dvd_pow Associates.eq_pow_count_factors_of_dvd_pow theorem count_factors_eq_find_of_dvd_pow [DecidableEq (Associates α)] {a p : Associates α} (hp : Irreducible p) [∀ n : ℕ, Decidable (a ∣ p ^ n)] {n : ℕ} (h : a ∣ p ^ n) : @Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩ = p.count a.factors := by apply le_antisymm · refine Nat.find_le ⟨1, ?_⟩ rw [mul_one] symm exact eq_pow_count_factors_of_dvd_pow hp h · have hph := pow_ne_zero (@Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩) hp.ne_zero cases' subsingleton_or_nontrivial α with hα hα · simp [eq_iff_true_of_subsingleton] at hph convert count_le_count_of_le hph hp (@Nat.find_spec (fun n => a ∣ p ^ n) _ ⟨n, h⟩) rw [count_pow hp.ne_zero hp, count_self hp, mul_one] #align associates.count_factors_eq_find_of_dvd_pow Associates.count_factors_eq_find_of_dvd_pow end count theorem eq_pow_of_mul_eq_pow {a b c : Associates α} (ha : a ≠ 0) (hb : b ≠ 0) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {k : ℕ} (h : a * b = c ^ k) : ∃ d : Associates α, a = d ^ k := by classical nontriviality α by_cases hk0 : k = 0 · use 1 rw [hk0, pow_zero] at h ⊢ apply (mul_eq_one_iff.1 h).1 · refine is_pow_of_dvd_count ha fun p hp ↦ ?_ apply dvd_count_of_dvd_count_mul hb hp hab rw [h] apply dvd_count_pow _ hp rintro rfl rw [zero_pow hk0] at h cases mul_eq_zero.mp h <;> contradiction #align associates.eq_pow_of_mul_eq_pow Associates.eq_pow_of_mul_eq_pow /-- The only divisors of prime powers are prime powers. -/ theorem eq_pow_find_of_dvd_irreducible_pow {a p : Associates α} (hp : Irreducible p) [∀ n : ℕ, Decidable (a ∣ p ^ n)] {n : ℕ} (h : a ∣ p ^ n) : a = p ^ @Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩ := by classical rw [count_factors_eq_find_of_dvd_pow hp, ← eq_pow_count_factors_of_dvd_pow hp h] exact h #align associates.eq_pow_find_of_dvd_irreducible_pow Associates.eq_pow_find_of_dvd_irreducible_pow end Associates section open Associates UniqueFactorizationMonoid /-- `toGCDMonoid` constructs a GCD monoid out of a unique factorization domain. -/ noncomputable def UniqueFactorizationMonoid.toGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : GCDMonoid α where gcd a b := Quot.out (Associates.mk a ⊓ Associates.mk b : Associates α) lcm a b := Quot.out (Associates.mk a ⊔ Associates.mk b : Associates α) gcd_dvd_left a b := by rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le] exact inf_le_left gcd_dvd_right a b := by rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le] exact inf_le_right dvd_gcd {a b c} hac hab := by rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le, le_inf_iff, mk_le_mk_iff_dvd, mk_le_mk_iff_dvd] exact ⟨hac, hab⟩ lcm_zero_left a := by simp lcm_zero_right a := by simp gcd_mul_lcm a b := by rw [← mk_eq_mk_iff_associated, ← Associates.mk_mul_mk, ← associated_iff_eq, Associates.quot_out, Associates.quot_out, mul_comm, sup_mul_inf, Associates.mk_mul_mk] #align unique_factorization_monoid.to_gcd_monoid UniqueFactorizationMonoid.toGCDMonoid /-- `toNormalizedGCDMonoid` constructs a GCD monoid out of a normalization on a unique factorization domain. -/ noncomputable def UniqueFactorizationMonoid.toNormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] [NormalizationMonoid α] : NormalizedGCDMonoid α := { ‹NormalizationMonoid α› with gcd := fun a b => (Associates.mk a ⊓ Associates.mk b).out lcm := fun a b => (Associates.mk a ⊔ Associates.mk b).out gcd_dvd_left := fun a b => (out_dvd_iff a (Associates.mk a ⊓ Associates.mk b)).2 <| inf_le_left gcd_dvd_right := fun a b => (out_dvd_iff b (Associates.mk a ⊓ Associates.mk b)).2 <| inf_le_right dvd_gcd := fun {a} {b} {c} hac hab => show a ∣ (Associates.mk c ⊓ Associates.mk b).out by rw [dvd_out_iff, le_inf_iff, mk_le_mk_iff_dvd, mk_le_mk_iff_dvd] exact ⟨hac, hab⟩ lcm_zero_left := fun a => show (⊤ ⊔ Associates.mk a).out = 0 by simp lcm_zero_right := fun a => show (Associates.mk a ⊔ ⊤).out = 0 by simp gcd_mul_lcm := fun a b => by rw [← out_mul, mul_comm, sup_mul_inf, mk_mul_mk, out_mk] exact normalize_associated (a * b) normalize_gcd := fun a b => by apply normalize_out _ normalize_lcm := fun a b => by apply normalize_out _ } #align unique_factorization_monoid.to_normalized_gcd_monoid UniqueFactorizationMonoid.toNormalizedGCDMonoid instance (α) [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : Nonempty (NormalizedGCDMonoid α) := by letI := UniqueFactorizationMonoid.normalizationMonoid (α := α) classical exact ⟨UniqueFactorizationMonoid.toNormalizedGCDMonoid α⟩ end namespace UniqueFactorizationMonoid /-- If `y` is a nonzero element of a unique factorization monoid with finitely many units (e.g. `ℤ`, `Ideal (ring_of_integers K)`), it has finitely many divisors. -/ noncomputable def fintypeSubtypeDvd {M : Type*} [CancelCommMonoidWithZero M] [UniqueFactorizationMonoid M] [Fintype Mˣ] (y : M) (hy : y ≠ 0) : Fintype { x // x ∣ y } := by haveI : Nontrivial M := ⟨⟨y, 0, hy⟩⟩ haveI : NormalizationMonoid M := UniqueFactorizationMonoid.normalizationMonoid haveI := Classical.decEq M haveI := Classical.decEq (Associates M) -- We'll show `λ (u : Mˣ) (f ⊆ factors y) → u * Π f` is injective -- and has image exactly the divisors of `y`. refine Fintype.ofFinset (((normalizedFactors y).powerset.toFinset ×ˢ (Finset.univ : Finset Mˣ)).image fun s => (s.snd : M) * s.fst.prod) fun x => ?_ simp only [exists_prop, Finset.mem_image, Finset.mem_product, Finset.mem_univ, and_true_iff, Multiset.mem_toFinset, Multiset.mem_powerset, exists_eq_right, Multiset.mem_map] constructor · rintro ⟨s, hs, rfl⟩ show (s.snd : M) * s.fst.prod ∣ y rw [(unit_associated_one.mul_right s.fst.prod).dvd_iff_dvd_left, one_mul, ← (normalizedFactors_prod hy).dvd_iff_dvd_right] exact Multiset.prod_dvd_prod_of_le hs · rintro (h : x ∣ y) have hx : x ≠ 0 := by refine mt (fun hx => ?_) hy rwa [hx, zero_dvd_iff] at h obtain ⟨u, hu⟩ := normalizedFactors_prod hx refine ⟨⟨normalizedFactors x, u⟩, ?_, (mul_comm _ _).trans hu⟩ exact (dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mp h #align unique_factorization_monoid.fintype_subtype_dvd UniqueFactorizationMonoid.fintypeSubtypeDvd end UniqueFactorizationMonoid section Finsupp variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] variable [NormalizationMonoid α] [DecidableEq α] open UniqueFactorizationMonoid /-- This returns the multiset of irreducible factors as a `Finsupp`. -/ noncomputable def factorization (n : α) : α →₀ ℕ := Multiset.toFinsupp (normalizedFactors n) #align factorization factorization theorem factorization_eq_count {n p : α} : factorization n p = Multiset.count p (normalizedFactors n) := by simp [factorization] #align factorization_eq_count factorization_eq_count @[simp] theorem factorization_zero : factorization (0 : α) = 0 := by simp [factorization] #align factorization_zero factorization_zero @[simp] theorem factorization_one : factorization (1 : α) = 0 := by simp [factorization] #align factorization_one factorization_one /-- The support of `factorization n` is exactly the Finset of normalized factors -/ @[simp] theorem support_factorization {n : α} : (factorization n).support = (normalizedFactors n).toFinset := by simp [factorization, Multiset.toFinsupp_support] #align support_factorization support_factorization /-- 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) : factorization (a * b) = factorization a + factorization b := by simp [factorization, normalizedFactors_mul ha hb] #align factorization_mul factorization_mul /-- For any `p`, the power of `p` in `x^n` is `n` times the power in `x` -/ theorem factorization_pow {x : α} {n : ℕ} : factorization (x ^ n) = n • factorization x := by ext simp [factorization] #align factorization_pow factorization_pow theorem associated_of_factorization_eq (a b : α) (ha : a ≠ 0) (hb : b ≠ 0) (h : factorization a = factorization b) : Associated a b := by simp_rw [factorization, AddEquiv.apply_eq_iff_eq] at h rwa [associated_iff_normalizedFactors_eq_normalizedFactors ha hb] #align associated_of_factorization_eq associated_of_factorization_eq end Finsupp open UniqueFactorizationMonoid in /-- Every non-zero prime ideal in a unique factorization domain contains a prime element. -/
Mathlib/RingTheory/UniqueFactorizationDomain.lean
2,085
2,095
theorem Ideal.IsPrime.exists_mem_prime_of_ne_bot {R : Type*} [CommSemiring R] [IsDomain R] [UniqueFactorizationMonoid R] {I : Ideal R} (hI₂ : I.IsPrime) (hI : I ≠ ⊥) : ∃ x ∈ I, Prime x := by
classical obtain ⟨a : R, ha₁ : a ∈ I, ha₂ : a ≠ 0⟩ := Submodule.exists_mem_ne_zero_of_ne_bot hI replace ha₁ : (factors a).prod ∈ I := by obtain ⟨u : Rˣ, hu : (factors a).prod * u = a⟩ := factors_prod ha₂ rwa [← hu, mul_unit_mem_iff_mem _ u.isUnit] at ha₁ obtain ⟨p : R, hp₁ : p ∈ factors a, hp₂ : p ∈ I⟩ := (hI₂.multiset_prod_mem_iff_exists_mem <| factors a).1 ha₁ exact ⟨p, hp₂, prime_of_factor p hp₁⟩
/- 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** -/ 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 #align cardinal.cantor Cardinal.cantor instance : NoMaxOrder Cardinal.{u} where exists_gt a := ⟨_, cantor a⟩ -- short-circuit type class inference instance : DistribLattice Cardinal.{u} := inferInstance theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not] #align cardinal.one_lt_iff_nontrivial Cardinal.one_lt_iff_nontrivial theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 := by by_cases ha : a = 0 · simp [ha, zero_power_le] · exact (power_le_power_left ha h).trans (le_max_left _ _) #align cardinal.power_le_max_power_one Cardinal.power_le_max_power_one theorem power_le_power_right {a b c : Cardinal} : a ≤ b → a ^ c ≤ b ^ c := inductionOn₃ a b c fun _ _ _ ⟨e⟩ => ⟨Embedding.arrowCongrRight e⟩ #align cardinal.power_le_power_right Cardinal.power_le_power_right theorem power_pos {a : Cardinal} (b : Cardinal) (ha : 0 < a) : 0 < a ^ b := (power_ne_zero _ ha.ne').bot_lt #align cardinal.power_pos Cardinal.power_pos end OrderProperties protected theorem lt_wf : @WellFounded Cardinal.{u} (· < ·) := ⟨fun a => by_contradiction fun h => by let ι := { c : Cardinal // ¬Acc (· < ·) c } let f : ι → Cardinal := Subtype.val haveI hι : Nonempty ι := ⟨⟨_, h⟩⟩ obtain ⟨⟨c : Cardinal, hc : ¬Acc (· < ·) c⟩, ⟨h_1 : ∀ j, (f ⟨c, hc⟩).out ↪ (f j).out⟩⟩ := Embedding.min_injective fun i => (f i).out refine hc (Acc.intro _ fun j h' => by_contradiction fun hj => h'.2 ?_) have : #_ ≤ #_ := ⟨h_1 ⟨j, hj⟩⟩ simpa only [mk_out] using this⟩ #align cardinal.lt_wf Cardinal.lt_wf instance : WellFoundedRelation Cardinal.{u} := ⟨(· < ·), Cardinal.lt_wf⟩ -- Porting note: this no longer is automatically inferred. instance : WellFoundedLT Cardinal.{u} := ⟨Cardinal.lt_wf⟩ instance wo : @IsWellOrder Cardinal.{u} (· < ·) where #align cardinal.wo Cardinal.wo instance : ConditionallyCompleteLinearOrderBot Cardinal := IsWellOrder.conditionallyCompleteLinearOrderBot _ @[simp] theorem sInf_empty : sInf (∅ : Set Cardinal.{u}) = 0 := dif_neg Set.not_nonempty_empty #align cardinal.Inf_empty Cardinal.sInf_empty lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases s.eq_empty_or_nonempty with rfl | hne · exact Or.inl rfl · exact Or.inr ⟨sInf s, csInf_mem hne, h⟩ · rcases h with rfl | ⟨a, ha, rfl⟩ · exact Cardinal.sInf_empty · exact eq_bot_iff.2 (csInf_le' ha) lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} : (⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by simp [iInf, sInf_eq_zero_iff] /-- Note that the successor of `c` is not the same as `c + 1` except in the case of finite `c`. -/ instance : SuccOrder Cardinal := SuccOrder.ofSuccLeIff (fun c => sInf { c' | c < c' }) -- Porting note: Needed to insert `by apply` in the next line ⟨by apply lt_of_lt_of_le <| csInf_mem <| exists_gt _, -- Porting note used to be just `csInf_le'` fun h ↦ csInf_le' h⟩ theorem succ_def (c : Cardinal) : succ c = sInf { c' | c < c' } := rfl #align cardinal.succ_def Cardinal.succ_def theorem succ_pos : ∀ c : Cardinal, 0 < succ c := bot_lt_succ #align cardinal.succ_pos Cardinal.succ_pos theorem succ_ne_zero (c : Cardinal) : succ c ≠ 0 := (succ_pos _).ne' #align cardinal.succ_ne_zero Cardinal.succ_ne_zero theorem add_one_le_succ (c : Cardinal.{u}) : c + 1 ≤ succ c := by -- Porting note: rewrote the next three lines to avoid defeq abuse. have : Set.Nonempty { c' | c < c' } := exists_gt c simp_rw [succ_def, le_csInf_iff'' this, mem_setOf] intro b hlt rcases b, c with ⟨⟨β⟩, ⟨γ⟩⟩ cases' le_of_lt hlt with f have : ¬Surjective f := fun hn => (not_le_of_lt hlt) (mk_le_of_surjective hn) simp only [Surjective, not_forall] at this rcases this with ⟨b, hb⟩ calc #γ + 1 = #(Option γ) := mk_option.symm _ ≤ #β := (f.optionElim b hb).cardinal_le #align cardinal.add_one_le_succ Cardinal.add_one_le_succ /-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ℵ₀` is a limit cardinal by this definition, but `0` isn't. Use `IsSuccLimit` if you want to include the `c = 0` case. -/ def IsLimit (c : Cardinal) : Prop := c ≠ 0 ∧ IsSuccLimit c #align cardinal.is_limit Cardinal.IsLimit protected theorem IsLimit.ne_zero {c} (h : IsLimit c) : c ≠ 0 := h.1 #align cardinal.is_limit.ne_zero Cardinal.IsLimit.ne_zero protected theorem IsLimit.isSuccLimit {c} (h : IsLimit c) : IsSuccLimit c := h.2 #align cardinal.is_limit.is_succ_limit Cardinal.IsLimit.isSuccLimit theorem IsLimit.succ_lt {x c} (h : IsLimit c) : x < c → succ x < c := h.isSuccLimit.succ_lt #align cardinal.is_limit.succ_lt Cardinal.IsLimit.succ_lt theorem isSuccLimit_zero : IsSuccLimit (0 : Cardinal) := isSuccLimit_bot #align cardinal.is_succ_limit_zero Cardinal.isSuccLimit_zero /-- The indexed sum of cardinals is the cardinality of the indexed disjoint union, i.e. sigma type. -/ def sum {ι} (f : ι → Cardinal) : Cardinal := mk (Σi, (f i).out) #align cardinal.sum Cardinal.sum theorem le_sum {ι} (f : ι → Cardinal) (i) : f i ≤ sum f := by rw [← Quotient.out_eq (f i)] exact ⟨⟨fun a => ⟨i, a⟩, fun a b h => by injection h⟩⟩ #align cardinal.le_sum Cardinal.le_sum @[simp] theorem mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum fun i => #(f i) := mk_congr <| Equiv.sigmaCongrRight fun _ => outMkEquiv.symm #align cardinal.mk_sigma Cardinal.mk_sigma @[simp] theorem sum_const (ι : Type u) (a : Cardinal.{v}) : (sum fun _ : ι => a) = lift.{v} #ι * lift.{u} a := inductionOn a fun α => mk_congr <| calc (Σ _ : ι, Quotient.out #α) ≃ ι × Quotient.out #α := Equiv.sigmaEquivProd _ _ _ ≃ ULift ι × ULift α := Equiv.ulift.symm.prodCongr (outMkEquiv.trans Equiv.ulift.symm) #align cardinal.sum_const Cardinal.sum_const theorem sum_const' (ι : Type u) (a : Cardinal.{u}) : (sum fun _ : ι => a) = #ι * a := by simp #align cardinal.sum_const' Cardinal.sum_const' @[simp] theorem sum_add_distrib {ι} (f g : ι → Cardinal) : sum (f + g) = sum f + sum g := by have := mk_congr (Equiv.sigmaSumDistrib (Quotient.out ∘ f) (Quotient.out ∘ g)) simp only [comp_apply, mk_sigma, mk_sum, mk_out, lift_id] at this exact this #align cardinal.sum_add_distrib Cardinal.sum_add_distrib @[simp] theorem sum_add_distrib' {ι} (f g : ι → Cardinal) : (Cardinal.sum fun i => f i + g i) = sum f + sum g := sum_add_distrib f g #align cardinal.sum_add_distrib' Cardinal.sum_add_distrib' @[simp] theorem lift_sum {ι : Type u} (f : ι → Cardinal.{v}) : Cardinal.lift.{w} (Cardinal.sum f) = Cardinal.sum fun i => Cardinal.lift.{w} (f i) := Equiv.cardinal_eq <| Equiv.ulift.trans <| Equiv.sigmaCongrRight fun a => -- Porting note: Inserted universe hint .{_,_,v} below Nonempty.some <| by rw [← lift_mk_eq.{_,_,v}, mk_out, mk_out, lift_lift] #align cardinal.lift_sum Cardinal.lift_sum theorem sum_le_sum {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g := ⟨(Embedding.refl _).sigmaMap fun i => Classical.choice <| by have := H i; rwa [← Quot.out_eq (f i), ← Quot.out_eq (g i)] at this⟩ #align cardinal.sum_le_sum Cardinal.sum_le_sum theorem mk_le_mk_mul_of_mk_preimage_le {c : Cardinal} (f : α → β) (hf : ∀ b : β, #(f ⁻¹' {b}) ≤ c) : #α ≤ #β * c := by simpa only [← mk_congr (@Equiv.sigmaFiberEquiv α β f), mk_sigma, ← sum_const'] using sum_le_sum _ _ hf #align cardinal.mk_le_mk_mul_of_mk_preimage_le Cardinal.mk_le_mk_mul_of_mk_preimage_le theorem lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le {α : Type u} {β : Type v} {c : Cardinal} (f : α → β) (hf : ∀ b : β, lift.{v} #(f ⁻¹' {b}) ≤ c) : lift.{v} #α ≤ lift.{u} #β * c := (mk_le_mk_mul_of_mk_preimage_le fun x : ULift.{v} α => ULift.up.{u} (f x.1)) <| ULift.forall.2 fun b => (mk_congr <| (Equiv.ulift.image _).trans (Equiv.trans (by rw [Equiv.image_eq_preimage] /- Porting note: Need to insert the following `have` b/c bad fun coercion behaviour for Equivs -/ have : DFunLike.coe (Equiv.symm (Equiv.ulift (α := α))) = ULift.up (α := α) := rfl rw [this] simp only [preimage, mem_singleton_iff, ULift.up_inj, mem_setOf_eq, coe_setOf] exact Equiv.refl _) Equiv.ulift.symm)).trans_le (hf b) #align cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le Cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le /-- The range of an indexed cardinal function, whose outputs live in a higher universe than the inputs, is always bounded above. -/ theorem bddAbove_range {ι : Type u} (f : ι → Cardinal.{max u v}) : BddAbove (Set.range f) := ⟨_, by rintro a ⟨i, rfl⟩ -- Porting note: Added universe reference below exact le_sum.{v,u} f i⟩ #align cardinal.bdd_above_range Cardinal.bddAbove_range instance (a : Cardinal.{u}) : Small.{u} (Set.Iic a) := by rw [← mk_out a] apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩ rintro ⟨x, hx⟩ simpa using le_mk_iff_exists_set.1 hx instance (a : Cardinal.{u}) : Small.{u} (Set.Iio a) := small_subset Iio_subset_Iic_self /-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/ theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun x h => ha h) _, by rintro ⟨ι, ⟨e⟩⟩ suffices (range fun x : ι => (e.symm x).1) = s by rw [← this] apply bddAbove_range.{u, u} ext x refine ⟨?_, fun hx => ⟨e ⟨x, hx⟩, ?_⟩⟩ · rintro ⟨a, rfl⟩ exact (e.symm a).2 · simp_rw [Equiv.symm_apply_apply]⟩ #align cardinal.bdd_above_iff_small Cardinal.bddAbove_iff_small theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h #align cardinal.bdd_above_of_small Cardinal.bddAbove_of_small theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}} (hs : BddAbove s) : BddAbove (f '' s) := by rw [bddAbove_iff_small] at hs ⊢ -- Porting note: added universes below exact small_lift.{_,v,_} _ #align cardinal.bdd_above_image Cardinal.bddAbove_image theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f)) (g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by rw [range_comp] exact bddAbove_image.{v,w} g hf #align cardinal.bdd_above_range_comp Cardinal.bddAbove_range_comp theorem iSup_le_sum {ι} (f : ι → Cardinal) : iSup f ≤ sum f := ciSup_le' <| le_sum.{u_2,u_1} _ #align cardinal.supr_le_sum Cardinal.iSup_le_sum -- Porting note: Added universe hint .{v,_} below theorem sum_le_iSup_lift {ι : Type u} (f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift.{v,_} #ι * iSup f := by rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const] exact sum_le_sum _ _ (le_ciSup <| bddAbove_range.{u, v} f) #align cardinal.sum_le_supr_lift Cardinal.sum_le_iSup_lift theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by rw [← lift_id #ι] exact sum_le_iSup_lift f #align cardinal.sum_le_supr Cardinal.sum_le_iSup theorem sum_nat_eq_add_sum_succ (f : ℕ → Cardinal.{u}) : Cardinal.sum f = f 0 + Cardinal.sum fun i => f (i + 1) := by refine (Equiv.sigmaNatSucc fun i => Quotient.out (f i)).cardinal_eq.trans ?_ simp only [mk_sum, mk_out, lift_id, mk_sigma] #align cardinal.sum_nat_eq_add_sum_succ Cardinal.sum_nat_eq_add_sum_succ -- Porting note: LFS is not in normal form. -- @[simp] /-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/ protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 := ciSup_of_empty f #align cardinal.supr_of_empty Cardinal.iSup_of_empty lemma exists_eq_of_iSup_eq_of_not_isSuccLimit {ι : Type u} (f : ι → Cardinal.{v}) (ω : Cardinal.{v}) (hω : ¬ Order.IsSuccLimit ω) (h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by subst h refine (isLUB_csSup' ?_).exists_of_not_isSuccLimit hω contrapose! hω with hf rw [iSup, csSup_of_not_bddAbove hf, csSup_empty] exact Order.isSuccLimit_bot lemma exists_eq_of_iSup_eq_of_not_isLimit {ι : Type u} [hι : Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (ω : Cardinal.{v}) (hω : ¬ ω.IsLimit) (h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by refine (not_and_or.mp hω).elim (fun e ↦ ⟨hι.some, ?_⟩) (Cardinal.exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f ω · h) cases not_not.mp e rw [← le_zero_iff] at h ⊢ exact (le_ciSup hf _).trans h -- Porting note: simpNF is not happy with universe levels. @[simp, nolint simpNF] theorem lift_mk_shrink (α : Type u) [Small.{v} α] : Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α := -- Porting note: Added .{v,u,w} universe hint below lift_mk_eq.{v,u,w}.2 ⟨(equivShrink α).symm⟩ #align cardinal.lift_mk_shrink Cardinal.lift_mk_shrink @[simp] theorem lift_mk_shrink' (α : Type u) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α := lift_mk_shrink.{u, v, 0} α #align cardinal.lift_mk_shrink' Cardinal.lift_mk_shrink' @[simp] theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = #α := by rw [← lift_umax', lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id] #align cardinal.lift_mk_shrink'' Cardinal.lift_mk_shrink'' /-- The indexed product of cardinals is the cardinality of the Pi type (dependent product). -/ def prod {ι : Type u} (f : ι → Cardinal) : Cardinal := #(∀ i, (f i).out) #align cardinal.prod Cardinal.prod @[simp] theorem mk_pi {ι : Type u} (α : ι → Type v) : #(∀ i, α i) = prod fun i => #(α i) := mk_congr <| Equiv.piCongrRight fun _ => outMkEquiv.symm #align cardinal.mk_pi Cardinal.mk_pi @[simp] theorem prod_const (ι : Type u) (a : Cardinal.{v}) : (prod fun _ : ι => a) = lift.{u} a ^ lift.{v} #ι := inductionOn a fun _ => mk_congr <| Equiv.piCongr Equiv.ulift.symm fun _ => outMkEquiv.trans Equiv.ulift.symm #align cardinal.prod_const Cardinal.prod_const theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = a ^ #ι := inductionOn a fun _ => (mk_pi _).symm #align cardinal.prod_const' Cardinal.prod_const' theorem prod_le_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g := ⟨Embedding.piCongrRight fun i => Classical.choice <| by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩ #align cardinal.prod_le_prod Cardinal.prod_le_prod @[simp] theorem prod_eq_zero {ι} (f : ι → Cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 := by lift f to ι → Type u using fun _ => trivial simp only [mk_eq_zero_iff, ← mk_pi, isEmpty_pi] #align cardinal.prod_eq_zero Cardinal.prod_eq_zero theorem prod_ne_zero {ι} (f : ι → Cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 := by simp [prod_eq_zero] #align cardinal.prod_ne_zero Cardinal.prod_ne_zero @[simp] theorem lift_prod {ι : Type u} (c : ι → Cardinal.{v}) : lift.{w} (prod c) = prod fun i => lift.{w} (c i) := by lift c to ι → Type v using fun _ => trivial simp only [← mk_pi, ← mk_uLift] exact mk_congr (Equiv.ulift.trans <| Equiv.piCongrRight fun i => Equiv.ulift.symm) #align cardinal.lift_prod Cardinal.lift_prod theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) : prod f = Cardinal.lift.{u} (∏ i, f i) := by revert f refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h) · intro α β hβ e h f letI := Fintype.ofEquiv β e.symm rw [← e.prod_comp f, ← h] exact mk_congr (e.piCongrLeft _).symm · intro f rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one] · intro α hα h f rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax'.{v, u}, mk_out, ← Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)] simp only [lift_id] #align cardinal.prod_eq_of_fintype Cardinal.prod_eq_of_fintype -- Porting note: Inserted .{u,v} below @[simp] theorem lift_sInf (s : Set Cardinal) : lift.{u,v} (sInf s) = sInf (lift.{u,v} '' s) := by rcases eq_empty_or_nonempty s with (rfl | hs) · simp · exact lift_monotone.map_csInf hs #align cardinal.lift_Inf Cardinal.lift_sInf -- Porting note: Inserted .{u,v} below @[simp] theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u,v} (iInf f) = ⨅ i, lift.{u,v} (f i) := by unfold iInf convert lift_sInf (range f) simp_rw [← comp_apply (f := lift), range_comp] #align cardinal.lift_infi Cardinal.lift_iInf theorem lift_down {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b ≤ lift.{v,u} a → ∃ a', lift.{v,u} a' = b := inductionOn₂ a b fun α β => by rw [← lift_id #β, ← lift_umax, ← lift_umax.{u, v}, lift_mk_le.{v}] exact fun ⟨f⟩ => ⟨#(Set.range f), Eq.symm <| lift_mk_eq.{_, _, v}.2 ⟨Function.Embedding.equivOfSurjective (Embedding.codRestrict _ f Set.mem_range_self) fun ⟨a, ⟨b, e⟩⟩ => ⟨b, Subtype.eq e⟩⟩⟩ #align cardinal.lift_down Cardinal.lift_down -- Porting note: Inserted .{u,v} below theorem le_lift_iff {a : Cardinal.{u}} {b : Cardinal.{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 cardinal.le_lift_iff Cardinal.le_lift_iff -- Porting note: Inserted .{u,v} below theorem lt_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a := ⟨fun h => let ⟨a', e⟩ := lift_down h.le ⟨a', e, lift_lt.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩ #align cardinal.lt_lift_iff Cardinal.lt_lift_iff -- Porting note: Inserted .{u,v} below @[simp] theorem lift_succ (a) : lift.{v,u} (succ a) = succ (lift.{v,u} a) := le_antisymm (le_of_not_gt fun h => by rcases lt_lift_iff.1 h with ⟨b, e, h⟩ rw [lt_succ_iff, ← lift_le, e] at h exact h.not_lt (lt_succ _)) (succ_le_of_lt <| lift_lt.2 <| lt_succ a) #align cardinal.lift_succ Cardinal.lift_succ -- Porting note: simpNF is not happy with universe levels. -- Porting note: Inserted .{u,v} below @[simp, nolint simpNF] theorem lift_umax_eq {a : Cardinal.{u}} {b : Cardinal.{v}} : lift.{max v w} a = lift.{max u w} b ↔ lift.{v} a = lift.{u} b := by rw [← lift_lift.{v, w, u}, ← lift_lift.{u, w, v}, lift_inj] #align cardinal.lift_umax_eq Cardinal.lift_umax_eq -- Porting note: Inserted .{u,v} below @[simp] theorem lift_min {a b : Cardinal} : lift.{u,v} (min a b) = min (lift.{u,v} a) (lift.{u,v} b) := lift_monotone.map_min #align cardinal.lift_min Cardinal.lift_min -- Porting note: Inserted .{u,v} below @[simp] theorem lift_max {a b : Cardinal} : lift.{u,v} (max a b) = max (lift.{u,v} a) (lift.{u,v} b) := lift_monotone.map_max #align cardinal.lift_max Cardinal.lift_max /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) : lift.{u} (sSup s) = sSup (lift.{u} '' s) := by apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _) · intro c hc by_contra h obtain ⟨d, rfl⟩ := Cardinal.lift_down (not_le.1 h).le simp_rw [lift_le] at h hc rw [csSup_le_iff' hs] at h exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha) · rintro i ⟨j, hj, rfl⟩ exact lift_le.2 (le_csSup hs hj) #align cardinal.lift_Sup Cardinal.lift_sSup /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) : lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by rw [iSup, iSup, lift_sSup hf, ← range_comp] simp [Function.comp] #align cardinal.lift_supr Cardinal.lift_iSup /-- To prove that the lift of a supremum is bounded by some cardinal `t`, it suffices to show that the lift of each cardinal is bounded by `t`. -/ theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f)) (w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by rw [lift_iSup hf] exact ciSup_le' w #align cardinal.lift_supr_le Cardinal.lift_iSup_le @[simp] theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) {t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by rw [lift_iSup hf] exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _) #align cardinal.lift_supr_le_iff Cardinal.lift_iSup_le_iff universe v' w' /-- To prove an inequality between the lifts to a common universe of two different supremums, it suffices to show that the lift of each cardinal from the smaller supremum if bounded by the lift of some cardinal from the larger supremum. -/ theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}} {f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'} (h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by rw [lift_iSup hf, lift_iSup hf'] exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩ #align cardinal.lift_supr_le_lift_supr Cardinal.lift_iSup_le_lift_iSup /-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`. This is sometimes necessary to avoid universe unification issues. -/ theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}} {f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι') (h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') := lift_iSup_le_lift_iSup hf hf' h #align cardinal.lift_supr_le_lift_supr' Cardinal.lift_iSup_le_lift_iSup' /-- `ℵ₀` is the smallest infinite cardinal. -/ def aleph0 : Cardinal.{u} := lift #ℕ #align cardinal.aleph_0 Cardinal.aleph0 @[inherit_doc] scoped notation "ℵ₀" => Cardinal.aleph0 theorem mk_nat : #ℕ = ℵ₀ := (lift_id _).symm #align cardinal.mk_nat Cardinal.mk_nat theorem aleph0_ne_zero : ℵ₀ ≠ 0 := mk_ne_zero _ #align cardinal.aleph_0_ne_zero Cardinal.aleph0_ne_zero theorem aleph0_pos : 0 < ℵ₀ := pos_iff_ne_zero.2 aleph0_ne_zero #align cardinal.aleph_0_pos Cardinal.aleph0_pos @[simp] theorem lift_aleph0 : lift ℵ₀ = ℵ₀ := lift_lift _ #align cardinal.lift_aleph_0 Cardinal.lift_aleph0 @[simp] theorem aleph0_le_lift {c : Cardinal.{u}} : ℵ₀ ≤ lift.{v} c ↔ ℵ₀ ≤ c := by rw [← lift_aleph0.{u,v}, lift_le] #align cardinal.aleph_0_le_lift Cardinal.aleph0_le_lift @[simp] theorem lift_le_aleph0 {c : Cardinal.{u}} : lift.{v} c ≤ ℵ₀ ↔ c ≤ ℵ₀ := by rw [← lift_aleph0.{u,v}, lift_le] #align cardinal.lift_le_aleph_0 Cardinal.lift_le_aleph0 @[simp] theorem aleph0_lt_lift {c : Cardinal.{u}} : ℵ₀ < lift.{v} c ↔ ℵ₀ < c := by rw [← lift_aleph0.{u,v}, lift_lt] #align cardinal.aleph_0_lt_lift Cardinal.aleph0_lt_lift @[simp] theorem lift_lt_aleph0 {c : Cardinal.{u}} : lift.{v} c < ℵ₀ ↔ c < ℵ₀ := by rw [← lift_aleph0.{u,v}, lift_lt] #align cardinal.lift_lt_aleph_0 Cardinal.lift_lt_aleph0 /-! ### Properties about the cast from `ℕ` -/ section castFromN -- porting note (#10618): simp can prove this -- @[simp] theorem mk_fin (n : ℕ) : #(Fin n) = n := by simp #align cardinal.mk_fin Cardinal.mk_fin @[simp] theorem lift_natCast (n : ℕ) : lift.{u} (n : Cardinal.{v}) = n := by induction n <;> simp [*] #align cardinal.lift_nat_cast Cardinal.lift_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] : lift.{u} (no_index (OfNat.ofNat n : Cardinal.{v})) = OfNat.ofNat n := lift_natCast n @[simp] theorem lift_eq_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n := lift_injective.eq_iff' (lift_natCast n) #align cardinal.lift_eq_nat_iff Cardinal.lift_eq_nat_iff @[simp] theorem lift_eq_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a = (no_index (OfNat.ofNat n)) ↔ a = OfNat.ofNat n := lift_eq_nat_iff @[simp] theorem nat_eq_lift_iff {n : ℕ} {a : Cardinal.{u}} : (n : Cardinal) = lift.{v} a ↔ (n : Cardinal) = a := by rw [← lift_natCast.{v,u} n, lift_inj] #align cardinal.nat_eq_lift_iff Cardinal.nat_eq_lift_iff @[simp] theorem zero_eq_lift_iff {a : Cardinal.{u}} : (0 : Cardinal) = lift.{v} a ↔ 0 = a := by simpa using nat_eq_lift_iff (n := 0) @[simp] theorem one_eq_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) = lift.{v} a ↔ 1 = a := by simpa using nat_eq_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_eq_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) = lift.{v} a ↔ (OfNat.ofNat n : Cardinal) = a := nat_eq_lift_iff @[simp] theorem lift_le_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a ≤ n ↔ a ≤ n := by rw [← lift_natCast.{v,u}, lift_le] #align cardinal.lift_le_nat_iff Cardinal.lift_le_nat_iff @[simp] theorem lift_le_one_iff {a : Cardinal.{u}} : lift.{v} a ≤ 1 ↔ a ≤ 1 := by simpa using lift_le_nat_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_le_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a ≤ (no_index (OfNat.ofNat n)) ↔ a ≤ OfNat.ofNat n := lift_le_nat_iff @[simp] theorem nat_le_lift_iff {n : ℕ} {a : Cardinal.{u}} : n ≤ lift.{v} a ↔ n ≤ a := by rw [← lift_natCast.{v,u}, lift_le] #align cardinal.nat_le_lift_iff Cardinal.nat_le_lift_iff @[simp] theorem one_le_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) ≤ lift.{v} a ↔ 1 ≤ a := by simpa using nat_le_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_le_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) ≤ lift.{v} a ↔ (OfNat.ofNat n : Cardinal) ≤ a := nat_le_lift_iff @[simp] theorem lift_lt_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a < n ↔ a < n := by rw [← lift_natCast.{v,u}, lift_lt] #align cardinal.lift_lt_nat_iff Cardinal.lift_lt_nat_iff -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_lt_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a < (no_index (OfNat.ofNat n)) ↔ a < OfNat.ofNat n := lift_lt_nat_iff @[simp] theorem nat_lt_lift_iff {n : ℕ} {a : Cardinal.{u}} : n < lift.{v} a ↔ n < a := by rw [← lift_natCast.{v,u}, lift_lt] #align cardinal.nat_lt_lift_iff Cardinal.nat_lt_lift_iff -- See note [no_index around OfNat.ofNat] @[simp] theorem zero_lt_lift_iff {a : Cardinal.{u}} : (0 : Cardinal) < lift.{v} a ↔ 0 < a := by simpa using nat_lt_lift_iff (n := 0) @[simp] theorem one_lt_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) < lift.{v} a ↔ 1 < a := by simpa using nat_lt_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_lt_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) < lift.{v} a ↔ (OfNat.ofNat n : Cardinal) < a := nat_lt_lift_iff theorem lift_mk_fin (n : ℕ) : lift #(Fin n) = n := rfl #align cardinal.lift_mk_fin Cardinal.lift_mk_fin theorem mk_coe_finset {α : Type u} {s : Finset α} : #s = ↑(Finset.card s) := by simp #align cardinal.mk_coe_finset Cardinal.mk_coe_finset theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by simp [Pow.pow] #align cardinal.mk_finset_of_fintype Cardinal.mk_finset_of_fintype @[simp] theorem mk_finsupp_lift_of_fintype (α : Type u) (β : Type v) [Fintype α] [Zero β] : #(α →₀ β) = lift.{u} #β ^ Fintype.card α := by simpa using (@Finsupp.equivFunOnFinite α β _ _).cardinal_eq #align cardinal.mk_finsupp_lift_of_fintype Cardinal.mk_finsupp_lift_of_fintype theorem mk_finsupp_of_fintype (α β : Type u) [Fintype α] [Zero β] : #(α →₀ β) = #β ^ Fintype.card α := by simp #align cardinal.mk_finsupp_of_fintype Cardinal.mk_finsupp_of_fintype theorem card_le_of_finset {α} (s : Finset α) : (s.card : Cardinal) ≤ #α := @mk_coe_finset _ s ▸ mk_set_le _ #align cardinal.card_le_of_finset Cardinal.card_le_of_finset -- Porting note: was `simp`. LHS is not normal form. -- @[simp, norm_cast] @[norm_cast] theorem natCast_pow {m n : ℕ} : (↑(m ^ n) : Cardinal) = (↑m : Cardinal) ^ (↑n : Cardinal) := by induction n <;> simp [pow_succ, power_add, *, Pow.pow] #align cardinal.nat_cast_pow Cardinal.natCast_pow -- porting note (#10618): simp can prove this -- @[simp, norm_cast] @[norm_cast] theorem natCast_le {m n : ℕ} : (m : Cardinal) ≤ n ↔ m ≤ n := by rw [← lift_mk_fin, ← lift_mk_fin, lift_le, le_def, Function.Embedding.nonempty_iff_card_le, Fintype.card_fin, Fintype.card_fin] #align cardinal.nat_cast_le Cardinal.natCast_le -- porting note (#10618): simp can prove this -- @[simp, norm_cast] @[norm_cast] theorem natCast_lt {m n : ℕ} : (m : Cardinal) < n ↔ m < n := by rw [lt_iff_le_not_le, ← not_le] simp only [natCast_le, not_le, and_iff_right_iff_imp] exact fun h ↦ le_of_lt h #align cardinal.nat_cast_lt Cardinal.natCast_lt instance : CharZero Cardinal := ⟨StrictMono.injective fun _ _ => natCast_lt.2⟩ theorem natCast_inj {m n : ℕ} : (m : Cardinal) = n ↔ m = n := Nat.cast_inj #align cardinal.nat_cast_inj Cardinal.natCast_inj theorem natCast_injective : Injective ((↑) : ℕ → Cardinal) := Nat.cast_injective #align cardinal.nat_cast_injective Cardinal.natCast_injective @[norm_cast] theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by rw [Nat.cast_succ] refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_) rw [← Nat.cast_succ] exact natCast_lt.2 (Nat.lt_succ_self _) lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by rw [← Cardinal.nat_succ] norm_cast lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by rw [← Order.succ_le_iff, Cardinal.succ_natCast] lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by convert natCast_add_one_le_iff norm_cast @[simp] theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast #align cardinal.succ_zero Cardinal.succ_zero theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) : ∃ s : Finset α, n ≤ s.card := by obtain hα|hα := finite_or_infinite α · let hα := Fintype.ofFinite α use Finset.univ simpa only [mk_fintype, Nat.cast_le] using h · obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n exact ⟨s, hs.ge⟩ theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by contrapose! H apply exists_finset_le_card α (n+1) simpa only [nat_succ, succ_le_iff] using H #align cardinal.card_le_of Cardinal.card_le_of theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb exact (cantor a).trans_le (power_le_power_right hb) #align cardinal.cantor' Cardinal.cantor' theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by rw [← succ_zero, succ_le_iff] #align cardinal.one_le_iff_pos Cardinal.one_le_iff_pos theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by rw [one_le_iff_pos, pos_iff_ne_zero] #align cardinal.one_le_iff_ne_zero Cardinal.one_le_iff_ne_zero @[simp] theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by simpa using lt_succ_bot_iff (a := c) theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ := succ_le_iff.1 (by rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}] exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩) #align cardinal.nat_lt_aleph_0 Cardinal.nat_lt_aleph0 @[simp] theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1 #align cardinal.one_lt_aleph_0 Cardinal.one_lt_aleph0 theorem one_le_aleph0 : 1 ≤ ℵ₀ := one_lt_aleph0.le #align cardinal.one_le_aleph_0 Cardinal.one_le_aleph0 theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n := ⟨fun h => by rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩ rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩ suffices S.Finite by lift S to Finset ℕ using this simp contrapose! h' haveI := Infinite.to_subtype h' exact ⟨Infinite.natEmbedding S⟩, fun ⟨n, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩ #align cardinal.lt_aleph_0 Cardinal.lt_aleph0 lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h rw [hn, succ_natCast] theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c := ⟨fun h n => (nat_lt_aleph0 _).le.trans h, fun h => le_of_not_lt fun hn => by rcases lt_aleph0.1 hn with ⟨n, rfl⟩ exact (Nat.lt_succ_self _).not_le (natCast_le.1 (h (n + 1)))⟩ #align cardinal.aleph_0_le Cardinal.aleph0_le theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := isSuccLimit_of_succ_lt fun a ha => by rcases lt_aleph0.1 ha with ⟨n, rfl⟩ rw [← nat_succ] apply nat_lt_aleph0 #align cardinal.is_succ_limit_aleph_0 Cardinal.isSuccLimit_aleph0 theorem isLimit_aleph0 : IsLimit ℵ₀ := ⟨aleph0_ne_zero, isSuccLimit_aleph0⟩ #align cardinal.is_limit_aleph_0 Cardinal.isLimit_aleph0 lemma not_isLimit_natCast : (n : ℕ) → ¬ IsLimit (n : Cardinal.{u}) | 0, e => e.1 rfl | Nat.succ n, e => Order.not_isSuccLimit_succ _ (nat_succ n ▸ e.2) theorem IsLimit.aleph0_le {c : Cardinal} (h : IsLimit c) : ℵ₀ ≤ c := by by_contra! h' rcases lt_aleph0.1 h' with ⟨n, rfl⟩ exact not_isLimit_natCast n h lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n := exists_eq_of_iSup_eq_of_not_isLimit.{u, v} f hf _ (not_isLimit_natCast n) h @[simp] theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ := ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0] #align cardinal.range_nat_cast Cardinal.range_natCast theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq'] #align cardinal.mk_eq_nat_iff Cardinal.mk_eq_nat_iff theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin] #align cardinal.lt_aleph_0_iff_finite Cardinal.lt_aleph0_iff_finite theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) := lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _) #align cardinal.lt_aleph_0_iff_fintype Cardinal.lt_aleph0_iff_fintype theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ := lt_aleph0_iff_finite.2 ‹_› #align cardinal.lt_aleph_0_of_finite Cardinal.lt_aleph0_of_finite -- porting note (#10618): simp can prove this -- @[simp] theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite := lt_aleph0_iff_finite.trans finite_coe_iff #align cardinal.lt_aleph_0_iff_set_finite Cardinal.lt_aleph0_iff_set_finite alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite #align set.finite.lt_aleph_0 Set.Finite.lt_aleph0 @[simp] theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite := lt_aleph0_iff_set_finite #align cardinal.lt_aleph_0_iff_subtype_finite Cardinal.lt_aleph0_iff_subtype_finite theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le'] #align cardinal.mk_le_aleph_0_iff Cardinal.mk_le_aleph0_iff @[simp] theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ := mk_le_aleph0_iff.mpr ‹_› #align cardinal.mk_le_aleph_0 Cardinal.mk_le_aleph0 -- porting note (#10618): simp can prove this -- @[simp] theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff #align cardinal.le_aleph_0_iff_set_countable Cardinal.le_aleph0_iff_set_countable alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable #align set.countable.le_aleph_0 Set.Countable.le_aleph0 @[simp] theorem le_aleph0_iff_subtype_countable {p : α → Prop} : #{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable := le_aleph0_iff_set_countable #align cardinal.le_aleph_0_iff_subtype_countable Cardinal.le_aleph0_iff_subtype_countable instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ := ⟨fun _ hx => let ⟨n, hn⟩ := lt_aleph0.mp hx ⟨n, hn.symm⟩⟩ #align cardinal.can_lift_cardinal_nat Cardinal.canLiftCardinalNat theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0 #align cardinal.add_lt_aleph_0 Cardinal.add_lt_aleph0 theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := ⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩, fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩ #align cardinal.add_lt_aleph_0_iff Cardinal.add_lt_aleph0_iff theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by simp only [← not_lt, add_lt_aleph0_iff, not_and_or] #align cardinal.aleph_0_le_add_iff Cardinal.aleph0_le_add_iff /-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/ theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by cases n with | zero => simpa using nat_lt_aleph0 0 | succ n => simp only [Nat.succ_ne_zero, false_or_iff] induction' n with n ih · simp rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff] #align cardinal.nsmul_lt_aleph_0_iff Cardinal.nsmul_lt_aleph0_iff /-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/ theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ := nsmul_lt_aleph0_iff.trans <| or_iff_right h #align cardinal.nsmul_lt_aleph_0_iff_of_ne_zero Cardinal.nsmul_lt_aleph0_iff_of_ne_zero theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0 #align cardinal.mul_lt_aleph_0 Cardinal.mul_lt_aleph0 theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by refine ⟨fun h => ?_, ?_⟩ · by_cases ha : a = 0 · exact Or.inl ha right by_cases hb : b = 0 · exact Or.inl hb right rw [← Ne, ← one_le_iff_ne_zero] at ha hb constructor · rw [← mul_one a] exact (mul_le_mul' le_rfl hb).trans_lt h · rw [← one_mul b] exact (mul_le_mul' ha le_rfl).trans_lt h rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero] #align cardinal.mul_lt_aleph_0_iff Cardinal.mul_lt_aleph0_iff /-- See also `Cardinal.aleph0_le_mul_iff`. -/ theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by let h := (@mul_lt_aleph0_iff a b).not rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h #align cardinal.aleph_0_le_mul_iff Cardinal.aleph0_le_mul_iff /-- See also `Cardinal.aleph0_le_mul_iff'`. -/ theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)] simp only [and_comm, or_comm] #align cardinal.aleph_0_le_mul_iff' Cardinal.aleph0_le_mul_iff' theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) : a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb] #align cardinal.mul_lt_aleph_0_iff_of_ne_zero Cardinal.mul_lt_aleph0_iff_of_ne_zero theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← natCast_pow]; apply nat_lt_aleph0 #align cardinal.power_lt_aleph_0 Cardinal.power_lt_aleph0 theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α := calc #α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff _ ↔ Subsingleton α ∧ Nonempty α := le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff) #align cardinal.eq_one_iff_unique Cardinal.eq_one_iff_unique theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite] #align cardinal.infinite_iff Cardinal.infinite_iff lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff] @[simp] theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α := infinite_iff.1 ‹_› #align cardinal.aleph_0_le_mk Cardinal.aleph0_le_mk @[simp] theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ := mk_le_aleph0.antisymm <| aleph0_le_mk _ #align cardinal.mk_eq_aleph_0 Cardinal.mk_eq_aleph0 theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ := ⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by cases' Quotient.exact h with f exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩ #align cardinal.denumerable_iff Cardinal.denumerable_iff -- porting note (#10618): simp can prove this -- @[simp] theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ := denumerable_iff.1 ⟨‹_›⟩ #align cardinal.mk_denumerable Cardinal.mk_denumerable theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} : s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff] @[simp] theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ := mk_denumerable _ #align cardinal.aleph_0_add_aleph_0 Cardinal.aleph0_add_aleph0 theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ := mk_denumerable _ #align cardinal.aleph_0_mul_aleph_0 Cardinal.aleph0_mul_aleph0 @[simp] theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ := le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <| le_mul_of_one_le_left (zero_le _) <| by rwa [← Nat.cast_one, natCast_le, Nat.one_le_iff_ne_zero] #align cardinal.nat_mul_aleph_0 Cardinal.nat_mul_aleph0 @[simp] theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn] #align cardinal.aleph_0_mul_nat Cardinal.aleph0_mul_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) * ℵ₀ = ℵ₀ := nat_mul_aleph0 (NeZero.ne n) -- See note [no_index around OfNat.ofNat] @[simp] theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * no_index (OfNat.ofNat n) = ℵ₀ := aleph0_mul_nat (NeZero.ne n) @[simp] theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ := ⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h => aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩ #align cardinal.add_le_aleph_0 Cardinal.add_le_aleph0 @[simp] theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ := (add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add #align cardinal.aleph_0_add_nat Cardinal.aleph0_add_nat @[simp] theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat] #align cardinal.nat_add_aleph_0 Cardinal.nat_add_aleph0 -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) + ℵ₀ = ℵ₀ := nat_add_aleph0 n -- See note [no_index around OfNat.ofNat] @[simp] theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + no_index (OfNat.ofNat n) = ℵ₀ := aleph0_add_nat n theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by lift c to ℕ using h.trans_lt (nat_lt_aleph0 _) exact ⟨c, mod_cast h, rfl⟩ #align cardinal.exists_nat_eq_of_le_nat Cardinal.exists_nat_eq_of_le_nat theorem mk_int : #ℤ = ℵ₀ := mk_denumerable ℤ #align cardinal.mk_int Cardinal.mk_int theorem mk_pNat : #ℕ+ = ℵ₀ := mk_denumerable ℕ+ #align cardinal.mk_pnat Cardinal.mk_pNat end castFromN variable {c : Cardinal} /-- **König's theorem** -/ theorem sum_lt_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i < g i) : sum f < prod g := lt_of_not_ge fun ⟨F⟩ => by have : Inhabited (∀ i : ι, (g i).out) := by refine ⟨fun i => Classical.choice <| mk_ne_zero_iff.1 ?_⟩ rw [mk_out] exact (H i).ne_bot let G := invFun F have sG : Surjective G := invFun_surjective F.2 choose C hc using show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b by intro i simp only [not_exists.symm, not_forall.symm] refine fun h => (H i).not_le ?_ rw [← mk_out (f i), ← mk_out (g i)] exact ⟨Embedding.ofSurjective _ h⟩ let ⟨⟨i, a⟩, h⟩ := sG C exact hc i a (congr_fun h _) #align cardinal.sum_lt_prod Cardinal.sum_lt_prod /-! Cardinalities of sets: cardinality of empty, finite sets, unions, subsets etc. -/ section sets -- porting note (#10618): simp can prove this -- @[simp] theorem mk_empty : #Empty = 0 := mk_eq_zero _ #align cardinal.mk_empty Cardinal.mk_empty -- porting note (#10618): simp can prove this -- @[simp] theorem mk_pempty : #PEmpty = 0 := mk_eq_zero _ #align cardinal.mk_pempty Cardinal.mk_pempty -- porting note (#10618): simp can prove this -- @[simp] theorem mk_punit : #PUnit = 1 := mk_eq_one PUnit #align cardinal.mk_punit Cardinal.mk_punit theorem mk_unit : #Unit = 1 := mk_punit #align cardinal.mk_unit Cardinal.mk_unit -- porting note (#10618): simp can prove this -- @[simp] theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 := mk_eq_one _ #align cardinal.mk_singleton Cardinal.mk_singleton -- porting note (#10618): simp can prove this -- @[simp] theorem mk_plift_true : #(PLift True) = 1 := mk_eq_one _ #align cardinal.mk_plift_true Cardinal.mk_plift_true -- porting note (#10618): simp can prove this -- @[simp] theorem mk_plift_false : #(PLift False) = 0 := mk_eq_zero _ #align cardinal.mk_plift_false Cardinal.mk_plift_false @[simp] theorem mk_vector (α : Type u) (n : ℕ) : #(Vector α n) = #α ^ n := (mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp #align cardinal.mk_vector Cardinal.mk_vector theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n := calc #(List α) = #(Σn, Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm _ = sum fun n : ℕ => #α ^ n := by simp #align cardinal.mk_list_eq_sum_pow Cardinal.mk_list_eq_sum_pow theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α := mk_le_of_surjective Quot.exists_rep #align cardinal.mk_quot_le Cardinal.mk_quot_le theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α := mk_quot_le #align cardinal.mk_quotient_le Cardinal.mk_quotient_le theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) : #(Subtype p) ≤ #(Subtype q) := ⟨Embedding.subtypeMap (Embedding.refl α) h⟩ #align cardinal.mk_subtype_le_of_subset Cardinal.mk_subtype_le_of_subset -- porting note (#10618): simp can prove this -- @[simp] theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 := mk_eq_zero _ #align cardinal.mk_emptyc Cardinal.mk_emptyCollection theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by constructor · intro h rw [mk_eq_zero_iff] at h exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩ · rintro rfl exact mk_emptyCollection _ #align cardinal.mk_emptyc_iff Cardinal.mk_emptyCollection_iff @[simp] theorem mk_univ {α : Type u} : #(@univ α) = #α := mk_congr (Equiv.Set.univ α) #align cardinal.mk_univ Cardinal.mk_univ theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s := mk_le_of_surjective surjective_onto_image #align cardinal.mk_image_le Cardinal.mk_image_le theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} : lift.{u} #(f '' s) ≤ lift.{v} #s := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩ #align cardinal.mk_image_le_lift Cardinal.mk_image_le_lift theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α := mk_le_of_surjective surjective_onto_range #align cardinal.mk_range_le Cardinal.mk_range_le theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} : lift.{u} #(range f) ≤ lift.{v} #α := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩ #align cardinal.mk_range_le_lift Cardinal.mk_range_le_lift theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α := mk_congr (Equiv.ofInjective f h).symm #align cardinal.mk_range_eq Cardinal.mk_range_eq theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{max u w} #(range f) = lift.{max v w} #α := lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩ #align cardinal.mk_range_eq_lift Cardinal.mk_range_eq_lift theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{u} #(range f) = lift.{v} #α := lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩ #align cardinal.mk_range_eq_of_injective Cardinal.mk_range_eq_of_injective lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by rw [← Cardinal.mk_range_eq_of_injective hf] exact Cardinal.lift_le.2 (Cardinal.mk_set_le _) lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) : Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) := lift_mk_le_lift_mk_of_injective (injective_surjInv hf) theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) : #(f '' s) = #s := mk_congr (Equiv.Set.imageOfInjOn f s h).symm #align cardinal.mk_image_eq_of_inj_on Cardinal.mk_image_eq_of_injOn theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s := lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩ #align cardinal.mk_image_eq_of_inj_on_lift Cardinal.mk_image_eq_of_injOn_lift theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s := mk_image_eq_of_injOn _ _ hf.injOn #align cardinal.mk_image_eq Cardinal.mk_image_eq theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_of_injOn_lift _ _ h.injOn #align cardinal.mk_image_eq_lift Cardinal.mk_image_eq_lift theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) := calc #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ #align cardinal.mk_Union_le_sum_mk Cardinal.mk_iUnion_le_sum_mk theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} : lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α} (h : Pairwise fun i j => Disjoint (f i) (f j)) : #(⋃ i, f i) = sum fun i => #(f i) := calc #(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ #align cardinal.mk_Union_eq_sum_mk Cardinal.mk_iUnion_eq_sum_mk theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} (h : Pairwise fun i j => Disjoint (f i) (f j)) : lift.{v} #(⋃ i, f i) = sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) = #(Σi, f i) := mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) := mk_iUnion_le_sum_mk.trans (sum_le_iSup _) #align cardinal.mk_Union_le Cardinal.mk_iUnion_le theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) : lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _) rw [← lift_sum, lift_id'.{_,u}] theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by rw [sUnion_eq_iUnion] apply mk_iUnion_le #align cardinal.mk_sUnion_le Cardinal.mk_sUnion_le theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) : #(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le #align cardinal.mk_bUnion_le Cardinal.mk_biUnion_le theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) : lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le_lift theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ := lt_aleph0_of_finite _ #align cardinal.finset_card_lt_aleph_0 Cardinal.finset_card_lt_aleph0 theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} : #s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by constructor · intro h lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n) simpa using h · rintro ⟨t, rfl, rfl⟩ exact mk_coe_finset #align cardinal.mk_set_eq_nat_iff_finset Cardinal.mk_set_eq_nat_iff_finset theorem mk_eq_nat_iff_finset {n : ℕ} : #α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by rw [← mk_univ, mk_set_eq_nat_iff_finset] #align cardinal.mk_eq_nat_iff_finset Cardinal.mk_eq_nat_iff_finset
Mathlib/SetTheory/Cardinal/Basic.lean
2,089
2,095
theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by
rw [mk_eq_nat_iff_finset] constructor · rintro ⟨t, ht, hn⟩ exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩ · rintro ⟨⟨t, ht⟩, hn⟩ exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Algebra.Group.Int import Mathlib.Algebra.Order.Group.Abs #align_import data.int.order.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # The integers form a linear ordered group This file contains the linear ordered group instance on the integers. See note [foundational algebra order theory]. ## Recursors * `Int.rec`: Sign disjunction. Something is true/defined on `ℤ` if it's true/defined for nonnegative and for negative values. (Defined in core Lean 3) * `Int.inductionOn`: Simple growing induction on positive numbers, plus simple decreasing induction on negative numbers. Note that this recursor is currently only `Prop`-valued. * `Int.inductionOn'`: Simple growing induction for numbers greater than `b`, plus simple decreasing induction on numbers less than `b`. -/ -- We should need only a minimal development of sets in order to get here. assert_not_exists Set.Subsingleton assert_not_exists Ring open Function Nat namespace Int theorem natCast_strictMono : StrictMono (· : ℕ → ℤ) := fun _ _ ↦ Int.ofNat_lt.2 #align int.coe_nat_strict_mono Int.natCast_strictMono @[deprecated (since := "2024-05-25")] alias coe_nat_strictMono := natCast_strictMono instance linearOrderedAddCommGroup : LinearOrderedAddCommGroup ℤ where __ := instLinearOrder __ := instAddCommGroup add_le_add_left _ _ := Int.add_le_add_left /-! ### Miscellaneous lemmas -/ theorem abs_eq_natAbs : ∀ a : ℤ, |a| = natAbs a | (n : ℕ) => abs_of_nonneg <| ofNat_zero_le _ | -[_+1] => abs_of_nonpos <| le_of_lt <| negSucc_lt_zero _ #align int.abs_eq_nat_abs Int.abs_eq_natAbs @[simp, norm_cast] lemma natCast_natAbs (n : ℤ) : (n.natAbs : ℤ) = |n| := n.abs_eq_natAbs.symm #align int.coe_nat_abs Int.natCast_natAbs theorem natAbs_abs (a : ℤ) : natAbs |a| = natAbs a := by rw [abs_eq_natAbs]; rfl #align int.nat_abs_abs Int.natAbs_abs
Mathlib/Algebra/Order/Group/Int.lean
60
61
theorem sign_mul_abs (a : ℤ) : sign a * |a| = a := by
rw [abs_eq_natAbs, sign_mul_natAbs a]
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.MeasureTheory.Integral.IntegrableOn import Mathlib.MeasureTheory.Integral.Bochner import Mathlib.MeasureTheory.Function.LocallyIntegrable import Mathlib.Topology.MetricSpace.ThickenedIndicator import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Analysis.NormedSpace.HahnBanach.SeparatingDual #align_import measure_theory.integral.setIntegral from "leanprover-community/mathlib"@"24e0c85412ff6adbeca08022c25ba4876eedf37a" /-! # Set integral In this file we prove some properties of `∫ x in s, f x ∂μ`. Recall that this notation is defined as `∫ x, f x ∂(μ.restrict s)`. In `integral_indicator` we prove that for a measurable function `f` and a measurable set `s` this definition coincides with another natural definition: `∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ`, where `indicator s f x` is equal to `f x` for `x ∈ s` and is zero otherwise. Since `∫ x in s, f x ∂μ` is a notation, one can rewrite or apply any theorem about `∫ x, f x ∂μ` directly. In this file we prove some theorems about dependence of `∫ x in s, f x ∂μ` on `s`, e.g. `integral_union`, `integral_empty`, `integral_univ`. We use the property `IntegrableOn f s μ := Integrable f (μ.restrict s)`, defined in `MeasureTheory.IntegrableOn`. We also defined in that same file a predicate `IntegrableAtFilter (f : X → E) (l : Filter X) (μ : Measure X)` saying that `f` is integrable at some set `s ∈ l`. Finally, we prove a version of the [Fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) for set integral, see `Filter.Tendsto.integral_sub_linear_isLittleO_ae` and its corollaries. Namely, consider a measurably generated filter `l`, a measure `μ` finite at this filter, and a function `f` that has a finite limit `c` at `l ⊓ ae μ`. Then `∫ x in s, f x ∂μ = μ s • c + o(μ s)` as `s` tends to `l.smallSets`, i.e. for any `ε>0` there exists `t ∈ l` such that `‖∫ x in s, f x ∂μ - μ s • c‖ ≤ ε * μ s` whenever `s ⊆ t`. We also formulate a version of this theorem for a locally finite measure `μ` and a function `f` continuous at a point `a`. ## Notation We provide the following notations for expressing the integral of a function on a set : * `∫ x in s, f x ∂μ` is `MeasureTheory.integral (μ.restrict s) f` * `∫ x in s, f x` is `∫ x in s, f x ∂volume` Note that the set notations are defined in the file `Mathlib/MeasureTheory/Integral/Bochner.lean`, but we reference them here because all theorems about set integrals are in this file. -/ assert_not_exists InnerProductSpace noncomputable section open Set Filter TopologicalSpace MeasureTheory Function RCLike open scoped Classical Topology ENNReal NNReal variable {X Y E F : Type*} [MeasurableSpace X] namespace MeasureTheory section NormedAddCommGroup variable [NormedAddCommGroup E] [NormedSpace ℝ E] {f g : X → E} {s t : Set X} {μ ν : Measure X} {l l' : Filter X} theorem setIntegral_congr_ae₀ (hs : NullMeasurableSet s μ) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := integral_congr_ae ((ae_restrict_iff'₀ hs).2 h) #align measure_theory.set_integral_congr_ae₀ MeasureTheory.setIntegral_congr_ae₀ @[deprecated (since := "2024-04-17")] alias set_integral_congr_ae₀ := setIntegral_congr_ae₀ theorem setIntegral_congr_ae (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := integral_congr_ae ((ae_restrict_iff' hs).2 h) #align measure_theory.set_integral_congr_ae MeasureTheory.setIntegral_congr_ae @[deprecated (since := "2024-04-17")] alias set_integral_congr_ae := setIntegral_congr_ae theorem setIntegral_congr₀ (hs : NullMeasurableSet s μ) (h : EqOn f g s) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := setIntegral_congr_ae₀ hs <| eventually_of_forall h #align measure_theory.set_integral_congr₀ MeasureTheory.setIntegral_congr₀ @[deprecated (since := "2024-04-17")] alias set_integral_congr₀ := setIntegral_congr₀ theorem setIntegral_congr (hs : MeasurableSet s) (h : EqOn f g s) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := setIntegral_congr_ae hs <| eventually_of_forall h #align measure_theory.set_integral_congr MeasureTheory.setIntegral_congr @[deprecated (since := "2024-04-17")] alias set_integral_congr := setIntegral_congr theorem setIntegral_congr_set_ae (hst : s =ᵐ[μ] t) : ∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ := by rw [Measure.restrict_congr_set hst] #align measure_theory.set_integral_congr_set_ae MeasureTheory.setIntegral_congr_set_ae @[deprecated (since := "2024-04-17")] alias set_integral_congr_set_ae := setIntegral_congr_set_ae theorem integral_union_ae (hst : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) (hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ := by simp only [IntegrableOn, Measure.restrict_union₀ hst ht, integral_add_measure hfs hft] #align measure_theory.integral_union_ae MeasureTheory.integral_union_ae theorem integral_union (hst : Disjoint s t) (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ := integral_union_ae hst.aedisjoint ht.nullMeasurableSet hfs hft #align measure_theory.integral_union MeasureTheory.integral_union theorem integral_diff (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) (hts : t ⊆ s) : ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ - ∫ x in t, f x ∂μ := by rw [eq_sub_iff_add_eq, ← integral_union, diff_union_of_subset hts] exacts [disjoint_sdiff_self_left, ht, hfs.mono_set diff_subset, hfs.mono_set hts] #align measure_theory.integral_diff MeasureTheory.integral_diff theorem integral_inter_add_diff₀ (ht : NullMeasurableSet t μ) (hfs : IntegrableOn f s μ) : ∫ x in s ∩ t, f x ∂μ + ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ := by rw [← Measure.restrict_inter_add_diff₀ s ht, integral_add_measure] · exact Integrable.mono_measure hfs (Measure.restrict_mono inter_subset_left le_rfl) · exact Integrable.mono_measure hfs (Measure.restrict_mono diff_subset le_rfl) #align measure_theory.integral_inter_add_diff₀ MeasureTheory.integral_inter_add_diff₀ theorem integral_inter_add_diff (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) : ∫ x in s ∩ t, f x ∂μ + ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_inter_add_diff₀ ht.nullMeasurableSet hfs #align measure_theory.integral_inter_add_diff MeasureTheory.integral_inter_add_diff theorem integral_finset_biUnion {ι : Type*} (t : Finset ι) {s : ι → Set X} (hs : ∀ i ∈ t, MeasurableSet (s i)) (h's : Set.Pairwise (↑t) (Disjoint on s)) (hf : ∀ i ∈ t, IntegrableOn f (s i) μ) : ∫ x in ⋃ i ∈ t, s i, f x ∂μ = ∑ i ∈ t, ∫ x in s i, f x ∂μ := by induction' t using Finset.induction_on with a t hat IH hs h's · simp · simp only [Finset.coe_insert, Finset.forall_mem_insert, Set.pairwise_insert, Finset.set_biUnion_insert] at hs hf h's ⊢ rw [integral_union _ _ hf.1 (integrableOn_finset_iUnion.2 hf.2)] · rw [Finset.sum_insert hat, IH hs.2 h's.1 hf.2] · simp only [disjoint_iUnion_right] exact fun i hi => (h's.2 i hi (ne_of_mem_of_not_mem hi hat).symm).1 · exact Finset.measurableSet_biUnion _ hs.2 #align measure_theory.integral_finset_bUnion MeasureTheory.integral_finset_biUnion theorem integral_fintype_iUnion {ι : Type*} [Fintype ι] {s : ι → Set X} (hs : ∀ i, MeasurableSet (s i)) (h's : Pairwise (Disjoint on s)) (hf : ∀ i, IntegrableOn f (s i) μ) : ∫ x in ⋃ i, s i, f x ∂μ = ∑ i, ∫ x in s i, f x ∂μ := by convert integral_finset_biUnion Finset.univ (fun i _ => hs i) _ fun i _ => hf i · simp · simp [pairwise_univ, h's] #align measure_theory.integral_fintype_Union MeasureTheory.integral_fintype_iUnion theorem integral_empty : ∫ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, integral_zero_measure] #align measure_theory.integral_empty MeasureTheory.integral_empty theorem integral_univ : ∫ x in univ, f x ∂μ = ∫ x, f x ∂μ := by rw [Measure.restrict_univ] #align measure_theory.integral_univ MeasureTheory.integral_univ theorem integral_add_compl₀ (hs : NullMeasurableSet s μ) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ := by rw [ ← integral_union_ae disjoint_compl_right.aedisjoint hs.compl hfi.integrableOn hfi.integrableOn, union_compl_self, integral_univ] #align measure_theory.integral_add_compl₀ MeasureTheory.integral_add_compl₀ theorem integral_add_compl (hs : MeasurableSet s) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ := integral_add_compl₀ hs.nullMeasurableSet hfi #align measure_theory.integral_add_compl MeasureTheory.integral_add_compl /-- For a function `f` and a measurable set `s`, the integral of `indicator s f` over the whole space is equal to `∫ x in s, f x ∂μ` defined as `∫ x, f x ∂(μ.restrict s)`. -/ theorem integral_indicator (hs : MeasurableSet s) : ∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ := by by_cases hfi : IntegrableOn f s μ; swap · rw [integral_undef hfi, integral_undef] rwa [integrable_indicator_iff hs] calc ∫ x, indicator s f x ∂μ = ∫ x in s, indicator s f x ∂μ + ∫ x in sᶜ, indicator s f x ∂μ := (integral_add_compl hs (hfi.integrable_indicator hs)).symm _ = ∫ x in s, f x ∂μ + ∫ x in sᶜ, 0 ∂μ := (congr_arg₂ (· + ·) (integral_congr_ae (indicator_ae_eq_restrict hs)) (integral_congr_ae (indicator_ae_eq_restrict_compl hs))) _ = ∫ x in s, f x ∂μ := by simp #align measure_theory.integral_indicator MeasureTheory.integral_indicator theorem setIntegral_indicator (ht : MeasurableSet t) : ∫ x in s, t.indicator f x ∂μ = ∫ x in s ∩ t, f x ∂μ := by rw [integral_indicator ht, Measure.restrict_restrict ht, Set.inter_comm] #align measure_theory.set_integral_indicator MeasureTheory.setIntegral_indicator @[deprecated (since := "2024-04-17")] alias set_integral_indicator := setIntegral_indicator theorem ofReal_setIntegral_one_of_measure_ne_top {X : Type*} {m : MeasurableSpace X} {μ : Measure X} {s : Set X} (hs : μ s ≠ ∞) : ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = μ s := calc ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = ENNReal.ofReal (∫ _ in s, ‖(1 : ℝ)‖ ∂μ) := by simp only [norm_one] _ = ∫⁻ _ in s, 1 ∂μ := by rw [ofReal_integral_norm_eq_lintegral_nnnorm (integrableOn_const.2 (Or.inr hs.lt_top))] simp only [nnnorm_one, ENNReal.coe_one] _ = μ s := set_lintegral_one _ #align measure_theory.of_real_set_integral_one_of_measure_ne_top MeasureTheory.ofReal_setIntegral_one_of_measure_ne_top @[deprecated (since := "2024-04-17")] alias ofReal_set_integral_one_of_measure_ne_top := ofReal_setIntegral_one_of_measure_ne_top theorem ofReal_setIntegral_one {X : Type*} {_ : MeasurableSpace X} (μ : Measure X) [IsFiniteMeasure μ] (s : Set X) : ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = μ s := ofReal_setIntegral_one_of_measure_ne_top (measure_ne_top μ s) #align measure_theory.of_real_set_integral_one MeasureTheory.ofReal_setIntegral_one @[deprecated (since := "2024-04-17")] alias ofReal_set_integral_one := ofReal_setIntegral_one theorem integral_piecewise [DecidablePred (· ∈ s)] (hs : MeasurableSet s) (hf : IntegrableOn f s μ) (hg : IntegrableOn g sᶜ μ) : ∫ x, s.piecewise f g x ∂μ = ∫ x in s, f x ∂μ + ∫ x in sᶜ, g x ∂μ := by rw [← Set.indicator_add_compl_eq_piecewise, integral_add' (hf.integrable_indicator hs) (hg.integrable_indicator hs.compl), integral_indicator hs, integral_indicator hs.compl] #align measure_theory.integral_piecewise MeasureTheory.integral_piecewise theorem tendsto_setIntegral_of_monotone {ι : Type*} [Countable ι] [SemilatticeSup ι] {s : ι → Set X} (hsm : ∀ i, MeasurableSet (s i)) (h_mono : Monotone s) (hfi : IntegrableOn f (⋃ n, s n) μ) : Tendsto (fun i => ∫ x in s i, f x ∂μ) atTop (𝓝 (∫ x in ⋃ n, s n, f x ∂μ)) := by have hfi' : ∫⁻ x in ⋃ n, s n, ‖f x‖₊ ∂μ < ∞ := hfi.2 set S := ⋃ i, s i have hSm : MeasurableSet S := MeasurableSet.iUnion hsm have hsub : ∀ {i}, s i ⊆ S := @(subset_iUnion s) rw [← withDensity_apply _ hSm] at hfi' set ν := μ.withDensity fun x => ‖f x‖₊ with hν refine Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le have : ∀ᶠ i in atTop, ν (s i) ∈ Icc (ν S - ε) (ν S + ε) := tendsto_measure_iUnion h_mono (ENNReal.Icc_mem_nhds hfi'.ne (ENNReal.coe_pos.2 ε0).ne') filter_upwards [this] with i hi rw [mem_closedBall_iff_norm', ← integral_diff (hsm i) hfi hsub, ← coe_nnnorm, NNReal.coe_le_coe, ← ENNReal.coe_le_coe] refine (ennnorm_integral_le_lintegral_ennnorm _).trans ?_ rw [← withDensity_apply _ (hSm.diff (hsm _)), ← hν, measure_diff hsub (hsm _)] exacts [tsub_le_iff_tsub_le.mp hi.1, (hi.2.trans_lt <| ENNReal.add_lt_top.2 ⟨hfi', ENNReal.coe_lt_top⟩).ne] #align measure_theory.tendsto_set_integral_of_monotone MeasureTheory.tendsto_setIntegral_of_monotone @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_monotone := tendsto_setIntegral_of_monotone theorem tendsto_setIntegral_of_antitone {ι : Type*} [Countable ι] [SemilatticeSup ι] {s : ι → Set X} (hsm : ∀ i, MeasurableSet (s i)) (h_anti : Antitone s) (hfi : ∃ i, IntegrableOn f (s i) μ) : Tendsto (fun i ↦ ∫ x in s i, f x ∂μ) atTop (𝓝 (∫ x in ⋂ n, s n, f x ∂μ)) := by set S := ⋂ i, s i have hSm : MeasurableSet S := MeasurableSet.iInter hsm have hsub i : S ⊆ s i := iInter_subset _ _ set ν := μ.withDensity fun x => ‖f x‖₊ with hν refine Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le rcases hfi with ⟨i₀, hi₀⟩ have νi₀ : ν (s i₀) ≠ ∞ := by simpa [hsm i₀, ν, ENNReal.ofReal, norm_toNNReal] using hi₀.norm.lintegral_lt_top.ne have νS : ν S ≠ ∞ := ((measure_mono (hsub i₀)).trans_lt νi₀.lt_top).ne have : ∀ᶠ i in atTop, ν (s i) ∈ Icc (ν S - ε) (ν S + ε) := by apply tendsto_measure_iInter hsm h_anti ⟨i₀, νi₀⟩ apply ENNReal.Icc_mem_nhds νS (ENNReal.coe_pos.2 ε0).ne' filter_upwards [this, Ici_mem_atTop i₀] with i hi h'i rw [mem_closedBall_iff_norm, ← integral_diff hSm (hi₀.mono_set (h_anti h'i)) (hsub i), ← coe_nnnorm, NNReal.coe_le_coe, ← ENNReal.coe_le_coe] refine (ennnorm_integral_le_lintegral_ennnorm _).trans ?_ rw [← withDensity_apply _ ((hsm _).diff hSm), ← hν, measure_diff (hsub i) hSm νS] exact tsub_le_iff_left.2 hi.2 @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_antitone := tendsto_setIntegral_of_antitone theorem hasSum_integral_iUnion_ae {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : HasSum (fun n => ∫ x in s n, f x ∂μ) (∫ x in ⋃ n, s n, f x ∂μ) := by simp only [IntegrableOn, Measure.restrict_iUnion_ae hd hm] at hfi ⊢ exact hasSum_integral_measure hfi #align measure_theory.has_sum_integral_Union_ae MeasureTheory.hasSum_integral_iUnion_ae theorem hasSum_integral_iUnion {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : HasSum (fun n => ∫ x in s n, f x ∂μ) (∫ x in ⋃ n, s n, f x ∂μ) := hasSum_integral_iUnion_ae (fun i => (hm i).nullMeasurableSet) (hd.mono fun _ _ h => h.aedisjoint) hfi #align measure_theory.has_sum_integral_Union MeasureTheory.hasSum_integral_iUnion theorem integral_iUnion {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : ∫ x in ⋃ n, s n, f x ∂μ = ∑' n, ∫ x in s n, f x ∂μ := (HasSum.tsum_eq (hasSum_integral_iUnion hm hd hfi)).symm #align measure_theory.integral_Union MeasureTheory.integral_iUnion theorem integral_iUnion_ae {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : ∫ x in ⋃ n, s n, f x ∂μ = ∑' n, ∫ x in s n, f x ∂μ := (HasSum.tsum_eq (hasSum_integral_iUnion_ae hm hd hfi)).symm #align measure_theory.integral_Union_ae MeasureTheory.integral_iUnion_ae theorem setIntegral_eq_zero_of_ae_eq_zero (ht_eq : ∀ᵐ x ∂μ, x ∈ t → f x = 0) : ∫ x in t, f x ∂μ = 0 := by by_cases hf : AEStronglyMeasurable f (μ.restrict t); swap · rw [integral_undef] contrapose! hf exact hf.1 have : ∫ x in t, hf.mk f x ∂μ = 0 := by refine integral_eq_zero_of_ae ?_ rw [EventuallyEq, ae_restrict_iff (hf.stronglyMeasurable_mk.measurableSet_eq_fun stronglyMeasurable_zero)] filter_upwards [ae_imp_of_ae_restrict hf.ae_eq_mk, ht_eq] with x hx h'x h''x rw [← hx h''x] exact h'x h''x rw [← this] exact integral_congr_ae hf.ae_eq_mk #align measure_theory.set_integral_eq_zero_of_ae_eq_zero MeasureTheory.setIntegral_eq_zero_of_ae_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_of_ae_eq_zero := setIntegral_eq_zero_of_ae_eq_zero theorem setIntegral_eq_zero_of_forall_eq_zero (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in t, f x ∂μ = 0 := setIntegral_eq_zero_of_ae_eq_zero (eventually_of_forall ht_eq) #align measure_theory.set_integral_eq_zero_of_forall_eq_zero MeasureTheory.setIntegral_eq_zero_of_forall_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_of_forall_eq_zero := setIntegral_eq_zero_of_forall_eq_zero theorem integral_union_eq_left_of_ae_aux (ht_eq : ∀ᵐ x ∂μ.restrict t, f x = 0) (haux : StronglyMeasurable f) (H : IntegrableOn f (s ∪ t) μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := by let k := f ⁻¹' {0} have hk : MeasurableSet k := by borelize E; exact haux.measurable (measurableSet_singleton _) have h's : IntegrableOn f s μ := H.mono subset_union_left le_rfl have A : ∀ u : Set X, ∫ x in u ∩ k, f x ∂μ = 0 := fun u => setIntegral_eq_zero_of_forall_eq_zero fun x hx => hx.2 rw [← integral_inter_add_diff hk h's, ← integral_inter_add_diff hk H, A, A, zero_add, zero_add, union_diff_distrib, union_comm] apply setIntegral_congr_set_ae rw [union_ae_eq_right] apply measure_mono_null diff_subset rw [measure_zero_iff_ae_nmem] filter_upwards [ae_imp_of_ae_restrict ht_eq] with x hx h'x using h'x.2 (hx h'x.1) #align measure_theory.integral_union_eq_left_of_ae_aux MeasureTheory.integral_union_eq_left_of_ae_aux theorem integral_union_eq_left_of_ae (ht_eq : ∀ᵐ x ∂μ.restrict t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := by have ht : IntegrableOn f t μ := by apply integrableOn_zero.congr_fun_ae; symm; exact ht_eq by_cases H : IntegrableOn f (s ∪ t) μ; swap · rw [integral_undef H, integral_undef]; simpa [integrableOn_union, ht] using H let f' := H.1.mk f calc ∫ x : X in s ∪ t, f x ∂μ = ∫ x : X in s ∪ t, f' x ∂μ := integral_congr_ae H.1.ae_eq_mk _ = ∫ x in s, f' x ∂μ := by apply integral_union_eq_left_of_ae_aux _ H.1.stronglyMeasurable_mk (H.congr_fun_ae H.1.ae_eq_mk) filter_upwards [ht_eq, ae_mono (Measure.restrict_mono subset_union_right le_rfl) H.1.ae_eq_mk] with x hx h'x rw [← h'x, hx] _ = ∫ x in s, f x ∂μ := integral_congr_ae (ae_mono (Measure.restrict_mono subset_union_left le_rfl) H.1.ae_eq_mk.symm) #align measure_theory.integral_union_eq_left_of_ae MeasureTheory.integral_union_eq_left_of_ae theorem integral_union_eq_left_of_forall₀ {f : X → E} (ht : NullMeasurableSet t μ) (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_union_eq_left_of_ae ((ae_restrict_iff'₀ ht).2 (eventually_of_forall ht_eq)) #align measure_theory.integral_union_eq_left_of_forall₀ MeasureTheory.integral_union_eq_left_of_forall₀ theorem integral_union_eq_left_of_forall {f : X → E} (ht : MeasurableSet t) (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_union_eq_left_of_forall₀ ht.nullMeasurableSet ht_eq #align measure_theory.integral_union_eq_left_of_forall MeasureTheory.integral_union_eq_left_of_forall theorem setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux (hts : s ⊆ t) (h't : ∀ᵐ x ∂μ, x ∈ t \ s → f x = 0) (haux : StronglyMeasurable f) (h'aux : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := by let k := f ⁻¹' {0} have hk : MeasurableSet k := by borelize E; exact haux.measurable (measurableSet_singleton _) calc ∫ x in t, f x ∂μ = ∫ x in t ∩ k, f x ∂μ + ∫ x in t \ k, f x ∂μ := by rw [integral_inter_add_diff hk h'aux] _ = ∫ x in t \ k, f x ∂μ := by rw [setIntegral_eq_zero_of_forall_eq_zero fun x hx => ?_, zero_add]; exact hx.2 _ = ∫ x in s \ k, f x ∂μ := by apply setIntegral_congr_set_ae filter_upwards [h't] with x hx change (x ∈ t \ k) = (x ∈ s \ k) simp only [mem_preimage, mem_singleton_iff, eq_iff_iff, and_congr_left_iff, mem_diff] intro h'x by_cases xs : x ∈ s · simp only [xs, hts xs] · simp only [xs, iff_false_iff] intro xt exact h'x (hx ⟨xt, xs⟩) _ = ∫ x in s ∩ k, f x ∂μ + ∫ x in s \ k, f x ∂μ := by have : ∀ x ∈ s ∩ k, f x = 0 := fun x hx => hx.2 rw [setIntegral_eq_zero_of_forall_eq_zero this, zero_add] _ = ∫ x in s, f x ∂μ := by rw [integral_inter_add_diff hk (h'aux.mono hts le_rfl)] #align measure_theory.set_integral_eq_of_subset_of_ae_diff_eq_zero_aux MeasureTheory.setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_ae_diff_eq_zero_aux := setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux /-- If a function vanishes almost everywhere on `t \ s` with `s ⊆ t`, then its integrals on `s` and `t` coincide if `t` is null-measurable. -/ theorem setIntegral_eq_of_subset_of_ae_diff_eq_zero (ht : NullMeasurableSet t μ) (hts : s ⊆ t) (h't : ∀ᵐ x ∂μ, x ∈ t \ s → f x = 0) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := by by_cases h : IntegrableOn f t μ; swap · have : ¬IntegrableOn f s μ := fun H => h (H.of_ae_diff_eq_zero ht h't) rw [integral_undef h, integral_undef this] let f' := h.1.mk f calc ∫ x in t, f x ∂μ = ∫ x in t, f' x ∂μ := integral_congr_ae h.1.ae_eq_mk _ = ∫ x in s, f' x ∂μ := by apply setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux hts _ h.1.stronglyMeasurable_mk (h.congr h.1.ae_eq_mk) filter_upwards [h't, ae_imp_of_ae_restrict h.1.ae_eq_mk] with x hx h'x h''x rw [← h'x h''x.1, hx h''x] _ = ∫ x in s, f x ∂μ := by apply integral_congr_ae apply ae_restrict_of_ae_restrict_of_subset hts exact h.1.ae_eq_mk.symm #align measure_theory.set_integral_eq_of_subset_of_ae_diff_eq_zero MeasureTheory.setIntegral_eq_of_subset_of_ae_diff_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_ae_diff_eq_zero := setIntegral_eq_of_subset_of_ae_diff_eq_zero /-- If a function vanishes on `t \ s` with `s ⊆ t`, then its integrals on `s` and `t` coincide if `t` is measurable. -/ theorem setIntegral_eq_of_subset_of_forall_diff_eq_zero (ht : MeasurableSet t) (hts : s ⊆ t) (h't : ∀ x ∈ t \ s, f x = 0) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := setIntegral_eq_of_subset_of_ae_diff_eq_zero ht.nullMeasurableSet hts (eventually_of_forall fun x hx => h't x hx) #align measure_theory.set_integral_eq_of_subset_of_forall_diff_eq_zero MeasureTheory.setIntegral_eq_of_subset_of_forall_diff_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_forall_diff_eq_zero := setIntegral_eq_of_subset_of_forall_diff_eq_zero /-- If a function vanishes almost everywhere on `sᶜ`, then its integral on `s` coincides with its integral on the whole space. -/ theorem setIntegral_eq_integral_of_ae_compl_eq_zero (h : ∀ᵐ x ∂μ, x ∉ s → f x = 0) : ∫ x in s, f x ∂μ = ∫ x, f x ∂μ := by symm nth_rw 1 [← integral_univ] apply setIntegral_eq_of_subset_of_ae_diff_eq_zero nullMeasurableSet_univ (subset_univ _) filter_upwards [h] with x hx h'x using hx h'x.2 #align measure_theory.set_integral_eq_integral_of_ae_compl_eq_zero MeasureTheory.setIntegral_eq_integral_of_ae_compl_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_integral_of_ae_compl_eq_zero := setIntegral_eq_integral_of_ae_compl_eq_zero /-- If a function vanishes on `sᶜ`, then its integral on `s` coincides with its integral on the whole space. -/ theorem setIntegral_eq_integral_of_forall_compl_eq_zero (h : ∀ x, x ∉ s → f x = 0) : ∫ x in s, f x ∂μ = ∫ x, f x ∂μ := setIntegral_eq_integral_of_ae_compl_eq_zero (eventually_of_forall h) #align measure_theory.set_integral_eq_integral_of_forall_compl_eq_zero MeasureTheory.setIntegral_eq_integral_of_forall_compl_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_integral_of_forall_compl_eq_zero := setIntegral_eq_integral_of_forall_compl_eq_zero
Mathlib/MeasureTheory/Integral/SetIntegral.lean
482
492
theorem setIntegral_neg_eq_setIntegral_nonpos [LinearOrder E] {f : X → E} (hf : AEStronglyMeasurable f μ) : ∫ x in {x | f x < 0}, f x ∂μ = ∫ x in {x | f x ≤ 0}, f x ∂μ := by
have h_union : {x | f x ≤ 0} = {x | f x < 0} ∪ {x | f x = 0} := by simp_rw [le_iff_lt_or_eq, setOf_or] rw [h_union] have B : NullMeasurableSet {x | f x = 0} μ := hf.nullMeasurableSet_eq_fun aestronglyMeasurable_zero symm refine integral_union_eq_left_of_ae ?_ filter_upwards [ae_restrict_mem₀ B] with x hx using hx
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Yury G. Kudryashov -/ import Mathlib.Logic.Function.Basic import Mathlib.Tactic.MkIffOfInductiveProp #align_import data.sum.basic from "leanprover-community/mathlib"@"bd9851ca476957ea4549eb19b40e7b5ade9428cc" /-! # Additional lemmas about sum types Most of the former contents of this file have been moved to Batteries. -/ universe u v w x variable {α : Type u} {α' : Type w} {β : Type v} {β' : Type x} {γ δ : Type*} namespace Sum #align sum.forall Sum.forall #align sum.exists Sum.exists theorem exists_sum {γ : α ⊕ β → Sort*} (p : (∀ ab, γ ab) → Prop) : (∃ fab, p fab) ↔ (∃ fa fb, p (Sum.rec fa fb)) := by rw [← not_forall_not, forall_sum] simp theorem inl_injective : Function.Injective (inl : α → Sum α β) := fun _ _ ↦ inl.inj #align sum.inl_injective Sum.inl_injective theorem inr_injective : Function.Injective (inr : β → Sum α β) := fun _ _ ↦ inr.inj #align sum.inr_injective Sum.inr_injective theorem sum_rec_congr (P : α ⊕ β → Sort*) (f : ∀ i, P (inl i)) (g : ∀ i, P (inr i)) {x y : α ⊕ β} (h : x = y) : @Sum.rec _ _ _ f g x = cast (congr_arg P h.symm) (@Sum.rec _ _ _ f g y) := by cases h; rfl section get #align sum.is_left Sum.isLeft #align sum.is_right Sum.isRight #align sum.get_left Sum.getLeft? #align sum.get_right Sum.getRight? variable {x y : Sum α β} #align sum.get_left_eq_none_iff Sum.getLeft?_eq_none_iff #align sum.get_right_eq_none_iff Sum.getRight?_eq_none_iff theorem eq_left_iff_getLeft_eq {a : α} : x = inl a ↔ ∃ h, x.getLeft h = a := by cases x <;> simp theorem eq_right_iff_getRight_eq {b : β} : x = inr b ↔ ∃ h, x.getRight h = b := by cases x <;> simp #align sum.get_left_eq_some_iff Sum.getLeft?_eq_some_iff #align sum.get_right_eq_some_iff Sum.getRight?_eq_some_iff
Mathlib/Data/Sum/Basic.lean
63
64
theorem getLeft_eq_getLeft? (h₁ : x.isLeft) (h₂ : x.getLeft?.isSome) : x.getLeft h₁ = x.getLeft?.get h₂ := by
simp [← getLeft?_eq_some_iff]
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov, David Loeffler -/ import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Convex.Slope /-! # Convexity of functions and derivatives Here we relate convexity of functions `ℝ → ℝ` to properties of their derivatives. ## Main results * `MonotoneOn.convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `ConvexOn.monotoneOn_deriv`: if a function is convex and differentiable, then its derivative is monotone. -/ open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ## Monotonicity of `f'` implies convexity of `f` -/ /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is monotone on the interior, then `f` is convex on `D`. -/ theorem MonotoneOn.convexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn ℝ D f := convexOn_of_slope_mono_adjacent hD (by intro x y z hx hz hxy hyz -- First we prove some trivial inclusions have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD have hyzD' : Ioo y z ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩ -- Then we apply MVT to both `[x, y]` and `[y, z]` obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD') obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b = (f z - f y) / (z - y) := exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD') rw [← ha, ← hb] exact hf'_mono (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb).le) #align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is antitone on the interior, then `f` is concave on `D`. -/ theorem AntitoneOn.concaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn ℝ D f := haveI : MonotoneOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg) #align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem => (differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy hf A rcases nonempty_Ioo.2 hay with ⟨b, ⟨hab, hby⟩⟩ refine ⟨b, ⟨hxa.trans hab, hby⟩, ?_⟩ rw [← ha] exact hf'_mono ⟨hxa, hay⟩ ⟨hxa.trans hab, hby⟩ hab #align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
Mathlib/Analysis/Convex/Deriv.lean
78
108
theorem StrictMonoOn.exists_slope_lt_deriv {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0 · apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h · push_neg at h rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩ obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, (f w - f x) / (w - x) < deriv f a := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _ · exact hf.mono (Icc_subset_Icc le_rfl hwy.le) · exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) · intro z hz rw [← hw] apply ne_of_lt exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2 obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, (f y - f w) / (y - w) < deriv f b := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _ · refine hf.mono (Icc_subset_Icc hxw.le le_rfl) · exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) · intro z hz rw [← hw] apply ne_of_gt exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1 refine ⟨b, ⟨hxw.trans hwb, hby⟩, ?_⟩ simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb ⊢ have : deriv f a * (w - x) < deriv f b * (w - x) := by apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _ · exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb) · rw [← hw] exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le linarith
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Data.Finset.Prod import Mathlib.Data.Sym.Basic import Mathlib.Data.Sym.Sym2.Init import Mathlib.Data.SetLike.Basic #align_import data.sym.sym2 from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # The symmetric square This file defines the symmetric square, which is `α × α` modulo swapping. This is also known as the type of unordered pairs. More generally, the symmetric square is the second symmetric power (see `Data.Sym.Basic`). The equivalence is `Sym2.equivSym`. From the point of view that an unordered pair is equivalent to a multiset of cardinality two (see `Sym2.equivMultiset`), there is a `Mem` instance `Sym2.Mem`, which is a `Prop`-valued membership test. Given `h : a ∈ z` for `z : Sym2 α`, then `Mem.other h` is the other element of the pair, defined using `Classical.choice`. If `α` has decidable equality, then `h.other'` computably gives the other element. The universal property of `Sym2` is provided as `Sym2.lift`, which states that functions from `Sym2 α` are equivalent to symmetric two-argument functions from `α`. Recall that an undirected graph (allowing self loops, but no multiple edges) is equivalent to a symmetric relation on the vertex type `α`. Given a symmetric relation on `α`, the corresponding edge set is constructed by `Sym2.fromRel` which is a special case of `Sym2.lift`. ## Notation The element `Sym2.mk (a, b)` can be written as `s(a, b)` for short. ## Tags symmetric square, unordered pairs, symmetric powers -/ assert_not_exists MonoidWithZero open Finset Function Sym universe u variable {α β γ : Type*} namespace Sym2 /-- This is the relation capturing the notion of pairs equivalent up to permutations. -/ @[aesop (rule_sets := [Sym2]) [safe [constructors, cases], norm]] inductive Rel (α : Type u) : α × α → α × α → Prop | refl (x y : α) : Rel _ (x, y) (x, y) | swap (x y : α) : Rel _ (x, y) (y, x) #align sym2.rel Sym2.Rel #align sym2.rel.refl Sym2.Rel.refl #align sym2.rel.swap Sym2.Rel.swap attribute [refl] Rel.refl @[symm] theorem Rel.symm {x y : α × α} : Rel α x y → Rel α y x := by aesop (rule_sets := [Sym2]) #align sym2.rel.symm Sym2.Rel.symm @[trans] theorem Rel.trans {x y z : α × α} (a : Rel α x y) (b : Rel α y z) : Rel α x z := by aesop (rule_sets := [Sym2]) #align sym2.rel.trans Sym2.Rel.trans theorem Rel.is_equivalence : Equivalence (Rel α) := { refl := fun (x, y) ↦ Rel.refl x y, symm := Rel.symm, trans := Rel.trans } #align sym2.rel.is_equivalence Sym2.Rel.is_equivalence /-- One can use `attribute [local instance] Sym2.Rel.setoid` to temporarily make `Quotient` functionality work for `α × α`. -/ def Rel.setoid (α : Type u) : Setoid (α × α) := ⟨Rel α, Rel.is_equivalence⟩ #align sym2.rel.setoid Sym2.Rel.setoid @[simp] theorem rel_iff' {p q : α × α} : Rel α p q ↔ p = q ∨ p = q.swap := by aesop (rule_sets := [Sym2]) theorem rel_iff {x y z w : α} : Rel α (x, y) (z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp #align sym2.rel_iff Sym2.rel_iff end Sym2 /-- `Sym2 α` is the symmetric square of `α`, which, in other words, is the type of unordered pairs. It is equivalent in a natural way to multisets of cardinality 2 (see `Sym2.equivMultiset`). -/ abbrev Sym2 (α : Type u) := Quot (Sym2.Rel α) #align sym2 Sym2 /-- Constructor for `Sym2`. This is the quotient map `α × α → Sym2 α`. -/ protected abbrev Sym2.mk {α : Type*} (p : α × α) : Sym2 α := Quot.mk (Sym2.Rel α) p /-- `s(x, y)` is an unordered pair, which is to say a pair modulo the action of the symmetric group. It is equal to `Sym2.mk (x, y)`. -/ notation3 "s(" x ", " y ")" => Sym2.mk (x, y) namespace Sym2 protected theorem sound {p p' : α × α} (h : Sym2.Rel α p p') : Sym2.mk p = Sym2.mk p' := Quot.sound h protected theorem exact {p p' : α × α} (h : Sym2.mk p = Sym2.mk p') : Sym2.Rel α p p' := Quotient.exact (s := Sym2.Rel.setoid α) h @[simp] protected theorem eq {p p' : α × α} : Sym2.mk p = Sym2.mk p' ↔ Sym2.Rel α p p' := Quotient.eq' (s₁ := Sym2.Rel.setoid α) @[elab_as_elim] protected theorem ind {f : Sym2 α → Prop} (h : ∀ x y, f s(x, y)) : ∀ i, f i := Quot.ind <| Prod.rec <| h #align sym2.ind Sym2.ind @[elab_as_elim] protected theorem inductionOn {f : Sym2 α → Prop} (i : Sym2 α) (hf : ∀ x y, f s(x, y)) : f i := i.ind hf #align sym2.induction_on Sym2.inductionOn @[elab_as_elim] protected theorem inductionOn₂ {f : Sym2 α → Sym2 β → Prop} (i : Sym2 α) (j : Sym2 β) (hf : ∀ a₁ a₂ b₁ b₂, f s(a₁, a₂) s(b₁, b₂)) : f i j := Quot.induction_on₂ i j <| by intro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ exact hf _ _ _ _ #align sym2.induction_on₂ Sym2.inductionOn₂ /-- Dependent recursion principal for `Sym2`. See `Quot.rec`. -/ @[elab_as_elim] protected def rec {motive : Sym2 α → Sort*} (f : (p : α × α) → motive (Sym2.mk p)) (h : (p q : α × α) → (h : Sym2.Rel α p q) → Eq.ndrec (f p) (Sym2.sound h) = f q) (z : Sym2 α) : motive z := Quot.rec f h z /-- Dependent recursion principal for `Sym2` when the target is a `Subsingleton` type. See `Quot.recOnSubsingleton`. -/ @[elab_as_elim] protected abbrev recOnSubsingleton {motive : Sym2 α → Sort*} [(p : α × α) → Subsingleton (motive (Sym2.mk p))] (z : Sym2 α) (f : (p : α × α) → motive (Sym2.mk p)) : motive z := Quot.recOnSubsingleton z f protected theorem «exists» {α : Sort _} {f : Sym2 α → Prop} : (∃ x : Sym2 α, f x) ↔ ∃ x y, f s(x, y) := (surjective_quot_mk _).exists.trans Prod.exists #align sym2.exists Sym2.exists protected theorem «forall» {α : Sort _} {f : Sym2 α → Prop} : (∀ x : Sym2 α, f x) ↔ ∀ x y, f s(x, y) := (surjective_quot_mk _).forall.trans Prod.forall #align sym2.forall Sym2.forall theorem eq_swap {a b : α} : s(a, b) = s(b, a) := Quot.sound (Rel.swap _ _) #align sym2.eq_swap Sym2.eq_swap @[simp] theorem mk_prod_swap_eq {p : α × α} : Sym2.mk p.swap = Sym2.mk p := by cases p exact eq_swap #align sym2.mk_prod_swap_eq Sym2.mk_prod_swap_eq theorem congr_right {a b c : α} : s(a, b) = s(a, c) ↔ b = c := by simp (config := {contextual := true}) #align sym2.congr_right Sym2.congr_right theorem congr_left {a b c : α} : s(b, a) = s(c, a) ↔ b = c := by simp (config := {contextual := true}) #align sym2.congr_left Sym2.congr_left theorem eq_iff {x y z w : α} : s(x, y) = s(z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp #align sym2.eq_iff Sym2.eq_iff theorem mk_eq_mk_iff {p q : α × α} : Sym2.mk p = Sym2.mk q ↔ p = q ∨ p = q.swap := by cases p cases q simp only [eq_iff, Prod.mk.inj_iff, Prod.swap_prod_mk] #align sym2.mk_eq_mk_iff Sym2.mk_eq_mk_iff /-- The universal property of `Sym2`; symmetric functions of two arguments are equivalent to functions from `Sym2`. Note that when `β` is `Prop`, it can sometimes be more convenient to use `Sym2.fromRel` instead. -/ def lift : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ } ≃ (Sym2 α → β) where toFun f := Quot.lift (uncurry ↑f) <| by rintro _ _ ⟨⟩ exacts [rfl, f.prop _ _] invFun F := ⟨curry (F ∘ Sym2.mk), fun a₁ a₂ => congr_arg F eq_swap⟩ left_inv f := Subtype.ext rfl right_inv F := funext <| Sym2.ind fun x y => rfl #align sym2.lift Sym2.lift @[simp] theorem lift_mk (f : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ }) (a₁ a₂ : α) : lift f s(a₁, a₂) = (f : α → α → β) a₁ a₂ := rfl #align sym2.lift_mk Sym2.lift_mk @[simp] theorem coe_lift_symm_apply (F : Sym2 α → β) (a₁ a₂ : α) : (lift.symm F : α → α → β) a₁ a₂ = F s(a₁, a₂) := rfl #align sym2.coe_lift_symm_apply Sym2.coe_lift_symm_apply /-- A two-argument version of `Sym2.lift`. -/ def lift₂ : { f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ } ≃ (Sym2 α → Sym2 β → γ) where toFun f := Quotient.lift₂ (s₁ := Sym2.Rel.setoid α) (s₂ := Sym2.Rel.setoid β) (fun (a : α × α) (b : β × β) => f.1 a.1 a.2 b.1 b.2) (by rintro _ _ _ _ ⟨⟩ ⟨⟩ exacts [rfl, (f.2 _ _ _ _).2, (f.2 _ _ _ _).1, (f.2 _ _ _ _).1.trans (f.2 _ _ _ _).2]) invFun F := ⟨fun a₁ a₂ b₁ b₂ => F s(a₁, a₂) s(b₁, b₂), fun a₁ a₂ b₁ b₂ => by constructor exacts [congr_arg₂ F eq_swap rfl, congr_arg₂ F rfl eq_swap]⟩ left_inv f := Subtype.ext rfl right_inv F := funext₂ fun a b => Sym2.inductionOn₂ a b fun _ _ _ _ => rfl #align sym2.lift₂ Sym2.lift₂ @[simp] theorem lift₂_mk (f : { f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ }) (a₁ a₂ : α) (b₁ b₂ : β) : lift₂ f s(a₁, a₂) s(b₁, b₂) = (f : α → α → β → β → γ) a₁ a₂ b₁ b₂ := rfl #align sym2.lift₂_mk Sym2.lift₂_mk @[simp] theorem coe_lift₂_symm_apply (F : Sym2 α → Sym2 β → γ) (a₁ a₂ : α) (b₁ b₂ : β) : (lift₂.symm F : α → α → β → β → γ) a₁ a₂ b₁ b₂ = F s(a₁, a₂) s(b₁, b₂) := rfl #align sym2.coe_lift₂_symm_apply Sym2.coe_lift₂_symm_apply /-- The functor `Sym2` is functorial, and this function constructs the induced maps. -/ def map (f : α → β) : Sym2 α → Sym2 β := Quot.map (Prod.map f f) (by intro _ _ h; cases h <;> constructor) #align sym2.map Sym2.map @[simp] theorem map_id : map (@id α) = id := by ext ⟨⟨x, y⟩⟩ rfl #align sym2.map_id Sym2.map_id
Mathlib/Data/Sym/Sym2.lean
270
272
theorem map_comp {g : β → γ} {f : α → β} : Sym2.map (g ∘ f) = Sym2.map g ∘ Sym2.map f := by
ext ⟨⟨x, y⟩⟩ rfl
/- 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.CharP.Invertible import Mathlib.Algebra.Order.Invertible import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Algebra.Order.Group.Instances import Mathlib.LinearAlgebra.AffineSpace.Slope import Mathlib.LinearAlgebra.AffineSpace.Midpoint import Mathlib.Tactic.FieldSimp #align_import linear_algebra.affine_space.ordered from "leanprover-community/mathlib"@"78261225eb5cedc61c5c74ecb44e5b385d13b733" /-! # Ordered modules as affine spaces In this file we prove some theorems about `slope` and `lineMap` in the case when the module `E` acting on the codomain `PE` of a function is an ordered module over its domain `k`. We also prove inequalities that can be used to link convexity of a function on an interval to monotonicity of the slope, see section docstring below for details. ## Implementation notes We do not introduce the notion of ordered affine spaces (yet?). Instead, we prove various theorems for an ordered module interpreted as an affine space. ## Tags affine space, ordered module, slope -/ open AffineMap variable {k E PE : Type*} /-! ### Monotonicity of `lineMap` In this section we prove that `lineMap a b r` is monotone (strictly or not) in its arguments if other arguments belong to specific domains. -/ section OrderedRing variable [OrderedRing k] [OrderedAddCommGroup E] [Module k E] [OrderedSMul k E] variable {a a' b b' : E} {r r' : k} theorem lineMap_mono_left (ha : a ≤ a') (hr : r ≤ 1) : lineMap a b r ≤ lineMap a' b r := by simp only [lineMap_apply_module] exact add_le_add_right (smul_le_smul_of_nonneg_left ha (sub_nonneg.2 hr)) _ #align line_map_mono_left lineMap_mono_left theorem lineMap_strict_mono_left (ha : a < a') (hr : r < 1) : lineMap a b r < lineMap a' b r := by simp only [lineMap_apply_module] exact add_lt_add_right (smul_lt_smul_of_pos_left ha (sub_pos.2 hr)) _ #align line_map_strict_mono_left lineMap_strict_mono_left theorem lineMap_mono_right (hb : b ≤ b') (hr : 0 ≤ r) : lineMap a b r ≤ lineMap a b' r := by simp only [lineMap_apply_module] exact add_le_add_left (smul_le_smul_of_nonneg_left hb hr) _ #align line_map_mono_right lineMap_mono_right
Mathlib/LinearAlgebra/AffineSpace/Ordered.lean
67
69
theorem lineMap_strict_mono_right (hb : b < b') (hr : 0 < r) : lineMap a b r < lineMap a b' r := by
simp only [lineMap_apply_module] exact add_lt_add_left (smul_lt_smul_of_pos_left hb hr) _
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Sub.Defs import Mathlib.Util.AssertExists #align_import algebra.order.group.defs from "leanprover-community/mathlib"@"b599f4e4e5cf1fbcb4194503671d3d9e569c1fce" /-! # Ordered groups This file develops the basics of ordered groups. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ open Function universe u variable {α : Type u} /-- An ordered additive commutative group is an additive commutative group with a partial order in which addition is strictly monotone. -/ class OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where /-- Addition is monotone in an ordered additive commutative group. -/ protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b #align ordered_add_comm_group OrderedAddCommGroup /-- An ordered commutative group is a commutative group with a partial order in which multiplication is strictly monotone. -/ class OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where /-- Multiplication is monotone in an ordered commutative group. -/ protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b #align ordered_comm_group OrderedCommGroup attribute [to_additive] OrderedCommGroup @[to_additive] instance OrderedCommGroup.to_covariantClass_left_le (α : Type u) [OrderedCommGroup α] : CovariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := OrderedCommGroup.mul_le_mul_left b c bc a #align ordered_comm_group.to_covariant_class_left_le OrderedCommGroup.to_covariantClass_left_le #align ordered_add_comm_group.to_covariant_class_left_le OrderedAddCommGroup.to_covariantClass_left_le -- See note [lower instance priority] @[to_additive OrderedAddCommGroup.toOrderedCancelAddCommMonoid] instance (priority := 100) OrderedCommGroup.toOrderedCancelCommMonoid [OrderedCommGroup α] : OrderedCancelCommMonoid α := { ‹OrderedCommGroup α› with le_of_mul_le_mul_left := fun a b c ↦ le_of_mul_le_mul_left' } #align ordered_comm_group.to_ordered_cancel_comm_monoid OrderedCommGroup.toOrderedCancelCommMonoid #align ordered_add_comm_group.to_ordered_cancel_add_comm_monoid OrderedAddCommGroup.toOrderedCancelAddCommMonoid example (α : Type u) [OrderedAddCommGroup α] : CovariantClass α α (swap (· + ·)) (· < ·) := IsRightCancelAdd.covariant_swap_add_lt_of_covariant_swap_add_le α -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- It was introduced in https://github.com/leanprover-community/mathlib/pull/17564 -- but without the motivation clearly explained. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_left_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_left_le OrderedCommGroup.to_contravariantClass_left_le #align ordered_add_comm_group.to_contravariant_class_left_le OrderedAddCommGroup.to_contravariantClass_left_le -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- See further explanation on `OrderedCommGroup.to_contravariantClass_left_le`. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_right_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (swap (· * ·)) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_right' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_right_le OrderedCommGroup.to_contravariantClass_right_le #align ordered_add_comm_group.to_contravariant_class_right_le OrderedAddCommGroup.to_contravariantClass_right_le section Group variable [Group α] section TypeclassesLeftLE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [← mul_le_mul_iff_left a] simp #align left.inv_le_one_iff Left.inv_le_one_iff #align left.neg_nonpos_iff Left.neg_nonpos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [← mul_le_mul_iff_left a] simp #align left.one_le_inv_iff Left.one_le_inv_iff #align left.nonneg_neg_iff Left.nonneg_neg_iff @[to_additive (attr := simp)] theorem le_inv_mul_iff_mul_le : b ≤ a⁻¹ * c ↔ a * b ≤ c := by rw [← mul_le_mul_iff_left a] simp #align le_inv_mul_iff_mul_le le_inv_mul_iff_mul_le #align le_neg_add_iff_add_le le_neg_add_iff_add_le @[to_additive (attr := simp)] theorem inv_mul_le_iff_le_mul : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [← mul_le_mul_iff_left b, mul_inv_cancel_left] #align inv_mul_le_iff_le_mul inv_mul_le_iff_le_mul #align neg_add_le_iff_le_add neg_add_le_iff_le_add @[to_additive neg_le_iff_add_nonneg'] theorem inv_le_iff_one_le_mul' : a⁻¹ ≤ b ↔ 1 ≤ a * b := (mul_le_mul_iff_left a).symm.trans <| by rw [mul_inv_self] #align inv_le_iff_one_le_mul' inv_le_iff_one_le_mul' #align neg_le_iff_add_nonneg' neg_le_iff_add_nonneg' @[to_additive] theorem le_inv_iff_mul_le_one_left : a ≤ b⁻¹ ↔ b * a ≤ 1 := (mul_le_mul_iff_left b).symm.trans <| by rw [mul_inv_self] #align le_inv_iff_mul_le_one_left le_inv_iff_mul_le_one_left #align le_neg_iff_add_nonpos_left le_neg_iff_add_nonpos_left @[to_additive] theorem le_inv_mul_iff_le : 1 ≤ b⁻¹ * a ↔ b ≤ a := by rw [← mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left] #align le_inv_mul_iff_le le_inv_mul_iff_le #align le_neg_add_iff_le le_neg_add_iff_le @[to_additive] theorem inv_mul_le_one_iff : a⁻¹ * b ≤ 1 ↔ b ≤ a := -- Porting note: why is the `_root_` needed? _root_.trans inv_mul_le_iff_le_mul <| by rw [mul_one] #align inv_mul_le_one_iff inv_mul_le_one_iff #align neg_add_nonpos_iff neg_add_nonpos_iff end TypeclassesLeftLE section TypeclassesLeftLT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) Left.neg_pos_iff "Uses `left` co(ntra)variant."] theorem Left.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] #align left.one_lt_inv_iff Left.one_lt_inv_iff #align left.neg_pos_iff Left.neg_pos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] #align left.inv_lt_one_iff Left.inv_lt_one_iff #align left.neg_neg_iff Left.neg_neg_iff @[to_additive (attr := simp)] theorem lt_inv_mul_iff_mul_lt : b < a⁻¹ * c ↔ a * b < c := by rw [← mul_lt_mul_iff_left a] simp #align lt_inv_mul_iff_mul_lt lt_inv_mul_iff_mul_lt #align lt_neg_add_iff_add_lt lt_neg_add_iff_add_lt @[to_additive (attr := simp)] theorem inv_mul_lt_iff_lt_mul : b⁻¹ * a < c ↔ a < b * c := by rw [← mul_lt_mul_iff_left b, mul_inv_cancel_left] #align inv_mul_lt_iff_lt_mul inv_mul_lt_iff_lt_mul #align neg_add_lt_iff_lt_add neg_add_lt_iff_lt_add @[to_additive] theorem inv_lt_iff_one_lt_mul' : a⁻¹ < b ↔ 1 < a * b := (mul_lt_mul_iff_left a).symm.trans <| by rw [mul_inv_self] #align inv_lt_iff_one_lt_mul' inv_lt_iff_one_lt_mul' #align neg_lt_iff_pos_add' neg_lt_iff_pos_add' @[to_additive] theorem lt_inv_iff_mul_lt_one' : a < b⁻¹ ↔ b * a < 1 := (mul_lt_mul_iff_left b).symm.trans <| by rw [mul_inv_self] #align lt_inv_iff_mul_lt_one' lt_inv_iff_mul_lt_one' #align lt_neg_iff_add_neg' lt_neg_iff_add_neg' @[to_additive] theorem lt_inv_mul_iff_lt : 1 < b⁻¹ * a ↔ b < a := by rw [← mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left] #align lt_inv_mul_iff_lt lt_inv_mul_iff_lt #align lt_neg_add_iff_lt lt_neg_add_iff_lt @[to_additive] theorem inv_mul_lt_one_iff : a⁻¹ * b < 1 ↔ b < a := _root_.trans inv_mul_lt_iff_lt_mul <| by rw [mul_one] #align inv_mul_lt_one_iff inv_mul_lt_one_iff #align neg_add_neg_iff neg_add_neg_iff end TypeclassesLeftLT section TypeclassesRightLE variable [LE α] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [← mul_le_mul_iff_right a] simp #align right.inv_le_one_iff Right.inv_le_one_iff #align right.neg_nonpos_iff Right.neg_nonpos_iff /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [← mul_le_mul_iff_right a] simp #align right.one_le_inv_iff Right.one_le_inv_iff #align right.nonneg_neg_iff Right.nonneg_neg_iff @[to_additive neg_le_iff_add_nonneg] theorem inv_le_iff_one_le_mul : a⁻¹ ≤ b ↔ 1 ≤ b * a := (mul_le_mul_iff_right a).symm.trans <| by rw [inv_mul_self] #align inv_le_iff_one_le_mul inv_le_iff_one_le_mul #align neg_le_iff_add_nonneg neg_le_iff_add_nonneg @[to_additive] theorem le_inv_iff_mul_le_one_right : a ≤ b⁻¹ ↔ a * b ≤ 1 := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_self] #align le_inv_iff_mul_le_one_right le_inv_iff_mul_le_one_right #align le_neg_iff_add_nonpos_right le_neg_iff_add_nonpos_right @[to_additive (attr := simp)] theorem mul_inv_le_iff_le_mul : a * b⁻¹ ≤ c ↔ a ≤ c * b := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align mul_inv_le_iff_le_mul mul_inv_le_iff_le_mul #align add_neg_le_iff_le_add add_neg_le_iff_le_add @[to_additive (attr := simp)] theorem le_mul_inv_iff_mul_le : c ≤ a * b⁻¹ ↔ c * b ≤ a := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align le_mul_inv_iff_mul_le le_mul_inv_iff_mul_le #align le_add_neg_iff_add_le le_add_neg_iff_add_le -- Porting note (#10618): `simp` can prove this @[to_additive] theorem mul_inv_le_one_iff_le : a * b⁻¹ ≤ 1 ↔ a ≤ b := mul_inv_le_iff_le_mul.trans <| by rw [one_mul] #align mul_inv_le_one_iff_le mul_inv_le_one_iff_le #align add_neg_nonpos_iff_le add_neg_nonpos_iff_le @[to_additive] theorem le_mul_inv_iff_le : 1 ≤ a * b⁻¹ ↔ b ≤ a := by rw [← mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right] #align le_mul_inv_iff_le le_mul_inv_iff_le #align le_add_neg_iff_le le_add_neg_iff_le @[to_additive] theorem mul_inv_le_one_iff : b * a⁻¹ ≤ 1 ↔ b ≤ a := _root_.trans mul_inv_le_iff_le_mul <| by rw [one_mul] #align mul_inv_le_one_iff mul_inv_le_one_iff #align add_neg_nonpos_iff add_neg_nonpos_iff end TypeclassesRightLE section TypeclassesRightLT variable [LT α] [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] #align right.inv_lt_one_iff Right.inv_lt_one_iff #align right.neg_neg_iff Right.neg_neg_iff /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) Right.neg_pos_iff "Uses `right` co(ntra)variant."] theorem Right.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] #align right.one_lt_inv_iff Right.one_lt_inv_iff #align right.neg_pos_iff Right.neg_pos_iff @[to_additive] theorem inv_lt_iff_one_lt_mul : a⁻¹ < b ↔ 1 < b * a := (mul_lt_mul_iff_right a).symm.trans <| by rw [inv_mul_self] #align inv_lt_iff_one_lt_mul inv_lt_iff_one_lt_mul #align neg_lt_iff_pos_add neg_lt_iff_pos_add @[to_additive] theorem lt_inv_iff_mul_lt_one : a < b⁻¹ ↔ a * b < 1 := (mul_lt_mul_iff_right b).symm.trans <| by rw [inv_mul_self] #align lt_inv_iff_mul_lt_one lt_inv_iff_mul_lt_one #align lt_neg_iff_add_neg lt_neg_iff_add_neg @[to_additive (attr := simp)] theorem mul_inv_lt_iff_lt_mul : a * b⁻¹ < c ↔ a < c * b := by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right] #align mul_inv_lt_iff_lt_mul mul_inv_lt_iff_lt_mul #align add_neg_lt_iff_lt_add add_neg_lt_iff_lt_add @[to_additive (attr := simp)] theorem lt_mul_inv_iff_mul_lt : c < a * b⁻¹ ↔ c * b < a := (mul_lt_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align lt_mul_inv_iff_mul_lt lt_mul_inv_iff_mul_lt #align lt_add_neg_iff_add_lt lt_add_neg_iff_add_lt -- Porting note (#10618): `simp` can prove this @[to_additive] theorem inv_mul_lt_one_iff_lt : a * b⁻¹ < 1 ↔ a < b := by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right, one_mul] #align inv_mul_lt_one_iff_lt inv_mul_lt_one_iff_lt #align neg_add_neg_iff_lt neg_add_neg_iff_lt @[to_additive] theorem lt_mul_inv_iff_lt : 1 < a * b⁻¹ ↔ b < a := by rw [← mul_lt_mul_iff_right b, one_mul, inv_mul_cancel_right] #align lt_mul_inv_iff_lt lt_mul_inv_iff_lt #align lt_add_neg_iff_lt lt_add_neg_iff_lt @[to_additive] theorem mul_inv_lt_one_iff : b * a⁻¹ < 1 ↔ b < a := _root_.trans mul_inv_lt_iff_lt_mul <| by rw [one_mul] #align mul_inv_lt_one_iff mul_inv_lt_one_iff #align add_neg_neg_iff add_neg_neg_iff end TypeclassesRightLT section TypeclassesLeftRightLE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c d : α} @[to_additive (attr := simp)] theorem inv_le_inv_iff : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← mul_le_mul_iff_left a, ← mul_le_mul_iff_right b] simp #align inv_le_inv_iff inv_le_inv_iff #align neg_le_neg_iff neg_le_neg_iff alias ⟨le_of_neg_le_neg, _⟩ := neg_le_neg_iff #align le_of_neg_le_neg le_of_neg_le_neg @[to_additive] theorem mul_inv_le_inv_mul_iff : a * b⁻¹ ≤ d⁻¹ * c ↔ d * a ≤ c * b := by rw [← mul_le_mul_iff_left d, ← mul_le_mul_iff_right b, mul_inv_cancel_left, mul_assoc, inv_mul_cancel_right] #align mul_inv_le_inv_mul_iff mul_inv_le_inv_mul_iff #align add_neg_le_neg_add_iff add_neg_le_neg_add_iff @[to_additive (attr := simp)] theorem div_le_self_iff (a : α) {b : α} : a / b ≤ a ↔ 1 ≤ b := by simp [div_eq_mul_inv] #align div_le_self_iff div_le_self_iff #align sub_le_self_iff sub_le_self_iff @[to_additive (attr := simp)] theorem le_div_self_iff (a : α) {b : α} : a ≤ a / b ↔ b ≤ 1 := by simp [div_eq_mul_inv] #align le_div_self_iff le_div_self_iff #align le_sub_self_iff le_sub_self_iff alias ⟨_, sub_le_self⟩ := sub_le_self_iff #align sub_le_self sub_le_self end TypeclassesLeftRightLE section TypeclassesLeftRightLT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c d : α} @[to_additive (attr := simp)] theorem inv_lt_inv_iff : a⁻¹ < b⁻¹ ↔ b < a := by rw [← mul_lt_mul_iff_left a, ← mul_lt_mul_iff_right b] simp #align inv_lt_inv_iff inv_lt_inv_iff #align neg_lt_neg_iff neg_lt_neg_iff @[to_additive neg_lt] theorem inv_lt' : a⁻¹ < b ↔ b⁻¹ < a := by rw [← inv_lt_inv_iff, inv_inv] #align inv_lt' inv_lt' #align neg_lt neg_lt @[to_additive lt_neg] theorem lt_inv' : a < b⁻¹ ↔ b < a⁻¹ := by rw [← inv_lt_inv_iff, inv_inv] #align lt_inv' lt_inv' #align lt_neg lt_neg alias ⟨lt_inv_of_lt_inv, _⟩ := lt_inv' #align lt_inv_of_lt_inv lt_inv_of_lt_inv attribute [to_additive] lt_inv_of_lt_inv #align lt_neg_of_lt_neg lt_neg_of_lt_neg alias ⟨inv_lt_of_inv_lt', _⟩ := inv_lt' #align inv_lt_of_inv_lt' inv_lt_of_inv_lt' attribute [to_additive neg_lt_of_neg_lt] inv_lt_of_inv_lt' #align neg_lt_of_neg_lt neg_lt_of_neg_lt @[to_additive] theorem mul_inv_lt_inv_mul_iff : a * b⁻¹ < d⁻¹ * c ↔ d * a < c * b := by rw [← mul_lt_mul_iff_left d, ← mul_lt_mul_iff_right b, mul_inv_cancel_left, mul_assoc, inv_mul_cancel_right] #align mul_inv_lt_inv_mul_iff mul_inv_lt_inv_mul_iff #align add_neg_lt_neg_add_iff add_neg_lt_neg_add_iff @[to_additive (attr := simp)] theorem div_lt_self_iff (a : α) {b : α} : a / b < a ↔ 1 < b := by simp [div_eq_mul_inv] #align div_lt_self_iff div_lt_self_iff #align sub_lt_self_iff sub_lt_self_iff alias ⟨_, sub_lt_self⟩ := sub_lt_self_iff #align sub_lt_self sub_lt_self end TypeclassesLeftRightLT section Preorder variable [Preorder α] section LeftLE variable [CovariantClass α α (· * ·) (· ≤ ·)] {a : α} @[to_additive] theorem Left.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a := le_trans (Left.inv_le_one_iff.mpr h) h #align left.inv_le_self Left.inv_le_self #align left.neg_le_self Left.neg_le_self alias neg_le_self := Left.neg_le_self #align neg_le_self neg_le_self @[to_additive] theorem Left.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ := le_trans h (Left.one_le_inv_iff.mpr h) #align left.self_le_inv Left.self_le_inv #align left.self_le_neg Left.self_le_neg end LeftLE section LeftLT variable [CovariantClass α α (· * ·) (· < ·)] {a : α} @[to_additive] theorem Left.inv_lt_self (h : 1 < a) : a⁻¹ < a := (Left.inv_lt_one_iff.mpr h).trans h #align left.inv_lt_self Left.inv_lt_self #align left.neg_lt_self Left.neg_lt_self alias neg_lt_self := Left.neg_lt_self #align neg_lt_self neg_lt_self @[to_additive] theorem Left.self_lt_inv (h : a < 1) : a < a⁻¹ := lt_trans h (Left.one_lt_inv_iff.mpr h) #align left.self_lt_inv Left.self_lt_inv #align left.self_lt_neg Left.self_lt_neg end LeftLT section RightLE variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a : α} @[to_additive] theorem Right.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a := le_trans (Right.inv_le_one_iff.mpr h) h #align right.inv_le_self Right.inv_le_self #align right.neg_le_self Right.neg_le_self @[to_additive] theorem Right.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ := le_trans h (Right.one_le_inv_iff.mpr h) #align right.self_le_inv Right.self_le_inv #align right.self_le_neg Right.self_le_neg end RightLE section RightLT variable [CovariantClass α α (swap (· * ·)) (· < ·)] {a : α} @[to_additive] theorem Right.inv_lt_self (h : 1 < a) : a⁻¹ < a := (Right.inv_lt_one_iff.mpr h).trans h #align right.inv_lt_self Right.inv_lt_self #align right.neg_lt_self Right.neg_lt_self @[to_additive] theorem Right.self_lt_inv (h : a < 1) : a < a⁻¹ := lt_trans h (Right.one_lt_inv_iff.mpr h) #align right.self_lt_inv Right.self_lt_inv #align right.self_lt_neg Right.self_lt_neg end RightLT end Preorder end Group section CommGroup variable [CommGroup α] section LE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} @[to_additive] theorem inv_mul_le_iff_le_mul' : c⁻¹ * a ≤ b ↔ a ≤ b * c := by rw [inv_mul_le_iff_le_mul, mul_comm] #align inv_mul_le_iff_le_mul' inv_mul_le_iff_le_mul' #align neg_add_le_iff_le_add' neg_add_le_iff_le_add' -- Porting note: `simp` simplifies LHS to `a ≤ c * b` @[to_additive] theorem mul_inv_le_iff_le_mul' : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [← inv_mul_le_iff_le_mul, mul_comm] #align mul_inv_le_iff_le_mul' mul_inv_le_iff_le_mul' #align add_neg_le_iff_le_add' add_neg_le_iff_le_add' @[to_additive add_neg_le_add_neg_iff] theorem mul_inv_le_mul_inv_iff' : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by rw [mul_comm c, mul_inv_le_inv_mul_iff, mul_comm] #align mul_inv_le_mul_inv_iff' mul_inv_le_mul_inv_iff' #align add_neg_le_add_neg_iff add_neg_le_add_neg_iff end LE section LT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c d : α} @[to_additive] theorem inv_mul_lt_iff_lt_mul' : c⁻¹ * a < b ↔ a < b * c := by rw [inv_mul_lt_iff_lt_mul, mul_comm] #align inv_mul_lt_iff_lt_mul' inv_mul_lt_iff_lt_mul' #align neg_add_lt_iff_lt_add' neg_add_lt_iff_lt_add' -- Porting note: `simp` simplifies LHS to `a < c * b` @[to_additive] theorem mul_inv_lt_iff_le_mul' : a * b⁻¹ < c ↔ a < b * c := by rw [← inv_mul_lt_iff_lt_mul, mul_comm] #align mul_inv_lt_iff_le_mul' mul_inv_lt_iff_le_mul' #align add_neg_lt_iff_le_add' add_neg_lt_iff_le_add' @[to_additive add_neg_lt_add_neg_iff] theorem mul_inv_lt_mul_inv_iff' : a * b⁻¹ < c * d⁻¹ ↔ a * d < c * b := by rw [mul_comm c, mul_inv_lt_inv_mul_iff, mul_comm] #align mul_inv_lt_mul_inv_iff' mul_inv_lt_mul_inv_iff' #align add_neg_lt_add_neg_iff add_neg_lt_add_neg_iff end LT end CommGroup alias ⟨one_le_of_inv_le_one, _⟩ := Left.inv_le_one_iff #align one_le_of_inv_le_one one_le_of_inv_le_one attribute [to_additive] one_le_of_inv_le_one #align nonneg_of_neg_nonpos nonneg_of_neg_nonpos alias ⟨le_one_of_one_le_inv, _⟩ := Left.one_le_inv_iff #align le_one_of_one_le_inv le_one_of_one_le_inv attribute [to_additive nonpos_of_neg_nonneg] le_one_of_one_le_inv #align nonpos_of_neg_nonneg nonpos_of_neg_nonneg alias ⟨lt_of_inv_lt_inv, _⟩ := inv_lt_inv_iff #align lt_of_inv_lt_inv lt_of_inv_lt_inv attribute [to_additive] lt_of_inv_lt_inv #align lt_of_neg_lt_neg lt_of_neg_lt_neg alias ⟨one_lt_of_inv_lt_one, _⟩ := Left.inv_lt_one_iff #align one_lt_of_inv_lt_one one_lt_of_inv_lt_one attribute [to_additive] one_lt_of_inv_lt_one #align pos_of_neg_neg pos_of_neg_neg alias inv_lt_one_iff_one_lt := Left.inv_lt_one_iff #align inv_lt_one_iff_one_lt inv_lt_one_iff_one_lt attribute [to_additive] inv_lt_one_iff_one_lt #align neg_neg_iff_pos neg_neg_iff_pos alias inv_lt_one' := Left.inv_lt_one_iff #align inv_lt_one' inv_lt_one' attribute [to_additive neg_lt_zero] inv_lt_one' #align neg_lt_zero neg_lt_zero alias ⟨inv_of_one_lt_inv, _⟩ := Left.one_lt_inv_iff #align inv_of_one_lt_inv inv_of_one_lt_inv attribute [to_additive neg_of_neg_pos] inv_of_one_lt_inv #align neg_of_neg_pos neg_of_neg_pos alias ⟨_, one_lt_inv_of_inv⟩ := Left.one_lt_inv_iff #align one_lt_inv_of_inv one_lt_inv_of_inv attribute [to_additive neg_pos_of_neg] one_lt_inv_of_inv #align neg_pos_of_neg neg_pos_of_neg alias ⟨mul_le_of_le_inv_mul, _⟩ := le_inv_mul_iff_mul_le #align mul_le_of_le_inv_mul mul_le_of_le_inv_mul attribute [to_additive] mul_le_of_le_inv_mul #align add_le_of_le_neg_add add_le_of_le_neg_add alias ⟨_, le_inv_mul_of_mul_le⟩ := le_inv_mul_iff_mul_le #align le_inv_mul_of_mul_le le_inv_mul_of_mul_le attribute [to_additive] le_inv_mul_of_mul_le #align le_neg_add_of_add_le le_neg_add_of_add_le alias ⟨_, inv_mul_le_of_le_mul⟩ := inv_mul_le_iff_le_mul #align inv_mul_le_of_le_mul inv_mul_le_of_le_mul -- Porting note: was `inv_mul_le_iff_le_mul` attribute [to_additive] inv_mul_le_of_le_mul alias ⟨mul_lt_of_lt_inv_mul, _⟩ := lt_inv_mul_iff_mul_lt #align mul_lt_of_lt_inv_mul mul_lt_of_lt_inv_mul attribute [to_additive] mul_lt_of_lt_inv_mul #align add_lt_of_lt_neg_add add_lt_of_lt_neg_add alias ⟨_, lt_inv_mul_of_mul_lt⟩ := lt_inv_mul_iff_mul_lt #align lt_inv_mul_of_mul_lt lt_inv_mul_of_mul_lt attribute [to_additive] lt_inv_mul_of_mul_lt #align lt_neg_add_of_add_lt lt_neg_add_of_add_lt alias ⟨lt_mul_of_inv_mul_lt, inv_mul_lt_of_lt_mul⟩ := inv_mul_lt_iff_lt_mul #align lt_mul_of_inv_mul_lt lt_mul_of_inv_mul_lt #align inv_mul_lt_of_lt_mul inv_mul_lt_of_lt_mul attribute [to_additive] lt_mul_of_inv_mul_lt #align lt_add_of_neg_add_lt lt_add_of_neg_add_lt attribute [to_additive] inv_mul_lt_of_lt_mul #align neg_add_lt_of_lt_add neg_add_lt_of_lt_add alias lt_mul_of_inv_mul_lt_left := lt_mul_of_inv_mul_lt #align lt_mul_of_inv_mul_lt_left lt_mul_of_inv_mul_lt_left attribute [to_additive] lt_mul_of_inv_mul_lt_left #align lt_add_of_neg_add_lt_left lt_add_of_neg_add_lt_left alias inv_le_one' := Left.inv_le_one_iff #align inv_le_one' inv_le_one' attribute [to_additive neg_nonpos] inv_le_one' #align neg_nonpos neg_nonpos alias one_le_inv' := Left.one_le_inv_iff #align one_le_inv' one_le_inv' attribute [to_additive neg_nonneg] one_le_inv' #align neg_nonneg neg_nonneg alias one_lt_inv' := Left.one_lt_inv_iff #align one_lt_inv' one_lt_inv' attribute [to_additive neg_pos] one_lt_inv' #align neg_pos neg_pos alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left' #align ordered_comm_group.mul_lt_mul_left' OrderedCommGroup.mul_lt_mul_left' attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left' #align ordered_add_comm_group.add_lt_add_left OrderedAddCommGroup.add_lt_add_left alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left' #align ordered_comm_group.le_of_mul_le_mul_left OrderedCommGroup.le_of_mul_le_mul_left attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left #align ordered_add_comm_group.le_of_add_le_add_left OrderedAddCommGroup.le_of_add_le_add_left alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left' #align ordered_comm_group.lt_of_mul_lt_mul_left OrderedCommGroup.lt_of_mul_lt_mul_left attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left #align ordered_add_comm_group.lt_of_add_lt_add_left OrderedAddCommGroup.lt_of_add_lt_add_left -- Most of the lemmas that are primed in this section appear in ordered_field. -- I (DT) did not try to minimise the assumptions. section Group variable [Group α] [LE α] section Right variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c d : α} @[to_additive] theorem div_le_div_iff_right (c : α) : a / c ≤ b / c ↔ a ≤ b := by simpa only [div_eq_mul_inv] using mul_le_mul_iff_right _ #align div_le_div_iff_right div_le_div_iff_right #align sub_le_sub_iff_right sub_le_sub_iff_right @[to_additive (attr := gcongr) sub_le_sub_right] theorem div_le_div_right' (h : a ≤ b) (c : α) : a / c ≤ b / c := (div_le_div_iff_right c).2 h #align div_le_div_right' div_le_div_right' #align sub_le_sub_right sub_le_sub_right @[to_additive (attr := simp) sub_nonneg] theorem one_le_div' : 1 ≤ a / b ↔ b ≤ a := by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] #align one_le_div' one_le_div' #align sub_nonneg sub_nonneg alias ⟨le_of_sub_nonneg, sub_nonneg_of_le⟩ := sub_nonneg #align sub_nonneg_of_le sub_nonneg_of_le #align le_of_sub_nonneg le_of_sub_nonneg @[to_additive sub_nonpos] theorem div_le_one' : a / b ≤ 1 ↔ a ≤ b := by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] #align div_le_one' div_le_one' #align sub_nonpos sub_nonpos alias ⟨le_of_sub_nonpos, sub_nonpos_of_le⟩ := sub_nonpos #align sub_nonpos_of_le sub_nonpos_of_le #align le_of_sub_nonpos le_of_sub_nonpos @[to_additive] theorem le_div_iff_mul_le : a ≤ c / b ↔ a * b ≤ c := by rw [← mul_le_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right] #align le_div_iff_mul_le le_div_iff_mul_le #align le_sub_iff_add_le le_sub_iff_add_le alias ⟨add_le_of_le_sub_right, le_sub_right_of_add_le⟩ := le_sub_iff_add_le #align add_le_of_le_sub_right add_le_of_le_sub_right #align le_sub_right_of_add_le le_sub_right_of_add_le @[to_additive] theorem div_le_iff_le_mul : a / c ≤ b ↔ a ≤ b * c := by rw [← mul_le_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right] #align div_le_iff_le_mul div_le_iff_le_mul #align sub_le_iff_le_add sub_le_iff_le_add -- Note: we intentionally don't have `@[simp]` for the additive version, -- since the LHS simplifies with `tsub_le_iff_right` attribute [simp] div_le_iff_le_mul -- TODO: Should we get rid of `sub_le_iff_le_add` in favor of -- (a renamed version of) `tsub_le_iff_right`? -- see Note [lower instance priority] instance (priority := 100) AddGroup.toHasOrderedSub {α : Type*} [AddGroup α] [LE α] [CovariantClass α α (swap (· + ·)) (· ≤ ·)] : OrderedSub α := ⟨fun _ _ _ => sub_le_iff_le_add⟩ #align add_group.to_has_ordered_sub AddGroup.toHasOrderedSub end Right section Left variable [CovariantClass α α (· * ·) (· ≤ ·)] variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c : α} @[to_additive] theorem div_le_div_iff_left (a : α) : a / b ≤ a / c ↔ c ≤ b := by rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_le_mul_iff_left a⁻¹, inv_mul_cancel_left, inv_mul_cancel_left, inv_le_inv_iff] #align div_le_div_iff_left div_le_div_iff_left #align sub_le_sub_iff_left sub_le_sub_iff_left @[to_additive (attr := gcongr) sub_le_sub_left] theorem div_le_div_left' (h : a ≤ b) (c : α) : c / b ≤ c / a := (div_le_div_iff_left c).2 h #align div_le_div_left' div_le_div_left' #align sub_le_sub_left sub_le_sub_left end Left end Group section CommGroup variable [CommGroup α] section LE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} @[to_additive sub_le_sub_iff] theorem div_le_div_iff' : a / b ≤ c / d ↔ a * d ≤ c * b := by simpa only [div_eq_mul_inv] using mul_inv_le_mul_inv_iff' #align div_le_div_iff' div_le_div_iff' #align sub_le_sub_iff sub_le_sub_iff @[to_additive] theorem le_div_iff_mul_le' : b ≤ c / a ↔ a * b ≤ c := by rw [le_div_iff_mul_le, mul_comm] #align le_div_iff_mul_le' le_div_iff_mul_le' #align le_sub_iff_add_le' le_sub_iff_add_le' alias ⟨add_le_of_le_sub_left, le_sub_left_of_add_le⟩ := le_sub_iff_add_le' #align le_sub_left_of_add_le le_sub_left_of_add_le #align add_le_of_le_sub_left add_le_of_le_sub_left @[to_additive] theorem div_le_iff_le_mul' : a / b ≤ c ↔ a ≤ b * c := by rw [div_le_iff_le_mul, mul_comm] #align div_le_iff_le_mul' div_le_iff_le_mul' #align sub_le_iff_le_add' sub_le_iff_le_add' alias ⟨le_add_of_sub_left_le, sub_left_le_of_le_add⟩ := sub_le_iff_le_add' #align sub_left_le_of_le_add sub_left_le_of_le_add #align le_add_of_sub_left_le le_add_of_sub_left_le @[to_additive (attr := simp)] theorem inv_le_div_iff_le_mul : b⁻¹ ≤ a / c ↔ c ≤ a * b := le_div_iff_mul_le.trans inv_mul_le_iff_le_mul' #align inv_le_div_iff_le_mul inv_le_div_iff_le_mul #align neg_le_sub_iff_le_add neg_le_sub_iff_le_add @[to_additive] theorem inv_le_div_iff_le_mul' : a⁻¹ ≤ b / c ↔ c ≤ a * b := by rw [inv_le_div_iff_le_mul, mul_comm] #align inv_le_div_iff_le_mul' inv_le_div_iff_le_mul' #align neg_le_sub_iff_le_add' neg_le_sub_iff_le_add' @[to_additive] theorem div_le_comm : a / b ≤ c ↔ a / c ≤ b := div_le_iff_le_mul'.trans div_le_iff_le_mul.symm #align div_le_comm div_le_comm #align sub_le_comm sub_le_comm @[to_additive] theorem le_div_comm : a ≤ b / c ↔ c ≤ b / a := le_div_iff_mul_le'.trans le_div_iff_mul_le.symm #align le_div_comm le_div_comm #align le_sub_comm le_sub_comm end LE section Preorder variable [Preorder α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} @[to_additive (attr := gcongr) sub_le_sub] theorem div_le_div'' (hab : a ≤ b) (hcd : c ≤ d) : a / d ≤ b / c := by rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_le_inv_mul_iff, mul_comm] exact mul_le_mul' hab hcd #align div_le_div'' div_le_div'' #align sub_le_sub sub_le_sub end Preorder end CommGroup -- Most of the lemmas that are primed in this section appear in ordered_field. -- I (DT) did not try to minimise the assumptions. section Group variable [Group α] [LT α] section Right variable [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c d : α} @[to_additive (attr := simp)]
Mathlib/Algebra/Order/Group/Defs.lean
875
876
theorem div_lt_div_iff_right (c : α) : a / c < b / c ↔ a < b := by
simpa only [div_eq_mul_inv] using mul_lt_mul_iff_right _
/- Copyright (c) 2021 Alena Gusakov, Bhavik Mehta, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alena Gusakov, Bhavik Mehta, Kyle Miller -/ import Mathlib.Data.Fintype.Basic import Mathlib.Data.Set.Finite #align_import combinatorics.hall.finite from "leanprover-community/mathlib"@"d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce" /-! # Hall's Marriage Theorem for finite index types This module proves the basic form of Hall's theorem. In contrast to the theorem described in `Combinatorics.Hall.Basic`, this version requires that the indexed family `t : ι → Finset α` have `ι` be finite. The `Combinatorics.Hall.Basic` module applies a compactness argument to this version to remove the `Finite` constraint on `ι`. The modules are split like this since the generalized statement depends on the topology and category theory libraries, but the finite case in this module has few dependencies. A description of this formalization is in [Gusakov2021]. ## Main statements * `Finset.all_card_le_biUnion_card_iff_existsInjective'` is Hall's theorem with a finite index set. This is elsewhere generalized to `Finset.all_card_le_biUnion_card_iff_existsInjective`. ## Tags Hall's Marriage Theorem, indexed families -/ open Finset universe u v namespace HallMarriageTheorem variable {ι : Type u} {α : Type v} [DecidableEq α] {t : ι → Finset α} section Fintype variable [Fintype ι] theorem hall_cond_of_erase {x : ι} (a : α) (ha : ∀ s : Finset ι, s.Nonempty → s ≠ univ → s.card < (s.biUnion t).card) (s' : Finset { x' : ι | x' ≠ x }) : s'.card ≤ (s'.biUnion fun x' => (t x').erase a).card := by haveI := Classical.decEq ι specialize ha (s'.image fun z => z.1) rw [image_nonempty, Finset.card_image_of_injective s' Subtype.coe_injective] at ha by_cases he : s'.Nonempty · have ha' : s'.card < (s'.biUnion fun x => t x).card := by convert ha he fun h => by simpa [← h] using mem_univ x using 2 ext x simp only [mem_image, mem_biUnion, exists_prop, SetCoe.exists, exists_and_right, exists_eq_right, Subtype.coe_mk] rw [← erase_biUnion] by_cases hb : a ∈ s'.biUnion fun x => t x · rw [card_erase_of_mem hb] exact Nat.le_sub_one_of_lt ha' · rw [erase_eq_of_not_mem hb] exact Nat.le_of_lt ha' · rw [nonempty_iff_ne_empty, not_not] at he subst s' simp #align hall_marriage_theorem.hall_cond_of_erase HallMarriageTheorem.hall_cond_of_erase /-- First case of the inductive step: assuming that `∀ (s : Finset ι), s.Nonempty → s ≠ univ → s.card < (s.biUnion t).card` and that the statement of **Hall's Marriage Theorem** is true for all `ι'` of cardinality ≤ `n`, then it is true for `ι` of cardinality `n + 1`. -/
Mathlib/Combinatorics/Hall/Finite.lean
78
121
theorem hall_hard_inductive_step_A {n : ℕ} (hn : Fintype.card ι = n + 1) (ht : ∀ s : Finset ι, s.card ≤ (s.biUnion t).card) (ih : ∀ {ι' : Type u} [Fintype ι'] (t' : ι' → Finset α), Fintype.card ι' ≤ n → (∀ s' : Finset ι', s'.card ≤ (s'.biUnion t').card) → ∃ f : ι' → α, Function.Injective f ∧ ∀ x, f x ∈ t' x) (ha : ∀ s : Finset ι, s.Nonempty → s ≠ univ → s.card < (s.biUnion t).card) : ∃ f : ι → α, Function.Injective f ∧ ∀ x, f x ∈ t x := by
haveI : Nonempty ι := Fintype.card_pos_iff.mp (hn.symm ▸ Nat.succ_pos _) haveI := Classical.decEq ι -- Choose an arbitrary element `x : ι` and `y : t x`. let x := Classical.arbitrary ι have tx_ne : (t x).Nonempty := by rw [← Finset.card_pos] calc 0 < 1 := Nat.one_pos _ ≤ (Finset.biUnion {x} t).card := ht {x} _ = (t x).card := by rw [Finset.singleton_biUnion] choose y hy using tx_ne -- Restrict to everything except `x` and `y`. let ι' := { x' : ι | x' ≠ x } let t' : ι' → Finset α := fun x' => (t x').erase y have card_ι' : Fintype.card ι' = n := calc Fintype.card ι' = Fintype.card ι - 1 := Set.card_ne_eq _ _ = n := by rw [hn, Nat.add_succ_sub_one, add_zero] rcases ih t' card_ι'.le (hall_cond_of_erase y ha) with ⟨f', hfinj, hfr⟩ -- Extend the resulting function. refine ⟨fun z => if h : z = x then y else f' ⟨z, h⟩, ?_, ?_⟩ · rintro z₁ z₂ have key : ∀ {x}, y ≠ f' x := by intro x h simpa [t', ← h] using hfr x by_cases h₁ : z₁ = x <;> by_cases h₂ : z₂ = x <;> simp [h₁, h₂, hfinj.eq_iff, key, key.symm] · intro z simp only [ne_eq, Set.mem_setOf_eq] split_ifs with hz · rwa [hz] · specialize hfr ⟨z, hz⟩ rw [mem_erase] at hfr exact hfr.2
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.Vector.Basic import Mathlib.Data.PFun import Mathlib.Logic.Function.Iterate import Mathlib.Order.Basic import Mathlib.Tactic.ApplyFun #align_import computability.turing_machine from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Turing machines This file defines a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Γ` is the alphabet on the tape. * `Λ` is the set of labels, or internal machine states. * `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Λ`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Λ → Stmt`, although different models have different ways of halting and other actions. * `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Γ`. * `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-- The `BlankExtends` partial order holds of `l₁` and `l₂` if `l₂` is obtained by adding blanks (`default : Γ`) to the end of `l₁`. -/ def BlankExtends {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := ∃ n, l₂ = l₁ ++ List.replicate n default #align turing.blank_extends Turing.BlankExtends @[refl] theorem BlankExtends.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankExtends l l := ⟨0, by simp⟩ #align turing.blank_extends.refl Turing.BlankExtends.refl @[trans] theorem BlankExtends.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankExtends l₁ l₂ → BlankExtends l₂ l₃ → BlankExtends l₁ l₃ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ exact ⟨i + j, by simp [List.replicate_add]⟩ #align turing.blank_extends.trans Turing.BlankExtends.trans theorem BlankExtends.below_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l l₁ → BlankExtends l l₂ → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ h; use j - i simp only [List.length_append, Nat.add_le_add_iff_left, List.length_replicate] at h simp only [← List.replicate_add, Nat.add_sub_cancel' h, List.append_assoc] #align turing.blank_extends.below_of_le Turing.BlankExtends.below_of_le /-- Any two extensions by blank `l₁,l₂` of `l` have a common join (which can be taken to be the longer of `l₁` and `l₂`). -/ def BlankExtends.above {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} (h₁ : BlankExtends l l₁) (h₂ : BlankExtends l l₂) : { l' // BlankExtends l₁ l' ∧ BlankExtends l₂ l' } := if h : l₁.length ≤ l₂.length then ⟨l₂, h₁.below_of_le h₂ h, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, h₂.below_of_le h₁ (le_of_not_ge h)⟩ #align turing.blank_extends.above Turing.BlankExtends.above theorem BlankExtends.above_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l₁ l → BlankExtends l₂ l → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, e⟩ h; use i - j refine List.append_cancel_right (e.symm.trans ?_) rw [List.append_assoc, ← List.replicate_add, Nat.sub_add_cancel] apply_fun List.length at e simp only [List.length_append, List.length_replicate] at e rwa [← Nat.add_le_add_iff_left, e, Nat.add_le_add_iff_right] #align turing.blank_extends.above_of_le Turing.BlankExtends.above_of_le /-- `BlankRel` is the symmetric closure of `BlankExtends`, turning it into an equivalence relation. Two lists are related by `BlankRel` if one extends the other by blanks. -/ def BlankRel {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := BlankExtends l₁ l₂ ∨ BlankExtends l₂ l₁ #align turing.blank_rel Turing.BlankRel @[refl] theorem BlankRel.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankRel l l := Or.inl (BlankExtends.refl _) #align turing.blank_rel.refl Turing.BlankRel.refl @[symm] theorem BlankRel.symm {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₁ := Or.symm #align turing.blank_rel.symm Turing.BlankRel.symm @[trans] theorem BlankRel.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₃ → BlankRel l₁ l₃ := by rintro (h₁ | h₁) (h₂ | h₂) · exact Or.inl (h₁.trans h₂) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.above_of_le h₂ h) · exact Or.inr (h₂.above_of_le h₁ h) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.below_of_le h₂ h) · exact Or.inr (h₂.below_of_le h₁ h) · exact Or.inr (h₂.trans h₁) #align turing.blank_rel.trans Turing.BlankRel.trans /-- Given two `BlankRel` lists, there exists (constructively) a common join. -/ def BlankRel.above {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l₁ l ∧ BlankExtends l₂ l } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₂, Or.elim h id fun h' ↦ ?_, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, Or.elim h (fun h' ↦ ?_) id⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.above Turing.BlankRel.above /-- Given two `BlankRel` lists, there exists (constructively) a common meet. -/ def BlankRel.below {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l l₁ ∧ BlankExtends l l₂ } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₁, BlankExtends.refl _, Or.elim h id fun h' ↦ ?_⟩ else ⟨l₂, Or.elim h (fun h' ↦ ?_) id, BlankExtends.refl _⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.below Turing.BlankRel.below theorem BlankRel.equivalence (Γ) [Inhabited Γ] : Equivalence (@BlankRel Γ _) := ⟨BlankRel.refl, @BlankRel.symm _ _, @BlankRel.trans _ _⟩ #align turing.blank_rel.equivalence Turing.BlankRel.equivalence /-- Construct a setoid instance for `BlankRel`. -/ def BlankRel.setoid (Γ) [Inhabited Γ] : Setoid (List Γ) := ⟨_, BlankRel.equivalence _⟩ #align turing.blank_rel.setoid Turing.BlankRel.setoid /-- A `ListBlank Γ` is a quotient of `List Γ` by extension by blanks at the end. This is used to represent half-tapes of a Turing machine, so that we can pretend that the list continues infinitely with blanks. -/ def ListBlank (Γ) [Inhabited Γ] := Quotient (BlankRel.setoid Γ) #align turing.list_blank Turing.ListBlank instance ListBlank.inhabited {Γ} [Inhabited Γ] : Inhabited (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.inhabited Turing.ListBlank.inhabited instance ListBlank.hasEmptyc {Γ} [Inhabited Γ] : EmptyCollection (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.has_emptyc Turing.ListBlank.hasEmptyc /-- A modified version of `Quotient.liftOn'` specialized for `ListBlank`, with the stronger precondition `BlankExtends` instead of `BlankRel`. -/ -- Porting note: Removed `@[elab_as_elim]` protected abbrev ListBlank.liftOn {Γ} [Inhabited Γ] {α} (l : ListBlank Γ) (f : List Γ → α) (H : ∀ a b, BlankExtends a b → f a = f b) : α := l.liftOn' f <| by rintro a b (h | h) <;> [exact H _ _ h; exact (H _ _ h).symm] #align turing.list_blank.lift_on Turing.ListBlank.liftOn /-- The quotient map turning a `List` into a `ListBlank`. -/ def ListBlank.mk {Γ} [Inhabited Γ] : List Γ → ListBlank Γ := Quotient.mk'' #align turing.list_blank.mk Turing.ListBlank.mk @[elab_as_elim] protected theorem ListBlank.induction_on {Γ} [Inhabited Γ] {p : ListBlank Γ → Prop} (q : ListBlank Γ) (h : ∀ a, p (ListBlank.mk a)) : p q := Quotient.inductionOn' q h #align turing.list_blank.induction_on Turing.ListBlank.induction_on /-- The head of a `ListBlank` is well defined. -/ def ListBlank.head {Γ} [Inhabited Γ] (l : ListBlank Γ) : Γ := by apply l.liftOn List.headI rintro a _ ⟨i, rfl⟩ cases a · cases i <;> rfl rfl #align turing.list_blank.head Turing.ListBlank.head @[simp] theorem ListBlank.head_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.head (ListBlank.mk l) = l.headI := rfl #align turing.list_blank.head_mk Turing.ListBlank.head_mk /-- The tail of a `ListBlank` is well defined (up to the tail of blanks). -/ def ListBlank.tail {Γ} [Inhabited Γ] (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk l.tail) rintro a _ ⟨i, rfl⟩ refine Quotient.sound' (Or.inl ?_) cases a · cases' i with i <;> [exact ⟨0, rfl⟩; exact ⟨i, rfl⟩] exact ⟨i, rfl⟩ #align turing.list_blank.tail Turing.ListBlank.tail @[simp] theorem ListBlank.tail_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.tail (ListBlank.mk l) = ListBlank.mk l.tail := rfl #align turing.list_blank.tail_mk Turing.ListBlank.tail_mk /-- We can cons an element onto a `ListBlank`. -/ def ListBlank.cons {Γ} [Inhabited Γ] (a : Γ) (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk (List.cons a l)) rintro _ _ ⟨i, rfl⟩ exact Quotient.sound' (Or.inl ⟨i, rfl⟩) #align turing.list_blank.cons Turing.ListBlank.cons @[simp] theorem ListBlank.cons_mk {Γ} [Inhabited Γ] (a : Γ) (l : List Γ) : ListBlank.cons a (ListBlank.mk l) = ListBlank.mk (a :: l) := rfl #align turing.list_blank.cons_mk Turing.ListBlank.cons_mk @[simp] theorem ListBlank.head_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).head = a := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.head_cons Turing.ListBlank.head_cons @[simp] theorem ListBlank.tail_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).tail = l := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.tail_cons Turing.ListBlank.tail_cons /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ @[simp] theorem ListBlank.cons_head_tail {Γ} [Inhabited Γ] : ∀ l : ListBlank Γ, l.tail.cons l.head = l := by apply Quotient.ind' refine fun l ↦ Quotient.sound' (Or.inr ?_) cases l · exact ⟨1, rfl⟩ · rfl #align turing.list_blank.cons_head_tail Turing.ListBlank.cons_head_tail /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ theorem ListBlank.exists_cons {Γ} [Inhabited Γ] (l : ListBlank Γ) : ∃ a l', l = ListBlank.cons a l' := ⟨_, _, (ListBlank.cons_head_tail _).symm⟩ #align turing.list_blank.exists_cons Turing.ListBlank.exists_cons /-- The n-th element of a `ListBlank` is well defined for all `n : ℕ`, unlike in a `List`. -/ def ListBlank.nth {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : Γ := by apply l.liftOn (fun l ↦ List.getI l n) rintro l _ ⟨i, rfl⟩ cases' lt_or_le n _ with h h · rw [List.getI_append _ _ _ h] rw [List.getI_eq_default _ h] rcases le_or_lt _ n with h₂ | h₂ · rw [List.getI_eq_default _ h₂] rw [List.getI_eq_get _ h₂, List.get_append_right' h, List.get_replicate] #align turing.list_blank.nth Turing.ListBlank.nth @[simp] theorem ListBlank.nth_mk {Γ} [Inhabited Γ] (l : List Γ) (n : ℕ) : (ListBlank.mk l).nth n = l.getI n := rfl #align turing.list_blank.nth_mk Turing.ListBlank.nth_mk @[simp] theorem ListBlank.nth_zero {Γ} [Inhabited Γ] (l : ListBlank Γ) : l.nth 0 = l.head := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_zero Turing.ListBlank.nth_zero @[simp] theorem ListBlank.nth_succ {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : l.nth (n + 1) = l.tail.nth n := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_succ Turing.ListBlank.nth_succ @[ext] theorem ListBlank.ext {Γ} [i : Inhabited Γ] {L₁ L₂ : ListBlank Γ} : (∀ i, L₁.nth i = L₂.nth i) → L₁ = L₂ := by refine ListBlank.induction_on L₁ fun l₁ ↦ ListBlank.induction_on L₂ fun l₂ H ↦ ?_ wlog h : l₁.length ≤ l₂.length · cases le_total l₁.length l₂.length <;> [skip; symm] <;> apply this <;> try assumption intro rw [H] refine Quotient.sound' (Or.inl ⟨l₂.length - l₁.length, ?_⟩) refine List.ext_get ?_ fun i h h₂ ↦ Eq.symm ?_ · simp only [Nat.add_sub_cancel' h, List.length_append, List.length_replicate] simp only [ListBlank.nth_mk] at H cases' lt_or_le i l₁.length with h' h' · simp only [List.get_append _ h', List.get?_eq_get h, List.get?_eq_get h', ← List.getI_eq_get _ h, ← List.getI_eq_get _ h', H] · simp only [List.get_append_right' h', List.get_replicate, List.get?_eq_get h, List.get?_len_le h', ← List.getI_eq_default _ h', H, List.getI_eq_get _ h] #align turing.list_blank.ext Turing.ListBlank.ext /-- Apply a function to a value stored at the nth position of the list. -/ @[simp] def ListBlank.modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) : ℕ → ListBlank Γ → ListBlank Γ | 0, L => L.tail.cons (f L.head) | n + 1, L => (L.tail.modifyNth f n).cons L.head #align turing.list_blank.modify_nth Turing.ListBlank.modifyNth theorem ListBlank.nth_modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) (n i) (L : ListBlank Γ) : (L.modifyNth f n).nth i = if i = n then f (L.nth i) else L.nth i := by induction' n with n IH generalizing i L · cases i <;> simp only [ListBlank.nth_zero, if_true, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.nth_succ, if_false, ListBlank.tail_cons, Nat.zero_eq] · cases i · rw [if_neg (Nat.succ_ne_zero _).symm] simp only [ListBlank.nth_zero, ListBlank.head_cons, ListBlank.modifyNth, Nat.zero_eq] · simp only [IH, ListBlank.modifyNth, ListBlank.nth_succ, ListBlank.tail_cons, Nat.succ.injEq] #align turing.list_blank.nth_modify_nth Turing.ListBlank.nth_modifyNth /-- A pointed map of `Inhabited` types is a map that sends one default value to the other. -/ structure PointedMap.{u, v} (Γ : Type u) (Γ' : Type v) [Inhabited Γ] [Inhabited Γ'] : Type max u v where /-- The map underlying this instance. -/ f : Γ → Γ' map_pt' : f default = default #align turing.pointed_map Turing.PointedMap instance {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] : Inhabited (PointedMap Γ Γ') := ⟨⟨default, rfl⟩⟩ instance {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] : CoeFun (PointedMap Γ Γ') fun _ ↦ Γ → Γ' := ⟨PointedMap.f⟩ -- @[simp] -- Porting note (#10685): dsimp can prove this theorem PointedMap.mk_val {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : Γ → Γ') (pt) : (PointedMap.mk f pt : Γ → Γ') = f := rfl #align turing.pointed_map.mk_val Turing.PointedMap.mk_val @[simp] theorem PointedMap.map_pt {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') : f default = default := PointedMap.map_pt' _ #align turing.pointed_map.map_pt Turing.PointedMap.map_pt @[simp] theorem PointedMap.headI_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (l.map f).headI = f l.headI := by cases l <;> [exact (PointedMap.map_pt f).symm; rfl] #align turing.pointed_map.head_map Turing.PointedMap.headI_map /-- The `map` function on lists is well defined on `ListBlank`s provided that the map is pointed. -/ def ListBlank.map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : ListBlank Γ' := by apply l.liftOn (fun l ↦ ListBlank.mk (List.map f l)) rintro l _ ⟨i, rfl⟩; refine Quotient.sound' (Or.inl ⟨i, ?_⟩) simp only [PointedMap.map_pt, List.map_append, List.map_replicate] #align turing.list_blank.map Turing.ListBlank.map @[simp] theorem ListBlank.map_mk {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (ListBlank.mk l).map f = ListBlank.mk (l.map f) := rfl #align turing.list_blank.map_mk Turing.ListBlank.map_mk @[simp] theorem ListBlank.head_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : (l.map f).head = f l.head := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l fun a ↦ rfl #align turing.list_blank.head_map Turing.ListBlank.head_map @[simp] theorem ListBlank.tail_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : (l.map f).tail = l.tail.map f := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l fun a ↦ rfl #align turing.list_blank.tail_map Turing.ListBlank.tail_map @[simp] theorem ListBlank.map_cons {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) (a : Γ) : (l.cons a).map f = (l.map f).cons (f a) := by refine (ListBlank.cons_head_tail _).symm.trans ?_ simp only [ListBlank.head_map, ListBlank.head_cons, ListBlank.tail_map, ListBlank.tail_cons] #align turing.list_blank.map_cons Turing.ListBlank.map_cons @[simp] theorem ListBlank.nth_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) (n : ℕ) : (l.map f).nth n = f (l.nth n) := by refine l.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices ((mk l).map f).nth n = f ((mk l).nth n) by exact this simp only [List.get?_map, ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_get?] cases l.get? n · exact f.2.symm · rfl #align turing.list_blank.nth_map Turing.ListBlank.nth_map /-- The `i`-th projection as a pointed map. -/ def proj {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) : PointedMap (∀ i, Γ i) (Γ i) := ⟨fun a ↦ a i, rfl⟩ #align turing.proj Turing.proj theorem proj_map_nth {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) (L n) : (ListBlank.map (@proj ι Γ _ i) L).nth n = L.nth n i := by rw [ListBlank.nth_map]; rfl #align turing.proj_map_nth Turing.proj_map_nth theorem ListBlank.map_modifyNth {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (F : PointedMap Γ Γ') (f : Γ → Γ) (f' : Γ' → Γ') (H : ∀ x, F (f x) = f' (F x)) (n) (L : ListBlank Γ) : (L.modifyNth f n).map F = (L.map F).modifyNth f' n := by induction' n with n IH generalizing L <;> simp only [*, ListBlank.head_map, ListBlank.modifyNth, ListBlank.map_cons, ListBlank.tail_map] #align turing.list_blank.map_modify_nth Turing.ListBlank.map_modifyNth /-- Append a list on the left side of a `ListBlank`. -/ @[simp] def ListBlank.append {Γ} [Inhabited Γ] : List Γ → ListBlank Γ → ListBlank Γ | [], L => L | a :: l, L => ListBlank.cons a (ListBlank.append l L) #align turing.list_blank.append Turing.ListBlank.append @[simp] theorem ListBlank.append_mk {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : ListBlank.append l₁ (ListBlank.mk l₂) = ListBlank.mk (l₁ ++ l₂) := by induction l₁ <;> simp only [*, ListBlank.append, List.nil_append, List.cons_append, ListBlank.cons_mk] #align turing.list_blank.append_mk Turing.ListBlank.append_mk theorem ListBlank.append_assoc {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) (l₃ : ListBlank Γ) : ListBlank.append (l₁ ++ l₂) l₃ = ListBlank.append l₁ (ListBlank.append l₂ l₃) := by refine l₃.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices append (l₁ ++ l₂) (mk l) = append l₁ (append l₂ (mk l)) by exact this simp only [ListBlank.append_mk, List.append_assoc] #align turing.list_blank.append_assoc Turing.ListBlank.append_assoc /-- The `bind` function on lists is well defined on `ListBlank`s provided that the default element is sent to a sequence of default elements. -/ def ListBlank.bind {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : ListBlank Γ) (f : Γ → List Γ') (hf : ∃ n, f default = List.replicate n default) : ListBlank Γ' := by apply l.liftOn (fun l ↦ ListBlank.mk (List.bind l f)) rintro l _ ⟨i, rfl⟩; cases' hf with n e; refine Quotient.sound' (Or.inl ⟨i * n, ?_⟩) rw [List.append_bind, mul_comm]; congr induction' i with i IH · rfl simp only [IH, e, List.replicate_add, Nat.mul_succ, add_comm, List.replicate_succ, List.cons_bind] #align turing.list_blank.bind Turing.ListBlank.bind @[simp] theorem ListBlank.bind_mk {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : List Γ) (f : Γ → List Γ') (hf) : (ListBlank.mk l).bind f hf = ListBlank.mk (l.bind f) := rfl #align turing.list_blank.bind_mk Turing.ListBlank.bind_mk @[simp] theorem ListBlank.cons_bind {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (a : Γ) (l : ListBlank Γ) (f : Γ → List Γ') (hf) : (l.cons a).bind f hf = (l.bind f hf).append (f a) := by refine l.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices ((mk l).cons a).bind f hf = ((mk l).bind f hf).append (f a) by exact this simp only [ListBlank.append_mk, ListBlank.bind_mk, ListBlank.cons_mk, List.cons_bind] #align turing.list_blank.cons_bind Turing.ListBlank.cons_bind /-- The tape of a Turing machine is composed of a head element (which we imagine to be the current position of the head), together with two `ListBlank`s denoting the portions of the tape going off to the left and right. When the Turing machine moves right, an element is pulled from the right side and becomes the new head, while the head element is `cons`ed onto the left side. -/ structure Tape (Γ : Type*) [Inhabited Γ] where /-- The current position of the head. -/ head : Γ /-- The portion of the tape going off to the left. -/ left : ListBlank Γ /-- The portion of the tape going off to the right. -/ right : ListBlank Γ #align turing.tape Turing.Tape instance Tape.inhabited {Γ} [Inhabited Γ] : Inhabited (Tape Γ) := ⟨by constructor <;> apply default⟩ #align turing.tape.inhabited Turing.Tape.inhabited /-- A direction for the Turing machine `move` command, either left or right. -/ inductive Dir | left | right deriving DecidableEq, Inhabited #align turing.dir Turing.Dir /-- The "inclusive" left side of the tape, including both `left` and `head`. -/ def Tape.left₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ := T.left.cons T.head #align turing.tape.left₀ Turing.Tape.left₀ /-- The "inclusive" right side of the tape, including both `right` and `head`. -/ def Tape.right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ := T.right.cons T.head #align turing.tape.right₀ Turing.Tape.right₀ /-- Move the tape in response to a motion of the Turing machine. Note that `T.move Dir.left` makes `T.left` smaller; the Turing machine is moving left and the tape is moving right. -/ def Tape.move {Γ} [Inhabited Γ] : Dir → Tape Γ → Tape Γ | Dir.left, ⟨a, L, R⟩ => ⟨L.head, L.tail, R.cons a⟩ | Dir.right, ⟨a, L, R⟩ => ⟨R.head, L.cons a, R.tail⟩ #align turing.tape.move Turing.Tape.move @[simp] theorem Tape.move_left_right {Γ} [Inhabited Γ] (T : Tape Γ) : (T.move Dir.left).move Dir.right = T := by cases T; simp [Tape.move] #align turing.tape.move_left_right Turing.Tape.move_left_right @[simp] theorem Tape.move_right_left {Γ} [Inhabited Γ] (T : Tape Γ) : (T.move Dir.right).move Dir.left = T := by cases T; simp [Tape.move] #align turing.tape.move_right_left Turing.Tape.move_right_left /-- Construct a tape from a left side and an inclusive right side. -/ def Tape.mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : Tape Γ := ⟨R.head, L, R.tail⟩ #align turing.tape.mk' Turing.Tape.mk' @[simp] theorem Tape.mk'_left {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).left = L := rfl #align turing.tape.mk'_left Turing.Tape.mk'_left @[simp] theorem Tape.mk'_head {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).head = R.head := rfl #align turing.tape.mk'_head Turing.Tape.mk'_head @[simp] theorem Tape.mk'_right {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right = R.tail := rfl #align turing.tape.mk'_right Turing.Tape.mk'_right @[simp] theorem Tape.mk'_right₀ {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right₀ = R := ListBlank.cons_head_tail _ #align turing.tape.mk'_right₀ Turing.Tape.mk'_right₀ @[simp] theorem Tape.mk'_left_right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : Tape.mk' T.left T.right₀ = T := by cases T simp only [Tape.right₀, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons, eq_self_iff_true, and_self_iff] #align turing.tape.mk'_left_right₀ Turing.Tape.mk'_left_right₀ theorem Tape.exists_mk' {Γ} [Inhabited Γ] (T : Tape Γ) : ∃ L R, T = Tape.mk' L R := ⟨_, _, (Tape.mk'_left_right₀ _).symm⟩ #align turing.tape.exists_mk' Turing.Tape.exists_mk' @[simp] theorem Tape.move_left_mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).move Dir.left = Tape.mk' L.tail (R.cons L.head) := by simp only [Tape.move, Tape.mk', ListBlank.head_cons, eq_self_iff_true, ListBlank.cons_head_tail, and_self_iff, ListBlank.tail_cons] #align turing.tape.move_left_mk' Turing.Tape.move_left_mk' @[simp] theorem Tape.move_right_mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).move Dir.right = Tape.mk' (L.cons R.head) R.tail := by simp only [Tape.move, Tape.mk', ListBlank.head_cons, eq_self_iff_true, ListBlank.cons_head_tail, and_self_iff, ListBlank.tail_cons] #align turing.tape.move_right_mk' Turing.Tape.move_right_mk' /-- Construct a tape from a left side and an inclusive right side. -/ def Tape.mk₂ {Γ} [Inhabited Γ] (L R : List Γ) : Tape Γ := Tape.mk' (ListBlank.mk L) (ListBlank.mk R) #align turing.tape.mk₂ Turing.Tape.mk₂ /-- Construct a tape from a list, with the head of the list at the TM head and the rest going to the right. -/ def Tape.mk₁ {Γ} [Inhabited Γ] (l : List Γ) : Tape Γ := Tape.mk₂ [] l #align turing.tape.mk₁ Turing.Tape.mk₁ /-- The `nth` function of a tape is integer-valued, with index `0` being the head, negative indexes on the left and positive indexes on the right. (Picture a number line.) -/ def Tape.nth {Γ} [Inhabited Γ] (T : Tape Γ) : ℤ → Γ | 0 => T.head | (n + 1 : ℕ) => T.right.nth n | -(n + 1 : ℕ) => T.left.nth n #align turing.tape.nth Turing.Tape.nth @[simp] theorem Tape.nth_zero {Γ} [Inhabited Γ] (T : Tape Γ) : T.nth 0 = T.1 := rfl #align turing.tape.nth_zero Turing.Tape.nth_zero theorem Tape.right₀_nth {Γ} [Inhabited Γ] (T : Tape Γ) (n : ℕ) : T.right₀.nth n = T.nth n := by cases n <;> simp only [Tape.nth, Tape.right₀, Int.ofNat_zero, ListBlank.nth_zero, ListBlank.nth_succ, ListBlank.head_cons, ListBlank.tail_cons, Nat.zero_eq] #align turing.tape.right₀_nth Turing.Tape.right₀_nth @[simp] theorem Tape.mk'_nth_nat {Γ} [Inhabited Γ] (L R : ListBlank Γ) (n : ℕ) : (Tape.mk' L R).nth n = R.nth n := by rw [← Tape.right₀_nth, Tape.mk'_right₀] #align turing.tape.mk'_nth_nat Turing.Tape.mk'_nth_nat @[simp] theorem Tape.move_left_nth {Γ} [Inhabited Γ] : ∀ (T : Tape Γ) (i : ℤ), (T.move Dir.left).nth i = T.nth (i - 1) | ⟨_, L, _⟩, -(n + 1 : ℕ) => (ListBlank.nth_succ _ _).symm | ⟨_, L, _⟩, 0 => (ListBlank.nth_zero _).symm | ⟨a, L, R⟩, 1 => (ListBlank.nth_zero _).trans (ListBlank.head_cons _ _) | ⟨a, L, R⟩, (n + 1 : ℕ) + 1 => by rw [add_sub_cancel_right] change (R.cons a).nth (n + 1) = R.nth n rw [ListBlank.nth_succ, ListBlank.tail_cons] #align turing.tape.move_left_nth Turing.Tape.move_left_nth @[simp] theorem Tape.move_right_nth {Γ} [Inhabited Γ] (T : Tape Γ) (i : ℤ) : (T.move Dir.right).nth i = T.nth (i + 1) := by conv => rhs; rw [← T.move_right_left] rw [Tape.move_left_nth, add_sub_cancel_right] #align turing.tape.move_right_nth Turing.Tape.move_right_nth @[simp] theorem Tape.move_right_n_head {Γ} [Inhabited Γ] (T : Tape Γ) (i : ℕ) : ((Tape.move Dir.right)^[i] T).head = T.nth i := by induction i generalizing T · rfl · simp only [*, Tape.move_right_nth, Int.ofNat_succ, iterate_succ, Function.comp_apply] #align turing.tape.move_right_n_head Turing.Tape.move_right_n_head /-- Replace the current value of the head on the tape. -/ def Tape.write {Γ} [Inhabited Γ] (b : Γ) (T : Tape Γ) : Tape Γ := { T with head := b } #align turing.tape.write Turing.Tape.write @[simp] theorem Tape.write_self {Γ} [Inhabited Γ] : ∀ T : Tape Γ, T.write T.1 = T := by rintro ⟨⟩; rfl #align turing.tape.write_self Turing.Tape.write_self @[simp] theorem Tape.write_nth {Γ} [Inhabited Γ] (b : Γ) : ∀ (T : Tape Γ) {i : ℤ}, (T.write b).nth i = if i = 0 then b else T.nth i | _, 0 => rfl | _, (_ + 1 : ℕ) => rfl | _, -(_ + 1 : ℕ) => rfl #align turing.tape.write_nth Turing.Tape.write_nth @[simp] theorem Tape.write_mk' {Γ} [Inhabited Γ] (a b : Γ) (L R : ListBlank Γ) : (Tape.mk' L (R.cons a)).write b = Tape.mk' L (R.cons b) := by simp only [Tape.write, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons, eq_self_iff_true, and_self_iff] #align turing.tape.write_mk' Turing.Tape.write_mk' /-- Apply a pointed map to a tape to change the alphabet. -/ def Tape.map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (T : Tape Γ) : Tape Γ' := ⟨f T.1, T.2.map f, T.3.map f⟩ #align turing.tape.map Turing.Tape.map @[simp] theorem Tape.map_fst {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') : ∀ T : Tape Γ, (T.map f).1 = f T.1 := by rintro ⟨⟩; rfl #align turing.tape.map_fst Turing.Tape.map_fst @[simp] theorem Tape.map_write {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (b : Γ) : ∀ T : Tape Γ, (T.write b).map f = (T.map f).write (f b) := by rintro ⟨⟩; rfl #align turing.tape.map_write Turing.Tape.map_write -- Porting note: `simpNF` complains about LHS does not simplify when using the simp lemma on -- itself, but it does indeed. @[simp, nolint simpNF] theorem Tape.write_move_right_n {Γ} [Inhabited Γ] (f : Γ → Γ) (L R : ListBlank Γ) (n : ℕ) : ((Tape.move Dir.right)^[n] (Tape.mk' L R)).write (f (R.nth n)) = (Tape.move Dir.right)^[n] (Tape.mk' L (R.modifyNth f n)) := by induction' n with n IH generalizing L R · simp only [ListBlank.nth_zero, ListBlank.modifyNth, iterate_zero_apply, Nat.zero_eq] rw [← Tape.write_mk', ListBlank.cons_head_tail] simp only [ListBlank.head_cons, ListBlank.nth_succ, ListBlank.modifyNth, Tape.move_right_mk', ListBlank.tail_cons, iterate_succ_apply, IH] #align turing.tape.write_move_right_n Turing.Tape.write_move_right_n theorem Tape.map_move {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (T : Tape Γ) (d) : (T.move d).map f = (T.map f).move d := by cases T cases d <;> simp only [Tape.move, Tape.map, ListBlank.head_map, eq_self_iff_true, ListBlank.map_cons, and_self_iff, ListBlank.tail_map] #align turing.tape.map_move Turing.Tape.map_move theorem Tape.map_mk' {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (L R : ListBlank Γ) : (Tape.mk' L R).map f = Tape.mk' (L.map f) (R.map f) := by simp only [Tape.mk', Tape.map, ListBlank.head_map, eq_self_iff_true, and_self_iff, ListBlank.tail_map] #align turing.tape.map_mk' Turing.Tape.map_mk' theorem Tape.map_mk₂ {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (L R : List Γ) : (Tape.mk₂ L R).map f = Tape.mk₂ (L.map f) (R.map f) := by simp only [Tape.mk₂, Tape.map_mk', ListBlank.map_mk] #align turing.tape.map_mk₂ Turing.Tape.map_mk₂ theorem Tape.map_mk₁ {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (Tape.mk₁ l).map f = Tape.mk₁ (l.map f) := Tape.map_mk₂ _ _ _ #align turing.tape.map_mk₁ Turing.Tape.map_mk₁ /-- Run a state transition function `σ → Option σ` "to completion". The return value is the last state returned before a `none` result. If the state transition function always returns `some`, then the computation diverges, returning `Part.none`. -/ def eval {σ} (f : σ → Option σ) : σ → Part σ := PFun.fix fun s ↦ Part.some <| (f s).elim (Sum.inl s) Sum.inr #align turing.eval Turing.eval /-- The reflexive transitive closure of a state transition function. `Reaches f a b` means there is a finite sequence of steps `f a = some a₁`, `f a₁ = some a₂`, ... such that `aₙ = b`. This relation permits zero steps of the state transition function. -/ def Reaches {σ} (f : σ → Option σ) : σ → σ → Prop := ReflTransGen fun a b ↦ b ∈ f a #align turing.reaches Turing.Reaches /-- The transitive closure of a state transition function. `Reaches₁ f a b` means there is a nonempty finite sequence of steps `f a = some a₁`, `f a₁ = some a₂`, ... such that `aₙ = b`. This relation does not permit zero steps of the state transition function. -/ def Reaches₁ {σ} (f : σ → Option σ) : σ → σ → Prop := TransGen fun a b ↦ b ∈ f a #align turing.reaches₁ Turing.Reaches₁ theorem reaches₁_eq {σ} {f : σ → Option σ} {a b c} (h : f a = f b) : Reaches₁ f a c ↔ Reaches₁ f b c := TransGen.head'_iff.trans (TransGen.head'_iff.trans <| by rw [h]).symm #align turing.reaches₁_eq Turing.reaches₁_eq theorem reaches_total {σ} {f : σ → Option σ} {a b c} (hab : Reaches f a b) (hac : Reaches f a c) : Reaches f b c ∨ Reaches f c b := ReflTransGen.total_of_right_unique (fun _ _ _ ↦ Option.mem_unique) hab hac #align turing.reaches_total Turing.reaches_total theorem reaches₁_fwd {σ} {f : σ → Option σ} {a b c} (h₁ : Reaches₁ f a c) (h₂ : b ∈ f a) : Reaches f b c := by rcases TransGen.head'_iff.1 h₁ with ⟨b', hab, hbc⟩ cases Option.mem_unique hab h₂; exact hbc #align turing.reaches₁_fwd Turing.reaches₁_fwd /-- A variation on `Reaches`. `Reaches₀ f a b` holds if whenever `Reaches₁ f b c` then `Reaches₁ f a c`. This is a weaker property than `Reaches` and is useful for replacing states with equivalent states without taking a step. -/ def Reaches₀ {σ} (f : σ → Option σ) (a b : σ) : Prop := ∀ c, Reaches₁ f b c → Reaches₁ f a c #align turing.reaches₀ Turing.Reaches₀ theorem Reaches₀.trans {σ} {f : σ → Option σ} {a b c : σ} (h₁ : Reaches₀ f a b) (h₂ : Reaches₀ f b c) : Reaches₀ f a c | _, h₃ => h₁ _ (h₂ _ h₃) #align turing.reaches₀.trans Turing.Reaches₀.trans @[refl] theorem Reaches₀.refl {σ} {f : σ → Option σ} (a : σ) : Reaches₀ f a a | _, h => h #align turing.reaches₀.refl Turing.Reaches₀.refl theorem Reaches₀.single {σ} {f : σ → Option σ} {a b : σ} (h : b ∈ f a) : Reaches₀ f a b | _, h₂ => h₂.head h #align turing.reaches₀.single Turing.Reaches₀.single theorem Reaches₀.head {σ} {f : σ → Option σ} {a b c : σ} (h : b ∈ f a) (h₂ : Reaches₀ f b c) : Reaches₀ f a c := (Reaches₀.single h).trans h₂ #align turing.reaches₀.head Turing.Reaches₀.head theorem Reaches₀.tail {σ} {f : σ → Option σ} {a b c : σ} (h₁ : Reaches₀ f a b) (h : c ∈ f b) : Reaches₀ f a c := h₁.trans (Reaches₀.single h) #align turing.reaches₀.tail Turing.Reaches₀.tail theorem reaches₀_eq {σ} {f : σ → Option σ} {a b} (e : f a = f b) : Reaches₀ f a b | _, h => (reaches₁_eq e).2 h #align turing.reaches₀_eq Turing.reaches₀_eq theorem Reaches₁.to₀ {σ} {f : σ → Option σ} {a b : σ} (h : Reaches₁ f a b) : Reaches₀ f a b | _, h₂ => h.trans h₂ #align turing.reaches₁.to₀ Turing.Reaches₁.to₀ theorem Reaches.to₀ {σ} {f : σ → Option σ} {a b : σ} (h : Reaches f a b) : Reaches₀ f a b | _, h₂ => h₂.trans_right h #align turing.reaches.to₀ Turing.Reaches.to₀ theorem Reaches₀.tail' {σ} {f : σ → Option σ} {a b c : σ} (h : Reaches₀ f a b) (h₂ : c ∈ f b) : Reaches₁ f a c := h _ (TransGen.single h₂) #align turing.reaches₀.tail' Turing.Reaches₀.tail' /-- (co-)Induction principle for `eval`. If a property `C` holds of any point `a` evaluating to `b` which is either terminal (meaning `a = b`) or where the next point also satisfies `C`, then it holds of any point where `eval f a` evaluates to `b`. This formalizes the notion that if `eval f a` evaluates to `b` then it reaches terminal state `b` in finitely many steps. -/ @[elab_as_elim] def evalInduction {σ} {f : σ → Option σ} {b : σ} {C : σ → Sort*} {a : σ} (h : b ∈ eval f a) (H : ∀ a, b ∈ eval f a → (∀ a', f a = some a' → C a') → C a) : C a := PFun.fixInduction h fun a' ha' h' ↦ H _ ha' fun b' e ↦ h' _ <| Part.mem_some_iff.2 <| by rw [e]; rfl #align turing.eval_induction Turing.evalInduction theorem mem_eval {σ} {f : σ → Option σ} {a b} : b ∈ eval f a ↔ Reaches f a b ∧ f b = none := by refine ⟨fun h ↦ ?_, fun ⟨h₁, h₂⟩ ↦ ?_⟩ · -- Porting note: Explicitly specify `c`. refine @evalInduction _ _ _ (fun a ↦ Reaches f a b ∧ f b = none) _ h fun a h IH ↦ ?_ cases' e : f a with a' · rw [Part.mem_unique h (PFun.mem_fix_iff.2 <| Or.inl <| Part.mem_some_iff.2 <| by rw [e] <;> rfl)] exact ⟨ReflTransGen.refl, e⟩ · rcases PFun.mem_fix_iff.1 h with (h | ⟨_, h, _⟩) <;> rw [e] at h <;> cases Part.mem_some_iff.1 h cases' IH a' e with h₁ h₂ exact ⟨ReflTransGen.head e h₁, h₂⟩ · refine ReflTransGen.head_induction_on h₁ ?_ fun h _ IH ↦ ?_ · refine PFun.mem_fix_iff.2 (Or.inl ?_) rw [h₂] apply Part.mem_some · refine PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, IH⟩) rw [h] apply Part.mem_some #align turing.mem_eval Turing.mem_eval theorem eval_maximal₁ {σ} {f : σ → Option σ} {a b} (h : b ∈ eval f a) (c) : ¬Reaches₁ f b c | bc => by let ⟨_, b0⟩ := mem_eval.1 h let ⟨b', h', _⟩ := TransGen.head'_iff.1 bc cases b0.symm.trans h' #align turing.eval_maximal₁ Turing.eval_maximal₁ theorem eval_maximal {σ} {f : σ → Option σ} {a b} (h : b ∈ eval f a) {c} : Reaches f b c ↔ c = b := let ⟨_, b0⟩ := mem_eval.1 h reflTransGen_iff_eq fun b' h' ↦ by cases b0.symm.trans h' #align turing.eval_maximal Turing.eval_maximal theorem reaches_eval {σ} {f : σ → Option σ} {a b} (ab : Reaches f a b) : eval f a = eval f b := by refine Part.ext fun _ ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · have ⟨ac, c0⟩ := mem_eval.1 h exact mem_eval.2 ⟨(or_iff_left_of_imp fun cb ↦ (eval_maximal h).1 cb ▸ ReflTransGen.refl).1 (reaches_total ab ac), c0⟩ · have ⟨bc, c0⟩ := mem_eval.1 h exact mem_eval.2 ⟨ab.trans bc, c0⟩ #align turing.reaches_eval Turing.reaches_eval /-- Given a relation `tr : σ₁ → σ₂ → Prop` between state spaces, and state transition functions `f₁ : σ₁ → Option σ₁` and `f₂ : σ₂ → Option σ₂`, `Respects f₁ f₂ tr` means that if `tr a₁ a₂` holds initially and `f₁` takes a step to `a₂` then `f₂` will take one or more steps before reaching a state `b₂` satisfying `tr a₂ b₂`, and if `f₁ a₁` terminates then `f₂ a₂` also terminates. Such a relation `tr` is also known as a refinement. -/ def Respects {σ₁ σ₂} (f₁ : σ₁ → Option σ₁) (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂ → Prop) := ∀ ⦃a₁ a₂⦄, tr a₁ a₂ → (match f₁ a₁ with | some b₁ => ∃ b₂, tr b₁ b₂ ∧ Reaches₁ f₂ a₂ b₂ | none => f₂ a₂ = none : Prop) #align turing.respects Turing.Respects theorem tr_reaches₁ {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : Reaches₁ f₁ a₁ b₁) : ∃ b₂, tr b₁ b₂ ∧ Reaches₁ f₂ a₂ b₂ := by induction' ab with c₁ ac c₁ d₁ _ cd IH · have := H aa rwa [show f₁ a₁ = _ from ac] at this · rcases IH with ⟨c₂, cc, ac₂⟩ have := H cc rw [show f₁ c₁ = _ from cd] at this rcases this with ⟨d₂, dd, cd₂⟩ exact ⟨_, dd, ac₂.trans cd₂⟩ #align turing.tr_reaches₁ Turing.tr_reaches₁ theorem tr_reaches {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : Reaches f₁ a₁ b₁) : ∃ b₂, tr b₁ b₂ ∧ Reaches f₂ a₂ b₂ := by rcases reflTransGen_iff_eq_or_transGen.1 ab with (rfl | ab) · exact ⟨_, aa, ReflTransGen.refl⟩ · have ⟨b₂, bb, h⟩ := tr_reaches₁ H aa ab exact ⟨b₂, bb, h.to_reflTransGen⟩ #align turing.tr_reaches Turing.tr_reaches theorem tr_reaches_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₂} (ab : Reaches f₂ a₂ b₂) : ∃ c₁ c₂, Reaches f₂ b₂ c₂ ∧ tr c₁ c₂ ∧ Reaches f₁ a₁ c₁ := by induction' ab with c₂ d₂ _ cd IH · exact ⟨_, _, ReflTransGen.refl, aa, ReflTransGen.refl⟩ · rcases IH with ⟨e₁, e₂, ce, ee, ae⟩ rcases ReflTransGen.cases_head ce with (rfl | ⟨d', cd', de⟩) · have := H ee revert this cases' eg : f₁ e₁ with g₁ <;> simp only [Respects, and_imp, exists_imp] · intro c0 cases cd.symm.trans c0 · intro g₂ gg cg rcases TransGen.head'_iff.1 cg with ⟨d', cd', dg⟩ cases Option.mem_unique cd cd' exact ⟨_, _, dg, gg, ae.tail eg⟩ · cases Option.mem_unique cd cd' exact ⟨_, _, de, ee, ae⟩ #align turing.tr_reaches_rev Turing.tr_reaches_rev theorem tr_eval {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ b₁ a₂} (aa : tr a₁ a₂) (ab : b₁ ∈ eval f₁ a₁) : ∃ b₂, tr b₁ b₂ ∧ b₂ ∈ eval f₂ a₂ := by cases' mem_eval.1 ab with ab b0 rcases tr_reaches H aa ab with ⟨b₂, bb, ab⟩ refine ⟨_, bb, mem_eval.2 ⟨ab, ?_⟩⟩ have := H bb; rwa [b0] at this #align turing.tr_eval Turing.tr_eval theorem tr_eval_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ b₂ a₂} (aa : tr a₁ a₂) (ab : b₂ ∈ eval f₂ a₂) : ∃ b₁, tr b₁ b₂ ∧ b₁ ∈ eval f₁ a₁ := by cases' mem_eval.1 ab with ab b0 rcases tr_reaches_rev H aa ab with ⟨c₁, c₂, bc, cc, ac⟩ cases (reflTransGen_iff_eq (Option.eq_none_iff_forall_not_mem.1 b0)).1 bc refine ⟨_, cc, mem_eval.2 ⟨ac, ?_⟩⟩ have := H cc cases' hfc : f₁ c₁ with d₁ · rfl rw [hfc] at this rcases this with ⟨d₂, _, bd⟩ rcases TransGen.head'_iff.1 bd with ⟨e, h, _⟩ cases b0.symm.trans h #align turing.tr_eval_rev Turing.tr_eval_rev theorem tr_eval_dom {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) : (eval f₂ a₂).Dom ↔ (eval f₁ a₁).Dom := ⟨fun h ↦ let ⟨_, _, h, _⟩ := tr_eval_rev H aa ⟨h, rfl⟩ h, fun h ↦ let ⟨_, _, h, _⟩ := tr_eval H aa ⟨h, rfl⟩ h⟩ #align turing.tr_eval_dom Turing.tr_eval_dom /-- A simpler version of `Respects` when the state transition relation `tr` is a function. -/ def FRespects {σ₁ σ₂} (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂) (a₂ : σ₂) : Option σ₁ → Prop | some b₁ => Reaches₁ f₂ a₂ (tr b₁) | none => f₂ a₂ = none #align turing.frespects Turing.FRespects theorem frespects_eq {σ₁ σ₂} {f₂ : σ₂ → Option σ₂} {tr : σ₁ → σ₂} {a₂ b₂} (h : f₂ a₂ = f₂ b₂) : ∀ {b₁}, FRespects f₂ tr a₂ b₁ ↔ FRespects f₂ tr b₂ b₁ | some b₁ => reaches₁_eq h | none => by unfold FRespects; rw [h] #align turing.frespects_eq Turing.frespects_eq theorem fun_respects {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂} : (Respects f₁ f₂ fun a b ↦ tr a = b) ↔ ∀ ⦃a₁⦄, FRespects f₂ tr (tr a₁) (f₁ a₁) := forall_congr' fun a₁ ↦ by cases f₁ a₁ <;> simp only [FRespects, Respects, exists_eq_left', forall_eq'] #align turing.fun_respects Turing.fun_respects theorem tr_eval' {σ₁ σ₂} (f₁ : σ₁ → Option σ₁) (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂) (H : Respects f₁ f₂ fun a b ↦ tr a = b) (a₁) : eval f₂ (tr a₁) = tr <$> eval f₁ a₁ := Part.ext fun b₂ ↦ ⟨fun h ↦ let ⟨b₁, bb, hb⟩ := tr_eval_rev H rfl h (Part.mem_map_iff _).2 ⟨b₁, hb, bb⟩, fun h ↦ by rcases (Part.mem_map_iff _).1 h with ⟨b₁, ab, bb⟩ rcases tr_eval H rfl ab with ⟨_, rfl, h⟩ rwa [bb] at h⟩ #align turing.tr_eval' Turing.tr_eval' /-! ## The TM0 model A TM0 Turing machine is essentially a Post-Turing machine, adapted for type theory. A Post-Turing machine with symbol type `Γ` and label type `Λ` is a function `Λ → Γ → Option (Λ × Stmt)`, where a `Stmt` can be either `move left`, `move right` or `write a` for `a : Γ`. The machine works over a "tape", a doubly-infinite sequence of elements of `Γ`, and an instantaneous configuration, `Cfg`, is a label `q : Λ` indicating the current internal state of the machine, and a `Tape Γ` (which is essentially `ℤ →₀ Γ`). The evolution is described by the `step` function: * If `M q T.head = none`, then the machine halts. * If `M q T.head = some (q', s)`, then the machine performs action `s : Stmt` and then transitions to state `q'`. The initial state takes a `List Γ` and produces a `Tape Γ` where the head of the list is the head of the tape and the rest of the list extends to the right, with the left side all blank. The final state takes the entire right side of the tape right or equal to the current position of the machine. (This is actually a `ListBlank Γ`, not a `List Γ`, because we don't know, at this level of generality, where the output ends. If equality to `default : Γ` is decidable we can trim the list to remove the infinite tail of blanks.) -/ namespace TM0 set_option linter.uppercaseLean3 false -- for "TM0" section -- type of tape symbols variable (Γ : Type*) [Inhabited Γ] -- type of "labels" or TM states variable (Λ : Type*) [Inhabited Λ] /-- A Turing machine "statement" is just a command to either move left or right, or write a symbol on the tape. -/ inductive Stmt | move : Dir → Stmt | write : Γ → Stmt #align turing.TM0.stmt Turing.TM0.Stmt local notation "Stmt₀" => Stmt Γ -- Porting note (#10750): added this to clean up types. instance Stmt.inhabited : Inhabited Stmt₀ := ⟨Stmt.write default⟩ #align turing.TM0.stmt.inhabited Turing.TM0.Stmt.inhabited /-- A Post-Turing machine with symbol type `Γ` and label type `Λ` is a function which, given the current state `q : Λ` and the tape head `a : Γ`, either halts (returns `none`) or returns a new state `q' : Λ` and a `Stmt` describing what to do, either a move left or right, or a write command. Both `Λ` and `Γ` are required to be inhabited; the default value for `Γ` is the "blank" tape value, and the default value of `Λ` is the initial state. -/ @[nolint unusedArguments] -- this is a deliberate addition, see comment def Machine [Inhabited Λ] := Λ → Γ → Option (Λ × Stmt₀) #align turing.TM0.machine Turing.TM0.Machine local notation "Machine₀" => Machine Γ Λ -- Porting note (#10750): added this to clean up types. instance Machine.inhabited : Inhabited Machine₀ := by unfold Machine; infer_instance #align turing.TM0.machine.inhabited Turing.TM0.Machine.inhabited /-- The configuration state of a Turing machine during operation consists of a label (machine state), and a tape. The tape is represented in the form `(a, L, R)`, meaning the tape looks like `L.rev ++ [a] ++ R` with the machine currently reading the `a`. The lists are automatically extended with blanks as the machine moves around. -/ structure Cfg where /-- The current machine state. -/ q : Λ /-- The current state of the tape: current symbol, left and right parts. -/ Tape : Tape Γ #align turing.TM0.cfg Turing.TM0.Cfg local notation "Cfg₀" => Cfg Γ Λ -- Porting note (#10750): added this to clean up types. instance Cfg.inhabited : Inhabited Cfg₀ := ⟨⟨default, default⟩⟩ #align turing.TM0.cfg.inhabited Turing.TM0.Cfg.inhabited variable {Γ Λ} /-- Execution semantics of the Turing machine. -/ def step (M : Machine₀) : Cfg₀ → Option Cfg₀ := fun ⟨q, T⟩ ↦ (M q T.1).map fun ⟨q', a⟩ ↦ ⟨q', match a with | Stmt.move d => T.move d | Stmt.write a => T.write a⟩ #align turing.TM0.step Turing.TM0.step /-- The statement `Reaches M s₁ s₂` means that `s₂` is obtained starting from `s₁` after a finite number of steps from `s₂`. -/ def Reaches (M : Machine₀) : Cfg₀ → Cfg₀ → Prop := ReflTransGen fun a b ↦ b ∈ step M a #align turing.TM0.reaches Turing.TM0.Reaches /-- The initial configuration. -/ def init (l : List Γ) : Cfg₀ := ⟨default, Tape.mk₁ l⟩ #align turing.TM0.init Turing.TM0.init /-- Evaluate a Turing machine on initial input to a final state, if it terminates. -/ def eval (M : Machine₀) (l : List Γ) : Part (ListBlank Γ) := (Turing.eval (step M) (init l)).map fun c ↦ c.Tape.right₀ #align turing.TM0.eval Turing.TM0.eval /-- The raw definition of a Turing machine does not require that `Γ` and `Λ` are finite, and in practice we will be interested in the infinite `Λ` case. We recover instead a notion of "effectively finite" Turing machines, which only make use of a finite subset of their states. We say that a set `S ⊆ Λ` supports a Turing machine `M` if `S` is closed under the transition function and contains the initial state. -/ def Supports (M : Machine₀) (S : Set Λ) := default ∈ S ∧ ∀ {q a q' s}, (q', s) ∈ M q a → q ∈ S → q' ∈ S #align turing.TM0.supports Turing.TM0.Supports
Mathlib/Computability/TuringMachine.lean
1,117
1,121
theorem step_supports (M : Machine₀) {S : Set Λ} (ss : Supports M S) : ∀ {c c' : Cfg₀}, c' ∈ step M c → c.q ∈ S → c'.q ∈ S := by
intro ⟨q, T⟩ c' h₁ h₂ rcases Option.map_eq_some'.1 h₁ with ⟨⟨q', a⟩, h, rfl⟩ exact ss.2 h h₂
/- 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.Algebra.BigOperators.Fin import Mathlib.Algebra.GeomSum import Mathlib.LinearAlgebra.Matrix.Block import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Nondegenerate #align_import linear_algebra.vandermonde from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Vandermonde matrix This file defines the `vandermonde` matrix and gives its determinant. ## Main definitions - `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`. ## Main results - `det_vandermonde`: `det (vandermonde v)` is the product of `v i - v j`, where `(i, j)` ranges over the unordered pairs. -/ variable {R : Type*} [CommRing R] open Equiv Finset open Matrix namespace Matrix /-- `vandermonde v` is the square matrix with `i`th row equal to `1, v i, v i ^ 2, v i ^ 3, ...`. -/ def vandermonde {n : ℕ} (v : Fin n → R) : Matrix (Fin n) (Fin n) R := fun i j => v i ^ (j : ℕ) #align matrix.vandermonde Matrix.vandermonde @[simp] theorem vandermonde_apply {n : ℕ} (v : Fin n → R) (i j) : vandermonde v i j = v i ^ (j : ℕ) := rfl #align matrix.vandermonde_apply Matrix.vandermonde_apply @[simp] theorem vandermonde_cons {n : ℕ} (v0 : R) (v : Fin n → R) : vandermonde (Fin.cons v0 v : Fin n.succ → R) = Fin.cons (fun (j : Fin n.succ) => v0 ^ (j : ℕ)) fun i => Fin.cons 1 fun j => v i * vandermonde v i j := by ext i j refine Fin.cases (by simp) (fun i => ?_) i refine Fin.cases (by simp) (fun j => ?_) j simp [pow_succ'] #align matrix.vandermonde_cons Matrix.vandermonde_cons theorem vandermonde_succ {n : ℕ} (v : Fin n.succ → R) : vandermonde v = Fin.cons (fun (j : Fin n.succ) => v 0 ^ (j : ℕ)) fun i => Fin.cons 1 fun j => v i.succ * vandermonde (Fin.tail v) i j := by conv_lhs => rw [← Fin.cons_self_tail v, vandermonde_cons] rfl #align matrix.vandermonde_succ Matrix.vandermonde_succ theorem vandermonde_mul_vandermonde_transpose {n : ℕ} (v w : Fin n → R) (i j) : (vandermonde v * (vandermonde w)ᵀ) i j = ∑ k : Fin n, (v i * w j) ^ (k : ℕ) := by simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, mul_pow] #align matrix.vandermonde_mul_vandermonde_transpose Matrix.vandermonde_mul_vandermonde_transpose theorem vandermonde_transpose_mul_vandermonde {n : ℕ} (v : Fin n → R) (i j) : ((vandermonde v)ᵀ * vandermonde v) i j = ∑ k : Fin n, v k ^ (i + j : ℕ) := by simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, pow_add] #align matrix.vandermonde_transpose_mul_vandermonde Matrix.vandermonde_transpose_mul_vandermonde
Mathlib/LinearAlgebra/Vandermonde.lean
77
139
theorem det_vandermonde {n : ℕ} (v : Fin n → R) : det (vandermonde v) = ∏ i : Fin n, ∏ j ∈ Ioi i, (v j - v i) := by
unfold vandermonde induction' n with n ih · exact det_eq_one_of_card_eq_zero (Fintype.card_fin 0) calc det (of fun i j : Fin n.succ => v i ^ (j : ℕ)) = det (of fun i j : Fin n.succ => Matrix.vecCons (v 0 ^ (j : ℕ)) (fun i => v (Fin.succ i) ^ (j : ℕ) - v 0 ^ (j : ℕ)) i) := det_eq_of_forall_row_eq_smul_add_const (Matrix.vecCons 0 1) 0 (Fin.cons_zero _ _) ?_ _ = det (of fun i j : Fin n => Matrix.vecCons (v 0 ^ (j.succ : ℕ)) (fun i : Fin n => v (Fin.succ i) ^ (j.succ : ℕ) - v 0 ^ (j.succ : ℕ)) (Fin.succAbove 0 i)) := by simp_rw [det_succ_column_zero, Fin.sum_univ_succ, of_apply, Matrix.cons_val_zero, submatrix, of_apply, Matrix.cons_val_succ, Fin.val_zero, pow_zero, one_mul, sub_self, mul_zero, zero_mul, Finset.sum_const_zero, add_zero] _ = det (of fun i j : Fin n => (v (Fin.succ i) - v 0) * ∑ k ∈ Finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ) : Matrix _ _ R) := by congr ext i j rw [Fin.succAbove_zero, Matrix.cons_val_succ, Fin.val_succ, mul_comm] exact (geom_sum₂_mul (v i.succ) (v 0) (j + 1 : ℕ)).symm _ = (∏ i ∈ Finset.univ, (v (Fin.succ i) - v 0)) * det fun i j : Fin n => ∑ k ∈ Finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ) := (det_mul_column (fun i => v (Fin.succ i) - v 0) _) _ = (∏ i ∈ Finset.univ, (v (Fin.succ i) - v 0)) * det fun i j : Fin n => v (Fin.succ i) ^ (j : ℕ) := congr_arg _ ?_ _ = ∏ i : Fin n.succ, ∏ j ∈ Ioi i, (v j - v i) := by simp_rw [Fin.prod_univ_succ, Fin.prod_Ioi_zero, Fin.prod_Ioi_succ] have h := ih (v ∘ Fin.succ) unfold Function.comp at h rw [h] · intro i j simp_rw [of_apply] rw [Matrix.cons_val_zero] refine Fin.cases ?_ (fun i => ?_) i · simp rw [Matrix.cons_val_succ, Matrix.cons_val_succ, Pi.one_apply] ring · cases n · rw [det_eq_one_of_card_eq_zero (Fintype.card_fin 0), det_eq_one_of_card_eq_zero (Fintype.card_fin 0)] apply det_eq_of_forall_col_eq_smul_add_pred fun _ => v 0 · intro j simp · intro i j simp only [smul_eq_mul, Pi.add_apply, Fin.val_succ, Fin.coe_castSucc, Pi.smul_apply] rw [Finset.sum_range_succ, add_comm, tsub_self, pow_zero, mul_one, Finset.mul_sum] congr 1 refine Finset.sum_congr rfl fun i' hi' => ?_ rw [mul_left_comm (v 0), Nat.succ_sub, pow_succ'] exact Nat.lt_succ_iff.mp (Finset.mem_range.mp hi')
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.MeasureTheory.Integral.IntegrableOn import Mathlib.MeasureTheory.Integral.Bochner import Mathlib.MeasureTheory.Function.LocallyIntegrable import Mathlib.Topology.MetricSpace.ThickenedIndicator import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Analysis.NormedSpace.HahnBanach.SeparatingDual #align_import measure_theory.integral.setIntegral from "leanprover-community/mathlib"@"24e0c85412ff6adbeca08022c25ba4876eedf37a" /-! # Set integral In this file we prove some properties of `∫ x in s, f x ∂μ`. Recall that this notation is defined as `∫ x, f x ∂(μ.restrict s)`. In `integral_indicator` we prove that for a measurable function `f` and a measurable set `s` this definition coincides with another natural definition: `∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ`, where `indicator s f x` is equal to `f x` for `x ∈ s` and is zero otherwise. Since `∫ x in s, f x ∂μ` is a notation, one can rewrite or apply any theorem about `∫ x, f x ∂μ` directly. In this file we prove some theorems about dependence of `∫ x in s, f x ∂μ` on `s`, e.g. `integral_union`, `integral_empty`, `integral_univ`. We use the property `IntegrableOn f s μ := Integrable f (μ.restrict s)`, defined in `MeasureTheory.IntegrableOn`. We also defined in that same file a predicate `IntegrableAtFilter (f : X → E) (l : Filter X) (μ : Measure X)` saying that `f` is integrable at some set `s ∈ l`. Finally, we prove a version of the [Fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) for set integral, see `Filter.Tendsto.integral_sub_linear_isLittleO_ae` and its corollaries. Namely, consider a measurably generated filter `l`, a measure `μ` finite at this filter, and a function `f` that has a finite limit `c` at `l ⊓ ae μ`. Then `∫ x in s, f x ∂μ = μ s • c + o(μ s)` as `s` tends to `l.smallSets`, i.e. for any `ε>0` there exists `t ∈ l` such that `‖∫ x in s, f x ∂μ - μ s • c‖ ≤ ε * μ s` whenever `s ⊆ t`. We also formulate a version of this theorem for a locally finite measure `μ` and a function `f` continuous at a point `a`. ## Notation We provide the following notations for expressing the integral of a function on a set : * `∫ x in s, f x ∂μ` is `MeasureTheory.integral (μ.restrict s) f` * `∫ x in s, f x` is `∫ x in s, f x ∂volume` Note that the set notations are defined in the file `Mathlib/MeasureTheory/Integral/Bochner.lean`, but we reference them here because all theorems about set integrals are in this file. -/ assert_not_exists InnerProductSpace noncomputable section open Set Filter TopologicalSpace MeasureTheory Function RCLike open scoped Classical Topology ENNReal NNReal variable {X Y E F : Type*} [MeasurableSpace X] namespace MeasureTheory section NormedAddCommGroup variable [NormedAddCommGroup E] [NormedSpace ℝ E] {f g : X → E} {s t : Set X} {μ ν : Measure X} {l l' : Filter X} theorem setIntegral_congr_ae₀ (hs : NullMeasurableSet s μ) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := integral_congr_ae ((ae_restrict_iff'₀ hs).2 h) #align measure_theory.set_integral_congr_ae₀ MeasureTheory.setIntegral_congr_ae₀ @[deprecated (since := "2024-04-17")] alias set_integral_congr_ae₀ := setIntegral_congr_ae₀ theorem setIntegral_congr_ae (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := integral_congr_ae ((ae_restrict_iff' hs).2 h) #align measure_theory.set_integral_congr_ae MeasureTheory.setIntegral_congr_ae @[deprecated (since := "2024-04-17")] alias set_integral_congr_ae := setIntegral_congr_ae theorem setIntegral_congr₀ (hs : NullMeasurableSet s μ) (h : EqOn f g s) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := setIntegral_congr_ae₀ hs <| eventually_of_forall h #align measure_theory.set_integral_congr₀ MeasureTheory.setIntegral_congr₀ @[deprecated (since := "2024-04-17")] alias set_integral_congr₀ := setIntegral_congr₀ theorem setIntegral_congr (hs : MeasurableSet s) (h : EqOn f g s) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := setIntegral_congr_ae hs <| eventually_of_forall h #align measure_theory.set_integral_congr MeasureTheory.setIntegral_congr @[deprecated (since := "2024-04-17")] alias set_integral_congr := setIntegral_congr theorem setIntegral_congr_set_ae (hst : s =ᵐ[μ] t) : ∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ := by rw [Measure.restrict_congr_set hst] #align measure_theory.set_integral_congr_set_ae MeasureTheory.setIntegral_congr_set_ae @[deprecated (since := "2024-04-17")] alias set_integral_congr_set_ae := setIntegral_congr_set_ae theorem integral_union_ae (hst : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) (hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ := by simp only [IntegrableOn, Measure.restrict_union₀ hst ht, integral_add_measure hfs hft] #align measure_theory.integral_union_ae MeasureTheory.integral_union_ae theorem integral_union (hst : Disjoint s t) (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ := integral_union_ae hst.aedisjoint ht.nullMeasurableSet hfs hft #align measure_theory.integral_union MeasureTheory.integral_union theorem integral_diff (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) (hts : t ⊆ s) : ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ - ∫ x in t, f x ∂μ := by rw [eq_sub_iff_add_eq, ← integral_union, diff_union_of_subset hts] exacts [disjoint_sdiff_self_left, ht, hfs.mono_set diff_subset, hfs.mono_set hts] #align measure_theory.integral_diff MeasureTheory.integral_diff theorem integral_inter_add_diff₀ (ht : NullMeasurableSet t μ) (hfs : IntegrableOn f s μ) : ∫ x in s ∩ t, f x ∂μ + ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ := by rw [← Measure.restrict_inter_add_diff₀ s ht, integral_add_measure] · exact Integrable.mono_measure hfs (Measure.restrict_mono inter_subset_left le_rfl) · exact Integrable.mono_measure hfs (Measure.restrict_mono diff_subset le_rfl) #align measure_theory.integral_inter_add_diff₀ MeasureTheory.integral_inter_add_diff₀ theorem integral_inter_add_diff (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) : ∫ x in s ∩ t, f x ∂μ + ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_inter_add_diff₀ ht.nullMeasurableSet hfs #align measure_theory.integral_inter_add_diff MeasureTheory.integral_inter_add_diff theorem integral_finset_biUnion {ι : Type*} (t : Finset ι) {s : ι → Set X} (hs : ∀ i ∈ t, MeasurableSet (s i)) (h's : Set.Pairwise (↑t) (Disjoint on s)) (hf : ∀ i ∈ t, IntegrableOn f (s i) μ) : ∫ x in ⋃ i ∈ t, s i, f x ∂μ = ∑ i ∈ t, ∫ x in s i, f x ∂μ := by induction' t using Finset.induction_on with a t hat IH hs h's · simp · simp only [Finset.coe_insert, Finset.forall_mem_insert, Set.pairwise_insert, Finset.set_biUnion_insert] at hs hf h's ⊢ rw [integral_union _ _ hf.1 (integrableOn_finset_iUnion.2 hf.2)] · rw [Finset.sum_insert hat, IH hs.2 h's.1 hf.2] · simp only [disjoint_iUnion_right] exact fun i hi => (h's.2 i hi (ne_of_mem_of_not_mem hi hat).symm).1 · exact Finset.measurableSet_biUnion _ hs.2 #align measure_theory.integral_finset_bUnion MeasureTheory.integral_finset_biUnion theorem integral_fintype_iUnion {ι : Type*} [Fintype ι] {s : ι → Set X} (hs : ∀ i, MeasurableSet (s i)) (h's : Pairwise (Disjoint on s)) (hf : ∀ i, IntegrableOn f (s i) μ) : ∫ x in ⋃ i, s i, f x ∂μ = ∑ i, ∫ x in s i, f x ∂μ := by convert integral_finset_biUnion Finset.univ (fun i _ => hs i) _ fun i _ => hf i · simp · simp [pairwise_univ, h's] #align measure_theory.integral_fintype_Union MeasureTheory.integral_fintype_iUnion theorem integral_empty : ∫ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, integral_zero_measure] #align measure_theory.integral_empty MeasureTheory.integral_empty theorem integral_univ : ∫ x in univ, f x ∂μ = ∫ x, f x ∂μ := by rw [Measure.restrict_univ] #align measure_theory.integral_univ MeasureTheory.integral_univ theorem integral_add_compl₀ (hs : NullMeasurableSet s μ) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ := by rw [ ← integral_union_ae disjoint_compl_right.aedisjoint hs.compl hfi.integrableOn hfi.integrableOn, union_compl_self, integral_univ] #align measure_theory.integral_add_compl₀ MeasureTheory.integral_add_compl₀ theorem integral_add_compl (hs : MeasurableSet s) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ := integral_add_compl₀ hs.nullMeasurableSet hfi #align measure_theory.integral_add_compl MeasureTheory.integral_add_compl /-- For a function `f` and a measurable set `s`, the integral of `indicator s f` over the whole space is equal to `∫ x in s, f x ∂μ` defined as `∫ x, f x ∂(μ.restrict s)`. -/ theorem integral_indicator (hs : MeasurableSet s) : ∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ := by by_cases hfi : IntegrableOn f s μ; swap · rw [integral_undef hfi, integral_undef] rwa [integrable_indicator_iff hs] calc ∫ x, indicator s f x ∂μ = ∫ x in s, indicator s f x ∂μ + ∫ x in sᶜ, indicator s f x ∂μ := (integral_add_compl hs (hfi.integrable_indicator hs)).symm _ = ∫ x in s, f x ∂μ + ∫ x in sᶜ, 0 ∂μ := (congr_arg₂ (· + ·) (integral_congr_ae (indicator_ae_eq_restrict hs)) (integral_congr_ae (indicator_ae_eq_restrict_compl hs))) _ = ∫ x in s, f x ∂μ := by simp #align measure_theory.integral_indicator MeasureTheory.integral_indicator theorem setIntegral_indicator (ht : MeasurableSet t) : ∫ x in s, t.indicator f x ∂μ = ∫ x in s ∩ t, f x ∂μ := by rw [integral_indicator ht, Measure.restrict_restrict ht, Set.inter_comm] #align measure_theory.set_integral_indicator MeasureTheory.setIntegral_indicator @[deprecated (since := "2024-04-17")] alias set_integral_indicator := setIntegral_indicator theorem ofReal_setIntegral_one_of_measure_ne_top {X : Type*} {m : MeasurableSpace X} {μ : Measure X} {s : Set X} (hs : μ s ≠ ∞) : ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = μ s := calc ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = ENNReal.ofReal (∫ _ in s, ‖(1 : ℝ)‖ ∂μ) := by simp only [norm_one] _ = ∫⁻ _ in s, 1 ∂μ := by rw [ofReal_integral_norm_eq_lintegral_nnnorm (integrableOn_const.2 (Or.inr hs.lt_top))] simp only [nnnorm_one, ENNReal.coe_one] _ = μ s := set_lintegral_one _ #align measure_theory.of_real_set_integral_one_of_measure_ne_top MeasureTheory.ofReal_setIntegral_one_of_measure_ne_top @[deprecated (since := "2024-04-17")] alias ofReal_set_integral_one_of_measure_ne_top := ofReal_setIntegral_one_of_measure_ne_top theorem ofReal_setIntegral_one {X : Type*} {_ : MeasurableSpace X} (μ : Measure X) [IsFiniteMeasure μ] (s : Set X) : ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = μ s := ofReal_setIntegral_one_of_measure_ne_top (measure_ne_top μ s) #align measure_theory.of_real_set_integral_one MeasureTheory.ofReal_setIntegral_one @[deprecated (since := "2024-04-17")] alias ofReal_set_integral_one := ofReal_setIntegral_one theorem integral_piecewise [DecidablePred (· ∈ s)] (hs : MeasurableSet s) (hf : IntegrableOn f s μ) (hg : IntegrableOn g sᶜ μ) : ∫ x, s.piecewise f g x ∂μ = ∫ x in s, f x ∂μ + ∫ x in sᶜ, g x ∂μ := by rw [← Set.indicator_add_compl_eq_piecewise, integral_add' (hf.integrable_indicator hs) (hg.integrable_indicator hs.compl), integral_indicator hs, integral_indicator hs.compl] #align measure_theory.integral_piecewise MeasureTheory.integral_piecewise theorem tendsto_setIntegral_of_monotone {ι : Type*} [Countable ι] [SemilatticeSup ι] {s : ι → Set X} (hsm : ∀ i, MeasurableSet (s i)) (h_mono : Monotone s) (hfi : IntegrableOn f (⋃ n, s n) μ) : Tendsto (fun i => ∫ x in s i, f x ∂μ) atTop (𝓝 (∫ x in ⋃ n, s n, f x ∂μ)) := by have hfi' : ∫⁻ x in ⋃ n, s n, ‖f x‖₊ ∂μ < ∞ := hfi.2 set S := ⋃ i, s i have hSm : MeasurableSet S := MeasurableSet.iUnion hsm have hsub : ∀ {i}, s i ⊆ S := @(subset_iUnion s) rw [← withDensity_apply _ hSm] at hfi' set ν := μ.withDensity fun x => ‖f x‖₊ with hν refine Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le have : ∀ᶠ i in atTop, ν (s i) ∈ Icc (ν S - ε) (ν S + ε) := tendsto_measure_iUnion h_mono (ENNReal.Icc_mem_nhds hfi'.ne (ENNReal.coe_pos.2 ε0).ne') filter_upwards [this] with i hi rw [mem_closedBall_iff_norm', ← integral_diff (hsm i) hfi hsub, ← coe_nnnorm, NNReal.coe_le_coe, ← ENNReal.coe_le_coe] refine (ennnorm_integral_le_lintegral_ennnorm _).trans ?_ rw [← withDensity_apply _ (hSm.diff (hsm _)), ← hν, measure_diff hsub (hsm _)] exacts [tsub_le_iff_tsub_le.mp hi.1, (hi.2.trans_lt <| ENNReal.add_lt_top.2 ⟨hfi', ENNReal.coe_lt_top⟩).ne] #align measure_theory.tendsto_set_integral_of_monotone MeasureTheory.tendsto_setIntegral_of_monotone @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_monotone := tendsto_setIntegral_of_monotone theorem tendsto_setIntegral_of_antitone {ι : Type*} [Countable ι] [SemilatticeSup ι] {s : ι → Set X} (hsm : ∀ i, MeasurableSet (s i)) (h_anti : Antitone s) (hfi : ∃ i, IntegrableOn f (s i) μ) : Tendsto (fun i ↦ ∫ x in s i, f x ∂μ) atTop (𝓝 (∫ x in ⋂ n, s n, f x ∂μ)) := by set S := ⋂ i, s i have hSm : MeasurableSet S := MeasurableSet.iInter hsm have hsub i : S ⊆ s i := iInter_subset _ _ set ν := μ.withDensity fun x => ‖f x‖₊ with hν refine Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le rcases hfi with ⟨i₀, hi₀⟩ have νi₀ : ν (s i₀) ≠ ∞ := by simpa [hsm i₀, ν, ENNReal.ofReal, norm_toNNReal] using hi₀.norm.lintegral_lt_top.ne have νS : ν S ≠ ∞ := ((measure_mono (hsub i₀)).trans_lt νi₀.lt_top).ne have : ∀ᶠ i in atTop, ν (s i) ∈ Icc (ν S - ε) (ν S + ε) := by apply tendsto_measure_iInter hsm h_anti ⟨i₀, νi₀⟩ apply ENNReal.Icc_mem_nhds νS (ENNReal.coe_pos.2 ε0).ne' filter_upwards [this, Ici_mem_atTop i₀] with i hi h'i rw [mem_closedBall_iff_norm, ← integral_diff hSm (hi₀.mono_set (h_anti h'i)) (hsub i), ← coe_nnnorm, NNReal.coe_le_coe, ← ENNReal.coe_le_coe] refine (ennnorm_integral_le_lintegral_ennnorm _).trans ?_ rw [← withDensity_apply _ ((hsm _).diff hSm), ← hν, measure_diff (hsub i) hSm νS] exact tsub_le_iff_left.2 hi.2 @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_antitone := tendsto_setIntegral_of_antitone theorem hasSum_integral_iUnion_ae {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : HasSum (fun n => ∫ x in s n, f x ∂μ) (∫ x in ⋃ n, s n, f x ∂μ) := by simp only [IntegrableOn, Measure.restrict_iUnion_ae hd hm] at hfi ⊢ exact hasSum_integral_measure hfi #align measure_theory.has_sum_integral_Union_ae MeasureTheory.hasSum_integral_iUnion_ae theorem hasSum_integral_iUnion {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : HasSum (fun n => ∫ x in s n, f x ∂μ) (∫ x in ⋃ n, s n, f x ∂μ) := hasSum_integral_iUnion_ae (fun i => (hm i).nullMeasurableSet) (hd.mono fun _ _ h => h.aedisjoint) hfi #align measure_theory.has_sum_integral_Union MeasureTheory.hasSum_integral_iUnion theorem integral_iUnion {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : ∫ x in ⋃ n, s n, f x ∂μ = ∑' n, ∫ x in s n, f x ∂μ := (HasSum.tsum_eq (hasSum_integral_iUnion hm hd hfi)).symm #align measure_theory.integral_Union MeasureTheory.integral_iUnion theorem integral_iUnion_ae {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : ∫ x in ⋃ n, s n, f x ∂μ = ∑' n, ∫ x in s n, f x ∂μ := (HasSum.tsum_eq (hasSum_integral_iUnion_ae hm hd hfi)).symm #align measure_theory.integral_Union_ae MeasureTheory.integral_iUnion_ae theorem setIntegral_eq_zero_of_ae_eq_zero (ht_eq : ∀ᵐ x ∂μ, x ∈ t → f x = 0) : ∫ x in t, f x ∂μ = 0 := by by_cases hf : AEStronglyMeasurable f (μ.restrict t); swap · rw [integral_undef] contrapose! hf exact hf.1 have : ∫ x in t, hf.mk f x ∂μ = 0 := by refine integral_eq_zero_of_ae ?_ rw [EventuallyEq, ae_restrict_iff (hf.stronglyMeasurable_mk.measurableSet_eq_fun stronglyMeasurable_zero)] filter_upwards [ae_imp_of_ae_restrict hf.ae_eq_mk, ht_eq] with x hx h'x h''x rw [← hx h''x] exact h'x h''x rw [← this] exact integral_congr_ae hf.ae_eq_mk #align measure_theory.set_integral_eq_zero_of_ae_eq_zero MeasureTheory.setIntegral_eq_zero_of_ae_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_of_ae_eq_zero := setIntegral_eq_zero_of_ae_eq_zero theorem setIntegral_eq_zero_of_forall_eq_zero (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in t, f x ∂μ = 0 := setIntegral_eq_zero_of_ae_eq_zero (eventually_of_forall ht_eq) #align measure_theory.set_integral_eq_zero_of_forall_eq_zero MeasureTheory.setIntegral_eq_zero_of_forall_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_of_forall_eq_zero := setIntegral_eq_zero_of_forall_eq_zero theorem integral_union_eq_left_of_ae_aux (ht_eq : ∀ᵐ x ∂μ.restrict t, f x = 0) (haux : StronglyMeasurable f) (H : IntegrableOn f (s ∪ t) μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := by let k := f ⁻¹' {0} have hk : MeasurableSet k := by borelize E; exact haux.measurable (measurableSet_singleton _) have h's : IntegrableOn f s μ := H.mono subset_union_left le_rfl have A : ∀ u : Set X, ∫ x in u ∩ k, f x ∂μ = 0 := fun u => setIntegral_eq_zero_of_forall_eq_zero fun x hx => hx.2 rw [← integral_inter_add_diff hk h's, ← integral_inter_add_diff hk H, A, A, zero_add, zero_add, union_diff_distrib, union_comm] apply setIntegral_congr_set_ae rw [union_ae_eq_right] apply measure_mono_null diff_subset rw [measure_zero_iff_ae_nmem] filter_upwards [ae_imp_of_ae_restrict ht_eq] with x hx h'x using h'x.2 (hx h'x.1) #align measure_theory.integral_union_eq_left_of_ae_aux MeasureTheory.integral_union_eq_left_of_ae_aux theorem integral_union_eq_left_of_ae (ht_eq : ∀ᵐ x ∂μ.restrict t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := by have ht : IntegrableOn f t μ := by apply integrableOn_zero.congr_fun_ae; symm; exact ht_eq by_cases H : IntegrableOn f (s ∪ t) μ; swap · rw [integral_undef H, integral_undef]; simpa [integrableOn_union, ht] using H let f' := H.1.mk f calc ∫ x : X in s ∪ t, f x ∂μ = ∫ x : X in s ∪ t, f' x ∂μ := integral_congr_ae H.1.ae_eq_mk _ = ∫ x in s, f' x ∂μ := by apply integral_union_eq_left_of_ae_aux _ H.1.stronglyMeasurable_mk (H.congr_fun_ae H.1.ae_eq_mk) filter_upwards [ht_eq, ae_mono (Measure.restrict_mono subset_union_right le_rfl) H.1.ae_eq_mk] with x hx h'x rw [← h'x, hx] _ = ∫ x in s, f x ∂μ := integral_congr_ae (ae_mono (Measure.restrict_mono subset_union_left le_rfl) H.1.ae_eq_mk.symm) #align measure_theory.integral_union_eq_left_of_ae MeasureTheory.integral_union_eq_left_of_ae theorem integral_union_eq_left_of_forall₀ {f : X → E} (ht : NullMeasurableSet t μ) (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_union_eq_left_of_ae ((ae_restrict_iff'₀ ht).2 (eventually_of_forall ht_eq)) #align measure_theory.integral_union_eq_left_of_forall₀ MeasureTheory.integral_union_eq_left_of_forall₀ theorem integral_union_eq_left_of_forall {f : X → E} (ht : MeasurableSet t) (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_union_eq_left_of_forall₀ ht.nullMeasurableSet ht_eq #align measure_theory.integral_union_eq_left_of_forall MeasureTheory.integral_union_eq_left_of_forall theorem setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux (hts : s ⊆ t) (h't : ∀ᵐ x ∂μ, x ∈ t \ s → f x = 0) (haux : StronglyMeasurable f) (h'aux : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := by let k := f ⁻¹' {0} have hk : MeasurableSet k := by borelize E; exact haux.measurable (measurableSet_singleton _) calc ∫ x in t, f x ∂μ = ∫ x in t ∩ k, f x ∂μ + ∫ x in t \ k, f x ∂μ := by rw [integral_inter_add_diff hk h'aux] _ = ∫ x in t \ k, f x ∂μ := by rw [setIntegral_eq_zero_of_forall_eq_zero fun x hx => ?_, zero_add]; exact hx.2 _ = ∫ x in s \ k, f x ∂μ := by apply setIntegral_congr_set_ae filter_upwards [h't] with x hx change (x ∈ t \ k) = (x ∈ s \ k) simp only [mem_preimage, mem_singleton_iff, eq_iff_iff, and_congr_left_iff, mem_diff] intro h'x by_cases xs : x ∈ s · simp only [xs, hts xs] · simp only [xs, iff_false_iff] intro xt exact h'x (hx ⟨xt, xs⟩) _ = ∫ x in s ∩ k, f x ∂μ + ∫ x in s \ k, f x ∂μ := by have : ∀ x ∈ s ∩ k, f x = 0 := fun x hx => hx.2 rw [setIntegral_eq_zero_of_forall_eq_zero this, zero_add] _ = ∫ x in s, f x ∂μ := by rw [integral_inter_add_diff hk (h'aux.mono hts le_rfl)] #align measure_theory.set_integral_eq_of_subset_of_ae_diff_eq_zero_aux MeasureTheory.setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_ae_diff_eq_zero_aux := setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux /-- If a function vanishes almost everywhere on `t \ s` with `s ⊆ t`, then its integrals on `s` and `t` coincide if `t` is null-measurable. -/ theorem setIntegral_eq_of_subset_of_ae_diff_eq_zero (ht : NullMeasurableSet t μ) (hts : s ⊆ t) (h't : ∀ᵐ x ∂μ, x ∈ t \ s → f x = 0) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := by by_cases h : IntegrableOn f t μ; swap · have : ¬IntegrableOn f s μ := fun H => h (H.of_ae_diff_eq_zero ht h't) rw [integral_undef h, integral_undef this] let f' := h.1.mk f calc ∫ x in t, f x ∂μ = ∫ x in t, f' x ∂μ := integral_congr_ae h.1.ae_eq_mk _ = ∫ x in s, f' x ∂μ := by apply setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux hts _ h.1.stronglyMeasurable_mk (h.congr h.1.ae_eq_mk) filter_upwards [h't, ae_imp_of_ae_restrict h.1.ae_eq_mk] with x hx h'x h''x rw [← h'x h''x.1, hx h''x] _ = ∫ x in s, f x ∂μ := by apply integral_congr_ae apply ae_restrict_of_ae_restrict_of_subset hts exact h.1.ae_eq_mk.symm #align measure_theory.set_integral_eq_of_subset_of_ae_diff_eq_zero MeasureTheory.setIntegral_eq_of_subset_of_ae_diff_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_ae_diff_eq_zero := setIntegral_eq_of_subset_of_ae_diff_eq_zero /-- If a function vanishes on `t \ s` with `s ⊆ t`, then its integrals on `s` and `t` coincide if `t` is measurable. -/ theorem setIntegral_eq_of_subset_of_forall_diff_eq_zero (ht : MeasurableSet t) (hts : s ⊆ t) (h't : ∀ x ∈ t \ s, f x = 0) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := setIntegral_eq_of_subset_of_ae_diff_eq_zero ht.nullMeasurableSet hts (eventually_of_forall fun x hx => h't x hx) #align measure_theory.set_integral_eq_of_subset_of_forall_diff_eq_zero MeasureTheory.setIntegral_eq_of_subset_of_forall_diff_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_forall_diff_eq_zero := setIntegral_eq_of_subset_of_forall_diff_eq_zero /-- If a function vanishes almost everywhere on `sᶜ`, then its integral on `s` coincides with its integral on the whole space. -/ theorem setIntegral_eq_integral_of_ae_compl_eq_zero (h : ∀ᵐ x ∂μ, x ∉ s → f x = 0) : ∫ x in s, f x ∂μ = ∫ x, f x ∂μ := by symm nth_rw 1 [← integral_univ] apply setIntegral_eq_of_subset_of_ae_diff_eq_zero nullMeasurableSet_univ (subset_univ _) filter_upwards [h] with x hx h'x using hx h'x.2 #align measure_theory.set_integral_eq_integral_of_ae_compl_eq_zero MeasureTheory.setIntegral_eq_integral_of_ae_compl_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_integral_of_ae_compl_eq_zero := setIntegral_eq_integral_of_ae_compl_eq_zero /-- If a function vanishes on `sᶜ`, then its integral on `s` coincides with its integral on the whole space. -/ theorem setIntegral_eq_integral_of_forall_compl_eq_zero (h : ∀ x, x ∉ s → f x = 0) : ∫ x in s, f x ∂μ = ∫ x, f x ∂μ := setIntegral_eq_integral_of_ae_compl_eq_zero (eventually_of_forall h) #align measure_theory.set_integral_eq_integral_of_forall_compl_eq_zero MeasureTheory.setIntegral_eq_integral_of_forall_compl_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_integral_of_forall_compl_eq_zero := setIntegral_eq_integral_of_forall_compl_eq_zero theorem setIntegral_neg_eq_setIntegral_nonpos [LinearOrder E] {f : X → E} (hf : AEStronglyMeasurable f μ) : ∫ x in {x | f x < 0}, f x ∂μ = ∫ x in {x | f x ≤ 0}, f x ∂μ := by have h_union : {x | f x ≤ 0} = {x | f x < 0} ∪ {x | f x = 0} := by simp_rw [le_iff_lt_or_eq, setOf_or] rw [h_union] have B : NullMeasurableSet {x | f x = 0} μ := hf.nullMeasurableSet_eq_fun aestronglyMeasurable_zero symm refine integral_union_eq_left_of_ae ?_ filter_upwards [ae_restrict_mem₀ B] with x hx using hx #align measure_theory.set_integral_neg_eq_set_integral_nonpos MeasureTheory.setIntegral_neg_eq_setIntegral_nonpos @[deprecated (since := "2024-04-17")] alias set_integral_neg_eq_set_integral_nonpos := setIntegral_neg_eq_setIntegral_nonpos theorem integral_norm_eq_pos_sub_neg {f : X → ℝ} (hfi : Integrable f μ) : ∫ x, ‖f x‖ ∂μ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | f x ≤ 0}, f x ∂μ := have h_meas : NullMeasurableSet {x | 0 ≤ f x} μ := aestronglyMeasurable_const.nullMeasurableSet_le hfi.1 calc ∫ x, ‖f x‖ ∂μ = ∫ x in {x | 0 ≤ f x}, ‖f x‖ ∂μ + ∫ x in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ := by rw [← integral_add_compl₀ h_meas hfi.norm] _ = ∫ x in {x | 0 ≤ f x}, f x ∂μ + ∫ x in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ := by congr 1 refine setIntegral_congr₀ h_meas fun x hx => ?_ dsimp only rw [Real.norm_eq_abs, abs_eq_self.mpr _] exact hx _ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | 0 ≤ f x}ᶜ, f x ∂μ := by congr 1 rw [← integral_neg] refine setIntegral_congr₀ h_meas.compl fun x hx => ?_ dsimp only rw [Real.norm_eq_abs, abs_eq_neg_self.mpr _] rw [Set.mem_compl_iff, Set.nmem_setOf_iff] at hx linarith _ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | f x ≤ 0}, f x ∂μ := by rw [← setIntegral_neg_eq_setIntegral_nonpos hfi.1, compl_setOf]; simp only [not_le] #align measure_theory.integral_norm_eq_pos_sub_neg MeasureTheory.integral_norm_eq_pos_sub_neg theorem setIntegral_const [CompleteSpace E] (c : E) : ∫ _ in s, c ∂μ = (μ s).toReal • c := by rw [integral_const, Measure.restrict_apply_univ] #align measure_theory.set_integral_const MeasureTheory.setIntegral_const @[deprecated (since := "2024-04-17")] alias set_integral_const := setIntegral_const @[simp] theorem integral_indicator_const [CompleteSpace E] (e : E) ⦃s : Set X⦄ (s_meas : MeasurableSet s) : ∫ x : X, s.indicator (fun _ : X => e) x ∂μ = (μ s).toReal • e := by rw [integral_indicator s_meas, ← setIntegral_const] #align measure_theory.integral_indicator_const MeasureTheory.integral_indicator_const @[simp] theorem integral_indicator_one ⦃s : Set X⦄ (hs : MeasurableSet s) : ∫ x, s.indicator 1 x ∂μ = (μ s).toReal := (integral_indicator_const 1 hs).trans ((smul_eq_mul _).trans (mul_one _)) #align measure_theory.integral_indicator_one MeasureTheory.integral_indicator_one theorem setIntegral_indicatorConstLp [CompleteSpace E] {p : ℝ≥0∞} (hs : MeasurableSet s) (ht : MeasurableSet t) (hμt : μ t ≠ ∞) (e : E) : ∫ x in s, indicatorConstLp p ht hμt e x ∂μ = (μ (t ∩ s)).toReal • e := calc ∫ x in s, indicatorConstLp p ht hμt e x ∂μ = ∫ x in s, t.indicator (fun _ => e) x ∂μ := by rw [setIntegral_congr_ae hs (indicatorConstLp_coeFn.mono fun x hx _ => hx)] _ = (μ (t ∩ s)).toReal • e := by rw [integral_indicator_const _ ht, Measure.restrict_apply ht] set_option linter.uppercaseLean3 false in #align measure_theory.set_integral_indicator_const_Lp MeasureTheory.setIntegral_indicatorConstLp @[deprecated (since := "2024-04-17")] alias set_integral_indicatorConstLp := setIntegral_indicatorConstLp theorem integral_indicatorConstLp [CompleteSpace E] {p : ℝ≥0∞} (ht : MeasurableSet t) (hμt : μ t ≠ ∞) (e : E) : ∫ x, indicatorConstLp p ht hμt e x ∂μ = (μ t).toReal • e := calc ∫ x, indicatorConstLp p ht hμt e x ∂μ = ∫ x in univ, indicatorConstLp p ht hμt e x ∂μ := by rw [integral_univ] _ = (μ (t ∩ univ)).toReal • e := setIntegral_indicatorConstLp MeasurableSet.univ ht hμt e _ = (μ t).toReal • e := by rw [inter_univ] set_option linter.uppercaseLean3 false in #align measure_theory.integral_indicator_const_Lp MeasureTheory.integral_indicatorConstLp theorem setIntegral_map {Y} [MeasurableSpace Y] {g : X → Y} {f : Y → E} {s : Set Y} (hs : MeasurableSet s) (hf : AEStronglyMeasurable f (Measure.map g μ)) (hg : AEMeasurable g μ) : ∫ y in s, f y ∂Measure.map g μ = ∫ x in g ⁻¹' s, f (g x) ∂μ := by rw [Measure.restrict_map_of_aemeasurable hg hs, integral_map (hg.mono_measure Measure.restrict_le_self) (hf.mono_measure _)] exact Measure.map_mono_of_aemeasurable Measure.restrict_le_self hg #align measure_theory.set_integral_map MeasureTheory.setIntegral_map @[deprecated (since := "2024-04-17")] alias set_integral_map := setIntegral_map theorem _root_.MeasurableEmbedding.setIntegral_map {Y} {_ : MeasurableSpace Y} {f : X → Y} (hf : MeasurableEmbedding f) (g : Y → E) (s : Set Y) : ∫ y in s, g y ∂Measure.map f μ = ∫ x in f ⁻¹' s, g (f x) ∂μ := by rw [hf.restrict_map, hf.integral_map] #align measurable_embedding.set_integral_map MeasurableEmbedding.setIntegral_map @[deprecated (since := "2024-04-17")] alias _root_.MeasurableEmbedding.set_integral_map := _root_.MeasurableEmbedding.setIntegral_map theorem _root_.ClosedEmbedding.setIntegral_map [TopologicalSpace X] [BorelSpace X] {Y} [MeasurableSpace Y] [TopologicalSpace Y] [BorelSpace Y] {g : X → Y} {f : Y → E} (s : Set Y) (hg : ClosedEmbedding g) : ∫ y in s, f y ∂Measure.map g μ = ∫ x in g ⁻¹' s, f (g x) ∂μ := hg.measurableEmbedding.setIntegral_map _ _ #align closed_embedding.set_integral_map ClosedEmbedding.setIntegral_map @[deprecated (since := "2024-04-17")] alias _root_.ClosedEmbedding.set_integral_map := _root_.ClosedEmbedding.setIntegral_map theorem MeasurePreserving.setIntegral_preimage_emb {Y} {_ : MeasurableSpace Y} {f : X → Y} {ν} (h₁ : MeasurePreserving f μ ν) (h₂ : MeasurableEmbedding f) (g : Y → E) (s : Set Y) : ∫ x in f ⁻¹' s, g (f x) ∂μ = ∫ y in s, g y ∂ν := (h₁.restrict_preimage_emb h₂ s).integral_comp h₂ _ #align measure_theory.measure_preserving.set_integral_preimage_emb MeasureTheory.MeasurePreserving.setIntegral_preimage_emb @[deprecated (since := "2024-04-17")] alias MeasurePreserving.set_integral_preimage_emb := MeasurePreserving.setIntegral_preimage_emb theorem MeasurePreserving.setIntegral_image_emb {Y} {_ : MeasurableSpace Y} {f : X → Y} {ν} (h₁ : MeasurePreserving f μ ν) (h₂ : MeasurableEmbedding f) (g : Y → E) (s : Set X) : ∫ y in f '' s, g y ∂ν = ∫ x in s, g (f x) ∂μ := Eq.symm <| (h₁.restrict_image_emb h₂ s).integral_comp h₂ _ #align measure_theory.measure_preserving.set_integral_image_emb MeasureTheory.MeasurePreserving.setIntegral_image_emb @[deprecated (since := "2024-04-17")] alias MeasurePreserving.set_integral_image_emb := MeasurePreserving.setIntegral_image_emb theorem setIntegral_map_equiv {Y} [MeasurableSpace Y] (e : X ≃ᵐ Y) (f : Y → E) (s : Set Y) : ∫ y in s, f y ∂Measure.map e μ = ∫ x in e ⁻¹' s, f (e x) ∂μ := e.measurableEmbedding.setIntegral_map f s #align measure_theory.set_integral_map_equiv MeasureTheory.setIntegral_map_equiv @[deprecated (since := "2024-04-17")] alias set_integral_map_equiv := setIntegral_map_equiv theorem norm_setIntegral_le_of_norm_le_const_ae {C : ℝ} (hs : μ s < ∞) (hC : ∀ᵐ x ∂μ.restrict s, ‖f x‖ ≤ C) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := by rw [← Measure.restrict_apply_univ] at * haveI : IsFiniteMeasure (μ.restrict s) := ⟨hs⟩ exact norm_integral_le_of_norm_le_const hC #align measure_theory.norm_set_integral_le_of_norm_le_const_ae MeasureTheory.norm_setIntegral_le_of_norm_le_const_ae @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const_ae := norm_setIntegral_le_of_norm_le_const_ae theorem norm_setIntegral_le_of_norm_le_const_ae' {C : ℝ} (hs : μ s < ∞) (hC : ∀ᵐ x ∂μ, x ∈ s → ‖f x‖ ≤ C) (hfm : AEStronglyMeasurable f (μ.restrict s)) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := by apply norm_setIntegral_le_of_norm_le_const_ae hs have A : ∀ᵐ x : X ∂μ, x ∈ s → ‖AEStronglyMeasurable.mk f hfm x‖ ≤ C := by filter_upwards [hC, hfm.ae_mem_imp_eq_mk] with _ h1 h2 h3 rw [← h2 h3] exact h1 h3 have B : MeasurableSet {x | ‖hfm.mk f x‖ ≤ C} := hfm.stronglyMeasurable_mk.norm.measurable measurableSet_Iic filter_upwards [hfm.ae_eq_mk, (ae_restrict_iff B).2 A] with _ h1 _ rwa [h1] #align measure_theory.norm_set_integral_le_of_norm_le_const_ae' MeasureTheory.norm_setIntegral_le_of_norm_le_const_ae' @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const_ae' := norm_setIntegral_le_of_norm_le_const_ae' theorem norm_setIntegral_le_of_norm_le_const_ae'' {C : ℝ} (hs : μ s < ∞) (hsm : MeasurableSet s) (hC : ∀ᵐ x ∂μ, x ∈ s → ‖f x‖ ≤ C) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := norm_setIntegral_le_of_norm_le_const_ae hs <| by rwa [ae_restrict_eq hsm, eventually_inf_principal] #align measure_theory.norm_set_integral_le_of_norm_le_const_ae'' MeasureTheory.norm_setIntegral_le_of_norm_le_const_ae'' @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const_ae'' := norm_setIntegral_le_of_norm_le_const_ae'' theorem norm_setIntegral_le_of_norm_le_const {C : ℝ} (hs : μ s < ∞) (hC : ∀ x ∈ s, ‖f x‖ ≤ C) (hfm : AEStronglyMeasurable f (μ.restrict s)) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := norm_setIntegral_le_of_norm_le_const_ae' hs (eventually_of_forall hC) hfm #align measure_theory.norm_set_integral_le_of_norm_le_const MeasureTheory.norm_setIntegral_le_of_norm_le_const @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const := norm_setIntegral_le_of_norm_le_const theorem norm_setIntegral_le_of_norm_le_const' {C : ℝ} (hs : μ s < ∞) (hsm : MeasurableSet s) (hC : ∀ x ∈ s, ‖f x‖ ≤ C) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := norm_setIntegral_le_of_norm_le_const_ae'' hs hsm <| eventually_of_forall hC #align measure_theory.norm_set_integral_le_of_norm_le_const' MeasureTheory.norm_setIntegral_le_of_norm_le_const' @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const' := norm_setIntegral_le_of_norm_le_const' theorem setIntegral_eq_zero_iff_of_nonneg_ae {f : X → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f) (hfi : IntegrableOn f s μ) : ∫ x in s, f x ∂μ = 0 ↔ f =ᵐ[μ.restrict s] 0 := integral_eq_zero_iff_of_nonneg_ae hf hfi #align measure_theory.set_integral_eq_zero_iff_of_nonneg_ae MeasureTheory.setIntegral_eq_zero_iff_of_nonneg_ae @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_iff_of_nonneg_ae := setIntegral_eq_zero_iff_of_nonneg_ae theorem setIntegral_pos_iff_support_of_nonneg_ae {f : X → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f) (hfi : IntegrableOn f s μ) : (0 < ∫ x in s, f x ∂μ) ↔ 0 < μ (support f ∩ s) := by rw [integral_pos_iff_support_of_nonneg_ae hf hfi, Measure.restrict_apply₀] rw [support_eq_preimage] exact hfi.aestronglyMeasurable.aemeasurable.nullMeasurable (measurableSet_singleton 0).compl #align measure_theory.set_integral_pos_iff_support_of_nonneg_ae MeasureTheory.setIntegral_pos_iff_support_of_nonneg_ae @[deprecated (since := "2024-04-17")] alias set_integral_pos_iff_support_of_nonneg_ae := setIntegral_pos_iff_support_of_nonneg_ae theorem setIntegral_gt_gt {R : ℝ} {f : X → ℝ} (hR : 0 ≤ R) (hfm : Measurable f) (hfint : IntegrableOn f {x | ↑R < f x} μ) (hμ : μ {x | ↑R < f x} ≠ 0) : (μ {x | ↑R < f x}).toReal * R < ∫ x in {x | ↑R < f x}, f x ∂μ := by have : IntegrableOn (fun _ => R) {x | ↑R < f x} μ := by refine ⟨aestronglyMeasurable_const, lt_of_le_of_lt ?_ hfint.2⟩ refine set_lintegral_mono (Measurable.nnnorm ?_).coe_nnreal_ennreal hfm.nnnorm.coe_nnreal_ennreal fun x hx => ?_ · exact measurable_const · simp only [ENNReal.coe_le_coe, Real.nnnorm_of_nonneg hR, Real.nnnorm_of_nonneg (hR.trans <| le_of_lt hx), Subtype.mk_le_mk] exact le_of_lt hx rw [← sub_pos, ← smul_eq_mul, ← setIntegral_const, ← integral_sub hfint this, setIntegral_pos_iff_support_of_nonneg_ae] · rw [← zero_lt_iff] at hμ rwa [Set.inter_eq_self_of_subset_right] exact fun x hx => Ne.symm (ne_of_lt <| sub_pos.2 hx) · rw [Pi.zero_def, EventuallyLE, ae_restrict_iff] · exact eventually_of_forall fun x hx => sub_nonneg.2 <| le_of_lt hx · exact measurableSet_le measurable_zero (hfm.sub measurable_const) · exact Integrable.sub hfint this #align measure_theory.set_integral_gt_gt MeasureTheory.setIntegral_gt_gt @[deprecated (since := "2024-04-17")] alias set_integral_gt_gt := setIntegral_gt_gt theorem setIntegral_trim {X} {m m0 : MeasurableSpace X} {μ : Measure X} (hm : m ≤ m0) {f : X → E} (hf_meas : StronglyMeasurable[m] f) {s : Set X} (hs : MeasurableSet[m] s) : ∫ x in s, f x ∂μ = ∫ x in s, f x ∂μ.trim hm := by rwa [integral_trim hm hf_meas, restrict_trim hm μ] #align measure_theory.set_integral_trim MeasureTheory.setIntegral_trim @[deprecated (since := "2024-04-17")] alias set_integral_trim := setIntegral_trim /-! ### Lemmas about adding and removing interval boundaries The primed lemmas take explicit arguments about the endpoint having zero measure, while the unprimed ones use `[NoAtoms μ]`. -/ section PartialOrder variable [PartialOrder X] {x y : X} theorem integral_Icc_eq_integral_Ioc' (hx : μ {x} = 0) : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioc x y, f t ∂μ := setIntegral_congr_set_ae (Ioc_ae_eq_Icc' hx).symm #align measure_theory.integral_Icc_eq_integral_Ioc' MeasureTheory.integral_Icc_eq_integral_Ioc' theorem integral_Icc_eq_integral_Ico' (hy : μ {y} = 0) : ∫ t in Icc x y, f t ∂μ = ∫ t in Ico x y, f t ∂μ := setIntegral_congr_set_ae (Ico_ae_eq_Icc' hy).symm #align measure_theory.integral_Icc_eq_integral_Ico' MeasureTheory.integral_Icc_eq_integral_Ico' theorem integral_Ioc_eq_integral_Ioo' (hy : μ {y} = 0) : ∫ t in Ioc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := setIntegral_congr_set_ae (Ioo_ae_eq_Ioc' hy).symm #align measure_theory.integral_Ioc_eq_integral_Ioo' MeasureTheory.integral_Ioc_eq_integral_Ioo' theorem integral_Ico_eq_integral_Ioo' (hx : μ {x} = 0) : ∫ t in Ico x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := setIntegral_congr_set_ae (Ioo_ae_eq_Ico' hx).symm #align measure_theory.integral_Ico_eq_integral_Ioo' MeasureTheory.integral_Ico_eq_integral_Ioo' theorem integral_Icc_eq_integral_Ioo' (hx : μ {x} = 0) (hy : μ {y} = 0) : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := setIntegral_congr_set_ae (Ioo_ae_eq_Icc' hx hy).symm #align measure_theory.integral_Icc_eq_integral_Ioo' MeasureTheory.integral_Icc_eq_integral_Ioo' theorem integral_Iic_eq_integral_Iio' (hx : μ {x} = 0) : ∫ t in Iic x, f t ∂μ = ∫ t in Iio x, f t ∂μ := setIntegral_congr_set_ae (Iio_ae_eq_Iic' hx).symm #align measure_theory.integral_Iic_eq_integral_Iio' MeasureTheory.integral_Iic_eq_integral_Iio' theorem integral_Ici_eq_integral_Ioi' (hx : μ {x} = 0) : ∫ t in Ici x, f t ∂μ = ∫ t in Ioi x, f t ∂μ := setIntegral_congr_set_ae (Ioi_ae_eq_Ici' hx).symm #align measure_theory.integral_Ici_eq_integral_Ioi' MeasureTheory.integral_Ici_eq_integral_Ioi' variable [NoAtoms μ] theorem integral_Icc_eq_integral_Ioc : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioc x y, f t ∂μ := integral_Icc_eq_integral_Ioc' <| measure_singleton x #align measure_theory.integral_Icc_eq_integral_Ioc MeasureTheory.integral_Icc_eq_integral_Ioc theorem integral_Icc_eq_integral_Ico : ∫ t in Icc x y, f t ∂μ = ∫ t in Ico x y, f t ∂μ := integral_Icc_eq_integral_Ico' <| measure_singleton y #align measure_theory.integral_Icc_eq_integral_Ico MeasureTheory.integral_Icc_eq_integral_Ico theorem integral_Ioc_eq_integral_Ioo : ∫ t in Ioc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := integral_Ioc_eq_integral_Ioo' <| measure_singleton y #align measure_theory.integral_Ioc_eq_integral_Ioo MeasureTheory.integral_Ioc_eq_integral_Ioo theorem integral_Ico_eq_integral_Ioo : ∫ t in Ico x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := integral_Ico_eq_integral_Ioo' <| measure_singleton x #align measure_theory.integral_Ico_eq_integral_Ioo MeasureTheory.integral_Ico_eq_integral_Ioo theorem integral_Icc_eq_integral_Ioo : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := by rw [integral_Icc_eq_integral_Ico, integral_Ico_eq_integral_Ioo] #align measure_theory.integral_Icc_eq_integral_Ioo MeasureTheory.integral_Icc_eq_integral_Ioo theorem integral_Iic_eq_integral_Iio : ∫ t in Iic x, f t ∂μ = ∫ t in Iio x, f t ∂μ := integral_Iic_eq_integral_Iio' <| measure_singleton x #align measure_theory.integral_Iic_eq_integral_Iio MeasureTheory.integral_Iic_eq_integral_Iio theorem integral_Ici_eq_integral_Ioi : ∫ t in Ici x, f t ∂μ = ∫ t in Ioi x, f t ∂μ := integral_Ici_eq_integral_Ioi' <| measure_singleton x #align measure_theory.integral_Ici_eq_integral_Ioi MeasureTheory.integral_Ici_eq_integral_Ioi end PartialOrder end NormedAddCommGroup section Mono variable {μ : Measure X} {f g : X → ℝ} {s t : Set X} (hf : IntegrableOn f s μ) (hg : IntegrableOn g s μ) theorem setIntegral_mono_ae_restrict (h : f ≤ᵐ[μ.restrict s] g) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := integral_mono_ae hf hg h #align measure_theory.set_integral_mono_ae_restrict MeasureTheory.setIntegral_mono_ae_restrict @[deprecated (since := "2024-04-17")] alias set_integral_mono_ae_restrict := setIntegral_mono_ae_restrict theorem setIntegral_mono_ae (h : f ≤ᵐ[μ] g) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := setIntegral_mono_ae_restrict hf hg (ae_restrict_of_ae h) #align measure_theory.set_integral_mono_ae MeasureTheory.setIntegral_mono_ae @[deprecated (since := "2024-04-17")] alias set_integral_mono_ae := setIntegral_mono_ae theorem setIntegral_mono_on (hs : MeasurableSet s) (h : ∀ x ∈ s, f x ≤ g x) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := setIntegral_mono_ae_restrict hf hg (by simp [hs, EventuallyLE, eventually_inf_principal, ae_of_all _ h]) #align measure_theory.set_integral_mono_on MeasureTheory.setIntegral_mono_on @[deprecated (since := "2024-04-17")] alias set_integral_mono_on := setIntegral_mono_on theorem setIntegral_mono_on_ae (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := by refine setIntegral_mono_ae_restrict hf hg ?_; rwa [EventuallyLE, ae_restrict_iff' hs] #align measure_theory.set_integral_mono_on_ae MeasureTheory.setIntegral_mono_on_ae @[deprecated (since := "2024-04-17")] alias set_integral_mono_on_ae := setIntegral_mono_on_ae theorem setIntegral_mono (h : f ≤ g) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := integral_mono hf hg h #align measure_theory.set_integral_mono MeasureTheory.setIntegral_mono @[deprecated (since := "2024-04-17")] alias set_integral_mono := setIntegral_mono theorem setIntegral_mono_set (hfi : IntegrableOn f t μ) (hf : 0 ≤ᵐ[μ.restrict t] f) (hst : s ≤ᵐ[μ] t) : ∫ x in s, f x ∂μ ≤ ∫ x in t, f x ∂μ := integral_mono_measure (Measure.restrict_mono_ae hst) hf hfi #align measure_theory.set_integral_mono_set MeasureTheory.setIntegral_mono_set @[deprecated (since := "2024-04-17")] alias set_integral_mono_set := setIntegral_mono_set theorem setIntegral_le_integral (hfi : Integrable f μ) (hf : 0 ≤ᵐ[μ] f) : ∫ x in s, f x ∂μ ≤ ∫ x, f x ∂μ := integral_mono_measure (Measure.restrict_le_self) hf hfi @[deprecated (since := "2024-04-17")] alias set_integral_le_integral := setIntegral_le_integral theorem setIntegral_ge_of_const_le {c : ℝ} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (hf : ∀ x ∈ s, c ≤ f x) (hfint : IntegrableOn (fun x : X => f x) s μ) : c * (μ s).toReal ≤ ∫ x in s, f x ∂μ := by rw [mul_comm, ← smul_eq_mul, ← setIntegral_const c] exact setIntegral_mono_on (integrableOn_const.2 (Or.inr hμs.lt_top)) hfint hs hf #align measure_theory.set_integral_ge_of_const_le MeasureTheory.setIntegral_ge_of_const_le @[deprecated (since := "2024-04-17")] alias set_integral_ge_of_const_le := setIntegral_ge_of_const_le end Mono section Nonneg variable {μ : Measure X} {f : X → ℝ} {s : Set X} theorem setIntegral_nonneg_of_ae_restrict (hf : 0 ≤ᵐ[μ.restrict s] f) : 0 ≤ ∫ x in s, f x ∂μ := integral_nonneg_of_ae hf #align measure_theory.set_integral_nonneg_of_ae_restrict MeasureTheory.setIntegral_nonneg_of_ae_restrict @[deprecated (since := "2024-04-17")] alias set_integral_nonneg_of_ae_restrict := setIntegral_nonneg_of_ae_restrict theorem setIntegral_nonneg_of_ae (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ x in s, f x ∂μ := setIntegral_nonneg_of_ae_restrict (ae_restrict_of_ae hf) #align measure_theory.set_integral_nonneg_of_ae MeasureTheory.setIntegral_nonneg_of_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonneg_of_ae := setIntegral_nonneg_of_ae theorem setIntegral_nonneg (hs : MeasurableSet s) (hf : ∀ x, x ∈ s → 0 ≤ f x) : 0 ≤ ∫ x in s, f x ∂μ := setIntegral_nonneg_of_ae_restrict ((ae_restrict_iff' hs).mpr (ae_of_all μ hf)) #align measure_theory.set_integral_nonneg MeasureTheory.setIntegral_nonneg @[deprecated (since := "2024-04-17")] alias set_integral_nonneg := setIntegral_nonneg theorem setIntegral_nonneg_ae (hs : MeasurableSet s) (hf : ∀ᵐ x ∂μ, x ∈ s → 0 ≤ f x) : 0 ≤ ∫ x in s, f x ∂μ := setIntegral_nonneg_of_ae_restrict <| by rwa [EventuallyLE, ae_restrict_iff' hs] #align measure_theory.set_integral_nonneg_ae MeasureTheory.setIntegral_nonneg_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonneg_ae := setIntegral_nonneg_ae theorem setIntegral_le_nonneg {s : Set X} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ ≤ ∫ x in {y | 0 ≤ f y}, f x ∂μ := by rw [← integral_indicator hs, ← integral_indicator (stronglyMeasurable_const.measurableSet_le hf)] exact integral_mono (hfi.indicator hs) (hfi.indicator (stronglyMeasurable_const.measurableSet_le hf)) (indicator_le_indicator_nonneg s f) #align measure_theory.set_integral_le_nonneg MeasureTheory.setIntegral_le_nonneg @[deprecated (since := "2024-04-17")] alias set_integral_le_nonneg := setIntegral_le_nonneg theorem setIntegral_nonpos_of_ae_restrict (hf : f ≤ᵐ[μ.restrict s] 0) : ∫ x in s, f x ∂μ ≤ 0 := integral_nonpos_of_ae hf #align measure_theory.set_integral_nonpos_of_ae_restrict MeasureTheory.setIntegral_nonpos_of_ae_restrict @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_of_ae_restrict := setIntegral_nonpos_of_ae_restrict theorem setIntegral_nonpos_of_ae (hf : f ≤ᵐ[μ] 0) : ∫ x in s, f x ∂μ ≤ 0 := setIntegral_nonpos_of_ae_restrict (ae_restrict_of_ae hf) #align measure_theory.set_integral_nonpos_of_ae MeasureTheory.setIntegral_nonpos_of_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_of_ae := setIntegral_nonpos_of_ae theorem setIntegral_nonpos_ae (hs : MeasurableSet s) (hf : ∀ᵐ x ∂μ, x ∈ s → f x ≤ 0) : ∫ x in s, f x ∂μ ≤ 0 := setIntegral_nonpos_of_ae_restrict <| by rwa [EventuallyLE, ae_restrict_iff' hs] #align measure_theory.set_integral_nonpos_ae MeasureTheory.setIntegral_nonpos_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_ae := setIntegral_nonpos_ae theorem setIntegral_nonpos (hs : MeasurableSet s) (hf : ∀ x, x ∈ s → f x ≤ 0) : ∫ x in s, f x ∂μ ≤ 0 := setIntegral_nonpos_ae hs <| ae_of_all μ hf #align measure_theory.set_integral_nonpos MeasureTheory.setIntegral_nonpos @[deprecated (since := "2024-04-17")] alias set_integral_nonpos := setIntegral_nonpos theorem setIntegral_nonpos_le {s : Set X} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hfi : Integrable f μ) : ∫ x in {y | f y ≤ 0}, f x ∂μ ≤ ∫ x in s, f x ∂μ := by rw [← integral_indicator hs, ← integral_indicator (hf.measurableSet_le stronglyMeasurable_const)] exact integral_mono (hfi.indicator (hf.measurableSet_le stronglyMeasurable_const)) (hfi.indicator hs) (indicator_nonpos_le_indicator s f) #align measure_theory.set_integral_nonpos_le MeasureTheory.setIntegral_nonpos_le @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_le := setIntegral_nonpos_le lemma Integrable.measure_le_integral {f : X → ℝ} (f_int : Integrable f μ) (f_nonneg : 0 ≤ᵐ[μ] f) {s : Set X} (hs : ∀ x ∈ s, 1 ≤ f x) : μ s ≤ ENNReal.ofReal (∫ x, f x ∂μ) := by rw [ofReal_integral_eq_lintegral_ofReal f_int f_nonneg] apply meas_le_lintegral₀ · exact ENNReal.continuous_ofReal.measurable.comp_aemeasurable f_int.1.aemeasurable · intro x hx simpa using ENNReal.ofReal_le_ofReal (hs x hx) lemma integral_le_measure {f : X → ℝ} {s : Set X} (hs : ∀ x ∈ s, f x ≤ 1) (h's : ∀ x ∈ sᶜ, f x ≤ 0) : ENNReal.ofReal (∫ x, f x ∂μ) ≤ μ s := by by_cases H : Integrable f μ; swap · simp [integral_undef H] let g x := max (f x) 0 have g_int : Integrable g μ := H.pos_part have : ENNReal.ofReal (∫ x, f x ∂μ) ≤ ENNReal.ofReal (∫ x, g x ∂μ) := by apply ENNReal.ofReal_le_ofReal exact integral_mono H g_int (fun x ↦ le_max_left _ _) apply this.trans rw [ofReal_integral_eq_lintegral_ofReal g_int (eventually_of_forall (fun x ↦ le_max_right _ _))] apply lintegral_le_meas · intro x apply ENNReal.ofReal_le_of_le_toReal by_cases H : x ∈ s · simpa [g] using hs x H · apply le_trans _ zero_le_one simpa [g] using h's x H · intro x hx simpa [g] using h's x hx end Nonneg section IntegrableUnion variable {ι : Type*} [Countable ι] {μ : Measure X} [NormedAddCommGroup E] theorem integrableOn_iUnion_of_summable_integral_norm {f : X → E} {s : ι → Set X} (hs : ∀ i : ι, MeasurableSet (s i)) (hi : ∀ i : ι, IntegrableOn f (s i) μ) (h : Summable fun i : ι => ∫ x : X in s i, ‖f x‖ ∂μ) : IntegrableOn f (iUnion s) μ := by refine ⟨AEStronglyMeasurable.iUnion fun i => (hi i).1, (lintegral_iUnion_le _ _).trans_lt ?_⟩ have B := fun i => lintegral_coe_eq_integral (fun x : X => ‖f x‖₊) (hi i).norm rw [tsum_congr B] have S' : Summable fun i : ι => (⟨∫ x : X in s i, ‖f x‖₊ ∂μ, setIntegral_nonneg (hs i) fun x _ => NNReal.coe_nonneg _⟩ : NNReal) := by rw [← NNReal.summable_coe]; exact h have S'' := ENNReal.tsum_coe_eq S'.hasSum simp_rw [ENNReal.coe_nnreal_eq, NNReal.coe_mk, coe_nnnorm] at S'' convert ENNReal.ofReal_lt_top #align measure_theory.integrable_on_Union_of_summable_integral_norm MeasureTheory.integrableOn_iUnion_of_summable_integral_norm variable [TopologicalSpace X] [BorelSpace X] [MetrizableSpace X] [IsLocallyFiniteMeasure μ] /-- If `s` is a countable family of compact sets, `f` is a continuous function, and the sequence `‖f.restrict (s i)‖ * μ (s i)` is summable, then `f` is integrable on the union of the `s i`. -/ theorem integrableOn_iUnion_of_summable_norm_restrict {f : C(X, E)} {s : ι → Compacts X} (hf : Summable fun i : ι => ‖f.restrict (s i)‖ * ENNReal.toReal (μ <| s i)) : IntegrableOn f (⋃ i : ι, s i) μ := by refine integrableOn_iUnion_of_summable_integral_norm (fun i => (s i).isCompact.isClosed.measurableSet) (fun i => (map_continuous f).continuousOn.integrableOn_compact (s i).isCompact) (.of_nonneg_of_le (fun ι => integral_nonneg fun x => norm_nonneg _) (fun i => ?_) hf) rw [← (Real.norm_of_nonneg (integral_nonneg fun x => norm_nonneg _) : ‖_‖ = ∫ x in s i, ‖f x‖ ∂μ)] exact norm_setIntegral_le_of_norm_le_const' (s i).isCompact.measure_lt_top (s i).isCompact.isClosed.measurableSet fun x hx => (norm_norm (f x)).symm ▸ (f.restrict (s i : Set X)).norm_coe_le_norm ⟨x, hx⟩ #align measure_theory.integrable_on_Union_of_summable_norm_restrict MeasureTheory.integrableOn_iUnion_of_summable_norm_restrict /-- If `s` is a countable family of compact sets covering `X`, `f` is a continuous function, and the sequence `‖f.restrict (s i)‖ * μ (s i)` is summable, then `f` is integrable. -/ theorem integrable_of_summable_norm_restrict {f : C(X, E)} {s : ι → Compacts X} (hf : Summable fun i : ι => ‖f.restrict (s i)‖ * ENNReal.toReal (μ <| s i)) (hs : ⋃ i : ι, ↑(s i) = (univ : Set X)) : Integrable f μ := by simpa only [hs, integrableOn_univ] using integrableOn_iUnion_of_summable_norm_restrict hf #align measure_theory.integrable_of_summable_norm_restrict MeasureTheory.integrable_of_summable_norm_restrict end IntegrableUnion /-! ### Continuity of the set integral We prove that for any set `s`, the function `fun f : X →₁[μ] E => ∫ x in s, f x ∂μ` is continuous. -/ section ContinuousSetIntegral variable [NormedAddCommGroup E] {𝕜 : Type*} [NormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] {p : ℝ≥0∞} {μ : Measure X} /-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by `(Lp.memℒp f).restrict s).toLp f`. This map is additive. -/ theorem Lp_toLp_restrict_add (f g : Lp E p μ) (s : Set X) : ((Lp.memℒp (f + g)).restrict s).toLp (⇑(f + g)) = ((Lp.memℒp f).restrict s).toLp f + ((Lp.memℒp g).restrict s).toLp g := by ext1 refine (ae_restrict_of_ae (Lp.coeFn_add f g)).mp ?_ refine (Lp.coeFn_add (Memℒp.toLp f ((Lp.memℒp f).restrict s)) (Memℒp.toLp g ((Lp.memℒp g).restrict s))).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp f).restrict s)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp g).restrict s)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp (f + g)).restrict s)).mono fun x hx1 hx2 hx3 hx4 hx5 => ?_ rw [hx4, hx1, Pi.add_apply, hx2, hx3, hx5, Pi.add_apply] set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_add MeasureTheory.Lp_toLp_restrict_add /-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by `(Lp.memℒp f).restrict s).toLp f`. This map commutes with scalar multiplication. -/ theorem Lp_toLp_restrict_smul (c : 𝕜) (f : Lp F p μ) (s : Set X) : ((Lp.memℒp (c • f)).restrict s).toLp (⇑(c • f)) = c • ((Lp.memℒp f).restrict s).toLp f := by ext1 refine (ae_restrict_of_ae (Lp.coeFn_smul c f)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp f).restrict s)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp (c • f)).restrict s)).mp ?_ refine (Lp.coeFn_smul c (Memℒp.toLp f ((Lp.memℒp f).restrict s))).mono fun x hx1 hx2 hx3 hx4 => ?_ simp only [hx2, hx1, hx3, hx4, Pi.smul_apply] set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_smul MeasureTheory.Lp_toLp_restrict_smul /-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by `(Lp.memℒp f).restrict s).toLp f`. This map is non-expansive. -/ theorem norm_Lp_toLp_restrict_le (s : Set X) (f : Lp E p μ) : ‖((Lp.memℒp f).restrict s).toLp f‖ ≤ ‖f‖ := by rw [Lp.norm_def, Lp.norm_def, ENNReal.toReal_le_toReal (Lp.snorm_ne_top _) (Lp.snorm_ne_top _)] apply (le_of_eq _).trans (snorm_mono_measure _ (Measure.restrict_le_self (s := s))) exact snorm_congr_ae (Memℒp.coeFn_toLp _) set_option linter.uppercaseLean3 false in #align measure_theory.norm_Lp_to_Lp_restrict_le MeasureTheory.norm_Lp_toLp_restrict_le variable (X F 𝕜) in /-- Continuous linear map sending a function of `Lp F p μ` to the same function in `Lp F p (μ.restrict s)`. -/ def LpToLpRestrictCLM (μ : Measure X) (p : ℝ≥0∞) [hp : Fact (1 ≤ p)] (s : Set X) : Lp F p μ →L[𝕜] Lp F p (μ.restrict s) := @LinearMap.mkContinuous 𝕜 𝕜 (Lp F p μ) (Lp F p (μ.restrict s)) _ _ _ _ _ _ (RingHom.id 𝕜) ⟨⟨fun f => Memℒp.toLp f ((Lp.memℒp f).restrict s), fun f g => Lp_toLp_restrict_add f g s⟩, fun c f => Lp_toLp_restrict_smul c f s⟩ 1 (by intro f; rw [one_mul]; exact norm_Lp_toLp_restrict_le s f) set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_clm MeasureTheory.LpToLpRestrictCLM variable (𝕜) in theorem LpToLpRestrictCLM_coeFn [Fact (1 ≤ p)] (s : Set X) (f : Lp F p μ) : LpToLpRestrictCLM X F 𝕜 μ p s f =ᵐ[μ.restrict s] f := Memℒp.coeFn_toLp ((Lp.memℒp f).restrict s) set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_clm_coe_fn MeasureTheory.LpToLpRestrictCLM_coeFn @[continuity] theorem continuous_setIntegral [NormedSpace ℝ E] (s : Set X) : Continuous fun f : X →₁[μ] E => ∫ x in s, f x ∂μ := by haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩ have h_comp : (fun f : X →₁[μ] E => ∫ x in s, f x ∂μ) = integral (μ.restrict s) ∘ fun f => LpToLpRestrictCLM X E ℝ μ 1 s f := by ext1 f rw [Function.comp_apply, integral_congr_ae (LpToLpRestrictCLM_coeFn ℝ s f)] rw [h_comp] exact continuous_integral.comp (LpToLpRestrictCLM X E ℝ μ 1 s).continuous #align measure_theory.continuous_set_integral MeasureTheory.continuous_setIntegral @[deprecated (since := "2024-04-17")] alias continuous_set_integral := continuous_setIntegral end ContinuousSetIntegral end MeasureTheory section OpenPos open Measure variable [TopologicalSpace X] [OpensMeasurableSpace X] {μ : Measure X} [IsOpenPosMeasure μ] theorem Continuous.integral_pos_of_hasCompactSupport_nonneg_nonzero [IsFiniteMeasureOnCompacts μ] {f : X → ℝ} {x : X} (f_cont : Continuous f) (f_comp : HasCompactSupport f) (f_nonneg : 0 ≤ f) (f_x : f x ≠ 0) : 0 < ∫ x, f x ∂μ := integral_pos_of_integrable_nonneg_nonzero f_cont (f_cont.integrable_of_hasCompactSupport f_comp) f_nonneg f_x end OpenPos /-! Fundamental theorem of calculus for set integrals -/ section FTC open MeasureTheory Asymptotics Metric variable {ι : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] /-- Fundamental theorem of calculus for set integrals: if `μ` is a measure that is finite at a filter `l` and `f` is a measurable function that has a finite limit `b` at `l ⊓ ae μ`, then `∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that `s i` tends to `l.smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae {μ : Measure X} {l : Filter X} [l.IsMeasurablyGenerated] {f : X → E} {b : E} (h : Tendsto f (l ⊓ ae μ) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ) (hμ : μ.FiniteAtFilter l) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li l.smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by suffices (fun s => (∫ x in s, f x ∂μ) - (μ s).toReal • b) =o[l.smallSets] fun s => (μ s).toReal from (this.comp_tendsto hs).congr' (hsμ.mono fun a ha => by dsimp only [Function.comp_apply] at ha ⊢; rw [ha]) hsμ refine isLittleO_iff.2 fun ε ε₀ => ?_ have : ∀ᶠ s in l.smallSets, ∀ᵐ x ∂μ, x ∈ s → f x ∈ closedBall b ε := eventually_smallSets_eventually.2 (h.eventually <| closedBall_mem_nhds _ ε₀) filter_upwards [hμ.eventually, (hμ.integrableAtFilter_of_tendsto_ae hfm h).eventually, hfm.eventually, this] simp only [mem_closedBall, dist_eq_norm] intro s hμs h_integrable hfm h_norm rw [← setIntegral_const, ← integral_sub h_integrable (integrableOn_const.2 <| Or.inr hμs), Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg] exact norm_setIntegral_le_of_norm_le_const_ae' hμs h_norm (hfm.sub aestronglyMeasurable_const) #align filter.tendsto.integral_sub_linear_is_o_ae Filter.Tendsto.integral_sub_linear_isLittleO_ae /-- Fundamental theorem of calculus for set integrals, `nhdsWithin` version: if `μ` is a locally finite measure and `f` is an almost everywhere measurable function that is continuous at a point `a` within a measurable set `t`, then `∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at a filter `li` provided that `s i` tends to `(𝓝[t] a).smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem ContinuousWithinAt.integral_sub_linear_isLittleO_ae [TopologicalSpace X] [OpensMeasurableSpace X] {μ : Measure X} [IsLocallyFiniteMeasure μ] {x : X} {t : Set X} {f : X → E} (hx : ContinuousWithinAt f t x) (ht : MeasurableSet t) (hfm : StronglyMeasurableAtFilter f (𝓝[t] x) μ) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li (𝓝[t] x).smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • f x) =o[li] m := haveI : (𝓝[t] x).IsMeasurablyGenerated := ht.nhdsWithin_isMeasurablyGenerated _ (hx.mono_left inf_le_left).integral_sub_linear_isLittleO_ae hfm (μ.finiteAt_nhdsWithin x t) hs m hsμ #align continuous_within_at.integral_sub_linear_is_o_ae ContinuousWithinAt.integral_sub_linear_isLittleO_ae /-- Fundamental theorem of calculus for set integrals, `nhds` version: if `μ` is a locally finite measure and `f` is an almost everywhere measurable function that is continuous at a point `a`, then `∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at `li` provided that `s` tends to `(𝓝 a).smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem ContinuousAt.integral_sub_linear_isLittleO_ae [TopologicalSpace X] [OpensMeasurableSpace X] {μ : Measure X} [IsLocallyFiniteMeasure μ] {x : X} {f : X → E} (hx : ContinuousAt f x) (hfm : StronglyMeasurableAtFilter f (𝓝 x) μ) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li (𝓝 x).smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • f x) =o[li] m := (hx.mono_left inf_le_left).integral_sub_linear_isLittleO_ae hfm (μ.finiteAt_nhds x) hs m hsμ #align continuous_at.integral_sub_linear_is_o_ae ContinuousAt.integral_sub_linear_isLittleO_ae /-- Fundamental theorem of calculus for set integrals, `nhdsWithin` version: if `μ` is a locally finite measure, `f` is continuous on a measurable set `t`, and `a ∈ t`, then `∫ x in (s i), f x ∂μ = μ (s i) • f a + o(μ (s i))` at `li` provided that `s i` tends to `(𝓝[t] a).smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem ContinuousOn.integral_sub_linear_isLittleO_ae [TopologicalSpace X] [OpensMeasurableSpace X] [SecondCountableTopologyEither X E] {μ : Measure X} [IsLocallyFiniteMeasure μ] {x : X} {t : Set X} {f : X → E} (hft : ContinuousOn f t) (hx : x ∈ t) (ht : MeasurableSet t) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li (𝓝[t] x).smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • f x) =o[li] m := (hft x hx).integral_sub_linear_isLittleO_ae ht ⟨t, self_mem_nhdsWithin, hft.aestronglyMeasurable ht⟩ hs m hsμ #align continuous_on.integral_sub_linear_is_o_ae ContinuousOn.integral_sub_linear_isLittleO_ae end FTC section /-! ### Continuous linear maps composed with integration The goal of this section is to prove that integration commutes with continuous linear maps. This holds for simple functions. The general result follows from the continuity of all involved operations on the space `L¹`. Note that composition by a continuous linear map on `L¹` is not just the composition, as we are dealing with classes of functions, but it has already been defined as `ContinuousLinearMap.compLp`. We take advantage of this construction here. -/ open scoped ComplexConjugate variable {μ : Measure X} {𝕜 : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] {p : ENNReal} namespace ContinuousLinearMap variable [NormedSpace ℝ F] theorem integral_compLp (L : E →L[𝕜] F) (φ : Lp E p μ) : ∫ x, (L.compLp φ) x ∂μ = ∫ x, L (φ x) ∂μ := integral_congr_ae <| coeFn_compLp _ _ set_option linter.uppercaseLean3 false in #align continuous_linear_map.integral_comp_Lp ContinuousLinearMap.integral_compLp theorem setIntegral_compLp (L : E →L[𝕜] F) (φ : Lp E p μ) {s : Set X} (hs : MeasurableSet s) : ∫ x in s, (L.compLp φ) x ∂μ = ∫ x in s, L (φ x) ∂μ := setIntegral_congr_ae hs ((L.coeFn_compLp φ).mono fun _x hx _ => hx) set_option linter.uppercaseLean3 false in #align continuous_linear_map.set_integral_comp_Lp ContinuousLinearMap.setIntegral_compLp @[deprecated (since := "2024-04-17")] alias set_integral_compLp := setIntegral_compLp
Mathlib/MeasureTheory/Integral/SetIntegral.lean
1,287
1,289
theorem continuous_integral_comp_L1 (L : E →L[𝕜] F) : Continuous fun φ : X →₁[μ] E => ∫ x : X, L (φ x) ∂μ := by
rw [← funext L.integral_compLp]; exact continuous_integral.comp (L.compLpL 1 μ).continuous
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Bryan Gin-ge Chen -/ import Mathlib.Logic.Relation import Mathlib.Order.GaloisConnection #align_import data.setoid.basic from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821" /-! # Equivalence relations This file defines the complete lattice of equivalence relations on a type, results about the inductively defined equivalence closure of a binary relation, and the analogues of some isomorphism theorems for quotients of arbitrary types. ## Implementation notes The function `Rel` and lemmas ending in ' make it easier to talk about different equivalence relations on the same type. The complete lattice instance for equivalence relations could have been defined by lifting the Galois insertion of equivalence relations on α into binary relations on α, and then using `CompleteLattice.copy` to define a complete lattice instance with more appropriate definitional equalities (a similar example is `Filter.CompleteLattice` in `Order/Filter/Basic.lean`). This does not save space, however, and is less clear. Partitions are not defined as a separate structure here; users are encouraged to reason about them using the existing `Setoid` and its infrastructure. ## Tags setoid, equivalence, iseqv, relation, equivalence relation -/ variable {α : Type*} {β : Type*} /-- A version of `Setoid.r` that takes the equivalence relation as an explicit argument. -/ def Setoid.Rel (r : Setoid α) : α → α → Prop := @Setoid.r _ r #align setoid.rel Setoid.Rel instance Setoid.decidableRel (r : Setoid α) [h : DecidableRel r.r] : DecidableRel r.Rel := h #align setoid.decidable_rel Setoid.decidableRel /-- A version of `Quotient.eq'` compatible with `Setoid.Rel`, to make rewriting possible. -/ theorem Quotient.eq_rel {r : Setoid α} {x y} : (Quotient.mk' x : Quotient r) = Quotient.mk' y ↔ r.Rel x y := Quotient.eq #align quotient.eq_rel Quotient.eq_rel namespace Setoid @[ext] theorem ext' {r s : Setoid α} (H : ∀ a b, r.Rel a b ↔ s.Rel a b) : r = s := ext H #align setoid.ext' Setoid.ext' theorem ext_iff {r s : Setoid α} : r = s ↔ ∀ a b, r.Rel a b ↔ s.Rel a b := ⟨fun h _ _ => h ▸ Iff.rfl, ext'⟩ #align setoid.ext_iff Setoid.ext_iff /-- Two equivalence relations are equal iff their underlying binary operations are equal. -/ theorem eq_iff_rel_eq {r₁ r₂ : Setoid α} : r₁ = r₂ ↔ r₁.Rel = r₂.Rel := ⟨fun h => h ▸ rfl, fun h => Setoid.ext' fun _ _ => h ▸ Iff.rfl⟩ #align setoid.eq_iff_rel_eq Setoid.eq_iff_rel_eq /-- Defining `≤` for equivalence relations. -/ instance : LE (Setoid α) := ⟨fun r s => ∀ ⦃x y⦄, r.Rel x y → s.Rel x y⟩ theorem le_def {r s : Setoid α} : r ≤ s ↔ ∀ {x y}, r.Rel x y → s.Rel x y := Iff.rfl #align setoid.le_def Setoid.le_def @[refl] theorem refl' (r : Setoid α) (x) : r.Rel x x := r.iseqv.refl x #align setoid.refl' Setoid.refl' @[symm] theorem symm' (r : Setoid α) : ∀ {x y}, r.Rel x y → r.Rel y x := r.iseqv.symm #align setoid.symm' Setoid.symm' @[trans] theorem trans' (r : Setoid α) : ∀ {x y z}, r.Rel x y → r.Rel y z → r.Rel x z := r.iseqv.trans #align setoid.trans' Setoid.trans' theorem comm' (s : Setoid α) {x y} : s.Rel x y ↔ s.Rel y x := ⟨s.symm', s.symm'⟩ #align setoid.comm' Setoid.comm' /-- The kernel of a function is an equivalence relation. -/ def ker (f : α → β) : Setoid α := ⟨(· = ·) on f, eq_equivalence.comap f⟩ #align setoid.ker Setoid.ker /-- The kernel of the quotient map induced by an equivalence relation r equals r. -/ @[simp] theorem ker_mk_eq (r : Setoid α) : ker (@Quotient.mk'' _ r) = r := ext' fun _ _ => Quotient.eq #align setoid.ker_mk_eq Setoid.ker_mk_eq theorem ker_apply_mk_out {f : α → β} (a : α) : f (haveI := Setoid.ker f; ⟦a⟧.out) = f a := @Quotient.mk_out _ (Setoid.ker f) a #align setoid.ker_apply_mk_out Setoid.ker_apply_mk_out theorem ker_apply_mk_out' {f : α → β} (a : α) : f (Quotient.mk _ a : Quotient <| Setoid.ker f).out' = f a := @Quotient.mk_out' _ (Setoid.ker f) a #align setoid.ker_apply_mk_out' Setoid.ker_apply_mk_out' theorem ker_def {f : α → β} {x y : α} : (ker f).Rel x y ↔ f x = f y := Iff.rfl #align setoid.ker_def Setoid.ker_def /-- Given types `α`, `β`, the product of two equivalence relations `r` on `α` and `s` on `β`: `(x₁, x₂), (y₁, y₂) ∈ α × β` are related by `r.prod s` iff `x₁` is related to `y₁` by `r` and `x₂` is related to `y₂` by `s`. -/ protected def prod (r : Setoid α) (s : Setoid β) : Setoid (α × β) where r x y := r.Rel x.1 y.1 ∧ s.Rel x.2 y.2 iseqv := ⟨fun x => ⟨r.refl' x.1, s.refl' x.2⟩, fun h => ⟨r.symm' h.1, s.symm' h.2⟩, fun h₁ h₂ => ⟨r.trans' h₁.1 h₂.1, s.trans' h₁.2 h₂.2⟩⟩ #align setoid.prod Setoid.prod /-- The infimum of two equivalence relations. -/ instance : Inf (Setoid α) := ⟨fun r s => ⟨fun x y => r.Rel x y ∧ s.Rel x y, ⟨fun x => ⟨r.refl' x, s.refl' x⟩, fun h => ⟨r.symm' h.1, s.symm' h.2⟩, fun h1 h2 => ⟨r.trans' h1.1 h2.1, s.trans' h1.2 h2.2⟩⟩⟩⟩ /-- The infimum of 2 equivalence relations r and s is the same relation as the infimum of the underlying binary operations. -/ theorem inf_def {r s : Setoid α} : (r ⊓ s).Rel = r.Rel ⊓ s.Rel := rfl #align setoid.inf_def Setoid.inf_def theorem inf_iff_and {r s : Setoid α} {x y} : (r ⊓ s).Rel x y ↔ r.Rel x y ∧ s.Rel x y := Iff.rfl #align setoid.inf_iff_and Setoid.inf_iff_and /-- The infimum of a set of equivalence relations. -/ instance : InfSet (Setoid α) := ⟨fun S => { r := fun x y => ∀ r ∈ S, r.Rel x y iseqv := ⟨fun x r _ => r.refl' x, fun h r hr => r.symm' <| h r hr, fun h1 h2 r hr => r.trans' (h1 r hr) <| h2 r hr⟩ }⟩ /-- The underlying binary operation of the infimum of a set of equivalence relations is the infimum of the set's image under the map to the underlying binary operation. -/
Mathlib/Data/Setoid/Basic.lean
155
158
theorem sInf_def {s : Set (Setoid α)} : (sInf s).Rel = sInf (Rel '' s) := by
ext simp only [sInf_image, iInf_apply, iInf_Prop_eq] rfl
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Algebra.CharP.Basic import Mathlib.Data.Fintype.Units import Mathlib.GroupTheory.OrderOfElement #align_import number_theory.legendre_symbol.mul_character from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Multiplicative characters of finite rings and fields Let `R` and `R'` be a commutative rings. A *multiplicative character* of `R` with values in `R'` is a morphism of monoids from the multiplicative monoid of `R` into that of `R'` that sends non-units to zero. We use the namespace `MulChar` for the definitions and results. ## Main results We show that the multiplicative characters form a group (if `R'` is commutative); see `MulChar.commGroup`. We also provide an equivalence with the homomorphisms `Rˣ →* R'ˣ`; see `MulChar.equivToUnitHom`. We define a multiplicative character to be *quadratic* if its values are among `0`, `1` and `-1`, and we prove some properties of quadratic characters. Finally, we show that the sum of all values of a nontrivial multiplicative character vanishes; see `MulChar.IsNontrivial.sum_eq_zero`. ## Tags multiplicative character -/ /-! ### Definitions related to multiplicative characters Even though the intended use is when domain and target of the characters are commutative rings, we define them in the more general setting when the domain is a commutative monoid and the target is a commutative monoid with zero. (We need a zero in the target, since non-units are supposed to map to zero.) In this setting, there is an equivalence between multiplicative characters `R → R'` and group homomorphisms `Rˣ → R'ˣ`, and the multiplicative characters have a natural structure as a commutative group. -/ section Defi -- The domain of our multiplicative characters variable (R : Type*) [CommMonoid R] -- The target variable (R' : Type*) [CommMonoidWithZero R'] /-- Define a structure for multiplicative characters. A multiplicative character from a commutative monoid `R` to a commutative monoid with zero `R'` is a homomorphism of (multiplicative) monoids that sends non-units to zero. -/ structure MulChar extends MonoidHom R R' where map_nonunit' : ∀ a : R, ¬IsUnit a → toFun a = 0 #align mul_char MulChar instance MulChar.instFunLike : FunLike (MulChar R R') R R' := ⟨fun χ => χ.toFun, fun χ₀ χ₁ h => by cases χ₀; cases χ₁; congr; apply MonoidHom.ext (fun _ => congr_fun h _)⟩ /-- This is the corresponding extension of `MonoidHomClass`. -/ class MulCharClass (F : Type*) (R R' : outParam Type*) [CommMonoid R] [CommMonoidWithZero R'] [FunLike F R R'] extends MonoidHomClass F R R' : Prop where map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0 #align mul_char_class MulCharClass initialize_simps_projections MulChar (toFun → apply, -toMonoidHom) attribute [simp] MulCharClass.map_nonunit end Defi namespace MulChar section Group -- The domain of our multiplicative characters variable {R : Type*} [CommMonoid R] -- The target variable {R' : Type*} [CommMonoidWithZero R'] variable (R R') in /-- The trivial multiplicative character. It takes the value `0` on non-units and the value `1` on units. -/ @[simps] noncomputable def trivial : MulChar R R' where toFun := by classical exact fun x => if IsUnit x then 1 else 0 map_nonunit' := by intro a ha simp only [ha, if_false] map_one' := by simp only [isUnit_one, if_true] map_mul' := by intro x y classical simp only [IsUnit.mul_iff, boole_mul] split_ifs <;> tauto #align mul_char.trivial MulChar.trivial @[simp] theorem coe_mk (f : R →* R') (hf) : (MulChar.mk f hf : R → R') = f := rfl #align mul_char.coe_mk MulChar.coe_mk /-- Extensionality. See `ext` below for the version that will actually be used. -/
Mathlib/NumberTheory/MulChar/Basic.lean
119
123
theorem ext' {χ χ' : MulChar R R'} (h : ∀ a, χ a = χ' a) : χ = χ' := by
cases χ cases χ' congr exact MonoidHom.ext h
/- 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.Data.ENat.Lattice import Mathlib.Order.OrderIsoNat import Mathlib.Tactic.TFAE #align_import order.height from "leanprover-community/mathlib"@"bf27744463e9620ca4e4ebe951fe83530ae6949b" /-! # Maximal length of chains This file contains lemmas to work with the maximal length of strictly descending finite sequences (chains) in a partial order. ## Main definition - `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`. - `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order. This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`. ## Main results - `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there exists `s.subchain` of length `n`. - `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`. - `Set.chainHeight_image`: If `f` is an order embedding, then `(f '' s).chainHeight = s.chainHeight`. - `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then `(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`. - `Set.wellFoundedGT_of_chainHeight_ne_top`: If `s` has finite height, then `>` is well-founded on `s`. - `Set.wellFoundedLT_of_chainHeight_ne_top`: If `s` has finite height, then `<` is well-founded on `s`. -/ open List hiding le_antisymm open OrderDual universe u v variable {α β : Type*} namespace Set section LT variable [LT α] [LT β] (s t : Set α) /-- The set of strictly ascending lists of `α` contained in a `Set α`. -/ def subchain : Set (List α) := { l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s } #align set.subchain Set.subchain @[simp] -- porting note: new `simp` theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩ #align set.nil_mem_subchain Set.nil_mem_subchain variable {s} {l : List α} {a : α} theorem cons_mem_subchain_iff : (a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm, and_assoc] #align set.cons_mem_subchain_iff Set.cons_mem_subchain_iff @[simp] -- Porting note (#10756): new lemma + `simp` theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff] instance : Nonempty s.subchain := ⟨⟨[], s.nil_mem_subchain⟩⟩ variable (s) /-- The maximal length of a strictly ascending sequence in a partial order. -/ noncomputable def chainHeight : ℕ∞ := ⨆ l ∈ s.subchain, length l #align set.chain_height Set.chainHeight theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length := iSup_subtype' #align set.chain_height_eq_supr_subtype Set.chainHeight_eq_iSup_subtype theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) : ∃ l ∈ s.subchain, length l = n := by rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;> rw [chainHeight_eq_iSup_subtype] at ha · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ := not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take n).trans <| min_eq_left <| le_of_not_ge h₃⟩ · rw [ENat.iSup_coe_lt_top] at ha obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha refine ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take n).trans <| min_eq_left <| ?_⟩ rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype] #align set.exists_chain_of_le_chain_height Set.exists_chain_of_le_chainHeight theorem le_chainHeight_TFAE (n : ℕ) : TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩ tfae_have 3 → 1; · rintro ⟨l, hs, hn⟩; exact le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn) tfae_finish #align set.le_chain_height_tfae Set.le_chainHeight_TFAE variable {s t} theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n := (le_chainHeight_TFAE s n).out 0 1 #align set.le_chain_height_iff Set.le_chainHeight_iff theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight := le_chainHeight_iff.mpr ⟨l, hl, rfl⟩ #align set.length_le_chain_height_of_mem_subchain Set.length_le_chainHeight_of_mem_subchain theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩ contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <| (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩ #align set.chain_height_eq_top_iff Set.chainHeight_eq_top_iff @[simp] theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by rw [← Nat.cast_one, Set.le_chainHeight_iff] simp only [length_eq_one, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and, singleton_mem_subchain_iff, Set.Nonempty] #align set.one_le_chain_height_iff Set.one_le_chainHeight_iff @[simp] theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff, nonempty_iff_ne_empty] #align set.chain_height_eq_zero_iff Set.chainHeight_eq_zero_iff @[simp] theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 := chainHeight_eq_zero_iff.2 rfl #align set.chain_height_empty Set.chainHeight_empty @[simp] theorem chainHeight_of_isEmpty [IsEmpty α] : s.chainHeight = 0 := chainHeight_eq_zero_iff.mpr (Subsingleton.elim _ _) #align set.chain_height_of_is_empty Set.chainHeight_of_isEmpty theorem le_chainHeight_add_nat_iff {n m : ℕ} : ↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2] #align set.le_chain_height_add_nat_iff Set.le_chainHeight_add_nat_iff theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) : s.chainHeight + n ≤ t.chainHeight + m ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by refine ⟨fun e l h ↦ le_chainHeight_add_nat_iff.1 ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e), fun H ↦ ?_⟩ by_cases h : s.chainHeight = ⊤ · suffices t.chainHeight = ⊤ by rw [this, top_add] exact le_top rw [chainHeight_eq_top_iff] at h ⊢ intro k have := (le_chainHeight_TFAE t k).out 1 2 rw [this] obtain ⟨l, hs, hl⟩ := h (k + m) obtain ⟨l', ht, hl'⟩ := H l hs exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩ · obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le rw [← hk, ← hl] exact le_chainHeight_add_nat_iff.2 (H l hs) #align set.chain_height_add_le_chain_height_add Set.chainHeight_add_le_chainHeight_add theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) : TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l', ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by tfae_have 1 ↔ 3 · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero tfae_have 2 ↔ 3 · refine forall₂_congr fun l hl ↦ ?_ simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm] tfae_finish #align set.chain_height_le_chain_height_tfae Set.chainHeight_le_chainHeight_TFAE theorem chainHeight_le_chainHeight_iff {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 1 #align set.chain_height_le_chain_height_iff Set.chainHeight_le_chainHeight_iff theorem chainHeight_le_chainHeight_iff_le {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 2 #align set.chain_height_le_chain_height_iff_le Set.chainHeight_le_chainHeight_iff_le theorem chainHeight_mono (h : s ⊆ t) : s.chainHeight ≤ t.chainHeight := chainHeight_le_chainHeight_iff.2 fun l hl ↦ ⟨l, ⟨hl.1, fun i hi ↦ h <| hl.2 i hi⟩, rfl⟩ #align set.chain_height_mono Set.chainHeight_mono
Mathlib/Order/Height.lean
212
237
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) : (f '' s).chainHeight = s.chainHeight := by
apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff] · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by intro l hl obtain ⟨l', h₁, rfl⟩ := this l hl exact ⟨l', h₁, length_map _ _⟩ intro l induction' l with x xs hx · exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩ · intro h rw [cons_mem_subchain_iff] at h obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h obtain ⟨l', h₃, rfl⟩ := hx h₁ refine ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, ?_⟩, rfl⟩ cases l' · simp · simpa [← hf] using h₂ · intro l hl refine ⟨l.map f, ⟨?_, ?_⟩, ?_⟩ · simp_rw [chain'_map, ← hf] exact hl.1 · intro _ e obtain ⟨a, ha, rfl⟩ := mem_map.mp e exact Set.mem_image_of_mem _ (hl.2 _ ha) · rw [length_map]
/- 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.OfFunction import Mathlib.MeasureTheory.PiSystem /-! # The Caratheodory σ-algebra of an outer measure Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space. ## Main definitions and statements * `caratheodory` is the Carathéodory-measurable space of an outer measure. ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags Carathéodory-measurable, Carathéodory's criterion -/ #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 namespace OuterMeasure section CaratheodoryMeasurable universe u variable {α : Type u} (m : OuterMeasure α) attribute [local simp] Set.inter_comm Set.inter_left_comm Set.inter_assoc variable {s s₁ s₂ : Set α} /-- A set `s` is Carathéodory-measurable for an outer measure `m` if for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. -/ def IsCaratheodory (s : Set α) : Prop := ∀ t, m t = m (t ∩ s) + m (t \ s) #align measure_theory.outer_measure.is_caratheodory MeasureTheory.OuterMeasure.IsCaratheodory theorem isCaratheodory_iff_le' {s : Set α} : IsCaratheodory m s ↔ ∀ t, m (t ∩ s) + m (t \ s) ≤ m t := forall_congr' fun _ => le_antisymm_iff.trans <| and_iff_right <| measure_le_inter_add_diff _ _ _ #align measure_theory.outer_measure.is_caratheodory_iff_le' MeasureTheory.OuterMeasure.isCaratheodory_iff_le' @[simp] theorem isCaratheodory_empty : IsCaratheodory m ∅ := by simp [IsCaratheodory, m.empty, diff_empty] #align measure_theory.outer_measure.is_caratheodory_empty MeasureTheory.OuterMeasure.isCaratheodory_empty theorem isCaratheodory_compl : IsCaratheodory m s₁ → IsCaratheodory m s₁ᶜ := by simp [IsCaratheodory, diff_eq, add_comm] #align measure_theory.outer_measure.is_caratheodory_compl MeasureTheory.OuterMeasure.isCaratheodory_compl @[simp] theorem isCaratheodory_compl_iff : IsCaratheodory m sᶜ ↔ IsCaratheodory m s := ⟨fun h => by simpa using isCaratheodory_compl m h, isCaratheodory_compl m⟩ #align measure_theory.outer_measure.is_caratheodory_compl_iff MeasureTheory.OuterMeasure.isCaratheodory_compl_iff theorem isCaratheodory_union (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ ∪ s₂) := fun t => by rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)), inter_diff_assoc _ _ s₁, Set.inter_assoc _ _ s₁, inter_eq_self_of_subset_right Set.subset_union_left, union_diff_left, h₂ (t ∩ s₁)] simp [diff_eq, add_assoc] #align measure_theory.outer_measure.is_caratheodory_union MeasureTheory.OuterMeasure.isCaratheodory_union theorem measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : IsCaratheodory m s₁) {t : Set α} : m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) := by rw [h₁, Set.inter_assoc, Set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h] #align measure_theory.outer_measure.measure_inter_union MeasureTheory.OuterMeasure.measure_inter_union theorem isCaratheodory_iUnion_lt {s : ℕ → Set α} : ∀ {n : ℕ}, (∀ i < n, IsCaratheodory m (s i)) → IsCaratheodory m (⋃ i < n, s i) | 0, _ => by simp [Nat.not_lt_zero] | n + 1, h => by rw [biUnion_lt_succ] exact isCaratheodory_union m (isCaratheodory_iUnion_lt fun i hi => h i <| lt_of_lt_of_le hi <| Nat.le_succ _) (h n (le_refl (n + 1))) #align measure_theory.outer_measure.is_caratheodory_Union_lt MeasureTheory.OuterMeasure.isCaratheodory_iUnion_lt theorem isCaratheodory_inter (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ ∩ s₂) := by rw [← isCaratheodory_compl_iff, Set.compl_inter] exact isCaratheodory_union _ (isCaratheodory_compl _ h₁) (isCaratheodory_compl _ h₂) #align measure_theory.outer_measure.is_caratheodory_inter MeasureTheory.OuterMeasure.isCaratheodory_inter theorem isCaratheodory_sum {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) {t : Set α} : ∀ {n}, (∑ i ∈ Finset.range n, m (t ∩ s i)) = m (t ∩ ⋃ i < n, s i) | 0 => by simp [Nat.not_lt_zero, m.empty] | Nat.succ n => by rw [biUnion_lt_succ, Finset.sum_range_succ, Set.union_comm, isCaratheodory_sum h hd, m.measure_inter_union _ (h n), add_comm] intro a simpa using fun (h₁ : a ∈ s n) i (hi : i < n) h₂ => (hd (ne_of_gt hi)).le_bot ⟨h₁, h₂⟩ #align measure_theory.outer_measure.is_caratheodory_sum MeasureTheory.OuterMeasure.isCaratheodory_sum set_option linter.deprecated false in -- not immediately obvious how to replace `iUnion` here.
Mathlib/MeasureTheory/OuterMeasure/Caratheodory.lean
115
128
theorem isCaratheodory_iUnion_nat {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) : IsCaratheodory m (⋃ i, s i) := by
apply (isCaratheodory_iff_le' m).mpr intro t have hp : m (t ∩ ⋃ i, s i) ≤ ⨆ n, m (t ∩ ⋃ i < n, s i) := by convert m.iUnion fun i => t ∩ s i using 1 · simp [inter_iUnion] · simp [ENNReal.tsum_eq_iSup_nat, isCaratheodory_sum m h hd] refine le_trans (add_le_add_right hp _) ?_ rw [ENNReal.iSup_add] refine iSup_le fun n => le_trans (add_le_add_left ?_ _) (ge_of_eq (isCaratheodory_iUnion_lt m (fun i _ => h i) _)) refine m.mono (diff_subset_diff_right ?_) exact iUnion₂_subset fun i _ => subset_iUnion _ i
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.Logic.Equiv.Basic #align_import category_theory.limits.has_limits from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone #align category_theory.limits.limit_cone CategoryTheory.Limits.LimitCone #align category_theory.limits.limit_cone.is_limit CategoryTheory.Limits.LimitCone.isLimit /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) #align category_theory.limits.has_limit CategoryTheory.Limits.HasLimit theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_limit.mk CategoryTheory.Limits.HasLimit.mk /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit #align category_theory.limits.get_limit_cone CategoryTheory.Limits.getLimitCone variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance #align category_theory.limits.has_limits_of_shape CategoryTheory.Limits.HasLimitsOfShape /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance #align category_theory.limits.has_limits_of_size CategoryTheory.Limits.HasLimitsOfSize /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C #align category_theory.limits.has_limits CategoryTheory.Limits.HasLimits theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits.has_limits_of_shape CategoryTheory.Limits.HasLimits.has_limits_of_shape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F #align category_theory.limits.has_limit_of_has_limits_of_shape CategoryTheory.Limits.hasLimitOfHasLimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits_of_shape_of_has_limits CategoryTheory.Limits.hasLimitsOfShapeOfHasLimits -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone #align category_theory.limits.limit.cone CategoryTheory.Limits.limit.cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt #align category_theory.limits.limit CategoryTheory.Limits.limit /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j #align category_theory.limits.limit.π CategoryTheory.Limits.limit.π @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.limit.cone_X CategoryTheory.Limits.limit.cone_x @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl #align category_theory.limits.limit.cone_π CategoryTheory.Limits.limit.cone_π @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f #align category_theory.limits.limit.w CategoryTheory.Limits.limit.w /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit #align category_theory.limits.limit.is_limit CategoryTheory.Limits.limit.isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c #align category_theory.limits.limit.lift CategoryTheory.Limits.limit.lift @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl #align category_theory.limits.limit.is_limit_lift CategoryTheory.Limits.limit.isLimit_lift @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j #align category_theory.limits.limit.lift_π CategoryTheory.Limits.limit.lift_π /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α #align category_theory.limits.lim_map CategoryTheory.Limits.limMap @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j #align category_theory.limits.lim_map_π CategoryTheory.Limits.limMap_π /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c #align category_theory.limits.limit.cone_morphism CategoryTheory.Limits.limit.coneMorphism @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl #align category_theory.limits.limit.cone_morphism_hom CategoryTheory.Limits.limit.coneMorphism_hom theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp #align category_theory.limits.limit.cone_morphism_π CategoryTheory.Limits.limit.coneMorphism_π @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_hom_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_hom_comp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_inv_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_inv_comp theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ #align category_theory.limits.limit.exists_unique CategoryTheory.Limits.limit.existsUnique /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit #align category_theory.limits.limit.iso_limit_cone CategoryTheory.Limits.limit.isoLimitCone @[reassoc (attr := simp)] theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_hom_π CategoryTheory.Limits.limit.isoLimitCone_hom_π @[reassoc (attr := simp)] theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_inv_π CategoryTheory.Limits.limit.isoLimitCone_inv_π @[ext] theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.isLimit F).hom_ext w #align category_theory.limits.limit.hom_ext CategoryTheory.Limits.limit.hom_ext @[simp] theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) : limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by ext rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π] rfl #align category_theory.limits.limit.lift_map CategoryTheory.Limits.limit.lift_map @[simp] theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) := (limit.isLimit _).lift_self #align category_theory.limits.limit.lift_cone CategoryTheory.Limits.limit.lift_cone /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and cones with cone point `W`. -/ def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) := (limit.isLimit F).homIso W #align category_theory.limits.limit.hom_iso CategoryTheory.Limits.limit.homIso @[simp] theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) : (limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π := (limit.isLimit F).homIso_hom f #align category_theory.limits.limit.hom_iso_hom CategoryTheory.Limits.limit.homIso_hom /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and an explicit componentwise description of cones with cone point `W`. -/ def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.isLimit F).homIso' W #align category_theory.limits.limit.hom_iso' CategoryTheory.Limits.limit.homIso' theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by aesop_cat #align category_theory.limits.limit.lift_extend CategoryTheory.Limits.limit.lift_extend /-- If a functor `F` has a limit, so does any naturally isomorphic functor. -/ theorem hasLimitOfIso {F G : J ⥤ C} [HasLimit F] (α : F ≅ G) : HasLimit G := HasLimit.mk { cone := (Cones.postcompose α.hom).obj (limit.cone F) isLimit := (IsLimit.postcomposeHomEquiv _ _).symm (limit.isLimit F) } #align category_theory.limits.has_limit_of_iso CategoryTheory.Limits.hasLimitOfIso -- See the construction of limits from products and equalizers -- for an example usage. /-- If a functor `G` has the same collection of cones as a functor `F` which has a limit, then `G` also has a limit. -/ theorem HasLimit.ofConesIso {J K : Type u₁} [Category.{v₁} J] [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cones ≅ G.cones) [HasLimit F] : HasLimit G := HasLimit.mk ⟨_, IsLimit.ofNatIso (IsLimit.natIso (limit.isLimit F) ≪≫ h)⟩ #align category_theory.limits.has_limit.of_cones_iso CategoryTheory.Limits.HasLimit.ofConesIso /-- The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasLimit.isoOfNatIso {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) : limit F ≅ limit G := IsLimit.conePointsIsoOfNatIso (limit.isLimit F) (limit.isLimit G) w #align category_theory.limits.has_limit.iso_of_nat_iso CategoryTheory.Limits.HasLimit.isoOfNatIso @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_hom_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j := IsLimit.conePointsIsoOfNatIso_hom_comp _ _ _ _ #align category_theory.limits.has_limit.iso_of_nat_iso_hom_π CategoryTheory.Limits.HasLimit.isoOfNatIso_hom_π @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_inv_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j := IsLimit.conePointsIsoOfNatIso_inv_comp _ _ _ _ #align category_theory.limits.has_limit.iso_of_nat_iso_inv_π CategoryTheory.Limits.HasLimit.isoOfNatIso_inv_π @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_hom {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone F) (w : F ≅ G) : limit.lift F t ≫ (HasLimit.isoOfNatIso w).hom = limit.lift G ((Cones.postcompose w.hom).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_hom _ _ _ #align category_theory.limits.has_limit.lift_iso_of_nat_iso_hom CategoryTheory.Limits.HasLimit.lift_isoOfNatIso_hom @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_inv {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone G) (w : F ≅ G) : limit.lift G t ≫ (HasLimit.isoOfNatIso w).inv = limit.lift F ((Cones.postcompose w.inv).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_inv _ _ _ #align category_theory.limits.has_limit.lift_iso_of_nat_iso_inv CategoryTheory.Limits.HasLimit.lift_isoOfNatIso_inv /-- The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasLimit.isoOfEquivalence {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : limit F ≅ limit G := IsLimit.conePointsIsoOfEquivalence (limit.isLimit F) (limit.isLimit G) e w #align category_theory.limits.has_limit.iso_of_equivalence CategoryTheory.Limits.HasLimit.isoOfEquivalence @[simp] theorem HasLimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : (HasLimit.isoOfEquivalence e w).hom ≫ limit.π G k = limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp #align category_theory.limits.has_limit.iso_of_equivalence_hom_π CategoryTheory.Limits.HasLimit.isoOfEquivalence_hom_π @[simp] theorem HasLimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : (HasLimit.isoOfEquivalence e w).inv ≫ limit.π F j = limit.π G (e.functor.obj j) ≫ w.hom.app j := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp #align category_theory.limits.has_limit.iso_of_equivalence_inv_π CategoryTheory.Limits.HasLimit.isoOfEquivalence_inv_π section Pre variable (F) [HasLimit F] (E : K ⥤ J) [HasLimit (E ⋙ F)] /-- The canonical morphism from the limit of `F` to the limit of `E ⋙ F`. -/ def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) ((limit.cone F).whisker E) #align category_theory.limits.limit.pre CategoryTheory.Limits.limit.pre @[reassoc (attr := simp)] theorem limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw [IsLimit.fac] rfl #align category_theory.limits.limit.pre_π CategoryTheory.Limits.limit.pre_π @[simp] theorem limit.lift_pre (c : Cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp #align category_theory.limits.limit.lift_pre CategoryTheory.Limits.limit.lift_pre variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) [HasLimit (D ⋙ E ⋙ F)] @[simp] theorem limit.pre_pre [h : HasLimit (D ⋙ E ⋙ F)] : haveI : HasLimit ((D ⋙ E) ⋙ F) := h; limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by haveI : HasLimit ((D ⋙ E) ⋙ F) := h ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; rfl #align category_theory.limits.limit.pre_pre CategoryTheory.Limits.limit.pre_pre variable {E F} /-- - If we have particular limit cones available for `E ⋙ F` and for `F`, we obtain a formula for `limit.pre F E`. -/ theorem limit.pre_eq (s : LimitCone (E ⋙ F)) (t : LimitCone F) : limit.pre F E = (limit.isoLimitCone t).hom ≫ s.isLimit.lift (t.cone.whisker E) ≫ (limit.isoLimitCone s).inv := by aesop_cat #align category_theory.limits.limit.pre_eq CategoryTheory.Limits.limit.pre_eq end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F) [HasLimit F] (G : C ⥤ D) [HasLimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`. -/ def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) (G.mapCone (limit.cone F)) #align category_theory.limits.limit.post CategoryTheory.Limits.limit.post @[reassoc (attr := simp)] theorem limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw [IsLimit.fac] rfl #align category_theory.limits.limit.post_π CategoryTheory.Limits.limit.post_π @[simp] theorem limit.lift_post (c : Cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.mapCone c) := by ext rw [assoc, limit.post_π, ← G.map_comp, limit.lift_π, limit.lift_π] rfl #align category_theory.limits.limit.lift_post CategoryTheory.Limits.limit.lift_post @[simp] theorem limit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) [h : HasLimit ((F ⋙ G) ⋙ H)] : -- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) haveI : HasLimit (F ⋙ G ⋙ H) := h H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by haveI : HasLimit (F ⋙ G ⋙ H) := h ext; erw [assoc, limit.post_π, ← H.map_comp, limit.post_π, limit.post_π]; rfl #align category_theory.limits.limit.post_post CategoryTheory.Limits.limit.post_post end Post theorem limit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasLimit F] [HasLimit (E ⋙ F)] [HasLimit (F ⋙ G)] [h : HasLimit ((E ⋙ F) ⋙ G)] :-- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or haveI : HasLimit (E ⋙ F ⋙ G) := h G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by haveI : HasLimit (E ⋙ F ⋙ G) := h ext; erw [assoc, limit.post_π, ← G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π] #align category_theory.limits.limit.pre_post CategoryTheory.Limits.limit.pre_post open CategoryTheory.Equivalence instance hasLimitEquivalenceComp (e : K ≌ J) [HasLimit F] : HasLimit (e.functor ⋙ F) := HasLimit.mk { cone := Cone.whisker e.functor (limit.cone F) isLimit := IsLimit.whiskerEquivalence (limit.isLimit F) e } #align category_theory.limits.has_limit_equivalence_comp CategoryTheory.Limits.hasLimitEquivalenceComp -- Porting note: testing whether this still needed -- attribute [local elab_without_expected_type] inv_fun_id_assoc -- not entirely sure why this is needed /-- If a `E ⋙ F` has a limit, and `E` is an equivalence, we can construct a limit of `F`. -/ theorem hasLimitOfEquivalenceComp (e : K ≌ J) [HasLimit (e.functor ⋙ F)] : HasLimit F := by haveI : HasLimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasLimitEquivalenceComp e.symm apply hasLimitOfIso (e.invFunIdAssoc F) #align category_theory.limits.has_limit_of_equivalence_comp CategoryTheory.Limits.hasLimitOfEquivalenceComp -- `hasLimitCompEquivalence` and `hasLimitOfCompEquivalence` -- are proved in `CategoryTheory/Adjunction/Limits.lean`. section LimFunctor variable [HasLimitsOfShape J C] section /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ @[simps] def lim : (J ⥤ C) ⥤ C where obj F := limit F map α := limMap α map_id F := by apply Limits.limit.hom_ext; intro j erw [limMap_π, Category.id_comp, Category.comp_id] map_comp α β := by apply Limits.limit.hom_ext; intro j erw [assoc, IsLimit.fac, IsLimit.fac, ← assoc, IsLimit.fac, assoc]; rfl #align category_theory.limits.lim CategoryTheory.Limits.lim #align category_theory.limits.lim_map_eq_lim_map CategoryTheory.Limits.lim_map end variable {G : J ⥤ C} (α : F ⟶ G) theorem limit.map_pre [HasLimitsOfShape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whiskerLeft E α) := by ext simp #align category_theory.limits.limit.map_pre CategoryTheory.Limits.limit.map_pre theorem limit.map_pre' [HasLimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whiskerRight α F) := by ext1; simp [← category.assoc] #align category_theory.limits.limit.map_pre' CategoryTheory.Limits.limit.map_pre' theorem limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (Functor.leftUnitor F).inv := by aesop_cat #align category_theory.limits.limit.id_pre CategoryTheory.Limits.limit.id_pre theorem limit.map_post {D : Type u'} [Category.{v'} D] [HasLimitsOfShape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (limMap α) ≫ limit.post G H = limit.post F H ≫ limMap (whiskerRight α H) := by ext simp only [whiskerRight_app, limMap_π, assoc, limit.post_π_assoc, limit.post_π, ← H.map_comp] #align category_theory.limits.limit.map_post CategoryTheory.Limits.limit.map_post /-- The isomorphism between morphisms from `W` to the cone point of the limit cone for `F` and cones over `F` with cone point `W` is natural in `F`. -/ def limYoneda : lim ⋙ yoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => limit.homIso F (unop W) #align category_theory.limits.lim_yoneda CategoryTheory.Limits.limYoneda /-- The constant functor and limit functor are adjoint to each other-/ def constLimAdj : (const J : C ⥤ J ⥤ C) ⊣ lim where homEquiv c g := { toFun := fun f => limit.lift _ ⟨c, f⟩ invFun := fun f => { app := fun j => f ≫ limit.π _ _ } left_inv := by aesop_cat right_inv := by aesop_cat } unit := { app := fun c => limit.lift _ ⟨_, 𝟙 _⟩ } counit := { app := fun g => { app := limit.π _ } } -- This used to be automatic before leanprover/lean4#2644 homEquiv_unit := by -- Sad that aesop can no longer do this! intros dsimp ext simp #align category_theory.limits.const_lim_adj CategoryTheory.Limits.constLimAdj instance : IsRightAdjoint (lim : (J ⥤ C) ⥤ C) := ⟨_, ⟨constLimAdj⟩⟩ end LimFunctor instance limMap_mono' {F G : J ⥤ C} [HasLimitsOfShape J C] (α : F ⟶ G) [Mono α] : Mono (limMap α) := (lim : (J ⥤ C) ⥤ C).map_mono α #align category_theory.limits.lim_map_mono' CategoryTheory.Limits.limMap_mono' instance limMap_mono {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) [∀ j, Mono (α.app j)] : Mono (limMap α) := ⟨fun {Z} u v h => limit.hom_ext fun j => (cancel_mono (α.app j)).1 <| by simpa using h =≫ limit.π _ j⟩ #align category_theory.limits.lim_map_mono CategoryTheory.Limits.limMap_mono section Adjunction variable {L : (J ⥤ C) ⥤ C} (adj : Functor.const _ ⊣ L) /- The fact that the existence of limits of shape `J` is equivalent to the existence of a right adjoint to the constant functor `C ⥤ (J ⥤ C)` is obtained in the file `Mathlib.CategoryTheory.Limits.ConeCategory`: see the lemma `hasLimitsOfShape_iff_isLeftAdjoint_const`. In the definitions below, given an adjunction `adj : Functor.const _ ⊣ (L : (J ⥤ C) ⥤ C)`, we directly construct a limit cone for any `F : J ⥤ C`. -/ /-- The limit cone obtained from a right adjoint of the constant functor. -/ @[simps] noncomputable def coneOfAdj (F : J ⥤ C) : Cone F where pt := L.obj F π := adj.counit.app F /-- The cones defined by `coneOfAdj` are limit cones. -/ @[simps] def isLimitConeOfAdj (F : J ⥤ C) : IsLimit (coneOfAdj adj F) where lift s := adj.homEquiv _ _ s.π fac s j := by have eq := NatTrans.congr_app (adj.counit.naturality s.π) j have eq' := NatTrans.congr_app (adj.left_triangle_components s.pt) j dsimp at eq eq' ⊢ rw [Adjunction.homEquiv_unit, assoc, eq, reassoc_of% eq'] uniq s m hm := (adj.homEquiv _ _).symm.injective (by ext j; simpa using hm j) end Adjunction /-- We can transport limits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasLimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasLimitsOfShape J C] : HasLimitsOfShape J' C := by constructor intro F apply hasLimitOfEquivalenceComp e #align category_theory.limits.has_limits_of_shape_of_equivalence CategoryTheory.Limits.hasLimitsOfShape_of_equivalence variable (C) /-- A category that has larger limits also has smaller limits. -/ theorem hasLimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₂, u₂} C where has_limits_of_shape J {_} := hasLimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasLimitsOfSizeShrink.{v u} C` tries to obtain `HasLimitsOfSize.{v u} C` from some other `HasLimitsOfSize C`. -/ theorem hasLimitsOfSizeShrink [HasLimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasLimitsOfSize.{v₁, u₁} C := hasLimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C #align category_theory.limits.has_limits_of_size_shrink CategoryTheory.Limits.hasLimitsOfSizeShrink instance (priority := 100) hasSmallestLimitsOfHasLimits [HasLimits C] : HasLimitsOfSize.{0, 0} C := hasLimitsOfSizeShrink.{0, 0} C #align category_theory.limits.has_smallest_limits_of_has_limits CategoryTheory.Limits.hasSmallestLimitsOfHasLimits end Limit section Colimit /-- `ColimitCocone F` contains a cocone over `F` together with the information that it is a colimit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure ColimitCocone (F : J ⥤ C) where /-- The cocone itself -/ cocone : Cocone F /-- The proof that it is the colimit cocone -/ isColimit : IsColimit cocone #align category_theory.limits.colimit_cocone CategoryTheory.Limits.ColimitCocone #align category_theory.limits.colimit_cocone.is_colimit CategoryTheory.Limits.ColimitCocone.isColimit /-- `HasColimit F` represents the mere existence of a colimit for `F`. -/ class HasColimit (F : J ⥤ C) : Prop where mk' :: /-- There exists a colimit for `F` -/ exists_colimit : Nonempty (ColimitCocone F) #align category_theory.limits.has_colimit CategoryTheory.Limits.HasColimit theorem HasColimit.mk {F : J ⥤ C} (d : ColimitCocone F) : HasColimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_colimit.mk CategoryTheory.Limits.HasColimit.mk /-- Use the axiom of choice to extract explicit `ColimitCocone F` from `HasColimit F`. -/ def getColimitCocone (F : J ⥤ C) [HasColimit F] : ColimitCocone F := Classical.choice <| HasColimit.exists_colimit #align category_theory.limits.get_colimit_cocone CategoryTheory.Limits.getColimitCocone variable (J C) /-- `C` has colimits of shape `J` if there exists a colimit for every functor `F : J ⥤ C`. -/ class HasColimitsOfShape : Prop where /-- All `F : J ⥤ C` have colimits for a fixed `J` -/ has_colimit : ∀ F : J ⥤ C, HasColimit F := by infer_instance #align category_theory.limits.has_colimits_of_shape CategoryTheory.Limits.HasColimitsOfShape /-- `C` has all colimits of size `v₁ u₁` (`HasColimitsOfSize.{v₁ u₁} C`) if it has colimits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasColimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All `F : J ⥤ C` have colimits for all small `J` -/ has_colimits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasColimitsOfShape J C := by infer_instance #align category_theory.limits.has_colimits_of_size CategoryTheory.Limits.HasColimitsOfSize /-- `C` has all (small) colimits if it has colimits of every shape that is as big as its hom-sets. -/ abbrev HasColimits (C : Type u) [Category.{v} C] : Prop := HasColimitsOfSize.{v, v} C #align category_theory.limits.has_colimits CategoryTheory.Limits.HasColimits theorem HasColimits.hasColimitsOfShape {C : Type u} [Category.{v} C] [HasColimits C] (J : Type v) [Category.{v} J] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J #align category_theory.limits.has_colimits.has_colimits_of_shape CategoryTheory.Limits.HasColimits.hasColimitsOfShape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasColimitOfHasColimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasColimitsOfShape J C] (F : J ⥤ C) : HasColimit F := HasColimitsOfShape.has_colimit F #align category_theory.limits.has_colimit_of_has_colimits_of_shape CategoryTheory.Limits.hasColimitOfHasColimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasColimitsOfShapeOfHasColimitsOfSize {J : Type u₁} [Category.{v₁} J] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J #align category_theory.limits.has_colimits_of_shape_of_has_colimits_of_size CategoryTheory.Limits.hasColimitsOfShapeOfHasColimitsOfSize -- Interface to the `HasColimit` class. /-- An arbitrary choice of colimit cocone of a functor. -/ def colimit.cocone (F : J ⥤ C) [HasColimit F] : Cocone F := (getColimitCocone F).cocone #align category_theory.limits.colimit.cocone CategoryTheory.Limits.colimit.cocone /-- An arbitrary choice of colimit object of a functor. -/ def colimit (F : J ⥤ C) [HasColimit F] := (colimit.cocone F).pt #align category_theory.limits.colimit CategoryTheory.Limits.colimit /-- The coprojection from a value of the functor to the colimit object. -/ def colimit.ι (F : J ⥤ C) [HasColimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j #align category_theory.limits.colimit.ι CategoryTheory.Limits.colimit.ι @[simp] theorem colimit.cocone_ι {F : J ⥤ C} [HasColimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl #align category_theory.limits.colimit.cocone_ι CategoryTheory.Limits.colimit.cocone_ι @[simp] theorem colimit.cocone_x {F : J ⥤ C} [HasColimit F] : (colimit.cocone F).pt = colimit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.colimit.cocone_X CategoryTheory.Limits.colimit.cocone_x @[reassoc (attr := simp)] theorem colimit.w (F : J ⥤ C) [HasColimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f #align category_theory.limits.colimit.w CategoryTheory.Limits.colimit.w /-- Evidence that the arbitrary choice of cocone is a colimit cocone. -/ def colimit.isColimit (F : J ⥤ C) [HasColimit F] : IsColimit (colimit.cocone F) := (getColimitCocone F).isColimit #align category_theory.limits.colimit.is_colimit CategoryTheory.Limits.colimit.isColimit /-- The morphism from the colimit object to the cone point of any other cocone. -/ def colimit.desc (F : J ⥤ C) [HasColimit F] (c : Cocone F) : colimit F ⟶ c.pt := (colimit.isColimit F).desc c #align category_theory.limits.colimit.desc CategoryTheory.Limits.colimit.desc @[simp] theorem colimit.isColimit_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.isColimit F).desc c = colimit.desc F c := rfl #align category_theory.limits.colimit.is_colimit_desc CategoryTheory.Limits.colimit.isColimit_desc /-- We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`, and combined with `colimit.ext` we rely on these lemmas for many calculations. However, since `Category.assoc` is a `@[simp]` lemma, often expressions are right associated, and it's hard to apply these lemmas about `colimit.ι`. We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism. (see `Tactic/reassoc_axiom.lean`) -/ @[reassoc (attr := simp)] theorem colimit.ι_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := IsColimit.fac _ c j #align category_theory.limits.colimit.ι_desc CategoryTheory.Limits.colimit.ι_desc /-- Functoriality of colimits. Usually this morphism should be accessed through `colim.map`, but may be needed separately when you have specified colimits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) : colimit F ⟶ colimit G := IsColimit.map (colimit.isColimit F) _ α #align category_theory.limits.colim_map CategoryTheory.Limits.colimMap @[reassoc (attr := simp)] theorem ι_colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) (j : J) : colimit.ι F j ≫ colimMap α = α.app j ≫ colimit.ι G j := colimit.ι_desc _ j #align category_theory.limits.ι_colim_map CategoryTheory.Limits.ι_colimMap /-- The cocone morphism from the arbitrary choice of colimit cocone to any cocone. -/ def colimit.coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) : colimit.cocone F ⟶ c := (colimit.isColimit F).descCoconeMorphism c #align category_theory.limits.colimit.cocone_morphism CategoryTheory.Limits.colimit.coconeMorphism @[simp] theorem colimit.coconeMorphism_hom {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.coconeMorphism c).hom = colimit.desc F c := rfl #align category_theory.limits.colimit.cocone_morphism_hom CategoryTheory.Limits.colimit.coconeMorphism_hom theorem colimit.ι_coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ (colimit.coconeMorphism c).hom = c.ι.app j := by simp #align category_theory.limits.colimit.ι_cocone_morphism CategoryTheory.Limits.colimit.ι_coconeMorphism @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_hom {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hc).hom = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _ #align category_theory.limits.colimit.comp_cocone_point_unique_up_to_iso_hom CategoryTheory.Limits.colimit.comp_coconePointUniqueUpToIso_hom @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_inv {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso hc (colimit.isColimit _)).inv = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _ #align category_theory.limits.colimit.comp_cocone_point_unique_up_to_iso_inv CategoryTheory.Limits.colimit.comp_coconePointUniqueUpToIso_inv theorem colimit.existsUnique {F : J ⥤ C} [HasColimit F] (t : Cocone F) : ∃! d : colimit F ⟶ t.pt, ∀ j, colimit.ι F j ≫ d = t.ι.app j := (colimit.isColimit F).existsUnique _ #align category_theory.limits.colimit.exists_unique CategoryTheory.Limits.colimit.existsUnique /-- Given any other colimit cocone for `F`, the chosen `colimit F` is isomorphic to the cocone point. -/ def colimit.isoColimitCocone {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) : colimit F ≅ t.cocone.pt := IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) t.isColimit #align category_theory.limits.colimit.iso_colimit_cocone CategoryTheory.Limits.colimit.isoColimitCocone @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_hom {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : colimit.ι F j ≫ (colimit.isoColimitCocone t).hom = t.cocone.ι.app j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat #align category_theory.limits.colimit.iso_colimit_cocone_ι_hom CategoryTheory.Limits.colimit.isoColimitCocone_ι_hom @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_inv {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : t.cocone.ι.app j ≫ (colimit.isoColimitCocone t).inv = colimit.ι F j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat #align category_theory.limits.colimit.iso_colimit_cocone_ι_inv CategoryTheory.Limits.colimit.isoColimitCocone_ι_inv @[ext] theorem colimit.hom_ext {F : J ⥤ C} [HasColimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.isColimit F).hom_ext w #align category_theory.limits.colimit.hom_ext CategoryTheory.Limits.colimit.hom_ext @[simp] theorem colimit.desc_cocone {F : J ⥤ C} [HasColimit F] : colimit.desc F (colimit.cocone F) = 𝟙 (colimit F) := (colimit.isColimit _).desc_self #align category_theory.limits.colimit.desc_cocone CategoryTheory.Limits.colimit.desc_cocone /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and cocones with cone point `W`. -/ def colimit.homIso (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ F.cocones.obj W := (colimit.isColimit F).homIso W #align category_theory.limits.colimit.hom_iso CategoryTheory.Limits.colimit.homIso @[simp] theorem colimit.homIso_hom (F : J ⥤ C) [HasColimit F] {W : C} (f : ULift (colimit F ⟶ W)) : (colimit.homIso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f.down := (colimit.isColimit F).homIso_hom f #align category_theory.limits.colimit.hom_iso_hom CategoryTheory.Limits.colimit.homIso_hom /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and an explicit componentwise description of cocones with cone point `W`. -/ def colimit.homIso' (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.isColimit F).homIso' W #align category_theory.limits.colimit.hom_iso' CategoryTheory.Limits.colimit.homIso'
Mathlib/CategoryTheory/Limits/HasLimits.lean
902
903
theorem colimit.desc_extend (F : J ⥤ C) [HasColimit F] (c : Cocone F) {X : C} (f : c.pt ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := by
ext1; rw [← Category.assoc]; 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, Mario Carneiro -/ import Mathlib.MeasureTheory.OuterMeasure.Basic /-! # Operations on outer measures In this file we define algebraic operations (addition, scalar multiplication) on the type of outer measures on a type. We also show that outer measures on a type `α` form a complete lattice. ## References * <https://en.wikipedia.org/wiki/Outer_measure> ## 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 namespace OuterMeasure section Basic variable {α β : Type*} {m : OuterMeasure α} instance instZero : Zero (OuterMeasure α) := ⟨{ measureOf := fun _ => 0 empty := rfl mono := by intro _ _ _; exact le_refl 0 iUnion_nat := fun s _ => zero_le _ }⟩ #align measure_theory.outer_measure.has_zero MeasureTheory.OuterMeasure.instZero @[simp] theorem coe_zero : ⇑(0 : OuterMeasure α) = 0 := rfl #align measure_theory.outer_measure.coe_zero MeasureTheory.OuterMeasure.coe_zero instance instInhabited : Inhabited (OuterMeasure α) := ⟨0⟩ #align measure_theory.outer_measure.inhabited MeasureTheory.OuterMeasure.instInhabited instance instAdd : Add (OuterMeasure α) := ⟨fun m₁ m₂ => { measureOf := fun s => m₁ s + m₂ s empty := show m₁ ∅ + m₂ ∅ = 0 by simp [OuterMeasure.empty] mono := fun {s₁ s₂} h => add_le_add (m₁.mono h) (m₂.mono h) iUnion_nat := fun s _ => calc m₁ (⋃ i, s i) + m₂ (⋃ i, s i) ≤ (∑' i, m₁ (s i)) + ∑' i, m₂ (s i) := add_le_add (measure_iUnion_le s) (measure_iUnion_le s) _ = _ := ENNReal.tsum_add.symm }⟩ #align measure_theory.outer_measure.has_add MeasureTheory.OuterMeasure.instAdd @[simp] theorem coe_add (m₁ m₂ : OuterMeasure α) : ⇑(m₁ + m₂) = m₁ + m₂ := rfl #align measure_theory.outer_measure.coe_add MeasureTheory.OuterMeasure.coe_add theorem add_apply (m₁ m₂ : OuterMeasure α) (s : Set α) : (m₁ + m₂) s = m₁ s + m₂ s := rfl #align measure_theory.outer_measure.add_apply MeasureTheory.OuterMeasure.add_apply section SMul variable {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] variable {R' : Type*} [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞] instance instSMul : SMul R (OuterMeasure α) := ⟨fun c m => { measureOf := fun s => c • m s empty := by simp; rw [← smul_one_mul c]; simp mono := fun {s t} h => by simp only rw [← smul_one_mul c, ← smul_one_mul c (m t)] exact ENNReal.mul_left_mono (m.mono h) iUnion_nat := fun s _ => by simp_rw [← smul_one_mul c (m _), ENNReal.tsum_mul_left] exact ENNReal.mul_left_mono (measure_iUnion_le _) }⟩ @[simp] theorem coe_smul (c : R) (m : OuterMeasure α) : ⇑(c • m) = c • ⇑m := rfl #align measure_theory.outer_measure.coe_smul MeasureTheory.OuterMeasure.coe_smul theorem smul_apply (c : R) (m : OuterMeasure α) (s : Set α) : (c • m) s = c • m s := rfl #align measure_theory.outer_measure.smul_apply MeasureTheory.OuterMeasure.smul_apply instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] : SMulCommClass R R' (OuterMeasure α) := ⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩ #align measure_theory.outer_measure.smul_comm_class MeasureTheory.OuterMeasure.instSMulCommClass instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] : IsScalarTower R R' (OuterMeasure α) := ⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩ #align measure_theory.outer_measure.is_scalar_tower MeasureTheory.OuterMeasure.instIsScalarTower instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] : IsCentralScalar R (OuterMeasure α) := ⟨fun _ _ => ext fun _ => op_smul_eq_smul _ _⟩ #align measure_theory.outer_measure.is_central_scalar MeasureTheory.OuterMeasure.instIsCentralScalar end SMul instance instMulAction {R : Type*} [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] : MulAction R (OuterMeasure α) := Injective.mulAction _ coe_fn_injective coe_smul #align measure_theory.outer_measure.mul_action MeasureTheory.OuterMeasure.instMulAction instance addCommMonoid : AddCommMonoid (OuterMeasure α) := Injective.addCommMonoid (show OuterMeasure α → Set α → ℝ≥0∞ from _) coe_fn_injective rfl (fun _ _ => rfl) fun _ _ => rfl #align measure_theory.outer_measure.add_comm_monoid MeasureTheory.OuterMeasure.addCommMonoid /-- `(⇑)` as an `AddMonoidHom`. -/ @[simps] def coeFnAddMonoidHom : OuterMeasure α →+ Set α → ℝ≥0∞ where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align measure_theory.outer_measure.coe_fn_add_monoid_hom MeasureTheory.OuterMeasure.coeFnAddMonoidHom instance instDistribMulAction {R : Type*} [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] : DistribMulAction R (OuterMeasure α) := Injective.distribMulAction coeFnAddMonoidHom coe_fn_injective coe_smul #align measure_theory.outer_measure.distrib_mul_action MeasureTheory.OuterMeasure.instDistribMulAction instance instModule {R : Type*} [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] : Module R (OuterMeasure α) := Injective.module R coeFnAddMonoidHom coe_fn_injective coe_smul #align measure_theory.outer_measure.module MeasureTheory.OuterMeasure.instModule instance instBot : Bot (OuterMeasure α) := ⟨0⟩ #align measure_theory.outer_measure.has_bot MeasureTheory.OuterMeasure.instBot @[simp] theorem coe_bot : (⊥ : OuterMeasure α) = 0 := rfl #align measure_theory.outer_measure.coe_bot MeasureTheory.OuterMeasure.coe_bot instance instPartialOrder : PartialOrder (OuterMeasure α) where le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s le_refl a s := le_rfl le_trans a b c hab hbc s := le_trans (hab s) (hbc s) le_antisymm a b hab hba := ext fun s => le_antisymm (hab s) (hba s) #align measure_theory.outer_measure.outer_measure.partial_order MeasureTheory.OuterMeasure.instPartialOrder instance orderBot : OrderBot (OuterMeasure α) := { bot := 0, bot_le := fun a s => by simp only [coe_zero, Pi.zero_apply, coe_bot, zero_le] } #align measure_theory.outer_measure.outer_measure.order_bot MeasureTheory.OuterMeasure.orderBot theorem univ_eq_zero_iff (m : OuterMeasure α) : m univ = 0 ↔ m = 0 := ⟨fun h => bot_unique fun s => (measure_mono <| subset_univ s).trans_eq h, fun h => h.symm ▸ rfl⟩ #align measure_theory.outer_measure.univ_eq_zero_iff MeasureTheory.OuterMeasure.univ_eq_zero_iff section Supremum instance instSupSet : SupSet (OuterMeasure α) := ⟨fun ms => { measureOf := fun s => ⨆ m ∈ ms, (m : OuterMeasure α) s empty := nonpos_iff_eq_zero.1 <| iSup₂_le fun m _ => le_of_eq m.empty mono := fun {s₁ s₂} hs => iSup₂_mono fun m _ => m.mono hs iUnion_nat := fun f _ => iSup₂_le fun m hm => calc m (⋃ i, f i) ≤ ∑' i : ℕ, m (f i) := measure_iUnion_le _ _ ≤ ∑' i, ⨆ m ∈ ms, (m : OuterMeasure α) (f i) := ENNReal.tsum_le_tsum fun i => by apply le_iSup₂ m hm }⟩ #align measure_theory.outer_measure.has_Sup MeasureTheory.OuterMeasure.instSupSet instance instCompleteLattice : CompleteLattice (OuterMeasure α) := { OuterMeasure.orderBot, completeLatticeOfSup (OuterMeasure α) fun ms => ⟨fun m hm s => by apply le_iSup₂ m hm, fun m hm s => iSup₂_le fun m' hm' => hm hm' s⟩ with } #align measure_theory.outer_measure.complete_lattice MeasureTheory.OuterMeasure.instCompleteLattice @[simp] theorem sSup_apply (ms : Set (OuterMeasure α)) (s : Set α) : (sSup ms) s = ⨆ m ∈ ms, (m : OuterMeasure α) s := rfl #align measure_theory.outer_measure.Sup_apply MeasureTheory.OuterMeasure.sSup_apply @[simp] theorem iSup_apply {ι} (f : ι → OuterMeasure α) (s : Set α) : (⨆ i : ι, f i) s = ⨆ i, f i s := by rw [iSup, sSup_apply, iSup_range] #align measure_theory.outer_measure.supr_apply MeasureTheory.OuterMeasure.iSup_apply @[norm_cast] theorem coe_iSup {ι} (f : ι → OuterMeasure α) : ⇑(⨆ i, f i) = ⨆ i, ⇑(f i) := funext fun s => by simp #align measure_theory.outer_measure.coe_supr MeasureTheory.OuterMeasure.coe_iSup @[simp] theorem sup_apply (m₁ m₂ : OuterMeasure α) (s : Set α) : (m₁ ⊔ m₂) s = m₁ s ⊔ m₂ s := by have := iSup_apply (fun b => cond b m₁ m₂) s; rwa [iSup_bool_eq, iSup_bool_eq] at this #align measure_theory.outer_measure.sup_apply MeasureTheory.OuterMeasure.sup_apply theorem smul_iSup {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {ι : Sort*} (f : ι → OuterMeasure α) (c : R) : (c • ⨆ i, f i) = ⨆ i, c • f i := ext fun s => by simp only [smul_apply, iSup_apply, ENNReal.smul_iSup] #align measure_theory.outer_measure.smul_supr MeasureTheory.OuterMeasure.smul_iSup end Supremum @[mono, gcongr] theorem mono'' {m₁ m₂ : OuterMeasure α} {s₁ s₂ : Set α} (hm : m₁ ≤ m₂) (hs : s₁ ⊆ s₂) : m₁ s₁ ≤ m₂ s₂ := (hm s₁).trans (m₂.mono hs) #align measure_theory.outer_measure.mono'' MeasureTheory.OuterMeasure.mono'' /-- The pushforward of `m` along `f`. The outer measure on `s` is defined to be `m (f ⁻¹' s)`. -/ def map {β} (f : α → β) : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β where toFun m := { measureOf := fun s => m (f ⁻¹' s) empty := m.empty mono := fun {s t} h => m.mono (preimage_mono h) iUnion_nat := fun s _ => by simpa using measure_iUnion_le fun i => f ⁻¹' s i } map_add' m₁ m₂ := coe_fn_injective rfl map_smul' c m := coe_fn_injective rfl #align measure_theory.outer_measure.map MeasureTheory.OuterMeasure.map @[simp] theorem map_apply {β} (f : α → β) (m : OuterMeasure α) (s : Set β) : map f m s = m (f ⁻¹' s) := rfl #align measure_theory.outer_measure.map_apply MeasureTheory.OuterMeasure.map_apply @[simp] theorem map_id (m : OuterMeasure α) : map id m = m := ext fun _ => rfl #align measure_theory.outer_measure.map_id MeasureTheory.OuterMeasure.map_id @[simp] theorem map_map {β γ} (f : α → β) (g : β → γ) (m : OuterMeasure α) : map g (map f m) = map (g ∘ f) m := ext fun _ => rfl #align measure_theory.outer_measure.map_map MeasureTheory.OuterMeasure.map_map @[mono] theorem map_mono {β} (f : α → β) : Monotone (map f) := fun _ _ h _ => h _ #align measure_theory.outer_measure.map_mono MeasureTheory.OuterMeasure.map_mono @[simp] theorem map_sup {β} (f : α → β) (m m' : OuterMeasure α) : map f (m ⊔ m') = map f m ⊔ map f m' := ext fun s => by simp only [map_apply, sup_apply] #align measure_theory.outer_measure.map_sup MeasureTheory.OuterMeasure.map_sup @[simp] theorem map_iSup {β ι} (f : α → β) (m : ι → OuterMeasure α) : map f (⨆ i, m i) = ⨆ i, map f (m i) := ext fun s => by simp only [map_apply, iSup_apply] #align measure_theory.outer_measure.map_supr MeasureTheory.OuterMeasure.map_iSup instance instFunctor : Functor OuterMeasure where map {_ _} f := map f #align measure_theory.outer_measure.functor MeasureTheory.OuterMeasure.instFunctor instance instLawfulFunctor : LawfulFunctor OuterMeasure := by constructor <;> intros <;> rfl #align measure_theory.outer_measure.is_lawful_functor MeasureTheory.OuterMeasure.instLawfulFunctor /-- The dirac outer measure. -/ def dirac (a : α) : OuterMeasure α where measureOf s := indicator s (fun _ => 1) a empty := by simp mono {s t} h := indicator_le_indicator_of_subset h (fun _ => zero_le _) a iUnion_nat s _ := calc indicator (⋃ n, s n) 1 a = ⨆ n, indicator (s n) 1 a := indicator_iUnion_apply (M := ℝ≥0∞) rfl _ _ _ _ ≤ ∑' n, indicator (s n) 1 a := iSup_le fun _ ↦ ENNReal.le_tsum _ #align measure_theory.outer_measure.dirac MeasureTheory.OuterMeasure.dirac @[simp] theorem dirac_apply (a : α) (s : Set α) : dirac a s = indicator s (fun _ => 1) a := rfl #align measure_theory.outer_measure.dirac_apply MeasureTheory.OuterMeasure.dirac_apply /-- The sum of an (arbitrary) collection of outer measures. -/ def sum {ι} (f : ι → OuterMeasure α) : OuterMeasure α where measureOf s := ∑' i, f i s empty := by simp mono {s t} h := ENNReal.tsum_le_tsum fun i => measure_mono h iUnion_nat s _ := by rw [ENNReal.tsum_comm]; exact ENNReal.tsum_le_tsum fun i => measure_iUnion_le _ #align measure_theory.outer_measure.sum MeasureTheory.OuterMeasure.sum @[simp] theorem sum_apply {ι} (f : ι → OuterMeasure α) (s : Set α) : sum f s = ∑' i, f i s := rfl #align measure_theory.outer_measure.sum_apply MeasureTheory.OuterMeasure.sum_apply theorem smul_dirac_apply (a : ℝ≥0∞) (b : α) (s : Set α) : (a • dirac b) s = indicator s (fun _ => a) b := by simp only [smul_apply, smul_eq_mul, dirac_apply, ← indicator_mul_right _ fun _ => a, mul_one] #align measure_theory.outer_measure.smul_dirac_apply MeasureTheory.OuterMeasure.smul_dirac_apply /-- Pullback of an `OuterMeasure`: `comap f μ s = μ (f '' s)`. -/ def comap {β} (f : α → β) : OuterMeasure β →ₗ[ℝ≥0∞] OuterMeasure α where toFun m := { measureOf := fun s => m (f '' s) empty := by simp mono := fun {s t} h => m.mono <| image_subset f h iUnion_nat := fun s _ => by simpa only [image_iUnion] using measure_iUnion_le _ } map_add' m₁ m₂ := rfl map_smul' c m := rfl #align measure_theory.outer_measure.comap MeasureTheory.OuterMeasure.comap @[simp] theorem comap_apply {β} (f : α → β) (m : OuterMeasure β) (s : Set α) : comap f m s = m (f '' s) := rfl #align measure_theory.outer_measure.comap_apply MeasureTheory.OuterMeasure.comap_apply @[mono] theorem comap_mono {β} (f : α → β) : Monotone (comap f) := fun _ _ h _ => h _ #align measure_theory.outer_measure.comap_mono MeasureTheory.OuterMeasure.comap_mono @[simp] theorem comap_iSup {β ι} (f : α → β) (m : ι → OuterMeasure β) : comap f (⨆ i, m i) = ⨆ i, comap f (m i) := ext fun s => by simp only [comap_apply, iSup_apply] #align measure_theory.outer_measure.comap_supr MeasureTheory.OuterMeasure.comap_iSup /-- Restrict an `OuterMeasure` to a set. -/ def restrict (s : Set α) : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure α := (map (↑)).comp (comap ((↑) : s → α)) #align measure_theory.outer_measure.restrict MeasureTheory.OuterMeasure.restrict -- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)` @[simp] theorem restrict_apply (s t : Set α) (m : OuterMeasure α) : restrict s m t = m (t ∩ s) := by simp [restrict, inter_comm t] #align measure_theory.outer_measure.restrict_apply MeasureTheory.OuterMeasure.restrict_apply @[mono] theorem restrict_mono {s t : Set α} (h : s ⊆ t) {m m' : OuterMeasure α} (hm : m ≤ m') : restrict s m ≤ restrict t m' := fun u => by simp only [restrict_apply] exact (hm _).trans (m'.mono <| inter_subset_inter_right _ h) #align measure_theory.outer_measure.restrict_mono MeasureTheory.OuterMeasure.restrict_mono @[simp] theorem restrict_univ (m : OuterMeasure α) : restrict univ m = m := ext fun s => by simp #align measure_theory.outer_measure.restrict_univ MeasureTheory.OuterMeasure.restrict_univ @[simp] theorem restrict_empty (m : OuterMeasure α) : restrict ∅ m = 0 := ext fun s => by simp #align measure_theory.outer_measure.restrict_empty MeasureTheory.OuterMeasure.restrict_empty @[simp] theorem restrict_iSup {ι} (s : Set α) (m : ι → OuterMeasure α) : restrict s (⨆ i, m i) = ⨆ i, restrict s (m i) := by simp [restrict] #align measure_theory.outer_measure.restrict_supr MeasureTheory.OuterMeasure.restrict_iSup theorem map_comap {β} (f : α → β) (m : OuterMeasure β) : map f (comap f m) = restrict (range f) m := ext fun s => congr_arg m <| by simp only [image_preimage_eq_inter_range, Subtype.range_coe] #align measure_theory.outer_measure.map_comap MeasureTheory.OuterMeasure.map_comap theorem map_comap_le {β} (f : α → β) (m : OuterMeasure β) : map f (comap f m) ≤ m := fun _ => m.mono <| image_preimage_subset _ _ #align measure_theory.outer_measure.map_comap_le MeasureTheory.OuterMeasure.map_comap_le theorem restrict_le_self (m : OuterMeasure α) (s : Set α) : restrict s m ≤ m := map_comap_le _ _ #align measure_theory.outer_measure.restrict_le_self MeasureTheory.OuterMeasure.restrict_le_self @[simp] theorem map_le_restrict_range {β} {ma : OuterMeasure α} {mb : OuterMeasure β} {f : α → β} : map f ma ≤ restrict (range f) mb ↔ map f ma ≤ mb := ⟨fun h => h.trans (restrict_le_self _ _), fun h s => by simpa using h (s ∩ range f)⟩ #align measure_theory.outer_measure.map_le_restrict_range MeasureTheory.OuterMeasure.map_le_restrict_range theorem map_comap_of_surjective {β} {f : α → β} (hf : Surjective f) (m : OuterMeasure β) : map f (comap f m) = m := ext fun s => by rw [map_apply, comap_apply, hf.image_preimage] #align measure_theory.outer_measure.map_comap_of_surjective MeasureTheory.OuterMeasure.map_comap_of_surjective theorem le_comap_map {β} (f : α → β) (m : OuterMeasure α) : m ≤ comap f (map f m) := fun _ => m.mono <| subset_preimage_image _ _ #align measure_theory.outer_measure.le_comap_map MeasureTheory.OuterMeasure.le_comap_map theorem comap_map {β} {f : α → β} (hf : Injective f) (m : OuterMeasure α) : comap f (map f m) = m := ext fun s => by rw [comap_apply, map_apply, hf.preimage_image] #align measure_theory.outer_measure.comap_map MeasureTheory.OuterMeasure.comap_map @[simp] theorem top_apply {s : Set α} (h : s.Nonempty) : (⊤ : OuterMeasure α) s = ∞ := let ⟨a, as⟩ := h top_unique <| le_trans (by simp [smul_dirac_apply, as]) (le_iSup₂ (∞ • dirac a) trivial) #align measure_theory.outer_measure.top_apply MeasureTheory.OuterMeasure.top_apply theorem top_apply' (s : Set α) : (⊤ : OuterMeasure α) s = ⨅ h : s = ∅, 0 := s.eq_empty_or_nonempty.elim (fun h => by simp [h]) fun h => by simp [h, h.ne_empty] #align measure_theory.outer_measure.top_apply' MeasureTheory.OuterMeasure.top_apply' @[simp] theorem comap_top (f : α → β) : comap f ⊤ = ⊤ := ext_nonempty fun s hs => by rw [comap_apply, top_apply hs, top_apply (hs.image _)] #align measure_theory.outer_measure.comap_top MeasureTheory.OuterMeasure.comap_top theorem map_top (f : α → β) : map f ⊤ = restrict (range f) ⊤ := ext fun s => by rw [map_apply, restrict_apply, ← image_preimage_eq_inter_range, top_apply', top_apply', Set.image_eq_empty] #align measure_theory.outer_measure.map_top MeasureTheory.OuterMeasure.map_top @[simp]
Mathlib/MeasureTheory/OuterMeasure/Operations.lean
423
424
theorem map_top_of_surjective (f : α → β) (hf : Surjective f) : map f ⊤ = ⊤ := by
rw [map_top, hf.range_eq, restrict_univ]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs #align_import data.finset.locally_finite from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `≤` is the transitive closure of `⩿` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero assert_not_exists Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α} @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] #align finset.nonempty_Icc Finset.nonempty_Icc @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] #align finset.nonempty_Ico Finset.nonempty_Ico @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] #align finset.nonempty_Ioc Finset.nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] #align finset.nonempty_Ioo Finset.nonempty_Ioo @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] #align finset.Icc_eq_empty_iff Finset.Icc_eq_empty_iff @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] #align finset.Ico_eq_empty_iff Finset.Ico_eq_empty_iff @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] #align finset.Ioc_eq_empty_iff Finset.Ioc_eq_empty_iff -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] #align finset.Ioo_eq_empty_iff Finset.Ioo_eq_empty_iff alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff #align finset.Icc_eq_empty Finset.Icc_eq_empty alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff #align finset.Ico_eq_empty Finset.Ico_eq_empty alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff #align finset.Ioc_eq_empty Finset.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) #align finset.Ioo_eq_empty Finset.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align finset.Icc_eq_empty_of_lt Finset.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 finset.Ico_eq_empty_of_le Finset.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 finset.Ioc_eq_empty_of_le Finset.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 finset.Ioo_eq_empty_of_le Finset.Ioo_eq_empty_of_le -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and_iff, le_rfl] #align finset.left_mem_Icc Finset.left_mem_Icc -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and_iff, le_refl] #align finset.left_mem_Ico Finset.left_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true_iff, le_rfl] #align finset.right_mem_Icc Finset.right_mem_Icc -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true_iff, le_rfl] #align finset.right_mem_Ioc Finset.right_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 #align finset.left_not_mem_Ioc Finset.left_not_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 #align finset.left_not_mem_Ioo Finset.left_not_mem_Ioo -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 #align finset.right_not_mem_Ico Finset.right_not_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 #align finset.right_not_mem_Ioo Finset.right_not_mem_Ioo theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb #align finset.Icc_subset_Icc Finset.Icc_subset_Icc theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb #align finset.Ico_subset_Ico Finset.Ico_subset_Ico theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb #align finset.Ioc_subset_Ioc Finset.Ioc_subset_Ioc theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb #align finset.Ioo_subset_Ioo Finset.Ioo_subset_Ioo theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align finset.Icc_subset_Icc_left Finset.Icc_subset_Icc_left theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align finset.Ico_subset_Ico_left Finset.Ico_subset_Ico_left theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align finset.Ioc_subset_Ioc_left Finset.Ioc_subset_Ioc_left theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align finset.Ioo_subset_Ioo_left Finset.Ioo_subset_Ioo_left theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align finset.Icc_subset_Icc_right Finset.Icc_subset_Icc_right theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align finset.Ico_subset_Ico_right Finset.Ico_subset_Ico_right theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align finset.Ioc_subset_Ioc_right Finset.Ioc_subset_Ioc_right theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align finset.Ioo_subset_Ioo_right Finset.Ioo_subset_Ioo_right theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h #align finset.Ico_subset_Ioo_left Finset.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h #align finset.Ioc_subset_Ioo_right Finset.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h #align finset.Icc_subset_Ico_right Finset.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self #align finset.Ioo_subset_Ico_self Finset.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self #align finset.Ioo_subset_Ioc_self Finset.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self #align finset.Ico_subset_Icc_self Finset.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self #align finset.Ioc_subset_Icc_self Finset.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self #align finset.Ioo_subset_Icc_self Finset.Ioo_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] #align finset.Icc_subset_Icc_iff Finset.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] #align finset.Icc_subset_Ioo_iff Finset.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] #align finset.Icc_subset_Ico_iff Finset.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm #align finset.Icc_subset_Ioc_iff Finset.Icc_subset_Ioc_iff --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb #align finset.Icc_ssubset_Icc_left Finset.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb #align finset.Icc_ssubset_Icc_right Finset.Icc_ssubset_Icc_right variable (a) -- porting note (#10618): simp can prove this -- @[simp] theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align finset.Ico_self Finset.Ico_self -- porting note (#10618): simp can prove this -- @[simp] theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align finset.Ioc_self Finset.Ioc_self -- porting note (#10618): simp can prove this -- @[simp] theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align finset.Ioo_self Finset.Ioo_self variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ #align set.fintype_of_mem_bounds Set.fintypeOfMemBounds section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : (Ico a b).filter (· < c) = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt #align finset.Ico_filter_lt_of_le_left Finset.Ico_filter_lt_of_le_left theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : (Ico a b).filter (· < c) = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc #align finset.Ico_filter_lt_of_right_le Finset.Ico_filter_lt_of_right_le theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : (Ico a b).filter (· < c) = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb #align finset.Ico_filter_lt_of_le_right Finset.Ico_filter_lt_of_le_right theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : (Ico a b).filter (c ≤ ·) = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 #align finset.Ico_filter_le_of_le_left Finset.Ico_filter_le_of_le_left theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : (Ico a b).filter (b ≤ ·) = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le #align finset.Ico_filter_le_of_right_le Finset.Ico_filter_le_of_right_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : (Ico a b).filter (c ≤ ·) = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 #align finset.Ico_filter_le_of_left_le Finset.Ico_filter_le_of_left_le theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : (Icc a b).filter (· < c) = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h #align finset.Icc_filter_lt_of_lt_right Finset.Icc_filter_lt_of_lt_right theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : (Ioc a b).filter (· < c) = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h #align finset.Ioc_filter_lt_of_lt_right Finset.Ioc_filter_lt_of_lt_right theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : (Iic a).filter (· < c) = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h #align finset.Iic_filter_lt_of_lt_right Finset.Iic_filter_lt_of_lt_right variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : (univ.filter fun j => a < j ∧ j < b) = Ioo a b := by ext simp #align finset.filter_lt_lt_eq_Ioo Finset.filter_lt_lt_eq_Ioo theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : (univ.filter fun j => a < j ∧ j ≤ b) = Ioc a b := by ext simp #align finset.filter_lt_le_eq_Ioc Finset.filter_lt_le_eq_Ioc theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : (univ.filter fun j => a ≤ j ∧ j < b) = Ico a b := by ext simp #align finset.filter_le_lt_eq_Ico Finset.filter_le_lt_eq_Ico theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : (univ.filter fun j => a ≤ j ∧ j ≤ b) = Icc a b := by ext simp #align finset.filter_le_le_eq_Icc Finset.filter_le_le_eq_Icc end Filter section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self #align finset.Icc_subset_Ici_self Finset.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self #align finset.Ico_subset_Ici_self Finset.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self #align finset.Ioc_subset_Ioi_self Finset.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self #align finset.Ioo_subset_Ioi_self Finset.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self #align finset.Ioc_subset_Ici_self Finset.Ioc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self #align finset.Ioo_subset_Ici_self Finset.Ioo_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ @[simp] lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self #align finset.Icc_subset_Iic_self Finset.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self #align finset.Ioc_subset_Iic_self Finset.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self #align finset.Ico_subset_Iio_self Finset.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self #align finset.Ioo_subset_Iio_self Finset.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self #align finset.Ico_subset_Iic_self Finset.Ico_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self #align finset.Ioo_subset_Iic_self Finset.Ioo_subset_Iic_self end LocallyFiniteOrderBot end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a : α} theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self #align finset.Ioi_subset_Ici_self Finset.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set α} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx #align bdd_below.finite BddBelow.finite theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s := mt BddBelow.finite #align set.infinite.not_bdd_below Set.Infinite.not_bddBelow variable [Fintype α] theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : univ.filter (a < ·) = Ioi a := by ext simp #align finset.filter_lt_eq_Ioi Finset.filter_lt_eq_Ioi theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : univ.filter (a ≤ ·) = Ici a := by ext simp #align finset.filter_le_eq_Ici Finset.filter_le_eq_Ici end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {a : α} theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self #align finset.Iio_subset_Iic_self Finset.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite := hs.dual.finite #align bdd_above.finite BddAbove.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s := mt BddAbove.finite #align set.infinite.not_bdd_above Set.Infinite.not_bddAbove variable [Fintype α] theorem filter_gt_eq_Iio [DecidablePred (· < a)] : univ.filter (· < a) = Iio a := by ext simp #align finset.filter_gt_eq_Iio Finset.filter_gt_eq_Iio theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : univ.filter (· ≤ a) = Iic a := by ext simp #align finset.filter_ge_eq_Iic Finset.filter_ge_eq_Iic end LocallyFiniteOrderBot variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem disjoint_Ioi_Iio (a : α) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba #align finset.disjoint_Ioi_Iio Finset.disjoint_Ioi_Iio end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] #align finset.Icc_self Finset.Icc_self @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] #align finset.Icc_eq_singleton_iff Finset.Icc_eq_singleton_iff theorem Ico_disjoint_Ico_consecutive (a b c : α) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 #align finset.Ico_disjoint_Ico_consecutive Finset.Ico_disjoint_Ico_consecutive section DecidableEq variable [DecidableEq α] @[simp] theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] #align finset.Icc_erase_left Finset.Icc_erase_left @[simp] theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] #align finset.Icc_erase_right Finset.Icc_erase_right @[simp] theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] #align finset.Ico_erase_left Finset.Ico_erase_left @[simp]
Mathlib/Order/Interval/Finset/Basic.lean
568
568
theorem Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by
simp [← coe_inj]
/- 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.MonoidAlgebra.Degree import Mathlib.Algebra.Polynomial.Coeff import Mathlib.Algebra.Polynomial.Monomial import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Nat.WithBot import Mathlib.Data.Nat.Cast.WithTop import Mathlib.Data.Nat.SuccPred #align_import data.polynomial.degree.definitions from "leanprover-community/mathlib"@"808ea4ebfabeb599f21ec4ae87d6dc969597887f" /-! # Theory of univariate polynomials The definitions include `degree`, `Monic`, `leadingCoeff` Results include - `degree_mul` : The degree of the product is the sum of degrees - `leadingCoeff_add_of_degree_eq` and `leadingCoeff_add_of_degree_lt` : The leading_coefficient of a sum is determined by the leading coefficients and degrees -/ -- Porting note: `Mathlib.Data.Nat.Cast.WithTop` should be imported for `Nat.cast_withBot`. set_option linter.uppercaseLean3 false noncomputable section open Finsupp Finset open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = ⊥`. -/ def degree (p : R[X]) : WithBot ℕ := p.support.max #align polynomial.degree Polynomial.degree theorem supDegree_eq_degree (p : R[X]) : p.toFinsupp.supDegree WithBot.some = p.degree := max_eq_sup_coe theorem degree_lt_wf : WellFounded fun p q : R[X] => degree p < degree q := InvImage.wf degree wellFounded_lt #align polynomial.degree_lt_wf Polynomial.degree_lt_wf instance : WellFoundedRelation R[X] := ⟨_, degree_lt_wf⟩ /-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/ def natDegree (p : R[X]) : ℕ := (degree p).unbot' 0 #align polynomial.nat_degree Polynomial.natDegree /-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`-/ def leadingCoeff (p : R[X]) : R := coeff p (natDegree p) #align polynomial.leading_coeff Polynomial.leadingCoeff /-- a polynomial is `Monic` if its leading coefficient is 1 -/ def Monic (p : R[X]) := leadingCoeff p = (1 : R) #align polynomial.monic Polynomial.Monic @[nontriviality] theorem monic_of_subsingleton [Subsingleton R] (p : R[X]) : Monic p := Subsingleton.elim _ _ #align polynomial.monic_of_subsingleton Polynomial.monic_of_subsingleton theorem Monic.def : Monic p ↔ leadingCoeff p = 1 := Iff.rfl #align polynomial.monic.def Polynomial.Monic.def instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance #align polynomial.monic.decidable Polynomial.Monic.decidable @[simp] theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 := hp #align polynomial.monic.leading_coeff Polynomial.Monic.leadingCoeff theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 := hp #align polynomial.monic.coeff_nat_degree Polynomial.Monic.coeff_natDegree @[simp] theorem degree_zero : degree (0 : R[X]) = ⊥ := rfl #align polynomial.degree_zero Polynomial.degree_zero @[simp] theorem natDegree_zero : natDegree (0 : R[X]) = 0 := rfl #align polynomial.nat_degree_zero Polynomial.natDegree_zero @[simp] theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p := rfl #align polynomial.coeff_nat_degree Polynomial.coeff_natDegree @[simp] theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩ #align polynomial.degree_eq_bot Polynomial.degree_eq_bot @[nontriviality] theorem degree_of_subsingleton [Subsingleton R] : degree p = ⊥ := by rw [Subsingleton.elim p 0, degree_zero] #align polynomial.degree_of_subsingleton Polynomial.degree_of_subsingleton @[nontriviality] theorem natDegree_of_subsingleton [Subsingleton R] : natDegree p = 0 := by rw [Subsingleton.elim p 0, natDegree_zero] #align polynomial.nat_degree_of_subsingleton Polynomial.natDegree_of_subsingleton theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) have hn : degree p = some n := Classical.not_not.1 hn rw [natDegree, hn]; rfl #align polynomial.degree_eq_nat_degree Polynomial.degree_eq_natDegree theorem supDegree_eq_natDegree (p : R[X]) : p.toFinsupp.supDegree id = p.natDegree := by obtain rfl|h := eq_or_ne p 0 · simp apply WithBot.coe_injective rw [← AddMonoidAlgebra.supDegree_withBot_some_comp, Function.comp_id, supDegree_eq_degree, degree_eq_natDegree h, Nat.cast_withBot] rwa [support_toFinsupp, nonempty_iff_ne_empty, Ne, support_eq_empty] theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe #align polynomial.degree_eq_iff_nat_degree_eq Polynomial.degree_eq_iff_natDegree_eq theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) : p.degree = n ↔ p.natDegree = n := by obtain rfl|h := eq_or_ne p 0 · simp [hn.ne] · exact degree_eq_iff_natDegree_eq h #align polynomial.degree_eq_iff_nat_degree_eq_of_pos Polynomial.degree_eq_iff_natDegree_eq_of_pos theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by -- Porting note: `Nat.cast_withBot` is required. rw [natDegree, h, Nat.cast_withBot, WithBot.unbot'_coe] #align polynomial.nat_degree_eq_of_degree_eq_some Polynomial.natDegree_eq_of_degree_eq_some theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n := mt natDegree_eq_of_degree_eq_some #align polynomial.degree_ne_of_nat_degree_ne Polynomial.degree_ne_of_natDegree_ne @[simp] theorem degree_le_natDegree : degree p ≤ natDegree p := WithBot.giUnbot'Bot.gc.le_u_l _ #align polynomial.degree_le_nat_degree Polynomial.degree_le_natDegree theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) : natDegree p = natDegree q := by unfold natDegree; rw [h] #align polynomial.nat_degree_eq_of_degree_eq Polynomial.natDegree_eq_of_degree_eq theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by rw [Nat.cast_withBot] exact Finset.le_sup (mem_support_iff.2 h) #align polynomial.le_degree_of_ne_zero Polynomial.le_degree_of_ne_zero theorem le_natDegree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ natDegree p := by rw [← Nat.cast_le (α := WithBot ℕ), ← degree_eq_natDegree] · exact le_degree_of_ne_zero h · rintro rfl exact h rfl #align polynomial.le_nat_degree_of_ne_zero Polynomial.le_natDegree_of_ne_zero theorem le_natDegree_of_mem_supp (a : ℕ) : a ∈ p.support → a ≤ natDegree p := le_natDegree_of_ne_zero ∘ mem_support_iff.mp #align polynomial.le_nat_degree_of_mem_supp Polynomial.le_natDegree_of_mem_supp theorem degree_eq_of_le_of_coeff_ne_zero (pn : p.degree ≤ n) (p1 : p.coeff n ≠ 0) : p.degree = n := pn.antisymm (le_degree_of_ne_zero p1) #align polynomial.degree_eq_of_le_of_coeff_ne_zero Polynomial.degree_eq_of_le_of_coeff_ne_zero theorem natDegree_eq_of_le_of_coeff_ne_zero (pn : p.natDegree ≤ n) (p1 : p.coeff n ≠ 0) : p.natDegree = n := pn.antisymm (le_natDegree_of_ne_zero p1) #align polynomial.nat_degree_eq_of_le_of_coeff_ne_zero Polynomial.natDegree_eq_of_le_of_coeff_ne_zero theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) : f.degree ≤ g.degree := Finset.sup_mono h #align polynomial.degree_mono Polynomial.degree_mono theorem supp_subset_range (h : natDegree p < m) : p.support ⊆ Finset.range m := fun _n hn => mem_range.2 <| (le_natDegree_of_mem_supp _ hn).trans_lt h #align polynomial.supp_subset_range Polynomial.supp_subset_range theorem supp_subset_range_natDegree_succ : p.support ⊆ Finset.range (natDegree p + 1) := supp_subset_range (Nat.lt_succ_self _) #align polynomial.supp_subset_range_nat_degree_succ Polynomial.supp_subset_range_natDegree_succ theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by by_cases hp : p = 0 · rw [hp, degree_zero] exact bot_le · rw [degree_eq_natDegree hp] exact le_degree_of_ne_zero h #align polynomial.degree_le_degree Polynomial.degree_le_degree theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n := WithBot.unbot'_le_iff (fun _ ↦ bot_le) #align polynomial.nat_degree_le_iff_degree_le Polynomial.natDegree_le_iff_degree_le theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n := WithBot.unbot'_lt_iff (absurd · (degree_eq_bot.not.mpr hp)) #align polynomial.nat_degree_lt_iff_degree_lt Polynomial.natDegree_lt_iff_degree_lt alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le #align polynomial.degree_le_of_nat_degree_le Polynomial.degree_le_of_natDegree_le #align polynomial.nat_degree_le_of_degree_le Polynomial.natDegree_le_of_degree_le theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) : p.natDegree ≤ q.natDegree := WithBot.giUnbot'Bot.gc.monotone_l hpq #align polynomial.nat_degree_le_nat_degree Polynomial.natDegree_le_natDegree theorem natDegree_lt_natDegree {p q : R[X]} (hp : p ≠ 0) (hpq : p.degree < q.degree) : p.natDegree < q.natDegree := by by_cases hq : q = 0 · exact (not_lt_bot <| hq ▸ hpq).elim rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at hpq #align polynomial.nat_degree_lt_nat_degree Polynomial.natDegree_lt_natDegree @[simp] theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton, WithBot.coe_zero] #align polynomial.degree_C Polynomial.degree_C theorem degree_C_le : degree (C a) ≤ 0 := by by_cases h : a = 0 · rw [h, C_0] exact bot_le · rw [degree_C h] #align polynomial.degree_C_le Polynomial.degree_C_le theorem degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one #align polynomial.degree_C_lt Polynomial.degree_C_lt theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le #align polynomial.degree_one_le Polynomial.degree_one_le @[simp] theorem natDegree_C (a : R) : natDegree (C a) = 0 := by by_cases ha : a = 0 · have : C a = 0 := by rw [ha, C_0] rw [natDegree, degree_eq_bot.2 this, WithBot.unbot'_bot] · rw [natDegree, degree_C ha, WithBot.unbot_zero'] #align polynomial.nat_degree_C Polynomial.natDegree_C @[simp] theorem natDegree_one : natDegree (1 : R[X]) = 0 := natDegree_C 1 #align polynomial.nat_degree_one Polynomial.natDegree_one @[simp] theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natDegree_C] #align polynomial.nat_degree_nat_cast Polynomial.natDegree_natCast @[deprecated (since := "2024-04-17")] alias natDegree_nat_cast := natDegree_natCast theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[deprecated (since := "2024-04-17")] alias degree_nat_cast_le := degree_natCast_le @[simp] theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot] #align polynomial.degree_monomial Polynomial.degree_monomial @[simp] theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, degree_monomial n ha] #align polynomial.degree_C_mul_X_pow Polynomial.degree_C_mul_X_pow theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by simpa only [pow_one] using degree_C_mul_X_pow 1 ha #align polynomial.degree_C_mul_X Polynomial.degree_C_mul_X theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n := letI := Classical.decEq R if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le else le_of_eq (degree_monomial n h) #align polynomial.degree_monomial_le Polynomial.degree_monomial_le theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by rw [C_mul_X_pow_eq_monomial] apply degree_monomial_le #align polynomial.degree_C_mul_X_pow_le Polynomial.degree_C_mul_X_pow_le theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by simpa only [pow_one] using degree_C_mul_X_pow_le 1 a #align polynomial.degree_C_mul_X_le Polynomial.degree_C_mul_X_le @[simp] theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n := natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha) #align polynomial.nat_degree_C_mul_X_pow Polynomial.natDegree_C_mul_X_pow @[simp] theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha #align polynomial.nat_degree_C_mul_X Polynomial.natDegree_C_mul_X @[simp] theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) : natDegree (monomial i r) = if r = 0 then 0 else i := by split_ifs with hr · simp [hr] · rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr] #align polynomial.nat_degree_monomial Polynomial.natDegree_monomial theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by classical rw [Polynomial.natDegree_monomial] split_ifs exacts [Nat.zero_le _, le_rfl] #align polynomial.nat_degree_monomial_le Polynomial.natDegree_monomial_le theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i := letI := Classical.decEq R Eq.trans (natDegree_monomial _ _) (if_neg r0) #align polynomial.nat_degree_monomial_eq Polynomial.natDegree_monomial_eq theorem coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 := Classical.not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h)) #align polynomial.coeff_eq_zero_of_degree_lt Polynomial.coeff_eq_zero_of_degree_lt theorem coeff_eq_zero_of_natDegree_lt {p : R[X]} {n : ℕ} (h : p.natDegree < n) : p.coeff n = 0 := by apply coeff_eq_zero_of_degree_lt by_cases hp : p = 0 · subst hp exact WithBot.bot_lt_coe n · rwa [degree_eq_natDegree hp, Nat.cast_lt] #align polynomial.coeff_eq_zero_of_nat_degree_lt Polynomial.coeff_eq_zero_of_natDegree_lt theorem ext_iff_natDegree_le {p q : R[X]} {n : ℕ} (hp : p.natDegree ≤ n) (hq : q.natDegree ≤ n) : p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i := by refine Iff.trans Polynomial.ext_iff ?_ refine forall_congr' fun i => ⟨fun h _ => h, fun h => ?_⟩ refine (le_or_lt i n).elim h fun k => ?_ exact (coeff_eq_zero_of_natDegree_lt (hp.trans_lt k)).trans (coeff_eq_zero_of_natDegree_lt (hq.trans_lt k)).symm #align polynomial.ext_iff_nat_degree_le Polynomial.ext_iff_natDegree_le theorem ext_iff_degree_le {p q : R[X]} {n : ℕ} (hp : p.degree ≤ n) (hq : q.degree ≤ n) : p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i := ext_iff_natDegree_le (natDegree_le_of_degree_le hp) (natDegree_le_of_degree_le hq) #align polynomial.ext_iff_degree_le Polynomial.ext_iff_degree_le @[simp] theorem coeff_natDegree_succ_eq_zero {p : R[X]} : p.coeff (p.natDegree + 1) = 0 := coeff_eq_zero_of_natDegree_lt (lt_add_one _) #align polynomial.coeff_nat_degree_succ_eq_zero Polynomial.coeff_natDegree_succ_eq_zero -- We need the explicit `Decidable` argument here because an exotic one shows up in a moment! theorem ite_le_natDegree_coeff (p : R[X]) (n : ℕ) (I : Decidable (n < 1 + natDegree p)) : @ite _ (n < 1 + natDegree p) I (coeff p n) 0 = coeff p n := by split_ifs with h · rfl · exact (coeff_eq_zero_of_natDegree_lt (not_le.1 fun w => h (Nat.lt_one_add_iff.2 w))).symm #align polynomial.ite_le_nat_degree_coeff Polynomial.ite_le_natDegree_coeff theorem as_sum_support (p : R[X]) : p = ∑ i ∈ p.support, monomial i (p.coeff i) := (sum_monomial_eq p).symm #align polynomial.as_sum_support Polynomial.as_sum_support theorem as_sum_support_C_mul_X_pow (p : R[X]) : p = ∑ i ∈ p.support, C (p.coeff i) * X ^ i := _root_.trans p.as_sum_support <| by simp only [C_mul_X_pow_eq_monomial] #align polynomial.as_sum_support_C_mul_X_pow Polynomial.as_sum_support_C_mul_X_pow /-- We can reexpress a sum over `p.support` as a sum over `range n`, for any `n` satisfying `p.natDegree < n`. -/ theorem sum_over_range' [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) (n : ℕ) (w : p.natDegree < n) : p.sum f = ∑ a ∈ range n, f a (coeff p a) := by rcases p with ⟨⟩ have := supp_subset_range w simp only [Polynomial.sum, support, coeff, natDegree, degree] at this ⊢ exact Finsupp.sum_of_support_subset _ this _ fun n _hn => h n #align polynomial.sum_over_range' Polynomial.sum_over_range' /-- We can reexpress a sum over `p.support` as a sum over `range (p.natDegree + 1)`. -/ theorem sum_over_range [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) : p.sum f = ∑ a ∈ range (p.natDegree + 1), f a (coeff p a) := sum_over_range' p h (p.natDegree + 1) (lt_add_one _) #align polynomial.sum_over_range Polynomial.sum_over_range -- TODO this is essentially a duplicate of `sum_over_range`, and should be removed. theorem sum_fin [AddCommMonoid S] (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) {n : ℕ} {p : R[X]} (hn : p.degree < n) : (∑ i : Fin n, f i (p.coeff i)) = p.sum f := by by_cases hp : p = 0 · rw [hp, sum_zero_index, Finset.sum_eq_zero] intro i _ exact hf i rw [sum_over_range' _ hf n ((natDegree_lt_iff_degree_lt hp).mpr hn), Fin.sum_univ_eq_sum_range fun i => f i (p.coeff i)] #align polynomial.sum_fin Polynomial.sum_fin theorem as_sum_range' (p : R[X]) (n : ℕ) (w : p.natDegree < n) : p = ∑ i ∈ range n, monomial i (coeff p i) := p.sum_monomial_eq.symm.trans <| p.sum_over_range' monomial_zero_right _ w #align polynomial.as_sum_range' Polynomial.as_sum_range' theorem as_sum_range (p : R[X]) : p = ∑ i ∈ range (p.natDegree + 1), monomial i (coeff p i) := p.sum_monomial_eq.symm.trans <| p.sum_over_range <| monomial_zero_right #align polynomial.as_sum_range Polynomial.as_sum_range theorem as_sum_range_C_mul_X_pow (p : R[X]) : p = ∑ i ∈ range (p.natDegree + 1), C (coeff p i) * X ^ i := p.as_sum_range.trans <| by simp only [C_mul_X_pow_eq_monomial] #align polynomial.as_sum_range_C_mul_X_pow Polynomial.as_sum_range_C_mul_X_pow theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h => mem_support_iff.mp (mem_of_max hn) h #align polynomial.coeff_ne_zero_of_eq_degree Polynomial.coeff_ne_zero_of_eq_degree theorem eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) := ext fun n => Nat.casesOn n (by simp) fun n => Nat.casesOn n (by simp [coeff_C]) fun m => by -- Porting note: `by decide` → `Iff.mpr ..` have : degree p < m.succ.succ := lt_of_le_of_lt h (Iff.mpr WithBot.coe_lt_coe <| Nat.succ_lt_succ <| Nat.zero_lt_succ m) simp [coeff_eq_zero_of_degree_lt this, coeff_C, Nat.succ_ne_zero, coeff_X, Nat.succ_inj', @eq_comm ℕ 0] #align polynomial.eq_X_add_C_of_degree_le_one Polynomial.eq_X_add_C_of_degree_le_one theorem eq_X_add_C_of_degree_eq_one (h : degree p = 1) : p = C p.leadingCoeff * X + C (p.coeff 0) := (eq_X_add_C_of_degree_le_one h.le).trans (by rw [← Nat.cast_one] at h; rw [leadingCoeff, natDegree_eq_of_degree_eq_some h]) #align polynomial.eq_X_add_C_of_degree_eq_one Polynomial.eq_X_add_C_of_degree_eq_one theorem eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) := eq_X_add_C_of_degree_le_one <| degree_le_of_natDegree_le h #align polynomial.eq_X_add_C_of_nat_degree_le_one Polynomial.eq_X_add_C_of_natDegree_le_one theorem Monic.eq_X_add_C (hm : p.Monic) (hnd : p.natDegree = 1) : p = X + C (p.coeff 0) := by rw [← one_mul X, ← C_1, ← hm.coeff_natDegree, hnd, ← eq_X_add_C_of_natDegree_le_one hnd.le] #align polynomial.monic.eq_X_add_C Polynomial.Monic.eq_X_add_C theorem exists_eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) : ∃ a b, p = C a * X + C b := ⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_natDegree_le_one h⟩ #align polynomial.exists_eq_X_add_C_of_natDegree_le_one Polynomial.exists_eq_X_add_C_of_natDegree_le_one theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R) #align polynomial.degree_X_pow_le Polynomial.degree_X_pow_le theorem degree_X_le : degree (X : R[X]) ≤ 1 := degree_monomial_le _ _ #align polynomial.degree_X_le Polynomial.degree_X_le theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 := natDegree_le_of_degree_le degree_X_le #align polynomial.nat_degree_X_le Polynomial.natDegree_X_le theorem mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ support (C c * X ^ n)) : a = n := mem_singleton.1 <| support_C_mul_X_pow' n c h #align polynomial.mem_support_C_mul_X_pow Polynomial.mem_support_C_mul_X_pow theorem card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : card (support (C c * X ^ n)) ≤ 1 := by rw [← card_singleton n] apply card_le_card (support_C_mul_X_pow' n c) #align polynomial.card_support_C_mul_X_pow_le_one Polynomial.card_support_C_mul_X_pow_le_one theorem card_supp_le_succ_natDegree (p : R[X]) : p.support.card ≤ p.natDegree + 1 := by rw [← Finset.card_range (p.natDegree + 1)] exact Finset.card_le_card supp_subset_range_natDegree_succ #align polynomial.card_supp_le_succ_nat_degree Polynomial.card_supp_le_succ_natDegree theorem le_degree_of_mem_supp (a : ℕ) : a ∈ p.support → ↑a ≤ degree p := le_degree_of_ne_zero ∘ mem_support_iff.mp #align polynomial.le_degree_of_mem_supp Polynomial.le_degree_of_mem_supp theorem nonempty_support_iff : p.support.Nonempty ↔ p ≠ 0 := by rw [Ne, nonempty_iff_ne_empty, Ne, ← support_eq_empty] #align polynomial.nonempty_support_iff Polynomial.nonempty_support_iff end Semiring section NonzeroSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} @[simp] theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) := degree_C one_ne_zero #align polynomial.degree_one Polynomial.degree_one @[simp] theorem degree_X : degree (X : R[X]) = 1 := degree_monomial _ one_ne_zero #align polynomial.degree_X Polynomial.degree_X @[simp] theorem natDegree_X : (X : R[X]).natDegree = 1 := natDegree_eq_of_degree_eq_some degree_X #align polynomial.nat_degree_X Polynomial.natDegree_X end NonzeroSemiring section Ring variable [Ring R] theorem coeff_mul_X_sub_C {p : R[X]} {r : R} {a : ℕ} : coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r := by simp [mul_sub] #align polynomial.coeff_mul_X_sub_C Polynomial.coeff_mul_X_sub_C @[simp] theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg] #align polynomial.degree_neg Polynomial.degree_neg theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a := p.degree_neg.le.trans hp @[simp] theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree] #align polynomial.nat_degree_neg Polynomial.natDegree_neg theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m := (natDegree_neg p).le.trans hp @[simp] theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by rw [← C_eq_intCast, natDegree_C] #align polynomial.nat_degree_intCast Polynomial.natDegree_intCast @[deprecated (since := "2024-04-17")] alias natDegree_int_cast := natDegree_intCast theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[deprecated (since := "2024-04-17")] alias degree_int_cast_le := degree_intCast_le @[simp] theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg] #align polynomial.leading_coeff_neg Polynomial.leadingCoeff_neg end Ring section Semiring variable [Semiring R] {p : R[X]} /-- The second-highest coefficient, or 0 for constants -/ def nextCoeff (p : R[X]) : R := if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1) #align polynomial.next_coeff Polynomial.nextCoeff lemma nextCoeff_eq_zero : p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by simp [nextCoeff] @[simp] theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by rw [nextCoeff] simp #align polynomial.next_coeff_C_eq_zero Polynomial.nextCoeff_C_eq_zero theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) : nextCoeff p = p.coeff (p.natDegree - 1) := by rw [nextCoeff, if_neg] contrapose! hp simpa #align polynomial.next_coeff_of_pos_nat_degree Polynomial.nextCoeff_of_natDegree_pos variable {p q : R[X]} {ι : Type*} theorem coeff_natDegree_eq_zero_of_degree_lt (h : degree p < degree q) : coeff p (natDegree q) = 0 := coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_natDegree) #align polynomial.coeff_nat_degree_eq_zero_of_degree_lt Polynomial.coeff_natDegree_eq_zero_of_degree_lt theorem ne_zero_of_degree_gt {n : WithBot ℕ} (h : n < degree p) : p ≠ 0 := mt degree_eq_bot.2 h.ne_bot #align polynomial.ne_zero_of_degree_gt Polynomial.ne_zero_of_degree_gt theorem ne_zero_of_degree_ge_degree (hpq : p.degree ≤ q.degree) (hp : p ≠ 0) : q ≠ 0 := Polynomial.ne_zero_of_degree_gt (lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr (by rwa [Ne, Polynomial.degree_eq_bot])) hpq : q.degree > ⊥) #align polynomial.ne_zero_of_degree_ge_degree Polynomial.ne_zero_of_degree_ge_degree theorem ne_zero_of_natDegree_gt {n : ℕ} (h : n < natDegree p) : p ≠ 0 := fun H => by simp [H, Nat.not_lt_zero] at h #align polynomial.ne_zero_of_nat_degree_gt Polynomial.ne_zero_of_natDegree_gt theorem degree_lt_degree (h : natDegree p < natDegree q) : degree p < degree q := by by_cases hp : p = 0 · simp [hp] rw [bot_lt_iff_ne_bot] intro hq simp [hp, degree_eq_bot.mp hq, lt_irrefl] at h · rwa [degree_eq_natDegree hp, degree_eq_natDegree <| ne_zero_of_natDegree_gt h, Nat.cast_lt] #align polynomial.degree_lt_degree Polynomial.degree_lt_degree theorem natDegree_lt_natDegree_iff (hp : p ≠ 0) : natDegree p < natDegree q ↔ degree p < degree q := ⟨degree_lt_degree, fun h ↦ by have hq : q ≠ 0 := ne_zero_of_degree_gt h rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at h⟩ #align polynomial.nat_degree_lt_nat_degree_iff Polynomial.natDegree_lt_natDegree_iff theorem eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) := by ext (_ | n) · simp rw [coeff_C, if_neg (Nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt] exact h.trans_lt (WithBot.coe_lt_coe.2 n.succ_pos) #align polynomial.eq_C_of_degree_le_zero Polynomial.eq_C_of_degree_le_zero theorem eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) := eq_C_of_degree_le_zero h.le #align polynomial.eq_C_of_degree_eq_zero Polynomial.eq_C_of_degree_eq_zero theorem degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) := ⟨eq_C_of_degree_le_zero, fun h => h.symm ▸ degree_C_le⟩ #align polynomial.degree_le_zero_iff Polynomial.degree_le_zero_iff theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by simpa only [degree, ← support_toFinsupp, toFinsupp_add] using AddMonoidAlgebra.sup_support_add_le _ _ _ #align polynomial.degree_add_le Polynomial.degree_add_le theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) : degree (p + q) ≤ n := (degree_add_le p q).trans <| max_le hp hq #align polynomial.degree_add_le_of_degree_le Polynomial.degree_add_le_of_degree_le theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p + q) ≤ max a b := (p.degree_add_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by cases' le_max_iff.1 (degree_add_le p q) with h h <;> simp [natDegree_le_natDegree h] #align polynomial.nat_degree_add_le Polynomial.natDegree_add_le theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ n := (natDegree_add_le p q).trans <| max_le hp hq #align polynomial.nat_degree_add_le_of_degree_le Polynomial.natDegree_add_le_of_degree_le theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ max m n := (p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_› @[simp] theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 := rfl #align polynomial.leading_coeff_zero Polynomial.leadingCoeff_zero @[simp] theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 := ⟨fun h => Classical.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ #align polynomial.leading_coeff_eq_zero Polynomial.leadingCoeff_eq_zero theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero] #align polynomial.leading_coeff_ne_zero Polynomial.leadingCoeff_ne_zero theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by rw [leadingCoeff_eq_zero, degree_eq_bot] #align polynomial.leading_coeff_eq_zero_iff_deg_eq_bot Polynomial.leadingCoeff_eq_zero_iff_deg_eq_bot lemma natDegree_le_pred (hf : p.natDegree ≤ n) (hn : p.coeff n = 0) : p.natDegree ≤ n - 1 := by obtain _ | n := n · exact hf · refine (Nat.le_succ_iff_eq_or_le.1 hf).resolve_left fun h ↦ ?_ rw [← Nat.succ_eq_add_one, ← h, coeff_natDegree, leadingCoeff_eq_zero] at hn aesop theorem natDegree_mem_support_of_nonzero (H : p ≠ 0) : p.natDegree ∈ p.support := by rw [mem_support_iff] exact (not_congr leadingCoeff_eq_zero).mpr H #align polynomial.nat_degree_mem_support_of_nonzero Polynomial.natDegree_mem_support_of_nonzero theorem natDegree_eq_support_max' (h : p ≠ 0) : p.natDegree = p.support.max' (nonempty_support_iff.mpr h) := (le_max' _ _ <| natDegree_mem_support_of_nonzero h).antisymm <| max'_le _ _ _ le_natDegree_of_mem_supp #align polynomial.nat_degree_eq_support_max' Polynomial.natDegree_eq_support_max' theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n := natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _ #align polynomial.nat_degree_C_mul_X_pow_le Polynomial.natDegree_C_mul_X_pow_le theorem degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p := le_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) <| degree_le_degree <| by rw [coeff_add, coeff_natDegree_eq_zero_of_degree_lt h, add_zero] exact mt leadingCoeff_eq_zero.1 (ne_zero_of_degree_gt h) #align polynomial.degree_add_eq_left_of_degree_lt Polynomial.degree_add_eq_left_of_degree_lt theorem degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q := by rw [add_comm, degree_add_eq_left_of_degree_lt h] #align polynomial.degree_add_eq_right_of_degree_lt Polynomial.degree_add_eq_right_of_degree_lt theorem natDegree_add_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) : natDegree (p + q) = natDegree p := natDegree_eq_of_degree_eq (degree_add_eq_left_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_add_eq_left_of_nat_degree_lt Polynomial.natDegree_add_eq_left_of_natDegree_lt theorem natDegree_add_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) : natDegree (p + q) = natDegree q := natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_add_eq_right_of_nat_degree_lt Polynomial.natDegree_add_eq_right_of_natDegree_lt theorem degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p := add_comm (C a) p ▸ degree_add_eq_right_of_degree_lt <| lt_of_le_of_lt degree_C_le hp #align polynomial.degree_add_C Polynomial.degree_add_C @[simp] theorem natDegree_add_C {a : R} : (p + C a).natDegree = p.natDegree := by rcases eq_or_ne p 0 with rfl | hp · simp by_cases hpd : p.degree ≤ 0 · rw [eq_C_of_degree_le_zero hpd, ← C_add, natDegree_C, natDegree_C] · rw [not_le, degree_eq_natDegree hp, Nat.cast_pos, ← natDegree_C a] at hpd exact natDegree_add_eq_left_of_natDegree_lt hpd @[simp] theorem natDegree_C_add {a : R} : (C a + p).natDegree = p.natDegree := by simp [add_comm _ p] theorem degree_add_eq_of_leadingCoeff_add_ne_zero (h : leadingCoeff p + leadingCoeff q ≠ 0) : degree (p + q) = max p.degree q.degree := le_antisymm (degree_add_le _ _) <| match lt_trichotomy (degree p) (degree q) with | Or.inl hlt => by rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt] | Or.inr (Or.inl HEq) => le_of_not_gt fun hlt : max (degree p) (degree q) > degree (p + q) => h <| show leadingCoeff p + leadingCoeff q = 0 by rw [HEq, max_self] at hlt rw [leadingCoeff, leadingCoeff, natDegree_eq_of_degree_eq HEq, ← coeff_add] exact coeff_natDegree_eq_zero_of_degree_lt hlt | Or.inr (Or.inr hlt) => by rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt] #align polynomial.degree_add_eq_of_leading_coeff_add_ne_zero Polynomial.degree_add_eq_of_leadingCoeff_add_ne_zero lemma natDegree_eq_of_natDegree_add_lt_left (p q : R[X]) (H : natDegree (p + q) < natDegree p) : natDegree p = natDegree q := by by_contra h cases Nat.lt_or_lt_of_ne h with | inl h => exact lt_asymm h (by rwa [natDegree_add_eq_right_of_natDegree_lt h] at H) | inr h => rw [natDegree_add_eq_left_of_natDegree_lt h] at H exact LT.lt.false H lemma natDegree_eq_of_natDegree_add_lt_right (p q : R[X]) (H : natDegree (p + q) < natDegree q) : natDegree p = natDegree q := (natDegree_eq_of_natDegree_add_lt_left q p (add_comm p q ▸ H)).symm lemma natDegree_eq_of_natDegree_add_eq_zero (p q : R[X]) (H : natDegree (p + q) = 0) : natDegree p = natDegree q := by by_cases h₁ : natDegree p = 0; on_goal 1 => by_cases h₂ : natDegree q = 0 · exact h₁.trans h₂.symm · apply natDegree_eq_of_natDegree_add_lt_right; rwa [H, Nat.pos_iff_ne_zero] · apply natDegree_eq_of_natDegree_add_lt_left; rwa [H, Nat.pos_iff_ne_zero] theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by rcases p with ⟨p⟩ simp only [erase_def, degree, coeff, support] -- Porting note: simpler convert-free proof to be explicit about definition unfolding apply sup_mono rw [Finsupp.support_erase] apply Finset.erase_subset #align polynomial.degree_erase_le Polynomial.degree_erase_le theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by apply lt_of_le_of_ne (degree_erase_le _ _) rw [degree_eq_natDegree hp, degree, support_erase] exact fun h => not_mem_erase _ _ (mem_of_max h) #align polynomial.degree_erase_lt Polynomial.degree_erase_lt theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by classical rw [degree, support_update] split_ifs · exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _) · rw [max_insert, max_comm] exact le_rfl #align polynomial.degree_update_le Polynomial.degree_update_le theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) : degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) := Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) fun a s has ih => calc degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by rw [Finset.sum_cons]; exact degree_add_le _ _ _ ≤ _ := by rw [sup_cons, sup_eq_max]; exact max_le_max le_rfl ih #align polynomial.degree_sum_le Polynomial.degree_sum_le theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by simpa only [degree, ← support_toFinsupp, toFinsupp_mul] using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _ #align polynomial.degree_mul_le Polynomial.degree_mul_le theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p * q) ≤ a + b := (p.degree_mul_le _).trans <| add_le_add ‹_› ‹_› theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p | 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le | n + 1 => calc degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by rw [pow_succ]; exact degree_mul_le _ _ _ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _ #align polynomial.degree_pow_le Polynomial.degree_pow_le theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) : degree (p ^ b) ≤ b * a := by induction b with | zero => simp [degree_one_le] | succ n hn => rw [Nat.cast_succ, add_mul, one_mul, pow_succ] exact degree_mul_le_of_le hn hp @[simp] theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by classical by_cases ha : a = 0 · simp only [ha, (monomial n).map_zero, leadingCoeff_zero] · rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial] simp #align polynomial.leading_coeff_monomial Polynomial.leadingCoeff_monomial theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial] #align polynomial.leading_coeff_C_mul_X_pow Polynomial.leadingCoeff_C_mul_X_pow theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1 #align polynomial.leading_coeff_C_mul_X Polynomial.leadingCoeff_C_mul_X @[simp] theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a := leadingCoeff_monomial a 0 #align polynomial.leading_coeff_C Polynomial.leadingCoeff_C -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n #align polynomial.leading_coeff_X_pow Polynomial.leadingCoeff_X_pow -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by simpa only [pow_one] using @leadingCoeff_X_pow R _ 1 #align polynomial.leading_coeff_X Polynomial.leadingCoeff_X @[simp] theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) := leadingCoeff_X_pow n #align polynomial.monic_X_pow Polynomial.monic_X_pow @[simp] theorem monic_X : Monic (X : R[X]) := leadingCoeff_X #align polynomial.monic_X Polynomial.monic_X -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 := leadingCoeff_C 1 #align polynomial.leading_coeff_one Polynomial.leadingCoeff_one @[simp] theorem monic_one : Monic (1 : R[X]) := leadingCoeff_C _ #align polynomial.monic_one Polynomial.monic_one theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) : p ≠ 0 := by rintro rfl simp [Monic] at hp #align polynomial.monic.ne_zero Polynomial.Monic.ne_zero theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by nontriviality R exact hp.ne_zero #align polynomial.monic.ne_zero_of_ne Polynomial.Monic.ne_zero_of_ne theorem monic_of_natDegree_le_of_coeff_eq_one (n : ℕ) (pn : p.natDegree ≤ n) (p1 : p.coeff n = 1) : Monic p := by unfold Monic nontriviality refine (congr_arg _ <| natDegree_eq_of_le_of_coeff_ne_zero pn ?_).trans p1 exact ne_of_eq_of_ne p1 one_ne_zero #align polynomial.monic_of_nat_degree_le_of_coeff_eq_one Polynomial.monic_of_natDegree_le_of_coeff_eq_one theorem monic_of_degree_le_of_coeff_eq_one (n : ℕ) (pn : p.degree ≤ n) (p1 : p.coeff n = 1) : Monic p := monic_of_natDegree_le_of_coeff_eq_one n (natDegree_le_of_degree_le pn) p1 #align polynomial.monic_of_degree_le_of_coeff_eq_one Polynomial.monic_of_degree_le_of_coeff_eq_one theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 := haveI := Nontrivial.of_polynomial_ne hne hp.ne_zero #align polynomial.monic.ne_zero_of_polynomial_ne Polynomial.Monic.ne_zero_of_polynomial_ne theorem leadingCoeff_add_of_degree_lt (h : degree p < degree q) : leadingCoeff (p + q) = leadingCoeff q := by have : coeff p (natDegree q) = 0 := coeff_natDegree_eq_zero_of_degree_lt h simp only [leadingCoeff, natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h), this, coeff_add, zero_add] #align polynomial.leading_coeff_add_of_degree_lt Polynomial.leadingCoeff_add_of_degree_lt theorem leadingCoeff_add_of_degree_lt' (h : degree q < degree p) : leadingCoeff (p + q) = leadingCoeff p := by rw [add_comm] exact leadingCoeff_add_of_degree_lt h theorem leadingCoeff_add_of_degree_eq (h : degree p = degree q) (hlc : leadingCoeff p + leadingCoeff q ≠ 0) : leadingCoeff (p + q) = leadingCoeff p + leadingCoeff q := by have : natDegree (p + q) = natDegree p := by apply natDegree_eq_of_degree_eq rw [degree_add_eq_of_leadingCoeff_add_ne_zero hlc, h, max_self] simp only [leadingCoeff, this, natDegree_eq_of_degree_eq h, coeff_add] #align polynomial.leading_coeff_add_of_degree_eq Polynomial.leadingCoeff_add_of_degree_eq @[simp] theorem coeff_mul_degree_add_degree (p q : R[X]) : coeff (p * q) (natDegree p + natDegree q) = leadingCoeff p * leadingCoeff q := calc coeff (p * q) (natDegree p + natDegree q) = ∑ x ∈ antidiagonal (natDegree p + natDegree q), coeff p x.1 * coeff q x.2 := coeff_mul _ _ _ _ = coeff p (natDegree p) * coeff q (natDegree q) := by refine Finset.sum_eq_single (natDegree p, natDegree q) ?_ ?_ · rintro ⟨i, j⟩ h₁ h₂ rw [mem_antidiagonal] at h₁ by_cases H : natDegree p < i · rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 H)), zero_mul] · rw [not_lt_iff_eq_or_lt] at H cases' H with H H · subst H rw [add_left_cancel_iff] at h₁ dsimp at h₁ subst h₁ exact (h₂ rfl).elim · suffices natDegree q < j by rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 this)), mul_zero] by_contra! H' exact ne_of_lt (Nat.lt_of_lt_of_le (Nat.add_lt_add_right H j) (Nat.add_le_add_left H' _)) h₁ · intro H exfalso apply H rw [mem_antidiagonal] #align polynomial.coeff_mul_degree_add_degree Polynomial.coeff_mul_degree_add_degree theorem degree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : degree (p * q) = degree p + degree q := have hp : p ≠ 0 := by refine mt ?_ h; exact fun hp => by rw [hp, leadingCoeff_zero, zero_mul] have hq : q ≠ 0 := by refine mt ?_ h; exact fun hq => by rw [hq, leadingCoeff_zero, mul_zero] le_antisymm (degree_mul_le _ _) (by rw [degree_eq_natDegree hp, degree_eq_natDegree hq] refine le_degree_of_ne_zero (n := natDegree p + natDegree q) ?_ rwa [coeff_mul_degree_add_degree]) #align polynomial.degree_mul' Polynomial.degree_mul' theorem Monic.degree_mul (hq : Monic q) : degree (p * q) = degree p + degree q := letI := Classical.decEq R if hp : p = 0 then by simp [hp] else degree_mul' <| by rwa [hq.leadingCoeff, mul_one, Ne, leadingCoeff_eq_zero] #align polynomial.monic.degree_mul Polynomial.Monic.degree_mul theorem natDegree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : natDegree (p * q) = natDegree p + natDegree q := have hp : p ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, zero_mul] have hq : q ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, mul_zero] natDegree_eq_of_degree_eq_some <| by rw [degree_mul' h, Nat.cast_add, degree_eq_natDegree hp, degree_eq_natDegree hq] #align polynomial.nat_degree_mul' Polynomial.natDegree_mul' theorem leadingCoeff_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : leadingCoeff (p * q) = leadingCoeff p * leadingCoeff q := by unfold leadingCoeff rw [natDegree_mul' h, coeff_mul_degree_add_degree] rfl #align polynomial.leading_coeff_mul' Polynomial.leadingCoeff_mul' theorem monomial_natDegree_leadingCoeff_eq_self (h : p.support.card ≤ 1) : monomial p.natDegree p.leadingCoeff = p := by classical rcases card_support_le_one_iff_monomial.1 h with ⟨n, a, rfl⟩ by_cases ha : a = 0 <;> simp [ha] #align polynomial.monomial_nat_degree_leading_coeff_eq_self Polynomial.monomial_natDegree_leadingCoeff_eq_self theorem C_mul_X_pow_eq_self (h : p.support.card ≤ 1) : C p.leadingCoeff * X ^ p.natDegree = p := by rw [C_mul_X_pow_eq_monomial, monomial_natDegree_leadingCoeff_eq_self h] #align polynomial.C_mul_X_pow_eq_self Polynomial.C_mul_X_pow_eq_self theorem leadingCoeff_pow' : leadingCoeff p ^ n ≠ 0 → leadingCoeff (p ^ n) = leadingCoeff p ^ n := Nat.recOn n (by simp) fun n ih h => by have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul] have h₂ : leadingCoeff p * leadingCoeff (p ^ n) ≠ 0 := by rwa [pow_succ', ← ih h₁] at h rw [pow_succ', pow_succ', leadingCoeff_mul' h₂, ih h₁] #align polynomial.leading_coeff_pow' Polynomial.leadingCoeff_pow' theorem degree_pow' : ∀ {n : ℕ}, leadingCoeff p ^ n ≠ 0 → degree (p ^ n) = n • degree p | 0 => fun h => by rw [pow_zero, ← C_1] at *; rw [degree_C h, zero_nsmul] | n + 1 => fun h => by have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul] have h₂ : leadingCoeff (p ^ n) * leadingCoeff p ≠ 0 := by rwa [pow_succ, ← leadingCoeff_pow' h₁] at h rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁] #align polynomial.degree_pow' Polynomial.degree_pow' theorem natDegree_pow' {n : ℕ} (h : leadingCoeff p ^ n ≠ 0) : natDegree (p ^ n) = n * natDegree p := letI := Classical.decEq R if hp0 : p = 0 then if hn0 : n = 0 then by simp [*] else by rw [hp0, zero_pow hn0]; simp else have hpn : p ^ n ≠ 0 := fun hpn0 => by have h1 := h rw [← leadingCoeff_pow' h1, hpn0, leadingCoeff_zero] at h; exact h rfl Option.some_inj.1 <| show (natDegree (p ^ n) : WithBot ℕ) = (n * natDegree p : ℕ) by rw [← degree_eq_natDegree hpn, degree_pow' h, degree_eq_natDegree hp0]; simp #align polynomial.nat_degree_pow' Polynomial.natDegree_pow' theorem leadingCoeff_monic_mul {p q : R[X]} (hp : Monic p) : leadingCoeff (p * q) = leadingCoeff q := by rcases eq_or_ne q 0 with (rfl | H) · simp · rw [leadingCoeff_mul', hp.leadingCoeff, one_mul] rwa [hp.leadingCoeff, one_mul, Ne, leadingCoeff_eq_zero] #align polynomial.leading_coeff_monic_mul Polynomial.leadingCoeff_monic_mul theorem leadingCoeff_mul_monic {p q : R[X]} (hq : Monic q) : leadingCoeff (p * q) = leadingCoeff p := letI := Classical.decEq R Decidable.byCases (fun H : leadingCoeff p = 0 => by rw [H, leadingCoeff_eq_zero.1 H, zero_mul, leadingCoeff_zero]) fun H : leadingCoeff p ≠ 0 => by rw [leadingCoeff_mul', hq.leadingCoeff, mul_one] rwa [hq.leadingCoeff, mul_one] #align polynomial.leading_coeff_mul_monic Polynomial.leadingCoeff_mul_monic @[simp] theorem leadingCoeff_mul_X_pow {p : R[X]} {n : ℕ} : leadingCoeff (p * X ^ n) = leadingCoeff p := leadingCoeff_mul_monic (monic_X_pow n) #align polynomial.leading_coeff_mul_X_pow Polynomial.leadingCoeff_mul_X_pow @[simp] theorem leadingCoeff_mul_X {p : R[X]} : leadingCoeff (p * X) = leadingCoeff p := leadingCoeff_mul_monic monic_X #align polynomial.leading_coeff_mul_X Polynomial.leadingCoeff_mul_X theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by apply natDegree_le_of_degree_le apply le_trans (degree_mul_le p q) rw [Nat.cast_add] apply add_le_add <;> apply degree_le_natDegree #align polynomial.nat_degree_mul_le Polynomial.natDegree_mul_le theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) : natDegree (p * q) ≤ m + n := natDegree_mul_le.trans <| add_le_add ‹_› ‹_› theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by induction' n with i hi · simp · rw [pow_succ, Nat.succ_mul] apply le_trans natDegree_mul_le exact add_le_add_right hi _ #align polynomial.nat_degree_pow_le Polynomial.natDegree_pow_le theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) : natDegree (p ^ n) ≤ n * m := natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›) @[simp] theorem coeff_pow_mul_natDegree (p : R[X]) (n : ℕ) : (p ^ n).coeff (n * p.natDegree) = p.leadingCoeff ^ n := by induction' n with i hi · simp · rw [pow_succ, pow_succ, Nat.succ_mul] by_cases hp1 : p.leadingCoeff ^ i = 0 · rw [hp1, zero_mul] by_cases hp2 : p ^ i = 0 · rw [hp2, zero_mul, coeff_zero] · apply coeff_eq_zero_of_natDegree_lt have h1 : (p ^ i).natDegree < i * p.natDegree := by refine lt_of_le_of_ne natDegree_pow_le fun h => hp2 ?_ rw [← h, hp1] at hi exact leadingCoeff_eq_zero.mp hi calc (p ^ i * p).natDegree ≤ (p ^ i).natDegree + p.natDegree := natDegree_mul_le _ < i * p.natDegree + p.natDegree := add_lt_add_right h1 _ · rw [← natDegree_pow' hp1, ← leadingCoeff_pow' hp1] exact coeff_mul_degree_add_degree _ _ #align polynomial.coeff_pow_mul_nat_degree Polynomial.coeff_pow_mul_natDegree theorem coeff_mul_add_eq_of_natDegree_le {df dg : ℕ} {f g : R[X]} (hdf : natDegree f ≤ df) (hdg : natDegree g ≤ dg) : (f * g).coeff (df + dg) = f.coeff df * g.coeff dg := by rw [coeff_mul, Finset.sum_eq_single_of_mem (df, dg)] · rw [mem_antidiagonal] rintro ⟨df', dg'⟩ hmem hne obtain h | hdf' := lt_or_le df df' · rw [coeff_eq_zero_of_natDegree_lt (hdf.trans_lt h), zero_mul] obtain h | hdg' := lt_or_le dg dg' · rw [coeff_eq_zero_of_natDegree_lt (hdg.trans_lt h), mul_zero] obtain ⟨rfl, rfl⟩ := (add_eq_add_iff_eq_and_eq hdf' hdg').mp (mem_antidiagonal.1 hmem) exact (hne rfl).elim theorem zero_le_degree_iff : 0 ≤ degree p ↔ p ≠ 0 := by rw [← not_lt, Nat.WithBot.lt_zero_iff, degree_eq_bot] #align polynomial.zero_le_degree_iff Polynomial.zero_le_degree_iff theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero] #align polynomial.nat_degree_eq_zero_iff_degree_le_zero Polynomial.natDegree_eq_zero_iff_degree_le_zero theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) : degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by -- Porting note: `Nat.cast_withBot` is required. simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le, not_imp_comm, Nat.cast_withBot] #align polynomial.degree_le_iff_coeff_zero Polynomial.degree_le_iff_coeff_zero theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) : degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff, WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not] #align polynomial.degree_lt_iff_coeff_zero Polynomial.degree_lt_iff_coeff_zero theorem degree_smul_le (a : R) (p : R[X]) : degree (a • p) ≤ degree p := by refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_ rw [degree_lt_iff_coeff_zero] at hm simp [hm m le_rfl] #align polynomial.degree_smul_le Polynomial.degree_smul_le theorem natDegree_smul_le (a : R) (p : R[X]) : natDegree (a • p) ≤ natDegree p := natDegree_le_natDegree (degree_smul_le a p) #align polynomial.nat_degree_smul_le Polynomial.natDegree_smul_le theorem degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree := by haveI := Nontrivial.of_polynomial_ne hp have : leadingCoeff p * leadingCoeff X ≠ 0 := by simpa erw [degree_mul' this, degree_eq_natDegree hp, degree_X, ← WithBot.coe_one, ← WithBot.coe_add, WithBot.coe_lt_coe]; exact Nat.lt_succ_self _ #align polynomial.degree_lt_degree_mul_X Polynomial.degree_lt_degree_mul_X theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p := lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le #align polynomial.nat_degree_pos_iff_degree_pos Polynomial.natDegree_pos_iff_degree_pos theorem eq_C_of_natDegree_le_zero (h : natDegree p ≤ 0) : p = C (coeff p 0) := eq_C_of_degree_le_zero <| degree_le_of_natDegree_le h #align polynomial.eq_C_of_nat_degree_le_zero Polynomial.eq_C_of_natDegree_le_zero theorem eq_C_of_natDegree_eq_zero (h : natDegree p = 0) : p = C (coeff p 0) := eq_C_of_natDegree_le_zero h.le #align polynomial.eq_C_of_nat_degree_eq_zero Polynomial.eq_C_of_natDegree_eq_zero lemma natDegree_eq_zero {p : R[X]} : p.natDegree = 0 ↔ ∃ x, C x = p := ⟨fun h ↦ ⟨_, (eq_C_of_natDegree_eq_zero h).symm⟩, by aesop⟩ theorem eq_C_coeff_zero_iff_natDegree_eq_zero : p = C (p.coeff 0) ↔ p.natDegree = 0 := ⟨fun h ↦ by rw [h, natDegree_C], eq_C_of_natDegree_eq_zero⟩ theorem eq_one_of_monic_natDegree_zero (hf : p.Monic) (hfd : p.natDegree = 0) : p = 1 := by rw [Monic.def, leadingCoeff, hfd] at hf rw [eq_C_of_natDegree_eq_zero hfd, hf, map_one] theorem ne_zero_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : p ≠ 0 := zero_le_degree_iff.mp <| (WithBot.coe_le_coe.mpr n.zero_le).trans hdeg #align polynomial.ne_zero_of_coe_le_degree Polynomial.ne_zero_of_coe_le_degree theorem le_natDegree_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : n ≤ p.natDegree := -- Porting note: `.. ▸ ..` → `rwa [..] at ..` WithBot.coe_le_coe.mp <| by rwa [degree_eq_natDegree <| ne_zero_of_coe_le_degree hdeg] at hdeg #align polynomial.le_nat_degree_of_coe_le_degree Polynomial.le_natDegree_of_coe_le_degree theorem degree_sum_fin_lt {n : ℕ} (f : Fin n → R) : degree (∑ i : Fin n, C (f i) * X ^ (i : ℕ)) < n := (degree_sum_le _ _).trans_lt <| (Finset.sup_lt_iff <| WithBot.bot_lt_coe n).2 fun k _hk => (degree_C_mul_X_pow_le _ _).trans_lt <| WithBot.coe_lt_coe.2 k.is_lt #align polynomial.degree_sum_fin_lt Polynomial.degree_sum_fin_lt theorem degree_linear_le : degree (C a * X + C b) ≤ 1 := degree_add_le_of_degree_le (degree_C_mul_X_le _) <| le_trans degree_C_le Nat.WithBot.coe_nonneg #align polynomial.degree_linear_le Polynomial.degree_linear_le theorem degree_linear_lt : degree (C a * X + C b) < 2 := degree_linear_le.trans_lt <| WithBot.coe_lt_coe.mpr one_lt_two #align polynomial.degree_linear_lt Polynomial.degree_linear_lt theorem degree_C_lt_degree_C_mul_X (ha : a ≠ 0) : degree (C b) < degree (C a * X) := by simpa only [degree_C_mul_X ha] using degree_C_lt #align polynomial.degree_C_lt_degree_C_mul_X Polynomial.degree_C_lt_degree_C_mul_X @[simp] theorem degree_linear (ha : a ≠ 0) : degree (C a * X + C b) = 1 := by rw [degree_add_eq_left_of_degree_lt <| degree_C_lt_degree_C_mul_X ha, degree_C_mul_X ha] #align polynomial.degree_linear Polynomial.degree_linear theorem natDegree_linear_le : natDegree (C a * X + C b) ≤ 1 := natDegree_le_of_degree_le degree_linear_le #align polynomial.nat_degree_linear_le Polynomial.natDegree_linear_le theorem natDegree_linear (ha : a ≠ 0) : natDegree (C a * X + C b) = 1 := by rw [natDegree_add_C, natDegree_C_mul_X a ha] #align polynomial.nat_degree_linear Polynomial.natDegree_linear @[simp] theorem leadingCoeff_linear (ha : a ≠ 0) : leadingCoeff (C a * X + C b) = a := by rw [add_comm, leadingCoeff_add_of_degree_lt (degree_C_lt_degree_C_mul_X ha), leadingCoeff_C_mul_X] #align polynomial.leading_coeff_linear Polynomial.leadingCoeff_linear theorem degree_quadratic_le : degree (C a * X ^ 2 + C b * X + C c) ≤ 2 := by simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 2 a) (le_trans degree_linear_le <| WithBot.coe_le_coe.mpr one_le_two) #align polynomial.degree_quadratic_le Polynomial.degree_quadratic_le theorem degree_quadratic_lt : degree (C a * X ^ 2 + C b * X + C c) < 3 := degree_quadratic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 2 #align polynomial.degree_quadratic_lt Polynomial.degree_quadratic_lt theorem degree_linear_lt_degree_C_mul_X_sq (ha : a ≠ 0) : degree (C b * X + C c) < degree (C a * X ^ 2) := by simpa only [degree_C_mul_X_pow 2 ha] using degree_linear_lt #align polynomial.degree_linear_lt_degree_C_mul_X_sq Polynomial.degree_linear_lt_degree_C_mul_X_sq @[simp] theorem degree_quadratic (ha : a ≠ 0) : degree (C a * X ^ 2 + C b * X + C c) = 2 := by rw [add_assoc, degree_add_eq_left_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha, degree_C_mul_X_pow 2 ha] rfl #align polynomial.degree_quadratic Polynomial.degree_quadratic theorem natDegree_quadratic_le : natDegree (C a * X ^ 2 + C b * X + C c) ≤ 2 := natDegree_le_of_degree_le degree_quadratic_le #align polynomial.nat_degree_quadratic_le Polynomial.natDegree_quadratic_le theorem natDegree_quadratic (ha : a ≠ 0) : natDegree (C a * X ^ 2 + C b * X + C c) = 2 := natDegree_eq_of_degree_eq_some <| degree_quadratic ha #align polynomial.nat_degree_quadratic Polynomial.natDegree_quadratic @[simp] theorem leadingCoeff_quadratic (ha : a ≠ 0) : leadingCoeff (C a * X ^ 2 + C b * X + C c) = a := by rw [add_assoc, add_comm, leadingCoeff_add_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha, leadingCoeff_C_mul_X_pow] #align polynomial.leading_coeff_quadratic Polynomial.leadingCoeff_quadratic theorem degree_cubic_le : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 := by simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 3 a) (le_trans degree_quadratic_le <| WithBot.coe_le_coe.mpr <| Nat.le_succ 2) #align polynomial.degree_cubic_le Polynomial.degree_cubic_le theorem degree_cubic_lt : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) < 4 := degree_cubic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 3 #align polynomial.degree_cubic_lt Polynomial.degree_cubic_lt theorem degree_quadratic_lt_degree_C_mul_X_cb (ha : a ≠ 0) : degree (C b * X ^ 2 + C c * X + C d) < degree (C a * X ^ 3) := by simpa only [degree_C_mul_X_pow 3 ha] using degree_quadratic_lt #align polynomial.degree_quadratic_lt_degree_C_mul_X_cb Polynomial.degree_quadratic_lt_degree_C_mul_X_cb @[simp] theorem degree_cubic (ha : a ≠ 0) : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 := by rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), degree_add_eq_left_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha, degree_C_mul_X_pow 3 ha] rfl #align polynomial.degree_cubic Polynomial.degree_cubic theorem natDegree_cubic_le : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 := natDegree_le_of_degree_le degree_cubic_le #align polynomial.nat_degree_cubic_le Polynomial.natDegree_cubic_le theorem natDegree_cubic (ha : a ≠ 0) : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 := natDegree_eq_of_degree_eq_some <| degree_cubic ha #align polynomial.nat_degree_cubic Polynomial.natDegree_cubic @[simp] theorem leadingCoeff_cubic (ha : a ≠ 0) : leadingCoeff (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = a := by rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), add_comm, leadingCoeff_add_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha, leadingCoeff_C_mul_X_pow] #align polynomial.leading_coeff_cubic Polynomial.leadingCoeff_cubic end Semiring section NontrivialSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ) @[simp] theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)] #align polynomial.degree_X_pow Polynomial.degree_X_pow @[simp] theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n := natDegree_eq_of_degree_eq_some (degree_X_pow n) #align polynomial.nat_degree_X_pow Polynomial.natDegree_X_pow @[simp] lemma natDegree_mul_X (hp : p ≠ 0) : natDegree (p * X) = natDegree p + 1 := by rw [natDegree_mul' (by simpa), natDegree_X] @[simp] lemma natDegree_X_mul (hp : p ≠ 0) : natDegree (X * p) = natDegree p + 1 := by rw [commute_X p, natDegree_mul_X hp] @[simp] lemma natDegree_mul_X_pow (hp : p ≠ 0) : natDegree (p * X ^ n) = natDegree p + n := by rw [natDegree_mul' (by simpa), natDegree_X_pow] @[simp] lemma natDegree_X_pow_mul (hp : p ≠ 0) : natDegree (X ^ n * p) = natDegree p + n := by rw [commute_X_pow, natDegree_mul_X_pow n hp] -- This lemma explicitly does not require the `Nontrivial R` assumption. theorem natDegree_X_pow_le {R : Type*} [Semiring R] (n : ℕ) : (X ^ n : R[X]).natDegree ≤ n := by nontriviality R rw [Polynomial.natDegree_X_pow] #align polynomial.nat_degree_X_pow_le Polynomial.natDegree_X_pow_le theorem not_isUnit_X : ¬IsUnit (X : R[X]) := fun ⟨⟨_, g, _hfg, hgf⟩, rfl⟩ => zero_ne_one' R <| by rw [← coeff_one_zero, ← hgf] simp #align polynomial.not_is_unit_X Polynomial.not_isUnit_X @[simp] theorem degree_mul_X : degree (p * X) = degree p + 1 := by simp [monic_X.degree_mul] #align polynomial.degree_mul_X Polynomial.degree_mul_X @[simp] theorem degree_mul_X_pow : degree (p * X ^ n) = degree p + n := by simp [(monic_X_pow n).degree_mul] #align polynomial.degree_mul_X_pow Polynomial.degree_mul_X_pow end NontrivialSemiring section Ring variable [Ring R] {p q : R[X]} theorem degree_sub_C (hp : 0 < degree p) : degree (p - C a) = degree p := by rw [sub_eq_add_neg, ← C_neg, degree_add_C hp] @[simp] theorem natDegree_sub_C {a : R} : natDegree (p - C a) = natDegree p := by rw [sub_eq_add_neg, ← C_neg, natDegree_add_C] theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by simpa only [degree_neg q] using degree_add_le p (-q) #align polynomial.degree_sub_le Polynomial.degree_sub_le theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p - q) ≤ max a b := (p.degree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem leadingCoeff_sub_of_degree_lt (h : Polynomial.degree q < Polynomial.degree p) : (p - q).leadingCoeff = p.leadingCoeff := by rw [← q.degree_neg] at h rw [sub_eq_add_neg, leadingCoeff_add_of_degree_lt' h] theorem leadingCoeff_sub_of_degree_lt' (h : Polynomial.degree p < Polynomial.degree q) : (p - q).leadingCoeff = -q.leadingCoeff := by rw [← q.degree_neg] at h rw [sub_eq_add_neg, leadingCoeff_add_of_degree_lt h, leadingCoeff_neg] theorem leadingCoeff_sub_of_degree_eq (h : degree p = degree q) (hlc : leadingCoeff p ≠ leadingCoeff q) : leadingCoeff (p - q) = leadingCoeff p - leadingCoeff q := by replace h : degree p = degree (-q) := by rwa [q.degree_neg] replace hlc : leadingCoeff p + leadingCoeff (-q) ≠ 0 := by rwa [← sub_ne_zero, sub_eq_add_neg, ← q.leadingCoeff_neg] at hlc rw [sub_eq_add_neg, leadingCoeff_add_of_degree_eq h hlc, leadingCoeff_neg, sub_eq_add_neg] theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by simpa only [← natDegree_neg q] using natDegree_add_le p (-q) #align polynomial.nat_degree_sub_le Polynomial.natDegree_sub_le theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p - q) ≤ max m n := (p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0) (hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p := have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p := monomial_add_erase _ _ have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q := monomial_add_erase _ _ have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd] have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0) calc degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by conv => lhs rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg] _ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) := (degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _) _ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩ #align polynomial.degree_sub_lt Polynomial.degree_sub_lt theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 := (degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one)) #align polynomial.degree_X_sub_C_le Polynomial.degree_X_sub_C_le theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 := natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r #align polynomial.nat_degree_X_sub_C_le Polynomial.natDegree_X_sub_C_le theorem degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p := by rw [← degree_neg q] at h rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h] #align polynomial.degree_sub_eq_left_of_degree_lt Polynomial.degree_sub_eq_left_of_degree_lt theorem degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q := by rw [← degree_neg q] at h rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg] #align polynomial.degree_sub_eq_right_of_degree_lt Polynomial.degree_sub_eq_right_of_degree_lt theorem natDegree_sub_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) : natDegree (p - q) = natDegree p := natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_sub_eq_left_of_nat_degree_lt Polynomial.natDegree_sub_eq_left_of_natDegree_lt theorem natDegree_sub_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) : natDegree (p - q) = natDegree q := natDegree_eq_of_degree_eq (degree_sub_eq_right_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_sub_eq_right_of_nat_degree_lt Polynomial.natDegree_sub_eq_right_of_natDegree_lt end Ring section NonzeroRing variable [Nontrivial R] section Semiring variable [Semiring R] @[simp] theorem degree_X_add_C (a : R) : degree (X + C a) = 1 := by have : degree (C a) < degree (X : R[X]) := calc degree (C a) ≤ 0 := degree_C_le _ < 1 := WithBot.coe_lt_coe.mpr zero_lt_one _ = degree X := degree_X.symm rw [degree_add_eq_left_of_degree_lt this, degree_X] #align polynomial.degree_X_add_C Polynomial.degree_X_add_C theorem natDegree_X_add_C (x : R) : (X + C x).natDegree = 1 := natDegree_eq_of_degree_eq_some <| degree_X_add_C x #align polynomial.nat_degree_X_add_C Polynomial.natDegree_X_add_C @[simp] theorem nextCoeff_X_add_C [Semiring S] (c : S) : nextCoeff (X + C c) = c := by nontriviality S simp [nextCoeff_of_natDegree_pos] #align polynomial.next_coeff_X_add_C Polynomial.nextCoeff_X_add_C theorem degree_X_pow_add_C {n : ℕ} (hn : 0 < n) (a : R) : degree ((X : R[X]) ^ n + C a) = n := by have : degree (C a) < degree ((X : R[X]) ^ n) := degree_C_le.trans_lt <| by rwa [degree_X_pow, Nat.cast_pos] rw [degree_add_eq_left_of_degree_lt this, degree_X_pow] #align polynomial.degree_X_pow_add_C Polynomial.degree_X_pow_add_C theorem X_pow_add_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a ≠ 0 := mt degree_eq_bot.2 (show degree ((X : R[X]) ^ n + C a) ≠ ⊥ by rw [degree_X_pow_add_C hn a]; exact WithBot.coe_ne_bot) #align polynomial.X_pow_add_C_ne_zero Polynomial.X_pow_add_C_ne_zero theorem X_add_C_ne_zero (r : R) : X + C r ≠ 0 := pow_one (X : R[X]) ▸ X_pow_add_C_ne_zero zero_lt_one r #align polynomial.X_add_C_ne_zero Polynomial.X_add_C_ne_zero theorem zero_nmem_multiset_map_X_add_C {α : Type*} (m : Multiset α) (f : α → R) : (0 : R[X]) ∉ m.map fun a => X + C (f a) := fun mem => let ⟨_a, _, ha⟩ := Multiset.mem_map.mp mem X_add_C_ne_zero _ ha #align polynomial.zero_nmem_multiset_map_X_add_C Polynomial.zero_nmem_multiset_map_X_add_C theorem natDegree_X_pow_add_C {n : ℕ} {r : R} : (X ^ n + C r).natDegree = n := by by_cases hn : n = 0 · rw [hn, pow_zero, ← C_1, ← RingHom.map_add, natDegree_C] · exact natDegree_eq_of_degree_eq_some (degree_X_pow_add_C (pos_iff_ne_zero.mpr hn) r) #align polynomial.nat_degree_X_pow_add_C Polynomial.natDegree_X_pow_add_C theorem X_pow_add_C_ne_one {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a ≠ 1 := fun h => hn.ne' <| by simpa only [natDegree_X_pow_add_C, natDegree_one] using congr_arg natDegree h #align polynomial.X_pow_add_C_ne_one Polynomial.X_pow_add_C_ne_one theorem X_add_C_ne_one (r : R) : X + C r ≠ 1 := pow_one (X : R[X]) ▸ X_pow_add_C_ne_one zero_lt_one r #align polynomial.X_add_C_ne_one Polynomial.X_add_C_ne_one end Semiring end NonzeroRing section Semiring variable [Semiring R] @[simp] theorem leadingCoeff_X_pow_add_C {n : ℕ} (hn : 0 < n) {r : R} : (X ^ n + C r).leadingCoeff = 1 := by nontriviality R rw [leadingCoeff, natDegree_X_pow_add_C, coeff_add, coeff_X_pow_self, coeff_C, if_neg (pos_iff_ne_zero.mp hn), add_zero] #align polynomial.leading_coeff_X_pow_add_C Polynomial.leadingCoeff_X_pow_add_C @[simp] theorem leadingCoeff_X_add_C [Semiring S] (r : S) : (X + C r).leadingCoeff = 1 := by rw [← pow_one (X : S[X]), leadingCoeff_X_pow_add_C zero_lt_one] #align polynomial.leading_coeff_X_add_C Polynomial.leadingCoeff_X_add_C @[simp] theorem leadingCoeff_X_pow_add_one {n : ℕ} (hn : 0 < n) : (X ^ n + 1 : R[X]).leadingCoeff = 1 := leadingCoeff_X_pow_add_C hn #align polynomial.leading_coeff_X_pow_add_one Polynomial.leadingCoeff_X_pow_add_one @[simp] theorem leadingCoeff_pow_X_add_C (r : R) (i : ℕ) : leadingCoeff ((X + C r) ^ i) = 1 := by nontriviality rw [leadingCoeff_pow'] <;> simp #align polynomial.leading_coeff_pow_X_add_C Polynomial.leadingCoeff_pow_X_add_C end Semiring section Ring variable [Ring R] @[simp]
Mathlib/Algebra/Polynomial/Degree/Definitions.lean
1,587
1,589
theorem leadingCoeff_X_pow_sub_C {n : ℕ} (hn : 0 < n) {r : R} : (X ^ n - C r).leadingCoeff = 1 := by
rw [sub_eq_add_neg, ← map_neg C r, leadingCoeff_X_pow_add_C hn]
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Computation.Approximations import Mathlib.Algebra.ContinuedFractions.Computation.CorrectnessTerminating import Mathlib.Data.Rat.Floor #align_import algebra.continued_fractions.computation.terminates_iff_rat from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad" /-! # Termination of Continued Fraction Computations (`GeneralizedContinuedFraction.of`) ## Summary We show that the continued fraction for a value `v`, as defined in `Mathlib.Algebra.ContinuedFractions.Basic`, terminates if and only if `v` corresponds to a rational number, that is `↑v = q` for some `q : ℚ`. ## Main Theorems - `GeneralizedContinuedFraction.coe_of_rat_eq` shows that `GeneralizedContinuedFraction.of v = GeneralizedContinuedFraction.of q` for `v : α` given that `↑v = q` and `q : ℚ`. - `GeneralizedContinuedFraction.terminates_iff_rat` shows that `GeneralizedContinuedFraction.of v` terminates if and only if `↑v = q` for some `q : ℚ`. ## Tags rational, continued fraction, termination -/ namespace GeneralizedContinuedFraction open GeneralizedContinuedFraction (of) variable {K : Type*} [LinearOrderedField K] [FloorRing K] /- We will have to constantly coerce along our structures in the following proofs using their provided map functions. -/ attribute [local simp] Pair.map IntFractPair.mapFr section RatOfTerminates /-! ### Terminating Continued Fractions Are Rational We want to show that the computation of a continued fraction `GeneralizedContinuedFraction.of v` terminates if and only if `v ∈ ℚ`. In this section, we show the implication from left to right. We first show that every finite convergent corresponds to a rational number `q` and then use the finite correctness proof (`of_correctness_of_terminates`) of `GeneralizedContinuedFraction.of` to show that `v = ↑q`. -/ variable (v : K) (n : ℕ) nonrec theorem exists_gcf_pair_rat_eq_of_nth_conts_aux : ∃ conts : Pair ℚ, (of v).continuantsAux n = (conts.map (↑) : Pair K) := Nat.strong_induction_on n (by clear n let g := of v intro n IH rcases n with (_ | _ | n) -- n = 0 · suffices ∃ gp : Pair ℚ, Pair.mk (1 : K) 0 = gp.map (↑) by simpa [continuantsAux] use Pair.mk 1 0 simp -- n = 1 · suffices ∃ conts : Pair ℚ, Pair.mk g.h 1 = conts.map (↑) by simpa [continuantsAux] use Pair.mk ⌊v⌋ 1 simp [g] -- 2 ≤ n · cases' IH (n + 1) <| lt_add_one (n + 1) with pred_conts pred_conts_eq -- invoke the IH cases' s_ppred_nth_eq : g.s.get? n with gp_n -- option.none · use pred_conts have : g.continuantsAux (n + 2) = g.continuantsAux (n + 1) := continuantsAux_stable_of_terminated (n + 1).le_succ s_ppred_nth_eq simp only [this, pred_conts_eq] -- option.some · -- invoke the IH a second time cases' IH n <| lt_of_le_of_lt n.le_succ <| lt_add_one <| n + 1 with ppred_conts ppred_conts_eq obtain ⟨a_eq_one, z, b_eq_z⟩ : gp_n.a = 1 ∧ ∃ z : ℤ, gp_n.b = (z : K) := of_part_num_eq_one_and_exists_int_part_denom_eq s_ppred_nth_eq -- finally, unfold the recurrence to obtain the required rational value. simp only [a_eq_one, b_eq_z, continuantsAux_recurrence s_ppred_nth_eq ppred_conts_eq pred_conts_eq] use nextContinuants 1 (z : ℚ) ppred_conts pred_conts cases ppred_conts; cases pred_conts simp [nextContinuants, nextNumerator, nextDenominator]) #align generalized_continued_fraction.exists_gcf_pair_rat_eq_of_nth_conts_aux GeneralizedContinuedFraction.exists_gcf_pair_rat_eq_of_nth_conts_aux theorem exists_gcf_pair_rat_eq_nth_conts : ∃ conts : Pair ℚ, (of v).continuants n = (conts.map (↑) : Pair K) := by rw [nth_cont_eq_succ_nth_cont_aux]; exact exists_gcf_pair_rat_eq_of_nth_conts_aux v <| n + 1 #align generalized_continued_fraction.exists_gcf_pair_rat_eq_nth_conts GeneralizedContinuedFraction.exists_gcf_pair_rat_eq_nth_conts theorem exists_rat_eq_nth_numerator : ∃ q : ℚ, (of v).numerators n = (q : K) := by rcases exists_gcf_pair_rat_eq_nth_conts v n with ⟨⟨a, _⟩, nth_cont_eq⟩ use a simp [num_eq_conts_a, nth_cont_eq] #align generalized_continued_fraction.exists_rat_eq_nth_numerator GeneralizedContinuedFraction.exists_rat_eq_nth_numerator theorem exists_rat_eq_nth_denominator : ∃ q : ℚ, (of v).denominators n = (q : K) := by rcases exists_gcf_pair_rat_eq_nth_conts v n with ⟨⟨_, b⟩, nth_cont_eq⟩ use b simp [denom_eq_conts_b, nth_cont_eq] #align generalized_continued_fraction.exists_rat_eq_nth_denominator GeneralizedContinuedFraction.exists_rat_eq_nth_denominator /-- Every finite convergent corresponds to a rational number. -/ theorem exists_rat_eq_nth_convergent : ∃ q : ℚ, (of v).convergents n = (q : K) := by rcases exists_rat_eq_nth_numerator v n with ⟨Aₙ, nth_num_eq⟩ rcases exists_rat_eq_nth_denominator v n with ⟨Bₙ, nth_denom_eq⟩ use Aₙ / Bₙ simp [nth_num_eq, nth_denom_eq, convergent_eq_num_div_denom] #align generalized_continued_fraction.exists_rat_eq_nth_convergent GeneralizedContinuedFraction.exists_rat_eq_nth_convergent variable {v} /-- Every terminating continued fraction corresponds to a rational number. -/ theorem exists_rat_eq_of_terminates (terminates : (of v).Terminates) : ∃ q : ℚ, v = ↑q := by obtain ⟨n, v_eq_conv⟩ : ∃ n, v = (of v).convergents n := of_correctness_of_terminates terminates obtain ⟨q, conv_eq_q⟩ : ∃ q : ℚ, (of v).convergents n = (↑q : K) := exists_rat_eq_nth_convergent v n have : v = (↑q : K) := Eq.trans v_eq_conv conv_eq_q use q, this #align generalized_continued_fraction.exists_rat_eq_of_terminates GeneralizedContinuedFraction.exists_rat_eq_of_terminates end RatOfTerminates section RatTranslation /-! ### Technical Translation Lemmas Before we can show that the continued fraction of a rational number terminates, we have to prove some technical translation lemmas. More precisely, in this section, we show that, given a rational number `q : ℚ` and value `v : K` with `v = ↑q`, the continued fraction of `q` and `v` coincide. In particular, we show that ```lean (↑(GeneralizedContinuedFraction.of q : GeneralizedContinuedFraction ℚ) : GeneralizedContinuedFraction K) = GeneralizedContinuedFraction.of v` ``` in `GeneralizedContinuedFraction.coe_of_rat_eq`. To do this, we proceed bottom-up, showing the correspondence between the basic functions involved in the Computation first and then lift the results step-by-step. -/ -- The lifting works for arbitrary linear ordered fields with a floor function. variable {v : K} {q : ℚ} (v_eq_q : v = (↑q : K)) (n : ℕ) /-! First, we show the correspondence for the very basic functions in `GeneralizedContinuedFraction.IntFractPair`. -/ namespace IntFractPair theorem coe_of_rat_eq : ((IntFractPair.of q).mapFr (↑) : IntFractPair K) = IntFractPair.of v := by simp [IntFractPair.of, v_eq_q] #align generalized_continued_fraction.int_fract_pair.coe_of_rat_eq GeneralizedContinuedFraction.IntFractPair.coe_of_rat_eq theorem coe_stream_nth_rat_eq : ((IntFractPair.stream q n).map (mapFr (↑)) : Option <| IntFractPair K) = IntFractPair.stream v n := by induction n with | zero => -- Porting note: was -- simp [IntFractPair.stream, coe_of_rat_eq v_eq_q] simp only [IntFractPair.stream, Option.map_some', coe_of_rat_eq v_eq_q] | succ n IH => rw [v_eq_q] at IH cases stream_q_nth_eq : IntFractPair.stream q n with | none => simp [IntFractPair.stream, IH.symm, v_eq_q, stream_q_nth_eq] | some ifp_n => cases' ifp_n with b fr cases' Decidable.em (fr = 0) with fr_zero fr_ne_zero · simp [IntFractPair.stream, IH.symm, v_eq_q, stream_q_nth_eq, fr_zero] · replace IH : some (IntFractPair.mk b (fr : K)) = IntFractPair.stream (↑q) n := by rwa [stream_q_nth_eq] at IH have : (fr : K)⁻¹ = ((fr⁻¹ : ℚ) : K) := by norm_cast have coe_of_fr := coe_of_rat_eq this simpa [IntFractPair.stream, IH.symm, v_eq_q, stream_q_nth_eq, fr_ne_zero] #align generalized_continued_fraction.int_fract_pair.coe_stream_nth_rat_eq GeneralizedContinuedFraction.IntFractPair.coe_stream_nth_rat_eq theorem coe_stream'_rat_eq : ((IntFractPair.stream q).map (Option.map (mapFr (↑))) : Stream' <| Option <| IntFractPair K) = IntFractPair.stream v := by funext n; exact IntFractPair.coe_stream_nth_rat_eq v_eq_q n #align generalized_continued_fraction.int_fract_pair.coe_stream_rat_eq GeneralizedContinuedFraction.IntFractPair.coe_stream'_rat_eq end IntFractPair /-! Now we lift the coercion results to the continued fraction computation. -/ theorem coe_of_h_rat_eq : (↑((of q).h : ℚ) : K) = (of v).h := by unfold of IntFractPair.seq1 rw [← IntFractPair.coe_of_rat_eq v_eq_q] simp #align generalized_continued_fraction.coe_of_h_rat_eq GeneralizedContinuedFraction.coe_of_h_rat_eq theorem coe_of_s_get?_rat_eq : (((of q).s.get? n).map (Pair.map (↑)) : Option <| Pair K) = (of v).s.get? n := by simp only [of, IntFractPair.seq1, Stream'.Seq.map_get?, Stream'.Seq.get?_tail] simp only [Stream'.Seq.get?] rw [← IntFractPair.coe_stream'_rat_eq v_eq_q] rcases succ_nth_stream_eq : IntFractPair.stream q (n + 1) with (_ | ⟨_, _⟩) <;> simp [Stream'.map, Stream'.get, succ_nth_stream_eq] #align generalized_continued_fraction.coe_of_s_nth_rat_eq GeneralizedContinuedFraction.coe_of_s_get?_rat_eq theorem coe_of_s_rat_eq : ((of q).s.map (Pair.map ((↑))) : Stream'.Seq <| Pair K) = (of v).s := by ext n; rw [← coe_of_s_get?_rat_eq v_eq_q]; rfl #align generalized_continued_fraction.coe_of_s_rat_eq GeneralizedContinuedFraction.coe_of_s_rat_eq /-- Given `(v : K), (q : ℚ), and v = q`, we have that `of q = of v` -/ theorem coe_of_rat_eq : (⟨(of q).h, (of q).s.map (Pair.map (↑))⟩ : GeneralizedContinuedFraction K) = of v := by cases' gcf_v_eq : of v with h s; subst v -- Porting note: made coercion target explicit obtain rfl : ↑⌊(q : K)⌋ = h := by injection gcf_v_eq -- Porting note: was -- simp [coe_of_h_rat_eq rfl, coe_of_s_rat_eq rfl, gcf_v_eq] simp only [gcf_v_eq, Int.cast_inj, Rat.floor_cast, of_h_eq_floor, eq_self_iff_true, Rat.cast_intCast, and_self, coe_of_h_rat_eq rfl, coe_of_s_rat_eq rfl] #align generalized_continued_fraction.coe_of_rat_eq GeneralizedContinuedFraction.coe_of_rat_eq theorem of_terminates_iff_of_rat_terminates {v : K} {q : ℚ} (v_eq_q : v = (q : K)) : (of v).Terminates ↔ (of q).Terminates := by constructor <;> intro h <;> cases' h with n h <;> use n <;> simp only [Stream'.Seq.TerminatedAt, (coe_of_s_get?_rat_eq v_eq_q n).symm] at h ⊢ <;> cases h' : (of q).s.get? n <;> simp only [h'] at h <;> -- Porting note: added trivial #align generalized_continued_fraction.of_terminates_iff_of_rat_terminates GeneralizedContinuedFraction.of_terminates_iff_of_rat_terminates end RatTranslation section TerminatesOfRat /-! ### Continued Fractions of Rationals Terminate Finally, we show that the continued fraction of a rational number terminates. The crucial insight is that, given any `q : ℚ` with `0 < q < 1`, the numerator of `Int.fract q` is smaller than the numerator of `q`. As the continued fraction computation recursively operates on the fractional part of a value `v` and `0 ≤ Int.fract v < 1`, we infer that the numerator of the fractional part in the computation decreases by at least one in each step. As `0 ≤ Int.fract v`, this process must stop after finite number of steps, and the computation hence terminates. -/ namespace IntFractPair variable {q : ℚ} {n : ℕ} /-- Shows that for any `q : ℚ` with `0 < q < 1`, the numerator of the fractional part of `IntFractPair.of q⁻¹` is smaller than the numerator of `q`. -/ theorem of_inv_fr_num_lt_num_of_pos (q_pos : 0 < q) : (IntFractPair.of q⁻¹).fr.num < q.num := Rat.fract_inv_num_lt_num_of_pos q_pos #align generalized_continued_fraction.int_fract_pair.of_inv_fr_num_lt_num_of_pos GeneralizedContinuedFraction.IntFractPair.of_inv_fr_num_lt_num_of_pos /-- Shows that the sequence of numerators of the fractional parts of the stream is strictly antitone. -/ theorem stream_succ_nth_fr_num_lt_nth_fr_num_rat {ifp_n ifp_succ_n : IntFractPair ℚ} (stream_nth_eq : IntFractPair.stream q n = some ifp_n) (stream_succ_nth_eq : IntFractPair.stream q (n + 1) = some ifp_succ_n) : ifp_succ_n.fr.num < ifp_n.fr.num := by obtain ⟨ifp_n', stream_nth_eq', ifp_n_fract_ne_zero, IntFractPair.of_eq_ifp_succ_n⟩ : ∃ ifp_n', IntFractPair.stream q n = some ifp_n' ∧ ifp_n'.fr ≠ 0 ∧ IntFractPair.of ifp_n'.fr⁻¹ = ifp_succ_n := succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq have : ifp_n = ifp_n' := by injection Eq.trans stream_nth_eq.symm stream_nth_eq' cases this rw [← IntFractPair.of_eq_ifp_succ_n] cases' nth_stream_fr_nonneg_lt_one stream_nth_eq with zero_le_ifp_n_fract ifp_n_fract_lt_one have : 0 < ifp_n.fr := lt_of_le_of_ne zero_le_ifp_n_fract <| ifp_n_fract_ne_zero.symm exact of_inv_fr_num_lt_num_of_pos this #align generalized_continued_fraction.int_fract_pair.stream_succ_nth_fr_num_lt_nth_fr_num_rat GeneralizedContinuedFraction.IntFractPair.stream_succ_nth_fr_num_lt_nth_fr_num_rat
Mathlib/Algebra/ContinuedFractions/Computation/TerminatesIffRat.lean
295
312
theorem stream_nth_fr_num_le_fr_num_sub_n_rat : ∀ {ifp_n : IntFractPair ℚ}, IntFractPair.stream q n = some ifp_n → ifp_n.fr.num ≤ (IntFractPair.of q).fr.num - n := by
induction n with | zero => intro ifp_zero stream_zero_eq have : IntFractPair.of q = ifp_zero := by injection stream_zero_eq simp [le_refl, this.symm] | succ n IH => intro ifp_succ_n stream_succ_nth_eq suffices ifp_succ_n.fr.num + 1 ≤ (IntFractPair.of q).fr.num - n by rw [Int.ofNat_succ, sub_add_eq_sub_sub] solve_by_elim [le_sub_right_of_add_le] rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with ⟨ifp_n, stream_nth_eq, -⟩ have : ifp_succ_n.fr.num < ifp_n.fr.num := stream_succ_nth_fr_num_lt_nth_fr_num_rat stream_nth_eq stream_succ_nth_eq have : ifp_succ_n.fr.num + 1 ≤ ifp_n.fr.num := Int.add_one_le_of_lt this exact le_trans this (IH stream_nth_eq)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import measure_theory.measure.measure_space from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace open scoped Classical symmDiff open Topology Filter ENNReal NNReal Interval MeasureTheory variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ #align measure_theory.ae_is_measurably_generated MeasureTheory.ae_isMeasurablyGenerated /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] #align measure_theory.ae_uIoc_iff MeasureTheory.ae_uIoc_iff theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union MeasureTheory.measure_union theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union' MeasureTheory.measure_union' theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet #align measure_theory.measure_inter_add_diff MeasureTheory.measure_inter_add_diff theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) #align measure_theory.measure_diff_add_inter MeasureTheory.measure_diff_add_inter theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl #align measure_theory.measure_union_add_inter MeasureTheory.measure_union_add_inter theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] #align measure_theory.measure_union_add_inter' MeasureTheory.measure_union_add_inter' lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs) lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet #align measure_theory.measure_add_measure_compl MeasureTheory.measure_add_measure_compl theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 #align measure_theory.measure_bUnion₀ MeasureTheory.measure_biUnion₀ theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet #align measure_theory.measure_bUnion MeasureTheory.measure_biUnion theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] #align measure_theory.measure_sUnion₀ MeasureTheory.measure_sUnion₀ theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] #align measure_theory.measure_sUnion MeasureTheory.measure_sUnion theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm #align measure_theory.measure_bUnion_finset₀ MeasureTheory.measure_biUnion_finset₀ theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet #align measure_theory.measure_bUnion_finset MeasureTheory.measure_biUnion_finset /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) #align measure_theory.tsum_meas_le_meas_Union_of_disjoint MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] #align measure_theory.tsum_measure_preimage_singleton MeasureTheory.tsum_measure_preimage_singleton lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] #align measure_theory.sum_measure_preimage_singleton MeasureTheory.sum_measure_preimage_singleton theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h #align measure_theory.measure_diff_null' MeasureTheory.measure_diff_null' theorem measure_add_diff (hs : MeasurableSet s) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union' disjoint_sdiff_right hs, union_diff_self] #align measure_theory.measure_add_diff MeasureTheory.measure_add_diff theorem measure_diff' (s : Set α) (hm : MeasurableSet t) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := Eq.symm <| ENNReal.sub_eq_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] #align measure_theory.measure_diff' MeasureTheory.measure_diff' theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : MeasurableSet s₂) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] #align measure_theory.measure_diff MeasureTheory.measure_diff theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right #align measure_theory.le_measure_diff MeasureTheory.le_measure_diff /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := (WithTop.sub_eq_top_iff.2 ⟨hμu, hμv⟩).symm _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h #align measure_theory.measure_diff_lt_of_lt_add MeasureTheory.measure_diff_lt_of_lt_add theorem measure_diff_le_iff_le_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] #align measure_theory.measure_diff_le_iff_le_add MeasureTheory.measure_diff_le_iff_le_add theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) #align measure_theory.measure_eq_measure_of_null_diff MeasureTheory.measure_eq_measure_of_null_diff theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ #align measure_theory.measure_eq_measure_of_between_null_diff MeasureTheory.measure_eq_measure_of_between_null_diff theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 #align measure_theory.measure_eq_measure_smaller_of_between_null_diff MeasureTheory.measure_eq_measure_smaller_of_between_null_diff theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 #align measure_theory.measure_eq_measure_larger_of_between_null_diff MeasureTheory.measure_eq_measure_larger_of_between_null_diff lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin #align measure_theory.measure_compl MeasureTheory.measure_compl lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ #align measure_theory.union_ae_eq_left_iff_ae_subset MeasureTheory.union_ae_eq_left_iff_ae_subset @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] #align measure_theory.union_ae_eq_right_iff_ae_subset MeasureTheory.union_ae_eq_right_iff_ae_subset theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] #align measure_theory.ae_eq_of_ae_subset_of_measure_ge MeasureTheory.ae_eq_of_ae_subset_of_measure_ge /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht #align measure_theory.ae_eq_of_subset_of_measure_ge MeasureTheory.ae_eq_of_subset_of_measure_ge theorem measure_iUnion_congr_of_subset [Countable β] {s : β → Set α} {t : β → Set α} (hsub : ∀ b, s b ⊆ t b) (h_le : ∀ b, μ (t b) ≤ μ (s b)) : μ (⋃ b, s b) = μ (⋃ b, t b) := by rcases Classical.em (∃ b, μ (t b) = ∞) with (⟨b, hb⟩ | htop) · calc μ (⋃ b, s b) = ∞ := top_unique (hb ▸ (h_le b).trans <| measure_mono <| subset_iUnion _ _) _ = μ (⋃ b, t b) := Eq.symm <| top_unique <| hb ▸ measure_mono (subset_iUnion _ _) push_neg at htop refine le_antisymm (measure_mono (iUnion_mono hsub)) ?_ set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _) · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ #align measure_theory.measure_Union_congr_of_subset MeasureTheory.measure_iUnion_congr_of_subset theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) #align measure_theory.measure_union_congr_of_subset MeasureTheory.measure_union_congr_of_subset @[simp] theorem measure_iUnion_toMeasurable [Countable β] (s : β → Set α) : μ (⋃ b, toMeasurable μ (s b)) = μ (⋃ b, s b) := Eq.symm <| measure_iUnion_congr_of_subset (fun _b => subset_toMeasurable _ _) fun _b => (measure_toMeasurable _).le #align measure_theory.measure_Union_to_measurable MeasureTheory.measure_iUnion_toMeasurable theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] #align measure_theory.measure_bUnion_to_measurable MeasureTheory.measure_biUnion_toMeasurable @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl #align measure_theory.measure_to_measurable_union MeasureTheory.measure_toMeasurable_union @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le #align measure_theory.measure_union_to_measurable MeasureTheory.measure_union_toMeasurable theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : Set.PairwiseDisjoint (↑s) t) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset H h] exact measure_mono (subset_univ _) #align measure_theory.sum_measure_le_measure_univ MeasureTheory.sum_measure_le_measure_univ theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : Pairwise (Disjoint on s)) : (∑' i, μ (s i)) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij #align measure_theory.tsum_measure_le_measure_univ MeasureTheory.tsum_measure_le_measure_univ /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact disjoint_iff_inter_eq_empty.mpr (H i j hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
436
443
theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by
contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij)
/- Copyright (c) 2022 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Eric Wieser, Jeremy Avigad, Johan Commelin -/ import Mathlib.Data.Matrix.Invertible import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.PosDef #align_import linear_algebra.matrix.schur_complement from "leanprover-community/mathlib"@"a176cb1219e300e85793d44583dede42377b51af" /-! # 2×2 block matrices and the Schur complement This file proves properties of 2×2 block matrices `[A B; C D]` that relate to the Schur complement `D - C*A⁻¹*B`. Some of the results here generalize to 2×2 matrices in a category, rather than just a ring. A few results in this direction can be found in the file `CateogryTheory.Preadditive.Biproducts`, especially the declarations `CategoryTheory.Biprod.gaussian` and `CategoryTheory.Biprod.isoElim`. Compare with `Matrix.invertibleOfFromBlocks₁₁Invertible`. ## Main results * `Matrix.det_fromBlocks₁₁`, `Matrix.det_fromBlocks₂₂`: determinant of a block matrix in terms of the Schur complement. * `Matrix.invOf_fromBlocks_zero₂₁_eq`, `Matrix.invOf_fromBlocks_zero₁₂_eq`: the inverse of a block triangular matrix. * `Matrix.isUnit_fromBlocks_zero₂₁`, `Matrix.isUnit_fromBlocks_zero₁₂`: invertibility of a block triangular matrix. * `Matrix.det_one_add_mul_comm`: the **Weinstein–Aronszajn identity**. * `Matrix.PosSemidef.fromBlocks₁₁` and `Matrix.PosSemidef.fromBlocks₂₂`: If a matrix `A` is positive definite, then `[A B; Bᴴ D]` is postive semidefinite if and only if `D - Bᴴ A⁻¹ B` is postive semidefinite. -/ variable {l m n α : Type*} namespace Matrix open scoped Matrix section CommRing variable [Fintype l] [Fintype m] [Fintype n] variable [DecidableEq l] [DecidableEq m] [DecidableEq n] variable [CommRing α] /-- LDU decomposition of a block matrix with an invertible top-left corner, using the Schur complement. -/ theorem fromBlocks_eq_of_invertible₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix l m α) (D : Matrix l n α) [Invertible A] : fromBlocks A B C D = fromBlocks 1 0 (C * ⅟ A) 1 * fromBlocks A 0 0 (D - C * ⅟ A * B) * fromBlocks 1 (⅟ A * B) 0 1 := by simp only [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, add_zero, zero_add, Matrix.one_mul, Matrix.mul_one, invOf_mul_self, Matrix.mul_invOf_self_assoc, Matrix.mul_invOf_mul_self_cancel, Matrix.mul_assoc, add_sub_cancel] #align matrix.from_blocks_eq_of_invertible₁₁ Matrix.fromBlocks_eq_of_invertible₁₁ /-- LDU decomposition of a block matrix with an invertible bottom-right corner, using the Schur complement. -/ theorem fromBlocks_eq_of_invertible₂₂ (A : Matrix l m α) (B : Matrix l n α) (C : Matrix n m α) (D : Matrix n n α) [Invertible D] : fromBlocks A B C D = fromBlocks 1 (B * ⅟ D) 0 1 * fromBlocks (A - B * ⅟ D * C) 0 0 D * fromBlocks 1 0 (⅟ D * C) 1 := (Matrix.reindex (Equiv.sumComm _ _) (Equiv.sumComm _ _)).injective <| by simpa [reindex_apply, Equiv.sumComm_symm, ← submatrix_mul_equiv _ _ _ (Equiv.sumComm n m), ← submatrix_mul_equiv _ _ _ (Equiv.sumComm n l), Equiv.sumComm_apply, fromBlocks_submatrix_sum_swap_sum_swap] using fromBlocks_eq_of_invertible₁₁ D C B A #align matrix.from_blocks_eq_of_invertible₂₂ Matrix.fromBlocks_eq_of_invertible₂₂ section Triangular /-! #### Block triangular matrices -/ /-- An upper-block-triangular matrix is invertible if its diagonal is. -/ def fromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) [Invertible A] [Invertible D] : Invertible (fromBlocks A B 0 D) := invertibleOfLeftInverse _ (fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D)) <| by simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero, Matrix.neg_mul, invOf_mul_self, Matrix.mul_invOf_mul_self_cancel, add_right_neg, fromBlocks_one] #align matrix.from_blocks_zero₂₁_invertible Matrix.fromBlocksZero₂₁Invertible /-- A lower-block-triangular matrix is invertible if its diagonal is. -/ def fromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) [Invertible A] [Invertible D] : Invertible (fromBlocks A 0 C D) := invertibleOfLeftInverse _ (fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A)) (⅟ D)) <| by -- a symmetry argument is more work than just copying the proof simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero, Matrix.neg_mul, invOf_mul_self, Matrix.mul_invOf_mul_self_cancel, add_left_neg, fromBlocks_one] #align matrix.from_blocks_zero₁₂_invertible Matrix.fromBlocksZero₁₂Invertible theorem invOf_fromBlocks_zero₂₁_eq (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) [Invertible A] [Invertible D] [Invertible (fromBlocks A B 0 D)] : ⅟ (fromBlocks A B 0 D) = fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D) := by letI := fromBlocksZero₂₁Invertible A B D convert (rfl : ⅟ (fromBlocks A B 0 D) = _) #align matrix.inv_of_from_blocks_zero₂₁_eq Matrix.invOf_fromBlocks_zero₂₁_eq theorem invOf_fromBlocks_zero₁₂_eq (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) [Invertible A] [Invertible D] [Invertible (fromBlocks A 0 C D)] : ⅟ (fromBlocks A 0 C D) = fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A)) (⅟ D) := by letI := fromBlocksZero₁₂Invertible A C D convert (rfl : ⅟ (fromBlocks A 0 C D) = _) #align matrix.inv_of_from_blocks_zero₁₂_eq Matrix.invOf_fromBlocks_zero₁₂_eq /-- Both diagonal entries of an invertible upper-block-triangular matrix are invertible (by reading off the diagonal entries of the inverse). -/ def invertibleOfFromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) [Invertible (fromBlocks A B 0 D)] : Invertible A × Invertible D where fst := invertibleOfLeftInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₁₁ <| by have := invOf_mul_self (fromBlocks A B 0 D) rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this replace := congr_arg Matrix.toBlocks₁₁ this simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.mul_zero, add_zero, ← fromBlocks_one] using this snd := invertibleOfRightInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₂₂ <| by have := mul_invOf_self (fromBlocks A B 0 D) rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this replace := congr_arg Matrix.toBlocks₂₂ this simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.zero_mul, zero_add, ← fromBlocks_one] using this #align matrix.invertible_of_from_blocks_zero₂₁_invertible Matrix.invertibleOfFromBlocksZero₂₁Invertible /-- Both diagonal entries of an invertible lower-block-triangular matrix are invertible (by reading off the diagonal entries of the inverse). -/ def invertibleOfFromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) [Invertible (fromBlocks A 0 C D)] : Invertible A × Invertible D where fst := invertibleOfRightInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₁₁ <| by have := mul_invOf_self (fromBlocks A 0 C D) rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this replace := congr_arg Matrix.toBlocks₁₁ this simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.zero_mul, add_zero, ← fromBlocks_one] using this snd := invertibleOfLeftInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₂₂ <| by have := invOf_mul_self (fromBlocks A 0 C D) rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this replace := congr_arg Matrix.toBlocks₂₂ this simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.mul_zero, zero_add, ← fromBlocks_one] using this #align matrix.invertible_of_from_blocks_zero₁₂_invertible Matrix.invertibleOfFromBlocksZero₁₂Invertible /-- `invertibleOfFromBlocksZero₂₁Invertible` and `Matrix.fromBlocksZero₂₁Invertible` form an equivalence. -/ def fromBlocksZero₂₁InvertibleEquiv (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) : Invertible (fromBlocks A B 0 D) ≃ Invertible A × Invertible D where toFun _ := invertibleOfFromBlocksZero₂₁Invertible A B D invFun i := by letI := i.1 letI := i.2 exact fromBlocksZero₂₁Invertible A B D left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align matrix.from_blocks_zero₂₁_invertible_equiv Matrix.fromBlocksZero₂₁InvertibleEquiv /-- `invertibleOfFromBlocksZero₁₂Invertible` and `Matrix.fromBlocksZero₁₂Invertible` form an equivalence. -/ def fromBlocksZero₁₂InvertibleEquiv (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) : Invertible (fromBlocks A 0 C D) ≃ Invertible A × Invertible D where toFun _ := invertibleOfFromBlocksZero₁₂Invertible A C D invFun i := by letI := i.1 letI := i.2 exact fromBlocksZero₁₂Invertible A C D left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align matrix.from_blocks_zero₁₂_invertible_equiv Matrix.fromBlocksZero₁₂InvertibleEquiv /-- An upper block-triangular matrix is invertible iff both elements of its diagonal are. This is a propositional form of `Matrix.fromBlocksZero₂₁InvertibleEquiv`. -/ @[simp] theorem isUnit_fromBlocks_zero₂₁ {A : Matrix m m α} {B : Matrix m n α} {D : Matrix n n α} : IsUnit (fromBlocks A B 0 D) ↔ IsUnit A ∧ IsUnit D := by simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod, (fromBlocksZero₂₁InvertibleEquiv _ _ _).nonempty_congr] #align matrix.is_unit_from_blocks_zero₂₁ Matrix.isUnit_fromBlocks_zero₂₁ /-- A lower block-triangular matrix is invertible iff both elements of its diagonal are. This is a propositional form of `Matrix.fromBlocksZero₁₂InvertibleEquiv` forms an `iff`. -/ @[simp] theorem isUnit_fromBlocks_zero₁₂ {A : Matrix m m α} {C : Matrix n m α} {D : Matrix n n α} : IsUnit (fromBlocks A 0 C D) ↔ IsUnit A ∧ IsUnit D := by simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod, (fromBlocksZero₁₂InvertibleEquiv _ _ _).nonempty_congr] #align matrix.is_unit_from_blocks_zero₁₂ Matrix.isUnit_fromBlocks_zero₁₂ /-- An expression for the inverse of an upper block-triangular matrix, when either both elements of diagonal are invertible, or both are not. -/ theorem inv_fromBlocks_zero₂₁_of_isUnit_iff (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) (hAD : IsUnit A ↔ IsUnit D) : (fromBlocks A B 0 D)⁻¹ = fromBlocks A⁻¹ (-(A⁻¹ * B * D⁻¹)) 0 D⁻¹ := by by_cases hA : IsUnit A · have hD := hAD.mp hA cases hA.nonempty_invertible cases hD.nonempty_invertible letI := fromBlocksZero₂₁Invertible A B D simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₂₁_eq] · have hD := hAD.not.mp hA have : ¬IsUnit (fromBlocks A B 0 D) := isUnit_fromBlocks_zero₂₁.not.mpr (not_and'.mpr fun _ => hA) simp_rw [nonsing_inv_eq_ring_inverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD, Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero] #align matrix.inv_from_blocks_zero₂₁_of_is_unit_iff Matrix.inv_fromBlocks_zero₂₁_of_isUnit_iff /-- An expression for the inverse of a lower block-triangular matrix, when either both elements of diagonal are invertible, or both are not. -/
Mathlib/LinearAlgebra/Matrix/SchurComplement.lean
220
233
theorem inv_fromBlocks_zero₁₂_of_isUnit_iff (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) (hAD : IsUnit A ↔ IsUnit D) : (fromBlocks A 0 C D)⁻¹ = fromBlocks A⁻¹ 0 (-(D⁻¹ * C * A⁻¹)) D⁻¹ := by
by_cases hA : IsUnit A · have hD := hAD.mp hA cases hA.nonempty_invertible cases hD.nonempty_invertible letI := fromBlocksZero₁₂Invertible A C D simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₁₂_eq] · have hD := hAD.not.mp hA have : ¬IsUnit (fromBlocks A 0 C D) := isUnit_fromBlocks_zero₁₂.not.mpr (not_and'.mpr fun _ => hA) simp_rw [nonsing_inv_eq_ring_inverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD, Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero]
/- 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.GroupTheory.QuotientGroup import Mathlib.RingTheory.DedekindDomain.Ideal #align_import ring_theory.class_group from "leanprover-community/mathlib"@"565eb991e264d0db702722b4bde52ee5173c9950" /-! # The ideal class group This file defines the ideal class group `ClassGroup R` of fractional ideals of `R` inside its field of fractions. ## Main definitions - `toPrincipalIdeal` sends an invertible `x : K` to an invertible fractional ideal - `ClassGroup` is the quotient of invertible fractional ideals modulo `toPrincipalIdeal.range` - `ClassGroup.mk0` sends a nonzero integral ideal in a Dedekind domain to its class ## Main results - `ClassGroup.mk0_eq_mk0_iff` shows the equivalence with the "classical" definition, where `I ~ J` iff `x I = y J` for `x y ≠ (0 : R)` ## Implementation details The definition of `ClassGroup R` involves `FractionRing R`. However, the API should be completely identical no matter the choice of field of fractions for `R`. -/ variable {R K L : Type*} [CommRing R] variable [Field K] [Field L] [DecidableEq L] variable [Algebra R K] [IsFractionRing R K] variable [Algebra K L] [FiniteDimensional K L] variable [Algebra R L] [IsScalarTower R K L] open scoped nonZeroDivisors open IsLocalization IsFractionRing FractionalIdeal Units section variable (R K) /-- `toPrincipalIdeal R K x` sends `x ≠ 0 : K` to the fractional `R`-ideal generated by `x` -/ irreducible_def toPrincipalIdeal : Kˣ →* (FractionalIdeal R⁰ K)ˣ := { toFun := fun x => ⟨spanSingleton _ x, spanSingleton _ x⁻¹, by simp only [spanSingleton_one, Units.mul_inv', spanSingleton_mul_spanSingleton], by simp only [spanSingleton_one, Units.inv_mul', spanSingleton_mul_spanSingleton]⟩ map_mul' := fun x y => ext (by simp only [Units.val_mk, Units.val_mul, spanSingleton_mul_spanSingleton]) map_one' := ext (by simp only [spanSingleton_one, Units.val_mk, Units.val_one]) } #align to_principal_ideal toPrincipalIdeal variable {R K} @[simp] theorem coe_toPrincipalIdeal (x : Kˣ) : (toPrincipalIdeal R K x : FractionalIdeal R⁰ K) = spanSingleton _ (x : K) := by simp only [toPrincipalIdeal]; rfl #align coe_to_principal_ideal coe_toPrincipalIdeal @[simp] theorem toPrincipalIdeal_eq_iff {I : (FractionalIdeal R⁰ K)ˣ} {x : Kˣ} : toPrincipalIdeal R K x = I ↔ spanSingleton R⁰ (x : K) = I := by simp only [toPrincipalIdeal]; exact Units.ext_iff #align to_principal_ideal_eq_iff toPrincipalIdeal_eq_iff
Mathlib/RingTheory/ClassGroup.lean
72
79
theorem mem_principal_ideals_iff {I : (FractionalIdeal R⁰ K)ˣ} : I ∈ (toPrincipalIdeal R K).range ↔ ∃ x : K, spanSingleton R⁰ x = I := by
simp only [MonoidHom.mem_range, toPrincipalIdeal_eq_iff] constructor <;> rintro ⟨x, hx⟩ · exact ⟨x, hx⟩ · refine ⟨Units.mk0 x ?_, hx⟩ rintro rfl simp [I.ne_zero.symm] at hx
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Aurélien Saue, Anne Baanen -/ import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Tactic.NormNum.Inv import Mathlib.Tactic.NormNum.Pow import Mathlib.Util.AtomM /-! # `ring` tactic A tactic for solving equations in commutative (semi)rings, where the exponents can also contain variables. Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> . More precisely, expressions of the following form are supported: - constants (non-negative integers) - variables - coefficients (any rational number, embedded into the (semi)ring) - addition of expressions - multiplication of expressions (`a * b`) - scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`) - exponentiation of expressions (the exponent must have type `ℕ`) - subtraction and negation of expressions (if the base is a full ring) The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved, even though it is not strictly speaking an equation in the language of commutative rings. ## Implementation notes The basic approach to prove equalities is to normalise both sides and check for equality. The normalisation is guided by building a value in the type `ExSum` at the meta level, together with a proof (at the base level) that the original value is equal to the normalised version. The outline of the file: - Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`, which can represent expressions with `+`, `*`, `^` and rational numerals. The mutual induction ensures that associativity and distributivity are applied, by restricting which kinds of subexpressions appear as arguments to the various operators. - Represent addition, multiplication and exponentiation in the `ExSum` type, thus allowing us to map expressions to `ExSum` (the `eval` function drives this). We apply associativity and distributivity of the operators here (helped by `Ex*` types) and commutativity as well (by sorting the subterms; unfortunately not helped by anything). Any expression not of the above formats is treated as an atom (the same as a variable). There are some details we glossed over which make the plan more complicated: - The order on atoms is not initially obvious. We construct a list containing them in order of initial appearance in the expression, then use the index into the list as a key to order on. - For `pow`, the exponent must be a natural number, while the base can be any semiring `α`. We swap out operations for the base ring `α` with those for the exponent ring `ℕ` as soon as we deal with exponents. ## Caveats and future work The normalized form of an expression is the one that is useful for the tactic, but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`. Subtraction cancels out identical terms, but division does not. That is: `a - a = 0 := by ring` solves the goal, but `a / a := 1 by ring` doesn't. Note that `0 / 0` is generally defined to be `0`, so division cancelling out is not true in general. Multiplication of powers can be simplified a little bit further: `2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works. This feature wasn't needed yet, so it's not implemented yet. ## Tags ring, semiring, exponent, power -/ set_option autoImplicit true namespace Mathlib.Tactic namespace Ring open Mathlib.Meta Qq NormNum Lean.Meta AtomM open Lean (MetaM Expr mkRawNatLit) /-- A shortcut instance for `CommSemiring ℕ` used by ring. -/ def instCommSemiringNat : CommSemiring ℕ := inferInstance /-- A typed expression of type `CommSemiring ℕ` used when we are working on ring subexpressions of type `ℕ`. -/ def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat) -- In this file, we would like to use multi-character auto-implicits. set_option relaxedAutoImplicit true mutual /-- The base `e` of a normalized exponent expression. -/ inductive ExBase : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- An atomic expression `e` with id `id`. Atomic expressions are those which `ring` cannot parse any further. For instance, `a + (a % b)` has `a` and `(a % b)` as atoms. The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does. Atoms in fact represent equivalence classes of expressions, modulo definitional equality. The field `index : ℕ` should be a unique number for each class, while `value : expr` contains a representative of this class. The function `resolve_atom` determines the appropriate atom for a given expression. -/ | atom (id : ℕ) : ExBase sα e /-- A sum of monomials. -/ | sum (_ : ExSum sα e) : ExBase sα e /-- A monomial, which is a product of powers of `ExBase` expressions, terminated by a (nonzero) constant coefficient. -/ inductive ExProd : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast. If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/ | const (value : ℚ) (hyp : Option Expr := none) : ExProd sα e /-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase` and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/ | mul {α : Q(Type u)} {sα : Q(CommSemiring $α)} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} : ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b) /-- A polynomial expression, which is a sum of monomials. -/ inductive ExSum : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- Zero is a polynomial. `e` is the expression `0`. -/ | zero {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α) /-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/ | add {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExSum sα b → ExSum sα q($a + $b) end mutual -- partial only to speed up compilation /-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/ partial def ExBase.eq : ExBase sα a → ExBase sα b → Bool | .atom i, .atom j => i == j | .sum a, .sum b => a.eq b | _, _ => false @[inherit_doc ExBase.eq] partial def ExProd.eq : ExProd sα a → ExProd sα b → Bool | .const i _, .const j _ => i == j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃ | _, _ => false @[inherit_doc ExBase.eq] partial def ExSum.eq : ExSum sα a → ExSum sα b → Bool | .zero, .zero => true | .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂ | _, _ => false end mutual -- partial only to speed up compilation /-- A total order on normalized expressions. This is not an `Ord` instance because it is heterogeneous. -/ partial def ExBase.cmp : ExBase sα a → ExBase sα b → Ordering | .atom i, .atom j => compare i j | .sum a, .sum b => a.cmp b | .atom .., .sum .. => .lt | .sum .., .atom .. => .gt @[inherit_doc ExBase.cmp] partial def ExProd.cmp : ExProd sα a → ExProd sα b → Ordering | .const i _, .const j _ => compare i j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃) | .const _ _, .mul .. => .lt | .mul .., .const _ _ => .gt @[inherit_doc ExBase.cmp] partial def ExSum.cmp : ExSum sα a → ExSum sα b → Ordering | .zero, .zero => .eq | .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂) | .zero, .add .. => .lt | .add .., .zero => .gt end instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩ instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩ instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩ mutual /-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExBase.cast : ExBase sα a → Σ a, ExBase sβ a | .atom i => ⟨a, .atom i⟩ | .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩ /-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExProd.cast : ExProd sα a → Σ a, ExProd sβ a | .const i h => ⟨a, .const i h⟩ | .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩ /-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExSum.cast : ExSum sα a → Σ a, ExSum sβ a | .zero => ⟨_, .zero⟩ | .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩ end /-- The result of evaluating an (unnormalized) expression `e` into the type family `E` (one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'` and a representation `E e'` for it, and a proof of `e = e'`. -/ structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where /-- The normalized result. -/ expr : Q($α) /-- The data associated to the normalization. -/ val : E expr /-- A proof that the original expression is equal to the normalized result. -/ proof : Q($e = $expr) instance [Inhabited (Σ e, E e)] : Inhabited (Result E e) := let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩ variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) [CommSemiring R] /-- Constructs the expression corresponding to `.const n`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q(($lit).rawCast : $α), .const n none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) : (e : Q($α)) × ExProd sα e := ⟨q(Rat.rawCast $n $d : $α), .const q h⟩ section variable {sα} /-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/ def ExBase.toProd (va : ExBase sα a) (vb : ExProd sℕ b) : ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none) /-- Embed `ExProd` in `ExSum` by adding 0. -/ def ExProd.toSum (v : ExProd sα e) : ExSum sα q($e + 0) := .add v .zero /-- Get the leading coefficient of an `ExProd`. -/ def ExProd.coeff : ExProd sα e → ℚ | .const q _ => q | .mul _ _ v => v.coeff end /-- Two monomials are said to "overlap" if they differ by a constant factor, in which case the constants just add. When this happens, the constant may be either zero (if the monomials cancel) or nonzero (if they add up); the zero case is handled specially. -/ inductive Overlap (e : Q($α)) where /-- The expression `e` (the sum of monomials) is equal to `0`. -/ | zero (_ : Q(IsNat $e (nat_lit 0))) /-- The expression `e` (the sum of monomials) is equal to another monomial (with nonzero leading coefficient). -/ | nonzero (_ : Result (ExProd sα) e) theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) : x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add] theorem add_overlap_pf_zero (x : R) (e) : IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0) | ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩ /-- Given monomials `va, vb`, attempts to add them together to get another monomial. If the monomials are not compatible, returns `none`. For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none` and `xy + -xy = 0` is a `.zero` overlap. -/ def evalAddOverlap (va : ExProd sα a) (vb : ExProd sα b) : Option (Overlap sα q($a + $b)) := match va, vb with | .const za ha, .const zb hb => do let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb match res with | .isNat _ (.lit (.natVal 0)) p => pure <| .zero p | rc => let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq pure <| .nonzero ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do guard (va₁.eq vb₁ && va₂.eq vb₂) match ← evalAddOverlap va₃ vb₃ with | .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr) | .nonzero ⟨_, vc, p⟩ => pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩ | _, _ => none theorem add_pf_zero_add (b : R) : 0 + b = b := by simp theorem add_pf_add_zero (a : R) : a + 0 = a := by simp theorem add_pf_add_overlap (_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by subst_vars; simp [add_assoc, add_left_comm] theorem add_pf_add_overlap_zero (h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add] theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc] theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by subst_vars; simp [add_left_comm] /-- Adds two polynomials `va, vb` together to get a normalized result polynomial. * `0 + b = b` * `a + 0 = a` * `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`) * `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`) * `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`) -/ partial def evalAdd (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a + $b) := match va, vb with | .zero, vb => ⟨b, vb, q(add_pf_zero_add $b)⟩ | va, .zero => ⟨a, va, q(add_pf_add_zero $a)⟩ | .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ => match evalAddOverlap sα va₁ vb₁ with | some (.nonzero ⟨_, vc₁, pc₁⟩) => let ⟨_, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩ | some (.zero pc₁) => let ⟨c₂, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩ | none => if let .lt := va₁.cmp vb₁ then let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ := evalAdd va₂ vb ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩ else let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ := evalAdd va vb₂ ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩ theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast] theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast] theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) : (a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by subst_vars; rw [mul_assoc] theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) : a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by subst_vars; rw [mul_left_comm] theorem mul_pp_pf_overlap (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) : (x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by subst_vars; simp [pow_add, mul_mul_mul_comm] /-- Multiplies two monomials `va, vb` together to get a normalized result monomial. * `x * y = (x * y)` (for `x`, `y` coefficients) * `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient) * `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient) * `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)` (if `ea` and `eb` are identical except coefficient) * `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`) * `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`) -/ partial def evalMulProd (va : ExProd sα a) (vb : ExProd sα b) : Result (ExProd sα) q($a * $b) := match va, vb with | .const za ha, .const zb hb => if za = 1 then ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩ else if zb = 1 then ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩ else let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) ra rb).get! let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ => let ⟨_, vc, pc⟩ := evalMulProd va₃ vb ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩ | .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ => let ⟨_, vc, pc⟩ := evalMulProd va vb₃ ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩ | .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => Id.run do if vxa.eq vxb then if let some (.nonzero ⟨_, ve, pe⟩) := evalAddOverlap sℕ vea veb then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb₂ return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩ if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩ else let ⟨_, vc, pc⟩ := evalMulProd va vb₂ ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩ theorem mul_zero (a : R) : a * 0 = 0 := by simp theorem mul_add (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) : a * (b₁ + b₂) = d := by subst_vars; simp [_root_.mul_add] /-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial. * `a * 0 = 0` * `a * (b₁ + b₂) = (a * b₁) + (a * b₂)` -/ def evalMul₁ (va : ExProd sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match vb with | .zero => ⟨_, .zero, q(mul_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalMulProd sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalMul₁ va vb₂ let ⟨_, vd, pd⟩ := evalAdd sα vc₁.toSum vc₂ ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩ theorem zero_mul (b : R) : 0 * b = 0 := by simp theorem add_mul (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) : (a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul] /-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial. * `0 * b = 0` * `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)` -/ def evalMul (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match va with | .zero => ⟨_, .zero, q(zero_mul $b)⟩ | .add va₁ va₂ => let ⟨_, vc₁, pc₁⟩ := evalMul₁ sα va₁ vb let ⟨_, vc₂, pc₂⟩ := evalMul va₂ vb let ⟨_, vd, pd⟩ := evalAdd sα vc₁ vc₂ ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩ theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp theorem natCast_mul (a₂) (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by subst_vars; simp theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero theorem natCast_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp mutual /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * An atom `e` causes `↑e` to be allocated as a new atom. * A sum delegates to `ExSum.evalNatCast`. -/ partial def ExBase.evalNatCast (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) := match va with | .atom _ => do let a' : Q($α) := q($a) let i ← addAtom a' pure ⟨a', ExBase.atom i, (q(Eq.refl $a') : Expr)⟩ | .sum va => do let ⟨_, vc, p⟩ ← va.evalNatCast pure ⟨_, .sum vc, p⟩ /-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`. * `↑c = c` if `c` is a numeric literal * `↑(a ^ n * b) = ↑a ^ n * ↑b` -/ partial def ExProd.evalNatCast (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) := match va with | .const c hc => have n : Q(ℕ) := a.appArg! pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩ | .mul (e := a₂) va₁ va₂ va₃ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩ /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * `↑0 = 0` * `↑(a + b) = ↑a + ↑b` -/ partial def ExSum.evalNatCast (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) := match va with | .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩ | .add va₁ va₂ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩ end theorem smul_nat (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp theorem smul_eq_cast (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by subst_vars; simp /-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized polynomial expressions. * `a • b = a * b` if `α = ℕ` * `a • b = ↑a * b` otherwise -/ def evalNSMul (va : ExSum sℕ a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a • $b)) := do if ← isDefEq sα sℕ then let ⟨_, va'⟩ := va.cast have _b : Q(ℕ) := b let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩ else let ⟨_, va', pa'⟩ ← va.evalNatCast sα let ⟨_, vc, pc⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩ theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) : -a = b := by subst_vars; simp [Int.negOfNat] theorem neg_mul {R} [Ring R] (a₁ : R) (a₂) {a₃ b : R} (_ : -a₃ = b) : -(a₁ ^ a₂ * a₃) = a₁ ^ a₂ * b := by subst_vars; simp /-- Negates a monomial `va` to get another monomial. * `-c = (-c)` (for `c` coefficient) * `-(a₁ * a₂) = a₁ * -a₂` -/ def evalNegProd (rα : Q(Ring $α)) (va : ExProd sα a) : Result (ExProd sα) q(-$a) := match va with | .const za ha => let lit : Q(ℕ) := mkRawNatLit 1 let ⟨m1, _⟩ := ExProd.mkNegNat sα rα 1 let rm := Result.isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr) let ra := Result.ofRawRat za a ha let rb := (NormNum.evalMul.core q($m1 * $a) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) rm ra).get! let ⟨zb, hb⟩ := rb.toRatNZ.get! let ⟨b, (pb : Q((Int.negOfNat (nat_lit 1)).rawCast * $a = $b))⟩ := rb.toRawEq ⟨b, .const zb hb, (q(neg_one_mul (R := $α) $pb) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨_, vb, pb⟩ := evalNegProd rα va₃ ⟨_, .mul va₁ va₂ vb, (q(neg_mul $a₁ $a₂ $pb) : Expr)⟩ theorem neg_zero {R} [Ring R] : -(0 : R) = 0 := by simp theorem neg_add {R} [Ring R] {a₁ a₂ b₁ b₂ : R} (_ : -a₁ = b₁) (_ : -a₂ = b₂) : -(a₁ + a₂) = b₁ + b₂ := by subst_vars; simp [add_comm] /-- Negates a polynomial `va` to get another polynomial. * `-0 = 0` (for `c` coefficient) * `-(a₁ + a₂) = -a₁ + -a₂` -/ def evalNeg (rα : Q(Ring $α)) (va : ExSum sα a) : Result (ExSum sα) q(-$a) := match va with | .zero => ⟨_, .zero, (q(neg_zero (R := $α)) : Expr)⟩ | .add va₁ va₂ => let ⟨_, vb₁, pb₁⟩ := evalNegProd sα rα va₁ let ⟨_, vb₂, pb₂⟩ := evalNeg rα va₂ ⟨_, .add vb₁ vb₂, (q(neg_add $pb₁ $pb₂) : Expr)⟩ theorem sub_pf {R} [Ring R] {a b c d : R} (_ : -b = c) (_ : a + c = d) : a - b = d := by subst_vars; simp [sub_eq_add_neg] /-- Subtracts two polynomials `va, vb` to get a normalized result polynomial. * `a - b = a + -b` -/ def evalSub (rα : Q(Ring $α)) (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a - $b) := let ⟨_c, vc, pc⟩ := evalNeg sα rα vb let ⟨d, vd, (pd : Q($a + $_c = $d))⟩ := evalAdd sα va vc ⟨d, vd, (q(sub_pf $pc $pd) : Expr)⟩ theorem pow_prod_atom (a : R) (b) : a ^ b = (a + 0) ^ b * (nat_lit 1).rawCast := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. (This has a slightly different normalization than `evalPowAtom` because the input types are different.) * `x ^ e = (x + 0) ^ e * 1` -/ def evalPowProdAtom (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := ⟨_, (ExBase.sum va.toSum).toProd vb, q(pow_prod_atom $a $b)⟩ theorem pow_atom (a : R) (b) : a ^ b = a ^ b * (nat_lit 1).rawCast + 0 := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. * `x ^ e = x ^ e * 1 + 0` -/ def evalPowAtom (va : ExBase sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := ⟨_, (va.toProd vb).toSum, q(pow_atom $a $b)⟩ theorem const_pos (n : ℕ) (h : Nat.ble 1 n = true) : 0 < (n.rawCast : ℕ) := Nat.le_of_ble_eq_true h theorem mul_exp_pos (n) (h₁ : 0 < a₁) (h₂ : 0 < a₂) : 0 < a₁ ^ n * a₂ := Nat.mul_pos (Nat.pos_pow_of_pos _ h₁) h₂ theorem add_pos_left (a₂) (h : 0 < a₁) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_right ..) theorem add_pos_right (a₁) (h : 0 < a₂) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_left ..) mutual /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * Atoms are not (necessarily) positive * Sums defer to `ExSum.evalPos` -/ partial def ExBase.evalPos (va : ExBase sℕ a) : Option Q(0 < $a) := match va with | .atom _ => none | .sum va => va.evalPos /-- Attempts to prove that a monomial expression in `ℕ` is positive. * `0 < c` (where `c` is a numeral) is true by the normalization invariant (`c` is not zero) * `0 < x ^ e * b` if `0 < x` and `0 < b` -/ partial def ExProd.evalPos (va : ExProd sℕ a) : Option Q(0 < $a) := match va with | .const _ _ => -- it must be positive because it is a nonzero nat literal have lit : Q(ℕ) := a.appArg! haveI : $a =Q Nat.rawCast $lit := ⟨⟩ haveI p : Nat.ble 1 $lit =Q true := ⟨⟩ some q(const_pos $lit $p) | .mul (e := ea₁) vxa₁ _ va₂ => do let pa₁ ← vxa₁.evalPos let pa₂ ← va₂.evalPos some q(mul_exp_pos $ea₁ $pa₁ $pa₂) /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * `0 < 0` fails * `0 < a + b` if `0 < a` or `0 < b` -/ partial def ExSum.evalPos (va : ExSum sℕ a) : Option Q(0 < $a) := match va with | .zero => none | .add (a := a₁) (b := a₂) va₁ va₂ => do match va₁.evalPos with | some p => some q(add_pos_left $a₂ $p) | none => let p ← va₂.evalPos; some q(add_pos_right $a₁ $p) end theorem pow_one (a : R) : a ^ nat_lit 1 = a := by simp
Mathlib/Tactic/Ring/Basic.lean
665
666
theorem pow_bit0 (_ : (a : R) ^ k = b) (_ : b * b = c) : a ^ (Nat.mul (nat_lit 2) k) = c := by
subst_vars; simp [Nat.succ_mul, pow_add]
/- 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]
Mathlib/CategoryTheory/Limits/Shapes/Pullbacks.lean
811
813
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
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Algebra.DirectSum.Module import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.Convex.Uniform import Mathlib.Analysis.NormedSpace.Completion import Mathlib.Analysis.NormedSpace.BoundedLinearMaps #align_import analysis.inner_product_space.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Inner product space This file defines inner product spaces and proves the basic properties. We do not formally define Hilbert spaces, but they can be obtained using the set of assumptions `[NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E]`. An inner product space is a vector space endowed with an inner product. It generalizes the notion of dot product in `ℝ^n` and provides the means of defining the length of a vector and the angle between two vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero. We define both the real and complex cases at the same time using the `RCLike` typeclass. This file proves general results on inner product spaces. For the specific construction of an inner product structure on `n → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `EuclideanSpace` in `Analysis.InnerProductSpace.PiL2`. ## Main results - We define the class `InnerProductSpace 𝕜 E` extending `NormedSpace 𝕜 E` with a number of basic properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ` or `ℂ`, through the `RCLike` typeclass. - We show that the inner product is continuous, `continuous_inner`, and bundle it as the continuous sesquilinear map `innerSL` (see also `innerₛₗ` for the non-continuous version). - We define `Orthonormal`, a predicate on a function `v : ι → E`, and prove the existence of a maximal orthonormal set, `exists_maximal_orthonormal`. Bessel's inequality, `Orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`, the sum of the norm-squares of the inner products `⟪v i, x⟫` is no more than the norm-square of `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file `Analysis.InnerProductSpace.projection`. ## Notation We globally denote the real and complex inner products by `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively. We also provide two notation namespaces: `RealInnerProductSpace`, `ComplexInnerProductSpace`, which respectively introduce the plain notation `⟪·, ·⟫` for the real and complex inner product. ## Implementation notes We choose the convention that inner products are conjugate linear in the first argument and linear in the second. ## Tags inner product space, Hilbert space, norm ## References * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open Topology ComplexConjugate open LinearMap (BilinForm) variable {𝕜 E F : Type*} [RCLike 𝕜] /-- Syntactic typeclass for types endowed with an inner product -/ class Inner (𝕜 E : Type*) where /-- The inner product function. -/ inner : E → E → 𝕜 #align has_inner Inner export Inner (inner) /-- The inner product with values in `𝕜`. -/ notation3:max "⟪" x ", " y "⟫_" 𝕜:max => @inner 𝕜 _ _ x y section Notations /-- The inner product with values in `ℝ`. -/ scoped[RealInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℝ _ _ x y /-- The inner product with values in `ℂ`. -/ scoped[ComplexInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℂ _ _ x y end Notations /-- An inner product space is a vector space with an additional operation called inner product. The norm could be derived from the inner product, instead we require the existence of a norm and the fact that `‖x‖^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product spaces. To construct a norm from an inner product, see `InnerProductSpace.ofCore`. -/ class InnerProductSpace (𝕜 : Type*) (E : Type*) [RCLike 𝕜] [NormedAddCommGroup E] extends NormedSpace 𝕜 E, Inner 𝕜 E where /-- The inner product induces the norm. -/ norm_sq_eq_inner : ∀ x : E, ‖x‖ ^ 2 = re (inner x x) /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space InnerProductSpace /-! ### Constructing a normed space structure from an inner product In the definition of an inner product space, we require the existence of a norm, which is equal (but maybe not defeq) to the square root of the scalar product. This makes it possible to put an inner product space structure on spaces with a preexisting norm (for instance `ℝ`), with good properties. However, sometimes, one would like to define the norm starting only from a well-behaved scalar product. This is what we implement in this paragraph, starting from a structure `InnerProductSpace.Core` stating that we have a nice scalar product. Our goal here is not to develop a whole theory with all the supporting API, as this will be done below for `InnerProductSpace`. Instead, we implement the bare minimum to go as directly as possible to the construction of the norm and the proof of the triangular inequality. Warning: Do not use this `Core` structure if the space you are interested in already has a norm instance defined on it, otherwise this will create a second non-defeq norm instance! -/ /-- A structure requiring that a scalar product is positive definite and symmetric, from which one can construct an `InnerProductSpace` instance in `InnerProductSpace.ofCore`. -/ -- @[nolint HasNonemptyInstance] porting note: I don't think we have this linter anymore structure InnerProductSpace.Core (𝕜 : Type*) (F : Type*) [RCLike 𝕜] [AddCommGroup F] [Module 𝕜 F] extends Inner 𝕜 F where /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is positive (semi)definite. -/ nonneg_re : ∀ x, 0 ≤ re (inner x x) /-- The inner product is positive definite. -/ definite : ∀ x, inner x x = 0 → x = 0 /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space.core InnerProductSpace.Core /- We set `InnerProductSpace.Core` to be a class as we will use it as such in the construction of the normed space structure that it produces. However, all the instances we will use will be local to this proof. -/ attribute [class] InnerProductSpace.Core /-- Define `InnerProductSpace.Core` from `InnerProductSpace`. Defined to reuse lemmas about `InnerProductSpace.Core` for `InnerProductSpace`s. Note that the `Norm` instance provided by `InnerProductSpace.Core.norm` is propositionally but not definitionally equal to the original norm. -/ def InnerProductSpace.toCore [NormedAddCommGroup E] [c : InnerProductSpace 𝕜 E] : InnerProductSpace.Core 𝕜 E := { c with nonneg_re := fun x => by rw [← InnerProductSpace.norm_sq_eq_inner] apply sq_nonneg definite := fun x hx => norm_eq_zero.1 <| pow_eq_zero (n := 2) <| by rw [InnerProductSpace.norm_sq_eq_inner (𝕜 := 𝕜) x, hx, map_zero] } #align inner_product_space.to_core InnerProductSpace.toCore namespace InnerProductSpace.Core variable [AddCommGroup F] [Module 𝕜 F] [c : InnerProductSpace.Core 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 F _ x y local notation "normSqK" => @RCLike.normSq 𝕜 _ local notation "reK" => @RCLike.re 𝕜 _ local notation "ext_iff" => @RCLike.ext_iff 𝕜 _ local postfix:90 "†" => starRingEnd _ /-- Inner product defined by the `InnerProductSpace.Core` structure. We can't reuse `InnerProductSpace.Core.toInner` because it takes `InnerProductSpace.Core` as an explicit argument. -/ def toInner' : Inner 𝕜 F := c.toInner #align inner_product_space.core.to_has_inner' InnerProductSpace.Core.toInner' attribute [local instance] toInner' /-- The norm squared function for `InnerProductSpace.Core` structure. -/ def normSq (x : F) := reK ⟪x, x⟫ #align inner_product_space.core.norm_sq InnerProductSpace.Core.normSq local notation "normSqF" => @normSq 𝕜 F _ _ _ _ theorem inner_conj_symm (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ := c.conj_symm x y #align inner_product_space.core.inner_conj_symm InnerProductSpace.Core.inner_conj_symm theorem inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ := c.nonneg_re _ #align inner_product_space.core.inner_self_nonneg InnerProductSpace.Core.inner_self_nonneg theorem inner_self_im (x : F) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub] simp [inner_conj_symm] #align inner_product_space.core.inner_self_im InnerProductSpace.Core.inner_self_im theorem inner_add_left (x y z : F) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := c.add_left _ _ _ #align inner_product_space.core.inner_add_left InnerProductSpace.Core.inner_add_left theorem inner_add_right (x y z : F) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add]; simp only [inner_conj_symm] #align inner_product_space.core.inner_add_right InnerProductSpace.Core.inner_add_right theorem ofReal_normSq_eq_inner_self (x : F) : (normSqF x : 𝕜) = ⟪x, x⟫ := by rw [ext_iff] exact ⟨by simp only [ofReal_re]; rfl, by simp only [inner_self_im, ofReal_im]⟩ #align inner_product_space.core.coe_norm_sq_eq_inner_self InnerProductSpace.Core.ofReal_normSq_eq_inner_self theorem inner_re_symm (x y : F) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_product_space.core.inner_re_symm InnerProductSpace.Core.inner_re_symm theorem inner_im_symm (x y : F) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_product_space.core.inner_im_symm InnerProductSpace.Core.inner_im_symm theorem inner_smul_left (x y : F) {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := c.smul_left _ _ _ #align inner_product_space.core.inner_smul_left InnerProductSpace.Core.inner_smul_left theorem inner_smul_right (x y : F) {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left]; simp only [conj_conj, inner_conj_symm, RingHom.map_mul] #align inner_product_space.core.inner_smul_right InnerProductSpace.Core.inner_smul_right theorem inner_zero_left (x : F) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : F), inner_smul_left]; simp only [zero_mul, RingHom.map_zero] #align inner_product_space.core.inner_zero_left InnerProductSpace.Core.inner_zero_left theorem inner_zero_right (x : F) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left]; simp only [RingHom.map_zero] #align inner_product_space.core.inner_zero_right InnerProductSpace.Core.inner_zero_right theorem inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 := ⟨c.definite _, by rintro rfl exact inner_zero_left _⟩ #align inner_product_space.core.inner_self_eq_zero InnerProductSpace.Core.inner_self_eq_zero theorem normSq_eq_zero {x : F} : normSqF x = 0 ↔ x = 0 := Iff.trans (by simp only [normSq, ext_iff, map_zero, inner_self_im, eq_self_iff_true, and_true_iff]) (@inner_self_eq_zero 𝕜 _ _ _ _ _ x) #align inner_product_space.core.norm_sq_eq_zero InnerProductSpace.Core.normSq_eq_zero theorem inner_self_ne_zero {x : F} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_product_space.core.inner_self_ne_zero InnerProductSpace.Core.inner_self_ne_zero theorem inner_self_ofReal_re (x : F) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := by norm_num [ext_iff, inner_self_im] set_option linter.uppercaseLean3 false in #align inner_product_space.core.inner_self_re_to_K InnerProductSpace.Core.inner_self_ofReal_re theorem norm_inner_symm (x y : F) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align inner_product_space.core.norm_inner_symm InnerProductSpace.Core.norm_inner_symm
Mathlib/Analysis/InnerProductSpace/Basic.lean
277
279
theorem inner_neg_left (x y : F) : ⟪-x, y⟫ = -⟪x, y⟫ := by
rw [← neg_one_smul 𝕜 x, inner_smul_left] simp
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.Logic.Equiv.Basic #align_import category_theory.limits.has_limits from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone #align category_theory.limits.limit_cone CategoryTheory.Limits.LimitCone #align category_theory.limits.limit_cone.is_limit CategoryTheory.Limits.LimitCone.isLimit /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) #align category_theory.limits.has_limit CategoryTheory.Limits.HasLimit theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_limit.mk CategoryTheory.Limits.HasLimit.mk /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit #align category_theory.limits.get_limit_cone CategoryTheory.Limits.getLimitCone variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance #align category_theory.limits.has_limits_of_shape CategoryTheory.Limits.HasLimitsOfShape /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance #align category_theory.limits.has_limits_of_size CategoryTheory.Limits.HasLimitsOfSize /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C #align category_theory.limits.has_limits CategoryTheory.Limits.HasLimits theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits.has_limits_of_shape CategoryTheory.Limits.HasLimits.has_limits_of_shape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F #align category_theory.limits.has_limit_of_has_limits_of_shape CategoryTheory.Limits.hasLimitOfHasLimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits_of_shape_of_has_limits CategoryTheory.Limits.hasLimitsOfShapeOfHasLimits -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone #align category_theory.limits.limit.cone CategoryTheory.Limits.limit.cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt #align category_theory.limits.limit CategoryTheory.Limits.limit /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j #align category_theory.limits.limit.π CategoryTheory.Limits.limit.π @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.limit.cone_X CategoryTheory.Limits.limit.cone_x @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl #align category_theory.limits.limit.cone_π CategoryTheory.Limits.limit.cone_π @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f #align category_theory.limits.limit.w CategoryTheory.Limits.limit.w /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit #align category_theory.limits.limit.is_limit CategoryTheory.Limits.limit.isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c #align category_theory.limits.limit.lift CategoryTheory.Limits.limit.lift @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl #align category_theory.limits.limit.is_limit_lift CategoryTheory.Limits.limit.isLimit_lift @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j #align category_theory.limits.limit.lift_π CategoryTheory.Limits.limit.lift_π /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α #align category_theory.limits.lim_map CategoryTheory.Limits.limMap @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j #align category_theory.limits.lim_map_π CategoryTheory.Limits.limMap_π /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c #align category_theory.limits.limit.cone_morphism CategoryTheory.Limits.limit.coneMorphism @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl #align category_theory.limits.limit.cone_morphism_hom CategoryTheory.Limits.limit.coneMorphism_hom theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp #align category_theory.limits.limit.cone_morphism_π CategoryTheory.Limits.limit.coneMorphism_π @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_hom_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_hom_comp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_inv_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_inv_comp theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ #align category_theory.limits.limit.exists_unique CategoryTheory.Limits.limit.existsUnique /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit #align category_theory.limits.limit.iso_limit_cone CategoryTheory.Limits.limit.isoLimitCone @[reassoc (attr := simp)] theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_hom_π CategoryTheory.Limits.limit.isoLimitCone_hom_π @[reassoc (attr := simp)] theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_inv_π CategoryTheory.Limits.limit.isoLimitCone_inv_π @[ext] theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.isLimit F).hom_ext w #align category_theory.limits.limit.hom_ext CategoryTheory.Limits.limit.hom_ext @[simp] theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) : limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by ext rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π] rfl #align category_theory.limits.limit.lift_map CategoryTheory.Limits.limit.lift_map @[simp] theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) := (limit.isLimit _).lift_self #align category_theory.limits.limit.lift_cone CategoryTheory.Limits.limit.lift_cone /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and cones with cone point `W`. -/ def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) := (limit.isLimit F).homIso W #align category_theory.limits.limit.hom_iso CategoryTheory.Limits.limit.homIso @[simp] theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) : (limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π := (limit.isLimit F).homIso_hom f #align category_theory.limits.limit.hom_iso_hom CategoryTheory.Limits.limit.homIso_hom /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and an explicit componentwise description of cones with cone point `W`. -/ def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.isLimit F).homIso' W #align category_theory.limits.limit.hom_iso' CategoryTheory.Limits.limit.homIso' theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by aesop_cat #align category_theory.limits.limit.lift_extend CategoryTheory.Limits.limit.lift_extend /-- If a functor `F` has a limit, so does any naturally isomorphic functor. -/ theorem hasLimitOfIso {F G : J ⥤ C} [HasLimit F] (α : F ≅ G) : HasLimit G := HasLimit.mk { cone := (Cones.postcompose α.hom).obj (limit.cone F) isLimit := (IsLimit.postcomposeHomEquiv _ _).symm (limit.isLimit F) } #align category_theory.limits.has_limit_of_iso CategoryTheory.Limits.hasLimitOfIso -- See the construction of limits from products and equalizers -- for an example usage. /-- If a functor `G` has the same collection of cones as a functor `F` which has a limit, then `G` also has a limit. -/ theorem HasLimit.ofConesIso {J K : Type u₁} [Category.{v₁} J] [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cones ≅ G.cones) [HasLimit F] : HasLimit G := HasLimit.mk ⟨_, IsLimit.ofNatIso (IsLimit.natIso (limit.isLimit F) ≪≫ h)⟩ #align category_theory.limits.has_limit.of_cones_iso CategoryTheory.Limits.HasLimit.ofConesIso /-- The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasLimit.isoOfNatIso {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) : limit F ≅ limit G := IsLimit.conePointsIsoOfNatIso (limit.isLimit F) (limit.isLimit G) w #align category_theory.limits.has_limit.iso_of_nat_iso CategoryTheory.Limits.HasLimit.isoOfNatIso @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_hom_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j := IsLimit.conePointsIsoOfNatIso_hom_comp _ _ _ _ #align category_theory.limits.has_limit.iso_of_nat_iso_hom_π CategoryTheory.Limits.HasLimit.isoOfNatIso_hom_π @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_inv_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j := IsLimit.conePointsIsoOfNatIso_inv_comp _ _ _ _ #align category_theory.limits.has_limit.iso_of_nat_iso_inv_π CategoryTheory.Limits.HasLimit.isoOfNatIso_inv_π @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_hom {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone F) (w : F ≅ G) : limit.lift F t ≫ (HasLimit.isoOfNatIso w).hom = limit.lift G ((Cones.postcompose w.hom).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_hom _ _ _ #align category_theory.limits.has_limit.lift_iso_of_nat_iso_hom CategoryTheory.Limits.HasLimit.lift_isoOfNatIso_hom @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_inv {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone G) (w : F ≅ G) : limit.lift G t ≫ (HasLimit.isoOfNatIso w).inv = limit.lift F ((Cones.postcompose w.inv).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_inv _ _ _ #align category_theory.limits.has_limit.lift_iso_of_nat_iso_inv CategoryTheory.Limits.HasLimit.lift_isoOfNatIso_inv /-- The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasLimit.isoOfEquivalence {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : limit F ≅ limit G := IsLimit.conePointsIsoOfEquivalence (limit.isLimit F) (limit.isLimit G) e w #align category_theory.limits.has_limit.iso_of_equivalence CategoryTheory.Limits.HasLimit.isoOfEquivalence @[simp] theorem HasLimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : (HasLimit.isoOfEquivalence e w).hom ≫ limit.π G k = limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp #align category_theory.limits.has_limit.iso_of_equivalence_hom_π CategoryTheory.Limits.HasLimit.isoOfEquivalence_hom_π @[simp] theorem HasLimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : (HasLimit.isoOfEquivalence e w).inv ≫ limit.π F j = limit.π G (e.functor.obj j) ≫ w.hom.app j := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp #align category_theory.limits.has_limit.iso_of_equivalence_inv_π CategoryTheory.Limits.HasLimit.isoOfEquivalence_inv_π section Pre variable (F) [HasLimit F] (E : K ⥤ J) [HasLimit (E ⋙ F)] /-- The canonical morphism from the limit of `F` to the limit of `E ⋙ F`. -/ def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) ((limit.cone F).whisker E) #align category_theory.limits.limit.pre CategoryTheory.Limits.limit.pre @[reassoc (attr := simp)] theorem limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw [IsLimit.fac] rfl #align category_theory.limits.limit.pre_π CategoryTheory.Limits.limit.pre_π @[simp] theorem limit.lift_pre (c : Cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp #align category_theory.limits.limit.lift_pre CategoryTheory.Limits.limit.lift_pre variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) [HasLimit (D ⋙ E ⋙ F)] @[simp] theorem limit.pre_pre [h : HasLimit (D ⋙ E ⋙ F)] : haveI : HasLimit ((D ⋙ E) ⋙ F) := h; limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by haveI : HasLimit ((D ⋙ E) ⋙ F) := h ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; rfl #align category_theory.limits.limit.pre_pre CategoryTheory.Limits.limit.pre_pre variable {E F} /-- - If we have particular limit cones available for `E ⋙ F` and for `F`, we obtain a formula for `limit.pre F E`. -/ theorem limit.pre_eq (s : LimitCone (E ⋙ F)) (t : LimitCone F) : limit.pre F E = (limit.isoLimitCone t).hom ≫ s.isLimit.lift (t.cone.whisker E) ≫ (limit.isoLimitCone s).inv := by aesop_cat #align category_theory.limits.limit.pre_eq CategoryTheory.Limits.limit.pre_eq end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F) [HasLimit F] (G : C ⥤ D) [HasLimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`. -/ def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) (G.mapCone (limit.cone F)) #align category_theory.limits.limit.post CategoryTheory.Limits.limit.post @[reassoc (attr := simp)] theorem limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw [IsLimit.fac] rfl #align category_theory.limits.limit.post_π CategoryTheory.Limits.limit.post_π @[simp] theorem limit.lift_post (c : Cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.mapCone c) := by ext rw [assoc, limit.post_π, ← G.map_comp, limit.lift_π, limit.lift_π] rfl #align category_theory.limits.limit.lift_post CategoryTheory.Limits.limit.lift_post @[simp] theorem limit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) [h : HasLimit ((F ⋙ G) ⋙ H)] : -- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) haveI : HasLimit (F ⋙ G ⋙ H) := h H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by haveI : HasLimit (F ⋙ G ⋙ H) := h ext; erw [assoc, limit.post_π, ← H.map_comp, limit.post_π, limit.post_π]; rfl #align category_theory.limits.limit.post_post CategoryTheory.Limits.limit.post_post end Post theorem limit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasLimit F] [HasLimit (E ⋙ F)] [HasLimit (F ⋙ G)] [h : HasLimit ((E ⋙ F) ⋙ G)] :-- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or haveI : HasLimit (E ⋙ F ⋙ G) := h G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by haveI : HasLimit (E ⋙ F ⋙ G) := h ext; erw [assoc, limit.post_π, ← G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π] #align category_theory.limits.limit.pre_post CategoryTheory.Limits.limit.pre_post open CategoryTheory.Equivalence instance hasLimitEquivalenceComp (e : K ≌ J) [HasLimit F] : HasLimit (e.functor ⋙ F) := HasLimit.mk { cone := Cone.whisker e.functor (limit.cone F) isLimit := IsLimit.whiskerEquivalence (limit.isLimit F) e } #align category_theory.limits.has_limit_equivalence_comp CategoryTheory.Limits.hasLimitEquivalenceComp -- Porting note: testing whether this still needed -- attribute [local elab_without_expected_type] inv_fun_id_assoc -- not entirely sure why this is needed /-- If a `E ⋙ F` has a limit, and `E` is an equivalence, we can construct a limit of `F`. -/ theorem hasLimitOfEquivalenceComp (e : K ≌ J) [HasLimit (e.functor ⋙ F)] : HasLimit F := by haveI : HasLimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasLimitEquivalenceComp e.symm apply hasLimitOfIso (e.invFunIdAssoc F) #align category_theory.limits.has_limit_of_equivalence_comp CategoryTheory.Limits.hasLimitOfEquivalenceComp -- `hasLimitCompEquivalence` and `hasLimitOfCompEquivalence` -- are proved in `CategoryTheory/Adjunction/Limits.lean`. section LimFunctor variable [HasLimitsOfShape J C] section /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ @[simps] def lim : (J ⥤ C) ⥤ C where obj F := limit F map α := limMap α map_id F := by apply Limits.limit.hom_ext; intro j erw [limMap_π, Category.id_comp, Category.comp_id] map_comp α β := by apply Limits.limit.hom_ext; intro j erw [assoc, IsLimit.fac, IsLimit.fac, ← assoc, IsLimit.fac, assoc]; rfl #align category_theory.limits.lim CategoryTheory.Limits.lim #align category_theory.limits.lim_map_eq_lim_map CategoryTheory.Limits.lim_map end variable {G : J ⥤ C} (α : F ⟶ G) theorem limit.map_pre [HasLimitsOfShape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whiskerLeft E α) := by ext simp #align category_theory.limits.limit.map_pre CategoryTheory.Limits.limit.map_pre theorem limit.map_pre' [HasLimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whiskerRight α F) := by ext1; simp [← category.assoc] #align category_theory.limits.limit.map_pre' CategoryTheory.Limits.limit.map_pre' theorem limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (Functor.leftUnitor F).inv := by aesop_cat #align category_theory.limits.limit.id_pre CategoryTheory.Limits.limit.id_pre theorem limit.map_post {D : Type u'} [Category.{v'} D] [HasLimitsOfShape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (limMap α) ≫ limit.post G H = limit.post F H ≫ limMap (whiskerRight α H) := by ext simp only [whiskerRight_app, limMap_π, assoc, limit.post_π_assoc, limit.post_π, ← H.map_comp] #align category_theory.limits.limit.map_post CategoryTheory.Limits.limit.map_post /-- The isomorphism between morphisms from `W` to the cone point of the limit cone for `F` and cones over `F` with cone point `W` is natural in `F`. -/ def limYoneda : lim ⋙ yoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => limit.homIso F (unop W) #align category_theory.limits.lim_yoneda CategoryTheory.Limits.limYoneda /-- The constant functor and limit functor are adjoint to each other-/ def constLimAdj : (const J : C ⥤ J ⥤ C) ⊣ lim where homEquiv c g := { toFun := fun f => limit.lift _ ⟨c, f⟩ invFun := fun f => { app := fun j => f ≫ limit.π _ _ } left_inv := by aesop_cat right_inv := by aesop_cat } unit := { app := fun c => limit.lift _ ⟨_, 𝟙 _⟩ } counit := { app := fun g => { app := limit.π _ } } -- This used to be automatic before leanprover/lean4#2644 homEquiv_unit := by -- Sad that aesop can no longer do this! intros dsimp ext simp #align category_theory.limits.const_lim_adj CategoryTheory.Limits.constLimAdj instance : IsRightAdjoint (lim : (J ⥤ C) ⥤ C) := ⟨_, ⟨constLimAdj⟩⟩ end LimFunctor instance limMap_mono' {F G : J ⥤ C} [HasLimitsOfShape J C] (α : F ⟶ G) [Mono α] : Mono (limMap α) := (lim : (J ⥤ C) ⥤ C).map_mono α #align category_theory.limits.lim_map_mono' CategoryTheory.Limits.limMap_mono' instance limMap_mono {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) [∀ j, Mono (α.app j)] : Mono (limMap α) := ⟨fun {Z} u v h => limit.hom_ext fun j => (cancel_mono (α.app j)).1 <| by simpa using h =≫ limit.π _ j⟩ #align category_theory.limits.lim_map_mono CategoryTheory.Limits.limMap_mono section Adjunction variable {L : (J ⥤ C) ⥤ C} (adj : Functor.const _ ⊣ L) /- The fact that the existence of limits of shape `J` is equivalent to the existence of a right adjoint to the constant functor `C ⥤ (J ⥤ C)` is obtained in the file `Mathlib.CategoryTheory.Limits.ConeCategory`: see the lemma `hasLimitsOfShape_iff_isLeftAdjoint_const`. In the definitions below, given an adjunction `adj : Functor.const _ ⊣ (L : (J ⥤ C) ⥤ C)`, we directly construct a limit cone for any `F : J ⥤ C`. -/ /-- The limit cone obtained from a right adjoint of the constant functor. -/ @[simps] noncomputable def coneOfAdj (F : J ⥤ C) : Cone F where pt := L.obj F π := adj.counit.app F /-- The cones defined by `coneOfAdj` are limit cones. -/ @[simps] def isLimitConeOfAdj (F : J ⥤ C) : IsLimit (coneOfAdj adj F) where lift s := adj.homEquiv _ _ s.π fac s j := by have eq := NatTrans.congr_app (adj.counit.naturality s.π) j have eq' := NatTrans.congr_app (adj.left_triangle_components s.pt) j dsimp at eq eq' ⊢ rw [Adjunction.homEquiv_unit, assoc, eq, reassoc_of% eq'] uniq s m hm := (adj.homEquiv _ _).symm.injective (by ext j; simpa using hm j) end Adjunction /-- We can transport limits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasLimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasLimitsOfShape J C] : HasLimitsOfShape J' C := by constructor intro F apply hasLimitOfEquivalenceComp e #align category_theory.limits.has_limits_of_shape_of_equivalence CategoryTheory.Limits.hasLimitsOfShape_of_equivalence variable (C) /-- A category that has larger limits also has smaller limits. -/ theorem hasLimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₂, u₂} C where has_limits_of_shape J {_} := hasLimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasLimitsOfSizeShrink.{v u} C` tries to obtain `HasLimitsOfSize.{v u} C` from some other `HasLimitsOfSize C`. -/ theorem hasLimitsOfSizeShrink [HasLimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasLimitsOfSize.{v₁, u₁} C := hasLimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C #align category_theory.limits.has_limits_of_size_shrink CategoryTheory.Limits.hasLimitsOfSizeShrink instance (priority := 100) hasSmallestLimitsOfHasLimits [HasLimits C] : HasLimitsOfSize.{0, 0} C := hasLimitsOfSizeShrink.{0, 0} C #align category_theory.limits.has_smallest_limits_of_has_limits CategoryTheory.Limits.hasSmallestLimitsOfHasLimits end Limit section Colimit /-- `ColimitCocone F` contains a cocone over `F` together with the information that it is a colimit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure ColimitCocone (F : J ⥤ C) where /-- The cocone itself -/ cocone : Cocone F /-- The proof that it is the colimit cocone -/ isColimit : IsColimit cocone #align category_theory.limits.colimit_cocone CategoryTheory.Limits.ColimitCocone #align category_theory.limits.colimit_cocone.is_colimit CategoryTheory.Limits.ColimitCocone.isColimit /-- `HasColimit F` represents the mere existence of a colimit for `F`. -/ class HasColimit (F : J ⥤ C) : Prop where mk' :: /-- There exists a colimit for `F` -/ exists_colimit : Nonempty (ColimitCocone F) #align category_theory.limits.has_colimit CategoryTheory.Limits.HasColimit theorem HasColimit.mk {F : J ⥤ C} (d : ColimitCocone F) : HasColimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_colimit.mk CategoryTheory.Limits.HasColimit.mk /-- Use the axiom of choice to extract explicit `ColimitCocone F` from `HasColimit F`. -/ def getColimitCocone (F : J ⥤ C) [HasColimit F] : ColimitCocone F := Classical.choice <| HasColimit.exists_colimit #align category_theory.limits.get_colimit_cocone CategoryTheory.Limits.getColimitCocone variable (J C) /-- `C` has colimits of shape `J` if there exists a colimit for every functor `F : J ⥤ C`. -/ class HasColimitsOfShape : Prop where /-- All `F : J ⥤ C` have colimits for a fixed `J` -/ has_colimit : ∀ F : J ⥤ C, HasColimit F := by infer_instance #align category_theory.limits.has_colimits_of_shape CategoryTheory.Limits.HasColimitsOfShape /-- `C` has all colimits of size `v₁ u₁` (`HasColimitsOfSize.{v₁ u₁} C`) if it has colimits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasColimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All `F : J ⥤ C` have colimits for all small `J` -/ has_colimits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasColimitsOfShape J C := by infer_instance #align category_theory.limits.has_colimits_of_size CategoryTheory.Limits.HasColimitsOfSize /-- `C` has all (small) colimits if it has colimits of every shape that is as big as its hom-sets. -/ abbrev HasColimits (C : Type u) [Category.{v} C] : Prop := HasColimitsOfSize.{v, v} C #align category_theory.limits.has_colimits CategoryTheory.Limits.HasColimits theorem HasColimits.hasColimitsOfShape {C : Type u} [Category.{v} C] [HasColimits C] (J : Type v) [Category.{v} J] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J #align category_theory.limits.has_colimits.has_colimits_of_shape CategoryTheory.Limits.HasColimits.hasColimitsOfShape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasColimitOfHasColimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasColimitsOfShape J C] (F : J ⥤ C) : HasColimit F := HasColimitsOfShape.has_colimit F #align category_theory.limits.has_colimit_of_has_colimits_of_shape CategoryTheory.Limits.hasColimitOfHasColimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasColimitsOfShapeOfHasColimitsOfSize {J : Type u₁} [Category.{v₁} J] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J #align category_theory.limits.has_colimits_of_shape_of_has_colimits_of_size CategoryTheory.Limits.hasColimitsOfShapeOfHasColimitsOfSize -- Interface to the `HasColimit` class. /-- An arbitrary choice of colimit cocone of a functor. -/ def colimit.cocone (F : J ⥤ C) [HasColimit F] : Cocone F := (getColimitCocone F).cocone #align category_theory.limits.colimit.cocone CategoryTheory.Limits.colimit.cocone /-- An arbitrary choice of colimit object of a functor. -/ def colimit (F : J ⥤ C) [HasColimit F] := (colimit.cocone F).pt #align category_theory.limits.colimit CategoryTheory.Limits.colimit /-- The coprojection from a value of the functor to the colimit object. -/ def colimit.ι (F : J ⥤ C) [HasColimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j #align category_theory.limits.colimit.ι CategoryTheory.Limits.colimit.ι @[simp] theorem colimit.cocone_ι {F : J ⥤ C} [HasColimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl #align category_theory.limits.colimit.cocone_ι CategoryTheory.Limits.colimit.cocone_ι @[simp] theorem colimit.cocone_x {F : J ⥤ C} [HasColimit F] : (colimit.cocone F).pt = colimit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.colimit.cocone_X CategoryTheory.Limits.colimit.cocone_x @[reassoc (attr := simp)] theorem colimit.w (F : J ⥤ C) [HasColimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f #align category_theory.limits.colimit.w CategoryTheory.Limits.colimit.w /-- Evidence that the arbitrary choice of cocone is a colimit cocone. -/ def colimit.isColimit (F : J ⥤ C) [HasColimit F] : IsColimit (colimit.cocone F) := (getColimitCocone F).isColimit #align category_theory.limits.colimit.is_colimit CategoryTheory.Limits.colimit.isColimit /-- The morphism from the colimit object to the cone point of any other cocone. -/ def colimit.desc (F : J ⥤ C) [HasColimit F] (c : Cocone F) : colimit F ⟶ c.pt := (colimit.isColimit F).desc c #align category_theory.limits.colimit.desc CategoryTheory.Limits.colimit.desc @[simp] theorem colimit.isColimit_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.isColimit F).desc c = colimit.desc F c := rfl #align category_theory.limits.colimit.is_colimit_desc CategoryTheory.Limits.colimit.isColimit_desc /-- We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`, and combined with `colimit.ext` we rely on these lemmas for many calculations. However, since `Category.assoc` is a `@[simp]` lemma, often expressions are right associated, and it's hard to apply these lemmas about `colimit.ι`. We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism. (see `Tactic/reassoc_axiom.lean`) -/ @[reassoc (attr := simp)] theorem colimit.ι_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := IsColimit.fac _ c j #align category_theory.limits.colimit.ι_desc CategoryTheory.Limits.colimit.ι_desc /-- Functoriality of colimits. Usually this morphism should be accessed through `colim.map`, but may be needed separately when you have specified colimits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) : colimit F ⟶ colimit G := IsColimit.map (colimit.isColimit F) _ α #align category_theory.limits.colim_map CategoryTheory.Limits.colimMap @[reassoc (attr := simp)] theorem ι_colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) (j : J) : colimit.ι F j ≫ colimMap α = α.app j ≫ colimit.ι G j := colimit.ι_desc _ j #align category_theory.limits.ι_colim_map CategoryTheory.Limits.ι_colimMap /-- The cocone morphism from the arbitrary choice of colimit cocone to any cocone. -/ def colimit.coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) : colimit.cocone F ⟶ c := (colimit.isColimit F).descCoconeMorphism c #align category_theory.limits.colimit.cocone_morphism CategoryTheory.Limits.colimit.coconeMorphism @[simp] theorem colimit.coconeMorphism_hom {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.coconeMorphism c).hom = colimit.desc F c := rfl #align category_theory.limits.colimit.cocone_morphism_hom CategoryTheory.Limits.colimit.coconeMorphism_hom theorem colimit.ι_coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ (colimit.coconeMorphism c).hom = c.ι.app j := by simp #align category_theory.limits.colimit.ι_cocone_morphism CategoryTheory.Limits.colimit.ι_coconeMorphism @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_hom {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hc).hom = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _ #align category_theory.limits.colimit.comp_cocone_point_unique_up_to_iso_hom CategoryTheory.Limits.colimit.comp_coconePointUniqueUpToIso_hom @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_inv {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso hc (colimit.isColimit _)).inv = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _ #align category_theory.limits.colimit.comp_cocone_point_unique_up_to_iso_inv CategoryTheory.Limits.colimit.comp_coconePointUniqueUpToIso_inv theorem colimit.existsUnique {F : J ⥤ C} [HasColimit F] (t : Cocone F) : ∃! d : colimit F ⟶ t.pt, ∀ j, colimit.ι F j ≫ d = t.ι.app j := (colimit.isColimit F).existsUnique _ #align category_theory.limits.colimit.exists_unique CategoryTheory.Limits.colimit.existsUnique /-- Given any other colimit cocone for `F`, the chosen `colimit F` is isomorphic to the cocone point. -/ def colimit.isoColimitCocone {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) : colimit F ≅ t.cocone.pt := IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) t.isColimit #align category_theory.limits.colimit.iso_colimit_cocone CategoryTheory.Limits.colimit.isoColimitCocone @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_hom {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : colimit.ι F j ≫ (colimit.isoColimitCocone t).hom = t.cocone.ι.app j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat #align category_theory.limits.colimit.iso_colimit_cocone_ι_hom CategoryTheory.Limits.colimit.isoColimitCocone_ι_hom @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_inv {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : t.cocone.ι.app j ≫ (colimit.isoColimitCocone t).inv = colimit.ι F j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat #align category_theory.limits.colimit.iso_colimit_cocone_ι_inv CategoryTheory.Limits.colimit.isoColimitCocone_ι_inv @[ext] theorem colimit.hom_ext {F : J ⥤ C} [HasColimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.isColimit F).hom_ext w #align category_theory.limits.colimit.hom_ext CategoryTheory.Limits.colimit.hom_ext @[simp] theorem colimit.desc_cocone {F : J ⥤ C} [HasColimit F] : colimit.desc F (colimit.cocone F) = 𝟙 (colimit F) := (colimit.isColimit _).desc_self #align category_theory.limits.colimit.desc_cocone CategoryTheory.Limits.colimit.desc_cocone /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and cocones with cone point `W`. -/ def colimit.homIso (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ F.cocones.obj W := (colimit.isColimit F).homIso W #align category_theory.limits.colimit.hom_iso CategoryTheory.Limits.colimit.homIso @[simp] theorem colimit.homIso_hom (F : J ⥤ C) [HasColimit F] {W : C} (f : ULift (colimit F ⟶ W)) : (colimit.homIso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f.down := (colimit.isColimit F).homIso_hom f #align category_theory.limits.colimit.hom_iso_hom CategoryTheory.Limits.colimit.homIso_hom /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and an explicit componentwise description of cocones with cone point `W`. -/ def colimit.homIso' (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.isColimit F).homIso' W #align category_theory.limits.colimit.hom_iso' CategoryTheory.Limits.colimit.homIso' theorem colimit.desc_extend (F : J ⥤ C) [HasColimit F] (c : Cocone F) {X : C} (f : c.pt ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := by ext1; rw [← Category.assoc]; simp #align category_theory.limits.colimit.desc_extend CategoryTheory.Limits.colimit.desc_extend -- This has the isomorphism pointing in the opposite direction than in `has_limit_of_iso`. -- This is intentional; it seems to help with elaboration. /-- If `F` has a colimit, so does any naturally isomorphic functor. -/ theorem hasColimitOfIso {F G : J ⥤ C} [HasColimit F] (α : G ≅ F) : HasColimit G := HasColimit.mk { cocone := (Cocones.precompose α.hom).obj (colimit.cocone F) isColimit := (IsColimit.precomposeHomEquiv _ _).symm (colimit.isColimit F) } #align category_theory.limits.has_colimit_of_iso CategoryTheory.Limits.hasColimitOfIso /-- If a functor `G` has the same collection of cocones as a functor `F` which has a colimit, then `G` also has a colimit. -/ theorem HasColimit.ofCoconesIso {K : Type u₁} [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cocones ≅ G.cocones) [HasColimit F] : HasColimit G := HasColimit.mk ⟨_, IsColimit.ofNatIso (IsColimit.natIso (colimit.isColimit F) ≪≫ h)⟩ #align category_theory.limits.has_colimit.of_cocones_iso CategoryTheory.Limits.HasColimit.ofCoconesIso /-- The colimits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasColimit.isoOfNatIso {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfNatIso (colimit.isColimit F) (colimit.isColimit G) w #align category_theory.limits.has_colimit.iso_of_nat_iso CategoryTheory.Limits.HasColimit.isoOfNatIso @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_hom {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfNatIso w).hom = w.hom.app j ≫ colimit.ι G j := IsColimit.comp_coconePointsIsoOfNatIso_hom _ _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_ι_hom CategoryTheory.Limits.HasColimit.isoOfNatIso_ι_hom @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_inv {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι G j ≫ (HasColimit.isoOfNatIso w).inv = w.inv.app j ≫ colimit.ι F j := IsColimit.comp_coconePointsIsoOfNatIso_inv _ _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_ι_inv CategoryTheory.Limits.HasColimit.isoOfNatIso_ι_inv @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_hom_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone G) (w : F ≅ G) : (HasColimit.isoOfNatIso w).hom ≫ colimit.desc G t = colimit.desc F ((Cocones.precompose w.hom).obj _) := IsColimit.coconePointsIsoOfNatIso_hom_desc _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_hom_desc CategoryTheory.Limits.HasColimit.isoOfNatIso_hom_desc @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_inv_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone F) (w : F ≅ G) : (HasColimit.isoOfNatIso w).inv ≫ colimit.desc F t = colimit.desc G ((Cocones.precompose w.inv).obj _) := IsColimit.coconePointsIsoOfNatIso_inv_desc _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_inv_desc CategoryTheory.Limits.HasColimit.isoOfNatIso_inv_desc /-- The colimits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasColimit.isoOfEquivalence {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfEquivalence (colimit.isColimit F) (colimit.isColimit G) e w #align category_theory.limits.has_colimit.iso_of_equivalence CategoryTheory.Limits.HasColimit.isoOfEquivalence @[simp] theorem HasColimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfEquivalence e w).hom = F.map (e.unit.app j) ≫ w.inv.app _ ≫ colimit.ι G _ := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] #align category_theory.limits.has_colimit.iso_of_equivalence_hom_π CategoryTheory.Limits.HasColimit.isoOfEquivalence_hom_π @[simp] theorem HasColimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : colimit.ι G k ≫ (HasColimit.isoOfEquivalence e w).inv = G.map (e.counitInv.app k) ≫ w.hom.app (e.inverse.obj k) ≫ colimit.ι F (e.inverse.obj k) := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] #align category_theory.limits.has_colimit.iso_of_equivalence_inv_π CategoryTheory.Limits.HasColimit.isoOfEquivalence_inv_π section Pre variable (F) [HasColimit F] (E : K ⥤ J) [HasColimit (E ⋙ F)] /-- The canonical morphism from the colimit of `E ⋙ F` to the colimit of `F`. -/ def colimit.pre : colimit (E ⋙ F) ⟶ colimit F := colimit.desc (E ⋙ F) ((colimit.cocone F).whisker E) #align category_theory.limits.colimit.pre CategoryTheory.Limits.colimit.pre @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/HasLimits.lean
994
996
theorem colimit.ι_pre (k : K) : colimit.ι (E ⋙ F) k ≫ colimit.pre F E = colimit.ι F (E.obj k) := by
erw [IsColimit.fac] rfl
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Init.ZeroOne import Mathlib.Data.Set.Defs import Mathlib.Order.Basic import Mathlib.Order.SymmDiff import Mathlib.Tactic.Tauto import Mathlib.Tactic.ByContra import Mathlib.Util.Delaborators #align_import data.set.basic from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Basic properties of sets Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not be decidable. The definition is in the core library. This file provides some basic definitions related to sets and functions not present in the core library, as well as extra lemmas for functions in the core library (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset). Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending `s` to the corresponding subtype `↥s`. See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean. ## Main definitions Notation used here: - `f : α → β` is a function, - `s : Set α` and `s₁ s₂ : Set α` are subsets of `α` - `t : Set β` is a subset of `β`. Definitions in the file: * `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the fact that `s` has an element (see the Implementation Notes). * `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`. ## Notation * `sᶜ` for the complement of `s` ## Implementation notes * `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that the `s.Nonempty` dot notation can be used. * For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`. ## Tags set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset -/ /-! ### Set coercion to a type -/ open Function universe u v w x namespace Set variable {α : Type u} {s t : Set α} instance instBooleanAlgebraSet : BooleanAlgebra (Set α) := { (inferInstance : BooleanAlgebra (α → Prop)) with sup := (· ∪ ·), le := (· ≤ ·), lt := fun s t => s ⊆ t ∧ ¬t ⊆ s, inf := (· ∩ ·), bot := ∅, compl := (·ᶜ), top := univ, sdiff := (· \ ·) } instance : HasSSubset (Set α) := ⟨(· < ·)⟩ @[simp] theorem top_eq_univ : (⊤ : Set α) = univ := rfl #align set.top_eq_univ Set.top_eq_univ @[simp] theorem bot_eq_empty : (⊥ : Set α) = ∅ := rfl #align set.bot_eq_empty Set.bot_eq_empty @[simp] theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) := rfl #align set.sup_eq_union Set.sup_eq_union @[simp] theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) := rfl #align set.inf_eq_inter Set.inf_eq_inter @[simp] theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) := rfl #align set.le_eq_subset Set.le_eq_subset @[simp] theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) := rfl #align set.lt_eq_ssubset Set.lt_eq_ssubset theorem le_iff_subset : s ≤ t ↔ s ⊆ t := Iff.rfl #align set.le_iff_subset Set.le_iff_subset theorem lt_iff_ssubset : s < t ↔ s ⊂ t := Iff.rfl #align set.lt_iff_ssubset Set.lt_iff_ssubset alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset #align has_subset.subset.le HasSubset.Subset.le alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset #align has_ssubset.ssubset.lt HasSSubset.SSubset.lt instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α s #align set.pi_set_coe.can_lift Set.PiSetCoe.canLift instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiSetCoe.canLift ι (fun _ => α) s #align set.pi_set_coe.can_lift' Set.PiSetCoe.canLift' end Set section SetCoe variable {α : Type u} instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩ theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } := rfl #align set.coe_eq_subtype Set.coe_eq_subtype @[simp] theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } := rfl #align set.coe_set_of Set.coe_setOf -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align set_coe.forall SetCoe.forall -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.exists {s : Set α} {p : s → Prop} : (∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align set_coe.exists SetCoe.exists theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 := (@SetCoe.exists _ _ fun x => p x.1 x.2).symm #align set_coe.exists' SetCoe.exists' theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 := (@SetCoe.forall _ _ fun x => p x.1 x.2).symm #align set_coe.forall' SetCoe.forall' @[simp] theorem set_coe_cast : ∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | _, _, rfl, _, _ => rfl #align set_coe_cast set_coe_cast theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b := Subtype.eq #align set_coe.ext SetCoe.ext theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b := Iff.intro SetCoe.ext fun h => h ▸ rfl #align set_coe.ext_iff SetCoe.ext_iff end SetCoe /-- See also `Subtype.prop` -/ theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s := p.prop #align subtype.mem Subtype.mem /-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/ theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t := fun h₁ _ h₂ => by rw [← h₁]; exact h₂ #align eq.subset Eq.subset namespace Set variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α} instance : Inhabited (Set α) := ⟨∅⟩ theorem ext_iff {s t : Set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t := ⟨fun h x => by rw [h], ext⟩ #align set.ext_iff Set.ext_iff @[trans] theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx #align set.mem_of_mem_of_subset Set.mem_of_mem_of_subset theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by tauto #align set.forall_in_swap Set.forall_in_swap /-! ### Lemmas about `mem` and `setOf` -/ theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a := Iff.rfl #align set.mem_set_of Set.mem_setOf /-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can nevertheless be useful for various reasons, e.g. to apply further projection notation or in an argument to `simp`. -/ theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a := h #align has_mem.mem.out Membership.mem.out theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a := Iff.rfl #align set.nmem_set_of_iff Set.nmem_setOf_iff @[simp] theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s := rfl #align set.set_of_mem_eq Set.setOf_mem_eq theorem setOf_set {s : Set α} : setOf s = s := rfl #align set.set_of_set Set.setOf_set theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := Iff.rfl #align set.set_of_app_iff Set.setOf_app_iff theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a := Iff.rfl #align set.mem_def Set.mem_def theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) := bijective_id #align set.set_of_bijective Set.setOf_bijective theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x := Iff.rfl theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s := Iff.rfl @[simp] theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a := Iff.rfl #align set.set_of_subset_set_of Set.setOf_subset_setOf theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } := rfl #align set.set_of_and Set.setOf_and theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } := rfl #align set.set_of_or Set.setOf_or /-! ### Subset and strict subset relations -/ instance : IsRefl (Set α) (· ⊆ ·) := show IsRefl (Set α) (· ≤ ·) by infer_instance instance : IsTrans (Set α) (· ⊆ ·) := show IsTrans (Set α) (· ≤ ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) := show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance instance : IsAntisymm (Set α) (· ⊆ ·) := show IsAntisymm (Set α) (· ≤ ·) by infer_instance instance : IsIrrefl (Set α) (· ⊂ ·) := show IsIrrefl (Set α) (· < ·) by infer_instance instance : IsTrans (Set α) (· ⊂ ·) := show IsTrans (Set α) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· < ·) (· < ·) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) := show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance instance : IsAsymm (Set α) (· ⊂ ·) := show IsAsymm (Set α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl #align set.subset_def Set.subset_def theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) := rfl #align set.ssubset_def Set.ssubset_def @[refl] theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id #align set.subset.refl Set.Subset.refl theorem Subset.rfl {s : Set α} : s ⊆ s := Subset.refl s #align set.subset.rfl Set.Subset.rfl @[trans] theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h #align set.subset.trans Set.Subset.trans @[trans] theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h #align set.mem_of_eq_of_mem Set.mem_of_eq_of_mem theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩ #align set.subset.antisymm Set.Subset.antisymm theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩ #align set.subset.antisymm_iff Set.Subset.antisymm_iff -- an alternative name theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b := Subset.antisymm #align set.eq_of_subset_of_subset Set.eq_of_subset_of_subset theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _ #align set.mem_of_subset_of_mem Set.mem_of_subset_of_mem theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| mem_of_subset_of_mem h #align set.not_mem_subset Set.not_mem_subset theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by simp only [subset_def, not_forall, exists_prop] #align set.not_subset Set.not_subset lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h /-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/ protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t := eq_or_lt_of_le h #align set.eq_or_ssubset_of_subset Set.eq_or_ssubset_of_subset theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s := not_subset.1 h.2 #align set.exists_of_ssubset Set.exists_of_ssubset protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne (Set α) _ s t #align set.ssubset_iff_subset_ne Set.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s := ⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩ #align set.ssubset_iff_of_subset Set.ssubset_iff_of_subset protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩ #align set.ssubset_of_ssubset_of_subset Set.ssubset_of_ssubset_of_subset protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩ #align set.ssubset_of_subset_of_ssubset Set.ssubset_of_subset_of_ssubset theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) := id #align set.not_mem_empty Set.not_mem_empty -- Porting note (#10618): removed `simp` because `simp` can prove it theorem not_not_mem : ¬a ∉ s ↔ a ∈ s := not_not #align set.not_not_mem Set.not_not_mem /-! ### Non-empty sets -/ -- Porting note: we seem to need parentheses at `(↥s)`, -- even if we increase the right precedence of `↥` in `Mathlib.Tactic.Coe`. -- Porting note: removed `simp` as it is competing with `nonempty_subtype`. -- @[simp] theorem nonempty_coe_sort {s : Set α} : Nonempty (↥s) ↔ s.Nonempty := nonempty_subtype #align set.nonempty_coe_sort Set.nonempty_coe_sort alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align set.nonempty.coe_sort Set.Nonempty.coe_sort theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s := Iff.rfl #align set.nonempty_def Set.nonempty_def theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty := ⟨x, h⟩ #align set.nonempty_of_mem Set.nonempty_of_mem theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅ | ⟨_, hx⟩, hs => hs hx #align set.nonempty.not_subset_empty Set.Nonempty.not_subset_empty /-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/ protected noncomputable def Nonempty.some (h : s.Nonempty) : α := Classical.choose h #align set.nonempty.some Set.Nonempty.some protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s := Classical.choose_spec h #align set.nonempty.some_mem Set.Nonempty.some_mem theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := hs.imp ht #align set.nonempty.mono Set.Nonempty.mono theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty := let ⟨x, xs, xt⟩ := not_subset.1 h ⟨x, xs, xt⟩ #align set.nonempty_of_not_subset Set.nonempty_of_not_subset theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty := nonempty_of_not_subset ht.2 #align set.nonempty_of_ssubset Set.nonempty_of_ssubset theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.of_diff Set.Nonempty.of_diff theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty := (nonempty_of_ssubset ht).of_diff #align set.nonempty_of_ssubset' Set.nonempty_of_ssubset' theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty := hs.imp fun _ => Or.inl #align set.nonempty.inl Set.Nonempty.inl theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty := ht.imp fun _ => Or.inr #align set.nonempty.inr Set.Nonempty.inr @[simp] theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty := exists_or #align set.union_nonempty Set.union_nonempty theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.left Set.Nonempty.left theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty := h.imp fun _ => And.right #align set.nonempty.right Set.Nonempty.right theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t := Iff.rfl #align set.inter_nonempty Set.inter_nonempty theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by simp_rw [inter_nonempty] #align set.inter_nonempty_iff_exists_left Set.inter_nonempty_iff_exists_left theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by simp_rw [inter_nonempty, and_comm] #align set.inter_nonempty_iff_exists_right Set.inter_nonempty_iff_exists_right theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty := ⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩ #align set.nonempty_iff_univ_nonempty Set.nonempty_iff_univ_nonempty @[simp] theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty | ⟨x⟩ => ⟨x, trivial⟩ #align set.univ_nonempty Set.univ_nonempty theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) := nonempty_subtype.2 #align set.nonempty.to_subtype Set.Nonempty.to_subtype theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩ #align set.nonempty.to_type Set.Nonempty.to_type instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) := Set.univ_nonempty.to_subtype #align set.univ.nonempty Set.univ.nonempty theorem nonempty_of_nonempty_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_› #align set.nonempty_of_nonempty_subtype Set.nonempty_of_nonempty_subtype /-! ### Lemmas about the empty set -/ theorem empty_def : (∅ : Set α) = { _x : α | False } := rfl #align set.empty_def Set.empty_def @[simp] theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False := Iff.rfl #align set.mem_empty_iff_false Set.mem_empty_iff_false @[simp] theorem setOf_false : { _a : α | False } = ∅ := rfl #align set.set_of_false Set.setOf_false @[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl @[simp] theorem empty_subset (s : Set α) : ∅ ⊆ s := nofun #align set.empty_subset Set.empty_subset theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ := (Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm #align set.subset_empty_iff Set.subset_empty_iff theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm #align set.eq_empty_iff_forall_not_mem Set.eq_empty_iff_forall_not_mem theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ := subset_empty_iff.1 h #align set.eq_empty_of_forall_not_mem Set.eq_empty_of_forall_not_mem theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 #align set.eq_empty_of_subset_empty Set.eq_empty_of_subset_empty theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ := eq_empty_of_subset_empty fun x _ => isEmptyElim x #align set.eq_empty_of_is_empty Set.eq_empty_of_isEmpty /-- There is exactly one set of a type that is empty. -/ instance uniqueEmpty [IsEmpty α] : Unique (Set α) where default := ∅ uniq := eq_empty_of_isEmpty #align set.unique_empty Set.uniqueEmpty /-- See also `Set.nonempty_iff_ne_empty`. -/ theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem] #align set.not_nonempty_iff_eq_empty Set.not_nonempty_iff_eq_empty /-- See also `Set.not_nonempty_iff_eq_empty`. -/ theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ := not_nonempty_iff_eq_empty.not_right #align set.nonempty_iff_ne_empty Set.nonempty_iff_ne_empty /-- See also `nonempty_iff_ne_empty'`. -/ theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem] /-- See also `not_nonempty_iff_eq_empty'`. -/ theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ := not_nonempty_iff_eq_empty'.not_right alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty #align set.nonempty.ne_empty Set.Nonempty.ne_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx #align set.not_nonempty_empty Set.not_nonempty_empty -- Porting note: removing `@[simp]` as it is competing with `isEmpty_subtype`. -- @[simp] theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ := not_iff_not.1 <| by simpa using nonempty_iff_ne_empty #align set.is_empty_coe_sort Set.isEmpty_coe_sort theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty := or_iff_not_imp_left.2 nonempty_iff_ne_empty.2 #align set.eq_empty_or_nonempty Set.eq_empty_or_nonempty theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 <| e ▸ h #align set.subset_eq_empty Set.subset_eq_empty theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True := iff_true_intro fun _ => False.elim #align set.ball_empty_iff Set.forall_mem_empty @[deprecated (since := "2024-03-23")] alias ball_empty_iff := forall_mem_empty instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) := ⟨fun x => x.2⟩ @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm #align set.empty_ssubset Set.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align set.nonempty.empty_ssubset Set.Nonempty.empty_ssubset /-! ### Universal set. In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`. Mathematically it is the same as `α` but it has a different type. -/ @[simp] theorem setOf_true : { _x : α | True } = univ := rfl #align set.set_of_true Set.setOf_true @[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl @[simp] theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α := eq_empty_iff_forall_not_mem.trans ⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩ #align set.univ_eq_empty_iff Set.univ_eq_empty_iff theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e => not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm #align set.empty_ne_univ Set.empty_ne_univ @[simp] theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial #align set.subset_univ Set.subset_univ @[simp] theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ := @top_le_iff _ _ _ s #align set.univ_subset_iff Set.univ_subset_iff alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff #align set.eq_univ_of_univ_subset Set.eq_univ_of_univ_subset theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s := univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial #align set.eq_univ_iff_forall Set.eq_univ_iff_forall theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 #align set.eq_univ_of_forall Set.eq_univ_of_forall theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] #align set.nonempty.eq_univ Set.Nonempty.eq_univ theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ := eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t) #align set.eq_univ_of_subset Set.eq_univ_of_subset theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α) | ⟨x⟩ => ⟨x, trivial⟩ #align set.exists_mem_of_nonempty Set.exists_mem_of_nonempty theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by rw [← not_forall, ← eq_univ_iff_forall] #align set.ne_univ_iff_exists_not_mem Set.ne_univ_iff_exists_not_mem theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} : ¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def] #align set.not_subset_iff_exists_mem_not_mem Set.not_subset_iff_exists_mem_not_mem theorem univ_unique [Unique α] : @Set.univ α = {default} := Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default #align set.univ_unique Set.univ_unique theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ := lt_top_iff_ne_top #align set.ssubset_univ_iff Set.ssubset_univ_iff instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) := ⟨⟨∅, univ, empty_ne_univ⟩⟩ #align set.nontrivial_of_nonempty Set.nontrivial_of_nonempty /-! ### Lemmas about union -/ theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } := rfl #align set.union_def Set.union_def theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b := Or.inl #align set.mem_union_left Set.mem_union_left theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b := Or.inr #align set.mem_union_right Set.mem_union_right theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H #align set.mem_or_mem_of_mem_union Set.mem_or_mem_of_mem_union theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := Or.elim H₁ H₂ H₃ #align set.mem_union.elim Set.MemUnion.elim @[simp] theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := Iff.rfl #align set.mem_union Set.mem_union @[simp] theorem union_self (a : Set α) : a ∪ a = a := ext fun _ => or_self_iff #align set.union_self Set.union_self @[simp] theorem union_empty (a : Set α) : a ∪ ∅ = a := ext fun _ => or_false_iff _ #align set.union_empty Set.union_empty @[simp] theorem empty_union (a : Set α) : ∅ ∪ a = a := ext fun _ => false_or_iff _ #align set.empty_union Set.empty_union theorem union_comm (a b : Set α) : a ∪ b = b ∪ a := ext fun _ => or_comm #align set.union_comm Set.union_comm theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) := ext fun _ => or_assoc #align set.union_assoc Set.union_assoc instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) := ⟨union_assoc⟩ #align set.union_is_assoc Set.union_isAssoc instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) := ⟨union_comm⟩ #align set.union_is_comm Set.union_isComm theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext fun _ => or_left_comm #align set.union_left_comm Set.union_left_comm theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ := ext fun _ => or_right_comm #align set.union_right_comm Set.union_right_comm @[simp] theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align set.union_eq_left_iff_subset Set.union_eq_left @[simp] theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align set.union_eq_right_iff_subset Set.union_eq_right theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t := union_eq_right.mpr h #align set.union_eq_self_of_subset_left Set.union_eq_self_of_subset_left theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s := union_eq_left.mpr h #align set.union_eq_self_of_subset_right Set.union_eq_self_of_subset_right @[simp] theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl #align set.subset_union_left Set.subset_union_left @[simp] theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr #align set.subset_union_right Set.subset_union_right theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ => Or.rec (@sr _) (@tr _) #align set.union_subset Set.union_subset @[simp] theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (forall_congr' fun _ => or_imp).trans forall_and #align set.union_subset_iff Set.union_subset_iff @[gcongr] theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _) #align set.union_subset_union Set.union_subset_union @[gcongr] theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align set.union_subset_union_left Set.union_subset_union_left @[gcongr] theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align set.union_subset_union_right Set.union_subset_union_right theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u := h.trans subset_union_left #align set.subset_union_of_subset_left Set.subset_union_of_subset_left theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u := h.trans subset_union_right #align set.subset_union_of_subset_right Set.subset_union_of_subset_right -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align set.union_congr_left Set.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align set.union_congr_right Set.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align set.union_eq_union_iff_left Set.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align set.union_eq_union_iff_right Set.union_eq_union_iff_right @[simp] theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by simp only [← subset_empty_iff] exact union_subset_iff #align set.union_empty_iff Set.union_empty_iff @[simp] theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _ #align set.union_univ Set.union_univ @[simp] theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _ #align set.univ_union Set.univ_union /-! ### Lemmas about intersection -/ theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } := rfl #align set.inter_def Set.inter_def @[simp, mfld_simps] theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := Iff.rfl #align set.mem_inter_iff Set.mem_inter_iff theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ #align set.mem_inter Set.mem_inter theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a := h.left #align set.mem_of_mem_inter_left Set.mem_of_mem_inter_left theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b := h.right #align set.mem_of_mem_inter_right Set.mem_of_mem_inter_right @[simp] theorem inter_self (a : Set α) : a ∩ a = a := ext fun _ => and_self_iff #align set.inter_self Set.inter_self @[simp] theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ := ext fun _ => and_false_iff _ #align set.inter_empty Set.inter_empty @[simp] theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ := ext fun _ => false_and_iff _ #align set.empty_inter Set.empty_inter theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a := ext fun _ => and_comm #align set.inter_comm Set.inter_comm theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) := ext fun _ => and_assoc #align set.inter_assoc Set.inter_assoc instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) := ⟨inter_assoc⟩ #align set.inter_is_assoc Set.inter_isAssoc instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) := ⟨inter_comm⟩ #align set.inter_is_comm Set.inter_isComm theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => and_left_comm #align set.inter_left_comm Set.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => and_right_comm #align set.inter_right_comm Set.inter_right_comm @[simp, mfld_simps] theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left #align set.inter_subset_left Set.inter_subset_left @[simp] theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right #align set.inter_subset_right Set.inter_subset_right theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h => ⟨rs h, rt h⟩ #align set.subset_inter Set.subset_inter @[simp] theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := (forall_congr' fun _ => imp_and).trans forall_and #align set.subset_inter_iff Set.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align set.inter_eq_left_iff_subset Set.inter_eq_left @[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right #align set.inter_eq_right_iff_subset Set.inter_eq_right @[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf @[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s := inter_eq_left.mpr #align set.inter_eq_self_of_subset_left Set.inter_eq_self_of_subset_left theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t := inter_eq_right.mpr #align set.inter_eq_self_of_subset_right Set.inter_eq_self_of_subset_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align set.inter_congr_left Set.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align set.inter_congr_right Set.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align set.inter_eq_inter_iff_left Set.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align set.inter_eq_inter_iff_right Set.inter_eq_inter_iff_right @[simp, mfld_simps] theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _ #align set.inter_univ Set.inter_univ @[simp, mfld_simps] theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _ #align set.univ_inter Set.univ_inter @[gcongr] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _) #align set.inter_subset_inter Set.inter_subset_inter @[gcongr] theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter H Subset.rfl #align set.inter_subset_inter_left Set.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := inter_subset_inter Subset.rfl H #align set.inter_subset_inter_right Set.inter_subset_inter_right theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s := inter_eq_self_of_subset_right subset_union_left #align set.union_inter_cancel_left Set.union_inter_cancel_left theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t := inter_eq_self_of_subset_right subset_union_right #align set.union_inter_cancel_right Set.union_inter_cancel_right theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} := rfl #align set.inter_set_of_eq_sep Set.inter_setOf_eq_sep theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} := inter_comm _ _ #align set.set_of_inter_eq_sep Set.setOf_inter_eq_sep /-! ### Distributivity laws -/ theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align set.inter_distrib_left Set.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align set.inter_distrib_right Set.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align set.union_distrib_left Set.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align set.union_distrib_right Set.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align set.union_union_distrib_left Set.union_union_distrib_left theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align set.union_union_distrib_right Set.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align set.inter_inter_distrib_left Set.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align set.inter_inter_distrib_right Set.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align set.union_union_union_comm Set.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align set.inter_inter_inter_comm Set.inter_inter_inter_comm /-! ### Lemmas about `insert` `insert α s` is the set `{α} ∪ s`. -/ theorem insert_def (x : α) (s : Set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl #align set.insert_def Set.insert_def @[simp] theorem subset_insert (x : α) (s : Set α) : s ⊆ insert x s := fun _ => Or.inr #align set.subset_insert Set.subset_insert theorem mem_insert (x : α) (s : Set α) : x ∈ insert x s := Or.inl rfl #align set.mem_insert Set.mem_insert theorem mem_insert_of_mem {x : α} {s : Set α} (y : α) : x ∈ s → x ∈ insert y s := Or.inr #align set.mem_insert_of_mem Set.mem_insert_of_mem theorem eq_or_mem_of_mem_insert {x a : α} {s : Set α} : x ∈ insert a s → x = a ∨ x ∈ s := id #align set.eq_or_mem_of_mem_insert Set.eq_or_mem_of_mem_insert theorem mem_of_mem_insert_of_ne : b ∈ insert a s → b ≠ a → b ∈ s := Or.resolve_left #align set.mem_of_mem_insert_of_ne Set.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert : b ∈ insert a s → b ∉ s → b = a := Or.resolve_right #align set.eq_of_not_mem_of_mem_insert Set.eq_of_not_mem_of_mem_insert @[simp] theorem mem_insert_iff {x a : α} {s : Set α} : x ∈ insert a s ↔ x = a ∨ x ∈ s := Iff.rfl #align set.mem_insert_iff Set.mem_insert_iff @[simp] theorem insert_eq_of_mem {a : α} {s : Set α} (h : a ∈ s) : insert a s = s := ext fun _ => or_iff_right_of_imp fun e => e.symm ▸ h #align set.insert_eq_of_mem Set.insert_eq_of_mem theorem ne_insert_of_not_mem {s : Set α} (t : Set α) {a : α} : a ∉ s → s ≠ insert a t := mt fun e => e.symm ▸ mem_insert _ _ #align set.ne_insert_of_not_mem Set.ne_insert_of_not_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert _ _, insert_eq_of_mem⟩ #align set.insert_eq_self Set.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align set.insert_ne_self Set.insert_ne_self theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_def, mem_insert_iff, or_imp, forall_and, forall_eq] #align set.insert_subset Set.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha, hs⟩ theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := fun _ => Or.imp_right (@h _) #align set.insert_subset_insert Set.insert_subset_insert @[simp] theorem insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by refine ⟨fun h x hx => ?_, insert_subset_insert⟩ rcases h (subset_insert _ _ hx) with (rfl | hxt) exacts [(ha hx).elim, hxt] #align set.insert_subset_insert_iff Set.insert_subset_insert_iff theorem subset_insert_iff_of_not_mem (ha : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := forall₂_congr fun _ hb => or_iff_right <| ne_of_mem_of_not_mem hb ha #align set.subset_insert_iff_of_not_mem Set.subset_insert_iff_of_not_mem theorem ssubset_iff_insert {s t : Set α} : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := by simp only [insert_subset_iff, exists_and_right, ssubset_def, not_subset] aesop #align set.ssubset_iff_insert Set.ssubset_iff_insert theorem ssubset_insert {s : Set α} {a : α} (h : a ∉ s) : s ⊂ insert a s := ssubset_iff_insert.2 ⟨a, h, Subset.rfl⟩ #align set.ssubset_insert Set.ssubset_insert theorem insert_comm (a b : α) (s : Set α) : insert a (insert b s) = insert b (insert a s) := ext fun _ => or_left_comm #align set.insert_comm Set.insert_comm -- Porting note (#10618): removing `simp` attribute because `simp` can prove it theorem insert_idem (a : α) (s : Set α) : insert a (insert a s) = insert a s := insert_eq_of_mem <| mem_insert _ _ #align set.insert_idem Set.insert_idem theorem insert_union : insert a s ∪ t = insert a (s ∪ t) := ext fun _ => or_assoc #align set.insert_union Set.insert_union @[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) := ext fun _ => or_left_comm #align set.union_insert Set.union_insert @[simp] theorem insert_nonempty (a : α) (s : Set α) : (insert a s).Nonempty := ⟨a, mem_insert a s⟩ #align set.insert_nonempty Set.insert_nonempty instance (a : α) (s : Set α) : Nonempty (insert a s : Set α) := (insert_nonempty a s).to_subtype theorem insert_inter_distrib (a : α) (s t : Set α) : insert a (s ∩ t) = insert a s ∩ insert a t := ext fun _ => or_and_left #align set.insert_inter_distrib Set.insert_inter_distrib theorem insert_union_distrib (a : α) (s t : Set α) : insert a (s ∪ t) = insert a s ∪ insert a t := ext fun _ => or_or_distrib_left #align set.insert_union_distrib Set.insert_union_distrib theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert a s) ha, congr_arg (fun x => insert x s)⟩ #align set.insert_inj Set.insert_inj -- useful in proofs by induction theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ insert a s → P x) (x) (h : x ∈ s) : P x := H _ (Or.inr h) #align set.forall_of_forall_insert Set.forall_of_forall_insert theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ s → P x) (ha : P a) (x) (h : x ∈ insert a s) : P x := h.elim (fun e => e.symm ▸ ha) (H _) #align set.forall_insert_of_forall Set.forall_insert_of_forall /- Porting note: ∃ x ∈ insert a s, P x is parsed as ∃ x, x ∈ insert a s ∧ P x, where in Lean3 it was parsed as `∃ x, ∃ (h : x ∈ insert a s), P x` -/ theorem exists_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∃ x ∈ insert a s, P x) ↔ (P a ∨ ∃ x ∈ s, P x) := by simp [mem_insert_iff, or_and_right, exists_and_left, exists_or] #align set.bex_insert_iff Set.exists_mem_insert @[deprecated (since := "2024-03-23")] alias bex_insert_iff := exists_mem_insert theorem forall_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∀ x ∈ insert a s, P x) ↔ P a ∧ ∀ x ∈ s, P x := forall₂_or_left.trans <| and_congr_left' forall_eq #align set.ball_insert_iff Set.forall_mem_insert @[deprecated (since := "2024-03-23")] alias ball_insert_iff := forall_mem_insert /-! ### Lemmas about singletons -/ /- porting note: instance was in core in Lean3 -/ instance : LawfulSingleton α (Set α) := ⟨fun x => Set.ext fun a => by simp only [mem_empty_iff_false, mem_insert_iff, or_false] exact Iff.rfl⟩ theorem singleton_def (a : α) : ({a} : Set α) = insert a ∅ := (insert_emptyc_eq a).symm #align set.singleton_def Set.singleton_def @[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : Set α) ↔ a = b := Iff.rfl #align set.mem_singleton_iff Set.mem_singleton_iff @[simp] theorem setOf_eq_eq_singleton {a : α} : { n | n = a } = {a} := rfl #align set.set_of_eq_eq_singleton Set.setOf_eq_eq_singleton @[simp] theorem setOf_eq_eq_singleton' {a : α} : { x | a = x } = {a} := ext fun _ => eq_comm #align set.set_of_eq_eq_singleton' Set.setOf_eq_eq_singleton' -- TODO: again, annotation needed --Porting note (#11119): removed `simp` attribute theorem mem_singleton (a : α) : a ∈ ({a} : Set α) := @rfl _ _ #align set.mem_singleton Set.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Set α)) : x = y := h #align set.eq_of_mem_singleton Set.eq_of_mem_singleton @[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : Set α) ↔ x = y := ext_iff.trans eq_iff_eq_cancel_left #align set.singleton_eq_singleton_iff Set.singleton_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Set α) := fun _ _ => singleton_eq_singleton_iff.mp #align set.singleton_injective Set.singleton_injective theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : Set α) := H #align set.mem_singleton_of_eq Set.mem_singleton_of_eq theorem insert_eq (x : α) (s : Set α) : insert x s = ({x} : Set α) ∪ s := rfl #align set.insert_eq Set.insert_eq @[simp] theorem singleton_nonempty (a : α) : ({a} : Set α).Nonempty := ⟨a, rfl⟩ #align set.singleton_nonempty Set.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Set α) ≠ ∅ := (singleton_nonempty _).ne_empty #align set.singleton_ne_empty Set.singleton_ne_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem empty_ssubset_singleton : (∅ : Set α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align set.empty_ssubset_singleton Set.empty_ssubset_singleton @[simp] theorem singleton_subset_iff {a : α} {s : Set α} : {a} ⊆ s ↔ a ∈ s := forall_eq #align set.singleton_subset_iff Set.singleton_subset_iff theorem singleton_subset_singleton : ({a} : Set α) ⊆ {b} ↔ a = b := by simp #align set.singleton_subset_singleton Set.singleton_subset_singleton theorem set_compr_eq_eq_singleton {a : α} : { b | b = a } = {a} := rfl #align set.set_compr_eq_eq_singleton Set.set_compr_eq_eq_singleton @[simp] theorem singleton_union : {a} ∪ s = insert a s := rfl #align set.singleton_union Set.singleton_union @[simp] theorem union_singleton : s ∪ {a} = insert a s := union_comm _ _ #align set.union_singleton Set.union_singleton @[simp] theorem singleton_inter_nonempty : ({a} ∩ s).Nonempty ↔ a ∈ s := by simp only [Set.Nonempty, mem_inter_iff, mem_singleton_iff, exists_eq_left] #align set.singleton_inter_nonempty Set.singleton_inter_nonempty @[simp] theorem inter_singleton_nonempty : (s ∩ {a}).Nonempty ↔ a ∈ s := by rw [inter_comm, singleton_inter_nonempty] #align set.inter_singleton_nonempty Set.inter_singleton_nonempty @[simp] theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s := not_nonempty_iff_eq_empty.symm.trans singleton_inter_nonempty.not #align set.singleton_inter_eq_empty Set.singleton_inter_eq_empty @[simp] theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s := by rw [inter_comm, singleton_inter_eq_empty] #align set.inter_singleton_eq_empty Set.inter_singleton_eq_empty theorem nmem_singleton_empty {s : Set α} : s ∉ ({∅} : Set (Set α)) ↔ s.Nonempty := nonempty_iff_ne_empty.symm #align set.nmem_singleton_empty Set.nmem_singleton_empty instance uniqueSingleton (a : α) : Unique (↥({a} : Set α)) := ⟨⟨⟨a, mem_singleton a⟩⟩, fun ⟨_, h⟩ => Subtype.eq h⟩ #align set.unique_singleton Set.uniqueSingleton theorem eq_singleton_iff_unique_mem : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := Subset.antisymm_iff.trans <| and_comm.trans <| and_congr_left' singleton_subset_iff #align set.eq_singleton_iff_unique_mem Set.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := eq_singleton_iff_unique_mem.trans <| and_congr_left fun H => ⟨fun h' => ⟨_, h'⟩, fun ⟨x, h⟩ => H x h ▸ h⟩ #align set.eq_singleton_iff_nonempty_unique_mem Set.eq_singleton_iff_nonempty_unique_mem set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 -- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS. @[simp] theorem default_coe_singleton (x : α) : (default : ({x} : Set α)) = ⟨x, rfl⟩ := rfl #align set.default_coe_singleton Set.default_coe_singleton /-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/ section Sep variable {p q : α → Prop} {x : α} theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } := ⟨xs, px⟩ #align set.mem_sep Set.mem_sep @[simp] theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t := rfl #align set.sep_mem_eq Set.sep_mem_eq @[simp] theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x := Iff.rfl #align set.mem_sep_iff Set.mem_sep_iff theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by simp_rw [ext_iff, mem_sep_iff, and_congr_right_iff] #align set.sep_ext_iff Set.sep_ext_iff theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s := inter_eq_self_of_subset_right h #align set.sep_eq_of_subset Set.sep_eq_of_subset @[simp] theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left #align set.sep_subset Set.sep_subset @[simp] theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by simp_rw [ext_iff, mem_sep_iff, and_iff_left_iff_imp] #align set.sep_eq_self_iff_mem_true Set.sep_eq_self_iff_mem_true @[simp] theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by simp_rw [ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false_iff, not_and] #align set.sep_eq_empty_iff_mem_false Set.sep_eq_empty_iff_mem_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_true : { x ∈ s | True } = s := inter_univ s #align set.sep_true Set.sep_true --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_false : { x ∈ s | False } = ∅ := inter_empty s #align set.sep_false Set.sep_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ := empty_inter {x | p x} #align set.sep_empty Set.sep_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } := univ_inter {x | p x} #align set.sep_univ Set.sep_univ @[simp] theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } := union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p #align set.sep_union Set.sep_union @[simp] theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } := inter_inter_distrib_right s t {x | p x} #align set.sep_inter Set.sep_inter @[simp] theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } := inter_inter_distrib_left s {x | p x} {x | q x} #align set.sep_and Set.sep_and @[simp] theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } := inter_union_distrib_left s p q #align set.sep_or Set.sep_or @[simp] theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } := rfl #align set.sep_set_of Set.sep_setOf end Sep @[simp] theorem subset_singleton_iff {α : Type*} {s : Set α} {x : α} : s ⊆ {x} ↔ ∀ y ∈ s, y = x := Iff.rfl #align set.subset_singleton_iff Set.subset_singleton_iff theorem subset_singleton_iff_eq {s : Set α} {x : α} : s ⊆ {x} ↔ s = ∅ ∨ s = {x} := by obtain rfl | hs := s.eq_empty_or_nonempty · exact ⟨fun _ => Or.inl rfl, fun _ => empty_subset _⟩ · simp [eq_singleton_iff_nonempty_unique_mem, hs, hs.ne_empty] #align set.subset_singleton_iff_eq Set.subset_singleton_iff_eq theorem Nonempty.subset_singleton_iff (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff_eq.trans <| or_iff_right h.ne_empty #align set.nonempty.subset_singleton_iff Set.Nonempty.subset_singleton_iff theorem ssubset_singleton_iff {s : Set α} {x : α} : s ⊂ {x} ↔ s = ∅ := by rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] exact fun h => h ▸ (singleton_ne_empty _).symm #align set.ssubset_singleton_iff Set.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Set α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align set.eq_empty_of_ssubset_singleton Set.eq_empty_of_ssubset_singleton theorem eq_of_nonempty_of_subsingleton {α} [Subsingleton α] (s t : Set α) [Nonempty s] [Nonempty t] : s = t := nonempty_of_nonempty_subtype.eq_univ.trans nonempty_of_nonempty_subtype.eq_univ.symm theorem eq_of_nonempty_of_subsingleton' {α} [Subsingleton α] {s : Set α} (t : Set α) (hs : s.Nonempty) [Nonempty t] : s = t := have := hs.to_subtype; eq_of_nonempty_of_subsingleton s t set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_zero [Subsingleton α] [Zero α] {s : Set α} (h : s.Nonempty) : s = {0} := eq_of_nonempty_of_subsingleton' {0} h set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_one [Subsingleton α] [One α] {s : Set α} (h : s.Nonempty) : s = {1} := eq_of_nonempty_of_subsingleton' {1} h /-! ### Disjointness -/ protected theorem disjoint_iff : Disjoint s t ↔ s ∩ t ⊆ ∅ := disjoint_iff_inf_le #align set.disjoint_iff Set.disjoint_iff theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align set.disjoint_iff_inter_eq_empty Set.disjoint_iff_inter_eq_empty theorem _root_.Disjoint.inter_eq : Disjoint s t → s ∩ t = ∅ := Disjoint.eq_bot #align disjoint.inter_eq Disjoint.inter_eq theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := disjoint_iff_inf_le.trans <| forall_congr' fun _ => not_and #align set.disjoint_left Set.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [disjoint_comm, disjoint_left] #align set.disjoint_right Set.disjoint_right lemma not_disjoint_iff : ¬Disjoint s t ↔ ∃ x, x ∈ s ∧ x ∈ t := Set.disjoint_iff.not.trans <| not_forall.trans <| exists_congr fun _ ↦ not_not #align set.not_disjoint_iff Set.not_disjoint_iff lemma not_disjoint_iff_nonempty_inter : ¬ Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff #align set.not_disjoint_iff_nonempty_inter Set.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align set.nonempty.not_disjoint Set.Nonempty.not_disjoint lemma disjoint_or_nonempty_inter (s t : Set α) : Disjoint s t ∨ (s ∩ t).Nonempty := (em _).imp_right not_disjoint_iff_nonempty_inter.1 #align set.disjoint_or_nonempty_inter Set.disjoint_or_nonempty_inter lemma disjoint_iff_forall_ne : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ t → a ≠ b := by simp only [Ne, disjoint_left, @imp_not_comm _ (_ = _), forall_eq'] #align set.disjoint_iff_forall_ne Set.disjoint_iff_forall_ne alias ⟨_root_.Disjoint.ne_of_mem, _⟩ := disjoint_iff_forall_ne #align disjoint.ne_of_mem Disjoint.ne_of_mem lemma disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := d.mono_left h #align set.disjoint_of_subset_left Set.disjoint_of_subset_left lemma disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := d.mono_right h #align set.disjoint_of_subset_right Set.disjoint_of_subset_right lemma disjoint_of_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (h : Disjoint s₂ t₂) : Disjoint s₁ t₁ := h.mono hs ht #align set.disjoint_of_subset Set.disjoint_of_subset @[simp] lemma disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := disjoint_sup_left #align set.disjoint_union_left Set.disjoint_union_left @[simp] lemma disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := disjoint_sup_right #align set.disjoint_union_right Set.disjoint_union_right @[simp] lemma disjoint_empty (s : Set α) : Disjoint s ∅ := disjoint_bot_right #align set.disjoint_empty Set.disjoint_empty @[simp] lemma empty_disjoint (s : Set α) : Disjoint ∅ s := disjoint_bot_left #align set.empty_disjoint Set.empty_disjoint @[simp] lemma univ_disjoint : Disjoint univ s ↔ s = ∅ := top_disjoint #align set.univ_disjoint Set.univ_disjoint @[simp] lemma disjoint_univ : Disjoint s univ ↔ s = ∅ := disjoint_top #align set.disjoint_univ Set.disjoint_univ lemma disjoint_sdiff_left : Disjoint (t \ s) s := disjoint_sdiff_self_left #align set.disjoint_sdiff_left Set.disjoint_sdiff_left lemma disjoint_sdiff_right : Disjoint s (t \ s) := disjoint_sdiff_self_right #align set.disjoint_sdiff_right Set.disjoint_sdiff_right -- TODO: prove this in terms of a lattice lemma theorem disjoint_sdiff_inter : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right disjoint_sdiff_left #align set.disjoint_sdiff_inter Set.disjoint_sdiff_inter theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut #align set.diff_union_diff_cancel Set.diff_union_diff_cancel theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h #align set.diff_diff_eq_sdiff_union Set.diff_diff_eq_sdiff_union @[simp default+1] lemma disjoint_singleton_left : Disjoint {a} s ↔ a ∉ s := by simp [Set.disjoint_iff, subset_def] #align set.disjoint_singleton_left Set.disjoint_singleton_left @[simp] lemma disjoint_singleton_right : Disjoint s {a} ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align set.disjoint_singleton_right Set.disjoint_singleton_right lemma disjoint_singleton : Disjoint ({a} : Set α) {b} ↔ a ≠ b := by simp #align set.disjoint_singleton Set.disjoint_singleton lemma subset_diff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff #align set.subset_diff Set.subset_diff lemma ssubset_iff_sdiff_singleton : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t \ {a} := by simp [ssubset_iff_insert, subset_diff, insert_subset_iff]; aesop theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) := inf_sdiff_distrib_left _ _ _ #align set.inter_diff_distrib_left Set.inter_diff_distrib_left theorem inter_diff_distrib_right (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ (t ∩ u) := inf_sdiff_distrib_right _ _ _ #align set.inter_diff_distrib_right Set.inter_diff_distrib_right /-! ### Lemmas about complement -/ theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } := rfl #align set.compl_def Set.compl_def theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h #align set.mem_compl Set.mem_compl theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } := rfl #align set.compl_set_of Set.compl_setOf theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h #align set.not_mem_of_mem_compl Set.not_mem_of_mem_compl theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s := not_not #align set.not_mem_compl_iff Set.not_mem_compl_iff @[simp] theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot #align set.inter_compl_self Set.inter_compl_self @[simp] theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot #align set.compl_inter_self Set.compl_inter_self @[simp] theorem compl_empty : (∅ : Set α)ᶜ = univ := compl_bot #align set.compl_empty Set.compl_empty @[simp] theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup #align set.compl_union Set.compl_union theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf #align set.compl_inter Set.compl_inter @[simp] theorem compl_univ : (univ : Set α)ᶜ = ∅ := compl_top #align set.compl_univ Set.compl_univ @[simp] theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot #align set.compl_empty_iff Set.compl_empty_iff @[simp] theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top #align set.compl_univ_iff Set.compl_univ_iff theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm #align set.compl_ne_univ Set.compl_ne_univ theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ := (ne_univ_iff_exists_not_mem s).symm #align set.nonempty_compl Set.nonempty_compl @[simp] lemma nonempty_compl_of_nontrivial [Nontrivial α] (x : α) : Set.Nonempty {x}ᶜ := by obtain ⟨y, hy⟩ := exists_ne x exact ⟨y, by simp [hy]⟩ theorem mem_compl_singleton_iff {a x : α} : x ∈ ({a} : Set α)ᶜ ↔ x ≠ a := Iff.rfl #align set.mem_compl_singleton_iff Set.mem_compl_singleton_iff theorem compl_singleton_eq (a : α) : ({a} : Set α)ᶜ = { x | x ≠ a } := rfl #align set.compl_singleton_eq Set.compl_singleton_eq @[simp] theorem compl_ne_eq_singleton (a : α) : ({ x | x ≠ a } : Set α)ᶜ = {a} := compl_compl _ #align set.compl_ne_eq_singleton Set.compl_ne_eq_singleton theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ := ext fun _ => or_iff_not_and_not #align set.union_eq_compl_compl_inter_compl Set.union_eq_compl_compl_inter_compl theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ := ext fun _ => and_iff_not_or_not #align set.inter_eq_compl_compl_union_compl Set.inter_eq_compl_compl_union_compl @[simp] theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 fun _ => em _ #align set.union_compl_self Set.union_compl_self @[simp] theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self] #align set.compl_union_self Set.compl_union_self theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s _ _ #align set.compl_subset_comm Set.compl_subset_comm theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ := @le_compl_iff_le_compl _ _ _ t #align set.subset_compl_comm Set.subset_compl_comm @[simp] theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le (Set α) _ _ _ #align set.compl_subset_compl Set.compl_subset_compl @[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h theorem subset_compl_iff_disjoint_left : s ⊆ tᶜ ↔ Disjoint t s := @le_compl_iff_disjoint_left (Set α) _ _ _ #align set.subset_compl_iff_disjoint_left Set.subset_compl_iff_disjoint_left theorem subset_compl_iff_disjoint_right : s ⊆ tᶜ ↔ Disjoint s t := @le_compl_iff_disjoint_right (Set α) _ _ _ #align set.subset_compl_iff_disjoint_right Set.subset_compl_iff_disjoint_right theorem disjoint_compl_left_iff_subset : Disjoint sᶜ t ↔ t ⊆ s := disjoint_compl_left_iff #align set.disjoint_compl_left_iff_subset Set.disjoint_compl_left_iff_subset theorem disjoint_compl_right_iff_subset : Disjoint s tᶜ ↔ s ⊆ t := disjoint_compl_right_iff #align set.disjoint_compl_right_iff_subset Set.disjoint_compl_right_iff_subset alias ⟨_, _root_.Disjoint.subset_compl_right⟩ := subset_compl_iff_disjoint_right #align disjoint.subset_compl_right Disjoint.subset_compl_right alias ⟨_, _root_.Disjoint.subset_compl_left⟩ := subset_compl_iff_disjoint_left #align disjoint.subset_compl_left Disjoint.subset_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_left⟩ := disjoint_compl_left_iff_subset #align has_subset.subset.disjoint_compl_left HasSubset.Subset.disjoint_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_right⟩ := disjoint_compl_right_iff_subset #align has_subset.subset.disjoint_compl_right HasSubset.Subset.disjoint_compl_right theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t := (@isCompl_compl _ u _).le_sup_right_iff_inf_left_le #align set.subset_union_compl_iff_inter_subset Set.subset_union_compl_iff_inter_subset theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ := Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left #align set.compl_subset_iff_union Set.compl_subset_iff_union @[simp] theorem subset_compl_singleton_iff {a : α} {s : Set α} : s ⊆ {a}ᶜ ↔ a ∉ s := subset_compl_comm.trans singleton_subset_iff #align set.subset_compl_singleton_iff Set.subset_compl_singleton_iff theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c := forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or #align set.inter_subset Set.inter_subset theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t := (not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm #align set.inter_compl_nonempty_iff Set.inter_compl_nonempty_iff /-! ### Lemmas about set difference -/ theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx #align set.not_mem_diff_of_mem Set.not_mem_diff_of_mem theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left #align set.mem_of_mem_diff Set.mem_of_mem_diff theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right #align set.not_mem_of_mem_diff Set.not_mem_of_mem_diff theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm] #align set.diff_eq_compl_inter Set.diff_eq_compl_inter theorem nonempty_diff {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t := inter_compl_nonempty_iff #align set.nonempty_diff Set.nonempty_diff theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le #align set.diff_subset Set.diff_subset theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ := diff_eq_compl_inter ▸ inter_subset_left theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u := sup_sdiff_cancel' h₁ h₂ #align set.union_diff_cancel' Set.union_diff_cancel' theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h #align set.union_diff_cancel Set.union_diff_cancel theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t := Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_left Set.union_diff_cancel_left theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s := Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_right Set.union_diff_cancel_right @[simp] theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s := sup_sdiff_left_self #align set.union_diff_left Set.union_diff_left @[simp] theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align set.union_diff_right Set.union_diff_right theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u := sup_sdiff #align set.union_diff_distrib Set.union_diff_distrib theorem inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc #align set.inter_diff_assoc Set.inter_diff_assoc @[simp] theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ := inf_sdiff_self_right #align set.inter_diff_self Set.inter_diff_self @[simp] theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s := sup_inf_sdiff s t #align set.inter_union_diff Set.inter_union_diff @[simp] theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by rw [union_comm] exact sup_inf_sdiff _ _ #align set.diff_union_inter Set.diff_union_inter @[simp] theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s := inter_union_diff _ _ #align set.inter_union_compl Set.inter_union_compl @[gcongr] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff #align set.diff_subset_diff Set.diff_subset_diff @[gcongr] theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t := sdiff_le_sdiff_right ‹s₁ ≤ s₂› #align set.diff_subset_diff_left Set.diff_subset_diff_left @[gcongr] theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t := sdiff_le_sdiff_left ‹t ≤ u› #align set.diff_subset_diff_right Set.diff_subset_diff_right theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s := top_sdiff.symm #align set.compl_eq_univ_diff Set.compl_eq_univ_diff @[simp] theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ := bot_sdiff #align set.empty_diff Set.empty_diff theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff #align set.diff_eq_empty Set.diff_eq_empty @[simp] theorem diff_empty {s : Set α} : s \ ∅ = s := sdiff_bot #align set.diff_empty Set.diff_empty @[simp] theorem diff_univ (s : Set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s) #align set.diff_univ Set.diff_univ theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) := sdiff_sdiff_left #align set.diff_diff Set.diff_diff -- the following statement contains parentheses to help the reader theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t := sdiff_sdiff_comm #align set.diff_diff_comm Set.diff_diff_comm theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u := show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff #align set.diff_subset_iff Set.diff_subset_iff theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t := show s ≤ s \ t ∪ t from le_sdiff_sup #align set.subset_diff_union Set.subset_diff_union theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s := Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _) #align set.diff_union_of_subset Set.diff_union_of_subset @[simp] theorem diff_singleton_subset_iff {x : α} {s t : Set α} : s \ {x} ⊆ t ↔ s ⊆ insert x t := by rw [← union_singleton, union_comm] apply diff_subset_iff #align set.diff_singleton_subset_iff Set.diff_singleton_subset_iff theorem subset_diff_singleton {x : α} {s t : Set α} (h : s ⊆ t) (hx : x ∉ s) : s ⊆ t \ {x} := subset_inter h <| subset_compl_comm.1 <| singleton_subset_iff.2 hx #align set.subset_diff_singleton Set.subset_diff_singleton theorem subset_insert_diff_singleton (x : α) (s : Set α) : s ⊆ insert x (s \ {x}) := by rw [← diff_singleton_subset_iff] #align set.subset_insert_diff_singleton Set.subset_insert_diff_singleton theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t := show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm #align set.diff_subset_comm Set.diff_subset_comm theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf #align set.diff_inter Set.diff_inter theorem diff_inter_diff {s t u : Set α} : s \ t ∩ (s \ u) = s \ (t ∪ u) := sdiff_sup.symm #align set.diff_inter_diff Set.diff_inter_diff theorem diff_compl : s \ tᶜ = s ∩ t := sdiff_compl #align set.diff_compl Set.diff_compl theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u := sdiff_sdiff_right' #align set.diff_diff_right Set.diff_diff_right @[simp] theorem insert_diff_of_mem (s) (h : a ∈ t) : insert a s \ t = s \ t := by ext constructor <;> simp (config := { contextual := true }) [or_imp, h] #align set.insert_diff_of_mem Set.insert_diff_of_mem theorem insert_diff_of_not_mem (s) (h : a ∉ t) : insert a s \ t = insert a (s \ t) := by classical ext x by_cases h' : x ∈ t · have : x ≠ a := by intro H rw [H] at h' exact h h' simp [h, h', this] · simp [h, h'] #align set.insert_diff_of_not_mem Set.insert_diff_of_not_mem theorem insert_diff_self_of_not_mem {a : α} {s : Set α} (h : a ∉ s) : insert a s \ {a} = s := by ext x simp [and_iff_left_of_imp fun hx : x ∈ s => show x ≠ a from fun hxa => h <| hxa ▸ hx] #align set.insert_diff_self_of_not_mem Set.insert_diff_self_of_not_mem @[simp] theorem insert_diff_eq_singleton {a : α} {s : Set α} (h : a ∉ s) : insert a s \ s = {a} := by ext rw [Set.mem_diff, Set.mem_insert_iff, Set.mem_singleton_iff, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] rintro rfl exact h #align set.insert_diff_eq_singleton Set.insert_diff_eq_singleton theorem inter_insert_of_mem (h : a ∈ s) : s ∩ insert a t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.inter_insert_of_mem Set.inter_insert_of_mem theorem insert_inter_of_mem (h : a ∈ t) : insert a s ∩ t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.insert_inter_of_mem Set.insert_inter_of_mem theorem inter_insert_of_not_mem (h : a ∉ s) : s ∩ insert a t = s ∩ t := ext fun _ => and_congr_right fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.inter_insert_of_not_mem Set.inter_insert_of_not_mem theorem insert_inter_of_not_mem (h : a ∉ t) : insert a s ∩ t = s ∩ t := ext fun _ => and_congr_left fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.insert_inter_of_not_mem Set.insert_inter_of_not_mem @[simp] theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t := sup_sdiff_self _ _ #align set.union_diff_self Set.union_diff_self @[simp] theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t := sdiff_sup_self _ _ #align set.diff_union_self Set.diff_union_self @[simp] theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ := inf_sdiff_self_left #align set.diff_inter_self Set.diff_inter_self @[simp] theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ #align set.diff_inter_self_eq_diff Set.diff_inter_self_eq_diff @[simp] theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ #align set.diff_self_inter Set.diff_self_inter @[simp] theorem diff_singleton_eq_self {a : α} {s : Set α} (h : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [h] #align set.diff_singleton_eq_self Set.diff_singleton_eq_self @[simp] theorem diff_singleton_sSubset {s : Set α} {a : α} : s \ {a} ⊂ s ↔ a ∈ s := sdiff_le.lt_iff_ne.trans <| sdiff_eq_left.not.trans <| by simp #align set.diff_singleton_ssubset Set.diff_singleton_sSubset @[simp] theorem insert_diff_singleton {a : α} {s : Set α} : insert a (s \ {a}) = insert a s := by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union] #align set.insert_diff_singleton Set.insert_diff_singleton theorem insert_diff_singleton_comm (hab : a ≠ b) (s : Set α) : insert a (s \ {b}) = insert a s \ {b} := by simp_rw [← union_singleton, union_diff_distrib, diff_singleton_eq_self (mem_singleton_iff.not.2 hab.symm)] #align set.insert_diff_singleton_comm Set.insert_diff_singleton_comm --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem diff_self {s : Set α} : s \ s = ∅ := sdiff_self #align set.diff_self Set.diff_self theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self #align set.diff_diff_right_self Set.diff_diff_right_self theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s := sdiff_sdiff_eq_self h #align set.diff_diff_cancel_left Set.diff_diff_cancel_left theorem mem_diff_singleton {x y : α} {s : Set α} : x ∈ s \ {y} ↔ x ∈ s ∧ x ≠ y := Iff.rfl #align set.mem_diff_singleton Set.mem_diff_singleton theorem mem_diff_singleton_empty {t : Set (Set α)} : s ∈ t \ {∅} ↔ s ∈ t ∧ s.Nonempty := mem_diff_singleton.trans <| and_congr_right' nonempty_iff_ne_empty.symm #align set.mem_diff_singleton_empty Set.mem_diff_singleton_empty theorem subset_insert_iff {s t : Set α} {x : α} : s ⊆ insert x t ↔ s ⊆ t ∨ (x ∈ s ∧ s \ {x} ⊆ t) := by rw [← diff_singleton_subset_iff] by_cases hx : x ∈ s · rw [and_iff_right hx, or_iff_right_of_imp diff_subset.trans] rw [diff_singleton_eq_self hx, or_iff_left_of_imp And.right] theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf #align set.union_eq_diff_union_diff_union_inter Set.union_eq_diff_union_diff_union_inter /-! ### Lemmas about pairs -/ --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem pair_eq_singleton (a : α) : ({a, a} : Set α) = {a} := union_self _ #align set.pair_eq_singleton Set.pair_eq_singleton theorem pair_comm (a b : α) : ({a, b} : Set α) = {b, a} := union_comm _ _ #align set.pair_comm Set.pair_comm theorem pair_eq_pair_iff {x y z w : α} : ({x, y} : Set α) = {z, w} ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp [subset_antisymm_iff, insert_subset_iff]; aesop #align set.pair_eq_pair_iff Set.pair_eq_pair_iff theorem pair_diff_left (hne : a ≠ b) : ({a, b} : Set α) \ {a} = {b} := by rw [insert_diff_of_mem _ (mem_singleton a), diff_singleton_eq_self (by simpa)] theorem pair_diff_right (hne : a ≠ b) : ({a, b} : Set α) \ {b} = {a} := by rw [pair_comm, pair_diff_left hne.symm] theorem pair_subset_iff : {a, b} ⊆ s ↔ a ∈ s ∧ b ∈ s := by rw [insert_subset_iff, singleton_subset_iff] theorem pair_subset (ha : a ∈ s) (hb : b ∈ s) : {a, b} ⊆ s := pair_subset_iff.2 ⟨ha,hb⟩ theorem subset_pair_iff : s ⊆ {a, b} ↔ ∀ x ∈ s, x = a ∨ x = b := by simp [subset_def] theorem subset_pair_iff_eq {x y : α} : s ⊆ {x, y} ↔ s = ∅ ∨ s = {x} ∨ s = {y} ∨ s = {x, y} := by refine ⟨?_, by rintro (rfl | rfl | rfl | rfl) <;> simp [pair_subset_iff]⟩ rw [subset_insert_iff, subset_singleton_iff_eq, subset_singleton_iff_eq, ← subset_empty_iff (s := s \ {x}), diff_subset_iff, union_empty, subset_singleton_iff_eq] have h : x ∈ s → {y} = s \ {x} → s = {x,y} := fun h₁ h₂ ↦ by simp [h₁, h₂] tauto theorem Nonempty.subset_pair_iff_eq (hs : s.Nonempty) : s ⊆ {a, b} ↔ s = {a} ∨ s = {b} ∨ s = {a, b} := by rw [Set.subset_pair_iff_eq, or_iff_right]; exact hs.ne_empty /-! ### Symmetric difference -/ section open scoped symmDiff theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s := Iff.rfl #align set.mem_symm_diff Set.mem_symmDiff protected theorem symmDiff_def (s t : Set α) : s ∆ t = s \ t ∪ t \ s := rfl #align set.symm_diff_def Set.symmDiff_def theorem symmDiff_subset_union : s ∆ t ⊆ s ∪ t := @symmDiff_le_sup (Set α) _ _ _ #align set.symm_diff_subset_union Set.symmDiff_subset_union @[simp] theorem symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t := symmDiff_eq_bot #align set.symm_diff_eq_empty Set.symmDiff_eq_empty @[simp] theorem symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t := nonempty_iff_ne_empty.trans symmDiff_eq_empty.not #align set.symm_diff_nonempty Set.symmDiff_nonempty theorem inter_symmDiff_distrib_left (s t u : Set α) : s ∩ t ∆ u = (s ∩ t) ∆ (s ∩ u) := inf_symmDiff_distrib_left _ _ _ #align set.inter_symm_diff_distrib_left Set.inter_symmDiff_distrib_left theorem inter_symmDiff_distrib_right (s t u : Set α) : s ∆ t ∩ u = (s ∩ u) ∆ (t ∩ u) := inf_symmDiff_distrib_right _ _ _ #align set.inter_symm_diff_distrib_right Set.inter_symmDiff_distrib_right theorem subset_symmDiff_union_symmDiff_left (h : Disjoint s t) : u ⊆ s ∆ u ∪ t ∆ u := h.le_symmDiff_sup_symmDiff_left #align set.subset_symm_diff_union_symm_diff_left Set.subset_symmDiff_union_symmDiff_left theorem subset_symmDiff_union_symmDiff_right (h : Disjoint t u) : s ⊆ s ∆ t ∪ s ∆ u := h.le_symmDiff_sup_symmDiff_right #align set.subset_symm_diff_union_symm_diff_right Set.subset_symmDiff_union_symmDiff_right end /-! ### Powerset -/ #align set.powerset Set.powerset theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h #align set.mem_powerset Set.mem_powerset theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h #align set.subset_of_mem_powerset Set.subset_of_mem_powerset @[simp] theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s := Iff.rfl #align set.mem_powerset_iff Set.mem_powerset_iff theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t := ext fun _ => subset_inter_iff #align set.powerset_inter Set.powerset_inter @[simp] theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t := ⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩ #align set.powerset_mono Set.powerset_mono theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2 #align set.monotone_powerset Set.monotone_powerset @[simp] theorem powerset_nonempty : (𝒫 s).Nonempty := ⟨∅, fun _ h => empty_subset s h⟩ #align set.powerset_nonempty Set.powerset_nonempty @[simp] theorem powerset_empty : 𝒫(∅ : Set α) = {∅} := ext fun _ => subset_empty_iff #align set.powerset_empty Set.powerset_empty @[simp] theorem powerset_univ : 𝒫(univ : Set α) = univ := eq_univ_of_forall subset_univ #align set.powerset_univ Set.powerset_univ /-- The powerset of a singleton contains only `∅` and the singleton itself. -/ theorem powerset_singleton (x : α) : 𝒫({x} : Set α) = {∅, {x}} := by ext y rw [mem_powerset_iff, subset_singleton_iff_eq, mem_insert_iff, mem_singleton_iff] #align set.powerset_singleton Set.powerset_singleton /-! ### Sets defined as an if-then-else -/ theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) : (x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h := by split_ifs with hp · exact ⟨fun hx => ⟨fun _ => hx, fun hnp => (hnp hp).elim⟩, fun hx => hx.1 hp⟩ · exact ⟨fun hx => ⟨fun h => (hp h).elim, fun _ => hx⟩, fun hx => hx.2 hp⟩ theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by split_ifs <;> simp_all #align set.mem_dite_univ_right Set.mem_dite_univ_right @[simp] theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t Set.univ ↔ p → x ∈ t := mem_dite_univ_right p (fun _ => t) x #align set.mem_ite_univ_right Set.mem_ite_univ_right theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by split_ifs <;> simp_all #align set.mem_dite_univ_left Set.mem_dite_univ_left @[simp] theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p Set.univ t ↔ ¬p → x ∈ t := mem_dite_univ_left p (fun _ => t) x #align set.mem_ite_univ_left Set.mem_ite_univ_left theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false, not_not] exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩ #align set.mem_dite_empty_right Set.mem_dite_empty_right @[simp] theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t ∅ ↔ p ∧ x ∈ t := (mem_dite_empty_right p (fun _ => t) x).trans (by simp) #align set.mem_ite_empty_right Set.mem_ite_empty_right theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false] exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩ #align set.mem_dite_empty_left Set.mem_dite_empty_left @[simp] theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t := (mem_dite_empty_left p (fun _ => t) x).trans (by simp) #align set.mem_ite_empty_left Set.mem_ite_empty_left /-! ### If-then-else for sets -/ /-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`. Defined as `s ∩ t ∪ s' \ t`. -/ protected def ite (t s s' : Set α) : Set α := s ∩ t ∪ s' \ t #align set.ite Set.ite @[simp] theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty] #align set.ite_inter_self Set.ite_inter_self @[simp] theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq] #align set.ite_compl Set.ite_compl @[simp] theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by rw [← ite_compl, ite_inter_self] #align set.ite_inter_compl_self Set.ite_inter_compl_self @[simp] theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t := ite_inter_compl_self t s s' #align set.ite_diff_self Set.ite_diff_self @[simp] theorem ite_same (t s : Set α) : t.ite s s = s := inter_union_diff _ _ #align set.ite_same Set.ite_same @[simp] theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite] #align set.ite_left Set.ite_left @[simp] theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite] #align set.ite_right Set.ite_right @[simp] theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite] #align set.ite_empty Set.ite_empty @[simp] theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite] #align set.ite_univ Set.ite_univ @[simp] theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite] #align set.ite_empty_left Set.ite_empty_left @[simp] theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite] #align set.ite_empty_right Set.ite_empty_right theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') : t.ite s₁ s₁' ⊆ t.ite s₂ s₂' := union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h') #align set.ite_mono Set.ite_mono theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' := union_subset_union inter_subset_left diff_subset #align set.ite_subset_union Set.ite_subset_union theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' := ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right #align set.inter_subset_ite Set.inter_subset_ite theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) : t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by ext x simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union] tauto #align set.ite_inter_inter Set.ite_inter_inter theorem ite_inter (t s₁ s₂ s : Set α) : t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s := by rw [ite_inter_inter, ite_same] #align set.ite_inter Set.ite_inter theorem ite_inter_of_inter_eq (t : Set α) {s₁ s₂ s : Set α} (h : s₁ ∩ s = s₂ ∩ s) : t.ite s₁ s₂ ∩ s = s₁ ∩ s := by rw [← ite_inter, ← h, ite_same] #align set.ite_inter_of_inter_eq Set.ite_inter_of_inter_eq theorem subset_ite {t s s' u : Set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' := by simp only [subset_def, ← forall_and] refine forall_congr' fun x => ?_ by_cases hx : x ∈ t <;> simp [*, Set.ite] #align set.subset_ite Set.subset_ite theorem ite_eq_of_subset_left (t : Set α) {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) : t.ite s₁ s₂ = s₁ ∪ (s₂ \ t) := by ext x by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_right_of_imp (@h x)] theorem ite_eq_of_subset_right (t : Set α) {s₁ s₂ : Set α} (h : s₂ ⊆ s₁) : t.ite s₁ s₂ = (s₁ ∩ t) ∪ s₂ := by ext x by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_left_of_imp (@h x)] section Preorder variable [Preorder α] [Preorder β] {f : α → β} -- Porting note: -- If we decide we want `Elem` to semireducible rather than reducible, we will need: -- instance : Preorder (↑s) := Subtype.instPreorderSubtype _ -- here, along with appropriate lemmas. theorem monotoneOn_iff_monotone : MonotoneOn f s ↔ Monotone fun a : s => f a := by simp [Monotone, MonotoneOn] #align set.monotone_on_iff_monotone Set.monotoneOn_iff_monotone theorem antitoneOn_iff_antitone : AntitoneOn f s ↔ Antitone fun a : s => f a := by simp [Antitone, AntitoneOn] #align set.antitone_on_iff_antitone Set.antitoneOn_iff_antitone theorem strictMonoOn_iff_strictMono : StrictMonoOn f s ↔ StrictMono fun a : s => f a := by simp [StrictMono, StrictMonoOn] #align set.strict_mono_on_iff_strict_mono Set.strictMonoOn_iff_strictMono theorem strictAntiOn_iff_strictAnti : StrictAntiOn f s ↔ StrictAnti fun a : s => f a := by simp [StrictAnti, StrictAntiOn] #align set.strict_anti_on_iff_strict_anti Set.strictAntiOn_iff_strictAnti end Preorder section LinearOrder variable [LinearOrder α] [LinearOrder β] {f : α → β} /-- A function between linear orders which is neither monotone nor antitone makes a dent upright or downright. -/ theorem not_monotoneOn_not_antitoneOn_iff_exists_le_le : ¬MonotoneOn f s ∧ ¬AntitoneOn f s ↔ ∃ᵉ (a ∈ s) (b ∈ s) (c ∈ s), a ≤ b ∧ b ≤ c ∧ (f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) := by simp [monotoneOn_iff_monotone, antitoneOn_iff_antitone, and_assoc, exists_and_left, not_monotone_not_antitone_iff_exists_le_le, @and_left_comm (_ ∈ s)] #align set.not_monotone_on_not_antitone_on_iff_exists_le_le Set.not_monotoneOn_not_antitoneOn_iff_exists_le_le /-- A function between linear orders which is neither monotone nor antitone makes a dent upright or downright. -/ theorem not_monotoneOn_not_antitoneOn_iff_exists_lt_lt : ¬MonotoneOn f s ∧ ¬AntitoneOn f s ↔ ∃ᵉ (a ∈ s) (b ∈ s) (c ∈ s), a < b ∧ b < c ∧ (f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) := by simp [monotoneOn_iff_monotone, antitoneOn_iff_antitone, and_assoc, exists_and_left, not_monotone_not_antitone_iff_exists_lt_lt, @and_left_comm (_ ∈ s)] #align set.not_monotone_on_not_antitone_on_iff_exists_lt_lt Set.not_monotoneOn_not_antitoneOn_iff_exists_lt_lt end LinearOrder end Set open Set namespace Function variable {ι : Sort*} {α : Type*} {β : Type*} {f : α → β} theorem Injective.nonempty_apply_iff {f : Set α → Set β} (hf : Injective f) (h2 : f ∅ = ∅) {s : Set α} : (f s).Nonempty ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, ← h2, nonempty_iff_ne_empty, hf.ne_iff] #align function.injective.nonempty_apply_iff Function.Injective.nonempty_apply_iff end Function open Function namespace Set /-! ### Lemmas about `inclusion`, the injection of subtypes induced by `⊆` -/ section Inclusion variable {α : Type*} {s t u : Set α} /-- `inclusion` is the "identity" function between two subsets `s` and `t`, where `s ⊆ t` -/ def inclusion (h : s ⊆ t) : s → t := fun x : s => (⟨x, h x.2⟩ : t) #align set.inclusion Set.inclusion @[simp] theorem inclusion_self (x : s) : inclusion Subset.rfl x = x := by cases x rfl #align set.inclusion_self Set.inclusion_self theorem inclusion_eq_id (h : s ⊆ s) : inclusion h = id := funext inclusion_self #align set.inclusion_eq_id Set.inclusion_eq_id @[simp] theorem inclusion_mk {h : s ⊆ t} (a : α) (ha : a ∈ s) : inclusion h ⟨a, ha⟩ = ⟨a, h ha⟩ := rfl #align set.inclusion_mk Set.inclusion_mk theorem inclusion_right (h : s ⊆ t) (x : t) (m : (x : α) ∈ s) : inclusion h ⟨x, m⟩ = x := by cases x rfl #align set.inclusion_right Set.inclusion_right @[simp]
Mathlib/Data/Set/Basic.lean
2,466
2,469
theorem inclusion_inclusion (hst : s ⊆ t) (htu : t ⊆ u) (x : s) : inclusion htu (inclusion hst x) = inclusion (hst.trans htu) x := by
cases 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, Yaël Dillies -/ import Mathlib.Data.Set.Lattice import Mathlib.Data.SetLike.Basic import Mathlib.Order.GaloisConnection import Mathlib.Order.Hom.Basic #align_import order.closure from "leanprover-community/mathlib"@"f252872231e87a5db80d9938fc05530e70f23a94" /-! # Closure operators between preorders We define (bundled) closure operators on a preorder as monotone (increasing), extensive (inflationary) and idempotent functions. We define closed elements for the operator as elements which are fixed by it. Lower adjoints to a function between preorders `u : β → α` allow to generalise closure operators to situations where the closure operator we are dealing with naturally decomposes as `u ∘ l` where `l` is a worthy function to have on its own. Typical examples include `l : Set G → Subgroup G := Subgroup.closure`, `u : Subgroup G → Set G := (↑)`, where `G` is a group. This shows there is a close connection between closure operators, lower adjoints and Galois connections/insertions: every Galois connection induces a lower adjoint which itself induces a closure operator by composition (see `GaloisConnection.lowerAdjoint` and `LowerAdjoint.closureOperator`), and every closure operator on a partial order induces a Galois insertion from the set of closed elements to the underlying type (see `ClosureOperator.gi`). ## Main definitions * `ClosureOperator`: A closure operator is a monotone function `f : α → α` such that `∀ x, x ≤ f x` and `∀ x, f (f x) = f x`. * `LowerAdjoint`: A lower adjoint to `u : β → α` is a function `l : α → β` such that `l` and `u` form a Galois connection. ## Implementation details Although `LowerAdjoint` is technically a generalisation of `ClosureOperator` (by defining `toFun := id`), it is desirable to have both as otherwise `id`s would be carried all over the place when using concrete closure operators such as `ConvexHull`. `LowerAdjoint` really is a semibundled `structure` version of `GaloisConnection`. ## References * https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets -/ open Set /-! ### Closure operator -/ variable (α : Type*) {ι : Sort*} {κ : ι → Sort*} /-- A closure operator on the preorder `α` is a monotone function which is extensive (every `x` is less than its closure) and idempotent. -/ structure ClosureOperator [Preorder α] extends α →o α where /-- An element is less than or equal its closure -/ le_closure' : ∀ x, x ≤ toFun x /-- Closures are idempotent -/ idempotent' : ∀ x, toFun (toFun x) = toFun x /-- Predicate for an element to be closed. By default, this is defined as `c.IsClosed x := (c x = x)` (see `isClosed_iff`). We allow an override to fix definitional equalities. -/ IsClosed (x : α) : Prop := toFun x = x isClosed_iff {x : α} : IsClosed x ↔ toFun x = x := by aesop #align closure_operator ClosureOperator namespace ClosureOperator instance [Preorder α] : FunLike (ClosureOperator α) α α where coe c := c.1 coe_injective' := by rintro ⟨⟩ ⟨⟩ h; obtain rfl := DFunLike.ext' h; congr with x; simp_all instance [Preorder α] : OrderHomClass (ClosureOperator α) α α where map_rel f _ _ h := f.mono h initialize_simps_projections ClosureOperator (toFun → apply, IsClosed → isClosed) /-- If `c` is a closure operator on `α` and `e` an order-isomorphism between `α` and `β` then `e ∘ c ∘ e⁻¹` is a closure operator on `β`. -/ @[simps apply] def conjBy {α β} [Preorder α] [Preorder β] (c : ClosureOperator α) (e : α ≃o β) : ClosureOperator β where toFun := e.conj c IsClosed b := c.IsClosed (e.symm b) monotone' _ _ h := (map_le_map_iff e).mpr <| c.monotone <| (map_le_map_iff e.symm).mpr h le_closure' _ := e.symm_apply_le.mp (c.le_closure' _) idempotent' _ := congrArg e <| Eq.trans (congrArg c (e.symm_apply_apply _)) (c.idempotent' _) isClosed_iff := Iff.trans c.isClosed_iff e.eq_symm_apply lemma conjBy_refl {α} [Preorder α] (c : ClosureOperator α) : c.conjBy (OrderIso.refl α) = c := rfl lemma conjBy_trans {α β γ} [Preorder α] [Preorder β] [Preorder γ] (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : ClosureOperator α) : c.conjBy (e₁.trans e₂) = (c.conjBy e₁).conjBy e₂ := rfl section PartialOrder variable [PartialOrder α] /-- The identity function as a closure operator. -/ @[simps!] def id : ClosureOperator α where toOrderHom := OrderHom.id le_closure' _ := le_rfl idempotent' _ := rfl IsClosed _ := True #align closure_operator.id ClosureOperator.id #align closure_operator.id_apply ClosureOperator.id_apply #align closure_operator.closed ClosureOperator.IsClosed #align closure_operator.mem_closed_iff ClosureOperator.isClosed_iff instance : Inhabited (ClosureOperator α) := ⟨id α⟩ variable {α} [PartialOrder α] (c : ClosureOperator α) @[ext] theorem ext : ∀ c₁ c₂ : ClosureOperator α, (∀ x, c₁ x = c₂ x) → c₁ = c₂ := DFunLike.ext /-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) ≤ f x`. -/ @[simps] def mk' (f : α → α) (hf₁ : Monotone f) (hf₂ : ∀ x, x ≤ f x) (hf₃ : ∀ x, f (f x) ≤ f x) : ClosureOperator α where toFun := f monotone' := hf₁ le_closure' := hf₂ idempotent' x := (hf₃ x).antisymm (hf₁ (hf₂ x)) #align closure_operator.mk' ClosureOperator.mk' #align closure_operator.mk'_apply ClosureOperator.mk'_apply /-- Convenience constructor for a closure operator using the weaker minimality axiom: `x ≤ f y → f x ≤ f y`, which is sometimes easier to prove in practice. -/ @[simps] def mk₂ (f : α → α) (hf : ∀ x, x ≤ f x) (hmin : ∀ ⦃x y⦄, x ≤ f y → f x ≤ f y) : ClosureOperator α where toFun := f monotone' _ y hxy := hmin (hxy.trans (hf y)) le_closure' := hf idempotent' _ := (hmin le_rfl).antisymm (hf _) #align closure_operator.mk₂ ClosureOperator.mk₂ #align closure_operator.mk₂_apply ClosureOperator.mk₂_apply /-- Construct a closure operator from an inflationary function `f` and a "closedness" predicate `p` witnessing minimality of `f x` among closed elements greater than `x`. -/ @[simps!] def ofPred (f : α → α) (p : α → Prop) (hf : ∀ x, x ≤ f x) (hfp : ∀ x, p (f x)) (hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y) : ClosureOperator α where __ := mk₂ f hf fun _ y hxy => hmin hxy (hfp y) IsClosed := p isClosed_iff := ⟨fun hx ↦ (hmin le_rfl hx).antisymm <| hf _, fun hx ↦ hx ▸ hfp _⟩ #align closure_operator.mk₃ ClosureOperator.ofPred #align closure_operator.mk₃_apply ClosureOperator.ofPred_apply #align closure_operator.mem_mk₃_closed ClosureOperator.ofPred_isClosed #noalign closure_operator.closure_mem_ofPred #noalign closure_operator.closure_le_ofPred_iff @[mono] theorem monotone : Monotone c := c.monotone' #align closure_operator.monotone ClosureOperator.monotone /-- Every element is less than its closure. This property is sometimes referred to as extensivity or inflationarity. -/ theorem le_closure (x : α) : x ≤ c x := c.le_closure' x #align closure_operator.le_closure ClosureOperator.le_closure @[simp] theorem idempotent (x : α) : c (c x) = c x := c.idempotent' x #align closure_operator.idempotent ClosureOperator.idempotent @[simp] lemma isClosed_closure (x : α) : c.IsClosed (c x) := c.isClosed_iff.2 <| c.idempotent x #align closure_operator.closure_is_closed ClosureOperator.isClosed_closure /-- The type of elements closed under a closure operator. -/ abbrev Closeds := {x // c.IsClosed x} /-- Send an element to a closed element (by taking the closure). -/ def toCloseds (x : α) : c.Closeds := ⟨c x, c.isClosed_closure x⟩ #align closure_operator.to_closed ClosureOperator.toCloseds variable {c} {x y : α} theorem IsClosed.closure_eq : c.IsClosed x → c x = x := c.isClosed_iff.1 #align closure_operator.closure_eq_self_of_mem_closed ClosureOperator.IsClosed.closure_eq theorem isClosed_iff_closure_le : c.IsClosed x ↔ c x ≤ x := ⟨fun h ↦ h.closure_eq.le, fun h ↦ c.isClosed_iff.2 <| h.antisymm <| c.le_closure x⟩ #align closure_operator.mem_closed_iff_closure_le ClosureOperator.isClosed_iff_closure_le /-- The set of closed elements for `c` is exactly its range. -/ theorem setOf_isClosed_eq_range_closure : {x | c.IsClosed x} = Set.range c := by ext x; exact ⟨fun hx ↦ ⟨x, hx.closure_eq⟩, by rintro ⟨y, rfl⟩; exact c.isClosed_closure _⟩ #align closure_operator.closed_eq_range_close ClosureOperator.setOf_isClosed_eq_range_closure theorem le_closure_iff : x ≤ c y ↔ c x ≤ c y := ⟨fun h ↦ c.idempotent y ▸ c.monotone h, (c.le_closure x).trans⟩ #align closure_operator.le_closure_iff ClosureOperator.le_closure_iff @[simp] theorem IsClosed.closure_le_iff (hy : c.IsClosed y) : c x ≤ y ↔ x ≤ y := by rw [← hy.closure_eq, ← le_closure_iff] #align closure_operator.closure_le_closed_iff_le ClosureOperator.IsClosed.closure_le_iff lemma closure_min (hxy : x ≤ y) (hy : c.IsClosed y) : c x ≤ y := hy.closure_le_iff.2 hxy lemma closure_isGLB (x : α) : IsGLB { y | x ≤ y ∧ c.IsClosed y } (c x) where left _ := and_imp.mpr closure_min right _ h := h ⟨c.le_closure x, c.isClosed_closure x⟩ theorem ext_isClosed (c₁ c₂ : ClosureOperator α) (h : ∀ x, c₁.IsClosed x ↔ c₂.IsClosed x) : c₁ = c₂ := ext c₁ c₂ <| fun x => IsGLB.unique (c₁.closure_isGLB x) <| (Set.ext (and_congr_right' <| h ·)).substr (c₂.closure_isGLB x) /-- A closure operator is equal to the closure operator obtained by feeding `c.closed` into the `ofPred` constructor. -/ theorem eq_ofPred_closed (c : ClosureOperator α) : c = ofPred c c.IsClosed c.le_closure c.isClosed_closure fun x y ↦ closure_min := by ext rfl #align closure_operator.eq_mk₃_closed ClosureOperator.eq_ofPred_closed end PartialOrder variable {α} section OrderTop variable [PartialOrder α] [OrderTop α] (c : ClosureOperator α) @[simp] theorem closure_top : c ⊤ = ⊤ := le_top.antisymm (c.le_closure _) #align closure_operator.closure_top ClosureOperator.closure_top @[simp] lemma isClosed_top : c.IsClosed ⊤ := c.isClosed_iff.2 c.closure_top #align closure_operator.top_mem_closed ClosureOperator.isClosed_top end OrderTop theorem closure_inf_le [SemilatticeInf α] (c : ClosureOperator α) (x y : α) : c (x ⊓ y) ≤ c x ⊓ c y := c.monotone.map_inf_le _ _ #align closure_operator.closure_inf_le ClosureOperator.closure_inf_le section SemilatticeSup variable [SemilatticeSup α] (c : ClosureOperator α) theorem closure_sup_closure_le (x y : α) : c x ⊔ c y ≤ c (x ⊔ y) := c.monotone.le_map_sup _ _ #align closure_operator.closure_sup_closure_le ClosureOperator.closure_sup_closure_le theorem closure_sup_closure_left (x y : α) : c (c x ⊔ y) = c (x ⊔ y) := (le_closure_iff.1 (sup_le (c.monotone le_sup_left) (le_sup_right.trans (c.le_closure _)))).antisymm (c.monotone (sup_le_sup_right (c.le_closure _) _)) #align closure_operator.closure_sup_closure_left ClosureOperator.closure_sup_closure_left theorem closure_sup_closure_right (x y : α) : c (x ⊔ c y) = c (x ⊔ y) := by rw [sup_comm, closure_sup_closure_left, sup_comm (a := x)] #align closure_operator.closure_sup_closure_right ClosureOperator.closure_sup_closure_right theorem closure_sup_closure (x y : α) : c (c x ⊔ c y) = c (x ⊔ y) := by rw [closure_sup_closure_left, closure_sup_closure_right] #align closure_operator.closure_sup_closure ClosureOperator.closure_sup_closure end SemilatticeSup section CompleteLattice variable [CompleteLattice α] (c : ClosureOperator α) {p : α → Prop} /-- Define a closure operator from a predicate that's preserved under infima. -/ @[simps!] def ofCompletePred (p : α → Prop) (hsinf : ∀ s, (∀ a ∈ s, p a) → p (sInf s)) : ClosureOperator α := ofPred (fun a ↦ ⨅ b : {b // a ≤ b ∧ p b}, b) p (fun a ↦ by set_option tactic.skipAssignedInstances false in simp [forall_swap]) (fun a ↦ hsinf _ <| forall_mem_range.2 fun b ↦ b.2.2) (fun a b hab hb ↦ iInf_le_of_le ⟨b, hab, hb⟩ le_rfl) theorem sInf_isClosed {c : ClosureOperator α} {S : Set α} (H : ∀ x ∈ S, c.IsClosed x) : c.IsClosed (sInf S) := isClosed_iff_closure_le.mpr <| le_of_le_of_eq c.monotone.map_sInf_le <| Eq.trans (biInf_congr (c.isClosed_iff.mp <| H · ·)) sInf_eq_iInf.symm @[simp] theorem closure_iSup_closure (f : ι → α) : c (⨆ i, c (f i)) = c (⨆ i, f i) := le_antisymm (le_closure_iff.1 <| iSup_le fun i => c.monotone <| le_iSup f i) <| c.monotone <| iSup_mono fun _ => c.le_closure _ #align closure_operator.closure_supr_closure ClosureOperator.closure_iSup_closure @[simp] theorem closure_iSup₂_closure (f : ∀ i, κ i → α) : c (⨆ (i) (j), c (f i j)) = c (⨆ (i) (j), f i j) := le_antisymm (le_closure_iff.1 <| iSup₂_le fun i j => c.monotone <| le_iSup₂ i j) <| c.monotone <| iSup₂_mono fun _ _ => c.le_closure _ #align closure_operator.closure_supr₂_closure ClosureOperator.closure_iSup₂_closure end CompleteLattice end ClosureOperator /-- Conjugating `ClosureOperators` on `α` and on `β` by a fixed isomorphism `e : α ≃o β` gives an equivalence `ClosureOperator α ≃ ClosureOperator β`. -/ @[simps apply symm_apply] def OrderIso.equivClosureOperator {α β} [Preorder α] [Preorder β] (e : α ≃o β) : ClosureOperator α ≃ ClosureOperator β where toFun c := c.conjBy e invFun c := c.conjBy e.symm left_inv c := Eq.trans (c.conjBy_trans _ _).symm <| Eq.trans (congrArg _ e.self_trans_symm) c.conjBy_refl right_inv c := Eq.trans (c.conjBy_trans _ _).symm <| Eq.trans (congrArg _ e.symm_trans_self) c.conjBy_refl /-! ### Lower adjoint -/ variable {α} {β : Type*} /-- A lower adjoint of `u` on the preorder `α` is a function `l` such that `l` and `u` form a Galois connection. It allows us to define closure operators whose output does not match the input. In practice, `u` is often `(↑) : β → α`. -/ structure LowerAdjoint [Preorder α] [Preorder β] (u : β → α) where /-- The underlying function -/ toFun : α → β /-- The underlying function is a lower adjoint. -/ gc' : GaloisConnection toFun u #align lower_adjoint LowerAdjoint namespace LowerAdjoint variable (α) /-- The identity function as a lower adjoint to itself. -/ @[simps] protected def id [Preorder α] : LowerAdjoint (id : α → α) where toFun x := x gc' := GaloisConnection.id #align lower_adjoint.id LowerAdjoint.id #align lower_adjoint.id_to_fun LowerAdjoint.id_toFun variable {α} instance [Preorder α] : Inhabited (LowerAdjoint (id : α → α)) := ⟨LowerAdjoint.id α⟩ section Preorder variable [Preorder α] [Preorder β] {u : β → α} (l : LowerAdjoint u) instance : CoeFun (LowerAdjoint u) fun _ => α → β where coe := toFun theorem gc : GaloisConnection l u := l.gc' #align lower_adjoint.gc LowerAdjoint.gc @[ext] theorem ext : ∀ l₁ l₂ : LowerAdjoint u, (l₁ : α → β) = (l₂ : α → β) → l₁ = l₂ | ⟨l₁, _⟩, ⟨l₂, _⟩, h => by congr #align lower_adjoint.ext LowerAdjoint.ext @[mono] theorem monotone : Monotone (u ∘ l) := l.gc.monotone_u.comp l.gc.monotone_l #align lower_adjoint.monotone LowerAdjoint.monotone /-- Every element is less than its closure. This property is sometimes referred to as extensivity or inflationarity. -/ theorem le_closure (x : α) : x ≤ u (l x) := l.gc.le_u_l _ #align lower_adjoint.le_closure LowerAdjoint.le_closure end Preorder section PartialOrder variable [PartialOrder α] [Preorder β] {u : β → α} (l : LowerAdjoint u) /-- Every lower adjoint induces a closure operator given by the composition. This is the partial order version of the statement that every adjunction induces a monad. -/ @[simps] def closureOperator : ClosureOperator α where toFun x := u (l x) monotone' := l.monotone le_closure' := l.le_closure idempotent' x := l.gc.u_l_u_eq_u (l x) #align lower_adjoint.closure_operator LowerAdjoint.closureOperator #align lower_adjoint.closure_operator_apply LowerAdjoint.closureOperator_apply theorem idempotent (x : α) : u (l (u (l x))) = u (l x) := l.closureOperator.idempotent _ #align lower_adjoint.idempotent LowerAdjoint.idempotent theorem le_closure_iff (x y : α) : x ≤ u (l y) ↔ u (l x) ≤ u (l y) := l.closureOperator.le_closure_iff #align lower_adjoint.le_closure_iff LowerAdjoint.le_closure_iff end PartialOrder section Preorder variable [Preorder α] [Preorder β] {u : β → α} (l : LowerAdjoint u) /-- An element `x` is closed for `l : LowerAdjoint u` if it is a fixed point: `u (l x) = x` -/ def closed : Set α := {x | u (l x) = x} #align lower_adjoint.closed LowerAdjoint.closed theorem mem_closed_iff (x : α) : x ∈ l.closed ↔ u (l x) = x := Iff.rfl #align lower_adjoint.mem_closed_iff LowerAdjoint.mem_closed_iff theorem closure_eq_self_of_mem_closed {x : α} (h : x ∈ l.closed) : u (l x) = x := h #align lower_adjoint.closure_eq_self_of_mem_closed LowerAdjoint.closure_eq_self_of_mem_closed end Preorder section PartialOrder variable [PartialOrder α] [PartialOrder β] {u : β → α} (l : LowerAdjoint u) theorem mem_closed_iff_closure_le (x : α) : x ∈ l.closed ↔ u (l x) ≤ x := l.closureOperator.isClosed_iff_closure_le #align lower_adjoint.mem_closed_iff_closure_le LowerAdjoint.mem_closed_iff_closure_le @[simp, nolint simpNF] -- Porting note: lemma does prove itself, seems to be a linter error theorem closure_is_closed (x : α) : u (l x) ∈ l.closed := l.idempotent x #align lower_adjoint.closure_is_closed LowerAdjoint.closure_is_closed /-- The set of closed elements for `l` is the range of `u ∘ l`. -/ theorem closed_eq_range_close : l.closed = Set.range (u ∘ l) := l.closureOperator.setOf_isClosed_eq_range_closure #align lower_adjoint.closed_eq_range_close LowerAdjoint.closed_eq_range_close /-- Send an `x` to an element of the set of closed elements (by taking the closure). -/ def toClosed (x : α) : l.closed := ⟨u (l x), l.closure_is_closed x⟩ #align lower_adjoint.to_closed LowerAdjoint.toClosed @[simp] theorem closure_le_closed_iff_le (x : α) {y : α} (hy : l.closed y) : u (l x) ≤ y ↔ x ≤ y := (show l.closureOperator.IsClosed y from hy).closure_le_iff #align lower_adjoint.closure_le_closed_iff_le LowerAdjoint.closure_le_closed_iff_le end PartialOrder theorem closure_top [PartialOrder α] [OrderTop α] [Preorder β] {u : β → α} (l : LowerAdjoint u) : u (l ⊤) = ⊤ := l.closureOperator.closure_top #align lower_adjoint.closure_top LowerAdjoint.closure_top theorem closure_inf_le [SemilatticeInf α] [Preorder β] {u : β → α} (l : LowerAdjoint u) (x y : α) : u (l (x ⊓ y)) ≤ u (l x) ⊓ u (l y) := l.closureOperator.closure_inf_le x y #align lower_adjoint.closure_inf_le LowerAdjoint.closure_inf_le section SemilatticeSup variable [SemilatticeSup α] [Preorder β] {u : β → α} (l : LowerAdjoint u) theorem closure_sup_closure_le (x y : α) : u (l x) ⊔ u (l y) ≤ u (l (x ⊔ y)) := l.closureOperator.closure_sup_closure_le x y #align lower_adjoint.closure_sup_closure_le LowerAdjoint.closure_sup_closure_le theorem closure_sup_closure_left (x y : α) : u (l (u (l x) ⊔ y)) = u (l (x ⊔ y)) := l.closureOperator.closure_sup_closure_left x y #align lower_adjoint.closure_sup_closure_left LowerAdjoint.closure_sup_closure_left theorem closure_sup_closure_right (x y : α) : u (l (x ⊔ u (l y))) = u (l (x ⊔ y)) := l.closureOperator.closure_sup_closure_right x y #align lower_adjoint.closure_sup_closure_right LowerAdjoint.closure_sup_closure_right theorem closure_sup_closure (x y : α) : u (l (u (l x) ⊔ u (l y))) = u (l (x ⊔ y)) := l.closureOperator.closure_sup_closure x y #align lower_adjoint.closure_sup_closure LowerAdjoint.closure_sup_closure end SemilatticeSup section CompleteLattice variable [CompleteLattice α] [Preorder β] {u : β → α} (l : LowerAdjoint u) theorem closure_iSup_closure (f : ι → α) : u (l (⨆ i, u (l (f i)))) = u (l (⨆ i, f i)) := l.closureOperator.closure_iSup_closure _ #align lower_adjoint.closure_supr_closure LowerAdjoint.closure_iSup_closure theorem closure_iSup₂_closure (f : ∀ i, κ i → α) : u (l <| ⨆ (i) (j), u (l <| f i j)) = u (l <| ⨆ (i) (j), f i j) := l.closureOperator.closure_iSup₂_closure _ #align lower_adjoint.closure_supr₂_closure LowerAdjoint.closure_iSup₂_closure end CompleteLattice -- Lemmas for `LowerAdjoint ((↑) : α → Set β)`, where `SetLike α β` section CoeToSet variable [SetLike α β] (l : LowerAdjoint ((↑) : α → Set β)) theorem subset_closure (s : Set β) : s ⊆ l s := l.le_closure s #align lower_adjoint.subset_closure LowerAdjoint.subset_closure theorem not_mem_of_not_mem_closure {s : Set β} {P : β} (hP : P ∉ l s) : P ∉ s := fun h => hP (subset_closure _ s h) #align lower_adjoint.not_mem_of_not_mem_closure LowerAdjoint.not_mem_of_not_mem_closure theorem le_iff_subset (s : Set β) (S : α) : l s ≤ S ↔ s ⊆ S := l.gc s S #align lower_adjoint.le_iff_subset LowerAdjoint.le_iff_subset theorem mem_iff (s : Set β) (x : β) : x ∈ l s ↔ ∀ S : α, s ⊆ S → x ∈ S := by simp_rw [← SetLike.mem_coe, ← Set.singleton_subset_iff, ← l.le_iff_subset] exact ⟨fun h S => h.trans, fun h => h _ le_rfl⟩ #align lower_adjoint.mem_iff LowerAdjoint.mem_iff theorem eq_of_le {s : Set β} {S : α} (h₁ : s ⊆ S) (h₂ : S ≤ l s) : l s = S := ((l.le_iff_subset _ _).2 h₁).antisymm h₂ #align lower_adjoint.eq_of_le LowerAdjoint.eq_of_le theorem closure_union_closure_subset (x y : α) : (l x : Set β) ∪ l y ⊆ l (x ∪ y) := l.closure_sup_closure_le x y #align lower_adjoint.closure_union_closure_subset LowerAdjoint.closure_union_closure_subset @[simp] theorem closure_union_closure_left (x y : α) : l (l x ∪ y) = l (x ∪ y) := SetLike.coe_injective (l.closure_sup_closure_left x y) #align lower_adjoint.closure_union_closure_left LowerAdjoint.closure_union_closure_left @[simp] theorem closure_union_closure_right (x y : α) : l (x ∪ l y) = l (x ∪ y) := SetLike.coe_injective (l.closure_sup_closure_right x y) #align lower_adjoint.closure_union_closure_right LowerAdjoint.closure_union_closure_right theorem closure_union_closure (x y : α) : l (l x ∪ l y) = l (x ∪ y) := by rw [closure_union_closure_right, closure_union_closure_left] #align lower_adjoint.closure_union_closure LowerAdjoint.closure_union_closure @[simp] theorem closure_iUnion_closure (f : ι → α) : l (⋃ i, l (f i)) = l (⋃ i, f i) := SetLike.coe_injective <| l.closure_iSup_closure _ #align lower_adjoint.closure_Union_closure LowerAdjoint.closure_iUnion_closure /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[simp] theorem closure_iUnion₂_closure (f : ∀ i, κ i → α) : l (⋃ (i) (j), l (f i j)) = l (⋃ (i) (j), f i j) := SetLike.coe_injective <| l.closure_iSup₂_closure _ #align lower_adjoint.closure_Union₂_closure LowerAdjoint.closure_iUnion₂_closure end CoeToSet end LowerAdjoint /-! ### Translations between `GaloisConnection`, `LowerAdjoint`, `ClosureOperator` -/ /-- Every Galois connection induces a lower adjoint. -/ @[simps] def GaloisConnection.lowerAdjoint [Preorder α] [Preorder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : LowerAdjoint u where toFun := l gc' := gc #align galois_connection.lower_adjoint GaloisConnection.lowerAdjoint #align galois_connection.lower_adjoint_to_fun GaloisConnection.lowerAdjoint_toFun /-- Every Galois connection induces a closure operator given by the composition. This is the partial order version of the statement that every adjunction induces a monad. -/ @[simps!] def GaloisConnection.closureOperator [PartialOrder α] [Preorder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : ClosureOperator α := gc.lowerAdjoint.closureOperator #align galois_connection.closure_operator GaloisConnection.closureOperator #align galois_connection.closure_operator_apply GaloisConnection.closureOperator_apply /-- The set of closed elements has a Galois insertion to the underlying type. -/ def ClosureOperator.gi [PartialOrder α] (c : ClosureOperator α) : GaloisInsertion c.toCloseds (↑) where choice x hx := ⟨x, isClosed_iff_closure_le.2 hx⟩ gc _ y := y.2.closure_le_iff le_l_u _ := c.le_closure _ choice_eq x hx := le_antisymm (c.le_closure x) hx #align closure_operator.gi ClosureOperator.gi /-- The Galois insertion associated to a closure operator can be used to reconstruct the closure operator. Note that the inverse in the opposite direction does not hold in general. -/ @[simp]
Mathlib/Order/Closure.lean
604
607
theorem closureOperator_gi_self [PartialOrder α] (c : ClosureOperator α) : c.gi.gc.closureOperator = c := by
ext x rfl
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.Matrix.Diagonal import Mathlib.LinearAlgebra.Matrix.Transvection import Mathlib.MeasureTheory.Group.LIntegral import Mathlib.MeasureTheory.Integral.Marginal import Mathlib.MeasureTheory.Measure.Stieltjes import Mathlib.MeasureTheory.Measure.Haar.OfBasis #align_import measure_theory.measure.lebesgue.basic from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Lebesgue measure on the real line and on `ℝⁿ` We show that the Lebesgue measure on the real line (constructed as a particular case of additive Haar measure on inner product spaces) coincides with the Stieltjes measure associated to the function `x ↦ x`. We deduce properties of this measure on `ℝ`, and then of the product Lebesgue measure on `ℝⁿ`. In particular, we prove that they are translation invariant. We show that, on `ℝⁿ`, a linear map acts on Lebesgue measure by rescaling it through the absolute value of its determinant, in `Real.map_linearMap_volume_pi_eq_smul_volume_pi`. More properties of the Lebesgue measure are deduced from this in `Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean`, where they are proved more generally for any additive Haar measure on a finite-dimensional real vector space. -/ assert_not_exists MeasureTheory.integral noncomputable section open scoped Classical open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace open ENNReal (ofReal) open scoped ENNReal NNReal Topology /-! ### Definition of the Lebesgue measure and lengths of intervals -/ namespace Real variable {ι : Type*} [Fintype ι] /-- The volume on the real line (as a particular case of the volume on a finite-dimensional inner product space) coincides with the Stieltjes measure coming from the identity function. -/ theorem volume_eq_stieltjes_id : (volume : Measure ℝ) = StieltjesFunction.id.measure := by haveI : IsAddLeftInvariant StieltjesFunction.id.measure := ⟨fun a => Eq.symm <| Real.measure_ext_Ioo_rat fun p q => by simp only [Measure.map_apply (measurable_const_add a) measurableSet_Ioo, sub_sub_sub_cancel_right, StieltjesFunction.measure_Ioo, StieltjesFunction.id_leftLim, StieltjesFunction.id_apply, id, preimage_const_add_Ioo]⟩ have A : StieltjesFunction.id.measure (stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped = 1 := by change StieltjesFunction.id.measure (parallelepiped (stdOrthonormalBasis ℝ ℝ)) = 1 rcases parallelepiped_orthonormalBasis_one_dim (stdOrthonormalBasis ℝ ℝ) with (H | H) <;> simp only [H, StieltjesFunction.measure_Icc, StieltjesFunction.id_apply, id, tsub_zero, StieltjesFunction.id_leftLim, sub_neg_eq_add, zero_add, ENNReal.ofReal_one] conv_rhs => rw [addHaarMeasure_unique StieltjesFunction.id.measure (stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped, A] simp only [volume, Basis.addHaar, one_smul] #align real.volume_eq_stieltjes_id Real.volume_eq_stieltjes_id theorem volume_val (s) : volume s = StieltjesFunction.id.measure s := by simp [volume_eq_stieltjes_id] #align real.volume_val Real.volume_val @[simp] theorem volume_Ico {a b : ℝ} : volume (Ico a b) = ofReal (b - a) := by simp [volume_val] #align real.volume_Ico Real.volume_Ico @[simp] theorem volume_Icc {a b : ℝ} : volume (Icc a b) = ofReal (b - a) := by simp [volume_val] #align real.volume_Icc Real.volume_Icc @[simp] theorem volume_Ioo {a b : ℝ} : volume (Ioo a b) = ofReal (b - a) := by simp [volume_val] #align real.volume_Ioo Real.volume_Ioo @[simp] theorem volume_Ioc {a b : ℝ} : volume (Ioc a b) = ofReal (b - a) := by simp [volume_val] #align real.volume_Ioc Real.volume_Ioc -- @[simp] -- Porting note (#10618): simp can prove this theorem volume_singleton {a : ℝ} : volume ({a} : Set ℝ) = 0 := by simp [volume_val] #align real.volume_singleton Real.volume_singleton -- @[simp] -- Porting note (#10618): simp can prove this, after mathlib4#4628 theorem volume_univ : volume (univ : Set ℝ) = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => calc (r : ℝ≥0∞) = volume (Icc (0 : ℝ) r) := by simp _ ≤ volume univ := measure_mono (subset_univ _) #align real.volume_univ Real.volume_univ @[simp] theorem volume_ball (a r : ℝ) : volume (Metric.ball a r) = ofReal (2 * r) := by rw [ball_eq_Ioo, volume_Ioo, ← sub_add, add_sub_cancel_left, two_mul] #align real.volume_ball Real.volume_ball @[simp] theorem volume_closedBall (a r : ℝ) : volume (Metric.closedBall a r) = ofReal (2 * r) := by rw [closedBall_eq_Icc, volume_Icc, ← sub_add, add_sub_cancel_left, two_mul] #align real.volume_closed_ball Real.volume_closedBall @[simp] theorem volume_emetric_ball (a : ℝ) (r : ℝ≥0∞) : volume (EMetric.ball a r) = 2 * r := by rcases eq_or_ne r ∞ with (rfl | hr) · rw [Metric.emetric_ball_top, volume_univ, two_mul, _root_.top_add] · lift r to ℝ≥0 using hr rw [Metric.emetric_ball_nnreal, volume_ball, two_mul, ← NNReal.coe_add, ENNReal.ofReal_coe_nnreal, ENNReal.coe_add, two_mul] #align real.volume_emetric_ball Real.volume_emetric_ball @[simp] theorem volume_emetric_closedBall (a : ℝ) (r : ℝ≥0∞) : volume (EMetric.closedBall a r) = 2 * r := by rcases eq_or_ne r ∞ with (rfl | hr) · rw [EMetric.closedBall_top, volume_univ, two_mul, _root_.top_add] · lift r to ℝ≥0 using hr rw [Metric.emetric_closedBall_nnreal, volume_closedBall, two_mul, ← NNReal.coe_add, ENNReal.ofReal_coe_nnreal, ENNReal.coe_add, two_mul] #align real.volume_emetric_closed_ball Real.volume_emetric_closedBall instance noAtoms_volume : NoAtoms (volume : Measure ℝ) := ⟨fun _ => volume_singleton⟩ #align real.has_no_atoms_volume Real.noAtoms_volume @[simp] theorem volume_interval {a b : ℝ} : volume (uIcc a b) = ofReal |b - a| := by rw [← Icc_min_max, volume_Icc, max_sub_min_eq_abs] #align real.volume_interval Real.volume_interval @[simp] theorem volume_Ioi {a : ℝ} : volume (Ioi a) = ∞ := top_unique <| le_of_tendsto' ENNReal.tendsto_nat_nhds_top fun n => calc (n : ℝ≥0∞) = volume (Ioo a (a + n)) := by simp _ ≤ volume (Ioi a) := measure_mono Ioo_subset_Ioi_self #align real.volume_Ioi Real.volume_Ioi @[simp] theorem volume_Ici {a : ℝ} : volume (Ici a) = ∞ := by rw [← measure_congr Ioi_ae_eq_Ici]; simp #align real.volume_Ici Real.volume_Ici @[simp] theorem volume_Iio {a : ℝ} : volume (Iio a) = ∞ := top_unique <| le_of_tendsto' ENNReal.tendsto_nat_nhds_top fun n => calc (n : ℝ≥0∞) = volume (Ioo (a - n) a) := by simp _ ≤ volume (Iio a) := measure_mono Ioo_subset_Iio_self #align real.volume_Iio Real.volume_Iio @[simp] theorem volume_Iic {a : ℝ} : volume (Iic a) = ∞ := by rw [← measure_congr Iio_ae_eq_Iic]; simp #align real.volume_Iic Real.volume_Iic instance locallyFinite_volume : IsLocallyFiniteMeasure (volume : Measure ℝ) := ⟨fun x => ⟨Ioo (x - 1) (x + 1), IsOpen.mem_nhds isOpen_Ioo ⟨sub_lt_self _ zero_lt_one, lt_add_of_pos_right _ zero_lt_one⟩, by simp only [Real.volume_Ioo, ENNReal.ofReal_lt_top]⟩⟩ #align real.locally_finite_volume Real.locallyFinite_volume instance isFiniteMeasure_restrict_Icc (x y : ℝ) : IsFiniteMeasure (volume.restrict (Icc x y)) := ⟨by simp⟩ #align real.is_finite_measure_restrict_Icc Real.isFiniteMeasure_restrict_Icc instance isFiniteMeasure_restrict_Ico (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ico x y)) := ⟨by simp⟩ #align real.is_finite_measure_restrict_Ico Real.isFiniteMeasure_restrict_Ico instance isFiniteMeasure_restrict_Ioc (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ioc x y)) := ⟨by simp⟩ #align real.is_finite_measure_restrict_Ioc Real.isFiniteMeasure_restrict_Ioc instance isFiniteMeasure_restrict_Ioo (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ioo x y)) := ⟨by simp⟩ #align real.is_finite_measure_restrict_Ioo Real.isFiniteMeasure_restrict_Ioo theorem volume_le_diam (s : Set ℝ) : volume s ≤ EMetric.diam s := by by_cases hs : Bornology.IsBounded s · rw [Real.ediam_eq hs, ← volume_Icc] exact volume.mono hs.subset_Icc_sInf_sSup · rw [Metric.ediam_of_unbounded hs]; exact le_top #align real.volume_le_diam Real.volume_le_diam theorem _root_.Filter.Eventually.volume_pos_of_nhds_real {p : ℝ → Prop} {a : ℝ} (h : ∀ᶠ x in 𝓝 a, p x) : (0 : ℝ≥0∞) < volume { x | p x } := by rcases h.exists_Ioo_subset with ⟨l, u, hx, hs⟩ refine lt_of_lt_of_le ?_ (measure_mono hs) simpa [-mem_Ioo] using hx.1.trans hx.2 #align filter.eventually.volume_pos_of_nhds_real Filter.Eventually.volume_pos_of_nhds_real /-! ### Volume of a box in `ℝⁿ` -/ theorem volume_Icc_pi {a b : ι → ℝ} : volume (Icc a b) = ∏ i, ENNReal.ofReal (b i - a i) := by rw [← pi_univ_Icc, volume_pi_pi] simp only [Real.volume_Icc] #align real.volume_Icc_pi Real.volume_Icc_pi @[simp] theorem volume_Icc_pi_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (Icc a b)).toReal = ∏ i, (b i - a i) := by simp only [volume_Icc_pi, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] #align real.volume_Icc_pi_to_real Real.volume_Icc_pi_toReal theorem volume_pi_Ioo {a b : ι → ℝ} : volume (pi univ fun i => Ioo (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) := (measure_congr Measure.univ_pi_Ioo_ae_eq_Icc).trans volume_Icc_pi #align real.volume_pi_Ioo Real.volume_pi_Ioo @[simp] theorem volume_pi_Ioo_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (pi univ fun i => Ioo (a i) (b i))).toReal = ∏ i, (b i - a i) := by simp only [volume_pi_Ioo, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] #align real.volume_pi_Ioo_to_real Real.volume_pi_Ioo_toReal theorem volume_pi_Ioc {a b : ι → ℝ} : volume (pi univ fun i => Ioc (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) := (measure_congr Measure.univ_pi_Ioc_ae_eq_Icc).trans volume_Icc_pi #align real.volume_pi_Ioc Real.volume_pi_Ioc @[simp] theorem volume_pi_Ioc_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (pi univ fun i => Ioc (a i) (b i))).toReal = ∏ i, (b i - a i) := by simp only [volume_pi_Ioc, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] #align real.volume_pi_Ioc_to_real Real.volume_pi_Ioc_toReal theorem volume_pi_Ico {a b : ι → ℝ} : volume (pi univ fun i => Ico (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) := (measure_congr Measure.univ_pi_Ico_ae_eq_Icc).trans volume_Icc_pi #align real.volume_pi_Ico Real.volume_pi_Ico @[simp] theorem volume_pi_Ico_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (pi univ fun i => Ico (a i) (b i))).toReal = ∏ i, (b i - a i) := by simp only [volume_pi_Ico, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] #align real.volume_pi_Ico_to_real Real.volume_pi_Ico_toReal @[simp] nonrec theorem volume_pi_ball (a : ι → ℝ) {r : ℝ} (hr : 0 < r) : volume (Metric.ball a r) = ENNReal.ofReal ((2 * r) ^ Fintype.card ι) := by simp only [MeasureTheory.volume_pi_ball a hr, volume_ball, Finset.prod_const] exact (ENNReal.ofReal_pow (mul_nonneg zero_le_two hr.le) _).symm #align real.volume_pi_ball Real.volume_pi_ball @[simp] nonrec theorem volume_pi_closedBall (a : ι → ℝ) {r : ℝ} (hr : 0 ≤ r) : volume (Metric.closedBall a r) = ENNReal.ofReal ((2 * r) ^ Fintype.card ι) := by simp only [MeasureTheory.volume_pi_closedBall a hr, volume_closedBall, Finset.prod_const] exact (ENNReal.ofReal_pow (mul_nonneg zero_le_two hr) _).symm #align real.volume_pi_closed_ball Real.volume_pi_closedBall theorem volume_pi_le_prod_diam (s : Set (ι → ℝ)) : volume s ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) := calc volume s ≤ volume (pi univ fun i => closure (Function.eval i '' s)) := volume.mono <| Subset.trans (subset_pi_eval_image univ s) <| pi_mono fun _ _ => subset_closure _ = ∏ i, volume (closure <| Function.eval i '' s) := volume_pi_pi _ _ ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) := Finset.prod_le_prod' fun _ _ => (volume_le_diam _).trans_eq (EMetric.diam_closure _) #align real.volume_pi_le_prod_diam Real.volume_pi_le_prod_diam theorem volume_pi_le_diam_pow (s : Set (ι → ℝ)) : volume s ≤ EMetric.diam s ^ Fintype.card ι := calc volume s ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) := volume_pi_le_prod_diam s _ ≤ ∏ _i : ι, (1 : ℝ≥0) * EMetric.diam s := (Finset.prod_le_prod' fun i _ => (LipschitzWith.eval i).ediam_image_le s) _ = EMetric.diam s ^ Fintype.card ι := by simp only [ENNReal.coe_one, one_mul, Finset.prod_const, Fintype.card] #align real.volume_pi_le_diam_pow Real.volume_pi_le_diam_pow /-! ### Images of the Lebesgue measure under multiplication in ℝ -/ theorem smul_map_volume_mul_left {a : ℝ} (h : a ≠ 0) : ENNReal.ofReal |a| • Measure.map (a * ·) volume = volume := by refine (Real.measure_ext_Ioo_rat fun p q => ?_).symm cases' lt_or_gt_of_ne h with h h · simp only [Real.volume_Ioo, Measure.smul_apply, ← ENNReal.ofReal_mul (le_of_lt <| neg_pos.2 h), Measure.map_apply (measurable_const_mul a) measurableSet_Ioo, neg_sub_neg, neg_mul, preimage_const_mul_Ioo_of_neg _ _ h, abs_of_neg h, mul_sub, smul_eq_mul, mul_div_cancel₀ _ (ne_of_lt h)] · simp only [Real.volume_Ioo, Measure.smul_apply, ← ENNReal.ofReal_mul (le_of_lt h), Measure.map_apply (measurable_const_mul a) measurableSet_Ioo, preimage_const_mul_Ioo _ _ h, abs_of_pos h, mul_sub, mul_div_cancel₀ _ (ne_of_gt h), smul_eq_mul] #align real.smul_map_volume_mul_left Real.smul_map_volume_mul_left theorem map_volume_mul_left {a : ℝ} (h : a ≠ 0) : Measure.map (a * ·) volume = ENNReal.ofReal |a⁻¹| • volume := by conv_rhs => rw [← Real.smul_map_volume_mul_left h, smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel h, abs_one, ENNReal.ofReal_one, one_smul] #align real.map_volume_mul_left Real.map_volume_mul_left @[simp] theorem volume_preimage_mul_left {a : ℝ} (h : a ≠ 0) (s : Set ℝ) : volume ((a * ·) ⁻¹' s) = ENNReal.ofReal (abs a⁻¹) * volume s := calc volume ((a * ·) ⁻¹' s) = Measure.map (a * ·) volume s := ((Homeomorph.mulLeft₀ a h).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs a⁻¹) * volume s := by rw [map_volume_mul_left h]; rfl #align real.volume_preimage_mul_left Real.volume_preimage_mul_left theorem smul_map_volume_mul_right {a : ℝ} (h : a ≠ 0) : ENNReal.ofReal |a| • Measure.map (· * a) volume = volume := by simpa only [mul_comm] using Real.smul_map_volume_mul_left h #align real.smul_map_volume_mul_right Real.smul_map_volume_mul_right theorem map_volume_mul_right {a : ℝ} (h : a ≠ 0) : Measure.map (· * a) volume = ENNReal.ofReal |a⁻¹| • volume := by simpa only [mul_comm] using Real.map_volume_mul_left h #align real.map_volume_mul_right Real.map_volume_mul_right @[simp] theorem volume_preimage_mul_right {a : ℝ} (h : a ≠ 0) (s : Set ℝ) : volume ((· * a) ⁻¹' s) = ENNReal.ofReal (abs a⁻¹) * volume s := calc volume ((· * a) ⁻¹' s) = Measure.map (· * a) volume s := ((Homeomorph.mulRight₀ a h).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs a⁻¹) * volume s := by rw [map_volume_mul_right h]; rfl #align real.volume_preimage_mul_right Real.volume_preimage_mul_right /-! ### Images of the Lebesgue measure under translation/linear maps in ℝⁿ -/ open Matrix /-- A diagonal matrix rescales Lebesgue according to its determinant. This is a special case of `Real.map_matrix_volume_pi_eq_smul_volume_pi`, that one should use instead (and whose proof uses this particular case). -/ theorem smul_map_diagonal_volume_pi [DecidableEq ι] {D : ι → ℝ} (h : det (diagonal D) ≠ 0) : ENNReal.ofReal (abs (det (diagonal D))) • Measure.map (toLin' (diagonal D)) volume = volume := by refine (Measure.pi_eq fun s hs => ?_).symm simp only [det_diagonal, Measure.coe_smul, Algebra.id.smul_eq_mul, Pi.smul_apply] rw [Measure.map_apply _ (MeasurableSet.univ_pi hs)] swap; · exact Continuous.measurable (LinearMap.continuous_on_pi _) have : (Matrix.toLin' (diagonal D) ⁻¹' Set.pi Set.univ fun i : ι => s i) = Set.pi Set.univ fun i : ι => (D i * ·) ⁻¹' s i := by ext f simp only [LinearMap.coe_proj, Algebra.id.smul_eq_mul, LinearMap.smul_apply, mem_univ_pi, mem_preimage, LinearMap.pi_apply, diagonal_toLin'] have B : ∀ i, ofReal (abs (D i)) * volume ((D i * ·) ⁻¹' s i) = volume (s i) := by intro i have A : D i ≠ 0 := by simp only [det_diagonal, Ne] at h exact Finset.prod_ne_zero_iff.1 h i (Finset.mem_univ i) rw [volume_preimage_mul_left A, ← mul_assoc, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, mul_inv_cancel A, abs_one, ENNReal.ofReal_one, one_mul] rw [this, volume_pi_pi, Finset.abs_prod, ENNReal.ofReal_prod_of_nonneg fun i _ => abs_nonneg (D i), ← Finset.prod_mul_distrib] simp only [B] #align real.smul_map_diagonal_volume_pi Real.smul_map_diagonal_volume_pi /-- A transvection preserves Lebesgue measure. -/ theorem volume_preserving_transvectionStruct [DecidableEq ι] (t : TransvectionStruct ι ℝ) : MeasurePreserving (toLin' t.toMatrix) := by /- We use `lmarginal` to conveniently use Fubini's theorem. Along the coordinate where there is a shearing, it acts like a translation, and therefore preserves Lebesgue. -/ have ht : Measurable (toLin' t.toMatrix) := (toLin' t.toMatrix).continuous_of_finiteDimensional.measurable refine ⟨ht, ?_⟩ refine (pi_eq fun s hs ↦ ?_).symm have h2s : MeasurableSet (univ.pi s) := .pi countable_univ fun i _ ↦ hs i simp_rw [← pi_pi, ← lintegral_indicator_one h2s] rw [lintegral_map (measurable_one.indicator h2s) ht, volume_pi] refine lintegral_eq_of_lmarginal_eq {t.i} ((measurable_one.indicator h2s).comp ht) (measurable_one.indicator h2s) ?_ simp_rw [lmarginal_singleton] ext x cases t with | mk t_i t_j t_hij t_c => simp [transvection, mulVec_stdBasisMatrix, t_hij.symm, ← Function.update_add, lintegral_add_right_eq_self fun xᵢ ↦ indicator (univ.pi s) 1 (Function.update x t_i xᵢ)] #align real.volume_preserving_transvection_struct Real.volume_preserving_transvectionStruct /-- Any invertible matrix rescales Lebesgue measure through the absolute value of its determinant. -/ theorem map_matrix_volume_pi_eq_smul_volume_pi [DecidableEq ι] {M : Matrix ι ι ℝ} (hM : det M ≠ 0) : Measure.map (toLin' M) volume = ENNReal.ofReal (abs (det M)⁻¹) • volume := by -- This follows from the cases we have already proved, of diagonal matrices and transvections, -- as these matrices generate all invertible matrices. apply diagonal_transvection_induction_of_det_ne_zero _ M hM · intro D hD conv_rhs => rw [← smul_map_diagonal_volume_pi hD] rw [smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel hD, abs_one, ENNReal.ofReal_one, one_smul] · intro t simp_rw [Matrix.TransvectionStruct.det, _root_.inv_one, abs_one, ENNReal.ofReal_one, one_smul, (volume_preserving_transvectionStruct _).map_eq] · intro A B _ _ IHA IHB rw [toLin'_mul, det_mul, LinearMap.coe_comp, ← Measure.map_map, IHB, Measure.map_smul, IHA, smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, mul_comm, mul_inv] · apply Continuous.measurable apply LinearMap.continuous_on_pi · apply Continuous.measurable apply LinearMap.continuous_on_pi #align real.map_matrix_volume_pi_eq_smul_volume_pi Real.map_matrix_volume_pi_eq_smul_volume_pi /-- Any invertible linear map rescales Lebesgue measure through the absolute value of its determinant. -/ theorem map_linearMap_volume_pi_eq_smul_volume_pi {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ} (hf : LinearMap.det f ≠ 0) : Measure.map f volume = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • volume := by classical -- this is deduced from the matrix case let M := LinearMap.toMatrix' f have A : LinearMap.det f = det M := by simp only [M, LinearMap.det_toMatrix'] have B : f = toLin' M := by simp only [M, toLin'_toMatrix'] rw [A, B] apply map_matrix_volume_pi_eq_smul_volume_pi rwa [A] at hf #align real.map_linear_map_volume_pi_eq_smul_volume_pi Real.map_linearMap_volume_pi_eq_smul_volume_pi end Real section regionBetween variable {α : Type*} /-- The region between two real-valued functions on an arbitrary set. -/ def regionBetween (f g : α → ℝ) (s : Set α) : Set (α × ℝ) := { p : α × ℝ | p.1 ∈ s ∧ p.2 ∈ Ioo (f p.1) (g p.1) } #align region_between regionBetween theorem regionBetween_subset (f g : α → ℝ) (s : Set α) : regionBetween f g s ⊆ s ×ˢ univ := by simpa only [prod_univ, regionBetween, Set.preimage, setOf_subset_setOf] using fun a => And.left #align region_between_subset regionBetween_subset variable [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ} {s : Set α} /-- The region between two measurable functions on a measurable set is measurable. -/ theorem measurableSet_regionBetween (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet (regionBetween f g s) := by dsimp only [regionBetween, Ioo, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_lt (hf.comp measurable_fst) measurable_snd).inter (measurableSet_lt measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs #align measurable_set_region_between measurableSet_regionBetween /-- The region between two measurable functions on a measurable set is measurable; a version for the region together with the graph of the upper function. -/ theorem measurableSet_region_between_oc (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Ioc (f p.fst) (g p.fst) } := by dsimp only [regionBetween, Ioc, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_lt (hf.comp measurable_fst) measurable_snd).inter (measurableSet_le measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs #align measurable_set_region_between_oc measurableSet_region_between_oc /-- The region between two measurable functions on a measurable set is measurable; a version for the region together with the graph of the lower function. -/ theorem measurableSet_region_between_co (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Ico (f p.fst) (g p.fst) } := by dsimp only [regionBetween, Ico, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_le (hf.comp measurable_fst) measurable_snd).inter (measurableSet_lt measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs #align measurable_set_region_between_co measurableSet_region_between_co /-- The region between two measurable functions on a measurable set is measurable; a version for the region together with the graphs of both functions. -/
Mathlib/MeasureTheory/Measure/Lebesgue/Basic.lean
494
502
theorem measurableSet_region_between_cc (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Icc (f p.fst) (g p.fst) } := by
dsimp only [regionBetween, Icc, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_le (hf.comp measurable_fst) measurable_snd).inter (measurableSet_le measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Nat import Mathlib.Algebra.Order.Sub.Canonical import Mathlib.Data.List.Perm import Mathlib.Data.Set.List import Mathlib.Init.Quot import Mathlib.Order.Hom.Basic #align_import data.multiset.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Multisets These are implemented as the quotient of a list by permutations. ## Notation We define the global infix notation `::ₘ` for `Multiset.cons`. -/ universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} /-- `Multiset α` is the quotient of `List α` by list permutation. The result is a type of finite sets with duplicates allowed. -/ def Multiset.{u} (α : Type u) : Type u := Quotient (List.isSetoid α) #align multiset Multiset namespace Multiset -- Porting note: new /-- The quotient map from `List α` to `Multiset α`. -/ @[coe] def ofList : List α → Multiset α := Quot.mk _ instance : Coe (List α) (Multiset α) := ⟨ofList⟩ @[simp] theorem quot_mk_to_coe (l : List α) : @Eq (Multiset α) ⟦l⟧ l := rfl #align multiset.quot_mk_to_coe Multiset.quot_mk_to_coe @[simp] theorem quot_mk_to_coe' (l : List α) : @Eq (Multiset α) (Quot.mk (· ≈ ·) l) l := rfl #align multiset.quot_mk_to_coe' Multiset.quot_mk_to_coe' @[simp] theorem quot_mk_to_coe'' (l : List α) : @Eq (Multiset α) (Quot.mk Setoid.r l) l := rfl #align multiset.quot_mk_to_coe'' Multiset.quot_mk_to_coe'' @[simp] theorem coe_eq_coe {l₁ l₂ : List α} : (l₁ : Multiset α) = l₂ ↔ l₁ ~ l₂ := Quotient.eq #align multiset.coe_eq_coe Multiset.coe_eq_coe -- Porting note: new instance; -- Porting note (#11215): TODO: move to better place instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ ≈ l₂) := inferInstanceAs (Decidable (l₁ ~ l₂)) -- Porting note: `Quotient.recOnSubsingleton₂ s₁ s₂` was in parens which broke elaboration instance decidableEq [DecidableEq α] : DecidableEq (Multiset α) | s₁, s₂ => Quotient.recOnSubsingleton₂ s₁ s₂ fun _ _ => decidable_of_iff' _ Quotient.eq #align multiset.has_decidable_eq Multiset.decidableEq /-- defines a size for a multiset by referring to the size of the underlying list -/ protected def sizeOf [SizeOf α] (s : Multiset α) : ℕ := (Quot.liftOn s SizeOf.sizeOf) fun _ _ => Perm.sizeOf_eq_sizeOf #align multiset.sizeof Multiset.sizeOf instance [SizeOf α] : SizeOf (Multiset α) := ⟨Multiset.sizeOf⟩ /-! ### Empty multiset -/ /-- `0 : Multiset α` is the empty set -/ protected def zero : Multiset α := @nil α #align multiset.zero Multiset.zero instance : Zero (Multiset α) := ⟨Multiset.zero⟩ instance : EmptyCollection (Multiset α) := ⟨0⟩ instance inhabitedMultiset : Inhabited (Multiset α) := ⟨0⟩ #align multiset.inhabited_multiset Multiset.inhabitedMultiset instance [IsEmpty α] : Unique (Multiset α) where default := 0 uniq := by rintro ⟨_ | ⟨a, l⟩⟩; exacts [rfl, isEmptyElim a] @[simp] theorem coe_nil : (@nil α : Multiset α) = 0 := rfl #align multiset.coe_nil Multiset.coe_nil @[simp] theorem empty_eq_zero : (∅ : Multiset α) = 0 := rfl #align multiset.empty_eq_zero Multiset.empty_eq_zero @[simp] theorem coe_eq_zero (l : List α) : (l : Multiset α) = 0 ↔ l = [] := Iff.trans coe_eq_coe perm_nil #align multiset.coe_eq_zero Multiset.coe_eq_zero theorem coe_eq_zero_iff_isEmpty (l : List α) : (l : Multiset α) = 0 ↔ l.isEmpty := Iff.trans (coe_eq_zero l) isEmpty_iff_eq_nil.symm #align multiset.coe_eq_zero_iff_empty Multiset.coe_eq_zero_iff_isEmpty /-! ### `Multiset.cons` -/ /-- `cons a s` is the multiset which contains `s` plus one more instance of `a`. -/ def cons (a : α) (s : Multiset α) : Multiset α := Quot.liftOn s (fun l => (a :: l : Multiset α)) fun _ _ p => Quot.sound (p.cons a) #align multiset.cons Multiset.cons @[inherit_doc Multiset.cons] infixr:67 " ::ₘ " => Multiset.cons instance : Insert α (Multiset α) := ⟨cons⟩ @[simp] theorem insert_eq_cons (a : α) (s : Multiset α) : insert a s = a ::ₘ s := rfl #align multiset.insert_eq_cons Multiset.insert_eq_cons @[simp] theorem cons_coe (a : α) (l : List α) : (a ::ₘ l : Multiset α) = (a :: l : List α) := rfl #align multiset.cons_coe Multiset.cons_coe @[simp] theorem cons_inj_left {a b : α} (s : Multiset α) : a ::ₘ s = b ::ₘ s ↔ a = b := ⟨Quot.inductionOn s fun l e => have : [a] ++ l ~ [b] ++ l := Quotient.exact e singleton_perm_singleton.1 <| (perm_append_right_iff _).1 this, congr_arg (· ::ₘ _)⟩ #align multiset.cons_inj_left Multiset.cons_inj_left @[simp] theorem cons_inj_right (a : α) : ∀ {s t : Multiset α}, a ::ₘ s = a ::ₘ t ↔ s = t := by rintro ⟨l₁⟩ ⟨l₂⟩; simp #align multiset.cons_inj_right Multiset.cons_inj_right @[elab_as_elim] protected theorem induction {p : Multiset α → Prop} (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : ∀ s, p s := by rintro ⟨l⟩; induction' l with _ _ ih <;> [exact empty; exact cons _ _ ih] #align multiset.induction Multiset.induction @[elab_as_elim] protected theorem induction_on {p : Multiset α → Prop} (s : Multiset α) (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : p s := Multiset.induction empty cons s #align multiset.induction_on Multiset.induction_on theorem cons_swap (a b : α) (s : Multiset α) : a ::ₘ b ::ₘ s = b ::ₘ a ::ₘ s := Quot.inductionOn s fun _ => Quotient.sound <| Perm.swap _ _ _ #align multiset.cons_swap Multiset.cons_swap section Rec variable {C : Multiset α → Sort*} /-- Dependent recursor on multisets. TODO: should be @[recursor 6], but then the definition of `Multiset.pi` fails with a stack overflow in `whnf`. -/ protected def rec (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) (m : Multiset α) : C m := Quotient.hrecOn m (@List.rec α (fun l => C ⟦l⟧) C_0 fun a l b => C_cons a ⟦l⟧ b) fun l l' h => h.rec_heq (fun hl _ ↦ by congr 1; exact Quot.sound hl) (C_cons_heq _ _ ⟦_⟧ _) #align multiset.rec Multiset.rec /-- Companion to `Multiset.rec` with more convenient argument order. -/ @[elab_as_elim] protected def recOn (m : Multiset α) (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) : C m := Multiset.rec C_0 C_cons C_cons_heq m #align multiset.rec_on Multiset.recOn variable {C_0 : C 0} {C_cons : ∀ a m, C m → C (a ::ₘ m)} {C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))} @[simp] theorem recOn_0 : @Multiset.recOn α C (0 : Multiset α) C_0 C_cons C_cons_heq = C_0 := rfl #align multiset.rec_on_0 Multiset.recOn_0 @[simp] theorem recOn_cons (a : α) (m : Multiset α) : (a ::ₘ m).recOn C_0 C_cons C_cons_heq = C_cons a m (m.recOn C_0 C_cons C_cons_heq) := Quotient.inductionOn m fun _ => rfl #align multiset.rec_on_cons Multiset.recOn_cons end Rec section Mem /-- `a ∈ s` means that `a` has nonzero multiplicity in `s`. -/ def Mem (a : α) (s : Multiset α) : Prop := Quot.liftOn s (fun l => a ∈ l) fun l₁ l₂ (e : l₁ ~ l₂) => propext <| e.mem_iff #align multiset.mem Multiset.Mem instance : Membership α (Multiset α) := ⟨Mem⟩ @[simp] theorem mem_coe {a : α} {l : List α} : a ∈ (l : Multiset α) ↔ a ∈ l := Iff.rfl #align multiset.mem_coe Multiset.mem_coe instance decidableMem [DecidableEq α] (a : α) (s : Multiset α) : Decidable (a ∈ s) := Quot.recOnSubsingleton' s fun l ↦ inferInstanceAs (Decidable (a ∈ l)) #align multiset.decidable_mem Multiset.decidableMem @[simp] theorem mem_cons {a b : α} {s : Multiset α} : a ∈ b ::ₘ s ↔ a = b ∨ a ∈ s := Quot.inductionOn s fun _ => List.mem_cons #align multiset.mem_cons Multiset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Multiset α} (h : a ∈ s) : a ∈ b ::ₘ s := mem_cons.2 <| Or.inr h #align multiset.mem_cons_of_mem Multiset.mem_cons_of_mem -- @[simp] -- Porting note (#10618): simp can prove this theorem mem_cons_self (a : α) (s : Multiset α) : a ∈ a ::ₘ s := mem_cons.2 (Or.inl rfl) #align multiset.mem_cons_self Multiset.mem_cons_self theorem forall_mem_cons {p : α → Prop} {a : α} {s : Multiset α} : (∀ x ∈ a ::ₘ s, p x) ↔ p a ∧ ∀ x ∈ s, p x := Quotient.inductionOn' s fun _ => List.forall_mem_cons #align multiset.forall_mem_cons Multiset.forall_mem_cons theorem exists_cons_of_mem {s : Multiset α} {a : α} : a ∈ s → ∃ t, s = a ::ₘ t := Quot.inductionOn s fun l (h : a ∈ l) => let ⟨l₁, l₂, e⟩ := append_of_mem h e.symm ▸ ⟨(l₁ ++ l₂ : List α), Quot.sound perm_middle⟩ #align multiset.exists_cons_of_mem Multiset.exists_cons_of_mem @[simp] theorem not_mem_zero (a : α) : a ∉ (0 : Multiset α) := List.not_mem_nil _ #align multiset.not_mem_zero Multiset.not_mem_zero theorem eq_zero_of_forall_not_mem {s : Multiset α} : (∀ x, x ∉ s) → s = 0 := Quot.inductionOn s fun l H => by rw [eq_nil_iff_forall_not_mem.mpr H]; rfl #align multiset.eq_zero_of_forall_not_mem Multiset.eq_zero_of_forall_not_mem theorem eq_zero_iff_forall_not_mem {s : Multiset α} : s = 0 ↔ ∀ a, a ∉ s := ⟨fun h => h.symm ▸ fun _ => not_mem_zero _, eq_zero_of_forall_not_mem⟩ #align multiset.eq_zero_iff_forall_not_mem Multiset.eq_zero_iff_forall_not_mem theorem exists_mem_of_ne_zero {s : Multiset α} : s ≠ 0 → ∃ a : α, a ∈ s := Quot.inductionOn s fun l hl => match l, hl with | [], h => False.elim <| h rfl | a :: l, _ => ⟨a, by simp⟩ #align multiset.exists_mem_of_ne_zero Multiset.exists_mem_of_ne_zero theorem empty_or_exists_mem (s : Multiset α) : s = 0 ∨ ∃ a, a ∈ s := or_iff_not_imp_left.mpr Multiset.exists_mem_of_ne_zero #align multiset.empty_or_exists_mem Multiset.empty_or_exists_mem @[simp] theorem zero_ne_cons {a : α} {m : Multiset α} : 0 ≠ a ::ₘ m := fun h => have : a ∈ (0 : Multiset α) := h.symm ▸ mem_cons_self _ _ not_mem_zero _ this #align multiset.zero_ne_cons Multiset.zero_ne_cons @[simp] theorem cons_ne_zero {a : α} {m : Multiset α} : a ::ₘ m ≠ 0 := zero_ne_cons.symm #align multiset.cons_ne_zero Multiset.cons_ne_zero theorem cons_eq_cons {a b : α} {as bs : Multiset α} : a ::ₘ as = b ::ₘ bs ↔ a = b ∧ as = bs ∨ a ≠ b ∧ ∃ cs, as = b ::ₘ cs ∧ bs = a ::ₘ cs := by haveI : DecidableEq α := Classical.decEq α constructor · intro eq by_cases h : a = b · subst h simp_all · have : a ∈ b ::ₘ bs := eq ▸ mem_cons_self _ _ have : a ∈ bs := by simpa [h] rcases exists_cons_of_mem this with ⟨cs, hcs⟩ simp only [h, hcs, false_and, ne_eq, not_false_eq_true, cons_inj_right, exists_eq_right', true_and, false_or] have : a ::ₘ as = b ::ₘ a ::ₘ cs := by simp [eq, hcs] have : a ::ₘ as = a ::ₘ b ::ₘ cs := by rwa [cons_swap] simpa using this · intro h rcases h with (⟨eq₁, eq₂⟩ | ⟨_, cs, eq₁, eq₂⟩) · simp [*] · simp [*, cons_swap a b] #align multiset.cons_eq_cons Multiset.cons_eq_cons end Mem /-! ### Singleton -/ instance : Singleton α (Multiset α) := ⟨fun a => a ::ₘ 0⟩ instance : LawfulSingleton α (Multiset α) := ⟨fun _ => rfl⟩ @[simp] theorem cons_zero (a : α) : a ::ₘ 0 = {a} := rfl #align multiset.cons_zero Multiset.cons_zero @[simp, norm_cast] theorem coe_singleton (a : α) : ([a] : Multiset α) = {a} := rfl #align multiset.coe_singleton Multiset.coe_singleton @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Multiset α) ↔ b = a := by simp only [← cons_zero, mem_cons, iff_self_iff, or_false_iff, not_mem_zero] #align multiset.mem_singleton Multiset.mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Multiset α) := by rw [← cons_zero] exact mem_cons_self _ _ #align multiset.mem_singleton_self Multiset.mem_singleton_self @[simp] theorem singleton_inj {a b : α} : ({a} : Multiset α) = {b} ↔ a = b := by simp_rw [← cons_zero] exact cons_inj_left _ #align multiset.singleton_inj Multiset.singleton_inj @[simp, norm_cast] theorem coe_eq_singleton {l : List α} {a : α} : (l : Multiset α) = {a} ↔ l = [a] := by rw [← coe_singleton, coe_eq_coe, List.perm_singleton] #align multiset.coe_eq_singleton Multiset.coe_eq_singleton @[simp] theorem singleton_eq_cons_iff {a b : α} (m : Multiset α) : {a} = b ::ₘ m ↔ a = b ∧ m = 0 := by rw [← cons_zero, cons_eq_cons] simp [eq_comm] #align multiset.singleton_eq_cons_iff Multiset.singleton_eq_cons_iff theorem pair_comm (x y : α) : ({x, y} : Multiset α) = {y, x} := cons_swap x y 0 #align multiset.pair_comm Multiset.pair_comm /-! ### `Multiset.Subset` -/ section Subset variable {s : Multiset α} {a : α} /-- `s ⊆ t` is the lift of the list subset relation. It means that any element with nonzero multiplicity in `s` has nonzero multiplicity in `t`, but it does not imply that the multiplicity of `a` in `s` is less or equal than in `t`; see `s ≤ t` for this relation. -/ protected def Subset (s t : Multiset α) : Prop := ∀ ⦃a : α⦄, a ∈ s → a ∈ t #align multiset.subset Multiset.Subset instance : HasSubset (Multiset α) := ⟨Multiset.Subset⟩ instance : HasSSubset (Multiset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance instIsNonstrictStrictOrder : IsNonstrictStrictOrder (Multiset α) (· ⊆ ·) (· ⊂ ·) where right_iff_left_not_left _ _ := Iff.rfl @[simp] theorem coe_subset {l₁ l₂ : List α} : (l₁ : Multiset α) ⊆ l₂ ↔ l₁ ⊆ l₂ := Iff.rfl #align multiset.coe_subset Multiset.coe_subset @[simp] theorem Subset.refl (s : Multiset α) : s ⊆ s := fun _ h => h #align multiset.subset.refl Multiset.Subset.refl theorem Subset.trans {s t u : Multiset α} : s ⊆ t → t ⊆ u → s ⊆ u := fun h₁ h₂ _ m => h₂ (h₁ m) #align multiset.subset.trans Multiset.Subset.trans theorem subset_iff {s t : Multiset α} : s ⊆ t ↔ ∀ ⦃x⦄, x ∈ s → x ∈ t := Iff.rfl #align multiset.subset_iff Multiset.subset_iff theorem mem_of_subset {s t : Multiset α} {a : α} (h : s ⊆ t) : a ∈ s → a ∈ t := @h _ #align multiset.mem_of_subset Multiset.mem_of_subset @[simp] theorem zero_subset (s : Multiset α) : 0 ⊆ s := fun a => (not_mem_nil a).elim #align multiset.zero_subset Multiset.zero_subset theorem subset_cons (s : Multiset α) (a : α) : s ⊆ a ::ₘ s := fun _ => mem_cons_of_mem #align multiset.subset_cons Multiset.subset_cons theorem ssubset_cons {s : Multiset α} {a : α} (ha : a ∉ s) : s ⊂ a ::ₘ s := ⟨subset_cons _ _, fun h => ha <| h <| mem_cons_self _ _⟩ #align multiset.ssubset_cons Multiset.ssubset_cons @[simp] theorem cons_subset {a : α} {s t : Multiset α} : a ::ₘ s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp [subset_iff, or_imp, forall_and] #align multiset.cons_subset Multiset.cons_subset theorem cons_subset_cons {a : α} {s t : Multiset α} : s ⊆ t → a ::ₘ s ⊆ a ::ₘ t := Quotient.inductionOn₂ s t fun _ _ => List.cons_subset_cons _ #align multiset.cons_subset_cons Multiset.cons_subset_cons theorem eq_zero_of_subset_zero {s : Multiset α} (h : s ⊆ 0) : s = 0 := eq_zero_of_forall_not_mem fun _ hx ↦ not_mem_zero _ (h hx) #align multiset.eq_zero_of_subset_zero Multiset.eq_zero_of_subset_zero @[simp] lemma subset_zero : s ⊆ 0 ↔ s = 0 := ⟨eq_zero_of_subset_zero, fun xeq => xeq.symm ▸ Subset.refl 0⟩ #align multiset.subset_zero Multiset.subset_zero @[simp] lemma zero_ssubset : 0 ⊂ s ↔ s ≠ 0 := by simp [ssubset_iff_subset_not_subset] @[simp] lemma singleton_subset : {a} ⊆ s ↔ a ∈ s := by simp [subset_iff] theorem induction_on' {p : Multiset α → Prop} (S : Multiset α) (h₁ : p 0) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → p s → p (insert a s)) : p S := @Multiset.induction_on α (fun T => T ⊆ S → p T) S (fun _ => h₁) (fun _ _ hps hs => let ⟨hS, sS⟩ := cons_subset.1 hs h₂ hS sS (hps sS)) (Subset.refl S) #align multiset.induction_on' Multiset.induction_on' end Subset /-! ### `Multiset.toList` -/ section ToList /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def toList (s : Multiset α) := s.out' #align multiset.to_list Multiset.toList @[simp, norm_cast] theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s := s.out_eq' #align multiset.coe_to_list Multiset.coe_toList @[simp] theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_toList] #align multiset.to_list_eq_nil Multiset.toList_eq_nil @[simp] theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := isEmpty_iff_eq_nil.trans toList_eq_nil #align multiset.empty_to_list Multiset.empty_toList @[simp] theorem toList_zero : (Multiset.toList 0 : List α) = [] := toList_eq_nil.mpr rfl #align multiset.to_list_zero Multiset.toList_zero @[simp] theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by rw [← mem_coe, coe_toList] #align multiset.mem_to_list Multiset.mem_toList @[simp] theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton] #align multiset.to_list_eq_singleton_iff Multiset.toList_eq_singleton_iff @[simp] theorem toList_singleton (a : α) : ({a} : Multiset α).toList = [a] := Multiset.toList_eq_singleton_iff.2 rfl #align multiset.to_list_singleton Multiset.toList_singleton end ToList /-! ### Partial order on `Multiset`s -/ /-- `s ≤ t` means that `s` is a sublist of `t` (up to permutation). Equivalently, `s ≤ t` means that `count a s ≤ count a t` for all `a`. -/ protected def Le (s t : Multiset α) : Prop := (Quotient.liftOn₂ s t (· <+~ ·)) fun _ _ _ _ p₁ p₂ => propext (p₂.subperm_left.trans p₁.subperm_right) #align multiset.le Multiset.Le instance : PartialOrder (Multiset α) where le := Multiset.Le le_refl := by rintro ⟨l⟩; exact Subperm.refl _ le_trans := by rintro ⟨l₁⟩ ⟨l₂⟩ ⟨l₃⟩; exact @Subperm.trans _ _ _ _ le_antisymm := by rintro ⟨l₁⟩ ⟨l₂⟩ h₁ h₂; exact Quot.sound (Subperm.antisymm h₁ h₂) instance decidableLE [DecidableEq α] : DecidableRel ((· ≤ ·) : Multiset α → Multiset α → Prop) := fun s t => Quotient.recOnSubsingleton₂ s t List.decidableSubperm #align multiset.decidable_le Multiset.decidableLE section variable {s t : Multiset α} {a : α} theorem subset_of_le : s ≤ t → s ⊆ t := Quotient.inductionOn₂ s t fun _ _ => Subperm.subset #align multiset.subset_of_le Multiset.subset_of_le alias Le.subset := subset_of_le #align multiset.le.subset Multiset.Le.subset theorem mem_of_le (h : s ≤ t) : a ∈ s → a ∈ t := mem_of_subset (subset_of_le h) #align multiset.mem_of_le Multiset.mem_of_le theorem not_mem_mono (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| @h _ #align multiset.not_mem_mono Multiset.not_mem_mono @[simp] theorem coe_le {l₁ l₂ : List α} : (l₁ : Multiset α) ≤ l₂ ↔ l₁ <+~ l₂ := Iff.rfl #align multiset.coe_le Multiset.coe_le @[elab_as_elim] theorem leInductionOn {C : Multiset α → Multiset α → Prop} {s t : Multiset α} (h : s ≤ t) (H : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → C l₁ l₂) : C s t := Quotient.inductionOn₂ s t (fun l₁ _ ⟨l, p, s⟩ => (show ⟦l⟧ = ⟦l₁⟧ from Quot.sound p) ▸ H s) h #align multiset.le_induction_on Multiset.leInductionOn theorem zero_le (s : Multiset α) : 0 ≤ s := Quot.inductionOn s fun l => (nil_sublist l).subperm #align multiset.zero_le Multiset.zero_le instance : OrderBot (Multiset α) where bot := 0 bot_le := zero_le /-- This is a `rfl` and `simp` version of `bot_eq_zero`. -/ @[simp] theorem bot_eq_zero : (⊥ : Multiset α) = 0 := rfl #align multiset.bot_eq_zero Multiset.bot_eq_zero theorem le_zero : s ≤ 0 ↔ s = 0 := le_bot_iff #align multiset.le_zero Multiset.le_zero theorem lt_cons_self (s : Multiset α) (a : α) : s < a ::ₘ s := Quot.inductionOn s fun l => suffices l <+~ a :: l ∧ ¬l ~ a :: l by simpa [lt_iff_le_and_ne] ⟨(sublist_cons _ _).subperm, fun p => _root_.ne_of_lt (lt_succ_self (length l)) p.length_eq⟩ #align multiset.lt_cons_self Multiset.lt_cons_self theorem le_cons_self (s : Multiset α) (a : α) : s ≤ a ::ₘ s := le_of_lt <| lt_cons_self _ _ #align multiset.le_cons_self Multiset.le_cons_self theorem cons_le_cons_iff (a : α) : a ::ₘ s ≤ a ::ₘ t ↔ s ≤ t := Quotient.inductionOn₂ s t fun _ _ => subperm_cons a #align multiset.cons_le_cons_iff Multiset.cons_le_cons_iff theorem cons_le_cons (a : α) : s ≤ t → a ::ₘ s ≤ a ::ₘ t := (cons_le_cons_iff a).2 #align multiset.cons_le_cons Multiset.cons_le_cons @[simp] lemma cons_lt_cons_iff : a ::ₘ s < a ::ₘ t ↔ s < t := lt_iff_lt_of_le_iff_le' (cons_le_cons_iff _) (cons_le_cons_iff _) lemma cons_lt_cons (a : α) (h : s < t) : a ::ₘ s < a ::ₘ t := cons_lt_cons_iff.2 h theorem le_cons_of_not_mem (m : a ∉ s) : s ≤ a ::ₘ t ↔ s ≤ t := by refine ⟨?_, fun h => le_trans h <| le_cons_self _ _⟩ suffices ∀ {t'}, s ≤ t' → a ∈ t' → a ::ₘ s ≤ t' by exact fun h => (cons_le_cons_iff a).1 (this h (mem_cons_self _ _)) introv h revert m refine leInductionOn h ?_ introv s m₁ m₂ rcases append_of_mem m₂ with ⟨r₁, r₂, rfl⟩ exact perm_middle.subperm_left.2 ((subperm_cons _).2 <| ((sublist_or_mem_of_sublist s).resolve_right m₁).subperm) #align multiset.le_cons_of_not_mem Multiset.le_cons_of_not_mem @[simp] theorem singleton_ne_zero (a : α) : ({a} : Multiset α) ≠ 0 := ne_of_gt (lt_cons_self _ _) #align multiset.singleton_ne_zero Multiset.singleton_ne_zero @[simp] theorem singleton_le {a : α} {s : Multiset α} : {a} ≤ s ↔ a ∈ s := ⟨fun h => mem_of_le h (mem_singleton_self _), fun h => let ⟨_t, e⟩ := exists_cons_of_mem h e.symm ▸ cons_le_cons _ (zero_le _)⟩ #align multiset.singleton_le Multiset.singleton_le @[simp] lemma le_singleton : s ≤ {a} ↔ s = 0 ∨ s = {a} := Quot.induction_on s fun l ↦ by simp only [cons_zero, ← coe_singleton, quot_mk_to_coe'', coe_le, coe_eq_zero, coe_eq_coe, perm_singleton, subperm_singleton_iff] @[simp] lemma lt_singleton : s < {a} ↔ s = 0 := by simp only [lt_iff_le_and_ne, le_singleton, or_and_right, Ne, and_not_self, or_false, and_iff_left_iff_imp] rintro rfl exact (singleton_ne_zero _).symm @[simp] lemma ssubset_singleton_iff : s ⊂ {a} ↔ s = 0 := by refine ⟨fun hs ↦ eq_zero_of_subset_zero fun b hb ↦ (hs.2 ?_).elim, ?_⟩ · obtain rfl := mem_singleton.1 (hs.1 hb) rwa [singleton_subset] · rintro rfl simp end /-! ### Additive monoid -/ /-- The sum of two multisets is the lift of the list append operation. This adds the multiplicities of each element, i.e. `count a (s + t) = count a s + count a t`. -/ protected def add (s₁ s₂ : Multiset α) : Multiset α := (Quotient.liftOn₂ s₁ s₂ fun l₁ l₂ => ((l₁ ++ l₂ : List α) : Multiset α)) fun _ _ _ _ p₁ p₂ => Quot.sound <| p₁.append p₂ #align multiset.add Multiset.add instance : Add (Multiset α) := ⟨Multiset.add⟩ @[simp] theorem coe_add (s t : List α) : (s + t : Multiset α) = (s ++ t : List α) := rfl #align multiset.coe_add Multiset.coe_add @[simp] theorem singleton_add (a : α) (s : Multiset α) : {a} + s = a ::ₘ s := rfl #align multiset.singleton_add Multiset.singleton_add private theorem add_le_add_iff_left' {s t u : Multiset α} : s + t ≤ s + u ↔ t ≤ u := Quotient.inductionOn₃ s t u fun _ _ _ => subperm_append_left _ instance : CovariantClass (Multiset α) (Multiset α) (· + ·) (· ≤ ·) := ⟨fun _s _t _u => add_le_add_iff_left'.2⟩ instance : ContravariantClass (Multiset α) (Multiset α) (· + ·) (· ≤ ·) := ⟨fun _s _t _u => add_le_add_iff_left'.1⟩ instance : OrderedCancelAddCommMonoid (Multiset α) where zero := 0 add := (· + ·) add_comm := fun s t => Quotient.inductionOn₂ s t fun l₁ l₂ => Quot.sound perm_append_comm add_assoc := fun s₁ s₂ s₃ => Quotient.inductionOn₃ s₁ s₂ s₃ fun l₁ l₂ l₃ => congr_arg _ <| append_assoc l₁ l₂ l₃ zero_add := fun s => Quot.inductionOn s fun l => rfl add_zero := fun s => Quotient.inductionOn s fun l => congr_arg _ <| append_nil l add_le_add_left := fun s₁ s₂ => add_le_add_left le_of_add_le_add_left := fun s₁ s₂ s₃ => le_of_add_le_add_left nsmul := nsmulRec theorem le_add_right (s t : Multiset α) : s ≤ s + t := by simpa using add_le_add_left (zero_le t) s #align multiset.le_add_right Multiset.le_add_right theorem le_add_left (s t : Multiset α) : s ≤ t + s := by simpa using add_le_add_right (zero_le t) s #align multiset.le_add_left Multiset.le_add_left theorem le_iff_exists_add {s t : Multiset α} : s ≤ t ↔ ∃ u, t = s + u := ⟨fun h => leInductionOn h fun s => let ⟨l, p⟩ := s.exists_perm_append ⟨l, Quot.sound p⟩, fun ⟨_u, e⟩ => e.symm ▸ le_add_right _ _⟩ #align multiset.le_iff_exists_add Multiset.le_iff_exists_add instance : CanonicallyOrderedAddCommMonoid (Multiset α) where __ := inferInstanceAs (OrderBot (Multiset α)) le_self_add := le_add_right exists_add_of_le h := leInductionOn h fun s => let ⟨l, p⟩ := s.exists_perm_append ⟨l, Quot.sound p⟩ @[simp] theorem cons_add (a : α) (s t : Multiset α) : a ::ₘ s + t = a ::ₘ (s + t) := by rw [← singleton_add, ← singleton_add, add_assoc] #align multiset.cons_add Multiset.cons_add @[simp] theorem add_cons (a : α) (s t : Multiset α) : s + a ::ₘ t = a ::ₘ (s + t) := by rw [add_comm, cons_add, add_comm] #align multiset.add_cons Multiset.add_cons @[simp] theorem mem_add {a : α} {s t : Multiset α} : a ∈ s + t ↔ a ∈ s ∨ a ∈ t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => mem_append #align multiset.mem_add Multiset.mem_add theorem mem_of_mem_nsmul {a : α} {s : Multiset α} {n : ℕ} (h : a ∈ n • s) : a ∈ s := by induction' n with n ih · rw [zero_nsmul] at h exact absurd h (not_mem_zero _) · rw [succ_nsmul, mem_add] at h exact h.elim ih id #align multiset.mem_of_mem_nsmul Multiset.mem_of_mem_nsmul @[simp] theorem mem_nsmul {a : α} {s : Multiset α} {n : ℕ} (h0 : n ≠ 0) : a ∈ n • s ↔ a ∈ s := by refine ⟨mem_of_mem_nsmul, fun h => ?_⟩ obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero h0 rw [succ_nsmul, mem_add] exact Or.inr h #align multiset.mem_nsmul Multiset.mem_nsmul theorem nsmul_cons {s : Multiset α} (n : ℕ) (a : α) : n • (a ::ₘ s) = n • ({a} : Multiset α) + n • s := by rw [← singleton_add, nsmul_add] #align multiset.nsmul_cons Multiset.nsmul_cons /-! ### Cardinality -/ /-- The cardinality of a multiset is the sum of the multiplicities of all its elements, or simply the length of the underlying list. -/ def card : Multiset α →+ ℕ where toFun s := (Quot.liftOn s length) fun _l₁ _l₂ => Perm.length_eq map_zero' := rfl map_add' s t := Quotient.inductionOn₂ s t length_append #align multiset.card Multiset.card @[simp] theorem coe_card (l : List α) : card (l : Multiset α) = length l := rfl #align multiset.coe_card Multiset.coe_card @[simp] theorem length_toList (s : Multiset α) : s.toList.length = card s := by rw [← coe_card, coe_toList] #align multiset.length_to_list Multiset.length_toList @[simp, nolint simpNF] -- Porting note (#10675): `dsimp` can not prove this, yet linter complains theorem card_zero : @card α 0 = 0 := rfl #align multiset.card_zero Multiset.card_zero theorem card_add (s t : Multiset α) : card (s + t) = card s + card t := card.map_add s t #align multiset.card_add Multiset.card_add theorem card_nsmul (s : Multiset α) (n : ℕ) : card (n • s) = n * card s := by rw [card.map_nsmul s n, Nat.nsmul_eq_mul] #align multiset.card_nsmul Multiset.card_nsmul @[simp] theorem card_cons (a : α) (s : Multiset α) : card (a ::ₘ s) = card s + 1 := Quot.inductionOn s fun _l => rfl #align multiset.card_cons Multiset.card_cons @[simp] theorem card_singleton (a : α) : card ({a} : Multiset α) = 1 := by simp only [← cons_zero, card_zero, eq_self_iff_true, zero_add, card_cons] #align multiset.card_singleton Multiset.card_singleton theorem card_pair (a b : α) : card {a, b} = 2 := by rw [insert_eq_cons, card_cons, card_singleton] #align multiset.card_pair Multiset.card_pair theorem card_eq_one {s : Multiset α} : card s = 1 ↔ ∃ a, s = {a} := ⟨Quot.inductionOn s fun _l h => (List.length_eq_one.1 h).imp fun _a => congr_arg _, fun ⟨_a, e⟩ => e.symm ▸ rfl⟩ #align multiset.card_eq_one Multiset.card_eq_one theorem card_le_card {s t : Multiset α} (h : s ≤ t) : card s ≤ card t := leInductionOn h Sublist.length_le #align multiset.card_le_of_le Multiset.card_le_card @[mono] theorem card_mono : Monotone (@card α) := fun _a _b => card_le_card #align multiset.card_mono Multiset.card_mono theorem eq_of_le_of_card_le {s t : Multiset α} (h : s ≤ t) : card t ≤ card s → s = t := leInductionOn h fun s h₂ => congr_arg _ <| s.eq_of_length_le h₂ #align multiset.eq_of_le_of_card_le Multiset.eq_of_le_of_card_le theorem card_lt_card {s t : Multiset α} (h : s < t) : card s < card t := lt_of_not_ge fun h₂ => _root_.ne_of_lt h <| eq_of_le_of_card_le (le_of_lt h) h₂ #align multiset.card_lt_card Multiset.card_lt_card lemma card_strictMono : StrictMono (card : Multiset α → ℕ) := fun _ _ ↦ card_lt_card theorem lt_iff_cons_le {s t : Multiset α} : s < t ↔ ∃ a, a ::ₘ s ≤ t := ⟨Quotient.inductionOn₂ s t fun _l₁ _l₂ h => Subperm.exists_of_length_lt (le_of_lt h) (card_lt_card h), fun ⟨_a, h⟩ => lt_of_lt_of_le (lt_cons_self _ _) h⟩ #align multiset.lt_iff_cons_le Multiset.lt_iff_cons_le @[simp] theorem card_eq_zero {s : Multiset α} : card s = 0 ↔ s = 0 := ⟨fun h => (eq_of_le_of_card_le (zero_le _) (le_of_eq h)).symm, fun e => by simp [e]⟩ #align multiset.card_eq_zero Multiset.card_eq_zero theorem card_pos {s : Multiset α} : 0 < card s ↔ s ≠ 0 := Nat.pos_iff_ne_zero.trans <| not_congr card_eq_zero #align multiset.card_pos Multiset.card_pos theorem card_pos_iff_exists_mem {s : Multiset α} : 0 < card s ↔ ∃ a, a ∈ s := Quot.inductionOn s fun _l => length_pos_iff_exists_mem #align multiset.card_pos_iff_exists_mem Multiset.card_pos_iff_exists_mem theorem card_eq_two {s : Multiset α} : card s = 2 ↔ ∃ x y, s = {x, y} := ⟨Quot.inductionOn s fun _l h => (List.length_eq_two.mp h).imp fun _a => Exists.imp fun _b => congr_arg _, fun ⟨_a, _b, e⟩ => e.symm ▸ rfl⟩ #align multiset.card_eq_two Multiset.card_eq_two theorem card_eq_three {s : Multiset α} : card s = 3 ↔ ∃ x y z, s = {x, y, z} := ⟨Quot.inductionOn s fun _l h => (List.length_eq_three.mp h).imp fun _a => Exists.imp fun _b => Exists.imp fun _c => congr_arg _, fun ⟨_a, _b, _c, e⟩ => e.symm ▸ rfl⟩ #align multiset.card_eq_three Multiset.card_eq_three /-! ### Induction principles -/ /-- The strong induction principle for multisets. -/ @[elab_as_elim] def strongInductionOn {p : Multiset α → Sort*} (s : Multiset α) (ih : ∀ s, (∀ t < s, p t) → p s) : p s := (ih s) fun t _h => strongInductionOn t ih termination_by card s decreasing_by exact card_lt_card _h #align multiset.strong_induction_on Multiset.strongInductionOnₓ -- Porting note: reorderd universes theorem strongInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) (H) : @strongInductionOn _ p s H = H s fun t _h => @strongInductionOn _ p t H := by rw [strongInductionOn] #align multiset.strong_induction_eq Multiset.strongInductionOn_eq @[elab_as_elim] theorem case_strongInductionOn {p : Multiset α → Prop} (s : Multiset α) (h₀ : p 0) (h₁ : ∀ a s, (∀ t ≤ s, p t) → p (a ::ₘ s)) : p s := Multiset.strongInductionOn s fun s => Multiset.induction_on s (fun _ => h₀) fun _a _s _ ih => (h₁ _ _) fun _t h => ih _ <| lt_of_le_of_lt h <| lt_cons_self _ _ #align multiset.case_strong_induction_on Multiset.case_strongInductionOn /-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than `n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of cardinality less than `n`, starting from multisets of card `n` and iterating. This can be used either to define data, or to prove properties. -/ def strongDownwardInduction {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : card s ≤ n → p s := H s fun {t} ht _h => strongDownwardInduction H t ht termination_by n - card s decreasing_by simp_wf; have := (card_lt_card _h); omega -- Porting note: reorderd universes #align multiset.strong_downward_induction Multiset.strongDownwardInductionₓ theorem strongDownwardInduction_eq {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : strongDownwardInduction H s = H s fun ht _hst => strongDownwardInduction H _ ht := by rw [strongDownwardInduction] #align multiset.strong_downward_induction_eq Multiset.strongDownwardInduction_eq /-- Analogue of `strongDownwardInduction` with order of arguments swapped. -/ @[elab_as_elim] def strongDownwardInductionOn {p : Multiset α → Sort*} {n : ℕ} : ∀ s : Multiset α, (∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) → card s ≤ n → p s := fun s H => strongDownwardInduction H s #align multiset.strong_downward_induction_on Multiset.strongDownwardInductionOn theorem strongDownwardInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) : s.strongDownwardInductionOn H = H s fun {t} ht _h => t.strongDownwardInductionOn H ht := by dsimp only [strongDownwardInductionOn] rw [strongDownwardInduction] #align multiset.strong_downward_induction_on_eq Multiset.strongDownwardInductionOn_eq #align multiset.well_founded_lt wellFounded_lt /-- Another way of expressing `strongInductionOn`: the `(<)` relation is well-founded. -/ instance instWellFoundedLT : WellFoundedLT (Multiset α) := ⟨Subrelation.wf Multiset.card_lt_card (measure Multiset.card).2⟩ #align multiset.is_well_founded_lt Multiset.instWellFoundedLT /-! ### `Multiset.replicate` -/ /-- `replicate n a` is the multiset containing only `a` with multiplicity `n`. -/ def replicate (n : ℕ) (a : α) : Multiset α := List.replicate n a #align multiset.replicate Multiset.replicate theorem coe_replicate (n : ℕ) (a : α) : (List.replicate n a : Multiset α) = replicate n a := rfl #align multiset.coe_replicate Multiset.coe_replicate @[simp] theorem replicate_zero (a : α) : replicate 0 a = 0 := rfl #align multiset.replicate_zero Multiset.replicate_zero @[simp] theorem replicate_succ (a : α) (n) : replicate (n + 1) a = a ::ₘ replicate n a := rfl #align multiset.replicate_succ Multiset.replicate_succ theorem replicate_add (m n : ℕ) (a : α) : replicate (m + n) a = replicate m a + replicate n a := congr_arg _ <| List.replicate_add .. #align multiset.replicate_add Multiset.replicate_add /-- `Multiset.replicate` as an `AddMonoidHom`. -/ @[simps] def replicateAddMonoidHom (a : α) : ℕ →+ Multiset α where toFun := fun n => replicate n a map_zero' := replicate_zero a map_add' := fun _ _ => replicate_add _ _ a #align multiset.replicate_add_monoid_hom Multiset.replicateAddMonoidHom #align multiset.replicate_add_monoid_hom_apply Multiset.replicateAddMonoidHom_apply theorem replicate_one (a : α) : replicate 1 a = {a} := rfl #align multiset.replicate_one Multiset.replicate_one @[simp] theorem card_replicate (n) (a : α) : card (replicate n a) = n := length_replicate n a #align multiset.card_replicate Multiset.card_replicate theorem mem_replicate {a b : α} {n : ℕ} : b ∈ replicate n a ↔ n ≠ 0 ∧ b = a := List.mem_replicate #align multiset.mem_replicate Multiset.mem_replicate theorem eq_of_mem_replicate {a b : α} {n} : b ∈ replicate n a → b = a := List.eq_of_mem_replicate #align multiset.eq_of_mem_replicate Multiset.eq_of_mem_replicate theorem eq_replicate_card {a : α} {s : Multiset α} : s = replicate (card s) a ↔ ∀ b ∈ s, b = a := Quot.inductionOn s fun _l => coe_eq_coe.trans <| perm_replicate.trans eq_replicate_length #align multiset.eq_replicate_card Multiset.eq_replicate_card alias ⟨_, eq_replicate_of_mem⟩ := eq_replicate_card #align multiset.eq_replicate_of_mem Multiset.eq_replicate_of_mem theorem eq_replicate {a : α} {n} {s : Multiset α} : s = replicate n a ↔ card s = n ∧ ∀ b ∈ s, b = a := ⟨fun h => h.symm ▸ ⟨card_replicate _ _, fun _b => eq_of_mem_replicate⟩, fun ⟨e, al⟩ => e ▸ eq_replicate_of_mem al⟩ #align multiset.eq_replicate Multiset.eq_replicate theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ #align multiset.replicate_right_injective Multiset.replicate_right_injective @[simp] theorem replicate_right_inj {a b : α} {n : ℕ} (h : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective h).eq_iff #align multiset.replicate_right_inj Multiset.replicate_right_inj theorem replicate_left_injective (a : α) : Injective (replicate · a) := -- Porting note: was `fun m n h => by rw [← (eq_replicate.1 h).1, card_replicate]` LeftInverse.injective (card_replicate · a) #align multiset.replicate_left_injective Multiset.replicate_left_injective theorem replicate_subset_singleton (n : ℕ) (a : α) : replicate n a ⊆ {a} := List.replicate_subset_singleton n a #align multiset.replicate_subset_singleton Multiset.replicate_subset_singleton theorem replicate_le_coe {a : α} {n} {l : List α} : replicate n a ≤ l ↔ List.replicate n a <+ l := ⟨fun ⟨_l', p, s⟩ => perm_replicate.1 p ▸ s, Sublist.subperm⟩ #align multiset.replicate_le_coe Multiset.replicate_le_coe theorem nsmul_replicate {a : α} (n m : ℕ) : n • replicate m a = replicate (n * m) a := ((replicateAddMonoidHom a).map_nsmul _ _).symm #align multiset.nsmul_replicate Multiset.nsmul_replicate theorem nsmul_singleton (a : α) (n) : n • ({a} : Multiset α) = replicate n a := by rw [← replicate_one, nsmul_replicate, mul_one] #align multiset.nsmul_singleton Multiset.nsmul_singleton theorem replicate_le_replicate (a : α) {k n : ℕ} : replicate k a ≤ replicate n a ↔ k ≤ n := _root_.trans (by rw [← replicate_le_coe, coe_replicate]) (List.replicate_sublist_replicate a) #align multiset.replicate_le_replicate Multiset.replicate_le_replicate theorem le_replicate_iff {m : Multiset α} {a : α} {n : ℕ} : m ≤ replicate n a ↔ ∃ k ≤ n, m = replicate k a := ⟨fun h => ⟨card m, (card_mono h).trans_eq (card_replicate _ _), eq_replicate_card.2 fun _ hb => eq_of_mem_replicate <| subset_of_le h hb⟩, fun ⟨_, hkn, hm⟩ => hm.symm ▸ (replicate_le_replicate _).2 hkn⟩ #align multiset.le_replicate_iff Multiset.le_replicate_iff theorem lt_replicate_succ {m : Multiset α} {x : α} {n : ℕ} : m < replicate (n + 1) x ↔ m ≤ replicate n x := by rw [lt_iff_cons_le] constructor · rintro ⟨x', hx'⟩ have := eq_of_mem_replicate (mem_of_le hx' (mem_cons_self _ _)) rwa [this, replicate_succ, cons_le_cons_iff] at hx' · intro h rw [replicate_succ] exact ⟨x, cons_le_cons _ h⟩ #align multiset.lt_replicate_succ Multiset.lt_replicate_succ /-! ### Erasing one copy of an element -/ section Erase variable [DecidableEq α] {s t : Multiset α} {a b : α} /-- `erase s a` is the multiset that subtracts 1 from the multiplicity of `a`. -/ def erase (s : Multiset α) (a : α) : Multiset α := Quot.liftOn s (fun l => (l.erase a : Multiset α)) fun _l₁ _l₂ p => Quot.sound (p.erase a) #align multiset.erase Multiset.erase @[simp] theorem coe_erase (l : List α) (a : α) : erase (l : Multiset α) a = l.erase a := rfl #align multiset.coe_erase Multiset.coe_erase @[simp, nolint simpNF] -- Porting note (#10675): `dsimp` can not prove this, yet linter complains theorem erase_zero (a : α) : (0 : Multiset α).erase a = 0 := rfl #align multiset.erase_zero Multiset.erase_zero @[simp] theorem erase_cons_head (a : α) (s : Multiset α) : (a ::ₘ s).erase a = s := Quot.inductionOn s fun l => congr_arg _ <| List.erase_cons_head a l #align multiset.erase_cons_head Multiset.erase_cons_head @[simp] theorem erase_cons_tail {a b : α} (s : Multiset α) (h : b ≠ a) : (b ::ₘ s).erase a = b ::ₘ s.erase a := Quot.inductionOn s fun l => congr_arg _ <| List.erase_cons_tail l (not_beq_of_ne h) #align multiset.erase_cons_tail Multiset.erase_cons_tail @[simp] theorem erase_singleton (a : α) : ({a} : Multiset α).erase a = 0 := erase_cons_head a 0 #align multiset.erase_singleton Multiset.erase_singleton @[simp] theorem erase_of_not_mem {a : α} {s : Multiset α} : a ∉ s → s.erase a = s := Quot.inductionOn s fun _l h => congr_arg _ <| List.erase_of_not_mem h #align multiset.erase_of_not_mem Multiset.erase_of_not_mem @[simp] theorem cons_erase {s : Multiset α} {a : α} : a ∈ s → a ::ₘ s.erase a = s := Quot.inductionOn s fun _l h => Quot.sound (perm_cons_erase h).symm #align multiset.cons_erase Multiset.cons_erase theorem erase_cons_tail_of_mem (h : a ∈ s) : (b ::ₘ s).erase a = b ::ₘ s.erase a := by rcases eq_or_ne a b with rfl | hab · simp [cons_erase h] · exact s.erase_cons_tail hab.symm theorem le_cons_erase (s : Multiset α) (a : α) : s ≤ a ::ₘ s.erase a := if h : a ∈ s then le_of_eq (cons_erase h).symm else by rw [erase_of_not_mem h]; apply le_cons_self #align multiset.le_cons_erase Multiset.le_cons_erase theorem add_singleton_eq_iff {s t : Multiset α} {a : α} : s + {a} = t ↔ a ∈ t ∧ s = t.erase a := by rw [add_comm, singleton_add]; constructor · rintro rfl exact ⟨s.mem_cons_self a, (s.erase_cons_head a).symm⟩ · rintro ⟨h, rfl⟩ exact cons_erase h #align multiset.add_singleton_eq_iff Multiset.add_singleton_eq_iff theorem erase_add_left_pos {a : α} {s : Multiset α} (t) : a ∈ s → (s + t).erase a = s.erase a + t := Quotient.inductionOn₂ s t fun _l₁ l₂ h => congr_arg _ <| erase_append_left l₂ h #align multiset.erase_add_left_pos Multiset.erase_add_left_pos theorem erase_add_right_pos {a : α} (s) {t : Multiset α} (h : a ∈ t) : (s + t).erase a = s + t.erase a := by rw [add_comm, erase_add_left_pos s h, add_comm] #align multiset.erase_add_right_pos Multiset.erase_add_right_pos theorem erase_add_right_neg {a : α} {s : Multiset α} (t) : a ∉ s → (s + t).erase a = s + t.erase a := Quotient.inductionOn₂ s t fun _l₁ l₂ h => congr_arg _ <| erase_append_right l₂ h #align multiset.erase_add_right_neg Multiset.erase_add_right_neg theorem erase_add_left_neg {a : α} (s) {t : Multiset α} (h : a ∉ t) : (s + t).erase a = s.erase a + t := by rw [add_comm, erase_add_right_neg s h, add_comm] #align multiset.erase_add_left_neg Multiset.erase_add_left_neg theorem erase_le (a : α) (s : Multiset α) : s.erase a ≤ s := Quot.inductionOn s fun l => (erase_sublist a l).subperm #align multiset.erase_le Multiset.erase_le @[simp] theorem erase_lt {a : α} {s : Multiset α} : s.erase a < s ↔ a ∈ s := ⟨fun h => not_imp_comm.1 erase_of_not_mem (ne_of_lt h), fun h => by simpa [h] using lt_cons_self (s.erase a) a⟩ #align multiset.erase_lt Multiset.erase_lt theorem erase_subset (a : α) (s : Multiset α) : s.erase a ⊆ s := subset_of_le (erase_le a s) #align multiset.erase_subset Multiset.erase_subset theorem mem_erase_of_ne {a b : α} {s : Multiset α} (ab : a ≠ b) : a ∈ s.erase b ↔ a ∈ s := Quot.inductionOn s fun _l => List.mem_erase_of_ne ab #align multiset.mem_erase_of_ne Multiset.mem_erase_of_ne theorem mem_of_mem_erase {a b : α} {s : Multiset α} : a ∈ s.erase b → a ∈ s := mem_of_subset (erase_subset _ _) #align multiset.mem_of_mem_erase Multiset.mem_of_mem_erase theorem erase_comm (s : Multiset α) (a b : α) : (s.erase a).erase b = (s.erase b).erase a := Quot.inductionOn s fun l => congr_arg _ <| l.erase_comm a b #align multiset.erase_comm Multiset.erase_comm theorem erase_le_erase {s t : Multiset α} (a : α) (h : s ≤ t) : s.erase a ≤ t.erase a := leInductionOn h fun h => (h.erase _).subperm #align multiset.erase_le_erase Multiset.erase_le_erase theorem erase_le_iff_le_cons {s t : Multiset α} {a : α} : s.erase a ≤ t ↔ s ≤ a ::ₘ t := ⟨fun h => le_trans (le_cons_erase _ _) (cons_le_cons _ h), fun h => if m : a ∈ s then by rw [← cons_erase m] at h; exact (cons_le_cons_iff _).1 h else le_trans (erase_le _ _) ((le_cons_of_not_mem m).1 h)⟩ #align multiset.erase_le_iff_le_cons Multiset.erase_le_iff_le_cons @[simp] theorem card_erase_of_mem {a : α} {s : Multiset α} : a ∈ s → card (s.erase a) = pred (card s) := Quot.inductionOn s fun _l => length_erase_of_mem #align multiset.card_erase_of_mem Multiset.card_erase_of_mem @[simp] theorem card_erase_add_one {a : α} {s : Multiset α} : a ∈ s → card (s.erase a) + 1 = card s := Quot.inductionOn s fun _l => length_erase_add_one #align multiset.card_erase_add_one Multiset.card_erase_add_one theorem card_erase_lt_of_mem {a : α} {s : Multiset α} : a ∈ s → card (s.erase a) < card s := fun h => card_lt_card (erase_lt.mpr h) #align multiset.card_erase_lt_of_mem Multiset.card_erase_lt_of_mem theorem card_erase_le {a : α} {s : Multiset α} : card (s.erase a) ≤ card s := card_le_card (erase_le a s) #align multiset.card_erase_le Multiset.card_erase_le theorem card_erase_eq_ite {a : α} {s : Multiset α} : card (s.erase a) = if a ∈ s then pred (card s) else card s := by by_cases h : a ∈ s · rwa [card_erase_of_mem h, if_pos] · rwa [erase_of_not_mem h, if_neg] #align multiset.card_erase_eq_ite Multiset.card_erase_eq_ite end Erase @[simp] theorem coe_reverse (l : List α) : (reverse l : Multiset α) = l := Quot.sound <| reverse_perm _ #align multiset.coe_reverse Multiset.coe_reverse /-! ### `Multiset.map` -/ /-- `map f s` is the lift of the list `map` operation. The multiplicity of `b` in `map f s` is the number of `a ∈ s` (counting multiplicity) such that `f a = b`. -/ def map (f : α → β) (s : Multiset α) : Multiset β := Quot.liftOn s (fun l : List α => (l.map f : Multiset β)) fun _l₁ _l₂ p => Quot.sound (p.map f) #align multiset.map Multiset.map @[congr] theorem map_congr {f g : α → β} {s t : Multiset α} : s = t → (∀ x ∈ t, f x = g x) → map f s = map g t := by rintro rfl h induction s using Quot.inductionOn exact congr_arg _ (List.map_congr h) #align multiset.map_congr Multiset.map_congr theorem map_hcongr {β' : Type v} {m : Multiset α} {f : α → β} {f' : α → β'} (h : β = β') (hf : ∀ a ∈ m, HEq (f a) (f' a)) : HEq (map f m) (map f' m) := by subst h; simp at hf simp [map_congr rfl hf] #align multiset.map_hcongr Multiset.map_hcongr theorem forall_mem_map_iff {f : α → β} {p : β → Prop} {s : Multiset α} : (∀ y ∈ s.map f, p y) ↔ ∀ x ∈ s, p (f x) := Quotient.inductionOn' s fun _L => List.forall_mem_map_iff #align multiset.forall_mem_map_iff Multiset.forall_mem_map_iff @[simp, norm_cast] lemma map_coe (f : α → β) (l : List α) : map f l = l.map f := rfl #align multiset.coe_map Multiset.map_coe @[simp] theorem map_zero (f : α → β) : map f 0 = 0 := rfl #align multiset.map_zero Multiset.map_zero @[simp] theorem map_cons (f : α → β) (a s) : map f (a ::ₘ s) = f a ::ₘ map f s := Quot.inductionOn s fun _l => rfl #align multiset.map_cons Multiset.map_cons theorem map_comp_cons (f : α → β) (t) : map f ∘ cons t = cons (f t) ∘ map f := by ext simp #align multiset.map_comp_cons Multiset.map_comp_cons @[simp] theorem map_singleton (f : α → β) (a : α) : ({a} : Multiset α).map f = {f a} := rfl #align multiset.map_singleton Multiset.map_singleton @[simp] theorem map_replicate (f : α → β) (k : ℕ) (a : α) : (replicate k a).map f = replicate k (f a) := by simp only [← coe_replicate, map_coe, List.map_replicate] #align multiset.map_replicate Multiset.map_replicate @[simp] theorem map_add (f : α → β) (s t) : map f (s + t) = map f s + map f t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => congr_arg _ <| map_append _ _ _ #align multiset.map_add Multiset.map_add /-- If each element of `s : Multiset α` can be lifted to `β`, then `s` can be lifted to `Multiset β`. -/ instance canLift (c) (p) [CanLift α β c p] : CanLift (Multiset α) (Multiset β) (map c) fun s => ∀ x ∈ s, p x where prf := by rintro ⟨l⟩ hl lift l to List β using hl exact ⟨l, map_coe _ _⟩ #align multiset.can_lift Multiset.canLift /-- `Multiset.map` as an `AddMonoidHom`. -/ def mapAddMonoidHom (f : α → β) : Multiset α →+ Multiset β where toFun := map f map_zero' := map_zero _ map_add' := map_add _ #align multiset.map_add_monoid_hom Multiset.mapAddMonoidHom @[simp] theorem coe_mapAddMonoidHom (f : α → β) : (mapAddMonoidHom f : Multiset α → Multiset β) = map f := rfl #align multiset.coe_map_add_monoid_hom Multiset.coe_mapAddMonoidHom theorem map_nsmul (f : α → β) (n : ℕ) (s) : map f (n • s) = n • map f s := (mapAddMonoidHom f).map_nsmul _ _ #align multiset.map_nsmul Multiset.map_nsmul @[simp] theorem mem_map {f : α → β} {b : β} {s : Multiset α} : b ∈ map f s ↔ ∃ a, a ∈ s ∧ f a = b := Quot.inductionOn s fun _l => List.mem_map #align multiset.mem_map Multiset.mem_map @[simp] theorem card_map (f : α → β) (s) : card (map f s) = card s := Quot.inductionOn s fun _l => length_map _ _ #align multiset.card_map Multiset.card_map @[simp] theorem map_eq_zero {s : Multiset α} {f : α → β} : s.map f = 0 ↔ s = 0 := by rw [← Multiset.card_eq_zero, Multiset.card_map, Multiset.card_eq_zero] #align multiset.map_eq_zero Multiset.map_eq_zero theorem mem_map_of_mem (f : α → β) {a : α} {s : Multiset α} (h : a ∈ s) : f a ∈ map f s := mem_map.2 ⟨_, h, rfl⟩ #align multiset.mem_map_of_mem Multiset.mem_map_of_mem theorem map_eq_singleton {f : α → β} {s : Multiset α} {b : β} : map f s = {b} ↔ ∃ a : α, s = {a} ∧ f a = b := by constructor · intro h obtain ⟨a, ha⟩ : ∃ a, s = {a} := by rw [← card_eq_one, ← card_map, h, card_singleton] refine ⟨a, ha, ?_⟩ rw [← mem_singleton, ← h, ha, map_singleton, mem_singleton] · rintro ⟨a, rfl, rfl⟩ simp #align multiset.map_eq_singleton Multiset.map_eq_singleton theorem map_eq_cons [DecidableEq α] (f : α → β) (s : Multiset α) (t : Multiset β) (b : β) : (∃ a ∈ s, f a = b ∧ (s.erase a).map f = t) ↔ s.map f = b ::ₘ t := by constructor · rintro ⟨a, ha, rfl, rfl⟩ rw [← map_cons, Multiset.cons_erase ha] · intro h have : b ∈ s.map f := by rw [h] exact mem_cons_self _ _ obtain ⟨a, h1, rfl⟩ := mem_map.mp this obtain ⟨u, rfl⟩ := exists_cons_of_mem h1 rw [map_cons, cons_inj_right] at h refine ⟨a, mem_cons_self _ _, rfl, ?_⟩ rw [Multiset.erase_cons_head, h] #align multiset.map_eq_cons Multiset.map_eq_cons -- The simpNF linter says that the LHS can be simplified via `Multiset.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Function.Injective f) {a : α} {s : Multiset α} : f a ∈ map f s ↔ a ∈ s := Quot.inductionOn s fun _l => List.mem_map_of_injective H #align multiset.mem_map_of_injective Multiset.mem_map_of_injective @[simp] theorem map_map (g : β → γ) (f : α → β) (s : Multiset α) : map g (map f s) = map (g ∘ f) s := Quot.inductionOn s fun _l => congr_arg _ <| List.map_map _ _ _ #align multiset.map_map Multiset.map_map theorem map_id (s : Multiset α) : map id s = s := Quot.inductionOn s fun _l => congr_arg _ <| List.map_id _ #align multiset.map_id Multiset.map_id @[simp] theorem map_id' (s : Multiset α) : map (fun x => x) s = s := map_id s #align multiset.map_id' Multiset.map_id' -- Porting note: was a `simp` lemma in mathlib3 theorem map_const (s : Multiset α) (b : β) : map (const α b) s = replicate (card s) b := Quot.inductionOn s fun _ => congr_arg _ <| List.map_const' _ _ #align multiset.map_const Multiset.map_const -- Porting note: was not a `simp` lemma in mathlib3 because `Function.const` was reducible @[simp] theorem map_const' (s : Multiset α) (b : β) : map (fun _ ↦ b) s = replicate (card s) b := map_const _ _ #align multiset.map_const' Multiset.map_const' theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (Function.const α b₂) l) : b₁ = b₂ := eq_of_mem_replicate <| by rwa [map_const] at h #align multiset.eq_of_mem_map_const Multiset.eq_of_mem_map_const @[simp] theorem map_le_map {f : α → β} {s t : Multiset α} (h : s ≤ t) : map f s ≤ map f t := leInductionOn h fun h => (h.map f).subperm #align multiset.map_le_map Multiset.map_le_map @[simp] theorem map_lt_map {f : α → β} {s t : Multiset α} (h : s < t) : s.map f < t.map f := by refine (map_le_map h.le).lt_of_not_le fun H => h.ne <| eq_of_le_of_card_le h.le ?_ rw [← s.card_map f, ← t.card_map f] exact card_le_card H #align multiset.map_lt_map Multiset.map_lt_map theorem map_mono (f : α → β) : Monotone (map f) := fun _ _ => map_le_map #align multiset.map_mono Multiset.map_mono theorem map_strictMono (f : α → β) : StrictMono (map f) := fun _ _ => map_lt_map #align multiset.map_strict_mono Multiset.map_strictMono @[simp] theorem map_subset_map {f : α → β} {s t : Multiset α} (H : s ⊆ t) : map f s ⊆ map f t := fun _b m => let ⟨a, h, e⟩ := mem_map.1 m mem_map.2 ⟨a, H h, e⟩ #align multiset.map_subset_map Multiset.map_subset_map theorem map_erase [DecidableEq α] [DecidableEq β] (f : α → β) (hf : Function.Injective f) (x : α) (s : Multiset α) : (s.erase x).map f = (s.map f).erase (f x) := by induction' s using Multiset.induction_on with y s ih · simp by_cases hxy : y = x · cases hxy simp · rw [s.erase_cons_tail hxy, map_cons, map_cons, (s.map f).erase_cons_tail (hf.ne hxy), ih] #align multiset.map_erase Multiset.map_erase theorem map_erase_of_mem [DecidableEq α] [DecidableEq β] (f : α → β) (s : Multiset α) {x : α} (h : x ∈ s) : (s.erase x).map f = (s.map f).erase (f x) := by induction' s using Multiset.induction_on with y s ih · simp rcases eq_or_ne y x with rfl | hxy · simp replace h : x ∈ s := by simpa [hxy.symm] using h rw [s.erase_cons_tail hxy, map_cons, map_cons, ih h, erase_cons_tail_of_mem (mem_map_of_mem f h)] theorem map_surjective_of_surjective {f : α → β} (hf : Function.Surjective f) : Function.Surjective (map f) := by intro s induction' s using Multiset.induction_on with x s ih · exact ⟨0, map_zero _⟩ · obtain ⟨y, rfl⟩ := hf x obtain ⟨t, rfl⟩ := ih exact ⟨y ::ₘ t, map_cons _ _ _⟩ #align multiset.map_surjective_of_surjective Multiset.map_surjective_of_surjective /-! ### `Multiset.fold` -/ /-- `foldl f H b s` is the lift of the list operation `foldl f b l`, which folds `f` over the multiset. It is well defined when `f` is right-commutative, that is, `f (f b a₁) a₂ = f (f b a₂) a₁`. -/ def foldl (f : β → α → β) (H : RightCommutative f) (b : β) (s : Multiset α) : β := Quot.liftOn s (fun l => List.foldl f b l) fun _l₁ _l₂ p => p.foldl_eq H b #align multiset.foldl Multiset.foldl @[simp] theorem foldl_zero (f : β → α → β) (H b) : foldl f H b 0 = b := rfl #align multiset.foldl_zero Multiset.foldl_zero @[simp] theorem foldl_cons (f : β → α → β) (H b a s) : foldl f H b (a ::ₘ s) = foldl f H (f b a) s := Quot.inductionOn s fun _l => rfl #align multiset.foldl_cons Multiset.foldl_cons @[simp] theorem foldl_add (f : β → α → β) (H b s t) : foldl f H b (s + t) = foldl f H (foldl f H b s) t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => foldl_append _ _ _ _ #align multiset.foldl_add Multiset.foldl_add /-- `foldr f H b s` is the lift of the list operation `foldr f b l`, which folds `f` over the multiset. It is well defined when `f` is left-commutative, that is, `f a₁ (f a₂ b) = f a₂ (f a₁ b)`. -/ def foldr (f : α → β → β) (H : LeftCommutative f) (b : β) (s : Multiset α) : β := Quot.liftOn s (fun l => List.foldr f b l) fun _l₁ _l₂ p => p.foldr_eq H b #align multiset.foldr Multiset.foldr @[simp] theorem foldr_zero (f : α → β → β) (H b) : foldr f H b 0 = b := rfl #align multiset.foldr_zero Multiset.foldr_zero @[simp] theorem foldr_cons (f : α → β → β) (H b a s) : foldr f H b (a ::ₘ s) = f a (foldr f H b s) := Quot.inductionOn s fun _l => rfl #align multiset.foldr_cons Multiset.foldr_cons @[simp] theorem foldr_singleton (f : α → β → β) (H b a) : foldr f H b ({a} : Multiset α) = f a b := rfl #align multiset.foldr_singleton Multiset.foldr_singleton @[simp] theorem foldr_add (f : α → β → β) (H b s t) : foldr f H b (s + t) = foldr f H (foldr f H b t) s := Quotient.inductionOn₂ s t fun _l₁ _l₂ => foldr_append _ _ _ _ #align multiset.foldr_add Multiset.foldr_add @[simp] theorem coe_foldr (f : α → β → β) (H : LeftCommutative f) (b : β) (l : List α) : foldr f H b l = l.foldr f b := rfl #align multiset.coe_foldr Multiset.coe_foldr @[simp] theorem coe_foldl (f : β → α → β) (H : RightCommutative f) (b : β) (l : List α) : foldl f H b l = l.foldl f b := rfl #align multiset.coe_foldl Multiset.coe_foldl theorem coe_foldr_swap (f : α → β → β) (H : LeftCommutative f) (b : β) (l : List α) : foldr f H b l = l.foldl (fun x y => f y x) b := (congr_arg (foldr f H b) (coe_reverse l)).symm.trans <| foldr_reverse _ _ _ #align multiset.coe_foldr_swap Multiset.coe_foldr_swap theorem foldr_swap (f : α → β → β) (H : LeftCommutative f) (b : β) (s : Multiset α) : foldr f H b s = foldl (fun x y => f y x) (fun _x _y _z => (H _ _ _).symm) b s := Quot.inductionOn s fun _l => coe_foldr_swap _ _ _ _ #align multiset.foldr_swap Multiset.foldr_swap theorem foldl_swap (f : β → α → β) (H : RightCommutative f) (b : β) (s : Multiset α) : foldl f H b s = foldr (fun x y => f y x) (fun _x _y _z => (H _ _ _).symm) b s := (foldr_swap _ _ _ _).symm #align multiset.foldl_swap Multiset.foldl_swap theorem foldr_induction' (f : α → β → β) (H : LeftCommutative f) (x : β) (q : α → Prop) (p : β → Prop) (s : Multiset α) (hpqf : ∀ a b, q a → p b → p (f a b)) (px : p x) (q_s : ∀ a ∈ s, q a) : p (foldr f H x s) := by induction s using Multiset.induction with | empty => simpa | cons a s ihs => simp only [forall_mem_cons, foldr_cons] at q_s ⊢ exact hpqf _ _ q_s.1 (ihs q_s.2) #align multiset.foldr_induction' Multiset.foldr_induction' theorem foldr_induction (f : α → α → α) (H : LeftCommutative f) (x : α) (p : α → Prop) (s : Multiset α) (p_f : ∀ a b, p a → p b → p (f a b)) (px : p x) (p_s : ∀ a ∈ s, p a) : p (foldr f H x s) := foldr_induction' f H x p p s p_f px p_s #align multiset.foldr_induction Multiset.foldr_induction theorem foldl_induction' (f : β → α → β) (H : RightCommutative f) (x : β) (q : α → Prop) (p : β → Prop) (s : Multiset α) (hpqf : ∀ a b, q a → p b → p (f b a)) (px : p x) (q_s : ∀ a ∈ s, q a) : p (foldl f H x s) := by rw [foldl_swap] exact foldr_induction' (fun x y => f y x) (fun x y z => (H _ _ _).symm) x q p s hpqf px q_s #align multiset.foldl_induction' Multiset.foldl_induction' theorem foldl_induction (f : α → α → α) (H : RightCommutative f) (x : α) (p : α → Prop) (s : Multiset α) (p_f : ∀ a b, p a → p b → p (f b a)) (px : p x) (p_s : ∀ a ∈ s, p a) : p (foldl f H x s) := foldl_induction' f H x p p s p_f px p_s #align multiset.foldl_induction Multiset.foldl_induction /-! ### Map for partial functions -/ /-- Lift of the list `pmap` operation. Map a partial function `f` over a multiset `s` whose elements are all in the domain of `f`. -/ nonrec def pmap {p : α → Prop} (f : ∀ a, p a → β) (s : Multiset α) : (∀ a ∈ s, p a) → Multiset β := Quot.recOn' s (fun l H => ↑(pmap f l H)) fun l₁ l₂ (pp : l₁ ~ l₂) => funext fun H₂ : ∀ a ∈ l₂, p a => have H₁ : ∀ a ∈ l₁, p a := fun a h => H₂ a (pp.subset h) have : ∀ {s₂ e H}, @Eq.ndrec (Multiset α) l₁ (fun s => (∀ a ∈ s, p a) → Multiset β) (fun _ => ↑(pmap f l₁ H₁)) s₂ e H = ↑(pmap f l₁ H₁) := by intro s₂ e _; subst e; rfl this.trans <| Quot.sound <| pp.pmap f #align multiset.pmap Multiset.pmap @[simp] theorem coe_pmap {p : α → Prop} (f : ∀ a, p a → β) (l : List α) (H : ∀ a ∈ l, p a) : pmap f l H = l.pmap f H := rfl #align multiset.coe_pmap Multiset.coe_pmap @[simp] theorem pmap_zero {p : α → Prop} (f : ∀ a, p a → β) (h : ∀ a ∈ (0 : Multiset α), p a) : pmap f 0 h = 0 := rfl #align multiset.pmap_zero Multiset.pmap_zero @[simp] theorem pmap_cons {p : α → Prop} (f : ∀ a, p a → β) (a : α) (m : Multiset α) : ∀ h : ∀ b ∈ a ::ₘ m, p b, pmap f (a ::ₘ m) h = f a (h a (mem_cons_self a m)) ::ₘ pmap f m fun a ha => h a <| mem_cons_of_mem ha := Quotient.inductionOn m fun _l _h => rfl #align multiset.pmap_cons Multiset.pmap_cons /-- "Attach" a proof that `a ∈ s` to each element `a` in `s` to produce a multiset on `{x // x ∈ s}`. -/ def attach (s : Multiset α) : Multiset { x // x ∈ s } := pmap Subtype.mk s fun _a => id #align multiset.attach Multiset.attach @[simp] theorem coe_attach (l : List α) : @Eq (Multiset { x // x ∈ l }) (@attach α l) l.attach := rfl #align multiset.coe_attach Multiset.coe_attach theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Multiset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by induction' s using Quot.inductionOn with l a b exact List.sizeOf_lt_sizeOf_of_mem hx #align multiset.sizeof_lt_sizeof_of_mem Multiset.sizeOf_lt_sizeOf_of_mem theorem pmap_eq_map (p : α → Prop) (f : α → β) (s : Multiset α) : ∀ H, @pmap _ _ p (fun a _ => f a) s H = map f s := Quot.inductionOn s fun l H => congr_arg _ <| List.pmap_eq_map p f l H #align multiset.pmap_eq_map Multiset.pmap_eq_map theorem pmap_congr {p q : α → Prop} {f : ∀ a, p a → β} {g : ∀ a, q a → β} (s : Multiset α) : ∀ {H₁ H₂}, (∀ a ∈ s, ∀ (h₁ h₂), f a h₁ = g a h₂) → pmap f s H₁ = pmap g s H₂ := @(Quot.inductionOn s (fun l _H₁ _H₂ h => congr_arg _ <| List.pmap_congr l h)) #align multiset.pmap_congr Multiset.pmap_congr theorem map_pmap {p : α → Prop} (g : β → γ) (f : ∀ a, p a → β) (s) : ∀ H, map g (pmap f s H) = pmap (fun a h => g (f a h)) s H := Quot.inductionOn s fun l H => congr_arg _ <| List.map_pmap g f l H #align multiset.map_pmap Multiset.map_pmap theorem pmap_eq_map_attach {p : α → Prop} (f : ∀ a, p a → β) (s) : ∀ H, pmap f s H = s.attach.map fun x => f x.1 (H _ x.2) := Quot.inductionOn s fun l H => congr_arg _ <| List.pmap_eq_map_attach f l H #align multiset.pmap_eq_map_attach Multiset.pmap_eq_map_attach -- @[simp] -- Porting note: Left hand does not simplify theorem attach_map_val' (s : Multiset α) (f : α → β) : (s.attach.map fun i => f i.val) = s.map f := Quot.inductionOn s fun l => congr_arg _ <| List.attach_map_coe' l f #align multiset.attach_map_coe' Multiset.attach_map_val' #align multiset.attach_map_val' Multiset.attach_map_val' @[simp] theorem attach_map_val (s : Multiset α) : s.attach.map Subtype.val = s := (attach_map_val' _ _).trans s.map_id #align multiset.attach_map_coe Multiset.attach_map_val #align multiset.attach_map_val Multiset.attach_map_val @[simp] theorem mem_attach (s : Multiset α) : ∀ x, x ∈ s.attach := Quot.inductionOn s fun _l => List.mem_attach _ #align multiset.mem_attach Multiset.mem_attach @[simp] theorem mem_pmap {p : α → Prop} {f : ∀ a, p a → β} {s H b} : b ∈ pmap f s H ↔ ∃ (a : _) (h : a ∈ s), f a (H a h) = b := Quot.inductionOn s (fun _l _H => List.mem_pmap) H #align multiset.mem_pmap Multiset.mem_pmap @[simp] theorem card_pmap {p : α → Prop} (f : ∀ a, p a → β) (s H) : card (pmap f s H) = card s := Quot.inductionOn s (fun _l _H => length_pmap) H #align multiset.card_pmap Multiset.card_pmap @[simp] theorem card_attach {m : Multiset α} : card (attach m) = card m := card_pmap _ _ _ #align multiset.card_attach Multiset.card_attach @[simp] theorem attach_zero : (0 : Multiset α).attach = 0 := rfl #align multiset.attach_zero Multiset.attach_zero theorem attach_cons (a : α) (m : Multiset α) : (a ::ₘ m).attach = ⟨a, mem_cons_self a m⟩ ::ₘ m.attach.map fun p => ⟨p.1, mem_cons_of_mem p.2⟩ := Quotient.inductionOn m fun l => congr_arg _ <| congr_arg (List.cons _) <| by rw [List.map_pmap]; exact List.pmap_congr _ fun _ _ _ _ => Subtype.eq rfl #align multiset.attach_cons Multiset.attach_cons section DecidablePiExists variable {m : Multiset α} /-- If `p` is a decidable predicate, so is the predicate that all elements of a multiset satisfy `p`. -/ protected def decidableForallMultiset {p : α → Prop} [hp : ∀ a, Decidable (p a)] : Decidable (∀ a ∈ m, p a) := Quotient.recOnSubsingleton m fun l => decidable_of_iff (∀ a ∈ l, p a) <| by simp #align multiset.decidable_forall_multiset Multiset.decidableForallMultiset instance decidableDforallMultiset {p : ∀ a ∈ m, Prop} [_hp : ∀ (a) (h : a ∈ m), Decidable (p a h)] : Decidable (∀ (a) (h : a ∈ m), p a h) := @decidable_of_iff _ _ (Iff.intro (fun h a ha => h ⟨a, ha⟩ (mem_attach _ _)) fun h ⟨_a, _ha⟩ _ => h _ _) (@Multiset.decidableForallMultiset _ m.attach (fun a => p a.1 a.2) _) #align multiset.decidable_dforall_multiset Multiset.decidableDforallMultiset /-- decidable equality for functions whose domain is bounded by multisets -/ instance decidableEqPiMultiset {β : α → Type*} [h : ∀ a, DecidableEq (β a)] : DecidableEq (∀ a ∈ m, β a) := fun f g => decidable_of_iff (∀ (a) (h : a ∈ m), f a h = g a h) (by simp [Function.funext_iff]) #align multiset.decidable_eq_pi_multiset Multiset.decidableEqPiMultiset /-- If `p` is a decidable predicate, so is the existence of an element in a multiset satisfying `p`. -/ protected def decidableExistsMultiset {p : α → Prop} [DecidablePred p] : Decidable (∃ x ∈ m, p x) := Quotient.recOnSubsingleton m fun l => decidable_of_iff (∃ a ∈ l, p a) <| by simp #align multiset.decidable_exists_multiset Multiset.decidableExistsMultiset instance decidableDexistsMultiset {p : ∀ a ∈ m, Prop} [_hp : ∀ (a) (h : a ∈ m), Decidable (p a h)] : Decidable (∃ (a : _) (h : a ∈ m), p a h) := @decidable_of_iff _ _ (Iff.intro (fun ⟨⟨a, ha₁⟩, _, ha₂⟩ => ⟨a, ha₁, ha₂⟩) fun ⟨a, ha₁, ha₂⟩ => ⟨⟨a, ha₁⟩, mem_attach _ _, ha₂⟩) (@Multiset.decidableExistsMultiset { a // a ∈ m } m.attach (fun a => p a.1 a.2) _) #align multiset.decidable_dexists_multiset Multiset.decidableDexistsMultiset end DecidablePiExists /-! ### Subtraction -/ section variable [DecidableEq α] {s t u : Multiset α} {a b : α} /-- `s - t` is the multiset such that `count a (s - t) = count a s - count a t` for all `a` (note that it is truncated subtraction, so it is `0` if `count a t ≥ count a s`). -/ protected def sub (s t : Multiset α) : Multiset α := (Quotient.liftOn₂ s t fun l₁ l₂ => (l₁.diff l₂ : Multiset α)) fun _v₁ _v₂ _w₁ _w₂ p₁ p₂ => Quot.sound <| p₁.diff p₂ #align multiset.sub Multiset.sub instance : Sub (Multiset α) := ⟨Multiset.sub⟩ @[simp] theorem coe_sub (s t : List α) : (s - t : Multiset α) = (s.diff t : List α) := rfl #align multiset.coe_sub Multiset.coe_sub /-- This is a special case of `tsub_zero`, which should be used instead of this. This is needed to prove `OrderedSub (Multiset α)`. -/ protected theorem sub_zero (s : Multiset α) : s - 0 = s := Quot.inductionOn s fun _l => rfl #align multiset.sub_zero Multiset.sub_zero @[simp] theorem sub_cons (a : α) (s t : Multiset α) : s - a ::ₘ t = s.erase a - t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => congr_arg _ <| diff_cons _ _ _ #align multiset.sub_cons Multiset.sub_cons /-- This is a special case of `tsub_le_iff_right`, which should be used instead of this. This is needed to prove `OrderedSub (Multiset α)`. -/ protected theorem sub_le_iff_le_add : s - t ≤ u ↔ s ≤ u + t := by revert s exact @(Multiset.induction_on t (by simp [Multiset.sub_zero]) fun a t IH s => by simp [IH, erase_le_iff_le_cons]) #align multiset.sub_le_iff_le_add Multiset.sub_le_iff_le_add instance : OrderedSub (Multiset α) := ⟨fun _n _m _k => Multiset.sub_le_iff_le_add⟩ theorem cons_sub_of_le (a : α) {s t : Multiset α} (h : t ≤ s) : a ::ₘ s - t = a ::ₘ (s - t) := by rw [← singleton_add, ← singleton_add, add_tsub_assoc_of_le h] #align multiset.cons_sub_of_le Multiset.cons_sub_of_le theorem sub_eq_fold_erase (s t : Multiset α) : s - t = foldl erase erase_comm s t := Quotient.inductionOn₂ s t fun l₁ l₂ => by show ofList (l₁.diff l₂) = foldl erase erase_comm l₁ l₂ rw [diff_eq_foldl l₁ l₂] symm exact foldl_hom _ _ _ _ _ fun x y => rfl #align multiset.sub_eq_fold_erase Multiset.sub_eq_fold_erase @[simp] theorem card_sub {s t : Multiset α} (h : t ≤ s) : card (s - t) = card s - card t := Nat.eq_sub_of_add_eq $ by rw [← card_add, tsub_add_cancel_of_le h] #align multiset.card_sub Multiset.card_sub /-! ### Union -/ /-- `s ∪ t` is the lattice join operation with respect to the multiset `≤`. The multiplicity of `a` in `s ∪ t` is the maximum of the multiplicities in `s` and `t`. -/ def union (s t : Multiset α) : Multiset α := s - t + t #align multiset.union Multiset.union instance : Union (Multiset α) := ⟨union⟩ theorem union_def (s t : Multiset α) : s ∪ t = s - t + t := rfl #align multiset.union_def Multiset.union_def theorem le_union_left (s t : Multiset α) : s ≤ s ∪ t := le_tsub_add #align multiset.le_union_left Multiset.le_union_left theorem le_union_right (s t : Multiset α) : t ≤ s ∪ t := le_add_left _ _ #align multiset.le_union_right Multiset.le_union_right theorem eq_union_left : t ≤ s → s ∪ t = s := tsub_add_cancel_of_le #align multiset.eq_union_left Multiset.eq_union_left theorem union_le_union_right (h : s ≤ t) (u) : s ∪ u ≤ t ∪ u := add_le_add_right (tsub_le_tsub_right h _) u #align multiset.union_le_union_right Multiset.union_le_union_right theorem union_le (h₁ : s ≤ u) (h₂ : t ≤ u) : s ∪ t ≤ u := by rw [← eq_union_left h₂]; exact union_le_union_right h₁ t #align multiset.union_le Multiset.union_le @[simp] theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t := ⟨fun h => (mem_add.1 h).imp_left (mem_of_le tsub_le_self), (Or.elim · (mem_of_le <| le_union_left _ _) (mem_of_le <| le_union_right _ _))⟩ #align multiset.mem_union Multiset.mem_union @[simp] theorem map_union [DecidableEq β] {f : α → β} (finj : Function.Injective f) {s t : Multiset α} : map f (s ∪ t) = map f s ∪ map f t := Quotient.inductionOn₂ s t fun l₁ l₂ => congr_arg ofList (by rw [List.map_append f, List.map_diff finj]) #align multiset.map_union Multiset.map_union -- Porting note (#10756): new theorem @[simp] theorem zero_union : 0 ∪ s = s := by simp [union_def] -- Porting note (#10756): new theorem @[simp] theorem union_zero : s ∪ 0 = s := by simp [union_def] /-! ### Intersection -/ /-- `s ∩ t` is the lattice meet operation with respect to the multiset `≤`. The multiplicity of `a` in `s ∩ t` is the minimum of the multiplicities in `s` and `t`. -/ def inter (s t : Multiset α) : Multiset α := Quotient.liftOn₂ s t (fun l₁ l₂ => (l₁.bagInter l₂ : Multiset α)) fun _v₁ _v₂ _w₁ _w₂ p₁ p₂ => Quot.sound <| p₁.bagInter p₂ #align multiset.inter Multiset.inter instance : Inter (Multiset α) := ⟨inter⟩ @[simp] theorem inter_zero (s : Multiset α) : s ∩ 0 = 0 := Quot.inductionOn s fun l => congr_arg ofList l.bagInter_nil #align multiset.inter_zero Multiset.inter_zero @[simp] theorem zero_inter (s : Multiset α) : 0 ∩ s = 0 := Quot.inductionOn s fun l => congr_arg ofList l.nil_bagInter #align multiset.zero_inter Multiset.zero_inter @[simp] theorem cons_inter_of_pos {a} (s : Multiset α) {t} : a ∈ t → (a ::ₘ s) ∩ t = a ::ₘ s ∩ t.erase a := Quotient.inductionOn₂ s t fun _l₁ _l₂ h => congr_arg ofList <| cons_bagInter_of_pos _ h #align multiset.cons_inter_of_pos Multiset.cons_inter_of_pos @[simp] theorem cons_inter_of_neg {a} (s : Multiset α) {t} : a ∉ t → (a ::ₘ s) ∩ t = s ∩ t := Quotient.inductionOn₂ s t fun _l₁ _l₂ h => congr_arg ofList <| cons_bagInter_of_neg _ h #align multiset.cons_inter_of_neg Multiset.cons_inter_of_neg theorem inter_le_left (s t : Multiset α) : s ∩ t ≤ s := Quotient.inductionOn₂ s t fun _l₁ _l₂ => (bagInter_sublist_left _ _).subperm #align multiset.inter_le_left Multiset.inter_le_left theorem inter_le_right (s : Multiset α) : ∀ t, s ∩ t ≤ t := Multiset.induction_on s (fun t => (zero_inter t).symm ▸ zero_le _) fun a s IH t => if h : a ∈ t then by simpa [h] using cons_le_cons a (IH (t.erase a)) else by simp [h, IH] #align multiset.inter_le_right Multiset.inter_le_right theorem le_inter (h₁ : s ≤ t) (h₂ : s ≤ u) : s ≤ t ∩ u := by revert s u; refine @(Multiset.induction_on t ?_ fun a t IH => ?_) <;> intros s u h₁ h₂ · simpa only [zero_inter, nonpos_iff_eq_zero] using h₁ by_cases h : a ∈ u · rw [cons_inter_of_pos _ h, ← erase_le_iff_le_cons] exact IH (erase_le_iff_le_cons.2 h₁) (erase_le_erase _ h₂) · rw [cons_inter_of_neg _ h] exact IH ((le_cons_of_not_mem <| mt (mem_of_le h₂) h).1 h₁) h₂ #align multiset.le_inter Multiset.le_inter @[simp] theorem mem_inter : a ∈ s ∩ t ↔ a ∈ s ∧ a ∈ t := ⟨fun h => ⟨mem_of_le (inter_le_left _ _) h, mem_of_le (inter_le_right _ _) h⟩, fun ⟨h₁, h₂⟩ => by rw [← cons_erase h₁, cons_inter_of_pos _ h₂]; apply mem_cons_self⟩ #align multiset.mem_inter Multiset.mem_inter instance : Lattice (Multiset α) := { sup := (· ∪ ·) sup_le := @union_le _ _ le_sup_left := le_union_left le_sup_right := le_union_right inf := (· ∩ ·) le_inf := @le_inter _ _ inf_le_left := inter_le_left inf_le_right := inter_le_right } @[simp] theorem sup_eq_union (s t : Multiset α) : s ⊔ t = s ∪ t := rfl #align multiset.sup_eq_union Multiset.sup_eq_union @[simp] theorem inf_eq_inter (s t : Multiset α) : s ⊓ t = s ∩ t := rfl #align multiset.inf_eq_inter Multiset.inf_eq_inter @[simp] theorem le_inter_iff : s ≤ t ∩ u ↔ s ≤ t ∧ s ≤ u := le_inf_iff #align multiset.le_inter_iff Multiset.le_inter_iff @[simp] theorem union_le_iff : s ∪ t ≤ u ↔ s ≤ u ∧ t ≤ u := sup_le_iff #align multiset.union_le_iff Multiset.union_le_iff theorem union_comm (s t : Multiset α) : s ∪ t = t ∪ s := sup_comm _ _ #align multiset.union_comm Multiset.union_comm theorem inter_comm (s t : Multiset α) : s ∩ t = t ∩ s := inf_comm _ _ #align multiset.inter_comm Multiset.inter_comm theorem eq_union_right (h : s ≤ t) : s ∪ t = t := by rw [union_comm, eq_union_left h] #align multiset.eq_union_right Multiset.eq_union_right theorem union_le_union_left (h : s ≤ t) (u) : u ∪ s ≤ u ∪ t := sup_le_sup_left h _ #align multiset.union_le_union_left Multiset.union_le_union_left theorem union_le_add (s t : Multiset α) : s ∪ t ≤ s + t := union_le (le_add_right _ _) (le_add_left _ _) #align multiset.union_le_add Multiset.union_le_add theorem union_add_distrib (s t u : Multiset α) : s ∪ t + u = s + u ∪ (t + u) := by simpa [(· ∪ ·), union, eq_comm, add_assoc] using show s + u - (t + u) = s - t by rw [add_comm t, tsub_add_eq_tsub_tsub, add_tsub_cancel_right] #align multiset.union_add_distrib Multiset.union_add_distrib theorem add_union_distrib (s t u : Multiset α) : s + (t ∪ u) = s + t ∪ (s + u) := by rw [add_comm, union_add_distrib, add_comm s, add_comm s] #align multiset.add_union_distrib Multiset.add_union_distrib theorem cons_union_distrib (a : α) (s t : Multiset α) : a ::ₘ (s ∪ t) = a ::ₘ s ∪ a ::ₘ t := by simpa using add_union_distrib (a ::ₘ 0) s t #align multiset.cons_union_distrib Multiset.cons_union_distrib theorem inter_add_distrib (s t u : Multiset α) : s ∩ t + u = (s + u) ∩ (t + u) := by by_contra h cases' lt_iff_cons_le.1 (lt_of_le_of_ne (le_inter (add_le_add_right (inter_le_left s t) u) (add_le_add_right (inter_le_right s t) u)) h) with a hl rw [← cons_add] at hl exact not_le_of_lt (lt_cons_self (s ∩ t) a) (le_inter (le_of_add_le_add_right (le_trans hl (inter_le_left _ _))) (le_of_add_le_add_right (le_trans hl (inter_le_right _ _)))) #align multiset.inter_add_distrib Multiset.inter_add_distrib theorem add_inter_distrib (s t u : Multiset α) : s + t ∩ u = (s + t) ∩ (s + u) := by rw [add_comm, inter_add_distrib, add_comm s, add_comm s] #align multiset.add_inter_distrib Multiset.add_inter_distrib theorem cons_inter_distrib (a : α) (s t : Multiset α) : a ::ₘ s ∩ t = (a ::ₘ s) ∩ (a ::ₘ t) := by simp #align multiset.cons_inter_distrib Multiset.cons_inter_distrib theorem union_add_inter (s t : Multiset α) : s ∪ t + s ∩ t = s + t := by apply _root_.le_antisymm · rw [union_add_distrib] refine union_le (add_le_add_left (inter_le_right _ _) _) ?_ rw [add_comm] exact add_le_add_right (inter_le_left _ _) _ · rw [add_comm, add_inter_distrib] refine le_inter (add_le_add_right (le_union_right _ _) _) ?_ rw [add_comm] exact add_le_add_right (le_union_left _ _) _ #align multiset.union_add_inter Multiset.union_add_inter theorem sub_add_inter (s t : Multiset α) : s - t + s ∩ t = s := by rw [inter_comm] revert s; refine Multiset.induction_on t (by simp) fun a t IH s => ?_ by_cases h : a ∈ s · rw [cons_inter_of_pos _ h, sub_cons, add_cons, IH, cons_erase h] · rw [cons_inter_of_neg _ h, sub_cons, erase_of_not_mem h, IH] #align multiset.sub_add_inter Multiset.sub_add_inter theorem sub_inter (s t : Multiset α) : s - s ∩ t = s - t := add_right_cancel <| by rw [sub_add_inter s t, tsub_add_cancel_of_le (inter_le_left s t)] #align multiset.sub_inter Multiset.sub_inter end /-! ### `Multiset.filter` -/ section variable (p : α → Prop) [DecidablePred p] /-- `Filter p s` returns the elements in `s` (with the same multiplicities) which satisfy `p`, and removes the rest. -/ def filter (s : Multiset α) : Multiset α := Quot.liftOn s (fun l => (List.filter p l : Multiset α)) fun _l₁ _l₂ h => Quot.sound <| h.filter p #align multiset.filter Multiset.filter @[simp, norm_cast] lemma filter_coe (l : List α) : filter p l = l.filter p := rfl #align multiset.coe_filter Multiset.filter_coe @[simp] theorem filter_zero : filter p 0 = 0 := rfl #align multiset.filter_zero Multiset.filter_zero theorem filter_congr {p q : α → Prop} [DecidablePred p] [DecidablePred q] {s : Multiset α} : (∀ x ∈ s, p x ↔ q x) → filter p s = filter q s := Quot.inductionOn s fun _l h => congr_arg ofList <| filter_congr' <| by simpa using h #align multiset.filter_congr Multiset.filter_congr @[simp] theorem filter_add (s t : Multiset α) : filter p (s + t) = filter p s + filter p t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => congr_arg ofList <| filter_append _ _ #align multiset.filter_add Multiset.filter_add @[simp] theorem filter_le (s : Multiset α) : filter p s ≤ s := Quot.inductionOn s fun _l => (filter_sublist _).subperm #align multiset.filter_le Multiset.filter_le @[simp] theorem filter_subset (s : Multiset α) : filter p s ⊆ s := subset_of_le <| filter_le _ _ #align multiset.filter_subset Multiset.filter_subset theorem filter_le_filter {s t} (h : s ≤ t) : filter p s ≤ filter p t := leInductionOn h fun h => (h.filter (p ·)).subperm #align multiset.filter_le_filter Multiset.filter_le_filter theorem monotone_filter_left : Monotone (filter p) := fun _s _t => filter_le_filter p #align multiset.monotone_filter_left Multiset.monotone_filter_left theorem monotone_filter_right (s : Multiset α) ⦃p q : α → Prop⦄ [DecidablePred p] [DecidablePred q] (h : ∀ b, p b → q b) : s.filter p ≤ s.filter q := Quotient.inductionOn s fun l => (l.monotone_filter_right <| by simpa using h).subperm #align multiset.monotone_filter_right Multiset.monotone_filter_right variable {p} @[simp] theorem filter_cons_of_pos {a : α} (s) : p a → filter p (a ::ₘ s) = a ::ₘ filter p s := Quot.inductionOn s fun l h => congr_arg ofList <| List.filter_cons_of_pos l <| by simpa using h #align multiset.filter_cons_of_pos Multiset.filter_cons_of_pos @[simp] theorem filter_cons_of_neg {a : α} (s) : ¬p a → filter p (a ::ₘ s) = filter p s := Quot.inductionOn s fun l h => congr_arg ofList <| List.filter_cons_of_neg l <| by simpa using h #align multiset.filter_cons_of_neg Multiset.filter_cons_of_neg @[simp] theorem mem_filter {a : α} {s} : a ∈ filter p s ↔ a ∈ s ∧ p a := Quot.inductionOn s fun _l => by simpa using List.mem_filter (p := (p ·)) #align multiset.mem_filter Multiset.mem_filter theorem of_mem_filter {a : α} {s} (h : a ∈ filter p s) : p a := (mem_filter.1 h).2 #align multiset.of_mem_filter Multiset.of_mem_filter theorem mem_of_mem_filter {a : α} {s} (h : a ∈ filter p s) : a ∈ s := (mem_filter.1 h).1 #align multiset.mem_of_mem_filter Multiset.mem_of_mem_filter theorem mem_filter_of_mem {a : α} {l} (m : a ∈ l) (h : p a) : a ∈ filter p l := mem_filter.2 ⟨m, h⟩ #align multiset.mem_filter_of_mem Multiset.mem_filter_of_mem theorem filter_eq_self {s} : filter p s = s ↔ ∀ a ∈ s, p a := Quot.inductionOn s fun _l => Iff.trans ⟨fun h => (filter_sublist _).eq_of_length (@congr_arg _ _ _ _ card h), congr_arg ofList⟩ <| by simp #align multiset.filter_eq_self Multiset.filter_eq_self theorem filter_eq_nil {s} : filter p s = 0 ↔ ∀ a ∈ s, ¬p a := Quot.inductionOn s fun _l => Iff.trans ⟨fun h => eq_nil_of_length_eq_zero (@congr_arg _ _ _ _ card h), congr_arg ofList⟩ <| by simpa using List.filter_eq_nil (p := (p ·)) #align multiset.filter_eq_nil Multiset.filter_eq_nil theorem le_filter {s t} : s ≤ filter p t ↔ s ≤ t ∧ ∀ a ∈ s, p a := ⟨fun h => ⟨le_trans h (filter_le _ _), fun _a m => of_mem_filter (mem_of_le h m)⟩, fun ⟨h, al⟩ => filter_eq_self.2 al ▸ filter_le_filter p h⟩ #align multiset.le_filter Multiset.le_filter theorem filter_cons {a : α} (s : Multiset α) : filter p (a ::ₘ s) = (if p a then {a} else 0) + filter p s := by split_ifs with h · rw [filter_cons_of_pos _ h, singleton_add] · rw [filter_cons_of_neg _ h, zero_add] #align multiset.filter_cons Multiset.filter_cons theorem filter_singleton {a : α} (p : α → Prop) [DecidablePred p] : filter p {a} = if p a then {a} else ∅ := by simp only [singleton, filter_cons, filter_zero, add_zero, empty_eq_zero] #align multiset.filter_singleton Multiset.filter_singleton theorem filter_nsmul (s : Multiset α) (n : ℕ) : filter p (n • s) = n • filter p s := by refine s.induction_on ?_ ?_ · simp only [filter_zero, nsmul_zero] · intro a ha ih rw [nsmul_cons, filter_add, ih, filter_cons, nsmul_add] congr split_ifs with hp <;> · simp only [filter_eq_self, nsmul_zero, filter_eq_nil] intro b hb rwa [mem_singleton.mp (mem_of_mem_nsmul hb)] #align multiset.filter_nsmul Multiset.filter_nsmul variable (p) @[simp] theorem filter_sub [DecidableEq α] (s t : Multiset α) : filter p (s - t) = filter p s - filter p t := by revert s; refine Multiset.induction_on t (by simp) fun a t IH s => ?_ rw [sub_cons, IH] by_cases h : p a · rw [filter_cons_of_pos _ h, sub_cons] congr by_cases m : a ∈ s · rw [← cons_inj_right a, ← filter_cons_of_pos _ h, cons_erase (mem_filter_of_mem m h), cons_erase m] · rw [erase_of_not_mem m, erase_of_not_mem (mt mem_of_mem_filter m)] · rw [filter_cons_of_neg _ h] by_cases m : a ∈ s · rw [(by rw [filter_cons_of_neg _ h] : filter p (erase s a) = filter p (a ::ₘ erase s a)), cons_erase m] · rw [erase_of_not_mem m] #align multiset.filter_sub Multiset.filter_sub @[simp] theorem filter_union [DecidableEq α] (s t : Multiset α) : filter p (s ∪ t) = filter p s ∪ filter p t := by simp [(· ∪ ·), union] #align multiset.filter_union Multiset.filter_union @[simp] theorem filter_inter [DecidableEq α] (s t : Multiset α) : filter p (s ∩ t) = filter p s ∩ filter p t := le_antisymm (le_inter (filter_le_filter _ <| inter_le_left _ _) (filter_le_filter _ <| inter_le_right _ _)) <| le_filter.2 ⟨inf_le_inf (filter_le _ _) (filter_le _ _), fun _a h => of_mem_filter (mem_of_le (inter_le_left _ _) h)⟩ #align multiset.filter_inter Multiset.filter_inter @[simp] theorem filter_filter (q) [DecidablePred q] (s : Multiset α) : filter p (filter q s) = filter (fun a => p a ∧ q a) s := Quot.inductionOn s fun l => by simp #align multiset.filter_filter Multiset.filter_filter lemma filter_comm (q) [DecidablePred q] (s : Multiset α) : filter p (filter q s) = filter q (filter p s) := by simp [and_comm] #align multiset.filter_comm Multiset.filter_comm theorem filter_add_filter (q) [DecidablePred q] (s : Multiset α) : filter p s + filter q s = filter (fun a => p a ∨ q a) s + filter (fun a => p a ∧ q a) s := Multiset.induction_on s rfl fun a s IH => by by_cases p a <;> by_cases q a <;> simp [*] #align multiset.filter_add_filter Multiset.filter_add_filter
Mathlib/Data/Multiset/Basic.lean
2,138
2,143
theorem filter_add_not (s : Multiset α) : filter p s + filter (fun a => ¬p a) s = s := by
rw [filter_add_filter, filter_eq_self.2, filter_eq_nil.2] · simp only [add_zero] · simp [Decidable.em, -Bool.not_eq_true, -not_and, not_and_or, or_comm] · simp only [Bool.not_eq_true, decide_eq_true_eq, Bool.eq_false_or_eq_true, decide_True, implies_true, Decidable.em]
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Geometry.RingedSpace.OpenImmersion import Mathlib.AlgebraicGeometry.Scheme import Mathlib.CategoryTheory.Limits.Shapes.CommSq #align_import algebraic_geometry.open_immersion.Scheme from "leanprover-community/mathlib"@"533f62f4dd62a5aad24a04326e6e787c8f7e98b1" /-! # Open immersions of schemes -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 set_option linter.uppercaseLean3 false noncomputable section open TopologicalSpace CategoryTheory Opposite open CategoryTheory.Limits namespace AlgebraicGeometry universe v v₁ v₂ u variable {C : Type u} [Category.{v} C] /-- A morphism of Schemes is an open immersion if it is an open immersion as a morphism of LocallyRingedSpaces -/ abbrev IsOpenImmersion {X Y : Scheme.{u}} (f : X ⟶ Y) : Prop := LocallyRingedSpace.IsOpenImmersion f #align algebraic_geometry.IsOpenImmersion AlgebraicGeometry.IsOpenImmersion instance IsOpenImmersion.comp {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) [IsOpenImmersion f] [IsOpenImmersion g] : IsOpenImmersion (f ≫ g) := LocallyRingedSpace.IsOpenImmersion.comp f g namespace LocallyRingedSpace.IsOpenImmersion /-- To show that a locally ringed space is a scheme, it suffices to show that it has a jointly surjective family of open immersions from affine schemes. -/ protected def scheme (X : LocallyRingedSpace.{u}) (h : ∀ x : X, ∃ (R : CommRingCat) (f : Spec.toLocallyRingedSpace.obj (op R) ⟶ X), (x ∈ Set.range f.1.base : _) ∧ LocallyRingedSpace.IsOpenImmersion f) : Scheme where toLocallyRingedSpace := X local_affine := by intro x obtain ⟨R, f, h₁, h₂⟩ := h x refine ⟨⟨⟨_, h₂.base_open.isOpen_range⟩, h₁⟩, R, ⟨?_⟩⟩ apply LocallyRingedSpace.isoOfSheafedSpaceIso refine SheafedSpace.forgetToPresheafedSpace.preimageIso ?_ apply PresheafedSpace.IsOpenImmersion.isoOfRangeEq (PresheafedSpace.ofRestrict _ _) f.1 · exact Subtype.range_coe_subtype · exact Opens.openEmbedding _ -- Porting note (#11187): was `infer_instance` #align algebraic_geometry.LocallyRingedSpace.IsOpenImmersion.Scheme AlgebraicGeometry.LocallyRingedSpace.IsOpenImmersion.scheme end LocallyRingedSpace.IsOpenImmersion theorem IsOpenImmersion.isOpen_range {X Y : Scheme.{u}} (f : X ⟶ Y) [H : IsOpenImmersion f] : IsOpen (Set.range f.1.base) := H.base_open.isOpen_range #align algebraic_geometry.IsOpenImmersion.open_range AlgebraicGeometry.IsOpenImmersion.isOpen_range @[deprecated (since := "2024-03-17")] alias IsOpenImmersion.open_range := IsOpenImmersion.isOpen_range section OpenCover namespace Scheme -- TODO: provide API to and from a presieve. /-- An open cover of `X` consists of a family of open immersions into `X`, and for each `x : X` an open immersion (indexed by `f x`) that covers `x`. This is merely a coverage in the Zariski pretopology, and it would be optimal if we could reuse the existing API about pretopologies, However, the definitions of sieves and grothendieck topologies uses `Prop`s, so that the actual open sets and immersions are hard to obtain. Also, since such a coverage in the pretopology usually contains a proper class of immersions, it is quite hard to glue them, reason about finite covers, etc. -/ structure OpenCover (X : Scheme.{u}) where /-- index set of an open cover of a scheme `X` -/ J : Type v /-- the subschemes of an open cover -/ obj : J → Scheme /-- the embedding of subschemes to `X` -/ map : ∀ j : J, obj j ⟶ X /-- given a point of `x : X`, `f x` is the index of the subscheme which contains `x` -/ f : X.carrier → J /-- the subschemes covers `X` -/ Covers : ∀ x, x ∈ Set.range (map (f x)).1.base /-- the embedding of subschemes are open immersions -/ IsOpen : ∀ x, IsOpenImmersion (map x) := by infer_instance #align algebraic_geometry.Scheme.open_cover AlgebraicGeometry.Scheme.OpenCover attribute [instance] OpenCover.IsOpen variable {X Y Z : Scheme.{u}} (𝒰 : OpenCover X) (f : X ⟶ Z) (g : Y ⟶ Z) variable [∀ x, HasPullback (𝒰.map x ≫ f) g] /-- The affine cover of a scheme. -/ def affineCover (X : Scheme.{u}) : OpenCover X where J := X.carrier obj x := Spec.obj <| Opposite.op (X.local_affine x).choose_spec.choose map x := ((X.local_affine x).choose_spec.choose_spec.some.inv ≫ X.toLocallyRingedSpace.ofRestrict _ : _) f x := x IsOpen x := by apply (config := { allowSynthFailures := true }) PresheafedSpace.IsOpenImmersion.comp apply PresheafedSpace.IsOpenImmersion.ofRestrict Covers := by intro x erw [TopCat.coe_comp] -- now `erw` after #13170 rw [Set.range_comp, Set.range_iff_surjective.mpr, Set.image_univ] · erw [Subtype.range_coe_subtype] exact (X.local_affine x).choose.2 erw [← TopCat.epi_iff_surjective] -- now `erw` after #13170 change Epi ((SheafedSpace.forget _).map (LocallyRingedSpace.forgetToSheafedSpace.map _)) infer_instance #align algebraic_geometry.Scheme.affine_cover AlgebraicGeometry.Scheme.affineCover instance : Inhabited X.OpenCover := ⟨X.affineCover⟩ /-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these open covers to form an open cover of `X`. -/ @[simps! J obj map] def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where J := Σ i : 𝒰.J, (f i).J obj x := (f x.1).obj x.2 map x := (f x.1).map x.2 ≫ 𝒰.map x.1 f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩ Covers x := by let y := (𝒰.Covers x).choose have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.Covers x).choose_spec rcases (f (𝒰.f x)).Covers y with ⟨z, hz⟩ change x ∈ Set.range ((f (𝒰.f x)).map ((f (𝒰.f x)).f y) ≫ 𝒰.map (𝒰.f x)).1.base use z erw [comp_apply] erw [hz, hy] -- now `erw` after #13170 -- Porting note: weirdly, even though no input is needed, `inferInstance` does not work -- `PresheafedSpace.IsOpenImmersion.comp` is marked as `instance` IsOpen x := PresheafedSpace.IsOpenImmersion.comp _ _ #align algebraic_geometry.Scheme.open_cover.bind AlgebraicGeometry.Scheme.OpenCover.bind /-- An isomorphism `X ⟶ Y` is an open cover of `Y`. -/ @[simps J obj map] def openCoverOfIsIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : OpenCover Y where J := PUnit.{v + 1} obj _ := X map _ := f f _ := PUnit.unit Covers x := by rw [Set.range_iff_surjective.mpr] all_goals try trivial rw [← TopCat.epi_iff_surjective] infer_instance #align algebraic_geometry.Scheme.open_cover_of_is_iso AlgebraicGeometry.Scheme.openCoverOfIsIso /-- We construct an open cover from another, by providing the needed fields and showing that the provided fields are isomorphic with the original open cover. -/ @[simps J obj map] def OpenCover.copy {X : Scheme.{u}} (𝒰 : OpenCover X) (J : Type*) (obj : J → Scheme) (map : ∀ i, obj i ⟶ X) (e₁ : J ≃ 𝒰.J) (e₂ : ∀ i, obj i ≅ 𝒰.obj (e₁ i)) (e₂ : ∀ i, map i = (e₂ i).hom ≫ 𝒰.map (e₁ i)) : OpenCover X := { J, obj, map f := fun x => e₁.symm (𝒰.f x) Covers := fun x => by rw [e₂, Scheme.comp_val_base, TopCat.coe_comp, Set.range_comp, Set.range_iff_surjective.mpr, Set.image_univ, e₁.rightInverse_symm] · exact 𝒰.Covers x · erw [← TopCat.epi_iff_surjective]; infer_instance -- now `erw` after #13170 -- Porting note: weirdly, even though no input is needed, `inferInstance` does not work -- `PresheafedSpace.IsOpenImmersion.comp` is marked as `instance` IsOpen := fun i => by rw [e₂]; exact PresheafedSpace.IsOpenImmersion.comp _ _ } #align algebraic_geometry.Scheme.open_cover.copy AlgebraicGeometry.Scheme.OpenCover.copy -- Porting note: need more hint on universe level /-- The pushforward of an open cover along an isomorphism. -/ @[simps! J obj map] def OpenCover.pushforwardIso {X Y : Scheme.{u}} (𝒰 : OpenCover.{v} X) (f : X ⟶ Y) [IsIso f] : OpenCover.{v} Y := ((openCoverOfIsIso.{v, u} f).bind fun _ => 𝒰).copy 𝒰.J _ _ ((Equiv.punitProd _).symm.trans (Equiv.sigmaEquivProd PUnit 𝒰.J).symm) (fun _ => Iso.refl _) fun _ => (Category.id_comp _).symm #align algebraic_geometry.Scheme.open_cover.pushforward_iso AlgebraicGeometry.Scheme.OpenCover.pushforwardIso /-- Adding an open immersion into an open cover gives another open cover. -/ @[simps] def OpenCover.add {X Y : Scheme.{u}} (𝒰 : X.OpenCover) (f : Y ⟶ X) [IsOpenImmersion f] : X.OpenCover where J := Option 𝒰.J obj i := Option.rec Y 𝒰.obj i map i := Option.rec f 𝒰.map i f x := some (𝒰.f x) Covers := 𝒰.Covers IsOpen := by rintro (_ | _) <;> dsimp <;> infer_instance #align algebraic_geometry.Scheme.open_cover.add AlgebraicGeometry.Scheme.OpenCover.add -- Related result : `open_cover.pullback_cover`, where we pullback an open cover on `X` along a -- morphism `W ⟶ X`. This is provided at the end of the file since it needs some more results -- about open immersion (which in turn needs the open cover API). -- attribute [local reducible] CommRingCat.of CommRingCat.ofHom instance val_base_isIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : IsIso f.1.base := Scheme.forgetToTop.map_isIso f #align algebraic_geometry.Scheme.val_base_is_iso AlgebraicGeometry.Scheme.val_base_isIso instance basic_open_isOpenImmersion {R : CommRingCat.{u}} (f : R) : AlgebraicGeometry.IsOpenImmersion (Scheme.Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away f))).op) := by apply SheafedSpace.IsOpenImmersion.of_stalk_iso (H := ?_) · exact (PrimeSpectrum.localization_away_openEmbedding (Localization.Away f) f : _) · intro x exact Spec_map_localization_isIso R (Submonoid.powers f) x #align algebraic_geometry.Scheme.basic_open_IsOpenImmersion AlgebraicGeometry.Scheme.basic_open_isOpenImmersion /-- The basic open sets form an affine open cover of `Spec R`. -/ def affineBasisCoverOfAffine (R : CommRingCat.{u}) : OpenCover (Spec.obj (Opposite.op R)) where J := R obj r := Spec.obj (Opposite.op <| CommRingCat.of <| Localization.Away r) map r := Spec.map (Quiver.Hom.op (algebraMap R (Localization.Away r) : _)) f _ := 1 Covers r := by rw [Set.range_iff_surjective.mpr ((TopCat.epi_iff_surjective _).mp _)] · exact trivial · -- Porting note: need more hand holding here because Lean knows that -- `CommRing.ofHom ...` is iso, but without `ofHom` Lean does not know what to do change Epi (Spec.map (CommRingCat.ofHom (algebraMap _ _)).op).1.base infer_instance IsOpen x := AlgebraicGeometry.Scheme.basic_open_isOpenImmersion x #align algebraic_geometry.Scheme.affine_basis_cover_of_affine AlgebraicGeometry.Scheme.affineBasisCoverOfAffine /-- We may bind the basic open sets of an open affine cover to form an affine cover that is also a basis. -/ def affineBasisCover (X : Scheme.{u}) : OpenCover X := X.affineCover.bind fun _ => affineBasisCoverOfAffine _ #align algebraic_geometry.Scheme.affine_basis_cover AlgebraicGeometry.Scheme.affineBasisCover /-- The coordinate ring of a component in the `affine_basis_cover`. -/ def affineBasisCoverRing (X : Scheme.{u}) (i : X.affineBasisCover.J) : CommRingCat := CommRingCat.of <| @Localization.Away (X.local_affine i.1).choose_spec.choose _ i.2 #align algebraic_geometry.Scheme.affine_basis_cover_ring AlgebraicGeometry.Scheme.affineBasisCoverRing theorem affineBasisCover_obj (X : Scheme.{u}) (i : X.affineBasisCover.J) : X.affineBasisCover.obj i = Spec.obj (op <| X.affineBasisCoverRing i) := rfl #align algebraic_geometry.Scheme.affine_basis_cover_obj AlgebraicGeometry.Scheme.affineBasisCover_obj theorem affineBasisCover_map_range (X : Scheme.{u}) (x : X) (r : (X.local_affine x).choose_spec.choose) : Set.range (X.affineBasisCover.map ⟨x, r⟩).1.base = (X.affineCover.map x).1.base '' (PrimeSpectrum.basicOpen r).1 := by erw [coe_comp, Set.range_comp] -- Porting note: `congr` fails to see the goal is comparing image of the same function refine congr_arg (_ '' ·) ?_ exact (PrimeSpectrum.localization_away_comap_range (Localization.Away r) r : _) #align algebraic_geometry.Scheme.affine_basis_cover_map_range AlgebraicGeometry.Scheme.affineBasisCover_map_range theorem affineBasisCover_is_basis (X : Scheme.{u}) : TopologicalSpace.IsTopologicalBasis {x : Set X | ∃ a : X.affineBasisCover.J, x = Set.range (X.affineBasisCover.map a).1.base} := by apply TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds · rintro _ ⟨a, rfl⟩ exact IsOpenImmersion.isOpen_range (X.affineBasisCover.map a) · rintro a U haU hU rcases X.affineCover.Covers a with ⟨x, e⟩ let U' := (X.affineCover.map (X.affineCover.f a)).1.base ⁻¹' U have hxU' : x ∈ U' := by rw [← e] at haU; exact haU rcases PrimeSpectrum.isBasis_basic_opens.exists_subset_of_mem_open hxU' ((X.affineCover.map (X.affineCover.f a)).1.base.continuous_toFun.isOpen_preimage _ hU) with ⟨_, ⟨_, ⟨s, rfl⟩, rfl⟩, hxV, hVU⟩ refine ⟨_, ⟨⟨_, s⟩, rfl⟩, ?_, ?_⟩ <;> erw [affineBasisCover_map_range] · exact ⟨x, hxV, e⟩ · rw [Set.image_subset_iff]; exact hVU #align algebraic_geometry.Scheme.affine_basis_cover_is_basis AlgebraicGeometry.Scheme.affineBasisCover_is_basis /-- Every open cover of a quasi-compact scheme can be refined into a finite subcover. -/ @[simps! obj map] def OpenCover.finiteSubcover {X : Scheme.{u}} (𝒰 : OpenCover X) [H : CompactSpace X] : OpenCover X := by have := @CompactSpace.elim_nhds_subcover _ _ H (fun x : X => Set.range (𝒰.map (𝒰.f x)).1.base) fun x => (IsOpenImmersion.isOpen_range (𝒰.map (𝒰.f x))).mem_nhds (𝒰.Covers x) let t := this.choose have h : ∀ x : X, ∃ y : t, x ∈ Set.range (𝒰.map (𝒰.f y)).1.base := by intro x have h' : x ∈ (⊤ : Set X) := trivial rw [← Classical.choose_spec this, Set.mem_iUnion] at h' rcases h' with ⟨y, _, ⟨hy, rfl⟩, hy'⟩ exact ⟨⟨y, hy⟩, hy'⟩ exact { J := t obj := fun x => 𝒰.obj (𝒰.f x.1) map := fun x => 𝒰.map (𝒰.f x.1) f := fun x => (h x).choose Covers := fun x => (h x).choose_spec } #align algebraic_geometry.Scheme.open_cover.finite_subcover AlgebraicGeometry.Scheme.OpenCover.finiteSubcover instance [H : CompactSpace X] : Fintype 𝒰.finiteSubcover.J := by delta OpenCover.finiteSubcover; infer_instance end Scheme end OpenCover namespace PresheafedSpace.IsOpenImmersion section ToScheme variable {X : PresheafedSpace CommRingCat.{u}} (Y : Scheme.{u}) variable (f : X ⟶ Y.toPresheafedSpace) [H : PresheafedSpace.IsOpenImmersion f] /-- If `X ⟶ Y` is an open immersion, and `Y` is a scheme, then so is `X`. -/ def toScheme : Scheme := by apply LocallyRingedSpace.IsOpenImmersion.scheme (toLocallyRingedSpace _ f) intro x obtain ⟨_, ⟨i, rfl⟩, hx, hi⟩ := Y.affineBasisCover_is_basis.exists_subset_of_mem_open (Set.mem_range_self x) H.base_open.isOpen_range use Y.affineBasisCoverRing i use LocallyRingedSpace.IsOpenImmersion.lift (toLocallyRingedSpaceHom _ f) _ hi constructor · rw [LocallyRingedSpace.IsOpenImmersion.lift_range]; exact hx · delta LocallyRingedSpace.IsOpenImmersion.lift; infer_instance #align algebraic_geometry.PresheafedSpace.IsOpenImmersion.to_Scheme AlgebraicGeometry.PresheafedSpace.IsOpenImmersionₓ.toScheme @[simp] theorem toScheme_toLocallyRingedSpace : (toScheme Y f).toLocallyRingedSpace = toLocallyRingedSpace Y.1 f := rfl #align algebraic_geometry.PresheafedSpace.IsOpenImmersion.to_Scheme_to_LocallyRingedSpace AlgebraicGeometry.PresheafedSpace.IsOpenImmersionₓ.toScheme_toLocallyRingedSpace /-- If `X ⟶ Y` is an open immersion of PresheafedSpaces, and `Y` is a Scheme, we can upgrade it into a morphism of Schemes. -/ def toSchemeHom : toScheme Y f ⟶ Y := toLocallyRingedSpaceHom _ f #align algebraic_geometry.PresheafedSpace.IsOpenImmersion.to_Scheme_hom AlgebraicGeometry.PresheafedSpace.IsOpenImmersionₓ.toSchemeHom @[simp] theorem toSchemeHom_val : (toSchemeHom Y f).val = f := rfl #align algebraic_geometry.PresheafedSpace.IsOpenImmersion.to_Scheme_hom_val AlgebraicGeometry.PresheafedSpace.IsOpenImmersionₓ.toSchemeHom_val instance toSchemeHom_isOpenImmersion : AlgebraicGeometry.IsOpenImmersion (toSchemeHom Y f) := H #align algebraic_geometry.PresheafedSpace.IsOpenImmersion.to_Scheme_hom_IsOpenImmersion AlgebraicGeometry.PresheafedSpace.IsOpenImmersionₓ.toSchemeHom_isOpenImmersionₓ theorem scheme_eq_of_locallyRingedSpace_eq {X Y : Scheme.{u}} (H : X.toLocallyRingedSpace = Y.toLocallyRingedSpace) : X = Y := by cases X; cases Y; congr #align algebraic_geometry.PresheafedSpace.IsOpenImmersion.Scheme_eq_of_LocallyRingedSpace_eq AlgebraicGeometry.PresheafedSpace.IsOpenImmersionₓ.scheme_eq_of_locallyRingedSpace_eq theorem scheme_toScheme {X Y : Scheme.{u}} (f : X ⟶ Y) [AlgebraicGeometry.IsOpenImmersion f] : toScheme Y f.1 = X := by apply scheme_eq_of_locallyRingedSpace_eq exact locallyRingedSpace_toLocallyRingedSpace f #align algebraic_geometry.PresheafedSpace.IsOpenImmersion.Scheme_to_Scheme AlgebraicGeometry.PresheafedSpace.IsOpenImmersionₓ.scheme_toScheme end ToScheme end PresheafedSpace.IsOpenImmersion /-- The restriction of a Scheme along an open embedding. -/ @[simps! (config := .lemmasOnly) carrier, simps! presheaf_map presheaf_obj] def Scheme.restrict {U : TopCat.{u}} (X : Scheme.{u}) {f : U ⟶ TopCat.of X} (h : OpenEmbedding f) : Scheme := { PresheafedSpace.IsOpenImmersion.toScheme X (X.toPresheafedSpace.ofRestrict h) with toPresheafedSpace := X.toPresheafedSpace.restrict h } #align algebraic_geometry.Scheme.restrict AlgebraicGeometry.Scheme.restrict lemma Scheme.restrict_toPresheafedSpace {U : TopCat.{u}} (X : Scheme.{u}) {f : U ⟶ TopCat.of X} (h : OpenEmbedding f) : (X.restrict h).toPresheafedSpace = X.toPresheafedSpace.restrict h := rfl /-- The canonical map from the restriction to the subspace. -/ @[simps!] def Scheme.ofRestrict {U : TopCat.{u}} (X : Scheme.{u}) {f : U ⟶ TopCat.of X} (h : OpenEmbedding f) : X.restrict h ⟶ X := X.toLocallyRingedSpace.ofRestrict h #align algebraic_geometry.Scheme.ofRestrict AlgebraicGeometry.Scheme.ofRestrict instance IsOpenImmersion.ofRestrict {U : TopCat.{u}} (X : Scheme.{u}) {f : U ⟶ TopCat.of X} (h : OpenEmbedding f) : IsOpenImmersion (X.ofRestrict h) := show PresheafedSpace.IsOpenImmersion (X.toPresheafedSpace.ofRestrict h) by infer_instance #align algebraic_geometry.IsOpenImmersion.ofRestrict AlgebraicGeometry.IsOpenImmersion.ofRestrict namespace IsOpenImmersion variable {X Y Z : Scheme.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) variable [H : IsOpenImmersion f] instance (priority := 100) of_isIso [IsIso g] : IsOpenImmersion g := @LocallyRingedSpace.IsOpenImmersion.of_isIso _ _ _ (show IsIso ((inducedFunctor _).map g) by infer_instance) #align algebraic_geometry.IsOpenImmersion.of_is_iso AlgebraicGeometry.IsOpenImmersion.of_isIso theorem to_iso {X Y : Scheme.{u}} (f : X ⟶ Y) [h : IsOpenImmersion f] [Epi f.1.base] : IsIso f := @isIso_of_reflects_iso _ _ _ _ _ _ f (Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) (@PresheafedSpace.IsOpenImmersion.to_iso _ _ _ _ f.1 h _) _ #align algebraic_geometry.IsOpenImmersion.to_iso AlgebraicGeometry.IsOpenImmersion.to_iso theorem of_stalk_iso {X Y : Scheme.{u}} (f : X ⟶ Y) (hf : OpenEmbedding f.1.base) [∀ x, IsIso (PresheafedSpace.stalkMap f.1 x)] : IsOpenImmersion f := SheafedSpace.IsOpenImmersion.of_stalk_iso f.1 hf #align algebraic_geometry.IsOpenImmersion.of_stalk_iso AlgebraicGeometry.IsOpenImmersion.of_stalk_iso theorem iff_stalk_iso {X Y : Scheme.{u}} (f : X ⟶ Y) : IsOpenImmersion f ↔ OpenEmbedding f.1.base ∧ ∀ x, IsIso (PresheafedSpace.stalkMap f.1 x) := ⟨fun H => ⟨H.1, inferInstance⟩, fun ⟨h₁, h₂⟩ => @IsOpenImmersion.of_stalk_iso _ _ f h₁ h₂⟩ #align algebraic_geometry.IsOpenImmersion.iff_stalk_iso AlgebraicGeometry.IsOpenImmersion.iff_stalk_iso theorem _root_.AlgebraicGeometry.isIso_iff_isOpenImmersion {X Y : Scheme.{u}} (f : X ⟶ Y) : IsIso f ↔ IsOpenImmersion f ∧ Epi f.1.base := ⟨fun _ => ⟨inferInstance, inferInstance⟩, fun ⟨h₁, h₂⟩ => @IsOpenImmersion.to_iso _ _ f h₁ h₂⟩ #align algebraic_geometry.is_iso_iff_IsOpenImmersion AlgebraicGeometry.isIso_iff_isOpenImmersion theorem _root_.AlgebraicGeometry.isIso_iff_stalk_iso {X Y : Scheme.{u}} (f : X ⟶ Y) : IsIso f ↔ IsIso f.1.base ∧ ∀ x, IsIso (PresheafedSpace.stalkMap f.1 x) := by rw [isIso_iff_isOpenImmersion, IsOpenImmersion.iff_stalk_iso, and_comm, ← and_assoc] refine and_congr ⟨?_, ?_⟩ Iff.rfl · rintro ⟨h₁, h₂⟩ convert_to IsIso (TopCat.isoOfHomeo (Homeomorph.homeomorphOfContinuousOpen (Equiv.ofBijective _ ⟨h₂.inj, (TopCat.epi_iff_surjective _).mp h₁⟩) h₂.continuous h₂.isOpenMap)).hom infer_instance · intro H; exact ⟨inferInstance, (TopCat.homeoOfIso (asIso f.1.base)).openEmbedding⟩ #align algebraic_geometry.is_iso_iff_stalk_iso AlgebraicGeometry.isIso_iff_stalk_iso /-- An open immersion induces an isomorphism from the domain onto the image -/ def isoRestrict : X ≅ (Z.restrict H.base_open : _) := ⟨(LocallyRingedSpace.IsOpenImmersion.isoRestrict H).hom, (LocallyRingedSpace.IsOpenImmersion.isoRestrict H).inv, (LocallyRingedSpace.IsOpenImmersion.isoRestrict H).hom_inv_id, (LocallyRingedSpace.IsOpenImmersion.isoRestrict H).inv_hom_id⟩ #align algebraic_geometry.IsOpenImmersion.iso_restrict AlgebraicGeometry.IsOpenImmersion.isoRestrict local notation "forget" => Scheme.forgetToLocallyRingedSpace instance mono : Mono f := (inducedFunctor _).mono_of_mono_map (show @Mono LocallyRingedSpace _ _ _ f by infer_instance) #align algebraic_geometry.IsOpenImmersion.mono AlgebraicGeometry.IsOpenImmersion.mono instance forget_map_isOpenImmersion : LocallyRingedSpace.IsOpenImmersion ((forget).map f) := ⟨H.base_open, H.c_iso⟩ #align algebraic_geometry.IsOpenImmersion.forget_map_IsOpenImmersion AlgebraicGeometry.IsOpenImmersion.forget_map_isOpenImmersion instance hasLimit_cospan_forget_of_left : HasLimit (cospan f g ⋙ Scheme.forgetToLocallyRingedSpace) := by apply @hasLimitOfIso _ _ _ _ _ _ ?_ (diagramIsoCospan.{u} _).symm change HasLimit (cospan ((forget).map f) ((forget).map g)) infer_instance #align algebraic_geometry.IsOpenImmersion.has_limit_cospan_forget_of_left AlgebraicGeometry.IsOpenImmersion.hasLimit_cospan_forget_of_left open CategoryTheory.Limits.WalkingCospan instance hasLimit_cospan_forget_of_left' : HasLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map f) ((forget).map g)) from inferInstance #align algebraic_geometry.IsOpenImmersion.has_limit_cospan_forget_of_left' AlgebraicGeometry.IsOpenImmersion.hasLimit_cospan_forget_of_left' instance hasLimit_cospan_forget_of_right : HasLimit (cospan g f ⋙ forget) := by apply @hasLimitOfIso _ _ _ _ _ _ ?_ (diagramIsoCospan.{u} _).symm change HasLimit (cospan ((forget).map g) ((forget).map f)) infer_instance #align algebraic_geometry.IsOpenImmersion.has_limit_cospan_forget_of_right AlgebraicGeometry.IsOpenImmersion.hasLimit_cospan_forget_of_right instance hasLimit_cospan_forget_of_right' : HasLimit (cospan ((cospan g f ⋙ forget).map Hom.inl) ((cospan g f ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map g) ((forget).map f)) from inferInstance #align algebraic_geometry.IsOpenImmersion.has_limit_cospan_forget_of_right' AlgebraicGeometry.IsOpenImmersion.hasLimit_cospan_forget_of_right' instance forgetCreatesPullbackOfLeft : CreatesLimit (cospan f g) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toScheme Y (@pullback.snd LocallyRingedSpace _ _ _ _ f g _).1) (eqToIso (by simp) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) #align algebraic_geometry.IsOpenImmersion.forget_creates_pullback_of_left AlgebraicGeometry.IsOpenImmersion.forgetCreatesPullbackOfLeft instance forgetCreatesPullbackOfRight : CreatesLimit (cospan g f) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toScheme Y (@pullback.fst LocallyRingedSpace _ _ _ _ g f _).1) (eqToIso (by simp) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) #align algebraic_geometry.IsOpenImmersion.forget_creates_pullback_of_right AlgebraicGeometry.IsOpenImmersion.forgetCreatesPullbackOfRight instance forgetPreservesOfLeft : PreservesLimit (cospan f g) forget := CategoryTheory.preservesLimitOfCreatesLimitAndHasLimit _ _ #align algebraic_geometry.IsOpenImmersion.forget_preserves_of_left AlgebraicGeometry.IsOpenImmersion.forgetPreservesOfLeft instance forgetPreservesOfRight : PreservesLimit (cospan g f) forget := preservesPullbackSymmetry _ _ _ #align algebraic_geometry.IsOpenImmersion.forget_preserves_of_right AlgebraicGeometry.IsOpenImmersion.forgetPreservesOfRight instance hasPullback_of_left : HasPullback f g := hasLimit_of_created (cospan f g) forget #align algebraic_geometry.IsOpenImmersion.has_pullback_of_left AlgebraicGeometry.IsOpenImmersion.hasPullback_of_left instance hasPullback_of_right : HasPullback g f := hasLimit_of_created (cospan g f) forget #align algebraic_geometry.IsOpenImmersion.has_pullback_of_right AlgebraicGeometry.IsOpenImmersion.hasPullback_of_right instance pullback_snd_of_left : IsOpenImmersion (pullback.snd : pullback f g ⟶ _) := by have := PreservesPullback.iso_hom_snd forget f g dsimp only [Scheme.forgetToLocallyRingedSpace, inducedFunctor_map] at this rw [← this] change LocallyRingedSpace.IsOpenImmersion _ infer_instance #align algebraic_geometry.IsOpenImmersion.pullback_snd_of_left AlgebraicGeometry.IsOpenImmersion.pullback_snd_of_left instance pullback_fst_of_right : IsOpenImmersion (pullback.fst : pullback g f ⟶ _) := by rw [← pullbackSymmetry_hom_comp_snd] -- Porting note: was just `infer_instance`, it is a bit weird that no explicit class instance is -- provided but still class inference fail to find this exact LocallyRingedSpace.IsOpenImmersion.comp (H := inferInstance) _ #align algebraic_geometry.IsOpenImmersion.pullback_fst_of_right AlgebraicGeometry.IsOpenImmersion.pullback_fst_of_right instance pullback_to_base [IsOpenImmersion g] : IsOpenImmersion (limit.π (cospan f g) WalkingCospan.one) := by rw [← limit.w (cospan f g) WalkingCospan.Hom.inl] change IsOpenImmersion (_ ≫ f) -- Porting note: was just `infer_instance`, it is a bit weird that no explicit class instance is -- provided but still class inference fail to find this exact LocallyRingedSpace.IsOpenImmersion.comp (H := inferInstance) _ #align algebraic_geometry.IsOpenImmersion.pullback_to_base AlgebraicGeometry.IsOpenImmersion.pullback_to_base instance forgetToTopPreservesOfLeft : PreservesLimit (cospan f g) Scheme.forgetToTop := by delta Scheme.forgetToTop apply @Limits.compPreservesLimit (K := cospan f g) (F := forget) (G := LocallyRingedSpace.forgetToTop) ?_ ?_ · infer_instance apply @preservesLimitOfIsoDiagram (F := _) _ _ _ _ _ _ (diagramIsoCospan.{u} _).symm ?_ dsimp [LocallyRingedSpace.forgetToTop] infer_instance #align algebraic_geometry.IsOpenImmersion.forget_to_Top_preserves_of_left AlgebraicGeometry.IsOpenImmersion.forgetToTopPreservesOfLeft instance forgetToTopPreservesOfRight : PreservesLimit (cospan g f) Scheme.forgetToTop := preservesPullbackSymmetry _ _ _ #align algebraic_geometry.IsOpenImmersion.forget_to_Top_preserves_of_right AlgebraicGeometry.IsOpenImmersion.forgetToTopPreservesOfRight theorem range_pullback_snd_of_left : Set.range (pullback.snd : pullback f g ⟶ Y).1.base = ((Opens.map g.1.base).obj ⟨Set.range f.1.base, H.base_open.isOpen_range⟩).1 := by rw [← show _ = (pullback.snd : pullback f g ⟶ _).1.base from PreservesPullback.iso_hom_snd Scheme.forgetToTop f g] -- Porting note (#10691): was `rw` erw [coe_comp] rw [Set.range_comp, Set.range_iff_surjective.mpr, ← @Set.preimage_univ _ _ (pullback.fst : pullback f.1.base g.1.base ⟶ _)] -- Porting note (#10691): was `rw` · erw [TopCat.pullback_snd_image_fst_preimage] rw [Set.image_univ] rfl erw [← TopCat.epi_iff_surjective] -- now `erw` after #13170 infer_instance #align algebraic_geometry.IsOpenImmersion.range_pullback_snd_of_left AlgebraicGeometry.IsOpenImmersion.range_pullback_snd_of_left theorem range_pullback_fst_of_right : Set.range (pullback.fst : pullback g f ⟶ Y).1.base = ((Opens.map g.1.base).obj ⟨Set.range f.1.base, H.base_open.isOpen_range⟩).1 := by rw [← show _ = (pullback.fst : pullback g f ⟶ _).1.base from PreservesPullback.iso_hom_fst Scheme.forgetToTop g f] -- Porting note (#10691): was `rw` erw [coe_comp] rw [Set.range_comp, Set.range_iff_surjective.mpr, ← @Set.preimage_univ _ _ (pullback.snd : pullback g.1.base f.1.base ⟶ _)] -- Porting note (#10691): was `rw` · erw [TopCat.pullback_fst_image_snd_preimage] rw [Set.image_univ] rfl erw [← TopCat.epi_iff_surjective] -- now `erw` after #13170 infer_instance #align algebraic_geometry.IsOpenImmersion.range_pullback_fst_of_right AlgebraicGeometry.IsOpenImmersion.range_pullback_fst_of_right theorem range_pullback_to_base_of_left : Set.range (pullback.fst ≫ f : pullback f g ⟶ Z).1.base = Set.range f.1.base ∩ Set.range g.1.base := by rw [pullback.condition, Scheme.comp_val_base, TopCat.coe_comp, Set.range_comp, range_pullback_snd_of_left, Opens.carrier_eq_coe, Opens.map_obj, Opens.coe_mk, Set.image_preimage_eq_inter_range] #align algebraic_geometry.IsOpenImmersion.range_pullback_to_base_of_left AlgebraicGeometry.IsOpenImmersion.range_pullback_to_base_of_left theorem range_pullback_to_base_of_right : Set.range (pullback.fst ≫ g : pullback g f ⟶ Z).1.base = Set.range g.1.base ∩ Set.range f.1.base := by rw [Scheme.comp_val_base, TopCat.coe_comp, Set.range_comp, range_pullback_fst_of_right, Opens.map_obj, Opens.carrier_eq_coe, Opens.coe_mk, Set.image_preimage_eq_inter_range, Set.inter_comm] #align algebraic_geometry.IsOpenImmersion.range_pullback_to_base_of_right AlgebraicGeometry.IsOpenImmersion.range_pullback_to_base_of_right /-- The universal property of open immersions: For an open immersion `f : X ⟶ Z`, given any morphism of schemes `g : Y ⟶ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟶ X` that commutes with these maps. -/ def lift (H' : Set.range g.1.base ⊆ Set.range f.1.base) : Y ⟶ X := LocallyRingedSpace.IsOpenImmersion.lift f g H' #align algebraic_geometry.IsOpenImmersion.lift AlgebraicGeometry.IsOpenImmersion.lift @[simp, reassoc] theorem lift_fac (H' : Set.range g.1.base ⊆ Set.range f.1.base) : lift f g H' ≫ f = g := LocallyRingedSpace.IsOpenImmersion.lift_fac f g H' #align algebraic_geometry.IsOpenImmersion.lift_fac AlgebraicGeometry.IsOpenImmersion.lift_fac theorem lift_uniq (H' : Set.range g.1.base ⊆ Set.range f.1.base) (l : Y ⟶ X) (hl : l ≫ f = g) : l = lift f g H' := LocallyRingedSpace.IsOpenImmersion.lift_uniq f g H' l hl #align algebraic_geometry.IsOpenImmersion.lift_uniq AlgebraicGeometry.IsOpenImmersion.lift_uniq /-- Two open immersions with equal range are isomorphic. -/ def isoOfRangeEq [IsOpenImmersion g] (e : Set.range f.1.base = Set.range g.1.base) : X ≅ Y where hom := lift g f (le_of_eq e) inv := lift f g (le_of_eq e.symm) hom_inv_id := by rw [← cancel_mono f]; simp inv_hom_id := by rw [← cancel_mono g]; simp #align algebraic_geometry.IsOpenImmersion.iso_of_range_eq AlgebraicGeometry.IsOpenImmersion.isoOfRangeEq @[simp, reassoc] lemma isoOfRangeEq_hom_fac {X Y Z : Scheme.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) [IsOpenImmersion f] [IsOpenImmersion g] (e : Set.range f.1.base = Set.range g.1.base) : (isoOfRangeEq f g e).hom ≫ g = f := lift_fac _ _ (le_of_eq e) @[simp, reassoc] lemma isoOfRangeEq_inv_fac {X Y Z : Scheme.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) [IsOpenImmersion f] [IsOpenImmersion g] (e : Set.range f.1.base = Set.range g.1.base) : (isoOfRangeEq f g e).inv ≫ f = g := lift_fac _ _ (le_of_eq e.symm) /-- The functor `opens X ⥤ opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev _root_.AlgebraicGeometry.Scheme.Hom.opensFunctor {X Y : Scheme.{u}} (f : X ⟶ Y) [H : IsOpenImmersion f] : Opens X ⥤ Opens Y := H.openFunctor #align algebraic_geometry.Scheme.hom.opens_functor AlgebraicGeometry.Scheme.Hom.opensFunctor /-- The isomorphism `Γ(X, U) ⟶ Γ(Y, f(U))` induced by an open immersion `f : X ⟶ Y`. -/ def _root_.AlgebraicGeometry.Scheme.Hom.invApp {X Y : Scheme.{u}} (f : X ⟶ Y) [H : IsOpenImmersion f] (U) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (f.opensFunctor.obj U)) := H.invApp U #align algebraic_geometry.Scheme.hom.inv_app AlgebraicGeometry.Scheme.Hom.invApp
Mathlib/AlgebraicGeometry/OpenImmersion.lean
659
666
theorem app_eq_inv_app_app_of_comp_eq_aux {X Y U : Scheme.{u}} (f : Y ⟶ U) (g : U ⟶ X) (fg : Y ⟶ X) (H : fg = f ≫ g) [h : IsOpenImmersion g] (V : Opens U) : (Opens.map f.1.base).obj V = (Opens.map fg.1.base).obj (g.opensFunctor.obj V) := by
subst H rw [Scheme.comp_val_base, Opens.map_comp_obj] congr 1 ext1 exact (Set.preimage_image_eq _ h.base_open.inj).symm
/- Copyright (c) 2018 Louis Carlin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Louis Carlin, Mario Carneiro -/ import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Basic #align_import algebra.euclidean_domain.basic from "leanprover-community/mathlib"@"bf9bbbcf0c1c1ead18280b0d010e417b10abb1b6" /-! # Lemmas about Euclidean domains ## Main statements * `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains. -/ universe u namespace EuclideanDomain variable {R : Type u} variable [EuclideanDomain R] /-- The well founded relation in a Euclidean Domain satisfying `a % b ≺ b` for `b ≠ 0` -/ local infixl:50 " ≺ " => EuclideanDomain.R -- See note [lower instance priority] instance (priority := 100) toMulDivCancelClass : MulDivCancelClass R where mul_div_cancel a b hb := by refine (eq_of_sub_eq_zero ?_).symm by_contra h have := mul_right_not_lt b h rw [sub_mul, mul_comm (_ / _), sub_eq_iff_eq_add'.2 (div_add_mod (a * b) b).symm] at this exact this (mod_lt _ hb) #align euclidean_domain.mul_div_cancel_left mul_div_cancel_left₀ #align euclidean_domain.mul_div_cancel mul_div_cancel_right₀ @[simp] theorem mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a := ⟨fun h => by rw [← div_add_mod a b, h, add_zero] exact dvd_mul_right _ _, fun ⟨c, e⟩ => by rw [e, ← add_left_cancel_iff, div_add_mod, add_zero] haveI := Classical.dec by_cases b0 : b = 0 · simp only [b0, zero_mul] · rw [mul_div_cancel_left₀ _ b0]⟩ #align euclidean_domain.mod_eq_zero EuclideanDomain.mod_eq_zero @[simp] theorem mod_self (a : R) : a % a = 0 := mod_eq_zero.2 dvd_rfl #align euclidean_domain.mod_self EuclideanDomain.mod_self theorem dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a := by rw [← dvd_add_right (h.mul_right _), div_add_mod] #align euclidean_domain.dvd_mod_iff EuclideanDomain.dvd_mod_iff @[simp] theorem mod_one (a : R) : a % 1 = 0 := mod_eq_zero.2 (one_dvd _) #align euclidean_domain.mod_one EuclideanDomain.mod_one @[simp] theorem zero_mod (b : R) : 0 % b = 0 := mod_eq_zero.2 (dvd_zero _) #align euclidean_domain.zero_mod EuclideanDomain.zero_mod @[simp] theorem zero_div {a : R} : 0 / a = 0 := by_cases (fun a0 : a = 0 => a0.symm ▸ div_zero 0) fun a0 => by simpa only [zero_mul] using mul_div_cancel_right₀ 0 a0 #align euclidean_domain.zero_div EuclideanDomain.zero_div @[simp] theorem div_self {a : R} (a0 : a ≠ 0) : a / a = 1 := by simpa only [one_mul] using mul_div_cancel_right₀ 1 a0 #align euclidean_domain.div_self EuclideanDomain.div_self
Mathlib/Algebra/EuclideanDomain/Basic.lean
88
89
theorem eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b := by
rw [← h, mul_div_cancel_right₀ _ hb]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd #align_import data.set.prod from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Sets in product and pi types This file defines the product of sets in `α × β` and in `Π i, α i` along with the diagonal of a type. ## Main declarations * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun _ => And.decidable #align set.decidable_mem_prod Set.decidableMemProd @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ #align set.prod_mono Set.prod_mono @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl #align set.prod_mono_left Set.prod_mono_left @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht #align set.prod_mono_right Set.prod_mono_right @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ #align set.prod_self_subset_prod_self Set.prod_self_subset_prod_self @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self #align set.prod_self_ssubset_prod_self Set.prod_self_ssubset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ #align set.prod_subset_iff Set.prod_subset_iff theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff #align set.forall_prod_set Set.forall_prod_set theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] #align set.exists_prod_set Set.exists_prod_set @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact and_false_iff _ #align set.prod_empty Set.prod_empty @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact false_and_iff _ #align set.empty_prod Set.empty_prod @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact true_and_iff _ #align set.univ_prod_univ Set.univ_prod_univ theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] #align set.univ_prod Set.univ_prod theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] #align set.prod_univ Set.prod_univ @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] @[simp] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.singleton_prod Set.singleton_prod @[simp] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.prod_singleton Set.prod_singleton theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by simp #align set.singleton_prod_singleton Set.singleton_prod_singleton @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] #align set.union_prod Set.union_prod @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] #align set.prod_union Set.prod_union theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] #align set.inter_prod Set.inter_prod theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] #align set.prod_inter Set.prod_inter @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] #align set.prod_inter_prod Set.prod_inter_prod lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h · by_cases fst_in_s : p.fst ∈ s · exact Or.inr (h fst_in_s) · exact Or.inl fst_in_s · intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ← @forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] #align set.disjoint_prod Set.disjoint_prod theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂ #align set.disjoint.set_prod_left Set.Disjoint.set_prod_left theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂ #align set.disjoint.set_prod_right Set.Disjoint.set_prod_right theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by ext ⟨x, y⟩ simp (config := { contextual := true }) [image, iff_def, or_imp] #align set.insert_prod Set.insert_prod theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by ext ⟨x, y⟩ -- porting note (#10745): -- was `simp (config := { contextual := true }) [image, iff_def, or_imp, Imp.swap]` simp only [mem_prod, mem_insert_iff, image, mem_union, mem_setOf_eq, Prod.mk.injEq] refine ⟨fun h => ?_, fun h => ?_⟩ · obtain ⟨hx, rfl|hy⟩ := h · exact Or.inl ⟨x, hx, rfl, rfl⟩ · exact Or.inr ⟨hx, hy⟩ · obtain ⟨x, hx, rfl, rfl⟩|⟨hx, hy⟩ := h · exact ⟨hx, Or.inl rfl⟩ · exact ⟨hx, Or.inr hy⟩ #align set.prod_insert Set.prod_insert theorem prod_preimage_eq {f : γ → α} {g : δ → β} : (f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_eq Set.prod_preimage_eq theorem prod_preimage_left {f : γ → α} : (f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_left Set.prod_preimage_left theorem prod_preimage_right {g : δ → β} : s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_right Set.prod_preimage_right theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) : Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) := rfl #align set.preimage_prod_map_prod Set.preimage_prod_map_prod theorem mk_preimage_prod (f : γ → α) (g : γ → β) : (fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl #align set.mk_preimage_prod Set.mk_preimage_prod @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by ext a simp [hb] #align set.mk_preimage_prod_left Set.mk_preimage_prod_left @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by ext b simp [ha] #align set.mk_preimage_prod_right Set.mk_preimage_prod_right @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by ext a simp [hb] #align set.mk_preimage_prod_left_eq_empty Set.mk_preimage_prod_left_eq_empty @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by ext b simp [ha] #align set.mk_preimage_prod_right_eq_empty Set.mk_preimage_prod_right_eq_empty theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] : (fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_left_eq_if Set.mk_preimage_prod_left_eq_if theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] : Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_right_eq_if Set.mk_preimage_prod_right_eq_if theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) : (fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage] #align set.mk_preimage_prod_left_fn_eq_if Set.mk_preimage_prod_left_fn_eq_if theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) : (fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] #align set.mk_preimage_prod_right_fn_eq_if Set.mk_preimage_prod_right_fn_eq_if @[simp] theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by ext ⟨x, y⟩ simp [and_comm] #align set.preimage_swap_prod Set.preimage_swap_prod @[simp] theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] #align set.image_swap_prod Set.image_swap_prod theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : (m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t := ext <| by simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm] #align set.prod_image_image_eq Set.prod_image_image_eq theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} : range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_range_range_eq Set.prod_range_range_eq @[simp, mfld_simps] theorem range_prod_map {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ := prod_range_range_eq.symm #align set.range_prod_map Set.range_prod_map theorem prod_range_univ_eq {m₁ : α → γ} : range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) := ext <| by simp [range] #align set.prod_range_univ_eq Set.prod_range_univ_eq theorem prod_univ_range_eq {m₂ : β → δ} : (univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_univ_range_eq Set.prod_univ_range_eq theorem range_pair_subset (f : α → β) (g : α → γ) : (range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl rw [this, ← range_prod_map] apply range_comp_subset_range #align set.range_pair_subset Set.range_pair_subset theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ => ⟨(x, y), ⟨hx, hy⟩⟩ #align set.nonempty.prod Set.Nonempty.prod theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩ #align set.nonempty.fst Set.Nonempty.fst theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩ #align set.nonempty.snd Set.Nonempty.snd @[simp] theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩ #align set.prod_nonempty_iff Set.prod_nonempty_iff @[simp] theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or] #align set.prod_eq_empty_iff Set.prod_eq_empty_iff theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} : s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def] #align set.prod_sub_preimage_iff Set.prod_sub_preimage_iff theorem image_prod_mk_subset_prod {f : α → β} {g : α → γ} {s : Set α} : (fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by rintro _ ⟨x, hx, rfl⟩ exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx) #align set.image_prod_mk_subset_prod Set.image_prod_mk_subset_prod theorem image_prod_mk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by rintro _ ⟨a, ha, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_left Set.image_prod_mk_subset_prod_left theorem image_prod_mk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by rintro _ ⟨b, hb, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_right Set.image_prod_mk_subset_prod_right theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s := inter_subset_left #align set.prod_subset_preimage_fst Set.prod_subset_preimage_fst theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s := image_subset_iff.2 <| prod_subset_preimage_fst s t #align set.fst_image_prod_subset Set.fst_image_prod_subset theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s := (fst_image_prod_subset _ _).antisymm fun y hy => let ⟨x, hx⟩ := ht ⟨(y, x), ⟨hy, hx⟩, rfl⟩ #align set.fst_image_prod Set.fst_image_prod theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t := inter_subset_right #align set.prod_subset_preimage_snd Set.prod_subset_preimage_snd theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t := image_subset_iff.2 <| prod_subset_preimage_snd s t #align set.snd_image_prod_subset Set.snd_image_prod_subset theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t := (snd_image_prod_subset _ _).antisymm fun y y_in => let ⟨x, x_in⟩ := hs ⟨(x, y), ⟨x_in, y_in⟩, rfl⟩ #align set.snd_image_prod Set.snd_image_prod theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by ext x by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*] #align set.prod_diff_prod Set.prod_diff_prod /-- A product set is included in a product set if and only factors are included, or a factor of the first set is empty. -/ theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩ · have := image_subset (Prod.fst : α × β → α) H rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this · have := image_subset (Prod.snd : α × β → β) H rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this · intro H simp only [st.1.ne_empty, st.2.ne_empty, or_false_iff] at H exact prod_mono H.1 H.2 #align set.prod_subset_prod_iff Set.prod_subset_prod_iff theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by constructor · intro heq have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq] rw [prod_nonempty_iff] at h h₁ rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and_iff, ← snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq] · rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_prod_iff_of_nonempty Set.prod_eq_prod_iff_of_nonempty theorem prod_eq_prod_iff : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by symm rcases eq_empty_or_nonempty (s ×ˢ t) with h | h · simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and_iff, or_iff_right_iff_imp] rintro ⟨rfl, rfl⟩ exact prod_eq_empty_iff.mp h rw [prod_eq_prod_iff_of_nonempty h] rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h simp_rw [h, false_and_iff, or_false_iff] #align set.prod_eq_prod_iff Set.prod_eq_prod_iff @[simp] theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true_iff, or_iff_left_iff_imp, or_false_iff] rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_iff_eq Set.prod_eq_iff_eq section Mono variable [Preorder α] {f : α → Set β} {g : α → Set γ} theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align monotone.set_prod Monotone.set_prod theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) : Antitone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align antitone.set_prod Antitone.set_prod theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align monotone_on.set_prod MonotoneOn.set_prod theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align antitone_on.set_prod AntitoneOn.set_prod end Mono end Prod /-! ### Diagonal In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map `fun x ↦ (x, x)`. -/ section Diagonal variable {α : Type*} {s t : Set α} lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty := Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩ #align set.diagonal_nonempty Set.diagonal_nonempty instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) := h x.1 x.2 #align set.decidable_mem_diagonal Set.decidableMemDiagonal theorem preimage_coe_coe_diagonal (s : Set α) : Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ simp [Set.diagonal] #align set.preimage_coe_coe_diagonal Set.preimage_coe_coe_diagonal @[simp] theorem range_diag : (range fun x => (x, x)) = diagonal α := by ext ⟨x, y⟩ simp [diagonal, eq_comm] #align set.range_diag Set.range_diag theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by rw [← range_diag, range_subset_iff] #align set.diagonal_subset_iff Set.diagonal_subset_iff @[simp] theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t := prod_subset_iff.trans disjoint_iff_forall_ne.symm #align set.prod_subset_compl_diagonal_iff_disjoint Set.prod_subset_compl_diagonal_iff_disjoint @[simp] theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t := rfl #align set.diag_preimage_prod Set.diag_preimage_prod theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s := inter_self s #align set.diag_preimage_prod_self Set.diag_preimage_prod_self theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self] #align set.diag_image Set.diag_image theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff] theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_› end Diagonal /-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/ theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] : range (const α) = {f : α → β | ∀ x y, f x = f y} := by refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩ rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩ · exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩ · exact ⟨f a, funext fun x ↦ hf _ _⟩ end Set section Pullback open Set variable {X Y Z} /-- The fiber product $X \times_Y Z$. -/ abbrev Function.Pullback (f : X → Y) (g : Z → Y) := {p : X × Z // f p.1 = g p.2} /-- The fiber product $X \times_Y X$. -/ abbrev Function.PullbackSelf (f : X → Y) := f.Pullback f /-- The projection from the fiber product to the first factor. -/ def Function.Pullback.fst {f : X → Y} {g : Z → Y} (p : f.Pullback g) : X := p.val.1 /-- The projection from the fiber product to the second factor. -/ def Function.Pullback.snd {f : X → Y} {g : Z → Y} (p : f.Pullback g) : Z := p.val.2 open Function.Pullback in lemma Function.pullback_comm_sq (f : X → Y) (g : Z → Y) : f ∘ @fst X Y Z f g = g ∘ @snd X Y Z f g := funext fun p ↦ p.2 /-- The diagonal map $\Delta: X \to X \times_Y X$. -/ def toPullbackDiag (f : X → Y) (x : X) : f.Pullback f := ⟨(x, x), rfl⟩ /-- The diagonal $\Delta(X) \subseteq X \times_Y X$. -/ def Function.pullbackDiagonal (f : X → Y) : Set (f.Pullback f) := {p | p.fst = p.snd} /-- Three functions between the three pairs of spaces $X_i, Y_i, Z_i$ that are compatible induce a function $X_1 \times_{Y_1} Z_1 \to X_2 \times_{Y_2} Z_2$. -/ def Function.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂} {f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂} (mapX : X₁ → X₂) (mapY : Y₁ → Y₂) (mapZ : Z₁ → Z₂) (commX : f₂ ∘ mapX = mapY ∘ f₁) (commZ : g₂ ∘ mapZ = mapY ∘ g₁) (p : f₁.Pullback g₁) : f₂.Pullback g₂ := ⟨(mapX p.fst, mapZ p.snd), (congr_fun commX _).trans <| (congr_arg mapY p.2).trans <| congr_fun commZ.symm _⟩ open Function.Pullback in /-- The projection $(X \times_Y Z) \times_Z (X \times_Y Z) \to X \times_Y X$. -/ def Function.PullbackSelf.map_fst {f : X → Y} {g : Z → Y} : (@snd X Y Z f g).PullbackSelf → f.PullbackSelf := mapPullback fst g fst (pullback_comm_sq f g) (pullback_comm_sq f g) open Function.Pullback in /-- The projection $(X \times_Y Z) \times_X (X \times_Y Z) \to Z \times_Y Z$. -/ def Function.PullbackSelf.map_snd {f : X → Y} {g : Z → Y} : (@fst X Y Z f g).PullbackSelf → g.PullbackSelf := mapPullback snd f snd (pullback_comm_sq f g).symm (pullback_comm_sq f g).symm open Function.PullbackSelf Function.Pullback theorem preimage_map_fst_pullbackDiagonal {f : X → Y} {g : Z → Y} : @map_fst X Y Z f g ⁻¹' pullbackDiagonal f = pullbackDiagonal (@snd X Y Z f g) := by ext ⟨⟨p₁, p₂⟩, he⟩ simp_rw [pullbackDiagonal, mem_setOf, Subtype.ext_iff, Prod.ext_iff] exact (and_iff_left he).symm theorem Function.Injective.preimage_pullbackDiagonal {f : X → Y} {g : Z → X} (inj : g.Injective) : mapPullback g id g (by rfl) (by rfl) ⁻¹' pullbackDiagonal f = pullbackDiagonal (f ∘ g) := ext fun _ ↦ inj.eq_iff theorem image_toPullbackDiag (f : X → Y) (s : Set X) : toPullbackDiag f '' s = pullbackDiagonal f ∩ Subtype.val ⁻¹' s ×ˢ s := by ext x constructor · rintro ⟨x, hx, rfl⟩ exact ⟨rfl, hx, hx⟩ · obtain ⟨⟨x, y⟩, h⟩ := x rintro ⟨rfl : x = y, h2x⟩ exact mem_image_of_mem _ h2x.1 theorem range_toPullbackDiag (f : X → Y) : range (toPullbackDiag f) = pullbackDiagonal f := by rw [← image_univ, image_toPullbackDiag, univ_prod_univ, preimage_univ, inter_univ] theorem injective_toPullbackDiag (f : X → Y) : (toPullbackDiag f).Injective := fun _ _ h ↦ congr_arg Prod.fst (congr_arg Subtype.val h) end Pullback namespace Set section OffDiag variable {α : Type*} {s t : Set α} {x : α × α} {a : α} theorem offDiag_mono : Monotone (offDiag : Set α → Set (α × α)) := fun _ _ h _ => And.imp (@h _) <| And.imp_left <| @h _ #align set.off_diag_mono Set.offDiag_mono @[simp] theorem offDiag_nonempty : s.offDiag.Nonempty ↔ s.Nontrivial := by simp [offDiag, Set.Nonempty, Set.Nontrivial] #align set.off_diag_nonempty Set.offDiag_nonempty @[simp] theorem offDiag_eq_empty : s.offDiag = ∅ ↔ s.Subsingleton := by rw [← not_nonempty_iff_eq_empty, ← not_nontrivial_iff, offDiag_nonempty.not] #align set.off_diag_eq_empty Set.offDiag_eq_empty alias ⟨_, Nontrivial.offDiag_nonempty⟩ := offDiag_nonempty #align set.nontrivial.off_diag_nonempty Set.Nontrivial.offDiag_nonempty alias ⟨_, Subsingleton.offDiag_eq_empty⟩ := offDiag_nonempty #align set.subsingleton.off_diag_eq_empty Set.Subsingleton.offDiag_eq_empty variable (s t) theorem offDiag_subset_prod : s.offDiag ⊆ s ×ˢ s := fun _ hx => ⟨hx.1, hx.2.1⟩ #align set.off_diag_subset_prod Set.offDiag_subset_prod theorem offDiag_eq_sep_prod : s.offDiag = { x ∈ s ×ˢ s | x.1 ≠ x.2 } := ext fun _ => and_assoc.symm #align set.off_diag_eq_sep_prod Set.offDiag_eq_sep_prod @[simp] theorem offDiag_empty : (∅ : Set α).offDiag = ∅ := by simp #align set.off_diag_empty Set.offDiag_empty @[simp] theorem offDiag_singleton (a : α) : ({a} : Set α).offDiag = ∅ := by simp #align set.off_diag_singleton Set.offDiag_singleton @[simp] theorem offDiag_univ : (univ : Set α).offDiag = (diagonal α)ᶜ := ext <| by simp #align set.off_diag_univ Set.offDiag_univ @[simp] theorem prod_sdiff_diagonal : s ×ˢ s \ diagonal α = s.offDiag := ext fun _ => and_assoc #align set.prod_sdiff_diagonal Set.prod_sdiff_diagonal @[simp] theorem disjoint_diagonal_offDiag : Disjoint (diagonal α) s.offDiag := disjoint_left.mpr fun _ hd ho => ho.2.2 hd #align set.disjoint_diagonal_off_diag Set.disjoint_diagonal_offDiag theorem offDiag_inter : (s ∩ t).offDiag = s.offDiag ∩ t.offDiag := ext fun x => by simp only [mem_offDiag, mem_inter_iff] tauto #align set.off_diag_inter Set.offDiag_inter variable {s t}
Mathlib/Data/Set/Prod.lean
673
685
theorem offDiag_union (h : Disjoint s t) : (s ∪ t).offDiag = s.offDiag ∪ t.offDiag ∪ s ×ˢ t ∪ t ×ˢ s := by
ext x simp only [mem_offDiag, mem_union, ne_eq, mem_prod] constructor · rintro ⟨h0|h0, h1|h1, h2⟩ <;> simp [h0, h1, h2] · rintro (((⟨h0, h1, h2⟩|⟨h0, h1, h2⟩)|⟨h0, h1⟩)|⟨h0, h1⟩) <;> simp [*] · rintro h3 rw [h3] at h0 exact Set.disjoint_left.mp h h0 h1 · rintro h3 rw [h3] at h0 exact (Set.disjoint_right.mp h h0 h1).elim
/- 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, Floris Van Doorn, Yury Kudryashov -/ import Mathlib.Topology.MetricSpace.HausdorffDistance import Mathlib.MeasureTheory.Constructions.BorelSpace.Order #align_import measure_theory.measure.regular from "leanprover-community/mathlib"@"bf6a01357ff5684b1ebcd0f1a13be314fc82c0bf" /-! # Regular measures A measure is `OuterRegular` if the measure of any measurable set `A` is the infimum of `μ U` over all open sets `U` containing `A`. A measure is `WeaklyRegular` if it satisfies the following properties: * it is outer regular; * it is inner regular for open sets with respect to closed sets: the measure of any open set `U` is the supremum of `μ F` over all closed sets `F` contained in `U`. A measure is `Regular` if it satisfies the following properties: * it is finite on compact sets; * it is outer regular; * it is inner regular for open sets with respect to compacts closed sets: the measure of any open set `U` is the supremum of `μ K` over all compact sets `K` contained in `U`. A measure is `InnerRegular` if it is inner regular for measurable sets with respect to compact sets: the measure of any measurable set `s` is the supremum of `μ K` over all compact sets contained in `s`. A measure is `InnerRegularCompactLTTop` if it is inner regular for measurable sets of finite measure with respect to compact sets: the measure of any measurable set `s` is the supremum of `μ K` over all compact sets contained in `s`. There is a reason for this zoo of regularity classes: * A finite measure on a metric space is always weakly regular. Therefore, in probability theory, weakly regular measures play a prominent role. * In locally compact topological spaces, there are two competing notions of Radon measures: the ones that are regular, and the ones that are inner regular. For any of these two notions, there is a Riesz representation theorem, and an existence and uniqueness statement for the Haar measure in locally compact topological groups. The two notions coincide in sigma-compact spaces, but they differ in general, so it is worth having the two of them. * Both notions of Haar measure satisfy the weaker notion `InnerRegularCompactLTTop`, so it is worth trying to express theorems using this weaker notion whenever possible, to make sure that it applies to both Haar measures simultaneously. While traditional textbooks on measure theory on locally compact spaces emphasize regular measures, more recent textbooks emphasize that inner regular Haar measures are better behaved than regular Haar measures, so we will develop both notions. The five conditions above are registered as typeclasses for a measure `μ`, and implications between them are recorded as instances. For example, in a Hausdorff topological space, regularity implies weak regularity. Also, regularity or inner regularity both imply `InnerRegularCompactLTTop`. In a regular locally compact finite measure space, then regularity, inner regularity and `InnerRegularCompactLTTop` are all equivalent. In order to avoid code duplication, we also define a measure `μ` to be `InnerRegularWRT` for sets satisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set `U ∈ {U | q U}` and a number `r < μ U` there exists `F ⊆ U` such that `p F` and `r < μ F`. There are two main nontrivial results in the development below: * `InnerRegularWRT.measurableSet_of_isOpen` shows that, for an outer regular measure, inner regularity for open sets with respect to compact sets or closed sets implies inner regularity for all measurable sets of finite measure (with respect to compact sets or closed sets respectively). * `InnerRegularWRT.weaklyRegular_of_finite` shows that a finite measure which is inner regular for open sets with respect to closed sets (for instance a finite measure on a metric space) is weakly regular. All other results are deduced from these ones. Here is an example showing how regularity and inner regularity may differ even on locally compact spaces. Consider the group `ℝ × ℝ` where the first factor has the discrete topology and the second one the usual topology. It is a locally compact Hausdorff topological group, with Haar measure equal to Lebesgue measure on each vertical fiber. Let us consider the regular version of Haar measure. Then the set `ℝ × {0}` has infinite measure (by outer regularity), but any compact set it contains has zero measure (as it is finite). In fact, this set only contains subset with measure zero or infinity. The inner regular version of Haar measure, on the other hand, gives zero mass to the set `ℝ × {0}`. Another interesting example is the sum of the Dirac masses at rational points in the real line. It is a σ-finite measure on a locally compact metric space, but it is not outer regular: for outer regularity, one needs additional locally finite assumptions. On the other hand, it is inner regular. Several authors require both regularity and inner regularity for their measures. We have opted for the more fine grained definitions above as they apply more generally. ## Main definitions * `MeasureTheory.Measure.OuterRegular μ`: a typeclass registering that a measure `μ` on a topological space is outer regular. * `MeasureTheory.Measure.Regular μ`: a typeclass registering that a measure `μ` on a topological space is regular. * `MeasureTheory.Measure.WeaklyRegular μ`: a typeclass registering that a measure `μ` on a topological space is weakly regular. * `MeasureTheory.Measure.InnerRegularWRT μ p q`: a non-typeclass predicate saying that a measure `μ` is inner regular for sets satisfying `q` with respect to sets satisfying `p`. * `MeasureTheory.Measure.InnerRegular μ`: a typeclass registering that a measure `μ` on a topological space is inner regular for measurable sets with respect to compact sets. * `MeasureTheory.Measure.InnerRegularCompactLTTop μ`: a typeclass registering that a measure `μ` on a topological space is inner regular for measurable sets of finite measure with respect to compact sets. ## Main results ### Outer regular measures * `Set.measure_eq_iInf_isOpen` asserts that, when `μ` is outer regular, the measure of a set is the infimum of the measure of open sets containing it. * `Set.exists_isOpen_lt_of_lt` asserts that, when `μ` is outer regular, for every set `s` and `r > μ s` there exists an open superset `U ⊇ s` of measure less than `r`. * push forward of an outer regular measure is outer regular, and scalar multiplication of a regular measure by a finite number is outer regular. ### Weakly regular measures * `IsOpen.measure_eq_iSup_isClosed` asserts that the measure of an open set is the supremum of the measure of closed sets it contains. * `IsOpen.exists_lt_isClosed`: for an open set `U` and `r < μ U`, there exists a closed `F ⊆ U` of measure greater than `r`; * `MeasurableSet.measure_eq_iSup_isClosed_of_ne_top` asserts that the measure of a measurable set of finite measure is the supremum of the measure of closed sets it contains. * `MeasurableSet.exists_lt_isClosed_of_ne_top` and `MeasurableSet.exists_isClosed_lt_add`: a measurable set of finite measure can be approximated by a closed subset (stated as `r < μ F` and `μ s < μ F + ε`, respectively). * `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_of_isFiniteMeasure` is an instance registering that a finite measure on a metric space is weakly regular (in fact, a pseudo metrizable space is enough); * `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_secondCountable_of_locallyFinite` is an instance registering that a locally finite measure on a second countable metric space (or even a pseudo metrizable space) is weakly regular. ### Regular measures * `IsOpen.measure_eq_iSup_isCompact` asserts that the measure of an open set is the supremum of the measure of compact sets it contains. * `IsOpen.exists_lt_isCompact`: for an open set `U` and `r < μ U`, there exists a compact `K ⊆ U` of measure greater than `r`; * `MeasureTheory.Measure.Regular.of_sigmaCompactSpace_of_isLocallyFiniteMeasure` is an instance registering that a locally finite measure on a `σ`-compact metric space is regular (in fact, an emetric space is enough). ### Inner regular measures * `MeasurableSet.measure_eq_iSup_isCompact` asserts that the measure of a measurable set is the supremum of the measure of compact sets it contains. * `MeasurableSet.exists_lt_isCompact`: for a measurable set `s` and `r < μ s`, there exists a compact `K ⊆ s` of measure greater than `r`; ### Inner regular measures for finite measure sets with respect to compact sets * `MeasurableSet.measure_eq_iSup_isCompact_of_ne_top` asserts that the measure of a measurable set of finite measure is the supremum of the measure of compact sets it contains. * `MeasurableSet.exists_lt_isCompact_of_ne_top` and `MeasurableSet.exists_isCompact_lt_add`: a measurable set of finite measure can be approximated by a compact subset (stated as `r < μ K` and `μ s < μ K + ε`, respectively). ## Implementation notes The main nontrivial statement is `MeasureTheory.Measure.InnerRegular.weaklyRegular_of_finite`, expressing that in a finite measure space, if every open set can be approximated from inside by closed sets, then the measure is in fact weakly regular. To prove that we show that any measurable set can be approximated from inside by closed sets and from outside by open sets. This statement is proved by measurable induction, starting from open sets and checking that it is stable by taking complements (this is the point of this condition, being symmetrical between inside and outside) and countable disjoint unions. Once this statement is proved, one deduces results for `σ`-finite measures from this statement, by restricting them to finite measure sets (and proving that this restriction is weakly regular, using again the same statement). For non-Hausdorff spaces, one may argue whether the right condition for inner regularity is with respect to compact sets, or to compact closed sets. For instance, [Fremlin, *Measure Theory* (volume 4, 411J)][fremlin_vol4] considers measures which are inner regular with respect to compact closed sets (and calls them *tight*). However, since most of the literature uses mere compact sets, we have chosen to follow this convention. It doesn't make a difference in Hausdorff spaces, of course. In locally compact topological groups, the two conditions coincide, since if a compact set `k` is contained in a measurable set `u`, then the closure of `k` is a compact closed set still contained in `u`, see `IsCompact.closure_subset_of_measurableSet_of_group`. ## References [Halmos, Measure Theory, §52][halmos1950measure]. Note that Halmos uses an unusual definition of Borel sets (for him, they are elements of the `σ`-algebra generated by compact sets!), so his proofs or statements do not apply directly. [Billingsley, Convergence of Probability Measures][billingsley1999] [Bogachev, Measure Theory, volume 2, Theorem 7.11.1][bogachev2007] -/ open Set Filter ENNReal Topology NNReal TopologicalSpace namespace MeasureTheory namespace Measure /-- We say that a measure `μ` is *inner regular* with respect to predicates `p q : Set α → Prop`, if for every `U` such that `q U` and `r < μ U`, there exists a subset `K ⊆ U` satisfying `p K` of measure greater than `r`. This definition is used to prove some facts about regular and weakly regular measures without repeating the proofs. -/ def InnerRegularWRT {α} {_ : MeasurableSpace α} (μ : Measure α) (p q : Set α → Prop) := ∀ ⦃U⦄, q U → ∀ r < μ U, ∃ K, K ⊆ U ∧ p K ∧ r < μ K #align measure_theory.measure.inner_regular MeasureTheory.Measure.InnerRegularWRT namespace InnerRegularWRT variable {α : Type*} {m : MeasurableSpace α} {μ : Measure α} {p q : Set α → Prop} {U : Set α} {ε : ℝ≥0∞} theorem measure_eq_iSup (H : InnerRegularWRT μ p q) (hU : q U) : μ U = ⨆ (K) (_ : K ⊆ U) (_ : p K), μ K := by refine le_antisymm (le_of_forall_lt fun r hr => ?_) (iSup₂_le fun K hK => iSup_le fun _ => μ.mono hK) simpa only [lt_iSup_iff, exists_prop] using H hU r hr #align measure_theory.measure.inner_regular.measure_eq_supr MeasureTheory.Measure.InnerRegularWRT.measure_eq_iSup theorem exists_subset_lt_add (H : InnerRegularWRT μ p q) (h0 : p ∅) (hU : q U) (hμU : μ U ≠ ∞) (hε : ε ≠ 0) : ∃ K, K ⊆ U ∧ p K ∧ μ U < μ K + ε := by rcases eq_or_ne (μ U) 0 with h₀ | h₀ · refine ⟨∅, empty_subset _, h0, ?_⟩ rwa [measure_empty, h₀, zero_add, pos_iff_ne_zero] · rcases H hU _ (ENNReal.sub_lt_self hμU h₀ hε) with ⟨K, hKU, hKc, hrK⟩ exact ⟨K, hKU, hKc, ENNReal.lt_add_of_sub_lt_right (Or.inl hμU) hrK⟩ #align measure_theory.measure.inner_regular.exists_subset_lt_add MeasureTheory.Measure.InnerRegularWRT.exists_subset_lt_add protected theorem map {α β} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α} {pa qa : Set α → Prop} (H : InnerRegularWRT μ pa qa) {f : α → β} (hf : AEMeasurable f μ) {pb qb : Set β → Prop} (hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K)) (hB₂ : ∀ U, qb U → MeasurableSet U) : InnerRegularWRT (map f μ) pb qb := by intro U hU r hr rw [map_apply_of_aemeasurable hf (hB₂ _ hU)] at hr rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩ refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩ exact hK.trans_le (le_map_apply_image hf _) #align measure_theory.measure.inner_regular.map MeasureTheory.Measure.InnerRegularWRT.map theorem map' {α β} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α} {pa qa : Set α → Prop} (H : InnerRegularWRT μ pa qa) (f : α ≃ᵐ β) {pb qb : Set β → Prop} (hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K)) : InnerRegularWRT (map f μ) pb qb := by intro U hU r hr rw [f.map_apply U] at hr rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩ refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩ rwa [f.map_apply, f.preimage_image] theorem smul (H : InnerRegularWRT μ p q) (c : ℝ≥0∞) : InnerRegularWRT (c • μ) p q := by intro U hU r hr rw [smul_apply, H.measure_eq_iSup hU, smul_eq_mul] at hr simpa only [ENNReal.mul_iSup, lt_iSup_iff, exists_prop] using hr #align measure_theory.measure.inner_regular.smul MeasureTheory.Measure.InnerRegularWRT.smul theorem trans {q' : Set α → Prop} (H : InnerRegularWRT μ p q) (H' : InnerRegularWRT μ q q') : InnerRegularWRT μ p q' := by intro U hU r hr rcases H' hU r hr with ⟨F, hFU, hqF, hF⟩; rcases H hqF _ hF with ⟨K, hKF, hpK, hrK⟩ exact ⟨K, hKF.trans hFU, hpK, hrK⟩ #align measure_theory.measure.inner_regular.trans MeasureTheory.Measure.InnerRegularWRT.trans theorem rfl {p : Set α → Prop} : InnerRegularWRT μ p p := fun U hU _r hr ↦ ⟨U, Subset.rfl, hU, hr⟩ theorem of_imp (h : ∀ s, q s → p s) : InnerRegularWRT μ p q := fun U hU _ hr ↦ ⟨U, Subset.rfl, h U hU, hr⟩ theorem mono {p' q' : Set α → Prop} (H : InnerRegularWRT μ p q) (h : ∀ s, q' s → q s) (h' : ∀ s, p s → p' s) : InnerRegularWRT μ p' q' := of_imp h' |>.trans H |>.trans (of_imp h) end InnerRegularWRT variable {α β : Type*} [MeasurableSpace α] [TopologicalSpace α] {μ : Measure α} /-- A measure `μ` is outer regular if `μ(A) = inf {μ(U) | A ⊆ U open}` for a measurable set `A`. This definition implies the same equality for any (not necessarily measurable) set, see `Set.measure_eq_iInf_isOpen`. -/ class OuterRegular (μ : Measure α) : Prop where protected outerRegular : ∀ ⦃A : Set α⦄, MeasurableSet A → ∀ r > μ A, ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r #align measure_theory.measure.outer_regular MeasureTheory.Measure.OuterRegular #align measure_theory.measure.outer_regular.outer_regular MeasureTheory.Measure.OuterRegular.outerRegular /-- A measure `μ` is regular if - it is finite on all compact sets; - it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable; - it is inner regular for open sets, using compact sets: `μ(U) = sup {μ(K) | K ⊆ U compact}` for `U` open. -/ class Regular (μ : Measure α) extends IsFiniteMeasureOnCompacts μ, OuterRegular μ : Prop where innerRegular : InnerRegularWRT μ IsCompact IsOpen #align measure_theory.measure.regular MeasureTheory.Measure.Regular /-- A measure `μ` is weakly regular if - it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable; - it is inner regular for open sets, using closed sets: `μ(U) = sup {μ(F) | F ⊆ U closed}` for `U` open. -/ class WeaklyRegular (μ : Measure α) extends OuterRegular μ : Prop where protected innerRegular : InnerRegularWRT μ IsClosed IsOpen #align measure_theory.measure.weakly_regular MeasureTheory.Measure.WeaklyRegular #align measure_theory.measure.weakly_regular.inner_regular MeasureTheory.Measure.WeaklyRegular.innerRegular /-- A measure `μ` is inner regular if, for any measurable set `s`, then `μ(s) = sup {μ(K) | K ⊆ s compact}`. -/ class InnerRegular (μ : Measure α) : Prop where protected innerRegular : InnerRegularWRT μ IsCompact (fun s ↦ MeasurableSet s) /-- A measure `μ` is inner regular for finite measure sets with respect to compact sets: for any measurable set `s` with finite measure, then `μ(s) = sup {μ(K) | K ⊆ s compact}`. The main interest of this class is that it is satisfied for both natural Haar measures (the regular one and the inner regular one). -/ class InnerRegularCompactLTTop (μ : Measure α) : Prop where protected innerRegular : InnerRegularWRT μ IsCompact (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞) -- see Note [lower instance priority] /-- A regular measure is weakly regular in an R₁ space. -/ instance (priority := 100) Regular.weaklyRegular [R1Space α] [Regular μ] : WeaklyRegular μ where innerRegular := fun _U hU r hr ↦ let ⟨K, KU, K_comp, hK⟩ := Regular.innerRegular hU r hr ⟨closure K, K_comp.closure_subset_of_isOpen hU KU, isClosed_closure, hK.trans_le (measure_mono subset_closure)⟩ #align measure_theory.measure.regular.weakly_regular MeasureTheory.Measure.Regular.weaklyRegular namespace OuterRegular instance zero : OuterRegular (0 : Measure α) := ⟨fun A _ _r hr => ⟨univ, subset_univ A, isOpen_univ, hr⟩⟩ #align measure_theory.measure.outer_regular.zero MeasureTheory.Measure.OuterRegular.zero /-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with measure less than `r`. -/ theorem _root_.Set.exists_isOpen_lt_of_lt [OuterRegular μ] (A : Set α) (r : ℝ≥0∞) (hr : μ A < r) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r := by rcases OuterRegular.outerRegular (measurableSet_toMeasurable μ A) r (by rwa [measure_toMeasurable]) with ⟨U, hAU, hUo, hU⟩ exact ⟨U, (subset_toMeasurable _ _).trans hAU, hUo, hU⟩ #align set.exists_is_open_lt_of_lt Set.exists_isOpen_lt_of_lt /-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets containing it. -/ theorem _root_.Set.measure_eq_iInf_isOpen (A : Set α) (μ : Measure α) [OuterRegular μ] : μ A = ⨅ (U : Set α) (_ : A ⊆ U) (_ : IsOpen U), μ U := by refine le_antisymm (le_iInf₂ fun s hs => le_iInf fun _ => μ.mono hs) ?_ refine le_of_forall_lt' fun r hr => ?_ simpa only [iInf_lt_iff, exists_prop] using A.exists_isOpen_lt_of_lt r hr #align set.measure_eq_infi_is_open Set.measure_eq_iInf_isOpen theorem _root_.Set.exists_isOpen_lt_add [OuterRegular μ] (A : Set α) (hA : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < μ A + ε := A.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hA hε) #align set.exists_is_open_lt_add Set.exists_isOpen_lt_add theorem _root_.Set.exists_isOpen_le_add (A : Set α) (μ : Measure α) [OuterRegular μ] {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U ≤ μ A + ε := by rcases eq_or_ne (μ A) ∞ with (H | H) · exact ⟨univ, subset_univ _, isOpen_univ, by simp only [H, _root_.top_add, le_top]⟩ · rcases A.exists_isOpen_lt_add H hε with ⟨U, AU, U_open, hU⟩ exact ⟨U, AU, U_open, hU.le⟩ #align set.exists_is_open_le_add Set.exists_isOpen_le_add theorem _root_.MeasurableSet.exists_isOpen_diff_lt [OuterRegular μ] {A : Set α} (hA : MeasurableSet A) (hA' : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < ∞ ∧ μ (U \ A) < ε := by rcases A.exists_isOpen_lt_add hA' hε with ⟨U, hAU, hUo, hU⟩ use U, hAU, hUo, hU.trans_le le_top exact measure_diff_lt_of_lt_add hA hAU hA' hU #align measurable_set.exists_is_open_diff_lt MeasurableSet.exists_isOpen_diff_lt protected theorem map [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β] [BorelSpace β] (f : α ≃ₜ β) (μ : Measure α) [OuterRegular μ] : (Measure.map f μ).OuterRegular := by refine ⟨fun A hA r hr => ?_⟩ rw [map_apply f.measurable hA, ← f.image_symm] at hr rcases Set.exists_isOpen_lt_of_lt _ r hr with ⟨U, hAU, hUo, hU⟩ have : IsOpen (f.symm ⁻¹' U) := hUo.preimage f.symm.continuous refine ⟨f.symm ⁻¹' U, image_subset_iff.1 hAU, this, ?_⟩ rwa [map_apply f.measurable this.measurableSet, f.preimage_symm, f.preimage_image] #align measure_theory.measure.outer_regular.map MeasureTheory.Measure.OuterRegular.map protected theorem smul (μ : Measure α) [OuterRegular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) : (x • μ).OuterRegular := by rcases eq_or_ne x 0 with (rfl | h0) · rw [zero_smul] exact OuterRegular.zero · refine ⟨fun A _ r hr => ?_⟩ rw [smul_apply, A.measure_eq_iInf_isOpen, smul_eq_mul] at hr simpa only [ENNReal.mul_iInf_of_ne h0 hx, gt_iff_lt, iInf_lt_iff, exists_prop] using hr #align measure_theory.measure.outer_regular.smul MeasureTheory.Measure.OuterRegular.smul instance smul_nnreal (μ : Measure α) [OuterRegular μ] (c : ℝ≥0) : OuterRegular (c • μ) := OuterRegular.smul μ coe_ne_top /-- If the restrictions of a measure to countably many open sets covering the space are outer regular, then the measure itself is outer regular. -/ lemma of_restrict [OpensMeasurableSpace α] {μ : Measure α} {s : ℕ → Set α} (h : ∀ n, OuterRegular (μ.restrict (s n))) (h' : ∀ n, IsOpen (s n)) (h'' : univ ⊆ ⋃ n, s n) : OuterRegular μ := by refine ⟨fun A hA r hr => ?_⟩ have HA : μ A < ∞ := lt_of_lt_of_le hr le_top have hm : ∀ n, MeasurableSet (s n) := fun n => (h' n).measurableSet -- Note that `A = ⋃ n, A ∩ disjointed s n`. We replace `A` with this sequence. obtain ⟨A, hAm, hAs, hAd, rfl⟩ : ∃ A' : ℕ → Set α, (∀ n, MeasurableSet (A' n)) ∧ (∀ n, A' n ⊆ s n) ∧ Pairwise (Disjoint on A') ∧ A = ⋃ n, A' n := by refine ⟨fun n => A ∩ disjointed s n, fun n => hA.inter (MeasurableSet.disjointed hm _), fun n => inter_subset_right.trans (disjointed_subset _ _), (disjoint_disjointed s).mono fun k l hkl => hkl.mono inf_le_right inf_le_right, ?_⟩ rw [← inter_iUnion, iUnion_disjointed, univ_subset_iff.mp h'', inter_univ] rcases ENNReal.exists_pos_sum_of_countable' (tsub_pos_iff_lt.2 hr).ne' ℕ with ⟨δ, δ0, hδε⟩ rw [lt_tsub_iff_right, add_comm] at hδε have : ∀ n, ∃ U ⊇ A n, IsOpen U ∧ μ U < μ (A n) + δ n := by intro n have H₁ : ∀ t, μ.restrict (s n) t = μ (t ∩ s n) := fun t => restrict_apply' (hm n) have Ht : μ.restrict (s n) (A n) ≠ ∞ := by rw [H₁] exact ((measure_mono (inter_subset_left.trans (subset_iUnion A n))).trans_lt HA).ne rcases (A n).exists_isOpen_lt_add Ht (δ0 n).ne' with ⟨U, hAU, hUo, hU⟩ rw [H₁, H₁, inter_eq_self_of_subset_left (hAs _)] at hU exact ⟨U ∩ s n, subset_inter hAU (hAs _), hUo.inter (h' n), hU⟩ choose U hAU hUo hU using this refine ⟨⋃ n, U n, iUnion_mono hAU, isOpen_iUnion hUo, ?_⟩ calc μ (⋃ n, U n) ≤ ∑' n, μ (U n) := measure_iUnion_le _ _ ≤ ∑' n, (μ (A n) + δ n) := ENNReal.tsum_le_tsum fun n => (hU n).le _ = ∑' n, μ (A n) + ∑' n, δ n := ENNReal.tsum_add _ = μ (⋃ n, A n) + ∑' n, δ n := (congr_arg₂ (· + ·) (measure_iUnion hAd hAm).symm rfl) _ < r := hδε /-- See also `IsCompact.measure_closure` for a version that assumes the `σ`-algebra to be the Borel `σ`-algebra but makes no assumptions on `μ`. -/ lemma measure_closure_eq_of_isCompact [R1Space α] [OuterRegular μ] {k : Set α} (hk : IsCompact k) : μ (closure k) = μ k := by apply le_antisymm ?_ (measure_mono subset_closure) simp only [measure_eq_iInf_isOpen k, le_iInf_iff] intro u ku u_open exact measure_mono (hk.closure_subset_of_isOpen u_open ku) end OuterRegular /-- If a measure `μ` admits finite spanning open sets such that the restriction of `μ` to each set is outer regular, then the original measure is outer regular as well. -/ protected theorem FiniteSpanningSetsIn.outerRegular [OpensMeasurableSpace α] {μ : Measure α} (s : μ.FiniteSpanningSetsIn { U | IsOpen U ∧ OuterRegular (μ.restrict U) }) : OuterRegular μ := OuterRegular.of_restrict (s := fun n ↦ s.set n) (fun n ↦ (s.set_mem n).2) (fun n ↦ (s.set_mem n).1) s.spanning.symm.subset #align measure_theory.measure.finite_spanning_sets_in.outer_regular MeasureTheory.Measure.FiniteSpanningSetsIn.outerRegular namespace InnerRegularWRT variable {p q : Set α → Prop} {U s : Set α} {ε r : ℝ≥0∞} /-- If a measure is inner regular (using closed or compact sets) for open sets, then every measurable set of finite measure can be approximated by a (closed or compact) subset. -/ theorem measurableSet_of_isOpen [OuterRegular μ] (H : InnerRegularWRT μ p IsOpen) (hd : ∀ ⦃s U⦄, p s → IsOpen U → p (s \ U)) : InnerRegularWRT μ p fun s => MeasurableSet s ∧ μ s ≠ ∞ := by rintro s ⟨hs, hμs⟩ r hr have h0 : p ∅ := by have : 0 < μ univ := (bot_le.trans_lt hr).trans_le (measure_mono (subset_univ _)) obtain ⟨K, -, hK, -⟩ : ∃ K, K ⊆ univ ∧ p K ∧ 0 < μ K := H isOpen_univ _ this simpa using hd hK isOpen_univ obtain ⟨ε, hε, hεs, rfl⟩ : ∃ ε ≠ 0, ε + ε ≤ μ s ∧ r = μ s - (ε + ε) := by use (μ s - r) / 2 simp [*, hr.le, ENNReal.add_halves, ENNReal.sub_sub_cancel, le_add_right, tsub_eq_zero_iff_le] rcases hs.exists_isOpen_diff_lt hμs hε with ⟨U, hsU, hUo, hUt, hμU⟩ rcases (U \ s).exists_isOpen_lt_of_lt _ hμU with ⟨U', hsU', hU'o, hμU'⟩ replace hsU' := diff_subset_comm.1 hsU' rcases H.exists_subset_lt_add h0 hUo hUt.ne hε with ⟨K, hKU, hKc, hKr⟩ refine ⟨K \ U', fun x hx => hsU' ⟨hKU hx.1, hx.2⟩, hd hKc hU'o, ENNReal.sub_lt_of_lt_add hεs ?_⟩ calc μ s ≤ μ U := μ.mono hsU _ < μ K + ε := hKr _ ≤ μ (K \ U') + μ U' + ε := add_le_add_right (tsub_le_iff_right.1 le_measure_diff) _ _ ≤ μ (K \ U') + ε + ε := by gcongr _ = μ (K \ U') + (ε + ε) := add_assoc _ _ _ #align measure_theory.measure.inner_regular.measurable_set_of_open MeasureTheory.Measure.InnerRegularWRT.measurableSet_of_isOpen open Finset in /-- In a finite measure space, assume that any open set can be approximated from inside by closed sets. Then the measure is weakly regular. -/ theorem weaklyRegular_of_finite [BorelSpace α] (μ : Measure α) [IsFiniteMeasure μ] (H : InnerRegularWRT μ IsClosed IsOpen) : WeaklyRegular μ := by have hfin : ∀ {s}, μ s ≠ ∞ := @(measure_ne_top μ) suffices ∀ s, MeasurableSet s → ∀ ε, ε ≠ 0 → ∃ F, F ⊆ s ∧ ∃ U, U ⊇ s ∧ IsClosed F ∧ IsOpen U ∧ μ s ≤ μ F + ε ∧ μ U ≤ μ s + ε by refine { outerRegular := fun s hs r hr => ?_ innerRegular := H } rcases exists_between hr with ⟨r', hsr', hr'r⟩ rcases this s hs _ (tsub_pos_iff_lt.2 hsr').ne' with ⟨-, -, U, hsU, -, hUo, -, H⟩ refine ⟨U, hsU, hUo, ?_⟩ rw [add_tsub_cancel_of_le hsr'.le] at H exact H.trans_lt hr'r apply MeasurableSet.induction_on_open /- The proof is by measurable induction: we should check that the property is true for the empty set, for open sets, and is stable by taking the complement and by taking countable disjoint unions. The point of the property we are proving is that it is stable by taking complements (exchanging the roles of closed and open sets and thanks to the finiteness of the measure). -/ -- check for open set · intro U hU ε hε rcases H.exists_subset_lt_add isClosed_empty hU hfin hε with ⟨F, hsF, hFc, hF⟩ exact ⟨F, hsF, U, Subset.rfl, hFc, hU, hF.le, le_self_add⟩ -- check for complements · rintro s hs H ε hε rcases H ε hε with ⟨F, hFs, U, hsU, hFc, hUo, hF, hU⟩ refine ⟨Uᶜ, compl_subset_compl.2 hsU, Fᶜ, compl_subset_compl.2 hFs, hUo.isClosed_compl, hFc.isOpen_compl, ?_⟩ simp only [measure_compl_le_add_iff, *, hUo.measurableSet, hFc.measurableSet, true_and_iff] -- check for disjoint unions · intro s hsd hsm H ε ε0 have ε0' : ε / 2 ≠ 0 := (ENNReal.half_pos ε0).ne' rcases ENNReal.exists_pos_sum_of_countable' ε0' ℕ with ⟨δ, δ0, hδε⟩ choose F hFs U hsU hFc hUo hF hU using fun n => H n (δ n) (δ0 n).ne' -- the approximating closed set is constructed by considering finitely many sets `s i`, which -- cover all the measure up to `ε/2`, approximating each of these by a closed set `F i`, and -- taking the union of these (finitely many) `F i`. have : Tendsto (fun t => (∑ k ∈ t, μ (s k)) + ε / 2) atTop (𝓝 <| μ (⋃ n, s n) + ε / 2) := by rw [measure_iUnion hsd hsm] exact Tendsto.add ENNReal.summable.hasSum tendsto_const_nhds rcases (this.eventually <| lt_mem_nhds <| ENNReal.lt_add_right hfin ε0').exists with ⟨t, ht⟩ -- the approximating open set is constructed by taking for each `s n` an approximating open set -- `U n` with measure at most `μ (s n) + δ n` for a summable `δ`, and taking the union of these. refine ⟨⋃ k ∈ t, F k, iUnion_mono fun k => iUnion_subset fun _ => hFs _, ⋃ n, U n, iUnion_mono hsU, isClosed_biUnion_finset fun k _ => hFc k, isOpen_iUnion hUo, ht.le.trans ?_, ?_⟩ · calc (∑ k ∈ t, μ (s k)) + ε / 2 ≤ ((∑ k ∈ t, μ (F k)) + ∑ k ∈ t, δ k) + ε / 2 := by rw [← sum_add_distrib] gcongr apply hF _ ≤ (∑ k ∈ t, μ (F k)) + ε / 2 + ε / 2 := by gcongr exact (ENNReal.sum_le_tsum _).trans hδε.le _ = μ (⋃ k ∈ t, F k) + ε := by rw [measure_biUnion_finset, add_assoc, ENNReal.add_halves] exacts [fun k _ n _ hkn => (hsd hkn).mono (hFs k) (hFs n), fun k _ => (hFc k).measurableSet] · calc μ (⋃ n, U n) ≤ ∑' n, μ (U n) := measure_iUnion_le _ _ ≤ ∑' n, (μ (s n) + δ n) := ENNReal.tsum_le_tsum hU _ = μ (⋃ n, s n) + ∑' n, δ n := by rw [measure_iUnion hsd hsm, ENNReal.tsum_add] _ ≤ μ (⋃ n, s n) + ε := add_le_add_left (hδε.le.trans ENNReal.half_le_self) _ #align measure_theory.measure.inner_regular.weakly_regular_of_finite MeasureTheory.Measure.InnerRegularWRT.weaklyRegular_of_finite /-- If the restrictions of a measure to a monotone sequence of sets covering the space are inner regular for some property `p` and all measurable sets, then the measure itself is inner regular. -/ lemma of_restrict {μ : Measure α} {s : ℕ → Set α} (h : ∀ n, InnerRegularWRT (μ.restrict (s n)) p MeasurableSet) (hs : univ ⊆ ⋃ n, s n) (hmono : Monotone s) : InnerRegularWRT μ p MeasurableSet := by intro F hF r hr have hBU : ⋃ n, F ∩ s n = F := by rw [← inter_iUnion, univ_subset_iff.mp hs, inter_univ] have : μ F = ⨆ n, μ (F ∩ s n) := by rw [← measure_iUnion_eq_iSup, hBU] exact Monotone.directed_le fun m n h ↦ inter_subset_inter_right _ (hmono h) rw [this] at hr rcases lt_iSup_iff.1 hr with ⟨n, hn⟩ rw [← restrict_apply hF] at hn rcases h n hF _ hn with ⟨K, KF, hKp, hK⟩ exact ⟨K, KF, hKp, hK.trans_le (restrict_apply_le _ _)⟩ /-- In a metrizable space (or even a pseudo metrizable space), an open set can be approximated from inside by closed sets. -/ theorem of_pseudoMetrizableSpace {X : Type*} [TopologicalSpace X] [PseudoMetrizableSpace X] [MeasurableSpace X] (μ : Measure X) : InnerRegularWRT μ IsClosed IsOpen := by let A : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X intro U hU r hr rcases hU.exists_iUnion_isClosed with ⟨F, F_closed, -, rfl, F_mono⟩ rw [measure_iUnion_eq_iSup F_mono.directed_le] at hr rcases lt_iSup_iff.1 hr with ⟨n, hn⟩ exact ⟨F n, subset_iUnion _ _, F_closed n, hn⟩ #align measure_theory.measure.inner_regular.of_pseudo_emetric_space MeasureTheory.Measure.InnerRegularWRT.of_pseudoMetrizableSpace /-- In a `σ`-compact space, any closed set can be approximated by a compact subset. -/ theorem isCompact_isClosed {X : Type*} [TopologicalSpace X] [SigmaCompactSpace X] [MeasurableSpace X] (μ : Measure X) : InnerRegularWRT μ IsCompact IsClosed := by intro F hF r hr set B : ℕ → Set X := compactCovering X have hBc : ∀ n, IsCompact (F ∩ B n) := fun n => (isCompact_compactCovering X n).inter_left hF have hBU : ⋃ n, F ∩ B n = F := by rw [← inter_iUnion, iUnion_compactCovering, Set.inter_univ] have : μ F = ⨆ n, μ (F ∩ B n) := by rw [← measure_iUnion_eq_iSup, hBU] exact Monotone.directed_le fun m n h => inter_subset_inter_right _ (compactCovering_subset _ h) rw [this] at hr rcases lt_iSup_iff.1 hr with ⟨n, hn⟩ exact ⟨_, inter_subset_left, hBc n, hn⟩ #align measure_theory.measure.inner_regular.is_compact_is_closed MeasureTheory.Measure.InnerRegularWRT.isCompact_isClosed /-- If `μ` is inner regular for measurable finite measure sets with respect to some class of sets, then its restriction to any set is also inner regular for measurable finite measure sets, with respect to the same class of sets. -/ lemma restrict (h : InnerRegularWRT μ p (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞)) (A : Set α) : InnerRegularWRT (μ.restrict A) p (fun s ↦ MeasurableSet s ∧ μ.restrict A s ≠ ∞) := by rintro s ⟨s_meas, hs⟩ r hr rw [restrict_apply s_meas] at hs obtain ⟨K, K_subs, pK, rK⟩ : ∃ K, K ⊆ (toMeasurable μ (s ∩ A)) ∩ s ∧ p K ∧ r < μ K := by have : r < μ ((toMeasurable μ (s ∩ A)) ∩ s) := by apply hr.trans_le rw [restrict_apply s_meas] exact measure_mono <| subset_inter (subset_toMeasurable μ (s ∩ A)) inter_subset_left refine h ⟨(measurableSet_toMeasurable _ _).inter s_meas, ?_⟩ _ this apply (lt_of_le_of_lt _ hs.lt_top).ne rw [← measure_toMeasurable (s ∩ A)] exact measure_mono inter_subset_left refine ⟨K, K_subs.trans inter_subset_right, pK, ?_⟩ calc r < μ K := rK _ = μ.restrict (toMeasurable μ (s ∩ A)) K := by rw [restrict_apply' (measurableSet_toMeasurable μ (s ∩ A))] congr apply (inter_eq_left.2 ?_).symm exact K_subs.trans inter_subset_left _ = μ.restrict (s ∩ A) K := by rwa [restrict_toMeasurable] _ ≤ μ.restrict A K := Measure.le_iff'.1 (restrict_mono inter_subset_right le_rfl) K /-- If `μ` is inner regular for measurable finite measure sets with respect to some class of sets, then its restriction to any finite measure set is also inner regular for measurable sets with respect to the same class of sets. -/ lemma restrict_of_measure_ne_top (h : InnerRegularWRT μ p (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞)) {A : Set α} (hA : μ A ≠ ∞) : InnerRegularWRT (μ.restrict A) p (fun s ↦ MeasurableSet s) := by have : Fact (μ A < ∞) := ⟨hA.lt_top⟩ exact (restrict h A).trans (of_imp (fun s hs ↦ ⟨hs, measure_ne_top _ _⟩)) /-- Given a σ-finite measure, any measurable set can be approximated from inside by a measurable set of finite measure. -/ lemma of_sigmaFinite [SigmaFinite μ] : InnerRegularWRT μ (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞) (fun s ↦ MeasurableSet s) := by intro s hs r hr set B : ℕ → Set α := spanningSets μ have hBU : ⋃ n, s ∩ B n = s := by rw [← inter_iUnion, iUnion_spanningSets, inter_univ] have : μ s = ⨆ n, μ (s ∩ B n) := by rw [← measure_iUnion_eq_iSup, hBU] exact Monotone.directed_le fun m n h => inter_subset_inter_right _ (monotone_spanningSets μ h) rw [this] at hr rcases lt_iSup_iff.1 hr with ⟨n, hn⟩ refine ⟨s ∩ B n, inter_subset_left, ⟨hs.inter (measurable_spanningSets μ n), ?_⟩, hn⟩ exact ((measure_mono inter_subset_right).trans_lt (measure_spanningSets_lt_top μ n)).ne end InnerRegularWRT namespace InnerRegular variable {U : Set α} {ε : ℝ≥0∞} /-- The measure of a measurable set is the supremum of the measures of compact sets it contains. -/ theorem _root_.MeasurableSet.measure_eq_iSup_isCompact ⦃U : Set α⦄ (hU : MeasurableSet U) (μ : Measure α) [InnerRegular μ] : μ U = ⨆ (K : Set α) (_ : K ⊆ U) (_ : IsCompact K), μ K := InnerRegular.innerRegular.measure_eq_iSup hU instance zero : InnerRegular (0 : Measure α) := ⟨fun _ _ _r hr => ⟨∅, empty_subset _, isCompact_empty, hr⟩⟩ instance smul [h : InnerRegular μ] (c : ℝ≥0∞) : InnerRegular (c • μ) := ⟨InnerRegularWRT.smul h.innerRegular c⟩ instance smul_nnreal [InnerRegular μ] (c : ℝ≥0) : InnerRegular (c • μ) := smul (c : ℝ≥0∞) instance (priority := 100) [InnerRegular μ] : InnerRegularCompactLTTop μ := ⟨fun _s hs r hr ↦ InnerRegular.innerRegular hs.1 r hr⟩ lemma innerRegularWRT_isClosed_isOpen [R1Space α] [OpensMeasurableSpace α] [h : InnerRegular μ] : InnerRegularWRT μ IsClosed IsOpen := by intro U hU r hr rcases h.innerRegular hU.measurableSet r hr with ⟨K, KU, K_comp, hK⟩ exact ⟨closure K, K_comp.closure_subset_of_isOpen hU KU, isClosed_closure, hK.trans_le (measure_mono subset_closure)⟩ theorem exists_compact_not_null [InnerRegular μ] : (∃ K, IsCompact K ∧ μ K ≠ 0) ↔ μ ≠ 0 := by simp_rw [Ne, ← measure_univ_eq_zero, MeasurableSet.univ.measure_eq_iSup_isCompact, ENNReal.iSup_eq_zero, not_forall, exists_prop, subset_univ, true_and_iff] /-- If `μ` is inner regular, then any measurable set can be approximated by a compact subset. See also `MeasurableSet.exists_isCompact_lt_add_of_ne_top`. -/ theorem _root_.MeasurableSet.exists_lt_isCompact [InnerRegular μ] ⦃A : Set α⦄ (hA : MeasurableSet A) {r : ℝ≥0∞} (hr : r < μ A) : ∃ K, K ⊆ A ∧ IsCompact K ∧ r < μ K := InnerRegular.innerRegular hA _ hr protected theorem map_of_continuous [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β] [BorelSpace β] [h : InnerRegular μ] {f : α → β} (hf : Continuous f) : InnerRegular (Measure.map f μ) := ⟨InnerRegularWRT.map h.innerRegular hf.aemeasurable (fun _s hs ↦ hf.measurable hs) (fun _K hK ↦ hK.image hf) (fun _s hs ↦ hs)⟩ protected theorem map [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β] [BorelSpace β] [InnerRegular μ] (f : α ≃ₜ β) : (Measure.map f μ).InnerRegular := InnerRegular.map_of_continuous f.continuous protected theorem map_iff [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β] [BorelSpace β] (f : α ≃ₜ β) : InnerRegular (Measure.map f μ) ↔ InnerRegular μ := by refine ⟨fun h ↦ ?_, fun h ↦ h.map f⟩ convert h.map f.symm rw [map_map f.symm.continuous.measurable f.continuous.measurable] simp end InnerRegular namespace InnerRegularCompactLTTop /-- If `μ` is inner regular for finite measure sets with respect to compact sets, then any measurable set of finite measure can be approximated by a compact subset. See also `MeasurableSet.exists_lt_isCompact_of_ne_top`. -/ theorem _root_.MeasurableSet.exists_isCompact_lt_add [InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ K, K ⊆ A ∧ IsCompact K ∧ μ A < μ K + ε := InnerRegularCompactLTTop.innerRegular.exists_subset_lt_add isCompact_empty ⟨hA, h'A⟩ h'A hε #align measurable_set.exists_is_compact_lt_add MeasurableSet.exists_isCompact_lt_add /-- If `μ` is inner regular for finite measure sets with respect to compact sets, then any measurable set of finite measure can be approximated by a compact subset. See also `MeasurableSet.exists_isCompact_lt_add` and `MeasurableSet.exists_lt_isCompact_of_ne_top`. -/ theorem _root_.MeasurableSet.exists_isCompact_diff_lt [OpensMeasurableSpace α] [T2Space α] [InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ K, K ⊆ A ∧ IsCompact K ∧ μ (A \ K) < ε := by rcases hA.exists_isCompact_lt_add h'A hε with ⟨K, hKA, hKc, hK⟩ exact ⟨K, hKA, hKc, measure_diff_lt_of_lt_add hKc.measurableSet hKA (ne_top_of_le_ne_top h'A <| measure_mono hKA) hK⟩ #align measurable_set.exists_is_compact_diff_lt MeasurableSet.exists_isCompact_diff_lt /-- If `μ` is inner regular for finite measure sets with respect to compact sets, then any measurable set of finite measure can be approximated by a compact subset. See also `MeasurableSet.exists_isCompact_lt_add`. -/ theorem _root_.MeasurableSet.exists_lt_isCompact_of_ne_top [InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) : ∃ K, K ⊆ A ∧ IsCompact K ∧ r < μ K := InnerRegularCompactLTTop.innerRegular ⟨hA, h'A⟩ _ hr #align measurable_set.exists_lt_is_compact_of_ne_top MeasurableSet.exists_lt_isCompact_of_ne_top /-- If `μ` is inner regular for finite measure sets with respect to compact sets, any measurable set of finite mass can be approximated from inside by compact sets. -/ theorem _root_.MeasurableSet.measure_eq_iSup_isCompact_of_ne_top [InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) : μ A = ⨆ (K) (_ : K ⊆ A) (_ : IsCompact K), μ K := InnerRegularCompactLTTop.innerRegular.measure_eq_iSup ⟨hA, h'A⟩ #align measurable_set.measure_eq_supr_is_compact_of_ne_top MeasurableSet.measure_eq_iSup_isCompact_of_ne_top /-- If `μ` is inner regular for finite measure sets with respect to compact sets, then its restriction to any set also is. -/ instance restrict [h : InnerRegularCompactLTTop μ] (A : Set α) : InnerRegularCompactLTTop (μ.restrict A) := ⟨InnerRegularWRT.restrict h.innerRegular A⟩ instance (priority := 50) [h : InnerRegularCompactLTTop μ] [IsFiniteMeasure μ] : InnerRegular μ := by constructor convert h.innerRegular with s simp [measure_ne_top μ s] instance (priority := 50) [BorelSpace α] [R1Space α] [InnerRegularCompactLTTop μ] [IsFiniteMeasure μ] : WeaklyRegular μ := InnerRegular.innerRegularWRT_isClosed_isOpen.weaklyRegular_of_finite _ instance (priority := 50) [BorelSpace α] [R1Space α] [h : InnerRegularCompactLTTop μ] [IsFiniteMeasure μ] : Regular μ where innerRegular := InnerRegularWRT.trans h.innerRegular <| InnerRegularWRT.of_imp (fun U hU ↦ ⟨hU.measurableSet, measure_ne_top μ U⟩) protected lemma _root_.IsCompact.exists_isOpen_lt_of_lt [InnerRegularCompactLTTop μ] [IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α] {K : Set α} (hK : IsCompact K) (r : ℝ≥0∞) (hr : μ K < r) : ∃ U, K ⊆ U ∧ IsOpen U ∧ μ U < r := by rcases hK.exists_open_superset_measure_lt_top μ with ⟨V, hKV, hVo, hμV⟩ have := Fact.mk hμV obtain ⟨U, hKU, hUo, hμU⟩ : ∃ U, K ⊆ U ∧ IsOpen U ∧ μ.restrict V U < r := exists_isOpen_lt_of_lt K r <| (restrict_apply_le _ _).trans_lt hr refine ⟨U ∩ V, subset_inter hKU hKV, hUo.inter hVo, ?_⟩ rwa [restrict_apply hUo.measurableSet] at hμU /-- If `μ` is inner regular for finite measure sets with respect to compact sets and is locally finite in an R₁ space, then any compact set can be approximated from outside by open sets. -/ protected lemma _root_.IsCompact.measure_eq_iInf_isOpen [InnerRegularCompactLTTop μ] [IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α] {K : Set α} (hK : IsCompact K) : μ K = ⨅ (U : Set α) (_ : K ⊆ U) (_ : IsOpen U), μ U := by apply le_antisymm · simp only [le_iInf_iff] exact fun U KU _ ↦ measure_mono KU · apply le_of_forall_lt' simpa only [iInf_lt_iff, exists_prop, exists_and_left] using hK.exists_isOpen_lt_of_lt @[deprecated (since := "2024-01-28")] alias _root_.IsCompact.measure_eq_infi_isOpen := IsCompact.measure_eq_iInf_isOpen protected theorem _root_.IsCompact.exists_isOpen_lt_add [InnerRegularCompactLTTop μ] [IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α] {K : Set α} (hK : IsCompact K) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ U, K ⊆ U ∧ IsOpen U ∧ μ U < μ K + ε := hK.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hK.measure_lt_top.ne hε) instance smul [h : InnerRegularCompactLTTop μ] (c : ℝ≥0∞) : InnerRegularCompactLTTop (c • μ) := by by_cases hc : c = 0 · simp only [hc, zero_smul] infer_instance by_cases h'c : c = ∞ · constructor intro s hs r hr simp only [h'c, smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply, smul_eq_mul] at hr by_cases h's : μ s = 0 · simp [h's] at hr · simp [h'c, ENNReal.mul_eq_top, h's] at hs · constructor convert InnerRegularWRT.smul h.innerRegular c using 2 with s have : (c • μ) s ≠ ∞ ↔ μ s ≠ ∞ := by simp [not_iff_not, ENNReal.mul_eq_top, hc, h'c] simp only [this] instance smul_nnreal [InnerRegularCompactLTTop μ] (c : ℝ≥0) : InnerRegularCompactLTTop (c • μ) := inferInstanceAs (InnerRegularCompactLTTop ((c : ℝ≥0∞) • μ)) instance (priority := 80) [InnerRegularCompactLTTop μ] [SigmaFinite μ] : InnerRegular μ := ⟨InnerRegularCompactLTTop.innerRegular.trans InnerRegularWRT.of_sigmaFinite⟩ protected theorem map_of_continuous [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β] [BorelSpace β] [h : InnerRegularCompactLTTop μ] {f : α → β} (hf : Continuous f) : InnerRegularCompactLTTop (Measure.map f μ) := by constructor refine InnerRegularWRT.map h.innerRegular hf.aemeasurable ?_ (fun K hK ↦ hK.image hf) ?_ · rintro s ⟨hs, h's⟩ exact ⟨hf.measurable hs, by rwa [map_apply hf.measurable hs] at h's⟩ · rintro s ⟨hs, -⟩ exact hs end InnerRegularCompactLTTop -- Generalized and moved to another file #align measure_theory.measure.regular.sigma_finite MeasureTheory.SigmaFinite.of_isFiniteMeasureOnCompacts namespace WeaklyRegular instance zero : WeaklyRegular (0 : Measure α) := ⟨fun _ _ _r hr => ⟨∅, empty_subset _, isClosed_empty, hr⟩⟩ /-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/ theorem _root_.IsOpen.exists_lt_isClosed [WeaklyRegular μ] ⦃U : Set α⦄ (hU : IsOpen U) {r : ℝ≥0∞} (hr : r < μ U) : ∃ F, F ⊆ U ∧ IsClosed F ∧ r < μ F := WeaklyRegular.innerRegular hU r hr #align is_open.exists_lt_is_closed IsOpen.exists_lt_isClosed /-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/ theorem _root_.IsOpen.measure_eq_iSup_isClosed ⦃U : Set α⦄ (hU : IsOpen U) (μ : Measure α) [WeaklyRegular μ] : μ U = ⨆ (F) (_ : F ⊆ U) (_ : IsClosed F), μ F := WeaklyRegular.innerRegular.measure_eq_iSup hU #align is_open.measure_eq_supr_is_closed IsOpen.measure_eq_iSup_isClosed theorem innerRegular_measurable [WeaklyRegular μ] : InnerRegularWRT μ IsClosed fun s => MeasurableSet s ∧ μ s ≠ ∞ := WeaklyRegular.innerRegular.measurableSet_of_isOpen (fun _ _ h₁ h₂ ↦ h₁.inter h₂.isClosed_compl) #align measure_theory.measure.weakly_regular.inner_regular_measurable MeasureTheory.Measure.WeaklyRegular.innerRegular_measurable /-- If `s` is a measurable set, a weakly regular measure `μ` is finite on `s`, and `ε` is a positive number, then there exist a closed set `K ⊆ s` such that `μ s < μ K + ε`. -/ theorem _root_.MeasurableSet.exists_isClosed_lt_add [WeaklyRegular μ] {s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ K, K ⊆ s ∧ IsClosed K ∧ μ s < μ K + ε := innerRegular_measurable.exists_subset_lt_add isClosed_empty ⟨hs, hμs⟩ hμs hε #align measurable_set.exists_is_closed_lt_add MeasurableSet.exists_isClosed_lt_add
Mathlib/MeasureTheory/Measure/Regular.lean
877
882
theorem _root_.MeasurableSet.exists_isClosed_diff_lt [OpensMeasurableSpace α] [WeaklyRegular μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ F, F ⊆ A ∧ IsClosed F ∧ μ (A \ F) < ε := by
rcases hA.exists_isClosed_lt_add h'A hε with ⟨F, hFA, hFc, hF⟩ exact ⟨F, hFA, hFc, measure_diff_lt_of_lt_add hFc.measurableSet hFA (ne_top_of_le_ne_top h'A <| measure_mono hFA) hF⟩
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Algebra.DirectSum.Module import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.Convex.Uniform import Mathlib.Analysis.NormedSpace.Completion import Mathlib.Analysis.NormedSpace.BoundedLinearMaps #align_import analysis.inner_product_space.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Inner product space This file defines inner product spaces and proves the basic properties. We do not formally define Hilbert spaces, but they can be obtained using the set of assumptions `[NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E]`. An inner product space is a vector space endowed with an inner product. It generalizes the notion of dot product in `ℝ^n` and provides the means of defining the length of a vector and the angle between two vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero. We define both the real and complex cases at the same time using the `RCLike` typeclass. This file proves general results on inner product spaces. For the specific construction of an inner product structure on `n → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `EuclideanSpace` in `Analysis.InnerProductSpace.PiL2`. ## Main results - We define the class `InnerProductSpace 𝕜 E` extending `NormedSpace 𝕜 E` with a number of basic properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ` or `ℂ`, through the `RCLike` typeclass. - We show that the inner product is continuous, `continuous_inner`, and bundle it as the continuous sesquilinear map `innerSL` (see also `innerₛₗ` for the non-continuous version). - We define `Orthonormal`, a predicate on a function `v : ι → E`, and prove the existence of a maximal orthonormal set, `exists_maximal_orthonormal`. Bessel's inequality, `Orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`, the sum of the norm-squares of the inner products `⟪v i, x⟫` is no more than the norm-square of `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file `Analysis.InnerProductSpace.projection`. ## Notation We globally denote the real and complex inner products by `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively. We also provide two notation namespaces: `RealInnerProductSpace`, `ComplexInnerProductSpace`, which respectively introduce the plain notation `⟪·, ·⟫` for the real and complex inner product. ## Implementation notes We choose the convention that inner products are conjugate linear in the first argument and linear in the second. ## Tags inner product space, Hilbert space, norm ## References * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open Topology ComplexConjugate open LinearMap (BilinForm) variable {𝕜 E F : Type*} [RCLike 𝕜] /-- Syntactic typeclass for types endowed with an inner product -/ class Inner (𝕜 E : Type*) where /-- The inner product function. -/ inner : E → E → 𝕜 #align has_inner Inner export Inner (inner) /-- The inner product with values in `𝕜`. -/ notation3:max "⟪" x ", " y "⟫_" 𝕜:max => @inner 𝕜 _ _ x y section Notations /-- The inner product with values in `ℝ`. -/ scoped[RealInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℝ _ _ x y /-- The inner product with values in `ℂ`. -/ scoped[ComplexInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℂ _ _ x y end Notations /-- An inner product space is a vector space with an additional operation called inner product. The norm could be derived from the inner product, instead we require the existence of a norm and the fact that `‖x‖^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product spaces. To construct a norm from an inner product, see `InnerProductSpace.ofCore`. -/ class InnerProductSpace (𝕜 : Type*) (E : Type*) [RCLike 𝕜] [NormedAddCommGroup E] extends NormedSpace 𝕜 E, Inner 𝕜 E where /-- The inner product induces the norm. -/ norm_sq_eq_inner : ∀ x : E, ‖x‖ ^ 2 = re (inner x x) /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space InnerProductSpace /-! ### Constructing a normed space structure from an inner product In the definition of an inner product space, we require the existence of a norm, which is equal (but maybe not defeq) to the square root of the scalar product. This makes it possible to put an inner product space structure on spaces with a preexisting norm (for instance `ℝ`), with good properties. However, sometimes, one would like to define the norm starting only from a well-behaved scalar product. This is what we implement in this paragraph, starting from a structure `InnerProductSpace.Core` stating that we have a nice scalar product. Our goal here is not to develop a whole theory with all the supporting API, as this will be done below for `InnerProductSpace`. Instead, we implement the bare minimum to go as directly as possible to the construction of the norm and the proof of the triangular inequality. Warning: Do not use this `Core` structure if the space you are interested in already has a norm instance defined on it, otherwise this will create a second non-defeq norm instance! -/ /-- A structure requiring that a scalar product is positive definite and symmetric, from which one can construct an `InnerProductSpace` instance in `InnerProductSpace.ofCore`. -/ -- @[nolint HasNonemptyInstance] porting note: I don't think we have this linter anymore structure InnerProductSpace.Core (𝕜 : Type*) (F : Type*) [RCLike 𝕜] [AddCommGroup F] [Module 𝕜 F] extends Inner 𝕜 F where /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is positive (semi)definite. -/ nonneg_re : ∀ x, 0 ≤ re (inner x x) /-- The inner product is positive definite. -/ definite : ∀ x, inner x x = 0 → x = 0 /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space.core InnerProductSpace.Core /- We set `InnerProductSpace.Core` to be a class as we will use it as such in the construction of the normed space structure that it produces. However, all the instances we will use will be local to this proof. -/ attribute [class] InnerProductSpace.Core /-- Define `InnerProductSpace.Core` from `InnerProductSpace`. Defined to reuse lemmas about `InnerProductSpace.Core` for `InnerProductSpace`s. Note that the `Norm` instance provided by `InnerProductSpace.Core.norm` is propositionally but not definitionally equal to the original norm. -/ def InnerProductSpace.toCore [NormedAddCommGroup E] [c : InnerProductSpace 𝕜 E] : InnerProductSpace.Core 𝕜 E := { c with nonneg_re := fun x => by rw [← InnerProductSpace.norm_sq_eq_inner] apply sq_nonneg definite := fun x hx => norm_eq_zero.1 <| pow_eq_zero (n := 2) <| by rw [InnerProductSpace.norm_sq_eq_inner (𝕜 := 𝕜) x, hx, map_zero] } #align inner_product_space.to_core InnerProductSpace.toCore namespace InnerProductSpace.Core variable [AddCommGroup F] [Module 𝕜 F] [c : InnerProductSpace.Core 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 F _ x y local notation "normSqK" => @RCLike.normSq 𝕜 _ local notation "reK" => @RCLike.re 𝕜 _ local notation "ext_iff" => @RCLike.ext_iff 𝕜 _ local postfix:90 "†" => starRingEnd _ /-- Inner product defined by the `InnerProductSpace.Core` structure. We can't reuse `InnerProductSpace.Core.toInner` because it takes `InnerProductSpace.Core` as an explicit argument. -/ def toInner' : Inner 𝕜 F := c.toInner #align inner_product_space.core.to_has_inner' InnerProductSpace.Core.toInner' attribute [local instance] toInner' /-- The norm squared function for `InnerProductSpace.Core` structure. -/ def normSq (x : F) := reK ⟪x, x⟫ #align inner_product_space.core.norm_sq InnerProductSpace.Core.normSq local notation "normSqF" => @normSq 𝕜 F _ _ _ _ theorem inner_conj_symm (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ := c.conj_symm x y #align inner_product_space.core.inner_conj_symm InnerProductSpace.Core.inner_conj_symm theorem inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ := c.nonneg_re _ #align inner_product_space.core.inner_self_nonneg InnerProductSpace.Core.inner_self_nonneg theorem inner_self_im (x : F) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub] simp [inner_conj_symm] #align inner_product_space.core.inner_self_im InnerProductSpace.Core.inner_self_im theorem inner_add_left (x y z : F) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := c.add_left _ _ _ #align inner_product_space.core.inner_add_left InnerProductSpace.Core.inner_add_left theorem inner_add_right (x y z : F) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add]; simp only [inner_conj_symm] #align inner_product_space.core.inner_add_right InnerProductSpace.Core.inner_add_right theorem ofReal_normSq_eq_inner_self (x : F) : (normSqF x : 𝕜) = ⟪x, x⟫ := by rw [ext_iff] exact ⟨by simp only [ofReal_re]; rfl, by simp only [inner_self_im, ofReal_im]⟩ #align inner_product_space.core.coe_norm_sq_eq_inner_self InnerProductSpace.Core.ofReal_normSq_eq_inner_self theorem inner_re_symm (x y : F) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_product_space.core.inner_re_symm InnerProductSpace.Core.inner_re_symm theorem inner_im_symm (x y : F) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_product_space.core.inner_im_symm InnerProductSpace.Core.inner_im_symm theorem inner_smul_left (x y : F) {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := c.smul_left _ _ _ #align inner_product_space.core.inner_smul_left InnerProductSpace.Core.inner_smul_left theorem inner_smul_right (x y : F) {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left]; simp only [conj_conj, inner_conj_symm, RingHom.map_mul] #align inner_product_space.core.inner_smul_right InnerProductSpace.Core.inner_smul_right theorem inner_zero_left (x : F) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : F), inner_smul_left]; simp only [zero_mul, RingHom.map_zero] #align inner_product_space.core.inner_zero_left InnerProductSpace.Core.inner_zero_left theorem inner_zero_right (x : F) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left]; simp only [RingHom.map_zero] #align inner_product_space.core.inner_zero_right InnerProductSpace.Core.inner_zero_right theorem inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 := ⟨c.definite _, by rintro rfl exact inner_zero_left _⟩ #align inner_product_space.core.inner_self_eq_zero InnerProductSpace.Core.inner_self_eq_zero theorem normSq_eq_zero {x : F} : normSqF x = 0 ↔ x = 0 := Iff.trans (by simp only [normSq, ext_iff, map_zero, inner_self_im, eq_self_iff_true, and_true_iff]) (@inner_self_eq_zero 𝕜 _ _ _ _ _ x) #align inner_product_space.core.norm_sq_eq_zero InnerProductSpace.Core.normSq_eq_zero theorem inner_self_ne_zero {x : F} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_product_space.core.inner_self_ne_zero InnerProductSpace.Core.inner_self_ne_zero theorem inner_self_ofReal_re (x : F) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := by norm_num [ext_iff, inner_self_im] set_option linter.uppercaseLean3 false in #align inner_product_space.core.inner_self_re_to_K InnerProductSpace.Core.inner_self_ofReal_re theorem norm_inner_symm (x y : F) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align inner_product_space.core.norm_inner_symm InnerProductSpace.Core.norm_inner_symm theorem inner_neg_left (x y : F) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp #align inner_product_space.core.inner_neg_left InnerProductSpace.Core.inner_neg_left theorem inner_neg_right (x y : F) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] #align inner_product_space.core.inner_neg_right InnerProductSpace.Core.inner_neg_right theorem inner_sub_left (x y z : F) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left, inner_neg_left] #align inner_product_space.core.inner_sub_left InnerProductSpace.Core.inner_sub_left theorem inner_sub_right (x y z : F) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right, inner_neg_right] #align inner_product_space.core.inner_sub_right InnerProductSpace.Core.inner_sub_right theorem inner_mul_symm_re_eq_norm (x y : F) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) #align inner_product_space.core.inner_mul_symm_re_eq_norm InnerProductSpace.Core.inner_mul_symm_re_eq_norm /-- Expand `inner (x + y) (x + y)` -/ theorem inner_add_add_self (x y : F) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring #align inner_product_space.core.inner_add_add_self InnerProductSpace.Core.inner_add_add_self -- Expand `inner (x - y) (x - y)` theorem inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring #align inner_product_space.core.inner_sub_sub_self InnerProductSpace.Core.inner_sub_sub_self /-- An auxiliary equality useful to prove the **Cauchy–Schwarz inequality**: the square of the norm of `⟪x, y⟫ • x - ⟪x, x⟫ • y` is equal to `‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2 - ‖⟪x, y⟫‖ ^ 2)`. We use `InnerProductSpace.ofCore.normSq x` etc (defeq to `is_R_or_C.re ⟪x, x⟫`) instead of `‖x‖ ^ 2` etc to avoid extra rewrites when applying it to an `InnerProductSpace`. -/ theorem cauchy_schwarz_aux (x y : F) : normSqF (⟪x, y⟫ • x - ⟪x, x⟫ • y) = normSqF x * (normSqF x * normSqF y - ‖⟪x, y⟫‖ ^ 2) := by rw [← @ofReal_inj 𝕜, ofReal_normSq_eq_inner_self] simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, conj_ofReal, mul_sub, ← ofReal_normSq_eq_inner_self x, ← ofReal_normSq_eq_inner_self y] rw [← mul_assoc, mul_conj, RCLike.conj_mul, mul_left_comm, ← inner_conj_symm y, mul_conj] push_cast ring #align inner_product_space.core.cauchy_schwarz_aux InnerProductSpace.Core.cauchy_schwarz_aux /-- **Cauchy–Schwarz inequality**. We need this for the `Core` structure to prove the triangle inequality below when showing the core is a normed group. -/ theorem inner_mul_inner_self_le (x y : F) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := by rcases eq_or_ne x 0 with (rfl | hx) · simpa only [inner_zero_left, map_zero, zero_mul, norm_zero] using le_rfl · have hx' : 0 < normSqF x := inner_self_nonneg.lt_of_ne' (mt normSq_eq_zero.1 hx) rw [← sub_nonneg, ← mul_nonneg_iff_right_nonneg_of_pos hx', ← normSq, ← normSq, norm_inner_symm y, ← sq, ← cauchy_schwarz_aux] exact inner_self_nonneg #align inner_product_space.core.inner_mul_inner_self_le InnerProductSpace.Core.inner_mul_inner_self_le /-- Norm constructed from an `InnerProductSpace.Core` structure, defined to be the square root of the scalar product. -/ def toNorm : Norm F where norm x := √(re ⟪x, x⟫) #align inner_product_space.core.to_has_norm InnerProductSpace.Core.toNorm attribute [local instance] toNorm theorem norm_eq_sqrt_inner (x : F) : ‖x‖ = √(re ⟪x, x⟫) := rfl #align inner_product_space.core.norm_eq_sqrt_inner InnerProductSpace.Core.norm_eq_sqrt_inner
Mathlib/Analysis/InnerProductSpace/Basic.lean
346
347
theorem inner_self_eq_norm_mul_norm (x : F) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by
rw [norm_eq_sqrt_inner, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Yury Kudryashov -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.normed_space.add_torsor from "leanprover-community/mathlib"@"837f72de63ad6cd96519cde5f1ffd5ed8d280ad0" /-! # Torsors of normed space actions. This file contains lemmas about normed additive torsors over normed spaces. -/ noncomputable section open NNReal Topology open Filter variable {α V P W Q : Type*} [SeminormedAddCommGroup V] [PseudoMetricSpace P] [NormedAddTorsor V P] [NormedAddCommGroup W] [MetricSpace Q] [NormedAddTorsor W Q] section NormedSpace variable {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 V] [NormedSpace 𝕜 W] open AffineMap theorem AffineSubspace.isClosed_direction_iff (s : AffineSubspace 𝕜 Q) : IsClosed (s.direction : Set W) ↔ IsClosed (s : Set Q) := by rcases s.eq_bot_or_nonempty with (rfl | ⟨x, hx⟩); · simp [isClosed_singleton] rw [← (IsometryEquiv.vaddConst x).toHomeomorph.symm.isClosed_image, AffineSubspace.coe_direction_eq_vsub_set_right hx] rfl #align affine_subspace.is_closed_direction_iff AffineSubspace.isClosed_direction_iff @[simp] theorem dist_center_homothety (p₁ p₂ : P) (c : 𝕜) : dist p₁ (homothety p₁ c p₂) = ‖c‖ * dist p₁ p₂ := by simp [homothety_def, norm_smul, ← dist_eq_norm_vsub, dist_comm] #align dist_center_homothety dist_center_homothety @[simp] theorem nndist_center_homothety (p₁ p₂ : P) (c : 𝕜) : nndist p₁ (homothety p₁ c p₂) = ‖c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_center_homothety _ _ _ #align nndist_center_homothety nndist_center_homothety @[simp]
Mathlib/Analysis/NormedSpace/AddTorsor.lean
57
58
theorem dist_homothety_center (p₁ p₂ : P) (c : 𝕜) : dist (homothety p₁ c p₂) p₁ = ‖c‖ * dist p₁ p₂ := by
rw [dist_comm, dist_center_homothety]
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn -/ import Mathlib.Tactic.CategoryTheory.Reassoc #align_import category_theory.isomorphism from "leanprover-community/mathlib"@"8350c34a64b9bc3fc64335df8006bffcadc7baa6" /-! # Isomorphisms This file defines isomorphisms between objects of a category. ## Main definitions - `structure Iso` : a bundled isomorphism between two objects of a category; - `class IsIso` : an unbundled version of `iso`; note that `IsIso f` is a `Prop`, and only asserts the existence of an inverse. Of course, this inverse is unique, so it doesn't cost us much to use choice to retrieve it. - `inv f`, for the inverse of a morphism with `[IsIso f]` - `asIso` : convert from `IsIso` to `Iso` (noncomputable); - `of_iso` : convert from `Iso` to `IsIso`; - standard operations on isomorphisms (composition, inverse etc) ## Notations - `X ≅ Y` : same as `Iso X Y`; - `α ≪≫ β` : composition of two isomorphisms; it is called `Iso.trans` ## Tags category, category theory, isomorphism -/ universe v u -- morphism levels before object levels. See note [CategoryTheory universes]. namespace CategoryTheory open Category /-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category. The inverse morphism is bundled. See also `CategoryTheory.Core` for the category with the same objects and isomorphisms playing the role of morphisms. See <https://stacks.math.columbia.edu/tag/0017>. -/ structure Iso {C : Type u} [Category.{v} C] (X Y : C) where /-- The forward direction of an isomorphism. -/ hom : X ⟶ Y /-- The backwards direction of an isomorphism. -/ inv : Y ⟶ X /-- Composition of the two directions of an isomorphism is the identity on the source. -/ hom_inv_id : hom ≫ inv = 𝟙 X := by aesop_cat /-- Composition of the two directions of an isomorphism in reverse order is the identity on the target. -/ inv_hom_id : inv ≫ hom = 𝟙 Y := by aesop_cat #align category_theory.iso CategoryTheory.Iso #align category_theory.iso.hom CategoryTheory.Iso.hom #align category_theory.iso.inv CategoryTheory.Iso.inv #align category_theory.iso.inv_hom_id CategoryTheory.Iso.inv_hom_id #align category_theory.iso.hom_inv_id CategoryTheory.Iso.hom_inv_id attribute [reassoc (attr := simp)] Iso.hom_inv_id Iso.inv_hom_id #align category_theory.iso.hom_inv_id_assoc CategoryTheory.Iso.hom_inv_id_assoc #align category_theory.iso.inv_hom_id_assoc CategoryTheory.Iso.inv_hom_id_assoc /-- Notation for an isomorphism in a category. -/ infixr:10 " ≅ " => Iso -- type as \cong or \iso variable {C : Type u} [Category.{v} C] {X Y Z : C} namespace Iso @[ext] theorem ext ⦃α β : X ≅ Y⦄ (w : α.hom = β.hom) : α = β := suffices α.inv = β.inv by cases α cases β cases w cases this rfl calc α.inv = α.inv ≫ β.hom ≫ β.inv := by rw [Iso.hom_inv_id, Category.comp_id] _ = (α.inv ≫ α.hom) ≫ β.inv := by rw [Category.assoc, ← w] _ = β.inv := by rw [Iso.inv_hom_id, Category.id_comp] #align category_theory.iso.ext CategoryTheory.Iso.ext /-- Inverse isomorphism. -/ @[symm] def symm (I : X ≅ Y) : Y ≅ X where hom := I.inv inv := I.hom #align category_theory.iso.symm CategoryTheory.Iso.symm @[simp] theorem symm_hom (α : X ≅ Y) : α.symm.hom = α.inv := rfl #align category_theory.iso.symm_hom CategoryTheory.Iso.symm_hom @[simp] theorem symm_inv (α : X ≅ Y) : α.symm.inv = α.hom := rfl #align category_theory.iso.symm_inv CategoryTheory.Iso.symm_inv @[simp] theorem symm_mk {X Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) : Iso.symm { hom, inv, hom_inv_id := hom_inv_id, inv_hom_id := inv_hom_id } = { hom := inv, inv := hom, hom_inv_id := inv_hom_id, inv_hom_id := hom_inv_id } := rfl #align category_theory.iso.symm_mk CategoryTheory.Iso.symm_mk @[simp] theorem symm_symm_eq {X Y : C} (α : X ≅ Y) : α.symm.symm = α := by cases α; rfl #align category_theory.iso.symm_symm_eq CategoryTheory.Iso.symm_symm_eq @[simp] theorem symm_eq_iff {X Y : C} {α β : X ≅ Y} : α.symm = β.symm ↔ α = β := ⟨fun h => symm_symm_eq α ▸ symm_symm_eq β ▸ congr_arg symm h, congr_arg symm⟩ #align category_theory.iso.symm_eq_iff CategoryTheory.Iso.symm_eq_iff theorem nonempty_iso_symm (X Y : C) : Nonempty (X ≅ Y) ↔ Nonempty (Y ≅ X) := ⟨fun h => ⟨h.some.symm⟩, fun h => ⟨h.some.symm⟩⟩ #align category_theory.iso.nonempty_iso_symm CategoryTheory.Iso.nonempty_iso_symm /-- Identity isomorphism. -/ @[refl, simps] def refl (X : C) : X ≅ X where hom := 𝟙 X inv := 𝟙 X #align category_theory.iso.refl CategoryTheory.Iso.refl #align category_theory.iso.refl_inv CategoryTheory.Iso.refl_inv #align category_theory.iso.refl_hom CategoryTheory.Iso.refl_hom instance : Inhabited (X ≅ X) := ⟨Iso.refl X⟩ theorem nonempty_iso_refl (X : C) : Nonempty (X ≅ X) := ⟨default⟩ @[simp] theorem refl_symm (X : C) : (Iso.refl X).symm = Iso.refl X := rfl #align category_theory.iso.refl_symm CategoryTheory.Iso.refl_symm -- Porting note: It seems that the trans `trans` attribute isn't working properly -- in this case, so we have to manually add a `Trans` instance (with a `simps` tag). /-- Composition of two isomorphisms -/ @[trans, simps] def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z where hom := α.hom ≫ β.hom inv := β.inv ≫ α.inv #align category_theory.iso.trans CategoryTheory.Iso.trans #align category_theory.iso.trans_hom CategoryTheory.Iso.trans_hom #align category_theory.iso.trans_inv CategoryTheory.Iso.trans_inv @[simps] instance instTransIso : Trans (α := C) (· ≅ ·) (· ≅ ·) (· ≅ ·) where trans := trans /-- Notation for composition of isomorphisms. -/ infixr:80 " ≪≫ " => Iso.trans -- type as `\ll \gg`. @[simp] theorem trans_mk {X Y Z : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) (hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') : Iso.trans ⟨hom, inv, hom_inv_id, inv_hom_id⟩ ⟨hom', inv', hom_inv_id', inv_hom_id'⟩ = ⟨hom ≫ hom', inv' ≫ inv, hom_inv_id'', inv_hom_id''⟩ := rfl #align category_theory.iso.trans_mk CategoryTheory.Iso.trans_mk @[simp] theorem trans_symm (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).symm = β.symm ≪≫ α.symm := rfl #align category_theory.iso.trans_symm CategoryTheory.Iso.trans_symm @[simp] theorem trans_assoc {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') : (α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ := by ext; simp only [trans_hom, Category.assoc] #align category_theory.iso.trans_assoc CategoryTheory.Iso.trans_assoc @[simp] theorem refl_trans (α : X ≅ Y) : Iso.refl X ≪≫ α = α := by ext; apply Category.id_comp #align category_theory.iso.refl_trans CategoryTheory.Iso.refl_trans @[simp] theorem trans_refl (α : X ≅ Y) : α ≪≫ Iso.refl Y = α := by ext; apply Category.comp_id #align category_theory.iso.trans_refl CategoryTheory.Iso.trans_refl @[simp] theorem symm_self_id (α : X ≅ Y) : α.symm ≪≫ α = Iso.refl Y := ext α.inv_hom_id #align category_theory.iso.symm_self_id CategoryTheory.Iso.symm_self_id @[simp] theorem self_symm_id (α : X ≅ Y) : α ≪≫ α.symm = Iso.refl X := ext α.hom_inv_id #align category_theory.iso.self_symm_id CategoryTheory.Iso.self_symm_id @[simp] theorem symm_self_id_assoc (α : X ≅ Y) (β : Y ≅ Z) : α.symm ≪≫ α ≪≫ β = β := by rw [← trans_assoc, symm_self_id, refl_trans] #align category_theory.iso.symm_self_id_assoc CategoryTheory.Iso.symm_self_id_assoc @[simp] theorem self_symm_id_assoc (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ α.symm ≪≫ β = β := by rw [← trans_assoc, self_symm_id, refl_trans] #align category_theory.iso.self_symm_id_assoc CategoryTheory.Iso.self_symm_id_assoc theorem inv_comp_eq (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : α.inv ≫ f = g ↔ f = α.hom ≫ g := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ #align category_theory.iso.inv_comp_eq CategoryTheory.Iso.inv_comp_eq theorem eq_inv_comp (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = α.inv ≫ f ↔ α.hom ≫ g = f := (inv_comp_eq α.symm).symm #align category_theory.iso.eq_inv_comp CategoryTheory.Iso.eq_inv_comp theorem comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ #align category_theory.iso.comp_inv_eq CategoryTheory.Iso.comp_inv_eq theorem eq_comp_inv (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ α.inv ↔ g ≫ α.hom = f := (comp_inv_eq α.symm).symm #align category_theory.iso.eq_comp_inv CategoryTheory.Iso.eq_comp_inv theorem inv_eq_inv (f g : X ≅ Y) : f.inv = g.inv ↔ f.hom = g.hom := have : ∀ {X Y : C} (f g : X ≅ Y), f.hom = g.hom → f.inv = g.inv := fun f g h => by rw [ext h] ⟨this f.symm g.symm, this f g⟩ #align category_theory.iso.inv_eq_inv CategoryTheory.Iso.inv_eq_inv theorem hom_comp_eq_id (α : X ≅ Y) {f : Y ⟶ X} : α.hom ≫ f = 𝟙 X ↔ f = α.inv := by rw [← eq_inv_comp, comp_id] #align category_theory.iso.hom_comp_eq_id CategoryTheory.Iso.hom_comp_eq_id theorem comp_hom_eq_id (α : X ≅ Y) {f : Y ⟶ X} : f ≫ α.hom = 𝟙 Y ↔ f = α.inv := by rw [← eq_comp_inv, id_comp] #align category_theory.iso.comp_hom_eq_id CategoryTheory.Iso.comp_hom_eq_id theorem inv_comp_eq_id (α : X ≅ Y) {f : X ⟶ Y} : α.inv ≫ f = 𝟙 Y ↔ f = α.hom := hom_comp_eq_id α.symm #align category_theory.iso.inv_comp_eq_id CategoryTheory.Iso.inv_comp_eq_id theorem comp_inv_eq_id (α : X ≅ Y) {f : X ⟶ Y} : f ≫ α.inv = 𝟙 X ↔ f = α.hom := comp_hom_eq_id α.symm #align category_theory.iso.comp_inv_eq_id CategoryTheory.Iso.comp_inv_eq_id theorem hom_eq_inv (α : X ≅ Y) (β : Y ≅ X) : α.hom = β.inv ↔ β.hom = α.inv := by erw [inv_eq_inv α.symm β, eq_comm] rfl #align category_theory.iso.hom_eq_inv CategoryTheory.Iso.hom_eq_inv end Iso /-- `IsIso` typeclass expressing that a morphism is invertible. -/ class IsIso (f : X ⟶ Y) : Prop where /-- The existence of an inverse morphism. -/ out : ∃ inv : Y ⟶ X, f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y #align category_theory.is_iso CategoryTheory.IsIso /-- The inverse of a morphism `f` when we have `[IsIso f]`. -/ noncomputable def inv (f : X ⟶ Y) [I : IsIso f] : Y ⟶ X := Classical.choose I.1 #align category_theory.inv CategoryTheory.inv namespace IsIso @[simp] theorem hom_inv_id (f : X ⟶ Y) [I : IsIso f] : f ≫ inv f = 𝟙 X := (Classical.choose_spec I.1).left #align category_theory.is_iso.hom_inv_id CategoryTheory.IsIso.hom_inv_id @[simp] theorem inv_hom_id (f : X ⟶ Y) [I : IsIso f] : inv f ≫ f = 𝟙 Y := (Classical.choose_spec I.1).right #align category_theory.is_iso.inv_hom_id CategoryTheory.IsIso.inv_hom_id -- FIXME putting @[reassoc] on the `hom_inv_id` above somehow unfolds `inv` -- This happens even if we make `inv` irreducible! -- I don't understand how this is happening: it is likely a bug. -- attribute [reassoc] hom_inv_id inv_hom_id -- #print hom_inv_id_assoc -- theorem CategoryTheory.IsIso.hom_inv_id_assoc {X Y : C} (f : X ⟶ Y) [I : IsIso f] -- {Z : C} (h : X ⟶ Z), -- f ≫ Classical.choose (_ : Exists fun inv ↦ f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y) ≫ h = h := ... @[simp] theorem hom_inv_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : X ⟶ Z) : f ≫ inv f ≫ g = g := by simp [← Category.assoc] #align category_theory.is_iso.hom_inv_id_assoc CategoryTheory.IsIso.hom_inv_id_assoc @[simp] theorem inv_hom_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : Y ⟶ Z) : inv f ≫ f ≫ g = g := by simp [← Category.assoc] #align category_theory.is_iso.inv_hom_id_assoc CategoryTheory.IsIso.inv_hom_id_assoc end IsIso lemma Iso.isIso_hom (e : X ≅ Y) : IsIso e.hom := ⟨e.inv, by simp, by simp⟩ #align category_theory.is_iso.of_iso CategoryTheory.Iso.isIso_hom lemma Iso.isIso_inv (e : X ≅ Y) : IsIso e.inv := e.symm.isIso_hom #align category_theory.is_iso.of_iso_inv CategoryTheory.Iso.isIso_inv attribute [instance] Iso.isIso_hom Iso.isIso_inv open IsIso /-- Reinterpret a morphism `f` with an `IsIso f` instance as an `Iso`. -/ noncomputable def asIso (f : X ⟶ Y) [IsIso f] : X ≅ Y := ⟨f, inv f, hom_inv_id f, inv_hom_id f⟩ #align category_theory.as_iso CategoryTheory.asIso -- Porting note: the `IsIso f` argument had been instance implicit, -- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor` -- was failing to generate it by typeclass search. @[simp] theorem asIso_hom (f : X ⟶ Y) {_ : IsIso f} : (asIso f).hom = f := rfl #align category_theory.as_iso_hom CategoryTheory.asIso_hom -- Porting note: the `IsIso f` argument had been instance implicit, -- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor` -- was failing to generate it by typeclass search. @[simp] theorem asIso_inv (f : X ⟶ Y) {_ : IsIso f} : (asIso f).inv = inv f := rfl #align category_theory.as_iso_inv CategoryTheory.asIso_inv namespace IsIso -- see Note [lower instance priority] instance (priority := 100) epi_of_iso (f : X ⟶ Y) [IsIso f] : Epi f where left_cancellation g h w := by rw [← IsIso.inv_hom_id_assoc f g, w, IsIso.inv_hom_id_assoc f h] #align category_theory.is_iso.epi_of_iso CategoryTheory.IsIso.epi_of_iso -- see Note [lower instance priority] instance (priority := 100) mono_of_iso (f : X ⟶ Y) [IsIso f] : Mono f where right_cancellation g h w := by rw [← Category.comp_id g, ← Category.comp_id h, ← IsIso.hom_inv_id f, ← Category.assoc, w, ← Category.assoc] #align category_theory.is_iso.mono_of_iso CategoryTheory.IsIso.mono_of_iso -- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule @[aesop apply safe (rule_sets := [CategoryTheory])] theorem inv_eq_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) : inv f = g := by apply (cancel_epi f).mp simp [hom_inv_id] #align category_theory.is_iso.inv_eq_of_hom_inv_id CategoryTheory.IsIso.inv_eq_of_hom_inv_id theorem inv_eq_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) : inv f = g := by apply (cancel_mono f).mp simp [inv_hom_id] #align category_theory.is_iso.inv_eq_of_inv_hom_id CategoryTheory.IsIso.inv_eq_of_inv_hom_id -- Porting note: `@[ext]` used to accept lemmas like this. @[aesop apply safe (rule_sets := [CategoryTheory])] theorem eq_inv_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) : g = inv f := (inv_eq_of_hom_inv_id hom_inv_id).symm #align category_theory.is_iso.eq_inv_of_hom_inv_id CategoryTheory.IsIso.eq_inv_of_hom_inv_id theorem eq_inv_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) : g = inv f := (inv_eq_of_inv_hom_id inv_hom_id).symm #align category_theory.is_iso.eq_inv_of_inv_hom_id CategoryTheory.IsIso.eq_inv_of_inv_hom_id instance id (X : C) : IsIso (𝟙 X) := ⟨⟨𝟙 X, by simp⟩⟩ #align category_theory.is_iso.id CategoryTheory.IsIso.id -- deprecated on 2024-05-15 @[deprecated] alias of_iso := CategoryTheory.Iso.isIso_hom @[deprecated] alias of_iso_inv := CategoryTheory.Iso.isIso_inv variable {f g : X ⟶ Y} {h : Y ⟶ Z} instance inv_isIso [IsIso f] : IsIso (inv f) := (asIso f).isIso_inv #align category_theory.is_iso.inv_is_iso CategoryTheory.IsIso.inv_isIso /- The following instance has lower priority for the following reason: Suppose we are given `f : X ≅ Y` with `X Y : Type u`. Without the lower priority, typeclass inference cannot deduce `IsIso f.hom` because `f.hom` is defeq to `(fun x ↦ x) ≫ f.hom`, triggering a loop. -/ instance (priority := 900) comp_isIso [IsIso f] [IsIso h] : IsIso (f ≫ h) := (asIso f ≪≫ asIso h).isIso_hom #align category_theory.is_iso.comp_is_iso CategoryTheory.IsIso.comp_isIso @[simp] theorem inv_id : inv (𝟙 X) = 𝟙 X := by apply inv_eq_of_hom_inv_id simp #align category_theory.is_iso.inv_id CategoryTheory.IsIso.inv_id @[simp] theorem inv_comp [IsIso f] [IsIso h] : inv (f ≫ h) = inv h ≫ inv f := by apply inv_eq_of_hom_inv_id simp #align category_theory.is_iso.inv_comp CategoryTheory.IsIso.inv_comp @[simp] theorem inv_inv [IsIso f] : inv (inv f) = f := by apply inv_eq_of_hom_inv_id simp #align category_theory.is_iso.inv_inv CategoryTheory.IsIso.inv_inv @[simp] theorem Iso.inv_inv (f : X ≅ Y) : inv f.inv = f.hom := by apply inv_eq_of_hom_inv_id simp #align category_theory.is_iso.iso.inv_inv CategoryTheory.IsIso.Iso.inv_inv @[simp] theorem Iso.inv_hom (f : X ≅ Y) : inv f.hom = f.inv := by apply inv_eq_of_hom_inv_id simp #align category_theory.is_iso.iso.inv_hom CategoryTheory.IsIso.Iso.inv_hom @[simp] theorem inv_comp_eq (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : inv α ≫ f = g ↔ f = α ≫ g := (asIso α).inv_comp_eq #align category_theory.is_iso.inv_comp_eq CategoryTheory.IsIso.inv_comp_eq @[simp] theorem eq_inv_comp (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : g = inv α ≫ f ↔ α ≫ g = f := (asIso α).eq_inv_comp #align category_theory.is_iso.eq_inv_comp CategoryTheory.IsIso.eq_inv_comp @[simp] theorem comp_inv_eq (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ inv α = g ↔ f = g ≫ α := (asIso α).comp_inv_eq #align category_theory.is_iso.comp_inv_eq CategoryTheory.IsIso.comp_inv_eq @[simp] theorem eq_comp_inv (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ inv α ↔ g ≫ α = f := (asIso α).eq_comp_inv #align category_theory.is_iso.eq_comp_inv CategoryTheory.IsIso.eq_comp_inv
Mathlib/CategoryTheory/Iso.lean
445
448
theorem of_isIso_comp_left {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [IsIso (f ≫ g)] : IsIso g := by
rw [← id_comp g, ← inv_hom_id f, assoc] infer_instance
/- Copyright (c) 2022 Apurva Nakade. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Apurva Nakade -/ import Mathlib.Analysis.Convex.Cone.Closure import Mathlib.Analysis.InnerProductSpace.Adjoint #align_import analysis.convex.cone.proper from "leanprover-community/mathlib"@"147b294346843885f952c5171e9606616a8fd869" /-! # Proper cones We define a *proper cone* as a closed, pointed cone. Proper cones are used in defining conic programs which generalize linear programs. A linear program is a conic program for the positive cone. We then prove Farkas' lemma for conic programs following the proof in the reference below. Farkas' lemma is equivalent to strong duality. So, once we have the definitions of conic and linear programs, the results from this file can be used to prove duality theorems. ## TODO The next steps are: - Add convex_cone_class that extends set_like and replace the below instance - Define primal and dual cone programs and prove weak duality. - Prove regular and strong duality for cone programs using Farkas' lemma (see reference). - Define linear programs and prove LP duality as a special case of cone duality. - Find a better reference (textbook instead of lecture notes). ## References - [B. Gartner and J. Matousek, Cone Programming][gartnerMatousek] -/ open ContinuousLinearMap Filter Set /-- A proper cone is a pointed cone `K` that is closed. Proper cones have the nice property that they are equal to their double dual, see `ProperCone.dual_dual`. This makes them useful for defining cone programs and proving duality theorems. -/ structure ProperCone (𝕜 : Type*) (E : Type*) [OrderedSemiring 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] extends Submodule {c : 𝕜 // 0 ≤ c} E where isClosed' : IsClosed (carrier : Set E) #align proper_cone ProperCone namespace ProperCone section Module variable {𝕜 : Type*} [OrderedSemiring 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] /-- A `PointedCone` is defined as an alias of submodule. We replicate the abbreviation here and define `toPointedCone` as an alias of `toSubmodule`. -/ abbrev toPointedCone (C : ProperCone 𝕜 E) := C.toSubmodule attribute [coe] toPointedCone instance : Coe (ProperCone 𝕜 E) (PointedCone 𝕜 E) := ⟨toPointedCone⟩ -- Porting note: now a syntactic tautology -- @[simp] -- theorem toConvexCone_eq_coe (K : ProperCone 𝕜 E) : K.toConvexCone = K := -- rfl #noalign proper_cone.to_convex_cone_eq_coe theorem toPointedCone_injective : Function.Injective ((↑) : ProperCone 𝕜 E → PointedCone 𝕜 E) := fun S T h => by cases S; cases T; congr #align proper_cone.ext' ProperCone.toPointedCone_injective -- TODO: add `ConvexConeClass` that extends `SetLike` and replace the below instance instance : SetLike (ProperCone 𝕜 E) E where coe K := K.carrier coe_injective' _ _ h := ProperCone.toPointedCone_injective (SetLike.coe_injective h) @[ext] theorem ext {S T : ProperCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align proper_cone.ext ProperCone.ext @[simp] theorem mem_coe {x : E} {K : ProperCone 𝕜 E} : x ∈ (K : PointedCone 𝕜 E) ↔ x ∈ K := Iff.rfl #align proper_cone.mem_coe ProperCone.mem_coe instance instZero (K : ProperCone 𝕜 E) : Zero K := PointedCone.instZero (K.toSubmodule) protected theorem nonempty (K : ProperCone 𝕜 E) : (K : Set E).Nonempty := ⟨0, by { simp_rw [SetLike.mem_coe, ← ProperCone.mem_coe, Submodule.zero_mem] }⟩ #align proper_cone.nonempty ProperCone.nonempty protected theorem isClosed (K : ProperCone 𝕜 E) : IsClosed (K : Set E) := K.isClosed' #align proper_cone.is_closed ProperCone.isClosed end Module section PositiveCone variable (𝕜 E) variable [OrderedSemiring 𝕜] [OrderedAddCommGroup E] [Module 𝕜 E] [OrderedSMul 𝕜 E] [TopologicalSpace E] [OrderClosedTopology E] /-- The positive cone is the proper cone formed by the set of nonnegative elements in an ordered module. -/ def positive : ProperCone 𝕜 E where toSubmodule := PointedCone.positive 𝕜 E isClosed' := isClosed_Ici @[simp] theorem mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := Iff.rfl @[simp] theorem coe_positive : ↑(positive 𝕜 E) = ConvexCone.positive 𝕜 E := rfl end PositiveCone section Module variable {𝕜 : Type*} [OrderedSemiring 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [T1Space E] [Module 𝕜 E] instance : Zero (ProperCone 𝕜 E) := ⟨{ toSubmodule := 0 isClosed' := isClosed_singleton }⟩ instance : Inhabited (ProperCone 𝕜 E) := ⟨0⟩ @[simp] theorem mem_zero (x : E) : x ∈ (0 : ProperCone 𝕜 E) ↔ x = 0 := Iff.rfl #align proper_cone.mem_zero ProperCone.mem_zero @[simp, norm_cast] theorem coe_zero : ↑(0 : ProperCone 𝕜 E) = (0 : ConvexCone 𝕜 E) := rfl #align proper_cone.coe_zero ProperCone.coe_zero theorem pointed_zero : ((0 : ProperCone 𝕜 E) : ConvexCone 𝕜 E).Pointed := by simp [ConvexCone.pointed_zero] #align proper_cone.pointed_zero ProperCone.pointed_zero end Module section InnerProductSpace variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace ℝ G] protected theorem pointed (K : ProperCone ℝ E) : (K : ConvexCone ℝ E).Pointed := (K : ConvexCone ℝ E).pointed_of_nonempty_of_isClosed K.nonempty K.isClosed #align proper_cone.pointed ProperCone.pointed /-- The closure of image of a proper cone under a continuous `ℝ`-linear map is a proper cone. We use continuous maps here so that the comap of f is also a map between proper cones. -/ noncomputable def map (f : E →L[ℝ] F) (K : ProperCone ℝ E) : ProperCone ℝ F where toSubmodule := PointedCone.closure (PointedCone.map (f : E →ₗ[ℝ] F) ↑K) isClosed' := isClosed_closure #align proper_cone.map ProperCone.map @[simp, norm_cast] theorem coe_map (f : E →L[ℝ] F) (K : ProperCone ℝ E) : ↑(K.map f) = (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure := rfl #align proper_cone.coe_map ProperCone.coe_map @[simp] theorem mem_map {f : E →L[ℝ] F} {K : ProperCone ℝ E} {y : F} : y ∈ K.map f ↔ y ∈ (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure := Iff.rfl #align proper_cone.mem_map ProperCone.mem_map @[simp] theorem map_id (K : ProperCone ℝ E) : K.map (ContinuousLinearMap.id ℝ E) = K := ProperCone.toPointedCone_injective <| by simpa using IsClosed.closure_eq K.isClosed #align proper_cone.map_id ProperCone.map_id /-- The inner dual cone of a proper cone is a proper cone. -/ def dual (K : ProperCone ℝ E) : ProperCone ℝ E where toSubmodule := PointedCone.dual (K : PointedCone ℝ E) isClosed' := isClosed_innerDualCone _ #align proper_cone.dual ProperCone.dual @[simp, norm_cast] theorem coe_dual (K : ProperCone ℝ E) : K.dual = (K : Set E).innerDualCone := rfl #align proper_cone.coe_dual ProperCone.coe_dual @[simp] theorem mem_dual {K : ProperCone ℝ E} {y : E} : y ∈ dual K ↔ ∀ ⦃x⦄, x ∈ K → 0 ≤ ⟪x, y⟫_ℝ := by aesop #align proper_cone.mem_dual ProperCone.mem_dual /-- The preimage of a proper cone under a continuous `ℝ`-linear map is a proper cone. -/ noncomputable def comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : ProperCone ℝ E where toSubmodule := PointedCone.comap (f : E →ₗ[ℝ] F) S isClosed' := by rw [PointedCone.comap] apply IsClosed.preimage f.2 S.isClosed #align proper_cone.comap ProperCone.comap @[simp] theorem coe_comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : (S.comap f : Set E) = f ⁻¹' S := rfl #align proper_cone.coe_comap ProperCone.coe_comap @[simp] theorem comap_id (S : ConvexCone ℝ E) : S.comap LinearMap.id = S := SetLike.coe_injective preimage_id #align proper_cone.comap_id ProperCone.comap_id theorem comap_comap (g : F →L[ℝ] G) (f : E →L[ℝ] F) (S : ProperCone ℝ G) : (S.comap g).comap f = S.comap (g.comp f) := SetLike.coe_injective <| by congr #align proper_cone.comap_comap ProperCone.comap_comap @[simp] theorem mem_comap {f : E →L[ℝ] F} {S : ProperCone ℝ F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl #align proper_cone.mem_comap ProperCone.mem_comap end InnerProductSpace section CompleteSpace variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [CompleteSpace F] /-- The dual of the dual of a proper cone is itself. -/ @[simp] theorem dual_dual (K : ProperCone ℝ E) : K.dual.dual = K := ProperCone.toPointedCone_injective <| PointedCone.toConvexCone_injective <| (K : ConvexCone ℝ E).innerDualCone_of_innerDualCone_eq_self K.nonempty K.isClosed #align proper_cone.dual_dual ProperCone.dual_dual /-- This is a relative version of `ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`, which we recover by setting `f` to be the identity map. This is also a geometric interpretation of the Farkas' lemma stated using proper cones. -/ theorem hyperplane_separation (K : ProperCone ℝ E) {f : E →L[ℝ] F} {b : F} : b ∈ K.map f ↔ ∀ y : F, adjoint f y ∈ K.dual → 0 ≤ ⟪y, b⟫_ℝ := Iff.intro (by -- suppose `b ∈ K.map f` simp_rw [mem_map, PointedCone.mem_closure, PointedCone.coe_map, coe_coe, mem_closure_iff_seq_limit, mem_image, SetLike.mem_coe, mem_coe, mem_dual, adjoint_inner_right, forall_exists_index, and_imp] -- there is a sequence `seq : ℕ → F` in the image of `f` that converges to `b` rintro seq hmem htends y hinner suffices h : ∀ n, 0 ≤ ⟪y, seq n⟫_ℝ from ge_of_tendsto' (Continuous.seqContinuous (Continuous.inner (@continuous_const _ _ _ _ y) continuous_id) htends) h intro n obtain ⟨_, h, hseq⟩ := hmem n simpa only [← hseq, real_inner_comm] using hinner h) (by -- proof by contradiction -- suppose `b ∉ K.map f` intro h contrapose! h -- as `b ∉ K.map f`, there is a hyperplane `y` separating `b` from `K.map f` let C := @PointedCone.toConvexCone ℝ F _ _ _ (K.map f) obtain ⟨y, hxy, hyb⟩ := @ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem _ _ _ _ C (K.map f).nonempty (K.map f).isClosed b h -- the rest of the proof is a straightforward algebraic manipulation refine ⟨y, ?_, hyb⟩ simp_rw [ProperCone.mem_dual, adjoint_inner_right] intro x hxK apply hxy (f x) simp_rw [C, coe_map] apply subset_closure simp_rw [PointedCone.toConvexCone_map, ConvexCone.coe_map, coe_coe, mem_image, SetLike.mem_coe] exact ⟨x, hxK, rfl⟩) #align proper_cone.hyperplane_separation ProperCone.hyperplane_separation
Mathlib/Analysis/Convex/Cone/Proper.lean
286
288
theorem hyperplane_separation_of_nmem (K : ProperCone ℝ E) {f : E →L[ℝ] F} {b : F} (disj : b ∉ K.map f) : ∃ y : F, adjoint f y ∈ K.dual ∧ ⟪y, b⟫_ℝ < 0 := by
contrapose! disj; rwa [K.hyperplane_separation]
/- Copyright (c) 2022 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Amelia Livingston -/ import Mathlib.Algebra.Homology.Additive import Mathlib.CategoryTheory.Abelian.Pseudoelements import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Images #align_import category_theory.abelian.homology from "leanprover-community/mathlib"@"956af7c76589f444f2e1313911bad16366ea476d" /-! The object `homology' f g w`, where `w : f ≫ g = 0`, can be identified with either a cokernel or a kernel. The isomorphism with a cokernel is `homology'IsoCokernelLift`, which was obtained elsewhere. In the case of an abelian category, this file shows the isomorphism with a kernel as well. We use these isomorphisms to obtain the analogous api for `homology'`: - `homology'.ι` is the map from `homology' f g w` into the cokernel of `f`. - `homology'.π'` is the map from `kernel g` to `homology' f g w`. - `homology'.desc'` constructs a morphism from `homology' f g w`, when it is viewed as a cokernel. - `homology'.lift` constructs a morphism to `homology' f g w`, when it is viewed as a kernel. - Various small lemmas are proved as well, mimicking the API for (co)kernels. With these definitions and lemmas, the isomorphisms between homology and a (co)kernel need not be used directly. Note: As part of the homology refactor, it is planned to remove the definitions in this file, because it can be replaced by the content of `Algebra.Homology.ShortComplex.Homology`. -/ open CategoryTheory.Limits open CategoryTheory noncomputable section universe v u variable {A : Type u} [Category.{v} A] [Abelian A] variable {X Y Z : A} (f : X ⟶ Y) (g : Y ⟶ Z) (w : f ≫ g = 0) namespace CategoryTheory.Abelian /-- The cokernel of `kernel.lift g f w`. This is isomorphic to `homology f g w`. See `homologyIsoCokernelLift`. -/ abbrev homologyC : A := cokernel (kernel.lift g f w) #align category_theory.abelian.homology_c CategoryTheory.Abelian.homologyC /-- The kernel of `cokernel.desc f g w`. This is isomorphic to `homology f g w`. See `homologyIsoKernelDesc`. -/ abbrev homologyK : A := kernel (cokernel.desc f g w) #align category_theory.abelian.homology_k CategoryTheory.Abelian.homologyK /-- The canonical map from `homologyC` to `homologyK`. This is an isomorphism, and it is used in obtaining the API for `homology f g w` in the bottom of this file. -/ abbrev homologyCToK : homologyC f g w ⟶ homologyK f g w := cokernel.desc _ (kernel.lift _ (kernel.ι _ ≫ cokernel.π _) (by simp)) (by ext; simp) #align category_theory.abelian.homology_c_to_k CategoryTheory.Abelian.homologyCToK attribute [local instance] Pseudoelement.homToFun Pseudoelement.hasZero instance : Mono (homologyCToK f g w) := by apply Pseudoelement.mono_of_zero_of_map_zero intro a ha obtain ⟨a, rfl⟩ := Pseudoelement.pseudo_surjective_of_epi (cokernel.π (kernel.lift g f w)) a apply_fun kernel.ι (cokernel.desc f g w) at ha simp only [← Pseudoelement.comp_apply, cokernel.π_desc, kernel.lift_ι, Pseudoelement.apply_zero] at ha simp only [Pseudoelement.comp_apply] at ha obtain ⟨b, hb⟩ : ∃ b, f b = _ := (Pseudoelement.pseudo_exact_of_exact (exact_cokernel f)).2 _ ha rsuffices ⟨c, rfl⟩ : ∃ c, kernel.lift g f w c = a · simp [← Pseudoelement.comp_apply] use b apply_fun kernel.ι g swap; · apply Pseudoelement.pseudo_injective_of_mono simpa [← Pseudoelement.comp_apply] instance : Epi (homologyCToK f g w) := by apply Pseudoelement.epi_of_pseudo_surjective intro a let b := kernel.ι (cokernel.desc f g w) a obtain ⟨c, hc⟩ : ∃ c, cokernel.π f c = b := by apply Pseudoelement.pseudo_surjective_of_epi (cokernel.π f) have : g c = 0 := by rw [show g = cokernel.π f ≫ cokernel.desc f g w by simp, Pseudoelement.comp_apply, hc] simp [b, ← Pseudoelement.comp_apply] obtain ⟨d, hd⟩ : ∃ d, kernel.ι g d = c := by apply (Pseudoelement.pseudo_exact_of_exact exact_kernel_ι).2 _ this use cokernel.π (kernel.lift g f w) d apply_fun kernel.ι (cokernel.desc f g w) swap · apply Pseudoelement.pseudo_injective_of_mono simp only [← Pseudoelement.comp_apply, cokernel.π_desc, kernel.lift_ι] simp only [Pseudoelement.comp_apply, hd, hc] instance (w : f ≫ g = 0) : IsIso (homologyCToK f g w) := isIso_of_mono_of_epi _ end CategoryTheory.Abelian /-- The homology associated to `f` and `g` is isomorphic to a kernel. -/ def homology'IsoKernelDesc : homology' f g w ≅ kernel (cokernel.desc f g w) := homology'IsoCokernelLift _ _ _ ≪≫ asIso (CategoryTheory.Abelian.homologyCToK _ _ _) #align homology_iso_kernel_desc homology'IsoKernelDesc namespace homology' -- `homology'.π` is taken /-- The canonical map from the kernel of `g` to the homology of `f` and `g`. -/ def π' : kernel g ⟶ homology' f g w := cokernel.π _ ≫ (homology'IsoCokernelLift _ _ _).inv #align homology.π' homology'.π' /-- The canonical map from the homology of `f` and `g` to the cokernel of `f`. -/ def ι : homology' f g w ⟶ cokernel f := (homology'IsoKernelDesc _ _ _).hom ≫ kernel.ι _ #align homology.ι homology'.ι /-- Obtain a morphism from the homology, given a morphism from the kernel. -/ def desc' {W : A} (e : kernel g ⟶ W) (he : kernel.lift g f w ≫ e = 0) : homology' f g w ⟶ W := (homology'IsoCokernelLift _ _ _).hom ≫ cokernel.desc _ e he #align homology.desc' homology'.desc' /-- Obtain a morphism to the homology, given a morphism to the kernel. -/ def lift {W : A} (e : W ⟶ cokernel f) (he : e ≫ cokernel.desc f g w = 0) : W ⟶ homology' f g w := kernel.lift _ e he ≫ (homology'IsoKernelDesc _ _ _).inv #align homology.lift homology'.lift @[reassoc (attr := simp)] theorem π'_desc' {W : A} (e : kernel g ⟶ W) (he : kernel.lift g f w ≫ e = 0) : π' f g w ≫ desc' f g w e he = e := by dsimp [π', desc'] simp #align homology.π'_desc' homology'.π'_desc' @[reassoc (attr := simp)] theorem lift_ι {W : A} (e : W ⟶ cokernel f) (he : e ≫ cokernel.desc f g w = 0) : lift f g w e he ≫ ι _ _ _ = e := by dsimp [ι, lift] simp #align homology.lift_ι homology'.lift_ι @[reassoc (attr := simp)] theorem condition_π' : kernel.lift g f w ≫ π' f g w = 0 := by dsimp [π'] simp #align homology.condition_π' homology'.condition_π' @[reassoc (attr := simp)] theorem condition_ι : ι f g w ≫ cokernel.desc f g w = 0 := by dsimp [ι] simp #align homology.condition_ι homology'.condition_ι @[ext] theorem hom_from_ext {W : A} (a b : homology' f g w ⟶ W) (h : π' f g w ≫ a = π' f g w ≫ b) : a = b := by dsimp [π'] at h apply_fun fun e => (homology'IsoCokernelLift f g w).inv ≫ e swap · intro i j hh apply_fun fun e => (homology'IsoCokernelLift f g w).hom ≫ e at hh simpa using hh simp only [Category.assoc] at h exact coequalizer.hom_ext h #align homology.hom_from_ext homology'.hom_from_ext @[ext] theorem hom_to_ext {W : A} (a b : W ⟶ homology' f g w) (h : a ≫ ι f g w = b ≫ ι f g w) : a = b := by dsimp [ι] at h apply_fun fun e => e ≫ (homology'IsoKernelDesc f g w).hom swap · intro i j hh apply_fun fun e => e ≫ (homology'IsoKernelDesc f g w).inv at hh simpa using hh simp only [← Category.assoc] at h exact equalizer.hom_ext h #align homology.hom_to_ext homology'.hom_to_ext @[reassoc (attr := simp)] theorem π'_ι : π' f g w ≫ ι f g w = kernel.ι _ ≫ cokernel.π _ := by dsimp [π', ι, homology'IsoKernelDesc] simp #align homology.π'_ι homology'.π'_ι @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Abelian/Homology.lean
194
199
theorem π'_eq_π : (kernelSubobjectIso _).hom ≫ π' f g w = π _ _ _ := by
dsimp [π', homology'IsoCokernelLift] simp only [← Category.assoc] rw [Iso.comp_inv_eq] dsimp [π, homology'IsoCokernelImageToKernel'] simp
/- 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.Integral.IntervalIntegral import Mathlib.Analysis.Calculus.Deriv.ZPow import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.Analytic.Basic #align_import measure_theory.integral.circle_integral from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Integral over a circle in `ℂ` In this file we define `∮ z in C(c, R), f z` to be the integral $\oint_{|z-c|=|R|} f(z)\,dz$ and prove some properties of this integral. We give definition and prove most lemmas for a function `f : ℂ → E`, where `E` is a complex Banach space. For this reason, some lemmas use, e.g., `(z - c)⁻¹ • f z` instead of `f z / (z - c)`. ## Main definitions * `circleMap c R`: the exponential map $θ ↦ c + R e^{θi}$; * `CircleIntegrable f c R`: a function `f : ℂ → E` is integrable on the circle with center `c` and radius `R` if `f ∘ circleMap c R` is integrable on `[0, 2π]`; * `circleIntegral f c R`: the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$; * `cauchyPowerSeries f c R`: the power series that is equal to $\sum_{n=0}^{\infty} \oint_{|z-c|=R} \left(\frac{w-c}{z - c}\right)^n \frac{1}{z-c}f(z)\,dz$ at `w - c`. The coefficients of this power series depend only on `f ∘ circleMap c R`, and the power series converges to `f w` if `f` is differentiable on the closed ball `Metric.closedBall c R` and `w` belongs to the corresponding open ball. ## Main statements * `hasFPowerSeriesOn_cauchy_integral`: for any circle integrable function `f`, the power series `cauchyPowerSeries f c R`, `R > 0`, converges to the Cauchy integral `(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`; * `circleIntegral.integral_sub_zpow_of_undef`, `circleIntegral.integral_sub_zpow_of_ne`, and `circleIntegral.integral_sub_inv_of_mem_ball`: formulas for `∮ z in C(c, R), (z - w) ^ n`, `n : ℤ`. These lemmas cover the following cases: - `circleIntegral.integral_sub_zpow_of_undef`, `n < 0` and `|w - c| = |R|`: in this case the function is not integrable, so the integral is equal to its default value (zero); - `circleIntegral.integral_sub_zpow_of_ne`, `n ≠ -1`: in the cases not covered by the previous lemma, we have `(z - w) ^ n = ((z - w) ^ (n + 1) / (n + 1))'`, thus the integral equals zero; - `circleIntegral.integral_sub_inv_of_mem_ball`, `n = -1`, `|w - c| < R`: in this case the integral is equal to `2πi`. The case `n = -1`, `|w -c| > R` is not covered by these lemmas. While it is possible to construct an explicit primitive, it is easier to apply Cauchy theorem, so we postpone the proof till we have this theorem (see #10000). ## Notation - `∮ z in C(c, R), f z`: notation for the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$. ## Tags integral, circle, Cauchy integral -/ variable {E : Type*} [NormedAddCommGroup E] noncomputable section open scoped Real NNReal Interval Pointwise Topology open Complex MeasureTheory TopologicalSpace Metric Function Set Filter Asymptotics /-! ### `circleMap`, a parametrization of a circle -/ /-- The exponential map $θ ↦ c + R e^{θi}$. The range of this map is the circle in `ℂ` with center `c` and radius `|R|`. -/ def circleMap (c : ℂ) (R : ℝ) : ℝ → ℂ := fun θ => c + R * exp (θ * I) #align circle_map circleMap /-- `circleMap` is `2π`-periodic. -/ theorem periodic_circleMap (c : ℂ) (R : ℝ) : Periodic (circleMap c R) (2 * π) := fun θ => by simp [circleMap, add_mul, exp_periodic _] #align periodic_circle_map periodic_circleMap theorem Set.Countable.preimage_circleMap {s : Set ℂ} (hs : s.Countable) (c : ℂ) {R : ℝ} (hR : R ≠ 0) : (circleMap c R ⁻¹' s).Countable := show (((↑) : ℝ → ℂ) ⁻¹' ((· * I) ⁻¹' (exp ⁻¹' ((R * ·) ⁻¹' ((c + ·) ⁻¹' s))))).Countable from (((hs.preimage (add_right_injective _)).preimage <| mul_right_injective₀ <| ofReal_ne_zero.2 hR).preimage_cexp.preimage <| mul_left_injective₀ I_ne_zero).preimage ofReal_injective #align set.countable.preimage_circle_map Set.Countable.preimage_circleMap @[simp] theorem circleMap_sub_center (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ - c = circleMap 0 R θ := by simp [circleMap] #align circle_map_sub_center circleMap_sub_center theorem circleMap_zero (R θ : ℝ) : circleMap 0 R θ = R * exp (θ * I) := zero_add _ #align circle_map_zero circleMap_zero @[simp] theorem abs_circleMap_zero (R : ℝ) (θ : ℝ) : abs (circleMap 0 R θ) = |R| := by simp [circleMap] #align abs_circle_map_zero abs_circleMap_zero theorem circleMap_mem_sphere' (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ ∈ sphere c |R| := by simp #align circle_map_mem_sphere' circleMap_mem_sphere' theorem circleMap_mem_sphere (c : ℂ) {R : ℝ} (hR : 0 ≤ R) (θ : ℝ) : circleMap c R θ ∈ sphere c R := by simpa only [_root_.abs_of_nonneg hR] using circleMap_mem_sphere' c R θ #align circle_map_mem_sphere circleMap_mem_sphere theorem circleMap_mem_closedBall (c : ℂ) {R : ℝ} (hR : 0 ≤ R) (θ : ℝ) : circleMap c R θ ∈ closedBall c R := sphere_subset_closedBall (circleMap_mem_sphere c hR θ) #align circle_map_mem_closed_ball circleMap_mem_closedBall theorem circleMap_not_mem_ball (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ ∉ ball c R := by simp [dist_eq, le_abs_self] #align circle_map_not_mem_ball circleMap_not_mem_ball theorem circleMap_ne_mem_ball {c : ℂ} {R : ℝ} {w : ℂ} (hw : w ∈ ball c R) (θ : ℝ) : circleMap c R θ ≠ w := (ne_of_mem_of_not_mem hw (circleMap_not_mem_ball _ _ _)).symm #align circle_map_ne_mem_ball circleMap_ne_mem_ball /-- The range of `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem range_circleMap (c : ℂ) (R : ℝ) : range (circleMap c R) = sphere c |R| := calc range (circleMap c R) = c +ᵥ R • range fun θ : ℝ => exp (θ * I) := by simp (config := { unfoldPartialApp := true }) only [← image_vadd, ← image_smul, ← range_comp, vadd_eq_add, circleMap, Function.comp_def, real_smul] _ = sphere c |R| := by rw [Complex.range_exp_mul_I, smul_sphere R 0 zero_le_one] simp #align range_circle_map range_circleMap /-- The image of `(0, 2π]` under `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem image_circleMap_Ioc (c : ℂ) (R : ℝ) : circleMap c R '' Ioc 0 (2 * π) = sphere c |R| := by rw [← range_circleMap, ← (periodic_circleMap c R).image_Ioc Real.two_pi_pos 0, zero_add] #align image_circle_map_Ioc image_circleMap_Ioc @[simp] theorem circleMap_eq_center_iff {c : ℂ} {R : ℝ} {θ : ℝ} : circleMap c R θ = c ↔ R = 0 := by simp [circleMap, exp_ne_zero] #align circle_map_eq_center_iff circleMap_eq_center_iff @[simp] theorem circleMap_zero_radius (c : ℂ) : circleMap c 0 = const ℝ c := funext fun _ => circleMap_eq_center_iff.2 rfl #align circle_map_zero_radius circleMap_zero_radius theorem circleMap_ne_center {c : ℂ} {R : ℝ} (hR : R ≠ 0) {θ : ℝ} : circleMap c R θ ≠ c := mt circleMap_eq_center_iff.1 hR #align circle_map_ne_center circleMap_ne_center theorem hasDerivAt_circleMap (c : ℂ) (R : ℝ) (θ : ℝ) : HasDerivAt (circleMap c R) (circleMap 0 R θ * I) θ := by simpa only [mul_assoc, one_mul, ofRealCLM_apply, circleMap, ofReal_one, zero_add] using (((ofRealCLM.hasDerivAt (x := θ)).mul_const I).cexp.const_mul (R : ℂ)).const_add c #align has_deriv_at_circle_map hasDerivAt_circleMap /- TODO: prove `ContDiff ℝ (circleMap c R)`. This needs a version of `ContDiff.mul` for multiplication in a normed algebra over the base field. -/ theorem differentiable_circleMap (c : ℂ) (R : ℝ) : Differentiable ℝ (circleMap c R) := fun θ => (hasDerivAt_circleMap c R θ).differentiableAt #align differentiable_circle_map differentiable_circleMap @[continuity] theorem continuous_circleMap (c : ℂ) (R : ℝ) : Continuous (circleMap c R) := (differentiable_circleMap c R).continuous #align continuous_circle_map continuous_circleMap @[measurability] theorem measurable_circleMap (c : ℂ) (R : ℝ) : Measurable (circleMap c R) := (continuous_circleMap c R).measurable #align measurable_circle_map measurable_circleMap @[simp] theorem deriv_circleMap (c : ℂ) (R : ℝ) (θ : ℝ) : deriv (circleMap c R) θ = circleMap 0 R θ * I := (hasDerivAt_circleMap _ _ _).deriv #align deriv_circle_map deriv_circleMap theorem deriv_circleMap_eq_zero_iff {c : ℂ} {R : ℝ} {θ : ℝ} : deriv (circleMap c R) θ = 0 ↔ R = 0 := by simp [I_ne_zero] #align deriv_circle_map_eq_zero_iff deriv_circleMap_eq_zero_iff theorem deriv_circleMap_ne_zero {c : ℂ} {R : ℝ} {θ : ℝ} (hR : R ≠ 0) : deriv (circleMap c R) θ ≠ 0 := mt deriv_circleMap_eq_zero_iff.1 hR #align deriv_circle_map_ne_zero deriv_circleMap_ne_zero theorem lipschitzWith_circleMap (c : ℂ) (R : ℝ) : LipschitzWith (Real.nnabs R) (circleMap c R) := lipschitzWith_of_nnnorm_deriv_le (differentiable_circleMap _ _) fun θ => NNReal.coe_le_coe.1 <| by simp #align lipschitz_with_circle_map lipschitzWith_circleMap theorem continuous_circleMap_inv {R : ℝ} {z w : ℂ} (hw : w ∈ ball z R) : Continuous fun θ => (circleMap z R θ - w)⁻¹ := by have : ∀ θ, circleMap z R θ - w ≠ 0 := by simp_rw [sub_ne_zero] exact fun θ => circleMap_ne_mem_ball hw θ -- Porting note: was `continuity` exact Continuous.inv₀ (by continuity) this #align continuous_circle_map_inv continuous_circleMap_inv /-! ### Integrability of a function on a circle -/ /-- We say that a function `f : ℂ → E` is integrable on the circle with center `c` and radius `R` if the function `f ∘ circleMap c R` is integrable on `[0, 2π]`. Note that the actual function used in the definition of `circleIntegral` is `(deriv (circleMap c R) θ) • f (circleMap c R θ)`. Integrability of this function is equivalent to integrability of `f ∘ circleMap c R` whenever `R ≠ 0`. -/ def CircleIntegrable (f : ℂ → E) (c : ℂ) (R : ℝ) : Prop := IntervalIntegrable (fun θ : ℝ => f (circleMap c R θ)) volume 0 (2 * π) #align circle_integrable CircleIntegrable @[simp] theorem circleIntegrable_const (a : E) (c : ℂ) (R : ℝ) : CircleIntegrable (fun _ => a) c R := intervalIntegrable_const #align circle_integrable_const circleIntegrable_const namespace CircleIntegrable variable {f g : ℂ → E} {c : ℂ} {R : ℝ} nonrec theorem add (hf : CircleIntegrable f c R) (hg : CircleIntegrable g c R) : CircleIntegrable (f + g) c R := hf.add hg #align circle_integrable.add CircleIntegrable.add nonrec theorem neg (hf : CircleIntegrable f c R) : CircleIntegrable (-f) c R := hf.neg #align circle_integrable.neg CircleIntegrable.neg /-- The function we actually integrate over `[0, 2π]` in the definition of `circleIntegral` is integrable. -/ theorem out [NormedSpace ℂ E] (hf : CircleIntegrable f c R) : IntervalIntegrable (fun θ : ℝ => deriv (circleMap c R) θ • f (circleMap c R θ)) volume 0 (2 * π) := by simp only [CircleIntegrable, deriv_circleMap, intervalIntegrable_iff] at * refine (hf.norm.const_mul |R|).mono' ?_ ?_ · exact ((continuous_circleMap _ _).aestronglyMeasurable.mul_const I).smul hf.aestronglyMeasurable · simp [norm_smul] #align circle_integrable.out CircleIntegrable.out end CircleIntegrable @[simp] theorem circleIntegrable_zero_radius {f : ℂ → E} {c : ℂ} : CircleIntegrable f c 0 := by simp [CircleIntegrable] #align circle_integrable_zero_radius circleIntegrable_zero_radius theorem circleIntegrable_iff [NormedSpace ℂ E] {f : ℂ → E} {c : ℂ} (R : ℝ) : CircleIntegrable f c R ↔ IntervalIntegrable (fun θ : ℝ => deriv (circleMap c R) θ • f (circleMap c R θ)) volume 0 (2 * π) := by by_cases h₀ : R = 0 · simp (config := { unfoldPartialApp := true }) [h₀, const] refine ⟨fun h => h.out, fun h => ?_⟩ simp only [CircleIntegrable, intervalIntegrable_iff, deriv_circleMap] at h ⊢ refine (h.norm.const_mul |R|⁻¹).mono' ?_ ?_ · have H : ∀ {θ}, circleMap 0 R θ * I ≠ 0 := fun {θ} => by simp [h₀, I_ne_zero] simpa only [inv_smul_smul₀ H] using ((continuous_circleMap 0 R).aestronglyMeasurable.mul_const I).aemeasurable.inv.aestronglyMeasurable.smul h.aestronglyMeasurable · simp [norm_smul, h₀] #align circle_integrable_iff circleIntegrable_iff theorem ContinuousOn.circleIntegrable' {f : ℂ → E} {c : ℂ} {R : ℝ} (hf : ContinuousOn f (sphere c |R|)) : CircleIntegrable f c R := (hf.comp_continuous (continuous_circleMap _ _) (circleMap_mem_sphere' _ _)).intervalIntegrable _ _ #align continuous_on.circle_integrable' ContinuousOn.circleIntegrable' theorem ContinuousOn.circleIntegrable {f : ℂ → E} {c : ℂ} {R : ℝ} (hR : 0 ≤ R) (hf : ContinuousOn f (sphere c R)) : CircleIntegrable f c R := ContinuousOn.circleIntegrable' <| (_root_.abs_of_nonneg hR).symm ▸ hf #align continuous_on.circle_integrable ContinuousOn.circleIntegrable #adaptation_note /-- nightly-2024-04-01: the simpNF linter now times out on this lemma. -/ /-- The function `fun z ↦ (z - w) ^ n`, `n : ℤ`, is circle integrable on the circle with center `c` and radius `|R|` if and only if `R = 0` or `0 ≤ n`, or `w` does not belong to this circle. -/ @[simp, nolint simpNF] theorem circleIntegrable_sub_zpow_iff {c w : ℂ} {R : ℝ} {n : ℤ} : CircleIntegrable (fun z => (z - w) ^ n) c R ↔ R = 0 ∨ 0 ≤ n ∨ w ∉ sphere c |R| := by constructor · intro h; contrapose! h; rcases h with ⟨hR, hn, hw⟩ simp only [circleIntegrable_iff R, deriv_circleMap] rw [← image_circleMap_Ioc] at hw; rcases hw with ⟨θ, hθ, rfl⟩ replace hθ : θ ∈ [[0, 2 * π]] := Icc_subset_uIcc (Ioc_subset_Icc_self hθ) refine not_intervalIntegrable_of_sub_inv_isBigO_punctured ?_ Real.two_pi_pos.ne hθ set f : ℝ → ℂ := fun θ' => circleMap c R θ' - circleMap c R θ have : ∀ᶠ θ' in 𝓝[≠] θ, f θ' ∈ ball (0 : ℂ) 1 \ {0} := by suffices ∀ᶠ z in 𝓝[≠] circleMap c R θ, z - circleMap c R θ ∈ ball (0 : ℂ) 1 \ {0} from ((differentiable_circleMap c R θ).hasDerivAt.tendsto_punctured_nhds (deriv_circleMap_ne_zero hR)).eventually this filter_upwards [self_mem_nhdsWithin, mem_nhdsWithin_of_mem_nhds (ball_mem_nhds _ zero_lt_one)] simp_all [dist_eq, sub_eq_zero] refine (((hasDerivAt_circleMap c R θ).isBigO_sub.mono inf_le_left).inv_rev (this.mono fun θ' h₁ h₂ => absurd h₂ h₁.2)).trans ?_ refine IsBigO.of_bound |R|⁻¹ (this.mono fun θ' hθ' => ?_) set x := abs (f θ') suffices x⁻¹ ≤ x ^ n by simpa only [inv_mul_cancel_left₀, abs_eq_zero.not.2 hR, norm_eq_abs, map_inv₀, Algebra.id.smul_eq_mul, map_mul, abs_circleMap_zero, abs_I, mul_one, abs_zpow, Ne, not_false_iff] using this have : x ∈ Ioo (0 : ℝ) 1 := by simpa [x, and_comm] using hθ' rw [← zpow_neg_one] refine (zpow_strictAnti this.1 this.2).le_iff_le.2 (Int.lt_add_one_iff.1 ?_); exact hn · rintro (rfl | H) exacts [circleIntegrable_zero_radius, ((continuousOn_id.sub continuousOn_const).zpow₀ _ fun z hz => H.symm.imp_left fun (hw : w ∉ sphere c |R|) => sub_ne_zero.2 <| ne_of_mem_of_not_mem hz hw).circleIntegrable'] #align circle_integrable_sub_zpow_iff circleIntegrable_sub_zpow_iff #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. -/ @[simp, nolint simpNF] theorem circleIntegrable_sub_inv_iff {c w : ℂ} {R : ℝ} : CircleIntegrable (fun z => (z - w)⁻¹) c R ↔ R = 0 ∨ w ∉ sphere c |R| := by simp only [← zpow_neg_one, circleIntegrable_sub_zpow_iff]; norm_num #align circle_integrable_sub_inv_iff circleIntegrable_sub_inv_iff variable [NormedSpace ℂ E] [CompleteSpace E] /-- Definition for $\oint_{|z-c|=R} f(z)\,dz$. -/ def circleIntegral (f : ℂ → E) (c : ℂ) (R : ℝ) : E := ∫ θ : ℝ in (0)..2 * π, deriv (circleMap c R) θ • f (circleMap c R θ) #align circle_integral circleIntegral notation3 "∮ "(...)" in ""C("c", "R")"", "r:(scoped f => circleIntegral f c R) => r theorem circleIntegral_def_Icc (f : ℂ → E) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), f z) = ∫ θ in Icc 0 (2 * π), deriv (circleMap c R) θ • f (circleMap c R θ) := by rw [circleIntegral, intervalIntegral.integral_of_le Real.two_pi_pos.le, Measure.restrict_congr_set Ioc_ae_eq_Icc] #align circle_integral_def_Icc circleIntegral_def_Icc namespace circleIntegral @[simp] theorem integral_radius_zero (f : ℂ → E) (c : ℂ) : (∮ z in C(c, 0), f z) = 0 := by simp (config := { unfoldPartialApp := true }) [circleIntegral, const] #align circle_integral.integral_radius_zero circleIntegral.integral_radius_zero theorem integral_congr {f g : ℂ → E} {c : ℂ} {R : ℝ} (hR : 0 ≤ R) (h : EqOn f g (sphere c R)) : (∮ z in C(c, R), f z) = ∮ z in C(c, R), g z := intervalIntegral.integral_congr fun θ _ => by simp only [h (circleMap_mem_sphere _ hR _)] #align circle_integral.integral_congr circleIntegral.integral_congr theorem integral_sub_inv_smul_sub_smul (f : ℂ → E) (c w : ℂ) (R : ℝ) : (∮ z in C(c, R), (z - w)⁻¹ • (z - w) • f z) = ∮ z in C(c, R), f z := by rcases eq_or_ne R 0 with (rfl | hR); · simp only [integral_radius_zero] have : (circleMap c R ⁻¹' {w}).Countable := (countable_singleton _).preimage_circleMap c hR refine intervalIntegral.integral_congr_ae ((this.ae_not_mem _).mono fun θ hθ _' => ?_) change circleMap c R θ ≠ w at hθ simp only [inv_smul_smul₀ (sub_ne_zero.2 <| hθ)] #align circle_integral.integral_sub_inv_smul_sub_smul circleIntegral.integral_sub_inv_smul_sub_smul theorem integral_undef {f : ℂ → E} {c : ℂ} {R : ℝ} (hf : ¬CircleIntegrable f c R) : (∮ z in C(c, R), f z) = 0 := intervalIntegral.integral_undef (mt (circleIntegrable_iff R).mpr hf) #align circle_integral.integral_undef circleIntegral.integral_undef theorem integral_sub {f g : ℂ → E} {c : ℂ} {R : ℝ} (hf : CircleIntegrable f c R) (hg : CircleIntegrable g c R) : (∮ z in C(c, R), f z - g z) = (∮ z in C(c, R), f z) - ∮ z in C(c, R), g z := by simp only [circleIntegral, smul_sub, intervalIntegral.integral_sub hf.out hg.out] #align circle_integral.integral_sub circleIntegral.integral_sub theorem norm_integral_le_of_norm_le_const' {f : ℂ → E} {c : ℂ} {R C : ℝ} (hf : ∀ z ∈ sphere c |R|, ‖f z‖ ≤ C) : ‖∮ z in C(c, R), f z‖ ≤ 2 * π * |R| * C := calc ‖∮ z in C(c, R), f z‖ ≤ |R| * C * |2 * π - 0| := intervalIntegral.norm_integral_le_of_norm_le_const fun θ _ => calc ‖deriv (circleMap c R) θ • f (circleMap c R θ)‖ = |R| * ‖f (circleMap c R θ)‖ := by simp [norm_smul] _ ≤ |R| * C := mul_le_mul_of_nonneg_left (hf _ <| circleMap_mem_sphere' _ _ _) (abs_nonneg _) _ = 2 * π * |R| * C := by rw [sub_zero, _root_.abs_of_pos Real.two_pi_pos]; ac_rfl #align circle_integral.norm_integral_le_of_norm_le_const' circleIntegral.norm_integral_le_of_norm_le_const' theorem norm_integral_le_of_norm_le_const {f : ℂ → E} {c : ℂ} {R C : ℝ} (hR : 0 ≤ R) (hf : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) : ‖∮ z in C(c, R), f z‖ ≤ 2 * π * R * C := have : |R| = R := abs_of_nonneg hR calc ‖∮ z in C(c, R), f z‖ ≤ 2 * π * |R| * C := norm_integral_le_of_norm_le_const' <| by rwa [this] _ = 2 * π * R * C := by rw [this] #align circle_integral.norm_integral_le_of_norm_le_const circleIntegral.norm_integral_le_of_norm_le_const theorem norm_two_pi_i_inv_smul_integral_le_of_norm_le_const {f : ℂ → E} {c : ℂ} {R C : ℝ} (hR : 0 ≤ R) (hf : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) : ‖(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), f z‖ ≤ R * C := by have : ‖(2 * π * I : ℂ)⁻¹‖ = (2 * π)⁻¹ := by simp [Real.pi_pos.le] rw [norm_smul, this, ← div_eq_inv_mul, div_le_iff Real.two_pi_pos, mul_comm (R * C), ← mul_assoc] exact norm_integral_le_of_norm_le_const hR hf set_option linter.uppercaseLean3 false in #align circle_integral.norm_two_pi_I_inv_smul_integral_le_of_norm_le_const circleIntegral.norm_two_pi_i_inv_smul_integral_le_of_norm_le_const /-- If `f` is continuous on the circle `|z - c| = R`, `R > 0`, the `‖f z‖` is less than or equal to `C : ℝ` on this circle, and this norm is strictly less than `C` at some point `z` of the circle, then `‖∮ z in C(c, R), f z‖ < 2 * π * R * C`. -/ theorem norm_integral_lt_of_norm_le_const_of_lt {f : ℂ → E} {c : ℂ} {R C : ℝ} (hR : 0 < R) (hc : ContinuousOn f (sphere c R)) (hf : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) (hlt : ∃ z ∈ sphere c R, ‖f z‖ < C) : ‖∮ z in C(c, R), f z‖ < 2 * π * R * C := by rw [← _root_.abs_of_pos hR, ← image_circleMap_Ioc] at hlt rcases hlt with ⟨_, ⟨θ₀, hmem, rfl⟩, hlt⟩ calc ‖∮ z in C(c, R), f z‖ ≤ ∫ θ in (0)..2 * π, ‖deriv (circleMap c R) θ • f (circleMap c R θ)‖ := intervalIntegral.norm_integral_le_integral_norm Real.two_pi_pos.le _ < ∫ _ in (0)..2 * π, R * C := by simp only [norm_smul, deriv_circleMap, norm_eq_abs, map_mul, abs_I, mul_one, abs_circleMap_zero, abs_of_pos hR] refine intervalIntegral.integral_lt_integral_of_continuousOn_of_le_of_exists_lt Real.two_pi_pos ?_ continuousOn_const (fun θ _ => ?_) ⟨θ₀, Ioc_subset_Icc_self hmem, ?_⟩ · exact continuousOn_const.mul (hc.comp (continuous_circleMap _ _).continuousOn fun θ _ => circleMap_mem_sphere _ hR.le _).norm · exact mul_le_mul_of_nonneg_left (hf _ <| circleMap_mem_sphere _ hR.le _) hR.le · exact (mul_lt_mul_left hR).2 hlt _ = 2 * π * R * C := by simp [mul_assoc]; ring #align circle_integral.norm_integral_lt_of_norm_le_const_of_lt circleIntegral.norm_integral_lt_of_norm_le_const_of_lt @[simp] theorem integral_smul {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [SMulCommClass 𝕜 ℂ E] (a : 𝕜) (f : ℂ → E) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), a • f z) = a • ∮ z in C(c, R), f z := by simp only [circleIntegral, ← smul_comm a (_ : ℂ) (_ : E), intervalIntegral.integral_smul] #align circle_integral.integral_smul circleIntegral.integral_smul @[simp] theorem integral_smul_const (f : ℂ → ℂ) (a : E) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), f z • a) = (∮ z in C(c, R), f z) • a := by simp only [circleIntegral, intervalIntegral.integral_smul_const, ← smul_assoc] #align circle_integral.integral_smul_const circleIntegral.integral_smul_const @[simp] theorem integral_const_mul (a : ℂ) (f : ℂ → ℂ) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), a * f z) = a * ∮ z in C(c, R), f z := integral_smul a f c R #align circle_integral.integral_const_mul circleIntegral.integral_const_mul @[simp]
Mathlib/MeasureTheory/Integral/CircleIntegral.lean
462
466
theorem integral_sub_center_inv (c : ℂ) {R : ℝ} (hR : R ≠ 0) : (∮ z in C(c, R), (z - c)⁻¹) = 2 * π * I := by
simp [circleIntegral, ← div_eq_mul_inv, mul_div_cancel_left₀ _ (circleMap_ne_center hR), -- Porting note: `simp` didn't need a hint to apply `integral_const` here intervalIntegral.integral_const I]
/- Copyright (c) 2022 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.Algebra.Group.Subgroup.Actions import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.GroupAction.FixedPoints #align_import group_theory.group_action.fixing_subgroup from "leanprover-community/mathlib"@"f93c11933efbc3c2f0299e47b8ff83e9b539cbf6" /-! # Fixing submonoid, fixing subgroup of an action In the presence of an action of a monoid or a group, this file defines the fixing submonoid or the fixing subgroup, and relates it to the set of fixed points via a Galois connection. ## Main definitions * `fixingSubmonoid M s` : in the presence of `MulAction M α` (with `Monoid M`) it is the `Submonoid M` consisting of elements which fix `s : Set α` pointwise. * `fixingSubmonoid_fixedPoints_gc M α` is the `GaloisConnection` that relates `fixingSubmonoid` with `fixedPoints`. * `fixingSubgroup M s` : in the presence of `MulAction M α` (with `Group M`) it is the `Subgroup M` consisting of elements which fix `s : Set α` pointwise. * `fixingSubgroup_fixedPoints_gc M α` is the `GaloisConnection` that relates `fixingSubgroup` with `fixedPoints`. TODO : * Maybe other lemmas are useful * Treat semigroups ? * add `to_additive` for the various lemmas -/ section Monoid open MulAction variable (M : Type*) {α : Type*} [Monoid M] [MulAction M α] /-- The submonoid fixing a set under a `MulAction`. -/ @[to_additive " The additive submonoid fixing a set under an `AddAction`. "] def fixingSubmonoid (s : Set α) : Submonoid M where carrier := { ϕ : M | ∀ x : s, ϕ • (x : α) = x } one_mem' _ := one_smul _ _ mul_mem' {x y} hx hy z := by rw [mul_smul, hy z, hx z] #align fixing_submonoid fixingSubmonoid #align fixing_add_submonoid fixingAddSubmonoid theorem mem_fixingSubmonoid_iff {s : Set α} {m : M} : m ∈ fixingSubmonoid M s ↔ ∀ y ∈ s, m • y = y := ⟨fun hg y hy => hg ⟨y, hy⟩, fun h ⟨y, hy⟩ => h y hy⟩ #align mem_fixing_submonoid_iff mem_fixingSubmonoid_iff variable (α) /-- The Galois connection between fixing submonoids and fixed points of a monoid action -/ theorem fixingSubmonoid_fixedPoints_gc : GaloisConnection (OrderDual.toDual ∘ fixingSubmonoid M) ((fun P : Submonoid M => fixedPoints P α) ∘ OrderDual.ofDual) := fun _s _P => ⟨fun h s hs p => h p.2 ⟨s, hs⟩, fun h p hp s => h s.2 ⟨p, hp⟩⟩ #align fixing_submonoid_fixed_points_gc fixingSubmonoid_fixedPoints_gc theorem fixingSubmonoid_antitone : Antitone fun s : Set α => fixingSubmonoid M s := (fixingSubmonoid_fixedPoints_gc M α).monotone_l #align fixing_submonoid_antitone fixingSubmonoid_antitone theorem fixedPoints_antitone : Antitone fun P : Submonoid M => fixedPoints P α := (fixingSubmonoid_fixedPoints_gc M α).monotone_u.dual_left #align fixed_points_antitone fixedPoints_antitone /-- Fixing submonoid of union is intersection -/ theorem fixingSubmonoid_union {s t : Set α} : fixingSubmonoid M (s ∪ t) = fixingSubmonoid M s ⊓ fixingSubmonoid M t := (fixingSubmonoid_fixedPoints_gc M α).l_sup #align fixing_submonoid_union fixingSubmonoid_union /-- Fixing submonoid of iUnion is intersection -/ theorem fixingSubmonoid_iUnion {ι : Sort*} {s : ι → Set α} : fixingSubmonoid M (⋃ i, s i) = ⨅ i, fixingSubmonoid M (s i) := (fixingSubmonoid_fixedPoints_gc M α).l_iSup #align fixing_submonoid_Union fixingSubmonoid_iUnion /-- Fixed points of sup of submonoids is intersection -/ theorem fixedPoints_submonoid_sup {P Q : Submonoid M} : fixedPoints (↥(P ⊔ Q)) α = fixedPoints P α ∩ fixedPoints Q α := (fixingSubmonoid_fixedPoints_gc M α).u_inf #align fixed_points_submonoid_sup fixedPoints_submonoid_sup /-- Fixed points of iSup of submonoids is intersection -/ theorem fixedPoints_submonoid_iSup {ι : Sort*} {P : ι → Submonoid M} : fixedPoints (↥(iSup P)) α = ⋂ i, fixedPoints (P i) α := (fixingSubmonoid_fixedPoints_gc M α).u_iInf #align fixed_points_submonoid_supr fixedPoints_submonoid_iSup end Monoid section Group open MulAction variable (M : Type*) {α : Type*} [Group M] [MulAction M α] /-- The subgroup fixing a set under a `MulAction`. -/ @[to_additive " The additive subgroup fixing a set under an `AddAction`. "] def fixingSubgroup (s : Set α) : Subgroup M := { fixingSubmonoid M s with inv_mem' := fun hx z => by rw [inv_smul_eq_iff, hx z] } #align fixing_subgroup fixingSubgroup #align fixing_add_subgroup fixingAddSubgroup theorem mem_fixingSubgroup_iff {s : Set α} {m : M} : m ∈ fixingSubgroup M s ↔ ∀ y ∈ s, m • y = y := ⟨fun hg y hy => hg ⟨y, hy⟩, fun h ⟨y, hy⟩ => h y hy⟩ #align mem_fixing_subgroup_iff mem_fixingSubgroup_iff
Mathlib/GroupTheory/GroupAction/FixingSubgroup.lean
125
127
theorem mem_fixingSubgroup_iff_subset_fixedBy {s : Set α} {m : M} : m ∈ fixingSubgroup M s ↔ s ⊆ fixedBy α m := by
simp_rw [mem_fixingSubgroup_iff, Set.subset_def, mem_fixedBy]
/- 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.Interval.Set.Basic import Mathlib.Data.Set.Lattice import Mathlib.Data.SetLike.Basic #align_import order.interval from "leanprover-community/mathlib"@"6623e6af705e97002a9054c1c05a980180276fc1" /-! # Order intervals This file defines (nonempty) closed intervals in an order (see `Set.Icc`). This is a prototype for interval arithmetic. ## Main declarations * `NonemptyInterval`: Nonempty intervals. Pairs where the second element is greater than the first. * `Interval`: Intervals. Either `∅` or a nonempty interval. -/ open Function OrderDual Set variable {α β γ δ : Type*} {ι : Sort*} {κ : ι → Sort*} /-- The nonempty closed intervals in an order. We define intervals by the pair of endpoints `fst`, `snd`. To convert intervals to the set of elements between these endpoints, use the coercion `NonemptyInterval α → Set α`. -/ @[ext (flat := false)] structure NonemptyInterval (α : Type*) [LE α] extends Prod α α where /-- The starting point of an interval is smaller than the endpoint. -/ fst_le_snd : fst ≤ snd #align nonempty_interval NonemptyInterval #align nonempty_interval.ext NonemptyInterval.ext #align nonempty_interval.ext_iff NonemptyInterval.ext_iff namespace NonemptyInterval section LE variable [LE α] {s t : NonemptyInterval α} theorem toProd_injective : Injective (toProd : NonemptyInterval α → α × α) := fun s t h => by cases s; cases t; congr #align nonempty_interval.to_prod_injective NonemptyInterval.toProd_injective /-- The injection that induces the order on intervals. -/ def toDualProd : NonemptyInterval α → αᵒᵈ × α := toProd #align nonempty_interval.to_dual_prod NonemptyInterval.toDualProd @[simp] theorem toDualProd_apply (s : NonemptyInterval α) : s.toDualProd = (toDual s.fst, s.snd) := rfl #align nonempty_interval.to_dual_prod_apply NonemptyInterval.toDualProd_apply theorem toDualProd_injective : Injective (toDualProd : NonemptyInterval α → αᵒᵈ × α) := toProd_injective #align nonempty_interval.to_dual_prod_injective NonemptyInterval.toDualProd_injective instance [IsEmpty α] : IsEmpty (NonemptyInterval α) := ⟨fun s => isEmptyElim s.fst⟩ instance [Subsingleton α] : Subsingleton (NonemptyInterval α) := toDualProd_injective.subsingleton instance le : LE (NonemptyInterval α) := ⟨fun s t => t.fst ≤ s.fst ∧ s.snd ≤ t.snd⟩ theorem le_def : s ≤ t ↔ t.fst ≤ s.fst ∧ s.snd ≤ t.snd := Iff.rfl #align nonempty_interval.le_def NonemptyInterval.le_def /-- `toDualProd` as an order embedding. -/ @[simps] def toDualProdHom : NonemptyInterval α ↪o αᵒᵈ × α where toFun := toDualProd inj' := toDualProd_injective map_rel_iff' := Iff.rfl #align nonempty_interval.to_dual_prod_hom NonemptyInterval.toDualProdHom /-- Turn an interval into an interval in the dual order. -/ def dual : NonemptyInterval α ≃ NonemptyInterval αᵒᵈ where toFun s := ⟨s.toProd.swap, s.fst_le_snd⟩ invFun s := ⟨s.toProd.swap, s.fst_le_snd⟩ left_inv _ := rfl right_inv _ := rfl #align nonempty_interval.dual NonemptyInterval.dual @[simp] theorem fst_dual (s : NonemptyInterval α) : s.dual.fst = toDual s.snd := rfl #align nonempty_interval.fst_dual NonemptyInterval.fst_dual @[simp] theorem snd_dual (s : NonemptyInterval α) : s.dual.snd = toDual s.fst := rfl #align nonempty_interval.snd_dual NonemptyInterval.snd_dual end LE section Preorder variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] {s : NonemptyInterval α} {x : α × α} {a : α} instance : Preorder (NonemptyInterval α) := Preorder.lift toDualProd instance : Coe (NonemptyInterval α) (Set α) := ⟨fun s => Icc s.fst s.snd⟩ instance (priority := 100) : Membership α (NonemptyInterval α) := ⟨fun a s => a ∈ (s : Set α)⟩ @[simp] theorem mem_mk {hx : x.1 ≤ x.2} : a ∈ mk x hx ↔ x.1 ≤ a ∧ a ≤ x.2 := Iff.rfl #align nonempty_interval.mem_mk NonemptyInterval.mem_mk theorem mem_def : a ∈ s ↔ s.fst ≤ a ∧ a ≤ s.snd := Iff.rfl #align nonempty_interval.mem_def NonemptyInterval.mem_def -- @[simp] -- Porting note: not in simpNF theorem coe_nonempty (s : NonemptyInterval α) : (s : Set α).Nonempty := nonempty_Icc.2 s.fst_le_snd #align nonempty_interval.coe_nonempty NonemptyInterval.coe_nonempty /-- `{a}` as an interval. -/ @[simps] def pure (a : α) : NonemptyInterval α := ⟨⟨a, a⟩, le_rfl⟩ #align nonempty_interval.pure NonemptyInterval.pure theorem mem_pure_self (a : α) : a ∈ pure a := ⟨le_rfl, le_rfl⟩ #align nonempty_interval.mem_pure_self NonemptyInterval.mem_pure_self theorem pure_injective : Injective (pure : α → NonemptyInterval α) := fun _ _ => congr_arg <| Prod.fst ∘ toProd #align nonempty_interval.pure_injective NonemptyInterval.pure_injective @[simp] theorem dual_pure (a : α) : dual (pure a) = pure (toDual a) := rfl #align nonempty_interval.dual_pure NonemptyInterval.dual_pure instance [Inhabited α] : Inhabited (NonemptyInterval α) := ⟨pure default⟩ instance [Nonempty α] : Nonempty (NonemptyInterval α) := Nonempty.map pure (by infer_instance) instance [Nontrivial α] : Nontrivial (NonemptyInterval α) := pure_injective.nontrivial /-- Pushforward of nonempty intervals. -/ @[simps!] def map (f : α →o β) (a : NonemptyInterval α) : NonemptyInterval β := ⟨a.toProd.map f f, f.mono a.fst_le_snd⟩ #align nonempty_interval.map NonemptyInterval.map @[simp] theorem map_pure (f : α →o β) (a : α) : (pure a).map f = pure (f a) := rfl #align nonempty_interval.map_pure NonemptyInterval.map_pure @[simp] theorem map_map (g : β →o γ) (f : α →o β) (a : NonemptyInterval α) : (a.map f).map g = a.map (g.comp f) := rfl #align nonempty_interval.map_map NonemptyInterval.map_map @[simp] theorem dual_map (f : α →o β) (a : NonemptyInterval α) : dual (a.map f) = a.dual.map (OrderHom.dual f) := rfl #align nonempty_interval.dual_map NonemptyInterval.dual_map /-- Binary pushforward of nonempty intervals. -/ @[simps] def map₂ (f : α → β → γ) (h₀ : ∀ b, Monotone fun a => f a b) (h₁ : ∀ a, Monotone (f a)) : NonemptyInterval α → NonemptyInterval β → NonemptyInterval γ := fun s t => ⟨(f s.fst t.fst, f s.snd t.snd), (h₀ _ s.fst_le_snd).trans <| h₁ _ t.fst_le_snd⟩ #align nonempty_interval.map₂ NonemptyInterval.map₂ @[simp] theorem map₂_pure (f : α → β → γ) (h₀ h₁) (a : α) (b : β) : map₂ f h₀ h₁ (pure a) (pure b) = pure (f a b) := rfl #align nonempty_interval.map₂_pure NonemptyInterval.map₂_pure @[simp] theorem dual_map₂ (f : α → β → γ) (h₀ h₁ s t) : dual (map₂ f h₀ h₁ s t) = map₂ (fun a b => toDual <| f (ofDual a) <| ofDual b) (fun _ => (h₀ _).dual) (fun _ => (h₁ _).dual) (dual s) (dual t) := rfl #align nonempty_interval.dual_map₂ NonemptyInterval.dual_map₂ variable [BoundedOrder α] instance : OrderTop (NonemptyInterval α) where top := ⟨⟨⊥, ⊤⟩, bot_le⟩ le_top _ := ⟨bot_le, le_top⟩ @[simp] theorem dual_top : dual (⊤ : NonemptyInterval α) = ⊤ := rfl #align nonempty_interval.dual_top NonemptyInterval.dual_top end Preorder section PartialOrder variable [PartialOrder α] [PartialOrder β] {s t : NonemptyInterval α} {x : α × α} {a b : α} instance : PartialOrder (NonemptyInterval α) := PartialOrder.lift _ toDualProd_injective /-- Consider a nonempty interval `[a, b]` as the set `[a, b]`. -/ def coeHom : NonemptyInterval α ↪o Set α := OrderEmbedding.ofMapLEIff (fun s => Icc s.fst s.snd) fun s _ => Icc_subset_Icc_iff s.fst_le_snd #align nonempty_interval.coe_hom NonemptyInterval.coeHom instance setLike : SetLike (NonemptyInterval α) α where coe s := Icc s.fst s.snd coe_injective' := coeHom.injective @[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF theorem coe_subset_coe : (s : Set α) ⊆ t ↔ (s : NonemptyInterval α) ≤ t := (@coeHom α _).le_iff_le #align nonempty_interval.coe_subset_coe NonemptyInterval.coe_subset_coe @[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF theorem coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := (@coeHom α _).lt_iff_lt #align nonempty_interval.coe_ssubset_coe NonemptyInterval.coe_ssubset_coe @[simp] theorem coe_coeHom : (coeHom : NonemptyInterval α → Set α) = ((↑) : NonemptyInterval α → Set α) := rfl #align nonempty_interval.coe_coe_hom NonemptyInterval.coe_coeHom theorem coe_def (s : NonemptyInterval α) : (s : Set α) = Set.Icc s.toProd.1 s.toProd.2 := rfl @[simp, norm_cast] theorem coe_pure (a : α) : (pure a : Set α) = {a} := Icc_self _ #align nonempty_interval.coe_pure NonemptyInterval.coe_pure @[simp] theorem mem_pure : b ∈ pure a ↔ b = a := by rw [← SetLike.mem_coe, coe_pure, mem_singleton_iff] #align nonempty_interval.mem_pure NonemptyInterval.mem_pure @[simp, norm_cast] theorem coe_top [BoundedOrder α] : ((⊤ : NonemptyInterval α) : Set α) = univ := Icc_bot_top #align nonempty_interval.coe_top NonemptyInterval.coe_top @[simp, norm_cast] theorem coe_dual (s : NonemptyInterval α) : (dual s : Set αᵒᵈ) = ofDual ⁻¹' s := dual_Icc #align nonempty_interval.coe_dual NonemptyInterval.coe_dual theorem subset_coe_map (f : α →o β) (s : NonemptyInterval α) : f '' s ⊆ s.map f := image_subset_iff.2 fun _ ha => ⟨f.mono ha.1, f.mono ha.2⟩ #align nonempty_interval.subset_coe_map NonemptyInterval.subset_coe_map end PartialOrder section Lattice variable [Lattice α] instance : Sup (NonemptyInterval α) := ⟨fun s t => ⟨⟨s.fst ⊓ t.fst, s.snd ⊔ t.snd⟩, inf_le_left.trans <| s.fst_le_snd.trans le_sup_left⟩⟩ instance : SemilatticeSup (NonemptyInterval α) := toDualProd_injective.semilatticeSup _ fun _ _ => rfl @[simp] theorem fst_sup (s t : NonemptyInterval α) : (s ⊔ t).fst = s.fst ⊓ t.fst := rfl #align nonempty_interval.fst_sup NonemptyInterval.fst_sup @[simp] theorem snd_sup (s t : NonemptyInterval α) : (s ⊔ t).snd = s.snd ⊔ t.snd := rfl #align nonempty_interval.snd_sup NonemptyInterval.snd_sup end Lattice end NonemptyInterval /-- The closed intervals in an order. We represent intervals either as `⊥` or a nonempty interval given by its endpoints `fst`, `snd`. To convert intervals to the set of elements between these endpoints, use the coercion `Interval α → Set α`. -/ -- Porting note: added reducible, it seems to help with coercions abbrev Interval (α : Type*) [LE α] := WithBot (NonemptyInterval α) -- deriving Inhabited, LE, OrderBot #align interval Interval namespace Interval section LE variable [LE α] {s t : Interval α} -- Porting note: previously found using `deriving` instance : Inhabited (Interval α) := WithBot.inhabited instance : LE (Interval α) := WithBot.le instance : OrderBot (Interval α) := WithBot.orderBot instance : Coe (NonemptyInterval α) (Interval α) := WithBot.coe instance canLift : CanLift (Interval α) (NonemptyInterval α) (↑) fun r => r ≠ ⊥ := WithBot.canLift #align interval.can_lift Interval.canLift /-- Recursor for `Interval` using the preferred forms `⊥` and `↑a`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recBotCoe {C : Interval α → Sort*} (bot : C ⊥) (coe : ∀ a : NonemptyInterval α, C a) : ∀ n : Interval α, C n := WithBot.recBotCoe bot coe theorem coe_injective : Injective ((↑) : NonemptyInterval α → Interval α) := WithBot.coe_injective #align interval.coe_injective Interval.coe_injective @[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF theorem coe_inj {s t : NonemptyInterval α} : (s : Interval α) = t ↔ s = t := WithBot.coe_inj #align interval.coe_inj Interval.coe_inj protected theorem «forall» {p : Interval α → Prop} : (∀ s, p s) ↔ p ⊥ ∧ ∀ s : NonemptyInterval α, p s := Option.forall #align interval.forall Interval.forall protected theorem «exists» {p : Interval α → Prop} : (∃ s, p s) ↔ p ⊥ ∨ ∃ s : NonemptyInterval α, p s := Option.exists #align interval.exists Interval.exists instance [IsEmpty α] : Unique (Interval α) := inferInstanceAs <| Unique (Option _) /-- Turn an interval into an interval in the dual order. -/ def dual : Interval α ≃ Interval αᵒᵈ := NonemptyInterval.dual.optionCongr #align interval.dual Interval.dual end LE section Preorder variable [Preorder α] [Preorder β] [Preorder γ] instance : Preorder (Interval α) := WithBot.preorder /-- `{a}` as an interval. -/ def pure (a : α) : Interval α := NonemptyInterval.pure a #align interval.pure Interval.pure theorem pure_injective : Injective (pure : α → Interval α) := coe_injective.comp NonemptyInterval.pure_injective #align interval.pure_injective Interval.pure_injective @[simp] theorem dual_pure (a : α) : dual (pure a) = pure (toDual a) := rfl #align interval.dual_pure Interval.dual_pure @[simp] theorem dual_bot : dual (⊥ : Interval α) = ⊥ := rfl #align interval.dual_bot Interval.dual_bot @[simp] theorem pure_ne_bot {a : α} : pure a ≠ ⊥ := WithBot.coe_ne_bot #align interval.pure_ne_bot Interval.pure_ne_bot @[simp] theorem bot_ne_pure {a : α} : ⊥ ≠ pure a := WithBot.bot_ne_coe #align interval.bot_ne_pure Interval.bot_ne_pure instance [Nonempty α] : Nontrivial (Interval α) := Option.nontrivial /-- Pushforward of intervals. -/ def map (f : α →o β) : Interval α → Interval β := WithBot.map (NonemptyInterval.map f) #align interval.map Interval.map @[simp] theorem map_pure (f : α →o β) (a : α) : (pure a).map f = pure (f a) := rfl #align interval.map_pure Interval.map_pure @[simp] theorem map_map (g : β →o γ) (f : α →o β) (s : Interval α) : (s.map f).map g = s.map (g.comp f) := Option.map_map _ _ _ #align interval.map_map Interval.map_map @[simp] theorem dual_map (f : α →o β) (s : Interval α) : dual (s.map f) = s.dual.map (OrderHom.dual f) := by cases s · rfl · exact WithBot.map_comm rfl _ #align interval.dual_map Interval.dual_map variable [BoundedOrder α] instance boundedOrder : BoundedOrder (Interval α) := WithBot.instBoundedOrder @[simp] theorem dual_top : dual (⊤ : Interval α) = ⊤ := rfl #align interval.dual_top Interval.dual_top end Preorder section PartialOrder variable [PartialOrder α] [PartialOrder β] {s t : Interval α} {a b : α} instance partialOrder : PartialOrder (Interval α) := WithBot.partialOrder /-- Consider an interval `[a, b]` as the set `[a, b]`. -/ def coeHom : Interval α ↪o Set α := OrderEmbedding.ofMapLEIff (fun s => match s with | ⊥ => ∅ | some s => s) fun s t => match s, t with | ⊥, _ => iff_of_true bot_le bot_le | some s, ⊥ => iff_of_false (fun h => s.coe_nonempty.ne_empty <| le_bot_iff.1 h) (WithBot.not_coe_le_bot _) | some _, some _ => (@NonemptyInterval.coeHom α _).le_iff_le.trans WithBot.coe_le_coe.symm #align interval.coe_hom Interval.coeHom instance setLike : SetLike (Interval α) α where coe := coeHom coe_injective' := coeHom.injective @[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF theorem coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t := (@coeHom α _).le_iff_le #align interval.coe_subset_coe Interval.coe_subset_coe @[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF theorem coe_sSubset_coe : (s : Set α) ⊂ t ↔ s < t := (@coeHom α _).lt_iff_lt #align interval.coe_ssubset_coe Interval.coe_sSubset_coe @[simp, norm_cast] theorem coe_pure (a : α) : (pure a : Set α) = {a} := Icc_self _ #align interval.coe_pure Interval.coe_pure @[simp, norm_cast] theorem coe_coe (s : NonemptyInterval α) : ((s : Interval α) : Set α) = s := rfl #align interval.coe_coe Interval.coe_coe @[simp, norm_cast] theorem coe_bot : ((⊥ : Interval α) : Set α) = ∅ := rfl #align interval.coe_bot Interval.coe_bot @[simp, norm_cast] theorem coe_top [BoundedOrder α] : ((⊤ : Interval α) : Set α) = univ := Icc_bot_top #align interval.coe_top Interval.coe_top @[simp, norm_cast]
Mathlib/Order/Interval/Basic.lean
495
498
theorem coe_dual (s : Interval α) : (dual s : Set αᵒᵈ) = ofDual ⁻¹' s := by
cases s with | bot => rfl | coe s₀ => exact NonemptyInterval.coe_dual s₀
/- 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.Algebra.BigOperators.Group.Multiset import Mathlib.Data.PNat.Prime import Mathlib.Data.Nat.Factors import Mathlib.Data.Multiset.Sort #align_import data.pnat.factors from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Prime factors of nonzero naturals This file defines the factorization of a nonzero natural number `n` as a multiset of primes, the multiplicity of `p` in this factors multiset being the p-adic valuation of `n`. ## Main declarations * `PrimeMultiset`: Type of multisets of prime numbers. * `FactorMultiset n`: Multiset of prime factors of `n`. -/ -- Porting note: `deriving` contained Inhabited, CanonicallyOrderedAddCommMonoid, DistribLattice, -- SemilatticeSup, OrderBot, Sub, OrderedSub /-- The type of multisets of prime numbers. Unique factorization gives an equivalence between this set and ℕ+, as we will formalize below. -/ def PrimeMultiset := Multiset Nat.Primes deriving Inhabited, CanonicallyOrderedAddCommMonoid, DistribLattice, SemilatticeSup, Sub #align prime_multiset PrimeMultiset instance : OrderBot PrimeMultiset where bot_le := by simp only [bot_le, forall_const] instance : OrderedSub PrimeMultiset where tsub_le_iff_right _ _ _ := Multiset.sub_le_iff_le_add namespace PrimeMultiset -- `@[derive]` doesn't work for `meta` instances unsafe instance : Repr PrimeMultiset := by delta PrimeMultiset; infer_instance /-- The multiset consisting of a single prime -/ def ofPrime (p : Nat.Primes) : PrimeMultiset := ({p} : Multiset Nat.Primes) #align prime_multiset.of_prime PrimeMultiset.ofPrime theorem card_ofPrime (p : Nat.Primes) : Multiset.card (ofPrime p) = 1 := rfl #align prime_multiset.card_of_prime PrimeMultiset.card_ofPrime /-- We can forget the primality property and regard a multiset of primes as just a multiset of positive integers, or a multiset of natural numbers. In the opposite direction, if we have a multiset of positive integers or natural numbers, together with a proof that all the elements are prime, then we can regard it as a multiset of primes. The next block of results records obvious properties of these coercions. -/ def toNatMultiset : PrimeMultiset → Multiset ℕ := fun v => v.map Coe.coe #align prime_multiset.to_nat_multiset PrimeMultiset.toNatMultiset instance coeNat : Coe PrimeMultiset (Multiset ℕ) := ⟨toNatMultiset⟩ #align prime_multiset.coe_nat PrimeMultiset.coeNat /-- `PrimeMultiset.coe`, the coercion from a multiset of primes to a multiset of naturals, promoted to an `AddMonoidHom`. -/ def coeNatMonoidHom : PrimeMultiset →+ Multiset ℕ := { Multiset.mapAddMonoidHom Coe.coe with toFun := Coe.coe } #align prime_multiset.coe_nat_monoid_hom PrimeMultiset.coeNatMonoidHom @[simp] theorem coe_coeNatMonoidHom : (coeNatMonoidHom : PrimeMultiset → Multiset ℕ) = Coe.coe := rfl #align prime_multiset.coe_coe_nat_monoid_hom PrimeMultiset.coe_coeNatMonoidHom theorem coeNat_injective : Function.Injective (Coe.coe : PrimeMultiset → Multiset ℕ) := Multiset.map_injective Nat.Primes.coe_nat_injective #align prime_multiset.coe_nat_injective PrimeMultiset.coeNat_injective theorem coeNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset ℕ) = {(p : ℕ)} := rfl #align prime_multiset.coe_nat_of_prime PrimeMultiset.coeNat_ofPrime theorem coeNat_prime (v : PrimeMultiset) (p : ℕ) (h : p ∈ (v : Multiset ℕ)) : p.Prime := by rcases Multiset.mem_map.mp h with ⟨⟨_, hp'⟩, ⟨_, h_eq⟩⟩ exact h_eq ▸ hp' #align prime_multiset.coe_nat_prime PrimeMultiset.coeNat_prime /-- Converts a `PrimeMultiset` to a `Multiset ℕ+`. -/ def toPNatMultiset : PrimeMultiset → Multiset ℕ+ := fun v => v.map Coe.coe #align prime_multiset.to_pnat_multiset PrimeMultiset.toPNatMultiset instance coePNat : Coe PrimeMultiset (Multiset ℕ+) := ⟨toPNatMultiset⟩ #align prime_multiset.coe_pnat PrimeMultiset.coePNat /-- `coePNat`, the coercion from a multiset of primes to a multiset of positive naturals, regarded as an `AddMonoidHom`. -/ def coePNatMonoidHom : PrimeMultiset →+ Multiset ℕ+ := { Multiset.mapAddMonoidHom Coe.coe with toFun := Coe.coe } #align prime_multiset.coe_pnat_monoid_hom PrimeMultiset.coePNatMonoidHom @[simp] theorem coe_coePNatMonoidHom : (coePNatMonoidHom : PrimeMultiset → Multiset ℕ+) = Coe.coe := rfl #align prime_multiset.coe_coe_pnat_monoid_hom PrimeMultiset.coe_coePNatMonoidHom theorem coePNat_injective : Function.Injective (Coe.coe : PrimeMultiset → Multiset ℕ+) := Multiset.map_injective Nat.Primes.coe_pnat_injective #align prime_multiset.coe_pnat_injective PrimeMultiset.coePNat_injective theorem coePNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset ℕ+) = {(p : ℕ+)} := rfl #align prime_multiset.coe_pnat_of_prime PrimeMultiset.coePNat_ofPrime theorem coePNat_prime (v : PrimeMultiset) (p : ℕ+) (h : p ∈ (v : Multiset ℕ+)) : p.Prime := by rcases Multiset.mem_map.mp h with ⟨⟨_, hp'⟩, ⟨_, h_eq⟩⟩ exact h_eq ▸ hp' #align prime_multiset.coe_pnat_prime PrimeMultiset.coePNat_prime instance coeMultisetPNatNat : Coe (Multiset ℕ+) (Multiset ℕ) := ⟨fun v => v.map Coe.coe⟩ #align prime_multiset.coe_multiset_pnat_nat PrimeMultiset.coeMultisetPNatNat theorem coePNat_nat (v : PrimeMultiset) : ((v : Multiset ℕ+) : Multiset ℕ) = (v : Multiset ℕ) := by change (v.map (Coe.coe : Nat.Primes → ℕ+)).map Subtype.val = v.map Subtype.val rw [Multiset.map_map] congr #align prime_multiset.coe_pnat_nat PrimeMultiset.coePNat_nat /-- The product of a `PrimeMultiset`, as a `ℕ+`. -/ def prod (v : PrimeMultiset) : ℕ+ := (v : Multiset PNat).prod #align prime_multiset.prod PrimeMultiset.prod theorem coe_prod (v : PrimeMultiset) : (v.prod : ℕ) = (v : Multiset ℕ).prod := by let h : (v.prod : ℕ) = ((v.map Coe.coe).map Coe.coe).prod := PNat.coeMonoidHom.map_multiset_prod v.toPNatMultiset rw [Multiset.map_map] at h have : (Coe.coe : ℕ+ → ℕ) ∘ (Coe.coe : Nat.Primes → ℕ+) = Coe.coe := funext fun p => rfl rw [this] at h; exact h #align prime_multiset.coe_prod PrimeMultiset.coe_prod theorem prod_ofPrime (p : Nat.Primes) : (ofPrime p).prod = (p : ℕ+) := Multiset.prod_singleton _ #align prime_multiset.prod_of_prime PrimeMultiset.prod_ofPrime /-- If a `Multiset ℕ` consists only of primes, it can be recast as a `PrimeMultiset`. -/ def ofNatMultiset (v : Multiset ℕ) (h : ∀ p : ℕ, p ∈ v → p.Prime) : PrimeMultiset := @Multiset.pmap ℕ Nat.Primes Nat.Prime (fun p hp => ⟨p, hp⟩) v h #align prime_multiset.of_nat_multiset PrimeMultiset.ofNatMultiset theorem to_ofNatMultiset (v : Multiset ℕ) (h) : (ofNatMultiset v h : Multiset ℕ) = v := by dsimp [ofNatMultiset, toNatMultiset] have : (fun p h => (Coe.coe : Nat.Primes → ℕ) ⟨p, h⟩) = fun p _ => id p := by funext p h rfl rw [Multiset.map_pmap, this, Multiset.pmap_eq_map, Multiset.map_id] #align prime_multiset.to_of_nat_multiset PrimeMultiset.to_ofNatMultiset theorem prod_ofNatMultiset (v : Multiset ℕ) (h) : ((ofNatMultiset v h).prod : ℕ) = (v.prod : ℕ) := by rw [coe_prod, to_ofNatMultiset] #align prime_multiset.prod_of_nat_multiset PrimeMultiset.prod_ofNatMultiset /-- If a `Multiset ℕ+` consists only of primes, it can be recast as a `PrimeMultiset`. -/ def ofPNatMultiset (v : Multiset ℕ+) (h : ∀ p : ℕ+, p ∈ v → p.Prime) : PrimeMultiset := @Multiset.pmap ℕ+ Nat.Primes PNat.Prime (fun p hp => ⟨(p : ℕ), hp⟩) v h #align prime_multiset.of_pnat_multiset PrimeMultiset.ofPNatMultiset theorem to_ofPNatMultiset (v : Multiset ℕ+) (h) : (ofPNatMultiset v h : Multiset ℕ+) = v := by dsimp [ofPNatMultiset, toPNatMultiset] have : (fun (p : ℕ+) (h : p.Prime) => (Coe.coe : Nat.Primes → ℕ+) ⟨p, h⟩) = fun p _ => id p := by funext p h apply Subtype.eq rfl rw [Multiset.map_pmap, this, Multiset.pmap_eq_map, Multiset.map_id] #align prime_multiset.to_of_pnat_multiset PrimeMultiset.to_ofPNatMultiset theorem prod_ofPNatMultiset (v : Multiset ℕ+) (h) : ((ofPNatMultiset v h).prod : ℕ+) = v.prod := by dsimp [prod] rw [to_ofPNatMultiset] #align prime_multiset.prod_of_pnat_multiset PrimeMultiset.prod_ofPNatMultiset /-- Lists can be coerced to multisets; here we have some results about how this interacts with our constructions on multisets. -/ def ofNatList (l : List ℕ) (h : ∀ p : ℕ, p ∈ l → p.Prime) : PrimeMultiset := ofNatMultiset (l : Multiset ℕ) h #align prime_multiset.of_nat_list PrimeMultiset.ofNatList theorem prod_ofNatList (l : List ℕ) (h) : ((ofNatList l h).prod : ℕ) = l.prod := by have := prod_ofNatMultiset (l : Multiset ℕ) h rw [Multiset.prod_coe] at this exact this #align prime_multiset.prod_of_nat_list PrimeMultiset.prod_ofNatList /-- If a `List ℕ+` consists only of primes, it can be recast as a `PrimeMultiset` with the coercion from lists to multisets. -/ def ofPNatList (l : List ℕ+) (h : ∀ p : ℕ+, p ∈ l → p.Prime) : PrimeMultiset := ofPNatMultiset (l : Multiset ℕ+) h #align prime_multiset.of_pnat_list PrimeMultiset.ofPNatList theorem prod_ofPNatList (l : List ℕ+) (h) : (ofPNatList l h).prod = l.prod := by have := prod_ofPNatMultiset (l : Multiset ℕ+) h rw [Multiset.prod_coe] at this exact this #align prime_multiset.prod_of_pnat_list PrimeMultiset.prod_ofPNatList /-- The product map gives a homomorphism from the additive monoid of multisets to the multiplicative monoid ℕ+. -/ theorem prod_zero : (0 : PrimeMultiset).prod = 1 := by exact Multiset.prod_zero #align prime_multiset.prod_zero PrimeMultiset.prod_zero theorem prod_add (u v : PrimeMultiset) : (u + v).prod = u.prod * v.prod := by change (coePNatMonoidHom (u + v)).prod = _ rw [coePNatMonoidHom.map_add] exact Multiset.prod_add _ _ #align prime_multiset.prod_add PrimeMultiset.prod_add theorem prod_smul (d : ℕ) (u : PrimeMultiset) : (d • u).prod = u.prod ^ d := by induction d with | zero => simp only [Nat.zero_eq, zero_nsmul, pow_zero, prod_zero] | succ n ih => rw [succ_nsmul, prod_add, ih, pow_succ] #align prime_multiset.prod_smul PrimeMultiset.prod_smul end PrimeMultiset namespace PNat /-- The prime factors of n, regarded as a multiset -/ def factorMultiset (n : ℕ+) : PrimeMultiset := PrimeMultiset.ofNatList (Nat.factors n) (@Nat.prime_of_mem_factors n) #align pnat.factor_multiset PNat.factorMultiset /-- The product of the factors is the original number -/ theorem prod_factorMultiset (n : ℕ+) : (factorMultiset n).prod = n := eq <| by dsimp [factorMultiset] rw [PrimeMultiset.prod_ofNatList] exact Nat.prod_factors n.ne_zero #align pnat.prod_factor_multiset PNat.prod_factorMultiset theorem coeNat_factorMultiset (n : ℕ+) : (factorMultiset n : Multiset ℕ) = (Nat.factors n : Multiset ℕ) := PrimeMultiset.to_ofNatMultiset (Nat.factors n) (@Nat.prime_of_mem_factors n) #align pnat.coe_nat_factor_multiset PNat.coeNat_factorMultiset end PNat namespace PrimeMultiset /-- If we start with a multiset of primes, take the product and then factor it, we get back the original multiset. -/ theorem factorMultiset_prod (v : PrimeMultiset) : v.prod.factorMultiset = v := by apply PrimeMultiset.coeNat_injective suffices toNatMultiset (PNat.factorMultiset (prod v)) = toNatMultiset v by exact this rw [v.prod.coeNat_factorMultiset, PrimeMultiset.coe_prod] rcases v with ⟨l⟩ --unfold_coes dsimp [PrimeMultiset.toNatMultiset] rw [Multiset.prod_coe] let l' := l.map (Coe.coe : Nat.Primes → ℕ) have : ∀ p : ℕ, p ∈ l' → p.Prime := fun p hp => by rcases List.mem_map.mp hp with ⟨⟨_, hp'⟩, ⟨_, h_eq⟩⟩ exact h_eq ▸ hp' exact Multiset.coe_eq_coe.mpr (@Nat.factors_unique _ l' rfl this).symm #align prime_multiset.factor_multiset_prod PrimeMultiset.factorMultiset_prod end PrimeMultiset namespace PNat /-- Positive integers biject with multisets of primes. -/ def factorMultisetEquiv : ℕ+ ≃ PrimeMultiset where toFun := factorMultiset invFun := PrimeMultiset.prod left_inv := prod_factorMultiset right_inv := PrimeMultiset.factorMultiset_prod #align pnat.factor_multiset_equiv PNat.factorMultisetEquiv /-- Factoring gives a homomorphism from the multiplicative monoid ℕ+ to the additive monoid of multisets. -/ theorem factorMultiset_one : factorMultiset 1 = 0 := by simp [factorMultiset, PrimeMultiset.ofNatList, PrimeMultiset.ofNatMultiset] #align pnat.factor_multiset_one PNat.factorMultiset_one theorem factorMultiset_mul (n m : ℕ+) : factorMultiset (n * m) = factorMultiset n + factorMultiset m := by let u := factorMultiset n let v := factorMultiset m have : n = u.prod := (prod_factorMultiset n).symm; rw [this] have : m = v.prod := (prod_factorMultiset m).symm; rw [this] rw [← PrimeMultiset.prod_add] repeat' rw [PrimeMultiset.factorMultiset_prod] #align pnat.factor_multiset_mul PNat.factorMultiset_mul theorem factorMultiset_pow (n : ℕ+) (m : ℕ) : factorMultiset (n ^ m) = m • factorMultiset n := by let u := factorMultiset n have : n = u.prod := (prod_factorMultiset n).symm rw [this, ← PrimeMultiset.prod_smul] repeat' rw [PrimeMultiset.factorMultiset_prod] #align pnat.factor_multiset_pow PNat.factorMultiset_pow /-- Factoring a prime gives the corresponding one-element multiset. -/ theorem factorMultiset_ofPrime (p : Nat.Primes) : (p : ℕ+).factorMultiset = PrimeMultiset.ofPrime p := by apply factorMultisetEquiv.symm.injective change (p : ℕ+).factorMultiset.prod = (PrimeMultiset.ofPrime p).prod rw [(p : ℕ+).prod_factorMultiset, PrimeMultiset.prod_ofPrime] #align pnat.factor_multiset_of_prime PNat.factorMultiset_ofPrime /-- We now have four different results that all encode the idea that inequality of multisets corresponds to divisibility of positive integers. -/ theorem factorMultiset_le_iff {m n : ℕ+} : factorMultiset m ≤ factorMultiset n ↔ m ∣ n := by constructor · intro h rw [← prod_factorMultiset m, ← prod_factorMultiset m] apply Dvd.intro (n.factorMultiset - m.factorMultiset).prod rw [← PrimeMultiset.prod_add, PrimeMultiset.factorMultiset_prod, add_tsub_cancel_of_le h, prod_factorMultiset] · intro h rw [← mul_div_exact h, factorMultiset_mul] exact le_self_add #align pnat.factor_multiset_le_iff PNat.factorMultiset_le_iff theorem factorMultiset_le_iff' {m : ℕ+} {v : PrimeMultiset} : factorMultiset m ≤ v ↔ m ∣ v.prod := by let h := @factorMultiset_le_iff m v.prod rw [v.factorMultiset_prod] at h exact h #align pnat.factor_multiset_le_iff' PNat.factorMultiset_le_iff' end PNat namespace PrimeMultiset theorem prod_dvd_iff {u v : PrimeMultiset} : u.prod ∣ v.prod ↔ u ≤ v := by let h := @PNat.factorMultiset_le_iff' u.prod v rw [u.factorMultiset_prod] at h exact h.symm #align prime_multiset.prod_dvd_iff PrimeMultiset.prod_dvd_iff theorem prod_dvd_iff' {u : PrimeMultiset} {n : ℕ+} : u.prod ∣ n ↔ u ≤ n.factorMultiset := by let h := @prod_dvd_iff u n.factorMultiset rw [n.prod_factorMultiset] at h exact h #align prime_multiset.prod_dvd_iff' PrimeMultiset.prod_dvd_iff' end PrimeMultiset namespace PNat /-- The gcd and lcm operations on positive integers correspond to the inf and sup operations on multisets. -/
Mathlib/Data/PNat/Factors.lean
362
371
theorem factorMultiset_gcd (m n : ℕ+) : factorMultiset (gcd m n) = factorMultiset m ⊓ factorMultiset n := by
apply le_antisymm · apply le_inf_iff.mpr; constructor <;> apply factorMultiset_le_iff.mpr · exact gcd_dvd_left m n · exact gcd_dvd_right m n · rw [← PrimeMultiset.prod_dvd_iff, prod_factorMultiset] apply dvd_gcd <;> rw [PrimeMultiset.prod_dvd_iff'] · exact inf_le_left · exact inf_le_right
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Interval.Finset.Nat import Mathlib.Data.PNat.Defs #align_import data.pnat.interval from "leanprover-community/mathlib"@"1d29de43a5ba4662dd33b5cfeecfc2a27a5a8a29" /-! # Finite intervals of positive naturals This file proves that `ℕ+` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. -/ open Finset Function PNat namespace PNat variable (a b : ℕ+) instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ+ := Subtype.instLocallyFiniteOrder _ theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl #align pnat.Icc_eq_finset_subtype PNat.Icc_eq_finset_subtype theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl #align pnat.Ico_eq_finset_subtype PNat.Ico_eq_finset_subtype theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl #align pnat.Ioc_eq_finset_subtype PNat.Ioc_eq_finset_subtype theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl #align pnat.Ioo_eq_finset_subtype PNat.Ioo_eq_finset_subtype theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl #align pnat.uIcc_eq_finset_subtype PNat.uIcc_eq_finset_subtype theorem map_subtype_embedding_Icc : (Icc a b).map (Embedding.subtype _) = Icc ↑a ↑b := Finset.map_subtype_embedding_Icc _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx #align pnat.map_subtype_embedding_Icc PNat.map_subtype_embedding_Icc theorem map_subtype_embedding_Ico : (Ico a b).map (Embedding.subtype _) = Ico ↑a ↑b := Finset.map_subtype_embedding_Ico _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx #align pnat.map_subtype_embedding_Ico PNat.map_subtype_embedding_Ico theorem map_subtype_embedding_Ioc : (Ioc a b).map (Embedding.subtype _) = Ioc ↑a ↑b := Finset.map_subtype_embedding_Ioc _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx #align pnat.map_subtype_embedding_Ioc PNat.map_subtype_embedding_Ioc theorem map_subtype_embedding_Ioo : (Ioo a b).map (Embedding.subtype _) = Ioo ↑a ↑b := Finset.map_subtype_embedding_Ioo _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx #align pnat.map_subtype_embedding_Ioo PNat.map_subtype_embedding_Ioo theorem map_subtype_embedding_uIcc : (uIcc a b).map (Embedding.subtype _) = uIcc ↑a ↑b := map_subtype_embedding_Icc _ _ #align pnat.map_subtype_embedding_uIcc PNat.map_subtype_embedding_uIcc @[simp] theorem card_Icc : (Icc a b).card = b + 1 - a := by rw [← Nat.card_Icc] -- Porting note: I had to change this to `erw` *and* provide the proof, yuck. -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [← Finset.map_subtype_embedding_Icc _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)] rw [card_map] #align pnat.card_Icc PNat.card_Icc @[simp] theorem card_Ico : (Ico a b).card = b - a := by rw [← Nat.card_Ico] -- Porting note: I had to change this to `erw` *and* provide the proof, yuck. -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [← Finset.map_subtype_embedding_Ico _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)] rw [card_map] #align pnat.card_Ico PNat.card_Ico @[simp] theorem card_Ioc : (Ioc a b).card = b - a := by rw [← Nat.card_Ioc] -- Porting note: I had to change this to `erw` *and* provide the proof, yuck. -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [← Finset.map_subtype_embedding_Ioc _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)] rw [card_map] #align pnat.card_Ioc PNat.card_Ioc @[simp] theorem card_Ioo : (Ioo a b).card = b - a - 1 := by rw [← Nat.card_Ioo] -- Porting note: I had to change this to `erw` *and* provide the proof, yuck. -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [← Finset.map_subtype_embedding_Ioo _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)] rw [card_map] #align pnat.card_Ioo PNat.card_Ioo @[simp] theorem card_uIcc : (uIcc a b).card = (b - a : ℤ).natAbs + 1 := by rw [← Nat.card_uIcc, ← map_subtype_embedding_uIcc, card_map] #align pnat.card_uIcc PNat.card_uIcc -- Porting note: `simpNF` says `simp` can prove this theorem card_fintype_Icc : Fintype.card (Set.Icc a b) = b + 1 - a := by rw [← card_Icc, Fintype.card_ofFinset] #align pnat.card_fintype_Icc PNat.card_fintype_Icc -- Porting note: `simpNF` says `simp` can prove this theorem card_fintype_Ico : Fintype.card (Set.Ico a b) = b - a := by rw [← card_Ico, Fintype.card_ofFinset] #align pnat.card_fintype_Ico PNat.card_fintype_Ico -- Porting note: `simpNF` says `simp` can prove this theorem card_fintype_Ioc : Fintype.card (Set.Ioc a b) = b - a := by rw [← card_Ioc, Fintype.card_ofFinset] #align pnat.card_fintype_Ioc PNat.card_fintype_Ioc -- Porting note: `simpNF` says `simp` can prove this
Mathlib/Data/PNat/Interval.lean
123
124
theorem card_fintype_Ioo : Fintype.card (Set.Ioo a b) = b - a - 1 := by
rw [← card_Ioo, Fintype.card_ofFinset]
/- 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.Arctan import Mathlib.Analysis.SpecialFunctions.Trigonometric.ComplexDeriv #align_import analysis.special_functions.trigonometric.arctan_deriv from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Derivatives of the `tan` and `arctan` functions. Continuity and derivatives of the tangent and arctangent functions. -/ noncomputable section namespace Real open Set Filter open scoped Topology Real theorem hasStrictDerivAt_tan {x : ℝ} (h : cos x ≠ 0) : HasStrictDerivAt tan (1 / cos x ^ 2) x := mod_cast (Complex.hasStrictDerivAt_tan (by exact mod_cast h)).real_of_complex #align real.has_strict_deriv_at_tan Real.hasStrictDerivAt_tan theorem hasDerivAt_tan {x : ℝ} (h : cos x ≠ 0) : HasDerivAt tan (1 / cos x ^ 2) x := mod_cast (Complex.hasDerivAt_tan (by exact mod_cast h)).real_of_complex #align real.has_deriv_at_tan Real.hasDerivAt_tan
Mathlib/Analysis/SpecialFunctions/Trigonometric/ArctanDeriv.lean
34
40
theorem tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) : Tendsto (fun x => abs (tan x)) (𝓝[≠] x) atTop := by
have hx : Complex.cos x = 0 := mod_cast hx simp only [← Complex.abs_ofReal, Complex.ofReal_tan] refine (Complex.tendsto_abs_tan_of_cos_eq_zero hx).comp ?_ refine Tendsto.inf Complex.continuous_ofReal.continuousAt ?_ exact tendsto_principal_principal.2 fun y => mt Complex.ofReal_inj.1
/- 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.Basic import Mathlib.Algebra.Ring.Idempotents import Mathlib.RingTheory.Ideal.LocalRing import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.ReesAlgebra import Mathlib.RingTheory.Finiteness import Mathlib.Order.Basic import Mathlib.Order.Hom.Lattice #align_import ring_theory.filtration from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # `I`-filtrations of modules This file contains the definitions and basic results around (stable) `I`-filtrations of modules. ## Main results - `Ideal.Filtration`: An `I`-filtration on the module `M` is a sequence of decreasing submodules `N i` such that `∀ i, I • (N i) ≤ N (i + 1)`. Note that we do not require the filtration to start from `⊤`. - `Ideal.Filtration.Stable`: An `I`-filtration is stable if `I • (N i) = N (i + 1)` for large enough `i`. - `Ideal.Filtration.submodule`: The associated module `⨁ Nᵢ` of a filtration, implemented as a submodule of `M[X]`. - `Ideal.Filtration.submodule_fg_iff_stable`: If `F.N i` are all finitely generated, then `F.Stable` iff `F.submodule.FG`. - `Ideal.Filtration.Stable.of_le`: In a finite module over a noetherian ring, if `F' ≤ F`, then `F.Stable → F'.Stable`. - `Ideal.exists_pow_inf_eq_pow_smul`: **Artin-Rees lemma**. given `N ≤ M`, there exists a `k` such that `IⁿM ⊓ N = Iⁿ⁻ᵏ(IᵏM ⊓ N)` for all `n ≥ k`. - `Ideal.iInf_pow_eq_bot_of_localRing`: **Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian local rings. - `Ideal.iInf_pow_eq_bot_of_isDomain`: **Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian domains. -/ universe u v variable {R M : Type u} [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R) open Polynomial open scoped Polynomial /-- An `I`-filtration on the module `M` is a sequence of decreasing submodules `N i` such that `I • (N i) ≤ N (i + 1)`. Note that we do not require the filtration to start from `⊤`. -/ @[ext] structure Ideal.Filtration (M : Type u) [AddCommGroup M] [Module R M] where N : ℕ → Submodule R M mono : ∀ i, N (i + 1) ≤ N i smul_le : ∀ i, I • N i ≤ N (i + 1) #align ideal.filtration Ideal.Filtration variable (F F' : I.Filtration M) {I} namespace Ideal.Filtration theorem pow_smul_le (i j : ℕ) : I ^ i • F.N j ≤ F.N (i + j) := by induction' i with _ ih · simp · rw [pow_succ', mul_smul, add_assoc, add_comm 1, ← add_assoc] exact (smul_mono_right _ ih).trans (F.smul_le _) #align ideal.filtration.pow_smul_le Ideal.Filtration.pow_smul_le theorem pow_smul_le_pow_smul (i j k : ℕ) : I ^ (i + k) • F.N j ≤ I ^ k • F.N (i + j) := by rw [add_comm, pow_add, mul_smul] exact smul_mono_right _ (F.pow_smul_le i j) #align ideal.filtration.pow_smul_le_pow_smul Ideal.Filtration.pow_smul_le_pow_smul protected theorem antitone : Antitone F.N := antitone_nat_of_succ_le F.mono #align ideal.filtration.antitone Ideal.Filtration.antitone /-- The trivial `I`-filtration of `N`. -/ @[simps] def _root_.Ideal.trivialFiltration (I : Ideal R) (N : Submodule R M) : I.Filtration M where N _ := N mono _ := le_rfl smul_le _ := Submodule.smul_le_right #align ideal.trivial_filtration Ideal.trivialFiltration /-- The `sup` of two `I.Filtration`s is an `I.Filtration`. -/ instance : Sup (I.Filtration M) := ⟨fun F F' => ⟨F.N ⊔ F'.N, fun i => sup_le_sup (F.mono i) (F'.mono i), fun i => (Submodule.smul_sup _ _ _).trans_le <| sup_le_sup (F.smul_le i) (F'.smul_le i)⟩⟩ /-- The `sSup` of a family of `I.Filtration`s is an `I.Filtration`. -/ instance : SupSet (I.Filtration M) := ⟨fun S => { N := sSup (Ideal.Filtration.N '' S) mono := fun i => by apply sSup_le_sSup_of_forall_exists_le _ rintro _ ⟨⟨_, F, hF, rfl⟩, rfl⟩ exact ⟨_, ⟨⟨_, F, hF, rfl⟩, rfl⟩, F.mono i⟩ smul_le := fun i => by rw [sSup_eq_iSup', iSup_apply, Submodule.smul_iSup, iSup_apply] apply iSup_mono _ rintro ⟨_, F, hF, rfl⟩ exact F.smul_le i }⟩ /-- The `inf` of two `I.Filtration`s is an `I.Filtration`. -/ instance : Inf (I.Filtration M) := ⟨fun F F' => ⟨F.N ⊓ F'.N, fun i => inf_le_inf (F.mono i) (F'.mono i), fun i => (smul_inf_le _ _ _).trans <| inf_le_inf (F.smul_le i) (F'.smul_le i)⟩⟩ /-- The `sInf` of a family of `I.Filtration`s is an `I.Filtration`. -/ instance : InfSet (I.Filtration M) := ⟨fun S => { N := sInf (Ideal.Filtration.N '' S) mono := fun i => by apply sInf_le_sInf_of_forall_exists_le _ rintro _ ⟨⟨_, F, hF, rfl⟩, rfl⟩ exact ⟨_, ⟨⟨_, F, hF, rfl⟩, rfl⟩, F.mono i⟩ smul_le := fun i => by rw [sInf_eq_iInf', iInf_apply, iInf_apply] refine smul_iInf_le.trans ?_ apply iInf_mono _ rintro ⟨_, F, hF, rfl⟩ exact F.smul_le i }⟩ instance : Top (I.Filtration M) := ⟨I.trivialFiltration ⊤⟩ instance : Bot (I.Filtration M) := ⟨I.trivialFiltration ⊥⟩ @[simp] theorem sup_N : (F ⊔ F').N = F.N ⊔ F'.N := rfl set_option linter.uppercaseLean3 false in #align ideal.filtration.sup_N Ideal.Filtration.sup_N @[simp] theorem sSup_N (S : Set (I.Filtration M)) : (sSup S).N = sSup (Ideal.Filtration.N '' S) := rfl set_option linter.uppercaseLean3 false in #align ideal.filtration.Sup_N Ideal.Filtration.sSup_N @[simp] theorem inf_N : (F ⊓ F').N = F.N ⊓ F'.N := rfl set_option linter.uppercaseLean3 false in #align ideal.filtration.inf_N Ideal.Filtration.inf_N @[simp] theorem sInf_N (S : Set (I.Filtration M)) : (sInf S).N = sInf (Ideal.Filtration.N '' S) := rfl set_option linter.uppercaseLean3 false in #align ideal.filtration.Inf_N Ideal.Filtration.sInf_N @[simp] theorem top_N : (⊤ : I.Filtration M).N = ⊤ := rfl set_option linter.uppercaseLean3 false in #align ideal.filtration.top_N Ideal.Filtration.top_N @[simp] theorem bot_N : (⊥ : I.Filtration M).N = ⊥ := rfl set_option linter.uppercaseLean3 false in #align ideal.filtration.bot_N Ideal.Filtration.bot_N @[simp] theorem iSup_N {ι : Sort*} (f : ι → I.Filtration M) : (iSup f).N = ⨆ i, (f i).N := congr_arg sSup (Set.range_comp _ _).symm set_option linter.uppercaseLean3 false in #align ideal.filtration.supr_N Ideal.Filtration.iSup_N @[simp] theorem iInf_N {ι : Sort*} (f : ι → I.Filtration M) : (iInf f).N = ⨅ i, (f i).N := congr_arg sInf (Set.range_comp _ _).symm set_option linter.uppercaseLean3 false in #align ideal.filtration.infi_N Ideal.Filtration.iInf_N instance : CompleteLattice (I.Filtration M) := Function.Injective.completeLattice Ideal.Filtration.N Ideal.Filtration.ext sup_N inf_N (fun _ => sSup_image) (fun _ => sInf_image) top_N bot_N instance : Inhabited (I.Filtration M) := ⟨⊥⟩ /-- An `I` filtration is stable if `I • F.N n = F.N (n+1)` for large enough `n`. -/ def Stable : Prop := ∃ n₀, ∀ n ≥ n₀, I • F.N n = F.N (n + 1) #align ideal.filtration.stable Ideal.Filtration.Stable /-- The trivial stable `I`-filtration of `N`. -/ @[simps] def _root_.Ideal.stableFiltration (I : Ideal R) (N : Submodule R M) : I.Filtration M where N i := I ^ i • N mono i := by dsimp only; rw [add_comm, pow_add, mul_smul]; exact Submodule.smul_le_right smul_le i := by dsimp only; rw [add_comm, pow_add, mul_smul, pow_one] #align ideal.stable_filtration Ideal.stableFiltration
Mathlib/RingTheory/Filtration.lean
206
211
theorem _root_.Ideal.stableFiltration_stable (I : Ideal R) (N : Submodule R M) : (I.stableFiltration N).Stable := by
use 0 intro n _ dsimp rw [add_comm, pow_add, mul_smul, pow_one]
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash, Yury Kudryashov -/ import Mathlib.Topology.CompactOpen import Mathlib.Topology.LocallyFinite import Mathlib.Topology.ProperMap import Mathlib.Topology.UniformSpace.UniformConvergenceTopology #align_import topology.uniform_space.compact_convergence from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Compact convergence (uniform convergence on compact sets) Given a topological space `α` and a uniform space `β` (e.g., a metric space or a topological group), the space of continuous maps `C(α, β)` carries a natural uniform space structure. We define this uniform space structure in this file and also prove its basic properties. ## Main definitions - `ContinuousMap.toUniformOnFunIsCompact`: natural embedding of `C(α, β)` into the space `α →ᵤ[{K | IsCompact K}] β` of all maps `α → β` with the uniform space structure of uniform convergence on compacts. - `ContinuousMap.compactConvergenceUniformSpace`: the `UniformSpace` structure on `C(α, β)` induced by the map above. ## Main results * `ContinuousMap.mem_compactConvergence_entourage_iff`: a characterisation of the entourages of `C(α, β)`. The entourages are generated by the following sets. Given `K : Set α` and `V : Set (β × β)`, let `E(K, V) : Set (C(α, β) × C(α, β))` be the set of pairs of continuous functions `α → β` which are `V`-close on `K`: $$ E(K, V) = \{ (f, g) | ∀ (x ∈ K), (f x, g x) ∈ V \}. $$ Then the sets `E(K, V)` for all compact sets `K` and all entourages `V` form a basis of entourages of `C(α, β)`. As usual, this basis of entourages provides a basis of neighbourhoods by fixing `f`, see `nhds_basis_uniformity'`. * `Filter.HasBasis.compactConvergenceUniformity`: a similar statement that uses a basis of entourages of `β` instead of all entourages. It is useful, e.g., if `β` is a metric space. * `ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn`: a sequence of functions `Fₙ` in `C(α, β)` converges in the compact-open topology to some `f` iff `Fₙ` converges to `f` uniformly on each compact subset `K` of `α`. * Topology induced by the uniformity described above agrees with the compact-open topology. This is essentially the same as `ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn`. This fact is not available as a separate theorem. Instead, we override the projection of `ContinuousMap.compactConvergenceUniformity` to `TopologicalSpace` to be `ContinuousMap.compactOpen` and prove that they agree, see Note [forgetful inheritance] and implementation notes below. * `ContinuousMap.tendsto_iff_tendstoLocallyUniformly`: on a weakly locally compact space, a sequence of functions `Fₙ` in `C(α, β)` converges to some `f` iff `Fₙ` converges to `f` locally uniformly. * `ContinuousMap.tendsto_iff_tendstoUniformly`: on a compact space, a sequence of functions `Fₙ` in `C(α, β)` converges to some `f` iff `Fₙ` converges to `f` uniformly. ## Implementation details For technical reasons (see Note [forgetful inheritance]), instead of defining a `UniformSpace C(α, β)` structure and proving in a theorem that it agrees with the compact-open topology, we override the projection right in the definition, so that the resulting instance uses the compact-open topology. ## TODO * Results about uniformly continuous functions `γ → C(α, β)` and uniform limits of sequences `ι → γ → C(α, β)`. -/ universe u₁ u₂ u₃ open scoped Uniformity Topology UniformConvergence open UniformSpace Set Filter variable {α : Type u₁} {β : Type u₂} [TopologicalSpace α] [UniformSpace β] variable (K : Set α) (V : Set (β × β)) (f : C(α, β)) namespace ContinuousMap /-- Compact-open topology on `C(α, β)` agrees with the topology of uniform convergence on compacts: a family of continuous functions `F i` tends to `f` in the compact-open topology if and only if the `F i` tends to `f` uniformly on all compact sets. -/ theorem tendsto_iff_forall_compact_tendstoUniformlyOn {ι : Type u₃} {p : Filter ι} {F : ι → C(α, β)} {f} : Tendsto F p (𝓝 f) ↔ ∀ K, IsCompact K → TendstoUniformlyOn (fun i a => F i a) f p K := by rw [tendsto_nhds_compactOpen] constructor · -- Let us prove that convergence in the compact-open topology -- implies uniform convergence on compacts. -- Consider a compact set `K` intro h K hK -- Since `K` is compact, it suffices to prove locally uniform convergence rw [← tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK] -- Now choose an entourage `U` in the codomain and a point `x ∈ K`. intro U hU x _ -- Choose an open symmetric entourage `V` such that `V ○ V ⊆ U`. rcases comp_open_symm_mem_uniformity_sets hU with ⟨V, hV, hVo, hVsymm, hVU⟩ -- Then choose a closed entourage `W ⊆ V` rcases mem_uniformity_isClosed hV with ⟨W, hW, hWc, hWU⟩ -- Consider `s = {y ∈ K | (f x, f y) ∈ W}` set s := K ∩ f ⁻¹' ball (f x) W -- This is a neighbourhood of `x` within `K`, because `W` is an entourage. have hnhds : s ∈ 𝓝[K] x := inter_mem_nhdsWithin _ <| f.continuousAt _ (ball_mem_nhds _ hW) -- This set is compact because it is an intersection of `K` -- with a closed set `{y | (f x, f y) ∈ W} = f ⁻¹' UniformSpace.ball (f x) W` have hcomp : IsCompact s := hK.inter_right <| (isClosed_ball _ hWc).preimage f.continuous -- `f` maps `s` to the open set `ball (f x) V = {z | (f x, z) ∈ V}` have hmaps : MapsTo f s (ball (f x) V) := fun x hx ↦ hWU hx.2 use s, hnhds -- Continuous maps `F i` in a neighbourhood of `f` map `s` to `ball (f x) V` as well. refine (h s hcomp _ (isOpen_ball _ hVo) hmaps).mono fun g hg y hy ↦ ?_ -- Then for `y ∈ s` we have `(f y, f x) ∈ V` and `(f x, F i y) ∈ V`, thus `(f y, F i y) ∈ U` exact hVU ⟨f x, hVsymm.mk_mem_comm.2 <| hmaps hy, hg hy⟩ · -- Now we prove that uniform convergence on compacts -- implies convergence in the compact-open topology -- Consider a compact set `K`, an open set `U`, and a continuous map `f` that maps `K` to `U` intro h K hK U hU hf -- Due to Lebesgue number lemma, there exists an entourage `V` -- such that `U` includes the `V`-thickening of `f '' K`. rcases lebesgue_number_of_compact_open (hK.image (map_continuous f)) hU hf.image_subset with ⟨V, hV, -, hVf⟩ -- Then any continuous map that is uniformly `V`-close to `f` on `K` -- maps `K` to `U` as well filter_upwards [h K hK V hV] with g hg x hx using hVf _ (mem_image_of_mem f hx) (hg x hx) #align continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn /-- Interpret a bundled continuous map as an element of `α →ᵤ[{K | IsCompact K}] β`. We use this map to induce the `UniformSpace` structure on `C(α, β)`. -/ def toUniformOnFunIsCompact (f : C(α, β)) : α →ᵤ[{K | IsCompact K}] β := UniformOnFun.ofFun {K | IsCompact K} f @[simp] theorem toUniformOnFun_toFun (f : C(α, β)) : UniformOnFun.toFun _ f.toUniformOnFunIsCompact = f := rfl open UniformSpace in /-- Uniform space structure on `C(α, β)`. The uniformity comes from `α →ᵤ[{K | IsCompact K}] β` (i.e., `UniformOnFun α β {K | IsCompact K}`) which defines topology of uniform convergence on compact sets. We use `ContinuousMap.tendsto_iff_forall_compact_tendstoUniformlyOn` to show that the induced topology agrees with the compact-open topology and replace the topology with `compactOpen` to avoid non-defeq diamonds, see Note [forgetful inheritance]. -/ instance compactConvergenceUniformSpace : UniformSpace C(α, β) := .replaceTopology (.comap toUniformOnFunIsCompact inferInstance) <| by refine TopologicalSpace.ext_nhds fun f ↦ eq_of_forall_le_iff fun l ↦ ?_ simp_rw [← tendsto_id', tendsto_iff_forall_compact_tendstoUniformlyOn, nhds_induced, tendsto_comap_iff, UniformOnFun.tendsto_iff_tendstoUniformlyOn] rfl #align continuous_map.compact_convergence_uniform_space ContinuousMap.compactConvergenceUniformSpace theorem uniformEmbedding_toUniformOnFunIsCompact : UniformEmbedding (toUniformOnFunIsCompact : C(α, β) → α →ᵤ[{K | IsCompact K}] β) where comap_uniformity := rfl inj := DFunLike.coe_injective -- The following definitions and theorems -- used to be a part of the construction of the `UniformSpace C(α, β)` structure -- before it was migrated to `UniformOnFun` #noalign continuous_map.compact_conv_nhd #noalign continuous_map.self_mem_compact_conv_nhd #noalign continuous_map.compact_conv_nhd_mono #noalign continuous_map.compact_conv_nhd_mem_comp #noalign continuous_map.compact_conv_nhd_nhd_basis #noalign continuous_map.compact_conv_nhd_subset_inter #noalign continuous_map.compact_conv_nhd_compact_entourage_nonempty #noalign continuous_map.compact_conv_nhd_filter_is_basis #noalign continuous_map.compact_convergence_filter_basis #noalign continuous_map.mem_compact_convergence_nhd_filter #noalign continuous_map.compact_convergence_topology #noalign continuous_map.nhds_compact_convergence #noalign continuous_map.has_basis_nhds_compact_convergence #noalign continuous_map.tendsto_iff_forall_compact_tendsto_uniformly_on' #noalign continuous_map.compact_conv_nhd_subset_compact_open #noalign continuous_map.Inter_compact_open_gen_subset_compact_conv_nhd #noalign continuous_map.compact_open_eq_compact_convergence #noalign continuous_map.compact_convergence_uniformity #noalign continuous_map.has_basis_compact_convergence_uniformity_aux #noalign continuous_map.mem_compact_convergence_uniformity theorem _root_.Filter.HasBasis.compactConvergenceUniformity {ι : Type*} {pi : ι → Prop} {s : ι → Set (β × β)} (h : (𝓤 β).HasBasis pi s) : HasBasis (𝓤 C(α, β)) (fun p : Set α × ι => IsCompact p.1 ∧ pi p.2) fun p => { fg : C(α, β) × C(α, β) | ∀ x ∈ p.1, (fg.1 x, fg.2 x) ∈ s p.2 } := by rw [← uniformEmbedding_toUniformOnFunIsCompact.comap_uniformity] exact .comap _ <| UniformOnFun.hasBasis_uniformity_of_basis _ _ {K | IsCompact K} ⟨∅, isCompact_empty⟩ (directedOn_of_sup_mem fun _ _ ↦ IsCompact.union) h #align filter.has_basis.compact_convergence_uniformity Filter.HasBasis.compactConvergenceUniformity theorem hasBasis_compactConvergenceUniformity : HasBasis (𝓤 C(α, β)) (fun p : Set α × Set (β × β) => IsCompact p.1 ∧ p.2 ∈ 𝓤 β) fun p => { fg : C(α, β) × C(α, β) | ∀ x ∈ p.1, (fg.1 x, fg.2 x) ∈ p.2 } := (basis_sets _).compactConvergenceUniformity #align continuous_map.has_basis_compact_convergence_uniformity ContinuousMap.hasBasis_compactConvergenceUniformity theorem mem_compactConvergence_entourage_iff (X : Set (C(α, β) × C(α, β))) : X ∈ 𝓤 C(α, β) ↔ ∃ (K : Set α) (V : Set (β × β)), IsCompact K ∧ V ∈ 𝓤 β ∧ { fg : C(α, β) × C(α, β) | ∀ x ∈ K, (fg.1 x, fg.2 x) ∈ V } ⊆ X := by simp [hasBasis_compactConvergenceUniformity.mem_iff, and_assoc] #align continuous_map.mem_compact_convergence_entourage_iff ContinuousMap.mem_compactConvergence_entourage_iff /-- If `K` is a compact exhaustion of `α` and `V i` bounded by `p i` is a basis of entourages of `β`, then `fun (n, i) ↦ {(f, g) | ∀ x ∈ K n, (f x, g x) ∈ V i}` bounded by `p i` is a basis of entourages of `C(α, β)`. -/ theorem _root_.CompactExhaustion.hasBasis_compactConvergenceUniformity {ι : Type*} {p : ι → Prop} {V : ι → Set (β × β)} (K : CompactExhaustion α) (hb : (𝓤 β).HasBasis p V) : HasBasis (𝓤 C(α, β)) (fun i : ℕ × ι ↦ p i.2) fun i ↦ {fg | ∀ x ∈ K i.1, (fg.1 x, fg.2 x) ∈ V i.2} := (UniformOnFun.hasBasis_uniformity_of_covering_of_basis {K | IsCompact K} K.isCompact (Monotone.directed_le K.subset) (fun _ ↦ K.exists_superset_of_isCompact) hb).comap _ theorem _root_.CompactExhaustion.hasAntitoneBasis_compactConvergenceUniformity {V : ℕ → Set (β × β)} (K : CompactExhaustion α) (hb : (𝓤 β).HasAntitoneBasis V) : HasAntitoneBasis (𝓤 C(α, β)) fun n ↦ {fg | ∀ x ∈ K n, (fg.1 x, fg.2 x) ∈ V n} := (UniformOnFun.hasAntitoneBasis_uniformity {K | IsCompact K} K.isCompact K.subset (fun _ ↦ K.exists_superset_of_isCompact) hb).comap _ /-- If `α` is a weakly locally compact σ-compact space (e.g., a proper pseudometric space or a compact spaces) and the uniformity on `β` is pseudometrizable, then the uniformity on `C(α, β)` is pseudometrizable too. -/ instance [WeaklyLocallyCompactSpace α] [SigmaCompactSpace α] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (C(α, β))) := let ⟨_V, hV⟩ := exists_antitone_basis (𝓤 β) ((CompactExhaustion.choice α).hasAntitoneBasis_compactConvergenceUniformity hV).isCountablyGenerated variable {ι : Type u₃} {p : Filter ι} {F : ι → C(α, β)} {f} /-- Locally uniform convergence implies convergence in the compact-open topology. -/ theorem tendsto_of_tendstoLocallyUniformly (h : TendstoLocallyUniformly (fun i a => F i a) f p) : Tendsto F p (𝓝 f) := by rw [tendsto_iff_forall_compact_tendstoUniformlyOn] intro K hK rw [← tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK] exact h.tendstoLocallyUniformlyOn #align continuous_map.tendsto_of_tendsto_locally_uniformly ContinuousMap.tendsto_of_tendstoLocallyUniformly /-- In a weakly locally compact space, convergence in the compact-open topology is the same as locally uniform convergence. The right-to-left implication holds in any topological space, see `ContinuousMap.tendsto_of_tendstoLocallyUniformly`. -/ theorem tendsto_iff_tendstoLocallyUniformly [WeaklyLocallyCompactSpace α] : Tendsto F p (𝓝 f) ↔ TendstoLocallyUniformly (fun i a => F i a) f p := by refine ⟨fun h V hV x ↦ ?_, tendsto_of_tendstoLocallyUniformly⟩ rw [tendsto_iff_forall_compact_tendstoUniformlyOn] at h obtain ⟨n, hn₁, hn₂⟩ := exists_compact_mem_nhds x exact ⟨n, hn₂, h n hn₁ V hV⟩ #align continuous_map.tendsto_iff_tendsto_locally_uniformly ContinuousMap.tendsto_iff_tendstoLocallyUniformly @[deprecated tendsto_iff_tendstoLocallyUniformly (since := "2023-09-03")] theorem tendstoLocallyUniformly_of_tendsto [WeaklyLocallyCompactSpace α] (h : Tendsto F p (𝓝 f)) : TendstoLocallyUniformly (fun i a => F i a) f p := tendsto_iff_tendstoLocallyUniformly.1 h #align continuous_map.tendsto_locally_uniformly_of_tendsto ContinuousMap.tendstoLocallyUniformly_of_tendsto section Functorial variable {γ δ : Type*} [TopologicalSpace γ] [UniformSpace δ] theorem uniformContinuous_comp (g : C(β, δ)) (hg : UniformContinuous g) : UniformContinuous (ContinuousMap.comp g : C(α, β) → C(α, δ)) := uniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.postcomp_uniformContinuous hg |>.comp uniformEmbedding_toUniformOnFunIsCompact.uniformContinuous theorem uniformInducing_comp (g : C(β, δ)) (hg : UniformInducing g) : UniformInducing (ContinuousMap.comp g : C(α, β) → C(α, δ)) := uniformEmbedding_toUniformOnFunIsCompact.toUniformInducing.of_comp_iff.mp <| UniformOnFun.postcomp_uniformInducing hg |>.comp uniformEmbedding_toUniformOnFunIsCompact.toUniformInducing theorem uniformEmbedding_comp (g : C(β, δ)) (hg : UniformEmbedding g) : UniformEmbedding (ContinuousMap.comp g : C(α, β) → C(α, δ)) := uniformEmbedding_toUniformOnFunIsCompact.of_comp_iff.mp <| UniformOnFun.postcomp_uniformEmbedding hg |>.comp uniformEmbedding_toUniformOnFunIsCompact theorem uniformContinuous_comp_left (g : C(α, γ)) : UniformContinuous (fun f ↦ f.comp g : C(γ, β) → C(α, β)) := uniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.precomp_uniformContinuous (fun _ hK ↦ hK.image g.continuous) |>.comp uniformEmbedding_toUniformOnFunIsCompact.uniformContinuous /-- Any pair of a homeomorphism `X ≃ₜ Z` and an isomorphism `Y ≃ᵤ T` of uniform spaces gives rise to an isomorphism `C(X, Y) ≃ᵤ C(Z, T)`. -/ protected def _root_.UniformEquiv.arrowCongr (φ : α ≃ₜ γ) (ψ : β ≃ᵤ δ) : C(α, β) ≃ᵤ C(γ, δ) where toFun f := .comp ψ.toHomeomorph <| f.comp φ.symm invFun f := .comp ψ.symm.toHomeomorph <| f.comp φ left_inv f := ext fun _ ↦ ψ.left_inv (f _) |>.trans <| congrArg f <| φ.left_inv _ right_inv f := ext fun _ ↦ ψ.right_inv (f _) |>.trans <| congrArg f <| φ.right_inv _ uniformContinuous_toFun := uniformContinuous_comp _ ψ.uniformContinuous |>.comp <| uniformContinuous_comp_left _ uniformContinuous_invFun := uniformContinuous_comp _ ψ.symm.uniformContinuous |>.comp <| uniformContinuous_comp_left _ end Functorial section CompactDomain variable [CompactSpace α] theorem hasBasis_compactConvergenceUniformity_of_compact : HasBasis (𝓤 C(α, β)) (fun V : Set (β × β) => V ∈ 𝓤 β) fun V => { fg : C(α, β) × C(α, β) | ∀ x, (fg.1 x, fg.2 x) ∈ V } := hasBasis_compactConvergenceUniformity.to_hasBasis (fun p hp => ⟨p.2, hp.2, fun _fg hfg x _hx => hfg x⟩) fun V hV => ⟨⟨univ, V⟩, ⟨isCompact_univ, hV⟩, fun _fg hfg x => hfg x (mem_univ x)⟩ #align continuous_map.has_basis_compact_convergence_uniformity_of_compact ContinuousMap.hasBasis_compactConvergenceUniformity_of_compact /-- Convergence in the compact-open topology is the same as uniform convergence for sequences of continuous functions on a compact space. -/ theorem tendsto_iff_tendstoUniformly : Tendsto F p (𝓝 f) ↔ TendstoUniformly (fun i a => F i a) f p := by rw [tendsto_iff_forall_compact_tendstoUniformlyOn, ← tendstoUniformlyOn_univ] exact ⟨fun h => h univ isCompact_univ, fun h K _hK => h.mono (subset_univ K)⟩ #align continuous_map.tendsto_iff_tendsto_uniformly ContinuousMap.tendsto_iff_tendstoUniformly end CompactDomain
Mathlib/Topology/UniformSpace/CompactConvergence.lean
348
369
theorem uniformSpace_eq_inf_precomp_of_cover {δ₁ δ₂ : Type*} [TopologicalSpace δ₁] [TopologicalSpace δ₂] (φ₁ : C(δ₁, α)) (φ₂ : C(δ₂, α)) (h_proper₁ : IsProperMap φ₁) (h_proper₂ : IsProperMap φ₂) (h_cover : range φ₁ ∪ range φ₂ = univ) : (inferInstanceAs <| UniformSpace C(α, β)) = .comap (comp · φ₁) inferInstance ⊓ .comap (comp · φ₂) inferInstance := by
-- We check the analogous result for `UniformOnFun` using -- `UniformOnFun.uniformSpace_eq_inf_precomp_of_cover`... set 𝔖 : Set (Set α) := {K | IsCompact K} set 𝔗₁ : Set (Set δ₁) := {K | IsCompact K} set 𝔗₂ : Set (Set δ₂) := {K | IsCompact K} have h_image₁ : MapsTo (φ₁ '' ·) 𝔗₁ 𝔖 := fun K hK ↦ hK.image φ₁.continuous have h_image₂ : MapsTo (φ₂ '' ·) 𝔗₂ 𝔖 := fun K hK ↦ hK.image φ₂.continuous have h_preimage₁ : MapsTo (φ₁ ⁻¹' ·) 𝔖 𝔗₁ := fun K ↦ h_proper₁.isCompact_preimage have h_preimage₂ : MapsTo (φ₂ ⁻¹' ·) 𝔖 𝔗₂ := fun K ↦ h_proper₂.isCompact_preimage have h_cover' : ∀ S ∈ 𝔖, S ⊆ range φ₁ ∪ range φ₂ := fun S _ ↦ h_cover ▸ subset_univ _ -- ... and we just pull it back. simp_rw [compactConvergenceUniformSpace, replaceTopology_eq, inferInstanceAs, inferInstance, UniformOnFun.uniformSpace_eq_inf_precomp_of_cover _ _ _ _ _ h_image₁ h_image₂ h_preimage₁ h_preimage₂ h_cover', UniformSpace.comap_inf, ← UniformSpace.comap_comap] rfl
/- 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 theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a := symmDiff_comm a b ▸ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] (a b c d : α) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b := rfl #align to_dual_bihimp toDual_bihimp @[simp] theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b := rfl #align of_dual_symm_diff ofDual_symmDiff theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm] #align bihimp_comm bihimp_comm instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) := ⟨bihimp_comm⟩ #align bihimp_is_comm bihimp_isCommutative @[simp] theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self] #align bihimp_self bihimp_self @[simp] theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] #align bihimp_top bihimp_top @[simp] theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top] #align top_bihimp top_bihimp @[simp] theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b := @symmDiff_eq_bot αᵒᵈ _ _ _ #align bihimp_eq_top bihimp_eq_top theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq] #align bihimp_of_le bihimp_of_le theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq] #align bihimp_of_ge bihimp_of_ge theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c := le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb #align le_bihimp le_bihimp theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm] #align le_bihimp_iff le_bihimp_iff @[simp] theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b := inf_le_inf le_himp le_himp #align inf_le_bihimp inf_le_bihimp theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp] #align bihimp_eq_inf_himp_inf bihimp_eq_inf_himp_inf theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by rw [bihimp, h.himp_eq_left, h.himp_eq_right] #align codisjoint.bihimp_eq_inf Codisjoint.bihimp_eq_inf theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by rw [bihimp, himp_inf_distrib, himp_himp, himp_himp] #align himp_bihimp himp_bihimp @[simp] theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by rw [himp_bihimp] simp [bihimp] #align sup_himp_bihimp sup_himp_bihimp @[simp] theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a ⊓ b := @symmDiff_sdiff_eq_sup αᵒᵈ _ _ _ #align bihimp_himp_eq_inf bihimp_himp_eq_inf @[simp] theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a ⊓ b := @sdiff_symmDiff_eq_sup αᵒᵈ _ _ _ #align himp_bihimp_eq_inf himp_bihimp_eq_inf @[simp] theorem bihimp_inf_sup : a ⇔ b ⊓ (a ⊔ b) = a ⊓ b := @symmDiff_sup_inf αᵒᵈ _ _ _ #align bihimp_inf_sup bihimp_inf_sup @[simp] theorem sup_inf_bihimp : (a ⊔ b) ⊓ a ⇔ b = a ⊓ b := @inf_sup_symmDiff αᵒᵈ _ _ _ #align sup_inf_bihimp sup_inf_bihimp @[simp] theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a ⊔ b) = a ⊓ b := @symmDiff_symmDiff_inf αᵒᵈ _ _ _ #align bihimp_bihimp_sup bihimp_bihimp_sup @[simp] theorem sup_bihimp_bihimp : (a ⊔ b) ⇔ (a ⇔ b) = a ⊓ b := @inf_symmDiff_symmDiff αᵒᵈ _ _ _ #align sup_bihimp_bihimp sup_bihimp_bihimp theorem bihimp_triangle : a ⇔ b ⊓ b ⇔ c ≤ a ⇔ c := @symmDiff_triangle αᵒᵈ _ _ _ _ #align bihimp_triangle bihimp_triangle end GeneralizedHeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra α] (a : α) @[simp] theorem symmDiff_top' : a ∆ ⊤ = ¬a := by simp [symmDiff] #align symm_diff_top' symmDiff_top' @[simp] theorem top_symmDiff' : ⊤ ∆ a = ¬a := by simp [symmDiff] #align top_symm_diff' top_symmDiff' @[simp] theorem hnot_symmDiff_self : (¬a) ∆ a = ⊤ := by rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self] exact Codisjoint.top_le codisjoint_hnot_left #align hnot_symm_diff_self hnot_symmDiff_self @[simp] theorem symmDiff_hnot_self : a ∆ (¬a) = ⊤ := by rw [symmDiff_comm, hnot_symmDiff_self] #align symm_diff_hnot_self symmDiff_hnot_self theorem IsCompl.symmDiff_eq_top {a b : α} (h : IsCompl a b) : a ∆ b = ⊤ := by rw [h.eq_hnot, hnot_symmDiff_self] #align is_compl.symm_diff_eq_top IsCompl.symmDiff_eq_top end CoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] (a : α) @[simp] theorem bihimp_bot : a ⇔ ⊥ = aᶜ := by simp [bihimp] #align bihimp_bot bihimp_bot @[simp] theorem bot_bihimp : ⊥ ⇔ a = aᶜ := by simp [bihimp] #align bot_bihimp bot_bihimp @[simp] theorem compl_bihimp_self : aᶜ ⇔ a = ⊥ := @hnot_symmDiff_self αᵒᵈ _ _ #align compl_bihimp_self compl_bihimp_self @[simp] theorem bihimp_hnot_self : a ⇔ aᶜ = ⊥ := @symmDiff_hnot_self αᵒᵈ _ _ #align bihimp_hnot_self bihimp_hnot_self theorem IsCompl.bihimp_eq_bot {a b : α} (h : IsCompl a b) : a ⇔ b = ⊥ := by rw [h.eq_compl, compl_bihimp_self] #align is_compl.bihimp_eq_bot IsCompl.bihimp_eq_bot end HeytingAlgebra section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] (a b c d : α) @[simp] theorem sup_sdiff_symmDiff : (a ⊔ b) \ a ∆ b = a ⊓ b := sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf]) #align sup_sdiff_symm_diff sup_sdiff_symmDiff theorem disjoint_symmDiff_inf : Disjoint (a ∆ b) (a ⊓ b) := by rw [symmDiff_eq_sup_sdiff_inf] exact disjoint_sdiff_self_left #align disjoint_symm_diff_inf disjoint_symmDiff_inf theorem inf_symmDiff_distrib_left : a ⊓ b ∆ c = (a ⊓ b) ∆ (a ⊓ c) := by rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left, symmDiff_eq_sup_sdiff_inf] #align inf_symm_diff_distrib_left inf_symmDiff_distrib_left theorem inf_symmDiff_distrib_right : a ∆ b ⊓ c = (a ⊓ c) ∆ (b ⊓ c) := by simp_rw [inf_comm _ c, inf_symmDiff_distrib_left] #align inf_symm_diff_distrib_right inf_symmDiff_distrib_right theorem sdiff_symmDiff : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ a ⊓ c \ b := by simp only [(· ∆ ·), sdiff_sdiff_sup_sdiff'] #align sdiff_symm_diff sdiff_symmDiff theorem sdiff_symmDiff' : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ (a ⊔ b) := by rw [sdiff_symmDiff, sdiff_sup] #align sdiff_symm_diff' sdiff_symmDiff' @[simp]
Mathlib/Order/SymmDiff.lean
426
427
theorem symmDiff_sdiff_left : a ∆ b \ a = b \ a := by
rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.PowerBasis import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.RingTheory.QuotientNoetherian #align_import ring_theory.adjoin_root from "leanprover-community/mathlib"@"5c4b3d41a84bd2a1d79c7d9265e58a891e71be89" /-! # Adjoining roots of polynomials This file defines the commutative ring `AdjoinRoot f`, the ring R[X]/(f) obtained from a commutative ring `R` and a polynomial `f : R[X]`. If furthermore `R` is a field and `f` is irreducible, the field structure on `AdjoinRoot f` is constructed. We suggest stating results on `IsAdjoinRoot` instead of `AdjoinRoot` to achieve higher generality, since `IsAdjoinRoot` works for all different constructions of `R[α]` including `AdjoinRoot f = R[X]/(f)` itself. ## Main definitions and results The main definitions are in the `AdjoinRoot` namespace. * `mk f : R[X] →+* AdjoinRoot f`, the natural ring homomorphism. * `of f : R →+* AdjoinRoot f`, the natural ring homomorphism. * `root f : AdjoinRoot f`, the image of X in R[X]/(f). * `lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : (AdjoinRoot f) →+* S`, the ring homomorphism from R[X]/(f) to S extending `i : R →+* S` and sending `X` to `x`. * `lift_hom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S`, the algebra homomorphism from R[X]/(f) to S extending `algebraMap R S` and sending `X` to `x` * `equiv : (AdjoinRoot f →ₐ[F] E) ≃ {x // x ∈ f.aroots E}` a bijection between algebra homomorphisms from `AdjoinRoot` and roots of `f` in `S` -/ noncomputable section open scoped Classical open Polynomial universe u v w variable {R : Type u} {S : Type v} {K : Type w} open Polynomial Ideal /-- Adjoin a root of a polynomial `f` to a commutative ring `R`. We define the new ring as the quotient of `R[X]` by the principal ideal generated by `f`. -/ def AdjoinRoot [CommRing R] (f : R[X]) : Type u := Polynomial R ⧸ (span {f} : Ideal R[X]) #align adjoin_root AdjoinRoot namespace AdjoinRoot section CommRing variable [CommRing R] (f : R[X]) instance instCommRing : CommRing (AdjoinRoot f) := Ideal.Quotient.commRing _ #align adjoin_root.comm_ring AdjoinRoot.instCommRing instance : Inhabited (AdjoinRoot f) := ⟨0⟩ instance : DecidableEq (AdjoinRoot f) := Classical.decEq _ protected theorem nontrivial [IsDomain R] (h : degree f ≠ 0) : Nontrivial (AdjoinRoot f) := Ideal.Quotient.nontrivial (by simp_rw [Ne, span_singleton_eq_top, Polynomial.isUnit_iff, not_exists, not_and] rintro x hx rfl exact h (degree_C hx.ne_zero)) #align adjoin_root.nontrivial AdjoinRoot.nontrivial /-- Ring homomorphism from `R[x]` to `AdjoinRoot f` sending `X` to the `root`. -/ def mk : R[X] →+* AdjoinRoot f := Ideal.Quotient.mk _ #align adjoin_root.mk AdjoinRoot.mk @[elab_as_elim] theorem induction_on {C : AdjoinRoot f → Prop} (x : AdjoinRoot f) (ih : ∀ p : R[X], C (mk f p)) : C x := Quotient.inductionOn' x ih #align adjoin_root.induction_on AdjoinRoot.induction_on /-- Embedding of the original ring `R` into `AdjoinRoot f`. -/ def of : R →+* AdjoinRoot f := (mk f).comp C #align adjoin_root.of AdjoinRoot.of instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) := Submodule.Quotient.instSMul' _ instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) := Submodule.Quotient.distribSMul' _ @[simp] theorem smul_mk [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R[X]) : a • mk f x = mk f (a • x) := rfl #align adjoin_root.smul_mk AdjoinRoot.smul_mk theorem smul_of [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R) : a • of f x = of f (a • x) := by rw [of, RingHom.comp_apply, RingHom.comp_apply, smul_mk, smul_C] #align adjoin_root.smul_of AdjoinRoot.smul_of instance (R₁ R₂ : Type*) [SMul R₁ R₂] [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [IsScalarTower R₁ R₂ R] (f : R[X]) : IsScalarTower R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.isScalarTower _ _ instance (R₁ R₂ : Type*) [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [SMulCommClass R₁ R₂ R] (f : R[X]) : SMulCommClass R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.smulCommClass _ _ instance isScalarTower_right [DistribSMul S R] [IsScalarTower S R R] : IsScalarTower S (AdjoinRoot f) (AdjoinRoot f) := Ideal.Quotient.isScalarTower_right #align adjoin_root.is_scalar_tower_right AdjoinRoot.isScalarTower_right instance [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (f : R[X]) : DistribMulAction S (AdjoinRoot f) := Submodule.Quotient.distribMulAction' _ instance [CommSemiring S] [Algebra S R] : Algebra S (AdjoinRoot f) := Ideal.Quotient.algebra S @[simp] theorem algebraMap_eq : algebraMap R (AdjoinRoot f) = of f := rfl #align adjoin_root.algebra_map_eq AdjoinRoot.algebraMap_eq variable (S) theorem algebraMap_eq' [CommSemiring S] [Algebra S R] : algebraMap S (AdjoinRoot f) = (of f).comp (algebraMap S R) := rfl #align adjoin_root.algebra_map_eq' AdjoinRoot.algebraMap_eq' variable {S} theorem finiteType : Algebra.FiniteType R (AdjoinRoot f) := (Algebra.FiniteType.polynomial R).of_surjective _ (Ideal.Quotient.mkₐ_surjective R _) #align adjoin_root.finite_type AdjoinRoot.finiteType theorem finitePresentation : Algebra.FinitePresentation R (AdjoinRoot f) := (Algebra.FinitePresentation.polynomial R).quotient (Submodule.fg_span_singleton f) #align adjoin_root.finite_presentation AdjoinRoot.finitePresentation /-- The adjoined root. -/ def root : AdjoinRoot f := mk f X #align adjoin_root.root AdjoinRoot.root variable {f} instance hasCoeT : CoeTC R (AdjoinRoot f) := ⟨of f⟩ #align adjoin_root.has_coe_t AdjoinRoot.hasCoeT /-- Two `R`-`AlgHom` from `AdjoinRoot f` to the same `R`-algebra are the same iff they agree on `root f`. -/ @[ext] theorem algHom_ext [Semiring S] [Algebra R S] {g₁ g₂ : AdjoinRoot f →ₐ[R] S} (h : g₁ (root f) = g₂ (root f)) : g₁ = g₂ := Ideal.Quotient.algHom_ext R <| Polynomial.algHom_ext h #align adjoin_root.alg_hom_ext AdjoinRoot.algHom_ext @[simp] theorem mk_eq_mk {g h : R[X]} : mk f g = mk f h ↔ f ∣ g - h := Ideal.Quotient.eq.trans Ideal.mem_span_singleton #align adjoin_root.mk_eq_mk AdjoinRoot.mk_eq_mk @[simp] theorem mk_eq_zero {g : R[X]} : mk f g = 0 ↔ f ∣ g := mk_eq_mk.trans <| by rw [sub_zero] #align adjoin_root.mk_eq_zero AdjoinRoot.mk_eq_zero @[simp] theorem mk_self : mk f f = 0 := Quotient.sound' <| QuotientAddGroup.leftRel_apply.mpr (mem_span_singleton.2 <| by simp) #align adjoin_root.mk_self AdjoinRoot.mk_self @[simp] theorem mk_C (x : R) : mk f (C x) = x := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.mk_C AdjoinRoot.mk_C @[simp] theorem mk_X : mk f X = root f := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.mk_X AdjoinRoot.mk_X theorem mk_ne_zero_of_degree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : degree g < degree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_degree_lt h0 hd #align adjoin_root.mk_ne_zero_of_degree_lt AdjoinRoot.mk_ne_zero_of_degree_lt theorem mk_ne_zero_of_natDegree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : natDegree g < natDegree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_natDegree_lt h0 hd #align adjoin_root.mk_ne_zero_of_nat_degree_lt AdjoinRoot.mk_ne_zero_of_natDegree_lt @[simp] theorem aeval_eq (p : R[X]) : aeval (root f) p = mk f p := Polynomial.induction_on p (fun x => by rw [aeval_C] rfl) (fun p q ihp ihq => by rw [AlgHom.map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [AlgHom.map_mul, aeval_C, AlgHom.map_pow, aeval_X, RingHom.map_mul, mk_C, RingHom.map_pow, mk_X] rfl #align adjoin_root.aeval_eq AdjoinRoot.aeval_eq -- Porting note: the following proof was partly in term-mode, but I was not able to fix it. theorem adjoinRoot_eq_top : Algebra.adjoin R ({root f} : Set (AdjoinRoot f)) = ⊤ := by refine Algebra.eq_top_iff.2 fun x => ?_ induction x using AdjoinRoot.induction_on with | ih p => exact (Algebra.adjoin_singleton_eq_range_aeval R (root f)).symm ▸ ⟨p, aeval_eq p⟩ #align adjoin_root.adjoin_root_eq_top AdjoinRoot.adjoinRoot_eq_top @[simp] theorem eval₂_root (f : R[X]) : f.eval₂ (of f) (root f) = 0 := by rw [← algebraMap_eq, ← aeval_def, aeval_eq, mk_self] #align adjoin_root.eval₂_root AdjoinRoot.eval₂_root theorem isRoot_root (f : R[X]) : IsRoot (f.map (of f)) (root f) := by rw [IsRoot, eval_map, eval₂_root] #align adjoin_root.is_root_root AdjoinRoot.isRoot_root theorem isAlgebraic_root (hf : f ≠ 0) : IsAlgebraic R (root f) := ⟨f, hf, eval₂_root f⟩ #align adjoin_root.is_algebraic_root AdjoinRoot.isAlgebraic_root theorem of.injective_of_degree_ne_zero [IsDomain R] (hf : f.degree ≠ 0) : Function.Injective (AdjoinRoot.of f) := by rw [injective_iff_map_eq_zero] intro p hp rw [AdjoinRoot.of, RingHom.comp_apply, AdjoinRoot.mk_eq_zero] at hp by_cases h : f = 0 · exact C_eq_zero.mp (eq_zero_of_zero_dvd (by rwa [h] at hp)) · contrapose! hf with h_contra rw [← degree_C h_contra] apply le_antisymm (degree_le_of_dvd hp (by rwa [Ne, C_eq_zero])) _ rwa [degree_C h_contra, zero_le_degree_iff] #align adjoin_root.of.injective_of_degree_ne_zero AdjoinRoot.of.injective_of_degree_ne_zero variable [CommRing S] /-- Lift a ring homomorphism `i : R →+* S` to `AdjoinRoot f →+* S`. -/ def lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : AdjoinRoot f →+* S := by apply Ideal.Quotient.lift _ (eval₂RingHom i x) intro g H rcases mem_span_singleton.1 H with ⟨y, hy⟩ rw [hy, RingHom.map_mul, coe_eval₂RingHom, h, zero_mul] #align adjoin_root.lift AdjoinRoot.lift variable {i : R →+* S} {a : S} (h : f.eval₂ i a = 0) @[simp] theorem lift_mk (g : R[X]) : lift i a h (mk f g) = g.eval₂ i a := Ideal.Quotient.lift_mk _ _ _ #align adjoin_root.lift_mk AdjoinRoot.lift_mk @[simp] theorem lift_root : lift i a h (root f) = a := by rw [root, lift_mk, eval₂_X] #align adjoin_root.lift_root AdjoinRoot.lift_root @[simp] theorem lift_of {x : R} : lift i a h x = i x := by rw [← mk_C x, lift_mk, eval₂_C] #align adjoin_root.lift_of AdjoinRoot.lift_of @[simp] theorem lift_comp_of : (lift i a h).comp (of f) = i := RingHom.ext fun _ => @lift_of _ _ _ _ _ _ _ h _ #align adjoin_root.lift_comp_of AdjoinRoot.lift_comp_of variable (f) [Algebra R S] /-- Produce an algebra homomorphism `AdjoinRoot f →ₐ[R] S` sending `root f` to a root of `f` in `S`. -/ def liftHom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S := { lift (algebraMap R S) x hfx with commutes' := fun r => show lift _ _ hfx r = _ from lift_of hfx } #align adjoin_root.lift_hom AdjoinRoot.liftHom @[simp] theorem coe_liftHom (x : S) (hfx : aeval x f = 0) : (liftHom f x hfx : AdjoinRoot f →+* S) = lift (algebraMap R S) x hfx := rfl #align adjoin_root.coe_lift_hom AdjoinRoot.coe_liftHom @[simp] theorem aeval_algHom_eq_zero (ϕ : AdjoinRoot f →ₐ[R] S) : aeval (ϕ (root f)) f = 0 := by have h : ϕ.toRingHom.comp (of f) = algebraMap R S := RingHom.ext_iff.mpr ϕ.commutes rw [aeval_def, ← h, ← RingHom.map_zero ϕ.toRingHom, ← eval₂_root f, hom_eval₂] rfl #align adjoin_root.aeval_alg_hom_eq_zero AdjoinRoot.aeval_algHom_eq_zero @[simp] theorem liftHom_eq_algHom (f : R[X]) (ϕ : AdjoinRoot f →ₐ[R] S) : liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ) = ϕ := by suffices ϕ.equalizer (liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ)) = ⊤ by exact (AlgHom.ext fun x => (SetLike.ext_iff.mp this x).mpr Algebra.mem_top).symm rw [eq_top_iff, ← adjoinRoot_eq_top, Algebra.adjoin_le_iff, Set.singleton_subset_iff] exact (@lift_root _ _ _ _ _ _ _ (aeval_algHom_eq_zero f ϕ)).symm #align adjoin_root.lift_hom_eq_alg_hom AdjoinRoot.liftHom_eq_algHom variable (hfx : aeval a f = 0) @[simp] theorem liftHom_mk {g : R[X]} : liftHom f a hfx (mk f g) = aeval a g := lift_mk hfx g #align adjoin_root.lift_hom_mk AdjoinRoot.liftHom_mk @[simp] theorem liftHom_root : liftHom f a hfx (root f) = a := lift_root hfx #align adjoin_root.lift_hom_root AdjoinRoot.liftHom_root @[simp] theorem liftHom_of {x : R} : liftHom f a hfx (of f x) = algebraMap _ _ x := lift_of hfx #align adjoin_root.lift_hom_of AdjoinRoot.liftHom_of section AdjoinInv @[simp] theorem root_isInv (r : R) : of _ r * root (C r * X - 1) = 1 := by convert sub_eq_zero.1 ((eval₂_sub _).symm.trans <| eval₂_root <| C r * X - 1) <;> simp only [eval₂_mul, eval₂_C, eval₂_X, eval₂_one] #align adjoin_root.root_is_inv AdjoinRoot.root_isInv theorem algHom_subsingleton {S : Type*} [CommRing S] [Algebra R S] {r : R} : Subsingleton (AdjoinRoot (C r * X - 1) →ₐ[R] S) := ⟨fun f g => algHom_ext (@inv_unique _ _ (algebraMap R S r) _ _ (by rw [← f.commutes, ← f.map_mul, algebraMap_eq, root_isInv, map_one]) (by rw [← g.commutes, ← g.map_mul, algebraMap_eq, root_isInv, map_one]))⟩ #align adjoin_root.alg_hom_subsingleton AdjoinRoot.algHom_subsingleton end AdjoinInv section Prime variable {f} theorem isDomain_of_prime (hf : Prime f) : IsDomain (AdjoinRoot f) := (Ideal.Quotient.isDomain_iff_prime (span {f} : Ideal R[X])).mpr <| (Ideal.span_singleton_prime hf.ne_zero).mpr hf #align adjoin_root.is_domain_of_prime AdjoinRoot.isDomain_of_prime theorem noZeroSMulDivisors_of_prime_of_degree_ne_zero [IsDomain R] (hf : Prime f) (hf' : f.degree ≠ 0) : NoZeroSMulDivisors R (AdjoinRoot f) := haveI := isDomain_of_prime hf NoZeroSMulDivisors.iff_algebraMap_injective.mpr (of.injective_of_degree_ne_zero hf') #align adjoin_root.no_zero_smul_divisors_of_prime_of_degree_ne_zero AdjoinRoot.noZeroSMulDivisors_of_prime_of_degree_ne_zero end Prime end CommRing section Irreducible variable [Field K] {f : K[X]} instance span_maximal_of_irreducible [Fact (Irreducible f)] : (span {f}).IsMaximal := PrincipalIdealRing.isMaximal_of_irreducible <| Fact.out #align adjoin_root.span_maximal_of_irreducible AdjoinRoot.span_maximal_of_irreducible noncomputable instance instGroupWithZero [Fact (Irreducible f)] : GroupWithZero (AdjoinRoot f) := Quotient.groupWithZero (span {f} : Ideal K[X]) noncomputable instance instField [Fact (Irreducible f)] : Field (AdjoinRoot f) where __ := instCommRing _ __ := instGroupWithZero nnqsmul := (· • ·) qsmul := (· • ·) nnratCast_def q := by rw [← map_natCast (of f), ← map_natCast (of f), ← map_div₀, ← NNRat.cast_def]; rfl ratCast_def q := by rw [← map_natCast (of f), ← map_intCast (of f), ← map_div₀, ← Rat.cast_def]; rfl nnqsmul_def q x := AdjoinRoot.induction_on (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.nnqsmul_eq_C_mul] qsmul_def q x := -- Porting note: I gave the explicit motive and changed `rw` to `simp`. AdjoinRoot.induction_on (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.qsmul_eq_C_mul] #align adjoin_root.field AdjoinRoot.instField theorem coe_injective (h : degree f ≠ 0) : Function.Injective ((↑) : K → AdjoinRoot f) := have := AdjoinRoot.nontrivial f h (of f).injective #align adjoin_root.coe_injective AdjoinRoot.coe_injective theorem coe_injective' [Fact (Irreducible f)] : Function.Injective ((↑) : K → AdjoinRoot f) := (of f).injective #align adjoin_root.coe_injective' AdjoinRoot.coe_injective' variable (f) theorem mul_div_root_cancel [Fact (Irreducible f)] : (X - C (root f)) * ((f.map (of f)) / (X - C (root f))) = f.map (of f) := mul_div_eq_iff_isRoot.2 <| isRoot_root _ #align adjoin_root.mul_div_root_cancel AdjoinRoot.mul_div_root_cancel end Irreducible section IsNoetherianRing instance [CommRing R] [IsNoetherianRing R] {f : R[X]} : IsNoetherianRing (AdjoinRoot f) := Ideal.Quotient.isNoetherianRing _ end IsNoetherianRing section PowerBasis variable [CommRing R] {g : R[X]} theorem isIntegral_root' (hg : g.Monic) : IsIntegral R (root g) := ⟨g, hg, eval₂_root g⟩ #align adjoin_root.is_integral_root' AdjoinRoot.isIntegral_root' /-- `AdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. This is a well-defined right inverse to `AdjoinRoot.mk`, see `AdjoinRoot.mk_leftInverse`. -/ def modByMonicHom (hg : g.Monic) : AdjoinRoot g →ₗ[R] R[X] := (Submodule.liftQ _ (Polynomial.modByMonicHom g) fun f (hf : f ∈ (Ideal.span {g}).restrictScalars R) => (mem_ker_modByMonic hg).mpr (Ideal.mem_span_singleton.mp hf)).comp <| (Submodule.Quotient.restrictScalarsEquiv R (Ideal.span {g} : Ideal R[X])).symm.toLinearMap #align adjoin_root.mod_by_monic_hom AdjoinRoot.modByMonicHom @[simp] theorem modByMonicHom_mk (hg : g.Monic) (f : R[X]) : modByMonicHom hg (mk g f) = f %ₘ g := rfl #align adjoin_root.mod_by_monic_hom_mk AdjoinRoot.modByMonicHom_mk -- Porting note: the following proof was partly in term-mode, but I was not able to fix it. theorem mk_leftInverse (hg : g.Monic) : Function.LeftInverse (mk g) (modByMonicHom hg) := by intro f induction f using AdjoinRoot.induction_on rw [modByMonicHom_mk hg, mk_eq_mk, modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel_left, dvd_neg] apply dvd_mul_right #align adjoin_root.mk_left_inverse AdjoinRoot.mk_leftInverse theorem mk_surjective : Function.Surjective (mk g) := Ideal.Quotient.mk_surjective #align adjoin_root.mk_surjective AdjoinRoot.mk_surjectiveₓ /-- The elements `1, root g, ..., root g ^ (d - 1)` form a basis for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ def powerBasisAux' (hg : g.Monic) : Basis (Fin g.natDegree) R (AdjoinRoot g) := Basis.ofEquivFun { toFun := fun f i => (modByMonicHom hg f).coeff i invFun := fun c => mk g <| ∑ i : Fin g.natDegree, monomial i (c i) map_add' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_add, coeff_add, Pi.add_apply] map_smul' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_smul, coeff_smul, Pi.smul_apply, RingHom.id_apply] -- Porting note: another proof that I converted to tactic mode left_inv := by intro f induction f using AdjoinRoot.induction_on simp only [modByMonicHom_mk, sum_modByMonic_coeff hg degree_le_natDegree] refine (mk_eq_mk.mpr ?_).symm rw [modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel] exact dvd_mul_right _ _ right_inv := fun x => funext fun i => by nontriviality R simp only [modByMonicHom_mk] rw [(modByMonic_eq_self_iff hg).mpr, finset_sum_coeff] · simp_rw [coeff_monomial, Fin.val_eq_val, Finset.sum_ite_eq', if_pos (Finset.mem_univ _)] · simp_rw [← C_mul_X_pow_eq_monomial] exact (degree_eq_natDegree <| hg.ne_zero).symm ▸ degree_sum_fin_lt _ } #align adjoin_root.power_basis_aux' AdjoinRoot.powerBasisAux' -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. -- This lemma should have the simp tag but this causes a lint issue. theorem powerBasisAux'_repr_symm_apply (hg : g.Monic) (c : Fin g.natDegree →₀ R) : (powerBasisAux' hg).repr.symm c = mk g (∑ i : Fin _, monomial i (c i)) := rfl #align adjoin_root.power_basis_aux'_repr_symm_apply AdjoinRoot.powerBasisAux'_repr_symm_apply -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. @[simp] theorem powerBasisAux'_repr_apply_to_fun (hg : g.Monic) (f : AdjoinRoot g) (i : Fin g.natDegree) : (powerBasisAux' hg).repr f i = (modByMonicHom hg f).coeff ↑i := rfl #align adjoin_root.power_basis_aux'_repr_apply_to_fun AdjoinRoot.powerBasisAux'_repr_apply_to_fun /-- The power basis `1, root g, ..., root g ^ (d - 1)` for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ @[simps] def powerBasis' (hg : g.Monic) : PowerBasis R (AdjoinRoot g) where gen := root g dim := g.natDegree basis := powerBasisAux' hg basis_eq_pow i := by simp only [powerBasisAux', Basis.coe_ofEquivFun, LinearEquiv.coe_symm_mk] rw [Finset.sum_eq_single i] · rw [Function.update_same, monomial_one_right_eq_X_pow, (mk g).map_pow, mk_X] · intro j _ hj rw [← monomial_zero_right _] convert congr_arg _ (Function.update_noteq hj _ _) -- Fix `DecidableEq` mismatch · intros have := Finset.mem_univ i contradiction #align adjoin_root.power_basis' AdjoinRoot.powerBasis' variable [Field K] {f : K[X]} theorem isIntegral_root (hf : f ≠ 0) : IsIntegral K (root f) := (isAlgebraic_root hf).isIntegral #align adjoin_root.is_integral_root AdjoinRoot.isIntegral_root theorem minpoly_root (hf : f ≠ 0) : minpoly K (root f) = f * C f.leadingCoeff⁻¹ := by have f'_monic : Monic _ := monic_mul_leadingCoeff_inv hf refine (minpoly.unique K _ f'_monic ?_ ?_).symm · rw [AlgHom.map_mul, aeval_eq, mk_self, zero_mul] intro q q_monic q_aeval have commutes : (lift (algebraMap K (AdjoinRoot f)) (root f) q_aeval).comp (mk q) = mk f := by ext · simp only [RingHom.comp_apply, mk_C, lift_of] rfl · simp only [RingHom.comp_apply, mk_X, lift_root] rw [degree_eq_natDegree f'_monic.ne_zero, degree_eq_natDegree q_monic.ne_zero, Nat.cast_le, natDegree_mul hf, natDegree_C, add_zero] · apply natDegree_le_of_dvd · have : mk f q = 0 := by rw [← commutes, RingHom.comp_apply, mk_self, RingHom.map_zero] exact mk_eq_zero.1 this · exact q_monic.ne_zero · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] #align adjoin_root.minpoly_root AdjoinRoot.minpoly_root /-- The elements `1, root f, ..., root f ^ (d - 1)` form a basis for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ def powerBasisAux (hf : f ≠ 0) : Basis (Fin f.natDegree) K (AdjoinRoot f) := by let f' := f * C f.leadingCoeff⁻¹ have deg_f' : f'.natDegree = f.natDegree := by rw [natDegree_mul hf, natDegree_C, add_zero] · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] have minpoly_eq : minpoly K (root f) = f' := minpoly_root hf apply @Basis.mk _ _ _ fun i : Fin f.natDegree => root f ^ i.val · rw [← deg_f', ← minpoly_eq] exact linearIndependent_pow (root f) · rintro y - rw [← deg_f', ← minpoly_eq] apply (isIntegral_root hf).mem_span_pow obtain ⟨g⟩ := y use g rw [aeval_eq] rfl #align adjoin_root.power_basis_aux AdjoinRoot.powerBasisAux /-- The power basis `1, root f, ..., root f ^ (d - 1)` for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ @[simps!] -- Porting note: was `[simps]` def powerBasis (hf : f ≠ 0) : PowerBasis K (AdjoinRoot f) where gen := root f dim := f.natDegree basis := powerBasisAux hf basis_eq_pow := by simp [powerBasisAux] #align adjoin_root.power_basis AdjoinRoot.powerBasis theorem minpoly_powerBasis_gen (hf : f ≠ 0) : minpoly K (powerBasis hf).gen = f * C f.leadingCoeff⁻¹ := by rw [powerBasis_gen, minpoly_root hf] #align adjoin_root.minpoly_power_basis_gen AdjoinRoot.minpoly_powerBasis_gen theorem minpoly_powerBasis_gen_of_monic (hf : f.Monic) (hf' : f ≠ 0 := hf.ne_zero) : minpoly K (powerBasis hf').gen = f := by rw [minpoly_powerBasis_gen hf', hf.leadingCoeff, inv_one, C.map_one, mul_one] #align adjoin_root.minpoly_power_basis_gen_of_monic AdjoinRoot.minpoly_powerBasis_gen_of_monic end PowerBasis section Equiv section minpoly variable [CommRing R] [CommRing S] [Algebra R S] (x : S) (R) open Algebra Polynomial /-- The surjective algebra morphism `R[X]/(minpoly R x) → R[x]`. If `R` is a integrally closed domain and `x` is integral, this is an isomorphism, see `minpoly.equivAdjoin`. -/ @[simps!] def Minpoly.toAdjoin : AdjoinRoot (minpoly R x) →ₐ[R] adjoin R ({x} : Set S) := liftHom _ ⟨x, self_mem_adjoin_singleton R x⟩ (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) #align adjoin_root.minpoly.to_adjoin AdjoinRoot.Minpoly.toAdjoin variable {R x} theorem Minpoly.toAdjoin_apply' (a : AdjoinRoot (minpoly R x)) : Minpoly.toAdjoin R x a = liftHom (minpoly R x) (⟨x, self_mem_adjoin_singleton R x⟩ : adjoin R ({x} : Set S)) (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) a := rfl #align adjoin_root.minpoly.to_adjoin_apply' AdjoinRoot.Minpoly.toAdjoin_apply' theorem Minpoly.toAdjoin.apply_X : Minpoly.toAdjoin R x (mk (minpoly R x) X) = ⟨x, self_mem_adjoin_singleton R x⟩ := by simp [toAdjoin] set_option linter.uppercaseLean3 false in #align adjoin_root.minpoly.to_adjoin.apply_X AdjoinRoot.Minpoly.toAdjoin.apply_X variable (R x) theorem Minpoly.toAdjoin.surjective : Function.Surjective (Minpoly.toAdjoin R x) := by rw [← range_top_iff_surjective, _root_.eq_top_iff, ← adjoin_adjoin_coe_preimage] exact adjoin_le fun ⟨y₁, y₂⟩ h ↦ ⟨mk (minpoly R x) X, by simpa [toAdjoin] using h.symm⟩ #align adjoin_root.minpoly.to_adjoin.surjective AdjoinRoot.Minpoly.toAdjoin.surjective end minpoly section Equiv' variable [CommRing R] [CommRing S] [Algebra R S] variable (g : R[X]) (pb : PowerBasis R S) /-- If `S` is an extension of `R` with power basis `pb` and `g` is a monic polynomial over `R` such that `pb.gen` has a minimal polynomial `g`, then `S` is isomorphic to `AdjoinRoot g`. Compare `PowerBasis.equivOfRoot`, which would require `h₂ : aeval pb.gen (minpoly R (root g)) = 0`; that minimal polynomial is not guaranteed to be identical to `g`. -/ @[simps (config := .asFn)] def equiv' (h₁ : aeval (root g) (minpoly R pb.gen) = 0) (h₂ : aeval pb.gen g = 0) : AdjoinRoot g ≃ₐ[R] S := { AdjoinRoot.liftHom g pb.gen h₂ with toFun := AdjoinRoot.liftHom g pb.gen h₂ invFun := pb.lift (root g) h₁ -- Porting note: another term-mode proof converted to tactic-mode. left_inv := fun x => by induction x using AdjoinRoot.induction_on rw [liftHom_mk, pb.lift_aeval, aeval_eq] right_inv := fun x => by nontriviality S obtain ⟨f, _hf, rfl⟩ := pb.exists_eq_aeval x rw [pb.lift_aeval, aeval_eq, liftHom_mk] } #align adjoin_root.equiv' AdjoinRoot.equiv' -- This lemma should have the simp tag but this causes a lint issue. theorem equiv'_toAlgHom (h₁ : aeval (root g) (minpoly R pb.gen) = 0) (h₂ : aeval pb.gen g = 0) : (equiv' g pb h₁ h₂).toAlgHom = AdjoinRoot.liftHom g pb.gen h₂ := rfl #align adjoin_root.equiv'_to_alg_hom AdjoinRoot.equiv'_toAlgHom -- This lemma should have the simp tag but this causes a lint issue. theorem equiv'_symm_toAlgHom (h₁ : aeval (root g) (minpoly R pb.gen) = 0) (h₂ : aeval pb.gen g = 0) : (equiv' g pb h₁ h₂).symm.toAlgHom = pb.lift (root g) h₁ := rfl #align adjoin_root.equiv'_symm_to_alg_hom AdjoinRoot.equiv'_symm_toAlgHom end Equiv' section Field variable (L F : Type*) [Field F] [CommRing L] [IsDomain L] [Algebra F L] /-- If `L` is a field extension of `F` and `f` is a polynomial over `F` then the set of maps from `F[x]/(f)` into `L` is in bijection with the set of roots of `f` in `L`. -/ def equiv (f : F[X]) (hf : f ≠ 0) : (AdjoinRoot f →ₐ[F] L) ≃ { x // x ∈ f.aroots L } := (powerBasis hf).liftEquiv'.trans ((Equiv.refl _).subtypeEquiv fun x => by rw [powerBasis_gen, minpoly_root hf, aroots_mul, aroots_C, add_zero, Equiv.refl_apply] exact (monic_mul_leadingCoeff_inv hf).ne_zero) #align adjoin_root.equiv AdjoinRoot.equiv end Field end Equiv -- Porting note: consider splitting the file here. In the current mathlib3, the only result -- that depends any of these lemmas was -- `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` in `NumberTheory.KummerDedekind` -- that uses -- `PowerBasis.quotientEquivQuotientMinpolyMap == PowerBasis.quotientEquivQuotientMinpolyMap` section open Ideal DoubleQuot Polynomial variable [CommRing R] (I : Ideal R) (f : R[X]) /-- The natural isomorphism `R[α]/(I[α]) ≅ R[α]/((I[x] ⊔ (f)) / (f))` for `α` a root of `f : R[X]` and `I : Ideal R`. See `adjoin_root.quot_map_of_equiv` for the isomorphism with `(R/I)[X] / (f mod I)`. -/ def quotMapOfEquivQuotMapCMapSpanMk : AdjoinRoot f ⧸ I.map (of f) ≃+* AdjoinRoot f ⧸ (I.map (C : R →+* R[X])).map (Ideal.Quotient.mk (span {f})) := Ideal.quotEquivOfEq (by rw [of, AdjoinRoot.mk, Ideal.map_map]) set_option linter.uppercaseLean3 false in #align adjoin_root.quot_map_of_equiv_quot_map_C_map_span_mk AdjoinRoot.quotMapOfEquivQuotMapCMapSpanMk @[simp] theorem quotMapOfEquivQuotMapCMapSpanMk_mk (x : AdjoinRoot f) : quotMapOfEquivQuotMapCMapSpanMk I f (Ideal.Quotient.mk (I.map (of f)) x) = Ideal.Quotient.mk (Ideal.map (Ideal.Quotient.mk (span {f})) (I.map (C : R →+* R[X]))) x := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.quot_map_of_equiv_quot_map_C_map_span_mk_mk AdjoinRoot.quotMapOfEquivQuotMapCMapSpanMk_mk --this lemma should have the simp tag but this causes a lint issue theorem quotMapOfEquivQuotMapCMapSpanMk_symm_mk (x : AdjoinRoot f) : (quotMapOfEquivQuotMapCMapSpanMk I f).symm (Ideal.Quotient.mk ((I.map (C : R →+* R[X])).map (Ideal.Quotient.mk (span {f}))) x) = Ideal.Quotient.mk (I.map (of f)) x := by rw [quotMapOfEquivQuotMapCMapSpanMk, Ideal.quotEquivOfEq_symm] exact Ideal.quotEquivOfEq_mk _ _ set_option linter.uppercaseLean3 false in #align adjoin_root.quot_map_of_equiv_quot_map_C_map_span_mk_symm_mk AdjoinRoot.quotMapOfEquivQuotMapCMapSpanMk_symm_mk /-- The natural isomorphism `R[α]/((I[x] ⊔ (f)) / (f)) ≅ (R[x]/I[x])/((f) ⊔ I[x] / I[x])` for `α` a root of `f : R[X]` and `I : Ideal R`-/ def quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk : AdjoinRoot f ⧸ (I.map (C : R →+* R[X])).map (Ideal.Quotient.mk (span ({f} : Set R[X]))) ≃+* (R[X] ⧸ I.map (C : R →+* R[X])) ⧸ (span ({f} : Set R[X])).map (Ideal.Quotient.mk (I.map (C : R →+* R[X]))) := quotQuotEquivComm (Ideal.span ({f} : Set R[X])) (I.map (C : R →+* R[X])) set_option linter.uppercaseLean3 false in #align adjoin_root.quot_map_C_map_span_mk_equiv_quot_map_C_quot_map_span_mk AdjoinRoot.quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk -- This lemma should have the simp tag but this causes a lint issue. theorem quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk_mk (p : R[X]) : quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk I f (Ideal.Quotient.mk _ (mk f p)) = quotQuotMk (I.map C) (span {f}) p := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.quot_map_C_map_span_mk_equiv_quot_map_C_quot_map_span_mk_mk AdjoinRoot.quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk_mk @[simp] theorem quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk_symm_quotQuotMk (p : R[X]) : (quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk I f).symm (quotQuotMk (I.map C) (span {f}) p) = Ideal.Quotient.mk (Ideal.map (Ideal.Quotient.mk (span {f})) (I.map (C : R →+* R[X]))) (mk f p) := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.quot_map_C_map_span_mk_equiv_quot_map_C_quot_map_span_mk_symm_quot_quot_mk AdjoinRoot.quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk_symm_quotQuotMk /-- The natural isomorphism `(R/I)[x]/(f mod I) ≅ (R[x]/I*R[x])/(f mod I[x])` where `f : R[X]` and `I : Ideal R`-/ def Polynomial.quotQuotEquivComm : (R ⧸ I)[X] ⧸ span ({f.map (Ideal.Quotient.mk I)} : Set (Polynomial (R ⧸ I))) ≃+* (R[X] ⧸ (I.map C)) ⧸ span ({(Ideal.Quotient.mk (I.map C)) f} : Set (R[X] ⧸ (I.map C))) := quotientEquiv (span ({f.map (Ideal.Quotient.mk I)} : Set (Polynomial (R ⧸ I)))) (span {Ideal.Quotient.mk (I.map Polynomial.C) f}) (polynomialQuotientEquivQuotientPolynomial I) (by rw [map_span, Set.image_singleton, RingEquiv.coe_toRingHom, polynomialQuotientEquivQuotientPolynomial_map_mk I f]) #align adjoin_root.polynomial.quot_quot_equiv_comm AdjoinRoot.Polynomial.quotQuotEquivComm @[simp]
Mathlib/RingTheory/AdjoinRoot.lean
786
791
theorem Polynomial.quotQuotEquivComm_mk (p : R[X]) : (Polynomial.quotQuotEquivComm I f) (Ideal.Quotient.mk _ (p.map (Ideal.Quotient.mk I))) = Ideal.Quotient.mk (span ({(Ideal.Quotient.mk (I.map C)) f} : Set (R[X] ⧸ (I.map C)))) (Ideal.Quotient.mk (I.map C) p) := by
simp only [Polynomial.quotQuotEquivComm, quotientEquiv_mk, polynomialQuotientEquivQuotientPolynomial_map_mk]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Anne Baanen -/ import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.Data.Matrix.RowCol import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.GroupTheory.Perm.Fin import Mathlib.LinearAlgebra.Alternating.Basic #align_import linear_algebra.matrix.determinant from "leanprover-community/mathlib"@"c3019c79074b0619edb4b27553a91b2e82242395" /-! # Determinant of a matrix This file defines the determinant of a matrix, `Matrix.det`, and its essential properties. ## Main definitions - `Matrix.det`: the determinant of a square matrix, as a sum over permutations - `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix ## Main results - `det_mul`: the determinant of `A * B` is the product of determinants - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row - `det_block_diagonal`: the determinant of a block diagonal matrix is a product of the blocks' determinants ## Implementation notes It is possible to configure `simp` to compute determinants. See the file `test/matrix.lean` for some examples. -/ universe u v w z open Equiv Equiv.Perm Finset Function namespace Matrix open Matrix variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] variable {R : Type v} [CommRing R] local notation "ε " σ:arg => ((sign σ : ℤ) : R) /-- `det` is an `AlternatingMap` in the rows of the matrix. -/ def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R := MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj) #align matrix.det_row_alternating Matrix.detRowAlternating /-- The determinant of a matrix given by the Leibniz formula. -/ abbrev det (M : Matrix n n R) : R := detRowAlternating M #align matrix.det Matrix.det theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i := MultilinearMap.alternatization_apply _ M #align matrix.det_apply Matrix.det_apply -- This is what the old definition was. We use it to avoid having to change the old proofs below theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by simp [det_apply, Units.smul_def] #align matrix.det_apply' Matrix.det_apply' @[simp] theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by rw [det_apply'] refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_ · rintro σ - h2 cases' not_forall.1 (mt Equiv.ext h2) with x h3 convert mul_zero (ε σ) apply Finset.prod_eq_zero (mem_univ x) exact if_neg h3 · simp · simp #align matrix.det_diagonal Matrix.det_diagonal -- @[simp] -- Porting note (#10618): simp can prove this theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero #align matrix.det_zero Matrix.det_zero @[simp] theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one] #align matrix.det_one Matrix.det_one theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply] #align matrix.det_is_empty Matrix.det_isEmpty @[simp] theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by ext exact det_isEmpty #align matrix.coe_det_is_empty Matrix.coe_det_isEmpty theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 := haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h det_isEmpty #align matrix.det_eq_one_of_card_eq_zero Matrix.det_eq_one_of_card_eq_zero /-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element. Although `Unique` implies `DecidableEq` and `Fintype`, the instances might not be syntactically equal. Thus, we need to fill in the args explicitly. -/ @[simp] theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) : det A = A default default := by simp [det_apply, univ_unique] #align matrix.det_unique Matrix.det_unique theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) : det A = A k k := by have := uniqueOfSubsingleton k convert det_unique A #align matrix.det_eq_elem_of_subsingleton Matrix.det_eq_elem_of_subsingleton theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) : det A = A k k := haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le det_eq_elem_of_subsingleton _ _ #align matrix.det_eq_elem_of_card_eq_one Matrix.det_eq_elem_of_card_eq_one theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) : (∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by rw [← Finite.injective_iff_bijective, Injective] at H push_neg at H exact H exact sum_involution (fun σ _ => σ * Equiv.swap i j) (fun σ _ => by have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) simp [this, sign_swap hij, -sign_swap', prod_mul_distrib]) (fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ => mul_swap_involutive i j σ #align matrix.det_mul_aux Matrix.det_mul_aux @[simp] theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N := calc det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] rw [Finset.sum_comm] _ = ∑ p ∈ (@univ (n → n) _).filter Bijective, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := (Eq.symm <| sum_subset (filter_subset _ _) fun f _ hbij => det_mul_aux <| by simpa only [true_and_iff, mem_filter, mem_univ] using hbij) _ = ∑ τ : Perm n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (τ i) * N (τ i) i := sum_bij (fun p h ↦ Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ ↦ mem_univ _) (fun _ _ _ _ h ↦ by injection h) (fun b _ ↦ ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) fun _ _ ↦ rfl _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * ε τ * ∏ j, M (τ j) (σ j) := by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * (ε σ * ε τ) * ∏ i, M (τ i) i := (sum_congr rfl fun σ _ => Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ fun τ => by have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by rw [← (σ⁻¹ : _ ≃ _).prod_comp] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] have h : ε σ * ε (τ * σ⁻¹) = ε τ := calc ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by rw [mul_comm, sign_mul (τ * σ⁻¹)] simp only [Int.cast_mul, Units.val_mul] _ = ε τ := by simp only [inv_mul_cancel_right] simp_rw [Equiv.coe_mulRight, h] simp only [this]) _ = det M * det N := by simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc] #align matrix.det_mul Matrix.det_mul /-- The determinant of a matrix, as a monoid homomorphism. -/ def detMonoidHom : Matrix n n R →* R where toFun := det map_one' := det_one map_mul' := det_mul #align matrix.det_monoid_hom Matrix.detMonoidHom @[simp] theorem coe_detMonoidHom : (detMonoidHom : Matrix n n R → R) = det := rfl #align matrix.coe_det_monoid_hom Matrix.coe_detMonoidHom /-- On square matrices, `mul_comm` applies under `det`. -/ theorem det_mul_comm (M N : Matrix m m R) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] #align matrix.det_mul_comm Matrix.det_mul_comm /-- On square matrices, `mul_left_comm` applies under `det`. -/
Mathlib/LinearAlgebra/Matrix/Determinant/Basic.lean
199
200
theorem det_mul_left_comm (M N P : Matrix m m R) : det (M * (N * P)) = det (N * (M * P)) := by
rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul]
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.FinitelyGenerated import Mathlib.ModelTheory.DirectLimit import Mathlib.ModelTheory.Bundled #align_import model_theory.fraisse from "leanprover-community/mathlib"@"0602c59878ff3d5f71dea69c2d32ccf2e93e5398" /-! # Fraïssé Classes and Fraïssé Limits This file pertains to the ages of countable first-order structures. The age of a structure is the class of all finitely-generated structures that embed into it. Of particular interest are Fraïssé classes, which are exactly the ages of countable ultrahomogeneous structures. To each is associated a unique (up to nonunique isomorphism) Fraïssé limit - the countable ultrahomogeneous structure with that age. ## Main Definitions * `FirstOrder.Language.age` is the class of finitely-generated structures that embed into a particular structure. * A class `K` is `FirstOrder.Language.Hereditary` when all finitely-generated structures that embed into structures in `K` are also in `K`. * A class `K` has `FirstOrder.Language.JointEmbedding` when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. * A class `K` has `FirstOrder.Language.Amalgamation` when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. * `FirstOrder.Language.IsFraisse` indicates that a class is nonempty, isomorphism-invariant, essentially countable, and satisfies the hereditary, joint embedding, and amalgamation properties. * `FirstOrder.Language.IsFraisseLimit` indicates that a structure is a Fraïssé limit for a given class. ## Main Results * We show that the age of any structure is isomorphism-invariant and satisfies the hereditary and joint-embedding properties. * `FirstOrder.Language.age.countable_quotient` shows that the age of any countable structure is essentially countable. * `FirstOrder.Language.exists_countable_is_age_of_iff` gives necessary and sufficient conditions for a class to be the age of a countable structure in a language with countably many functions. ## Implementation Notes * Classes of structures are formalized with `Set (Bundled L.Structure)`. * Some results pertain to countable limit structures, others to countably-generated limit structures. In the case of a language with countably many function symbols, these are equivalent. ## References - [W. Hodges, *A Shorter Model Theory*][Hodges97] - [K. Tent, M. Ziegler, *A Course in Model Theory*][Tent_Ziegler] ## TODO * Show existence and uniqueness of Fraïssé limits -/ universe u v w w' open scoped FirstOrder open Set CategoryTheory namespace FirstOrder namespace Language open Structure Substructure variable (L : Language.{u, v}) /-! ### The Age of a Structure and Fraïssé Classes-/ /-- The age of a structure `M` is the class of finitely-generated structures that embed into it. -/ def age (M : Type w) [L.Structure M] : Set (Bundled.{w} L.Structure) := {N | Structure.FG L N ∧ Nonempty (N ↪[L] M)} #align first_order.language.age FirstOrder.Language.age variable {L} (K : Set (Bundled.{w} L.Structure)) /-- A class `K` has the hereditary property when all finitely-generated structures that embed into structures in `K` are also in `K`. -/ def Hereditary : Prop := ∀ M : Bundled.{w} L.Structure, M ∈ K → L.age M ⊆ K #align first_order.language.hereditary FirstOrder.Language.Hereditary /-- A class `K` has the joint embedding property when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. -/ def JointEmbedding : Prop := DirectedOn (fun M N : Bundled.{w} L.Structure => Nonempty (M ↪[L] N)) K #align first_order.language.joint_embedding FirstOrder.Language.JointEmbedding /-- A class `K` has the amalgamation property when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. -/ def Amalgamation : Prop := ∀ (M N P : Bundled.{w} L.Structure) (MN : M ↪[L] N) (MP : M ↪[L] P), M ∈ K → N ∈ K → P ∈ K → ∃ (Q : Bundled.{w} L.Structure) (NQ : N ↪[L] Q) (PQ : P ↪[L] Q), Q ∈ K ∧ NQ.comp MN = PQ.comp MP #align first_order.language.amalgamation FirstOrder.Language.Amalgamation /-- A Fraïssé class is a nonempty, isomorphism-invariant, essentially countable class of structures satisfying the hereditary, joint embedding, and amalgamation properties. -/ class IsFraisse : Prop where is_nonempty : K.Nonempty FG : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M is_equiv_invariant : ∀ M N : Bundled.{w} L.Structure, Nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K) is_essentially_countable : (Quotient.mk' '' K).Countable hereditary : Hereditary K jointEmbedding : JointEmbedding K amalgamation : Amalgamation K #align first_order.language.is_fraisse FirstOrder.Language.IsFraisse variable {K} (L) (M : Type w) [Structure L M] theorem age.is_equiv_invariant (N P : Bundled.{w} L.Structure) (h : Nonempty (N ≃[L] P)) : N ∈ L.age M ↔ P ∈ L.age M := and_congr h.some.fg_iff ⟨Nonempty.map fun x => Embedding.comp x h.some.symm.toEmbedding, Nonempty.map fun x => Embedding.comp x h.some.toEmbedding⟩ #align first_order.language.age.is_equiv_invariant FirstOrder.Language.age.is_equiv_invariant variable {L} {M} {N : Type w} [Structure L N] theorem Embedding.age_subset_age (MN : M ↪[L] N) : L.age M ⊆ L.age N := fun _ => And.imp_right (Nonempty.map MN.comp) #align first_order.language.embedding.age_subset_age FirstOrder.Language.Embedding.age_subset_age theorem Equiv.age_eq_age (MN : M ≃[L] N) : L.age M = L.age N := le_antisymm MN.toEmbedding.age_subset_age MN.symm.toEmbedding.age_subset_age #align first_order.language.equiv.age_eq_age FirstOrder.Language.Equiv.age_eq_age theorem Structure.FG.mem_age_of_equiv {M N : Bundled L.Structure} (h : Structure.FG L M) (MN : Nonempty (M ≃[L] N)) : N ∈ L.age M := ⟨MN.some.fg_iff.1 h, ⟨MN.some.symm.toEmbedding⟩⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Structure.fg.mem_age_of_equiv FirstOrder.Language.Structure.FG.mem_age_of_equiv theorem Hereditary.is_equiv_invariant_of_fg (h : Hereditary K) (fg : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) (M N : Bundled.{w} L.Structure) (hn : Nonempty (M ≃[L] N)) : M ∈ K ↔ N ∈ K := ⟨fun MK => h M MK ((fg M MK).mem_age_of_equiv hn), fun NK => h N NK ((fg N NK).mem_age_of_equiv ⟨hn.some.symm⟩)⟩ #align first_order.language.hereditary.is_equiv_invariant_of_fg FirstOrder.Language.Hereditary.is_equiv_invariant_of_fg variable (M) theorem age.nonempty : (L.age M).Nonempty := ⟨Bundled.of (Substructure.closure L (∅ : Set M)), (fg_iff_structure_fg _).1 (fg_closure Set.finite_empty), ⟨Substructure.subtype _⟩⟩ #align first_order.language.age.nonempty FirstOrder.Language.age.nonempty theorem age.hereditary : Hereditary (L.age M) := fun _ hN _ hP => hN.2.some.age_subset_age hP #align first_order.language.age.hereditary FirstOrder.Language.age.hereditary theorem age.jointEmbedding : JointEmbedding (L.age M) := fun _ hN _ hP => ⟨Bundled.of (↥(hN.2.some.toHom.range ⊔ hP.2.some.toHom.range)), ⟨(fg_iff_structure_fg _).1 ((hN.1.range hN.2.some.toHom).sup (hP.1.range hP.2.some.toHom)), ⟨Substructure.subtype _⟩⟩, ⟨Embedding.comp (inclusion le_sup_left) hN.2.some.equivRange.toEmbedding⟩, ⟨Embedding.comp (inclusion le_sup_right) hP.2.some.equivRange.toEmbedding⟩⟩ #align first_order.language.age.joint_embedding FirstOrder.Language.age.jointEmbedding /-- The age of a countable structure is essentially countable (has countably many isomorphism classes). -/ theorem age.countable_quotient [h : Countable M] : (Quotient.mk' '' L.age M).Countable := by classical refine (congr_arg _ (Set.ext <| Quotient.forall.2 fun N => ?_)).mp (countable_range fun s : Finset M => ⟦⟨closure L (s : Set M), inferInstance⟩⟧) constructor · rintro ⟨s, hs⟩ use Bundled.of (closure L (s : Set M)) exact ⟨⟨(fg_iff_structure_fg _).1 (fg_closure s.finite_toSet), ⟨Substructure.subtype _⟩⟩, hs⟩ · simp only [mem_range, Quotient.eq] rintro ⟨P, ⟨⟨s, hs⟩, ⟨PM⟩⟩, hP2⟩ have : P ≈ N := by apply Quotient.eq'.mp; rw [hP2]; rfl -- Porting note: added refine ⟨s.image PM, Setoid.trans (b := P) ?_ this⟩ rw [← Embedding.coe_toHom, Finset.coe_image, closure_image PM.toHom, hs, ← Hom.range_eq_map] exact ⟨PM.equivRange.symm⟩ #align first_order.language.age.countable_quotient FirstOrder.Language.age.countable_quotient /-- The age of a direct limit of structures is the union of the ages of the structures. -/ -- @[simp] -- Porting note: cannot simplify itself theorem age_directLimit {ι : Type w} [Preorder ι] [IsDirected ι (· ≤ ·)] [Nonempty ι] (G : ι → Type max w w') [∀ i, L.Structure (G i)] (f : ∀ i j, i ≤ j → G i ↪[L] G j) [DirectedSystem G fun i j h => f i j h] : L.age (DirectLimit G f) = ⋃ i : ι, L.age (G i) := by classical ext M simp only [mem_iUnion] constructor · rintro ⟨Mfg, ⟨e⟩⟩ obtain ⟨s, hs⟩ := Mfg.range e.toHom let out := @Quotient.out _ (DirectLimit.setoid G f) obtain ⟨i, hi⟩ := Finset.exists_le (s.image (Sigma.fst ∘ out)) have e' := (DirectLimit.of L ι G f i).equivRange.symm.toEmbedding refine ⟨i, Mfg, ⟨e'.comp ((Substructure.inclusion ?_).comp e.equivRange.toEmbedding)⟩⟩ rw [← hs, closure_le] intro x hx refine ⟨f (out x).1 i (hi (out x).1 (Finset.mem_image_of_mem _ hx)) (out x).2, ?_⟩ rw [Embedding.coe_toHom, DirectLimit.of_apply, @Quotient.mk_eq_iff_out _ (_), DirectLimit.equiv_iff G f _ (hi (out x).1 (Finset.mem_image_of_mem _ hx)), DirectedSystem.map_self] rfl · rintro ⟨i, Mfg, ⟨e⟩⟩ exact ⟨Mfg, ⟨Embedding.comp (DirectLimit.of L ι G f i) e⟩⟩ #align first_order.language.age_direct_limit FirstOrder.Language.age_directLimit /-- Sufficient conditions for a class to be the age of a countably-generated structure. -/
Mathlib/ModelTheory/Fraisse.lean
212
246
theorem exists_cg_is_age_of (hn : K.Nonempty) (h : ∀ M N : Bundled.{w} L.Structure, Nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) (hc : (Quotient.mk' '' K).Countable) (fg : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) (hp : Hereditary K) (jep : JointEmbedding K) : ∃ M : Bundled.{w} L.Structure, Structure.CG L M ∧ L.age M = K := by
obtain ⟨F, hF⟩ := hc.exists_eq_range (hn.image _) simp only [Set.ext_iff, Quotient.forall, mem_image, mem_range, Quotient.eq'] at hF simp_rw [Quotient.eq_mk_iff_out] at hF have hF' : ∀ n : ℕ, (F n).out ∈ K := by intro n obtain ⟨P, hP1, hP2⟩ := (hF (F n).out).2 ⟨n, Setoid.refl _⟩ -- Porting note: fix hP2 because `Quotient.out (Quotient.mk' x) ≈ a` was not simplified -- to `x ≈ a` in hF replace hP2 := Setoid.trans (Setoid.symm (Quotient.mk_out P)) hP2 exact (h _ _ hP2).1 hP1 choose P hPK hP hFP using fun (N : K) (n : ℕ) => jep N N.2 (F (n + 1)).out (hF' _) let G : ℕ → K := @Nat.rec (fun _ => K) ⟨(F 0).out, hF' 0⟩ fun n N => ⟨P N n, hPK N n⟩ -- Poting note: was -- let f : ∀ i j, i ≤ j → G i ↪[L] G j := DirectedSystem.natLeRec fun n => (hP _ n).some let f : ∀ (i j : ℕ), i ≤ j → (G i).val ↪[L] (G j).val := by refine DirectedSystem.natLERec (G' := fun i => (G i).val) (L := L) ?_ dsimp only [G] exact fun n => (hP _ n).some have : DirectedSystem (fun n ↦ (G n).val) fun i j h ↦ ↑(f i j h) := by dsimp [f, G]; infer_instance refine ⟨Bundled.of (@DirectLimit L _ _ (fun n ↦ (G n).val) _ f _ _), ?_, ?_⟩ · exact DirectLimit.cg _ (fun n => (fg _ (G n).2).cg) · refine (age_directLimit (fun n ↦ (G n).val) f).trans (subset_antisymm (iUnion_subset fun n N hN => hp (G n).val (G n).2 hN) fun N KN => ?_) have : Quotient.out (Quotient.mk' N) ≈ N := Quotient.eq_mk_iff_out.mp rfl obtain ⟨n, ⟨e⟩⟩ := (hF N).1 ⟨N, KN, this⟩ refine mem_iUnion_of_mem n ⟨fg _ KN, ⟨Embedding.comp ?_ e.symm.toEmbedding⟩⟩ cases' n with n · dsimp [G]; exact Embedding.refl _ _ · dsimp [G]; exact (hFP _ n).some
/- 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
Mathlib/MeasureTheory/Function/SimpleFunc.lean
270
275
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]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes, Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Data.FunLike.Basic import Mathlib.Logic.Function.Iterate #align_import algebra.hom.group from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64" /-! # Monoid and group homomorphisms This file defines the bundled structures for monoid and group homomorphisms. Namely, we define `MonoidHom` (resp., `AddMonoidHom`) to be bundled homomorphisms between multiplicative (resp., additive) monoids or groups. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. This file also defines the lesser-used (and notation-less) homomorphism types which are used as building blocks for other homomorphisms: * `ZeroHom` * `OneHom` * `AddHom` * `MulHom` ## Notations * `→+`: Bundled `AddMonoid` homs. Also use for `AddGroup` homs. * `→*`: Bundled `Monoid` homs. Also use for `Group` homs. * `→ₙ*`: Bundled `Semigroup` homs. ## Implementation notes There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. There is no `GroupHom` -- the idea is that `MonoidHom` is used. The constructor for `MonoidHom` needs a proof of `map_one` as well as `map_mul`; a separate constructor `MonoidHom.mk'` will construct group homs (i.e. monoid homs between groups) given only a proof that multiplication is preserved, Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `MonoidHom`. When they can be inferred from the type it is faster to use this method than to use type class inference. Historically this file also included definitions of unbundled homomorphism classes; they were deprecated and moved to `Deprecated/Group`. ## Tags MonoidHom, AddMonoidHom -/ variable {ι α β M N P : Type*} -- monoids variable {G : Type*} {H : Type*} -- groups variable {F : Type*} -- homs section Zero /-- `ZeroHom M N` is the type of functions `M → N` that preserve zero. When possible, instead of parametrizing results over `(f : ZeroHom M N)`, you should parametrize over `(F : Type*) [ZeroHomClass F M N] (f : F)`. When you extend this structure, make sure to also extend `ZeroHomClass`. -/ structure ZeroHom (M : Type*) (N : Type*) [Zero M] [Zero N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves 0 -/ protected map_zero' : toFun 0 = 0 #align zero_hom ZeroHom #align zero_hom.map_zero' ZeroHom.map_zero' /-- `ZeroHomClass F M N` states that `F` is a type of zero-preserving homomorphisms. You should extend this typeclass when you extend `ZeroHom`. -/ class ZeroHomClass (F : Type*) (M N : outParam Type*) [Zero M] [Zero N] [FunLike F M N] : Prop where /-- The proposition that the function preserves 0 -/ map_zero : ∀ f : F, f 0 = 0 #align zero_hom_class ZeroHomClass #align zero_hom_class.map_zero ZeroHomClass.map_zero -- Instances and lemmas are defined below through `@[to_additive]`. end Zero section Add /-- `AddHom M N` is the type of functions `M → N` that preserve addition. When possible, instead of parametrizing results over `(f : AddHom M N)`, you should parametrize over `(F : Type*) [AddHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `AddHomClass`. -/ structure AddHom (M : Type*) (N : Type*) [Add M] [Add N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves addition -/ protected map_add' : ∀ x y, toFun (x + y) = toFun x + toFun y #align add_hom AddHom /-- `AddHomClass F M N` states that `F` is a type of addition-preserving homomorphisms. You should declare an instance of this typeclass when you extend `AddHom`. -/ class AddHomClass (F : Type*) (M N : outParam Type*) [Add M] [Add N] [FunLike F M N] : Prop where /-- The proposition that the function preserves addition -/ map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y #align add_hom_class AddHomClass -- Instances and lemmas are defined below through `@[to_additive]`. end Add section add_zero /-- `M →+ N` is the type of functions `M → N` that preserve the `AddZeroClass` structure. `AddMonoidHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [AddMonoidHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `AddMonoidHomClass`. -/ structure AddMonoidHom (M : Type*) (N : Type*) [AddZeroClass M] [AddZeroClass N] extends ZeroHom M N, AddHom M N #align add_monoid_hom AddMonoidHom attribute [nolint docBlame] AddMonoidHom.toAddHom attribute [nolint docBlame] AddMonoidHom.toZeroHom /-- `M →+ N` denotes the type of additive monoid homomorphisms from `M` to `N`. -/ infixr:25 " →+ " => AddMonoidHom /-- `AddMonoidHomClass F M N` states that `F` is a type of `AddZeroClass`-preserving homomorphisms. You should also extend this typeclass when you extend `AddMonoidHom`. -/ class AddMonoidHomClass (F M N : Type*) [AddZeroClass M] [AddZeroClass N] [FunLike F M N] extends AddHomClass F M N, ZeroHomClass F M N : Prop #align add_monoid_hom_class AddMonoidHomClass -- Instances and lemmas are defined below through `@[to_additive]`. end add_zero section One variable [One M] [One N] /-- `OneHom M N` is the type of functions `M → N` that preserve one. When possible, instead of parametrizing results over `(f : OneHom M N)`, you should parametrize over `(F : Type*) [OneHomClass F M N] (f : F)`. When you extend this structure, make sure to also extend `OneHomClass`. -/ @[to_additive] structure OneHom (M : Type*) (N : Type*) [One M] [One N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves 1 -/ protected map_one' : toFun 1 = 1 #align one_hom OneHom /-- `OneHomClass F M N` states that `F` is a type of one-preserving homomorphisms. You should extend this typeclass when you extend `OneHom`. -/ @[to_additive] class OneHomClass (F : Type*) (M N : outParam Type*) [One M] [One N] [FunLike F M N] : Prop where /-- The proposition that the function preserves 1 -/ map_one : ∀ f : F, f 1 = 1 #align one_hom_class OneHomClass @[to_additive] instance OneHom.funLike : FunLike (OneHom M N) M N where coe := OneHom.toFun coe_injective' f g h := by cases f; cases g; congr @[to_additive] instance OneHom.oneHomClass : OneHomClass (OneHom M N) M N where map_one := OneHom.map_one' #align one_hom.one_hom_class OneHom.oneHomClass #align zero_hom.zero_hom_class ZeroHom.zeroHomClass variable [FunLike F M N] @[to_additive (attr := simp)] theorem map_one [OneHomClass F M N] (f : F) : f 1 = 1 := OneHomClass.map_one f #align map_one map_one #align map_zero map_zero @[to_additive] lemma map_comp_one [OneHomClass F M N] (f : F) : f ∘ (1 : ι → M) = 1 := by simp /-- In principle this could be an instance, but in practice it causes performance issues. -/ @[to_additive] theorem Subsingleton.of_oneHomClass [Subsingleton M] [OneHomClass F M N] : Subsingleton F where allEq f g := DFunLike.ext _ _ fun x ↦ by simp [Subsingleton.elim x 1] @[to_additive] instance [Subsingleton M] : Subsingleton (OneHom M N) := .of_oneHomClass @[to_additive] theorem map_eq_one_iff [OneHomClass F M N] (f : F) (hf : Function.Injective f) {x : M} : f x = 1 ↔ x = 1 := hf.eq_iff' (map_one f) #align map_eq_one_iff map_eq_one_iff #align map_eq_zero_iff map_eq_zero_iff @[to_additive] theorem map_ne_one_iff {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] (f : F) (hf : Function.Injective f) {x : R} : f x ≠ 1 ↔ x ≠ 1 := (map_eq_one_iff f hf).not #align map_ne_one_iff map_ne_one_iff #align map_ne_zero_iff map_ne_zero_iff @[to_additive] theorem ne_one_of_map {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] {f : F} {x : R} (hx : f x ≠ 1) : x ≠ 1 := ne_of_apply_ne f <| (by rwa [(map_one f)]) #align ne_one_of_map ne_one_of_map #align ne_zero_of_map ne_zero_of_map /-- Turn an element of a type `F` satisfying `OneHomClass F M N` into an actual `OneHom`. This is declared as the default coercion from `F` to `OneHom M N`. -/ @[to_additive (attr := coe) "Turn an element of a type `F` satisfying `ZeroHomClass F M N` into an actual `ZeroHom`. This is declared as the default coercion from `F` to `ZeroHom M N`."] def OneHomClass.toOneHom [OneHomClass F M N] (f : F) : OneHom M N where toFun := f map_one' := map_one f /-- Any type satisfying `OneHomClass` can be cast into `OneHom` via `OneHomClass.toOneHom`. -/ @[to_additive "Any type satisfying `ZeroHomClass` can be cast into `ZeroHom` via `ZeroHomClass.toZeroHom`. "] instance [OneHomClass F M N] : CoeTC F (OneHom M N) := ⟨OneHomClass.toOneHom⟩ @[to_additive (attr := simp)] theorem OneHom.coe_coe [OneHomClass F M N] (f : F) : ((f : OneHom M N) : M → N) = f := rfl #align one_hom.coe_coe OneHom.coe_coe #align zero_hom.coe_coe ZeroHom.coe_coe end One section Mul variable [Mul M] [Mul N] /-- `M →ₙ* N` is the type of functions `M → N` that preserve multiplication. The `ₙ` in the notation stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and `NonUnitalRingHom`, so a `MulHom` is a non-unital monoid hom. When possible, instead of parametrizing results over `(f : M →ₙ* N)`, you should parametrize over `(F : Type*) [MulHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `MulHomClass`. -/ @[to_additive] structure MulHom (M : Type*) (N : Type*) [Mul M] [Mul N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves multiplication -/ protected map_mul' : ∀ x y, toFun (x * y) = toFun x * toFun y #align mul_hom MulHom /-- `M →ₙ* N` denotes the type of multiplication-preserving maps from `M` to `N`. -/ infixr:25 " →ₙ* " => MulHom /-- `MulHomClass F M N` states that `F` is a type of multiplication-preserving homomorphisms. You should declare an instance of this typeclass when you extend `MulHom`. -/ @[to_additive] class MulHomClass (F : Type*) (M N : outParam Type*) [Mul M] [Mul N] [FunLike F M N] : Prop where /-- The proposition that the function preserves multiplication -/ map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y #align mul_hom_class MulHomClass @[to_additive] instance MulHom.funLike : FunLike (M →ₙ* N) M N where coe := MulHom.toFun coe_injective' f g h := by cases f; cases g; congr /-- `MulHom` is a type of multiplication-preserving homomorphisms -/ @[to_additive "`AddHom` is a type of addition-preserving homomorphisms"] instance MulHom.mulHomClass : MulHomClass (M →ₙ* N) M N where map_mul := MulHom.map_mul' #align mul_hom.mul_hom_class MulHom.mulHomClass #align add_hom.add_hom_class AddHom.addHomClass variable [FunLike F M N] @[to_additive (attr := simp)] theorem map_mul [MulHomClass F M N] (f : F) (x y : M) : f (x * y) = f x * f y := MulHomClass.map_mul f x y #align map_mul map_mul #align map_add map_add @[to_additive (attr := simp)] lemma map_comp_mul [MulHomClass F M N] (f : F) (g h : ι → M) : f ∘ (g * h) = f ∘ g * f ∘ h := by ext; simp /-- Turn an element of a type `F` satisfying `MulHomClass F M N` into an actual `MulHom`. This is declared as the default coercion from `F` to `M →ₙ* N`. -/ @[to_additive (attr := coe) "Turn an element of a type `F` satisfying `AddHomClass F M N` into an actual `AddHom`. This is declared as the default coercion from `F` to `M →ₙ+ N`."] def MulHomClass.toMulHom [MulHomClass F M N] (f : F) : M →ₙ* N where toFun := f map_mul' := map_mul f /-- Any type satisfying `MulHomClass` can be cast into `MulHom` via `MulHomClass.toMulHom`. -/ @[to_additive "Any type satisfying `AddHomClass` can be cast into `AddHom` via `AddHomClass.toAddHom`."] instance [MulHomClass F M N] : CoeTC F (M →ₙ* N) := ⟨MulHomClass.toMulHom⟩ @[to_additive (attr := simp)] theorem MulHom.coe_coe [MulHomClass F M N] (f : F) : ((f : MulHom M N) : M → N) = f := rfl #align mul_hom.coe_coe MulHom.coe_coe #align add_hom.coe_coe AddHom.coe_coe end Mul section mul_one variable [MulOneClass M] [MulOneClass N] /-- `M →* N` is the type of functions `M → N` that preserve the `Monoid` structure. `MonoidHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [MonoidHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `MonoidHomClass`. -/ @[to_additive] structure MonoidHom (M : Type*) (N : Type*) [MulOneClass M] [MulOneClass N] extends OneHom M N, M →ₙ* N #align monoid_hom MonoidHom -- Porting note: remove once `to_additive` is updated -- This is waiting on https://github.com/leanprover-community/mathlib4/issues/660 attribute [to_additive existing] MonoidHom.toMulHom attribute [nolint docBlame] MonoidHom.toMulHom attribute [nolint docBlame] MonoidHom.toOneHom /-- `M →* N` denotes the type of monoid homomorphisms from `M` to `N`. -/ infixr:25 " →* " => MonoidHom /-- `MonoidHomClass F M N` states that `F` is a type of `Monoid`-preserving homomorphisms. You should also extend this typeclass when you extend `MonoidHom`. -/ @[to_additive] class MonoidHomClass (F : Type*) (M N : outParam Type*) [MulOneClass M] [MulOneClass N] [FunLike F M N] extends MulHomClass F M N, OneHomClass F M N : Prop #align monoid_hom_class MonoidHomClass @[to_additive] instance MonoidHom.instFunLike : FunLike (M →* N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h @[to_additive] instance MonoidHom.instMonoidHomClass : MonoidHomClass (M →* N) M N where map_mul := MonoidHom.map_mul' map_one f := f.toOneHom.map_one' #align monoid_hom.monoid_hom_class MonoidHom.instMonoidHomClass #align add_monoid_hom.add_monoid_hom_class AddMonoidHom.instAddMonoidHomClass @[to_additive] instance [Subsingleton M] : Subsingleton (M →* N) := .of_oneHomClass variable [FunLike F M N] /-- Turn an element of a type `F` satisfying `MonoidHomClass F M N` into an actual `MonoidHom`. This is declared as the default coercion from `F` to `M →* N`. -/ @[to_additive (attr := coe) "Turn an element of a type `F` satisfying `AddMonoidHomClass F M N` into an actual `MonoidHom`. This is declared as the default coercion from `F` to `M →+ N`."] def MonoidHomClass.toMonoidHom [MonoidHomClass F M N] (f : F) : M →* N := { (f : M →ₙ* N), (f : OneHom M N) with } /-- Any type satisfying `MonoidHomClass` can be cast into `MonoidHom` via `MonoidHomClass.toMonoidHom`. -/ @[to_additive "Any type satisfying `AddMonoidHomClass` can be cast into `AddMonoidHom` via `AddMonoidHomClass.toAddMonoidHom`."] instance [MonoidHomClass F M N] : CoeTC F (M →* N) := ⟨MonoidHomClass.toMonoidHom⟩ @[to_additive (attr := simp)] theorem MonoidHom.coe_coe [MonoidHomClass F M N] (f : F) : ((f : M →* N) : M → N) = f := rfl #align monoid_hom.coe_coe MonoidHom.coe_coe #align add_monoid_hom.coe_coe AddMonoidHom.coe_coe @[to_additive]
Mathlib/Algebra/Group/Hom/Defs.lean
416
418
theorem map_mul_eq_one [MonoidHomClass F M N] (f : F) {a b : M} (h : a * b = 1) : f a * f b = 1 := by
rw [← map_mul, h, map_one]
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap import Mathlib.MeasureTheory.Covering.BesicovitchVectorSpace import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.MeasureTheory.Constructions.Polish import Mathlib.Analysis.Calculus.InverseFunctionTheorem.ApproximatesLinearOn #align_import measure_theory.function.jacobian from "leanprover-community/mathlib"@"b84aee748341da06a6d78491367e2c0e9f15e8a5" /-! # Change of variables in higher-dimensional integrals Let `μ` be a Lebesgue measure on a finite-dimensional real vector space `E`. Let `f : E → E` be a function which is injective and differentiable on a measurable set `s`, with derivative `f'`. Then we prove that `f '' s` is measurable, and its measure is given by the formula `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ` (where `(f' x).det` is almost everywhere measurable, but not Borel-measurable in general). This formula is proved in `lintegral_abs_det_fderiv_eq_addHaar_image`. We deduce the change of variables formula for the Lebesgue and Bochner integrals, in `lintegral_image_eq_lintegral_abs_det_fderiv_mul` and `integral_image_eq_integral_abs_det_fderiv_smul` respectively. ## Main results * `addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero`: if `f` is differentiable on a set `s` with zero measure, then `f '' s` also has zero measure. * `addHaar_image_eq_zero_of_det_fderivWithin_eq_zero`: if `f` is differentiable on a set `s`, and its derivative is never invertible, then `f '' s` has zero measure (a version of Sard's lemma). * `aemeasurable_fderivWithin`: if `f` is differentiable on a measurable set `s`, then `f'` is almost everywhere measurable on `s`. For the next statements, `s` is a measurable set and `f` is differentiable on `s` (with a derivative `f'`) and injective on `s`. * `measurable_image_of_fderivWithin`: the image `f '' s` is measurable. * `measurableEmbedding_of_fderivWithin`: the function `s.restrict f` is a measurable embedding. * `lintegral_abs_det_fderiv_eq_addHaar_image`: the image measure is given by `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ`. * `lintegral_image_eq_lintegral_abs_det_fderiv_mul`: for `g : E → ℝ≥0∞`, one has `∫⁻ x in f '' s, g x ∂μ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| * g (f x) ∂μ`. * `integral_image_eq_integral_abs_det_fderiv_smul`: for `g : E → F`, one has `∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ`. * `integrableOn_image_iff_integrableOn_abs_det_fderiv_smul`: for `g : E → F`, the function `g` is integrable on `f '' s` if and only if `|(f' x).det| • g (f x))` is integrable on `s`. ## Implementation Typical versions of these results in the literature have much stronger assumptions: `s` would typically be open, and the derivative `f' x` would depend continuously on `x` and be invertible everywhere, to have the local inverse theorem at our disposal. The proof strategy under our weaker assumptions is more involved. We follow [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2]. The first remark is that, if `f` is sufficiently well approximated by a linear map `A` on a set `s`, then `f` expands the volume of `s` by at least `A.det - ε` and at most `A.det + ε`, where the closeness condition depends on `A` in a non-explicit way (see `addHaar_image_le_mul_of_det_lt` and `mul_le_addHaar_image_of_lt_det`). This fact holds for balls by a simple inclusion argument, and follows for general sets using the Besicovitch covering theorem to cover the set by balls with measures adding up essentially to `μ s`. When `f` is differentiable on `s`, one may partition `s` into countably many subsets `s ∩ t n` (where `t n` is measurable), on each of which `f` is well approximated by a linear map, so that the above results apply. See `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, which follows from the pointwise differentiability (in a non-completely trivial way, as one should ensure a form of uniformity on the sets of the partition). Combining the above two results would give the conclusion, except for two difficulties: it is not obvious why `f '' s` and `f'` should be measurable, which prevents us from using countable additivity for the measure and the integral. It turns out that `f '' s` is indeed measurable, and that `f'` is almost everywhere measurable, which is enough to recover countable additivity. The measurability of `f '' s` follows from the deep Lusin-Souslin theorem ensuring that, in a Polish space, a continuous injective image of a measurable set is measurable. The key point to check the almost everywhere measurability of `f'` is that, if `f` is approximated up to `δ` by a linear map on a set `s`, then `f'` is within `δ` of `A` on a full measure subset of `s` (namely, its density points). With the above approximation argument, it follows that `f'` is the almost everywhere limit of a sequence of measurable functions (which are constant on the pieces of the good discretization), and is therefore almost everywhere measurable. ## Tags Change of variables in integrals ## References [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2] -/ open MeasureTheory MeasureTheory.Measure Metric Filter Set FiniteDimensional Asymptotics TopologicalSpace open scoped NNReal ENNReal Topology Pointwise variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {s : Set E} {f : E → E} {f' : E → E →L[ℝ] E} /-! ### Decomposition lemmas We state lemmas ensuring that a differentiable function can be approximated, on countably many measurable pieces, by linear maps (with a prescribed precision depending on the linear map). -/ /-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may cover `s` with countably many closed sets `t n` on which `f` is well approximated by linear maps `A n`. -/ theorem exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F] (f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F), (∀ n, IsClosed (t n)) ∧ (s ⊆ ⋃ n, t n) ∧ (∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by /- Choose countably many linear maps `f' z`. For every such map, if `f` has a derivative at `x` close enough to `f' z`, then `f y - f x` is well approximated by `f' z (y - x)` for `y` close enough to `x`, say on a ball of radius `r` (or even `u n` for some `n`, where `u` is a fixed sequence tending to `0`). Let `M n z` be the points where this happens. Then this set is relatively closed inside `s`, and moreover in every closed ball of radius `u n / 3` inside it the map is well approximated by `f' z`. Using countably many closed balls to split `M n z` into small diameter subsets `K n z p`, one obtains the desired sets `t q` after reindexing. -/ -- exclude the trivial case where `s` is empty rcases eq_empty_or_nonempty s with (rfl | hs) · refine ⟨fun _ => ∅, fun _ => 0, ?_, ?_, ?_, ?_⟩ <;> simp -- we will use countably many linear maps. Select these from all the derivatives since the -- space of linear maps is second-countable obtain ⟨T, T_count, hT⟩ : ∃ T : Set s, T.Countable ∧ ⋃ x ∈ T, ball (f' (x : E)) (r (f' x)) = ⋃ x : s, ball (f' x) (r (f' x)) := TopologicalSpace.isOpen_iUnion_countable _ fun x => isOpen_ball -- fix a sequence `u` of positive reals tending to zero. obtain ⟨u, _, u_pos, u_lim⟩ : ∃ u : ℕ → ℝ, StrictAnti u ∧ (∀ n : ℕ, 0 < u n) ∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) -- `M n z` is the set of points `x` such that `f y - f x` is close to `f' z (y - x)` for `y` -- in the ball of radius `u n` around `x`. let M : ℕ → T → Set E := fun n z => {x | x ∈ s ∧ ∀ y ∈ s ∩ ball x (u n), ‖f y - f x - f' z (y - x)‖ ≤ r (f' z) * ‖y - x‖} -- As `f` is differentiable everywhere on `s`, the sets `M n z` cover `s` by design. have s_subset : ∀ x ∈ s, ∃ (n : ℕ) (z : T), x ∈ M n z := by intro x xs obtain ⟨z, zT, hz⟩ : ∃ z ∈ T, f' x ∈ ball (f' (z : E)) (r (f' z)) := by have : f' x ∈ ⋃ z ∈ T, ball (f' (z : E)) (r (f' z)) := by rw [hT] refine mem_iUnion.2 ⟨⟨x, xs⟩, ?_⟩ simpa only [mem_ball, Subtype.coe_mk, dist_self] using (rpos (f' x)).bot_lt rwa [mem_iUnion₂, bex_def] at this obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ ‖f' x - f' z‖ + ε ≤ r (f' z) := by refine ⟨r (f' z) - ‖f' x - f' z‖, ?_, le_of_eq (by abel)⟩ simpa only [sub_pos] using mem_ball_iff_norm.mp hz obtain ⟨δ, δpos, hδ⟩ : ∃ (δ : ℝ), 0 < δ ∧ ball x δ ∩ s ⊆ {y | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} := Metric.mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos) obtain ⟨n, hn⟩ : ∃ n, u n < δ := ((tendsto_order.1 u_lim).2 _ δpos).exists refine ⟨n, ⟨z, zT⟩, ⟨xs, ?_⟩⟩ intro y hy calc ‖f y - f x - (f' z) (y - x)‖ = ‖f y - f x - (f' x) (y - x) + (f' x - f' z) (y - x)‖ := by congr 1 simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply] abel _ ≤ ‖f y - f x - (f' x) (y - x)‖ + ‖(f' x - f' z) (y - x)‖ := norm_add_le _ _ _ ≤ ε * ‖y - x‖ + ‖f' x - f' z‖ * ‖y - x‖ := by refine add_le_add (hδ ?_) (ContinuousLinearMap.le_opNorm _ _) rw [inter_comm] exact inter_subset_inter_right _ (ball_subset_ball hn.le) hy _ ≤ r (f' z) * ‖y - x‖ := by rw [← add_mul, add_comm] gcongr -- the sets `M n z` are relatively closed in `s`, as all the conditions defining it are clearly -- closed have closure_M_subset : ∀ n z, s ∩ closure (M n z) ⊆ M n z := by rintro n z x ⟨xs, hx⟩ refine ⟨xs, fun y hy => ?_⟩ obtain ⟨a, aM, a_lim⟩ : ∃ a : ℕ → E, (∀ k, a k ∈ M n z) ∧ Tendsto a atTop (𝓝 x) := mem_closure_iff_seq_limit.1 hx have L1 : Tendsto (fun k : ℕ => ‖f y - f (a k) - (f' z) (y - a k)‖) atTop (𝓝 ‖f y - f x - (f' z) (y - x)‖) := by apply Tendsto.norm have L : Tendsto (fun k => f (a k)) atTop (𝓝 (f x)) := by apply (hf' x xs).continuousWithinAt.tendsto.comp apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ a_lim exact eventually_of_forall fun k => (aM k).1 apply Tendsto.sub (tendsto_const_nhds.sub L) exact ((f' z).continuous.tendsto _).comp (tendsto_const_nhds.sub a_lim) have L2 : Tendsto (fun k : ℕ => (r (f' z) : ℝ) * ‖y - a k‖) atTop (𝓝 (r (f' z) * ‖y - x‖)) := (tendsto_const_nhds.sub a_lim).norm.const_mul _ have I : ∀ᶠ k in atTop, ‖f y - f (a k) - (f' z) (y - a k)‖ ≤ r (f' z) * ‖y - a k‖ := by have L : Tendsto (fun k => dist y (a k)) atTop (𝓝 (dist y x)) := tendsto_const_nhds.dist a_lim filter_upwards [(tendsto_order.1 L).2 _ hy.2] intro k hk exact (aM k).2 y ⟨hy.1, hk⟩ exact le_of_tendsto_of_tendsto L1 L2 I -- choose a dense sequence `d p` rcases TopologicalSpace.exists_dense_seq E with ⟨d, hd⟩ -- split `M n z` into subsets `K n z p` of small diameters by intersecting with the ball -- `closedBall (d p) (u n / 3)`. let K : ℕ → T → ℕ → Set E := fun n z p => closure (M n z) ∩ closedBall (d p) (u n / 3) -- on the sets `K n z p`, the map `f` is well approximated by `f' z` by design. have K_approx : ∀ (n) (z : T) (p), ApproximatesLinearOn f (f' z) (s ∩ K n z p) (r (f' z)) := by intro n z p x hx y hy have yM : y ∈ M n z := closure_M_subset _ _ ⟨hy.1, hy.2.1⟩ refine yM.2 _ ⟨hx.1, ?_⟩ calc dist x y ≤ dist x (d p) + dist y (d p) := dist_triangle_right _ _ _ _ ≤ u n / 3 + u n / 3 := add_le_add hx.2.2 hy.2.2 _ < u n := by linarith [u_pos n] -- the sets `K n z p` are also closed, again by design. have K_closed : ∀ (n) (z : T) (p), IsClosed (K n z p) := fun n z p => isClosed_closure.inter isClosed_ball -- reindex the sets `K n z p`, to let them only depend on an integer parameter `q`. obtain ⟨F, hF⟩ : ∃ F : ℕ → ℕ × T × ℕ, Function.Surjective F := by haveI : Encodable T := T_count.toEncodable have : Nonempty T := by rcases hs with ⟨x, xs⟩ rcases s_subset x xs with ⟨n, z, _⟩ exact ⟨z⟩ inhabit ↥T exact ⟨_, Encodable.surjective_decode_iget (ℕ × T × ℕ)⟩ -- these sets `t q = K n z p` will do refine ⟨fun q => K (F q).1 (F q).2.1 (F q).2.2, fun q => f' (F q).2.1, fun n => K_closed _ _ _, fun x xs => ?_, fun q => K_approx _ _ _, fun _ q => ⟨(F q).2.1, (F q).2.1.1.2, rfl⟩⟩ -- the only fact that needs further checking is that they cover `s`. -- we already know that any point `x ∈ s` belongs to a set `M n z`. obtain ⟨n, z, hnz⟩ : ∃ (n : ℕ) (z : T), x ∈ M n z := s_subset x xs -- by density, it also belongs to a ball `closedBall (d p) (u n / 3)`. obtain ⟨p, hp⟩ : ∃ p : ℕ, x ∈ closedBall (d p) (u n / 3) := by have : Set.Nonempty (ball x (u n / 3)) := by simp only [nonempty_ball]; linarith [u_pos n] obtain ⟨p, hp⟩ : ∃ p : ℕ, d p ∈ ball x (u n / 3) := hd.exists_mem_open isOpen_ball this exact ⟨p, (mem_ball'.1 hp).le⟩ -- choose `q` for which `t q = K n z p`. obtain ⟨q, hq⟩ : ∃ q, F q = (n, z, p) := hF _ -- then `x` belongs to `t q`. apply mem_iUnion.2 ⟨q, _⟩ simp (config := { zeta := false }) only [K, hq, mem_inter_iff, hp, and_true] exact subset_closure hnz #align exists_closed_cover_approximates_linear_on_of_has_fderiv_within_at exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt variable [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] /-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may partition `s` into countably many disjoint relatively measurable sets (i.e., intersections of `s` with measurable sets `t n`) on which `f` is well approximated by linear maps `A n`. -/ theorem exists_partition_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F] (f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F), Pairwise (Disjoint on t) ∧ (∀ n, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n, t n) ∧ (∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by rcases exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' r rpos with ⟨t, A, t_closed, st, t_approx, ht⟩ refine ⟨disjointed t, A, disjoint_disjointed _, MeasurableSet.disjointed fun n => (t_closed n).measurableSet, ?_, ?_, ht⟩ · rw [iUnion_disjointed]; exact st · intro n; exact (t_approx n).mono_set (inter_subset_inter_right _ (disjointed_subset _ _)) #align exists_partition_approximates_linear_on_of_has_fderiv_within_at exists_partition_approximatesLinearOn_of_hasFDerivWithinAt namespace MeasureTheory /-! ### Local lemmas We check that a function which is well enough approximated by a linear map expands the volume essentially like this linear map, and that its derivative (if it exists) is almost everywhere close to the approximating linear map. -/ /-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear map `A`. Then it expands the volume of any set by at most `m` for any `m > det A`. -/ theorem addHaar_image_le_mul_of_det_lt (A : E →L[ℝ] E) {m : ℝ≥0} (hm : ENNReal.ofReal |A.det| < m) : ∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → μ (f '' s) ≤ m * μ s := by apply nhdsWithin_le_nhds let d := ENNReal.ofReal |A.det| -- construct a small neighborhood of `A '' (closedBall 0 1)` with measure comparable to -- the determinant of `A`. obtain ⟨ε, hε, εpos⟩ : ∃ ε : ℝ, μ (closedBall 0 ε + A '' closedBall 0 1) < m * μ (closedBall 0 1) ∧ 0 < ε := by have HC : IsCompact (A '' closedBall 0 1) := (ProperSpace.isCompact_closedBall _ _).image A.continuous have L0 : Tendsto (fun ε => μ (cthickening ε (A '' closedBall 0 1))) (𝓝[>] 0) (𝓝 (μ (A '' closedBall 0 1))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds exact tendsto_measure_cthickening_of_isCompact HC have L1 : Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0) (𝓝 (μ (A '' closedBall 0 1))) := by apply L0.congr' _ filter_upwards [self_mem_nhdsWithin] with r hr rw [← HC.add_closedBall_zero (le_of_lt hr), add_comm] have L2 : Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0) (𝓝 (d * μ (closedBall 0 1))) := by convert L1 exact (addHaar_image_continuousLinearMap _ _ _).symm have I : d * μ (closedBall 0 1) < m * μ (closedBall 0 1) := (ENNReal.mul_lt_mul_right (measure_closedBall_pos μ _ zero_lt_one).ne' measure_closedBall_lt_top.ne).2 hm have H : ∀ᶠ b : ℝ in 𝓝[>] 0, μ (closedBall 0 b + A '' closedBall 0 1) < m * μ (closedBall 0 1) := (tendsto_order.1 L2).2 _ I exact (H.and self_mem_nhdsWithin).exists have : Iio (⟨ε, εpos.le⟩ : ℝ≥0) ∈ 𝓝 (0 : ℝ≥0) := by apply Iio_mem_nhds; exact εpos filter_upwards [this] -- fix a function `f` which is close enough to `A`. intro δ hδ s f hf simp only [mem_Iio, ← NNReal.coe_lt_coe, NNReal.coe_mk] at hδ -- This function expands the volume of any ball by at most `m` have I : ∀ x r, x ∈ s → 0 ≤ r → μ (f '' (s ∩ closedBall x r)) ≤ m * μ (closedBall x r) := by intro x r xs r0 have K : f '' (s ∩ closedBall x r) ⊆ A '' closedBall 0 r + closedBall (f x) (ε * r) := by rintro y ⟨z, ⟨zs, zr⟩, rfl⟩ rw [mem_closedBall_iff_norm] at zr apply Set.mem_add.2 ⟨A (z - x), _, f z - f x - A (z - x) + f x, _, _⟩ · apply mem_image_of_mem simpa only [dist_eq_norm, mem_closedBall, mem_closedBall_zero_iff, sub_zero] using zr · rw [mem_closedBall_iff_norm, add_sub_cancel_right] calc ‖f z - f x - A (z - x)‖ ≤ δ * ‖z - x‖ := hf _ zs _ xs _ ≤ ε * r := by gcongr · simp only [map_sub, Pi.sub_apply] abel have : A '' closedBall 0 r + closedBall (f x) (ε * r) = {f x} + r • (A '' closedBall 0 1 + closedBall 0 ε) := by rw [smul_add, ← add_assoc, add_comm {f x}, add_assoc, smul_closedBall _ _ εpos.le, smul_zero, singleton_add_closedBall_zero, ← image_smul_set ℝ E E A, smul_closedBall _ _ zero_le_one, smul_zero, Real.norm_eq_abs, abs_of_nonneg r0, mul_one, mul_comm] rw [this] at K calc μ (f '' (s ∩ closedBall x r)) ≤ μ ({f x} + r • (A '' closedBall 0 1 + closedBall 0 ε)) := measure_mono K _ = ENNReal.ofReal (r ^ finrank ℝ E) * μ (A '' closedBall 0 1 + closedBall 0 ε) := by simp only [abs_of_nonneg r0, addHaar_smul, image_add_left, abs_pow, singleton_add, measure_preimage_add] _ ≤ ENNReal.ofReal (r ^ finrank ℝ E) * (m * μ (closedBall 0 1)) := by rw [add_comm]; gcongr _ = m * μ (closedBall x r) := by simp only [addHaar_closedBall' μ _ r0]; ring -- covering `s` by closed balls with total measure very close to `μ s`, one deduces that the -- measure of `f '' s` is at most `m * (μ s + a)` for any positive `a`. have J : ∀ᶠ a in 𝓝[>] (0 : ℝ≥0∞), μ (f '' s) ≤ m * (μ s + a) := by filter_upwards [self_mem_nhdsWithin] with a ha rw [mem_Ioi] at ha obtain ⟨t, r, t_count, ts, rpos, st, μt⟩ : ∃ (t : Set E) (r : E → ℝ), t.Countable ∧ t ⊆ s ∧ (∀ x : E, x ∈ t → 0 < r x) ∧ (s ⊆ ⋃ x ∈ t, closedBall x (r x)) ∧ (∑' x : ↥t, μ (closedBall (↑x) (r ↑x))) ≤ μ s + a := Besicovitch.exists_closedBall_covering_tsum_measure_le μ ha.ne' (fun _ => Ioi 0) s fun x _ δ δpos => ⟨δ / 2, by simp [half_pos δpos, δpos]⟩ haveI : Encodable t := t_count.toEncodable calc μ (f '' s) ≤ μ (⋃ x : t, f '' (s ∩ closedBall x (r x))) := by rw [biUnion_eq_iUnion] at st apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact image_subset _ (subset_inter (Subset.refl _) st) _ ≤ ∑' x : t, μ (f '' (s ∩ closedBall x (r x))) := measure_iUnion_le _ _ ≤ ∑' x : t, m * μ (closedBall x (r x)) := (ENNReal.tsum_le_tsum fun x => I x (r x) (ts x.2) (rpos x x.2).le) _ ≤ m * (μ s + a) := by rw [ENNReal.tsum_mul_left]; gcongr -- taking the limit in `a`, one obtains the conclusion have L : Tendsto (fun a => (m : ℝ≥0∞) * (μ s + a)) (𝓝[>] 0) (𝓝 (m * (μ s + 0))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds apply ENNReal.Tendsto.const_mul (tendsto_const_nhds.add tendsto_id) simp only [ENNReal.coe_ne_top, Ne, or_true_iff, not_false_iff] rw [add_zero] at L exact ge_of_tendsto L J #align measure_theory.add_haar_image_le_mul_of_det_lt MeasureTheory.addHaar_image_le_mul_of_det_lt /-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear map `A`. Then it expands the volume of any set by at least `m` for any `m < det A`. -/ theorem mul_le_addHaar_image_of_lt_det (A : E →L[ℝ] E) {m : ℝ≥0} (hm : (m : ℝ≥0∞) < ENNReal.ofReal |A.det|) : ∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → (m : ℝ≥0∞) * μ s ≤ μ (f '' s) := by apply nhdsWithin_le_nhds -- The assumption `hm` implies that `A` is invertible. If `f` is close enough to `A`, it is also -- invertible. One can then pass to the inverses, and deduce the estimate from -- `addHaar_image_le_mul_of_det_lt` applied to `f⁻¹` and `A⁻¹`. -- exclude first the trivial case where `m = 0`. rcases eq_or_lt_of_le (zero_le m) with (rfl | mpos) · filter_upwards simp only [forall_const, zero_mul, imp_true_iff, zero_le, ENNReal.coe_zero] have hA : A.det ≠ 0 := by intro h; simp only [h, ENNReal.not_lt_zero, ENNReal.ofReal_zero, abs_zero] at hm -- let `B` be the continuous linear equiv version of `A`. let B := A.toContinuousLinearEquivOfDetNeZero hA -- the determinant of `B.symm` is bounded by `m⁻¹` have I : ENNReal.ofReal |(B.symm : E →L[ℝ] E).det| < (m⁻¹ : ℝ≥0) := by simp only [ENNReal.ofReal, abs_inv, Real.toNNReal_inv, ContinuousLinearEquiv.det_coe_symm, ContinuousLinearMap.coe_toContinuousLinearEquivOfDetNeZero, ENNReal.coe_lt_coe] at hm ⊢ exact NNReal.inv_lt_inv mpos.ne' hm -- therefore, we may apply `addHaar_image_le_mul_of_det_lt` to `B.symm` and `m⁻¹`. obtain ⟨δ₀, δ₀pos, hδ₀⟩ : ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t := by have : ∀ᶠ δ : ℝ≥0 in 𝓝[>] 0, ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t := addHaar_image_le_mul_of_det_lt μ B.symm I rcases (this.and self_mem_nhdsWithin).exists with ⟨δ₀, h, h'⟩ exact ⟨δ₀, h', h⟩ -- record smallness conditions for `δ` that will be needed to apply `hδ₀` below. have L1 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), Subsingleton E ∨ δ < ‖(B.symm : E →L[ℝ] E)‖₊⁻¹ := by by_cases h : Subsingleton E · simp only [h, true_or_iff, eventually_const] simp only [h, false_or_iff] apply Iio_mem_nhds simpa only [h, false_or_iff, inv_pos] using B.subsingleton_or_nnnorm_symm_pos have L2 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ < δ₀ := by have : Tendsto (fun δ => ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ) (𝓝 0) (𝓝 (‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - 0)⁻¹ * 0)) := by rcases eq_or_ne ‖(B.symm : E →L[ℝ] E)‖₊ 0 with (H | H) · simpa only [H, zero_mul] using tendsto_const_nhds refine Tendsto.mul (tendsto_const_nhds.mul ?_) tendsto_id refine (Tendsto.sub tendsto_const_nhds tendsto_id).inv₀ ?_ simpa only [tsub_zero, inv_eq_zero, Ne] using H simp only [mul_zero] at this exact (tendsto_order.1 this).2 δ₀ δ₀pos -- let `δ` be small enough, and `f` approximated by `B` up to `δ`. filter_upwards [L1, L2] intro δ h1δ h2δ s f hf have hf' : ApproximatesLinearOn f (B : E →L[ℝ] E) s δ := by convert hf let F := hf'.toPartialEquiv h1δ -- the condition to be checked can be reformulated in terms of the inverse maps suffices H : μ (F.symm '' F.target) ≤ (m⁻¹ : ℝ≥0) * μ F.target by change (m : ℝ≥0∞) * μ F.source ≤ μ F.target rwa [← F.symm_image_target_eq_source, mul_comm, ← ENNReal.le_div_iff_mul_le, div_eq_mul_inv, mul_comm, ← ENNReal.coe_inv mpos.ne'] · apply Or.inl simpa only [ENNReal.coe_eq_zero, Ne] using mpos.ne' · simp only [ENNReal.coe_ne_top, true_or_iff, Ne, not_false_iff] -- as `f⁻¹` is well approximated by `B⁻¹`, the conclusion follows from `hδ₀` -- and our choice of `δ`. exact hδ₀ _ _ ((hf'.to_inv h1δ).mono_num h2δ.le) #align measure_theory.mul_le_add_haar_image_of_lt_det MeasureTheory.mul_le_addHaar_image_of_lt_det /-- If a differentiable function `f` is approximated by a linear map `A` on a set `s`, up to `δ`, then at almost every `x` in `s` one has `‖f' x - A‖ ≤ δ`. -/ theorem _root_.ApproximatesLinearOn.norm_fderiv_sub_le {A : E →L[ℝ] E} {δ : ℝ≥0} (hf : ApproximatesLinearOn f A s δ) (hs : MeasurableSet s) (f' : E → E →L[ℝ] E) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : ∀ᵐ x ∂μ.restrict s, ‖f' x - A‖₊ ≤ δ := by /- The conclusion will hold at the Lebesgue density points of `s` (which have full measure). At such a point `x`, for any `z` and any `ε > 0` one has for small `r` that `{x} + r • closedBall z ε` intersects `s`. At a point `y` in the intersection, `f y - f x` is close both to `f' x (r z)` (by differentiability) and to `A (r z)` (by linear approximation), so these two quantities are close, i.e., `(f' x - A) z` is small. -/ filter_upwards [Besicovitch.ae_tendsto_measure_inter_div μ s, ae_restrict_mem hs] -- start from a Lebesgue density point `x`, belonging to `s`. intro x hx xs -- consider an arbitrary vector `z`. apply ContinuousLinearMap.opNorm_le_bound _ δ.2 fun z => ?_ -- to show that `‖(f' x - A) z‖ ≤ δ ‖z‖`, it suffices to do it up to some error that vanishes -- asymptotically in terms of `ε > 0`. suffices H : ∀ ε, 0 < ε → ‖(f' x - A) z‖ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε by have : Tendsto (fun ε : ℝ => ((δ : ℝ) + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε) (𝓝[>] 0) (𝓝 ((δ + 0) * (‖z‖ + 0) + ‖f' x - A‖ * 0)) := Tendsto.mono_left (Continuous.tendsto (by continuity) 0) nhdsWithin_le_nhds simp only [add_zero, mul_zero] at this apply le_of_tendsto_of_tendsto tendsto_const_nhds this filter_upwards [self_mem_nhdsWithin] exact H -- fix a positive `ε`. intro ε εpos -- for small enough `r`, the rescaled ball `r • closedBall z ε` intersects `s`, as `x` is a -- density point have B₁ : ∀ᶠ r in 𝓝[>] (0 : ℝ), (s ∩ ({x} + r • closedBall z ε)).Nonempty := eventually_nonempty_inter_smul_of_density_one μ s x hx _ measurableSet_closedBall (measure_closedBall_pos μ z εpos).ne' obtain ⟨ρ, ρpos, hρ⟩ : ∃ ρ > 0, ball x ρ ∩ s ⊆ {y : E | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} := mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos) -- for small enough `r`, the rescaled ball `r • closedBall z ε` is included in the set where -- `f y - f x` is well approximated by `f' x (y - x)`. have B₂ : ∀ᶠ r in 𝓝[>] (0 : ℝ), {x} + r • closedBall z ε ⊆ ball x ρ := by apply nhdsWithin_le_nhds exact eventually_singleton_add_smul_subset isBounded_closedBall (ball_mem_nhds x ρpos) -- fix a small positive `r` satisfying the above properties, as well as a corresponding `y`. obtain ⟨r, ⟨y, ⟨ys, hy⟩⟩, rρ, rpos⟩ : ∃ r : ℝ, (s ∩ ({x} + r • closedBall z ε)).Nonempty ∧ {x} + r • closedBall z ε ⊆ ball x ρ ∧ 0 < r := (B₁.and (B₂.and self_mem_nhdsWithin)).exists -- write `y = x + r a` with `a ∈ closedBall z ε`. obtain ⟨a, az, ya⟩ : ∃ a, a ∈ closedBall z ε ∧ y = x + r • a := by simp only [mem_smul_set, image_add_left, mem_preimage, singleton_add] at hy rcases hy with ⟨a, az, ha⟩ exact ⟨a, az, by simp only [ha, add_neg_cancel_left]⟩ have norm_a : ‖a‖ ≤ ‖z‖ + ε := calc ‖a‖ = ‖z + (a - z)‖ := by simp only [add_sub_cancel] _ ≤ ‖z‖ + ‖a - z‖ := norm_add_le _ _ _ ≤ ‖z‖ + ε := add_le_add_left (mem_closedBall_iff_norm.1 az) _ -- use the approximation properties to control `(f' x - A) a`, and then `(f' x - A) z` as `z` is -- close to `a`. have I : r * ‖(f' x - A) a‖ ≤ r * (δ + ε) * (‖z‖ + ε) := calc r * ‖(f' x - A) a‖ = ‖(f' x - A) (r • a)‖ := by simp only [ContinuousLinearMap.map_smul, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le] _ = ‖f y - f x - A (y - x) - (f y - f x - (f' x) (y - x))‖ := by congr 1 simp only [ya, add_sub_cancel_left, sub_sub_sub_cancel_left, ContinuousLinearMap.coe_sub', eq_self_iff_true, sub_left_inj, Pi.sub_apply, ContinuousLinearMap.map_smul, smul_sub] _ ≤ ‖f y - f x - A (y - x)‖ + ‖f y - f x - (f' x) (y - x)‖ := norm_sub_le _ _ _ ≤ δ * ‖y - x‖ + ε * ‖y - x‖ := (add_le_add (hf _ ys _ xs) (hρ ⟨rρ hy, ys⟩)) _ = r * (δ + ε) * ‖a‖ := by simp only [ya, add_sub_cancel_left, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le] ring _ ≤ r * (δ + ε) * (‖z‖ + ε) := by gcongr calc ‖(f' x - A) z‖ = ‖(f' x - A) a + (f' x - A) (z - a)‖ := by congr 1 simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply] abel _ ≤ ‖(f' x - A) a‖ + ‖(f' x - A) (z - a)‖ := norm_add_le _ _ _ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ‖z - a‖ := by apply add_le_add · rw [mul_assoc] at I; exact (mul_le_mul_left rpos).1 I · apply ContinuousLinearMap.le_opNorm _ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε := by rw [mem_closedBall_iff_norm'] at az gcongr #align approximates_linear_on.norm_fderiv_sub_le ApproximatesLinearOn.norm_fderiv_sub_le /-! ### Measure zero of the image, over non-measurable sets If a set has measure `0`, then its image under a differentiable map has measure zero. This doesn't require the set to be measurable. In the same way, if `f` is differentiable on a set `s` with non-invertible derivative everywhere, then `f '' s` has measure `0`, again without measurability assumptions. -/ /-- A differentiable function maps sets of measure zero to sets of measure zero. -/ theorem addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero (hf : DifferentiableOn ℝ f s) (hs : μ s = 0) : μ (f '' s) = 0 := by refine le_antisymm ?_ (zero_le _) have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E), ApproximatesLinearOn f A t δ → μ (f '' t) ≤ (Real.toNNReal |A.det| + 1 : ℝ≥0) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + 1 have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, zero_lt_one, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩ exact ⟨δ, h', fun t ht => h t f ht⟩ choose δ hδ using this obtain ⟨t, A, _, _, t_cover, ht, -⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = fderivWithin ℝ f s y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s (fderivWithin ℝ f s) (fun x xs => (hf x xs).hasFDerivWithinAt) δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact image_subset f (subset_inter Subset.rfl t_cover) _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (Real.toNNReal |(A n).det| + 1 : ℝ≥0) * μ (s ∩ t n) := by apply ENNReal.tsum_le_tsum fun n => ?_ apply (hδ (A n)).2 exact ht n _ ≤ ∑' n, ((Real.toNNReal |(A n).det| + 1 : ℝ≥0) : ℝ≥0∞) * 0 := by refine ENNReal.tsum_le_tsum fun n => mul_le_mul_left' ?_ _ exact le_trans (measure_mono inter_subset_left) (le_of_eq hs) _ = 0 := by simp only [tsum_zero, mul_zero] #align measure_theory.add_haar_image_eq_zero_of_differentiable_on_of_add_haar_eq_zero MeasureTheory.addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero /-- A version of **Sard's lemma** in fixed dimension: given a differentiable function from `E` to `E` and a set where the differential is not invertible, then the image of this set has zero measure. Here, we give an auxiliary statement towards this result. -/ theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (R : ℝ) (hs : s ⊆ closedBall 0 R) (ε : ℝ≥0) (εpos : 0 < ε) (h'f' : ∀ x ∈ s, (f' x).det = 0) : μ (f '' s) ≤ ε * μ (closedBall 0 R) := by rcases eq_empty_or_nonempty s with (rfl | h's); · simp only [measure_empty, zero_le, image_empty] have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ ∀ (t : Set E), ApproximatesLinearOn f A t δ → μ (f '' t) ≤ (Real.toNNReal |A.det| + ε : ℝ≥0) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + ε have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, εpos, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩ exact ⟨δ, h', fun t ht => h t f ht⟩ choose δ hδ using this obtain ⟨t, A, t_disj, t_meas, t_cover, ht, Af'⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by rw [← image_iUnion, ← inter_iUnion] gcongr exact subset_inter Subset.rfl t_cover _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (Real.toNNReal |(A n).det| + ε : ℝ≥0) * μ (s ∩ t n) := by gcongr exact (hδ (A _)).2 _ (ht _) _ = ∑' n, ε * μ (s ∩ t n) := by congr with n rcases Af' h's n with ⟨y, ys, hy⟩ simp only [hy, h'f' y ys, Real.toNNReal_zero, abs_zero, zero_add] _ ≤ ε * ∑' n, μ (closedBall 0 R ∩ t n) := by rw [ENNReal.tsum_mul_left] gcongr _ = ε * μ (⋃ n, closedBall 0 R ∩ t n) := by rw [measure_iUnion] · exact pairwise_disjoint_mono t_disj fun n => inter_subset_right · intro n exact measurableSet_closedBall.inter (t_meas n) _ ≤ ε * μ (closedBall 0 R) := by rw [← inter_iUnion] exact mul_le_mul_left' (measure_mono inter_subset_left) _ #align measure_theory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux MeasureTheory.addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux /-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and a set where the differential is not invertible, then the image of this set has zero measure. -/ theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (h'f' : ∀ x ∈ s, (f' x).det = 0) : μ (f '' s) = 0 := by suffices H : ∀ R, μ (f '' (s ∩ closedBall 0 R)) = 0 by apply le_antisymm _ (zero_le _) rw [← iUnion_inter_closedBall_nat s 0] calc μ (f '' ⋃ n : ℕ, s ∩ closedBall 0 n) ≤ ∑' n : ℕ, μ (f '' (s ∩ closedBall 0 n)) := by rw [image_iUnion]; exact measure_iUnion_le _ _ ≤ 0 := by simp only [H, tsum_zero, nonpos_iff_eq_zero] intro R have A : ∀ (ε : ℝ≥0), 0 < ε → μ (f '' (s ∩ closedBall 0 R)) ≤ ε * μ (closedBall 0 R) := fun ε εpos => addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux μ (fun x hx => (hf' x hx.1).mono inter_subset_left) R inter_subset_right ε εpos fun x hx => h'f' x hx.1 have B : Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝[>] 0) (𝓝 0) := by have : Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝 0) (𝓝 (((0 : ℝ≥0) : ℝ≥0∞) * μ (closedBall 0 R))) := ENNReal.Tendsto.mul_const (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr measure_closedBall_lt_top.ne) simp only [zero_mul, ENNReal.coe_zero] at this exact Tendsto.mono_left this nhdsWithin_le_nhds apply le_antisymm _ (zero_le _) apply ge_of_tendsto B filter_upwards [self_mem_nhdsWithin] exact A #align measure_theory.add_haar_image_eq_zero_of_det_fderiv_within_eq_zero MeasureTheory.addHaar_image_eq_zero_of_det_fderivWithin_eq_zero /-! ### Weak measurability statements We show that the derivative of a function on a set is almost everywhere measurable, and that the image `f '' s` is measurable if `f` is injective on `s`. The latter statement follows from the Lusin-Souslin theorem. -/ /-- The derivative of a function on a measurable set is almost everywhere measurable on this set with respect to Lebesgue measure. Note that, in general, it is not genuinely measurable there, as `f'` is not unique (but only on a set of measure `0`, as the argument shows). -/ theorem aemeasurable_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable f' (μ.restrict s) := by /- It suffices to show that `f'` can be uniformly approximated by a measurable function. Fix `ε > 0`. Thanks to `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, one can find a countable measurable partition of `s` into sets `s ∩ t n` on which `f` is well approximated by linear maps `A n`. On almost all of `s ∩ t n`, it follows from `ApproximatesLinearOn.norm_fderiv_sub_le` that `f'` is uniformly approximated by `A n`, which gives the conclusion. -/ -- fix a precision `ε` refine aemeasurable_of_unif_approx fun ε εpos => ?_ let δ : ℝ≥0 := ⟨ε, le_of_lt εpos⟩ have δpos : 0 < δ := εpos -- partition `s` into sets `s ∩ t n` on which `f` is approximated by linear maps `A n`. obtain ⟨t, A, t_disj, t_meas, t_cover, ht, _⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) δ) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' (fun _ => δ) fun _ => δpos.ne' -- define a measurable function `g` which coincides with `A n` on `t n`. obtain ⟨g, g_meas, hg⟩ : ∃ g : E → E →L[ℝ] E, Measurable g ∧ ∀ (n : ℕ) (x : E), x ∈ t n → g x = A n := exists_measurable_piecewise t t_meas (fun n _ => A n) (fun n => measurable_const) <| t_disj.mono fun i j h => by simp only [h.inter_eq, eqOn_empty] refine ⟨g, g_meas.aemeasurable, ?_⟩ -- reduce to checking that `f'` and `g` are close on almost all of `s ∩ t n`, for all `n`. suffices H : ∀ᵐ x : E ∂sum fun n ↦ μ.restrict (s ∩ t n), dist (g x) (f' x) ≤ ε by have : μ.restrict s ≤ sum fun n => μ.restrict (s ∩ t n) := by have : s = ⋃ n, s ∩ t n := by rw [← inter_iUnion] exact Subset.antisymm (subset_inter Subset.rfl t_cover) inter_subset_left conv_lhs => rw [this] exact restrict_iUnion_le exact ae_mono this H -- fix such an `n`. refine ae_sum_iff.2 fun n => ?_ -- on almost all `s ∩ t n`, `f' x` is close to `A n` thanks to -- `ApproximatesLinearOn.norm_fderiv_sub_le`. have E₁ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), ‖f' x - A n‖₊ ≤ δ := (ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx => (hf' x hx.1).mono inter_subset_left -- moreover, `g x` is equal to `A n` there. have E₂ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), g x = A n := by suffices H : ∀ᵐ x : E ∂μ.restrict (t n), g x = A n from ae_mono (restrict_mono inter_subset_right le_rfl) H filter_upwards [ae_restrict_mem (t_meas n)] exact hg n -- putting these two properties together gives the conclusion. filter_upwards [E₁, E₂] with x hx1 hx2 rw [← nndist_eq_nnnorm] at hx1 rw [hx2, dist_comm] exact hx1 #align measure_theory.ae_measurable_fderiv_within MeasureTheory.aemeasurable_fderivWithin theorem aemeasurable_ofReal_abs_det_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable (fun x => ENNReal.ofReal |(f' x).det|) (μ.restrict s) := by apply ENNReal.measurable_ofReal.comp_aemeasurable refine continuous_abs.measurable.comp_aemeasurable ?_ refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_ exact aemeasurable_fderivWithin μ hs hf' #align measure_theory.ae_measurable_of_real_abs_det_fderiv_within MeasureTheory.aemeasurable_ofReal_abs_det_fderivWithin theorem aemeasurable_toNNReal_abs_det_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable (fun x => |(f' x).det|.toNNReal) (μ.restrict s) := by apply measurable_real_toNNReal.comp_aemeasurable refine continuous_abs.measurable.comp_aemeasurable ?_ refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_ exact aemeasurable_fderivWithin μ hs hf' #align measure_theory.ae_measurable_to_nnreal_abs_det_fderiv_within MeasureTheory.aemeasurable_toNNReal_abs_det_fderivWithin /-- If a function is differentiable and injective on a measurable set, then the image is measurable. -/ theorem measurable_image_of_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : MeasurableSet (f '' s) := haveI : DifferentiableOn ℝ f s := fun x hx => (hf' x hx).differentiableWithinAt hs.image_of_continuousOn_injOn (DifferentiableOn.continuousOn this) hf #align measure_theory.measurable_image_of_fderiv_within MeasureTheory.measurable_image_of_fderivWithin /-- If a function is differentiable and injective on a measurable set `s`, then its restriction to `s` is a measurable embedding. -/ theorem measurableEmbedding_of_fderivWithin (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : MeasurableEmbedding (s.restrict f) := haveI : DifferentiableOn ℝ f s := fun x hx => (hf' x hx).differentiableWithinAt this.continuousOn.measurableEmbedding hs hf #align measure_theory.measurable_embedding_of_fderiv_within MeasureTheory.measurableEmbedding_of_fderivWithin /-! ### Proving the estimate for the measure of the image We show the formula `∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ = μ (f '' s)`, in `lintegral_abs_det_fderiv_eq_addHaar_image`. For this, we show both inequalities in both directions, first up to controlled errors and then letting these errors tend to `0`. -/ theorem addHaar_image_le_lintegral_abs_det_fderiv_aux1 (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) {ε : ℝ≥0} (εpos : 0 < ε) : μ (f '' s) ≤ (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * ε * μ s := by /- To bound `μ (f '' s)`, we cover `s` by sets where `f` is well-approximated by linear maps `A n` (and where `f'` is almost everywhere close to `A n`), and then use that `f` expands the measure of such a set by at most `(A n).det + ε`. -/ have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ (∀ B : E →L[ℝ] E, ‖B - A‖ ≤ δ → |B.det - A.det| ≤ ε) ∧ ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g A t δ → μ (g '' t) ≤ (ENNReal.ofReal |A.det| + ε) * μ t := by intro A let m : ℝ≥0 := Real.toNNReal |A.det| + ε have I : ENNReal.ofReal |A.det| < m := by simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, εpos, ENNReal.coe_lt_coe] rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, δpos⟩ obtain ⟨δ', δ'pos, hδ'⟩ : ∃ (δ' : ℝ), 0 < δ' ∧ ∀ B, dist B A < δ' → dist B.det A.det < ↑ε := continuousAt_iff.1 ContinuousLinearMap.continuous_det.continuousAt ε εpos let δ'' : ℝ≥0 := ⟨δ' / 2, (half_pos δ'pos).le⟩ refine ⟨min δ δ'', lt_min δpos (half_pos δ'pos), ?_, ?_⟩ · intro B hB rw [← Real.dist_eq] apply (hδ' B _).le rw [dist_eq_norm] calc ‖B - A‖ ≤ (min δ δ'' : ℝ≥0) := hB _ ≤ δ'' := by simp only [le_refl, NNReal.coe_min, min_le_iff, or_true_iff] _ < δ' := half_lt_self δ'pos · intro t g htg exact h t g (htg.mono_num (min_le_left _ _)) choose δ hδ using this obtain ⟨t, A, t_disj, t_meas, t_cover, ht, -⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne' calc μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by apply measure_mono rw [← image_iUnion, ← inter_iUnion] exact image_subset f (subset_inter Subset.rfl t_cover) _ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _ _ ≤ ∑' n, (ENNReal.ofReal |(A n).det| + ε) * μ (s ∩ t n) := by apply ENNReal.tsum_le_tsum fun n => ?_ apply (hδ (A n)).2.2 exact ht n _ = ∑' n, ∫⁻ _ in s ∩ t n, ENNReal.ofReal |(A n).det| + ε ∂μ := by simp only [lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter] _ ≤ ∑' n, ∫⁻ x in s ∩ t n, ENNReal.ofReal |(f' x).det| + 2 * ε ∂μ := by apply ENNReal.tsum_le_tsum fun n => ?_ apply lintegral_mono_ae filter_upwards [(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx => (hf' x hx.1).mono inter_subset_left] intro x hx have I : |(A n).det| ≤ |(f' x).det| + ε := calc |(A n).det| = |(f' x).det - ((f' x).det - (A n).det)| := by congr 1; abel _ ≤ |(f' x).det| + |(f' x).det - (A n).det| := abs_sub _ _ _ ≤ |(f' x).det| + ε := add_le_add le_rfl ((hδ (A n)).2.1 _ hx) calc ENNReal.ofReal |(A n).det| + ε ≤ ENNReal.ofReal (|(f' x).det| + ε) + ε := by gcongr _ = ENNReal.ofReal |(f' x).det| + 2 * ε := by simp only [ENNReal.ofReal_add, abs_nonneg, two_mul, add_assoc, NNReal.zero_le_coe, ENNReal.ofReal_coe_nnreal] _ = ∫⁻ x in ⋃ n, s ∩ t n, ENNReal.ofReal |(f' x).det| + 2 * ε ∂μ := by have M : ∀ n : ℕ, MeasurableSet (s ∩ t n) := fun n => hs.inter (t_meas n) rw [lintegral_iUnion M] exact pairwise_disjoint_mono t_disj fun n => inter_subset_right _ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| + 2 * ε ∂μ := by rw [← inter_iUnion, inter_eq_self_of_subset_left t_cover] _ = (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * ε * μ s := by simp only [lintegral_add_right' _ aemeasurable_const, set_lintegral_const] #align measure_theory.add_haar_image_le_lintegral_abs_det_fderiv_aux1 MeasureTheory.addHaar_image_le_lintegral_abs_det_fderiv_aux1 theorem addHaar_image_le_lintegral_abs_det_fderiv_aux2 (hs : MeasurableSet s) (h's : μ s ≠ ∞) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : μ (f '' s) ≤ ∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ := by -- We just need to let the error tend to `0` in the previous lemma. have : Tendsto (fun ε : ℝ≥0 => (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * ε * μ s) (𝓝[>] 0) (𝓝 ((∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) + 2 * (0 : ℝ≥0) * μ s)) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds refine tendsto_const_nhds.add ?_ refine ENNReal.Tendsto.mul_const ?_ (Or.inr h's) exact ENNReal.Tendsto.const_mul (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr ENNReal.coe_ne_top) simp only [add_zero, zero_mul, mul_zero, ENNReal.coe_zero] at this apply ge_of_tendsto this filter_upwards [self_mem_nhdsWithin] intro ε εpos rw [mem_Ioi] at εpos exact addHaar_image_le_lintegral_abs_det_fderiv_aux1 μ hs hf' εpos #align measure_theory.add_haar_image_le_lintegral_abs_det_fderiv_aux2 MeasureTheory.addHaar_image_le_lintegral_abs_det_fderiv_aux2 theorem addHaar_image_le_lintegral_abs_det_fderiv (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : μ (f '' s) ≤ ∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ := by /- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using `spanningSets μ`, and apply the previous result to each of these parts. -/ let u n := disjointed (spanningSets μ) n have u_meas : ∀ n, MeasurableSet (u n) := by intro n apply MeasurableSet.disjointed fun i => ?_ exact measurable_spanningSets μ i have A : s = ⋃ n, s ∩ u n := by rw [← inter_iUnion, iUnion_disjointed, iUnion_spanningSets, inter_univ] calc μ (f '' s) ≤ ∑' n, μ (f '' (s ∩ u n)) := by conv_lhs => rw [A, image_iUnion] exact measure_iUnion_le _ _ ≤ ∑' n, ∫⁻ x in s ∩ u n, ENNReal.ofReal |(f' x).det| ∂μ := by apply ENNReal.tsum_le_tsum fun n => ?_ apply addHaar_image_le_lintegral_abs_det_fderiv_aux2 μ (hs.inter (u_meas n)) _ fun x hx => (hf' x hx.1).mono inter_subset_left have : μ (u n) < ∞ := lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanningSets_lt_top μ n) exact ne_of_lt (lt_of_le_of_lt (measure_mono inter_subset_right) this) _ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ := by conv_rhs => rw [A] rw [lintegral_iUnion] · intro n; exact hs.inter (u_meas n) · exact pairwise_disjoint_mono (disjoint_disjointed _) fun n => inter_subset_right #align measure_theory.add_haar_image_le_lintegral_abs_det_fderiv MeasureTheory.addHaar_image_le_lintegral_abs_det_fderiv theorem lintegral_abs_det_fderiv_le_addHaar_image_aux1 (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) {ε : ℝ≥0} (εpos : 0 < ε) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) ≤ μ (f '' s) + 2 * ε * μ s := by /- To bound `∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ`, we cover `s` by sets where `f` is well-approximated by linear maps `A n` (and where `f'` is almost everywhere close to `A n`), and then use that `f` expands the measure of such a set by at least `(A n).det - ε`. -/ have : ∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧ (∀ B : E →L[ℝ] E, ‖B - A‖ ≤ δ → |B.det - A.det| ≤ ε) ∧ ∀ (t : Set E) (g : E → E), ApproximatesLinearOn g A t δ → ENNReal.ofReal |A.det| * μ t ≤ μ (g '' t) + ε * μ t := by intro A obtain ⟨δ', δ'pos, hδ'⟩ : ∃ (δ' : ℝ), 0 < δ' ∧ ∀ B, dist B A < δ' → dist B.det A.det < ↑ε := continuousAt_iff.1 ContinuousLinearMap.continuous_det.continuousAt ε εpos let δ'' : ℝ≥0 := ⟨δ' / 2, (half_pos δ'pos).le⟩ have I'' : ∀ B : E →L[ℝ] E, ‖B - A‖ ≤ ↑δ'' → |B.det - A.det| ≤ ↑ε := by intro B hB rw [← Real.dist_eq] apply (hδ' B _).le rw [dist_eq_norm] exact hB.trans_lt (half_lt_self δ'pos) rcases eq_or_ne A.det 0 with (hA | hA) · refine ⟨δ'', half_pos δ'pos, I'', ?_⟩ simp only [hA, forall_const, zero_mul, ENNReal.ofReal_zero, imp_true_iff, zero_le, abs_zero] let m : ℝ≥0 := Real.toNNReal |A.det| - ε have I : (m : ℝ≥0∞) < ENNReal.ofReal |A.det| := by simp only [m, ENNReal.ofReal, ENNReal.coe_sub] apply ENNReal.sub_lt_self ENNReal.coe_ne_top · simpa only [abs_nonpos_iff, Real.toNNReal_eq_zero, ENNReal.coe_eq_zero, Ne] using hA · simp only [εpos.ne', ENNReal.coe_eq_zero, Ne, not_false_iff] rcases ((mul_le_addHaar_image_of_lt_det μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, δpos⟩ refine ⟨min δ δ'', lt_min δpos (half_pos δ'pos), ?_, ?_⟩ · intro B hB apply I'' _ (hB.trans _) simp only [le_refl, NNReal.coe_min, min_le_iff, or_true_iff] · intro t g htg rcases eq_or_ne (μ t) ∞ with (ht | ht) · simp only [ht, εpos.ne', ENNReal.mul_top, ENNReal.coe_eq_zero, le_top, Ne, not_false_iff, _root_.add_top] have := h t g (htg.mono_num (min_le_left _ _)) rwa [ENNReal.coe_sub, ENNReal.sub_mul, tsub_le_iff_right] at this simp only [ht, imp_true_iff, Ne, not_false_iff] choose δ hδ using this obtain ⟨t, A, t_disj, t_meas, t_cover, ht, -⟩ : ∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E), Pairwise (Disjoint on t) ∧ (∀ n : ℕ, MeasurableSet (t n)) ∧ (s ⊆ ⋃ n : ℕ, t n) ∧ (∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧ (s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne' have s_eq : s = ⋃ n, s ∩ t n := by rw [← inter_iUnion] exact Subset.antisymm (subset_inter Subset.rfl t_cover) inter_subset_left calc (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = ∑' n, ∫⁻ x in s ∩ t n, ENNReal.ofReal |(f' x).det| ∂μ := by conv_lhs => rw [s_eq] rw [lintegral_iUnion] · exact fun n => hs.inter (t_meas n) · exact pairwise_disjoint_mono t_disj fun n => inter_subset_right _ ≤ ∑' n, ∫⁻ _ in s ∩ t n, ENNReal.ofReal |(A n).det| + ε ∂μ := by apply ENNReal.tsum_le_tsum fun n => ?_ apply lintegral_mono_ae filter_upwards [(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx => (hf' x hx.1).mono inter_subset_left] intro x hx have I : |(f' x).det| ≤ |(A n).det| + ε := calc |(f' x).det| = |(A n).det + ((f' x).det - (A n).det)| := by congr 1; abel _ ≤ |(A n).det| + |(f' x).det - (A n).det| := abs_add _ _ _ ≤ |(A n).det| + ε := add_le_add le_rfl ((hδ (A n)).2.1 _ hx) calc ENNReal.ofReal |(f' x).det| ≤ ENNReal.ofReal (|(A n).det| + ε) := ENNReal.ofReal_le_ofReal I _ = ENNReal.ofReal |(A n).det| + ε := by simp only [ENNReal.ofReal_add, abs_nonneg, NNReal.zero_le_coe, ENNReal.ofReal_coe_nnreal] _ = ∑' n, (ENNReal.ofReal |(A n).det| * μ (s ∩ t n) + ε * μ (s ∩ t n)) := by simp only [set_lintegral_const, lintegral_add_right _ measurable_const] _ ≤ ∑' n, (μ (f '' (s ∩ t n)) + ε * μ (s ∩ t n) + ε * μ (s ∩ t n)) := by gcongr exact (hδ (A _)).2.2 _ _ (ht _) _ = μ (f '' s) + 2 * ε * μ s := by conv_rhs => rw [s_eq] rw [image_iUnion, measure_iUnion]; rotate_left · intro i j hij apply Disjoint.image _ hf inter_subset_left inter_subset_left exact Disjoint.mono inter_subset_right inter_subset_right (t_disj hij) · intro i exact measurable_image_of_fderivWithin (hs.inter (t_meas i)) (fun x hx => (hf' x hx.1).mono inter_subset_left) (hf.mono inter_subset_left) rw [measure_iUnion]; rotate_left · exact pairwise_disjoint_mono t_disj fun i => inter_subset_right · exact fun i => hs.inter (t_meas i) rw [← ENNReal.tsum_mul_left, ← ENNReal.tsum_add] congr 1 ext1 i rw [mul_assoc, two_mul, add_assoc] #align measure_theory.lintegral_abs_det_fderiv_le_add_haar_image_aux1 MeasureTheory.lintegral_abs_det_fderiv_le_addHaar_image_aux1 theorem lintegral_abs_det_fderiv_le_addHaar_image_aux2 (hs : MeasurableSet s) (h's : μ s ≠ ∞) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) ≤ μ (f '' s) := by -- We just need to let the error tend to `0` in the previous lemma. have : Tendsto (fun ε : ℝ≥0 => μ (f '' s) + 2 * ε * μ s) (𝓝[>] 0) (𝓝 (μ (f '' s) + 2 * (0 : ℝ≥0) * μ s)) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds refine tendsto_const_nhds.add ?_ refine ENNReal.Tendsto.mul_const ?_ (Or.inr h's) exact ENNReal.Tendsto.const_mul (ENNReal.tendsto_coe.2 tendsto_id) (Or.inr ENNReal.coe_ne_top) simp only [add_zero, zero_mul, mul_zero, ENNReal.coe_zero] at this apply ge_of_tendsto this filter_upwards [self_mem_nhdsWithin] intro ε εpos rw [mem_Ioi] at εpos exact lintegral_abs_det_fderiv_le_addHaar_image_aux1 μ hs hf' hf εpos #align measure_theory.lintegral_abs_det_fderiv_le_add_haar_image_aux2 MeasureTheory.lintegral_abs_det_fderiv_le_addHaar_image_aux2 theorem lintegral_abs_det_fderiv_le_addHaar_image (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) ≤ μ (f '' s) := by /- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using `spanningSets μ`, and apply the previous result to each of these parts. -/ let u n := disjointed (spanningSets μ) n have u_meas : ∀ n, MeasurableSet (u n) := by intro n apply MeasurableSet.disjointed fun i => ?_ exact measurable_spanningSets μ i have A : s = ⋃ n, s ∩ u n := by rw [← inter_iUnion, iUnion_disjointed, iUnion_spanningSets, inter_univ] calc (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = ∑' n, ∫⁻ x in s ∩ u n, ENNReal.ofReal |(f' x).det| ∂μ := by conv_lhs => rw [A] rw [lintegral_iUnion] · intro n; exact hs.inter (u_meas n) · exact pairwise_disjoint_mono (disjoint_disjointed _) fun n => inter_subset_right _ ≤ ∑' n, μ (f '' (s ∩ u n)) := by apply ENNReal.tsum_le_tsum fun n => ?_ apply lintegral_abs_det_fderiv_le_addHaar_image_aux2 μ (hs.inter (u_meas n)) _ (fun x hx => (hf' x hx.1).mono inter_subset_left) (hf.mono inter_subset_left) have : μ (u n) < ∞ := lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanningSets_lt_top μ n) exact ne_of_lt (lt_of_le_of_lt (measure_mono inter_subset_right) this) _ = μ (f '' s) := by conv_rhs => rw [A, image_iUnion] rw [measure_iUnion] · intro i j hij apply Disjoint.image _ hf inter_subset_left inter_subset_left exact Disjoint.mono inter_subset_right inter_subset_right (disjoint_disjointed _ hij) · intro i exact measurable_image_of_fderivWithin (hs.inter (u_meas i)) (fun x hx => (hf' x hx.1).mono inter_subset_left) (hf.mono inter_subset_left) #align measure_theory.lintegral_abs_det_fderiv_le_add_haar_image MeasureTheory.lintegral_abs_det_fderiv_le_addHaar_image /-- Change of variable formula for differentiable functions, set version: if a function `f` is injective and differentiable on a measurable set `s`, then the measure of `f '' s` is given by the integral of `|(f' x).det|` on `s`. Note that the measurability of `f '' s` is given by `measurable_image_of_fderivWithin`. -/ theorem lintegral_abs_det_fderiv_eq_addHaar_image (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : (∫⁻ x in s, ENNReal.ofReal |(f' x).det| ∂μ) = μ (f '' s) := le_antisymm (lintegral_abs_det_fderiv_le_addHaar_image μ hs hf' hf) (addHaar_image_le_lintegral_abs_det_fderiv μ hs hf') #align measure_theory.lintegral_abs_det_fderiv_eq_add_haar_image MeasureTheory.lintegral_abs_det_fderiv_eq_addHaar_image /-- Change of variable formula for differentiable functions, set version: if a function `f` is injective and differentiable on a measurable set `s`, then the pushforward of the measure with density `|(f' x).det|` on `s` is the Lebesgue measure on the image set. This version requires that `f` is measurable, as otherwise `Measure.map f` is zero per our definitions. For a version without measurability assumption but dealing with the restricted function `s.restrict f`, see `restrict_map_withDensity_abs_det_fderiv_eq_addHaar`. -/ theorem map_withDensity_abs_det_fderiv_eq_addHaar (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) (h'f : Measurable f) : Measure.map f ((μ.restrict s).withDensity fun x => ENNReal.ofReal |(f' x).det|) = μ.restrict (f '' s) := by apply Measure.ext fun t ht => ?_ rw [map_apply h'f ht, withDensity_apply _ (h'f ht), Measure.restrict_apply ht, restrict_restrict (h'f ht), lintegral_abs_det_fderiv_eq_addHaar_image μ ((h'f ht).inter hs) (fun x hx => (hf' x hx.2).mono inter_subset_right) (hf.mono inter_subset_right), image_preimage_inter] #align measure_theory.map_with_density_abs_det_fderiv_eq_add_haar MeasureTheory.map_withDensity_abs_det_fderiv_eq_addHaar /-- Change of variable formula for differentiable functions, set version: if a function `f` is injective and differentiable on a measurable set `s`, then the pushforward of the measure with density `|(f' x).det|` on `s` is the Lebesgue measure on the image set. This version is expressed in terms of the restricted function `s.restrict f`. For a version for the original function, but with a measurability assumption, see `map_withDensity_abs_det_fderiv_eq_addHaar`. -/
Mathlib/MeasureTheory/Function/Jacobian.lean
1,128
1,151
theorem restrict_map_withDensity_abs_det_fderiv_eq_addHaar (hs : MeasurableSet s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf : InjOn f s) : Measure.map (s.restrict f) (comap (↑) (μ.withDensity fun x => ENNReal.ofReal |(f' x).det|)) = μ.restrict (f '' s) := by
obtain ⟨u, u_meas, uf⟩ : ∃ u, Measurable u ∧ EqOn u f s := by classical refine ⟨piecewise s f 0, ?_, piecewise_eqOn _ _ _⟩ refine ContinuousOn.measurable_piecewise ?_ continuous_zero.continuousOn hs have : DifferentiableOn ℝ f s := fun x hx => (hf' x hx).differentiableWithinAt exact this.continuousOn have u' : ∀ x ∈ s, HasFDerivWithinAt u (f' x) s x := fun x hx => (hf' x hx).congr (fun y hy => uf hy) (uf hx) set F : s → E := u ∘ (↑) with hF have A : Measure.map F (comap (↑) (μ.withDensity fun x => ENNReal.ofReal |(f' x).det|)) = μ.restrict (u '' s) := by rw [hF, ← Measure.map_map u_meas measurable_subtype_coe, map_comap_subtype_coe hs, restrict_withDensity hs] exact map_withDensity_abs_det_fderiv_eq_addHaar μ hs u' (hf.congr uf.symm) u_meas rw [uf.image_eq] at A have : F = s.restrict f := by ext x exact uf x.2 rwa [this] at A
/- 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.Polynomial.Expand import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.Matrix.Charpoly.LinearMap import Mathlib.RingTheory.Adjoin.FG import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Polynomial.ScaleRoots import Mathlib.RingTheory.Polynomial.Tower import Mathlib.RingTheory.TensorProduct.Basic #align_import ring_theory.integral_closure from "leanprover-community/mathlib"@"641b6a82006416ec431b2987b354af9311fed4f2" /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. Enough theory is developed to prove that integral elements form a sub-R-algebra of A. ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `RingHom.IsIntegralElem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `IsIntegral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. * `integralClosure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`. -/ open scoped Classical open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/ def RingHom.IsIntegralElem (f : R →+* A) (x : A) := ∃ p : R[X], Monic p ∧ eval₂ f x p = 0 #align ring_hom.is_integral_elem RingHom.IsIntegralElem /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ def RingHom.IsIntegral (f : R →+* A) := ∀ x : A, f.IsIntegralElem x #align ring_hom.is_integral RingHom.IsIntegral variable [Algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : R[X]`. Equivalently, the element is integral over `R` with respect to the induced `algebraMap` -/ def IsIntegral (x : A) : Prop := (algebraMap R A).IsIntegralElem x #align is_integral IsIntegral variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring -/ protected class Algebra.IsIntegral : Prop := isIntegral : ∀ x : A, IsIntegral R x #align algebra.is_integral Algebra.IsIntegral variable {R A} lemma Algebra.isIntegral_def : Algebra.IsIntegral R A ↔ ∀ x : A, IsIntegral R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ theorem RingHom.isIntegralElem_map {x : R} : f.IsIntegralElem (f x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ #align ring_hom.is_integral_map RingHom.isIntegralElem_map theorem isIntegral_algebraMap {x : R} : IsIntegral R (algebraMap R A x) := (algebraMap R A).isIntegralElem_map #align is_integral_algebra_map isIntegral_algebraMap end Ring section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] (f : R →+* S) theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C] [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [FunLike F B C] [AlgHomClass F A B C] (f : F) (hb : IsIntegral R b) : IsIntegral R (f b) := by obtain ⟨P, hP⟩ := hb refine ⟨P, hP.1, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap A, aeval_algHom_apply, aeval_map_algebraMap, aeval_def, hP.2, _root_.map_zero] #align map_is_integral IsIntegral.map theorem IsIntegral.map_of_comp_eq {R S T U : Type*} [CommRing R] [Ring S] [CommRing T] [Ring U] [Algebra R S] [Algebra T U] (φ : R →+* T) (ψ : S →+* U) (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) {a : S} (ha : IsIntegral R a) : IsIntegral T (ψ a) := let ⟨p, hp⟩ := ha ⟨p.map φ, hp.1.map _, by rw [← eval_map, map_map, h, ← map_map, eval_map, eval₂_at_apply, eval_map, hp.2, ψ.map_zero]⟩ #align is_integral_map_of_comp_eq_of_is_integral IsIntegral.map_of_comp_eq section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] variable (f : A →ₐ[R] B) (hf : Function.Injective f) theorem isIntegral_algHom_iff {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := by refine ⟨fun ⟨p, hp, hx⟩ ↦ ⟨p, hp, ?_⟩, IsIntegral.map f⟩ rwa [← f.comp_algebraMap, ← AlgHom.coe_toRingHom, ← hom_eval₂, AlgHom.coe_toRingHom, map_eq_zero_iff f hf] at hx #align is_integral_alg_hom_iff isIntegral_algHom_iff theorem Algebra.IsIntegral.of_injective [Algebra.IsIntegral R B] : Algebra.IsIntegral R A := ⟨fun _ ↦ (isIntegral_algHom_iff f hf).mp (isIntegral _)⟩ end @[simp] theorem isIntegral_algEquiv {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] (f : A ≃ₐ[R] B) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := ⟨fun h ↦ by simpa using h.map f.symm, IsIntegral.map f⟩ #align is_integral_alg_equiv isIntegral_algEquiv /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B`. -/ theorem IsIntegral.tower_top [Algebra A B] [IsScalarTower R A B] {x : B} (hx : IsIntegral R x) : IsIntegral A x := let ⟨p, hp, hpx⟩ := hx ⟨p.map <| algebraMap R A, hp.map _, by rw [← aeval_def, aeval_map_algebraMap, aeval_def, hpx]⟩ #align is_integral_of_is_scalar_tower IsIntegral.tower_top #align is_integral_tower_top_of_is_integral IsIntegral.tower_top theorem map_isIntegral_int {B C F : Type*} [Ring B] [Ring C] {b : B} [FunLike F B C] [RingHomClass F B C] (f : F) (hb : IsIntegral ℤ b) : IsIntegral ℤ (f b) := hb.map (f : B →+* C).toIntAlgHom #align map_is_integral_int map_isIntegral_int theorem IsIntegral.of_subring {x : B} (T : Subring R) (hx : IsIntegral T x) : IsIntegral R x := hx.tower_top #align is_integral_of_subring IsIntegral.of_subring protected theorem IsIntegral.algebraMap [Algebra A B] [IsScalarTower R A B] {x : A} (h : IsIntegral R x) : IsIntegral R (algebraMap A B x) := by rcases h with ⟨f, hf, hx⟩ use f, hf rw [IsScalarTower.algebraMap_eq R A B, ← hom_eval₂, hx, RingHom.map_zero] #align is_integral.algebra_map IsIntegral.algebraMap theorem isIntegral_algebraMap_iff [Algebra A B] [IsScalarTower R A B] {x : A} (hAB : Function.Injective (algebraMap A B)) : IsIntegral R (algebraMap A B x) ↔ IsIntegral R x := isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) hAB #align is_integral_algebra_map_iff isIntegral_algebraMap_iff theorem isIntegral_iff_isIntegral_closure_finite {r : B} : IsIntegral R r ↔ ∃ s : Set R, s.Finite ∧ IsIntegral (Subring.closure s) r := by constructor <;> intro hr · rcases hr with ⟨p, hmp, hpr⟩ refine ⟨_, Finset.finite_toSet _, p.restriction, monic_restriction.2 hmp, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap R r p.restriction, map_restriction, aeval_def, hpr] rcases hr with ⟨s, _, hsr⟩ exact hsr.of_subring _ #align is_integral_iff_is_integral_closure_finite isIntegral_iff_isIntegral_closure_finite theorem Submodule.span_range_natDegree_eq_adjoin {R A} [CommRing R] [Semiring A] [Algebra R A] {x : A} {f : R[X]} (hf : f.Monic) (hfx : aeval x f = 0) : span R (Finset.image (x ^ ·) (Finset.range (natDegree f))) = Subalgebra.toSubmodule (Algebra.adjoin R {x}) := by nontriviality A have hf1 : f ≠ 1 := by rintro rfl; simp [one_ne_zero' A] at hfx refine (span_le.mpr fun s hs ↦ ?_).antisymm fun r hr ↦ ?_ · rcases Finset.mem_image.1 hs with ⟨k, -, rfl⟩ exact (Algebra.adjoin R {x}).pow_mem (Algebra.subset_adjoin rfl) k rw [Subalgebra.mem_toSubmodule, Algebra.adjoin_singleton_eq_range_aeval] at hr rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩ rw [← modByMonic_add_div p hf, map_add, map_mul, hfx, zero_mul, add_zero, ← sum_C_mul_X_pow_eq (p %ₘ f), aeval_def, eval₂_sum, sum_def] refine sum_mem fun k hkq ↦ ?_ rw [C_mul_X_pow_eq_monomial, eval₂_monomial, ← Algebra.smul_def] exact smul_mem _ _ (subset_span <| Finset.mem_image_of_mem _ <| Finset.mem_range.mpr <| (le_natDegree_of_mem_supp _ hkq).trans_lt <| natDegree_modByMonic_lt p hf hf1) theorem IsIntegral.fg_adjoin_singleton {x : B} (hx : IsIntegral R x) : (Algebra.adjoin R {x}).toSubmodule.FG := by rcases hx with ⟨f, hfm, hfx⟩ use (Finset.range <| f.natDegree).image (x ^ ·) exact span_range_natDegree_eq_adjoin hfm (by rwa [aeval_def]) theorem fg_adjoin_of_finite {s : Set A} (hfs : s.Finite) (his : ∀ x ∈ s, IsIntegral R x) : (Algebra.adjoin R s).toSubmodule.FG := Set.Finite.induction_on hfs (fun _ => ⟨{1}, Submodule.ext fun x => by rw [Algebra.adjoin_empty, Finset.coe_singleton, ← one_eq_span, Algebra.toSubmodule_bot]⟩) (fun {a s} _ _ ih his => by rw [← Set.union_singleton, Algebra.adjoin_union_coe_submodule] exact FG.mul (ih fun i hi => his i <| Set.mem_insert_of_mem a hi) (his a <| Set.mem_insert a s).fg_adjoin_singleton) his #align fg_adjoin_of_finite fg_adjoin_of_finite theorem isNoetherian_adjoin_finset [IsNoetherianRing R] (s : Finset A) (hs : ∀ x ∈ s, IsIntegral R x) : IsNoetherian R (Algebra.adjoin R (s : Set A)) := isNoetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_toSet hs) #align is_noetherian_adjoin_finset isNoetherian_adjoin_finset instance Module.End.isIntegral {M : Type*} [AddCommGroup M] [Module R M] [Module.Finite R M] : Algebra.IsIntegral R (Module.End R M) := ⟨LinearMap.exists_monic_and_aeval_eq_zero R⟩ #align module.End.is_integral Module.End.isIntegral variable (R) theorem IsIntegral.of_finite [Module.Finite R B] (x : B) : IsIntegral R x := (isIntegral_algHom_iff (Algebra.lmul R B) Algebra.lmul_injective).mp (Algebra.IsIntegral.isIntegral _) variable (B) instance Algebra.IsIntegral.of_finite [Module.Finite R B] : Algebra.IsIntegral R B := ⟨.of_finite R⟩ #align algebra.is_integral.of_finite Algebra.IsIntegral.of_finite variable {R B} /-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module, then all elements of `S` are integral over `R`. -/ theorem IsIntegral.of_mem_of_fg {A} [Ring A] [Algebra R A] (S : Subalgebra R A) (HS : S.toSubmodule.FG) (x : A) (hx : x ∈ S) : IsIntegral R x := have : Module.Finite R S := ⟨(fg_top _).mpr HS⟩ (isIntegral_algHom_iff S.val Subtype.val_injective).mpr (.of_finite R (⟨x, hx⟩ : S)) #align is_integral_of_mem_of_fg IsIntegral.of_mem_of_fg theorem isIntegral_of_noetherian (_ : IsNoetherian R B) (x : B) : IsIntegral R x := .of_finite R x #align is_integral_of_noetherian isIntegral_of_noetherian theorem isIntegral_of_submodule_noetherian (S : Subalgebra R B) (H : IsNoetherian R (Subalgebra.toSubmodule S)) (x : B) (hx : x ∈ S) : IsIntegral R x := .of_mem_of_fg _ ((fg_top _).mp <| H.noetherian _) _ hx #align is_integral_of_submodule_noetherian isIntegral_of_submodule_noetherian /-- Suppose `A` is an `R`-algebra, `M` is an `A`-module such that `a • m ≠ 0` for all non-zero `a` and `m`. If `x : A` fixes a nontrivial f.g. `R`-submodule `N` of `M`, then `x` is `R`-integral. -/ theorem isIntegral_of_smul_mem_submodule {M : Type*} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors A M] (N : Submodule R M) (hN : N ≠ ⊥) (hN' : N.FG) (x : A) (hx : ∀ n ∈ N, x • n ∈ N) : IsIntegral R x := by let A' : Subalgebra R A := { carrier := { x | ∀ n ∈ N, x • n ∈ N } mul_mem' := fun {a b} ha hb n hn => smul_smul a b n ▸ ha _ (hb _ hn) one_mem' := fun n hn => (one_smul A n).symm ▸ hn add_mem' := fun {a b} ha hb n hn => (add_smul a b n).symm ▸ N.add_mem (ha _ hn) (hb _ hn) zero_mem' := fun n _hn => (zero_smul A n).symm ▸ N.zero_mem algebraMap_mem' := fun r n hn => (algebraMap_smul A r n).symm ▸ N.smul_mem r hn } let f : A' →ₐ[R] Module.End R N := AlgHom.ofLinearMap { toFun := fun x => (DistribMulAction.toLinearMap R M x).restrict x.prop -- Porting note: was -- `fun x y => LinearMap.ext fun n => Subtype.ext <| add_smul x y n` map_add' := by intros x y; ext; exact add_smul _ _ _ -- Porting note: was -- `fun r s => LinearMap.ext fun n => Subtype.ext <| smul_assoc r s n` map_smul' := by intros r s; ext; apply smul_assoc } -- Porting note: the next two lines were --`(LinearMap.ext fun n => Subtype.ext <| one_smul _ _) fun x y =>` --`LinearMap.ext fun n => Subtype.ext <| mul_smul x y n` (by ext; apply one_smul) (by intros x y; ext; apply mul_smul) obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ N, a ≠ (0 : M) := by by_contra! h' apply hN rwa [eq_bot_iff] have : Function.Injective f := by show Function.Injective f.toLinearMap rw [← LinearMap.ker_eq_bot, eq_bot_iff] intro s hs have : s.1 • a = 0 := congr_arg Subtype.val (LinearMap.congr_fun hs ⟨a, ha₁⟩) exact Subtype.ext ((eq_zero_or_eq_zero_of_smul_eq_zero this).resolve_right ha₂) show IsIntegral R (A'.val ⟨x, hx⟩) rw [isIntegral_algHom_iff A'.val Subtype.val_injective, ← isIntegral_algHom_iff f this] haveI : Module.Finite R N := by rwa [Module.finite_def, Submodule.fg_top] apply Algebra.IsIntegral.isIntegral #align is_integral_of_smul_mem_submodule isIntegral_of_smul_mem_submodule variable {f} theorem RingHom.Finite.to_isIntegral (h : f.Finite) : f.IsIntegral := letI := f.toAlgebra fun _ ↦ IsIntegral.of_mem_of_fg ⊤ h.1 _ trivial #align ring_hom.finite.to_is_integral RingHom.Finite.to_isIntegral alias RingHom.IsIntegral.of_finite := RingHom.Finite.to_isIntegral #align ring_hom.is_integral.of_finite RingHom.IsIntegral.of_finite /-- The [Kurosh problem](https://en.wikipedia.org/wiki/Kurosh_problem) asks to show that this is still true when `A` is not necessarily commutative and `R` is a field, but it has been solved in the negative. See https://arxiv.org/pdf/1706.02383.pdf for criteria for a finitely generated algebraic (= integral) algebra over a field to be finite dimensional. This could be an `instance`, but we tend to go from `Module.Finite` to `IsIntegral`/`IsAlgebraic`, and making it an instance will cause the search to be complicated a lot. -/ theorem Algebra.IsIntegral.finite [Algebra.IsIntegral R A] [h' : Algebra.FiniteType R A] : Module.Finite R A := have ⟨s, hs⟩ := h' ⟨by apply hs ▸ fg_adjoin_of_finite s.finite_toSet fun x _ ↦ Algebra.IsIntegral.isIntegral x⟩ #align algebra.is_integral.finite Algebra.IsIntegral.finite /-- finite = integral + finite type -/ theorem Algebra.finite_iff_isIntegral_and_finiteType : Module.Finite R A ↔ Algebra.IsIntegral R A ∧ Algebra.FiniteType R A := ⟨fun _ ↦ ⟨⟨.of_finite R⟩, inferInstance⟩, fun ⟨h, _⟩ ↦ h.finite⟩ #align algebra.finite_iff_is_integral_and_finite_type Algebra.finite_iff_isIntegral_and_finiteType theorem RingHom.IsIntegral.to_finite (h : f.IsIntegral) (h' : f.FiniteType) : f.Finite := let _ := f.toAlgebra let _ : Algebra.IsIntegral R S := ⟨h⟩ Algebra.IsIntegral.finite (h' := h') #align ring_hom.is_integral.to_finite RingHom.IsIntegral.to_finite alias RingHom.Finite.of_isIntegral_of_finiteType := RingHom.IsIntegral.to_finite #align ring_hom.finite.of_is_integral_of_finite_type RingHom.Finite.of_isIntegral_of_finiteType /-- finite = integral + finite type -/ theorem RingHom.finite_iff_isIntegral_and_finiteType : f.Finite ↔ f.IsIntegral ∧ f.FiniteType := ⟨fun h ↦ ⟨h.to_isIntegral, h.to_finiteType⟩, fun ⟨h, h'⟩ ↦ h.to_finite h'⟩ #align ring_hom.finite_iff_is_integral_and_finite_type RingHom.finite_iff_isIntegral_and_finiteType variable (f) theorem RingHom.IsIntegralElem.of_mem_closure {x y z : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) (hz : z ∈ Subring.closure ({x, y} : Set S)) : f.IsIntegralElem z := by letI : Algebra R S := f.toAlgebra have := (IsIntegral.fg_adjoin_singleton hx).mul (IsIntegral.fg_adjoin_singleton hy) rw [← Algebra.adjoin_union_coe_submodule, Set.singleton_union] at this exact IsIntegral.of_mem_of_fg (Algebra.adjoin R {x, y}) this z (Algebra.mem_adjoin_iff.2 <| Subring.closure_mono Set.subset_union_right hz) #align ring_hom.is_integral_of_mem_closure RingHom.IsIntegralElem.of_mem_closure nonrec theorem IsIntegral.of_mem_closure {x y z : A} (hx : IsIntegral R x) (hy : IsIntegral R y) (hz : z ∈ Subring.closure ({x, y} : Set A)) : IsIntegral R z := hx.of_mem_closure (algebraMap R A) hy hz #align is_integral_of_mem_closure IsIntegral.of_mem_closure variable (f : R →+* B) theorem RingHom.isIntegralElem_zero : f.IsIntegralElem 0 := f.map_zero ▸ f.isIntegralElem_map #align ring_hom.is_integral_zero RingHom.isIntegralElem_zero theorem isIntegral_zero : IsIntegral R (0 : B) := (algebraMap R B).isIntegralElem_zero #align is_integral_zero isIntegral_zero theorem RingHom.isIntegralElem_one : f.IsIntegralElem 1 := f.map_one ▸ f.isIntegralElem_map #align ring_hom.is_integral_one RingHom.isIntegralElem_one theorem isIntegral_one : IsIntegral R (1 : B) := (algebraMap R B).isIntegralElem_one #align is_integral_one isIntegral_one theorem RingHom.IsIntegralElem.add (f : R →+* S) {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x + y) := hx.of_mem_closure f hy <| Subring.add_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl)) #align ring_hom.is_integral_add RingHom.IsIntegralElem.add nonrec theorem IsIntegral.add {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x + y) := hx.add (algebraMap R A) hy #align is_integral_add IsIntegral.add variable (f : R →+* S) -- can be generalized to noncommutative S. theorem RingHom.IsIntegralElem.neg {x : S} (hx : f.IsIntegralElem x) : f.IsIntegralElem (-x) := hx.of_mem_closure f hx (Subring.neg_mem _ (Subring.subset_closure (Or.inl rfl))) #align ring_hom.is_integral_neg RingHom.IsIntegralElem.neg theorem IsIntegral.neg {x : B} (hx : IsIntegral R x) : IsIntegral R (-x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ (Subalgebra.neg_mem _ <| Algebra.subset_adjoin rfl) #align is_integral_neg IsIntegral.neg theorem RingHom.IsIntegralElem.sub {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x - y) := by simpa only [sub_eq_add_neg] using hx.add f (hy.neg f) #align ring_hom.is_integral_sub RingHom.IsIntegralElem.sub nonrec theorem IsIntegral.sub {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x - y) := hx.sub (algebraMap R A) hy #align is_integral_sub IsIntegral.sub theorem RingHom.IsIntegralElem.mul {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x * y) := hx.of_mem_closure f hy (Subring.mul_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl))) #align ring_hom.is_integral_mul RingHom.IsIntegralElem.mul nonrec theorem IsIntegral.mul {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x * y) := hx.mul (algebraMap R A) hy #align is_integral_mul IsIntegral.mul theorem IsIntegral.smul {R} [CommSemiring R] [CommRing S] [Algebra R B] [Algebra S B] [Algebra R S] [IsScalarTower R S B] {x : B} (r : R)(hx : IsIntegral S x) : IsIntegral S (r • x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ <| by rw [← algebraMap_smul S]; apply Subalgebra.smul_mem; exact Algebra.subset_adjoin rfl #align is_integral_smul IsIntegral.smul theorem IsIntegral.of_pow {x : B} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : IsIntegral R x := by rcases hx with ⟨p, hmonic, heval⟩ exact ⟨expand R n p, hmonic.expand hn, by rwa [← aeval_def, expand_aeval]⟩ #align is_integral_of_pow IsIntegral.of_pow variable (R A) /-- The integral closure of R in an R-algebra A. -/ def integralClosure : Subalgebra R A where carrier := { r | IsIntegral R r } zero_mem' := isIntegral_zero one_mem' := isIntegral_one add_mem' := IsIntegral.add mul_mem' := IsIntegral.mul algebraMap_mem' _ := isIntegral_algebraMap #align integral_closure integralClosure theorem mem_integralClosure_iff_mem_fg {r : A} : r ∈ integralClosure R A ↔ ∃ M : Subalgebra R A, M.toSubmodule.FG ∧ r ∈ M := ⟨fun hr => ⟨Algebra.adjoin R {r}, hr.fg_adjoin_singleton, Algebra.subset_adjoin rfl⟩, fun ⟨M, Hf, hrM⟩ => .of_mem_of_fg M Hf _ hrM⟩ #align mem_integral_closure_iff_mem_fg mem_integralClosure_iff_mem_fg variable {R A} theorem adjoin_le_integralClosure {x : A} (hx : IsIntegral R x) : Algebra.adjoin R {x} ≤ integralClosure R A := by rw [Algebra.adjoin_le_iff] simp only [SetLike.mem_coe, Set.singleton_subset_iff] exact hx #align adjoin_le_integral_closure adjoin_le_integralClosure theorem le_integralClosure_iff_isIntegral {S : Subalgebra R A} : S ≤ integralClosure R A ↔ Algebra.IsIntegral R S := SetLike.forall.symm.trans <| (forall_congr' fun x => show IsIntegral R (algebraMap S A x) ↔ IsIntegral R x from isIntegral_algebraMap_iff Subtype.coe_injective).trans Algebra.isIntegral_def.symm #align le_integral_closure_iff_is_integral le_integralClosure_iff_isIntegral theorem Algebra.isIntegral_sup {S T : Subalgebra R A} : Algebra.IsIntegral R (S ⊔ T : Subalgebra R A) ↔ Algebra.IsIntegral R S ∧ Algebra.IsIntegral R T := by simp only [← le_integralClosure_iff_isIntegral, sup_le_iff] #align is_integral_sup Algebra.isIntegral_sup /-- Mapping an integral closure along an `AlgEquiv` gives the integral closure. -/ theorem integralClosure_map_algEquiv [Algebra R S] (f : A ≃ₐ[R] S) : (integralClosure R A).map (f : A →ₐ[R] S) = integralClosure R S := by ext y rw [Subalgebra.mem_map] constructor · rintro ⟨x, hx, rfl⟩ exact hx.map f · intro hy use f.symm y, hy.map (f.symm : S →ₐ[R] A) simp #align integral_closure_map_alg_equiv integralClosure_map_algEquiv /-- An `AlgHom` between two rings restrict to an `AlgHom` between the integral closures inside them. -/ def AlgHom.mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) : integralClosure R A →ₐ[R] integralClosure R S := (f.restrictDomain (integralClosure R A)).codRestrict (integralClosure R S) (fun ⟨_, h⟩ => h.map f) @[simp] theorem AlgHom.coe_mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl /-- An `AlgEquiv` between two rings restrict to an `AlgEquiv` between the integral closures inside them. -/ def AlgEquiv.mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) : integralClosure R A ≃ₐ[R] integralClosure R S := AlgEquiv.ofAlgHom (f : A →ₐ[R] S).mapIntegralClosure (f.symm : S →ₐ[R] A).mapIntegralClosure (AlgHom.ext fun _ ↦ Subtype.ext (f.right_inv _)) (AlgHom.ext fun _ ↦ Subtype.ext (f.left_inv _)) @[simp] theorem AlgEquiv.coe_mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl theorem integralClosure.isIntegral (x : integralClosure R A) : IsIntegral R x := let ⟨p, hpm, hpx⟩ := x.2 ⟨p, hpm, Subtype.eq <| by rwa [← aeval_def, ← Subalgebra.val_apply, aeval_algHom_apply] at hpx⟩ #align integral_closure.is_integral integralClosure.isIntegral instance integralClosure.AlgebraIsIntegral : Algebra.IsIntegral R (integralClosure R A) := ⟨integralClosure.isIntegral⟩
Mathlib/RingTheory/IntegralClosure.lean
519
525
theorem IsIntegral.of_mul_unit {x y : B} {r : R} (hr : algebraMap R B r * y = 1) (hx : IsIntegral R (x * y)) : IsIntegral R x := by
obtain ⟨p, p_monic, hp⟩ := hx refine ⟨scaleRoots p r, (monic_scaleRoots_iff r).2 p_monic, ?_⟩ convert scaleRoots_aeval_eq_zero hp rw [Algebra.commutes] at hr ⊢ rw [mul_assoc, hr, mul_one]; rfl
/- 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.Order.Partition.Equipartition #align_import combinatorics.simple_graph.regularity.equitabilise from "leanprover-community/mathlib"@"bf7ef0e83e5b7e6c1169e97f055e58a2e4e9d52d" /-! # Equitabilising a partition This file allows to blow partitions up into parts of controlled size. Given a partition `P` and `a b m : ℕ`, we want to find a partition `Q` with `a` parts of size `m` and `b` parts of size `m + 1` such that all parts of `P` are "as close as possible" to unions of parts of `Q`. By "as close as possible", we mean that each part of `P` can be written as the union of some parts of `Q` along with at most `m` other elements. ## Main declarations * `Finpartition.equitabilise`: `P.equitabilise h` where `h : a * m + b * (m + 1)` is a partition with `a` parts of size `m` and `b` parts of size `m + 1` which almost refines `P`. * `Finpartition.exists_equipartition_card_eq`: We can find equipartitions of arbitrary size. ## References [Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp] -/ open Finset Nat namespace Finpartition variable {α : Type*} [DecidableEq α] {s t : Finset α} {m n a b : ℕ} {P : Finpartition s} /-- Given a partition `P` of `s`, as well as a proof that `a * m + b * (m + 1) = s.card`, we can find a new partition `Q` of `s` where each part has size `m` or `m + 1`, every part of `P` is the union of parts of `Q` plus at most `m` extra elements, there are `b` parts of size `m + 1` and (provided `m > 0`, because a partition does not have parts of size `0`) there are `a` parts of size `m` and hence `a + b` parts in total. -/ theorem equitabilise_aux (hs : a * m + b * (m + 1) = s.card) : ∃ Q : Finpartition s, (∀ x : Finset α, x ∈ Q.parts → x.card = m ∨ x.card = m + 1) ∧ (∀ x, x ∈ P.parts → (x \ (Q.parts.filter fun y => y ⊆ x).biUnion id).card ≤ m) ∧ (Q.parts.filter fun i => card i = m + 1).card = b := by -- Get rid of the easy case `m = 0` obtain rfl | m_pos := m.eq_zero_or_pos · refine ⟨⊥, by simp, ?_, by simpa [Finset.filter_true_of_mem] using hs.symm⟩ simp only [le_zero_iff, card_eq_zero, mem_biUnion, exists_prop, mem_filter, id, and_assoc, sdiff_eq_empty_iff_subset, subset_iff] exact fun x hx a ha => ⟨{a}, mem_map_of_mem _ (P.le hx ha), singleton_subset_iff.2 ha, mem_singleton_self _⟩ -- Prove the case `m > 0` by strong induction on `s` induction' s using Finset.strongInduction with s ih generalizing a b -- If `a = b = 0`, then `s = ∅` and we can partition into zero parts by_cases hab : a = 0 ∧ b = 0 · simp only [hab.1, hab.2, add_zero, zero_mul, eq_comm, card_eq_zero, Finset.bot_eq_empty] at hs subst hs -- Porting note: to synthesize `Finpartition ∅`, `have` is required have : P = Finpartition.empty _ := Unique.eq_default (α := Finpartition ⊥) P exact ⟨Finpartition.empty _, by simp, by simp [this], by simp [hab.2]⟩ simp_rw [not_and_or, ← Ne.eq_def, ← pos_iff_ne_zero] at hab -- `n` will be the size of the smallest part set n := if 0 < a then m else m + 1 with hn -- Some easy facts about it obtain ⟨hn₀, hn₁, hn₂, hn₃⟩ : 0 < n ∧ n ≤ m + 1 ∧ n ≤ a * m + b * (m + 1) ∧ ite (0 < a) (a - 1) a * m + ite (0 < a) b (b - 1) * (m + 1) = s.card - n := by rw [hn, ← hs] split_ifs with h <;> rw [tsub_mul, one_mul] · refine ⟨m_pos, le_succ _, le_add_right (Nat.le_mul_of_pos_left _ ‹0 < a›), ?_⟩ rw [tsub_add_eq_add_tsub (Nat.le_mul_of_pos_left _ h)] · refine ⟨succ_pos', le_rfl, le_add_left (Nat.le_mul_of_pos_left _ <| hab.resolve_left ‹¬0 < a›), ?_⟩ rw [← add_tsub_assoc_of_le (Nat.le_mul_of_pos_left _ <| hab.resolve_left ‹¬0 < a›)] /- We will call the inductive hypothesis on a partition of `s \ t` for a carefully chosen `t ⊆ s`. To decide which, however, we must distinguish the case where all parts of `P` have size `m` (in which case we take `t` to be an arbitrary subset of `s` of size `n`) from the case where at least one part `u` of `P` has size `m + 1` (in which case we take `t` to be an arbitrary subset of `u` of size `n`). The rest of each branch is just tedious calculations to satisfy the induction hypothesis. -/ by_cases h : ∀ u ∈ P.parts, card u < m + 1 · obtain ⟨t, hts, htn⟩ := exists_smaller_set s n (hn₂.trans_eq hs) have ht : t.Nonempty := by rwa [← card_pos, htn] have hcard : ite (0 < a) (a - 1) a * m + ite (0 < a) b (b - 1) * (m + 1) = (s \ t).card := by rw [card_sdiff ‹t ⊆ s›, htn, hn₃] obtain ⟨R, hR₁, _, hR₃⟩ := @ih (s \ t) (sdiff_ssubset hts ‹t.Nonempty›) (if 0 < a then a - 1 else a) (if 0 < a then b else b - 1) (P.avoid t) hcard refine ⟨R.extend ht.ne_empty sdiff_disjoint (sdiff_sup_cancel hts), ?_, ?_, ?_⟩ · simp only [extend_parts, mem_insert, forall_eq_or_imp, and_iff_left hR₁, htn, hn] exact ite_eq_or_eq _ _ _ · exact fun x hx => (card_le_card sdiff_subset).trans (Nat.lt_succ_iff.1 <| h _ hx) simp_rw [extend_parts, filter_insert, htn, m.succ_ne_self.symm.ite_eq_right_iff] split_ifs with ha · rw [hR₃, if_pos ha] rw [card_insert_of_not_mem, hR₃, if_neg ha, tsub_add_cancel_of_le] · exact hab.resolve_left ha · intro H; exact ht.ne_empty (le_sdiff_iff.1 <| R.le <| filter_subset _ _ H) push_neg at h obtain ⟨u, hu₁, hu₂⟩ := h obtain ⟨t, htu, htn⟩ := exists_smaller_set _ _ (hn₁.trans hu₂) have ht : t.Nonempty := by rwa [← card_pos, htn] have hcard : ite (0 < a) (a - 1) a * m + ite (0 < a) b (b - 1) * (m + 1) = (s \ t).card := by rw [card_sdiff (htu.trans <| P.le hu₁), htn, hn₃] obtain ⟨R, hR₁, hR₂, hR₃⟩ := @ih (s \ t) (sdiff_ssubset (htu.trans <| P.le hu₁) ht) (if 0 < a then a - 1 else a) (if 0 < a then b else b - 1) (P.avoid t) hcard refine ⟨R.extend ht.ne_empty sdiff_disjoint (sdiff_sup_cancel <| htu.trans <| P.le hu₁), ?_, ?_, ?_⟩ · simp only [mem_insert, forall_eq_or_imp, extend_parts, and_iff_left hR₁, htn, hn] exact ite_eq_or_eq _ _ _ · conv in _ ∈ _ => rw [← insert_erase hu₁] simp only [and_imp, mem_insert, forall_eq_or_imp, Ne, extend_parts] refine ⟨?_, fun x hx => (card_le_card ?_).trans <| hR₂ x ?_⟩ · simp only [filter_insert, if_pos htu, biUnion_insert, mem_erase, id] obtain rfl | hut := eq_or_ne u t · rw [sdiff_eq_empty_iff_subset.2 subset_union_left] exact bot_le refine (card_le_card fun i => ?_).trans (hR₂ (u \ t) <| P.mem_avoid.2 ⟨u, hu₁, fun i => hut <| i.antisymm htu, rfl⟩) -- Porting note: `not_and` required because `∃ x ∈ s, p x` is defined differently simp only [not_exists, not_and, mem_biUnion, and_imp, mem_union, mem_filter, mem_sdiff, id, not_or] exact fun hi₁ hi₂ hi₃ => ⟨⟨hi₁, hi₂⟩, fun x hx hx' => hi₃ _ hx <| hx'.trans sdiff_subset⟩ · apply sdiff_subset_sdiff Subset.rfl (biUnion_subset_biUnion_of_subset_left _ _) exact filter_subset_filter _ (subset_insert _ _) simp only [avoid, ofErase, mem_erase, mem_image, bot_eq_empty] exact ⟨(nonempty_of_mem_parts _ <| mem_of_mem_erase hx).ne_empty, _, mem_of_mem_erase hx, (disjoint_of_subset_right htu <| P.disjoint (mem_of_mem_erase hx) hu₁ <| ne_of_mem_erase hx).sdiff_eq_left⟩ simp only [extend_parts, filter_insert, htn, hn, m.succ_ne_self.symm.ite_eq_right_iff] split_ifs with h · rw [hR₃, if_pos h] · rw [card_insert_of_not_mem, hR₃, if_neg h, Nat.sub_add_cancel (hab.resolve_left h)] intro H; exact ht.ne_empty (le_sdiff_iff.1 <| R.le <| filter_subset _ _ H) #align finpartition.equitabilise_aux Finpartition.equitabilise_aux variable (h : a * m + b * (m + 1) = s.card) /-- Given a partition `P` of `s`, as well as a proof that `a * m + b * (m + 1) = s.card`, build a new partition `Q` of `s` where each part has size `m` or `m + 1`, every part of `P` is the union of parts of `Q` plus at most `m` extra elements, there are `b` parts of size `m + 1` and (provided `m > 0`, because a partition does not have parts of size `0`) there are `a` parts of size `m` and hence `a + b` parts in total. -/ noncomputable def equitabilise : Finpartition s := (P.equitabilise_aux h).choose #align finpartition.equitabilise Finpartition.equitabilise variable {h} theorem card_eq_of_mem_parts_equitabilise : t ∈ (P.equitabilise h).parts → t.card = m ∨ t.card = m + 1 := (P.equitabilise_aux h).choose_spec.1 _ #align finpartition.card_eq_of_mem_parts_equitabilise Finpartition.card_eq_of_mem_parts_equitabilise theorem equitabilise_isEquipartition : (P.equitabilise h).IsEquipartition := Set.equitableOn_iff_exists_eq_eq_add_one.2 ⟨m, fun _ => card_eq_of_mem_parts_equitabilise⟩ #align finpartition.equitabilise_is_equipartition Finpartition.equitabilise_isEquipartition variable (P h) theorem card_filter_equitabilise_big : ((P.equitabilise h).parts.filter fun u : Finset α => u.card = m + 1).card = b := (P.equitabilise_aux h).choose_spec.2.2 #align finpartition.card_filter_equitabilise_big Finpartition.card_filter_equitabilise_big
Mathlib/Combinatorics/SimpleGraph/Regularity/Equitabilise.lean
171
187
theorem card_filter_equitabilise_small (hm : m ≠ 0) : ((P.equitabilise h).parts.filter fun u : Finset α => u.card = m).card = a := by
refine (mul_eq_mul_right_iff.1 <| (add_left_inj (b * (m + 1))).1 ?_).resolve_right hm rw [h, ← (P.equitabilise h).sum_card_parts] have hunion : (P.equitabilise h).parts = ((P.equitabilise h).parts.filter fun u => u.card = m) ∪ (P.equitabilise h).parts.filter fun u => u.card = m + 1 := by rw [← filter_or, filter_true_of_mem] exact fun x => card_eq_of_mem_parts_equitabilise nth_rw 2 [hunion] rw [sum_union, sum_const_nat fun x hx => (mem_filter.1 hx).2, sum_const_nat fun x hx => (mem_filter.1 hx).2, P.card_filter_equitabilise_big] refine disjoint_filter_filter' _ _ ?_ intro x ha hb i h apply succ_ne_self m _ exact (hb i h).symm.trans (ha i h)
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.SpecialFunctions.Complex.Circle import Mathlib.Geometry.Euclidean.Angle.Oriented.Basic #align_import geometry.euclidean.angle.oriented.rotation from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Rotations by oriented angles. This file defines rotations by oriented angles in real inner product spaces. ## Main definitions * `Orientation.rotation` is the rotation by an oriented angle with respect to an orientation. -/ noncomputable section open FiniteDimensional Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "J" => o.rightAngleRotation /-- Auxiliary construction to build a rotation by the oriented angle `θ`. -/ def rotationAux (θ : Real.Angle) : V →ₗᵢ[ℝ] V := LinearMap.isometryOfInner (Real.Angle.cos θ • LinearMap.id + Real.Angle.sin θ • (LinearIsometryEquiv.toLinearEquiv J).toLinearMap) (by intro x y simp only [RCLike.conj_to_real, id, LinearMap.smul_apply, LinearMap.add_apply, LinearMap.id_coe, LinearEquiv.coe_coe, LinearIsometryEquiv.coe_toLinearEquiv, Orientation.areaForm_rightAngleRotation_left, Orientation.inner_rightAngleRotation_left, Orientation.inner_rightAngleRotation_right, inner_add_left, inner_smul_left, inner_add_right, inner_smul_right] linear_combination inner (𝕜 := ℝ) x y * θ.cos_sq_add_sin_sq) #align orientation.rotation_aux Orientation.rotationAux @[simp] theorem rotationAux_apply (θ : Real.Angle) (x : V) : o.rotationAux θ x = Real.Angle.cos θ • x + Real.Angle.sin θ • J x := rfl #align orientation.rotation_aux_apply Orientation.rotationAux_apply /-- A rotation by the oriented angle `θ`. -/ def rotation (θ : Real.Angle) : V ≃ₗᵢ[ℝ] V := LinearIsometryEquiv.ofLinearIsometry (o.rotationAux θ) (Real.Angle.cos θ • LinearMap.id - Real.Angle.sin θ • (LinearIsometryEquiv.toLinearEquiv J).toLinearMap) (by ext x convert congr_arg (fun t : ℝ => t • x) θ.cos_sq_add_sin_sq using 1 · simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply, Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap, LinearIsometryEquiv.coe_toLinearEquiv, map_smul, map_sub, LinearMap.coe_comp, LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply, ← mul_smul, add_smul, smul_add, smul_neg, smul_sub, mul_comm, sq] abel · simp) (by ext x convert congr_arg (fun t : ℝ => t • x) θ.cos_sq_add_sin_sq using 1 · simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply, Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap, LinearIsometryEquiv.coe_toLinearEquiv, map_add, map_smul, LinearMap.coe_comp, LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply, add_smul, smul_neg, smul_sub, smul_smul] ring_nf abel · simp) #align orientation.rotation Orientation.rotation theorem rotation_apply (θ : Real.Angle) (x : V) : o.rotation θ x = Real.Angle.cos θ • x + Real.Angle.sin θ • J x := rfl #align orientation.rotation_apply Orientation.rotation_apply theorem rotation_symm_apply (θ : Real.Angle) (x : V) : (o.rotation θ).symm x = Real.Angle.cos θ • x - Real.Angle.sin θ • J x := rfl #align orientation.rotation_symm_apply Orientation.rotation_symm_apply theorem rotation_eq_matrix_toLin (θ : Real.Angle) {x : V} (hx : x ≠ 0) : (o.rotation θ).toLinearMap = Matrix.toLin (o.basisRightAngleRotation x hx) (o.basisRightAngleRotation x hx) !![θ.cos, -θ.sin; θ.sin, θ.cos] := by apply (o.basisRightAngleRotation x hx).ext intro i fin_cases i · rw [Matrix.toLin_self] simp [rotation_apply, Fin.sum_univ_succ] · rw [Matrix.toLin_self] simp [rotation_apply, Fin.sum_univ_succ, add_comm] #align orientation.rotation_eq_matrix_to_lin Orientation.rotation_eq_matrix_toLin /-- The determinant of `rotation` (as a linear map) is equal to `1`. -/ @[simp] theorem det_rotation (θ : Real.Angle) : LinearMap.det (o.rotation θ).toLinearMap = 1 := by haveI : Nontrivial V := FiniteDimensional.nontrivial_of_finrank_eq_succ (@Fact.out (finrank ℝ V = 2) _) obtain ⟨x, hx⟩ : ∃ x, x ≠ (0 : V) := exists_ne (0 : V) rw [o.rotation_eq_matrix_toLin θ hx] simpa [sq] using θ.cos_sq_add_sin_sq #align orientation.det_rotation Orientation.det_rotation /-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/ @[simp] theorem linearEquiv_det_rotation (θ : Real.Angle) : LinearEquiv.det (o.rotation θ).toLinearEquiv = 1 := Units.ext <| by -- Porting note: Lean can't see through `LinearEquiv.coe_det` and needed the rewrite -- in mathlib3 this was just `units.ext <| o.det_rotation θ` simpa only [LinearEquiv.coe_det, Units.val_one] using o.det_rotation θ #align orientation.linear_equiv_det_rotation Orientation.linearEquiv_det_rotation /-- The inverse of `rotation` is rotation by the negation of the angle. -/ @[simp] theorem rotation_symm (θ : Real.Angle) : (o.rotation θ).symm = o.rotation (-θ) := by ext; simp [o.rotation_apply, o.rotation_symm_apply, sub_eq_add_neg] #align orientation.rotation_symm Orientation.rotation_symm /-- Rotation by 0 is the identity. -/ @[simp] theorem rotation_zero : o.rotation 0 = LinearIsometryEquiv.refl ℝ V := by ext; simp [rotation] #align orientation.rotation_zero Orientation.rotation_zero /-- Rotation by π is negation. -/ @[simp] theorem rotation_pi : o.rotation π = LinearIsometryEquiv.neg ℝ := by ext x simp [rotation] #align orientation.rotation_pi Orientation.rotation_pi /-- Rotation by π is negation. -/ theorem rotation_pi_apply (x : V) : o.rotation π x = -x := by simp #align orientation.rotation_pi_apply Orientation.rotation_pi_apply /-- Rotation by π / 2 is the "right-angle-rotation" map `J`. -/ theorem rotation_pi_div_two : o.rotation (π / 2 : ℝ) = J := by ext x simp [rotation] #align orientation.rotation_pi_div_two Orientation.rotation_pi_div_two /-- Rotating twice is equivalent to rotating by the sum of the angles. -/ @[simp] theorem rotation_rotation (θ₁ θ₂ : Real.Angle) (x : V) : o.rotation θ₁ (o.rotation θ₂ x) = o.rotation (θ₁ + θ₂) x := by simp only [o.rotation_apply, ← mul_smul, Real.Angle.cos_add, Real.Angle.sin_add, add_smul, sub_smul, LinearIsometryEquiv.trans_apply, smul_add, LinearIsometryEquiv.map_add, LinearIsometryEquiv.map_smul, rightAngleRotation_rightAngleRotation, smul_neg] ring_nf abel #align orientation.rotation_rotation Orientation.rotation_rotation /-- Rotating twice is equivalent to rotating by the sum of the angles. -/ @[simp] theorem rotation_trans (θ₁ θ₂ : Real.Angle) : (o.rotation θ₁).trans (o.rotation θ₂) = o.rotation (θ₂ + θ₁) := LinearIsometryEquiv.ext fun _ => by rw [← rotation_rotation, LinearIsometryEquiv.trans_apply] #align orientation.rotation_trans Orientation.rotation_trans /-- Rotating the first of two vectors by `θ` scales their Kahler form by `cos θ - sin θ * I`. -/ @[simp] theorem kahler_rotation_left (x y : V) (θ : Real.Angle) : o.kahler (o.rotation θ x) y = conj (θ.expMapCircle : ℂ) * o.kahler x y := by -- Porting note: this needed the `Complex.conj_ofReal` instead of `RCLike.conj_ofReal`; -- I believe this is because the respective coercions are no longer defeq, and -- `Real.Angle.coe_expMapCircle` uses the `Complex` version. simp only [o.rotation_apply, map_add, map_mul, LinearMap.map_smulₛₗ, RingHom.id_apply, LinearMap.add_apply, LinearMap.smul_apply, real_smul, kahler_rightAngleRotation_left, Real.Angle.coe_expMapCircle, Complex.conj_ofReal, conj_I] ring #align orientation.kahler_rotation_left Orientation.kahler_rotation_left /-- Negating a rotation is equivalent to rotation by π plus the angle. -/ theorem neg_rotation (θ : Real.Angle) (x : V) : -o.rotation θ x = o.rotation (π + θ) x := by rw [← o.rotation_pi_apply, rotation_rotation] #align orientation.neg_rotation Orientation.neg_rotation /-- Negating a rotation by -π / 2 is equivalent to rotation by π / 2. -/ @[simp] theorem neg_rotation_neg_pi_div_two (x : V) : -o.rotation (-π / 2 : ℝ) x = o.rotation (π / 2 : ℝ) x := by rw [neg_rotation, ← Real.Angle.coe_add, neg_div, ← sub_eq_add_neg, sub_half] #align orientation.neg_rotation_neg_pi_div_two Orientation.neg_rotation_neg_pi_div_two /-- Negating a rotation by π / 2 is equivalent to rotation by -π / 2. -/ theorem neg_rotation_pi_div_two (x : V) : -o.rotation (π / 2 : ℝ) x = o.rotation (-π / 2 : ℝ) x := (neg_eq_iff_eq_neg.mp <| o.neg_rotation_neg_pi_div_two _).symm #align orientation.neg_rotation_pi_div_two Orientation.neg_rotation_pi_div_two /-- Rotating the first of two vectors by `θ` scales their Kahler form by `cos (-θ) + sin (-θ) * I`. -/ theorem kahler_rotation_left' (x y : V) (θ : Real.Angle) : o.kahler (o.rotation θ x) y = (-θ).expMapCircle * o.kahler x y := by simp only [Real.Angle.expMapCircle_neg, coe_inv_circle_eq_conj, kahler_rotation_left] #align orientation.kahler_rotation_left' Orientation.kahler_rotation_left' /-- Rotating the second of two vectors by `θ` scales their Kahler form by `cos θ + sin θ * I`. -/ @[simp] theorem kahler_rotation_right (x y : V) (θ : Real.Angle) : o.kahler x (o.rotation θ y) = θ.expMapCircle * o.kahler x y := by simp only [o.rotation_apply, map_add, LinearMap.map_smulₛₗ, RingHom.id_apply, real_smul, kahler_rightAngleRotation_right, Real.Angle.coe_expMapCircle] ring #align orientation.kahler_rotation_right Orientation.kahler_rotation_right /-- Rotating the first vector by `θ` subtracts `θ` from the angle between two vectors. -/ @[simp] theorem oangle_rotation_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) (θ : Real.Angle) : o.oangle (o.rotation θ x) y = o.oangle x y - θ := by simp only [oangle, o.kahler_rotation_left'] rw [Complex.arg_mul_coe_angle, Real.Angle.arg_expMapCircle] · abel · exact ne_zero_of_mem_circle _ · exact o.kahler_ne_zero hx hy #align orientation.oangle_rotation_left Orientation.oangle_rotation_left /-- Rotating the second vector by `θ` adds `θ` to the angle between two vectors. -/ @[simp] theorem oangle_rotation_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) (θ : Real.Angle) : o.oangle x (o.rotation θ y) = o.oangle x y + θ := by simp only [oangle, o.kahler_rotation_right] rw [Complex.arg_mul_coe_angle, Real.Angle.arg_expMapCircle] · abel · exact ne_zero_of_mem_circle _ · exact o.kahler_ne_zero hx hy #align orientation.oangle_rotation_right Orientation.oangle_rotation_right /-- The rotation of a vector by `θ` has an angle of `-θ` from that vector. -/ @[simp] theorem oangle_rotation_self_left {x : V} (hx : x ≠ 0) (θ : Real.Angle) : o.oangle (o.rotation θ x) x = -θ := by simp [hx] #align orientation.oangle_rotation_self_left Orientation.oangle_rotation_self_left /-- A vector has an angle of `θ` from the rotation of that vector by `θ`. -/ @[simp] theorem oangle_rotation_self_right {x : V} (hx : x ≠ 0) (θ : Real.Angle) : o.oangle x (o.rotation θ x) = θ := by simp [hx] #align orientation.oangle_rotation_self_right Orientation.oangle_rotation_self_right /-- Rotating the first vector by the angle between the two vectors results in an angle of 0. -/ @[simp] theorem oangle_rotation_oangle_left (x y : V) : o.oangle (o.rotation (o.oangle x y) x) y = 0 := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [hx, hy] #align orientation.oangle_rotation_oangle_left Orientation.oangle_rotation_oangle_left /-- Rotating the first vector by the angle between the two vectors and swapping the vectors results in an angle of 0. -/ @[simp] theorem oangle_rotation_oangle_right (x y : V) : o.oangle y (o.rotation (o.oangle x y) x) = 0 := by rw [oangle_rev] simp #align orientation.oangle_rotation_oangle_right Orientation.oangle_rotation_oangle_right /-- Rotating both vectors by the same angle does not change the angle between those vectors. -/ @[simp] theorem oangle_rotation (x y : V) (θ : Real.Angle) : o.oangle (o.rotation θ x) (o.rotation θ y) = o.oangle x y := by by_cases hx : x = 0 <;> by_cases hy : y = 0 <;> simp [hx, hy] #align orientation.oangle_rotation Orientation.oangle_rotation /-- A rotation of a nonzero vector equals that vector if and only if the angle is zero. -/ @[simp] theorem rotation_eq_self_iff_angle_eq_zero {x : V} (hx : x ≠ 0) (θ : Real.Angle) : o.rotation θ x = x ↔ θ = 0 := by constructor · intro h rw [eq_comm] simpa [hx, h] using o.oangle_rotation_right hx hx θ · intro h simp [h] #align orientation.rotation_eq_self_iff_angle_eq_zero Orientation.rotation_eq_self_iff_angle_eq_zero /-- A nonzero vector equals a rotation of that vector if and only if the angle is zero. -/ @[simp] theorem eq_rotation_self_iff_angle_eq_zero {x : V} (hx : x ≠ 0) (θ : Real.Angle) : x = o.rotation θ x ↔ θ = 0 := by rw [← o.rotation_eq_self_iff_angle_eq_zero hx, eq_comm] #align orientation.eq_rotation_self_iff_angle_eq_zero Orientation.eq_rotation_self_iff_angle_eq_zero /-- A rotation of a vector equals that vector if and only if the vector or the angle is zero. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/Rotation.lean
302
303
theorem rotation_eq_self_iff (x : V) (θ : Real.Angle) : o.rotation θ x = x ↔ x = 0 ∨ θ = 0 := by
by_cases h : x = 0 <;> simp [h]
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order #align_import probability.process.stopping from "leanprover-community/mathlib"@"ba074af83b6cf54c3104e59402b39410ddbd6dca" /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memℒp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped process belongs to `ℒp` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable with respect to `f i`. Intuitively, the stopping time `τ` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → ι) := ∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i} #align measure_theory.is_stopping_time MeasureTheory.IsStoppingTime theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] #align measure_theory.is_stopping_time_const MeasureTheory.isStoppingTime_const section MeasurableSet section Preorder variable [Preorder ι] {f : Filtration ι m} {τ : Ω → ι} protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω ≤ i} := hτ i #align measure_theory.is_stopping_time.measurable_set_le MeasureTheory.IsStoppingTime.measurableSet_le theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (τ ω) have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i) #align measure_theory.is_stopping_time.measurable_set_lt_of_pred MeasureTheory.IsStoppingTime.measurableSet_lt_of_pred end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ι] {τ : Ω → ι} {f : Filtration ι m} protected theorem measurableSet_eq_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} \ ⋃ (j ∈ Set.range τ) (_ : j < i), {ω | τ ω ≤ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le] constructor <;> intro h · simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] · exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hτ.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ rw [Set.iUnion_eq_if] split_ifs with hji · exact f.mono hji.le _ (hτ.measurableSet_le j) · exact @MeasurableSet.empty _ (f i) #align measure_theory.is_stopping_time.measurable_set_eq_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable_range protected theorem measurableSet_eq_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable protected theorem measurableSet_lt_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω; simp [lt_iff_le_and_ne] rw [this] exact (hτ.measurableSet_le i).diff (hτ.measurableSet_eq_of_countable_range h_countable i) #align measure_theory.is_stopping_time.measurable_set_lt_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable_range protected theorem measurableSet_lt_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_lt_of_countable MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable protected theorem measurableSet_ge_of_countable_range {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt_of_countable_range h_countable i).compl #align measure_theory.is_stopping_time.measurable_set_ge_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable_range protected theorem measurableSet_ge_of_countable {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_ge_of_countable MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} theorem IsStoppingTime.measurableSet_gt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i < τ ω} := by have : {ω | i < τ ω} = {ω | τ ω ≤ i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hτ.measurableSet_le i).compl #align measure_theory.is_stopping_time.measurable_set_gt MeasureTheory.IsStoppingTime.measurableSet_gt section TopologicalSpace variable [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hτ : IsStoppingTime f τ) (i : ι) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] exact isMin_iff_forall_not_lt.mp hi_min (τ ω) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : ∃ seq : ℕ → ι, Monotone seq ∧ (∀ j, seq j ≤ i) ∧ Tendsto seq atTop (𝓝 i) ∧ ∀ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≤ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ · rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : ∃ a : ℕ, ∀ b : ℕ, b ≥ a → k ≤ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ · obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {ω | τ ω < i} = τ ⁻¹' Set.Iio i := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hτ.measurableSet_le (seq n)) #align measure_theory.is_stopping_time.measurable_set_lt_of_is_lub MeasureTheory.IsStoppingTime.measurableSet_lt_of_isLUB theorem IsStoppingTime.measurableSet_lt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by obtain ⟨i', hi'_lub⟩ : ∃ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i cases' lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i h_Iio_eq_Iic · rw [← hi'_eq_i] at hi'_lub ⊢ exact hτ.measurableSet_lt_of_isLUB i' hi'_lub · have h_lt_eq_preimage : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hτ.measurableSet_le i') #align measure_theory.is_stopping_time.measurable_set_lt MeasureTheory.IsStoppingTime.measurableSet_lt theorem IsStoppingTime.measurableSet_ge (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt i).compl #align measure_theory.is_stopping_time.measurable_set_ge MeasureTheory.IsStoppingTime.measurableSet_ge theorem IsStoppingTime.measurableSet_eq (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} ∩ {ω | τ ω ≥ i} := by ext1 ω; simp only [Set.mem_setOf_eq, ge_iff_le, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i) #align measure_theory.is_stopping_time.measurable_set_eq MeasureTheory.IsStoppingTime.measurableSet_eq theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω = i} := f.mono hle _ <| hτ.measurableSet_eq i #align measure_theory.is_stopping_time.measurable_set_eq_le MeasureTheory.IsStoppingTime.measurableSet_eq_le theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω < i} := f.mono hle _ <| hτ.measurableSet_lt i #align measure_theory.is_stopping_time.measurable_set_lt_le MeasureTheory.IsStoppingTime.measurableSet_lt_le end TopologicalSpace end LinearOrder section Countable theorem isStoppingTime_of_measurableSet_eq [Preorder ι] [Countable ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : ∀ i, MeasurableSet[f i] {ω | τ ω = i}) : IsStoppingTime f τ := by intro i rw [show {ω | τ ω ≤ i} = ⋃ k ≤ i, {ω | τ ω = k} by ext; simp] refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_ exact f.mono hk _ (hτ k) #align measure_theory.is_stopping_time_of_measurable_set_eq MeasureTheory.isStoppingTime_of_measurableSet_eq end Countable end MeasurableSet namespace IsStoppingTime protected theorem max [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => max (τ ω) (π ω) := by intro i simp_rw [max_le_iff, Set.setOf_and] exact (hτ i).inter (hπ i) #align measure_theory.is_stopping_time.max MeasureTheory.IsStoppingTime.max protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i := hτ.max (isStoppingTime_const f i) #align measure_theory.is_stopping_time.max_const MeasureTheory.IsStoppingTime.max_const protected theorem min [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => min (τ ω) (π ω) := by intro i simp_rw [min_le_iff, Set.setOf_or] exact (hτ i).union (hπ i) #align measure_theory.is_stopping_time.min MeasureTheory.IsStoppingTime.min protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i := hτ.min (isStoppingTime_const f i) #align measure_theory.is_stopping_time.min_const MeasureTheory.IsStoppingTime.min_const theorem add_const [AddGroup ι] [Preorder ι] [CovariantClass ι ι (Function.swap (· + ·)) (· ≤ ·)] [CovariantClass ι ι (· + ·) (· ≤ ·)] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {i : ι} (hi : 0 ≤ i) : IsStoppingTime f fun ω => τ ω + i := by intro j simp_rw [← le_sub_iff_add_le] exact f.mono (sub_le_self j hi) _ (hτ (j - i)) #align measure_theory.is_stopping_time.add_const MeasureTheory.IsStoppingTime.add_const theorem add_const_nat {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) {i : ℕ} : IsStoppingTime f fun ω => τ ω + i := by refine isStoppingTime_of_measurableSet_eq fun j => ?_ by_cases hij : i ≤ j · simp_rw [eq_comm, ← Nat.sub_eq_iff_eq_add hij, eq_comm] exact f.mono (j.sub_le i) _ (hτ.measurableSet_eq (j - i)) · rw [not_le] at hij convert @MeasurableSet.empty _ (f.1 j) ext ω simp only [Set.mem_empty_iff_false, iff_false_iff, Set.mem_setOf] omega #align measure_theory.is_stopping_time.add_const_nat MeasureTheory.IsStoppingTime.add_const_nat -- generalize to certain countable type? theorem add {f : Filtration ℕ m} {τ π : Ω → ℕ} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f (τ + π) := by intro i rw [(_ : {ω | (τ + π) ω ≤ i} = ⋃ k ≤ i, {ω | π ω = k} ∩ {ω | τ ω + k ≤ i})] · exact MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun hk => (hπ.measurableSet_eq_le hk).inter (hτ.add_const_nat i) ext ω simp only [Pi.add_apply, Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_prop] refine ⟨fun h => ⟨π ω, by omega, rfl, h⟩, ?_⟩ rintro ⟨j, hj, rfl, h⟩ assumption #align measure_theory.is_stopping_time.add MeasureTheory.IsStoppingTime.add section Preorder variable [Preorder ι] {f : Filtration ι m} {τ π : Ω → ι} /-- The associated σ-algebra with a stopping time. -/ protected def measurableSpace (hτ : IsStoppingTime f τ) : MeasurableSpace Ω where MeasurableSet' s := ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) measurableSet_empty i := (Set.empty_inter {ω | τ ω ≤ i}).symm ▸ @MeasurableSet.empty _ (f i) measurableSet_compl s hs i := by rw [(_ : sᶜ ∩ {ω | τ ω ≤ i} = (sᶜ ∪ {ω | τ ω ≤ i}ᶜ) ∩ {ω | τ ω ≤ i})] · refine MeasurableSet.inter ?_ ?_ · rw [← Set.compl_inter] exact (hs i).compl · exact hτ i · rw [Set.union_inter_distrib_right] simp only [Set.compl_inter_self, Set.union_empty] measurableSet_iUnion s hs i := by rw [forall_swap] at hs rw [Set.iUnion_inter] exact MeasurableSet.iUnion (hs i) #align measure_theory.is_stopping_time.measurable_space MeasureTheory.IsStoppingTime.measurableSpace protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] s ↔ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) := Iff.rfl #align measure_theory.is_stopping_time.measurable_set MeasureTheory.IsStoppingTime.measurableSet theorem measurableSpace_mono (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (hle : τ ≤ π) : hτ.measurableSpace ≤ hπ.measurableSpace := by intro s hs i rw [(_ : s ∩ {ω | π ω ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | π ω ≤ i})] · exact (hs i).inter (hπ i) · ext simp only [Set.mem_inter_iff, iff_self_and, and_congr_left_iff, Set.mem_setOf_eq] intro hle' _ exact le_trans (hle _) hle' #align measure_theory.is_stopping_time.measurable_space_mono MeasureTheory.IsStoppingTime.measurableSpace_mono theorem measurableSpace_le_of_countable [Countable ι] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.iUnion fun i => f.le i _ (hs i) · ext ω; constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, hx, le_rfl⟩ · rintro ⟨_, hx, _⟩ exact hx #align measure_theory.is_stopping_time.measurable_space_le_of_countable MeasureTheory.IsStoppingTime.measurableSpace_le_of_countable theorem measurableSpace_le' [IsCountablyGenerated (atTop : Filter ι)] [(atTop : Filter ι).NeBot] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs obtain ⟨seq : ℕ → ι, h_seq_tendsto⟩ := (atTop : Filter ι).exists_seq_tendsto rw [(_ : s = ⋃ n, s ∩ {ω | τ ω ≤ seq n})] · exact MeasurableSet.iUnion fun i => f.le (seq i) _ (hs (seq i)) · ext ω; constructor <;> rw [Set.mem_iUnion] · intro hx suffices ∃ i, τ ω ≤ seq i from ⟨this.choose, hx, this.choose_spec⟩ rw [tendsto_atTop] at h_seq_tendsto exact (h_seq_tendsto (τ ω)).exists · rintro ⟨_, hx, _⟩ exact hx #align measure_theory.is_stopping_time.measurable_space_le' MeasureTheory.IsStoppingTime.measurableSpace_le' theorem measurableSpace_le {ι} [SemilatticeSup ι] {f : Filtration ι m} {τ : Ω → ι} [IsCountablyGenerated (atTop : Filter ι)] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by cases isEmpty_or_nonempty ι · haveI : IsEmpty Ω := ⟨fun ω => IsEmpty.false (τ ω)⟩ intro s _ suffices hs : s = ∅ by rw [hs]; exact MeasurableSet.empty haveI : Unique (Set Ω) := Set.uniqueEmpty rw [Unique.eq_default s, Unique.eq_default ∅] exact measurableSpace_le' hτ #align measure_theory.is_stopping_time.measurable_space_le MeasureTheory.IsStoppingTime.measurableSpace_le example {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le example {f : Filtration ℝ m} {τ : Ω → ℝ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le @[simp] theorem measurableSpace_const (f : Filtration ι m) (i : ι) : (isStoppingTime_const f i).measurableSpace = f i := by ext1 s change MeasurableSet[(isStoppingTime_const f i).measurableSpace] s ↔ MeasurableSet[f i] s rw [IsStoppingTime.measurableSet] constructor <;> intro h · specialize h i simpa only [le_refl, Set.setOf_true, Set.inter_univ] using h · intro j by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp only [hij, Set.setOf_false, Set.inter_empty, @MeasurableSet.empty _ (f.1 j)] #align measure_theory.is_stopping_time.measurable_space_const MeasureTheory.IsStoppingTime.measurableSpace_const theorem measurableSet_inter_eq_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω = i}) ↔ MeasurableSet[f i] (s ∩ {ω | τ ω = i}) := by have : ∀ j, {ω : Ω | τ ω = i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω = i} ∩ {_ω | i ≤ j} := by intro j ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] intro hxi rw [hxi] constructor <;> intro h · specialize h i simpa only [Set.inter_assoc, this, le_refl, Set.setOf_true, Set.inter_univ] using h · intro j rw [Set.inter_assoc, this] by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · set_option tactic.skipAssignedInstances false in simp [hij] convert @MeasurableSet.empty _ (Filtration.seq f j) #align measure_theory.is_stopping_time.measurable_set_inter_eq_iff MeasureTheory.IsStoppingTime.measurableSet_inter_eq_iff theorem measurableSpace_le_of_le_const (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : hτ.measurableSpace ≤ f i := (measurableSpace_mono hτ _ hτ_le).trans (measurableSpace_const _ _).le #align measure_theory.is_stopping_time.measurable_space_le_of_le_const MeasureTheory.IsStoppingTime.measurableSpace_le_of_le_const theorem measurableSpace_le_of_le (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : hτ.measurableSpace ≤ m := (hτ.measurableSpace_le_of_le_const hτ_le).trans (f.le n) #align measure_theory.is_stopping_time.measurable_space_le_of_le MeasureTheory.IsStoppingTime.measurableSpace_le_of_le theorem le_measurableSpace_of_const_le (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, i ≤ τ ω) : f i ≤ hτ.measurableSpace := (measurableSpace_const _ _).symm.le.trans (measurableSpace_mono _ hτ hτ_le) #align measure_theory.is_stopping_time.le_measurable_space_of_const_le MeasureTheory.IsStoppingTime.le_measurableSpace_of_const_le end Preorder instance sigmaFinite_stopping_time {ι} [SemilatticeSup ι] [OrderBot ι] [(Filter.atTop : Filter ι).IsCountablyGenerated] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) : SigmaFinite (μ.trim hτ.measurableSpace_le) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance #align measure_theory.is_stopping_time.sigma_finite_stopping_time MeasureTheory.IsStoppingTime.sigmaFinite_stopping_time instance sigmaFinite_stopping_time_of_le {ι} [SemilatticeSup ι] [OrderBot ι] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance #align measure_theory.is_stopping_time.sigma_finite_stopping_time_of_le MeasureTheory.IsStoppingTime.sigmaFinite_stopping_time_of_le section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} protected theorem measurableSet_le' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ i} := by intro j have : {ω : Ω | τ ω ≤ i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω ≤ min i j} := by ext1 ω; simp only [Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff] rw [this] exact f.mono (min_le_right i j) _ (hτ _) #align measure_theory.is_stopping_time.measurable_set_le' MeasureTheory.IsStoppingTime.measurableSet_le' protected theorem measurableSet_gt' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i < τ ω} := by have : {ω : Ω | i < τ ω} = {ω : Ω | τ ω ≤ i}ᶜ := by ext1 ω; simp rw [this] exact (hτ.measurableSet_le' i).compl #align measure_theory.is_stopping_time.measurable_set_gt' MeasureTheory.IsStoppingTime.measurableSet_gt' protected theorem measurableSet_eq' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq i #align measure_theory.is_stopping_time.measurable_set_eq' MeasureTheory.IsStoppingTime.measurableSet_eq' protected theorem measurableSet_ge' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq' i).union (hτ.measurableSet_gt' i) #align measure_theory.is_stopping_time.measurable_set_ge' MeasureTheory.IsStoppingTime.measurableSet_ge' protected theorem measurableSet_lt' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq' i) #align measure_theory.is_stopping_time.measurable_set_lt' MeasureTheory.IsStoppingTime.measurableSet_lt' section Countable protected theorem measurableSet_eq_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq_of_countable_range h_countable i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable_range' protected theorem measurableSet_eq_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable' MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable' protected theorem measurableSet_ge_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq_of_countable_range' h_countable i).union (hτ.measurableSet_gt' i) #align measure_theory.is_stopping_time.measurable_set_ge_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable_range' protected theorem measurableSet_ge_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_ge_of_countable' MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable' protected theorem measurableSet_lt_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq_of_countable_range' h_countable i) #align measure_theory.is_stopping_time.measurable_set_lt_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable_range' protected theorem measurableSet_lt_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_lt_of_countable' MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable' protected theorem measurableSpace_le_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i ∈ Set.range τ, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.biUnion h_countable fun i _ => f.le i _ (hs i) · ext ω constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, by simpa using hx⟩ · rintro ⟨i, hx⟩ simp only [Set.mem_range, Set.iUnion_exists, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, exists_and_right] at hx exact hx.2.1 #align measure_theory.is_stopping_time.measurable_space_le_of_countable_range MeasureTheory.IsStoppingTime.measurableSpace_le_of_countable_range end Countable protected theorem measurable [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] τ := @measurable_of_Iic ι Ω _ _ _ hτ.measurableSpace _ _ _ _ fun i => hτ.measurableSet_le' i #align measure_theory.is_stopping_time.measurable MeasureTheory.IsStoppingTime.measurable protected theorem measurable_of_le [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : Measurable[f i] τ := hτ.measurable.mono (measurableSpace_le_of_le_const _ hτ_le) le_rfl #align measure_theory.is_stopping_time.measurable_of_le MeasureTheory.IsStoppingTime.measurable_of_le theorem measurableSpace_min (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : (hτ.min hπ).measurableSpace = hτ.measurableSpace ⊓ hπ.measurableSpace := by refine le_antisymm ?_ ?_ · exact le_inf (measurableSpace_mono _ hτ fun _ => min_le_left _ _) (measurableSpace_mono _ hπ fun _ => min_le_right _ _) · intro s change MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s → MeasurableSet[(hτ.min hπ).measurableSpace] s simp_rw [IsStoppingTime.measurableSet] have : ∀ i, {ω | min (τ ω) (π ω) ≤ i} = {ω | τ ω ≤ i} ∪ {ω | π ω ≤ i} := by intro i; ext1 ω; simp simp_rw [this, Set.inter_union_distrib_left] exact fun h i => (h.left i).union (h.right i) #align measure_theory.is_stopping_time.measurable_space_min MeasureTheory.IsStoppingTime.measurableSpace_min theorem measurableSet_min_iff (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[(hτ.min hπ).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s := by rw [measurableSpace_min hτ hπ]; rfl #align measure_theory.is_stopping_time.measurable_set_min_iff MeasureTheory.IsStoppingTime.measurableSet_min_iff theorem measurableSpace_min_const (hτ : IsStoppingTime f τ) {i : ι} : (hτ.min_const i).measurableSpace = hτ.measurableSpace ⊓ f i := by rw [hτ.measurableSpace_min (isStoppingTime_const _ i), measurableSpace_const] #align measure_theory.is_stopping_time.measurable_space_min_const MeasureTheory.IsStoppingTime.measurableSpace_min_const theorem measurableSet_min_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) {i : ι} : MeasurableSet[(hτ.min_const i).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[f i] s := by rw [measurableSpace_min_const hτ]; apply MeasurableSpace.measurableSet_inf #align measure_theory.is_stopping_time.measurable_set_min_const_iff MeasureTheory.IsStoppingTime.measurableSet_min_const_iff theorem measurableSet_inter_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) (hs : MeasurableSet[hτ.measurableSpace] s) : MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by simp_rw [IsStoppingTime.measurableSet] at hs ⊢ intro i have : s ∩ {ω | τ ω ≤ π ω} ∩ {ω | min (τ ω) (π ω) ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | min (τ ω) (π ω) ≤ i} ∩ {ω | min (τ ω) i ≤ min (min (τ ω) (π ω)) i} := by ext1 ω simp only [min_le_iff, Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff, le_refl, true_and_iff, and_true_iff, true_or_iff, or_true_iff] by_cases hτi : τ ω ≤ i · simp only [hτi, true_or_iff, and_true_iff, and_congr_right_iff] intro constructor <;> intro h · exact Or.inl h · cases' h with h h · exact h · exact hτi.trans h simp only [hτi, false_or_iff, and_false_iff, false_and_iff, iff_false_iff, not_and, not_le, and_imp] refine fun _ hτ_le_π => lt_of_lt_of_le ?_ hτ_le_π rw [← not_le] exact hτi rw [this] refine ((hs i).inter ((hτ.min hπ) i)).inter ?_ apply @measurableSet_le _ _ _ _ _ (Filtration.seq f i) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const i).measurable_of_le fun _ => min_le_right _ _ · exact ((hτ.min hπ).min_const i).measurable_of_le fun _ => min_le_right _ _ #align measure_theory.is_stopping_time.measurable_set_inter_le MeasureTheory.IsStoppingTime.measurableSet_inter_le theorem measurableSet_inter_le_iff [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) ↔ MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by constructor <;> intro h · have : s ∩ {ω | τ ω ≤ π ω} = s ∩ {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ π ω} := by rw [Set.inter_assoc, Set.inter_self] rw [this] exact measurableSet_inter_le _ hπ _ h · rw [measurableSet_min_iff hτ hπ] at h exact h.1 #align measure_theory.is_stopping_time.measurable_set_inter_le_iff MeasureTheory.IsStoppingTime.measurableSet_inter_le_iff theorem measurableSet_inter_le_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ i}) ↔ MeasurableSet[(hτ.min_const i).measurableSpace] (s ∩ {ω | τ ω ≤ i}) := by rw [IsStoppingTime.measurableSet_min_iff hτ (isStoppingTime_const _ i), IsStoppingTime.measurableSpace_const, IsStoppingTime.measurableSet] refine ⟨fun h => ⟨h, ?_⟩, fun h j => h.1 j⟩ specialize h i rwa [Set.inter_assoc, Set.inter_self] at h #align measure_theory.is_stopping_time.measurable_set_inter_le_const_iff MeasureTheory.IsStoppingTime.measurableSet_inter_le_const_iff theorem measurableSet_le_stopping_time [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j ≤ min (π ω) j} ∩ {ω | τ ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, min_le_iff, le_min_iff, le_refl, and_true_iff, and_congr_left_iff] intro h simp only [h, or_self_iff, and_true_iff] rw [Iff.comm, or_iff_left_iff_imp] exact h.trans rw [this] refine MeasurableSet.inter ?_ (hτ.measurableSet_le j) apply @measurableSet_le _ _ _ _ _ (Filtration.seq f j) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ #align measure_theory.is_stopping_time.measurable_set_le_stopping_time MeasureTheory.IsStoppingTime.measurableSet_le_stopping_time theorem measurableSet_stopping_time_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hπ.measurableSpace] {ω | τ ω ≤ π ω} := by suffices MeasurableSet[(hτ.min hπ).measurableSpace] {ω : Ω | τ ω ≤ π ω} by rw [measurableSet_min_iff hτ hπ] at this; exact this.2 rw [← Set.univ_inter {ω : Ω | τ ω ≤ π ω}, ← hτ.measurableSet_inter_le_iff hπ, Set.univ_inter] exact measurableSet_le_stopping_time hτ hπ #align measure_theory.is_stopping_time.measurable_set_stopping_time_le MeasureTheory.IsStoppingTime.measurableSet_stopping_time_le
Mathlib/Probability/Process/Stopping.lean
703
724
theorem measurableSet_eq_stopping_time [AddGroup ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] [MeasurableSub₂ ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by
rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · cases' h with h' hσ_le cases' h' with h_eq hτ_le rwa [min_eq_left hτ_le, min_eq_left hσ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Kernel.CondDistrib #align_import probability.kernel.condexp from "leanprover-community/mathlib"@"00abe0695d8767201e6d008afa22393978bb324d" /-! # Kernel associated with a conditional expectation We define `condexpKernel μ m`, a kernel from `Ω` to `Ω` such that for all integrable functions `f`, `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. This kernel is defined if `Ω` is a standard Borel space. In general, `μ⟦s | m⟧` maps a measurable set `s` to a function `Ω → ℝ≥0∞`, and for all `s` that map is unique up to a `μ`-null set. For all `a`, the map from sets to `ℝ≥0∞` that we obtain that way verifies some of the properties of a measure, but the fact that the `μ`-null set depends on `s` can prevent us from finding versions of the conditional expectation that combine into a true measure. The standard Borel space assumption on `Ω` allows us to do so. ## Main definitions * `condexpKernel μ m`: kernel such that `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. ## Main statements * `condexp_ae_eq_integral_condexpKernel`: `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped ENNReal MeasureTheory ProbabilityTheory namespace ProbabilityTheory section AuxLemmas variable {Ω F : Type*} {m mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → F} theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id [TopologicalSpace F] (hm : m ≤ mΩ) (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x : Ω × Ω => f x.2) (@Measure.map Ω (Ω × Ω) (m.prod mΩ) mΩ (fun ω => (id ω, id ω)) μ) := by rw [← aestronglyMeasurable_comp_snd_map_prod_mk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf #align measure_theory.ae_strongly_measurable.comp_snd_map_prod_id MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id theorem _root_.MeasureTheory.Integrable.comp_snd_map_prod_id [NormedAddCommGroup F] (hm : m ≤ mΩ) (hf : Integrable f μ) : Integrable (fun x : Ω × Ω => f x.2) (@Measure.map Ω (Ω × Ω) (m.prod mΩ) mΩ (fun ω => (id ω, id ω)) μ) := by rw [← integrable_comp_snd_map_prod_mk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf #align measure_theory.integrable.comp_snd_map_prod_id MeasureTheory.Integrable.comp_snd_map_prod_id end AuxLemmas variable {Ω F : Type*} {m : MeasurableSpace Ω} [mΩ : MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] {μ : Measure Ω} [IsFiniteMeasure μ] /-- Kernel associated with the conditional expectation with respect to a σ-algebra. It satisfies `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. It is defined as the conditional distribution of the identity given the identity, where the second identity is understood as a map from `Ω` with the σ-algebra `mΩ` to `Ω` with σ-algebra `m ⊓ mΩ`. We use `m ⊓ mΩ` instead of `m` to ensure that it is a sub-σ-algebra of `mΩ`. We then use `kernel.comap` to get a kernel from `m` to `mΩ` instead of from `m ⊓ mΩ` to `mΩ`. -/ noncomputable irreducible_def condexpKernel (μ : Measure Ω) [IsFiniteMeasure μ] (m : MeasurableSpace Ω) : @kernel Ω Ω m mΩ := kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id (measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m)) #align probability_theory.condexp_kernel ProbabilityTheory.condexpKernel lemma condexpKernel_apply_eq_condDistrib {ω : Ω} : condexpKernel μ m ω = @condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _ (id ω) := by simp_rw [condexpKernel, kernel.comap_apply] instance : IsMarkovKernel (condexpKernel μ m) := by simp only [condexpKernel]; infer_instance section Measurability variable [NormedAddCommGroup F] {f : Ω → F} theorem measurable_condexpKernel {s : Set Ω} (hs : MeasurableSet s) : Measurable[m] fun ω => condexpKernel μ m ω s := by simp_rw [condexpKernel_apply_eq_condDistrib] refine Measurable.mono ?_ (inf_le_left : m ⊓ mΩ ≤ m) le_rfl convert measurable_condDistrib (μ := μ) hs rw [MeasurableSpace.comap_id] #align probability_theory.measurable_condexp_kernel ProbabilityTheory.measurable_condexpKernel theorem stronglyMeasurable_condexpKernel {s : Set Ω} (hs : MeasurableSet s) : StronglyMeasurable[m] fun ω => condexpKernel μ m ω s := Measurable.stronglyMeasurable (measurable_condexpKernel hs) theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condexpKernel [NormedSpace ℝ F] (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun ω => ∫ y, f y ∂condexpKernel μ m ω) μ := by simp_rw [condexpKernel_apply_eq_condDistrib] exact AEStronglyMeasurable.integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf.comp_snd_map_prod_id inf_le_right) #align measure_theory.ae_strongly_measurable.integral_condexp_kernel MeasureTheory.AEStronglyMeasurable.integral_condexpKernel theorem aestronglyMeasurable'_integral_condexpKernel [NormedSpace ℝ F] (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable' m (fun ω => ∫ y, f y ∂condexpKernel μ m ω) μ := by rw [condexpKernel] have h := aestronglyMeasurable'_integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) rw [MeasurableSpace.comap_id] at h exact AEStronglyMeasurable'.mono h inf_le_left #align probability_theory.ae_strongly_measurable'_integral_condexp_kernel ProbabilityTheory.aestronglyMeasurable'_integral_condexpKernel end Measurability section Integrability variable [NormedAddCommGroup F] {f : Ω → F} theorem _root_.MeasureTheory.Integrable.condexpKernel_ae (hf_int : Integrable f μ) : ∀ᵐ ω ∂μ, Integrable f (condexpKernel μ m ω) := by rw [condexpKernel] convert Integrable.condDistrib_ae (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 #align measure_theory.integrable.condexp_kernel_ae MeasureTheory.Integrable.condexpKernel_ae theorem _root_.MeasureTheory.Integrable.integral_norm_condexpKernel (hf_int : Integrable f μ) : Integrable (fun ω => ∫ y, ‖f y‖ ∂condexpKernel μ m ω) μ := by rw [condexpKernel] convert Integrable.integral_norm_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 #align measure_theory.integrable.integral_norm_condexp_kernel MeasureTheory.Integrable.integral_norm_condexpKernel theorem _root_.MeasureTheory.Integrable.norm_integral_condexpKernel [NormedSpace ℝ F] (hf_int : Integrable f μ) : Integrable (fun ω => ‖∫ y, f y ∂condexpKernel μ m ω‖) μ := by rw [condexpKernel] convert Integrable.norm_integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 #align measure_theory.integrable.norm_integral_condexp_kernel MeasureTheory.Integrable.norm_integral_condexpKernel theorem _root_.MeasureTheory.Integrable.integral_condexpKernel [NormedSpace ℝ F] (hf_int : Integrable f μ) : Integrable (fun ω => ∫ y, f y ∂condexpKernel μ m ω) μ := by rw [condexpKernel] convert Integrable.integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 #align measure_theory.integrable.integral_condexp_kernel MeasureTheory.Integrable.integral_condexpKernel theorem integrable_toReal_condexpKernel {s : Set Ω} (hs : MeasurableSet s) : Integrable (fun ω => (condexpKernel μ m ω s).toReal) μ := by rw [condexpKernel] exact integrable_toReal_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) hs #align probability_theory.integrable_to_real_condexp_kernel ProbabilityTheory.integrable_toReal_condexpKernel end Integrability lemma condexpKernel_ae_eq_condexp' [IsFiniteMeasure μ] {s : Set Ω} (hs : MeasurableSet s) : (fun ω ↦ (condexpKernel μ m ω s).toReal) =ᵐ[μ] μ⟦s | m ⊓ mΩ⟧ := by have h := condDistrib_ae_eq_condexp (μ := μ) (measurable_id'' (inf_le_right : m ⊓ mΩ ≤ mΩ)) measurable_id hs simp only [id_eq, ge_iff_le, MeasurableSpace.comap_id, preimage_id_eq] at h simp_rw [condexpKernel_apply_eq_condDistrib] exact h lemma condexpKernel_ae_eq_condexp [IsFiniteMeasure μ] (hm : m ≤ mΩ) {s : Set Ω} (hs : MeasurableSet s) : (fun ω ↦ (condexpKernel μ m ω s).toReal) =ᵐ[μ] μ⟦s | m⟧ := (condexpKernel_ae_eq_condexp' hs).trans (by rw [inf_of_le_left hm]) lemma condexpKernel_ae_eq_trim_condexp [IsFiniteMeasure μ] (hm : m ≤ mΩ) {s : Set Ω} (hs : MeasurableSet s) : (fun ω ↦ (condexpKernel μ m ω s).toReal) =ᵐ[μ.trim hm] μ⟦s | m⟧ := by rw [ae_eq_trim_iff hm _ stronglyMeasurable_condexp] · exact condexpKernel_ae_eq_condexp hm hs · refine Measurable.stronglyMeasurable ?_ exact @Measurable.ennreal_toReal _ m _ (measurable_condexpKernel hs)
Mathlib/Probability/Kernel/Condexp.lean
188
194
theorem condexp_ae_eq_integral_condexpKernel' [NormedAddCommGroup F] {f : Ω → F} [NormedSpace ℝ F] [CompleteSpace F] (hf_int : Integrable f μ) : μ[f|m ⊓ mΩ] =ᵐ[μ] fun ω => ∫ y, f y ∂condexpKernel μ m ω := by
have hX : @Measurable Ω Ω mΩ (m ⊓ mΩ) id := measurable_id.mono le_rfl (inf_le_right : m ⊓ mΩ ≤ mΩ) simp_rw [condexpKernel_apply_eq_condDistrib] have h := condexp_ae_eq_integral_condDistrib_id hX hf_int simpa only [MeasurableSpace.comap_id, id_eq] using h
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.DiscreteCategory import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Terminal #align_import category_theory.limits.shapes.binary_products from "leanprover-community/mathlib"@"fec1d95fc61c750c1ddbb5b1f7f48b8e811a80d7" /-! # Binary (co)products We define a category `WalkingPair`, which is the index category for a binary (co)product diagram. A convenience method `pair X Y` constructs the functor from the walking pair, hitting the given objects. We define `prod X Y` and `coprod X Y` as limits and colimits of such functors. Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence of (co)limits shaped as walking pairs. We include lemmas for simplifying equations involving projections and coprojections, and define braiding and associating isomorphisms, and the product comparison morphism. ## References * [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R) * [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN) -/ noncomputable section universe v u u₂ open CategoryTheory namespace CategoryTheory.Limits /-- The type of objects for the diagram indexing a binary (co)product. -/ inductive WalkingPair : Type | left | right deriving DecidableEq, Inhabited #align category_theory.limits.walking_pair CategoryTheory.Limits.WalkingPair open WalkingPair /-- The equivalence swapping left and right. -/ def WalkingPair.swap : WalkingPair ≃ WalkingPair where toFun j := WalkingPair.recOn j right left invFun j := WalkingPair.recOn j right left left_inv j := by cases j; repeat rfl right_inv j := by cases j; repeat rfl #align category_theory.limits.walking_pair.swap CategoryTheory.Limits.WalkingPair.swap @[simp] theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right := rfl #align category_theory.limits.walking_pair.swap_apply_left CategoryTheory.Limits.WalkingPair.swap_apply_left @[simp] theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left := rfl #align category_theory.limits.walking_pair.swap_apply_right CategoryTheory.Limits.WalkingPair.swap_apply_right @[simp] theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right := rfl #align category_theory.limits.walking_pair.swap_symm_apply_tt CategoryTheory.Limits.WalkingPair.swap_symm_apply_tt @[simp] theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left := rfl #align category_theory.limits.walking_pair.swap_symm_apply_ff CategoryTheory.Limits.WalkingPair.swap_symm_apply_ff /-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits. -/ def WalkingPair.equivBool : WalkingPair ≃ Bool where toFun j := WalkingPair.recOn j true false -- to match equiv.sum_equiv_sigma_bool invFun b := Bool.recOn b right left left_inv j := by cases j; repeat rfl right_inv b := by cases b; repeat rfl #align category_theory.limits.walking_pair.equiv_bool CategoryTheory.Limits.WalkingPair.equivBool @[simp] theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true := rfl #align category_theory.limits.walking_pair.equiv_bool_apply_left CategoryTheory.Limits.WalkingPair.equivBool_apply_left @[simp] theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false := rfl #align category_theory.limits.walking_pair.equiv_bool_apply_right CategoryTheory.Limits.WalkingPair.equivBool_apply_right @[simp] theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left := rfl #align category_theory.limits.walking_pair.equiv_bool_symm_apply_tt CategoryTheory.Limits.WalkingPair.equivBool_symm_apply_true @[simp] theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right := rfl #align category_theory.limits.walking_pair.equiv_bool_symm_apply_ff CategoryTheory.Limits.WalkingPair.equivBool_symm_apply_false variable {C : Type u} /-- The function on the walking pair, sending the two points to `X` and `Y`. -/ def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y #align category_theory.limits.pair_function CategoryTheory.Limits.pairFunction @[simp] theorem pairFunction_left (X Y : C) : pairFunction X Y left = X := rfl #align category_theory.limits.pair_function_left CategoryTheory.Limits.pairFunction_left @[simp] theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y := rfl #align category_theory.limits.pair_function_right CategoryTheory.Limits.pairFunction_right variable [Category.{v} C] /-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/ def pair (X Y : C) : Discrete WalkingPair ⥤ C := Discrete.functor fun j => WalkingPair.casesOn j X Y #align category_theory.limits.pair CategoryTheory.Limits.pair @[simp] theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X := rfl #align category_theory.limits.pair_obj_left CategoryTheory.Limits.pair_obj_left @[simp] theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y := rfl #align category_theory.limits.pair_obj_right CategoryTheory.Limits.pair_obj_right section variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- The natural transformation between two functors out of the walking pair, specified by its components. -/ def mapPair : F ⟶ G where app j := Discrete.recOn j fun j => WalkingPair.casesOn j f g naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat #align category_theory.limits.map_pair CategoryTheory.Limits.mapPair @[simp] theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f := rfl #align category_theory.limits.map_pair_left CategoryTheory.Limits.mapPair_left @[simp] theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g := rfl #align category_theory.limits.map_pair_right CategoryTheory.Limits.mapPair_right /-- The natural isomorphism between two functors out of the walking pair, specified by its components. -/ @[simps!] def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G := NatIso.ofComponents (fun j => Discrete.recOn j fun j => WalkingPair.casesOn j f g) (fun ⟨⟨u⟩⟩ => by aesop_cat) #align category_theory.limits.map_pair_iso CategoryTheory.Limits.mapPairIso end /-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/ @[simps!] def diagramIsoPair (F : Discrete WalkingPair ⥤ C) : F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) := mapPairIso (Iso.refl _) (Iso.refl _) #align category_theory.limits.diagram_iso_pair CategoryTheory.Limits.diagramIsoPair section variable {D : Type u} [Category.{v} D] /-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/ def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) := diagramIsoPair _ #align category_theory.limits.pair_comp CategoryTheory.Limits.pairComp end /-- A binary fan is just a cone on a diagram indexing a product. -/ abbrev BinaryFan (X Y : C) := Cone (pair X Y) #align category_theory.limits.binary_fan CategoryTheory.Limits.BinaryFan /-- The first projection of a binary fan. -/ abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.left⟩ #align category_theory.limits.binary_fan.fst CategoryTheory.Limits.BinaryFan.fst /-- The second projection of a binary fan. -/ abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_fan.snd CategoryTheory.Limits.BinaryFan.snd @[simp] theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst := rfl #align category_theory.limits.binary_fan.π_app_left CategoryTheory.Limits.BinaryFan.π_app_left @[simp] theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd := rfl #align category_theory.limits.binary_fan.π_app_right CategoryTheory.Limits.BinaryFan.π_app_right /-- A convenient way to show that a binary fan is a limit. -/ def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y) (lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt) (hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f) (hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g) (uniq : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g), m = lift f g) : IsLimit s := Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t)) (by rintro t (rfl | rfl) · exact hl₁ _ _ · exact hl₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) #align category_theory.limits.binary_fan.is_limit.mk CategoryTheory.Limits.BinaryFan.IsLimit.mk theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt} (h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ #align category_theory.limits.binary_fan.is_limit.hom_ext CategoryTheory.Limits.BinaryFan.IsLimit.hom_ext /-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/ abbrev BinaryCofan (X Y : C) := Cocone (pair X Y) #align category_theory.limits.binary_cofan CategoryTheory.Limits.BinaryCofan /-- The first inclusion of a binary cofan. -/ abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩ #align category_theory.limits.binary_cofan.inl CategoryTheory.Limits.BinaryCofan.inl /-- The second inclusion of a binary cofan. -/ abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_cofan.inr CategoryTheory.Limits.BinaryCofan.inr @[simp] theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl #align category_theory.limits.binary_cofan.ι_app_left CategoryTheory.Limits.BinaryCofan.ι_app_left @[simp] theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl #align category_theory.limits.binary_cofan.ι_app_right CategoryTheory.Limits.BinaryCofan.ι_app_right /-- A convenient way to show that a binary cofan is a colimit. -/ def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y) (desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T) (hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f) (hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g) (uniq : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g), m = desc f g) : IsColimit s := Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t)) (by rintro t (rfl | rfl) · exact hd₁ _ _ · exact hd₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) #align category_theory.limits.binary_cofan.is_colimit.mk CategoryTheory.Limits.BinaryCofan.IsColimit.mk theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) {f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ #align category_theory.limits.binary_cofan.is_colimit.hom_ext CategoryTheory.Limits.BinaryCofan.IsColimit.hom_ext variable {X Y : C} section attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/ @[simps pt] def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where pt := P π := { app := fun ⟨j⟩ => by cases j <;> simpa } #align category_theory.limits.binary_fan.mk CategoryTheory.Limits.BinaryFan.mk /-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/ @[simps pt] def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where pt := P ι := { app := fun ⟨j⟩ => by cases j <;> simpa } #align category_theory.limits.binary_cofan.mk CategoryTheory.Limits.BinaryCofan.mk end @[simp] theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ := rfl #align category_theory.limits.binary_fan.mk_fst CategoryTheory.Limits.BinaryFan.mk_fst @[simp] theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ := rfl #align category_theory.limits.binary_fan.mk_snd CategoryTheory.Limits.BinaryFan.mk_snd @[simp] theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ := rfl #align category_theory.limits.binary_cofan.mk_inl CategoryTheory.Limits.BinaryCofan.mk_inl @[simp] theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ := rfl #align category_theory.limits.binary_cofan.mk_inr CategoryTheory.Limits.BinaryCofan.mk_inr /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd := Cones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp #align category_theory.limits.iso_binary_fan_mk CategoryTheory.Limits.isoBinaryFanMk /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr := Cocones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp #align category_theory.limits.iso_binary_cofan_mk CategoryTheory.Limits.isoBinaryCofanMk /-- This is a more convenient formulation to show that a `BinaryFan` constructed using `BinaryFan.mk` is a limit cone. -/ def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W) (fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst) (fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd) (uniq : ∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (BinaryFan.mk fst snd) := { lift := lift fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } #align category_theory.limits.binary_fan.is_limit_mk CategoryTheory.Limits.BinaryFan.isLimitMk /-- This is a more convenient formulation to show that a `BinaryCofan` constructed using `BinaryCofan.mk` is a colimit cocone. -/ def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W} (desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt) (fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl) (fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr) (uniq : ∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (BinaryCofan.mk inl inr) := { desc := desc fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } #align category_theory.limits.binary_cofan.is_colimit_mk CategoryTheory.Limits.BinaryCofan.isColimitMk /-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`. -/ @[simps] def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } := ⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩ #align category_theory.limits.binary_fan.is_limit.lift' CategoryTheory.Limits.BinaryFan.IsLimit.lift' /-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`. -/ @[simps] def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W) (g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } := ⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩ #align category_theory.limits.binary_cofan.is_colimit.desc' CategoryTheory.Limits.BinaryCofan.IsColimit.desc' /-- Binary products are symmetric. -/ def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) : IsLimit (BinaryFan.mk c.snd c.fst) := BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryFan.IsLimit.hom_ext hc (e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm) #align category_theory.limits.binary_fan.is_limit_flip CategoryTheory.Limits.BinaryFan.isLimitFlip theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.fst := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X) exact ⟨⟨l, BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _) (h.hom_ext _ _), hl⟩⟩ · intro exact ⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩ #align category_theory.limits.binary_fan.is_limit_iff_is_iso_fst CategoryTheory.Limits.BinaryFan.isLimit_iff_isIso_fst theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.snd := by refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst)) exact ⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h => ⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩ #align category_theory.limits.binary_fan.is_limit_iff_is_iso_snd CategoryTheory.Limits.BinaryFan.isLimit_iff_isIso_snd /-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/ noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by fapply BinaryFan.isLimitMk · exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd) · intro s -- Porting note: simp timed out here simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id, BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc] · intro s -- Porting note: simp timed out here simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac] · intro s m e₁ e₂ -- Porting note: simpa timed out here also apply BinaryFan.IsLimit.hom_ext h · simpa only [BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv] · simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac] #align category_theory.limits.binary_fan.is_limit_comp_left_iso CategoryTheory.Limits.BinaryFan.isLimitCompLeftIso /-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/ noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) := BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h) #align category_theory.limits.binary_fan.is_limit_comp_right_iso CategoryTheory.Limits.BinaryFan.isLimitCompRightIso /-- Binary coproducts are symmetric. -/ def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) : IsColimit (BinaryCofan.mk c.inr c.inl) := BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryCofan.IsColimit.hom_ext hc (e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm) #align category_theory.limits.binary_cofan.is_colimit_flip CategoryTheory.Limits.BinaryCofan.isColimitFlip theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inl := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X) refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩ rw [Category.comp_id] have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl rwa [Category.assoc,Category.id_comp] at e · intro exact ⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f) (fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => (IsIso.eq_inv_comp _).mpr e⟩ #align category_theory.limits.binary_cofan.is_colimit_iff_is_iso_inl CategoryTheory.Limits.BinaryCofan.isColimit_iff_isIso_inl theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inr := by refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl)) exact ⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h => ⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩ #align category_theory.limits.binary_cofan.is_colimit_iff_is_iso_inr CategoryTheory.Limits.BinaryCofan.isColimit_iff_isIso_inr /-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/ noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by fapply BinaryCofan.isColimitMk · exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr) · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] · intro s m e₁ e₂ apply BinaryCofan.IsColimit.hom_ext h · rw [← cancel_epi f] -- Porting note: simp timed out here too simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁ -- Porting note: simp timed out here too · simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] #align category_theory.limits.binary_cofan.is_colimit_comp_left_iso CategoryTheory.Limits.BinaryCofan.isColimitCompLeftIso /-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/ noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) := BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h) #align category_theory.limits.binary_cofan.is_colimit_comp_right_iso CategoryTheory.Limits.BinaryCofan.isColimitCompRightIso /-- An abbreviation for `HasLimit (pair X Y)`. -/ abbrev HasBinaryProduct (X Y : C) := HasLimit (pair X Y) #align category_theory.limits.has_binary_product CategoryTheory.Limits.HasBinaryProduct /-- An abbreviation for `HasColimit (pair X Y)`. -/ abbrev HasBinaryCoproduct (X Y : C) := HasColimit (pair X Y) #align category_theory.limits.has_binary_coproduct CategoryTheory.Limits.HasBinaryCoproduct /-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or `X ⨯ Y`. -/ abbrev prod (X Y : C) [HasBinaryProduct X Y] := limit (pair X Y) #align category_theory.limits.prod CategoryTheory.Limits.prod /-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or `X ⨿ Y`. -/ abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] := colimit (pair X Y) #align category_theory.limits.coprod CategoryTheory.Limits.coprod /-- Notation for the product -/ notation:20 X " ⨯ " Y:20 => prod X Y /-- Notation for the coproduct -/ notation:20 X " ⨿ " Y:20 => coprod X Y /-- The projection map to the first component of the product. -/ abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X := limit.π (pair X Y) ⟨WalkingPair.left⟩ #align category_theory.limits.prod.fst CategoryTheory.Limits.prod.fst /-- The projection map to the second component of the product. -/ abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y := limit.π (pair X Y) ⟨WalkingPair.right⟩ #align category_theory.limits.prod.snd CategoryTheory.Limits.prod.snd /-- The inclusion map from the first component of the coproduct. -/ abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.left⟩ #align category_theory.limits.coprod.inl CategoryTheory.Limits.coprod.inl /-- The inclusion map from the second component of the coproduct. -/ abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.right⟩ #align category_theory.limits.coprod.inr CategoryTheory.Limits.coprod.inr /-- The binary fan constructed from the projection maps is a limit. -/ def prodIsProd (X Y : C) [HasBinaryProduct X Y] : IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) := (limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.id_comp]; rfl · dsimp; simp only [Category.id_comp]; rfl )) #align category_theory.limits.prod_is_prod CategoryTheory.Limits.prodIsProd /-- The binary cofan constructed from the coprojection maps is a colimit. -/ def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] : IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) := (colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.comp_id] · dsimp; simp only [Category.comp_id] )) #align category_theory.limits.coprod_is_coprod CategoryTheory.Limits.coprodIsCoprod @[ext 1100] theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y} (h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g := BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂ #align category_theory.limits.prod.hom_ext CategoryTheory.Limits.prod.hom_ext @[ext 1100] theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W} (h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂ #align category_theory.limits.coprod.hom_ext CategoryTheory.Limits.coprod.hom_ext /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/ abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y := limit.lift _ (BinaryFan.mk f g) #align category_theory.limits.prod.lift CategoryTheory.Limits.prod.lift /-- diagonal arrow of the binary product in the category `fam I` -/ abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X := prod.lift (𝟙 _) (𝟙 _) #align category_theory.limits.diag CategoryTheory.Limits.diag /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/ abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W := colimit.desc _ (BinaryCofan.mk f g) #align category_theory.limits.coprod.desc CategoryTheory.Limits.coprod.desc /-- codiagonal arrow of the binary coproduct -/ abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X := coprod.desc (𝟙 _) (𝟙 _) #align category_theory.limits.codiag CategoryTheory.Limits.codiag -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.fst = f := limit.lift_π _ _ #align category_theory.limits.prod.lift_fst CategoryTheory.Limits.prod.lift_fst #align category_theory.limits.prod.lift_fst_assoc CategoryTheory.Limits.prod.lift_fst_assoc -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.snd = g := limit.lift_π _ _ #align category_theory.limits.prod.lift_snd CategoryTheory.Limits.prod.lift_snd #align category_theory.limits.prod.lift_snd_assoc CategoryTheory.Limits.prod.lift_snd_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inl ≫ coprod.desc f g = f := colimit.ι_desc _ _ #align category_theory.limits.coprod.inl_desc CategoryTheory.Limits.coprod.inl_desc #align category_theory.limits.coprod.inl_desc_assoc CategoryTheory.Limits.coprod.inl_desc_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inr ≫ coprod.desc f g = g := colimit.ι_desc _ _ #align category_theory.limits.coprod.inr_desc CategoryTheory.Limits.coprod.inr_desc #align category_theory.limits.coprod.inr_desc_assoc CategoryTheory.Limits.coprod.inr_desc_assoc instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_fst _ _ #align category_theory.limits.prod.mono_lift_of_mono_left CategoryTheory.Limits.prod.mono_lift_of_mono_left instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_snd _ _ #align category_theory.limits.prod.mono_lift_of_mono_right CategoryTheory.Limits.prod.mono_lift_of_mono_right instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inl_desc _ _ #align category_theory.limits.coprod.epi_desc_of_epi_left CategoryTheory.Limits.coprod.epi_desc_of_epi_left instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inr_desc _ _ #align category_theory.limits.coprod.epi_desc_of_epi_right CategoryTheory.Limits.coprod.epi_desc_of_epi_right /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/ def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } := ⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩ #align category_theory.limits.prod.lift' CategoryTheory.Limits.prod.lift' /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and `coprod.inr ≫ l = g`. -/ def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : { l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } := ⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩ #align category_theory.limits.coprod.desc' CategoryTheory.Limits.coprod.desc' /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/ def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z := limMap (mapPair f g) #align category_theory.limits.prod.map CategoryTheory.Limits.prod.map /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/ def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z := colimMap (mapPair f g) #align category_theory.limits.coprod.map CategoryTheory.Limits.coprod.map section ProdLemmas -- Making the reassoc version of this a simp lemma seems to be more harmful than helpful. @[reassoc, simp] theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) : f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp #align category_theory.limits.prod.comp_lift CategoryTheory.Limits.prod.comp_lift #align category_theory.limits.prod.comp_lift_assoc CategoryTheory.Limits.prod.comp_lift_assoc theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) : f ≫ diag Y = prod.lift f f := by simp #align category_theory.limits.prod.comp_diag CategoryTheory.Limits.prod.comp_diag @[reassoc (attr := simp)] theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f := limMap_π _ _ #align category_theory.limits.prod.map_fst CategoryTheory.Limits.prod.map_fst #align category_theory.limits.prod.map_fst_assoc CategoryTheory.Limits.prod.map_fst_assoc @[reassoc (attr := simp)] theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g := limMap_π _ _ #align category_theory.limits.prod.map_snd CategoryTheory.Limits.prod.map_snd #align category_theory.limits.prod.map_snd_assoc CategoryTheory.Limits.prod.map_snd_assoc @[simp] theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp #align category_theory.limits.prod.map_id_id CategoryTheory.Limits.prod.map_id_id @[simp] theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] : prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp #align category_theory.limits.prod.lift_fst_snd CategoryTheory.Limits.prod.lift_fst_snd @[reassoc (attr := simp)] theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W) (g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) : prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.prod.lift_map CategoryTheory.Limits.prod.lift_map #align category_theory.limits.prod.lift_map_assoc CategoryTheory.Limits.prod.lift_map_assoc @[simp] theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by rw [← prod.lift_map] simp #align category_theory.limits.prod.lift_fst_comp_snd_comp CategoryTheory.Limits.prod.lift_fst_comp_snd_comp -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just -- as well. @[reassoc (attr := simp)] theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂] [HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.prod.map_map CategoryTheory.Limits.prod.map_map #align category_theory.limits.prod.map_map_assoc CategoryTheory.Limits.prod.map_map_assoc -- TODO: is it necessary to weaken the assumption here? @[reassoc] theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasLimitsOfShape (Discrete WalkingPair) C] : prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp #align category_theory.limits.prod.map_swap CategoryTheory.Limits.prod.map_swap #align category_theory.limits.prod.map_swap_assoc CategoryTheory.Limits.prod.map_swap_assoc @[reassoc] theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W] [HasBinaryProduct Z W] [HasBinaryProduct Y W] : prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp #align category_theory.limits.prod.map_comp_id CategoryTheory.Limits.prod.map_comp_id #align category_theory.limits.prod.map_comp_id_assoc CategoryTheory.Limits.prod.map_comp_id_assoc @[reassoc] theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X] [HasBinaryProduct W Y] [HasBinaryProduct W Z] : prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp #align category_theory.limits.prod.map_id_comp CategoryTheory.Limits.prod.map_id_comp #align category_theory.limits.prod.map_id_comp_assoc CategoryTheory.Limits.prod.map_id_comp_assoc /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/ @[simps] def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where hom := prod.map f.hom g.hom inv := prod.map f.inv g.inv #align category_theory.limits.prod.map_iso CategoryTheory.Limits.prod.mapIso instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) := (prod.mapIso (asIso f) (asIso g)).isIso_hom #align category_theory.limits.is_iso_prod CategoryTheory.Limits.isIso_prod instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_mono f] simpa using congr_arg (fun f => f ≫ prod.fst) h · rw [← cancel_mono g] simpa using congr_arg (fun f => f ≫ prod.snd) h⟩ #align category_theory.limits.prod.map_mono CategoryTheory.Limits.prod.map_mono @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] : diag X ≫ prod.map f f = f ≫ diag Y := by simp #align category_theory.limits.prod.diag_map CategoryTheory.Limits.prod.diag_map #align category_theory.limits.prod.diag_map_assoc CategoryTheory.Limits.prod.diag_map_assoc @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] : diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp #align category_theory.limits.prod.diag_map_fst_snd CategoryTheory.Limits.prod.diag_map_fst_snd #align category_theory.limits.prod.diag_map_fst_snd_assoc CategoryTheory.Limits.prod.diag_map_fst_snd_assoc @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp #align category_theory.limits.prod.diag_map_fst_snd_comp CategoryTheory.Limits.prod.diag_map_fst_snd_comp #align category_theory.limits.prod.diag_map_fst_snd_comp_assoc CategoryTheory.Limits.prod.diag_map_fst_snd_comp_assoc instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) := IsSplitMono.mk' { retraction := prod.fst } end ProdLemmas section CoprodLemmas -- @[reassoc (attr := simp)] @[simp] -- Porting note: removing reassoc tag since result is not hygienic (two h's) theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by ext <;> simp #align category_theory.limits.coprod.desc_comp CategoryTheory.Limits.coprod.desc_comp -- Porting note: hand generated reassoc here. Simp can prove it theorem coprod.desc_comp_assoc {C : Type u} [Category C] {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) {Z : C} (l : W ⟶ Z) : coprod.desc g h ≫ f ≫ l = coprod.desc (g ≫ f) (h ≫ f) ≫ l := by simp #align category_theory.limits.coprod.desc_comp_assoc CategoryTheory.Limits.coprod.desc_comp theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) : codiag X ≫ f = coprod.desc f f := by simp #align category_theory.limits.coprod.diag_comp CategoryTheory.Limits.coprod.diag_comp @[reassoc (attr := simp)] theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl := ι_colimMap _ _ #align category_theory.limits.coprod.inl_map CategoryTheory.Limits.coprod.inl_map #align category_theory.limits.coprod.inl_map_assoc CategoryTheory.Limits.coprod.inl_map_assoc @[reassoc (attr := simp)] theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr := ι_colimMap _ _ #align category_theory.limits.coprod.inr_map CategoryTheory.Limits.coprod.inr_map #align category_theory.limits.coprod.inr_map_assoc CategoryTheory.Limits.coprod.inr_map_assoc @[simp] theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp #align category_theory.limits.coprod.map_id_id CategoryTheory.Limits.coprod.map_id_id @[simp] theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] : coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp #align category_theory.limits.coprod.desc_inl_inr CategoryTheory.Limits.coprod.desc_inl_inr -- The simp linter says simp can prove the reassoc version of this lemma. @[reassoc, simp] theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V] (f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) : coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by ext <;> simp #align category_theory.limits.coprod.map_desc CategoryTheory.Limits.coprod.map_desc #align category_theory.limits.coprod.map_desc_assoc CategoryTheory.Limits.coprod.map_desc_assoc @[simp] theorem coprod.desc_comp_inl_comp_inr {W X Y Z : C} [HasBinaryCoproduct W Y] [HasBinaryCoproduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : coprod.desc (g ≫ coprod.inl) (g' ≫ coprod.inr) = coprod.map g g' := by rw [← coprod.map_desc]; simp #align category_theory.limits.coprod.desc_comp_inl_comp_inr CategoryTheory.Limits.coprod.desc_comp_inl_comp_inr -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `inl_map` and `inr_map` can still work just -- as well. @[reassoc (attr := simp)] theorem coprod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryCoproduct A₁ B₁] [HasBinaryCoproduct A₂ B₂] [HasBinaryCoproduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : coprod.map f g ≫ coprod.map h k = coprod.map (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.coprod.map_map CategoryTheory.Limits.coprod.map_map #align category_theory.limits.coprod.map_map_assoc CategoryTheory.Limits.coprod.map_map_assoc -- I don't think it's a good idea to make any of the following three simp lemmas. @[reassoc] theorem coprod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasColimitsOfShape (Discrete WalkingPair) C] : coprod.map (𝟙 X) f ≫ coprod.map g (𝟙 B) = coprod.map g (𝟙 A) ≫ coprod.map (𝟙 Y) f := by simp #align category_theory.limits.coprod.map_swap CategoryTheory.Limits.coprod.map_swap #align category_theory.limits.coprod.map_swap_assoc CategoryTheory.Limits.coprod.map_swap_assoc @[reassoc] theorem coprod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct Z W] [HasBinaryCoproduct Y W] [HasBinaryCoproduct X W] : coprod.map (f ≫ g) (𝟙 W) = coprod.map f (𝟙 W) ≫ coprod.map g (𝟙 W) := by simp #align category_theory.limits.coprod.map_comp_id CategoryTheory.Limits.coprod.map_comp_id #align category_theory.limits.coprod.map_comp_id_assoc CategoryTheory.Limits.coprod.map_comp_id_assoc @[reassoc] theorem coprod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct W X] [HasBinaryCoproduct W Y] [HasBinaryCoproduct W Z] : coprod.map (𝟙 W) (f ≫ g) = coprod.map (𝟙 W) f ≫ coprod.map (𝟙 W) g := by simp #align category_theory.limits.coprod.map_id_comp CategoryTheory.Limits.coprod.map_id_comp #align category_theory.limits.coprod.map_id_comp_assoc CategoryTheory.Limits.coprod.map_id_comp_assoc /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : W ≅ Z` induces an isomorphism `coprod.mapIso f g : W ⨿ X ≅ Y ⨿ Z`. -/ @[simps] def coprod.mapIso {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨿ X ≅ Y ⨿ Z where hom := coprod.map f.hom g.hom inv := coprod.map f.inv g.inv #align category_theory.limits.coprod.map_iso CategoryTheory.Limits.coprod.mapIso instance isIso_coprod {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (coprod.map f g) := (coprod.mapIso (asIso f) (asIso g)).isIso_hom #align category_theory.limits.is_iso_coprod CategoryTheory.Limits.isIso_coprod instance coprod.map_epi {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f] [Epi g] [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] : Epi (coprod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_epi f] simpa using congr_arg (fun f => coprod.inl ≫ f) h · rw [← cancel_epi g] simpa using congr_arg (fun f => coprod.inr ≫ f) h⟩ #align category_theory.limits.coprod.map_epi CategoryTheory.Limits.coprod.map_epi -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc] theorem coprod.map_codiag {X Y : C} (f : X ⟶ Y) [HasBinaryCoproduct X X] [HasBinaryCoproduct Y Y] : coprod.map f f ≫ codiag Y = codiag X ≫ f := by simp #align category_theory.limits.coprod.map_codiag CategoryTheory.Limits.coprod.map_codiag #align category_theory.limits.coprod.map_codiag_assoc CategoryTheory.Limits.coprod.map_codiag_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc]
Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean
960
962
theorem coprod.map_inl_inr_codiag {X Y : C} [HasBinaryCoproduct X Y] [HasBinaryCoproduct (X ⨿ Y) (X ⨿ Y)] : coprod.map coprod.inl coprod.inr ≫ codiag (X ⨿ Y) = 𝟙 (X ⨿ Y) := by
simp
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Units.Equiv import Mathlib.CategoryTheory.Endomorphism #align_import category_theory.conj from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Conjugate morphisms by isomorphisms An isomorphism `α : X ≅ Y` defines - a monoid isomorphism `CategoryTheory.Iso.conj : End X ≃* End Y` by `α.conj f = α.inv ≫ f ≫ α.hom`; - a group isomorphism `CategoryTheory.Iso.conjAut : Aut X ≃* Aut Y` by `α.conjAut f = α.symm ≪≫ f ≪≫ α`. For completeness, we also define `CategoryTheory.Iso.homCongr : (X ≅ X₁) → (Y ≅ Y₁) → (X ⟶ Y) ≃ (X₁ ⟶ Y₁)`, cf. `Equiv.arrowCongr`, and `CategoryTheory.Iso.isoCongr : (f : X₁ ≅ X₂) → (g : Y₁ ≅ Y₂) → (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂)`. -/ universe v u namespace CategoryTheory namespace Iso variable {C : Type u} [Category.{v} C] /-- If `X` is isomorphic to `X₁` and `Y` is isomorphic to `Y₁`, then there is a natural bijection between `X ⟶ Y` and `X₁ ⟶ Y₁`. See also `Equiv.arrowCongr`. -/ def homCongr {X Y X₁ Y₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) : (X ⟶ Y) ≃ (X₁ ⟶ Y₁) where toFun f := α.inv ≫ f ≫ β.hom invFun f := α.hom ≫ f ≫ β.inv left_inv f := show α.hom ≫ (α.inv ≫ f ≫ β.hom) ≫ β.inv = f by rw [Category.assoc, Category.assoc, β.hom_inv_id, α.hom_inv_id_assoc, Category.comp_id] right_inv f := show α.inv ≫ (α.hom ≫ f ≫ β.inv) ≫ β.hom = f by rw [Category.assoc, Category.assoc, β.inv_hom_id, α.inv_hom_id_assoc, Category.comp_id] #align category_theory.iso.hom_congr CategoryTheory.Iso.homCongr -- @[simp, nolint simpNF] Porting note (#10675): dsimp can not prove this @[simp] theorem homCongr_apply {X Y X₁ Y₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) (f : X ⟶ Y) : α.homCongr β f = α.inv ≫ f ≫ β.hom := by rfl #align category_theory.iso.hom_congr_apply CategoryTheory.Iso.homCongr_apply theorem homCongr_comp {X Y Z X₁ Y₁ Z₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) (γ : Z ≅ Z₁) (f : X ⟶ Y) (g : Y ⟶ Z) : α.homCongr γ (f ≫ g) = α.homCongr β f ≫ β.homCongr γ g := by simp #align category_theory.iso.hom_congr_comp CategoryTheory.Iso.homCongr_comp /- Porting note (#10618): removed `@[simp]`; simp can prove this -/ theorem homCongr_refl {X Y : C} (f : X ⟶ Y) : (Iso.refl X).homCongr (Iso.refl Y) f = f := by simp #align category_theory.iso.hom_congr_refl CategoryTheory.Iso.homCongr_refl /- Porting note (#10618): removed `@[simp]`; simp can prove this -/ theorem homCongr_trans {X₁ Y₁ X₂ Y₂ X₃ Y₃ : C} (α₁ : X₁ ≅ X₂) (β₁ : Y₁ ≅ Y₂) (α₂ : X₂ ≅ X₃) (β₂ : Y₂ ≅ Y₃) (f : X₁ ⟶ Y₁) : (α₁ ≪≫ α₂).homCongr (β₁ ≪≫ β₂) f = (α₁.homCongr β₁).trans (α₂.homCongr β₂) f := by simp #align category_theory.iso.hom_congr_trans CategoryTheory.Iso.homCongr_trans @[simp] theorem homCongr_symm {X₁ Y₁ X₂ Y₂ : C} (α : X₁ ≅ X₂) (β : Y₁ ≅ Y₂) : (α.homCongr β).symm = α.symm.homCongr β.symm := rfl #align category_theory.iso.hom_congr_symm CategoryTheory.Iso.homCongr_symm /-- If `X` is isomorphic to `X₁` and `Y` is isomorphic to `Y₁`, then there is a bijection between `X ≅ Y` and `X₁ ≅ Y₁`. -/ def isoCongr {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ≅ X₂) (g : Y₁ ≅ Y₂) : (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂) where toFun h := f.symm.trans <| h.trans <| g invFun h := f.trans <| h.trans <| g.symm left_inv := by aesop_cat right_inv := by aesop_cat /-- If `X₁` is isomorphic to `X₂`, then there is a bijection between `X₁ ≅ Y` and `X₂ ≅ Y`. -/ def isoCongrLeft {X₁ X₂ Y : C} (f : X₁ ≅ X₂) : (X₁ ≅ Y) ≃ (X₂ ≅ Y) := isoCongr f (Iso.refl _) /-- If `Y₁` is isomorphic to `Y₂`, then there is a bijection between `X ≅ Y₁` and `X ≅ Y₂`. -/ def isoCongrRight {X Y₁ Y₂ : C} (g : Y₁ ≅ Y₂) : (X ≅ Y₁) ≃ (X ≅ Y₂) := isoCongr (Iso.refl _) g variable {X Y : C} (α : X ≅ Y) /-- An isomorphism between two objects defines a monoid isomorphism between their monoid of endomorphisms. -/ def conj : End X ≃* End Y := { homCongr α α with map_mul' := fun f g => homCongr_comp α α α g f } #align category_theory.iso.conj CategoryTheory.Iso.conj theorem conj_apply (f : End X) : α.conj f = α.inv ≫ f ≫ α.hom := rfl #align category_theory.iso.conj_apply CategoryTheory.Iso.conj_apply @[simp] theorem conj_comp (f g : End X) : α.conj (f ≫ g) = α.conj f ≫ α.conj g := α.conj.map_mul g f #align category_theory.iso.conj_comp CategoryTheory.Iso.conj_comp @[simp] theorem conj_id : α.conj (𝟙 X) = 𝟙 Y := α.conj.map_one #align category_theory.iso.conj_id CategoryTheory.Iso.conj_id @[simp] theorem refl_conj (f : End X) : (Iso.refl X).conj f = f := by rw [conj_apply, Iso.refl_inv, Iso.refl_hom, Category.id_comp, Category.comp_id] #align category_theory.iso.refl_conj CategoryTheory.Iso.refl_conj @[simp] theorem trans_conj {Z : C} (β : Y ≅ Z) (f : End X) : (α ≪≫ β).conj f = β.conj (α.conj f) := homCongr_trans α α β β f #align category_theory.iso.trans_conj CategoryTheory.Iso.trans_conj @[simp] theorem symm_self_conj (f : End X) : α.symm.conj (α.conj f) = f := by rw [← trans_conj, α.self_symm_id, refl_conj] #align category_theory.iso.symm_self_conj CategoryTheory.Iso.symm_self_conj @[simp] theorem self_symm_conj (f : End Y) : α.conj (α.symm.conj f) = f := α.symm.symm_self_conj f #align category_theory.iso.self_symm_conj CategoryTheory.Iso.self_symm_conj /- Porting note (#10618): removed `@[simp]`; simp can prove this -/ theorem conj_pow (f : End X) (n : ℕ) : α.conj (f ^ n) = α.conj f ^ n := α.conj.toMonoidHom.map_pow f n #align category_theory.iso.conj_pow CategoryTheory.Iso.conj_pow -- Porting note (#11215): TODO: change definition so that `conjAut_apply` becomes a `rfl`? /-- `conj` defines a group isomorphisms between groups of automorphisms -/ def conjAut : Aut X ≃* Aut Y := (Aut.unitsEndEquivAut X).symm.trans <| (Units.mapEquiv α.conj).trans <| Aut.unitsEndEquivAut Y set_option linter.uppercaseLean3 false in #align category_theory.iso.conj_Aut CategoryTheory.Iso.conjAut theorem conjAut_apply (f : Aut X) : α.conjAut f = α.symm ≪≫ f ≪≫ α := by aesop_cat set_option linter.uppercaseLean3 false in #align category_theory.iso.conj_Aut_apply CategoryTheory.Iso.conjAut_apply @[simp] theorem conjAut_hom (f : Aut X) : (α.conjAut f).hom = α.conj f.hom := rfl set_option linter.uppercaseLean3 false in #align category_theory.iso.conj_Aut_hom CategoryTheory.Iso.conjAut_hom @[simp]
Mathlib/CategoryTheory/Conj.lean
156
158
theorem trans_conjAut {Z : C} (β : Y ≅ Z) (f : Aut X) : (α ≪≫ β).conjAut f = β.conjAut (α.conjAut f) := by
simp only [conjAut_apply, Iso.trans_symm, Iso.trans_assoc]
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Group.Subsemigroup.Membership import Mathlib.Algebra.Ring.Center import Mathlib.Algebra.Ring.Centralizer import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Prod import Mathlib.Algebra.Group.Hom.End import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.Subsemigroup.Centralizer #align_import ring_theory.non_unital_subsemiring.basic from "leanprover-community/mathlib"@"b915e9392ecb2a861e1e766f0e1df6ac481188ca" /-! # Bundled non-unital subsemirings We define bundled non-unital subsemirings and some standard constructions: `CompleteLattice` structure, `subtype` and `inclusion` ring homomorphisms, non-unital subsemiring `map`, `comap` and range (`srange`) of a `NonUnitalRingHom` etc. -/ universe u v w variable {R : Type u} {S : Type v} {T : Type w} [NonUnitalNonAssocSemiring R] (M : Subsemigroup R) /-- `NonUnitalSubsemiringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both an additive submonoid and also a multiplicative subsemigroup. -/ class NonUnitalSubsemiringClass (S : Type*) (R : Type u) [NonUnitalNonAssocSemiring R] [SetLike S R] extends AddSubmonoidClass S R : Prop where mul_mem : ∀ {s : S} {a b : R}, a ∈ s → b ∈ s → a * b ∈ s #align non_unital_subsemiring_class NonUnitalSubsemiringClass -- See note [lower instance priority] instance (priority := 100) NonUnitalSubsemiringClass.mulMemClass (S : Type*) (R : Type u) [NonUnitalNonAssocSemiring R] [SetLike S R] [h : NonUnitalSubsemiringClass S R] : MulMemClass S R := { h with } #align non_unital_subsemiring_class.mul_mem_class NonUnitalSubsemiringClass.mulMemClass namespace NonUnitalSubsemiringClass variable [SetLike S R] [NonUnitalSubsemiringClass S R] (s : S) open AddSubmonoidClass /- Prefer subclasses of `NonUnitalNonAssocSemiring` over subclasses of `NonUnitalSubsemiringClass`. -/ /-- A non-unital subsemiring of a `NonUnitalNonAssocSemiring` inherits a `NonUnitalNonAssocSemiring` structure -/ instance (priority := 75) toNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring s := Subtype.coe_injective.nonUnitalNonAssocSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl #align non_unital_subsemiring_class.to_non_unital_non_assoc_semiring NonUnitalSubsemiringClass.toNonUnitalNonAssocSemiring instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s := Subtype.coe_injective.noZeroDivisors (↑) rfl fun _ _ => rfl #align non_unital_subsemiring_class.no_zero_divisors NonUnitalSubsemiringClass.noZeroDivisors /-- The natural non-unital ring hom from a non-unital subsemiring of a non-unital semiring `R` to `R`. -/ def subtype : s →ₙ+* R := { AddSubmonoidClass.subtype s, MulMemClass.subtype s with toFun := (↑) } #align non_unital_subsemiring_class.subtype NonUnitalSubsemiringClass.subtype @[simp] theorem coeSubtype : (subtype s : s → R) = ((↑) : s → R) := rfl #align non_unital_subsemiring_class.coe_subtype NonUnitalSubsemiringClass.coeSubtype /-- A non-unital subsemiring of a `NonUnitalSemiring` is a `NonUnitalSemiring`. -/ instance toNonUnitalSemiring {R} [NonUnitalSemiring R] [SetLike S R] [NonUnitalSubsemiringClass S R] : NonUnitalSemiring s := Subtype.coe_injective.nonUnitalSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl #align non_unital_subsemiring_class.to_non_unital_semiring NonUnitalSubsemiringClass.toNonUnitalSemiring /-- A non-unital subsemiring of a `NonUnitalCommSemiring` is a `NonUnitalCommSemiring`. -/ instance toNonUnitalCommSemiring {R} [NonUnitalCommSemiring R] [SetLike S R] [NonUnitalSubsemiringClass S R] : NonUnitalCommSemiring s := Subtype.coe_injective.nonUnitalCommSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl #align non_unital_subsemiring_class.to_non_unital_comm_semiring NonUnitalSubsemiringClass.toNonUnitalCommSemiring /-! Note: currently, there are no ordered versions of non-unital rings. -/ end NonUnitalSubsemiringClass variable [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring T] /-- A non-unital subsemiring of a non-unital semiring `R` is a subset `s` that is both an additive submonoid and a semigroup. -/ structure NonUnitalSubsemiring (R : Type u) [NonUnitalNonAssocSemiring R] extends AddSubmonoid R, Subsemigroup R #align non_unital_subsemiring NonUnitalSubsemiring /-- Reinterpret a `NonUnitalSubsemiring` as a `Subsemigroup`. -/ add_decl_doc NonUnitalSubsemiring.toSubsemigroup /-- Reinterpret a `NonUnitalSubsemiring` as an `AddSubmonoid`. -/ add_decl_doc NonUnitalSubsemiring.toAddSubmonoid namespace NonUnitalSubsemiring instance : SetLike (NonUnitalSubsemiring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h instance : NonUnitalSubsemiringClass (NonUnitalSubsemiring R) R where zero_mem {s} := AddSubmonoid.zero_mem' s.toAddSubmonoid add_mem {s} := AddSubsemigroup.add_mem' s.toAddSubmonoid.toAddSubsemigroup mul_mem {s} := mul_mem' s theorem mem_carrier {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_carrier NonUnitalSubsemiring.mem_carrier /-- Two non-unital subsemirings are equal if they have the same elements. -/ @[ext] theorem ext {S T : NonUnitalSubsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align non_unital_subsemiring.ext NonUnitalSubsemiring.ext /-- Copy of a non-unital subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : NonUnitalSubsemiring R := { S.toAddSubmonoid.copy s hs, S.toSubsemigroup.copy s hs with carrier := s } #align non_unital_subsemiring.copy NonUnitalSubsemiring.copy @[simp] theorem coe_copy (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl #align non_unital_subsemiring.coe_copy NonUnitalSubsemiring.coe_copy theorem copy_eq (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs #align non_unital_subsemiring.copy_eq NonUnitalSubsemiring.copy_eq theorem toSubsemigroup_injective : Function.Injective (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align non_unital_subsemiring.to_subsemigroup_injective NonUnitalSubsemiring.toSubsemigroup_injective @[mono] theorem toSubsemigroup_strictMono : StrictMono (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) := fun _ _ => id #align non_unital_subsemiring.to_subsemigroup_strict_mono NonUnitalSubsemiring.toSubsemigroup_strictMono @[mono] theorem toSubsemigroup_mono : Monotone (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) := toSubsemigroup_strictMono.monotone #align non_unital_subsemiring.to_subsemigroup_mono NonUnitalSubsemiring.toSubsemigroup_mono theorem toAddSubmonoid_injective : Function.Injective (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align non_unital_subsemiring.to_add_submonoid_injective NonUnitalSubsemiring.toAddSubmonoid_injective @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) := fun _ _ => id #align non_unital_subsemiring.to_add_submonoid_strict_mono NonUnitalSubsemiring.toAddSubmonoid_strictMono @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) := toAddSubmonoid_strictMono.monotone #align non_unital_subsemiring.to_add_submonoid_mono NonUnitalSubsemiring.toAddSubmonoid_mono /-- Construct a `NonUnitalSubsemiring R` from a set `s`, a subsemigroup `sg`, and an additive submonoid `sa` such that `x ∈ s ↔ x ∈ sg ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sg : Subsemigroup R) (hg : ↑sg = s) (sa : AddSubmonoid R) (ha : ↑sa = s) : NonUnitalSubsemiring R where carrier := s zero_mem' := by subst ha; exact sa.zero_mem add_mem' := by subst ha; exact sa.add_mem mul_mem' := by subst hg; exact sg.mul_mem #align non_unital_subsemiring.mk' NonUnitalSubsemiring.mk' @[simp] theorem coe_mk' {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha : Set R) = s := rfl #align non_unital_subsemiring.coe_mk' NonUnitalSubsemiring.coe_mk' @[simp] theorem mem_mk' {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) {x : R} : x ∈ NonUnitalSubsemiring.mk' s sg hg sa ha ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_mk' NonUnitalSubsemiring.mem_mk' @[simp] theorem mk'_toSubsemigroup {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha).toSubsemigroup = sg := SetLike.coe_injective hg.symm #align non_unital_subsemiring.mk'_to_subsemigroup NonUnitalSubsemiring.mk'_toSubsemigroup @[simp] theorem mk'_toAddSubmonoid {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha).toAddSubmonoid = sa := SetLike.coe_injective ha.symm #align non_unital_subsemiring.mk'_to_add_submonoid NonUnitalSubsemiring.mk'_toAddSubmonoid end NonUnitalSubsemiring namespace NonUnitalSubsemiring variable {F G : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] [FunLike G S T] [NonUnitalRingHomClass G S T] (s : NonUnitalSubsemiring R) @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = (0 : R) := rfl #align non_unital_subsemiring.coe_zero NonUnitalSubsemiring.coe_zero @[simp, norm_cast] theorem coe_add (x y : s) : ((x + y : s) : R) = (x + y : R) := rfl #align non_unital_subsemiring.coe_add NonUnitalSubsemiring.coe_add @[simp, norm_cast] theorem coe_mul (x y : s) : ((x * y : s) : R) = (x * y : R) := rfl #align non_unital_subsemiring.coe_mul NonUnitalSubsemiring.coe_mul /-! Note: currently, there are no ordered versions of non-unital rings. -/ @[simp high] theorem mem_toSubsemigroup {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.toSubsemigroup ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_to_subsemigroup NonUnitalSubsemiring.mem_toSubsemigroup @[simp high] theorem coe_toSubsemigroup (s : NonUnitalSubsemiring R) : (s.toSubsemigroup : Set R) = s := rfl #align non_unital_subsemiring.coe_to_subsemigroup NonUnitalSubsemiring.coe_toSubsemigroup @[simp] theorem mem_toAddSubmonoid {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.toAddSubmonoid ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_to_add_submonoid NonUnitalSubsemiring.mem_toAddSubmonoid @[simp] theorem coe_toAddSubmonoid (s : NonUnitalSubsemiring R) : (s.toAddSubmonoid : Set R) = s := rfl #align non_unital_subsemiring.coe_to_add_submonoid NonUnitalSubsemiring.coe_toAddSubmonoid /-- The non-unital subsemiring `R` of the non-unital semiring `R`. -/ instance : Top (NonUnitalSubsemiring R) := ⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubmonoid R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubsemiring R) := Set.mem_univ x #align non_unital_subsemiring.mem_top NonUnitalSubsemiring.mem_top @[simp] theorem coe_top : ((⊤ : NonUnitalSubsemiring R) : Set R) = Set.univ := rfl #align non_unital_subsemiring.coe_top NonUnitalSubsemiring.coe_top /-- The ring equiv between the top element of `NonUnitalSubsemiring R` and `R`. -/ @[simps!] def topEquiv : (⊤ : NonUnitalSubsemiring R) ≃+* R := { Subsemigroup.topEquiv, AddSubmonoid.topEquiv with } /-- The preimage of a non-unital subsemiring along a non-unital ring homomorphism is a non-unital subsemiring. -/ def comap (f : F) (s : NonUnitalSubsemiring S) : NonUnitalSubsemiring R := { s.toSubsemigroup.comap (f : MulHom R S), s.toAddSubmonoid.comap (f : R →+ S) with carrier := f ⁻¹' s } #align non_unital_subsemiring.comap NonUnitalSubsemiring.comap @[simp] theorem coe_comap (s : NonUnitalSubsemiring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s := rfl #align non_unital_subsemiring.coe_comap NonUnitalSubsemiring.coe_comap @[simp] theorem mem_comap {s : NonUnitalSubsemiring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_comap NonUnitalSubsemiring.mem_comap -- this has some nasty coercions, how to deal with it? theorem comap_comap (s : NonUnitalSubsemiring T) (g : G) (f : F) : ((s.comap g : NonUnitalSubsemiring S).comap f : NonUnitalSubsemiring R) = s.comap ((g : S →ₙ+* T).comp (f : R →ₙ+* S)) := rfl #align non_unital_subsemiring.comap_comap NonUnitalSubsemiring.comap_comap /-- The image of a non-unital subsemiring along a ring homomorphism is a non-unital subsemiring. -/ def map (f : F) (s : NonUnitalSubsemiring R) : NonUnitalSubsemiring S := { s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubmonoid.map (f : R →+ S) with carrier := f '' s } #align non_unital_subsemiring.map NonUnitalSubsemiring.map @[simp] theorem coe_map (f : F) (s : NonUnitalSubsemiring R) : (s.map f : Set S) = f '' s := rfl #align non_unital_subsemiring.coe_map NonUnitalSubsemiring.coe_map @[simp] theorem mem_map {f : F} {s : NonUnitalSubsemiring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl #align non_unital_subsemiring.mem_map NonUnitalSubsemiring.mem_map @[simp] theorem map_id : s.map (NonUnitalRingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ #align non_unital_subsemiring.map_id NonUnitalSubsemiring.map_id -- unavoidable coercions? theorem map_map (g : G) (f : F) : (s.map (f : R →ₙ+* S)).map (g : S →ₙ+* T) = s.map ((g : S →ₙ+* T).comp (f : R →ₙ+* S)) := SetLike.coe_injective <| Set.image_image _ _ _ #align non_unital_subsemiring.map_map NonUnitalSubsemiring.map_map theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubsemiring R} {t : NonUnitalSubsemiring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff #align non_unital_subsemiring.map_le_iff_le_comap NonUnitalSubsemiring.map_le_iff_le_comap theorem gc_map_comap (f : F) : @GaloisConnection (NonUnitalSubsemiring R) (NonUnitalSubsemiring S) _ _ (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align non_unital_subsemiring.gc_map_comap NonUnitalSubsemiring.gc_map_comap /-- A non-unital subsemiring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) map_add' := fun _ _ => Subtype.ext (map_add f _ _) } #align non_unital_subsemiring.equiv_map_of_injective NonUnitalSubsemiring.equivMapOfInjective @[simp] theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl #align non_unital_subsemiring.coe_equiv_map_of_injective_apply NonUnitalSubsemiring.coe_equivMapOfInjective_apply end NonUnitalSubsemiring namespace NonUnitalRingHom open NonUnitalSubsemiring variable {F G : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] variable [FunLike G S T] [NonUnitalRingHomClass G S T] (f : F) (g : G) /-- The range of a non-unital ring homomorphism is a non-unital subsemiring. See note [range copy pattern]. -/ def srange : NonUnitalSubsemiring S := ((⊤ : NonUnitalSubsemiring R).map (f : R →ₙ+* S)).copy (Set.range f) Set.image_univ.symm #align non_unital_ring_hom.srange NonUnitalRingHom.srange @[simp] theorem coe_srange : (srange f : Set S) = Set.range f := rfl #align non_unital_ring_hom.coe_srange NonUnitalRingHom.coe_srange @[simp] theorem mem_srange {f : F} {y : S} : y ∈ srange f ↔ ∃ x, f x = y := Iff.rfl #align non_unital_ring_hom.mem_srange NonUnitalRingHom.mem_srange theorem srange_eq_map : srange f = (⊤ : NonUnitalSubsemiring R).map f := by ext simp #align non_unital_ring_hom.srange_eq_map NonUnitalRingHom.srange_eq_map theorem mem_srange_self (f : F) (x : R) : f x ∈ srange f := mem_srange.mpr ⟨x, rfl⟩ #align non_unital_ring_hom.mem_srange_self NonUnitalRingHom.mem_srange_self theorem map_srange (g : S →ₙ+* T) (f : R →ₙ+* S) : map g (srange f) = srange (g.comp f) := by simpa only [srange_eq_map] using (⊤ : NonUnitalSubsemiring R).map_map g f #align non_unital_ring_hom.map_srange NonUnitalRingHom.map_srange /-- The range of a morphism of non-unital semirings is finite if the domain is a finite. -/ instance finite_srange [Finite R] (f : F) : Finite (srange f : NonUnitalSubsemiring S) := (Set.finite_range f).to_subtype #align non_unital_ring_hom.finite_srange NonUnitalRingHom.finite_srange end NonUnitalRingHom namespace NonUnitalSubsemiring -- should we define this as the range of the zero homomorphism? instance : Bot (NonUnitalSubsemiring R) := ⟨{ carrier := {0} add_mem' := fun _ _ => by simp_all zero_mem' := Set.mem_singleton 0 mul_mem' := fun _ _ => by simp_all }⟩ instance : Inhabited (NonUnitalSubsemiring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : NonUnitalSubsemiring R) : Set R) = {0} := rfl #align non_unital_subsemiring.coe_bot NonUnitalSubsemiring.coe_bot theorem mem_bot {x : R} : x ∈ (⊥ : NonUnitalSubsemiring R) ↔ x = 0 := Set.mem_singleton_iff #align non_unital_subsemiring.mem_bot NonUnitalSubsemiring.mem_bot /-- The inf of two non-unital subsemirings is their intersection. -/ instance : Inf (NonUnitalSubsemiring R) := ⟨fun s t => { s.toSubsemigroup ⊓ t.toSubsemigroup, s.toAddSubmonoid ⊓ t.toAddSubmonoid with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : NonUnitalSubsemiring R) : ((p ⊓ p' : NonUnitalSubsemiring R) : Set R) = (p : Set R) ∩ p' := rfl #align non_unital_subsemiring.coe_inf NonUnitalSubsemiring.coe_inf @[simp] theorem mem_inf {p p' : NonUnitalSubsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align non_unital_subsemiring.mem_inf NonUnitalSubsemiring.mem_inf instance : InfSet (NonUnitalSubsemiring R) := ⟨fun s => NonUnitalSubsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, NonUnitalSubsemiring.toSubsemigroup t) (by simp) (⨅ t ∈ s, NonUnitalSubsemiring.toAddSubmonoid t) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalSubsemiring R)) : ((sInf S : NonUnitalSubsemiring R) : Set R) = ⋂ s ∈ S, ↑s := rfl #align non_unital_subsemiring.coe_Inf NonUnitalSubsemiring.coe_sInf theorem mem_sInf {S : Set (NonUnitalSubsemiring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align non_unital_subsemiring.mem_Inf NonUnitalSubsemiring.mem_sInf @[simp] theorem sInf_toSubsemigroup (s : Set (NonUnitalSubsemiring R)) : (sInf s).toSubsemigroup = ⨅ t ∈ s, NonUnitalSubsemiring.toSubsemigroup t := mk'_toSubsemigroup _ _ #align non_unital_subsemiring.Inf_to_subsemigroup NonUnitalSubsemiring.sInf_toSubsemigroup @[simp] theorem sInf_toAddSubmonoid (s : Set (NonUnitalSubsemiring R)) : (sInf s).toAddSubmonoid = ⨅ t ∈ s, NonUnitalSubsemiring.toAddSubmonoid t := mk'_toAddSubmonoid _ _ #align non_unital_subsemiring.Inf_to_add_submonoid NonUnitalSubsemiring.sInf_toAddSubmonoid /-- Non-unital subsemirings of a non-unital semiring form a complete lattice. -/ instance : CompleteLattice (NonUnitalSubsemiring R) := { completeLatticeOfInf (NonUnitalSubsemiring R) fun _ => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with bot := ⊥ bot_le := fun s _ hx => (mem_bot.mp hx).symm ▸ zero_mem s top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _ _ _ h₁ h₂ _ hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : NonUnitalSubsemiring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ #align non_unital_subsemiring.eq_top_iff' NonUnitalSubsemiring.eq_top_iff' section NonUnitalNonAssocSemiring variable (R) [NonUnitalNonAssocSemiring R] /-- The center of a semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center : NonUnitalSubsemiring R := { Subsemigroup.center R with zero_mem' := Set.zero_mem_center R add_mem' := Set.add_mem_center } #align non_unital_subsemiring.center NonUnitalSubsemiring.center theorem coe_center : ↑(center R) = Set.center R := rfl #align non_unital_subsemiring.coe_center NonUnitalSubsemiring.coe_center @[simp] theorem center_toSubsemigroup : (center R).toSubsemigroup = Subsemigroup.center R := rfl #align non_unital_subsemiring.center_to_subsemigroup NonUnitalSubsemiring.center_toSubsemigroup /-- The center is commutative and associative. -/ instance center.instNonUnitalCommSemiring : NonUnitalCommSemiring (center R) := { Subsemigroup.center.commSemigroup, NonUnitalSubsemiringClass.toNonUnitalNonAssocSemiring (center R) with } /-- A point-free means of proving membership in the center, for a non-associative ring. This can be helpful when working with types that have ext lemmas for `R →+ R`. -/ lemma _root_.Set.mem_center_iff_addMonoidHom (a : R) : a ∈ Set.center R ↔ AddMonoidHom.mulLeft a = .mulRight a ∧ AddMonoidHom.compr₂ .mul (.mulLeft a) = .comp .mul (.mulLeft a) ∧ AddMonoidHom.comp .mul (.mulRight a) = .compl₂ .mul (.mulLeft a) ∧ AddMonoidHom.compr₂ .mul (.mulRight a) = .compl₂ .mul (.mulRight a) := by rw [Set.mem_center_iff, isMulCentral_iff] simp [DFunLike.ext_iff] end NonUnitalNonAssocSemiring section NonUnitalSemiring -- no instance diamond, unlike the unital version example {R} [NonUnitalSemiring R] : (center.instNonUnitalCommSemiring _).toNonUnitalSemiring = NonUnitalSubsemiringClass.toNonUnitalSemiring (center R) := by with_reducible_and_instances rfl theorem mem_center_iff {R} [NonUnitalSemiring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := by rw [← Semigroup.mem_center_iff] exact Iff.rfl #align non_unital_subsemiring.mem_center_iff NonUnitalSubsemiring.mem_center_iff instance decidableMemCenter {R} [NonUnitalSemiring R] [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff #align non_unital_subsemiring.decidable_mem_center NonUnitalSubsemiring.decidableMemCenter @[simp] theorem center_eq_top (R) [NonUnitalCommSemiring R] : center R = ⊤ := SetLike.coe_injective (Set.center_eq_univ R) #align non_unital_subsemiring.center_eq_top NonUnitalSubsemiring.center_eq_top end NonUnitalSemiring section Centralizer /-- The centralizer of a set as non-unital subsemiring. -/ def centralizer {R} [NonUnitalSemiring R] (s : Set R) : NonUnitalSubsemiring R := { Subsemigroup.centralizer s with carrier := s.centralizer zero_mem' := Set.zero_mem_centralizer _ add_mem' := Set.add_mem_centralizer } #align non_unital_subsemiring.centralizer NonUnitalSubsemiring.centralizer @[simp, norm_cast] theorem coe_centralizer {R} [NonUnitalSemiring R] (s : Set R) : (centralizer s : Set R) = s.centralizer := rfl #align non_unital_subsemiring.coe_centralizer NonUnitalSubsemiring.coe_centralizer theorem centralizer_toSubsemigroup {R} [NonUnitalSemiring R] (s : Set R) : (centralizer s).toSubsemigroup = Subsemigroup.centralizer s := rfl #align non_unital_subsemiring.centralizer_to_subsemigroup NonUnitalSubsemiring.centralizer_toSubsemigroup theorem mem_centralizer_iff {R} [NonUnitalSemiring R] {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl #align non_unital_subsemiring.mem_centralizer_iff NonUnitalSubsemiring.mem_centralizer_iff theorem center_le_centralizer {R} [NonUnitalSemiring R] (s) : center R ≤ centralizer s := s.center_subset_centralizer #align non_unital_subsemiring.center_le_centralizer NonUnitalSubsemiring.center_le_centralizer theorem centralizer_le {R} [NonUnitalSemiring R] (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s := Set.centralizer_subset h #align non_unital_subsemiring.centralizer_le NonUnitalSubsemiring.centralizer_le @[simp] theorem centralizer_eq_top_iff_subset {R} [NonUnitalSemiring R] {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset #align non_unital_subsemiring.centralizer_eq_top_iff_subset NonUnitalSubsemiring.centralizer_eq_top_iff_subset @[simp] theorem centralizer_univ {R} [NonUnitalSemiring R] : centralizer Set.univ = center R := SetLike.ext' (Set.centralizer_univ R) #align non_unital_subsemiring.centralizer_univ NonUnitalSubsemiring.centralizer_univ end Centralizer /-- The `NonUnitalSubsemiring` generated by a set. -/ def closure (s : Set R) : NonUnitalSubsemiring R := sInf { S | s ⊆ S } #align non_unital_subsemiring.closure NonUnitalSubsemiring.closure theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : NonUnitalSubsemiring R, s ⊆ S → x ∈ S := mem_sInf #align non_unital_subsemiring.mem_closure NonUnitalSubsemiring.mem_closure /-- The non-unital subsemiring generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx #align non_unital_subsemiring.subset_closure NonUnitalSubsemiring.subset_closure theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align non_unital_subsemiring.not_mem_of_not_mem_closure NonUnitalSubsemiring.not_mem_of_not_mem_closure /-- A non-unital subsemiring `S` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : NonUnitalSubsemiring R} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ #align non_unital_subsemiring.closure_le NonUnitalSubsemiring.closure_le /-- Subsemiring closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure #align non_unital_subsemiring.closure_mono NonUnitalSubsemiring.closure_mono theorem closure_eq_of_le {s : Set R} {t : NonUnitalSubsemiring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ #align non_unital_subsemiring.closure_eq_of_le NonUnitalSubsemiring.closure_eq_of_le theorem mem_map_equiv {f : R ≃+* S} {K : NonUnitalSubsemiring R} {x : S} : x ∈ K.map (f : R →ₙ+* S) ↔ f.symm x ∈ K := by convert @Set.mem_image_equiv _ _ (↑K) f.toEquiv x #align non_unital_subsemiring.mem_map_equiv NonUnitalSubsemiring.mem_map_equiv theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : NonUnitalSubsemiring R) : K.map (f : R →ₙ+* S) = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) #align non_unital_subsemiring.map_equiv_eq_comap_symm NonUnitalSubsemiring.map_equiv_eq_comap_symm theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : NonUnitalSubsemiring S) : K.comap (f : R →ₙ+* S) = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm #align non_unital_subsemiring.comap_equiv_eq_map_symm NonUnitalSubsemiring.comap_equiv_eq_map_symm end NonUnitalSubsemiring namespace Subsemigroup /-- The additive closure of a non-unital subsemigroup is a non-unital subsemiring. -/ def nonUnitalSubsemiringClosure (M : Subsemigroup R) : NonUnitalSubsemiring R := { AddSubmonoid.closure (M : Set R) with mul_mem' := MulMemClass.mul_mem_add_closure } #align subsemigroup.non_unital_subsemiring_closure Subsemigroup.nonUnitalSubsemiringClosure theorem nonUnitalSubsemiringClosure_coe : (M.nonUnitalSubsemiringClosure : Set R) = AddSubmonoid.closure (M : Set R) := rfl #align subsemigroup.non_unital_subsemiring_closure_coe Subsemigroup.nonUnitalSubsemiringClosure_coe theorem nonUnitalSubsemiringClosure_toAddSubmonoid : M.nonUnitalSubsemiringClosure.toAddSubmonoid = AddSubmonoid.closure (M : Set R) := rfl #align subsemigroup.non_unital_subsemiring_closure_to_add_submonoid Subsemigroup.nonUnitalSubsemiringClosure_toAddSubmonoid /-- The `NonUnitalSubsemiring` generated by a multiplicative subsemigroup coincides with the `NonUnitalSubsemiring.closure` of the subsemigroup itself . -/ theorem nonUnitalSubsemiringClosure_eq_closure : M.nonUnitalSubsemiringClosure = NonUnitalSubsemiring.closure (M : Set R) := by ext refine ⟨fun hx => ?_, fun hx => (NonUnitalSubsemiring.mem_closure.mp hx) M.nonUnitalSubsemiringClosure fun s sM => ?_⟩ <;> rintro - ⟨H1, rfl⟩ <;> rintro - ⟨H2, rfl⟩ · exact AddSubmonoid.mem_closure.mp hx H1.toAddSubmonoid H2 · exact H2 sM #align subsemigroup.non_unital_subsemiring_closure_eq_closure Subsemigroup.nonUnitalSubsemiringClosure_eq_closure end Subsemigroup namespace NonUnitalSubsemiring @[simp] theorem closure_subsemigroup_closure (s : Set R) : closure ↑(Subsemigroup.closure s) = closure s := le_antisymm (closure_le.mpr fun _ hy => (Subsemigroup.mem_closure.mp hy) (closure s).toSubsemigroup subset_closure) (closure_mono Subsemigroup.subset_closure) #align non_unital_subsemiring.closure_subsemigroup_closure NonUnitalSubsemiring.closure_subsemigroup_closure /-- The elements of the non-unital subsemiring closure of `M` are exactly the elements of the additive closure of a multiplicative subsemigroup `M`. -/ theorem coe_closure_eq (s : Set R) : (closure s : Set R) = AddSubmonoid.closure (Subsemigroup.closure s : Set R) := by simp [← Subsemigroup.nonUnitalSubsemiringClosure_toAddSubmonoid, Subsemigroup.nonUnitalSubsemiringClosure_eq_closure] #align non_unital_subsemiring.coe_closure_eq NonUnitalSubsemiring.coe_closure_eq theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubmonoid.closure (Subsemigroup.closure s : Set R) := Set.ext_iff.mp (coe_closure_eq s) x #align non_unital_subsemiring.mem_closure_iff NonUnitalSubsemiring.mem_closure_iff @[simp] theorem closure_addSubmonoid_closure {s : Set R} : closure ↑(AddSubmonoid.closure s) = closure s := by ext x refine ⟨fun hx => ?_, fun hx => closure_mono AddSubmonoid.subset_closure hx⟩ rintro - ⟨H, rfl⟩ rintro - ⟨J, rfl⟩ refine (AddSubmonoid.mem_closure.mp (mem_closure_iff.mp hx)) H.toAddSubmonoid fun y hy => ?_ refine (Subsemigroup.mem_closure.mp hy) H.toSubsemigroup fun z hz => ?_ exact (AddSubmonoid.mem_closure.mp hz) H.toAddSubmonoid fun w hw => J hw #align non_unital_subsemiring.closure_add_submonoid_closure NonUnitalSubsemiring.closure_addSubmonoid_closure /-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements of `s`, and is preserved under addition and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set R} {p : R → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨⟨⟨p, fun {a b} => add a b⟩, zero⟩, fun {a b} => mul a b⟩).2 mem h #align non_unital_subsemiring.closure_induction NonUnitalSubsemiring.closure_induction /-- An induction principle for closure membership for predicates with two arguments. -/ @[elab_as_elim] theorem closure_induction₂ {s : Set R} {p : R → R → Prop} {x} {y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ x, p 0 x) (H0_right : ∀ x, p x 0) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p x y := closure_induction hx (fun x₁ x₁s => closure_induction hy (Hs x₁ x₁s) (H0_right x₁) (Hadd_right x₁) (Hmul_right x₁)) (H0_left y) (fun z z' => Hadd_left z z' y) fun z z' => Hmul_left z z' y #align non_unital_subsemiring.closure_induction₂ NonUnitalSubsemiring.closure_induction₂ variable (R) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure R _) (↑) where choice s _ := closure s gc _ _ := closure_le le_l_u _ := subset_closure choice_eq _ _ := rfl #align non_unital_subsemiring.gi NonUnitalSubsemiring.gi variable {R} variable {F : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] /-- Closure of a non-unital subsemiring `S` equals `S`. -/ theorem closure_eq (s : NonUnitalSubsemiring R) : closure (s : Set R) = s := (NonUnitalSubsemiring.gi R).l_u_eq s #align non_unital_subsemiring.closure_eq NonUnitalSubsemiring.closure_eq @[simp] theorem closure_empty : closure (∅ : Set R) = ⊥ := (NonUnitalSubsemiring.gi R).gc.l_bot #align non_unital_subsemiring.closure_empty NonUnitalSubsemiring.closure_empty @[simp] theorem closure_univ : closure (Set.univ : Set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤ #align non_unital_subsemiring.closure_univ NonUnitalSubsemiring.closure_univ theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t := (NonUnitalSubsemiring.gi R).gc.l_sup #align non_unital_subsemiring.closure_union NonUnitalSubsemiring.closure_union theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (NonUnitalSubsemiring.gi R).gc.l_iSup #align non_unital_subsemiring.closure_Union NonUnitalSubsemiring.closure_iUnion theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (NonUnitalSubsemiring.gi R).gc.l_sSup #align non_unital_subsemiring.closure_sUnion NonUnitalSubsemiring.closure_sUnion theorem map_sup (s t : NonUnitalSubsemiring R) (f : F) : (map f (s ⊔ t) : NonUnitalSubsemiring S) = map f s ⊔ map f t := @GaloisConnection.l_sup _ _ s t _ _ _ _ (gc_map_comap f) #align non_unital_subsemiring.map_sup NonUnitalSubsemiring.map_sup theorem map_iSup {ι : Sort*} (f : F) (s : ι → NonUnitalSubsemiring R) : (map f (iSup s) : NonUnitalSubsemiring S) = ⨆ i, map f (s i) := @GaloisConnection.l_iSup _ _ _ _ _ _ _ (gc_map_comap f) s #align non_unital_subsemiring.map_supr NonUnitalSubsemiring.map_iSup theorem comap_inf (s t : NonUnitalSubsemiring S) (f : F) : (comap f (s ⊓ t) : NonUnitalSubsemiring R) = comap f s ⊓ comap f t := @GaloisConnection.u_inf _ _ s t _ _ _ _ (gc_map_comap f) #align non_unital_subsemiring.comap_inf NonUnitalSubsemiring.comap_inf theorem comap_iInf {ι : Sort*} (f : F) (s : ι → NonUnitalSubsemiring S) : (comap f (iInf s) : NonUnitalSubsemiring R) = ⨅ i, comap f (s i) := @GaloisConnection.u_iInf _ _ _ _ _ _ _ (gc_map_comap f) s #align non_unital_subsemiring.comap_infi NonUnitalSubsemiring.comap_iInf @[simp] theorem map_bot (f : F) : map f (⊥ : NonUnitalSubsemiring R) = (⊥ : NonUnitalSubsemiring S) := (gc_map_comap f).l_bot #align non_unital_subsemiring.map_bot NonUnitalSubsemiring.map_bot @[simp] theorem comap_top (f : F) : comap f (⊤ : NonUnitalSubsemiring S) = (⊤ : NonUnitalSubsemiring R) := (gc_map_comap f).u_top #align non_unital_subsemiring.comap_top NonUnitalSubsemiring.comap_top /-- Given `NonUnitalSubsemiring`s `s`, `t` of semirings `R`, `S` respectively, `s.prod t` is `s × t` as a non-unital subsemiring of `R × S`. -/ def prod (s : NonUnitalSubsemiring R) (t : NonUnitalSubsemiring S) : NonUnitalSubsemiring (R × S) := { s.toSubsemigroup.prod t.toSubsemigroup, s.toAddSubmonoid.prod t.toAddSubmonoid with carrier := (s : Set R) ×ˢ (t : Set S) } #align non_unital_subsemiring.prod NonUnitalSubsemiring.prod @[norm_cast] theorem coe_prod (s : NonUnitalSubsemiring R) (t : NonUnitalSubsemiring S) : (s.prod t : Set (R × S)) = (s : Set R) ×ˢ (t : Set S) := rfl #align non_unital_subsemiring.coe_prod NonUnitalSubsemiring.coe_prod theorem mem_prod {s : NonUnitalSubsemiring R} {t : NonUnitalSubsemiring S} {p : R × S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl #align non_unital_subsemiring.mem_prod NonUnitalSubsemiring.mem_prod @[mono] theorem prod_mono ⦃s₁ s₂ : NonUnitalSubsemiring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : NonUnitalSubsemiring S⦄ (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht #align non_unital_subsemiring.prod_mono NonUnitalSubsemiring.prod_mono theorem prod_mono_right (s : NonUnitalSubsemiring R) : Monotone fun t : NonUnitalSubsemiring S => s.prod t := prod_mono (le_refl s) #align non_unital_subsemiring.prod_mono_right NonUnitalSubsemiring.prod_mono_right theorem prod_mono_left (t : NonUnitalSubsemiring S) : Monotone fun s : NonUnitalSubsemiring R => s.prod t := fun _ _ hs => prod_mono hs (le_refl t) #align non_unital_subsemiring.prod_mono_left NonUnitalSubsemiring.prod_mono_left theorem prod_top (s : NonUnitalSubsemiring R) : s.prod (⊤ : NonUnitalSubsemiring S) = s.comap (NonUnitalRingHom.fst R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] #align non_unital_subsemiring.prod_top NonUnitalSubsemiring.prod_top theorem top_prod (s : NonUnitalSubsemiring S) : (⊤ : NonUnitalSubsemiring R).prod s = s.comap (NonUnitalRingHom.snd R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] #align non_unital_subsemiring.top_prod NonUnitalSubsemiring.top_prod @[simp] theorem top_prod_top : (⊤ : NonUnitalSubsemiring R).prod (⊤ : NonUnitalSubsemiring S) = ⊤ := (top_prod _).trans <| comap_top _ #align non_unital_subsemiring.top_prod_top NonUnitalSubsemiring.top_prod_top /-- Product of non-unital subsemirings is isomorphic to their product as semigroups. -/ def prodEquiv (s : NonUnitalSubsemiring R) (t : NonUnitalSubsemiring S) : s.prod t ≃+* s × t := { Equiv.Set.prod (s : Set R) (t : Set S) with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } #align non_unital_subsemiring.prod_equiv NonUnitalSubsemiring.prodEquiv
Mathlib/RingTheory/NonUnitalSubsemiring/Basic.lean
852
861
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → NonUnitalSubsemiring R} (hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ let U : NonUnitalSubsemiring R := NonUnitalSubsemiring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubsemigroup) (Subsemigroup.coe_iSup_of_directed hS) (⨆ i, (S i).toAddSubmonoid) (AddSubmonoid.coe_iSup_of_directed hS) -- Porting note `@this` doesn't work suffices H : ⨆ i, S i ≤ U by simpa [U] using @H x exact iSup_le fun i x hx => Set.mem_iUnion.2 ⟨i, hx⟩
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Chris Hughes -/ import Mathlib.Algebra.Associated import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.SMulWithZero import Mathlib.Data.Nat.PartENat import Mathlib.Tactic.Linarith #align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Multiplicity of a divisor For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves several basic results on it. ## Main definitions * `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers `n`. * `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite. -/ variable {α β : Type*} open Nat Part /-- `multiplicity a b` returns the largest natural number `n` such that `a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`, then it returns `⊤`-/ def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat := PartENat.find fun n => ¬a ^ (n + 1) ∣ b #align multiplicity multiplicity namespace multiplicity section Monoid variable [Monoid α] [Monoid β] /-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/ abbrev Finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b #align multiplicity.finite multiplicity.Finite theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} : Finite a b ↔ (multiplicity a b).Dom := Iff.rfl #align multiplicity.finite_iff_dom multiplicity.finite_iff_dom theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := Iff.rfl #align multiplicity.finite_def multiplicity.finite_def theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ => hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩ #align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right @[norm_cast] theorem Int.natCast_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by apply Part.ext' · rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ] norm_cast · intro h1 h2 apply _root_.le_antisymm <;> · apply Nat.find_mono norm_cast simp #align multiplicity.int.coe_nat_multiplicity multiplicity.Int.natCast_multiplicity @[deprecated (since := "2024-04-05")] alias Int.coe_nat_multiplicity := Int.natCast_multiplicity theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b := ⟨fun h n => Nat.casesOn n (by rw [_root_.pow_zero] exact one_dvd _) (by simpa [Finite, Classical.not_not] using h), by simp [Finite, multiplicity, Classical.not_not]; tauto⟩ #align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a := let ⟨n, hn⟩ := h hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1) #align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ => ⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩ #align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)] theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by rw [← PartENat.some_eq_natCast] exact Nat.casesOn k (fun _ => by rw [_root_.pow_zero] exact one_dvd _) fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk #align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b := pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get]) #align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h) #align multiplicity.is_greatest multiplicity.is_greatest theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) : ¬a ^ m ∣ b := is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm) #align multiplicity.is_greatest' multiplicity.is_greatest' theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) : 0 < (multiplicity a b).get hfin := by refine zero_lt_iff.2 fun h => ?_ simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h) #align multiplicity.pos_of_dvd multiplicity.pos_of_dvd theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : (k : PartENat) = multiplicity a b := le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by have : Finite a b := ⟨k, hsucc⟩ rw [PartENat.le_coe_iff] exact ⟨this, Nat.find_min' _ hsucc⟩ #align multiplicity.unique multiplicity.unique theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : k = get (multiplicity a b) ⟨k, hsucc⟩ := by rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc] #align multiplicity.unique' multiplicity.unique' theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) : (k : PartENat) ≤ multiplicity a b := le_of_not_gt fun hk' => is_greatest hk' hk #align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} : a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b := ⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩ #align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity
Mathlib/RingTheory/Multiplicity.lean
152
153
theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} : multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by
rw [pow_dvd_iff_le_multiplicity, not_le]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ 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
Mathlib/Combinatorics/Enumerative/Composition.lean
524
541
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
/- 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.Lattice import Mathlib.Data.Set.Pairwise.Basic #align_import data.set.pairwise.lattice from "leanprover-community/mathlib"@"c4c2ed622f43768eff32608d4a0f8a6cec1c047d" /-! # Relations holding pairwise In this file we prove many facts about `Pairwise` and the set lattice. -/ open Function Set Order variable {α β γ ι ι' : Type*} {κ : Sort*} {r p q : α → α → Prop} section Pairwise variable {f g : ι → α} {s t u : Set α} {a b : α} namespace Set theorem pairwise_iUnion {f : κ → Set α} (h : Directed (· ⊆ ·) f) : (⋃ n, f n).Pairwise r ↔ ∀ n, (f n).Pairwise r := by constructor · intro H n exact Pairwise.mono (subset_iUnion _ _) H · intro H i hi j hj hij rcases mem_iUnion.1 hi with ⟨m, hm⟩ rcases mem_iUnion.1 hj with ⟨n, hn⟩ rcases h m n with ⟨p, mp, np⟩ exact H p (mp hm) (np hn) hij #align set.pairwise_Union Set.pairwise_iUnion theorem pairwise_sUnion {r : α → α → Prop} {s : Set (Set α)} (h : DirectedOn (· ⊆ ·) s) : (⋃₀ s).Pairwise r ↔ ∀ a ∈ s, Set.Pairwise a r := by rw [sUnion_eq_iUnion, pairwise_iUnion h.directed_val, SetCoe.forall] #align set.pairwise_sUnion Set.pairwise_sUnion end Set end Pairwise namespace Set section PartialOrderBot variable [PartialOrder α] [OrderBot α] {s t : Set ι} {f g : ι → α} theorem pairwiseDisjoint_iUnion {g : ι' → Set ι} (h : Directed (· ⊆ ·) g) : (⋃ n, g n).PairwiseDisjoint f ↔ ∀ ⦃n⦄, (g n).PairwiseDisjoint f := pairwise_iUnion h #align set.pairwise_disjoint_Union Set.pairwiseDisjoint_iUnion theorem pairwiseDisjoint_sUnion {s : Set (Set ι)} (h : DirectedOn (· ⊆ ·) s) : (⋃₀ s).PairwiseDisjoint f ↔ ∀ ⦃a⦄, a ∈ s → Set.PairwiseDisjoint a f := pairwise_sUnion h #align set.pairwise_disjoint_sUnion Set.pairwiseDisjoint_sUnion end PartialOrderBot section CompleteLattice variable [CompleteLattice α] {s : Set ι} {t : Set ι'} /-- Bind operation for `Set.PairwiseDisjoint`. If you want to only consider finsets of indices, you can use `Set.PairwiseDisjoint.biUnion_finset`. -/ theorem PairwiseDisjoint.biUnion {s : Set ι'} {g : ι' → Set ι} {f : ι → α} (hs : s.PairwiseDisjoint fun i' : ι' => ⨆ i ∈ g i', f i) (hg : ∀ i ∈ s, (g i).PairwiseDisjoint f) : (⋃ i ∈ s, g i).PairwiseDisjoint f := by rintro a ha b hb hab simp_rw [Set.mem_iUnion] at ha hb obtain ⟨c, hc, ha⟩ := ha obtain ⟨d, hd, hb⟩ := hb obtain hcd | hcd := eq_or_ne (g c) (g d) · exact hg d hd (hcd.subst ha) hb hab -- Porting note: the elaborator couldn't figure out `f` here. · exact (hs hc hd <| ne_of_apply_ne _ hcd).mono (le_iSup₂ (f := fun i (_ : i ∈ g c) => f i) a ha) (le_iSup₂ (f := fun i (_ : i ∈ g d) => f i) b hb) #align set.pairwise_disjoint.bUnion Set.PairwiseDisjoint.biUnion /-- If the suprema of columns are pairwise disjoint and suprema of rows as well, then everything is pairwise disjoint. Not to be confused with `Set.PairwiseDisjoint.prod`. -/ theorem PairwiseDisjoint.prod_left {f : ι × ι' → α} (hs : s.PairwiseDisjoint fun i => ⨆ i' ∈ t, f (i, i')) (ht : t.PairwiseDisjoint fun i' => ⨆ i ∈ s, f (i, i')) : (s ×ˢ t : Set (ι × ι')).PairwiseDisjoint f := by rintro ⟨i, i'⟩ hi ⟨j, j'⟩ hj h rw [mem_prod] at hi hj obtain rfl | hij := eq_or_ne i j · refine (ht hi.2 hj.2 <| (Prod.mk.inj_left _).ne_iff.1 h).mono ?_ ?_ · convert le_iSup₂ (α := α) i hi.1; rfl · convert le_iSup₂ (α := α) i hj.1; rfl · refine (hs hi.1 hj.1 hij).mono ?_ ?_ · convert le_iSup₂ (α := α) i' hi.2; rfl · convert le_iSup₂ (α := α) j' hj.2; rfl #align set.pairwise_disjoint.prod_left Set.PairwiseDisjoint.prod_left end CompleteLattice section Frame variable [Frame α]
Mathlib/Data/Set/Pairwise/Lattice.lean
110
119
theorem pairwiseDisjoint_prod_left {s : Set ι} {t : Set ι'} {f : ι × ι' → α} : (s ×ˢ t : Set (ι × ι')).PairwiseDisjoint f ↔ (s.PairwiseDisjoint fun i => ⨆ i' ∈ t, f (i, i')) ∧ t.PairwiseDisjoint fun i' => ⨆ i ∈ s, f (i, i') := by
refine ⟨fun h => ⟨fun i hi j hj hij => ?_, fun i hi j hj hij => ?_⟩, fun h => h.1.prod_left h.2⟩ <;> simp_rw [Function.onFun, iSup_disjoint_iff, disjoint_iSup_iff] <;> intro i' hi' j' hj' · exact h (mk_mem_prod hi hi') (mk_mem_prod hj hj') (ne_of_apply_ne Prod.fst hij) · exact h (mk_mem_prod hi' hi) (mk_mem_prod hj' hj) (ne_of_apply_ne Prod.snd hij)
/- 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 theorem not_mem_iff_boolIndicator (x : α) : x ∉ s ↔ s.boolIndicator x = false := by unfold boolIndicator split_ifs with h <;> simp [h] #align set.not_mem_iff_bool_indicator Set.not_mem_iff_boolIndicator theorem preimage_boolIndicator_true : s.boolIndicator ⁻¹' {true} = s := ext fun x ↦ (s.mem_iff_boolIndicator x).symm #align set.preimage_bool_indicator_true Set.preimage_boolIndicator_true theorem preimage_boolIndicator_false : s.boolIndicator ⁻¹' {false} = sᶜ := ext fun x ↦ (s.not_mem_iff_boolIndicator x).symm #align set.preimage_bool_indicator_false Set.preimage_boolIndicator_false open scoped Classical
Mathlib/Data/Set/BoolIndicator.lean
47
51
theorem preimage_boolIndicator_eq_union (t : Set Bool) : s.boolIndicator ⁻¹' t = (if true ∈ t then s else ∅) ∪ if false ∈ t then sᶜ else ∅ := by
ext x simp only [boolIndicator, mem_preimage] split_ifs <;> simp [*]
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Constructions #align_import topology.continuous_on from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Neighborhoods and continuity relative to a subset This file defines relative versions * `nhdsWithin` of `nhds` * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` and proves their basic properties, including the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology Filter variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variable [TopologicalSpace α] @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl #align nhds_bind_nhds_within nhds_bind_nhdsWithin @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } #align eventually_nhds_nhds_within eventually_nhds_nhdsWithin theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal #align eventually_nhds_within_iff eventually_nhdsWithin_iff theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] #align frequently_nhds_within_iff frequently_nhdsWithin_iff theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] #align mem_closure_ne_iff_frequently_within mem_closure_ne_iff_frequently_within @[simp] theorem eventually_nhdsWithin_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs #align eventually_nhds_within_nhds_within eventually_nhdsWithin_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf #align nhds_within_eq nhdsWithin_eq theorem nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] #align nhds_within_univ nhdsWithin_univ theorem nhdsWithin_hasBasis {p : β → Prop} {s : β → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t #align nhds_within_has_basis nhdsWithin_hasBasis theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t #align nhds_within_basis_open nhdsWithin_basis_open theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff #align mem_nhds_within mem_nhdsWithin theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff #align mem_nhds_within_iff_exists_mem_nhds_inter mem_nhdsWithin_iff_exists_mem_nhds_inter theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t #align diff_mem_nhds_within_compl diff_mem_nhdsWithin_compl theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) #align diff_mem_nhds_within_diff diff_mem_nhdsWithin_diff theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw #align nhds_of_nhds_within_of_nhds nhds_of_nhdsWithin_of_nhds theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal #align mem_nhds_within_iff_eventually mem_nhdsWithin_iff_eventually theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and] #align mem_nhds_within_iff_eventually_eq mem_nhdsWithin_iff_eventuallyEq theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t := set_eventuallyEq_iff_inf_principal.symm #align nhds_within_eq_iff_eventually_eq nhdsWithin_eq_iff_eventuallyEq theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x := set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal #align nhds_within_le_iff nhdsWithin_le_iff -- Porting note: golfed, dropped an unneeded assumption theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝[t] a := by lift a to t using h replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs rwa [← map_nhds_subtype_val, mem_map] #align preimage_nhds_within_coinduced' preimage_nhdsWithin_coinduced'ₓ theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_of_left h #align mem_nhds_within_of_mem_nhds mem_nhdsWithin_of_mem_nhds theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a := mem_inf_of_right (mem_principal_self s) #align self_mem_nhds_within self_mem_nhdsWithin theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s := self_mem_nhdsWithin #align eventually_mem_nhds_within eventually_mem_nhdsWithin theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem self_mem_nhdsWithin (mem_inf_of_left h) #align inter_mem_nhds_within inter_mem_nhdsWithin theorem nhdsWithin_mono (a : α) {s t : Set α} (h : s ⊆ t) : 𝓝[s] a ≤ 𝓝[t] a := inf_le_inf_left _ (principal_mono.mpr h) #align nhds_within_mono nhdsWithin_mono theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) #align pure_le_nhds_within pure_le_nhdsWithin theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhdsWithin ha ht #align mem_of_mem_nhds_within mem_of_mem_nhdsWithin theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhdsWithin hx h #align filter.eventually.self_of_nhds_within Filter.Eventually.self_of_nhdsWithin theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) : Tendsto (fun _ : β => a) l (𝓝[s] a) := tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha #align tendsto_const_nhds_within tendsto_const_nhdsWithin theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h))) (inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left)) #align nhds_within_restrict'' nhdsWithin_restrict'' theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict'' s <| mem_inf_of_left h #align nhds_within_restrict' nhdsWithin_restrict' theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀) #align nhds_within_restrict nhdsWithin_restrict theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := nhdsWithin_le_iff.mpr h #align nhds_within_le_of_mem nhdsWithin_le_of_mem theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by rw [← nhdsWithin_univ] apply nhdsWithin_le_of_mem exact univ_mem #align nhds_within_le_nhds nhdsWithin_le_nhds theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂] #align nhds_within_eq_nhds_within' nhdsWithin_eq_nhdsWithin' theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂] #align nhds_within_eq_nhds_within nhdsWithin_eq_nhdsWithin @[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a := inf_eq_left.trans le_principal_iff #align nhds_within_eq_nhds nhdsWithin_eq_nhds theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a := nhdsWithin_eq_nhds.2 <| h.mem_nhds ha #align is_open.nhds_within_eq IsOpen.nhdsWithin_eq theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (ht : IsOpen t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝 a := by rw [← ht.nhdsWithin_eq h] exact preimage_nhdsWithin_coinduced' h hs #align preimage_nhds_within_coinduced preimage_nhds_within_coinduced @[simp] theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq] #align nhds_within_empty nhdsWithin_empty theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by delta nhdsWithin rw [← inf_sup_left, sup_principal] #align nhds_within_union nhdsWithin_union theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) : 𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := Set.Finite.induction_on hI (by simp) fun _ _ hT ↦ by simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert] #align nhds_within_bUnion nhdsWithin_biUnion theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) : 𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS] #align nhds_within_sUnion nhdsWithin_sUnion theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) : 𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range] #align nhds_within_Union nhdsWithin_iUnion theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by delta nhdsWithin rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem] #align nhds_within_inter nhdsWithin_inter theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by delta nhdsWithin rw [← inf_principal, inf_assoc] #align nhds_within_inter' nhdsWithin_inter' theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by rw [nhdsWithin_inter, inf_eq_right] exact nhdsWithin_le_of_mem h #align nhds_within_inter_of_mem nhdsWithin_inter_of_mem theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by rw [inter_comm, nhdsWithin_inter_of_mem h] #align nhds_within_inter_of_mem' nhdsWithin_inter_of_mem' @[simp] theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] #align nhds_within_singleton nhdsWithin_singleton @[simp] theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton] #align nhds_within_insert nhdsWithin_insert theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp #align mem_nhds_within_insert mem_nhdsWithin_insert theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h] #align insert_mem_nhds_within_insert insert_mem_nhdsWithin_insert theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left, insert_def] #align insert_mem_nhds_iff insert_mem_nhds_iff @[simp] theorem nhdsWithin_compl_singleton_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ] #align nhds_within_compl_singleton_sup_pure nhdsWithin_compl_singleton_sup_pure theorem nhdsWithin_prod {α : Type*} [TopologicalSpace α] {β : Type*} [TopologicalSpace β] {s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by rw [nhdsWithin_prod_eq] exact prod_mem_prod hu hv #align nhds_within_prod nhdsWithin_prod theorem nhdsWithin_pi_eq' {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ← iInf_principal_finite hI, ← iInf_inf_eq] #align nhds_within_pi_eq' nhdsWithin_pi_eq' theorem nhdsWithin_pi_eq {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓ ⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf, comap_principal, eval] rw [iInf_split _ fun i => i ∈ I, inf_right_comm] simp only [iInf_inf_eq] #align nhds_within_pi_eq nhdsWithin_pi_eq theorem nhdsWithin_pi_univ_eq {ι : Type*} {α : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (α i)] (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x #align nhds_within_pi_univ_eq nhdsWithin_pi_univ_eq theorem nhdsWithin_pi_eq_bot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot] #align nhds_within_pi_eq_bot nhdsWithin_pi_eq_bot theorem nhdsWithin_pi_neBot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by simp [neBot_iff, nhdsWithin_pi_eq_bot] #align nhds_within_pi_ne_bot nhdsWithin_pi_neBot theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l) (h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter'] #align filter.tendsto.piecewise_nhds_within Filter.Tendsto.piecewise_nhdsWithin theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l) (h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) : Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhdsWithin h₁ #align filter.tendsto.if_nhds_within Filter.Tendsto.if_nhdsWithin theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) : map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) := ((nhdsWithin_basis_open a s).map f).eq_biInf #align map_nhds_within map_nhdsWithin theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t) (h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l := h.mono_left <| nhdsWithin_mono a hst #align tendsto_nhds_within_mono_left tendsto_nhdsWithin_mono_left theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t) (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) := h.mono_right (nhdsWithin_mono a hst) #align tendsto_nhds_within_mono_right tendsto_nhdsWithin_mono_right theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l := h.mono_left inf_le_left #align tendsto_nhds_within_of_tendsto_nhds tendsto_nhdsWithin_of_tendsto_nhds theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff, eventually_and] at h exact (h univ ⟨mem_univ a, isOpen_univ⟩).2 #align eventually_mem_of_tendsto_nhds_within eventually_mem_of_tendsto_nhdsWithin theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) := h.mono_right nhdsWithin_le_nhds #align tendsto_nhds_of_tendsto_nhds_within tendsto_nhds_of_tendsto_nhdsWithin theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) := mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx #align nhds_within_ne_bot_of_mem nhdsWithin_neBot_of_mem theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α} (hx : NeBot <| 𝓝[s] x) : x ∈ s := hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx #align is_closed.mem_of_nhds_within_ne_bot IsClosed.mem_of_nhdsWithin_neBot theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) : NeBot (𝓝[range f] x) := mem_closure_iff_clusterPt.1 (h x) #align dense_range.nhds_within_ne_bot DenseRange.nhdsWithin_neBot theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot] #align mem_closure_pi mem_closure_pi theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι) (s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) := Set.ext fun _ => mem_closure_pi #align closure_pi_set closure_pi_set theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)} (I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq, pi_univ] #align dense_pi dense_pi theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} : f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal #align eventually_eq_nhds_within_iff eventuallyEq_nhdsWithin_iff theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := mem_inf_of_right h #align eventually_eq_nhds_within_of_eq_on eventuallyEq_nhdsWithin_of_eqOn theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := eventuallyEq_nhdsWithin_of_eqOn h #align set.eq_on.eventually_eq_nhds_within Set.EqOn.eventuallyEq_nhdsWithin theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β} (hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l := (tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf #align tendsto_nhds_within_congr tendsto_nhdsWithin_congr theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_inf_of_right h #align eventually_nhds_within_of_forall eventually_nhdsWithin_of_forall theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α} (f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) := tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩ #align tendsto_nhds_within_of_tendsto_nhds_of_eventually_within tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} : Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s := ⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h => tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩ #align tendsto_nhds_within_iff tendsto_nhdsWithin_iff @[simp] theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} : Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) := ⟨fun h => h.mono_right inf_le_left, fun h => tendsto_inf.2 ⟨h, tendsto_principal.2 <| eventually_of_forall mem_range_self⟩⟩ #align tendsto_nhds_within_range tendsto_nhdsWithin_range theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g) (hmem : a ∈ s) : f a = g a := h.self_of_nhdsWithin hmem #align filter.eventually_eq.eq_of_nhds_within Filter.EventuallyEq.eq_of_nhdsWithin theorem eventually_nhdsWithin_of_eventually_nhds {α : Type*} [TopologicalSpace α] {s : Set α} {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_nhdsWithin_of_mem_nhds h #align eventually_nhds_within_of_eventually_nhds eventually_nhdsWithin_of_eventually_nhds /-! ### `nhdsWithin` and subtypes -/ theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} : t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin] #align mem_nhds_within_subtype mem_nhdsWithin_subtype theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) : 𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) := Filter.ext fun _ => mem_nhdsWithin_subtype #align nhds_within_subtype nhdsWithin_subtype theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) : 𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) := (map_nhds_subtype_val ⟨a, h⟩).symm #align nhds_within_eq_map_subtype_coe nhdsWithin_eq_map_subtype_coe theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} : t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective] #align mem_nhds_subtype_iff_nhds_within mem_nhds_subtype_iff_nhdsWithin theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by rw [← map_nhds_subtype_val, mem_map] #align preimage_coe_mem_nhds_subtype preimage_coe_mem_nhds_subtype theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x := preimage_coe_mem_nhds_subtype theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x := eventually_nhds_subtype_iff s a (¬ P ·) |>.not theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) : Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl #align tendsto_nhds_within_iff_subtype tendsto_nhdsWithin_iff_subtype variable [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ] /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as `ContinuousWithinAt.comp` will have a different meaning. -/ theorem ContinuousWithinAt.tendsto {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝 (f x)) := h #align continuous_within_at.tendsto ContinuousWithinAt.tendsto theorem ContinuousOn.continuousWithinAt {f : α → β} {s : Set α} {x : α} (hf : ContinuousOn f s) (hx : x ∈ s) : ContinuousWithinAt f s x := hf x hx #align continuous_on.continuous_within_at ContinuousOn.continuousWithinAt theorem continuousWithinAt_univ (f : α → β) (x : α) : ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_within_at_univ continuousWithinAt_univ theorem continuous_iff_continuousOn_univ {f : α → β} : Continuous f ↔ ContinuousOn f univ := by simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_iff_continuous_on_univ continuous_iff_continuousOn_univ theorem continuousWithinAt_iff_continuousAt_restrict (f : α → β) {x : α} {s : Set α} (h : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousAt (s.restrict f) ⟨x, h⟩ := tendsto_nhdsWithin_iff_subtype h f _ #align continuous_within_at_iff_continuous_at_restrict continuousWithinAt_iff_continuousAt_restrict theorem ContinuousWithinAt.tendsto_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : MapsTo f s t) : Tendsto f (𝓝[s] x) (𝓝[t] f x) := tendsto_inf.2 ⟨h, tendsto_principal.2 <| mem_inf_of_right <| mem_principal.2 <| ht⟩ #align continuous_within_at.tendsto_nhds_within ContinuousWithinAt.tendsto_nhdsWithin theorem ContinuousWithinAt.tendsto_nhdsWithin_image {f : α → β} {x : α} {s : Set α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝[f '' s] f x) := h.tendsto_nhdsWithin (mapsTo_image _ _) #align continuous_within_at.tendsto_nhds_within_image ContinuousWithinAt.tendsto_nhdsWithin_image theorem ContinuousWithinAt.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} {x : α} {y : β} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g t y) : ContinuousWithinAt (Prod.map f g) (s ×ˢ t) (x, y) := by unfold ContinuousWithinAt at * rw [nhdsWithin_prod_eq, Prod.map, nhds_prod_eq] exact hf.prod_map hg #align continuous_within_at.prod_map ContinuousWithinAt.prod_map theorem continuousWithinAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨x.1, ·⟩) {b | (x.1, b) ∈ s} x.2 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, pure_prod, ← map_inf_principal_preimage]; rfl theorem continuousWithinAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨·, x.2⟩) {a | (a, x.2) ∈ s} x.1 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, prod_pure, ← map_inf_principal_preimage]; rfl theorem continuousAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨x.1, ·⟩) x.2 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_left theorem continuousAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨·, x.2⟩) x.1 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_right theorem continuousOn_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ a, ContinuousOn (f ⟨a, ·⟩) {b | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_left]; rfl theorem continuousOn_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ b, ContinuousOn (f ⟨·, b⟩) {a | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_right]; apply forall_swap /-- If a function `f a b` is such that `y ↦ f a b` is continuous for all `a`, and `a` lives in a discrete space, then `f` is continuous, and vice versa. -/ theorem continuous_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : Continuous f ↔ ∀ a, Continuous (f ⟨a, ·⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_left theorem continuous_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : Continuous f ↔ ∀ b, Continuous (f ⟨·, b⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_right theorem isOpenMap_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : IsOpenMap f ↔ ∀ a, IsOpenMap (f ⟨a, ·⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, nhds_prod_eq, nhds_discrete, pure_prod, map_map] rfl theorem isOpenMap_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : IsOpenMap f ↔ ∀ b, IsOpenMap (f ⟨·, b⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, forall_swap (α := α) (β := β), nhds_prod_eq, nhds_discrete, prod_pure, map_map]; rfl theorem continuousWithinAt_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ∀ i, ContinuousWithinAt (fun y => f y i) s x := tendsto_pi_nhds #align continuous_within_at_pi continuousWithinAt_pi theorem continuousOn_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} : ContinuousOn f s ↔ ∀ i, ContinuousOn (fun y => f y i) s := ⟨fun h i x hx => tendsto_pi_nhds.1 (h x hx) i, fun h x hx => tendsto_pi_nhds.2 fun i => h i x hx⟩ #align continuous_on_pi continuousOn_pi @[fun_prop] theorem continuousOn_pi' {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} (hf : ∀ i, ContinuousOn (fun y => f y i) s) : ContinuousOn f s := continuousOn_pi.2 hf theorem ContinuousWithinAt.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) {g : α → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => i.insertNth (f a) (g a)) s a := hf.tendsto.fin_insertNth i hg #align continuous_within_at.fin_insert_nth ContinuousWithinAt.fin_insertNth nonrec theorem ContinuousOn.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {s : Set α} (hf : ContinuousOn f s) {g : α → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousOn g s) : ContinuousOn (fun a => i.insertNth (f a) (g a)) s := fun a ha => (hf a ha).fin_insertNth i (hg a ha) #align continuous_on.fin_insert_nth ContinuousOn.fin_insertNth theorem continuousOn_iff {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ x ∈ s, ∀ t : Set β, IsOpen t → f x ∈ t → ∃ u, IsOpen u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by simp only [ContinuousOn, ContinuousWithinAt, tendsto_nhds, mem_nhdsWithin] #align continuous_on_iff continuousOn_iff theorem continuousOn_iff_continuous_restrict {f : α → β} {s : Set α} : ContinuousOn f s ↔ Continuous (s.restrict f) := by rw [ContinuousOn, continuous_iff_continuousAt]; constructor · rintro h ⟨x, xs⟩ exact (continuousWithinAt_iff_continuousAt_restrict f xs).mp (h x xs) intro h x xs exact (continuousWithinAt_iff_continuousAt_restrict f xs).mpr (h ⟨x, xs⟩) #align continuous_on_iff_continuous_restrict continuousOn_iff_continuous_restrict -- Porting note: 2 new lemmas alias ⟨ContinuousOn.restrict, _⟩ := continuousOn_iff_continuous_restrict theorem ContinuousOn.restrict_mapsTo {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (ht : MapsTo f s t) : Continuous (ht.restrict f s t) := hf.restrict.codRestrict _ theorem continuousOn_iff' {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ t : Set β, IsOpen t → ∃ u, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsOpen (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isOpen_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff] constructor <;> · rintro ⟨u, ou, useq⟩ exact ⟨u, ou, by simpa only [Set.inter_comm, eq_comm] using useq⟩ rw [continuousOn_iff_continuous_restrict, continuous_def]; simp only [this] #align continuous_on_iff' continuousOn_iff' /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any finer topology on the source space. -/ theorem ContinuousOn.mono_dom {α β : Type*} {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₃ f s) : @ContinuousOn α β t₂ t₃ f s := fun x hx _u hu => map_mono (inf_le_inf_right _ <| nhds_mono h₁) (h₂ x hx hu) #align continuous_on.mono_dom ContinuousOn.mono_dom /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any coarser topology on the target space. -/ theorem ContinuousOn.mono_rng {α β : Type*} {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₂ f s) : @ContinuousOn α β t₁ t₃ f s := fun x hx _u hu => h₂ x hx <| nhds_mono h₁ hu #align continuous_on.mono_rng ContinuousOn.mono_rng theorem continuousOn_iff_isClosed {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ t : Set β, IsClosed t → ∃ u, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsClosed (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isClosed_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm, Set.inter_comm s] rw [continuousOn_iff_continuous_restrict, continuous_iff_isClosed]; simp only [this] #align continuous_on_iff_is_closed continuousOn_iff_isClosed theorem ContinuousOn.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hg : ContinuousOn g t) : ContinuousOn (Prod.map f g) (s ×ˢ t) := fun ⟨x, y⟩ ⟨hx, hy⟩ => ContinuousWithinAt.prod_map (hf x hx) (hg y hy) #align continuous_on.prod_map ContinuousOn.prod_map theorem continuous_of_cover_nhds {ι : Sort*} {f : α → β} {s : ι → Set α} (hs : ∀ x : α, ∃ i, s i ∈ 𝓝 x) (hf : ∀ i, ContinuousOn f (s i)) : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ let ⟨i, hi⟩ := hs x; by rw [ContinuousAt, ← nhdsWithin_eq_nhds.2 hi] exact hf _ _ (mem_of_mem_nhds hi) #align continuous_of_cover_nhds continuous_of_cover_nhds theorem continuousOn_empty (f : α → β) : ContinuousOn f ∅ := fun _ => False.elim #align continuous_on_empty continuousOn_empty @[simp] theorem continuousOn_singleton (f : α → β) (a : α) : ContinuousOn f {a} := forall_eq.2 <| by simpa only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_left] using fun s => mem_of_mem_nhds #align continuous_on_singleton continuousOn_singleton theorem Set.Subsingleton.continuousOn {s : Set α} (hs : s.Subsingleton) (f : α → β) : ContinuousOn f s := hs.induction_on (continuousOn_empty f) (continuousOn_singleton f) #align set.subsingleton.continuous_on Set.Subsingleton.continuousOn theorem nhdsWithin_le_comap {x : α} {s : Set α} {f : α → β} (ctsf : ContinuousWithinAt f s x) : 𝓝[s] x ≤ comap f (𝓝[f '' s] f x) := ctsf.tendsto_nhdsWithin_image.le_comap #align nhds_within_le_comap nhdsWithin_le_comap @[simp] theorem comap_nhdsWithin_range {α} (f : α → β) (y : β) : comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range #align comap_nhds_within_range comap_nhdsWithin_range theorem ContinuousWithinAt.mono {f : α → β} {s t : Set α} {x : α} (h : ContinuousWithinAt f t x) (hs : s ⊆ t) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_mono x hs) #align continuous_within_at.mono ContinuousWithinAt.mono theorem ContinuousWithinAt.mono_of_mem {f : α → β} {s t : Set α} {x : α} (h : ContinuousWithinAt f t x) (hs : t ∈ 𝓝[s] x) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_le_of_mem hs) #align continuous_within_at.mono_of_mem ContinuousWithinAt.mono_of_mem theorem continuousWithinAt_congr_nhds {f : α → β} {s t : Set α} {x : α} (h : 𝓝[s] x = 𝓝[t] x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, h] theorem continuousWithinAt_inter' {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝[s] x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict'' s h] #align continuous_within_at_inter' continuousWithinAt_inter' theorem continuousWithinAt_inter {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝 x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict' s h] #align continuous_within_at_inter continuousWithinAt_inter theorem continuousWithinAt_union {f : α → β} {s t : Set α} {x : α} : ContinuousWithinAt f (s ∪ t) x ↔ ContinuousWithinAt f s x ∧ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, nhdsWithin_union, tendsto_sup] #align continuous_within_at_union continuousWithinAt_union theorem ContinuousWithinAt.union {f : α → β} {s t : Set α} {x : α} (hs : ContinuousWithinAt f s x) (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s ∪ t) x := continuousWithinAt_union.2 ⟨hs, ht⟩ #align continuous_within_at.union ContinuousWithinAt.union theorem ContinuousWithinAt.mem_closure_image {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := haveI := mem_closure_iff_nhdsWithin_neBot.1 hx mem_closure_of_tendsto h <| mem_of_superset self_mem_nhdsWithin (subset_preimage_image f s) #align continuous_within_at.mem_closure_image ContinuousWithinAt.mem_closure_image theorem ContinuousWithinAt.mem_closure {f : α → β} {s : Set α} {x : α} {A : Set β} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) (hA : MapsTo f s A) : f x ∈ closure A := closure_mono (image_subset_iff.2 hA) (h.mem_closure_image hx) #align continuous_within_at.mem_closure ContinuousWithinAt.mem_closure theorem Set.MapsTo.closure_of_continuousWithinAt {f : α → β} {s : Set α} {t : Set β} (h : MapsTo f s t) (hc : ∀ x ∈ closure s, ContinuousWithinAt f s x) : MapsTo f (closure s) (closure t) := fun x hx => (hc x hx).mem_closure hx h #align set.maps_to.closure_of_continuous_within_at Set.MapsTo.closure_of_continuousWithinAt theorem Set.MapsTo.closure_of_continuousOn {f : α → β} {s : Set α} {t : Set β} (h : MapsTo f s t) (hc : ContinuousOn f (closure s)) : MapsTo f (closure s) (closure t) := h.closure_of_continuousWithinAt fun x hx => (hc x hx).mono subset_closure #align set.maps_to.closure_of_continuous_on Set.MapsTo.closure_of_continuousOn theorem ContinuousWithinAt.image_closure {f : α → β} {s : Set α} (hf : ∀ x ∈ closure s, ContinuousWithinAt f s x) : f '' closure s ⊆ closure (f '' s) := ((mapsTo_image f s).closure_of_continuousWithinAt hf).image_subset #align continuous_within_at.image_closure ContinuousWithinAt.image_closure theorem ContinuousOn.image_closure {f : α → β} {s : Set α} (hf : ContinuousOn f (closure s)) : f '' closure s ⊆ closure (f '' s) := ContinuousWithinAt.image_closure fun x hx => (hf x hx).mono subset_closure #align continuous_on.image_closure ContinuousOn.image_closure @[simp] theorem continuousWithinAt_singleton {f : α → β} {x : α} : ContinuousWithinAt f {x} x := by simp only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_nhds] #align continuous_within_at_singleton continuousWithinAt_singleton @[simp] theorem continuousWithinAt_insert_self {f : α → β} {x : α} {s : Set α} : ContinuousWithinAt f (insert x s) x ↔ ContinuousWithinAt f s x := by simp only [← singleton_union, continuousWithinAt_union, continuousWithinAt_singleton, true_and_iff] #align continuous_within_at_insert_self continuousWithinAt_insert_self alias ⟨_, ContinuousWithinAt.insert_self⟩ := continuousWithinAt_insert_self #align continuous_within_at.insert_self ContinuousWithinAt.insert_self theorem ContinuousWithinAt.diff_iff {f : α → β} {s t : Set α} {x : α} (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s \ t) x ↔ ContinuousWithinAt f s x := ⟨fun h => (h.union ht).mono <| by simp only [diff_union_self, subset_union_left], fun h => h.mono diff_subset⟩ #align continuous_within_at.diff_iff ContinuousWithinAt.diff_iff @[simp] theorem continuousWithinAt_diff_self {f : α → β} {s : Set α} {x : α} : ContinuousWithinAt f (s \ {x}) x ↔ ContinuousWithinAt f s x := continuousWithinAt_singleton.diff_iff #align continuous_within_at_diff_self continuousWithinAt_diff_self @[simp] theorem continuousWithinAt_compl_self {f : α → β} {a : α} : ContinuousWithinAt f {a}ᶜ a ↔ ContinuousAt f a := by rw [compl_eq_univ_diff, continuousWithinAt_diff_self, continuousWithinAt_univ] #align continuous_within_at_compl_self continuousWithinAt_compl_self @[simp] theorem continuousWithinAt_update_same [DecidableEq α] {f : α → β} {s : Set α} {x : α} {y : β} : ContinuousWithinAt (update f x y) s x ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := calc ContinuousWithinAt (update f x y) s x ↔ Tendsto (update f x y) (𝓝[s \ {x}] x) (𝓝 y) := by { rw [← continuousWithinAt_diff_self, ContinuousWithinAt, update_same] } _ ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := tendsto_congr' <| eventually_nhdsWithin_iff.2 <| eventually_of_forall fun z hz => update_noteq hz.2 _ _ #align continuous_within_at_update_same continuousWithinAt_update_same @[simp] theorem continuousAt_update_same [DecidableEq α] {f : α → β} {x : α} {y : β} : ContinuousAt (Function.update f x y) x ↔ Tendsto f (𝓝[≠] x) (𝓝 y) := by rw [← continuousWithinAt_univ, continuousWithinAt_update_same, compl_eq_univ_diff] #align continuous_at_update_same continuousAt_update_same theorem IsOpenMap.continuousOn_image_of_leftInvOn {f : α → β} {s : Set α} (h : IsOpenMap (s.restrict f)) {finv : β → α} (hleft : LeftInvOn finv f s) : ContinuousOn finv (f '' s) := by refine continuousOn_iff'.2 fun t ht => ⟨f '' (t ∩ s), ?_, ?_⟩ · rw [← image_restrict] exact h _ (ht.preimage continuous_subtype_val) · rw [inter_eq_self_of_subset_left (image_subset f inter_subset_right), hleft.image_inter'] #align is_open_map.continuous_on_image_of_left_inv_on IsOpenMap.continuousOn_image_of_leftInvOn theorem IsOpenMap.continuousOn_range_of_leftInverse {f : α → β} (hf : IsOpenMap f) {finv : β → α} (hleft : Function.LeftInverse finv f) : ContinuousOn finv (range f) := by rw [← image_univ] exact (hf.restrict isOpen_univ).continuousOn_image_of_leftInvOn fun x _ => hleft x #align is_open_map.continuous_on_range_of_left_inverse IsOpenMap.continuousOn_range_of_leftInverse theorem ContinuousOn.congr_mono {f g : α → β} {s s₁ : Set α} (h : ContinuousOn f s) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) : ContinuousOn g s₁ := by intro x hx unfold ContinuousWithinAt have A := (h x (h₁ hx)).mono h₁ unfold ContinuousWithinAt at A rw [← h' hx] at A exact A.congr' h'.eventuallyEq_nhdsWithin.symm #align continuous_on.congr_mono ContinuousOn.congr_mono theorem ContinuousOn.congr {f g : α → β} {s : Set α} (h : ContinuousOn f s) (h' : EqOn g f s) : ContinuousOn g s := h.congr_mono h' (Subset.refl _) #align continuous_on.congr ContinuousOn.congr theorem continuousOn_congr {f g : α → β} {s : Set α} (h' : EqOn g f s) : ContinuousOn g s ↔ ContinuousOn f s := ⟨fun h => ContinuousOn.congr h h'.symm, fun h => h.congr h'⟩ #align continuous_on_congr continuousOn_congr theorem ContinuousAt.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : ContinuousAt f x) : ContinuousWithinAt f s x := ContinuousWithinAt.mono ((continuousWithinAt_univ f x).2 h) (subset_univ _) #align continuous_at.continuous_within_at ContinuousAt.continuousWithinAt theorem continuousWithinAt_iff_continuousAt {f : α → β} {s : Set α} {x : α} (h : s ∈ 𝓝 x) : ContinuousWithinAt f s x ↔ ContinuousAt f x := by rw [← univ_inter s, continuousWithinAt_inter h, continuousWithinAt_univ] #align continuous_within_at_iff_continuous_at continuousWithinAt_iff_continuousAt theorem ContinuousWithinAt.continuousAt {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (hs : s ∈ 𝓝 x) : ContinuousAt f x := (continuousWithinAt_iff_continuousAt hs).mp h #align continuous_within_at.continuous_at ContinuousWithinAt.continuousAt theorem IsOpen.continuousOn_iff {f : α → β} {s : Set α} (hs : IsOpen s) : ContinuousOn f s ↔ ∀ ⦃a⦄, a ∈ s → ContinuousAt f a := forall₂_congr fun _ => continuousWithinAt_iff_continuousAt ∘ hs.mem_nhds #align is_open.continuous_on_iff IsOpen.continuousOn_iff theorem ContinuousOn.continuousAt {f : α → β} {s : Set α} {x : α} (h : ContinuousOn f s) (hx : s ∈ 𝓝 x) : ContinuousAt f x := (h x (mem_of_mem_nhds hx)).continuousAt hx #align continuous_on.continuous_at ContinuousOn.continuousAt theorem ContinuousAt.continuousOn {f : α → β} {s : Set α} (hcont : ∀ x ∈ s, ContinuousAt f x) : ContinuousOn f s := fun x hx => (hcont x hx).continuousWithinAt #align continuous_at.continuous_on ContinuousAt.continuousOn theorem ContinuousWithinAt.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) : ContinuousWithinAt (g ∘ f) s x := hg.tendsto.comp (hf.tendsto_nhdsWithin h) #align continuous_within_at.comp ContinuousWithinAt.comp theorem ContinuousWithinAt.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp (hf.mono inter_subset_left) inter_subset_right #align continuous_within_at.comp' ContinuousWithinAt.comp' theorem ContinuousAt.comp_continuousWithinAt {g : β → γ} {f : α → β} {s : Set α} {x : α} (hg : ContinuousAt g (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) s x := hg.continuousWithinAt.comp hf (mapsTo_univ _ _) #align continuous_at.comp_continuous_within_at ContinuousAt.comp_continuousWithinAt theorem ContinuousOn.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : MapsTo f s t) : ContinuousOn (g ∘ f) s := fun x hx => ContinuousWithinAt.comp (hg _ (h hx)) (hf x hx) h #align continuous_on.comp ContinuousOn.comp @[fun_prop] theorem ContinuousOn.comp'' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : Set.MapsTo f s t) : ContinuousOn (fun x => g (f x)) s := ContinuousOn.comp hg hf h theorem ContinuousOn.mono {f : α → β} {s t : Set α} (hf : ContinuousOn f s) (h : t ⊆ s) : ContinuousOn f t := fun x hx => (hf x (h hx)).mono_left (nhdsWithin_mono _ h) #align continuous_on.mono ContinuousOn.mono theorem antitone_continuousOn {f : α → β} : Antitone (ContinuousOn f) := fun _s _t hst hf => hf.mono hst #align antitone_continuous_on antitone_continuousOn @[fun_prop] theorem ContinuousOn.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right #align continuous_on.comp' ContinuousOn.comp' @[fun_prop] theorem Continuous.continuousOn {f : α → β} {s : Set α} (h : Continuous f) : ContinuousOn f s := by rw [continuous_iff_continuousOn_univ] at h exact h.mono (subset_univ _) #align continuous.continuous_on Continuous.continuousOn theorem Continuous.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : Continuous f) : ContinuousWithinAt f s x := h.continuousAt.continuousWithinAt #align continuous.continuous_within_at Continuous.continuousWithinAt theorem Continuous.comp_continuousOn {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) s := hg.continuousOn.comp hf (mapsTo_univ _ _) #align continuous.comp_continuous_on Continuous.comp_continuousOn @[fun_prop] theorem Continuous.comp_continuousOn' {α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (fun x ↦ g (f x)) s := hg.comp_continuousOn hf theorem ContinuousOn.comp_continuous {g : β → γ} {f : α → β} {s : Set β} (hg : ContinuousOn g s) (hf : Continuous f) (hs : ∀ x, f x ∈ s) : Continuous (g ∘ f) := by rw [continuous_iff_continuousOn_univ] at * exact hg.comp hf fun x _ => hs x #align continuous_on.comp_continuous ContinuousOn.comp_continuous @[fun_prop] theorem continuousOn_apply {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] (i : ι) (s) : ContinuousOn (fun p : ∀ i, π i => p i) s := Continuous.continuousOn (continuous_apply i) theorem ContinuousWithinAt.preimage_mem_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝[s] x := h ht #align continuous_within_at.preimage_mem_nhds_within ContinuousWithinAt.preimage_mem_nhdsWithin theorem Set.LeftInvOn.map_nhdsWithin_eq {f : α → β} {g : β → α} {x : β} {s : Set β} (h : LeftInvOn f g s) (hx : f (g x) = x) (hf : ContinuousWithinAt f (g '' s) (g x)) (hg : ContinuousWithinAt g s x) : map g (𝓝[s] x) = 𝓝[g '' s] g x := by apply le_antisymm · exact hg.tendsto_nhdsWithin (mapsTo_image _ _) · have A : g ∘ f =ᶠ[𝓝[g '' s] g x] id := h.rightInvOn_image.eqOn.eventuallyEq_of_mem self_mem_nhdsWithin refine le_map_of_right_inverse A ?_ simpa only [hx] using hf.tendsto_nhdsWithin (h.mapsTo (surjOn_image _ _)) #align set.left_inv_on.map_nhds_within_eq Set.LeftInvOn.map_nhdsWithin_eq theorem Function.LeftInverse.map_nhds_eq {f : α → β} {g : β → α} {x : β} (h : Function.LeftInverse f g) (hf : ContinuousWithinAt f (range g) (g x)) (hg : ContinuousAt g x) : map g (𝓝 x) = 𝓝[range g] g x := by simpa only [nhdsWithin_univ, image_univ] using (h.leftInvOn univ).map_nhdsWithin_eq (h x) (by rwa [image_univ]) hg.continuousWithinAt #align function.left_inverse.map_nhds_eq Function.LeftInverse.map_nhds_eq theorem ContinuousWithinAt.preimage_mem_nhdsWithin' {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝[f '' s] f x) : f ⁻¹' t ∈ 𝓝[s] x := h.tendsto_nhdsWithin (mapsTo_image _ _) ht #align continuous_within_at.preimage_mem_nhds_within' ContinuousWithinAt.preimage_mem_nhdsWithin' theorem ContinuousWithinAt.preimage_mem_nhdsWithin'' {f : α → β} {x : α} {y : β} {s t : Set β} (h : ContinuousWithinAt f (f ⁻¹' s) x) (ht : t ∈ 𝓝[s] y) (hxy : y = f x) : f ⁻¹' t ∈ 𝓝[f ⁻¹' s] x := by rw [hxy] at ht exact h.preimage_mem_nhdsWithin' (nhdsWithin_mono _ (image_preimage_subset f s) ht) theorem Filter.EventuallyEq.congr_continuousWithinAt {f g : α → β} {s : Set α} {x : α} (h : f =ᶠ[𝓝[s] x] g) (hx : f x = g x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := by rw [ContinuousWithinAt, hx, tendsto_congr' h, ContinuousWithinAt] #align filter.eventually_eq.congr_continuous_within_at Filter.EventuallyEq.congr_continuousWithinAt theorem ContinuousWithinAt.congr_of_eventuallyEq {f f₁ : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContinuousWithinAt f₁ s x := (h₁.congr_continuousWithinAt hx).2 h #align continuous_within_at.congr_of_eventually_eq ContinuousWithinAt.congr_of_eventuallyEq theorem ContinuousWithinAt.congr {f f₁ : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContinuousWithinAt f₁ s x := h.congr_of_eventuallyEq (mem_of_superset self_mem_nhdsWithin h₁) hx #align continuous_within_at.congr ContinuousWithinAt.congr theorem ContinuousWithinAt.congr_mono {f g : α → β} {s s₁ : Set α} {x : α} (h : ContinuousWithinAt f s x) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) (hx : g x = f x) : ContinuousWithinAt g s₁ x := (h.mono h₁).congr h' hx #align continuous_within_at.congr_mono ContinuousWithinAt.congr_mono @[fun_prop] theorem continuousOn_const {s : Set α} {c : β} : ContinuousOn (fun _ => c) s := continuous_const.continuousOn #align continuous_on_const continuousOn_const theorem continuousWithinAt_const {b : β} {s : Set α} {x : α} : ContinuousWithinAt (fun _ : α => b) s x := continuous_const.continuousWithinAt #align continuous_within_at_const continuousWithinAt_const theorem continuousOn_id {s : Set α} : ContinuousOn id s := continuous_id.continuousOn #align continuous_on_id continuousOn_id @[fun_prop] theorem continuousOn_id' (s : Set α) : ContinuousOn (fun x : α => x) s := continuousOn_id theorem continuousWithinAt_id {s : Set α} {x : α} : ContinuousWithinAt id s x := continuous_id.continuousWithinAt #align continuous_within_at_id continuousWithinAt_id theorem continuousOn_open_iff {f : α → β} {s : Set α} (hs : IsOpen s) : ContinuousOn f s ↔ ∀ t, IsOpen t → IsOpen (s ∩ f ⁻¹' t) := by rw [continuousOn_iff'] constructor · intro h t ht rcases h t ht with ⟨u, u_open, hu⟩ rw [inter_comm, hu] apply IsOpen.inter u_open hs · intro h t ht refine ⟨s ∩ f ⁻¹' t, h t ht, ?_⟩ rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self] #align continuous_on_open_iff continuousOn_open_iff theorem ContinuousOn.isOpen_inter_preimage {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ∩ f ⁻¹' t) := (continuousOn_open_iff hs).1 hf t ht #align continuous_on.preimage_open_of_open ContinuousOn.isOpen_inter_preimage theorem ContinuousOn.isOpen_preimage {f : α → β} {s : Set α} {t : Set β} (h : ContinuousOn f s) (hs : IsOpen s) (hp : f ⁻¹' t ⊆ s) (ht : IsOpen t) : IsOpen (f ⁻¹' t) := by convert (continuousOn_open_iff hs).mp h t ht rw [inter_comm, inter_eq_self_of_subset_left hp] #align continuous_on.is_open_preimage ContinuousOn.isOpen_preimage theorem ContinuousOn.preimage_isClosed_of_isClosed {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsClosed s) (ht : IsClosed t) : IsClosed (s ∩ f ⁻¹' t) := by rcases continuousOn_iff_isClosed.1 hf t ht with ⟨u, hu⟩ rw [inter_comm, hu.2] apply IsClosed.inter hu.1 hs #align continuous_on.preimage_closed_of_closed ContinuousOn.preimage_isClosed_of_isClosed theorem ContinuousOn.preimage_interior_subset_interior_preimage {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) : s ∩ f ⁻¹' interior t ⊆ s ∩ interior (f ⁻¹' t) := calc s ∩ f ⁻¹' interior t ⊆ interior (s ∩ f ⁻¹' t) := interior_maximal (inter_subset_inter (Subset.refl _) (preimage_mono interior_subset)) (hf.isOpen_inter_preimage hs isOpen_interior) _ = s ∩ interior (f ⁻¹' t) := by rw [interior_inter, hs.interior_eq] #align continuous_on.preimage_interior_subset_interior_preimage ContinuousOn.preimage_interior_subset_interior_preimage theorem continuousOn_of_locally_continuousOn {f : α → β} {s : Set α} (h : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ContinuousOn f (s ∩ t)) : ContinuousOn f s := by intro x xs rcases h x xs with ⟨t, open_t, xt, ct⟩ have := ct x ⟨xs, xt⟩ rwa [ContinuousWithinAt, ← nhdsWithin_restrict _ xt open_t] at this #align continuous_on_of_locally_continuous_on continuousOn_of_locally_continuousOn -- Porting note (#10756): new lemma theorem continuousOn_to_generateFrom_iff {s : Set α} {T : Set (Set β)} {f : α → β} : @ContinuousOn α β _ (.generateFrom T) f s ↔ ∀ x ∈ s, ∀ t ∈ T, f x ∈ t → f ⁻¹' t ∈ 𝓝[s] x := forall₂_congr fun x _ => by delta ContinuousWithinAt simp only [TopologicalSpace.nhds_generateFrom, tendsto_iInf, tendsto_principal, mem_setOf_eq, and_imp] exact forall_congr' fun t => forall_swap -- Porting note: dropped an unneeded assumption theorem continuousOn_isOpen_of_generateFrom {β : Type*} {s : Set α} {T : Set (Set β)} {f : α → β} (h : ∀ t ∈ T, IsOpen (s ∩ f ⁻¹' t)) : @ContinuousOn α β _ (.generateFrom T) f s := continuousOn_to_generateFrom_iff.2 fun _x hx t ht hxt => mem_nhdsWithin.2 ⟨_, h t ht, ⟨hx, hxt⟩, fun _y hy => hy.1.2⟩ #align continuous_on_open_of_generate_from continuousOn_isOpen_of_generateFromₓ theorem ContinuousWithinAt.prod {f : α → β} {g : α → γ} {s : Set α} {x : α} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) : ContinuousWithinAt (fun x => (f x, g x)) s x := hf.prod_mk_nhds hg #align continuous_within_at.prod ContinuousWithinAt.prod @[fun_prop] theorem ContinuousOn.prod {f : α → β} {g : α → γ} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => (f x, g x)) s := fun x hx => ContinuousWithinAt.prod (hf x hx) (hg x hx) #align continuous_on.prod ContinuousOn.prod theorem ContinuousAt.comp₂_continuousWithinAt {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} (hf : ContinuousAt f (g x, h x)) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := ContinuousAt.comp_continuousWithinAt hf (hg.prod hh) theorem ContinuousAt.comp₂_continuousWithinAt_of_eq {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} {y : β × γ} (hf : ContinuousAt f y) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) (e : (g x, h x) = y) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := by rw [← e] at hf exact hf.comp₂_continuousWithinAt hg hh theorem Inducing.continuousWithinAt_iff {f : α → β} {g : β → γ} (hg : Inducing g) {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (g ∘ f) s x := by simp_rw [ContinuousWithinAt, Inducing.tendsto_nhds_iff hg]; rfl #align inducing.continuous_within_at_iff Inducing.continuousWithinAt_iff
Mathlib/Topology/ContinuousOn.lean
1,165
1,167
theorem Inducing.continuousOn_iff {f : α → β} {g : β → γ} (hg : Inducing g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := by
simp_rw [ContinuousOn, hg.continuousWithinAt_iff]
/- Copyright (c) 2020 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.List.Basic /-! # Properties of `List.reduceOption` In this file we prove basic lemmas about `List.reduceOption`. -/ namespace List variable {α β : Type*} @[simp] theorem reduceOption_cons_of_some (x : α) (l : List (Option α)) : reduceOption (some x :: l) = x :: l.reduceOption := by simp only [reduceOption, filterMap, id, eq_self_iff_true, and_self_iff] #align list.reduce_option_cons_of_some List.reduceOption_cons_of_some @[simp] theorem reduceOption_cons_of_none (l : List (Option α)) : reduceOption (none :: l) = l.reduceOption := by simp only [reduceOption, filterMap, id] #align list.reduce_option_cons_of_none List.reduceOption_cons_of_none @[simp] theorem reduceOption_nil : @reduceOption α [] = [] := rfl #align list.reduce_option_nil List.reduceOption_nil @[simp] theorem reduceOption_map {l : List (Option α)} {f : α → β} : reduceOption (map (Option.map f) l) = map f (reduceOption l) := by induction' l with hd tl hl · simp only [reduceOption_nil, map_nil] · cases hd <;> simpa [true_and_iff, Option.map_some', map, eq_self_iff_true, reduceOption_cons_of_some] using hl #align list.reduce_option_map List.reduceOption_map theorem reduceOption_append (l l' : List (Option α)) : (l ++ l').reduceOption = l.reduceOption ++ l'.reduceOption := filterMap_append l l' id #align list.reduce_option_append List.reduceOption_append theorem reduceOption_length_eq {l : List (Option α)} : l.reduceOption.length = (l.filter Option.isSome).length := by induction' l with hd tl hl · simp_rw [reduceOption_nil, filter_nil, length] · cases hd <;> simp [hl] theorem length_eq_reduceOption_length_add_filter_none {l : List (Option α)} : l.length = l.reduceOption.length + (l.filter Option.isNone).length := by simp_rw [reduceOption_length_eq, l.length_eq_length_filter_add Option.isSome, Option.bnot_isSome] theorem reduceOption_length_le (l : List (Option α)) : l.reduceOption.length ≤ l.length := by rw [length_eq_reduceOption_length_add_filter_none] apply Nat.le_add_right #align list.reduce_option_length_le List.reduceOption_length_le theorem reduceOption_length_eq_iff {l : List (Option α)} : l.reduceOption.length = l.length ↔ ∀ x ∈ l, Option.isSome x := by rw [reduceOption_length_eq, List.filter_length_eq_length] #align list.reduce_option_length_eq_iff List.reduceOption_length_eq_iff
Mathlib/Data/List/ReduceOption.lean
69
74
theorem reduceOption_length_lt_iff {l : List (Option α)} : l.reduceOption.length < l.length ↔ none ∈ l := by
rw [Nat.lt_iff_le_and_ne, and_iff_right (reduceOption_length_le l), Ne, reduceOption_length_eq_iff] induction l <;> simp [*] rw [@eq_comm _ none, ← Option.not_isSome_iff_eq_none, Decidable.imp_iff_not_or]
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.Discriminant import Mathlib.RingTheory.Polynomial.Eisenstein.IsIntegral import Mathlib.RingTheory.Ideal.Norm #align_import number_theory.cyclotomic.rat from "leanprover-community/mathlib"@"b353176c24d96c23f0ce1cc63efc3f55019702d9" /-! # Ring of integers of `p ^ n`-th cyclotomic fields We gather results about cyclotomic extensions of `ℚ`. In particular, we compute the ring of integers of a `p ^ n`-th cyclotomic extension of `ℚ`. ## Main results * `IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime_pow`: if `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. * `IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime_pow`: the integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. * `IsCyclotomicExtension.Rat.absdiscr_prime_pow` and related results: the absolute discriminant of cyclotomic fields. -/ universe u open Algebra IsCyclotomicExtension Polynomial NumberField open scoped Cyclotomic Nat variable {p : ℕ+} {k : ℕ} {K : Type u} [Field K] [CharZero K] {ζ : K} [hp : Fact (p : ℕ).Prime] namespace IsCyclotomicExtension.Rat /-- The discriminant of the power basis given by `ζ - 1`. -/ theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hk : p ^ (k + 1) ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ (k + 1) : ℕ).totient / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by rw [← discr_prime_pow_ne_two hζ (cyclotomic.irreducible_rat (p ^ (k + 1)).pos) hk] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm #align is_cyclotomic_extension.rat.discr_prime_pow_ne_two' IsCyclotomicExtension.Rat.discr_prime_pow_ne_two' theorem discr_odd_prime' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (hodd : p ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by rw [← discr_odd_prime hζ (cyclotomic.irreducible_rat hp.out.pos) hodd] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm #align is_cyclotomic_extension.rat.discr_odd_prime' IsCyclotomicExtension.Rat.discr_odd_prime' /-- The discriminant of the power basis given by `ζ - 1`. Beware that in the cases `p ^ k = 1` and `p ^ k = 2` the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform result. See also `IsCyclotomicExtension.Rat.discr_prime_pow_eq_unit_mul_pow'`. -/ theorem discr_prime_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ k : ℕ).totient / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) := by rw [← discr_prime_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos)] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm #align is_cyclotomic_extension.rat.discr_prime_pow' IsCyclotomicExtension.Rat.discr_prime_pow' /-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then there are `u : ℤˣ` and `n : ℕ` such that the discriminant of the power basis given by `ζ - 1` is `u * p ^ n`. Often this is enough and less cumbersome to use than `IsCyclotomicExtension.Rat.discr_prime_pow'`. -/ theorem discr_prime_pow_eq_unit_mul_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : ∃ (u : ℤˣ) (n : ℕ), discr ℚ (hζ.subOnePowerBasis ℚ).basis = u * p ^ n := by rw [hζ.discr_zeta_eq_discr_zeta_sub_one.symm] exact discr_prime_pow_eq_unit_mul_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos) #align is_cyclotomic_extension.rat.discr_prime_pow_eq_unit_mul_pow' IsCyclotomicExtension.Rat.discr_prime_pow_eq_unit_mul_pow' /-- If `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. -/ theorem isIntegralClosure_adjoin_singleton_of_prime_pow [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : IsIntegralClosure (adjoin ℤ ({ζ} : Set K)) ℤ K := by refine ⟨Subtype.val_injective, @fun x => ⟨fun h => ⟨⟨x, ?_⟩, rfl⟩, ?_⟩⟩ swap · rintro ⟨y, rfl⟩ exact IsIntegral.algebraMap ((le_integralClosure_iff_isIntegral.1 (adjoin_le_integralClosure (hζ.isIntegral (p ^ k).pos))).isIntegral _) let B := hζ.subOnePowerBasis ℚ have hint : IsIntegral ℤ B.gen := (hζ.isIntegral (p ^ k).pos).sub isIntegral_one -- Porting note: the following `haveI` was not needed because the locale `cyclotomic` set it -- as instances. letI := IsCyclotomicExtension.finiteDimensional {p ^ k} ℚ K have H := discr_mul_isIntegral_mem_adjoin ℚ hint h obtain ⟨u, n, hun⟩ := discr_prime_pow_eq_unit_mul_pow' hζ rw [hun] at H replace H := Subalgebra.smul_mem _ H u.inv -- Porting note: the proof is slightly different because of coercions. rw [← smul_assoc, ← smul_mul_assoc, Units.inv_eq_val_inv, zsmul_eq_mul, ← Int.cast_mul, Units.inv_mul, Int.cast_one, one_mul, smul_def, map_pow] at H cases k · haveI : IsCyclotomicExtension {1} ℚ K := by simpa using hcycl have : x ∈ (⊥ : Subalgebra ℚ K) := by rw [singleton_one ℚ K] exact mem_top obtain ⟨y, rfl⟩ := mem_bot.1 this replace h := (isIntegral_algebraMap_iff (algebraMap ℚ K).injective).1 h obtain ⟨z, hz⟩ := IsIntegrallyClosed.isIntegral_iff.1 h rw [← hz, ← IsScalarTower.algebraMap_apply] exact Subalgebra.algebraMap_mem _ _ · have hmin : (minpoly ℤ B.gen).IsEisensteinAt (Submodule.span ℤ {((p : ℕ) : ℤ)}) := by have h₁ := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hint have h₂ := hζ.minpoly_sub_one_eq_cyclotomic_comp (cyclotomic.irreducible_rat (p ^ _).pos) rw [IsPrimitiveRoot.subOnePowerBasis_gen] at h₁ rw [h₁, ← map_cyclotomic_int, show Int.castRingHom ℚ = algebraMap ℤ ℚ by rfl, show X + 1 = map (algebraMap ℤ ℚ) (X + 1) by simp, ← map_comp] at h₂ rw [IsPrimitiveRoot.subOnePowerBasis_gen, map_injective (algebraMap ℤ ℚ) (algebraMap ℤ ℚ).injective_int h₂] exact cyclotomic_prime_pow_comp_X_add_one_isEisensteinAt p _ refine adjoin_le ?_ (mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt (n := n) (Nat.prime_iff_prime_int.1 hp.out) hint h (by simpa using H) hmin) simp only [Set.singleton_subset_iff, SetLike.mem_coe] exact Subalgebra.sub_mem _ (self_mem_adjoin_singleton ℤ _) (Subalgebra.one_mem _) #align is_cyclotomic_extension.rat.is_integral_closure_adjoin_singleton_of_prime_pow IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime_pow theorem isIntegralClosure_adjoin_singleton_of_prime [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : IsIntegralClosure (adjoin ℤ ({ζ} : Set K)) ℤ K := by rw [← pow_one p] at hζ hcycl exact isIntegralClosure_adjoin_singleton_of_prime_pow hζ #align is_cyclotomic_extension.rat.is_integral_closure_adjoin_singleton_of_prime IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime /-- The integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. -/ theorem cyclotomicRing_isIntegralClosure_of_prime_pow : IsIntegralClosure (CyclotomicRing (p ^ k) ℤ ℚ) ℤ (CyclotomicField (p ^ k) ℚ) := by have hζ := zeta_spec (p ^ k) ℚ (CyclotomicField (p ^ k) ℚ) refine ⟨IsFractionRing.injective _ _, @fun x => ⟨fun h => ⟨⟨x, ?_⟩, rfl⟩, ?_⟩⟩ -- Porting note: having `.isIntegral_iff` inside the definition of `this` causes an error. · have := isIntegralClosure_adjoin_singleton_of_prime_pow hζ obtain ⟨y, rfl⟩ := this.isIntegral_iff.1 h refine adjoin_mono ?_ y.2 simp only [PNat.pow_coe, Set.singleton_subset_iff, Set.mem_setOf_eq] exact hζ.pow_eq_one · rintro ⟨y, rfl⟩ exact IsIntegral.algebraMap ((IsCyclotomicExtension.integral {p ^ k} ℤ _).isIntegral _) #align is_cyclotomic_extension.rat.cyclotomic_ring_is_integral_closure_of_prime_pow IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime_pow theorem cyclotomicRing_isIntegralClosure_of_prime : IsIntegralClosure (CyclotomicRing p ℤ ℚ) ℤ (CyclotomicField p ℚ) := by rw [← pow_one p] exact cyclotomicRing_isIntegralClosure_of_prime_pow #align is_cyclotomic_extension.rat.cyclotomic_ring_is_integral_closure_of_prime IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime end IsCyclotomicExtension.Rat section PowerBasis open IsCyclotomicExtension.Rat namespace IsPrimitiveRoot /-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p ^ k`-th root of unity and `K` is a `p ^ k`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : adjoin ℤ ({ζ} : Set K) ≃ₐ[ℤ] 𝓞 K := let _ := isIntegralClosure_adjoin_singleton_of_prime_pow hζ IsIntegralClosure.equiv ℤ (adjoin ℤ ({ζ} : Set K)) K (𝓞 K) #align is_primitive_root.adjoin_equiv_ring_of_integers IsPrimitiveRoot.adjoinEquivRingOfIntegers /-- The ring of integers of a `p ^ k`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance IsCyclotomicExtension.ringOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] : IsCyclotomicExtension {p ^ k} ℤ (𝓞 K) := let _ := (zeta_spec (p ^ k) ℚ K).adjoin_isCyclotomicExtension ℤ IsCyclotomicExtension.equiv _ ℤ _ (zeta_spec (p ^ k) ℚ K).adjoinEquivRingOfIntegers #align is_cyclotomic_extension.ring_of_integers IsPrimitiveRoot.IsCyclotomicExtension.ringOfIntegers /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis ℤ (𝓞 K) := (Algebra.adjoin.powerBasis' (hζ.isIntegral (p ^ k).pos)).map hζ.adjoinEquivRingOfIntegers #align is_primitive_root.integral_power_basis IsPrimitiveRoot.integralPowerBasis /-- Abbreviation to see a primitive root of unity as a member of the ring of integers. -/ abbrev toInteger {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : 𝓞 K := ⟨ζ, hζ.isIntegral k.pos⟩ lemma toInteger_isPrimitiveRoot {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : IsPrimitiveRoot hζ.toInteger k := IsPrimitiveRoot.of_map_of_injective (by exact hζ) RingOfIntegers.coe_injective -- Porting note: the proof changed because `simp` unfolds too much. @[simp] theorem integralPowerBasis_gen [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.gen = hζ.toInteger := Subtype.ext <| show algebraMap _ K hζ.integralPowerBasis.gen = _ by rw [integralPowerBasis, PowerBasis.map_gen, adjoin.powerBasis'_gen] simp only [adjoinEquivRingOfIntegers_apply, IsIntegralClosure.algebraMap_lift] rfl #align is_primitive_root.integral_power_basis_gen IsPrimitiveRoot.integralPowerBasis_gen @[simp] theorem integralPowerBasis_dim [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.dim = φ (p ^ k) := by simp [integralPowerBasis, ← cyclotomic_eq_minpoly hζ, natDegree_cyclotomic] #align is_primitive_root.integral_power_basis_dim IsPrimitiveRoot.integralPowerBasis_dim /-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p`-th root of unity and `K` is a `p`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : adjoin ℤ ({ζ} : Set K) ≃ₐ[ℤ] 𝓞 K := @adjoinEquivRingOfIntegers p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) #align is_primitive_root.adjoin_equiv_ring_of_integers' IsPrimitiveRoot.adjoinEquivRingOfIntegers' /-- The ring of integers of a `p`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance _root_.IsCyclotomicExtension.ring_of_integers' [IsCyclotomicExtension {p} ℚ K] : IsCyclotomicExtension {p} ℤ (𝓞 K) := let _ := (zeta_spec p ℚ K).adjoin_isCyclotomicExtension ℤ IsCyclotomicExtension.equiv _ ℤ _ (zeta_spec p ℚ K).adjoinEquivRingOfIntegers' #align is_cyclotomic_extension.ring_of_integers' IsCyclotomicExtension.ring_of_integers' /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis ℤ (𝓞 K) := @integralPowerBasis p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) #align is_primitive_root.integral_power_basis' IsPrimitiveRoot.integralPowerBasis' @[simp] theorem integralPowerBasis'_gen [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.gen = hζ.toInteger := @integralPowerBasis_gen p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) #align is_primitive_root.integral_power_basis'_gen IsPrimitiveRoot.integralPowerBasis'_gen @[simp] theorem power_basis_int'_dim [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.dim = φ p := by erw [@integralPowerBasis_dim p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]), pow_one] #align is_primitive_root.power_basis_int'_dim IsPrimitiveRoot.power_basis_int'_dim /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis ℤ (𝓞 K) := PowerBasis.ofGenMemAdjoin' hζ.integralPowerBasis (RingOfIntegers.isIntegral _) (by simp only [integralPowerBasis_gen, toInteger] convert Subalgebra.add_mem _ (self_mem_adjoin_singleton ℤ (⟨ζ - 1, _⟩ : 𝓞 K)) (Subalgebra.one_mem _) -- Porting note: `simp` was able to finish the proof. · simp only [Subsemiring.coe_add, Subalgebra.coe_toSubsemiring, OneMemClass.coe_one, sub_add_cancel] · exact Subalgebra.sub_mem _ (hζ.isIntegral (by simp)) (Subalgebra.one_mem _)) #align is_primitive_root.sub_one_integral_power_basis IsPrimitiveRoot.subOneIntegralPowerBasis @[simp] theorem subOneIntegralPowerBasis_gen [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.subOneIntegralPowerBasis.gen = ⟨ζ - 1, Subalgebra.sub_mem _ (hζ.isIntegral (p ^ k).pos) (Subalgebra.one_mem _)⟩ := by simp [subOneIntegralPowerBasis] #align is_primitive_root.sub_one_integral_power_basis_gen IsPrimitiveRoot.subOneIntegralPowerBasis_gen /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis ℤ (𝓞 K) := @subOneIntegralPowerBasis p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) #align is_primitive_root.sub_one_integral_power_basis' IsPrimitiveRoot.subOneIntegralPowerBasis' @[simp] theorem subOneIntegralPowerBasis'_gen [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.subOneIntegralPowerBasis'.gen = hζ.toInteger - 1 := @subOneIntegralPowerBasis_gen p 1 K _ _ _ _ (by convert hcycl; rw [pow_one]) (by rwa [pow_one]) #align is_primitive_root.sub_one_integral_power_basis'_gen IsPrimitiveRoot.subOneIntegralPowerBasis'_gen /-- `ζ - 1` is prime if `p ≠ 2` and `ζ` is a primitive `p ^ (k + 1)`-th root of unity. See `zeta_sub_one_prime` for a general statement. -/ theorem zeta_sub_one_prime_of_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : Prime (hζ.toInteger - 1) := by letI := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K refine Ideal.prime_of_irreducible_absNorm_span (fun h ↦ ?_) ?_ · apply hζ.pow_ne_one_of_pos_of_lt zero_lt_one (one_lt_pow hp.out.one_lt (by simp)) rw [sub_eq_zero] at h simpa using congrArg (algebraMap _ K) h rw [Nat.irreducible_iff_prime, Ideal.absNorm_span_singleton, ← Nat.prime_iff, ← Int.prime_iff_natAbs_prime] convert Nat.prime_iff_prime_int.1 hp.out apply RingHom.injective_int (algebraMap ℤ ℚ) rw [← Algebra.norm_localization (Sₘ := K) ℤ (nonZeroDivisors ℤ)] simp only [PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_natCast] exact hζ.norm_sub_one_of_prime_ne_two (Polynomial.cyclotomic.irreducible_rat (PNat.pos _)) hodd /-- `ζ - 1` is prime if `ζ` is a primitive `2 ^ (k + 1)`-th root of unity. See `zeta_sub_one_prime` for a general statement. -/ theorem zeta_sub_one_prime_of_two_pow [IsCyclotomicExtension {(2 : ℕ+) ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑((2 : ℕ+) ^ (k + 1))) : Prime (hζ.toInteger - 1) := by letI := IsCyclotomicExtension.numberField {(2 : ℕ+) ^ (k + 1)} ℚ K refine Ideal.prime_of_irreducible_absNorm_span (fun h ↦ ?_) ?_ · apply hζ.pow_ne_one_of_pos_of_lt zero_lt_one (one_lt_pow (by decide) (by simp)) rw [sub_eq_zero] at h simpa using congrArg (algebraMap _ K) h rw [Nat.irreducible_iff_prime, Ideal.absNorm_span_singleton, ← Nat.prime_iff, ← Int.prime_iff_natAbs_prime] cases k · convert Prime.neg Int.prime_two apply RingHom.injective_int (algebraMap ℤ ℚ) rw [← Algebra.norm_localization (Sₘ := K) ℤ (nonZeroDivisors ℤ)] simp only [Nat.zero_eq, PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_neg, map_ofNat] simpa only [zero_add, pow_one, AddSubgroupClass.coe_sub, OneMemClass.coe_one, Nat.zero_eq, pow_zero] using hζ.norm_pow_sub_one_two (cyclotomic.irreducible_rat (by simp only [Nat.zero_eq, zero_add, pow_one, Nat.ofNat_pos])) convert Int.prime_two apply RingHom.injective_int (algebraMap ℤ ℚ) rw [← Algebra.norm_localization (Sₘ := K) ℤ (nonZeroDivisors ℤ)] simp only [PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_natCast] exact hζ.norm_sub_one_two Nat.AtLeastTwo.prop (cyclotomic.irreducible_rat (by simp)) /-- `ζ - 1` is prime if `ζ` is a primitive `p ^ (k + 1)`-th root of unity. -/
Mathlib/NumberTheory/Cyclotomic/Rat.lean
328
333
theorem zeta_sub_one_prime [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) : Prime (hζ.toInteger - 1) := by
by_cases htwo : p = 2 · subst htwo apply hζ.zeta_sub_one_prime_of_two_pow · apply hζ.zeta_sub_one_prime_of_ne_two htwo
/- 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.Algebra.BigOperators.Ring import Mathlib.Algebra.Module.BigOperators import Mathlib.NumberTheory.Divisors import Mathlib.Data.Nat.Squarefree import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic.ArithMult #align_import number_theory.arithmetic_function from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Arithmetic Functions and Dirichlet Convolution This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition, to form the Dirichlet ring. ## Main Definitions * `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`. * An arithmetic function `f` `IsMultiplicative` when `x.coprime y → f (x * y) = f x * f y`. * The pointwise operations `pmul` and `ppow` differ from the multiplication and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication. * `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`. * `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`. * `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`. * `id` is the identity arithmetic function on `ℕ`. * `ω n` is the number of distinct prime factors of `n`. * `Ω n` is the number of prime factors of `n` counted with multiplicity. * `μ` is the Möbius function (spelled `moebius` in code). ## Main Results * Several forms of Möbius inversion: * `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero` * And variants that apply when the equalities only hold on a set `S : Set ℕ` such that `m ∣ n → n ∈ S → m ∈ S`: * `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero` ## Notation All notation is localized in the namespace `ArithmeticFunction`. The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names. In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`, `ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`, `ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`, to allow for selective access to these notations. The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation `∏ᵖ p ∣ n, f p` when applied to `n`. ## Tags arithmetic functions, dirichlet convolution, divisors -/ open Finset open Nat variable (R : Type*) /-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by Dirichlet convolution. -/ def ArithmeticFunction [Zero R] := ZeroHom ℕ R #align nat.arithmetic_function ArithmeticFunction instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) := inferInstanceAs (Zero (ZeroHom ℕ R)) instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R)) variable {R} namespace ArithmeticFunction section Zero variable [Zero R] -- porting note: used to be `CoeFun` instance : FunLike (ArithmeticFunction R) ℕ R := inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R) @[simp] theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl #align nat.arithmetic_function.to_fun_eq ArithmeticFunction.toFun_eq @[simp] theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _ (ZeroHom.mk f hf) = f := rfl @[simp] theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 := ZeroHom.map_zero' f #align nat.arithmetic_function.map_zero ArithmeticFunction.map_zero theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g := DFunLike.coe_fn_eq #align nat.arithmetic_function.coe_inj ArithmeticFunction.coe_inj @[simp] theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 := ZeroHom.zero_apply x #align nat.arithmetic_function.zero_apply ArithmeticFunction.zero_apply @[ext] theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g := ZeroHom.ext h #align nat.arithmetic_function.ext ArithmeticFunction.ext theorem ext_iff {f g : ArithmeticFunction R} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align nat.arithmetic_function.ext_iff ArithmeticFunction.ext_iff section One variable [One R] instance one : One (ArithmeticFunction R) := ⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩ theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 := rfl #align nat.arithmetic_function.one_apply ArithmeticFunction.one_apply @[simp] theorem one_one : (1 : ArithmeticFunction R) 1 = 1 := rfl #align nat.arithmetic_function.one_one ArithmeticFunction.one_one @[simp] theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 := if_neg h #align nat.arithmetic_function.one_apply_ne ArithmeticFunction.one_apply_ne end One end Zero /-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline this in `natCoe` because it gets unfolded too much. -/ @[coe] -- Porting note: added `coe` tag. def natToArithmeticFunction [AddMonoidWithOne R] : (ArithmeticFunction ℕ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) := ⟨natToArithmeticFunction⟩ #align nat.arithmetic_function.nat_coe ArithmeticFunction.natCoe @[simp] theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f := ext fun _ => cast_id _ #align nat.arithmetic_function.nat_coe_nat ArithmeticFunction.natCoe_nat @[simp] theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl #align nat.arithmetic_function.nat_coe_apply ArithmeticFunction.natCoe_apply /-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline this in `intCoe` because it gets unfolded too much. -/ @[coe] def ofInt [AddGroupWithOne R] : (ArithmeticFunction ℤ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) := ⟨ofInt⟩ #align nat.arithmetic_function.int_coe ArithmeticFunction.intCoe @[simp] theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f := ext fun _ => Int.cast_id #align nat.arithmetic_function.int_coe_int ArithmeticFunction.intCoe_int @[simp] theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl #align nat.arithmetic_function.int_coe_apply ArithmeticFunction.intCoe_apply @[simp] theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} : ((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by ext simp #align nat.arithmetic_function.coe_coe ArithmeticFunction.coe_coe @[simp] theorem natCoe_one [AddMonoidWithOne R] : ((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] #align nat.arithmetic_function.nat_coe_one ArithmeticFunction.natCoe_one @[simp] theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] #align nat.arithmetic_function.int_coe_one ArithmeticFunction.intCoe_one section AddMonoid variable [AddMonoid R] instance add : Add (ArithmeticFunction R) := ⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩ @[simp] theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n := rfl #align nat.arithmetic_function.add_apply ArithmeticFunction.add_apply instance instAddMonoid : AddMonoid (ArithmeticFunction R) := { ArithmeticFunction.zero R, ArithmeticFunction.add with add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _ zero_add := fun _ => ext fun _ => zero_add _ add_zero := fun _ => ext fun _ => add_zero _ nsmul := nsmulRec } #align nat.arithmetic_function.add_monoid ArithmeticFunction.instAddMonoid end AddMonoid instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid, ArithmeticFunction.one with natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩ natCast_zero := by ext; simp natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] } #align nat.arithmetic_function.add_monoid_with_one ArithmeticFunction.instAddMonoidWithOne instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ } instance [NegZeroClass R] : Neg (ArithmeticFunction R) where neg f := ⟨fun n => -f n, by simp⟩ instance [AddGroup R] : AddGroup (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with add_left_neg := fun _ => ext fun _ => add_left_neg _ zsmul := zsmulRec } instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) := { show AddGroup (ArithmeticFunction R) by infer_instance with add_comm := fun _ _ ↦ add_comm _ _ } section SMul variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M] /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) := ⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩ @[simp] theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} : (f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd := rfl #align nat.arithmetic_function.smul_apply ArithmeticFunction.smul_apply end SMul /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance [Semiring R] : Mul (ArithmeticFunction R) := ⟨(· • ·)⟩ @[simp] theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} : (f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd := rfl #align nat.arithmetic_function.mul_apply ArithmeticFunction.mul_apply theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp #align nat.arithmetic_function.mul_apply_one ArithmeticFunction.mul_apply_one @[simp, norm_cast] theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} : (↑(f * g) : ArithmeticFunction R) = f * g := by ext n simp #align nat.arithmetic_function.nat_coe_mul ArithmeticFunction.natCoe_mul @[simp, norm_cast] theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} : (↑(f * g) : ArithmeticFunction R) = ↑f * g := by ext n simp #align nat.arithmetic_function.int_coe_mul ArithmeticFunction.intCoe_mul section Module variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) : (f * g) • h = f • g • h := by ext n simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc) #align nat.arithmetic_function.mul_smul' ArithmeticFunction.mul_smul' theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by ext x rw [smul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro y ymem ynmem have y1ne : y.fst ≠ 1 := by intro con simp only [Con, mem_divisorsAntidiagonal, one_mul, Ne] at ymem simp only [mem_singleton, Prod.ext_iff] at ynmem -- Porting note: `tauto` worked from here. cases y subst con simp only [true_and, one_mul, x0, not_false_eq_true, and_true] at ynmem ymem tauto simp [y1ne] #align nat.arithmetic_function.one_smul' ArithmeticFunction.one_smul' end Module section Semiring variable [Semiring R] instance instMonoid : Monoid (ArithmeticFunction R) := { one := One.one mul := Mul.mul one_mul := one_smul' mul_one := fun f => by ext x rw [mul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro y ymem ynmem have y2ne : y.snd ≠ 1 := by intro con cases y; subst con -- Porting note: added simp only [Con, mem_divisorsAntidiagonal, mul_one, Ne] at ymem simp only [mem_singleton, Prod.ext_iff] at ynmem tauto simp [y2ne] mul_assoc := mul_smul' } #align nat.arithmetic_function.monoid ArithmeticFunction.instMonoid instance instSemiring : Semiring (ArithmeticFunction R) := -- Porting note: I reorganized this instance { ArithmeticFunction.instAddMonoidWithOne, ArithmeticFunction.instMonoid, ArithmeticFunction.instAddCommMonoid with zero_mul := fun f => by ext simp only [mul_apply, zero_mul, sum_const_zero, zero_apply] mul_zero := fun f => by ext simp only [mul_apply, sum_const_zero, mul_zero, zero_apply] left_distrib := fun a b c => by ext simp only [← sum_add_distrib, mul_add, mul_apply, add_apply] right_distrib := fun a b c => by ext simp only [← sum_add_distrib, add_mul, mul_apply, add_apply] } #align nat.arithmetic_function.semiring ArithmeticFunction.instSemiring end Semiring instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with mul_comm := fun f g => by ext rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map] simp [mul_comm] } instance [CommRing R] : CommRing (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with add_left_neg := add_left_neg mul_comm := mul_comm zsmul := (· • ·) } instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] : Module (ArithmeticFunction R) (ArithmeticFunction M) where one_smul := one_smul' mul_smul := mul_smul' smul_add r x y := by ext simp only [sum_add_distrib, smul_add, smul_apply, add_apply] smul_zero r := by ext simp only [smul_apply, sum_const_zero, smul_zero, zero_apply] add_smul r s x := by ext simp only [add_smul, sum_add_distrib, smul_apply, add_apply] zero_smul r := by ext simp only [smul_apply, sum_const_zero, zero_smul, zero_apply] section Zeta /-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/ def zeta : ArithmeticFunction ℕ := ⟨fun x => ite (x = 0) 0 1, rfl⟩ #align nat.arithmetic_function.zeta ArithmeticFunction.zeta @[inherit_doc] scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta @[inherit_doc] scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta @[simp] theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 := rfl #align nat.arithmetic_function.zeta_apply ArithmeticFunction.zeta_apply theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 := if_neg h #align nat.arithmetic_function.zeta_apply_ne ArithmeticFunction.zeta_apply_ne -- Porting note: removed `@[simp]`, LHS not in normal form theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [Module R M] {f : ArithmeticFunction M} {x : ℕ} : ((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by rw [smul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.snd · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul] · rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk] #align nat.arithmetic_function.coe_zeta_smul_apply ArithmeticFunction.coe_zeta_smul_apply -- Porting note: removed `@[simp]` to make the linter happy. theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (↑ζ * f) x = ∑ i ∈ divisors x, f i := coe_zeta_smul_apply #align nat.arithmetic_function.coe_zeta_mul_apply ArithmeticFunction.coe_zeta_mul_apply -- Porting note: removed `@[simp]` to make the linter happy. theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by rw [mul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.1 · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one] · rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk] #align nat.arithmetic_function.coe_mul_zeta_apply ArithmeticFunction.coe_mul_zeta_apply theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := coe_zeta_mul_apply -- Porting note: was `by rw [← nat_coe_nat ζ, coe_zeta_mul_apply]`. Is this `theorem` obsolete? #align nat.arithmetic_function.zeta_mul_apply ArithmeticFunction.zeta_mul_apply theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := coe_mul_zeta_apply -- Porting note: was `by rw [← natCoe_nat ζ, coe_mul_zeta_apply]`. Is this `theorem` obsolete= #align nat.arithmetic_function.mul_zeta_apply ArithmeticFunction.mul_zeta_apply end Zeta open ArithmeticFunction section Pmul /-- This is the pointwise product of `ArithmeticFunction`s. -/ def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun x => f x * g x, by simp⟩ #align nat.arithmetic_function.pmul ArithmeticFunction.pmul @[simp] theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x := rfl #align nat.arithmetic_function.pmul_apply ArithmeticFunction.pmul_apply theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by ext simp [mul_comm] #align nat.arithmetic_function.pmul_comm ArithmeticFunction.pmul_comm lemma pmul_assoc [CommMonoidWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) : pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by ext simp only [pmul_apply, mul_assoc] section NonAssocSemiring variable [NonAssocSemiring R] @[simp] theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by ext x cases x <;> simp [Nat.succ_ne_zero] #align nat.arithmetic_function.pmul_zeta ArithmeticFunction.pmul_zeta @[simp] theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by ext x cases x <;> simp [Nat.succ_ne_zero] #align nat.arithmetic_function.zeta_pmul ArithmeticFunction.zeta_pmul end NonAssocSemiring variable [Semiring R] /-- This is the pointwise power of `ArithmeticFunction`s. -/ def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R := if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩ #align nat.arithmetic_function.ppow ArithmeticFunction.ppow @[simp] theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl] #align nat.arithmetic_function.ppow_zero ArithmeticFunction.ppow_zero @[simp] theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by rw [ppow, dif_neg (Nat.ne_of_gt kpos)] rfl #align nat.arithmetic_function.ppow_apply ArithmeticFunction.ppow_apply theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ'] induction k <;> simp #align nat.arithmetic_function.ppow_succ ArithmeticFunction.ppow_succ' theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} : f.ppow (k + 1) = (f.ppow k).pmul f := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ] induction k <;> simp #align nat.arithmetic_function.ppow_succ' ArithmeticFunction.ppow_succ end Pmul section Pdiv /-- This is the pointwise division of `ArithmeticFunction`s. -/ def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩ @[simp] theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) : pdiv f g n = f n / g n := rfl /-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/ @[simp] theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) : pdiv f zeta = f := by ext n cases n <;> simp [succ_ne_zero] end Pdiv section ProdPrimeFactors /-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/ def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p map_zero' := if_pos rfl open Batteries.ExtendedBinder /-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/ scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term scoped macro_rules (kind := bigproddvd) | `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n) @[simp] theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f: ℕ → R} {n : ℕ} (hn : n ≠ 0) : ∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p := if_neg hn end ProdPrimeFactors /-- Multiplicative functions -/ def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop := f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n #align nat.arithmetic_function.is_multiplicative ArithmeticFunction.IsMultiplicative namespace IsMultiplicative section MonoidWithZero variable [MonoidWithZero R] @[simp, arith_mult] theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 := h.1 #align nat.arithmetic_function.is_multiplicative.map_one ArithmeticFunction.IsMultiplicative.map_one @[simp] theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ} (h : m.Coprime n) : f (m * n) = f m * f n := hf.2 h #align nat.arithmetic_function.is_multiplicative.map_mul_of_coprime ArithmeticFunction.IsMultiplicative.map_mul_of_coprime end MonoidWithZero theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) : f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by classical induction' s using Finset.induction_on with a s has ih hs · simp [hf] rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1] exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm #align nat.arithmetic_function.is_multiplicative.map_prod ArithmeticFunction.IsMultiplicative.map_prod theorem map_prod_of_prime [CommSemiring R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy theorem map_prod_of_subset_primeFactors [CommSemiring R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ) (t : Finset ℕ) (ht : t ⊆ l.primeFactors) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a) @[arith_mult] theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := -- Porting note: was `by simp [cop, h]` ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ #align nat.arithmetic_function.is_multiplicative.nat_cast ArithmeticFunction.IsMultiplicative.natCast @[deprecated (since := "2024-04-17")] alias nat_cast := natCast @[arith_mult] theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := -- Porting note: was `by simp [cop, h]` ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ #align nat.arithmetic_function.is_multiplicative.int_cast ArithmeticFunction.IsMultiplicative.intCast @[deprecated (since := "2024-04-17")] alias int_cast := intCast @[arith_mult] theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by refine ⟨by simp [hf.1, hg.1], ?_⟩ simp only [mul_apply] intro m n cop rw [sum_mul_sum, ← sum_product'] symm apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l) · rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne] constructor · ring rw [Nat.mul_eq_zero] at * apply not_or_of_not ha hb · simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk.inj_iff] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h simp only [Prod.mk.inj_iff] at h ext <;> dsimp only · trans Nat.gcd (a1 * a2) (a1 * b1) · rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.1, Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · trans Nat.gcd (a1 * a2) (a2 * b2) · rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a1 * b1) · rw [mul_comm, Nat.gcd_mul_right, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a2 * b2) · rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.2, Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Set.mem_image, exists_prop, Prod.mk.inj_iff] rintro ⟨b1, b2⟩ h dsimp at h use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n)) rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _] · rw [Nat.mul_eq_zero, not_or] at h simp [h.2.1, h.2.2] rw [mul_comm n m, h.1] · simp only [mem_divisorsAntidiagonal, Ne, mem_product] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ dsimp only rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right, hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right] ring #align nat.arithmetic_function.is_multiplicative.mul ArithmeticFunction.IsMultiplicative.mul @[arith_mult] theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) := ⟨by simp [hf, hg], fun {m n} cop => by simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop] ring⟩ #align nat.arithmetic_function.is_multiplicative.pmul ArithmeticFunction.IsMultiplicative.pmul @[arith_mult] theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) := ⟨ by simp [hf, hg], fun {m n} cop => by simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop, div_eq_mul_inv, mul_inv] apply mul_mul_mul_comm ⟩ /-- For any multiplicative function `f` and any `n > 0`, we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/ nonrec -- Porting note: added theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) : f n = n.factorization.prod fun p k => f (p ^ k) := multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn #align nat.arithmetic_function.is_multiplicative.multiplicative_factorization ArithmeticFunction.IsMultiplicative.multiplicative_factorization /-- A recapitulation of the definition of multiplicative that is simpler for proofs -/ theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} : IsMultiplicative f ↔ f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩) rcases eq_or_ne m 0 with (rfl | hm) · simp rcases eq_or_ne n 0 with (rfl | hn) · simp exact h hm hn hmn #align nat.arithmetic_function.is_multiplicative.iff_ne_zero ArithmeticFunction.IsMultiplicative.iff_ne_zero /-- Two multiplicative functions `f` and `g` are equal if and only if they agree on prime powers -/ theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) : f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by constructor · intro h p i _ rw [h] intro h ext n by_cases hn : n = 0 · rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero] rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn] exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp) #align nat.arithmetic_function.is_multiplicative.eq_iff_eq_on_prime_powers ArithmeticFunction.IsMultiplicative.eq_iff_eq_on_prime_powers @[arith_mult] theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : IsMultiplicative (prodPrimeFactors f) := by rw [iff_ne_zero] simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one, prod_empty, true_and] intro x y hx hy hxy have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy, Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors] theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) : ∏ᵖ p ∣ n, (f + g) p = (f * g) n := by rw [prodPrimeFactors_apply hn.ne_zero] simp_rw [add_apply (f:=f) (g:=g)] rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·), ← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero, factors_eq] apply Finset.sum_congr rfl intro t ht rw [t.prod_val, Function.id_def, ← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht), hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht), ← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset] theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} : f (x.lcm y) * f (x.gcd y) = f x * f y := by by_cases hx : x = 0 · simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left] by_cases hy : y = 0 · simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul] have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by intro i; rw [Nat.pow_zero, hf.1] iterate 4 rw [hf.multiplicative_factorization f (by assumption), Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero) (s := (x.primeFactors ⊔ y.primeFactors))] · rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib] apply Finset.prod_congr rfl intro p _ rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;> simp only [factorization_lcm hx hy, ge_iff_le, Finsupp.sup_apply, h, sup_of_le_right, sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply, inf_of_le_left, mul_comm] · apply Finset.subset_union_right · apply Finset.subset_union_left · rw [factorization_gcd hx hy, Finsupp.support_inf, Finset.sup_eq_union] apply Finset.inter_subset_union · simp [factorization_lcm hx hy] end IsMultiplicative section SpecialFunctions /-- The identity on `ℕ` as an `ArithmeticFunction`. -/ nonrec -- Porting note (#11445): added def id : ArithmeticFunction ℕ := ⟨id, rfl⟩ #align nat.arithmetic_function.id ArithmeticFunction.id @[simp] theorem id_apply {x : ℕ} : id x = x := rfl #align nat.arithmetic_function.id_apply ArithmeticFunction.id_apply /-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/ def pow (k : ℕ) : ArithmeticFunction ℕ := id.ppow k #align nat.arithmetic_function.pow ArithmeticFunction.pow @[simp] theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by cases k · simp [pow] rename_i k -- Porting note: added simp [pow, k.succ_pos.ne'] #align nat.arithmetic_function.pow_apply ArithmeticFunction.pow_apply theorem pow_zero_eq_zeta : pow 0 = ζ := by ext n simp #align nat.arithmetic_function.pow_zero_eq_zeta ArithmeticFunction.pow_zero_eq_zeta /-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/ def sigma (k : ℕ) : ArithmeticFunction ℕ := ⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩ #align nat.arithmetic_function.sigma ArithmeticFunction.sigma @[inherit_doc] scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma @[inherit_doc] scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k := rfl #align nat.arithmetic_function.sigma_apply ArithmeticFunction.sigma_apply theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply] #align nat.arithmetic_function.sigma_one_apply ArithmeticFunction.sigma_one_apply theorem sigma_zero_apply (n : ℕ) : σ 0 n = (divisors n).card := by simp [sigma_apply] #align nat.arithmetic_function.sigma_zero_apply ArithmeticFunction.sigma_zero_apply theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by rw [sigma_zero_apply, divisors_prime_pow hp, card_map, card_range] #align nat.arithmetic_function.sigma_zero_apply_prime_pow ArithmeticFunction.sigma_zero_apply_prime_pow theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by ext rw [sigma, zeta_mul_apply] apply sum_congr rfl intro x hx rw [pow_apply, if_neg (not_and_of_not_right _ _)] contrapose! hx simp [hx] #align nat.arithmetic_function.zeta_mul_pow_eq_sigma ArithmeticFunction.zeta_mul_pow_eq_sigma @[arith_mult] theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by intro m n hm _hn hmn rcases eq_or_ne m 1 with (rfl | hm') · simp rw [one_apply_ne, one_apply_ne hm', zero_mul] rw [Ne, mul_eq_one, not_and_or] exact Or.inl hm'⟩ #align nat.arithmetic_function.is_multiplicative_one ArithmeticFunction.isMultiplicative_one @[arith_mult] theorem isMultiplicative_zeta : IsMultiplicative ζ := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp (config := { contextual := true })⟩ #align nat.arithmetic_function.is_multiplicative_zeta ArithmeticFunction.isMultiplicative_zeta @[arith_mult] theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id := ⟨rfl, fun {_ _} _ => rfl⟩ #align nat.arithmetic_function.is_multiplicative_id ArithmeticFunction.isMultiplicative_id @[arith_mult] theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {k : ℕ} : IsMultiplicative (f.ppow k) := by induction' k with k hi · exact isMultiplicative_zeta.natCast · rw [ppow_succ'] apply hf.pmul hi #align nat.arithmetic_function.is_multiplicative.ppow ArithmeticFunction.IsMultiplicative.ppow @[arith_mult] theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) := isMultiplicative_id.ppow #align nat.arithmetic_function.is_multiplicative_pow ArithmeticFunction.isMultiplicative_pow @[arith_mult] theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by rw [← zeta_mul_pow_eq_sigma] apply isMultiplicative_zeta.mul isMultiplicative_pow #align nat.arithmetic_function.is_multiplicative_sigma ArithmeticFunction.isMultiplicative_sigma /-- `Ω n` is the number of prime factors of `n`. -/ def cardFactors : ArithmeticFunction ℕ := ⟨fun n => n.factors.length, by simp⟩ #align nat.arithmetic_function.card_factors ArithmeticFunction.cardFactors @[inherit_doc] scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors @[inherit_doc] scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors theorem cardFactors_apply {n : ℕ} : Ω n = n.factors.length := rfl #align nat.arithmetic_function.card_factors_apply ArithmeticFunction.cardFactors_apply lemma cardFactors_zero : Ω 0 = 0 := by simp @[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply] #align nat.arithmetic_function.card_factors_one ArithmeticFunction.cardFactors_one @[simp] theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by refine ⟨fun h => ?_, fun h => List.length_eq_one.2 ⟨n, factors_prime h⟩⟩ cases' n with n · simp at h rcases List.length_eq_one.1 h with ⟨x, hx⟩ rw [← prod_factors n.add_one_ne_zero, hx, List.prod_singleton] apply prime_of_mem_factors rw [hx, List.mem_singleton] #align nat.arithmetic_function.card_factors_eq_one_iff_prime ArithmeticFunction.cardFactors_eq_one_iff_prime theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq, UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq, Multiset.card_add, Multiset.coe_card, Multiset.coe_card] #align nat.arithmetic_function.card_factors_mul ArithmeticFunction.cardFactors_mul theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) : Ω s.prod = (Multiset.map Ω s).sum := by induction s using Multiset.induction_on with | empty => simp | cons ih => simp_all [cardFactors_mul, not_or] #align nat.arithmetic_function.card_factors_multiset_prod ArithmeticFunction.cardFactors_multiset_prod @[simp] theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 := cardFactors_eq_one_iff_prime.2 hp #align nat.arithmetic_function.card_factors_apply_prime ArithmeticFunction.cardFactors_apply_prime @[simp] theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by rw [cardFactors_apply, hp.factors_pow, List.length_replicate] #align nat.arithmetic_function.card_factors_apply_prime_pow ArithmeticFunction.cardFactors_apply_prime_pow /-- `ω n` is the number of distinct prime factors of `n`. -/ def cardDistinctFactors : ArithmeticFunction ℕ := ⟨fun n => n.factors.dedup.length, by simp⟩ #align nat.arithmetic_function.card_distinct_factors ArithmeticFunction.cardDistinctFactors @[inherit_doc] scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors @[inherit_doc] scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors theorem cardDistinctFactors_zero : ω 0 = 0 := by simp #align nat.arithmetic_function.card_distinct_factors_zero ArithmeticFunction.cardDistinctFactors_zero @[simp]
Mathlib/NumberTheory/ArithmeticFunction.lean
1,019
1,019
theorem cardDistinctFactors_one : ω 1 = 0 := by
simp [cardDistinctFactors]
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Analysis.Calculus.BumpFunction.Basic import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar #align_import analysis.calculus.bump_function_inner from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Normed bump function In this file we define `ContDiffBump.normed f μ` to be the bump function `f` normalized so that `∫ x, f.normed μ x ∂μ = 1` and prove some properties of this function. -/ noncomputable section open Function Filter Set Metric MeasureTheory FiniteDimensional Measure open scoped Topology namespace ContDiffBump variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [HasContDiffBump E] [MeasurableSpace E] {c : E} (f : ContDiffBump c) {x : E} {n : ℕ∞} {μ : Measure E} /-- A bump function normed so that `∫ x, f.normed μ x ∂μ = 1`. -/ protected def normed (μ : Measure E) : E → ℝ := fun x => f x / ∫ x, f x ∂μ #align cont_diff_bump.normed ContDiffBump.normed theorem normed_def {μ : Measure E} (x : E) : f.normed μ x = f x / ∫ x, f x ∂μ := rfl #align cont_diff_bump.normed_def ContDiffBump.normed_def theorem nonneg_normed (x : E) : 0 ≤ f.normed μ x := div_nonneg f.nonneg <| integral_nonneg f.nonneg' #align cont_diff_bump.nonneg_normed ContDiffBump.nonneg_normed theorem contDiff_normed {n : ℕ∞} : ContDiff ℝ n (f.normed μ) := f.contDiff.div_const _ #align cont_diff_bump.cont_diff_normed ContDiffBump.contDiff_normed theorem continuous_normed : Continuous (f.normed μ) := f.continuous.div_const _ #align cont_diff_bump.continuous_normed ContDiffBump.continuous_normed theorem normed_sub (x : E) : f.normed μ (c - x) = f.normed μ (c + x) := by simp_rw [f.normed_def, f.sub] #align cont_diff_bump.normed_sub ContDiffBump.normed_sub theorem normed_neg (f : ContDiffBump (0 : E)) (x : E) : f.normed μ (-x) = f.normed μ x := by simp_rw [f.normed_def, f.neg] #align cont_diff_bump.normed_neg ContDiffBump.normed_neg variable [BorelSpace E] [FiniteDimensional ℝ E] [IsLocallyFiniteMeasure μ] protected theorem integrable : Integrable f μ := f.continuous.integrable_of_hasCompactSupport f.hasCompactSupport #align cont_diff_bump.integrable ContDiffBump.integrable protected theorem integrable_normed : Integrable (f.normed μ) μ := f.integrable.div_const _ #align cont_diff_bump.integrable_normed ContDiffBump.integrable_normed variable [μ.IsOpenPosMeasure]
Mathlib/Analysis/Calculus/BumpFunction/Normed.lean
69
72
theorem integral_pos : 0 < ∫ x, f x ∂μ := by
refine (integral_pos_iff_support_of_nonneg f.nonneg' f.integrable).mpr ?_ rw [f.support_eq] exact measure_ball_pos μ c f.rOut_pos
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo, Yaël Dillies, Moritz Doll -/ import Mathlib.Data.Real.Pointwise import Mathlib.Analysis.Convex.Function import Mathlib.Analysis.LocallyConvex.Basic import Mathlib.Data.Real.Sqrt #align_import analysis.seminorm from "leanprover-community/mathlib"@"09079525fd01b3dda35e96adaa08d2f943e1648c" /-! # Seminorms This file defines seminorms. A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and subadditive. They are closely related to convex sets, and a topological vector space is locally convex if and only if its topology is induced by a family of seminorms. ## Main declarations For a module over a normed ring: * `Seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and subadditive. * `normSeminorm 𝕜 E`: The norm on `E` as a seminorm. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags seminorm, locally convex, LCTVS -/ open NormedField Set Filter open scoped NNReal Pointwise Topology Uniformity variable {R R' 𝕜 𝕜₂ 𝕜₃ 𝕝 E E₂ E₃ F G ι : Type*} /-- A seminorm on a module over a normed ring is a function to the reals that is positive semidefinite, positive homogeneous, and subadditive. -/ structure Seminorm (𝕜 : Type*) (E : Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] extends AddGroupSeminorm E where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ smul' : ∀ (a : 𝕜) (x : E), toFun (a • x) = ‖a‖ * toFun x #align seminorm Seminorm attribute [nolint docBlame] Seminorm.toAddGroupSeminorm /-- `SeminormClass F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module `E`. You should extend this class when you extend `Seminorm`. -/ class SeminormClass (F : Type*) (𝕜 E : outParam Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] [FunLike F E ℝ] extends AddGroupSeminormClass F E ℝ : Prop where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x #align seminorm_class SeminormClass export SeminormClass (map_smul_eq_mul) -- Porting note: dangerous instances no longer exist -- attribute [nolint dangerousInstance] SeminormClass.toAddGroupSeminormClass section Of /-- Alternative constructor for a `Seminorm` on an `AddCommGroup E` that is a module over a `SeminormedRing 𝕜`. -/ def Seminorm.of [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (add_le : ∀ x y : E, f (x + y) ≤ f x + f y) (smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) : Seminorm 𝕜 E where toFun := f map_zero' := by rw [← zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul] add_le' := add_le smul' := smul neg' x := by rw [← neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul] #align seminorm.of Seminorm.of /-- Alternative constructor for a `Seminorm` over a normed field `𝕜` that only assumes `f 0 = 0` and an inequality for the scalar multiplication. -/ def Seminorm.ofSMulLE [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (map_zero : f 0 = 0) (add_le : ∀ x y, f (x + y) ≤ f x + f y) (smul_le : ∀ (r : 𝕜) (x), f (r • x) ≤ ‖r‖ * f x) : Seminorm 𝕜 E := Seminorm.of f add_le fun r x => by refine le_antisymm (smul_le r x) ?_ by_cases h : r = 0 · simp [h, map_zero] rw [← mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h))] rw [inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h)] specialize smul_le r⁻¹ (r • x) rw [norm_inv] at smul_le convert smul_le simp [h] #align seminorm.of_smul_le Seminorm.ofSMulLE end Of namespace Seminorm section SeminormedRing variable [SeminormedRing 𝕜] section AddGroup variable [AddGroup E] section SMul variable [SMul 𝕜 E] instance instFunLike : FunLike (Seminorm 𝕜 E) E ℝ where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨_⟩⟩ rcases g with ⟨⟨_⟩⟩ congr instance instSeminormClass : SeminormClass (Seminorm 𝕜 E) 𝕜 E where map_zero f := f.map_zero' map_add_le_add f := f.add_le' map_neg_eq_map f := f.neg' map_smul_eq_mul f := f.smul' #align seminorm.seminorm_class Seminorm.instSeminormClass @[ext] theorem ext {p q : Seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q := DFunLike.ext p q h #align seminorm.ext Seminorm.ext instance instZero : Zero (Seminorm 𝕜 E) := ⟨{ AddGroupSeminorm.instZeroAddGroupSeminorm.zero with smul' := fun _ _ => (mul_zero _).symm }⟩ @[simp] theorem coe_zero : ⇑(0 : Seminorm 𝕜 E) = 0 := rfl #align seminorm.coe_zero Seminorm.coe_zero @[simp] theorem zero_apply (x : E) : (0 : Seminorm 𝕜 E) x = 0 := rfl #align seminorm.zero_apply Seminorm.zero_apply instance : Inhabited (Seminorm 𝕜 E) := ⟨0⟩ variable (p : Seminorm 𝕜 E) (c : 𝕜) (x y : E) (r : ℝ) /-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/ instance instSMul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : SMul R (Seminorm 𝕜 E) where smul r p := { r • p.toAddGroupSeminorm with toFun := fun x => r • p x smul' := fun _ _ => by simp only [← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul] rw [map_smul_eq_mul, mul_left_comm] } instance [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] [SMul R' ℝ] [SMul R' ℝ≥0] [IsScalarTower R' ℝ≥0 ℝ] [SMul R R'] [IsScalarTower R R' ℝ] : IsScalarTower R R' (Seminorm 𝕜 E) where smul_assoc r a p := ext fun x => smul_assoc r a (p x) theorem coe_smul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) : ⇑(r • p) = r • ⇑p := rfl #align seminorm.coe_smul Seminorm.coe_smul @[simp] theorem smul_apply [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) (x : E) : (r • p) x = r • p x := rfl #align seminorm.smul_apply Seminorm.smul_apply instance instAdd : Add (Seminorm 𝕜 E) where add p q := { p.toAddGroupSeminorm + q.toAddGroupSeminorm with toFun := fun x => p x + q x smul' := fun a x => by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add] } theorem coe_add (p q : Seminorm 𝕜 E) : ⇑(p + q) = p + q := rfl #align seminorm.coe_add Seminorm.coe_add @[simp] theorem add_apply (p q : Seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x := rfl #align seminorm.add_apply Seminorm.add_apply instance instAddMonoid : AddMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.addMonoid _ rfl coe_add fun _ _ => by rfl instance instOrderedCancelAddCommMonoid : OrderedCancelAddCommMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.orderedCancelAddCommMonoid _ rfl coe_add fun _ _ => rfl instance instMulAction [Monoid R] [MulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : MulAction R (Seminorm 𝕜 E) := DFunLike.coe_injective.mulAction _ (by intros; rfl) variable (𝕜 E) /-- `coeFn` as an `AddMonoidHom`. Helper definition for showing that `Seminorm 𝕜 E` is a module. -/ @[simps] def coeFnAddMonoidHom : AddMonoidHom (Seminorm 𝕜 E) (E → ℝ) where toFun := (↑) map_zero' := coe_zero map_add' := coe_add #align seminorm.coe_fn_add_monoid_hom Seminorm.coeFnAddMonoidHom theorem coeFnAddMonoidHom_injective : Function.Injective (coeFnAddMonoidHom 𝕜 E) := show @Function.Injective (Seminorm 𝕜 E) (E → ℝ) (↑) from DFunLike.coe_injective #align seminorm.coe_fn_add_monoid_hom_injective Seminorm.coeFnAddMonoidHom_injective variable {𝕜 E} instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : DistribMulAction R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).distribMulAction _ (by intros; rfl) instance instModule [Semiring R] [Module R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : Module R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).module R _ (by intros; rfl) instance instSup : Sup (Seminorm 𝕜 E) where sup p q := { p.toAddGroupSeminorm ⊔ q.toAddGroupSeminorm with toFun := p ⊔ q smul' := fun x v => (congr_arg₂ max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans <| (mul_max_of_nonneg _ _ <| norm_nonneg x).symm } @[simp] theorem coe_sup (p q : Seminorm 𝕜 E) : ⇑(p ⊔ q) = (p : E → ℝ) ⊔ (q : E → ℝ) := rfl #align seminorm.coe_sup Seminorm.coe_sup theorem sup_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x := rfl #align seminorm.sup_apply Seminorm.sup_apply theorem smul_sup [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) : r • (p ⊔ q) = r • p ⊔ r • q := have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y) := fun x y => by simpa only [← smul_eq_mul, ← NNReal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)] using mul_max_of_nonneg x y (r • (1 : ℝ≥0) : ℝ≥0).coe_nonneg ext fun x => real.smul_max _ _ #align seminorm.smul_sup Seminorm.smul_sup instance instPartialOrder : PartialOrder (Seminorm 𝕜 E) := PartialOrder.lift _ DFunLike.coe_injective @[simp, norm_cast] theorem coe_le_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) ≤ q ↔ p ≤ q := Iff.rfl #align seminorm.coe_le_coe Seminorm.coe_le_coe @[simp, norm_cast] theorem coe_lt_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) < q ↔ p < q := Iff.rfl #align seminorm.coe_lt_coe Seminorm.coe_lt_coe theorem le_def {p q : Seminorm 𝕜 E} : p ≤ q ↔ ∀ x, p x ≤ q x := Iff.rfl #align seminorm.le_def Seminorm.le_def theorem lt_def {p q : Seminorm 𝕜 E} : p < q ↔ p ≤ q ∧ ∃ x, p x < q x := @Pi.lt_def _ _ _ p q #align seminorm.lt_def Seminorm.lt_def instance instSemilatticeSup : SemilatticeSup (Seminorm 𝕜 E) := Function.Injective.semilatticeSup _ DFunLike.coe_injective coe_sup end SMul end AddGroup section Module variable [SeminormedRing 𝕜₂] [SeminormedRing 𝕜₃] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} [RingHomIsometric σ₂₃] variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomIsometric σ₁₃] variable [AddCommGroup E] [AddCommGroup E₂] [AddCommGroup E₃] variable [AddCommGroup F] [AddCommGroup G] variable [Module 𝕜 E] [Module 𝕜₂ E₂] [Module 𝕜₃ E₃] [Module 𝕜 F] [Module 𝕜 G] -- Porting note: even though this instance is found immediately by typeclass search, -- it seems to be needed below!? noncomputable instance smul_nnreal_real : SMul ℝ≥0 ℝ := inferInstance variable [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] /-- Composition of a seminorm with a linear map is a seminorm. -/ def comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜 E := { p.toAddGroupSeminorm.comp f.toAddMonoidHom with toFun := fun x => p (f x) -- Porting note: the `simp only` below used to be part of the `rw`. -- I'm not sure why this change was needed, and am worried by it! -- Note: #8386 had to change `map_smulₛₗ` to `map_smulₛₗ _` smul' := fun _ _ => by simp only [map_smulₛₗ _]; rw [map_smul_eq_mul, RingHomIsometric.is_iso] } #align seminorm.comp Seminorm.comp theorem coe_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f := rfl #align seminorm.coe_comp Seminorm.coe_comp @[simp] theorem comp_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) : (p.comp f) x = p (f x) := rfl #align seminorm.comp_apply Seminorm.comp_apply @[simp] theorem comp_id (p : Seminorm 𝕜 E) : p.comp LinearMap.id = p := ext fun _ => rfl #align seminorm.comp_id Seminorm.comp_id @[simp] theorem comp_zero (p : Seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 := ext fun _ => map_zero p #align seminorm.comp_zero Seminorm.comp_zero @[simp] theorem zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : Seminorm 𝕜₂ E₂).comp f = 0 := ext fun _ => rfl #align seminorm.zero_comp Seminorm.zero_comp theorem comp_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (p : Seminorm 𝕜₃ E₃) (g : E₂ →ₛₗ[σ₂₃] E₃) (f : E →ₛₗ[σ₁₂] E₂) : p.comp (g.comp f) = (p.comp g).comp f := ext fun _ => rfl #align seminorm.comp_comp Seminorm.comp_comp theorem add_comp (p q : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : (p + q).comp f = p.comp f + q.comp f := ext fun _ => rfl #align seminorm.add_comp Seminorm.add_comp theorem comp_add_le (p : Seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) : p.comp (f + g) ≤ p.comp f + p.comp g := fun _ => map_add_le_add p _ _ #align seminorm.comp_add_le Seminorm.comp_add_le theorem smul_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) : (c • p).comp f = c • p.comp f := ext fun _ => rfl #align seminorm.smul_comp Seminorm.smul_comp theorem comp_mono {p q : Seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) : p.comp f ≤ q.comp f := fun _ => hp _ #align seminorm.comp_mono Seminorm.comp_mono /-- The composition as an `AddMonoidHom`. -/ @[simps] def pullback (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜₂ E₂ →+ Seminorm 𝕜 E where toFun := fun p => p.comp f map_zero' := zero_comp f map_add' := fun p q => add_comp p q f #align seminorm.pullback Seminorm.pullback instance instOrderBot : OrderBot (Seminorm 𝕜 E) where bot := 0 bot_le := apply_nonneg @[simp] theorem coe_bot : ⇑(⊥ : Seminorm 𝕜 E) = 0 := rfl #align seminorm.coe_bot Seminorm.coe_bot theorem bot_eq_zero : (⊥ : Seminorm 𝕜 E) = 0 := rfl #align seminorm.bot_eq_zero Seminorm.bot_eq_zero theorem smul_le_smul {p q : Seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) : a • p ≤ b • q := by simp_rw [le_def] intro x exact mul_le_mul hab (hpq x) (apply_nonneg p x) (NNReal.coe_nonneg b) #align seminorm.smul_le_smul Seminorm.smul_le_smul theorem finset_sup_apply (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) : s.sup p x = ↑(s.sup fun i => ⟨p i x, apply_nonneg (p i) x⟩ : ℝ≥0) := by induction' s using Finset.cons_induction_on with a s ha ih · rw [Finset.sup_empty, Finset.sup_empty, coe_bot, _root_.bot_eq_zero, Pi.zero_apply] norm_cast · rw [Finset.sup_cons, Finset.sup_cons, coe_sup, sup_eq_max, Pi.sup_apply, sup_eq_max, NNReal.coe_max, NNReal.coe_mk, ih] #align seminorm.finset_sup_apply Seminorm.finset_sup_apply theorem exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) {s : Finset ι} (hs : s.Nonempty) (x : E) : ∃ i ∈ s, s.sup p x = p i x := by rcases Finset.exists_mem_eq_sup s hs (fun i ↦ (⟨p i x, apply_nonneg _ _⟩ : ℝ≥0)) with ⟨i, hi, hix⟩ rw [finset_sup_apply] exact ⟨i, hi, congr_arg _ hix⟩ theorem zero_or_exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) : s.sup p x = 0 ∨ ∃ i ∈ s, s.sup p x = p i x := by rcases Finset.eq_empty_or_nonempty s with (rfl|hs) · left; rfl · right; exact exists_apply_eq_finset_sup p hs x theorem finset_sup_smul (p : ι → Seminorm 𝕜 E) (s : Finset ι) (C : ℝ≥0) : s.sup (C • p) = C • s.sup p := by ext x rw [smul_apply, finset_sup_apply, finset_sup_apply] symm exact congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.mul_finset_sup C s (fun i ↦ ⟨p i x, apply_nonneg _ _⟩)) theorem finset_sup_le_sum (p : ι → Seminorm 𝕜 E) (s : Finset ι) : s.sup p ≤ ∑ i ∈ s, p i := by classical refine Finset.sup_le_iff.mpr ?_ intro i hi rw [Finset.sum_eq_sum_diff_singleton_add hi, le_add_iff_nonneg_left] exact bot_le #align seminorm.finset_sup_le_sum Seminorm.finset_sup_le_sum theorem finset_sup_apply_le {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 ≤ a) (h : ∀ i, i ∈ s → p i x ≤ a) : s.sup p x ≤ a := by lift a to ℝ≥0 using ha rw [finset_sup_apply, NNReal.coe_le_coe] exact Finset.sup_le h #align seminorm.finset_sup_apply_le Seminorm.finset_sup_apply_le theorem le_finset_sup_apply {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {i : ι} (hi : i ∈ s) : p i x ≤ s.sup p x := (Finset.le_sup hi : p i ≤ s.sup p) x theorem finset_sup_apply_lt {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 < a) (h : ∀ i, i ∈ s → p i x < a) : s.sup p x < a := by lift a to ℝ≥0 using ha.le rw [finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff] · exact h · exact NNReal.coe_pos.mpr ha #align seminorm.finset_sup_apply_lt Seminorm.finset_sup_apply_lt theorem norm_sub_map_le_sub (p : Seminorm 𝕜 E) (x y : E) : ‖p x - p y‖ ≤ p (x - y) := abs_sub_map_le_sub p x y #align seminorm.norm_sub_map_le_sub Seminorm.norm_sub_map_le_sub end Module end SeminormedRing section SeminormedCommRing variable [SeminormedRing 𝕜] [SeminormedCommRing 𝕜₂] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable [AddCommGroup E] [AddCommGroup E₂] [Module 𝕜 E] [Module 𝕜₂ E₂] theorem comp_smul (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) : p.comp (c • f) = ‖c‖₊ • p.comp f := ext fun _ => by rw [comp_apply, smul_apply, LinearMap.smul_apply, map_smul_eq_mul, NNReal.smul_def, coe_nnnorm, smul_eq_mul, comp_apply] #align seminorm.comp_smul Seminorm.comp_smul theorem comp_smul_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) (x : E) : p.comp (c • f) x = ‖c‖ * p (f x) := map_smul_eq_mul p _ _ #align seminorm.comp_smul_apply Seminorm.comp_smul_apply end SeminormedCommRing section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {p q : Seminorm 𝕜 E} {x : E} /-- Auxiliary lemma to show that the infimum of seminorms is well-defined. -/ theorem bddBelow_range_add : BddBelow (range fun u => p u + q (x - u)) := ⟨0, by rintro _ ⟨x, rfl⟩ dsimp; positivity⟩ #align seminorm.bdd_below_range_add Seminorm.bddBelow_range_add noncomputable instance instInf : Inf (Seminorm 𝕜 E) where inf p q := { p.toAddGroupSeminorm ⊓ q.toAddGroupSeminorm with toFun := fun x => ⨅ u : E, p u + q (x - u) smul' := by intro a x obtain rfl | ha := eq_or_ne a 0 · rw [norm_zero, zero_mul, zero_smul] refine ciInf_eq_of_forall_ge_of_forall_gt_exists_lt -- Porting note: the following was previously `fun i => by positivity` (fun i => add_nonneg (apply_nonneg _ _) (apply_nonneg _ _)) fun x hx => ⟨0, by rwa [map_zero, sub_zero, map_zero, add_zero]⟩ simp_rw [Real.mul_iInf_of_nonneg (norm_nonneg a), mul_add, ← map_smul_eq_mul p, ← map_smul_eq_mul q, smul_sub] refine Function.Surjective.iInf_congr ((a⁻¹ • ·) : E → E) (fun u => ⟨a • u, inv_smul_smul₀ ha u⟩) fun u => ?_ rw [smul_inv_smul₀ ha] } @[simp] theorem inf_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊓ q) x = ⨅ u : E, p u + q (x - u) := rfl #align seminorm.inf_apply Seminorm.inf_apply noncomputable instance instLattice : Lattice (Seminorm 𝕜 E) := { Seminorm.instSemilatticeSup with inf := (· ⊓ ·) inf_le_left := fun p q x => ciInf_le_of_le bddBelow_range_add x <| by simp only [sub_self, map_zero, add_zero]; rfl inf_le_right := fun p q x => ciInf_le_of_le bddBelow_range_add 0 <| by simp only [sub_self, map_zero, zero_add, sub_zero]; rfl le_inf := fun a b c hab hac x => le_ciInf fun u => (le_map_add_map_sub a _ _).trans <| add_le_add (hab _) (hac _) } theorem smul_inf [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) : r • (p ⊓ q) = r • p ⊓ r • q := by ext simp_rw [smul_apply, inf_apply, smul_apply, ← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul, Real.mul_iInf_of_nonneg (NNReal.coe_nonneg _), mul_add] #align seminorm.smul_inf Seminorm.smul_inf section Classical open scoped Classical /-- We define the supremum of an arbitrary subset of `Seminorm 𝕜 E` as follows: * if `s` is `BddAbove` *as a set of functions `E → ℝ`* (that is, if `s` is pointwise bounded above), we take the pointwise supremum of all elements of `s`, and we prove that it is indeed a seminorm. * otherwise, we take the zero seminorm `⊥`. There are two things worth mentioning here: * First, it is not trivial at first that `s` being bounded above *by a function* implies being bounded above *as a seminorm*. We show this in `Seminorm.bddAbove_iff` by using that the `Sup s` as defined here is then a bounding seminorm for `s`. So it is important to make the case disjunction on `BddAbove ((↑) '' s : Set (E → ℝ))` and not `BddAbove s`. * Since the pointwise `Sup` already gives `0` at points where a family of functions is not bounded above, one could hope that just using the pointwise `Sup` would work here, without the need for an additional case disjunction. As discussed on Zulip, this doesn't work because this can give a function which does *not* satisfy the seminorm axioms (typically sub-additivity). -/ noncomputable instance instSupSet : SupSet (Seminorm 𝕜 E) where sSup s := if h : BddAbove ((↑) '' s : Set (E → ℝ)) then { toFun := ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) map_zero' := by rw [iSup_apply, ← @Real.ciSup_const_zero s] congr! rename_i _ _ _ i exact map_zero i.1 add_le' := fun x y => by rcases h with ⟨q, hq⟩ obtain rfl | h := s.eq_empty_or_nonempty · simp [Real.iSup_of_isEmpty] haveI : Nonempty ↑s := h.coe_sort simp only [iSup_apply] refine ciSup_le fun i => ((i : Seminorm 𝕜 E).add_le' x y).trans <| add_le_add -- Porting note: `f` is provided to force `Subtype.val` to appear. -- A type ascription on `_` would have also worked, but would have been more verbose. (le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun x) ⟨q x, ?_⟩ i) (le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun y) ⟨q y, ?_⟩ i) <;> rw [mem_upperBounds, forall_mem_range] <;> exact fun j => hq (mem_image_of_mem _ j.2) _ neg' := fun x => by simp only [iSup_apply] congr! 2 rename_i _ _ _ i exact i.1.neg' _ smul' := fun a x => by simp only [iSup_apply] rw [← smul_eq_mul, Real.smul_iSup_of_nonneg (norm_nonneg a) fun i : s => (i : Seminorm 𝕜 E) x] congr! rename_i _ _ _ i exact i.1.smul' a x } else ⊥ protected theorem coe_sSup_eq' {s : Set <| Seminorm 𝕜 E} (hs : BddAbove ((↑) '' s : Set (E → ℝ))) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) := congr_arg _ (dif_pos hs) #align seminorm.coe_Sup_eq' Seminorm.coe_sSup_eq' protected theorem bddAbove_iff {s : Set <| Seminorm 𝕜 E} : BddAbove s ↔ BddAbove ((↑) '' s : Set (E → ℝ)) := ⟨fun ⟨q, hq⟩ => ⟨q, forall_mem_image.2 fun p hp => hq hp⟩, fun H => ⟨sSup s, fun p hp x => by dsimp rw [Seminorm.coe_sSup_eq' H, iSup_apply] rcases H with ⟨q, hq⟩ exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq (mem_image_of_mem _ i.2) x⟩ ⟨p, hp⟩⟩⟩ #align seminorm.bdd_above_iff Seminorm.bddAbove_iff protected theorem bddAbove_range_iff {ι : Sort*} {p : ι → Seminorm 𝕜 E} : BddAbove (range p) ↔ ∀ x, BddAbove (range fun i ↦ p i x) := by rw [Seminorm.bddAbove_iff, ← range_comp, bddAbove_range_pi]; rfl protected theorem coe_sSup_eq {s : Set <| Seminorm 𝕜 E} (hs : BddAbove s) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) := Seminorm.coe_sSup_eq' (Seminorm.bddAbove_iff.mp hs) #align seminorm.coe_Sup_eq Seminorm.coe_sSup_eq protected theorem coe_iSup_eq {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) : ↑(⨆ i, p i) = ⨆ i, ((p i : Seminorm 𝕜 E) : E → ℝ) := by rw [← sSup_range, Seminorm.coe_sSup_eq hp] exact iSup_range' (fun p : Seminorm 𝕜 E => (p : E → ℝ)) p #align seminorm.coe_supr_eq Seminorm.coe_iSup_eq protected theorem sSup_apply {s : Set (Seminorm 𝕜 E)} (hp : BddAbove s) {x : E} : (sSup s) x = ⨆ p : s, (p : E → ℝ) x := by rw [Seminorm.coe_sSup_eq hp, iSup_apply] protected theorem iSup_apply {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) {x : E} : (⨆ i, p i) x = ⨆ i, p i x := by rw [Seminorm.coe_iSup_eq hp, iSup_apply] protected theorem sSup_empty : sSup (∅ : Set (Seminorm 𝕜 E)) = ⊥ := by ext rw [Seminorm.sSup_apply bddAbove_empty, Real.iSup_of_isEmpty] rfl private theorem isLUB_sSup (s : Set (Seminorm 𝕜 E)) (hs₁ : BddAbove s) (hs₂ : s.Nonempty) : IsLUB s (sSup s) := by refine ⟨fun p hp x => ?_, fun p hp x => ?_⟩ <;> haveI : Nonempty ↑s := hs₂.coe_sort <;> dsimp <;> rw [Seminorm.coe_sSup_eq hs₁, iSup_apply] · rcases hs₁ with ⟨q, hq⟩ exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq i.2 x⟩ ⟨p, hp⟩ · exact ciSup_le fun q => hp q.2 x /-- `Seminorm 𝕜 E` is a conditionally complete lattice. Note that, while `inf`, `sup` and `sSup` have good definitional properties (corresponding to the instances given here for `Inf`, `Sup` and `SupSet` respectively), `sInf s` is just defined as the supremum of the lower bounds of `s`, which is not really useful in practice. If you need to use `sInf` on seminorms, then you should probably provide a more workable definition first, but this is unlikely to happen so we keep the "bad" definition for now. -/ noncomputable instance instConditionallyCompleteLattice : ConditionallyCompleteLattice (Seminorm 𝕜 E) := conditionallyCompleteLatticeOfLatticeOfsSup (Seminorm 𝕜 E) Seminorm.isLUB_sSup end Classical end NormedField /-! ### Seminorm ball -/ section SeminormedRing variable [SeminormedRing 𝕜] section AddCommGroup variable [AddCommGroup E] section SMul variable [SMul 𝕜 E] (p : Seminorm 𝕜 E) /-- The ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with `p (y - x) < r`. -/ def ball (x : E) (r : ℝ) := { y : E | p (y - x) < r } #align seminorm.ball Seminorm.ball /-- The closed ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with `p (y - x) ≤ r`. -/ def closedBall (x : E) (r : ℝ) := { y : E | p (y - x) ≤ r } #align seminorm.closed_ball Seminorm.closedBall variable {x y : E} {r : ℝ} @[simp] theorem mem_ball : y ∈ ball p x r ↔ p (y - x) < r := Iff.rfl #align seminorm.mem_ball Seminorm.mem_ball @[simp] theorem mem_closedBall : y ∈ closedBall p x r ↔ p (y - x) ≤ r := Iff.rfl #align seminorm.mem_closed_ball Seminorm.mem_closedBall theorem mem_ball_self (hr : 0 < r) : x ∈ ball p x r := by simp [hr] #align seminorm.mem_ball_self Seminorm.mem_ball_self theorem mem_closedBall_self (hr : 0 ≤ r) : x ∈ closedBall p x r := by simp [hr] #align seminorm.mem_closed_ball_self Seminorm.mem_closedBall_self theorem mem_ball_zero : y ∈ ball p 0 r ↔ p y < r := by rw [mem_ball, sub_zero] #align seminorm.mem_ball_zero Seminorm.mem_ball_zero theorem mem_closedBall_zero : y ∈ closedBall p 0 r ↔ p y ≤ r := by rw [mem_closedBall, sub_zero] #align seminorm.mem_closed_ball_zero Seminorm.mem_closedBall_zero theorem ball_zero_eq : ball p 0 r = { y : E | p y < r } := Set.ext fun _ => p.mem_ball_zero #align seminorm.ball_zero_eq Seminorm.ball_zero_eq theorem closedBall_zero_eq : closedBall p 0 r = { y : E | p y ≤ r } := Set.ext fun _ => p.mem_closedBall_zero #align seminorm.closed_ball_zero_eq Seminorm.closedBall_zero_eq theorem ball_subset_closedBall (x r) : ball p x r ⊆ closedBall p x r := fun _ h => (mem_closedBall _).mpr ((mem_ball _).mp h).le #align seminorm.ball_subset_closed_ball Seminorm.ball_subset_closedBall theorem closedBall_eq_biInter_ball (x r) : closedBall p x r = ⋂ ρ > r, ball p x ρ := by ext y; simp_rw [mem_closedBall, mem_iInter₂, mem_ball, ← forall_lt_iff_le'] #align seminorm.closed_ball_eq_bInter_ball Seminorm.closedBall_eq_biInter_ball @[simp] theorem ball_zero' (x : E) (hr : 0 < r) : ball (0 : Seminorm 𝕜 E) x r = Set.univ := by rw [Set.eq_univ_iff_forall, ball] simp [hr] #align seminorm.ball_zero' Seminorm.ball_zero' @[simp] theorem closedBall_zero' (x : E) (hr : 0 < r) : closedBall (0 : Seminorm 𝕜 E) x r = Set.univ := eq_univ_of_subset (ball_subset_closedBall _ _ _) (ball_zero' x hr) #align seminorm.closed_ball_zero' Seminorm.closedBall_zero'
Mathlib/Analysis/Seminorm.lean
723
727
theorem ball_smul (p : Seminorm 𝕜 E) {c : NNReal} (hc : 0 < c) (r : ℝ) (x : E) : (c • p).ball x r = p.ball x (r / c) := by
ext rw [mem_ball, mem_ball, smul_apply, NNReal.smul_def, smul_eq_mul, mul_comm, lt_div_iff (NNReal.coe_pos.mpr hc)]
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.NormedSpace.Star.Spectrum import Mathlib.Analysis.Normed.Group.Quotient import Mathlib.Analysis.NormedSpace.Algebra import Mathlib.Topology.ContinuousFunction.Units import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.ContinuousFunction.Ideals import Mathlib.Topology.ContinuousFunction.StoneWeierstrass #align_import analysis.normed_space.star.gelfand_duality from "leanprover-community/mathlib"@"e65771194f9e923a70dfb49b6ca7be6e400d8b6f" /-! # Gelfand Duality The `gelfandTransform` is an algebra homomorphism from a topological `𝕜`-algebra `A` to `C(characterSpace 𝕜 A, 𝕜)`. In the case where `A` is a commutative complex Banach algebra, then the Gelfand transform is actually spectrum-preserving (`spectrum.gelfandTransform_eq`). Moreover, when `A` is a commutative C⋆-algebra over `ℂ`, then the Gelfand transform is a surjective isometry, and even an equivalence between C⋆-algebras. Consider the contravariant functors between compact Hausdorff spaces and commutative unital C⋆algebras `F : Cpct → CommCStarAlg := X ↦ C(X, ℂ)` and `G : CommCStarAlg → Cpct := A → characterSpace ℂ A` whose actions on morphisms are given by `WeakDual.CharacterSpace.compContinuousMap` and `ContinuousMap.compStarAlgHom'`, respectively. Then `η₁ : id → F ∘ G := gelfandStarTransform` and `η₂ : id → G ∘ F := WeakDual.CharacterSpace.homeoEval` are the natural isomorphisms implementing **Gelfand Duality**, i.e., the (contravariant) equivalence of these categories. ## Main definitions * `Ideal.toCharacterSpace` : constructs an element of the character space from a maximal ideal in a commutative complex Banach algebra * `WeakDual.CharacterSpace.compContinuousMap`: The functorial map taking `ψ : A →⋆ₐ[𝕜] B` to a continuous function `characterSpace 𝕜 B → characterSpace 𝕜 A` given by pre-composition with `ψ`. ## Main statements * `spectrum.gelfandTransform_eq` : the Gelfand transform is spectrum-preserving when the algebra is a commutative complex Banach algebra. * `gelfandTransform_isometry` : the Gelfand transform is an isometry when the algebra is a commutative (unital) C⋆-algebra over `ℂ`. * `gelfandTransform_bijective` : the Gelfand transform is bijective when the algebra is a commutative (unital) C⋆-algebra over `ℂ`. * `gelfandStarTransform_naturality`: The `gelfandStarTransform` is a natural isomorphism * `WeakDual.CharacterSpace.homeoEval_naturality`: This map implements a natural isomorphism ## TODO * After defining the category of commutative unital C⋆-algebras, bundle the existing unbundled **Gelfand duality** into an actual equivalence (duality) of categories associated to the functors `C(·, ℂ)` and `characterSpace ℂ ·` and the natural isomorphisms `gelfandStarTransform` and `WeakDual.CharacterSpace.homeoEval`. ## Tags Gelfand transform, character space, C⋆-algebra -/ open WeakDual open scoped NNReal section ComplexBanachAlgebra open Ideal variable {A : Type*} [NormedCommRing A] [NormedAlgebra ℂ A] [CompleteSpace A] (I : Ideal A) [Ideal.IsMaximal I] /-- Every maximal ideal in a commutative complex Banach algebra gives rise to a character on that algebra. In particular, the character, which may be identified as an algebra homomorphism due to `WeakDual.CharacterSpace.equivAlgHom`, is given by the composition of the quotient map and the Gelfand-Mazur isomorphism `NormedRing.algEquivComplexOfComplete`. -/ noncomputable def Ideal.toCharacterSpace : characterSpace ℂ A := CharacterSpace.equivAlgHom.symm <| ((NormedRing.algEquivComplexOfComplete (letI := Quotient.field I; isUnit_iff_ne_zero (G₀ := A ⧸ I))).symm : A ⧸ I →ₐ[ℂ] ℂ).comp <| Quotient.mkₐ ℂ I #align ideal.to_character_space Ideal.toCharacterSpace
Mathlib/Analysis/NormedSpace/Star/GelfandDuality.lean
88
94
theorem Ideal.toCharacterSpace_apply_eq_zero_of_mem {a : A} (ha : a ∈ I) : I.toCharacterSpace a = 0 := by
unfold Ideal.toCharacterSpace simp only [CharacterSpace.equivAlgHom_symm_coe, AlgHom.coe_comp, AlgHom.coe_coe, Quotient.mkₐ_eq_mk, Function.comp_apply, NormedRing.algEquivComplexOfComplete_symm_apply] simp_rw [Quotient.eq_zero_iff_mem.mpr ha, spectrum.zero_eq] exact Set.eq_of_mem_singleton (Set.singleton_nonempty (0 : ℂ)).some_mem
/- 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.AEMeasurable #align_import measure_theory.group.arithmetic from "leanprover-community/mathlib"@"a75898643b2d774cced9ae7c0b28c21663b99666" /-! # Typeclasses for measurability of operations In this file we define classes `MeasurableMul` etc and prove dot-style lemmas (`Measurable.mul`, `AEMeasurable.mul` etc). For binary operations we define two typeclasses: - `MeasurableMul` says that both left and right multiplication are measurable; - `MeasurableMul₂` says that `fun p : α × α => p.1 * p.2` is measurable, and similarly for other binary operations. The reason for introducing these classes is that in case of topological space `α` equipped with the Borel `σ`-algebra, instances for `MeasurableMul₂` etc require `α` to have a second countable topology. We define separate classes for `MeasurableDiv`/`MeasurableSub` because on some types (e.g., `ℕ`, `ℝ≥0∞`) division and/or subtraction are not defined as `a * b⁻¹` / `a + (-b)`. For instances relating, e.g., `ContinuousMul` to `MeasurableMul` see file `MeasureTheory.BorelSpace`. ## Implementation notes For the heuristics of `@[to_additive]` it is important that the type with a multiplication (or another multiplicative operations) is the first (implicit) argument of all declarations. ## Tags measurable function, arithmetic operator ## Todo * Uniformize the treatment of `pow` and `smul`. * Use `@[to_additive]` to send `MeasurablePow` to `MeasurableSMul₂`. * This might require changing the definition (swapping the arguments in the function that is in the conclusion of `MeasurableSMul`.) -/ open MeasureTheory open scoped Pointwise universe u v variable {α : Type*} /-! ### Binary operations: `(· + ·)`, `(· * ·)`, `(· - ·)`, `(· / ·)` -/ /-- We say that a type has `MeasurableAdd` if `(· + c)` and `(· + c)` are measurable functions. For a typeclass assuming measurability of `uncurry (· + ·)` see `MeasurableAdd₂`. -/ class MeasurableAdd (M : Type*) [MeasurableSpace M] [Add M] : Prop where measurable_const_add : ∀ c : M, Measurable (c + ·) measurable_add_const : ∀ c : M, Measurable (· + c) #align has_measurable_add MeasurableAdd #align has_measurable_add.measurable_const_add MeasurableAdd.measurable_const_add #align has_measurable_add.measurable_add_const MeasurableAdd.measurable_add_const export MeasurableAdd (measurable_const_add measurable_add_const) /-- We say that a type has `MeasurableAdd₂` if `uncurry (· + ·)` is a measurable functions. For a typeclass assuming measurability of `(c + ·)` and `(· + c)` see `MeasurableAdd`. -/ class MeasurableAdd₂ (M : Type*) [MeasurableSpace M] [Add M] : Prop where measurable_add : Measurable fun p : M × M => p.1 + p.2 #align has_measurable_add₂ MeasurableAdd₂ export MeasurableAdd₂ (measurable_add) /-- We say that a type has `MeasurableMul` if `(c * ·)` and `(· * c)` are measurable functions. For a typeclass assuming measurability of `uncurry (*)` see `MeasurableMul₂`. -/ @[to_additive] class MeasurableMul (M : Type*) [MeasurableSpace M] [Mul M] : Prop where measurable_const_mul : ∀ c : M, Measurable (c * ·) measurable_mul_const : ∀ c : M, Measurable (· * c) #align has_measurable_mul MeasurableMul #align has_measurable_mul.measurable_const_mul MeasurableMul.measurable_const_mul #align has_measurable_mul.measurable_mul_const MeasurableMul.measurable_mul_const export MeasurableMul (measurable_const_mul measurable_mul_const) /-- We say that a type has `MeasurableMul₂` if `uncurry (· * ·)` is a measurable functions. For a typeclass assuming measurability of `(c * ·)` and `(· * c)` see `MeasurableMul`. -/ @[to_additive MeasurableAdd₂] class MeasurableMul₂ (M : Type*) [MeasurableSpace M] [Mul M] : Prop where measurable_mul : Measurable fun p : M × M => p.1 * p.2 #align has_measurable_mul₂ MeasurableMul₂ #align has_measurable_mul₂.measurable_mul MeasurableMul₂.measurable_mul export MeasurableMul₂ (measurable_mul) section Mul variable {M α : Type*} [MeasurableSpace M] [Mul M] {m : MeasurableSpace α} {f g : α → M} {μ : Measure α} @[to_additive (attr := measurability)] theorem Measurable.const_mul [MeasurableMul M] (hf : Measurable f) (c : M) : Measurable fun x => c * f x := (measurable_const_mul c).comp hf #align measurable.const_mul Measurable.const_mul #align measurable.const_add Measurable.const_add @[to_additive (attr := measurability)] theorem AEMeasurable.const_mul [MeasurableMul M] (hf : AEMeasurable f μ) (c : M) : AEMeasurable (fun x => c * f x) μ := (MeasurableMul.measurable_const_mul c).comp_aemeasurable hf #align ae_measurable.const_mul AEMeasurable.const_mul #align ae_measurable.const_add AEMeasurable.const_add @[to_additive (attr := measurability)] theorem Measurable.mul_const [MeasurableMul M] (hf : Measurable f) (c : M) : Measurable fun x => f x * c := (measurable_mul_const c).comp hf #align measurable.mul_const Measurable.mul_const #align measurable.add_const Measurable.add_const @[to_additive (attr := measurability)] theorem AEMeasurable.mul_const [MeasurableMul M] (hf : AEMeasurable f μ) (c : M) : AEMeasurable (fun x => f x * c) μ := (measurable_mul_const c).comp_aemeasurable hf #align ae_measurable.mul_const AEMeasurable.mul_const #align ae_measurable.add_const AEMeasurable.add_const @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.mul' [MeasurableMul₂ M] (hf : Measurable f) (hg : Measurable g) : Measurable (f * g) := measurable_mul.comp (hf.prod_mk hg) #align measurable.mul' Measurable.mul' #align measurable.add' Measurable.add' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.mul [MeasurableMul₂ M] (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a * g a := measurable_mul.comp (hf.prod_mk hg) #align measurable.mul Measurable.mul #align measurable.add Measurable.add @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.mul' [MeasurableMul₂ M] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (f * g) μ := measurable_mul.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.mul' AEMeasurable.mul' #align ae_measurable.add' AEMeasurable.add' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.mul [MeasurableMul₂ M] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => f a * g a) μ := measurable_mul.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.mul AEMeasurable.mul #align ae_measurable.add AEMeasurable.add @[to_additive] instance (priority := 100) MeasurableMul₂.toMeasurableMul [MeasurableMul₂ M] : MeasurableMul M := ⟨fun _ => measurable_const.mul measurable_id, fun _ => measurable_id.mul measurable_const⟩ #align has_measurable_mul₂.to_has_measurable_mul MeasurableMul₂.toMeasurableMul #align has_measurable_add₂.to_has_measurable_add MeasurableAdd₂.toMeasurableAdd @[to_additive] instance Pi.measurableMul {ι : Type*} {α : ι → Type*} [∀ i, Mul (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableMul (α i)] : MeasurableMul (∀ i, α i) := ⟨fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).const_mul _, fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).mul_const _⟩ #align pi.has_measurable_mul Pi.measurableMul #align pi.has_measurable_add Pi.measurableAdd @[to_additive Pi.measurableAdd₂] instance Pi.measurableMul₂ {ι : Type*} {α : ι → Type*} [∀ i, Mul (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableMul₂ (α i)] : MeasurableMul₂ (∀ i, α i) := ⟨measurable_pi_iff.mpr fun _ => measurable_fst.eval.mul measurable_snd.eval⟩ #align pi.has_measurable_mul₂ Pi.measurableMul₂ #align pi.has_measurable_add₂ Pi.measurableAdd₂ end Mul /-- A version of `measurable_div_const` that assumes `MeasurableMul` instead of `MeasurableDiv`. This can be nice to avoid unnecessary type-class assumptions. -/ @[to_additive " A version of `measurable_sub_const` that assumes `MeasurableAdd` instead of `MeasurableSub`. This can be nice to avoid unnecessary type-class assumptions. "] theorem measurable_div_const' {G : Type*} [DivInvMonoid G] [MeasurableSpace G] [MeasurableMul G] (g : G) : Measurable fun h => h / g := by simp_rw [div_eq_mul_inv, measurable_mul_const] #align measurable_div_const' measurable_div_const' #align measurable_sub_const' measurable_sub_const' /-- This class assumes that the map `β × γ → β` given by `(x, y) ↦ x ^ y` is measurable. -/ class MeasurablePow (β γ : Type*) [MeasurableSpace β] [MeasurableSpace γ] [Pow β γ] : Prop where measurable_pow : Measurable fun p : β × γ => p.1 ^ p.2 #align has_measurable_pow MeasurablePow export MeasurablePow (measurable_pow) /-- `Monoid.Pow` is measurable. -/ instance Monoid.measurablePow (M : Type*) [Monoid M] [MeasurableSpace M] [MeasurableMul₂ M] : MeasurablePow M ℕ := ⟨measurable_from_prod_countable fun n => by induction' n with n ih · simp only [Nat.zero_eq, pow_zero, ← Pi.one_def, measurable_one] · simp only [pow_succ] exact ih.mul measurable_id⟩ #align monoid.has_measurable_pow Monoid.measurablePow section Pow variable {β γ α : Type*} [MeasurableSpace β] [MeasurableSpace γ] [Pow β γ] [MeasurablePow β γ] {m : MeasurableSpace α} {μ : Measure α} {f : α → β} {g : α → γ} @[aesop safe 20 apply (rule_sets := [Measurable])] theorem Measurable.pow (hf : Measurable f) (hg : Measurable g) : Measurable fun x => f x ^ g x := measurable_pow.comp (hf.prod_mk hg) #align measurable.pow Measurable.pow @[aesop safe 20 apply (rule_sets := [Measurable])] theorem AEMeasurable.pow (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun x => f x ^ g x) μ := measurable_pow.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.pow AEMeasurable.pow @[measurability] theorem Measurable.pow_const (hf : Measurable f) (c : γ) : Measurable fun x => f x ^ c := hf.pow measurable_const #align measurable.pow_const Measurable.pow_const @[measurability] theorem AEMeasurable.pow_const (hf : AEMeasurable f μ) (c : γ) : AEMeasurable (fun x => f x ^ c) μ := hf.pow aemeasurable_const #align ae_measurable.pow_const AEMeasurable.pow_const @[measurability] theorem Measurable.const_pow (hg : Measurable g) (c : β) : Measurable fun x => c ^ g x := measurable_const.pow hg #align measurable.const_pow Measurable.const_pow @[measurability] theorem AEMeasurable.const_pow (hg : AEMeasurable g μ) (c : β) : AEMeasurable (fun x => c ^ g x) μ := aemeasurable_const.pow hg #align ae_measurable.const_pow AEMeasurable.const_pow end Pow /-- We say that a type has `MeasurableSub` if `(c - ·)` and `(· - c)` are measurable functions. For a typeclass assuming measurability of `uncurry (-)` see `MeasurableSub₂`. -/ class MeasurableSub (G : Type*) [MeasurableSpace G] [Sub G] : Prop where measurable_const_sub : ∀ c : G, Measurable (c - ·) measurable_sub_const : ∀ c : G, Measurable (· - c) #align has_measurable_sub MeasurableSub #align has_measurable_sub.measurable_const_sub MeasurableSub.measurable_const_sub #align has_measurable_sub.measurable_sub_const MeasurableSub.measurable_sub_const export MeasurableSub (measurable_const_sub measurable_sub_const) /-- We say that a type has `MeasurableSub₂` if `uncurry (· - ·)` is a measurable functions. For a typeclass assuming measurability of `(c - ·)` and `(· - c)` see `MeasurableSub`. -/ class MeasurableSub₂ (G : Type*) [MeasurableSpace G] [Sub G] : Prop where measurable_sub : Measurable fun p : G × G => p.1 - p.2 #align has_measurable_sub₂ MeasurableSub₂ #align has_measurable_sub₂.measurable_sub MeasurableSub₂.measurable_sub export MeasurableSub₂ (measurable_sub) /-- We say that a type has `MeasurableDiv` if `(c / ·)` and `(· / c)` are measurable functions. For a typeclass assuming measurability of `uncurry (· / ·)` see `MeasurableDiv₂`. -/ @[to_additive] class MeasurableDiv (G₀ : Type*) [MeasurableSpace G₀] [Div G₀] : Prop where measurable_const_div : ∀ c : G₀, Measurable (c / ·) measurable_div_const : ∀ c : G₀, Measurable (· / c) #align has_measurable_div MeasurableDiv #align has_measurable_div.measurable_const_div MeasurableDiv.measurable_div_const #align has_measurable_div.measurable_div_const MeasurableDiv.measurable_div_const export MeasurableDiv (measurable_const_div measurable_div_const) /-- We say that a type has `MeasurableDiv₂` if `uncurry (· / ·)` is a measurable functions. For a typeclass assuming measurability of `(c / ·)` and `(· / c)` see `MeasurableDiv`. -/ @[to_additive MeasurableSub₂] class MeasurableDiv₂ (G₀ : Type*) [MeasurableSpace G₀] [Div G₀] : Prop where measurable_div : Measurable fun p : G₀ × G₀ => p.1 / p.2 #align has_measurable_div₂ MeasurableDiv₂ #align has_measurable_div₂.measurable_div MeasurableDiv₂.measurable_div export MeasurableDiv₂ (measurable_div) section Div variable {G α : Type*} [MeasurableSpace G] [Div G] {m : MeasurableSpace α} {f g : α → G} {μ : Measure α} @[to_additive (attr := measurability)] theorem Measurable.const_div [MeasurableDiv G] (hf : Measurable f) (c : G) : Measurable fun x => c / f x := (MeasurableDiv.measurable_const_div c).comp hf #align measurable.const_div Measurable.const_div #align measurable.const_sub Measurable.const_sub @[to_additive (attr := measurability)] theorem AEMeasurable.const_div [MeasurableDiv G] (hf : AEMeasurable f μ) (c : G) : AEMeasurable (fun x => c / f x) μ := (MeasurableDiv.measurable_const_div c).comp_aemeasurable hf #align ae_measurable.const_div AEMeasurable.const_div #align ae_measurable.const_sub AEMeasurable.const_sub @[to_additive (attr := measurability)] theorem Measurable.div_const [MeasurableDiv G] (hf : Measurable f) (c : G) : Measurable fun x => f x / c := (MeasurableDiv.measurable_div_const c).comp hf #align measurable.div_const Measurable.div_const #align measurable.sub_const Measurable.sub_const @[to_additive (attr := measurability)] theorem AEMeasurable.div_const [MeasurableDiv G] (hf : AEMeasurable f μ) (c : G) : AEMeasurable (fun x => f x / c) μ := (MeasurableDiv.measurable_div_const c).comp_aemeasurable hf #align ae_measurable.div_const AEMeasurable.div_const #align ae_measurable.sub_const AEMeasurable.sub_const @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.div' [MeasurableDiv₂ G] (hf : Measurable f) (hg : Measurable g) : Measurable (f / g) := measurable_div.comp (hf.prod_mk hg) #align measurable.div' Measurable.div' #align measurable.sub' Measurable.sub' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.div [MeasurableDiv₂ G] (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a / g a := measurable_div.comp (hf.prod_mk hg) #align measurable.div Measurable.div #align measurable.sub Measurable.sub @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.div' [MeasurableDiv₂ G] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (f / g) μ := measurable_div.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.div' AEMeasurable.div' #align ae_measurable.sub' AEMeasurable.sub' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.div [MeasurableDiv₂ G] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => f a / g a) μ := measurable_div.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.div AEMeasurable.div #align ae_measurable.sub AEMeasurable.sub @[to_additive] instance (priority := 100) MeasurableDiv₂.toMeasurableDiv [MeasurableDiv₂ G] : MeasurableDiv G := ⟨fun _ => measurable_const.div measurable_id, fun _ => measurable_id.div measurable_const⟩ #align has_measurable_div₂.to_has_measurable_div MeasurableDiv₂.toMeasurableDiv #align has_measurable_sub₂.to_has_measurable_sub MeasurableSub₂.toMeasurableSub @[to_additive] instance Pi.measurableDiv {ι : Type*} {α : ι → Type*} [∀ i, Div (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableDiv (α i)] : MeasurableDiv (∀ i, α i) := ⟨fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).const_div _, fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).div_const _⟩ #align pi.has_measurable_div Pi.measurableDiv #align pi.has_measurable_sub Pi.measurableSub @[to_additive Pi.measurableSub₂] instance Pi.measurableDiv₂ {ι : Type*} {α : ι → Type*} [∀ i, Div (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableDiv₂ (α i)] : MeasurableDiv₂ (∀ i, α i) := ⟨measurable_pi_iff.mpr fun _ => measurable_fst.eval.div measurable_snd.eval⟩ #align pi.has_measurable_div₂ Pi.measurableDiv₂ #align pi.has_measurable_sub₂ Pi.measurableSub₂ @[measurability]
Mathlib/MeasureTheory/Group/Arithmetic.lean
376
383
theorem measurableSet_eq_fun {m : MeasurableSpace α} {E} [MeasurableSpace E] [AddGroup E] [MeasurableSingletonClass E] [MeasurableSub₂ E] {f g : α → E} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { x | f x = g x } := by
suffices h_set_eq : { x : α | f x = g x } = { x | (f - g) x = (0 : E) } by rw [h_set_eq] exact (hf.sub hg) measurableSet_eq ext simp_rw [Set.mem_setOf_eq, Pi.sub_apply, sub_eq_zero]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Yury Kudryashov -/ import Mathlib.Data.Set.Pointwise.SMul #align_import algebra.add_torsor from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Torsors of additive group actions This file defines torsors of additive group actions. ## Notations The group elements are referred to as acting on points. This file defines the notation `+ᵥ` for adding a group element to a point and `-ᵥ` for subtracting two points to produce a group element. ## Implementation notes Affine spaces are the motivating example of torsors of additive group actions. It may be appropriate to refactor in terms of the general definition of group actions, via `to_additive`, when there is a use for multiplicative torsors (currently mathlib only develops the theory of group actions for multiplicative group actions). ## Notations * `v +ᵥ p` is a notation for `VAdd.vadd`, the left action of an additive monoid; * `p₁ -ᵥ p₂` is a notation for `VSub.vsub`, difference between two points in an additive torsor as an element of the corresponding additive group; ## References * https://en.wikipedia.org/wiki/Principal_homogeneous_space * https://en.wikipedia.org/wiki/Affine_space -/ /-- An `AddTorsor G P` gives a structure to the nonempty type `P`, acted on by an `AddGroup G` with a transitive and free action given by the `+ᵥ` operation and a corresponding subtraction given by the `-ᵥ` operation. In the case of a vector space, it is an affine space. -/ class AddTorsor (G : outParam Type*) (P : Type*) [AddGroup G] extends AddAction G P, VSub G P where [nonempty : Nonempty P] /-- Torsor subtraction and addition with the same element cancels out. -/ vsub_vadd' : ∀ p₁ p₂ : P, (p₁ -ᵥ p₂ : G) +ᵥ p₂ = p₁ /-- Torsor addition and subtraction with the same element cancels out. -/ vadd_vsub' : ∀ (g : G) (p : P), g +ᵥ p -ᵥ p = g #align add_torsor AddTorsor -- Porting note(#12096): removed `nolint instance_priority`; lint not ported yet attribute [instance 100] AddTorsor.nonempty -- Porting note(#12094): removed nolint; dangerous_instance linter not ported yet --attribute [nolint dangerous_instance] AddTorsor.toVSub /-- An `AddGroup G` is a torsor for itself. -/ -- Porting note(#12096): linter not ported yet --@[nolint instance_priority] instance addGroupIsAddTorsor (G : Type*) [AddGroup G] : AddTorsor G G where vsub := Sub.sub vsub_vadd' := sub_add_cancel vadd_vsub' := add_sub_cancel_right #align add_group_is_add_torsor addGroupIsAddTorsor /-- Simplify subtraction for a torsor for an `AddGroup G` over itself. -/ @[simp] theorem vsub_eq_sub {G : Type*} [AddGroup G] (g₁ g₂ : G) : g₁ -ᵥ g₂ = g₁ - g₂ := rfl #align vsub_eq_sub vsub_eq_sub section General variable {G : Type*} {P : Type*} [AddGroup G] [T : AddTorsor G P] /-- Adding the result of subtracting from another point produces that point. -/ @[simp] theorem vsub_vadd (p₁ p₂ : P) : p₁ -ᵥ p₂ +ᵥ p₂ = p₁ := AddTorsor.vsub_vadd' p₁ p₂ #align vsub_vadd vsub_vadd /-- Adding a group element then subtracting the original point produces that group element. -/ @[simp] theorem vadd_vsub (g : G) (p : P) : g +ᵥ p -ᵥ p = g := AddTorsor.vadd_vsub' g p #align vadd_vsub vadd_vsub /-- If the same point added to two group elements produces equal results, those group elements are equal. -/ theorem vadd_right_cancel {g₁ g₂ : G} (p : P) (h : g₁ +ᵥ p = g₂ +ᵥ p) : g₁ = g₂ := by -- Porting note: vadd_vsub g₁ → vadd_vsub g₁ p rw [← vadd_vsub g₁ p, h, vadd_vsub] #align vadd_right_cancel vadd_right_cancel @[simp] theorem vadd_right_cancel_iff {g₁ g₂ : G} (p : P) : g₁ +ᵥ p = g₂ +ᵥ p ↔ g₁ = g₂ := ⟨vadd_right_cancel p, fun h => h ▸ rfl⟩ #align vadd_right_cancel_iff vadd_right_cancel_iff /-- Adding a group element to the point `p` is an injective function. -/ theorem vadd_right_injective (p : P) : Function.Injective ((· +ᵥ p) : G → P) := fun _ _ => vadd_right_cancel p #align vadd_right_injective vadd_right_injective /-- Adding a group element to a point, then subtracting another point, produces the same result as subtracting the points then adding the group element. -/ theorem vadd_vsub_assoc (g : G) (p₁ p₂ : P) : g +ᵥ p₁ -ᵥ p₂ = g + (p₁ -ᵥ p₂) := by apply vadd_right_cancel p₂ rw [vsub_vadd, add_vadd, vsub_vadd] #align vadd_vsub_assoc vadd_vsub_assoc /-- Subtracting a point from itself produces 0. -/ @[simp] theorem vsub_self (p : P) : p -ᵥ p = (0 : G) := by rw [← zero_add (p -ᵥ p), ← vadd_vsub_assoc, vadd_vsub] #align vsub_self vsub_self /-- If subtracting two points produces 0, they are equal. -/ theorem eq_of_vsub_eq_zero {p₁ p₂ : P} (h : p₁ -ᵥ p₂ = (0 : G)) : p₁ = p₂ := by rw [← vsub_vadd p₁ p₂, h, zero_vadd] #align eq_of_vsub_eq_zero eq_of_vsub_eq_zero /-- Subtracting two points produces 0 if and only if they are equal. -/ @[simp] theorem vsub_eq_zero_iff_eq {p₁ p₂ : P} : p₁ -ᵥ p₂ = (0 : G) ↔ p₁ = p₂ := Iff.intro eq_of_vsub_eq_zero fun h => h ▸ vsub_self _ #align vsub_eq_zero_iff_eq vsub_eq_zero_iff_eq theorem vsub_ne_zero {p q : P} : p -ᵥ q ≠ (0 : G) ↔ p ≠ q := not_congr vsub_eq_zero_iff_eq #align vsub_ne_zero vsub_ne_zero /-- Cancellation adding the results of two subtractions. -/ @[simp] theorem vsub_add_vsub_cancel (p₁ p₂ p₃ : P) : p₁ -ᵥ p₂ + (p₂ -ᵥ p₃) = p₁ -ᵥ p₃ := by apply vadd_right_cancel p₃ rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd] #align vsub_add_vsub_cancel vsub_add_vsub_cancel /-- Subtracting two points in the reverse order produces the negation of subtracting them. -/ @[simp] theorem neg_vsub_eq_vsub_rev (p₁ p₂ : P) : -(p₁ -ᵥ p₂) = p₂ -ᵥ p₁ := by refine neg_eq_of_add_eq_zero_right (vadd_right_cancel p₁ ?_) rw [vsub_add_vsub_cancel, vsub_self] #align neg_vsub_eq_vsub_rev neg_vsub_eq_vsub_rev theorem vadd_vsub_eq_sub_vsub (g : G) (p q : P) : g +ᵥ p -ᵥ q = g - (q -ᵥ p) := by rw [vadd_vsub_assoc, sub_eq_add_neg, neg_vsub_eq_vsub_rev] #align vadd_vsub_eq_sub_vsub vadd_vsub_eq_sub_vsub /-- Subtracting the result of adding a group element produces the same result as subtracting the points and subtracting that group element. -/ theorem vsub_vadd_eq_vsub_sub (p₁ p₂ : P) (g : G) : p₁ -ᵥ (g +ᵥ p₂) = p₁ -ᵥ p₂ - g := by rw [← add_right_inj (p₂ -ᵥ p₁ : G), vsub_add_vsub_cancel, ← neg_vsub_eq_vsub_rev, vadd_vsub, ← add_sub_assoc, ← neg_vsub_eq_vsub_rev, neg_add_self, zero_sub] #align vsub_vadd_eq_vsub_sub vsub_vadd_eq_vsub_sub /-- Cancellation subtracting the results of two subtractions. -/ @[simp] theorem vsub_sub_vsub_cancel_right (p₁ p₂ p₃ : P) : p₁ -ᵥ p₃ - (p₂ -ᵥ p₃) = p₁ -ᵥ p₂ := by rw [← vsub_vadd_eq_vsub_sub, vsub_vadd] #align vsub_sub_vsub_cancel_right vsub_sub_vsub_cancel_right /-- Convert between an equality with adding a group element to a point and an equality of a subtraction of two points with a group element. -/ theorem eq_vadd_iff_vsub_eq (p₁ : P) (g : G) (p₂ : P) : p₁ = g +ᵥ p₂ ↔ p₁ -ᵥ p₂ = g := ⟨fun h => h.symm ▸ vadd_vsub _ _, fun h => h ▸ (vsub_vadd _ _).symm⟩ #align eq_vadd_iff_vsub_eq eq_vadd_iff_vsub_eq theorem vadd_eq_vadd_iff_neg_add_eq_vsub {v₁ v₂ : G} {p₁ p₂ : P} : v₁ +ᵥ p₁ = v₂ +ᵥ p₂ ↔ -v₁ + v₂ = p₁ -ᵥ p₂ := by rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, ← add_right_inj (-v₁), neg_add_cancel_left, eq_comm] #align vadd_eq_vadd_iff_neg_add_eq_vsub vadd_eq_vadd_iff_neg_add_eq_vsub namespace Set open Pointwise -- porting note (#10618): simp can prove this --@[simp] theorem singleton_vsub_self (p : P) : ({p} : Set P) -ᵥ {p} = {(0 : G)} := by rw [Set.singleton_vsub_singleton, vsub_self] #align set.singleton_vsub_self Set.singleton_vsub_self end Set @[simp] theorem vadd_vsub_vadd_cancel_right (v₁ v₂ : G) (p : P) : v₁ +ᵥ p -ᵥ (v₂ +ᵥ p) = v₁ - v₂ := by rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero] #align vadd_vsub_vadd_cancel_right vadd_vsub_vadd_cancel_right /-- If the same point subtracted from two points produces equal results, those points are equal. -/ theorem vsub_left_cancel {p₁ p₂ p : P} (h : p₁ -ᵥ p = p₂ -ᵥ p) : p₁ = p₂ := by rwa [← sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h #align vsub_left_cancel vsub_left_cancel /-- The same point subtracted from two points produces equal results if and only if those points are equal. -/ @[simp] theorem vsub_left_cancel_iff {p₁ p₂ p : P} : p₁ -ᵥ p = p₂ -ᵥ p ↔ p₁ = p₂ := ⟨vsub_left_cancel, fun h => h ▸ rfl⟩ #align vsub_left_cancel_iff vsub_left_cancel_iff /-- Subtracting the point `p` is an injective function. -/ theorem vsub_left_injective (p : P) : Function.Injective ((· -ᵥ p) : P → G) := fun _ _ => vsub_left_cancel #align vsub_left_injective vsub_left_injective /-- If subtracting two points from the same point produces equal results, those points are equal. -/ theorem vsub_right_cancel {p₁ p₂ p : P} (h : p -ᵥ p₁ = p -ᵥ p₂) : p₁ = p₂ := by refine vadd_left_cancel (p -ᵥ p₂) ?_ rw [vsub_vadd, ← h, vsub_vadd] #align vsub_right_cancel vsub_right_cancel /-- Subtracting two points from the same point produces equal results if and only if those points are equal. -/ @[simp] theorem vsub_right_cancel_iff {p₁ p₂ p : P} : p -ᵥ p₁ = p -ᵥ p₂ ↔ p₁ = p₂ := ⟨vsub_right_cancel, fun h => h ▸ rfl⟩ #align vsub_right_cancel_iff vsub_right_cancel_iff /-- Subtracting a point from the point `p` is an injective function. -/ theorem vsub_right_injective (p : P) : Function.Injective ((p -ᵥ ·) : P → G) := fun _ _ => vsub_right_cancel #align vsub_right_injective vsub_right_injective end General section comm variable {G : Type*} {P : Type*} [AddCommGroup G] [AddTorsor G P] /-- Cancellation subtracting the results of two subtractions. -/ @[simp]
Mathlib/Algebra/AddTorsor.lean
251
252
theorem vsub_sub_vsub_cancel_left (p₁ p₂ p₃ : P) : p₃ -ᵥ p₂ - (p₃ -ᵥ p₁) = p₁ -ᵥ p₂ := by
rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.Topology.Algebra.Module.WeakDual import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction import Mathlib.MeasureTheory.Measure.HasOuterApproxClosed #align_import measure_theory.measure.finite_measure from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Finite measures This file defines the type of finite measures on a given measurable space. When the underlying space has a topology and the measurable space structure (sigma algebra) is finer than the Borel sigma algebra, then the type of finite measures is equipped with the topology of weak convergence of measures. The topology of weak convergence is the coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued function `f`, the integration of `f` against the measure is continuous. ## Main definitions The main definitions are * `MeasureTheory.FiniteMeasure Ω`: The type of finite measures on `Ω` with the topology of weak convergence of measures. * `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))`: Interpret a finite measure as a continuous linear functional on the space of bounded continuous nonnegative functions on `Ω`. This is used for the definition of the topology of weak convergence. * `MeasureTheory.FiniteMeasure.map`: The push-forward `f* μ` of a finite measure `μ` on `Ω` along a measurable function `f : Ω → Ω'`. * `MeasureTheory.FiniteMeasure.mapCLM`: The push-forward along a given continuous `f : Ω → Ω'` as a continuous linear map `f* : FiniteMeasure Ω →L[ℝ≥0] FiniteMeasure Ω'`. ## Main results * Finite measures `μ` on `Ω` give rise to continuous linear functionals on the space of bounded continuous nonnegative functions on `Ω` via integration: `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))` * `MeasureTheory.FiniteMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of finite measures is characterized by the convergence of integrals of all bounded continuous functions. This shows that the chosen definition of topology coincides with the common textbook definition of weak convergence of measures. A similar characterization by the convergence of integrals (in the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative functions is `MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto`. * `MeasureTheory.FiniteMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the push-forward of finite measures `f* : FiniteMeasure Ω → FiniteMeasure Ω'` is continuous. * `MeasureTheory.FiniteMeasure.t2Space`: The topology of weak convergence of finite Borel measures is Hausdorff on spaces where indicators of closed sets have continuous decreasing approximating sequences (in particular on any pseudo-metrizable spaces). ## Implementation notes The topology of weak convergence of finite Borel measures is defined using a mapping from `MeasureTheory.FiniteMeasure Ω` to `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)`, inheriting the topology from the latter. The implementation of `MeasureTheory.FiniteMeasure Ω` and is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`. Another alternative would have been to use a bijection with `MeasureTheory.VectorMeasure Ω ℝ≥0` as an intermediate step. Some considerations: * Potential advantages of using the `NNReal`-valued vector measure alternative: * The coercion to function would avoid need to compose with `ENNReal.toNNReal`, the `NNReal`-valued API could be more directly available. * Potential drawbacks of the vector measure alternative: * The coercion to function would lose monotonicity, as non-measurable sets would be defined to have measure 0. * No integration theory directly. E.g., the topology definition requires `MeasureTheory.lintegral` w.r.t. a coercion to `MeasureTheory.Measure Ω` in any case. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, finite measure -/ noncomputable section open MeasureTheory open Set open Filter open BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory namespace FiniteMeasure section FiniteMeasure /-! ### Finite measures In this section we define the `Type` of `MeasureTheory.FiniteMeasure Ω`, when `Ω` is a measurable space. Finite measures on `Ω` are a module over `ℝ≥0`. If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.FiniteMeasure Ω` is equipped with the topology of weak convergence of measures. This is implemented by defining a pairing of finite measures `μ` on `Ω` with continuous bounded nonnegative functions `f : Ω →ᵇ ℝ≥0` via integration, and using the associated weak topology (essentially the weak-star topology on the dual of `Ω →ᵇ ℝ≥0`). -/ variable {Ω : Type*} [MeasurableSpace Ω] /-- Finite measures are defined as the subtype of measures that have the property of being finite measures (i.e., their total mass is finite). -/ def _root_.MeasureTheory.FiniteMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ := { μ : Measure Ω // IsFiniteMeasure μ } #align measure_theory.finite_measure MeasureTheory.FiniteMeasure -- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`, we need a new function for the -- coercion instead of relying on `Subtype.val`. /-- Coercion from `MeasureTheory.FiniteMeasure Ω` to `MeasureTheory.Measure Ω`. -/ @[coe] def toMeasure : FiniteMeasure Ω → Measure Ω := Subtype.val /-- A finite measure can be interpreted as a measure. -/ instance instCoe : Coe (FiniteMeasure Ω) (MeasureTheory.Measure Ω) where coe := toMeasure instance isFiniteMeasure (μ : FiniteMeasure Ω) : IsFiniteMeasure (μ : Measure Ω) := μ.prop #align measure_theory.finite_measure.is_finite_measure MeasureTheory.FiniteMeasure.isFiniteMeasure @[simp] theorem val_eq_toMeasure (ν : FiniteMeasure Ω) : ν.val = (ν : Measure Ω) := rfl #align measure_theory.finite_measure.val_eq_to_measure MeasureTheory.FiniteMeasure.val_eq_toMeasure theorem toMeasure_injective : Function.Injective ((↑) : FiniteMeasure Ω → Measure Ω) := Subtype.coe_injective #align measure_theory.finite_measure.coe_injective MeasureTheory.FiniteMeasure.toMeasure_injective instance instFunLike : FunLike (FiniteMeasure Ω) (Set Ω) ℝ≥0 where coe μ s := ((μ : Measure Ω) s).toNNReal coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s lemma coeFn_def (μ : FiniteMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl #align measure_theory.finite_measure.coe_fn_eq_to_nnreal_coe_fn_to_measure MeasureTheory.FiniteMeasure.coeFn_def lemma coeFn_mk (μ : Measure Ω) (hμ) : DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl @[simp, norm_cast] lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) : DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl @[simp] theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : FiniteMeasure Ω) (s : Set Ω) : (ν s : ℝ≥0∞) = (ν : Measure Ω) s := ENNReal.coe_toNNReal (measure_lt_top (↑ν) s).ne #align measure_theory.finite_measure.ennreal_coe_fn_eq_coe_fn_to_measure MeasureTheory.FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure theorem apply_mono (μ : FiniteMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by change ((μ : Measure Ω) s₁).toNNReal ≤ ((μ : Measure Ω) s₂).toNNReal have key : (μ : Measure Ω) s₁ ≤ (μ : Measure Ω) s₂ := (μ : Measure Ω).mono h apply (ENNReal.toNNReal_le_toNNReal (measure_ne_top _ s₁) (measure_ne_top _ s₂)).mpr key #align measure_theory.finite_measure.apply_mono MeasureTheory.FiniteMeasure.apply_mono /-- The (total) mass of a finite measure `μ` is `μ univ`, i.e., the cast to `NNReal` of `(μ : measure Ω) univ`. -/ def mass (μ : FiniteMeasure Ω) : ℝ≥0 := μ univ #align measure_theory.finite_measure.mass MeasureTheory.FiniteMeasure.mass @[simp] theorem apply_le_mass (μ : FiniteMeasure Ω) (s : Set Ω) : μ s ≤ μ.mass := by simpa using apply_mono μ (subset_univ s) @[simp] theorem ennreal_mass {μ : FiniteMeasure Ω} : (μ.mass : ℝ≥0∞) = (μ : Measure Ω) univ := ennreal_coeFn_eq_coeFn_toMeasure μ Set.univ #align measure_theory.finite_measure.ennreal_mass MeasureTheory.FiniteMeasure.ennreal_mass instance instZero : Zero (FiniteMeasure Ω) where zero := ⟨0, MeasureTheory.isFiniteMeasureZero⟩ #align measure_theory.finite_measure.has_zero MeasureTheory.FiniteMeasure.instZero @[simp, norm_cast] lemma coeFn_zero : ⇑(0 : FiniteMeasure Ω) = 0 := rfl #align measure_theory.finite_measure.coe_fn_zero MeasureTheory.FiniteMeasure.coeFn_zero @[simp] theorem zero_mass : (0 : FiniteMeasure Ω).mass = 0 := rfl #align measure_theory.finite_measure.zero.mass MeasureTheory.FiniteMeasure.zero_mass @[simp] theorem mass_zero_iff (μ : FiniteMeasure Ω) : μ.mass = 0 ↔ μ = 0 := by refine ⟨fun μ_mass => ?_, fun hμ => by simp only [hμ, zero_mass]⟩ apply toMeasure_injective apply Measure.measure_univ_eq_zero.mp rwa [← ennreal_mass, ENNReal.coe_eq_zero] #align measure_theory.finite_measure.mass_zero_iff MeasureTheory.FiniteMeasure.mass_zero_iff theorem mass_nonzero_iff (μ : FiniteMeasure Ω) : μ.mass ≠ 0 ↔ μ ≠ 0 := by rw [not_iff_not] exact FiniteMeasure.mass_zero_iff μ #align measure_theory.finite_measure.mass_nonzero_iff MeasureTheory.FiniteMeasure.mass_nonzero_iff @[ext] theorem eq_of_forall_toMeasure_apply_eq (μ ν : FiniteMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by apply Subtype.ext ext1 s s_mble exact h s s_mble #align measure_theory.finite_measure.eq_of_forall_measure_apply_eq MeasureTheory.FiniteMeasure.eq_of_forall_toMeasure_apply_eq
Mathlib/MeasureTheory/Measure/FiniteMeasure.lean
220
223
theorem eq_of_forall_apply_eq (μ ν : FiniteMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by
ext1 s s_mble simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble)
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.InnerProductSpace.Symmetric import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Algebra.DirectSum.Decomposition #align_import analysis.inner_product_space.projection from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b" /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `orthogonalProjection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = orthogonalProjection K u` in `K` minimizes the distance `‖u - v‖` to `u`. Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `reflection K u` to satisfy `u + (reflection K u) = 2 • orthogonalProjection K u`. Basic API for `orthogonalProjection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma `Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open LinearMap (ker range) open Topology variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "absR" => abs /-! ### Orthogonal projection in inner product spaces -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. /-- Existence of minimizers Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/ theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K) (h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by let δ := ⨅ w : K, ‖u - w‖ letI : Nonempty K := ne.to_subtype have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _ have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩ have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩ -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n => lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat have h := fun n => exists_lt_of_ciInf_lt (hδ n) let w : ℕ → K := fun n => Classical.choose (h n) exact ⟨w, fun n => Classical.choose_spec (h n)⟩ rcases exists_seq with ⟨w, hw⟩ have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by convert h.add tendsto_one_div_add_atTop_nhds_zero_nat simp only [add_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _) -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : CauchySeq fun n => (w n : F) := by rw [cauchySeq_iff_le_tendsto_0] -- splits into three goals let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1)) use fun n => √(b n) constructor -- first goal : `∀ (n : ℕ), 0 ≤ √(b n)` · intro n exact sqrt_nonneg _ constructor -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)` · intro p q N hp hq let wp := (w p : F) let wq := (w q : F) let a := u - wq let b := u - wp let half := 1 / (2 : ℝ) let div := 1 / ((N : ℝ) + 1) have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := calc 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by ring _ = absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by rw [_root_.abs_of_nonneg] exact zero_le_two _ = ‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ + ‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul] _ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul] simp only [one_smul] have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm have eq₂ : u + u - (wq + wp) = a + b := by show u + u - (wq + wp) = u - wq + (u - wp) abel rw [eq₁, eq₂] _ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _ have eq : δ ≤ ‖u - half • (wq + wp)‖ := by rw [smul_add] apply δ_le' apply h₂ repeat' exact Subtype.mem _ repeat' exact le_of_lt one_half_pos exact add_halves 1 have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp_rw [mul_assoc] gcongr have eq₂ : ‖a‖ ≤ δ + div := le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _) have eq₂' : ‖b‖ ≤ δ + div := le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _) rw [dist_eq_norm] apply nonneg_le_nonneg_of_sq_le_sq · exact sqrt_nonneg _ rw [mul_self_sqrt] · calc ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp [← this] _ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr _ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr _ = 8 * δ * div + 4 * div * div := by ring positivity -- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)` suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0) from this.comp tendsto_one_div_add_atTop_nhds_zero_nat exact Continuous.tendsto' (by continuity) _ _ (by simp) -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩ use v use hv have h_cont : Continuous fun v => ‖u - v‖ := Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id) have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by convert Tendsto.comp h_cont.continuousAt w_tendsto exact tendsto_nhds_unique this norm_tendsto #align exists_norm_eq_infi_of_complete_convex exists_norm_eq_iInf_of_complete_convex /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by letI : Nonempty K := ⟨⟨v, hv⟩⟩ constructor · intro eq w hw let δ := ⨅ w : K, ‖u - w‖ let p := ⟪u - v, w - v⟫_ℝ let q := ‖w - v‖ ^ 2 have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _ have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩ have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 := calc ‖u - v‖ ^ 2 _ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _) rw [eq]; apply δ_le' apply h hw hv exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _] _ = ‖u - v - θ • (w - v)‖ ^ 2 := by have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by rw [smul_sub, sub_smul, one_smul] simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] rw [this] _ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul] simp only [sq] show ‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) + absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) = ‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖) rw [abs_of_pos hθ₁]; ring have eq₁ : ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 = ‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by abel rw [eq₁, le_add_iff_nonneg_right] at this have eq₂ : θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) = θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring rw [eq₂] at this have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁) exact this by_cases hq : q = 0 · rw [hq] at this have : p ≤ 0 := by have := this (1 : ℝ) (by norm_num) (by norm_num) linarith exact this · have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm by_contra hp rw [not_le] at hp let θ := min (1 : ℝ) (p / q) have eq₁ : θ * q ≤ p := calc θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) _ = p := div_mul_cancel₀ _ hq have : 2 * p ≤ p := calc 2 * p ≤ θ * q := by set_option tactic.skipAssignedInstances false in exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ]) _ ≤ p := eq₁ linarith · intro h apply le_antisymm · apply le_ciInf intro w apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) have := h w w.2 calc ‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith _ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by rw [sq] refine le_add_of_nonneg_right ?_ exact sq_nonneg _ _ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm _ = ‖u - w‖ * ‖u - w‖ := by have : u - v - (w - v) = u - w := by abel rw [this, sq] · show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩ apply ciInf_le use 0 rintro y ⟨z, rfl⟩ exact norm_nonneg _ #align norm_eq_infi_iff_real_inner_le_zero norm_eq_iInf_iff_real_inner_le_zero variable (K : Submodule 𝕜 E) /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex #align exists_norm_eq_infi_of_complete_subspace exists_norm_eq_iInf_of_complete_subspace /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superceded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over any `RCLike` field. -/ theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := Iff.intro (by intro h have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by rwa [norm_eq_iInf_iff_real_inner_le_zero] at h exacts [K.convex, hv] intro w hw have le : ⟪u - v, w⟫_ℝ ≤ 0 := by let w' := w + v have : w' ∈ K := Submodule.add_mem _ hw hv have h₁ := h w' this have h₂ : w' - v = w := by simp only [w', add_neg_cancel_right, sub_eq_add_neg] rw [h₂] at h₁ exact h₁ have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by let w'' := -w + v have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv have h₁ := h w'' this have h₂ : w'' - v = -w := by simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg] rw [h₂, inner_neg_right] at h₁ linarith exact le_antisymm le ge) (by intro h have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by intro w hw let w' := w - v have : w' ∈ K := Submodule.sub_mem _ hw hv have h₁ := h w' this exact le_of_eq h₁ rwa [norm_eq_iInf_iff_real_inner_le_zero] exacts [Submodule.convex _, hv]) #align norm_eq_infi_iff_real_inner_eq_zero norm_eq_iInf_iff_real_inner_eq_zero /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := K.restrictScalars ℝ constructor · intro H have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_iInf_iff_real_inner_eq_zero K' hv).1 H intro w hw apply ext · simp [A w hw] · symm calc im (0 : 𝕜) = 0 := im.map_zero _ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm _ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right] _ = im ⟪u - v, w⟫ := by simp · intro H have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by intro w hw rw [real_inner_eq_re_inner, H w hw] exact zero_re' exact (norm_eq_iInf_iff_real_inner_eq_zero K' hv).2 this #align norm_eq_infi_iff_inner_eq_zero norm_eq_iInf_iff_inner_eq_zero /-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if evey vector `v : E` admits an orthogonal projection to `K`. -/ class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] : HasOrthogonalProjection K where exists_orthogonal v := by rcases exists_norm_eq_iInf_of_complete_subspace K (completeSpace_coe_iff_isComplete.mp ‹_›) v with ⟨w, hwK, hw⟩ refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩ rwa [← norm_eq_iInf_iff_inner_eq_zero K hwK] instance [HasOrthogonalProjection K] : HasOrthogonalProjection Kᗮ where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩ refine ⟨_, hw, ?_⟩ rw [sub_sub_cancel] exact K.le_orthogonal_orthogonal hwK instance HasOrthogonalProjection.map_linearIsometryEquiv [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩ refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩ erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu] instance HasOrthogonalProjection.map_linearIsometryEquiv' [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map f.toLinearIsometry) := HasOrthogonalProjection.map_linearIsometryEquiv K f instance : HasOrthogonalProjection (⊤ : Submodule 𝕜 E) := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩ section orthogonalProjection variable [HasOrthogonalProjection K] /-- The orthogonal projection onto a complete subspace, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (v : E) := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose #align orthogonal_projection_fn orthogonalProjectionFn variable {K} /-- The unbundled orthogonal projection is in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem (v : E) : orthogonalProjectionFn K v ∈ K := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left #align orthogonal_projection_fn_mem orthogonalProjectionFn_mem /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjectionFn K v, w⟫ = 0 := (K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right #align orthogonal_projection_fn_inner_eq_zero orthogonalProjectionFn_inner_eq_zero /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonalProjectionFn K u = v := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hvs : orthogonalProjectionFn K u - v ∈ K := Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm have huo : ⟪u - orthogonalProjectionFn K u, orthogonalProjectionFn K u - v⟫ = 0 := orthogonalProjectionFn_inner_eq_zero u _ hvs have huv : ⟪u - v, orthogonalProjectionFn K u - v⟫ = 0 := hvo _ hvs have houv : ⟪u - v - (u - orthogonalProjectionFn K u), orthogonalProjectionFn K u - v⟫ = 0 := by rw [inner_sub_left, huo, huv, sub_zero] rwa [sub_sub_sub_cancel_left] at houv #align eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero variable (K) theorem orthogonalProjectionFn_norm_sq (v : E) : ‖v‖ * ‖v‖ = ‖v - orthogonalProjectionFn K v‖ * ‖v - orthogonalProjectionFn K v‖ + ‖orthogonalProjectionFn K v‖ * ‖orthogonalProjectionFn K v‖ := by set p := orthogonalProjectionFn K v have h' : ⟪v - p, p⟫ = 0 := orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v) convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp #align orthogonal_projection_fn_norm_sq orthogonalProjectionFn_norm_sq /-- The orthogonal projection onto a complete subspace. -/ def orthogonalProjection : E →L[𝕜] K := LinearMap.mkContinuous { toFun := fun v => ⟨orthogonalProjectionFn K v, orthogonalProjectionFn_mem v⟩ map_add' := fun x y => by have hm : orthogonalProjectionFn K x + orthogonalProjectionFn K y ∈ K := Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y) have ho : ∀ w ∈ K, ⟪x + y - (orthogonalProjectionFn K x + orthogonalProjectionFn K y), w⟫ = 0 := by intro w hw rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw, orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] map_smul' := fun c x => by have hm : c • orthogonalProjectionFn K x ∈ K := Submodule.smul_mem K _ (orthogonalProjectionFn_mem x) have ho : ∀ w ∈ K, ⟪c • x - c • orthogonalProjectionFn K x, w⟫ = 0 := by intro w hw rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw, mul_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] } 1 fun x => by simp only [one_mul, LinearMap.coe_mk] refine le_of_pow_le_pow_left two_ne_zero (norm_nonneg _) ?_ change ‖orthogonalProjectionFn K x‖ ^ 2 ≤ ‖x‖ ^ 2 nlinarith [orthogonalProjectionFn_norm_sq K x] #align orthogonal_projection orthogonalProjection variable {K} @[simp] theorem orthogonalProjectionFn_eq (v : E) : orthogonalProjectionFn K v = (orthogonalProjection K v : E) := rfl #align orthogonal_projection_fn_eq orthogonalProjectionFn_eq /-- The characterization of the orthogonal projection. -/ @[simp] theorem orthogonalProjection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjection K v, w⟫ = 0 := orthogonalProjectionFn_inner_eq_zero v #align orthogonal_projection_inner_eq_zero orthogonalProjection_inner_eq_zero /-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/ @[simp] theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - orthogonalProjection K v ∈ Kᗮ := by intro w hw rw [inner_eq_zero_symm] exact orthogonalProjection_inner_eq_zero _ _ hw #align sub_orthogonal_projection_mem_orthogonal sub_orthogonalProjection_mem_orthogonal /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo #align eq_orthogonal_projection_of_mem_of_inner_eq_zero eq_orthogonalProjection_of_mem_of_inner_eq_zero /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo #align eq_orthogonal_projection_of_mem_orthogonal eq_orthogonalProjection_of_mem_orthogonal /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonalProjection K u : E) = v := eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] ) #align eq_orthogonal_projection_of_mem_orthogonal' eq_orthogonalProjection_of_mem_orthogonal' @[simp] theorem orthogonalProjection_orthogonal_val (u : E) : (orthogonalProjection Kᗮ u : E) = u - orthogonalProjection K u := eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _) (K.le_orthogonal_orthogonal (orthogonalProjection K u).2) <| by simp theorem orthogonalProjection_orthogonal (u : E) : orthogonalProjection Kᗮ u = ⟨u - orthogonalProjection K u, sub_orthogonalProjection_mem_orthogonal _⟩ := Subtype.eq <| orthogonalProjection_orthogonal_val _ /-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/ theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [HasOrthogonalProjection U] (y : E) : ‖y - orthogonalProjection U y‖ = ⨅ x : U, ‖y - x‖ := by rw [norm_eq_iInf_iff_inner_eq_zero _ (Submodule.coe_mem _)] exact orthogonalProjection_inner_eq_zero _ #align orthogonal_projection_minimal orthogonalProjection_minimal /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [HasOrthogonalProjection K'] (h : K = K') (u : E) : (orthogonalProjection K u : E) = (orthogonalProjection K' u : E) := by subst h; rfl #align eq_orthogonal_projection_of_eq_submodule eq_orthogonalProjection_of_eq_submodule /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp] theorem orthogonalProjection_mem_subspace_eq_self (v : K) : orthogonalProjection K v = v := by ext apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp #align orthogonal_projection_mem_subspace_eq_self orthogonalProjection_mem_subspace_eq_self /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {v : E} : (orthogonalProjection K v : E) = v ↔ v ∈ K := by refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩ · rw [← h] simp · simp #align orthogonal_projection_eq_self_iff orthogonalProjection_eq_self_iff @[simp] theorem orthogonalProjection_eq_zero_iff {v : E} : orthogonalProjection K v = 0 ↔ v ∈ Kᗮ := by refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal (zero_mem _) ?_⟩ · simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v · simpa @[simp] theorem ker_orthogonalProjection : LinearMap.ker (orthogonalProjection K) = Kᗮ := by ext; exact orthogonalProjection_eq_zero_iff theorem LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f.toLinearMap)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f.toLinearMap) (f x) := by refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm · refine Submodule.apply_coe_mem_map _ _ rcases hy with ⟨x', hx', rfl : f x' = y⟩ rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx'] #align linear_isometry.map_orthogonal_projection LinearIsometry.map_orthogonalProjection theorem LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f) (f x) := have : HasOrthogonalProjection (p.map f.toLinearMap) := ‹_› f.map_orthogonalProjection p x #align linear_isometry.map_orthogonal_projection' LinearIsometry.map_orthogonalProjection' /-- Orthogonal projection onto the `Submodule.map` of a subspace. -/ theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] (x : E') : (orthogonalProjection (p.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x : E') = f (orthogonalProjection p (f.symm x)) := by simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using (f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm #align orthogonal_projection_map_apply orthogonalProjection_map_apply /-- The orthogonal projection onto the trivial submodule is the zero map. -/ @[simp] theorem orthogonalProjection_bot : orthogonalProjection (⊥ : Submodule 𝕜 E) = 0 := by ext #align orthogonal_projection_bot orthogonalProjection_bot variable (K) /-- The orthogonal projection has norm `≤ 1`. -/ theorem orthogonalProjection_norm_le : ‖orthogonalProjection K‖ ≤ 1 := LinearMap.mkContinuous_norm_le _ (by norm_num) _ #align orthogonal_projection_norm_le orthogonalProjection_norm_le variable (𝕜) theorem smul_orthogonalProjection_singleton {v : E} (w : E) : ((‖v‖ ^ 2 : ℝ) : 𝕜) • (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by suffices ((orthogonalProjection (𝕜 ∙ v) (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by simpa using this apply eq_orthogonalProjection_of_mem_of_inner_eq_zero · rw [Submodule.mem_span_singleton] use ⟪v, w⟫ · rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left] simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm] #align smul_orthogonal_projection_singleton smul_orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single vector. -/ theorem orthogonalProjection_singleton {v : E} (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by by_cases hv : v = 0 · rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)] simp have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv) have key : (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • ((orthogonalProjection (𝕜 ∙ v) w) : E) = (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -ofReal_pow] convert key using 1 <;> field_simp [hv'] #align orthogonal_projection_singleton orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single unit vector. -/ theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by rw [← smul_orthogonalProjection_singleton 𝕜 w] simp [hv] #align orthogonal_projection_unit_singleton orthogonalProjection_unit_singleton end orthogonalProjection section reflection variable [HasOrthogonalProjection K] -- Porting note: `bit0` is deprecated. /-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/ def reflectionLinearEquiv : E ≃ₗ[𝕜] E := LinearEquiv.ofInvolutive (2 • (K.subtype.comp (orthogonalProjection K).toLinearMap) - LinearMap.id) fun x => by simp [two_smul] #align reflection_linear_equiv reflectionLinearEquivₓ /-- Reflection in a complete subspace of an inner product space. The word "reflection" is sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes more generally to cover operations such as reflection in a point. The definition here, of reflection in a subspace, is a more general sense of the word that includes both those common cases. -/ def reflection : E ≃ₗᵢ[𝕜] E := { reflectionLinearEquiv K with norm_map' := by intro x dsimp only let w : K := orthogonalProjection K x let v := x - w have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2 convert norm_sub_eq_norm_add this using 2 · rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe, LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul, LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply, ContinuousLinearMap.coe_coe] dsimp [v] abel · simp only [v, add_sub_cancel, eq_self_iff_true] } #align reflection reflection variable {K} /-- The result of reflecting. -/ theorem reflection_apply (p : E) : reflection K p = 2 • (orthogonalProjection K p : E) - p := rfl #align reflection_apply reflection_applyₓ /-- Reflection is its own inverse. -/ @[simp] theorem reflection_symm : (reflection K).symm = reflection K := rfl #align reflection_symm reflection_symm /-- Reflection is its own inverse. -/ @[simp] theorem reflection_inv : (reflection K)⁻¹ = reflection K := rfl #align reflection_inv reflection_inv variable (K) /-- Reflecting twice in the same subspace. -/ @[simp] theorem reflection_reflection (p : E) : reflection K (reflection K p) = p := (reflection K).left_inv p #align reflection_reflection reflection_reflection /-- Reflection is involutive. -/ theorem reflection_involutive : Function.Involutive (reflection K) := reflection_reflection K #align reflection_involutive reflection_involutive /-- Reflection is involutive. -/ @[simp] theorem reflection_trans_reflection : (reflection K).trans (reflection K) = LinearIsometryEquiv.refl 𝕜 E := LinearIsometryEquiv.ext <| reflection_involutive K #align reflection_trans_reflection reflection_trans_reflection /-- Reflection is involutive. -/ @[simp] theorem reflection_mul_reflection : reflection K * reflection K = 1 := reflection_trans_reflection _ #align reflection_mul_reflection reflection_mul_reflection theorem reflection_orthogonal_apply (v : E) : reflection Kᗮ v = -reflection K v := by simp [reflection_apply]; abel theorem reflection_orthogonal : reflection Kᗮ = .trans (reflection K) (.neg _) := by ext; apply reflection_orthogonal_apply variable {K} theorem reflection_singleton_apply (u v : E) : reflection (𝕜 ∙ u) v = 2 • (⟪u, v⟫ / ((‖u‖ : 𝕜) ^ 2)) • u - v := by rw [reflection_apply, orthogonalProjection_singleton, ofReal_pow] /-- A point is its own reflection if and only if it is in the subspace. -/ theorem reflection_eq_self_iff (x : E) : reflection K x = x ↔ x ∈ K := by rw [← orthogonalProjection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜, two_smul ℕ, ← two_smul 𝕜] refine (smul_right_injective E ?_).eq_iff exact two_ne_zero #align reflection_eq_self_iff reflection_eq_self_iff theorem reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : reflection K x = x := (reflection_eq_self_iff x).mpr hx #align reflection_mem_subspace_eq_self reflection_mem_subspace_eq_self /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [HasOrthogonalProjection K] (x : E') : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x = f (reflection K (f.symm x)) := by simp [two_smul, reflection_apply, orthogonalProjection_map_apply f K x] #align reflection_map_apply reflection_map_apply /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [HasOrthogonalProjection K] : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) = f.symm.trans ((reflection K).trans f) := LinearIsometryEquiv.ext <| reflection_map_apply f K #align reflection_map reflection_map /-- Reflection through the trivial subspace {0} is just negation. -/ @[simp] theorem reflection_bot : reflection (⊥ : Submodule 𝕜 E) = LinearIsometryEquiv.neg 𝕜 := by ext; simp [reflection_apply] #align reflection_bot reflection_bot end reflection section Orthogonal /-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/ theorem Submodule.sup_orthogonal_inf_of_completeSpace {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂) [HasOrthogonalProjection K₁] : K₁ ⊔ K₁ᗮ ⊓ K₂ = K₂ := by ext x rw [Submodule.mem_sup] let v : K₁ := orthogonalProjection K₁ x have hvm : x - v ∈ K₁ᗮ := sub_orthogonalProjection_mem_orthogonal x constructor · rintro ⟨y, hy, z, hz, rfl⟩ exact K₂.add_mem (h hy) hz.2 · exact fun hx => ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel _ _⟩ #align submodule.sup_orthogonal_inf_of_complete_space Submodule.sup_orthogonal_inf_of_completeSpace variable {K} /-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/ theorem Submodule.sup_orthogonal_of_completeSpace [HasOrthogonalProjection K] : K ⊔ Kᗮ = ⊤ := by convert Submodule.sup_orthogonal_inf_of_completeSpace (le_top : K ≤ ⊤) using 2 simp #align submodule.sup_orthogonal_of_complete_space Submodule.sup_orthogonal_of_completeSpace variable (K) /-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/ theorem Submodule.exists_add_mem_mem_orthogonal [HasOrthogonalProjection K] (v : E) : ∃ y ∈ K, ∃ z ∈ Kᗮ, v = y + z := ⟨orthogonalProjection K v, Subtype.coe_prop _, v - orthogonalProjection K v, sub_orthogonalProjection_mem_orthogonal _, by simp⟩ #align submodule.exists_sum_mem_mem_orthogonal Submodule.exists_add_mem_mem_orthogonal /-- If `K` admits an orthogonal projection, then the orthogonal complement of its orthogonal complement is itself. -/ @[simp] theorem Submodule.orthogonal_orthogonal [HasOrthogonalProjection K] : Kᗮᗮ = K := by ext v constructor · obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_add_mem_mem_orthogonal v intro hv have hz' : z = 0 := by have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm] simpa [inner_add_right, hyz] using hv z hz simp [hy, hz'] · intro hv w hw rw [inner_eq_zero_symm] exact hw v hv #align submodule.orthogonal_orthogonal Submodule.orthogonal_orthogonal /-- In a Hilbert space, the orthogonal complement of the orthogonal complement of a subspace `K` is the topological closure of `K`. Note that the completeness assumption is necessary. Let `E` be the space `ℕ →₀ ℝ` with inner space structure inherited from `PiLp 2 (fun _ : ℕ ↦ ℝ)`. Let `K` be the subspace of sequences with the sum of all elements equal to zero. Then `Kᗮ = ⊥`, `Kᗮᗮ = ⊤`. -/ theorem Submodule.orthogonal_orthogonal_eq_closure [CompleteSpace E] : Kᗮᗮ = K.topologicalClosure := by refine le_antisymm ?_ ?_ · convert Submodule.orthogonal_orthogonal_monotone K.le_topologicalClosure using 1 rw [K.topologicalClosure.orthogonal_orthogonal] · exact K.topologicalClosure_minimal K.le_orthogonal_orthogonal Kᗮ.isClosed_orthogonal #align submodule.orthogonal_orthogonal_eq_closure Submodule.orthogonal_orthogonal_eq_closure variable {K} /-- If `K` admits an orthogonal projection, `K` and `Kᗮ` are complements of each other. -/ theorem Submodule.isCompl_orthogonal_of_completeSpace [HasOrthogonalProjection K] : IsCompl K Kᗮ := ⟨K.orthogonal_disjoint, codisjoint_iff.2 Submodule.sup_orthogonal_of_completeSpace⟩ #align submodule.is_compl_orthogonal_of_complete_space Submodule.isCompl_orthogonal_of_completeSpace @[simp] theorem Submodule.orthogonal_eq_bot_iff [HasOrthogonalProjection K] : Kᗮ = ⊥ ↔ K = ⊤ := by refine ⟨?_, fun h => by rw [h, Submodule.top_orthogonal_eq_bot]⟩ intro h have : K ⊔ Kᗮ = ⊤ := Submodule.sup_orthogonal_of_completeSpace rwa [h, sup_comm, bot_sup_eq] at this #align submodule.orthogonal_eq_bot_iff Submodule.orthogonal_eq_bot_iff /-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero [HasOrthogonalProjection K] {v : E} (hv : v ∈ Kᗮ) : orthogonalProjection K v = 0 := by ext convert eq_orthogonalProjection_of_mem_orthogonal (K := K) _ _ <;> simp [hv] #align orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero /-- The projection into `U` from an orthogonal submodule `V` is the zero map. -/ theorem Submodule.IsOrtho.orthogonalProjection_comp_subtypeL {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] (h : U ⟂ V) : orthogonalProjection U ∘L V.subtypeL = 0 := ContinuousLinearMap.ext fun v => orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero <| h.symm v.prop set_option linter.uppercaseLean3 false in #align submodule.is_ortho.orthogonal_projection_comp_subtypeL Submodule.IsOrtho.orthogonalProjection_comp_subtypeL /-- The projection into `U` from `V` is the zero map if and only if `U` and `V` are orthogonal. -/ theorem orthogonalProjection_comp_subtypeL_eq_zero_iff {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] : orthogonalProjection U ∘L V.subtypeL = 0 ↔ U ⟂ V := ⟨fun h u hu v hv => by convert orthogonalProjection_inner_eq_zero v u hu using 2 have : orthogonalProjection U v = 0 := DFunLike.congr_fun h (⟨_, hv⟩ : V) rw [this, Submodule.coe_zero, sub_zero], Submodule.IsOrtho.orthogonalProjection_comp_subtypeL⟩ set_option linter.uppercaseLean3 false in #align orthogonal_projection_comp_subtypeL_eq_zero_iff orthogonalProjection_comp_subtypeL_eq_zero_iff theorem orthogonalProjection_eq_linear_proj [HasOrthogonalProjection K] (x : E) : orthogonalProjection K x = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace x := by have : IsCompl K Kᗮ := Submodule.isCompl_orthogonal_of_completeSpace conv_lhs => rw [← Submodule.linear_proj_add_linearProjOfIsCompl_eq_self this x] rw [map_add, orthogonalProjection_mem_subspace_eq_self, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.coe_mem _), add_zero] #align orthogonal_projection_eq_linear_proj orthogonalProjection_eq_linear_proj theorem orthogonalProjection_coe_linearMap_eq_linearProj [HasOrthogonalProjection K] : (orthogonalProjection K : E →ₗ[𝕜] K) = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace := LinearMap.ext <| orthogonalProjection_eq_linear_proj #align orthogonal_projection_coe_linear_map_eq_linear_proj orthogonalProjection_coe_linearMap_eq_linearProj /-- The reflection in `K` of an element of `Kᗮ` is its negation. -/ theorem reflection_mem_subspace_orthogonalComplement_eq_neg [HasOrthogonalProjection K] {v : E} (hv : v ∈ Kᗮ) : reflection K v = -v := by simp [reflection_apply, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero hv] #align reflection_mem_subspace_orthogonal_complement_eq_neg reflection_mem_subspace_orthogonalComplement_eq_neg /-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero [HasOrthogonalProjection Kᗮ] {v : E} (hv : v ∈ K) : orthogonalProjection Kᗮ v = 0 := orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (K.le_orthogonal_orthogonal hv) #align orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero /-- If `U ≤ V`, then projecting on `V` and then on `U` is the same as projecting on `U`. -/ theorem orthogonalProjection_orthogonalProjection_of_le {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] [HasOrthogonalProjection V] (h : U ≤ V) (x : E) : orthogonalProjection U (orthogonalProjection V x) = orthogonalProjection U x := Eq.symm <| by simpa only [sub_eq_zero, map_sub] using orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.orthogonal_le h (sub_orthogonalProjection_mem_orthogonal x)) #align orthogonal_projection_orthogonal_projection_of_le orthogonalProjection_orthogonalProjection_of_le /-- Given a monotone family `U` of complete submodules of `E` and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to the orthogonal projection of `x` on `(⨆ i, U i).topologicalClosure` along `atTop`. -/ theorem orthogonalProjection_tendsto_closure_iSup [CompleteSpace E] {ι : Type*} [SemilatticeSup ι] (U : ι → Submodule 𝕜 E) [∀ i, CompleteSpace (U i)] (hU : Monotone U) (x : E) : Filter.Tendsto (fun i => (orthogonalProjection (U i) x : E)) atTop (𝓝 (orthogonalProjection (⨆ i, U i).topologicalClosure x : E)) := by cases isEmpty_or_nonempty ι · exact tendsto_of_isEmpty let y := (orthogonalProjection (⨆ i, U i).topologicalClosure x : E) have proj_x : ∀ i, orthogonalProjection (U i) x = orthogonalProjection (U i) y := fun i => (orthogonalProjection_orthogonalProjection_of_le ((le_iSup U i).trans (iSup U).le_topologicalClosure) _).symm suffices ∀ ε > 0, ∃ I, ∀ i ≥ I, ‖(orthogonalProjection (U i) y : E) - y‖ < ε by simpa only [proj_x, NormedAddCommGroup.tendsto_atTop] using this intro ε hε obtain ⟨a, ha, hay⟩ : ∃ a ∈ ⨆ i, U i, dist y a < ε := by have y_mem : y ∈ (⨆ i, U i).topologicalClosure := Submodule.coe_mem _ rw [← SetLike.mem_coe, Submodule.topologicalClosure_coe, Metric.mem_closure_iff] at y_mem exact y_mem ε hε rw [dist_eq_norm] at hay obtain ⟨I, hI⟩ : ∃ I, a ∈ U I := by rwa [Submodule.mem_iSup_of_directed _ hU.directed_le] at ha refine ⟨I, fun i (hi : I ≤ i) => ?_⟩ rw [norm_sub_rev, orthogonalProjection_minimal] refine lt_of_le_of_lt ?_ hay change _ ≤ ‖y - (⟨a, hU hi hI⟩ : U i)‖ exact ciInf_le ⟨0, Set.forall_mem_range.mpr fun _ => norm_nonneg _⟩ _ #align orthogonal_projection_tendsto_closure_supr orthogonalProjection_tendsto_closure_iSup /-- Given a monotone family `U` of complete submodules of `E` with dense span supremum, and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to `x` along `at_top`. -/ theorem orthogonalProjection_tendsto_self [CompleteSpace E] {ι : Type*} [SemilatticeSup ι] (U : ι → Submodule 𝕜 E) [∀ t, CompleteSpace (U t)] (hU : Monotone U) (x : E) (hU' : ⊤ ≤ (⨆ t, U t).topologicalClosure) : Filter.Tendsto (fun t => (orthogonalProjection (U t) x : E)) atTop (𝓝 x) := by rw [← eq_top_iff] at hU' convert orthogonalProjection_tendsto_closure_iSup U hU x rw [orthogonalProjection_eq_self_iff.mpr _] rw [hU'] trivial #align orthogonal_projection_tendsto_self orthogonalProjection_tendsto_self /-- The orthogonal complement satisfies `Kᗮᗮᗮ = Kᗮ`. -/ theorem Submodule.triorthogonal_eq_orthogonal [CompleteSpace E] : Kᗮᗮᗮ = Kᗮ := by rw [Kᗮ.orthogonal_orthogonal_eq_closure] exact K.isClosed_orthogonal.submodule_topologicalClosure_eq #align submodule.triorthogonal_eq_orthogonal Submodule.triorthogonal_eq_orthogonal /-- The closure of `K` is the full space iff `Kᗮ` is trivial. -/ theorem Submodule.topologicalClosure_eq_top_iff [CompleteSpace E] : K.topologicalClosure = ⊤ ↔ Kᗮ = ⊥ := by rw [← Submodule.orthogonal_orthogonal_eq_closure] constructor <;> intro h · rw [← Submodule.triorthogonal_eq_orthogonal, h, Submodule.top_orthogonal_eq_bot] · rw [h, Submodule.bot_orthogonal_eq_top] #align submodule.topological_closure_eq_top_iff Submodule.topologicalClosure_eq_top_iff namespace Dense /- Porting note: unneeded assumption `[CompleteSpace E]` was removed from all theorems in this section. TODO: Move to another file? -/ open Submodule variable {x y : E} theorem eq_zero_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = 0) : x = 0 := by have : (⟪x, ·⟫) = 0 := (continuous_const.inner continuous_id).ext_on hK continuous_const (Subtype.forall.1 h) simpa using congr_fun this x #align dense.eq_zero_of_inner_left Dense.eq_zero_of_inner_left theorem eq_zero_of_mem_orthogonal (hK : Dense (K : Set E)) (h : x ∈ Kᗮ) : x = 0 := eq_zero_of_inner_left hK fun v ↦ (mem_orthogonal' _ _).1 h _ v.2 #align dense.eq_zero_of_mem_orthogonal Dense.eq_zero_of_mem_orthogonal /-- If `S` is dense and `x - y ∈ Kᗮ`, then `x = y`. -/ theorem eq_of_sub_mem_orthogonal (hK : Dense (K : Set E)) (h : x - y ∈ Kᗮ) : x = y := sub_eq_zero.1 <| eq_zero_of_mem_orthogonal hK h #align dense.eq_of_sub_mem_orthogonal Dense.eq_of_sub_mem_orthogonal theorem eq_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_left h) #align dense.eq_of_inner_left Dense.eq_of_inner_left theorem eq_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_right h) #align dense.eq_of_inner_right Dense.eq_of_inner_right theorem eq_zero_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = 0) : x = 0 := hK.eq_of_inner_right fun v => by rw [inner_zero_right, h v] #align dense.eq_zero_of_inner_right Dense.eq_zero_of_inner_right end Dense /-- The reflection in `Kᗮ` of an element of `K` is its negation. -/ theorem reflection_mem_subspace_orthogonal_precomplement_eq_neg [HasOrthogonalProjection K] {v : E} (hv : v ∈ K) : reflection Kᗮ v = -v := reflection_mem_subspace_orthogonalComplement_eq_neg (K.le_orthogonal_orthogonal hv) #align reflection_mem_subspace_orthogonal_precomplement_eq_neg reflection_mem_subspace_orthogonal_precomplement_eq_neg /-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/ theorem orthogonalProjection_orthogonalComplement_singleton_eq_zero (v : E) : orthogonalProjection (𝕜 ∙ v)ᗮ v = 0 := orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero (Submodule.mem_span_singleton_self v) #align orthogonal_projection_orthogonal_complement_singleton_eq_zero orthogonalProjection_orthogonalComplement_singleton_eq_zero /-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/ theorem reflection_orthogonalComplement_singleton_eq_neg (v : E) : reflection (𝕜 ∙ v)ᗮ v = -v := reflection_mem_subspace_orthogonal_precomplement_eq_neg (Submodule.mem_span_singleton_self v) #align reflection_orthogonal_complement_singleton_eq_neg reflection_orthogonalComplement_singleton_eq_neg theorem reflection_sub {v w : F} (h : ‖v‖ = ‖w‖) : reflection (ℝ ∙ (v - w))ᗮ v = w := by set R : F ≃ₗᵢ[ℝ] F := reflection (ℝ ∙ v - w)ᗮ suffices R v + R v = w + w by apply smul_right_injective F (by norm_num : (2 : ℝ) ≠ 0) simpa [two_smul] using this have h₁ : R (v - w) = -(v - w) := reflection_orthogonalComplement_singleton_eq_neg (v - w) have h₂ : R (v + w) = v + w := by apply reflection_mem_subspace_eq_self rw [Submodule.mem_orthogonal_singleton_iff_inner_left] rw [real_inner_add_sub_eq_zero_iff] exact h convert congr_arg₂ (· + ·) h₂ h₁ using 1 · simp · abel #align reflection_sub reflection_sub variable (K) -- Porting note: relax assumptions, swap LHS with RHS /-- If the orthogonal projection to `K` is well-defined, then a vector splits as the sum of its orthogonal projections onto a complete submodule `K` and onto the orthogonal complement of `K`. -/ theorem orthogonalProjection_add_orthogonalProjection_orthogonal [HasOrthogonalProjection K] (w : E) : (orthogonalProjection K w : E) + (orthogonalProjection Kᗮ w : E) = w := by simp #align eq_sum_orthogonal_projection_self_orthogonal_complement orthogonalProjection_add_orthogonalProjection_orthogonalₓ /-- The Pythagorean theorem, for an orthogonal projection. -/ theorem norm_sq_eq_add_norm_sq_projection (x : E) (S : Submodule 𝕜 E) [HasOrthogonalProjection S] : ‖x‖ ^ 2 = ‖orthogonalProjection S x‖ ^ 2 + ‖orthogonalProjection Sᗮ x‖ ^ 2 := calc ‖x‖ ^ 2 = ‖(orthogonalProjection S x : E) + orthogonalProjection Sᗮ x‖ ^ 2 := by rw [orthogonalProjection_add_orthogonalProjection_orthogonal] _ = ‖orthogonalProjection S x‖ ^ 2 + ‖orthogonalProjection Sᗮ x‖ ^ 2 := by simp only [sq] exact norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero _ _ <| (S.mem_orthogonal _).1 (orthogonalProjection Sᗮ x).2 _ (orthogonalProjection S x).2 #align norm_sq_eq_add_norm_sq_projection norm_sq_eq_add_norm_sq_projection /-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal complement sum to the identity. -/ theorem id_eq_sum_orthogonalProjection_self_orthogonalComplement [HasOrthogonalProjection K] : ContinuousLinearMap.id 𝕜 E = K.subtypeL.comp (orthogonalProjection K) + Kᗮ.subtypeL.comp (orthogonalProjection Kᗮ) := by ext w exact (orthogonalProjection_add_orthogonalProjection_orthogonal K w).symm #align id_eq_sum_orthogonal_projection_self_orthogonal_complement id_eq_sum_orthogonalProjection_self_orthogonalComplement -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high] theorem inner_orthogonalProjection_eq_of_mem_right [HasOrthogonalProjection K] (u : K) (v : E) : ⟪orthogonalProjection K v, u⟫ = ⟪v, u⟫ := calc ⟪orthogonalProjection K v, u⟫ = ⟪(orthogonalProjection K v : E), u⟫ := K.coe_inner _ _ _ = ⟪(orthogonalProjection K v : E), u⟫ + ⟪v - orthogonalProjection K v, u⟫ := by rw [orthogonalProjection_inner_eq_zero _ _ (Submodule.coe_mem _), add_zero] _ = ⟪v, u⟫ := by rw [← inner_add_left, add_sub_cancel] #align inner_orthogonal_projection_eq_of_mem_right inner_orthogonalProjection_eq_of_mem_right -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high] theorem inner_orthogonalProjection_eq_of_mem_left [HasOrthogonalProjection K] (u : K) (v : E) : ⟪u, orthogonalProjection K v⟫ = ⟪(u : E), v⟫ := by rw [← inner_conj_symm, ← inner_conj_symm (u : E), inner_orthogonalProjection_eq_of_mem_right] #align inner_orthogonal_projection_eq_of_mem_left inner_orthogonalProjection_eq_of_mem_left /-- The orthogonal projection is self-adjoint. -/ theorem inner_orthogonalProjection_left_eq_right [HasOrthogonalProjection K] (u v : E) : ⟪↑(orthogonalProjection K u), v⟫ = ⟪u, orthogonalProjection K v⟫ := by rw [← inner_orthogonalProjection_eq_of_mem_left, inner_orthogonalProjection_eq_of_mem_right] #align inner_orthogonal_projection_left_eq_right inner_orthogonalProjection_left_eq_right /-- The orthogonal projection is symmetric. -/ theorem orthogonalProjection_isSymmetric [HasOrthogonalProjection K] : (K.subtypeL ∘L orthogonalProjection K : E →ₗ[𝕜] E).IsSymmetric := inner_orthogonalProjection_left_eq_right K #align orthogonal_projection_is_symmetric orthogonalProjection_isSymmetric open FiniteDimensional /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` contained in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ theorem Submodule.finrank_add_inf_finrank_orthogonal {K₁ K₂ : Submodule 𝕜 E} [FiniteDimensional 𝕜 K₂] (h : K₁ ≤ K₂) : finrank 𝕜 K₁ + finrank 𝕜 (K₁ᗮ ⊓ K₂ : Submodule 𝕜 E) = finrank 𝕜 K₂ := by haveI : FiniteDimensional 𝕜 K₁ := Submodule.finiteDimensional_of_le h haveI := proper_rclike 𝕜 K₁ have hd := Submodule.finrank_sup_add_finrank_inf_eq K₁ (K₁ᗮ ⊓ K₂) rw [← inf_assoc, (Submodule.orthogonal_disjoint K₁).eq_bot, bot_inf_eq, finrank_bot, Submodule.sup_orthogonal_inf_of_completeSpace h] at hd rw [add_zero] at hd exact hd.symm #align submodule.finrank_add_inf_finrank_orthogonal Submodule.finrank_add_inf_finrank_orthogonal /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` contained in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ theorem Submodule.finrank_add_inf_finrank_orthogonal' {K₁ K₂ : Submodule 𝕜 E} [FiniteDimensional 𝕜 K₂] (h : K₁ ≤ K₂) {n : ℕ} (h_dim : finrank 𝕜 K₁ + n = finrank 𝕜 K₂) : finrank 𝕜 (K₁ᗮ ⊓ K₂ : Submodule 𝕜 E) = n := by rw [← add_right_inj (finrank 𝕜 K₁)] simp [Submodule.finrank_add_inf_finrank_orthogonal h, h_dim] #align submodule.finrank_add_inf_finrank_orthogonal' Submodule.finrank_add_inf_finrank_orthogonal' /-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to that of `E`. -/ theorem Submodule.finrank_add_finrank_orthogonal [FiniteDimensional 𝕜 E] (K : Submodule 𝕜 E) : finrank 𝕜 K + finrank 𝕜 Kᗮ = finrank 𝕜 E := by convert Submodule.finrank_add_inf_finrank_orthogonal (le_top : K ≤ ⊤) using 1 · rw [inf_top_eq] · simp #align submodule.finrank_add_finrank_orthogonal Submodule.finrank_add_finrank_orthogonal /-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to that of `E`. -/ theorem Submodule.finrank_add_finrank_orthogonal' [FiniteDimensional 𝕜 E] {K : Submodule 𝕜 E} {n : ℕ} (h_dim : finrank 𝕜 K + n = finrank 𝕜 E) : finrank 𝕜 Kᗮ = n := by rw [← add_right_inj (finrank 𝕜 K)] simp [Submodule.finrank_add_finrank_orthogonal, h_dim] #align submodule.finrank_add_finrank_orthogonal' Submodule.finrank_add_finrank_orthogonal' /-- In a finite-dimensional inner product space, the dimension of the orthogonal complement of the span of a nonzero vector is one less than the dimension of the space. -/ theorem finrank_orthogonal_span_singleton {n : ℕ} [_i : Fact (finrank 𝕜 E = n + 1)] {v : E} (hv : v ≠ 0) : finrank 𝕜 (𝕜 ∙ v)ᗮ = n := by haveI : FiniteDimensional 𝕜 E := .of_fact_finrank_eq_succ n exact Submodule.finrank_add_finrank_orthogonal' <| by simp [finrank_span_singleton hv, _i.elim, add_comm] #align finrank_orthogonal_span_singleton finrank_orthogonal_span_singleton /-- An element `φ` of the orthogonal group of `F` can be factored as a product of reflections, and specifically at most as many reflections as the dimension of the complement of the fixed subspace of `φ`. -/ theorem LinearIsometryEquiv.reflections_generate_dim_aux [FiniteDimensional ℝ F] {n : ℕ} (φ : F ≃ₗᵢ[ℝ] F) (hn : finrank ℝ (ker (ContinuousLinearMap.id ℝ F - φ))ᗮ ≤ n) : ∃ l : List F, l.length ≤ n ∧ φ = (l.map fun v => reflection (ℝ ∙ v)ᗮ).prod := by -- We prove this by strong induction on `n`, the dimension of the orthogonal complement of the -- fixed subspace of the endomorphism `φ` induction' n with n IH generalizing φ · -- Base case: `n = 0`, the fixed subspace is the whole space, so `φ = id` refine ⟨[], rfl.le, show φ = 1 from ?_⟩ have : ker (ContinuousLinearMap.id ℝ F - φ) = ⊤ := by rwa [le_zero_iff, Submodule.finrank_eq_zero, Submodule.orthogonal_eq_bot_iff] at hn symm ext x have := LinearMap.congr_fun (LinearMap.ker_eq_top.mp this) x simpa only [sub_eq_zero, ContinuousLinearMap.coe_sub, LinearMap.sub_apply, LinearMap.zero_apply] using this · -- Inductive step. Let `W` be the fixed subspace of `φ`. We suppose its complement to have -- dimension at most n + 1. let W := ker (ContinuousLinearMap.id ℝ F - φ) have hW : ∀ w ∈ W, φ w = w := fun w hw => (sub_eq_zero.mp hw).symm by_cases hn' : finrank ℝ Wᗮ ≤ n · obtain ⟨V, hV₁, hV₂⟩ := IH φ hn' exact ⟨V, hV₁.trans n.le_succ, hV₂⟩ -- Take a nonzero element `v` of the orthogonal complement of `W`. haveI : Nontrivial Wᗮ := nontrivial_of_finrank_pos (by omega : 0 < finrank ℝ Wᗮ) obtain ⟨v, hv⟩ := exists_ne (0 : Wᗮ) have hφv : φ v ∈ Wᗮ := by intro w hw rw [← hW w hw, LinearIsometryEquiv.inner_map_map] exact v.prop w hw have hv' : (v : F) ∉ W := by intro h exact hv ((Submodule.mem_left_iff_eq_zero_of_disjoint W.orthogonal_disjoint).mp h) -- Let `ρ` be the reflection in `v - φ v`; this is designed to swap `v` and `φ v` let x : F := v - φ v let ρ := reflection (ℝ ∙ x)ᗮ -- Notation: Let `V` be the fixed subspace of `φ.trans ρ` let V := ker (ContinuousLinearMap.id ℝ F - φ.trans ρ) have hV : ∀ w, ρ (φ w) = w → w ∈ V := by intro w hw change w - ρ (φ w) = 0 rw [sub_eq_zero, hw] -- Everything fixed by `φ` is fixed by `φ.trans ρ` have H₂V : W ≤ V := by intro w hw apply hV rw [hW w hw] refine reflection_mem_subspace_eq_self ?_ rw [Submodule.mem_orthogonal_singleton_iff_inner_left] exact Submodule.sub_mem _ v.prop hφv _ hw -- `v` is also fixed by `φ.trans ρ` have H₁V : (v : F) ∈ V := by apply hV have : ρ v = φ v := reflection_sub (φ.norm_map v).symm rw [← this] exact reflection_reflection _ _ -- By dimension-counting, the complement of the fixed subspace of `φ.trans ρ` has dimension at -- most `n` have : finrank ℝ Vᗮ ≤ n := by change finrank ℝ Wᗮ ≤ n + 1 at hn have : finrank ℝ W + 1 ≤ finrank ℝ V := Submodule.finrank_lt_finrank_of_lt (SetLike.lt_iff_le_and_exists.2 ⟨H₂V, v, H₁V, hv'⟩) have : finrank ℝ V + finrank ℝ Vᗮ = finrank ℝ F := V.finrank_add_finrank_orthogonal have : finrank ℝ W + finrank ℝ Wᗮ = finrank ℝ F := W.finrank_add_finrank_orthogonal omega -- So apply the inductive hypothesis to `φ.trans ρ` obtain ⟨l, hl, hφl⟩ := IH (ρ * φ) this -- Prepend `ρ` to the factorization into reflections obtained for `φ.trans ρ`; this gives a -- factorization into reflections for `φ`. refine ⟨x::l, Nat.succ_le_succ hl, ?_⟩ rw [List.map_cons, List.prod_cons] have := congr_arg (ρ * ·) hφl dsimp only at this rwa [← mul_assoc, reflection_mul_reflection, one_mul] at this #align linear_isometry_equiv.reflections_generate_dim_aux LinearIsometryEquiv.reflections_generate_dim_aux /-- The orthogonal group of `F` is generated by reflections; specifically each element `φ` of the orthogonal group is a product of at most as many reflections as the dimension of `F`. Special case of the **Cartan–Dieudonné theorem**. -/ theorem LinearIsometryEquiv.reflections_generate_dim [FiniteDimensional ℝ F] (φ : F ≃ₗᵢ[ℝ] F) : ∃ l : List F, l.length ≤ finrank ℝ F ∧ φ = (l.map fun v => reflection (ℝ ∙ v)ᗮ).prod := let ⟨l, hl₁, hl₂⟩ := φ.reflections_generate_dim_aux le_rfl ⟨l, hl₁.trans (Submodule.finrank_le _), hl₂⟩ #align linear_isometry_equiv.reflections_generate_dim LinearIsometryEquiv.reflections_generate_dim /-- The orthogonal group of `F` is generated by reflections. -/ theorem LinearIsometryEquiv.reflections_generate [FiniteDimensional ℝ F] : Subgroup.closure (Set.range fun v : F => reflection (ℝ ∙ v)ᗮ) = ⊤ := by rw [Subgroup.eq_top_iff'] intro φ rcases φ.reflections_generate_dim with ⟨l, _, rfl⟩ apply (Subgroup.closure _).list_prod_mem intro x hx rcases List.mem_map.mp hx with ⟨a, _, hax⟩ exact Subgroup.subset_closure ⟨a, hax⟩ #align linear_isometry_equiv.reflections_generate LinearIsometryEquiv.reflections_generate end Orthogonal section OrthogonalFamily variable {ι : Type*} /-- An orthogonal family of subspaces of `E` satisfies `DirectSum.IsInternal` (that is, they provide an internal direct sum decomposition of `E`) if and only if their span has trivial orthogonal complement. -/ theorem OrthogonalFamily.isInternal_iff_of_isComplete [DecidableEq ι] {V : ι → Submodule 𝕜 E} (hV : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) (hc : IsComplete (↑(iSup V) : Set E)) : DirectSum.IsInternal V ↔ (iSup V)ᗮ = ⊥ := by haveI : CompleteSpace (↥(iSup V)) := hc.completeSpace_coe simp only [DirectSum.isInternal_submodule_iff_independent_and_iSup_eq_top, hV.independent, true_and_iff, Submodule.orthogonal_eq_bot_iff] #align orthogonal_family.is_internal_iff_of_is_complete OrthogonalFamily.isInternal_iff_of_isComplete /-- An orthogonal family of subspaces of `E` satisfies `DirectSum.IsInternal` (that is, they provide an internal direct sum decomposition of `E`) if and only if their span has trivial orthogonal complement. -/ theorem OrthogonalFamily.isInternal_iff [DecidableEq ι] [FiniteDimensional 𝕜 E] {V : ι → Submodule 𝕜 E} (hV : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) : DirectSum.IsInternal V ↔ (iSup V)ᗮ = ⊥ := haveI h := FiniteDimensional.proper_rclike 𝕜 (↥(iSup V)) hV.isInternal_iff_of_isComplete (completeSpace_coe_iff_isComplete.mp inferInstance) #align orthogonal_family.is_internal_iff OrthogonalFamily.isInternal_iff open DirectSum /-- If `x` lies within an orthogonal family `v`, it can be expressed as a sum of projections. -/ theorem OrthogonalFamily.sum_projection_of_mem_iSup [Fintype ι] {V : ι → Submodule 𝕜 E} [∀ i, CompleteSpace (V i)] (hV : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) (x : E) (hx : x ∈ iSup V) : (∑ i, (orthogonalProjection (V i) x : E)) = x := by -- Porting note: switch to the better `induction _ using`. Need the primed induction principle, -- the unprimed one doesn't work with `induction` (as it isn't as syntactically general) induction hx using Submodule.iSup_induction' with | mem i x hx => refine (Finset.sum_eq_single_of_mem i (Finset.mem_univ _) fun j _ hij => ?_).trans (orthogonalProjection_eq_self_iff.mpr hx) rw [orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero, Submodule.coe_zero] exact hV.isOrtho hij.symm hx | zero => simp_rw [map_zero, Submodule.coe_zero, Finset.sum_const_zero] | add x y _ _ hx hy => simp_rw [map_add, Submodule.coe_add, Finset.sum_add_distrib] exact congr_arg₂ (· + ·) hx hy #align orthogonal_family.sum_projection_of_mem_supr OrthogonalFamily.sum_projection_of_mem_iSup /-- If a family of submodules is orthogonal, then the `orthogonalProjection` on a direct sum is just the coefficient of that direct sum. -/ theorem OrthogonalFamily.projection_directSum_coeAddHom [DecidableEq ι] {V : ι → Submodule 𝕜 E} (hV : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) (x : ⨁ i, V i) (i : ι) [CompleteSpace (V i)] : orthogonalProjection (V i) (DirectSum.coeAddMonoidHom V x) = x i := by induction' x using DirectSum.induction_on with j x x y hx hy · simp · simp_rw [DirectSum.coeAddMonoidHom_of, DirectSum.of] -- Porting note: was in the previous `simp_rw`, no longer works -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [DFinsupp.singleAddHom_apply] obtain rfl | hij := Decidable.eq_or_ne i j · rw [orthogonalProjection_mem_subspace_eq_self, DFinsupp.single_eq_same] · rw [orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero, DFinsupp.single_eq_of_ne hij.symm] exact hV.isOrtho hij.symm x.prop · simp_rw [map_add] exact congr_arg₂ (· + ·) hx hy #align orthogonal_family.projection_direct_sum_coe_add_hom OrthogonalFamily.projection_directSum_coeAddHom /-- If a family of submodules is orthogonal and they span the whole space, then the orthogonal projection provides a means to decompose the space into its submodules. The projection function is `decompose V x i = orthogonalProjection (V i) x`. See note [reducible non-instances]. -/ abbrev OrthogonalFamily.decomposition [DecidableEq ι] [Fintype ι] {V : ι → Submodule 𝕜 E} [∀ i, CompleteSpace (V i)] (hV : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) (h : iSup V = ⊤) : DirectSum.Decomposition V where decompose' x := DFinsupp.equivFunOnFintype.symm fun i => orthogonalProjection (V i) x left_inv x := by dsimp only letI := fun i => Classical.decEq (V i) rw [DirectSum.coeAddMonoidHom, DirectSum.toAddMonoid, DFinsupp.liftAddHom_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [DFinsupp.sumAddHom_apply]; rw [DFinsupp.sum_eq_sum_fintype] · simp_rw [Equiv.apply_symm_apply, AddSubmonoidClass.coe_subtype] exact hV.sum_projection_of_mem_iSup _ ((h.ge : _) Submodule.mem_top) · intro i exact map_zero _ right_inv x := by dsimp only simp_rw [hV.projection_directSum_coeAddHom, DFinsupp.equivFunOnFintype_symm_coe] #align orthogonal_family.decomposition OrthogonalFamily.decomposition end OrthogonalFamily section OrthonormalBasis variable {v : Set E} open FiniteDimensional Submodule Set /-- An orthonormal set in an `InnerProductSpace` is maximal, if and only if the orthogonal complement of its span is empty. -/
Mathlib/Analysis/InnerProductSpace/Projection.lean
1,367
1,426
theorem maximal_orthonormal_iff_orthogonalComplement_eq_bot (hv : Orthonormal 𝕜 ((↑) : v → E)) : (∀ u ⊇ v, Orthonormal 𝕜 ((↑) : u → E) → u = v) ↔ (span 𝕜 v)ᗮ = ⊥ := by
rw [Submodule.eq_bot_iff] constructor · contrapose! -- ** direction 1: nonempty orthogonal complement implies nonmaximal rintro ⟨x, hx', hx⟩ -- take a nonzero vector and normalize it let e := (‖x‖⁻¹ : 𝕜) • x have he : ‖e‖ = 1 := by simp [norm_smul_inv_norm hx] have he' : e ∈ (span 𝕜 v)ᗮ := smul_mem' _ _ hx' have he'' : e ∉ v := by intro hev have : e = 0 := by have : e ∈ span 𝕜 v ⊓ (span 𝕜 v)ᗮ := ⟨subset_span hev, he'⟩ simpa [(span 𝕜 v).inf_orthogonal_eq_bot] using this have : e ≠ 0 := hv.ne_zero ⟨e, hev⟩ contradiction -- put this together with `v` to provide a candidate orthonormal basis for the whole space refine ⟨insert e v, v.subset_insert e, ⟨?_, ?_⟩, (ne_insert_of_not_mem v he'').symm⟩ · -- show that the elements of `insert e v` have unit length rintro ⟨a, ha'⟩ cases' eq_or_mem_of_mem_insert ha' with ha ha · simp [ha, he] · exact hv.1 ⟨a, ha⟩ · -- show that the elements of `insert e v` are orthogonal have h_end : ∀ a ∈ v, ⟪a, e⟫ = 0 := by intro a ha exact he' a (Submodule.subset_span ha) rintro ⟨a, ha'⟩ cases' eq_or_mem_of_mem_insert ha' with ha ha · rintro ⟨b, hb'⟩ hab' have hb : b ∈ v := by refine mem_of_mem_insert_of_ne hb' ?_ intro hbe' apply hab' simp [ha, hbe'] rw [inner_eq_zero_symm] simpa [ha] using h_end b hb rintro ⟨b, hb'⟩ hab' cases' eq_or_mem_of_mem_insert hb' with hb hb · simpa [hb] using h_end a ha have : (⟨a, ha⟩ : v) ≠ ⟨b, hb⟩ := by intro hab'' apply hab' simpa using hab'' exact hv.2 this · -- ** direction 2: empty orthogonal complement implies maximal simp only [Subset.antisymm_iff] rintro h u (huv : v ⊆ u) hu refine ⟨?_, huv⟩ intro x hxu refine ((mt (h x)) (hu.ne_zero ⟨x, hxu⟩)).imp_symm ?_ intro hxv y hy have hxv' : (⟨x, hxu⟩ : u) ∉ ((↑) ⁻¹' v : Set u) := by simp [huv, hxv] obtain ⟨l, hl, rfl⟩ : ∃ l ∈ Finsupp.supported 𝕜 𝕜 ((↑) ⁻¹' v : Set u), (Finsupp.total (↥u) E 𝕜 (↑)) l = y := by rw [← Finsupp.mem_span_image_iff_total] simp [huv, inter_eq_self_of_subset_right, hy] exact hu.inner_finsupp_eq_zero hxv' hl
/- Copyright (c) 2022 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.Spectrum import Mathlib.Data.Matrix.Rank import Mathlib.LinearAlgebra.Matrix.Diagonal import Mathlib.LinearAlgebra.Matrix.Hermitian #align_import linear_algebra.matrix.spectrum from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Spectral theory of hermitian matrices This file proves the spectral theorem for matrices. The proof of the spectral theorem is based on the spectral theorem for linear maps (`LinearMap.IsSymmetric.eigenvectorBasis_apply_self_apply`). ## Tags spectral theorem, diagonalization theorem-/ namespace Matrix variable {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] variable {A : Matrix n n 𝕜} namespace IsHermitian section DecidableEq variable [DecidableEq n] variable (hA : A.IsHermitian) /-- The eigenvalues of a hermitian matrix, indexed by `Fin (Fintype.card n)` where `n` is the index type of the matrix. -/ noncomputable def eigenvalues₀ : Fin (Fintype.card n) → ℝ := (isHermitian_iff_isSymmetric.1 hA).eigenvalues finrank_euclideanSpace #align matrix.is_hermitian.eigenvalues₀ Matrix.IsHermitian.eigenvalues₀ /-- The eigenvalues of a hermitian matrix, reusing the index `n` of the matrix entries. -/ noncomputable def eigenvalues : n → ℝ := fun i => hA.eigenvalues₀ <| (Fintype.equivOfCardEq (Fintype.card_fin _)).symm i #align matrix.is_hermitian.eigenvalues Matrix.IsHermitian.eigenvalues /-- A choice of an orthonormal basis of eigenvectors of a hermitian matrix. -/ noncomputable def eigenvectorBasis : OrthonormalBasis n 𝕜 (EuclideanSpace 𝕜 n) := ((isHermitian_iff_isSymmetric.1 hA).eigenvectorBasis finrank_euclideanSpace).reindex (Fintype.equivOfCardEq (Fintype.card_fin _)) #align matrix.is_hermitian.eigenvector_basis Matrix.IsHermitian.eigenvectorBasis lemma mulVec_eigenvectorBasis (j : n) : A *ᵥ ⇑(hA.eigenvectorBasis j) = (hA.eigenvalues j) • ⇑(hA.eigenvectorBasis j) := by simpa only [eigenvectorBasis, OrthonormalBasis.reindex_apply, toEuclideanLin_apply, RCLike.real_smul_eq_coe_smul (K := 𝕜)] using congr(⇑$((isHermitian_iff_isSymmetric.1 hA).apply_eigenvectorBasis finrank_euclideanSpace ((Fintype.equivOfCardEq (Fintype.card_fin _)).symm j))) /-- Unitary matrix whose columns are `Matrix.IsHermitian.eigenvectorBasis`. -/ noncomputable def eigenvectorUnitary {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]{A : Matrix n n 𝕜} [DecidableEq n] (hA : Matrix.IsHermitian A) : Matrix.unitaryGroup n 𝕜 := ⟨(EuclideanSpace.basisFun n 𝕜).toBasis.toMatrix (hA.eigenvectorBasis).toBasis, (EuclideanSpace.basisFun n 𝕜).toMatrix_orthonormalBasis_mem_unitary (eigenvectorBasis hA)⟩ #align matrix.is_hermitian.eigenvector_matrix Matrix.IsHermitian.eigenvectorUnitary lemma eigenvectorUnitary_coe {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] {A : Matrix n n 𝕜} [DecidableEq n] (hA : Matrix.IsHermitian A) : eigenvectorUnitary hA = (EuclideanSpace.basisFun n 𝕜).toBasis.toMatrix (hA.eigenvectorBasis).toBasis := rfl @[simp] theorem eigenvectorUnitary_apply (i j : n) : eigenvectorUnitary hA i j = ⇑(hA.eigenvectorBasis j) i := rfl #align matrix.is_hermitian.eigenvector_matrix_apply Matrix.IsHermitian.eigenvectorUnitary_apply theorem eigenvectorUnitary_mulVec (j : n) : eigenvectorUnitary hA *ᵥ Pi.single j 1 = ⇑(hA.eigenvectorBasis j) := by simp only [mulVec_single, eigenvectorUnitary_apply, mul_one] theorem star_eigenvectorUnitary_mulVec (j : n) : (star (eigenvectorUnitary hA : Matrix n n 𝕜)) *ᵥ ⇑(hA.eigenvectorBasis j) = Pi.single j 1 := by rw [← eigenvectorUnitary_mulVec, mulVec_mulVec, unitary.coe_star_mul_self, one_mulVec] /-- Unitary diagonalization of a Hermitian matrix. -/ theorem star_mul_self_mul_eq_diagonal : (star (eigenvectorUnitary hA : Matrix n n 𝕜)) * A * (eigenvectorUnitary hA : Matrix n n 𝕜) = diagonal (RCLike.ofReal ∘ hA.eigenvalues) := by apply Matrix.toEuclideanLin.injective apply Basis.ext (EuclideanSpace.basisFun n 𝕜).toBasis intro i simp only [toEuclideanLin_apply, OrthonormalBasis.coe_toBasis, EuclideanSpace.basisFun_apply, WithLp.equiv_single, ← mulVec_mulVec, eigenvectorUnitary_mulVec, ← mulVec_mulVec, mulVec_eigenvectorBasis, Matrix.diagonal_mulVec_single, mulVec_smul, star_eigenvectorUnitary_mulVec, RCLike.real_smul_eq_coe_smul (K := 𝕜), WithLp.equiv_symm_smul, WithLp.equiv_symm_single, Function.comp_apply, mul_one, WithLp.equiv_symm_single] apply PiLp.ext intro j simp only [PiLp.smul_apply, EuclideanSpace.single_apply, smul_eq_mul, mul_ite, mul_one, mul_zero] /-- **Diagonalization theorem**, **spectral theorem** for matrices; A hermitian matrix can be diagonalized by a change of basis. For the spectral theorem on linear maps, see `LinearMap.IsSymmetric.eigenvectorBasis_apply_self_apply`.-/
Mathlib/LinearAlgebra/Matrix/Spectrum.lean
106
111
theorem spectral_theorem : A = (eigenvectorUnitary hA : Matrix n n 𝕜) * diagonal (RCLike.ofReal ∘ hA.eigenvalues) * (star (eigenvectorUnitary hA : Matrix n n 𝕜)) := by
rw [← star_mul_self_mul_eq_diagonal, mul_assoc, mul_assoc, (Matrix.mem_unitaryGroup_iff).mp (eigenvectorUnitary hA).2, mul_one, ← mul_assoc, (Matrix.mem_unitaryGroup_iff).mp (eigenvectorUnitary hA).2, one_mul]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Anne Baanen -/ import Mathlib.Tactic.Ring.Basic import Mathlib.Tactic.TryThis import Mathlib.Tactic.Conv import Mathlib.Util.Qq /-! # `ring_nf` tactic A tactic which uses `ring` to rewrite expressions. This can be used non-terminally to normalize ring expressions in the goal such as `⊢ P (x + x + x)` ~> `⊢ P (x * 3)`, as well as being able to prove some equations that `ring` cannot because they involve ring reasoning inside a subterm, such as `sin (x + y) + sin (y + x) = 2 * sin (x + y)`. -/ set_option autoImplicit true -- In this file we would like to be able to use multi-character auto-implicits. set_option relaxedAutoImplicit true namespace Mathlib.Tactic open Lean hiding Rat open Qq Meta namespace Ring /-- True if this represents an atomic expression. -/ def ExBase.isAtom : ExBase sα a → Bool | .atom _ => true | _ => false /-- True if this represents an atomic expression. -/ def ExProd.isAtom : ExProd sα a → Bool | .mul va₁ (.const 1 _) (.const 1 _) => va₁.isAtom | _ => false /-- True if this represents an atomic expression. -/ def ExSum.isAtom : ExSum sα a → Bool | .add va₁ va₂ => match va₂ with -- FIXME: this takes a while to compile as one match | .zero => va₁.isAtom | _ => false | _ => false end Ring namespace RingNF open Ring /-- The normalization style for `ring_nf`. -/ inductive RingMode where /-- Sum-of-products form, like `x + x * y * 2 + z ^ 2`. -/ | SOP /-- Raw form: the representation `ring` uses internally. -/ | raw deriving Inhabited, BEq, Repr /-- Configuration for `ring_nf`. -/ structure Config where /-- the reducibility setting to use when comparing atoms for defeq -/ red := TransparencyMode.reducible /-- if true, atoms inside ring expressions will be reduced recursively -/ recursive := true /-- The normalization style. -/ mode := RingMode.SOP deriving Inhabited, BEq, Repr /-- Function elaborating `RingNF.Config`. -/ declare_config_elab elabConfig Config /-- The read-only state of the `RingNF` monad. -/ structure Context where /-- A basically empty simp context, passed to the `simp` traversal in `RingNF.rewrite`. -/ ctx : Simp.Context /-- A cleanup routine, which simplifies normalized polynomials to a more human-friendly format. -/ simp : Simp.Result → SimpM Simp.Result /-- The monad for `RingNF` contains, in addition to the `AtomM` state, a simp context for the main traversal and a simp function (which has another simp context) to simplify normalized polynomials. -/ abbrev M := ReaderT Context AtomM /-- A tactic in the `RingNF.M` monad which will simplify expression `parent` to a normal form. * `root`: true if this is a direct call to the function. `RingNF.M.run` sets this to `false` in recursive mode. -/ def rewrite (parent : Expr) (root := true) : M Simp.Result := fun nctx rctx s ↦ do let pre : Simp.Simproc := fun e => try guard <| root || parent != e -- recursion guard let e ← withReducible <| whnf e guard e.isApp -- all interesting ring expressions are applications let ⟨u, α, e⟩ ← inferTypeQ' e let sα ← synthInstanceQ (q(CommSemiring $α) : Q(Type u)) let c ← mkCache sα let ⟨a, _, pa⟩ ← match ← isAtomOrDerivable sα c e rctx s with | none => eval sα c e rctx s -- `none` indicates that `eval` will find something algebraic. | some none => failure -- No point rewriting atoms | some (some r) => pure r -- Nothing algebraic for `eval` to use, but `norm_num` simplifies. let r ← nctx.simp { expr := a, proof? := pa } if ← withReducible <| isDefEq r.expr e then return .done { expr := r.expr } pure (.done r) catch _ => pure <| .continue let post := Simp.postDefault #[] (·.1) <$> Simp.main parent nctx.ctx (methods := { pre, post }) variable [CommSemiring R] theorem add_assoc_rev (a b c : R) : a + (b + c) = a + b + c := (add_assoc ..).symm theorem mul_assoc_rev (a b c : R) : a * (b * c) = a * b * c := (mul_assoc ..).symm theorem mul_neg {R} [Ring R] (a b : R) : a * -b = -(a * b) := by simp theorem add_neg {R} [Ring R] (a b : R) : a + -b = a - b := (sub_eq_add_neg ..).symm theorem nat_rawCast_0 : (Nat.rawCast 0 : R) = 0 := by simp theorem nat_rawCast_1 : (Nat.rawCast 1 : R) = 1 := by simp theorem nat_rawCast_2 [Nat.AtLeastTwo n] : (Nat.rawCast n : R) = OfNat.ofNat n := rfl theorem int_rawCast_neg {R} [Ring R] : (Int.rawCast (.negOfNat n) : R) = -Nat.rawCast n := by simp
Mathlib/Tactic/Ring/RingNF.lean
124
125
theorem rat_rawCast_pos {R} [DivisionRing R] : (Rat.rawCast (.ofNat n) d : R) = Nat.rawCast n / Nat.rawCast d := by
simp
/- 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.Order.Floor import Mathlib.Algebra.Order.Field.Power import Mathlib.Data.Nat.Log #align_import data.int.log from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # Integer logarithms in a field with respect to a natural base This file defines two `ℤ`-valued analogs of the logarithm of `r : R` with base `b : ℕ`: * `Int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `↑b^k ≤ r`. * `Int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r ≤ ↑b^k`. Note that `Int.log` gives the position of the left-most non-zero digit: ```lean #eval (Int.log 10 (0.09 : ℚ), Int.log 10 (0.10 : ℚ), Int.log 10 (0.11 : ℚ)) -- (-2, -1, -1) #eval (Int.log 10 (9 : ℚ), Int.log 10 (10 : ℚ), Int.log 10 (11 : ℚ)) -- (0, 1, 1) ``` which means it can be used for computing digit expansions ```lean import Data.Fin.VecNotation import Mathlib.Data.Rat.Floor def digits (b : ℕ) (q : ℚ) (n : ℕ) : ℕ := ⌊q * ((b : ℚ) ^ (n - Int.log b q))⌋₊ % b #eval digits 10 (1/7) ∘ ((↑) : Fin 8 → ℕ) -- ![1, 4, 2, 8, 5, 7, 1, 4] ``` ## Main results * For `Int.log`: * `Int.zpow_log_le_self`, `Int.lt_zpow_succ_log_self`: the bounds formed by `Int.log`, `(b : R) ^ log b r ≤ r < (b : R) ^ (log b r + 1)`. * `Int.zpow_log_gi`: the galois coinsertion between `zpow` and `Int.log`. * For `Int.clog`: * `Int.zpow_pred_clog_lt_self`, `Int.self_le_zpow_clog`: the bounds formed by `Int.clog`, `(b : R) ^ (clog b r - 1) < r ≤ (b : R) ^ clog b r`. * `Int.clog_zpow_gi`: the galois insertion between `Int.clog` and `zpow`. * `Int.neg_log_inv_eq_clog`, `Int.neg_clog_inv_eq_log`: the link between the two definitions. -/ variable {R : Type*} [LinearOrderedSemifield R] [FloorSemiring R] namespace Int /-- The greatest power of `b` such that `b ^ log b r ≤ r`. -/ def log (b : ℕ) (r : R) : ℤ := if 1 ≤ r then Nat.log b ⌊r⌋₊ else -Nat.clog b ⌈r⁻¹⌉₊ #align int.log Int.log theorem log_of_one_le_right (b : ℕ) {r : R} (hr : 1 ≤ r) : log b r = Nat.log b ⌊r⌋₊ := if_pos hr #align int.log_of_one_le_right Int.log_of_one_le_right theorem log_of_right_le_one (b : ℕ) {r : R} (hr : r ≤ 1) : log b r = -Nat.clog b ⌈r⁻¹⌉₊ := by obtain rfl | hr := hr.eq_or_lt · rw [log, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] · exact if_neg hr.not_le #align int.log_of_right_le_one Int.log_of_right_le_one @[simp, norm_cast] theorem log_natCast (b : ℕ) (n : ℕ) : log b (n : R) = Nat.log b n := by cases n · simp [log_of_right_le_one] · rw [log_of_one_le_right, Nat.floor_natCast] simp #align int.log_nat_cast Int.log_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem log_ofNat (b : ℕ) (n : ℕ) [n.AtLeastTwo] : log b (no_index (OfNat.ofNat n : R)) = Nat.log b (OfNat.ofNat n) := log_natCast b n theorem log_of_left_le_one {b : ℕ} (hb : b ≤ 1) (r : R) : log b r = 0 := by rcases le_total 1 r with h | h · rw [log_of_one_le_right _ h, Nat.log_of_left_le_one hb, Int.ofNat_zero] · rw [log_of_right_le_one _ h, Nat.clog_of_left_le_one hb, Int.ofNat_zero, neg_zero] #align int.log_of_left_le_one Int.log_of_left_le_one theorem log_of_right_le_zero (b : ℕ) {r : R} (hr : r ≤ 0) : log b r = 0 := by rw [log_of_right_le_one _ (hr.trans zero_le_one), Nat.clog_of_right_le_one ((Nat.ceil_eq_zero.mpr <| inv_nonpos.2 hr).trans_le zero_le_one), Int.ofNat_zero, neg_zero] #align int.log_of_right_le_zero Int.log_of_right_le_zero theorem zpow_log_le_self {b : ℕ} {r : R} (hb : 1 < b) (hr : 0 < r) : (b : R) ^ log b r ≤ r := by rcases le_total 1 r with hr1 | hr1 · rw [log_of_one_le_right _ hr1] rw [zpow_natCast, ← Nat.cast_pow, ← Nat.le_floor_iff hr.le] exact Nat.pow_log_le_self b (Nat.floor_pos.mpr hr1).ne' · rw [log_of_right_le_one _ hr1, zpow_neg, zpow_natCast, ← Nat.cast_pow] exact inv_le_of_inv_le hr (Nat.ceil_le.1 <| Nat.le_pow_clog hb _) #align int.zpow_log_le_self Int.zpow_log_le_self theorem lt_zpow_succ_log_self {b : ℕ} (hb : 1 < b) (r : R) : r < (b : R) ^ (log b r + 1) := by rcases le_or_lt r 0 with hr | hr · rw [log_of_right_le_zero _ hr, zero_add, zpow_one] exact hr.trans_lt (zero_lt_one.trans_le <| mod_cast hb.le) rcases le_or_lt 1 r with hr1 | hr1 · rw [log_of_one_le_right _ hr1] rw [Int.ofNat_add_one_out, zpow_natCast, ← Nat.cast_pow] apply Nat.lt_of_floor_lt exact Nat.lt_pow_succ_log_self hb _ · rw [log_of_right_le_one _ hr1.le] have hcri : 1 < r⁻¹ := one_lt_inv hr hr1 have : 1 ≤ Nat.clog b ⌈r⁻¹⌉₊ := Nat.succ_le_of_lt (Nat.clog_pos hb <| Nat.one_lt_cast.1 <| hcri.trans_le (Nat.le_ceil _)) rw [neg_add_eq_sub, ← neg_sub, ← Int.ofNat_one, ← Int.ofNat_sub this, zpow_neg, zpow_natCast, lt_inv hr (pow_pos (Nat.cast_pos.mpr <| zero_lt_one.trans hb) _), ← Nat.cast_pow] refine Nat.lt_ceil.1 ?_ exact Nat.pow_pred_clog_lt_self hb <| Nat.one_lt_cast.1 <| hcri.trans_le <| Nat.le_ceil _ #align int.lt_zpow_succ_log_self Int.lt_zpow_succ_log_self @[simp] theorem log_zero_right (b : ℕ) : log b (0 : R) = 0 := log_of_right_le_zero b le_rfl #align int.log_zero_right Int.log_zero_right @[simp] theorem log_one_right (b : ℕ) : log b (1 : R) = 0 := by rw [log_of_one_le_right _ le_rfl, Nat.floor_one, Nat.log_one_right, Int.ofNat_zero] #align int.log_one_right Int.log_one_right -- Porting note: needed to replace b ^ z with (b : R) ^ z in the below theorem log_zpow {b : ℕ} (hb : 1 < b) (z : ℤ) : log b ((b : R) ^ z : R) = z := by obtain ⟨n, rfl | rfl⟩ := Int.eq_nat_or_neg z · rw [log_of_one_le_right _ (one_le_zpow_of_nonneg _ <| Int.natCast_nonneg _), zpow_natCast, ← Nat.cast_pow, Nat.floor_natCast, Nat.log_pow hb] exact mod_cast hb.le · rw [log_of_right_le_one _ (zpow_le_one_of_nonpos _ <| neg_nonpos.mpr (Int.natCast_nonneg _)), zpow_neg, inv_inv, zpow_natCast, ← Nat.cast_pow, Nat.ceil_natCast, Nat.clog_pow _ _ hb] exact mod_cast hb.le #align int.log_zpow Int.log_zpow @[mono] theorem log_mono_right {b : ℕ} {r₁ r₂ : R} (h₀ : 0 < r₁) (h : r₁ ≤ r₂) : log b r₁ ≤ log b r₂ := by rcases le_total r₁ 1 with h₁ | h₁ <;> rcases le_total r₂ 1 with h₂ | h₂ · rw [log_of_right_le_one _ h₁, log_of_right_le_one _ h₂, neg_le_neg_iff, Int.ofNat_le] exact Nat.clog_mono_right _ (Nat.ceil_mono <| inv_le_inv_of_le h₀ h) · rw [log_of_right_le_one _ h₁, log_of_one_le_right _ h₂] exact (neg_nonpos.mpr (Int.natCast_nonneg _)).trans (Int.natCast_nonneg _) · obtain rfl := le_antisymm h (h₂.trans h₁) rfl · rw [log_of_one_le_right _ h₁, log_of_one_le_right _ h₂, Int.ofNat_le] exact Nat.log_mono_right (Nat.floor_mono h) #align int.log_mono_right Int.log_mono_right variable (R) /-- Over suitable subtypes, `zpow` and `Int.log` form a galois coinsertion -/ def zpowLogGi {b : ℕ} (hb : 1 < b) : GaloisCoinsertion (fun z : ℤ => Subtype.mk ((b : R) ^ z) <| zpow_pos_of_pos (mod_cast zero_lt_one.trans hb) z) fun r : Set.Ioi (0 : R) => Int.log b (r : R) := GaloisCoinsertion.monotoneIntro (fun r₁ _ => log_mono_right r₁.2) (fun _ _ hz => Subtype.coe_le_coe.mp <| (zpow_strictMono <| mod_cast hb).monotone hz) (fun r => Subtype.coe_le_coe.mp <| zpow_log_le_self hb r.2) fun _ => log_zpow (R := R) hb _ #align int.zpow_log_gi Int.zpowLogGi variable {R} /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem lt_zpow_iff_log_lt {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : r < (b : R) ^ x ↔ log b r < x := @GaloisConnection.lt_iff_lt _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ #align int.lt_zpow_iff_log_lt Int.lt_zpow_iff_log_lt /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem zpow_le_iff_le_log {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : (b : R) ^ x ≤ r ↔ x ≤ log b r := @GaloisConnection.le_iff_le _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ #align int.zpow_le_iff_le_log Int.zpow_le_iff_le_log /-- The least power of `b` such that `r ≤ b ^ log b r`. -/ def clog (b : ℕ) (r : R) : ℤ := if 1 ≤ r then Nat.clog b ⌈r⌉₊ else -Nat.log b ⌊r⁻¹⌋₊ #align int.clog Int.clog theorem clog_of_one_le_right (b : ℕ) {r : R} (hr : 1 ≤ r) : clog b r = Nat.clog b ⌈r⌉₊ := if_pos hr #align int.clog_of_one_le_right Int.clog_of_one_le_right theorem clog_of_right_le_one (b : ℕ) {r : R} (hr : r ≤ 1) : clog b r = -Nat.log b ⌊r⁻¹⌋₊ := by obtain rfl | hr := hr.eq_or_lt · rw [clog, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] · exact if_neg hr.not_le #align int.clog_of_right_le_one Int.clog_of_right_le_one theorem clog_of_right_le_zero (b : ℕ) {r : R} (hr : r ≤ 0) : clog b r = 0 := by rw [clog, if_neg (hr.trans_lt zero_lt_one).not_le, neg_eq_zero, Int.natCast_eq_zero, Nat.log_eq_zero_iff] rcases le_or_lt b 1 with hb | hb · exact Or.inr hb · refine Or.inl (lt_of_le_of_lt ?_ hb) exact Nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one) #align int.clog_of_right_le_zero Int.clog_of_right_le_zero @[simp] theorem clog_inv (b : ℕ) (r : R) : clog b r⁻¹ = -log b r := by cases' lt_or_le 0 r with hrp hrp · obtain hr | hr := le_total 1 r · rw [clog_of_right_le_one _ (inv_le_one hr), log_of_one_le_right _ hr, inv_inv] · rw [clog_of_one_le_right _ (one_le_inv hrp hr), log_of_right_le_one _ hr, neg_neg] · rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero] #align int.clog_inv Int.clog_inv @[simp] theorem log_inv (b : ℕ) (r : R) : log b r⁻¹ = -clog b r := by rw [← inv_inv r, clog_inv, neg_neg, inv_inv] #align int.log_inv Int.log_inv -- note this is useful for writing in reverse
Mathlib/Data/Int/Log.lean
228
228
theorem neg_log_inv_eq_clog (b : ℕ) (r : R) : -log b r⁻¹ = clog b r := by
rw [log_inv, neg_neg]
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Bhavik Mehta -/ import Mathlib.Probability.ConditionalProbability import Mathlib.MeasureTheory.Measure.Count #align_import probability.cond_count from "leanprover-community/mathlib"@"117e93f82b5f959f8193857370109935291f0cc4" /-! # Classical probability The classical formulation of probability states that the probability of an event occurring in a finite probability space is the ratio of that event to all possible events. This notion can be expressed with measure theory using the counting measure. In particular, given the sets `s` and `t`, we define the probability of `t` occurring in `s` to be `|s|⁻¹ * |s ∩ t|`. With this definition, we recover the probability over the entire sample space when `s = Set.univ`. Classical probability is often used in combinatorics and we prove some useful lemmas in this file for that purpose. ## Main definition * `ProbabilityTheory.condCount`: given a set `s`, `condCount s` is the counting measure conditioned on `s`. This is a probability measure when `s` is finite and nonempty. ## Notes The original aim of this file is to provide a measure theoretic method of describing the probability an element of a set `s` satisfies some predicate `P`. Our current formulation still allow us to describe this by abusing the definitional equality of sets and predicates by simply writing `condCount s P`. We should avoid this however as none of the lemmas are written for predicates. -/ noncomputable section open ProbabilityTheory open MeasureTheory MeasurableSpace namespace ProbabilityTheory variable {Ω : Type*} [MeasurableSpace Ω] /-- Given a set `s`, `condCount s` is the counting measure conditioned on `s`. In particular, `condCount s t` is the proportion of `s` that is contained in `t`. This is a probability measure when `s` is finite and nonempty and is given by `ProbabilityTheory.condCount_isProbabilityMeasure`. -/ def condCount (s : Set Ω) : Measure Ω := Measure.count[|s] #align probability_theory.cond_count ProbabilityTheory.condCount @[simp] theorem condCount_empty_meas : (condCount ∅ : Measure Ω) = 0 := by simp [condCount] #align probability_theory.cond_count_empty_meas ProbabilityTheory.condCount_empty_meas theorem condCount_empty {s : Set Ω} : condCount s ∅ = 0 := by simp #align probability_theory.cond_count_empty ProbabilityTheory.condCount_empty theorem finite_of_condCount_ne_zero {s t : Set Ω} (h : condCount s t ≠ 0) : s.Finite := by by_contra hs' simp [condCount, cond, Measure.count_apply_infinite hs'] at h #align probability_theory.finite_of_cond_count_ne_zero ProbabilityTheory.finite_of_condCount_ne_zero theorem condCount_univ [Fintype Ω] {s : Set Ω} : condCount Set.univ s = Measure.count s / Fintype.card Ω := by rw [condCount, cond_apply _ MeasurableSet.univ, ← ENNReal.div_eq_inv_mul, Set.univ_inter] congr rw [← Finset.coe_univ, Measure.count_apply, Finset.univ.tsum_subtype' fun _ => (1 : ENNReal)] · simp [Finset.card_univ] · exact (@Finset.coe_univ Ω _).symm ▸ MeasurableSet.univ #align probability_theory.cond_count_univ ProbabilityTheory.condCount_univ variable [MeasurableSingletonClass Ω] theorem condCount_isProbabilityMeasure {s : Set Ω} (hs : s.Finite) (hs' : s.Nonempty) : IsProbabilityMeasure (condCount s) := { measure_univ := by rw [condCount, cond_apply _ hs.measurableSet, Set.inter_univ, ENNReal.inv_mul_cancel] · exact fun h => hs'.ne_empty <| Measure.empty_of_count_eq_zero h · exact (Measure.count_apply_lt_top.2 hs).ne } #align probability_theory.cond_count_is_probability_measure ProbabilityTheory.condCount_isProbabilityMeasure theorem condCount_singleton (ω : Ω) (t : Set Ω) [Decidable (ω ∈ t)] : condCount {ω} t = if ω ∈ t then 1 else 0 := by rw [condCount, cond_apply _ (measurableSet_singleton ω), Measure.count_singleton, inv_one, one_mul] split_ifs · rw [(by simpa : ({ω} : Set Ω) ∩ t = {ω}), Measure.count_singleton] · rw [(by simpa : ({ω} : Set Ω) ∩ t = ∅), Measure.count_empty] #align probability_theory.cond_count_singleton ProbabilityTheory.condCount_singleton variable {s t u : Set Ω} theorem condCount_inter_self (hs : s.Finite) : condCount s (s ∩ t) = condCount s t := by rw [condCount, cond_inter_self _ hs.measurableSet] #align probability_theory.cond_count_inter_self ProbabilityTheory.condCount_inter_self theorem condCount_self (hs : s.Finite) (hs' : s.Nonempty) : condCount s s = 1 := by rw [condCount, cond_apply _ hs.measurableSet, Set.inter_self, ENNReal.inv_mul_cancel] · exact fun h => hs'.ne_empty <| Measure.empty_of_count_eq_zero h · exact (Measure.count_apply_lt_top.2 hs).ne #align probability_theory.cond_count_self ProbabilityTheory.condCount_self theorem condCount_eq_one_of (hs : s.Finite) (hs' : s.Nonempty) (ht : s ⊆ t) : condCount s t = 1 := by haveI := condCount_isProbabilityMeasure hs hs' refine eq_of_le_of_not_lt prob_le_one ?_ rw [not_lt, ← condCount_self hs hs'] exact measure_mono ht #align probability_theory.cond_count_eq_one_of ProbabilityTheory.condCount_eq_one_of theorem pred_true_of_condCount_eq_one (h : condCount s t = 1) : s ⊆ t := by have hsf := finite_of_condCount_ne_zero (by rw [h]; exact one_ne_zero) rw [condCount, cond_apply _ hsf.measurableSet, mul_comm] at h replace h := ENNReal.eq_inv_of_mul_eq_one_left h rw [inv_inv, Measure.count_apply_finite _ hsf, Measure.count_apply_finite _ (hsf.inter_of_left _), Nat.cast_inj] at h suffices s ∩ t = s by exact this ▸ fun x hx => hx.2 rw [← @Set.Finite.toFinset_inj _ _ _ (hsf.inter_of_left _) hsf] exact Finset.eq_of_subset_of_card_le (Set.Finite.toFinset_mono s.inter_subset_left) h.ge #align probability_theory.pred_true_of_cond_count_eq_one ProbabilityTheory.pred_true_of_condCount_eq_one theorem condCount_eq_zero_iff (hs : s.Finite) : condCount s t = 0 ↔ s ∩ t = ∅ := by simp [condCount, cond_apply _ hs.measurableSet, Measure.count_apply_eq_top, Set.not_infinite.2 hs, Measure.count_apply_finite _ (hs.inter_of_left _)] #align probability_theory.cond_count_eq_zero_iff ProbabilityTheory.condCount_eq_zero_iff theorem condCount_of_univ (hs : s.Finite) (hs' : s.Nonempty) : condCount s Set.univ = 1 := condCount_eq_one_of hs hs' s.subset_univ #align probability_theory.cond_count_of_univ ProbabilityTheory.condCount_of_univ theorem condCount_inter (hs : s.Finite) : condCount s (t ∩ u) = condCount (s ∩ t) u * condCount s t := by by_cases hst : s ∩ t = ∅ · rw [hst, condCount_empty_meas, Measure.coe_zero, Pi.zero_apply, zero_mul, condCount_eq_zero_iff hs, ← Set.inter_assoc, hst, Set.empty_inter] rw [condCount, condCount, cond_apply _ hs.measurableSet, cond_apply _ hs.measurableSet, cond_apply _ (hs.inter_of_left _).measurableSet, mul_comm _ (Measure.count (s ∩ t)), ← mul_assoc, mul_comm _ (Measure.count (s ∩ t)), ← mul_assoc, ENNReal.mul_inv_cancel, one_mul, mul_comm, Set.inter_assoc] · rwa [← Measure.count_eq_zero_iff] at hst · exact (Measure.count_apply_lt_top.2 <| hs.inter_of_left _).ne #align probability_theory.cond_count_inter ProbabilityTheory.condCount_inter
Mathlib/Probability/CondCount.lean
151
154
theorem condCount_inter' (hs : s.Finite) : condCount s (t ∩ u) = condCount (s ∩ u) t * condCount s u := by
rw [← Set.inter_comm] exact condCount_inter hs
/- Copyright (c) 2021 Alex J. Best. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best -/ import Mathlib.Analysis.Convex.Body import Mathlib.Analysis.Convex.Measure import Mathlib.MeasureTheory.Group.FundamentalDomain #align_import measure_theory.group.geometry_of_numbers from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Geometry of numbers In this file we prove some of the fundamental theorems in the geometry of numbers, as studied by Hermann Minkowski. ## Main results * `exists_pair_mem_lattice_not_disjoint_vadd`: Blichfeldt's principle, existence of two distinct points in a subgroup such that the translates of a set by these two points are not disjoint when the covolume of the subgroup is larger than the volume of the set. * `exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure`: Minkowski's theorem, existence of a non-zero lattice point inside a convex symmetric domain of large enough volume. ## TODO * Calculate the volume of the fundamental domain of a finite index subgroup * Voronoi diagrams * See [Pete L. Clark, *Abstract Geometry of Numbers: Linear Forms* (arXiv)](https://arxiv.org/abs/1405.2119) for some more ideas. ## References * [Pete L. Clark, *Geometry of Numbers with Applications to Number Theory*][clark_gon] p.28 -/ namespace MeasureTheory open ENNReal FiniteDimensional MeasureTheory MeasureTheory.Measure Set Filter open scoped Pointwise NNReal variable {E L : Type*} [MeasurableSpace E] {μ : Measure E} {F s : Set E} /-- **Blichfeldt's Theorem**. If the volume of the set `s` is larger than the covolume of the countable subgroup `L` of `E`, then there exist two distinct points `x, y ∈ L` such that `(x + s)` and `(y + s)` are not disjoint. -/ theorem exists_pair_mem_lattice_not_disjoint_vadd [AddCommGroup L] [Countable L] [AddAction L E] [MeasurableSpace L] [MeasurableVAdd L E] [VAddInvariantMeasure L E μ] (fund : IsAddFundamentalDomain L F μ) (hS : NullMeasurableSet s μ) (h : μ F < μ s) : ∃ x y : L, x ≠ y ∧ ¬Disjoint (x +ᵥ s) (y +ᵥ s) := by contrapose! h exact ((fund.measure_eq_tsum _).trans (measure_iUnion₀ (Pairwise.mono h fun i j hij => (hij.mono inf_le_left inf_le_left).aedisjoint) fun _ => (hS.vadd _).inter fund.nullMeasurableSet).symm).trans_le (measure_mono <| Set.iUnion_subset fun _ => Set.inter_subset_right) #align measure_theory.exists_pair_mem_lattice_not_disjoint_vadd MeasureTheory.exists_pair_mem_lattice_not_disjoint_vadd /-- The **Minkowski Convex Body Theorem**. If `s` is a convex symmetric domain of `E` whose volume is large enough compared to the covolume of a lattice `L` of `E`, then it contains a non-zero lattice point of `L`. -/
Mathlib/MeasureTheory/Group/GeometryOfNumbers.lean
64
83
theorem exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure [NormedAddCommGroup E] [NormedSpace ℝ E] [BorelSpace E] [FiniteDimensional ℝ E] [IsAddHaarMeasure μ] {L : AddSubgroup E} [Countable L] (fund : IsAddFundamentalDomain L F μ) (h_symm : ∀ x ∈ s, -x ∈ s) (h_conv : Convex ℝ s) (h : μ F * 2 ^ finrank ℝ E < μ s) : ∃ x ≠ 0, ((x : L) : E) ∈ s := by
have h_vol : μ F < μ ((2⁻¹ : ℝ) • s) := by rw [addHaar_smul_of_nonneg μ (by norm_num : 0 ≤ (2 : ℝ)⁻¹) s, ← mul_lt_mul_right (pow_ne_zero (finrank ℝ E) (two_ne_zero' _)) (pow_ne_top two_ne_top), mul_right_comm, ofReal_pow (by norm_num : 0 ≤ (2 : ℝ)⁻¹), ofReal_inv_of_pos zero_lt_two] norm_num rwa [← mul_pow, ENNReal.inv_mul_cancel two_ne_zero two_ne_top, one_pow, one_mul] obtain ⟨x, y, hxy, h⟩ := exists_pair_mem_lattice_not_disjoint_vadd fund ((h_conv.smul _).nullMeasurableSet _) h_vol obtain ⟨_, ⟨v, hv, rfl⟩, w, hw, hvw⟩ := Set.not_disjoint_iff.mp h refine ⟨x - y, sub_ne_zero.2 hxy, ?_⟩ rw [Set.mem_inv_smul_set_iff₀ (two_ne_zero' ℝ)] at hv hw simp_rw [AddSubgroup.vadd_def, vadd_eq_add, add_comm _ w, ← sub_eq_sub_iff_add_eq_add, ← AddSubgroup.coe_sub] at hvw rw [← hvw, ← inv_smul_smul₀ (two_ne_zero' ℝ) (_ - _), smul_sub, sub_eq_add_neg, smul_add] refine h_conv hw (h_symm _ hv) ?_ ?_ ?_ <;> norm_num
/- 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.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Group.Commute.Hom import Mathlib.Data.Fintype.Card #align_import data.finset.noncomm_prod from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # Products (respectively, sums) over a finset or a multiset. The regular `Finset.prod` and `Multiset.prod` require `[CommMonoid α]`. Often, there are collections `s : Finset α` where `[Monoid α]` and we know, in a dependent fashion, that for all the terms `∀ (x ∈ s) (y ∈ s), Commute x y`. This allows to still have a well-defined product over `s`. ## Main definitions - `Finset.noncommProd`, requiring a proof of commutativity of held terms - `Multiset.noncommProd`, requiring a proof of commutativity of held terms ## Implementation details While `List.prod` is defined via `List.foldl`, `noncommProd` is defined via `Multiset.foldr` for neater proofs and definitions. By the commutativity assumption, the two must be equal. TODO: Tidy up this file by using the fact that the submonoid generated by commuting elements is commutative and using the `Finset.prod` versions of lemmas to prove the `noncommProd` version. -/ variable {F ι α β γ : Type*} (f : α → β → β) (op : α → α → α) namespace Multiset /-- Fold of a `s : Multiset α` with `f : α → β → β`, given a proof that `LeftCommutative f` on all elements `x ∈ s`. -/ def noncommFoldr (s : Multiset α) (comm : { x | x ∈ s }.Pairwise fun x y => ∀ b, f x (f y b) = f y (f x b)) (b : β) : β := s.attach.foldr (f ∘ Subtype.val) (fun ⟨_, hx⟩ ⟨_, hy⟩ => haveI : IsRefl α fun x y => ∀ b, f x (f y b) = f y (f x b) := ⟨fun _ _ => rfl⟩ comm.of_refl hx hy) b #align multiset.noncomm_foldr Multiset.noncommFoldr @[simp] theorem noncommFoldr_coe (l : List α) (comm) (b : β) : noncommFoldr f (l : Multiset α) comm b = l.foldr f b := by simp only [noncommFoldr, coe_foldr, coe_attach, List.attach, List.attachWith, Function.comp] rw [← List.foldr_map] simp [List.map_pmap] #align multiset.noncomm_foldr_coe Multiset.noncommFoldr_coe @[simp] theorem noncommFoldr_empty (h) (b : β) : noncommFoldr f (0 : Multiset α) h b = b := rfl #align multiset.noncomm_foldr_empty Multiset.noncommFoldr_empty theorem noncommFoldr_cons (s : Multiset α) (a : α) (h h') (b : β) : noncommFoldr f (a ::ₘ s) h b = f a (noncommFoldr f s h' b) := by induction s using Quotient.inductionOn simp #align multiset.noncomm_foldr_cons Multiset.noncommFoldr_cons theorem noncommFoldr_eq_foldr (s : Multiset α) (h : LeftCommutative f) (b : β) : noncommFoldr f s (fun x _ y _ _ => h x y) b = foldr f h b s := by induction s using Quotient.inductionOn simp #align multiset.noncomm_foldr_eq_foldr Multiset.noncommFoldr_eq_foldr section assoc variable [assoc : Std.Associative op] /-- Fold of a `s : Multiset α` with an associative `op : α → α → α`, given a proofs that `op` is commutative on all elements `x ∈ s`. -/ def noncommFold (s : Multiset α) (comm : { x | x ∈ s }.Pairwise fun x y => op x y = op y x) : α → α := noncommFoldr op s fun x hx y hy h b => by rw [← assoc.assoc, comm hx hy h, assoc.assoc] #align multiset.noncomm_fold Multiset.noncommFold @[simp] theorem noncommFold_coe (l : List α) (comm) (a : α) : noncommFold op (l : Multiset α) comm a = l.foldr op a := by simp [noncommFold] #align multiset.noncomm_fold_coe Multiset.noncommFold_coe @[simp] theorem noncommFold_empty (h) (a : α) : noncommFold op (0 : Multiset α) h a = a := rfl #align multiset.noncomm_fold_empty Multiset.noncommFold_empty theorem noncommFold_cons (s : Multiset α) (a : α) (h h') (x : α) : noncommFold op (a ::ₘ s) h x = op a (noncommFold op s h' x) := by induction s using Quotient.inductionOn simp #align multiset.noncomm_fold_cons Multiset.noncommFold_cons theorem noncommFold_eq_fold (s : Multiset α) [Std.Commutative op] (a : α) : noncommFold op s (fun x _ y _ _ => Std.Commutative.comm x y) a = fold op a s := by induction s using Quotient.inductionOn simp #align multiset.noncomm_fold_eq_fold Multiset.noncommFold_eq_fold end assoc variable [Monoid α] [Monoid β] /-- Product of a `s : Multiset α` with `[Monoid α]`, given a proof that `*` commutes on all elements `x ∈ s`. -/ @[to_additive "Sum of a `s : Multiset α` with `[AddMonoid α]`, given a proof that `+` commutes on all elements `x ∈ s`."] def noncommProd (s : Multiset α) (comm : { x | x ∈ s }.Pairwise Commute) : α := s.noncommFold (· * ·) comm 1 #align multiset.noncomm_prod Multiset.noncommProd #align multiset.noncomm_sum Multiset.noncommSum @[to_additive (attr := simp)] theorem noncommProd_coe (l : List α) (comm) : noncommProd (l : Multiset α) comm = l.prod := by rw [noncommProd] simp only [noncommFold_coe] induction' l with hd tl hl · simp · rw [List.prod_cons, List.foldr, hl] intro x hx y hy exact comm (List.mem_cons_of_mem _ hx) (List.mem_cons_of_mem _ hy) #align multiset.noncomm_prod_coe Multiset.noncommProd_coe #align multiset.noncomm_sum_coe Multiset.noncommSum_coe @[to_additive (attr := simp)] theorem noncommProd_empty (h) : noncommProd (0 : Multiset α) h = 1 := rfl #align multiset.noncomm_prod_empty Multiset.noncommProd_empty #align multiset.noncomm_sum_empty Multiset.noncommSum_empty @[to_additive (attr := simp)] theorem noncommProd_cons (s : Multiset α) (a : α) (comm) : noncommProd (a ::ₘ s) comm = a * noncommProd s (comm.mono fun _ => mem_cons_of_mem) := by induction s using Quotient.inductionOn simp #align multiset.noncomm_prod_cons Multiset.noncommProd_cons #align multiset.noncomm_sum_cons Multiset.noncommSum_cons @[to_additive] theorem noncommProd_cons' (s : Multiset α) (a : α) (comm) : noncommProd (a ::ₘ s) comm = noncommProd s (comm.mono fun _ => mem_cons_of_mem) * a := by induction' s using Quotient.inductionOn with s simp only [quot_mk_to_coe, cons_coe, noncommProd_coe, List.prod_cons] induction' s with hd tl IH · simp · rw [List.prod_cons, mul_assoc, ← IH, ← mul_assoc, ← mul_assoc] · congr 1 apply comm.of_refl <;> simp · intro x hx y hy simp only [quot_mk_to_coe, List.mem_cons, mem_coe, cons_coe] at hx hy apply comm · cases hx <;> simp [*] · cases hy <;> simp [*] #align multiset.noncomm_prod_cons' Multiset.noncommProd_cons' #align multiset.noncomm_sum_cons' Multiset.noncommSum_cons' @[to_additive] theorem noncommProd_add (s t : Multiset α) (comm) : noncommProd (s + t) comm = noncommProd s (comm.mono <| subset_of_le <| s.le_add_right t) * noncommProd t (comm.mono <| subset_of_le <| t.le_add_left s) := by rcases s with ⟨⟩ rcases t with ⟨⟩ simp #align multiset.noncomm_prod_add Multiset.noncommProd_add #align multiset.noncomm_sum_add Multiset.noncommSum_add @[to_additive] lemma noncommProd_induction (s : Multiset α) (comm) (p : α → Prop) (hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p x) : p (s.noncommProd comm) := by induction' s using Quotient.inductionOn with l simp only [quot_mk_to_coe, noncommProd_coe, mem_coe] at base ⊢ exact l.prod_induction p hom unit base variable [FunLike F α β] @[to_additive] protected theorem noncommProd_map_aux [MonoidHomClass F α β] (s : Multiset α) (comm : { x | x ∈ s }.Pairwise Commute) (f : F) : { x | x ∈ s.map f }.Pairwise Commute := by simp only [Multiset.mem_map] rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ _ exact (comm.of_refl hx hy).map f #align multiset.noncomm_prod_map_aux Multiset.noncommProd_map_aux #align multiset.noncomm_sum_map_aux Multiset.noncommSum_map_aux @[to_additive] theorem noncommProd_map [MonoidHomClass F α β] (s : Multiset α) (comm) (f : F) : f (s.noncommProd comm) = (s.map f).noncommProd (Multiset.noncommProd_map_aux s comm f) := by induction s using Quotient.inductionOn simpa using map_list_prod f _ #align multiset.noncomm_prod_map Multiset.noncommProd_map #align multiset.noncomm_sum_map Multiset.noncommSum_map @[to_additive noncommSum_eq_card_nsmul] theorem noncommProd_eq_pow_card (s : Multiset α) (comm) (m : α) (h : ∀ x ∈ s, x = m) : s.noncommProd comm = m ^ Multiset.card s := by induction s using Quotient.inductionOn simp only [quot_mk_to_coe, noncommProd_coe, coe_card, mem_coe] at * exact List.prod_eq_pow_card _ m h #align multiset.noncomm_prod_eq_pow_card Multiset.noncommProd_eq_pow_card #align multiset.noncomm_sum_eq_card_nsmul Multiset.noncommSum_eq_card_nsmul @[to_additive] theorem noncommProd_eq_prod {α : Type*} [CommMonoid α] (s : Multiset α) : (noncommProd s fun _ _ _ _ _ => Commute.all _ _) = prod s := by induction s using Quotient.inductionOn simp #align multiset.noncomm_prod_eq_prod Multiset.noncommProd_eq_prod #align multiset.noncomm_sum_eq_sum Multiset.noncommSum_eq_sum @[to_additive] theorem noncommProd_commute (s : Multiset α) (comm) (y : α) (h : ∀ x ∈ s, Commute y x) : Commute y (s.noncommProd comm) := by induction s using Quotient.inductionOn simp only [quot_mk_to_coe, noncommProd_coe] exact Commute.list_prod_right _ _ h #align multiset.noncomm_prod_commute Multiset.noncommProd_commute #align multiset.noncomm_sum_add_commute Multiset.noncommSum_addCommute theorem mul_noncommProd_erase [DecidableEq α] (s : Multiset α) {a : α} (h : a ∈ s) (comm) (comm' := fun x hx y hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) : a * (s.erase a).noncommProd comm' = s.noncommProd comm := by induction' s using Quotient.inductionOn with l simp only [quot_mk_to_coe, mem_coe, coe_erase, noncommProd_coe] at comm h ⊢ suffices ∀ x ∈ l, ∀ y ∈ l, x * y = y * x by rw [List.prod_erase_of_comm h this] intro x hx y hy rcases eq_or_ne x y with rfl | hxy · rfl exact comm hx hy hxy theorem noncommProd_erase_mul [DecidableEq α] (s : Multiset α) {a : α} (h : a ∈ s) (comm) (comm' := fun x hx y hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) : (s.erase a).noncommProd comm' * a = s.noncommProd comm := by suffices ∀ b ∈ erase s a, Commute a b by rw [← (noncommProd_commute (s.erase a) comm' a this).eq, mul_noncommProd_erase s h comm comm'] intro b hb rcases eq_or_ne a b with rfl | hab · rfl exact comm h (mem_of_mem_erase hb) hab end Multiset namespace Finset variable [Monoid β] [Monoid γ] /-- Proof used in definition of `Finset.noncommProd` -/ @[to_additive] theorem noncommProd_lemma (s : Finset α) (f : α → β) (comm : (s : Set α).Pairwise fun a b => Commute (f a) (f b)) : Set.Pairwise { x | x ∈ Multiset.map f s.val } Commute := by simp_rw [Multiset.mem_map] rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ _ exact comm.of_refl ha hb /-- Product of a `s : Finset α` mapped with `f : α → β` with `[Monoid β]`, given a proof that `*` commutes on all elements `f x` for `x ∈ s`. -/ @[to_additive "Sum of a `s : Finset α` mapped with `f : α → β` with `[AddMonoid β]`, given a proof that `+` commutes on all elements `f x` for `x ∈ s`."] def noncommProd (s : Finset α) (f : α → β) (comm : (s : Set α).Pairwise fun a b => Commute (f a) (f b)) : β := (s.1.map f).noncommProd <| noncommProd_lemma s f comm #align finset.noncomm_prod Finset.noncommProd #align finset.noncomm_sum Finset.noncommSum @[to_additive] lemma noncommProd_induction (s : Finset α) (f : α → β) (comm) (p : β → Prop) (hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p (f x)) : p (s.noncommProd f comm) := by refine Multiset.noncommProd_induction _ _ _ hom unit fun b hb ↦ ?_ obtain (⟨a, ha : a ∈ s, rfl : f a = b⟩) := by simpa using hb exact base a ha @[to_additive (attr := congr)] theorem noncommProd_congr {s₁ s₂ : Finset α} {f g : α → β} (h₁ : s₁ = s₂) (h₂ : ∀ x ∈ s₂, f x = g x) (comm) : noncommProd s₁ f comm = noncommProd s₂ g fun x hx y hy h => by dsimp only rw [← h₂ _ hx, ← h₂ _ hy] subst h₁ exact comm hx hy h := by simp_rw [noncommProd, Multiset.map_congr (congr_arg _ h₁) h₂] #align finset.noncomm_prod_congr Finset.noncommProd_congr #align finset.noncomm_sum_congr Finset.noncommSum_congr @[to_additive (attr := simp)] theorem noncommProd_toFinset [DecidableEq α] (l : List α) (f : α → β) (comm) (hl : l.Nodup) : noncommProd l.toFinset f comm = (l.map f).prod := by rw [← List.dedup_eq_self] at hl simp [noncommProd, hl] #align finset.noncomm_prod_to_finset Finset.noncommProd_toFinset #align finset.noncomm_sum_to_finset Finset.noncommSum_toFinset @[to_additive (attr := simp)] theorem noncommProd_empty (f : α → β) (h) : noncommProd (∅ : Finset α) f h = 1 := rfl #align finset.noncomm_prod_empty Finset.noncommProd_empty #align finset.noncomm_sum_empty Finset.noncommSum_empty @[to_additive (attr := simp)] theorem noncommProd_cons (s : Finset α) (a : α) (f : α → β) (ha : a ∉ s) (comm) : noncommProd (cons a s ha) f comm = f a * noncommProd s f (comm.mono fun _ => Finset.mem_cons.2 ∘ .inr) := by simp_rw [noncommProd, Finset.cons_val, Multiset.map_cons, Multiset.noncommProd_cons] @[to_additive] theorem noncommProd_cons' (s : Finset α) (a : α) (f : α → β) (ha : a ∉ s) (comm) : noncommProd (cons a s ha) f comm = noncommProd s f (comm.mono fun _ => Finset.mem_cons.2 ∘ .inr) * f a := by simp_rw [noncommProd, Finset.cons_val, Multiset.map_cons, Multiset.noncommProd_cons'] @[to_additive (attr := simp)] theorem noncommProd_insert_of_not_mem [DecidableEq α] (s : Finset α) (a : α) (f : α → β) (comm) (ha : a ∉ s) : noncommProd (insert a s) f comm = f a * noncommProd s f (comm.mono fun _ => mem_insert_of_mem) := by simp only [← cons_eq_insert _ _ ha, noncommProd_cons] #align finset.noncomm_prod_insert_of_not_mem Finset.noncommProd_insert_of_not_mem #align finset.noncomm_sum_insert_of_not_mem Finset.noncommSum_insert_of_not_mem @[to_additive] theorem noncommProd_insert_of_not_mem' [DecidableEq α] (s : Finset α) (a : α) (f : α → β) (comm) (ha : a ∉ s) : noncommProd (insert a s) f comm = noncommProd s f (comm.mono fun _ => mem_insert_of_mem) * f a := by simp only [← cons_eq_insert _ _ ha, noncommProd_cons'] #align finset.noncomm_prod_insert_of_not_mem' Finset.noncommProd_insert_of_not_mem' #align finset.noncomm_sum_insert_of_not_mem' Finset.noncommSum_insert_of_not_mem' @[to_additive (attr := simp)] theorem noncommProd_singleton (a : α) (f : α → β) : noncommProd ({a} : Finset α) f (by norm_cast exact Set.pairwise_singleton _ _) = f a := mul_one _ #align finset.noncomm_prod_singleton Finset.noncommProd_singleton #align finset.noncomm_sum_singleton Finset.noncommSum_singleton variable [FunLike F β γ] @[to_additive] theorem noncommProd_map [MonoidHomClass F β γ] (s : Finset α) (f : α → β) (comm) (g : F) : g (s.noncommProd f comm) = s.noncommProd (fun i => g (f i)) fun x hx y hy _ => (comm.of_refl hx hy).map g := by simp [noncommProd, Multiset.noncommProd_map] #align finset.noncomm_prod_map Finset.noncommProd_map #align finset.noncomm_sum_map Finset.noncommSum_map @[to_additive noncommSum_eq_card_nsmul] theorem noncommProd_eq_pow_card (s : Finset α) (f : α → β) (comm) (m : β) (h : ∀ x ∈ s, f x = m) : s.noncommProd f comm = m ^ s.card := by rw [noncommProd, Multiset.noncommProd_eq_pow_card _ _ m] · simp only [Finset.card_def, Multiset.card_map] · simpa using h #align finset.noncomm_prod_eq_pow_card Finset.noncommProd_eq_pow_card #align finset.noncomm_sum_eq_card_nsmul Finset.noncommSum_eq_card_nsmul @[to_additive] theorem noncommProd_commute (s : Finset α) (f : α → β) (comm) (y : β) (h : ∀ x ∈ s, Commute y (f x)) : Commute y (s.noncommProd f comm) := by apply Multiset.noncommProd_commute intro y rw [Multiset.mem_map] rintro ⟨x, ⟨hx, rfl⟩⟩ exact h x hx #align finset.noncomm_prod_commute Finset.noncommProd_commute #align finset.noncomm_sum_add_commute Finset.noncommSum_addCommute theorem mul_noncommProd_erase [DecidableEq α] (s : Finset α) {a : α} (h : a ∈ s) (f : α → β) (comm) (comm' := fun x hx y hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) : f a * (s.erase a).noncommProd f comm' = s.noncommProd f comm := by classical simpa only [← Multiset.map_erase_of_mem _ _ h] using Multiset.mul_noncommProd_erase (s.1.map f) (Multiset.mem_map_of_mem f h) _ theorem noncommProd_erase_mul [DecidableEq α] (s : Finset α) {a : α} (h : a ∈ s) (f : α → β) (comm) (comm' := fun x hx y hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) : (s.erase a).noncommProd f comm' * f a = s.noncommProd f comm := by classical simpa only [← Multiset.map_erase_of_mem _ _ h] using Multiset.noncommProd_erase_mul (s.1.map f) (Multiset.mem_map_of_mem f h) _ @[to_additive] theorem noncommProd_eq_prod {β : Type*} [CommMonoid β] (s : Finset α) (f : α → β) : (noncommProd s f fun _ _ _ _ _ => Commute.all _ _) = s.prod f := by induction' s using Finset.cons_induction_on with a s ha IH · simp · simp [ha, IH] #align finset.noncomm_prod_eq_prod Finset.noncommProd_eq_prod #align finset.noncomm_sum_eq_sum Finset.noncommSum_eq_sum /-- The non-commutative version of `Finset.prod_union` -/ @[to_additive "The non-commutative version of `Finset.sum_union`"] theorem noncommProd_union_of_disjoint [DecidableEq α] {s t : Finset α} (h : Disjoint s t) (f : α → β) (comm : { x | x ∈ s ∪ t }.Pairwise fun a b => Commute (f a) (f b)) : noncommProd (s ∪ t) f comm = noncommProd s f (comm.mono <| coe_subset.2 subset_union_left) * noncommProd t f (comm.mono <| coe_subset.2 subset_union_right) := by obtain ⟨sl, sl', rfl⟩ := exists_list_nodup_eq s obtain ⟨tl, tl', rfl⟩ := exists_list_nodup_eq t rw [List.disjoint_toFinset_iff_disjoint] at h calc noncommProd (List.toFinset sl ∪ List.toFinset tl) f comm = noncommProd ⟨↑(sl ++ tl), Multiset.coe_nodup.2 (sl'.append tl' h)⟩ f (by convert comm; simp [Set.ext_iff]) := noncommProd_congr (by ext; simp) (by simp) _ _ = noncommProd (List.toFinset sl) f (comm.mono <| coe_subset.2 subset_union_left) * noncommProd (List.toFinset tl) f (comm.mono <| coe_subset.2 subset_union_right) := by simp [noncommProd, List.dedup_eq_self.2 sl', List.dedup_eq_self.2 tl', h] #align finset.noncomm_prod_union_of_disjoint Finset.noncommProd_union_of_disjoint #align finset.noncomm_sum_union_of_disjoint Finset.noncommSum_union_of_disjoint @[to_additive] theorem noncommProd_mul_distrib_aux {s : Finset α} {f : α → β} {g : α → β} (comm_ff : (s : Set α).Pairwise fun x y => Commute (f x) (f y)) (comm_gg : (s : Set α).Pairwise fun x y => Commute (g x) (g y)) (comm_gf : (s : Set α).Pairwise fun x y => Commute (g x) (f y)) : (s : Set α).Pairwise fun x y => Commute ((f * g) x) ((f * g) y) := by intro x hx y hy h apply Commute.mul_left <;> apply Commute.mul_right · exact comm_ff.of_refl hx hy · exact (comm_gf hy hx h.symm).symm · exact comm_gf hx hy h · exact comm_gg.of_refl hx hy #align finset.noncomm_prod_mul_distrib_aux Finset.noncommProd_mul_distrib_aux #align finset.noncomm_sum_add_distrib_aux Finset.noncommSum_add_distrib_aux /-- The non-commutative version of `Finset.prod_mul_distrib` -/ @[to_additive "The non-commutative version of `Finset.sum_add_distrib`"] theorem noncommProd_mul_distrib {s : Finset α} (f : α → β) (g : α → β) (comm_ff comm_gg comm_gf) : noncommProd s (f * g) (noncommProd_mul_distrib_aux comm_ff comm_gg comm_gf) = noncommProd s f comm_ff * noncommProd s g comm_gg := by induction' s using Finset.cons_induction_on with x s hnmem ih · simp rw [Finset.noncommProd_cons, Finset.noncommProd_cons, Finset.noncommProd_cons, Pi.mul_apply, ih (comm_ff.mono fun _ => mem_cons_of_mem) (comm_gg.mono fun _ => mem_cons_of_mem) (comm_gf.mono fun _ => mem_cons_of_mem), (noncommProd_commute _ _ _ _ fun y hy => ?_).mul_mul_mul_comm] exact comm_gf (mem_cons_self x s) (mem_cons_of_mem hy) (ne_of_mem_of_not_mem hy hnmem).symm #align finset.noncomm_prod_mul_distrib Finset.noncommProd_mul_distrib #align finset.noncomm_sum_add_distrib Finset.noncommSum_add_distrib section FinitePi variable {M : ι → Type*} [∀ i, Monoid (M i)] @[to_additive]
Mathlib/Data/Finset/NoncommProd.lean
463
484
theorem noncommProd_mul_single [Fintype ι] [DecidableEq ι] (x : ∀ i, M i) : (univ.noncommProd (fun i => Pi.mulSingle i (x i)) fun i _ j _ _ => Pi.mulSingle_apply_commute x i j) = x := by
ext i apply (univ.noncommProd_map (fun i ↦ MonoidHom.mulSingle M i (x i)) ?a (Pi.evalMonoidHom M i)).trans case a => intro i _ j _ _ exact Pi.mulSingle_apply_commute x i j convert (noncommProd_congr (insert_erase (mem_univ i)).symm _ _).trans _ · intro j exact Pi.mulSingle j (x j) i · intro j _; dsimp · rw [noncommProd_insert_of_not_mem _ _ _ _ (not_mem_erase _ _), noncommProd_eq_pow_card (univ.erase i), one_pow, mul_one] · simp only [MonoidHom.mulSingle_apply, ne_eq, Pi.mulSingle_eq_same] · intro j hj simp? at hj says simp only [mem_erase, ne_eq, mem_univ, and_true] at hj simp only [MonoidHom.mulSingle_apply, Pi.mulSingle, Function.update, Eq.ndrec, Pi.one_apply, ne_eq, dite_eq_right_iff] intro h simp [*] at *
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.FiniteMeasure import Mathlib.MeasureTheory.Integral.Average #align_import measure_theory.measure.probability_measure from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Probability measures This file defines the type of probability measures on a given measurable space. When the underlying space has a topology and the measurable space structure (sigma algebra) is finer than the Borel sigma algebra, then the type of probability measures is equipped with the topology of convergence in distribution (weak convergence of measures). The topology of convergence in distribution is the coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued random variable `X`, the expected value of `X` depends continuously on the choice of probability measure. This is a special case of the topology of weak convergence of finite measures. ## Main definitions The main definitions are * the type `MeasureTheory.ProbabilityMeasure Ω` with the topology of convergence in distribution (a.k.a. convergence in law, weak convergence of measures); * `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`: Interpret a probability measure as a finite measure; * `MeasureTheory.FiniteMeasure.normalize`: Normalize a finite measure to a probability measure (returns junk for the zero measure). * `MeasureTheory.ProbabilityMeasure.map`: The push-forward `f* μ` of a probability measure `μ` on `Ω` along a measurable function `f : Ω → Ω'`. ## Main results * `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of probability measures is characterized by the convergence of expected values of all bounded continuous random variables. This shows that the chosen definition of topology coincides with the common textbook definition of convergence in distribution, i.e., weak convergence of measures. A similar characterization by the convergence of expected values (in the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative random variables is `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto`. * `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`: The convergence of finite measures to a nonzero limit is characterized by the convergence of the probability-normalized versions and of the total masses. * `MeasureTheory.ProbabilityMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the push-forward of probability measures `f* : ProbabilityMeasure Ω → ProbabilityMeasure Ω'` is continuous. * `MeasureTheory.ProbabilityMeasure.t2Space`: The topology of convergence in distribution is Hausdorff on Borel spaces where indicators of closed sets have continuous decreasing approximating sequences (in particular on any pseudo-metrizable spaces). TODO: * Probability measures form a convex space. ## Implementation notes The topology of convergence in distribution on `MeasureTheory.ProbabilityMeasure Ω` is inherited weak convergence of finite measures via the mapping `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. Like `MeasureTheory.FiniteMeasure Ω`, the implementation of `MeasureTheory.ProbabilityMeasure Ω` is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags convergence in distribution, convergence in law, weak convergence of measures, probability measure -/ noncomputable section open MeasureTheory open Set open Filter open BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section ProbabilityMeasure /-! ### Probability measures In this section we define the type of probability measures on a measurable space `Ω`, denoted by `MeasureTheory.ProbabilityMeasure Ω`. If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.ProbabilityMeasure Ω` is equipped with the topology of weak convergence of measures. Since every probability measure is a finite measure, this is implemented as the induced topology from the mapping `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/ /-- Probability measures are defined as the subtype of measures that have the property of being probability measures (i.e., their total mass is one). -/ def ProbabilityMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ := { μ : Measure Ω // IsProbabilityMeasure μ } #align measure_theory.probability_measure MeasureTheory.ProbabilityMeasure namespace ProbabilityMeasure variable {Ω : Type*} [MeasurableSpace Ω] instance [Inhabited Ω] : Inhabited (ProbabilityMeasure Ω) := ⟨⟨Measure.dirac default, Measure.dirac.isProbabilityMeasure⟩⟩ -- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`), we need a new function for the -- coercion instead of relying on `Subtype.val`. /-- Coercion from `MeasureTheory.ProbabilityMeasure Ω` to `MeasureTheory.Measure Ω`. -/ @[coe] def toMeasure : ProbabilityMeasure Ω → Measure Ω := Subtype.val /-- A probability measure can be interpreted as a measure. -/ instance : Coe (ProbabilityMeasure Ω) (MeasureTheory.Measure Ω) where coe := toMeasure instance (μ : ProbabilityMeasure Ω) : IsProbabilityMeasure (μ : Measure Ω) := μ.prop @[simp, norm_cast] lemma coe_mk (μ : Measure Ω) (hμ) : toMeasure ⟨μ, hμ⟩ = μ := rfl @[simp] theorem val_eq_to_measure (ν : ProbabilityMeasure Ω) : ν.val = (ν : Measure Ω) := rfl #align measure_theory.probability_measure.val_eq_to_measure MeasureTheory.ProbabilityMeasure.val_eq_to_measure theorem toMeasure_injective : Function.Injective ((↑) : ProbabilityMeasure Ω → Measure Ω) := Subtype.coe_injective #align measure_theory.probability_measure.coe_injective MeasureTheory.ProbabilityMeasure.toMeasure_injective instance instFunLike : FunLike (ProbabilityMeasure Ω) (Set Ω) ℝ≥0 where coe μ s := ((μ : Measure Ω) s).toNNReal coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s lemma coeFn_def (μ : ProbabilityMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl #align measure_theory.probability_measure.coe_fn_eq_to_nnreal_coe_fn_to_measure MeasureTheory.ProbabilityMeasure.coeFn_def lemma coeFn_mk (μ : Measure Ω) (hμ) : DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl @[simp, norm_cast] lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) : DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl @[simp, norm_cast] theorem coeFn_univ (ν : ProbabilityMeasure Ω) : ν univ = 1 := congr_arg ENNReal.toNNReal ν.prop.measure_univ #align measure_theory.probability_measure.coe_fn_univ MeasureTheory.ProbabilityMeasure.coeFn_univ theorem coeFn_univ_ne_zero (ν : ProbabilityMeasure Ω) : ν univ ≠ 0 := by simp only [coeFn_univ, Ne, one_ne_zero, not_false_iff] #align measure_theory.probability_measure.coe_fn_univ_ne_zero MeasureTheory.ProbabilityMeasure.coeFn_univ_ne_zero /-- A probability measure can be interpreted as a finite measure. -/ def toFiniteMeasure (μ : ProbabilityMeasure Ω) : FiniteMeasure Ω := ⟨μ, inferInstance⟩ #align measure_theory.probability_measure.to_finite_measure MeasureTheory.ProbabilityMeasure.toFiniteMeasure @[simp] lemma coeFn_toFiniteMeasure (μ : ProbabilityMeasure Ω) : ⇑μ.toFiniteMeasure = μ := rfl lemma toFiniteMeasure_apply (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ.toFiniteMeasure s = μ s := rfl @[simp] theorem toMeasure_comp_toFiniteMeasure_eq_toMeasure (ν : ProbabilityMeasure Ω) : (ν.toFiniteMeasure : Measure Ω) = (ν : Measure Ω) := rfl #align measure_theory.probability_measure.coe_comp_to_finite_measure_eq_coe MeasureTheory.ProbabilityMeasure.toMeasure_comp_toFiniteMeasure_eq_toMeasure @[simp] theorem coeFn_comp_toFiniteMeasure_eq_coeFn (ν : ProbabilityMeasure Ω) : (ν.toFiniteMeasure : Set Ω → ℝ≥0) = (ν : Set Ω → ℝ≥0) := rfl #align measure_theory.probability_measure.coe_fn_comp_to_finite_measure_eq_coe_fn MeasureTheory.ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn @[simp] theorem toFiniteMeasure_apply_eq_apply (ν : ProbabilityMeasure Ω) (s : Set Ω) : ν.toFiniteMeasure s = ν s := rfl @[simp] theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : ProbabilityMeasure Ω) (s : Set Ω) : (ν s : ℝ≥0∞) = (ν : Measure Ω) s := by rw [← coeFn_comp_toFiniteMeasure_eq_coeFn, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure, toMeasure_comp_toFiniteMeasure_eq_toMeasure] #align measure_theory.probability_measure.ennreal_coe_fn_eq_coe_fn_to_measure MeasureTheory.ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure theorem apply_mono (μ : ProbabilityMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by rw [← coeFn_comp_toFiniteMeasure_eq_coeFn] exact MeasureTheory.FiniteMeasure.apply_mono _ h #align measure_theory.probability_measure.apply_mono MeasureTheory.ProbabilityMeasure.apply_mono @[simp] theorem apply_le_one (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ s ≤ 1 := by simpa using apply_mono μ (subset_univ s) theorem nonempty (μ : ProbabilityMeasure Ω) : Nonempty Ω := by by_contra maybe_empty have zero : (μ : Measure Ω) univ = 0 := by rw [univ_eq_empty_iff.mpr (not_nonempty_iff.mp maybe_empty), measure_empty] rw [measure_univ] at zero exact zero_ne_one zero.symm #align measure_theory.probability_measure.nonempty_of_probability_measure MeasureTheory.ProbabilityMeasure.nonempty @[ext] theorem eq_of_forall_toMeasure_apply_eq (μ ν : ProbabilityMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by apply toMeasure_injective ext1 s s_mble exact h s s_mble #align measure_theory.probability_measure.eq_of_forall_measure_apply_eq MeasureTheory.ProbabilityMeasure.eq_of_forall_toMeasure_apply_eq theorem eq_of_forall_apply_eq (μ ν : ProbabilityMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by ext1 s s_mble simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble) #align measure_theory.probability_measure.eq_of_forall_apply_eq MeasureTheory.ProbabilityMeasure.eq_of_forall_apply_eq @[simp] theorem mass_toFiniteMeasure (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.mass = 1 := μ.coeFn_univ #align measure_theory.probability_measure.mass_to_finite_measure MeasureTheory.ProbabilityMeasure.mass_toFiniteMeasure theorem toFiniteMeasure_nonzero (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure ≠ 0 := by rw [← FiniteMeasure.mass_nonzero_iff, μ.mass_toFiniteMeasure] exact one_ne_zero #align measure_theory.probability_measure.to_finite_measure_nonzero MeasureTheory.ProbabilityMeasure.toFiniteMeasure_nonzero section convergence_in_distribution variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] theorem testAgainstNN_lipschitz (μ : ProbabilityMeasure Ω) : LipschitzWith 1 fun f : Ω →ᵇ ℝ≥0 => μ.toFiniteMeasure.testAgainstNN f := μ.mass_toFiniteMeasure ▸ μ.toFiniteMeasure.testAgainstNN_lipschitz #align measure_theory.probability_measure.test_against_nn_lipschitz MeasureTheory.ProbabilityMeasure.testAgainstNN_lipschitz /-- The topology of weak convergence on `MeasureTheory.ProbabilityMeasure Ω`. This is inherited (induced) from the topology of weak convergence of finite measures via the inclusion `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/ instance : TopologicalSpace (ProbabilityMeasure Ω) := TopologicalSpace.induced toFiniteMeasure inferInstance theorem toFiniteMeasure_continuous : Continuous (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) := continuous_induced_dom #align measure_theory.probability_measure.to_finite_measure_continuous MeasureTheory.ProbabilityMeasure.toFiniteMeasure_continuous /-- Probability measures yield elements of the `WeakDual` of bounded continuous nonnegative functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/ def toWeakDualBCNN : ProbabilityMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) := FiniteMeasure.toWeakDualBCNN ∘ toFiniteMeasure #align measure_theory.probability_measure.to_weak_dual_bcnn MeasureTheory.ProbabilityMeasure.toWeakDualBCNN @[simp] theorem coe_toWeakDualBCNN (μ : ProbabilityMeasure Ω) : ⇑μ.toWeakDualBCNN = μ.toFiniteMeasure.testAgainstNN := rfl #align measure_theory.probability_measure.coe_to_weak_dual_bcnn MeasureTheory.ProbabilityMeasure.coe_toWeakDualBCNN @[simp] theorem toWeakDualBCNN_apply (μ : ProbabilityMeasure Ω) (f : Ω →ᵇ ℝ≥0) : μ.toWeakDualBCNN f = (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal := rfl #align measure_theory.probability_measure.to_weak_dual_bcnn_apply MeasureTheory.ProbabilityMeasure.toWeakDualBCNN_apply theorem toWeakDualBCNN_continuous : Continuous fun μ : ProbabilityMeasure Ω => μ.toWeakDualBCNN := FiniteMeasure.toWeakDualBCNN_continuous.comp toFiniteMeasure_continuous #align measure_theory.probability_measure.to_weak_dual_bcnn_continuous MeasureTheory.ProbabilityMeasure.toWeakDualBCNN_continuous /- Integration of (nonnegative bounded continuous) test functions against Borel probability measures depends continuously on the measure. -/ theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) : Continuous fun μ : ProbabilityMeasure Ω => μ.toFiniteMeasure.testAgainstNN f := (FiniteMeasure.continuous_testAgainstNN_eval f).comp toFiniteMeasure_continuous #align measure_theory.probability_measure.continuous_test_against_nn_eval MeasureTheory.ProbabilityMeasure.continuous_testAgainstNN_eval -- The canonical mapping from probability measures to finite measures is an embedding. theorem toFiniteMeasure_embedding (Ω : Type*) [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] : Embedding (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) := { induced := rfl inj := fun _μ _ν h => Subtype.eq <| congr_arg FiniteMeasure.toMeasure h } #align measure_theory.probability_measure.to_finite_measure_embedding MeasureTheory.ProbabilityMeasure.toFiniteMeasure_embedding theorem tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds {δ : Type*} (F : Filter δ) {μs : δ → ProbabilityMeasure Ω} {μ₀ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ₀) ↔ Tendsto (toFiniteMeasure ∘ μs) F (𝓝 μ₀.toFiniteMeasure) := Embedding.tendsto_nhds_iff (toFiniteMeasure_embedding Ω) #align measure_theory.probability_measure.tendsto_nhds_iff_to_finite_measures_tendsto_nhds MeasureTheory.ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds /-- A characterization of weak convergence of probability measures by the condition that the integrals of every continuous bounded nonnegative function converge to the integral of the function against the limit measure. -/ theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => ∫⁻ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := by rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] exact FiniteMeasure.tendsto_iff_forall_lintegral_tendsto #align measure_theory.probability_measure.tendsto_iff_forall_lintegral_tendsto MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto /-- The characterization of weak convergence of probability measures by the usual (defining) condition that the integrals of every continuous bounded function converge to the integral of the function against the limit measure. -/ theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ, Tendsto (fun i => ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] rw [FiniteMeasure.tendsto_iff_forall_integral_tendsto] rfl #align measure_theory.probability_measure.tendsto_iff_forall_integral_tendsto MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto end convergence_in_distribution -- section section Hausdorff variable [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [BorelSpace Ω] variable (Ω) /-- On topological spaces where indicators of closed sets have decreasing approximating sequences of continuous functions (`HasOuterApproxClosed`), the topology of convergence in distribution of Borel probability measures is Hausdorff (`T2Space`). -/ instance t2Space : T2Space (ProbabilityMeasure Ω) := Embedding.t2Space (toFiniteMeasure_embedding Ω) end Hausdorff -- section end ProbabilityMeasure -- namespace end ProbabilityMeasure -- section section NormalizeFiniteMeasure /-! ### Normalization of finite measures to probability measures This section is about normalizing finite measures to probability measures. The weak convergence of finite measures to nonzero limit measures is characterized by the convergence of the total mass and the convergence of the normalized probability measures. -/ namespace FiniteMeasure variable {Ω : Type*} [Nonempty Ω] {m0 : MeasurableSpace Ω} (μ : FiniteMeasure Ω) /-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the total mass. -/ def normalize : ProbabilityMeasure Ω := if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩ else { val := ↑(μ.mass⁻¹ • μ) property := by refine ⟨?_⟩ -- Porting note: paying the price that this isn't `simp` lemma now. rw [FiniteMeasure.toMeasure_smul] simp only [Measure.coe_smul, Pi.smul_apply, Measure.nnreal_smul_coe_apply, ne_eq, mass_zero_iff, ENNReal.coe_inv zero, ennreal_mass] rw [← Ne, ← ENNReal.coe_ne_zero, ennreal_mass] at zero exact ENNReal.inv_mul_cancel zero μ.prop.measure_univ_lt_top.ne } #align measure_theory.finite_measure.normalize MeasureTheory.FiniteMeasure.normalize @[simp] theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by obtain rfl | h := eq_or_ne μ 0 · simp have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff] simp only [normalize, dif_neg mass_nonzero] simp [ProbabilityMeasure.coe_mk, toMeasure_smul, mul_inv_cancel_left₀ mass_nonzero, coeFn_def] #align measure_theory.finite_measure.self_eq_mass_mul_normalize MeasureTheory.FiniteMeasure.self_eq_mass_mul_normalize theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by apply eq_of_forall_apply_eq intro s _s_mble rw [μ.self_eq_mass_mul_normalize s, smul_apply, smul_eq_mul, ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn] #align measure_theory.finite_measure.self_eq_mass_smul_normalize MeasureTheory.FiniteMeasure.self_eq_mass_smul_normalize theorem normalize_eq_of_nonzero (nonzero : μ ≠ 0) (s : Set Ω) : μ.normalize s = μ.mass⁻¹ * μ s := by simp only [μ.self_eq_mass_mul_normalize, μ.mass_nonzero_iff.mpr nonzero, inv_mul_cancel_left₀, Ne, not_false_iff] #align measure_theory.finite_measure.normalize_eq_of_nonzero MeasureTheory.FiniteMeasure.normalize_eq_of_nonzero theorem normalize_eq_inv_mass_smul_of_nonzero (nonzero : μ ≠ 0) : μ.normalize.toFiniteMeasure = μ.mass⁻¹ • μ := by nth_rw 3 [μ.self_eq_mass_smul_normalize] rw [← smul_assoc] simp only [μ.mass_nonzero_iff.mpr nonzero, Algebra.id.smul_eq_mul, inv_mul_cancel, Ne, not_false_iff, one_smul] #align measure_theory.finite_measure.normalize_eq_inv_mass_smul_of_nonzero MeasureTheory.FiniteMeasure.normalize_eq_inv_mass_smul_of_nonzero theorem toMeasure_normalize_eq_of_nonzero (nonzero : μ ≠ 0) : (μ.normalize : Measure Ω) = μ.mass⁻¹ • μ := by ext1 s _s_mble rw [← μ.normalize.ennreal_coeFn_eq_coeFn_toMeasure s, μ.normalize_eq_of_nonzero nonzero s, ENNReal.coe_mul, ennreal_coeFn_eq_coeFn_toMeasure] exact Measure.coe_nnreal_smul_apply _ _ _ #align measure_theory.finite_measure.coe_normalize_eq_of_nonzero MeasureTheory.FiniteMeasure.toMeasure_normalize_eq_of_nonzero @[simp] theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω} (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by apply ProbabilityMeasure.eq_of_forall_apply_eq intro s _s_mble rw [μ.toFiniteMeasure.normalize_eq_of_nonzero μ.toFiniteMeasure_nonzero s] simp only [ProbabilityMeasure.mass_toFiniteMeasure, inv_one, one_mul, μ.coeFn_toFiniteMeasure] #align probability_measure.to_finite_measure_normalize_eq_self ProbabilityMeasure.toFiniteMeasure_normalize_eq_self /-- Averaging with respect to a finite measure is the same as integrating against `MeasureTheory.FiniteMeasure.normalize`. -/
Mathlib/MeasureTheory/Measure/ProbabilityMeasure.lean
427
432
theorem average_eq_integral_normalize {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (nonzero : μ ≠ 0) (f : Ω → E) : average (μ : Measure Ω) f = ∫ ω, f ω ∂(μ.normalize : Measure Ω) := by
rw [μ.toMeasure_normalize_eq_of_nonzero nonzero, average] congr simp [ENNReal.coe_inv (μ.mass_nonzero_iff.mpr nonzero), ennreal_mass]
/- 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. -/ 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' #align normalized_factors_equiv_of_quot_equiv_multiplicity_eq_multiplicity normalizedFactorsEquivOfQuotEquiv_multiplicity_eq_multiplicity end section ChineseRemainder open Ideal UniqueFactorizationMonoid variable {R} theorem Ring.DimensionLeOne.prime_le_prime_iff_eq [Ring.DimensionLEOne R] {P Q : Ideal R} [hP : P.IsPrime] [hQ : Q.IsPrime] (hP0 : P ≠ ⊥) : P ≤ Q ↔ P = Q := ⟨(hP.isMaximal hP0).eq_of_le hQ.ne_top, Eq.le⟩ #align ring.dimension_le_one.prime_le_prime_iff_eq Ring.DimensionLeOne.prime_le_prime_iff_eq theorem Ideal.coprime_of_no_prime_ge {I J : Ideal R} (h : ∀ P, I ≤ P → J ≤ P → ¬IsPrime P) : IsCoprime I J := by rw [isCoprime_iff_sup_eq] by_contra hIJ obtain ⟨P, hP, hIJ⟩ := Ideal.exists_le_maximal _ hIJ exact h P (le_trans le_sup_left hIJ) (le_trans le_sup_right hIJ) hP.isPrime #align ideal.coprime_of_no_prime_ge Ideal.coprime_of_no_prime_ge section DedekindDomain variable [IsDedekindDomain R] theorem Ideal.IsPrime.mul_mem_pow (I : Ideal R) [hI : I.IsPrime] {a b : R} {n : ℕ} (h : a * b ∈ I ^ n) : a ∈ I ∨ b ∈ I ^ n := by cases n; · simp by_cases hI0 : I = ⊥; · simpa [pow_succ, hI0] using h simp only [← Submodule.span_singleton_le_iff_mem, Ideal.submodule_span_eq, ← Ideal.dvd_iff_le, ← Ideal.span_singleton_mul_span_singleton] at h ⊢ by_cases ha : I ∣ span {a} · exact Or.inl ha rw [mul_comm] at h exact Or.inr (Prime.pow_dvd_of_dvd_mul_right ((Ideal.prime_iff_isPrime hI0).mpr hI) _ ha h) #align ideal.is_prime.mul_mem_pow Ideal.IsPrime.mul_mem_pow theorem Ideal.IsPrime.mem_pow_mul (I : Ideal R) [hI : I.IsPrime] {a b : R} {n : ℕ} (h : a * b ∈ I ^ n) : a ∈ I ^ n ∨ b ∈ I := by rw [mul_comm] at h rw [or_comm] exact Ideal.IsPrime.mul_mem_pow _ h section theorem Ideal.count_normalizedFactors_eq {p x : Ideal R} [hp : p.IsPrime] {n : ℕ} (hle : x ≤ p ^ n) [DecidableEq (Ideal R)] (hlt : ¬x ≤ p ^ (n + 1)) : (normalizedFactors x).count p = n := count_normalizedFactors_eq' ((Ideal.isPrime_iff_bot_or_prime.mp hp).imp_right Prime.irreducible) (normalize_eq _) (Ideal.dvd_iff_le.mpr hle) (mt Ideal.le_of_dvd hlt) #align ideal.count_normalized_factors_eq Ideal.count_normalizedFactors_eq end theorem Ideal.le_mul_of_no_prime_factors {I J K : Ideal R} (coprime : ∀ P, J ≤ P → K ≤ P → ¬IsPrime P) (hJ : I ≤ J) (hK : I ≤ K) : I ≤ J * K := by simp only [← Ideal.dvd_iff_le] at coprime hJ hK ⊢ by_cases hJ0 : J = 0 · simpa only [hJ0, zero_mul] using hJ obtain ⟨I', rfl⟩ := hK rw [mul_comm] refine mul_dvd_mul_left K (UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors (b := K) hJ0 ?_ hJ) exact fun hPJ hPK => mt Ideal.isPrime_of_prime (coprime _ hPJ hPK) #align ideal.le_mul_of_no_prime_factors Ideal.le_mul_of_no_prime_factors theorem Ideal.le_of_pow_le_prime {I P : Ideal R} [hP : P.IsPrime] {n : ℕ} (h : I ^ n ≤ P) : I ≤ P := by by_cases hP0 : P = ⊥ · simp only [hP0, le_bot_iff] at h ⊢ exact pow_eq_zero h rw [← Ideal.dvd_iff_le] at h ⊢ exact ((Ideal.prime_iff_isPrime hP0).mpr hP).dvd_of_dvd_pow h #align ideal.le_of_pow_le_prime Ideal.le_of_pow_le_prime theorem Ideal.pow_le_prime_iff {I P : Ideal R} [_hP : P.IsPrime] {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ P ↔ I ≤ P := ⟨Ideal.le_of_pow_le_prime, fun h => _root_.trans (Ideal.pow_le_self hn) h⟩ #align ideal.pow_le_prime_iff Ideal.pow_le_prime_iff theorem Ideal.prod_le_prime {ι : Type*} {s : Finset ι} {f : ι → Ideal R} {P : Ideal R} [hP : P.IsPrime] : ∏ i ∈ s, f i ≤ P ↔ ∃ i ∈ s, f i ≤ P := by by_cases hP0 : P = ⊥ · simp only [hP0, le_bot_iff] rw [← Ideal.zero_eq_bot, Finset.prod_eq_zero_iff] simp only [← Ideal.dvd_iff_le] exact ((Ideal.prime_iff_isPrime hP0).mpr hP).dvd_finset_prod_iff _ #align ideal.prod_le_prime Ideal.prod_le_prime /-- The intersection of distinct prime powers in a Dedekind domain is the product of these prime powers. -/ theorem IsDedekindDomain.inf_prime_pow_eq_prod {ι : Type*} (s : Finset ι) (f : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (f i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → f i ≠ f j) : (s.inf fun i => f i ^ e i) = ∏ i ∈ s, f i ^ e i := by letI := Classical.decEq ι revert prime coprime refine s.induction ?_ ?_ · simp intro a s ha ih prime coprime specialize ih (fun i hi => prime i (Finset.mem_insert_of_mem hi)) fun i hi j hj => coprime i (Finset.mem_insert_of_mem hi) j (Finset.mem_insert_of_mem hj) rw [Finset.inf_insert, Finset.prod_insert ha, ih] refine le_antisymm (Ideal.le_mul_of_no_prime_factors ?_ inf_le_left inf_le_right) Ideal.mul_le_inf intro P hPa hPs hPp obtain ⟨b, hb, hPb⟩ := Ideal.prod_le_prime.mp hPs haveI := Ideal.isPrime_of_prime (prime a (Finset.mem_insert_self a s)) haveI := Ideal.isPrime_of_prime (prime b (Finset.mem_insert_of_mem hb)) refine coprime a (Finset.mem_insert_self a s) b (Finset.mem_insert_of_mem hb) ?_ ?_ · exact (ne_of_mem_of_not_mem hb ha).symm · refine ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPa)).trans ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPb)).symm · exact (prime a (Finset.mem_insert_self a s)).ne_zero · exact (prime b (Finset.mem_insert_of_mem hb)).ne_zero #align is_dedekind_domain.inf_prime_pow_eq_prod IsDedekindDomain.inf_prime_pow_eq_prod /-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as `∏ i, P i ^ e i`, then `R ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`. -/ noncomputable def IsDedekindDomain.quotientEquivPiOfProdEq {ι : Type*} [Fintype ι] (I : Ideal R) (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i, Prime (P i)) (coprime : Pairwise fun i j => P i ≠ P j) (prod_eq : ∏ i, P i ^ e i = I) : R ⧸ I ≃+* ∀ i, R ⧸ P i ^ e i := (Ideal.quotEquivOfEq (by simp only [← prod_eq, Finset.inf_eq_iInf, Finset.mem_univ, ciInf_pos, ← IsDedekindDomain.inf_prime_pow_eq_prod _ _ _ (fun i _ => prime i) (coprime.set_pairwise _)])).trans <| Ideal.quotientInfRingEquivPiQuotient _ fun i j hij => Ideal.coprime_of_no_prime_ge (by intro P hPi hPj hPp haveI := Ideal.isPrime_of_prime (prime i) haveI := Ideal.isPrime_of_prime (prime j) refine coprime hij ?_ refine ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPi)).trans ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (Ideal.le_of_pow_le_prime hPj)).symm · exact (prime i).ne_zero · exact (prime j).ne_zero) #align is_dedekind_domain.quotient_equiv_pi_of_prod_eq IsDedekindDomain.quotientEquivPiOfProdEq open scoped Classical /-- **Chinese remainder theorem** for a Dedekind domain: `R ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`, where `P i` ranges over the prime factors of `I` and `e i` over the multiplicities. -/ noncomputable def IsDedekindDomain.quotientEquivPiFactors {I : Ideal R} (hI : I ≠ ⊥) : R ⧸ I ≃+* ∀ P : (factors I).toFinset, R ⧸ (P : Ideal R) ^ (Multiset.count ↑P (factors I)) := IsDedekindDomain.quotientEquivPiOfProdEq _ _ _ (fun P : (factors I).toFinset => prime_of_factor _ (Multiset.mem_toFinset.mp P.prop)) (fun i j hij => Subtype.coe_injective.ne hij) (calc (∏ P : (factors I).toFinset, (P : Ideal R) ^ (factors I).count (P : Ideal R)) = ∏ P ∈ (factors I).toFinset, P ^ (factors I).count P := (factors I).toFinset.prod_coe_sort fun P => P ^ (factors I).count P _ = ((factors I).map fun P => P).prod := (Finset.prod_multiset_map_count (factors I) id).symm _ = (factors I).prod := by rw [Multiset.map_id'] _ = I := (@associated_iff_eq (Ideal R) _ Ideal.uniqueUnits _ _).mp (factors_prod hI) ) #align is_dedekind_domain.quotient_equiv_pi_factors IsDedekindDomain.quotientEquivPiFactors @[simp] theorem IsDedekindDomain.quotientEquivPiFactors_mk {I : Ideal R} (hI : I ≠ ⊥) (x : R) : IsDedekindDomain.quotientEquivPiFactors hI (Ideal.Quotient.mk I x) = fun _P => Ideal.Quotient.mk _ x := rfl #align is_dedekind_domain.quotient_equiv_pi_factors_mk IsDedekindDomain.quotientEquivPiFactors_mk /-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as `∏ i ∈ s, P i ^ e i`, then `R ⧸ I` factors as `Π (i : s), R ⧸ (P i ^ e i)`. This is a version of `IsDedekindDomain.quotientEquivPiOfProdEq` where we restrict the product to a finite subset `s` of a potentially infinite indexing type `ι`. -/ noncomputable def IsDedekindDomain.quotientEquivPiOfFinsetProdEq {ι : Type*} {s : Finset ι} (I : Ideal R) (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (prod_eq : ∏ i ∈ s, P i ^ e i = I) : R ⧸ I ≃+* ∀ i : s, R ⧸ P i ^ e i := IsDedekindDomain.quotientEquivPiOfProdEq I (fun i : s => P i) (fun i : s => e i) (fun i => prime i i.2) (fun i j h => coprime i i.2 j j.2 (Subtype.coe_injective.ne h)) (_root_.trans (Finset.prod_coe_sort s fun i => P i ^ e i) prod_eq) #align is_dedekind_domain.quotient_equiv_pi_of_finset_prod_eq IsDedekindDomain.quotientEquivPiOfFinsetProdEq /-- Corollary of the Chinese remainder theorem: given elements `x i : R / P i ^ e i`, we can choose a representative `y : R` such that `y ≡ x i (mod P i ^ e i)`. -/ theorem IsDedekindDomain.exists_representative_mod_finset {ι : Type*} {s : Finset ι} (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (x : ∀ i : s, R ⧸ P i ^ e i) : ∃ y, ∀ (i) (hi : i ∈ s), Ideal.Quotient.mk (P i ^ e i) y = x ⟨i, hi⟩ := by let f := IsDedekindDomain.quotientEquivPiOfFinsetProdEq _ P e prime coprime rfl obtain ⟨y, rfl⟩ := f.surjective x obtain ⟨z, rfl⟩ := Ideal.Quotient.mk_surjective y exact ⟨z, fun i _hi => rfl⟩ #align is_dedekind_domain.exists_representative_mod_finset IsDedekindDomain.exists_representative_mod_finset /-- Corollary of the Chinese remainder theorem: given elements `x i : R`, we can choose a representative `y : R` such that `y - x i ∈ P i ^ e i`. -/ theorem IsDedekindDomain.exists_forall_sub_mem_ideal {ι : Type*} {s : Finset ι} (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i)) (coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (x : s → R) : ∃ y, ∀ (i) (hi : i ∈ s), y - x ⟨i, hi⟩ ∈ P i ^ e i := by obtain ⟨y, hy⟩ := IsDedekindDomain.exists_representative_mod_finset P e prime coprime fun i => Ideal.Quotient.mk _ (x i) exact ⟨y, fun i hi => Ideal.Quotient.eq.mp (hy i hi)⟩ #align is_dedekind_domain.exists_forall_sub_mem_ideal IsDedekindDomain.exists_forall_sub_mem_ideal end DedekindDomain end ChineseRemainder section PID open multiplicity UniqueFactorizationMonoid Ideal variable {R} variable [IsDomain R] [IsPrincipalIdealRing R] theorem span_singleton_dvd_span_singleton_iff_dvd {a b : R} : Ideal.span {a} ∣ Ideal.span ({b} : Set R) ↔ a ∣ b := ⟨fun h => mem_span_singleton.mp (dvd_iff_le.mp h (mem_span_singleton.mpr (dvd_refl b))), fun h => dvd_iff_le.mpr fun _d hd => mem_span_singleton.mpr (dvd_trans h (mem_span_singleton.mp hd))⟩ #align span_singleton_dvd_span_singleton_iff_dvd span_singleton_dvd_span_singleton_iff_dvd @[simp] theorem Ideal.squarefree_span_singleton {a : R} : Squarefree (span {a}) ↔ Squarefree a := by refine ⟨fun h x hx ↦ ?_, fun h I hI ↦ ?_⟩ · rw [← span_singleton_dvd_span_singleton_iff_dvd, ← span_singleton_mul_span_singleton] at hx simpa using h _ hx · rw [← span_singleton_generator I, span_singleton_mul_span_singleton, span_singleton_dvd_span_singleton_iff_dvd] at hI exact isUnit_iff.mpr <| eq_top_of_isUnit_mem _ (Submodule.IsPrincipal.generator_mem I) (h _ hI) theorem singleton_span_mem_normalizedFactors_of_mem_normalizedFactors [NormalizationMonoid R] {a b : R} (ha : a ∈ normalizedFactors b) : Ideal.span ({a} : Set R) ∈ normalizedFactors (Ideal.span ({b} : Set R)) := by by_cases hb : b = 0 · rw [Ideal.span_singleton_eq_bot.mpr hb, bot_eq_zero, normalizedFactors_zero] rw [hb, normalizedFactors_zero] at ha exact absurd ha (Multiset.not_mem_zero a) · suffices Prime (Ideal.span ({a} : Set R)) by obtain ⟨c, hc, hc'⟩ := exists_mem_normalizedFactors_of_dvd ?_ this.irreducible (dvd_iff_le.mpr (span_singleton_le_span_singleton.mpr (dvd_of_mem_normalizedFactors ha))) rwa [associated_iff_eq.mp hc'] · by_contra h exact hb (span_singleton_eq_bot.mp h) rw [prime_iff_isPrime] · exact (span_singleton_prime (prime_of_normalized_factor a ha).ne_zero).mpr (prime_of_normalized_factor a ha) · by_contra h exact (prime_of_normalized_factor a ha).ne_zero (span_singleton_eq_bot.mp h) #align singleton_span_mem_normalized_factors_of_mem_normalized_factors singleton_span_mem_normalizedFactors_of_mem_normalizedFactors theorem multiplicity_eq_multiplicity_span [DecidableRel ((· ∣ ·) : R → R → Prop)] [DecidableRel ((· ∣ ·) : Ideal R → Ideal R → Prop)] {a b : R} : multiplicity (Ideal.span {a}) (Ideal.span ({b} : Set R)) = multiplicity a b := by by_cases h : Finite a b · rw [← PartENat.natCast_get (finite_iff_dom.mp h)] refine (multiplicity.unique (show Ideal.span {a} ^ (multiplicity a b).get h ∣ Ideal.span {b} from ?_) ?_).symm <;> rw [Ideal.span_singleton_pow, span_singleton_dvd_span_singleton_iff_dvd] · exact pow_multiplicity_dvd h · exact multiplicity.is_greatest ((PartENat.lt_coe_iff _ _).mpr (Exists.intro (finite_iff_dom.mp h) (Nat.lt_succ_self _))) · suffices ¬Finite (Ideal.span ({a} : Set R)) (Ideal.span ({b} : Set R)) by rw [finite_iff_dom, PartENat.not_dom_iff_eq_top] at h this rw [h, this] exact not_finite_iff_forall.mpr fun n => by rw [Ideal.span_singleton_pow, span_singleton_dvd_span_singleton_iff_dvd] exact not_finite_iff_forall.mp h n #align multiplicity_eq_multiplicity_span multiplicity_eq_multiplicity_span variable [DecidableEq R] [DecidableEq (Ideal R)] [NormalizationMonoid R] /-- The bijection between the (normalized) prime factors of `r` and the (normalized) prime factors of `span {r}` -/ -- @[simps] -- Porting note: simpNF complains about the lemmas generated by simps noncomputable def normalizedFactorsEquivSpanNormalizedFactors {r : R} (hr : r ≠ 0) : { d : R | d ∈ normalizedFactors r } ≃ { I : Ideal R | I ∈ normalizedFactors (Ideal.span ({r} : Set R)) } := by refine Equiv.ofBijective ?_ ?_ · exact fun d => ⟨Ideal.span {↑d}, singleton_span_mem_normalizedFactors_of_mem_normalizedFactors d.prop⟩ · refine ⟨?_, ?_⟩ · rintro ⟨a, ha⟩ ⟨b, hb⟩ h rw [Subtype.mk_eq_mk, Ideal.span_singleton_eq_span_singleton, Subtype.coe_mk, Subtype.coe_mk] at h exact Subtype.mk_eq_mk.mpr (mem_normalizedFactors_eq_of_associated ha hb h) · rintro ⟨i, hi⟩ have : i.IsPrime := isPrime_of_prime (prime_of_normalized_factor i hi) have := exists_mem_normalizedFactors_of_dvd hr (Submodule.IsPrincipal.prime_generator_of_isPrime i (prime_of_normalized_factor i hi).ne_zero).irreducible ?_ · obtain ⟨a, ha, ha'⟩ := this use ⟨a, ha⟩ simp only [Subtype.coe_mk, Subtype.mk_eq_mk, ← span_singleton_eq_span_singleton.mpr ha', Ideal.span_singleton_generator] · exact (Submodule.IsPrincipal.mem_iff_generator_dvd i).mp ((show Ideal.span {r} ≤ i from dvd_iff_le.mp (dvd_of_mem_normalizedFactors hi)) (mem_span_singleton.mpr (dvd_refl r))) #align normalized_factors_equiv_span_normalized_factors normalizedFactorsEquivSpanNormalizedFactors variable [DecidableRel ((· ∣ ·) : R → R → Prop)] [DecidableRel ((· ∣ ·) : Ideal R → Ideal R → Prop)] /-- The bijection `normalizedFactorsEquivSpanNormalizedFactors` between the set of prime factors of `r` and the set of prime factors of the ideal `⟨r⟩` preserves multiplicities. See `count_normalizedFactorsSpan_eq_count` for the version stated in terms of multisets `count`.-/ theorem multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity {r d : R} (hr : r ≠ 0) (hd : d ∈ normalizedFactors r) : multiplicity d r = multiplicity (normalizedFactorsEquivSpanNormalizedFactors hr ⟨d, hd⟩ : Ideal R) (Ideal.span {r}) := by simp only [normalizedFactorsEquivSpanNormalizedFactors, multiplicity_eq_multiplicity_span, Subtype.coe_mk, Equiv.ofBijective_apply] #align multiplicity_normalized_factors_equiv_span_normalized_factors_eq_multiplicity multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity /-- The bijection `normalized_factors_equiv_span_normalized_factors.symm` between the set of prime factors of the ideal `⟨r⟩` and the set of prime factors of `r` preserves multiplicities. -/ theorem multiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_multiplicity {r : R} (hr : r ≠ 0) (I : { I : Ideal R | I ∈ normalizedFactors (Ideal.span ({r} : Set R)) }) : multiplicity ((normalizedFactorsEquivSpanNormalizedFactors hr).symm I : R) r = multiplicity (I : Ideal R) (Ideal.span {r}) := by obtain ⟨x, hx⟩ := (normalizedFactorsEquivSpanNormalizedFactors hr).surjective I obtain ⟨a, ha⟩ := x rw [hx.symm, Equiv.symm_apply_apply, Subtype.coe_mk, multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity hr ha] #align multiplicity_normalized_factors_equiv_span_normalized_factors_symm_eq_multiplicity multiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_multiplicity /-- The bijection between the set of prime factors of the ideal `⟨r⟩` and the set of prime factors of `r` preserves `count` of the corresponding multisets. See `multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity` for the version stated in terms of multiplicity. -/ theorem count_span_normalizedFactors_eq {r X : R} (hr : r ≠ 0) (hX : Prime X) : Multiset.count (Ideal.span {X} : Ideal R) (normalizedFactors (Ideal.span {r})) = Multiset.count (normalize X) (normalizedFactors r) := by have := multiplicity_eq_multiplicity_span (R := R) (a := X) (b := r) rw [multiplicity_eq_count_normalizedFactors (Prime.irreducible hX) hr, multiplicity_eq_count_normalizedFactors (Prime.irreducible ?_), normalize_apply, normUnit_eq_one, Units.val_one, one_eq_top, mul_top, Nat.cast_inj] at this simp only [normalize_apply, this] · simp only [Submodule.zero_eq_bot, ne_eq, span_singleton_eq_bot, hr, not_false_eq_true] · simpa only [prime_span_singleton_iff] theorem count_span_normalizedFactors_eq_of_normUnit {r X : R} (hr : r ≠ 0) (hX₁ : normUnit X = 1) (hX : Prime X) : Multiset.count (Ideal.span {X} : Ideal R) (normalizedFactors (Ideal.span {r})) = Multiset.count X (normalizedFactors r) := by simpa [hX₁] using count_span_normalizedFactors_eq hr hX /-- The number of times an ideal `I` occurs as normalized factor of another ideal `J` is stable when regarding at these ideals as associated elements of the monoid of ideals.-/
Mathlib/RingTheory/DedekindDomain/Ideal.lean
1,548
1,560
theorem count_associates_factors_eq [DecidableEq <| Associates (Ideal R)] [∀ (p : Associates <| Ideal R), Decidable (Irreducible p)] (I J : Ideal R) (hI : I ≠ 0) (hJ : J.IsPrime) (hJ₀ : J ≠ ⊥) : (Associates.mk J).count (Associates.mk I).factors = Multiset.count J (normalizedFactors I) := by
replace hI : Associates.mk I ≠ 0 := Associates.mk_ne_zero.mpr hI have hJ' : Irreducible (Associates.mk J) := by simpa only [Associates.irreducible_mk] using (Ideal.prime_of_isPrime hJ₀ hJ).irreducible apply (Ideal.count_normalizedFactors_eq (p := J) (x := I) _ _).symm all_goals rw [← Ideal.dvd_iff_le, ← Associates.mk_dvd_mk, Associates.mk_pow] simp only [Associates.dvd_eq_le] rw [Associates.prime_pow_dvd_iff_le hI hJ'] linarith
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Decomposition.RadonNikodym import Mathlib.MeasureTheory.Measure.Haar.OfBasis import Mathlib.Probability.Independence.Basic #align_import probability.density from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Probability density function This file defines the probability density function of random variables, by which we mean measurable functions taking values in a Borel space. The probability density function is defined as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f` is said to the probability density function of a random variable `X` if for all measurable sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing the distribution of a random variable, and are useful for calculating probabilities and finding moments (although the latter is better achieved with moment generating functions). This file also defines the continuous uniform distribution and proves some properties about random variables with this distribution. ## Main definitions * `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`. * `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. * `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform distribution if it has a constant probability density function with a compact, non-null support. ## Main results * `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician, i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for all measurable `g : E → F`. * `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with pdf `f` has expectation `∫ x, x * f x dx`. * `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ` is the Lebesgue measure. ## TODOs Ultimately, we would also like to define characteristic functions to describe distributions as it exists for all random variables. However, to define this, we will need Fourier transforms which we currently do not have. -/ open scoped Classical MeasureTheory NNReal ENNReal open TopologicalSpace MeasureTheory.Measure noncomputable section namespace MeasureTheory variable {Ω E : Type*} [MeasurableSpace E] /-- A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`. -/ class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Prop where pdf' : AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ #align measure_theory.has_pdf MeasureTheory.HasPDF section HasPDF variable {_ : MeasurableSpace Ω} theorem hasPDF_iff {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} : HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := ⟨@HasPDF.pdf' _ _ _ _ _ _ _, HasPDF.mk⟩ #align measure_theory.pdf.has_pdf_iff MeasureTheory.hasPDF_iff theorem hasPDF_iff_of_aemeasurable {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hX : AEMeasurable X ℙ) : HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by rw [hasPDF_iff] simp only [hX, true_and] #align measure_theory.pdf.has_pdf_iff_of_measurable MeasureTheory.hasPDF_iff_of_aemeasurable @[measurability] theorem HasPDF.aemeasurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E) [hX : HasPDF X ℙ μ] : AEMeasurable X ℙ := hX.pdf'.1 #align measure_theory.has_pdf.measurable MeasureTheory.HasPDF.aemeasurable instance HasPDF.haveLebesgueDecomposition {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} [hX : HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ := hX.pdf'.2.1 #align measure_theory.pdf.have_lebesgue_decomposition_of_has_pdf MeasureTheory.HasPDF.haveLebesgueDecomposition theorem HasPDF.absolutelyContinuous {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} [hX : HasPDF X ℙ μ] : map X ℙ ≪ μ := hX.pdf'.2.2 #align measure_theory.pdf.map_absolutely_continuous MeasureTheory.HasPDF.absolutelyContinuous /-- A random variable that `HasPDF` is quasi-measure preserving. -/ theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E) [HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ := { measurable := h absolutelyContinuous := HasPDF.absolutelyContinuous } #align measure_theory.pdf.to_quasi_measure_preserving MeasureTheory.HasPDF.quasiMeasurePreserving_of_measurable theorem HasPDF.congr {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y) [hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ := ⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition, ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩ theorem HasPDF.congr' {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y) : HasPDF X ℙ μ ↔ HasPDF Y ℙ μ := ⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩ /-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/ theorem hasPDF_of_map_eq_withDensity {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ) (h : map X ℙ = μ.withDensity f) : HasPDF X ℙ μ := by refine ⟨hX, ?_, ?_⟩ <;> rw [h] · rw [withDensity_congr_ae hf.ae_eq_mk] exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk · exact withDensity_absolutelyContinuous μ f end HasPDF /-- If `X` is a random variable, then `pdf X` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. -/ def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : E → ℝ≥0∞ := (map X ℙ).rnDeriv μ #align measure_theory.pdf MeasureTheory.pdf theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} : pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by rw [pdf_def, map_of_not_aemeasurable hX] exact rnDeriv_zero μ #align measure_theory.pdf_eq_zero_of_not_measurable MeasureTheory.pdf_of_not_aemeasurable theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 := rnDeriv_of_not_haveLebesgueDecomposition h theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} (X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by contrapose! h exact pdf_of_not_aemeasurable h #align measure_theory.measurable_of_pdf_ne_zero MeasureTheory.aemeasurable_of_pdf_ne_zero theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by refine ⟨?_, ?_, hac⟩ · exact aemeasurable_of_pdf_ne_zero X hpdf · contrapose! hpdf have := pdf_of_not_haveLebesgueDecomposition hpdf filter_upwards using congrFun this #align measure_theory.has_pdf_of_pdf_ne_zero MeasureTheory.hasPDF_of_pdf_ne_zero @[measurability] theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by exact measurable_rnDeriv _ _ #align measure_theory.measurable_pdf MeasureTheory.measurable_pdf theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ := withDensity_rnDeriv_le _ _
Mathlib/Probability/Density.lean
177
181
theorem set_lintegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by
volume_tac) (s : Set E) : ∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by apply (withDensity_apply_le _ s).trans exact withDensity_pdf_le_map _ _ _ s
/- 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, Yury Kudryashov -/ import Mathlib.Topology.Order.LeftRightNhds /-! # Properties of LUB and GLB in an order topology -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β γ : Type*} section OrderTopology variable [TopologicalSpace α] [TopologicalSpace β] [LinearOrder α] [LinearOrder β] [OrderTopology α] [OrderTopology β] theorem IsLUB.frequently_mem {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) : ∃ᶠ x in 𝓝[≤] a, x ∈ s := by rcases hs with ⟨a', ha'⟩ intro h rcases (ha.1 ha').eq_or_lt with (rfl | ha'a) · exact h.self_of_nhdsWithin le_rfl ha' · rcases (mem_nhdsWithin_Iic_iff_exists_Ioc_subset' ha'a).1 h with ⟨b, hba, hb⟩ rcases ha.exists_between hba with ⟨b', hb's, hb'⟩ exact hb hb' hb's #align is_lub.frequently_mem IsLUB.frequently_mem theorem IsLUB.frequently_nhds_mem {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left #align is_lub.frequently_nhds_mem IsLUB.frequently_nhds_mem theorem IsGLB.frequently_mem {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty) : ∃ᶠ x in 𝓝[≥] a, x ∈ s := IsLUB.frequently_mem (α := αᵒᵈ) ha hs #align is_glb.frequently_mem IsGLB.frequently_mem theorem IsGLB.frequently_nhds_mem {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left #align is_glb.frequently_nhds_mem IsGLB.frequently_nhds_mem theorem IsLUB.mem_closure {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure #align is_lub.mem_closure IsLUB.mem_closure theorem IsGLB.mem_closure {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure #align is_glb.mem_closure IsGLB.mem_closure theorem IsLUB.nhdsWithin_neBot {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) : NeBot (𝓝[s] a) := mem_closure_iff_nhdsWithin_neBot.1 (ha.mem_closure hs) #align is_lub.nhds_within_ne_bot IsLUB.nhdsWithin_neBot theorem IsGLB.nhdsWithin_neBot : ∀ {a : α} {s : Set α}, IsGLB s a → s.Nonempty → NeBot (𝓝[s] a) := IsLUB.nhdsWithin_neBot (α := αᵒᵈ) #align is_glb.nhds_within_ne_bot IsGLB.nhdsWithin_neBot theorem isLUB_of_mem_nhds {s : Set α} {a : α} {f : Filter α} (hsa : a ∈ upperBounds s) (hsf : s ∈ f) [NeBot (f ⊓ 𝓝 a)] : IsLUB s a := ⟨hsa, fun b hb => not_lt.1 fun hba => have : s ∩ { a | b < a } ∈ f ⊓ 𝓝 a := inter_mem_inf hsf (IsOpen.mem_nhds (isOpen_lt' _) hba) let ⟨_x, ⟨hxs, hxb⟩⟩ := Filter.nonempty_of_mem this have : b < b := lt_of_lt_of_le hxb <| hb hxs lt_irrefl b this⟩ #align is_lub_of_mem_nhds isLUB_of_mem_nhds theorem isLUB_of_mem_closure {s : Set α} {a : α} (hsa : a ∈ upperBounds s) (hsf : a ∈ closure s) : IsLUB s a := by rw [mem_closure_iff_clusterPt, ClusterPt, inf_comm] at hsf exact isLUB_of_mem_nhds hsa (mem_principal_self s) #align is_lub_of_mem_closure isLUB_of_mem_closure theorem isGLB_of_mem_nhds : ∀ {s : Set α} {a : α} {f : Filter α}, a ∈ lowerBounds s → s ∈ f → NeBot (f ⊓ 𝓝 a) → IsGLB s a := isLUB_of_mem_nhds (α := αᵒᵈ) #align is_glb_of_mem_nhds isGLB_of_mem_nhds theorem isGLB_of_mem_closure {s : Set α} {a : α} (hsa : a ∈ lowerBounds s) (hsf : a ∈ closure s) : IsGLB s a := isLUB_of_mem_closure (α := αᵒᵈ) hsa hsf #align is_glb_of_mem_closure isGLB_of_mem_closure theorem IsLUB.mem_upperBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ} {s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) (ha : IsLUB s a) (hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upperBounds (f '' s) := by rintro _ ⟨x, hx, rfl⟩ replace ha := ha.inter_Ici_of_mem hx haveI := ha.nhdsWithin_neBot ⟨x, hx, le_rfl⟩ refine ge_of_tendsto (hb.mono_left (nhdsWithin_mono a (inter_subset_left (t := Ici x)))) ?_ exact mem_of_superset self_mem_nhdsWithin fun y hy => hf hx hy.1 hy.2 #align is_lub.mem_upper_bounds_of_tendsto IsLUB.mem_upperBounds_of_tendsto -- For a version of this theorem in which the convergence considered on the domain `α` is as `x : α` -- tends to infinity, rather than tending to a point `x` in `α`, see `isLUB_of_tendsto_atTop` theorem IsLUB.isLUB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ} {s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) (ha : IsLUB s a) (hs : s.Nonempty) (hb : Tendsto f (𝓝[s] a) (𝓝 b)) : IsLUB (f '' s) b := haveI := ha.nhdsWithin_neBot hs ⟨ha.mem_upperBounds_of_tendsto hf hb, fun _b' hb' => le_of_tendsto hb (mem_of_superset self_mem_nhdsWithin fun _ hx => hb' <| mem_image_of_mem _ hx)⟩ #align is_lub.is_lub_of_tendsto IsLUB.isLUB_of_tendsto theorem IsGLB.mem_lowerBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ} {s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) (ha : IsGLB s a) (hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lowerBounds (f '' s) := IsLUB.mem_upperBounds_of_tendsto (α := αᵒᵈ) (γ := γᵒᵈ) hf.dual ha hb #align is_glb.mem_lower_bounds_of_tendsto IsGLB.mem_lowerBounds_of_tendsto -- For a version of this theorem in which the convergence considered on the domain `α` is as -- `x : α` tends to negative infinity, rather than tending to a point `x` in `α`, see -- `isGLB_of_tendsto_atBot` theorem IsGLB.isGLB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ} {s : Set α} {a : α} {b : γ} (hf : MonotoneOn f s) : IsGLB s a → s.Nonempty → Tendsto f (𝓝[s] a) (𝓝 b) → IsGLB (f '' s) b := IsLUB.isLUB_of_tendsto (α := αᵒᵈ) (γ := γᵒᵈ) hf.dual #align is_glb.is_glb_of_tendsto IsGLB.isGLB_of_tendsto theorem IsLUB.mem_lowerBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ} {s : Set α} {a : α} {b : γ} (hf : AntitoneOn f s) (ha : IsLUB s a) (hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lowerBounds (f '' s) := IsLUB.mem_upperBounds_of_tendsto (γ := γᵒᵈ) hf ha hb #align is_lub.mem_lower_bounds_of_tendsto IsLUB.mem_lowerBounds_of_tendsto theorem IsLUB.isGLB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] : ∀ {f : α → γ} {s : Set α} {a : α} {b : γ}, AntitoneOn f s → IsLUB s a → s.Nonempty → Tendsto f (𝓝[s] a) (𝓝 b) → IsGLB (f '' s) b := IsLUB.isLUB_of_tendsto (γ := γᵒᵈ) #align is_lub.is_glb_of_tendsto IsLUB.isGLB_of_tendsto theorem IsGLB.mem_upperBounds_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] {f : α → γ} {s : Set α} {a : α} {b : γ} (hf : AntitoneOn f s) (ha : IsGLB s a) (hb : Tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upperBounds (f '' s) := IsGLB.mem_lowerBounds_of_tendsto (γ := γᵒᵈ) hf ha hb #align is_glb.mem_upper_bounds_of_tendsto IsGLB.mem_upperBounds_of_tendsto theorem IsGLB.isLUB_of_tendsto [Preorder γ] [TopologicalSpace γ] [OrderClosedTopology γ] : ∀ {f : α → γ} {s : Set α} {a : α} {b : γ}, AntitoneOn f s → IsGLB s a → s.Nonempty → Tendsto f (𝓝[s] a) (𝓝 b) → IsLUB (f '' s) b := IsGLB.isGLB_of_tendsto (γ := γᵒᵈ) #align is_glb.is_lub_of_tendsto IsGLB.isLUB_of_tendsto theorem IsLUB.mem_of_isClosed {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) (sc : IsClosed s) : a ∈ s := sc.closure_subset <| ha.mem_closure hs #align is_lub.mem_of_is_closed IsLUB.mem_of_isClosed alias IsClosed.isLUB_mem := IsLUB.mem_of_isClosed #align is_closed.is_lub_mem IsClosed.isLUB_mem theorem IsGLB.mem_of_isClosed {a : α} {s : Set α} (ha : IsGLB s a) (hs : s.Nonempty) (sc : IsClosed s) : a ∈ s := sc.closure_subset <| ha.mem_closure hs #align is_glb.mem_of_is_closed IsGLB.mem_of_isClosed alias IsClosed.isGLB_mem := IsGLB.mem_of_isClosed #align is_closed.is_glb_mem IsClosed.isGLB_mem /-! ### Existence of sequences tending to `sInf` or `sSup` of a given set -/ theorem IsLUB.exists_seq_strictMono_tendsto_of_not_mem {t : Set α} {x : α} [IsCountablyGenerated (𝓝 x)] (htx : IsLUB t x) (not_mem : x ∉ t) (ht : t.Nonempty) : ∃ u : ℕ → α, StrictMono u ∧ (∀ n, u n < x) ∧ Tendsto u atTop (𝓝 x) ∧ ∀ n, u n ∈ t := by obtain ⟨v, hvx, hvt⟩ := exists_seq_forall_of_frequently (htx.frequently_mem ht) replace hvx := hvx.mono_right nhdsWithin_le_nhds have hvx' : ∀ {n}, v n < x := (htx.1 (hvt _)).lt_of_ne (ne_of_mem_of_not_mem (hvt _) not_mem) have : ∀ k, ∀ᶠ l in atTop, v k < v l := fun k => hvx.eventually (lt_mem_nhds hvx') choose N hN hvN using fun k => ((eventually_gt_atTop k).and (this k)).exists refine ⟨fun k => v (N^[k] 0), strictMono_nat_of_lt_succ fun _ => ?_, fun _ => hvx', hvx.comp (strictMono_nat_of_lt_succ fun _ => ?_).tendsto_atTop, fun _ => hvt _⟩ · rw [iterate_succ_apply']; exact hvN _ · rw [iterate_succ_apply']; exact hN _ #align is_lub.exists_seq_strict_mono_tendsto_of_not_mem IsLUB.exists_seq_strictMono_tendsto_of_not_mem theorem IsLUB.exists_seq_monotone_tendsto {t : Set α} {x : α} [IsCountablyGenerated (𝓝 x)] (htx : IsLUB t x) (ht : t.Nonempty) : ∃ u : ℕ → α, Monotone u ∧ (∀ n, u n ≤ x) ∧ Tendsto u atTop (𝓝 x) ∧ ∀ n, u n ∈ t := by by_cases h : x ∈ t · exact ⟨fun _ => x, monotone_const, fun n => le_rfl, tendsto_const_nhds, fun _ => h⟩ · rcases htx.exists_seq_strictMono_tendsto_of_not_mem h ht with ⟨u, hu⟩ exact ⟨u, hu.1.monotone, fun n => (hu.2.1 n).le, hu.2.2⟩ #align is_lub.exists_seq_monotone_tendsto IsLUB.exists_seq_monotone_tendsto theorem exists_seq_strictMono_tendsto' {α : Type*} [LinearOrder α] [TopologicalSpace α] [DenselyOrdered α] [OrderTopology α] [FirstCountableTopology α] {x y : α} (hy : y < x) : ∃ u : ℕ → α, StrictMono u ∧ (∀ n, u n ∈ Ioo y x) ∧ Tendsto u atTop (𝓝 x) := by have hx : x ∉ Ioo y x := fun h => (lt_irrefl x h.2).elim have ht : Set.Nonempty (Ioo y x) := nonempty_Ioo.2 hy rcases (isLUB_Ioo hy).exists_seq_strictMono_tendsto_of_not_mem hx ht with ⟨u, hu⟩ exact ⟨u, hu.1, hu.2.2.symm⟩ #align exists_seq_strict_mono_tendsto' exists_seq_strictMono_tendsto' theorem exists_seq_strictMono_tendsto [DenselyOrdered α] [NoMinOrder α] [FirstCountableTopology α] (x : α) : ∃ u : ℕ → α, StrictMono u ∧ (∀ n, u n < x) ∧ Tendsto u atTop (𝓝 x) := by obtain ⟨y, hy⟩ : ∃ y, y < x := exists_lt x rcases exists_seq_strictMono_tendsto' hy with ⟨u, hu_mono, hu_mem, hux⟩ exact ⟨u, hu_mono, fun n => (hu_mem n).2, hux⟩ #align exists_seq_strict_mono_tendsto exists_seq_strictMono_tendsto theorem exists_seq_strictMono_tendsto_nhdsWithin [DenselyOrdered α] [NoMinOrder α] [FirstCountableTopology α] (x : α) : ∃ u : ℕ → α, StrictMono u ∧ (∀ n, u n < x) ∧ Tendsto u atTop (𝓝[<] x) := let ⟨u, hu, hx, h⟩ := exists_seq_strictMono_tendsto x ⟨u, hu, hx, tendsto_nhdsWithin_mono_right (range_subset_iff.2 hx) <| tendsto_nhdsWithin_range.2 h⟩ #align exists_seq_strict_mono_tendsto_nhds_within exists_seq_strictMono_tendsto_nhdsWithin theorem exists_seq_tendsto_sSup {α : Type*} [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [FirstCountableTopology α] {S : Set α} (hS : S.Nonempty) (hS' : BddAbove S) : ∃ u : ℕ → α, Monotone u ∧ Tendsto u atTop (𝓝 (sSup S)) ∧ ∀ n, u n ∈ S := by rcases (isLUB_csSup hS hS').exists_seq_monotone_tendsto hS with ⟨u, hu⟩ exact ⟨u, hu.1, hu.2.2⟩ #align exists_seq_tendsto_Sup exists_seq_tendsto_sSup theorem IsGLB.exists_seq_strictAnti_tendsto_of_not_mem {t : Set α} {x : α} [IsCountablyGenerated (𝓝 x)] (htx : IsGLB t x) (not_mem : x ∉ t) (ht : t.Nonempty) : ∃ u : ℕ → α, StrictAnti u ∧ (∀ n, x < u n) ∧ Tendsto u atTop (𝓝 x) ∧ ∀ n, u n ∈ t := IsLUB.exists_seq_strictMono_tendsto_of_not_mem (α := αᵒᵈ) htx not_mem ht #align is_glb.exists_seq_strict_anti_tendsto_of_not_mem IsGLB.exists_seq_strictAnti_tendsto_of_not_mem theorem IsGLB.exists_seq_antitone_tendsto {t : Set α} {x : α} [IsCountablyGenerated (𝓝 x)] (htx : IsGLB t x) (ht : t.Nonempty) : ∃ u : ℕ → α, Antitone u ∧ (∀ n, x ≤ u n) ∧ Tendsto u atTop (𝓝 x) ∧ ∀ n, u n ∈ t := IsLUB.exists_seq_monotone_tendsto (α := αᵒᵈ) htx ht #align is_glb.exists_seq_antitone_tendsto IsGLB.exists_seq_antitone_tendsto
Mathlib/Topology/Order/IsLUB.lean
237
240
theorem exists_seq_strictAnti_tendsto' [DenselyOrdered α] [FirstCountableTopology α] {x y : α} (hy : x < y) : ∃ u : ℕ → α, StrictAnti u ∧ (∀ n, u n ∈ Ioo x y) ∧ Tendsto u atTop (𝓝 x) := by
simpa only [dual_Ioo] using exists_seq_strictMono_tendsto' (α := αᵒᵈ) (OrderDual.toDual_lt_toDual.2 hy)
/- 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.Fintype.List #align_import data.list.cycle from "leanprover-community/mathlib"@"7413128c3bcb3b0818e3e18720abc9ea3100fb49" /-! # Cycles of a list Lists have an equivalence relation of whether they are rotational permutations of one another. This relation is defined as `IsRotated`. Based on this, we define the quotient of lists by the rotation relation, called `Cycle`. We also define a representation of concrete cycles, available when viewing them in a goal state or via `#eval`, when over representable types. For example, the cycle `(2 1 4 3)` will be shown as `c[2, 1, 4, 3]`. Two equal cycles may be printed differently if their internal representation is different. -/ assert_not_exists MonoidWithZero namespace List variable {α : Type*} [DecidableEq α] /-- Return the `z` such that `x :: z :: _` appears in `xs`, or `default` if there is no such `z`. -/ def nextOr : ∀ (_ : List α) (_ _ : α), α | [], _, default => default | [_], _, default => default -- Handles the not-found and the wraparound case | y :: z :: xs, x, default => if x = y then z else nextOr (z :: xs) x default #align list.next_or List.nextOr @[simp] theorem nextOr_nil (x d : α) : nextOr [] x d = d := rfl #align list.next_or_nil List.nextOr_nil @[simp] theorem nextOr_singleton (x y d : α) : nextOr [y] x d = d := rfl #align list.next_or_singleton List.nextOr_singleton @[simp] theorem nextOr_self_cons_cons (xs : List α) (x y d : α) : nextOr (x :: y :: xs) x d = y := if_pos rfl #align list.next_or_self_cons_cons List.nextOr_self_cons_cons theorem nextOr_cons_of_ne (xs : List α) (y x d : α) (h : x ≠ y) : nextOr (y :: xs) x d = nextOr xs x d := by cases' xs with z zs · rfl · exact if_neg h #align list.next_or_cons_of_ne List.nextOr_cons_of_ne /-- `nextOr` does not depend on the default value, if the next value appears. -/ theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs) (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by induction' xs with y ys IH · cases x_mem cases' ys with z zs · simp at x_mem x_ne contradiction by_cases h : x = y · rw [h, nextOr_self_cons_cons, nextOr_self_cons_cons] · rw [nextOr, nextOr, IH] · simpa [h] using x_mem · simpa using x_ne #align list.next_or_eq_next_or_of_mem_of_ne List.nextOr_eq_nextOr_of_mem_of_ne theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by induction' xs with y ys IH · simp at h cases' ys with z zs · simp at h · by_cases hx : x = y · simp [hx] · rw [nextOr_cons_of_ne _ _ _ _ hx] at h simpa [hx] using IH h #align list.mem_of_next_or_ne List.mem_of_nextOr_ne theorem nextOr_concat {xs : List α} {x : α} (d : α) (h : x ∉ xs) : nextOr (xs ++ [x]) x d = d := by induction' xs with z zs IH · simp · obtain ⟨hz, hzs⟩ := not_or.mp (mt mem_cons.2 h) rw [cons_append, nextOr_cons_of_ne _ _ _ _ hz, IH hzs] #align list.next_or_concat List.nextOr_concat theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by revert hd suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by exact this xs fun _ => id intro xs' hxs' hd induction' xs with y ys ih · exact hd cases' ys with z zs · exact hd rw [nextOr] split_ifs with h · exact hxs' _ (mem_cons_of_mem _ (mem_cons_self _ _)) · exact ih fun _ h => hxs' _ (mem_cons_of_mem _ h) #align list.next_or_mem List.nextOr_mem /-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the next element of `l`. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates. For example: * `next [1, 2, 3] 2 _ = 3` * `next [1, 2, 3] 3 _ = 1` * `next [1, 2, 3, 2, 4] 2 _ = 3` * `next [1, 2, 3, 2] 2 _ = 3` * `next [1, 1, 2, 3, 2] 1 _ = 1` -/ def next (l : List α) (x : α) (h : x ∈ l) : α := nextOr l x (l.get ⟨0, length_pos_of_mem h⟩) #align list.next List.next /-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the previous element of `l`. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates. * `prev [1, 2, 3] 2 _ = 1` * `prev [1, 2, 3] 1 _ = 3` * `prev [1, 2, 3, 2, 4] 2 _ = 1` * `prev [1, 2, 3, 4, 2] 2 _ = 1` * `prev [1, 1, 2] 1 _ = 2` -/ def prev : ∀ l : List α, ∀ x ∈ l, α | [], _, h => by simp at h | [y], _, _ => y | y :: z :: xs, x, h => if hx : x = y then getLast (z :: xs) (cons_ne_nil _ _) else if x = z then y else prev (z :: xs) x (by simpa [hx] using h) #align list.prev List.prev variable (l : List α) (x : α) @[simp] theorem next_singleton (x y : α) (h : x ∈ [y]) : next [y] x h = y := rfl #align list.next_singleton List.next_singleton @[simp] theorem prev_singleton (x y : α) (h : x ∈ [y]) : prev [y] x h = y := rfl #align list.prev_singleton List.prev_singleton theorem next_cons_cons_eq' (y z : α) (h : x ∈ y :: z :: l) (hx : x = y) : next (y :: z :: l) x h = z := by rw [next, nextOr, if_pos hx] #align list.next_cons_cons_eq' List.next_cons_cons_eq' @[simp] theorem next_cons_cons_eq (z : α) (h : x ∈ x :: z :: l) : next (x :: z :: l) x h = z := next_cons_cons_eq' l x x z h rfl #align list.next_cons_cons_eq List.next_cons_cons_eq theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y) (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) : next (y :: l) x h = next l x (by simpa [hy] using h) := by rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne] · rwa [getLast_cons] at hx exact ne_nil_of_mem (by assumption) · rwa [getLast_cons] at hx #align list.next_ne_head_ne_last List.next_ne_head_ne_getLast theorem next_cons_concat (y : α) (hy : x ≠ y) (hx : x ∉ l) (h : x ∈ y :: l ++ [x] := mem_append_right _ (mem_singleton_self x)) : next (y :: l ++ [x]) x h = y := by rw [next, nextOr_concat] · rfl · simp [hy, hx] #align list.next_cons_concat List.next_cons_concat theorem next_getLast_cons (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y) (hx : x = getLast (y :: l) (cons_ne_nil _ _)) (hl : Nodup l) : next (y :: l) x h = y := by rw [next, get, ← dropLast_append_getLast (cons_ne_nil y l), hx, nextOr_concat] subst hx intro H obtain ⟨⟨_ | k, hk⟩, hk'⟩ := get_of_mem H · rw [← Option.some_inj] at hk' rw [← get?_eq_get, dropLast_eq_take, get?_take, get?_zero, head?_cons, Option.some_inj] at hk' · exact hy (Eq.symm hk') rw [length_cons, Nat.pred_succ] exact length_pos_of_mem (by assumption) suffices k + 1 = l.length by simp [this] at hk cases' l with hd tl · simp at hk · rw [nodup_iff_injective_get] at hl rw [length, Nat.succ_inj'] refine Fin.val_eq_of_eq <| @hl ⟨k, Nat.lt_of_succ_lt <| by simpa using hk⟩ ⟨tl.length, by simp⟩ ?_ rw [← Option.some_inj] at hk' rw [← get?_eq_get, dropLast_eq_take, get?_take, get?, get?_eq_get, Option.some_inj] at hk' · rw [hk'] simp only [getLast_eq_get, length_cons, ge_iff_le, Nat.succ_sub_succ_eq_sub, nonpos_iff_eq_zero, add_eq_zero_iff, and_false, Nat.sub_zero, get_cons_succ] simpa using hk #align list.next_last_cons List.next_getLast_cons theorem prev_getLast_cons' (y : α) (hxy : x ∈ y :: l) (hx : x = y) : prev (y :: l) x hxy = getLast (y :: l) (cons_ne_nil _ _) := by cases l <;> simp [prev, hx] #align list.prev_last_cons' List.prev_getLast_cons' @[simp] theorem prev_getLast_cons (h : x ∈ x :: l) : prev (x :: l) x h = getLast (x :: l) (cons_ne_nil _ _) := prev_getLast_cons' l x x h rfl #align list.prev_last_cons List.prev_getLast_cons theorem prev_cons_cons_eq' (y z : α) (h : x ∈ y :: z :: l) (hx : x = y) : prev (y :: z :: l) x h = getLast (z :: l) (cons_ne_nil _ _) := by rw [prev, dif_pos hx] #align list.prev_cons_cons_eq' List.prev_cons_cons_eq' --@[simp] Porting note (#10618): `simp` can prove it theorem prev_cons_cons_eq (z : α) (h : x ∈ x :: z :: l) : prev (x :: z :: l) x h = getLast (z :: l) (cons_ne_nil _ _) := prev_cons_cons_eq' l x x z h rfl #align list.prev_cons_cons_eq List.prev_cons_cons_eq theorem prev_cons_cons_of_ne' (y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y) (hz : x = z) : prev (y :: z :: l) x h = y := by cases l · simp [prev, hy, hz] · rw [prev, dif_neg hy, if_pos hz] #align list.prev_cons_cons_of_ne' List.prev_cons_cons_of_ne' theorem prev_cons_cons_of_ne (y : α) (h : x ∈ y :: x :: l) (hy : x ≠ y) : prev (y :: x :: l) x h = y := prev_cons_cons_of_ne' _ _ _ _ _ hy rfl #align list.prev_cons_cons_of_ne List.prev_cons_cons_of_ne theorem prev_ne_cons_cons (y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y) (hz : x ≠ z) : prev (y :: z :: l) x h = prev (z :: l) x (by simpa [hy] using h) := by cases l · simp [hy, hz] at h · rw [prev, dif_neg hy, if_neg hz] #align list.prev_ne_cons_cons List.prev_ne_cons_cons theorem next_mem (h : x ∈ l) : l.next x h ∈ l := nextOr_mem (get_mem _ _ _) #align list.next_mem List.next_mem theorem prev_mem (h : x ∈ l) : l.prev x h ∈ l := by cases' l with hd tl · simp at h induction' tl with hd' tl hl generalizing hd · simp · by_cases hx : x = hd · simp only [hx, prev_cons_cons_eq] exact mem_cons_of_mem _ (getLast_mem _) · rw [prev, dif_neg hx] split_ifs with hm · exact mem_cons_self _ _ · exact mem_cons_of_mem _ (hl _ _) #align list.prev_mem List.prev_mem -- Porting note (#10756): new theorem theorem next_get : ∀ (l : List α) (_h : Nodup l) (i : Fin l.length), next l (l.get i) (get_mem _ _ _) = l.get ⟨(i + 1) % l.length, Nat.mod_lt _ (i.1.zero_le.trans_lt i.2)⟩ | [], _, i => by simpa using i.2 | [_], _, _ => by simp | x::y::l, _h, ⟨0, h0⟩ => by have h₁ : get (x :: y :: l) { val := 0, isLt := h0 } = x := by simp rw [next_cons_cons_eq' _ _ _ _ _ h₁] simp | x::y::l, hn, ⟨i+1, hi⟩ => by have hx' : (x :: y :: l).get ⟨i+1, hi⟩ ≠ x := by intro H suffices (i + 1 : ℕ) = 0 by simpa rw [nodup_iff_injective_get] at hn refine Fin.val_eq_of_eq (@hn ⟨i + 1, hi⟩ ⟨0, by simp⟩ ?_) simpa using H have hi' : i ≤ l.length := Nat.le_of_lt_succ (Nat.succ_lt_succ_iff.1 hi) rcases hi'.eq_or_lt with (hi' | hi') · subst hi' rw [next_getLast_cons] · simp [hi', get] · rw [get_cons_succ]; exact get_mem _ _ _ · exact hx' · simp [getLast_eq_get] · exact hn.of_cons · rw [next_ne_head_ne_getLast _ _ _ _ _ hx'] · simp only [get_cons_succ] rw [next_get (y::l), ← get_cons_succ (a := x)] · congr dsimp rw [Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 hi'), Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 (Nat.succ_lt_succ_iff.2 hi'))] · simp [Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 hi'), Nat.succ_eq_add_one, hi'] · exact hn.of_cons · rw [getLast_eq_get] intro h have := nodup_iff_injective_get.1 hn h simp at this; simp [this] at hi' · rw [get_cons_succ]; exact get_mem _ _ _ set_option linter.deprecated false in @[deprecated next_get (since := "2023-01-27")] theorem next_nthLe (l : List α) (h : Nodup l) (n : ℕ) (hn : n < l.length) : next l (l.nthLe n hn) (nthLe_mem _ _ _) = l.nthLe ((n + 1) % l.length) (Nat.mod_lt _ (n.zero_le.trans_lt hn)) := next_get l h ⟨n, hn⟩ #align list.next_nth_le List.next_nthLe set_option linter.deprecated false in theorem prev_nthLe (l : List α) (h : Nodup l) (n : ℕ) (hn : n < l.length) : prev l (l.nthLe n hn) (nthLe_mem _ _ _) = l.nthLe ((n + (l.length - 1)) % l.length) (Nat.mod_lt _ (n.zero_le.trans_lt hn)) := by cases' l with x l · simp at hn induction' l with y l hl generalizing n x · simp · rcases n with (_ | _ | n) · simp [Nat.add_succ_sub_one, add_zero, List.prev_cons_cons_eq, Nat.zero_eq, List.length, List.nthLe, Nat.succ_add_sub_one, zero_add, getLast_eq_get, Nat.mod_eq_of_lt (Nat.succ_lt_succ l.length.lt_succ_self)] · simp only [mem_cons, nodup_cons] at h push_neg at h simp only [List.prev_cons_cons_of_ne _ _ _ _ h.left.left.symm, Nat.zero_eq, List.length, List.nthLe, add_comm, eq_self_iff_true, Nat.succ_add_sub_one, Nat.mod_self, zero_add, List.get] · rw [prev_ne_cons_cons] · convert hl n.succ y h.of_cons (Nat.le_of_succ_le_succ hn) using 1 have : ∀ k hk, (y :: l).nthLe k hk = (x :: y :: l).nthLe (k + 1) (Nat.succ_lt_succ hk) := by intros simp [List.nthLe] rw [this] congr simp only [Nat.add_succ_sub_one, add_zero, length] simp only [length, Nat.succ_lt_succ_iff] at hn set k := l.length rw [Nat.succ_add, ← Nat.add_succ, Nat.add_mod_right, Nat.succ_add, ← Nat.add_succ _ k, Nat.add_mod_right, Nat.mod_eq_of_lt, Nat.mod_eq_of_lt] · exact Nat.lt_succ_of_lt hn · exact Nat.succ_lt_succ (Nat.lt_succ_of_lt hn) · intro H suffices n.succ.succ = 0 by simpa rw [nodup_iff_nthLe_inj] at h refine h _ _ hn Nat.succ_pos' ?_ simpa using H · intro H suffices n.succ.succ = 1 by simpa rw [nodup_iff_nthLe_inj] at h refine h _ _ hn (Nat.succ_lt_succ Nat.succ_pos') ?_ simpa using H #align list.prev_nth_le List.prev_nthLe set_option linter.deprecated false in theorem pmap_next_eq_rotate_one (h : Nodup l) : (l.pmap l.next fun _ h => h) = l.rotate 1 := by apply List.ext_nthLe · simp · intros rw [nthLe_pmap, nthLe_rotate, next_nthLe _ h] #align list.pmap_next_eq_rotate_one List.pmap_next_eq_rotate_one set_option linter.deprecated false in theorem pmap_prev_eq_rotate_length_sub_one (h : Nodup l) : (l.pmap l.prev fun _ h => h) = l.rotate (l.length - 1) := by apply List.ext_nthLe · simp · intro n hn hn' rw [nthLe_rotate, nthLe_pmap, prev_nthLe _ h] #align list.pmap_prev_eq_rotate_length_sub_one List.pmap_prev_eq_rotate_length_sub_one set_option linter.deprecated false in theorem prev_next (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : prev l (next l x hx) (next_mem _ _ _) = x := by obtain ⟨n, hn, rfl⟩ := nthLe_of_mem hx simp only [next_nthLe, prev_nthLe, h, Nat.mod_add_mod] cases' l with hd tl · simp at hx · have : (n + 1 + length tl) % (length tl + 1) = n := by rw [length_cons, Nat.succ_eq_add_one] at hn rw [add_assoc, add_comm 1, Nat.add_mod_right, Nat.mod_eq_of_lt hn] simp only [length_cons, Nat.succ_sub_succ_eq_sub, Nat.sub_zero, Nat.succ_eq_add_one, this] #align list.prev_next List.prev_next set_option linter.deprecated false in theorem next_prev (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : next l (prev l x hx) (prev_mem _ _ _) = x := by obtain ⟨n, hn, rfl⟩ := nthLe_of_mem hx simp only [next_nthLe, prev_nthLe, h, Nat.mod_add_mod] cases' l with hd tl · simp at hx · have : (n + length tl + 1) % (length tl + 1) = n := by rw [length_cons, Nat.succ_eq_add_one] at hn rw [add_assoc, Nat.add_mod_right, Nat.mod_eq_of_lt hn] simp [this] #align list.next_prev List.next_prev set_option linter.deprecated false in
Mathlib/Data/List/Cycle.lean
400
414
theorem prev_reverse_eq_next (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : prev l.reverse x (mem_reverse.mpr hx) = next l x hx := by
obtain ⟨k, hk, rfl⟩ := nthLe_of_mem hx have lpos : 0 < l.length := k.zero_le.trans_lt hk have key : l.length - 1 - k < l.length := by omega rw [← nthLe_pmap l.next (fun _ h => h) (by simpa using hk)] simp_rw [← nthLe_reverse l k (key.trans_le (by simp)), pmap_next_eq_rotate_one _ h] rw [← nthLe_pmap l.reverse.prev fun _ h => h] · simp_rw [pmap_prev_eq_rotate_length_sub_one _ (nodup_reverse.mpr h), rotate_reverse, length_reverse, Nat.mod_eq_of_lt (Nat.sub_lt lpos Nat.succ_pos'), Nat.sub_sub_self (Nat.succ_le_of_lt lpos)] rw [← nthLe_reverse] · simp [Nat.sub_sub_self (Nat.le_sub_one_of_lt hk)] · simpa using (Nat.sub_le _ _).trans_lt (Nat.sub_lt lpos Nat.succ_pos') · simpa
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.AlgebraicTopology.DoldKan.GammaCompN import Mathlib.AlgebraicTopology.DoldKan.NReflectsIso #align_import algebraic_topology.dold_kan.n_comp_gamma from "leanprover-community/mathlib"@"32a7e535287f9c73f2e4d2aef306a39190f0b504" /-! The unit isomorphism of the Dold-Kan equivalence In order to construct the unit isomorphism of the Dold-Kan equivalence, we first construct natural transformations `Γ₂N₁.natTrans : N₁ ⋙ Γ₂ ⟶ toKaroubi (SimplicialObject C)` and `Γ₂N₂.natTrans : N₂ ⋙ Γ₂ ⟶ 𝟭 (SimplicialObject C)`. It is then shown that `Γ₂N₂.natTrans` is an isomorphism by using that it becomes an isomorphism after the application of the functor `N₂ : Karoubi (SimplicialObject C) ⥤ Karoubi (ChainComplex C ℕ)` which reflects isomorphisms. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Idempotents SimplexCategory Opposite SimplicialObject Simplicial DoldKan namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] theorem PInfty_comp_map_mono_eq_zero (X : SimplicialObject C) {n : ℕ} {Δ' : SimplexCategory} (i : Δ' ⟶ [n]) [hi : Mono i] (h₁ : Δ'.len ≠ n) (h₂ : ¬Isδ₀ i) : PInfty.f n ≫ X.map i.op = 0 := by induction' Δ' using SimplexCategory.rec with m obtain ⟨k, hk⟩ := Nat.exists_eq_add_of_lt (len_lt_of_mono i fun h => by rw [← h] at h₁ exact h₁ rfl) simp only [len_mk] at hk rcases k with _|k · change n = m + 1 at hk subst hk obtain ⟨j, rfl⟩ := eq_δ_of_mono i rw [Isδ₀.iff] at h₂ have h₃ : 1 ≤ (j : ℕ) := by by_contra h exact h₂ (by simpa only [Fin.ext_iff, not_le, Nat.lt_one_iff] using h) exact (HigherFacesVanish.of_P (m + 1) m).comp_δ_eq_zero j h₂ (by omega) · simp only [Nat.succ_eq_add_one, ← add_assoc] at hk clear h₂ hi subst hk obtain ⟨j₁ : Fin (_ + 1), i, rfl⟩ := eq_comp_δ_of_not_surjective i fun h => by have h' := len_le_of_epi (SimplexCategory.epi_iff_surjective.2 h) dsimp at h' omega obtain ⟨j₂, i, rfl⟩ := eq_comp_δ_of_not_surjective i fun h => by have h' := len_le_of_epi (SimplexCategory.epi_iff_surjective.2 h) dsimp at h' omega by_cases hj₁ : j₁ = 0 · subst hj₁ rw [assoc, ← SimplexCategory.δ_comp_δ'' (Fin.zero_le _)] simp only [op_comp, X.map_comp, assoc, PInfty_f] erw [(HigherFacesVanish.of_P _ _).comp_δ_eq_zero_assoc _ j₂.succ_ne_zero, zero_comp] simp only [Nat.succ_eq_add_one, Nat.add, Fin.succ] omega · simp only [op_comp, X.map_comp, assoc, PInfty_f] erw [(HigherFacesVanish.of_P _ _).comp_δ_eq_zero_assoc _ hj₁, zero_comp] by_contra exact hj₁ (by simp only [Fin.ext_iff, Fin.val_zero]; linarith) set_option linter.uppercaseLean3 false in #align algebraic_topology.dold_kan.P_infty_comp_map_mono_eq_zero AlgebraicTopology.DoldKan.PInfty_comp_map_mono_eq_zero @[reassoc]
Mathlib/AlgebraicTopology/DoldKan/NCompGamma.lean
83
124
theorem Γ₀_obj_termwise_mapMono_comp_PInfty (X : SimplicialObject C) {Δ Δ' : SimplexCategory} (i : Δ ⟶ Δ') [Mono i] : Γ₀.Obj.Termwise.mapMono (AlternatingFaceMapComplex.obj X) i ≫ PInfty.f Δ.len = PInfty.f Δ'.len ≫ X.map i.op := by
induction' Δ using SimplexCategory.rec with n induction' Δ' using SimplexCategory.rec with n' dsimp -- We start with the case `i` is an identity by_cases h : n = n' · subst h simp only [SimplexCategory.eq_id_of_mono i, Γ₀.Obj.Termwise.mapMono_id, op_id, X.map_id] dsimp simp only [id_comp, comp_id] by_cases hi : Isδ₀ i -- The case `i = δ 0` · have h' : n' = n + 1 := hi.left subst h' simp only [Γ₀.Obj.Termwise.mapMono_δ₀' _ i hi] dsimp rw [← PInfty.comm _ n, AlternatingFaceMapComplex.obj_d_eq] simp only [eq_self_iff_true, id_comp, if_true, Preadditive.comp_sum] rw [Finset.sum_eq_single (0 : Fin (n + 2))] rotate_left · intro b _ hb rw [Preadditive.comp_zsmul] erw [PInfty_comp_map_mono_eq_zero X (SimplexCategory.δ b) h (by rw [Isδ₀.iff] exact hb), zsmul_zero] · simp only [Finset.mem_univ, not_true, IsEmpty.forall_iff] · simp only [hi.eq_δ₀, Fin.val_zero, pow_zero, one_zsmul] rfl -- The case `i ≠ δ 0` · rw [Γ₀.Obj.Termwise.mapMono_eq_zero _ i _ hi, zero_comp] swap · by_contra h' exact h (congr_arg SimplexCategory.len h'.symm) rw [PInfty_comp_map_mono_eq_zero] · exact h · by_contra h' exact hi h'