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
| Mathlib/Algebra/Order/Field/Basic.lean | 382 | 382 | theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by | simpa using le_inv ha hb
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.MeasureTheory.Function.SimpleFunc
import Mathlib.MeasureTheory.Measure.MutuallySingular
import Mathlib.MeasureTheory.Measure.Count
import Mathlib.Topology.IndicatorConstPointwise
import Mathlib.MeasureTheory.Constructions.BorelSpace.Real
#align_import measure_theory.integral.lebesgue from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520"
/-!
# Lower Lebesgue integral for `ℝ≥0∞`-valued functions
We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function.
## Notation
We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`.
* `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`;
* `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure
`volume` on `α`;
* `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect
to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`;
* `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect
to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`.
-/
assert_not_exists NormedSpace
set_option autoImplicit true
noncomputable section
open Set hiding restrict restrict_apply
open Filter ENNReal
open Function (support)
open scoped Classical
open Topology NNReal ENNReal MeasureTheory
namespace MeasureTheory
local infixr:25 " →ₛ " => SimpleFunc
variable {α β γ δ : Type*}
section Lintegral
open SimpleFunc
variable {m : MeasurableSpace α} {μ ν : Measure α}
/-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/
irreducible_def lintegral {_ : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ :=
⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ
#align measure_theory.lintegral MeasureTheory.lintegral
/-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly,
and needs parentheses. We do not set the binding power of `r` to `0`, because then
`∫⁻ x, f x = 0` will be parsed incorrectly. -/
@[inherit_doc MeasureTheory.lintegral]
notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r
@[inherit_doc MeasureTheory.lintegral]
notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r
@[inherit_doc MeasureTheory.lintegral]
notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r
@[inherit_doc MeasureTheory.lintegral]
notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r
theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) :
∫⁻ a, f a ∂μ = f.lintegral μ := by
rw [MeasureTheory.lintegral]
exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl)
(le_iSup₂_of_le f le_rfl le_rfl)
#align measure_theory.simple_func.lintegral_eq_lintegral MeasureTheory.SimpleFunc.lintegral_eq_lintegral
@[mono]
theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄
(hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by
rw [lintegral, lintegral]
exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩
#align measure_theory.lintegral_mono' MeasureTheory.lintegral_mono'
-- workaround for the known eta-reduction issue with `@[gcongr]`
@[gcongr] theorem lintegral_mono_fn' ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) (h2 : μ ≤ ν) :
lintegral μ f ≤ lintegral ν g :=
lintegral_mono' h2 hfg
theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ :=
lintegral_mono' (le_refl μ) hfg
#align measure_theory.lintegral_mono MeasureTheory.lintegral_mono
-- workaround for the known eta-reduction issue with `@[gcongr]`
@[gcongr] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) :
lintegral μ f ≤ lintegral μ g :=
lintegral_mono hfg
theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ :=
lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a)
#align measure_theory.lintegral_mono_nnreal MeasureTheory.lintegral_mono_nnreal
theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) :
⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by
apply le_antisymm
· exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i
· rw [lintegral]
refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_
exact le_of_eq (i.lintegral_eq_lintegral _).symm
#align measure_theory.supr_lintegral_measurable_le_eq_lintegral MeasureTheory.iSup_lintegral_measurable_le_eq_lintegral
theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞}
(hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ :=
lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f)
#align measure_theory.lintegral_mono_set MeasureTheory.lintegral_mono_set
theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞}
(hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ :=
lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f)
#align measure_theory.lintegral_mono_set' MeasureTheory.lintegral_mono_set'
theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) :=
lintegral_mono
#align measure_theory.monotone_lintegral MeasureTheory.monotone_lintegral
@[simp]
theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by
rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const]
rfl
#align measure_theory.lintegral_const MeasureTheory.lintegral_const
theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp
#align measure_theory.lintegral_zero MeasureTheory.lintegral_zero
theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 :=
lintegral_zero
#align measure_theory.lintegral_zero_fun MeasureTheory.lintegral_zero_fun
-- @[simp] -- Porting note (#10618): simp can prove this
theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul]
#align measure_theory.lintegral_one MeasureTheory.lintegral_one
theorem set_lintegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by
rw [lintegral_const, Measure.restrict_apply_univ]
#align measure_theory.set_lintegral_const MeasureTheory.set_lintegral_const
theorem set_lintegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [set_lintegral_const, one_mul]
#align measure_theory.set_lintegral_one MeasureTheory.set_lintegral_one
theorem set_lintegral_const_lt_top [IsFiniteMeasure μ] (s : Set α) {c : ℝ≥0∞} (hc : c ≠ ∞) :
∫⁻ _ in s, c ∂μ < ∞ := by
rw [lintegral_const]
exact ENNReal.mul_lt_top hc (measure_ne_top (μ.restrict s) univ)
#align measure_theory.set_lintegral_const_lt_top MeasureTheory.set_lintegral_const_lt_top
theorem lintegral_const_lt_top [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _, c ∂μ < ∞ := by
simpa only [Measure.restrict_univ] using set_lintegral_const_lt_top (univ : Set α) hc
#align measure_theory.lintegral_const_lt_top MeasureTheory.lintegral_const_lt_top
section
variable (μ)
/-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same
integral. -/
theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) :
∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by
rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀
· exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩
rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩
have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by
intro n
simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using
(hLf n).2
choose g hgm hgf hLg using this
refine
⟨fun x => ⨆ n, g n x, measurable_iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩
· refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_
exact le_iSup (fun n => g n x) n
· exact lintegral_mono fun x => iSup_le fun n => hgf n x
#align measure_theory.exists_measurable_le_lintegral_eq MeasureTheory.exists_measurable_le_lintegral_eq
end
/-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions
`φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take
functions `φ : α →ₛ ℝ≥0`. -/
theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) :
∫⁻ a, f a ∂μ =
⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by
rw [lintegral]
refine
le_antisymm (iSup₂_le fun φ hφ => ?_) (iSup_mono' fun φ => ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩)
by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞
· let ψ := φ.map ENNReal.toNNReal
replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal
have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x)
exact
le_iSup_of_le (φ.map ENNReal.toNNReal) (le_iSup_of_le this (ge_of_eq <| lintegral_congr h))
· have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_nmem.1 h
refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_)
obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb)
use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞})
simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const,
ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast,
restrict_const_lintegral]
refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩
simp only [mem_preimage, mem_singleton_iff] at hx
simp only [hx, le_top]
#align measure_theory.lintegral_eq_nnreal MeasureTheory.lintegral_eq_nnreal
theorem exists_simpleFunc_forall_lintegral_sub_lt_of_pos {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ φ : α →ₛ ℝ≥0,
(∀ x, ↑(φ x) ≤ f x) ∧
∀ ψ : α →ₛ ℝ≥0, (∀ x, ↑(ψ x) ≤ f x) → (map (↑) (ψ - φ)).lintegral μ < ε := by
rw [lintegral_eq_nnreal] at h
have := ENNReal.lt_add_right h hε
erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => zero_le _⟩]
simp_rw [lt_iSup_iff, iSup_lt_iff, iSup_le_iff] at this
rcases this with ⟨φ, hle : ∀ x, ↑(φ x) ≤ f x, b, hbφ, hb⟩
refine ⟨φ, hle, fun ψ hψ => ?_⟩
have : (map (↑) φ).lintegral μ ≠ ∞ := ne_top_of_le_ne_top h (by exact le_iSup₂ (α := ℝ≥0∞) φ hle)
rw [← ENNReal.add_lt_add_iff_left this, ← add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add]
refine (hb _ fun x => le_trans ?_ (max_le (hle x) (hψ x))).trans_lt hbφ
norm_cast
simp only [add_apply, sub_apply, add_tsub_eq_max]
rfl
#align measure_theory.exists_simple_func_forall_lintegral_sub_lt_of_pos MeasureTheory.exists_simpleFunc_forall_lintegral_sub_lt_of_pos
theorem iSup_lintegral_le {ι : Sort*} (f : ι → α → ℝ≥0∞) :
⨆ i, ∫⁻ a, f i a ∂μ ≤ ∫⁻ a, ⨆ i, f i a ∂μ := by
simp only [← iSup_apply]
exact (monotone_lintegral μ).le_map_iSup
#align measure_theory.supr_lintegral_le MeasureTheory.iSup_lintegral_le
theorem iSup₂_lintegral_le {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) :
⨆ (i) (j), ∫⁻ a, f i j a ∂μ ≤ ∫⁻ a, ⨆ (i) (j), f i j a ∂μ := by
convert (monotone_lintegral μ).le_map_iSup₂ f with a
simp only [iSup_apply]
#align measure_theory.supr₂_lintegral_le MeasureTheory.iSup₂_lintegral_le
theorem le_iInf_lintegral {ι : Sort*} (f : ι → α → ℝ≥0∞) :
∫⁻ a, ⨅ i, f i a ∂μ ≤ ⨅ i, ∫⁻ a, f i a ∂μ := by
simp only [← iInf_apply]
exact (monotone_lintegral μ).map_iInf_le
#align measure_theory.le_infi_lintegral MeasureTheory.le_iInf_lintegral
theorem le_iInf₂_lintegral {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) :
∫⁻ a, ⨅ (i) (h : ι' i), f i h a ∂μ ≤ ⨅ (i) (h : ι' i), ∫⁻ a, f i h a ∂μ := by
convert (monotone_lintegral μ).map_iInf₂_le f with a
simp only [iInf_apply]
#align measure_theory.le_infi₂_lintegral MeasureTheory.le_iInf₂_lintegral
theorem lintegral_mono_ae {f g : α → ℝ≥0∞} (h : ∀ᵐ a ∂μ, f a ≤ g a) :
∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := by
rcases exists_measurable_superset_of_null h with ⟨t, hts, ht, ht0⟩
have : ∀ᵐ x ∂μ, x ∉ t := measure_zero_iff_ae_nmem.1 ht0
rw [lintegral, lintegral]
refine iSup_le fun s => iSup_le fun hfs => le_iSup_of_le (s.restrict tᶜ) <| le_iSup_of_le ?_ ?_
· intro a
by_cases h : a ∈ t <;>
simp only [restrict_apply s ht.compl, mem_compl_iff, h, not_true, not_false_eq_true,
indicator_of_not_mem, zero_le, not_false_eq_true, indicator_of_mem]
exact le_trans (hfs a) (_root_.by_contradiction fun hnfg => h (hts hnfg))
· refine le_of_eq (SimpleFunc.lintegral_congr <| this.mono fun a hnt => ?_)
by_cases hat : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, hat, not_true,
not_false_eq_true, indicator_of_not_mem, not_false_eq_true, indicator_of_mem]
exact (hnt hat).elim
#align measure_theory.lintegral_mono_ae MeasureTheory.lintegral_mono_ae
theorem set_lintegral_mono_ae {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g)
(hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ :=
lintegral_mono_ae <| (ae_restrict_iff <| measurableSet_le hf hg).2 hfg
#align measure_theory.set_lintegral_mono_ae MeasureTheory.set_lintegral_mono_ae
theorem set_lintegral_mono {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g)
(hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ :=
set_lintegral_mono_ae hf hg (ae_of_all _ hfg)
#align measure_theory.set_lintegral_mono MeasureTheory.set_lintegral_mono
theorem set_lintegral_mono_ae' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s)
(hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ :=
lintegral_mono_ae <| (ae_restrict_iff' hs).2 hfg
theorem set_lintegral_mono' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s)
(hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ :=
set_lintegral_mono_ae' hs (ae_of_all _ hfg)
theorem set_lintegral_le_lintegral (s : Set α) (f : α → ℝ≥0∞) :
∫⁻ x in s, f x ∂μ ≤ ∫⁻ x, f x ∂μ :=
lintegral_mono' Measure.restrict_le_self le_rfl
theorem lintegral_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ :=
le_antisymm (lintegral_mono_ae <| h.le) (lintegral_mono_ae <| h.symm.le)
#align measure_theory.lintegral_congr_ae MeasureTheory.lintegral_congr_ae
theorem lintegral_congr {f g : α → ℝ≥0∞} (h : ∀ a, f a = g a) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by
simp only [h]
#align measure_theory.lintegral_congr MeasureTheory.lintegral_congr
theorem set_lintegral_congr {f : α → ℝ≥0∞} {s t : Set α} (h : s =ᵐ[μ] t) :
∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := by rw [Measure.restrict_congr_set h]
#align measure_theory.set_lintegral_congr MeasureTheory.set_lintegral_congr
theorem set_lintegral_congr_fun {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s)
(hfg : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := by
rw [lintegral_congr_ae]
rw [EventuallyEq]
rwa [ae_restrict_iff' hs]
#align measure_theory.set_lintegral_congr_fun MeasureTheory.set_lintegral_congr_fun
theorem lintegral_ofReal_le_lintegral_nnnorm (f : α → ℝ) :
∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ ∫⁻ x, ‖f x‖₊ ∂μ := by
simp_rw [← ofReal_norm_eq_coe_nnnorm]
refine lintegral_mono fun x => ENNReal.ofReal_le_ofReal ?_
rw [Real.norm_eq_abs]
exact le_abs_self (f x)
#align measure_theory.lintegral_of_real_le_lintegral_nnnorm MeasureTheory.lintegral_ofReal_le_lintegral_nnnorm
theorem lintegral_nnnorm_eq_of_ae_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ᵐ[μ] f) :
∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by
apply lintegral_congr_ae
filter_upwards [h_nonneg] with x hx
rw [Real.nnnorm_of_nonneg hx, ENNReal.ofReal_eq_coe_nnreal hx]
#align measure_theory.lintegral_nnnorm_eq_of_ae_nonneg MeasureTheory.lintegral_nnnorm_eq_of_ae_nonneg
theorem lintegral_nnnorm_eq_of_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ f) :
∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ :=
lintegral_nnnorm_eq_of_ae_nonneg (Filter.eventually_of_forall h_nonneg)
#align measure_theory.lintegral_nnnorm_eq_of_nonneg MeasureTheory.lintegral_nnnorm_eq_of_nonneg
/-- **Monotone convergence theorem** -- sometimes called **Beppo-Levi convergence**.
See `lintegral_iSup_directed` for a more general form. -/
theorem lintegral_iSup {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : Monotone f) :
∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by
set c : ℝ≥0 → ℝ≥0∞ := (↑)
set F := fun a : α => ⨆ n, f n a
refine le_antisymm ?_ (iSup_lintegral_le _)
rw [lintegral_eq_nnreal]
refine iSup_le fun s => iSup_le fun hsf => ?_
refine ENNReal.le_of_forall_lt_one_mul_le fun a ha => ?_
rcases ENNReal.lt_iff_exists_coe.1 ha with ⟨r, rfl, _⟩
have ha : r < 1 := ENNReal.coe_lt_coe.1 ha
let rs := s.map fun a => r * a
have eq_rs : rs.map c = (const α r : α →ₛ ℝ≥0∞) * map c s := rfl
have eq : ∀ p, rs.map c ⁻¹' {p} = ⋃ n, rs.map c ⁻¹' {p} ∩ { a | p ≤ f n a } := by
intro p
rw [← inter_iUnion]; nth_rw 1 [← inter_univ (map c rs ⁻¹' {p})]
refine Set.ext fun x => and_congr_right fun hx => true_iff_iff.2 ?_
by_cases p_eq : p = 0
· simp [p_eq]
simp only [coe_map, mem_preimage, Function.comp_apply, mem_singleton_iff] at hx
subst hx
have : r * s x ≠ 0 := by rwa [Ne, ← ENNReal.coe_eq_zero]
have : s x ≠ 0 := right_ne_zero_of_mul this
have : (rs.map c) x < ⨆ n : ℕ, f n x := by
refine lt_of_lt_of_le (ENNReal.coe_lt_coe.2 ?_) (hsf x)
suffices r * s x < 1 * s x by simpa
exact mul_lt_mul_of_pos_right ha (pos_iff_ne_zero.2 this)
rcases lt_iSup_iff.1 this with ⟨i, hi⟩
exact mem_iUnion.2 ⟨i, le_of_lt hi⟩
have mono : ∀ r : ℝ≥0∞, Monotone fun n => rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a } := by
intro r i j h
refine inter_subset_inter_right _ ?_
simp_rw [subset_def, mem_setOf]
intro x hx
exact le_trans hx (h_mono h x)
have h_meas : ∀ n, MeasurableSet {a : α | map c rs a ≤ f n a} := fun n =>
measurableSet_le (SimpleFunc.measurable _) (hf n)
calc
(r : ℝ≥0∞) * (s.map c).lintegral μ = ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r}) := by
rw [← const_mul_lintegral, eq_rs, SimpleFunc.lintegral]
_ = ∑ r ∈ (rs.map c).range, r * μ (⋃ n, rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by
simp only [(eq _).symm]
_ = ∑ r ∈ (rs.map c).range, ⨆ n, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) :=
(Finset.sum_congr rfl fun x _ => by
rw [measure_iUnion_eq_iSup (mono x).directed_le, ENNReal.mul_iSup])
_ = ⨆ n, ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by
refine ENNReal.finset_sum_iSup_nat fun p i j h ↦ ?_
gcongr _ * μ ?_
exact mono p h
_ ≤ ⨆ n : ℕ, ((rs.map c).restrict { a | (rs.map c) a ≤ f n a }).lintegral μ := by
gcongr with n
rw [restrict_lintegral _ (h_meas n)]
refine le_of_eq (Finset.sum_congr rfl fun r _ => ?_)
congr 2 with a
refine and_congr_right ?_
simp (config := { contextual := true })
_ ≤ ⨆ n, ∫⁻ a, f n a ∂μ := by
simp only [← SimpleFunc.lintegral_eq_lintegral]
gcongr with n a
simp only [map_apply] at h_meas
simp only [coe_map, restrict_apply _ (h_meas _), (· ∘ ·)]
exact indicator_apply_le id
#align measure_theory.lintegral_supr MeasureTheory.lintegral_iSup
/-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence. Version with
ae_measurable functions. -/
theorem lintegral_iSup' {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ)
(h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by
simp_rw [← iSup_apply]
let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Monotone f'
have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_mono
have h_ae_seq_mono : Monotone (aeSeq hf p) := by
intro n m hnm x
by_cases hx : x ∈ aeSeqSet hf p
· exact aeSeq.prop_of_mem_aeSeqSet hf hx hnm
· simp only [aeSeq, hx, if_false, le_rfl]
rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm]
simp_rw [iSup_apply]
rw [lintegral_iSup (aeSeq.measurable hf p) h_ae_seq_mono]
congr with n
exact lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae hf hp n)
#align measure_theory.lintegral_supr' MeasureTheory.lintegral_iSup'
/-- Monotone convergence theorem expressed with limits -/
theorem lintegral_tendsto_of_tendsto_of_monotone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞}
(hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x)
(h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 <| F x)) :
Tendsto (fun n => ∫⁻ x, f n x ∂μ) atTop (𝓝 <| ∫⁻ x, F x ∂μ) := by
have : Monotone fun n => ∫⁻ x, f n x ∂μ := fun i j hij =>
lintegral_mono_ae (h_mono.mono fun x hx => hx hij)
suffices key : ∫⁻ x, F x ∂μ = ⨆ n, ∫⁻ x, f n x ∂μ by
rw [key]
exact tendsto_atTop_iSup this
rw [← lintegral_iSup' hf h_mono]
refine lintegral_congr_ae ?_
filter_upwards [h_mono, h_tendsto] with _ hx_mono hx_tendsto using
tendsto_nhds_unique hx_tendsto (tendsto_atTop_iSup hx_mono)
#align measure_theory.lintegral_tendsto_of_tendsto_of_monotone MeasureTheory.lintegral_tendsto_of_tendsto_of_monotone
theorem lintegral_eq_iSup_eapprox_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) :
∫⁻ a, f a ∂μ = ⨆ n, (eapprox f n).lintegral μ :=
calc
∫⁻ a, f a ∂μ = ∫⁻ a, ⨆ n, (eapprox f n : α → ℝ≥0∞) a ∂μ := by
congr; ext a; rw [iSup_eapprox_apply f hf]
_ = ⨆ n, ∫⁻ a, (eapprox f n : α → ℝ≥0∞) a ∂μ := by
apply lintegral_iSup
· measurability
· intro i j h
exact monotone_eapprox f h
_ = ⨆ n, (eapprox f n).lintegral μ := by
congr; ext n; rw [(eapprox f n).lintegral_eq_lintegral]
#align measure_theory.lintegral_eq_supr_eapprox_lintegral MeasureTheory.lintegral_eq_iSup_eapprox_lintegral
/-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. This lemma states this fact in terms of `ε` and `δ`. -/
theorem exists_pos_set_lintegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞}
(hε : ε ≠ 0) : ∃ δ > 0, ∀ s, μ s < δ → ∫⁻ x in s, f x ∂μ < ε := by
rcases exists_between (pos_iff_ne_zero.mpr hε) with ⟨ε₂, hε₂0, hε₂ε⟩
rcases exists_between hε₂0 with ⟨ε₁, hε₁0, hε₁₂⟩
rcases exists_simpleFunc_forall_lintegral_sub_lt_of_pos h hε₁0.ne' with ⟨φ, _, hφ⟩
rcases φ.exists_forall_le with ⟨C, hC⟩
use (ε₂ - ε₁) / C, ENNReal.div_pos_iff.2 ⟨(tsub_pos_iff_lt.2 hε₁₂).ne', ENNReal.coe_ne_top⟩
refine fun s hs => lt_of_le_of_lt ?_ hε₂ε
simp only [lintegral_eq_nnreal, iSup_le_iff]
intro ψ hψ
calc
(map (↑) ψ).lintegral (μ.restrict s) ≤
(map (↑) φ).lintegral (μ.restrict s) + (map (↑) (ψ - φ)).lintegral (μ.restrict s) := by
rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add]
refine SimpleFunc.lintegral_mono (fun x => ?_) le_rfl
simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add,
SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)]
_ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by
gcongr
refine le_trans ?_ (hφ _ hψ).le
exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self
_ ≤ (SimpleFunc.const α (C : ℝ≥0∞)).lintegral (μ.restrict s) + ε₁ := by
gcongr
exact SimpleFunc.lintegral_mono (fun x ↦ ENNReal.coe_le_coe.2 (hC x)) le_rfl
_ = C * μ s + ε₁ := by
simp only [← SimpleFunc.lintegral_eq_lintegral, coe_const, lintegral_const,
Measure.restrict_apply, MeasurableSet.univ, univ_inter, Function.const]
_ ≤ C * ((ε₂ - ε₁) / C) + ε₁ := by gcongr
_ ≤ ε₂ - ε₁ + ε₁ := by gcongr; apply mul_div_le
_ = ε₂ := tsub_add_cancel_of_le hε₁₂.le
#align measure_theory.exists_pos_set_lintegral_lt_of_measure_lt MeasureTheory.exists_pos_set_lintegral_lt_of_measure_lt
/-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
theorem tendsto_set_lintegral_zero {ι} {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {l : Filter ι}
{s : ι → Set α} (hl : Tendsto (μ ∘ s) l (𝓝 0)) :
Tendsto (fun i => ∫⁻ x in s i, f x ∂μ) l (𝓝 0) := by
simp only [ENNReal.nhds_zero, tendsto_iInf, tendsto_principal, mem_Iio,
← pos_iff_ne_zero] at hl ⊢
intro ε ε0
rcases exists_pos_set_lintegral_lt_of_measure_lt h ε0.ne' with ⟨δ, δ0, hδ⟩
exact (hl δ δ0).mono fun i => hδ _
#align measure_theory.tendsto_set_lintegral_zero MeasureTheory.tendsto_set_lintegral_zero
/-- The sum of the lower Lebesgue integrals of two functions is less than or equal to the integral
of their sum. The other inequality needs one of these functions to be (a.e.-)measurable. -/
theorem le_lintegral_add (f g : α → ℝ≥0∞) :
∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ ≤ ∫⁻ a, f a + g a ∂μ := by
simp only [lintegral]
refine ENNReal.biSup_add_biSup_le' (p := fun h : α →ₛ ℝ≥0∞ => h ≤ f)
(q := fun h : α →ₛ ℝ≥0∞ => h ≤ g) ⟨0, zero_le f⟩ ⟨0, zero_le g⟩ fun f' hf' g' hg' => ?_
exact le_iSup₂_of_le (f' + g') (add_le_add hf' hg') (add_lintegral _ _).ge
#align measure_theory.le_lintegral_add MeasureTheory.le_lintegral_add
-- Use stronger lemmas `lintegral_add_left`/`lintegral_add_right` instead
theorem lintegral_add_aux {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) :
∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ :=
calc
∫⁻ a, f a + g a ∂μ =
∫⁻ a, (⨆ n, (eapprox f n : α → ℝ≥0∞) a) + ⨆ n, (eapprox g n : α → ℝ≥0∞) a ∂μ := by
simp only [iSup_eapprox_apply, hf, hg]
_ = ∫⁻ a, ⨆ n, (eapprox f n + eapprox g n : α → ℝ≥0∞) a ∂μ := by
congr; funext a
rw [ENNReal.iSup_add_iSup_of_monotone]
· simp only [Pi.add_apply]
· intro i j h
exact monotone_eapprox _ h a
· intro i j h
exact monotone_eapprox _ h a
_ = ⨆ n, (eapprox f n).lintegral μ + (eapprox g n).lintegral μ := by
rw [lintegral_iSup]
· congr
funext n
rw [← SimpleFunc.add_lintegral, ← SimpleFunc.lintegral_eq_lintegral]
simp only [Pi.add_apply, SimpleFunc.coe_add]
· measurability
· intro i j h a
dsimp
gcongr <;> exact monotone_eapprox _ h _
_ = (⨆ n, (eapprox f n).lintegral μ) + ⨆ n, (eapprox g n).lintegral μ := by
refine (ENNReal.iSup_add_iSup_of_monotone ?_ ?_).symm <;>
· intro i j h
exact SimpleFunc.lintegral_mono (monotone_eapprox _ h) le_rfl
_ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by
rw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral hg]
#align measure_theory.lintegral_add_aux MeasureTheory.lintegral_add_aux
/-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue
integral of `f + g` equals the sum of integrals. This lemma assumes that `f` is integrable, see also
`MeasureTheory.lintegral_add_right` and primed versions of these lemmas. -/
@[simp]
theorem lintegral_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) :
∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by
refine le_antisymm ?_ (le_lintegral_add _ _)
rcases exists_measurable_le_lintegral_eq μ fun a => f a + g a with ⟨φ, hφm, hφ_le, hφ_eq⟩
calc
∫⁻ a, f a + g a ∂μ = ∫⁻ a, φ a ∂μ := hφ_eq
_ ≤ ∫⁻ a, f a + (φ a - f a) ∂μ := lintegral_mono fun a => le_add_tsub
_ = ∫⁻ a, f a ∂μ + ∫⁻ a, φ a - f a ∂μ := lintegral_add_aux hf (hφm.sub hf)
_ ≤ ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ :=
add_le_add_left (lintegral_mono fun a => tsub_le_iff_left.2 <| hφ_le a) _
#align measure_theory.lintegral_add_left MeasureTheory.lintegral_add_left
theorem lintegral_add_left' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (g : α → ℝ≥0∞) :
∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by
rw [lintegral_congr_ae hf.ae_eq_mk, ← lintegral_add_left hf.measurable_mk,
lintegral_congr_ae (hf.ae_eq_mk.add (ae_eq_refl g))]
#align measure_theory.lintegral_add_left' MeasureTheory.lintegral_add_left'
theorem lintegral_add_right' (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) :
∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by
simpa only [add_comm] using lintegral_add_left' hg f
#align measure_theory.lintegral_add_right' MeasureTheory.lintegral_add_right'
/-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue
integral of `f + g` equals the sum of integrals. This lemma assumes that `g` is integrable, see also
`MeasureTheory.lintegral_add_left` and primed versions of these lemmas. -/
@[simp]
theorem lintegral_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) :
∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ :=
lintegral_add_right' f hg.aemeasurable
#align measure_theory.lintegral_add_right MeasureTheory.lintegral_add_right
@[simp]
theorem lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂c • μ = c * ∫⁻ a, f a ∂μ := by
simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_smul, ENNReal.mul_iSup, smul_eq_mul]
#align measure_theory.lintegral_smul_measure MeasureTheory.lintegral_smul_measure
lemma set_lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) (s : Set α) :
∫⁻ a in s, f a ∂(c • μ) = c * ∫⁻ a in s, f a ∂μ := by
rw [Measure.restrict_smul, lintegral_smul_measure]
@[simp]
theorem lintegral_sum_measure {m : MeasurableSpace α} {ι} (f : α → ℝ≥0∞) (μ : ι → Measure α) :
∫⁻ a, f a ∂Measure.sum μ = ∑' i, ∫⁻ a, f a ∂μ i := by
simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_sum, ENNReal.tsum_eq_iSup_sum]
rw [iSup_comm]
congr; funext s
induction' s using Finset.induction_on with i s hi hs
· simp
simp only [Finset.sum_insert hi, ← hs]
refine (ENNReal.iSup_add_iSup ?_).symm
intro φ ψ
exact
⟨⟨φ ⊔ ψ, fun x => sup_le (φ.2 x) (ψ.2 x)⟩,
add_le_add (SimpleFunc.lintegral_mono le_sup_left le_rfl)
(Finset.sum_le_sum fun j _ => SimpleFunc.lintegral_mono le_sup_right le_rfl)⟩
#align measure_theory.lintegral_sum_measure MeasureTheory.lintegral_sum_measure
theorem hasSum_lintegral_measure {ι} {_ : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : ι → Measure α) :
HasSum (fun i => ∫⁻ a, f a ∂μ i) (∫⁻ a, f a ∂Measure.sum μ) :=
(lintegral_sum_measure f μ).symm ▸ ENNReal.summable.hasSum
#align measure_theory.has_sum_lintegral_measure MeasureTheory.hasSum_lintegral_measure
@[simp]
theorem lintegral_add_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ ν : Measure α) :
∫⁻ a, f a ∂(μ + ν) = ∫⁻ a, f a ∂μ + ∫⁻ a, f a ∂ν := by
simpa [tsum_fintype] using lintegral_sum_measure f fun b => cond b μ ν
#align measure_theory.lintegral_add_measure MeasureTheory.lintegral_add_measure
@[simp]
theorem lintegral_finset_sum_measure {ι} {m : MeasurableSpace α} (s : Finset ι) (f : α → ℝ≥0∞)
(μ : ι → Measure α) : ∫⁻ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫⁻ a, f a ∂μ i := by
rw [← Measure.sum_coe_finset, lintegral_sum_measure, ← Finset.tsum_subtype']
simp only [Finset.coe_sort_coe]
#align measure_theory.lintegral_finset_sum_measure MeasureTheory.lintegral_finset_sum_measure
@[simp]
theorem lintegral_zero_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) :
∫⁻ a, f a ∂(0 : Measure α) = 0 := by
simp [lintegral]
#align measure_theory.lintegral_zero_measure MeasureTheory.lintegral_zero_measure
@[simp]
theorem lintegral_of_isEmpty {α} [MeasurableSpace α] [IsEmpty α] (μ : Measure α) (f : α → ℝ≥0∞) :
∫⁻ x, f x ∂μ = 0 := by
have : Subsingleton (Measure α) := inferInstance
convert lintegral_zero_measure f
theorem set_lintegral_empty (f : α → ℝ≥0∞) : ∫⁻ x in ∅, f x ∂μ = 0 := by
rw [Measure.restrict_empty, lintegral_zero_measure]
#align measure_theory.set_lintegral_empty MeasureTheory.set_lintegral_empty
theorem set_lintegral_univ (f : α → ℝ≥0∞) : ∫⁻ x in univ, f x ∂μ = ∫⁻ x, f x ∂μ := by
rw [Measure.restrict_univ]
#align measure_theory.set_lintegral_univ MeasureTheory.set_lintegral_univ
theorem set_lintegral_measure_zero (s : Set α) (f : α → ℝ≥0∞) (hs' : μ s = 0) :
∫⁻ x in s, f x ∂μ = 0 := by
convert lintegral_zero_measure _
exact Measure.restrict_eq_zero.2 hs'
#align measure_theory.set_lintegral_measure_zero MeasureTheory.set_lintegral_measure_zero
theorem lintegral_finset_sum' (s : Finset β) {f : β → α → ℝ≥0∞}
(hf : ∀ b ∈ s, AEMeasurable (f b) μ) :
∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := by
induction' s using Finset.induction_on with a s has ih
· simp
· simp only [Finset.sum_insert has]
rw [Finset.forall_mem_insert] at hf
rw [lintegral_add_left' hf.1, ih hf.2]
#align measure_theory.lintegral_finset_sum' MeasureTheory.lintegral_finset_sum'
theorem lintegral_finset_sum (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, Measurable (f b)) :
∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ :=
lintegral_finset_sum' s fun b hb => (hf b hb).aemeasurable
#align measure_theory.lintegral_finset_sum MeasureTheory.lintegral_finset_sum
@[simp]
theorem lintegral_const_mul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) :
∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ :=
calc
∫⁻ a, r * f a ∂μ = ∫⁻ a, ⨆ n, (const α r * eapprox f n) a ∂μ := by
congr
funext a
rw [← iSup_eapprox_apply f hf, ENNReal.mul_iSup]
simp
_ = ⨆ n, r * (eapprox f n).lintegral μ := by
rw [lintegral_iSup]
· congr
funext n
rw [← SimpleFunc.const_mul_lintegral, ← SimpleFunc.lintegral_eq_lintegral]
· intro n
exact SimpleFunc.measurable _
· intro i j h a
exact mul_le_mul_left' (monotone_eapprox _ h _) _
_ = r * ∫⁻ a, f a ∂μ := by rw [← ENNReal.mul_iSup, lintegral_eq_iSup_eapprox_lintegral hf]
#align measure_theory.lintegral_const_mul MeasureTheory.lintegral_const_mul
| Mathlib/MeasureTheory/Integral/Lebesgue.lean | 689 | 694 | theorem lintegral_const_mul'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) :
∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by |
have A : ∫⁻ a, f a ∂μ = ∫⁻ a, hf.mk f a ∂μ := lintegral_congr_ae hf.ae_eq_mk
have B : ∫⁻ a, r * f a ∂μ = ∫⁻ a, r * hf.mk f a ∂μ :=
lintegral_congr_ae (EventuallyEq.fun_comp hf.ae_eq_mk _)
rw [A, B, lintegral_const_mul _ hf.measurable_mk]
|
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Basic
import Mathlib.Topology.MetricSpace.Thickening
import Mathlib.Topology.MetricSpace.IsometricSMul
#align_import analysis.normed.group.pointwise from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328"
/-!
# Properties of pointwise addition of sets in normed groups
We explore the relationships between pointwise addition of sets in normed groups, and the norm.
Notably, we show that the sum of bounded sets remain bounded.
-/
open Metric Set Pointwise Topology
variable {E : Type*}
section SeminormedGroup
variable [SeminormedGroup E] {ε δ : ℝ} {s t : Set E} {x y : E}
-- note: we can't use `LipschitzOnWith.isBounded_image2` here without adding `[IsometricSMul E E]`
@[to_additive]
theorem Bornology.IsBounded.mul (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s * t) := by
obtain ⟨Rs, hRs⟩ : ∃ R, ∀ x ∈ s, ‖x‖ ≤ R := hs.exists_norm_le'
obtain ⟨Rt, hRt⟩ : ∃ R, ∀ x ∈ t, ‖x‖ ≤ R := ht.exists_norm_le'
refine isBounded_iff_forall_norm_le'.2 ⟨Rs + Rt, ?_⟩
rintro z ⟨x, hx, y, hy, rfl⟩
exact norm_mul_le_of_le (hRs x hx) (hRt y hy)
#align metric.bounded.mul Bornology.IsBounded.mul
#align metric.bounded.add Bornology.IsBounded.add
@[to_additive]
theorem Bornology.IsBounded.of_mul (hst : IsBounded (s * t)) : IsBounded s ∨ IsBounded t :=
AntilipschitzWith.isBounded_of_image2_left _ (fun x => (isometry_mul_right x).antilipschitz) hst
#align metric.bounded.of_mul Bornology.IsBounded.of_mul
#align metric.bounded.of_add Bornology.IsBounded.of_add
@[to_additive]
theorem Bornology.IsBounded.inv : IsBounded s → IsBounded s⁻¹ := by
simp_rw [isBounded_iff_forall_norm_le', ← image_inv, forall_mem_image, norm_inv']
exact id
#align metric.bounded.inv Bornology.IsBounded.inv
#align metric.bounded.neg Bornology.IsBounded.neg
@[to_additive]
theorem Bornology.IsBounded.div (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s / t) :=
div_eq_mul_inv s t ▸ hs.mul ht.inv
#align metric.bounded.div Bornology.IsBounded.div
#align metric.bounded.sub Bornology.IsBounded.sub
end SeminormedGroup
section SeminormedCommGroup
variable [SeminormedCommGroup E] {ε δ : ℝ} {s t : Set E} {x y : E}
section EMetric
open EMetric
@[to_additive (attr := simp)]
theorem infEdist_inv_inv (x : E) (s : Set E) : infEdist x⁻¹ s⁻¹ = infEdist x s := by
rw [← image_inv, infEdist_image isometry_inv]
#align inf_edist_inv_inv infEdist_inv_inv
#align inf_edist_neg_neg infEdist_neg_neg
@[to_additive]
theorem infEdist_inv (x : E) (s : Set E) : infEdist x⁻¹ s = infEdist x s⁻¹ := by
rw [← infEdist_inv_inv, inv_inv]
#align inf_edist_inv infEdist_inv
#align inf_edist_neg infEdist_neg
@[to_additive]
theorem ediam_mul_le (x y : Set E) : EMetric.diam (x * y) ≤ EMetric.diam x + EMetric.diam y :=
(LipschitzOnWith.ediam_image2_le (· * ·) _ _
(fun _ _ => (isometry_mul_right _).lipschitz.lipschitzOnWith _) fun _ _ =>
(isometry_mul_left _).lipschitz.lipschitzOnWith _).trans_eq <|
by simp only [ENNReal.coe_one, one_mul]
#align ediam_mul_le ediam_mul_le
#align ediam_add_le ediam_add_le
end EMetric
variable (ε δ s t x y)
@[to_additive (attr := simp)]
theorem inv_thickening : (thickening δ s)⁻¹ = thickening δ s⁻¹ := by
simp_rw [thickening, ← infEdist_inv]
rfl
#align inv_thickening inv_thickening
#align neg_thickening neg_thickening
@[to_additive (attr := simp)]
theorem inv_cthickening : (cthickening δ s)⁻¹ = cthickening δ s⁻¹ := by
simp_rw [cthickening, ← infEdist_inv]
rfl
#align inv_cthickening inv_cthickening
#align neg_cthickening neg_cthickening
@[to_additive (attr := simp)]
theorem inv_ball : (ball x δ)⁻¹ = ball x⁻¹ δ := (IsometryEquiv.inv E).preimage_ball x δ
#align inv_ball inv_ball
#align neg_ball neg_ball
@[to_additive (attr := simp)]
theorem inv_closedBall : (closedBall x δ)⁻¹ = closedBall x⁻¹ δ :=
(IsometryEquiv.inv E).preimage_closedBall x δ
#align inv_closed_ball inv_closedBall
#align neg_closed_ball neg_closedBall
@[to_additive]
theorem singleton_mul_ball : {x} * ball y δ = ball (x * y) δ := by
simp only [preimage_mul_ball, image_mul_left, singleton_mul, div_inv_eq_mul, mul_comm y x]
#align singleton_mul_ball singleton_mul_ball
#align singleton_add_ball singleton_add_ball
@[to_additive]
theorem singleton_div_ball : {x} / ball y δ = ball (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_ball, singleton_mul_ball]
#align singleton_div_ball singleton_div_ball
#align singleton_sub_ball singleton_sub_ball
@[to_additive]
theorem ball_mul_singleton : ball x δ * {y} = ball (x * y) δ := by
rw [mul_comm, singleton_mul_ball, mul_comm y]
#align ball_mul_singleton ball_mul_singleton
#align ball_add_singleton ball_add_singleton
@[to_additive]
theorem ball_div_singleton : ball x δ / {y} = ball (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_singleton, ball_mul_singleton]
#align ball_div_singleton ball_div_singleton
#align ball_sub_singleton ball_sub_singleton
@[to_additive]
theorem singleton_mul_ball_one : {x} * ball 1 δ = ball x δ := by simp
#align singleton_mul_ball_one singleton_mul_ball_one
#align singleton_add_ball_zero singleton_add_ball_zero
@[to_additive]
theorem singleton_div_ball_one : {x} / ball 1 δ = ball x δ := by
rw [singleton_div_ball, div_one]
#align singleton_div_ball_one singleton_div_ball_one
#align singleton_sub_ball_zero singleton_sub_ball_zero
@[to_additive]
theorem ball_one_mul_singleton : ball 1 δ * {x} = ball x δ := by simp [ball_mul_singleton]
#align ball_one_mul_singleton ball_one_mul_singleton
#align ball_zero_add_singleton ball_zero_add_singleton
@[to_additive]
theorem ball_one_div_singleton : ball 1 δ / {x} = ball x⁻¹ δ := by
rw [ball_div_singleton, one_div]
#align ball_one_div_singleton ball_one_div_singleton
#align ball_zero_sub_singleton ball_zero_sub_singleton
@[to_additive]
theorem smul_ball_one : x • ball (1 : E) δ = ball x δ := by
rw [smul_ball, smul_eq_mul, mul_one]
#align smul_ball_one smul_ball_one
#align vadd_ball_zero vadd_ball_zero
@[to_additive (attr := simp 1100)]
theorem singleton_mul_closedBall : {x} * closedBall y δ = closedBall (x * y) δ := by
simp_rw [singleton_mul, ← smul_eq_mul, image_smul, smul_closedBall]
#align singleton_mul_closed_ball singleton_mul_closedBall
#align singleton_add_closed_ball singleton_add_closedBall
@[to_additive (attr := simp 1100)]
theorem singleton_div_closedBall : {x} / closedBall y δ = closedBall (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_closedBall, singleton_mul_closedBall]
#align singleton_div_closed_ball singleton_div_closedBall
#align singleton_sub_closed_ball singleton_sub_closedBall
@[to_additive (attr := simp 1100)]
| Mathlib/Analysis/Normed/Group/Pointwise.lean | 183 | 184 | theorem closedBall_mul_singleton : closedBall x δ * {y} = closedBall (x * y) δ := by |
simp [mul_comm _ {y}, mul_comm y]
|
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang
-/
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.BigOperators.RingEquiv
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.Algebra.Module.Pi
import Mathlib.Algebra.Star.BigOperators
import Mathlib.Algebra.Star.Module
import Mathlib.Algebra.Star.Pi
import Mathlib.Data.Fintype.BigOperators
import Mathlib.GroupTheory.GroupAction.BigOperators
#align_import data.matrix.basic from "leanprover-community/mathlib"@"eba5bb3155cab51d80af00e8d7d69fa271b1302b"
/-!
# Matrices
This file defines basic properties of matrices.
Matrices with rows indexed by `m`, columns indexed by `n`, and entries of type `α` are represented
with `Matrix m n α`. For the typical approach of counting rows and columns,
`Matrix (Fin m) (Fin n) α` can be used.
## Notation
The locale `Matrix` gives the following notation:
* `⬝ᵥ` for `Matrix.dotProduct`
* `*ᵥ` for `Matrix.mulVec`
* `ᵥ*` for `Matrix.vecMul`
* `ᵀ` for `Matrix.transpose`
* `ᴴ` for `Matrix.conjTranspose`
## Implementation notes
For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix
to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the
form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n α)`, as these are not recognized by Lean
as having the right type. Instead, `Matrix.of` should be used.
## TODO
Under various conditions, multiplication of infinite matrices makes sense.
These have not yet been implemented.
-/
universe u u' v w
/-- `Matrix m n R` is the type of matrices with entries in `R`, whose rows are indexed by `m`
and whose columns are indexed by `n`. -/
def Matrix (m : Type u) (n : Type u') (α : Type v) : Type max u u' v :=
m → n → α
#align matrix Matrix
variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*}
variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*}
namespace Matrix
section Ext
variable {M N : Matrix m n α}
theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N :=
⟨fun h => funext fun i => funext <| h i, fun h => by simp [h]⟩
#align matrix.ext_iff Matrix.ext_iff
@[ext]
theorem ext : (∀ i j, M i j = N i j) → M = N :=
ext_iff.mp
#align matrix.ext Matrix.ext
end Ext
/-- Cast a function into a matrix.
The two sides of the equivalence are definitionally equal types. We want to use an explicit cast
to distinguish the types because `Matrix` has different instances to pi types (such as `Pi.mul`,
which performs elementwise multiplication, vs `Matrix.mul`).
If you are defining a matrix, in terms of its entries, use `of (fun i j ↦ _)`. The
purpose of this approach is to ensure that terms of the form `(fun i j ↦ _) * (fun i j ↦ _)` do not
appear, as the type of `*` can be misleading.
Porting note: In Lean 3, it is also safe to use pattern matching in a definition as `| i j := _`,
which can only be unfolded when fully-applied. leanprover/lean4#2042 means this does not
(currently) work in Lean 4.
-/
def of : (m → n → α) ≃ Matrix m n α :=
Equiv.refl _
#align matrix.of Matrix.of
@[simp]
theorem of_apply (f : m → n → α) (i j) : of f i j = f i j :=
rfl
#align matrix.of_apply Matrix.of_apply
@[simp]
theorem of_symm_apply (f : Matrix m n α) (i j) : of.symm f i j = f i j :=
rfl
#align matrix.of_symm_apply Matrix.of_symm_apply
/-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`.
This is available in bundled forms as:
* `AddMonoidHom.mapMatrix`
* `LinearMap.mapMatrix`
* `RingHom.mapMatrix`
* `AlgHom.mapMatrix`
* `Equiv.mapMatrix`
* `AddEquiv.mapMatrix`
* `LinearEquiv.mapMatrix`
* `RingEquiv.mapMatrix`
* `AlgEquiv.mapMatrix`
-/
def map (M : Matrix m n α) (f : α → β) : Matrix m n β :=
of fun i j => f (M i j)
#align matrix.map Matrix.map
@[simp]
theorem map_apply {M : Matrix m n α} {f : α → β} {i : m} {j : n} : M.map f i j = f (M i j) :=
rfl
#align matrix.map_apply Matrix.map_apply
@[simp]
theorem map_id (M : Matrix m n α) : M.map id = M := by
ext
rfl
#align matrix.map_id Matrix.map_id
@[simp]
theorem map_id' (M : Matrix m n α) : M.map (·) = M := map_id M
@[simp]
theorem map_map {M : Matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} :
(M.map f).map g = M.map (g ∘ f) := by
ext
rfl
#align matrix.map_map Matrix.map_map
theorem map_injective {f : α → β} (hf : Function.Injective f) :
Function.Injective fun M : Matrix m n α => M.map f := fun _ _ h =>
ext fun i j => hf <| ext_iff.mpr h i j
#align matrix.map_injective Matrix.map_injective
/-- The transpose of a matrix. -/
def transpose (M : Matrix m n α) : Matrix n m α :=
of fun x y => M y x
#align matrix.transpose Matrix.transpose
-- TODO: set as an equation lemma for `transpose`, see mathlib4#3024
@[simp]
theorem transpose_apply (M : Matrix m n α) (i j) : transpose M i j = M j i :=
rfl
#align matrix.transpose_apply Matrix.transpose_apply
@[inherit_doc]
scoped postfix:1024 "ᵀ" => Matrix.transpose
/-- The conjugate transpose of a matrix defined in term of `star`. -/
def conjTranspose [Star α] (M : Matrix m n α) : Matrix n m α :=
M.transpose.map star
#align matrix.conj_transpose Matrix.conjTranspose
@[inherit_doc]
scoped postfix:1024 "ᴴ" => Matrix.conjTranspose
instance inhabited [Inhabited α] : Inhabited (Matrix m n α) :=
inferInstanceAs <| Inhabited <| m → n → α
-- Porting note: new, Lean3 found this automatically
instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) :=
Fintype.decidablePiFintype
instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] :
Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α))
instance {n m} [Finite m] [Finite n] (α) [Finite α] :
Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α))
instance add [Add α] : Add (Matrix m n α) :=
Pi.instAdd
instance addSemigroup [AddSemigroup α] : AddSemigroup (Matrix m n α) :=
Pi.addSemigroup
instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (Matrix m n α) :=
Pi.addCommSemigroup
instance zero [Zero α] : Zero (Matrix m n α) :=
Pi.instZero
instance addZeroClass [AddZeroClass α] : AddZeroClass (Matrix m n α) :=
Pi.addZeroClass
instance addMonoid [AddMonoid α] : AddMonoid (Matrix m n α) :=
Pi.addMonoid
instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (Matrix m n α) :=
Pi.addCommMonoid
instance neg [Neg α] : Neg (Matrix m n α) :=
Pi.instNeg
instance sub [Sub α] : Sub (Matrix m n α) :=
Pi.instSub
instance addGroup [AddGroup α] : AddGroup (Matrix m n α) :=
Pi.addGroup
instance addCommGroup [AddCommGroup α] : AddCommGroup (Matrix m n α) :=
Pi.addCommGroup
instance unique [Unique α] : Unique (Matrix m n α) :=
Pi.unique
instance subsingleton [Subsingleton α] : Subsingleton (Matrix m n α) :=
inferInstanceAs <| Subsingleton <| m → n → α
instance nonempty [Nonempty m] [Nonempty n] [Nontrivial α] : Nontrivial (Matrix m n α) :=
Function.nontrivial
instance smul [SMul R α] : SMul R (Matrix m n α) :=
Pi.instSMul
instance smulCommClass [SMul R α] [SMul S α] [SMulCommClass R S α] :
SMulCommClass R S (Matrix m n α) :=
Pi.smulCommClass
instance isScalarTower [SMul R S] [SMul R α] [SMul S α] [IsScalarTower R S α] :
IsScalarTower R S (Matrix m n α) :=
Pi.isScalarTower
instance isCentralScalar [SMul R α] [SMul Rᵐᵒᵖ α] [IsCentralScalar R α] :
IsCentralScalar R (Matrix m n α) :=
Pi.isCentralScalar
instance mulAction [Monoid R] [MulAction R α] : MulAction R (Matrix m n α) :=
Pi.mulAction _
instance distribMulAction [Monoid R] [AddMonoid α] [DistribMulAction R α] :
DistribMulAction R (Matrix m n α) :=
Pi.distribMulAction _
instance module [Semiring R] [AddCommMonoid α] [Module R α] : Module R (Matrix m n α) :=
Pi.module _ _ _
-- Porting note (#10756): added the following section with simp lemmas because `simp` fails
-- to apply the corresponding lemmas in the namespace `Pi`.
-- (e.g. `Pi.zero_apply` used on `OfNat.ofNat 0 i j`)
section
@[simp]
theorem zero_apply [Zero α] (i : m) (j : n) : (0 : Matrix m n α) i j = 0 := rfl
@[simp]
theorem add_apply [Add α] (A B : Matrix m n α) (i : m) (j : n) :
(A + B) i j = (A i j) + (B i j) := rfl
@[simp]
theorem smul_apply [SMul β α] (r : β) (A : Matrix m n α) (i : m) (j : n) :
(r • A) i j = r • (A i j) := rfl
@[simp]
theorem sub_apply [Sub α] (A B : Matrix m n α) (i : m) (j : n) :
(A - B) i j = (A i j) - (B i j) := rfl
@[simp]
theorem neg_apply [Neg α] (A : Matrix m n α) (i : m) (j : n) :
(-A) i j = -(A i j) := rfl
end
/-! simp-normal form pulls `of` to the outside. -/
@[simp]
theorem of_zero [Zero α] : of (0 : m → n → α) = 0 :=
rfl
#align matrix.of_zero Matrix.of_zero
@[simp]
theorem of_add_of [Add α] (f g : m → n → α) : of f + of g = of (f + g) :=
rfl
#align matrix.of_add_of Matrix.of_add_of
@[simp]
theorem of_sub_of [Sub α] (f g : m → n → α) : of f - of g = of (f - g) :=
rfl
#align matrix.of_sub_of Matrix.of_sub_of
@[simp]
theorem neg_of [Neg α] (f : m → n → α) : -of f = of (-f) :=
rfl
#align matrix.neg_of Matrix.neg_of
@[simp]
theorem smul_of [SMul R α] (r : R) (f : m → n → α) : r • of f = of (r • f) :=
rfl
#align matrix.smul_of Matrix.smul_of
@[simp]
protected theorem map_zero [Zero α] [Zero β] (f : α → β) (h : f 0 = 0) :
(0 : Matrix m n α).map f = 0 := by
ext
simp [h]
#align matrix.map_zero Matrix.map_zero
protected theorem map_add [Add α] [Add β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂)
(M N : Matrix m n α) : (M + N).map f = M.map f + N.map f :=
ext fun _ _ => hf _ _
#align matrix.map_add Matrix.map_add
protected theorem map_sub [Sub α] [Sub β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ - a₂) = f a₁ - f a₂)
(M N : Matrix m n α) : (M - N).map f = M.map f - N.map f :=
ext fun _ _ => hf _ _
#align matrix.map_sub Matrix.map_sub
theorem map_smul [SMul R α] [SMul R β] (f : α → β) (r : R) (hf : ∀ a, f (r • a) = r • f a)
(M : Matrix m n α) : (r • M).map f = r • M.map f :=
ext fun _ _ => hf _
#align matrix.map_smul Matrix.map_smul
/-- The scalar action via `Mul.toSMul` is transformed by the same map as the elements
of the matrix, when `f` preserves multiplication. -/
theorem map_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α)
(hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (r • A).map f = f r • A.map f :=
ext fun _ _ => hf _ _
#align matrix.map_smul' Matrix.map_smul'
/-- The scalar action via `mul.toOppositeSMul` is transformed by the same map as the
elements of the matrix, when `f` preserves multiplication. -/
theorem map_op_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α)
(hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) :
(MulOpposite.op r • A).map f = MulOpposite.op (f r) • A.map f :=
ext fun _ _ => hf _ _
#align matrix.map_op_smul' Matrix.map_op_smul'
theorem _root_.IsSMulRegular.matrix [SMul R S] {k : R} (hk : IsSMulRegular S k) :
IsSMulRegular (Matrix m n S) k :=
IsSMulRegular.pi fun _ => IsSMulRegular.pi fun _ => hk
#align is_smul_regular.matrix IsSMulRegular.matrix
theorem _root_.IsLeftRegular.matrix [Mul α] {k : α} (hk : IsLeftRegular k) :
IsSMulRegular (Matrix m n α) k :=
hk.isSMulRegular.matrix
#align is_left_regular.matrix IsLeftRegular.matrix
instance subsingleton_of_empty_left [IsEmpty m] : Subsingleton (Matrix m n α) :=
⟨fun M N => by
ext i
exact isEmptyElim i⟩
#align matrix.subsingleton_of_empty_left Matrix.subsingleton_of_empty_left
instance subsingleton_of_empty_right [IsEmpty n] : Subsingleton (Matrix m n α) :=
⟨fun M N => by
ext i j
exact isEmptyElim j⟩
#align matrix.subsingleton_of_empty_right Matrix.subsingleton_of_empty_right
end Matrix
open Matrix
namespace Matrix
section Diagonal
variable [DecidableEq n]
/-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0`
if `i ≠ j`.
Note that bundled versions exist as:
* `Matrix.diagonalAddMonoidHom`
* `Matrix.diagonalLinearMap`
* `Matrix.diagonalRingHom`
* `Matrix.diagonalAlgHom`
-/
def diagonal [Zero α] (d : n → α) : Matrix n n α :=
of fun i j => if i = j then d i else 0
#align matrix.diagonal Matrix.diagonal
-- TODO: set as an equation lemma for `diagonal`, see mathlib4#3024
theorem diagonal_apply [Zero α] (d : n → α) (i j) : diagonal d i j = if i = j then d i else 0 :=
rfl
#align matrix.diagonal_apply Matrix.diagonal_apply
@[simp]
theorem diagonal_apply_eq [Zero α] (d : n → α) (i : n) : (diagonal d) i i = d i := by
simp [diagonal]
#align matrix.diagonal_apply_eq Matrix.diagonal_apply_eq
@[simp]
theorem diagonal_apply_ne [Zero α] (d : n → α) {i j : n} (h : i ≠ j) : (diagonal d) i j = 0 := by
simp [diagonal, h]
#align matrix.diagonal_apply_ne Matrix.diagonal_apply_ne
theorem diagonal_apply_ne' [Zero α] (d : n → α) {i j : n} (h : j ≠ i) : (diagonal d) i j = 0 :=
diagonal_apply_ne d h.symm
#align matrix.diagonal_apply_ne' Matrix.diagonal_apply_ne'
@[simp]
theorem diagonal_eq_diagonal_iff [Zero α] {d₁ d₂ : n → α} :
diagonal d₁ = diagonal d₂ ↔ ∀ i, d₁ i = d₂ i :=
⟨fun h i => by simpa using congr_arg (fun m : Matrix n n α => m i i) h, fun h => by
rw [show d₁ = d₂ from funext h]⟩
#align matrix.diagonal_eq_diagonal_iff Matrix.diagonal_eq_diagonal_iff
theorem diagonal_injective [Zero α] : Function.Injective (diagonal : (n → α) → Matrix n n α) :=
fun d₁ d₂ h => funext fun i => by simpa using Matrix.ext_iff.mpr h i i
#align matrix.diagonal_injective Matrix.diagonal_injective
@[simp]
theorem diagonal_zero [Zero α] : (diagonal fun _ => 0 : Matrix n n α) = 0 := by
ext
simp [diagonal]
#align matrix.diagonal_zero Matrix.diagonal_zero
@[simp]
theorem diagonal_transpose [Zero α] (v : n → α) : (diagonal v)ᵀ = diagonal v := by
ext i j
by_cases h : i = j
· simp [h, transpose]
· simp [h, transpose, diagonal_apply_ne' _ h]
#align matrix.diagonal_transpose Matrix.diagonal_transpose
@[simp]
theorem diagonal_add [AddZeroClass α] (d₁ d₂ : n → α) :
diagonal d₁ + diagonal d₂ = diagonal fun i => d₁ i + d₂ i := by
ext i j
by_cases h : i = j <;>
simp [h]
#align matrix.diagonal_add Matrix.diagonal_add
@[simp]
theorem diagonal_smul [Zero α] [SMulZeroClass R α] (r : R) (d : n → α) :
diagonal (r • d) = r • diagonal d := by
ext i j
by_cases h : i = j <;> simp [h]
#align matrix.diagonal_smul Matrix.diagonal_smul
@[simp]
theorem diagonal_neg [NegZeroClass α] (d : n → α) :
-diagonal d = diagonal fun i => -d i := by
ext i j
by_cases h : i = j <;>
simp [h]
#align matrix.diagonal_neg Matrix.diagonal_neg
@[simp]
theorem diagonal_sub [SubNegZeroMonoid α] (d₁ d₂ : n → α) :
diagonal d₁ - diagonal d₂ = diagonal fun i => d₁ i - d₂ i := by
ext i j
by_cases h : i = j <;>
simp [h]
instance [Zero α] [NatCast α] : NatCast (Matrix n n α) where
natCast m := diagonal fun _ => m
@[norm_cast]
theorem diagonal_natCast [Zero α] [NatCast α] (m : ℕ) : diagonal (fun _ : n => (m : α)) = m := rfl
@[norm_cast]
theorem diagonal_natCast' [Zero α] [NatCast α] (m : ℕ) : diagonal ((m : n → α)) = m := rfl
-- See note [no_index around OfNat.ofNat]
theorem diagonal_ofNat [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] :
diagonal (fun _ : n => no_index (OfNat.ofNat m : α)) = OfNat.ofNat m := rfl
-- See note [no_index around OfNat.ofNat]
theorem diagonal_ofNat' [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] :
diagonal (no_index (OfNat.ofNat m : n → α)) = OfNat.ofNat m := rfl
instance [Zero α] [IntCast α] : IntCast (Matrix n n α) where
intCast m := diagonal fun _ => m
@[norm_cast]
theorem diagonal_intCast [Zero α] [IntCast α] (m : ℤ) : diagonal (fun _ : n => (m : α)) = m := rfl
@[norm_cast]
theorem diagonal_intCast' [Zero α] [IntCast α] (m : ℤ) : diagonal ((m : n → α)) = m := rfl
variable (n α)
/-- `Matrix.diagonal` as an `AddMonoidHom`. -/
@[simps]
def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where
toFun := diagonal
map_zero' := diagonal_zero
map_add' x y := (diagonal_add x y).symm
#align matrix.diagonal_add_monoid_hom Matrix.diagonalAddMonoidHom
variable (R)
/-- `Matrix.diagonal` as a `LinearMap`. -/
@[simps]
def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α :=
{ diagonalAddMonoidHom n α with map_smul' := diagonal_smul }
#align matrix.diagonal_linear_map Matrix.diagonalLinearMap
variable {n α R}
@[simp]
theorem diagonal_map [Zero α] [Zero β] {f : α → β} (h : f 0 = 0) {d : n → α} :
(diagonal d).map f = diagonal fun m => f (d m) := by
ext
simp only [diagonal_apply, map_apply]
split_ifs <;> simp [h]
#align matrix.diagonal_map Matrix.diagonal_map
@[simp]
theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α) :
(diagonal v)ᴴ = diagonal (star v) := by
rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)]
rfl
#align matrix.diagonal_conj_transpose Matrix.diagonal_conjTranspose
section One
variable [Zero α] [One α]
instance one : One (Matrix n n α) :=
⟨diagonal fun _ => 1⟩
@[simp]
theorem diagonal_one : (diagonal fun _ => 1 : Matrix n n α) = 1 :=
rfl
#align matrix.diagonal_one Matrix.diagonal_one
theorem one_apply {i j} : (1 : Matrix n n α) i j = if i = j then 1 else 0 :=
rfl
#align matrix.one_apply Matrix.one_apply
@[simp]
theorem one_apply_eq (i) : (1 : Matrix n n α) i i = 1 :=
diagonal_apply_eq _ i
#align matrix.one_apply_eq Matrix.one_apply_eq
@[simp]
theorem one_apply_ne {i j} : i ≠ j → (1 : Matrix n n α) i j = 0 :=
diagonal_apply_ne _
#align matrix.one_apply_ne Matrix.one_apply_ne
theorem one_apply_ne' {i j} : j ≠ i → (1 : Matrix n n α) i j = 0 :=
diagonal_apply_ne' _
#align matrix.one_apply_ne' Matrix.one_apply_ne'
@[simp]
theorem map_one [Zero β] [One β] (f : α → β) (h₀ : f 0 = 0) (h₁ : f 1 = 1) :
(1 : Matrix n n α).map f = (1 : Matrix n n β) := by
ext
simp only [one_apply, map_apply]
split_ifs <;> simp [h₀, h₁]
#align matrix.map_one Matrix.map_one
-- Porting note: added implicit argument `(f := fun_ => α)`, why is that needed?
theorem one_eq_pi_single {i j} : (1 : Matrix n n α) i j = Pi.single (f := fun _ => α) i 1 j := by
simp only [one_apply, Pi.single_apply, eq_comm]
#align matrix.one_eq_pi_single Matrix.one_eq_pi_single
lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) :
0 ≤ (1 : Matrix n n α) i j := by
by_cases hi : i = j <;> simp [hi]
lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) :
0 ≤ (1 : Matrix n n α) i :=
zero_le_one_elem i
end One
instance instAddMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (Matrix n n α) where
natCast_zero := show diagonal _ = _ by
rw [Nat.cast_zero, diagonal_zero]
natCast_succ n := show diagonal _ = diagonal _ + _ by
rw [Nat.cast_succ, ← diagonal_add, diagonal_one]
instance instAddGroupWithOne [AddGroupWithOne α] : AddGroupWithOne (Matrix n n α) where
intCast_ofNat n := show diagonal _ = diagonal _ by
rw [Int.cast_natCast]
intCast_negSucc n := show diagonal _ = -(diagonal _) by
rw [Int.cast_negSucc, diagonal_neg]
__ := addGroup
__ := instAddMonoidWithOne
instance instAddCommMonoidWithOne [AddCommMonoidWithOne α] :
AddCommMonoidWithOne (Matrix n n α) where
__ := addCommMonoid
__ := instAddMonoidWithOne
instance instAddCommGroupWithOne [AddCommGroupWithOne α] :
AddCommGroupWithOne (Matrix n n α) where
__ := addCommGroup
__ := instAddGroupWithOne
section Numeral
set_option linter.deprecated false
@[deprecated, simp]
theorem bit0_apply [Add α] (M : Matrix m m α) (i : m) (j : m) : (bit0 M) i j = bit0 (M i j) :=
rfl
#align matrix.bit0_apply Matrix.bit0_apply
variable [AddZeroClass α] [One α]
@[deprecated]
theorem bit1_apply (M : Matrix n n α) (i : n) (j : n) :
(bit1 M) i j = if i = j then bit1 (M i j) else bit0 (M i j) := by
dsimp [bit1]
by_cases h : i = j <;>
simp [h]
#align matrix.bit1_apply Matrix.bit1_apply
@[deprecated, simp]
theorem bit1_apply_eq (M : Matrix n n α) (i : n) : (bit1 M) i i = bit1 (M i i) := by
simp [bit1_apply]
#align matrix.bit1_apply_eq Matrix.bit1_apply_eq
@[deprecated, simp]
theorem bit1_apply_ne (M : Matrix n n α) {i j : n} (h : i ≠ j) : (bit1 M) i j = bit0 (M i j) := by
simp [bit1_apply, h]
#align matrix.bit1_apply_ne Matrix.bit1_apply_ne
end Numeral
end Diagonal
section Diag
/-- The diagonal of a square matrix. -/
-- @[simp] -- Porting note: simpNF does not like this.
def diag (A : Matrix n n α) (i : n) : α :=
A i i
#align matrix.diag Matrix.diag
-- Porting note: new, because of removed `simp` above.
-- TODO: set as an equation lemma for `diag`, see mathlib4#3024
@[simp]
theorem diag_apply (A : Matrix n n α) (i) : diag A i = A i i :=
rfl
@[simp]
theorem diag_diagonal [DecidableEq n] [Zero α] (a : n → α) : diag (diagonal a) = a :=
funext <| @diagonal_apply_eq _ _ _ _ a
#align matrix.diag_diagonal Matrix.diag_diagonal
@[simp]
theorem diag_transpose (A : Matrix n n α) : diag Aᵀ = diag A :=
rfl
#align matrix.diag_transpose Matrix.diag_transpose
@[simp]
theorem diag_zero [Zero α] : diag (0 : Matrix n n α) = 0 :=
rfl
#align matrix.diag_zero Matrix.diag_zero
@[simp]
theorem diag_add [Add α] (A B : Matrix n n α) : diag (A + B) = diag A + diag B :=
rfl
#align matrix.diag_add Matrix.diag_add
@[simp]
theorem diag_sub [Sub α] (A B : Matrix n n α) : diag (A - B) = diag A - diag B :=
rfl
#align matrix.diag_sub Matrix.diag_sub
@[simp]
theorem diag_neg [Neg α] (A : Matrix n n α) : diag (-A) = -diag A :=
rfl
#align matrix.diag_neg Matrix.diag_neg
@[simp]
theorem diag_smul [SMul R α] (r : R) (A : Matrix n n α) : diag (r • A) = r • diag A :=
rfl
#align matrix.diag_smul Matrix.diag_smul
@[simp]
theorem diag_one [DecidableEq n] [Zero α] [One α] : diag (1 : Matrix n n α) = 1 :=
diag_diagonal _
#align matrix.diag_one Matrix.diag_one
variable (n α)
/-- `Matrix.diag` as an `AddMonoidHom`. -/
@[simps]
def diagAddMonoidHom [AddZeroClass α] : Matrix n n α →+ n → α where
toFun := diag
map_zero' := diag_zero
map_add' := diag_add
#align matrix.diag_add_monoid_hom Matrix.diagAddMonoidHom
variable (R)
/-- `Matrix.diag` as a `LinearMap`. -/
@[simps]
def diagLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : Matrix n n α →ₗ[R] n → α :=
{ diagAddMonoidHom n α with map_smul' := diag_smul }
#align matrix.diag_linear_map Matrix.diagLinearMap
variable {n α R}
theorem diag_map {f : α → β} {A : Matrix n n α} : diag (A.map f) = f ∘ diag A :=
rfl
#align matrix.diag_map Matrix.diag_map
@[simp]
theorem diag_conjTranspose [AddMonoid α] [StarAddMonoid α] (A : Matrix n n α) :
diag Aᴴ = star (diag A) :=
rfl
#align matrix.diag_conj_transpose Matrix.diag_conjTranspose
@[simp]
theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum :=
map_list_sum (diagAddMonoidHom n α) l
#align matrix.diag_list_sum Matrix.diag_list_sum
@[simp]
theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) :
diag s.sum = (s.map diag).sum :=
map_multiset_sum (diagAddMonoidHom n α) s
#align matrix.diag_multiset_sum Matrix.diag_multiset_sum
@[simp]
theorem diag_sum {ι} [AddCommMonoid α] (s : Finset ι) (f : ι → Matrix n n α) :
diag (∑ i ∈ s, f i) = ∑ i ∈ s, diag (f i) :=
map_sum (diagAddMonoidHom n α) f s
#align matrix.diag_sum Matrix.diag_sum
end Diag
section DotProduct
variable [Fintype m] [Fintype n]
/-- `dotProduct v w` is the sum of the entrywise products `v i * w i` -/
def dotProduct [Mul α] [AddCommMonoid α] (v w : m → α) : α :=
∑ i, v i * w i
#align matrix.dot_product Matrix.dotProduct
/- The precedence of 72 comes immediately after ` • ` for `SMul.smul`,
so that `r₁ • a ⬝ᵥ r₂ • b` is parsed as `(r₁ • a) ⬝ᵥ (r₂ • b)` here. -/
@[inherit_doc]
scoped infixl:72 " ⬝ᵥ " => Matrix.dotProduct
theorem dotProduct_assoc [NonUnitalSemiring α] (u : m → α) (w : n → α) (v : Matrix m n α) :
(fun j => u ⬝ᵥ fun i => v i j) ⬝ᵥ w = u ⬝ᵥ fun i => v i ⬝ᵥ w := by
simpa [dotProduct, Finset.mul_sum, Finset.sum_mul, mul_assoc] using Finset.sum_comm
#align matrix.dot_product_assoc Matrix.dotProduct_assoc
theorem dotProduct_comm [AddCommMonoid α] [CommSemigroup α] (v w : m → α) : v ⬝ᵥ w = w ⬝ᵥ v := by
simp_rw [dotProduct, mul_comm]
#align matrix.dot_product_comm Matrix.dotProduct_comm
@[simp]
theorem dotProduct_pUnit [AddCommMonoid α] [Mul α] (v w : PUnit → α) : v ⬝ᵥ w = v ⟨⟩ * w ⟨⟩ := by
simp [dotProduct]
#align matrix.dot_product_punit Matrix.dotProduct_pUnit
section MulOneClass
variable [MulOneClass α] [AddCommMonoid α]
theorem dotProduct_one (v : n → α) : v ⬝ᵥ 1 = ∑ i, v i := by simp [(· ⬝ᵥ ·)]
#align matrix.dot_product_one Matrix.dotProduct_one
theorem one_dotProduct (v : n → α) : 1 ⬝ᵥ v = ∑ i, v i := by simp [(· ⬝ᵥ ·)]
#align matrix.one_dot_product Matrix.one_dotProduct
end MulOneClass
section NonUnitalNonAssocSemiring
variable [NonUnitalNonAssocSemiring α] (u v w : m → α) (x y : n → α)
@[simp]
theorem dotProduct_zero : v ⬝ᵥ 0 = 0 := by simp [dotProduct]
#align matrix.dot_product_zero Matrix.dotProduct_zero
@[simp]
theorem dotProduct_zero' : (v ⬝ᵥ fun _ => 0) = 0 :=
dotProduct_zero v
#align matrix.dot_product_zero' Matrix.dotProduct_zero'
@[simp]
theorem zero_dotProduct : 0 ⬝ᵥ v = 0 := by simp [dotProduct]
#align matrix.zero_dot_product Matrix.zero_dotProduct
@[simp]
theorem zero_dotProduct' : (fun _ => (0 : α)) ⬝ᵥ v = 0 :=
zero_dotProduct v
#align matrix.zero_dot_product' Matrix.zero_dotProduct'
@[simp]
theorem add_dotProduct : (u + v) ⬝ᵥ w = u ⬝ᵥ w + v ⬝ᵥ w := by
simp [dotProduct, add_mul, Finset.sum_add_distrib]
#align matrix.add_dot_product Matrix.add_dotProduct
@[simp]
theorem dotProduct_add : u ⬝ᵥ (v + w) = u ⬝ᵥ v + u ⬝ᵥ w := by
simp [dotProduct, mul_add, Finset.sum_add_distrib]
#align matrix.dot_product_add Matrix.dotProduct_add
@[simp]
theorem sum_elim_dotProduct_sum_elim : Sum.elim u x ⬝ᵥ Sum.elim v y = u ⬝ᵥ v + x ⬝ᵥ y := by
simp [dotProduct]
#align matrix.sum_elim_dot_product_sum_elim Matrix.sum_elim_dotProduct_sum_elim
/-- Permuting a vector on the left of a dot product can be transferred to the right. -/
@[simp]
theorem comp_equiv_symm_dotProduct (e : m ≃ n) : u ∘ e.symm ⬝ᵥ x = u ⬝ᵥ x ∘ e :=
(e.sum_comp _).symm.trans <|
Finset.sum_congr rfl fun _ _ => by simp only [Function.comp, Equiv.symm_apply_apply]
#align matrix.comp_equiv_symm_dot_product Matrix.comp_equiv_symm_dotProduct
/-- Permuting a vector on the right of a dot product can be transferred to the left. -/
@[simp]
theorem dotProduct_comp_equiv_symm (e : n ≃ m) : u ⬝ᵥ x ∘ e.symm = u ∘ e ⬝ᵥ x := by
simpa only [Equiv.symm_symm] using (comp_equiv_symm_dotProduct u x e.symm).symm
#align matrix.dot_product_comp_equiv_symm Matrix.dotProduct_comp_equiv_symm
/-- Permuting vectors on both sides of a dot product is a no-op. -/
@[simp]
theorem comp_equiv_dotProduct_comp_equiv (e : m ≃ n) : x ∘ e ⬝ᵥ y ∘ e = x ⬝ᵥ y := by
-- Porting note: was `simp only` with all three lemmas
rw [← dotProduct_comp_equiv_symm]; simp only [Function.comp, Equiv.apply_symm_apply]
#align matrix.comp_equiv_dot_product_comp_equiv Matrix.comp_equiv_dotProduct_comp_equiv
end NonUnitalNonAssocSemiring
section NonUnitalNonAssocSemiringDecidable
variable [DecidableEq m] [NonUnitalNonAssocSemiring α] (u v w : m → α)
@[simp]
theorem diagonal_dotProduct (i : m) : diagonal v i ⬝ᵥ w = v i * w i := by
have : ∀ j ≠ i, diagonal v i j * w j = 0 := fun j hij => by
simp [diagonal_apply_ne' _ hij]
convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp
#align matrix.diagonal_dot_product Matrix.diagonal_dotProduct
@[simp]
theorem dotProduct_diagonal (i : m) : v ⬝ᵥ diagonal w i = v i * w i := by
have : ∀ j ≠ i, v j * diagonal w i j = 0 := fun j hij => by
simp [diagonal_apply_ne' _ hij]
convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp
#align matrix.dot_product_diagonal Matrix.dotProduct_diagonal
@[simp]
theorem dotProduct_diagonal' (i : m) : (v ⬝ᵥ fun j => diagonal w j i) = v i * w i := by
have : ∀ j ≠ i, v j * diagonal w j i = 0 := fun j hij => by
simp [diagonal_apply_ne _ hij]
convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp
#align matrix.dot_product_diagonal' Matrix.dotProduct_diagonal'
@[simp]
theorem single_dotProduct (x : α) (i : m) : Pi.single i x ⬝ᵥ v = x * v i := by
-- Porting note: (implicit arg) added `(f := fun _ => α)`
have : ∀ j ≠ i, Pi.single (f := fun _ => α) i x j * v j = 0 := fun j hij => by
simp [Pi.single_eq_of_ne hij]
convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp
#align matrix.single_dot_product Matrix.single_dotProduct
@[simp]
theorem dotProduct_single (x : α) (i : m) : v ⬝ᵥ Pi.single i x = v i * x := by
-- Porting note: (implicit arg) added `(f := fun _ => α)`
have : ∀ j ≠ i, v j * Pi.single (f := fun _ => α) i x j = 0 := fun j hij => by
simp [Pi.single_eq_of_ne hij]
convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp
#align matrix.dot_product_single Matrix.dotProduct_single
end NonUnitalNonAssocSemiringDecidable
section NonAssocSemiring
variable [NonAssocSemiring α]
@[simp]
theorem one_dotProduct_one : (1 : n → α) ⬝ᵥ 1 = Fintype.card n := by
simp [dotProduct]
#align matrix.one_dot_product_one Matrix.one_dotProduct_one
end NonAssocSemiring
section NonUnitalNonAssocRing
variable [NonUnitalNonAssocRing α] (u v w : m → α)
@[simp]
theorem neg_dotProduct : -v ⬝ᵥ w = -(v ⬝ᵥ w) := by simp [dotProduct]
#align matrix.neg_dot_product Matrix.neg_dotProduct
@[simp]
theorem dotProduct_neg : v ⬝ᵥ -w = -(v ⬝ᵥ w) := by simp [dotProduct]
#align matrix.dot_product_neg Matrix.dotProduct_neg
lemma neg_dotProduct_neg : -v ⬝ᵥ -w = v ⬝ᵥ w := by
rw [neg_dotProduct, dotProduct_neg, neg_neg]
@[simp]
theorem sub_dotProduct : (u - v) ⬝ᵥ w = u ⬝ᵥ w - v ⬝ᵥ w := by simp [sub_eq_add_neg]
#align matrix.sub_dot_product Matrix.sub_dotProduct
@[simp]
theorem dotProduct_sub : u ⬝ᵥ (v - w) = u ⬝ᵥ v - u ⬝ᵥ w := by simp [sub_eq_add_neg]
#align matrix.dot_product_sub Matrix.dotProduct_sub
end NonUnitalNonAssocRing
section DistribMulAction
variable [Monoid R] [Mul α] [AddCommMonoid α] [DistribMulAction R α]
@[simp]
theorem smul_dotProduct [IsScalarTower R α α] (x : R) (v w : m → α) :
x • v ⬝ᵥ w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, smul_mul_assoc]
#align matrix.smul_dot_product Matrix.smul_dotProduct
@[simp]
theorem dotProduct_smul [SMulCommClass R α α] (x : R) (v w : m → α) :
v ⬝ᵥ x • w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, mul_smul_comm]
#align matrix.dot_product_smul Matrix.dotProduct_smul
end DistribMulAction
section StarRing
variable [NonUnitalSemiring α] [StarRing α] (v w : m → α)
theorem star_dotProduct_star : star v ⬝ᵥ star w = star (w ⬝ᵥ v) := by simp [dotProduct]
#align matrix.star_dot_product_star Matrix.star_dotProduct_star
theorem star_dotProduct : star v ⬝ᵥ w = star (star w ⬝ᵥ v) := by simp [dotProduct]
#align matrix.star_dot_product Matrix.star_dotProduct
theorem dotProduct_star : v ⬝ᵥ star w = star (w ⬝ᵥ star v) := by simp [dotProduct]
#align matrix.dot_product_star Matrix.dotProduct_star
end StarRing
end DotProduct
open Matrix
/-- `M * N` is the usual product of matrices `M` and `N`, i.e. we have that
`(M * N) i k` is the dot product of the `i`-th row of `M` by the `k`-th column of `N`.
This is currently only defined when `m` is finite. -/
-- We want to be lower priority than `instHMul`, but without this we can't have operands with
-- implicit dimensions.
@[default_instance 100]
instance [Fintype m] [Mul α] [AddCommMonoid α] :
HMul (Matrix l m α) (Matrix m n α) (Matrix l n α) where
hMul M N := fun i k => (fun j => M i j) ⬝ᵥ fun j => N j k
#align matrix.mul HMul.hMul
theorem mul_apply [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α}
{i k} : (M * N) i k = ∑ j, M i j * N j k :=
rfl
#align matrix.mul_apply Matrix.mul_apply
instance [Fintype n] [Mul α] [AddCommMonoid α] : Mul (Matrix n n α) where mul M N := M * N
#noalign matrix.mul_eq_mul
theorem mul_apply' [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α}
{i k} : (M * N) i k = (fun j => M i j) ⬝ᵥ fun j => N j k :=
rfl
#align matrix.mul_apply' Matrix.mul_apply'
theorem sum_apply [AddCommMonoid α] (i : m) (j : n) (s : Finset β) (g : β → Matrix m n α) :
(∑ c ∈ s, g c) i j = ∑ c ∈ s, g c i j :=
(congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _)
#align matrix.sum_apply Matrix.sum_apply
theorem two_mul_expl {R : Type*} [CommRing R] (A B : Matrix (Fin 2) (Fin 2) R) :
(A * B) 0 0 = A 0 0 * B 0 0 + A 0 1 * B 1 0 ∧
(A * B) 0 1 = A 0 0 * B 0 1 + A 0 1 * B 1 1 ∧
(A * B) 1 0 = A 1 0 * B 0 0 + A 1 1 * B 1 0 ∧
(A * B) 1 1 = A 1 0 * B 0 1 + A 1 1 * B 1 1 := by
refine ⟨?_, ?_, ?_, ?_⟩ <;>
· rw [Matrix.mul_apply, Finset.sum_fin_eq_sum_range, Finset.sum_range_succ, Finset.sum_range_succ]
simp
#align matrix.two_mul_expl Matrix.two_mul_expl
section AddCommMonoid
variable [AddCommMonoid α] [Mul α]
@[simp]
theorem smul_mul [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] (a : R)
(M : Matrix m n α) (N : Matrix n l α) : (a • M) * N = a • (M * N) := by
ext
apply smul_dotProduct a
#align matrix.smul_mul Matrix.smul_mul
@[simp]
theorem mul_smul [Fintype n] [Monoid R] [DistribMulAction R α] [SMulCommClass R α α]
(M : Matrix m n α) (a : R) (N : Matrix n l α) : M * (a • N) = a • (M * N) := by
ext
apply dotProduct_smul
#align matrix.mul_smul Matrix.mul_smul
end AddCommMonoid
section NonUnitalNonAssocSemiring
variable [NonUnitalNonAssocSemiring α]
@[simp]
protected theorem mul_zero [Fintype n] (M : Matrix m n α) : M * (0 : Matrix n o α) = 0 := by
ext
apply dotProduct_zero
#align matrix.mul_zero Matrix.mul_zero
@[simp]
protected theorem zero_mul [Fintype m] (M : Matrix m n α) : (0 : Matrix l m α) * M = 0 := by
ext
apply zero_dotProduct
#align matrix.zero_mul Matrix.zero_mul
protected theorem mul_add [Fintype n] (L : Matrix m n α) (M N : Matrix n o α) :
L * (M + N) = L * M + L * N := by
ext
apply dotProduct_add
#align matrix.mul_add Matrix.mul_add
protected theorem add_mul [Fintype m] (L M : Matrix l m α) (N : Matrix m n α) :
(L + M) * N = L * N + M * N := by
ext
apply add_dotProduct
#align matrix.add_mul Matrix.add_mul
instance nonUnitalNonAssocSemiring [Fintype n] : NonUnitalNonAssocSemiring (Matrix n n α) :=
{ Matrix.addCommMonoid with
mul_zero := Matrix.mul_zero
zero_mul := Matrix.zero_mul
left_distrib := Matrix.mul_add
right_distrib := Matrix.add_mul }
@[simp]
theorem diagonal_mul [Fintype m] [DecidableEq m] (d : m → α) (M : Matrix m n α) (i j) :
(diagonal d * M) i j = d i * M i j :=
diagonal_dotProduct _ _ _
#align matrix.diagonal_mul Matrix.diagonal_mul
@[simp]
theorem mul_diagonal [Fintype n] [DecidableEq n] (d : n → α) (M : Matrix m n α) (i j) :
(M * diagonal d) i j = M i j * d j := by
rw [← diagonal_transpose]
apply dotProduct_diagonal
#align matrix.mul_diagonal Matrix.mul_diagonal
@[simp]
theorem diagonal_mul_diagonal [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) :
diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i := by
ext i j
by_cases h : i = j <;>
simp [h]
#align matrix.diagonal_mul_diagonal Matrix.diagonal_mul_diagonal
theorem diagonal_mul_diagonal' [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) :
diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i :=
diagonal_mul_diagonal _ _
#align matrix.diagonal_mul_diagonal' Matrix.diagonal_mul_diagonal'
theorem smul_eq_diagonal_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) (a : α) :
a • M = (diagonal fun _ => a) * M := by
ext
simp
#align matrix.smul_eq_diagonal_mul Matrix.smul_eq_diagonal_mul
theorem op_smul_eq_mul_diagonal [Fintype n] [DecidableEq n] (M : Matrix m n α) (a : α) :
MulOpposite.op a • M = M * (diagonal fun _ : n => a) := by
ext
simp
/-- Left multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/
@[simps]
def addMonoidHomMulLeft [Fintype m] (M : Matrix l m α) : Matrix m n α →+ Matrix l n α where
toFun x := M * x
map_zero' := Matrix.mul_zero _
map_add' := Matrix.mul_add _
#align matrix.add_monoid_hom_mul_left Matrix.addMonoidHomMulLeft
/-- Right multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/
@[simps]
def addMonoidHomMulRight [Fintype m] (M : Matrix m n α) : Matrix l m α →+ Matrix l n α where
toFun x := x * M
map_zero' := Matrix.zero_mul _
map_add' _ _ := Matrix.add_mul _ _ _
#align matrix.add_monoid_hom_mul_right Matrix.addMonoidHomMulRight
protected theorem sum_mul [Fintype m] (s : Finset β) (f : β → Matrix l m α) (M : Matrix m n α) :
(∑ a ∈ s, f a) * M = ∑ a ∈ s, f a * M :=
map_sum (addMonoidHomMulRight M) f s
#align matrix.sum_mul Matrix.sum_mul
protected theorem mul_sum [Fintype m] (s : Finset β) (f : β → Matrix m n α) (M : Matrix l m α) :
(M * ∑ a ∈ s, f a) = ∑ a ∈ s, M * f a :=
map_sum (addMonoidHomMulLeft M) f s
#align matrix.mul_sum Matrix.mul_sum
/-- This instance enables use with `smul_mul_assoc`. -/
instance Semiring.isScalarTower [Fintype n] [Monoid R] [DistribMulAction R α]
[IsScalarTower R α α] : IsScalarTower R (Matrix n n α) (Matrix n n α) :=
⟨fun r m n => Matrix.smul_mul r m n⟩
#align matrix.semiring.is_scalar_tower Matrix.Semiring.isScalarTower
/-- This instance enables use with `mul_smul_comm`. -/
instance Semiring.smulCommClass [Fintype n] [Monoid R] [DistribMulAction R α]
[SMulCommClass R α α] : SMulCommClass R (Matrix n n α) (Matrix n n α) :=
⟨fun r m n => (Matrix.mul_smul m r n).symm⟩
#align matrix.semiring.smul_comm_class Matrix.Semiring.smulCommClass
end NonUnitalNonAssocSemiring
section NonAssocSemiring
variable [NonAssocSemiring α]
@[simp]
protected theorem one_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) :
(1 : Matrix m m α) * M = M := by
ext
rw [← diagonal_one, diagonal_mul, one_mul]
#align matrix.one_mul Matrix.one_mul
@[simp]
protected theorem mul_one [Fintype n] [DecidableEq n] (M : Matrix m n α) :
M * (1 : Matrix n n α) = M := by
ext
rw [← diagonal_one, mul_diagonal, mul_one]
#align matrix.mul_one Matrix.mul_one
instance nonAssocSemiring [Fintype n] [DecidableEq n] : NonAssocSemiring (Matrix n n α) :=
{ Matrix.nonUnitalNonAssocSemiring, Matrix.instAddCommMonoidWithOne with
one := 1
one_mul := Matrix.one_mul
mul_one := Matrix.mul_one }
@[simp]
| Mathlib/Data/Matrix/Basic.lean | 1,148 | 1,151 | theorem map_mul [Fintype n] {L : Matrix m n α} {M : Matrix n o α} [NonAssocSemiring β]
{f : α →+* β} : (L * M).map f = L.map f * M.map f := by |
ext
simp [mul_apply, map_sum]
|
/-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Fintype.BigOperators
#align_import data.sign from "leanprover-community/mathlib"@"2445c98ae4b87eabebdde552593519b9b6dc350c"
/-!
# Sign function
This file defines the sign function for types with zero and a decidable less-than relation, and
proves some basic theorems about it.
-/
-- Porting note (#11081): cannot automatically derive Fintype, added manually
/-- The type of signs. -/
inductive SignType
| zero
| neg
| pos
deriving DecidableEq, Inhabited
#align sign_type SignType
-- Porting note: these lemmas are autogenerated by the inductive definition and are not
-- in simple form due to the below `x_eq_x` lemmas
attribute [nolint simpNF] SignType.zero.sizeOf_spec
attribute [nolint simpNF] SignType.neg.sizeOf_spec
attribute [nolint simpNF] SignType.pos.sizeOf_spec
namespace SignType
-- Porting note: Added Fintype SignType manually
instance : Fintype SignType :=
Fintype.ofMultiset (zero :: neg :: pos :: List.nil) (fun x ↦ by cases x <;> simp)
instance : Zero SignType :=
⟨zero⟩
instance : One SignType :=
⟨pos⟩
instance : Neg SignType :=
⟨fun s =>
match s with
| neg => pos
| zero => zero
| pos => neg⟩
@[simp]
theorem zero_eq_zero : zero = 0 :=
rfl
#align sign_type.zero_eq_zero SignType.zero_eq_zero
@[simp]
theorem neg_eq_neg_one : neg = -1 :=
rfl
#align sign_type.neg_eq_neg_one SignType.neg_eq_neg_one
@[simp]
theorem pos_eq_one : pos = 1 :=
rfl
#align sign_type.pos_eq_one SignType.pos_eq_one
instance : Mul SignType :=
⟨fun x y =>
match x with
| neg => -y
| zero => zero
| pos => y⟩
/-- The less-than-or-equal relation on signs. -/
protected inductive LE : SignType → SignType → Prop
| of_neg (a) : SignType.LE neg a
| zero : SignType.LE zero zero
| of_pos (a) : SignType.LE a pos
#align sign_type.le SignType.LE
instance : LE SignType :=
⟨SignType.LE⟩
instance LE.decidableRel : DecidableRel SignType.LE := fun a b => by
cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩)
instance decidableEq : DecidableEq SignType := fun a b => by
cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩)
private lemma mul_comm : ∀ (a b : SignType), a * b = b * a := by rintro ⟨⟩ ⟨⟩ <;> rfl
private lemma mul_assoc : ∀ (a b c : SignType), (a * b) * c = a * (b * c) := by
rintro ⟨⟩ ⟨⟩ ⟨⟩ <;> rfl
/- We can define a `Field` instance on `SignType`, but it's not mathematically sensible,
so we only define the `CommGroupWithZero`. -/
instance : CommGroupWithZero SignType where
zero := 0
one := 1
mul := (· * ·)
inv := id
mul_zero a := by cases a <;> rfl
zero_mul a := by cases a <;> rfl
mul_one a := by cases a <;> rfl
one_mul a := by cases a <;> rfl
mul_inv_cancel a ha := by cases a <;> trivial
mul_comm := mul_comm
mul_assoc := mul_assoc
exists_pair_ne := ⟨0, 1, by rintro ⟨_⟩⟩
inv_zero := rfl
private lemma le_antisymm (a b : SignType) (_ : a ≤ b) (_: b ≤ a) : a = b := by
cases a <;> cases b <;> trivial
private lemma le_trans (a b c : SignType) (_ : a ≤ b) (_: b ≤ c) : a ≤ c := by
cases a <;> cases b <;> cases c <;> tauto
instance : LinearOrder SignType where
le := (· ≤ ·)
le_refl a := by cases a <;> constructor
le_total a b := by cases a <;> cases b <;> first | left; constructor | right; constructor
le_antisymm := le_antisymm
le_trans := le_trans
decidableLE := LE.decidableRel
decidableEq := SignType.decidableEq
instance : BoundedOrder SignType where
top := 1
le_top := LE.of_pos
bot := -1
bot_le := LE.of_neg
instance : HasDistribNeg SignType :=
{ neg_neg := fun x => by cases x <;> rfl
neg_mul := fun x y => by cases x <;> cases y <;> rfl
mul_neg := fun x y => by cases x <;> cases y <;> rfl }
/-- `SignType` is equivalent to `Fin 3`. -/
def fin3Equiv : SignType ≃* Fin 3 where
toFun a :=
match a with
| 0 => ⟨0, by simp⟩
| 1 => ⟨1, by simp⟩
| -1 => ⟨2, by simp⟩
invFun a :=
match a with
| ⟨0, _⟩ => 0
| ⟨1, _⟩ => 1
| ⟨2, _⟩ => -1
left_inv a := by cases a <;> rfl
right_inv a :=
match a with
| ⟨0, _⟩ => by simp
| ⟨1, _⟩ => by simp
| ⟨2, _⟩ => by simp
map_mul' a b := by
cases a <;> cases b <;> rfl
#align sign_type.fin3_equiv SignType.fin3Equiv
section CaseBashing
-- Porting note: a lot of these thms used to use decide! which is not implemented yet
theorem nonneg_iff {a : SignType} : 0 ≤ a ↔ a = 0 ∨ a = 1 := by cases a <;> decide
#align sign_type.nonneg_iff SignType.nonneg_iff
theorem nonneg_iff_ne_neg_one {a : SignType} : 0 ≤ a ↔ a ≠ -1 := by cases a <;> decide
#align sign_type.nonneg_iff_ne_neg_one SignType.nonneg_iff_ne_neg_one
theorem neg_one_lt_iff {a : SignType} : -1 < a ↔ 0 ≤ a := by cases a <;> decide
#align sign_type.neg_one_lt_iff SignType.neg_one_lt_iff
theorem nonpos_iff {a : SignType} : a ≤ 0 ↔ a = -1 ∨ a = 0 := by cases a <;> decide
#align sign_type.nonpos_iff SignType.nonpos_iff
theorem nonpos_iff_ne_one {a : SignType} : a ≤ 0 ↔ a ≠ 1 := by cases a <;> decide
#align sign_type.nonpos_iff_ne_one SignType.nonpos_iff_ne_one
theorem lt_one_iff {a : SignType} : a < 1 ↔ a ≤ 0 := by cases a <;> decide
#align sign_type.lt_one_iff SignType.lt_one_iff
@[simp]
theorem neg_iff {a : SignType} : a < 0 ↔ a = -1 := by cases a <;> decide
#align sign_type.neg_iff SignType.neg_iff
@[simp]
theorem le_neg_one_iff {a : SignType} : a ≤ -1 ↔ a = -1 :=
le_bot_iff
#align sign_type.le_neg_one_iff SignType.le_neg_one_iff
@[simp]
theorem pos_iff {a : SignType} : 0 < a ↔ a = 1 := by cases a <;> decide
#align sign_type.pos_iff SignType.pos_iff
@[simp]
theorem one_le_iff {a : SignType} : 1 ≤ a ↔ a = 1 :=
top_le_iff
#align sign_type.one_le_iff SignType.one_le_iff
@[simp]
theorem neg_one_le (a : SignType) : -1 ≤ a :=
bot_le
#align sign_type.neg_one_le SignType.neg_one_le
@[simp]
theorem le_one (a : SignType) : a ≤ 1 :=
le_top
#align sign_type.le_one SignType.le_one
@[simp]
theorem not_lt_neg_one (a : SignType) : ¬a < -1 :=
not_lt_bot
#align sign_type.not_lt_neg_one SignType.not_lt_neg_one
@[simp]
theorem not_one_lt (a : SignType) : ¬1 < a :=
not_top_lt
#align sign_type.not_one_lt SignType.not_one_lt
@[simp]
theorem self_eq_neg_iff (a : SignType) : a = -a ↔ a = 0 := by cases a <;> decide
#align sign_type.self_eq_neg_iff SignType.self_eq_neg_iff
@[simp]
theorem neg_eq_self_iff (a : SignType) : -a = a ↔ a = 0 := by cases a <;> decide
#align sign_type.neg_eq_self_iff SignType.neg_eq_self_iff
@[simp]
theorem neg_one_lt_one : (-1 : SignType) < 1 :=
bot_lt_top
#align sign_type.neg_one_lt_one SignType.neg_one_lt_one
end CaseBashing
section cast
variable {α : Type*} [Zero α] [One α] [Neg α]
/-- Turn a `SignType` into zero, one, or minus one. This is a coercion instance, but note it is
only a `CoeTC` instance: see note [use has_coe_t]. -/
@[coe]
def cast : SignType → α
| zero => 0
| pos => 1
| neg => -1
#align sign_type.cast SignType.cast
-- Porting note: Translated has_coe_t to CoeTC
instance : CoeTC SignType α :=
⟨cast⟩
-- Porting note: `cast_eq_coe` removed, syntactic equality
/-- Casting out of `SignType` respects composition with functions preserving `0, 1, -1`. -/
lemma map_cast' {β : Type*} [One β] [Neg β] [Zero β]
(f : α → β) (h₁ : f 1 = 1) (h₂ : f 0 = 0) (h₃ : f (-1) = -1) (s : SignType) :
f s = s := by
cases s <;> simp only [SignType.cast, h₁, h₂, h₃]
/-- Casting out of `SignType` respects composition with suitable bundled homomorphism types. -/
lemma map_cast {α β F : Type*} [AddGroupWithOne α] [One β] [SubtractionMonoid β]
[FunLike F α β] [AddMonoidHomClass F α β] [OneHomClass F α β] (f : F) (s : SignType) :
f s = s := by
apply map_cast' <;> simp
@[simp]
theorem coe_zero : ↑(0 : SignType) = (0 : α) :=
rfl
#align sign_type.coe_zero SignType.coe_zero
@[simp]
theorem coe_one : ↑(1 : SignType) = (1 : α) :=
rfl
#align sign_type.coe_one SignType.coe_one
@[simp]
theorem coe_neg_one : ↑(-1 : SignType) = (-1 : α) :=
rfl
#align sign_type.coe_neg_one SignType.coe_neg_one
@[simp, norm_cast]
lemma coe_neg {α : Type*} [One α] [SubtractionMonoid α] (s : SignType) :
(↑(-s) : α) = -↑s := by
cases s <;> simp
/-- Casting `SignType → ℤ → α` is the same as casting directly `SignType → α`. -/
@[simp, norm_cast]
lemma intCast_cast {α : Type*} [AddGroupWithOne α] (s : SignType) : ((s : ℤ) : α) = s :=
map_cast' _ Int.cast_one Int.cast_zero (@Int.cast_one α _ ▸ Int.cast_neg 1) _
end cast
/-- `SignType.cast` as a `MulWithZeroHom`. -/
@[simps]
def castHom {α} [MulZeroOneClass α] [HasDistribNeg α] : SignType →*₀ α where
toFun := cast
map_zero' := rfl
map_one' := rfl
map_mul' x y := by cases x <;> cases y <;> simp [zero_eq_zero, pos_eq_one, neg_eq_neg_one]
#align sign_type.cast_hom SignType.castHom
-- Porting note (#10756): new theorem
theorem univ_eq : (Finset.univ : Finset SignType) = {0, -1, 1} := by
decide
theorem range_eq {α} (f : SignType → α) : Set.range f = {f zero, f neg, f pos} := by
classical rw [← Fintype.coe_image_univ, univ_eq]
classical simp [Finset.coe_insert]
#align sign_type.range_eq SignType.range_eq
@[simp, norm_cast] lemma coe_mul {α} [MulZeroOneClass α] [HasDistribNeg α] (a b : SignType) :
↑(a * b) = (a : α) * b :=
map_mul SignType.castHom _ _
@[simp, norm_cast] lemma coe_pow {α} [MonoidWithZero α] [HasDistribNeg α] (a : SignType) (k : ℕ) :
↑(a ^ k) = (a : α) ^ k :=
map_pow SignType.castHom _ _
@[simp, norm_cast] lemma coe_zpow {α} [GroupWithZero α] [HasDistribNeg α] (a : SignType) (k : ℤ) :
↑(a ^ k) = (a : α) ^ k :=
map_zpow₀ SignType.castHom _ _
end SignType
variable {α : Type*}
open SignType
section Preorder
variable [Zero α] [Preorder α] [DecidableRel ((· < ·) : α → α → Prop)] {a : α}
-- Porting note: needed to rename this from sign to SignType.sign to avoid ambiguity with Int.sign
/-- The sign of an element is 1 if it's positive, -1 if negative, 0 otherwise. -/
def SignType.sign : α →o SignType :=
⟨fun a => if 0 < a then 1 else if a < 0 then -1 else 0, fun a b h => by
dsimp
split_ifs with h₁ h₂ h₃ h₄ _ _ h₂ h₃ <;> try constructor
· cases lt_irrefl 0 (h₁.trans <| h.trans_lt h₃)
· cases h₂ (h₁.trans_le h)
· cases h₄ (h.trans_lt h₃)⟩
#align sign SignType.sign
theorem sign_apply : sign a = ite (0 < a) 1 (ite (a < 0) (-1) 0) :=
rfl
#align sign_apply sign_apply
@[simp]
theorem sign_zero : sign (0 : α) = 0 := by simp [sign_apply]
#align sign_zero sign_zero
@[simp]
theorem sign_pos (ha : 0 < a) : sign a = 1 := by rwa [sign_apply, if_pos]
#align sign_pos sign_pos
@[simp]
theorem sign_neg (ha : a < 0) : sign a = -1 := by rwa [sign_apply, if_neg <| asymm ha, if_pos]
#align sign_neg sign_neg
theorem sign_eq_one_iff : sign a = 1 ↔ 0 < a := by
refine ⟨fun h => ?_, fun h => sign_pos h⟩
by_contra hn
rw [sign_apply, if_neg hn] at h
split_ifs at h
#align sign_eq_one_iff sign_eq_one_iff
theorem sign_eq_neg_one_iff : sign a = -1 ↔ a < 0 := by
refine ⟨fun h => ?_, fun h => sign_neg h⟩
rw [sign_apply] at h
split_ifs at h
assumption
#align sign_eq_neg_one_iff sign_eq_neg_one_iff
end Preorder
section LinearOrder
variable [Zero α] [LinearOrder α] {a : α}
/-- `SignType.sign` respects strictly monotone zero-preserving maps. -/
lemma StrictMono.sign_comp {β F : Type*} [Zero β] [Preorder β] [DecidableRel ((· < ·) : β → β → _)]
[FunLike F α β] [ZeroHomClass F α β] {f : F} (hf : StrictMono f) (a : α) :
sign (f a) = sign a := by
simp only [sign_apply, ← map_zero f, hf.lt_iff_lt]
@[simp]
theorem sign_eq_zero_iff : sign a = 0 ↔ a = 0 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ sign_zero⟩
rw [sign_apply] at h
split_ifs at h with h_1 h_2
cases' h
exact (le_of_not_lt h_1).eq_of_not_lt h_2
#align sign_eq_zero_iff sign_eq_zero_iff
theorem sign_ne_zero : sign a ≠ 0 ↔ a ≠ 0 :=
sign_eq_zero_iff.not
#align sign_ne_zero sign_ne_zero
@[simp]
theorem sign_nonneg_iff : 0 ≤ sign a ↔ 0 ≤ a := by
rcases lt_trichotomy 0 a with (h | h | h)
· simp [h, h.le]
· simp [← h]
· simp [h, h.not_le]
#align sign_nonneg_iff sign_nonneg_iff
@[simp]
theorem sign_nonpos_iff : sign a ≤ 0 ↔ a ≤ 0 := by
rcases lt_trichotomy 0 a with (h | h | h)
· simp [h, h.not_le]
· simp [← h]
· simp [h, h.le]
#align sign_nonpos_iff sign_nonpos_iff
end LinearOrder
section OrderedSemiring
variable [OrderedSemiring α] [DecidableRel ((· < ·) : α → α → Prop)] [Nontrivial α]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem sign_one : sign (1 : α) = 1 :=
sign_pos zero_lt_one
#align sign_one sign_one
end OrderedSemiring
section OrderedRing
@[simp]
lemma sign_intCast {α : Type*} [OrderedRing α] [Nontrivial α]
[DecidableRel ((· < ·) : α → α → Prop)] (n : ℤ) :
sign (n : α) = sign n := by
simp only [sign_apply, Int.cast_pos, Int.cast_lt_zero]
end OrderedRing
section LinearOrderedRing
variable [LinearOrderedRing α] {a b : α}
theorem sign_mul (x y : α) : sign (x * y) = sign x * sign y := by
rcases lt_trichotomy x 0 with (hx | hx | hx) <;> rcases lt_trichotomy y 0 with (hy | hy | hy) <;>
simp [hx, hy, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg]
#align sign_mul sign_mul
@[simp] theorem sign_mul_abs (x : α) : (sign x * |x| : α) = x := by
rcases lt_trichotomy x 0 with hx | rfl | hx <;> simp [*, abs_of_pos, abs_of_neg]
@[simp] theorem abs_mul_sign (x : α) : (|x| * sign x : α) = x := by
rcases lt_trichotomy x 0 with hx | rfl | hx <;> simp [*, abs_of_pos, abs_of_neg]
@[simp]
theorem sign_mul_self (x : α) : sign x * x = |x| := by
rcases lt_trichotomy x 0 with hx | rfl | hx <;> simp [*, abs_of_pos, abs_of_neg]
@[simp]
theorem self_mul_sign (x : α) : x * sign x = |x| := by
rcases lt_trichotomy x 0 with hx | rfl | hx <;> simp [*, abs_of_pos, abs_of_neg]
/-- `SignType.sign` as a `MonoidWithZeroHom` for a nontrivial ordered semiring. Note that linearity
is required; consider ℂ with the order `z ≤ w` iff they have the same imaginary part and
`z - w ≤ 0` in the reals; then `1 + I` and `1 - I` are incomparable to zero, and thus we have:
`0 * 0 = SignType.sign (1 + I) * SignType.sign (1 - I) ≠ SignType.sign 2 = 1`.
(`Complex.orderedCommRing`) -/
def signHom : α →*₀ SignType where
toFun := sign
map_zero' := sign_zero
map_one' := sign_one
map_mul' := sign_mul
#align sign_hom signHom
theorem sign_pow (x : α) (n : ℕ) : sign (x ^ n) = sign x ^ n := map_pow signHom x n
#align sign_pow sign_pow
end LinearOrderedRing
section AddGroup
variable [AddGroup α] [Preorder α] [DecidableRel ((· < ·) : α → α → Prop)]
theorem Left.sign_neg [CovariantClass α α (· + ·) (· < ·)] (a : α) : sign (-a) = -sign a := by
simp_rw [sign_apply, Left.neg_pos_iff, Left.neg_neg_iff]
split_ifs with h h'
· exact False.elim (lt_asymm h h')
· simp
· simp
· simp
#align left.sign_neg Left.sign_neg
theorem Right.sign_neg [CovariantClass α α (Function.swap (· + ·)) (· < ·)] (a : α) :
sign (-a) = -sign a := by
simp_rw [sign_apply, Right.neg_pos_iff, Right.neg_neg_iff]
split_ifs with h h'
· exact False.elim (lt_asymm h h')
· simp
· simp
· simp
#align right.sign_neg Right.sign_neg
end AddGroup
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α]
/- I'm not sure why this is necessary, see
https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Decidable.20vs.20decidable_rel
-/
attribute [local instance] LinearOrderedAddCommGroup.decidableLT
theorem sign_sum {ι : Type*} {s : Finset ι} {f : ι → α} (hs : s.Nonempty) (t : SignType)
(h : ∀ i ∈ s, sign (f i) = t) : sign (∑ i ∈ s, f i) = t := by
cases t
· simp_rw [zero_eq_zero, sign_eq_zero_iff] at h ⊢
exact Finset.sum_eq_zero h
· simp_rw [neg_eq_neg_one, sign_eq_neg_one_iff] at h ⊢
exact Finset.sum_neg h hs
· simp_rw [pos_eq_one, sign_eq_one_iff] at h ⊢
exact Finset.sum_pos h hs
#align sign_sum sign_sum
end LinearOrderedAddCommGroup
namespace Int
| Mathlib/Data/Sign.lean | 525 | 526 | theorem sign_eq_sign (n : ℤ) : Int.sign n = SignType.sign n := by |
obtain (n | _) | _ := n <;> simp [sign, Int.sign_neg, negSucc_lt_zero]
|
/-
Copyright (c) 2024 Mitchell Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Lee
-/
import Mathlib.RingTheory.Flat.Basic
import Mathlib.LinearAlgebra.TensorProduct.Vanishing
import Mathlib.Algebra.Module.FinitePresentation
/-! # The equational criterion for flatness
Let $M$ be a module over a commutative ring $R$. Let us say that a relation
$\sum_{i \in \iota} f_i x_i = 0$ in $M$ is *trivial* (`Module.IsTrivialRelation`) if there exist a
finite index type $\kappa$, elements $(y_j)_{j \in \kappa}$ of $M$,
and elements $(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$ such that for all $i$,
$$x_i = \sum_j a_{ij} y_j$$
and for all $j$,
$$\sum_{i} f_i a_{ij} = 0.$$
The *equational criterion for flatness* [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK)
(`Module.Flat.iff_forall_isTrivialRelation`) states that $M$ is flat if and only if every relation
in $M$ is trivial.
The equational criterion for flatness can be stated in the following form
(`Module.Flat.iff_forall_exists_factorization`). Let $M$ be an $R$-module. Then the following two
conditions are equivalent:
* $M$ is flat.
* For all finite index types $\iota$, all elements $f \in R^{\iota}$, and all homomorphisms
$x \colon R^{\iota} \to M$ such that $x(f) = 0$, there exist a finite index type $\kappa$ and module
homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such
that $x = y \circ a$ and $a(f) = 0$.
Of course, the module $R^\iota$ in this statement can be replaced by an arbitrary free module
(`Module.Flat.exists_factorization_of_apply_eq_zero_of_free`).
We also have the following strengthening of the equational criterion for flatness
(`Module.Flat.exists_factorization_of_comp_eq_zero_of_free`): Let $M$ be a
flat module. Let $K$ and $N$ be finite $R$-modules with $N$ free, and let $f \colon K \to N$ and
$x \colon N \to M$ be homomorphisms such that $x \circ f = 0$. Then there exist a finite index type
$\kappa$ and module homomorphisms $a \colon N \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such
that $x = y \circ a$ and $a \circ f = 0$. We recover the usual equational criterion for flatness if
$K = R$ and $N = R^\iota$. This is used in the proof of Lazard's theorem.
We conclude that every homomorphism from a finitely presented module to a flat module factors
through a finite free module (`Module.Flat.exists_factorization_of_isFinitelyPresented`).
## References
* [Stacks: Flat modules and flat ring maps](https://stacks.math.columbia.edu/tag/00H9)
* [Stacks: Characterizing flatness](https://stacks.math.columbia.edu/tag/058C)
-/
universe u
variable {R M : Type u} [CommRing R] [AddCommGroup M] [Module R M]
open Classical DirectSum LinearMap TensorProduct Finsupp
open scoped BigOperators
namespace Module
variable {ι : Type u} [Fintype ι] (f : ι → R) (x : ι → M)
/-- The proposition that the relation $\sum_i f_i x_i = 0$ in $M$ is trivial.
That is, there exist a finite index type $\kappa$, elements
$(y_j)_{j \in \kappa}$ of $M$, and elements $(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$
such that for all $i$,
$$x_i = \sum_j a_{ij} y_j$$
and for all $j$,
$$\sum_{i} f_i a_{ij} = 0.$$
By `Module.sum_smul_eq_zero_of_isTrivialRelation`, this condition implies $\sum_i f_i x_i = 0$. -/
abbrev IsTrivialRelation : Prop :=
∃ (κ : Type u) (_ : Fintype κ) (a : ι → κ → R) (y : κ → M),
(∀ i, x i = ∑ j, a i j • y j) ∧ ∀ j, ∑ i, f i * a i j = 0
variable {f x}
/-- `Module.IsTrivialRelation` is equivalent to the predicate `TensorProduct.VanishesTrivially`
defined in `Mathlib/LinearAlgebra/TensorProduct/Vanishing.lean`. -/
theorem isTrivialRelation_iff_vanishesTrivially :
IsTrivialRelation f x ↔ VanishesTrivially R f x := by
simp only [IsTrivialRelation, VanishesTrivially, smul_eq_mul, mul_comm]
/-- If the relation given by $(f_i)_{i \in \iota}$ and $(x_i)_{i \in \iota}$ is trivial, then
$\sum_{i} f_i x_i$ is actually equal to $0$. -/
theorem sum_smul_eq_zero_of_isTrivialRelation (h : IsTrivialRelation f x) :
∑ i, f i • x i = 0 := by
simpa using
congr_arg (TensorProduct.lid R M) <|
sum_tmul_eq_zero_of_vanishesTrivially R (isTrivialRelation_iff_vanishesTrivially.mp h)
end Module
namespace Module.Flat
variable (R M) in
/-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK),
combined form.
Let $M$ be a module over a commutative ring $R$. The following are equivalent:
* $M$ is flat.
* For all ideals $I \subseteq R$, the map $I \otimes M \to M$ is injective.
* Every $\sum_i f_i \otimes x_i$ that vanishes in $R \otimes M$ vanishes trivially.
* Every relation $\sum_i f_i x_i = 0$ in $M$ is trivial.
* For all finite index types $\iota$, all elements $f \in R^{\iota}$, and all homomorphisms
$x \colon R^{\iota} \to M$ such that $x(f) = 0$, there exist a finite index type $\kappa$ and module
homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such
that $x = y \circ a$ and $a(f) = 0$.
* For all finite free modules $N$, all elements $f \in N$, and all homomorphisms $x \colon N \to M$
such that $x(f) = 0$, there exist a finite index type $\kappa$ and module homomorphisms
$a \colon N \to R^{\kappa}$ and $y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and
$a(f) = 0$. -/
theorem tfae_equational_criterion : List.TFAE [
Flat R M,
∀ (I : Ideal R), Function.Injective ⇑(rTensor M (Submodule.subtype I)),
∀ {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M}, ∑ i, f i ⊗ₜ x i = (0 : R ⊗[R] M) →
VanishesTrivially R f x,
∀ {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M}, ∑ i, f i • x i = 0 → IsTrivialRelation f x,
∀ {ι : Type u} [Fintype ι] {f : ι →₀ R} {x : (ι →₀ R) →ₗ[R] M}, x f = 0 →
∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M),
x = y ∘ₗ a ∧ a f = 0,
∀ {N : Type u} [AddCommGroup N] [Module R N] [Free R N] [Finite R N] {f : N} {x : N →ₗ[R] M},
x f = 0 →
∃ (κ : Type u) (_ : Fintype κ) (a : N →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M),
x = y ∘ₗ a ∧ a f = 0] := by
tfae_have 1 ↔ 2
· exact iff_rTensor_injective' R M
tfae_have 3 ↔ 2
· exact forall_vanishesTrivially_iff_forall_rTensor_injective R
tfae_have 3 ↔ 4
· simp [(TensorProduct.lid R M).injective.eq_iff.symm, isTrivialRelation_iff_vanishesTrivially]
tfae_have 4 → 5
· intro h₄ ι hι f x hfx
let f' : ι → R := f
let x' : ι → M := fun i ↦ x (single i 1)
have := calc
∑ i, f' i • x' i
_ = ∑ i, f i • x (single i 1) := rfl
_ = x (∑ i, f i • Finsupp.single i 1) := by simp_rw [map_sum, map_smul]
_ = x f := by
simp_rw [smul_single, smul_eq_mul, mul_one, univ_sum_single]
_ = 0 := hfx
obtain ⟨κ, hκ, a', y', ⟨ha'y', ha'⟩⟩ := h₄ this
use κ, hκ
use Finsupp.total ι (κ →₀ R) R (fun i ↦ equivFunOnFinite.symm (a' i))
use Finsupp.total κ M R y'
constructor
· apply Finsupp.basisSingleOne.ext
intro i
simpa [total_apply, sum_fintype, single_apply] using ha'y' i
· ext j
simp only [total_apply, zero_smul, implies_true, sum_fintype, finset_sum_apply]
exact ha' j
tfae_have 5 → 4
· intro h₅ ι hi f x hfx
let f' : ι →₀ R := equivFunOnFinite.symm f
let x' : (ι →₀ R) →ₗ[R] M := Finsupp.total ι M R x
have : x' f' = 0 := by simpa [x', f', total_apply, sum_fintype] using hfx
obtain ⟨κ, hκ, a', y', ha'y', ha'⟩ := h₅ this
refine ⟨κ, hκ, fun i ↦ a' (single i 1), fun j ↦ y' (single j 1), fun i ↦ ?_, fun j ↦ ?_⟩
· simpa [x', ← map_smul, ← map_sum, smul_single] using
LinearMap.congr_fun ha'y' (Finsupp.single i 1)
· simp_rw [← smul_eq_mul, ← Finsupp.smul_apply, ← map_smul, ← finset_sum_apply, ← map_sum,
smul_single, smul_eq_mul, mul_one,
← (fun _ ↦ equivFunOnFinite_symm_apply_toFun _ _ : ∀ x, f' x = f x), univ_sum_single]
simpa using DFunLike.congr_fun ha' j
tfae_have 5 → 6
· intro h₅ N _ _ _ _ f x hfx
have ϕ := Module.Free.repr R N
have : (x ∘ₗ ϕ.symm) (ϕ f) = 0 := by simpa
obtain ⟨κ, hκ, a', y, ha'y, ha'⟩ := h₅ this
refine ⟨κ, hκ, a' ∘ₗ ϕ, y, ?_, ?_⟩
· simpa [LinearMap.comp_assoc] using congrArg (fun g ↦ (g ∘ₗ ϕ : N →ₗ[R] M)) ha'y
· simpa using ha'
tfae_have 6 → 5
· intro h₆ _ _ _ _ hfx
exact h₆ hfx
tfae_finish
/-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK).
A module $M$ is flat if and only if every relation $\sum_i f_i x_i = 0$ in $M$ is trivial. -/
theorem iff_forall_isTrivialRelation : Flat R M ↔ ∀ {ι : Type u} [Fintype ι] {f : ι → R}
{x : ι → M}, ∑ i, f i • x i = 0 → IsTrivialRelation f x :=
(tfae_equational_criterion R M).out 0 3
/-- **Equational criterion for flatness**
[Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), forward direction.
If $M$ is flat, then every relation $\sum_i f_i x_i = 0$ in $M$ is trivial. -/
theorem isTrivialRelation_of_sum_smul_eq_zero [Flat R M] {ι : Type u} [Fintype ι] {f : ι → R}
{x : ι → M} (h : ∑ i, f i • x i = 0) : IsTrivialRelation f x :=
iff_forall_isTrivialRelation.mp ‹Flat R M› h
/-- **Equational criterion for flatness**
[Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), backward direction.
If every relation $\sum_i f_i x_i = 0$ in $M$ is trivial, then $M$ is flat. -/
theorem of_forall_isTrivialRelation (hfx : ∀ {ι : Type u} [Fintype ι] {f : ι → R} {x : ι → M},
∑ i, f i • x i = 0 → IsTrivialRelation f x) : Flat R M :=
iff_forall_isTrivialRelation.mpr hfx
/-- **Equational criterion for flatness**
[Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), alternate form.
A module $M$ is flat if and only if for all finite free modules $R^\iota$,
all $f \in R^{\iota}$, and all homomorphisms $x \colon R^{\iota} \to M$ such that $x(f) = 0$, there
exist a finite free module $R^\kappa$ and homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and
$y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. -/
theorem iff_forall_exists_factorization : Flat R M ↔
∀ {ι : Type u} [Fintype ι] {f : ι →₀ R} {x : (ι →₀ R) →ₗ[R] M}, x f = 0 →
∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M),
x = y ∘ₗ a ∧ a f = 0 := (tfae_equational_criterion R M).out 0 4
/-- **Equational criterion for flatness**
[Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), forward direction, alternate form.
Let $M$ be a flat module. Let $R^\iota$ be a finite free module, let $f \in R^{\iota}$ be an
element, and let $x \colon R^{\iota} \to M$ be a homomorphism such that $x(f) = 0$. Then there
exist a finite free module $R^\kappa$ and homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and
$y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. -/
theorem exists_factorization_of_apply_eq_zero [Flat R M] {ι : Type u} [Fintype ι]
{f : ι →₀ R} {x : (ι →₀ R) →ₗ[R] M} (h : x f = 0) :
∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M),
x = y ∘ₗ a ∧ a f = 0 := iff_forall_exists_factorization.mp ‹Flat R M› h
/-- **Equational criterion for flatness**
[Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK), backward direction, alternate form.
Let $M$ be a module over a commutative ring $R$. Suppose that for all finite free modules $R^\iota$,
all $f \in R^{\iota}$, and all homomorphisms $x \colon R^{\iota} \to M$ such that $x(f) = 0$, there
exist a finite free module $R^\kappa$ and homomorphisms $a \colon R^{\iota} \to R^{\kappa}$ and
$y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. Then $M$ is flat. -/
theorem of_forall_exists_factorization (h : ∀ {ι : Type u} [Fintype ι] {f : ι →₀ R}
{x : (ι →₀ R) →ₗ[R] M}, x f = 0 →
∃ (κ : Type u) (_ : Fintype κ) (a : (ι →₀ R) →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M),
x = y ∘ₗ a ∧ a f = 0) : Flat R M := iff_forall_exists_factorization.mpr h
/-- **Equational criterion for flatness** [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK),
forward direction, second alternate form.
Let $M$ be a flat module over a commutative ring $R$. Let $N$ be a finite free module over $R$,
let $f \in N$, and let $x \colon N \to M$ be a homomorphism such that $x(f) = 0$. Then there exist a
finite index type $\kappa$ and module homomorphisms $a \colon N \to R^{\kappa}$ and
$y \colon R^{\kappa} \to M$ such that $x = y \circ a$ and $a(f) = 0$. -/
| Mathlib/RingTheory/Flat/EquationalCriterion.lean | 248 | 252 | theorem exists_factorization_of_apply_eq_zero_of_free [Flat R M] {N : Type u}
[AddCommGroup N] [Module R N] [Free R N] [Finite R N] {f : N} {x : N →ₗ[R] M} (h : x f = 0) :
∃ (κ : Type u) (_ : Fintype κ) (a : N →ₗ[R] (κ →₀ R)) (y : (κ →₀ R) →ₗ[R] M),
x = y ∘ₗ a ∧ a f = 0 := by |
exact ((tfae_equational_criterion R M).out 0 5 rfl rfl).mp ‹Flat R M› h
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Ring.Divisibility.Lemmas
import Mathlib.Algebra.Lie.Nilpotent
import Mathlib.Algebra.Lie.Engel
import Mathlib.LinearAlgebra.Eigenspace.Triangularizable
import Mathlib.RingTheory.Artinian
import Mathlib.LinearAlgebra.Trace
import Mathlib.LinearAlgebra.FreeModule.PID
#align_import algebra.lie.weights from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1"
/-!
# Weight spaces of Lie modules of nilpotent Lie algebras
Just as a key tool when studying the behaviour of a linear operator is to decompose the space on
which it acts into a sum of (generalised) eigenspaces, a key tool when studying a representation `M`
of Lie algebra `L` is to decompose `M` into a sum of simultaneous eigenspaces of `x` as `x` ranges
over `L`. These simultaneous generalised eigenspaces are known as the weight spaces of `M`.
When `L` is nilpotent, it follows from the binomial theorem that weight spaces are Lie submodules.
Basic definitions and properties of the above ideas are provided in this file.
## Main definitions
* `LieModule.weightSpaceOf`
* `LieModule.weightSpace`
* `LieModule.Weight`
* `LieModule.posFittingCompOf`
* `LieModule.posFittingComp`
* `LieModule.iSup_ucs_eq_weightSpace_zero`
* `LieModule.iInf_lowerCentralSeries_eq_posFittingComp`
* `LieModule.isCompl_weightSpace_zero_posFittingComp`
* `LieModule.independent_weightSpace`
* `LieModule.iSup_weightSpace_eq_top`
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b)
## Tags
lie character, eigenvalue, eigenspace, weight, weight vector, root, root vector
-/
variable {K R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [LieAlgebra.IsNilpotent R L]
[AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
namespace LieModule
open Set Function LieAlgebra TensorProduct TensorProduct.LieModule
open scoped TensorProduct
section notation_weightSpaceOf
/-- Until we define `LieModule.weightSpaceOf`, it is useful to have some notation as follows: -/
local notation3 "𝕎("M", " χ", " x")" => (toEnd R L M x).maxGenEigenspace χ
/-- See also `bourbaki1975b` Chapter VII §1.1, Proposition 2 (ii). -/
protected theorem weight_vector_multiplication (M₁ M₂ M₃ : Type*)
[AddCommGroup M₁] [Module R M₁] [LieRingModule L M₁] [LieModule R L M₁] [AddCommGroup M₂]
[Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] [AddCommGroup M₃] [Module R M₃]
[LieRingModule L M₃] [LieModule R L M₃] (g : M₁ ⊗[R] M₂ →ₗ⁅R,L⁆ M₃) (χ₁ χ₂ : R) (x : L) :
LinearMap.range ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (mapIncl 𝕎(M₁, χ₁, x) 𝕎(M₂, χ₂, x))) ≤
𝕎(M₃, χ₁ + χ₂, x) := by
-- Unpack the statement of the goal.
intro m₃
simp only [TensorProduct.mapIncl, LinearMap.mem_range, LinearMap.coe_comp,
LieModuleHom.coe_toLinearMap, Function.comp_apply, Pi.add_apply, exists_imp,
Module.End.mem_maxGenEigenspace]
rintro t rfl
-- Set up some notation.
let F : Module.End R M₃ := toEnd R L M₃ x - (χ₁ + χ₂) • ↑1
-- The goal is linear in `t` so use induction to reduce to the case that `t` is a pure tensor.
refine t.induction_on ?_ ?_ ?_
· use 0; simp only [LinearMap.map_zero, LieModuleHom.map_zero]
swap
· rintro t₁ t₂ ⟨k₁, hk₁⟩ ⟨k₂, hk₂⟩; use max k₁ k₂
simp only [LieModuleHom.map_add, LinearMap.map_add,
LinearMap.pow_map_zero_of_le (le_max_left k₁ k₂) hk₁,
LinearMap.pow_map_zero_of_le (le_max_right k₁ k₂) hk₂, add_zero]
-- Now the main argument: pure tensors.
rintro ⟨m₁, hm₁⟩ ⟨m₂, hm₂⟩
change ∃ k, (F ^ k) ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃) (m₁ ⊗ₜ m₂)) = (0 : M₃)
-- Eliminate `g` from the picture.
let f₁ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₁ x - χ₁ • ↑1).rTensor M₂
let f₂ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₂ x - χ₂ • ↑1).lTensor M₁
have h_comm_square : F ∘ₗ ↑g = (g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (f₁ + f₂) := by
ext m₁ m₂;
simp only [f₁, f₂, F, ← g.map_lie x (m₁ ⊗ₜ m₂), add_smul, sub_tmul, tmul_sub, smul_tmul,
lie_tmul_right, tmul_smul, toEnd_apply_apply, LieModuleHom.map_smul,
LinearMap.one_apply, LieModuleHom.coe_toLinearMap, LinearMap.smul_apply, Function.comp_apply,
LinearMap.coe_comp, LinearMap.rTensor_tmul, LieModuleHom.map_add, LinearMap.add_apply,
LieModuleHom.map_sub, LinearMap.sub_apply, LinearMap.lTensor_tmul,
AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, LinearMap.toFun_eq_coe,
LinearMap.coe_restrictScalars]
abel
rsuffices ⟨k, hk⟩ : ∃ k : ℕ, ((f₁ + f₂) ^ k) (m₁ ⊗ₜ m₂) = 0
· use k
change (F ^ k) (g.toLinearMap (m₁ ⊗ₜ[R] m₂)) = 0
rw [← LinearMap.comp_apply, LinearMap.commute_pow_left_of_commute h_comm_square,
LinearMap.comp_apply, hk, LinearMap.map_zero]
-- Unpack the information we have about `m₁`, `m₂`.
simp only [Module.End.mem_maxGenEigenspace] at hm₁ hm₂
obtain ⟨k₁, hk₁⟩ := hm₁
obtain ⟨k₂, hk₂⟩ := hm₂
have hf₁ : (f₁ ^ k₁) (m₁ ⊗ₜ m₂) = 0 := by
simp only [f₁, hk₁, zero_tmul, LinearMap.rTensor_tmul, LinearMap.rTensor_pow]
have hf₂ : (f₂ ^ k₂) (m₁ ⊗ₜ m₂) = 0 := by
simp only [f₂, hk₂, tmul_zero, LinearMap.lTensor_tmul, LinearMap.lTensor_pow]
-- It's now just an application of the binomial theorem.
use k₁ + k₂ - 1
have hf_comm : Commute f₁ f₂ := by
ext m₁ m₂
simp only [f₁, f₂, LinearMap.mul_apply, LinearMap.rTensor_tmul, LinearMap.lTensor_tmul,
AlgebraTensorModule.curry_apply, LinearMap.toFun_eq_coe, LinearMap.lTensor_tmul,
TensorProduct.curry_apply, LinearMap.coe_restrictScalars]
rw [hf_comm.add_pow']
simp only [TensorProduct.mapIncl, Submodule.subtype_apply, Finset.sum_apply, Submodule.coe_mk,
LinearMap.coeFn_sum, TensorProduct.map_tmul, LinearMap.smul_apply]
-- The required sum is zero because each individual term is zero.
apply Finset.sum_eq_zero
rintro ⟨i, j⟩ hij
-- Eliminate the binomial coefficients from the picture.
suffices (f₁ ^ i * f₂ ^ j) (m₁ ⊗ₜ m₂) = 0 by rw [this]; apply smul_zero
-- Finish off with appropriate case analysis.
cases' Nat.le_or_le_of_add_eq_add_pred (Finset.mem_antidiagonal.mp hij) with hi hj
· rw [(hf_comm.pow_pow i j).eq, LinearMap.mul_apply, LinearMap.pow_map_zero_of_le hi hf₁,
LinearMap.map_zero]
· rw [LinearMap.mul_apply, LinearMap.pow_map_zero_of_le hj hf₂, LinearMap.map_zero]
lemma lie_mem_maxGenEigenspace_toEnd
{χ₁ χ₂ : R} {x y : L} {m : M} (hy : y ∈ 𝕎(L, χ₁, x)) (hm : m ∈ 𝕎(M, χ₂, x)) :
⁅y, m⁆ ∈ 𝕎(M, χ₁ + χ₂, x) := by
apply LieModule.weight_vector_multiplication L M M (toModuleHom R L M) χ₁ χ₂
simp only [LieModuleHom.coe_toLinearMap, Function.comp_apply, LinearMap.coe_comp,
TensorProduct.mapIncl, LinearMap.mem_range]
use ⟨y, hy⟩ ⊗ₜ ⟨m, hm⟩
simp only [Submodule.subtype_apply, toModuleHom_apply, TensorProduct.map_tmul]
variable (M)
/-- If `M` is a representation of a nilpotent Lie algebra `L`, `χ` is a scalar, and `x : L`, then
`weightSpaceOf M χ x` is the maximal generalized `χ`-eigenspace of the action of `x` on `M`.
It is a Lie submodule because `L` is nilpotent. -/
def weightSpaceOf (χ : R) (x : L) : LieSubmodule R L M :=
{ 𝕎(M, χ, x) with
lie_mem := by
intro y m hm
simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup,
Submodule.mem_toAddSubmonoid] at hm ⊢
rw [← zero_add χ]
exact lie_mem_maxGenEigenspace_toEnd (by simp) hm }
end notation_weightSpaceOf
variable (M)
theorem mem_weightSpaceOf (χ : R) (x : L) (m : M) :
m ∈ weightSpaceOf M χ x ↔ ∃ k : ℕ, ((toEnd R L M x - χ • ↑1) ^ k) m = 0 := by
simp [weightSpaceOf]
theorem coe_weightSpaceOf_zero (x : L) :
↑(weightSpaceOf M (0 : R) x) = ⨆ k, LinearMap.ker (toEnd R L M x ^ k) := by
simp [weightSpaceOf, Module.End.maxGenEigenspace]
/-- If `M` is a representation of a nilpotent Lie algebra `L` and `χ : L → R` is a family of
scalars, then `weightSpace M χ` is the intersection of the maximal generalized `χ x`-eigenspaces of
the action of `x` on `M` as `x` ranges over `L`.
It is a Lie submodule because `L` is nilpotent. -/
def weightSpace (χ : L → R) : LieSubmodule R L M :=
⨅ x, weightSpaceOf M (χ x) x
theorem mem_weightSpace (χ : L → R) (m : M) :
m ∈ weightSpace M χ ↔ ∀ x, ∃ k : ℕ, ((toEnd R L M x - χ x • ↑1) ^ k) m = 0 := by
simp [weightSpace, mem_weightSpaceOf]
lemma weightSpace_le_weightSpaceOf (x : L) (χ : L → R) :
weightSpace M χ ≤ weightSpaceOf M (χ x) x :=
iInf_le _ x
variable (R L) in
/-- A weight of a Lie module is a map `L → R` such that the corresponding weight space is
non-trivial. -/
structure Weight where
/-- The family of eigenvalues corresponding to a weight. -/
toFun : L → R
weightSpace_ne_bot' : weightSpace M toFun ≠ ⊥
namespace Weight
instance instFunLike : FunLike (Weight R L M) L R where
coe χ := χ.1
coe_injective' χ₁ χ₂ h := by cases χ₁; cases χ₂; simp_all
@[simp] lemma coe_weight_mk (χ : L → R) (h) :
(↑(⟨χ, h⟩ : Weight R L M) : L → R) = χ :=
rfl
lemma weightSpace_ne_bot (χ : Weight R L M) : weightSpace M χ ≠ ⊥ := χ.weightSpace_ne_bot'
variable {M}
@[ext] lemma ext {χ₁ χ₂ : Weight R L M} (h : ∀ x, χ₁ x = χ₂ x) : χ₁ = χ₂ := by
cases' χ₁ with f₁ _; cases' χ₂ with f₂ _; aesop
lemma ext_iff {χ₁ χ₂ : Weight R L M} : (χ₁ : L → R) = χ₂ ↔ χ₁ = χ₂ := by aesop
lemma exists_ne_zero (χ : Weight R L M) :
∃ x ∈ weightSpace M χ, x ≠ 0 := by
simpa [LieSubmodule.eq_bot_iff] using χ.weightSpace_ne_bot
instance [Subsingleton M] : IsEmpty (Weight R L M) :=
⟨fun h ↦ h.2 (Subsingleton.elim _ _)⟩
instance [Nontrivial (weightSpace M (0 : L → R))] : Zero (Weight R L M) :=
⟨0, fun e ↦ not_nontrivial (⊥ : LieSubmodule R L M) (e ▸ ‹_›)⟩
@[simp]
lemma coe_zero [Nontrivial (weightSpace M (0 : L → R))] : ((0 : Weight R L M) : L → R) = 0 := rfl
lemma zero_apply [Nontrivial (weightSpace M (0 : L → R))] (x) : (0 : Weight R L M) x = 0 := rfl
/-- The proposition that a weight of a Lie module is zero.
We make this definition because we cannot define a `Zero (Weight R L M)` instance since the weight
space of the zero function can be trivial. -/
def IsZero (χ : Weight R L M) := (χ : L → R) = 0
@[simp] lemma IsZero.eq {χ : Weight R L M} (hχ : χ.IsZero) : (χ : L → R) = 0 := hχ
@[simp] lemma coe_eq_zero_iff (χ : Weight R L M) : (χ : L → R) = 0 ↔ χ.IsZero := Iff.rfl
lemma isZero_iff_eq_zero [Nontrivial (weightSpace M (0 : L → R))] {χ : Weight R L M} :
χ.IsZero ↔ χ = 0 := ext_iff (χ₂ := 0)
lemma isZero_zero [Nontrivial (weightSpace M (0 : L → R))] : IsZero (0 : Weight R L M) := rfl
/-- The proposition that a weight of a Lie module is non-zero. -/
abbrev IsNonZero (χ : Weight R L M) := ¬ IsZero (χ : Weight R L M)
lemma isNonZero_iff_ne_zero [Nontrivial (weightSpace M (0 : L → R))] {χ : Weight R L M} :
χ.IsNonZero ↔ χ ≠ 0 := isZero_iff_eq_zero.not
variable (R L M) in
/-- The set of weights is equivalent to a subtype. -/
def equivSetOf : Weight R L M ≃ {χ : L → R | weightSpace M χ ≠ ⊥} where
toFun w := ⟨w.1, w.2⟩
invFun w := ⟨w.1, w.2⟩
left_inv w := by simp
right_inv w := by simp
lemma weightSpaceOf_ne_bot (χ : Weight R L M) (x : L) :
weightSpaceOf M (χ x) x ≠ ⊥ := by
have : ⨅ x, weightSpaceOf M (χ x) x ≠ ⊥ := χ.weightSpace_ne_bot
contrapose! this
rw [eq_bot_iff]
exact le_of_le_of_eq (iInf_le _ _) this
lemma hasEigenvalueAt (χ : Weight R L M) (x : L) :
(toEnd R L M x).HasEigenvalue (χ x) := by
obtain ⟨k : ℕ, hk : (toEnd R L M x).genEigenspace (χ x) k ≠ ⊥⟩ := by
simpa [Module.End.maxGenEigenspace, weightSpaceOf] using χ.weightSpaceOf_ne_bot x
exact Module.End.hasEigenvalue_of_hasGenEigenvalue hk
lemma apply_eq_zero_of_isNilpotent [NoZeroSMulDivisors R M] [IsReduced R]
(x : L) (h : _root_.IsNilpotent (toEnd R L M x)) (χ : Weight R L M) :
χ x = 0 :=
((χ.hasEigenvalueAt x).isNilpotent_of_isNilpotent h).eq_zero
end Weight
/-- See also the more useful form `LieModule.zero_weightSpace_eq_top_of_nilpotent`. -/
@[simp]
theorem zero_weightSpace_eq_top_of_nilpotent' [IsNilpotent R L M] :
weightSpace M (0 : L → R) = ⊤ := by
ext
simp [weightSpace, weightSpaceOf]
#align lie_module.zero_weight_space_eq_top_of_nilpotent' LieModule.zero_weightSpace_eq_top_of_nilpotent'
theorem coe_weightSpace_of_top (χ : L → R) :
(weightSpace M (χ ∘ (⊤ : LieSubalgebra R L).incl) : Submodule R M) = weightSpace M χ := by
ext m
simp only [mem_weightSpace, LieSubmodule.mem_coeSubmodule, Subtype.forall]
apply forall_congr'
simp
#align lie_module.coe_weight_space_of_top LieModule.coe_weightSpace_of_top
@[simp]
theorem zero_weightSpace_eq_top_of_nilpotent [IsNilpotent R L M] :
weightSpace M (0 : (⊤ : LieSubalgebra R L) → R) = ⊤ := by
ext m
simp only [mem_weightSpace, Pi.zero_apply, zero_smul, sub_zero, Subtype.forall, forall_true_left,
LieSubalgebra.toEnd_mk, LieSubalgebra.mem_top, LieSubmodule.mem_top, iff_true]
intro x
obtain ⟨k, hk⟩ := exists_forall_pow_toEnd_eq_zero R L M
exact ⟨k, by simp [hk x]⟩
#align lie_module.zero_weight_space_eq_top_of_nilpotent LieModule.zero_weightSpace_eq_top_of_nilpotent
theorem exists_weightSpace_le_ker_of_isNoetherian [IsNoetherian R M] (χ : L → R) (x : L) :
∃ k : ℕ,
weightSpace M χ ≤ LinearMap.ker ((toEnd R L M x - algebraMap R _ (χ x)) ^ k) := by
use (toEnd R L M x).maxGenEigenspaceIndex (χ x)
intro m hm
replace hm : m ∈ (toEnd R L M x).maxGenEigenspace (χ x) :=
weightSpace_le_weightSpaceOf M x χ hm
rwa [Module.End.maxGenEigenspace_eq] at hm
variable (R) in
theorem exists_weightSpace_zero_le_ker_of_isNoetherian
[IsNoetherian R M] (x : L) :
∃ k : ℕ, weightSpace M (0 : L → R) ≤ LinearMap.ker (toEnd R L M x ^ k) := by
simpa using exists_weightSpace_le_ker_of_isNoetherian M (0 : L → R) x
lemma isNilpotent_toEnd_sub_algebraMap [IsNoetherian R M] (χ : L → R) (x : L) :
_root_.IsNilpotent <| toEnd R L (weightSpace M χ) x - algebraMap R _ (χ x) := by
have : toEnd R L (weightSpace M χ) x - algebraMap R _ (χ x) =
(toEnd R L M x - algebraMap R _ (χ x)).restrict
(fun m hm ↦ sub_mem (LieSubmodule.lie_mem _ hm) (Submodule.smul_mem _ _ hm)) := by
rfl
obtain ⟨k, hk⟩ := exists_weightSpace_le_ker_of_isNoetherian M χ x
use k
ext ⟨m, hm⟩
simpa [this, LinearMap.pow_restrict _, LinearMap.restrict_apply] using hk hm
/-- A (nilpotent) Lie algebra acts nilpotently on the zero weight space of a Noetherian Lie
module. -/
| Mathlib/Algebra/Lie/Weights/Basic.lean | 334 | 336 | theorem isNilpotent_toEnd_weightSpace_zero [IsNoetherian R M] (x : L) :
_root_.IsNilpotent <| toEnd R L (weightSpace M (0 : L → R)) x := by |
simpa using isNilpotent_toEnd_sub_algebraMap M (0 : L → R) x
|
/-
Copyright (c) 2022 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.BigOperators.NatAntidiagonal
import Mathlib.Algebra.CharZero.Lemmas
import Mathlib.Data.Finset.NatAntidiagonal
import Mathlib.Data.Nat.Choose.Central
import Mathlib.Data.Tree.Basic
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.Positivity
#align_import combinatorics.catalan from "leanprover-community/mathlib"@"26b40791e4a5772a4e53d0e28e4df092119dc7da"
/-!
# Catalan numbers
The Catalan numbers (http://oeis.org/A000108) are probably the most ubiquitous sequence of integers
in mathematics. They enumerate several important objects like binary trees, Dyck paths, and
triangulations of convex polygons.
## Main definitions
* `catalan n`: the `n`th Catalan number, defined recursively as
`catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)`.
## Main results
* `catalan_eq_centralBinom_div`: The explicit formula for the Catalan number using the central
binomial coefficient, `catalan n = Nat.centralBinom n / (n + 1)`.
* `treesOfNodesEq_card_eq_catalan`: The number of binary trees with `n` internal nodes
is `catalan n`
## Implementation details
The proof of `catalan_eq_centralBinom_div` follows https://math.stackexchange.com/questions/3304415
## TODO
* Prove that the Catalan numbers enumerate many interesting objects.
* Provide the many variants of Catalan numbers, e.g. associated to complex reflection groups,
Fuss-Catalan, etc.
-/
open Finset
open Finset.antidiagonal (fst_le snd_le)
/-- The recursive definition of the sequence of Catalan numbers:
`catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)` -/
def catalan : ℕ → ℕ
| 0 => 1
| n + 1 =>
∑ i : Fin n.succ,
catalan i * catalan (n - i)
#align catalan catalan
@[simp]
theorem catalan_zero : catalan 0 = 1 := by rw [catalan]
#align catalan_zero catalan_zero
theorem catalan_succ (n : ℕ) : catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i) := by
rw [catalan]
#align catalan_succ catalan_succ
theorem catalan_succ' (n : ℕ) :
catalan (n + 1) = ∑ ij ∈ antidiagonal n, catalan ij.1 * catalan ij.2 := by
rw [catalan_succ, Nat.sum_antidiagonal_eq_sum_range_succ (fun x y => catalan x * catalan y) n,
sum_range]
#align catalan_succ' catalan_succ'
@[simp]
| Mathlib/Combinatorics/Enumerative/Catalan.lean | 79 | 79 | theorem catalan_one : catalan 1 = 1 := by | simp [catalan_succ]
|
/-
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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Module.Submodule.EqLocus
import Mathlib.Algebra.Module.Submodule.RestrictScalars
import Mathlib.Algebra.Ring.Idempotents
import Mathlib.Data.Set.Pointwise.SMul
import Mathlib.LinearAlgebra.Basic
import Mathlib.Order.CompactlyGenerated.Basic
import Mathlib.Order.OmegaCompletePartialOrder
#align_import linear_algebra.span from "leanprover-community/mathlib"@"10878f6bf1dab863445907ab23fbfcefcb5845d0"
/-!
# The span of a set of vectors, as a submodule
* `Submodule.span s` is defined to be the smallest submodule containing the set `s`.
## Notations
* We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is
`\span`, not the same as the scalar multiplication `•`/`\bub`.
-/
variable {R R₂ K M M₂ V S : Type*}
namespace Submodule
open Function Set
open Pointwise
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable {x : M} (p p' : Submodule R M)
variable [Semiring R₂] {σ₁₂ : R →+* R₂}
variable [AddCommMonoid M₂] [Module R₂ M₂]
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
section
variable (R)
/-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/
def span (s : Set M) : Submodule R M :=
sInf { p | s ⊆ p }
#align submodule.span Submodule.span
variable {R}
-- Porting note: renamed field to `principal'` and added `principal` to fix explicit argument
/-- An `R`-submodule of `M` is principal if it is generated by one element. -/
@[mk_iff]
class IsPrincipal (S : Submodule R M) : Prop where
principal' : ∃ a, S = span R {a}
#align submodule.is_principal Submodule.IsPrincipal
theorem IsPrincipal.principal (S : Submodule R M) [S.IsPrincipal] :
∃ a, S = span R {a} :=
Submodule.IsPrincipal.principal'
#align submodule.is_principal.principal Submodule.IsPrincipal.principal
end
variable {s t : Set M}
theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p :=
mem_iInter₂
#align submodule.mem_span Submodule.mem_span
@[aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h
#align submodule.subset_span Submodule.subset_span
theorem span_le {p} : span R s ≤ p ↔ s ⊆ p :=
⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩
#align submodule.span_le Submodule.span_le
theorem span_mono (h : s ⊆ t) : span R s ≤ span R t :=
span_le.2 <| Subset.trans h subset_span
#align submodule.span_mono Submodule.span_mono
theorem span_monotone : Monotone (span R : Set M → Submodule R M) := fun _ _ => span_mono
#align submodule.span_monotone Submodule.span_monotone
theorem span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p :=
le_antisymm (span_le.2 h₁) h₂
#align submodule.span_eq_of_le Submodule.span_eq_of_le
theorem span_eq : span R (p : Set M) = p :=
span_eq_of_le _ (Subset.refl _) subset_span
#align submodule.span_eq Submodule.span_eq
theorem span_eq_span (hs : s ⊆ span R t) (ht : t ⊆ span R s) : span R s = span R t :=
le_antisymm (span_le.2 hs) (span_le.2 ht)
#align submodule.span_eq_span Submodule.span_eq_span
/-- A version of `Submodule.span_eq` for subobjects closed under addition and scalar multiplication
and containing zero. In general, this should not be used directly, but can be used to quickly
generate proofs for specific types of subobjects. -/
lemma coe_span_eq_self [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) :
(span R (s : Set M) : Set M) = s := by
refine le_antisymm ?_ subset_span
let s' : Submodule R M :=
{ carrier := s
add_mem' := add_mem
zero_mem' := zero_mem _
smul_mem' := SMulMemClass.smul_mem }
exact span_le (p := s') |>.mpr le_rfl
/-- A version of `Submodule.span_eq` for when the span is by a smaller ring. -/
@[simp]
theorem span_coe_eq_restrictScalars [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] :
span S (p : Set M) = p.restrictScalars S :=
span_eq (p.restrictScalars S)
#align submodule.span_coe_eq_restrict_scalars Submodule.span_coe_eq_restrictScalars
/-- A version of `Submodule.map_span_le` that does not require the `RingHomSurjective`
assumption. -/
theorem image_span_subset (f : F) (s : Set M) (N : Submodule R₂ M₂) :
f '' span R s ⊆ N ↔ ∀ m ∈ s, f m ∈ N := image_subset_iff.trans <| span_le (p := N.comap f)
theorem image_span_subset_span (f : F) (s : Set M) : f '' span R s ⊆ span R₂ (f '' s) :=
(image_span_subset f s _).2 fun x hx ↦ subset_span ⟨x, hx, rfl⟩
theorem map_span [RingHomSurjective σ₁₂] (f : F) (s : Set M) :
(span R s).map f = span R₂ (f '' s) :=
Eq.symm <| span_eq_of_le _ (Set.image_subset f subset_span) (image_span_subset_span f s)
#align submodule.map_span Submodule.map_span
alias _root_.LinearMap.map_span := Submodule.map_span
#align linear_map.map_span LinearMap.map_span
theorem map_span_le [RingHomSurjective σ₁₂] (f : F) (s : Set M) (N : Submodule R₂ M₂) :
map f (span R s) ≤ N ↔ ∀ m ∈ s, f m ∈ N := image_span_subset f s N
#align submodule.map_span_le Submodule.map_span_le
alias _root_.LinearMap.map_span_le := Submodule.map_span_le
#align linear_map.map_span_le LinearMap.map_span_le
@[simp]
theorem span_insert_zero : span R (insert (0 : M) s) = span R s := by
refine le_antisymm ?_ (Submodule.span_mono (Set.subset_insert 0 s))
rw [span_le, Set.insert_subset_iff]
exact ⟨by simp only [SetLike.mem_coe, Submodule.zero_mem], Submodule.subset_span⟩
#align submodule.span_insert_zero Submodule.span_insert_zero
-- See also `span_preimage_eq` below.
theorem span_preimage_le (f : F) (s : Set M₂) :
span R (f ⁻¹' s) ≤ (span R₂ s).comap f := by
rw [span_le, comap_coe]
exact preimage_mono subset_span
#align submodule.span_preimage_le Submodule.span_preimage_le
alias _root_.LinearMap.span_preimage_le := Submodule.span_preimage_le
#align linear_map.span_preimage_le LinearMap.span_preimage_le
theorem closure_subset_span {s : Set M} : (AddSubmonoid.closure s : Set M) ⊆ span R s :=
(@AddSubmonoid.closure_le _ _ _ (span R s).toAddSubmonoid).mpr subset_span
#align submodule.closure_subset_span Submodule.closure_subset_span
theorem closure_le_toAddSubmonoid_span {s : Set M} :
AddSubmonoid.closure s ≤ (span R s).toAddSubmonoid :=
closure_subset_span
#align submodule.closure_le_to_add_submonoid_span Submodule.closure_le_toAddSubmonoid_span
@[simp]
theorem span_closure {s : Set M} : span R (AddSubmonoid.closure s : Set M) = span R s :=
le_antisymm (span_le.mpr closure_subset_span) (span_mono AddSubmonoid.subset_closure)
#align submodule.span_closure Submodule.span_closure
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition and scalar multiplication, then `p` holds for all elements of the span of
`s`. -/
@[elab_as_elim]
theorem span_induction {p : M → Prop} (h : x ∈ span R s) (mem : ∀ x ∈ s, p x) (zero : p 0)
(add : ∀ x y, p x → p y → p (x + y)) (smul : ∀ (a : R) (x), p x → p (a • x)) : p x :=
((@span_le (p := ⟨⟨⟨p, by intros x y; exact add x y⟩, zero⟩, smul⟩)) s).2 mem h
#align submodule.span_induction Submodule.span_induction
/-- An induction principle for span membership. This is a version of `Submodule.span_induction`
for binary predicates. -/
theorem span_induction₂ {p : M → M → Prop} {a b : M} (ha : a ∈ Submodule.span R s)
(hb : b ∈ Submodule.span R s) (mem_mem : ∀ x ∈ s, ∀ y ∈ s, p x y)
(zero_left : ∀ y, p 0 y) (zero_right : ∀ x, p x 0)
(add_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y)
(add_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂))
(smul_left : ∀ (r : R) x y, p x y → p (r • x) y)
(smul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b :=
Submodule.span_induction ha
(fun x hx => Submodule.span_induction hb (mem_mem x hx) (zero_right x) (add_right x) fun r =>
smul_right r x)
(zero_left b) (fun x₁ x₂ => add_left x₁ x₂ b) fun r x => smul_left r x b
/-- A dependent version of `Submodule.span_induction`. -/
@[elab_as_elim]
theorem span_induction' {p : ∀ x, x ∈ span R s → Prop}
(mem : ∀ (x) (h : x ∈ s), p x (subset_span h))
(zero : p 0 (Submodule.zero_mem _))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›))
(smul : ∀ (a : R) (x hx), p x hx → p (a • x) (Submodule.smul_mem _ _ ‹_›)) {x}
(hx : x ∈ span R s) : p x hx := by
refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) => hc
refine
span_induction hx (fun m hm => ⟨subset_span hm, mem m hm⟩) ⟨zero_mem _, zero⟩
(fun x y hx hy =>
Exists.elim hx fun hx' hx =>
Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩)
fun r x hx => Exists.elim hx fun hx' hx => ⟨smul_mem _ _ hx', smul r _ _ hx⟩
#align submodule.span_induction' Submodule.span_induction'
open AddSubmonoid in
theorem span_eq_closure {s : Set M} : (span R s).toAddSubmonoid = closure (@univ R • s) := by
refine le_antisymm
(fun x hx ↦ span_induction hx (fun x hx ↦ subset_closure ⟨1, trivial, x, hx, one_smul R x⟩)
(zero_mem _) (fun _ _ ↦ add_mem) fun r m hm ↦ closure_induction hm ?_ ?_ fun _ _ h h' ↦ ?_)
(closure_le.2 ?_)
· rintro _ ⟨r, -, m, hm, rfl⟩; exact smul_mem _ _ (subset_span hm)
· rintro _ ⟨r', -, m, hm, rfl⟩; exact subset_closure ⟨r * r', trivial, m, hm, mul_smul r r' m⟩
· rw [smul_zero]; apply zero_mem
· rw [smul_add]; exact add_mem h h'
/-- A variant of `span_induction` that combines `∀ x ∈ s, p x` and `∀ r x, p x → p (r • x)`
into a single condition `∀ r, ∀ x ∈ s, p (r • x)`, which can be easier to verify. -/
@[elab_as_elim]
theorem closure_induction {p : M → Prop} (h : x ∈ span R s) (zero : p 0)
(add : ∀ x y, p x → p y → p (x + y)) (smul_mem : ∀ r : R, ∀ x ∈ s, p (r • x)) : p x := by
rw [← mem_toAddSubmonoid, span_eq_closure] at h
refine AddSubmonoid.closure_induction h ?_ zero add
rintro _ ⟨r, -, m, hm, rfl⟩
exact smul_mem r m hm
/-- A dependent version of `Submodule.closure_induction`. -/
@[elab_as_elim]
theorem closure_induction' {p : ∀ x, x ∈ span R s → Prop}
(zero : p 0 (Submodule.zero_mem _))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›))
(smul_mem : ∀ (r x) (h : x ∈ s), p (r • x) (Submodule.smul_mem _ _ <| subset_span h)) {x}
(hx : x ∈ span R s) : p x hx := by
refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) ↦ hc
refine closure_induction hx ⟨zero_mem _, zero⟩
(fun x y hx hy ↦ Exists.elim hx fun hx' hx ↦
Exists.elim hy fun hy' hy ↦ ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩)
fun r x hx ↦ ⟨Submodule.smul_mem _ _ (subset_span hx), smul_mem r x hx⟩
@[simp]
theorem span_span_coe_preimage : span R (((↑) : span R s → M) ⁻¹' s) = ⊤ :=
eq_top_iff.2 fun x ↦ Subtype.recOn x fun x hx _ ↦ by
refine span_induction' (p := fun x hx ↦ (⟨x, hx⟩ : span R s) ∈ span R (Subtype.val ⁻¹' s))
(fun x' hx' ↦ subset_span hx') ?_ (fun x _ y _ ↦ ?_) (fun r x _ ↦ ?_) hx
· exact zero_mem _
· exact add_mem
· exact smul_mem _ _
#align submodule.span_span_coe_preimage Submodule.span_span_coe_preimage
@[simp]
lemma span_setOf_mem_eq_top :
span R {x : span R s | (x : M) ∈ s} = ⊤ :=
span_span_coe_preimage
theorem span_nat_eq_addSubmonoid_closure (s : Set M) :
(span ℕ s).toAddSubmonoid = AddSubmonoid.closure s := by
refine Eq.symm (AddSubmonoid.closure_eq_of_le subset_span ?_)
apply (OrderIso.to_galoisConnection (AddSubmonoid.toNatSubmodule (M := M)).symm).l_le
(a := span ℕ s) (b := AddSubmonoid.closure s)
rw [span_le]
exact AddSubmonoid.subset_closure
#align submodule.span_nat_eq_add_submonoid_closure Submodule.span_nat_eq_addSubmonoid_closure
@[simp]
| Mathlib/LinearAlgebra/Span.lean | 276 | 277 | theorem span_nat_eq (s : AddSubmonoid M) : (span ℕ (s : Set M)).toAddSubmonoid = s := by |
rw [span_nat_eq_addSubmonoid_closure, s.closure_eq]
|
/-
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]
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 1,575 | 1,577 | theorem leadingCoeff_pow_X_add_C (r : R) (i : ℕ) : leadingCoeff ((X + C r) ^ i) = 1 := by |
nontriviality
rw [leadingCoeff_pow'] <;> simp
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.OfAssociative
import Mathlib.Algebra.Lie.IdealOperations
#align_import algebra.lie.abelian from "leanprover-community/mathlib"@"8983bec7cdf6cb2dd1f21315c8a34ab00d7b2f6d"
/-!
# Trivial Lie modules and Abelian Lie algebras
The action of a Lie algebra `L` on a module `M` is trivial if `⁅x, m⁆ = 0` for all `x ∈ L` and
`m ∈ M`. In the special case that `M = L` with the adjoint action, triviality corresponds to the
concept of an Abelian Lie algebra.
In this file we define these concepts and provide some related definitions and results.
## Main definitions
* `LieModule.IsTrivial`
* `IsLieAbelian`
* `commutative_ring_iff_abelian_lie_ring`
* `LieModule.ker`
* `LieModule.maxTrivSubmodule`
* `LieAlgebra.center`
## Tags
lie algebra, abelian, commutative, center
-/
universe u v w w₁ w₂
/-- A Lie (ring) module is trivial iff all brackets vanish. -/
class LieModule.IsTrivial (L : Type v) (M : Type w) [Bracket L M] [Zero M] : Prop where
trivial : ∀ (x : L) (m : M), ⁅x, m⁆ = 0
#align lie_module.is_trivial LieModule.IsTrivial
@[simp]
theorem trivial_lie_zero (L : Type v) (M : Type w) [Bracket L M] [Zero M] [LieModule.IsTrivial L M]
(x : L) (m : M) : ⁅x, m⁆ = 0 :=
LieModule.IsTrivial.trivial x m
#align trivial_lie_zero trivial_lie_zero
instance LieModule.instIsTrivialOfSubsingleton {L M : Type*}
[LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton L] : LieModule.IsTrivial L M :=
⟨fun x m ↦ by rw [Subsingleton.eq_zero x, zero_lie]⟩
instance LieModule.instIsTrivialOfSubsingleton' {L M : Type*}
[LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton M] : LieModule.IsTrivial L M :=
⟨fun x m ↦ by simp_rw [Subsingleton.eq_zero m, lie_zero]⟩
/-- A Lie algebra is Abelian iff it is trivial as a Lie module over itself. -/
abbrev IsLieAbelian (L : Type v) [Bracket L L] [Zero L] : Prop :=
LieModule.IsTrivial L L
#align is_lie_abelian IsLieAbelian
instance LieIdeal.isLieAbelian_of_trivial (R : Type u) (L : Type v) [CommRing R] [LieRing L]
[LieAlgebra R L] (I : LieIdeal R L) [h : LieModule.IsTrivial L I] : IsLieAbelian I where
trivial x y := by apply h.trivial
#align lie_ideal.is_lie_abelian_of_trivial LieIdeal.isLieAbelian_of_trivial
theorem Function.Injective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R]
[LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂}
(h₁ : Function.Injective f) (_ : IsLieAbelian L₂) : IsLieAbelian L₁ :=
{ trivial := fun x y => h₁ <|
calc
f ⁅x, y⁆ = ⁅f x, f y⁆ := LieHom.map_lie f x y
_ = 0 := trivial_lie_zero _ _ _ _
_ = f 0 := f.map_zero.symm}
#align function.injective.is_lie_abelian Function.Injective.isLieAbelian
theorem Function.Surjective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R]
[LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂}
(h₁ : Function.Surjective f) (h₂ : IsLieAbelian L₁) : IsLieAbelian L₂ :=
{ trivial := fun x y => by
obtain ⟨u, rfl⟩ := h₁ x
obtain ⟨v, rfl⟩ := h₁ y
rw [← LieHom.map_lie, trivial_lie_zero, LieHom.map_zero] }
#align function.surjective.is_lie_abelian Function.Surjective.isLieAbelian
theorem lie_abelian_iff_equiv_lie_abelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R]
[LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] (e : L₁ ≃ₗ⁅R⁆ L₂) :
IsLieAbelian L₁ ↔ IsLieAbelian L₂ :=
⟨e.symm.injective.isLieAbelian, e.injective.isLieAbelian⟩
#align lie_abelian_iff_equiv_lie_abelian lie_abelian_iff_equiv_lie_abelian
theorem commutative_ring_iff_abelian_lie_ring {A : Type v} [Ring A] :
Std.Commutative (α := A) (· * ·) ↔ IsLieAbelian A := by
have h₁ : Std.Commutative (α := A) (· * ·) ↔ ∀ a b : A, a * b = b * a :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
have h₂ : IsLieAbelian A ↔ ∀ a b : A, ⁅a, b⁆ = 0 := ⟨fun h => h.1, fun h => ⟨h⟩⟩
simp only [h₁, h₂, LieRing.of_associative_ring_bracket, sub_eq_zero]
#align commutative_ring_iff_abelian_lie_ring commutative_ring_iff_abelian_lie_ring
section Center
variable (R : Type u) (L : Type v) (M : Type w) (N : Type w₁)
variable [CommRing R] [LieRing L] [LieAlgebra R L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N]
namespace LieModule
/-- The kernel of the action of a Lie algebra `L` on a Lie module `M` as a Lie ideal in `L`. -/
protected def ker : LieIdeal R L :=
(toEnd R L M).ker
#align lie_module.ker LieModule.ker
@[simp]
protected theorem mem_ker (x : L) : x ∈ LieModule.ker R L M ↔ ∀ m : M, ⁅x, m⁆ = 0 := by
simp only [LieModule.ker, LieHom.mem_ker, LinearMap.ext_iff, LinearMap.zero_apply,
toEnd_apply_apply]
#align lie_module.mem_ker LieModule.mem_ker
/-- The largest submodule of a Lie module `M` on which the Lie algebra `L` acts trivially. -/
def maxTrivSubmodule : LieSubmodule R L M where
carrier := { m | ∀ x : L, ⁅x, m⁆ = 0 }
zero_mem' x := lie_zero x
add_mem' {x y} hx hy z := by rw [lie_add, hx, hy, add_zero]
smul_mem' c x hx y := by rw [lie_smul, hx, smul_zero]
lie_mem {x m} hm y := by rw [hm, lie_zero]
#align lie_module.max_triv_submodule LieModule.maxTrivSubmodule
@[simp]
theorem mem_maxTrivSubmodule (m : M) : m ∈ maxTrivSubmodule R L M ↔ ∀ x : L, ⁅x, m⁆ = 0 :=
Iff.rfl
#align lie_module.mem_max_triv_submodule LieModule.mem_maxTrivSubmodule
instance : IsTrivial L (maxTrivSubmodule R L M) where trivial x m := Subtype.ext (m.property x)
@[simp]
theorem ideal_oper_maxTrivSubmodule_eq_bot (I : LieIdeal R L) :
⁅I, maxTrivSubmodule R L M⁆ = ⊥ := by
rw [← LieSubmodule.coe_toSubmodule_eq_iff, LieSubmodule.lieIdeal_oper_eq_linear_span,
LieSubmodule.bot_coeSubmodule, Submodule.span_eq_bot]
rintro m ⟨⟨x, hx⟩, ⟨⟨m, hm⟩, rfl⟩⟩
exact hm x
#align lie_module.ideal_oper_max_triv_submodule_eq_bot LieModule.ideal_oper_maxTrivSubmodule_eq_bot
theorem le_max_triv_iff_bracket_eq_bot {N : LieSubmodule R L M} :
N ≤ maxTrivSubmodule R L M ↔ ⁅(⊤ : LieIdeal R L), N⁆ = ⊥ := by
refine ⟨fun h => ?_, fun h m hm => ?_⟩
· rw [← le_bot_iff, ← ideal_oper_maxTrivSubmodule_eq_bot R L M ⊤]
exact LieSubmodule.mono_lie_right _ _ ⊤ h
· rw [mem_maxTrivSubmodule]
rw [LieSubmodule.lie_eq_bot_iff] at h
exact fun x => h x (LieSubmodule.mem_top x) m hm
#align lie_module.le_max_triv_iff_bracket_eq_bot LieModule.le_max_triv_iff_bracket_eq_bot
theorem trivial_iff_le_maximal_trivial (N : LieSubmodule R L M) :
IsTrivial L N ↔ N ≤ maxTrivSubmodule R L M :=
⟨fun h m hm x => IsTrivial.casesOn h fun h => Subtype.ext_iff.mp (h x ⟨m, hm⟩), fun h =>
{ trivial := fun x m => Subtype.ext (h m.2 x) }⟩
#align lie_module.trivial_iff_le_maximal_trivial LieModule.trivial_iff_le_maximal_trivial
theorem isTrivial_iff_max_triv_eq_top : IsTrivial L M ↔ maxTrivSubmodule R L M = ⊤ := by
constructor
· rintro ⟨h⟩; ext; simp only [mem_maxTrivSubmodule, h, forall_const, LieSubmodule.mem_top]
· intro h; constructor; intro x m; revert x
rw [← mem_maxTrivSubmodule R L M, h]; exact LieSubmodule.mem_top m
#align lie_module.is_trivial_iff_max_triv_eq_top LieModule.isTrivial_iff_max_triv_eq_top
variable {R L M N}
/-- `maxTrivSubmodule` is functorial. -/
def maxTrivHom (f : M →ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M →ₗ⁅R,L⁆ maxTrivSubmodule R L N where
toFun m := ⟨f m, fun x =>
(LieModuleHom.map_lie _ _ _).symm.trans <|
(congr_arg f (m.property x)).trans (LieModuleHom.map_zero _)⟩
map_add' m n := by simp [Function.comp_apply]; rfl -- Porting note:
map_smul' t m := by simp [Function.comp_apply]; rfl -- these two were `by simpa`
map_lie' {x m} := by simp
#align lie_module.max_triv_hom LieModule.maxTrivHom
@[norm_cast, simp]
theorem coe_maxTrivHom_apply (f : M →ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) :
(maxTrivHom f m : N) = f m :=
rfl
#align lie_module.coe_max_triv_hom_apply LieModule.coe_maxTrivHom_apply
/-- The maximal trivial submodules of Lie-equivalent Lie modules are Lie-equivalent. -/
def maxTrivEquiv (e : M ≃ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M ≃ₗ⁅R,L⁆ maxTrivSubmodule R L N :=
{ maxTrivHom (e : M →ₗ⁅R,L⁆ N) with
toFun := maxTrivHom (e : M →ₗ⁅R,L⁆ N)
invFun := maxTrivHom (e.symm : N →ₗ⁅R,L⁆ M)
left_inv := fun m => by ext; simp [LieModuleEquiv.coe_to_lieModuleHom]
right_inv := fun n => by ext; simp [LieModuleEquiv.coe_to_lieModuleHom] }
#align lie_module.max_triv_equiv LieModule.maxTrivEquiv
@[norm_cast, simp]
theorem coe_maxTrivEquiv_apply (e : M ≃ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) :
(maxTrivEquiv e m : N) = e ↑m :=
rfl
#align lie_module.coe_max_triv_equiv_apply LieModule.coe_maxTrivEquiv_apply
@[simp]
| Mathlib/Algebra/Lie/Abelian.lean | 201 | 203 | theorem maxTrivEquiv_of_refl_eq_refl :
maxTrivEquiv (LieModuleEquiv.refl : M ≃ₗ⁅R,L⁆ M) = LieModuleEquiv.refl := by |
ext; simp only [coe_maxTrivEquiv_apply, LieModuleEquiv.refl_apply]
|
/-
Copyright (c) 2021 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno
-/
import Mathlib.CategoryTheory.NatIso
#align_import category_theory.bicategory.basic from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514"
/-!
# Bicategories
In this file we define typeclass for bicategories.
A bicategory `B` consists of
* objects `a : B`,
* 1-morphisms `f : a ⟶ b` between objects `a b : B`, and
* 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`.
We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms,
respectively.
A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that
we have
* a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and
* an identity `𝟙 a : a ⟶ a` for each object `a : B`.
For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The
2-morphisms in the bicategory are implemented as the morphisms in this family of categories.
The composition of 1-morphisms is in fact an object part of a functor
`(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not
require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism
`f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a
2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g`
between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism
`whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law
`whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`,
which is required as an axiom in the definition here.
-/
namespace CategoryTheory
universe w v u
open Category Iso
-- intended to be used with explicit universe parameters
/-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain
a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative,
but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`.
There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor
isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`.
These associators and unitors satisfy the pentagon and triangle equations.
See https://ncatlab.org/nlab/show/bicategory.
-/
@[nolint checkUnivs]
class Bicategory (B : Type u) extends CategoryStruct.{v} B where
-- category structure on the collection of 1-morphisms:
homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance
-- left whiskering:
whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h
-- right whiskering:
whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h
-- associator:
associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h
-- left unitor:
leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f
-- right unitor:
rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f
-- axioms for left whiskering:
whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by
aesop_cat
whiskerLeft_comp :
∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i),
whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by
aesop_cat
id_whiskerLeft :
∀ {a b} {f g : a ⟶ b} (η : f ⟶ g),
whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by
aesop_cat
comp_whiskerLeft :
∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'),
whiskerLeft (f ≫ g) η =
(associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by
aesop_cat
-- axioms for right whiskering:
id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by
aesop_cat
comp_whiskerRight :
∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c),
whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by
aesop_cat
whiskerRight_id :
∀ {a b} {f g : a ⟶ b} (η : f ⟶ g),
whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by
aesop_cat
whiskerRight_comp :
∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d),
whiskerRight η (g ≫ h) =
(associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by
aesop_cat
-- associativity of whiskerings:
whisker_assoc :
∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d),
whiskerRight (whiskerLeft f η) h =
(associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by
aesop_cat
-- exchange law of left and right whiskerings:
whisker_exchange :
∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i),
whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by
aesop_cat
-- pentagon identity:
pentagon :
∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e),
whiskerRight (associator f g h).hom i ≫
(associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom =
(associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by
aesop_cat
-- triangle identity:
triangle :
∀ {a b c} (f : a ⟶ b) (g : b ⟶ c),
(associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom
= whiskerRight (rightUnitor f).hom g := by
aesop_cat
#align category_theory.bicategory CategoryTheory.Bicategory
#align category_theory.bicategory.hom_category CategoryTheory.Bicategory.homCategory
#align category_theory.bicategory.whisker_left CategoryTheory.Bicategory.whiskerLeft
#align category_theory.bicategory.whisker_right CategoryTheory.Bicategory.whiskerRight
#align category_theory.bicategory.left_unitor CategoryTheory.Bicategory.leftUnitor
#align category_theory.bicategory.right_unitor CategoryTheory.Bicategory.rightUnitor
#align category_theory.bicategory.whisker_left_id' CategoryTheory.Bicategory.whiskerLeft_id
#align category_theory.bicategory.whisker_left_comp' CategoryTheory.Bicategory.whiskerLeft_comp
#align category_theory.bicategory.id_whisker_left' CategoryTheory.Bicategory.id_whiskerLeft
#align category_theory.bicategory.comp_whisker_left' CategoryTheory.Bicategory.comp_whiskerLeft
#align category_theory.bicategory.id_whisker_right' CategoryTheory.Bicategory.id_whiskerRight
#align category_theory.bicategory.comp_whisker_right' CategoryTheory.Bicategory.comp_whiskerRight
#align category_theory.bicategory.whisker_right_id' CategoryTheory.Bicategory.whiskerRight_id
#align category_theory.bicategory.whisker_right_comp' CategoryTheory.Bicategory.whiskerRight_comp
#align category_theory.bicategory.whisker_assoc' CategoryTheory.Bicategory.whisker_assoc
#align category_theory.bicategory.whisker_exchange' CategoryTheory.Bicategory.whisker_exchange
#align category_theory.bicategory.pentagon' CategoryTheory.Bicategory.pentagon
#align category_theory.bicategory.triangle' CategoryTheory.Bicategory.triangle
namespace Bicategory
scoped infixr:81 " ◁ " => Bicategory.whiskerLeft
scoped infixl:81 " ▷ " => Bicategory.whiskerRight
scoped notation "α_" => Bicategory.associator
scoped notation "λ_" => Bicategory.leftUnitor
scoped notation "ρ_" => Bicategory.rightUnitor
/-!
### Simp-normal form for 2-morphisms
Rewriting involving associators and unitors could be very complicated. We try to ease this
complexity by putting carefully chosen simp lemmas that rewrite any 2-morphisms into simp-normal
form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming)
`coherence` tactic.
The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of
parentheses. More precisely,
1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is
either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors)
or non-structural 2-morphisms, and
2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`,
where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a
non-structural 2-morphisms that is also not the identity or a composite.
Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`.
-/
attribute [instance] homCategory
attribute [reassoc]
whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id
whiskerRight_comp whisker_assoc whisker_exchange
attribute [reassoc (attr := simp)] pentagon triangle
/-
The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There
are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`),
which at first glance look more complicated than the LHS, but they will be eventually reduced by
the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic.
-/
attribute [simp]
whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight
whiskerRight_id whiskerRight_comp whisker_assoc
variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B}
@[reassoc (attr := simp)]
theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) :
f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id]
#align category_theory.bicategory.hom_inv_whisker_left CategoryTheory.Bicategory.whiskerLeft_hom_inv
@[reassoc (attr := simp)]
theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) :
η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight]
#align category_theory.bicategory.hom_inv_whisker_right CategoryTheory.Bicategory.hom_inv_whiskerRight
@[reassoc (attr := simp)]
theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) :
f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id]
#align category_theory.bicategory.inv_hom_whisker_left CategoryTheory.Bicategory.whiskerLeft_inv_hom
@[reassoc (attr := simp)]
theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) :
η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight]
#align category_theory.bicategory.inv_hom_whisker_right CategoryTheory.Bicategory.inv_hom_whiskerRight
/-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/
@[simps]
def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where
hom := f ◁ η.hom
inv := f ◁ η.inv
#align category_theory.bicategory.whisker_left_iso CategoryTheory.Bicategory.whiskerLeftIso
instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) :=
(whiskerLeftIso f (asIso η)).isIso_hom
#align category_theory.bicategory.whisker_left_is_iso CategoryTheory.Bicategory.whiskerLeft_isIso
@[simp]
theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] :
inv (f ◁ η) = f ◁ inv η := by
apply IsIso.inv_eq_of_hom_inv_id
simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id]
#align category_theory.bicategory.inv_whisker_left CategoryTheory.Bicategory.inv_whiskerLeft
/-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/
@[simps!]
def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where
hom := η.hom ▷ h
inv := η.inv ▷ h
#align category_theory.bicategory.whisker_right_iso CategoryTheory.Bicategory.whiskerRightIso
instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) :=
(whiskerRightIso (asIso η) h).isIso_hom
#align category_theory.bicategory.whisker_right_is_iso CategoryTheory.Bicategory.whiskerRight_isIso
@[simp]
theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] :
inv (η ▷ h) = inv η ▷ h := by
apply IsIso.inv_eq_of_hom_inv_id
simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id]
#align category_theory.bicategory.inv_whisker_right CategoryTheory.Bicategory.inv_whiskerRight
@[reassoc (attr := simp)]
theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i =
(α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv :=
eq_of_inv_eq_inv (by simp)
#align category_theory.bicategory.pentagon_inv CategoryTheory.Bicategory.pentagon_inv
@[reassoc (attr := simp)]
theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom =
f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by
rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv]
simp
#align category_theory.bicategory.pentagon_inv_inv_hom_hom_inv CategoryTheory.Bicategory.pentagon_inv_inv_hom_hom_inv
@[reassoc (attr := simp)]
theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom =
(α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv :=
eq_of_inv_eq_inv (by simp)
#align category_theory.bicategory.pentagon_inv_hom_hom_hom_inv CategoryTheory.Bicategory.pentagon_inv_hom_hom_hom_inv
@[reassoc (attr := simp)]
theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv =
(α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by
simp [← cancel_epi (f ◁ (α_ g h i).inv)]
#align category_theory.bicategory.pentagon_hom_inv_inv_inv_inv CategoryTheory.Bicategory.pentagon_hom_inv_inv_inv_inv
@[reassoc (attr := simp)]
theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv =
(α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom :=
eq_of_inv_eq_inv (by simp)
#align category_theory.bicategory.pentagon_hom_hom_inv_hom_hom CategoryTheory.Bicategory.pentagon_hom_hom_inv_hom_hom
@[reassoc (attr := simp)]
theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv =
(α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by
rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)]
simp
#align category_theory.bicategory.pentagon_hom_inv_inv_inv_hom CategoryTheory.Bicategory.pentagon_hom_inv_inv_inv_hom
@[reassoc (attr := simp)]
theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv =
(α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom :=
eq_of_inv_eq_inv (by simp)
#align category_theory.bicategory.pentagon_hom_hom_inv_inv_hom CategoryTheory.Bicategory.pentagon_hom_hom_inv_inv_hom
@[reassoc (attr := simp)]
theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom =
(α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by
simp [← cancel_epi ((α_ f g h).hom ▷ i)]
#align category_theory.bicategory.pentagon_inv_hom_hom_hom_hom CategoryTheory.Bicategory.pentagon_inv_hom_hom_hom_hom
@[reassoc (attr := simp)]
theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i =
f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv :=
eq_of_inv_eq_inv (by simp)
#align category_theory.bicategory.pentagon_inv_inv_hom_inv_inv CategoryTheory.Bicategory.pentagon_inv_inv_hom_inv_inv
theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) :
(α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g :=
triangle f g
#align category_theory.bicategory.triangle_assoc_comp_left CategoryTheory.Bicategory.triangle_assoc_comp_left
@[reassoc (attr := simp)]
theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) :
(α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc]
#align category_theory.bicategory.triangle_assoc_comp_right CategoryTheory.Bicategory.triangle_assoc_comp_right
@[reassoc (attr := simp)]
| Mathlib/CategoryTheory/Bicategory/Basic.lean | 327 | 329 | theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) :
(ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by |
simp [← cancel_mono (f ◁ (λ_ g).hom)]
|
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yaël Dillies
-/
import Mathlib.Data.Finset.NAry
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Set.Pointwise.Finite
import Mathlib.Data.Set.Pointwise.SMul
import Mathlib.Data.Set.Pointwise.ListOfFn
import Mathlib.GroupTheory.GroupAction.Pi
import Mathlib.SetTheory.Cardinal.Finite
#align_import data.finset.pointwise from "leanprover-community/mathlib"@"eba7871095e834365616b5e43c8c7bb0b37058d0"
/-!
# Pointwise operations of finsets
This file defines pointwise algebraic operations on finsets.
## Main declarations
For finsets `s` and `t`:
* `0` (`Finset.zero`): The singleton `{0}`.
* `1` (`Finset.one`): The singleton `{1}`.
* `-s` (`Finset.neg`): Negation, finset of all `-x` where `x ∈ s`.
* `s⁻¹` (`Finset.inv`): Inversion, finset of all `x⁻¹` where `x ∈ s`.
* `s + t` (`Finset.add`): Addition, finset of all `x + y` where `x ∈ s` and `y ∈ t`.
* `s * t` (`Finset.mul`): Multiplication, finset of all `x * y` where `x ∈ s` and `y ∈ t`.
* `s - t` (`Finset.sub`): Subtraction, finset of all `x - y` where `x ∈ s` and `y ∈ t`.
* `s / t` (`Finset.div`): Division, finset of all `x / y` where `x ∈ s` and `y ∈ t`.
* `s +ᵥ t` (`Finset.vadd`): Scalar addition, finset of all `x +ᵥ y` where `x ∈ s` and `y ∈ t`.
* `s • t` (`Finset.smul`): Scalar multiplication, finset of all `x • y` where `x ∈ s` and
`y ∈ t`.
* `s -ᵥ t` (`Finset.vsub`): Scalar subtraction, finset of all `x -ᵥ y` where `x ∈ s` and
`y ∈ t`.
* `a • s` (`Finset.smulFinset`): Scaling, finset of all `a • x` where `x ∈ s`.
* `a +ᵥ s` (`Finset.vaddFinset`): Translation, finset of all `a +ᵥ x` where `x ∈ s`.
For `α` a semigroup/monoid, `Finset α` is a semigroup/monoid.
As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between
pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action].
## Implementation notes
We put all instances in the locale `Pointwise`, so that these instances are not available by
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
since we expect the locale to be open whenever the instances are actually used (and making the
instances reducible changes the behavior of `simp`.
## Tags
finset multiplication, finset addition, pointwise addition, pointwise multiplication,
pointwise subtraction
-/
open Function MulOpposite
open scoped Pointwise
variable {F α β γ : Type*}
namespace Finset
/-! ### `0`/`1` as finsets -/
section One
variable [One α] {s : Finset α} {a : α}
/-- The finset `1 : Finset α` is defined as `{1}` in locale `Pointwise`. -/
@[to_additive "The finset `0 : Finset α` is defined as `{0}` in locale `Pointwise`."]
protected def one : One (Finset α) :=
⟨{1}⟩
#align finset.has_one Finset.one
#align finset.has_zero Finset.zero
scoped[Pointwise] attribute [instance] Finset.one Finset.zero
@[to_additive (attr := simp)]
theorem mem_one : a ∈ (1 : Finset α) ↔ a = 1 :=
mem_singleton
#align finset.mem_one Finset.mem_one
#align finset.mem_zero Finset.mem_zero
@[to_additive (attr := simp, norm_cast)]
theorem coe_one : ↑(1 : Finset α) = (1 : Set α) :=
coe_singleton 1
#align finset.coe_one Finset.coe_one
#align finset.coe_zero Finset.coe_zero
@[to_additive (attr := simp, norm_cast)]
lemma coe_eq_one : (s : Set α) = 1 ↔ s = 1 := coe_eq_singleton
@[to_additive (attr := simp)]
theorem one_subset : (1 : Finset α) ⊆ s ↔ (1 : α) ∈ s :=
singleton_subset_iff
#align finset.one_subset Finset.one_subset
#align finset.zero_subset Finset.zero_subset
@[to_additive]
theorem singleton_one : ({1} : Finset α) = 1 :=
rfl
#align finset.singleton_one Finset.singleton_one
#align finset.singleton_zero Finset.singleton_zero
@[to_additive]
theorem one_mem_one : (1 : α) ∈ (1 : Finset α) :=
mem_singleton_self _
#align finset.one_mem_one Finset.one_mem_one
#align finset.zero_mem_zero Finset.zero_mem_zero
@[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))]
theorem one_nonempty : (1 : Finset α).Nonempty :=
⟨1, one_mem_one⟩
#align finset.one_nonempty Finset.one_nonempty
#align finset.zero_nonempty Finset.zero_nonempty
@[to_additive (attr := simp)]
protected theorem map_one {f : α ↪ β} : map f 1 = {f 1} :=
map_singleton f 1
#align finset.map_one Finset.map_one
#align finset.map_zero Finset.map_zero
@[to_additive (attr := simp)]
theorem image_one [DecidableEq β] {f : α → β} : image f 1 = {f 1} :=
image_singleton _ _
#align finset.image_one Finset.image_one
#align finset.image_zero Finset.image_zero
@[to_additive]
theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 :=
subset_singleton_iff
#align finset.subset_one_iff_eq Finset.subset_one_iff_eq
#align finset.subset_zero_iff_eq Finset.subset_zero_iff_eq
@[to_additive]
theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 :=
h.subset_singleton_iff
#align finset.nonempty.subset_one_iff Finset.Nonempty.subset_one_iff
#align finset.nonempty.subset_zero_iff Finset.Nonempty.subset_zero_iff
@[to_additive (attr := simp)]
theorem card_one : (1 : Finset α).card = 1 :=
card_singleton _
#align finset.card_one Finset.card_one
#align finset.card_zero Finset.card_zero
/-- The singleton operation as a `OneHom`. -/
@[to_additive "The singleton operation as a `ZeroHom`."]
def singletonOneHom : OneHom α (Finset α) where
toFun := singleton; map_one' := singleton_one
#align finset.singleton_one_hom Finset.singletonOneHom
#align finset.singleton_zero_hom Finset.singletonZeroHom
@[to_additive (attr := simp)]
theorem coe_singletonOneHom : (singletonOneHom : α → Finset α) = singleton :=
rfl
#align finset.coe_singleton_one_hom Finset.coe_singletonOneHom
#align finset.coe_singleton_zero_hom Finset.coe_singletonZeroHom
@[to_additive (attr := simp)]
theorem singletonOneHom_apply (a : α) : singletonOneHom a = {a} :=
rfl
#align finset.singleton_one_hom_apply Finset.singletonOneHom_apply
#align finset.singleton_zero_hom_apply Finset.singletonZeroHom_apply
/-- Lift a `OneHom` to `Finset` via `image`. -/
@[to_additive (attr := simps) "Lift a `ZeroHom` to `Finset` via `image`"]
def imageOneHom [DecidableEq β] [One β] [FunLike F α β] [OneHomClass F α β] (f : F) :
OneHom (Finset α) (Finset β) where
toFun := Finset.image f
map_one' := by rw [image_one, map_one, singleton_one]
#align finset.image_one_hom Finset.imageOneHom
#align finset.image_zero_hom Finset.imageZeroHom
@[to_additive (attr := simp)]
lemma sup_one [SemilatticeSup β] [OrderBot β] (f : α → β) : sup 1 f = f 1 := sup_singleton
@[to_additive (attr := simp)]
lemma sup'_one [SemilatticeSup β] (f : α → β) : sup' 1 one_nonempty f = f 1 := rfl
@[to_additive (attr := simp)]
lemma inf_one [SemilatticeInf β] [OrderTop β] (f : α → β) : inf 1 f = f 1 := inf_singleton
@[to_additive (attr := simp)]
lemma inf'_one [SemilatticeInf β] (f : α → β) : inf' 1 one_nonempty f = f 1 := rfl
@[to_additive (attr := simp)]
lemma max_one [LinearOrder α] : (1 : Finset α).max = 1 := rfl
@[to_additive (attr := simp)]
lemma min_one [LinearOrder α] : (1 : Finset α).min = 1 := rfl
@[to_additive (attr := simp)]
lemma max'_one [LinearOrder α] : (1 : Finset α).max' one_nonempty = 1 := rfl
@[to_additive (attr := simp)]
lemma min'_one [LinearOrder α] : (1 : Finset α).min' one_nonempty = 1 := rfl
end One
/-! ### Finset negation/inversion -/
section Inv
variable [DecidableEq α] [Inv α] {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α}
/-- The pointwise inversion of finset `s⁻¹` is defined as `{x⁻¹ | x ∈ s}` in locale `Pointwise`. -/
@[to_additive
"The pointwise negation of finset `-s` is defined as `{-x | x ∈ s}` in locale `Pointwise`."]
protected def inv : Inv (Finset α) :=
⟨image Inv.inv⟩
#align finset.has_inv Finset.inv
#align finset.has_neg Finset.neg
scoped[Pointwise] attribute [instance] Finset.inv Finset.neg
@[to_additive]
theorem inv_def : s⁻¹ = s.image fun x => x⁻¹ :=
rfl
#align finset.inv_def Finset.inv_def
#align finset.neg_def Finset.neg_def
@[to_additive]
theorem image_inv : (s.image fun x => x⁻¹) = s⁻¹ :=
rfl
#align finset.image_inv Finset.image_inv
#align finset.image_neg Finset.image_neg
@[to_additive]
theorem mem_inv {x : α} : x ∈ s⁻¹ ↔ ∃ y ∈ s, y⁻¹ = x :=
mem_image
#align finset.mem_inv Finset.mem_inv
#align finset.mem_neg Finset.mem_neg
@[to_additive]
theorem inv_mem_inv (ha : a ∈ s) : a⁻¹ ∈ s⁻¹ :=
mem_image_of_mem _ ha
#align finset.inv_mem_inv Finset.inv_mem_inv
#align finset.neg_mem_neg Finset.neg_mem_neg
@[to_additive]
theorem card_inv_le : s⁻¹.card ≤ s.card :=
card_image_le
#align finset.card_inv_le Finset.card_inv_le
#align finset.card_neg_le Finset.card_neg_le
@[to_additive (attr := simp)]
theorem inv_empty : (∅ : Finset α)⁻¹ = ∅ :=
image_empty _
#align finset.inv_empty Finset.inv_empty
#align finset.neg_empty Finset.neg_empty
@[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))]
theorem inv_nonempty_iff : s⁻¹.Nonempty ↔ s.Nonempty := image_nonempty
#align finset.inv_nonempty_iff Finset.inv_nonempty_iff
#align finset.neg_nonempty_iff Finset.neg_nonempty_iff
alias ⟨Nonempty.of_inv, Nonempty.inv⟩ := inv_nonempty_iff
#align finset.nonempty.of_inv Finset.Nonempty.of_inv
#align finset.nonempty.inv Finset.Nonempty.inv
attribute [to_additive] Nonempty.inv Nonempty.of_inv
@[to_additive (attr := simp)]
theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := image_eq_empty
@[to_additive (attr := mono)]
theorem inv_subset_inv (h : s ⊆ t) : s⁻¹ ⊆ t⁻¹ :=
image_subset_image h
#align finset.inv_subset_inv Finset.inv_subset_inv
#align finset.neg_subset_neg Finset.neg_subset_neg
@[to_additive (attr := simp)]
theorem inv_singleton (a : α) : ({a} : Finset α)⁻¹ = {a⁻¹} :=
image_singleton _ _
#align finset.inv_singleton Finset.inv_singleton
#align finset.neg_singleton Finset.neg_singleton
@[to_additive (attr := simp)]
theorem inv_insert (a : α) (s : Finset α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ :=
image_insert _ _ _
#align finset.inv_insert Finset.inv_insert
#align finset.neg_insert Finset.neg_insert
@[to_additive (attr := simp)]
lemma sup_inv [SemilatticeSup β] [OrderBot β] (s : Finset α) (f : α → β) :
sup s⁻¹ f = sup s (f ·⁻¹) :=
sup_image ..
@[to_additive (attr := simp)]
lemma sup'_inv [SemilatticeSup β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) :
sup' s⁻¹ hs f = sup' s hs.of_inv (f ·⁻¹) :=
sup'_image ..
@[to_additive (attr := simp)]
lemma inf_inv [SemilatticeInf β] [OrderTop β] (s : Finset α) (f : α → β) :
inf s⁻¹ f = inf s (f ·⁻¹) :=
inf_image ..
@[to_additive (attr := simp)]
lemma inf'_inv [SemilatticeInf β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) :
inf' s⁻¹ hs f = inf' s hs.of_inv (f ·⁻¹) :=
inf'_image ..
@[to_additive] lemma image_op_inv (s : Finset α) : s⁻¹.image op = (s.image op)⁻¹ :=
image_comm op_inv
end Inv
open Pointwise
section InvolutiveInv
variable [DecidableEq α] [InvolutiveInv α] {s : Finset α} {a : α}
@[to_additive (attr := simp)]
lemma mem_inv' : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := by simp [mem_inv, inv_eq_iff_eq_inv]
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv (s : Finset α) : ↑s⁻¹ = (s : Set α)⁻¹ := coe_image.trans Set.image_inv
#align finset.coe_inv Finset.coe_inv
#align finset.coe_neg Finset.coe_neg
@[to_additive (attr := simp)]
theorem card_inv (s : Finset α) : s⁻¹.card = s.card := card_image_of_injective _ inv_injective
#align finset.card_inv Finset.card_inv
#align finset.card_neg Finset.card_neg
@[to_additive (attr := simp)]
theorem preimage_inv (s : Finset α) : s.preimage (·⁻¹) inv_injective.injOn = s⁻¹ :=
coe_injective <| by rw [coe_preimage, Set.inv_preimage, coe_inv]
#align finset.preimage_inv Finset.preimage_inv
#align finset.preimage_neg Finset.preimage_neg
@[to_additive (attr := simp)]
lemma inv_univ [Fintype α] : (univ : Finset α)⁻¹ = univ := by ext; simp
@[to_additive (attr := simp)]
lemma inv_inter (s t : Finset α) : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := coe_injective <| by simp
end InvolutiveInv
/-! ### Finset addition/multiplication -/
section Mul
variable [DecidableEq α] [DecidableEq β] [Mul α] [Mul β] [FunLike F α β] [MulHomClass F α β]
(f : F) {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α}
/-- The pointwise multiplication of finsets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}`
in locale `Pointwise`. -/
@[to_additive
"The pointwise addition of finsets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in
locale `Pointwise`."]
protected def mul : Mul (Finset α) :=
⟨image₂ (· * ·)⟩
#align finset.has_mul Finset.mul
#align finset.has_add Finset.add
scoped[Pointwise] attribute [instance] Finset.mul Finset.add
@[to_additive]
theorem mul_def : s * t = (s ×ˢ t).image fun p : α × α => p.1 * p.2 :=
rfl
#align finset.mul_def Finset.mul_def
#align finset.add_def Finset.add_def
@[to_additive]
theorem image_mul_product : ((s ×ˢ t).image fun x : α × α => x.fst * x.snd) = s * t :=
rfl
#align finset.image_mul_product Finset.image_mul_product
#align finset.image_add_product Finset.image_add_product
@[to_additive]
theorem mem_mul {x : α} : x ∈ s * t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := mem_image₂
#align finset.mem_mul Finset.mem_mul
#align finset.mem_add Finset.mem_add
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul (s t : Finset α) : (↑(s * t) : Set α) = ↑s * ↑t :=
coe_image₂ _ _ _
#align finset.coe_mul Finset.coe_mul
#align finset.coe_add Finset.coe_add
@[to_additive]
theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t :=
mem_image₂_of_mem
#align finset.mul_mem_mul Finset.mul_mem_mul
#align finset.add_mem_add Finset.add_mem_add
@[to_additive]
theorem card_mul_le : (s * t).card ≤ s.card * t.card :=
card_image₂_le _ _ _
#align finset.card_mul_le Finset.card_mul_le
#align finset.card_add_le Finset.card_add_le
@[to_additive]
theorem card_mul_iff :
(s * t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 :=
card_image₂_iff
#align finset.card_mul_iff Finset.card_mul_iff
#align finset.card_add_iff Finset.card_add_iff
@[to_additive (attr := simp)]
theorem empty_mul (s : Finset α) : ∅ * s = ∅ :=
image₂_empty_left
#align finset.empty_mul Finset.empty_mul
#align finset.empty_add Finset.empty_add
@[to_additive (attr := simp)]
theorem mul_empty (s : Finset α) : s * ∅ = ∅ :=
image₂_empty_right
#align finset.mul_empty Finset.mul_empty
#align finset.add_empty Finset.add_empty
@[to_additive (attr := simp)]
theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
#align finset.mul_eq_empty Finset.mul_eq_empty
#align finset.add_eq_empty Finset.add_eq_empty
@[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))]
theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
#align finset.mul_nonempty Finset.mul_nonempty
#align finset.add_nonempty Finset.add_nonempty
@[to_additive]
theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty :=
Nonempty.image₂
#align finset.nonempty.mul Finset.Nonempty.mul
#align finset.nonempty.add Finset.Nonempty.add
@[to_additive]
theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
#align finset.nonempty.of_mul_left Finset.Nonempty.of_mul_left
#align finset.nonempty.of_add_left Finset.Nonempty.of_add_left
@[to_additive]
theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
#align finset.nonempty.of_mul_right Finset.Nonempty.of_mul_right
#align finset.nonempty.of_add_right Finset.Nonempty.of_add_right
@[to_additive]
theorem mul_singleton (a : α) : s * {a} = s.image (· * a) :=
image₂_singleton_right
#align finset.mul_singleton Finset.mul_singleton
#align finset.add_singleton Finset.add_singleton
@[to_additive]
theorem singleton_mul (a : α) : {a} * s = s.image (a * ·) :=
image₂_singleton_left
#align finset.singleton_mul Finset.singleton_mul
#align finset.singleton_add Finset.singleton_add
@[to_additive (attr := simp)]
theorem singleton_mul_singleton (a b : α) : ({a} : Finset α) * {b} = {a * b} :=
image₂_singleton
#align finset.singleton_mul_singleton Finset.singleton_mul_singleton
#align finset.singleton_add_singleton Finset.singleton_add_singleton
@[to_additive (attr := mono)]
theorem mul_subset_mul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ * t₁ ⊆ s₂ * t₂ :=
image₂_subset
#align finset.mul_subset_mul Finset.mul_subset_mul
#align finset.add_subset_add Finset.add_subset_add
@[to_additive]
theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ :=
image₂_subset_left
#align finset.mul_subset_mul_left Finset.mul_subset_mul_left
#align finset.add_subset_add_left Finset.add_subset_add_left
@[to_additive]
theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t :=
image₂_subset_right
#align finset.mul_subset_mul_right Finset.mul_subset_mul_right
#align finset.add_subset_add_right Finset.add_subset_add_right
@[to_additive]
theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u :=
image₂_subset_iff
#align finset.mul_subset_iff Finset.mul_subset_iff
#align finset.add_subset_iff Finset.add_subset_iff
@[to_additive]
theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t :=
image₂_union_left
#align finset.union_mul Finset.union_mul
#align finset.union_add Finset.union_add
@[to_additive]
theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ :=
image₂_union_right
#align finset.mul_union Finset.mul_union
#align finset.add_union Finset.add_union
@[to_additive]
theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) :=
image₂_inter_subset_left
#align finset.inter_mul_subset Finset.inter_mul_subset
#align finset.inter_add_subset Finset.inter_add_subset
@[to_additive]
theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) :=
image₂_inter_subset_right
#align finset.mul_inter_subset Finset.mul_inter_subset
#align finset.add_inter_subset Finset.add_inter_subset
@[to_additive]
theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ :=
image₂_inter_union_subset_union
#align finset.inter_mul_union_subset_union Finset.inter_mul_union_subset_union
#align finset.inter_add_union_subset_union Finset.inter_add_union_subset_union
@[to_additive]
theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ :=
image₂_union_inter_subset_union
#align finset.union_mul_inter_subset_union Finset.union_mul_inter_subset_union
#align finset.union_add_inter_subset_union Finset.union_add_inter_subset_union
/-- If a finset `u` is contained in the product of two sets `s * t`, we can find two finsets `s'`,
`t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' * t'`. -/
@[to_additive
"If a finset `u` is contained in the sum of two sets `s + t`, we can find two finsets
`s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' + t'`."]
theorem subset_mul {s t : Set α} :
↑u ⊆ s * t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' * t' :=
subset_image₂
#align finset.subset_mul Finset.subset_mul
#align finset.subset_add Finset.subset_add
@[to_additive]
theorem image_mul : (s * t).image (f : α → β) = s.image f * t.image f :=
image_image₂_distrib <| map_mul f
#align finset.image_mul Finset.image_mul
#align finset.image_add Finset.image_add
/-- The singleton operation as a `MulHom`. -/
@[to_additive "The singleton operation as an `AddHom`."]
def singletonMulHom : α →ₙ* Finset α where
toFun := singleton; map_mul' _ _ := (singleton_mul_singleton _ _).symm
#align finset.singleton_mul_hom Finset.singletonMulHom
#align finset.singleton_add_hom Finset.singletonAddHom
@[to_additive (attr := simp)]
theorem coe_singletonMulHom : (singletonMulHom : α → Finset α) = singleton :=
rfl
#align finset.coe_singleton_mul_hom Finset.coe_singletonMulHom
#align finset.coe_singleton_add_hom Finset.coe_singletonAddHom
@[to_additive (attr := simp)]
theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} :=
rfl
#align finset.singleton_mul_hom_apply Finset.singletonMulHom_apply
#align finset.singleton_add_hom_apply Finset.singletonAddHom_apply
/-- Lift a `MulHom` to `Finset` via `image`. -/
@[to_additive (attr := simps) "Lift an `AddHom` to `Finset` via `image`"]
def imageMulHom : Finset α →ₙ* Finset β where
toFun := Finset.image f
map_mul' _ _ := image_mul _
#align finset.image_mul_hom Finset.imageMulHom
#align finset.image_add_hom Finset.imageAddHom
@[to_additive (attr := simp (default + 1))]
lemma sup_mul_le [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} :
sup (s * t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x * y) ≤ a :=
sup_image₂_le
@[to_additive]
lemma sup_mul_left [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s * t) f = sup s fun x ↦ sup t (f <| x * ·) :=
sup_image₂_left ..
@[to_additive]
lemma sup_mul_right [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s * t) f = sup t fun y ↦ sup s (f <| · * y) :=
sup_image₂_right ..
@[to_additive (attr := simp (default + 1))]
lemma le_inf_mul [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} :
a ≤ inf (s * t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x * y) :=
le_inf_image₂
@[to_additive]
lemma inf_mul_left [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s * t) f = inf s fun x ↦ inf t (f <| x * ·) :=
inf_image₂_left ..
@[to_additive]
lemma inf_mul_right [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s * t) f = inf t fun y ↦ inf s (f <| · * y) :=
inf_image₂_right ..
end Mul
/-! ### Finset subtraction/division -/
section Div
variable [DecidableEq α] [Div α] {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α}
/-- The pointwise division of finsets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale
`Pointwise`. -/
@[to_additive
"The pointwise subtraction of finsets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}`
in locale `Pointwise`."]
protected def div : Div (Finset α) :=
⟨image₂ (· / ·)⟩
#align finset.has_div Finset.div
#align finset.has_sub Finset.sub
scoped[Pointwise] attribute [instance] Finset.div Finset.sub
@[to_additive]
theorem div_def : s / t = (s ×ˢ t).image fun p : α × α => p.1 / p.2 :=
rfl
#align finset.div_def Finset.div_def
#align finset.sub_def Finset.sub_def
@[to_additive]
theorem image_div_product : ((s ×ˢ t).image fun x : α × α => x.fst / x.snd) = s / t :=
rfl
#align finset.image_div_prod Finset.image_div_product
#align finset.add_image_prod Finset.image_sub_product
@[to_additive]
theorem mem_div : a ∈ s / t ↔ ∃ b ∈ s, ∃ c ∈ t, b / c = a :=
mem_image₂
#align finset.mem_div Finset.mem_div
#align finset.mem_sub Finset.mem_sub
@[to_additive (attr := simp, norm_cast)]
theorem coe_div (s t : Finset α) : (↑(s / t) : Set α) = ↑s / ↑t :=
coe_image₂ _ _ _
#align finset.coe_div Finset.coe_div
#align finset.coe_sub Finset.coe_sub
@[to_additive]
theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t :=
mem_image₂_of_mem
#align finset.div_mem_div Finset.div_mem_div
#align finset.sub_mem_sub Finset.sub_mem_sub
@[to_additive]
theorem div_card_le : (s / t).card ≤ s.card * t.card :=
card_image₂_le _ _ _
#align finset.div_card_le Finset.div_card_le
#align finset.sub_card_le Finset.sub_card_le
@[to_additive (attr := simp)]
theorem empty_div (s : Finset α) : ∅ / s = ∅ :=
image₂_empty_left
#align finset.empty_div Finset.empty_div
#align finset.empty_sub Finset.empty_sub
@[to_additive (attr := simp)]
theorem div_empty (s : Finset α) : s / ∅ = ∅ :=
image₂_empty_right
#align finset.div_empty Finset.div_empty
#align finset.sub_empty Finset.sub_empty
@[to_additive (attr := simp)]
theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
#align finset.div_eq_empty Finset.div_eq_empty
#align finset.sub_eq_empty Finset.sub_eq_empty
@[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))]
theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
#align finset.div_nonempty Finset.div_nonempty
#align finset.sub_nonempty Finset.sub_nonempty
@[to_additive]
theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty :=
Nonempty.image₂
#align finset.nonempty.div Finset.Nonempty.div
#align finset.nonempty.sub Finset.Nonempty.sub
@[to_additive]
theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
#align finset.nonempty.of_div_left Finset.Nonempty.of_div_left
#align finset.nonempty.of_sub_left Finset.Nonempty.of_sub_left
@[to_additive]
theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
#align finset.nonempty.of_div_right Finset.Nonempty.of_div_right
#align finset.nonempty.of_sub_right Finset.Nonempty.of_sub_right
@[to_additive (attr := simp)]
theorem div_singleton (a : α) : s / {a} = s.image (· / a) :=
image₂_singleton_right
#align finset.div_singleton Finset.div_singleton
#align finset.sub_singleton Finset.sub_singleton
@[to_additive (attr := simp)]
theorem singleton_div (a : α) : {a} / s = s.image (a / ·) :=
image₂_singleton_left
#align finset.singleton_div Finset.singleton_div
#align finset.singleton_sub Finset.singleton_sub
-- @[to_additive (attr := simp)]
-- Porting note (#10618): simp can prove this & the additive version
@[to_additive]
theorem singleton_div_singleton (a b : α) : ({a} : Finset α) / {b} = {a / b} :=
image₂_singleton
#align finset.singleton_div_singleton Finset.singleton_div_singleton
#align finset.singleton_sub_singleton Finset.singleton_sub_singleton
@[to_additive (attr := mono)]
theorem div_subset_div : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ / t₁ ⊆ s₂ / t₂ :=
image₂_subset
#align finset.div_subset_div Finset.div_subset_div
#align finset.sub_subset_sub Finset.sub_subset_sub
@[to_additive]
theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ :=
image₂_subset_left
#align finset.div_subset_div_left Finset.div_subset_div_left
#align finset.sub_subset_sub_left Finset.sub_subset_sub_left
@[to_additive]
theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t :=
image₂_subset_right
#align finset.div_subset_div_right Finset.div_subset_div_right
#align finset.sub_subset_sub_right Finset.sub_subset_sub_right
@[to_additive]
theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u :=
image₂_subset_iff
#align finset.div_subset_iff Finset.div_subset_iff
#align finset.sub_subset_iff Finset.sub_subset_iff
@[to_additive]
theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t :=
image₂_union_left
#align finset.union_div Finset.union_div
#align finset.union_sub Finset.union_sub
@[to_additive]
theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ :=
image₂_union_right
#align finset.div_union Finset.div_union
#align finset.sub_union Finset.sub_union
@[to_additive]
theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) :=
image₂_inter_subset_left
#align finset.inter_div_subset Finset.inter_div_subset
#align finset.inter_sub_subset Finset.inter_sub_subset
@[to_additive]
theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) :=
image₂_inter_subset_right
#align finset.div_inter_subset Finset.div_inter_subset
#align finset.sub_inter_subset Finset.sub_inter_subset
@[to_additive]
theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ :=
image₂_inter_union_subset_union
#align finset.inter_div_union_subset_union Finset.inter_div_union_subset_union
#align finset.inter_sub_union_subset_union Finset.inter_sub_union_subset_union
@[to_additive]
theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ :=
image₂_union_inter_subset_union
#align finset.union_div_inter_subset_union Finset.union_div_inter_subset_union
#align finset.union_sub_inter_subset_union Finset.union_sub_inter_subset_union
/-- If a finset `u` is contained in the product of two sets `s / t`, we can find two finsets `s'`,
`t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' / t'`. -/
@[to_additive
"If a finset `u` is contained in the sum of two sets `s - t`, we can find two finsets
`s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' - t'`."]
theorem subset_div {s t : Set α} :
↑u ⊆ s / t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' / t' :=
subset_image₂
#align finset.subset_div Finset.subset_div
#align finset.subset_sub Finset.subset_sub
@[to_additive (attr := simp (default + 1))]
lemma sup_div_le [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} :
sup (s / t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x / y) ≤ a :=
sup_image₂_le
@[to_additive]
lemma sup_div_left [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s / t) f = sup s fun x ↦ sup t (f <| x / ·) :=
sup_image₂_left ..
@[to_additive]
lemma sup_div_right [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s / t) f = sup t fun y ↦ sup s (f <| · / y) :=
sup_image₂_right ..
@[to_additive (attr := simp (default + 1))]
lemma le_inf_div [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} :
a ≤ inf (s / t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x / y) :=
le_inf_image₂
@[to_additive]
lemma inf_div_left [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s / t) f = inf s fun x ↦ inf t (f <| x / ·) :=
inf_image₂_left ..
@[to_additive]
lemma inf_div_right [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s / t) f = inf t fun y ↦ inf s (f <| · / y) :=
inf_image₂_right ..
end Div
/-! ### Instances -/
open Pointwise
section Instances
variable [DecidableEq α] [DecidableEq β]
/-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Finset`. See
note [pointwise nat action]. -/
protected def nsmul [Zero α] [Add α] : SMul ℕ (Finset α) :=
⟨nsmulRec⟩
#align finset.has_nsmul Finset.nsmul
/-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a
`Finset`. See note [pointwise nat action]. -/
protected def npow [One α] [Mul α] : Pow (Finset α) ℕ :=
⟨fun s n => npowRec n s⟩
#align finset.has_npow Finset.npow
attribute [to_additive existing] Finset.npow
/-- Repeated pointwise addition/subtraction (not the same as pointwise repeated
addition/subtraction!) of a `Finset`. See note [pointwise nat action]. -/
protected def zsmul [Zero α] [Add α] [Neg α] : SMul ℤ (Finset α) :=
⟨zsmulRec⟩
#align finset.has_zsmul Finset.zsmul
/-- Repeated pointwise multiplication/division (not the same as pointwise repeated
multiplication/division!) of a `Finset`. See note [pointwise nat action]. -/
@[to_additive existing]
protected def zpow [One α] [Mul α] [Inv α] : Pow (Finset α) ℤ :=
⟨fun s n => zpowRec npowRec n s⟩
#align finset.has_zpow Finset.zpow
scoped[Pointwise] attribute [instance] Finset.nsmul Finset.npow Finset.zsmul Finset.zpow
/-- `Finset α` is a `Semigroup` under pointwise operations if `α` is. -/
@[to_additive "`Finset α` is an `AddSemigroup` under pointwise operations if `α` is. "]
protected def semigroup [Semigroup α] : Semigroup (Finset α) :=
coe_injective.semigroup _ coe_mul
#align finset.semigroup Finset.semigroup
#align finset.add_semigroup Finset.addSemigroup
section CommSemigroup
variable [CommSemigroup α] {s t : Finset α}
/-- `Finset α` is a `CommSemigroup` under pointwise operations if `α` is. -/
@[to_additive "`Finset α` is an `AddCommSemigroup` under pointwise operations if `α` is. "]
protected def commSemigroup : CommSemigroup (Finset α) :=
coe_injective.commSemigroup _ coe_mul
#align finset.comm_semigroup Finset.commSemigroup
#align finset.add_comm_semigroup Finset.addCommSemigroup
@[to_additive]
theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t :=
image₂_inter_union_subset mul_comm
#align finset.inter_mul_union_subset Finset.inter_mul_union_subset
#align finset.inter_add_union_subset Finset.inter_add_union_subset
@[to_additive]
theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t :=
image₂_union_inter_subset mul_comm
#align finset.union_mul_inter_subset Finset.union_mul_inter_subset
#align finset.union_add_inter_subset Finset.union_add_inter_subset
end CommSemigroup
section MulOneClass
variable [MulOneClass α]
/-- `Finset α` is a `MulOneClass` under pointwise operations if `α` is. -/
@[to_additive "`Finset α` is an `AddZeroClass` under pointwise operations if `α` is."]
protected def mulOneClass : MulOneClass (Finset α) :=
coe_injective.mulOneClass _ (coe_singleton 1) coe_mul
#align finset.mul_one_class Finset.mulOneClass
#align finset.add_zero_class Finset.addZeroClass
scoped[Pointwise] attribute [instance] Finset.semigroup Finset.addSemigroup Finset.commSemigroup
Finset.addCommSemigroup Finset.mulOneClass Finset.addZeroClass
@[to_additive]
theorem subset_mul_left (s : Finset α) {t : Finset α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun a ha =>
mem_mul.2 ⟨a, ha, 1, ht, mul_one _⟩
#align finset.subset_mul_left Finset.subset_mul_left
#align finset.subset_add_left Finset.subset_add_left
@[to_additive]
theorem subset_mul_right {s : Finset α} (t : Finset α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun a ha =>
mem_mul.2 ⟨1, hs, a, ha, one_mul _⟩
#align finset.subset_mul_right Finset.subset_mul_right
#align finset.subset_add_right Finset.subset_add_right
/-- The singleton operation as a `MonoidHom`. -/
@[to_additive "The singleton operation as an `AddMonoidHom`."]
def singletonMonoidHom : α →* Finset α :=
{ singletonMulHom, singletonOneHom with }
#align finset.singleton_monoid_hom Finset.singletonMonoidHom
#align finset.singleton_add_monoid_hom Finset.singletonAddMonoidHom
@[to_additive (attr := simp)]
theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Finset α) = singleton :=
rfl
#align finset.coe_singleton_monoid_hom Finset.coe_singletonMonoidHom
#align finset.coe_singleton_add_monoid_hom Finset.coe_singletonAddMonoidHom
@[to_additive (attr := simp)]
theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} :=
rfl
#align finset.singleton_monoid_hom_apply Finset.singletonMonoidHom_apply
#align finset.singleton_add_monoid_hom_apply Finset.singletonAddMonoidHom_apply
/-- The coercion from `Finset` to `Set` as a `MonoidHom`. -/
@[to_additive "The coercion from `Finset` to `set` as an `AddMonoidHom`."]
noncomputable def coeMonoidHom : Finset α →* Set α where
toFun := CoeTC.coe
map_one' := coe_one
map_mul' := coe_mul
#align finset.coe_monoid_hom Finset.coeMonoidHom
#align finset.coe_add_monoid_hom Finset.coeAddMonoidHom
@[to_additive (attr := simp)]
theorem coe_coeMonoidHom : (coeMonoidHom : Finset α → Set α) = CoeTC.coe :=
rfl
#align finset.coe_coe_monoid_hom Finset.coe_coeMonoidHom
#align finset.coe_coe_add_monoid_hom Finset.coe_coeAddMonoidHom
@[to_additive (attr := simp)]
theorem coeMonoidHom_apply (s : Finset α) : coeMonoidHom s = s :=
rfl
#align finset.coe_monoid_hom_apply Finset.coeMonoidHom_apply
#align finset.coe_add_monoid_hom_apply Finset.coeAddMonoidHom_apply
/-- Lift a `MonoidHom` to `Finset` via `image`. -/
@[to_additive (attr := simps) "Lift an `add_monoid_hom` to `Finset` via `image`"]
def imageMonoidHom [MulOneClass β] [FunLike F α β] [MonoidHomClass F α β] (f : F) :
Finset α →* Finset β :=
{ imageMulHom f, imageOneHom f with }
#align finset.image_monoid_hom Finset.imageMonoidHom
#align finset.image_add_monoid_hom Finset.imageAddMonoidHom
end MulOneClass
section Monoid
variable [Monoid α] {s t : Finset α} {a : α} {m n : ℕ}
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow (s : Finset α) (n : ℕ) : ↑(s ^ n) = (s : Set α) ^ n := by
change ↑(npowRec n s) = (s: Set α) ^ n
induction' n with n ih
· rw [npowRec, pow_zero, coe_one]
· rw [npowRec, pow_succ, coe_mul, ih]
#align finset.coe_pow Finset.coe_pow
/-- `Finset α` is a `Monoid` under pointwise operations if `α` is. -/
@[to_additive "`Finset α` is an `AddMonoid` under pointwise operations if `α` is. "]
protected def monoid : Monoid (Finset α) :=
coe_injective.monoid _ coe_one coe_mul coe_pow
#align finset.monoid Finset.monoid
#align finset.add_monoid Finset.addMonoid
scoped[Pointwise] attribute [instance] Finset.monoid Finset.addMonoid
@[to_additive]
theorem pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n
| 0 => by
rw [pow_zero]
exact one_mem_one
| n + 1 => by
rw [pow_succ]
exact mul_mem_mul (pow_mem_pow ha n) ha
#align finset.pow_mem_pow Finset.pow_mem_pow
#align finset.nsmul_mem_nsmul Finset.nsmul_mem_nsmul
@[to_additive]
theorem pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n
| 0 => by
simp [pow_zero]
| n + 1 => by
rw [pow_succ]
exact mul_subset_mul (pow_subset_pow hst n) hst
#align finset.pow_subset_pow Finset.pow_subset_pow
#align finset.nsmul_subset_nsmul Finset.nsmul_subset_nsmul
@[to_additive]
theorem pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) : m ≤ n → s ^ m ⊆ s ^ n := by
apply Nat.le_induction
· exact fun _ hn => hn
· intro n _ hmn
rw [pow_succ]
exact hmn.trans (subset_mul_left (s ^ n) hs)
#align finset.pow_subset_pow_of_one_mem Finset.pow_subset_pow_of_one_mem
#align finset.nsmul_subset_nsmul_of_zero_mem Finset.nsmul_subset_nsmul_of_zero_mem
@[to_additive (attr := simp, norm_cast)]
theorem coe_list_prod (s : List (Finset α)) : (↑s.prod : Set α) = (s.map (↑)).prod :=
map_list_prod (coeMonoidHom : Finset α →* Set α) _
#align finset.coe_list_prod Finset.coe_list_prod
#align finset.coe_list_sum Finset.coe_list_sum
@[to_additive]
theorem mem_prod_list_ofFn {a : α} {s : Fin n → Finset α} :
a ∈ (List.ofFn s).prod ↔ ∃ f : ∀ i : Fin n, s i, (List.ofFn fun i => (f i : α)).prod = a := by
rw [← mem_coe, coe_list_prod, List.map_ofFn, Set.mem_prod_list_ofFn]
rfl
#align finset.mem_prod_list_of_fn Finset.mem_prod_list_ofFn
#align finset.mem_sum_list_of_fn Finset.mem_sum_list_ofFn
@[to_additive]
theorem mem_pow {a : α} {n : ℕ} :
a ∈ s ^ n ↔ ∃ f : Fin n → s, (List.ofFn fun i => ↑(f i)).prod = a := by
set_option tactic.skipAssignedInstances false in
simp [← mem_coe, coe_pow, Set.mem_pow]
#align finset.mem_pow Finset.mem_pow
#align finset.mem_nsmul Finset.mem_nsmul
@[to_additive (attr := simp)]
theorem empty_pow (hn : n ≠ 0) : (∅ : Finset α) ^ n = ∅ := by
rw [← tsub_add_cancel_of_le (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn), pow_succ', empty_mul]
#align finset.empty_pow Finset.empty_pow
#align finset.empty_nsmul Finset.empty_nsmul
@[to_additive]
theorem mul_univ_of_one_mem [Fintype α] (hs : (1 : α) ∈ s) : s * univ = univ :=
eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, hs, _, mem_univ _, one_mul _⟩
#align finset.mul_univ_of_one_mem Finset.mul_univ_of_one_mem
#align finset.add_univ_of_zero_mem Finset.add_univ_of_zero_mem
@[to_additive]
theorem univ_mul_of_one_mem [Fintype α] (ht : (1 : α) ∈ t) : univ * t = univ :=
eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, mem_univ _, _, ht, mul_one _⟩
#align finset.univ_mul_of_one_mem Finset.univ_mul_of_one_mem
#align finset.univ_add_of_zero_mem Finset.univ_add_of_zero_mem
@[to_additive (attr := simp)]
theorem univ_mul_univ [Fintype α] : (univ : Finset α) * univ = univ :=
mul_univ_of_one_mem <| mem_univ _
#align finset.univ_mul_univ Finset.univ_mul_univ
#align finset.univ_add_univ Finset.univ_add_univ
@[to_additive (attr := simp) nsmul_univ]
theorem univ_pow [Fintype α] (hn : n ≠ 0) : (univ : Finset α) ^ n = univ :=
coe_injective <| by rw [coe_pow, coe_univ, Set.univ_pow hn]
#align finset.univ_pow Finset.univ_pow
#align finset.nsmul_univ Finset.nsmul_univ
@[to_additive]
protected theorem _root_.IsUnit.finset : IsUnit a → IsUnit ({a} : Finset α) :=
IsUnit.map (singletonMonoidHom : α →* Finset α)
#align is_unit.finset IsUnit.finset
#align is_add_unit.finset IsAddUnit.finset
end Monoid
section CommMonoid
variable [CommMonoid α]
/-- `Finset α` is a `CommMonoid` under pointwise operations if `α` is. -/
@[to_additive "`Finset α` is an `AddCommMonoid` under pointwise operations if `α` is. "]
protected def commMonoid : CommMonoid (Finset α) :=
coe_injective.commMonoid _ coe_one coe_mul coe_pow
#align finset.comm_monoid Finset.commMonoid
#align finset.add_comm_monoid Finset.addCommMonoid
scoped[Pointwise] attribute [instance] Finset.commMonoid Finset.addCommMonoid
@[to_additive (attr := simp, norm_cast)]
theorem coe_prod {ι : Type*} (s : Finset ι) (f : ι → Finset α) :
↑(∏ i ∈ s, f i) = ∏ i ∈ s, (f i : Set α) :=
map_prod ((coeMonoidHom) : Finset α →* Set α) _ _
#align finset.coe_prod Finset.coe_prod
#align finset.coe_sum Finset.coe_sum
end CommMonoid
open Pointwise
section DivisionMonoid
variable [DivisionMonoid α] {s t : Finset α}
@[to_additive (attr := simp)]
theorem coe_zpow (s : Finset α) : ∀ n : ℤ, ↑(s ^ n) = (s : Set α) ^ n
| Int.ofNat n => coe_pow _ _
| Int.negSucc n => by
refine (coe_inv _).trans ?_
exact congr_arg Inv.inv (coe_pow _ _)
#align finset.coe_zpow Finset.coe_zpow
#align finset.coe_zsmul Finset.coe_zsmul
@[to_additive]
protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 := by
simp_rw [← coe_inj, coe_mul, coe_one, Set.mul_eq_one_iff, coe_singleton]
#align finset.mul_eq_one_iff Finset.mul_eq_one_iff
#align finset.add_eq_zero_iff Finset.add_eq_zero_iff
/-- `Finset α` is a division monoid under pointwise operations if `α` is. -/
@[to_additive subtractionMonoid
"`Finset α` is a subtraction monoid under pointwise operations if `α` is."]
protected def divisionMonoid : DivisionMonoid (Finset α) :=
coe_injective.divisionMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow
#align finset.division_monoid Finset.divisionMonoid
#align finset.subtraction_monoid Finset.subtractionMonoid
scoped[Pointwise] attribute [instance] Finset.divisionMonoid Finset.subtractionMonoid
@[to_additive (attr := simp)]
theorem isUnit_iff : IsUnit s ↔ ∃ a, s = {a} ∧ IsUnit a := by
constructor
· rintro ⟨u, rfl⟩
obtain ⟨a, b, ha, hb, h⟩ := Finset.mul_eq_one_iff.1 u.mul_inv
refine ⟨a, ha, ⟨a, b, h, singleton_injective ?_⟩, rfl⟩
rw [← singleton_mul_singleton, ← ha, ← hb]
exact u.inv_mul
· rintro ⟨a, rfl, ha⟩
exact ha.finset
#align finset.is_unit_iff Finset.isUnit_iff
#align finset.is_add_unit_iff Finset.isAddUnit_iff
@[to_additive (attr := simp)]
theorem isUnit_coe : IsUnit (s : Set α) ↔ IsUnit s := by
simp_rw [isUnit_iff, Set.isUnit_iff, coe_eq_singleton]
#align finset.is_unit_coe Finset.isUnit_coe
#align finset.is_add_unit_coe Finset.isAddUnit_coe
@[to_additive (attr := simp)]
lemma univ_div_univ [Fintype α] : (univ / univ : Finset α) = univ := by simp [div_eq_mul_inv]
end DivisionMonoid
/-- `Finset α` is a commutative division monoid under pointwise operations if `α` is. -/
@[to_additive subtractionCommMonoid
"`Finset α` is a commutative subtraction monoid under pointwise operations if `α` is."]
protected def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Finset α) :=
coe_injective.divisionCommMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow
#align finset.division_comm_monoid Finset.divisionCommMonoid
#align finset.subtraction_comm_monoid Finset.subtractionCommMonoid
/-- `Finset α` has distributive negation if `α` has. -/
protected def distribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Finset α) :=
coe_injective.hasDistribNeg _ coe_neg coe_mul
#align finset.has_distrib_neg Finset.distribNeg
scoped[Pointwise]
attribute [instance] Finset.divisionCommMonoid Finset.subtractionCommMonoid Finset.distribNeg
section Distrib
variable [Distrib α] (s t u : Finset α)
/-!
Note that `Finset α` is not a `Distrib` because `s * t + s * u` has cross terms that `s * (t + u)`
lacks.
```lean
-- {10, 16, 18, 20, 8, 9}
#eval {1, 2} * ({3, 4} + {5, 6} : Finset ℕ)
-- {10, 11, 12, 13, 14, 15, 16, 18, 20, 8, 9}
#eval ({1, 2} : Finset ℕ) * {3, 4} + {1, 2} * {5, 6}
```
-/
theorem mul_add_subset : s * (t + u) ⊆ s * t + s * u :=
image₂_distrib_subset_left mul_add
#align finset.mul_add_subset Finset.mul_add_subset
theorem add_mul_subset : (s + t) * u ⊆ s * u + t * u :=
image₂_distrib_subset_right add_mul
#align finset.add_mul_subset Finset.add_mul_subset
end Distrib
section MulZeroClass
variable [MulZeroClass α] {s t : Finset α}
/-! Note that `Finset` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/
theorem mul_zero_subset (s : Finset α) : s * 0 ⊆ 0 := by simp [subset_iff, mem_mul]
#align finset.mul_zero_subset Finset.mul_zero_subset
theorem zero_mul_subset (s : Finset α) : 0 * s ⊆ 0 := by simp [subset_iff, mem_mul]
#align finset.zero_mul_subset Finset.zero_mul_subset
theorem Nonempty.mul_zero (hs : s.Nonempty) : s * 0 = 0 :=
s.mul_zero_subset.antisymm <| by simpa [mem_mul] using hs
#align finset.nonempty.mul_zero Finset.Nonempty.mul_zero
theorem Nonempty.zero_mul (hs : s.Nonempty) : 0 * s = 0 :=
s.zero_mul_subset.antisymm <| by simpa [mem_mul] using hs
#align finset.nonempty.zero_mul Finset.Nonempty.zero_mul
end MulZeroClass
section Group
variable [Group α] [DivisionMonoid β] [FunLike F α β] [MonoidHomClass F α β]
variable (f : F) {s t : Finset α} {a b : α}
/-! Note that `Finset` is not a `Group` because `s / s ≠ 1` in general. -/
@[to_additive (attr := simp)]
theorem one_mem_div_iff : (1 : α) ∈ s / t ↔ ¬Disjoint s t := by
rw [← mem_coe, ← disjoint_coe, coe_div, Set.one_mem_div_iff]
#align finset.one_mem_div_iff Finset.one_mem_div_iff
#align finset.zero_mem_sub_iff Finset.zero_mem_sub_iff
@[to_additive]
theorem not_one_mem_div_iff : (1 : α) ∉ s / t ↔ Disjoint s t :=
one_mem_div_iff.not_left
#align finset.not_one_mem_div_iff Finset.not_one_mem_div_iff
#align finset.not_zero_mem_sub_iff Finset.not_zero_mem_sub_iff
@[to_additive]
theorem Nonempty.one_mem_div (h : s.Nonempty) : (1 : α) ∈ s / s :=
let ⟨a, ha⟩ := h
mem_div.2 ⟨a, ha, a, ha, div_self' _⟩
#align finset.nonempty.one_mem_div Finset.Nonempty.one_mem_div
#align finset.nonempty.zero_mem_sub Finset.Nonempty.zero_mem_sub
@[to_additive]
theorem isUnit_singleton (a : α) : IsUnit ({a} : Finset α) :=
(Group.isUnit a).finset
#align finset.is_unit_singleton Finset.isUnit_singleton
#align finset.is_add_unit_singleton Finset.isAddUnit_singleton
/- Porting note: not in simp nf; Added non-simpable part as `isUnit_iff_singleton_aux` below
Left-hand side simplifies from
IsUnit s
to
∃ a, s = {a} ∧ IsUnit a -/
-- @[simp]
theorem isUnit_iff_singleton : IsUnit s ↔ ∃ a, s = {a} := by
simp only [isUnit_iff, Group.isUnit, and_true_iff]
#align finset.is_unit_iff_singleton Finset.isUnit_iff_singleton
@[simp]
theorem isUnit_iff_singleton_aux : (∃ a, s = {a} ∧ IsUnit a) ↔ ∃ a, s = {a} := by
simp only [Group.isUnit, and_true_iff]
@[to_additive (attr := simp)]
theorem image_mul_left :
image (fun b => a * b) t = preimage t (fun b => a⁻¹ * b) (mul_right_injective _).injOn :=
coe_injective <| by simp
#align finset.image_mul_left Finset.image_mul_left
#align finset.image_add_left Finset.image_add_left
@[to_additive (attr := simp)]
theorem image_mul_right : image (· * b) t = preimage t (· * b⁻¹) (mul_left_injective _).injOn :=
coe_injective <| by simp
#align finset.image_mul_right Finset.image_mul_right
#align finset.image_add_right Finset.image_add_right
@[to_additive]
theorem image_mul_left' :
image (fun b => a⁻¹ * b) t = preimage t (fun b => a * b) (mul_right_injective _).injOn := by
simp
#align finset.image_mul_left' Finset.image_mul_left'
#align finset.image_add_left' Finset.image_add_left'
@[to_additive]
theorem image_mul_right' :
image (· * b⁻¹) t = preimage t (· * b) (mul_left_injective _).injOn := by simp
#align finset.image_mul_right' Finset.image_mul_right'
#align finset.image_add_right' Finset.image_add_right'
theorem image_div : (s / t).image (f : α → β) = s.image f / t.image f :=
image_image₂_distrib <| map_div f
#align finset.image_div Finset.image_div
end Group
section GroupWithZero
variable [GroupWithZero α] {s t : Finset α}
theorem div_zero_subset (s : Finset α) : s / 0 ⊆ 0 := by simp [subset_iff, mem_div]
#align finset.div_zero_subset Finset.div_zero_subset
theorem zero_div_subset (s : Finset α) : 0 / s ⊆ 0 := by simp [subset_iff, mem_div]
#align finset.zero_div_subset Finset.zero_div_subset
theorem Nonempty.div_zero (hs : s.Nonempty) : s / 0 = 0 :=
s.div_zero_subset.antisymm <| by simpa [mem_div] using hs
#align finset.nonempty.div_zero Finset.Nonempty.div_zero
theorem Nonempty.zero_div (hs : s.Nonempty) : 0 / s = 0 :=
s.zero_div_subset.antisymm <| by simpa [mem_div] using hs
#align finset.nonempty.zero_div Finset.Nonempty.zero_div
end GroupWithZero
end Instances
section Group
variable [Group α] {s t : Finset α} {a b : α}
@[to_additive (attr := simp)]
theorem preimage_mul_left_singleton :
preimage {b} (a * ·) (mul_right_injective _).injOn = {a⁻¹ * b} := by
classical rw [← image_mul_left', image_singleton]
#align finset.preimage_mul_left_singleton Finset.preimage_mul_left_singleton
#align finset.preimage_add_left_singleton Finset.preimage_add_left_singleton
@[to_additive (attr := simp)]
theorem preimage_mul_right_singleton :
preimage {b} (· * a) (mul_left_injective _).injOn = {b * a⁻¹} := by
classical rw [← image_mul_right', image_singleton]
#align finset.preimage_mul_right_singleton Finset.preimage_mul_right_singleton
#align finset.preimage_add_right_singleton Finset.preimage_add_right_singleton
@[to_additive (attr := simp)]
theorem preimage_mul_left_one : preimage 1 (a * ·) (mul_right_injective _).injOn = {a⁻¹} := by
classical rw [← image_mul_left', image_one, mul_one]
#align finset.preimage_mul_left_one Finset.preimage_mul_left_one
#align finset.preimage_add_left_zero Finset.preimage_add_left_zero
@[to_additive (attr := simp)]
theorem preimage_mul_right_one : preimage 1 (· * b) (mul_left_injective _).injOn = {b⁻¹} := by
classical rw [← image_mul_right', image_one, one_mul]
#align finset.preimage_mul_right_one Finset.preimage_mul_right_one
#align finset.preimage_add_right_zero Finset.preimage_add_right_zero
@[to_additive]
theorem preimage_mul_left_one' : preimage 1 (a⁻¹ * ·) (mul_right_injective _).injOn = {a} := by
rw [preimage_mul_left_one, inv_inv]
#align finset.preimage_mul_left_one' Finset.preimage_mul_left_one'
#align finset.preimage_add_left_zero' Finset.preimage_add_left_zero'
@[to_additive]
theorem preimage_mul_right_one' : preimage 1 (· * b⁻¹) (mul_left_injective _).injOn = {b} := by
rw [preimage_mul_right_one, inv_inv]
#align finset.preimage_mul_right_one' Finset.preimage_mul_right_one'
#align finset.preimage_add_right_zero' Finset.preimage_add_right_zero'
end Group
/-! ### Scalar addition/multiplication of finsets -/
section SMul
variable [DecidableEq β] [SMul α β] {s s₁ s₂ : Finset α} {t t₁ t₂ u : Finset β} {a : α} {b : β}
/-- The pointwise product of two finsets `s` and `t`: `s • t = {x • y | x ∈ s, y ∈ t}`. -/
@[to_additive "The pointwise sum of two finsets `s` and `t`: `s +ᵥ t = {x +ᵥ y | x ∈ s, y ∈ t}`."]
protected def smul : SMul (Finset α) (Finset β) :=
⟨image₂ (· • ·)⟩
#align finset.has_smul Finset.smul
#align finset.has_vadd Finset.vadd
scoped[Pointwise] attribute [instance] Finset.smul Finset.vadd
@[to_additive]
theorem smul_def : s • t = (s ×ˢ t).image fun p : α × β => p.1 • p.2 :=
rfl
#align finset.smul_def Finset.smul_def
#align finset.vadd_def Finset.vadd_def
@[to_additive]
theorem image_smul_product : ((s ×ˢ t).image fun x : α × β => x.fst • x.snd) = s • t :=
rfl
#align finset.image_smul_product Finset.image_smul_product
#align finset.image_vadd_product Finset.image_vadd_product
@[to_additive]
theorem mem_smul {x : β} : x ∈ s • t ↔ ∃ y ∈ s, ∃ z ∈ t, y • z = x :=
mem_image₂
#align finset.mem_smul Finset.mem_smul
#align finset.mem_vadd Finset.mem_vadd
@[to_additive (attr := simp, norm_cast)]
theorem coe_smul (s : Finset α) (t : Finset β) : ↑(s • t) = (s : Set α) • (t : Set β) :=
coe_image₂ _ _ _
#align finset.coe_smul Finset.coe_smul
#align finset.coe_vadd Finset.coe_vadd
@[to_additive]
theorem smul_mem_smul : a ∈ s → b ∈ t → a • b ∈ s • t :=
mem_image₂_of_mem
#align finset.smul_mem_smul Finset.smul_mem_smul
#align finset.vadd_mem_vadd Finset.vadd_mem_vadd
@[to_additive]
theorem smul_card_le : (s • t).card ≤ s.card • t.card :=
card_image₂_le _ _ _
#align finset.smul_card_le Finset.smul_card_le
#align finset.vadd_card_le Finset.vadd_card_le
@[to_additive (attr := simp)]
theorem empty_smul (t : Finset β) : (∅ : Finset α) • t = ∅ :=
image₂_empty_left
#align finset.empty_smul Finset.empty_smul
#align finset.empty_vadd Finset.empty_vadd
@[to_additive (attr := simp)]
theorem smul_empty (s : Finset α) : s • (∅ : Finset β) = ∅ :=
image₂_empty_right
#align finset.smul_empty Finset.smul_empty
#align finset.vadd_empty Finset.vadd_empty
@[to_additive (attr := simp)]
theorem smul_eq_empty : s • t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
#align finset.smul_eq_empty Finset.smul_eq_empty
#align finset.vadd_eq_empty Finset.vadd_eq_empty
@[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))]
theorem smul_nonempty_iff : (s • t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
#align finset.smul_nonempty_iff Finset.smul_nonempty_iff
#align finset.vadd_nonempty_iff Finset.vadd_nonempty_iff
@[to_additive]
theorem Nonempty.smul : s.Nonempty → t.Nonempty → (s • t).Nonempty :=
Nonempty.image₂
#align finset.nonempty.smul Finset.Nonempty.smul
#align finset.nonempty.vadd Finset.Nonempty.vadd
@[to_additive]
theorem Nonempty.of_smul_left : (s • t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
#align finset.nonempty.of_smul_left Finset.Nonempty.of_smul_left
#align finset.nonempty.of_vadd_left Finset.Nonempty.of_vadd_left
@[to_additive]
theorem Nonempty.of_smul_right : (s • t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
#align finset.nonempty.of_smul_right Finset.Nonempty.of_smul_right
#align finset.nonempty.of_vadd_right Finset.Nonempty.of_vadd_right
@[to_additive]
theorem smul_singleton (b : β) : s • ({b} : Finset β) = s.image (· • b) :=
image₂_singleton_right
#align finset.smul_singleton Finset.smul_singleton
#align finset.vadd_singleton Finset.vadd_singleton
@[to_additive]
theorem singleton_smul_singleton (a : α) (b : β) : ({a} : Finset α) • ({b} : Finset β) = {a • b} :=
image₂_singleton
#align finset.singleton_smul_singleton Finset.singleton_smul_singleton
#align finset.singleton_vadd_singleton Finset.singleton_vadd_singleton
@[to_additive (attr := mono)]
theorem smul_subset_smul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ • t₁ ⊆ s₂ • t₂ :=
image₂_subset
#align finset.smul_subset_smul Finset.smul_subset_smul
#align finset.vadd_subset_vadd Finset.vadd_subset_vadd
@[to_additive]
theorem smul_subset_smul_left : t₁ ⊆ t₂ → s • t₁ ⊆ s • t₂ :=
image₂_subset_left
#align finset.smul_subset_smul_left Finset.smul_subset_smul_left
#align finset.vadd_subset_vadd_left Finset.vadd_subset_vadd_left
@[to_additive]
theorem smul_subset_smul_right : s₁ ⊆ s₂ → s₁ • t ⊆ s₂ • t :=
image₂_subset_right
#align finset.smul_subset_smul_right Finset.smul_subset_smul_right
#align finset.vadd_subset_vadd_right Finset.vadd_subset_vadd_right
@[to_additive]
theorem smul_subset_iff : s • t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a • b ∈ u :=
image₂_subset_iff
#align finset.smul_subset_iff Finset.smul_subset_iff
#align finset.vadd_subset_iff Finset.vadd_subset_iff
@[to_additive]
theorem union_smul [DecidableEq α] : (s₁ ∪ s₂) • t = s₁ • t ∪ s₂ • t :=
image₂_union_left
#align finset.union_smul Finset.union_smul
#align finset.union_vadd Finset.union_vadd
@[to_additive]
theorem smul_union : s • (t₁ ∪ t₂) = s • t₁ ∪ s • t₂ :=
image₂_union_right
#align finset.smul_union Finset.smul_union
#align finset.vadd_union Finset.vadd_union
@[to_additive]
theorem inter_smul_subset [DecidableEq α] : (s₁ ∩ s₂) • t ⊆ s₁ • t ∩ s₂ • t :=
image₂_inter_subset_left
#align finset.inter_smul_subset Finset.inter_smul_subset
#align finset.inter_vadd_subset Finset.inter_vadd_subset
@[to_additive]
theorem smul_inter_subset : s • (t₁ ∩ t₂) ⊆ s • t₁ ∩ s • t₂ :=
image₂_inter_subset_right
#align finset.smul_inter_subset Finset.smul_inter_subset
#align finset.vadd_inter_subset Finset.vadd_inter_subset
@[to_additive]
theorem inter_smul_union_subset_union [DecidableEq α] : (s₁ ∩ s₂) • (t₁ ∪ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ :=
image₂_inter_union_subset_union
#align finset.inter_smul_union_subset_union Finset.inter_smul_union_subset_union
#align finset.inter_vadd_union_subset_union Finset.inter_vadd_union_subset_union
@[to_additive]
theorem union_smul_inter_subset_union [DecidableEq α] : (s₁ ∪ s₂) • (t₁ ∩ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ :=
image₂_union_inter_subset_union
#align finset.union_smul_inter_subset_union Finset.union_smul_inter_subset_union
#align finset.union_vadd_inter_subset_union Finset.union_vadd_inter_subset_union
/-- If a finset `u` is contained in the scalar product of two sets `s • t`, we can find two finsets
`s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' • t'`. -/
@[to_additive
"If a finset `u` is contained in the scalar sum of two sets `s +ᵥ t`, we can find two
finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' +ᵥ t'`."]
theorem subset_smul {s : Set α} {t : Set β} :
↑u ⊆ s • t → ∃ (s' : Finset α) (t' : Finset β), ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' • t' :=
subset_image₂
#align finset.subset_smul Finset.subset_smul
#align finset.subset_vadd Finset.subset_vadd
end SMul
/-! ### Scalar subtraction of finsets -/
section VSub
-- Porting note: Reordered [VSub α β] and [DecidableEq α] to make vsub less dangerous. Bad?
variable [VSub α β] [DecidableEq α] {s s₁ s₂ t t₁ t₂ : Finset β} {u : Finset α} {a : α} {b c : β}
/-- The pointwise subtraction of two finsets `s` and `t`: `s -ᵥ t = {x -ᵥ y | x ∈ s, y ∈ t}`. -/
protected def vsub : VSub (Finset α) (Finset β) :=
⟨image₂ (· -ᵥ ·)⟩
#align finset.has_vsub Finset.vsub
scoped[Pointwise] attribute [instance] Finset.vsub
theorem vsub_def : s -ᵥ t = image₂ (· -ᵥ ·) s t :=
rfl
#align finset.vsub_def Finset.vsub_def
@[simp]
theorem image_vsub_product : image₂ (· -ᵥ ·) s t = s -ᵥ t :=
rfl
#align finset.image_vsub_product Finset.image_vsub_product
theorem mem_vsub : a ∈ s -ᵥ t ↔ ∃ b ∈ s, ∃ c ∈ t, b -ᵥ c = a :=
mem_image₂
#align finset.mem_vsub Finset.mem_vsub
@[simp, norm_cast]
theorem coe_vsub (s t : Finset β) : (↑(s -ᵥ t) : Set α) = (s : Set β) -ᵥ t :=
coe_image₂ _ _ _
#align finset.coe_vsub Finset.coe_vsub
theorem vsub_mem_vsub : b ∈ s → c ∈ t → b -ᵥ c ∈ s -ᵥ t :=
mem_image₂_of_mem
#align finset.vsub_mem_vsub Finset.vsub_mem_vsub
theorem vsub_card_le : (s -ᵥ t : Finset α).card ≤ s.card * t.card :=
card_image₂_le _ _ _
#align finset.vsub_card_le Finset.vsub_card_le
@[simp]
theorem empty_vsub (t : Finset β) : (∅ : Finset β) -ᵥ t = ∅ :=
image₂_empty_left
#align finset.empty_vsub Finset.empty_vsub
@[simp]
theorem vsub_empty (s : Finset β) : s -ᵥ (∅ : Finset β) = ∅ :=
image₂_empty_right
#align finset.vsub_empty Finset.vsub_empty
@[simp]
theorem vsub_eq_empty : s -ᵥ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
#align finset.vsub_eq_empty Finset.vsub_eq_empty
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem vsub_nonempty : (s -ᵥ t : Finset α).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
#align finset.vsub_nonempty Finset.vsub_nonempty
theorem Nonempty.vsub : s.Nonempty → t.Nonempty → (s -ᵥ t : Finset α).Nonempty :=
Nonempty.image₂
#align finset.nonempty.vsub Finset.Nonempty.vsub
theorem Nonempty.of_vsub_left : (s -ᵥ t : Finset α).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
#align finset.nonempty.of_vsub_left Finset.Nonempty.of_vsub_left
theorem Nonempty.of_vsub_right : (s -ᵥ t : Finset α).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
#align finset.nonempty.of_vsub_right Finset.Nonempty.of_vsub_right
@[simp]
theorem vsub_singleton (b : β) : s -ᵥ ({b} : Finset β) = s.image (· -ᵥ b) :=
image₂_singleton_right
#align finset.vsub_singleton Finset.vsub_singleton
theorem singleton_vsub (a : β) : ({a} : Finset β) -ᵥ t = t.image (a -ᵥ ·) :=
image₂_singleton_left
#align finset.singleton_vsub Finset.singleton_vsub
-- @[simp] -- Porting note (#10618): simp can prove this
theorem singleton_vsub_singleton (a b : β) : ({a} : Finset β) -ᵥ {b} = {a -ᵥ b} :=
image₂_singleton
#align finset.singleton_vsub_singleton Finset.singleton_vsub_singleton
@[mono]
theorem vsub_subset_vsub : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ -ᵥ t₁ ⊆ s₂ -ᵥ t₂ :=
image₂_subset
#align finset.vsub_subset_vsub Finset.vsub_subset_vsub
theorem vsub_subset_vsub_left : t₁ ⊆ t₂ → s -ᵥ t₁ ⊆ s -ᵥ t₂ :=
image₂_subset_left
#align finset.vsub_subset_vsub_left Finset.vsub_subset_vsub_left
theorem vsub_subset_vsub_right : s₁ ⊆ s₂ → s₁ -ᵥ t ⊆ s₂ -ᵥ t :=
image₂_subset_right
#align finset.vsub_subset_vsub_right Finset.vsub_subset_vsub_right
theorem vsub_subset_iff : s -ᵥ t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x -ᵥ y ∈ u :=
image₂_subset_iff
#align finset.vsub_subset_iff Finset.vsub_subset_iff
section
variable [DecidableEq β]
theorem union_vsub : s₁ ∪ s₂ -ᵥ t = s₁ -ᵥ t ∪ (s₂ -ᵥ t) :=
image₂_union_left
#align finset.union_vsub Finset.union_vsub
theorem vsub_union : s -ᵥ (t₁ ∪ t₂) = s -ᵥ t₁ ∪ (s -ᵥ t₂) :=
image₂_union_right
#align finset.vsub_union Finset.vsub_union
theorem inter_vsub_subset : s₁ ∩ s₂ -ᵥ t ⊆ (s₁ -ᵥ t) ∩ (s₂ -ᵥ t) :=
image₂_inter_subset_left
#align finset.inter_vsub_subset Finset.inter_vsub_subset
theorem vsub_inter_subset : s -ᵥ t₁ ∩ t₂ ⊆ (s -ᵥ t₁) ∩ (s -ᵥ t₂) :=
image₂_inter_subset_right
#align finset.vsub_inter_subset Finset.vsub_inter_subset
end
/-- If a finset `u` is contained in the pointwise subtraction of two sets `s -ᵥ t`, we can find two
finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' -ᵥ t'`. -/
theorem subset_vsub {s t : Set β} :
↑u ⊆ s -ᵥ t → ∃ s' t' : Finset β, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' -ᵥ t' :=
subset_image₂
#align finset.subset_vsub Finset.subset_vsub
end VSub
open Pointwise
/-! ### Translation/scaling of finsets -/
section SMul
variable [DecidableEq β] [SMul α β] {s s₁ s₂ t u : Finset β} {a : α} {b : β}
/-- The scaling of a finset `s` by a scalar `a`: `a • s = {a • x | x ∈ s}`. -/
@[to_additive "The translation of a finset `s` by a vector `a`: `a +ᵥ s = {a +ᵥ x | x ∈ s}`."]
protected def smulFinset : SMul α (Finset β) :=
⟨fun a => image <| (a • ·)⟩
#align finset.has_smul_finset Finset.smulFinset
#align finset.has_vadd_finset Finset.vaddFinset
scoped[Pointwise] attribute [instance] Finset.smulFinset Finset.vaddFinset
@[to_additive]
theorem smul_finset_def : a • s = s.image (a • ·) :=
rfl
#align finset.smul_finset_def Finset.smul_finset_def
#align finset.vadd_finset_def Finset.vadd_finset_def
@[to_additive]
theorem image_smul : (s.image fun x => a • x) = a • s :=
rfl
#align finset.image_smul Finset.image_smul
#align finset.image_vadd Finset.image_vadd
@[to_additive]
theorem mem_smul_finset {x : β} : x ∈ a • s ↔ ∃ y, y ∈ s ∧ a • y = x := by
simp only [Finset.smul_finset_def, and_assoc, mem_image, exists_prop, Prod.exists, mem_product]
#align finset.mem_smul_finset Finset.mem_smul_finset
#align finset.mem_vadd_finset Finset.mem_vadd_finset
@[to_additive (attr := simp, norm_cast)]
theorem coe_smul_finset (a : α) (s : Finset β) : ↑(a • s) = a • (↑s : Set β) :=
coe_image
#align finset.coe_smul_finset Finset.coe_smul_finset
#align finset.coe_vadd_finset Finset.coe_vadd_finset
@[to_additive]
theorem smul_mem_smul_finset : b ∈ s → a • b ∈ a • s :=
mem_image_of_mem _
#align finset.smul_mem_smul_finset Finset.smul_mem_smul_finset
#align finset.vadd_mem_vadd_finset Finset.vadd_mem_vadd_finset
@[to_additive]
theorem smul_finset_card_le : (a • s).card ≤ s.card :=
card_image_le
#align finset.smul_finset_card_le Finset.smul_finset_card_le
#align finset.vadd_finset_card_le Finset.vadd_finset_card_le
@[to_additive (attr := simp)]
theorem smul_finset_empty (a : α) : a • (∅ : Finset β) = ∅ :=
image_empty _
#align finset.smul_finset_empty Finset.smul_finset_empty
#align finset.vadd_finset_empty Finset.vadd_finset_empty
@[to_additive (attr := simp)]
theorem smul_finset_eq_empty : a • s = ∅ ↔ s = ∅ :=
image_eq_empty
#align finset.smul_finset_eq_empty Finset.smul_finset_eq_empty
#align finset.vadd_finset_eq_empty Finset.vadd_finset_eq_empty
@[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))]
theorem smul_finset_nonempty : (a • s).Nonempty ↔ s.Nonempty :=
image_nonempty
#align finset.smul_finset_nonempty Finset.smul_finset_nonempty
#align finset.vadd_finset_nonempty Finset.vadd_finset_nonempty
@[to_additive]
theorem Nonempty.smul_finset (hs : s.Nonempty) : (a • s).Nonempty :=
hs.image _
#align finset.nonempty.smul_finset Finset.Nonempty.smul_finset
#align finset.nonempty.vadd_finset Finset.Nonempty.vadd_finset
@[to_additive (attr := simp)]
theorem singleton_smul (a : α) : ({a} : Finset α) • t = a • t :=
image₂_singleton_left
#align finset.singleton_smul Finset.singleton_smul
#align finset.singleton_vadd Finset.singleton_vadd
@[to_additive (attr := mono)]
theorem smul_finset_subset_smul_finset : s ⊆ t → a • s ⊆ a • t :=
image_subset_image
#align finset.smul_finset_subset_smul_finset Finset.smul_finset_subset_smul_finset
#align finset.vadd_finset_subset_vadd_finset Finset.vadd_finset_subset_vadd_finset
@[to_additive (attr := simp)]
theorem smul_finset_singleton (b : β) : a • ({b} : Finset β) = {a • b} :=
image_singleton _ _
#align finset.smul_finset_singleton Finset.smul_finset_singleton
#align finset.vadd_finset_singleton Finset.vadd_finset_singleton
@[to_additive]
theorem smul_finset_union : a • (s₁ ∪ s₂) = a • s₁ ∪ a • s₂ :=
image_union _ _
#align finset.smul_finset_union Finset.smul_finset_union
#align finset.vadd_finset_union Finset.vadd_finset_union
@[to_additive]
theorem smul_finset_inter_subset : a • (s₁ ∩ s₂) ⊆ a • s₁ ∩ a • s₂ :=
image_inter_subset _ _ _
#align finset.smul_finset_inter_subset Finset.smul_finset_inter_subset
#align finset.vadd_finset_inter_subset Finset.vadd_finset_inter_subset
@[to_additive]
theorem smul_finset_subset_smul {s : Finset α} : a ∈ s → a • t ⊆ s • t :=
image_subset_image₂_right
#align finset.smul_finset_subset_smul Finset.smul_finset_subset_smul
#align finset.vadd_finset_subset_vadd Finset.vadd_finset_subset_vadd
@[to_additive (attr := simp)]
theorem biUnion_smul_finset (s : Finset α) (t : Finset β) : s.biUnion (· • t) = s • t :=
biUnion_image_left
#align finset.bUnion_smul_finset Finset.biUnion_smul_finset
#align finset.bUnion_vadd_finset Finset.biUnion_vadd_finset
end SMul
open Pointwise
section Instances
variable [DecidableEq γ]
@[to_additive]
instance smulCommClass_finset [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α β (Finset γ) :=
⟨fun _ _ => Commute.finset_image <| smul_comm _ _⟩
#align finset.smul_comm_class_finset Finset.smulCommClass_finset
#align finset.vadd_comm_class_finset Finset.vaddCommClass_finset
@[to_additive]
instance smulCommClass_finset' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α (Finset β) (Finset γ) :=
⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_comm]⟩
#align finset.smul_comm_class_finset' Finset.smulCommClass_finset'
#align finset.vadd_comm_class_finset' Finset.vaddCommClass_finset'
@[to_additive]
instance smulCommClass_finset'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Finset α) β (Finset γ) :=
haveI := SMulCommClass.symm α β γ
SMulCommClass.symm _ _ _
#align finset.smul_comm_class_finset'' Finset.smulCommClass_finset''
#align finset.vadd_comm_class_finset'' Finset.vaddCommClass_finset''
@[to_additive]
instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Finset α) (Finset β) (Finset γ) :=
⟨fun s t u => coe_injective <| by simp_rw [coe_smul, smul_comm]⟩
#align finset.smul_comm_class Finset.smulCommClass
#align finset.vadd_comm_class Finset.vaddCommClass
@[to_additive vaddAssocClass]
instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α β (Finset γ) :=
⟨fun a b s => by simp only [← image_smul, image_image, smul_assoc, Function.comp]⟩
#align finset.is_scalar_tower Finset.isScalarTower
#align finset.vadd_assoc_class Finset.vaddAssocClass
variable [DecidableEq β]
@[to_additive vaddAssocClass']
instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α (Finset β) (Finset γ) :=
⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_assoc]⟩
#align finset.is_scalar_tower' Finset.isScalarTower'
#align finset.vadd_assoc_class' Finset.vaddAssocClass'
@[to_additive vaddAssocClass'']
instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower (Finset α) (Finset β) (Finset γ) :=
⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_assoc]⟩
#align finset.is_scalar_tower'' Finset.isScalarTower''
#align finset.vadd_assoc_class'' Finset.vaddAssocClass''
@[to_additive]
instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] :
IsCentralScalar α (Finset β) :=
⟨fun a s => coe_injective <| by simp only [coe_smul_finset, coe_smul, op_smul_eq_smul]⟩
#align finset.is_central_scalar Finset.isCentralScalar
#align finset.is_central_vadd Finset.isCentralVAdd
/-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of
`Finset α` on `Finset β`. -/
@[to_additive
"An additive action of an additive monoid `α` on a type `β` gives an additive action
of `Finset α` on `Finset β`"]
protected def mulAction [DecidableEq α] [Monoid α] [MulAction α β] :
MulAction (Finset α) (Finset β) where
mul_smul _ _ _ := image₂_assoc mul_smul
one_smul s := image₂_singleton_left.trans <| by simp_rw [one_smul, image_id']
#align finset.mul_action Finset.mulAction
#align finset.add_action Finset.addAction
/-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Finset β`.
-/
@[to_additive
"An additive action of an additive monoid on a type `β` gives an additive action
on `Finset β`."]
protected def mulActionFinset [Monoid α] [MulAction α β] : MulAction α (Finset β) :=
coe_injective.mulAction _ coe_smul_finset
#align finset.mul_action_finset Finset.mulActionFinset
#align finset.add_action_finset Finset.addActionFinset
scoped[Pointwise]
attribute [instance]
Finset.mulActionFinset Finset.addActionFinset Finset.mulAction Finset.addAction
/-- If scalar multiplication by elements of `α` sends `(0 : β)` to zero,
then the same is true for `(0 : Finset β)`. -/
protected def smulZeroClassFinset [Zero β] [SMulZeroClass α β] :
SMulZeroClass α (Finset β) :=
coe_injective.smulZeroClass ⟨(↑), coe_zero⟩ coe_smul_finset
scoped[Pointwise] attribute [instance] Finset.smulZeroClassFinset
/-- If the scalar multiplication `(· • ·) : α → β → β` is distributive,
then so is `(· • ·) : α → Finset β → Finset β`. -/
protected def distribSMulFinset [AddZeroClass β] [DistribSMul α β] :
DistribSMul α (Finset β) :=
coe_injective.distribSMul coeAddMonoidHom coe_smul_finset
scoped[Pointwise] attribute [instance] Finset.distribSMulFinset
/-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive
multiplicative action on `Finset β`. -/
protected def distribMulActionFinset [Monoid α] [AddMonoid β] [DistribMulAction α β] :
DistribMulAction α (Finset β) :=
Function.Injective.distribMulAction coeAddMonoidHom coe_injective coe_smul_finset
#align finset.distrib_mul_action_finset Finset.distribMulActionFinset
/-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/
protected def mulDistribMulActionFinset [Monoid α] [Monoid β] [MulDistribMulAction α β] :
MulDistribMulAction α (Finset β) :=
Function.Injective.mulDistribMulAction coeMonoidHom coe_injective coe_smul_finset
#align finset.mul_distrib_mul_action_finset Finset.mulDistribMulActionFinset
scoped[Pointwise]
attribute [instance] Finset.distribMulActionFinset Finset.mulDistribMulActionFinset
instance [DecidableEq α] [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors (Finset α) :=
Function.Injective.noZeroDivisors (↑) coe_injective coe_zero coe_mul
instance noZeroSMulDivisors [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] :
NoZeroSMulDivisors (Finset α) (Finset β) where
eq_zero_or_eq_zero_of_smul_eq_zero {s t} := by
exact_mod_cast eq_zero_or_eq_zero_of_smul_eq_zero (c := s.toSet) (x := t.toSet)
instance noZeroSMulDivisors_finset [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] :
NoZeroSMulDivisors α (Finset β) :=
Function.Injective.noZeroSMulDivisors (↑) coe_injective coe_zero coe_smul_finset
#align finset.no_zero_smul_divisors_finset Finset.noZeroSMulDivisors_finset
end Instances
section SMul
variable [DecidableEq β] [DecidableEq γ] [SMul αᵐᵒᵖ β] [SMul β γ] [SMul α γ]
-- TODO: replace hypothesis and conclusion with a typeclass
@[to_additive]
theorem op_smul_finset_smul_eq_smul_smul_finset (a : α) (s : Finset β) (t : Finset γ)
(h : ∀ (a : α) (b : β) (c : γ), (op a • b) • c = b • a • c) : (op a • s) • t = s • a • t := by
ext
simp [mem_smul, mem_smul_finset, h]
#align finset.op_smul_finset_smul_eq_smul_smul_finset Finset.op_smul_finset_smul_eq_smul_smul_finset
#align finset.op_vadd_finset_vadd_eq_vadd_vadd_finset Finset.op_vadd_finset_vadd_eq_vadd_vadd_finset
end SMul
section Mul
variable [Mul α] [DecidableEq α] {s t u : Finset α} {a : α}
@[to_additive]
theorem op_smul_finset_subset_mul : a ∈ t → op a • s ⊆ s * t :=
image_subset_image₂_left
#align finset.op_smul_finset_subset_mul Finset.op_smul_finset_subset_mul
#align finset.op_vadd_finset_subset_add Finset.op_vadd_finset_subset_add
@[to_additive (attr := simp)]
theorem biUnion_op_smul_finset (s t : Finset α) : (t.biUnion fun a => op a • s) = s * t :=
biUnion_image_right
#align finset.bUnion_op_smul_finset Finset.biUnion_op_smul_finset
#align finset.bUnion_op_vadd_finset Finset.biUnion_op_vadd_finset
@[to_additive]
theorem mul_subset_iff_left : s * t ⊆ u ↔ ∀ a ∈ s, a • t ⊆ u :=
image₂_subset_iff_left
#align finset.mul_subset_iff_left Finset.mul_subset_iff_left
#align finset.add_subset_iff_left Finset.add_subset_iff_left
@[to_additive]
theorem mul_subset_iff_right : s * t ⊆ u ↔ ∀ b ∈ t, op b • s ⊆ u :=
image₂_subset_iff_right
#align finset.mul_subset_iff_right Finset.mul_subset_iff_right
#align finset.add_subset_iff_right Finset.add_subset_iff_right
end Mul
section Semigroup
variable [Semigroup α] [DecidableEq α]
@[to_additive]
theorem op_smul_finset_mul_eq_mul_smul_finset (a : α) (s : Finset α) (t : Finset α) :
op a • s * t = s * a • t :=
op_smul_finset_smul_eq_smul_smul_finset _ _ _ fun _ _ _ => mul_assoc _ _ _
#align finset.op_smul_finset_mul_eq_mul_smul_finset Finset.op_smul_finset_mul_eq_mul_smul_finset
#align finset.op_vadd_finset_add_eq_add_vadd_finset Finset.op_vadd_finset_add_eq_add_vadd_finset
end Semigroup
section IsLeftCancelMul
variable [Mul α] [IsLeftCancelMul α] [DecidableEq α] (s t : Finset α) (a : α)
@[to_additive]
theorem pairwiseDisjoint_smul_iff {s : Set α} {t : Finset α} :
s.PairwiseDisjoint (· • t) ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 := by
simp_rw [← pairwiseDisjoint_coe, coe_smul_finset, Set.pairwiseDisjoint_smul_iff]
#align finset.pairwise_disjoint_smul_iff Finset.pairwiseDisjoint_smul_iff
#align finset.pairwise_disjoint_vadd_iff Finset.pairwiseDisjoint_vadd_iff
@[to_additive (attr := simp)]
theorem card_singleton_mul : ({a} * t).card = t.card :=
card_image₂_singleton_left _ <| mul_right_injective _
#align finset.card_singleton_mul Finset.card_singleton_mul
#align finset.card_singleton_add Finset.card_singleton_add
@[to_additive]
theorem singleton_mul_inter : {a} * (s ∩ t) = {a} * s ∩ ({a} * t) :=
image₂_singleton_inter _ _ <| mul_right_injective _
#align finset.singleton_mul_inter Finset.singleton_mul_inter
#align finset.singleton_add_inter Finset.singleton_add_inter
@[to_additive]
theorem card_le_card_mul_left {s : Finset α} (hs : s.Nonempty) : t.card ≤ (s * t).card :=
card_le_card_image₂_left _ hs mul_right_injective
#align finset.card_le_card_mul_left Finset.card_le_card_mul_left
#align finset.card_le_card_add_left Finset.card_le_card_add_left
end IsLeftCancelMul
section
variable [Mul α] [IsRightCancelMul α] [DecidableEq α] (s t : Finset α) (a : α)
@[to_additive (attr := simp)]
theorem card_mul_singleton : (s * {a}).card = s.card :=
card_image₂_singleton_right _ <| mul_left_injective _
#align finset.card_mul_singleton Finset.card_mul_singleton
#align finset.card_add_singleton Finset.card_add_singleton
@[to_additive]
theorem inter_mul_singleton : s ∩ t * {a} = s * {a} ∩ (t * {a}) :=
image₂_inter_singleton _ _ <| mul_left_injective _
#align finset.inter_mul_singleton Finset.inter_mul_singleton
#align finset.inter_add_singleton Finset.inter_add_singleton
@[to_additive]
theorem card_le_card_mul_right {t : Finset α} (ht : t.Nonempty) : s.card ≤ (s * t).card :=
card_le_card_image₂_right _ ht mul_left_injective
#align finset.card_le_card_mul_right Finset.card_le_card_mul_right
#align finset.card_le_card_add_right Finset.card_le_card_add_right
end
section Group
variable [Group α] [DecidableEq α] {s t : Finset α}
@[to_additive] lemma card_le_card_div_left (hs : s.Nonempty) : t.card ≤ (s / t).card :=
card_le_card_image₂_left _ hs fun _ ↦ div_right_injective
@[to_additive] lemma card_le_card_div_right (ht : t.Nonempty) : s.card ≤ (s / t).card :=
card_le_card_image₂_right _ ht fun _ ↦ div_left_injective
end Group
open Pointwise
@[to_additive]
theorem image_smul_comm [DecidableEq β] [DecidableEq γ] [SMul α β] [SMul α γ] (f : β → γ) (a : α)
(s : Finset β) : (∀ b, f (a • b) = a • f b) → (a • s).image f = a • s.image f :=
image_comm
#align finset.image_smul_comm Finset.image_smul_comm
#align finset.image_vadd_comm Finset.image_vadd_comm
@[to_additive]
theorem image_smul_distrib [DecidableEq α] [DecidableEq β] [Monoid α] [Monoid β] [FunLike F α β]
[MonoidHomClass F α β] (f : F) (a : α) (s : Finset α) : (a • s).image f = f a • s.image f :=
image_comm <| map_mul _ _
#align finset.image_smul_distrib Finset.image_smul_distrib
#align finset.image_vadd_distrib Finset.image_vadd_distrib
section Group
variable [DecidableEq β] [Group α] [MulAction α β] {s t : Finset β} {a : α} {b : β}
@[to_additive (attr := simp)]
theorem smul_mem_smul_finset_iff (a : α) : a • b ∈ a • s ↔ b ∈ s :=
(MulAction.injective _).mem_finset_image
#align finset.smul_mem_smul_finset_iff Finset.smul_mem_smul_finset_iff
#align finset.vadd_mem_vadd_finset_iff Finset.vadd_mem_vadd_finset_iff
@[to_additive]
theorem inv_smul_mem_iff : a⁻¹ • b ∈ s ↔ b ∈ a • s := by
rw [← smul_mem_smul_finset_iff a, smul_inv_smul]
#align finset.inv_smul_mem_iff Finset.inv_smul_mem_iff
#align finset.neg_vadd_mem_iff Finset.neg_vadd_mem_iff
@[to_additive]
theorem mem_inv_smul_finset_iff : b ∈ a⁻¹ • s ↔ a • b ∈ s := by
rw [← smul_mem_smul_finset_iff a, smul_inv_smul]
#align finset.mem_inv_smul_finset_iff Finset.mem_inv_smul_finset_iff
#align finset.mem_neg_vadd_finset_iff Finset.mem_neg_vadd_finset_iff
@[to_additive (attr := simp)]
theorem smul_finset_subset_smul_finset_iff : a • s ⊆ a • t ↔ s ⊆ t :=
image_subset_image_iff <| MulAction.injective _
#align finset.smul_finset_subset_smul_finset_iff Finset.smul_finset_subset_smul_finset_iff
#align finset.vadd_finset_subset_vadd_finset_iff Finset.vadd_finset_subset_vadd_finset_iff
@[to_additive]
theorem smul_finset_subset_iff : a • s ⊆ t ↔ s ⊆ a⁻¹ • t := by
simp_rw [← coe_subset]
push_cast
exact Set.set_smul_subset_iff
#align finset.smul_finset_subset_iff Finset.smul_finset_subset_iff
#align finset.vadd_finset_subset_iff Finset.vadd_finset_subset_iff
@[to_additive]
theorem subset_smul_finset_iff : s ⊆ a • t ↔ a⁻¹ • s ⊆ t := by
simp_rw [← coe_subset]
push_cast
exact Set.subset_set_smul_iff
#align finset.subset_smul_finset_iff Finset.subset_smul_finset_iff
#align finset.subset_vadd_finset_iff Finset.subset_vadd_finset_iff
@[to_additive]
theorem smul_finset_inter : a • (s ∩ t) = a • s ∩ a • t :=
image_inter _ _ <| MulAction.injective a
#align finset.smul_finset_inter Finset.smul_finset_inter
#align finset.vadd_finset_inter Finset.vadd_finset_inter
@[to_additive]
theorem smul_finset_sdiff : a • (s \ t) = a • s \ a • t :=
image_sdiff _ _ <| MulAction.injective a
#align finset.smul_finset_sdiff Finset.smul_finset_sdiff
#align finset.vadd_finset_sdiff Finset.vadd_finset_sdiff
open scoped symmDiff in
@[to_additive]
theorem smul_finset_symmDiff : a • s ∆ t = (a • s) ∆ (a • t) :=
image_symmDiff _ _ <| MulAction.injective a
#align finset.smul_finset_symm_diff Finset.smul_finset_symmDiff
#align finset.vadd_finset_symm_diff Finset.vadd_finset_symmDiff
@[to_additive (attr := simp)]
theorem smul_finset_univ [Fintype β] : a • (univ : Finset β) = univ :=
image_univ_of_surjective <| MulAction.surjective a
#align finset.smul_finset_univ Finset.smul_finset_univ
#align finset.vadd_finset_univ Finset.vadd_finset_univ
@[to_additive (attr := simp)]
theorem smul_univ [Fintype β] {s : Finset α} (hs : s.Nonempty) : s • (univ : Finset β) = univ :=
coe_injective <| by
push_cast
exact Set.smul_univ hs
#align finset.smul_univ Finset.smul_univ
#align finset.vadd_univ Finset.vadd_univ
@[to_additive (attr := simp)]
theorem card_smul_finset (a : α) (s : Finset β) : (a • s).card = s.card :=
card_image_of_injective _ <| MulAction.injective _
#align finset.card_smul_finset Finset.card_smul_finset
#align finset.card_vadd_finset Finset.card_vadd_finset
/-- If the left cosets of `t` by elements of `s` are disjoint (but not necessarily distinct!), then
the size of `t` divides the size of `s • t`. -/
@[to_additive "If the left cosets of `t` by elements of `s` are disjoint (but not necessarily
distinct!), then the size of `t` divides the size of `s +ᵥ t`."]
theorem card_dvd_card_smul_right {s : Finset α} :
((· • t) '' (s : Set α)).PairwiseDisjoint id → t.card ∣ (s • t).card :=
card_dvd_card_image₂_right fun _ _ => MulAction.injective _
#align finset.card_dvd_card_smul_right Finset.card_dvd_card_smul_right
#align finset.card_dvd_card_vadd_right Finset.card_dvd_card_vadd_right
variable [DecidableEq α]
/-- If the right cosets of `s` by elements of `t` are disjoint (but not necessarily distinct!), then
the size of `s` divides the size of `s * t`. -/
@[to_additive "If the right cosets of `s` by elements of `t` are disjoint (but not necessarily
distinct!), then the size of `s` divides the size of `s + t`."]
theorem card_dvd_card_mul_left {s t : Finset α} :
((fun b => s.image fun a => a * b) '' (t : Set α)).PairwiseDisjoint id →
s.card ∣ (s * t).card :=
card_dvd_card_image₂_left fun _ _ => mul_left_injective _
#align finset.card_dvd_card_mul_left Finset.card_dvd_card_mul_left
#align finset.card_dvd_card_add_left Finset.card_dvd_card_add_left
/-- If the left cosets of `t` by elements of `s` are disjoint (but not necessarily distinct!), then
the size of `t` divides the size of `s * t`. -/
@[to_additive "If the left cosets of `t` by elements of `s` are disjoint (but not necessarily
distinct!), then the size of `t` divides the size of `s + t`."]
theorem card_dvd_card_mul_right {s t : Finset α} :
((· • t) '' (s : Set α)).PairwiseDisjoint id → t.card ∣ (s * t).card :=
card_dvd_card_image₂_right fun _ _ => mul_right_injective _
@[to_additive (attr := simp)]
lemma inv_smul_finset_distrib (a : α) (s : Finset α) : (a • s)⁻¹ = op a⁻¹ • s⁻¹ := by
ext; simp [← inv_smul_mem_iff]
@[to_additive (attr := simp)]
lemma inv_op_smul_finset_distrib (a : α) (s : Finset α) : (op a • s)⁻¹ = a⁻¹ • s⁻¹ := by
ext; simp [← inv_smul_mem_iff]
end Group
section SMulZeroClass
variable [Zero β] [SMulZeroClass α β] [DecidableEq β] {s : Finset α} {t : Finset β} {a : α}
| Mathlib/Data/Finset/Pointwise.lean | 2,213 | 2,213 | theorem smul_zero_subset (s : Finset α) : s • (0 : Finset β) ⊆ 0 := by | simp [subset_iff, mem_smul]
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.BoxIntegral.Partition.Additive
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
#align_import analysis.box_integral.partition.measure from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844"
/-!
# Box-additive functions defined by measures
In this file we prove a few simple facts about rectangular boxes, partitions, and measures:
- given a box `I : Box ι`, its coercion to `Set (ι → ℝ)` and `I.Icc` are measurable sets;
- if `μ` is a locally finite measure, then `(I : Set (ι → ℝ))` and `I.Icc` have finite measure;
- if `μ` is a locally finite measure, then `fun J ↦ (μ J).toReal` is a box additive function.
For the last statement, we both prove it as a proposition and define a bundled
`BoxIntegral.BoxAdditiveMap` function.
## Tags
rectangular box, measure
-/
open Set
noncomputable section
open scoped ENNReal Classical BoxIntegral
variable {ι : Type*}
namespace BoxIntegral
open MeasureTheory
namespace Box
variable (I : Box ι)
theorem measure_Icc_lt_top (μ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure μ] : μ (Box.Icc I) < ∞ :=
show μ (Icc I.lower I.upper) < ∞ from I.isCompact_Icc.measure_lt_top
#align box_integral.box.measure_Icc_lt_top BoxIntegral.Box.measure_Icc_lt_top
theorem measure_coe_lt_top (μ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure μ] : μ I < ∞ :=
(measure_mono <| coe_subset_Icc).trans_lt (I.measure_Icc_lt_top μ)
#align box_integral.box.measure_coe_lt_top BoxIntegral.Box.measure_coe_lt_top
section Countable
variable [Countable ι]
theorem measurableSet_coe : MeasurableSet (I : Set (ι → ℝ)) := by
rw [coe_eq_pi]
exact MeasurableSet.univ_pi fun i => measurableSet_Ioc
#align box_integral.box.measurable_set_coe BoxIntegral.Box.measurableSet_coe
theorem measurableSet_Icc : MeasurableSet (Box.Icc I) :=
_root_.measurableSet_Icc
#align box_integral.box.measurable_set_Icc BoxIntegral.Box.measurableSet_Icc
theorem measurableSet_Ioo : MeasurableSet (Box.Ioo I) :=
MeasurableSet.univ_pi fun _ => _root_.measurableSet_Ioo
#align box_integral.box.measurable_set_Ioo BoxIntegral.Box.measurableSet_Ioo
end Countable
variable [Fintype ι]
theorem coe_ae_eq_Icc : (I : Set (ι → ℝ)) =ᵐ[volume] Box.Icc I := by
rw [coe_eq_pi]
exact Measure.univ_pi_Ioc_ae_eq_Icc
#align box_integral.box.coe_ae_eq_Icc BoxIntegral.Box.coe_ae_eq_Icc
theorem Ioo_ae_eq_Icc : Box.Ioo I =ᵐ[volume] Box.Icc I :=
Measure.univ_pi_Ioo_ae_eq_Icc
#align box_integral.box.Ioo_ae_eq_Icc BoxIntegral.Box.Ioo_ae_eq_Icc
end Box
| Mathlib/Analysis/BoxIntegral/Partition/Measure.lean | 85 | 89 | theorem Prepartition.measure_iUnion_toReal [Finite ι] {I : Box ι} (π : Prepartition I)
(μ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure μ] :
(μ π.iUnion).toReal = ∑ J ∈ π.boxes, (μ J).toReal := by |
erw [← ENNReal.toReal_sum, π.iUnion_def, measure_biUnion_finset π.pairwiseDisjoint]
exacts [fun J _ => J.measurableSet_coe, fun J _ => (J.measure_coe_lt_top μ).ne]
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Data.Finset.Fold
import Mathlib.Data.Finset.Option
import Mathlib.Data.Finset.Pi
import Mathlib.Data.Finset.Prod
import Mathlib.Data.Multiset.Lattice
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Hom.Lattice
import Mathlib.Order.Nat
#align_import data.finset.lattice from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
/-!
# Lattice operations on finsets
-/
-- TODO:
-- assert_not_exists OrderedCommMonoid
assert_not_exists MonoidWithZero
open Function Multiset OrderDual
variable {F α β γ ι κ : Type*}
namespace Finset
/-! ### sup -/
section Sup
-- TODO: define with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]`
variable [SemilatticeSup α] [OrderBot α]
/-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/
def sup (s : Finset β) (f : β → α) : α :=
s.fold (· ⊔ ·) ⊥ f
#align finset.sup Finset.sup
variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α}
theorem sup_def : s.sup f = (s.1.map f).sup :=
rfl
#align finset.sup_def Finset.sup_def
@[simp]
theorem sup_empty : (∅ : Finset β).sup f = ⊥ :=
fold_empty
#align finset.sup_empty Finset.sup_empty
@[simp]
theorem sup_cons {b : β} (h : b ∉ s) : (cons b s h).sup f = f b ⊔ s.sup f :=
fold_cons h
#align finset.sup_cons Finset.sup_cons
@[simp]
theorem sup_insert [DecidableEq β] {b : β} : (insert b s : Finset β).sup f = f b ⊔ s.sup f :=
fold_insert_idem
#align finset.sup_insert Finset.sup_insert
@[simp]
theorem sup_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) :
(s.image f).sup g = s.sup (g ∘ f) :=
fold_image_idem
#align finset.sup_image Finset.sup_image
@[simp]
theorem sup_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).sup g = s.sup (g ∘ f) :=
fold_map
#align finset.sup_map Finset.sup_map
@[simp]
theorem sup_singleton {b : β} : ({b} : Finset β).sup f = f b :=
Multiset.sup_singleton
#align finset.sup_singleton Finset.sup_singleton
theorem sup_sup : s.sup (f ⊔ g) = s.sup f ⊔ s.sup g := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, sup_empty, sup_empty, bot_sup_eq]
| cons _ _ _ ih =>
rw [sup_cons, sup_cons, sup_cons, ih]
exact sup_sup_sup_comm _ _ _ _
#align finset.sup_sup Finset.sup_sup
theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
s₁.sup f = s₂.sup g := by
subst hs
exact Finset.fold_congr hfg
#align finset.sup_congr Finset.sup_congr
@[simp]
theorem _root_.map_finset_sup [SemilatticeSup β] [OrderBot β]
[FunLike F α β] [SupBotHomClass F α β]
(f : F) (s : Finset ι) (g : ι → α) : f (s.sup g) = s.sup (f ∘ g) :=
Finset.cons_induction_on s (map_bot f) fun i s _ h => by
rw [sup_cons, sup_cons, map_sup, h, Function.comp_apply]
#align map_finset_sup map_finset_sup
@[simp]
protected theorem sup_le_iff {a : α} : s.sup f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by
apply Iff.trans Multiset.sup_le
simp only [Multiset.mem_map, and_imp, exists_imp]
exact ⟨fun k b hb => k _ _ hb rfl, fun k a' b hb h => h ▸ k _ hb⟩
#align finset.sup_le_iff Finset.sup_le_iff
protected alias ⟨_, sup_le⟩ := Finset.sup_le_iff
#align finset.sup_le Finset.sup_le
theorem sup_const_le : (s.sup fun _ => a) ≤ a :=
Finset.sup_le fun _ _ => le_rfl
#align finset.sup_const_le Finset.sup_const_le
theorem le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f :=
Finset.sup_le_iff.1 le_rfl _ hb
#align finset.le_sup Finset.le_sup
theorem le_sup_of_le {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup f := h.trans <| le_sup hb
#align finset.le_sup_of_le Finset.le_sup_of_le
theorem sup_union [DecidableEq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f :=
eq_of_forall_ge_iff fun c => by simp [or_imp, forall_and]
#align finset.sup_union Finset.sup_union
@[simp]
theorem sup_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) :
(s.biUnion t).sup f = s.sup fun x => (t x).sup f :=
eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β]
#align finset.sup_bUnion Finset.sup_biUnion
theorem sup_const {s : Finset β} (h : s.Nonempty) (c : α) : (s.sup fun _ => c) = c :=
eq_of_forall_ge_iff (fun _ => Finset.sup_le_iff.trans h.forall_const)
#align finset.sup_const Finset.sup_const
@[simp]
theorem sup_bot (s : Finset β) : (s.sup fun _ => ⊥) = (⊥ : α) := by
obtain rfl | hs := s.eq_empty_or_nonempty
· exact sup_empty
· exact sup_const hs _
#align finset.sup_bot Finset.sup_bot
theorem sup_ite (p : β → Prop) [DecidablePred p] :
(s.sup fun i => ite (p i) (f i) (g i)) = (s.filter p).sup f ⊔ (s.filter fun i => ¬p i).sup g :=
fold_ite _
#align finset.sup_ite Finset.sup_ite
theorem sup_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.sup f ≤ s.sup g :=
Finset.sup_le fun b hb => le_trans (h b hb) (le_sup hb)
#align finset.sup_mono_fun Finset.sup_mono_fun
@[gcongr]
theorem sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f :=
Finset.sup_le (fun _ hb => le_sup (h hb))
#align finset.sup_mono Finset.sup_mono
protected theorem sup_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) :
(s.sup fun b => t.sup (f b)) = t.sup fun c => s.sup fun b => f b c :=
eq_of_forall_ge_iff fun a => by simpa using forall₂_swap
#align finset.sup_comm Finset.sup_comm
@[simp, nolint simpNF] -- Porting note: linter claims that LHS does not simplify
theorem sup_attach (s : Finset β) (f : β → α) : (s.attach.sup fun x => f x) = s.sup f :=
(s.attach.sup_map (Function.Embedding.subtype _) f).symm.trans <| congr_arg _ attach_map_val
#align finset.sup_attach Finset.sup_attach
/-- See also `Finset.product_biUnion`. -/
theorem sup_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = s.sup fun i => t.sup fun i' => f ⟨i, i'⟩ :=
eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ]
#align finset.sup_product_left Finset.sup_product_left
theorem sup_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = t.sup fun i' => s.sup fun i => f ⟨i, i'⟩ := by
rw [sup_product_left, Finset.sup_comm]
#align finset.sup_product_right Finset.sup_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] [OrderBot α] [OrderBot β]
{s : Finset ι} {t : Finset κ}
@[simp] lemma sup_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
sup (s ×ˢ t) (Prod.map f g) = (sup s f, sup t g) :=
eq_of_forall_ge_iff fun i ↦ by
obtain ⟨a, ha⟩ := hs
obtain ⟨b, hb⟩ := ht
simp only [Prod.map, Finset.sup_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def]
exact ⟨fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩, by aesop⟩
end Prod
@[simp]
| Mathlib/Data/Finset/Lattice.lean | 196 | 200 | theorem sup_erase_bot [DecidableEq α] (s : Finset α) : (s.erase ⊥).sup id = s.sup id := by |
refine (sup_mono (s.erase_subset _)).antisymm (Finset.sup_le_iff.2 fun a ha => ?_)
obtain rfl | ha' := eq_or_ne a ⊥
· exact bot_le
· exact le_sup (mem_erase.2 ⟨ha', ha⟩)
|
/-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Alex J. Best
-/
import Mathlib.Algebra.CharP.Quotient
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Data.Finsupp.Fintype
import Mathlib.Data.Int.AbsoluteValue
import Mathlib.Data.Int.Associated
import Mathlib.LinearAlgebra.FreeModule.Determinant
import Mathlib.LinearAlgebra.FreeModule.IdealQuotient
import Mathlib.RingTheory.DedekindDomain.PID
import Mathlib.RingTheory.Ideal.Basis
import Mathlib.RingTheory.LocalProperties
import Mathlib.RingTheory.Localization.NormTrace
#align_import ring_theory.ideal.norm from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Ideal norms
This file defines the absolute ideal norm `Ideal.absNorm (I : Ideal R) : ℕ` as the cardinality of
the quotient `R ⧸ I` (setting it to 0 if the cardinality is infinite),
and the relative ideal norm `Ideal.spanNorm R (I : Ideal S) : Ideal S` as the ideal spanned by
the norms of elements in `I`.
## Main definitions
* `Submodule.cardQuot (S : Submodule R M)`: the cardinality of the quotient `M ⧸ S`, in `ℕ`.
This maps `⊥` to `0` and `⊤` to `1`.
* `Ideal.absNorm (I : Ideal R)`: the absolute ideal norm, defined as
the cardinality of the quotient `R ⧸ I`, as a bundled monoid-with-zero homomorphism.
* `Ideal.spanNorm R (I : Ideal S)`: the ideal spanned by the norms of elements in `I`.
This is used to define `Ideal.relNorm`.
* `Ideal.relNorm R (I : Ideal S)`: the relative ideal norm as a bundled monoid-with-zero morphism,
defined as the ideal spanned by the norms of elements in `I`.
## Main results
* `map_mul Ideal.absNorm`: multiplicativity of the ideal norm is bundled in
the definition of `Ideal.absNorm`
* `Ideal.natAbs_det_basis_change`: the ideal norm is given by the determinant
of the basis change matrix
* `Ideal.absNorm_span_singleton`: the ideal norm of a principal ideal is the
norm of its generator
* `map_mul Ideal.relNorm`: multiplicativity of the relative ideal norm
-/
open scoped nonZeroDivisors
section abs_norm
namespace Submodule
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
section
/-- The cardinality of `(M ⧸ S)`, if `(M ⧸ S)` is finite, and `0` otherwise.
This is used to define the absolute ideal norm `Ideal.absNorm`.
-/
noncomputable def cardQuot (S : Submodule R M) : ℕ :=
AddSubgroup.index S.toAddSubgroup
#align submodule.card_quot Submodule.cardQuot
@[simp]
theorem cardQuot_apply (S : Submodule R M) [h : Fintype (M ⧸ S)] :
cardQuot S = Fintype.card (M ⧸ S) := by
-- Porting note: original proof was AddSubgroup.index_eq_card _
suffices Fintype (M ⧸ S.toAddSubgroup) by convert AddSubgroup.index_eq_card S.toAddSubgroup
convert h
#align submodule.card_quot_apply Submodule.cardQuot_apply
variable (R M)
@[simp]
theorem cardQuot_bot [Infinite M] : cardQuot (⊥ : Submodule R M) = 0 :=
AddSubgroup.index_bot.trans Nat.card_eq_zero_of_infinite
#align submodule.card_quot_bot Submodule.cardQuot_bot
-- @[simp] -- Porting note (#10618): simp can prove this
theorem cardQuot_top : cardQuot (⊤ : Submodule R M) = 1 :=
AddSubgroup.index_top
#align submodule.card_quot_top Submodule.cardQuot_top
variable {R M}
@[simp]
theorem cardQuot_eq_one_iff {P : Submodule R M} : cardQuot P = 1 ↔ P = ⊤ :=
AddSubgroup.index_eq_one.trans (by simp [SetLike.ext_iff])
#align submodule.card_quot_eq_one_iff Submodule.cardQuot_eq_one_iff
end
end Submodule
section RingOfIntegers
variable {S : Type*} [CommRing S] [IsDomain S]
open Submodule
/-- Multiplicity of the ideal norm, for coprime ideals.
This is essentially just a repackaging of the Chinese Remainder Theorem.
-/
theorem cardQuot_mul_of_coprime [Module.Free ℤ S] [Module.Finite ℤ S]
{I J : Ideal S} (coprime : IsCoprime I J) : cardQuot (I * J) = cardQuot I * cardQuot J := by
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty (Module.Free.ChooseBasisIndex ℤ S)
· haveI : Subsingleton S := Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective
nontriviality S
exfalso
exact not_nontrivial_iff_subsingleton.mpr ‹Subsingleton S› ‹Nontrivial S›
haveI : Infinite S := Infinite.of_surjective _ b.repr.toEquiv.surjective
by_cases hI : I = ⊥
· rw [hI, Submodule.bot_mul, cardQuot_bot, zero_mul]
by_cases hJ : J = ⊥
· rw [hJ, Submodule.mul_bot, cardQuot_bot, mul_zero]
have hIJ : I * J ≠ ⊥ := mt Ideal.mul_eq_bot.mp (not_or_of_not hI hJ)
letI := Classical.decEq (Module.Free.ChooseBasisIndex ℤ S)
letI := I.fintypeQuotientOfFreeOfNeBot hI
letI := J.fintypeQuotientOfFreeOfNeBot hJ
letI := (I * J).fintypeQuotientOfFreeOfNeBot hIJ
rw [cardQuot_apply, cardQuot_apply, cardQuot_apply,
Fintype.card_eq.mpr ⟨(Ideal.quotientMulEquivQuotientProd I J coprime).toEquiv⟩,
Fintype.card_prod]
#align card_quot_mul_of_coprime cardQuot_mul_of_coprime
/-- If the `d` from `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`,
then so are the `c`s, up to `P ^ (i + 1)`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.mul_add_mem_pow_succ_inj (P : Ideal S) {i : ℕ} (a d d' e e' : S) (a_mem : a ∈ P ^ i)
(e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1)) (h : d - d' ∈ P) :
a * d + e - (a * d' + e') ∈ P ^ (i + 1) := by
have : a * d - a * d' ∈ P ^ (i + 1) := by
simp only [← mul_sub]
exact Ideal.mul_mem_mul a_mem h
convert Ideal.add_mem _ this (Ideal.sub_mem _ e_mem e'_mem) using 1
ring
#align ideal.mul_add_mem_pow_succ_inj Ideal.mul_add_mem_pow_succ_inj
section PPrime
variable {P : Ideal S} [P_prime : P.IsPrime] (hP : P ≠ ⊥)
/-- If `a ∈ P^i \ P^(i+1)` and `c ∈ P^i`, then `a * d + e = c` for `e ∈ P^(i+1)`.
`Ideal.mul_add_mem_pow_succ_unique` shows the choice of `d` is unique, up to `P`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.exists_mul_add_mem_pow_succ [IsDedekindDomain S] {i : ℕ} (a c : S) (a_mem : a ∈ P ^ i)
(a_not_mem : a ∉ P ^ (i + 1)) (c_mem : c ∈ P ^ i) :
∃ d : S, ∃ e ∈ P ^ (i + 1), a * d + e = c := by
suffices eq_b : P ^ i = Ideal.span {a} ⊔ P ^ (i + 1) by
rw [eq_b] at c_mem
simp only [mul_comm a]
exact Ideal.mem_span_singleton_sup.mp c_mem
refine (Ideal.eq_prime_pow_of_succ_lt_of_le hP (lt_of_le_of_ne le_sup_right ?_)
(sup_le (Ideal.span_le.mpr (Set.singleton_subset_iff.mpr a_mem))
(Ideal.pow_succ_lt_pow hP i).le)).symm
contrapose! a_not_mem with this
rw [this]
exact mem_sup.mpr ⟨a, mem_span_singleton_self a, 0, by simp, by simp⟩
#align ideal.exists_mul_add_mem_pow_succ Ideal.exists_mul_add_mem_pow_succ
theorem Ideal.mem_prime_of_mul_mem_pow [IsDedekindDomain S] {P : Ideal S} [P_prime : P.IsPrime]
(hP : P ≠ ⊥) {i : ℕ} {a b : S} (a_not_mem : a ∉ P ^ (i + 1)) (ab_mem : a * b ∈ P ^ (i + 1)) :
b ∈ P := by
simp only [← Ideal.span_singleton_le_iff_mem, ← Ideal.dvd_iff_le, pow_succ, ←
Ideal.span_singleton_mul_span_singleton] at a_not_mem ab_mem ⊢
exact (prime_pow_succ_dvd_mul (Ideal.prime_of_isPrime hP P_prime) ab_mem).resolve_left a_not_mem
#align ideal.mem_prime_of_mul_mem_pow Ideal.mem_prime_of_mul_mem_pow
/-- The choice of `d` in `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.mul_add_mem_pow_succ_unique [IsDedekindDomain S] {i : ℕ} (a d d' e e' : S)
(a_not_mem : a ∉ P ^ (i + 1)) (e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1))
(h : a * d + e - (a * d' + e') ∈ P ^ (i + 1)) : d - d' ∈ P := by
have h' : a * (d - d') ∈ P ^ (i + 1) := by
convert Ideal.add_mem _ h (Ideal.sub_mem _ e'_mem e_mem) using 1
ring
exact Ideal.mem_prime_of_mul_mem_pow hP a_not_mem h'
#align ideal.mul_add_mem_pow_succ_unique Ideal.mul_add_mem_pow_succ_unique
/-- Multiplicity of the ideal norm, for powers of prime ideals. -/
theorem cardQuot_pow_of_prime [IsDedekindDomain S] [Module.Finite ℤ S] [Module.Free ℤ S] {i : ℕ} :
cardQuot (P ^ i) = cardQuot P ^ i := by
let _ := Module.Free.chooseBasis ℤ S
classical
induction' i with i ih
· simp
letI := Ideal.fintypeQuotientOfFreeOfNeBot (P ^ i.succ) (pow_ne_zero _ hP)
letI := Ideal.fintypeQuotientOfFreeOfNeBot (P ^ i) (pow_ne_zero _ hP)
letI := Ideal.fintypeQuotientOfFreeOfNeBot P hP
have : P ^ (i + 1) < P ^ i := Ideal.pow_succ_lt_pow hP i
suffices hquot : map (P ^ i.succ).mkQ (P ^ i) ≃ S ⧸ P by
rw [pow_succ' (cardQuot P), ← ih, cardQuot_apply (P ^ i.succ), ←
card_quotient_mul_card_quotient (P ^ i) (P ^ i.succ) this.le, cardQuot_apply (P ^ i),
cardQuot_apply P]
congr 1
rw [Fintype.card_eq]
exact ⟨hquot⟩
choose a a_mem a_not_mem using SetLike.exists_of_lt this
choose f g hg hf using fun c (hc : c ∈ P ^ i) =>
Ideal.exists_mul_add_mem_pow_succ hP a c a_mem a_not_mem hc
choose k hk_mem hk_eq using fun c' (hc' : c' ∈ map (mkQ (P ^ i.succ)) (P ^ i)) =>
Submodule.mem_map.mp hc'
refine Equiv.ofBijective (fun c' => Quotient.mk'' (f (k c' c'.prop) (hk_mem c' c'.prop))) ⟨?_, ?_⟩
· rintro ⟨c₁', hc₁'⟩ ⟨c₂', hc₂'⟩ h
rw [Subtype.mk_eq_mk, ← hk_eq _ hc₁', ← hk_eq _ hc₂', mkQ_apply, mkQ_apply,
Submodule.Quotient.eq, ← hf _ (hk_mem _ hc₁'), ← hf _ (hk_mem _ hc₂')]
refine Ideal.mul_add_mem_pow_succ_inj _ _ _ _ _ _ a_mem (hg _ _) (hg _ _) ?_
simpa only [Submodule.Quotient.mk''_eq_mk, Submodule.Quotient.mk''_eq_mk,
Submodule.Quotient.eq] using h
· intro d'
refine Quotient.inductionOn' d' fun d => ?_
have hd' := (mem_map (f := mkQ (P ^ i.succ))).mpr ⟨a * d, Ideal.mul_mem_right d _ a_mem, rfl⟩
refine ⟨⟨_, hd'⟩, ?_⟩
simp only [Submodule.Quotient.mk''_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.Quotient.eq,
Subtype.coe_mk]
refine
Ideal.mul_add_mem_pow_succ_unique hP a _ _ _ _ a_not_mem (hg _ (hk_mem _ hd')) (zero_mem _) ?_
rw [hf, add_zero]
exact (Submodule.Quotient.eq _).mp (hk_eq _ hd')
#align card_quot_pow_of_prime cardQuot_pow_of_prime
end PPrime
/-- Multiplicativity of the ideal norm in number rings. -/
theorem cardQuot_mul [IsDedekindDomain S] [Module.Free ℤ S] [Module.Finite ℤ S] (I J : Ideal S) :
cardQuot (I * J) = cardQuot I * cardQuot J := by
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty (Module.Free.ChooseBasisIndex ℤ S)
· haveI : Subsingleton S := Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective
nontriviality S
exfalso
exact not_nontrivial_iff_subsingleton.mpr ‹Subsingleton S› ‹Nontrivial S›
haveI : Infinite S := Infinite.of_surjective _ b.repr.toEquiv.surjective
exact UniqueFactorizationMonoid.multiplicative_of_coprime cardQuot I J (cardQuot_bot _ _)
(fun {I J} hI => by simp [Ideal.isUnit_iff.mp hI, Ideal.mul_top])
(fun {I} i hI =>
have : Ideal.IsPrime I := Ideal.isPrime_of_prime hI
cardQuot_pow_of_prime hI.ne_zero)
fun {I J} hIJ => cardQuot_mul_of_coprime <| Ideal.isCoprime_iff_sup_eq.mpr
(Ideal.isUnit_iff.mp
(hIJ (Ideal.dvd_iff_le.mpr le_sup_left) (Ideal.dvd_iff_le.mpr le_sup_right)))
#align card_quot_mul cardQuot_mul
/-- The absolute norm of the ideal `I : Ideal R` is the cardinality of the quotient `R ⧸ I`. -/
noncomputable def Ideal.absNorm [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S]
[Module.Finite ℤ S] : Ideal S →*₀ ℕ where
toFun := Submodule.cardQuot
map_mul' I J := by dsimp only; rw [cardQuot_mul]
map_one' := by dsimp only; rw [Ideal.one_eq_top, cardQuot_top]
map_zero' := by
have : Infinite S := Module.Free.infinite ℤ S
rw [Ideal.zero_eq_bot, cardQuot_bot]
#align ideal.abs_norm Ideal.absNorm
namespace Ideal
variable [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S] [Module.Finite ℤ S]
theorem absNorm_apply (I : Ideal S) : absNorm I = cardQuot I := rfl
#align ideal.abs_norm_apply Ideal.absNorm_apply
@[simp]
theorem absNorm_bot : absNorm (⊥ : Ideal S) = 0 := by rw [← Ideal.zero_eq_bot, _root_.map_zero]
#align ideal.abs_norm_bot Ideal.absNorm_bot
@[simp]
| Mathlib/RingTheory/Ideal/Norm.lean | 273 | 273 | theorem absNorm_top : absNorm (⊤ : Ideal S) = 1 := by | rw [← Ideal.one_eq_top, _root_.map_one]
|
/-
Copyright (c) 2021 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Star.Subalgebra
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.Tactic.NoncommRing
#align_import algebra.algebra.spectrum from "leanprover-community/mathlib"@"58a272265b5e05f258161260dd2c5d247213cbd3"
/-!
# Spectrum of an element in an algebra
This file develops the basic theory of the spectrum of an element of an algebra.
This theory will serve as the foundation for spectral theory in Banach algebras.
## Main definitions
* `resolventSet a : Set R`: the resolvent set of an element `a : A` where
`A` is an `R`-algebra.
* `spectrum a : Set R`: the spectrum of an element `a : A` where
`A` is an `R`-algebra.
* `resolvent : R → A`: the resolvent function is `fun r ↦ Ring.inverse (↑ₐr - a)`, and hence
when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - a)`.
## Main statements
* `spectrum.unit_smul_eq_smul` and `spectrum.smul_eq_smul`: units in the scalar ring commute
(multiplication) with the spectrum, and over a field even `0` commutes with the spectrum.
* `spectrum.left_add_coset_eq`: elements of the scalar ring commute (addition) with the spectrum.
* `spectrum.unit_mem_mul_iff_mem_swap_mul` and `spectrum.preimage_units_mul_eq_swap_mul`: the
units (of `R`) in `σ (a*b)` coincide with those in `σ (b*a)`.
* `spectrum.scalar_eq`: in a nontrivial algebra over a field, the spectrum of a scalar is
a singleton.
## Notations
* `σ a` : `spectrum R a` of `a : A`
-/
open Set
open scoped Pointwise
universe u v
section Defs
variable (R : Type u) {A : Type v}
variable [CommSemiring R] [Ring A] [Algebra R A]
local notation "↑ₐ" => algebraMap R A
-- definition and basic properties
/-- Given a commutative ring `R` and an `R`-algebra `A`, the *resolvent set* of `a : A`
is the `Set R` consisting of those `r : R` for which `r•1 - a` is a unit of the
algebra `A`. -/
def resolventSet (a : A) : Set R :=
{r : R | IsUnit (↑ₐ r - a)}
#align resolvent_set resolventSet
/-- Given a commutative ring `R` and an `R`-algebra `A`, the *spectrum* of `a : A`
is the `Set R` consisting of those `r : R` for which `r•1 - a` is not a unit of the
algebra `A`.
The spectrum is simply the complement of the resolvent set. -/
def spectrum (a : A) : Set R :=
(resolventSet R a)ᶜ
#align spectrum spectrum
variable {R}
/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is
a map `R → A` which sends `r : R` to `(algebraMap R A r - a)⁻¹` when
`r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/
noncomputable def resolvent (a : A) (r : R) : A :=
Ring.inverse (↑ₐ r - a)
#align resolvent resolvent
/-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/
@[simps]
noncomputable def IsUnit.subInvSMul {r : Rˣ} {s : R} {a : A} (h : IsUnit <| r • ↑ₐ s - a) : Aˣ where
val := ↑ₐ s - r⁻¹ • a
inv := r • ↑h.unit⁻¹
val_inv := by rw [mul_smul_comm, ← smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_val_inv]
inv_val := by rw [smul_mul_assoc, ← mul_smul_comm, smul_sub, smul_inv_smul, h.val_inv_mul]
#align is_unit.sub_inv_smul IsUnit.subInvSMul
#align is_unit.coe_sub_inv_smul IsUnit.val_subInvSMul
#align is_unit.coe_inv_sub_inv_smul IsUnit.val_inv_subInvSMul
end Defs
namespace spectrum
section ScalarSemiring
variable {R : Type u} {A : Type v}
variable [CommSemiring R] [Ring A] [Algebra R A]
local notation "σ" => spectrum R
local notation "↑ₐ" => algebraMap R A
theorem mem_iff {r : R} {a : A} : r ∈ σ a ↔ ¬IsUnit (↑ₐ r - a) :=
Iff.rfl
#align spectrum.mem_iff spectrum.mem_iff
theorem not_mem_iff {r : R} {a : A} : r ∉ σ a ↔ IsUnit (↑ₐ r - a) := by
apply not_iff_not.mp
simp [Set.not_not_mem, mem_iff]
#align spectrum.not_mem_iff spectrum.not_mem_iff
variable (R)
theorem zero_mem_iff {a : A} : (0 : R) ∈ σ a ↔ ¬IsUnit a := by
rw [mem_iff, map_zero, zero_sub, IsUnit.neg_iff]
#align spectrum.zero_mem_iff spectrum.zero_mem_iff
alias ⟨not_isUnit_of_zero_mem, zero_mem⟩ := spectrum.zero_mem_iff
theorem zero_not_mem_iff {a : A} : (0 : R) ∉ σ a ↔ IsUnit a := by
rw [zero_mem_iff, Classical.not_not]
#align spectrum.zero_not_mem_iff spectrum.zero_not_mem_iff
alias ⟨isUnit_of_zero_not_mem, zero_not_mem⟩ := spectrum.zero_not_mem_iff
lemma subset_singleton_zero_compl {a : A} (ha : IsUnit a) : spectrum R a ⊆ {0}ᶜ :=
Set.subset_compl_singleton_iff.mpr <| spectrum.zero_not_mem R ha
variable {R}
theorem mem_resolventSet_of_left_right_inverse {r : R} {a b c : A} (h₁ : (↑ₐ r - a) * b = 1)
(h₂ : c * (↑ₐ r - a) = 1) : r ∈ resolventSet R a :=
Units.isUnit ⟨↑ₐ r - a, b, h₁, by rwa [← left_inv_eq_right_inv h₂ h₁]⟩
#align spectrum.mem_resolvent_set_of_left_right_inverse spectrum.mem_resolventSet_of_left_right_inverse
theorem mem_resolventSet_iff {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (↑ₐ r - a) :=
Iff.rfl
#align spectrum.mem_resolvent_set_iff spectrum.mem_resolventSet_iff
@[simp]
theorem algebraMap_mem_iff (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S]
[Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} {r : R} :
algebraMap R S r ∈ spectrum S a ↔ r ∈ spectrum R a := by
simp only [spectrum.mem_iff, Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul]
protected alias ⟨of_algebraMap_mem, algebraMap_mem⟩ := spectrum.algebraMap_mem_iff
@[simp]
theorem preimage_algebraMap (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S]
[Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} :
algebraMap R S ⁻¹' spectrum S a = spectrum R a :=
Set.ext fun _ => spectrum.algebraMap_mem_iff _
@[simp]
theorem resolventSet_of_subsingleton [Subsingleton A] (a : A) : resolventSet R a = Set.univ := by
simp_rw [resolventSet, Subsingleton.elim (algebraMap R A _ - a) 1, isUnit_one, Set.setOf_true]
#align spectrum.resolvent_set_of_subsingleton spectrum.resolventSet_of_subsingleton
@[simp]
| Mathlib/Algebra/Algebra/Spectrum.lean | 162 | 163 | theorem of_subsingleton [Subsingleton A] (a : A) : spectrum R a = ∅ := by |
rw [spectrum, resolventSet_of_subsingleton, Set.compl_univ]
|
/-
Copyright (c) 2022 Wrenna Robson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wrenna Robson
-/
import Mathlib.Topology.MetricSpace.Basic
#align_import topology.metric_space.infsep from "leanprover-community/mathlib"@"5316314b553dcf8c6716541851517c1a9715e22b"
/-!
# Infimum separation
This file defines the extended infimum separation of a set. This is approximately dual to the
diameter of a set, but where the extended diameter of a set is the supremum of the extended distance
between elements of the set, the extended infimum separation is the infimum of the (extended)
distance between *distinct* elements in the set.
We also define the infimum separation as the cast of the extended infimum separation to the reals.
This is the infimum of the distance between distinct elements of the set when in a pseudometric
space.
All lemmas and definitions are in the `Set` namespace to give access to dot notation.
## Main definitions
* `Set.einfsep`: Extended infimum separation of a set.
* `Set.infsep`: Infimum separation of a set (when in a pseudometric space).
!-/
variable {α β : Type*}
namespace Set
section Einfsep
open ENNReal
open Function
/-- The "extended infimum separation" of a set with an edist function. -/
noncomputable def einfsep [EDist α] (s : Set α) : ℝ≥0∞ :=
⨅ (x ∈ s) (y ∈ s) (_ : x ≠ y), edist x y
#align set.einfsep Set.einfsep
section EDist
variable [EDist α] {x y : α} {s t : Set α}
theorem le_einfsep_iff {d} :
d ≤ s.einfsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y := by
simp_rw [einfsep, le_iInf_iff]
#align set.le_einfsep_iff Set.le_einfsep_iff
theorem einfsep_zero : s.einfsep = 0 ↔ ∀ C > 0, ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < C := by
simp_rw [einfsep, ← _root_.bot_eq_zero, iInf_eq_bot, iInf_lt_iff, exists_prop]
#align set.einfsep_zero Set.einfsep_zero
theorem einfsep_pos : 0 < s.einfsep ↔ ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by
rw [pos_iff_ne_zero, Ne, einfsep_zero]
simp only [not_forall, not_exists, not_lt, exists_prop, not_and]
#align set.einfsep_pos Set.einfsep_pos
theorem einfsep_top :
s.einfsep = ∞ ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → edist x y = ∞ := by
simp_rw [einfsep, iInf_eq_top]
#align set.einfsep_top Set.einfsep_top
theorem einfsep_lt_top :
s.einfsep < ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < ∞ := by
simp_rw [einfsep, iInf_lt_iff, exists_prop]
#align set.einfsep_lt_top Set.einfsep_lt_top
theorem einfsep_ne_top :
s.einfsep ≠ ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y ≠ ∞ := by
simp_rw [← lt_top_iff_ne_top, einfsep_lt_top]
#align set.einfsep_ne_top Set.einfsep_ne_top
theorem einfsep_lt_iff {d} :
s.einfsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < d := by
simp_rw [einfsep, iInf_lt_iff, exists_prop]
#align set.einfsep_lt_iff Set.einfsep_lt_iff
theorem nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.Nontrivial := by
rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩
exact ⟨_, hx, _, hy, hxy⟩
#align set.nontrivial_of_einfsep_lt_top Set.nontrivial_of_einfsep_lt_top
theorem nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.Nontrivial :=
nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs)
#align set.nontrivial_of_einfsep_ne_top Set.nontrivial_of_einfsep_ne_top
theorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = ∞ := by
rw [einfsep_top]
exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim
#align set.subsingleton.einfsep Set.Subsingleton.einfsep
theorem le_einfsep_image_iff {d} {f : β → α} {s : Set β} : d ≤ einfsep (f '' s)
↔ ∀ x ∈ s, ∀ y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) := by
simp_rw [le_einfsep_iff, forall_mem_image]
#align set.le_einfsep_image_iff Set.le_einfsep_image_iff
theorem le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hd : d ≤ s.einfsep) : d ≤ edist x y :=
le_einfsep_iff.1 hd x hx y hy hxy
#align set.le_edist_of_le_einfsep Set.le_edist_of_le_einfsep
theorem einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) :
s.einfsep ≤ edist x y :=
le_edist_of_le_einfsep hx hy hxy le_rfl
#align set.einfsep_le_edist_of_mem Set.einfsep_le_edist_of_mem
theorem einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hxy' : edist x y ≤ d) : s.einfsep ≤ d :=
le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy'
#align set.einfsep_le_of_mem_of_edist_le Set.einfsep_le_of_mem_of_edist_le
theorem le_einfsep {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y) : d ≤ s.einfsep :=
le_einfsep_iff.2 h
#align set.le_einfsep Set.le_einfsep
@[simp]
theorem einfsep_empty : (∅ : Set α).einfsep = ∞ :=
subsingleton_empty.einfsep
#align set.einfsep_empty Set.einfsep_empty
@[simp]
theorem einfsep_singleton : ({x} : Set α).einfsep = ∞ :=
subsingleton_singleton.einfsep
#align set.einfsep_singleton Set.einfsep_singleton
theorem einfsep_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) :
(⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o <;> simp
#align set.einfsep_Union_mem_option Set.einfsep_iUnion_mem_option
theorem einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep :=
le_einfsep fun _x hx _y hy => einfsep_le_edist_of_mem (hst hx) (hst hy)
#align set.einfsep_anti Set.einfsep_anti
theorem einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (_ : x ≠ y), edist x y := by
simp_rw [le_iInf_iff]
exact fun _ hy hxy => einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy
#align set.einfsep_insert_le Set.einfsep_insert_le
theorem le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : Set α).einfsep := by
simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff]
rintro a (rfl | rfl) b (rfl | rfl) hab <;> (try simp only [le_refl, true_or, or_true]) <;>
contradiction
#align set.le_einfsep_pair Set.le_einfsep_pair
theorem einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist x y :=
einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy
#align set.einfsep_pair_le_left Set.einfsep_pair_le_left
| Mathlib/Topology/MetricSpace/Infsep.lean | 155 | 156 | theorem einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist y x := by |
rw [pair_comm]; exact einfsep_pair_le_left hxy.symm
|
/-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.RingTheory.DedekindDomain.Ideal
#align_import number_theory.ramification_inertia from "leanprover-community/mathlib"@"039a089d2a4b93c761b234f3e5f5aeb752bac60f"
/-!
# Ramification index and inertia degree
Given `P : Ideal S` lying over `p : Ideal R` for the ring extension `f : R →+* S`
(assuming `P` and `p` are prime or maximal where needed),
the **ramification index** `Ideal.ramificationIdx f p P` is the multiplicity of `P` in `map f p`,
and the **inertia degree** `Ideal.inertiaDeg f p P` is the degree of the field extension
`(S / P) : (R / p)`.
## Main results
The main theorem `Ideal.sum_ramification_inertia` states that for all coprime `P` lying over `p`,
`Σ P, ramification_idx f p P * inertia_deg f p P` equals the degree of the field extension
`Frac(S) : Frac(R)`.
## Implementation notes
Often the above theory is set up in the case where:
* `R` is the ring of integers of a number field `K`,
* `L` is a finite separable extension of `K`,
* `S` is the integral closure of `R` in `L`,
* `p` and `P` are maximal ideals,
* `P` is an ideal lying over `p`
We will try to relax the above hypotheses as much as possible.
## Notation
In this file, `e` stands for the ramification index and `f` for the inertia degree of `P` over `p`,
leaving `p` and `P` implicit.
-/
namespace Ideal
universe u v
variable {R : Type u} [CommRing R]
variable {S : Type v} [CommRing S] (f : R →+* S)
variable (p : Ideal R) (P : Ideal S)
open FiniteDimensional
open UniqueFactorizationMonoid
section DecEq
open scoped Classical
/-- The ramification index of `P` over `p` is the largest exponent `n` such that
`p` is contained in `P^n`.
In particular, if `p` is not contained in `P^n`, then the ramification index is 0.
If there is no largest such `n` (e.g. because `p = ⊥`), then `ramificationIdx` is
defined to be 0.
-/
noncomputable def ramificationIdx : ℕ := sSup {n | map f p ≤ P ^ n}
#align ideal.ramification_idx Ideal.ramificationIdx
variable {f p P}
theorem ramificationIdx_eq_find (h : ∃ n, ∀ k, map f p ≤ P ^ k → k ≤ n) :
ramificationIdx f p P = Nat.find h :=
Nat.sSup_def h
#align ideal.ramification_idx_eq_find Ideal.ramificationIdx_eq_find
theorem ramificationIdx_eq_zero (h : ∀ n : ℕ, ∃ k, map f p ≤ P ^ k ∧ n < k) :
ramificationIdx f p P = 0 :=
dif_neg (by push_neg; exact h)
#align ideal.ramification_idx_eq_zero Ideal.ramificationIdx_eq_zero
theorem ramificationIdx_spec {n : ℕ} (hle : map f p ≤ P ^ n) (hgt : ¬map f p ≤ P ^ (n + 1)) :
ramificationIdx f p P = n := by
let Q : ℕ → Prop := fun m => ∀ k : ℕ, map f p ≤ P ^ k → k ≤ m
have : Q n := by
intro k hk
refine le_of_not_lt fun hnk => ?_
exact hgt (hk.trans (Ideal.pow_le_pow_right hnk))
rw [ramificationIdx_eq_find ⟨n, this⟩]
refine le_antisymm (Nat.find_min' _ this) (le_of_not_gt fun h : Nat.find _ < n => ?_)
obtain this' := Nat.find_spec ⟨n, this⟩
exact h.not_le (this' _ hle)
#align ideal.ramification_idx_spec Ideal.ramificationIdx_spec
theorem ramificationIdx_lt {n : ℕ} (hgt : ¬map f p ≤ P ^ n) : ramificationIdx f p P < n := by
cases' n with n n
· simp at hgt
· rw [Nat.lt_succ_iff]
have : ∀ k, map f p ≤ P ^ k → k ≤ n := by
refine fun k hk => le_of_not_lt fun hnk => ?_
exact hgt (hk.trans (Ideal.pow_le_pow_right hnk))
rw [ramificationIdx_eq_find ⟨n, this⟩]
exact Nat.find_min' ⟨n, this⟩ this
#align ideal.ramification_idx_lt Ideal.ramificationIdx_lt
@[simp]
theorem ramificationIdx_bot : ramificationIdx f ⊥ P = 0 :=
dif_neg <| not_exists.mpr fun n hn => n.lt_succ_self.not_le (hn _ (by simp))
#align ideal.ramification_idx_bot Ideal.ramificationIdx_bot
@[simp]
theorem ramificationIdx_of_not_le (h : ¬map f p ≤ P) : ramificationIdx f p P = 0 :=
ramificationIdx_spec (by simp) (by simpa using h)
#align ideal.ramification_idx_of_not_le Ideal.ramificationIdx_of_not_le
theorem ramificationIdx_ne_zero {e : ℕ} (he : e ≠ 0) (hle : map f p ≤ P ^ e)
(hnle : ¬map f p ≤ P ^ (e + 1)) : ramificationIdx f p P ≠ 0 := by
rwa [ramificationIdx_spec hle hnle]
#align ideal.ramification_idx_ne_zero Ideal.ramificationIdx_ne_zero
theorem le_pow_of_le_ramificationIdx {n : ℕ} (hn : n ≤ ramificationIdx f p P) :
map f p ≤ P ^ n := by
contrapose! hn
exact ramificationIdx_lt hn
#align ideal.le_pow_of_le_ramification_idx Ideal.le_pow_of_le_ramificationIdx
theorem le_pow_ramificationIdx : map f p ≤ P ^ ramificationIdx f p P :=
le_pow_of_le_ramificationIdx (le_refl _)
#align ideal.le_pow_ramification_idx Ideal.le_pow_ramificationIdx
theorem le_comap_pow_ramificationIdx : p ≤ comap f (P ^ ramificationIdx f p P) :=
map_le_iff_le_comap.mp le_pow_ramificationIdx
#align ideal.le_comap_pow_ramification_idx Ideal.le_comap_pow_ramificationIdx
theorem le_comap_of_ramificationIdx_ne_zero (h : ramificationIdx f p P ≠ 0) : p ≤ comap f P :=
Ideal.map_le_iff_le_comap.mp <| le_pow_ramificationIdx.trans <| Ideal.pow_le_self <| h
#align ideal.le_comap_of_ramification_idx_ne_zero Ideal.le_comap_of_ramificationIdx_ne_zero
namespace IsDedekindDomain
variable [IsDedekindDomain S]
theorem ramificationIdx_eq_normalizedFactors_count (hp0 : map f p ≠ ⊥) (hP : P.IsPrime)
(hP0 : P ≠ ⊥) : ramificationIdx f p P = (normalizedFactors (map f p)).count P := by
have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible
refine ramificationIdx_spec (Ideal.le_of_dvd ?_) (mt Ideal.dvd_iff_le.mpr ?_) <;>
rw [dvd_iff_normalizedFactors_le_normalizedFactors (pow_ne_zero _ hP0) hp0,
normalizedFactors_pow, normalizedFactors_irreducible hPirr, normalize_eq,
Multiset.nsmul_singleton, ← Multiset.le_count_iff_replicate_le]
exact (Nat.lt_succ_self _).not_le
#align ideal.is_dedekind_domain.ramification_idx_eq_normalized_factors_count Ideal.IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count
theorem ramificationIdx_eq_factors_count (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (hP0 : P ≠ ⊥) :
ramificationIdx f p P = (factors (map f p)).count P := by
rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0,
factors_eq_normalizedFactors]
#align ideal.is_dedekind_domain.ramification_idx_eq_factors_count Ideal.IsDedekindDomain.ramificationIdx_eq_factors_count
theorem ramificationIdx_ne_zero (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (le : map f p ≤ P) :
ramificationIdx f p P ≠ 0 := by
have hP0 : P ≠ ⊥ := by
rintro rfl
have := le_bot_iff.mp le
contradiction
have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible
rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0]
obtain ⟨P', hP', P'_eq⟩ :=
exists_mem_normalizedFactors_of_dvd hp0 hPirr (Ideal.dvd_iff_le.mpr le)
rwa [Multiset.count_ne_zero, associated_iff_eq.mp P'_eq]
#align ideal.is_dedekind_domain.ramification_idx_ne_zero Ideal.IsDedekindDomain.ramificationIdx_ne_zero
end IsDedekindDomain
variable (f p P)
attribute [local instance] Ideal.Quotient.field
/-- The inertia degree of `P : Ideal S` lying over `p : Ideal R` is the degree of the
extension `(S / P) : (R / p)`.
We do not assume `P` lies over `p` in the definition; we return `0` instead.
See `inertiaDeg_algebraMap` for the common case where `f = algebraMap R S`
and there is an algebra structure `R / p → S / P`.
-/
noncomputable def inertiaDeg [p.IsMaximal] : ℕ :=
if hPp : comap f P = p then
@finrank (R ⧸ p) (S ⧸ P) _ _ <|
@Algebra.toModule _ _ _ _ <|
RingHom.toAlgebra <|
Ideal.Quotient.lift p ((Ideal.Quotient.mk P).comp f) fun _ ha =>
Quotient.eq_zero_iff_mem.mpr <| mem_comap.mp <| hPp.symm ▸ ha
else 0
#align ideal.inertia_deg Ideal.inertiaDeg
-- Useful for the `nontriviality` tactic using `comap_eq_of_scalar_tower_quotient`.
@[simp]
theorem inertiaDeg_of_subsingleton [hp : p.IsMaximal] [hQ : Subsingleton (S ⧸ P)] :
inertiaDeg f p P = 0 := by
have := Ideal.Quotient.subsingleton_iff.mp hQ
subst this
exact dif_neg fun h => hp.ne_top <| h.symm.trans comap_top
#align ideal.inertia_deg_of_subsingleton Ideal.inertiaDeg_of_subsingleton
@[simp]
theorem inertiaDeg_algebraMap [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)]
[IsScalarTower R (R ⧸ p) (S ⧸ P)] [hp : p.IsMaximal] :
inertiaDeg (algebraMap R S) p P = finrank (R ⧸ p) (S ⧸ P) := by
nontriviality S ⧸ P using inertiaDeg_of_subsingleton, finrank_zero_of_subsingleton
have := comap_eq_of_scalar_tower_quotient (algebraMap (R ⧸ p) (S ⧸ P)).injective
rw [inertiaDeg, dif_pos this]
congr
refine Algebra.algebra_ext _ _ fun x' => Quotient.inductionOn' x' fun x => ?_
change Ideal.Quotient.lift p _ _ (Ideal.Quotient.mk p x) = algebraMap _ _ (Ideal.Quotient.mk p x)
rw [Ideal.Quotient.lift_mk, ← Ideal.Quotient.algebraMap_eq P, ← IsScalarTower.algebraMap_eq,
← Ideal.Quotient.algebraMap_eq, ← IsScalarTower.algebraMap_apply]
#align ideal.inertia_deg_algebra_map Ideal.inertiaDeg_algebraMap
end DecEq
section FinrankQuotientMap
open scoped nonZeroDivisors
variable [Algebra R S]
variable {K : Type*} [Field K] [Algebra R K] [hRK : IsFractionRing R K]
variable {L : Type*} [Field L] [Algebra S L] [IsFractionRing S L]
variable {V V' V'' : Type*}
variable [AddCommGroup V] [Module R V] [Module K V] [IsScalarTower R K V]
variable [AddCommGroup V'] [Module R V'] [Module S V'] [IsScalarTower R S V']
variable [AddCommGroup V''] [Module R V'']
variable (K)
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.
The statement we prove is actually slightly more general:
* it suffices that the inclusion `algebraMap R S : R → S` is nontrivial
* the function `f' : V'' → V'` doesn't need to be injective
-/
theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDedekindDomain R]
(hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f)
(f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) :
LinearIndependent K (f ∘ b) := by
contrapose! hb' with hb
-- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
-- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`,
-- where `I = ker (algebraMap R S)`.
-- We make use of the same principle but stay in `R` everywhere.
simp only [linearIndependent_iff', not_forall] at hb ⊢
obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb
use s
obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g
choose g'' hg'' using hag
letI := Classical.propDecidable
let g' i := if h : i ∈ s then g'' i h else 0
have hg' : ∀ i ∈ s, algebraMap _ _ (g' i) = a * g i := by
intro i hi; exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi)
-- Because `R/I` is nontrivial, we can lift `g` to a nontrivial linear dependence in `S`.
have hgI : algebraMap R S (g' j) ≠ 0 := by
simp only [FractionalIdeal.mem_coeIdeal, not_exists, not_and'] at hgI
exact hgI _ (hg' j hjs)
refine ⟨fun i => algebraMap R S (g' i), ?_, j, hjs, hgI⟩
have eq : f (∑ i ∈ s, g' i • b i) = 0 := by
rw [map_sum, ← smul_zero a, ← eq, Finset.smul_sum]
refine Finset.sum_congr rfl ?_
intro i hi
rw [LinearMap.map_smul, ← IsScalarTower.algebraMap_smul K, hg' i hi, ← smul_assoc,
smul_eq_mul, Function.comp_apply]
simp only [IsScalarTower.algebraMap_smul, ← map_smul, ← map_sum,
(f.map_eq_zero_iff hf).mp eq, LinearMap.map_zero, (· ∘ ·)]
#align ideal.finrank_quotient_map.linear_independent_of_nontrivial Ideal.FinrankQuotientMap.linearIndependent_of_nontrivial
open scoped Matrix
variable {K}
/-- If `b` mod `p` spans `S/p` as `R/p`-space, then `b` itself spans `Frac(S)` as `K`-space.
Here,
* `p` is an ideal of `R` such that `R / p` is nontrivial
* `K` is a field that has an embedding of `R` (in particular we can take `K = Frac(R)`)
* `L` is a field extension of `K`
* `S` is the integral closure of `R` in `L`
More precisely, we avoid quotients in this statement and instead require that `b ∪ pS` spans `S`.
-/
theorem FinrankQuotientMap.span_eq_top [IsDomain R] [IsDomain S] [Algebra K L] [IsNoetherian R S]
[Algebra R L] [IsScalarTower R S L] [IsScalarTower R K L] [IsIntegralClosure S R L]
[NoZeroSMulDivisors R K] (hp : p ≠ ⊤) (b : Set S)
(hb' : Submodule.span R b ⊔ (p.map (algebraMap R S)).restrictScalars R = ⊤) :
Submodule.span K (algebraMap S L '' b) = ⊤ := by
have hRL : Function.Injective (algebraMap R L) := by
rw [IsScalarTower.algebraMap_eq R K L]
exact (algebraMap K L).injective.comp (NoZeroSMulDivisors.algebraMap_injective R K)
-- Let `M` be the `R`-module spanned by the proposed basis elements.
let M : Submodule R S := Submodule.span R b
-- Then `S / M` is generated by some finite set of `n` vectors `a`.
letI h : Module.Finite R (S ⧸ M) :=
Module.Finite.of_surjective (Submodule.mkQ _) (Submodule.Quotient.mk_surjective _)
obtain ⟨n, a, ha⟩ := @Module.Finite.exists_fin _ _ _ _ _ h
-- Because the image of `p` in `S / M` is `⊤`,
have smul_top_eq : p • (⊤ : Submodule R (S ⧸ M)) = ⊤ := by
calc
p • ⊤ = Submodule.map M.mkQ (p • ⊤) := by
rw [Submodule.map_smul'', Submodule.map_top, M.range_mkQ]
_ = ⊤ := by rw [Ideal.smul_top_eq_map, (Submodule.map_mkQ_eq_top M _).mpr hb']
-- we can write the elements of `a` as `p`-linear combinations of other elements of `a`.
have exists_sum : ∀ x : S ⧸ M, ∃ a' : Fin n → R, (∀ i, a' i ∈ p) ∧ ∑ i, a' i • a i = x := by
intro x
obtain ⟨a'', ha'', hx⟩ := (Submodule.mem_ideal_smul_span_iff_exists_sum p a x).1
(by { rw [ha, smul_top_eq]; exact Submodule.mem_top } :
x ∈ p • Submodule.span R (Set.range a))
· refine ⟨fun i => a'' i, fun i => ha'' _, ?_⟩
rw [← hx, Finsupp.sum_fintype]
exact fun _ => zero_smul _ _
choose A' hA'p hA' using fun i => exists_sum (a i)
-- This gives us a(n invertible) matrix `A` such that `det A ∈ (M = span R b)`,
let A : Matrix (Fin n) (Fin n) R := Matrix.of A' - 1
let B := A.adjugate
have A_smul : ∀ i, ∑ j, A i j • a j = 0 := by
intros
simp [A, Matrix.sub_apply, Matrix.of_apply, ne_eq, Matrix.one_apply, sub_smul,
Finset.sum_sub_distrib, hA', sub_self]
-- since `span S {det A} / M = 0`.
have d_smul : ∀ i, A.det • a i = 0 := by
intro i
calc
A.det • a i = ∑ j, (B * A) i j • a j := ?_
_ = ∑ k, B i k • ∑ j, A k j • a j := ?_
_ = 0 := Finset.sum_eq_zero fun k _ => ?_
· simp only [B, Matrix.adjugate_mul, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, ite_true,
mul_ite, mul_one, mul_zero, ite_smul, zero_smul, Finset.sum_ite_eq, Finset.mem_univ]
· simp only [Matrix.mul_apply, Finset.smul_sum, Finset.sum_smul, smul_smul]
rw [Finset.sum_comm]
· rw [A_smul, smul_zero]
-- In the rings of integers we have the desired inclusion.
have span_d : (Submodule.span S ({algebraMap R S A.det} : Set S)).restrictScalars R ≤ M := by
intro x hx
rw [Submodule.restrictScalars_mem] at hx
obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hx
rw [smul_eq_mul, mul_comm, ← Algebra.smul_def] at hx ⊢
rw [← Submodule.Quotient.mk_eq_zero, Submodule.Quotient.mk_smul]
obtain ⟨a', _, quot_x_eq⟩ := exists_sum (Submodule.Quotient.mk x')
rw [← quot_x_eq, Finset.smul_sum]
conv =>
lhs; congr; next => skip
intro x; rw [smul_comm A.det, d_smul, smul_zero]
exact Finset.sum_const_zero
refine top_le_iff.mp
(calc
⊤ = (Ideal.span {algebraMap R L A.det}).restrictScalars K := ?_
_ ≤ Submodule.span K (algebraMap S L '' b) := ?_)
-- Because `det A ≠ 0`, we have `span L {det A} = ⊤`.
· rw [eq_comm, Submodule.restrictScalars_eq_top_iff, Ideal.span_singleton_eq_top]
refine IsUnit.mk0 _ ((map_ne_zero_iff (algebraMap R L) hRL).mpr ?_)
refine ne_zero_of_map (f := Ideal.Quotient.mk p) ?_
haveI := Ideal.Quotient.nontrivial hp
calc
Ideal.Quotient.mk p A.det = Matrix.det ((Ideal.Quotient.mk p).mapMatrix A) := by
rw [RingHom.map_det]
_ = Matrix.det ((Ideal.Quotient.mk p).mapMatrix (Matrix.of A' - 1)) := rfl
_ = Matrix.det fun i j =>
(Ideal.Quotient.mk p) (A' i j) - (1 : Matrix (Fin n) (Fin n) (R ⧸ p)) i j := ?_
_ = Matrix.det (-1 : Matrix (Fin n) (Fin n) (R ⧸ p)) := ?_
_ = (-1 : R ⧸ p) ^ n := by rw [Matrix.det_neg, Fintype.card_fin, Matrix.det_one, mul_one]
_ ≠ 0 := IsUnit.ne_zero (isUnit_one.neg.pow _)
· refine congr_arg Matrix.det (Matrix.ext fun i j => ?_)
rw [map_sub, RingHom.mapMatrix_apply, map_one]
rfl
· refine congr_arg Matrix.det (Matrix.ext fun i j => ?_)
rw [Ideal.Quotient.eq_zero_iff_mem.mpr (hA'p i j), zero_sub]
rfl
-- And we conclude `L = span L {det A} ≤ span K b`, so `span K b` spans everything.
· intro x hx
rw [Submodule.restrictScalars_mem, IsScalarTower.algebraMap_apply R S L] at hx
have : Algebra.IsAlgebraic R L := by
have : NoZeroSMulDivisors R L := NoZeroSMulDivisors.of_algebraMap_injective hRL
rw [← IsFractionRing.isAlgebraic_iff' R S]
infer_instance
refine IsFractionRing.ideal_span_singleton_map_subset R hRL span_d hx
#align ideal.finrank_quotient_map.span_eq_top Ideal.FinrankQuotientMap.span_eq_top
variable (K L)
/-- If `p` is a maximal ideal of `R`, and `S` is the integral closure of `R` in `L`,
then the dimension `[S/pS : R/p]` is equal to `[Frac(S) : Frac(R)]`. -/
theorem finrank_quotient_map [IsDomain S] [IsDedekindDomain R] [Algebra K L]
[Algebra R L] [IsScalarTower R K L] [IsScalarTower R S L] [IsIntegralClosure S R L]
[hp : p.IsMaximal] [IsNoetherian R S] :
finrank (R ⧸ p) (S ⧸ map (algebraMap R S) p) = finrank K L := by
-- Choose an arbitrary basis `b` for `[S/pS : R/p]`.
-- We'll use the previous results to turn it into a basis on `[Frac(S) : Frac(R)]`.
letI : Field (R ⧸ p) := Ideal.Quotient.field _
let ι := Module.Free.ChooseBasisIndex (R ⧸ p) (S ⧸ map (algebraMap R S) p)
let b : Basis ι (R ⧸ p) (S ⧸ map (algebraMap R S) p) := Module.Free.chooseBasis _ _
-- Namely, choose a representative `b' i : S` for each `b i : S / pS`.
let b' : ι → S := fun i => (Ideal.Quotient.mk_surjective (b i)).choose
have b_eq_b' : ⇑b = (Submodule.mkQ (map (algebraMap R S) p)).restrictScalars R ∘ b' :=
funext fun i => (Ideal.Quotient.mk_surjective (b i)).choose_spec.symm
-- We claim `b'` is a basis for `Frac(S)` over `Frac(R)` because it is linear independent
-- and spans the whole of `Frac(S)`.
let b'' : ι → L := algebraMap S L ∘ b'
have b''_li : LinearIndependent K b'' := ?_
· have b''_sp : Submodule.span K (Set.range b'') = ⊤ := ?_
-- Since the two bases have the same index set, the spaces have the same dimension.
· let c : Basis ι K L := Basis.mk b''_li b''_sp.ge
rw [finrank_eq_card_basis b, finrank_eq_card_basis c]
-- It remains to show that the basis is indeed linear independent and spans the whole space.
· rw [Set.range_comp]
refine FinrankQuotientMap.span_eq_top p hp.ne_top _ (top_le_iff.mp ?_)
-- The nicest way to show `S ≤ span b' ⊔ pS` is by reducing both sides modulo pS.
-- However, this would imply distinguishing between `pS` as `S`-ideal,
-- and `pS` as `R`-submodule, since they have different (non-defeq) quotients.
-- Instead we'll lift `x mod pS ∈ span b` to `y ∈ span b'` for some `y - x ∈ pS`.
intro x _
have mem_span_b : ((Submodule.mkQ (map (algebraMap R S) p)) x : S ⧸ map (algebraMap R S) p) ∈
Submodule.span (R ⧸ p) (Set.range b) := b.mem_span _
rw [← @Submodule.restrictScalars_mem R,
Submodule.restrictScalars_span R (R ⧸ p) Ideal.Quotient.mk_surjective, b_eq_b',
Set.range_comp, ← Submodule.map_span] at mem_span_b
obtain ⟨y, y_mem, y_eq⟩ := Submodule.mem_map.mp mem_span_b
suffices y + -(y - x) ∈ _ by simpa
rw [LinearMap.restrictScalars_apply, Submodule.mkQ_apply, Submodule.mkQ_apply,
Submodule.Quotient.eq] at y_eq
exact add_mem (Submodule.mem_sup_left y_mem) (neg_mem <| Submodule.mem_sup_right y_eq)
· have := b.linearIndependent; rw [b_eq_b'] at this
convert FinrankQuotientMap.linearIndependent_of_nontrivial K _
((Algebra.linearMap S L).restrictScalars R) _ ((Submodule.mkQ _).restrictScalars R) this
· rw [Quotient.algebraMap_eq, Ideal.mk_ker]
exact hp.ne_top
· exact IsFractionRing.injective S L
#align ideal.finrank_quotient_map Ideal.finrank_quotient_map
end FinrankQuotientMap
section FactLeComap
local notation "e" => ramificationIdx f p P
/-- `R / p` has a canonical map to `S / (P ^ e)`, where `e` is the ramification index
of `P` over `p`. -/
noncomputable instance Quotient.algebraQuotientPowRamificationIdx : Algebra (R ⧸ p) (S ⧸ P ^ e) :=
Quotient.algebraQuotientOfLEComap (Ideal.map_le_iff_le_comap.mp le_pow_ramificationIdx)
#align ideal.quotient.algebra_quotient_pow_ramification_idx Ideal.Quotient.algebraQuotientPowRamificationIdx
#adaptation_note /-- 2024-04-23
The right hand side here used to be `Ideal.Quotient.mk _ (f x)` which was somewhat slow,
but this is now even slower without `set_option backward.isDefEq.lazyProjDelta false in`
Instead we've replaced it with `Ideal.Quotient.mk (P ^ e) (f x)` (compare #12412) -/
@[simp]
theorem Quotient.algebraMap_quotient_pow_ramificationIdx (x : R) :
algebraMap (R ⧸ p) (S ⧸ P ^ e) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk (P ^ e) (f x) := rfl
#align ideal.quotient.algebra_map_quotient_pow_ramification_idx Ideal.Quotient.algebraMap_quotient_pow_ramificationIdx
variable [hfp : NeZero (ramificationIdx f p P)]
/-- If `P` lies over `p`, then `R / p` has a canonical map to `S / P`.
This can't be an instance since the map `f : R → S` is generally not inferrable.
-/
def Quotient.algebraQuotientOfRamificationIdxNeZero : Algebra (R ⧸ p) (S ⧸ P) :=
Quotient.algebraQuotientOfLEComap (le_comap_of_ramificationIdx_ne_zero hfp.out)
#align ideal.quotient.algebra_quotient_of_ramification_idx_ne_zero Ideal.Quotient.algebraQuotientOfRamificationIdxNeZero
set_option synthInstance.checkSynthOrder false -- Porting note: this is okay by the remark below
-- In this file, the value for `f` can be inferred.
attribute [local instance] Ideal.Quotient.algebraQuotientOfRamificationIdxNeZero
#adaptation_note /-- 2024-04-28
The RHS used to be `Ideal.Quotient.mk _ (f x)`, which was slow,
but this is now even slower without `set_option backward.isDefEq.lazyWhnfCore false in`
(compare https://github.com/leanprover-community/mathlib4/pull/12412) -/
@[simp]
theorem Quotient.algebraMap_quotient_of_ramificationIdx_neZero (x : R) :
algebraMap (R ⧸ p) (S ⧸ P) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk P (f x) := rfl
#align ideal.quotient.algebra_map_quotient_of_ramification_idx_ne_zero Ideal.Quotient.algebraMap_quotient_of_ramificationIdx_neZero
/-- The inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)`. -/
@[simps]
def powQuotSuccInclusion (i : ℕ) :
Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ (i + 1)) →ₗ[R ⧸ p]
Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i) where
toFun x := ⟨x, Ideal.map_mono (Ideal.pow_le_pow_right i.le_succ) x.2⟩
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align ideal.pow_quot_succ_inclusion Ideal.powQuotSuccInclusion
theorem powQuotSuccInclusion_injective (i : ℕ) :
Function.Injective (powQuotSuccInclusion f p P i) := by
rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot']
rintro ⟨x, hx⟩ hx0
rw [Subtype.ext_iff] at hx0 ⊢
rwa [powQuotSuccInclusion_apply_coe] at hx0
#align ideal.pow_quot_succ_inclusion_injective Ideal.powQuotSuccInclusion_injective
/-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`.
See `quotientToQuotientRangePowQuotSucc` for this as a linear map,
and `quotientRangePowQuotSuccInclusionEquiv` for this as a linear equivalence.
-/
noncomputable def quotientToQuotientRangePowQuotSuccAux {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) :
S ⧸ P →
(P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion f p P i) :=
Quotient.map' (fun x : S => ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩)
fun x y h => by
rw [Submodule.quotientRel_r_def] at h ⊢
simp only [_root_.map_mul, LinearMap.mem_range]
refine ⟨⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_mul a_mem h)⟩, ?_⟩
ext
rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Submodule.coe_sub, Subtype.coe_mk,
Subtype.coe_mk, _root_.map_mul, map_sub, mul_sub]
#align ideal.quotient_to_quotient_range_pow_quot_succ_aux Ideal.quotientToQuotientRangePowQuotSuccAux
theorem quotientToQuotientRangePowQuotSuccAux_mk {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) (x : S) :
quotientToQuotientRangePowQuotSuccAux f p P a_mem (Submodule.Quotient.mk x) =
Submodule.Quotient.mk ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩ := by
apply Quotient.map'_mk''
#align ideal.quotient_to_quotient_range_pow_quot_succ_aux_mk Ideal.quotientToQuotientRangePowQuotSuccAux_mk
/-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`. -/
noncomputable def quotientToQuotientRangePowQuotSucc {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) :
S ⧸ P →ₗ[R ⧸ p]
(P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion f p P i) where
toFun := quotientToQuotientRangePowQuotSuccAux f p P a_mem
map_add' := by
intro x y; refine Quotient.inductionOn' x fun x => Quotient.inductionOn' y fun y => ?_
simp only [Submodule.Quotient.mk''_eq_mk, ← Submodule.Quotient.mk_add,
quotientToQuotientRangePowQuotSuccAux_mk, mul_add]
exact congr_arg Submodule.Quotient.mk rfl
map_smul' := by
intro x y; refine Quotient.inductionOn' x fun x => Quotient.inductionOn' y fun y => ?_
simp only [Submodule.Quotient.mk''_eq_mk, RingHom.id_apply,
quotientToQuotientRangePowQuotSuccAux_mk]
refine congr_arg Submodule.Quotient.mk ?_
ext
simp only [mul_assoc, _root_.map_mul, Quotient.mk_eq_mk, Submodule.coe_smul_of_tower,
Algebra.smul_def, Quotient.algebraMap_quotient_pow_ramificationIdx]
ring
#align ideal.quotient_to_quotient_range_pow_quot_succ Ideal.quotientToQuotientRangePowQuotSucc
theorem quotientToQuotientRangePowQuotSucc_mk {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) (x : S) :
quotientToQuotientRangePowQuotSucc f p P a_mem (Submodule.Quotient.mk x) =
Submodule.Quotient.mk ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩ :=
quotientToQuotientRangePowQuotSuccAux_mk f p P a_mem x
#align ideal.quotient_to_quotient_range_pow_quot_succ_mk Ideal.quotientToQuotientRangePowQuotSucc_mk
theorem quotientToQuotientRangePowQuotSucc_injective [IsDedekindDomain S] [P.IsPrime]
{i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i) (a_not_mem : a ∉ P ^ (i + 1)) :
Function.Injective (quotientToQuotientRangePowQuotSucc f p P a_mem) := fun x =>
Quotient.inductionOn' x fun x y =>
Quotient.inductionOn' y fun y h => by
have Pe_le_Pi1 : P ^ e ≤ P ^ (i + 1) := Ideal.pow_le_pow_right hi
simp only [Submodule.Quotient.mk''_eq_mk, quotientToQuotientRangePowQuotSucc_mk,
Submodule.Quotient.eq, LinearMap.mem_range, Subtype.ext_iff, Subtype.coe_mk,
Submodule.coe_sub] at h ⊢
rcases h with ⟨⟨⟨z⟩, hz⟩, h⟩
rw [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi1] at hz
rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Submodule.Quotient.quot_mk_eq_mk,
Ideal.Quotient.mk_eq_mk, ← map_sub, Ideal.Quotient.eq, ← mul_sub] at h
exact
(Ideal.IsPrime.mem_pow_mul _
((Submodule.sub_mem_iff_right _ hz).mp (Pe_le_Pi1 h))).resolve_left
a_not_mem
#align ideal.quotient_to_quotient_range_pow_quot_succ_injective Ideal.quotientToQuotientRangePowQuotSucc_injective
theorem quotientToQuotientRangePowQuotSucc_surjective [IsDedekindDomain S]
(hP0 : P ≠ ⊥) [hP : P.IsPrime] {i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i)
(a_not_mem : a ∉ P ^ (i + 1)) :
Function.Surjective (quotientToQuotientRangePowQuotSucc f p P a_mem) := by
rintro ⟨⟨⟨x⟩, hx⟩⟩
have Pe_le_Pi : P ^ e ≤ P ^ i := Ideal.pow_le_pow_right hi.le
rw [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi] at hx
suffices hx' : x ∈ Ideal.span {a} ⊔ P ^ (i + 1) by
obtain ⟨y', hy', z, hz, rfl⟩ := Submodule.mem_sup.mp hx'
obtain ⟨y, rfl⟩ := Ideal.mem_span_singleton.mp hy'
refine ⟨Submodule.Quotient.mk y, ?_⟩
simp only [Submodule.Quotient.quot_mk_eq_mk, quotientToQuotientRangePowQuotSucc_mk,
Submodule.Quotient.eq, LinearMap.mem_range, Subtype.ext_iff, Subtype.coe_mk,
Submodule.coe_sub]
refine ⟨⟨_, Ideal.mem_map_of_mem _ (Submodule.neg_mem _ hz)⟩, ?_⟩
rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Ideal.Quotient.mk_eq_mk, map_add,
sub_add_cancel_left, map_neg]
letI := Classical.decEq (Ideal S)
rw [sup_eq_prod_inf_factors _ (pow_ne_zero _ hP0), normalizedFactors_pow,
normalizedFactors_irreducible ((Ideal.prime_iff_isPrime hP0).mpr hP).irreducible, normalize_eq,
Multiset.nsmul_singleton, Multiset.inter_replicate, Multiset.prod_replicate]
· rw [← Submodule.span_singleton_le_iff_mem, Ideal.submodule_span_eq] at a_mem a_not_mem
rwa [Ideal.count_normalizedFactors_eq a_mem a_not_mem, min_eq_left i.le_succ]
· intro ha
rw [Ideal.span_singleton_eq_bot.mp ha] at a_not_mem
have := (P ^ (i + 1)).zero_mem
contradiction
#align ideal.quotient_to_quotient_range_pow_quot_succ_surjective Ideal.quotientToQuotientRangePowQuotSucc_surjective
/-- Quotienting `P^i / P^e` by its subspace `P^(i+1) ⧸ P^e` is
`R ⧸ p`-linearly isomorphic to `S ⧸ P`. -/
noncomputable def quotientRangePowQuotSuccInclusionEquiv [IsDedekindDomain S]
[P.IsPrime] (hP : P ≠ ⊥) {i : ℕ} (hi : i < e) :
((P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion f p P i))
≃ₗ[R ⧸ p] S ⧸ P := by
choose a a_mem a_not_mem using
SetLike.exists_of_lt
(Ideal.pow_right_strictAnti P hP (Ideal.IsPrime.ne_top inferInstance) (le_refl i.succ))
refine (LinearEquiv.ofBijective ?_ ⟨?_, ?_⟩).symm
· exact quotientToQuotientRangePowQuotSucc f p P a_mem
· exact quotientToQuotientRangePowQuotSucc_injective f p P hi a_mem a_not_mem
· exact quotientToQuotientRangePowQuotSucc_surjective f p P hP hi a_mem a_not_mem
#align ideal.quotient_range_pow_quot_succ_inclusion_equiv Ideal.quotientRangePowQuotSuccInclusionEquiv
/-- Since the inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)` has a kernel isomorphic to `P / S`,
`[P^i / P^e : R / p] = [P^(i+1) / P^e : R / p] + [P / S : R / p]` -/
theorem rank_pow_quot_aux [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime] (hP0 : P ≠ ⊥)
{i : ℕ} (hi : i < e) :
Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i)) =
Module.rank (R ⧸ p) (S ⧸ P) +
Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ (i + 1))) := by
letI : Field (R ⧸ p) := Ideal.Quotient.field _
rw [← rank_range_of_injective _ (powQuotSuccInclusion_injective f p P i),
(quotientRangePowQuotSuccInclusionEquiv f p P hP0 hi).symm.rank_eq]
exact (rank_quotient_add_rank (LinearMap.range (powQuotSuccInclusion f p P i))).symm
#align ideal.rank_pow_quot_aux Ideal.rank_pow_quot_aux
theorem rank_pow_quot [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime] (hP0 : P ≠ ⊥)
(i : ℕ) (hi : i ≤ e) :
Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i)) =
(e - i) • Module.rank (R ⧸ p) (S ⧸ P) := by
-- Porting note: Lean cannot figure out what to prove by itself
let Q : ℕ → Prop :=
fun i => Module.rank (R ⧸ p) { x // x ∈ map (Quotient.mk (P ^ e)) (P ^ i) }
= (e - i) • Module.rank (R ⧸ p) (S ⧸ P)
refine Nat.decreasingInduction' (P := Q) (fun j lt_e _le_j ih => ?_) hi ?_
· dsimp only [Q]
rw [rank_pow_quot_aux f p P _ lt_e, ih, ← succ_nsmul', Nat.sub_succ, ← Nat.succ_eq_add_one,
Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt lt_e)]
assumption
· dsimp only [Q]
rw [Nat.sub_self, zero_nsmul, map_quotient_self]
exact rank_bot (R ⧸ p) (S ⧸ P ^ e)
#align ideal.rank_pow_quot Ideal.rank_pow_quot
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]` is equal to `e * [S/P : R/p]`. -/
theorem rank_prime_pow_ramificationIdx [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime]
(hP0 : P ≠ ⊥) (he : e ≠ 0) :
Module.rank (R ⧸ p) (S ⧸ P ^ e) =
e •
@Module.rank (R ⧸ p) (S ⧸ P) _ _
(@Algebra.toModule _ _ _ _ <|
@Quotient.algebraQuotientOfRamificationIdxNeZero _ _ _ _ _ _ _ ⟨he⟩) := by
letI : NeZero e := ⟨he⟩
have := rank_pow_quot f p P hP0 0 (Nat.zero_le e)
rw [pow_zero, Nat.sub_zero, Ideal.one_eq_top, Ideal.map_top] at this
exact (rank_top (R ⧸ p) _).symm.trans this
#align ideal.rank_prime_pow_ramification_idx Ideal.rank_prime_pow_ramificationIdx
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]`, as a natural number, is equal to `e * [S/P : R/p]`. -/
theorem finrank_prime_pow_ramificationIdx [IsDedekindDomain S] (hP0 : P ≠ ⊥)
[p.IsMaximal] [P.IsPrime] (he : e ≠ 0) :
finrank (R ⧸ p) (S ⧸ P ^ e) =
e *
@finrank (R ⧸ p) (S ⧸ P) _ _
(@Algebra.toModule _ _ _ _ <|
@Quotient.algebraQuotientOfRamificationIdxNeZero _ _ _ _ _ _ _ ⟨he⟩) := by
letI : NeZero e := ⟨he⟩
letI : Algebra (R ⧸ p) (S ⧸ P) := Quotient.algebraQuotientOfRamificationIdxNeZero f p P
letI := Ideal.Quotient.field p
have hdim := rank_prime_pow_ramificationIdx _ _ _ hP0 he
by_cases hP : FiniteDimensional (R ⧸ p) (S ⧸ P)
· haveI := hP
haveI := (finiteDimensional_iff_of_rank_eq_nsmul he hdim).mpr hP
refine Cardinal.natCast_injective ?_
rw [finrank_eq_rank', Nat.cast_mul, finrank_eq_rank', hdim, nsmul_eq_mul]
have hPe := mt (finiteDimensional_iff_of_rank_eq_nsmul he hdim).mp hP
simp only [finrank_of_infinite_dimensional hP, finrank_of_infinite_dimensional hPe,
mul_zero]
#align ideal.finrank_prime_pow_ramification_idx Ideal.finrank_prime_pow_ramificationIdx
end FactLeComap
section FactorsMap
open scoped Classical
/-! ## Properties of the factors of `p.map (algebraMap R S)` -/
variable [IsDedekindDomain S] [Algebra R S]
theorem Factors.ne_bot (P : (factors (map (algebraMap R S) p)).toFinset) : (P : Ideal S) ≠ ⊥ :=
(prime_of_factor _ (Multiset.mem_toFinset.mp P.2)).ne_zero
#align ideal.factors.ne_bot Ideal.Factors.ne_bot
instance Factors.isPrime (P : (factors (map (algebraMap R S) p)).toFinset) :
IsPrime (P : Ideal S) :=
Ideal.isPrime_of_prime (prime_of_factor _ (Multiset.mem_toFinset.mp P.2))
#align ideal.factors.is_prime Ideal.Factors.isPrime
theorem Factors.ramificationIdx_ne_zero (P : (factors (map (algebraMap R S) p)).toFinset) :
ramificationIdx (algebraMap R S) p P ≠ 0 :=
IsDedekindDomain.ramificationIdx_ne_zero (ne_zero_of_mem_factors (Multiset.mem_toFinset.mp P.2))
(Factors.isPrime p P) (Ideal.le_of_dvd (dvd_of_mem_factors (Multiset.mem_toFinset.mp P.2)))
#align ideal.factors.ramification_idx_ne_zero Ideal.Factors.ramificationIdx_ne_zero
instance Factors.fact_ramificationIdx_neZero (P : (factors (map (algebraMap R S) p)).toFinset) :
NeZero (ramificationIdx (algebraMap R S) p P) :=
⟨Factors.ramificationIdx_ne_zero p P⟩
#align ideal.factors.fact_ramification_idx_ne_zero Ideal.Factors.fact_ramificationIdx_neZero
set_option synthInstance.checkSynthOrder false
-- Porting note: this is okay since, as noted above, in this file the value of `f` can be inferred
attribute [local instance] Quotient.algebraQuotientOfRamificationIdxNeZero
instance Factors.isScalarTower (P : (factors (map (algebraMap R S) p)).toFinset) :
IsScalarTower R (R ⧸ p) (S ⧸ (P : Ideal S)) :=
IsScalarTower.of_algebraMap_eq fun x => by simp
#align ideal.factors.is_scalar_tower Ideal.Factors.isScalarTower
attribute [local instance] Ideal.Quotient.field
theorem Factors.finrank_pow_ramificationIdx [p.IsMaximal]
(P : (factors (map (algebraMap R S) p)).toFinset) :
finrank (R ⧸ p) (S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P) =
ramificationIdx (algebraMap R S) p P * inertiaDeg (algebraMap R S) p P := by
rw [finrank_prime_pow_ramificationIdx, inertiaDeg_algebraMap]
exacts [NeZero.ne _, Factors.ne_bot p P]
#align ideal.factors.finrank_pow_ramification_idx Ideal.Factors.finrank_pow_ramificationIdx
instance Factors.finiteDimensional_quotient [IsNoetherian R S] [p.IsMaximal]
(P : (factors (map (algebraMap R S) p)).toFinset) :
FiniteDimensional (R ⧸ p) (S ⧸ (P : Ideal S)) :=
IsNoetherian.iff_fg.mp <|
isNoetherian_of_tower R <|
isNoetherian_of_surjective S (Ideal.Quotient.mkₐ _ _).toLinearMap <|
LinearMap.range_eq_top.mpr Ideal.Quotient.mk_surjective
#align ideal.factors.finite_dimensional_quotient Ideal.Factors.finiteDimensional_quotient
theorem Factors.inertiaDeg_ne_zero [IsNoetherian R S] [p.IsMaximal]
(P : (factors (map (algebraMap R S) p)).toFinset) : inertiaDeg (algebraMap R S) p P ≠ 0 := by
rw [inertiaDeg_algebraMap]; exact (FiniteDimensional.finrank_pos_iff.mpr inferInstance).ne'
#align ideal.factors.inertia_deg_ne_zero Ideal.Factors.inertiaDeg_ne_zero
instance Factors.finiteDimensional_quotient_pow [IsNoetherian R S] [p.IsMaximal]
(P : (factors (map (algebraMap R S) p)).toFinset) :
FiniteDimensional (R ⧸ p) (S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P) := by
refine .of_finrank_pos ?_
rw [pos_iff_ne_zero, Factors.finrank_pow_ramificationIdx]
exact mul_ne_zero (Factors.ramificationIdx_ne_zero p P) (Factors.inertiaDeg_ne_zero p P)
#align ideal.factors.finite_dimensional_quotient_pow Ideal.Factors.finiteDimensional_quotient_pow
universe w
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : Ideal R`
factors in `S` as `∏ i, P i ^ e i`, then `S ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`. -/
noncomputable def Factors.piQuotientEquiv (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) :
S ⧸ map (algebraMap R S) p ≃+*
∀ P : (factors (map (algebraMap R S) p)).toFinset,
S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P :=
(IsDedekindDomain.quotientEquivPiFactors hp).trans <|
@RingEquiv.piCongrRight (factors (map (algebraMap R S) p)).toFinset
(fun P => S ⧸ (P : Ideal S) ^ (factors (map (algebraMap R S) p)).count (P : Ideal S))
(fun P => S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P) _ _
fun P : (factors (map (algebraMap R S) p)).toFinset =>
Ideal.quotEquivOfEq <| by
rw [IsDedekindDomain.ramificationIdx_eq_factors_count hp (Factors.isPrime p P)
(Factors.ne_bot p P)]
#align ideal.factors.pi_quotient_equiv Ideal.Factors.piQuotientEquiv
@[simp]
theorem Factors.piQuotientEquiv_mk (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) (x : S) :
Factors.piQuotientEquiv p hp (Ideal.Quotient.mk _ x) = fun _ => Ideal.Quotient.mk _ x := rfl
#align ideal.factors.pi_quotient_equiv_mk Ideal.Factors.piQuotientEquiv_mk
@[simp]
theorem Factors.piQuotientEquiv_map (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) (x : R) :
Factors.piQuotientEquiv p hp (algebraMap _ _ x) = fun _ =>
Ideal.Quotient.mk _ (algebraMap _ _ x) := rfl
#align ideal.factors.pi_quotient_equiv_map Ideal.Factors.piQuotientEquiv_map
variable (S)
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : Ideal R`
factors in `S` as `∏ i, P i ^ e i`,
then `S ⧸ I` factors `R ⧸ I`-linearly as `Π i, R ⧸ (P i ^ e i)`. -/
noncomputable def Factors.piQuotientLinearEquiv (p : Ideal R) (hp : map (algebraMap R S) p ≠ ⊥) :
(S ⧸ map (algebraMap R S) p) ≃ₗ[R ⧸ p]
∀ P : (factors (map (algebraMap R S) p)).toFinset,
S ⧸ (P : Ideal S) ^ ramificationIdx (algebraMap R S) p P :=
{ Factors.piQuotientEquiv p hp with
map_smul' := by
rintro ⟨c⟩ ⟨x⟩; ext P
simp only [Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, Algebra.smul_def,
Quotient.algebraMap_quotient_map_quotient, Quotient.mk_algebraMap,
RingHomCompTriple.comp_apply, Pi.mul_apply, Pi.algebraMap_apply]
congr }
#align ideal.factors.pi_quotient_linear_equiv Ideal.Factors.piQuotientLinearEquiv
variable {S}
/-- The **fundamental identity** of ramification index `e` and inertia degree `f`:
for `P` ranging over the primes lying over `p`, `∑ P, e P * f P = [Frac(S) : Frac(R)]`;
here `S` is a finite `R`-module (and thus `Frac(S) : Frac(R)` is a finite extension) and `p`
is maximal.
-/
| Mathlib/NumberTheory/RamificationInertia.lean | 808 | 839 | theorem sum_ramification_inertia (K L : Type*) [Field K] [Field L] [IsDedekindDomain R]
[Algebra R K] [IsFractionRing R K] [Algebra S L] [IsFractionRing S L] [Algebra K L]
[Algebra R L] [IsScalarTower R S L] [IsScalarTower R K L] [IsNoetherian R S]
[IsIntegralClosure S R L] [p.IsMaximal] (hp0 : p ≠ ⊥) :
(∑ P ∈ (factors (map (algebraMap R S) p)).toFinset,
ramificationIdx (algebraMap R S) p P * inertiaDeg (algebraMap R S) p P) =
finrank K L := by |
set e := ramificationIdx (algebraMap R S) p
set f := inertiaDeg (algebraMap R S) p
have inj_RL : Function.Injective (algebraMap R L) := by
rw [IsScalarTower.algebraMap_eq R K L, RingHom.coe_comp]
exact (RingHom.injective _).comp (IsFractionRing.injective R K)
have inj_RS : Function.Injective (algebraMap R S) := by
refine Function.Injective.of_comp (show Function.Injective (algebraMap S L ∘ _) from ?_)
rw [← RingHom.coe_comp, ← IsScalarTower.algebraMap_eq]
exact inj_RL
calc
(∑ P ∈ (factors (map (algebraMap R S) p)).toFinset, e P * f P) =
∑ P ∈ (factors (map (algebraMap R S) p)).toFinset.attach,
finrank (R ⧸ p) (S ⧸ (P : Ideal S) ^ e P) := ?_
_ = finrank (R ⧸ p)
(∀ P : (factors (map (algebraMap R S) p)).toFinset, S ⧸ (P : Ideal S) ^ e P) :=
(finrank_pi_fintype (R ⧸ p)).symm
_ = finrank (R ⧸ p) (S ⧸ map (algebraMap R S) p) := ?_
_ = finrank K L := ?_
· rw [← Finset.sum_attach]
refine Finset.sum_congr rfl fun P _ => ?_
rw [Factors.finrank_pow_ramificationIdx]
· refine LinearEquiv.finrank_eq (Factors.piQuotientLinearEquiv S p ?_).symm
rwa [Ne, Ideal.map_eq_bot_iff_le_ker, (RingHom.injective_iff_ker_eq_bot _).mp inj_RS,
le_bot_iff]
· exact finrank_quotient_map p K L
|
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky, Yury Kudryashov
-/
import Mathlib.Data.Set.Image
import Mathlib.Data.List.InsertNth
import Mathlib.Init.Data.List.Lemmas
#align_import data.list.lemmas from "leanprover-community/mathlib"@"2ec920d35348cb2d13ac0e1a2ad9df0fdf1a76b4"
/-! # Some lemmas about lists involving sets
Split out from `Data.List.Basic` to reduce its dependencies.
-/
open List
variable {α β γ : Type*}
namespace List
theorem injOn_insertNth_index_of_not_mem (l : List α) (x : α) (hx : x ∉ l) :
Set.InjOn (fun k => insertNth k x l) { n | n ≤ l.length } := by
induction' l with hd tl IH
· intro n hn m hm _
simp only [Set.mem_singleton_iff, Set.setOf_eq_eq_singleton,
length] at hn hm
simp_all [hn, hm]
· intro n hn m hm h
simp only [length, Set.mem_setOf_eq] at hn hm
simp only [mem_cons, not_or] at hx
cases n <;> cases m
· rfl
· simp [hx.left] at h
· simp [Ne.symm hx.left] at h
· simp only [true_and_iff, eq_self_iff_true, insertNth_succ_cons] at h
rw [Nat.succ_inj']
refine IH hx.right ?_ ?_ (by injection h)
· simpa [Nat.succ_le_succ_iff] using hn
· simpa [Nat.succ_le_succ_iff] using hm
#align list.inj_on_insert_nth_index_of_not_mem List.injOn_insertNth_index_of_not_mem
| Mathlib/Data/List/Lemmas.lean | 44 | 52 | theorem foldr_range_subset_of_range_subset {f : β → α → α} {g : γ → α → α}
(hfg : Set.range f ⊆ Set.range g) (a : α) : Set.range (foldr f a) ⊆ Set.range (foldr g a) := by |
rintro _ ⟨l, rfl⟩
induction' l with b l H
· exact ⟨[], rfl⟩
· cases' hfg (Set.mem_range_self b) with c hgf
cases' H with m hgf'
rw [foldr_cons, ← hgf, ← hgf']
exact ⟨c :: m, rfl⟩
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Data.Finset.Fold
import Mathlib.Data.Finset.Option
import Mathlib.Data.Finset.Pi
import Mathlib.Data.Finset.Prod
import Mathlib.Data.Multiset.Lattice
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Hom.Lattice
import Mathlib.Order.Nat
#align_import data.finset.lattice from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
/-!
# Lattice operations on finsets
-/
-- TODO:
-- assert_not_exists OrderedCommMonoid
assert_not_exists MonoidWithZero
open Function Multiset OrderDual
variable {F α β γ ι κ : Type*}
namespace Finset
/-! ### sup -/
section Sup
-- TODO: define with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]`
variable [SemilatticeSup α] [OrderBot α]
/-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/
def sup (s : Finset β) (f : β → α) : α :=
s.fold (· ⊔ ·) ⊥ f
#align finset.sup Finset.sup
variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α}
theorem sup_def : s.sup f = (s.1.map f).sup :=
rfl
#align finset.sup_def Finset.sup_def
@[simp]
theorem sup_empty : (∅ : Finset β).sup f = ⊥ :=
fold_empty
#align finset.sup_empty Finset.sup_empty
@[simp]
theorem sup_cons {b : β} (h : b ∉ s) : (cons b s h).sup f = f b ⊔ s.sup f :=
fold_cons h
#align finset.sup_cons Finset.sup_cons
@[simp]
theorem sup_insert [DecidableEq β] {b : β} : (insert b s : Finset β).sup f = f b ⊔ s.sup f :=
fold_insert_idem
#align finset.sup_insert Finset.sup_insert
@[simp]
theorem sup_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) :
(s.image f).sup g = s.sup (g ∘ f) :=
fold_image_idem
#align finset.sup_image Finset.sup_image
@[simp]
theorem sup_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).sup g = s.sup (g ∘ f) :=
fold_map
#align finset.sup_map Finset.sup_map
@[simp]
theorem sup_singleton {b : β} : ({b} : Finset β).sup f = f b :=
Multiset.sup_singleton
#align finset.sup_singleton Finset.sup_singleton
theorem sup_sup : s.sup (f ⊔ g) = s.sup f ⊔ s.sup g := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, sup_empty, sup_empty, bot_sup_eq]
| cons _ _ _ ih =>
rw [sup_cons, sup_cons, sup_cons, ih]
exact sup_sup_sup_comm _ _ _ _
#align finset.sup_sup Finset.sup_sup
theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
s₁.sup f = s₂.sup g := by
subst hs
exact Finset.fold_congr hfg
#align finset.sup_congr Finset.sup_congr
@[simp]
theorem _root_.map_finset_sup [SemilatticeSup β] [OrderBot β]
[FunLike F α β] [SupBotHomClass F α β]
(f : F) (s : Finset ι) (g : ι → α) : f (s.sup g) = s.sup (f ∘ g) :=
Finset.cons_induction_on s (map_bot f) fun i s _ h => by
rw [sup_cons, sup_cons, map_sup, h, Function.comp_apply]
#align map_finset_sup map_finset_sup
@[simp]
protected theorem sup_le_iff {a : α} : s.sup f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by
apply Iff.trans Multiset.sup_le
simp only [Multiset.mem_map, and_imp, exists_imp]
exact ⟨fun k b hb => k _ _ hb rfl, fun k a' b hb h => h ▸ k _ hb⟩
#align finset.sup_le_iff Finset.sup_le_iff
protected alias ⟨_, sup_le⟩ := Finset.sup_le_iff
#align finset.sup_le Finset.sup_le
theorem sup_const_le : (s.sup fun _ => a) ≤ a :=
Finset.sup_le fun _ _ => le_rfl
#align finset.sup_const_le Finset.sup_const_le
theorem le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f :=
Finset.sup_le_iff.1 le_rfl _ hb
#align finset.le_sup Finset.le_sup
theorem le_sup_of_le {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup f := h.trans <| le_sup hb
#align finset.le_sup_of_le Finset.le_sup_of_le
theorem sup_union [DecidableEq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f :=
eq_of_forall_ge_iff fun c => by simp [or_imp, forall_and]
#align finset.sup_union Finset.sup_union
@[simp]
theorem sup_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) :
(s.biUnion t).sup f = s.sup fun x => (t x).sup f :=
eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β]
#align finset.sup_bUnion Finset.sup_biUnion
theorem sup_const {s : Finset β} (h : s.Nonempty) (c : α) : (s.sup fun _ => c) = c :=
eq_of_forall_ge_iff (fun _ => Finset.sup_le_iff.trans h.forall_const)
#align finset.sup_const Finset.sup_const
@[simp]
theorem sup_bot (s : Finset β) : (s.sup fun _ => ⊥) = (⊥ : α) := by
obtain rfl | hs := s.eq_empty_or_nonempty
· exact sup_empty
· exact sup_const hs _
#align finset.sup_bot Finset.sup_bot
theorem sup_ite (p : β → Prop) [DecidablePred p] :
(s.sup fun i => ite (p i) (f i) (g i)) = (s.filter p).sup f ⊔ (s.filter fun i => ¬p i).sup g :=
fold_ite _
#align finset.sup_ite Finset.sup_ite
theorem sup_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.sup f ≤ s.sup g :=
Finset.sup_le fun b hb => le_trans (h b hb) (le_sup hb)
#align finset.sup_mono_fun Finset.sup_mono_fun
@[gcongr]
theorem sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f :=
Finset.sup_le (fun _ hb => le_sup (h hb))
#align finset.sup_mono Finset.sup_mono
protected theorem sup_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) :
(s.sup fun b => t.sup (f b)) = t.sup fun c => s.sup fun b => f b c :=
eq_of_forall_ge_iff fun a => by simpa using forall₂_swap
#align finset.sup_comm Finset.sup_comm
@[simp, nolint simpNF] -- Porting note: linter claims that LHS does not simplify
theorem sup_attach (s : Finset β) (f : β → α) : (s.attach.sup fun x => f x) = s.sup f :=
(s.attach.sup_map (Function.Embedding.subtype _) f).symm.trans <| congr_arg _ attach_map_val
#align finset.sup_attach Finset.sup_attach
/-- See also `Finset.product_biUnion`. -/
theorem sup_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = s.sup fun i => t.sup fun i' => f ⟨i, i'⟩ :=
eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ]
#align finset.sup_product_left Finset.sup_product_left
theorem sup_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = t.sup fun i' => s.sup fun i => f ⟨i, i'⟩ := by
rw [sup_product_left, Finset.sup_comm]
#align finset.sup_product_right Finset.sup_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] [OrderBot α] [OrderBot β]
{s : Finset ι} {t : Finset κ}
@[simp] lemma sup_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
sup (s ×ˢ t) (Prod.map f g) = (sup s f, sup t g) :=
eq_of_forall_ge_iff fun i ↦ by
obtain ⟨a, ha⟩ := hs
obtain ⟨b, hb⟩ := ht
simp only [Prod.map, Finset.sup_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def]
exact ⟨fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩, by aesop⟩
end Prod
@[simp]
theorem sup_erase_bot [DecidableEq α] (s : Finset α) : (s.erase ⊥).sup id = s.sup id := by
refine (sup_mono (s.erase_subset _)).antisymm (Finset.sup_le_iff.2 fun a ha => ?_)
obtain rfl | ha' := eq_or_ne a ⊥
· exact bot_le
· exact le_sup (mem_erase.2 ⟨ha', ha⟩)
#align finset.sup_erase_bot Finset.sup_erase_bot
theorem sup_sdiff_right {α β : Type*} [GeneralizedBooleanAlgebra α] (s : Finset β) (f : β → α)
(a : α) : (s.sup fun b => f b \ a) = s.sup f \ a := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, sup_empty, bot_sdiff]
| cons _ _ _ h => rw [sup_cons, sup_cons, h, sup_sdiff]
#align finset.sup_sdiff_right Finset.sup_sdiff_right
theorem comp_sup_eq_sup_comp [SemilatticeSup γ] [OrderBot γ] {s : Finset β} {f : β → α} (g : α → γ)
(g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) :=
Finset.cons_induction_on s bot fun c t hc ih => by
rw [sup_cons, sup_cons, g_sup, ih, Function.comp_apply]
#align finset.comp_sup_eq_sup_comp Finset.comp_sup_eq_sup_comp
/-- Computing `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/
theorem sup_coe {P : α → Prop} {Pbot : P ⊥} {Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)} (t : Finset β)
(f : β → { x : α // P x }) :
(@sup { x // P x } _ (Subtype.semilatticeSup Psup) (Subtype.orderBot Pbot) t f : α) =
t.sup fun x => ↑(f x) := by
letI := Subtype.semilatticeSup Psup
letI := Subtype.orderBot Pbot
apply comp_sup_eq_sup_comp Subtype.val <;> intros <;> rfl
#align finset.sup_coe Finset.sup_coe
@[simp]
theorem sup_toFinset {α β} [DecidableEq β] (s : Finset α) (f : α → Multiset β) :
(s.sup f).toFinset = s.sup fun x => (f x).toFinset :=
comp_sup_eq_sup_comp Multiset.toFinset toFinset_union rfl
#align finset.sup_to_finset Finset.sup_toFinset
theorem _root_.List.foldr_sup_eq_sup_toFinset [DecidableEq α] (l : List α) :
l.foldr (· ⊔ ·) ⊥ = l.toFinset.sup id := by
rw [← coe_fold_r, ← Multiset.fold_dedup_idem, sup_def, ← List.toFinset_coe, toFinset_val,
Multiset.map_id]
rfl
#align list.foldr_sup_eq_sup_to_finset List.foldr_sup_eq_sup_toFinset
theorem subset_range_sup_succ (s : Finset ℕ) : s ⊆ range (s.sup id).succ := fun _ hn =>
mem_range.2 <| Nat.lt_succ_of_le <| @le_sup _ _ _ _ _ id _ hn
#align finset.subset_range_sup_succ Finset.subset_range_sup_succ
theorem exists_nat_subset_range (s : Finset ℕ) : ∃ n : ℕ, s ⊆ range n :=
⟨_, s.subset_range_sup_succ⟩
#align finset.exists_nat_subset_range Finset.exists_nat_subset_range
| Mathlib/Data/Finset/Lattice.lean | 247 | 253 | theorem sup_induction {p : α → Prop} (hb : p ⊥) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.sup f) := by |
induction s using Finset.cons_induction with
| empty => exact hb
| cons _ _ _ ih =>
simp only [sup_cons, forall_mem_cons] at hs ⊢
exact hp _ hs.1 _ (ih hs.2)
|
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Monoidal.Category
import Mathlib.CategoryTheory.Adjunction.FullyFaithful
import Mathlib.CategoryTheory.Products.Basic
#align_import category_theory.monoidal.functor from "leanprover-community/mathlib"@"3d7987cda72abc473c7cdbbb075170e9ac620042"
/-!
# (Lax) monoidal functors
A lax monoidal functor `F` between monoidal categories `C` and `D`
is a functor between the underlying categories equipped with morphisms
* `ε : 𝟙_ D ⟶ F.obj (𝟙_ C)` (called the unit morphism)
* `μ X Y : (F.obj X) ⊗ (F.obj Y) ⟶ F.obj (X ⊗ Y)` (called the tensorator, or strength).
satisfying various axioms.
A monoidal functor is a lax monoidal functor for which `ε` and `μ` are isomorphisms.
We show that the composition of (lax) monoidal functors gives a (lax) monoidal functor.
See also `CategoryTheory.Monoidal.Functorial` for a typeclass decorating an object-level
function with the additional data of a monoidal functor.
This is useful when stating that a pre-existing functor is monoidal.
See `CategoryTheory.Monoidal.NaturalTransformation` for monoidal natural transformations.
We show in `CategoryTheory.Monoidal.Mon_` that lax monoidal functors take monoid objects
to monoid objects.
## References
See <https://stacks.math.columbia.edu/tag/0FFL>.
-/
open CategoryTheory
universe v₁ v₂ v₃ u₁ u₂ u₃
open CategoryTheory.Category
open CategoryTheory.Functor
namespace CategoryTheory
section
open MonoidalCategory
variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] (D : Type u₂) [Category.{v₂} D]
[MonoidalCategory.{v₂} D]
-- The direction of `left_unitality` and `right_unitality` as simp lemmas may look strange:
-- remember the rule of thumb that component indices of natural transformations
-- "weigh more" than structural maps.
-- (However by this argument `associativity` is currently stated backwards!)
/-- A lax monoidal functor is a functor `F : C ⥤ D` between monoidal categories,
equipped with morphisms `ε : 𝟙 _D ⟶ F.obj (𝟙_ C)` and `μ X Y : F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)`,
satisfying the appropriate coherences. -/
structure LaxMonoidalFunctor extends C ⥤ D where
/-- unit morphism -/
ε : 𝟙_ D ⟶ obj (𝟙_ C)
/-- tensorator -/
μ : ∀ X Y : C, obj X ⊗ obj Y ⟶ obj (X ⊗ Y)
μ_natural_left :
∀ {X Y : C} (f : X ⟶ Y) (X' : C),
map f ▷ obj X' ≫ μ Y X' = μ X X' ≫ map (f ▷ X') := by
aesop_cat
μ_natural_right :
∀ {X Y : C} (X' : C) (f : X ⟶ Y) ,
obj X' ◁ map f ≫ μ X' Y = μ X' X ≫ map (X' ◁ f) := by
aesop_cat
/-- associativity of the tensorator -/
associativity :
∀ X Y Z : C,
μ X Y ▷ obj Z ≫ μ (X ⊗ Y) Z ≫ map (α_ X Y Z).hom =
(α_ (obj X) (obj Y) (obj Z)).hom ≫ obj X ◁ μ Y Z ≫ μ X (Y ⊗ Z) := by
aesop_cat
-- unitality
left_unitality : ∀ X : C, (λ_ (obj X)).hom = ε ▷ obj X ≫ μ (𝟙_ C) X ≫ map (λ_ X).hom := by
aesop_cat
right_unitality : ∀ X : C, (ρ_ (obj X)).hom = obj X ◁ ε ≫ μ X (𝟙_ C) ≫ map (ρ_ X).hom := by
aesop_cat
#align category_theory.lax_monoidal_functor CategoryTheory.LaxMonoidalFunctor
-- Porting note (#11215): TODO: remove this configuration and use the default configuration.
-- We keep this to be consistent with Lean 3.
-- See also `initialize_simps_projections MonoidalFunctor` below.
-- This may require waiting on https://github.com/leanprover-community/mathlib4/pull/2936
initialize_simps_projections LaxMonoidalFunctor (+toFunctor, -obj, -map)
attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_left
attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_right
attribute [simp] LaxMonoidalFunctor.left_unitality
attribute [simp] LaxMonoidalFunctor.right_unitality
attribute [reassoc (attr := simp)] LaxMonoidalFunctor.associativity
-- When `rewrite_search` lands, add @[search] attributes to
-- LaxMonoidalFunctor.μ_natural LaxMonoidalFunctor.left_unitality
-- LaxMonoidalFunctor.right_unitality LaxMonoidalFunctor.associativity
section
variable {C D}
@[reassoc (attr := simp)]
theorem LaxMonoidalFunctor.μ_natural (F : LaxMonoidalFunctor C D) {X Y X' Y' : C}
(f : X ⟶ Y) (g : X' ⟶ Y') :
(F.map f ⊗ F.map g) ≫ F.μ Y Y' = F.μ X X' ≫ F.map (f ⊗ g) := by
simp [tensorHom_def]
/--
A constructor for lax monoidal functors whose axioms are described by `tensorHom` instead of
`whiskerLeft` and `whiskerRight`.
-/
@[simps]
def LaxMonoidalFunctor.ofTensorHom (F : C ⥤ D)
/- unit morphism -/
(ε : 𝟙_ D ⟶ F.obj (𝟙_ C))
/- tensorator -/
(μ : ∀ X Y : C, F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y))
(μ_natural :
∀ {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y'),
(F.map f ⊗ F.map g) ≫ μ Y Y' = μ X X' ≫ F.map (f ⊗ g) := by
aesop_cat)
/- associativity of the tensorator -/
(associativity :
∀ X Y Z : C,
(μ X Y ⊗ 𝟙 (F.obj Z)) ≫ μ (X ⊗ Y) Z ≫ F.map (α_ X Y Z).hom =
(α_ (F.obj X) (F.obj Y) (F.obj Z)).hom ≫ (𝟙 (F.obj X) ⊗ μ Y Z) ≫ μ X (Y ⊗ Z) := by
aesop_cat)
/- unitality -/
(left_unitality :
∀ X : C, (λ_ (F.obj X)).hom = (ε ⊗ 𝟙 (F.obj X)) ≫ μ (𝟙_ C) X ≫ F.map (λ_ X).hom := by
aesop_cat)
(right_unitality :
∀ X : C, (ρ_ (F.obj X)).hom = (𝟙 (F.obj X) ⊗ ε) ≫ μ X (𝟙_ C) ≫ F.map (ρ_ X).hom := by
aesop_cat) :
LaxMonoidalFunctor C D where
obj := F.obj
map := F.map
map_id := F.map_id
map_comp := F.map_comp
ε := ε
μ := μ
μ_natural_left := fun f X' => by
simp_rw [← tensorHom_id, ← F.map_id, μ_natural]
μ_natural_right := fun X' f => by
simp_rw [← id_tensorHom, ← F.map_id, μ_natural]
associativity := fun X Y Z => by
simp_rw [← tensorHom_id, ← id_tensorHom, associativity]
left_unitality := fun X => by
simp_rw [← tensorHom_id, left_unitality]
right_unitality := fun X => by
simp_rw [← id_tensorHom, right_unitality]
@[reassoc (attr := simp)]
| Mathlib/CategoryTheory/Monoidal/Functor.lean | 164 | 167 | theorem LaxMonoidalFunctor.left_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) :
(λ_ (F.obj X)).inv ≫ F.ε ▷ F.obj X ≫ F.μ (𝟙_ C) X = F.map (λ_ X).inv := by |
rw [Iso.inv_comp_eq, F.left_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp,
Iso.hom_inv_id, F.toFunctor.map_id, comp_id]
|
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Num.Lemmas
import Mathlib.Data.Nat.Prime
import Mathlib.Tactic.Ring
#align_import data.num.prime from "leanprover-community/mathlib"@"58581d0fe523063f5651df0619be2bf65012a94a"
/-!
# Primality for binary natural numbers
This file defines versions of `Nat.minFac` and `Nat.Prime` for `Num` and `PosNum`. As with other
`Num` definitions, they are not intended for general use (`Nat` should be used instead of `Num` in
most cases) but they can be used in contexts where kernel computation is required, such as proofs
by `rfl` and `decide`, as well as in `#reduce`.
The default decidable instance for `Nat.Prime` is optimized for VM evaluation, so it should be
preferred within `#eval` or in tactic execution, while for proofs the `norm_num` tactic can be used
to construct primality and non-primality proofs more efficiently than kernel computation.
Nevertheless, sometimes proof by computational reflection requires natural number computations, and
`Num` implements algorithms directly on binary natural numbers for this purpose.
-/
namespace PosNum
/-- Auxiliary function for computing the smallest prime factor of a `PosNum`. Unlike
`Nat.minFacAux`, we use a natural number `fuel` variable that is set to an upper bound on the
number of iterations. It is initialized to the number `n` we are determining primality for. Even
though this is exponential in the input (since it is a `Nat`, not a `Num`), it will get lazily
evaluated during kernel reduction, so we will only require about `sqrt n` unfoldings, for the
`sqrt n` iterations of the loop. -/
def minFacAux (n : PosNum) : ℕ → PosNum → PosNum
| 0, _ => n
| fuel + 1, k =>
if n < k.bit1 * k.bit1 then n else if k.bit1 ∣ n then k.bit1 else minFacAux n fuel k.succ
#align pos_num.min_fac_aux PosNum.minFacAux
set_option linter.deprecated false in
| Mathlib/Data/Num/Prime.lean | 44 | 54 | theorem minFacAux_to_nat {fuel : ℕ} {n k : PosNum} (h : Nat.sqrt n < fuel + k.bit1) :
(minFacAux n fuel k : ℕ) = Nat.minFacAux n k.bit1 := by |
induction' fuel with fuel ih generalizing k <;> rw [minFacAux, Nat.minFacAux]
· rw [Nat.zero_add, Nat.sqrt_lt] at h
simp only [h, ite_true]
simp_rw [← mul_to_nat]
simp only [cast_lt, dvd_to_nat]
split_ifs <;> try rfl
rw [ih] <;> [congr; convert Nat.lt_succ_of_lt h using 1] <;>
simp only [_root_.bit1, _root_.bit0, cast_bit1, cast_succ, Nat.succ_eq_add_one, add_assoc,
add_left_comm, ← one_add_one_eq_two]
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Analysis.Convex.Side
import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine
#align_import geometry.euclidean.angle.oriented.affine from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5"
/-!
# Oriented angles.
This file defines oriented angles in Euclidean affine spaces.
## Main definitions
* `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three
points.
-/
noncomputable section
open FiniteDimensional Complex
open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate
namespace EuclideanGeometry
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)]
/-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/
abbrev o := @Module.Oriented.positiveOrientation
/-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If
either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the
corresponding unoriented angle definition. -/
def oangle (p₁ p₂ p₃ : P) : Real.Angle :=
o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂)
#align euclidean_geometry.oangle EuclideanGeometry.oangle
@[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle
/-- Oriented angles are continuous when neither end point equals the middle point. -/
theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) :
ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by
let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1)
have hf1 : (f x).1 ≠ 0 := by simp [hx12]
have hf2 : (f x).2 ≠ 0 := by simp [hx32]
exact (o.continuousAt_oangle hf1 hf2).comp ((continuous_fst.vsub continuous_snd.fst).prod_mk
(continuous_snd.snd.vsub continuous_snd.fst)).continuousAt
#align euclidean_geometry.continuous_at_oangle EuclideanGeometry.continuousAt_oangle
/-- The angle ∡AAB at a point. -/
@[simp]
theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle]
#align euclidean_geometry.oangle_self_left EuclideanGeometry.oangle_self_left
/-- The angle ∡ABB at a point. -/
@[simp]
theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle]
#align euclidean_geometry.oangle_self_right EuclideanGeometry.oangle_self_right
/-- The angle ∡ABA at a point. -/
@[simp]
theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 :=
o.oangle_self _
#align euclidean_geometry.oangle_self_left_right EuclideanGeometry.oangle_self_left_right
/-- If the angle between three points is nonzero, the first two points are not equal. -/
theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by
rw [← @vsub_ne_zero V]; exact o.left_ne_zero_of_oangle_ne_zero h
#align euclidean_geometry.left_ne_of_oangle_ne_zero EuclideanGeometry.left_ne_of_oangle_ne_zero
/-- If the angle between three points is nonzero, the last two points are not equal. -/
theorem right_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₃ ≠ p₂ := by
rw [← @vsub_ne_zero V]; exact o.right_ne_zero_of_oangle_ne_zero h
#align euclidean_geometry.right_ne_of_oangle_ne_zero EuclideanGeometry.right_ne_of_oangle_ne_zero
/-- If the angle between three points is nonzero, the first and third points are not equal. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean | 85 | 86 | theorem left_ne_right_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₃ := by |
rw [← (vsub_left_injective p₂).ne_iff]; exact o.ne_of_oangle_ne_zero h
|
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Yury Kudryashov
-/
import Mathlib.Algebra.Star.Order
import Mathlib.Topology.Instances.NNReal
import Mathlib.Topology.Order.MonotoneContinuity
#align_import data.real.sqrt from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004"
/-!
# Square root of a real number
In this file we define
* `NNReal.sqrt` to be the square root of a nonnegative real number.
* `Real.sqrt` to be the square root of a real number, defined to be zero on negative numbers.
Then we prove some basic properties of these functions.
## Implementation notes
We define `NNReal.sqrt` as the noncomputable inverse to the function `x ↦ x * x`. We use general
theory of inverses of strictly monotone functions to prove that `NNReal.sqrt x` exists. As a side
effect, `NNReal.sqrt` is a bundled `OrderIso`, so for `NNReal` numbers we get continuity as well as
theorems like `NNReal.sqrt x ≤ y ↔ x ≤ y * y` for free.
Then we define `Real.sqrt x` to be `NNReal.sqrt (Real.toNNReal x)`.
## Tags
square root
-/
open Set Filter
open scoped Filter NNReal Topology
namespace NNReal
variable {x y : ℝ≥0}
/-- Square root of a nonnegative real number. -/
-- Porting note: was @[pp_nodot]
noncomputable def sqrt : ℝ≥0 ≃o ℝ≥0 :=
OrderIso.symm <| powOrderIso 2 two_ne_zero
#align nnreal.sqrt NNReal.sqrt
@[simp] lemma sq_sqrt (x : ℝ≥0) : sqrt x ^ 2 = x := sqrt.symm_apply_apply _
#align nnreal.sq_sqrt NNReal.sq_sqrt
@[simp] lemma sqrt_sq (x : ℝ≥0) : sqrt (x ^ 2) = x := sqrt.apply_symm_apply _
#align nnreal.sqrt_sq NNReal.sqrt_sq
@[simp] lemma mul_self_sqrt (x : ℝ≥0) : sqrt x * sqrt x = x := by rw [← sq, sq_sqrt]
#align nnreal.mul_self_sqrt NNReal.mul_self_sqrt
@[simp] lemma sqrt_mul_self (x : ℝ≥0) : sqrt (x * x) = x := by rw [← sq, sqrt_sq]
#align nnreal.sqrt_mul_self NNReal.sqrt_mul_self
lemma sqrt_le_sqrt : sqrt x ≤ sqrt y ↔ x ≤ y := sqrt.le_iff_le
#align nnreal.sqrt_le_sqrt_iff NNReal.sqrt_le_sqrt
lemma sqrt_lt_sqrt : sqrt x < sqrt y ↔ x < y := sqrt.lt_iff_lt
#align nnreal.sqrt_lt_sqrt_iff NNReal.sqrt_lt_sqrt
lemma sqrt_eq_iff_eq_sq : sqrt x = y ↔ x = y ^ 2 := sqrt.toEquiv.apply_eq_iff_eq_symm_apply
#align nnreal.sqrt_eq_iff_sq_eq NNReal.sqrt_eq_iff_eq_sq
lemma sqrt_le_iff_le_sq : sqrt x ≤ y ↔ x ≤ y ^ 2 := sqrt.to_galoisConnection _ _
#align nnreal.sqrt_le_iff NNReal.sqrt_le_iff_le_sq
lemma le_sqrt_iff_sq_le : x ≤ sqrt y ↔ x ^ 2 ≤ y := (sqrt.symm.to_galoisConnection _ _).symm
#align nnreal.le_sqrt_iff NNReal.le_sqrt_iff_sq_le
-- 2024-02-14
@[deprecated] alias sqrt_le_sqrt_iff := sqrt_le_sqrt
@[deprecated] alias sqrt_lt_sqrt_iff := sqrt_lt_sqrt
@[deprecated] alias sqrt_le_iff := sqrt_le_iff_le_sq
@[deprecated] alias le_sqrt_iff := le_sqrt_iff_sq_le
@[deprecated] alias sqrt_eq_iff_sq_eq := sqrt_eq_iff_eq_sq
@[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 := by simp [sqrt_eq_iff_eq_sq]
#align nnreal.sqrt_eq_zero NNReal.sqrt_eq_zero
@[simp] lemma sqrt_eq_one : sqrt x = 1 ↔ x = 1 := by simp [sqrt_eq_iff_eq_sq]
@[simp] lemma sqrt_zero : sqrt 0 = 0 := by simp
#align nnreal.sqrt_zero NNReal.sqrt_zero
@[simp] lemma sqrt_one : sqrt 1 = 1 := by simp
#align nnreal.sqrt_one NNReal.sqrt_one
@[simp] lemma sqrt_le_one : sqrt x ≤ 1 ↔ x ≤ 1 := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
@[simp] lemma one_le_sqrt : 1 ≤ sqrt x ↔ 1 ≤ x := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
theorem sqrt_mul (x y : ℝ≥0) : sqrt (x * y) = sqrt x * sqrt y := by
rw [sqrt_eq_iff_eq_sq, mul_pow, sq_sqrt, sq_sqrt]
#align nnreal.sqrt_mul NNReal.sqrt_mul
/-- `NNReal.sqrt` as a `MonoidWithZeroHom`. -/
noncomputable def sqrtHom : ℝ≥0 →*₀ ℝ≥0 :=
⟨⟨sqrt, sqrt_zero⟩, sqrt_one, sqrt_mul⟩
#align nnreal.sqrt_hom NNReal.sqrtHom
theorem sqrt_inv (x : ℝ≥0) : sqrt x⁻¹ = (sqrt x)⁻¹ :=
map_inv₀ sqrtHom x
#align nnreal.sqrt_inv NNReal.sqrt_inv
theorem sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y :=
map_div₀ sqrtHom x y
#align nnreal.sqrt_div NNReal.sqrt_div
@[continuity, fun_prop]
theorem continuous_sqrt : Continuous sqrt := sqrt.continuous
#align nnreal.continuous_sqrt NNReal.continuous_sqrt
@[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x := by simp [pos_iff_ne_zero]
alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos
end NNReal
namespace Real
/-- The square root of a real number. This returns 0 for negative inputs.
This has notation `√x`. Note that `√x⁻¹` is parsed as `√(x⁻¹)`. -/
noncomputable def sqrt (x : ℝ) : ℝ :=
NNReal.sqrt (Real.toNNReal x)
#align real.sqrt Real.sqrt
-- TODO: replace this with a typeclass
@[inherit_doc]
prefix:max "√" => Real.sqrt
/- quotient.lift_on x
(λ f, mk ⟨sqrt_aux f, (sqrt_aux_converges f).fst⟩)
(λ f g e, begin
rcases sqrt_aux_converges f with ⟨hf, x, x0, xf, xs⟩,
rcases sqrt_aux_converges g with ⟨hg, y, y0, yg, ys⟩,
refine xs.trans (eq.trans _ ys.symm),
rw [← @mul_self_inj_of_nonneg ℝ _ x y x0 y0, xf, yg],
congr' 1, exact quotient.sound e
end)-/
variable {x y : ℝ}
@[simp, norm_cast]
theorem coe_sqrt {x : ℝ≥0} : (NNReal.sqrt x : ℝ) = √(x : ℝ) := by
rw [Real.sqrt, Real.toNNReal_coe]
#align real.coe_sqrt Real.coe_sqrt
@[continuity]
theorem continuous_sqrt : Continuous (√· : ℝ → ℝ) :=
NNReal.continuous_coe.comp <| NNReal.continuous_sqrt.comp continuous_real_toNNReal
#align real.continuous_sqrt Real.continuous_sqrt
theorem sqrt_eq_zero_of_nonpos (h : x ≤ 0) : sqrt x = 0 := by simp [sqrt, Real.toNNReal_eq_zero.2 h]
#align real.sqrt_eq_zero_of_nonpos Real.sqrt_eq_zero_of_nonpos
theorem sqrt_nonneg (x : ℝ) : 0 ≤ √x :=
NNReal.coe_nonneg _
#align real.sqrt_nonneg Real.sqrt_nonneg
@[simp]
theorem mul_self_sqrt (h : 0 ≤ x) : √x * √x = x := by
rw [Real.sqrt, ← NNReal.coe_mul, NNReal.mul_self_sqrt, Real.coe_toNNReal _ h]
#align real.mul_self_sqrt Real.mul_self_sqrt
@[simp]
theorem sqrt_mul_self (h : 0 ≤ x) : √(x * x) = x :=
(mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _))
#align real.sqrt_mul_self Real.sqrt_mul_self
theorem sqrt_eq_cases : √x = y ↔ y * y = x ∧ 0 ≤ y ∨ x < 0 ∧ y = 0 := by
constructor
· rintro rfl
rcases le_or_lt 0 x with hle | hlt
· exact Or.inl ⟨mul_self_sqrt hle, sqrt_nonneg x⟩
· exact Or.inr ⟨hlt, sqrt_eq_zero_of_nonpos hlt.le⟩
· rintro (⟨rfl, hy⟩ | ⟨hx, rfl⟩)
exacts [sqrt_mul_self hy, sqrt_eq_zero_of_nonpos hx.le]
#align real.sqrt_eq_cases Real.sqrt_eq_cases
theorem sqrt_eq_iff_mul_self_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y * y = x :=
⟨fun h => by rw [← h, mul_self_sqrt hx], fun h => by rw [← h, sqrt_mul_self hy]⟩
#align real.sqrt_eq_iff_mul_self_eq Real.sqrt_eq_iff_mul_self_eq
theorem sqrt_eq_iff_mul_self_eq_of_pos (h : 0 < y) : √x = y ↔ y * y = x := by
simp [sqrt_eq_cases, h.ne', h.le]
#align real.sqrt_eq_iff_mul_self_eq_of_pos Real.sqrt_eq_iff_mul_self_eq_of_pos
@[simp]
theorem sqrt_eq_one : √x = 1 ↔ x = 1 :=
calc
√x = 1 ↔ 1 * 1 = x := sqrt_eq_iff_mul_self_eq_of_pos zero_lt_one
_ ↔ x = 1 := by rw [eq_comm, mul_one]
#align real.sqrt_eq_one Real.sqrt_eq_one
@[simp]
theorem sq_sqrt (h : 0 ≤ x) : √x ^ 2 = x := by rw [sq, mul_self_sqrt h]
#align real.sq_sqrt Real.sq_sqrt
@[simp]
theorem sqrt_sq (h : 0 ≤ x) : √(x ^ 2) = x := by rw [sq, sqrt_mul_self h]
#align real.sqrt_sq Real.sqrt_sq
theorem sqrt_eq_iff_sq_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y ^ 2 = x := by
rw [sq, sqrt_eq_iff_mul_self_eq hx hy]
#align real.sqrt_eq_iff_sq_eq Real.sqrt_eq_iff_sq_eq
theorem sqrt_mul_self_eq_abs (x : ℝ) : √(x * x) = |x| := by
rw [← abs_mul_abs_self x, sqrt_mul_self (abs_nonneg _)]
#align real.sqrt_mul_self_eq_abs Real.sqrt_mul_self_eq_abs
theorem sqrt_sq_eq_abs (x : ℝ) : √(x ^ 2) = |x| := by rw [sq, sqrt_mul_self_eq_abs]
#align real.sqrt_sq_eq_abs Real.sqrt_sq_eq_abs
@[simp]
theorem sqrt_zero : √0 = 0 := by simp [Real.sqrt]
#align real.sqrt_zero Real.sqrt_zero
@[simp]
theorem sqrt_one : √1 = 1 := by simp [Real.sqrt]
#align real.sqrt_one Real.sqrt_one
@[simp]
theorem sqrt_le_sqrt_iff (hy : 0 ≤ y) : √x ≤ √y ↔ x ≤ y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt, toNNReal_le_toNNReal_iff hy]
#align real.sqrt_le_sqrt_iff Real.sqrt_le_sqrt_iff
@[simp]
theorem sqrt_lt_sqrt_iff (hx : 0 ≤ x) : √x < √y ↔ x < y :=
lt_iff_lt_of_le_iff_le (sqrt_le_sqrt_iff hx)
#align real.sqrt_lt_sqrt_iff Real.sqrt_lt_sqrt_iff
theorem sqrt_lt_sqrt_iff_of_pos (hy : 0 < y) : √x < √y ↔ x < y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_lt_coe, NNReal.sqrt_lt_sqrt, toNNReal_lt_toNNReal_iff hy]
#align real.sqrt_lt_sqrt_iff_of_pos Real.sqrt_lt_sqrt_iff_of_pos
@[gcongr]
theorem sqrt_le_sqrt (h : x ≤ y) : √x ≤ √y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt]
exact toNNReal_le_toNNReal h
#align real.sqrt_le_sqrt Real.sqrt_le_sqrt
@[gcongr]
theorem sqrt_lt_sqrt (hx : 0 ≤ x) (h : x < y) : √x < √y :=
(sqrt_lt_sqrt_iff hx).2 h
#align real.sqrt_lt_sqrt Real.sqrt_lt_sqrt
| Mathlib/Data/Real/Sqrt.lean | 252 | 254 | theorem sqrt_le_left (hy : 0 ≤ y) : √x ≤ y ↔ x ≤ y ^ 2 := by |
rw [sqrt, ← Real.le_toNNReal_iff_coe_le hy, NNReal.sqrt_le_iff_le_sq, sq, ← Real.toNNReal_mul hy,
Real.toNNReal_le_toNNReal_iff (mul_self_nonneg y), sq]
|
/-
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
| Mathlib/MeasureTheory/Measure/FiniteMeasure.lean | 207 | 209 | theorem mass_nonzero_iff (μ : FiniteMeasure Ω) : μ.mass ≠ 0 ↔ μ ≠ 0 := by |
rw [not_iff_not]
exact FiniteMeasure.mass_zero_iff μ
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.SetToL1
#align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
/-!
# Bochner integral
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined through the extension process described in the file `SetToL1`,
which follows these steps:
1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`.
`weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive`
(defined in the file `SetToL1`) with respect to the set `s`.
2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`)
where `E` is a real normed space. (See `SimpleFunc.integral` for details.)
3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation :
`α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear
map from `α →₁ₛ[μ] E` to `E`.
4. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of
`α →₁ₛ[μ] E` into `α →₁[μ] E` is dense.
5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1
space, if it is in L1, and 0 otherwise.
The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to
`setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral
(like linearity) are particular cases of the properties of `setToFun` (which are described in the
file `SetToL1`).
## Main statements
1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure
space and `E` is a real normed space.
* `integral_zero` : `∫ 0 ∂μ = 0`
* `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ`
* `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ`
* `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ`
* `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ`
* `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ`
* `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ`
2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure
space.
* `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
* `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions,
which is called `lintegral` and has the notation `∫⁻`.
* `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` :
`∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`,
where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ`
4. (In the file `DominatedConvergence`)
`tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
5. (In the file `SetIntegral`) integration commutes with continuous linear maps.
* `ContinuousLinearMap.integral_comp_comm`
* `LinearIsometry.integral_comp_comm`
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one
of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove
something for an arbitrary integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves
that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued
function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part`
is scattered in sections with the name `posPart`.
Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all
functions :
1. First go to the `L¹` space.
For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of
`f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`.
3. Show that the property holds for all simple functions `s` in `L¹` space.
Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas
like `L1.integral_coe_eq_integral`.
4. Since simple functions are dense in `L¹`,
```
univ = closure {s simple}
= closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions
⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}
= {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself
```
Use `isClosed_property` or `DenseRange.induction_on` for this argument.
## Notations
* `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`)
* `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`MeasureTheory/LpSpace`)
* `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple
functions (defined in `MeasureTheory/SimpleFuncDense`)
* `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ`
* `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type
We also define notations for integral on a set, which are described in the file
`MeasureTheory/SetIntegral`.
Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
assert_not_exists Differentiable
noncomputable section
open scoped Topology NNReal ENNReal MeasureTheory
open Set Filter TopologicalSpace ENNReal EMetric
namespace MeasureTheory
variable {α E F 𝕜 : Type*}
section WeightedSMul
open ContinuousLinearMap
variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α}
/-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension
of that set function through `setToL1` gives the Bochner integral of L1 functions. -/
def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F :=
(μ s).toReal • ContinuousLinearMap.id ℝ F
#align measure_theory.weighted_smul MeasureTheory.weightedSMul
theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) :
weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul]
#align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply
@[simp]
theorem weightedSMul_zero_measure {m : MeasurableSpace α} :
weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul]
#align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure
@[simp]
theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) :
weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp
#align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty
theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α}
(hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) :
(weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by
ext1 x
push_cast
simp_rw [Pi.add_apply, weightedSMul_apply]
push_cast
rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul]
#align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure
theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} :
(weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by
ext1 x
push_cast
simp_rw [Pi.smul_apply, weightedSMul_apply]
push_cast
simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul]
#align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure
theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) :
(weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by
ext1 x; simp_rw [weightedSMul_apply]; congr 2
#align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr
theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by
ext1 x; rw [weightedSMul_apply, h_zero]; simp
#align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null
theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞)
(ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by
ext1 x
simp_rw [add_apply, weightedSMul_apply,
measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht,
ENNReal.toReal_add hs_finite ht_finite, add_smul]
#align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union'
@[nolint unusedArguments]
theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t :=
weightedSMul_union' s t ht hs_finite ht_finite h_inter
#align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union
theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜)
(s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by
simp_rw [weightedSMul_apply, smul_comm]
#align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul
theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal :=
calc
‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ :=
norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F)
_ ≤ ‖(μ s).toReal‖ :=
((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le)
_ = abs (μ s).toReal := Real.norm_eq_abs _
_ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg
#align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le
theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) :
DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 :=
⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩
#align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul
theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by
simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply]
exact mul_nonneg toReal_nonneg hx
#align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg
end WeightedSMul
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
section PosPart
variable [LinearOrder E] [Zero E] [MeasurableSpace α]
/-- Positive part of a simple function. -/
def posPart (f : α →ₛ E) : α →ₛ E :=
f.map fun b => max b 0
#align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart
/-- Negative part of a simple function. -/
def negPart [Neg E] (f : α →ₛ E) : α →ₛ E :=
posPart (-f)
#align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart
theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by
ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _
#align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm
theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by
rw [negPart]; exact posPart_map_norm _
#align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm
theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by
simp only [posPart, negPart]
ext a
rw [coe_sub]
exact max_zero_sub_eq_self (f a)
#align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart
end PosPart
section Integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group,
and prove basic property of this integral.
-/
open Finset
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*}
[NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α}
{μ : Measure α}
/-- Bochner integral of simple functions whose codomain is a real `NormedSpace`.
This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/
def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F :=
f.setToSimpleFunc (weightedSMul μ)
#align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral
theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl
#align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def
theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by
simp [integral, setToSimpleFunc, weightedSMul_apply]
#align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq
theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α}
(f : α →ₛ F) (μ : Measure α) :
f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by
rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr
#align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter
/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/
theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F}
(hs : (f.range.filter fun x => x ≠ 0) ⊆ s) :
f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by
rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs]
rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx
-- Porting note: reordered for clarity
rcases hx.symm with (rfl | hx)
· simp
rw [SimpleFunc.mem_range] at hx
-- Porting note: added
simp only [Set.mem_range, not_exists] at hx
rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx]
#align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset
@[simp]
theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) :
(const α y).integral μ = (μ univ).toReal • y := by
classical
calc
(const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z :=
integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _)
_ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage`
#align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const
@[simp]
theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α}
(hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by
classical
refine (integral_eq_sum_of_subset ?_).trans
((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm)
· intro y hy
simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,
mem_range_indicator] at *
rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩
exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩]
· dsimp
rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem,
Measure.restrict_apply (f.measurableSet_preimage _)]
exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀)
#align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero
/-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/
theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) :
(f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x :=
map_setToSimpleFunc _ weightedSMul_union hf hg
#align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral
/-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0)
(ht : ∀ b, g b ≠ ∞) :
(f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by
have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf
simp only [← map_apply g f, lintegral_eq_lintegral]
rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum]
· refine Finset.sum_congr rfl fun b _ => ?_
-- Porting note: added `Function.comp_apply`
rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply]
· rintro a -
by_cases a0 : a = 0
· rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top
· apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne
· simp [hg0]
#align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral'
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E]
theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) :
f.integral μ = g.integral μ :=
setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h
#align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr
/-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/
theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) :
f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by
have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) :=
h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm
rw [← integral_eq_lintegral' hf]
exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top]
#align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral
theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f + g) = integral μ f + integral μ g :=
setToSimpleFunc_add _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add
theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f :=
setToSimpleFunc_neg _ weightedSMul_union hf
#align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg
theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f - g) = integral μ f - integral μ g :=
setToSimpleFunc_sub _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub
theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) :
integral μ (c • f) = c • integral μ f :=
setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf
#align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul
theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E}
(hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ :=
calc
‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ :=
norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf
_ = C * (f.map norm).integral μ := by
rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul]
#align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm
theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) :
‖f.integral μ‖ ≤ (f.map norm).integral μ := by
refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le
exact (norm_weightedSMul_le s).trans (one_mul _).symm.le
#align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm
theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) :
f.integral (μ + ν) = f.integral μ + f.integral ν := by
simp_rw [integral_def]
refine setToSimpleFunc_add_left'
(weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf
rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs
rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2]
#align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure
end Integral
end SimpleFunc
namespace L1
set_option linter.uppercaseLean3 false -- `L1`
open AEEqFun Lp.simpleFunc Lp
variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α}
namespace SimpleFunc
theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by
rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero]
simp_rw [smul_eq_mul]
#align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral
section PosPart
/-- Positive part of a simple function in L1 space. -/
nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
⟨Lp.posPart (f : α →₁[μ] ℝ), by
rcases f with ⟨f, s, hsf⟩
use s.posPart
simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk,
SimpleFunc.coe_map, mk_eq_mk]
-- Porting note: added
simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩
#align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart
/-- Negative part of a simple function in L1 space. -/
def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
posPart (-f)
#align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart
@[norm_cast]
theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart
@[norm_cast]
theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart
end PosPart
section SimpleFuncIntegral
/-!
### The Bochner integral of `L1`
Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`,
and prove basic properties of this integral. -/
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*}
[NormedAddCommGroup F'] [NormedSpace ℝ F']
attribute [local instance] simpleFunc.normedSpace
/-- The Bochner integral over simple functions in L1 space. -/
def integral (f : α →₁ₛ[μ] E) : E :=
(toSimpleFunc f).integral μ
#align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral
theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl
#align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral
nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) :
integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by
rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos]
#align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral
theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl
#align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S
nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
integral f = integral g :=
SimpleFunc.integral_congr (SimpleFunc.integrable f) h
#align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr
theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g :=
setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _
#align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add
theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f :=
setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f
#align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul
theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by
rw [integral, norm_eq_integral]
exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f)
#align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm
variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E']
variable (α E μ 𝕜)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/
def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E :=
LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f =>
le_trans (norm_integral_le_norm _) <| by rw [one_mul]
#align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM'
/-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E :=
integralCLM' α E ℝ μ
#align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM
variable {α E μ 𝕜}
local notation "Integral" => integralCLM α E μ
open ContinuousLinearMap
theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 :=
-- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _`
LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by
rw [one_mul]
exact norm_integral_le_norm f)
#align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one
section PosPart
theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by
have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl
have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by
filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ),
toSimpleFunc_eq_toFun f] with _ _ h₂ h₃
convert h₂ using 1
-- Porting note: added
rw [h₃]
refine ae_eq.mono fun a h => ?_
rw [h, eq]
#align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc
theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by
rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart]
filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f]
intro a h₁ h₂
rw [h₁]
show max _ _ = max _ _
rw [h₂]
rfl
#align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc
theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by
filter_upwards [posPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply]
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by
filter_upwards [negPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply]
rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub]
· show (toSimpleFunc f).integral μ =
((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ
apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f)
filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂
show _ = _ - _
rw [← h₁, ← h₂]
have := (toSimpleFunc f).posPart_sub_negPart
conv_lhs => rw [← this]
rfl
· exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁
· exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂
#align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub
end PosPart
end SimpleFuncIntegral
end SimpleFunc
open SimpleFunc
local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _
variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E]
[NormedSpace ℝ F] [CompleteSpace E]
section IntegrationInL1
attribute [local instance] simpleFunc.normedSpace
open ContinuousLinearMap
variable (𝕜)
/-- The Bochner integral in L1 space as a continuous linear map. -/
nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E :=
(integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.uniformInducing
#align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM'
variable {𝕜}
/-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁[μ] E) →L[ℝ] E :=
integralCLM' ℝ
#align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM
-- Porting note: added `(E := E)` in several places below.
/-- The Bochner integral in L1 space -/
irreducible_def integral (f : α →₁[μ] E) : E :=
integralCLM (E := E) f
#align measure_theory.L1.integral MeasureTheory.L1.integral
theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by
simp only [integral]
#align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq
theorem integral_eq_setToL1 (f : α →₁[μ] E) :
integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral]; rfl
#align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1
@[norm_cast]
theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) :
L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by
simp only [integral, L1.integral]
exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f
#align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral
variable (α E)
@[simp]
theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by
simp only [integral]
exact map_zero integralCLM
#align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero
variable {α E}
@[integral_simps]
theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by
simp only [integral]
exact map_add integralCLM f g
#align measure_theory.L1.integral_add MeasureTheory.L1.integral_add
@[integral_simps]
theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by
simp only [integral]
exact map_neg integralCLM f
#align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg
@[integral_simps]
theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by
simp only [integral]
exact map_sub integralCLM f g
#align measure_theory.L1.integral_sub MeasureTheory.L1.integral_sub
@[integral_simps]
theorem integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := by
simp only [integral]
show (integralCLM' (E := E) 𝕜) (c • f) = c • (integralCLM' (E := E) 𝕜) f
exact map_smul (integralCLM' (E := E) 𝕜) c f
#align measure_theory.L1.integral_smul MeasureTheory.L1.integral_smul
local notation "Integral" => @integralCLM α E _ _ μ _ _
local notation "sIntegral" => @SimpleFunc.integralCLM α E _ _ μ _
theorem norm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖ ≤ 1 :=
norm_setToL1_le (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one
#align measure_theory.L1.norm_Integral_le_one MeasureTheory.L1.norm_Integral_le_one
theorem nnnorm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖₊ ≤ 1 :=
norm_Integral_le_one
theorem norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ :=
calc
‖integral f‖ = ‖integralCLM (E := E) f‖ := by simp only [integral]
_ ≤ ‖integralCLM (α := α) (E := E) (μ := μ)‖ * ‖f‖ := le_opNorm _ _
_ ≤ 1 * ‖f‖ := mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _
_ = ‖f‖ := one_mul _
#align measure_theory.L1.norm_integral_le MeasureTheory.L1.norm_integral_le
theorem nnnorm_integral_le (f : α →₁[μ] E) : ‖integral f‖₊ ≤ ‖f‖₊ :=
norm_integral_le f
@[continuity]
theorem continuous_integral : Continuous fun f : α →₁[μ] E => integral f := by
simp only [integral]
exact L1.integralCLM.continuous
#align measure_theory.L1.continuous_integral MeasureTheory.L1.continuous_integral
section PosPart
theorem integral_eq_norm_posPart_sub (f : α →₁[μ] ℝ) :
integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖ := by
-- Use `isClosed_property` and `isClosed_eq`
refine @isClosed_property _ _ _ ((↑) : (α →₁ₛ[μ] ℝ) → α →₁[μ] ℝ)
(fun f : α →₁[μ] ℝ => integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖)
(simpleFunc.denseRange one_ne_top) (isClosed_eq ?_ ?_) ?_ f
· simp only [integral]
exact cont _
· refine Continuous.sub (continuous_norm.comp Lp.continuous_posPart)
(continuous_norm.comp Lp.continuous_negPart)
-- Show that the property holds for all simple functions in the `L¹` space.
· intro s
norm_cast
exact SimpleFunc.integral_eq_norm_posPart_sub _
#align measure_theory.L1.integral_eq_norm_pos_part_sub MeasureTheory.L1.integral_eq_norm_posPart_sub
end PosPart
end IntegrationInL1
end L1
/-!
## The Bochner integral on functions
Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable
functions, and 0 otherwise; prove its basic properties.
-/
variable [NormedAddCommGroup E] [NormedSpace ℝ E] [hE : CompleteSpace E] [NontriviallyNormedField 𝕜]
[NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F]
{G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G]
section
open scoped Classical
/-- The Bochner integral -/
irreducible_def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α → G) : G :=
if _ : CompleteSpace G then
if hf : Integrable f μ then L1.integral (hf.toL1 f) else 0
else 0
#align measure_theory.integral MeasureTheory.integral
end
/-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly,
and needs parentheses. We do not set the binding power of `r` to `0`, because then
`∫ x, f x = 0` will be parsed incorrectly. -/
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => integral μ r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)", "r:60:(scoped f => integral volume f) => r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => integral (Measure.restrict μ s) r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)" in "s", "r:60:(scoped f => integral (Measure.restrict volume s) f) => r
section Properties
open ContinuousLinearMap MeasureTheory.SimpleFunc
variable {f g : α → E} {m : MeasurableSpace α} {μ : Measure α}
theorem integral_eq (f : α → E) (hf : Integrable f μ) : ∫ a, f a ∂μ = L1.integral (hf.toL1 f) := by
simp [integral, hE, hf]
#align measure_theory.integral_eq MeasureTheory.integral_eq
theorem integral_eq_setToFun (f : α → E) :
∫ a, f a ∂μ = setToFun μ (weightedSMul μ) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral, hE, L1.integral]; rfl
#align measure_theory.integral_eq_set_to_fun MeasureTheory.integral_eq_setToFun
theorem L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ := by
simp only [integral, L1.integral, integral_eq_setToFun]
exact (L1.setToFun_eq_setToL1 (dominatedFinMeasAdditive_weightedSMul μ) f).symm
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.integral_eq_integral MeasureTheory.L1.integral_eq_integral
theorem integral_undef {f : α → G} (h : ¬Integrable f μ) : ∫ a, f a ∂μ = 0 := by
by_cases hG : CompleteSpace G
· simp [integral, hG, h]
· simp [integral, hG]
#align measure_theory.integral_undef MeasureTheory.integral_undef
theorem Integrable.of_integral_ne_zero {f : α → G} (h : ∫ a, f a ∂μ ≠ 0) : Integrable f μ :=
Not.imp_symm integral_undef h
theorem integral_non_aestronglyMeasurable {f : α → G} (h : ¬AEStronglyMeasurable f μ) :
∫ a, f a ∂μ = 0 :=
integral_undef <| not_and_of_not_left _ h
#align measure_theory.integral_non_ae_strongly_measurable MeasureTheory.integral_non_aestronglyMeasurable
variable (α G)
@[simp]
theorem integral_zero : ∫ _ : α, (0 : G) ∂μ = 0 := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_zero (dominatedFinMeasAdditive_weightedSMul μ)
· simp [integral, hG]
#align measure_theory.integral_zero MeasureTheory.integral_zero
@[simp]
theorem integral_zero' : integral μ (0 : α → G) = 0 :=
integral_zero α G
#align measure_theory.integral_zero' MeasureTheory.integral_zero'
variable {α G}
theorem integrable_of_integral_eq_one {f : α → ℝ} (h : ∫ x, f x ∂μ = 1) : Integrable f μ :=
.of_integral_ne_zero <| h ▸ one_ne_zero
#align measure_theory.integrable_of_integral_eq_one MeasureTheory.integrable_of_integral_eq_one
theorem integral_add {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_add (dominatedFinMeasAdditive_weightedSMul μ) hf hg
· simp [integral, hG]
#align measure_theory.integral_add MeasureTheory.integral_add
theorem integral_add' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
integral_add hf hg
#align measure_theory.integral_add' MeasureTheory.integral_add'
theorem integral_finset_sum {ι} (s : Finset ι) {f : ι → α → G} (hf : ∀ i ∈ s, Integrable (f i) μ) :
∫ a, ∑ i ∈ s, f i a ∂μ = ∑ i ∈ s, ∫ a, f i a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_finset_sum (dominatedFinMeasAdditive_weightedSMul _) s hf
· simp [integral, hG]
#align measure_theory.integral_finset_sum MeasureTheory.integral_finset_sum
@[integral_simps]
theorem integral_neg (f : α → G) : ∫ a, -f a ∂μ = -∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_neg (dominatedFinMeasAdditive_weightedSMul μ) f
· simp [integral, hG]
#align measure_theory.integral_neg MeasureTheory.integral_neg
theorem integral_neg' (f : α → G) : ∫ a, (-f) a ∂μ = -∫ a, f a ∂μ :=
integral_neg f
#align measure_theory.integral_neg' MeasureTheory.integral_neg'
theorem integral_sub {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, f a - g a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_sub (dominatedFinMeasAdditive_weightedSMul μ) hf hg
· simp [integral, hG]
#align measure_theory.integral_sub MeasureTheory.integral_sub
theorem integral_sub' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, (f - g) a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ :=
integral_sub hf hg
#align measure_theory.integral_sub' MeasureTheory.integral_sub'
@[integral_simps]
theorem integral_smul [NormedSpace 𝕜 G] [SMulCommClass ℝ 𝕜 G] (c : 𝕜) (f : α → G) :
∫ a, c • f a ∂μ = c • ∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_smul (dominatedFinMeasAdditive_weightedSMul μ) weightedSMul_smul c f
· simp [integral, hG]
#align measure_theory.integral_smul MeasureTheory.integral_smul
theorem integral_mul_left {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, r * f a ∂μ = r * ∫ a, f a ∂μ :=
integral_smul r f
#align measure_theory.integral_mul_left MeasureTheory.integral_mul_left
theorem integral_mul_right {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, f a * r ∂μ = (∫ a, f a ∂μ) * r := by
simp only [mul_comm]; exact integral_mul_left r f
#align measure_theory.integral_mul_right MeasureTheory.integral_mul_right
theorem integral_div {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, f a / r ∂μ = (∫ a, f a ∂μ) / r := by
simpa only [← div_eq_mul_inv] using integral_mul_right r⁻¹ f
#align measure_theory.integral_div MeasureTheory.integral_div
theorem integral_congr_ae {f g : α → G} (h : f =ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_congr_ae (dominatedFinMeasAdditive_weightedSMul μ) h
· simp [integral, hG]
#align measure_theory.integral_congr_ae MeasureTheory.integral_congr_ae
-- Porting note: `nolint simpNF` added because simplify fails on left-hand side
@[simp, nolint simpNF]
theorem L1.integral_of_fun_eq_integral {f : α → G} (hf : Integrable f μ) :
∫ a, (hf.toL1 f) a ∂μ = ∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [MeasureTheory.integral, hG, L1.integral]
exact setToFun_toL1 (dominatedFinMeasAdditive_weightedSMul μ) hf
· simp [MeasureTheory.integral, hG]
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.integral_of_fun_eq_integral MeasureTheory.L1.integral_of_fun_eq_integral
@[continuity]
theorem continuous_integral : Continuous fun f : α →₁[μ] G => ∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuous_setToFun (dominatedFinMeasAdditive_weightedSMul μ)
· simp [integral, hG, continuous_const]
#align measure_theory.continuous_integral MeasureTheory.continuous_integral
theorem norm_integral_le_lintegral_norm (f : α → G) :
‖∫ a, f a ∂μ‖ ≤ ENNReal.toReal (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) := by
by_cases hG : CompleteSpace G
· by_cases hf : Integrable f μ
· rw [integral_eq f hf, ← Integrable.norm_toL1_eq_lintegral_norm f hf]
exact L1.norm_integral_le _
· rw [integral_undef hf, norm_zero]; exact toReal_nonneg
· simp [integral, hG]
#align measure_theory.norm_integral_le_lintegral_norm MeasureTheory.norm_integral_le_lintegral_norm
theorem ennnorm_integral_le_lintegral_ennnorm (f : α → G) :
(‖∫ a, f a ∂μ‖₊ : ℝ≥0∞) ≤ ∫⁻ a, ‖f a‖₊ ∂μ := by
simp_rw [← ofReal_norm_eq_coe_nnnorm]
apply ENNReal.ofReal_le_of_le_toReal
exact norm_integral_le_lintegral_norm f
#align measure_theory.ennnorm_integral_le_lintegral_ennnorm MeasureTheory.ennnorm_integral_le_lintegral_ennnorm
theorem integral_eq_zero_of_ae {f : α → G} (hf : f =ᵐ[μ] 0) : ∫ a, f a ∂μ = 0 := by
simp [integral_congr_ae hf, integral_zero]
#align measure_theory.integral_eq_zero_of_ae MeasureTheory.integral_eq_zero_of_ae
/-- If `f` has finite integral, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
theorem HasFiniteIntegral.tendsto_setIntegral_nhds_zero {ι} {f : α → G}
(hf : HasFiniteIntegral f μ) {l : Filter ι} {s : ι → Set α} (hs : Tendsto (μ ∘ s) l (𝓝 0)) :
Tendsto (fun i => ∫ x in s i, f x ∂μ) l (𝓝 0) := by
rw [tendsto_zero_iff_norm_tendsto_zero]
simp_rw [← coe_nnnorm, ← NNReal.coe_zero, NNReal.tendsto_coe, ← ENNReal.tendsto_coe,
ENNReal.coe_zero]
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
(tendsto_set_lintegral_zero (ne_of_lt hf) hs) (fun i => zero_le _)
fun i => ennnorm_integral_le_lintegral_ennnorm _
#align measure_theory.has_finite_integral.tendsto_set_integral_nhds_zero MeasureTheory.HasFiniteIntegral.tendsto_setIntegral_nhds_zero
@[deprecated (since := "2024-04-17")]
alias HasFiniteIntegral.tendsto_set_integral_nhds_zero :=
HasFiniteIntegral.tendsto_setIntegral_nhds_zero
/-- If `f` is integrable, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
theorem Integrable.tendsto_setIntegral_nhds_zero {ι} {f : α → G} (hf : Integrable f μ)
{l : Filter ι} {s : ι → Set α} (hs : Tendsto (μ ∘ s) l (𝓝 0)) :
Tendsto (fun i => ∫ x in s i, f x ∂μ) l (𝓝 0) :=
hf.2.tendsto_setIntegral_nhds_zero hs
#align measure_theory.integrable.tendsto_set_integral_nhds_zero MeasureTheory.Integrable.tendsto_setIntegral_nhds_zero
@[deprecated (since := "2024-04-17")]
alias Integrable.tendsto_set_integral_nhds_zero :=
Integrable.tendsto_setIntegral_nhds_zero
/-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/
theorem tendsto_integral_of_L1 {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ)
(hF : Tendsto (fun i => ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0)) :
Tendsto (fun i => ∫ x, F i x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact tendsto_setToFun_of_L1 (dominatedFinMeasAdditive_weightedSMul μ) f hfi hFi hF
· simp [integral, hG, tendsto_const_nhds]
set_option linter.uppercaseLean3 false in
#align measure_theory.tendsto_integral_of_L1 MeasureTheory.tendsto_integral_of_L1
/-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/
lemma tendsto_integral_of_L1' {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ snorm (F i - f) 1 μ) l (𝓝 0)) :
Tendsto (fun i ↦ ∫ x, F i x ∂μ) l (𝓝 (∫ x, f x ∂μ)) := by
refine tendsto_integral_of_L1 f hfi hFi ?_
simp_rw [snorm_one_eq_lintegral_nnnorm, Pi.sub_apply] at hF
exact hF
/-- If `F i → f` in `L1`, then `∫ x in s, F i x ∂μ → ∫ x in s, f x ∂μ`. -/
lemma tendsto_setIntegral_of_L1 {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G}
{l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0))
(s : Set α) :
Tendsto (fun i ↦ ∫ x in s, F i x ∂μ) l (𝓝 (∫ x in s, f x ∂μ)) := by
refine tendsto_integral_of_L1 f hfi.restrict ?_ ?_
· filter_upwards [hFi] with i hi using hi.restrict
· simp_rw [← snorm_one_eq_lintegral_nnnorm] at hF ⊢
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hF (fun _ ↦ zero_le')
(fun _ ↦ snorm_mono_measure _ Measure.restrict_le_self)
@[deprecated (since := "2024-04-17")]
alias tendsto_set_integral_of_L1 := tendsto_setIntegral_of_L1
/-- If `F i → f` in `L1`, then `∫ x in s, F i x ∂μ → ∫ x in s, f x ∂μ`. -/
lemma tendsto_setIntegral_of_L1' {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G}
{l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ snorm (F i - f) 1 μ) l (𝓝 0))
(s : Set α) :
Tendsto (fun i ↦ ∫ x in s, F i x ∂μ) l (𝓝 (∫ x in s, f x ∂μ)) := by
refine tendsto_setIntegral_of_L1 f hfi hFi ?_ s
simp_rw [snorm_one_eq_lintegral_nnnorm, Pi.sub_apply] at hF
exact hF
@[deprecated (since := "2024-04-17")]
alias tendsto_set_integral_of_L1' := tendsto_setIntegral_of_L1'
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
theorem continuousWithinAt_of_dominated {F : X → α → G} {x₀ : X} {bound : α → ℝ} {s : Set X}
(hF_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (F x) μ)
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousWithinAt (fun x => F x a) s x₀) :
ContinuousWithinAt (fun x => ∫ a, F x a ∂μ) s x₀ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuousWithinAt_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuousWithinAt_const]
#align measure_theory.continuous_within_at_of_dominated MeasureTheory.continuousWithinAt_of_dominated
theorem continuousAt_of_dominated {F : X → α → G} {x₀ : X} {bound : α → ℝ}
(hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousAt (fun x => F x a) x₀) :
ContinuousAt (fun x => ∫ a, F x a ∂μ) x₀ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuousAt_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuousAt_const]
#align measure_theory.continuous_at_of_dominated MeasureTheory.continuousAt_of_dominated
theorem continuousOn_of_dominated {F : X → α → G} {bound : α → ℝ} {s : Set X}
(hF_meas : ∀ x ∈ s, AEStronglyMeasurable (F x) μ)
(h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousOn (fun x => F x a) s) :
ContinuousOn (fun x => ∫ a, F x a ∂μ) s := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuousOn_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuousOn_const]
#align measure_theory.continuous_on_of_dominated MeasureTheory.continuousOn_of_dominated
theorem continuous_of_dominated {F : X → α → G} {bound : α → ℝ}
(hF_meas : ∀ x, AEStronglyMeasurable (F x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a)
(bound_integrable : Integrable bound μ) (h_cont : ∀ᵐ a ∂μ, Continuous fun x => F x a) :
Continuous fun x => ∫ a, F x a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuous_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuous_const]
#align measure_theory.continuous_of_dominated MeasureTheory.continuous_of_dominated
/-- The Bochner integral of a real-valued function `f : α → ℝ` is the difference between the
integral of the positive part of `f` and the integral of the negative part of `f`. -/
theorem integral_eq_lintegral_pos_part_sub_lintegral_neg_part {f : α → ℝ} (hf : Integrable f μ) :
∫ a, f a ∂μ =
ENNReal.toReal (∫⁻ a, .ofReal (f a) ∂μ) - ENNReal.toReal (∫⁻ a, .ofReal (-f a) ∂μ) := by
let f₁ := hf.toL1 f
-- Go to the `L¹` space
have eq₁ : ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) = ‖Lp.posPart f₁‖ := by
rw [L1.norm_def]
congr 1
apply lintegral_congr_ae
filter_upwards [Lp.coeFn_posPart f₁, hf.coeFn_toL1] with _ h₁ h₂
rw [h₁, h₂, ENNReal.ofReal]
congr 1
apply NNReal.eq
rw [Real.nnnorm_of_nonneg (le_max_right _ _)]
rw [Real.coe_toNNReal', NNReal.coe_mk]
-- Go to the `L¹` space
have eq₂ : ENNReal.toReal (∫⁻ a, ENNReal.ofReal (-f a) ∂μ) = ‖Lp.negPart f₁‖ := by
rw [L1.norm_def]
congr 1
apply lintegral_congr_ae
filter_upwards [Lp.coeFn_negPart f₁, hf.coeFn_toL1] with _ h₁ h₂
rw [h₁, h₂, ENNReal.ofReal]
congr 1
apply NNReal.eq
simp only [Real.coe_toNNReal', coe_nnnorm, nnnorm_neg]
rw [Real.norm_of_nonpos (min_le_right _ _), ← max_neg_neg, neg_zero]
rw [eq₁, eq₂, integral, dif_pos, dif_pos]
exact L1.integral_eq_norm_posPart_sub _
#align measure_theory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part MeasureTheory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part
theorem integral_eq_lintegral_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f)
(hfm : AEStronglyMeasurable f μ) :
∫ a, f a ∂μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by
by_cases hfi : Integrable f μ
· rw [integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi]
have h_min : ∫⁻ a, ENNReal.ofReal (-f a) ∂μ = 0 := by
rw [lintegral_eq_zero_iff']
· refine hf.mono ?_
simp only [Pi.zero_apply]
intro a h
simp only [h, neg_nonpos, ofReal_eq_zero]
· exact measurable_ofReal.comp_aemeasurable hfm.aemeasurable.neg
rw [h_min, zero_toReal, _root_.sub_zero]
· rw [integral_undef hfi]
simp_rw [Integrable, hfm, hasFiniteIntegral_iff_norm, lt_top_iff_ne_top, Ne, true_and_iff,
Classical.not_not] at hfi
have : ∫⁻ a : α, ENNReal.ofReal (f a) ∂μ = ∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ := by
refine lintegral_congr_ae (hf.mono fun a h => ?_)
dsimp only
rw [Real.norm_eq_abs, abs_of_nonneg h]
rw [this, hfi]; rfl
#align measure_theory.integral_eq_lintegral_of_nonneg_ae MeasureTheory.integral_eq_lintegral_of_nonneg_ae
theorem integral_norm_eq_lintegral_nnnorm {P : Type*} [NormedAddCommGroup P] {f : α → P}
(hf : AEStronglyMeasurable f μ) : ∫ x, ‖f x‖ ∂μ = ENNReal.toReal (∫⁻ x, ‖f x‖₊ ∂μ) := by
rw [integral_eq_lintegral_of_nonneg_ae _ hf.norm]
· simp_rw [ofReal_norm_eq_coe_nnnorm]
· filter_upwards; simp_rw [Pi.zero_apply, norm_nonneg, imp_true_iff]
#align measure_theory.integral_norm_eq_lintegral_nnnorm MeasureTheory.integral_norm_eq_lintegral_nnnorm
theorem ofReal_integral_norm_eq_lintegral_nnnorm {P : Type*} [NormedAddCommGroup P] {f : α → P}
(hf : Integrable f μ) : ENNReal.ofReal (∫ x, ‖f x‖ ∂μ) = ∫⁻ x, ‖f x‖₊ ∂μ := by
rw [integral_norm_eq_lintegral_nnnorm hf.aestronglyMeasurable,
ENNReal.ofReal_toReal (lt_top_iff_ne_top.mp hf.2)]
#align measure_theory.of_real_integral_norm_eq_lintegral_nnnorm MeasureTheory.ofReal_integral_norm_eq_lintegral_nnnorm
theorem integral_eq_integral_pos_part_sub_integral_neg_part {f : α → ℝ} (hf : Integrable f μ) :
∫ a, f a ∂μ = ∫ a, (Real.toNNReal (f a) : ℝ) ∂μ - ∫ a, (Real.toNNReal (-f a) : ℝ) ∂μ := by
rw [← integral_sub hf.real_toNNReal]
· simp
· exact hf.neg.real_toNNReal
#align measure_theory.integral_eq_integral_pos_part_sub_integral_neg_part MeasureTheory.integral_eq_integral_pos_part_sub_integral_neg_part
theorem integral_nonneg_of_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ a, f a ∂μ := by
have A : CompleteSpace ℝ := by infer_instance
simp only [integral_def, A, L1.integral_def, dite_true, ge_iff_le]
exact setToFun_nonneg (dominatedFinMeasAdditive_weightedSMul μ)
(fun s _ _ => weightedSMul_nonneg s) hf
#align measure_theory.integral_nonneg_of_ae MeasureTheory.integral_nonneg_of_ae
theorem lintegral_coe_eq_integral (f : α → ℝ≥0) (hfi : Integrable (fun x => (f x : ℝ)) μ) :
∫⁻ a, f a ∂μ = ENNReal.ofReal (∫ a, f a ∂μ) := by
simp_rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall fun x => (f x).coe_nonneg)
hfi.aestronglyMeasurable, ← ENNReal.coe_nnreal_eq]
rw [ENNReal.ofReal_toReal]
rw [← lt_top_iff_ne_top]
convert hfi.hasFiniteIntegral
-- Porting note: `convert` no longer unfolds `HasFiniteIntegral`
simp_rw [HasFiniteIntegral, NNReal.nnnorm_eq]
#align measure_theory.lintegral_coe_eq_integral MeasureTheory.lintegral_coe_eq_integral
theorem ofReal_integral_eq_lintegral_ofReal {f : α → ℝ} (hfi : Integrable f μ) (f_nn : 0 ≤ᵐ[μ] f) :
ENNReal.ofReal (∫ x, f x ∂μ) = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by
have : f =ᵐ[μ] (‖f ·‖) := f_nn.mono fun _x hx ↦ (abs_of_nonneg hx).symm
simp_rw [integral_congr_ae this, ofReal_integral_norm_eq_lintegral_nnnorm hfi,
← ofReal_norm_eq_coe_nnnorm]
exact lintegral_congr_ae (this.symm.fun_comp ENNReal.ofReal)
#align measure_theory.of_real_integral_eq_lintegral_of_real MeasureTheory.ofReal_integral_eq_lintegral_ofReal
theorem integral_toReal {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) (hf : ∀ᵐ x ∂μ, f x < ∞) :
∫ a, (f a).toReal ∂μ = (∫⁻ a, f a ∂μ).toReal := by
rw [integral_eq_lintegral_of_nonneg_ae _ hfm.ennreal_toReal.aestronglyMeasurable,
lintegral_congr_ae (ofReal_toReal_ae_eq hf)]
exact eventually_of_forall fun x => ENNReal.toReal_nonneg
#align measure_theory.integral_to_real MeasureTheory.integral_toReal
theorem lintegral_coe_le_coe_iff_integral_le {f : α → ℝ≥0} (hfi : Integrable (fun x => (f x : ℝ)) μ)
{b : ℝ≥0} : ∫⁻ a, f a ∂μ ≤ b ↔ ∫ a, (f a : ℝ) ∂μ ≤ b := by
rw [lintegral_coe_eq_integral f hfi, ENNReal.ofReal, ENNReal.coe_le_coe,
Real.toNNReal_le_iff_le_coe]
#align measure_theory.lintegral_coe_le_coe_iff_integral_le MeasureTheory.lintegral_coe_le_coe_iff_integral_le
theorem integral_coe_le_of_lintegral_coe_le {f : α → ℝ≥0} {b : ℝ≥0} (h : ∫⁻ a, f a ∂μ ≤ b) :
∫ a, (f a : ℝ) ∂μ ≤ b := by
by_cases hf : Integrable (fun a => (f a : ℝ)) μ
· exact (lintegral_coe_le_coe_iff_integral_le hf).1 h
· rw [integral_undef hf]; exact b.2
#align measure_theory.integral_coe_le_of_lintegral_coe_le MeasureTheory.integral_coe_le_of_lintegral_coe_le
theorem integral_nonneg {f : α → ℝ} (hf : 0 ≤ f) : 0 ≤ ∫ a, f a ∂μ :=
integral_nonneg_of_ae <| eventually_of_forall hf
#align measure_theory.integral_nonneg MeasureTheory.integral_nonneg
theorem integral_nonpos_of_ae {f : α → ℝ} (hf : f ≤ᵐ[μ] 0) : ∫ a, f a ∂μ ≤ 0 := by
have hf : 0 ≤ᵐ[μ] -f := hf.mono fun a h => by rwa [Pi.neg_apply, Pi.zero_apply, neg_nonneg]
have : 0 ≤ ∫ a, -f a ∂μ := integral_nonneg_of_ae hf
rwa [integral_neg, neg_nonneg] at this
#align measure_theory.integral_nonpos_of_ae MeasureTheory.integral_nonpos_of_ae
theorem integral_nonpos {f : α → ℝ} (hf : f ≤ 0) : ∫ a, f a ∂μ ≤ 0 :=
integral_nonpos_of_ae <| eventually_of_forall hf
#align measure_theory.integral_nonpos MeasureTheory.integral_nonpos
theorem integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : Integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 := by
simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ENNReal.toReal_eq_zero_iff,
← ENNReal.not_lt_top, ← hasFiniteIntegral_iff_ofReal hf, hfi.2, not_true_eq_false, or_false_iff]
-- Porting note: split into parts, to make `rw` and `simp` work
rw [lintegral_eq_zero_iff']
· rw [← hf.le_iff_eq, Filter.EventuallyEq, Filter.EventuallyLE]
simp only [Pi.zero_apply, ofReal_eq_zero]
· exact (ENNReal.measurable_ofReal.comp_aemeasurable hfi.1.aemeasurable)
#align measure_theory.integral_eq_zero_iff_of_nonneg_ae MeasureTheory.integral_eq_zero_iff_of_nonneg_ae
theorem integral_eq_zero_iff_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : Integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 :=
integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi
#align measure_theory.integral_eq_zero_iff_of_nonneg MeasureTheory.integral_eq_zero_iff_of_nonneg
lemma integral_eq_iff_of_ae_le {f g : α → ℝ}
(hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) :
∫ a, f a ∂μ = ∫ a, g a ∂μ ↔ f =ᵐ[μ] g := by
refine ⟨fun h_le ↦ EventuallyEq.symm ?_, fun h ↦ integral_congr_ae h⟩
rw [← sub_ae_eq_zero,
← integral_eq_zero_iff_of_nonneg_ae ((sub_nonneg_ae _ _).mpr hfg) (hg.sub hf)]
simpa [Pi.sub_apply, integral_sub hg hf, sub_eq_zero, eq_comm]
theorem integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : Integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (Function.support f) := by
simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, pos_iff_ne_zero, Ne, @eq_comm ℝ 0,
integral_eq_zero_iff_of_nonneg_ae hf hfi, Filter.EventuallyEq, ae_iff, Pi.zero_apply,
Function.support]
#align measure_theory.integral_pos_iff_support_of_nonneg_ae MeasureTheory.integral_pos_iff_support_of_nonneg_ae
theorem integral_pos_iff_support_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : Integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (Function.support f) :=
integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi
#align measure_theory.integral_pos_iff_support_of_nonneg MeasureTheory.integral_pos_iff_support_of_nonneg
lemma integral_exp_pos {μ : Measure α} {f : α → ℝ} [hμ : NeZero μ]
(hf : Integrable (fun x ↦ Real.exp (f x)) μ) :
0 < ∫ x, Real.exp (f x) ∂μ := by
rw [integral_pos_iff_support_of_nonneg (fun x ↦ (Real.exp_pos _).le) hf]
suffices (Function.support fun x ↦ Real.exp (f x)) = Set.univ by simp [this, hμ.out]
ext1 x
simp only [Function.mem_support, ne_eq, (Real.exp_pos _).ne', not_false_eq_true, Set.mem_univ]
/-- Monotone convergence theorem for real-valued functions and Bochner integrals -/
lemma integral_tendsto_of_tendsto_of_monotone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf : ∀ n, Integrable (f n) μ) (hF : Integrable F μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n ↦ f n x)
(h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) :
Tendsto (fun n ↦ ∫ x, f n x ∂μ) atTop (𝓝 (∫ x, F x ∂μ)) := by
-- switch from the Bochner to the Lebesgue integral
let f' := fun n x ↦ f n x - f 0 x
have hf'_nonneg : ∀ᵐ x ∂μ, ∀ n, 0 ≤ f' n x := by
filter_upwards [h_mono] with a ha n
simp [f', ha (zero_le n)]
have hf'_meas : ∀ n, Integrable (f' n) μ := fun n ↦ (hf n).sub (hf 0)
suffices Tendsto (fun n ↦ ∫ x, f' n x ∂μ) atTop (𝓝 (∫ x, (F - f 0) x ∂μ)) by
simp_rw [integral_sub (hf _) (hf _), integral_sub' hF (hf 0), tendsto_sub_const_iff] at this
exact this
have hF_ge : 0 ≤ᵐ[μ] fun x ↦ (F - f 0) x := by
filter_upwards [h_tendsto, h_mono] with x hx_tendsto hx_mono
simp only [Pi.zero_apply, Pi.sub_apply, sub_nonneg]
exact ge_of_tendsto' hx_tendsto (fun n ↦ hx_mono (zero_le _))
rw [ae_all_iff] at hf'_nonneg
simp_rw [integral_eq_lintegral_of_nonneg_ae (hf'_nonneg _) (hf'_meas _).1]
rw [integral_eq_lintegral_of_nonneg_ae hF_ge (hF.1.sub (hf 0).1)]
have h_cont := ENNReal.continuousAt_toReal (x := ∫⁻ a, ENNReal.ofReal ((F - f 0) a) ∂μ) ?_
swap
· rw [← ofReal_integral_eq_lintegral_ofReal (hF.sub (hf 0)) hF_ge]
exact ENNReal.ofReal_ne_top
refine h_cont.tendsto.comp ?_
-- use the result for the Lebesgue integral
refine lintegral_tendsto_of_tendsto_of_monotone ?_ ?_ ?_
· exact fun n ↦ ((hf n).sub (hf 0)).aemeasurable.ennreal_ofReal
· filter_upwards [h_mono] with x hx n m hnm
refine ENNReal.ofReal_le_ofReal ?_
simp only [f', tsub_le_iff_right, sub_add_cancel]
exact hx hnm
· filter_upwards [h_tendsto] with x hx
refine (ENNReal.continuous_ofReal.tendsto _).comp ?_
simp only [Pi.sub_apply]
exact Tendsto.sub hx tendsto_const_nhds
/-- Monotone convergence theorem for real-valued functions and Bochner integrals -/
lemma integral_tendsto_of_tendsto_of_antitone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf : ∀ n, Integrable (f n) μ) (hF : Integrable F μ) (h_mono : ∀ᵐ x ∂μ, Antitone fun n ↦ f n x)
(h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) :
Tendsto (fun n ↦ ∫ x, f n x ∂μ) atTop (𝓝 (∫ x, F x ∂μ)) := by
suffices Tendsto (fun n ↦ ∫ x, -f n x ∂μ) atTop (𝓝 (∫ x, -F x ∂μ)) by
suffices Tendsto (fun n ↦ ∫ x, - -f n x ∂μ) atTop (𝓝 (∫ x, - -F x ∂μ)) by
simpa [neg_neg] using this
convert this.neg <;> rw [integral_neg]
refine integral_tendsto_of_tendsto_of_monotone (fun n ↦ (hf n).neg) hF.neg ?_ ?_
· filter_upwards [h_mono] with x hx n m hnm using neg_le_neg_iff.mpr <| hx hnm
· filter_upwards [h_tendsto] with x hx using hx.neg
/-- If a monotone sequence of functions has an upper bound and the sequence of integrals of these
functions tends to the integral of the upper bound, then the sequence of functions converges
almost everywhere to the upper bound. -/
lemma tendsto_of_integral_tendsto_of_monotone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf_int : ∀ n, Integrable (f n) μ) (hF_int : Integrable F μ)
(hf_tendsto : Tendsto (fun i ↦ ∫ a, f i a ∂μ) atTop (𝓝 (∫ a, F a ∂μ)))
(hf_mono : ∀ᵐ a ∂μ, Monotone (fun i ↦ f i a))
(hf_bound : ∀ᵐ a ∂μ, ∀ i, f i a ≤ F a) :
∀ᵐ a ∂μ, Tendsto (fun i ↦ f i a) atTop (𝓝 (F a)) := by
-- reduce to the `ℝ≥0∞` case
let f' : ℕ → α → ℝ≥0∞ := fun n a ↦ ENNReal.ofReal (f n a - f 0 a)
let F' : α → ℝ≥0∞ := fun a ↦ ENNReal.ofReal (F a - f 0 a)
have hf'_int_eq : ∀ i, ∫⁻ a, f' i a ∂μ = ENNReal.ofReal (∫ a, f i a ∂μ - ∫ a, f 0 a ∂μ) := by
intro i
unfold_let f'
rw [← ofReal_integral_eq_lintegral_ofReal, integral_sub (hf_int i) (hf_int 0)]
· exact (hf_int i).sub (hf_int 0)
· filter_upwards [hf_mono] with a h_mono
simp [h_mono (zero_le i)]
have hF'_int_eq : ∫⁻ a, F' a ∂μ = ENNReal.ofReal (∫ a, F a ∂μ - ∫ a, f 0 a ∂μ) := by
unfold_let F'
rw [← ofReal_integral_eq_lintegral_ofReal, integral_sub hF_int (hf_int 0)]
· exact hF_int.sub (hf_int 0)
· filter_upwards [hf_bound] with a h_bound
simp [h_bound 0]
have h_tendsto : Tendsto (fun i ↦ ∫⁻ a, f' i a ∂μ) atTop (𝓝 (∫⁻ a, F' a ∂μ)) := by
simp_rw [hf'_int_eq, hF'_int_eq]
refine (ENNReal.continuous_ofReal.tendsto _).comp ?_
rwa [tendsto_sub_const_iff]
have h_mono : ∀ᵐ a ∂μ, Monotone (fun i ↦ f' i a) := by
filter_upwards [hf_mono] with a ha_mono i j hij
refine ENNReal.ofReal_le_ofReal ?_
simp [ha_mono hij]
have h_bound : ∀ᵐ a ∂μ, ∀ i, f' i a ≤ F' a := by
filter_upwards [hf_bound] with a ha_bound i
refine ENNReal.ofReal_le_ofReal ?_
simp only [tsub_le_iff_right, sub_add_cancel, ha_bound i]
-- use the corresponding lemma for `ℝ≥0∞`
have h := tendsto_of_lintegral_tendsto_of_monotone ?_ h_tendsto h_mono h_bound ?_
rotate_left
· exact (hF_int.1.aemeasurable.sub (hf_int 0).1.aemeasurable).ennreal_ofReal
· exact ((lintegral_ofReal_le_lintegral_nnnorm _).trans_lt (hF_int.sub (hf_int 0)).2).ne
filter_upwards [h, hf_mono, hf_bound] with a ha ha_mono ha_bound
have h1 : (fun i ↦ f i a) = fun i ↦ (f' i a).toReal + f 0 a := by
unfold_let f'
ext i
rw [ENNReal.toReal_ofReal]
· abel
· simp [ha_mono (zero_le i)]
have h2 : F a = (F' a).toReal + f 0 a := by
unfold_let F'
rw [ENNReal.toReal_ofReal]
· abel
· simp [ha_bound 0]
rw [h1, h2]
refine Filter.Tendsto.add ?_ tendsto_const_nhds
exact (ENNReal.continuousAt_toReal ENNReal.ofReal_ne_top).tendsto.comp ha
/-- If an antitone sequence of functions has a lower bound and the sequence of integrals of these
functions tends to the integral of the lower bound, then the sequence of functions converges
almost everywhere to the lower bound. -/
lemma tendsto_of_integral_tendsto_of_antitone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf_int : ∀ n, Integrable (f n) μ) (hF_int : Integrable F μ)
(hf_tendsto : Tendsto (fun i ↦ ∫ a, f i a ∂μ) atTop (𝓝 (∫ a, F a ∂μ)))
(hf_mono : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a))
(hf_bound : ∀ᵐ a ∂μ, ∀ i, F a ≤ f i a) :
∀ᵐ a ∂μ, Tendsto (fun i ↦ f i a) atTop (𝓝 (F a)) := by
let f' : ℕ → α → ℝ := fun i a ↦ - f i a
let F' : α → ℝ := fun a ↦ - F a
suffices ∀ᵐ a ∂μ, Tendsto (fun i ↦ f' i a) atTop (𝓝 (F' a)) by
filter_upwards [this] with a ha_tendsto
convert ha_tendsto.neg
· simp [f']
· simp [F']
refine tendsto_of_integral_tendsto_of_monotone (fun n ↦ (hf_int n).neg) hF_int.neg ?_ ?_ ?_
· convert hf_tendsto.neg
· rw [integral_neg]
· rw [integral_neg]
· filter_upwards [hf_mono] with a ha i j hij
simp [f', ha hij]
· filter_upwards [hf_bound] with a ha i
simp [f', F', ha i]
section NormedAddCommGroup
variable {H : Type*} [NormedAddCommGroup H]
theorem L1.norm_eq_integral_norm (f : α →₁[μ] H) : ‖f‖ = ∫ a, ‖f a‖ ∂μ := by
simp only [snorm, snorm', ENNReal.one_toReal, ENNReal.rpow_one, Lp.norm_def, if_false,
ENNReal.one_ne_top, one_ne_zero, _root_.div_one]
rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (by simp [norm_nonneg]))
(Lp.aestronglyMeasurable f).norm]
simp [ofReal_norm_eq_coe_nnnorm]
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.norm_eq_integral_norm MeasureTheory.L1.norm_eq_integral_norm
theorem L1.dist_eq_integral_dist (f g : α →₁[μ] H) : dist f g = ∫ a, dist (f a) (g a) ∂μ := by
simp only [dist_eq_norm, L1.norm_eq_integral_norm]
exact integral_congr_ae <| (Lp.coeFn_sub _ _).fun_comp norm
theorem L1.norm_of_fun_eq_integral_norm {f : α → H} (hf : Integrable f μ) :
‖hf.toL1 f‖ = ∫ a, ‖f a‖ ∂μ := by
rw [L1.norm_eq_integral_norm]
exact integral_congr_ae <| hf.coeFn_toL1.fun_comp _
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.norm_of_fun_eq_integral_norm MeasureTheory.L1.norm_of_fun_eq_integral_norm
theorem Memℒp.snorm_eq_integral_rpow_norm {f : α → H} {p : ℝ≥0∞} (hp1 : p ≠ 0) (hp2 : p ≠ ∞)
(hf : Memℒp f p μ) :
snorm f p μ = ENNReal.ofReal ((∫ a, ‖f a‖ ^ p.toReal ∂μ) ^ p.toReal⁻¹) := by
have A : ∫⁻ a : α, ENNReal.ofReal (‖f a‖ ^ p.toReal) ∂μ = ∫⁻ a : α, ‖f a‖₊ ^ p.toReal ∂μ := by
simp_rw [← ofReal_rpow_of_nonneg (norm_nonneg _) toReal_nonneg, ofReal_norm_eq_coe_nnnorm]
simp only [snorm_eq_lintegral_rpow_nnnorm hp1 hp2, one_div]
rw [integral_eq_lintegral_of_nonneg_ae]; rotate_left
· exact ae_of_all _ fun x => by positivity
· exact (hf.aestronglyMeasurable.norm.aemeasurable.pow_const _).aestronglyMeasurable
rw [A, ← ofReal_rpow_of_nonneg toReal_nonneg (inv_nonneg.2 toReal_nonneg), ofReal_toReal]
exact (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp1 hp2 hf.2).ne
#align measure_theory.mem_ℒp.snorm_eq_integral_rpow_norm MeasureTheory.Memℒp.snorm_eq_integral_rpow_norm
end NormedAddCommGroup
theorem integral_mono_ae {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (h : f ≤ᵐ[μ] g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := by
have A : CompleteSpace ℝ := by infer_instance
simp only [integral, A, L1.integral]
exact setToFun_mono (dominatedFinMeasAdditive_weightedSMul μ)
(fun s _ _ => weightedSMul_nonneg s) hf hg h
#align measure_theory.integral_mono_ae MeasureTheory.integral_mono_ae
@[mono]
theorem integral_mono {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (h : f ≤ g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
integral_mono_ae hf hg <| eventually_of_forall h
#align measure_theory.integral_mono MeasureTheory.integral_mono
theorem integral_mono_of_nonneg {f g : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hgi : Integrable g μ)
(h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := by
by_cases hfm : AEStronglyMeasurable f μ
· refine integral_mono_ae ⟨hfm, ?_⟩ hgi h
refine hgi.hasFiniteIntegral.mono <| h.mp <| hf.mono fun x hf hfg => ?_
simpa [abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)]
· rw [integral_non_aestronglyMeasurable hfm]
exact integral_nonneg_of_ae (hf.trans h)
#align measure_theory.integral_mono_of_nonneg MeasureTheory.integral_mono_of_nonneg
theorem integral_mono_measure {f : α → ℝ} {ν} (hle : μ ≤ ν) (hf : 0 ≤ᵐ[ν] f)
(hfi : Integrable f ν) : ∫ a, f a ∂μ ≤ ∫ a, f a ∂ν := by
have hfi' : Integrable f μ := hfi.mono_measure hle
have hf' : 0 ≤ᵐ[μ] f := hle.absolutelyContinuous hf
rw [integral_eq_lintegral_of_nonneg_ae hf' hfi'.1, integral_eq_lintegral_of_nonneg_ae hf hfi.1,
ENNReal.toReal_le_toReal]
exacts [lintegral_mono' hle le_rfl, ((hasFiniteIntegral_iff_ofReal hf').1 hfi'.2).ne,
((hasFiniteIntegral_iff_ofReal hf).1 hfi.2).ne]
#align measure_theory.integral_mono_measure MeasureTheory.integral_mono_measure
theorem norm_integral_le_integral_norm (f : α → G) : ‖∫ a, f a ∂μ‖ ≤ ∫ a, ‖f a‖ ∂μ := by
have le_ae : ∀ᵐ a ∂μ, 0 ≤ ‖f a‖ := eventually_of_forall fun a => norm_nonneg _
by_cases h : AEStronglyMeasurable f μ
· calc
‖∫ a, f a ∂μ‖ ≤ ENNReal.toReal (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) :=
norm_integral_le_lintegral_norm _
_ = ∫ a, ‖f a‖ ∂μ := (integral_eq_lintegral_of_nonneg_ae le_ae <| h.norm).symm
· rw [integral_non_aestronglyMeasurable h, norm_zero]
exact integral_nonneg_of_ae le_ae
#align measure_theory.norm_integral_le_integral_norm MeasureTheory.norm_integral_le_integral_norm
theorem norm_integral_le_of_norm_le {f : α → G} {g : α → ℝ} (hg : Integrable g μ)
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : ‖∫ x, f x ∂μ‖ ≤ ∫ x, g x ∂μ :=
calc
‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ := norm_integral_le_integral_norm f
_ ≤ ∫ x, g x ∂μ := integral_mono_of_nonneg (eventually_of_forall fun _ => norm_nonneg _) hg h
#align measure_theory.norm_integral_le_of_norm_le MeasureTheory.norm_integral_le_of_norm_le
theorem SimpleFunc.integral_eq_integral (f : α →ₛ E) (hfi : Integrable f μ) :
f.integral μ = ∫ x, f x ∂μ := by
rw [MeasureTheory.integral_eq f hfi, ← L1.SimpleFunc.toLp_one_eq_toL1,
L1.SimpleFunc.integral_L1_eq_integral, L1.SimpleFunc.integral_eq_integral]
exact SimpleFunc.integral_congr hfi (Lp.simpleFunc.toSimpleFunc_toLp _ _).symm
#align measure_theory.simple_func.integral_eq_integral MeasureTheory.SimpleFunc.integral_eq_integral
theorem SimpleFunc.integral_eq_sum (f : α →ₛ E) (hfi : Integrable f μ) :
∫ x, f x ∂μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • x := by
rw [← f.integral_eq_integral hfi, SimpleFunc.integral, ← SimpleFunc.integral_eq]; rfl
#align measure_theory.simple_func.integral_eq_sum MeasureTheory.SimpleFunc.integral_eq_sum
@[simp]
theorem integral_const (c : E) : ∫ _ : α, c ∂μ = (μ univ).toReal • c := by
cases' (@le_top _ _ _ (μ univ)).lt_or_eq with hμ hμ
· haveI : IsFiniteMeasure μ := ⟨hμ⟩
simp only [integral, hE, L1.integral]
exact setToFun_const (dominatedFinMeasAdditive_weightedSMul _) _
· by_cases hc : c = 0
· simp [hc, integral_zero]
· have : ¬Integrable (fun _ : α => c) μ := by
simp only [integrable_const_iff, not_or]
exact ⟨hc, hμ.not_lt⟩
simp [integral_undef, *]
#align measure_theory.integral_const MeasureTheory.integral_const
theorem norm_integral_le_of_norm_le_const [IsFiniteMeasure μ] {f : α → G} {C : ℝ}
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖∫ x, f x ∂μ‖ ≤ C * (μ univ).toReal :=
calc
‖∫ x, f x ∂μ‖ ≤ ∫ _, C ∂μ := norm_integral_le_of_norm_le (integrable_const C) h
_ = C * (μ univ).toReal := by rw [integral_const, smul_eq_mul, mul_comm]
#align measure_theory.norm_integral_le_of_norm_le_const MeasureTheory.norm_integral_le_of_norm_le_const
theorem tendsto_integral_approxOn_of_measurable [MeasurableSpace E] [BorelSpace E] {f : α → E}
{s : Set E} [SeparableSpace s] (hfi : Integrable f μ) (hfm : Measurable f)
(hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s) (h₀i : Integrable (fun _ => y₀) μ) :
Tendsto (fun n => (SimpleFunc.approxOn f hfm s y₀ h₀ n).integral μ)
atTop (𝓝 <| ∫ x, f x ∂μ) := by
have hfi' := SimpleFunc.integrable_approxOn hfm hfi h₀ h₀i
simp only [SimpleFunc.integral_eq_integral _ (hfi' _), integral, hE, L1.integral]
exact tendsto_setToFun_approxOn_of_measurable (dominatedFinMeasAdditive_weightedSMul μ)
hfi hfm hs h₀ h₀i
#align measure_theory.tendsto_integral_approx_on_of_measurable MeasureTheory.tendsto_integral_approxOn_of_measurable
theorem tendsto_integral_approxOn_of_measurable_of_range_subset [MeasurableSpace E] [BorelSpace E]
{f : α → E} (fmeas : Measurable f) (hf : Integrable f μ) (s : Set E) [SeparableSpace s]
(hs : range f ∪ {0} ⊆ s) :
Tendsto (fun n => (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n).integral μ) atTop
(𝓝 <| ∫ x, f x ∂μ) := by
apply tendsto_integral_approxOn_of_measurable hf fmeas _ _ (integrable_zero _ _ _)
exact eventually_of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _)))
#align measure_theory.tendsto_integral_approx_on_of_measurable_of_range_subset MeasureTheory.tendsto_integral_approxOn_of_measurable_of_range_subset
theorem tendsto_integral_norm_approxOn_sub [MeasurableSpace E] [BorelSpace E] {f : α → E}
(fmeas : Measurable f) (hf : Integrable f μ) [SeparableSpace (range f ∪ {0} : Set E)] :
Tendsto (fun n ↦ ∫ x, ‖SimpleFunc.approxOn f fmeas (range f ∪ {0}) 0 (by simp) n x - f x‖ ∂μ)
atTop (𝓝 0) := by
convert (tendsto_toReal zero_ne_top).comp (tendsto_approxOn_range_L1_nnnorm fmeas hf) with n
rw [integral_norm_eq_lintegral_nnnorm]
· simp
· apply (SimpleFunc.aestronglyMeasurable _).sub
apply (stronglyMeasurable_iff_measurable_separable.2 ⟨fmeas, ?_⟩ ).aestronglyMeasurable
exact .mono (.of_subtype (range f ∪ {0})) subset_union_left
variable {ν : Measure α}
theorem integral_add_measure {f : α → G} (hμ : Integrable f μ) (hν : Integrable f ν) :
∫ x, f x ∂(μ + ν) = ∫ x, f x ∂μ + ∫ x, f x ∂ν := by
by_cases hG : CompleteSpace G; swap
· simp [integral, hG]
have hfi := hμ.add_measure hν
simp_rw [integral_eq_setToFun]
have hμ_dfma : DominatedFinMeasAdditive (μ + ν) (weightedSMul μ : Set α → G →L[ℝ] G) 1 :=
DominatedFinMeasAdditive.add_measure_right μ ν (dominatedFinMeasAdditive_weightedSMul μ)
zero_le_one
have hν_dfma : DominatedFinMeasAdditive (μ + ν) (weightedSMul ν : Set α → G →L[ℝ] G) 1 :=
DominatedFinMeasAdditive.add_measure_left μ ν (dominatedFinMeasAdditive_weightedSMul ν)
zero_le_one
rw [← setToFun_congr_measure_of_add_right hμ_dfma
(dominatedFinMeasAdditive_weightedSMul μ) f hfi,
← setToFun_congr_measure_of_add_left hν_dfma (dominatedFinMeasAdditive_weightedSMul ν) f hfi]
refine setToFun_add_left' _ _ _ (fun s _ hμνs => ?_) f
rw [Measure.coe_add, Pi.add_apply, add_lt_top] at hμνs
rw [weightedSMul, weightedSMul, weightedSMul, ← add_smul, Measure.coe_add, Pi.add_apply,
toReal_add hμνs.1.ne hμνs.2.ne]
#align measure_theory.integral_add_measure MeasureTheory.integral_add_measure
@[simp]
theorem integral_zero_measure {m : MeasurableSpace α} (f : α → G) :
(∫ x, f x ∂(0 : Measure α)) = 0 := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_measure_zero (dominatedFinMeasAdditive_weightedSMul _) rfl
· simp [integral, hG]
#align measure_theory.integral_zero_measure MeasureTheory.integral_zero_measure
theorem integral_finset_sum_measure {ι} {m : MeasurableSpace α} {f : α → G} {μ : ι → Measure α}
{s : Finset ι} (hf : ∀ i ∈ s, Integrable f (μ i)) :
∫ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫ a, f a ∂μ i := by
induction s using Finset.cons_induction_on with
| h₁ => simp
| h₂ h ih =>
rw [Finset.forall_mem_cons] at hf
rw [Finset.sum_cons, Finset.sum_cons, ← ih hf.2]
exact integral_add_measure hf.1 (integrable_finset_sum_measure.2 hf.2)
#align measure_theory.integral_finset_sum_measure MeasureTheory.integral_finset_sum_measure
theorem nndist_integral_add_measure_le_lintegral
{f : α → G} (h₁ : Integrable f μ) (h₂ : Integrable f ν) :
(nndist (∫ x, f x ∂μ) (∫ x, f x ∂(μ + ν)) : ℝ≥0∞) ≤ ∫⁻ x, ‖f x‖₊ ∂ν := by
rw [integral_add_measure h₁ h₂, nndist_comm, nndist_eq_nnnorm, add_sub_cancel_left]
exact ennnorm_integral_le_lintegral_ennnorm _
#align measure_theory.nndist_integral_add_measure_le_lintegral MeasureTheory.nndist_integral_add_measure_le_lintegral
theorem hasSum_integral_measure {ι} {m : MeasurableSpace α} {f : α → G} {μ : ι → Measure α}
(hf : Integrable f (Measure.sum μ)) :
HasSum (fun i => ∫ a, f a ∂μ i) (∫ a, f a ∂Measure.sum μ) := by
have hfi : ∀ i, Integrable f (μ i) := fun i => hf.mono_measure (Measure.le_sum _ _)
simp only [HasSum, ← integral_finset_sum_measure fun i _ => hfi i]
refine Metric.nhds_basis_ball.tendsto_right_iff.mpr fun ε ε0 => ?_
lift ε to ℝ≥0 using ε0.le
have hf_lt : (∫⁻ x, ‖f x‖₊ ∂Measure.sum μ) < ∞ := hf.2
have hmem : ∀ᶠ y in 𝓝 (∫⁻ x, ‖f x‖₊ ∂Measure.sum μ), (∫⁻ x, ‖f x‖₊ ∂Measure.sum μ) < y + ε := by
refine tendsto_id.add tendsto_const_nhds (lt_mem_nhds (α := ℝ≥0∞) <| ENNReal.lt_add_right ?_ ?_)
exacts [hf_lt.ne, ENNReal.coe_ne_zero.2 (NNReal.coe_ne_zero.1 ε0.ne')]
refine ((hasSum_lintegral_measure (fun x => ‖f x‖₊) μ).eventually hmem).mono fun s hs => ?_
obtain ⟨ν, hν⟩ : ∃ ν, (∑ i ∈ s, μ i) + ν = Measure.sum μ := by
refine ⟨Measure.sum fun i : ↥(sᶜ : Set ι) => μ i, ?_⟩
simpa only [← Measure.sum_coe_finset] using Measure.sum_add_sum_compl (s : Set ι) μ
rw [Metric.mem_ball, ← coe_nndist, NNReal.coe_lt_coe, ← ENNReal.coe_lt_coe, ← hν]
rw [← hν, integrable_add_measure] at hf
refine (nndist_integral_add_measure_le_lintegral hf.1 hf.2).trans_lt ?_
rw [← hν, lintegral_add_measure, lintegral_finset_sum_measure] at hs
exact lt_of_add_lt_add_left hs
#align measure_theory.has_sum_integral_measure MeasureTheory.hasSum_integral_measure
theorem integral_sum_measure {ι} {_ : MeasurableSpace α} {f : α → G} {μ : ι → Measure α}
(hf : Integrable f (Measure.sum μ)) : ∫ a, f a ∂Measure.sum μ = ∑' i, ∫ a, f a ∂μ i :=
(hasSum_integral_measure hf).tsum_eq.symm
#align measure_theory.integral_sum_measure MeasureTheory.integral_sum_measure
@[simp]
theorem integral_smul_measure (f : α → G) (c : ℝ≥0∞) :
∫ x, f x ∂c • μ = c.toReal • ∫ x, f x ∂μ := by
by_cases hG : CompleteSpace G; swap
· simp [integral, hG]
-- First we consider the “degenerate” case `c = ∞`
rcases eq_or_ne c ∞ with (rfl | hc)
· rw [ENNReal.top_toReal, zero_smul, integral_eq_setToFun, setToFun_top_smul_measure]
-- Main case: `c ≠ ∞`
simp_rw [integral_eq_setToFun, ← setToFun_smul_left]
have hdfma : DominatedFinMeasAdditive μ (weightedSMul (c • μ) : Set α → G →L[ℝ] G) c.toReal :=
mul_one c.toReal ▸ (dominatedFinMeasAdditive_weightedSMul (c • μ)).of_smul_measure c hc
have hdfma_smul := dominatedFinMeasAdditive_weightedSMul (F := G) (c • μ)
rw [← setToFun_congr_smul_measure c hc hdfma hdfma_smul f]
exact setToFun_congr_left' _ _ (fun s _ _ => weightedSMul_smul_measure μ c) f
#align measure_theory.integral_smul_measure MeasureTheory.integral_smul_measure
@[simp]
theorem integral_smul_nnreal_measure (f : α → G) (c : ℝ≥0) :
∫ x, f x ∂(c • μ) = c • ∫ x, f x ∂μ :=
integral_smul_measure f (c : ℝ≥0∞)
theorem integral_map_of_stronglyMeasurable {β} [MeasurableSpace β] {φ : α → β} (hφ : Measurable φ)
{f : β → G} (hfm : StronglyMeasurable f) : ∫ y, f y ∂Measure.map φ μ = ∫ x, f (φ x) ∂μ := by
by_cases hG : CompleteSpace G; swap
· simp [integral, hG]
by_cases hfi : Integrable f (Measure.map φ μ); swap
· rw [integral_undef hfi, integral_undef]
exact fun hfφ => hfi ((integrable_map_measure hfm.aestronglyMeasurable hφ.aemeasurable).2 hfφ)
borelize G
have : SeparableSpace (range f ∪ {0} : Set G) := hfm.separableSpace_range_union_singleton
refine tendsto_nhds_unique
(tendsto_integral_approxOn_of_measurable_of_range_subset hfm.measurable hfi _ Subset.rfl) ?_
convert tendsto_integral_approxOn_of_measurable_of_range_subset (hfm.measurable.comp hφ)
((integrable_map_measure hfm.aestronglyMeasurable hφ.aemeasurable).1 hfi) (range f ∪ {0})
(by simp [insert_subset_insert, Set.range_comp_subset_range]) using 1
ext1 i
simp only [SimpleFunc.approxOn_comp, SimpleFunc.integral_eq, Measure.map_apply, hφ,
SimpleFunc.measurableSet_preimage, ← preimage_comp, SimpleFunc.coe_comp]
refine (Finset.sum_subset (SimpleFunc.range_comp_subset_range _ hφ) fun y _ hy => ?_).symm
rw [SimpleFunc.mem_range, ← Set.preimage_singleton_eq_empty, SimpleFunc.coe_comp] at hy
rw [hy]
simp
#align measure_theory.integral_map_of_strongly_measurable MeasureTheory.integral_map_of_stronglyMeasurable
theorem integral_map {β} [MeasurableSpace β] {φ : α → β} (hφ : AEMeasurable φ μ) {f : β → G}
(hfm : AEStronglyMeasurable f (Measure.map φ μ)) :
∫ y, f y ∂Measure.map φ μ = ∫ x, f (φ x) ∂μ :=
let g := hfm.mk f
calc
∫ y, f y ∂Measure.map φ μ = ∫ y, g y ∂Measure.map φ μ := integral_congr_ae hfm.ae_eq_mk
_ = ∫ y, g y ∂Measure.map (hφ.mk φ) μ := by congr 1; exact Measure.map_congr hφ.ae_eq_mk
_ = ∫ x, g (hφ.mk φ x) ∂μ :=
(integral_map_of_stronglyMeasurable hφ.measurable_mk hfm.stronglyMeasurable_mk)
_ = ∫ x, g (φ x) ∂μ := integral_congr_ae (hφ.ae_eq_mk.symm.fun_comp _)
_ = ∫ x, f (φ x) ∂μ := integral_congr_ae <| ae_eq_comp hφ hfm.ae_eq_mk.symm
#align measure_theory.integral_map MeasureTheory.integral_map
| Mathlib/MeasureTheory/Integral/Bochner.lean | 1,714 | 1,719 | theorem _root_.MeasurableEmbedding.integral_map {β} {_ : MeasurableSpace β} {f : α → β}
(hf : MeasurableEmbedding f) (g : β → G) : ∫ y, g y ∂Measure.map f μ = ∫ x, g (f x) ∂μ := by |
by_cases hgm : AEStronglyMeasurable g (Measure.map f μ)
· exact MeasureTheory.integral_map hf.measurable.aemeasurable hgm
· rw [integral_non_aestronglyMeasurable hgm, integral_non_aestronglyMeasurable]
exact fun hgf => hgm (hf.aestronglyMeasurable_map_iff.2 hgf)
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Semisimple.Defs
import Mathlib.Order.BooleanGenerators
#align_import algebra.lie.semisimple from "leanprover-community/mathlib"@"356447fe00e75e54777321045cdff7c9ea212e60"
/-!
# Semisimple Lie algebras
The famous Cartan-Dynkin-Killing classification of semisimple Lie algebras renders them one of the
most important classes of Lie algebras. In this file we prove basic results
abot simple and semisimple Lie algebras.
## Main declarations
* `LieAlgebra.IsSemisimple.instHasTrivialRadical`: A semisimple Lie algebra has trivial radical.
* `LieAlgebra.IsSemisimple.instBooleanAlgebra`:
The lattice of ideals in a semisimple Lie algebra is a boolean algebra.
In particular, this implies that the lattice of ideals is atomistic:
every ideal is a direct sum of atoms (simple ideals) in a unique way.
* `LieAlgebra.hasTrivialRadical_iff_no_solvable_ideals`
* `LieAlgebra.hasTrivialRadical_iff_no_abelian_ideals`
* `LieAlgebra.abelian_radical_iff_solvable_is_abelian`
## Tags
lie algebra, radical, simple, semisimple
-/
section Irreducible
variable (R L M : Type*) [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] [LieRingModule L M]
lemma LieModule.nontrivial_of_isIrreducible [LieModule.IsIrreducible R L M] : Nontrivial M where
exists_pair_ne := by
have aux : (⊥ : LieSubmodule R L M) ≠ ⊤ := bot_ne_top
contrapose! aux
ext m
simpa using aux m 0
end Irreducible
namespace LieAlgebra
variable (R L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L]
variable {R L} in
theorem HasTrivialRadical.eq_bot_of_isSolvable [HasTrivialRadical R L]
(I : LieIdeal R L) [hI : IsSolvable R I] : I = ⊥ :=
sSup_eq_bot.mp radical_eq_bot _ hI
@[simp]
theorem HasTrivialRadical.center_eq_bot [HasTrivialRadical R L] : center R L = ⊥ :=
HasTrivialRadical.eq_bot_of_isSolvable _
#align lie_algebra.center_eq_bot_of_semisimple LieAlgebra.HasTrivialRadical.center_eq_bot
variable {R L} in
theorem hasTrivialRadical_of_no_solvable_ideals (h : ∀ I : LieIdeal R L, IsSolvable R I → I = ⊥) :
HasTrivialRadical R L :=
⟨sSup_eq_bot.mpr h⟩
theorem hasTrivialRadical_iff_no_solvable_ideals :
HasTrivialRadical R L ↔ ∀ I : LieIdeal R L, IsSolvable R I → I = ⊥ :=
⟨@HasTrivialRadical.eq_bot_of_isSolvable _ _ _ _ _, hasTrivialRadical_of_no_solvable_ideals⟩
#align lie_algebra.is_semisimple_iff_no_solvable_ideals LieAlgebra.hasTrivialRadical_iff_no_solvable_ideals
theorem hasTrivialRadical_iff_no_abelian_ideals :
HasTrivialRadical R L ↔ ∀ I : LieIdeal R L, IsLieAbelian I → I = ⊥ := by
rw [hasTrivialRadical_iff_no_solvable_ideals]
constructor <;> intro h₁ I h₂
· exact h₁ _ <| LieAlgebra.ofAbelianIsSolvable R I
· rw [← abelian_of_solvable_ideal_eq_bot_iff]
exact h₁ _ <| abelian_derivedAbelianOfIdeal I
#align lie_algebra.is_semisimple_iff_no_abelian_ideals LieAlgebra.hasTrivialRadical_iff_no_abelian_ideals
namespace IsSimple
variable [IsSimple R L]
instance : LieModule.IsIrreducible R L L := by
suffices Nontrivial (LieIdeal R L) from ⟨IsSimple.eq_bot_or_eq_top⟩
rw [LieSubmodule.nontrivial_iff, ← not_subsingleton_iff_nontrivial]
have _i : ¬ IsLieAbelian L := IsSimple.non_abelian R
contrapose! _i
infer_instance
variable {R L} in
lemma eq_top_of_isAtom (I : LieIdeal R L) (hI : IsAtom I) : I = ⊤ :=
(IsSimple.eq_bot_or_eq_top I).resolve_left hI.1
lemma isAtom_top : IsAtom (⊤ : LieIdeal R L) :=
⟨bot_ne_top.symm, fun _ h ↦ h.eq_bot⟩
variable {R L} in
@[simp] lemma isAtom_iff_eq_top (I : LieIdeal R L) : IsAtom I ↔ I = ⊤ :=
⟨eq_top_of_isAtom I, fun h ↦ h ▸ isAtom_top R L⟩
instance : HasTrivialRadical R L := by
rw [hasTrivialRadical_iff_no_abelian_ideals]
intro I hI
apply (IsSimple.eq_bot_or_eq_top I).resolve_right
rintro rfl
rw [lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] at hI
exact IsSimple.non_abelian R (L := L) hI
end IsSimple
namespace IsSemisimple
open CompleteLattice IsCompactlyGenerated
variable {R L}
variable [IsSemisimple R L]
lemma isSimple_of_isAtom (I : LieIdeal R L) (hI : IsAtom I) : IsSimple R I where
non_abelian := IsSemisimple.non_abelian_of_isAtom I hI
eq_bot_or_eq_top := by
-- Suppose that `J` is an ideal of `I`.
intro J
-- We first show that `J` is also an ideal of the ambient Lie algebra `L`.
let J' : LieIdeal R L :=
{ __ := J.toSubmodule.map I.incl.toLinearMap
lie_mem := by
rintro x _ ⟨y, hy, rfl⟩
dsimp
-- We need to show that `⁅x, y⁆ ∈ J` for any `x ∈ L` and `y ∈ J`.
-- Since `L` is semisimple, `x` is contained
-- in the supremum of `I` and the atoms not equal to `I`.
have hx : x ∈ I ⊔ sSup ({I' : LieIdeal R L | IsAtom I'} \ {I}) := by
nth_rewrite 1 [← sSup_singleton (a := I)]
rw [← sSup_union, Set.union_diff_self, Set.union_eq_self_of_subset_left,
IsSemisimple.sSup_atoms_eq_top]
· apply LieSubmodule.mem_top
· simp only [Set.singleton_subset_iff, Set.mem_setOf_eq, hI]
-- Hence we can write `x` as `a + b` with `a ∈ I`
-- and `b` in the supremum of the atoms not equal to `I`.
rw [LieSubmodule.mem_sup] at hx
obtain ⟨a, ha, b, hb, rfl⟩ := hx
-- Therefore it suffices to show that `⁅a, y⁆ ∈ J` and `⁅b, y⁆ ∈ J`.
simp only [add_lie, AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup,
Submodule.mem_toAddSubmonoid]
apply add_mem
-- Now `⁅a, y⁆ ∈ J` since `a ∈ I`, `y ∈ J`, and `J` is an ideal of `I`.
· simp only [Submodule.mem_map, LieSubmodule.mem_coeSubmodule, Submodule.coeSubtype,
Subtype.exists, exists_and_right, exists_eq_right, ha, lie_mem_left, exists_true_left]
exact lie_mem_right R I J ⟨a, ha⟩ y hy
-- Finally `⁅b, y⁆ = 0`, by the independence of the atoms.
· suffices ⁅b, y.val⁆ = 0 by simp only [this, zero_mem]
rw [← LieSubmodule.mem_bot (R := R) (L := L),
← (IsSemisimple.setIndependent_isAtom hI).eq_bot]
exact ⟨lie_mem_right R L I b y y.2, lie_mem_left _ _ _ _ _ hb⟩ }
-- Now that we know that `J` is an ideal of `L`,
-- we start with the proof that `I` is a simple Lie algebra.
-- Assume that `J ≠ ⊤`.
rw [or_iff_not_imp_right]
intro hJ
suffices J' = ⊥ by
rw [eq_bot_iff] at this ⊢
intro x hx
suffices x ∈ J → x = 0 from this hx
simpa [J'] using @this x.1
-- We need to show that `J = ⊥`.
-- Since `J` is an ideal of `L`, and `I` is an atom,
-- it suffices to show that `J < I`.
apply hI.2
rw [lt_iff_le_and_ne]
constructor
-- We know that `J ≤ I` since `J` is an ideal of `I`.
· rintro _ ⟨x, -, rfl⟩
exact x.2
-- So we need to show `J ≠ I` as ideals of `L`.
-- This follows from our assumption that `J ≠ ⊤` as ideals of `I`.
contrapose! hJ
rw [eq_top_iff]
rintro ⟨x, hx⟩ -
rw [← hJ] at hx
rcases hx with ⟨y, hy, rfl⟩
exact hy
/--
In a semisimple Lie algebra,
Lie ideals that are contained in the supremum of a finite collection of atoms
are themselves the supremum of a finite subcollection of those atoms.
By a compactness argument, this statement can be extended to arbitrary sets of atoms.
See `atomistic`.
The proof is by induction on the finite set of atoms.
-/
private
lemma finitelyAtomistic : ∀ s : Finset (LieIdeal R L), ↑s ⊆ {I : LieIdeal R L | IsAtom I} →
∀ I : LieIdeal R L, I ≤ s.sup id → ∃ t ⊆ s, I = t.sup id := by
intro s hs I hI
let S := {I : LieIdeal R L | IsAtom I}
obtain rfl | hI := hI.eq_or_lt
· exact ⟨s, le_rfl, rfl⟩
-- We assume that `I` is strictly smaller than the supremum of `s`.
-- Hence there must exist an atom `J` that is not contained in `I`.
obtain ⟨J, hJs, hJI⟩ : ∃ J ∈ s, ¬ J ≤ I := by
by_contra! H
exact hI.ne (le_antisymm hI.le (s.sup_le H))
classical
let s' := s.erase J
have hs' : s' ⊂ s := Finset.erase_ssubset hJs
have hs'S : ↑s' ⊆ S := Set.Subset.trans (Finset.coe_subset.mpr hs'.subset) hs
-- If we show that `I` is contained in the supremum `K` of the complement of `J` in `s`,
-- then we are done by recursion.
set K := s'.sup id
suffices I ≤ K by
obtain ⟨t, hts', htI⟩ := finitelyAtomistic s' hs'S I this
exact ⟨t, le_trans hts' hs'.subset, htI⟩
-- Since `I` is contained in the supremum of `J` with the supremum of `s'`,
-- any element `x` of `I` can be written as `y + z` for some `y ∈ J` and `z ∈ K`.
intro x hx
obtain ⟨y, hy, z, hz, rfl⟩ : ∃ y ∈ id J, ∃ z ∈ K, y + z = x := by
rw [← LieSubmodule.mem_sup, ← Finset.sup_insert, Finset.insert_erase hJs]
exact hI.le hx
-- If we show that `y` is contained in the center of `J`,
-- then we find `x = z`, and hence `x` is contained in the supremum of `s'`.
-- Since `x` was arbitrary, we have shown that `I` is contained in the supremum of `s'`.
suffices ⟨y, hy⟩ ∈ LieAlgebra.center R J by
have _inst := isSimple_of_isAtom J (hs hJs)
rw [HasTrivialRadical.center_eq_bot R J, LieSubmodule.mem_bot] at this
apply_fun Subtype.val at this
dsimp at this
rwa [this, zero_add]
-- To show that `y` is in the center of `J`,
-- we show that any `j ∈ J` brackets to `0` with `z` and with `x = y + z`.
-- By a simple computation, that implies `⁅j, y⁆ = 0`, for all `j`, as desired.
intro j
suffices ⁅(j : L), z⁆ = 0 ∧ ⁅(j : L), y + z⁆ = 0 by
rw [lie_add, this.1, add_zero] at this
ext
exact this.2
rw [← LieSubmodule.mem_bot (R := R) (L := L), ← LieSubmodule.mem_bot (R := R) (L := L)]
constructor
-- `j` brackets to `0` with `z`, since `⁅j, z⁆` is contained in `⁅J, K⁆ ≤ J ⊓ K`,
-- and `J ⊓ K = ⊥` by the independence of the atoms.
· apply (setIndependent_isAtom.disjoint_sSup (hs hJs) hs'S (Finset.not_mem_erase _ _)).le_bot
apply LieSubmodule.lie_le_inf
apply LieSubmodule.lie_mem_lie _ _ j.2
simpa only [K, Finset.sup_id_eq_sSup] using hz
-- By similar reasoning, `j` brackets to `0` with `x = y + z ∈ I`, if we show `J ⊓ I = ⊥`.
suffices J ⊓ I = ⊥ by
apply this.le
apply LieSubmodule.lie_le_inf
exact LieSubmodule.lie_mem_lie _ _ j.2 hx
-- Indeed `J ⊓ I = ⊥`, since `J` is an atom that is not contained in `I`.
apply ((hs hJs).le_iff.mp _).resolve_right
· contrapose! hJI
rw [← hJI]
exact inf_le_right
exact inf_le_left
termination_by s => s.card
decreasing_by exact Finset.card_lt_card hs'
variable (R L) in
lemma booleanGenerators : BooleanGenerators {I : LieIdeal R L | IsAtom I} where
isAtom _ hI := hI
finitelyAtomistic _ _ hs _ hIs := finitelyAtomistic _ hs _ hIs
instance (priority := 100) instDistribLattice : DistribLattice (LieIdeal R L) :=
(booleanGenerators R L).distribLattice_of_sSup_eq_top sSup_atoms_eq_top
noncomputable
instance (priority := 100) instBooleanAlgebra : BooleanAlgebra (LieIdeal R L) :=
(booleanGenerators R L).booleanAlgebra_of_sSup_eq_top sSup_atoms_eq_top
/-- A semisimple Lie algebra has trivial radical. -/
instance (priority := 100) instHasTrivialRadical : HasTrivialRadical R L := by
rw [hasTrivialRadical_iff_no_abelian_ideals]
intro I hI
apply (eq_bot_or_exists_atom_le I).resolve_right
rintro ⟨J, hJ, hJ'⟩
apply IsSemisimple.non_abelian_of_isAtom J hJ
constructor
intro x y
ext
simp only [LieIdeal.coe_bracket_of_module, LieSubmodule.coe_bracket, ZeroMemClass.coe_zero]
have : (⁅(⟨x, hJ' x.2⟩ : I), ⟨y, hJ' y.2⟩⁆ : I) = 0 := trivial_lie_zero _ _ _ _
apply_fun Subtype.val at this
exact this
end IsSemisimple
/-- A simple Lie algebra is semisimple. -/
instance (priority := 100) IsSimple.instIsSemisimple [IsSimple R L] :
IsSemisimple R L := by
constructor
· simp
· simpa using CompleteLattice.setIndependent_singleton _
· intro I hI₁ hI₂
apply IsSimple.non_abelian (R := R) (L := L)
rw [IsSimple.isAtom_iff_eq_top] at hI₁
rwa [hI₁, lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] at hI₂
/-- An abelian Lie algebra with trivial radical is trivial. -/
theorem subsingleton_of_hasTrivialRadical_lie_abelian [HasTrivialRadical R L] [h : IsLieAbelian L] :
Subsingleton L := by
rw [isLieAbelian_iff_center_eq_top R L, HasTrivialRadical.center_eq_bot] at h
exact (LieSubmodule.subsingleton_iff R L L).mp (subsingleton_of_bot_eq_top h)
#align lie_algebra.subsingleton_of_semisimple_lie_abelian LieAlgebra.subsingleton_of_hasTrivialRadical_lie_abelian
theorem abelian_radical_of_hasTrivialRadical [HasTrivialRadical R L] :
IsLieAbelian (radical R L) := by
rw [HasTrivialRadical.radical_eq_bot]; infer_instance
#align lie_algebra.abelian_radical_of_semisimple LieAlgebra.abelian_radical_of_hasTrivialRadical
/-- The two properties shown to be equivalent here are possible definitions for a Lie algebra
to be reductive.
Note that there is absolutely [no agreement](https://mathoverflow.net/questions/284713/) on what
the label 'reductive' should mean when the coefficients are not a field of characteristic zero. -/
| Mathlib/Algebra/Lie/Semisimple/Basic.lean | 318 | 324 | theorem abelian_radical_iff_solvable_is_abelian [IsNoetherian R L] :
IsLieAbelian (radical R L) ↔ ∀ I : LieIdeal R L, IsSolvable R I → IsLieAbelian I := by |
constructor
· rintro h₁ I h₂
rw [LieIdeal.solvable_iff_le_radical] at h₂
exact (LieIdeal.inclusion_injective h₂).isLieAbelian h₁
· intro h; apply h; infer_instance
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Order.Filter.SmallSets
import Mathlib.Tactic.Monotonicity
import Mathlib.Topology.Compactness.Compact
import Mathlib.Topology.NhdsSet
import Mathlib.Algebra.Group.Defs
#align_import topology.uniform_space.basic from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c"
/-!
# Uniform spaces
Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly
generalize to uniform spaces, e.g.
* uniform continuity (in this file)
* completeness (in `Cauchy.lean`)
* extension of uniform continuous functions to complete spaces (in `UniformEmbedding.lean`)
* totally bounded sets (in `Cauchy.lean`)
* totally bounded complete sets are compact (in `Cauchy.lean`)
A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions
which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means
"for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages
of `X`. The two main examples are:
* If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V`
* If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V`
Those examples are generalizations in two different directions of the elementary example where
`X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological
group structure on `ℝ` and its metric space structure.
Each uniform structure on `X` induces a topology on `X` characterized by
> `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (Prod.mk x) (𝓤 X)`
where `Prod.mk x : X → X × X := (fun y ↦ (x, y))` is the partial evaluation of the product
constructor.
The dictionary with metric spaces includes:
* an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X`
* a ball `ball x r` roughly corresponds to `UniformSpace.ball x V := {y | (x, y) ∈ V}`
for some `V ∈ 𝓤 X`, but the later is more general (it includes in
particular both open and closed balls for suitable `V`).
In particular we have:
`isOpen_iff_ball_subset {s : Set X} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s`
The triangle inequality is abstracted to a statement involving the composition of relations in `X`.
First note that the triangle inequality in a metric space is equivalent to
`∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`.
Then, for any `V` and `W` with type `Set (X × X)`, the composition `V ○ W : Set (X × X)` is
defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`.
In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }`
then the triangle inequality, as reformulated above, says `V ○ W` is contained in
`{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`.
In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`.
Note that this discussion does not depend on any axiom imposed on the uniformity filter,
it is simply captured by the definition of composition.
The uniform space axioms ask the filter `𝓤 X` to satisfy the following:
* every `V ∈ 𝓤 X` contains the diagonal `idRel = { p | p.1 = p.2 }`. This abstracts the fact
that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that
`x - x` belongs to every neighborhood of zero in the topological group case.
* `V ∈ 𝓤 X → Prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x`
in a metric space, and to continuity of negation in the topological group case.
* `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds
to cutting the radius of a ball in half and applying the triangle inequality.
In the topological group case, it comes from continuity of addition at `(0, 0)`.
These three axioms are stated more abstractly in the definition below, in terms of
operations on filters, without directly manipulating entourages.
## Main definitions
* `UniformSpace X` is a uniform space structure on a type `X`
* `UniformContinuous f` is a predicate saying a function `f : α → β` between uniform spaces
is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r`
In this file we also define a complete lattice structure on the type `UniformSpace X`
of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures
coming from the pullback of filters.
Like distance functions, uniform structures cannot be pushed forward in general.
## Notations
Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`,
and `○` for composition of relations, seen as terms with type `Set (X × X)`.
## Implementation notes
There is already a theory of relations in `Data/Rel.lean` where the main definition is
`def Rel (α β : Type*) := α → β → Prop`.
The relations used in the current file involve only one type, but this is not the reason why
we don't reuse `Data/Rel.lean`. We use `Set (α × α)`
instead of `Rel α α` because we really need sets to use the filter library, and elements
of filters on `α × α` have type `Set (α × α)`.
The structure `UniformSpace X` bundles a uniform structure on `X`, a topology on `X` and
an assumption saying those are compatible. This may not seem mathematically reasonable at first,
but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance]
below.
## References
The formalization uses the books:
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
But it makes a more systematic use of the filter library.
-/
open Set Filter Topology
universe u v ua ub uc ud
/-!
### Relations, seen as `Set (α × α)`
-/
variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*}
/-- The identity relation, or the graph of the identity function -/
def idRel {α : Type*} :=
{ p : α × α | p.1 = p.2 }
#align id_rel idRel
@[simp]
theorem mem_idRel {a b : α} : (a, b) ∈ @idRel α ↔ a = b :=
Iff.rfl
#align mem_id_rel mem_idRel
@[simp]
theorem idRel_subset {s : Set (α × α)} : idRel ⊆ s ↔ ∀ a, (a, a) ∈ s := by
simp [subset_def]
#align id_rel_subset idRel_subset
/-- The composition of relations -/
def compRel (r₁ r₂ : Set (α × α)) :=
{ p : α × α | ∃ z : α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂ }
#align comp_rel compRel
@[inherit_doc]
scoped[Uniformity] infixl:62 " ○ " => compRel
open Uniformity
@[simp]
theorem mem_compRel {α : Type u} {r₁ r₂ : Set (α × α)} {x y : α} :
(x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ :=
Iff.rfl
#align mem_comp_rel mem_compRel
@[simp]
theorem swap_idRel : Prod.swap '' idRel = @idRel α :=
Set.ext fun ⟨a, b⟩ => by simpa [image_swap_eq_preimage_swap] using eq_comm
#align swap_id_rel swap_idRel
theorem Monotone.compRel [Preorder β] {f g : β → Set (α × α)} (hf : Monotone f) (hg : Monotone g) :
Monotone fun x => f x ○ g x := fun _ _ h _ ⟨z, h₁, h₂⟩ => ⟨z, hf h h₁, hg h h₂⟩
#align monotone.comp_rel Monotone.compRel
@[mono]
theorem compRel_mono {f g h k : Set (α × α)} (h₁ : f ⊆ h) (h₂ : g ⊆ k) : f ○ g ⊆ h ○ k :=
fun _ ⟨z, h, h'⟩ => ⟨z, h₁ h, h₂ h'⟩
#align comp_rel_mono compRel_mono
theorem prod_mk_mem_compRel {a b c : α} {s t : Set (α × α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) :
(a, b) ∈ s ○ t :=
⟨c, h₁, h₂⟩
#align prod_mk_mem_comp_rel prod_mk_mem_compRel
@[simp]
theorem id_compRel {r : Set (α × α)} : idRel ○ r = r :=
Set.ext fun ⟨a, b⟩ => by simp
#align id_comp_rel id_compRel
theorem compRel_assoc {r s t : Set (α × α)} : r ○ s ○ t = r ○ (s ○ t) := by
ext ⟨a, b⟩; simp only [mem_compRel]; tauto
#align comp_rel_assoc compRel_assoc
theorem left_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ t) : s ⊆ s ○ t := fun ⟨_x, y⟩ xy_in =>
⟨y, xy_in, h <| rfl⟩
#align left_subset_comp_rel left_subset_compRel
theorem right_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ s) : t ⊆ s ○ t := fun ⟨x, _y⟩ xy_in =>
⟨x, h <| rfl, xy_in⟩
#align right_subset_comp_rel right_subset_compRel
theorem subset_comp_self {s : Set (α × α)} (h : idRel ⊆ s) : s ⊆ s ○ s :=
left_subset_compRel h
#align subset_comp_self subset_comp_self
theorem subset_iterate_compRel {s t : Set (α × α)} (h : idRel ⊆ s) (n : ℕ) :
t ⊆ (s ○ ·)^[n] t := by
induction' n with n ihn generalizing t
exacts [Subset.rfl, (right_subset_compRel h).trans ihn]
#align subset_iterate_comp_rel subset_iterate_compRel
/-- The relation is invariant under swapping factors. -/
def SymmetricRel (V : Set (α × α)) : Prop :=
Prod.swap ⁻¹' V = V
#align symmetric_rel SymmetricRel
/-- The maximal symmetric relation contained in a given relation. -/
def symmetrizeRel (V : Set (α × α)) : Set (α × α) :=
V ∩ Prod.swap ⁻¹' V
#align symmetrize_rel symmetrizeRel
theorem symmetric_symmetrizeRel (V : Set (α × α)) : SymmetricRel (symmetrizeRel V) := by
simp [SymmetricRel, symmetrizeRel, preimage_inter, inter_comm, ← preimage_comp]
#align symmetric_symmetrize_rel symmetric_symmetrizeRel
theorem symmetrizeRel_subset_self (V : Set (α × α)) : symmetrizeRel V ⊆ V :=
sep_subset _ _
#align symmetrize_rel_subset_self symmetrizeRel_subset_self
@[mono]
theorem symmetrize_mono {V W : Set (α × α)} (h : V ⊆ W) : symmetrizeRel V ⊆ symmetrizeRel W :=
inter_subset_inter h <| preimage_mono h
#align symmetrize_mono symmetrize_mono
theorem SymmetricRel.mk_mem_comm {V : Set (α × α)} (hV : SymmetricRel V) {x y : α} :
(x, y) ∈ V ↔ (y, x) ∈ V :=
Set.ext_iff.1 hV (y, x)
#align symmetric_rel.mk_mem_comm SymmetricRel.mk_mem_comm
theorem SymmetricRel.eq {U : Set (α × α)} (hU : SymmetricRel U) : Prod.swap ⁻¹' U = U :=
hU
#align symmetric_rel.eq SymmetricRel.eq
theorem SymmetricRel.inter {U V : Set (α × α)} (hU : SymmetricRel U) (hV : SymmetricRel V) :
SymmetricRel (U ∩ V) := by rw [SymmetricRel, preimage_inter, hU.eq, hV.eq]
#align symmetric_rel.inter SymmetricRel.inter
/-- This core description of a uniform space is outside of the type class hierarchy. It is useful
for constructions of uniform spaces, when the topology is derived from the uniform space. -/
structure UniformSpace.Core (α : Type u) where
/-- The uniformity filter. Once `UniformSpace` is defined, `𝓤 α` (`_root_.uniformity`) becomes the
normal form. -/
uniformity : Filter (α × α)
/-- Every set in the uniformity filter includes the diagonal. -/
refl : 𝓟 idRel ≤ uniformity
/-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/
symm : Tendsto Prod.swap uniformity uniformity
/-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/
comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity
#align uniform_space.core UniformSpace.Core
protected theorem UniformSpace.Core.comp_mem_uniformity_sets {c : Core α} {s : Set (α × α)}
(hs : s ∈ c.uniformity) : ∃ t ∈ c.uniformity, t ○ t ⊆ s :=
(mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| c.comp hs
/-- An alternative constructor for `UniformSpace.Core`. This version unfolds various
`Filter`-related definitions. -/
def UniformSpace.Core.mk' {α : Type u} (U : Filter (α × α)) (refl : ∀ r ∈ U, ∀ (x), (x, x) ∈ r)
(symm : ∀ r ∈ U, Prod.swap ⁻¹' r ∈ U) (comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) :
UniformSpace.Core α :=
⟨U, fun _r ru => idRel_subset.2 (refl _ ru), symm, fun _r ru =>
let ⟨_s, hs, hsr⟩ := comp _ ru
mem_of_superset (mem_lift' hs) hsr⟩
#align uniform_space.core.mk' UniformSpace.Core.mk'
/-- Defining a `UniformSpace.Core` from a filter basis satisfying some uniformity-like axioms. -/
def UniformSpace.Core.mkOfBasis {α : Type u} (B : FilterBasis (α × α))
(refl : ∀ r ∈ B, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ B, ∃ t ∈ B, t ⊆ Prod.swap ⁻¹' r)
(comp : ∀ r ∈ B, ∃ t ∈ B, t ○ t ⊆ r) : UniformSpace.Core α where
uniformity := B.filter
refl := B.hasBasis.ge_iff.mpr fun _r ru => idRel_subset.2 <| refl _ ru
symm := (B.hasBasis.tendsto_iff B.hasBasis).mpr symm
comp := (HasBasis.le_basis_iff (B.hasBasis.lift' (monotone_id.compRel monotone_id))
B.hasBasis).2 comp
#align uniform_space.core.mk_of_basis UniformSpace.Core.mkOfBasis
/-- A uniform space generates a topological space -/
def UniformSpace.Core.toTopologicalSpace {α : Type u} (u : UniformSpace.Core α) :
TopologicalSpace α :=
.mkOfNhds fun x ↦ .comap (Prod.mk x) u.uniformity
#align uniform_space.core.to_topological_space UniformSpace.Core.toTopologicalSpace
theorem UniformSpace.Core.ext :
∀ {u₁ u₂ : UniformSpace.Core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
#align uniform_space.core_eq UniformSpace.Core.ext
theorem UniformSpace.Core.nhds_toTopologicalSpace {α : Type u} (u : Core α) (x : α) :
@nhds α u.toTopologicalSpace x = comap (Prod.mk x) u.uniformity := by
apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun _ ↦ (basis_sets _).comap _)
· exact fun a U hU ↦ u.refl hU rfl
· intro a U hU
rcases u.comp_mem_uniformity_sets hU with ⟨V, hV, hVU⟩
filter_upwards [preimage_mem_comap hV] with b hb
filter_upwards [preimage_mem_comap hV] with c hc
exact hVU ⟨b, hb, hc⟩
-- the topological structure is embedded in the uniform structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- A uniform space is a generalization of the "uniform" topological aspects of a
metric space. It consists of a filter on `α × α` called the "uniformity", which
satisfies properties analogous to the reflexivity, symmetry, and triangle properties
of a metric.
A metric space has a natural uniformity, and a uniform space has a natural topology.
A topological group also has a natural uniformity, even when it is not metrizable. -/
class UniformSpace (α : Type u) extends TopologicalSpace α where
/-- The uniformity filter. -/
protected uniformity : Filter (α × α)
/-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/
protected symm : Tendsto Prod.swap uniformity uniformity
/-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/
protected comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity
/-- The uniformity agrees with the topology: the neighborhoods filter of each point `x`
is equal to `Filter.comap (Prod.mk x) (𝓤 α)`. -/
protected nhds_eq_comap_uniformity (x : α) : 𝓝 x = comap (Prod.mk x) uniformity
#align uniform_space UniformSpace
#noalign uniform_space.mk' -- Can't be a `match_pattern`, so not useful anymore
/-- The uniformity is a filter on α × α (inferred from an ambient uniform space
structure on α). -/
def uniformity (α : Type u) [UniformSpace α] : Filter (α × α) :=
@UniformSpace.uniformity α _
#align uniformity uniformity
/-- Notation for the uniformity filter with respect to a non-standard `UniformSpace` instance. -/
scoped[Uniformity] notation "𝓤[" u "]" => @uniformity _ u
@[inherit_doc] -- Porting note (#11215): TODO: should we drop the `uniformity` def?
scoped[Uniformity] notation "𝓤" => uniformity
/-- Construct a `UniformSpace` from a `u : UniformSpace.Core` and a `TopologicalSpace` structure
that is equal to `u.toTopologicalSpace`. -/
abbrev UniformSpace.ofCoreEq {α : Type u} (u : UniformSpace.Core α) (t : TopologicalSpace α)
(h : t = u.toTopologicalSpace) : UniformSpace α where
__ := u
toTopologicalSpace := t
nhds_eq_comap_uniformity x := by rw [h, u.nhds_toTopologicalSpace]
#align uniform_space.of_core_eq UniformSpace.ofCoreEq
/-- Construct a `UniformSpace` from a `UniformSpace.Core`. -/
abbrev UniformSpace.ofCore {α : Type u} (u : UniformSpace.Core α) : UniformSpace α :=
.ofCoreEq u _ rfl
#align uniform_space.of_core UniformSpace.ofCore
/-- Construct a `UniformSpace.Core` from a `UniformSpace`. -/
abbrev UniformSpace.toCore (u : UniformSpace α) : UniformSpace.Core α where
__ := u
refl := by
rintro U hU ⟨x, y⟩ (rfl : x = y)
have : Prod.mk x ⁻¹' U ∈ 𝓝 x := by
rw [UniformSpace.nhds_eq_comap_uniformity]
exact preimage_mem_comap hU
convert mem_of_mem_nhds this
theorem UniformSpace.toCore_toTopologicalSpace (u : UniformSpace α) :
u.toCore.toTopologicalSpace = u.toTopologicalSpace :=
TopologicalSpace.ext_nhds fun a ↦ by
rw [u.nhds_eq_comap_uniformity, u.toCore.nhds_toTopologicalSpace]
#align uniform_space.to_core_to_topological_space UniformSpace.toCore_toTopologicalSpace
/-- Build a `UniformSpace` from a `UniformSpace.Core` and a compatible topology.
Use `UniformSpace.mk` instead to avoid proving
the unnecessary assumption `UniformSpace.Core.refl`.
The main constructor used to use a different compatibility assumption.
This definition was created as a step towards porting to a new definition.
Now the main definition is ported,
so this constructor will be removed in a few months. -/
@[deprecated UniformSpace.mk (since := "2024-03-20")]
def UniformSpace.ofNhdsEqComap (u : UniformSpace.Core α) (_t : TopologicalSpace α)
(h : ∀ x, 𝓝 x = u.uniformity.comap (Prod.mk x)) : UniformSpace α where
__ := u
nhds_eq_comap_uniformity := h
@[ext]
protected theorem UniformSpace.ext {u₁ u₂ : UniformSpace α} (h : 𝓤[u₁] = 𝓤[u₂]) : u₁ = u₂ := by
have : u₁.toTopologicalSpace = u₂.toTopologicalSpace := TopologicalSpace.ext_nhds fun x ↦ by
rw [u₁.nhds_eq_comap_uniformity, u₂.nhds_eq_comap_uniformity]
exact congr_arg (comap _) h
cases u₁; cases u₂; congr
#align uniform_space_eq UniformSpace.ext
protected theorem UniformSpace.ext_iff {u₁ u₂ : UniformSpace α} :
u₁ = u₂ ↔ ∀ s, s ∈ 𝓤[u₁] ↔ s ∈ 𝓤[u₂] :=
⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩
theorem UniformSpace.ofCoreEq_toCore (u : UniformSpace α) (t : TopologicalSpace α)
(h : t = u.toCore.toTopologicalSpace) : .ofCoreEq u.toCore t h = u :=
UniformSpace.ext rfl
#align uniform_space.of_core_eq_to_core UniformSpace.ofCoreEq_toCore
/-- Replace topology in a `UniformSpace` instance with a propositionally (but possibly not
definitionally) equal one. -/
abbrev UniformSpace.replaceTopology {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α)
(h : i = u.toTopologicalSpace) : UniformSpace α where
__ := u
toTopologicalSpace := i
nhds_eq_comap_uniformity x := by rw [h, u.nhds_eq_comap_uniformity]
#align uniform_space.replace_topology UniformSpace.replaceTopology
theorem UniformSpace.replaceTopology_eq {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α)
(h : i = u.toTopologicalSpace) : u.replaceTopology h = u :=
UniformSpace.ext rfl
#align uniform_space.replace_topology_eq UniformSpace.replaceTopology_eq
-- Porting note: rfc: use `UniformSpace.Core.mkOfBasis`? This will change defeq here and there
/-- Define a `UniformSpace` using a "distance" function. The function can be, e.g., the
distance in a (usual or extended) metric space or an absolute value on a ring. -/
def UniformSpace.ofFun {α : Type u} {β : Type v} [OrderedAddCommMonoid β]
(d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x)
(triangle : ∀ x y z, d x z ≤ d x y + d y z)
(half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) :
UniformSpace α :=
.ofCore
{ uniformity := ⨅ r > 0, 𝓟 { x | d x.1 x.2 < r }
refl := le_iInf₂ fun r hr => principal_mono.2 <| idRel_subset.2 fun x => by simpa [refl]
symm := tendsto_iInf_iInf fun r => tendsto_iInf_iInf fun _ => tendsto_principal_principal.2
fun x hx => by rwa [mem_setOf, symm]
comp := le_iInf₂ fun r hr => let ⟨δ, h0, hδr⟩ := half r hr; le_principal_iff.2 <|
mem_of_superset
(mem_lift' <| mem_iInf_of_mem δ <| mem_iInf_of_mem h0 <| mem_principal_self _)
fun (x, z) ⟨y, h₁, h₂⟩ => (triangle _ _ _).trans_lt (hδr _ h₁ _ h₂) }
#align uniform_space.of_fun UniformSpace.ofFun
theorem UniformSpace.hasBasis_ofFun {α : Type u} {β : Type v} [LinearOrderedAddCommMonoid β]
(h₀ : ∃ x : β, 0 < x) (d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x)
(triangle : ∀ x y z, d x z ≤ d x y + d y z)
(half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) :
𝓤[.ofFun d refl symm triangle half].HasBasis ((0 : β) < ·) (fun ε => { x | d x.1 x.2 < ε }) :=
hasBasis_biInf_principal'
(fun ε₁ h₁ ε₂ h₂ => ⟨min ε₁ ε₂, lt_min h₁ h₂, fun _x hx => lt_of_lt_of_le hx (min_le_left _ _),
fun _x hx => lt_of_lt_of_le hx (min_le_right _ _)⟩) h₀
#align uniform_space.has_basis_of_fun UniformSpace.hasBasis_ofFun
section UniformSpace
variable [UniformSpace α]
theorem nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (Prod.mk x) :=
UniformSpace.nhds_eq_comap_uniformity x
#align nhds_eq_comap_uniformity nhds_eq_comap_uniformity
theorem isOpen_uniformity {s : Set α} :
IsOpen s ↔ ∀ x ∈ s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by
simp only [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap_prod_mk]
#align is_open_uniformity isOpen_uniformity
theorem refl_le_uniformity : 𝓟 idRel ≤ 𝓤 α :=
(@UniformSpace.toCore α _).refl
#align refl_le_uniformity refl_le_uniformity
instance uniformity.neBot [Nonempty α] : NeBot (𝓤 α) :=
diagonal_nonempty.principal_neBot.mono refl_le_uniformity
#align uniformity.ne_bot uniformity.neBot
theorem refl_mem_uniformity {x : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) : (x, x) ∈ s :=
refl_le_uniformity h rfl
#align refl_mem_uniformity refl_mem_uniformity
theorem mem_uniformity_of_eq {x y : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) (hx : x = y) : (x, y) ∈ s :=
refl_le_uniformity h hx
#align mem_uniformity_of_eq mem_uniformity_of_eq
theorem symm_le_uniformity : map (@Prod.swap α α) (𝓤 _) ≤ 𝓤 _ :=
UniformSpace.symm
#align symm_le_uniformity symm_le_uniformity
theorem comp_le_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) ≤ 𝓤 α :=
UniformSpace.comp
#align comp_le_uniformity comp_le_uniformity
theorem lift'_comp_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) = 𝓤 α :=
comp_le_uniformity.antisymm <| le_lift'.2 fun _s hs ↦ mem_of_superset hs <|
subset_comp_self <| idRel_subset.2 fun _ ↦ refl_mem_uniformity hs
theorem tendsto_swap_uniformity : Tendsto (@Prod.swap α α) (𝓤 α) (𝓤 α) :=
symm_le_uniformity
#align tendsto_swap_uniformity tendsto_swap_uniformity
theorem comp_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ t ⊆ s :=
(mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| comp_le_uniformity hs
#align comp_mem_uniformity_sets comp_mem_uniformity_sets
/-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`,
we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/
theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) :
∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by
suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2
induction' n with n ihn generalizing s
· simpa
rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩
refine (ihn htU).mono fun U hU => ?_
rw [Function.iterate_succ_apply']
exact
⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts,
(compRel_mono hU.1 hU.2).trans hts⟩
#align eventually_uniformity_iterate_comp_subset eventually_uniformity_iterate_comp_subset
/-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`,
we have `t ○ t ⊆ s`. -/
theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s :=
eventually_uniformity_iterate_comp_subset hs 1
#align eventually_uniformity_comp_subset eventually_uniformity_comp_subset
/-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is transitive. -/
theorem Filter.Tendsto.uniformity_trans {l : Filter β} {f₁ f₂ f₃ : β → α}
(h₁₂ : Tendsto (fun x => (f₁ x, f₂ x)) l (𝓤 α))
(h₂₃ : Tendsto (fun x => (f₂ x, f₃ x)) l (𝓤 α)) : Tendsto (fun x => (f₁ x, f₃ x)) l (𝓤 α) := by
refine le_trans (le_lift'.2 fun s hs => mem_map.2 ?_) comp_le_uniformity
filter_upwards [mem_map.1 (h₁₂ hs), mem_map.1 (h₂₃ hs)] with x hx₁₂ hx₂₃ using ⟨_, hx₁₂, hx₂₃⟩
#align filter.tendsto.uniformity_trans Filter.Tendsto.uniformity_trans
/-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is symmetric. -/
theorem Filter.Tendsto.uniformity_symm {l : Filter β} {f : β → α × α} (h : Tendsto f l (𝓤 α)) :
Tendsto (fun x => ((f x).2, (f x).1)) l (𝓤 α) :=
tendsto_swap_uniformity.comp h
#align filter.tendsto.uniformity_symm Filter.Tendsto.uniformity_symm
/-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is reflexive. -/
theorem tendsto_diag_uniformity (f : β → α) (l : Filter β) :
Tendsto (fun x => (f x, f x)) l (𝓤 α) := fun _s hs =>
mem_map.2 <| univ_mem' fun _ => refl_mem_uniformity hs
#align tendsto_diag_uniformity tendsto_diag_uniformity
theorem tendsto_const_uniformity {a : α} {f : Filter β} : Tendsto (fun _ => (a, a)) f (𝓤 α) :=
tendsto_diag_uniformity (fun _ => a) f
#align tendsto_const_uniformity tendsto_const_uniformity
theorem symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀ a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s :=
have : preimage Prod.swap s ∈ 𝓤 α := symm_le_uniformity hs
⟨s ∩ preimage Prod.swap s, inter_mem hs this, fun _ _ ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩, inter_subset_left⟩
#align symm_of_uniformity symm_of_uniformity
theorem comp_symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀ {a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s :=
let ⟨_t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs
let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁
⟨t', ht', ht'₁ _ _, Subset.trans (monotone_id.compRel monotone_id ht'₂) ht₂⟩
#align comp_symm_of_uniformity comp_symm_of_uniformity
theorem uniformity_le_symm : 𝓤 α ≤ @Prod.swap α α <$> 𝓤 α := by
rw [map_swap_eq_comap_swap]; exact tendsto_swap_uniformity.le_comap
#align uniformity_le_symm uniformity_le_symm
theorem uniformity_eq_symm : 𝓤 α = @Prod.swap α α <$> 𝓤 α :=
le_antisymm uniformity_le_symm symm_le_uniformity
#align uniformity_eq_symm uniformity_eq_symm
@[simp]
theorem comap_swap_uniformity : comap (@Prod.swap α α) (𝓤 α) = 𝓤 α :=
(congr_arg _ uniformity_eq_symm).trans <| comap_map Prod.swap_injective
#align comap_swap_uniformity comap_swap_uniformity
theorem symmetrize_mem_uniformity {V : Set (α × α)} (h : V ∈ 𝓤 α) : symmetrizeRel V ∈ 𝓤 α := by
apply (𝓤 α).inter_sets h
rw [← image_swap_eq_preimage_swap, uniformity_eq_symm]
exact image_mem_map h
#align symmetrize_mem_uniformity symmetrize_mem_uniformity
/-- Symmetric entourages form a basis of `𝓤 α` -/
theorem UniformSpace.hasBasis_symmetric :
(𝓤 α).HasBasis (fun s : Set (α × α) => s ∈ 𝓤 α ∧ SymmetricRel s) id :=
hasBasis_self.2 fun t t_in =>
⟨symmetrizeRel t, symmetrize_mem_uniformity t_in, symmetric_symmetrizeRel t,
symmetrizeRel_subset_self t⟩
#align uniform_space.has_basis_symmetric UniformSpace.hasBasis_symmetric
theorem uniformity_lift_le_swap {g : Set (α × α) → Filter β} {f : Filter β} (hg : Monotone g)
(h : ((𝓤 α).lift fun s => g (preimage Prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f :=
calc
(𝓤 α).lift g ≤ (Filter.map (@Prod.swap α α) <| 𝓤 α).lift g :=
lift_mono uniformity_le_symm le_rfl
_ ≤ _ := by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h
#align uniformity_lift_le_swap uniformity_lift_le_swap
theorem uniformity_lift_le_comp {f : Set (α × α) → Filter β} (h : Monotone f) :
((𝓤 α).lift fun s => f (s ○ s)) ≤ (𝓤 α).lift f :=
calc
((𝓤 α).lift fun s => f (s ○ s)) = ((𝓤 α).lift' fun s : Set (α × α) => s ○ s).lift f := by
rw [lift_lift'_assoc]
· exact monotone_id.compRel monotone_id
· exact h
_ ≤ (𝓤 α).lift f := lift_mono comp_le_uniformity le_rfl
#align uniformity_lift_le_comp uniformity_lift_le_comp
-- Porting note (#10756): new lemma
theorem comp3_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ (t ○ t) ⊆ s :=
let ⟨_t', ht', ht's⟩ := comp_mem_uniformity_sets hs
let ⟨t, ht, htt'⟩ := comp_mem_uniformity_sets ht'
⟨t, ht, (compRel_mono ((subset_comp_self (refl_le_uniformity ht)).trans htt') htt').trans ht's⟩
/-- See also `comp3_mem_uniformity`. -/
theorem comp_le_uniformity3 : ((𝓤 α).lift' fun s : Set (α × α) => s ○ (s ○ s)) ≤ 𝓤 α := fun _ h =>
let ⟨_t, htU, ht⟩ := comp3_mem_uniformity h
mem_of_superset (mem_lift' htU) ht
#align comp_le_uniformity3 comp_le_uniformity3
/-- See also `comp_open_symm_mem_uniformity_sets`. -/
theorem comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ⊆ s := by
obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs
use symmetrizeRel w, symmetrize_mem_uniformity w_in, symmetric_symmetrizeRel w
have : symmetrizeRel w ⊆ w := symmetrizeRel_subset_self w
calc symmetrizeRel w ○ symmetrizeRel w
_ ⊆ w ○ w := by mono
_ ⊆ s := w_sub
#align comp_symm_mem_uniformity_sets comp_symm_mem_uniformity_sets
theorem subset_comp_self_of_mem_uniformity {s : Set (α × α)} (h : s ∈ 𝓤 α) : s ⊆ s ○ s :=
subset_comp_self (refl_le_uniformity h)
#align subset_comp_self_of_mem_uniformity subset_comp_self_of_mem_uniformity
theorem comp_comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ○ t ⊆ s := by
rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, _, w_sub⟩
rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩
use t, t_in, t_symm
have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in
-- Porting note: Needed the following `have`s to make `mono` work
have ht := Subset.refl t
have hw := Subset.refl w
calc
t ○ t ○ t ⊆ w ○ t := by mono
_ ⊆ w ○ (t ○ t) := by mono
_ ⊆ w ○ w := by mono
_ ⊆ s := w_sub
#align comp_comp_symm_mem_uniformity_sets comp_comp_symm_mem_uniformity_sets
/-!
### Balls in uniform spaces
-/
/-- The ball around `(x : β)` with respect to `(V : Set (β × β))`. Intended to be
used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the
notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/
def UniformSpace.ball (x : β) (V : Set (β × β)) : Set β :=
Prod.mk x ⁻¹' V
#align uniform_space.ball UniformSpace.ball
open UniformSpace (ball)
theorem UniformSpace.mem_ball_self (x : α) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : x ∈ ball x V :=
refl_mem_uniformity hV
#align uniform_space.mem_ball_self UniformSpace.mem_ball_self
/-- The triangle inequality for `UniformSpace.ball` -/
theorem mem_ball_comp {V W : Set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) :
z ∈ ball x (V ○ W) :=
prod_mk_mem_compRel h h'
#align mem_ball_comp mem_ball_comp
theorem ball_subset_of_comp_subset {V W : Set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) :
ball x W ⊆ ball y V := fun _z z_in => h' (mem_ball_comp h z_in)
#align ball_subset_of_comp_subset ball_subset_of_comp_subset
theorem ball_mono {V W : Set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W :=
preimage_mono h
#align ball_mono ball_mono
theorem ball_inter (x : β) (V W : Set (β × β)) : ball x (V ∩ W) = ball x V ∩ ball x W :=
preimage_inter
#align ball_inter ball_inter
theorem ball_inter_left (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x V :=
ball_mono inter_subset_left x
#align ball_inter_left ball_inter_left
theorem ball_inter_right (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x W :=
ball_mono inter_subset_right x
#align ball_inter_right ball_inter_right
theorem mem_ball_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x y} :
x ∈ ball y V ↔ y ∈ ball x V :=
show (x, y) ∈ Prod.swap ⁻¹' V ↔ (x, y) ∈ V by
unfold SymmetricRel at hV
rw [hV]
#align mem_ball_symmetry mem_ball_symmetry
theorem ball_eq_of_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x} :
ball x V = { y | (y, x) ∈ V } := by
ext y
rw [mem_ball_symmetry hV]
exact Iff.rfl
#align ball_eq_of_symmetry ball_eq_of_symmetry
theorem mem_comp_of_mem_ball {V W : Set (β × β)} {x y z : β} (hV : SymmetricRel V)
(hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W := by
rw [mem_ball_symmetry hV] at hx
exact ⟨z, hx, hy⟩
#align mem_comp_of_mem_ball mem_comp_of_mem_ball
theorem UniformSpace.isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) :=
hV.preimage <| continuous_const.prod_mk continuous_id
#align uniform_space.is_open_ball UniformSpace.isOpen_ball
theorem UniformSpace.isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) :
IsClosed (ball x V) :=
hV.preimage <| continuous_const.prod_mk continuous_id
theorem mem_comp_comp {V W M : Set (β × β)} (hW' : SymmetricRel W) {p : β × β} :
p ∈ V ○ M ○ W ↔ (ball p.1 V ×ˢ ball p.2 W ∩ M).Nonempty := by
cases' p with x y
constructor
· rintro ⟨z, ⟨w, hpw, hwz⟩, hzy⟩
exact ⟨(w, z), ⟨hpw, by rwa [mem_ball_symmetry hW']⟩, hwz⟩
· rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩
rw [mem_ball_symmetry hW'] at z_in
exact ⟨z, ⟨w, w_in, hwz⟩, z_in⟩
#align mem_comp_comp mem_comp_comp
/-!
### Neighborhoods in uniform spaces
-/
theorem mem_nhds_uniformity_iff_right {x : α} {s : Set α} :
s ∈ 𝓝 x ↔ { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by
simp only [nhds_eq_comap_uniformity, mem_comap_prod_mk]
#align mem_nhds_uniformity_iff_right mem_nhds_uniformity_iff_right
theorem mem_nhds_uniformity_iff_left {x : α} {s : Set α} :
s ∈ 𝓝 x ↔ { p : α × α | p.2 = x → p.1 ∈ s } ∈ 𝓤 α := by
rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right]
simp only [map_def, mem_map, preimage_setOf_eq, Prod.snd_swap, Prod.fst_swap]
#align mem_nhds_uniformity_iff_left mem_nhds_uniformity_iff_left
theorem nhdsWithin_eq_comap_uniformity_of_mem {x : α} {T : Set α} (hx : x ∈ T) (S : Set α) :
𝓝[S] x = (𝓤 α ⊓ 𝓟 (T ×ˢ S)).comap (Prod.mk x) := by
simp [nhdsWithin, nhds_eq_comap_uniformity, hx]
theorem nhdsWithin_eq_comap_uniformity {x : α} (S : Set α) :
𝓝[S] x = (𝓤 α ⊓ 𝓟 (univ ×ˢ S)).comap (Prod.mk x) :=
nhdsWithin_eq_comap_uniformity_of_mem (mem_univ _) S
/-- See also `isOpen_iff_open_ball_subset`. -/
theorem isOpen_iff_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, ball x V ⊆ s := by
simp_rw [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap, ball]
#align is_open_iff_ball_subset isOpen_iff_ball_subset
theorem nhds_basis_uniformity' {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s)
{x : α} : (𝓝 x).HasBasis p fun i => ball x (s i) := by
rw [nhds_eq_comap_uniformity]
exact h.comap (Prod.mk x)
#align nhds_basis_uniformity' nhds_basis_uniformity'
theorem nhds_basis_uniformity {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s)
{x : α} : (𝓝 x).HasBasis p fun i => { y | (y, x) ∈ s i } := by
replace h := h.comap Prod.swap
rw [comap_swap_uniformity] at h
exact nhds_basis_uniformity' h
#align nhds_basis_uniformity nhds_basis_uniformity
theorem nhds_eq_comap_uniformity' {x : α} : 𝓝 x = (𝓤 α).comap fun y => (y, x) :=
(nhds_basis_uniformity (𝓤 α).basis_sets).eq_of_same_basis <| (𝓤 α).basis_sets.comap _
#align nhds_eq_comap_uniformity' nhds_eq_comap_uniformity'
theorem UniformSpace.mem_nhds_iff {x : α} {s : Set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, ball x V ⊆ s := by
rw [nhds_eq_comap_uniformity, mem_comap]
simp_rw [ball]
#align uniform_space.mem_nhds_iff UniformSpace.mem_nhds_iff
theorem UniformSpace.ball_mem_nhds (x : α) ⦃V : Set (α × α)⦄ (V_in : V ∈ 𝓤 α) : ball x V ∈ 𝓝 x := by
rw [UniformSpace.mem_nhds_iff]
exact ⟨V, V_in, Subset.rfl⟩
#align uniform_space.ball_mem_nhds UniformSpace.ball_mem_nhds
theorem UniformSpace.ball_mem_nhdsWithin {x : α} {S : Set α} ⦃V : Set (α × α)⦄ (x_in : x ∈ S)
(V_in : V ∈ 𝓤 α ⊓ 𝓟 (S ×ˢ S)) : ball x V ∈ 𝓝[S] x := by
rw [nhdsWithin_eq_comap_uniformity_of_mem x_in, mem_comap]
exact ⟨V, V_in, Subset.rfl⟩
theorem UniformSpace.mem_nhds_iff_symm {x : α} {s : Set α} :
s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, SymmetricRel V ∧ ball x V ⊆ s := by
rw [UniformSpace.mem_nhds_iff]
constructor
· rintro ⟨V, V_in, V_sub⟩
use symmetrizeRel V, symmetrize_mem_uniformity V_in, symmetric_symmetrizeRel V
exact Subset.trans (ball_mono (symmetrizeRel_subset_self V) x) V_sub
· rintro ⟨V, V_in, _, V_sub⟩
exact ⟨V, V_in, V_sub⟩
#align uniform_space.mem_nhds_iff_symm UniformSpace.mem_nhds_iff_symm
theorem UniformSpace.hasBasis_nhds (x : α) :
HasBasis (𝓝 x) (fun s : Set (α × α) => s ∈ 𝓤 α ∧ SymmetricRel s) fun s => ball x s :=
⟨fun t => by simp [UniformSpace.mem_nhds_iff_symm, and_assoc]⟩
#align uniform_space.has_basis_nhds UniformSpace.hasBasis_nhds
open UniformSpace
theorem UniformSpace.mem_closure_iff_symm_ball {s : Set α} {x} :
x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → SymmetricRel V → (s ∩ ball x V).Nonempty := by
simp [mem_closure_iff_nhds_basis (hasBasis_nhds x), Set.Nonempty]
#align uniform_space.mem_closure_iff_symm_ball UniformSpace.mem_closure_iff_symm_ball
theorem UniformSpace.mem_closure_iff_ball {s : Set α} {x} :
x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → (ball x V ∩ s).Nonempty := by
simp [mem_closure_iff_nhds_basis' (nhds_basis_uniformity' (𝓤 α).basis_sets)]
#align uniform_space.mem_closure_iff_ball UniformSpace.mem_closure_iff_ball
theorem UniformSpace.hasBasis_nhds_prod (x y : α) :
HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ SymmetricRel s) fun s => ball x s ×ˢ ball y s := by
rw [nhds_prod_eq]
apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y)
rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩
exact
⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V,
ball_inter_right y U V⟩
#align uniform_space.has_basis_nhds_prod UniformSpace.hasBasis_nhds_prod
theorem nhds_eq_uniformity {x : α} : 𝓝 x = (𝓤 α).lift' (ball x) :=
(nhds_basis_uniformity' (𝓤 α).basis_sets).eq_biInf
#align nhds_eq_uniformity nhds_eq_uniformity
theorem nhds_eq_uniformity' {x : α} : 𝓝 x = (𝓤 α).lift' fun s => { y | (y, x) ∈ s } :=
(nhds_basis_uniformity (𝓤 α).basis_sets).eq_biInf
#align nhds_eq_uniformity' nhds_eq_uniformity'
theorem mem_nhds_left (x : α) {s : Set (α × α)} (h : s ∈ 𝓤 α) : { y : α | (x, y) ∈ s } ∈ 𝓝 x :=
ball_mem_nhds x h
#align mem_nhds_left mem_nhds_left
theorem mem_nhds_right (y : α) {s : Set (α × α)} (h : s ∈ 𝓤 α) : { x : α | (x, y) ∈ s } ∈ 𝓝 y :=
mem_nhds_left _ (symm_le_uniformity h)
#align mem_nhds_right mem_nhds_right
theorem exists_mem_nhds_ball_subset_of_mem_nhds {a : α} {U : Set α} (h : U ∈ 𝓝 a) :
∃ V ∈ 𝓝 a, ∃ t ∈ 𝓤 α, ∀ a' ∈ V, UniformSpace.ball a' t ⊆ U :=
let ⟨t, ht, htU⟩ := comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 h)
⟨_, mem_nhds_left a ht, t, ht, fun a₁ h₁ a₂ h₂ => @htU (a, a₂) ⟨a₁, h₁, h₂⟩ rfl⟩
#align exists_mem_nhds_ball_subset_of_mem_nhds exists_mem_nhds_ball_subset_of_mem_nhds
theorem tendsto_right_nhds_uniformity {a : α} : Tendsto (fun a' => (a', a)) (𝓝 a) (𝓤 α) := fun _ =>
mem_nhds_right a
#align tendsto_right_nhds_uniformity tendsto_right_nhds_uniformity
theorem tendsto_left_nhds_uniformity {a : α} : Tendsto (fun a' => (a, a')) (𝓝 a) (𝓤 α) := fun _ =>
mem_nhds_left a
#align tendsto_left_nhds_uniformity tendsto_left_nhds_uniformity
theorem lift_nhds_left {x : α} {g : Set α → Filter β} (hg : Monotone g) :
(𝓝 x).lift g = (𝓤 α).lift fun s : Set (α × α) => g (ball x s) := by
rw [nhds_eq_comap_uniformity, comap_lift_eq2 hg]
simp_rw [ball, Function.comp]
#align lift_nhds_left lift_nhds_left
theorem lift_nhds_right {x : α} {g : Set α → Filter β} (hg : Monotone g) :
(𝓝 x).lift g = (𝓤 α).lift fun s : Set (α × α) => g { y | (y, x) ∈ s } := by
rw [nhds_eq_comap_uniformity', comap_lift_eq2 hg]
simp_rw [Function.comp, preimage]
#align lift_nhds_right lift_nhds_right
theorem nhds_nhds_eq_uniformity_uniformity_prod {a b : α} :
𝓝 a ×ˢ 𝓝 b = (𝓤 α).lift fun s : Set (α × α) =>
(𝓤 α).lift' fun t => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ t } := by
rw [nhds_eq_uniformity', nhds_eq_uniformity, prod_lift'_lift']
exacts [rfl, monotone_preimage, monotone_preimage]
#align nhds_nhds_eq_uniformity_uniformity_prod nhds_nhds_eq_uniformity_uniformity_prod
theorem nhds_eq_uniformity_prod {a b : α} :
𝓝 (a, b) =
(𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by
rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift']
· exact fun s => monotone_const.set_prod monotone_preimage
· refine fun t => Monotone.set_prod ?_ monotone_const
exact monotone_preimage (f := fun y => (y, a))
#align nhds_eq_uniformity_prod nhds_eq_uniformity_prod
theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) :
∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧
t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by
let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d }
have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp =>
mem_nhds_iff.mp <|
show cl_d ∈ 𝓝 (x, y) by
rw [nhds_eq_uniformity_prod, mem_lift'_sets]
· exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩
· exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩
choose t ht using this
exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)),
isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left,
fun ⟨a, b⟩ hp => by
simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩,
iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩
#align nhdset_of_mem_uniformity nhdset_of_mem_uniformity
/-- Entourages are neighborhoods of the diagonal. -/
theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by
intro V V_in
rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩
have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by
rw [nhds_prod_eq]
exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in)
apply mem_of_superset this
rintro ⟨u, v⟩ ⟨u_in, v_in⟩
exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in)
#align nhds_le_uniformity nhds_le_uniformity
/-- Entourages are neighborhoods of the diagonal. -/
theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α :=
iSup_le nhds_le_uniformity
#align supr_nhds_le_uniformity iSup_nhds_le_uniformity
/-- Entourages are neighborhoods of the diagonal. -/
theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α :=
(nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity
#align nhds_set_diagonal_le_uniformity nhdsSet_diagonal_le_uniformity
/-!
### Closure and interior in uniform spaces
-/
theorem closure_eq_uniformity (s : Set <| α × α) :
closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ SymmetricRel V }, V ○ s ○ V := by
ext ⟨x, y⟩
simp (config := { contextual := true }) only
[mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq,
and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty]
#align closure_eq_uniformity closure_eq_uniformity
theorem uniformity_hasBasis_closed :
HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by
refine Filter.hasBasis_self.2 fun t h => ?_
rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩
refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩
refine Subset.trans ?_ r
rw [closure_eq_uniformity]
apply iInter_subset_of_subset
apply iInter_subset
exact ⟨w_in, w_symm⟩
#align uniformity_has_basis_closed uniformity_hasBasis_closed
theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure :=
Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right
#align uniformity_eq_uniformity_closure uniformity_eq_uniformity_closure
theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)}
(h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) :=
(@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure
#align filter.has_basis.uniformity_closure Filter.HasBasis.uniformity_closure
/-- Closed entourages form a basis of the uniformity filter. -/
theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure :=
(𝓤 α).basis_sets.uniformity_closure
#align uniformity_has_basis_closure uniformity_hasBasis_closure
theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) :=
calc
closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ SymmetricRel V), V ○ t ○ V := closure_eq_uniformity t
_ = ⋂ V ∈ 𝓤 α, V ○ t ○ V :=
Eq.symm <|
UniformSpace.hasBasis_symmetric.biInter_mem fun V₁ V₂ hV =>
compRel_mono (compRel_mono hV Subset.rfl) hV
_ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc]
#align closure_eq_inter_uniformity closure_eq_inter_uniformity
theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior :=
le_antisymm
(le_iInf₂ fun d hd => by
let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd
let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs
have : s ⊆ interior d :=
calc
s ⊆ t := hst
_ ⊆ interior d :=
ht.subset_interior_iff.mpr fun x (hx : x ∈ t) =>
let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx
hs_comp ⟨x, h₁, y, h₂, h₃⟩
have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this
simp [this])
fun s hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset
#align uniformity_eq_uniformity_interior uniformity_eq_uniformity_interior
theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by
rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs
#align interior_mem_uniformity interior_mem_uniformity
theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s :=
let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h
⟨t, ht_mem, htc, hts⟩
#align mem_uniformity_is_closed mem_uniformity_isClosed
theorem isOpen_iff_open_ball_subset {s : Set α} :
IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by
rw [isOpen_iff_ball_subset]
constructor <;> intro h x hx
· obtain ⟨V, hV, hV'⟩ := h x hx
exact
⟨interior V, interior_mem_uniformity hV, isOpen_interior,
(ball_mono interior_subset x).trans hV'⟩
· obtain ⟨V, hV, -, hV'⟩ := h x hx
exact ⟨V, hV, hV'⟩
#align is_open_iff_open_ball_subset isOpen_iff_open_ball_subset
/-- The uniform neighborhoods of all points of a dense set cover the whole space. -/
theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) :
⋃ x ∈ s, ball x U = univ := by
refine iUnion₂_eq_univ_iff.2 fun y => ?_
rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩
exact ⟨x, hxs, hxy⟩
#align dense.bUnion_uniformity_ball Dense.biUnion_uniformity_ball
/-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/
lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α}
(xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) :
⋃ i, UniformSpace.ball (xs i) U = univ := by
rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)]
exact Dense.biUnion_uniformity_ball xs_dense hU
/-!
### Uniformity bases
-/
/-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/
theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id :=
hasBasis_self.2 fun s hs =>
⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩
#align uniformity_has_basis_open uniformity_hasBasis_open
theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)}
(h : (𝓤 α).HasBasis p s) {t : Set (α × α)} :
t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t :=
h.mem_iff.trans <| by simp only [Prod.forall, subset_def]
#align filter.has_basis.mem_uniformity_iff Filter.HasBasis.mem_uniformity_iff
/-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis
of `𝓤 α`. -/
theorem uniformity_hasBasis_open_symmetric :
HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ SymmetricRel V) id := by
simp only [← and_assoc]
refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩
exact
⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩,
symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩
#align uniformity_has_basis_open_symmetric uniformity_hasBasis_open_symmetric
theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, IsOpen t ∧ SymmetricRel t ∧ t ○ t ⊆ s := by
obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs
obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁
exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩
#align comp_open_symm_mem_uniformity_sets comp_open_symm_mem_uniformity_sets
section
variable (α)
theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] :
∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, SymmetricRel (V n) :=
let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis
⟨U, hbasis, fun n => (hsym n).2⟩
#align uniform_space.has_seq_basis UniformSpace.has_seq_basis
end
theorem Filter.HasBasis.biInter_biUnion_ball {p : ι → Prop} {U : ι → Set (α × α)}
(h : HasBasis (𝓤 α) p U) (s : Set α) :
(⋂ (i) (_ : p i), ⋃ x ∈ s, ball x (U i)) = closure s := by
ext x
simp [mem_closure_iff_nhds_basis (nhds_basis_uniformity h), ball]
#align filter.has_basis.bInter_bUnion_ball Filter.HasBasis.biInter_biUnion_ball
/-! ### Uniform continuity -/
/-- A function `f : α → β` is *uniformly continuous* if `(f x, f y)` tends to the diagonal
as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then
`f x` is close to `f y` no matter where `x` and `y` are located in `α`. -/
def UniformContinuous [UniformSpace β] (f : α → β) :=
Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α) (𝓤 β)
#align uniform_continuous UniformContinuous
/-- Notation for uniform continuity with respect to non-standard `UniformSpace` instances. -/
scoped[Uniformity] notation "UniformContinuous[" u₁ ", " u₂ "]" => @UniformContinuous _ _ u₁ u₂
/-- A function `f : α → β` is *uniformly continuous* on `s : Set α` if `(f x, f y)` tends to
the diagonal as `(x, y)` tends to the diagonal while remaining in `s ×ˢ s`.
In other words, if `x` is sufficiently close to `y`, then `f x` is close to
`f y` no matter where `x` and `y` are located in `s`. -/
def UniformContinuousOn [UniformSpace β] (f : α → β) (s : Set α) : Prop :=
Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α ⊓ 𝓟 (s ×ˢ s)) (𝓤 β)
#align uniform_continuous_on UniformContinuousOn
theorem uniformContinuous_def [UniformSpace β] {f : α → β} :
UniformContinuous f ↔ ∀ r ∈ 𝓤 β, { x : α × α | (f x.1, f x.2) ∈ r } ∈ 𝓤 α :=
Iff.rfl
#align uniform_continuous_def uniformContinuous_def
theorem uniformContinuous_iff_eventually [UniformSpace β] {f : α → β} :
UniformContinuous f ↔ ∀ r ∈ 𝓤 β, ∀ᶠ x : α × α in 𝓤 α, (f x.1, f x.2) ∈ r :=
Iff.rfl
#align uniform_continuous_iff_eventually uniformContinuous_iff_eventually
theorem uniformContinuousOn_univ [UniformSpace β] {f : α → β} :
UniformContinuousOn f univ ↔ UniformContinuous f := by
rw [UniformContinuousOn, UniformContinuous, univ_prod_univ, principal_univ, inf_top_eq]
#align uniform_continuous_on_univ uniformContinuousOn_univ
theorem uniformContinuous_of_const [UniformSpace β] {c : α → β} (h : ∀ a b, c a = c b) :
UniformContinuous c :=
have : (fun x : α × α => (c x.fst, c x.snd)) ⁻¹' idRel = univ :=
eq_univ_iff_forall.2 fun ⟨a, b⟩ => h a b
le_trans (map_le_iff_le_comap.2 <| by simp [comap_principal, this, univ_mem]) refl_le_uniformity
#align uniform_continuous_of_const uniformContinuous_of_const
theorem uniformContinuous_id : UniformContinuous (@id α) := tendsto_id
#align uniform_continuous_id uniformContinuous_id
theorem uniformContinuous_const [UniformSpace β] {b : β} : UniformContinuous fun _ : α => b :=
uniformContinuous_of_const fun _ _ => rfl
#align uniform_continuous_const uniformContinuous_const
nonrec theorem UniformContinuous.comp [UniformSpace β] [UniformSpace γ] {g : β → γ} {f : α → β}
(hg : UniformContinuous g) (hf : UniformContinuous f) : UniformContinuous (g ∘ f) :=
hg.comp hf
#align uniform_continuous.comp UniformContinuous.comp
theorem Filter.HasBasis.uniformContinuous_iff {ι'} [UniformSpace β] {p : ι → Prop}
{s : ι → Set (α × α)} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)}
(hb : (𝓤 β).HasBasis q t) {f : α → β} :
UniformContinuous f ↔ ∀ i, q i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ t i :=
(ha.tendsto_iff hb).trans <| by simp only [Prod.forall]
#align filter.has_basis.uniform_continuous_iff Filter.HasBasis.uniformContinuous_iff
theorem Filter.HasBasis.uniformContinuousOn_iff {ι'} [UniformSpace β] {p : ι → Prop}
{s : ι → Set (α × α)} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)}
(hb : (𝓤 β).HasBasis q t) {f : α → β} {S : Set α} :
UniformContinuousOn f S ↔
∀ i, q i → ∃ j, p j ∧ ∀ x, x ∈ S → ∀ y, y ∈ S → (x, y) ∈ s j → (f x, f y) ∈ t i :=
((ha.inf_principal (S ×ˢ S)).tendsto_iff hb).trans <| by
simp_rw [Prod.forall, Set.inter_comm (s _), forall_mem_comm, mem_inter_iff, mem_prod, and_imp]
#align filter.has_basis.uniform_continuous_on_iff Filter.HasBasis.uniformContinuousOn_iff
end UniformSpace
open uniformity
section Constructions
instance : PartialOrder (UniformSpace α) :=
PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext
protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl
instance : InfSet (UniformSpace α) :=
⟨fun s =>
UniformSpace.ofCore
{ uniformity := ⨅ u ∈ s, 𝓤[u]
refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl
symm := le_iInf₂ fun u hu =>
le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm
comp := le_iInf₂ fun u hu =>
le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩
protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α}
(h : t ∈ tt) : sInf tt ≤ t :=
show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h
protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α}
(h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt :=
show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h
instance : Top (UniformSpace α) :=
⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩
instance : Bot (UniformSpace α) :=
⟨{ toTopologicalSpace := ⊥
uniformity := 𝓟 idRel
symm := by simp [Tendsto]
comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset
nhds_eq_comap_uniformity := fun s => by
let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α
simp [idRel] }⟩
instance : Inf (UniformSpace α) :=
⟨fun u₁ u₂ =>
{ uniformity := 𝓤[u₁] ⊓ 𝓤[u₂]
symm := u₁.symm.inf u₂.symm
comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp
toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace
nhds_eq_comap_uniformity := fun _ ↦ by
rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁,
@nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩
instance : CompleteLattice (UniformSpace α) :=
{ inferInstanceAs (PartialOrder (UniformSpace α)) with
sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x }
le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h
le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h
sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩
inf := (· ⊓ ·)
le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂
inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left
inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right
top := ⊤
le_top := fun a => show a.uniformity ≤ ⊤ from le_top
bot := ⊥
bot_le := fun u => u.toCore.refl
sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t }
le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h
sSup_le := fun _ _ h => UniformSpace.sInf_le h
sInf := sInf
le_sInf := fun _ _ hs => UniformSpace.le_sInf hs
sInf_le := fun _ _ ha => UniformSpace.sInf_le ha }
theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] :=
iInf_range
#align infi_uniformity iInf_uniformity
theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl
#align inf_uniformity inf_uniformity
lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl
lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl
instance inhabitedUniformSpace : Inhabited (UniformSpace α) :=
⟨⊥⟩
#align inhabited_uniform_space inhabitedUniformSpace
instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) :=
⟨@UniformSpace.toCore _ default⟩
#align inhabited_uniform_space_core inhabitedUniformSpaceCore
instance [Subsingleton α] : Unique (UniformSpace α) where
uniq u := bot_unique <| le_principal_iff.2 <| by
rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem
/-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f`
is the inverse image in the filter sense of the induced function `α × α → β × β`.
See note [reducible non-instances]. -/
abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where
uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2)
symm := by
simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)]
exact tendsto_swap_uniformity.comp tendsto_comap
comp := le_trans
(by
rw [comap_lift'_eq, comap_lift'_eq2]
· exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩
· exact monotone_id.compRel monotone_id)
(comap_mono u.comp)
toTopologicalSpace := u.toTopologicalSpace.induced f
nhds_eq_comap_uniformity x := by
simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp]
#align uniform_space.comap UniformSpace.comap
theorem uniformity_comap {_ : UniformSpace β} (f : α → β) :
𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) :=
rfl
#align uniformity_comap uniformity_comap
@[simp]
theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by
ext : 2
rw [uniformity_comap, Prod.map_id, comap_id]
#align uniform_space_comap_id uniformSpace_comap_id
theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} :
UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by
ext1
simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map]
#align uniform_space.comap_comap UniformSpace.comap_comap
theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} :
(u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f :=
UniformSpace.ext Filter.comap_inf
#align uniform_space.comap_inf UniformSpace.comap_inf
theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} :
(⨅ i, u i).comap f = ⨅ i, (u i).comap f := by
ext : 1
simp [uniformity_comap, iInf_uniformity]
#align uniform_space.comap_infi UniformSpace.comap_iInf
theorem UniformSpace.comap_mono {α γ} {f : α → γ} :
Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu =>
Filter.comap_mono hu
#align uniform_space.comap_mono UniformSpace.comap_mono
theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} :
UniformContinuous f ↔ uα ≤ uβ.comap f :=
Filter.map_le_iff_le_comap
#align uniform_continuous_iff uniformContinuous_iff
theorem le_iff_uniformContinuous_id {u v : UniformSpace α} :
u ≤ v ↔ @UniformContinuous _ _ u v id := by
rw [uniformContinuous_iff, uniformSpace_comap_id, id]
#align le_iff_uniform_continuous_id le_iff_uniformContinuous_id
theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] :
@UniformContinuous α β (UniformSpace.comap f u) u f :=
tendsto_comap
#align uniform_continuous_comap uniformContinuous_comap
theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α]
(h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g :=
tendsto_comap_iff.2 h
#align uniform_continuous_comap' uniformContinuous_comap'
namespace UniformSpace
theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) :
@nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤
@nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by
rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl
#align to_nhds_mono UniformSpace.to_nhds_mono
theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) :
@UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ :=
le_of_nhds_le_nhds <| to_nhds_mono h
#align to_topological_space_mono UniformSpace.toTopologicalSpace_mono
theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} :
@UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) =
TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) :=
rfl
#align to_topological_space_comap UniformSpace.toTopologicalSpace_comap
theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl
#align to_topological_space_bot UniformSpace.toTopologicalSpace_bot
theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl
#align to_topological_space_top UniformSpace.toTopologicalSpace_top
theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} :
(iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace :=
TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf,
iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf]
#align to_topological_space_infi UniformSpace.toTopologicalSpace_iInf
theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} :
(sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by
rw [sInf_eq_iInf]
simp only [← toTopologicalSpace_iInf]
#align to_topological_space_Inf UniformSpace.toTopologicalSpace_sInf
theorem toTopologicalSpace_inf {u v : UniformSpace α} :
(u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace :=
rfl
#align to_topological_space_inf UniformSpace.toTopologicalSpace_inf
end UniformSpace
theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β}
(hf : UniformContinuous f) : Continuous f :=
continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <|
uniformContinuous_iff.1 hf
#align uniform_continuous.continuous UniformContinuous.continuous
/-- Uniform space structure on `ULift α`. -/
instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) :=
UniformSpace.comap ULift.down ‹_›
#align ulift.uniform_space ULift.uniformSpace
section UniformContinuousInfi
-- Porting note: renamed for dot notation; add an `iff` lemma?
theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β}
(h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) :
UniformContinuous[u₁, u₂ ⊓ u₃] f :=
tendsto_inf.mpr ⟨h₁, h₂⟩
#align uniform_continuous_inf_rng UniformContinuous.inf_rng
-- Porting note: renamed for dot notation
theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β}
(hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f :=
tendsto_inf_left hf
#align uniform_continuous_inf_dom_left UniformContinuous.inf_dom_left
-- Porting note: renamed for dot notation
theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β}
(hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f :=
tendsto_inf_right hf
#align uniform_continuous_inf_dom_right UniformContinuous.inf_dom_right
theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β}
{u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) :
UniformContinuous[sInf u₁, u₂] f := by
delta UniformContinuous
rw [sInf_eq_iInf', iInf_uniformity]
exact tendsto_iInf' ⟨u, h₁⟩ hf
#align uniform_continuous_Inf_dom uniformContinuous_sInf_dom
theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} :
UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by
delta UniformContinuous
rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall]
#align uniform_continuous_Inf_rng uniformContinuous_sInf_rng
theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β}
{i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by
delta UniformContinuous
rw [iInf_uniformity]
exact tendsto_iInf' i hf
#align uniform_continuous_infi_dom uniformContinuous_iInf_dom
theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} :
UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by
delta UniformContinuous
rw [iInf_uniformity, tendsto_iInf]
#align uniform_continuous_infi_rng uniformContinuous_iInf_rng
end UniformContinuousInfi
/-- A uniform space with the discrete uniformity has the discrete topology. -/
theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) :
DiscreteTopology α :=
⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩
#align discrete_topology_of_discrete_uniformity discreteTopology_of_discrete_uniformity
instance : UniformSpace Empty := ⊥
instance : UniformSpace PUnit := ⊥
instance : UniformSpace Bool := ⊥
instance : UniformSpace ℕ := ⊥
instance : UniformSpace ℤ := ⊥
section
variable [UniformSpace α]
open Additive Multiplicative
instance : UniformSpace (Additive α) := ‹UniformSpace α›
instance : UniformSpace (Multiplicative α) := ‹UniformSpace α›
theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) :=
uniformContinuous_id
#align uniform_continuous_of_mul uniformContinuous_ofMul
theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) :=
uniformContinuous_id
#align uniform_continuous_to_mul uniformContinuous_toMul
theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) :=
uniformContinuous_id
#align uniform_continuous_of_add uniformContinuous_ofAdd
theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) :=
uniformContinuous_id
#align uniform_continuous_to_add uniformContinuous_toAdd
theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl
#align uniformity_additive uniformity_additive
theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl
#align uniformity_multiplicative uniformity_multiplicative
end
instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) :=
UniformSpace.comap Subtype.val t
theorem uniformity_subtype {p : α → Prop} [UniformSpace α] :
𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) :=
rfl
#align uniformity_subtype uniformity_subtype
theorem uniformity_setCoe {s : Set α} [UniformSpace α] :
𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) :=
rfl
#align uniformity_set_coe uniformity_setCoe
-- Porting note (#10756): new lemma
theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] :
map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by
rw [uniformity_setCoe, map_comap, range_prod_map, Subtype.range_val]
theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] :
UniformContinuous (Subtype.val : { a : α // p a } → α) :=
uniformContinuous_comap
#align uniform_continuous_subtype_val uniformContinuous_subtype_val
#align uniform_continuous_subtype_coe uniformContinuous_subtype_val
theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α}
(hf : UniformContinuous f) (h : ∀ x, p (f x)) :
UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) :=
uniformContinuous_comap' hf
#align uniform_continuous.subtype_mk UniformContinuous.subtype_mk
theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} :
UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by
delta UniformContinuousOn UniformContinuous
rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl
#align uniform_continuous_on_iff_restrict uniformContinuousOn_iff_restrict
theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β}
{s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) :
Tendsto f (𝓝 a) (𝓝 (f a)) := by
rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm]
exact tendsto_map' hf.continuous.continuousAt
#align tendsto_of_uniform_continuous_subtype tendsto_of_uniformContinuous_subtype
theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α}
(h : UniformContinuousOn f s) : ContinuousOn f s := by
rw [uniformContinuousOn_iff_restrict] at h
rw [continuousOn_iff_continuous_restrict]
exact h.continuous
#align uniform_continuous_on.continuous_on UniformContinuousOn.continuousOn
@[to_additive]
instance [UniformSpace α] : UniformSpace αᵐᵒᵖ :=
UniformSpace.comap MulOpposite.unop ‹_›
@[to_additive]
theorem uniformity_mulOpposite [UniformSpace α] :
𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) :=
rfl
#align uniformity_mul_opposite uniformity_mulOpposite
#align uniformity_add_opposite uniformity_addOpposite
@[to_additive (attr := simp)]
theorem comap_uniformity_mulOpposite [UniformSpace α] :
comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by
simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id
#align comap_uniformity_mul_opposite comap_uniformity_mulOpposite
#align comap_uniformity_add_opposite comap_uniformity_addOpposite
namespace MulOpposite
@[to_additive]
theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) :=
uniformContinuous_comap
#align mul_opposite.uniform_continuous_unop MulOpposite.uniformContinuous_unop
#align add_opposite.uniform_continuous_unop AddOpposite.uniformContinuous_unop
@[to_additive]
theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) :=
uniformContinuous_comap' uniformContinuous_id
#align mul_opposite.uniform_continuous_op MulOpposite.uniformContinuous_op
#align add_opposite.uniform_continuous_op AddOpposite.uniformContinuous_op
end MulOpposite
section Prod
/- a similar product space is possible on the function space (uniformity of pointwise convergence),
but we want to have the uniformity of uniform convergence on function spaces -/
instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) :=
u₁.comap Prod.fst ⊓ u₂.comap Prod.snd
-- check the above produces no diamond for `simp` and typeclass search
example [UniformSpace α] [UniformSpace β] :
(instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by
with_reducible_and_instances rfl
theorem uniformity_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) =
((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓
(𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) :=
rfl
#align uniformity_prod uniformity_prod
instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)]
[UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by
rw [uniformity_prod]
infer_instance
theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) =
comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by
dsimp [SProd.sprod]
rw [uniformity_prod, Filter.prod, comap_inf, comap_comap, comap_comap]; rfl
#align uniformity_prod_eq_comap_prod uniformity_prod_eq_comap_prod
theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by
rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod]
#align uniformity_prod_eq_prod uniformity_prod_eq_prod
theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β]
{s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2)
(hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by
rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf
rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩
exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩
#align mem_uniformity_of_uniform_continuous_invariant mem_uniformity_of_uniformContinuous_invariant
theorem mem_uniform_prod [t₁ : UniformSpace α] [t₂ : UniformSpace β] {a : Set (α × α)}
{b : Set (β × β)} (ha : a ∈ 𝓤 α) (hb : b ∈ 𝓤 β) :
{ p : (α × β) × α × β | (p.1.1, p.2.1) ∈ a ∧ (p.1.2, p.2.2) ∈ b } ∈ 𝓤 (α × β) := by
rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap ha) (preimage_mem_comap hb)
#align mem_uniform_prod mem_uniform_prod
theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] :
Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) :=
le_trans (map_mono inf_le_left) map_comap_le
#align tendsto_prod_uniformity_fst tendsto_prod_uniformity_fst
theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] :
Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) :=
le_trans (map_mono inf_le_right) map_comap_le
#align tendsto_prod_uniformity_snd tendsto_prod_uniformity_snd
theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] :
UniformContinuous fun p : α × β => p.1 :=
tendsto_prod_uniformity_fst
#align uniform_continuous_fst uniformContinuous_fst
theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] :
UniformContinuous fun p : α × β => p.2 :=
tendsto_prod_uniformity_snd
#align uniform_continuous_snd uniformContinuous_snd
variable [UniformSpace α] [UniformSpace β] [UniformSpace γ]
theorem UniformContinuous.prod_mk {f₁ : α → β} {f₂ : α → γ} (h₁ : UniformContinuous f₁)
(h₂ : UniformContinuous f₂) : UniformContinuous fun a => (f₁ a, f₂ a) := by
rw [UniformContinuous, uniformity_prod]
exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
#align uniform_continuous.prod_mk UniformContinuous.prod_mk
theorem UniformContinuous.prod_mk_left {f : α × β → γ} (h : UniformContinuous f) (b) :
UniformContinuous fun a => f (a, b) :=
h.comp (uniformContinuous_id.prod_mk uniformContinuous_const)
#align uniform_continuous.prod_mk_left UniformContinuous.prod_mk_left
theorem UniformContinuous.prod_mk_right {f : α × β → γ} (h : UniformContinuous f) (a) :
UniformContinuous fun b => f (a, b) :=
h.comp (uniformContinuous_const.prod_mk uniformContinuous_id)
#align uniform_continuous.prod_mk_right UniformContinuous.prod_mk_right
theorem UniformContinuous.prod_map [UniformSpace δ] {f : α → γ} {g : β → δ}
(hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) :=
(hf.comp uniformContinuous_fst).prod_mk (hg.comp uniformContinuous_snd)
#align uniform_continuous.prod_map UniformContinuous.prod_map
theorem toTopologicalSpace_prod {α} {β} [u : UniformSpace α] [v : UniformSpace β] :
@UniformSpace.toTopologicalSpace (α × β) instUniformSpaceProd =
@instTopologicalSpaceProd α β u.toTopologicalSpace v.toTopologicalSpace :=
rfl
#align to_topological_space_prod toTopologicalSpace_prod
/-- A version of `UniformContinuous.inf_dom_left` for binary functions -/
theorem uniformContinuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α}
{ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ}
(h : by haveI := ua1; haveI := ub1; exact UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2;
exact UniformContinuous fun p : α × β => f p.1 p.2 := by
-- proof essentially copied from `continuous_inf_dom_left₂`
have ha := @UniformContinuous.inf_dom_left _ _ id ua1 ua2 ua1 (@uniformContinuous_id _ (id _))
have hb := @UniformContinuous.inf_dom_left _ _ id ub1 ub2 ub1 (@uniformContinuous_id _ (id _))
have h_unif_cont_id :=
@UniformContinuous.prod_map _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua1 ub1 _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id
#align uniform_continuous_inf_dom_left₂ uniformContinuous_inf_dom_left₂
/-- A version of `UniformContinuous.inf_dom_right` for binary functions -/
| Mathlib/Topology/UniformSpace/Basic.lean | 1,655 | 1,665 | theorem uniformContinuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α}
{ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ}
(h : by haveI := ua2; haveI := ub2; exact UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2;
exact UniformContinuous fun p : α × β => f p.1 p.2 := by |
-- proof essentially copied from `continuous_inf_dom_right₂`
have ha := @UniformContinuous.inf_dom_right _ _ id ua1 ua2 ua2 (@uniformContinuous_id _ (id _))
have hb := @UniformContinuous.inf_dom_right _ _ id ub1 ub2 ub2 (@uniformContinuous_id _ (id _))
have h_unif_cont_id :=
@UniformContinuous.prod_map _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua2 ub2 _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id
|
/-
Copyright (c) 2022 Yuyang Zhao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuyang Zhao
-/
import Batteries.Classes.Order
namespace Batteries.PairingHeapImp
/--
A `Heap` is the nodes of the pairing heap.
Each node have two pointers: `child` going to the first child of this node,
and `sibling` goes to the next sibling of this tree.
So it actually encodes a forest where each node has children
`node.child`, `node.child.sibling`, `node.child.sibling.sibling`, etc.
Each edge in this forest denotes a `le a b` relation that has been checked, so
the root is smaller than everything else under it.
-/
inductive Heap (α : Type u) where
/-- An empty forest, which has depth `0`. -/
| nil : Heap α
/-- A forest consists of a root `a`, a forest `child` elements greater than `a`,
and another forest `sibling`. -/
| node (a : α) (child sibling : Heap α) : Heap α
deriving Repr
/-- `O(n)`. The number of elements in the heap. -/
def Heap.size : Heap α → Nat
| .nil => 0
| .node _ c s => c.size + 1 + s.size
/-- A node containing a single element `a`. -/
def Heap.singleton (a : α) : Heap α := .node a .nil .nil
/-- `O(1)`. Is the heap empty? -/
def Heap.isEmpty : Heap α → Bool
| .nil => true
| _ => false
/-- `O(1)`. Merge two heaps. Ignore siblings. -/
@[specialize] def Heap.merge (le : α → α → Bool) : Heap α → Heap α → Heap α
| .nil, .nil => .nil
| .nil, .node a₂ c₂ _ => .node a₂ c₂ .nil
| .node a₁ c₁ _, .nil => .node a₁ c₁ .nil
| .node a₁ c₁ _, .node a₂ c₂ _ =>
if le a₁ a₂ then .node a₁ (.node a₂ c₂ c₁) .nil else .node a₂ (.node a₁ c₁ c₂) .nil
/-- Auxiliary for `Heap.deleteMin`: merge the forest in pairs. -/
@[specialize] def Heap.combine (le : α → α → Bool) : Heap α → Heap α
| h₁@(.node _ _ h₂@(.node _ _ s)) => merge le (merge le h₁ h₂) (s.combine le)
| h => h
/-- `O(1)`. Get the smallest element in the heap, including the passed in value `a`. -/
@[inline] def Heap.headD (a : α) : Heap α → α
| .nil => a
| .node a _ _ => a
/-- `O(1)`. Get the smallest element in the heap, if it has an element. -/
@[inline] def Heap.head? : Heap α → Option α
| .nil => none
| .node a _ _ => some a
/-- Amortized `O(log n)`. Find and remove the the minimum element from the heap. -/
@[inline] def Heap.deleteMin (le : α → α → Bool) : Heap α → Option (α × Heap α)
| .nil => none
| .node a c _ => (a, combine le c)
/-- Amortized `O(log n)`. Get the tail of the pairing heap after removing the minimum element. -/
@[inline] def Heap.tail? (le : α → α → Bool) (h : Heap α) : Option (Heap α) :=
deleteMin le h |>.map (·.snd)
/-- Amortized `O(log n)`. Remove the minimum element of the heap. -/
@[inline] def Heap.tail (le : α → α → Bool) (h : Heap α) : Heap α :=
tail? le h |>.getD .nil
/-- A predicate says there is no more than one tree. -/
inductive Heap.NoSibling : Heap α → Prop
/-- An empty heap is no more than one tree. -/
| nil : NoSibling .nil
/-- Or there is exactly one tree. -/
| node (a c) : NoSibling (.node a c .nil)
instance : Decidable (Heap.NoSibling s) :=
match s with
| .nil => isTrue .nil
| .node a c .nil => isTrue (.node a c)
| .node _ _ (.node _ _ _) => isFalse nofun
theorem Heap.noSibling_merge (le) (s₁ s₂ : Heap α) :
(s₁.merge le s₂).NoSibling := by
unfold merge
(split <;> try split) <;> constructor
| .lake/packages/batteries/Batteries/Data/PairingHeap.lean | 95 | 101 | theorem Heap.noSibling_combine (le) (s : Heap α) :
(s.combine le).NoSibling := by |
unfold combine; split
· exact noSibling_merge _ _ _
· match s with
| nil | node _ _ nil => constructor
| node _ _ (node _ _ s) => rename_i h; exact (h _ _ _ _ _ rfl).elim
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.Data.Finsupp.Fin
import Mathlib.Data.Finsupp.Indicator
#align_import algebra.big_operators.finsupp from "leanprover-community/mathlib"@"842328d9df7e96fd90fc424e115679c15fb23a71"
/-!
# Big operators for finsupps
This file contains theorems relevant to big operators in finitely supported functions.
-/
noncomputable section
open Finset Function
variable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]
variable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)
variable {s : Finset α} {f : α → ι →₀ A} (i : ι)
variable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)
variable {β M M' N P G H R S : Type*}
namespace Finsupp
/-!
### Declarations about `Finsupp.sum` and `Finsupp.prod`
In most of this section, the domain `β` is assumed to be an `AddMonoid`.
-/
section SumProd
/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/
@[to_additive "`sum f g` is the sum of `g a (f a)` over the support of `f`. "]
def prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=
∏ a ∈ f.support, g a (f a)
#align finsupp.prod Finsupp.prod
#align finsupp.sum Finsupp.sum
variable [Zero M] [Zero M'] [CommMonoid N]
@[to_additive]
theorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)
(h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x ∈ s, g x (f x) := by
refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)
exact not_mem_support_iff.1 hx
#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset
#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset
@[to_additive]
theorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :
f.prod g = ∏ i, g i (f i) :=
f.prod_of_support_subset (subset_univ _) g fun x _ => h x
#align finsupp.prod_fintype Finsupp.prod_fintype
#align finsupp.sum_fintype Finsupp.sum_fintype
@[to_additive (attr := simp)]
theorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :
(single a b).prod h = h a b :=
calc
(single a b).prod h = ∏ x ∈ {a}, h x (single a b x) :=
prod_of_support_subset _ support_single_subset h fun x hx =>
(mem_singleton.1 hx).symm ▸ h_zero
_ = h a b := by simp
#align finsupp.prod_single_index Finsupp.prod_single_index
#align finsupp.sum_single_index Finsupp.sum_single_index
@[to_additive]
theorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}
(h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=
Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]
#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index
#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index
@[to_additive (attr := simp)]
theorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=
rfl
#align finsupp.prod_zero_index Finsupp.prod_zero_index
#align finsupp.sum_zero_index Finsupp.sum_zero_index
@[to_additive]
theorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :
(f.prod fun x v => g.prod fun x' v' => h x v x' v') =
g.prod fun x' v' => f.prod fun x v => h x v x' v' :=
Finset.prod_comm
#align finsupp.prod_comm Finsupp.prod_comm
#align finsupp.sum_comm Finsupp.sum_comm
@[to_additive (attr := simp)]
theorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :
(f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by
dsimp [Finsupp.prod]
rw [f.support.prod_ite_eq]
#align finsupp.prod_ite_eq Finsupp.prod_ite_eq
#align finsupp.sum_ite_eq Finsupp.sum_ite_eq
/- Porting note: simpnf linter, added aux lemma below
Left-hand side simplifies from
Finsupp.sum f fun x v => if a = x then v else 0
to
if ↑f a = 0 then 0 else ↑f a
-/
-- @[simp]
theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :
(f.sum fun x v => ite (a = x) v 0) = f a := by
classical
convert f.sum_ite_eq a fun _ => id
simp [ite_eq_right_iff.2 Eq.symm]
#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq
-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]
@[simp]
theorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :
(if a ∈ f.support then f a else 0) = f a := by
simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]
exact fun h ↦ h.symm
/-- A restatement of `prod_ite_eq` with the equality test reversed. -/
@[to_additive (attr := simp) "A restatement of `sum_ite_eq` with the equality test reversed."]
theorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :
(f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by
dsimp [Finsupp.prod]
rw [f.support.prod_ite_eq']
#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'
#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :
(f.sum fun x v => ite (x = a) v 0) = f a := by
classical
convert f.sum_ite_eq' a fun _ => id
simp [ite_eq_right_iff.2 Eq.symm]
#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'
@[simp]
theorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :
(f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=
f.prod_fintype _ fun _ ↦ pow_zero _
#align finsupp.prod_pow Finsupp.prod_pow
/-- If `g` maps a second argument of 0 to 1, then multiplying it over the
result of `onFinset` is the same as multiplying it over the original `Finset`. -/
@[to_additive
"If `g` maps a second argument of 0 to 0, summing it over the
result of `onFinset` is the same as summing it over the original `Finset`."]
theorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)
(hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a ∈ s, g a (f a) :=
Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]
#align finsupp.on_finset_prod Finsupp.onFinset_prod
#align finsupp.on_finset_sum Finsupp.onFinset_sum
/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element
`y ∈ f.support` by the product over `erase y f`. -/
@[to_additive
" Taking a sum over `f : α →₀ M` is the same as adding the value on a
single element `y ∈ f.support` to the sum over `erase y f`. "]
theorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :
g y (f y) * (erase y f).prod g = f.prod g := by
classical
rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,
Finset.prod_congr rfl]
intro h hx
rw [Finsupp.erase_ne (ne_of_mem_erase hx)]
#align finsupp.mul_prod_erase Finsupp.mul_prod_erase
#align finsupp.add_sum_erase Finsupp.add_sum_erase
/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,
then its product over `f : α →₀ M` is the same as multiplying the value on any element
`y : α` by the product over `erase y f`. -/
@[to_additive
" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0
to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element
`y : α` to the sum over `erase y f`. "]
theorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :
g y (f y) * (erase y f).prod g = f.prod g := by
classical
by_cases hyf : y ∈ f.support
· exact Finsupp.mul_prod_erase f y g hyf
· rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]
#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'
#align finsupp.add_sum_erase' Finsupp.add_sum_erase'
@[to_additive]
theorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]
(s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=
prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)
#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem
#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem
@[to_additive]
theorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :
f.prod g1 = f.prod g2 :=
Finset.prod_congr rfl h
#align finsupp.prod_congr Finsupp.prod_congr
#align finsupp.sum_congr Finsupp.sum_congr
@[to_additive]
theorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}
(h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :
f.prod g = g a (f a) := by
refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)
· exact h₀ b (mem_support_iff.mp hb₁) hb₂
· simp only [not_mem_support_iff] at h
rw [h]
exact h₁ h
end SumProd
section CommMonoidWithZero
variable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]
{f : ι →₀ α} (a : α) {g : ι → α → β}
@[simp]
lemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff
lemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff
end CommMonoidWithZero
end Finsupp
@[to_additive]
theorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*}
[FunLike H N P] [MonoidHomClass H N P]
(h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=
map_prod h _ _
#align map_finsupp_prod map_finsupp_prod
#align map_finsupp_sum map_finsupp_sum
#align mul_equiv.map_finsupp_prod map_finsupp_prod
#align add_equiv.map_finsupp_sum map_finsupp_sum
#align monoid_hom.map_finsupp_prod map_finsupp_prod
#align add_monoid_hom.map_finsupp_sum map_finsupp_sum
#align ring_hom.map_finsupp_sum map_finsupp_sum
#align ring_hom.map_finsupp_prod map_finsupp_prod
-- Porting note: inserted ⇑ on the rhs
@[to_additive]
theorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)
(g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=
MonoidHom.coe_finset_prod _ _
#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod
#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum
@[to_additive (attr := simp)]
theorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)
(g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=
MonoidHom.finset_prod_apply _ _ _
#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply
#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply
namespace Finsupp
theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :
single a s.sum = (s.map (single a)).sum :=
Multiset.induction_on s (single_zero _) fun a s ih => by
rw [Multiset.sum_cons, single_add, ih, Multiset.map_cons, Multiset.sum_cons]
#align finsupp.single_multiset_sum Finsupp.single_multiset_sum
theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :
single a (∑ b ∈ s, f b) = ∑ b ∈ s, single a (f b) := by
trans
· apply single_multiset_sum
· rw [Multiset.map_map]
rfl
#align finsupp.single_finset_sum Finsupp.single_finset_sum
theorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :
single a (s.sum f) = s.sum fun d c => single a (f d c) :=
single_finset_sum _ _ _
#align finsupp.single_sum Finsupp.single_sum
@[to_additive]
theorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}
(h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=
prod_mapRange_index h0
#align finsupp.prod_neg_index Finsupp.prod_neg_index
#align finsupp.sum_neg_index Finsupp.sum_neg_index
end Finsupp
namespace Finsupp
theorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :
(∑ i ∈ S, f i) a = ∑ i ∈ S, f i a :=
map_sum (applyAddHom a) _ _
#align finsupp.finset_sum_apply Finsupp.finset_sum_apply
@[simp]
theorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :
(f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=
finset_sum_apply _ _ _
#align finsupp.sum_apply Finsupp.sum_apply
-- Porting note: inserted ⇑ on the rhs
theorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :
⇑(∑ i ∈ S, f i) = ∑ i ∈ S, ⇑(f i) :=
map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _
#align finsupp.coe_finset_sum Finsupp.coe_finset_sum
-- Porting note: inserted ⇑ on the rhs
theorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :
⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=
coe_finset_sum _ _
#align finsupp.coe_sum Finsupp.coe_sum
theorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :
(f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by
have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>
let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h
⟨a, mem_support_iff.mp ha, ne⟩
simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]
#align finsupp.support_sum Finsupp.support_sum
theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :
(Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by
rw [← Finset.sup_eq_biUnion]
induction' s using Finset.cons_induction_on with a s ha ih
· rfl
· rw [Finset.sum_cons, Finset.sup_cons]
exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)
#align finsupp.support_finset_sum Finsupp.support_finset_sum
@[simp]
theorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=
Finset.sum_const_zero
#align finsupp.sum_zero Finsupp.sum_zero
@[to_additive (attr := simp)]
theorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :
(f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=
Finset.prod_mul_distrib
#align finsupp.prod_mul Finsupp.prod_mul
#align finsupp.sum_add Finsupp.sum_add
@[to_additive (attr := simp)]
theorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :
(f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=
(map_prod (MonoidHom.id G)⁻¹ _ _).symm
#align finsupp.prod_inv Finsupp.prod_inv
#align finsupp.sum_neg Finsupp.sum_neg
@[simp]
theorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :
(f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=
Finset.sum_sub_distrib
#align finsupp.sum_sub Finsupp.sum_sub
/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,
if `h` is an additive-to-multiplicative homomorphism on the support.
This is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/
@[to_additive
"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an
additive homomorphism on the support. This is a more general version of
`Finsupp.sum_add_index'`; the latter has simpler hypotheses."]
theorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}
{h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)
(h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f + g).prod h = f.prod h * g.prod h := by
rw [Finsupp.prod_of_support_subset f subset_union_left h h_zero,
Finsupp.prod_of_support_subset g subset_union_right h h_zero, ←
Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]
exact Finset.prod_congr rfl fun x hx => by apply h_add x hx
#align finsupp.prod_add_index Finsupp.prod_add_index
#align finsupp.sum_add_index Finsupp.sum_add_index
/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,
if `h` is an additive-to-multiplicative homomorphism.
This is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/
@[to_additive
"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive
homomorphism. This is a more specific version of `Finsupp.sum_add_index` with simpler
hypotheses."]
theorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}
(h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f + g).prod h = f.prod h * g.prod h := by
classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a
#align finsupp.prod_add_index' Finsupp.prod_add_index'
#align finsupp.sum_add_index' Finsupp.sum_add_index'
@[simp]
theorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :
((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=
sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add
#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index
@[simp]
theorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}
(h : α → Multiplicative M →* N) :
((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =
(f.prod fun a b => h a (Multiplicative.ofAdd b)) *
g.prod fun a b => h a (Multiplicative.ofAdd b) :=
prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul
#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index
/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`
and monoid homomorphisms `(α →₀ M) →+ N`. -/
def liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N) where
toFun F :=
{ toFun := fun f ↦ f.sum fun x ↦ F x
map_zero' := Finset.sum_empty
map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }
invFun F x := F.comp (singleAddHom x)
left_inv F := by
ext
simp [singleAddHom]
right_inv F := by
-- Porting note: This was `ext` and used the wrong lemma
apply Finsupp.addHom_ext'
simp [singleAddHom, AddMonoidHom.comp, Function.comp]
map_add' F G := by
ext x
exact sum_add
#align finsupp.lift_add_hom Finsupp.liftAddHom
@[simp]
theorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :
(liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=
rfl
#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply
@[simp]
theorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :
(liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=
rfl
#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply
theorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)
(y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=
rfl
#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply
@[simp]
theorem liftAddHom_singleAddHom [AddCommMonoid M] :
(liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =
AddMonoidHom.id _ :=
liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl
#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom
@[simp]
theorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=
DFunLike.congr_fun liftAddHom_singleAddHom f
#align finsupp.sum_single Finsupp.sum_single
/-- The `Finsupp` version of `Finset.univ_sum_single` -/
@[simp]
theorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :
∑ a : α, single a (f a) = f := by
classical
refine DFunLike.coe_injective ?_
simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]
@[simp]
theorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :
∑ j : α, single i m j = m := by
-- Porting note: rewrite due to leaky classical in lean3
classical rw [single, coe_mk, Finset.sum_pi_single']
simp
#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply
@[simp]
theorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :
∑ j : α, single j m i = m := by
-- Porting note: rewrite due to leaky classical in lean3
simp_rw [single, coe_mk]
classical rw [Finset.sum_pi_single]
simp
#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'
theorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :
equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by
rw [← univ_sum_single (equivFunOnFinite.symm f)]
ext
simp
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)
(b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=
sum_single_index (f a).map_zero
#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single
@[simp]
theorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :
((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=
AddMonoidHom.ext fun b => liftAddHom_apply_single f a b
#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single
theorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)
(f : α → M →+ N) :
g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =
(liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=
liftAddHom.symm_apply_eq.1 <|
funext fun a => by
rw [liftAddHom_symm_apply, AddMonoidHom.comp_assoc, liftAddHom_comp_single]
#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom
theorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}
(h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=
((liftAddHom (α := α) (M := β) (N := γ)) fun a =>
AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g
#align finsupp.sum_sub_index Finsupp.sum_sub_index
@[to_additive]
theorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :
(v.embDomain f).prod g = v.prod fun a b => g (f a) b := by
rw [prod, prod, support_embDomain, Finset.prod_map]
simp_rw [embDomain_apply]
#align finsupp.prod_emb_domain Finsupp.prod_embDomain
#align finsupp.sum_emb_domain Finsupp.sum_embDomain
@[to_additive]
theorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}
{h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(∏ i ∈ s, (g i).prod h) = (∑ i ∈ s, g i).prod h :=
Finset.cons_induction_on s rfl fun a s has ih => by
rw [prod_cons, ih, sum_cons, prod_add_index' h_zero h_add]
#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index
#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index
@[to_additive]
theorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}
{g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)
(h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f.sum g).prod h = f.prod fun a b => (g a b).prod h :=
(prod_finset_sum_index h_zero h_add).symm
#align finsupp.prod_sum_index Finsupp.prod_sum_index
#align finsupp.sum_sum_index Finsupp.sum_sum_index
theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))
(h : α → M → N) (h₀ : ∀ a, h a 0 = 0)
(h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :
f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=
Multiset.induction_on f rfl fun a s ih => by
rw [Multiset.sum_cons, Multiset.map_cons, Multiset.sum_cons, sum_add_index' h₀ h₁, ih]
#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index
theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]
[AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)
(h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :
(∑ i ∈ s, g i).support = s.biUnion fun i => (g i).support := by
classical
-- Porting note: apply Finset.induction_on s was not working; refine does.
refine Finset.induction_on s ?_ ?_
· simp
· intro i s hi
simp only [hi, sum_insert, not_false_iff, biUnion_insert]
intro hs
rw [Finsupp.support_add_eq, hs]
rw [hs, Finset.disjoint_biUnion_right]
intro j hj
exact h _ _ (ne_of_mem_of_not_mem hj hi).symm
#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion
theorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :
Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=
map_sum (Multiset.mapAddMonoidHom m) _ f.support
#align finsupp.multiset_map_sum Finsupp.multiset_map_sum
theorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :
Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=
map_sum Multiset.sumAddMonoidHom _ f.support
#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum
/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`
over `f1` and `f2` equals the product of `g` over `f1 + f2` -/
@[to_additive
"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`
over `f1` and `f2` equals the sum of `g` over `f1 + f2`"]
| Mathlib/Algebra/BigOperators/Finsupp.lean | 581 | 591 | theorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}
(hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :
(f1 + f2).prod g = f1.prod g * f2.prod g := by |
have :
∀ {f1 f2 : α →₀ M},
Disjoint f1.support f2.support → (∏ x ∈ f1.support, g x (f1 x + f2 x)) = f1.prod g :=
fun hd =>
Finset.prod_congr rfl fun x hx => by
simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]
classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,
prod_union hd, add_apply]
|
/-
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.SignedHahn
import Mathlib.MeasureTheory.Measure.MutuallySingular
#align_import measure_theory.decomposition.jordan from "leanprover-community/mathlib"@"70a4f2197832bceab57d7f41379b2592d1110570"
/-!
# Jordan decomposition
This file proves the existence and uniqueness of the Jordan decomposition for signed measures.
The Jordan decomposition theorem states that, given a signed measure `s`, there exists a
unique pair of mutually singular measures `μ` and `ν`, such that `s = μ - ν`.
The Jordan decomposition theorem for measures is a corollary of the Hahn decomposition theorem and
is useful for the Lebesgue decomposition theorem.
## Main definitions
* `MeasureTheory.JordanDecomposition`: a Jordan decomposition of a measurable space is a
pair of mutually singular finite measures. We say `j` is a Jordan decomposition of a signed
measure `s` if `s = j.posPart - j.negPart`.
* `MeasureTheory.SignedMeasure.toJordanDecomposition`: the Jordan decomposition of a
signed measure.
* `MeasureTheory.SignedMeasure.toJordanDecompositionEquiv`: is the `Equiv` between
`MeasureTheory.SignedMeasure` and `MeasureTheory.JordanDecomposition` formed by
`MeasureTheory.SignedMeasure.toJordanDecomposition`.
## Main results
* `MeasureTheory.SignedMeasure.toSignedMeasure_toJordanDecomposition` : the Jordan
decomposition theorem.
* `MeasureTheory.JordanDecomposition.toSignedMeasure_injective` : the Jordan decomposition of a
signed measure is unique.
## Tags
Jordan decomposition theorem
-/
noncomputable section
open scoped Classical MeasureTheory ENNReal NNReal
variable {α β : Type*} [MeasurableSpace α]
namespace MeasureTheory
/-- A Jordan decomposition of a measurable space is a pair of mutually singular,
finite measures. -/
@[ext]
structure JordanDecomposition (α : Type*) [MeasurableSpace α] where
(posPart negPart : Measure α)
[posPart_finite : IsFiniteMeasure posPart]
[negPart_finite : IsFiniteMeasure negPart]
mutuallySingular : posPart ⟂ₘ negPart
#align measure_theory.jordan_decomposition MeasureTheory.JordanDecomposition
#align measure_theory.jordan_decomposition.pos_part MeasureTheory.JordanDecomposition.posPart
#align measure_theory.jordan_decomposition.neg_part MeasureTheory.JordanDecomposition.negPart
#align measure_theory.jordan_decomposition.pos_part_finite MeasureTheory.JordanDecomposition.posPart_finite
#align measure_theory.jordan_decomposition.neg_part_finite MeasureTheory.JordanDecomposition.negPart_finite
#align measure_theory.jordan_decomposition.mutually_singular MeasureTheory.JordanDecomposition.mutuallySingular
attribute [instance] JordanDecomposition.posPart_finite
attribute [instance] JordanDecomposition.negPart_finite
namespace JordanDecomposition
open Measure VectorMeasure
variable (j : JordanDecomposition α)
instance instZero : Zero (JordanDecomposition α) where zero := ⟨0, 0, MutuallySingular.zero_right⟩
#align measure_theory.jordan_decomposition.has_zero MeasureTheory.JordanDecomposition.instZero
instance instInhabited : Inhabited (JordanDecomposition α) where default := 0
#align measure_theory.jordan_decomposition.inhabited MeasureTheory.JordanDecomposition.instInhabited
instance instInvolutiveNeg : InvolutiveNeg (JordanDecomposition α) where
neg j := ⟨j.negPart, j.posPart, j.mutuallySingular.symm⟩
neg_neg _ := JordanDecomposition.ext _ _ rfl rfl
#align measure_theory.jordan_decomposition.has_involutive_neg MeasureTheory.JordanDecomposition.instInvolutiveNeg
instance instSMul : SMul ℝ≥0 (JordanDecomposition α) where
smul r j :=
⟨r • j.posPart, r • j.negPart,
MutuallySingular.smul _ (MutuallySingular.smul _ j.mutuallySingular.symm).symm⟩
#align measure_theory.jordan_decomposition.has_smul MeasureTheory.JordanDecomposition.instSMul
instance instSMulReal : SMul ℝ (JordanDecomposition α) where
smul r j := if 0 ≤ r then r.toNNReal • j else -((-r).toNNReal • j)
#align measure_theory.jordan_decomposition.has_smul_real MeasureTheory.JordanDecomposition.instSMulReal
@[simp]
theorem zero_posPart : (0 : JordanDecomposition α).posPart = 0 :=
rfl
#align measure_theory.jordan_decomposition.zero_pos_part MeasureTheory.JordanDecomposition.zero_posPart
@[simp]
theorem zero_negPart : (0 : JordanDecomposition α).negPart = 0 :=
rfl
#align measure_theory.jordan_decomposition.zero_neg_part MeasureTheory.JordanDecomposition.zero_negPart
@[simp]
theorem neg_posPart : (-j).posPart = j.negPart :=
rfl
#align measure_theory.jordan_decomposition.neg_pos_part MeasureTheory.JordanDecomposition.neg_posPart
@[simp]
theorem neg_negPart : (-j).negPart = j.posPart :=
rfl
#align measure_theory.jordan_decomposition.neg_neg_part MeasureTheory.JordanDecomposition.neg_negPart
@[simp]
theorem smul_posPart (r : ℝ≥0) : (r • j).posPart = r • j.posPart :=
rfl
#align measure_theory.jordan_decomposition.smul_pos_part MeasureTheory.JordanDecomposition.smul_posPart
@[simp]
theorem smul_negPart (r : ℝ≥0) : (r • j).negPart = r • j.negPart :=
rfl
#align measure_theory.jordan_decomposition.smul_neg_part MeasureTheory.JordanDecomposition.smul_negPart
theorem real_smul_def (r : ℝ) (j : JordanDecomposition α) :
r • j = if 0 ≤ r then r.toNNReal • j else -((-r).toNNReal • j) :=
rfl
#align measure_theory.jordan_decomposition.real_smul_def MeasureTheory.JordanDecomposition.real_smul_def
@[simp]
theorem coe_smul (r : ℝ≥0) : (r : ℝ) • j = r • j := by
-- Porting note: replaced `show`
rw [real_smul_def, if_pos (NNReal.coe_nonneg r), Real.toNNReal_coe]
#align measure_theory.jordan_decomposition.coe_smul MeasureTheory.JordanDecomposition.coe_smul
theorem real_smul_nonneg (r : ℝ) (hr : 0 ≤ r) : r • j = r.toNNReal • j :=
dif_pos hr
#align measure_theory.jordan_decomposition.real_smul_nonneg MeasureTheory.JordanDecomposition.real_smul_nonneg
theorem real_smul_neg (r : ℝ) (hr : r < 0) : r • j = -((-r).toNNReal • j) :=
dif_neg (not_le.2 hr)
#align measure_theory.jordan_decomposition.real_smul_neg MeasureTheory.JordanDecomposition.real_smul_neg
theorem real_smul_posPart_nonneg (r : ℝ) (hr : 0 ≤ r) :
(r • j).posPart = r.toNNReal • j.posPart := by
rw [real_smul_def, ← smul_posPart, if_pos hr]
#align measure_theory.jordan_decomposition.real_smul_pos_part_nonneg MeasureTheory.JordanDecomposition.real_smul_posPart_nonneg
theorem real_smul_negPart_nonneg (r : ℝ) (hr : 0 ≤ r) :
(r • j).negPart = r.toNNReal • j.negPart := by
rw [real_smul_def, ← smul_negPart, if_pos hr]
#align measure_theory.jordan_decomposition.real_smul_neg_part_nonneg MeasureTheory.JordanDecomposition.real_smul_negPart_nonneg
theorem real_smul_posPart_neg (r : ℝ) (hr : r < 0) :
(r • j).posPart = (-r).toNNReal • j.negPart := by
rw [real_smul_def, ← smul_negPart, if_neg (not_le.2 hr), neg_posPart]
#align measure_theory.jordan_decomposition.real_smul_pos_part_neg MeasureTheory.JordanDecomposition.real_smul_posPart_neg
theorem real_smul_negPart_neg (r : ℝ) (hr : r < 0) :
(r • j).negPart = (-r).toNNReal • j.posPart := by
rw [real_smul_def, ← smul_posPart, if_neg (not_le.2 hr), neg_negPart]
#align measure_theory.jordan_decomposition.real_smul_neg_part_neg MeasureTheory.JordanDecomposition.real_smul_negPart_neg
/-- The signed measure associated with a Jordan decomposition. -/
def toSignedMeasure : SignedMeasure α :=
j.posPart.toSignedMeasure - j.negPart.toSignedMeasure
#align measure_theory.jordan_decomposition.to_signed_measure MeasureTheory.JordanDecomposition.toSignedMeasure
theorem toSignedMeasure_zero : (0 : JordanDecomposition α).toSignedMeasure = 0 := by
ext1 i hi
-- Porting note: replaced `erw` by adding further lemmas
rw [toSignedMeasure, toSignedMeasure_sub_apply hi, zero_posPart, zero_negPart, sub_self,
VectorMeasure.coe_zero, Pi.zero_apply]
#align measure_theory.jordan_decomposition.to_signed_measure_zero MeasureTheory.JordanDecomposition.toSignedMeasure_zero
theorem toSignedMeasure_neg : (-j).toSignedMeasure = -j.toSignedMeasure := by
ext1 i hi
-- Porting note: removed `rfl` after the `rw` by adding further steps.
rw [neg_apply, toSignedMeasure, toSignedMeasure, toSignedMeasure_sub_apply hi,
toSignedMeasure_sub_apply hi, neg_sub, neg_posPart, neg_negPart]
#align measure_theory.jordan_decomposition.to_signed_measure_neg MeasureTheory.JordanDecomposition.toSignedMeasure_neg
theorem toSignedMeasure_smul (r : ℝ≥0) : (r • j).toSignedMeasure = r • j.toSignedMeasure := by
ext1 i hi
rw [VectorMeasure.smul_apply, toSignedMeasure, toSignedMeasure,
toSignedMeasure_sub_apply hi, toSignedMeasure_sub_apply hi, smul_sub, smul_posPart,
smul_negPart, ← ENNReal.toReal_smul, ← ENNReal.toReal_smul, Measure.smul_apply,
Measure.smul_apply]
#align measure_theory.jordan_decomposition.to_signed_measure_smul MeasureTheory.JordanDecomposition.toSignedMeasure_smul
/-- A Jordan decomposition provides a Hahn decomposition. -/
theorem exists_compl_positive_negative :
∃ S : Set α,
MeasurableSet S ∧
j.toSignedMeasure ≤[S] 0 ∧
0 ≤[Sᶜ] j.toSignedMeasure ∧ j.posPart S = 0 ∧ j.negPart Sᶜ = 0 := by
obtain ⟨S, hS₁, hS₂, hS₃⟩ := j.mutuallySingular
refine ⟨S, hS₁, ?_, ?_, hS₂, hS₃⟩
· refine restrict_le_restrict_of_subset_le _ _ fun A hA hA₁ => ?_
rw [toSignedMeasure, toSignedMeasure_sub_apply hA,
show j.posPart A = 0 from nonpos_iff_eq_zero.1 (hS₂ ▸ measure_mono hA₁), ENNReal.zero_toReal,
zero_sub, neg_le, zero_apply, neg_zero]
exact ENNReal.toReal_nonneg
· refine restrict_le_restrict_of_subset_le _ _ fun A hA hA₁ => ?_
rw [toSignedMeasure, toSignedMeasure_sub_apply hA,
show j.negPart A = 0 from nonpos_iff_eq_zero.1 (hS₃ ▸ measure_mono hA₁), ENNReal.zero_toReal,
sub_zero]
exact ENNReal.toReal_nonneg
#align measure_theory.jordan_decomposition.exists_compl_positive_negative MeasureTheory.JordanDecomposition.exists_compl_positive_negative
end JordanDecomposition
namespace SignedMeasure
open scoped Classical
open JordanDecomposition Measure Set VectorMeasure
variable {s : SignedMeasure α} {μ ν : Measure α} [IsFiniteMeasure μ] [IsFiniteMeasure ν]
/-- Given a signed measure `s`, `s.toJordanDecomposition` is the Jordan decomposition `j`,
such that `s = j.toSignedMeasure`. This property is known as the Jordan decomposition
theorem, and is shown by
`MeasureTheory.SignedMeasure.toSignedMeasure_toJordanDecomposition`. -/
def toJordanDecomposition (s : SignedMeasure α) : JordanDecomposition α :=
let i := s.exists_compl_positive_negative.choose
let hi := s.exists_compl_positive_negative.choose_spec
{ posPart := s.toMeasureOfZeroLE i hi.1 hi.2.1
negPart := s.toMeasureOfLEZero iᶜ hi.1.compl hi.2.2
posPart_finite := inferInstance
negPart_finite := inferInstance
mutuallySingular := by
refine ⟨iᶜ, hi.1.compl, ?_, ?_⟩
-- Porting note: added `← NNReal.eq_iff`
· rw [toMeasureOfZeroLE_apply _ _ hi.1 hi.1.compl]; simp [← NNReal.eq_iff]
· rw [toMeasureOfLEZero_apply _ _ hi.1.compl hi.1.compl.compl]; simp [← NNReal.eq_iff] }
#align measure_theory.signed_measure.to_jordan_decomposition MeasureTheory.SignedMeasure.toJordanDecomposition
theorem toJordanDecomposition_spec (s : SignedMeasure α) :
∃ (i : Set α) (hi₁ : MeasurableSet i) (hi₂ : 0 ≤[i] s) (hi₃ : s ≤[iᶜ] 0),
s.toJordanDecomposition.posPart = s.toMeasureOfZeroLE i hi₁ hi₂ ∧
s.toJordanDecomposition.negPart = s.toMeasureOfLEZero iᶜ hi₁.compl hi₃ := by
set i := s.exists_compl_positive_negative.choose
obtain ⟨hi₁, hi₂, hi₃⟩ := s.exists_compl_positive_negative.choose_spec
exact ⟨i, hi₁, hi₂, hi₃, rfl, rfl⟩
#align measure_theory.signed_measure.to_jordan_decomposition_spec MeasureTheory.SignedMeasure.toJordanDecomposition_spec
/-- **The Jordan decomposition theorem**: Given a signed measure `s`, there exists a pair of
mutually singular measures `μ` and `ν` such that `s = μ - ν`. In this case, the measures `μ`
and `ν` are given by `s.toJordanDecomposition.posPart` and
`s.toJordanDecomposition.negPart` respectively.
Note that we use `MeasureTheory.JordanDecomposition.toSignedMeasure` to represent the
signed measure corresponding to
`s.toJordanDecomposition.posPart - s.toJordanDecomposition.negPart`. -/
@[simp]
theorem toSignedMeasure_toJordanDecomposition (s : SignedMeasure α) :
s.toJordanDecomposition.toSignedMeasure = s := by
obtain ⟨i, hi₁, hi₂, hi₃, hμ, hν⟩ := s.toJordanDecomposition_spec
simp only [JordanDecomposition.toSignedMeasure, hμ, hν]
ext k hk
rw [toSignedMeasure_sub_apply hk, toMeasureOfZeroLE_apply _ hi₂ hi₁ hk,
toMeasureOfLEZero_apply _ hi₃ hi₁.compl hk]
simp only [ENNReal.coe_toReal, NNReal.coe_mk, ENNReal.some_eq_coe, sub_neg_eq_add]
rw [← of_union _ (MeasurableSet.inter hi₁ hk) (MeasurableSet.inter hi₁.compl hk),
Set.inter_comm i, Set.inter_comm iᶜ, Set.inter_union_compl _ _]
exact (disjoint_compl_right.inf_left _).inf_right _
#align measure_theory.signed_measure.to_signed_measure_to_jordan_decomposition MeasureTheory.SignedMeasure.toSignedMeasure_toJordanDecomposition
section
variable {u v w : Set α}
/-- A subset `v` of a null-set `w` has zero measure if `w` is a subset of a positive set `u`. -/
theorem subset_positive_null_set (hu : MeasurableSet u) (hv : MeasurableSet v)
(hw : MeasurableSet w) (hsu : 0 ≤[u] s) (hw₁ : s w = 0) (hw₂ : w ⊆ u) (hwt : v ⊆ w) :
s v = 0 := by
have : s v + s (w \ v) = 0 := by
rw [← hw₁, ← of_union Set.disjoint_sdiff_right hv (hw.diff hv), Set.union_diff_self,
Set.union_eq_self_of_subset_left hwt]
have h₁ := nonneg_of_zero_le_restrict _ (restrict_le_restrict_subset _ _ hu hsu (hwt.trans hw₂))
have h₂ : 0 ≤ s (w \ v) :=
nonneg_of_zero_le_restrict _
(restrict_le_restrict_subset _ _ hu hsu (diff_subset.trans hw₂))
linarith
#align measure_theory.signed_measure.subset_positive_null_set MeasureTheory.SignedMeasure.subset_positive_null_set
/-- A subset `v` of a null-set `w` has zero measure if `w` is a subset of a negative set `u`. -/
theorem subset_negative_null_set (hu : MeasurableSet u) (hv : MeasurableSet v)
(hw : MeasurableSet w) (hsu : s ≤[u] 0) (hw₁ : s w = 0) (hw₂ : w ⊆ u) (hwt : v ⊆ w) :
s v = 0 := by
rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu
have := subset_positive_null_set hu hv hw hsu
simp only [Pi.neg_apply, neg_eq_zero, coe_neg] at this
exact this hw₁ hw₂ hwt
#align measure_theory.signed_measure.subset_negative_null_set MeasureTheory.SignedMeasure.subset_negative_null_set
open scoped symmDiff
/-- If the symmetric difference of two positive sets is a null-set, then so are the differences
between the two sets. -/
theorem of_diff_eq_zero_of_symmDiff_eq_zero_positive (hu : MeasurableSet u) (hv : MeasurableSet v)
(hsu : 0 ≤[u] s) (hsv : 0 ≤[v] s) (hs : s (u ∆ v) = 0) : s (u \ v) = 0 ∧ s (v \ u) = 0 := by
rw [restrict_le_restrict_iff] at hsu hsv
on_goal 1 =>
have a := hsu (hu.diff hv) diff_subset
have b := hsv (hv.diff hu) diff_subset
erw [of_union (Set.disjoint_of_subset_left diff_subset disjoint_sdiff_self_right)
(hu.diff hv) (hv.diff hu)] at hs
rw [zero_apply] at a b
constructor
all_goals first | linarith | assumption
#align measure_theory.signed_measure.of_diff_eq_zero_of_symm_diff_eq_zero_positive MeasureTheory.SignedMeasure.of_diff_eq_zero_of_symmDiff_eq_zero_positive
/-- If the symmetric difference of two negative sets is a null-set, then so are the differences
between the two sets. -/
theorem of_diff_eq_zero_of_symmDiff_eq_zero_negative (hu : MeasurableSet u) (hv : MeasurableSet v)
(hsu : s ≤[u] 0) (hsv : s ≤[v] 0) (hs : s (u ∆ v) = 0) : s (u \ v) = 0 ∧ s (v \ u) = 0 := by
rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu
rw [← s.neg_le_neg_iff _ hv, neg_zero] at hsv
have := of_diff_eq_zero_of_symmDiff_eq_zero_positive hu hv hsu hsv
simp only [Pi.neg_apply, neg_eq_zero, coe_neg] at this
exact this hs
#align measure_theory.signed_measure.of_diff_eq_zero_of_symm_diff_eq_zero_negative MeasureTheory.SignedMeasure.of_diff_eq_zero_of_symmDiff_eq_zero_negative
theorem of_inter_eq_of_symmDiff_eq_zero_positive (hu : MeasurableSet u) (hv : MeasurableSet v)
(hw : MeasurableSet w) (hsu : 0 ≤[u] s) (hsv : 0 ≤[v] s) (hs : s (u ∆ v) = 0) :
s (w ∩ u) = s (w ∩ v) := by
have hwuv : s ((w ∩ u) ∆ (w ∩ v)) = 0 := by
refine
subset_positive_null_set (hu.union hv) ((hw.inter hu).symmDiff (hw.inter hv))
(hu.symmDiff hv) (restrict_le_restrict_union _ _ hu hsu hv hsv) hs
Set.symmDiff_subset_union ?_
rw [← Set.inter_symmDiff_distrib_left]
exact Set.inter_subset_right
obtain ⟨huv, hvu⟩ :=
of_diff_eq_zero_of_symmDiff_eq_zero_positive (hw.inter hu) (hw.inter hv)
(restrict_le_restrict_subset _ _ hu hsu (w.inter_subset_right))
(restrict_le_restrict_subset _ _ hv hsv (w.inter_subset_right)) hwuv
rw [← of_diff_of_diff_eq_zero (hw.inter hu) (hw.inter hv) hvu, huv, zero_add]
#align measure_theory.signed_measure.of_inter_eq_of_symm_diff_eq_zero_positive MeasureTheory.SignedMeasure.of_inter_eq_of_symmDiff_eq_zero_positive
theorem of_inter_eq_of_symmDiff_eq_zero_negative (hu : MeasurableSet u) (hv : MeasurableSet v)
(hw : MeasurableSet w) (hsu : s ≤[u] 0) (hsv : s ≤[v] 0) (hs : s (u ∆ v) = 0) :
s (w ∩ u) = s (w ∩ v) := by
rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu
rw [← s.neg_le_neg_iff _ hv, neg_zero] at hsv
have := of_inter_eq_of_symmDiff_eq_zero_positive hu hv hw hsu hsv
simp only [Pi.neg_apply, neg_inj, neg_eq_zero, coe_neg] at this
exact this hs
#align measure_theory.signed_measure.of_inter_eq_of_symm_diff_eq_zero_negative MeasureTheory.SignedMeasure.of_inter_eq_of_symmDiff_eq_zero_negative
end
end SignedMeasure
namespace JordanDecomposition
open Measure VectorMeasure SignedMeasure Function
private theorem eq_of_posPart_eq_posPart {j₁ j₂ : JordanDecomposition α}
(hj : j₁.posPart = j₂.posPart) (hj' : j₁.toSignedMeasure = j₂.toSignedMeasure) : j₁ = j₂ := by
ext1
· exact hj
· rw [← toSignedMeasure_eq_toSignedMeasure_iff]
-- Porting note: golfed
unfold toSignedMeasure at hj'
simp_rw [hj, sub_right_inj] at hj'
exact hj'
/-- The Jordan decomposition of a signed measure is unique. -/
| Mathlib/MeasureTheory/Decomposition/Jordan.lean | 375 | 425 | theorem toSignedMeasure_injective : Injective <| @JordanDecomposition.toSignedMeasure α _ := by |
/- The main idea is that two Jordan decompositions of a signed measure provide two
Hahn decompositions for that measure. Then, from `of_symmDiff_compl_positive_negative`,
the symmetric difference of the two Hahn decompositions has measure zero, thus, allowing us to
show the equality of the underlying measures of the Jordan decompositions. -/
intro j₁ j₂ hj
-- obtain the two Hahn decompositions from the Jordan decompositions
obtain ⟨S, hS₁, hS₂, hS₃, hS₄, hS₅⟩ := j₁.exists_compl_positive_negative
obtain ⟨T, hT₁, hT₂, hT₃, hT₄, hT₅⟩ := j₂.exists_compl_positive_negative
rw [← hj] at hT₂ hT₃
-- the symmetric differences of the two Hahn decompositions have measure zero
obtain ⟨hST₁, -⟩ :=
of_symmDiff_compl_positive_negative hS₁.compl hT₁.compl ⟨hS₃, (compl_compl S).symm ▸ hS₂⟩
⟨hT₃, (compl_compl T).symm ▸ hT₂⟩
-- it suffices to show the Jordan decompositions have the same positive parts
refine eq_of_posPart_eq_posPart ?_ hj
ext1 i hi
-- we see that the positive parts of the two Jordan decompositions are equal to their
-- associated signed measures restricted on their associated Hahn decompositions
have hμ₁ : (j₁.posPart i).toReal = j₁.toSignedMeasure (i ∩ Sᶜ) := by
rw [toSignedMeasure, toSignedMeasure_sub_apply (hi.inter hS₁.compl),
show j₁.negPart (i ∩ Sᶜ) = 0 from
nonpos_iff_eq_zero.1 (hS₅ ▸ measure_mono Set.inter_subset_right),
ENNReal.zero_toReal, sub_zero]
conv_lhs => rw [← Set.inter_union_compl i S]
rw [measure_union,
show j₁.posPart (i ∩ S) = 0 from
nonpos_iff_eq_zero.1 (hS₄ ▸ measure_mono Set.inter_subset_right),
zero_add]
· refine
Set.disjoint_of_subset_left Set.inter_subset_right
(Set.disjoint_of_subset_right Set.inter_subset_right disjoint_compl_right)
· exact hi.inter hS₁.compl
have hμ₂ : (j₂.posPart i).toReal = j₂.toSignedMeasure (i ∩ Tᶜ) := by
rw [toSignedMeasure, toSignedMeasure_sub_apply (hi.inter hT₁.compl),
show j₂.negPart (i ∩ Tᶜ) = 0 from
nonpos_iff_eq_zero.1 (hT₅ ▸ measure_mono Set.inter_subset_right),
ENNReal.zero_toReal, sub_zero]
conv_lhs => rw [← Set.inter_union_compl i T]
rw [measure_union,
show j₂.posPart (i ∩ T) = 0 from
nonpos_iff_eq_zero.1 (hT₄ ▸ measure_mono Set.inter_subset_right),
zero_add]
· exact
Set.disjoint_of_subset_left Set.inter_subset_right
(Set.disjoint_of_subset_right Set.inter_subset_right disjoint_compl_right)
· exact hi.inter hT₁.compl
-- since the two signed measures associated with the Jordan decompositions are the same,
-- and the symmetric difference of the Hahn decompositions have measure zero, the result follows
rw [← ENNReal.toReal_eq_toReal (measure_ne_top _ _) (measure_ne_top _ _), hμ₁, hμ₂, ← hj]
exact of_inter_eq_of_symmDiff_eq_zero_positive hS₁.compl hT₁.compl hi hS₃ hT₃ hST₁
|
/-
Copyright (c) 2023 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Heather Macbeth
-/
import Mathlib.MeasureTheory.Constructions.Pi
import Mathlib.MeasureTheory.Integral.Lebesgue
/-!
# Marginals of multivariate functions
In this file, we define a convenient way to compute integrals of multivariate functions, especially
if you want to write expressions where you integrate only over some of the variables that the
function depends on. This is common in induction arguments involving integrals of multivariate
functions.
This constructions allows working with iterated integrals and applying Tonelli's theorem
and Fubini's theorem, without using measurable equivalences by changing the representation of your
space (e.g. `((ι ⊕ ι') → ℝ) ≃ (ι → ℝ) × (ι' → ℝ)`).
## Main Definitions
* Assume that `∀ i : ι, π i` is a product of measurable spaces with measures `μ i` on `π i`,
`f : (∀ i, π i) → ℝ≥0∞` is a function and `s : Finset ι`.
Then `lmarginal μ s f` or `∫⋯∫⁻_s, f ∂μ` is the function that integrates `f`
over all variables in `s`. It returns a function that still takes the same variables as `f`,
but is constant in the variables in `s`. Mathematically, if `s = {i₁, ..., iₖ}`,
then `lmarginal μ s f` is the expression
$$
\vec{x}\mapsto \int\!\!\cdots\!\!\int f(\vec{x}[\vec{y}])dy_{i_1}\cdots dy_{i_k}.
$$
where $\vec{x}[\vec{y}]$ is the vector $\vec{x}$ with $x_{i_j}$ replaced by $y_{i_j}$ for all
$1 \le j \le k$.
If `f` is the distribution of a random variable, this is the marginal distribution of all
variables not in `s` (but not the most general notion, since we only consider product measures
here).
Note that the notation `∫⋯∫⁻_s, f ∂μ` is not a binder, and returns a function.
## Main Results
* `lmarginal_union` is the analogue of Tonelli's theorem for iterated integrals. It states that
for measurable functions `f` and disjoint finsets `s` and `t` we have
`∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ`.
## Implementation notes
The function `f` can have an arbitrary product as its domain (even infinite products), but the
set `s` of integration variables is a `Finset`. We are assuming that the function `f` is measurable
for most of this file. Note that asking whether it is `AEMeasurable` is not even well-posed,
since there is no well-behaved measure on the domain of `f`.
## Todo
* Define the marginal function for functions taking values in a Banach space.
-/
open scoped Classical ENNReal
open Set Function Equiv Finset
noncomputable section
namespace MeasureTheory
section LMarginal
variable {δ δ' : Type*} {π : δ → Type*} [∀ x, MeasurableSpace (π x)]
variable {μ : ∀ i, Measure (π i)} [∀ i, SigmaFinite (μ i)] [DecidableEq δ]
variable {s t : Finset δ} {f g : (∀ i, π i) → ℝ≥0∞} {x y : ∀ i, π i} {i : δ}
/-- Integrate `f(x₁,…,xₙ)` over all variables `xᵢ` where `i ∈ s`. Return a function in the
remaining variables (it will be constant in the `xᵢ` for `i ∈ s`).
This is the marginal distribution of all variables not in `s` when the considered measure
is the product measure. -/
def lmarginal (μ : ∀ i, Measure (π i)) (s : Finset δ) (f : (∀ i, π i) → ℝ≥0∞)
(x : ∀ i, π i) : ℝ≥0∞ :=
∫⁻ y : ∀ i : s, π i, f (updateFinset x s y) ∂Measure.pi fun i : s => μ i
-- Note: this notation is not a binder. This is more convenient since it returns a function.
@[inherit_doc]
notation "∫⋯∫⁻_" s ", " f " ∂" μ:70 => lmarginal μ s f
@[inherit_doc]
notation "∫⋯∫⁻_" s ", " f => lmarginal (fun _ ↦ volume) s f
variable (μ)
theorem _root_.Measurable.lmarginal (hf : Measurable f) : Measurable (∫⋯∫⁻_s, f ∂μ) := by
refine Measurable.lintegral_prod_right ?_
refine hf.comp ?_
rw [measurable_pi_iff]; intro i
by_cases hi : i ∈ s
· simp [hi, updateFinset]
exact measurable_pi_iff.1 measurable_snd _
· simp [hi, updateFinset]
exact measurable_pi_iff.1 measurable_fst _
@[simp] theorem lmarginal_empty (f : (∀ i, π i) → ℝ≥0∞) : ∫⋯∫⁻_∅, f ∂μ = f := by
ext1 x
simp_rw [lmarginal, Measure.pi_of_empty fun i : (∅ : Finset δ) => μ i]
apply lintegral_dirac'
exact Subsingleton.measurable
/-- The marginal distribution is independent of the variables in `s`. -/
theorem lmarginal_congr {x y : ∀ i, π i} (f : (∀ i, π i) → ℝ≥0∞)
(h : ∀ i ∉ s, x i = y i) :
(∫⋯∫⁻_s, f ∂μ) x = (∫⋯∫⁻_s, f ∂μ) y := by
dsimp [lmarginal, updateFinset_def]; rcongr; exact h _ ‹_›
theorem lmarginal_update_of_mem {i : δ} (hi : i ∈ s)
(f : (∀ i, π i) → ℝ≥0∞) (x : ∀ i, π i) (y : π i) :
(∫⋯∫⁻_s, f ∂μ) (Function.update x i y) = (∫⋯∫⁻_s, f ∂μ) x := by
apply lmarginal_congr
intro j hj
have : j ≠ i := by rintro rfl; exact hj hi
apply update_noteq this
theorem lmarginal_union (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f)
(hst : Disjoint s t) : ∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ := by
ext1 x
let e := MeasurableEquiv.piFinsetUnion π hst
calc (∫⋯∫⁻_s ∪ t, f ∂μ) x
= ∫⁻ (y : (i : ↥(s ∪ t)) → π i), f (updateFinset x (s ∪ t) y)
∂.pi fun i' : ↥(s ∪ t) ↦ μ i' := rfl
_ = ∫⁻ (y : ((i : s) → π i) × ((j : t) → π j)), f (updateFinset x (s ∪ t) _)
∂(Measure.pi fun i : s ↦ μ i).prod (.pi fun j : t ↦ μ j) := by
rw [measurePreserving_piFinsetUnion hst μ |>.lintegral_map_equiv]
_ = ∫⁻ (y : (i : s) → π i), ∫⁻ (z : (j : t) → π j), f (updateFinset x (s ∪ t) (e (y, z)))
∂.pi fun j : t ↦ μ j ∂.pi fun i : s ↦ μ i := by
apply lintegral_prod
apply Measurable.aemeasurable
exact hf.comp <| measurable_updateFinset.comp e.measurable
_ = (∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ) x := by
simp_rw [lmarginal, updateFinset_updateFinset hst]
rfl
| Mathlib/MeasureTheory/Integral/Marginal.lean | 137 | 139 | theorem lmarginal_union' (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f) {s t : Finset δ}
(hst : Disjoint s t) : ∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_t, ∫⋯∫⁻_s, f ∂μ ∂μ := by |
rw [Finset.union_comm, lmarginal_union μ f hf hst.symm]
|
/-
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.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Tactic.NthRewrite
#align_import data.nat.gcd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Definitions and properties of `Nat.gcd`, `Nat.lcm`, and `Nat.coprime`
Generalizations of these are provided in a later file as `GCDMonoid.gcd` and
`GCDMonoid.lcm`.
Note that the global `IsCoprime` is not a straightforward generalization of `Nat.coprime`, see
`Nat.isCoprime_iff_coprime` for the connection between the two.
-/
namespace Nat
/-! ### `gcd` -/
theorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ d) :
d = a.gcd b :=
(dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm
#align nat.gcd_greatest Nat.gcd_greatest
/-! Lemmas where one argument consists of addition of a multiple of the other -/
@[simp]
theorem gcd_add_mul_right_right (m n k : ℕ) : gcd m (n + k * m) = gcd m n := by
simp [gcd_rec m (n + k * m), gcd_rec m n]
#align nat.gcd_add_mul_right_right Nat.gcd_add_mul_right_right
@[simp]
theorem gcd_add_mul_left_right (m n k : ℕ) : gcd m (n + m * k) = gcd m n := by
simp [gcd_rec m (n + m * k), gcd_rec m n]
#align nat.gcd_add_mul_left_right Nat.gcd_add_mul_left_right
@[simp]
theorem gcd_mul_right_add_right (m n k : ℕ) : gcd m (k * m + n) = gcd m n := by simp [add_comm _ n]
#align nat.gcd_mul_right_add_right Nat.gcd_mul_right_add_right
@[simp]
theorem gcd_mul_left_add_right (m n k : ℕ) : gcd m (m * k + n) = gcd m n := by simp [add_comm _ n]
#align nat.gcd_mul_left_add_right Nat.gcd_mul_left_add_right
@[simp]
theorem gcd_add_mul_right_left (m n k : ℕ) : gcd (m + k * n) n = gcd m n := by
rw [gcd_comm, gcd_add_mul_right_right, gcd_comm]
#align nat.gcd_add_mul_right_left Nat.gcd_add_mul_right_left
@[simp]
theorem gcd_add_mul_left_left (m n k : ℕ) : gcd (m + n * k) n = gcd m n := by
rw [gcd_comm, gcd_add_mul_left_right, gcd_comm]
#align nat.gcd_add_mul_left_left Nat.gcd_add_mul_left_left
@[simp]
theorem gcd_mul_right_add_left (m n k : ℕ) : gcd (k * n + m) n = gcd m n := by
rw [gcd_comm, gcd_mul_right_add_right, gcd_comm]
#align nat.gcd_mul_right_add_left Nat.gcd_mul_right_add_left
@[simp]
theorem gcd_mul_left_add_left (m n k : ℕ) : gcd (n * k + m) n = gcd m n := by
rw [gcd_comm, gcd_mul_left_add_right, gcd_comm]
#align nat.gcd_mul_left_add_left Nat.gcd_mul_left_add_left
/-! Lemmas where one argument consists of an addition of the other -/
@[simp]
theorem gcd_add_self_right (m n : ℕ) : gcd m (n + m) = gcd m n :=
Eq.trans (by rw [one_mul]) (gcd_add_mul_right_right m n 1)
#align nat.gcd_add_self_right Nat.gcd_add_self_right
@[simp]
theorem gcd_add_self_left (m n : ℕ) : gcd (m + n) n = gcd m n := by
rw [gcd_comm, gcd_add_self_right, gcd_comm]
#align nat.gcd_add_self_left Nat.gcd_add_self_left
@[simp]
theorem gcd_self_add_left (m n : ℕ) : gcd (m + n) m = gcd n m := by rw [add_comm, gcd_add_self_left]
#align nat.gcd_self_add_left Nat.gcd_self_add_left
@[simp]
theorem gcd_self_add_right (m n : ℕ) : gcd m (m + n) = gcd m n := by
rw [add_comm, gcd_add_self_right]
#align nat.gcd_self_add_right Nat.gcd_self_add_right
/-! Lemmas where one argument consists of a subtraction of the other -/
@[simp]
theorem gcd_sub_self_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) m = gcd n m := by
calc
gcd (n - m) m = gcd (n - m + m) m := by rw [← gcd_add_self_left (n - m) m]
_ = gcd n m := by rw [Nat.sub_add_cancel h]
@[simp]
theorem gcd_sub_self_right {m n : ℕ} (h : m ≤ n) : gcd m (n - m) = gcd m n := by
rw [gcd_comm, gcd_sub_self_left h, gcd_comm]
@[simp]
theorem gcd_self_sub_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) n = gcd m n := by
have := Nat.sub_add_cancel h
rw [gcd_comm m n, ← this, gcd_add_self_left (n - m) m]
have : gcd (n - m) n = gcd (n - m) m := by
nth_rw 2 [← Nat.add_sub_cancel' h]
rw [gcd_add_self_right, gcd_comm]
convert this
@[simp]
theorem gcd_self_sub_right {m n : ℕ} (h : m ≤ n) : gcd n (n - m) = gcd n m := by
rw [gcd_comm, gcd_self_sub_left h, gcd_comm]
/-! ### `lcm` -/
theorem lcm_dvd_mul (m n : ℕ) : lcm m n ∣ m * n :=
lcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _)
#align nat.lcm_dvd_mul Nat.lcm_dvd_mul
theorem lcm_dvd_iff {m n k : ℕ} : lcm m n ∣ k ↔ m ∣ k ∧ n ∣ k :=
⟨fun h => ⟨(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h⟩, and_imp.2 lcm_dvd⟩
#align nat.lcm_dvd_iff Nat.lcm_dvd_iff
theorem lcm_pos {m n : ℕ} : 0 < m → 0 < n → 0 < m.lcm n := by
simp_rw [pos_iff_ne_zero]
exact lcm_ne_zero
#align nat.lcm_pos Nat.lcm_pos
theorem lcm_mul_left {m n k : ℕ} : (m * n).lcm (m * k) = m * n.lcm k := by
apply dvd_antisymm
· exact lcm_dvd (mul_dvd_mul_left m (dvd_lcm_left n k)) (mul_dvd_mul_left m (dvd_lcm_right n k))
· have h : m ∣ lcm (m * n) (m * k) := (dvd_mul_right m n).trans (dvd_lcm_left (m * n) (m * k))
rw [← dvd_div_iff h, lcm_dvd_iff, dvd_div_iff h, dvd_div_iff h, ← lcm_dvd_iff]
theorem lcm_mul_right {m n k : ℕ} : (m * n).lcm (k * n) = m.lcm k * n := by
rw [mul_comm, mul_comm k n, lcm_mul_left, mul_comm]
/-!
### `Coprime`
See also `Nat.coprime_of_dvd` and `Nat.coprime_of_dvd'` to prove `Nat.Coprime m n`.
-/
instance (m n : ℕ) : Decidable (Coprime m n) := inferInstanceAs (Decidable (gcd m n = 1))
theorem Coprime.lcm_eq_mul {m n : ℕ} (h : Coprime m n) : lcm m n = m * n := by
rw [← one_mul (lcm m n), ← h.gcd_eq_one, gcd_mul_lcm]
#align nat.coprime.lcm_eq_mul Nat.Coprime.lcm_eq_mul
theorem Coprime.symmetric : Symmetric Coprime := fun _ _ => Coprime.symm
#align nat.coprime.symmetric Nat.Coprime.symmetric
theorem Coprime.dvd_mul_right {m n k : ℕ} (H : Coprime k n) : k ∣ m * n ↔ k ∣ m :=
⟨H.dvd_of_dvd_mul_right, fun h => dvd_mul_of_dvd_left h n⟩
#align nat.coprime.dvd_mul_right Nat.Coprime.dvd_mul_right
theorem Coprime.dvd_mul_left {m n k : ℕ} (H : Coprime k m) : k ∣ m * n ↔ k ∣ n :=
⟨H.dvd_of_dvd_mul_left, fun h => dvd_mul_of_dvd_right h m⟩
#align nat.coprime.dvd_mul_left Nat.Coprime.dvd_mul_left
@[simp]
theorem coprime_add_self_right {m n : ℕ} : Coprime m (n + m) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_self_right]
#align nat.coprime_add_self_right Nat.coprime_add_self_right
@[simp]
theorem coprime_self_add_right {m n : ℕ} : Coprime m (m + n) ↔ Coprime m n := by
rw [add_comm, coprime_add_self_right]
#align nat.coprime_self_add_right Nat.coprime_self_add_right
@[simp]
theorem coprime_add_self_left {m n : ℕ} : Coprime (m + n) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_self_left]
#align nat.coprime_add_self_left Nat.coprime_add_self_left
@[simp]
theorem coprime_self_add_left {m n : ℕ} : Coprime (m + n) m ↔ Coprime n m := by
rw [Coprime, Coprime, gcd_self_add_left]
#align nat.coprime_self_add_left Nat.coprime_self_add_left
@[simp]
theorem coprime_add_mul_right_right (m n k : ℕ) : Coprime m (n + k * m) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_right_right]
#align nat.coprime_add_mul_right_right Nat.coprime_add_mul_right_right
@[simp]
theorem coprime_add_mul_left_right (m n k : ℕ) : Coprime m (n + m * k) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_left_right]
#align nat.coprime_add_mul_left_right Nat.coprime_add_mul_left_right
@[simp]
theorem coprime_mul_right_add_right (m n k : ℕ) : Coprime m (k * m + n) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_right_add_right]
#align nat.coprime_mul_right_add_right Nat.coprime_mul_right_add_right
@[simp]
theorem coprime_mul_left_add_right (m n k : ℕ) : Coprime m (m * k + n) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_left_add_right]
#align nat.coprime_mul_left_add_right Nat.coprime_mul_left_add_right
@[simp]
theorem coprime_add_mul_right_left (m n k : ℕ) : Coprime (m + k * n) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_right_left]
#align nat.coprime_add_mul_right_left Nat.coprime_add_mul_right_left
@[simp]
theorem coprime_add_mul_left_left (m n k : ℕ) : Coprime (m + n * k) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_left_left]
#align nat.coprime_add_mul_left_left Nat.coprime_add_mul_left_left
@[simp]
theorem coprime_mul_right_add_left (m n k : ℕ) : Coprime (k * n + m) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_right_add_left]
#align nat.coprime_mul_right_add_left Nat.coprime_mul_right_add_left
@[simp]
theorem coprime_mul_left_add_left (m n k : ℕ) : Coprime (n * k + m) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_left_add_left]
#align nat.coprime_mul_left_add_left Nat.coprime_mul_left_add_left
@[simp]
theorem coprime_sub_self_left {m n : ℕ} (h : m ≤ n) : Coprime (n - m) m ↔ Coprime n m := by
rw [Coprime, Coprime, gcd_sub_self_left h]
@[simp]
theorem coprime_sub_self_right {m n : ℕ} (h : m ≤ n) : Coprime m (n - m) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_sub_self_right h]
@[simp]
theorem coprime_self_sub_left {m n : ℕ} (h : m ≤ n) : Coprime (n - m) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_self_sub_left h]
@[simp]
theorem coprime_self_sub_right {m n : ℕ} (h : m ≤ n) : Coprime n (n - m) ↔ Coprime n m := by
rw [Coprime, Coprime, gcd_self_sub_right h]
@[simp]
theorem coprime_pow_left_iff {n : ℕ} (hn : 0 < n) (a b : ℕ) :
Nat.Coprime (a ^ n) b ↔ Nat.Coprime a b := by
obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero hn.ne'
rw [Nat.pow_succ, Nat.coprime_mul_iff_left]
exact ⟨And.right, fun hab => ⟨hab.pow_left _, hab⟩⟩
#align nat.coprime_pow_left_iff Nat.coprime_pow_left_iff
@[simp]
theorem coprime_pow_right_iff {n : ℕ} (hn : 0 < n) (a b : ℕ) :
Nat.Coprime a (b ^ n) ↔ Nat.Coprime a b := by
rw [Nat.coprime_comm, coprime_pow_left_iff hn, Nat.coprime_comm]
#align nat.coprime_pow_right_iff Nat.coprime_pow_right_iff
theorem not_coprime_zero_zero : ¬Coprime 0 0 := by simp
#align nat.not_coprime_zero_zero Nat.not_coprime_zero_zero
theorem coprime_one_left_iff (n : ℕ) : Coprime 1 n ↔ True := by simp [Coprime]
#align nat.coprime_one_left_iff Nat.coprime_one_left_iff
theorem coprime_one_right_iff (n : ℕ) : Coprime n 1 ↔ True := by simp [Coprime]
#align nat.coprime_one_right_iff Nat.coprime_one_right_iff
theorem gcd_mul_of_coprime_of_dvd {a b c : ℕ} (hac : Coprime a c) (b_dvd_c : b ∣ c) :
gcd (a * b) c = b := by
rcases exists_eq_mul_left_of_dvd b_dvd_c with ⟨d, rfl⟩
rw [gcd_mul_right]
convert one_mul b
exact Coprime.coprime_mul_right_right hac
#align nat.gcd_mul_of_coprime_of_dvd Nat.gcd_mul_of_coprime_of_dvd
theorem Coprime.eq_of_mul_eq_zero {m n : ℕ} (h : m.Coprime n) (hmn : m * n = 0) :
m = 0 ∧ n = 1 ∨ m = 1 ∧ n = 0 :=
(Nat.eq_zero_of_mul_eq_zero hmn).imp (fun hm => ⟨hm, n.coprime_zero_left.mp <| hm ▸ h⟩) fun hn =>
let eq := hn ▸ h.symm
⟨m.coprime_zero_left.mp <| eq, hn⟩
#align nat.coprime.eq_of_mul_eq_zero Nat.Coprime.eq_of_mul_eq_zero
/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`.
See `exists_dvd_and_dvd_of_dvd_mul` for the more general but less constructive version for other
`GCDMonoid`s. -/
def prodDvdAndDvdOfDvdProd {m n k : ℕ} (H : k ∣ m * n) :
{ d : { m' // m' ∣ m } × { n' // n' ∣ n } // k = d.1 * d.2 } := by
cases h0 : gcd k m with
| zero =>
obtain rfl : k = 0 := eq_zero_of_gcd_eq_zero_left h0
obtain rfl : m = 0 := eq_zero_of_gcd_eq_zero_right h0
exact ⟨⟨⟨0, dvd_refl 0⟩, ⟨n, dvd_refl n⟩⟩, (zero_mul n).symm⟩
| succ tmp =>
have hpos : 0 < gcd k m := h0.symm ▸ Nat.zero_lt_succ _; clear h0 tmp
have hd : gcd k m * (k / gcd k m) = k := Nat.mul_div_cancel' (gcd_dvd_left k m)
refine ⟨⟨⟨gcd k m, gcd_dvd_right k m⟩, ⟨k / gcd k m, ?_⟩⟩, hd.symm⟩
apply Nat.dvd_of_mul_dvd_mul_left hpos
rw [hd, ← gcd_mul_right]
exact dvd_gcd (dvd_mul_right _ _) H
#align nat.prod_dvd_and_dvd_of_dvd_prod Nat.prodDvdAndDvdOfDvdProd
theorem dvd_mul {x m n : ℕ} : x ∣ m * n ↔ ∃ y z, y ∣ m ∧ z ∣ n ∧ y * z = x := by
constructor
· intro h
obtain ⟨⟨⟨y, hy⟩, ⟨z, hz⟩⟩, rfl⟩ := prod_dvd_and_dvd_of_dvd_prod h
exact ⟨y, z, hy, hz, rfl⟩
· rintro ⟨y, z, hy, hz, rfl⟩
exact mul_dvd_mul hy hz
#align nat.dvd_mul Nat.dvd_mul
| Mathlib/Data/Nat/GCD/Basic.lean | 308 | 317 | theorem pow_dvd_pow_iff {a b n : ℕ} (n0 : n ≠ 0) : a ^ n ∣ b ^ n ↔ a ∣ b := by |
refine ⟨fun h => ?_, fun h => pow_dvd_pow_of_dvd h _⟩
rcases Nat.eq_zero_or_pos (gcd a b) with g0 | g0
· simp [eq_zero_of_gcd_eq_zero_right g0]
rcases exists_coprime' g0 with ⟨g, a', b', g0', co, rfl, rfl⟩
rw [mul_pow, mul_pow] at h
replace h := Nat.dvd_of_mul_dvd_mul_right (pow_pos g0' _) h
have := pow_dvd_pow a' <| Nat.pos_of_ne_zero n0
rw [pow_one, (co.pow n n).eq_one_of_dvd h] at this
simp [eq_one_of_dvd_one this]
|
/-
Copyright (c) 2022 Felix Weilacher. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Felix Weilacher
-/
import Mathlib.Topology.Separation
/-!
# Perfect Sets
In this file we define perfect subsets of a topological space, and prove some basic properties,
including a version of the Cantor-Bendixson Theorem.
## Main Definitions
* `Perfect C`: A set `C` is perfect, meaning it is closed and every point of it
is an accumulation point of itself.
* `PerfectSpace X`: A topological space `X` is perfect if its universe is a perfect set.
## Main Statements
* `Perfect.splitting`: A perfect nonempty set contains two disjoint perfect nonempty subsets.
The main inductive step in the construction of an embedding from the Cantor space to a
perfect nonempty complete metric space.
* `exists_countable_union_perfect_of_isClosed`: One version of the **Cantor-Bendixson Theorem**:
A closed set in a second countable space can be written as the union of a countable set and a
perfect set.
## Implementation Notes
We do not require perfect sets to be nonempty.
We define a nonstandard predicate, `Preperfect`, which drops the closed-ness requirement
from the definition of perfect. In T1 spaces, this is equivalent to having a perfect closure,
see `preperfect_iff_perfect_closure`.
## See also
`Mathlib.Topology.MetricSpace.Perfect`, for properties of perfect sets in metric spaces,
namely Polish spaces.
## References
* [kechris1995] (Chapters 6-7)
## Tags
accumulation point, perfect set, cantor-bendixson.
-/
open Topology Filter Set TopologicalSpace
section Basic
variable {α : Type*} [TopologicalSpace α] {C : Set α}
/-- If `x` is an accumulation point of a set `C` and `U` is a neighborhood of `x`,
then `x` is an accumulation point of `U ∩ C`. -/
| Mathlib/Topology/Perfect.lean | 62 | 68 | theorem AccPt.nhds_inter {x : α} {U : Set α} (h_acc : AccPt x (𝓟 C)) (hU : U ∈ 𝓝 x) :
AccPt x (𝓟 (U ∩ C)) := by |
have : 𝓝[≠] x ≤ 𝓟 U := by
rw [le_principal_iff]
exact mem_nhdsWithin_of_mem_nhds hU
rw [AccPt, ← inf_principal, ← inf_assoc, inf_of_le_left this]
exact h_acc
|
/-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.FieldTheory.Galois
#align_import field_theory.polynomial_galois_group from "leanprover-community/mathlib"@"e3f4be1fcb5376c4948d7f095bec45350bfb9d1a"
/-!
# Galois Groups of Polynomials
In this file, we introduce the Galois group of a polynomial `p` over a field `F`,
defined as the automorphism group of its splitting field. We also provide
some results about some extension `E` above `p.SplittingField`.
## Main definitions
- `Polynomial.Gal p`: the Galois group of a polynomial p.
- `Polynomial.Gal.restrict p E`: the restriction homomorphism `(E ≃ₐ[F] E) → gal p`.
- `Polynomial.Gal.galAction p E`: the action of `gal p` on the roots of `p` in `E`.
## Main results
- `Polynomial.Gal.restrict_smul`: `restrict p E` is compatible with `gal_action p E`.
- `Polynomial.Gal.galActionHom_injective`: `gal p` acting on the roots of `p` in `E` is faithful.
- `Polynomial.Gal.restrictProd_injective`: `gal (p * q)` embeds as a subgroup of `gal p × gal q`.
- `Polynomial.Gal.card_of_separable`: For a separable polynomial, its Galois group has cardinality
equal to the dimension of its splitting field over `F`.
- `Polynomial.Gal.galActionHom_bijective_of_prime_degree`:
An irreducible polynomial of prime degree with two non-real roots has full Galois group.
## Other results
- `Polynomial.Gal.card_complex_roots_eq_card_real_add_card_not_gal_inv`: The number of complex roots
equals the number of real roots plus the number of roots not fixed by complex conjugation
(i.e. with some imaginary component).
-/
noncomputable section
open scoped Polynomial
open FiniteDimensional
namespace Polynomial
variable {F : Type*} [Field F] (p q : F[X]) (E : Type*) [Field E] [Algebra F E]
/-- The Galois group of a polynomial. -/
def Gal :=
p.SplittingField ≃ₐ[F] p.SplittingField
-- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020):
-- deriving Group, Fintype
#align polynomial.gal Polynomial.Gal
namespace Gal
instance instGroup : Group (Gal p) :=
inferInstanceAs (Group (p.SplittingField ≃ₐ[F] p.SplittingField))
instance instFintype : Fintype (Gal p) :=
inferInstanceAs (Fintype (p.SplittingField ≃ₐ[F] p.SplittingField))
instance : CoeFun p.Gal fun _ => p.SplittingField → p.SplittingField :=
-- Porting note: was AlgEquiv.hasCoeToFun
inferInstanceAs (CoeFun (p.SplittingField ≃ₐ[F] p.SplittingField) _)
instance applyMulSemiringAction : MulSemiringAction p.Gal p.SplittingField :=
AlgEquiv.applyMulSemiringAction
#align polynomial.gal.apply_mul_semiring_action Polynomial.Gal.applyMulSemiringAction
@[ext]
theorem ext {σ τ : p.Gal} (h : ∀ x ∈ p.rootSet p.SplittingField, σ x = τ x) : σ = τ := by
refine
AlgEquiv.ext fun x =>
(AlgHom.mem_equalizer σ.toAlgHom τ.toAlgHom x).mp
((SetLike.ext_iff.mp ?_ x).mpr Algebra.mem_top)
rwa [eq_top_iff, ← SplittingField.adjoin_rootSet, Algebra.adjoin_le_iff]
#align polynomial.gal.ext Polynomial.Gal.ext
/-- If `p` splits in `F` then the `p.gal` is trivial. -/
def uniqueGalOfSplits (h : p.Splits (RingHom.id F)) : Unique p.Gal where
default := 1
uniq f :=
AlgEquiv.ext fun x => by
obtain ⟨y, rfl⟩ :=
Algebra.mem_bot.mp
((SetLike.ext_iff.mp ((IsSplittingField.splits_iff _ p).mp h) x).mp Algebra.mem_top)
rw [AlgEquiv.commutes, AlgEquiv.commutes]
#align polynomial.gal.unique_gal_of_splits Polynomial.Gal.uniqueGalOfSplits
instance [h : Fact (p.Splits (RingHom.id F))] : Unique p.Gal :=
uniqueGalOfSplits _ h.1
instance uniqueGalZero : Unique (0 : F[X]).Gal :=
uniqueGalOfSplits _ (splits_zero _)
#align polynomial.gal.unique_gal_zero Polynomial.Gal.uniqueGalZero
instance uniqueGalOne : Unique (1 : F[X]).Gal :=
uniqueGalOfSplits _ (splits_one _)
#align polynomial.gal.unique_gal_one Polynomial.Gal.uniqueGalOne
instance uniqueGalC (x : F) : Unique (C x).Gal :=
uniqueGalOfSplits _ (splits_C _ _)
set_option linter.uppercaseLean3 false in
#align polynomial.gal.unique_gal_C Polynomial.Gal.uniqueGalC
instance uniqueGalX : Unique (X : F[X]).Gal :=
uniqueGalOfSplits _ (splits_X _)
set_option linter.uppercaseLean3 false in
#align polynomial.gal.unique_gal_X Polynomial.Gal.uniqueGalX
instance uniqueGalXSubC (x : F) : Unique (X - C x).Gal :=
uniqueGalOfSplits _ (splits_X_sub_C _)
set_option linter.uppercaseLean3 false in
#align polynomial.gal.unique_gal_X_sub_C Polynomial.Gal.uniqueGalXSubC
instance uniqueGalXPow (n : ℕ) : Unique (X ^ n : F[X]).Gal :=
uniqueGalOfSplits _ (splits_X_pow _ _)
set_option linter.uppercaseLean3 false in
#align polynomial.gal.unique_gal_X_pow Polynomial.Gal.uniqueGalXPow
instance [h : Fact (p.Splits (algebraMap F E))] : Algebra p.SplittingField E :=
(IsSplittingField.lift p.SplittingField p h.1).toRingHom.toAlgebra
instance [h : Fact (p.Splits (algebraMap F E))] : IsScalarTower F p.SplittingField E :=
IsScalarTower.of_algebraMap_eq fun x =>
((IsSplittingField.lift p.SplittingField p h.1).commutes x).symm
-- The `Algebra p.SplittingField E` instance above behaves badly when
-- `E := p.SplittingField`, since it may result in a unification problem
-- `IsSplittingField.lift.toRingHom.toAlgebra =?= Algebra.id`,
-- which takes an extremely long time to resolve, causing timeouts.
-- Since we don't really care about this definition, marking it as irreducible
-- causes that unification to error out early.
/-- Restrict from a superfield automorphism into a member of `gal p`. -/
def restrict [Fact (p.Splits (algebraMap F E))] : (E ≃ₐ[F] E) →* p.Gal :=
AlgEquiv.restrictNormalHom p.SplittingField
#align polynomial.gal.restrict Polynomial.Gal.restrict
theorem restrict_surjective [Fact (p.Splits (algebraMap F E))] [Normal F E] :
Function.Surjective (restrict p E) :=
AlgEquiv.restrictNormalHom_surjective E
#align polynomial.gal.restrict_surjective Polynomial.Gal.restrict_surjective
section RootsAction
/-- The function taking `rootSet p p.SplittingField` to `rootSet p E`. This is actually a bijection,
see `Polynomial.Gal.mapRoots_bijective`. -/
def mapRoots [Fact (p.Splits (algebraMap F E))] : rootSet p p.SplittingField → rootSet p E :=
Set.MapsTo.restrict (IsScalarTower.toAlgHom F p.SplittingField E) _ _ <| rootSet_mapsTo _
#align polynomial.gal.map_roots Polynomial.Gal.mapRoots
| Mathlib/FieldTheory/PolynomialGaloisGroup.lean | 155 | 168 | theorem mapRoots_bijective [h : Fact (p.Splits (algebraMap F E))] :
Function.Bijective (mapRoots p E) := by |
constructor
· exact fun _ _ h => Subtype.ext (RingHom.injective _ (Subtype.ext_iff.mp h))
· intro y
-- this is just an equality of two different ways to write the roots of `p` as an `E`-polynomial
have key :=
roots_map (IsScalarTower.toAlgHom F p.SplittingField E : p.SplittingField →+* E)
((splits_id_iff_splits _).mpr (IsSplittingField.splits p.SplittingField p))
rw [map_map, AlgHom.comp_algebraMap] at key
have hy := Subtype.mem y
simp only [rootSet, Finset.mem_coe, Multiset.mem_toFinset, key, Multiset.mem_map] at hy
rcases hy with ⟨x, hx1, hx2⟩
exact ⟨⟨x, (@Multiset.mem_toFinset _ (Classical.decEq _) _ _).mpr hx1⟩, Subtype.ext hx2⟩
|
/-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots
import Mathlib.NumberTheory.NumberField.Discriminant
#align_import number_theory.cyclotomic.discriminant from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1"
/-!
# Discriminant of cyclotomic fields
We compute the discriminant of a `p ^ n`-th cyclotomic extension.
## Main results
* `IsCyclotomicExtension.discr_odd_prime` : if `p` is an odd prime such that
`IsCyclotomicExtension {p} K L` and `Irreducible (cyclotomic p K)`, then
`discr K (hζ.powerBasis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2)` for any
`hζ : IsPrimitiveRoot ζ p`.
-/
universe u v
open Algebra Polynomial Nat IsPrimitiveRoot PowerBasis
open scoped Polynomial Cyclotomic
namespace IsPrimitiveRoot
variable {n : ℕ+} {K : Type u} [Field K] [CharZero K] {ζ : K}
variable [ce : IsCyclotomicExtension {n} ℚ K]
/-- The discriminant of the power basis given by a primitive root of unity `ζ` is the same as the
discriminant of the power basis given by `ζ - 1`. -/
| Mathlib/NumberTheory/Cyclotomic/Discriminant.lean | 37 | 48 | theorem discr_zeta_eq_discr_zeta_sub_one (hζ : IsPrimitiveRoot ζ n) :
discr ℚ (hζ.powerBasis ℚ).basis = discr ℚ (hζ.subOnePowerBasis ℚ).basis := by |
haveI : NumberField K := @NumberField.mk _ _ _ (IsCyclotomicExtension.finiteDimensional {n} ℚ K)
have H₁ : (aeval (hζ.powerBasis ℚ).gen) (X - 1 : ℤ[X]) = (hζ.subOnePowerBasis ℚ).gen := by simp
have H₂ : (aeval (hζ.subOnePowerBasis ℚ).gen) (X + 1 : ℤ[X]) = (hζ.powerBasis ℚ).gen := by simp
refine discr_eq_discr_of_toMatrix_coeff_isIntegral _ (fun i j => toMatrix_isIntegral H₁ ?_ ?_ _ _)
fun i j => toMatrix_isIntegral H₂ ?_ ?_ _ _
· exact hζ.isIntegral n.pos
· refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) (hζ.isIntegral n.pos)
· exact (hζ.isIntegral n.pos).sub isIntegral_one
· refine minpoly.isIntegrallyClosed_eq_field_fractions' (K := ℚ) ?_
exact (hζ.isIntegral n.pos).sub isIntegral_one
|
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, François Dupuis
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Order.Filter.Extr
import Mathlib.Tactic.GCongr
#align_import analysis.convex.function from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# Convex and concave functions
This file defines convex and concave functions in vector spaces and proves the finite Jensen
inequality. The integral version can be found in `Analysis.Convex.Integral`.
A function `f : E → β` is `ConvexOn` a set `s` if `s` is itself a convex set, and for any two
points `x y ∈ s`, the segment joining `(x, f x)` to `(y, f y)` is above the graph of `f`.
Equivalently, `ConvexOn 𝕜 f s` means that the epigraph `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is
a convex set.
## Main declarations
* `ConvexOn 𝕜 s f`: The function `f` is convex on `s` with scalars `𝕜`.
* `ConcaveOn 𝕜 s f`: The function `f` is concave on `s` with scalars `𝕜`.
* `StrictConvexOn 𝕜 s f`: The function `f` is strictly convex on `s` with scalars `𝕜`.
* `StrictConcaveOn 𝕜 s f`: The function `f` is strictly concave on `s` with scalars `𝕜`.
-/
open scoped Classical
open LinearMap Set Convex Pointwise
variable {𝕜 E F α β ι : Type*}
section OrderedSemiring
variable [OrderedSemiring 𝕜]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F]
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid α] [OrderedAddCommMonoid β]
section SMul
variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 α] [SMul 𝕜 β] (s : Set E) (f : E → β) {g : β → α}
/-- Convexity of functions -/
def ConvexOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ≤ a • f x + b • f y
#align convex_on ConvexOn
/-- Concavity of functions -/
def ConcaveOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
a • f x + b • f y ≤ f (a • x + b • y)
#align concave_on ConcaveOn
/-- Strict convexity of functions -/
def StrictConvexOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
f (a • x + b • y) < a • f x + b • f y
#align strict_convex_on StrictConvexOn
/-- Strict concavity of functions -/
def StrictConcaveOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y < f (a • x + b • y)
#align strict_concave_on StrictConcaveOn
variable {𝕜 s f}
open OrderDual (toDual ofDual)
theorem ConvexOn.dual (hf : ConvexOn 𝕜 s f) : ConcaveOn 𝕜 s (toDual ∘ f) := hf
#align convex_on.dual ConvexOn.dual
theorem ConcaveOn.dual (hf : ConcaveOn 𝕜 s f) : ConvexOn 𝕜 s (toDual ∘ f) := hf
#align concave_on.dual ConcaveOn.dual
theorem StrictConvexOn.dual (hf : StrictConvexOn 𝕜 s f) : StrictConcaveOn 𝕜 s (toDual ∘ f) := hf
#align strict_convex_on.dual StrictConvexOn.dual
theorem StrictConcaveOn.dual (hf : StrictConcaveOn 𝕜 s f) : StrictConvexOn 𝕜 s (toDual ∘ f) := hf
#align strict_concave_on.dual StrictConcaveOn.dual
theorem convexOn_id {s : Set β} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s _root_.id :=
⟨hs, by
intros
rfl⟩
#align convex_on_id convexOn_id
theorem concaveOn_id {s : Set β} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s _root_.id :=
⟨hs, by
intros
rfl⟩
#align concave_on_id concaveOn_id
theorem ConvexOn.subset {t : Set E} (hf : ConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) :
ConvexOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align convex_on.subset ConvexOn.subset
theorem ConcaveOn.subset {t : Set E} (hf : ConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) :
ConcaveOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align concave_on.subset ConcaveOn.subset
theorem StrictConvexOn.subset {t : Set E} (hf : StrictConvexOn 𝕜 t f) (hst : s ⊆ t)
(hs : Convex 𝕜 s) : StrictConvexOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align strict_convex_on.subset StrictConvexOn.subset
theorem StrictConcaveOn.subset {t : Set E} (hf : StrictConcaveOn 𝕜 t f) (hst : s ⊆ t)
(hs : Convex 𝕜 s) : StrictConcaveOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align strict_concave_on.subset StrictConcaveOn.subset
theorem ConvexOn.comp (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f)
(hg' : MonotoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy _ _ ha hb hab =>
(hg' (mem_image_of_mem f <| hf.1 hx hy ha hb hab)
(hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) <|
hf.2 hx hy ha hb hab).trans <|
hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab⟩
#align convex_on.comp ConvexOn.comp
theorem ConcaveOn.comp (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f)
(hg' : MonotoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy _ _ ha hb hab =>
(hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab).trans <|
hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab)
(mem_image_of_mem f <| hf.1 hx hy ha hb hab) <|
hf.2 hx hy ha hb hab⟩
#align concave_on.comp ConcaveOn.comp
theorem ConvexOn.comp_concaveOn (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f)
(hg' : AntitoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg'
#align convex_on.comp_concave_on ConvexOn.comp_concaveOn
theorem ConcaveOn.comp_convexOn (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f)
(hg' : AntitoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg'
#align concave_on.comp_convex_on ConcaveOn.comp_convexOn
theorem StrictConvexOn.comp (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f)
(hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab =>
(hg' (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab)
(hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) <|
hf.2 hx hy hxy ha hb hab).trans <|
hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab⟩
#align strict_convex_on.comp StrictConvexOn.comp
theorem StrictConcaveOn.comp (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f)
(hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab =>
(hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab).trans <|
hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab)
(mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) <|
hf.2 hx hy hxy ha hb hab⟩
#align strict_concave_on.comp StrictConcaveOn.comp
theorem StrictConvexOn.comp_strictConcaveOn (hg : StrictConvexOn 𝕜 (f '' s) g)
(hf : StrictConcaveOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) :
StrictConvexOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg' hf'
#align strict_convex_on.comp_strict_concave_on StrictConvexOn.comp_strictConcaveOn
theorem StrictConcaveOn.comp_strictConvexOn (hg : StrictConcaveOn 𝕜 (f '' s) g)
(hf : StrictConvexOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) :
StrictConcaveOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg' hf'
#align strict_concave_on.comp_strict_convex_on StrictConcaveOn.comp_strictConvexOn
end SMul
section DistribMulAction
variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β}
theorem ConvexOn.add (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f + g) :=
⟨hf.1, fun x hx y hy a b ha hb hab =>
calc
f (a • x + b • y) + g (a • x + b • y) ≤ a • f x + b • f y + (a • g x + b • g y) :=
add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
_ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]
⟩
#align convex_on.add ConvexOn.add
theorem ConcaveOn.add (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f + g) :=
hf.dual.add hg
#align concave_on.add ConcaveOn.add
end DistribMulAction
section Module
variable [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f : E → β}
theorem convexOn_const (c : β) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s fun _ : E => c :=
⟨hs, fun _ _ _ _ _ _ _ _ hab => (Convex.combo_self hab c).ge⟩
#align convex_on_const convexOn_const
theorem concaveOn_const (c : β) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s fun _ => c :=
convexOn_const (β := βᵒᵈ) _ hs
#align concave_on_const concaveOn_const
theorem convexOn_of_convex_epigraph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 }) :
ConvexOn 𝕜 s f :=
⟨fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).1,
fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).2⟩
#align convex_on_of_convex_epigraph convexOn_of_convex_epigraph
theorem concaveOn_of_convex_hypograph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 }) :
ConcaveOn 𝕜 s f :=
convexOn_of_convex_epigraph (β := βᵒᵈ) h
#align concave_on_of_convex_hypograph concaveOn_of_convex_hypograph
end Module
section OrderedSMul
variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β}
theorem ConvexOn.convex_le (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) :=
fun x hx y hy a b ha hb hab =>
⟨hf.1 hx.1 hy.1 ha hb hab,
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha hb hab
_ ≤ a • r + b • r := by
gcongr
· exact hx.2
· exact hy.2
_ = r := Convex.combo_self hab r
⟩
#align convex_on.convex_le ConvexOn.convex_le
theorem ConcaveOn.convex_ge (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) :=
hf.dual.convex_le r
#align concave_on.convex_ge ConcaveOn.convex_ge
theorem ConvexOn.convex_epigraph (hf : ConvexOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := by
rintro ⟨x, r⟩ ⟨hx, hr⟩ ⟨y, t⟩ ⟨hy, ht⟩ a b ha hb hab
refine ⟨hf.1 hx hy ha hb hab, ?_⟩
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab
_ ≤ a • r + b • t := by gcongr
#align convex_on.convex_epigraph ConvexOn.convex_epigraph
theorem ConcaveOn.convex_hypograph (hf : ConcaveOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } :=
hf.dual.convex_epigraph
#align concave_on.convex_hypograph ConcaveOn.convex_hypograph
theorem convexOn_iff_convex_epigraph :
ConvexOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } :=
⟨ConvexOn.convex_epigraph, convexOn_of_convex_epigraph⟩
#align convex_on_iff_convex_epigraph convexOn_iff_convex_epigraph
theorem concaveOn_iff_convex_hypograph :
ConcaveOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } :=
convexOn_iff_convex_epigraph (β := βᵒᵈ)
#align concave_on_iff_convex_hypograph concaveOn_iff_convex_hypograph
end OrderedSMul
section Module
variable [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β}
/-- Right translation preserves convexity. -/
theorem ConvexOn.translate_right (hf : ConvexOn 𝕜 s f) (c : E) :
ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) :=
⟨hf.1.translate_preimage_right _, fun x hx y hy a b ha hb hab =>
calc
f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by
rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab]
_ ≤ a • f (c + x) + b • f (c + y) := hf.2 hx hy ha hb hab
⟩
#align convex_on.translate_right ConvexOn.translate_right
/-- Right translation preserves concavity. -/
theorem ConcaveOn.translate_right (hf : ConcaveOn 𝕜 s f) (c : E) :
ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) :=
hf.dual.translate_right _
#align concave_on.translate_right ConcaveOn.translate_right
/-- Left translation preserves convexity. -/
theorem ConvexOn.translate_left (hf : ConvexOn 𝕜 s f) (c : E) :
ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by
simpa only [add_comm c] using hf.translate_right c
#align convex_on.translate_left ConvexOn.translate_left
/-- Left translation preserves concavity. -/
theorem ConcaveOn.translate_left (hf : ConcaveOn 𝕜 s f) (c : E) :
ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) :=
hf.dual.translate_left _
#align concave_on.translate_left ConcaveOn.translate_left
end Module
section Module
variable [Module 𝕜 E] [Module 𝕜 β]
theorem convexOn_iff_forall_pos {s : Set E} {f : E → β} :
ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b →
a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by
refine and_congr_right'
⟨fun h x hx y hy a b ha hb hab => h hx hy ha.le hb.le hab, fun h x hx y hy a b ha hb hab => ?_⟩
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_add] at hab
subst b
simp_rw [zero_smul, zero_add, one_smul, le_rfl]
obtain rfl | hb' := hb.eq_or_lt
· rw [add_zero] at hab
subst a
simp_rw [zero_smul, add_zero, one_smul, le_rfl]
exact h hx hy ha' hb' hab
#align convex_on_iff_forall_pos convexOn_iff_forall_pos
theorem concaveOn_iff_forall_pos {s : Set E} {f : E → β} :
ConcaveOn 𝕜 s f ↔
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y ≤ f (a • x + b • y) :=
convexOn_iff_forall_pos (β := βᵒᵈ)
#align concave_on_iff_forall_pos concaveOn_iff_forall_pos
theorem convexOn_iff_pairwise_pos {s : Set E} {f : E → β} :
ConvexOn 𝕜 s f ↔
Convex 𝕜 s ∧
s.Pairwise fun x y =>
∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by
rw [convexOn_iff_forall_pos]
refine
and_congr_right'
⟨fun h x hx y hy _ a b ha hb hab => h hx hy ha hb hab, fun h x hx y hy a b ha hb hab => ?_⟩
obtain rfl | hxy := eq_or_ne x y
· rw [Convex.combo_self hab, Convex.combo_self hab]
exact h hx hy hxy ha hb hab
#align convex_on_iff_pairwise_pos convexOn_iff_pairwise_pos
theorem concaveOn_iff_pairwise_pos {s : Set E} {f : E → β} :
ConcaveOn 𝕜 s f ↔
Convex 𝕜 s ∧
s.Pairwise fun x y =>
∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) :=
convexOn_iff_pairwise_pos (β := βᵒᵈ)
#align concave_on_iff_pairwise_pos concaveOn_iff_pairwise_pos
/-- A linear map is convex. -/
theorem LinearMap.convexOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f :=
⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩
#align linear_map.convex_on LinearMap.convexOn
/-- A linear map is concave. -/
theorem LinearMap.concaveOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f :=
⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩
#align linear_map.concave_on LinearMap.concaveOn
theorem StrictConvexOn.convexOn {s : Set E} {f : E → β} (hf : StrictConvexOn 𝕜 s f) :
ConvexOn 𝕜 s f :=
convexOn_iff_pairwise_pos.mpr
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hf.2 hx hy hxy ha hb hab).le⟩
#align strict_convex_on.convex_on StrictConvexOn.convexOn
theorem StrictConcaveOn.concaveOn {s : Set E} {f : E → β} (hf : StrictConcaveOn 𝕜 s f) :
ConcaveOn 𝕜 s f :=
hf.dual.convexOn
#align strict_concave_on.concave_on StrictConcaveOn.concaveOn
section OrderedSMul
variable [OrderedSMul 𝕜 β] {s : Set E} {f : E → β}
theorem StrictConvexOn.convex_lt (hf : StrictConvexOn 𝕜 s f) (r : β) :
Convex 𝕜 ({ x ∈ s | f x < r }) :=
convex_iff_pairwise_pos.2 fun x hx y hy hxy a b ha hb hab =>
⟨hf.1 hx.1 hy.1 ha.le hb.le hab,
calc
f (a • x + b • y) < a • f x + b • f y := hf.2 hx.1 hy.1 hxy ha hb hab
_ ≤ a • r + b • r := by
gcongr
· exact hx.2.le
· exact hy.2.le
_ = r := Convex.combo_self hab r
⟩
#align strict_convex_on.convex_lt StrictConvexOn.convex_lt
theorem StrictConcaveOn.convex_gt (hf : StrictConcaveOn 𝕜 s f) (r : β) :
Convex 𝕜 ({ x ∈ s | r < f x }) :=
hf.dual.convex_lt r
#align strict_concave_on.convex_gt StrictConcaveOn.convex_gt
end OrderedSMul
section LinearOrder
variable [LinearOrder E] {s : Set E} {f : E → β}
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is convex, it suffices to
verify the inequality `f (a • x + b • y) ≤ a • f x + b • f y` only for `x < y` and positive `a`,
`b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order.
-/
theorem LinearOrder.convexOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
f (a • x + b • y) ≤ a • f x + b • f y) :
ConvexOn 𝕜 s f := by
refine convexOn_iff_pairwise_pos.2 ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩
-- Porting note: without clearing the stray variables, `wlog` gives a bad term.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495
clear! α F ι
wlog h : x < y
· rw [add_comm (a • x), add_comm (a • f x)]
rw [add_comm] at hab
exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h)
exact hf hx hy h ha hb hab
#align linear_order.convex_on_of_lt LinearOrder.convexOn_of_lt
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is concave it suffices to
verify the inequality `a • f x + b • f y ≤ f (a • x + b • y)` for `x < y` and positive `a`, `b`. The
main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/
theorem LinearOrder.concaveOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y ≤ f (a • x + b • y)) :
ConcaveOn 𝕜 s f :=
LinearOrder.convexOn_of_lt (β := βᵒᵈ) hs hf
#align linear_order.concave_on_of_lt LinearOrder.concaveOn_of_lt
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is strictly convex, it suffices
to verify the inequality `f (a • x + b • y) < a • f x + b • f y` for `x < y` and positive `a`, `b`.
The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/
theorem LinearOrder.strictConvexOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
f (a • x + b • y) < a • f x + b • f y) :
StrictConvexOn 𝕜 s f := by
refine ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩
-- Porting note: without clearing the stray variables, `wlog` gives a bad term.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495
clear! α F ι
wlog h : x < y
· rw [add_comm (a • x), add_comm (a • f x)]
rw [add_comm] at hab
exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h)
exact hf hx hy h ha hb hab
#align linear_order.strict_convex_on_of_lt LinearOrder.strictConvexOn_of_lt
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is strictly concave it suffices
to verify the inequality `a • f x + b • f y < f (a • x + b • y)` for `x < y` and positive `a`, `b`.
The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/
theorem LinearOrder.strictConcaveOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y < f (a • x + b • y)) :
StrictConcaveOn 𝕜 s f :=
LinearOrder.strictConvexOn_of_lt (β := βᵒᵈ) hs hf
#align linear_order.strict_concave_on_of_lt LinearOrder.strictConcaveOn_of_lt
end LinearOrder
end Module
section Module
variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β]
/-- If `g` is convex on `s`, so is `(f ∘ g)` on `f ⁻¹' s` for a linear `f`. -/
theorem ConvexOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConvexOn 𝕜 s f) (g : E →ₗ[𝕜] F) :
ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) :=
⟨hf.1.linear_preimage _, fun x hx y hy a b ha hb hab =>
calc
f (g (a • x + b • y)) = f (a • g x + b • g y) := by rw [g.map_add, g.map_smul, g.map_smul]
_ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩
#align convex_on.comp_linear_map ConvexOn.comp_linearMap
/-- If `g` is concave on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/
theorem ConcaveOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConcaveOn 𝕜 s f) (g : E →ₗ[𝕜] F) :
ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) :=
hf.dual.comp_linearMap g
#align concave_on.comp_linear_map ConcaveOn.comp_linearMap
end Module
end OrderedAddCommMonoid
section OrderedCancelAddCommMonoid
variable [OrderedCancelAddCommMonoid β]
section DistribMulAction
variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β}
theorem StrictConvexOn.add_convexOn (hf : StrictConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f + g) :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab =>
calc
f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) :=
add_lt_add_of_lt_of_le (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy ha.le hb.le hab)
_ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩
#align strict_convex_on.add_convex_on StrictConvexOn.add_convexOn
theorem ConvexOn.add_strictConvexOn (hf : ConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f + g) :=
add_comm g f ▸ hg.add_convexOn hf
#align convex_on.add_strict_convex_on ConvexOn.add_strictConvexOn
theorem StrictConvexOn.add (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f + g) :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab =>
calc
f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) :=
add_lt_add (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy hxy ha hb hab)
_ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩
#align strict_convex_on.add StrictConvexOn.add
theorem StrictConcaveOn.add_concaveOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f + g) :=
hf.dual.add_convexOn hg.dual
#align strict_concave_on.add_concave_on StrictConcaveOn.add_concaveOn
theorem ConcaveOn.add_strictConcaveOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f + g) :=
hf.dual.add_strictConvexOn hg.dual
#align concave_on.add_strict_concave_on ConcaveOn.add_strictConcaveOn
theorem StrictConcaveOn.add (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f + g) :=
hf.dual.add hg
#align strict_concave_on.add StrictConcaveOn.add
end DistribMulAction
section Module
variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β}
theorem ConvexOn.convex_lt (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) :=
convex_iff_forall_pos.2 fun x hx y hy a b ha hb hab =>
⟨hf.1 hx.1 hy.1 ha.le hb.le hab,
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha.le hb.le hab
_ < a • r + b • r :=
(add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx.2 ha)
(smul_le_smul_of_nonneg_left hy.2.le hb.le))
_ = r := Convex.combo_self hab _⟩
#align convex_on.convex_lt ConvexOn.convex_lt
theorem ConcaveOn.convex_gt (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) :=
hf.dual.convex_lt r
#align concave_on.convex_gt ConcaveOn.convex_gt
theorem ConvexOn.openSegment_subset_strict_epigraph (hf : ConvexOn 𝕜 s f) (p q : E × β)
(hp : p.1 ∈ s ∧ f p.1 < p.2) (hq : q.1 ∈ s ∧ f q.1 ≤ q.2) :
openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := by
rintro _ ⟨a, b, ha, hb, hab, rfl⟩
refine ⟨hf.1 hp.1 hq.1 ha.le hb.le hab, ?_⟩
calc
f (a • p.1 + b • q.1) ≤ a • f p.1 + b • f q.1 := hf.2 hp.1 hq.1 ha.le hb.le hab
_ < a • p.2 + b • q.2 := add_lt_add_of_lt_of_le
(smul_lt_smul_of_pos_left hp.2 ha) (smul_le_smul_of_nonneg_left hq.2 hb.le)
#align convex_on.open_segment_subset_strict_epigraph ConvexOn.openSegment_subset_strict_epigraph
theorem ConcaveOn.openSegment_subset_strict_hypograph (hf : ConcaveOn 𝕜 s f) (p q : E × β)
(hp : p.1 ∈ s ∧ p.2 < f p.1) (hq : q.1 ∈ s ∧ q.2 ≤ f q.1) :
openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } :=
hf.dual.openSegment_subset_strict_epigraph p q hp hq
#align concave_on.open_segment_subset_strict_hypograph ConcaveOn.openSegment_subset_strict_hypograph
theorem ConvexOn.convex_strict_epigraph (hf : ConvexOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } :=
convex_iff_openSegment_subset.mpr fun p hp q hq =>
hf.openSegment_subset_strict_epigraph p q hp ⟨hq.1, hq.2.le⟩
#align convex_on.convex_strict_epigraph ConvexOn.convex_strict_epigraph
theorem ConcaveOn.convex_strict_hypograph (hf : ConcaveOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } :=
hf.dual.convex_strict_epigraph
#align concave_on.convex_strict_hypograph ConcaveOn.convex_strict_hypograph
end Module
end OrderedCancelAddCommMonoid
section LinearOrderedAddCommMonoid
variable [LinearOrderedAddCommMonoid β] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E}
{f g : E → β}
/-- The pointwise maximum of convex functions is convex. -/
theorem ConvexOn.sup (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f ⊔ g) := by
refine ⟨hf.left, fun x hx y hy a b ha hb hab => sup_le ?_ ?_⟩
· calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.right hx hy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left
· calc
g (a • x + b • y) ≤ a • g x + b • g y := hg.right hx hy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right
#align convex_on.sup ConvexOn.sup
/-- The pointwise minimum of concave functions is concave. -/
theorem ConcaveOn.inf (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f ⊓ g) :=
hf.dual.sup hg
#align concave_on.inf ConcaveOn.inf
/-- The pointwise maximum of strictly convex functions is strictly convex. -/
theorem StrictConvexOn.sup (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f ⊔ g) :=
⟨hf.left, fun x hx y hy hxy a b ha hb hab =>
max_lt
(calc
f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left)
(calc
g (a • x + b • y) < a • g x + b • g y := hg.2 hx hy hxy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right)⟩
#align strict_convex_on.sup StrictConvexOn.sup
/-- The pointwise minimum of strictly concave functions is strictly concave. -/
theorem StrictConcaveOn.inf (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f ⊓ g) :=
hf.dual.sup hg
#align strict_concave_on.inf StrictConcaveOn.inf
/-- A convex function on a segment is upper-bounded by the max of its endpoints. -/
theorem ConvexOn.le_on_segment' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜}
(ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : f (a • x + b • y) ≤ max (f x) (f y) :=
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab
_ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by
gcongr
· apply le_max_left
· apply le_max_right
_ = max (f x) (f y) := Convex.combo_self hab _
#align convex_on.le_on_segment' ConvexOn.le_on_segment'
/-- A concave function on a segment is lower-bounded by the min of its endpoints. -/
theorem ConcaveOn.ge_on_segment' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min (f x) (f y) ≤ f (a • x + b • y) :=
hf.dual.le_on_segment' hx hy ha hb hab
#align concave_on.ge_on_segment' ConcaveOn.ge_on_segment'
/-- A convex function on a segment is upper-bounded by the max of its endpoints. -/
theorem ConvexOn.le_on_segment (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ [x -[𝕜] y]) : f z ≤ max (f x) (f y) :=
let ⟨_, _, ha, hb, hab, hz⟩ := hz
hz ▸ hf.le_on_segment' hx hy ha hb hab
#align convex_on.le_on_segment ConvexOn.le_on_segment
/-- A concave function on a segment is lower-bounded by the min of its endpoints. -/
theorem ConcaveOn.ge_on_segment (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ [x -[𝕜] y]) : min (f x) (f y) ≤ f z :=
hf.dual.le_on_segment hx hy hz
#align concave_on.ge_on_segment ConcaveOn.ge_on_segment
/-- A strictly convex function on an open segment is strictly upper-bounded by the max of its
endpoints. -/
theorem StrictConvexOn.lt_on_open_segment' (hf : StrictConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
f (a • x + b • y) < max (f x) (f y) :=
calc
f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab
_ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by
gcongr
· apply le_max_left
· apply le_max_right
_ = max (f x) (f y) := Convex.combo_self hab _
#align strict_convex_on.lt_on_open_segment' StrictConvexOn.lt_on_open_segment'
/-- A strictly concave function on an open segment is strictly lower-bounded by the min of its
endpoints. -/
theorem StrictConcaveOn.lt_on_open_segment' (hf : StrictConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
min (f x) (f y) < f (a • x + b • y) :=
hf.dual.lt_on_open_segment' hx hy hxy ha hb hab
#align strict_concave_on.lt_on_open_segment' StrictConcaveOn.lt_on_open_segment'
/-- A strictly convex function on an open segment is strictly upper-bounded by the max of its
endpoints. -/
theorem StrictConvexOn.lt_on_openSegment (hf : StrictConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : f z < max (f x) (f y) :=
let ⟨_, _, ha, hb, hab, hz⟩ := hz
hz ▸ hf.lt_on_open_segment' hx hy hxy ha hb hab
#align strict_convex_on.lt_on_open_segment StrictConvexOn.lt_on_openSegment
/-- A strictly concave function on an open segment is strictly lower-bounded by the min of its
endpoints. -/
theorem StrictConcaveOn.lt_on_openSegment (hf : StrictConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : min (f x) (f y) < f z :=
hf.dual.lt_on_openSegment hx hy hxy hz
#align strict_concave_on.lt_on_open_segment StrictConcaveOn.lt_on_openSegment
end LinearOrderedAddCommMonoid
section LinearOrderedCancelAddCommMonoid
variable [LinearOrderedCancelAddCommMonoid β]
section OrderedSMul
variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β}
theorem ConvexOn.le_left_of_right_le' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f y ≤ f (a • x + b • y)) :
f (a • x + b • y) ≤ f x :=
le_of_not_lt fun h ↦ lt_irrefl (f (a • x + b • y)) <|
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb hab
_ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_lt_of_le
(smul_lt_smul_of_pos_left h ha) (smul_le_smul_of_nonneg_left hfy hb)
_ = f (a • x + b • y) := Convex.combo_self hab _
#align convex_on.le_left_of_right_le' ConvexOn.le_left_of_right_le'
theorem ConcaveOn.left_le_of_le_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f (a • x + b • y) ≤ f y) :
f x ≤ f (a • x + b • y) :=
hf.dual.le_left_of_right_le' hx hy ha hb hab hfy
#align concave_on.left_le_of_le_right' ConcaveOn.left_le_of_le_right'
theorem ConvexOn.le_right_of_left_le' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x ≤ f (a • x + b • y)) :
f (a • x + b • y) ≤ f y := by
rw [add_comm] at hab hfx ⊢
exact hf.le_left_of_right_le' hy hx hb ha hab hfx
#align convex_on.le_right_of_left_le' ConvexOn.le_right_of_left_le'
theorem ConcaveOn.right_le_of_le_left' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) ≤ f x) :
f y ≤ f (a • x + b • y) :=
hf.dual.le_right_of_left_le' hx hy ha hb hab hfx
#align concave_on.right_le_of_le_left' ConcaveOn.right_le_of_le_left'
theorem ConvexOn.le_left_of_right_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hyz : f y ≤ f z) : f z ≤ f x := by
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz
exact hf.le_left_of_right_le' hx hy ha hb.le hab hyz
#align convex_on.le_left_of_right_le ConvexOn.le_left_of_right_le
theorem ConcaveOn.left_le_of_le_right (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hyz : f z ≤ f y) : f x ≤ f z :=
hf.dual.le_left_of_right_le hx hy hz hyz
#align concave_on.left_le_of_le_right ConcaveOn.left_le_of_le_right
theorem ConvexOn.le_right_of_left_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hxz : f x ≤ f z) : f z ≤ f y := by
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz
exact hf.le_right_of_left_le' hx hy ha.le hb hab hxz
#align convex_on.le_right_of_left_le ConvexOn.le_right_of_left_le
theorem ConcaveOn.right_le_of_le_left (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hxz : f z ≤ f x) : f y ≤ f z :=
hf.dual.le_right_of_left_le hx hy hz hxz
#align concave_on.right_le_of_le_left ConcaveOn.right_le_of_le_left
end OrderedSMul
section Module
variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β}
/- The following lemmas don't require `Module 𝕜 E` if you add the hypothesis `x ≠ y`. At the time of
the writing, we decided the resulting lemmas wouldn't be useful. Feel free to reintroduce them. -/
theorem ConvexOn.lt_left_of_right_lt' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f y < f (a • x + b • y)) :
f (a • x + b • y) < f x :=
not_le.1 fun h ↦ lt_irrefl (f (a • x + b • y)) <|
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb.le hab
_ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_le_of_lt
(smul_le_smul_of_nonneg_left h ha.le) (smul_lt_smul_of_pos_left hfy hb)
_ = f (a • x + b • y) := Convex.combo_self hab _
#align convex_on.lt_left_of_right_lt' ConvexOn.lt_left_of_right_lt'
theorem ConcaveOn.left_lt_of_lt_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f (a • x + b • y) < f y) :
f x < f (a • x + b • y) :=
hf.dual.lt_left_of_right_lt' hx hy ha hb hab hfy
#align concave_on.left_lt_of_lt_right' ConcaveOn.left_lt_of_lt_right'
theorem ConvexOn.lt_right_of_left_lt' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x < f (a • x + b • y)) :
f (a • x + b • y) < f y := by
rw [add_comm] at hab hfx ⊢
exact hf.lt_left_of_right_lt' hy hx hb ha hab hfx
#align convex_on.lt_right_of_left_lt' ConvexOn.lt_right_of_left_lt'
theorem ConcaveOn.lt_right_of_left_lt' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) < f x) :
f y < f (a • x + b • y) :=
hf.dual.lt_right_of_left_lt' hx hy ha hb hab hfx
#align concave_on.lt_right_of_left_lt' ConcaveOn.lt_right_of_left_lt'
| Mathlib/Analysis/Convex/Function.lean | 805 | 808 | theorem ConvexOn.lt_left_of_right_lt (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hyz : f y < f z) : f z < f x := by |
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz
exact hf.lt_left_of_right_lt' hx hy ha hb hab hyz
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Sébastien Gouëzel, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.Projection
import Mathlib.Analysis.NormedSpace.PiLp
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.UnitaryGroup
#align_import analysis.inner_product_space.pi_L2 from "leanprover-community/mathlib"@"13bce9a6b6c44f6b4c91ac1c1d2a816e2533d395"
/-!
# `L²` inner product space structure on finite products of inner product spaces
The `L²` norm on a finite product of inner product spaces is compatible with an inner product
$$
\langle x, y\rangle = \sum \langle x_i, y_i \rangle.
$$
This is recorded in this file as an inner product space instance on `PiLp 2`.
This file develops the notion of a finite dimensional Hilbert space over `𝕜 = ℂ, ℝ`, referred to as
`E`. We define an `OrthonormalBasis 𝕜 ι E` as a linear isometric equivalence
between `E` and `EuclideanSpace 𝕜 ι`. Then `stdOrthonormalBasis` shows that such an equivalence
always exists if `E` is finite dimensional. We provide language for converting between a basis
that is orthonormal and an orthonormal basis (e.g. `Basis.toOrthonormalBasis`). We show that
orthonormal bases for each summand in a direct sum of spaces can be combined into an orthonormal
basis for the whole sum in `DirectSum.IsInternal.subordinateOrthonormalBasis`. In
the last section, various properties of matrices are explored.
## Main definitions
- `EuclideanSpace 𝕜 n`: defined to be `PiLp 2 (n → 𝕜)` for any `Fintype n`, i.e., the space
from functions to `n` to `𝕜` with the `L²` norm. We register several instances on it (notably
that it is a finite-dimensional inner product space).
- `OrthonormalBasis 𝕜 ι`: defined to be an isometry to Euclidean space from a given
finite-dimensional inner product space, `E ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 ι`.
- `Basis.toOrthonormalBasis`: constructs an `OrthonormalBasis` for a finite-dimensional
Euclidean space from a `Basis` which is `Orthonormal`.
- `Orthonormal.exists_orthonormalBasis_extension`: provides an existential result of an
`OrthonormalBasis` extending a given orthonormal set
- `exists_orthonormalBasis`: provides an orthonormal basis on a finite dimensional vector space
- `stdOrthonormalBasis`: provides an arbitrarily-chosen `OrthonormalBasis` of a given finite
dimensional inner product space
For consequences in infinite dimension (Hilbert bases, etc.), see the file
`Analysis.InnerProductSpace.L2Space`.
-/
set_option linter.uppercaseLean3 false
open Real Set Filter RCLike Submodule Function Uniformity Topology NNReal ENNReal
ComplexConjugate DirectSum
noncomputable section
variable {ι ι' 𝕜 : Type*} [RCLike 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E']
variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
variable {F' : Type*} [NormedAddCommGroup F'] [InnerProductSpace ℝ F']
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-
If `ι` is a finite type and each space `f i`, `i : ι`, is an inner product space,
then `Π i, f i` is an inner product space as well. Since `Π i, f i` is endowed with the sup norm,
we use instead `PiLp 2 f` for the product space, which is endowed with the `L^2` norm.
-/
instance PiLp.innerProductSpace {ι : Type*} [Fintype ι] (f : ι → Type*)
[∀ i, NormedAddCommGroup (f i)] [∀ i, InnerProductSpace 𝕜 (f i)] :
InnerProductSpace 𝕜 (PiLp 2 f) where
inner x y := ∑ i, inner (x i) (y i)
norm_sq_eq_inner x := by
simp only [PiLp.norm_sq_eq_of_L2, map_sum, ← norm_sq_eq_inner, one_div]
conj_symm := by
intro x y
unfold inner
rw [map_sum]
apply Finset.sum_congr rfl
rintro z -
apply inner_conj_symm
add_left x y z :=
show (∑ i, inner (x i + y i) (z i)) = (∑ i, inner (x i) (z i)) + ∑ i, inner (y i) (z i) by
simp only [inner_add_left, Finset.sum_add_distrib]
smul_left x y r :=
show (∑ i : ι, inner (r • x i) (y i)) = conj r * ∑ i, inner (x i) (y i) by
simp only [Finset.mul_sum, inner_smul_left]
#align pi_Lp.inner_product_space PiLp.innerProductSpace
@[simp]
theorem PiLp.inner_apply {ι : Type*} [Fintype ι] {f : ι → Type*} [∀ i, NormedAddCommGroup (f i)]
[∀ i, InnerProductSpace 𝕜 (f i)] (x y : PiLp 2 f) : ⟪x, y⟫ = ∑ i, ⟪x i, y i⟫ :=
rfl
#align pi_Lp.inner_apply PiLp.inner_apply
/-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional
space use `EuclideanSpace 𝕜 (Fin n)`. -/
abbrev EuclideanSpace (𝕜 : Type*) (n : Type*) : Type _ :=
PiLp 2 fun _ : n => 𝕜
#align euclidean_space EuclideanSpace
theorem EuclideanSpace.nnnorm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x : EuclideanSpace 𝕜 n) : ‖x‖₊ = NNReal.sqrt (∑ i, ‖x i‖₊ ^ 2) :=
PiLp.nnnorm_eq_of_L2 x
#align euclidean_space.nnnorm_eq EuclideanSpace.nnnorm_eq
theorem EuclideanSpace.norm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x : EuclideanSpace 𝕜 n) : ‖x‖ = √(∑ i, ‖x i‖ ^ 2) := by
simpa only [Real.coe_sqrt, NNReal.coe_sum] using congr_arg ((↑) : ℝ≥0 → ℝ) x.nnnorm_eq
#align euclidean_space.norm_eq EuclideanSpace.norm_eq
theorem EuclideanSpace.dist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x y : EuclideanSpace 𝕜 n) : dist x y = √(∑ i, dist (x i) (y i) ^ 2) :=
PiLp.dist_eq_of_L2 x y
#align euclidean_space.dist_eq EuclideanSpace.dist_eq
theorem EuclideanSpace.nndist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x y : EuclideanSpace 𝕜 n) : nndist x y = NNReal.sqrt (∑ i, nndist (x i) (y i) ^ 2) :=
PiLp.nndist_eq_of_L2 x y
#align euclidean_space.nndist_eq EuclideanSpace.nndist_eq
theorem EuclideanSpace.edist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x y : EuclideanSpace 𝕜 n) : edist x y = (∑ i, edist (x i) (y i) ^ 2) ^ (1 / 2 : ℝ) :=
PiLp.edist_eq_of_L2 x y
#align euclidean_space.edist_eq EuclideanSpace.edist_eq
theorem EuclideanSpace.ball_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) :
Metric.ball (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 < r ^ 2} := by
ext x
have : (0 : ℝ) ≤ ∑ i, x i ^ 2 := Finset.sum_nonneg fun _ _ => sq_nonneg _
simp_rw [mem_setOf, mem_ball_zero_iff, norm_eq, norm_eq_abs, sq_abs, sqrt_lt this hr]
theorem EuclideanSpace.closedBall_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) :
Metric.closedBall (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 ≤ r ^ 2} := by
ext
simp_rw [mem_setOf, mem_closedBall_zero_iff, norm_eq, norm_eq_abs, sq_abs, sqrt_le_left hr]
| Mathlib/Analysis/InnerProductSpace/PiL2.lean | 145 | 150 | theorem EuclideanSpace.sphere_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) :
Metric.sphere (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 = r ^ 2} := by |
ext x
have : (0 : ℝ) ≤ ∑ i, x i ^ 2 := Finset.sum_nonneg fun _ _ => sq_nonneg _
simp_rw [mem_setOf, mem_sphere_zero_iff_norm, norm_eq, norm_eq_abs, sq_abs,
Real.sqrt_eq_iff_sq_eq this hr, eq_comm]
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.SetToL1
#align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
/-!
# Bochner integral
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined through the extension process described in the file `SetToL1`,
which follows these steps:
1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`.
`weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive`
(defined in the file `SetToL1`) with respect to the set `s`.
2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`)
where `E` is a real normed space. (See `SimpleFunc.integral` for details.)
3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation :
`α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear
map from `α →₁ₛ[μ] E` to `E`.
4. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of
`α →₁ₛ[μ] E` into `α →₁[μ] E` is dense.
5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1
space, if it is in L1, and 0 otherwise.
The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to
`setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral
(like linearity) are particular cases of the properties of `setToFun` (which are described in the
file `SetToL1`).
## Main statements
1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure
space and `E` is a real normed space.
* `integral_zero` : `∫ 0 ∂μ = 0`
* `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ`
* `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ`
* `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ`
* `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ`
* `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ`
* `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ`
2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure
space.
* `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
* `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions,
which is called `lintegral` and has the notation `∫⁻`.
* `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` :
`∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`,
where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ`
4. (In the file `DominatedConvergence`)
`tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
5. (In the file `SetIntegral`) integration commutes with continuous linear maps.
* `ContinuousLinearMap.integral_comp_comm`
* `LinearIsometry.integral_comp_comm`
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one
of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove
something for an arbitrary integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves
that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued
function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part`
is scattered in sections with the name `posPart`.
Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all
functions :
1. First go to the `L¹` space.
For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of
`f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`.
3. Show that the property holds for all simple functions `s` in `L¹` space.
Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas
like `L1.integral_coe_eq_integral`.
4. Since simple functions are dense in `L¹`,
```
univ = closure {s simple}
= closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions
⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}
= {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself
```
Use `isClosed_property` or `DenseRange.induction_on` for this argument.
## Notations
* `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`)
* `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`MeasureTheory/LpSpace`)
* `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple
functions (defined in `MeasureTheory/SimpleFuncDense`)
* `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ`
* `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type
We also define notations for integral on a set, which are described in the file
`MeasureTheory/SetIntegral`.
Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
assert_not_exists Differentiable
noncomputable section
open scoped Topology NNReal ENNReal MeasureTheory
open Set Filter TopologicalSpace ENNReal EMetric
namespace MeasureTheory
variable {α E F 𝕜 : Type*}
section WeightedSMul
open ContinuousLinearMap
variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α}
/-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension
of that set function through `setToL1` gives the Bochner integral of L1 functions. -/
def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F :=
(μ s).toReal • ContinuousLinearMap.id ℝ F
#align measure_theory.weighted_smul MeasureTheory.weightedSMul
theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) :
weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul]
#align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply
@[simp]
theorem weightedSMul_zero_measure {m : MeasurableSpace α} :
weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul]
#align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure
@[simp]
theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) :
weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp
#align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty
theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α}
(hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) :
(weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by
ext1 x
push_cast
simp_rw [Pi.add_apply, weightedSMul_apply]
push_cast
rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul]
#align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure
theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} :
(weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by
ext1 x
push_cast
simp_rw [Pi.smul_apply, weightedSMul_apply]
push_cast
simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul]
#align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure
theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) :
(weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by
ext1 x; simp_rw [weightedSMul_apply]; congr 2
#align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr
theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by
ext1 x; rw [weightedSMul_apply, h_zero]; simp
#align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null
theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞)
(ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by
ext1 x
simp_rw [add_apply, weightedSMul_apply,
measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht,
ENNReal.toReal_add hs_finite ht_finite, add_smul]
#align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union'
@[nolint unusedArguments]
theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t :=
weightedSMul_union' s t ht hs_finite ht_finite h_inter
#align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union
theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜)
(s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by
simp_rw [weightedSMul_apply, smul_comm]
#align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul
theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal :=
calc
‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ :=
norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F)
_ ≤ ‖(μ s).toReal‖ :=
((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le)
_ = abs (μ s).toReal := Real.norm_eq_abs _
_ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg
#align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le
theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) :
DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 :=
⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩
#align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul
theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by
simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply]
exact mul_nonneg toReal_nonneg hx
#align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg
end WeightedSMul
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
section PosPart
variable [LinearOrder E] [Zero E] [MeasurableSpace α]
/-- Positive part of a simple function. -/
def posPart (f : α →ₛ E) : α →ₛ E :=
f.map fun b => max b 0
#align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart
/-- Negative part of a simple function. -/
def negPart [Neg E] (f : α →ₛ E) : α →ₛ E :=
posPart (-f)
#align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart
theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by
ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _
#align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm
theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by
rw [negPart]; exact posPart_map_norm _
#align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm
theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by
simp only [posPart, negPart]
ext a
rw [coe_sub]
exact max_zero_sub_eq_self (f a)
#align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart
end PosPart
section Integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group,
and prove basic property of this integral.
-/
open Finset
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*}
[NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α}
{μ : Measure α}
/-- Bochner integral of simple functions whose codomain is a real `NormedSpace`.
This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/
def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F :=
f.setToSimpleFunc (weightedSMul μ)
#align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral
theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl
#align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def
theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by
simp [integral, setToSimpleFunc, weightedSMul_apply]
#align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq
theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α}
(f : α →ₛ F) (μ : Measure α) :
f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by
rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr
#align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter
/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/
theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F}
(hs : (f.range.filter fun x => x ≠ 0) ⊆ s) :
f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by
rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs]
rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx
-- Porting note: reordered for clarity
rcases hx.symm with (rfl | hx)
· simp
rw [SimpleFunc.mem_range] at hx
-- Porting note: added
simp only [Set.mem_range, not_exists] at hx
rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx]
#align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset
@[simp]
theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) :
(const α y).integral μ = (μ univ).toReal • y := by
classical
calc
(const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z :=
integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _)
_ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage`
#align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const
@[simp]
theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α}
(hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by
classical
refine (integral_eq_sum_of_subset ?_).trans
((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm)
· intro y hy
simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,
mem_range_indicator] at *
rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩
exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩]
· dsimp
rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem,
Measure.restrict_apply (f.measurableSet_preimage _)]
exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀)
#align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero
/-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/
theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) :
(f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x :=
map_setToSimpleFunc _ weightedSMul_union hf hg
#align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral
/-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0)
(ht : ∀ b, g b ≠ ∞) :
(f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by
have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf
simp only [← map_apply g f, lintegral_eq_lintegral]
rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum]
· refine Finset.sum_congr rfl fun b _ => ?_
-- Porting note: added `Function.comp_apply`
rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply]
· rintro a -
by_cases a0 : a = 0
· rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top
· apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne
· simp [hg0]
#align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral'
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E]
theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) :
f.integral μ = g.integral μ :=
setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h
#align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr
/-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/
theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) :
f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by
have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) :=
h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm
rw [← integral_eq_lintegral' hf]
exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top]
#align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral
theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f + g) = integral μ f + integral μ g :=
setToSimpleFunc_add _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add
theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f :=
setToSimpleFunc_neg _ weightedSMul_union hf
#align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg
theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f - g) = integral μ f - integral μ g :=
setToSimpleFunc_sub _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub
theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) :
integral μ (c • f) = c • integral μ f :=
setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf
#align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul
theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E}
(hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ :=
calc
‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ :=
norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf
_ = C * (f.map norm).integral μ := by
rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul]
#align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm
theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) :
‖f.integral μ‖ ≤ (f.map norm).integral μ := by
refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le
exact (norm_weightedSMul_le s).trans (one_mul _).symm.le
#align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm
theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) :
f.integral (μ + ν) = f.integral μ + f.integral ν := by
simp_rw [integral_def]
refine setToSimpleFunc_add_left'
(weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf
rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs
rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2]
#align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure
end Integral
end SimpleFunc
namespace L1
set_option linter.uppercaseLean3 false -- `L1`
open AEEqFun Lp.simpleFunc Lp
variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α}
namespace SimpleFunc
theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by
rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero]
simp_rw [smul_eq_mul]
#align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral
section PosPart
/-- Positive part of a simple function in L1 space. -/
nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
⟨Lp.posPart (f : α →₁[μ] ℝ), by
rcases f with ⟨f, s, hsf⟩
use s.posPart
simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk,
SimpleFunc.coe_map, mk_eq_mk]
-- Porting note: added
simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩
#align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart
/-- Negative part of a simple function in L1 space. -/
def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
posPart (-f)
#align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart
@[norm_cast]
theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart
@[norm_cast]
theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart
end PosPart
section SimpleFuncIntegral
/-!
### The Bochner integral of `L1`
Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`,
and prove basic properties of this integral. -/
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*}
[NormedAddCommGroup F'] [NormedSpace ℝ F']
attribute [local instance] simpleFunc.normedSpace
/-- The Bochner integral over simple functions in L1 space. -/
def integral (f : α →₁ₛ[μ] E) : E :=
(toSimpleFunc f).integral μ
#align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral
theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl
#align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral
nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) :
integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by
rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos]
#align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral
theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl
#align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S
nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
integral f = integral g :=
SimpleFunc.integral_congr (SimpleFunc.integrable f) h
#align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr
theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g :=
setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _
#align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add
theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f :=
setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f
#align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul
theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by
rw [integral, norm_eq_integral]
exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f)
#align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm
variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E']
variable (α E μ 𝕜)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/
def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E :=
LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f =>
le_trans (norm_integral_le_norm _) <| by rw [one_mul]
#align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM'
/-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E :=
integralCLM' α E ℝ μ
#align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM
variable {α E μ 𝕜}
local notation "Integral" => integralCLM α E μ
open ContinuousLinearMap
theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 :=
-- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _`
LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by
rw [one_mul]
exact norm_integral_le_norm f)
#align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one
section PosPart
theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by
have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl
have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by
filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ),
toSimpleFunc_eq_toFun f] with _ _ h₂ h₃
convert h₂ using 1
-- Porting note: added
rw [h₃]
refine ae_eq.mono fun a h => ?_
rw [h, eq]
#align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc
theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by
rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart]
filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f]
intro a h₁ h₂
rw [h₁]
show max _ _ = max _ _
rw [h₂]
rfl
#align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc
theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by
filter_upwards [posPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply]
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by
filter_upwards [negPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply]
rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub]
· show (toSimpleFunc f).integral μ =
((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ
apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f)
filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂
show _ = _ - _
rw [← h₁, ← h₂]
have := (toSimpleFunc f).posPart_sub_negPart
conv_lhs => rw [← this]
rfl
· exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁
· exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂
#align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub
end PosPart
end SimpleFuncIntegral
end SimpleFunc
open SimpleFunc
local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _
variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E]
[NormedSpace ℝ F] [CompleteSpace E]
section IntegrationInL1
attribute [local instance] simpleFunc.normedSpace
open ContinuousLinearMap
variable (𝕜)
/-- The Bochner integral in L1 space as a continuous linear map. -/
nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E :=
(integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.uniformInducing
#align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM'
variable {𝕜}
/-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁[μ] E) →L[ℝ] E :=
integralCLM' ℝ
#align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM
-- Porting note: added `(E := E)` in several places below.
/-- The Bochner integral in L1 space -/
irreducible_def integral (f : α →₁[μ] E) : E :=
integralCLM (E := E) f
#align measure_theory.L1.integral MeasureTheory.L1.integral
theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by
simp only [integral]
#align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq
theorem integral_eq_setToL1 (f : α →₁[μ] E) :
integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral]; rfl
#align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1
@[norm_cast]
theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) :
L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by
simp only [integral, L1.integral]
exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f
#align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral
variable (α E)
@[simp]
theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by
simp only [integral]
exact map_zero integralCLM
#align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero
variable {α E}
@[integral_simps]
theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by
simp only [integral]
exact map_add integralCLM f g
#align measure_theory.L1.integral_add MeasureTheory.L1.integral_add
@[integral_simps]
theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by
simp only [integral]
exact map_neg integralCLM f
#align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg
@[integral_simps]
| Mathlib/MeasureTheory/Integral/Bochner.lean | 708 | 710 | theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by |
simp only [integral]
exact map_sub integralCLM f g
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Complex
import Qq
#align_import analysis.special_functions.pow.real from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8"
/-! # Power function on `ℝ`
We construct the power functions `x ^ y`, where `x` and `y` are real numbers.
-/
noncomputable section
open scoped Classical
open Real ComplexConjugate
open Finset Set
/-
## Definitions
-/
namespace Real
variable {x y z : ℝ}
/-- The real power function `x ^ y`, defined as the real part of the complex power function.
For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for
`y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex
determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/
noncomputable def rpow (x y : ℝ) :=
((x : ℂ) ^ (y : ℂ)).re
#align real.rpow Real.rpow
noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl
#align real.rpow_eq_pow Real.rpow_eq_pow
theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl
#align real.rpow_def Real.rpow_def
theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by
simp only [rpow_def, Complex.cpow_def]; split_ifs <;>
simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, -RCLike.ofReal_mul,
(Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero]
#align real.rpow_def_of_nonneg Real.rpow_def_of_nonneg
theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by
rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]
#align real.rpow_def_of_pos Real.rpow_def_of_pos
theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp]
#align real.exp_mul Real.exp_mul
@[simp, norm_cast]
theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast,
Complex.ofReal_re]
#align real.rpow_int_cast Real.rpow_intCast
@[deprecated (since := "2024-04-17")]
alias rpow_int_cast := rpow_intCast
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n
#align real.rpow_nat_cast Real.rpow_natCast
@[deprecated (since := "2024-04-17")]
alias rpow_nat_cast := rpow_natCast
@[simp]
theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul]
#align real.exp_one_rpow Real.exp_one_rpow
@[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow]
theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
simp only [rpow_def_of_nonneg hx]
split_ifs <;> simp [*, exp_ne_zero]
#align real.rpow_eq_zero_iff_of_nonneg Real.rpow_eq_zero_iff_of_nonneg
@[simp]
lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by
simp [rpow_eq_zero_iff_of_nonneg, *]
@[simp]
lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 :=
Real.rpow_eq_zero hx hy |>.not
open Real
theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by
rw [rpow_def, Complex.cpow_def, if_neg]
· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by
simp only [Complex.log, abs_of_neg hx, Complex.arg_ofReal_of_neg hx, Complex.abs_ofReal,
Complex.ofReal_mul]
ring
rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ←
Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul,
Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im,
Real.log_neg_eq_log]
ring
· rw [Complex.ofReal_eq_zero]
exact ne_of_lt hx
#align real.rpow_def_of_neg Real.rpow_def_of_neg
theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by
split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _
#align real.rpow_def_of_nonpos Real.rpow_def_of_nonpos
theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by
rw [rpow_def_of_pos hx]; apply exp_pos
#align real.rpow_pos_of_pos Real.rpow_pos_of_pos
@[simp]
theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def]
#align real.rpow_zero Real.rpow_zero
theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *]
#align real.zero_rpow Real.zero_rpow
theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
constructor
· intro hyp
simp only [rpow_def, Complex.ofReal_zero] at hyp
by_cases h : x = 0
· subst h
simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp
exact Or.inr ⟨rfl, hyp.symm⟩
· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp
exact Or.inl ⟨h, hyp.symm⟩
· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩)
· exact zero_rpow h
· exact rpow_zero _
#align real.zero_rpow_eq_iff Real.zero_rpow_eq_iff
theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
rw [← zero_rpow_eq_iff, eq_comm]
#align real.eq_zero_rpow_iff Real.eq_zero_rpow_iff
@[simp]
theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def]
#align real.rpow_one Real.rpow_one
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def]
#align real.one_rpow Real.one_rpow
theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
#align real.zero_rpow_le_one Real.zero_rpow_le_one
theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
#align real.zero_rpow_nonneg Real.zero_rpow_nonneg
theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by
rw [rpow_def_of_nonneg hx]; split_ifs <;>
simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)]
#align real.rpow_nonneg_of_nonneg Real.rpow_nonneg
theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by
have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _
rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg]
#align real.abs_rpow_of_nonneg Real.abs_rpow_of_nonneg
theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by
rcases le_or_lt 0 x with hx | hx
· rw [abs_rpow_of_nonneg hx]
· rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul,
abs_of_pos (exp_pos _)]
exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _)
#align real.abs_rpow_le_abs_rpow Real.abs_rpow_le_abs_rpow
theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by
refine (abs_rpow_le_abs_rpow x y).trans ?_
by_cases hx : x = 0
· by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one]
· rw [rpow_def_of_pos (abs_pos.2 hx), log_abs]
#align real.abs_rpow_le_exp_log_mul Real.abs_rpow_le_exp_log_mul
theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by
simp_rw [Real.norm_eq_abs]
exact abs_rpow_of_nonneg hx_nonneg
#align real.norm_rpow_of_nonneg Real.norm_rpow_of_nonneg
variable {w x y z : ℝ}
theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by
simp only [rpow_def_of_pos hx, mul_add, exp_add]
#align real.rpow_add Real.rpow_add
theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by
rcases hx.eq_or_lt with (rfl | pos)
· rw [zero_rpow h, zero_eq_mul]
have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0
exact this.imp zero_rpow zero_rpow
· exact rpow_add pos _ _
#align real.rpow_add' Real.rpow_add'
/-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add' hx]; rwa [h]
theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
rcases hy.eq_or_lt with (rfl | hy)
· rw [zero_add, rpow_zero, one_mul]
exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz)
#align real.rpow_add_of_nonneg Real.rpow_add_of_nonneg
/-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for
`x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish.
The inequality is always true, though, and given in this lemma. -/
theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by
rcases le_iff_eq_or_lt.1 hx with (H | pos)
· by_cases h : y + z = 0
· simp only [H.symm, h, rpow_zero]
calc
(0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 :=
mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one
_ = 1 := by simp
· simp [rpow_add', ← H, h]
· simp [rpow_add pos]
#align real.le_rpow_add Real.le_rpow_add
theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) :
(a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x :=
map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s
#align real.rpow_sum_of_pos Real.rpow_sum_of_pos
theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ}
(h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by
induction' s using Finset.cons_induction with i s hi ihs
· rw [sum_empty, Finset.prod_empty, rpow_zero]
· rw [forall_mem_cons] at h
rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)]
#align real.rpow_sum_of_nonneg Real.rpow_sum_of_nonneg
theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg]
#align real.rpow_neg Real.rpow_neg
theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv]
#align real.rpow_sub Real.rpow_sub
theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg] at h ⊢
simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv]
#align real.rpow_sub' Real.rpow_sub'
end Real
/-!
## Comparing real and complex powers
-/
namespace Complex
theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by
simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;>
simp [Complex.ofReal_log hx]
#align complex.of_real_cpow Complex.ofReal_cpow
| Mathlib/Analysis/SpecialFunctions/Pow/Real.lean | 280 | 287 | theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) :
(x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by |
rcases hx.eq_or_lt with (rfl | hlt)
· rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*]
have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne
rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log,
log, abs.map_neg, arg_ofReal_of_neg hlt, ← ofReal_neg,
arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero]
|
/-
Copyright (c) 2022 Rémy Degenne, Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Kexing Ying
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.MeasureTheory.Function.Egorov
import Mathlib.MeasureTheory.Function.LpSpace
#align_import measure_theory.function.convergence_in_measure from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8"
/-!
# Convergence in measure
We define convergence in measure which is one of the many notions of convergence in probability.
A sequence of functions `f` is said to converge in measure to some function `g`
if for all `ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i`
converges along some given filter `l`.
Convergence in measure is most notably used in the formulation of the weak law of large numbers
and is also useful in theorems such as the Vitali convergence theorem. This file provides some
basic lemmas for working with convergence in measure and establishes some relations between
convergence in measure and other notions of convergence.
## Main definitions
* `MeasureTheory.TendstoInMeasure (μ : Measure α) (f : ι → α → E) (g : α → E)`: `f` converges
in `μ`-measure to `g`.
## Main results
* `MeasureTheory.tendstoInMeasure_of_tendsto_ae`: convergence almost everywhere in a finite
measure space implies convergence in measure.
* `MeasureTheory.TendstoInMeasure.exists_seq_tendsto_ae`: if `f` is a sequence of functions
which converges in measure to `g`, then `f` has a subsequence which convergence almost
everywhere to `g`.
* `MeasureTheory.tendstoInMeasure_of_tendsto_snorm`: convergence in Lp implies convergence
in measure.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory Topology
namespace MeasureTheory
variable {α ι E : Type*} {m : MeasurableSpace α} {μ : Measure α}
/-- A sequence of functions `f` is said to converge in measure to some function `g` if for all
`ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i` converges along
some given filter `l`. -/
def TendstoInMeasure [Dist E] {_ : MeasurableSpace α} (μ : Measure α) (f : ι → α → E) (l : Filter ι)
(g : α → E) : Prop :=
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ dist (f i x) (g x) }) l (𝓝 0)
#align measure_theory.tendsto_in_measure MeasureTheory.TendstoInMeasure
theorem tendstoInMeasure_iff_norm [SeminormedAddCommGroup E] {l : Filter ι} {f : ι → α → E}
{g : α → E} :
TendstoInMeasure μ f l g ↔
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ ‖f i x - g x‖ }) l (𝓝 0) := by
simp_rw [TendstoInMeasure, dist_eq_norm]
#align measure_theory.tendsto_in_measure_iff_norm MeasureTheory.tendstoInMeasure_iff_norm
namespace TendstoInMeasure
variable [Dist E] {l : Filter ι} {f f' : ι → α → E} {g g' : α → E}
protected theorem congr' (h_left : ∀ᶠ i in l, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' := by
intro ε hε
suffices
(fun i => μ { x | ε ≤ dist (f' i x) (g' x) }) =ᶠ[l] fun i => μ { x | ε ≤ dist (f i x) (g x) } by
rw [tendsto_congr' this]
exact h_tendsto ε hε
filter_upwards [h_left] with i h_ae_eq
refine measure_congr ?_
filter_upwards [h_ae_eq, h_right] with x hxf hxg
rw [eq_iff_iff]
change ε ≤ dist (f' i x) (g' x) ↔ ε ≤ dist (f i x) (g x)
rw [hxg, hxf]
#align measure_theory.tendsto_in_measure.congr' MeasureTheory.TendstoInMeasure.congr'
protected theorem congr (h_left : ∀ i, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' :=
TendstoInMeasure.congr' (eventually_of_forall h_left) h_right h_tendsto
#align measure_theory.tendsto_in_measure.congr MeasureTheory.TendstoInMeasure.congr
theorem congr_left (h : ∀ i, f i =ᵐ[μ] f' i) (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f' l g :=
h_tendsto.congr h EventuallyEq.rfl
#align measure_theory.tendsto_in_measure.congr_left MeasureTheory.TendstoInMeasure.congr_left
theorem congr_right (h : g =ᵐ[μ] g') (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f l g' :=
h_tendsto.congr (fun _ => EventuallyEq.rfl) h
#align measure_theory.tendsto_in_measure.congr_right MeasureTheory.TendstoInMeasure.congr_right
end TendstoInMeasure
section ExistsSeqTendstoAe
variable [MetricSpace E]
variable {f : ℕ → α → E} {g : α → E}
/-- Auxiliary lemma for `tendstoInMeasure_of_tendsto_ae`. -/
theorem tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable [IsFiniteMeasure μ]
(hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by
refine fun ε hε => ENNReal.tendsto_atTop_zero.mpr fun δ hδ => ?_
by_cases hδi : δ = ∞
· simp only [hδi, imp_true_iff, le_top, exists_const]
lift δ to ℝ≥0 using hδi
rw [gt_iff_lt, ENNReal.coe_pos, ← NNReal.coe_pos] at hδ
obtain ⟨t, _, ht, hunif⟩ := tendstoUniformlyOn_of_ae_tendsto' hf hg hfg hδ
rw [ENNReal.ofReal_coe_nnreal] at ht
rw [Metric.tendstoUniformlyOn_iff] at hunif
obtain ⟨N, hN⟩ := eventually_atTop.1 (hunif ε hε)
refine ⟨N, fun n hn => ?_⟩
suffices { x : α | ε ≤ dist (f n x) (g x) } ⊆ t from (measure_mono this).trans ht
rw [← Set.compl_subset_compl]
intro x hx
rw [Set.mem_compl_iff, Set.nmem_setOf_iff, dist_comm, not_le]
exact hN n hn x hx
#align measure_theory.tendsto_in_measure_of_tendsto_ae_of_strongly_measurable MeasureTheory.tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable
/-- Convergence a.e. implies convergence in measure in a finite measure space. -/
theorem tendstoInMeasure_of_tendsto_ae [IsFiniteMeasure μ] (hf : ∀ n, AEStronglyMeasurable (f n) μ)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by
have hg : AEStronglyMeasurable g μ := aestronglyMeasurable_of_tendsto_ae _ hf hfg
refine TendstoInMeasure.congr (fun i => (hf i).ae_eq_mk.symm) hg.ae_eq_mk.symm ?_
refine tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable
(fun i => (hf i).stronglyMeasurable_mk) hg.stronglyMeasurable_mk ?_
have hf_eq_ae : ∀ᵐ x ∂μ, ∀ n, (hf n).mk (f n) x = f n x :=
ae_all_iff.mpr fun n => (hf n).ae_eq_mk.symm
filter_upwards [hf_eq_ae, hg.ae_eq_mk, hfg] with x hxf hxg hxfg
rw [← hxg, funext fun n => hxf n]
exact hxfg
#align measure_theory.tendsto_in_measure_of_tendsto_ae MeasureTheory.tendstoInMeasure_of_tendsto_ae
namespace ExistsSeqTendstoAe
theorem exists_nat_measure_lt_two_inv (hfg : TendstoInMeasure μ f atTop g) (n : ℕ) :
∃ N, ∀ m ≥ N, μ { x | (2 : ℝ)⁻¹ ^ n ≤ dist (f m x) (g x) } ≤ (2⁻¹ : ℝ≥0∞) ^ n := by
specialize hfg ((2⁻¹ : ℝ) ^ n) (by simp only [Real.rpow_natCast, inv_pos, zero_lt_two, pow_pos])
rw [ENNReal.tendsto_atTop_zero] at hfg
exact hfg ((2 : ℝ≥0∞)⁻¹ ^ n) (pos_iff_ne_zero.mpr fun h_zero => by simpa using pow_eq_zero h_zero)
#align measure_theory.exists_seq_tendsto_ae.exists_nat_measure_lt_two_inv MeasureTheory.ExistsSeqTendstoAe.exists_nat_measure_lt_two_inv
/-- Given a sequence of functions `f` which converges in measure to `g`,
`seqTendstoAeSeqAux` is a sequence such that
`∀ m ≥ seqTendstoAeSeqAux n, μ {x | 2⁻¹ ^ n ≤ dist (f m x) (g x)} ≤ 2⁻¹ ^ n`. -/
noncomputable def seqTendstoAeSeqAux (hfg : TendstoInMeasure μ f atTop g) (n : ℕ) :=
Classical.choose (exists_nat_measure_lt_two_inv hfg n)
#align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq_aux MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeqAux
/-- Transformation of `seqTendstoAeSeqAux` to makes sure it is strictly monotone. -/
noncomputable def seqTendstoAeSeq (hfg : TendstoInMeasure μ f atTop g) : ℕ → ℕ
| 0 => seqTendstoAeSeqAux hfg 0
| n + 1 => max (seqTendstoAeSeqAux hfg (n + 1)) (seqTendstoAeSeq hfg n + 1)
#align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeq
theorem seqTendstoAeSeq_succ (hfg : TendstoInMeasure μ f atTop g) {n : ℕ} :
seqTendstoAeSeq hfg (n + 1) =
max (seqTendstoAeSeqAux hfg (n + 1)) (seqTendstoAeSeq hfg n + 1) := by
rw [seqTendstoAeSeq]
#align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq_succ MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeq_succ
theorem seqTendstoAeSeq_spec (hfg : TendstoInMeasure μ f atTop g) (n k : ℕ)
(hn : seqTendstoAeSeq hfg n ≤ k) :
μ { x | (2 : ℝ)⁻¹ ^ n ≤ dist (f k x) (g x) } ≤ (2 : ℝ≥0∞)⁻¹ ^ n := by
cases n
· exact Classical.choose_spec (exists_nat_measure_lt_two_inv hfg 0) k hn
· exact Classical.choose_spec
(exists_nat_measure_lt_two_inv hfg _) _ (le_trans (le_max_left _ _) hn)
#align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq_spec MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeq_spec
theorem seqTendstoAeSeq_strictMono (hfg : TendstoInMeasure μ f atTop g) :
StrictMono (seqTendstoAeSeq hfg) := by
refine strictMono_nat_of_lt_succ fun n => ?_
rw [seqTendstoAeSeq_succ]
exact lt_of_lt_of_le (lt_add_one <| seqTendstoAeSeq hfg n) (le_max_right _ _)
#align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq_strict_mono MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeq_strictMono
end ExistsSeqTendstoAe
/-- If `f` is a sequence of functions which converges in measure to `g`, then there exists a
subsequence of `f` which converges a.e. to `g`. -/
theorem TendstoInMeasure.exists_seq_tendsto_ae (hfg : TendstoInMeasure μ f atTop g) :
∃ ns : ℕ → ℕ, StrictMono ns ∧ ∀ᵐ x ∂μ, Tendsto (fun i => f (ns i) x) atTop (𝓝 (g x)) := by
/- Since `f` tends to `g` in measure, it has a subsequence `k ↦ f (ns k)` such that
`μ {|f (ns k) - g| ≥ 2⁻ᵏ} ≤ 2⁻ᵏ` for all `k`. Defining
`s := ⋂ k, ⋃ i ≥ k, {|f (ns k) - g| ≥ 2⁻ᵏ}`, we see that `μ s = 0` by the
first Borel-Cantelli lemma.
On the other hand, as `s` is precisely the set for which `f (ns k)`
doesn't converge to `g`, `f (ns k)` converges almost everywhere to `g` as required. -/
have h_lt_ε_real : ∀ (ε : ℝ) (_ : 0 < ε), ∃ k : ℕ, 2 * (2 : ℝ)⁻¹ ^ k < ε := by
intro ε hε
obtain ⟨k, h_k⟩ : ∃ k : ℕ, (2 : ℝ)⁻¹ ^ k < ε := exists_pow_lt_of_lt_one hε (by norm_num)
refine ⟨k + 1, (le_of_eq ?_).trans_lt h_k⟩
rw [pow_add]; ring
set ns := ExistsSeqTendstoAe.seqTendstoAeSeq hfg
use ns
let S := fun k => { x | (2 : ℝ)⁻¹ ^ k ≤ dist (f (ns k) x) (g x) }
have hμS_le : ∀ k, μ (S k) ≤ (2 : ℝ≥0∞)⁻¹ ^ k :=
fun k => ExistsSeqTendstoAe.seqTendstoAeSeq_spec hfg k (ns k) le_rfl
set s := Filter.atTop.limsup S with hs
have hμs : μ s = 0 := by
refine measure_limsup_eq_zero (ne_of_lt <| lt_of_le_of_lt (ENNReal.tsum_le_tsum hμS_le) ?_)
simp only [ENNReal.tsum_geometric, ENNReal.one_sub_inv_two, ENNReal.two_lt_top, inv_inv]
have h_tendsto : ∀ x ∈ sᶜ, Tendsto (fun i => f (ns i) x) atTop (𝓝 (g x)) := by
refine fun x hx => Metric.tendsto_atTop.mpr fun ε hε => ?_
rw [hs, limsup_eq_iInf_iSup_of_nat] at hx
simp only [S, Set.iSup_eq_iUnion, Set.iInf_eq_iInter, Set.compl_iInter, Set.compl_iUnion,
Set.mem_iUnion, Set.mem_iInter, Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hx
obtain ⟨N, hNx⟩ := hx
obtain ⟨k, hk_lt_ε⟩ := h_lt_ε_real ε hε
refine ⟨max N (k - 1), fun n hn_ge => lt_of_le_of_lt ?_ hk_lt_ε⟩
specialize hNx n ((le_max_left _ _).trans hn_ge)
have h_inv_n_le_k : (2 : ℝ)⁻¹ ^ n ≤ 2 * (2 : ℝ)⁻¹ ^ k := by
rw [mul_comm, ← inv_mul_le_iff' (zero_lt_two' ℝ)]
conv_lhs =>
congr
rw [← pow_one (2 : ℝ)⁻¹]
rw [← pow_add, add_comm]
exact pow_le_pow_of_le_one (one_div (2 : ℝ) ▸ one_half_pos.le) (inv_le_one one_le_two)
((le_tsub_add.trans (add_le_add_right (le_max_right _ _) 1)).trans
(add_le_add_right hn_ge 1))
exact le_trans hNx.le h_inv_n_le_k
rw [ae_iff]
refine ⟨ExistsSeqTendstoAe.seqTendstoAeSeq_strictMono hfg, measure_mono_null (fun x => ?_) hμs⟩
rw [Set.mem_setOf_eq, ← @Classical.not_not (x ∈ s), not_imp_not]
exact h_tendsto x
#align measure_theory.tendsto_in_measure.exists_seq_tendsto_ae MeasureTheory.TendstoInMeasure.exists_seq_tendsto_ae
theorem TendstoInMeasure.exists_seq_tendstoInMeasure_atTop {u : Filter ι} [NeBot u]
[IsCountablyGenerated u] {f : ι → α → E} {g : α → E} (hfg : TendstoInMeasure μ f u g) :
∃ ns : ℕ → ι, TendstoInMeasure μ (fun n => f (ns n)) atTop g := by
obtain ⟨ns, h_tendsto_ns⟩ : ∃ ns : ℕ → ι, Tendsto ns atTop u := exists_seq_tendsto u
exact ⟨ns, fun ε hε => (hfg ε hε).comp h_tendsto_ns⟩
#align measure_theory.tendsto_in_measure.exists_seq_tendsto_in_measure_at_top MeasureTheory.TendstoInMeasure.exists_seq_tendstoInMeasure_atTop
theorem TendstoInMeasure.exists_seq_tendsto_ae' {u : Filter ι} [NeBot u] [IsCountablyGenerated u]
{f : ι → α → E} {g : α → E} (hfg : TendstoInMeasure μ f u g) :
∃ ns : ℕ → ι, ∀ᵐ x ∂μ, Tendsto (fun i => f (ns i) x) atTop (𝓝 (g x)) := by
obtain ⟨ms, hms⟩ := hfg.exists_seq_tendstoInMeasure_atTop
obtain ⟨ns, -, hns⟩ := hms.exists_seq_tendsto_ae
exact ⟨ms ∘ ns, hns⟩
#align measure_theory.tendsto_in_measure.exists_seq_tendsto_ae' MeasureTheory.TendstoInMeasure.exists_seq_tendsto_ae'
end ExistsSeqTendstoAe
section AEMeasurableOf
variable [MeasurableSpace E] [NormedAddCommGroup E] [BorelSpace E]
theorem TendstoInMeasure.aemeasurable {u : Filter ι} [NeBot u] [IsCountablyGenerated u]
{f : ι → α → E} {g : α → E} (hf : ∀ n, AEMeasurable (f n) μ)
(h_tendsto : TendstoInMeasure μ f u g) : AEMeasurable g μ := by
obtain ⟨ns, hns⟩ := h_tendsto.exists_seq_tendsto_ae'
exact aemeasurable_of_tendsto_metrizable_ae atTop (fun n => hf (ns n)) hns
#align measure_theory.tendsto_in_measure.ae_measurable MeasureTheory.TendstoInMeasure.aemeasurable
end AEMeasurableOf
section TendstoInMeasureOf
variable [NormedAddCommGroup E] {p : ℝ≥0∞}
variable {f : ι → α → E} {g : α → E}
/-- This lemma is superceded by `MeasureTheory.tendstoInMeasure_of_tendsto_snorm` where we
allow `p = ∞` and only require `AEStronglyMeasurable`. -/
theorem tendstoInMeasure_of_tendsto_snorm_of_stronglyMeasurable (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g)
{l : Filter ι} (hfg : Tendsto (fun n => snorm (f n - g) p μ) l (𝓝 0)) :
TendstoInMeasure μ f l g := by
intro ε hε
replace hfg := ENNReal.Tendsto.const_mul
(Tendsto.ennrpow_const p.toReal hfg) (Or.inr <| @ENNReal.ofReal_ne_top (1 / ε ^ p.toReal))
simp only [mul_zero,
ENNReal.zero_rpow_of_pos (ENNReal.toReal_pos hp_ne_zero hp_ne_top)] at hfg
rw [ENNReal.tendsto_nhds_zero] at hfg ⊢
intro δ hδ
refine (hfg δ hδ).mono fun n hn => ?_
refine le_trans ?_ hn
rw [ENNReal.ofReal_div_of_pos (Real.rpow_pos_of_pos hε _), ENNReal.ofReal_one, mul_comm,
mul_one_div, ENNReal.le_div_iff_mul_le _ (Or.inl ENNReal.ofReal_ne_top), mul_comm]
· rw [← ENNReal.ofReal_rpow_of_pos hε]
convert mul_meas_ge_le_pow_snorm' μ hp_ne_zero hp_ne_top ((hf n).sub hg).aestronglyMeasurable
(ENNReal.ofReal ε)
rw [dist_eq_norm, ← ENNReal.ofReal_le_ofReal_iff (norm_nonneg _), ofReal_norm_eq_coe_nnnorm]
exact Iff.rfl
· rw [Ne, ENNReal.ofReal_eq_zero, not_le]
exact Or.inl (Real.rpow_pos_of_pos hε _)
#align measure_theory.tendsto_in_measure_of_tendsto_snorm_of_strongly_measurable MeasureTheory.tendstoInMeasure_of_tendsto_snorm_of_stronglyMeasurable
/-- This lemma is superceded by `MeasureTheory.tendstoInMeasure_of_tendsto_snorm` where we
allow `p = ∞`. -/
theorem tendstoInMeasure_of_tendsto_snorm_of_ne_top (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf : ∀ n, AEStronglyMeasurable (f n) μ) (hg : AEStronglyMeasurable g μ) {l : Filter ι}
(hfg : Tendsto (fun n => snorm (f n - g) p μ) l (𝓝 0)) : TendstoInMeasure μ f l g := by
refine TendstoInMeasure.congr (fun i => (hf i).ae_eq_mk.symm) hg.ae_eq_mk.symm ?_
refine tendstoInMeasure_of_tendsto_snorm_of_stronglyMeasurable
hp_ne_zero hp_ne_top (fun i => (hf i).stronglyMeasurable_mk) hg.stronglyMeasurable_mk ?_
have : (fun n => snorm ((hf n).mk (f n) - hg.mk g) p μ) = fun n => snorm (f n - g) p μ := by
ext1 n; refine snorm_congr_ae (EventuallyEq.sub (hf n).ae_eq_mk.symm hg.ae_eq_mk.symm)
rw [this]
exact hfg
#align measure_theory.tendsto_in_measure_of_tendsto_snorm_of_ne_top MeasureTheory.tendstoInMeasure_of_tendsto_snorm_of_ne_top
/-- See also `MeasureTheory.tendstoInMeasure_of_tendsto_snorm` which work for general
Lp-convergence for all `p ≠ 0`. -/
theorem tendstoInMeasure_of_tendsto_snorm_top {E} [NormedAddCommGroup E] {f : ι → α → E} {g : α → E}
{l : Filter ι} (hfg : Tendsto (fun n => snorm (f n - g) ∞ μ) l (𝓝 0)) :
TendstoInMeasure μ f l g := by
intro δ hδ
simp only [snorm_exponent_top, snormEssSup] at hfg
rw [ENNReal.tendsto_nhds_zero] at hfg ⊢
intro ε hε
specialize hfg (ENNReal.ofReal δ / 2)
(ENNReal.div_pos_iff.2 ⟨(ENNReal.ofReal_pos.2 hδ).ne.symm, ENNReal.two_ne_top⟩)
refine hfg.mono fun n hn => ?_
simp only [true_and_iff, gt_iff_lt, ge_iff_le, zero_tsub, zero_le, zero_add, Set.mem_Icc,
Pi.sub_apply] at *
have : essSup (fun x : α => (‖f n x - g x‖₊ : ℝ≥0∞)) μ < ENNReal.ofReal δ :=
lt_of_le_of_lt hn
(ENNReal.half_lt_self (ENNReal.ofReal_pos.2 hδ).ne.symm ENNReal.ofReal_lt_top.ne)
refine ((le_of_eq ?_).trans (ae_lt_of_essSup_lt this).le).trans hε.le
congr with x
simp only [ENNReal.ofReal_le_iff_le_toReal ENNReal.coe_lt_top.ne, ENNReal.coe_toReal, not_lt,
coe_nnnorm, Set.mem_setOf_eq, Set.mem_compl_iff]
rw [← dist_eq_norm (f n x) (g x)]
#align measure_theory.tendsto_in_measure_of_tendsto_snorm_top MeasureTheory.tendstoInMeasure_of_tendsto_snorm_top
/-- Convergence in Lp implies convergence in measure. -/
| Mathlib/MeasureTheory/Function/ConvergenceInMeasure.lean | 337 | 343 | theorem tendstoInMeasure_of_tendsto_snorm {l : Filter ι} (hp_ne_zero : p ≠ 0)
(hf : ∀ n, AEStronglyMeasurable (f n) μ) (hg : AEStronglyMeasurable g μ)
(hfg : Tendsto (fun n => snorm (f n - g) p μ) l (𝓝 0)) : TendstoInMeasure μ f l g := by |
by_cases hp_ne_top : p = ∞
· subst hp_ne_top
exact tendstoInMeasure_of_tendsto_snorm_top hfg
· exact tendstoInMeasure_of_tendsto_snorm_of_ne_top hp_ne_zero hp_ne_top hf hg hfg
|
/-
Copyright (c) 2021 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.Spectrum
import Mathlib.FieldTheory.IsAlgClosed.Basic
#align_import field_theory.is_alg_closed.spectrum from "leanprover-community/mathlib"@"58a272265b5e05f258161260dd2c5d247213cbd3"
/-!
# Spectrum mapping theorem
This file develops proves the spectral mapping theorem for polynomials over algebraically closed
fields. In particular, if `a` is an element of a `𝕜`-algebra `A` where `𝕜` is a field, and
`p : 𝕜[X]` is a polynomial, then the spectrum of `Polynomial.aeval a p` contains the image of the
spectrum of `a` under `(fun k ↦ Polynomial.eval k p)`. When `𝕜` is algebraically closed,
these are in fact equal (assuming either that the spectrum of `a` is nonempty or the polynomial
has positive degree), which is the **spectral mapping theorem**.
In addition, this file contains the fact that every element of a finite dimensional nontrivial
algebra over an algebraically closed field has nonempty spectrum. In particular, this is used in
`Module.End.exists_eigenvalue` to show that every linear map from a vector space to itself has an
eigenvalue.
## Main statements
* `spectrum.subset_polynomial_aeval`, `spectrum.map_polynomial_aeval_of_degree_pos`,
`spectrum.map_polynomial_aeval_of_nonempty`: variations on the **spectral mapping theorem**.
* `spectrum.nonempty_of_isAlgClosed_of_finiteDimensional`: the spectrum is nonempty for any
element of a nontrivial finite dimensional algebra over an algebraically closed field.
## Notations
* `σ a` : `spectrum R a` of `a : A`
-/
namespace spectrum
open Set Polynomial
open scoped Pointwise Polynomial
universe u v
section ScalarRing
variable {R : Type u} {A : Type v}
variable [CommRing R] [Ring A] [Algebra R A]
local notation "σ" => spectrum R
local notation "↑ₐ" => algebraMap R A
-- Porting note: removed an unneeded assumption `p ≠ 0`
theorem exists_mem_of_not_isUnit_aeval_prod [IsDomain R] {p : R[X]} {a : A}
(h : ¬IsUnit (aeval a (Multiset.map (fun x : R => X - C x) p.roots).prod)) :
∃ k : R, k ∈ σ a ∧ eval k p = 0 := by
rw [← Multiset.prod_toList, AlgHom.map_list_prod] at h
replace h := mt List.prod_isUnit h
simp only [not_forall, exists_prop, aeval_C, Multiset.mem_toList, List.mem_map, aeval_X,
exists_exists_and_eq_and, Multiset.mem_map, AlgHom.map_sub] at h
rcases h with ⟨r, r_mem, r_nu⟩
exact ⟨r, by rwa [mem_iff, ← IsUnit.sub_iff], (mem_roots'.1 r_mem).2⟩
#align spectrum.exists_mem_of_not_is_unit_aeval_prod spectrum.exists_mem_of_not_isUnit_aeval_prodₓ
end ScalarRing
section ScalarField
variable {𝕜 : Type u} {A : Type v}
variable [Field 𝕜] [Ring A] [Algebra 𝕜 A]
local notation "σ" => spectrum 𝕜
local notation "↑ₐ" => algebraMap 𝕜 A
open Polynomial
/-- Half of the spectral mapping theorem for polynomials. We prove it separately
because it holds over any field, whereas `spectrum.map_polynomial_aeval_of_degree_pos` and
`spectrum.map_polynomial_aeval_of_nonempty` need the field to be algebraically closed. -/
theorem subset_polynomial_aeval (a : A) (p : 𝕜[X]) : (eval · p) '' σ a ⊆ σ (aeval a p) := by
rintro _ ⟨k, hk, rfl⟩
let q := C (eval k p) - p
have hroot : IsRoot q k := by simp only [q, eval_C, eval_sub, sub_self, IsRoot.def]
rw [← mul_div_eq_iff_isRoot, ← neg_mul_neg, neg_sub] at hroot
have aeval_q_eq : ↑ₐ (eval k p) - aeval a p = aeval a q := by
simp only [q, aeval_C, AlgHom.map_sub, sub_left_inj]
rw [mem_iff, aeval_q_eq, ← hroot, aeval_mul]
have hcomm := (Commute.all (C k - X) (-(q / (X - C k)))).map (aeval a : 𝕜[X] →ₐ[𝕜] A)
apply mt fun h => (hcomm.isUnit_mul_iff.mp h).1
simpa only [aeval_X, aeval_C, AlgHom.map_sub] using hk
#align spectrum.subset_polynomial_aeval spectrum.subset_polynomial_aeval
/-- The *spectral mapping theorem* for polynomials. Note: the assumption `degree p > 0`
is necessary in case `σ a = ∅`, for then the left-hand side is `∅` and the right-hand side,
assuming `[Nontrivial A]`, is `{k}` where `p = Polynomial.C k`. -/
theorem map_polynomial_aeval_of_degree_pos [IsAlgClosed 𝕜] (a : A) (p : 𝕜[X])
(hdeg : 0 < degree p) : σ (aeval a p) = (eval · p) '' σ a := by
-- handle the easy direction via `spectrum.subset_polynomial_aeval`
refine Set.eq_of_subset_of_subset (fun k hk => ?_) (subset_polynomial_aeval a p)
-- write `C k - p` product of linear factors and a constant; show `C k - p ≠ 0`.
have hprod := eq_prod_roots_of_splits_id (IsAlgClosed.splits (C k - p))
have h_ne : C k - p ≠ 0 := ne_zero_of_degree_gt <| by
rwa [degree_sub_eq_right_of_degree_lt (lt_of_le_of_lt degree_C_le hdeg)]
have lead_ne := leadingCoeff_ne_zero.mpr h_ne
have lead_unit := (Units.map ↑ₐ.toMonoidHom (Units.mk0 _ lead_ne)).isUnit
/- leading coefficient is a unit so product of linear factors is not a unit;
apply `exists_mem_of_not_is_unit_aeval_prod`. -/
have p_a_eq : aeval a (C k - p) = ↑ₐ k - aeval a p := by
simp only [aeval_C, AlgHom.map_sub, sub_left_inj]
rw [mem_iff, ← p_a_eq, hprod, aeval_mul,
((Commute.all _ _).map (aeval a : 𝕜[X] →ₐ[𝕜] A)).isUnit_mul_iff, aeval_C] at hk
replace hk := exists_mem_of_not_isUnit_aeval_prod (not_and.mp hk lead_unit)
rcases hk with ⟨r, r_mem, r_ev⟩
exact ⟨r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)⟩
#align spectrum.map_polynomial_aeval_of_degree_pos spectrum.map_polynomial_aeval_of_degree_pos
/-- In this version of the spectral mapping theorem, we assume the spectrum
is nonempty instead of assuming the degree of the polynomial is positive. -/
theorem map_polynomial_aeval_of_nonempty [IsAlgClosed 𝕜] (a : A) (p : 𝕜[X])
(hnon : (σ a).Nonempty) : σ (aeval a p) = (fun k => eval k p) '' σ a := by
nontriviality A
refine Or.elim (le_or_gt (degree p) 0) (fun h => ?_) (map_polynomial_aeval_of_degree_pos a p)
rw [eq_C_of_degree_le_zero h]
simp only [Set.image_congr, eval_C, aeval_C, scalar_eq, Set.Nonempty.image_const hnon]
#align spectrum.map_polynomial_aeval_of_nonempty spectrum.map_polynomial_aeval_of_nonempty
/-- A specialization of `spectrum.subset_polynomial_aeval` to monic monomials for convenience. -/
theorem pow_image_subset (a : A) (n : ℕ) : (fun x => x ^ n) '' σ a ⊆ σ (a ^ n) := by
simpa only [eval_pow, eval_X, aeval_X_pow] using subset_polynomial_aeval a (X ^ n : 𝕜[X])
#align spectrum.pow_image_subset spectrum.pow_image_subset
/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for
convenience. -/
theorem map_pow_of_pos [IsAlgClosed 𝕜] (a : A) {n : ℕ} (hn : 0 < n) :
σ (a ^ n) = (· ^ n) '' σ a := by
simpa only [aeval_X_pow, eval_pow, eval_X]
using map_polynomial_aeval_of_degree_pos a (X ^ n : 𝕜[X]) (by rwa [degree_X_pow, Nat.cast_pos])
#align spectrum.map_pow_of_pos spectrum.map_pow_of_pos
/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for
convenience. -/
theorem map_pow_of_nonempty [IsAlgClosed 𝕜] {a : A} (ha : (σ a).Nonempty) (n : ℕ) :
σ (a ^ n) = (· ^ n) '' σ a := by
simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval_of_nonempty a (X ^ n) ha
#align spectrum.map_pow_of_nonempty spectrum.map_pow_of_nonempty
variable (𝕜)
-- We will use this both to show eigenvalues exist, and to prove Schur's lemma.
/-- Every element `a` in a nontrivial finite-dimensional algebra `A`
over an algebraically closed field `𝕜` has non-empty spectrum. -/
| Mathlib/FieldTheory/IsAlgClosed/Spectrum.lean | 153 | 159 | theorem nonempty_of_isAlgClosed_of_finiteDimensional [IsAlgClosed 𝕜] [Nontrivial A]
[I : FiniteDimensional 𝕜 A] (a : A) : (σ a).Nonempty := by |
obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := isIntegral_of_noetherian (IsNoetherian.iff_fg.2 I) a
have nu : ¬IsUnit (aeval a p) := by rw [← aeval_def] at h_eval_p; rw [h_eval_p]; simp
rw [eq_prod_roots_of_monic_of_splits_id h_mon (IsAlgClosed.splits p)] at nu
obtain ⟨k, hk, _⟩ := exists_mem_of_not_isUnit_aeval_prod nu
exact ⟨k, hk⟩
|
/-
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, Matthew Robert Ballard
-/
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Digits
import Mathlib.Data.Nat.MaxPowDiv
import Mathlib.Data.Nat.Multiplicity
import Mathlib.Tactic.IntervalCases
#align_import number_theory.padics.padic_val from "leanprover-community/mathlib"@"60fa54e778c9e85d930efae172435f42fb0d71f7"
/-!
# `p`-adic Valuation
This file defines the `p`-adic valuation on `ℕ`, `ℤ`, and `ℚ`.
The `p`-adic valuation on `ℚ` is the difference of the multiplicities of `p` in the numerator and
denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate
assumptions on `p`. The `p`-adic valuations on `ℕ` and `ℤ` agree with that on `ℚ`.
The valuation induces a norm on `ℚ`. This norm is defined in padicNorm.lean.
## Notations
This file uses the local notation `/.` for `Rat.mk`.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[Fact p.Prime]` as a type class argument.
## Calculations with `p`-adic valuations
* `padicValNat_factorial`: Legendre's Theorem. The `p`-adic valuation of `n!` is the sum of the
quotients `n / p ^ i`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound
greater than `log p n`. See `Nat.Prime.multiplicity_factorial` for the same result but stated in the
language of prime multiplicity.
* `sub_one_mul_padicValNat_factorial`: Legendre's Theorem. Taking (`p - 1`) times
the `p`-adic valuation of `n!` equals `n` minus the sum of base `p` digits of `n`.
* `padicValNat_choose`: Kummer's Theorem. The `p`-adic valuation of `n.choose k` is the number
of carries when `k` and `n - k` are added in base `p`. This sum is expressed over the finset
`Ico 1 b` where `b` is any bound greater than `log p n`. See `Nat.Prime.multiplicity_choose` for the
same result but stated in the language of prime multiplicity.
* `sub_one_mul_padicValNat_choose_eq_sub_sum_digits`: Kummer's Theorem. Taking (`p - 1`) times the
`p`-adic valuation of the binomial `n` over `k` equals the sum of the digits of `k` plus the sum of
the digits of `n - k` minus the sum of digits of `n`, all base `p`.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation
-/
universe u
open Nat
open Rat
open multiplicity
/-- For `p ≠ 1`, the `p`-adic valuation of a natural `n ≠ 0` is the largest natural number `k` such
that `p^k` divides `n`. If `n = 0` or `p = 1`, then `padicValNat p q` defaults to `0`. -/
def padicValNat (p : ℕ) (n : ℕ) : ℕ :=
if h : p ≠ 1 ∧ 0 < n then (multiplicity p n).get (multiplicity.finite_nat_iff.2 h) else 0
#align padic_val_nat padicValNat
namespace padicValNat
open multiplicity
variable {p : ℕ}
/-- `padicValNat p 0` is `0` for any `p`. -/
@[simp]
protected theorem zero : padicValNat p 0 = 0 := by simp [padicValNat]
#align padic_val_nat.zero padicValNat.zero
/-- `padicValNat p 1` is `0` for any `p`. -/
@[simp]
protected theorem one : padicValNat p 1 = 0 := by
unfold padicValNat
split_ifs
· simp
· rfl
#align padic_val_nat.one padicValNat.one
/-- If `p ≠ 0` and `p ≠ 1`, then `padicValNat p p` is `1`. -/
@[simp]
theorem self (hp : 1 < p) : padicValNat p p = 1 := by
have neq_one : ¬p = 1 ↔ True := iff_of_true hp.ne' trivial
have eq_zero_false : p = 0 ↔ False := iff_false_intro (zero_lt_one.trans hp).ne'
simp [padicValNat, neq_one, eq_zero_false]
#align padic_val_nat.self padicValNat.self
@[simp]
theorem eq_zero_iff {n : ℕ} : padicValNat p n = 0 ↔ p = 1 ∨ n = 0 ∨ ¬p ∣ n := by
simp only [padicValNat, dite_eq_right_iff, PartENat.get_eq_iff_eq_coe, Nat.cast_zero,
multiplicity_eq_zero, and_imp, pos_iff_ne_zero, Ne, ← or_iff_not_imp_left]
#align padic_val_nat.eq_zero_iff padicValNat.eq_zero_iff
theorem eq_zero_of_not_dvd {n : ℕ} (h : ¬p ∣ n) : padicValNat p n = 0 :=
eq_zero_iff.2 <| Or.inr <| Or.inr h
#align padic_val_nat.eq_zero_of_not_dvd padicValNat.eq_zero_of_not_dvd
open Nat.maxPowDiv
theorem maxPowDiv_eq_multiplicity {p n : ℕ} (hp : 1 < p) (hn : 0 < n) :
p.maxPowDiv n = multiplicity p n := by
apply multiplicity.unique <| pow_dvd p n
intro h
apply Nat.not_lt.mpr <| le_of_dvd hp hn h
simp
theorem maxPowDiv_eq_multiplicity_get {p n : ℕ} (hp : 1 < p) (hn : 0 < n) (h : Finite p n) :
p.maxPowDiv n = (multiplicity p n).get h := by
rw [PartENat.get_eq_iff_eq_coe.mpr]
apply maxPowDiv_eq_multiplicity hp hn|>.symm
/-- Allows for more efficient code for `padicValNat` -/
@[csimp]
theorem padicValNat_eq_maxPowDiv : @padicValNat = @maxPowDiv := by
ext p n
by_cases h : 1 < p ∧ 0 < n
· dsimp [padicValNat]
rw [dif_pos ⟨Nat.ne_of_gt h.1,h.2⟩, maxPowDiv_eq_multiplicity_get h.1 h.2]
· simp only [not_and_or,not_gt_eq,Nat.le_zero] at h
apply h.elim
· intro h
interval_cases p
· simp [Classical.em]
· dsimp [padicValNat, maxPowDiv]
rw [go, if_neg, dif_neg] <;> simp
· intro h
simp [h]
end padicValNat
/-- For `p ≠ 1`, the `p`-adic valuation of an integer `z ≠ 0` is the largest natural number `k` such
that `p^k` divides `z`. If `x = 0` or `p = 1`, then `padicValInt p q` defaults to `0`. -/
def padicValInt (p : ℕ) (z : ℤ) : ℕ :=
padicValNat p z.natAbs
#align padic_val_int padicValInt
namespace padicValInt
open multiplicity
variable {p : ℕ}
theorem of_ne_one_ne_zero {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) :
padicValInt p z =
(multiplicity (p : ℤ) z).get
(by
apply multiplicity.finite_int_iff.2
simp [hp, hz]) := by
rw [padicValInt, padicValNat, dif_pos (And.intro hp (Int.natAbs_pos.mpr hz))]
simp only [multiplicity.Int.natAbs p z]
#align padic_val_int.of_ne_one_ne_zero padicValInt.of_ne_one_ne_zero
/-- `padicValInt p 0` is `0` for any `p`. -/
@[simp]
protected theorem zero : padicValInt p 0 = 0 := by simp [padicValInt]
#align padic_val_int.zero padicValInt.zero
/-- `padicValInt p 1` is `0` for any `p`. -/
@[simp]
protected theorem one : padicValInt p 1 = 0 := by simp [padicValInt]
#align padic_val_int.one padicValInt.one
/-- The `p`-adic value of a natural is its `p`-adic value as an integer. -/
@[simp]
theorem of_nat {n : ℕ} : padicValInt p n = padicValNat p n := by simp [padicValInt]
#align padic_val_int.of_nat padicValInt.of_nat
/-- If `p ≠ 0` and `p ≠ 1`, then `padicValInt p p` is `1`. -/
theorem self (hp : 1 < p) : padicValInt p p = 1 := by simp [padicValNat.self hp]
#align padic_val_int.self padicValInt.self
theorem eq_zero_of_not_dvd {z : ℤ} (h : ¬(p : ℤ) ∣ z) : padicValInt p z = 0 := by
rw [padicValInt, padicValNat]
split_ifs <;> simp [multiplicity.Int.natAbs, multiplicity_eq_zero.2 h]
#align padic_val_int.eq_zero_of_not_dvd padicValInt.eq_zero_of_not_dvd
end padicValInt
/-- `padicValRat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the
valuation of `q.den`. If `q = 0` or `p = 1`, then `padicValRat p q` defaults to `0`. -/
def padicValRat (p : ℕ) (q : ℚ) : ℤ :=
padicValInt p q.num - padicValNat p q.den
#align padic_val_rat padicValRat
lemma padicValRat_def (p : ℕ) (q : ℚ) :
padicValRat p q = padicValInt p q.num - padicValNat p q.den :=
rfl
namespace padicValRat
open multiplicity
variable {p : ℕ}
/-- `padicValRat p q` is symmetric in `q`. -/
@[simp]
protected theorem neg (q : ℚ) : padicValRat p (-q) = padicValRat p q := by
simp [padicValRat, padicValInt]
#align padic_val_rat.neg padicValRat.neg
/-- `padicValRat p 0` is `0` for any `p`. -/
@[simp]
protected theorem zero : padicValRat p 0 = 0 := by simp [padicValRat]
#align padic_val_rat.zero padicValRat.zero
/-- `padicValRat p 1` is `0` for any `p`. -/
@[simp]
protected theorem one : padicValRat p 1 = 0 := by simp [padicValRat]
#align padic_val_rat.one padicValRat.one
/-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic_value as a rational. -/
@[simp]
theorem of_int {z : ℤ} : padicValRat p z = padicValInt p z := by simp [padicValRat]
#align padic_val_rat.of_int padicValRat.of_int
/-- The `p`-adic value of an integer `z ≠ 0` is the multiplicity of `p` in `z`. -/
theorem of_int_multiplicity {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) :
padicValRat p (z : ℚ) = (multiplicity (p : ℤ) z).get (finite_int_iff.2 ⟨hp, hz⟩) := by
rw [of_int, padicValInt.of_ne_one_ne_zero hp hz]
#align padic_val_rat.of_int_multiplicity padicValRat.of_int_multiplicity
theorem multiplicity_sub_multiplicity {q : ℚ} (hp : p ≠ 1) (hq : q ≠ 0) :
padicValRat p q =
(multiplicity (p : ℤ) q.num).get (finite_int_iff.2 ⟨hp, Rat.num_ne_zero.2 hq⟩) -
(multiplicity p q.den).get
(by
rw [← finite_iff_dom, finite_nat_iff]
exact ⟨hp, q.pos⟩) := by
rw [padicValRat, padicValInt.of_ne_one_ne_zero hp, padicValNat, dif_pos]
· exact ⟨hp, q.pos⟩
· exact Rat.num_ne_zero.2 hq
#align padic_val_rat.multiplicity_sub_multiplicity padicValRat.multiplicity_sub_multiplicity
/-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic value as a rational. -/
@[simp]
theorem of_nat {n : ℕ} : padicValRat p n = padicValNat p n := by simp [padicValRat]
#align padic_val_rat.of_nat padicValRat.of_nat
/-- If `p ≠ 0` and `p ≠ 1`, then `padicValRat p p` is `1`. -/
theorem self (hp : 1 < p) : padicValRat p p = 1 := by simp [hp]
#align padic_val_rat.self padicValRat.self
end padicValRat
section padicValNat
variable {p : ℕ}
theorem zero_le_padicValRat_of_nat (n : ℕ) : 0 ≤ padicValRat p n := by simp
#align zero_le_padic_val_rat_of_nat zero_le_padicValRat_of_nat
/-- `padicValRat` coincides with `padicValNat`. -/
@[norm_cast]
theorem padicValRat_of_nat (n : ℕ) : ↑(padicValNat p n) = padicValRat p n := by simp
#align padic_val_rat_of_nat padicValRat_of_nat
/-- A simplification of `padicValNat` when one input is prime, by analogy with
`padicValRat_def`. -/
theorem padicValNat_def [hp : Fact p.Prime] {n : ℕ} (hn : 0 < n) :
padicValNat p n = (multiplicity p n).get (multiplicity.finite_nat_iff.2 ⟨hp.out.ne_one, hn⟩) :=
dif_pos ⟨hp.out.ne_one, hn⟩
#align padic_val_nat_def padicValNat_def
theorem padicValNat_def' {n : ℕ} (hp : p ≠ 1) (hn : 0 < n) :
↑(padicValNat p n) = multiplicity p n := by simp [padicValNat, hp, hn]
#align padic_val_nat_def' padicValNat_def'
@[simp]
theorem padicValNat_self [Fact p.Prime] : padicValNat p p = 1 := by
rw [padicValNat_def (@Fact.out p.Prime).pos]
simp
#align padic_val_nat_self padicValNat_self
theorem one_le_padicValNat_of_dvd {n : ℕ} [hp : Fact p.Prime] (hn : 0 < n) (div : p ∣ n) :
1 ≤ padicValNat p n := by
rwa [← PartENat.coe_le_coe, padicValNat_def' hp.out.ne_one hn, ← pow_dvd_iff_le_multiplicity,
pow_one]
#align one_le_padic_val_nat_of_dvd one_le_padicValNat_of_dvd
theorem dvd_iff_padicValNat_ne_zero {p n : ℕ} [Fact p.Prime] (hn0 : n ≠ 0) :
p ∣ n ↔ padicValNat p n ≠ 0 :=
⟨fun h => one_le_iff_ne_zero.mp (one_le_padicValNat_of_dvd hn0.bot_lt h), fun h =>
Classical.not_not.1 (mt padicValNat.eq_zero_of_not_dvd h)⟩
#align dvd_iff_padic_val_nat_ne_zero dvd_iff_padicValNat_ne_zero
open List
theorem le_multiplicity_iff_replicate_subperm_factors {a b : ℕ} {n : ℕ} (ha : a.Prime)
(hb : b ≠ 0) :
↑n ≤ multiplicity a b ↔ replicate n a <+~ b.factors :=
(replicate_subperm_factors_iff ha hb).trans multiplicity.pow_dvd_iff_le_multiplicity |>.symm
theorem le_padicValNat_iff_replicate_subperm_factors {a b : ℕ} {n : ℕ} (ha : a.Prime)
(hb : b ≠ 0) :
n ≤ padicValNat a b ↔ replicate n a <+~ b.factors := by
rw [← le_multiplicity_iff_replicate_subperm_factors ha hb,
← padicValNat_def' ha.ne_one (Nat.pos_of_ne_zero hb), Nat.cast_le]
end padicValNat
namespace padicValRat
open multiplicity
variable {p : ℕ} [hp : Fact p.Prime]
/-- The multiplicity of `p : ℕ` in `a : ℤ` is finite exactly when `a ≠ 0`. -/
theorem finite_int_prime_iff {a : ℤ} : Finite (p : ℤ) a ↔ a ≠ 0 := by
simp [finite_int_iff, hp.1.ne_one]
#align padic_val_rat.finite_int_prime_iff padicValRat.finite_int_prime_iff
/-- A rewrite lemma for `padicValRat p q` when `q` is expressed in terms of `Rat.mk`. -/
protected theorem defn (p : ℕ) [hp : Fact p.Prime] {q : ℚ} {n d : ℤ} (hqz : q ≠ 0)
(qdf : q = n /. d) :
padicValRat p q =
(multiplicity (p : ℤ) n).get
(finite_int_iff.2 ⟨hp.1.ne_one, fun hn => by simp_all⟩) -
(multiplicity (p : ℤ) d).get
(finite_int_iff.2 ⟨hp.1.ne_one, fun hd => by simp_all⟩) := by
have hd : d ≠ 0 := Rat.mk_denom_ne_zero_of_ne_zero hqz qdf
let ⟨c, hc1, hc2⟩ := Rat.num_den_mk hd qdf
rw [padicValRat.multiplicity_sub_multiplicity hp.1.ne_one hqz]
simp only [Nat.isUnit_iff, hc1, hc2]
rw [multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1),
multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1)]
rw [Nat.cast_add, Nat.cast_add]
simp_rw [Int.natCast_multiplicity p q.den]
ring
-- Porting note: was
-- simp only [hc1, hc2, multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1),
-- hp.1.ne_one, hqz, pos_iff_ne_zero, Int.natCast_multiplicity p q.den
#align padic_val_rat.defn padicValRat.defn
/-- A rewrite lemma for `padicValRat p (q * r)` with conditions `q ≠ 0`, `r ≠ 0`. -/
protected theorem mul {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :
padicValRat p (q * r) = padicValRat p q + padicValRat p r := by
have : q * r = (q.num * r.num) /. (q.den * r.den) := by
rw [Rat.mul_eq_mkRat, Rat.mkRat_eq_divInt, Nat.cast_mul]
have hq' : q.num /. q.den ≠ 0 := by rwa [Rat.num_divInt_den]
have hr' : r.num /. r.den ≠ 0 := by rwa [Rat.num_divInt_den]
have hp' : Prime (p : ℤ) := Nat.prime_iff_prime_int.1 hp.1
rw [padicValRat.defn p (mul_ne_zero hq hr) this]
conv_rhs =>
rw [← q.num_divInt_den, padicValRat.defn p hq', ← r.num_divInt_den, padicValRat.defn p hr']
rw [multiplicity.mul' hp', multiplicity.mul' hp', Nat.cast_add, Nat.cast_add]
ring
-- Porting note: was
-- simp [add_comm, add_left_comm, sub_eq_add_neg]
#align padic_val_rat.mul padicValRat.mul
/-- A rewrite lemma for `padicValRat p (q^k)` with condition `q ≠ 0`. -/
protected theorem pow {q : ℚ} (hq : q ≠ 0) {k : ℕ} :
padicValRat p (q ^ k) = k * padicValRat p q := by
induction k <;>
simp [*, padicValRat.mul hq (pow_ne_zero _ hq), _root_.pow_succ', add_mul, add_comm]
#align padic_val_rat.pow padicValRat.pow
/-- A rewrite lemma for `padicValRat p (q⁻¹)` with condition `q ≠ 0`. -/
protected theorem inv (q : ℚ) : padicValRat p q⁻¹ = -padicValRat p q := by
by_cases hq : q = 0
· simp [hq]
· rw [eq_neg_iff_add_eq_zero, ← padicValRat.mul (inv_ne_zero hq) hq, inv_mul_cancel hq,
padicValRat.one]
#align padic_val_rat.inv padicValRat.inv
/-- A rewrite lemma for `padicValRat p (q / r)` with conditions `q ≠ 0`, `r ≠ 0`. -/
protected theorem div {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :
padicValRat p (q / r) = padicValRat p q - padicValRat p r := by
rw [div_eq_mul_inv, padicValRat.mul hq (inv_ne_zero hr), padicValRat.inv r, sub_eq_add_neg]
#align padic_val_rat.div padicValRat.div
/-- A condition for `padicValRat p (n₁ / d₁) ≤ padicValRat p (n₂ / d₂)`, in terms of
divisibility by `p^n`. -/
theorem padicValRat_le_padicValRat_iff {n₁ n₂ d₁ d₂ : ℤ} (hn₁ : n₁ ≠ 0) (hn₂ : n₂ ≠ 0)
(hd₁ : d₁ ≠ 0) (hd₂ : d₂ ≠ 0) :
padicValRat p (n₁ /. d₁) ≤ padicValRat p (n₂ /. d₂) ↔
∀ n : ℕ, (p : ℤ) ^ n ∣ n₁ * d₂ → (p : ℤ) ^ n ∣ n₂ * d₁ := by
have hf1 : Finite (p : ℤ) (n₁ * d₂) := finite_int_prime_iff.2 (mul_ne_zero hn₁ hd₂)
have hf2 : Finite (p : ℤ) (n₂ * d₁) := finite_int_prime_iff.2 (mul_ne_zero hn₂ hd₁)
conv =>
lhs
rw [padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn₁ hd₁) rfl,
padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn₂ hd₂) rfl, sub_le_iff_le_add', ←
add_sub_assoc, _root_.le_sub_iff_add_le]
norm_cast
rw [← multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1) hf1, add_comm, ←
multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1) hf2, PartENat.get_le_get,
multiplicity_le_multiplicity_iff]
#align padic_val_rat.padic_val_rat_le_padic_val_rat_iff padicValRat.padicValRat_le_padicValRat_iff
/-- Sufficient conditions to show that the `p`-adic valuation of `q` is less than or equal to the
`p`-adic valuation of `q + r`. -/
theorem le_padicValRat_add_of_le {q r : ℚ} (hqr : q + r ≠ 0)
(h : padicValRat p q ≤ padicValRat p r) : padicValRat p q ≤ padicValRat p (q + r) :=
if hq : q = 0 then by simpa [hq] using h
else
if hr : r = 0 then by simp [hr]
else by
have hqn : q.num ≠ 0 := Rat.num_ne_zero.2 hq
have hqd : (q.den : ℤ) ≠ 0 := mod_cast Rat.den_nz _
have hrn : r.num ≠ 0 := Rat.num_ne_zero.2 hr
have hrd : (r.den : ℤ) ≠ 0 := mod_cast Rat.den_nz _
have hqreq : q + r = (q.num * r.den + q.den * r.num) /. (q.den * r.den) := Rat.add_num_den _ _
have hqrd : q.num * r.den + q.den * r.num ≠ 0 := Rat.mk_num_ne_zero_of_ne_zero hqr hqreq
conv_lhs => rw [← q.num_divInt_den]
rw [hqreq, padicValRat_le_padicValRat_iff hqn hqrd hqd (mul_ne_zero hqd hrd), ←
multiplicity_le_multiplicity_iff, mul_left_comm,
multiplicity.mul (Nat.prime_iff_prime_int.1 hp.1), add_mul]
rw [← q.num_divInt_den, ← r.num_divInt_den, padicValRat_le_padicValRat_iff hqn hrn hqd hrd, ←
multiplicity_le_multiplicity_iff] at h
calc
_ ≤
min (multiplicity (↑p) (q.num * r.den * q.den))
(multiplicity (↑p) (↑q.den * r.num * ↑q.den)) :=
le_min
(by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (Nat.prime_iff_prime_int.1 hp.1), add_comm])
(by
rw [mul_assoc,
@multiplicity.mul _ _ _ _ (q.den : ℤ) (_ * _)
(Nat.prime_iff_prime_int.1 hp.1)]
exact add_le_add_left h _)
_ ≤ _ := min_le_multiplicity_add
#align padic_val_rat.le_padic_val_rat_add_of_le padicValRat.le_padicValRat_add_of_le
/-- The minimum of the valuations of `q` and `r` is at most the valuation of `q + r`. -/
theorem min_le_padicValRat_add {q r : ℚ} (hqr : q + r ≠ 0) :
min (padicValRat p q) (padicValRat p r) ≤ padicValRat p (q + r) :=
(le_total (padicValRat p q) (padicValRat p r)).elim
(fun h => by rw [min_eq_left h]; exact le_padicValRat_add_of_le hqr h)
(fun h => by rw [min_eq_right h, add_comm]; exact le_padicValRat_add_of_le (by rwa [add_comm]) h)
#align padic_val_rat.min_le_padic_val_rat_add padicValRat.min_le_padicValRat_add
/-- Ultrametric property of a p-adic valuation. -/
lemma add_eq_min {q r : ℚ} (hqr : q + r ≠ 0) (hq : q ≠ 0) (hr : r ≠ 0)
(hval : padicValRat p q ≠ padicValRat p r) :
padicValRat p (q + r) = min (padicValRat p q) (padicValRat p r) := by
have h1 := min_le_padicValRat_add (p := p) hqr
have h2 := min_le_padicValRat_add (p := p) (ne_of_eq_of_ne (add_neg_cancel_right q r) hq)
have h3 := min_le_padicValRat_add (p := p) (ne_of_eq_of_ne (add_neg_cancel_right r q) hr)
rw [add_neg_cancel_right, padicValRat.neg] at h2 h3
rw [add_comm] at h3
refine le_antisymm (le_min ?_ ?_) h1
· contrapose! h2
rw [min_eq_right h2.le] at h3
exact lt_min h2 (lt_of_le_of_ne h3 hval)
· contrapose! h3
rw [min_eq_right h3.le] at h2
exact lt_min h3 (lt_of_le_of_ne h2 hval.symm)
lemma add_eq_of_lt {q r : ℚ} (hqr : q + r ≠ 0)
(hq : q ≠ 0) (hr : r ≠ 0) (hval : padicValRat p q < padicValRat p r) :
padicValRat p (q + r) = padicValRat p q := by
rw [add_eq_min hqr hq hr (ne_of_lt hval), min_eq_left (le_of_lt hval)]
lemma lt_add_of_lt {q r₁ r₂ : ℚ} (hqr : r₁ + r₂ ≠ 0)
(hval₁ : padicValRat p q < padicValRat p r₁) (hval₂ : padicValRat p q < padicValRat p r₂) :
padicValRat p q < padicValRat p (r₁ + r₂) :=
lt_of_lt_of_le (lt_min hval₁ hval₂) (padicValRat.min_le_padicValRat_add hqr)
@[simp]
lemma self_pow_inv (r : ℕ) : padicValRat p ((p : ℚ) ^ r)⁻¹ = -r := by
rw [padicValRat.inv, neg_inj, padicValRat.pow (Nat.cast_ne_zero.mpr hp.elim.ne_zero),
padicValRat.self hp.elim.one_lt, mul_one]
/-- A finite sum of rationals with positive `p`-adic valuation has positive `p`-adic valuation
(if the sum is non-zero). -/
theorem sum_pos_of_pos {n : ℕ} {F : ℕ → ℚ} (hF : ∀ i, i < n → 0 < padicValRat p (F i))
(hn0 : ∑ i ∈ Finset.range n, F i ≠ 0) : 0 < padicValRat p (∑ i ∈ Finset.range n, F i) := by
induction' n with d hd
· exact False.elim (hn0 rfl)
· rw [Finset.sum_range_succ] at hn0 ⊢
by_cases h : ∑ x ∈ Finset.range d, F x = 0
· rw [h, zero_add]
exact hF d (lt_add_one _)
· refine lt_of_lt_of_le ?_ (min_le_padicValRat_add hn0)
refine lt_min (hd (fun i hi => ?_) h) (hF d (lt_add_one _))
exact hF _ (lt_trans hi (lt_add_one _))
#align padic_val_rat.sum_pos_of_pos padicValRat.sum_pos_of_pos
/-- If the p-adic valuation of a finite set of positive rationals is greater than a given rational
number, then the p-adic valuation of their sum is also greater than the same rational number. -/
theorem lt_sum_of_lt {p j : ℕ} [hp : Fact (Nat.Prime p)] {F : ℕ → ℚ} {S : Finset ℕ}
(hS : S.Nonempty) (hF : ∀ i, i ∈ S → padicValRat p (F j) < padicValRat p (F i))
(hn1 : ∀ i : ℕ, 0 < F i) : padicValRat p (F j) < padicValRat p (∑ i ∈ S, F i) := by
induction' hS using Finset.Nonempty.cons_induction with k s S' Hnot Hne Hind
· rw [Finset.sum_singleton]
exact hF k (by simp)
· rw [Finset.cons_eq_insert, Finset.sum_insert Hnot]
exact padicValRat.lt_add_of_lt
(ne_of_gt (add_pos (hn1 s) (Finset.sum_pos (fun i _ => hn1 i) Hne)))
(hF _ (by simp [Finset.mem_insert, true_or]))
(Hind (fun i hi => hF _ (by rw [Finset.cons_eq_insert,Finset.mem_insert]; exact Or.inr hi)))
end padicValRat
namespace padicValNat
variable {p a b : ℕ} [hp : Fact p.Prime]
/-- A rewrite lemma for `padicValNat p (a * b)` with conditions `a ≠ 0`, `b ≠ 0`. -/
protected theorem mul : a ≠ 0 → b ≠ 0 → padicValNat p (a * b) = padicValNat p a + padicValNat p b :=
mod_cast @padicValRat.mul p _ a b
#align padic_val_nat.mul padicValNat.mul
protected theorem div_of_dvd (h : b ∣ a) :
padicValNat p (a / b) = padicValNat p a - padicValNat p b := by
rcases eq_or_ne a 0 with (rfl | ha)
· simp
obtain ⟨k, rfl⟩ := h
obtain ⟨hb, hk⟩ := mul_ne_zero_iff.mp ha
rw [mul_comm, k.mul_div_cancel hb.bot_lt, padicValNat.mul hk hb, Nat.add_sub_cancel]
#align padic_val_nat.div_of_dvd padicValNat.div_of_dvd
/-- Dividing out by a prime factor reduces the `padicValNat` by `1`. -/
protected theorem div (dvd : p ∣ b) : padicValNat p (b / p) = padicValNat p b - 1 := by
rw [padicValNat.div_of_dvd dvd, padicValNat_self]
#align padic_val_nat.div padicValNat.div
/-- A version of `padicValRat.pow` for `padicValNat`. -/
protected theorem pow (n : ℕ) (ha : a ≠ 0) : padicValNat p (a ^ n) = n * padicValNat p a := by
simpa only [← @Nat.cast_inj ℤ, push_cast] using padicValRat.pow (Nat.cast_ne_zero.mpr ha)
#align padic_val_nat.pow padicValNat.pow
@[simp]
protected theorem prime_pow (n : ℕ) : padicValNat p (p ^ n) = n := by
rw [padicValNat.pow _ (@Fact.out p.Prime).ne_zero, padicValNat_self, mul_one]
#align padic_val_nat.prime_pow padicValNat.prime_pow
protected theorem div_pow (dvd : p ^ a ∣ b) : padicValNat p (b / p ^ a) = padicValNat p b - a := by
rw [padicValNat.div_of_dvd dvd, padicValNat.prime_pow]
#align padic_val_nat.div_pow padicValNat.div_pow
protected theorem div' {m : ℕ} (cpm : Coprime p m) {b : ℕ} (dvd : m ∣ b) :
padicValNat p (b / m) = padicValNat p b := by
rw [padicValNat.div_of_dvd dvd, eq_zero_of_not_dvd (hp.out.coprime_iff_not_dvd.mp cpm),
Nat.sub_zero]
#align padic_val_nat.div' padicValNat.div'
end padicValNat
section padicValNat
variable {p : ℕ}
theorem dvd_of_one_le_padicValNat {n : ℕ} (hp : 1 ≤ padicValNat p n) : p ∣ n := by
by_contra h
rw [padicValNat.eq_zero_of_not_dvd h] at hp
exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp)
#align dvd_of_one_le_padic_val_nat dvd_of_one_le_padicValNat
theorem pow_padicValNat_dvd {n : ℕ} : p ^ padicValNat p n ∣ n := by
rcases n.eq_zero_or_pos with (rfl | hn); · simp
rcases eq_or_ne p 1 with (rfl | hp); · simp
rw [multiplicity.pow_dvd_iff_le_multiplicity, padicValNat_def'] <;> assumption
#align pow_padic_val_nat_dvd pow_padicValNat_dvd
theorem padicValNat_dvd_iff_le [hp : Fact p.Prime] {a n : ℕ} (ha : a ≠ 0) :
p ^ n ∣ a ↔ n ≤ padicValNat p a := by
rw [pow_dvd_iff_le_multiplicity, ← padicValNat_def' hp.out.ne_one ha.bot_lt, PartENat.coe_le_coe]
#align padic_val_nat_dvd_iff_le padicValNat_dvd_iff_le
theorem padicValNat_dvd_iff (n : ℕ) [hp : Fact p.Prime] (a : ℕ) :
p ^ n ∣ a ↔ a = 0 ∨ n ≤ padicValNat p a := by
rcases eq_or_ne a 0 with (rfl | ha)
· exact iff_of_true (dvd_zero _) (Or.inl rfl)
· rw [padicValNat_dvd_iff_le ha, or_iff_right ha]
#align padic_val_nat_dvd_iff padicValNat_dvd_iff
theorem pow_succ_padicValNat_not_dvd {n : ℕ} [hp : Fact p.Prime] (hn : n ≠ 0) :
¬p ^ (padicValNat p n + 1) ∣ n := by
rw [padicValNat_dvd_iff_le hn, not_le]
exact Nat.lt_succ_self _
#align pow_succ_padic_val_nat_not_dvd pow_succ_padicValNat_not_dvd
theorem padicValNat_primes {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime] (neq : p ≠ q) :
padicValNat p q = 0 :=
@padicValNat.eq_zero_of_not_dvd p q <|
(not_congr (Iff.symm (prime_dvd_prime_iff_eq hp.1 hq.1))).mp neq
#align padic_val_nat_primes padicValNat_primes
theorem padicValNat_prime_prime_pow {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime]
(n : ℕ) (neq : p ≠ q) : padicValNat p (q ^ n) = 0 := by
rw [padicValNat.pow _ <| Nat.Prime.ne_zero hq.elim, padicValNat_primes neq, mul_zero]
theorem padicValNat_mul_pow_left {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime]
(n m : ℕ) (neq : p ≠ q) : padicValNat p (p^n * q^m) = n := by
rw [padicValNat.mul (NeZero.ne' (p^n)).symm (NeZero.ne' (q^m)).symm,
padicValNat.prime_pow, padicValNat_prime_prime_pow m neq, add_zero]
theorem padicValNat_mul_pow_right {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime]
(n m : ℕ) (neq : q ≠ p) : padicValNat q (p^n * q^m) = m := by
rw [mul_comm (p^n) (q^m)]
exact padicValNat_mul_pow_left m n neq
/-- The p-adic valuation of `n` is less than or equal to its logarithm w.r.t `p`. -/
lemma padicValNat_le_nat_log (n : ℕ) : padicValNat p n ≤ Nat.log p n := by
rcases n with _ | n
· simp
rcases p with _ | _ | p
· simp
· simp
exact Nat.le_log_of_pow_le p.one_lt_succ_succ (le_of_dvd n.succ_pos pow_padicValNat_dvd)
/-- The p-adic valuation of `n` is equal to the logarithm w.r.t `p` iff
`n` is less than `p` raised to one plus the p-adic valuation of `n`. -/
lemma nat_log_eq_padicValNat_iff {n : ℕ} [hp : Fact (Nat.Prime p)] (hn : 0 < n) :
Nat.log p n = padicValNat p n ↔ n < p ^ (padicValNat p n + 1) := by
rw [Nat.log_eq_iff (Or.inr ⟨(Nat.Prime.one_lt' p).out, by omega⟩), and_iff_right_iff_imp]
exact fun _ => Nat.le_of_dvd hn pow_padicValNat_dvd
lemma Nat.log_ne_padicValNat_succ {n : ℕ} (hn : n ≠ 0) : log 2 n ≠ padicValNat 2 (n + 1) := by
rw [Ne, log_eq_iff (by simp [hn])]
rintro ⟨h1, h2⟩
rw [← lt_add_one_iff, ← mul_one (2 ^ _)] at h1
rw [← add_one_le_iff, Nat.pow_succ] at h2
refine not_dvd_of_between_consec_multiples h1 (lt_of_le_of_ne' h2 ?_) pow_padicValNat_dvd
-- TODO(kmill): Why is this `p := 2` necessary?
exact pow_succ_padicValNat_not_dvd (p := 2) n.succ_ne_zero ∘ dvd_of_eq
lemma Nat.max_log_padicValNat_succ_eq_log_succ (n : ℕ) :
max (log 2 n) (padicValNat 2 (n + 1)) = log 2 (n + 1) := by
apply le_antisymm (max_le (le_log_of_pow_le one_lt_two (pow_log_le_add_one 2 n))
(padicValNat_le_nat_log (n + 1)))
rw [le_max_iff, or_iff_not_imp_left, not_le]
intro h
replace h := le_antisymm (add_one_le_iff.mpr (lt_pow_of_log_lt one_lt_two h))
(pow_log_le_self 2 n.succ_ne_zero)
rw [h, padicValNat.prime_pow, ← h]
theorem range_pow_padicValNat_subset_divisors {n : ℕ} (hn : n ≠ 0) :
(Finset.range (padicValNat p n + 1)).image (p ^ ·) ⊆ n.divisors := by
intro t ht
simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht
obtain ⟨k, hk, rfl⟩ := ht
rw [Nat.mem_divisors]
exact ⟨(pow_dvd_pow p <| by omega).trans pow_padicValNat_dvd, hn⟩
#align range_pow_padic_val_nat_subset_divisors range_pow_padicValNat_subset_divisors
theorem range_pow_padicValNat_subset_divisors' {n : ℕ} [hp : Fact p.Prime] :
((Finset.range (padicValNat p n)).image fun t => p ^ (t + 1)) ⊆ n.divisors.erase 1 := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
intro t ht
simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht
obtain ⟨k, hk, rfl⟩ := ht
rw [Finset.mem_erase, Nat.mem_divisors]
refine ⟨?_, (pow_dvd_pow p <| succ_le_iff.2 hk).trans pow_padicValNat_dvd, hn⟩
exact (Nat.one_lt_pow k.succ_ne_zero hp.out.one_lt).ne'
#align range_pow_padic_val_nat_subset_divisors' range_pow_padicValNat_subset_divisors'
/-- The `p`-adic valuation of `(p * n)!` is `n` more than that of `n!`. -/
theorem padicValNat_factorial_mul (n : ℕ) [hp : Fact p.Prime] :
padicValNat p (p * n) ! = padicValNat p n ! + n := by
refine PartENat.natCast_inj.mp ?_
rw [padicValNat_def' (Nat.Prime.ne_one hp.out) <| factorial_pos (p * n), Nat.cast_add,
padicValNat_def' (Nat.Prime.ne_one hp.out) <| factorial_pos n]
exact Prime.multiplicity_factorial_mul hp.out
/-- The `p`-adic valuation of `m` equals zero if it is between `p * k` and `p * (k + 1)` for
some `k`. -/
theorem padicValNat_eq_zero_of_mem_Ioo {m k : ℕ}
(hm : m ∈ Set.Ioo (p * k) (p * (k + 1))) : padicValNat p m = 0 :=
padicValNat.eq_zero_of_not_dvd <| not_dvd_of_between_consec_multiples hm.1 hm.2
theorem padicValNat_factorial_mul_add {n : ℕ} (m : ℕ) [hp : Fact p.Prime] (h : n < p) :
padicValNat p (p * m + n) ! = padicValNat p (p * m) ! := by
induction' n with n hn
· rw [add_zero]
· rw [add_succ, factorial_succ,
padicValNat.mul (succ_ne_zero (p * m + n)) <| factorial_ne_zero (p * m + _),
hn <| lt_of_succ_lt h, ← add_succ,
padicValNat_eq_zero_of_mem_Ioo ⟨(Nat.lt_add_of_pos_right <| succ_pos n),
(Nat.mul_add _ _ _▸ Nat.mul_one _ ▸ ((add_lt_add_iff_left (p * m)).mpr h))⟩,
zero_add]
/-- The `p`-adic valuation of `n!` is equal to the `p`-adic valuation of the factorial of the
largest multiple of `p` below `n`, i.e. `(p * ⌊n / p⌋)!`. -/
@[simp] theorem padicValNat_mul_div_factorial (n : ℕ) [hp : Fact p.Prime] :
padicValNat p (p * (n / p))! = padicValNat p n ! := by
nth_rw 2 [← div_add_mod n p]
exact (padicValNat_factorial_mul_add (n / p) <| mod_lt n hp.out.pos).symm
/-- **Legendre's Theorem**
The `p`-adic valuation of `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed
over the finset `Ico 1 b` where `b` is any bound greater than `log p n`. -/
theorem padicValNat_factorial {n b : ℕ} [hp : Fact p.Prime] (hnb : log p n < b) :
padicValNat p (n !) = ∑ i ∈ Finset.Ico 1 b, n / p ^ i :=
PartENat.natCast_inj.mp ((padicValNat_def' (Nat.Prime.ne_one hp.out) <| factorial_pos _) ▸
Prime.multiplicity_factorial hp.out hnb)
/-- **Legendre's Theorem**
Taking (`p - 1`) times the `p`-adic valuation of `n!` equals `n` minus the sum of base `p` digits
of `n`. -/
| Mathlib/NumberTheory/Padics/PadicVal.lean | 715 | 720 | theorem sub_one_mul_padicValNat_factorial [hp : Fact p.Prime] (n : ℕ):
(p - 1) * padicValNat p (n !) = n - (p.digits n).sum := by |
rw [padicValNat_factorial <| lt_succ_of_lt <| lt.base (log p n)]
nth_rw 2 [← zero_add 1]
rw [Nat.succ_eq_add_one, ← Finset.sum_Ico_add' _ 0 _ 1,
Ico_zero_eq_range, ← sub_one_mul_sum_log_div_pow_eq_sub_sum_digits, Nat.succ_eq_add_one]
|
/-
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
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 _ _
#align measure_theory.is_stopping_time.measurable_set_eq_stopping_time MeasureTheory.IsStoppingTime.measurableSet_eq_stopping_time
theorem measurableSet_eq_stopping_time_of_countable [Countable ι] [TopologicalSpace ι]
[MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι]
[SecondCountableTopology ι] (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_of_countable
· 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_eq_stopping_time_of_countable MeasureTheory.IsStoppingTime.measurableSet_eq_stopping_time_of_countable
end LinearOrder
end IsStoppingTime
section LinearOrder
/-! ## Stopped value and stopped process -/
/-- Given a map `u : ι → Ω → E`, its stopped value with respect to the stopping
time `τ` is the map `x ↦ u (τ ω) ω`. -/
def stoppedValue (u : ι → Ω → β) (τ : Ω → ι) : Ω → β := fun ω => u (τ ω) ω
#align measure_theory.stopped_value MeasureTheory.stoppedValue
theorem stoppedValue_const (u : ι → Ω → β) (i : ι) : (stoppedValue u fun _ => i) = u i :=
rfl
#align measure_theory.stopped_value_const MeasureTheory.stoppedValue_const
variable [LinearOrder ι]
/-- Given a map `u : ι → Ω → E`, the stopped process with respect to `τ` is `u i ω` if
`i ≤ τ ω`, and `u (τ ω) ω` otherwise.
Intuitively, the stopped process stops evolving once the stopping time has occured. -/
def stoppedProcess (u : ι → Ω → β) (τ : Ω → ι) : ι → Ω → β := fun i ω => u (min i (τ ω)) ω
#align measure_theory.stopped_process MeasureTheory.stoppedProcess
theorem stoppedProcess_eq_stoppedValue {u : ι → Ω → β} {τ : Ω → ι} :
stoppedProcess u τ = fun i => stoppedValue u fun ω => min i (τ ω) :=
rfl
#align measure_theory.stopped_process_eq_stopped_value MeasureTheory.stoppedProcess_eq_stoppedValue
theorem stoppedValue_stoppedProcess {u : ι → Ω → β} {τ σ : Ω → ι} :
stoppedValue (stoppedProcess u τ) σ = stoppedValue u fun ω => min (σ ω) (τ ω) :=
rfl
#align measure_theory.stopped_value_stopped_process MeasureTheory.stoppedValue_stoppedProcess
theorem stoppedProcess_eq_of_le {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : i ≤ τ ω) :
stoppedProcess u τ i ω = u i ω := by simp [stoppedProcess, min_eq_left h]
#align measure_theory.stopped_process_eq_of_le MeasureTheory.stoppedProcess_eq_of_le
theorem stoppedProcess_eq_of_ge {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : τ ω ≤ i) :
stoppedProcess u τ i ω = u (τ ω) ω := by simp [stoppedProcess, min_eq_right h]
#align measure_theory.stopped_process_eq_of_ge MeasureTheory.stoppedProcess_eq_of_ge
section ProgMeasurable
variable [MeasurableSpace ι] [TopologicalSpace ι] [OrderTopology ι] [SecondCountableTopology ι]
[BorelSpace ι] [TopologicalSpace β] {u : ι → Ω → β} {τ : Ω → ι} {f : Filtration ι m}
theorem progMeasurable_min_stopping_time [MetrizableSpace ι] (hτ : IsStoppingTime f τ) :
ProgMeasurable f fun i ω => min i (τ ω) := by
intro i
let m_prod : MeasurableSpace (Set.Iic i × Ω) := Subtype.instMeasurableSpace.prod (f i)
let m_set : ∀ t : Set (Set.Iic i × Ω), MeasurableSpace t := fun _ =>
@Subtype.instMeasurableSpace (Set.Iic i × Ω) _ m_prod
let s := {p : Set.Iic i × Ω | τ p.2 ≤ i}
have hs : MeasurableSet[m_prod] s := @measurable_snd (Set.Iic i) Ω _ (f i) _ (hτ i)
have h_meas_fst : ∀ t : Set (Set.Iic i × Ω),
Measurable[m_set t] fun x : t => ((x : Set.Iic i × Ω).fst : ι) :=
fun t => (@measurable_subtype_coe (Set.Iic i × Ω) m_prod _).fst.subtype_val
apply Measurable.stronglyMeasurable
refine measurable_of_restrict_of_restrict_compl hs ?_ ?_
· refine @Measurable.min _ _ _ _ _ (m_set s) _ _ _ _ _ (h_meas_fst s) ?_
refine @measurable_of_Iic ι s _ _ _ (m_set s) _ _ _ _ fun j => ?_
have h_set_eq : (fun x : s => τ (x : Set.Iic i × Ω).snd) ⁻¹' Set.Iic j =
(fun x : s => (x : Set.Iic i × Ω).snd) ⁻¹' {ω | τ ω ≤ min i j} := by
ext1 ω
simp only [Set.mem_preimage, Set.mem_Iic, iff_and_self, le_min_iff, Set.mem_setOf_eq]
exact fun _ => ω.prop
rw [h_set_eq]
suffices h_meas : @Measurable _ _ (m_set s) (f i) fun x : s ↦ (x : Set.Iic i × Ω).snd from
h_meas (f.mono (min_le_left _ _) _ (hτ.measurableSet_le (min i j)))
exact measurable_snd.comp (@measurable_subtype_coe _ m_prod _)
· letI sc := sᶜ
suffices h_min_eq_left :
(fun x : sc => min (↑(x : Set.Iic i × Ω).fst) (τ (x : Set.Iic i × Ω).snd)) = fun x : sc =>
↑(x : Set.Iic i × Ω).fst by
simp (config := { unfoldPartialApp := true }) only [Set.restrict, h_min_eq_left]
exact h_meas_fst _
ext1 ω
rw [min_eq_left]
have hx_fst_le : ↑(ω : Set.Iic i × Ω).fst ≤ i := (ω : Set.Iic i × Ω).fst.prop
refine hx_fst_le.trans (le_of_lt ?_)
convert ω.prop
simp only [sc, s, not_le, Set.mem_compl_iff, Set.mem_setOf_eq]
#align measure_theory.prog_measurable_min_stopping_time MeasureTheory.progMeasurable_min_stopping_time
theorem ProgMeasurable.stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u)
(hτ : IsStoppingTime f τ) : ProgMeasurable f (stoppedProcess u τ) :=
h.comp (progMeasurable_min_stopping_time hτ) fun _ _ => min_le_left _ _
#align measure_theory.prog_measurable.stopped_process MeasureTheory.ProgMeasurable.stoppedProcess
theorem ProgMeasurable.adapted_stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u)
(hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) :=
(h.stoppedProcess hτ).adapted
#align measure_theory.prog_measurable.adapted_stopped_process MeasureTheory.ProgMeasurable.adapted_stoppedProcess
theorem ProgMeasurable.stronglyMeasurable_stoppedProcess [MetrizableSpace ι]
(hu : ProgMeasurable f u) (hτ : IsStoppingTime f τ) (i : ι) :
StronglyMeasurable (MeasureTheory.stoppedProcess u τ i) :=
(hu.adapted_stoppedProcess hτ i).mono (f.le _)
#align measure_theory.prog_measurable.strongly_measurable_stopped_process MeasureTheory.ProgMeasurable.stronglyMeasurable_stoppedProcess
theorem stronglyMeasurable_stoppedValue_of_le (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ)
{n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : StronglyMeasurable[f n] (stoppedValue u τ) := by
have : stoppedValue u τ =
(fun p : Set.Iic n × Ω => u (↑p.fst) p.snd) ∘ fun ω => (⟨τ ω, hτ_le ω⟩, ω) := by
ext1 ω; simp only [stoppedValue, Function.comp_apply, Subtype.coe_mk]
rw [this]
refine StronglyMeasurable.comp_measurable (h n) ?_
exact (hτ.measurable_of_le hτ_le).subtype_mk.prod_mk measurable_id
#align measure_theory.strongly_measurable_stopped_value_of_le MeasureTheory.stronglyMeasurable_stoppedValue_of_le
theorem measurable_stoppedValue [MetrizableSpace β] [MeasurableSpace β] [BorelSpace β]
(hf_prog : ProgMeasurable f u) (hτ : IsStoppingTime f τ) :
Measurable[hτ.measurableSpace] (stoppedValue u τ) := by
have h_str_meas : ∀ i, StronglyMeasurable[f i] (stoppedValue u fun ω => min (τ ω) i) := fun i =>
stronglyMeasurable_stoppedValue_of_le hf_prog (hτ.min_const i) fun _ => min_le_right _ _
intro t ht i
suffices stoppedValue u τ ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} =
(stoppedValue u fun ω => min (τ ω) i) ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} by
rw [this]; exact ((h_str_meas i).measurable ht).inter (hτ.measurableSet_le i)
ext1 ω
simp only [stoppedValue, Set.mem_inter_iff, Set.mem_preimage, Set.mem_setOf_eq,
and_congr_left_iff]
intro h
rw [min_eq_left h]
#align measure_theory.measurable_stopped_value MeasureTheory.measurable_stoppedValue
end ProgMeasurable
end LinearOrder
section StoppedValueOfMemFinset
variable {μ : Measure Ω} {τ σ : Ω → ι} {E : Type*} {p : ℝ≥0∞} {u : ι → Ω → E}
theorem stoppedValue_eq_of_mem_finset [AddCommMonoid E] {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) :
stoppedValue u τ = ∑ i ∈ s, Set.indicator {ω | τ ω = i} (u i) := by
ext y
rw [stoppedValue, Finset.sum_apply, Finset.sum_indicator_eq_sum_filter]
suffices Finset.filter (fun i => y ∈ {ω : Ω | τ ω = i}) s = ({τ y} : Finset ι) by
rw [this, Finset.sum_singleton]
ext1 ω
simp only [Set.mem_setOf_eq, Finset.mem_filter, Finset.mem_singleton]
constructor <;> intro h
· exact h.2.symm
· refine ⟨?_, h.symm⟩; rw [h]; exact hbdd y
#align measure_theory.stopped_value_eq_of_mem_finset MeasureTheory.stoppedValue_eq_of_mem_finset
theorem stoppedValue_eq' [Preorder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] {N : ι}
(hbdd : ∀ ω, τ ω ≤ N) :
stoppedValue u τ = ∑ i ∈ Finset.Iic N, Set.indicator {ω | τ ω = i} (u i) :=
stoppedValue_eq_of_mem_finset fun ω => Finset.mem_Iic.mpr (hbdd ω)
#align measure_theory.stopped_value_eq' MeasureTheory.stoppedValue_eq'
theorem stoppedProcess_eq_of_mem_finset [LinearOrder ι] [AddCommMonoid E] {s : Finset ι} (n : ι)
(hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) +
∑ i ∈ s.filter (· < n), Set.indicator {ω | τ ω = i} (u i) := by
ext ω
rw [Pi.add_apply, Finset.sum_apply]
rcases le_or_lt n (τ ω) with h | h
· rw [stoppedProcess_eq_of_le h, Set.indicator_of_mem, Finset.sum_eq_zero, add_zero]
· intro m hm
refine Set.indicator_of_not_mem ?_ _
rw [Finset.mem_filter] at hm
exact (hm.2.trans_le h).ne'
· exact h
· rw [stoppedProcess_eq_of_ge (le_of_lt h), Finset.sum_eq_single_of_mem (τ ω)]
· rw [Set.indicator_of_not_mem, zero_add, Set.indicator_of_mem] <;> rw [Set.mem_setOf]
exact not_le.2 h
· rw [Finset.mem_filter]
exact ⟨hbdd ω h, h⟩
· intro b _ hneq
rw [Set.indicator_of_not_mem]
rw [Set.mem_setOf]
exact hneq.symm
#align measure_theory.stopped_process_eq_of_mem_finset MeasureTheory.stoppedProcess_eq_of_mem_finset
theorem stoppedProcess_eq'' [LinearOrder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] (n : ι) :
stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) +
∑ i ∈ Finset.Iio n, Set.indicator {ω | τ ω = i} (u i) := by
have h_mem : ∀ ω, τ ω < n → τ ω ∈ Finset.Iio n := fun ω h => Finset.mem_Iio.mpr h
rw [stoppedProcess_eq_of_mem_finset n h_mem]
congr with i
simp
#align measure_theory.stopped_process_eq'' MeasureTheory.stoppedProcess_eq''
section StoppedValue
variable [PartialOrder ι] {ℱ : Filtration ι m} [NormedAddCommGroup E]
theorem memℒp_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ)
{s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : Memℒp (stoppedValue u τ) p μ := by
rw [stoppedValue_eq_of_mem_finset hbdd]
refine memℒp_finset_sum' _ fun i _ => Memℒp.indicator ?_ (hu i)
refine ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq_of_countable_range ?_ i)
refine ((Finset.finite_toSet s).subset fun ω hω => ?_).countable
obtain ⟨y, rfl⟩ := hω
exact hbdd y
#align measure_theory.mem_ℒp_stopped_value_of_mem_finset MeasureTheory.memℒp_stoppedValue_of_mem_finset
theorem memℒp_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Memℒp (u n) p μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : Memℒp (stoppedValue u τ) p μ :=
memℒp_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω)
#align measure_theory.mem_ℒp_stopped_value MeasureTheory.memℒp_stoppedValue
theorem integrable_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) :
Integrable (stoppedValue u τ) μ := by
simp_rw [← memℒp_one_iff_integrable] at hu ⊢
exact memℒp_stoppedValue_of_mem_finset hτ hu hbdd
#align measure_theory.integrable_stopped_value_of_mem_finset MeasureTheory.integrable_stoppedValue_of_mem_finset
variable (ι)
theorem integrable_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) :
Integrable (stoppedValue u τ) μ :=
integrable_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω)
#align measure_theory.integrable_stopped_value MeasureTheory.integrable_stoppedValue
end StoppedValue
section StoppedProcess
variable [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι]
{ℱ : Filtration ι m} [NormedAddCommGroup E]
theorem memℒp_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ)
(n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : Memℒp (stoppedProcess u τ n) p μ := by
rw [stoppedProcess_eq_of_mem_finset n hbdd]
refine Memℒp.add ?_ ?_
· exact Memℒp.indicator (ℱ.le n {a : Ω | n ≤ τ a} (hτ.measurableSet_ge n)) (hu n)
· suffices Memℒp (fun ω => ∑ i ∈ s.filter (· < n), {a : Ω | τ a = i}.indicator (u i) ω) p μ by
convert this using 1; ext1 ω; simp only [Finset.sum_apply]
refine memℒp_finset_sum _ fun i _ => Memℒp.indicator ?_ (hu i)
exact ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq i)
#align measure_theory.mem_ℒp_stopped_process_of_mem_finset MeasureTheory.memℒp_stoppedProcess_of_mem_finset
theorem memℒp_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Memℒp (u n) p μ) (n : ι) : Memℒp (stoppedProcess u τ n) p μ :=
memℒp_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h
#align measure_theory.mem_ℒp_stopped_process MeasureTheory.memℒp_stoppedProcess
theorem integrable_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) :
Integrable (stoppedProcess u τ n) μ := by
simp_rw [← memℒp_one_iff_integrable] at hu ⊢
exact memℒp_stoppedProcess_of_mem_finset hτ hu n hbdd
#align measure_theory.integrable_stopped_process_of_mem_finset MeasureTheory.integrable_stoppedProcess_of_mem_finset
theorem integrable_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) (n : ι) : Integrable (stoppedProcess u τ n) μ :=
integrable_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h
#align measure_theory.integrable_stopped_process MeasureTheory.integrable_stoppedProcess
end StoppedProcess
end StoppedValueOfMemFinset
section AdaptedStoppedProcess
variable [TopologicalSpace β] [PseudoMetrizableSpace β] [LinearOrder ι] [TopologicalSpace ι]
[SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι]
{f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → ι}
/-- The stopped process of an adapted process with continuous paths is adapted. -/
theorem Adapted.stoppedProcess [MetrizableSpace ι] (hu : Adapted f u)
(hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) :
Adapted f (stoppedProcess u τ) :=
((hu.progMeasurable_of_continuous hu_cont).stoppedProcess hτ).adapted
#align measure_theory.adapted.stopped_process MeasureTheory.Adapted.stoppedProcess
/-- If the indexing order has the discrete topology, then the stopped process of an adapted process
is adapted. -/
theorem Adapted.stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u)
(hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) :=
(hu.progMeasurable_of_discrete.stoppedProcess hτ).adapted
#align measure_theory.adapted.stopped_process_of_discrete MeasureTheory.Adapted.stoppedProcess_of_discrete
theorem Adapted.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : Adapted f u)
(hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) (n : ι) :
StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) :=
(hu.progMeasurable_of_continuous hu_cont).stronglyMeasurable_stoppedProcess hτ n
#align measure_theory.adapted.strongly_measurable_stopped_process MeasureTheory.Adapted.stronglyMeasurable_stoppedProcess
theorem Adapted.stronglyMeasurable_stoppedProcess_of_discrete [DiscreteTopology ι]
(hu : Adapted f u) (hτ : IsStoppingTime f τ) (n : ι) :
StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) :=
hu.progMeasurable_of_discrete.stronglyMeasurable_stoppedProcess hτ n
#align measure_theory.adapted.strongly_measurable_stopped_process_of_discrete MeasureTheory.Adapted.stronglyMeasurable_stoppedProcess_of_discrete
end AdaptedStoppedProcess
section Nat
/-! ### Filtrations indexed by `ℕ` -/
open Filtration
variable {f : Filtration ℕ m} {u : ℕ → Ω → β} {τ π : Ω → ℕ}
theorem stoppedValue_sub_eq_sum [AddCommGroup β] (hle : τ ≤ π) :
stoppedValue u π - stoppedValue u τ = fun ω =>
(∑ i ∈ Finset.Ico (τ ω) (π ω), (u (i + 1) - u i)) ω := by
ext ω
rw [Finset.sum_Ico_eq_sub _ (hle ω), Finset.sum_range_sub, Finset.sum_range_sub]
simp [stoppedValue]
#align measure_theory.stopped_value_sub_eq_sum MeasureTheory.stoppedValue_sub_eq_sum
theorem stoppedValue_sub_eq_sum' [AddCommGroup β] (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ ω, π ω ≤ N) :
stoppedValue u π - stoppedValue u τ = fun ω =>
(∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω ≤ i ∧ i < π ω} (u (i + 1) - u i)) ω := by
rw [stoppedValue_sub_eq_sum hle]
ext ω
simp only [Finset.sum_apply, Finset.sum_indicator_eq_sum_filter]
refine Finset.sum_congr ?_ fun _ _ => rfl
ext i
simp only [Finset.mem_filter, Set.mem_setOf_eq, Finset.mem_range, Finset.mem_Ico]
exact ⟨fun h => ⟨lt_trans h.2 (Nat.lt_succ_iff.2 <| hbdd _), h⟩, fun h => h.2⟩
#align measure_theory.stopped_value_sub_eq_sum' MeasureTheory.stoppedValue_sub_eq_sum'
section AddCommMonoid
variable [AddCommMonoid β]
theorem stoppedValue_eq {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = fun x =>
(∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω = i} (u i)) x :=
stoppedValue_eq_of_mem_finset fun ω => Finset.mem_range_succ_iff.mpr (hbdd ω)
#align measure_theory.stopped_value_eq MeasureTheory.stoppedValue_eq
| Mathlib/Probability/Process/Stopping.lean | 1,085 | 1,089 | theorem stoppedProcess_eq (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) +
∑ i ∈ Finset.range n, Set.indicator {ω | τ ω = i} (u i) := by |
rw [stoppedProcess_eq'' n]
congr with i
rw [Finset.mem_Iio, Finset.mem_range]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest
lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and
meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a ⊔ b`: the supremum or join of `a` and `b`
* `a ⊓ b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
/-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/
@[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where
eval h goal := do goal.assignIfDefeq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h])
universe u v w
variable {α : Type u} {β : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`⊔` which is the least element larger than both factors. -/
class SemilatticeSup (α : Type u) extends Sup α, PartialOrder α where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : ∀ a b : α, a ≤ a ⊔ b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : ∀ a b : α, b ≤ a ⊔ b
/-- The supremum is the *least* upper bound -/
protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {α : Type*} [Sup α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) :
SemilatticeSup α where
sup := (· ⊔ ·)
le a b := a ⊔ b = b
le_refl := sup_idem
le_trans a b c hab hbc := by dsimp; rw [← hbc, ← sup_assoc, hab]
le_antisymm a b hab hba := by rwa [← hba, sup_comm]
le_sup_left a b := by dsimp; rw [← sup_assoc, sup_idem]
le_sup_right a b := by dsimp; rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by dsimp; rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance OrderDual.instSup (α : Type*) [Inf α] : Sup αᵒᵈ :=
⟨((· ⊓ ·) : α → α → α)⟩
instance OrderDual.instInf (α : Type*) [Sup α] : Inf αᵒᵈ :=
⟨((· ⊔ ·) : α → α → α)⟩
section SemilatticeSup
variable [SemilatticeSup α] {a b c d : α}
@[simp]
theorem le_sup_left : a ≤ a ⊔ b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
#align le_sup_left' le_sup_left
@[deprecated (since := "2024-06-04")] alias le_sup_left' := le_sup_left
@[simp]
theorem le_sup_right : b ≤ a ⊔ b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
#align le_sup_right' le_sup_right
@[deprecated (since := "2024-06-04")] alias le_sup_right' := le_sup_right
theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c :=
⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩,
fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias ⟨_, sup_of_le_left⟩ := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a :=
le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b :=
le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by
constructor
· intro h
exact ⟨b, (sup_eq_right.mpr h).symm⟩
· rintro ⟨c, rfl : _ = _ ⊔ _⟩
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d :=
sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b :=
sup_le_sup le_rfl h₁
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c :=
sup_le_sup h₁ le_rfl
#align sup_le_sup_right sup_le_sup_right
theorem sup_idem (a : α) : a ⊔ a = a := by simp
#align sup_idem sup_idem
instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩
theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩
theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) :=
eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩
theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by
rw [sup_comm, sup_comm a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp
#align sup_left_idem sup_left_idem
theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by
rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by
rw [sup_assoc, sup_assoc, sup_comm b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by
rw [sup_assoc, sup_left_comm b, ← sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c :=
(sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c :=
(sup_le ha le_sup_right).antisymm <| sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b :=
⟨fun h => ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, fun h => sup_congr_left h.1 h.2⟩
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c :=
⟨fun h => ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, fun h => sup_congr_right h.1 h.2⟩
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/
theorem Monotone.forall_le_of_antitone {β : Type*} [Preorder β] {f g : α → β} (hf : Monotone f)
(hg : Antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n :=
calc
f m ≤ f (m ⊔ n) := hf le_sup_left
_ ≤ g (m ⊔ n) := h _
_ ≤ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {α} {A B : SemilatticeSup α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y)
(x y : α) :
(haveI := A; x ⊔ y) = x ⊔ y :=
eq_of_forall_ge_iff fun c => by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {α} {A B : SemilatticeSup α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : α) (P : Prop) [Decidable P] : ite P s s' ≤ s ⊔ s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`⊓` which is the greatest element smaller than both factors. -/
class SemilatticeInf (α : Type u) extends Inf α, PartialOrder α where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : ∀ a b : α, a ⊓ b ≤ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : ∀ a b : α, a ⊓ b ≤ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c
#align semilattice_inf SemilatticeInf
instance OrderDual.instSemilatticeSup (α) [SemilatticeInf α] : SemilatticeSup αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
__ := inferInstanceAs (Sup αᵒᵈ)
le_sup_left := @SemilatticeInf.inf_le_left α _
le_sup_right := @SemilatticeInf.inf_le_right α _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf α _ _ _ _ hca hcb
instance OrderDual.instSemilatticeInf (α) [SemilatticeSup α] : SemilatticeInf αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
__ := inferInstanceAs (Inf αᵒᵈ)
inf_le_left := @le_sup_left α _
inf_le_right := @le_sup_right α _
le_inf := fun _ _ _ hca hcb => @sup_le α _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (α : Type*) [H : SemilatticeSup α] :
OrderDual.instSemilatticeSup αᵒᵈ = H :=
SemilatticeSup.ext fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf α] {a b c d : α}
@[simp]
theorem inf_le_left : a ⊓ b ≤ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
#align inf_le_left' inf_le_left
@[deprecated (since := "2024-06-04")] alias inf_le_left' := inf_le_left
@[simp]
theorem inf_le_right : a ⊓ b ≤ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
#align inf_le_right' inf_le_right
@[deprecated (since := "2024-06-04")] alias inf_le_right' := inf_le_right
theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a ⊓ b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a ⊓ b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c :=
@sup_le_iff αᵒᵈ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias ⟨le_of_inf_eq, inf_of_le_left⟩ := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias ⟨_, inf_of_le_right⟩ := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a ⊓ b < a ↔ ¬a ≤ b :=
@left_lt_sup αᵒᵈ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a ⊓ b < b ↔ ¬b ≤ a :=
@right_lt_sup αᵒᵈ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a ≠ b) : a ⊓ b < a ∨ a ⊓ b < b :=
@left_or_right_lt_sup αᵒᵈ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d :=
@sup_le_sup αᵒᵈ _ _ _ _ _ h₁ h₂
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
theorem inf_idem (a : α) : a ⊓ a = a := by simp
#align inf_idem inf_idem
instance : Std.IdempotentOp (α := α) (· ⊓ ·) := ⟨inf_idem⟩
theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := @sup_comm αᵒᵈ _ _ _
#align inf_comm inf_comm
instance : Std.Commutative (α := α) (· ⊓ ·) := ⟨inf_comm⟩
theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := @sup_assoc αᵒᵈ _ _ _ _
#align inf_assoc inf_assoc
instance : Std.Associative (α := α) (· ⊓ ·) := ⟨inf_assoc⟩
theorem inf_left_right_swap (a b c : α) : a ⊓ b ⊓ c = c ⊓ b ⊓ a :=
@sup_left_right_swap αᵒᵈ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
theorem inf_left_idem (a b : α) : a ⊓ (a ⊓ b) = a ⊓ b := by simp
#align inf_left_idem inf_left_idem
theorem inf_right_idem (a b : α) : a ⊓ b ⊓ b = a ⊓ b := by simp
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) :=
@sup_left_comm αᵒᵈ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ b :=
@sup_right_comm αᵒᵈ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : α) : a ⊓ b ⊓ (c ⊓ d) = a ⊓ c ⊓ (b ⊓ d) :=
@sup_sup_sup_comm αᵒᵈ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : α) : a ⊓ (b ⊓ c) = a ⊓ b ⊓ (a ⊓ c) :=
@sup_sup_distrib_left αᵒᵈ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ (b ⊓ c) :=
@sup_sup_distrib_right αᵒᵈ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a ⊓ c ≤ b) (hc : a ⊓ b ≤ c) : a ⊓ b = a ⊓ c :=
@sup_congr_left αᵒᵈ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b ⊓ c ≤ a) (h2 : a ⊓ c ≤ b) : a ⊓ c = b ⊓ c :=
@sup_congr_right αᵒᵈ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a ⊓ b = a ⊓ c ↔ a ⊓ c ≤ b ∧ a ⊓ b ≤ c :=
@sup_eq_sup_iff_left αᵒᵈ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a ⊓ c = b ⊓ c ↔ b ⊓ c ≤ a ∧ a ⊓ c ≤ b :=
@sup_eq_sup_iff_right αᵒᵈ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a ≠ b → a ⊓ b < a ∨ a ⊓ b < b :=
@Ne.lt_sup_or_lt_sup αᵒᵈ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {α} {A B : SemilatticeInf α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y)
(x y : α) :
(haveI := A; x ⊓ y) = x ⊓ y :=
eq_of_forall_le_iff fun c => by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {α} {A B : SemilatticeInf α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (α : Type*) [H : SemilatticeInf α] :
OrderDual.instSemilatticeInf αᵒᵈ = H :=
SemilatticeInf.ext fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : α) (P : Prop) [Decidable P] : s ⊓ s' ≤ ite P s s' :=
@ite_le_sup αᵒᵈ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `b ⊓ a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {α : Type*} [Inf α] (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a) :
SemilatticeInf α := by
haveI : SemilatticeSup αᵒᵈ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.instSemilatticeInf αᵒᵈ
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (α : Type u) extends SemilatticeSup α, SemilatticeInf α
#align lattice Lattice
instance OrderDual.instLattice (α) [Lattice α] : Lattice αᵒᵈ where
__ := OrderDual.instSemilatticeSup α
__ := OrderDual.instSemilatticeInf α
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a ⊔ a ⊓ b = a`)
and `inf_sup_self` (`a ⊓ (a ⊔ b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{α : Type*} [Sup α] [Inf α]
(sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c))
(sup_idem : ∀ a : α, a ⊔ a = a) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a)
(sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a) (inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext fun a b =>
show a ⊔ b = b ↔ b ⊓ a = a from
⟨fun h => by rw [← h, inf_comm, inf_sup_self], fun h => by rw [← h, sup_comm, sup_inf_self]⟩
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {α : Type*} [Sup α] [Inf α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a)
(inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) : Lattice α :=
have sup_idem : ∀ b : α, b ⊔ b = b := fun b =>
calc
b ⊔ b = b ⊔ b ⊓ (b ⊔ b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : ∀ b : α, b ⊓ b = b := fun b =>
calc
b ⊓ b = b ⊓ (b ⊔ b ⊓ b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice α] {a b c d : α}
theorem inf_le_sup : a ⊓ b ≤ a ⊔ b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
theorem sup_le_inf : a ⊔ b ≤ a ⊓ b ↔ a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a ⊓ b = a ⊔ b ↔ a = b := by rw [← inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a ⊔ b = a ⊓ b ↔ a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a ⊓ b < a ⊔ b ↔ a ≠ b := by rw [inf_le_sup.lt_iff_ne, Ne, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a ⊓ b = c ∧ a ⊔ b = c ↔ a = c ∧ b = c := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h
· rintro ⟨rfl, rfl⟩
exact ⟨inf_idem _, sup_idem _⟩
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a ⊔ b ⊓ c ≤ (a ⊔ b) ⊓ (a ⊔ c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a ⊓ b ⊔ a ⊓ c ≤ a ⊓ (b ⊔ c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a ⊔ a ⊓ b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a ⊔ b = b ↔ a ⊓ b = a := by rw [sup_eq_right, ← inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {α} {A B : Lattice α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (α) extends Lattice α where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : ∀ x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice α] {x y z : α}
theorem le_sup_inf : ∀ {x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left (a b c : α) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right (a b c : α) : a ⊓ b ⊔ c = (a ⊔ c) ⊓ (b ⊔ c) := by
simp only [sup_inf_left, sup_comm _ c, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left (a b c : α) : a ⊓ (b ⊔ c) = a ⊓ b ⊔ a ⊓ c :=
calc
a ⊓ (b ⊔ c) = a ⊓ (a ⊔ c) ⊓ (b ⊔ c) := by rw [inf_sup_self]
_ = a ⊓ (a ⊓ b ⊔ c) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (a ⊔ a ⊓ b) ⊓ (a ⊓ b ⊔ c) := by rw [sup_inf_self]
_ = (a ⊓ b ⊔ a) ⊓ (a ⊓ b ⊔ c) := by rw [sup_comm]
_ = a ⊓ b ⊔ a ⊓ c := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.instDistribLattice (α : Type*) [DistribLattice α] : DistribLattice αᵒᵈ where
__ := inferInstanceAs (Lattice αᵒᵈ)
le_sup_inf _ _ _ := (inf_sup_left _ _ _).le
theorem inf_sup_right (a b c : α) : (a ⊔ b) ⊓ c = a ⊓ c ⊔ b ⊓ c := by
simp only [inf_sup_left, inf_comm _ c, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y :=
calc
x ≤ y ⊓ z ⊔ x := le_sup_right
_ = (y ⊔ x) ⊓ (x ⊔ z) := by rw [sup_inf_right, sup_comm x]
_ ≤ (y ⊔ x) ⊓ (y ⊔ z) := inf_le_inf_left _ h₂
_ = y ⊔ x ⊓ z := by rw [← sup_inf_left]
_ ≤ y ⊔ y ⊓ z := sup_le_sup_left h₁ _
_ ≤ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂))
(le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
abbrev DistribLattice.ofInfSupLe
[Lattice α] (inf_sup_le : ∀ a b c : α, a ⊓ (b ⊔ c) ≤ a ⊓ b ⊔ a ⊓ c) : DistribLattice α where
le_sup_inf := (@OrderDual.instDistribLattice αᵒᵈ {inferInstanceAs (Lattice αᵒᵈ) with
le_sup_inf := inf_sup_le}).le_sup_inf
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {α : Type u} [o : LinearOrder α] : Lattice α where
__ := o
sup := max
le_sup_left := le_max_left; le_sup_right := le_max_right; sup_le _ _ _ := max_le
inf := min
inf_le_left := min_le_left; inf_le_right := min_le_right; le_inf _ _ _ := le_min
section LinearOrder
variable [LinearOrder α] {a b c d : α}
theorem sup_eq_max : a ⊔ b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a ⊓ b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) :=
(IsTotal.total a b).elim (fun h : a ≤ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := by
exact ⟨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩
#align le_sup_iff le_sup_iff
@[simp]
| Mathlib/Order/Lattice.lean | 808 | 813 | theorem lt_sup_iff : a < b ⊔ c ↔ a < b ∨ a < c := by |
exact ⟨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_right⟩
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad
-/
import Mathlib.Order.Filter.Lift
import Mathlib.Topology.Defs.Filter
#align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40"
/-!
# Basic theory of topological spaces.
The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology.
Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and
`frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has
`x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x`
along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular
the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`.
For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`,
`ContinuousAt f x` means `f` is continuous at `x`, and global continuity is
`Continuous f`. There is also a version of continuity `PContinuous` for
partially defined functions.
## Notation
The following notation is introduced elsewhere and it heavily used in this file.
* `𝓝 x`: the filter `nhds x` 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`;
* `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`.
## Implementation notes
Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in
<https://leanprover-community.github.io/theories/topology.html>.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
## Tags
topological space, interior, closure, frontier, neighborhood, continuity, continuous function
-/
noncomputable section
open Set Filter
universe u v w x
/-!
### Topological spaces
-/
/-- A constructor for topologies by specifying the closed sets,
and showing that they satisfy the appropriate conditions. -/
def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T)
(sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T)
(union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where
IsOpen X := Xᶜ ∈ T
isOpen_univ := by simp [empty_mem]
isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht
isOpen_sUnion s hs := by
simp only [Set.compl_sUnion]
exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy
#align topological_space.of_closed TopologicalSpace.ofClosed
section TopologicalSpace
variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*}
{x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop}
open Topology
lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl
#align is_open_mk isOpen_mk
@[ext]
protected theorem TopologicalSpace.ext :
∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
#align topological_space_eq TopologicalSpace.ext
section
variable [TopologicalSpace X]
end
protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} :
t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s :=
⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩
#align topological_space_eq_iff TopologicalSpace.ext_iff
theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s :=
rfl
#align is_open_fold isOpen_fold
variable [TopologicalSpace X]
theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) :=
isOpen_sUnion (forall_mem_range.2 h)
#align is_open_Union isOpen_iUnion
theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋃ i ∈ s, f i) :=
isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi
#align is_open_bUnion isOpen_biUnion
theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by
rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩)
#align is_open.union IsOpen.union
lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) :
IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by
refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩
rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter]
exact isOpen_iUnion fun i ↦ h i
@[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by
rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim
#align is_open_empty isOpen_empty
theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) :
(∀ t ∈ s, IsOpen t) → IsOpen (⋂₀ s) :=
Finite.induction_on hs (fun _ => by rw [sInter_empty]; exact isOpen_univ) fun _ _ ih h => by
simp only [sInter_insert, forall_mem_insert] at h ⊢
exact h.1.inter (ih h.2)
#align is_open_sInter Set.Finite.isOpen_sInter
theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite)
(h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋂ i ∈ s, f i) :=
sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h)
#align is_open_bInter Set.Finite.isOpen_biInter
theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) :
IsOpen (⋂ i, s i) :=
(finite_range _).isOpen_sInter (forall_mem_range.2 h)
#align is_open_Inter isOpen_iInter_of_finite
theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋂ i ∈ s, f i) :=
s.finite_toSet.isOpen_biInter h
#align is_open_bInter_finset isOpen_biInter_finset
@[simp] -- Porting note: added `simp`
theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*]
#align is_open_const isOpen_const
theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } :=
IsOpen.inter
#align is_open.and IsOpen.and
@[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s :=
⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩
#align is_open_compl_iff isOpen_compl_iff
theorem TopologicalSpace.ext_iff_isClosed {t₁ t₂ : TopologicalSpace X} :
t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by
rw [TopologicalSpace.ext_iff, compl_surjective.forall]
simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂]
alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed
-- Porting note (#10756): new lemma
theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩
@[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const
#align is_closed_empty isClosed_empty
@[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const
#align is_closed_univ isClosed_univ
theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by
simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter
#align is_closed.union IsClosed.union
theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by
simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion
#align is_closed_sInter isClosed_sInter
theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) :=
isClosed_sInter <| forall_mem_range.2 h
#align is_closed_Inter isClosed_iInter
theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋂ i ∈ s, f i) :=
isClosed_iInter fun i => isClosed_iInter <| h i
#align is_closed_bInter isClosed_biInter
@[simp]
theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by
rw [← isOpen_compl_iff, compl_compl]
#align is_closed_compl_iff isClosed_compl_iff
alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff
#align is_open.is_closed_compl IsOpen.isClosed_compl
theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) :=
IsOpen.inter h₁ h₂.isOpen_compl
#align is_open.sdiff IsOpen.sdiff
theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by
rw [← isOpen_compl_iff] at *
rw [compl_inter]
exact IsOpen.union h₁ h₂
#align is_closed.inter IsClosed.inter
theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) :=
IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂)
#align is_closed.sdiff IsClosed.sdiff
theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite)
(h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋃ i ∈ s, f i) := by
simp only [← isOpen_compl_iff, compl_iUnion] at *
exact hs.isOpen_biInter h
#align is_closed_bUnion Set.Finite.isClosed_biUnion
lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋃ i ∈ s, f i) :=
s.finite_toSet.isClosed_biUnion h
theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) :
IsClosed (⋃ i, s i) := by
simp only [← isOpen_compl_iff, compl_iUnion] at *
exact isOpen_iInter_of_finite h
#align is_closed_Union isClosed_iUnion_of_finite
theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) :
IsClosed { x | p x → q x } := by
simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq
#align is_closed_imp isClosed_imp
theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } :=
isOpen_compl_iff.mpr
#align is_closed.not IsClosed.not
/-!
### Interior of a set
-/
theorem mem_interior : x ∈ interior s ↔ ∃ t ⊆ s, IsOpen t ∧ x ∈ t := by
simp only [interior, mem_sUnion, mem_setOf_eq, and_assoc, and_left_comm]
#align mem_interior mem_interiorₓ
@[simp]
theorem isOpen_interior : IsOpen (interior s) :=
isOpen_sUnion fun _ => And.left
#align is_open_interior isOpen_interior
theorem interior_subset : interior s ⊆ s :=
sUnion_subset fun _ => And.right
#align interior_subset interior_subset
theorem interior_maximal (h₁ : t ⊆ s) (h₂ : IsOpen t) : t ⊆ interior s :=
subset_sUnion_of_mem ⟨h₂, h₁⟩
#align interior_maximal interior_maximal
theorem IsOpen.interior_eq (h : IsOpen s) : interior s = s :=
interior_subset.antisymm (interior_maximal (Subset.refl s) h)
#align is_open.interior_eq IsOpen.interior_eq
theorem interior_eq_iff_isOpen : interior s = s ↔ IsOpen s :=
⟨fun h => h ▸ isOpen_interior, IsOpen.interior_eq⟩
#align interior_eq_iff_is_open interior_eq_iff_isOpen
theorem subset_interior_iff_isOpen : s ⊆ interior s ↔ IsOpen s := by
simp only [interior_eq_iff_isOpen.symm, Subset.antisymm_iff, interior_subset, true_and]
#align subset_interior_iff_is_open subset_interior_iff_isOpen
theorem IsOpen.subset_interior_iff (h₁ : IsOpen s) : s ⊆ interior t ↔ s ⊆ t :=
⟨fun h => Subset.trans h interior_subset, fun h₂ => interior_maximal h₂ h₁⟩
#align is_open.subset_interior_iff IsOpen.subset_interior_iff
theorem subset_interior_iff : t ⊆ interior s ↔ ∃ U, IsOpen U ∧ t ⊆ U ∧ U ⊆ s :=
⟨fun h => ⟨interior s, isOpen_interior, h, interior_subset⟩, fun ⟨_U, hU, htU, hUs⟩ =>
htU.trans (interior_maximal hUs hU)⟩
#align subset_interior_iff subset_interior_iff
lemma interior_subset_iff : interior s ⊆ t ↔ ∀ U, IsOpen U → U ⊆ s → U ⊆ t := by
simp [interior]
@[mono, gcongr]
theorem interior_mono (h : s ⊆ t) : interior s ⊆ interior t :=
interior_maximal (Subset.trans interior_subset h) isOpen_interior
#align interior_mono interior_mono
@[simp]
theorem interior_empty : interior (∅ : Set X) = ∅ :=
isOpen_empty.interior_eq
#align interior_empty interior_empty
@[simp]
theorem interior_univ : interior (univ : Set X) = univ :=
isOpen_univ.interior_eq
#align interior_univ interior_univ
@[simp]
theorem interior_eq_univ : interior s = univ ↔ s = univ :=
⟨fun h => univ_subset_iff.mp <| h.symm.trans_le interior_subset, fun h => h.symm ▸ interior_univ⟩
#align interior_eq_univ interior_eq_univ
@[simp]
theorem interior_interior : interior (interior s) = interior s :=
isOpen_interior.interior_eq
#align interior_interior interior_interior
@[simp]
theorem interior_inter : interior (s ∩ t) = interior s ∩ interior t :=
(Monotone.map_inf_le (fun _ _ ↦ interior_mono) s t).antisymm <|
interior_maximal (inter_subset_inter interior_subset interior_subset) <|
isOpen_interior.inter isOpen_interior
#align interior_inter interior_inter
theorem Set.Finite.interior_biInter {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) :
interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) :=
hs.induction_on (by simp) <| by intros; simp [*]
theorem Set.Finite.interior_sInter {S : Set (Set X)} (hS : S.Finite) :
interior (⋂₀ S) = ⋂ s ∈ S, interior s := by
rw [sInter_eq_biInter, hS.interior_biInter]
@[simp]
theorem Finset.interior_iInter {ι : Type*} (s : Finset ι) (f : ι → Set X) :
interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) :=
s.finite_toSet.interior_biInter f
#align finset.interior_Inter Finset.interior_iInter
@[simp]
theorem interior_iInter_of_finite [Finite ι] (f : ι → Set X) :
interior (⋂ i, f i) = ⋂ i, interior (f i) := by
rw [← sInter_range, (finite_range f).interior_sInter, biInter_range]
#align interior_Inter interior_iInter_of_finite
theorem interior_union_isClosed_of_interior_empty (h₁ : IsClosed s)
(h₂ : interior t = ∅) : interior (s ∪ t) = interior s :=
have : interior (s ∪ t) ⊆ s := fun x ⟨u, ⟨(hu₁ : IsOpen u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩ =>
by_contradiction fun hx₂ : x ∉ s =>
have : u \ s ⊆ t := fun x ⟨h₁, h₂⟩ => Or.resolve_left (hu₂ h₁) h₂
have : u \ s ⊆ interior t := by rwa [(IsOpen.sdiff hu₁ h₁).subset_interior_iff]
have : u \ s ⊆ ∅ := by rwa [h₂] at this
this ⟨hx₁, hx₂⟩
Subset.antisymm (interior_maximal this isOpen_interior) (interior_mono subset_union_left)
#align interior_union_is_closed_of_interior_empty interior_union_isClosed_of_interior_empty
theorem isOpen_iff_forall_mem_open : IsOpen s ↔ ∀ x ∈ s, ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := by
rw [← subset_interior_iff_isOpen]
simp only [subset_def, mem_interior]
#align is_open_iff_forall_mem_open isOpen_iff_forall_mem_open
theorem interior_iInter_subset (s : ι → Set X) : interior (⋂ i, s i) ⊆ ⋂ i, interior (s i) :=
subset_iInter fun _ => interior_mono <| iInter_subset _ _
#align interior_Inter_subset interior_iInter_subset
theorem interior_iInter₂_subset (p : ι → Sort*) (s : ∀ i, p i → Set X) :
interior (⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), interior (s i j) :=
(interior_iInter_subset _).trans <| iInter_mono fun _ => interior_iInter_subset _
#align interior_Inter₂_subset interior_iInter₂_subset
theorem interior_sInter_subset (S : Set (Set X)) : interior (⋂₀ S) ⊆ ⋂ s ∈ S, interior s :=
calc
interior (⋂₀ S) = interior (⋂ s ∈ S, s) := by rw [sInter_eq_biInter]
_ ⊆ ⋂ s ∈ S, interior s := interior_iInter₂_subset _ _
#align interior_sInter_subset interior_sInter_subset
theorem Filter.HasBasis.lift'_interior {l : Filter X} {p : ι → Prop} {s : ι → Set X}
(h : l.HasBasis p s) : (l.lift' interior).HasBasis p fun i => interior (s i) :=
h.lift' fun _ _ ↦ interior_mono
theorem Filter.lift'_interior_le (l : Filter X) : l.lift' interior ≤ l := fun _s hs ↦
mem_of_superset (mem_lift' hs) interior_subset
theorem Filter.HasBasis.lift'_interior_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X}
(h : l.HasBasis p s) (ho : ∀ i, p i → IsOpen (s i)) : l.lift' interior = l :=
le_antisymm l.lift'_interior_le <| h.lift'_interior.ge_iff.2 fun i hi ↦ by
simpa only [(ho i hi).interior_eq] using h.mem_of_mem hi
/-!
### Closure of a set
-/
@[simp]
theorem isClosed_closure : IsClosed (closure s) :=
isClosed_sInter fun _ => And.left
#align is_closed_closure isClosed_closure
theorem subset_closure : s ⊆ closure s :=
subset_sInter fun _ => And.right
#align subset_closure subset_closure
theorem not_mem_of_not_mem_closure {P : X} (hP : P ∉ closure s) : P ∉ s := fun h =>
hP (subset_closure h)
#align not_mem_of_not_mem_closure not_mem_of_not_mem_closure
theorem closure_minimal (h₁ : s ⊆ t) (h₂ : IsClosed t) : closure s ⊆ t :=
sInter_subset_of_mem ⟨h₂, h₁⟩
#align closure_minimal closure_minimal
theorem Disjoint.closure_left (hd : Disjoint s t) (ht : IsOpen t) :
Disjoint (closure s) t :=
disjoint_compl_left.mono_left <| closure_minimal hd.subset_compl_right ht.isClosed_compl
#align disjoint.closure_left Disjoint.closure_left
theorem Disjoint.closure_right (hd : Disjoint s t) (hs : IsOpen s) :
Disjoint s (closure t) :=
(hd.symm.closure_left hs).symm
#align disjoint.closure_right Disjoint.closure_right
theorem IsClosed.closure_eq (h : IsClosed s) : closure s = s :=
Subset.antisymm (closure_minimal (Subset.refl s) h) subset_closure
#align is_closed.closure_eq IsClosed.closure_eq
theorem IsClosed.closure_subset (hs : IsClosed s) : closure s ⊆ s :=
closure_minimal (Subset.refl _) hs
#align is_closed.closure_subset IsClosed.closure_subset
theorem IsClosed.closure_subset_iff (h₁ : IsClosed t) : closure s ⊆ t ↔ s ⊆ t :=
⟨Subset.trans subset_closure, fun h => closure_minimal h h₁⟩
#align is_closed.closure_subset_iff IsClosed.closure_subset_iff
theorem IsClosed.mem_iff_closure_subset (hs : IsClosed s) :
x ∈ s ↔ closure ({x} : Set X) ⊆ s :=
(hs.closure_subset_iff.trans Set.singleton_subset_iff).symm
#align is_closed.mem_iff_closure_subset IsClosed.mem_iff_closure_subset
@[mono, gcongr]
theorem closure_mono (h : s ⊆ t) : closure s ⊆ closure t :=
closure_minimal (Subset.trans h subset_closure) isClosed_closure
#align closure_mono closure_mono
theorem monotone_closure (X : Type*) [TopologicalSpace X] : Monotone (@closure X _) := fun _ _ =>
closure_mono
#align monotone_closure monotone_closure
theorem diff_subset_closure_iff : s \ t ⊆ closure t ↔ s ⊆ closure t := by
rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure]
#align diff_subset_closure_iff diff_subset_closure_iff
theorem closure_inter_subset_inter_closure (s t : Set X) :
closure (s ∩ t) ⊆ closure s ∩ closure t :=
(monotone_closure X).map_inf_le s t
#align closure_inter_subset_inter_closure closure_inter_subset_inter_closure
theorem isClosed_of_closure_subset (h : closure s ⊆ s) : IsClosed s := by
rw [subset_closure.antisymm h]; exact isClosed_closure
#align is_closed_of_closure_subset isClosed_of_closure_subset
theorem closure_eq_iff_isClosed : closure s = s ↔ IsClosed s :=
⟨fun h => h ▸ isClosed_closure, IsClosed.closure_eq⟩
#align closure_eq_iff_is_closed closure_eq_iff_isClosed
theorem closure_subset_iff_isClosed : closure s ⊆ s ↔ IsClosed s :=
⟨isClosed_of_closure_subset, IsClosed.closure_subset⟩
#align closure_subset_iff_is_closed closure_subset_iff_isClosed
@[simp]
theorem closure_empty : closure (∅ : Set X) = ∅ :=
isClosed_empty.closure_eq
#align closure_empty closure_empty
@[simp]
theorem closure_empty_iff (s : Set X) : closure s = ∅ ↔ s = ∅ :=
⟨subset_eq_empty subset_closure, fun h => h.symm ▸ closure_empty⟩
#align closure_empty_iff closure_empty_iff
@[simp]
theorem closure_nonempty_iff : (closure s).Nonempty ↔ s.Nonempty := by
simp only [nonempty_iff_ne_empty, Ne, closure_empty_iff]
#align closure_nonempty_iff closure_nonempty_iff
alias ⟨Set.Nonempty.of_closure, Set.Nonempty.closure⟩ := closure_nonempty_iff
#align set.nonempty.of_closure Set.Nonempty.of_closure
#align set.nonempty.closure Set.Nonempty.closure
@[simp]
theorem closure_univ : closure (univ : Set X) = univ :=
isClosed_univ.closure_eq
#align closure_univ closure_univ
@[simp]
theorem closure_closure : closure (closure s) = closure s :=
isClosed_closure.closure_eq
#align closure_closure closure_closure
theorem closure_eq_compl_interior_compl : closure s = (interior sᶜ)ᶜ := by
rw [interior, closure, compl_sUnion, compl_image_set_of]
simp only [compl_subset_compl, isOpen_compl_iff]
#align closure_eq_compl_interior_compl closure_eq_compl_interior_compl
@[simp]
theorem closure_union : closure (s ∪ t) = closure s ∪ closure t := by
simp [closure_eq_compl_interior_compl, compl_inter]
#align closure_union closure_union
theorem Set.Finite.closure_biUnion {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) :
closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := by
simp [closure_eq_compl_interior_compl, hs.interior_biInter]
theorem Set.Finite.closure_sUnion {S : Set (Set X)} (hS : S.Finite) :
closure (⋃₀ S) = ⋃ s ∈ S, closure s := by
rw [sUnion_eq_biUnion, hS.closure_biUnion]
@[simp]
theorem Finset.closure_biUnion {ι : Type*} (s : Finset ι) (f : ι → Set X) :
closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) :=
s.finite_toSet.closure_biUnion f
#align finset.closure_bUnion Finset.closure_biUnion
@[simp]
theorem closure_iUnion_of_finite [Finite ι] (f : ι → Set X) :
closure (⋃ i, f i) = ⋃ i, closure (f i) := by
rw [← sUnion_range, (finite_range _).closure_sUnion, biUnion_range]
#align closure_Union closure_iUnion_of_finite
theorem interior_subset_closure : interior s ⊆ closure s :=
Subset.trans interior_subset subset_closure
#align interior_subset_closure interior_subset_closure
@[simp]
| Mathlib/Topology/Basic.lean | 527 | 528 | theorem interior_compl : interior sᶜ = (closure s)ᶜ := by |
simp [closure_eq_compl_interior_compl]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Algebra.Group.Indicator
import Mathlib.Data.Finset.Piecewise
import Mathlib.Data.Finset.Preimage
#align_import algebra.big_operators.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83"
/-!
# Big operators
In this file we define products and sums indexed by finite sets (specifically, `Finset`).
## Notation
We introduce the following notation.
Let `s` be a `Finset α`, and `f : α → β` a function.
* `∏ x ∈ s, f x` is notation for `Finset.prod s f` (assuming `β` is a `CommMonoid`)
* `∑ x ∈ s, f x` is notation for `Finset.sum s f` (assuming `β` is an `AddCommMonoid`)
* `∏ x, f x` is notation for `Finset.prod Finset.univ f`
(assuming `α` is a `Fintype` and `β` is a `CommMonoid`)
* `∑ x, f x` is notation for `Finset.sum Finset.univ f`
(assuming `α` is a `Fintype` and `β` is an `AddCommMonoid`)
## Implementation Notes
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
-/
-- TODO
-- assert_not_exists AddCommMonoidWithOne
assert_not_exists MonoidWithZero
assert_not_exists MulAction
variable {ι κ α β γ : Type*}
open Fin Function
namespace Finset
/-- `∏ x ∈ s, f x` is the product of `f x`
as `x` ranges over the elements of the finite set `s`.
-/
@[to_additive "`∑ x ∈ s, f x` is the sum of `f x` as `x` ranges over the elements
of the finite set `s`."]
protected def prod [CommMonoid β] (s : Finset α) (f : α → β) : β :=
(s.1.map f).prod
#align finset.prod Finset.prod
#align finset.sum Finset.sum
@[to_additive (attr := simp)]
theorem prod_mk [CommMonoid β] (s : Multiset α) (hs : s.Nodup) (f : α → β) :
(⟨s, hs⟩ : Finset α).prod f = (s.map f).prod :=
rfl
#align finset.prod_mk Finset.prod_mk
#align finset.sum_mk Finset.sum_mk
@[to_additive (attr := simp)]
theorem prod_val [CommMonoid α] (s : Finset α) : s.1.prod = s.prod id := by
rw [Finset.prod, Multiset.map_id]
#align finset.prod_val Finset.prod_val
#align finset.sum_val Finset.sum_val
end Finset
library_note "operator precedence of big operators"/--
There is no established mathematical convention
for the operator precedence of big operators like `∏` and `∑`.
We will have to make a choice.
Online discussions, such as https://math.stackexchange.com/q/185538/30839
seem to suggest that `∏` and `∑` should have the same precedence,
and that this should be somewhere between `*` and `+`.
The latter have precedence levels `70` and `65` respectively,
and we therefore choose the level `67`.
In practice, this means that parentheses should be placed as follows:
```lean
∑ k ∈ K, (a k + b k) = ∑ k ∈ K, a k + ∑ k ∈ K, b k →
∏ k ∈ K, a k * b k = (∏ k ∈ K, a k) * (∏ k ∈ K, b k)
```
(Example taken from page 490 of Knuth's *Concrete Mathematics*.)
-/
namespace BigOperators
open Batteries.ExtendedBinder Lean Meta
-- TODO: contribute this modification back to `extBinder`
/-- A `bigOpBinder` is like an `extBinder` and has the form `x`, `x : ty`, or `x pred`
where `pred` is a `binderPred` like `< 2`.
Unlike `extBinder`, `x` is a term. -/
syntax bigOpBinder := term:max ((" : " term) <|> binderPred)?
/-- A BigOperator binder in parentheses -/
syntax bigOpBinderParenthesized := " (" bigOpBinder ")"
/-- A list of parenthesized binders -/
syntax bigOpBinderCollection := bigOpBinderParenthesized+
/-- A single (unparenthesized) binder, or a list of parenthesized binders -/
syntax bigOpBinders := bigOpBinderCollection <|> (ppSpace bigOpBinder)
/-- Collects additional binder/Finset pairs for the given `bigOpBinder`.
Note: this is not extensible at the moment, unlike the usual `bigOpBinder` expansions. -/
def processBigOpBinder (processed : (Array (Term × Term)))
(binder : TSyntax ``bigOpBinder) : MacroM (Array (Term × Term)) :=
set_option hygiene false in
withRef binder do
match binder with
| `(bigOpBinder| $x:term) =>
match x with
| `(($a + $b = $n)) => -- Maybe this is too cute.
return processed |>.push (← `(⟨$a, $b⟩), ← `(Finset.Nat.antidiagonal $n))
| _ => return processed |>.push (x, ← ``(Finset.univ))
| `(bigOpBinder| $x : $t) => return processed |>.push (x, ← ``((Finset.univ : Finset $t)))
| `(bigOpBinder| $x ∈ $s) => return processed |>.push (x, ← `(finset% $s))
| `(bigOpBinder| $x < $n) => return processed |>.push (x, ← `(Finset.Iio $n))
| `(bigOpBinder| $x ≤ $n) => return processed |>.push (x, ← `(Finset.Iic $n))
| `(bigOpBinder| $x > $n) => return processed |>.push (x, ← `(Finset.Ioi $n))
| `(bigOpBinder| $x ≥ $n) => return processed |>.push (x, ← `(Finset.Ici $n))
| _ => Macro.throwUnsupported
/-- Collects the binder/Finset pairs for the given `bigOpBinders`. -/
def processBigOpBinders (binders : TSyntax ``bigOpBinders) :
MacroM (Array (Term × Term)) :=
match binders with
| `(bigOpBinders| $b:bigOpBinder) => processBigOpBinder #[] b
| `(bigOpBinders| $[($bs:bigOpBinder)]*) => bs.foldlM processBigOpBinder #[]
| _ => Macro.throwUnsupported
/-- Collect the binderIdents into a `⟨...⟩` expression. -/
def bigOpBindersPattern (processed : (Array (Term × Term))) :
MacroM Term := do
let ts := processed.map Prod.fst
if ts.size == 1 then
return ts[0]!
else
`(⟨$ts,*⟩)
/-- Collect the terms into a product of sets. -/
def bigOpBindersProd (processed : (Array (Term × Term))) :
MacroM Term := do
if processed.isEmpty then
`((Finset.univ : Finset Unit))
else if processed.size == 1 then
return processed[0]!.2
else
processed.foldrM (fun s p => `(SProd.sprod $(s.2) $p)) processed.back.2
(start := processed.size - 1)
/--
- `∑ x, f x` is notation for `Finset.sum Finset.univ f`. It is the sum of `f x`,
where `x` ranges over the finite domain of `f`.
- `∑ x ∈ s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`,
where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance).
- `∑ x ∈ s with p x, f x` is notation for `Finset.sum (Finset.filter p s) f`.
- `∑ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.sum (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`.
These support destructuring, for example `∑ ⟨x, y⟩ ∈ s ×ˢ t, f x y`.
Notation: `"∑" bigOpBinders* ("with" term)? "," term` -/
syntax (name := bigsum) "∑ " bigOpBinders ("with " term)? ", " term:67 : term
/--
- `∏ x, f x` is notation for `Finset.prod Finset.univ f`. It is the product of `f x`,
where `x` ranges over the finite domain of `f`.
- `∏ x ∈ s, f x` is notation for `Finset.prod s f`. It is the product of `f x`,
where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance).
- `∏ x ∈ s with p x, f x` is notation for `Finset.prod (Finset.filter p s) f`.
- `∏ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.prod (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`.
These support destructuring, for example `∏ ⟨x, y⟩ ∈ s ×ˢ t, f x y`.
Notation: `"∏" bigOpBinders* ("with" term)? "," term` -/
syntax (name := bigprod) "∏ " bigOpBinders ("with " term)? ", " term:67 : term
macro_rules (kind := bigsum)
| `(∑ $bs:bigOpBinders $[with $p?]?, $v) => do
let processed ← processBigOpBinders bs
let x ← bigOpBindersPattern processed
let s ← bigOpBindersProd processed
match p? with
| some p => `(Finset.sum (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v))
| none => `(Finset.sum $s (fun $x ↦ $v))
macro_rules (kind := bigprod)
| `(∏ $bs:bigOpBinders $[with $p?]?, $v) => do
let processed ← processBigOpBinders bs
let x ← bigOpBindersPattern processed
let s ← bigOpBindersProd processed
match p? with
| some p => `(Finset.prod (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v))
| none => `(Finset.prod $s (fun $x ↦ $v))
/-- (Deprecated, use `∑ x ∈ s, f x`)
`∑ x in s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`,
where `x` ranges over the finite set `s`. -/
syntax (name := bigsumin) "∑ " extBinder " in " term ", " term:67 : term
macro_rules (kind := bigsumin)
| `(∑ $x:ident in $s, $r) => `(∑ $x:ident ∈ $s, $r)
| `(∑ $x:ident : $t in $s, $r) => `(∑ $x:ident ∈ ($s : Finset $t), $r)
/-- (Deprecated, use `∏ x ∈ s, f x`)
`∏ x in s, f x` is notation for `Finset.prod s f`. It is the product of `f x`,
where `x` ranges over the finite set `s`. -/
syntax (name := bigprodin) "∏ " extBinder " in " term ", " term:67 : term
macro_rules (kind := bigprodin)
| `(∏ $x:ident in $s, $r) => `(∏ $x:ident ∈ $s, $r)
| `(∏ $x:ident : $t in $s, $r) => `(∏ $x:ident ∈ ($s : Finset $t), $r)
open Lean Meta Parser.Term PrettyPrinter.Delaborator SubExpr
open Batteries.ExtendedBinder
/-- Delaborator for `Finset.prod`. The `pp.piBinderTypes` option controls whether
to show the domain type when the product is over `Finset.univ`. -/
@[delab app.Finset.prod] def delabFinsetProd : Delab :=
whenPPOption getPPNotation <| withOverApp 5 <| do
let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure
guard <| f.isLambda
let ppDomain ← getPPOption getPPPiBinderTypes
let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do
return (i, ← delab)
if s.isAppOfArity ``Finset.univ 2 then
let binder ←
if ppDomain then
let ty ← withNaryArg 0 delab
`(bigOpBinder| $(.mk i):ident : $ty)
else
`(bigOpBinder| $(.mk i):ident)
`(∏ $binder:bigOpBinder, $body)
else
let ss ← withNaryArg 3 <| delab
`(∏ $(.mk i):ident ∈ $ss, $body)
/-- Delaborator for `Finset.sum`. The `pp.piBinderTypes` option controls whether
to show the domain type when the sum is over `Finset.univ`. -/
@[delab app.Finset.sum] def delabFinsetSum : Delab :=
whenPPOption getPPNotation <| withOverApp 5 <| do
let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure
guard <| f.isLambda
let ppDomain ← getPPOption getPPPiBinderTypes
let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do
return (i, ← delab)
if s.isAppOfArity ``Finset.univ 2 then
let binder ←
if ppDomain then
let ty ← withNaryArg 0 delab
`(bigOpBinder| $(.mk i):ident : $ty)
else
`(bigOpBinder| $(.mk i):ident)
`(∑ $binder:bigOpBinder, $body)
else
let ss ← withNaryArg 3 <| delab
`(∑ $(.mk i):ident ∈ $ss, $body)
end BigOperators
namespace Finset
variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β}
@[to_additive]
theorem prod_eq_multiset_prod [CommMonoid β] (s : Finset α) (f : α → β) :
∏ x ∈ s, f x = (s.1.map f).prod :=
rfl
#align finset.prod_eq_multiset_prod Finset.prod_eq_multiset_prod
#align finset.sum_eq_multiset_sum Finset.sum_eq_multiset_sum
@[to_additive (attr := simp)]
lemma prod_map_val [CommMonoid β] (s : Finset α) (f : α → β) : (s.1.map f).prod = ∏ a ∈ s, f a :=
rfl
#align finset.prod_map_val Finset.prod_map_val
#align finset.sum_map_val Finset.sum_map_val
@[to_additive]
theorem prod_eq_fold [CommMonoid β] (s : Finset α) (f : α → β) :
∏ x ∈ s, f x = s.fold ((· * ·) : β → β → β) 1 f :=
rfl
#align finset.prod_eq_fold Finset.prod_eq_fold
#align finset.sum_eq_fold Finset.sum_eq_fold
@[simp]
theorem sum_multiset_singleton (s : Finset α) : (s.sum fun x => {x}) = s.val := by
simp only [sum_eq_multiset_sum, Multiset.sum_map_singleton]
#align finset.sum_multiset_singleton Finset.sum_multiset_singleton
end Finset
@[to_additive (attr := simp)]
theorem map_prod [CommMonoid β] [CommMonoid γ] {G : Type*} [FunLike G β γ] [MonoidHomClass G β γ]
(g : G) (f : α → β) (s : Finset α) : g (∏ x ∈ s, f x) = ∏ x ∈ s, g (f x) := by
simp only [Finset.prod_eq_multiset_prod, map_multiset_prod, Multiset.map_map]; rfl
#align map_prod map_prod
#align map_sum map_sum
@[to_additive]
theorem MonoidHom.coe_finset_prod [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) :
⇑(∏ x ∈ s, f x) = ∏ x ∈ s, ⇑(f x) :=
map_prod (MonoidHom.coeFn β γ) _ _
#align monoid_hom.coe_finset_prod MonoidHom.coe_finset_prod
#align add_monoid_hom.coe_finset_sum AddMonoidHom.coe_finset_sum
/-- See also `Finset.prod_apply`, with the same conclusion but with the weaker hypothesis
`f : α → β → γ` -/
@[to_additive (attr := simp)
"See also `Finset.sum_apply`, with the same conclusion but with the weaker hypothesis
`f : α → β → γ`"]
theorem MonoidHom.finset_prod_apply [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α)
(b : β) : (∏ x ∈ s, f x) b = ∏ x ∈ s, f x b :=
map_prod (MonoidHom.eval b) _ _
#align monoid_hom.finset_prod_apply MonoidHom.finset_prod_apply
#align add_monoid_hom.finset_sum_apply AddMonoidHom.finset_sum_apply
variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β}
namespace Finset
section CommMonoid
variable [CommMonoid β]
@[to_additive (attr := simp)]
theorem prod_empty : ∏ x ∈ ∅, f x = 1 :=
rfl
#align finset.prod_empty Finset.prod_empty
#align finset.sum_empty Finset.sum_empty
@[to_additive]
theorem prod_of_empty [IsEmpty α] (s : Finset α) : ∏ i ∈ s, f i = 1 := by
rw [eq_empty_of_isEmpty s, prod_empty]
#align finset.prod_of_empty Finset.prod_of_empty
#align finset.sum_of_empty Finset.sum_of_empty
@[to_additive (attr := simp)]
theorem prod_cons (h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x :=
fold_cons h
#align finset.prod_cons Finset.prod_cons
#align finset.sum_cons Finset.sum_cons
@[to_additive (attr := simp)]
theorem prod_insert [DecidableEq α] : a ∉ s → ∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x :=
fold_insert
#align finset.prod_insert Finset.prod_insert
#align finset.sum_insert Finset.sum_insert
/-- The product of `f` over `insert a s` is the same as
the product over `s`, as long as `a` is in `s` or `f a = 1`. -/
@[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `a` is in `s` or `f a = 0`."]
theorem prod_insert_of_eq_one_if_not_mem [DecidableEq α] (h : a ∉ s → f a = 1) :
∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := by
by_cases hm : a ∈ s
· simp_rw [insert_eq_of_mem hm]
· rw [prod_insert hm, h hm, one_mul]
#align finset.prod_insert_of_eq_one_if_not_mem Finset.prod_insert_of_eq_one_if_not_mem
#align finset.sum_insert_of_eq_zero_if_not_mem Finset.sum_insert_of_eq_zero_if_not_mem
/-- The product of `f` over `insert a s` is the same as
the product over `s`, as long as `f a = 1`. -/
@[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `f a = 0`."]
theorem prod_insert_one [DecidableEq α] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x :=
prod_insert_of_eq_one_if_not_mem fun _ => h
#align finset.prod_insert_one Finset.prod_insert_one
#align finset.sum_insert_zero Finset.sum_insert_zero
@[to_additive]
theorem prod_insert_div {M : Type*} [CommGroup M] [DecidableEq α] (ha : a ∉ s) {f : α → M} :
(∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x := by simp [ha]
@[to_additive (attr := simp)]
theorem prod_singleton (f : α → β) (a : α) : ∏ x ∈ singleton a, f x = f a :=
Eq.trans fold_singleton <| mul_one _
#align finset.prod_singleton Finset.prod_singleton
#align finset.sum_singleton Finset.sum_singleton
@[to_additive]
theorem prod_pair [DecidableEq α] {a b : α} (h : a ≠ b) :
(∏ x ∈ ({a, b} : Finset α), f x) = f a * f b := by
rw [prod_insert (not_mem_singleton.2 h), prod_singleton]
#align finset.prod_pair Finset.prod_pair
#align finset.sum_pair Finset.sum_pair
@[to_additive (attr := simp)]
theorem prod_const_one : (∏ _x ∈ s, (1 : β)) = 1 := by
simp only [Finset.prod, Multiset.map_const', Multiset.prod_replicate, one_pow]
#align finset.prod_const_one Finset.prod_const_one
#align finset.sum_const_zero Finset.sum_const_zero
@[to_additive (attr := simp)]
theorem prod_image [DecidableEq α] {s : Finset γ} {g : γ → α} :
(∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x) :=
fold_image
#align finset.prod_image Finset.prod_image
#align finset.sum_image Finset.sum_image
@[to_additive (attr := simp)]
theorem prod_map (s : Finset α) (e : α ↪ γ) (f : γ → β) :
∏ x ∈ s.map e, f x = ∏ x ∈ s, f (e x) := by
rw [Finset.prod, Finset.map_val, Multiset.map_map]; rfl
#align finset.prod_map Finset.prod_map
#align finset.sum_map Finset.sum_map
@[to_additive]
lemma prod_attach (s : Finset α) (f : α → β) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x := by
classical rw [← prod_image Subtype.coe_injective.injOn, attach_image_val]
#align finset.prod_attach Finset.prod_attach
#align finset.sum_attach Finset.sum_attach
@[to_additive (attr := congr)]
theorem prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g := by
rw [h]; exact fold_congr
#align finset.prod_congr Finset.prod_congr
#align finset.sum_congr Finset.sum_congr
@[to_additive]
theorem prod_eq_one {f : α → β} {s : Finset α} (h : ∀ x ∈ s, f x = 1) : ∏ x ∈ s, f x = 1 :=
calc
∏ x ∈ s, f x = ∏ _x ∈ s, 1 := Finset.prod_congr rfl h
_ = 1 := Finset.prod_const_one
#align finset.prod_eq_one Finset.prod_eq_one
#align finset.sum_eq_zero Finset.sum_eq_zero
@[to_additive]
theorem prod_disjUnion (h) :
∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
refine Eq.trans ?_ (fold_disjUnion h)
rw [one_mul]
rfl
#align finset.prod_disj_union Finset.prod_disjUnion
#align finset.sum_disj_union Finset.sum_disjUnion
@[to_additive]
theorem prod_disjiUnion (s : Finset ι) (t : ι → Finset α) (h) :
∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x := by
refine Eq.trans ?_ (fold_disjiUnion h)
dsimp [Finset.prod, Multiset.prod, Multiset.fold, Finset.disjUnion, Finset.fold]
congr
exact prod_const_one.symm
#align finset.prod_disj_Union Finset.prod_disjiUnion
#align finset.sum_disj_Union Finset.sum_disjiUnion
@[to_additive]
theorem prod_union_inter [DecidableEq α] :
(∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x :=
fold_union_inter
#align finset.prod_union_inter Finset.prod_union_inter
#align finset.sum_union_inter Finset.sum_union_inter
@[to_additive]
theorem prod_union [DecidableEq α] (h : Disjoint s₁ s₂) :
∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
rw [← prod_union_inter, disjoint_iff_inter_eq_empty.mp h]; exact (mul_one _).symm
#align finset.prod_union Finset.prod_union
#align finset.sum_union Finset.sum_union
@[to_additive]
theorem prod_filter_mul_prod_filter_not
(s : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : α → β) :
(∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, f x = ∏ x ∈ s, f x := by
have := Classical.decEq α
rw [← prod_union (disjoint_filter_filter_neg s s p), filter_union_filter_neg_eq]
#align finset.prod_filter_mul_prod_filter_not Finset.prod_filter_mul_prod_filter_not
#align finset.sum_filter_add_sum_filter_not Finset.sum_filter_add_sum_filter_not
section ToList
@[to_additive (attr := simp)]
theorem prod_to_list (s : Finset α) (f : α → β) : (s.toList.map f).prod = s.prod f := by
rw [Finset.prod, ← Multiset.prod_coe, ← Multiset.map_coe, Finset.coe_toList]
#align finset.prod_to_list Finset.prod_to_list
#align finset.sum_to_list Finset.sum_to_list
end ToList
@[to_additive]
theorem _root_.Equiv.Perm.prod_comp (σ : Equiv.Perm α) (s : Finset α) (f : α → β)
(hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x)) = ∏ x ∈ s, f x := by
convert (prod_map s σ.toEmbedding f).symm
exact (map_perm hs).symm
#align equiv.perm.prod_comp Equiv.Perm.prod_comp
#align equiv.perm.sum_comp Equiv.Perm.sum_comp
@[to_additive]
theorem _root_.Equiv.Perm.prod_comp' (σ : Equiv.Perm α) (s : Finset α) (f : α → α → β)
(hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x) x) = ∏ x ∈ s, f x (σ.symm x) := by
convert σ.prod_comp s (fun x => f x (σ.symm x)) hs
rw [Equiv.symm_apply_apply]
#align equiv.perm.prod_comp' Equiv.Perm.prod_comp'
#align equiv.perm.sum_comp' Equiv.Perm.sum_comp'
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets
of `s`, and over all subsets of `s` to which one adds `x`."]
lemma prod_powerset_insert [DecidableEq α] (ha : a ∉ s) (f : Finset α → β) :
∏ t ∈ (insert a s).powerset, f t =
(∏ t ∈ s.powerset, f t) * ∏ t ∈ s.powerset, f (insert a t) := by
rw [powerset_insert, prod_union, prod_image]
· exact insert_erase_invOn.2.injOn.mono fun t ht ↦ not_mem_mono (mem_powerset.1 ht) ha
· aesop (add simp [disjoint_left, insert_subset_iff])
#align finset.prod_powerset_insert Finset.prod_powerset_insert
#align finset.sum_powerset_insert Finset.sum_powerset_insert
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets
of `s`, and over all subsets of `s` to which one adds `x`."]
lemma prod_powerset_cons (ha : a ∉ s) (f : Finset α → β) :
∏ t ∈ (s.cons a ha).powerset, f t = (∏ t ∈ s.powerset, f t) *
∏ t ∈ s.powerset.attach, f (cons a t $ not_mem_mono (mem_powerset.1 t.2) ha) := by
classical
simp_rw [cons_eq_insert]
rw [prod_powerset_insert ha, prod_attach _ fun t ↦ f (insert a t)]
/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`. -/
@[to_additive "A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`"]
lemma prod_powerset (s : Finset α) (f : Finset α → β) :
∏ t ∈ powerset s, f t = ∏ j ∈ range (card s + 1), ∏ t ∈ powersetCard j s, f t := by
rw [powerset_card_disjiUnion, prod_disjiUnion]
#align finset.prod_powerset Finset.prod_powerset
#align finset.sum_powerset Finset.sum_powerset
end CommMonoid
end Finset
section
open Finset
variable [Fintype α] [CommMonoid β]
@[to_additive]
theorem IsCompl.prod_mul_prod {s t : Finset α} (h : IsCompl s t) (f : α → β) :
(∏ i ∈ s, f i) * ∏ i ∈ t, f i = ∏ i, f i :=
(Finset.prod_disjUnion h.disjoint).symm.trans <| by
classical rw [Finset.disjUnion_eq_union, ← Finset.sup_eq_union, h.sup_eq_top]; rfl
#align is_compl.prod_mul_prod IsCompl.prod_mul_prod
#align is_compl.sum_add_sum IsCompl.sum_add_sum
end
namespace Finset
section CommMonoid
variable [CommMonoid β]
/-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product.
For a version expressed with subtypes, see `Fintype.prod_subtype_mul_prod_subtype`. -/
@[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum.
For a version expressed with subtypes, see `Fintype.sum_subtype_add_sum_subtype`. "]
theorem prod_mul_prod_compl [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) :
(∏ i ∈ s, f i) * ∏ i ∈ sᶜ, f i = ∏ i, f i :=
IsCompl.prod_mul_prod isCompl_compl f
#align finset.prod_mul_prod_compl Finset.prod_mul_prod_compl
#align finset.sum_add_sum_compl Finset.sum_add_sum_compl
@[to_additive]
theorem prod_compl_mul_prod [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) :
(∏ i ∈ sᶜ, f i) * ∏ i ∈ s, f i = ∏ i, f i :=
(@isCompl_compl _ s _).symm.prod_mul_prod f
#align finset.prod_compl_mul_prod Finset.prod_compl_mul_prod
#align finset.sum_compl_add_sum Finset.sum_compl_add_sum
@[to_additive]
theorem prod_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) :
(∏ x ∈ s₂ \ s₁, f x) * ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := by
rw [← prod_union sdiff_disjoint, sdiff_union_of_subset h]
#align finset.prod_sdiff Finset.prod_sdiff
#align finset.sum_sdiff Finset.sum_sdiff
@[to_additive]
theorem prod_subset_one_on_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ s₂ \ s₁, g x = 1)
(hfg : ∀ x ∈ s₁, f x = g x) : ∏ i ∈ s₁, f i = ∏ i ∈ s₂, g i := by
rw [← prod_sdiff h, prod_eq_one hg, one_mul]
exact prod_congr rfl hfg
#align finset.prod_subset_one_on_sdiff Finset.prod_subset_one_on_sdiff
#align finset.sum_subset_zero_on_sdiff Finset.sum_subset_zero_on_sdiff
@[to_additive]
theorem prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) :
∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x :=
haveI := Classical.decEq α
prod_subset_one_on_sdiff h (by simpa) fun _ _ => rfl
#align finset.prod_subset Finset.prod_subset
#align finset.sum_subset Finset.sum_subset
@[to_additive (attr := simp)]
theorem prod_disj_sum (s : Finset α) (t : Finset γ) (f : Sum α γ → β) :
∏ x ∈ s.disjSum t, f x = (∏ x ∈ s, f (Sum.inl x)) * ∏ x ∈ t, f (Sum.inr x) := by
rw [← map_inl_disjUnion_map_inr, prod_disjUnion, prod_map, prod_map]
rfl
#align finset.prod_disj_sum Finset.prod_disj_sum
#align finset.sum_disj_sum Finset.sum_disj_sum
@[to_additive]
theorem prod_sum_elim (s : Finset α) (t : Finset γ) (f : α → β) (g : γ → β) :
∏ x ∈ s.disjSum t, Sum.elim f g x = (∏ x ∈ s, f x) * ∏ x ∈ t, g x := by simp
#align finset.prod_sum_elim Finset.prod_sum_elim
#align finset.sum_sum_elim Finset.sum_sum_elim
@[to_additive]
theorem prod_biUnion [DecidableEq α] {s : Finset γ} {t : γ → Finset α}
(hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i := by
rw [← disjiUnion_eq_biUnion _ _ hs, prod_disjiUnion]
#align finset.prod_bUnion Finset.prod_biUnion
#align finset.sum_bUnion Finset.sum_biUnion
/-- Product over a sigma type equals the product of fiberwise products. For rewriting
in the reverse direction, use `Finset.prod_sigma'`. -/
@[to_additive "Sum over a sigma type equals the sum of fiberwise sums. For rewriting
in the reverse direction, use `Finset.sum_sigma'`"]
theorem prod_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : Sigma σ → β) :
∏ x ∈ s.sigma t, f x = ∏ a ∈ s, ∏ s ∈ t a, f ⟨a, s⟩ := by
simp_rw [← disjiUnion_map_sigma_mk, prod_disjiUnion, prod_map, Function.Embedding.sigmaMk_apply]
#align finset.prod_sigma Finset.prod_sigma
#align finset.sum_sigma Finset.sum_sigma
@[to_additive]
theorem prod_sigma' {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : ∀ a, σ a → β) :
(∏ a ∈ s, ∏ s ∈ t a, f a s) = ∏ x ∈ s.sigma t, f x.1 x.2 :=
Eq.symm <| prod_sigma s t fun x => f x.1 x.2
#align finset.prod_sigma' Finset.prod_sigma'
#align finset.sum_sigma' Finset.sum_sigma'
section bij
variable {ι κ α : Type*} [CommMonoid α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α}
/-- Reorder a product.
The difference with `Finset.prod_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.prod_nbij` is that the bijection is allowed to use membership of the
domain of the product, rather than being a non-dependent function. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.sum_nbij` is that the bijection is allowed to use membership of the
domain of the sum, rather than being a non-dependent function."]
theorem prod_bij (i : ∀ a ∈ s, κ) (hi : ∀ a ha, i a ha ∈ t)
(i_inj : ∀ a₁ ha₁ a₂ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, ∃ a ha, i a ha = b) (h : ∀ a ha, f a = g (i a ha)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x :=
congr_arg Multiset.prod (Multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi i_inj i_surj h)
#align finset.prod_bij Finset.prod_bij
#align finset.sum_bij Finset.sum_bij
/-- Reorder a product.
The difference with `Finset.prod_bij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.prod_nbij'` is that the bijection and its inverse are allowed to use
membership of the domains of the products, rather than being non-dependent functions. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
The difference with `Finset.sum_nbij'` is that the bijection and its inverse are allowed to use
membership of the domains of the sums, rather than being non-dependent functions."]
theorem prod_bij' (i : ∀ a ∈ s, κ) (j : ∀ a ∈ t, ι) (hi : ∀ a ha, i a ha ∈ t)
(hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a)
(right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) (h : ∀ a ha, f a = g (i a ha)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x := by
refine prod_bij i hi (fun a1 h1 a2 h2 eq ↦ ?_) (fun b hb ↦ ⟨_, hj b hb, right_inv b hb⟩) h
rw [← left_inv a1 h1, ← left_inv a2 h2]
simp only [eq]
#align finset.prod_bij' Finset.prod_bij'
#align finset.sum_bij' Finset.sum_bij'
/-- Reorder a product.
The difference with `Finset.prod_nbij'` is that the bijection is specified as a surjective
injection, rather than by an inverse function.
The difference with `Finset.prod_bij` is that the bijection is a non-dependent function, rather than
being allowed to use membership of the domain of the product. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_nbij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.sum_bij` is that the bijection is a non-dependent function, rather than
being allowed to use membership of the domain of the sum."]
lemma prod_nbij (i : ι → κ) (hi : ∀ a ∈ s, i a ∈ t) (i_inj : (s : Set ι).InjOn i)
(i_surj : (s : Set ι).SurjOn i t) (h : ∀ a ∈ s, f a = g (i a)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x :=
prod_bij (fun a _ ↦ i a) hi i_inj (by simpa using i_surj) h
/-- Reorder a product.
The difference with `Finset.prod_nbij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.prod_bij'` is that the bijection and its inverse are non-dependent
functions, rather than being allowed to use membership of the domains of the products.
The difference with `Finset.prod_equiv` is that bijectivity is only required to hold on the domains
of the products, rather than on the entire types.
-/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_nbij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.sum_bij'` is that the bijection and its inverse are non-dependent
functions, rather than being allowed to use membership of the domains of the sums.
The difference with `Finset.sum_equiv` is that bijectivity is only required to hold on the domains
of the sums, rather than on the entire types."]
lemma prod_nbij' (i : ι → κ) (j : κ → ι) (hi : ∀ a ∈ s, i a ∈ t) (hj : ∀ a ∈ t, j a ∈ s)
(left_inv : ∀ a ∈ s, j (i a) = a) (right_inv : ∀ a ∈ t, i (j a) = a)
(h : ∀ a ∈ s, f a = g (i a)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x :=
prod_bij' (fun a _ ↦ i a) (fun b _ ↦ j b) hi hj left_inv right_inv h
/-- Specialization of `Finset.prod_nbij'` that automatically fills in most arguments.
See `Fintype.prod_equiv` for the version where `s` and `t` are `univ`. -/
@[to_additive "`Specialization of `Finset.sum_nbij'` that automatically fills in most arguments.
See `Fintype.sum_equiv` for the version where `s` and `t` are `univ`."]
lemma prod_equiv (e : ι ≃ κ) (hst : ∀ i, i ∈ s ↔ e i ∈ t) (hfg : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ i ∈ t, g i := by refine prod_nbij' e e.symm ?_ ?_ ?_ ?_ hfg <;> simp [hst]
#align finset.equiv.prod_comp_finset Finset.prod_equiv
#align finset.equiv.sum_comp_finset Finset.sum_equiv
/-- Specialization of `Finset.prod_bij` that automatically fills in most arguments.
See `Fintype.prod_bijective` for the version where `s` and `t` are `univ`. -/
@[to_additive "`Specialization of `Finset.sum_bij` that automatically fills in most arguments.
See `Fintype.sum_bijective` for the version where `s` and `t` are `univ`."]
lemma prod_bijective (e : ι → κ) (he : e.Bijective) (hst : ∀ i, i ∈ s ↔ e i ∈ t)
(hfg : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ i ∈ t, g i := prod_equiv (.ofBijective e he) hst hfg
@[to_additive]
lemma prod_of_injOn (e : ι → κ) (he : Set.InjOn e s) (hest : Set.MapsTo e s t)
(h' : ∀ i ∈ t, i ∉ e '' s → g i = 1) (h : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ j ∈ t, g j := by
classical
exact (prod_nbij e (fun a ↦ mem_image_of_mem e) he (by simp [Set.surjOn_image]) h).trans <|
prod_subset (image_subset_iff.2 hest) <| by simpa using h'
variable [DecidableEq κ]
@[to_additive]
lemma prod_fiberwise_eq_prod_filter (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : ι → α) :
∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f i := by
rw [← prod_disjiUnion, disjiUnion_filter_eq]
@[to_additive]
lemma prod_fiberwise_eq_prod_filter' (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : κ → α) :
∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f (g i) := by
calc
_ = ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f (g i) :=
prod_congr rfl fun j _ ↦ prod_congr rfl fun i hi ↦ by rw [(mem_filter.1 hi).2]
_ = _ := prod_fiberwise_eq_prod_filter _ _ _ _
@[to_additive]
lemma prod_fiberwise_of_maps_to {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : ι → α) :
∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i := by
rw [← prod_disjiUnion, disjiUnion_filter_eq_of_maps_to h]
#align finset.prod_fiberwise_of_maps_to Finset.prod_fiberwise_of_maps_to
#align finset.sum_fiberwise_of_maps_to Finset.sum_fiberwise_of_maps_to
@[to_additive]
lemma prod_fiberwise_of_maps_to' {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : κ → α) :
∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) := by
calc
_ = ∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f (g x) :=
prod_congr rfl fun y _ ↦ prod_congr rfl fun x hx ↦ by rw [(mem_filter.1 hx).2]
_ = _ := prod_fiberwise_of_maps_to h _
variable [Fintype κ]
@[to_additive]
lemma prod_fiberwise (s : Finset ι) (g : ι → κ) (f : ι → α) :
∏ j, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i :=
prod_fiberwise_of_maps_to (fun _ _ ↦ mem_univ _) _
#align finset.prod_fiberwise Finset.prod_fiberwise
#align finset.sum_fiberwise Finset.sum_fiberwise
@[to_additive]
lemma prod_fiberwise' (s : Finset ι) (g : ι → κ) (f : κ → α) :
∏ j, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) :=
prod_fiberwise_of_maps_to' (fun _ _ ↦ mem_univ _) _
end bij
/-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`.
`univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ
in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
`Fintype.piFinset t` is a `Finset (Π a, t a)`. -/
@[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over
`Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`,
but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
`Fintype.piFinset t` is a `Finset (Π a, t a)`."]
lemma prod_univ_pi [DecidableEq ι] [Fintype ι] {κ : ι → Type*} (t : ∀ i, Finset (κ i))
(f : (∀ i ∈ (univ : Finset ι), κ i) → β) :
∏ x ∈ univ.pi t, f x = ∏ x ∈ Fintype.piFinset t, f fun a _ ↦ x a := by
apply prod_nbij' (fun x i ↦ x i $ mem_univ _) (fun x i _ ↦ x i) <;> simp
#align finset.prod_univ_pi Finset.prod_univ_pi
#align finset.sum_univ_pi Finset.sum_univ_pi
@[to_additive (attr := simp)]
lemma prod_diag [DecidableEq α] (s : Finset α) (f : α × α → β) :
∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i) := by
apply prod_nbij' Prod.fst (fun i ↦ (i, i)) <;> simp
@[to_additive]
theorem prod_finset_product (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ × α → β} :
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (c, a) := by
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.1, p.2))
apply prod_equiv (Equiv.sigmaEquivProd _ _).symm <;> simp [h]
#align finset.prod_finset_product Finset.prod_finset_product
#align finset.sum_finset_product Finset.sum_finset_product
@[to_additive]
theorem prod_finset_product' (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ → α → β} :
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f c a :=
prod_finset_product r s t h
#align finset.prod_finset_product' Finset.prod_finset_product'
#align finset.sum_finset_product' Finset.sum_finset_product'
@[to_additive]
theorem prod_finset_product_right (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α × γ → β} :
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (a, c) := by
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.2, p.1))
apply prod_equiv ((Equiv.prodComm _ _).trans (Equiv.sigmaEquivProd _ _).symm) <;> simp [h]
#align finset.prod_finset_product_right Finset.prod_finset_product_right
#align finset.sum_finset_product_right Finset.sum_finset_product_right
@[to_additive]
theorem prod_finset_product_right' (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α → γ → β} :
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f a c :=
prod_finset_product_right r s t h
#align finset.prod_finset_product_right' Finset.prod_finset_product_right'
#align finset.sum_finset_product_right' Finset.sum_finset_product_right'
@[to_additive]
theorem prod_image' [DecidableEq α] {s : Finset γ} {g : γ → α} (h : γ → β)
(eq : ∀ c ∈ s, f (g c) = ∏ x ∈ s.filter fun c' => g c' = g c, h x) :
∏ x ∈ s.image g, f x = ∏ x ∈ s, h x :=
calc
∏ x ∈ s.image g, f x = ∏ x ∈ s.image g, ∏ x ∈ s.filter fun c' => g c' = x, h x :=
(prod_congr rfl) fun _x hx =>
let ⟨c, hcs, hc⟩ := mem_image.1 hx
hc ▸ eq c hcs
_ = ∏ x ∈ s, h x := prod_fiberwise_of_maps_to (fun _x => mem_image_of_mem g) _
#align finset.prod_image' Finset.prod_image'
#align finset.sum_image' Finset.sum_image'
@[to_additive]
theorem prod_mul_distrib : ∏ x ∈ s, f x * g x = (∏ x ∈ s, f x) * ∏ x ∈ s, g x :=
Eq.trans (by rw [one_mul]; rfl) fold_op_distrib
#align finset.prod_mul_distrib Finset.prod_mul_distrib
#align finset.sum_add_distrib Finset.sum_add_distrib
@[to_additive]
lemma prod_mul_prod_comm (f g h i : α → β) :
(∏ a ∈ s, f a * g a) * ∏ a ∈ s, h a * i a = (∏ a ∈ s, f a * h a) * ∏ a ∈ s, g a * i a := by
simp_rw [prod_mul_distrib, mul_mul_mul_comm]
@[to_additive]
theorem prod_product {s : Finset γ} {t : Finset α} {f : γ × α → β} :
∏ x ∈ s ×ˢ t, f x = ∏ x ∈ s, ∏ y ∈ t, f (x, y) :=
prod_finset_product (s ×ˢ t) s (fun _a => t) fun _p => mem_product
#align finset.prod_product Finset.prod_product
#align finset.sum_product Finset.sum_product
/-- An uncurried version of `Finset.prod_product`. -/
@[to_additive "An uncurried version of `Finset.sum_product`"]
theorem prod_product' {s : Finset γ} {t : Finset α} {f : γ → α → β} :
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ x ∈ s, ∏ y ∈ t, f x y :=
prod_product
#align finset.prod_product' Finset.prod_product'
#align finset.sum_product' Finset.sum_product'
@[to_additive]
theorem prod_product_right {s : Finset γ} {t : Finset α} {f : γ × α → β} :
∏ x ∈ s ×ˢ t, f x = ∏ y ∈ t, ∏ x ∈ s, f (x, y) :=
prod_finset_product_right (s ×ˢ t) t (fun _a => s) fun _p => mem_product.trans and_comm
#align finset.prod_product_right Finset.prod_product_right
#align finset.sum_product_right Finset.sum_product_right
/-- An uncurried version of `Finset.prod_product_right`. -/
@[to_additive "An uncurried version of `Finset.sum_product_right`"]
theorem prod_product_right' {s : Finset γ} {t : Finset α} {f : γ → α → β} :
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ y ∈ t, ∏ x ∈ s, f x y :=
prod_product_right
#align finset.prod_product_right' Finset.prod_product_right'
#align finset.sum_product_right' Finset.sum_product_right'
/-- Generalization of `Finset.prod_comm` to the case when the inner `Finset`s depend on the outer
variable. -/
@[to_additive "Generalization of `Finset.sum_comm` to the case when the inner `Finset`s depend on
the outer variable."]
theorem prod_comm' {s : Finset γ} {t : γ → Finset α} {t' : Finset α} {s' : α → Finset γ}
(h : ∀ x y, x ∈ s ∧ y ∈ t x ↔ x ∈ s' y ∧ y ∈ t') {f : γ → α → β} :
(∏ x ∈ s, ∏ y ∈ t x, f x y) = ∏ y ∈ t', ∏ x ∈ s' y, f x y := by
classical
have : ∀ z : γ × α, (z ∈ s.biUnion fun x => (t x).map <| Function.Embedding.sectr x _) ↔
z.1 ∈ s ∧ z.2 ∈ t z.1 := by
rintro ⟨x, y⟩
simp only [mem_biUnion, mem_map, Function.Embedding.sectr_apply, Prod.mk.injEq,
exists_eq_right, ← and_assoc]
exact
(prod_finset_product' _ _ _ this).symm.trans
((prod_finset_product_right' _ _ _) fun ⟨x, y⟩ => (this _).trans ((h x y).trans and_comm))
#align finset.prod_comm' Finset.prod_comm'
#align finset.sum_comm' Finset.sum_comm'
@[to_additive]
theorem prod_comm {s : Finset γ} {t : Finset α} {f : γ → α → β} :
(∏ x ∈ s, ∏ y ∈ t, f x y) = ∏ y ∈ t, ∏ x ∈ s, f x y :=
prod_comm' fun _ _ => Iff.rfl
#align finset.prod_comm Finset.prod_comm
#align finset.sum_comm Finset.sum_comm
@[to_additive]
theorem prod_hom_rel [CommMonoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : Finset α}
(h₁ : r 1 1) (h₂ : ∀ a b c, r b c → r (f a * b) (g a * c)) :
r (∏ x ∈ s, f x) (∏ x ∈ s, g x) := by
delta Finset.prod
apply Multiset.prod_hom_rel <;> assumption
#align finset.prod_hom_rel Finset.prod_hom_rel
#align finset.sum_hom_rel Finset.sum_hom_rel
@[to_additive]
theorem prod_filter_of_ne {p : α → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) :
∏ x ∈ s.filter p, f x = ∏ x ∈ s, f x :=
(prod_subset (filter_subset _ _)) fun x => by
classical
rw [not_imp_comm, mem_filter]
exact fun h₁ h₂ => ⟨h₁, by simpa using hp _ h₁ h₂⟩
#align finset.prod_filter_of_ne Finset.prod_filter_of_ne
#align finset.sum_filter_of_ne Finset.sum_filter_of_ne
-- If we use `[DecidableEq β]` here, some rewrites fail because they find a wrong `Decidable`
-- instance first; `{∀ x, Decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one`
@[to_additive]
theorem prod_filter_ne_one (s : Finset α) [∀ x, Decidable (f x ≠ 1)] :
∏ x ∈ s.filter fun x => f x ≠ 1, f x = ∏ x ∈ s, f x :=
prod_filter_of_ne fun _ _ => id
#align finset.prod_filter_ne_one Finset.prod_filter_ne_one
#align finset.sum_filter_ne_zero Finset.sum_filter_ne_zero
@[to_additive]
theorem prod_filter (p : α → Prop) [DecidablePred p] (f : α → β) :
∏ a ∈ s.filter p, f a = ∏ a ∈ s, if p a then f a else 1 :=
calc
∏ a ∈ s.filter p, f a = ∏ a ∈ s.filter p, if p a then f a else 1 :=
prod_congr rfl fun a h => by rw [if_pos]; simpa using (mem_filter.1 h).2
_ = ∏ a ∈ s, if p a then f a else 1 := by
{ refine prod_subset (filter_subset _ s) fun x hs h => ?_
rw [mem_filter, not_and] at h
exact if_neg (by simpa using h hs) }
#align finset.prod_filter Finset.prod_filter
#align finset.sum_filter Finset.sum_filter
@[to_additive]
theorem prod_eq_single_of_mem {s : Finset α} {f : α → β} (a : α) (h : a ∈ s)
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : ∏ x ∈ s, f x = f a := by
haveI := Classical.decEq α
calc
∏ x ∈ s, f x = ∏ x ∈ {a}, f x := by
{ refine (prod_subset ?_ ?_).symm
· intro _ H
rwa [mem_singleton.1 H]
· simpa only [mem_singleton] }
_ = f a := prod_singleton _ _
#align finset.prod_eq_single_of_mem Finset.prod_eq_single_of_mem
#align finset.sum_eq_single_of_mem Finset.sum_eq_single_of_mem
@[to_additive]
theorem prod_eq_single {s : Finset α} {f : α → β} (a : α) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1)
(h₁ : a ∉ s → f a = 1) : ∏ x ∈ s, f x = f a :=
haveI := Classical.decEq α
by_cases (prod_eq_single_of_mem a · h₀) fun this =>
(prod_congr rfl fun b hb => h₀ b hb <| by rintro rfl; exact this hb).trans <|
prod_const_one.trans (h₁ this).symm
#align finset.prod_eq_single Finset.prod_eq_single
#align finset.sum_eq_single Finset.sum_eq_single
@[to_additive]
lemma prod_union_eq_left [DecidableEq α] (hs : ∀ a ∈ s₂, a ∉ s₁ → f a = 1) :
∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₁, f a :=
Eq.symm <|
prod_subset subset_union_left fun _a ha ha' ↦ hs _ ((mem_union.1 ha).resolve_left ha') ha'
@[to_additive]
lemma prod_union_eq_right [DecidableEq α] (hs : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) :
∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₂, f a := by rw [union_comm, prod_union_eq_left hs]
@[to_additive]
theorem prod_eq_mul_of_mem {s : Finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s)
(hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : ∏ x ∈ s, f x = f a * f b := by
haveI := Classical.decEq α; let s' := ({a, b} : Finset α)
have hu : s' ⊆ s := by
refine insert_subset_iff.mpr ?_
apply And.intro ha
apply singleton_subset_iff.mpr hb
have hf : ∀ c ∈ s, c ∉ s' → f c = 1 := by
intro c hc hcs
apply h₀ c hc
apply not_or.mp
intro hab
apply hcs
rw [mem_insert, mem_singleton]
exact hab
rw [← prod_subset hu hf]
exact Finset.prod_pair hn
#align finset.prod_eq_mul_of_mem Finset.prod_eq_mul_of_mem
#align finset.sum_eq_add_of_mem Finset.sum_eq_add_of_mem
@[to_additive]
theorem prod_eq_mul {s : Finset α} {f : α → β} (a b : α) (hn : a ≠ b)
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) :
∏ x ∈ s, f x = f a * f b := by
haveI := Classical.decEq α; by_cases h₁ : a ∈ s <;> by_cases h₂ : b ∈ s
· exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀
· rw [hb h₂, mul_one]
apply prod_eq_single_of_mem a h₁
exact fun c hc hca => h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩
· rw [ha h₁, one_mul]
apply prod_eq_single_of_mem b h₂
exact fun c hc hcb => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩
· rw [ha h₁, hb h₂, mul_one]
exact
_root_.trans
(prod_congr rfl fun c hc =>
h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩)
prod_const_one
#align finset.prod_eq_mul Finset.prod_eq_mul
#align finset.sum_eq_add Finset.sum_eq_add
-- Porting note: simpNF linter complains that LHS doesn't simplify, but it does
/-- A product over `s.subtype p` equals one over `s.filter p`. -/
@[to_additive (attr := simp, nolint simpNF)
"A sum over `s.subtype p` equals one over `s.filter p`."]
theorem prod_subtype_eq_prod_filter (f : α → β) {p : α → Prop} [DecidablePred p] :
∏ x ∈ s.subtype p, f x = ∏ x ∈ s.filter p, f x := by
conv_lhs => erw [← prod_map (s.subtype p) (Function.Embedding.subtype _) f]
exact prod_congr (subtype_map _) fun x _hx => rfl
#align finset.prod_subtype_eq_prod_filter Finset.prod_subtype_eq_prod_filter
#align finset.sum_subtype_eq_sum_filter Finset.sum_subtype_eq_sum_filter
/-- If all elements of a `Finset` satisfy the predicate `p`, a product
over `s.subtype p` equals that product over `s`. -/
@[to_additive "If all elements of a `Finset` satisfy the predicate `p`, a sum
over `s.subtype p` equals that sum over `s`."]
theorem prod_subtype_of_mem (f : α → β) {p : α → Prop} [DecidablePred p] (h : ∀ x ∈ s, p x) :
∏ x ∈ s.subtype p, f x = ∏ x ∈ s, f x := by
rw [prod_subtype_eq_prod_filter, filter_true_of_mem]
simpa using h
#align finset.prod_subtype_of_mem Finset.prod_subtype_of_mem
#align finset.sum_subtype_of_mem Finset.sum_subtype_of_mem
/-- A product of a function over a `Finset` in a subtype equals a
product in the main type of a function that agrees with the first
function on that `Finset`. -/
@[to_additive "A sum of a function over a `Finset` in a subtype equals a
sum in the main type of a function that agrees with the first
function on that `Finset`."]
theorem prod_subtype_map_embedding {p : α → Prop} {s : Finset { x // p x }} {f : { x // p x } → β}
{g : α → β} (h : ∀ x : { x // p x }, x ∈ s → g x = f x) :
(∏ x ∈ s.map (Function.Embedding.subtype _), g x) = ∏ x ∈ s, f x := by
rw [Finset.prod_map]
exact Finset.prod_congr rfl h
#align finset.prod_subtype_map_embedding Finset.prod_subtype_map_embedding
#align finset.sum_subtype_map_embedding Finset.sum_subtype_map_embedding
variable (f s)
@[to_additive]
theorem prod_coe_sort_eq_attach (f : s → β) : ∏ i : s, f i = ∏ i ∈ s.attach, f i :=
rfl
#align finset.prod_coe_sort_eq_attach Finset.prod_coe_sort_eq_attach
#align finset.sum_coe_sort_eq_attach Finset.sum_coe_sort_eq_attach
@[to_additive]
theorem prod_coe_sort : ∏ i : s, f i = ∏ i ∈ s, f i := prod_attach _ _
#align finset.prod_coe_sort Finset.prod_coe_sort
#align finset.sum_coe_sort Finset.sum_coe_sort
@[to_additive]
theorem prod_finset_coe (f : α → β) (s : Finset α) : (∏ i : (s : Set α), f i) = ∏ i ∈ s, f i :=
prod_coe_sort s f
#align finset.prod_finset_coe Finset.prod_finset_coe
#align finset.sum_finset_coe Finset.sum_finset_coe
variable {f s}
@[to_additive]
theorem prod_subtype {p : α → Prop} {F : Fintype (Subtype p)} (s : Finset α) (h : ∀ x, x ∈ s ↔ p x)
(f : α → β) : ∏ a ∈ s, f a = ∏ a : Subtype p, f a := by
have : (· ∈ s) = p := Set.ext h
subst p
rw [← prod_coe_sort]
congr!
#align finset.prod_subtype Finset.prod_subtype
#align finset.sum_subtype Finset.sum_subtype
@[to_additive]
lemma prod_preimage' (f : ι → κ) [DecidablePred (· ∈ Set.range f)] (s : Finset κ) (hf) (g : κ → β) :
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s.filter (· ∈ Set.range f), g x := by
classical
calc
∏ x ∈ preimage s f hf, g (f x) = ∏ x ∈ image f (preimage s f hf), g x :=
Eq.symm <| prod_image <| by simpa only [mem_preimage, Set.InjOn] using hf
_ = ∏ x ∈ s.filter fun x => x ∈ Set.range f, g x := by rw [image_preimage]
#align finset.prod_preimage' Finset.prod_preimage'
#align finset.sum_preimage' Finset.sum_preimage'
@[to_additive]
lemma prod_preimage (f : ι → κ) (s : Finset κ) (hf) (g : κ → β)
(hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s, g x := by
classical rw [prod_preimage', prod_filter_of_ne]; exact fun x hx ↦ Not.imp_symm (hg x hx)
#align finset.prod_preimage Finset.prod_preimage
#align finset.sum_preimage Finset.sum_preimage
@[to_additive]
lemma prod_preimage_of_bij (f : ι → κ) (s : Finset κ) (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) (g : κ → β) :
∏ x ∈ s.preimage f hf.injOn, g (f x) = ∏ x ∈ s, g x :=
prod_preimage _ _ hf.injOn g fun _ hs h_f ↦ (h_f <| hf.subset_range hs).elim
#align finset.prod_preimage_of_bij Finset.prod_preimage_of_bij
#align finset.sum_preimage_of_bij Finset.sum_preimage_of_bij
@[to_additive]
theorem prod_set_coe (s : Set α) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i :=
(Finset.prod_subtype s.toFinset (fun _ ↦ Set.mem_toFinset) f).symm
/-- The product of a function `g` defined only on a set `s` is equal to
the product of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 1` off `s`. -/
@[to_additive "The sum of a function `g` defined only on a set `s` is equal to
the sum of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 0` off `s`."]
theorem prod_congr_set {α : Type*} [CommMonoid α] {β : Type*} [Fintype β] (s : Set β)
[DecidablePred (· ∈ s)] (f : β → α) (g : s → α) (w : ∀ (x : β) (h : x ∈ s), f x = g ⟨x, h⟩)
(w' : ∀ x : β, x ∉ s → f x = 1) : Finset.univ.prod f = Finset.univ.prod g := by
rw [← @Finset.prod_subset _ _ s.toFinset Finset.univ f _ (by simp)]
· rw [Finset.prod_subtype]
· apply Finset.prod_congr rfl
exact fun ⟨x, h⟩ _ => w x h
· simp
· rintro x _ h
exact w' x (by simpa using h)
#align finset.prod_congr_set Finset.prod_congr_set
#align finset.sum_congr_set Finset.sum_congr_set
@[to_additive]
theorem prod_apply_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p}
[DecidablePred fun x => ¬p x] (f : ∀ x : α, p x → γ) (g : ∀ x : α, ¬p x → γ) (h : γ → β) :
(∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) =
(∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter fun x => ¬p x).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) :=
calc
(∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) =
(∏ x ∈ s.filter p, h (if hx : p x then f x hx else g x hx)) *
∏ x ∈ s.filter (¬p ·), h (if hx : p x then f x hx else g x hx) :=
(prod_filter_mul_prod_filter_not s p _).symm
_ = (∏ x ∈ (s.filter p).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) *
∏ x ∈ (s.filter (¬p ·)).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx) :=
congr_arg₂ _ (prod_attach _ _).symm (prod_attach _ _).symm
_ = (∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter (¬p ·)).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) :=
congr_arg₂ _ (prod_congr rfl fun x _hx ↦
congr_arg h (dif_pos <| by simpa using (mem_filter.mp x.2).2))
(prod_congr rfl fun x _hx => congr_arg h (dif_neg <| by simpa using (mem_filter.mp x.2).2))
#align finset.prod_apply_dite Finset.prod_apply_dite
#align finset.sum_apply_dite Finset.sum_apply_dite
@[to_additive]
theorem prod_apply_ite {s : Finset α} {p : α → Prop} {_hp : DecidablePred p} (f g : α → γ)
(h : γ → β) :
(∏ x ∈ s, h (if p x then f x else g x)) =
(∏ x ∈ s.filter p, h (f x)) * ∏ x ∈ s.filter fun x => ¬p x, h (g x) :=
(prod_apply_dite _ _ _).trans <| congr_arg₂ _ (prod_attach _ (h ∘ f)) (prod_attach _ (h ∘ g))
#align finset.prod_apply_ite Finset.prod_apply_ite
#align finset.sum_apply_ite Finset.sum_apply_ite
@[to_additive]
theorem prod_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f : ∀ x : α, p x → β)
(g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) =
(∏ x ∈ (s.filter p).attach, f x.1 (by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter fun x => ¬p x).attach, g x.1 (by simpa using (mem_filter.mp x.2).2) := by
simp [prod_apply_dite _ _ fun x => x]
#align finset.prod_dite Finset.prod_dite
#align finset.sum_dite Finset.sum_dite
@[to_additive]
theorem prod_ite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f g : α → β) :
∏ x ∈ s, (if p x then f x else g x) =
(∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, g x := by
simp [prod_apply_ite _ _ fun x => x]
#align finset.prod_ite Finset.prod_ite
#align finset.sum_ite Finset.sum_ite
@[to_additive]
theorem prod_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, ¬p x) :
∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, g x := by
rw [prod_ite, filter_false_of_mem, filter_true_of_mem]
· simp only [prod_empty, one_mul]
all_goals intros; apply h; assumption
#align finset.prod_ite_of_false Finset.prod_ite_of_false
#align finset.sum_ite_of_false Finset.sum_ite_of_false
@[to_additive]
theorem prod_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, p x) :
∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, f x := by
simp_rw [← ite_not (p _)]
apply prod_ite_of_false
simpa
#align finset.prod_ite_of_true Finset.prod_ite_of_true
#align finset.sum_ite_of_true Finset.sum_ite_of_true
@[to_additive]
theorem prod_apply_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β)
(h : ∀ x ∈ s, ¬p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (g x) := by
simp_rw [apply_ite k]
exact prod_ite_of_false _ _ h
#align finset.prod_apply_ite_of_false Finset.prod_apply_ite_of_false
#align finset.sum_apply_ite_of_false Finset.sum_apply_ite_of_false
@[to_additive]
theorem prod_apply_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β)
(h : ∀ x ∈ s, p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (f x) := by
simp_rw [apply_ite k]
exact prod_ite_of_true _ _ h
#align finset.prod_apply_ite_of_true Finset.prod_apply_ite_of_true
#align finset.sum_apply_ite_of_true Finset.sum_apply_ite_of_true
@[to_additive]
theorem prod_extend_by_one [DecidableEq α] (s : Finset α) (f : α → β) :
∏ i ∈ s, (if i ∈ s then f i else 1) = ∏ i ∈ s, f i :=
(prod_congr rfl) fun _i hi => if_pos hi
#align finset.prod_extend_by_one Finset.prod_extend_by_one
#align finset.sum_extend_by_zero Finset.sum_extend_by_zero
@[to_additive (attr := simp)]
theorem prod_ite_mem [DecidableEq α] (s t : Finset α) (f : α → β) :
∏ i ∈ s, (if i ∈ t then f i else 1) = ∏ i ∈ s ∩ t, f i := by
rw [← Finset.prod_filter, Finset.filter_mem_eq_inter]
#align finset.prod_ite_mem Finset.prod_ite_mem
#align finset.sum_ite_mem Finset.sum_ite_mem
@[to_additive (attr := simp)]
theorem prod_dite_eq [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, a = x → β) :
∏ x ∈ s, (if h : a = x then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by
split_ifs with h
· rw [Finset.prod_eq_single a, dif_pos rfl]
· intros _ _ h
rw [dif_neg]
exact h.symm
· simp [h]
· rw [Finset.prod_eq_one]
intros
rw [dif_neg]
rintro rfl
contradiction
#align finset.prod_dite_eq Finset.prod_dite_eq
#align finset.sum_dite_eq Finset.sum_dite_eq
@[to_additive (attr := simp)]
theorem prod_dite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, x = a → β) :
∏ x ∈ s, (if h : x = a then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by
split_ifs with h
· rw [Finset.prod_eq_single a, dif_pos rfl]
· intros _ _ h
rw [dif_neg]
exact h
· simp [h]
· rw [Finset.prod_eq_one]
intros
rw [dif_neg]
rintro rfl
contradiction
#align finset.prod_dite_eq' Finset.prod_dite_eq'
#align finset.sum_dite_eq' Finset.sum_dite_eq'
@[to_additive (attr := simp)]
theorem prod_ite_eq [DecidableEq α] (s : Finset α) (a : α) (b : α → β) :
(∏ x ∈ s, ite (a = x) (b x) 1) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq s a fun x _ => b x
#align finset.prod_ite_eq Finset.prod_ite_eq
#align finset.sum_ite_eq Finset.sum_ite_eq
/-- A product taken over a conditional whose condition is an equality test on the index and whose
alternative is `1` has value either the term at that index or `1`.
The difference with `Finset.prod_ite_eq` is that the arguments to `Eq` are swapped. -/
@[to_additive (attr := simp) "A sum taken over a conditional whose condition is an equality
test on the index and whose alternative is `0` has value either the term at that index or `0`.
The difference with `Finset.sum_ite_eq` is that the arguments to `Eq` are swapped."]
theorem prod_ite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : α → β) :
(∏ x ∈ s, ite (x = a) (b x) 1) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq' s a fun x _ => b x
#align finset.prod_ite_eq' Finset.prod_ite_eq'
#align finset.sum_ite_eq' Finset.sum_ite_eq'
@[to_additive]
theorem prod_ite_index (p : Prop) [Decidable p] (s t : Finset α) (f : α → β) :
∏ x ∈ if p then s else t, f x = if p then ∏ x ∈ s, f x else ∏ x ∈ t, f x :=
apply_ite (fun s => ∏ x ∈ s, f x) _ _ _
#align finset.prod_ite_index Finset.prod_ite_index
#align finset.sum_ite_index Finset.sum_ite_index
@[to_additive (attr := simp)]
theorem prod_ite_irrel (p : Prop) [Decidable p] (s : Finset α) (f g : α → β) :
∏ x ∈ s, (if p then f x else g x) = if p then ∏ x ∈ s, f x else ∏ x ∈ s, g x := by
split_ifs with h <;> rfl
#align finset.prod_ite_irrel Finset.prod_ite_irrel
#align finset.sum_ite_irrel Finset.sum_ite_irrel
@[to_additive (attr := simp)]
theorem prod_dite_irrel (p : Prop) [Decidable p] (s : Finset α) (f : p → α → β) (g : ¬p → α → β) :
∏ x ∈ s, (if h : p then f h x else g h x) =
if h : p then ∏ x ∈ s, f h x else ∏ x ∈ s, g h x := by
split_ifs with h <;> rfl
#align finset.prod_dite_irrel Finset.prod_dite_irrel
#align finset.sum_dite_irrel Finset.sum_dite_irrel
@[to_additive (attr := simp)]
theorem prod_pi_mulSingle' [DecidableEq α] (a : α) (x : β) (s : Finset α) :
∏ a' ∈ s, Pi.mulSingle a x a' = if a ∈ s then x else 1 :=
prod_dite_eq' _ _ _
#align finset.prod_pi_mul_single' Finset.prod_pi_mulSingle'
#align finset.sum_pi_single' Finset.sum_pi_single'
@[to_additive (attr := simp)]
theorem prod_pi_mulSingle {β : α → Type*} [DecidableEq α] [∀ a, CommMonoid (β a)] (a : α)
(f : ∀ a, β a) (s : Finset α) :
(∏ a' ∈ s, Pi.mulSingle a' (f a') a) = if a ∈ s then f a else 1 :=
prod_dite_eq _ _ _
#align finset.prod_pi_mul_single Finset.prod_pi_mulSingle
@[to_additive]
lemma mulSupport_prod (s : Finset ι) (f : ι → α → β) :
mulSupport (fun x ↦ ∏ i ∈ s, f i x) ⊆ ⋃ i ∈ s, mulSupport (f i) := by
simp only [mulSupport_subset_iff', Set.mem_iUnion, not_exists, nmem_mulSupport]
exact fun x ↦ prod_eq_one
#align function.mul_support_prod Finset.mulSupport_prod
#align function.support_sum Finset.support_sum
section indicator
open Set
variable {κ : Type*}
/-- Consider a product of `g i (f i)` over a finset. Suppose `g` is a function such as
`n ↦ (· ^ n)`, which maps a second argument of `1` to `1`. Then if `f` is replaced by the
corresponding multiplicative indicator function, the finset may be replaced by a possibly larger
finset without changing the value of the product. -/
@[to_additive "Consider a sum of `g i (f i)` over a finset. Suppose `g` is a function such as
`n ↦ (n • ·)`, which maps a second argument of `0` to `0` (or a weighted sum of `f i * h i` or
`f i • h i`, where `f` gives the weights that are multiplied by some other function `h`). Then if
`f` is replaced by the corresponding indicator function, the finset may be replaced by a possibly
larger finset without changing the value of the sum."]
lemma prod_mulIndicator_subset_of_eq_one [One α] (f : ι → α) (g : ι → α → β) {s t : Finset ι}
(h : s ⊆ t) (hg : ∀ a, g a 1 = 1) :
∏ i ∈ t, g i (mulIndicator ↑s f i) = ∏ i ∈ s, g i (f i) := by
calc
_ = ∏ i ∈ s, g i (mulIndicator ↑s f i) := by rw [prod_subset h fun i _ hn ↦ by simp [hn, hg]]
-- Porting note: This did not use to need the implicit argument
_ = _ := prod_congr rfl fun i hi ↦ congr_arg _ <| mulIndicator_of_mem (α := ι) hi f
#align set.prod_mul_indicator_subset_of_eq_one Finset.prod_mulIndicator_subset_of_eq_one
#align set.sum_indicator_subset_of_eq_zero Finset.sum_indicator_subset_of_eq_zero
/-- Taking the product of an indicator function over a possibly larger finset is the same as
taking the original function over the original finset. -/
@[to_additive "Summing an indicator function over a possibly larger `Finset` is the same as summing
the original function over the original finset."]
lemma prod_mulIndicator_subset (f : ι → β) {s t : Finset ι} (h : s ⊆ t) :
∏ i ∈ t, mulIndicator (↑s) f i = ∏ i ∈ s, f i :=
prod_mulIndicator_subset_of_eq_one _ (fun _ ↦ id) h fun _ ↦ rfl
#align set.prod_mul_indicator_subset Finset.prod_mulIndicator_subset
#align set.sum_indicator_subset Finset.sum_indicator_subset
@[to_additive]
lemma prod_mulIndicator_eq_prod_filter (s : Finset ι) (f : ι → κ → β) (t : ι → Set κ) (g : ι → κ)
[DecidablePred fun i ↦ g i ∈ t i] :
∏ i ∈ s, mulIndicator (t i) (f i) (g i) = ∏ i ∈ s.filter fun i ↦ g i ∈ t i, f i (g i) := by
refine (prod_filter_mul_prod_filter_not s (fun i ↦ g i ∈ t i) _).symm.trans <|
Eq.trans (congr_arg₂ (· * ·) ?_ ?_) (mul_one _)
· exact prod_congr rfl fun x hx ↦ mulIndicator_of_mem (mem_filter.1 hx).2 _
· exact prod_eq_one fun x hx ↦ mulIndicator_of_not_mem (mem_filter.1 hx).2 _
#align finset.prod_mul_indicator_eq_prod_filter Finset.prod_mulIndicator_eq_prod_filter
#align finset.sum_indicator_eq_sum_filter Finset.sum_indicator_eq_sum_filter
@[to_additive]
lemma prod_mulIndicator_eq_prod_inter [DecidableEq ι] (s t : Finset ι) (f : ι → β) :
∏ i ∈ s, (t : Set ι).mulIndicator f i = ∏ i ∈ s ∩ t, f i := by
rw [← filter_mem_eq_inter, prod_mulIndicator_eq_prod_filter]; rfl
@[to_additive]
lemma mulIndicator_prod (s : Finset ι) (t : Set κ) (f : ι → κ → β) :
mulIndicator t (∏ i ∈ s, f i) = ∏ i ∈ s, mulIndicator t (f i) :=
map_prod (mulIndicatorHom _ _) _ _
#align set.mul_indicator_finset_prod Finset.mulIndicator_prod
#align set.indicator_finset_sum Finset.indicator_sum
variable {κ : Type*}
@[to_additive]
lemma mulIndicator_biUnion (s : Finset ι) (t : ι → Set κ) {f : κ → β} :
((s : Set ι).PairwiseDisjoint t) →
mulIndicator (⋃ i ∈ s, t i) f = fun a ↦ ∏ i ∈ s, mulIndicator (t i) f a := by
classical
refine Finset.induction_on s (by simp) fun i s hi ih hs ↦ funext fun j ↦ ?_
rw [prod_insert hi, set_biUnion_insert, mulIndicator_union_of_not_mem_inter,
ih (hs.subset <| subset_insert _ _)]
simp only [not_exists, exists_prop, mem_iUnion, mem_inter_iff, not_and]
exact fun hji i' hi' hji' ↦ (ne_of_mem_of_not_mem hi' hi).symm <|
hs.elim_set (mem_insert_self _ _) (mem_insert_of_mem hi') _ hji hji'
#align set.mul_indicator_finset_bUnion Finset.mulIndicator_biUnion
#align set.indicator_finset_bUnion Finset.indicator_biUnion
@[to_additive]
lemma mulIndicator_biUnion_apply (s : Finset ι) (t : ι → Set κ) {f : κ → β}
(h : (s : Set ι).PairwiseDisjoint t) (x : κ) :
mulIndicator (⋃ i ∈ s, t i) f x = ∏ i ∈ s, mulIndicator (t i) f x := by
rw [mulIndicator_biUnion s t h]
#align set.mul_indicator_finset_bUnion_apply Finset.mulIndicator_biUnion_apply
#align set.indicator_finset_bUnion_apply Finset.indicator_biUnion_apply
end indicator
@[to_additive]
theorem prod_bij_ne_one {s : Finset α} {t : Finset γ} {f : α → β} {g : γ → β}
(i : ∀ a ∈ s, f a ≠ 1 → γ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t)
(i_inj : ∀ a₁ h₁₁ h₁₂ a₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, i a h₁ h₂ = b) (h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x := by
classical
calc
∏ x ∈ s, f x = ∏ x ∈ s.filter fun x => f x ≠ 1, f x := by rw [prod_filter_ne_one]
_ = ∏ x ∈ t.filter fun x => g x ≠ 1, g x :=
prod_bij (fun a ha => i a (mem_filter.mp ha).1 <| by simpa using (mem_filter.mp ha).2)
?_ ?_ ?_ ?_
_ = ∏ x ∈ t, g x := prod_filter_ne_one _
· intros a ha
refine (mem_filter.mp ha).elim ?_
intros h₁ h₂
refine (mem_filter.mpr ⟨hi a h₁ _, ?_⟩)
specialize h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
rwa [← h]
· intros a₁ ha₁ a₂ ha₂
refine (mem_filter.mp ha₁).elim fun _ha₁₁ _ha₁₂ ↦ ?_
refine (mem_filter.mp ha₂).elim fun _ha₂₁ _ha₂₂ ↦ ?_
apply i_inj
· intros b hb
refine (mem_filter.mp hb).elim fun h₁ h₂ ↦ ?_
obtain ⟨a, ha₁, ha₂, eq⟩ := i_surj b h₁ fun H ↦ by rw [H] at h₂; simp at h₂
exact ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩
· refine (fun a ha => (mem_filter.mp ha).elim fun h₁ h₂ ↦ ?_)
exact h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
#align finset.prod_bij_ne_one Finset.prod_bij_ne_one
#align finset.sum_bij_ne_zero Finset.sum_bij_ne_zero
@[to_additive]
theorem prod_dite_of_false {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, ¬p x)
(f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, g x.val (h x.val x.property) := by
refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop
#align finset.prod_dite_of_false Finset.prod_dite_of_false
#align finset.sum_dite_of_false Finset.sum_dite_of_false
@[to_additive]
theorem prod_dite_of_true {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, p x)
(f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, f x.val (h x.val x.property) := by
refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop
#align finset.prod_dite_of_true Finset.prod_dite_of_true
#align finset.sum_dite_of_true Finset.sum_dite_of_true
@[to_additive]
theorem nonempty_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun H => False.elim <| h <| H.symm ▸ prod_empty) id
#align finset.nonempty_of_prod_ne_one Finset.nonempty_of_prod_ne_one
#align finset.nonempty_of_sum_ne_zero Finset.nonempty_of_sum_ne_zero
@[to_additive]
theorem exists_ne_one_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : ∃ a ∈ s, f a ≠ 1 := by
classical
rw [← prod_filter_ne_one] at h
rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩
exact ⟨x, (mem_filter.1 hx).1, by simpa using (mem_filter.1 hx).2⟩
#align finset.exists_ne_one_of_prod_ne_one Finset.exists_ne_one_of_prod_ne_one
#align finset.exists_ne_zero_of_sum_ne_zero Finset.exists_ne_zero_of_sum_ne_zero
@[to_additive]
theorem prod_range_succ_comm (f : ℕ → β) (n : ℕ) :
(∏ x ∈ range (n + 1), f x) = f n * ∏ x ∈ range n, f x := by
rw [range_succ, prod_insert not_mem_range_self]
#align finset.prod_range_succ_comm Finset.prod_range_succ_comm
#align finset.sum_range_succ_comm Finset.sum_range_succ_comm
@[to_additive]
theorem prod_range_succ (f : ℕ → β) (n : ℕ) :
(∏ x ∈ range (n + 1), f x) = (∏ x ∈ range n, f x) * f n := by
simp only [mul_comm, prod_range_succ_comm]
#align finset.prod_range_succ Finset.prod_range_succ
#align finset.sum_range_succ Finset.sum_range_succ
@[to_additive]
theorem prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (∏ k ∈ range (n + 1), f k) = (∏ k ∈ range n, f (k + 1)) * f 0
| 0 => prod_range_succ _ _
| n + 1 => by rw [prod_range_succ _ n, mul_right_comm, ← prod_range_succ' _ n, prod_range_succ]
#align finset.prod_range_succ' Finset.prod_range_succ'
#align finset.sum_range_succ' Finset.sum_range_succ'
@[to_additive]
theorem eventually_constant_prod {u : ℕ → β} {N : ℕ} (hu : ∀ n ≥ N, u n = 1) {n : ℕ} (hn : N ≤ n) :
(∏ k ∈ range n, u k) = ∏ k ∈ range N, u k := by
obtain ⟨m, rfl : n = N + m⟩ := Nat.exists_eq_add_of_le hn
clear hn
induction' m with m hm
· simp
· simp [← add_assoc, prod_range_succ, hm, hu]
#align finset.eventually_constant_prod Finset.eventually_constant_prod
#align finset.eventually_constant_sum Finset.eventually_constant_sum
@[to_additive]
theorem prod_range_add (f : ℕ → β) (n m : ℕ) :
(∏ x ∈ range (n + m), f x) = (∏ x ∈ range n, f x) * ∏ x ∈ range m, f (n + x) := by
induction' m with m hm
· simp
· erw [Nat.add_succ, prod_range_succ, prod_range_succ, hm, mul_assoc]
#align finset.prod_range_add Finset.prod_range_add
#align finset.sum_range_add Finset.sum_range_add
@[to_additive]
theorem prod_range_add_div_prod_range {α : Type*} [CommGroup α] (f : ℕ → α) (n m : ℕ) :
(∏ k ∈ range (n + m), f k) / ∏ k ∈ range n, f k = ∏ k ∈ Finset.range m, f (n + k) :=
div_eq_of_eq_mul' (prod_range_add f n m)
#align finset.prod_range_add_div_prod_range Finset.prod_range_add_div_prod_range
#align finset.sum_range_add_sub_sum_range Finset.sum_range_add_sub_sum_range
@[to_additive]
theorem prod_range_zero (f : ℕ → β) : ∏ k ∈ range 0, f k = 1 := by rw [range_zero, prod_empty]
#align finset.prod_range_zero Finset.prod_range_zero
#align finset.sum_range_zero Finset.sum_range_zero
@[to_additive sum_range_one]
theorem prod_range_one (f : ℕ → β) : ∏ k ∈ range 1, f k = f 0 := by
rw [range_one, prod_singleton]
#align finset.prod_range_one Finset.prod_range_one
#align finset.sum_range_one Finset.sum_range_one
open List
@[to_additive]
theorem prod_list_map_count [DecidableEq α] (l : List α) {M : Type*} [CommMonoid M] (f : α → M) :
(l.map f).prod = ∏ m ∈ l.toFinset, f m ^ l.count m := by
induction' l with a s IH; · simp only [map_nil, prod_nil, count_nil, pow_zero, prod_const_one]
simp only [List.map, List.prod_cons, toFinset_cons, IH]
by_cases has : a ∈ s.toFinset
· rw [insert_eq_of_mem has, ← insert_erase has, prod_insert (not_mem_erase _ _),
prod_insert (not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ']
congr 1
refine prod_congr rfl fun x hx => ?_
rw [count_cons_of_ne (ne_of_mem_erase hx)]
rw [prod_insert has, count_cons_self, count_eq_zero_of_not_mem (mt mem_toFinset.2 has), pow_one]
congr 1
refine prod_congr rfl fun x hx => ?_
rw [count_cons_of_ne]
rintro rfl
exact has hx
#align finset.prod_list_map_count Finset.prod_list_map_count
#align finset.sum_list_map_count Finset.sum_list_map_count
@[to_additive]
theorem prod_list_count [DecidableEq α] [CommMonoid α] (s : List α) :
s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by simpa using prod_list_map_count s id
#align finset.prod_list_count Finset.prod_list_count
#align finset.sum_list_count Finset.sum_list_count
@[to_additive]
theorem prod_list_count_of_subset [DecidableEq α] [CommMonoid α] (m : List α) (s : Finset α)
(hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
rw [prod_list_count]
refine prod_subset hs fun x _ hx => ?_
rw [mem_toFinset] at hx
rw [count_eq_zero_of_not_mem hx, pow_zero]
#align finset.prod_list_count_of_subset Finset.prod_list_count_of_subset
#align finset.sum_list_count_of_subset Finset.sum_list_count_of_subset
theorem sum_filter_count_eq_countP [DecidableEq α] (p : α → Prop) [DecidablePred p] (l : List α) :
∑ x ∈ l.toFinset.filter p, l.count x = l.countP p := by
simp [Finset.sum, sum_map_count_dedup_filter_eq_countP p l]
#align finset.sum_filter_count_eq_countp Finset.sum_filter_count_eq_countP
open Multiset
@[to_additive]
theorem prod_multiset_map_count [DecidableEq α] (s : Multiset α) {M : Type*} [CommMonoid M]
(f : α → M) : (s.map f).prod = ∏ m ∈ s.toFinset, f m ^ s.count m := by
refine Quot.induction_on s fun l => ?_
simp [prod_list_map_count l f]
#align finset.prod_multiset_map_count Finset.prod_multiset_map_count
#align finset.sum_multiset_map_count Finset.sum_multiset_map_count
@[to_additive]
theorem prod_multiset_count [DecidableEq α] [CommMonoid α] (s : Multiset α) :
s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by
convert prod_multiset_map_count s id
rw [Multiset.map_id]
#align finset.prod_multiset_count Finset.prod_multiset_count
#align finset.sum_multiset_count Finset.sum_multiset_count
@[to_additive]
theorem prod_multiset_count_of_subset [DecidableEq α] [CommMonoid α] (m : Multiset α) (s : Finset α)
(hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
revert hs
refine Quot.induction_on m fun l => ?_
simp only [quot_mk_to_coe'', prod_coe, coe_count]
apply prod_list_count_of_subset l s
#align finset.prod_multiset_count_of_subset Finset.prod_multiset_count_of_subset
#align finset.sum_multiset_count_of_subset Finset.sum_multiset_count_of_subset
@[to_additive]
theorem prod_mem_multiset [DecidableEq α] (m : Multiset α) (f : { x // x ∈ m } → β) (g : α → β)
(hfg : ∀ x, f x = g x) : ∏ x : { x // x ∈ m }, f x = ∏ x ∈ m.toFinset, g x := by
refine prod_bij' (fun x _ ↦ x) (fun x hx ↦ ⟨x, Multiset.mem_toFinset.1 hx⟩) ?_ ?_ ?_ ?_ ?_ <;>
simp [hfg]
#align finset.prod_mem_multiset Finset.prod_mem_multiset
#align finset.sum_mem_multiset Finset.sum_mem_multiset
/-- To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors. -/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
theorem prod_induction {M : Type*} [CommMonoid M] (f : α → M) (p : M → Prop)
(hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p <| f x) :
p <| ∏ x ∈ s, f x :=
Multiset.prod_induction _ _ hom unit (Multiset.forall_mem_map_iff.mpr base)
#align finset.prod_induction Finset.prod_induction
#align finset.sum_induction Finset.sum_induction
/-- To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors. -/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
theorem prod_induction_nonempty {M : Type*} [CommMonoid M] (f : α → M) (p : M → Prop)
(hom : ∀ a b, p a → p b → p (a * b)) (nonempty : s.Nonempty) (base : ∀ x ∈ s, p <| f x) :
p <| ∏ x ∈ s, f x :=
Multiset.prod_induction_nonempty p hom (by simp [nonempty_iff_ne_empty.mp nonempty])
(Multiset.forall_mem_map_iff.mpr base)
#align finset.prod_induction_nonempty Finset.prod_induction_nonempty
#align finset.sum_induction_nonempty Finset.sum_induction_nonempty
/-- For any product along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can verify
that it's equal to a different function just by checking ratios of adjacent terms.
This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
@[to_additive "For any sum along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can
verify that it's equal to a different function just by checking differences of adjacent terms.
This is a discrete analogue of the fundamental theorem of calculus."]
theorem prod_range_induction (f s : ℕ → β) (base : s 0 = 1)
(step : ∀ n, s (n + 1) = s n * f n) (n : ℕ) :
∏ k ∈ Finset.range n, f k = s n := by
induction' n with k hk
· rw [Finset.prod_range_zero, base]
· simp only [hk, Finset.prod_range_succ, step, mul_comm]
#align finset.prod_range_induction Finset.prod_range_induction
#align finset.sum_range_induction Finset.sum_range_induction
/-- A telescoping product along `{0, ..., n - 1}` of a commutative group valued function reduces to
the ratio of the last and first factors. -/
@[to_additive "A telescoping sum along `{0, ..., n - 1}` of an additive commutative group valued
function reduces to the difference of the last and first terms."]
theorem prod_range_div {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
(∏ i ∈ range n, f (i + 1) / f i) = f n / f 0 := by apply prod_range_induction <;> simp
#align finset.prod_range_div Finset.prod_range_div
#align finset.sum_range_sub Finset.sum_range_sub
@[to_additive]
theorem prod_range_div' {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
(∏ i ∈ range n, f i / f (i + 1)) = f 0 / f n := by apply prod_range_induction <;> simp
#align finset.prod_range_div' Finset.prod_range_div'
#align finset.sum_range_sub' Finset.sum_range_sub'
@[to_additive]
theorem eq_prod_range_div {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
f n = f 0 * ∏ i ∈ range n, f (i + 1) / f i := by rw [prod_range_div, mul_div_cancel]
#align finset.eq_prod_range_div Finset.eq_prod_range_div
#align finset.eq_sum_range_sub Finset.eq_sum_range_sub
@[to_additive]
theorem eq_prod_range_div' {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
f n = ∏ i ∈ range (n + 1), if i = 0 then f 0 else f i / f (i - 1) := by
conv_lhs => rw [Finset.eq_prod_range_div f]
simp [Finset.prod_range_succ', mul_comm]
#align finset.eq_prod_range_div' Finset.eq_prod_range_div'
#align finset.eq_sum_range_sub' Finset.eq_sum_range_sub'
/-- A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
reduces to the difference of the last and first terms
when the function we are summing is monotone.
-/
theorem sum_range_tsub [CanonicallyOrderedAddCommMonoid α] [Sub α] [OrderedSub α]
[ContravariantClass α α (· + ·) (· ≤ ·)] {f : ℕ → α} (h : Monotone f) (n : ℕ) :
∑ i ∈ range n, (f (i + 1) - f i) = f n - f 0 := by
apply sum_range_induction
case base => apply tsub_self
case step =>
intro n
have h₁ : f n ≤ f (n + 1) := h (Nat.le_succ _)
have h₂ : f 0 ≤ f n := h (Nat.zero_le _)
rw [tsub_add_eq_add_tsub h₂, add_tsub_cancel_of_le h₁]
#align finset.sum_range_tsub Finset.sum_range_tsub
@[to_additive (attr := simp)]
theorem prod_const (b : β) : ∏ _x ∈ s, b = b ^ s.card :=
(congr_arg _ <| s.val.map_const b).trans <| Multiset.prod_replicate s.card b
#align finset.prod_const Finset.prod_const
#align finset.sum_const Finset.sum_const
@[to_additive sum_eq_card_nsmul]
theorem prod_eq_pow_card {b : β} (hf : ∀ a ∈ s, f a = b) : ∏ a ∈ s, f a = b ^ s.card :=
(prod_congr rfl hf).trans <| prod_const _
#align finset.prod_eq_pow_card Finset.prod_eq_pow_card
#align finset.sum_eq_card_nsmul Finset.sum_eq_card_nsmul
@[to_additive card_nsmul_add_sum]
theorem pow_card_mul_prod {b : β} : b ^ s.card * ∏ a ∈ s, f a = ∏ a ∈ s, b * f a :=
(Finset.prod_const b).symm ▸ prod_mul_distrib.symm
@[to_additive sum_add_card_nsmul]
theorem prod_mul_pow_card {b : β} : (∏ a ∈ s, f a) * b ^ s.card = ∏ a ∈ s, f a * b :=
(Finset.prod_const b).symm ▸ prod_mul_distrib.symm
@[to_additive]
theorem pow_eq_prod_const (b : β) : ∀ n, b ^ n = ∏ _k ∈ range n, b := by simp
#align finset.pow_eq_prod_const Finset.pow_eq_prod_const
#align finset.nsmul_eq_sum_const Finset.nsmul_eq_sum_const
@[to_additive]
theorem prod_pow (s : Finset α) (n : ℕ) (f : α → β) : ∏ x ∈ s, f x ^ n = (∏ x ∈ s, f x) ^ n :=
Multiset.prod_map_pow
#align finset.prod_pow Finset.prod_pow
#align finset.sum_nsmul Finset.sum_nsmul
@[to_additive sum_nsmul_assoc]
lemma prod_pow_eq_pow_sum (s : Finset ι) (f : ι → ℕ) (a : β) :
∏ i ∈ s, a ^ f i = a ^ ∑ i ∈ s, f i :=
cons_induction (by simp) (fun _ _ _ _ ↦ by simp [prod_cons, sum_cons, pow_add, *]) s
#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum
/-- A product over `Finset.powersetCard` which only depends on the size of the sets is constant. -/
@[to_additive
"A sum over `Finset.powersetCard` which only depends on the size of the sets is constant."]
lemma prod_powersetCard (n : ℕ) (s : Finset α) (f : ℕ → β) :
∏ t ∈ powersetCard n s, f t.card = f n ^ s.card.choose n := by
rw [prod_eq_pow_card, card_powersetCard]; rintro a ha; rw [(mem_powersetCard.1 ha).2]
@[to_additive]
theorem prod_flip {n : ℕ} (f : ℕ → β) :
(∏ r ∈ range (n + 1), f (n - r)) = ∏ k ∈ range (n + 1), f k := by
induction' n with n ih
· rw [prod_range_one, prod_range_one]
· rw [prod_range_succ', prod_range_succ _ (Nat.succ n)]
simp [← ih]
#align finset.prod_flip Finset.prod_flip
#align finset.sum_flip Finset.sum_flip
@[to_additive]
theorem prod_involution {s : Finset α} {f : α → β} :
∀ (g : ∀ a ∈ s, α) (_ : ∀ a ha, f a * f (g a ha) = 1) (_ : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(g_mem : ∀ a ha, g a ha ∈ s) (_ : ∀ a ha, g (g a ha) (g_mem a ha) = a),
∏ x ∈ s, f x = 1 := by
haveI := Classical.decEq α; haveI := Classical.decEq β
exact
Finset.strongInductionOn s fun s ih g h g_ne g_mem g_inv =>
s.eq_empty_or_nonempty.elim (fun hs => hs.symm ▸ rfl) fun ⟨x, hx⟩ =>
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s := fun y hy =>
mem_of_mem_erase (mem_of_mem_erase hy)
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y := fun {x hx y hy} h => by
rw [← g_inv x hx, ← g_inv y hy]; simp [h]
have ih' : (∏ y ∈ erase (erase s x) (g x hx), f y) = (1 : β) :=
ih ((s.erase x).erase (g x hx))
⟨Subset.trans (erase_subset _ _) (erase_subset _ _), fun h =>
not_mem_erase (g x hx) (s.erase x) (h (g_mem x hx))⟩
(fun y hy => g y (hmem y hy)) (fun y hy => h y (hmem y hy))
(fun y hy => g_ne y (hmem y hy))
(fun y hy =>
mem_erase.2
⟨fun h : g y _ = g x hx => by simp [g_inj h] at hy,
mem_erase.2
⟨fun h : g y _ = x => by
have : y = g x hx := g_inv y (hmem y hy) ▸ by simp [h]
simp [this] at hy, g_mem y (hmem y hy)⟩⟩)
fun y hy => g_inv y (hmem y hy)
if hx1 : f x = 1 then
ih' ▸
Eq.symm
(prod_subset hmem fun y hy hy₁ =>
have : y = x ∨ y = g x hx := by
simpa [hy, -not_and, mem_erase, not_and_or, or_comm] using hy₁
this.elim (fun hy => hy.symm ▸ hx1) fun hy =>
h x hx ▸ hy ▸ hx1.symm ▸ (one_mul _).symm)
else by
rw [← insert_erase hx, prod_insert (not_mem_erase _ _), ←
insert_erase (mem_erase.2 ⟨g_ne x hx hx1, g_mem x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h x hx]
#align finset.prod_involution Finset.prod_involution
#align finset.sum_involution Finset.sum_involution
/-- The product of the composition of functions `f` and `g`, is the product over `b ∈ s.image g` of
`f b` to the power of the cardinality of the fibre of `b`. See also `Finset.prod_image`. -/
@[to_additive "The sum of the composition of functions `f` and `g`, is the sum over `b ∈ s.image g`
of `f b` times of the cardinality of the fibre of `b`. See also `Finset.sum_image`."]
theorem prod_comp [DecidableEq γ] (f : γ → β) (g : α → γ) :
∏ a ∈ s, f (g a) = ∏ b ∈ s.image g, f b ^ (s.filter fun a => g a = b).card := by
simp_rw [← prod_const, prod_fiberwise_of_maps_to' fun _ ↦ mem_image_of_mem _]
#align finset.prod_comp Finset.prod_comp
#align finset.sum_comp Finset.sum_comp
@[to_additive]
theorem prod_piecewise [DecidableEq α] (s t : Finset α) (f g : α → β) :
(∏ x ∈ s, (t.piecewise f g) x) = (∏ x ∈ s ∩ t, f x) * ∏ x ∈ s \ t, g x := by
erw [prod_ite, filter_mem_eq_inter, ← sdiff_eq_filter]
#align finset.prod_piecewise Finset.prod_piecewise
#align finset.sum_piecewise Finset.sum_piecewise
@[to_additive]
| Mathlib/Algebra/BigOperators/Group/Finset.lean | 1,850 | 1,853 | theorem prod_inter_mul_prod_diff [DecidableEq α] (s t : Finset α) (f : α → β) :
(∏ x ∈ s ∩ t, f x) * ∏ x ∈ s \ t, f x = ∏ x ∈ s, f x := by |
convert (s.prod_piecewise t f f).symm
simp (config := { unfoldPartialApp := true }) [Finset.piecewise]
|
/-
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.AlgebraicGeometry.OpenImmersion
/-!
# Restriction of Schemes and Morphisms
## Main definition
- `AlgebraicGeometry.Scheme.restrict`: The restriction of a scheme along an open embedding.
The map `X.restrict f ⟶ X` is `AlgebraicGeometry.Scheme.ofRestrict`.
`X ∣_ᵤ U` is the notation for restricting onto an open set, and `ιOpens U` is a shorthand
for `X.restrict U.open_embedding : X ∣_ᵤ U ⟶ X`.
- `AlgebraicGeometry.morphism_restrict`: The restriction of `X ⟶ Y` to `X ∣_ᵤ f ⁻¹ᵁ U ⟶ Y ∣_ᵤ U`.
-/
-- 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 u₁
variable {C : Type u₁} [Category.{v} C]
section
variable (X : Scheme.{u})
/-- `f ⁻¹ᵁ U` is notation for `(Opens.map f.1.base).obj U`,
the preimage of an open set `U` under `f`. -/
notation3:90 f:91 "⁻¹ᵁ " U:90 => (Opens.map (f : LocallyRingedSpace.Hom _ _).val.base).obj U
/-- `X ∣_ᵤ U` is notation for `X.restrict U.openEmbedding`, the restriction of `X` to an open set
`U` of `X`. -/
notation3:60 X:60 " ∣_ᵤ " U:61 => Scheme.restrict X (U : Opens X).openEmbedding
/-- The restriction of a scheme to an open subset. -/
abbrev Scheme.ιOpens {X : Scheme.{u}} (U : Opens X.carrier) : X ∣_ᵤ U ⟶ X := X.ofRestrict _
lemma Scheme.ofRestrict_val_c_app_self {X : Scheme.{u}} (U : Opens X) :
(X.ofRestrict U.openEmbedding).1.c.app (op U) = X.presheaf.map (eqToHom (by simp)).op := rfl
lemma Scheme.eq_restrict_presheaf_map_eqToHom {X : Scheme.{u}} (U : Opens X) {V W : Opens U}
(e : U.openEmbedding.isOpenMap.functor.obj V = U.openEmbedding.isOpenMap.functor.obj W) :
X.presheaf.map (eqToHom e).op =
(X ∣_ᵤ U).presheaf.map (eqToHom <| U.openEmbedding.functor_obj_injective e).op := rfl
instance ΓRestrictAlgebra {X : Scheme.{u}} {Y : TopCat.{u}} {f : Y ⟶ X} (hf : OpenEmbedding f) :
Algebra (Scheme.Γ.obj (op X)) (Scheme.Γ.obj (op <| X.restrict hf)) :=
(Scheme.Γ.map (X.ofRestrict hf).op).toAlgebra
#align algebraic_geometry.Γ_restrict_algebra AlgebraicGeometry.ΓRestrictAlgebra
lemma Scheme.map_basicOpen' (X : Scheme.{u}) (U : Opens X) (r : Scheme.Γ.obj (op <| X ∣_ᵤ U)) :
U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) = X.basicOpen
(X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
refine (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans ?_
erw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op]
rw [← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl,
op_id, CategoryTheory.Functor.map_id]
congr
exact PresheafedSpace.IsOpenImmersion.ofRestrict_invApp _ _ _
lemma Scheme.map_basicOpen (X : Scheme.{u}) (U : Opens X) (r : Scheme.Γ.obj (op <| X ∣_ᵤ U)) :
U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) = X.basicOpen r := by
rw [Scheme.map_basicOpen', Scheme.basicOpen_res_eq]
lemma Scheme.map_basicOpen_map (X : Scheme.{u}) (U : Opens X) (r : X.presheaf.obj (op U)) :
U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen <|
X.presheaf.map (eqToHom U.openEmbedding_obj_top).op r) = X.basicOpen r := by
rw [Scheme.map_basicOpen', Scheme.basicOpen_res_eq, Scheme.basicOpen_res_eq]
-- Porting note: `simps` can't synthesize `obj_left, obj_hom, mapLeft`
/-- The functor taking open subsets of `X` to open subschemes of `X`. -/
-- @[simps obj_left obj_hom mapLeft]
def Scheme.restrictFunctor : Opens X ⥤ Over X where
obj U := Over.mk (ιOpens U)
map {U V} i :=
Over.homMk
(IsOpenImmersion.lift (ιOpens V) (ιOpens U) <| by
dsimp [restrict, ofRestrict, LocallyRingedSpace.ofRestrict, Opens.coe_inclusion]
rw [Subtype.range_val, Subtype.range_val]
exact i.le)
(IsOpenImmersion.lift_fac _ _ _)
map_id U := by
ext1
dsimp only [Over.homMk_left, Over.id_left]
rw [← cancel_mono (ιOpens U), Category.id_comp,
IsOpenImmersion.lift_fac]
map_comp {U V W} i j := by
ext1
dsimp only [Over.homMk_left, Over.comp_left]
rw [← cancel_mono (ιOpens W), Category.assoc]
iterate 3 rw [IsOpenImmersion.lift_fac]
#align algebraic_geometry.Scheme.restrict_functor AlgebraicGeometry.Scheme.restrictFunctor
@[simp] lemma Scheme.restrictFunctor_obj_left (U : Opens X) :
(X.restrictFunctor.obj U).left = X ∣_ᵤ U := rfl
@[simp] lemma Scheme.restrictFunctor_obj_hom (U : Opens X) :
(X.restrictFunctor.obj U).hom = Scheme.ιOpens U := rfl
@[simp] lemma Scheme.restrictFunctor_map_left {U V : Opens X} (i : U ⟶ V) :
(X.restrictFunctor.map i).left = IsOpenImmersion.lift (ιOpens V) (ιOpens U) (by
dsimp [ofRestrict, LocallyRingedSpace.ofRestrict, Opens.inclusion]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [ContinuousMap.coe_mk, ContinuousMap.coe_mk]; rw [Subtype.range_val, Subtype.range_val]
exact i.le) := rfl
-- Porting note: the `by ...` used to be automatically done by unification magic
@[reassoc]
theorem Scheme.restrictFunctor_map_ofRestrict {U V : Opens X} (i : U ⟶ V) :
(X.restrictFunctor.map i).1 ≫ ιOpens V = ιOpens U :=
IsOpenImmersion.lift_fac _ _ (by
dsimp [restrict, ofRestrict, LocallyRingedSpace.ofRestrict]
rw [Subtype.range_val, Subtype.range_val]
exact i.le)
#align algebraic_geometry.Scheme.restrict_functor_map_ofRestrict AlgebraicGeometry.Scheme.restrictFunctor_map_ofRestrict
theorem Scheme.restrictFunctor_map_base {U V : Opens X} (i : U ⟶ V) :
(X.restrictFunctor.map i).1.1.base = (Opens.toTopCat _).map i := by
ext a; refine Subtype.ext ?_ -- Porting note: `ext` did not pick up `Subtype.ext`
exact (congr_arg (fun f : X.restrict U.openEmbedding ⟶ X => f.1.base a)
(X.restrictFunctor_map_ofRestrict i))
#align algebraic_geometry.Scheme.restrict_functor_map_base AlgebraicGeometry.Scheme.restrictFunctor_map_base
| Mathlib/AlgebraicGeometry/Restrict.lean | 138 | 144 | theorem Scheme.restrictFunctor_map_app_aux {U V : Opens X} (i : U ⟶ V) (W : Opens V) :
U.openEmbedding.isOpenMap.functor.obj ((X.restrictFunctor.map i).1 ⁻¹ᵁ W) ≤
V.openEmbedding.isOpenMap.functor.obj W := by |
simp only [← SetLike.coe_subset_coe, IsOpenMap.functor_obj_coe, Set.image_subset_iff,
Scheme.restrictFunctor_map_base, Opens.map_coe, Opens.inclusion_apply]
rintro _ h
exact ⟨_, h, rfl⟩
|
/-
Copyright (c) 2023 Joachim Breitner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joachim Breitner
-/
import Mathlib.Probability.ProbabilityMassFunction.Basic
import Mathlib.Probability.ProbabilityMassFunction.Constructions
import Mathlib.MeasureTheory.Integral.Bochner
/-!
# Integrals with a measure derived from probability mass functions.
This files connects `PMF` with `integral`. The main result is that the integral (i.e. the expected
value) with regard to a measure derived from a `PMF` is a sum weighted by the `PMF`.
It also provides the expected value for specific probability mass functions.
-/
namespace PMF
open MeasureTheory ENNReal TopologicalSpace
section General
variable {α : Type*} [MeasurableSpace α] [MeasurableSingletonClass α]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
| Mathlib/Probability/ProbabilityMassFunction/Integrals.lean | 28 | 41 | theorem integral_eq_tsum (p : PMF α) (f : α → E) (hf : Integrable f p.toMeasure) :
∫ a, f a ∂(p.toMeasure) = ∑' a, (p a).toReal • f a := calc
_ = ∫ a in p.support, f a ∂(p.toMeasure) := by | rw [restrict_toMeasure_support p]
_ = ∑' (a : support p), (p.toMeasure {a.val}).toReal • f a := by
apply integral_countable f p.support_countable
rwa [restrict_toMeasure_support p]
_ = ∑' (a : support p), (p a).toReal • f a := by
congr with x; congr 2
apply PMF.toMeasure_apply_singleton p x (MeasurableSet.singleton _)
_ = ∑' a, (p a).toReal • f a :=
tsum_subtype_eq_of_support_subset <| by calc
(fun a ↦ (p a).toReal • f a).support ⊆ (fun a ↦ (p a).toReal).support :=
Function.support_smul_subset_left _ _
_ ⊆ support p := fun x h1 h2 => h1 (by simp [h2])
|
/-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Data.Fintype.Card
#align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d"
/-!
# Multiset coercion to type
This module defines a `CoeSort` instance for multisets and gives it a `Fintype` instance.
It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of
a multiset. These coercions and definitions make it easier to sum over multisets using existing
`Finset` theory.
## Main definitions
* A coercion from `m : Multiset α` to a `Type*`. Each `x : m` has two components.
The first, `x.1`, can be obtained via the coercion `↑x : α`,
and it yields the underlying element of the multiset.
The second, `x.2`, is a term of `Fin (m.count x)`,
and its function is to ensure each term appears with the correct multiplicity.
Note that this coercion requires `DecidableEq α` due to the definition using `Multiset.count`.
* `Multiset.toEnumFinset` is a `Finset` version of this.
* `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion
and whose second component enumerates elements with multiplicity.
* `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`.
## Tags
multiset enumeration
-/
variable {α : Type*} [DecidableEq α] {m : Multiset α}
/-- Auxiliary definition for the `CoeSort` instance. This prevents the `CoeOut m α`
instance from inadvertently applying to other sigma types. -/
def Multiset.ToType (m : Multiset α) : Type _ := (x : α) × Fin (m.count x)
#align multiset.to_type Multiset.ToType
/-- Create a type that has the same number of elements as the multiset.
Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`.
This way repeated elements of a multiset appear multiple times from different values of `i`. -/
instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩
example : DecidableEq m := inferInstanceAs <| DecidableEq ((x : α) × Fin (m.count x))
-- Porting note: syntactic equality
#noalign multiset.coe_sort_eq
/-- Constructor for terms of the coercion of `m` to a type.
This helps Lean pick up the correct instances. -/
@[reducible, match_pattern]
def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m :=
⟨x, i⟩
#align multiset.mk_to_type Multiset.mkToType
/-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first
component. -/
instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α :=
⟨fun x ↦ x.1⟩
#align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ
-- Porting note: syntactic equality
#noalign multiset.fst_coe_eq_coe
-- Syntactic equality
#noalign multiset.coe_eq
-- @[simp] -- Porting note (#10685): dsimp can prove this
theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x :=
rfl
#align multiset.coe_mk Multiset.coe_mk
@[simp] lemma Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (by have := x.2.2; omega)
#align multiset.coe_mem Multiset.coe_mem
@[simp]
protected theorem Multiset.forall_coe (p : m → Prop) :
(∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ :=
Sigma.forall
#align multiset.forall_coe Multiset.forall_coe
@[simp]
protected theorem Multiset.exists_coe (p : m → Prop) :
(∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ :=
Sigma.exists
#align multiset.exists_coe Multiset.exists_coe
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } :=
Fintype.ofFinset
(m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩)
(by
rintro ⟨x, i⟩
simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range,
Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq]
simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp]
exact fun h ↦ Multiset.count_pos.mp (by omega))
/-- Construct a finset whose elements enumerate the elements of the multiset `m`.
The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times
then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/
def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) :=
{ p : α × ℕ | p.2 < m.count p.1 }.toFinset
#align multiset.to_enum_finset Multiset.toEnumFinset
@[simp]
theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) :
p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 :=
Set.mem_toFinset
#align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset
theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m :=
have := (m.mem_toEnumFinset p).mp h; Multiset.count_pos.mp (by omega)
#align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset
@[mono]
theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) :
m₁.toEnumFinset ⊆ m₂.toEnumFinset := by
intro p
simp only [Multiset.mem_toEnumFinset]
exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1)
#align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono
@[simp]
theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} :
m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by
refine ⟨fun h ↦ ?_, Multiset.toEnumFinset_mono⟩
rw [Multiset.le_iff_count]
intro x
by_cases hx : x ∈ m₁
· apply Nat.le_of_pred_lt
have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by
rw [Multiset.mem_toEnumFinset]
exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx))
simpa only [Multiset.mem_toEnumFinset] using h this
· simp [hx]
#align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats.
If you are looking for the function `m → α`, that would be plain `(↑)`. -/
@[simps]
def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where
toFun x := (x, x.2)
inj' := by
intro ⟨x, i, hi⟩ ⟨y, j, hj⟩
rintro ⟨⟩
rfl
#align multiset.coe_embedding Multiset.coeEmbedding
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce
that `Finset` to a type. -/
@[simps]
def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where
toFun x :=
⟨m.coeEmbedding x, by
rw [Multiset.mem_toEnumFinset]
exact x.2.2⟩
invFun x :=
⟨x.1.1, x.1.2, by
rw [← Multiset.mem_toEnumFinset]
exact x.2⟩
left_inv := by
rintro ⟨x, i, h⟩
rfl
right_inv := by
rintro ⟨⟨x, i⟩, h⟩
rfl
#align multiset.coe_equiv Multiset.coeEquiv
@[simp]
theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) :
m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl
#align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans
@[irreducible]
instance Multiset.fintypeCoe : Fintype m :=
Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm
#align multiset.fintype_coe Multiset.fintypeCoe
theorem Multiset.map_univ_coeEmbedding (m : Multiset α) :
(Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by
ext ⟨x, i⟩
simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply,
Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk,
exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff,
true_and_iff]
#align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) :
(m.toEnumFinset.filter fun p ↦ x = p.1) =
(Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by
ext ⟨y, i⟩
simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map,
Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop,
exists_eq_right_right', and_congr_left_iff]
rintro rfl
rfl
#align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq
@[simp]
theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by
ext x
simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq,
Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range]
#align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst
@[simp]
theorem Multiset.image_toEnumFinset_fst (m : Multiset α) :
m.toEnumFinset.image Prod.fst = m.toFinset := by
rw [Finset.image, Multiset.map_toEnumFinset_fst]
#align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst
@[simp]
| Mathlib/Data/Multiset/Fintype.lean | 219 | 224 | theorem Multiset.map_univ_coe (m : Multiset α) :
(Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by |
have := m.map_toEnumFinset_fst
rw [← m.map_univ_coeEmbedding] at this
simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map,
Function.comp_apply] using this
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Data.List.Lattice
import Mathlib.Data.List.Range
import Mathlib.Data.Bool.Basic
#align_import data.list.intervals from "leanprover-community/mathlib"@"7b78d1776212a91ecc94cf601f83bdcc46b04213"
/-!
# Intervals in ℕ
This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m`
and strictly less than `n`.
## TODO
- Define `Ioo` and `Icc`, state basic lemmas about them.
- Also do the versions for integers?
- One could generalise even further, defining 'locally finite partial orders', for which
`Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model.
- Once the above is done, get rid of `Data.Int.range` (and maybe `List.range'`?).
-/
open Nat
namespace List
/-- `Ico n m` is the list of natural numbers `n ≤ x < m`.
(Ico stands for "interval, closed-open".)
See also `Data/Set/Intervals.lean` for `Set.Ico`, modelling intervals in general preorders, and
`Multiset.Ico` and `Finset.Ico` for `n ≤ x < m` as a multiset or as a finset.
-/
def Ico (n m : ℕ) : List ℕ :=
range' n (m - n)
#align list.Ico List.Ico
namespace Ico
theorem zero_bot (n : ℕ) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range']
#align list.Ico.zero_bot List.Ico.zero_bot
@[simp]
theorem length (n m : ℕ) : length (Ico n m) = m - n := by
dsimp [Ico]
simp [length_range', autoParam]
#align list.Ico.length List.Ico.length
theorem pairwise_lt (n m : ℕ) : Pairwise (· < ·) (Ico n m) := by
dsimp [Ico]
simp [pairwise_lt_range', autoParam]
#align list.Ico.pairwise_lt List.Ico.pairwise_lt
theorem nodup (n m : ℕ) : Nodup (Ico n m) := by
dsimp [Ico]
simp [nodup_range', autoParam]
#align list.Ico.nodup List.Ico.nodup
@[simp]
theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := by
suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m by simp [Ico, this]
rcases le_total n m with hnm | hmn
· rw [Nat.add_sub_cancel' hnm]
· rw [Nat.sub_eq_zero_iff_le.mpr hmn, Nat.add_zero]
exact
and_congr_right fun hnl =>
Iff.intro (fun hln => (not_le_of_gt hln hnl).elim) fun hlm => lt_of_lt_of_le hlm hmn
#align list.Ico.mem List.Ico.mem
theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] := by
simp [Ico, Nat.sub_eq_zero_iff_le.mpr h]
#align list.Ico.eq_nil_of_le List.Ico.eq_nil_of_le
theorem map_add (n m k : ℕ) : (Ico n m).map (k + ·) = Ico (n + k) (m + k) := by
rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k]
#align list.Ico.map_add List.Ico.map_add
theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) :
((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by
rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' _ _ _ h₁]
#align list.Ico.map_sub List.Ico.map_sub
@[simp]
theorem self_empty {n : ℕ} : Ico n n = [] :=
eq_nil_of_le (le_refl n)
#align list.Ico.self_empty List.Ico.self_empty
@[simp]
theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n :=
Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le
#align list.Ico.eq_empty_iff List.Ico.eq_empty_iff
| Mathlib/Data/List/Intervals.lean | 95 | 100 | theorem append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) :
Ico n m ++ Ico m l = Ico n l := by |
dsimp only [Ico]
convert range'_append n (m-n) (l-m) 1 using 2
· rw [Nat.one_mul, Nat.add_sub_cancel' hnm]
· rw [Nat.sub_add_sub_cancel hml hnm]
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Aaron Anderson
-/
import Mathlib.Algebra.Order.Module.Defs
import Mathlib.Data.Finsupp.Basic
#align_import data.finsupp.order from "leanprover-community/mathlib"@"1d29de43a5ba4662dd33b5cfeecfc2a27a5a8a29"
/-!
# Pointwise order on finitely supported functions
This file lifts order structures on `α` to `ι →₀ α`.
## Main declarations
* `Finsupp.orderEmbeddingToFun`: The order embedding from finitely supported functions to
functions.
-/
-- Porting note: removed from module documentation because it moved to `Data.Finsupp.Multiset`
-- TODO: move to `Data.Finsupp.Multiset` when that is ported
-- * `Finsupp.orderIsoMultiset`: The order isomorphism between `ℕ`-valued finitely supported
-- functions and multisets.
noncomputable section
open Finset
variable {ι α β : Type*}
namespace Finsupp
/-! ### Order structures -/
section Zero
variable [Zero α]
section LE
variable [LE α] {f g : ι →₀ α}
instance instLEFinsupp : LE (ι →₀ α) :=
⟨fun f g => ∀ i, f i ≤ g i⟩
lemma le_def : f ≤ g ↔ ∀ i, f i ≤ g i := Iff.rfl
#align finsupp.le_def Finsupp.le_def
@[simp, norm_cast] lemma coe_le_coe : ⇑f ≤ g ↔ f ≤ g := Iff.rfl
/-- The order on `Finsupp`s over a partial order embeds into the order on functions -/
def orderEmbeddingToFun : (ι →₀ α) ↪o (ι → α) where
toFun f := f
inj' f g h :=
Finsupp.ext fun i => by
dsimp at h
rw [h]
map_rel_iff' := coe_le_coe
#align finsupp.order_embedding_to_fun Finsupp.orderEmbeddingToFun
@[simp]
theorem orderEmbeddingToFun_apply {f : ι →₀ α} {i : ι} : orderEmbeddingToFun f i = f i :=
rfl
#align finsupp.order_embedding_to_fun_apply Finsupp.orderEmbeddingToFun_apply
end LE
section Preorder
variable [Preorder α] {f g : ι →₀ α}
instance preorder : Preorder (ι →₀ α) :=
{ Finsupp.instLEFinsupp with
le_refl := fun f i => le_rfl
le_trans := fun f g h hfg hgh i => (hfg i).trans (hgh i) }
lemma lt_def : f < g ↔ f ≤ g ∧ ∃ i, f i < g i := Pi.lt_def
@[simp, norm_cast] lemma coe_lt_coe : ⇑f < g ↔ f < g := Iff.rfl
lemma coe_mono : Monotone (Finsupp.toFun : (ι →₀ α) → ι → α) := fun _ _ ↦ id
#align finsupp.monotone_to_fun Finsupp.coe_mono
lemma coe_strictMono : Monotone (Finsupp.toFun : (ι →₀ α) → ι → α) := fun _ _ ↦ id
end Preorder
instance partialorder [PartialOrder α] : PartialOrder (ι →₀ α) :=
{ Finsupp.preorder with le_antisymm :=
fun _f _g hfg hgf => ext fun i => (hfg i).antisymm (hgf i) }
instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (ι →₀ α) :=
{ Finsupp.partialorder with
inf := zipWith (· ⊓ ·) (inf_idem _)
inf_le_left := fun _f _g _i => inf_le_left
inf_le_right := fun _f _g _i => inf_le_right
le_inf := fun _f _g _i h1 h2 s => le_inf (h1 s) (h2 s) }
@[simp]
theorem inf_apply [SemilatticeInf α] {i : ι} {f g : ι →₀ α} : (f ⊓ g) i = f i ⊓ g i :=
rfl
#align finsupp.inf_apply Finsupp.inf_apply
instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (ι →₀ α) :=
{ Finsupp.partialorder with
sup := zipWith (· ⊔ ·) (sup_idem _)
le_sup_left := fun _f _g _i => le_sup_left
le_sup_right := fun _f _g _i => le_sup_right
sup_le := fun _f _g _h hf hg i => sup_le (hf i) (hg i) }
@[simp]
theorem sup_apply [SemilatticeSup α] {i : ι} {f g : ι →₀ α} : (f ⊔ g) i = f i ⊔ g i :=
rfl
#align finsupp.sup_apply Finsupp.sup_apply
instance lattice [Lattice α] : Lattice (ι →₀ α) :=
{ Finsupp.semilatticeInf, Finsupp.semilatticeSup with }
#align finsupp.lattice Finsupp.lattice
section Lattice
variable [DecidableEq ι] [Lattice α] (f g : ι →₀ α)
theorem support_inf_union_support_sup : (f ⊓ g).support ∪ (f ⊔ g).support = f.support ∪ g.support :=
coe_injective <| compl_injective <| by ext; simp [inf_eq_and_sup_eq_iff]
#align finsupp.support_inf_union_support_sup Finsupp.support_inf_union_support_sup
theorem support_sup_union_support_inf : (f ⊔ g).support ∪ (f ⊓ g).support = f.support ∪ g.support :=
(union_comm _ _).trans <| support_inf_union_support_sup _ _
#align finsupp.support_sup_union_support_inf Finsupp.support_sup_union_support_inf
end Lattice
end Zero
/-! ### Algebraic order structures -/
instance orderedAddCommMonoid [OrderedAddCommMonoid α] : OrderedAddCommMonoid (ι →₀ α) :=
{ Finsupp.instAddCommMonoid, Finsupp.partialorder with
add_le_add_left := fun _a _b h c s => add_le_add_left (h s) (c s) }
instance orderedCancelAddCommMonoid [OrderedCancelAddCommMonoid α] :
OrderedCancelAddCommMonoid (ι →₀ α) :=
{ Finsupp.orderedAddCommMonoid with
le_of_add_le_add_left := fun _f _g _i h s => le_of_add_le_add_left (h s) }
instance contravariantClass [OrderedAddCommMonoid α] [ContravariantClass α α (· + ·) (· ≤ ·)] :
ContravariantClass (ι →₀ α) (ι →₀ α) (· + ·) (· ≤ ·) :=
⟨fun _f _g _h H x => le_of_add_le_add_left <| H x⟩
section SMulZeroClass
variable [Zero α] [Preorder α] [Zero β] [Preorder β] [SMulZeroClass α β]
instance instPosSMulMono [PosSMulMono α β] : PosSMulMono α (ι →₀ β) :=
PosSMulMono.lift _ coe_le_coe coe_smul
instance instSMulPosMono [SMulPosMono α β] : SMulPosMono α (ι →₀ β) :=
SMulPosMono.lift _ coe_le_coe coe_smul coe_zero
instance instPosSMulReflectLE [PosSMulReflectLE α β] : PosSMulReflectLE α (ι →₀ β) :=
PosSMulReflectLE.lift _ coe_le_coe coe_smul
instance instSMulPosReflectLE [SMulPosReflectLE α β] : SMulPosReflectLE α (ι →₀ β) :=
SMulPosReflectLE.lift _ coe_le_coe coe_smul coe_zero
end SMulZeroClass
section SMulWithZero
variable [Zero α] [PartialOrder α] [Zero β] [PartialOrder β] [SMulWithZero α β]
instance instPosSMulStrictMono [PosSMulStrictMono α β] : PosSMulStrictMono α (ι →₀ β) :=
PosSMulStrictMono.lift _ coe_le_coe coe_smul
instance instSMulPosStrictMono [SMulPosStrictMono α β] : SMulPosStrictMono α (ι →₀ β) :=
SMulPosStrictMono.lift _ coe_le_coe coe_smul coe_zero
-- `PosSMulReflectLT α (ι →₀ β)` already follows from the other instances
instance instSMulPosReflectLT [SMulPosReflectLT α β] : SMulPosReflectLT α (ι →₀ β) :=
SMulPosReflectLT.lift _ coe_le_coe coe_smul coe_zero
end SMulWithZero
section CanonicallyOrderedAddCommMonoid
variable [CanonicallyOrderedAddCommMonoid α] {f g : ι →₀ α}
instance orderBot : OrderBot (ι →₀ α) where
bot := 0
bot_le := by simp only [le_def, coe_zero, Pi.zero_apply, imp_true_iff, zero_le]
protected theorem bot_eq_zero : (⊥ : ι →₀ α) = 0 :=
rfl
#align finsupp.bot_eq_zero Finsupp.bot_eq_zero
@[simp]
theorem add_eq_zero_iff (f g : ι →₀ α) : f + g = 0 ↔ f = 0 ∧ g = 0 := by
simp [DFunLike.ext_iff, forall_and]
#align finsupp.add_eq_zero_iff Finsupp.add_eq_zero_iff
theorem le_iff' (f g : ι →₀ α) {s : Finset ι} (hf : f.support ⊆ s) : f ≤ g ↔ ∀ i ∈ s, f i ≤ g i :=
⟨fun h s _hs => h s, fun h s => by
classical exact
if H : s ∈ f.support then h s (hf H) else (not_mem_support_iff.1 H).symm ▸ zero_le (g s)⟩
#align finsupp.le_iff' Finsupp.le_iff'
theorem le_iff (f g : ι →₀ α) : f ≤ g ↔ ∀ i ∈ f.support, f i ≤ g i :=
le_iff' f g <| Subset.refl _
#align finsupp.le_iff Finsupp.le_iff
lemma support_monotone : Monotone (support (α := ι) (M := α)) :=
fun f g h a ha ↦ by rw [mem_support_iff, ← pos_iff_ne_zero] at ha ⊢; exact ha.trans_le (h _)
lemma support_mono (hfg : f ≤ g) : f.support ⊆ g.support := support_monotone hfg
instance decidableLE [DecidableRel (@LE.le α _)] : DecidableRel (@LE.le (ι →₀ α) _) := fun f g =>
decidable_of_iff _ (le_iff f g).symm
#align finsupp.decidable_le Finsupp.decidableLE
instance decidableLT [DecidableRel (@LE.le α _)] : DecidableRel (@LT.lt (ι →₀ α) _) :=
decidableLTOfDecidableLE
@[simp]
theorem single_le_iff {i : ι} {x : α} {f : ι →₀ α} : single i x ≤ f ↔ x ≤ f i :=
(le_iff' _ _ support_single_subset).trans <| by simp
#align finsupp.single_le_iff Finsupp.single_le_iff
variable [Sub α] [OrderedSub α] {f g : ι →₀ α} {i : ι} {a b : α}
/-- This is called `tsub` for truncated subtraction, to distinguish it with subtraction in an
additive group. -/
instance tsub : Sub (ι →₀ α) :=
⟨zipWith (fun m n => m - n) (tsub_self 0)⟩
#align finsupp.tsub Finsupp.tsub
instance orderedSub : OrderedSub (ι →₀ α) :=
⟨fun _n _m _k => forall_congr' fun _x => tsub_le_iff_right⟩
instance : CanonicallyOrderedAddCommMonoid (ι →₀ α) :=
{ Finsupp.orderBot,
Finsupp.orderedAddCommMonoid with
exists_add_of_le := fun {f g} h => ⟨g - f, ext fun x => (add_tsub_cancel_of_le <| h x).symm⟩
le_self_add := fun _f _g _x => le_self_add }
@[simp, norm_cast] lemma coe_tsub (f g : ι →₀ α) : ⇑(f - g) = f - g := rfl
#align finsupp.coe_tsub Finsupp.coe_tsub
theorem tsub_apply (f g : ι →₀ α) (a : ι) : (f - g) a = f a - g a :=
rfl
#align finsupp.tsub_apply Finsupp.tsub_apply
@[simp]
theorem single_tsub : single i (a - b) = single i a - single i b := by
ext j
obtain rfl | h := eq_or_ne i j
· rw [tsub_apply, single_eq_same, single_eq_same, single_eq_same]
· rw [tsub_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, tsub_self]
#align finsupp.single_tsub Finsupp.single_tsub
theorem support_tsub {f1 f2 : ι →₀ α} : (f1 - f2).support ⊆ f1.support := by
simp (config := { contextual := true }) only [subset_iff, tsub_eq_zero_iff_le, mem_support_iff,
Ne, coe_tsub, Pi.sub_apply, not_imp_not, zero_le, imp_true_iff]
#align finsupp.support_tsub Finsupp.support_tsub
| Mathlib/Data/Finsupp/Order.lean | 265 | 267 | theorem subset_support_tsub [DecidableEq ι] {f1 f2 : ι →₀ α} :
f1.support \ f2.support ⊆ (f1 - f2).support := by |
simp (config := { contextual := true }) [subset_iff]
|
/-
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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.Algebra.Module.Submodule.LinearMap
/-!
# `map` and `comap` for `Submodule`s
## Main declarations
* `Submodule.map`: The pushforward of a submodule `p ⊆ M` by `f : M → M₂`
* `Submodule.comap`: The pullback of a submodule `p ⊆ M₂` along `f : M → M₂`
* `Submodule.giMapComap`: `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective.
* `Submodule.gciMapComap`: `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective.
## Tags
submodule, subspace, linear map, pushforward, pullback
-/
open Function Pointwise Set
variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*}
variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
namespace Submodule
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable (p p' : Submodule R M) (q q' : Submodule R₂ M₂)
variable {x : M}
section
variable [RingHomSurjective σ₁₂] {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
/-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/
def map (f : F) (p : Submodule R M) : Submodule R₂ M₂ :=
{ p.toAddSubmonoid.map f with
carrier := f '' p
smul_mem' := by
rintro c x ⟨y, hy, rfl⟩
obtain ⟨a, rfl⟩ := σ₁₂.surjective c
exact ⟨_, p.smul_mem a hy, map_smulₛₗ f _ _⟩ }
#align submodule.map Submodule.map
@[simp]
theorem map_coe (f : F) (p : Submodule R M) : (map f p : Set M₂) = f '' p :=
rfl
#align submodule.map_coe Submodule.map_coe
theorem map_toAddSubmonoid (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) :
(p.map f).toAddSubmonoid = p.toAddSubmonoid.map (f : M →+ M₂) :=
SetLike.coe_injective rfl
#align submodule.map_to_add_submonoid Submodule.map_toAddSubmonoid
theorem map_toAddSubmonoid' (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) :
(p.map f).toAddSubmonoid = p.toAddSubmonoid.map f :=
SetLike.coe_injective rfl
#align submodule.map_to_add_submonoid' Submodule.map_toAddSubmonoid'
@[simp]
theorem _root_.AddMonoidHom.coe_toIntLinearMap_map {A A₂ : Type*} [AddCommGroup A] [AddCommGroup A₂]
(f : A →+ A₂) (s : AddSubgroup A) :
(AddSubgroup.toIntSubmodule s).map f.toIntLinearMap =
AddSubgroup.toIntSubmodule (s.map f) := rfl
@[simp]
theorem _root_.MonoidHom.coe_toAdditive_map {G G₂ : Type*} [Group G] [Group G₂] (f : G →* G₂)
(s : Subgroup G) :
s.toAddSubgroup.map (MonoidHom.toAdditive f) = Subgroup.toAddSubgroup (s.map f) := rfl
@[simp]
theorem _root_.AddMonoidHom.coe_toMultiplicative_map {G G₂ : Type*} [AddGroup G] [AddGroup G₂]
(f : G →+ G₂) (s : AddSubgroup G) :
s.toSubgroup.map (AddMonoidHom.toMultiplicative f) = AddSubgroup.toSubgroup (s.map f) := rfl
@[simp]
theorem mem_map {f : F} {p : Submodule R M} {x : M₂} : x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x :=
Iff.rfl
#align submodule.mem_map Submodule.mem_map
theorem mem_map_of_mem {f : F} {p : Submodule R M} {r} (h : r ∈ p) : f r ∈ map f p :=
Set.mem_image_of_mem _ h
#align submodule.mem_map_of_mem Submodule.mem_map_of_mem
theorem apply_coe_mem_map (f : F) {p : Submodule R M} (r : p) : f r ∈ map f p :=
mem_map_of_mem r.prop
#align submodule.apply_coe_mem_map Submodule.apply_coe_mem_map
@[simp]
theorem map_id : map (LinearMap.id : M →ₗ[R] M) p = p :=
Submodule.ext fun a => by simp
#align submodule.map_id Submodule.map_id
theorem map_comp [RingHomSurjective σ₂₃] [RingHomSurjective σ₁₃] (f : M →ₛₗ[σ₁₂] M₂)
(g : M₂ →ₛₗ[σ₂₃] M₃) (p : Submodule R M) : map (g.comp f : M →ₛₗ[σ₁₃] M₃) p = map g (map f p) :=
SetLike.coe_injective <| by simp only [← image_comp, map_coe, LinearMap.coe_comp, comp_apply]
#align submodule.map_comp Submodule.map_comp
theorem map_mono {f : F} {p p' : Submodule R M} : p ≤ p' → map f p ≤ map f p' :=
image_subset _
#align submodule.map_mono Submodule.map_mono
@[simp]
theorem map_zero : map (0 : M →ₛₗ[σ₁₂] M₂) p = ⊥ :=
have : ∃ x : M, x ∈ p := ⟨0, p.zero_mem⟩
ext <| by simp [this, eq_comm]
#align submodule.map_zero Submodule.map_zero
theorem map_add_le (f g : M →ₛₗ[σ₁₂] M₂) : map (f + g) p ≤ map f p ⊔ map g p := by
rintro x ⟨m, hm, rfl⟩
exact add_mem_sup (mem_map_of_mem hm) (mem_map_of_mem hm)
#align submodule.map_add_le Submodule.map_add_le
theorem map_inf_le (f : F) {p q : Submodule R M} :
(p ⊓ q).map f ≤ p.map f ⊓ q.map f :=
image_inter_subset f p q
theorem map_inf (f : F) {p q : Submodule R M} (hf : Injective f) :
(p ⊓ q).map f = p.map f ⊓ q.map f :=
SetLike.coe_injective <| Set.image_inter hf
theorem range_map_nonempty (N : Submodule R M) :
(Set.range (fun ϕ => Submodule.map ϕ N : (M →ₛₗ[σ₁₂] M₂) → Submodule R₂ M₂)).Nonempty :=
⟨_, Set.mem_range.mpr ⟨0, rfl⟩⟩
#align submodule.range_map_nonempty Submodule.range_map_nonempty
end
section SemilinearMap
variable {σ₂₁ : R₂ →+* R} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
/-- The pushforward of a submodule by an injective linear map is
linearly equivalent to the original submodule. See also `LinearEquiv.submoduleMap` for a
computable version when `f` has an explicit inverse. -/
noncomputable def equivMapOfInjective (f : F) (i : Injective f) (p : Submodule R M) :
p ≃ₛₗ[σ₁₂] p.map f :=
{ Equiv.Set.image f p i with
map_add' := by
intros
simp only [coe_add, map_add, Equiv.toFun_as_coe, Equiv.Set.image_apply]
rfl
map_smul' := by
intros
-- Note: #8386 changed `map_smulₛₗ` into `map_smulₛₗ _`
simp only [coe_smul_of_tower, map_smulₛₗ _, Equiv.toFun_as_coe, Equiv.Set.image_apply]
rfl }
#align submodule.equiv_map_of_injective Submodule.equivMapOfInjective
@[simp]
theorem coe_equivMapOfInjective_apply (f : F) (i : Injective f) (p : Submodule R M) (x : p) :
(equivMapOfInjective f i p x : M₂) = f x :=
rfl
#align submodule.coe_equiv_map_of_injective_apply Submodule.coe_equivMapOfInjective_apply
@[simp]
theorem map_equivMapOfInjective_symm_apply (f : F) (i : Injective f) (p : Submodule R M)
(x : p.map f) : f ((equivMapOfInjective f i p).symm x) = x := by
rw [← LinearEquiv.apply_symm_apply (equivMapOfInjective f i p) x, coe_equivMapOfInjective_apply,
i.eq_iff, LinearEquiv.apply_symm_apply]
/-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/
def comap (f : F) (p : Submodule R₂ M₂) : Submodule R M :=
{ p.toAddSubmonoid.comap f with
carrier := f ⁻¹' p
-- Note: #8386 added `map_smulₛₗ _`
smul_mem' := fun a x h => by simp [p.smul_mem (σ₁₂ a) h, map_smulₛₗ _] }
#align submodule.comap Submodule.comap
@[simp]
theorem comap_coe (f : F) (p : Submodule R₂ M₂) : (comap f p : Set M) = f ⁻¹' p :=
rfl
#align submodule.comap_coe Submodule.comap_coe
@[simp]
theorem AddMonoidHom.coe_toIntLinearMap_comap {A A₂ : Type*} [AddCommGroup A] [AddCommGroup A₂]
(f : A →+ A₂) (s : AddSubgroup A₂) :
(AddSubgroup.toIntSubmodule s).comap f.toIntLinearMap =
AddSubgroup.toIntSubmodule (s.comap f) := rfl
@[simp]
theorem mem_comap {f : F} {p : Submodule R₂ M₂} : x ∈ comap f p ↔ f x ∈ p :=
Iff.rfl
#align submodule.mem_comap Submodule.mem_comap
@[simp]
theorem comap_id : comap (LinearMap.id : M →ₗ[R] M) p = p :=
SetLike.coe_injective rfl
#align submodule.comap_id Submodule.comap_id
theorem comap_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃) (p : Submodule R₃ M₃) :
comap (g.comp f : M →ₛₗ[σ₁₃] M₃) p = comap f (comap g p) :=
rfl
#align submodule.comap_comp Submodule.comap_comp
theorem comap_mono {f : F} {q q' : Submodule R₂ M₂} : q ≤ q' → comap f q ≤ comap f q' :=
preimage_mono
#align submodule.comap_mono Submodule.comap_mono
theorem le_comap_pow_of_le_comap (p : Submodule R M) {f : M →ₗ[R] M} (h : p ≤ p.comap f) (k : ℕ) :
p ≤ p.comap (f ^ k) := by
induction' k with k ih
· simp [LinearMap.one_eq_id]
· simp [LinearMap.iterate_succ, comap_comp, h.trans (comap_mono ih)]
#align submodule.le_comap_pow_of_le_comap Submodule.le_comap_pow_of_le_comap
section
variable [RingHomSurjective σ₁₂]
theorem map_le_iff_le_comap {f : F} {p : Submodule R M} {q : Submodule R₂ M₂} :
map f p ≤ q ↔ p ≤ comap f q :=
image_subset_iff
#align submodule.map_le_iff_le_comap Submodule.map_le_iff_le_comap
theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f)
| _, _ => map_le_iff_le_comap
#align submodule.gc_map_comap Submodule.gc_map_comap
@[simp]
theorem map_bot (f : F) : map f ⊥ = ⊥ :=
(gc_map_comap f).l_bot
#align submodule.map_bot Submodule.map_bot
@[simp]
theorem map_sup (f : F) : map f (p ⊔ p') = map f p ⊔ map f p' :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
#align submodule.map_sup Submodule.map_sup
@[simp]
theorem map_iSup {ι : Sort*} (f : F) (p : ι → Submodule R M) :
map f (⨆ i, p i) = ⨆ i, map f (p i) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
#align submodule.map_supr Submodule.map_iSup
end
@[simp]
theorem comap_top (f : F) : comap f ⊤ = ⊤ :=
rfl
#align submodule.comap_top Submodule.comap_top
@[simp]
theorem comap_inf (f : F) : comap f (q ⊓ q') = comap f q ⊓ comap f q' :=
rfl
#align submodule.comap_inf Submodule.comap_inf
@[simp]
theorem comap_iInf [RingHomSurjective σ₁₂] {ι : Sort*} (f : F) (p : ι → Submodule R₂ M₂) :
comap f (⨅ i, p i) = ⨅ i, comap f (p i) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
#align submodule.comap_infi Submodule.comap_iInf
@[simp]
theorem comap_zero : comap (0 : M →ₛₗ[σ₁₂] M₂) q = ⊤ :=
ext <| by simp
#align submodule.comap_zero Submodule.comap_zero
theorem map_comap_le [RingHomSurjective σ₁₂] (f : F) (q : Submodule R₂ M₂) :
map f (comap f q) ≤ q :=
(gc_map_comap f).l_u_le _
#align submodule.map_comap_le Submodule.map_comap_le
theorem le_comap_map [RingHomSurjective σ₁₂] (f : F) (p : Submodule R M) : p ≤ comap f (map f p) :=
(gc_map_comap f).le_u_l _
#align submodule.le_comap_map Submodule.le_comap_map
section GaloisInsertion
variable {f : F} (hf : Surjective f)
variable [RingHomSurjective σ₁₂]
/-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/
def giMapComap : GaloisInsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisInsertion fun S x hx => by
rcases hf x with ⟨y, rfl⟩
simp only [mem_map, mem_comap]
exact ⟨y, hx, rfl⟩
#align submodule.gi_map_comap Submodule.giMapComap
theorem map_comap_eq_of_surjective (p : Submodule R₂ M₂) : (p.comap f).map f = p :=
(giMapComap hf).l_u_eq _
#align submodule.map_comap_eq_of_surjective Submodule.map_comap_eq_of_surjective
theorem map_surjective_of_surjective : Function.Surjective (map f) :=
(giMapComap hf).l_surjective
#align submodule.map_surjective_of_surjective Submodule.map_surjective_of_surjective
theorem comap_injective_of_surjective : Function.Injective (comap f) :=
(giMapComap hf).u_injective
#align submodule.comap_injective_of_surjective Submodule.comap_injective_of_surjective
theorem map_sup_comap_of_surjective (p q : Submodule R₂ M₂) :
(p.comap f ⊔ q.comap f).map f = p ⊔ q :=
(giMapComap hf).l_sup_u _ _
#align submodule.map_sup_comap_of_surjective Submodule.map_sup_comap_of_surjective
theorem map_iSup_comap_of_sujective {ι : Sort*} (S : ι → Submodule R₂ M₂) :
(⨆ i, (S i).comap f).map f = iSup S :=
(giMapComap hf).l_iSup_u _
#align submodule.map_supr_comap_of_sujective Submodule.map_iSup_comap_of_sujective
theorem map_inf_comap_of_surjective (p q : Submodule R₂ M₂) :
(p.comap f ⊓ q.comap f).map f = p ⊓ q :=
(giMapComap hf).l_inf_u _ _
#align submodule.map_inf_comap_of_surjective Submodule.map_inf_comap_of_surjective
theorem map_iInf_comap_of_surjective {ι : Sort*} (S : ι → Submodule R₂ M₂) :
(⨅ i, (S i).comap f).map f = iInf S :=
(giMapComap hf).l_iInf_u _
#align submodule.map_infi_comap_of_surjective Submodule.map_iInf_comap_of_surjective
theorem comap_le_comap_iff_of_surjective (p q : Submodule R₂ M₂) : p.comap f ≤ q.comap f ↔ p ≤ q :=
(giMapComap hf).u_le_u_iff
#align submodule.comap_le_comap_iff_of_surjective Submodule.comap_le_comap_iff_of_surjective
theorem comap_strictMono_of_surjective : StrictMono (comap f) :=
(giMapComap hf).strictMono_u
#align submodule.comap_strict_mono_of_surjective Submodule.comap_strictMono_of_surjective
end GaloisInsertion
section GaloisCoinsertion
variable [RingHomSurjective σ₁₂] {f : F} (hf : Injective f)
/-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/
def gciMapComap : GaloisCoinsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisCoinsertion fun S x => by
simp [mem_comap, mem_map, forall_exists_index, and_imp]
intro y hy hxy
rw [hf.eq_iff] at hxy
rwa [← hxy]
#align submodule.gci_map_comap Submodule.gciMapComap
theorem comap_map_eq_of_injective (p : Submodule R M) : (p.map f).comap f = p :=
(gciMapComap hf).u_l_eq _
#align submodule.comap_map_eq_of_injective Submodule.comap_map_eq_of_injective
theorem comap_surjective_of_injective : Function.Surjective (comap f) :=
(gciMapComap hf).u_surjective
#align submodule.comap_surjective_of_injective Submodule.comap_surjective_of_injective
theorem map_injective_of_injective : Function.Injective (map f) :=
(gciMapComap hf).l_injective
#align submodule.map_injective_of_injective Submodule.map_injective_of_injective
theorem comap_inf_map_of_injective (p q : Submodule R M) : (p.map f ⊓ q.map f).comap f = p ⊓ q :=
(gciMapComap hf).u_inf_l _ _
#align submodule.comap_inf_map_of_injective Submodule.comap_inf_map_of_injective
theorem comap_iInf_map_of_injective {ι : Sort*} (S : ι → Submodule R M) :
(⨅ i, (S i).map f).comap f = iInf S :=
(gciMapComap hf).u_iInf_l _
#align submodule.comap_infi_map_of_injective Submodule.comap_iInf_map_of_injective
theorem comap_sup_map_of_injective (p q : Submodule R M) : (p.map f ⊔ q.map f).comap f = p ⊔ q :=
(gciMapComap hf).u_sup_l _ _
#align submodule.comap_sup_map_of_injective Submodule.comap_sup_map_of_injective
theorem comap_iSup_map_of_injective {ι : Sort*} (S : ι → Submodule R M) :
(⨆ i, (S i).map f).comap f = iSup S :=
(gciMapComap hf).u_iSup_l _
#align submodule.comap_supr_map_of_injective Submodule.comap_iSup_map_of_injective
theorem map_le_map_iff_of_injective (p q : Submodule R M) : p.map f ≤ q.map f ↔ p ≤ q :=
(gciMapComap hf).l_le_l_iff
#align submodule.map_le_map_iff_of_injective Submodule.map_le_map_iff_of_injective
theorem map_strictMono_of_injective : StrictMono (map f) :=
(gciMapComap hf).strictMono_l
#align submodule.map_strict_mono_of_injective Submodule.map_strictMono_of_injective
end GaloisCoinsertion
end SemilinearMap
section OrderIso
variable [RingHomSurjective σ₁₂] {F : Type*}
/-- A linear isomorphism induces an order isomorphism of submodules. -/
@[simps symm_apply apply]
def orderIsoMapComapOfBijective [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
(f : F) (hf : Bijective f) : Submodule R M ≃o Submodule R₂ M₂ where
toFun := map f
invFun := comap f
left_inv := comap_map_eq_of_injective hf.injective
right_inv := map_comap_eq_of_surjective hf.surjective
map_rel_iff' := map_le_map_iff_of_injective hf.injective _ _
/-- A linear isomorphism induces an order isomorphism of submodules. -/
@[simps! symm_apply apply]
def orderIsoMapComap [EquivLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] (f : F) :
Submodule R M ≃o Submodule R₂ M₂ := orderIsoMapComapOfBijective f (EquivLike.bijective f)
#align submodule.order_iso_map_comap Submodule.orderIsoMapComap
end OrderIso
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
--TODO(Mario): is there a way to prove this from order properties?
theorem map_inf_eq_map_inf_comap [RingHomSurjective σ₁₂] {f : F} {p : Submodule R M}
{p' : Submodule R₂ M₂} : map f p ⊓ p' = map f (p ⊓ comap f p') :=
le_antisymm (by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩)
(le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right))
#align submodule.map_inf_eq_map_inf_comap Submodule.map_inf_eq_map_inf_comap
@[simp]
theorem map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' :=
ext fun x => ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, fun ⟨h₁, h₂⟩ => ⟨⟨_, h₁⟩, h₂, rfl⟩⟩
#align submodule.map_comap_subtype Submodule.map_comap_subtype
theorem eq_zero_of_bot_submodule : ∀ b : (⊥ : Submodule R M), b = 0
| ⟨b', hb⟩ => Subtype.eq <| show b' = 0 from (mem_bot R).1 hb
#align submodule.eq_zero_of_bot_submodule Submodule.eq_zero_of_bot_submodule
/-- The infimum of a family of invariant submodule of an endomorphism is also an invariant
submodule. -/
theorem _root_.LinearMap.iInf_invariant {σ : R →+* R} [RingHomSurjective σ] {ι : Sort*}
(f : M →ₛₗ[σ] M) {p : ι → Submodule R M} (hf : ∀ i, ∀ v ∈ p i, f v ∈ p i) :
∀ v ∈ iInf p, f v ∈ iInf p := by
have : ∀ i, (p i).map f ≤ p i := by
rintro i - ⟨v, hv, rfl⟩
exact hf i v hv
suffices (iInf p).map f ≤ iInf p by exact fun v hv => this ⟨v, hv, rfl⟩
exact le_iInf fun i => (Submodule.map_mono (iInf_le p i)).trans (this i)
#align linear_map.infi_invariant LinearMap.iInf_invariant
theorem disjoint_iff_comap_eq_bot {p q : Submodule R M} : Disjoint p q ↔ comap p.subtype q = ⊥ := by
rw [← (map_injective_of_injective (show Injective p.subtype from Subtype.coe_injective)).eq_iff,
map_comap_subtype, map_bot, disjoint_iff]
#align submodule.disjoint_iff_comap_eq_bot Submodule.disjoint_iff_comap_eq_bot
end AddCommMonoid
section AddCommGroup
variable [Ring R] [AddCommGroup M] [Module R M] (p : Submodule R M)
variable [AddCommGroup M₂] [Module R M₂]
@[simp]
protected theorem map_neg (f : M →ₗ[R] M₂) : map (-f) p = map f p :=
ext fun _ =>
⟨fun ⟨x, hx, hy⟩ => hy ▸ ⟨-x, show -x ∈ p from neg_mem hx, map_neg f x⟩, fun ⟨x, hx, hy⟩ =>
hy ▸ ⟨-x, show -x ∈ p from neg_mem hx, (map_neg (-f) _).trans (neg_neg (f x))⟩⟩
#align submodule.map_neg Submodule.map_neg
@[simp]
lemma comap_neg {f : M →ₗ[R] M₂} {p : Submodule R M₂} :
p.comap (-f) = p.comap f := by
ext; simp
end AddCommGroup
end Submodule
namespace Submodule
variable {K : Type*} {V : Type*} {V₂ : Type*}
variable [Semifield K]
variable [AddCommMonoid V] [Module K V]
variable [AddCommMonoid V₂] [Module K V₂]
theorem comap_smul (f : V →ₗ[K] V₂) (p : Submodule K V₂) (a : K) (h : a ≠ 0) :
p.comap (a • f) = p.comap f := by
ext b; simp only [Submodule.mem_comap, p.smul_mem_iff h, LinearMap.smul_apply]
#align submodule.comap_smul Submodule.comap_smul
protected theorem map_smul (f : V →ₗ[K] V₂) (p : Submodule K V) (a : K) (h : a ≠ 0) :
p.map (a • f) = p.map f :=
le_antisymm (by rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap])
(by rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap])
#align submodule.map_smul Submodule.map_smul
theorem comap_smul' (f : V →ₗ[K] V₂) (p : Submodule K V₂) (a : K) :
p.comap (a • f) = ⨅ _ : a ≠ 0, p.comap f := by
classical by_cases h : a = 0 <;> simp [h, comap_smul]
#align submodule.comap_smul' Submodule.comap_smul'
theorem map_smul' (f : V →ₗ[K] V₂) (p : Submodule K V) (a : K) :
p.map (a • f) = ⨆ _ : a ≠ 0, map f p := by
classical by_cases h : a = 0 <;> simp [h, Submodule.map_smul]
#align submodule.map_smul' Submodule.map_smul'
end Submodule
namespace Submodule
section Module
variable [Semiring R] [AddCommMonoid M] [Module R M]
/-- If `s ≤ t`, then we can view `s` as a submodule of `t` by taking the comap
of `t.subtype`. -/
@[simps symm_apply]
def comapSubtypeEquivOfLe {p q : Submodule R M} (hpq : p ≤ q) : comap q.subtype p ≃ₗ[R] p where
toFun x := ⟨x, x.2⟩
invFun x := ⟨⟨x, hpq x.2⟩, x.2⟩
left_inv x := by simp only [coe_mk, SetLike.eta, LinearEquiv.coe_coe]
right_inv x := by simp only [Subtype.coe_mk, SetLike.eta, LinearEquiv.coe_coe]
map_add' x y := rfl
map_smul' c x := rfl
#align submodule.comap_subtype_equiv_of_le Submodule.comapSubtypeEquivOfLe
#align submodule.comap_subtype_equiv_of_le_symm_apply_coe_coe Submodule.comapSubtypeEquivOfLe_symm_apply
-- Porting note: The original theorem generated by `simps` was using `LinearEquiv.toLinearMap`,
-- different from the theorem on Lean 3, and not simp-normal form.
@[simp]
theorem comapSubtypeEquivOfLe_apply_coe {p q : Submodule R M} (hpq : p ≤ q)
(x : comap q.subtype p) :
(comapSubtypeEquivOfLe hpq x : M) = (x : M) :=
rfl
#align submodule.comap_subtype_equiv_of_le_apply_coe Submodule.comapSubtypeEquivOfLe_apply_coe
end Module
end Submodule
namespace Submodule
variable [Semiring R] [Semiring R₂]
variable [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R₂ M₂]
variable {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variable [RingHomInvPair τ₁₂ τ₂₁] [RingHomInvPair τ₂₁ τ₁₂]
variable (p : Submodule R M) (q : Submodule R₂ M₂)
-- Porting note: Was `@[simp]`.
@[simp high]
theorem mem_map_equiv {e : M ≃ₛₗ[τ₁₂] M₂} {x : M₂} :
x ∈ p.map (e : M →ₛₗ[τ₁₂] M₂) ↔ e.symm x ∈ p := by
rw [Submodule.mem_map]; constructor
· rintro ⟨y, hy, hx⟩
simp [← hx, hy]
· intro hx
exact ⟨e.symm x, hx, by simp⟩
#align submodule.mem_map_equiv Submodule.mem_map_equiv
theorem map_equiv_eq_comap_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : Submodule R M) :
K.map (e : M →ₛₗ[τ₁₂] M₂) = K.comap (e.symm : M₂ →ₛₗ[τ₂₁] M) :=
Submodule.ext fun _ => by rw [mem_map_equiv, mem_comap, LinearEquiv.coe_coe]
#align submodule.map_equiv_eq_comap_symm Submodule.map_equiv_eq_comap_symm
theorem comap_equiv_eq_map_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : Submodule R₂ M₂) :
K.comap (e : M →ₛₗ[τ₁₂] M₂) = K.map (e.symm : M₂ →ₛₗ[τ₂₁] M) :=
(map_equiv_eq_comap_symm e.symm K).symm
#align submodule.comap_equiv_eq_map_symm Submodule.comap_equiv_eq_map_symm
variable {p}
| Mathlib/Algebra/Module/Submodule/Map.lean | 564 | 572 | theorem map_symm_eq_iff (e : M ≃ₛₗ[τ₁₂] M₂) {K : Submodule R₂ M₂} :
K.map e.symm = p ↔ p.map e = K := by |
constructor <;> rintro rfl
· calc
map e (map e.symm K) = comap e.symm (map e.symm K) := map_equiv_eq_comap_symm _ _
_ = K := comap_map_eq_of_injective e.symm.injective _
· calc
map e.symm (map e p) = comap e (map e p) := (comap_equiv_eq_map_symm _ _).symm
_ = p := comap_map_eq_of_injective e.injective _
|
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.Data.Set.Card
import Mathlib.Order.Minimal
import Mathlib.Data.Matroid.Init
/-!
# Matroids
A `Matroid` is a structure that combinatorially abstracts
the notion of linear independence and dependence;
matroids have connections with graph theory, discrete optimization,
additive combinatorics and algebraic geometry.
Mathematically, a matroid `M` is a structure on a set `E` comprising a
collection of subsets of `E` called the bases of `M`,
where the bases are required to obey certain axioms.
This file gives a definition of a matroid `M` in terms of its bases,
and some API relating independent sets (subsets of bases) and the notion of a
basis of a set `X` (a maximal independent subset of `X`).
## Main definitions
* a `Matroid α` on a type `α` is a structure comprising a 'ground set'
and a suitably behaved 'base' predicate.
Given `M : Matroid α` ...
* `M.E` denotes the ground set of `M`, which has type `Set α`
* For `B : Set α`, `M.Base B` means that `B` is a base of `M`.
* For `I : Set α`, `M.Indep I` means that `I` is independent in `M`
(that is, `I` is contained in a base of `M`).
* For `D : Set α`, `M.Dep D` means that `D` is contained in the ground set of `M`
but isn't independent.
* For `I : Set α` and `X : Set α`, `M.Basis I X` means that `I` is a maximal independent
subset of `X`.
* `M.Finite` means that `M` has finite ground set.
* `M.Nonempty` means that the ground set of `M` is nonempty.
* `FiniteRk M` means that the bases of `M` are finite.
* `InfiniteRk M` means that the bases of `M` are infinite.
* `RkPos M` means that the bases of `M` are nonempty.
* `Finitary M` means that a set is independent if and only if all its finite subsets are
independent.
* `aesop_mat` : a tactic designed to prove `X ⊆ M.E` for some set `X` and matroid `M`.
## Implementation details
There are a few design decisions worth discussing.
### Finiteness
The first is that our matroids are allowed to be infinite.
Unlike with many mathematical structures, this isn't such an obvious choice.
Finite matroids have been studied since the 1930's,
and there was never controversy as to what is and isn't an example of a finite matroid -
in fact, surprisingly many apparently different definitions of a matroid
give rise to the same class of objects.
However, generalizing different definitions of a finite matroid
to the infinite in the obvious way (i.e. by simply allowing the ground set to be infinite)
gives a number of different notions of 'infinite matroid' that disagree with each other,
and that all lack nice properties.
Many different competing notions of infinite matroid were studied through the years;
in fact, the problem of which definition is the best was only really solved in 2013,
when Bruhn et al. [2] showed that there is a unique 'reasonable' notion of an infinite matroid
(these objects had previously defined by Higgs under the name 'B-matroid').
These are defined by adding one carefully chosen axiom to the standard set,
and adapting existing axioms to not mention set cardinalities;
they enjoy nearly all the nice properties of standard finite matroids.
Even though at least 90% of the literature is on finite matroids,
B-matroids are the definition we use, because they allow for additional generality,
nearly all theorems are still true and just as easy to state,
and (hopefully) the more general definition will prevent the need for a costly future refactor.
The disadvantage is that developing API for the finite case is harder work
(for instance, it is harder to prove that something is a matroid in the first place,
and one must deal with `ℕ∞` rather than `ℕ`).
For serious work on finite matroids, we provide the typeclasses
`[M.Finite]` and `[FiniteRk M]` and associated API.
### Cardinality
Just as with bases of a vector space,
all bases of a finite matroid `M` are finite and have the same cardinality;
this cardinality is an important invariant known as the 'rank' of `M`.
For infinite matroids, bases are not in general equicardinal;
in fact the equicardinality of bases of infinite matroids is independent of ZFC [3].
What is still true is that either all bases are finite and equicardinal,
or all bases are infinite. This means that the natural notion of 'size'
for a set in matroid theory is given by the function `Set.encard`, which
is the cardinality as a term in `ℕ∞`. We use this function extensively
in building the API; it is preferable to both `Set.ncard` and `Finset.card`
because it allows infinite sets to be handled without splitting into cases.
### The ground `Set`
A last place where we make a consequential choice is making the ground set of a matroid
a structure field of type `Set α` (where `α` is the type of 'possible matroid elements')
rather than just having a type `α` of all the matroid elements.
This is because of how common it is to simultaneously consider
a number of matroids on different but related ground sets.
For example, a matroid `M` on ground set `E` can have its structure
'restricted' to some subset `R ⊆ E` to give a smaller matroid `M ↾ R` with ground set `R`.
A statement like `(M ↾ R₁) ↾ R₂ = M ↾ R₂` is mathematically obvious.
But if the ground set of a matroid is a type, this doesn't typecheck,
and is only true up to canonical isomorphism.
Restriction is just the tip of the iceberg here;
one can also 'contract' and 'delete' elements and sets of elements
in a matroid to give a smaller matroid,
and in practice it is common to make statements like `M₁.E = M₂.E ∩ M₃.E` and
`((M ⟋ e) ↾ R) ⟋ C = M ⟋ (C ∪ {e}) ↾ R`.
Such things are a nightmare to work with unless `=` is actually propositional equality
(especially because the relevant coercions are usually between sets and not just elements).
So the solution is that the ground set `M.E` has type `Set α`,
and there are elements of type `α` that aren't in the matroid.
The tradeoff is that for many statements, one now has to add
hypotheses of the form `X ⊆ M.E` to make sure than `X` is actually 'in the matroid',
rather than letting a 'type of matroid elements' take care of this invisibly.
It still seems that this is worth it.
The tactic `aesop_mat` exists specifically to discharge such goals
with minimal fuss (using default values).
The tactic works fairly well, but has room for improvement.
Even though the carrier set is written `M.E`,
A related decision is to not have matroids themselves be a typeclass.
This would make things be notationally simpler
(having `Base` in the presence of `[Matroid α]` rather than `M.Base` for a term `M : Matroid α`)
but is again just too awkward when one has multiple matroids on the same type.
In fact, in regular written mathematics,
it is normal to explicitly indicate which matroid something is happening in,
so our notation mirrors common practice.
### Notation
We use a couple of nonstandard conventions in theorem names that are related to the above.
First, we mirror common informal practice by referring explicitly to the `ground` set rather
than the notation `E`. (Writing `ground` everywhere in a proof term would be unwieldy, and
writing `E` in theorem names would be unnatural to read.)
Second, because we are typically interested in subsets of the ground set `M.E`,
using `Set.compl` is inconvenient, since `Xᶜ ⊆ M.E` is typically false for `X ⊆ M.E`.
On the other hand (especially when duals arise), it is common to complement
a set `X ⊆ M.E` *within* the ground set, giving `M.E \ X`.
For this reason, we use the term `compl` in theorem names to refer to taking a set difference
with respect to the ground set, rather than a complement within a type. The lemma
`compl_base_dual` is one of the many examples of this.
## References
[1] The standard text on matroid theory
[J. G. Oxley, Matroid Theory, Oxford University Press, New York, 2011.]
[2] The robust axiomatic definition of infinite matroids
[H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids,
Adv. Math 239 (2013), 18-46]
[3] Equicardinality of matroid bases is independent of ZFC.
[N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets,
Proc. Amer. Math. Soc. 144 (2016), 459-471]
-/
set_option autoImplicit true
open Set
/-- A predicate `P` on sets satisfies the **exchange property** if,
for all `X` and `Y` satisfying `P` and all `a ∈ X \ Y`, there exists `b ∈ Y \ X` so that
swapping `a` for `b` in `X` maintains `P`. -/
def Matroid.ExchangeProperty {α : Type _} (P : Set α → Prop) : Prop :=
∀ X Y, P X → P Y → ∀ a ∈ X \ Y, ∃ b ∈ Y \ X, P (insert b (X \ {a}))
/-- A set `X` has the maximal subset property for a predicate `P` if every subset of `X` satisfying
`P` is contained in a maximal subset of `X` satisfying `P`. -/
def Matroid.ExistsMaximalSubsetProperty {α : Type _} (P : Set α → Prop) (X : Set α) : Prop :=
∀ I, P I → I ⊆ X → (maximals (· ⊆ ·) {Y | P Y ∧ I ⊆ Y ∧ Y ⊆ X}).Nonempty
/-- A `Matroid α` is a ground set `E` of type `Set α`, and a nonempty collection of its subsets
satisfying the exchange property and the maximal subset property. Each such set is called a
`Base` of `M`. An `Indep`endent set is just a set contained in a base, but we include this
predicate as a structure field for better definitional properties.
In most cases, using this definition directly is not the best way to construct a matroid,
since it requires specifying both the bases and independent sets. If the bases are known,
use `Matroid.ofBase` or a variant. If just the independent sets are known,
define an `IndepMatroid`, and then use `IndepMatroid.matroid`.
-/
@[ext] structure Matroid (α : Type _) where
/-- `M` has a ground set `E`. -/
(E : Set α)
/-- `M` has a predicate `Base` definining its bases. -/
(Base : Set α → Prop)
/-- `M` has a predicate `Indep` defining its independent sets. -/
(Indep : Set α → Prop)
/-- The `Indep`endent sets are those contained in `Base`s. -/
(indep_iff' : ∀ ⦃I⦄, Indep I ↔ ∃ B, Base B ∧ I ⊆ B)
/-- There is at least one `Base`. -/
(exists_base : ∃ B, Base B)
/-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f`
is a base. -/
(base_exchange : Matroid.ExchangeProperty Base)
/-- Every independent subset `I` of a set `X` for is contained in a maximal independent
subset of `X`. -/
(maximality : ∀ X, X ⊆ E → Matroid.ExistsMaximalSubsetProperty Indep X)
/-- Every base is contained in the ground set. -/
(subset_ground : ∀ B, Base B → B ⊆ E)
namespace Matroid
variable {α : Type*} {M : Matroid α}
/-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`-/
protected class Finite (M : Matroid α) : Prop where
/-- The ground set is finite -/
(ground_finite : M.E.Finite)
/-- Typeclass for a matroid having nonempty ground set. Just a wrapper for `M.E.Nonempty`-/
protected class Nonempty (M : Matroid α) : Prop where
/-- The ground set is nonempty -/
(ground_nonempty : M.E.Nonempty)
theorem ground_nonempty (M : Matroid α) [M.Nonempty] : M.E.Nonempty :=
Nonempty.ground_nonempty
theorem ground_nonempty_iff (M : Matroid α) : M.E.Nonempty ↔ M.Nonempty :=
⟨fun h ↦ ⟨h⟩, fun ⟨h⟩ ↦ h⟩
theorem ground_finite (M : Matroid α) [M.Finite] : M.E.Finite :=
Finite.ground_finite
theorem set_finite (M : Matroid α) [M.Finite] (X : Set α) (hX : X ⊆ M.E := by aesop) : X.Finite :=
M.ground_finite.subset hX
instance finite_of_finite [Finite α] {M : Matroid α} : M.Finite :=
⟨Set.toFinite _⟩
/-- A `FiniteRk` matroid is one whose bases are finite -/
class FiniteRk (M : Matroid α) : Prop where
/-- There is a finite base -/
exists_finite_base : ∃ B, M.Base B ∧ B.Finite
instance finiteRk_of_finite (M : Matroid α) [M.Finite] : FiniteRk M :=
⟨M.exists_base.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩
/-- An `InfiniteRk` matroid is one whose bases are infinite. -/
class InfiniteRk (M : Matroid α) : Prop where
/-- There is an infinite base -/
exists_infinite_base : ∃ B, M.Base B ∧ B.Infinite
/-- A `RkPos` matroid is one whose bases are nonempty. -/
class RkPos (M : Matroid α) : Prop where
/-- The empty set isn't a base -/
empty_not_base : ¬M.Base ∅
theorem rkPos_iff_empty_not_base : M.RkPos ↔ ¬M.Base ∅ :=
⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩
section exchange
namespace ExchangeProperty
variable {Base : Set α → Prop} (exch : ExchangeProperty Base)
/-- A family of sets with the exchange property is an antichain. -/
theorem antichain (hB : Base B) (hB' : Base B') (h : B ⊆ B') : B = B' :=
h.antisymm (fun x hx ↦ by_contra
(fun hxB ↦ let ⟨_, hy, _⟩ := exch B' B hB' hB x ⟨hx, hxB⟩; hy.2 <| h hy.1))
theorem encard_diff_le_aux (exch : ExchangeProperty Base) (hB₁ : Base B₁) (hB₂ : Base B₂) :
(B₁ \ B₂).encard ≤ (B₂ \ B₁).encard := by
obtain (he | hinf | ⟨e, he, hcard⟩) :=
(B₂ \ B₁).eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt
· rw [exch.antichain hB₂ hB₁ (diff_eq_empty.mp he)]
· exact le_top.trans_eq hinf.symm
obtain ⟨f, hf, hB'⟩ := exch B₂ B₁ hB₂ hB₁ e he
have : encard (insert f (B₂ \ {e}) \ B₁) < encard (B₂ \ B₁) := by
rw [insert_diff_of_mem _ hf.1, diff_diff_comm]; exact hcard
have hencard := encard_diff_le_aux exch hB₁ hB'
rw [insert_diff_of_mem _ hf.1, diff_diff_comm, ← union_singleton, ← diff_diff, diff_diff_right,
inter_singleton_eq_empty.mpr he.2, union_empty] at hencard
rw [← encard_diff_singleton_add_one he, ← encard_diff_singleton_add_one hf]
exact add_le_add_right hencard 1
termination_by (B₂ \ B₁).encard
/-- For any two sets `B₁`, `B₂` in a family with the exchange property, the differences `B₁ \ B₂`
and `B₂ \ B₁` have the same `ℕ∞`-cardinality. -/
theorem encard_diff_eq (hB₁ : Base B₁) (hB₂ : Base B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard :=
(encard_diff_le_aux exch hB₁ hB₂).antisymm (encard_diff_le_aux exch hB₂ hB₁)
/-- Any two sets `B₁`, `B₂` in a family with the exchange property have the same
`ℕ∞`-cardinality. -/
theorem encard_base_eq (hB₁ : Base B₁) (hB₂ : Base B₂) : B₁.encard = B₂.encard := by
rw [← encard_diff_add_encard_inter B₁ B₂, exch.encard_diff_eq hB₁ hB₂, inter_comm,
encard_diff_add_encard_inter]
end ExchangeProperty
end exchange
section aesop
/-- The `aesop_mat` tactic attempts to prove a set is contained in the ground set of a matroid.
It uses a `[Matroid]` ruleset, and is allowed to fail. -/
macro (name := aesop_mat) "aesop_mat" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c* (config := { terminal := true })
(rule_sets := [$(Lean.mkIdent `Matroid):ident]))
/- We add a number of trivial lemmas (deliberately specialized to statements in terms of the
ground set of a matroid) to the ruleset `Matroid` for `aesop`. -/
@[aesop unsafe 5% (rule_sets := [Matroid])]
private theorem inter_right_subset_ground (hX : X ⊆ M.E) :
X ∩ Y ⊆ M.E := inter_subset_left.trans hX
@[aesop unsafe 5% (rule_sets := [Matroid])]
private theorem inter_left_subset_ground (hX : X ⊆ M.E) :
Y ∩ X ⊆ M.E := inter_subset_right.trans hX
@[aesop unsafe 5% (rule_sets := [Matroid])]
private theorem diff_subset_ground (hX : X ⊆ M.E) : X \ Y ⊆ M.E :=
diff_subset.trans hX
@[aesop unsafe 10% (rule_sets := [Matroid])]
private theorem ground_diff_subset_ground : M.E \ X ⊆ M.E :=
diff_subset_ground rfl.subset
@[aesop unsafe 10% (rule_sets := [Matroid])]
private theorem singleton_subset_ground (he : e ∈ M.E) : {e} ⊆ M.E :=
singleton_subset_iff.mpr he
@[aesop unsafe 5% (rule_sets := [Matroid])]
private theorem subset_ground_of_subset (hXY : X ⊆ Y) (hY : Y ⊆ M.E) : X ⊆ M.E :=
hXY.trans hY
@[aesop unsafe 5% (rule_sets := [Matroid])]
private theorem mem_ground_of_mem_of_subset (hX : X ⊆ M.E) (heX : e ∈ X) : e ∈ M.E :=
hX heX
@[aesop safe (rule_sets := [Matroid])]
private theorem insert_subset_ground {e : α} {X : Set α} {M : Matroid α}
(he : e ∈ M.E) (hX : X ⊆ M.E) : insert e X ⊆ M.E :=
insert_subset he hX
@[aesop safe (rule_sets := [Matroid])]
private theorem ground_subset_ground {M : Matroid α} : M.E ⊆ M.E :=
rfl.subset
attribute [aesop safe (rule_sets := [Matroid])] empty_subset union_subset iUnion_subset
end aesop
section Base
@[aesop unsafe 10% (rule_sets := [Matroid])]
theorem Base.subset_ground (hB : M.Base B) : B ⊆ M.E :=
M.subset_ground B hB
theorem Base.exchange (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hx : e ∈ B₁ \ B₂) :
∃ y ∈ B₂ \ B₁, M.Base (insert y (B₁ \ {e})) :=
M.base_exchange B₁ B₂ hB₁ hB₂ _ hx
theorem Base.exchange_mem (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hxB₁ : e ∈ B₁) (hxB₂ : e ∉ B₂) :
∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.Base (insert y (B₁ \ {e})) := by
simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩
theorem Base.eq_of_subset_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hB₁B₂ : B₁ ⊆ B₂) :
B₁ = B₂ :=
M.base_exchange.antichain hB₁ hB₂ hB₁B₂
theorem Base.not_base_of_ssubset (hB : M.Base B) (hX : X ⊂ B) : ¬ M.Base X :=
fun h ↦ hX.ne (h.eq_of_subset_base hB hX.subset)
theorem Base.insert_not_base (hB : M.Base B) (heB : e ∉ B) : ¬ M.Base (insert e B) :=
fun h ↦ h.not_base_of_ssubset (ssubset_insert heB) hB
theorem Base.encard_diff_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) :
(B₁ \ B₂).encard = (B₂ \ B₁).encard :=
M.base_exchange.encard_diff_eq hB₁ hB₂
theorem Base.ncard_diff_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) :
(B₁ \ B₂).ncard = (B₂ \ B₁).ncard := by
rw [ncard_def, hB₁.encard_diff_comm hB₂, ← ncard_def]
theorem Base.card_eq_card_of_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) :
B₁.encard = B₂.encard := by
rw [M.base_exchange.encard_base_eq hB₁ hB₂]
theorem Base.ncard_eq_ncard_of_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : B₁.ncard = B₂.ncard := by
rw [ncard_def B₁, hB₁.card_eq_card_of_base hB₂, ← ncard_def]
theorem Base.finite_of_finite (hB : M.Base B) (h : B.Finite) (hB' : M.Base B') : B'.Finite :=
(finite_iff_finite_of_encard_eq_encard (hB.card_eq_card_of_base hB')).mp h
theorem Base.infinite_of_infinite (hB : M.Base B) (h : B.Infinite) (hB₁ : M.Base B₁) :
B₁.Infinite :=
by_contra (fun hB_inf ↦ (hB₁.finite_of_finite (not_infinite.mp hB_inf) hB).not_infinite h)
theorem Base.finite [FiniteRk M] (hB : M.Base B) : B.Finite :=
let ⟨B₀,hB₀⟩ := ‹FiniteRk M›.exists_finite_base
hB₀.1.finite_of_finite hB₀.2 hB
theorem Base.infinite [InfiniteRk M] (hB : M.Base B) : B.Infinite :=
let ⟨B₀,hB₀⟩ := ‹InfiniteRk M›.exists_infinite_base
hB₀.1.infinite_of_infinite hB₀.2 hB
theorem empty_not_base [h : RkPos M] : ¬M.Base ∅ :=
h.empty_not_base
theorem Base.nonempty [RkPos M] (hB : M.Base B) : B.Nonempty := by
rw [nonempty_iff_ne_empty]; rintro rfl; exact M.empty_not_base hB
theorem Base.rkPos_of_nonempty (hB : M.Base B) (h : B.Nonempty) : M.RkPos := by
rw [rkPos_iff_empty_not_base]
intro he
obtain rfl := he.eq_of_subset_base hB (empty_subset B)
simp at h
theorem Base.finiteRk_of_finite (hB : M.Base B) (hfin : B.Finite) : FiniteRk M :=
⟨⟨B, hB, hfin⟩⟩
theorem Base.infiniteRk_of_infinite (hB : M.Base B) (h : B.Infinite) : InfiniteRk M :=
⟨⟨B, hB, h⟩⟩
theorem not_finiteRk (M : Matroid α) [InfiniteRk M] : ¬ FiniteRk M := by
intro h; obtain ⟨B,hB⟩ := M.exists_base; exact hB.infinite hB.finite
theorem not_infiniteRk (M : Matroid α) [FiniteRk M] : ¬ InfiniteRk M := by
intro h; obtain ⟨B,hB⟩ := M.exists_base; exact hB.infinite hB.finite
theorem finite_or_infiniteRk (M : Matroid α) : FiniteRk M ∨ InfiniteRk M :=
let ⟨B, hB⟩ := M.exists_base
B.finite_or_infinite.elim
(Or.inl ∘ hB.finiteRk_of_finite) (Or.inr ∘ hB.infiniteRk_of_infinite)
theorem Base.diff_finite_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) :
(B₁ \ B₂).Finite ↔ (B₂ \ B₁).Finite :=
finite_iff_finite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂)
theorem Base.diff_infinite_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) :
(B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite :=
infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂)
theorem eq_of_base_iff_base_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.Base B ↔ M₂.Base B)) : M₁ = M₂ := by
have h' : ∀ B, M₁.Base B ↔ M₂.Base B :=
fun B ↦ ⟨fun hB ↦ (h hB.subset_ground).1 hB,
fun hB ↦ (h <| hB.subset_ground.trans_eq hE.symm).2 hB⟩
ext <;> simp [hE, M₁.indep_iff', M₂.indep_iff', h']
theorem base_compl_iff_mem_maximals_disjoint_base (hB : B ⊆ M.E := by aesop_mat) :
M.Base (M.E \ B) ↔ B ∈ maximals (· ⊆ ·) {I | I ⊆ M.E ∧ ∃ B, M.Base B ∧ Disjoint I B} := by
simp_rw [mem_maximals_setOf_iff, and_iff_right hB, and_imp, forall_exists_index]
refine ⟨fun h ↦ ⟨⟨_, h, disjoint_sdiff_right⟩,
fun I hI B' ⟨hB', hIB'⟩ hBI ↦ hBI.antisymm ?_⟩, fun ⟨⟨B', hB', hBB'⟩,h⟩ ↦ ?_⟩
· rw [hB'.eq_of_subset_base h, ← subset_compl_iff_disjoint_right, diff_eq, compl_inter,
compl_compl] at hIB'
· exact fun e he ↦ (hIB' he).elim (fun h' ↦ (h' (hI he)).elim) id
rw [subset_diff, and_iff_right hB'.subset_ground, disjoint_comm]
exact disjoint_of_subset_left hBI hIB'
rw [h diff_subset B' ⟨hB', disjoint_sdiff_left⟩]
· simpa [hB'.subset_ground]
simp [subset_diff, hB, hBB']
end Base
section dep_indep
/-- A subset of `M.E` is `Dep`endent if it is not `Indep`endent . -/
def Dep (M : Matroid α) (D : Set α) : Prop := ¬M.Indep D ∧ D ⊆ M.E
theorem indep_iff : M.Indep I ↔ ∃ B, M.Base B ∧ I ⊆ B :=
M.indep_iff' (I := I)
theorem setOf_indep_eq (M : Matroid α) : {I | M.Indep I} = lowerClosure ({B | M.Base B}) := by
simp_rw [indep_iff]
rfl
theorem Indep.exists_base_superset (hI : M.Indep I) : ∃ B, M.Base B ∧ I ⊆ B :=
indep_iff.1 hI
theorem dep_iff : M.Dep D ↔ ¬M.Indep D ∧ D ⊆ M.E := Iff.rfl
theorem setOf_dep_eq (M : Matroid α) : {D | M.Dep D} = {I | M.Indep I}ᶜ ∩ Iic M.E := rfl
@[aesop unsafe 30% (rule_sets := [Matroid])]
theorem Indep.subset_ground (hI : M.Indep I) : I ⊆ M.E := by
obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset
exact hIB.trans hB.subset_ground
@[aesop unsafe 20% (rule_sets := [Matroid])]
theorem Dep.subset_ground (hD : M.Dep D) : D ⊆ M.E :=
hD.2
theorem indep_or_dep (hX : X ⊆ M.E := by aesop_mat) : M.Indep X ∨ M.Dep X := by
rw [Dep, and_iff_left hX]
apply em
theorem Indep.not_dep (hI : M.Indep I) : ¬ M.Dep I :=
fun h ↦ h.1 hI
theorem Dep.not_indep (hD : M.Dep D) : ¬ M.Indep D :=
hD.1
theorem dep_of_not_indep (hD : ¬ M.Indep D) (hDE : D ⊆ M.E := by aesop_mat) : M.Dep D :=
⟨hD, hDE⟩
theorem indep_of_not_dep (hI : ¬ M.Dep I) (hIE : I ⊆ M.E := by aesop_mat) : M.Indep I :=
by_contra (fun h ↦ hI ⟨h, hIE⟩)
@[simp] theorem not_dep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Dep X ↔ M.Indep X := by
rw [Dep, and_iff_left hX, not_not]
@[simp] theorem not_indep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Indep X ↔ M.Dep X := by
rw [Dep, and_iff_left hX]
theorem indep_iff_not_dep : M.Indep I ↔ ¬M.Dep I ∧ I ⊆ M.E := by
rw [dep_iff, not_and, not_imp_not]
exact ⟨fun h ↦ ⟨fun _ ↦ h, h.subset_ground⟩, fun h ↦ h.1 h.2⟩
theorem Indep.subset (hJ : M.Indep J) (hIJ : I ⊆ J) : M.Indep I := by
obtain ⟨B, hB, hJB⟩ := hJ.exists_base_superset
exact indep_iff.2 ⟨B, hB, hIJ.trans hJB⟩
theorem Dep.superset (hD : M.Dep D) (hDX : D ⊆ X) (hXE : X ⊆ M.E := by aesop_mat) : M.Dep X :=
dep_of_not_indep (fun hI ↦ (hI.subset hDX).not_dep hD)
theorem Base.indep (hB : M.Base B) : M.Indep B :=
indep_iff.2 ⟨B, hB, subset_rfl⟩
@[simp] theorem empty_indep (M : Matroid α) : M.Indep ∅ :=
Exists.elim M.exists_base (fun _ hB ↦ hB.indep.subset (empty_subset _))
theorem Dep.nonempty (hD : M.Dep D) : D.Nonempty := by
rw [nonempty_iff_ne_empty]; rintro rfl; exact hD.not_indep M.empty_indep
theorem Indep.finite [FiniteRk M] (hI : M.Indep I) : I.Finite :=
let ⟨_, hB, hIB⟩ := hI.exists_base_superset
hB.finite.subset hIB
theorem Indep.rkPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RkPos := by
obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset
exact hB.rkPos_of_nonempty (hne.mono hIB)
theorem Indep.inter_right (hI : M.Indep I) (X : Set α) : M.Indep (I ∩ X) :=
hI.subset inter_subset_left
theorem Indep.inter_left (hI : M.Indep I) (X : Set α) : M.Indep (X ∩ I) :=
hI.subset inter_subset_right
theorem Indep.diff (hI : M.Indep I) (X : Set α) : M.Indep (I \ X) :=
hI.subset diff_subset
theorem Base.eq_of_subset_indep (hB : M.Base B) (hI : M.Indep I) (hBI : B ⊆ I) : B = I :=
let ⟨B', hB', hB'I⟩ := hI.exists_base_superset
hBI.antisymm (by rwa [hB.eq_of_subset_base hB' (hBI.trans hB'I)])
theorem base_iff_maximal_indep : M.Base B ↔ M.Indep B ∧ ∀ I, M.Indep I → B ⊆ I → B = I := by
refine ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep ⟩, fun ⟨h, h'⟩ ↦ ?_⟩
obtain ⟨B', hB', hBB'⟩ := h.exists_base_superset
rwa [h' _ hB'.indep hBB']
theorem setOf_base_eq_maximals_setOf_indep : {B | M.Base B} = maximals (· ⊆ ·) {I | M.Indep I} := by
ext B; rw [mem_maximals_setOf_iff, mem_setOf, base_iff_maximal_indep]
theorem Indep.base_of_maximal (hI : M.Indep I) (h : ∀ J, M.Indep J → I ⊆ J → I = J) : M.Base I :=
base_iff_maximal_indep.mpr ⟨hI,h⟩
theorem Base.dep_of_ssubset (hB : M.Base B) (h : B ⊂ X) (hX : X ⊆ M.E := by aesop_mat) : M.Dep X :=
⟨fun hX ↦ h.ne (hB.eq_of_subset_indep hX h.subset), hX⟩
theorem Base.dep_of_insert (hB : M.Base B) (heB : e ∉ B) (he : e ∈ M.E := by aesop_mat) :
M.Dep (insert e B) := hB.dep_of_ssubset (ssubset_insert heB) (insert_subset he hB.subset_ground)
theorem Base.mem_of_insert_indep (hB : M.Base B) (heB : M.Indep (insert e B)) : e ∈ B :=
by_contra fun he ↦ (hB.dep_of_insert he (heB.subset_ground (mem_insert _ _))).not_indep heB
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1
rw [insert_diff_singleton_comm hne] at hb
refine ⟨f, hf, (hb.eq_of_subset_base hB' ?_).symm⟩
rw [diff_subset_iff, insert_subset_iff, union_comm, ← diff_subset_iff, h, and_iff_left rfl.subset]
exact Or.inl hf.1
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
(hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
have hcard := hB'.encard_diff_comm hB
rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
at hIB'
obtain ⟨hfB, (h | h)⟩ := hIB'
· rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
exact (hcard f ⟨hfB, hf⟩).elim
rw [h, encard_singleton, encard_eq_one] at hcard
obtain ⟨x, hx⟩ := hcard
obtain (rfl : f = x) := hx.subset ⟨hfB, hf⟩
simp_rw [← h, ← singleton_union, ← hx, sdiff_sdiff_right_self, inf_eq_inter, inter_comm B,
diff_union_inter]
exact hB'
theorem Base.exchange_base_of_indep' (hB : M.Base B) (he : e ∈ B) (hf : f ∉ B)
(hI : M.Indep (insert f B \ {e})) : M.Base (insert f B \ {e}) := by
have hfe : f ≠ e := by rintro rfl; exact hf he
rw [← insert_diff_singleton_comm hfe] at *
exact hB.exchange_base_of_indep hf hI
theorem Base.insert_dep (hB : M.Base B) (h : e ∈ M.E \ B) : M.Dep (insert e B) := by
rw [← not_indep_iff (insert_subset h.1 hB.subset_ground)]
exact h.2 ∘ (fun hi ↦ insert_eq_self.mp (hB.eq_of_subset_indep hi (subset_insert e B)).symm)
theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) :
∃ e ∈ B \ I, M.Indep (insert e I) := by
obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB')))
obtain (hxB | hxB) := em (x ∈ B)
· exact ⟨x, ⟨hxB, hx⟩, hB'.indep.subset (insert_subset hxB' hIB') ⟩
obtain ⟨e,he, hBase⟩ := hB'.exchange hB ⟨hxB',hxB⟩
exact ⟨e, ⟨he.1, not_mem_subset hIB' he.2⟩,
indep_iff.2 ⟨_, hBase, insert_subset_insert (subset_diff_singleton hIB' hx)⟩⟩
/-- This is the same as `Indep.exists_insert_of_not_base`, but phrased so that
it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_mem_maximals (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
(hInotmax : I ∉ maximals (· ⊆ ·) {I | M.Indep I}) (hB : B ∈ maximals (· ⊆ ·) {I | M.Indep I}) :
∃ x ∈ B \ I, M.Indep (insert x I) := by
simp only [mem_maximals_iff, mem_setOf_eq, not_and, not_forall, exists_prop,
exists_and_left, iff_true_intro hI, true_imp_iff] at hB hInotmax
refine hI.exists_insert_of_not_base (fun hIb ↦ ?_) ?_
· obtain ⟨I', hII', hI', hne⟩ := hInotmax
exact hne <| hIb.eq_of_subset_indep hII' hI'
exact hB.1.base_of_maximal fun J hJ hBJ ↦ hB.2 hJ hBJ
theorem ground_indep_iff_base : M.Indep M.E ↔ M.Base M.E :=
⟨fun h ↦ h.base_of_maximal (fun _ hJ hEJ ↦ hEJ.antisymm hJ.subset_ground), Base.indep⟩
theorem Base.exists_insert_of_ssubset (hB : M.Base B) (hIB : I ⊂ B) (hB' : M.Base B') :
∃ e ∈ B' \ I, M.Indep (insert e I) :=
(hB.indep.subset hIB.subset).exists_insert_of_not_base
(fun hI ↦ hIB.ne (hI.eq_of_subset_base hB hIB.subset)) hB'
theorem eq_of_indep_iff_indep_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(h : ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ :=
let h' : ∀ I, M₁.Indep I ↔ M₂.Indep I := fun I ↦
(em (I ⊆ M₁.E)).elim (h I) (fun h' ↦ iff_of_false (fun hi ↦ h' (hi.subset_ground))
(fun hi ↦ h' (hi.subset_ground.trans_eq hE.symm)))
eq_of_base_iff_base_forall hE (fun B _ ↦ by simp_rw [base_iff_maximal_indep, h'])
theorem eq_iff_indep_iff_indep_forall {M₁ M₂ : Matroid α} :
M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) :=
⟨fun h ↦ by (subst h; simp), fun h ↦ eq_of_indep_iff_indep_forall h.1 h.2⟩
/-- A `Finitary` matroid is one where a set is independent if and only if it all
its finite subsets are independent, or equivalently a matroid whose circuits are finite. -/
class Finitary (M : Matroid α) : Prop where
/-- `I` is independent if all its finite subsets are independent. -/
indep_of_forall_finite : ∀ I, (∀ J, J ⊆ I → J.Finite → M.Indep J) → M.Indep I
theorem indep_of_forall_finite_subset_indep {M : Matroid α} [Finitary M] (I : Set α)
(h : ∀ J, J ⊆ I → J.Finite → M.Indep J) : M.Indep I :=
Finitary.indep_of_forall_finite I h
theorem indep_iff_forall_finite_subset_indep {M : Matroid α} [Finitary M] :
M.Indep I ↔ ∀ J, J ⊆ I → J.Finite → M.Indep J :=
⟨fun h _ hJI _ ↦ h.subset hJI, Finitary.indep_of_forall_finite I⟩
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
obtain ⟨B, hB⟩ := M.exists_base
obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1)
obtain ⟨B', hB', hI₀B'⟩ := (hI _ hI₀I hI₀fin).exists_base_superset
have hle := ncard_le_ncard hI₀B' hB'.finite
rw [hI₀card, hB'.ncard_eq_ncard_of_base hB, Nat.add_one_le_iff] at hle
exact hle.ne rfl ⟩
/-- Matroids obey the maximality axiom -/
theorem existsMaximalSubsetProperty_indep (M : Matroid α) :
∀ X, X ⊆ M.E → ExistsMaximalSubsetProperty M.Indep X :=
M.maximality
end dep_indep
section Basis
/-- A Basis for a set `X ⊆ M.E` is a maximal independent subset of `X`
(Often in the literature, the word 'Basis' is used to refer to what we call a 'Base'). -/
def Basis (M : Matroid α) (I X : Set α) : Prop :=
I ∈ maximals (· ⊆ ·) {A | M.Indep A ∧ A ⊆ X} ∧ X ⊆ M.E
/-- A `Basis'` is a basis without the requirement that `X ⊆ M.E`. This is convenient for some
API building, especially when working with rank and closure. -/
def Basis' (M : Matroid α) (I X : Set α) : Prop :=
I ∈ maximals (· ⊆ ·) {A | M.Indep A ∧ A ⊆ X}
theorem Basis'.indep (hI : M.Basis' I X) : M.Indep I :=
hI.1.1
theorem Basis.indep (hI : M.Basis I X) : M.Indep I :=
hI.1.1.1
theorem Basis.subset (hI : M.Basis I X) : I ⊆ X :=
hI.1.1.2
theorem Basis.basis' (hI : M.Basis I X) : M.Basis' I X :=
hI.1
theorem Basis'.basis (hI : M.Basis' I X) (hX : X ⊆ M.E := by aesop_mat) : M.Basis I X :=
⟨hI, hX⟩
theorem Basis'.subset (hI : M.Basis' I X) : I ⊆ X :=
hI.1.2
theorem setOf_basis_eq (M : Matroid α) (hX : X ⊆ M.E := by aesop_mat) :
{I | M.Basis I X} = maximals (· ⊆ ·) ({I | M.Indep I} ∩ Iic X) := by
ext I; simp [Matroid.Basis, maximals, iff_true_intro hX]
@[aesop unsafe 15% (rule_sets := [Matroid])]
theorem Basis.subset_ground (hI : M.Basis I X) : X ⊆ M.E :=
hI.2
theorem Basis.basis_inter_ground (hI : M.Basis I X) : M.Basis I (X ∩ M.E) := by
convert hI
rw [inter_eq_self_of_subset_left hI.subset_ground]
@[aesop unsafe 15% (rule_sets := [Matroid])]
theorem Basis.left_subset_ground (hI : M.Basis I X) : I ⊆ M.E :=
hI.indep.subset_ground
theorem Basis.eq_of_subset_indep (hI : M.Basis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) (hJX : J ⊆ X) :
I = J :=
hIJ.antisymm (hI.1.2 ⟨hJ, hJX⟩ hIJ)
theorem Basis.Finite (hI : M.Basis I X) [FiniteRk M] : I.Finite := hI.indep.finite
theorem basis_iff' :
M.Basis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E := by
simp [Basis, mem_maximals_setOf_iff, and_assoc, and_congr_left_iff, and_imp,
and_congr_left_iff, and_congr_right_iff, @Imp.swap (_ ⊆ X)]
theorem basis_iff (hX : X ⊆ M.E := by aesop_mat) :
M.Basis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) := by
rw [basis_iff', and_iff_left hX]
theorem basis'_iff_basis_inter_ground : M.Basis' I X ↔ M.Basis I (X ∩ M.E) := by
rw [Basis', Basis, and_iff_left inter_subset_right]
convert Iff.rfl using 3
ext I
simp only [subset_inter_iff, mem_setOf_eq, and_congr_right_iff, and_iff_left_iff_imp]
exact fun h _ ↦ h.subset_ground
theorem basis'_iff_basis (hX : X ⊆ M.E := by aesop_mat) : M.Basis' I X ↔ M.Basis I X := by
rw [basis'_iff_basis_inter_ground, inter_eq_self_of_subset_left hX]
theorem basis_iff_basis'_subset_ground : M.Basis I X ↔ M.Basis' I X ∧ X ⊆ M.E :=
⟨fun h ↦ ⟨h.basis', h.subset_ground⟩, fun h ↦ (basis'_iff_basis h.2).mp h.1⟩
theorem Basis'.basis_inter_ground (hIX : M.Basis' I X) : M.Basis I (X ∩ M.E) :=
basis'_iff_basis_inter_ground.mp hIX
theorem Basis'.eq_of_subset_indep (hI : M.Basis' I X) (hJ : M.Indep J) (hIJ : I ⊆ J)
(hJX : J ⊆ X) : I = J :=
hIJ.antisymm (hI.2 ⟨hJ, hJX⟩ hIJ)
theorem Basis'.insert_not_indep (hI : M.Basis' I X) (he : e ∈ X \ I) : ¬ M.Indep (insert e I) :=
fun hi ↦ he.2 <| insert_eq_self.1 <| Eq.symm <|
hI.eq_of_subset_indep hi (subset_insert _ _) (insert_subset he.1 hI.subset)
theorem basis_iff_mem_maximals (hX : X ⊆ M.E := by aesop_mat):
M.Basis I X ↔ I ∈ maximals (· ⊆ ·) {I | M.Indep I ∧ I ⊆ X} := by
rw [Basis, and_iff_left hX]
theorem basis_iff_mem_maximals_Prop (hX : X ⊆ M.E := by aesop_mat):
M.Basis I X ↔ I ∈ maximals (· ⊆ ·) (fun I ↦ M.Indep I ∧ I ⊆ X) :=
basis_iff_mem_maximals
theorem Indep.basis_of_maximal_subset (hI : M.Indep I) (hIX : I ⊆ X)
(hmax : ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I) (hX : X ⊆ M.E := by aesop_mat) :
M.Basis I X := by
rw [basis_iff (by aesop_mat : X ⊆ M.E), and_iff_right hI, and_iff_right hIX]
exact fun J hJ hIJ hJX ↦ hIJ.antisymm (hmax hJ hIJ hJX)
theorem Basis.basis_subset (hI : M.Basis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) : M.Basis I Y := by
rw [basis_iff (hYX.trans hI.subset_ground), and_iff_right hI.indep, and_iff_right hIY]
exact fun J hJ hIJ hJY ↦ hI.eq_of_subset_indep hJ hIJ (hJY.trans hYX)
@[simp] theorem basis_self_iff_indep : M.Basis I I ↔ M.Indep I := by
rw [basis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp]
exact fun hi ↦ ⟨fun _ _ ↦ subset_antisymm, hi.subset_ground⟩
theorem Indep.basis_self (h : M.Indep I) : M.Basis I I :=
basis_self_iff_indep.mpr h
@[simp] theorem basis_empty_iff (M : Matroid α) : M.Basis I ∅ ↔ I = ∅ :=
⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (rw [h]; exact M.empty_indep.basis_self)⟩
theorem Basis.dep_of_ssubset (hI : M.Basis I X) (hIY : I ⊂ Y) (hYX : Y ⊆ X) : M.Dep Y := by
have : X ⊆ M.E := hI.subset_ground
rw [← not_indep_iff]
exact fun hY ↦ hIY.ne (hI.eq_of_subset_indep hY hIY.subset hYX)
theorem Basis.insert_dep (hI : M.Basis I X) (he : e ∈ X \ I) : M.Dep (insert e I) :=
hI.dep_of_ssubset (ssubset_insert he.2) (insert_subset he.1 hI.subset)
theorem Basis.mem_of_insert_indep (hI : M.Basis I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) :
e ∈ I :=
by_contra (fun heI ↦ (hI.insert_dep ⟨he, heI⟩).not_indep hIe)
theorem Basis'.mem_of_insert_indep (hI : M.Basis' I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) :
e ∈ I :=
hI.basis_inter_ground.mem_of_insert_indep ⟨he, hIe.subset_ground (mem_insert _ _)⟩ hIe
theorem Basis.not_basis_of_ssubset (hI : M.Basis I X) (hJI : J ⊂ I) : ¬ M.Basis J X :=
fun h ↦ hJI.ne (h.eq_of_subset_indep hI.indep hJI.subset hI.subset)
theorem Indep.subset_basis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) :
∃ J, M.Basis J X ∧ I ⊆ J := by
obtain ⟨J, ⟨(hJ : M.Indep J),hIJ,hJX⟩, hJmax⟩ := M.maximality X hX I hI hIX
use J
rw [and_iff_left hIJ, basis_iff, and_iff_right hJ, and_iff_right hJX]
exact fun K hK hJK hKX ↦ hJK.antisymm (hJmax ⟨hK, hIJ.trans hJK, hKX⟩ hJK)
theorem Indep.subset_basis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) :
∃ J, M.Basis' J X ∧ I ⊆ J := by
simp_rw [basis'_iff_basis_inter_ground]
exact hI.subset_basis_of_subset (subset_inter hIX hI.subset_ground)
theorem exists_basis (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) :
∃ I, M.Basis I X :=
let ⟨_, hI, _⟩ := M.empty_indep.subset_basis_of_subset (empty_subset X)
⟨_,hI⟩
theorem exists_basis' (M : Matroid α) (X : Set α) : ∃ I, M.Basis' I X :=
let ⟨_, hI, _⟩ := M.empty_indep.subset_basis'_of_subset (empty_subset X)
⟨_,hI⟩
theorem exists_basis_subset_basis (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) :
∃ I J, M.Basis I X ∧ M.Basis J Y ∧ I ⊆ J := by
obtain ⟨I, hI⟩ := M.exists_basis X (hXY.trans hY)
obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_basis_of_subset (hI.subset.trans hXY)
exact ⟨_, _, hI, hJ, hIJ⟩
theorem Basis.exists_basis_inter_eq_of_superset (hI : M.Basis I X) (hXY : X ⊆ Y)
(hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.Basis J Y ∧ J ∩ X = I := by
obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_basis_of_subset (hI.subset.trans hXY)
refine ⟨J, hJ, subset_antisymm ?_ (subset_inter hIJ hI.subset)⟩
exact fun e he ↦ hI.mem_of_insert_indep he.2 (hJ.indep.subset (insert_subset he.1 hIJ))
| Mathlib/Data/Matroid/Basic.lean | 852 | 856 | theorem exists_basis_union_inter_basis (M : Matroid α) (X Y : Set α) (hX : X ⊆ M.E := by | aesop_mat)
(hY : Y ⊆ M.E := by aesop_mat) : ∃ I, M.Basis I (X ∪ Y) ∧ M.Basis (I ∩ Y) Y :=
let ⟨J, hJ⟩ := M.exists_basis Y
(hJ.exists_basis_inter_eq_of_superset subset_union_right).imp
(fun I hI ↦ ⟨hI.1, by rwa [hI.2]⟩)
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Data.Nat.Choose.Cast
import Mathlib.Data.Nat.Choose.Vandermonde
import Mathlib.Tactic.FieldSimp
#align_import data.polynomial.hasse_deriv from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"
/-!
# Hasse derivative of polynomials
The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`.
It is a variant of the usual derivative, and satisfies `k! * (hasseDeriv k f) = derivative^[k] f`.
The main benefit is that is gives an atomic way of talking about expressions such as
`(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example.
## Main declarations
In the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`.
* `Polynomial.hasseDeriv`: the `k`-th Hasse derivative of a polynomial
* `Polynomial.hasseDeriv_zero`: the `0`th Hasse derivative is the identity
* `Polynomial.hasseDeriv_one`: the `1`st Hasse derivative is the usual derivative
* `Polynomial.factorial_smul_hasseDeriv`: the identity `k! • (D k f) = derivative^[k] f`
* `Polynomial.hasseDeriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k • D (k+l)`
* `Polynomial.hasseDeriv_mul`:
the "Leibniz rule" `D k (f * g) = ∑ ij ∈ antidiagonal k, D ij.1 f * D ij.2 g`
For the identity principle, see `Polynomial.eq_zero_of_hasseDeriv_eq_zero`
in `Data/Polynomial/Taylor.lean`.
## Reference
https://math.fontein.de/2009/08/12/the-hasse-derivative/
-/
noncomputable section
namespace Polynomial
open Nat Polynomial
open Function
variable {R : Type*} [Semiring R] (k : ℕ) (f : R[X])
/-- The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`.
It satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/
def hasseDeriv (k : ℕ) : R[X] →ₗ[R] R[X] :=
lsum fun i => monomial (i - k) ∘ₗ DistribMulAction.toLinearMap R R (i.choose k)
#align polynomial.hasse_deriv Polynomial.hasseDeriv
theorem hasseDeriv_apply :
hasseDeriv k f = f.sum fun i r => monomial (i - k) (↑(i.choose k) * r) := by
dsimp [hasseDeriv]
congr; ext; congr
apply nsmul_eq_mul
#align polynomial.hasse_deriv_apply Polynomial.hasseDeriv_apply
theorem hasseDeriv_coeff (n : ℕ) :
(hasseDeriv k f).coeff n = (n + k).choose k * f.coeff (n + k) := by
rw [hasseDeriv_apply, coeff_sum, sum_def, Finset.sum_eq_single (n + k), coeff_monomial]
· simp only [if_true, add_tsub_cancel_right, eq_self_iff_true]
· intro i _hi hink
rw [coeff_monomial]
by_cases hik : i < k
· simp only [Nat.choose_eq_zero_of_lt hik, ite_self, Nat.cast_zero, zero_mul]
· push_neg at hik
rw [if_neg]
contrapose! hink
exact (tsub_eq_iff_eq_add_of_le hik).mp hink
· intro h
simp only [not_mem_support_iff.mp h, monomial_zero_right, mul_zero, coeff_zero]
#align polynomial.hasse_deriv_coeff Polynomial.hasseDeriv_coeff
theorem hasseDeriv_zero' : hasseDeriv 0 f = f := by
simp only [hasseDeriv_apply, tsub_zero, Nat.choose_zero_right, Nat.cast_one, one_mul,
sum_monomial_eq]
#align polynomial.hasse_deriv_zero' Polynomial.hasseDeriv_zero'
@[simp]
theorem hasseDeriv_zero : @hasseDeriv R _ 0 = LinearMap.id :=
LinearMap.ext <| hasseDeriv_zero'
#align polynomial.hasse_deriv_zero Polynomial.hasseDeriv_zero
| Mathlib/Algebra/Polynomial/HasseDeriv.lean | 93 | 97 | theorem hasseDeriv_eq_zero_of_lt_natDegree (p : R[X]) (n : ℕ) (h : p.natDegree < n) :
hasseDeriv n p = 0 := by |
rw [hasseDeriv_apply, sum_def]
refine Finset.sum_eq_zero fun x hx => ?_
simp [Nat.choose_eq_zero_of_lt ((le_natDegree_of_mem_supp _ hx).trans_lt h)]
|
/-
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, Floris van Doorn
-/
import Mathlib.Analysis.Calculus.ContDiff.Defs
import Mathlib.Analysis.Calculus.FDeriv.Add
import Mathlib.Analysis.Calculus.FDeriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Inverse
#align_import analysis.calculus.cont_diff from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-!
# Higher differentiability of usual operations
We prove that the usual operations (addition, multiplication, difference, composition, and
so on) preserve `C^n` functions. We also expand the API around `C^n` functions.
## Main results
* `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`.
Similar results are given for `C^n` functions on domains.
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `⊤ : ℕ∞` with `∞`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open scoped Classical NNReal Nat
local notation "∞" => (⊤ : ℕ∞)
universe u v w uD uE uF uG
attribute [local instance 1001]
NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid
open Set Fin Filter Function
open scoped Topology
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D]
[NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF}
[NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
{X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F}
{g : F → G} {x x₀ : E} {c : F} {b : E × F → G} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Constants -/
@[simp]
theorem iteratedFDerivWithin_zero_fun (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} :
iteratedFDerivWithin 𝕜 i (fun _ : E ↦ (0 : F)) s x = 0 := by
induction i generalizing x with
| zero => ext; simp
| succ i IH =>
ext m
rw [iteratedFDerivWithin_succ_apply_left, fderivWithin_congr (fun _ ↦ IH) (IH hx)]
rw [fderivWithin_const_apply _ (hs x hx)]
rfl
@[simp]
theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↦ (0 : F)) = 0 :=
funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using
iteratedFDerivWithin_zero_fun uniqueDiffOn_univ (mem_univ x)
#align iterated_fderiv_zero_fun iteratedFDeriv_zero_fun
theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) :=
contDiff_of_differentiable_iteratedFDeriv fun m _ => by
rw [iteratedFDeriv_zero_fun]
exact differentiable_const (0 : E[×m]→L[𝕜] F)
#align cont_diff_zero_fun contDiff_zero_fun
/-- Constants are `C^∞`.
-/
theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c := by
suffices h : ContDiff 𝕜 ∞ fun _ : E => c from h.of_le le_top
rw [contDiff_top_iff_fderiv]
refine ⟨differentiable_const c, ?_⟩
rw [fderiv_const]
exact contDiff_zero_fun
#align cont_diff_const contDiff_const
theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s :=
contDiff_const.contDiffOn
#align cont_diff_on_const contDiffOn_const
theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x :=
contDiff_const.contDiffAt
#align cont_diff_at_const contDiffAt_const
theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x :=
contDiffAt_const.contDiffWithinAt
#align cont_diff_within_at_const contDiffWithinAt_const
@[nontriviality]
theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const
#align cont_diff_of_subsingleton contDiff_of_subsingleton
@[nontriviality]
theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const
#align cont_diff_at_of_subsingleton contDiffAt_of_subsingleton
@[nontriviality]
theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const
#align cont_diff_within_at_of_subsingleton contDiffWithinAt_of_subsingleton
@[nontriviality]
theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const
#align cont_diff_on_of_subsingleton contDiffOn_of_subsingleton
theorem iteratedFDerivWithin_succ_const (n : ℕ) (c : F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 (n + 1) (fun _ : E ↦ c) s x = 0 := by
ext m
rw [iteratedFDerivWithin_succ_apply_right hs hx]
rw [iteratedFDerivWithin_congr (fun y hy ↦ fderivWithin_const_apply c (hs y hy)) hx]
rw [iteratedFDerivWithin_zero_fun hs hx]
simp [ContinuousMultilinearMap.zero_apply (R := 𝕜)]
theorem iteratedFDeriv_succ_const (n : ℕ) (c : F) :
(iteratedFDeriv 𝕜 (n + 1) fun _ : E ↦ c) = 0 :=
funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using
iteratedFDerivWithin_succ_const n c uniqueDiffOn_univ (mem_univ x)
#align iterated_fderiv_succ_const iteratedFDeriv_succ_const
theorem iteratedFDerivWithin_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 n (fun _ : E ↦ c) s x = 0 := by
cases n with
| zero => contradiction
| succ n => exact iteratedFDerivWithin_succ_const n c hs hx
theorem iteratedFDeriv_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) :
(iteratedFDeriv 𝕜 n fun _ : E ↦ c) = 0 :=
funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using
iteratedFDerivWithin_const_of_ne hn c uniqueDiffOn_univ (mem_univ x)
#align iterated_fderiv_const_of_ne iteratedFDeriv_const_of_ne
/-! ### Smoothness of linear functions -/
/-- Unbundled bounded linear functions are `C^∞`.
-/
theorem IsBoundedLinearMap.contDiff (hf : IsBoundedLinearMap 𝕜 f) : ContDiff 𝕜 n f := by
suffices h : ContDiff 𝕜 ∞ f from h.of_le le_top
rw [contDiff_top_iff_fderiv]
refine ⟨hf.differentiable, ?_⟩
simp_rw [hf.fderiv]
exact contDiff_const
#align is_bounded_linear_map.cont_diff IsBoundedLinearMap.contDiff
theorem ContinuousLinearMap.contDiff (f : E →L[𝕜] F) : ContDiff 𝕜 n f :=
f.isBoundedLinearMap.contDiff
#align continuous_linear_map.cont_diff ContinuousLinearMap.contDiff
theorem ContinuousLinearEquiv.contDiff (f : E ≃L[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
#align continuous_linear_equiv.cont_diff ContinuousLinearEquiv.contDiff
theorem LinearIsometry.contDiff (f : E →ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
f.toContinuousLinearMap.contDiff
#align linear_isometry.cont_diff LinearIsometry.contDiff
theorem LinearIsometryEquiv.contDiff (f : E ≃ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
#align linear_isometry_equiv.cont_diff LinearIsometryEquiv.contDiff
/-- The identity is `C^∞`.
-/
theorem contDiff_id : ContDiff 𝕜 n (id : E → E) :=
IsBoundedLinearMap.id.contDiff
#align cont_diff_id contDiff_id
theorem contDiffWithinAt_id {s x} : ContDiffWithinAt 𝕜 n (id : E → E) s x :=
contDiff_id.contDiffWithinAt
#align cont_diff_within_at_id contDiffWithinAt_id
theorem contDiffAt_id {x} : ContDiffAt 𝕜 n (id : E → E) x :=
contDiff_id.contDiffAt
#align cont_diff_at_id contDiffAt_id
theorem contDiffOn_id {s} : ContDiffOn 𝕜 n (id : E → E) s :=
contDiff_id.contDiffOn
#align cont_diff_on_id contDiffOn_id
/-- Bilinear functions are `C^∞`.
-/
theorem IsBoundedBilinearMap.contDiff (hb : IsBoundedBilinearMap 𝕜 b) : ContDiff 𝕜 n b := by
suffices h : ContDiff 𝕜 ∞ b from h.of_le le_top
rw [contDiff_top_iff_fderiv]
refine ⟨hb.differentiable, ?_⟩
simp only [hb.fderiv]
exact hb.isBoundedLinearMap_deriv.contDiff
#align is_bounded_bilinear_map.cont_diff IsBoundedBilinearMap.contDiff
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor
series whose `k`-th term is given by `g ∘ (p k)`. -/
theorem HasFTaylorSeriesUpToOn.continuousLinearMap_comp (g : F →L[𝕜] G)
(hf : HasFTaylorSeriesUpToOn n f p s) :
HasFTaylorSeriesUpToOn n (g ∘ f) (fun x k => g.compContinuousMultilinearMap (p x k)) s where
zero_eq x hx := congr_arg g (hf.zero_eq x hx)
fderivWithin m hm x hx := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).hasFDerivAt.comp_hasFDerivWithinAt x (hf.fderivWithin m hm x hx)
cont m hm := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).continuous.comp_continuousOn (hf.cont m hm)
#align has_ftaylor_series_up_to_on.continuous_linear_map_comp HasFTaylorSeriesUpToOn.continuousLinearMap_comp
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffWithinAt.continuousLinearMap_comp (g : F →L[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := fun m hm ↦ by
rcases hf m hm with ⟨u, hu, p, hp⟩
exact ⟨u, hu, _, hp.continuousLinearMap_comp g⟩
#align cont_diff_within_at.continuous_linear_map_comp ContDiffWithinAt.continuousLinearMap_comp
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (g ∘ f) x :=
ContDiffWithinAt.continuousLinearMap_comp g hf
#align cont_diff_at.continuous_linear_map_comp ContDiffAt.continuousLinearMap_comp
/-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/
theorem ContDiffOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (g ∘ f) s := fun x hx => (hf x hx).continuousLinearMap_comp g
#align cont_diff_on.continuous_linear_map_comp ContDiffOn.continuousLinearMap_comp
/-- Composition by continuous linear maps on the left preserves `C^n` functions. -/
theorem ContDiff.continuousLinearMap_comp {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n fun x => g (f x) :=
contDiffOn_univ.1 <| ContDiffOn.continuousLinearMap_comp _ (contDiffOn_univ.2 hf)
#align cont_diff.continuous_linear_map_comp ContDiff.continuousLinearMap_comp
/-- The iterated derivative within a set of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
theorem ContinuousLinearMap.iteratedFDerivWithin_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
g.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) :=
(((hf.ftaylorSeriesWithin hs).continuousLinearMap_comp g).eq_iteratedFDerivWithin_of_uniqueDiffOn
hi hs hx).symm
#align continuous_linear_map.iterated_fderiv_within_comp_left ContinuousLinearMap.iteratedFDerivWithin_comp_left
/-- The iterated derivative of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
theorem ContinuousLinearMap.iteratedFDeriv_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≤ n) :
iteratedFDeriv 𝕜 i (g ∘ f) x = g.compContinuousMultilinearMap (iteratedFDeriv 𝕜 i f x) := by
simp only [← iteratedFDerivWithin_univ]
exact g.iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi
#align continuous_linear_map.iterated_fderiv_comp_left ContinuousLinearMap.iteratedFDeriv_comp_left
/-- The iterated derivative within a set of the composition with a linear equiv on the left is
obtained by applying the linear equiv to the iterated derivative. This is true without
differentiability assumptions. -/
theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_left (g : F ≃L[𝕜] G) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by
induction' i with i IH generalizing x
· ext1 m
simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, coe_coe]
· ext1 m
rw [iteratedFDerivWithin_succ_apply_left]
have Z : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (g ∘ f) s) s x =
fderivWithin 𝕜 (g.compContinuousMultilinearMapL (fun _ : Fin i => E) ∘
iteratedFDerivWithin 𝕜 i f s) s x :=
fderivWithin_congr' (@IH) hx
simp_rw [Z]
rw [(g.compContinuousMultilinearMapL fun _ : Fin i => E).comp_fderivWithin (hs x hx)]
simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply,
ContinuousLinearEquiv.compContinuousMultilinearMapL_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, EmbeddingLike.apply_eq_iff_eq]
rw [iteratedFDerivWithin_succ_apply_left]
#align continuous_linear_equiv.iterated_fderiv_within_comp_left ContinuousLinearEquiv.iteratedFDerivWithin_comp_left
/-- Composition with a linear isometry on the left preserves the norm of the iterated
derivative within a set. -/
theorem LinearIsometry.norm_iteratedFDerivWithin_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G)
(hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) :
‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by
have :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
g.toContinuousLinearMap.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) :=
g.toContinuousLinearMap.iteratedFDerivWithin_comp_left hf hs hx hi
rw [this]
apply LinearIsometry.norm_compContinuousMultilinearMap
#align linear_isometry.norm_iterated_fderiv_within_comp_left LinearIsometry.norm_iteratedFDerivWithin_comp_left
/-- Composition with a linear isometry on the left preserves the norm of the iterated
derivative. -/
theorem LinearIsometry.norm_iteratedFDeriv_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G)
(hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≤ n) :
‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by
simp only [← iteratedFDerivWithin_univ]
exact g.norm_iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi
#align linear_isometry.norm_iterated_fderiv_comp_left LinearIsometry.norm_iteratedFDeriv_comp_left
/-- Composition with a linear isometry equiv on the left preserves the norm of the iterated
derivative within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) :
‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by
have :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) :=
g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_left f hs hx i
rw [this]
apply LinearIsometry.norm_compContinuousMultilinearMap g.toLinearIsometry
#align linear_isometry_equiv.norm_iterated_fderiv_within_comp_left LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left
/-- Composition with a linear isometry equiv on the left preserves the norm of the iterated
derivative. -/
theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (x : E)
(i : ℕ) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by
rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ]
apply g.norm_iteratedFDerivWithin_comp_left f uniqueDiffOn_univ (mem_univ x) i
#align linear_isometry_equiv.norm_iterated_fderiv_comp_left LinearIsometryEquiv.norm_iteratedFDeriv_comp_left
/-- Composition by continuous linear equivs on the left respects higher differentiability at a
point in a domain. -/
theorem ContinuousLinearEquiv.comp_contDiffWithinAt_iff (e : F ≃L[𝕜] G) :
ContDiffWithinAt 𝕜 n (e ∘ f) s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H => by
simpa only [(· ∘ ·), e.symm.coe_coe, e.symm_apply_apply] using
H.continuousLinearMap_comp (e.symm : G →L[𝕜] F),
fun H => H.continuousLinearMap_comp (e : F →L[𝕜] G)⟩
#align continuous_linear_equiv.comp_cont_diff_within_at_iff ContinuousLinearEquiv.comp_contDiffWithinAt_iff
/-- Composition by continuous linear equivs on the left respects higher differentiability at a
point. -/
theorem ContinuousLinearEquiv.comp_contDiffAt_iff (e : F ≃L[𝕜] G) :
ContDiffAt 𝕜 n (e ∘ f) x ↔ ContDiffAt 𝕜 n f x := by
simp only [← contDiffWithinAt_univ, e.comp_contDiffWithinAt_iff]
#align continuous_linear_equiv.comp_cont_diff_at_iff ContinuousLinearEquiv.comp_contDiffAt_iff
/-- Composition by continuous linear equivs on the left respects higher differentiability on
domains. -/
theorem ContinuousLinearEquiv.comp_contDiffOn_iff (e : F ≃L[𝕜] G) :
ContDiffOn 𝕜 n (e ∘ f) s ↔ ContDiffOn 𝕜 n f s := by
simp [ContDiffOn, e.comp_contDiffWithinAt_iff]
#align continuous_linear_equiv.comp_cont_diff_on_iff ContinuousLinearEquiv.comp_contDiffOn_iff
/-- Composition by continuous linear equivs on the left respects higher differentiability. -/
theorem ContinuousLinearEquiv.comp_contDiff_iff (e : F ≃L[𝕜] G) :
ContDiff 𝕜 n (e ∘ f) ↔ ContDiff 𝕜 n f := by
simp only [← contDiffOn_univ, e.comp_contDiffOn_iff]
#align continuous_linear_equiv.comp_cont_diff_iff ContinuousLinearEquiv.comp_contDiff_iff
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor
series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vₖ)` . -/
theorem HasFTaylorSeriesUpToOn.compContinuousLinearMap (hf : HasFTaylorSeriesUpToOn n f p s)
(g : G →L[𝕜] E) :
HasFTaylorSeriesUpToOn n (f ∘ g) (fun x k => (p (g x) k).compContinuousLinearMap fun _ => g)
(g ⁻¹' s) := by
let A : ∀ m : ℕ, (E[×m]→L[𝕜] F) → G[×m]→L[𝕜] F := fun m h => h.compContinuousLinearMap fun _ => g
have hA : ∀ m, IsBoundedLinearMap 𝕜 (A m) := fun m =>
isBoundedLinearMap_continuousMultilinearMap_comp_linear g
constructor
· intro x hx
simp only [(hf.zero_eq (g x) hx).symm, Function.comp_apply]
change (p (g x) 0 fun _ : Fin 0 => g 0) = p (g x) 0 0
rw [ContinuousLinearMap.map_zero]
rfl
· intro m hm x hx
convert (hA m).hasFDerivAt.comp_hasFDerivWithinAt x
((hf.fderivWithin m hm (g x) hx).comp x g.hasFDerivWithinAt (Subset.refl _))
ext y v
change p (g x) (Nat.succ m) (g ∘ cons y v) = p (g x) m.succ (cons (g y) (g ∘ v))
rw [comp_cons]
· intro m hm
exact (hA m).continuous.comp_continuousOn <| (hf.cont m hm).comp g.continuous.continuousOn <|
Subset.refl _
#align has_ftaylor_series_up_to_on.comp_continuous_linear_map HasFTaylorSeriesUpToOn.compContinuousLinearMap
/-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on
a domain. -/
theorem ContDiffWithinAt.comp_continuousLinearMap {x : G} (g : G →L[𝕜] E)
(hf : ContDiffWithinAt 𝕜 n f s (g x)) : ContDiffWithinAt 𝕜 n (f ∘ g) (g ⁻¹' s) x := by
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
refine ⟨g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g⟩
refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu
exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _)
#align cont_diff_within_at.comp_continuous_linear_map ContDiffWithinAt.comp_continuousLinearMap
/-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/
theorem ContDiffOn.comp_continuousLinearMap (hf : ContDiffOn 𝕜 n f s) (g : G →L[𝕜] E) :
ContDiffOn 𝕜 n (f ∘ g) (g ⁻¹' s) := fun x hx => (hf (g x) hx).comp_continuousLinearMap g
#align cont_diff_on.comp_continuous_linear_map ContDiffOn.comp_continuousLinearMap
/-- Composition by continuous linear maps on the right preserves `C^n` functions. -/
theorem ContDiff.comp_continuousLinearMap {f : E → F} {g : G →L[𝕜] E} (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n (f ∘ g) :=
contDiffOn_univ.1 <| ContDiffOn.comp_continuousLinearMap (contDiffOn_univ.2 hf) _
#align cont_diff.comp_continuous_linear_map ContDiff.comp_continuousLinearMap
/-- The iterated derivative within a set of the composition with a linear map on the right is
obtained by composing the iterated derivative with the linear map. -/
theorem ContinuousLinearMap.iteratedFDerivWithin_comp_right {f : E → F} (g : G →L[𝕜] E)
(hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (h's : UniqueDiffOn 𝕜 (g ⁻¹' s)) {x : G}
(hx : g x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) :
iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g :=
(((hf.ftaylorSeriesWithin hs).compContinuousLinearMap g).eq_iteratedFDerivWithin_of_uniqueDiffOn
hi h's hx).symm
#align continuous_linear_map.iterated_fderiv_within_comp_right ContinuousLinearMap.iteratedFDerivWithin_comp_right
/-- The iterated derivative within a set of the composition with a linear equiv on the right is
obtained by composing the iterated derivative with the linear equiv. -/
theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_right (g : G ≃L[𝕜] E) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) :
iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := by
induction' i with i IH generalizing x
· ext1
simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply,
ContinuousMultilinearMap.compContinuousLinearMap_apply]
· ext1 m
simp only [ContinuousMultilinearMap.compContinuousLinearMap_apply,
ContinuousLinearEquiv.coe_coe, iteratedFDerivWithin_succ_apply_left]
have : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s)) (g ⁻¹' s) x =
fderivWithin 𝕜
(ContinuousMultilinearMap.compContinuousLinearMapEquivL _ (fun _x : Fin i => g) ∘
(iteratedFDerivWithin 𝕜 i f s ∘ g)) (g ⁻¹' s) x :=
fderivWithin_congr' (@IH) hx
rw [this, ContinuousLinearEquiv.comp_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx)]
simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply,
ContinuousMultilinearMap.compContinuousLinearMapEquivL_apply,
ContinuousMultilinearMap.compContinuousLinearMap_apply]
rw [ContinuousLinearEquiv.comp_right_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx),
ContinuousLinearMap.coe_comp', coe_coe, comp_apply, tail_def, tail_def]
#align continuous_linear_equiv.iterated_fderiv_within_comp_right ContinuousLinearEquiv.iteratedFDerivWithin_comp_right
/-- The iterated derivative of the composition with a linear map on the right is
obtained by composing the iterated derivative with the linear map. -/
theorem ContinuousLinearMap.iteratedFDeriv_comp_right (g : G →L[𝕜] E) {f : E → F}
(hf : ContDiff 𝕜 n f) (x : G) {i : ℕ} (hi : (i : ℕ∞) ≤ n) :
iteratedFDeriv 𝕜 i (f ∘ g) x =
(iteratedFDeriv 𝕜 i f (g x)).compContinuousLinearMap fun _ => g := by
simp only [← iteratedFDerivWithin_univ]
exact g.iteratedFDerivWithin_comp_right hf.contDiffOn uniqueDiffOn_univ uniqueDiffOn_univ
(mem_univ _) hi
#align continuous_linear_map.iterated_fderiv_comp_right ContinuousLinearMap.iteratedFDeriv_comp_right
/-- Composition with a linear isometry on the right preserves the norm of the iterated derivative
within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) :
‖iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x‖ = ‖iteratedFDerivWithin 𝕜 i f s (g x)‖ := by
have : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g :=
g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_right f hs hx i
rw [this, ContinuousMultilinearMap.norm_compContinuous_linearIsometryEquiv]
#align linear_isometry_equiv.norm_iterated_fderiv_within_comp_right LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right
/-- Composition with a linear isometry on the right preserves the norm of the iterated derivative
within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (x : G)
(i : ℕ) : ‖iteratedFDeriv 𝕜 i (f ∘ g) x‖ = ‖iteratedFDeriv 𝕜 i f (g x)‖ := by
simp only [← iteratedFDerivWithin_univ]
apply g.norm_iteratedFDerivWithin_comp_right f uniqueDiffOn_univ (mem_univ (g x)) i
#align linear_isometry_equiv.norm_iterated_fderiv_comp_right LinearIsometryEquiv.norm_iteratedFDeriv_comp_right
/-- Composition by continuous linear equivs on the right respects higher differentiability at a
point in a domain. -/
theorem ContinuousLinearEquiv.contDiffWithinAt_comp_iff (e : G ≃L[𝕜] E) :
ContDiffWithinAt 𝕜 n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔ ContDiffWithinAt 𝕜 n f s x := by
constructor
· intro H
simpa [← preimage_comp, (· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G)
· intro H
rw [← e.apply_symm_apply x, ← e.coe_coe] at H
exact H.comp_continuousLinearMap _
#align continuous_linear_equiv.cont_diff_within_at_comp_iff ContinuousLinearEquiv.contDiffWithinAt_comp_iff
/-- Composition by continuous linear equivs on the right respects higher differentiability at a
point. -/
theorem ContinuousLinearEquiv.contDiffAt_comp_iff (e : G ≃L[𝕜] E) :
ContDiffAt 𝕜 n (f ∘ e) (e.symm x) ↔ ContDiffAt 𝕜 n f x := by
rw [← contDiffWithinAt_univ, ← contDiffWithinAt_univ, ← preimage_univ]
exact e.contDiffWithinAt_comp_iff
#align continuous_linear_equiv.cont_diff_at_comp_iff ContinuousLinearEquiv.contDiffAt_comp_iff
/-- Composition by continuous linear equivs on the right respects higher differentiability on
domains. -/
theorem ContinuousLinearEquiv.contDiffOn_comp_iff (e : G ≃L[𝕜] E) :
ContDiffOn 𝕜 n (f ∘ e) (e ⁻¹' s) ↔ ContDiffOn 𝕜 n f s :=
⟨fun H => by simpa [(· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G), fun H =>
H.comp_continuousLinearMap (e : G →L[𝕜] E)⟩
#align continuous_linear_equiv.cont_diff_on_comp_iff ContinuousLinearEquiv.contDiffOn_comp_iff
/-- Composition by continuous linear equivs on the right respects higher differentiability. -/
theorem ContinuousLinearEquiv.contDiff_comp_iff (e : G ≃L[𝕜] E) :
ContDiff 𝕜 n (f ∘ e) ↔ ContDiff 𝕜 n f := by
rw [← contDiffOn_univ, ← contDiffOn_univ, ← preimage_univ]
exact e.contDiffOn_comp_iff
#align continuous_linear_equiv.cont_diff_comp_iff ContinuousLinearEquiv.contDiff_comp_iff
/-- If two functions `f` and `g` admit Taylor series `p` and `q` in a set `s`, then the cartesian
product of `f` and `g` admits the cartesian product of `p` and `q` as a Taylor series. -/
theorem HasFTaylorSeriesUpToOn.prod (hf : HasFTaylorSeriesUpToOn n f p s) {g : E → G}
{q : E → FormalMultilinearSeries 𝕜 E G} (hg : HasFTaylorSeriesUpToOn n g q s) :
HasFTaylorSeriesUpToOn n (fun y => (f y, g y)) (fun y k => (p y k).prod (q y k)) s := by
set L := fun m => ContinuousMultilinearMap.prodL 𝕜 (fun _ : Fin m => E) F G
constructor
· intro x hx; rw [← hf.zero_eq x hx, ← hg.zero_eq x hx]; rfl
· intro m hm x hx
convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x
((hf.fderivWithin m hm x hx).prod (hg.fderivWithin m hm x hx))
· intro m hm
exact (L m).continuous.comp_continuousOn ((hf.cont m hm).prod (hg.cont m hm))
#align has_ftaylor_series_up_to_on.prod HasFTaylorSeriesUpToOn.prod
/-- The cartesian product of `C^n` functions at a point in a domain is `C^n`. -/
theorem ContDiffWithinAt.prod {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffWithinAt 𝕜 n f s x)
(hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x : E => (f x, g x)) s x := by
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
rcases hg m hm with ⟨v, hv, q, hq⟩
exact
⟨u ∩ v, Filter.inter_mem hu hv, _,
(hp.mono inter_subset_left).prod (hq.mono inter_subset_right)⟩
#align cont_diff_within_at.prod ContDiffWithinAt.prod
/-- The cartesian product of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.prod {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x : E => (f x, g x)) s := fun x hx =>
(hf x hx).prod (hg x hx)
#align cont_diff_on.prod ContDiffOn.prod
/-- The cartesian product of `C^n` functions at a point is `C^n`. -/
theorem ContDiffAt.prod {f : E → F} {g : E → G} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x : E => (f x, g x)) x :=
contDiffWithinAt_univ.1 <|
ContDiffWithinAt.prod (contDiffWithinAt_univ.2 hf) (contDiffWithinAt_univ.2 hg)
#align cont_diff_at.prod ContDiffAt.prod
/-- The cartesian product of `C^n` functions is `C^n`. -/
theorem ContDiff.prod {f : E → F} {g : E → G} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n fun x : E => (f x, g x) :=
contDiffOn_univ.1 <| ContDiffOn.prod (contDiffOn_univ.2 hf) (contDiffOn_univ.2 hg)
#align cont_diff.prod ContDiff.prod
/-!
### Composition of `C^n` functions
We show that the composition of `C^n` functions is `C^n`. One way to prove it would be to write
the `n`-th derivative of the composition (this is Faà di Bruno's formula) and check its continuity,
but this is very painful. Instead, we go for a simple inductive proof. Assume it is done for `n`.
Then, to check it for `n+1`, one needs to check that the derivative of `g ∘ f` is `C^n`, i.e.,
that `Dg(f x) ⬝ Df(x)` is `C^n`. The term `Dg (f x)` is the composition of two `C^n` functions, so
it is `C^n` by the inductive assumption. The term `Df(x)` is also `C^n`. Then, the matrix
multiplication is the application of a bilinear map (which is `C^∞`, and therefore `C^n`) to
`x ↦ (Dg(f x), Df x)`. As the composition of two `C^n` maps, it is again `C^n`, and we are done.
There is a subtlety in this argument: we apply the inductive assumption to functions on other Banach
spaces. In maths, one would say: prove by induction over `n` that, for all `C^n` maps between all
pairs of Banach spaces, their composition is `C^n`. In Lean, this is fine as long as the spaces
stay in the same universe. This is not the case in the above argument: if `E` lives in universe `u`
and `F` lives in universe `v`, then linear maps from `E` to `F` (to which the derivative of `f`
belongs) is in universe `max u v`. If one could quantify over finitely many universes, the above
proof would work fine, but this is not the case. One could still write the proof considering spaces
in any universe in `u, v, w, max u v, max v w, max u v w`, but it would be extremely tedious and
lead to a lot of duplication. Instead, we formulate the above proof when all spaces live in the same
universe (where everything is fine), and then we deduce the general result by lifting all our spaces
to a common universe through `ULift`. This lifting is done through a continuous linear equiv.
We have already proved that composing with such a linear equiv does not change the fact of
being `C^n`, which concludes the proof.
-/
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
{Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
[NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
(hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
ContDiffOn 𝕜 n (g ∘ f) s := by
induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
· rw [contDiffOn_zero] at hf hg ⊢
exact ContinuousOn.comp hg hf st
· rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
intro x hx
rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
rw [insert_eq_of_mem hx] at hu ⊢
have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
let w := s ∩ (u ∩ f ⁻¹' v)
have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
have wu : w ⊆ u := fun y hy => hy.2.1
have ws : w ⊆ s := fun y hy => hy.1
refine ⟨w, ?_, fun y => (g' (f y)).comp (f' y), ?_, ?_⟩
· show w ∈ 𝓝[s] x
apply Filter.inter_mem self_mem_nhdsWithin
apply Filter.inter_mem hu
apply ContinuousWithinAt.preimage_mem_nhdsWithin'
· rw [← continuousWithinAt_inter' hu]
exact (hf' x xu).differentiableWithinAt.continuousWithinAt.mono inter_subset_right
· apply nhdsWithin_mono _ _ hv
exact Subset.trans (image_subset_iff.mpr st) (subset_insert (f x) t)
· show ∀ y ∈ w, HasFDerivWithinAt (g ∘ f) ((g' (f y)).comp (f' y)) w y
rintro y ⟨-, yu, yv⟩
exact (hg' (f y) yv).comp y ((hf' y yu).mono wu) wv
· show ContDiffOn 𝕜 n (fun y => (g' (f y)).comp (f' y)) w
have A : ContDiffOn 𝕜 n (fun y => g' (f y)) w :=
IH g'_diff ((hf.of_le (WithTop.coe_le_coe.2 (Nat.le_succ n))).mono ws) wv
have B : ContDiffOn 𝕜 n f' w := f'_diff.mono wu
have C : ContDiffOn 𝕜 n (fun y => (g' (f y), f' y)) w := A.prod B
have D : ContDiffOn 𝕜 n (fun p : (Fu →L[𝕜] Gu) × (Eu →L[𝕜] Fu) => p.1.comp p.2) univ :=
isBoundedBilinearMap_comp.contDiff.contDiffOn
exact IH D C (subset_univ _)
· rw [contDiffOn_top] at hf hg ⊢
exact fun n => Itop n (hg n) (hf n) st
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
(hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) : ContDiffOn 𝕜 n (g ∘ f) s := by
/- we lift all the spaces to a common universe, as we have already proved the result in this
situation. -/
let Eu : Type max uE uF uG := ULift.{max uF uG} E
let Fu : Type max uE uF uG := ULift.{max uE uG} F
let Gu : Type max uE uF uG := ULift.{max uE uF} G
-- declare the isomorphisms
have isoE : Eu ≃L[𝕜] E := ContinuousLinearEquiv.ulift
have isoF : Fu ≃L[𝕜] F := ContinuousLinearEquiv.ulift
have isoG : Gu ≃L[𝕜] G := ContinuousLinearEquiv.ulift
-- lift the functions to the new spaces, check smoothness there, and then go back.
let fu : Eu → Fu := (isoF.symm ∘ f) ∘ isoE
have fu_diff : ContDiffOn 𝕜 n fu (isoE ⁻¹' s) := by
rwa [isoE.contDiffOn_comp_iff, isoF.symm.comp_contDiffOn_iff]
let gu : Fu → Gu := (isoG.symm ∘ g) ∘ isoF
have gu_diff : ContDiffOn 𝕜 n gu (isoF ⁻¹' t) := by
rwa [isoF.contDiffOn_comp_iff, isoG.symm.comp_contDiffOn_iff]
have main : ContDiffOn 𝕜 n (gu ∘ fu) (isoE ⁻¹' s) := by
apply ContDiffOn.comp_same_univ gu_diff fu_diff
intro y hy
simp only [fu, ContinuousLinearEquiv.coe_apply, Function.comp_apply, mem_preimage]
rw [isoF.apply_symm_apply (f (isoE y))]
exact st hy
have : gu ∘ fu = (isoG.symm ∘ g ∘ f) ∘ isoE := by
ext y
simp only [fu, gu, Function.comp_apply]
rw [isoF.apply_symm_apply (f (isoE y))]
rwa [this, isoE.contDiffOn_comp_iff, isoG.symm.comp_contDiffOn_iff] at main
#align cont_diff_on.comp ContDiffOn.comp
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp' {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
(hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) :=
hg.comp (hf.mono inter_subset_left) inter_subset_right
#align cont_diff_on.comp' ContDiffOn.comp'
/-- The composition of a `C^n` function on a domain with a `C^n` function is `C^n`. -/
theorem ContDiff.comp_contDiffOn {s : Set E} {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g)
(hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s :=
(contDiffOn_univ.2 hg).comp hf subset_preimage_univ
#align cont_diff.comp_cont_diff_on ContDiff.comp_contDiffOn
/-- The composition of `C^n` functions is `C^n`. -/
theorem ContDiff.comp {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n (g ∘ f) :=
contDiffOn_univ.1 <| ContDiffOn.comp (contDiffOn_univ.2 hg) (contDiffOn_univ.2 hf) (subset_univ _)
#align cont_diff.comp ContDiff.comp
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) (st : s ⊆ f ⁻¹' t) :
ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
intro m hm
rcases hg.contDiffOn hm with ⟨u, u_nhd, _, hu⟩
rcases hf.contDiffOn hm with ⟨v, v_nhd, vs, hv⟩
have xmem : x ∈ f ⁻¹' u ∩ v :=
⟨(mem_of_mem_nhdsWithin (mem_insert (f x) _) u_nhd : _),
mem_of_mem_nhdsWithin (mem_insert x s) v_nhd⟩
have : f ⁻¹' u ∈ 𝓝[insert x s] x := by
apply hf.continuousWithinAt.insert_self.preimage_mem_nhdsWithin'
apply nhdsWithin_mono _ _ u_nhd
rw [image_insert_eq]
exact insert_subset_insert (image_subset_iff.mpr st)
have Z :=
(hu.comp (hv.mono inter_subset_right) inter_subset_left).contDiffWithinAt
xmem m le_rfl
have : 𝓝[f ⁻¹' u ∩ v] x = 𝓝[insert x s] x := by
have A : f ⁻¹' u ∩ v = insert x s ∩ (f ⁻¹' u ∩ v) := by
apply Subset.antisymm _ inter_subset_right
rintro y ⟨hy1, hy2⟩
simpa only [mem_inter_iff, mem_preimage, hy2, and_true, true_and, vs hy2] using hy1
rw [A, ← nhdsWithin_restrict'']
exact Filter.inter_mem this v_nhd
rwa [insert_eq_of_mem xmem, this] at Z
#align cont_diff_within_at.comp ContDiffWithinAt.comp
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_mem {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : t ∈ 𝓝[f '' s] f x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
(hg.mono_of_mem hs).comp x hf (subset_preimage_image f s)
#align cont_diff_within_at.comp_of_mem ContDiffWithinAt.comp_of_mem
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp' {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) x :=
hg.comp x (hf.mono inter_subset_left) inter_subset_right
#align cont_diff_within_at.comp' ContDiffWithinAt.comp'
theorem ContDiffAt.comp_contDiffWithinAt {n} (x : E) (hg : ContDiffAt 𝕜 n g (f x))
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
hg.comp x hf (mapsTo_univ _ _)
#align cont_diff_at.comp_cont_diff_within_at ContDiffAt.comp_contDiffWithinAt
/-- The composition of `C^n` functions at points is `C^n`. -/
nonrec theorem ContDiffAt.comp (x : E) (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (g ∘ f) x :=
hg.comp x hf subset_preimage_univ
#align cont_diff_at.comp ContDiffAt.comp
theorem ContDiff.comp_contDiffWithinAt {g : F → G} {f : E → F} (h : ContDiff 𝕜 n g)
(hf : ContDiffWithinAt 𝕜 n f t x) : ContDiffWithinAt 𝕜 n (g ∘ f) t x :=
haveI : ContDiffWithinAt 𝕜 n g univ (f x) := h.contDiffAt.contDiffWithinAt
this.comp x hf (subset_univ _)
#align cont_diff.comp_cont_diff_within_at ContDiff.comp_contDiffWithinAt
theorem ContDiff.comp_contDiffAt {g : F → G} {f : E → F} (x : E) (hg : ContDiff 𝕜 n g)
(hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x :=
hg.comp_contDiffWithinAt hf
#align cont_diff.comp_cont_diff_at ContDiff.comp_contDiffAt
/-!
### Smoothness of projections
-/
/-- The first projection in a product is `C^∞`. -/
theorem contDiff_fst : ContDiff 𝕜 n (Prod.fst : E × F → E) :=
IsBoundedLinearMap.contDiff IsBoundedLinearMap.fst
#align cont_diff_fst contDiff_fst
/-- Postcomposing `f` with `Prod.fst` is `C^n` -/
theorem ContDiff.fst {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).1 :=
contDiff_fst.comp hf
#align cont_diff.fst ContDiff.fst
/-- Precomposing `f` with `Prod.fst` is `C^n` -/
theorem ContDiff.fst' {f : E → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.1 :=
hf.comp contDiff_fst
#align cont_diff.fst' ContDiff.fst'
/-- The first projection on a domain in a product is `C^∞`. -/
theorem contDiffOn_fst {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.fst : E × F → E) s :=
ContDiff.contDiffOn contDiff_fst
#align cont_diff_on_fst contDiffOn_fst
theorem ContDiffOn.fst {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (f x).1) s :=
contDiff_fst.comp_contDiffOn hf
#align cont_diff_on.fst ContDiffOn.fst
/-- The first projection at a point in a product is `C^∞`. -/
theorem contDiffAt_fst {p : E × F} : ContDiffAt 𝕜 n (Prod.fst : E × F → E) p :=
contDiff_fst.contDiffAt
#align cont_diff_at_fst contDiffAt_fst
/-- Postcomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/
theorem ContDiffAt.fst {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (f x).1) x :=
contDiffAt_fst.comp x hf
#align cont_diff_at.fst ContDiffAt.fst
/-- Precomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/
theorem ContDiffAt.fst' {f : E → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x : E × F => f x.1) (x, y) :=
ContDiffAt.comp (x, y) hf contDiffAt_fst
#align cont_diff_at.fst' ContDiffAt.fst'
/-- Precomposing `f` with `Prod.fst` is `C^n` at `x : E × F` -/
theorem ContDiffAt.fst'' {f : E → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.1) :
ContDiffAt 𝕜 n (fun x : E × F => f x.1) x :=
hf.comp x contDiffAt_fst
#align cont_diff_at.fst'' ContDiffAt.fst''
/-- The first projection within a domain at a point in a product is `C^∞`. -/
theorem contDiffWithinAt_fst {s : Set (E × F)} {p : E × F} :
ContDiffWithinAt 𝕜 n (Prod.fst : E × F → E) s p :=
contDiff_fst.contDiffWithinAt
#align cont_diff_within_at_fst contDiffWithinAt_fst
/-- The second projection in a product is `C^∞`. -/
theorem contDiff_snd : ContDiff 𝕜 n (Prod.snd : E × F → F) :=
IsBoundedLinearMap.contDiff IsBoundedLinearMap.snd
#align cont_diff_snd contDiff_snd
/-- Postcomposing `f` with `Prod.snd` is `C^n` -/
theorem ContDiff.snd {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).2 :=
contDiff_snd.comp hf
#align cont_diff.snd ContDiff.snd
/-- Precomposing `f` with `Prod.snd` is `C^n` -/
theorem ContDiff.snd' {f : F → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.2 :=
hf.comp contDiff_snd
#align cont_diff.snd' ContDiff.snd'
/-- The second projection on a domain in a product is `C^∞`. -/
theorem contDiffOn_snd {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.snd : E × F → F) s :=
ContDiff.contDiffOn contDiff_snd
#align cont_diff_on_snd contDiffOn_snd
theorem ContDiffOn.snd {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (f x).2) s :=
contDiff_snd.comp_contDiffOn hf
#align cont_diff_on.snd ContDiffOn.snd
/-- The second projection at a point in a product is `C^∞`. -/
theorem contDiffAt_snd {p : E × F} : ContDiffAt 𝕜 n (Prod.snd : E × F → F) p :=
contDiff_snd.contDiffAt
#align cont_diff_at_snd contDiffAt_snd
/-- Postcomposing `f` with `Prod.snd` is `C^n` at `x` -/
theorem ContDiffAt.snd {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (f x).2) x :=
contDiffAt_snd.comp x hf
#align cont_diff_at.snd ContDiffAt.snd
/-- Precomposing `f` with `Prod.snd` is `C^n` at `(x, y)` -/
theorem ContDiffAt.snd' {f : F → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f y) :
ContDiffAt 𝕜 n (fun x : E × F => f x.2) (x, y) :=
ContDiffAt.comp (x, y) hf contDiffAt_snd
#align cont_diff_at.snd' ContDiffAt.snd'
/-- Precomposing `f` with `Prod.snd` is `C^n` at `x : E × F` -/
theorem ContDiffAt.snd'' {f : F → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.2) :
ContDiffAt 𝕜 n (fun x : E × F => f x.2) x :=
hf.comp x contDiffAt_snd
#align cont_diff_at.snd'' ContDiffAt.snd''
/-- The second projection within a domain at a point in a product is `C^∞`. -/
theorem contDiffWithinAt_snd {s : Set (E × F)} {p : E × F} :
ContDiffWithinAt 𝕜 n (Prod.snd : E × F → F) s p :=
contDiff_snd.contDiffWithinAt
#align cont_diff_within_at_snd contDiffWithinAt_snd
section NAry
variable {E₁ E₂ E₃ E₄ : Type*}
variable [NormedAddCommGroup E₁] [NormedAddCommGroup E₂] [NormedAddCommGroup E₃]
[NormedAddCommGroup E₄] [NormedSpace 𝕜 E₁] [NormedSpace 𝕜 E₂] [NormedSpace 𝕜 E₃]
[NormedSpace 𝕜 E₄]
theorem ContDiff.comp₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} (hg : ContDiff 𝕜 n g)
(hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) : ContDiff 𝕜 n fun x => g (f₁ x, f₂ x) :=
hg.comp <| hf₁.prod hf₂
#align cont_diff.comp₂ ContDiff.comp₂
theorem ContDiff.comp₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) (hf₃ : ContDiff 𝕜 n f₃) :
ContDiff 𝕜 n fun x => g (f₁ x, f₂ x, f₃ x) :=
hg.comp₂ hf₁ <| hf₂.prod hf₃
#align cont_diff.comp₃ ContDiff.comp₃
theorem ContDiff.comp_contDiff_on₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {s : Set F}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s) :
ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x)) s :=
hg.comp_contDiffOn <| hf₁.prod hf₂
#align cont_diff.comp_cont_diff_on₂ ContDiff.comp_contDiff_on₂
theorem ContDiff.comp_contDiff_on₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃}
{s : Set F} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s)
(hf₃ : ContDiffOn 𝕜 n f₃ s) : ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x, f₃ x)) s :=
hg.comp_contDiff_on₂ hf₁ <| hf₂.prod hf₃
#align cont_diff.comp_cont_diff_on₃ ContDiff.comp_contDiff_on₃
end NAry
section SpecificBilinearMaps
theorem ContDiff.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} (hg : ContDiff 𝕜 n g)
(hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (g x).comp (f x) :=
isBoundedBilinearMap_comp.contDiff.comp₂ hg hf
#align cont_diff.clm_comp ContDiff.clm_comp
theorem ContDiffOn.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {s : Set X}
(hg : ContDiffOn 𝕜 n g s) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (g x).comp (f x)) s :=
isBoundedBilinearMap_comp.contDiff.comp_contDiff_on₂ hg hf
#align cont_diff_on.clm_comp ContDiffOn.clm_comp
theorem ContDiff.clm_apply {f : E → F →L[𝕜] G} {g : E → F} {n : ℕ∞} (hf : ContDiff 𝕜 n f)
(hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x) (g x) :=
isBoundedBilinearMap_apply.contDiff.comp₂ hf hg
#align cont_diff.clm_apply ContDiff.clm_apply
theorem ContDiffOn.clm_apply {f : E → F →L[𝕜] G} {g : E → F} {n : ℕ∞} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => (f x) (g x)) s :=
isBoundedBilinearMap_apply.contDiff.comp_contDiff_on₂ hf hg
#align cont_diff_on.clm_apply ContDiffOn.clm_apply
-- Porting note: In Lean 3 we had to give implicit arguments in proofs like the following,
-- to speed up elaboration. In Lean 4 this isn't necessary anymore.
theorem ContDiff.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} {n : ℕ∞} (hf : ContDiff 𝕜 n f)
(hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x).smulRight (g x) :=
isBoundedBilinearMap_smulRight.contDiff.comp₂ hf hg
#align cont_diff.smul_right ContDiff.smulRight
end SpecificBilinearMaps
section ClmApplyConst
/-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDerivWithin`. -/
theorem iteratedFDerivWithin_clm_apply_const_apply
{s : Set E} (hs : UniqueDiffOn 𝕜 s) {n : ℕ∞} {c : E → F →L[𝕜] G} (hc : ContDiffOn 𝕜 n c s)
{i : ℕ} (hi : i ≤ n) {x : E} (hx : x ∈ s) {u : F} {m : Fin i → E} :
(iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s x) m = (iteratedFDerivWithin 𝕜 i c s x) m u := by
induction i generalizing x with
| zero => simp
| succ i ih =>
replace hi : i < n := lt_of_lt_of_le (by norm_cast; simp) hi
have h_deriv_apply : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s) s :=
(hc.clm_apply contDiffOn_const).differentiableOn_iteratedFDerivWithin hi hs
have h_deriv : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i c s) s :=
hc.differentiableOn_iteratedFDerivWithin hi hs
simp only [iteratedFDerivWithin_succ_apply_left]
rw [← fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv_apply x hx)]
rw [fderivWithin_congr' (fun x hx ↦ ih hi.le hx) hx]
rw [fderivWithin_clm_apply (hs x hx) (h_deriv.continuousMultilinear_apply_const _ x hx)
(differentiableWithinAt_const u)]
rw [fderivWithin_const_apply _ (hs x hx)]
simp only [ContinuousLinearMap.flip_apply, ContinuousLinearMap.comp_zero, zero_add]
rw [fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv x hx)]
/-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDeriv`. -/
theorem iteratedFDeriv_clm_apply_const_apply
{n : ℕ∞} {c : E → F →L[𝕜] G} (hc : ContDiff 𝕜 n c)
{i : ℕ} (hi : i ≤ n) {x : E} {u : F} {m : Fin i → E} :
(iteratedFDeriv 𝕜 i (fun y ↦ (c y) u) x) m = (iteratedFDeriv 𝕜 i c x) m u := by
simp only [← iteratedFDerivWithin_univ]
exact iteratedFDerivWithin_clm_apply_const_apply uniqueDiffOn_univ hc.contDiffOn hi (mem_univ _)
end ClmApplyConst
/-- The natural equivalence `(E × F) × G ≃ E × (F × G)` is smooth.
Warning: if you think you need this lemma, it is likely that you can simplify your proof by
reformulating the lemma that you're applying next using the tips in
Note [continuity lemma statement]
-/
theorem contDiff_prodAssoc : ContDiff 𝕜 ⊤ <| Equiv.prodAssoc E F G :=
(LinearIsometryEquiv.prodAssoc 𝕜 E F G).contDiff
#align cont_diff_prod_assoc contDiff_prodAssoc
/-- The natural equivalence `E × (F × G) ≃ (E × F) × G` is smooth.
Warning: see remarks attached to `contDiff_prodAssoc`
-/
theorem contDiff_prodAssoc_symm : ContDiff 𝕜 ⊤ <| (Equiv.prodAssoc E F G).symm :=
(LinearIsometryEquiv.prodAssoc 𝕜 E F G).symm.contDiff
#align cont_diff_prod_assoc_symm contDiff_prodAssoc_symm
/-! ### Bundled derivatives are smooth -/
/-- One direction of `contDiffWithinAt_succ_iff_hasFDerivWithinAt`, but where all derivatives
taken within the same set. Version for partial derivatives / functions with parameters. `f x` is a
`C^n+1` family of functions and `g x` is a `C^n` family of points, then the derivative of `f x` at
`g x` depends in a `C^n` way on `x`. We give a general version of this fact relative to sets which
may not have unique derivatives, in the following form. If `f : E × F → G` is `C^n+1` at
`(x₀, g(x₀))` in `(s ∪ {x₀}) × t ⊆ E × F` and `g : E → F` is `C^n` at `x₀` within some set `s ⊆ E`,
then there is a function `f' : E → F →L[𝕜] G` that is `C^n` at `x₀` within `s` such that for all `x`
sufficiently close to `x₀` within `s ∪ {x₀}` the function `y ↦ f x y` has derivative `f' x` at `g x`
within `t ⊆ F`. For convenience, we return an explicit set of `x`'s where this holds that is a
subset of `s ∪ {x₀}`. We need one additional condition, namely that `t` is a neighborhood of
`g(x₀)` within `g '' s`. -/
theorem ContDiffWithinAt.hasFDerivWithinAt_nhds {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ}
{x₀ : E} (hf : ContDiffWithinAt 𝕜 (n + 1) (uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 n g s x₀) (hgt : t ∈ 𝓝[g '' s] g x₀) :
∃ v ∈ 𝓝[insert x₀ s] x₀, v ⊆ insert x₀ s ∧ ∃ f' : E → F →L[𝕜] G,
(∀ x ∈ v, HasFDerivWithinAt (f x) (f' x) t (g x)) ∧
ContDiffWithinAt 𝕜 n (fun x => f' x) s x₀ := by
have hst : insert x₀ s ×ˢ t ∈ 𝓝[(fun x => (x, g x)) '' s] (x₀, g x₀) := by
refine nhdsWithin_mono _ ?_ (nhdsWithin_prod self_mem_nhdsWithin hgt)
simp_rw [image_subset_iff, mk_preimage_prod, preimage_id', subset_inter_iff, subset_insert,
true_and_iff, subset_preimage_image]
obtain ⟨v, hv, hvs, f', hvf', hf'⟩ := contDiffWithinAt_succ_iff_hasFDerivWithinAt'.mp hf
refine
⟨(fun z => (z, g z)) ⁻¹' v ∩ insert x₀ s, ?_, inter_subset_right, fun z =>
(f' (z, g z)).comp (ContinuousLinearMap.inr 𝕜 E F), ?_, ?_⟩
· refine inter_mem ?_ self_mem_nhdsWithin
have := mem_of_mem_nhdsWithin (mem_insert _ _) hv
refine mem_nhdsWithin_insert.mpr ⟨this, ?_⟩
refine (continuousWithinAt_id.prod hg.continuousWithinAt).preimage_mem_nhdsWithin' ?_
rw [← nhdsWithin_le_iff] at hst hv ⊢
exact (hst.trans <| nhdsWithin_mono _ <| subset_insert _ _).trans hv
· intro z hz
have := hvf' (z, g z) hz.1
refine this.comp _ (hasFDerivAt_prod_mk_right _ _).hasFDerivWithinAt ?_
exact mapsTo'.mpr (image_prod_mk_subset_prod_right hz.2)
· exact (hf'.continuousLinearMap_comp <| (ContinuousLinearMap.compL 𝕜 F (E × F) G).flip
(ContinuousLinearMap.inr 𝕜 E F)).comp_of_mem x₀ (contDiffWithinAt_id.prod hg) hst
#align cont_diff_within_at.has_fderiv_within_at_nhds ContDiffWithinAt.hasFDerivWithinAt_nhds
/-- The most general lemma stating that `x ↦ fderivWithin 𝕜 (f x) t (g x)` is `C^n`
at a point within a set.
To show that `x ↦ D_yf(x,y)g(x)` (taken within `t`) is `C^m` at `x₀` within `s`, we require that
* `f` is `C^n` at `(x₀, g(x₀))` within `(s ∪ {x₀}) × t` for `n ≥ m+1`.
* `g` is `C^m` at `x₀` within `s`;
* Derivatives are unique at `g(x)` within `t` for `x` sufficiently close to `x₀` within `s ∪ {x₀}`;
* `t` is a neighborhood of `g(x₀)` within `g '' s`; -/
theorem ContDiffWithinAt.fderivWithin'' {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀)
(ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n)
(hgt : t ∈ 𝓝[g '' s] g x₀) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
have : ∀ k : ℕ, (k : ℕ∞) ≤ m →
ContDiffWithinAt 𝕜 k (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := fun k hkm ↦ by
obtain ⟨v, hv, -, f', hvf', hf'⟩ :=
(hf.of_le <| (add_le_add_right hkm 1).trans hmn).hasFDerivWithinAt_nhds (hg.of_le hkm) hgt
refine hf'.congr_of_eventuallyEq_insert ?_
filter_upwards [hv, ht]
exact fun y hy h2y => (hvf' y hy).fderivWithin h2y
induction' m with m
· obtain rfl := eq_top_iff.mpr hmn
rw [contDiffWithinAt_top]
exact fun m => this m le_top
exact this _ le_rfl
#align cont_diff_within_at.fderiv_within'' ContDiffWithinAt.fderivWithin''
/-- A special case of `ContDiffWithinAt.fderivWithin''` where we require that `s ⊆ g⁻¹(t)`. -/
theorem ContDiffWithinAt.fderivWithin' {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀)
(ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n)
(hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ :=
hf.fderivWithin'' hg ht hmn <| mem_of_superset self_mem_nhdsWithin <| image_subset_iff.mpr hst
#align cont_diff_within_at.fderiv_within' ContDiffWithinAt.fderivWithin'
/-- A special case of `ContDiffWithinAt.fderivWithin'` where we require that `x₀ ∈ s` and there
are unique derivatives everywhere within `t`. -/
protected theorem ContDiffWithinAt.fderivWithin {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : UniqueDiffOn 𝕜 t) (hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s)
(hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
rw [← insert_eq_self.mpr hx₀] at hf
refine hf.fderivWithin' hg ?_ hmn hst
rw [insert_eq_self.mpr hx₀]
exact eventually_of_mem self_mem_nhdsWithin fun x hx => ht _ (hst hx)
#align cont_diff_within_at.fderiv_within ContDiffWithinAt.fderivWithin
/-- `x ↦ fderivWithin 𝕜 (f x) t (g x) (k x)` is smooth at a point within a set. -/
theorem ContDiffWithinAt.fderivWithin_apply {f : E → F → G} {g k : E → F} {t : Set F} {n : ℕ∞}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀) (hk : ContDiffWithinAt 𝕜 m k s x₀) (ht : UniqueDiffOn 𝕜 t)
(hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s) (hst : s ⊆ g ⁻¹' t) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x) (k x)) s x₀ :=
(contDiff_fst.clm_apply contDiff_snd).contDiffAt.comp_contDiffWithinAt x₀
((hf.fderivWithin hg ht hmn hx₀ hst).prod hk)
#align cont_diff_within_at.fderiv_within_apply ContDiffWithinAt.fderivWithin_apply
/-- `fderivWithin 𝕜 f s` is smooth at `x₀` within `s`. -/
theorem ContDiffWithinAt.fderivWithin_right (hf : ContDiffWithinAt 𝕜 n f s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : (m + 1 : ℕ∞) ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (fderivWithin 𝕜 f s) s x₀ :=
ContDiffWithinAt.fderivWithin
(ContDiffWithinAt.comp (x₀, x₀) hf contDiffWithinAt_snd <| prod_subset_preimage_snd s s)
contDiffWithinAt_id hs hmn hx₀s (by rw [preimage_id'])
#align cont_diff_within_at.fderiv_within_right ContDiffWithinAt.fderivWithin_right
-- TODO: can we make a version of `ContDiffWithinAt.fderivWithin` for iterated derivatives?
theorem ContDiffWithinAt.iteratedFderivWithin_right {i : ℕ} (hf : ContDiffWithinAt 𝕜 n f s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : (m + i : ℕ∞) ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (iteratedFDerivWithin 𝕜 i f s) s x₀ := by
induction' i with i hi generalizing m
· rw [ENat.coe_zero, add_zero] at hmn
exact (hf.of_le hmn).continuousLinearMap_comp
((continuousMultilinearCurryFin0 𝕜 E F).symm : _ →L[𝕜] E [×0]→L[𝕜] F)
· rw [Nat.cast_succ, add_comm _ 1, ← add_assoc] at hmn
exact ((hi hmn).fderivWithin_right hs le_rfl hx₀s).continuousLinearMap_comp
(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (i+1) ↦ E) F : _ →L[𝕜] E [×(i+1)]→L[𝕜] F)
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth at `x₀`. -/
protected theorem ContDiffAt.fderiv {f : E → F → G} {g : E → F} {n : ℕ∞}
(hf : ContDiffAt 𝕜 n (Function.uncurry f) (x₀, g x₀)) (hg : ContDiffAt 𝕜 m g x₀)
(hmn : m + 1 ≤ n) : ContDiffAt 𝕜 m (fun x => fderiv 𝕜 (f x) (g x)) x₀ := by
simp_rw [← fderivWithin_univ]
refine (ContDiffWithinAt.fderivWithin hf.contDiffWithinAt hg.contDiffWithinAt uniqueDiffOn_univ
hmn (mem_univ x₀) ?_).contDiffAt univ_mem
rw [preimage_univ]
#align cont_diff_at.fderiv ContDiffAt.fderiv
/-- `fderiv 𝕜 f` is smooth at `x₀`. -/
theorem ContDiffAt.fderiv_right (hf : ContDiffAt 𝕜 n f x₀) (hmn : (m + 1 : ℕ∞) ≤ n) :
ContDiffAt 𝕜 m (fderiv 𝕜 f) x₀ :=
ContDiffAt.fderiv (ContDiffAt.comp (x₀, x₀) hf contDiffAt_snd) contDiffAt_id hmn
#align cont_diff_at.fderiv_right ContDiffAt.fderiv_right
theorem ContDiffAt.iteratedFDeriv_right {i : ℕ} (hf : ContDiffAt 𝕜 n f x₀)
(hmn : (m + i : ℕ∞) ≤ n) : ContDiffAt 𝕜 m (iteratedFDeriv 𝕜 i f) x₀ := by
rw [← iteratedFDerivWithin_univ, ← contDiffWithinAt_univ] at *
exact hf.iteratedFderivWithin_right uniqueDiffOn_univ hmn trivial
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth. -/
protected theorem ContDiff.fderiv {f : E → F → G} {g : E → F} {n m : ℕ∞}
(hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hnm : n + 1 ≤ m) :
ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) :=
contDiff_iff_contDiffAt.mpr fun _ => hf.contDiffAt.fderiv hg.contDiffAt hnm
#align cont_diff.fderiv ContDiff.fderiv
/-- `fderiv 𝕜 f` is smooth. -/
theorem ContDiff.fderiv_right (hf : ContDiff 𝕜 n f) (hmn : (m + 1 : ℕ∞) ≤ n) :
ContDiff 𝕜 m (fderiv 𝕜 f) :=
contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.fderiv_right hmn
#align cont_diff.fderiv_right ContDiff.fderiv_right
theorem ContDiff.iteratedFDeriv_right {i : ℕ} (hf : ContDiff 𝕜 n f)
(hmn : (m + i : ℕ∞) ≤ n) : ContDiff 𝕜 m (iteratedFDeriv 𝕜 i f) :=
contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.iteratedFDeriv_right hmn
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is continuous. -/
theorem Continuous.fderiv {f : E → F → G} {g : E → F} {n : ℕ∞}
(hf : ContDiff 𝕜 n <| Function.uncurry f) (hg : Continuous g) (hn : 1 ≤ n) :
Continuous fun x => fderiv 𝕜 (f x) (g x) :=
(hf.fderiv (contDiff_zero.mpr hg) hn).continuous
#align continuous.fderiv Continuous.fderiv
/-- `x ↦ fderiv 𝕜 (f x) (g x) (k x)` is smooth. -/
theorem ContDiff.fderiv_apply {f : E → F → G} {g k : E → F} {n m : ℕ∞}
(hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hk : ContDiff 𝕜 n k)
(hnm : n + 1 ≤ m) : ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) (k x) :=
(hf.fderiv hg hnm).clm_apply hk
#align cont_diff.fderiv_apply ContDiff.fderiv_apply
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
theorem contDiffOn_fderivWithin_apply {m n : ℕ∞} {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E →L[𝕜] F) p.2) (s ×ˢ univ) :=
((hf.fderivWithin hs hmn).comp contDiffOn_fst (prod_subset_preimage_fst _ _)).clm_apply
contDiffOn_snd
#align cont_diff_on_fderiv_within_apply contDiffOn_fderivWithin_apply
/-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is
continuous. -/
theorem ContDiffOn.continuousOn_fderivWithin_apply (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hn : 1 ≤ n) :
ContinuousOn (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E → F) p.2) (s ×ˢ univ) :=
(contDiffOn_fderivWithin_apply hf hs <| by rwa [zero_add]).continuousOn
#align cont_diff_on.continuous_on_fderiv_within_apply ContDiffOn.continuousOn_fderivWithin_apply
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
theorem ContDiff.contDiff_fderiv_apply {f : E → F} (hf : ContDiff 𝕜 n f) (hmn : m + 1 ≤ n) :
ContDiff 𝕜 m fun p : E × E => (fderiv 𝕜 f p.1 : E →L[𝕜] F) p.2 := by
rw [← contDiffOn_univ] at hf ⊢
rw [← fderivWithin_univ, ← univ_prod_univ]
exact contDiffOn_fderivWithin_apply hf uniqueDiffOn_univ hmn
#align cont_diff.cont_diff_fderiv_apply ContDiff.contDiff_fderiv_apply
/-!
### Smoothness of functions `f : E → Π i, F' i`
-/
section Pi
variable {ι ι' : Type*} [Fintype ι] [Fintype ι'] {F' : ι → Type*} [∀ i, NormedAddCommGroup (F' i)]
[∀ i, NormedSpace 𝕜 (F' i)] {φ : ∀ i, E → F' i} {p' : ∀ i, E → FormalMultilinearSeries 𝕜 E (F' i)}
{Φ : E → ∀ i, F' i} {P' : E → FormalMultilinearSeries 𝕜 E (∀ i, F' i)}
theorem hasFTaylorSeriesUpToOn_pi :
HasFTaylorSeriesUpToOn n (fun x i => φ i x)
(fun x m => ContinuousMultilinearMap.pi fun i => p' i x m) s ↔
∀ i, HasFTaylorSeriesUpToOn n (φ i) (p' i) s := by
set pr := @ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _
letI : ∀ (m : ℕ) (i : ι), NormedSpace 𝕜 (E[×m]→L[𝕜] F' i) := fun m i => inferInstance
set L : ∀ m : ℕ, (∀ i, E[×m]→L[𝕜] F' i) ≃ₗᵢ[𝕜] E[×m]→L[𝕜] ∀ i, F' i := fun m =>
ContinuousMultilinearMap.piₗᵢ _ _
refine ⟨fun h i => ?_, fun h => ⟨fun x hx => ?_, ?_, ?_⟩⟩
· convert h.continuousLinearMap_comp (pr i)
· ext1 i
exact (h i).zero_eq x hx
· intro m hm x hx
have := hasFDerivWithinAt_pi.2 fun i => (h i).fderivWithin m hm x hx
convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x this
· intro m hm
have := continuousOn_pi.2 fun i => (h i).cont m hm
convert (L m).continuous.comp_continuousOn this
#align has_ftaylor_series_up_to_on_pi hasFTaylorSeriesUpToOn_pi
@[simp]
theorem hasFTaylorSeriesUpToOn_pi' :
HasFTaylorSeriesUpToOn n Φ P' s ↔
∀ i, HasFTaylorSeriesUpToOn n (fun x => Φ x i)
(fun x m => (@ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _ i).compContinuousMultilinearMap
(P' x m)) s := by
convert hasFTaylorSeriesUpToOn_pi (𝕜 := 𝕜) (φ := fun i x ↦ Φ x i); ext; rfl
#align has_ftaylor_series_up_to_on_pi' hasFTaylorSeriesUpToOn_pi'
theorem contDiffWithinAt_pi :
ContDiffWithinAt 𝕜 n Φ s x ↔ ∀ i, ContDiffWithinAt 𝕜 n (fun x => Φ x i) s x := by
set pr := @ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _
refine ⟨fun h i => h.continuousLinearMap_comp (pr i), fun h m hm => ?_⟩
choose u hux p hp using fun i => h i m hm
exact ⟨⋂ i, u i, Filter.iInter_mem.2 hux, _,
hasFTaylorSeriesUpToOn_pi.2 fun i => (hp i).mono <| iInter_subset _ _⟩
#align cont_diff_within_at_pi contDiffWithinAt_pi
theorem contDiffOn_pi : ContDiffOn 𝕜 n Φ s ↔ ∀ i, ContDiffOn 𝕜 n (fun x => Φ x i) s :=
⟨fun h _ x hx => contDiffWithinAt_pi.1 (h x hx) _, fun h x hx =>
contDiffWithinAt_pi.2 fun i => h i x hx⟩
#align cont_diff_on_pi contDiffOn_pi
theorem contDiffAt_pi : ContDiffAt 𝕜 n Φ x ↔ ∀ i, ContDiffAt 𝕜 n (fun x => Φ x i) x :=
contDiffWithinAt_pi
#align cont_diff_at_pi contDiffAt_pi
theorem contDiff_pi : ContDiff 𝕜 n Φ ↔ ∀ i, ContDiff 𝕜 n fun x => Φ x i := by
simp only [← contDiffOn_univ, contDiffOn_pi]
#align cont_diff_pi contDiff_pi
theorem contDiff_update [DecidableEq ι] (k : ℕ∞) (x : ∀ i, F' i) (i : ι) :
ContDiff 𝕜 k (update x i) := by
rw [contDiff_pi]
intro j
dsimp [Function.update]
split_ifs with h
· subst h
exact contDiff_id
· exact contDiff_const
variable (F') in
theorem contDiff_single [DecidableEq ι] (k : ℕ∞) (i : ι) :
ContDiff 𝕜 k (Pi.single i : F' i → ∀ i, F' i) :=
contDiff_update k 0 i
variable (𝕜 E)
theorem contDiff_apply (i : ι) : ContDiff 𝕜 n fun f : ι → E => f i :=
contDiff_pi.mp contDiff_id i
#align cont_diff_apply contDiff_apply
theorem contDiff_apply_apply (i : ι) (j : ι') : ContDiff 𝕜 n fun f : ι → ι' → E => f i j :=
contDiff_pi.mp (contDiff_apply 𝕜 (ι' → E) i) j
#align cont_diff_apply_apply contDiff_apply_apply
end Pi
/-! ### Sum of two functions -/
section Add
theorem HasFTaylorSeriesUpToOn.add {q g} (hf : HasFTaylorSeriesUpToOn n f p s)
(hg : HasFTaylorSeriesUpToOn n g q s) : HasFTaylorSeriesUpToOn n (f + g) (p + q) s := by
convert HasFTaylorSeriesUpToOn.continuousLinearMap_comp
(ContinuousLinearMap.fst 𝕜 F F + .snd 𝕜 F F) (hf.prod hg)
-- The sum is smooth.
theorem contDiff_add : ContDiff 𝕜 n fun p : F × F => p.1 + p.2 :=
(IsBoundedLinearMap.fst.add IsBoundedLinearMap.snd).contDiff
#align cont_diff_add contDiff_add
/-- The sum of two `C^n` functions within a set at a point is `C^n` within this set
at this point. -/
theorem ContDiffWithinAt.add {s : Set E} {f g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x)
(hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x + g x) s x :=
contDiff_add.contDiffWithinAt.comp x (hf.prod hg) subset_preimage_univ
#align cont_diff_within_at.add ContDiffWithinAt.add
/-- The sum of two `C^n` functions at a point is `C^n` at this point. -/
theorem ContDiffAt.add {f g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) :
ContDiffAt 𝕜 n (fun x => f x + g x) x := by
rw [← contDiffWithinAt_univ] at *; exact hf.add hg
#align cont_diff_at.add ContDiffAt.add
/-- The sum of two `C^n`functions is `C^n`. -/
theorem ContDiff.add {f g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n fun x => f x + g x :=
contDiff_add.comp (hf.prod hg)
#align cont_diff.add ContDiff.add
/-- The sum of two `C^n` functions on a domain is `C^n`. -/
theorem ContDiffOn.add {s : Set E} {f g : E → F} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x + g x) s := fun x hx =>
(hf x hx).add (hg x hx)
#align cont_diff_on.add ContDiffOn.add
variable {i : ℕ}
/-- The iterated derivative of the sum of two functions is the sum of the iterated derivatives.
See also `iteratedFDerivWithin_add_apply'`, which uses the spelling `(fun x ↦ f x + g x)`
instead of `f + g`. -/
theorem iteratedFDerivWithin_add_apply {f g : E → F} (hf : ContDiffOn 𝕜 i f s)
(hg : ContDiffOn 𝕜 i g s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 i (f + g) s x =
iteratedFDerivWithin 𝕜 i f s x + iteratedFDerivWithin 𝕜 i g s x :=
Eq.symm <| ((hf.ftaylorSeriesWithin hu).add
(hg.ftaylorSeriesWithin hu)).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hu hx
#align iterated_fderiv_within_add_apply iteratedFDerivWithin_add_apply
/-- The iterated derivative of the sum of two functions is the sum of the iterated derivatives.
This is the same as `iteratedFDerivWithin_add_apply`, but using the spelling `(fun x ↦ f x + g x)`
instead of `f + g`, which can be handy for some rewrites.
TODO: use one form consistently. -/
theorem iteratedFDerivWithin_add_apply' {f g : E → F} (hf : ContDiffOn 𝕜 i f s)
(hg : ContDiffOn 𝕜 i g s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 i (fun x => f x + g x) s x =
iteratedFDerivWithin 𝕜 i f s x + iteratedFDerivWithin 𝕜 i g s x :=
iteratedFDerivWithin_add_apply hf hg hu hx
#align iterated_fderiv_within_add_apply' iteratedFDerivWithin_add_apply'
theorem iteratedFDeriv_add_apply {i : ℕ} {f g : E → F} (hf : ContDiff 𝕜 i f) (hg : ContDiff 𝕜 i g) :
iteratedFDeriv 𝕜 i (f + g) x = iteratedFDeriv 𝕜 i f x + iteratedFDeriv 𝕜 i g x := by
simp_rw [← contDiffOn_univ, ← iteratedFDerivWithin_univ] at hf hg ⊢
exact iteratedFDerivWithin_add_apply hf hg uniqueDiffOn_univ (Set.mem_univ _)
#align iterated_fderiv_add_apply iteratedFDeriv_add_apply
theorem iteratedFDeriv_add_apply' {i : ℕ} {f g : E → F} (hf : ContDiff 𝕜 i f)
(hg : ContDiff 𝕜 i g) :
iteratedFDeriv 𝕜 i (fun x => f x + g x) x = iteratedFDeriv 𝕜 i f x + iteratedFDeriv 𝕜 i g x :=
iteratedFDeriv_add_apply hf hg
#align iterated_fderiv_add_apply' iteratedFDeriv_add_apply'
end Add
/-! ### Negative -/
section Neg
-- The negative is smooth.
theorem contDiff_neg : ContDiff 𝕜 n fun p : F => -p :=
IsBoundedLinearMap.id.neg.contDiff
#align cont_diff_neg contDiff_neg
/-- The negative of a `C^n` function within a domain at a point is `C^n` within this domain at
this point. -/
theorem ContDiffWithinAt.neg {s : Set E} {f : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n (fun x => -f x) s x :=
contDiff_neg.contDiffWithinAt.comp x hf subset_preimage_univ
#align cont_diff_within_at.neg ContDiffWithinAt.neg
/-- The negative of a `C^n` function at a point is `C^n` at this point. -/
theorem ContDiffAt.neg {f : E → F} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => -f x) x := by rw [← contDiffWithinAt_univ] at *; exact hf.neg
#align cont_diff_at.neg ContDiffAt.neg
/-- The negative of a `C^n`function is `C^n`. -/
theorem ContDiff.neg {f : E → F} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => -f x :=
contDiff_neg.comp hf
#align cont_diff.neg ContDiff.neg
/-- The negative of a `C^n` function on a domain is `C^n`. -/
theorem ContDiffOn.neg {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => -f x) s := fun x hx => (hf x hx).neg
#align cont_diff_on.neg ContDiffOn.neg
variable {i : ℕ}
-- Porting note (#11215): TODO: define `Neg` instance on `ContinuousLinearEquiv`,
-- prove it from `ContinuousLinearEquiv.iteratedFDerivWithin_comp_left`
theorem iteratedFDerivWithin_neg_apply {f : E → F} (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 i (-f) s x = -iteratedFDerivWithin 𝕜 i f s x := by
induction' i with i hi generalizing x
· ext; simp
· ext h
calc
iteratedFDerivWithin 𝕜 (i + 1) (-f) s x h =
fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (-f) s) s x (h 0) (Fin.tail h) :=
rfl
_ = fderivWithin 𝕜 (-iteratedFDerivWithin 𝕜 i f s) s x (h 0) (Fin.tail h) := by
rw [fderivWithin_congr' (@hi) hx]; rfl
_ = -(fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i f s) s) x (h 0) (Fin.tail h) := by
rw [Pi.neg_def, fderivWithin_neg (hu x hx)]; rfl
_ = -(iteratedFDerivWithin 𝕜 (i + 1) f s) x h := rfl
#align iterated_fderiv_within_neg_apply iteratedFDerivWithin_neg_apply
theorem iteratedFDeriv_neg_apply {i : ℕ} {f : E → F} :
iteratedFDeriv 𝕜 i (-f) x = -iteratedFDeriv 𝕜 i f x := by
simp_rw [← iteratedFDerivWithin_univ]
exact iteratedFDerivWithin_neg_apply uniqueDiffOn_univ (Set.mem_univ _)
#align iterated_fderiv_neg_apply iteratedFDeriv_neg_apply
end Neg
/-! ### Subtraction -/
/-- The difference of two `C^n` functions within a set at a point is `C^n` within this set
at this point. -/
theorem ContDiffWithinAt.sub {s : Set E} {f g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x)
(hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x - g x) s x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
#align cont_diff_within_at.sub ContDiffWithinAt.sub
/-- The difference of two `C^n` functions at a point is `C^n` at this point. -/
theorem ContDiffAt.sub {f g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) :
ContDiffAt 𝕜 n (fun x => f x - g x) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg
#align cont_diff_at.sub ContDiffAt.sub
/-- The difference of two `C^n` functions on a domain is `C^n`. -/
theorem ContDiffOn.sub {s : Set E} {f g : E → F} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x - g x) s := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
#align cont_diff_on.sub ContDiffOn.sub
/-- The difference of two `C^n` functions is `C^n`. -/
theorem ContDiff.sub {f g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n fun x => f x - g x := by simpa only [sub_eq_add_neg] using hf.add hg.neg
#align cont_diff.sub ContDiff.sub
/-! ### Sum of finitely many functions -/
theorem ContDiffWithinAt.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {t : Set E} {x : E}
(h : ∀ i ∈ s, ContDiffWithinAt 𝕜 n (fun x => f i x) t x) :
ContDiffWithinAt 𝕜 n (fun x => ∑ i ∈ s, f i x) t x := by
classical
induction' s using Finset.induction_on with i s is IH
· simp [contDiffWithinAt_const]
· simp only [is, Finset.sum_insert, not_false_iff]
exact (h _ (Finset.mem_insert_self i s)).add
(IH fun j hj => h _ (Finset.mem_insert_of_mem hj))
#align cont_diff_within_at.sum ContDiffWithinAt.sum
theorem ContDiffAt.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {x : E}
(h : ∀ i ∈ s, ContDiffAt 𝕜 n (fun x => f i x) x) :
ContDiffAt 𝕜 n (fun x => ∑ i ∈ s, f i x) x := by
rw [← contDiffWithinAt_univ] at *; exact ContDiffWithinAt.sum h
#align cont_diff_at.sum ContDiffAt.sum
theorem ContDiffOn.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {t : Set E}
(h : ∀ i ∈ s, ContDiffOn 𝕜 n (fun x => f i x) t) :
ContDiffOn 𝕜 n (fun x => ∑ i ∈ s, f i x) t := fun x hx =>
ContDiffWithinAt.sum fun i hi => h i hi x hx
#align cont_diff_on.sum ContDiffOn.sum
theorem ContDiff.sum {ι : Type*} {f : ι → E → F} {s : Finset ι}
(h : ∀ i ∈ s, ContDiff 𝕜 n fun x => f i x) : ContDiff 𝕜 n fun x => ∑ i ∈ s, f i x := by
simp only [← contDiffOn_univ] at *; exact ContDiffOn.sum h
#align cont_diff.sum ContDiff.sum
theorem iteratedFDerivWithin_sum_apply {ι : Type*} {f : ι → E → F} {u : Finset ι} {i : ℕ} {x : E}
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : ∀ j ∈ u, ContDiffOn 𝕜 i (f j) s) :
iteratedFDerivWithin 𝕜 i (∑ j ∈ u, f j ·) s x =
∑ j ∈ u, iteratedFDerivWithin 𝕜 i (f j) s x := by
induction u using Finset.cons_induction with
| empty => ext; simp [hs, hx]
| cons a u ha IH =>
simp only [Finset.mem_cons, forall_eq_or_imp] at h
simp only [Finset.sum_cons]
rw [iteratedFDerivWithin_add_apply' h.1 (ContDiffOn.sum h.2) hs hx, IH h.2]
theorem iteratedFDeriv_sum {ι : Type*} {f : ι → E → F} {u : Finset ι} {i : ℕ}
(h : ∀ j ∈ u, ContDiff 𝕜 i (f j)) :
iteratedFDeriv 𝕜 i (∑ j ∈ u, f j ·) = ∑ j ∈ u, iteratedFDeriv 𝕜 i (f j) :=
funext fun x ↦ by simpa [iteratedFDerivWithin_univ] using
iteratedFDerivWithin_sum_apply uniqueDiffOn_univ (mem_univ x) fun j hj ↦ (h j hj).contDiffOn
/-! ### Product of two functions -/
section MulProd
variable {𝔸 𝔸' ι 𝕜' : Type*} [NormedRing 𝔸] [NormedAlgebra 𝕜 𝔸] [NormedCommRing 𝔸']
[NormedAlgebra 𝕜 𝔸'] [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜']
-- The product is smooth.
theorem contDiff_mul : ContDiff 𝕜 n fun p : 𝔸 × 𝔸 => p.1 * p.2 :=
(ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.contDiff
#align cont_diff_mul contDiff_mul
/-- The product of two `C^n` functions within a set at a point is `C^n` within this set
at this point. -/
theorem ContDiffWithinAt.mul {s : Set E} {f g : E → 𝔸} (hf : ContDiffWithinAt 𝕜 n f s x)
(hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x * g x) s x :=
contDiff_mul.comp_contDiffWithinAt (hf.prod hg)
#align cont_diff_within_at.mul ContDiffWithinAt.mul
/-- The product of two `C^n` functions at a point is `C^n` at this point. -/
nonrec theorem ContDiffAt.mul {f g : E → 𝔸} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) :
ContDiffAt 𝕜 n (fun x => f x * g x) x :=
hf.mul hg
#align cont_diff_at.mul ContDiffAt.mul
/-- The product of two `C^n` functions on a domain is `C^n`. -/
theorem ContDiffOn.mul {f g : E → 𝔸} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) :
ContDiffOn 𝕜 n (fun x => f x * g x) s := fun x hx => (hf x hx).mul (hg x hx)
#align cont_diff_on.mul ContDiffOn.mul
/-- The product of two `C^n`functions is `C^n`. -/
theorem ContDiff.mul {f g : E → 𝔸} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n fun x => f x * g x :=
contDiff_mul.comp (hf.prod hg)
#align cont_diff.mul ContDiff.mul
theorem contDiffWithinAt_prod' {t : Finset ι} {f : ι → E → 𝔸'}
(h : ∀ i ∈ t, ContDiffWithinAt 𝕜 n (f i) s x) : ContDiffWithinAt 𝕜 n (∏ i ∈ t, f i) s x :=
Finset.prod_induction f (fun f => ContDiffWithinAt 𝕜 n f s x) (fun _ _ => ContDiffWithinAt.mul)
(contDiffWithinAt_const (c := 1)) h
#align cont_diff_within_at_prod' contDiffWithinAt_prod'
theorem contDiffWithinAt_prod {t : Finset ι} {f : ι → E → 𝔸'}
(h : ∀ i ∈ t, ContDiffWithinAt 𝕜 n (f i) s x) :
ContDiffWithinAt 𝕜 n (fun y => ∏ i ∈ t, f i y) s x := by
simpa only [← Finset.prod_apply] using contDiffWithinAt_prod' h
#align cont_diff_within_at_prod contDiffWithinAt_prod
theorem contDiffAt_prod' {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffAt 𝕜 n (f i) x) :
ContDiffAt 𝕜 n (∏ i ∈ t, f i) x :=
contDiffWithinAt_prod' h
#align cont_diff_at_prod' contDiffAt_prod'
theorem contDiffAt_prod {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffAt 𝕜 n (f i) x) :
ContDiffAt 𝕜 n (fun y => ∏ i ∈ t, f i y) x :=
contDiffWithinAt_prod h
#align cont_diff_at_prod contDiffAt_prod
theorem contDiffOn_prod' {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffOn 𝕜 n (f i) s) :
ContDiffOn 𝕜 n (∏ i ∈ t, f i) s := fun x hx => contDiffWithinAt_prod' fun i hi => h i hi x hx
#align cont_diff_on_prod' contDiffOn_prod'
theorem contDiffOn_prod {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffOn 𝕜 n (f i) s) :
ContDiffOn 𝕜 n (fun y => ∏ i ∈ t, f i y) s := fun x hx =>
contDiffWithinAt_prod fun i hi => h i hi x hx
#align cont_diff_on_prod contDiffOn_prod
theorem contDiff_prod' {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiff 𝕜 n (f i)) :
ContDiff 𝕜 n (∏ i ∈ t, f i) :=
contDiff_iff_contDiffAt.mpr fun _ => contDiffAt_prod' fun i hi => (h i hi).contDiffAt
#align cont_diff_prod' contDiff_prod'
theorem contDiff_prod {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiff 𝕜 n (f i)) :
ContDiff 𝕜 n fun y => ∏ i ∈ t, f i y :=
contDiff_iff_contDiffAt.mpr fun _ => contDiffAt_prod fun i hi => (h i hi).contDiffAt
#align cont_diff_prod contDiff_prod
theorem ContDiff.pow {f : E → 𝔸} (hf : ContDiff 𝕜 n f) : ∀ m : ℕ, ContDiff 𝕜 n fun x => f x ^ m
| 0 => by simpa using contDiff_const
| m + 1 => by simpa [pow_succ] using (hf.pow m).mul hf
#align cont_diff.pow ContDiff.pow
theorem ContDiffWithinAt.pow {f : E → 𝔸} (hf : ContDiffWithinAt 𝕜 n f s x) (m : ℕ) :
ContDiffWithinAt 𝕜 n (fun y => f y ^ m) s x :=
(contDiff_id.pow m).comp_contDiffWithinAt hf
#align cont_diff_within_at.pow ContDiffWithinAt.pow
nonrec theorem ContDiffAt.pow {f : E → 𝔸} (hf : ContDiffAt 𝕜 n f x) (m : ℕ) :
ContDiffAt 𝕜 n (fun y => f y ^ m) x :=
hf.pow m
#align cont_diff_at.pow ContDiffAt.pow
theorem ContDiffOn.pow {f : E → 𝔸} (hf : ContDiffOn 𝕜 n f s) (m : ℕ) :
ContDiffOn 𝕜 n (fun y => f y ^ m) s := fun y hy => (hf y hy).pow m
#align cont_diff_on.pow ContDiffOn.pow
theorem ContDiffWithinAt.div_const {f : E → 𝕜'} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (c : 𝕜') :
ContDiffWithinAt 𝕜 n (fun x => f x / c) s x := by
simpa only [div_eq_mul_inv] using hf.mul contDiffWithinAt_const
#align cont_diff_within_at.div_const ContDiffWithinAt.div_const
nonrec theorem ContDiffAt.div_const {f : E → 𝕜'} {n} (hf : ContDiffAt 𝕜 n f x) (c : 𝕜') :
ContDiffAt 𝕜 n (fun x => f x / c) x :=
hf.div_const c
#align cont_diff_at.div_const ContDiffAt.div_const
theorem ContDiffOn.div_const {f : E → 𝕜'} {n} (hf : ContDiffOn 𝕜 n f s) (c : 𝕜') :
ContDiffOn 𝕜 n (fun x => f x / c) s := fun x hx => (hf x hx).div_const c
#align cont_diff_on.div_const ContDiffOn.div_const
theorem ContDiff.div_const {f : E → 𝕜'} {n} (hf : ContDiff 𝕜 n f) (c : 𝕜') :
ContDiff 𝕜 n fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul contDiff_const
#align cont_diff.div_const ContDiff.div_const
end MulProd
/-! ### Scalar multiplication -/
section SMul
-- The scalar multiplication is smooth.
theorem contDiff_smul : ContDiff 𝕜 n fun p : 𝕜 × F => p.1 • p.2 :=
isBoundedBilinearMap_smul.contDiff
#align cont_diff_smul contDiff_smul
/-- The scalar multiplication of two `C^n` functions within a set at a point is `C^n` within this
set at this point. -/
theorem ContDiffWithinAt.smul {s : Set E} {f : E → 𝕜} {g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x)
(hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x • g x) s x :=
contDiff_smul.contDiffWithinAt.comp x (hf.prod hg) subset_preimage_univ
#align cont_diff_within_at.smul ContDiffWithinAt.smul
/-- The scalar multiplication of two `C^n` functions at a point is `C^n` at this point. -/
theorem ContDiffAt.smul {f : E → 𝕜} {g : E → F} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x • g x) x := by
rw [← contDiffWithinAt_univ] at *; exact hf.smul hg
#align cont_diff_at.smul ContDiffAt.smul
/-- The scalar multiplication of two `C^n` functions is `C^n`. -/
theorem ContDiff.smul {f : E → 𝕜} {g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n fun x => f x • g x :=
contDiff_smul.comp (hf.prod hg)
#align cont_diff.smul ContDiff.smul
/-- The scalar multiplication of two `C^n` functions on a domain is `C^n`. -/
theorem ContDiffOn.smul {s : Set E} {f : E → 𝕜} {g : E → F} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x • g x) s := fun x hx =>
(hf x hx).smul (hg x hx)
#align cont_diff_on.smul ContDiffOn.smul
end SMul
/-! ### Constant scalar multiplication
Porting note (#11215): TODO: generalize results in this section.
1. It should be possible to assume `[Monoid R] [DistribMulAction R F] [SMulCommClass 𝕜 R F]`.
2. If `c` is a unit (or `R` is a group), then one can drop `ContDiff*` assumptions in some
lemmas.
-/
section ConstSMul
variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F]
variable [ContinuousConstSMul R F]
-- The scalar multiplication with a constant is smooth.
theorem contDiff_const_smul (c : R) : ContDiff 𝕜 n fun p : F => c • p :=
(c • ContinuousLinearMap.id 𝕜 F).contDiff
#align cont_diff_const_smul contDiff_const_smul
/-- The scalar multiplication of a constant and a `C^n` function within a set at a point is `C^n`
within this set at this point. -/
theorem ContDiffWithinAt.const_smul {s : Set E} {f : E → F} {x : E} (c : R)
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (fun y => c • f y) s x :=
(contDiff_const_smul c).contDiffAt.comp_contDiffWithinAt x hf
#align cont_diff_within_at.const_smul ContDiffWithinAt.const_smul
/-- The scalar multiplication of a constant and a `C^n` function at a point is `C^n` at this
point. -/
theorem ContDiffAt.const_smul {f : E → F} {x : E} (c : R) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun y => c • f y) x := by
rw [← contDiffWithinAt_univ] at *; exact hf.const_smul c
#align cont_diff_at.const_smul ContDiffAt.const_smul
/-- The scalar multiplication of a constant and a `C^n` function is `C^n`. -/
theorem ContDiff.const_smul {f : E → F} (c : R) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n fun y => c • f y :=
(contDiff_const_smul c).comp hf
#align cont_diff.const_smul ContDiff.const_smul
/-- The scalar multiplication of a constant and a `C^n` on a domain is `C^n`. -/
theorem ContDiffOn.const_smul {s : Set E} {f : E → F} (c : R) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun y => c • f y) s := fun x hx => (hf x hx).const_smul c
#align cont_diff_on.const_smul ContDiffOn.const_smul
variable {i : ℕ} {a : R}
theorem iteratedFDerivWithin_const_smul_apply (hf : ContDiffOn 𝕜 i f s) (hu : UniqueDiffOn 𝕜 s)
(hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (a • f) s x = a • iteratedFDerivWithin 𝕜 i f s x :=
(a • (1 : F →L[𝕜] F)).iteratedFDerivWithin_comp_left hf hu hx le_rfl
#align iterated_fderiv_within_const_smul_apply iteratedFDerivWithin_const_smul_apply
theorem iteratedFDeriv_const_smul_apply {x : E} (hf : ContDiff 𝕜 i f) :
iteratedFDeriv 𝕜 i (a • f) x = a • iteratedFDeriv 𝕜 i f x := by
simp_rw [← contDiffOn_univ, ← iteratedFDerivWithin_univ] at *
exact iteratedFDerivWithin_const_smul_apply hf uniqueDiffOn_univ (Set.mem_univ _)
#align iterated_fderiv_const_smul_apply iteratedFDeriv_const_smul_apply
theorem iteratedFDeriv_const_smul_apply' {x : E} (hf : ContDiff 𝕜 i f) :
iteratedFDeriv 𝕜 i (fun x ↦ a • f x) x = a • iteratedFDeriv 𝕜 i f x :=
iteratedFDeriv_const_smul_apply hf
end ConstSMul
/-! ### Cartesian product of two functions -/
section prodMap
variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E']
variable {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F']
/-- The product map of two `C^n` functions within a set at a point is `C^n`
within the product set at the product point. -/
theorem ContDiffWithinAt.prod_map' {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} {p : E × E'}
(hf : ContDiffWithinAt 𝕜 n f s p.1) (hg : ContDiffWithinAt 𝕜 n g t p.2) :
ContDiffWithinAt 𝕜 n (Prod.map f g) (s ×ˢ t) p :=
(hf.comp p contDiffWithinAt_fst (prod_subset_preimage_fst _ _)).prod
(hg.comp p contDiffWithinAt_snd (prod_subset_preimage_snd _ _))
#align cont_diff_within_at.prod_map' ContDiffWithinAt.prod_map'
theorem ContDiffWithinAt.prod_map {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} {x : E}
{y : E'} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g t y) :
ContDiffWithinAt 𝕜 n (Prod.map f g) (s ×ˢ t) (x, y) :=
ContDiffWithinAt.prod_map' hf hg
#align cont_diff_within_at.prod_map ContDiffWithinAt.prod_map
/-- The product map of two `C^n` functions on a set is `C^n` on the product set. -/
theorem ContDiffOn.prod_map {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {F' : Type*}
[NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'}
(hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g t) : ContDiffOn 𝕜 n (Prod.map f g) (s ×ˢ t) :=
(hf.comp contDiffOn_fst (prod_subset_preimage_fst _ _)).prod
(hg.comp contDiffOn_snd (prod_subset_preimage_snd _ _))
#align cont_diff_on.prod_map ContDiffOn.prod_map
/-- The product map of two `C^n` functions within a set at a point is `C^n`
within the product set at the product point. -/
theorem ContDiffAt.prod_map {f : E → F} {g : E' → F'} {x : E} {y : E'} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g y) : ContDiffAt 𝕜 n (Prod.map f g) (x, y) := by
rw [ContDiffAt] at *
convert hf.prod_map hg
simp only [univ_prod_univ]
#align cont_diff_at.prod_map ContDiffAt.prod_map
/-- The product map of two `C^n` functions within a set at a point is `C^n`
within the product set at the product point. -/
theorem ContDiffAt.prod_map' {f : E → F} {g : E' → F'} {p : E × E'} (hf : ContDiffAt 𝕜 n f p.1)
(hg : ContDiffAt 𝕜 n g p.2) : ContDiffAt 𝕜 n (Prod.map f g) p := by
rcases p with ⟨⟩
exact ContDiffAt.prod_map hf hg
#align cont_diff_at.prod_map' ContDiffAt.prod_map'
/-- The product map of two `C^n` functions is `C^n`. -/
theorem ContDiff.prod_map {f : E → F} {g : E' → F'} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n (Prod.map f g) := by
rw [contDiff_iff_contDiffAt] at *
exact fun ⟨x, y⟩ => (hf x).prod_map (hg y)
#align cont_diff.prod_map ContDiff.prod_map
theorem contDiff_prod_mk_left (f₀ : F) : ContDiff 𝕜 n fun e : E => (e, f₀) :=
contDiff_id.prod contDiff_const
#align cont_diff_prod_mk_left contDiff_prod_mk_left
theorem contDiff_prod_mk_right (e₀ : E) : ContDiff 𝕜 n fun f : F => (e₀, f) :=
contDiff_const.prod contDiff_id
#align cont_diff_prod_mk_right contDiff_prod_mk_right
end prodMap
/-! ### Inversion in a complete normed algebra -/
section AlgebraInverse
variable (𝕜) {R : Type*} [NormedRing R]
-- Porting note: this couldn't be on the same line as the binder type update of `𝕜`
variable [NormedAlgebra 𝕜 R]
open NormedRing ContinuousLinearMap Ring
/-- In a complete normed algebra, the operation of inversion is `C^n`, for all `n`, at each
invertible element. The proof is by induction, bootstrapping using an identity expressing the
derivative of inversion as a bilinear map of inversion itself. -/
theorem contDiffAt_ring_inverse [CompleteSpace R] (x : Rˣ) :
ContDiffAt 𝕜 n Ring.inverse (x : R) := by
induction' n using ENat.nat_induction with n IH Itop
· intro m hm
refine ⟨{ y : R | IsUnit y }, ?_, ?_⟩
· simp [nhdsWithin_univ]
exact x.nhds
· use ftaylorSeriesWithin 𝕜 inverse univ
rw [le_antisymm hm bot_le, hasFTaylorSeriesUpToOn_zero_iff]
constructor
· rintro _ ⟨x', rfl⟩
exact (inverse_continuousAt x').continuousWithinAt
· simp [ftaylorSeriesWithin]
· rw [contDiffAt_succ_iff_hasFDerivAt]
refine ⟨fun x : R => -mulLeftRight 𝕜 R (inverse x) (inverse x), ?_, ?_⟩
· refine ⟨{ y : R | IsUnit y }, x.nhds, ?_⟩
rintro _ ⟨y, rfl⟩
simp_rw [inverse_unit]
exact hasFDerivAt_ring_inverse y
· convert (mulLeftRight_isBoundedBilinear 𝕜 R).contDiff.neg.comp_contDiffAt (x : R)
(IH.prod IH)
· exact contDiffAt_top.mpr Itop
#align cont_diff_at_ring_inverse contDiffAt_ring_inverse
variable {𝕜' : Type*} [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [CompleteSpace 𝕜']
theorem contDiffAt_inv {x : 𝕜'} (hx : x ≠ 0) {n} : ContDiffAt 𝕜 n Inv.inv x := by
simpa only [Ring.inverse_eq_inv'] using contDiffAt_ring_inverse 𝕜 (Units.mk0 x hx)
#align cont_diff_at_inv contDiffAt_inv
theorem contDiffOn_inv {n} : ContDiffOn 𝕜 n (Inv.inv : 𝕜' → 𝕜') {0}ᶜ := fun _ hx =>
(contDiffAt_inv 𝕜 hx).contDiffWithinAt
#align cont_diff_on_inv contDiffOn_inv
variable {𝕜}
-- TODO: the next few lemmas don't need `𝕜` or `𝕜'` to be complete
-- A good way to show this is to generalize `contDiffAt_ring_inverse` to the setting
-- of a function `f` such that `∀ᶠ x in 𝓝 a, x * f x = 1`.
theorem ContDiffWithinAt.inv {f : E → 𝕜'} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (hx : f x ≠ 0) :
ContDiffWithinAt 𝕜 n (fun x => (f x)⁻¹) s x :=
(contDiffAt_inv 𝕜 hx).comp_contDiffWithinAt x hf
#align cont_diff_within_at.inv ContDiffWithinAt.inv
theorem ContDiffOn.inv {f : E → 𝕜'} {n} (hf : ContDiffOn 𝕜 n f s) (h : ∀ x ∈ s, f x ≠ 0) :
ContDiffOn 𝕜 n (fun x => (f x)⁻¹) s := fun x hx => (hf.contDiffWithinAt hx).inv (h x hx)
#align cont_diff_on.inv ContDiffOn.inv
nonrec theorem ContDiffAt.inv {f : E → 𝕜'} {n} (hf : ContDiffAt 𝕜 n f x) (hx : f x ≠ 0) :
ContDiffAt 𝕜 n (fun x => (f x)⁻¹) x :=
hf.inv hx
#align cont_diff_at.inv ContDiffAt.inv
theorem ContDiff.inv {f : E → 𝕜'} {n} (hf : ContDiff 𝕜 n f) (h : ∀ x, f x ≠ 0) :
ContDiff 𝕜 n fun x => (f x)⁻¹ := by
rw [contDiff_iff_contDiffAt]; exact fun x => hf.contDiffAt.inv (h x)
#align cont_diff.inv ContDiff.inv
-- TODO: generalize to `f g : E → 𝕜'`
theorem ContDiffWithinAt.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffWithinAt 𝕜 n f s x)
(hg : ContDiffWithinAt 𝕜 n g s x) (hx : g x ≠ 0) :
ContDiffWithinAt 𝕜 n (fun x => f x / g x) s x := by
simpa only [div_eq_mul_inv] using hf.mul (hg.inv hx)
#align cont_diff_within_at.div ContDiffWithinAt.div
theorem ContDiffOn.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) (h₀ : ∀ x ∈ s, g x ≠ 0) : ContDiffOn 𝕜 n (f / g) s := fun x hx =>
(hf x hx).div (hg x hx) (h₀ x hx)
#align cont_diff_on.div ContDiffOn.div
nonrec theorem ContDiffAt.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) (hx : g x ≠ 0) : ContDiffAt 𝕜 n (fun x => f x / g x) x :=
hf.div hg hx
#align cont_diff_at.div ContDiffAt.div
theorem ContDiff.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g)
(h0 : ∀ x, g x ≠ 0) : ContDiff 𝕜 n fun x => f x / g x := by
simp only [contDiff_iff_contDiffAt] at *
exact fun x => (hf x).div (hg x) (h0 x)
#align cont_diff.div ContDiff.div
end AlgebraInverse
/-! ### Inversion of continuous linear maps between Banach spaces -/
section MapInverse
open ContinuousLinearMap
/-- At a continuous linear equivalence `e : E ≃L[𝕜] F` between Banach spaces, the operation of
inversion is `C^n`, for all `n`. -/
theorem contDiffAt_map_inverse [CompleteSpace E] (e : E ≃L[𝕜] F) :
ContDiffAt 𝕜 n inverse (e : E →L[𝕜] F) := by
nontriviality E
-- first, we use the lemma `to_ring_inverse` to rewrite in terms of `Ring.inverse` in the ring
-- `E →L[𝕜] E`
let O₁ : (E →L[𝕜] E) → F →L[𝕜] E := fun f => f.comp (e.symm : F →L[𝕜] E)
let O₂ : (E →L[𝕜] F) → E →L[𝕜] E := fun f => (e.symm : F →L[𝕜] E).comp f
have : ContinuousLinearMap.inverse = O₁ ∘ Ring.inverse ∘ O₂ := funext (to_ring_inverse e)
rw [this]
-- `O₁` and `O₂` are `ContDiff`,
-- so we reduce to proving that `Ring.inverse` is `ContDiff`
have h₁ : ContDiff 𝕜 n O₁ := contDiff_id.clm_comp contDiff_const
have h₂ : ContDiff 𝕜 n O₂ := contDiff_const.clm_comp contDiff_id
refine h₁.contDiffAt.comp _ (ContDiffAt.comp _ ?_ h₂.contDiffAt)
convert contDiffAt_ring_inverse 𝕜 (1 : (E →L[𝕜] E)ˣ)
simp [O₂, one_def]
#align cont_diff_at_map_inverse contDiffAt_map_inverse
end MapInverse
section FunctionInverse
open ContinuousLinearMap
/-- If `f` is a local homeomorphism and the point `a` is in its target,
and if `f` is `n` times continuously differentiable at `f.symm a`,
and if the derivative at `f.symm a` is a continuous linear equivalence,
then `f.symm` is `n` times continuously differentiable at the point `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem PartialHomeomorph.contDiffAt_symm [CompleteSpace E] (f : PartialHomeomorph E F)
{f₀' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target)
(hf₀' : HasFDerivAt f (f₀' : E →L[𝕜] F) (f.symm a)) (hf : ContDiffAt 𝕜 n f (f.symm a)) :
ContDiffAt 𝕜 n f.symm a := by
-- We prove this by induction on `n`
induction' n using ENat.nat_induction with n IH Itop
· rw [contDiffAt_zero]
exact ⟨f.target, IsOpen.mem_nhds f.open_target ha, f.continuousOn_invFun⟩
· obtain ⟨f', ⟨u, hu, hff'⟩, hf'⟩ := contDiffAt_succ_iff_hasFDerivAt.mp hf
rw [contDiffAt_succ_iff_hasFDerivAt]
-- For showing `n.succ` times continuous differentiability (the main inductive step), it
-- suffices to produce the derivative and show that it is `n` times continuously differentiable
have eq_f₀' : f' (f.symm a) = f₀' := (hff' (f.symm a) (mem_of_mem_nhds hu)).unique hf₀'
-- This follows by a bootstrapping formula expressing the derivative as a function of `f` itself
refine ⟨inverse ∘ f' ∘ f.symm, ?_, ?_⟩
· -- We first check that the derivative of `f` is that formula
have h_nhds : { y : E | ∃ e : E ≃L[𝕜] F, ↑e = f' y } ∈ 𝓝 (f.symm a) := by
have hf₀' := f₀'.nhds
rw [← eq_f₀'] at hf₀'
exact hf'.continuousAt.preimage_mem_nhds hf₀'
obtain ⟨t, htu, ht, htf⟩ := mem_nhds_iff.mp (Filter.inter_mem hu h_nhds)
use f.target ∩ f.symm ⁻¹' t
refine ⟨IsOpen.mem_nhds ?_ ?_, ?_⟩
· exact f.isOpen_inter_preimage_symm ht
· exact mem_inter ha (mem_preimage.mpr htf)
intro x hx
obtain ⟨hxu, e, he⟩ := htu hx.2
have h_deriv : HasFDerivAt f (e : E →L[𝕜] F) (f.symm x) := by
rw [he]
exact hff' (f.symm x) hxu
convert f.hasFDerivAt_symm hx.1 h_deriv
simp [← he]
· -- Then we check that the formula, being a composition of `ContDiff` pieces, is
-- itself `ContDiff`
have h_deriv₁ : ContDiffAt 𝕜 n inverse (f' (f.symm a)) := by
rw [eq_f₀']
exact contDiffAt_map_inverse _
have h_deriv₂ : ContDiffAt 𝕜 n f.symm a := by
refine IH (hf.of_le ?_)
norm_cast
exact Nat.le_succ n
exact (h_deriv₁.comp _ hf').comp _ h_deriv₂
· refine contDiffAt_top.mpr ?_
intro n
exact Itop n (contDiffAt_top.mp hf n)
#align local_homeomorph.cont_diff_at_symm PartialHomeomorph.contDiffAt_symm
/-- If `f` is an `n` times continuously differentiable homeomorphism,
and if the derivative of `f` at each point is a continuous linear equivalence,
then `f.symm` is `n` times continuously differentiable.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem Homeomorph.contDiff_symm [CompleteSpace E] (f : E ≃ₜ F) {f₀' : E → E ≃L[𝕜] F}
(hf₀' : ∀ a, HasFDerivAt f (f₀' a : E →L[𝕜] F) a) (hf : ContDiff 𝕜 n (f : E → F)) :
ContDiff 𝕜 n (f.symm : F → E) :=
contDiff_iff_contDiffAt.2 fun x =>
f.toPartialHomeomorph.contDiffAt_symm (mem_univ x) (hf₀' _) hf.contDiffAt
#align homeomorph.cont_diff_symm Homeomorph.contDiff_symm
/-- Let `f` be a local homeomorphism of a nontrivially normed field, let `a` be a point in its
target. if `f` is `n` times continuously differentiable at `f.symm a`, and if the derivative at
`f.symm a` is nonzero, then `f.symm` is `n` times continuously differentiable at the point `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem PartialHomeomorph.contDiffAt_symm_deriv [CompleteSpace 𝕜] (f : PartialHomeomorph 𝕜 𝕜)
{f₀' a : 𝕜} (h₀ : f₀' ≠ 0) (ha : a ∈ f.target) (hf₀' : HasDerivAt f f₀' (f.symm a))
(hf : ContDiffAt 𝕜 n f (f.symm a)) : ContDiffAt 𝕜 n f.symm a :=
f.contDiffAt_symm ha (hf₀'.hasFDerivAt_equiv h₀) hf
#align local_homeomorph.cont_diff_at_symm_deriv PartialHomeomorph.contDiffAt_symm_deriv
/-- Let `f` be an `n` times continuously differentiable homeomorphism of a nontrivially normed
field. Suppose that the derivative of `f` is never equal to zero. Then `f.symm` is `n` times
continuously differentiable.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem Homeomorph.contDiff_symm_deriv [CompleteSpace 𝕜] (f : 𝕜 ≃ₜ 𝕜) {f' : 𝕜 → 𝕜}
(h₀ : ∀ x, f' x ≠ 0) (hf' : ∀ x, HasDerivAt f (f' x) x) (hf : ContDiff 𝕜 n (f : 𝕜 → 𝕜)) :
ContDiff 𝕜 n (f.symm : 𝕜 → 𝕜) :=
contDiff_iff_contDiffAt.2 fun x =>
f.toPartialHomeomorph.contDiffAt_symm_deriv (h₀ _) (mem_univ x) (hf' _) hf.contDiffAt
#align homeomorph.cont_diff_symm_deriv Homeomorph.contDiff_symm_deriv
namespace PartialHomeomorph
variable (𝕜)
/-- Restrict a partial homeomorphism to the subsets of the source and target
that consist of points `x ∈ f.source`, `y = f x ∈ f.target`
such that `f` is `C^n` at `x` and `f.symm` is `C^n` at `y`.
Note that `n` is a natural number, not `∞`,
because the set of points of `C^∞`-smoothness of `f` is not guaranteed to be open. -/
@[simps! apply symm_apply source target]
def restrContDiff (f : PartialHomeomorph E F) (n : ℕ) : PartialHomeomorph E F :=
haveI H : f.IsImage {x | ContDiffAt 𝕜 n f x ∧ ContDiffAt 𝕜 n f.symm (f x)}
{y | ContDiffAt 𝕜 n f.symm y ∧ ContDiffAt 𝕜 n f (f.symm y)} := fun x hx ↦ by
simp [hx, and_comm]
H.restr <| isOpen_iff_mem_nhds.2 fun x ⟨hxs, hxf, hxf'⟩ ↦
inter_mem (f.open_source.mem_nhds hxs) <| hxf.eventually.and <|
f.continuousAt hxs hxf'.eventually
lemma contDiffOn_restrContDiff_source (f : PartialHomeomorph E F) (n : ℕ) :
ContDiffOn 𝕜 n f (f.restrContDiff 𝕜 n).source := fun _x hx ↦ hx.2.1.contDiffWithinAt
lemma contDiffOn_restrContDiff_target (f : PartialHomeomorph E F) (n : ℕ) :
ContDiffOn 𝕜 n f.symm (f.restrContDiff 𝕜 n).target := fun _x hx ↦ hx.2.1.contDiffWithinAt
end PartialHomeomorph
end FunctionInverse
section deriv
/-!
### One dimension
All results up to now have been expressed in terms of the general Fréchet derivative `fderiv`. For
maps defined on the field, the one-dimensional derivative `deriv` is often easier to use. In this
paragraph, we reformulate some higher smoothness results in terms of `deriv`.
-/
variable {f₂ : 𝕜 → F} {s₂ : Set 𝕜}
open ContinuousLinearMap (smulRight)
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (formulated with `derivWithin`) is `C^n`. -/
theorem contDiffOn_succ_iff_derivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s₂) :
ContDiffOn 𝕜 (n + 1 : ℕ) f₂ s₂ ↔
DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 n (derivWithin f₂ s₂) s₂ := by
rw [contDiffOn_succ_iff_fderivWithin hs, and_congr_right_iff]
intro _
constructor
· intro h
have : derivWithin f₂ s₂ = (fun u : 𝕜 →L[𝕜] F => u 1) ∘ fderivWithin 𝕜 f₂ s₂ := by
ext x; rfl
simp_rw [this]
apply ContDiff.comp_contDiffOn _ h
exact (isBoundedBilinearMap_apply.isBoundedLinearMap_left _).contDiff
· intro h
have : fderivWithin 𝕜 f₂ s₂ = smulRight (1 : 𝕜 →L[𝕜] 𝕜) ∘ derivWithin f₂ s₂ := by
ext x; simp [derivWithin]
simp only [this]
apply ContDiff.comp_contDiffOn _ h
have : IsBoundedBilinearMap 𝕜 fun _ : (𝕜 →L[𝕜] 𝕜) × F => _ := isBoundedBilinearMap_smulRight
exact (this.isBoundedLinearMap_right _).contDiff
#align cont_diff_on_succ_iff_deriv_within contDiffOn_succ_iff_derivWithin
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (formulated with `deriv`) is `C^n`. -/
theorem contDiffOn_succ_iff_deriv_of_isOpen {n : ℕ} (hs : IsOpen s₂) :
ContDiffOn 𝕜 (n + 1 : ℕ) f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 n (deriv f₂) s₂ := by
rw [contDiffOn_succ_iff_derivWithin hs.uniqueDiffOn]
exact Iff.rfl.and (contDiffOn_congr fun _ => derivWithin_of_isOpen hs)
#align cont_diff_on_succ_iff_deriv_of_open contDiffOn_succ_iff_deriv_of_isOpen
/-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable
there, and its derivative (formulated with `derivWithin`) is `C^∞`. -/
theorem contDiffOn_top_iff_derivWithin (hs : UniqueDiffOn 𝕜 s₂) :
ContDiffOn 𝕜 ∞ f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 ∞ (derivWithin f₂ s₂) s₂ := by
constructor
· intro h
refine ⟨h.differentiableOn le_top, ?_⟩
refine contDiffOn_top.2 fun n => ((contDiffOn_succ_iff_derivWithin hs).1 ?_).2
exact h.of_le le_top
· intro h
refine contDiffOn_top.2 fun n => ?_
have A : (n : ℕ∞) ≤ ∞ := le_top
apply ((contDiffOn_succ_iff_derivWithin hs).2 ⟨h.1, h.2.of_le A⟩).of_le
exact WithTop.coe_le_coe.2 (Nat.le_succ n)
#align cont_diff_on_top_iff_deriv_within contDiffOn_top_iff_derivWithin
/-- A function is `C^∞` on an open domain if and only if it is differentiable
there, and its derivative (formulated with `deriv`) is `C^∞`. -/
| Mathlib/Analysis/Calculus/ContDiff/Basic.lean | 2,058 | 2,061 | theorem contDiffOn_top_iff_deriv_of_isOpen (hs : IsOpen s₂) :
ContDiffOn 𝕜 ∞ f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 ∞ (deriv f₂) s₂ := by |
rw [contDiffOn_top_iff_derivWithin hs.uniqueDiffOn]
exact Iff.rfl.and <| contDiffOn_congr fun _ => derivWithin_of_isOpen hs
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Ken Lee, Chris Hughes
-/
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Int.GCD
import Mathlib.RingTheory.Coprime.Basic
#align_import ring_theory.coprime.lemmas from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226"
/-!
# Additional lemmas about elements of a ring satisfying `IsCoprime`
and elements of a monoid satisfying `IsRelPrime`
These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime`
as they require more imports.
Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and
lemmas about `Pow` since these are easiest to prove via `Finset.prod`.
-/
universe u v
section IsCoprime
variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I}
section
theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by
constructor
· rintro ⟨a, b, h⟩
have : 1 = m * a + n * b := by rwa [mul_comm m, mul_comm n, eq_comm]
exact Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, this⟩)
· rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one]
intro h
exact ⟨_, _, h⟩
theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by
rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast]
#align nat.is_coprime_iff_coprime Nat.isCoprime_iff_coprime
alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime
#align is_coprime.nat_coprime IsCoprime.nat_coprime
#align nat.coprime.is_coprime Nat.Coprime.isCoprime
theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) :
IsCoprime (a : R) (b : R) := by
rw [← isCoprime_iff_coprime] at h
rw [← Int.cast_natCast a, ← Int.cast_natCast b]
exact IsCoprime.intCast h
theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ}
(h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 :=
IsCoprime.ne_zero_or_ne_zero (R := A) <| by
simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A)
theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by
classical
refine Finset.induction_on t (fun _ ↦ isCoprime_one_left) fun b t hbt ih H ↦ ?_
rw [Finset.prod_insert hbt]
rw [Finset.forall_mem_insert] at H
exact H.1.mul_left (ih H.2)
#align is_coprime.prod_left IsCoprime.prod_left
| Mathlib/RingTheory/Coprime/Lemmas.lean | 69 | 70 | theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by |
simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R)
|
/-
Copyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Pierre-Alexandre Bazin
-/
import Mathlib.Algebra.Module.DedekindDomain
import Mathlib.LinearAlgebra.FreeModule.PID
import Mathlib.Algebra.Module.Projective
import Mathlib.Algebra.Category.ModuleCat.Biproducts
import Mathlib.RingTheory.SimpleModule
#align_import algebra.module.pid from "leanprover-community/mathlib"@"cdc34484a07418af43daf8198beaf5c00324bca8"
/-!
# Structure of finitely generated modules over a PID
## Main statements
* `Module.equiv_directSum_of_isTorsion` : A finitely generated torsion module over a PID is
isomorphic to a direct sum of some `R ⧸ R ∙ (p i ^ e i)` where the `p i ^ e i` are prime powers.
* `Module.equiv_free_prod_directSum` : A finitely generated module over a PID is isomorphic to the
product of a free module (its torsion free part) and a direct sum of the form above (its torsion
submodule).
## Notation
* `R` is a PID and `M` is a (finitely generated for main statements) `R`-module, with additional
torsion hypotheses in the intermediate lemmas.
* `N` is an `R`-module lying over a higher type universe than `R`. This assumption is needed on the
final statement for technical reasons.
* `p` is an irreducible element of `R` or a tuple of these.
## Implementation details
We first prove (`Submodule.isInternal_prime_power_torsion_of_pid`) that a finitely generated
torsion module is the internal direct sum of its `p i ^ e i`-torsion submodules for some
(finitely many) prime powers `p i ^ e i`. This is proved in more generality for a Dedekind domain
at `Submodule.isInternal_prime_power_torsion`.
Then we treat the case of a `p ^ ∞`-torsion module (that is, a module where all elements are
cancelled by scalar multiplication by some power of `p`) and apply it to the `p i ^ e i`-torsion
submodules (that are `p i ^ ∞`-torsion) to get the result for torsion modules.
Then we get the general result using that a torsion free module is free (which has been proved at
`Module.free_of_finite_type_torsion_free'` at `LinearAlgebra.FreeModule.PID`.)
## Tags
Finitely generated module, principal ideal domain, classification, structure theorem
-/
universe u v
open scoped Classical
variable {R : Type u} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
variable {M : Type v} [AddCommGroup M] [Module R M]
variable {N : Type max u v} [AddCommGroup N] [Module R N]
open scoped DirectSum
open Submodule
open UniqueFactorizationMonoid
theorem Submodule.isSemisimple_torsionBy_of_irreducible {a : R} (h : Irreducible a) :
IsSemisimpleModule R (torsionBy R M a) :=
haveI := PrincipalIdealRing.isMaximal_of_irreducible h
letI := Ideal.Quotient.field (R ∙ a)
(submodule_torsionBy_orderIso a).complementedLattice
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`. -/
theorem Submodule.isInternal_prime_power_torsion_of_pid [Module.Finite R M]
(hM : Module.IsTorsion R M) :
DirectSum.IsInternal fun p : (factors (⊤ : Submodule R M).annihilator).toFinset =>
torsionBy R M
(IsPrincipal.generator (p : Ideal R) ^
(factors (⊤ : Submodule R M).annihilator).count ↑p) := by
convert isInternal_prime_power_torsion hM
ext p : 1
rw [← torsionBySet_span_singleton_eq, Ideal.submodule_span_eq, ← Ideal.span_singleton_pow,
Ideal.span_singleton_generator]
#align submodule.is_internal_prime_power_torsion_of_pid Submodule.isInternal_prime_power_torsion_of_pid
/-- A finitely generated torsion module over a PID is an internal direct sum of its
`p i ^ e i`-torsion submodules for some primes `p i` and numbers `e i`. -/
theorem Submodule.exists_isInternal_prime_power_torsion_of_pid [Module.Finite R M]
(hM : Module.IsTorsion R M) :
∃ (ι : Type u) (_ : Fintype ι) (_ : DecidableEq ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i)
(e : ι → ℕ), DirectSum.IsInternal fun i => torsionBy R M <| p i ^ e i := by
refine ⟨_, ?_, _, _, ?_, _, Submodule.isInternal_prime_power_torsion_of_pid hM⟩
· exact Finset.fintypeCoeSort _
· rintro ⟨p, hp⟩
have hP := prime_of_factor p (Multiset.mem_toFinset.mp hp)
haveI := Ideal.isPrime_of_prime hP
exact (IsPrincipal.prime_generator_of_isPrime p hP.ne_zero).irreducible
#align submodule.exists_is_internal_prime_power_torsion_of_pid Submodule.exists_isInternal_prime_power_torsion_of_pid
namespace Module
section PTorsion
variable {p : R} (hp : Irreducible p) (hM : Module.IsTorsion' M (Submonoid.powers p))
variable [dec : ∀ x : M, Decidable (x = 0)]
open Ideal Submodule.IsPrincipal
theorem _root_.Ideal.torsionOf_eq_span_pow_pOrder (x : M) :
torsionOf R M x = span {p ^ pOrder hM x} := by
dsimp only [pOrder]
rw [← (torsionOf R M x).span_singleton_generator, Ideal.span_singleton_eq_span_singleton, ←
Associates.mk_eq_mk_iff_associated, Associates.mk_pow]
have prop :
(fun n : ℕ => p ^ n • x = 0) = fun n : ℕ =>
(Associates.mk <| generator <| torsionOf R M x) ∣ Associates.mk p ^ n := by
ext n; rw [← Associates.mk_pow, Associates.mk_dvd_mk, ← mem_iff_generator_dvd]; rfl
have := (isTorsion'_powers_iff p).mp hM x; rw [prop] at this
convert Associates.eq_pow_find_of_dvd_irreducible_pow (Associates.irreducible_mk.mpr hp)
this.choose_spec
#align ideal.torsion_of_eq_span_pow_p_order Ideal.torsionOf_eq_span_pow_pOrder
theorem p_pow_smul_lift {x y : M} {k : ℕ} (hM' : Module.IsTorsionBy R M (p ^ pOrder hM y))
(h : p ^ k • x ∈ R ∙ y) : ∃ a : R, p ^ k • x = p ^ k • a • y := by
-- Porting note: needed to make `smul_smul` work below.
letI : MulAction R M := MulActionWithZero.toMulAction
by_cases hk : k ≤ pOrder hM y
· let f :=
((R ∙ p ^ (pOrder hM y - k) * p ^ k).quotEquivOfEq _ ?_).trans
(quotTorsionOfEquivSpanSingleton R M y)
· have : f.symm ⟨p ^ k • x, h⟩ ∈
R ∙ Ideal.Quotient.mk (R ∙ p ^ (pOrder hM y - k) * p ^ k) (p ^ k) := by
rw [← Quotient.torsionBy_eq_span_singleton, mem_torsionBy_iff, ← f.symm.map_smul]
· convert f.symm.map_zero; ext
rw [coe_smul_of_tower, coe_mk, coe_zero, smul_smul, ← pow_add, Nat.sub_add_cancel hk,
@hM' x]
· exact mem_nonZeroDivisors_of_ne_zero (pow_ne_zero _ hp.ne_zero)
rw [Submodule.mem_span_singleton] at this; obtain ⟨a, ha⟩ := this; use a
rw [f.eq_symm_apply, ← Ideal.Quotient.mk_eq_mk, ← Quotient.mk_smul] at ha
dsimp only [smul_eq_mul, LinearEquiv.trans_apply, Submodule.quotEquivOfEq_mk,
quotTorsionOfEquivSpanSingleton_apply_mk] at ha
rw [smul_smul, mul_comm]; exact congr_arg ((↑) : _ → M) ha.symm
· symm; convert Ideal.torsionOf_eq_span_pow_pOrder hp hM y
rw [← pow_add, Nat.sub_add_cancel hk]
· use 0
rw [zero_smul, smul_zero, ← Nat.sub_add_cancel (le_of_not_le hk), pow_add, mul_smul, hM',
smul_zero]
#align module.p_pow_smul_lift Module.p_pow_smul_lift
open Submodule.Quotient
theorem exists_smul_eq_zero_and_mk_eq {z : M} (hz : Module.IsTorsionBy R M (p ^ pOrder hM z))
{k : ℕ} (f : (R ⧸ R ∙ p ^ k) →ₗ[R] M ⧸ R ∙ z) :
∃ x : M, p ^ k • x = 0 ∧ Submodule.Quotient.mk (p := span R {z}) x = f 1 := by
have f1 := mk_surjective (R ∙ z) (f 1)
have : p ^ k • f1.choose ∈ R ∙ z := by
rw [← Quotient.mk_eq_zero, mk_smul, f1.choose_spec, ← f.map_smul]
convert f.map_zero; change _ • Submodule.Quotient.mk _ = _
rw [← mk_smul, Quotient.mk_eq_zero, Algebra.id.smul_eq_mul, mul_one]
exact Submodule.mem_span_singleton_self _
obtain ⟨a, ha⟩ := p_pow_smul_lift hp hM hz this
refine ⟨f1.choose - a • z, by rw [smul_sub, sub_eq_zero, ha], ?_⟩
rw [mk_sub, mk_smul, (Quotient.mk_eq_zero _).mpr <| Submodule.mem_span_singleton_self _,
smul_zero, sub_zero, f1.choose_spec]
#align module.exists_smul_eq_zero_and_mk_eq Module.exists_smul_eq_zero_and_mk_eq
open Finset Multiset
/-- A finitely generated `p ^ ∞`-torsion module over a PID is isomorphic to a direct sum of some
`R ⧸ R ∙ (p ^ e i)` for some `e i`. -/
theorem torsion_by_prime_power_decomposition (hN : Module.IsTorsion' N (Submonoid.powers p))
[h' : Module.Finite R N] :
∃ (d : ℕ) (k : Fin d → ℕ), Nonempty <| N ≃ₗ[R] ⨁ i : Fin d, R ⧸ R ∙ p ^ (k i : ℕ) := by
obtain ⟨d, s, hs⟩ := @Module.Finite.exists_fin _ _ _ _ _ h'; use d; clear h'
induction' d with d IH generalizing N
· -- Porting note: was `use fun i => finZeroElim i`
use finZeroElim
rw [Set.range_eq_empty, Submodule.span_empty] at hs
haveI : Unique N :=
⟨⟨0⟩, fun x => by dsimp; rw [← Submodule.mem_bot R, hs]; exact Submodule.mem_top⟩
haveI : IsEmpty (Fin Nat.zero) := inferInstanceAs (IsEmpty (Fin 0))
exact ⟨0⟩
· have : ∀ x : N, Decidable (x = 0) := fun _ => by classical infer_instance
obtain ⟨j, hj⟩ := exists_isTorsionBy hN d.succ d.succ_ne_zero s hs
let s' : Fin d → N ⧸ R ∙ s j := Submodule.Quotient.mk ∘ s ∘ j.succAbove
-- Porting note(https://github.com/leanprover-community/mathlib4/issues/5732):
-- `obtain` doesn't work with placeholders.
have := IH ?_ s' ?_
· obtain ⟨k, ⟨f⟩⟩ := this
clear IH
have : ∀ i : Fin d,
∃ x : N, p ^ k i • x = 0 ∧ f (Submodule.Quotient.mk x) = DirectSum.lof R _ _ i 1 := by
intro i
let fi := f.symm.toLinearMap.comp (DirectSum.lof _ _ _ i)
obtain ⟨x, h0, h1⟩ := exists_smul_eq_zero_and_mk_eq hp hN hj fi; refine ⟨x, h0, ?_⟩; rw [h1]
simp only [fi, LinearMap.coe_comp, f.symm.coe_toLinearMap, f.apply_symm_apply,
Function.comp_apply]
refine ⟨?_, ⟨?_⟩⟩
· exact fun a => (fun i => (Option.rec (pOrder hN (s j)) k i : ℕ)) (finSuccEquiv d a)
· refine (((lequivProdOfRightSplitExact
(g := (f.trans ULift.moduleEquiv.{u, u, v}.symm).toLinearMap.comp <| mkQ _)
(f := (DirectSum.toModule _ _ _ fun i => (liftQSpanSingleton (p ^ k i)
(LinearMap.toSpanSingleton _ _ _) (this i).choose_spec.left : R ⧸ _ →ₗ[R] _)).comp
ULift.moduleEquiv.toLinearMap) (R ∙ s j).injective_subtype ?_ ?_).symm.trans
(((quotTorsionOfEquivSpanSingleton R N (s j)).symm.trans
(quotEquivOfEq (torsionOf R N (s j)) _
(Ideal.torsionOf_eq_span_pow_pOrder hp hN (s j)))).prod
(ULift.moduleEquiv))).trans
(@DirectSum.lequivProdDirectSum R _ _ _
(fun i => R ⧸ R ∙ p ^ @Option.rec _ (fun _ => ℕ) (pOrder hN <| s j) k i) _ _).symm).trans
(DirectSum.lequivCongrLeft R (finSuccEquiv d).symm)
· rw [range_subtype, LinearEquiv.ker_comp, ker_mkQ]
· rw [← f.comp_coe, LinearMap.comp_assoc, LinearMap.comp_assoc,
LinearEquiv.toLinearMap_symm_comp_eq, LinearMap.comp_id, ← LinearMap.comp_assoc,
← LinearMap.comp_assoc]
suffices (f.toLinearMap.comp (R ∙ s j).mkQ).comp _ = LinearMap.id by
rw [this, LinearMap.id_comp]
ext i : 3
simp only [LinearMap.coe_comp, Function.comp_apply, mkQ_apply]
rw [LinearEquiv.coe_toLinearMap, LinearMap.id_apply, DirectSum.toModule_lof,
liftQSpanSingleton_apply, LinearMap.toSpanSingleton_one, Ideal.Quotient.mk_eq_mk,
map_one (Ideal.Quotient.mk _), (this i).choose_spec.right]
· exact (mk_surjective _).forall.mpr fun x =>
⟨(@hN x).choose, by rw [← Quotient.mk_smul, (@hN x).choose_spec, Quotient.mk_zero]⟩
· have hs' := congr_arg (Submodule.map <| mkQ <| R ∙ s j) hs
rw [Submodule.map_span, Submodule.map_top, range_mkQ] at hs'; simp only [mkQ_apply] at hs'
simp only [s']; rw [← Function.comp.assoc, Set.range_comp (_ ∘ s), Fin.range_succAbove]
rw [← Set.range_comp, ← Set.insert_image_compl_eq_range _ j, Function.comp_apply,
(Quotient.mk_eq_zero _).mpr (Submodule.mem_span_singleton_self _), span_insert_zero] at hs'
exact hs'
#align module.torsion_by_prime_power_decomposition Module.torsion_by_prime_power_decomposition
end PTorsion
/-- A finitely generated torsion module over a PID is isomorphic to a direct sum of some
`R ⧸ R ∙ (p i ^ e i)` where the `p i ^ e i` are prime powers. -/
| Mathlib/Algebra/Module/PID.lean | 238 | 260 | theorem equiv_directSum_of_isTorsion [h' : Module.Finite R N] (hN : Module.IsTorsion R N) :
∃ (ι : Type u) (_ : Fintype ι) (p : ι → R) (_ : ∀ i, Irreducible <| p i) (e : ι → ℕ),
Nonempty <| N ≃ₗ[R] ⨁ i : ι, R ⧸ R ∙ p i ^ e i := by |
obtain ⟨I, fI, _, p, hp, e, h⟩ := Submodule.exists_isInternal_prime_power_torsion_of_pid hN
haveI := fI
have :
∀ i,
∃ (d : ℕ) (k : Fin d → ℕ),
Nonempty <| torsionBy R N (p i ^ e i) ≃ₗ[R] ⨁ j, R ⧸ R ∙ p i ^ k j := by
haveI := fun i => isNoetherian_submodule' (torsionBy R N <| p i ^ e i)
exact fun i =>
torsion_by_prime_power_decomposition.{u, v} (hp i)
((isTorsion'_powers_iff <| p i).mpr fun x => ⟨e i, smul_torsionBy _ _⟩)
classical
refine
⟨Σ i, Fin (this i).choose, inferInstance, fun ⟨i, _⟩ => p i, fun ⟨i, _⟩ => hp i, fun ⟨i, j⟩ =>
(this i).choose_spec.choose j,
⟨(LinearEquiv.ofBijective (DirectSum.coeLinearMap _) h).symm.trans <|
(DFinsupp.mapRange.linearEquiv fun i => (this i).choose_spec.choose_spec.some).trans <|
(DirectSum.sigmaLcurryEquiv R).symm.trans
(DFinsupp.mapRange.linearEquiv fun i => quotEquivOfEq _ _ ?_)⟩⟩
cases' i with i j
simp only
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import Mathlib.Logic.Equiv.Nat
import Mathlib.Data.PNat.Basic
import Mathlib.Order.Directed
import Mathlib.Data.Countable.Defs
import Mathlib.Order.RelIso.Basic
import Mathlib.Data.Fin.Basic
#align_import logic.encodable.basic from "leanprover-community/mathlib"@"7c523cb78f4153682c2929e3006c863bfef463d0"
/-!
# Encodable types
This file defines encodable (constructively countable) types as a typeclass.
This is used to provide explicit encode/decode functions from and to `ℕ`, with the information that
those functions are inverses of each other.
The difference with `Denumerable` is that finite types are encodable. For infinite types,
`Encodable` and `Denumerable` agree.
## Main declarations
* `Encodable α`: States that there exists an explicit encoding function `encode : α → ℕ` with a
partial inverse `decode : ℕ → Option α`.
* `decode₂`: Version of `decode` that is equal to `none` outside of the range of `encode`. Useful as
we do not require this in the definition of `decode`.
* `ULower α`: Any encodable type has an equivalent type living in the lowest universe, namely a
subtype of `ℕ`. `ULower α` finds it.
## Implementation notes
The point of asking for an explicit partial inverse `decode : ℕ → Option α` to `encode : α → ℕ` is
to make the range of `encode` decidable even when the finiteness of `α` is not.
-/
open Option List Nat Function
/-- Constructively countable type. Made from an explicit injection `encode : α → ℕ` and a partial
inverse `decode : ℕ → Option α`. Note that finite types *are* countable. See `Denumerable` if you
wish to enforce infiniteness. -/
class Encodable (α : Type*) where
/-- Encoding from Type α to ℕ -/
encode : α → ℕ
-- Porting note: was `decode [] : ℕ → Option α`. This means that `decode` does not take the type
--explicitly in Lean4
/-- Decoding from ℕ to Option α-/
decode : ℕ → Option α
/-- Invariant relationship between encoding and decoding-/
encodek : ∀ a, decode (encode a) = some a
#align encodable Encodable
attribute [simp] Encodable.encodek
namespace Encodable
variable {α : Type*} {β : Type*}
universe u
theorem encode_injective [Encodable α] : Function.Injective (@encode α _)
| x, y, e => Option.some.inj <| by rw [← encodek, e, encodek]
#align encodable.encode_injective Encodable.encode_injective
@[simp]
theorem encode_inj [Encodable α] {a b : α} : encode a = encode b ↔ a = b :=
encode_injective.eq_iff
#align encodable.encode_inj Encodable.encode_inj
-- The priority of the instance below is less than the priorities of `Subtype.Countable`
-- and `Quotient.Countable`
instance (priority := 400) countable [Encodable α] : Countable α where
exists_injective_nat' := ⟨_,encode_injective⟩
theorem surjective_decode_iget (α : Type*) [Encodable α] [Inhabited α] :
Surjective fun n => ((Encodable.decode n).iget : α) := fun x =>
⟨Encodable.encode x, by simp_rw [Encodable.encodek]⟩
#align encodable.surjective_decode_iget Encodable.surjective_decode_iget
/-- An encodable type has decidable equality. Not set as an instance because this is usually not the
best way to infer decidability. -/
def decidableEqOfEncodable (α) [Encodable α] : DecidableEq α
| _, _ => decidable_of_iff _ encode_inj
#align encodable.decidable_eq_of_encodable Encodable.decidableEqOfEncodable
/-- If `α` is encodable and there is an injection `f : β → α`, then `β` is encodable as well. -/
def ofLeftInjection [Encodable α] (f : β → α) (finv : α → Option β)
(linv : ∀ b, finv (f b) = some b) : Encodable β :=
⟨fun b => encode (f b), fun n => (decode n).bind finv, fun b => by
simp [Encodable.encodek, linv]⟩
#align encodable.of_left_injection Encodable.ofLeftInjection
/-- If `α` is encodable and `f : β → α` is invertible, then `β` is encodable as well. -/
def ofLeftInverse [Encodable α] (f : β → α) (finv : α → β) (linv : ∀ b, finv (f b) = b) :
Encodable β :=
ofLeftInjection f (some ∘ finv) fun b => congr_arg some (linv b)
#align encodable.of_left_inverse Encodable.ofLeftInverse
/-- Encodability is preserved by equivalence. -/
def ofEquiv (α) [Encodable α] (e : β ≃ α) : Encodable β :=
ofLeftInverse e e.symm e.left_inv
#align encodable.of_equiv Encodable.ofEquiv
-- Porting note: removing @[simp], too powerful
theorem encode_ofEquiv {α β} [Encodable α] (e : β ≃ α) (b : β) :
@encode _ (ofEquiv _ e) b = encode (e b) :=
rfl
#align encodable.encode_of_equiv Encodable.encode_ofEquiv
-- Porting note: removing @[simp], too powerful
theorem decode_ofEquiv {α β} [Encodable α] (e : β ≃ α) (n : ℕ) :
@decode _ (ofEquiv _ e) n = (decode n).map e.symm :=
show Option.bind _ _ = Option.map _ _
by rw [Option.map_eq_bind]
#align encodable.decode_of_equiv Encodable.decode_ofEquiv
instance _root_.Nat.encodable : Encodable ℕ :=
⟨id, some, fun _ => rfl⟩
#align nat.encodable Nat.encodable
@[simp]
theorem encode_nat (n : ℕ) : encode n = n :=
rfl
#align encodable.encode_nat Encodable.encode_nat
@[simp 1100]
theorem decode_nat (n : ℕ) : decode n = some n :=
rfl
#align encodable.decode_nat Encodable.decode_nat
instance (priority := 100) _root_.IsEmpty.toEncodable [IsEmpty α] : Encodable α :=
⟨isEmptyElim, fun _ => none, isEmptyElim⟩
#align is_empty.to_encodable IsEmpty.toEncodable
instance _root_.PUnit.encodable : Encodable PUnit :=
⟨fun _ => 0, fun n => Nat.casesOn n (some PUnit.unit) fun _ => none, fun _ => by simp⟩
#align punit.encodable PUnit.encodable
@[simp]
theorem encode_star : encode PUnit.unit = 0 :=
rfl
#align encodable.encode_star Encodable.encode_star
@[simp]
theorem decode_unit_zero : decode 0 = some PUnit.unit :=
rfl
#align encodable.decode_unit_zero Encodable.decode_unit_zero
@[simp]
theorem decode_unit_succ (n) : decode (succ n) = (none : Option PUnit) :=
rfl
#align encodable.decode_unit_succ Encodable.decode_unit_succ
/-- If `α` is encodable, then so is `Option α`. -/
instance _root_.Option.encodable {α : Type*} [h : Encodable α] : Encodable (Option α) :=
⟨fun o => Option.casesOn o Nat.zero fun a => succ (encode a), fun n =>
Nat.casesOn n (some none) fun m => (decode m).map some, fun o => by
cases o <;> dsimp; simp [encodek, Nat.succ_ne_zero]⟩
#align option.encodable Option.encodable
@[simp]
theorem encode_none [Encodable α] : encode (@none α) = 0 :=
rfl
#align encodable.encode_none Encodable.encode_none
@[simp]
theorem encode_some [Encodable α] (a : α) : encode (some a) = succ (encode a) :=
rfl
#align encodable.encode_some Encodable.encode_some
@[simp]
theorem decode_option_zero [Encodable α] : (decode 0 : Option (Option α))= some none :=
rfl
#align encodable.decode_option_zero Encodable.decode_option_zero
@[simp]
theorem decode_option_succ [Encodable α] (n) :
(decode (succ n) : Option (Option α)) = (decode n).map some :=
rfl
#align encodable.decode_option_succ Encodable.decode_option_succ
/-- Failsafe variant of `decode`. `decode₂ α n` returns the preimage of `n` under `encode` if it
exists, and returns `none` if it doesn't. This requirement could be imposed directly on `decode` but
is not to help make the definition easier to use. -/
def decode₂ (α) [Encodable α] (n : ℕ) : Option α :=
(decode n).bind (Option.guard fun a => encode a = n)
#align encodable.decode₂ Encodable.decode₂
theorem mem_decode₂' [Encodable α] {n : ℕ} {a : α} :
a ∈ decode₂ α n ↔ a ∈ decode n ∧ encode a = n := by
simpa [decode₂, bind_eq_some] using
⟨fun ⟨_, h₁, rfl, h₂⟩ => ⟨h₁, h₂⟩, fun ⟨h₁, h₂⟩ => ⟨_, h₁, rfl, h₂⟩⟩
#align encodable.mem_decode₂' Encodable.mem_decode₂'
theorem mem_decode₂ [Encodable α] {n : ℕ} {a : α} : a ∈ decode₂ α n ↔ encode a = n :=
mem_decode₂'.trans (and_iff_right_of_imp fun e => e ▸ encodek _)
#align encodable.mem_decode₂ Encodable.mem_decode₂
theorem decode₂_eq_some [Encodable α] {n : ℕ} {a : α} : decode₂ α n = some a ↔ encode a = n :=
mem_decode₂
#align encodable.decode₂_eq_some Encodable.decode₂_eq_some
@[simp]
theorem decode₂_encode [Encodable α] (a : α) : decode₂ α (encode a) = some a := by
ext
simp [mem_decode₂, eq_comm, decode₂_eq_some]
#align encodable.decode₂_encode Encodable.decode₂_encode
theorem decode₂_ne_none_iff [Encodable α] {n : ℕ} :
decode₂ α n ≠ none ↔ n ∈ Set.range (encode : α → ℕ) := by
simp_rw [Set.range, Set.mem_setOf_eq, Ne, Option.eq_none_iff_forall_not_mem,
Encodable.mem_decode₂, not_forall, not_not]
#align encodable.decode₂_ne_none_iff Encodable.decode₂_ne_none_iff
theorem decode₂_is_partial_inv [Encodable α] : IsPartialInv encode (decode₂ α) := fun _ _ =>
mem_decode₂
#align encodable.decode₂_is_partial_inv Encodable.decode₂_is_partial_inv
theorem decode₂_inj [Encodable α] {n : ℕ} {a₁ a₂ : α} (h₁ : a₁ ∈ decode₂ α n)
(h₂ : a₂ ∈ decode₂ α n) : a₁ = a₂ :=
encode_injective <| (mem_decode₂.1 h₁).trans (mem_decode₂.1 h₂).symm
#align encodable.decode₂_inj Encodable.decode₂_inj
theorem encodek₂ [Encodable α] (a : α) : decode₂ α (encode a) = some a :=
mem_decode₂.2 rfl
#align encodable.encodek₂ Encodable.encodek₂
/-- The encoding function has decidable range. -/
def decidableRangeEncode (α : Type*) [Encodable α] : DecidablePred (· ∈ Set.range (@encode α _)) :=
fun x =>
decidable_of_iff (Option.isSome (decode₂ α x))
⟨fun h => ⟨Option.get _ h, by rw [← decode₂_is_partial_inv (Option.get _ h), Option.some_get]⟩,
fun ⟨n, hn⟩ => by rw [← hn, encodek₂]; exact rfl⟩
#align encodable.decidable_range_encode Encodable.decidableRangeEncode
/-- An encodable type is equivalent to the range of its encoding function. -/
def equivRangeEncode (α : Type*) [Encodable α] : α ≃ Set.range (@encode α _) where
toFun := fun a : α => ⟨encode a, Set.mem_range_self _⟩
invFun n :=
Option.get _
(show isSome (decode₂ α n.1) by cases' n.2 with x hx; rw [← hx, encodek₂]; exact rfl)
left_inv a := by dsimp; rw [← Option.some_inj, Option.some_get, encodek₂]
right_inv := fun ⟨n, x, hx⟩ => by
apply Subtype.eq
dsimp
conv =>
rhs
rw [← hx]
rw [encode_injective.eq_iff, ← Option.some_inj, Option.some_get, ← hx, encodek₂]
#align encodable.equiv_range_encode Encodable.equivRangeEncode
/-- A type with unique element is encodable. This is not an instance to avoid diamonds. -/
def _root_.Unique.encodable [Unique α] : Encodable α :=
⟨fun _ => 0, fun _ => some default, Unique.forall_iff.2 rfl⟩
#align unique.encodable Unique.encodable
section Sum
variable [Encodable α] [Encodable β]
-- Porting note: removing bit0 and bit1
/-- Explicit encoding function for the sum of two encodable types. -/
def encodeSum : Sum α β → ℕ
| Sum.inl a => 2 * encode a
| Sum.inr b => 2 * encode b + 1
#align encodable.encode_sum Encodable.encodeSum
/-- Explicit decoding function for the sum of two encodable types. -/
def decodeSum (n : ℕ) : Option (Sum α β) :=
match boddDiv2 n with
| (false, m) => (decode m : Option α).map Sum.inl
| (_, m) => (decode m : Option β).map Sum.inr
#align encodable.decode_sum Encodable.decodeSum
/-- If `α` and `β` are encodable, then so is their sum. -/
instance _root_.Sum.encodable : Encodable (Sum α β) :=
⟨encodeSum, decodeSum, fun s => by cases s <;> simp [encodeSum, div2_val, decodeSum, encodek]⟩
#align sum.encodable Sum.encodable
-- Porting note: removing bit0 and bit1 from statement
@[simp]
theorem encode_inl (a : α) : @encode (Sum α β) _ (Sum.inl a) = 2 * (encode a) :=
rfl
#align encodable.encode_inl Encodable.encode_inlₓ
-- Porting note: removing bit0 and bit1 from statement
@[simp]
theorem encode_inr (b : β) : @encode (Sum α β) _ (Sum.inr b) = 2 * (encode b) + 1 :=
rfl
#align encodable.encode_inr Encodable.encode_inrₓ
@[simp]
theorem decode_sum_val (n : ℕ) : (decode n : Option (Sum α β)) = decodeSum n :=
rfl
#align encodable.decode_sum_val Encodable.decode_sum_val
end Sum
instance _root_.Bool.encodable : Encodable Bool :=
ofEquiv (Sum Unit Unit) Equiv.boolEquivPUnitSumPUnit
#align bool.encodable Bool.encodable
@[simp]
theorem encode_true : encode true = 1 :=
rfl
#align encodable.encode_tt Encodable.encode_true
@[simp]
theorem encode_false : encode false = 0 :=
rfl
#align encodable.encode_ff Encodable.encode_false
@[simp]
theorem decode_zero : (decode 0 : Option Bool) = some false :=
rfl
#align encodable.decode_zero Encodable.decode_zero
@[simp]
theorem decode_one : (decode 1 : Option Bool) = some true :=
rfl
#align encodable.decode_one Encodable.decode_one
theorem decode_ge_two (n) (h : 2 ≤ n) : (decode n : Option Bool) = none := by
suffices decodeSum n = none by
change (decodeSum n).bind _ = none
rw [this]
rfl
have : 1 ≤ n / 2 := by
rw [Nat.le_div_iff_mul_le]
exacts [h, by decide]
cases' exists_eq_succ_of_ne_zero (_root_.ne_of_gt this) with m e
simp only [decodeSum, boddDiv2_eq, div2_val]; cases bodd n <;> simp [e]
#align encodable.decode_ge_two Encodable.decode_ge_two
noncomputable instance _root_.Prop.encodable : Encodable Prop :=
ofEquiv Bool Equiv.propEquivBool
#align Prop.encodable Prop.encodable
section Sigma
variable {γ : α → Type*} [Encodable α] [∀ a, Encodable (γ a)]
/-- Explicit encoding function for `Sigma γ` -/
def encodeSigma : Sigma γ → ℕ
| ⟨a, b⟩ => pair (encode a) (encode b)
#align encodable.encode_sigma Encodable.encodeSigma
/-- Explicit decoding function for `Sigma γ` -/
def decodeSigma (n : ℕ) : Option (Sigma γ) :=
let (n₁, n₂) := unpair n
(decode n₁).bind fun a => (decode n₂).map <| Sigma.mk a
#align encodable.decode_sigma Encodable.decodeSigma
instance _root_.Sigma.encodable : Encodable (Sigma γ) :=
⟨encodeSigma, decodeSigma, fun ⟨a, b⟩ => by
simp [encodeSigma, decodeSigma, unpair_pair, encodek]⟩
#align sigma.encodable Sigma.encodable
@[simp]
theorem decode_sigma_val (n : ℕ) :
(decode n : Option (Sigma γ)) =
(decode n.unpair.1).bind fun a => (decode n.unpair.2).map <| Sigma.mk a :=
rfl
#align encodable.decode_sigma_val Encodable.decode_sigma_val
@[simp]
theorem encode_sigma_val (a b) : @encode (Sigma γ) _ ⟨a, b⟩ = pair (encode a) (encode b) :=
rfl
#align encodable.encode_sigma_val Encodable.encode_sigma_val
end Sigma
section Prod
variable [Encodable α] [Encodable β]
/-- If `α` and `β` are encodable, then so is their product. -/
instance Prod.encodable : Encodable (α × β) :=
ofEquiv _ (Equiv.sigmaEquivProd α β).symm
@[simp]
| Mathlib/Logic/Encodable/Basic.lean | 385 | 390 | theorem decode_prod_val [i : Encodable α] (n : ℕ) :
(@decode (α × β) _ n : Option (α × β))
= (decode n.unpair.1).bind fun a => (decode n.unpair.2).map <| Prod.mk a := by |
simp only [decode_ofEquiv, Equiv.symm_symm, decode_sigma_val]
cases (decode n.unpair.1 : Option α) <;> cases (decode n.unpair.2 : Option β)
<;> rfl
|
/-
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.Analysis.NormedSpace.Multilinear.Basic
#align_import analysis.normed_space.multilinear from "leanprover-community/mathlib"@"f40476639bac089693a489c9e354ebd75dc0f886"
/-!
# Currying and uncurrying continuous multilinear maps
We associate to a continuous multilinear map in `n+1` variables (i.e., based on `Fin n.succ`) two
curried functions, named `f.curryLeft` (which is a continuous linear map on `E 0` taking values
in continuous multilinear maps in `n` variables) and `f.curryRight` (which is a continuous
multilinear map in `n` variables taking values in continuous linear maps on `E (last n)`).
The inverse operations are called `uncurryLeft` and `uncurryRight`.
We also register continuous linear equiv versions of these correspondences, in
`continuousMultilinearCurryLeftEquiv` and `continuousMultilinearCurryRightEquiv`.
## Main results
* `ContinuousMultilinearMap.curryLeft`, `ContinuousLinearMap.uncurryLeft` and
`continuousMultilinearCurryLeftEquiv`
* `ContinuousMultilinearMap.curryRight`, `ContinuousMultilinearMap.uncurryRight` and
`continuousMultilinearCurryRightEquiv`.
-/
suppress_compilation
noncomputable section
open NNReal Finset Metric ContinuousMultilinearMap Fin Function
/-!
### Type variables
We use the following type variables in this file:
* `𝕜` : a `NontriviallyNormedField`;
* `ι`, `ι'` : finite index types with decidable equality;
* `E`, `E₁` : families of normed vector spaces over `𝕜` indexed by `i : ι`;
* `E'` : a family of normed vector spaces over `𝕜` indexed by `i' : ι'`;
* `Ei` : a family of normed vector spaces over `𝕜` indexed by `i : Fin (Nat.succ n)`;
* `G`, `G'` : normed vector spaces over `𝕜`.
-/
universe u v v' wE wE₁ wE' wEi wG wG'
variable {𝕜 : Type u} {ι : Type v} {ι' : Type v'} {n : ℕ} {E : ι → Type wE} {E₁ : ι → Type wE₁}
{E' : ι' → Type wE'} {Ei : Fin n.succ → Type wEi} {G : Type wG} {G' : Type wG'} [Fintype ι]
[Fintype ι'] [NontriviallyNormedField 𝕜] [∀ i, NormedAddCommGroup (E i)]
[∀ i, NormedSpace 𝕜 (E i)] [∀ i, NormedAddCommGroup (E₁ i)] [∀ i, NormedSpace 𝕜 (E₁ i)]
[∀ i, NormedAddCommGroup (E' i)] [∀ i, NormedSpace 𝕜 (E' i)] [∀ i, NormedAddCommGroup (Ei i)]
[∀ i, NormedSpace 𝕜 (Ei i)] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup G']
[NormedSpace 𝕜 G']
theorem ContinuousLinearMap.norm_map_tail_le
(f : Ei 0 →L[𝕜] ContinuousMultilinearMap 𝕜 (fun i : Fin n => Ei i.succ) G) (m : ∀ i, Ei i) :
‖f (m 0) (tail m)‖ ≤ ‖f‖ * ∏ i, ‖m i‖ :=
calc
‖f (m 0) (tail m)‖ ≤ ‖f (m 0)‖ * ∏ i, ‖(tail m) i‖ := (f (m 0)).le_opNorm _
_ ≤ ‖f‖ * ‖m 0‖ * ∏ i, ‖tail m i‖ := mul_le_mul_of_nonneg_right (f.le_opNorm _) <| by positivity
_ = ‖f‖ * (‖m 0‖ * ∏ i, ‖(tail m) i‖) := by ring
_ = ‖f‖ * ∏ i, ‖m i‖ := by
rw [prod_univ_succ]
rfl
#align continuous_linear_map.norm_map_tail_le ContinuousLinearMap.norm_map_tail_le
theorem ContinuousMultilinearMap.norm_map_init_le
(f : ContinuousMultilinearMap 𝕜 (fun i : Fin n => Ei <| castSucc i) (Ei (last n) →L[𝕜] G))
(m : ∀ i, Ei i) : ‖f (init m) (m (last n))‖ ≤ ‖f‖ * ∏ i, ‖m i‖ :=
calc
‖f (init m) (m (last n))‖ ≤ ‖f (init m)‖ * ‖m (last n)‖ := (f (init m)).le_opNorm _
_ ≤ (‖f‖ * ∏ i, ‖(init m) i‖) * ‖m (last n)‖ :=
(mul_le_mul_of_nonneg_right (f.le_opNorm _) (norm_nonneg _))
_ = ‖f‖ * ((∏ i, ‖(init m) i‖) * ‖m (last n)‖) := mul_assoc _ _ _
_ = ‖f‖ * ∏ i, ‖m i‖ := by
rw [prod_univ_castSucc]
rfl
#align continuous_multilinear_map.norm_map_init_le ContinuousMultilinearMap.norm_map_init_le
| Mathlib/Analysis/NormedSpace/Multilinear/Curry.lean | 86 | 92 | theorem ContinuousMultilinearMap.norm_map_cons_le (f : ContinuousMultilinearMap 𝕜 Ei G) (x : Ei 0)
(m : ∀ i : Fin n, Ei i.succ) : ‖f (cons x m)‖ ≤ ‖f‖ * ‖x‖ * ∏ i, ‖m i‖ :=
calc
‖f (cons x m)‖ ≤ ‖f‖ * ∏ i, ‖cons x m i‖ := f.le_opNorm _
_ = ‖f‖ * ‖x‖ * ∏ i, ‖m i‖ := by |
rw [prod_univ_succ]
simp [mul_assoc]
|
/-
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.GroupPower.IterateHom
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Data.List.Cycle
import Mathlib.Data.Nat.Prime
import Mathlib.Data.PNat.Basic
import Mathlib.Dynamics.FixedPoints.Basic
import Mathlib.GroupTheory.GroupAction.Group
#align_import dynamics.periodic_pts from "leanprover-community/mathlib"@"d07245fd37786daa997af4f1a73a49fa3b748408"
/-!
# Periodic points
A point `x : α` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`.
## Main definitions
* `IsPeriodicPt f n x` : `x` is a periodic point of `f` of period `n`, i.e. `f^[n] x = x`.
We do not require `n > 0` in the definition.
* `ptsOfPeriod f n` : the set `{x | IsPeriodicPt f n x}`. Note that `n` is not required to
be the minimal period of `x`.
* `periodicPts f` : the set of all periodic points of `f`.
* `minimalPeriod f x` : the minimal period of a point `x` under an endomorphism `f` or zero
if `x` is not a periodic point of `f`.
* `orbit f x`: the cycle `[x, f x, f (f x), ...]` for a periodic point.
* `MulAction.period g x` : the minimal period of a point `x` under the multiplicative action of `g`;
an equivalent `AddAction.period g x` is defined for additive actions.
## Main statements
We provide “dot syntax”-style operations on terms of the form `h : IsPeriodicPt f n x` including
arithmetic operations on `n` and `h.map (hg : SemiconjBy g f f')`. We also prove that `f`
is bijective on each set `ptsOfPeriod f n` and on `periodicPts f`. Finally, we prove that `x`
is a periodic point of `f` of period `n` if and only if `minimalPeriod f x | n`.
## References
* https://en.wikipedia.org/wiki/Periodic_point
-/
open Set
namespace Function
open Function (Commute)
variable {α : Type*} {β : Type*} {f fa : α → α} {fb : β → β} {x y : α} {m n : ℕ}
/-- A point `x` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`.
Note that we do not require `0 < n` in this definition. Many theorems about periodic points
need this assumption. -/
def IsPeriodicPt (f : α → α) (n : ℕ) (x : α) :=
IsFixedPt f^[n] x
#align function.is_periodic_pt Function.IsPeriodicPt
/-- A fixed point of `f` is a periodic point of `f` of any prescribed period. -/
theorem IsFixedPt.isPeriodicPt (hf : IsFixedPt f x) (n : ℕ) : IsPeriodicPt f n x :=
hf.iterate n
#align function.is_fixed_pt.is_periodic_pt Function.IsFixedPt.isPeriodicPt
/-- For the identity map, all points are periodic. -/
theorem is_periodic_id (n : ℕ) (x : α) : IsPeriodicPt id n x :=
(isFixedPt_id x).isPeriodicPt n
#align function.is_periodic_id Function.is_periodic_id
/-- Any point is a periodic point of period `0`. -/
theorem isPeriodicPt_zero (f : α → α) (x : α) : IsPeriodicPt f 0 x :=
isFixedPt_id x
#align function.is_periodic_pt_zero Function.isPeriodicPt_zero
namespace IsPeriodicPt
instance [DecidableEq α] {f : α → α} {n : ℕ} {x : α} : Decidable (IsPeriodicPt f n x) :=
IsFixedPt.decidable
protected theorem isFixedPt (hf : IsPeriodicPt f n x) : IsFixedPt f^[n] x :=
hf
#align function.is_periodic_pt.is_fixed_pt Function.IsPeriodicPt.isFixedPt
protected theorem map (hx : IsPeriodicPt fa n x) {g : α → β} (hg : Semiconj g fa fb) :
IsPeriodicPt fb n (g x) :=
IsFixedPt.map hx (hg.iterate_right n)
#align function.is_periodic_pt.map Function.IsPeriodicPt.map
theorem apply_iterate (hx : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f n (f^[m] x) :=
hx.map <| Commute.iterate_self f m
#align function.is_periodic_pt.apply_iterate Function.IsPeriodicPt.apply_iterate
protected theorem apply (hx : IsPeriodicPt f n x) : IsPeriodicPt f n (f x) :=
hx.apply_iterate 1
#align function.is_periodic_pt.apply Function.IsPeriodicPt.apply
protected theorem add (hn : IsPeriodicPt f n x) (hm : IsPeriodicPt f m x) :
IsPeriodicPt f (n + m) x := by
rw [IsPeriodicPt, iterate_add]
exact hn.comp hm
#align function.is_periodic_pt.add Function.IsPeriodicPt.add
theorem left_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f m x) :
IsPeriodicPt f n x := by
rw [IsPeriodicPt, iterate_add] at hn
exact hn.left_of_comp hm
#align function.is_periodic_pt.left_of_add Function.IsPeriodicPt.left_of_add
theorem right_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f n x) :
IsPeriodicPt f m x := by
rw [add_comm] at hn
exact hn.left_of_add hm
#align function.is_periodic_pt.right_of_add Function.IsPeriodicPt.right_of_add
protected theorem sub (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) :
IsPeriodicPt f (m - n) x := by
rcases le_total n m with h | h
· refine left_of_add ?_ hn
rwa [tsub_add_cancel_of_le h]
· rw [tsub_eq_zero_iff_le.mpr h]
apply isPeriodicPt_zero
#align function.is_periodic_pt.sub Function.IsPeriodicPt.sub
protected theorem mul_const (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (m * n) x := by
simp only [IsPeriodicPt, iterate_mul, hm.isFixedPt.iterate n]
#align function.is_periodic_pt.mul_const Function.IsPeriodicPt.mul_const
protected theorem const_mul (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (n * m) x := by
simp only [mul_comm n, hm.mul_const n]
#align function.is_periodic_pt.const_mul Function.IsPeriodicPt.const_mul
theorem trans_dvd (hm : IsPeriodicPt f m x) {n : ℕ} (hn : m ∣ n) : IsPeriodicPt f n x :=
let ⟨k, hk⟩ := hn
hk.symm ▸ hm.mul_const k
#align function.is_periodic_pt.trans_dvd Function.IsPeriodicPt.trans_dvd
protected theorem iterate (hf : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f^[m] n x := by
rw [IsPeriodicPt, ← iterate_mul, mul_comm, iterate_mul]
exact hf.isFixedPt.iterate m
#align function.is_periodic_pt.iterate Function.IsPeriodicPt.iterate
theorem comp {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f n x) (hg : IsPeriodicPt g n x) :
IsPeriodicPt (f ∘ g) n x := by
rw [IsPeriodicPt, hco.comp_iterate]
exact IsFixedPt.comp hf hg
#align function.is_periodic_pt.comp Function.IsPeriodicPt.comp
theorem comp_lcm {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f m x)
(hg : IsPeriodicPt g n x) : IsPeriodicPt (f ∘ g) (Nat.lcm m n) x :=
(hf.trans_dvd <| Nat.dvd_lcm_left _ _).comp hco (hg.trans_dvd <| Nat.dvd_lcm_right _ _)
#align function.is_periodic_pt.comp_lcm Function.IsPeriodicPt.comp_lcm
| Mathlib/Dynamics/PeriodicPts.lean | 156 | 159 | theorem left_of_comp {g : α → α} (hco : Commute f g) (hfg : IsPeriodicPt (f ∘ g) n x)
(hg : IsPeriodicPt g n x) : IsPeriodicPt f n x := by |
rw [IsPeriodicPt, hco.comp_iterate] at hfg
exact hfg.left_of_comp hg
|
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Order.ToIntervalMod
import Mathlib.Algebra.Ring.AddAut
import Mathlib.Data.Nat.Totient
import Mathlib.GroupTheory.Divisible
import Mathlib.Topology.Connected.PathConnected
import Mathlib.Topology.IsLocalHomeomorph
#align_import topology.instances.add_circle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec"
/-!
# The additive circle
We define the additive circle `AddCircle p` as the quotient `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`.
See also `Circle` and `Real.angle`. For the normed group structure on `AddCircle`, see
`AddCircle.NormedAddCommGroup` in a later file.
## Main definitions and results:
* `AddCircle`: the additive circle `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`
* `UnitAddCircle`: the special case `ℝ ⧸ ℤ`
* `AddCircle.equivAddCircle`: the rescaling equivalence `AddCircle p ≃+ AddCircle q`
* `AddCircle.equivIco`: the natural equivalence `AddCircle p ≃ Ico a (a + p)`
* `AddCircle.addOrderOf_div_of_gcd_eq_one`: rational points have finite order
* `AddCircle.exists_gcd_eq_one_of_isOfFinAddOrder`: finite-order points are rational
* `AddCircle.homeoIccQuot`: the natural topological equivalence between `AddCircle p` and
`Icc a (a + p)` with its endpoints identified.
* `AddCircle.liftIco_continuous`: if `f : ℝ → B` is continuous, and `f a = f (a + p)` for
some `a`, then there is a continuous function `AddCircle p → B` which agrees with `f` on
`Icc a (a + p)`.
## Implementation notes:
Although the most important case is `𝕜 = ℝ` we wish to support other types of scalars, such as
the rational circle `AddCircle (1 : ℚ)`, and so we set things up more generally.
## TODO
* Link with periodicity
* Lie group structure
* Exponential equivalence to `Circle`
-/
noncomputable section
open AddCommGroup Set Function AddSubgroup TopologicalSpace
open Topology
variable {𝕜 B : Type*}
section Continuity
variable [LinearOrderedAddCommGroup 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜]
{p : 𝕜} (hp : 0 < p) (a x : 𝕜)
theorem continuous_right_toIcoMod : ContinuousWithinAt (toIcoMod hp a) (Ici x) x := by
intro s h
rw [Filter.mem_map, mem_nhdsWithin_iff_exists_mem_nhds_inter]
haveI : Nontrivial 𝕜 := ⟨⟨0, p, hp.ne⟩⟩
simp_rw [mem_nhds_iff_exists_Ioo_subset] at h ⊢
obtain ⟨l, u, hxI, hIs⟩ := h
let d := toIcoDiv hp a x • p
have hd := toIcoMod_mem_Ico hp a x
simp_rw [subset_def, mem_inter_iff]
refine ⟨_, ⟨l + d, min (a + p) u + d, ?_, fun x => id⟩, fun y => ?_⟩ <;>
simp_rw [← sub_mem_Ioo_iff_left, mem_Ioo, lt_min_iff]
· exact ⟨hxI.1, hd.2, hxI.2⟩
· rintro ⟨h, h'⟩
apply hIs
rw [← toIcoMod_sub_zsmul, (toIcoMod_eq_self _).2]
exacts [⟨h.1, h.2.2⟩, ⟨hd.1.trans (sub_le_sub_right h' _), h.2.1⟩]
#align continuous_right_to_Ico_mod continuous_right_toIcoMod
| Mathlib/Topology/Instances/AddCircle.lean | 82 | 89 | theorem continuous_left_toIocMod : ContinuousWithinAt (toIocMod hp a) (Iic x) x := by |
rw [(funext fun y => Eq.trans (by rw [neg_neg]) <| toIocMod_neg _ _ _ :
toIocMod hp a = (fun x => p - x) ∘ toIcoMod hp (-a) ∘ Neg.neg)]
-- Porting note: added
have : ContinuousNeg 𝕜 := TopologicalAddGroup.toContinuousNeg
exact
(continuous_sub_left _).continuousAt.comp_continuousWithinAt <|
(continuous_right_toIcoMod _ _ _).comp continuous_neg.continuousWithinAt fun y => neg_le_neg
|
/-
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.CharP.ExpChar
import Mathlib.Algebra.GeomSum
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.RingTheory.Polynomial.Content
import Mathlib.RingTheory.UniqueFactorizationDomain
#align_import ring_theory.polynomial.basic from "leanprover-community/mathlib"@"da420a8c6dd5bdfb85c4ced85c34388f633bc6ff"
/-!
# Ring-theoretic supplement of Algebra.Polynomial.
## Main results
* `MvPolynomial.isDomain`:
If a ring is an integral domain, then so is its polynomial ring over finitely many variables.
* `Polynomial.isNoetherianRing`:
Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring.
* `Polynomial.wfDvdMonoid`:
If an integral domain is a `WFDvdMonoid`, then so is its polynomial ring.
* `Polynomial.uniqueFactorizationMonoid`, `MvPolynomial.uniqueFactorizationMonoid`:
If an integral domain is a `UniqueFactorizationMonoid`, then so is its polynomial ring (of any
number of variables).
-/
noncomputable section
open Polynomial
open Finset
universe u v w
variable {R : Type u} {S : Type*}
namespace Polynomial
section Semiring
variable [Semiring R]
instance instCharP (p : ℕ) [h : CharP R p] : CharP R[X] p :=
let ⟨h⟩ := h
⟨fun n => by rw [← map_natCast C, ← C_0, C_inj, h]⟩
instance instExpChar (p : ℕ) [h : ExpChar R p] : ExpChar R[X] p := by
cases h; exacts [ExpChar.zero, ExpChar.prime ‹_›]
variable (R)
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/
def degreeLE (n : WithBot ℕ) : Submodule R R[X] :=
⨅ k : ℕ, ⨅ _ : ↑k > n, LinearMap.ker (lcoeff R k)
#align polynomial.degree_le Polynomial.degreeLE
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/
def degreeLT (n : ℕ) : Submodule R R[X] :=
⨅ k : ℕ, ⨅ (_ : k ≥ n), LinearMap.ker (lcoeff R k)
#align polynomial.degree_lt Polynomial.degreeLT
variable {R}
theorem mem_degreeLE {n : WithBot ℕ} {f : R[X]} : f ∈ degreeLE R n ↔ degree f ≤ n := by
simp only [degreeLE, Submodule.mem_iInf, degree_le_iff_coeff_zero, LinearMap.mem_ker]; rfl
#align polynomial.mem_degree_le Polynomial.mem_degreeLE
@[mono]
theorem degreeLE_mono {m n : WithBot ℕ} (H : m ≤ n) : degreeLE R m ≤ degreeLE R n := fun _ hf =>
mem_degreeLE.2 (le_trans (mem_degreeLE.1 hf) H)
#align polynomial.degree_le_mono Polynomial.degreeLE_mono
theorem degreeLE_eq_span_X_pow [DecidableEq R] {n : ℕ} :
degreeLE R n = Submodule.span R ↑((Finset.range (n + 1)).image fun n => (X : R[X]) ^ n) := by
apply le_antisymm
· intro p hp
replace hp := mem_degreeLE.1 hp
rw [← Polynomial.sum_monomial_eq p, Polynomial.sum]
refine Submodule.sum_mem _ fun k hk => ?_
have := WithBot.coe_le_coe.1 (Finset.sup_le_iff.1 hp k hk)
rw [← C_mul_X_pow_eq_monomial, C_mul']
refine
Submodule.smul_mem _ _
(Submodule.subset_span <|
Finset.mem_coe.2 <|
Finset.mem_image.2 ⟨_, Finset.mem_range.2 (Nat.lt_succ_of_le this), rfl⟩)
rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff]
intro k hk
apply mem_degreeLE.2
exact
(degree_X_pow_le _).trans (WithBot.coe_le_coe.2 <| Nat.le_of_lt_succ <| Finset.mem_range.1 hk)
set_option linter.uppercaseLean3 false in
#align polynomial.degree_le_eq_span_X_pow Polynomial.degreeLE_eq_span_X_pow
theorem mem_degreeLT {n : ℕ} {f : R[X]} : f ∈ degreeLT R n ↔ degree f < n := by
rw [degreeLT, Submodule.mem_iInf]
conv_lhs => intro i; rw [Submodule.mem_iInf]
rw [degree, Finset.max_eq_sup_coe]
rw [Finset.sup_lt_iff ?_]
rotate_left
· apply WithBot.bot_lt_coe
conv_rhs =>
simp only [mem_support_iff]
intro b
rw [Nat.cast_withBot, WithBot.coe_lt_coe, lt_iff_not_le, Ne, not_imp_not]
rfl
#align polynomial.mem_degree_lt Polynomial.mem_degreeLT
@[mono]
theorem degreeLT_mono {m n : ℕ} (H : m ≤ n) : degreeLT R m ≤ degreeLT R n := fun _ hf =>
mem_degreeLT.2 (lt_of_lt_of_le (mem_degreeLT.1 hf) <| WithBot.coe_le_coe.2 H)
#align polynomial.degree_lt_mono Polynomial.degreeLT_mono
theorem degreeLT_eq_span_X_pow [DecidableEq R] {n : ℕ} :
degreeLT R n = Submodule.span R ↑((Finset.range n).image fun n => X ^ n : Finset R[X]) := by
apply le_antisymm
· intro p hp
replace hp := mem_degreeLT.1 hp
rw [← Polynomial.sum_monomial_eq p, Polynomial.sum]
refine Submodule.sum_mem _ fun k hk => ?_
have := WithBot.coe_lt_coe.1 ((Finset.sup_lt_iff <| WithBot.bot_lt_coe n).1 hp k hk)
rw [← C_mul_X_pow_eq_monomial, C_mul']
refine
Submodule.smul_mem _ _
(Submodule.subset_span <|
Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 this, rfl⟩)
rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff]
intro k hk
apply mem_degreeLT.2
exact lt_of_le_of_lt (degree_X_pow_le _) (WithBot.coe_lt_coe.2 <| Finset.mem_range.1 hk)
set_option linter.uppercaseLean3 false in
#align polynomial.degree_lt_eq_span_X_pow Polynomial.degreeLT_eq_span_X_pow
/-- The first `n` coefficients on `degreeLT n` form a linear equivalence with `Fin n → R`. -/
def degreeLTEquiv (R) [Semiring R] (n : ℕ) : degreeLT R n ≃ₗ[R] Fin n → R where
toFun p n := (↑p : R[X]).coeff n
invFun f :=
⟨∑ i : Fin n, monomial i (f i),
(degreeLT R n).sum_mem fun i _ =>
mem_degreeLT.mpr
(lt_of_le_of_lt (degree_monomial_le i (f i)) (WithBot.coe_lt_coe.mpr i.is_lt))⟩
map_add' p q := by
ext
dsimp
rw [coeff_add]
map_smul' x p := by
ext
dsimp
rw [coeff_smul]
rfl
left_inv := by
rintro ⟨p, hp⟩
ext1
simp only [Submodule.coe_mk]
by_cases hp0 : p = 0
· subst hp0
simp only [coeff_zero, LinearMap.map_zero, Finset.sum_const_zero]
rw [mem_degreeLT, degree_eq_natDegree hp0, Nat.cast_lt] at hp
conv_rhs => rw [p.as_sum_range' n hp, ← Fin.sum_univ_eq_sum_range]
right_inv f := by
ext i
simp only [finset_sum_coeff, Submodule.coe_mk]
rw [Finset.sum_eq_single i, coeff_monomial, if_pos rfl]
· rintro j - hji
rw [coeff_monomial, if_neg]
rwa [← Fin.ext_iff]
· intro h
exact (h (Finset.mem_univ _)).elim
#align polynomial.degree_lt_equiv Polynomial.degreeLTEquiv
-- Porting note: removed @[simp] as simp can prove this
theorem degreeLTEquiv_eq_zero_iff_eq_zero {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) :
degreeLTEquiv _ _ ⟨p, hp⟩ = 0 ↔ p = 0 := by
rw [LinearEquiv.map_eq_zero_iff, Submodule.mk_eq_zero]
#align polynomial.degree_lt_equiv_eq_zero_iff_eq_zero Polynomial.degreeLTEquiv_eq_zero_iff_eq_zero
theorem eval_eq_sum_degreeLTEquiv {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) (x : R) :
p.eval x = ∑ i, degreeLTEquiv _ _ ⟨p, hp⟩ i * x ^ (i : ℕ) := by
simp_rw [eval_eq_sum]
exact (sum_fin _ (by simp_rw [zero_mul, forall_const]) (mem_degreeLT.mp hp)).symm
#align polynomial.eval_eq_sum_degree_lt_equiv Polynomial.eval_eq_sum_degreeLTEquiv
theorem degreeLT_succ_eq_degreeLE {n : ℕ} : degreeLT R (n + 1) = degreeLE R n := by
ext x
by_cases x_zero : x = 0
· simp_rw [x_zero, Submodule.zero_mem]
· rw [mem_degreeLT, mem_degreeLE, ← natDegree_lt_iff_degree_lt (by rwa [ne_eq]),
← natDegree_le_iff_degree_le, Nat.lt_succ]
/-- For every polynomial `p` in the span of a set `s : Set R[X]`, there exists a polynomial of
`p' ∈ s` with higher degree. See also `Polynomial.exists_degree_le_of_mem_span_of_finite`. -/
theorem exists_degree_le_of_mem_span {s : Set R[X]} {p : R[X]}
(hs : s.Nonempty) (hp : p ∈ Submodule.span R s) :
∃ p' ∈ s, degree p ≤ degree p' := by
by_contra! h
by_cases hp_zero : p = 0
· rw [hp_zero, degree_zero] at h
rcases hs with ⟨x, hx⟩
exact not_lt_bot (h x hx)
· have : p ∈ degreeLT R (natDegree p) := by
refine (Submodule.span_le.mpr fun p' p'_mem => ?_) hp
rw [SetLike.mem_coe, mem_degreeLT, Nat.cast_withBot]
exact lt_of_lt_of_le (h p' p'_mem) degree_le_natDegree
rwa [mem_degreeLT, Nat.cast_withBot, degree_eq_natDegree hp_zero,
Nat.cast_withBot, lt_self_iff_false] at this
/-- A stronger version of `Polynomial.exists_degree_le_of_mem_span` under the assumption that the
set `s : R[X]` is finite. There exists a polynomial `p' ∈ s` whose degree dominates the degree of
every element of `p ∈ span R s`-/
theorem exists_degree_le_of_mem_span_of_finite {s : Set R[X]} (s_fin : s.Finite) (hs : s.Nonempty) :
∃ p' ∈ s, ∀ (p : R[X]), p ∈ Submodule.span R s → degree p ≤ degree p' := by
rcases Set.Finite.exists_maximal_wrt degree s s_fin hs with ⟨a, has, hmax⟩
refine ⟨a, has, fun p hp => ?_⟩
rcases exists_degree_le_of_mem_span hs hp with ⟨p', hp'⟩
by_cases h : degree a ≤ degree p'
· rw [← hmax p' hp'.left h] at hp'; exact hp'.right
· exact le_trans hp'.right (not_le.mp h).le
/-- The span of every finite set of polynomials is contained in a `degreeLE n` for some `n`. -/
theorem span_le_degreeLE_of_finite {s : Set R[X]} (s_fin : s.Finite) :
∃ n : ℕ, Submodule.span R s ≤ degreeLE R n := by
by_cases s_emp : s.Nonempty
· rcases exists_degree_le_of_mem_span_of_finite s_fin s_emp with ⟨p', _, hp'max⟩
exact ⟨natDegree p', fun p hp => mem_degreeLE.mpr ((hp'max _ hp).trans degree_le_natDegree)⟩
· rw [Set.not_nonempty_iff_eq_empty] at s_emp
rw [s_emp, Submodule.span_empty]
exact ⟨0, bot_le⟩
/-- The span of every finite set of polynomials is contained in a `degreeLT n` for some `n`. -/
theorem span_of_finite_le_degreeLT {s : Set R[X]} (s_fin : s.Finite) :
∃ n : ℕ, Submodule.span R s ≤ degreeLT R n := by
rcases span_le_degreeLE_of_finite s_fin with ⟨n, _⟩
exact ⟨n + 1, by rwa [degreeLT_succ_eq_degreeLE]⟩
/-- If `R` is a nontrivial ring, the polynomials `R[X]` are not finite as an `R`-module. When `R` is
a field, this is equivalent to `R[X]` being an infinite-dimensional vector space over `R`. -/
theorem not_finite [Nontrivial R] : ¬ Module.Finite R R[X] := by
rw [Module.finite_def, Submodule.fg_def]
push_neg
intro s hs contra
rcases span_le_degreeLE_of_finite hs with ⟨n,hn⟩
have : ((X : R[X]) ^ (n + 1)) ∈ Polynomial.degreeLE R ↑n := by
rw [contra] at hn
exact hn Submodule.mem_top
rw [mem_degreeLE, degree_X_pow, Nat.cast_le, add_le_iff_nonpos_right, nonpos_iff_eq_zero] at this
exact one_ne_zero this
/-- The finset of nonzero coefficients of a polynomial. -/
def coeffs (p : R[X]) : Finset R :=
letI := Classical.decEq R
Finset.image (fun n => p.coeff n) p.support
#align polynomial.frange Polynomial.coeffs
@[deprecated (since := "2024-05-17")] noncomputable alias frange := coeffs
theorem coeffs_zero : coeffs (0 : R[X]) = ∅ :=
rfl
#align polynomial.frange_zero Polynomial.coeffs_zero
@[deprecated (since := "2024-05-17")] alias frange_zero := coeffs_zero
theorem mem_coeffs_iff {p : R[X]} {c : R} : c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by
simp [coeffs, eq_comm, (Finset.mem_image)]
#align polynomial.mem_frange_iff Polynomial.mem_coeffs_iff
@[deprecated (since := "2024-05-17")] alias mem_frange_iff := mem_coeffs_iff
theorem coeffs_one : coeffs (1 : R[X]) ⊆ {1} := by
classical
simp_rw [coeffs, Finset.image_subset_iff]
simp_all [coeff_one]
#align polynomial.frange_one Polynomial.coeffs_one
@[deprecated (since := "2024-05-17")] alias frange_one := coeffs_one
theorem coeff_mem_coeffs (p : R[X]) (n : ℕ) (h : p.coeff n ≠ 0) : p.coeff n ∈ p.coeffs := by
classical
simp only [coeffs, exists_prop, mem_support_iff, Finset.mem_image, Ne]
exact ⟨n, h, rfl⟩
#align polynomial.coeff_mem_frange Polynomial.coeff_mem_coeffs
@[deprecated (since := "2024-05-17")] alias coeff_mem_frange := coeff_mem_coeffs
theorem geom_sum_X_comp_X_add_one_eq_sum (n : ℕ) :
(∑ i ∈ range n, (X : R[X]) ^ i).comp (X + 1) =
(Finset.range n).sum fun i : ℕ => (n.choose (i + 1) : R[X]) * X ^ i := by
ext i
trans (n.choose (i + 1) : R); swap
· simp only [finset_sum_coeff, ← C_eq_natCast, coeff_C_mul_X_pow]
rw [Finset.sum_eq_single i, if_pos rfl]
· simp (config := { contextual := true }) only [@eq_comm _ i, if_false, eq_self_iff_true,
imp_true_iff]
· simp (config := { contextual := true }) only [Nat.lt_add_one_iff, Nat.choose_eq_zero_of_lt,
Nat.cast_zero, Finset.mem_range, not_lt, eq_self_iff_true, if_true, imp_true_iff]
induction' n with n ih generalizing i
· dsimp; simp only [zero_comp, coeff_zero, Nat.cast_zero]
· simp only [geom_sum_succ', ih, add_comp, X_pow_comp, coeff_add, Nat.choose_succ_succ,
Nat.cast_add, coeff_X_add_one_pow]
set_option linter.uppercaseLean3 false in
#align polynomial.geom_sum_X_comp_X_add_one_eq_sum Polynomial.geom_sum_X_comp_X_add_one_eq_sum
theorem Monic.geom_sum {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.natDegree) {n : ℕ} (hn : n ≠ 0) :
(∑ i ∈ range n, P ^ i).Monic := by
nontriviality R
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn
rw [geom_sum_succ']
refine (hP.pow _).add_of_left ?_
refine lt_of_le_of_lt (degree_sum_le _ _) ?_
rw [Finset.sup_lt_iff]
· simp only [Finset.mem_range, degree_eq_natDegree (hP.pow _).ne_zero]
simp only [Nat.cast_lt, hP.natDegree_pow]
intro k
exact nsmul_lt_nsmul_left hdeg
· rw [bot_lt_iff_ne_bot, Ne, degree_eq_bot]
exact (hP.pow _).ne_zero
#align polynomial.monic.geom_sum Polynomial.Monic.geom_sum
theorem Monic.geom_sum' {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.degree) {n : ℕ} (hn : n ≠ 0) :
(∑ i ∈ range n, P ^ i).Monic :=
hP.geom_sum (natDegree_pos_iff_degree_pos.2 hdeg) hn
#align polynomial.monic.geom_sum' Polynomial.Monic.geom_sum'
theorem monic_geom_sum_X {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, (X : R[X]) ^ i).Monic := by
nontriviality R
apply monic_X.geom_sum _ hn
simp only [natDegree_X, zero_lt_one]
set_option linter.uppercaseLean3 false in
#align polynomial.monic_geom_sum_X Polynomial.monic_geom_sum_X
end Semiring
section Ring
variable [Ring R]
/-- Given a polynomial, return the polynomial whose coefficients are in
the ring closure of the original coefficients. -/
def restriction (p : R[X]) : Polynomial (Subring.closure (↑p.coeffs : Set R)) :=
∑ i ∈ p.support,
monomial i
(⟨p.coeff i,
letI := Classical.decEq R
if H : p.coeff i = 0 then H.symm ▸ (Subring.closure _).zero_mem
else Subring.subset_closure (p.coeff_mem_coeffs _ H)⟩ :
Subring.closure (↑p.coeffs : Set R))
#align polynomial.restriction Polynomial.restriction
@[simp]
theorem coeff_restriction {p : R[X]} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := by
classical
simp only [restriction, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
Ne, ite_not]
split_ifs with h
· rw [h]
rfl
· rfl
#align polynomial.coeff_restriction Polynomial.coeff_restriction
-- Porting note: removed @[simp] as simp can prove this
theorem coeff_restriction' {p : R[X]} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n :=
coeff_restriction
#align polynomial.coeff_restriction' Polynomial.coeff_restriction'
@[simp]
theorem support_restriction (p : R[X]) : support (restriction p) = support p := by
ext i
simp only [mem_support_iff, not_iff_not, Ne]
conv_rhs => rw [← coeff_restriction]
exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩
#align polynomial.support_restriction Polynomial.support_restriction
@[simp]
theorem map_restriction {R : Type u} [CommRing R] (p : R[X]) :
p.restriction.map (algebraMap _ _) = p :=
ext fun n => by rw [coeff_map, Algebra.algebraMap_ofSubring_apply, coeff_restriction]
#align polynomial.map_restriction Polynomial.map_restriction
@[simp]
theorem degree_restriction {p : R[X]} : (restriction p).degree = p.degree := by simp [degree]
#align polynomial.degree_restriction Polynomial.degree_restriction
@[simp]
theorem natDegree_restriction {p : R[X]} : (restriction p).natDegree = p.natDegree := by
simp [natDegree]
#align polynomial.nat_degree_restriction Polynomial.natDegree_restriction
@[simp]
theorem monic_restriction {p : R[X]} : Monic (restriction p) ↔ Monic p := by
simp only [Monic, leadingCoeff, natDegree_restriction]
rw [← @coeff_restriction _ _ p]
exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩
#align polynomial.monic_restriction Polynomial.monic_restriction
@[simp]
theorem restriction_zero : restriction (0 : R[X]) = 0 := by
simp only [restriction, Finset.sum_empty, support_zero]
#align polynomial.restriction_zero Polynomial.restriction_zero
@[simp]
theorem restriction_one : restriction (1 : R[X]) = 1 :=
ext fun i => Subtype.eq <| by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs <;> rfl
#align polynomial.restriction_one Polynomial.restriction_one
variable [Semiring S] {f : R →+* S} {x : S}
theorem eval₂_restriction {p : R[X]} :
eval₂ f x p =
eval₂ (f.comp (Subring.subtype (Subring.closure (p.coeffs : Set R)))) x p.restriction := by
simp only [eval₂_eq_sum, sum, support_restriction, ← @coeff_restriction _ _ p, RingHom.comp_apply,
Subring.coeSubtype]
#align polynomial.eval₂_restriction Polynomial.eval₂_restriction
section ToSubring
variable (p : R[X]) (T : Subring R)
/-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`,
return the corresponding polynomial whose coefficients are in `T`. -/
def toSubring (hp : (↑p.coeffs : Set R) ⊆ T) : T[X] :=
∑ i ∈ p.support,
monomial i
(⟨p.coeff i,
letI := Classical.decEq R
if H : p.coeff i = 0 then H.symm ▸ T.zero_mem else hp (p.coeff_mem_coeffs _ H)⟩ : T)
#align polynomial.to_subring Polynomial.toSubring
variable (hp : (↑p.coeffs : Set R) ⊆ T)
@[simp]
theorem coeff_toSubring {n : ℕ} : ↑(coeff (toSubring p T hp) n) = coeff p n := by
classical
simp only [toSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
Ne, ite_not]
split_ifs with h
· rw [h]
rfl
· rfl
#align polynomial.coeff_to_subring Polynomial.coeff_toSubring
-- Porting note: removed @[simp] as simp can prove this
theorem coeff_toSubring' {n : ℕ} : (coeff (toSubring p T hp) n).1 = coeff p n :=
coeff_toSubring _ _ hp
#align polynomial.coeff_to_subring' Polynomial.coeff_toSubring'
@[simp]
theorem support_toSubring : support (toSubring p T hp) = support p := by
ext i
simp only [mem_support_iff, not_iff_not, Ne]
conv_rhs => rw [← coeff_toSubring p T hp]
exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩
#align polynomial.support_to_subring Polynomial.support_toSubring
@[simp]
theorem degree_toSubring : (toSubring p T hp).degree = p.degree := by simp [degree]
#align polynomial.degree_to_subring Polynomial.degree_toSubring
@[simp]
theorem natDegree_toSubring : (toSubring p T hp).natDegree = p.natDegree := by simp [natDegree]
#align polynomial.nat_degree_to_subring Polynomial.natDegree_toSubring
@[simp]
theorem monic_toSubring : Monic (toSubring p T hp) ↔ Monic p := by
simp_rw [Monic, leadingCoeff, natDegree_toSubring, ← coeff_toSubring p T hp]
exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩
#align polynomial.monic_to_subring Polynomial.monic_toSubring
@[simp]
theorem toSubring_zero : toSubring (0 : R[X]) T (by simp [coeffs]) = 0 := by
ext i
simp
#align polynomial.to_subring_zero Polynomial.toSubring_zero
@[simp]
theorem toSubring_one :
toSubring (1 : R[X]) T
(Set.Subset.trans coeffs_one <| Finset.singleton_subset_set_iff.2 T.one_mem) =
1 :=
ext fun i => Subtype.eq <| by
rw [coeff_toSubring', coeff_one, coeff_one, apply_ite Subtype.val, ZeroMemClass.coe_zero,
OneMemClass.coe_one]
#align polynomial.to_subring_one Polynomial.toSubring_one
@[simp]
theorem map_toSubring : (p.toSubring T hp).map (Subring.subtype T) = p := by
ext n
simp [coeff_map]
#align polynomial.map_to_subring Polynomial.map_toSubring
end ToSubring
variable (T : Subring R)
/-- Given a polynomial whose coefficients are in some subring, return
the corresponding polynomial whose coefficients are in the ambient ring. -/
def ofSubring (p : T[X]) : R[X] :=
∑ i ∈ p.support, monomial i (p.coeff i : R)
#align polynomial.of_subring Polynomial.ofSubring
theorem coeff_ofSubring (p : T[X]) (n : ℕ) : coeff (ofSubring T p) n = (coeff p n : T) := by
simp only [ofSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
ite_eq_right_iff, Ne, ite_not, Classical.not_not, ite_eq_left_iff]
intro h
rw [h, ZeroMemClass.coe_zero]
#align polynomial.coeff_of_subring Polynomial.coeff_ofSubring
@[simp]
theorem coeffs_ofSubring {p : T[X]} : (↑(p.ofSubring T).coeffs : Set R) ⊆ T := by
classical
intro i hi
simp only [coeffs, Set.mem_image, mem_support_iff, Ne, Finset.mem_coe,
(Finset.coe_image)] at hi
rcases hi with ⟨n, _, h'n⟩
rw [← h'n, coeff_ofSubring]
exact Subtype.mem (coeff p n : T)
#align polynomial.frange_of_subring Polynomial.coeffs_ofSubring
@[deprecated (since := "2024-05-17")] alias frange_ofSubring := coeffs_ofSubring
end Ring
section CommRing
variable [CommRing R]
section ModByMonic
variable {q : R[X]}
theorem mem_ker_modByMonic (hq : q.Monic) {p : R[X]} :
p ∈ LinearMap.ker (modByMonicHom q) ↔ q ∣ p :=
LinearMap.mem_ker.trans (modByMonic_eq_zero_iff_dvd hq)
#align polynomial.mem_ker_mod_by_monic Polynomial.mem_ker_modByMonic
@[simp]
theorem ker_modByMonicHom (hq : q.Monic) :
LinearMap.ker (Polynomial.modByMonicHom q) = (Ideal.span {q}).restrictScalars R :=
Submodule.ext fun _ => (mem_ker_modByMonic hq).trans Ideal.mem_span_singleton.symm
#align polynomial.ker_mod_by_monic_hom Polynomial.ker_modByMonicHom
end ModByMonic
end CommRing
end Polynomial
namespace Ideal
open Polynomial
section Semiring
variable [Semiring R]
/-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/
def ofPolynomial (I : Ideal R[X]) : Submodule R R[X] where
carrier := I.carrier
zero_mem' := I.zero_mem
add_mem' := I.add_mem
smul_mem' c x H := by
rw [← C_mul']
exact I.mul_mem_left _ H
#align ideal.of_polynomial Ideal.ofPolynomial
variable {I : Ideal R[X]}
theorem mem_ofPolynomial (x) : x ∈ I.ofPolynomial ↔ x ∈ I :=
Iff.rfl
#align ideal.mem_of_polynomial Ideal.mem_ofPolynomial
variable (I)
/-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I`
consisting of polynomials of degree ≤ `n`. -/
def degreeLE (n : WithBot ℕ) : Submodule R R[X] :=
Polynomial.degreeLE R n ⊓ I.ofPolynomial
#align ideal.degree_le Ideal.degreeLE
/-- Given an ideal `I` of `R[X]`, make the ideal in `R` of
leading coefficients of polynomials in `I` with degree ≤ `n`. -/
def leadingCoeffNth (n : ℕ) : Ideal R :=
(I.degreeLE n).map <| lcoeff R n
#align ideal.leading_coeff_nth Ideal.leadingCoeffNth
/-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the
leading coefficients in `I`. -/
def leadingCoeff : Ideal R :=
⨆ n : ℕ, I.leadingCoeffNth n
#align ideal.leading_coeff Ideal.leadingCoeff
end Semiring
section CommSemiring
variable [CommSemiring R] [Semiring S]
/-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself -/
theorem polynomial_mem_ideal_of_coeff_mem_ideal (I : Ideal R[X]) (p : R[X])
(hp : ∀ n : ℕ, p.coeff n ∈ I.comap (C : R →+* R[X])) : p ∈ I :=
sum_C_mul_X_pow_eq p ▸ Submodule.sum_mem I fun n _ => I.mul_mem_right _ (hp n)
#align ideal.polynomial_mem_ideal_of_coeff_mem_ideal Ideal.polynomial_mem_ideal_of_coeff_mem_ideal
/-- The push-forward of an ideal `I` of `R` to `R[X]` via inclusion
is exactly the set of polynomials whose coefficients are in `I` -/
theorem mem_map_C_iff {I : Ideal R} {f : R[X]} :
f ∈ (Ideal.map (C : R →+* R[X]) I : Ideal R[X]) ↔ ∀ n : ℕ, f.coeff n ∈ I := by
constructor
· intro hf
apply @Submodule.span_induction _ _ _ _ _ f _ _ hf
· intro f hf n
cases' (Set.mem_image _ _ _).mp hf with x hx
rw [← hx.right, coeff_C]
by_cases h : n = 0
· simpa [h] using hx.left
· simp [h]
· simp
· exact fun f g hf hg n => by simp [I.add_mem (hf n) (hg n)]
· refine fun f g hg n => ?_
rw [smul_eq_mul, coeff_mul]
exact I.sum_mem fun c _ => I.mul_mem_left (f.coeff c.fst) (hg c.snd)
· intro hf
rw [← sum_monomial_eq f]
refine (I.map C : Ideal R[X]).sum_mem fun n _ => ?_
simp only [← C_mul_X_pow_eq_monomial, ne_eq]
rw [mul_comm]
exact (I.map C : Ideal R[X]).mul_mem_left _ (mem_map_of_mem _ (hf n))
set_option linter.uppercaseLean3 false in
#align ideal.mem_map_C_iff Ideal.mem_map_C_iff
theorem _root_.Polynomial.ker_mapRingHom (f : R →+* S) :
LinearMap.ker (Polynomial.mapRingHom f).toSemilinearMap = f.ker.map (C : R →+* R[X]) := by
ext
simp only [LinearMap.mem_ker, RingHom.toSemilinearMap_apply, coe_mapRingHom]
rw [mem_map_C_iff, Polynomial.ext_iff]
simp_rw [RingHom.mem_ker f]
simp
#align polynomial.ker_map_ring_hom Polynomial.ker_mapRingHom
variable (I : Ideal R[X])
theorem mem_leadingCoeffNth (n : ℕ) (x) :
x ∈ I.leadingCoeffNth n ↔ ∃ p ∈ I, degree p ≤ n ∧ p.leadingCoeff = x := by
simp only [leadingCoeffNth, degreeLE, Submodule.mem_map, lcoeff_apply, Submodule.mem_inf,
mem_degreeLE]
constructor
· rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩
rcases lt_or_eq_of_le hpdeg with hpdeg | hpdeg
· refine ⟨0, I.zero_mem, bot_le, ?_⟩
rw [leadingCoeff_zero, eq_comm]
exact coeff_eq_zero_of_degree_lt hpdeg
· refine ⟨p, hpI, le_of_eq hpdeg, ?_⟩
rw [Polynomial.leadingCoeff, natDegree, hpdeg, Nat.cast_withBot, WithBot.unbot'_coe]
· rintro ⟨p, hpI, hpdeg, rfl⟩
have : natDegree p + (n - natDegree p) = n :=
add_tsub_cancel_of_le (natDegree_le_of_degree_le hpdeg)
refine ⟨p * X ^ (n - natDegree p), ⟨?_, I.mul_mem_right _ hpI⟩, ?_⟩
· apply le_trans (degree_mul_le _ _) _
apply le_trans (add_le_add degree_le_natDegree (degree_X_pow_le _)) _
rw [← Nat.cast_add, this]
· rw [Polynomial.leadingCoeff, ← coeff_mul_X_pow p (n - natDegree p), this]
#align ideal.mem_leading_coeff_nth Ideal.mem_leadingCoeffNth
theorem mem_leadingCoeffNth_zero (x) : x ∈ I.leadingCoeffNth 0 ↔ C x ∈ I :=
(mem_leadingCoeffNth _ _ _).trans
⟨fun ⟨p, hpI, hpdeg, hpx⟩ => by
rwa [← hpx, Polynomial.leadingCoeff,
Nat.eq_zero_of_le_zero (natDegree_le_of_degree_le hpdeg), ← eq_C_of_degree_le_zero hpdeg],
fun hx => ⟨C x, hx, degree_C_le, leadingCoeff_C x⟩⟩
#align ideal.mem_leading_coeff_nth_zero Ideal.mem_leadingCoeffNth_zero
theorem leadingCoeffNth_mono {m n : ℕ} (H : m ≤ n) : I.leadingCoeffNth m ≤ I.leadingCoeffNth n := by
intro r hr
simp only [SetLike.mem_coe, mem_leadingCoeffNth] at hr ⊢
rcases hr with ⟨p, hpI, hpdeg, rfl⟩
refine ⟨p * X ^ (n - m), I.mul_mem_right _ hpI, ?_, leadingCoeff_mul_X_pow⟩
refine le_trans (degree_mul_le _ _) ?_
refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) ?_
rw [← Nat.cast_add, add_tsub_cancel_of_le H]
#align ideal.leading_coeff_nth_mono Ideal.leadingCoeffNth_mono
theorem mem_leadingCoeff (x) : x ∈ I.leadingCoeff ↔ ∃ p ∈ I, Polynomial.leadingCoeff p = x := by
rw [leadingCoeff, Submodule.mem_iSup_of_directed]
· simp only [mem_leadingCoeffNth]
constructor
· rintro ⟨i, p, hpI, _, rfl⟩
exact ⟨p, hpI, rfl⟩
rintro ⟨p, hpI, rfl⟩
exact ⟨natDegree p, p, hpI, degree_le_natDegree, rfl⟩
intro i j
exact
⟨i + j, I.leadingCoeffNth_mono (Nat.le_add_right _ _),
I.leadingCoeffNth_mono (Nat.le_add_left _ _)⟩
#align ideal.mem_leading_coeff Ideal.mem_leadingCoeff
/-- If `I` is an ideal, and `pᵢ` is a finite family of polynomials each satisfying
`∀ k, (pᵢ)ₖ ∈ Iⁿⁱ⁻ᵏ` for some `nᵢ`, then `p = ∏ pᵢ` also satisfies `∀ k, pₖ ∈ Iⁿ⁻ᵏ` with `n = ∑ nᵢ`.
-/
theorem _root_.Polynomial.coeff_prod_mem_ideal_pow_tsub {ι : Type*} (s : Finset ι) (f : ι → R[X])
(I : Ideal R) (n : ι → ℕ) (h : ∀ i ∈ s, ∀ (k), (f i).coeff k ∈ I ^ (n i - k)) (k : ℕ) :
(s.prod f).coeff k ∈ I ^ (s.sum n - k) := by
classical
induction' s using Finset.induction with a s ha hs generalizing k
· rw [sum_empty, prod_empty, coeff_one, zero_tsub, pow_zero, Ideal.one_eq_top]
exact Submodule.mem_top
· rw [sum_insert ha, prod_insert ha, coeff_mul]
apply sum_mem
rintro ⟨i, j⟩ e
obtain rfl : i + j = k := mem_antidiagonal.mp e
apply Ideal.pow_le_pow_right add_tsub_add_le_tsub_add_tsub
rw [pow_add]
exact
Ideal.mul_mem_mul (h _ (Finset.mem_insert.mpr <| Or.inl rfl) _)
(hs (fun i hi k => h _ (Finset.mem_insert.mpr <| Or.inr hi) _) j)
#align polynomial.coeff_prod_mem_ideal_pow_tsub Polynomial.coeff_prod_mem_ideal_pow_tsub
end CommSemiring
section Ring
variable [Ring R]
/-- `R[X]` is never a field for any ring `R`. -/
theorem polynomial_not_isField : ¬IsField R[X] := by
nontriviality R
intro hR
obtain ⟨p, hp⟩ := hR.mul_inv_cancel X_ne_zero
have hp0 : p ≠ 0 := right_ne_zero_of_mul_eq_one hp
have := degree_lt_degree_mul_X hp0
rw [← X_mul, congr_arg degree hp, degree_one, Nat.WithBot.lt_zero_iff, degree_eq_bot] at this
exact hp0 this
#align ideal.polynomial_not_is_field Ideal.polynomial_not_isField
/-- The only constant in a maximal ideal over a field is `0`. -/
theorem eq_zero_of_constant_mem_of_maximal (hR : IsField R) (I : Ideal R[X]) [hI : I.IsMaximal]
(x : R) (hx : C x ∈ I) : x = 0 := by
refine Classical.by_contradiction fun hx0 => hI.ne_top ((eq_top_iff_one I).2 ?_)
obtain ⟨y, hy⟩ := hR.mul_inv_cancel hx0
convert I.mul_mem_left (C y) hx
rw [← C.map_mul, hR.mul_comm y x, hy, RingHom.map_one]
#align ideal.eq_zero_of_constant_mem_of_maximal Ideal.eq_zero_of_constant_mem_of_maximal
end Ring
section CommRing
variable [CommRing R]
/-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/
theorem isPrime_map_C_iff_isPrime (P : Ideal R) :
IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) ↔ IsPrime P := by
-- Note: the following proof avoids quotient rings
-- It can be golfed substantially by using something like
-- `(Quotient.isDomain_iff_prime (map C P : Ideal R[X]))`
constructor
· intro H
have := comap_isPrime C (map C P)
convert this using 1
ext x
simp only [mem_comap, mem_map_C_iff]
constructor
· rintro h (- | n)
· rwa [coeff_C_zero]
· simp only [coeff_C_ne_zero (Nat.succ_ne_zero _), Submodule.zero_mem]
· intro h
simpa only [coeff_C_zero] using h 0
· intro h
constructor
· rw [Ne, eq_top_iff_one, mem_map_C_iff, not_forall]
use 0
rw [coeff_one_zero, ← eq_top_iff_one]
exact h.1
· intro f g
simp only [mem_map_C_iff]
contrapose!
rintro ⟨hf, hg⟩
classical
let m := Nat.find hf
let n := Nat.find hg
refine ⟨m + n, ?_⟩
rw [coeff_mul, ← Finset.insert_erase ((Finset.mem_antidiagonal (a := (m,n))).mpr rfl),
Finset.sum_insert (Finset.not_mem_erase _ _), (P.add_mem_iff_left _).not]
· apply mt h.2
rw [not_or]
exact ⟨Nat.find_spec hf, Nat.find_spec hg⟩
apply P.sum_mem
rintro ⟨i, j⟩ hij
rw [Finset.mem_erase, Finset.mem_antidiagonal] at hij
simp only [Ne, Prod.mk.inj_iff, not_and_or] at hij
obtain hi | hj : i < m ∨ j < n := by
rw [or_iff_not_imp_left, not_lt, le_iff_lt_or_eq]
rintro (hmi | rfl)
· rw [← not_le]
intro hnj
exact (add_lt_add_of_lt_of_le hmi hnj).ne hij.2.symm
· simp only [eq_self_iff_true, not_true, false_or_iff, add_right_inj,
not_and_self_iff] at hij
· rw [mul_comm]
apply P.mul_mem_left
exact Classical.not_not.1 (Nat.find_min hf hi)
· apply P.mul_mem_left
exact Classical.not_not.1 (Nat.find_min hg hj)
set_option linter.uppercaseLean3 false in
#align ideal.is_prime_map_C_iff_is_prime Ideal.isPrime_map_C_iff_isPrime
/-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/
theorem isPrime_map_C_of_isPrime {P : Ideal R} (H : IsPrime P) :
IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) :=
(isPrime_map_C_iff_isPrime P).mpr H
set_option linter.uppercaseLean3 false in
#align ideal.is_prime_map_C_of_is_prime Ideal.isPrime_map_C_of_isPrime
theorem is_fg_degreeLE [IsNoetherianRing R] (I : Ideal R[X]) (n : ℕ) :
Submodule.FG (I.degreeLE n) :=
letI := Classical.decEq R
isNoetherian_submodule_left.1
(isNoetherian_of_fg_of_noetherian _ ⟨_, degreeLE_eq_span_X_pow.symm⟩) _
#align ideal.is_fg_degree_le Ideal.is_fg_degreeLE
end CommRing
end Ideal
variable {σ : Type v} {M : Type w}
variable [CommRing R] [CommRing S] [AddCommGroup M] [Module R M]
section Prime
variable (σ) {r : R}
namespace Polynomial
theorem prime_C_iff : Prime (C r) ↔ Prime r :=
⟨comap_prime C (evalRingHom (0 : R)) fun r => eval_C, fun hr => by
have := hr.1
rw [← Ideal.span_singleton_prime] at hr ⊢
· rw [← Set.image_singleton, ← Ideal.map_span]
apply Ideal.isPrime_map_C_of_isPrime hr
· intro h; apply (this (C_eq_zero.mp h))
· assumption⟩
set_option linter.uppercaseLean3 false in
#align polynomial.prime_C_iff Polynomial.prime_C_iff
end Polynomial
namespace MvPolynomial
private theorem prime_C_iff_of_fintype {R : Type u} (σ : Type v) {r : R} [CommRing R] [Fintype σ] :
Prime (C r : MvPolynomial σ R) ↔ Prime r := by
rw [(renameEquiv R (Fintype.equivFin σ)).toMulEquiv.prime_iff]
convert_to Prime (C r) ↔ _
· congr!
apply rename_C
· symm
induction' Fintype.card σ with d hd
· exact (isEmptyAlgEquiv R (Fin 0)).toMulEquiv.symm.prime_iff
· rw [hd, ← Polynomial.prime_C_iff]
convert (finSuccEquiv R d).toMulEquiv.symm.prime_iff (p := Polynomial.C (C r))
rw [← finSuccEquiv_comp_C_eq_C]; rfl
theorem prime_C_iff : Prime (C r : MvPolynomial σ R) ↔ Prime r :=
⟨comap_prime C constantCoeff (constantCoeff_C _), fun hr =>
⟨fun h => hr.1 <| by
rw [← C_inj, h]
simp,
fun h =>
hr.2.1 <| by
rw [← constantCoeff_C _ r]
exact h.map _,
fun a b hd => by
obtain ⟨s, a', b', rfl, rfl⟩ := exists_finset_rename₂ a b
rw [← algebraMap_eq] at hd
have : algebraMap R _ r ∣ a' * b' := by
convert killCompl Subtype.coe_injective |>.toRingHom.map_dvd hd <;> simp
rw [← rename_C ((↑) : s → σ)]
let f := (rename (R := R) ((↑) : s → σ)).toRingHom
exact (((prime_C_iff_of_fintype s).2 hr).2.2 a' b' this).imp f.map_dvd f.map_dvd⟩⟩
set_option linter.uppercaseLean3 false in
#align mv_polynomial.prime_C_iff MvPolynomial.prime_C_iff
variable {σ}
theorem prime_rename_iff (s : Set σ) {p : MvPolynomial s R} :
Prime (rename ((↑) : s → σ) p) ↔ Prime (p : MvPolynomial s R) := by
classical
symm
let eqv :=
(sumAlgEquiv R (↥sᶜ) s).symm.trans
(renameEquiv R <| (Equiv.sumComm (↥sᶜ) s).trans <| Equiv.Set.sumCompl s)
have : (rename (↑)).toRingHom = eqv.toAlgHom.toRingHom.comp C := by
apply ringHom_ext
· intro
simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_C,
AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp,
AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply,
iterToSum_C_C, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply]
· intro
simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_X,
AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp,
AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply,
iterToSum_C_X, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, Sum.swap_inr,
Equiv.Set.sumCompl_apply_inl]
apply_fun (· p) at this
simp_rw [AlgHom.toRingHom_eq_coe, RingHom.coe_coe] at this
rw [← prime_C_iff, eqv.toMulEquiv.prime_iff, this]
simp only [MulEquiv.coe_mk, AlgEquiv.toEquiv_eq_coe, EquivLike.coe_coe, AlgEquiv.trans_apply,
MvPolynomial.sumAlgEquiv_symm_apply, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply,
AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, RingHom.coe_coe,
AlgEquiv.coe_trans, Function.comp_apply]
#align mv_polynomial.prime_rename_iff MvPolynomial.prime_rename_iff
end MvPolynomial
end Prime
namespace Polynomial
instance (priority := 100) wfDvdMonoid {R : Type*} [CommRing R] [IsDomain R] [WfDvdMonoid R] :
WfDvdMonoid R[X] where
wellFounded_dvdNotUnit := by
classical
refine
RelHomClass.wellFounded
(⟨fun p : R[X] =>
((if p = 0 then ⊤ else ↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff), ?_⟩ :
DvdNotUnit →r Prod.Lex (· < ·) DvdNotUnit)
(wellFounded_lt.prod_lex ‹WfDvdMonoid R›.wellFounded_dvdNotUnit)
rintro a b ⟨ane0, ⟨c, ⟨not_unit_c, rfl⟩⟩⟩
dsimp
rw [Polynomial.degree_mul, if_neg ane0]
split_ifs with hac
· rw [hac, Polynomial.leadingCoeff_zero]
apply Prod.Lex.left
exact lt_of_le_of_ne le_top WithTop.coe_ne_top
have cne0 : c ≠ 0 := right_ne_zero_of_mul hac
simp only [cne0, ane0, Polynomial.leadingCoeff_mul]
by_cases hdeg : c.degree = 0
· simp only [hdeg, add_zero]
refine Prod.Lex.right _ ⟨?_, ⟨c.leadingCoeff, fun unit_c => not_unit_c ?_, rfl⟩⟩
· rwa [Ne, Polynomial.leadingCoeff_eq_zero]
rw [Polynomial.isUnit_iff, Polynomial.eq_C_of_degree_eq_zero hdeg]
use c.leadingCoeff, unit_c
rw [Polynomial.leadingCoeff, Polynomial.natDegree_eq_of_degree_eq_some hdeg]; rfl
· apply Prod.Lex.left
rw [Polynomial.degree_eq_natDegree cne0] at *
rw [WithTop.coe_lt_coe, Polynomial.degree_eq_natDegree ane0, ← Nat.cast_add, Nat.cast_lt]
exact lt_add_of_pos_right _ (Nat.pos_of_ne_zero fun h => hdeg (h.symm ▸ WithBot.coe_zero))
end Polynomial
/-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/
protected theorem Polynomial.isNoetherianRing [inst : IsNoetherianRing R] : IsNoetherianRing R[X] :=
isNoetherianRing_iff.2
⟨fun I : Ideal R[X] =>
let M :=
WellFounded.min (isNoetherian_iff_wellFounded.1 (by infer_instance))
(Set.range I.leadingCoeffNth) ⟨_, ⟨0, rfl⟩⟩
have hm : M ∈ Set.range I.leadingCoeffNth := WellFounded.min_mem _ _ _
let ⟨N, HN⟩ := hm
let ⟨s, hs⟩ := I.is_fg_degreeLE N
have hm2 : ∀ k, I.leadingCoeffNth k ≤ M := fun k =>
Or.casesOn (le_or_lt k N) (fun h => HN ▸ I.leadingCoeffNth_mono h) fun h x hx =>
Classical.by_contradiction fun hxm =>
haveI : IsNoetherian R R := inst
have : ¬M < I.leadingCoeffNth k := by
refine WellFounded.not_lt_min (wellFounded_submodule_gt R R) _ _ ?_; exact ⟨k, rfl⟩
this ⟨HN ▸ I.leadingCoeffNth_mono (le_of_lt h), fun H => hxm (H hx)⟩
have hs2 : ∀ {x}, x ∈ I.degreeLE N → x ∈ Ideal.span (↑s : Set R[X]) :=
hs ▸ fun hx =>
Submodule.span_induction hx (fun _ hx => Ideal.subset_span hx) (Ideal.zero_mem _)
(fun _ _ => Ideal.add_mem _) fun c f hf => f.C_mul' c ▸ Ideal.mul_mem_left _ _ hf
⟨s, le_antisymm (Ideal.span_le.2 fun x hx =>
have : x ∈ I.degreeLE N := hs ▸ Submodule.subset_span hx
this.2) <| by
have : Submodule.span R[X] ↑s = Ideal.span ↑s := rfl
rw [this]
intro p hp
generalize hn : p.natDegree = k
induction' k using Nat.strong_induction_on with k ih generalizing p
rcases le_or_lt k N with h | h
· subst k
refine hs2 ⟨Polynomial.mem_degreeLE.2
(le_trans Polynomial.degree_le_natDegree <| WithBot.coe_le_coe.2 h), hp⟩
· have hp0 : p ≠ 0 := by
rintro rfl
cases hn
exact Nat.not_lt_zero _ h
have : (0 : R) ≠ 1 := by
intro h
apply hp0
ext i
refine (mul_one _).symm.trans ?_
rw [← h, mul_zero]
rfl
haveI : Nontrivial R := ⟨⟨0, 1, this⟩⟩
have : p.leadingCoeff ∈ I.leadingCoeffNth N := by
rw [HN]
exact hm2 k ((I.mem_leadingCoeffNth _ _).2
⟨_, hp, hn ▸ Polynomial.degree_le_natDegree, rfl⟩)
rw [I.mem_leadingCoeffNth] at this
rcases this with ⟨q, hq, hdq, hlqp⟩
have hq0 : q ≠ 0 := by
intro H
rw [← Polynomial.leadingCoeff_eq_zero] at H
rw [hlqp, Polynomial.leadingCoeff_eq_zero] at H
exact hp0 H
have h1 : p.degree = (q * Polynomial.X ^ (k - q.natDegree)).degree := by
rw [Polynomial.degree_mul', Polynomial.degree_X_pow]
· rw [Polynomial.degree_eq_natDegree hp0, Polynomial.degree_eq_natDegree hq0]
rw [← Nat.cast_add, add_tsub_cancel_of_le, hn]
· refine le_trans (Polynomial.natDegree_le_of_degree_le hdq) (le_of_lt h)
rw [Polynomial.leadingCoeff_X_pow, mul_one]
exact mt Polynomial.leadingCoeff_eq_zero.1 hq0
have h2 : p.leadingCoeff = (q * Polynomial.X ^ (k - q.natDegree)).leadingCoeff := by
rw [← hlqp, Polynomial.leadingCoeff_mul_X_pow]
have := Polynomial.degree_sub_lt h1 hp0 h2
rw [Polynomial.degree_eq_natDegree hp0] at this
rw [← sub_add_cancel p (q * Polynomial.X ^ (k - q.natDegree))]
convert (Ideal.span ↑s).add_mem _ ((Ideal.span (s : Set R[X])).mul_mem_right _ _)
· by_cases hpq : p - q * Polynomial.X ^ (k - q.natDegree) = 0
· rw [hpq]
exact Ideal.zero_mem _
refine ih _ ?_ (I.sub_mem hp (I.mul_mem_right _ hq)) rfl
rwa [Polynomial.degree_eq_natDegree hpq, Nat.cast_lt, hn] at this
exact hs2 ⟨Polynomial.mem_degreeLE.2 hdq, hq⟩⟩⟩
#align polynomial.is_noetherian_ring Polynomial.isNoetherianRing
attribute [instance] Polynomial.isNoetherianRing
namespace Polynomial
theorem exists_irreducible_of_degree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R]
{f : R[X]} (hf : 0 < f.degree) : ∃ g, Irreducible g ∧ g ∣ f :=
WfDvdMonoid.exists_irreducible_factor (fun huf => ne_of_gt hf <| degree_eq_zero_of_isUnit huf)
fun hf0 => not_lt_of_lt hf <| hf0.symm ▸ (@degree_zero R _).symm ▸ WithBot.bot_lt_coe _
#align polynomial.exists_irreducible_of_degree_pos Polynomial.exists_irreducible_of_degree_pos
theorem exists_irreducible_of_natDegree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R]
{f : R[X]} (hf : 0 < f.natDegree) : ∃ g, Irreducible g ∧ g ∣ f :=
exists_irreducible_of_degree_pos <| by
contrapose! hf
exact natDegree_le_of_degree_le hf
#align polynomial.exists_irreducible_of_nat_degree_pos Polynomial.exists_irreducible_of_natDegree_pos
theorem exists_irreducible_of_natDegree_ne_zero {R : Type u} [CommRing R] [IsDomain R]
[WfDvdMonoid R] {f : R[X]} (hf : f.natDegree ≠ 0) : ∃ g, Irreducible g ∧ g ∣ f :=
exists_irreducible_of_natDegree_pos <| Nat.pos_of_ne_zero hf
#align polynomial.exists_irreducible_of_nat_degree_ne_zero Polynomial.exists_irreducible_of_natDegree_ne_zero
theorem linearIndependent_powers_iff_aeval (f : M →ₗ[R] M) (v : M) :
(LinearIndependent R fun n : ℕ => (f ^ n) v) ↔ ∀ p : R[X], aeval f p v = 0 → p = 0 := by
rw [linearIndependent_iff]
simp only [Finsupp.total_apply, aeval_endomorphism, forall_iff_forall_finsupp, Sum, support,
coeff, ofFinsupp_eq_zero]
exact Iff.rfl
#align polynomial.linear_independent_powers_iff_aeval Polynomial.linearIndependent_powers_iff_aeval
attribute [-instance] Ring.toNonAssocRing
| Mathlib/RingTheory/Polynomial/Basic.lean | 1,061 | 1,068 | theorem disjoint_ker_aeval_of_coprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) :
Disjoint (LinearMap.ker (aeval f p)) (LinearMap.ker (aeval f q)) := by |
rw [disjoint_iff_inf_le]
intro v hv
rcases hpq with ⟨p', q', hpq'⟩
simpa [LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).1,
LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).2] using
congr_arg (fun p : R[X] => aeval f p v) hpq'.symm
|
/-
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
-/
import Mathlib.Analysis.Calculus.Deriv.AffineMap
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.LocalExtr.Rolle
import Mathlib.Analysis.Convex.Normed
import Mathlib.Analysis.RCLike.Basic
#align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the
derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`,
so they work both for real and complex derivatives.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or
`‖f x‖ ≤ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `ℝ`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `‖f x - f a‖ ≤ C * ‖x - a‖`; several versions deal with
right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`).
* `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` :
Cauchy's Mean Value Theorem.
* `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem.
* `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain.
* `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`,
`Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`,
if `∀ x, C (</≤/>/≥) (f' x)`, then `C * (y - x) (</≤/>/≥) (f y - f x)` whenever `x < y`.
* `monotoneOn_of_deriv_nonneg`, `antitoneOn_of_deriv_nonpos`,
`strictMono_of_deriv_pos`, `strictAnti_of_deriv_neg` :
if the derivative of a function is non-negative/non-positive/positive/negative, then
the function is monotone/antitone/strictly monotone/strictly monotonically
decreasing.
* `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.
* `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is
strictly differentiable. (This is a corollary of the mean value inequality.)
-/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F]
[NormedSpace ℝ F]
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Classical Topology NNReal
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
| Mathlib/Analysis/Calculus/MeanValue.lean | 92 | 124 | theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by |
change Icc a b ⊆ { x | f x ≤ B x }
set s := { x | f x ≤ B x } ∩ Icc a b
have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB
have : IsClosed s := by
simp only [s, inter_comm]
exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le'
apply this.Icc_subset_of_forall_exists_gt ha
rintro x ⟨hxB : f x ≤ B x, xab⟩ y hy
cases' hxB.lt_or_eq with hxB hxB
· -- If `f x < B x`, then all we need is continuity of both sides
refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))
have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x :=
A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB)
have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this
exact this.mono fun y => le_of_lt
· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩
specialize hf' x xab r hfr
have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z :=
(hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici
(Ioi_mem_nhds hrB)
obtain ⟨z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y :=
(hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists
refine ⟨z, ?_, hz⟩
have := (hfz.trans hzB).le
rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB,
sub_le_sub_iff_right] at this
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Set.Function
import Mathlib.Logic.Function.Iterate
import Mathlib.GroupTheory.Perm.Basic
#align_import dynamics.fixed_points.basic from "leanprover-community/mathlib"@"b86832321b586c6ac23ef8cdef6a7a27e42b13bd"
/-!
# Fixed points of a self-map
In this file we define
* the predicate `IsFixedPt f x := f x = x`;
* the set `fixedPoints f` of fixed points of a self-map `f`.
We also prove some simple lemmas about `IsFixedPt` and `∘`, `iterate`, and `Semiconj`.
## Tags
fixed point
-/
open Equiv
universe u v
variable {α : Type u} {β : Type v} {f fa g : α → α} {x y : α} {fb : β → β} {m n k : ℕ} {e : Perm α}
namespace Function
open Function (Commute)
/-- A point `x` is a fixed point of `f : α → α` if `f x = x`. -/
def IsFixedPt (f : α → α) (x : α) :=
f x = x
#align function.is_fixed_pt Function.IsFixedPt
/-- Every point is a fixed point of `id`. -/
theorem isFixedPt_id (x : α) : IsFixedPt id x :=
(rfl : _)
#align function.is_fixed_pt_id Function.isFixedPt_id
namespace IsFixedPt
instance decidable [h : DecidableEq α] {f : α → α} {x : α} : Decidable (IsFixedPt f x) :=
h (f x) x
/-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`. -/
protected theorem eq (hf : IsFixedPt f x) : f x = x :=
hf
#align function.is_fixed_pt.eq Function.IsFixedPt.eq
/-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f ∘ g`. -/
protected theorem comp (hf : IsFixedPt f x) (hg : IsFixedPt g x) : IsFixedPt (f ∘ g) x :=
calc
f (g x) = f x := congr_arg f hg
_ = x := hf
#align function.is_fixed_pt.comp Function.IsFixedPt.comp
/-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/
protected theorem iterate (hf : IsFixedPt f x) (n : ℕ) : IsFixedPt f^[n] x :=
iterate_fixed hf n
#align function.is_fixed_pt.iterate Function.IsFixedPt.iterate
/-- If `x` is a fixed point of `f ∘ g` and `g`, then it is a fixed point of `f`. -/
theorem left_of_comp (hfg : IsFixedPt (f ∘ g) x) (hg : IsFixedPt g x) : IsFixedPt f x :=
calc
f x = f (g x) := congr_arg f hg.symm
_ = x := hfg
#align function.is_fixed_pt.left_of_comp Function.IsFixedPt.left_of_comp
/-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed
point of `g`. -/
theorem to_leftInverse (hf : IsFixedPt f x) (h : LeftInverse g f) : IsFixedPt g x :=
calc
g x = g (f x) := congr_arg g hf.symm
_ = x := h x
#align function.is_fixed_pt.to_left_inverse Function.IsFixedPt.to_leftInverse
/-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points
of `fb`. -/
protected theorem map {x : α} (hx : IsFixedPt fa x) {g : α → β} (h : Semiconj g fa fb) :
IsFixedPt fb (g x) :=
calc
fb (g x) = g (fa x) := (h.eq x).symm
_ = g x := congr_arg g hx
#align function.is_fixed_pt.map Function.IsFixedPt.map
protected theorem apply {x : α} (hx : IsFixedPt f x) : IsFixedPt f (f x) := by convert hx
#align function.is_fixed_pt.apply Function.IsFixedPt.apply
theorem preimage_iterate {s : Set α} (h : IsFixedPt (Set.preimage f) s) (n : ℕ) :
IsFixedPt (Set.preimage f^[n]) s := by
rw [Set.preimage_iterate_eq]
exact h.iterate n
#align function.is_fixed_pt.preimage_iterate Function.IsFixedPt.preimage_iterate
lemma image_iterate {s : Set α} (h : IsFixedPt (Set.image f) s) (n : ℕ) :
IsFixedPt (Set.image f^[n]) s :=
Set.image_iterate_eq ▸ h.iterate n
protected theorem equiv_symm (h : IsFixedPt e x) : IsFixedPt e.symm x :=
h.to_leftInverse e.leftInverse_symm
#align function.is_fixed_pt.equiv_symm Function.IsFixedPt.equiv_symm
protected theorem perm_inv (h : IsFixedPt e x) : IsFixedPt (⇑e⁻¹) x :=
h.equiv_symm
#align function.is_fixed_pt.perm_inv Function.IsFixedPt.perm_inv
protected theorem perm_pow (h : IsFixedPt e x) (n : ℕ) : IsFixedPt (⇑(e ^ n)) x := h.iterate _
#align function.is_fixed_pt.perm_pow Function.IsFixedPt.perm_pow
protected theorem perm_zpow (h : IsFixedPt e x) : ∀ n : ℤ, IsFixedPt (⇑(e ^ n)) x
| Int.ofNat _ => h.perm_pow _
| Int.negSucc n => (h.perm_pow <| n + 1).perm_inv
#align function.is_fixed_pt.perm_zpow Function.IsFixedPt.perm_zpow
end IsFixedPt
@[simp]
theorem Injective.isFixedPt_apply_iff (hf : Injective f) {x : α} :
IsFixedPt f (f x) ↔ IsFixedPt f x :=
⟨fun h => hf h.eq, IsFixedPt.apply⟩
#align function.injective.is_fixed_pt_apply_iff Function.Injective.isFixedPt_apply_iff
/-- The set of fixed points of a map `f : α → α`. -/
def fixedPoints (f : α → α) : Set α :=
{ x : α | IsFixedPt f x }
#align function.fixed_points Function.fixedPoints
instance fixedPoints.decidable [DecidableEq α] (f : α → α) (x : α) :
Decidable (x ∈ fixedPoints f) :=
IsFixedPt.decidable
#align function.fixed_points.decidable Function.fixedPoints.decidable
@[simp]
theorem mem_fixedPoints : x ∈ fixedPoints f ↔ IsFixedPt f x :=
Iff.rfl
#align function.mem_fixed_points Function.mem_fixedPoints
theorem mem_fixedPoints_iff {α : Type*} {f : α → α} {x : α} : x ∈ fixedPoints f ↔ f x = x := by
rfl
#align function.mem_fixed_points_iff Function.mem_fixedPoints_iff
@[simp]
theorem fixedPoints_id : fixedPoints (@id α) = Set.univ :=
Set.ext fun _ => by simpa using isFixedPt_id _
#align function.fixed_points_id Function.fixedPoints_id
theorem fixedPoints_subset_range : fixedPoints f ⊆ Set.range f := fun x hx => ⟨x, hx⟩
#align function.fixed_points_subset_range Function.fixedPoints_subset_range
/-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points
of `fb`. -/
theorem Semiconj.mapsTo_fixedPoints {g : α → β} (h : Semiconj g fa fb) :
Set.MapsTo g (fixedPoints fa) (fixedPoints fb) := fun _ hx => hx.map h
#align function.semiconj.maps_to_fixed_pts Function.Semiconj.mapsTo_fixedPoints
/-- Any two maps `f : α → β` and `g : β → α` are inverse of each other on the sets of fixed points
of `f ∘ g` and `g ∘ f`, respectively. -/
theorem invOn_fixedPoints_comp (f : α → β) (g : β → α) :
Set.InvOn f g (fixedPoints <| f ∘ g) (fixedPoints <| g ∘ f) :=
⟨fun _ => id, fun _ => id⟩
#align function.inv_on_fixed_pts_comp Function.invOn_fixedPoints_comp
/-- Any map `f` sends fixed points of `g ∘ f` to fixed points of `f ∘ g`. -/
theorem mapsTo_fixedPoints_comp (f : α → β) (g : β → α) :
Set.MapsTo f (fixedPoints <| g ∘ f) (fixedPoints <| f ∘ g) := fun _ hx => hx.map fun _ => rfl
#align function.maps_to_fixed_pts_comp Function.mapsTo_fixedPoints_comp
/-- Given two maps `f : α → β` and `g : β → α`, `g` is a bijective map between the fixed points
of `f ∘ g` and the fixed points of `g ∘ f`. The inverse map is `f`, see `invOn_fixedPoints_comp`. -/
theorem bijOn_fixedPoints_comp (f : α → β) (g : β → α) :
Set.BijOn g (fixedPoints <| f ∘ g) (fixedPoints <| g ∘ f) :=
(invOn_fixedPoints_comp f g).bijOn (mapsTo_fixedPoints_comp g f) (mapsTo_fixedPoints_comp f g)
#align function.bij_on_fixed_pts_comp Function.bijOn_fixedPoints_comp
/-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points
of `f ∘ g`. This is a particular case of `Function.invOn_fixedPoints_comp`. -/
theorem Commute.invOn_fixedPoints_comp (h : Commute f g) :
Set.InvOn f g (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by
simpa only [h.comp_eq] using Function.invOn_fixedPoints_comp f g
#align function.commute.inv_on_fixed_pts_comp Function.Commute.invOn_fixedPoints_comp
/-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f ∘ g`.
This is a particular case of `Function.bijOn_fixedPoints_comp`. -/
| Mathlib/Dynamics/FixedPoints/Basic.lean | 192 | 194 | theorem Commute.left_bijOn_fixedPoints_comp (h : Commute f g) :
Set.BijOn f (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by |
simpa only [h.comp_eq] using bijOn_fixedPoints_comp g f
|
/-
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]
| Mathlib/RingTheory/UniqueFactorizationDomain.lean | 594 | 599 | 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
|
/-
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.MeasureSpace
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
#align measure_theory.measure.restrictₗ MeasureTheory.Measure.restrictₗ
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
#align measure_theory.measure.restrict MeasureTheory.Measure.restrict
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
#align measure_theory.measure.restrictₗ_apply MeasureTheory.Measure.restrictₗ_apply
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
#align measure_theory.measure.restrict_to_outer_measure_eq_to_outer_measure_restrict MeasureTheory.Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
#align measure_theory.measure.restrict_apply₀ MeasureTheory.Measure.restrict_apply₀
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
#align measure_theory.measure.restrict_apply MeasureTheory.Measure.restrict_apply
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
#align measure_theory.measure.restrict_mono' MeasureTheory.Measure.restrict_mono'
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
#align measure_theory.measure.restrict_mono MeasureTheory.Measure.restrict_mono
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
#align measure_theory.measure.restrict_mono_ae MeasureTheory.Measure.restrict_mono_ae
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
#align measure_theory.measure.restrict_congr_set MeasureTheory.Measure.restrict_congr_set
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
#align measure_theory.measure.restrict_apply' MeasureTheory.Measure.restrict_apply'
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
#align measure_theory.measure.restrict_apply₀' MeasureTheory.Measure.restrict_apply₀'
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
#align measure_theory.measure.restrict_le_self MeasureTheory.Measure.restrict_le_self
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
#align measure_theory.measure.restrict_eq_self MeasureTheory.Measure.restrict_eq_self
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
#align measure_theory.measure.restrict_apply_self MeasureTheory.Measure.restrict_apply_self
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
#align measure_theory.measure.restrict_apply_univ MeasureTheory.Measure.restrict_apply_univ
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
#align measure_theory.measure.le_restrict_apply MeasureTheory.Measure.le_restrict_apply
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
#align measure_theory.measure.restrict_apply_superset MeasureTheory.Measure.restrict_apply_superset
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
#align measure_theory.measure.restrict_add MeasureTheory.Measure.restrict_add
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
#align measure_theory.measure.restrict_zero MeasureTheory.Measure.restrict_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} (c : ℝ≥0∞) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s :=
(restrictₗ s).map_smul c μ
#align measure_theory.measure.restrict_smul MeasureTheory.Measure.restrict_smul
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
#align measure_theory.measure.restrict_restrict₀ MeasureTheory.Measure.restrict_restrict₀
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
#align measure_theory.measure.restrict_restrict MeasureTheory.Measure.restrict_restrict
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
#align measure_theory.measure.restrict_restrict_of_subset MeasureTheory.Measure.restrict_restrict_of_subset
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
#align measure_theory.measure.restrict_restrict₀' MeasureTheory.Measure.restrict_restrict₀'
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
#align measure_theory.measure.restrict_restrict' MeasureTheory.Measure.restrict_restrict'
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
#align measure_theory.measure.restrict_comm MeasureTheory.Measure.restrict_comm
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
#align measure_theory.measure.restrict_apply_eq_zero MeasureTheory.Measure.restrict_apply_eq_zero
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
#align measure_theory.measure.measure_inter_eq_zero_of_restrict MeasureTheory.Measure.measure_inter_eq_zero_of_restrict
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
#align measure_theory.measure.restrict_apply_eq_zero' MeasureTheory.Measure.restrict_apply_eq_zero'
@[simp]
| Mathlib/MeasureTheory/Measure/Restrict.lean | 221 | 222 | theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by |
rw [← measure_univ_eq_zero, restrict_apply_univ]
|
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.Topology.Category.Profinite.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Pullbacks
import Mathlib.Topology.Category.CompHaus.Limits
/-!
# Explicit limits and colimits
This file collects some constructions of explicit limits and colimits in `Profinite`,
which may be useful due to their definitional properties.
## Main definitions
- `Profinite.pullback`: Explicit pullback, defined in the "usual" way as a subset of the product.
- `Profinite.finiteCoproduct`: Explicit finite coproducts, defined as a disjoint union.
-/
namespace Profinite
universe u w
/-
Previously, this had accidentally been made a global instance,
and we now turn it on locally when convenient.
-/
attribute [local instance] CategoryTheory.ConcreteCategory.instFunLike
open CategoryTheory Limits
section Pullbacks
variable {X Y B : Profinite.{u}} (f : X ⟶ B) (g : Y ⟶ B)
/--
The pullback of two morphisms `f, g` in `Profinite`, constructed explicitly as the set of
pairs `(x, y)` such that `f x = g y`, with the topology induced by the product.
-/
def pullback : Profinite.{u} :=
letI set := { xy : X × Y | f xy.fst = g xy.snd }
haveI : CompactSpace set := isCompact_iff_compactSpace.mp
(isClosed_eq (f.continuous.comp continuous_fst) (g.continuous.comp continuous_snd)).isCompact
Profinite.of set
/-- The projection from the pullback to the first component. -/
def pullback.fst : pullback f g ⟶ X where
toFun := fun ⟨⟨x, _⟩, _⟩ => x
continuous_toFun := Continuous.comp continuous_fst continuous_subtype_val
/-- The projection from the pullback to the second component. -/
def pullback.snd : pullback f g ⟶ Y where
toFun := fun ⟨⟨_, y⟩, _⟩ => y
continuous_toFun := Continuous.comp continuous_snd continuous_subtype_val
@[reassoc]
lemma pullback.condition : pullback.fst f g ≫ f = pullback.snd f g ≫ g := by
ext ⟨_, h⟩
exact h
/--
Construct a morphism to the explicit pullback given morphisms to the factors
which are compatible with the maps to the base.
This is essentially the universal property of the pullback.
-/
def pullback.lift {Z : Profinite.{u}} (a : Z ⟶ X) (b : Z ⟶ Y) (w : a ≫ f = b ≫ g) :
Z ⟶ pullback f g where
toFun := fun z => ⟨⟨a z, b z⟩, by apply_fun (· z) at w; exact w⟩
continuous_toFun := by
apply Continuous.subtype_mk
rw [continuous_prod_mk]
exact ⟨a.continuous, b.continuous⟩
@[reassoc (attr := simp)]
lemma pullback.lift_fst {Z : Profinite.{u}} (a : Z ⟶ X) (b : Z ⟶ Y) (w : a ≫ f = b ≫ g) :
pullback.lift f g a b w ≫ pullback.fst f g = a := rfl
@[reassoc (attr := simp)]
lemma pullback.lift_snd {Z : Profinite.{u}} (a : Z ⟶ X) (b : Z ⟶ Y) (w : a ≫ f = b ≫ g) :
pullback.lift f g a b w ≫ pullback.snd f g = b := rfl
lemma pullback.hom_ext {Z : Profinite.{u}} (a b : Z ⟶ pullback f g)
(hfst : a ≫ pullback.fst f g = b ≫ pullback.fst f g)
(hsnd : a ≫ pullback.snd f g = b ≫ pullback.snd f g) : a = b := by
ext z
apply_fun (· z) at hfst hsnd
apply Subtype.ext
apply Prod.ext
· exact hfst
· exact hsnd
/-- The pullback cone whose cone point is the explicit pullback. -/
@[simps! pt π]
def pullback.cone : Limits.PullbackCone f g :=
Limits.PullbackCone.mk (pullback.fst f g) (pullback.snd f g) (pullback.condition f g)
/-- The explicit pullback cone is a limit cone. -/
@[simps! lift]
def pullback.isLimit : Limits.IsLimit (pullback.cone f g) :=
Limits.PullbackCone.isLimitAux _
(fun s => pullback.lift f g s.fst s.snd s.condition)
(fun _ => pullback.lift_fst _ _ _ _ _)
(fun _ => pullback.lift_snd _ _ _ _ _)
(fun _ _ hm => pullback.hom_ext _ _ _ _ (hm .left) (hm .right))
section Isos
/-- The isomorphism from the explicit pullback to the abstract pullback. -/
noncomputable
def pullbackIsoPullback : Profinite.pullback f g ≅ Limits.pullback f g :=
Limits.IsLimit.conePointUniqueUpToIso (pullback.isLimit f g) (Limits.limit.isLimit _)
/-- The homeomorphism from the explicit pullback to the abstract pullback. -/
noncomputable
def pullbackHomeoPullback : (Profinite.pullback f g).toCompHaus ≃ₜ
(Limits.pullback f g).toCompHaus :=
Profinite.homeoOfIso (pullbackIsoPullback f g)
| Mathlib/Topology/Category/Profinite/Limits.lean | 123 | 126 | theorem pullback_fst_eq :
Profinite.pullback.fst f g = (pullbackIsoPullback f g).hom ≫ Limits.pullback.fst := by |
dsimp [pullbackIsoPullback]
simp only [Limits.limit.conePointUniqueUpToIso_hom_comp, pullback.cone_pt, pullback.cone_π]
|
/-
Copyright (c) 2021 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.Topology.Separation
import Mathlib.Algebra.Group.Defs
#align_import topology.algebra.semigroup from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514"
/-!
# Idempotents in topological semigroups
This file provides a sufficient condition for a semigroup `M` to contain an idempotent (i.e. an
element `m` such that `m * m = m `), namely that `M` is a nonempty compact Hausdorff space where
right-multiplication by constants is continuous.
We also state a corresponding lemma guaranteeing that a subset of `M` contains an idempotent.
-/
/-- Any nonempty compact Hausdorff semigroup where right-multiplication is continuous contains
an idempotent, i.e. an `m` such that `m * m = m`. -/
@[to_additive
"Any nonempty compact Hausdorff additive semigroup where right-addition is continuous
contains an idempotent, i.e. an `m` such that `m + m = m`"]
| Mathlib/Topology/Algebra/Semigroup.lean | 27 | 72 | theorem exists_idempotent_of_compact_t2_of_continuous_mul_left {M} [Nonempty M] [Semigroup M]
[TopologicalSpace M] [CompactSpace M] [T2Space M]
(continuous_mul_left : ∀ r : M, Continuous (· * r)) : ∃ m : M, m * m = m := by |
/- We apply Zorn's lemma to the poset of nonempty closed subsemigroups of `M`.
It will turn out that any minimal element is `{m}` for an idempotent `m : M`. -/
let S : Set (Set M) :=
{ N | IsClosed N ∧ N.Nonempty ∧ ∀ (m) (_ : m ∈ N) (m') (_ : m' ∈ N), m * m' ∈ N }
rsuffices ⟨N, ⟨N_closed, ⟨m, hm⟩, N_mul⟩, N_minimal⟩ : ∃ N ∈ S, ∀ N' ∈ S, N' ⊆ N → N' = N
· use m
/- We now have an element `m : M` of a minimal subsemigroup `N`, and want to show `m + m = m`.
We first show that every element of `N` is of the form `m' + m`. -/
have scaling_eq_self : (· * m) '' N = N := by
apply N_minimal
· refine ⟨(continuous_mul_left m).isClosedMap _ N_closed, ⟨_, ⟨m, hm, rfl⟩⟩, ?_⟩
rintro _ ⟨m'', hm'', rfl⟩ _ ⟨m', hm', rfl⟩
exact ⟨m'' * m * m', N_mul _ (N_mul _ hm'' _ hm) _ hm', mul_assoc _ _ _⟩
· rintro _ ⟨m', hm', rfl⟩
exact N_mul _ hm' _ hm
/- In particular, this means that `m' * m = m` for some `m'`. We now use minimality again
to show that this holds for all `m' ∈ N`. -/
have absorbing_eq_self : N ∩ { m' | m' * m = m } = N := by
apply N_minimal
· refine ⟨N_closed.inter ((T1Space.t1 m).preimage (continuous_mul_left m)), ?_, ?_⟩
· rwa [← scaling_eq_self] at hm
· rintro m'' ⟨mem'', eq'' : _ = m⟩ m' ⟨mem', eq' : _ = m⟩
refine ⟨N_mul _ mem'' _ mem', ?_⟩
rw [Set.mem_setOf_eq, mul_assoc, eq', eq'']
apply Set.inter_subset_left
-- Thus `m * m = m` as desired.
rw [← absorbing_eq_self] at hm
exact hm.2
refine zorn_superset _ fun c hcs hc => ?_
refine
⟨⋂₀ c, ⟨isClosed_sInter fun t ht => (hcs ht).1, ?_, fun m hm m' hm' => ?_⟩, fun s hs =>
Set.sInter_subset_of_mem hs⟩
· obtain rfl | hcnemp := c.eq_empty_or_nonempty
· rw [Set.sInter_empty]
apply Set.univ_nonempty
convert
@IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ _ _ hcnemp.coe_sort
((↑) : c → Set M) ?_ ?_ ?_ ?_
· exact Set.sInter_eq_iInter
· refine DirectedOn.directed_val (IsChain.directedOn hc.symm)
exacts [fun i => (hcs i.prop).2.1, fun i => (hcs i.prop).1.isCompact, fun i => (hcs i.prop).1]
· rw [Set.mem_sInter]
exact fun t ht => (hcs ht).2.2 m (Set.mem_sInter.mp hm t ht) m' (Set.mem_sInter.mp hm' t ht)
|
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.MeasureTheory.Measure.Regular
import Mathlib.MeasureTheory.Function.SimpleFuncDenseLp
import Mathlib.Topology.UrysohnsLemma
import Mathlib.MeasureTheory.Integral.Bochner
#align_import measure_theory.function.continuous_map_dense from "leanprover-community/mathlib"@"e0736bb5b48bdadbca19dbd857e12bee38ccfbb8"
/-!
# Approximation in Lᵖ by continuous functions
This file proves that bounded continuous functions are dense in `Lp E p μ`, for `p < ∞`, if the
domain `α` of the functions is a normal topological space and the measure `μ` is weakly regular.
It also proves the same results for approximation by continuous functions with compact support
when the space is locally compact and `μ` is regular.
The result is presented in several versions. First concrete versions giving an approximation
up to `ε` in these various contexts, and then abstract versions stating that the topological
closure of the relevant subgroups of `Lp` are the whole space.
* `MeasureTheory.Memℒp.exists_hasCompactSupport_snorm_sub_le` states that, in a locally compact
space, an `ℒp` function can be approximated by continuous functions with compact support,
in the sense that `snorm (f - g) p μ` is small.
* `MeasureTheory.Memℒp.exists_hasCompactSupport_integral_rpow_sub_le`: same result, but expressed in
terms of `∫ ‖f - g‖^p`.
Versions with `Integrable` instead of `Memℒp` are specialized to the case `p = 1`.
Versions with `boundedContinuous` instead of `HasCompactSupport` drop the locally
compact assumption and give only approximation by a bounded continuous function.
* `MeasureTheory.Lp.boundedContinuousFunction_dense`: The subgroup
`MeasureTheory.Lp.boundedContinuousFunction` of `Lp E p μ`, the additive subgroup of
`Lp E p μ` consisting of equivalence classes containing a continuous representative, is dense in
`Lp E p μ`.
* `BoundedContinuousFunction.toLp_denseRange`: For finite-measure `μ`, the continuous linear
map `BoundedContinuousFunction.toLp p μ 𝕜` from `α →ᵇ E` to `Lp E p μ` has dense range.
* `ContinuousMap.toLp_denseRange`: For compact `α` and finite-measure `μ`, the continuous linear
map `ContinuousMap.toLp p μ 𝕜` from `C(α, E)` to `Lp E p μ` has dense range.
Note that for `p = ∞` this result is not true: the characteristic function of the set `[0, ∞)` in
`ℝ` cannot be continuously approximated in `L∞`.
The proof is in three steps. First, since simple functions are dense in `Lp`, it suffices to prove
the result for a scalar multiple of a characteristic function of a measurable set `s`. Secondly,
since the measure `μ` is weakly regular, the set `s` can be approximated above by an open set and
below by a closed set. Finally, since the domain `α` is normal, we use Urysohn's lemma to find a
continuous function interpolating between these two sets.
## Related results
Are you looking for a result on "directional" approximation (above or below with respect to an
order) of functions whose codomain is `ℝ≥0∞` or `ℝ`, by semicontinuous functions? See the
Vitali-Carathéodory theorem, in the file `Mathlib/MeasureTheory/Integral/VitaliCaratheodory.lean`.
-/
open scoped ENNReal NNReal Topology BoundedContinuousFunction
open MeasureTheory TopologicalSpace ContinuousMap Set Bornology
variable {α : Type*} [MeasurableSpace α] [TopologicalSpace α] [T4Space α] [BorelSpace α]
variable {E : Type*} [NormedAddCommGroup E] {μ : Measure α} {p : ℝ≥0∞}
namespace MeasureTheory
variable [NormedSpace ℝ E]
/-- A variant of Urysohn's lemma, `ℒ^p` version, for an outer regular measure `μ`:
consider two sets `s ⊆ u` which are respectively closed and open with `μ s < ∞`, and a vector `c`.
Then one may find a continuous function `f` equal to `c` on `s` and to `0` outside of `u`,
bounded by `‖c‖` everywhere, and such that the `ℒ^p` norm of `f - s.indicator (fun y ↦ c)` is
arbitrarily small. Additionally, this function `f` belongs to `ℒ^p`. -/
theorem exists_continuous_snorm_sub_le_of_closed [μ.OuterRegular] (hp : p ≠ ∞) {s u : Set α}
(s_closed : IsClosed s) (u_open : IsOpen u) (hsu : s ⊆ u) (hs : μ s ≠ ∞) (c : E) {ε : ℝ≥0∞}
(hε : ε ≠ 0) :
∃ f : α → E,
Continuous f ∧
snorm (fun x => f x - s.indicator (fun _y => c) x) p μ ≤ ε ∧
(∀ x, ‖f x‖ ≤ ‖c‖) ∧ Function.support f ⊆ u ∧ Memℒp f p μ := by
obtain ⟨η, η_pos, hη⟩ :
∃ η : ℝ≥0, 0 < η ∧ ∀ s : Set α, μ s ≤ η → snorm (s.indicator fun _x => c) p μ ≤ ε :=
exists_snorm_indicator_le hp c hε
have ηpos : (0 : ℝ≥0∞) < η := ENNReal.coe_lt_coe.2 η_pos
obtain ⟨V, sV, V_open, h'V, hV⟩ : ∃ (V : Set α), V ⊇ s ∧ IsOpen V ∧ μ V < ∞ ∧ μ (V \ s) < η :=
s_closed.measurableSet.exists_isOpen_diff_lt hs ηpos.ne'
let v := u ∩ V
have hsv : s ⊆ v := subset_inter hsu sV
have hμv : μ v < ∞ := (measure_mono inter_subset_right).trans_lt h'V
obtain ⟨g, hgv, hgs, hg_range⟩ :=
exists_continuous_zero_one_of_isClosed (u_open.inter V_open).isClosed_compl s_closed
(disjoint_compl_left_iff.2 hsv)
-- Multiply this by `c` to get a continuous approximation to the function `f`; the key point is
-- that this is pointwise bounded by the indicator of the set `v \ s`, which has small measure.
have g_norm : ∀ x, ‖g x‖ = g x := fun x => by rw [Real.norm_eq_abs, abs_of_nonneg (hg_range x).1]
have gc_bd0 : ∀ x, ‖g x • c‖ ≤ ‖c‖ := by
intro x
simp only [norm_smul, g_norm x]
apply mul_le_of_le_one_left (norm_nonneg _)
exact (hg_range x).2
have gc_bd :
∀ x, ‖g x • c - s.indicator (fun _x => c) x‖ ≤ ‖(v \ s).indicator (fun _x => c) x‖ := by
intro x
by_cases hv : x ∈ v
· rw [← Set.diff_union_of_subset hsv] at hv
cases' hv with hsv hs
· simpa only [hsv.2, Set.indicator_of_not_mem, not_false_iff, sub_zero, hsv,
Set.indicator_of_mem] using gc_bd0 x
· simp [hgs hs, hs]
· simp [hgv hv, show x ∉ s from fun h => hv (hsv h)]
have gc_support : (Function.support fun x : α => g x • c) ⊆ v := by
refine Function.support_subset_iff'.2 fun x hx => ?_
simp only [hgv hx, Pi.zero_apply, zero_smul]
have gc_mem : Memℒp (fun x => g x • c) p μ := by
refine Memℒp.smul_of_top_left (memℒp_top_const _) ?_
refine ⟨g.continuous.aestronglyMeasurable, ?_⟩
have : snorm (v.indicator fun _x => (1 : ℝ)) p μ < ⊤ := by
refine (snorm_indicator_const_le _ _).trans_lt ?_
simp only [lt_top_iff_ne_top, hμv.ne, nnnorm_one, ENNReal.coe_one, one_div, one_mul, Ne,
ENNReal.rpow_eq_top_iff, inv_lt_zero, false_and_iff, or_false_iff, not_and, not_lt,
ENNReal.toReal_nonneg, imp_true_iff]
refine (snorm_mono fun x => ?_).trans_lt this
by_cases hx : x ∈ v
· simp only [hx, abs_of_nonneg (hg_range x).1, (hg_range x).2, Real.norm_eq_abs,
indicator_of_mem, CstarRing.norm_one]
· simp only [hgv hx, Pi.zero_apply, Real.norm_eq_abs, abs_zero, abs_nonneg]
refine
⟨fun x => g x • c, g.continuous.smul continuous_const, (snorm_mono gc_bd).trans ?_, gc_bd0,
gc_support.trans inter_subset_left, gc_mem⟩
exact hη _ ((measure_mono (diff_subset_diff inter_subset_right Subset.rfl)).trans hV.le)
#align measure_theory.exists_continuous_snorm_sub_le_of_closed MeasureTheory.exists_continuous_snorm_sub_le_of_closed
/-- In a locally compact space, any function in `ℒp` can be approximated by compactly supported
continuous functions when `p < ∞`, version in terms of `snorm`. -/
theorem Memℒp.exists_hasCompactSupport_snorm_sub_le [WeaklyLocallyCompactSpace α] [μ.Regular]
(hp : p ≠ ∞) {f : α → E} (hf : Memℒp f p μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ g : α → E, HasCompactSupport g ∧ snorm (f - g) p μ ≤ ε ∧ Continuous g ∧ Memℒp g p μ := by
suffices H :
∃ g : α → E, snorm (f - g) p μ ≤ ε ∧ Continuous g ∧ Memℒp g p μ ∧ HasCompactSupport g by
rcases H with ⟨g, hg, g_cont, g_mem, g_support⟩
exact ⟨g, g_support, hg, g_cont, g_mem⟩
-- It suffices to check that the set of functions we consider approximates characteristic
-- functions, is stable under addition and consists of ae strongly measurable functions.
-- First check the latter easy facts.
apply hf.induction_dense hp _ _ _ _ hε
rotate_left
-- stability under addition
· rintro f g ⟨f_cont, f_mem, hf⟩ ⟨g_cont, g_mem, hg⟩
exact ⟨f_cont.add g_cont, f_mem.add g_mem, hf.add hg⟩
-- ae strong measurability
· rintro f ⟨_f_cont, f_mem, _hf⟩
exact f_mem.aestronglyMeasurable
-- We are left with approximating characteristic functions.
-- This follows from `exists_continuous_snorm_sub_le_of_closed`.
intro c t ht htμ ε hε
rcases exists_Lp_half E μ p hε with ⟨δ, δpos, hδ⟩
obtain ⟨η, ηpos, hη⟩ :
∃ η : ℝ≥0, 0 < η ∧ ∀ s : Set α, μ s ≤ η → snorm (s.indicator fun _x => c) p μ ≤ δ :=
exists_snorm_indicator_le hp c δpos.ne'
have hη_pos' : (0 : ℝ≥0∞) < η := ENNReal.coe_pos.2 ηpos
obtain ⟨s, st, s_compact, μs⟩ : ∃ s, s ⊆ t ∧ IsCompact s ∧ μ (t \ s) < η :=
ht.exists_isCompact_diff_lt htμ.ne hη_pos'.ne'
have hsμ : μ s < ∞ := (measure_mono st).trans_lt htμ
have I1 : snorm ((s.indicator fun _y => c) - t.indicator fun _y => c) p μ ≤ δ := by
rw [← snorm_neg, neg_sub, ← indicator_diff st]
exact hη _ μs.le
obtain ⟨k, k_compact, sk⟩ : ∃ k : Set α, IsCompact k ∧ s ⊆ interior k :=
exists_compact_superset s_compact
rcases exists_continuous_snorm_sub_le_of_closed hp s_compact.isClosed isOpen_interior sk hsμ.ne c
δpos.ne' with
⟨f, f_cont, I2, _f_bound, f_support, f_mem⟩
have I3 : snorm (f - t.indicator fun _y => c) p μ ≤ ε := by
convert
(hδ _ _
(f_mem.aestronglyMeasurable.sub
(aestronglyMeasurable_const.indicator s_compact.measurableSet))
((aestronglyMeasurable_const.indicator s_compact.measurableSet).sub
(aestronglyMeasurable_const.indicator ht))
I2 I1).le using 2
simp only [sub_add_sub_cancel]
refine ⟨f, I3, f_cont, f_mem, HasCompactSupport.intro k_compact fun x hx => ?_⟩
rw [← Function.nmem_support]
contrapose! hx
exact interior_subset (f_support hx)
#align measure_theory.mem_ℒp.exists_has_compact_support_snorm_sub_le MeasureTheory.Memℒp.exists_hasCompactSupport_snorm_sub_le
/-- In a locally compact space, any function in `ℒp` can be approximated by compactly supported
continuous functions when `0 < p < ∞`, version in terms of `∫`. -/
theorem Memℒp.exists_hasCompactSupport_integral_rpow_sub_le
[WeaklyLocallyCompactSpace α] [μ.Regular]
{p : ℝ} (hp : 0 < p) {f : α → E} (hf : Memℒp f (ENNReal.ofReal p) μ) {ε : ℝ} (hε : 0 < ε) :
∃ g : α → E,
HasCompactSupport g ∧
(∫ x, ‖f x - g x‖ ^ p ∂μ) ≤ ε ∧ Continuous g ∧ Memℒp g (ENNReal.ofReal p) μ := by
have I : 0 < ε ^ (1 / p) := Real.rpow_pos_of_pos hε _
have A : ENNReal.ofReal (ε ^ (1 / p)) ≠ 0 := by
simp only [Ne, ENNReal.ofReal_eq_zero, not_le, I]
have B : ENNReal.ofReal p ≠ 0 := by simpa only [Ne, ENNReal.ofReal_eq_zero, not_le] using hp
rcases hf.exists_hasCompactSupport_snorm_sub_le ENNReal.coe_ne_top A with
⟨g, g_support, hg, g_cont, g_mem⟩
change snorm _ (ENNReal.ofReal p) _ ≤ _ at hg
refine ⟨g, g_support, ?_, g_cont, g_mem⟩
rwa [(hf.sub g_mem).snorm_eq_integral_rpow_norm B ENNReal.coe_ne_top,
ENNReal.ofReal_le_ofReal_iff I.le, one_div, ENNReal.toReal_ofReal hp.le,
Real.rpow_le_rpow_iff _ hε.le (inv_pos.2 hp)] at hg
positivity
#align measure_theory.mem_ℒp.exists_has_compact_support_integral_rpow_sub_le MeasureTheory.Memℒp.exists_hasCompactSupport_integral_rpow_sub_le
/-- In a locally compact space, any integrable function can be approximated by compactly supported
continuous functions, version in terms of `∫⁻`. -/
theorem Integrable.exists_hasCompactSupport_lintegral_sub_le
[WeaklyLocallyCompactSpace α] [μ.Regular]
{f : α → E} (hf : Integrable f μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ g : α → E,
HasCompactSupport g ∧ (∫⁻ x, ‖f x - g x‖₊ ∂μ) ≤ ε ∧ Continuous g ∧ Integrable g μ := by
simp only [← memℒp_one_iff_integrable, ← snorm_one_eq_lintegral_nnnorm] at hf ⊢
exact hf.exists_hasCompactSupport_snorm_sub_le ENNReal.one_ne_top hε
#align measure_theory.integrable.exists_has_compact_support_lintegral_sub_le MeasureTheory.Integrable.exists_hasCompactSupport_lintegral_sub_le
/-- In a locally compact space, any integrable function can be approximated by compactly supported
continuous functions, version in terms of `∫`. -/
theorem Integrable.exists_hasCompactSupport_integral_sub_le
[WeaklyLocallyCompactSpace α] [μ.Regular]
{f : α → E} (hf : Integrable f μ) {ε : ℝ} (hε : 0 < ε) :
∃ g : α → E, HasCompactSupport g ∧ (∫ x, ‖f x - g x‖ ∂μ) ≤ ε ∧
Continuous g ∧ Integrable g μ := by
simp only [← memℒp_one_iff_integrable, ← snorm_one_eq_lintegral_nnnorm, ← ENNReal.ofReal_one]
at hf ⊢
simpa using hf.exists_hasCompactSupport_integral_rpow_sub_le zero_lt_one hε
#align measure_theory.integrable.exists_has_compact_support_integral_sub_le MeasureTheory.Integrable.exists_hasCompactSupport_integral_sub_le
/-- Any function in `ℒp` can be approximated by bounded continuous functions when `p < ∞`,
version in terms of `snorm`. -/
theorem Memℒp.exists_boundedContinuous_snorm_sub_le [μ.WeaklyRegular] (hp : p ≠ ∞) {f : α → E}
(hf : Memℒp f p μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ g : α →ᵇ E, snorm (f - (g : α → E)) p μ ≤ ε ∧ Memℒp g p μ := by
suffices H :
∃ g : α → E, snorm (f - g) p μ ≤ ε ∧ Continuous g ∧ Memℒp g p μ ∧ IsBounded (range g) by
rcases H with ⟨g, hg, g_cont, g_mem, g_bd⟩
exact ⟨⟨⟨g, g_cont⟩, Metric.isBounded_range_iff.1 g_bd⟩, hg, g_mem⟩
-- It suffices to check that the set of functions we consider approximates characteristic
-- functions, is stable under addition and made of ae strongly measurable functions.
-- First check the latter easy facts.
apply hf.induction_dense hp _ _ _ _ hε
rotate_left
-- stability under addition
· rintro f g ⟨f_cont, f_mem, f_bd⟩ ⟨g_cont, g_mem, g_bd⟩
refine ⟨f_cont.add g_cont, f_mem.add g_mem, ?_⟩
let f' : α →ᵇ E := ⟨⟨f, f_cont⟩, Metric.isBounded_range_iff.1 f_bd⟩
let g' : α →ᵇ E := ⟨⟨g, g_cont⟩, Metric.isBounded_range_iff.1 g_bd⟩
exact (f' + g').isBounded_range
-- ae strong measurability
· exact fun f ⟨_, h, _⟩ => h.aestronglyMeasurable
-- We are left with approximating characteristic functions.
-- This follows from `exists_continuous_snorm_sub_le_of_closed`.
intro c t ht htμ ε hε
rcases exists_Lp_half E μ p hε with ⟨δ, δpos, hδ⟩
obtain ⟨η, ηpos, hη⟩ :
∃ η : ℝ≥0, 0 < η ∧ ∀ s : Set α, μ s ≤ η → snorm (s.indicator fun _x => c) p μ ≤ δ :=
exists_snorm_indicator_le hp c δpos.ne'
have hη_pos' : (0 : ℝ≥0∞) < η := ENNReal.coe_pos.2 ηpos
obtain ⟨s, st, s_closed, μs⟩ : ∃ s, s ⊆ t ∧ IsClosed s ∧ μ (t \ s) < η :=
ht.exists_isClosed_diff_lt htμ.ne hη_pos'.ne'
have hsμ : μ s < ∞ := (measure_mono st).trans_lt htμ
have I1 : snorm ((s.indicator fun _y => c) - t.indicator fun _y => c) p μ ≤ δ := by
rw [← snorm_neg, neg_sub, ← indicator_diff st]
exact hη _ μs.le
rcases exists_continuous_snorm_sub_le_of_closed hp s_closed isOpen_univ (subset_univ _) hsμ.ne c
δpos.ne' with
⟨f, f_cont, I2, f_bound, -, f_mem⟩
have I3 : snorm (f - t.indicator fun _y => c) p μ ≤ ε := by
convert
(hδ _ _
(f_mem.aestronglyMeasurable.sub
(aestronglyMeasurable_const.indicator s_closed.measurableSet))
((aestronglyMeasurable_const.indicator s_closed.measurableSet).sub
(aestronglyMeasurable_const.indicator ht))
I2 I1).le using 2
simp only [sub_add_sub_cancel]
refine ⟨f, I3, f_cont, f_mem, ?_⟩
exact (BoundedContinuousFunction.ofNormedAddCommGroup f f_cont _ f_bound).isBounded_range
#align measure_theory.mem_ℒp.exists_bounded_continuous_snorm_sub_le MeasureTheory.Memℒp.exists_boundedContinuous_snorm_sub_le
/-- Any function in `ℒp` can be approximated by bounded continuous functions when `0 < p < ∞`,
version in terms of `∫`. -/
theorem Memℒp.exists_boundedContinuous_integral_rpow_sub_le [μ.WeaklyRegular] {p : ℝ} (hp : 0 < p)
{f : α → E} (hf : Memℒp f (ENNReal.ofReal p) μ) {ε : ℝ} (hε : 0 < ε) :
∃ g : α →ᵇ E, (∫ x, ‖f x - g x‖ ^ p ∂μ) ≤ ε ∧ Memℒp g (ENNReal.ofReal p) μ := by
have I : 0 < ε ^ (1 / p) := Real.rpow_pos_of_pos hε _
have A : ENNReal.ofReal (ε ^ (1 / p)) ≠ 0 := by
simp only [Ne, ENNReal.ofReal_eq_zero, not_le, I]
have B : ENNReal.ofReal p ≠ 0 := by simpa only [Ne, ENNReal.ofReal_eq_zero, not_le] using hp
rcases hf.exists_boundedContinuous_snorm_sub_le ENNReal.coe_ne_top A with ⟨g, hg, g_mem⟩
change snorm _ (ENNReal.ofReal p) _ ≤ _ at hg
refine ⟨g, ?_, g_mem⟩
rwa [(hf.sub g_mem).snorm_eq_integral_rpow_norm B ENNReal.coe_ne_top,
ENNReal.ofReal_le_ofReal_iff I.le, one_div, ENNReal.toReal_ofReal hp.le,
Real.rpow_le_rpow_iff _ hε.le (inv_pos.2 hp)] at hg
positivity
#align measure_theory.mem_ℒp.exists_bounded_continuous_integral_rpow_sub_le MeasureTheory.Memℒp.exists_boundedContinuous_integral_rpow_sub_le
/-- Any integrable function can be approximated by bounded continuous functions,
version in terms of `∫⁻`. -/
theorem Integrable.exists_boundedContinuous_lintegral_sub_le [μ.WeaklyRegular] {f : α → E}
(hf : Integrable f μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ g : α →ᵇ E, (∫⁻ x, ‖f x - g x‖₊ ∂μ) ≤ ε ∧ Integrable g μ := by
simp only [← memℒp_one_iff_integrable, ← snorm_one_eq_lintegral_nnnorm] at hf ⊢
exact hf.exists_boundedContinuous_snorm_sub_le ENNReal.one_ne_top hε
#align measure_theory.integrable.exists_bounded_continuous_lintegral_sub_le MeasureTheory.Integrable.exists_boundedContinuous_lintegral_sub_le
/-- Any integrable function can be approximated by bounded continuous functions,
version in terms of `∫`. -/
theorem Integrable.exists_boundedContinuous_integral_sub_le [μ.WeaklyRegular] {f : α → E}
(hf : Integrable f μ) {ε : ℝ} (hε : 0 < ε) :
∃ g : α →ᵇ E, (∫ x, ‖f x - g x‖ ∂μ) ≤ ε ∧ Integrable g μ := by
simp only [← memℒp_one_iff_integrable, ← snorm_one_eq_lintegral_nnnorm, ← ENNReal.ofReal_one]
at hf ⊢
simpa using hf.exists_boundedContinuous_integral_rpow_sub_le zero_lt_one hε
#align measure_theory.integrable.exists_bounded_continuous_integral_sub_le MeasureTheory.Integrable.exists_boundedContinuous_integral_sub_le
namespace Lp
variable (E μ)
/-- A function in `Lp` can be approximated in `Lp` by continuous functions. -/
theorem boundedContinuousFunction_dense [SecondCountableTopologyEither α E] [Fact (1 ≤ p)]
(hp : p ≠ ∞) [μ.WeaklyRegular] :
Dense (boundedContinuousFunction E p μ : Set (Lp E p μ)) := by
intro f
refine (mem_closure_iff_nhds_basis EMetric.nhds_basis_closed_eball).2 fun ε hε ↦ ?_
obtain ⟨g, hg, g_mem⟩ :
∃ g : α →ᵇ E, snorm ((f : α → E) - (g : α → E)) p μ ≤ ε ∧ Memℒp g p μ :=
(Lp.memℒp f).exists_boundedContinuous_snorm_sub_le hp hε.ne'
refine ⟨g_mem.toLp _, ⟨g, rfl⟩, ?_⟩
rwa [EMetric.mem_closedBall', ← Lp.toLp_coeFn f (Lp.memℒp f), Lp.edist_toLp_toLp]
/-- A function in `Lp` can be approximated in `Lp` by continuous functions. -/
theorem boundedContinuousFunction_topologicalClosure [SecondCountableTopologyEither α E]
[Fact (1 ≤ p)] (hp : p ≠ ∞) [μ.WeaklyRegular] :
(boundedContinuousFunction E p μ).topologicalClosure = ⊤ :=
SetLike.ext' <| (boundedContinuousFunction_dense E μ hp).closure_eq
set_option linter.uppercaseLean3 false in
#align measure_theory.Lp.bounded_continuous_function_dense MeasureTheory.Lp.boundedContinuousFunction_topologicalClosure
end Lp
end MeasureTheory
variable [SecondCountableTopologyEither α E] [_i : Fact (1 ≤ p)] (hp : p ≠ ∞)
variable (𝕜 : Type*) [NormedField 𝕜] [NormedAlgebra ℝ 𝕜] [NormedSpace 𝕜 E]
variable (E) (μ)
namespace BoundedContinuousFunction
theorem toLp_denseRange [μ.WeaklyRegular] [IsFiniteMeasure μ] :
DenseRange (toLp p μ 𝕜 : (α →ᵇ E) →L[𝕜] Lp E p μ) := by
haveI : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E
simpa only [← range_toLp p μ (𝕜 := 𝕜)]
using MeasureTheory.Lp.boundedContinuousFunction_dense E μ hp
set_option linter.uppercaseLean3 false in
#align bounded_continuous_function.to_Lp_dense_range BoundedContinuousFunction.toLp_denseRange
end BoundedContinuousFunction
namespace ContinuousMap
/-- Continuous functions are dense in `MeasureTheory.Lp`, `1 ≤ p < ∞`. This theorem assumes that
the domain is a compact space because otherwise `ContinuousMap.toLp` is undefined. Use
`BoundedContinuousFunction.toLp_denseRange` if the domain is not a compact space. -/
| Mathlib/MeasureTheory/Function/ContinuousMapDense.lean | 374 | 378 | theorem toLp_denseRange [CompactSpace α] [μ.WeaklyRegular] [IsFiniteMeasure μ] :
DenseRange (toLp p μ 𝕜 : C(α, E) →L[𝕜] Lp E p μ) := by |
refine (BoundedContinuousFunction.toLp_denseRange _ _ hp 𝕜).mono ?_
refine range_subset_iff.2 fun f ↦ ?_
exact ⟨f.toContinuousMap, rfl⟩
|
/-
Copyright (c) 2021 Henry Swanson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henry Swanson
-/
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Combinatorics.Derangements.Basic
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Tactic.Ring
#align_import combinatorics.derangements.finite from "leanprover-community/mathlib"@"c3019c79074b0619edb4b27553a91b2e82242395"
/-!
# Derangements on fintypes
This file contains lemmas that describe the cardinality of `derangements α` when `α` is a fintype.
# Main definitions
* `card_derangements_invariant`: A lemma stating that the number of derangements on a type `α`
depends only on the cardinality of `α`.
* `numDerangements n`: The number of derangements on an n-element set, defined in a computation-
friendly way.
* `card_derangements_eq_numDerangements`: Proof that `numDerangements` really does compute the
number of derangements.
* `numDerangements_sum`: A lemma giving an expression for `numDerangements n` in terms of
factorials.
-/
open derangements Equiv Fintype
variable {α : Type*} [DecidableEq α] [Fintype α]
instance : DecidablePred (derangements α) := fun _ => Fintype.decidableForallFintype
-- Porting note: used to use the tactic delta_instance
instance : Fintype (derangements α) := Subtype.fintype (fun (_ : Perm α) => ∀ (x_1 : α), ¬_ = x_1)
theorem card_derangements_invariant {α β : Type*} [Fintype α] [DecidableEq α] [Fintype β]
[DecidableEq β] (h : card α = card β) : card (derangements α) = card (derangements β) :=
Fintype.card_congr (Equiv.derangementsCongr <| equivOfCardEq h)
#align card_derangements_invariant card_derangements_invariant
theorem card_derangements_fin_add_two (n : ℕ) :
card (derangements (Fin (n + 2))) =
(n + 1) * card (derangements (Fin n)) + (n + 1) * card (derangements (Fin (n + 1))) := by
-- get some basic results about the size of fin (n+1) plus or minus an element
have h1 : ∀ a : Fin (n + 1), card ({a}ᶜ : Set (Fin (n + 1))) = card (Fin n) := by
intro a
simp only [Fintype.card_fin, Finset.card_fin, Fintype.card_ofFinset, Finset.filter_ne' _ a,
Set.mem_compl_singleton_iff, Finset.card_erase_of_mem (Finset.mem_univ a),
add_tsub_cancel_right]
have h2 : card (Fin (n + 2)) = card (Option (Fin (n + 1))) := by simp only [card_fin, card_option]
-- rewrite the LHS and substitute in our fintype-level equivalence
simp only [card_derangements_invariant h2,
card_congr
(@derangementsRecursionEquiv (Fin (n + 1))
_),-- push the cardinality through the Σ and ⊕ so that we can use `card_n`
card_sigma,
card_sum, card_derangements_invariant (h1 _), Finset.sum_const, nsmul_eq_mul, Finset.card_fin,
mul_add, Nat.cast_id]
#align card_derangements_fin_add_two card_derangements_fin_add_two
/-- The number of derangements of an `n`-element set. -/
def numDerangements : ℕ → ℕ
| 0 => 1
| 1 => 0
| n + 2 => (n + 1) * (numDerangements n + numDerangements (n + 1))
#align num_derangements numDerangements
@[simp]
theorem numDerangements_zero : numDerangements 0 = 1 :=
rfl
#align num_derangements_zero numDerangements_zero
@[simp]
theorem numDerangements_one : numDerangements 1 = 0 :=
rfl
#align num_derangements_one numDerangements_one
theorem numDerangements_add_two (n : ℕ) :
numDerangements (n + 2) = (n + 1) * (numDerangements n + numDerangements (n + 1)) :=
rfl
#align num_derangements_add_two numDerangements_add_two
theorem numDerangements_succ (n : ℕ) :
(numDerangements (n + 1) : ℤ) = (n + 1) * (numDerangements n : ℤ) - (-1) ^ n := by
induction' n with n hn
· rfl
· simp only [numDerangements_add_two, hn, pow_succ, Int.ofNat_mul, Int.ofNat_add, Int.ofNat_succ]
ring
#align num_derangements_succ numDerangements_succ
theorem card_derangements_fin_eq_numDerangements {n : ℕ} :
card (derangements (Fin n)) = numDerangements n := by
induction' n using Nat.strong_induction_on with n hyp
rcases n with _ | _ | n
-- knock out cases 0 and 1
· rfl
· rfl
-- now we have n ≥ 2. rewrite everything in terms of card_derangements, so that we can use
-- `card_derangements_fin_add_two`
rw [numDerangements_add_two, card_derangements_fin_add_two, mul_add, hyp, hyp] <;> omega
#align card_derangements_fin_eq_num_derangements card_derangements_fin_eq_numDerangements
| Mathlib/Combinatorics/Derangements/Finite.lean | 107 | 110 | theorem card_derangements_eq_numDerangements (α : Type*) [Fintype α] [DecidableEq α] :
card (derangements α) = numDerangements (card α) := by |
rw [← card_derangements_invariant (card_fin _)]
exact card_derangements_fin_eq_numDerangements
|
/-
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
-/
import Mathlib.MeasureTheory.Measure.Dirac
/-!
# Counting measure
In this file we define the counting measure `MeasurTheory.Measure.count`
as `MeasureTheory.Measure.sum MeasureTheory.Measure.dirac`
and prove basic properties of this measure.
-/
set_option autoImplicit true
open Set
open scoped ENNReal Classical
variable [MeasurableSpace α] [MeasurableSpace β] {s : Set α}
noncomputable section
namespace MeasureTheory.Measure
/-- Counting measure on any measurable space. -/
def count : Measure α :=
sum dirac
#align measure_theory.measure.count MeasureTheory.Measure.count
theorem le_count_apply : ∑' _ : s, (1 : ℝ≥0∞) ≤ count s :=
calc
(∑' _ : s, 1 : ℝ≥0∞) = ∑' i, indicator s 1 i := tsum_subtype s 1
_ ≤ ∑' i, dirac i s := ENNReal.tsum_le_tsum fun _ => le_dirac_apply
_ ≤ count s := le_sum_apply _ _
#align measure_theory.measure.le_count_apply MeasureTheory.Measure.le_count_apply
| Mathlib/MeasureTheory/Measure/Count.lean | 39 | 40 | theorem count_apply (hs : MeasurableSet s) : count s = ∑' i : s, 1 := by |
simp only [count, sum_apply, hs, dirac_apply', ← tsum_subtype s (1 : α → ℝ≥0∞), Pi.one_apply]
|
/-
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
| Mathlib/MeasureTheory/Integral/SetIntegral.lean | 498 | 520 | 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]
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.CharP.Two
import Mathlib.Algebra.CharP.Reduced
import Mathlib.Algebra.NeZero
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.GroupTheory.SpecificGroups.Cyclic
import Mathlib.NumberTheory.Divisors
import Mathlib.RingTheory.IntegralDomain
import Mathlib.Tactic.Zify
#align_import ring_theory.roots_of_unity.basic from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f"
/-!
# Roots of unity and primitive roots of unity
We define roots of unity in the context of an arbitrary commutative monoid,
as a subgroup of the group of units. We also define a predicate `IsPrimitiveRoot` on commutative
monoids, expressing that an element is a primitive root of unity.
## Main definitions
* `rootsOfUnity n M`, for `n : ℕ+` is the subgroup of the units of a commutative monoid `M`
consisting of elements `x` that satisfy `x ^ n = 1`.
* `IsPrimitiveRoot ζ k`: an element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`,
and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`.
* `primitiveRoots k R`: the finset of primitive `k`-th roots of unity in an integral domain `R`.
* `IsPrimitiveRoot.autToPow`: the monoid hom that takes an automorphism of a ring to the power
it sends that specific primitive root, as a member of `(ZMod n)ˣ`.
## Main results
* `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group.
* `IsPrimitiveRoot.zmodEquivZPowers`: `ZMod k` is equivalent to
the subgroup generated by a primitive `k`-th root of unity.
* `IsPrimitiveRoot.zpowers_eq`: in an integral domain, the subgroup generated by
a primitive `k`-th root of unity is equal to the `k`-th roots of unity.
* `IsPrimitiveRoot.card_primitiveRoots`: if an integral domain
has a primitive `k`-th root of unity, then it has `φ k` of them.
## Implementation details
It is desirable that `rootsOfUnity` is a subgroup,
and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields.
We therefore implement it as a subgroup of the units of a commutative monoid.
We have chosen to define `rootsOfUnity n` for `n : ℕ+`, instead of `n : ℕ`,
because almost all lemmas need the positivity assumption,
and in particular the type class instances for `Fintype` and `IsCyclic`.
On the other hand, for primitive roots of unity, it is desirable to have a predicate
not just on units, but directly on elements of the ring/field.
For example, we want to say that `exp (2 * pi * I / n)` is a primitive `n`-th root of unity
in the complex numbers, without having to turn that number into a unit first.
This creates a little bit of friction, but lemmas like `IsPrimitiveRoot.isUnit` and
`IsPrimitiveRoot.coe_units_iff` should provide the necessary glue.
-/
open scoped Classical Polynomial
noncomputable section
open Polynomial
open Finset
variable {M N G R S F : Type*}
variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G]
section rootsOfUnity
variable {k l : ℕ+}
/-- `rootsOfUnity k M` is the subgroup of elements `m : Mˣ` that satisfy `m ^ k = 1`. -/
def rootsOfUnity (k : ℕ+) (M : Type*) [CommMonoid M] : Subgroup Mˣ where
carrier := {ζ | ζ ^ (k : ℕ) = 1}
one_mem' := one_pow _
mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul]
inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one]
#align roots_of_unity rootsOfUnity
@[simp]
theorem mem_rootsOfUnity (k : ℕ+) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ ζ ^ (k : ℕ) = 1 :=
Iff.rfl
#align mem_roots_of_unity mem_rootsOfUnity
theorem mem_rootsOfUnity' (k : ℕ+) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ (ζ : M) ^ (k : ℕ) = 1 := by
rw [mem_rootsOfUnity]; norm_cast
#align mem_roots_of_unity' mem_rootsOfUnity'
@[simp]
theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = ⊥ := by ext; simp
theorem rootsOfUnity.coe_injective {n : ℕ+} :
Function.Injective (fun x : rootsOfUnity n M ↦ x.val.val) :=
Units.ext.comp fun _ _ => Subtype.eq
#align roots_of_unity.coe_injective rootsOfUnity.coe_injective
/-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has
a positive power equal to one. -/
@[simps! coe_val]
def rootsOfUnity.mkOfPowEq (ζ : M) {n : ℕ+} (h : ζ ^ (n : ℕ) = 1) : rootsOfUnity n M :=
⟨Units.ofPowEqOne ζ n h n.ne_zero, Units.pow_ofPowEqOne _ _⟩
#align roots_of_unity.mk_of_pow_eq rootsOfUnity.mkOfPowEq
#align roots_of_unity.mk_of_pow_eq_coe_coe rootsOfUnity.val_mkOfPowEq_coe
@[simp]
theorem rootsOfUnity.coe_mkOfPowEq {ζ : M} {n : ℕ+} (h : ζ ^ (n : ℕ) = 1) :
((rootsOfUnity.mkOfPowEq _ h : Mˣ) : M) = ζ :=
rfl
#align roots_of_unity.coe_mk_of_pow_eq rootsOfUnity.coe_mkOfPowEq
theorem rootsOfUnity_le_of_dvd (h : k ∣ l) : rootsOfUnity k M ≤ rootsOfUnity l M := by
obtain ⟨d, rfl⟩ := h
intro ζ h
simp_all only [mem_rootsOfUnity, PNat.mul_coe, pow_mul, one_pow]
#align roots_of_unity_le_of_dvd rootsOfUnity_le_of_dvd
theorem map_rootsOfUnity (f : Mˣ →* Nˣ) (k : ℕ+) : (rootsOfUnity k M).map f ≤ rootsOfUnity k N := by
rintro _ ⟨ζ, h, rfl⟩
simp_all only [← map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one]
#align map_roots_of_unity map_rootsOfUnity
@[norm_cast]
theorem rootsOfUnity.coe_pow [CommMonoid R] (ζ : rootsOfUnity k R) (m : ℕ) :
(((ζ ^ m :) : Rˣ) : R) = ((ζ : Rˣ) : R) ^ m := by
rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val]
#align roots_of_unity.coe_pow rootsOfUnity.coe_pow
section CommMonoid
variable [CommMonoid R] [CommMonoid S] [FunLike F R S]
/-- Restrict a ring homomorphism to the nth roots of unity. -/
def restrictRootsOfUnity [MonoidHomClass F R S] (σ : F) (n : ℕ+) :
rootsOfUnity n R →* rootsOfUnity n S :=
let h : ∀ ξ : rootsOfUnity n R, (σ (ξ : Rˣ)) ^ (n : ℕ) = 1 := fun ξ => by
rw [← map_pow, ← Units.val_pow_eq_pow_val, show (ξ : Rˣ) ^ (n : ℕ) = 1 from ξ.2, Units.val_one,
map_one σ]
{ toFun := fun ξ =>
⟨@unitOfInvertible _ _ _ (invertibleOfPowEqOne _ _ (h ξ) n.ne_zero), by
ext; rw [Units.val_pow_eq_pow_val]; exact h ξ⟩
map_one' := by ext; exact map_one σ
map_mul' := fun ξ₁ ξ₂ => by ext; rw [Subgroup.coe_mul, Units.val_mul]; exact map_mul σ _ _ }
#align restrict_roots_of_unity restrictRootsOfUnity
@[simp]
theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (σ : F) (ζ : rootsOfUnity k R) :
(restrictRootsOfUnity σ k ζ : Sˣ) = σ (ζ : Rˣ) :=
rfl
#align restrict_roots_of_unity_coe_apply restrictRootsOfUnity_coe_apply
/-- Restrict a monoid isomorphism to the nth roots of unity. -/
nonrec def MulEquiv.restrictRootsOfUnity (σ : R ≃* S) (n : ℕ+) :
rootsOfUnity n R ≃* rootsOfUnity n S where
toFun := restrictRootsOfUnity σ n
invFun := restrictRootsOfUnity σ.symm n
left_inv ξ := by ext; exact σ.symm_apply_apply (ξ : Rˣ)
right_inv ξ := by ext; exact σ.apply_symm_apply (ξ : Sˣ)
map_mul' := (restrictRootsOfUnity _ n).map_mul
#align ring_equiv.restrict_roots_of_unity MulEquiv.restrictRootsOfUnity
@[simp]
theorem MulEquiv.restrictRootsOfUnity_coe_apply (σ : R ≃* S) (ζ : rootsOfUnity k R) :
(σ.restrictRootsOfUnity k ζ : Sˣ) = σ (ζ : Rˣ) :=
rfl
#align ring_equiv.restrict_roots_of_unity_coe_apply MulEquiv.restrictRootsOfUnity_coe_apply
@[simp]
theorem MulEquiv.restrictRootsOfUnity_symm (σ : R ≃* S) :
(σ.restrictRootsOfUnity k).symm = σ.symm.restrictRootsOfUnity k :=
rfl
#align ring_equiv.restrict_roots_of_unity_symm MulEquiv.restrictRootsOfUnity_symm
end CommMonoid
section IsDomain
variable [CommRing R] [IsDomain R]
theorem mem_rootsOfUnity_iff_mem_nthRoots {ζ : Rˣ} :
ζ ∈ rootsOfUnity k R ↔ (ζ : R) ∈ nthRoots k (1 : R) := by
simp only [mem_rootsOfUnity, mem_nthRoots k.pos, Units.ext_iff, Units.val_one,
Units.val_pow_eq_pow_val]
#align mem_roots_of_unity_iff_mem_nth_roots mem_rootsOfUnity_iff_mem_nthRoots
variable (k R)
/-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`.
This is implemented as equivalence of subtypes,
because `rootsOfUnity` is a subgroup of the group of units,
whereas `nthRoots` is a multiset. -/
def rootsOfUnityEquivNthRoots : rootsOfUnity k R ≃ { x // x ∈ nthRoots k (1 : R) } where
toFun x := ⟨(x : Rˣ), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2⟩
invFun x := by
refine ⟨⟨x, ↑x ^ (k - 1 : ℕ), ?_, ?_⟩, ?_⟩
all_goals
rcases x with ⟨x, hx⟩; rw [mem_nthRoots k.pos] at hx
simp only [Subtype.coe_mk, ← pow_succ, ← pow_succ', hx,
tsub_add_cancel_of_le (show 1 ≤ (k : ℕ) from k.one_le)]
show (_ : Rˣ) ^ (k : ℕ) = 1
simp only [Units.ext_iff, hx, Units.val_mk, Units.val_one, Subtype.coe_mk,
Units.val_pow_eq_pow_val]
left_inv := by rintro ⟨x, hx⟩; ext; rfl
right_inv := by rintro ⟨x, hx⟩; ext; rfl
#align roots_of_unity_equiv_nth_roots rootsOfUnityEquivNthRoots
variable {k R}
@[simp]
theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) :
(rootsOfUnityEquivNthRoots R k x : R) = ((x : Rˣ) : R) :=
rfl
#align roots_of_unity_equiv_nth_roots_apply rootsOfUnityEquivNthRoots_apply
@[simp]
theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x ∈ nthRoots k (1 : R) }) :
(((rootsOfUnityEquivNthRoots R k).symm x : Rˣ) : R) = (x : R) :=
rfl
#align roots_of_unity_equiv_nth_roots_symm_apply rootsOfUnityEquivNthRoots_symm_apply
variable (k R)
instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) :=
Fintype.ofEquiv { x // x ∈ nthRoots k (1 : R) } <| (rootsOfUnityEquivNthRoots R k).symm
#align roots_of_unity.fintype rootsOfUnity.fintype
instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) :=
isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype)
(Units.ext.comp Subtype.val_injective)
#align roots_of_unity.is_cyclic rootsOfUnity.isCyclic
theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) ≤ k :=
calc
Fintype.card (rootsOfUnity k R) = Fintype.card { x // x ∈ nthRoots k (1 : R) } :=
Fintype.card_congr (rootsOfUnityEquivNthRoots R k)
_ ≤ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _)
_ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach
_ ≤ k := card_nthRoots k 1
#align card_roots_of_unity card_rootsOfUnity
variable {k R}
theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [RingHomClass F R R] (σ : F)
(ζ : rootsOfUnity k R) :
∃ m : ℕ, σ (ζ : Rˣ) = ((ζ : Rˣ) : R) ^ m := by
obtain ⟨m, hm⟩ := MonoidHom.map_cyclic (restrictRootsOfUnity σ k)
rw [← restrictRootsOfUnity_coe_apply, hm, ← zpow_mod_orderOf, ← Int.toNat_of_nonneg
(m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ζ)))),
zpow_natCast, rootsOfUnity.coe_pow]
exact ⟨(m % orderOf ζ).toNat, rfl⟩
#align map_root_of_unity_eq_pow_self map_rootsOfUnity_eq_pow_self
end IsDomain
section Reduced
variable (R) [CommRing R] [IsReduced R]
-- @[simp] -- Porting note: simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'`
theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : ℕ) (m : ℕ+) [ExpChar R p]
{ζ : Rˣ} : ζ ∈ rootsOfUnity (⟨p, expChar_pos R p⟩ ^ k * m) R ↔ ζ ∈ rootsOfUnity m R := by
simp only [mem_rootsOfUnity', PNat.mul_coe, PNat.pow_coe, PNat.mk_coe,
ExpChar.pow_prime_pow_mul_eq_one_iff]
#align mem_roots_of_unity_prime_pow_mul_iff mem_rootsOfUnity_prime_pow_mul_iff
@[simp]
theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : ℕ) (m : ℕ+) [ExpChar R p]
{ζ : Rˣ} : ζ ^ (p ^ k * ↑m) = 1 ↔ ζ ∈ rootsOfUnity m R := by
rw [← PNat.mk_coe p (expChar_pos R p), ← PNat.pow_coe, ← PNat.mul_coe, ← mem_rootsOfUnity,
mem_rootsOfUnity_prime_pow_mul_iff]
end Reduced
end rootsOfUnity
/-- An element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`,
and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`. -/
@[mk_iff IsPrimitiveRoot.iff_def]
structure IsPrimitiveRoot (ζ : M) (k : ℕ) : Prop where
pow_eq_one : ζ ^ (k : ℕ) = 1
dvd_of_pow_eq_one : ∀ l : ℕ, ζ ^ l = 1 → k ∣ l
#align is_primitive_root IsPrimitiveRoot
#align is_primitive_root.iff_def IsPrimitiveRoot.iff_def
/-- Turn a primitive root μ into a member of the `rootsOfUnity` subgroup. -/
@[simps!]
def IsPrimitiveRoot.toRootsOfUnity {μ : M} {n : ℕ+} (h : IsPrimitiveRoot μ n) : rootsOfUnity n M :=
rootsOfUnity.mkOfPowEq μ h.pow_eq_one
#align is_primitive_root.to_roots_of_unity IsPrimitiveRoot.toRootsOfUnity
#align is_primitive_root.coe_to_roots_of_unity_coe IsPrimitiveRoot.val_toRootsOfUnity_coe
#align is_primitive_root.coe_inv_to_roots_of_unity_coe IsPrimitiveRoot.val_inv_toRootsOfUnity_coe
section primitiveRoots
variable {k : ℕ}
/-- `primitiveRoots k R` is the finset of primitive `k`-th roots of unity
in the integral domain `R`. -/
def primitiveRoots (k : ℕ) (R : Type*) [CommRing R] [IsDomain R] : Finset R :=
(nthRoots k (1 : R)).toFinset.filter fun ζ => IsPrimitiveRoot ζ k
#align primitive_roots primitiveRoots
variable [CommRing R] [IsDomain R]
@[simp]
theorem mem_primitiveRoots {ζ : R} (h0 : 0 < k) : ζ ∈ primitiveRoots k R ↔ IsPrimitiveRoot ζ k := by
rw [primitiveRoots, mem_filter, Multiset.mem_toFinset, mem_nthRoots h0, and_iff_right_iff_imp]
exact IsPrimitiveRoot.pow_eq_one
#align mem_primitive_roots mem_primitiveRoots
@[simp]
theorem primitiveRoots_zero : primitiveRoots 0 R = ∅ := by
rw [primitiveRoots, nthRoots_zero, Multiset.toFinset_zero, Finset.filter_empty]
#align primitive_roots_zero primitiveRoots_zero
theorem isPrimitiveRoot_of_mem_primitiveRoots {ζ : R} (h : ζ ∈ primitiveRoots k R) :
IsPrimitiveRoot ζ k :=
k.eq_zero_or_pos.elim (fun hk => by simp [hk] at h) fun hk => (mem_primitiveRoots hk).1 h
#align is_primitive_root_of_mem_primitive_roots isPrimitiveRoot_of_mem_primitiveRoots
end primitiveRoots
namespace IsPrimitiveRoot
variable {k l : ℕ}
theorem mk_of_lt (ζ : M) (hk : 0 < k) (h1 : ζ ^ k = 1) (h : ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1) :
IsPrimitiveRoot ζ k := by
refine ⟨h1, fun l hl => ?_⟩
suffices k.gcd l = k by exact this ▸ k.gcd_dvd_right l
rw [eq_iff_le_not_lt]
refine ⟨Nat.le_of_dvd hk (k.gcd_dvd_left l), ?_⟩
intro h'; apply h _ (Nat.gcd_pos_of_pos_left _ hk) h'
exact pow_gcd_eq_one _ h1 hl
#align is_primitive_root.mk_of_lt IsPrimitiveRoot.mk_of_lt
section CommMonoid
variable {ζ : M} {f : F} (h : IsPrimitiveRoot ζ k)
@[nontriviality]
theorem of_subsingleton [Subsingleton M] (x : M) : IsPrimitiveRoot x 1 :=
⟨Subsingleton.elim _ _, fun _ _ => one_dvd _⟩
#align is_primitive_root.of_subsingleton IsPrimitiveRoot.of_subsingleton
theorem pow_eq_one_iff_dvd (l : ℕ) : ζ ^ l = 1 ↔ k ∣ l :=
⟨h.dvd_of_pow_eq_one l, by
rintro ⟨i, rfl⟩; simp only [pow_mul, h.pow_eq_one, one_pow, PNat.mul_coe]⟩
#align is_primitive_root.pow_eq_one_iff_dvd IsPrimitiveRoot.pow_eq_one_iff_dvd
theorem isUnit (h : IsPrimitiveRoot ζ k) (h0 : 0 < k) : IsUnit ζ := by
apply isUnit_of_mul_eq_one ζ (ζ ^ (k - 1))
rw [← pow_succ', tsub_add_cancel_of_le h0.nat_succ_le, h.pow_eq_one]
#align is_primitive_root.is_unit IsPrimitiveRoot.isUnit
theorem pow_ne_one_of_pos_of_lt (h0 : 0 < l) (hl : l < k) : ζ ^ l ≠ 1 :=
mt (Nat.le_of_dvd h0 ∘ h.dvd_of_pow_eq_one _) <| not_le_of_lt hl
#align is_primitive_root.pow_ne_one_of_pos_of_lt IsPrimitiveRoot.pow_ne_one_of_pos_of_lt
theorem ne_one (hk : 1 < k) : ζ ≠ 1 :=
h.pow_ne_one_of_pos_of_lt zero_lt_one hk ∘ (pow_one ζ).trans
#align is_primitive_root.ne_one IsPrimitiveRoot.ne_one
theorem pow_inj (h : IsPrimitiveRoot ζ k) ⦃i j : ℕ⦄ (hi : i < k) (hj : j < k) (H : ζ ^ i = ζ ^ j) :
i = j := by
wlog hij : i ≤ j generalizing i j
· exact (this hj hi H.symm (le_of_not_le hij)).symm
apply le_antisymm hij
rw [← tsub_eq_zero_iff_le]
apply Nat.eq_zero_of_dvd_of_lt _ (lt_of_le_of_lt tsub_le_self hj)
apply h.dvd_of_pow_eq_one
rw [← ((h.isUnit (lt_of_le_of_lt (Nat.zero_le _) hi)).pow i).mul_left_inj, ← pow_add,
tsub_add_cancel_of_le hij, H, one_mul]
#align is_primitive_root.pow_inj IsPrimitiveRoot.pow_inj
theorem one : IsPrimitiveRoot (1 : M) 1 :=
{ pow_eq_one := pow_one _
dvd_of_pow_eq_one := fun _ _ => one_dvd _ }
#align is_primitive_root.one IsPrimitiveRoot.one
@[simp]
theorem one_right_iff : IsPrimitiveRoot ζ 1 ↔ ζ = 1 := by
clear h
constructor
· intro h; rw [← pow_one ζ, h.pow_eq_one]
· rintro rfl; exact one
#align is_primitive_root.one_right_iff IsPrimitiveRoot.one_right_iff
@[simp]
theorem coe_submonoidClass_iff {M B : Type*} [CommMonoid M] [SetLike B M] [SubmonoidClass B M]
{N : B} {ζ : N} : IsPrimitiveRoot (ζ : M) k ↔ IsPrimitiveRoot ζ k := by
simp_rw [iff_def]
norm_cast
#align is_primitive_root.coe_submonoid_class_iff IsPrimitiveRoot.coe_submonoidClass_iff
@[simp]
theorem coe_units_iff {ζ : Mˣ} : IsPrimitiveRoot (ζ : M) k ↔ IsPrimitiveRoot ζ k := by
simp only [iff_def, Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one]
#align is_primitive_root.coe_units_iff IsPrimitiveRoot.coe_units_iff
lemma isUnit_unit {ζ : M} {n} (hn) (hζ : IsPrimitiveRoot ζ n) :
IsPrimitiveRoot (hζ.isUnit hn).unit n := coe_units_iff.mp hζ
lemma isUnit_unit' {ζ : G} {n} (hn) (hζ : IsPrimitiveRoot ζ n) :
IsPrimitiveRoot (hζ.isUnit hn).unit' n := coe_units_iff.mp hζ
-- Porting note `variable` above already contains `(h : IsPrimitiveRoot ζ k)`
theorem pow_of_coprime (i : ℕ) (hi : i.Coprime k) : IsPrimitiveRoot (ζ ^ i) k := by
by_cases h0 : k = 0
· subst k; simp_all only [pow_one, Nat.coprime_zero_right]
rcases h.isUnit (Nat.pos_of_ne_zero h0) with ⟨ζ, rfl⟩
rw [← Units.val_pow_eq_pow_val]
rw [coe_units_iff] at h ⊢
refine
{ pow_eq_one := by rw [← pow_mul', pow_mul, h.pow_eq_one, one_pow]
dvd_of_pow_eq_one := ?_ }
intro l hl
apply h.dvd_of_pow_eq_one
rw [← pow_one ζ, ← zpow_natCast ζ, ← hi.gcd_eq_one, Nat.gcd_eq_gcd_ab, zpow_add, mul_pow,
← zpow_natCast, ← zpow_mul, mul_right_comm]
simp only [zpow_mul, hl, h.pow_eq_one, one_zpow, one_pow, one_mul, zpow_natCast]
#align is_primitive_root.pow_of_coprime IsPrimitiveRoot.pow_of_coprime
theorem pow_of_prime (h : IsPrimitiveRoot ζ k) {p : ℕ} (hprime : Nat.Prime p) (hdiv : ¬p ∣ k) :
IsPrimitiveRoot (ζ ^ p) k :=
h.pow_of_coprime p (hprime.coprime_iff_not_dvd.2 hdiv)
#align is_primitive_root.pow_of_prime IsPrimitiveRoot.pow_of_prime
theorem pow_iff_coprime (h : IsPrimitiveRoot ζ k) (h0 : 0 < k) (i : ℕ) :
IsPrimitiveRoot (ζ ^ i) k ↔ i.Coprime k := by
refine ⟨?_, h.pow_of_coprime i⟩
intro hi
obtain ⟨a, ha⟩ := i.gcd_dvd_left k
obtain ⟨b, hb⟩ := i.gcd_dvd_right k
suffices b = k by
-- Porting note: was `rwa [this, ← one_mul k, mul_left_inj' h0.ne', eq_comm] at hb`
rw [this, eq_comm, Nat.mul_left_eq_self_iff h0] at hb
rwa [Nat.Coprime]
rw [ha] at hi
rw [mul_comm] at hb
apply Nat.dvd_antisymm ⟨i.gcd k, hb⟩ (hi.dvd_of_pow_eq_one b _)
rw [← pow_mul', ← mul_assoc, ← hb, pow_mul, h.pow_eq_one, one_pow]
#align is_primitive_root.pow_iff_coprime IsPrimitiveRoot.pow_iff_coprime
protected theorem orderOf (ζ : M) : IsPrimitiveRoot ζ (orderOf ζ) :=
⟨pow_orderOf_eq_one ζ, fun _ => orderOf_dvd_of_pow_eq_one⟩
#align is_primitive_root.order_of IsPrimitiveRoot.orderOf
theorem unique {ζ : M} (hk : IsPrimitiveRoot ζ k) (hl : IsPrimitiveRoot ζ l) : k = l :=
Nat.dvd_antisymm (hk.2 _ hl.1) (hl.2 _ hk.1)
#align is_primitive_root.unique IsPrimitiveRoot.unique
theorem eq_orderOf : k = orderOf ζ :=
h.unique (IsPrimitiveRoot.orderOf ζ)
#align is_primitive_root.eq_order_of IsPrimitiveRoot.eq_orderOf
protected theorem iff (hk : 0 < k) :
IsPrimitiveRoot ζ k ↔ ζ ^ k = 1 ∧ ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1 := by
refine ⟨fun h => ⟨h.pow_eq_one, fun l hl' hl => ?_⟩,
fun ⟨hζ, hl⟩ => IsPrimitiveRoot.mk_of_lt ζ hk hζ hl⟩
rw [h.eq_orderOf] at hl
exact pow_ne_one_of_lt_orderOf' hl'.ne' hl
#align is_primitive_root.iff IsPrimitiveRoot.iff
protected theorem not_iff : ¬IsPrimitiveRoot ζ k ↔ orderOf ζ ≠ k :=
⟨fun h hk => h <| hk ▸ IsPrimitiveRoot.orderOf ζ,
fun h hk => h.symm <| hk.unique <| IsPrimitiveRoot.orderOf ζ⟩
#align is_primitive_root.not_iff IsPrimitiveRoot.not_iff
theorem pow_mul_pow_lcm {ζ' : M} {k' : ℕ} (hζ : IsPrimitiveRoot ζ k) (hζ' : IsPrimitiveRoot ζ' k')
(hk : k ≠ 0) (hk' : k' ≠ 0) :
IsPrimitiveRoot
(ζ ^ (k / Nat.factorizationLCMLeft k k') * ζ' ^ (k' / Nat.factorizationLCMRight k k'))
(Nat.lcm k k') := by
convert IsPrimitiveRoot.orderOf _
convert ((Commute.all ζ ζ').orderOf_mul_pow_eq_lcm
(by simpa [← hζ.eq_orderOf]) (by simpa [← hζ'.eq_orderOf])).symm using 2
all_goals simp [hζ.eq_orderOf, hζ'.eq_orderOf]
theorem pow_of_dvd (h : IsPrimitiveRoot ζ k) {p : ℕ} (hp : p ≠ 0) (hdiv : p ∣ k) :
IsPrimitiveRoot (ζ ^ p) (k / p) := by
suffices orderOf (ζ ^ p) = k / p by exact this ▸ IsPrimitiveRoot.orderOf (ζ ^ p)
rw [orderOf_pow' _ hp, ← eq_orderOf h, Nat.gcd_eq_right hdiv]
#align is_primitive_root.pow_of_dvd IsPrimitiveRoot.pow_of_dvd
protected theorem mem_rootsOfUnity {ζ : Mˣ} {n : ℕ+} (h : IsPrimitiveRoot ζ n) :
ζ ∈ rootsOfUnity n M :=
h.pow_eq_one
#align is_primitive_root.mem_roots_of_unity IsPrimitiveRoot.mem_rootsOfUnity
/-- If there is an `n`-th primitive root of unity in `R` and `b` divides `n`,
then there is a `b`-th primitive root of unity in `R`. -/
theorem pow {n : ℕ} {a b : ℕ} (hn : 0 < n) (h : IsPrimitiveRoot ζ n) (hprod : n = a * b) :
IsPrimitiveRoot (ζ ^ a) b := by
subst n
simp only [iff_def, ← pow_mul, h.pow_eq_one, eq_self_iff_true, true_and_iff]
intro l hl
-- Porting note: was `by rintro rfl; simpa only [Nat.not_lt_zero, zero_mul] using hn`
have ha0 : a ≠ 0 := left_ne_zero_of_mul hn.ne'
rw [← mul_dvd_mul_iff_left ha0]
exact h.dvd_of_pow_eq_one _ hl
#align is_primitive_root.pow IsPrimitiveRoot.pow
lemma injOn_pow {n : ℕ} {ζ : M} (hζ : IsPrimitiveRoot ζ n) :
Set.InjOn (ζ ^ ·) (Finset.range n) := by
obtain (rfl|hn) := n.eq_zero_or_pos; · simp
intros i hi j hj e
rw [Finset.coe_range, Set.mem_Iio] at hi hj
have : (hζ.isUnit hn).unit ^ i = (hζ.isUnit hn).unit ^ j := Units.ext (by simpa using e)
rw [pow_inj_mod, ← orderOf_injective ⟨⟨Units.val, Units.val_one⟩, Units.val_mul⟩
Units.ext (hζ.isUnit hn).unit] at this
simpa [← hζ.eq_orderOf, Nat.mod_eq_of_lt, hi, hj] using this
section Maps
open Function
variable [FunLike F M N]
theorem map_of_injective [MonoidHomClass F M N] (h : IsPrimitiveRoot ζ k) (hf : Injective f) :
IsPrimitiveRoot (f ζ) k where
pow_eq_one := by rw [← map_pow, h.pow_eq_one, _root_.map_one]
dvd_of_pow_eq_one := by
rw [h.eq_orderOf]
intro l hl
rw [← map_pow, ← map_one f] at hl
exact orderOf_dvd_of_pow_eq_one (hf hl)
#align is_primitive_root.map_of_injective IsPrimitiveRoot.map_of_injective
theorem of_map_of_injective [MonoidHomClass F M N] (h : IsPrimitiveRoot (f ζ) k)
(hf : Injective f) : IsPrimitiveRoot ζ k where
pow_eq_one := by apply_fun f; rw [map_pow, _root_.map_one, h.pow_eq_one]
dvd_of_pow_eq_one := by
rw [h.eq_orderOf]
intro l hl
apply_fun f at hl
rw [map_pow, _root_.map_one] at hl
exact orderOf_dvd_of_pow_eq_one hl
#align is_primitive_root.of_map_of_injective IsPrimitiveRoot.of_map_of_injective
theorem map_iff_of_injective [MonoidHomClass F M N] (hf : Injective f) :
IsPrimitiveRoot (f ζ) k ↔ IsPrimitiveRoot ζ k :=
⟨fun h => h.of_map_of_injective hf, fun h => h.map_of_injective hf⟩
#align is_primitive_root.map_iff_of_injective IsPrimitiveRoot.map_iff_of_injective
end Maps
end CommMonoid
section CommMonoidWithZero
variable {M₀ : Type*} [CommMonoidWithZero M₀]
theorem zero [Nontrivial M₀] : IsPrimitiveRoot (0 : M₀) 0 :=
⟨pow_zero 0, fun l hl => by
simpa [zero_pow_eq, show ∀ p, ¬p → False ↔ p from @Classical.not_not] using hl⟩
#align is_primitive_root.zero IsPrimitiveRoot.zero
protected theorem ne_zero [Nontrivial M₀] {ζ : M₀} (h : IsPrimitiveRoot ζ k) : k ≠ 0 → ζ ≠ 0 :=
mt fun hn => h.unique (hn.symm ▸ IsPrimitiveRoot.zero)
#align is_primitive_root.ne_zero IsPrimitiveRoot.ne_zero
end CommMonoidWithZero
section CancelCommMonoidWithZero
variable {M₀ : Type*} [CancelCommMonoidWithZero M₀]
lemma injOn_pow_mul {n : ℕ} {ζ : M₀} (hζ : IsPrimitiveRoot ζ n)
{α : M₀} (hα : α ≠ 0) :
Set.InjOn (ζ ^ · * α) (Finset.range n) := fun i hi j hj e ↦
hζ.injOn_pow hi hj (by simpa [mul_eq_mul_right_iff, or_iff_left hα] using e)
end CancelCommMonoidWithZero
section DivisionCommMonoid
variable {ζ : G}
theorem zpow_eq_one (h : IsPrimitiveRoot ζ k) : ζ ^ (k : ℤ) = 1 := by
rw [zpow_natCast]; exact h.pow_eq_one
#align is_primitive_root.zpow_eq_one IsPrimitiveRoot.zpow_eq_one
theorem zpow_eq_one_iff_dvd (h : IsPrimitiveRoot ζ k) (l : ℤ) : ζ ^ l = 1 ↔ (k : ℤ) ∣ l := by
by_cases h0 : 0 ≤ l
· lift l to ℕ using h0; rw [zpow_natCast]; norm_cast; exact h.pow_eq_one_iff_dvd l
· have : 0 ≤ -l := by simp only [not_le, neg_nonneg] at h0 ⊢; exact le_of_lt h0
lift -l to ℕ using this with l' hl'
rw [← dvd_neg, ← hl']
norm_cast
rw [← h.pow_eq_one_iff_dvd, ← inv_inj, ← zpow_neg, ← hl', zpow_natCast, inv_one]
#align is_primitive_root.zpow_eq_one_iff_dvd IsPrimitiveRoot.zpow_eq_one_iff_dvd
theorem inv (h : IsPrimitiveRoot ζ k) : IsPrimitiveRoot ζ⁻¹ k :=
{ pow_eq_one := by simp only [h.pow_eq_one, inv_one, eq_self_iff_true, inv_pow]
dvd_of_pow_eq_one := by
intro l hl
apply h.dvd_of_pow_eq_one l
rw [← inv_inj, ← inv_pow, hl, inv_one] }
#align is_primitive_root.inv IsPrimitiveRoot.inv
@[simp]
theorem inv_iff : IsPrimitiveRoot ζ⁻¹ k ↔ IsPrimitiveRoot ζ k := by
refine ⟨?_, fun h => inv h⟩; intro h; rw [← inv_inv ζ]; exact inv h
#align is_primitive_root.inv_iff IsPrimitiveRoot.inv_iff
theorem zpow_of_gcd_eq_one (h : IsPrimitiveRoot ζ k) (i : ℤ) (hi : i.gcd k = 1) :
IsPrimitiveRoot (ζ ^ i) k := by
by_cases h0 : 0 ≤ i
· lift i to ℕ using h0
rw [zpow_natCast]
exact h.pow_of_coprime i hi
have : 0 ≤ -i := by simp only [not_le, neg_nonneg] at h0 ⊢; exact le_of_lt h0
lift -i to ℕ using this with i' hi'
rw [← inv_iff, ← zpow_neg, ← hi', zpow_natCast]
apply h.pow_of_coprime
rw [Int.gcd, ← Int.natAbs_neg, ← hi'] at hi
exact hi
#align is_primitive_root.zpow_of_gcd_eq_one IsPrimitiveRoot.zpow_of_gcd_eq_one
end DivisionCommMonoid
section CommRing
variable [CommRing R] {n : ℕ} (hn : 1 < n) {ζ : R} (hζ : IsPrimitiveRoot ζ n)
theorem sub_one_ne_zero : ζ - 1 ≠ 0 := sub_ne_zero.mpr <| hζ.ne_one hn
end CommRing
section IsDomain
variable {ζ : R}
variable [CommRing R] [IsDomain R]
@[simp]
| Mathlib/RingTheory/RootsOfUnity/Basic.lean | 645 | 651 | theorem primitiveRoots_one : primitiveRoots 1 R = {(1 : R)} := by |
apply Finset.eq_singleton_iff_unique_mem.2
constructor
· simp only [IsPrimitiveRoot.one_right_iff, mem_primitiveRoots zero_lt_one]
· intro x hx
rw [mem_primitiveRoots zero_lt_one, IsPrimitiveRoot.one_right_iff] at hx
exact hx
|
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.Normed.Group.Hom
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Data.Set.Image
import Mathlib.MeasureTheory.Function.LpSeminorm.ChebyshevMarkov
import Mathlib.MeasureTheory.Function.LpSeminorm.CompareExp
import Mathlib.MeasureTheory.Function.LpSeminorm.TriangleInequality
import Mathlib.MeasureTheory.Measure.OpenPos
import Mathlib.Topology.ContinuousFunction.Compact
import Mathlib.Order.Filter.IndicatorFunction
#align_import measure_theory.function.lp_space from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9"
/-!
# Lp space
This file provides the space `Lp E p μ` as the subtype of elements of `α →ₘ[μ] E` (see ae_eq_fun)
such that `snorm f p μ` is finite. For `1 ≤ p`, `snorm` defines a norm and `Lp` is a complete metric
space.
## Main definitions
* `Lp E p μ` : elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. Defined
as an `AddSubgroup` of `α →ₘ[μ] E`.
Lipschitz functions vanishing at zero act by composition on `Lp`. We define this action, and prove
that it is continuous. In particular,
* `ContinuousLinearMap.compLp` defines the action on `Lp` of a continuous linear map.
* `Lp.posPart` is the positive part of an `Lp` function.
* `Lp.negPart` is the negative part of an `Lp` function.
When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map
from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this
as `BoundedContinuousFunction.toLp`.
## Notations
* `α →₁[μ] E` : the type `Lp E 1 μ`.
* `α →₂[μ] E` : the type `Lp E 2 μ`.
## Implementation
Since `Lp` is defined as an `AddSubgroup`, dot notation does not work. Use `Lp.Measurable f` to
say that the coercion of `f` to a genuine function is measurable, instead of the non-working
`f.Measurable`.
To prove that two `Lp` elements are equal, it suffices to show that their coercions to functions
coincide almost everywhere (this is registered as an `ext` rule). This can often be done using
`filter_upwards`. For instance, a proof from first principles that `f + (g + h) = (f + g) + h`
could read (in the `Lp` namespace)
```
example (f g h : Lp E p μ) : (f + g) + h = f + (g + h) := by
ext1
filter_upwards [coeFn_add (f + g) h, coeFn_add f g, coeFn_add f (g + h), coeFn_add g h]
with _ ha1 ha2 ha3 ha4
simp only [ha1, ha2, ha3, ha4, add_assoc]
```
The lemma `coeFn_add` states that the coercion of `f + g` coincides almost everywhere with the sum
of the coercions of `f` and `g`. All such lemmas use `coeFn` in their name, to distinguish the
function coercion from the coercion to almost everywhere defined functions.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology MeasureTheory Uniformity
variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G]
namespace MeasureTheory
/-!
### Lp space
The space of equivalence classes of measurable functions for which `snorm f p μ < ∞`.
-/
@[simp]
theorem snorm_aeeqFun {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E]
{p : ℝ≥0∞} {f : α → E} (hf : AEStronglyMeasurable f μ) :
snorm (AEEqFun.mk f hf) p μ = snorm f p μ :=
snorm_congr_ae (AEEqFun.coeFn_mk _ _)
#align measure_theory.snorm_ae_eq_fun MeasureTheory.snorm_aeeqFun
theorem Memℒp.snorm_mk_lt_top {α E : Type*} [MeasurableSpace α] {μ : Measure α}
[NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hfp : Memℒp f p μ) :
snorm (AEEqFun.mk f hfp.1) p μ < ∞ := by simp [hfp.2]
#align measure_theory.mem_ℒp.snorm_mk_lt_top MeasureTheory.Memℒp.snorm_mk_lt_top
/-- Lp space -/
def Lp {α} (E : Type*) {m : MeasurableSpace α} [NormedAddCommGroup E] (p : ℝ≥0∞)
(μ : Measure α := by volume_tac) : AddSubgroup (α →ₘ[μ] E) where
carrier := { f | snorm f p μ < ∞ }
zero_mem' := by simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero]
add_mem' {f g} hf hg := by
simp [snorm_congr_ae (AEEqFun.coeFn_add f g),
snorm_add_lt_top ⟨f.aestronglyMeasurable, hf⟩ ⟨g.aestronglyMeasurable, hg⟩]
neg_mem' {f} hf := by rwa [Set.mem_setOf_eq, snorm_congr_ae (AEEqFun.coeFn_neg f), snorm_neg]
#align measure_theory.Lp MeasureTheory.Lp
-- Porting note: calling the first argument `α` breaks the `(α := ·)` notation
scoped notation:25 α' " →₁[" μ "] " E => MeasureTheory.Lp (α := α') E 1 μ
scoped notation:25 α' " →₂[" μ "] " E => MeasureTheory.Lp (α := α') E 2 μ
namespace Memℒp
/-- make an element of Lp from a function verifying `Memℒp` -/
def toLp (f : α → E) (h_mem_ℒp : Memℒp f p μ) : Lp E p μ :=
⟨AEEqFun.mk f h_mem_ℒp.1, h_mem_ℒp.snorm_mk_lt_top⟩
#align measure_theory.mem_ℒp.to_Lp MeasureTheory.Memℒp.toLp
theorem coeFn_toLp {f : α → E} (hf : Memℒp f p μ) : hf.toLp f =ᵐ[μ] f :=
AEEqFun.coeFn_mk _ _
#align measure_theory.mem_ℒp.coe_fn_to_Lp MeasureTheory.Memℒp.coeFn_toLp
theorem toLp_congr {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) (hfg : f =ᵐ[μ] g) :
hf.toLp f = hg.toLp g := by simp [toLp, hfg]
#align measure_theory.mem_ℒp.to_Lp_congr MeasureTheory.Memℒp.toLp_congr
@[simp]
theorem toLp_eq_toLp_iff {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
hf.toLp f = hg.toLp g ↔ f =ᵐ[μ] g := by simp [toLp]
#align measure_theory.mem_ℒp.to_Lp_eq_to_Lp_iff MeasureTheory.Memℒp.toLp_eq_toLp_iff
@[simp]
theorem toLp_zero (h : Memℒp (0 : α → E) p μ) : h.toLp 0 = 0 :=
rfl
#align measure_theory.mem_ℒp.to_Lp_zero MeasureTheory.Memℒp.toLp_zero
theorem toLp_add {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
(hf.add hg).toLp (f + g) = hf.toLp f + hg.toLp g :=
rfl
#align measure_theory.mem_ℒp.to_Lp_add MeasureTheory.Memℒp.toLp_add
theorem toLp_neg {f : α → E} (hf : Memℒp f p μ) : hf.neg.toLp (-f) = -hf.toLp f :=
rfl
#align measure_theory.mem_ℒp.to_Lp_neg MeasureTheory.Memℒp.toLp_neg
theorem toLp_sub {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
(hf.sub hg).toLp (f - g) = hf.toLp f - hg.toLp g :=
rfl
#align measure_theory.mem_ℒp.to_Lp_sub MeasureTheory.Memℒp.toLp_sub
end Memℒp
namespace Lp
instance instCoeFun : CoeFun (Lp E p μ) (fun _ => α → E) :=
⟨fun f => ((f : α →ₘ[μ] E) : α → E)⟩
#align measure_theory.Lp.has_coe_to_fun MeasureTheory.Lp.instCoeFun
@[ext high]
theorem ext {f g : Lp E p μ} (h : f =ᵐ[μ] g) : f = g := by
cases f
cases g
simp only [Subtype.mk_eq_mk]
exact AEEqFun.ext h
#align measure_theory.Lp.ext MeasureTheory.Lp.ext
theorem ext_iff {f g : Lp E p μ} : f = g ↔ f =ᵐ[μ] g :=
⟨fun h => by rw [h], fun h => ext h⟩
#align measure_theory.Lp.ext_iff MeasureTheory.Lp.ext_iff
theorem mem_Lp_iff_snorm_lt_top {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ snorm f p μ < ∞ := Iff.rfl
#align measure_theory.Lp.mem_Lp_iff_snorm_lt_top MeasureTheory.Lp.mem_Lp_iff_snorm_lt_top
theorem mem_Lp_iff_memℒp {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ Memℒp f p μ := by
simp [mem_Lp_iff_snorm_lt_top, Memℒp, f.stronglyMeasurable.aestronglyMeasurable]
#align measure_theory.Lp.mem_Lp_iff_mem_ℒp MeasureTheory.Lp.mem_Lp_iff_memℒp
protected theorem antitone [IsFiniteMeasure μ] {p q : ℝ≥0∞} (hpq : p ≤ q) : Lp E q μ ≤ Lp E p μ :=
fun f hf => (Memℒp.memℒp_of_exponent_le ⟨f.aestronglyMeasurable, hf⟩ hpq).2
#align measure_theory.Lp.antitone MeasureTheory.Lp.antitone
@[simp]
theorem coeFn_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α → E) = f :=
rfl
#align measure_theory.Lp.coe_fn_mk MeasureTheory.Lp.coeFn_mk
-- @[simp] -- Porting note (#10685): dsimp can prove this
theorem coe_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α →ₘ[μ] E) = f :=
rfl
#align measure_theory.Lp.coe_mk MeasureTheory.Lp.coe_mk
@[simp]
theorem toLp_coeFn (f : Lp E p μ) (hf : Memℒp f p μ) : hf.toLp f = f := by
cases f
simp [Memℒp.toLp]
#align measure_theory.Lp.to_Lp_coe_fn MeasureTheory.Lp.toLp_coeFn
theorem snorm_lt_top (f : Lp E p μ) : snorm f p μ < ∞ :=
f.prop
#align measure_theory.Lp.snorm_lt_top MeasureTheory.Lp.snorm_lt_top
theorem snorm_ne_top (f : Lp E p μ) : snorm f p μ ≠ ∞ :=
(snorm_lt_top f).ne
#align measure_theory.Lp.snorm_ne_top MeasureTheory.Lp.snorm_ne_top
@[measurability]
protected theorem stronglyMeasurable (f : Lp E p μ) : StronglyMeasurable f :=
f.val.stronglyMeasurable
#align measure_theory.Lp.strongly_measurable MeasureTheory.Lp.stronglyMeasurable
@[measurability]
protected theorem aestronglyMeasurable (f : Lp E p μ) : AEStronglyMeasurable f μ :=
f.val.aestronglyMeasurable
#align measure_theory.Lp.ae_strongly_measurable MeasureTheory.Lp.aestronglyMeasurable
protected theorem memℒp (f : Lp E p μ) : Memℒp f p μ :=
⟨Lp.aestronglyMeasurable f, f.prop⟩
#align measure_theory.Lp.mem_ℒp MeasureTheory.Lp.memℒp
variable (E p μ)
theorem coeFn_zero : ⇑(0 : Lp E p μ) =ᵐ[μ] 0 :=
AEEqFun.coeFn_zero
#align measure_theory.Lp.coe_fn_zero MeasureTheory.Lp.coeFn_zero
variable {E p μ}
theorem coeFn_neg (f : Lp E p μ) : ⇑(-f) =ᵐ[μ] -f :=
AEEqFun.coeFn_neg _
#align measure_theory.Lp.coe_fn_neg MeasureTheory.Lp.coeFn_neg
theorem coeFn_add (f g : Lp E p μ) : ⇑(f + g) =ᵐ[μ] f + g :=
AEEqFun.coeFn_add _ _
#align measure_theory.Lp.coe_fn_add MeasureTheory.Lp.coeFn_add
theorem coeFn_sub (f g : Lp E p μ) : ⇑(f - g) =ᵐ[μ] f - g :=
AEEqFun.coeFn_sub _ _
#align measure_theory.Lp.coe_fn_sub MeasureTheory.Lp.coeFn_sub
theorem const_mem_Lp (α) {_ : MeasurableSpace α} (μ : Measure α) (c : E) [IsFiniteMeasure μ] :
@AEEqFun.const α _ _ μ _ c ∈ Lp E p μ :=
(memℒp_const c).snorm_mk_lt_top
#align measure_theory.Lp.mem_Lp_const MeasureTheory.Lp.const_mem_Lp
instance instNorm : Norm (Lp E p μ) where norm f := ENNReal.toReal (snorm f p μ)
#align measure_theory.Lp.has_norm MeasureTheory.Lp.instNorm
-- note: we need this to be defeq to the instance from `SeminormedAddGroup.toNNNorm`, so
-- can't use `ENNReal.toNNReal (snorm f p μ)`
instance instNNNorm : NNNorm (Lp E p μ) where nnnorm f := ⟨‖f‖, ENNReal.toReal_nonneg⟩
#align measure_theory.Lp.has_nnnorm MeasureTheory.Lp.instNNNorm
instance instDist : Dist (Lp E p μ) where dist f g := ‖f - g‖
#align measure_theory.Lp.has_dist MeasureTheory.Lp.instDist
instance instEDist : EDist (Lp E p μ) where edist f g := snorm (⇑f - ⇑g) p μ
#align measure_theory.Lp.has_edist MeasureTheory.Lp.instEDist
theorem norm_def (f : Lp E p μ) : ‖f‖ = ENNReal.toReal (snorm f p μ) :=
rfl
#align measure_theory.Lp.norm_def MeasureTheory.Lp.norm_def
theorem nnnorm_def (f : Lp E p μ) : ‖f‖₊ = ENNReal.toNNReal (snorm f p μ) :=
rfl
#align measure_theory.Lp.nnnorm_def MeasureTheory.Lp.nnnorm_def
@[simp, norm_cast]
protected theorem coe_nnnorm (f : Lp E p μ) : (‖f‖₊ : ℝ) = ‖f‖ :=
rfl
#align measure_theory.Lp.coe_nnnorm MeasureTheory.Lp.coe_nnnorm
@[simp, norm_cast]
theorem nnnorm_coe_ennreal (f : Lp E p μ) : (‖f‖₊ : ℝ≥0∞) = snorm f p μ :=
ENNReal.coe_toNNReal <| Lp.snorm_ne_top f
@[simp]
theorem norm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖ = ENNReal.toReal (snorm f p μ) := by
erw [norm_def, snorm_congr_ae (Memℒp.coeFn_toLp hf)]
#align measure_theory.Lp.norm_to_Lp MeasureTheory.Lp.norm_toLp
@[simp]
theorem nnnorm_toLp (f : α → E) (hf : Memℒp f p μ) :
‖hf.toLp f‖₊ = ENNReal.toNNReal (snorm f p μ) :=
NNReal.eq <| norm_toLp f hf
#align measure_theory.Lp.nnnorm_to_Lp MeasureTheory.Lp.nnnorm_toLp
theorem coe_nnnorm_toLp {f : α → E} (hf : Memℒp f p μ) : (‖hf.toLp f‖₊ : ℝ≥0∞) = snorm f p μ := by
rw [nnnorm_toLp f hf, ENNReal.coe_toNNReal hf.2.ne]
theorem dist_def (f g : Lp E p μ) : dist f g = (snorm (⇑f - ⇑g) p μ).toReal := by
simp_rw [dist, norm_def]
refine congr_arg _ ?_
apply snorm_congr_ae (coeFn_sub _ _)
#align measure_theory.Lp.dist_def MeasureTheory.Lp.dist_def
theorem edist_def (f g : Lp E p μ) : edist f g = snorm (⇑f - ⇑g) p μ :=
rfl
#align measure_theory.Lp.edist_def MeasureTheory.Lp.edist_def
protected theorem edist_dist (f g : Lp E p μ) : edist f g = .ofReal (dist f g) := by
rw [edist_def, dist_def, ← snorm_congr_ae (coeFn_sub _ _),
ENNReal.ofReal_toReal (snorm_ne_top (f - g))]
protected theorem dist_edist (f g : Lp E p μ) : dist f g = (edist f g).toReal :=
MeasureTheory.Lp.dist_def ..
theorem dist_eq_norm (f g : Lp E p μ) : dist f g = ‖f - g‖ := rfl
@[simp]
theorem edist_toLp_toLp (f g : α → E) (hf : Memℒp f p μ) (hg : Memℒp g p μ) :
edist (hf.toLp f) (hg.toLp g) = snorm (f - g) p μ := by
rw [edist_def]
exact snorm_congr_ae (hf.coeFn_toLp.sub hg.coeFn_toLp)
#align measure_theory.Lp.edist_to_Lp_to_Lp MeasureTheory.Lp.edist_toLp_toLp
@[simp]
theorem edist_toLp_zero (f : α → E) (hf : Memℒp f p μ) : edist (hf.toLp f) 0 = snorm f p μ := by
convert edist_toLp_toLp f 0 hf zero_memℒp
simp
#align measure_theory.Lp.edist_to_Lp_zero MeasureTheory.Lp.edist_toLp_zero
@[simp]
theorem nnnorm_zero : ‖(0 : Lp E p μ)‖₊ = 0 := by
rw [nnnorm_def]
change (snorm (⇑(0 : α →ₘ[μ] E)) p μ).toNNReal = 0
simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero]
#align measure_theory.Lp.nnnorm_zero MeasureTheory.Lp.nnnorm_zero
@[simp]
theorem norm_zero : ‖(0 : Lp E p μ)‖ = 0 :=
congr_arg ((↑) : ℝ≥0 → ℝ) nnnorm_zero
#align measure_theory.Lp.norm_zero MeasureTheory.Lp.norm_zero
@[simp]
| Mathlib/MeasureTheory/Function/LpSpace.lean | 338 | 339 | theorem norm_measure_zero (f : Lp E p (0 : MeasureTheory.Measure α)) : ‖f‖ = 0 := by |
simp [norm_def]
|
/-
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.Basic
import Mathlib.MeasureTheory.Constructions.Prod.Basic
import Mathlib.MeasureTheory.Integral.DominatedConvergence
#align_import probability.kernel.measurable_integral from "leanprover-community/mathlib"@"28b2a92f2996d28e580450863c130955de0ed398"
/-!
# Measurability of the integral against a kernel
The Lebesgue integral of a measurable function against a kernel is measurable. The Bochner integral
is strongly measurable.
## Main statements
* `Measurable.lintegral_kernel_prod_right`: the function `a ↦ ∫⁻ b, f a b ∂(κ a)` is measurable,
for an s-finite kernel `κ : kernel α β` and a function `f : α → β → ℝ≥0∞` such that `uncurry f`
is measurable.
* `MeasureTheory.StronglyMeasurable.integral_kernel_prod_right`: the function
`a ↦ ∫ b, f a b ∂(κ a)` is measurable, for an s-finite kernel `κ : kernel α β` and a function
`f : α → β → E` such that `uncurry f` is measurable.
-/
open MeasureTheory ProbabilityTheory Function Set Filter
open scoped MeasureTheory ENNReal Topology
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
{κ : kernel α β} {η : kernel (α × β) γ} {a : α}
namespace ProbabilityTheory
namespace kernel
/-- This is an auxiliary lemma for `measurable_kernel_prod_mk_left`. -/
theorem measurable_kernel_prod_mk_left_of_finite {t : Set (α × β)} (ht : MeasurableSet t)
(hκs : ∀ a, IsFiniteMeasure (κ a)) : Measurable fun a => κ a (Prod.mk a ⁻¹' t) := by
-- `t` is a measurable set in the product `α × β`: we use that the product σ-algebra is generated
-- by boxes to prove the result by induction.
-- Porting note: added motive
refine MeasurableSpace.induction_on_inter
(C := fun t => Measurable fun a => κ a (Prod.mk a ⁻¹' t))
generateFrom_prod.symm isPiSystem_prod ?_ ?_ ?_ ?_ ht
·-- case `t = ∅`
simp only [preimage_empty, measure_empty, measurable_const]
· -- case of a box: `t = t₁ ×ˢ t₂` for measurable sets `t₁` and `t₂`
intro t' ht'
simp only [Set.mem_image2, Set.mem_setOf_eq, exists_and_left] at ht'
obtain ⟨t₁, ht₁, t₂, ht₂, rfl⟩ := ht'
classical
simp_rw [mk_preimage_prod_right_eq_if]
have h_eq_ite : (fun a => κ a (ite (a ∈ t₁) t₂ ∅)) = fun a => ite (a ∈ t₁) (κ a t₂) 0 := by
ext1 a
split_ifs
exacts [rfl, measure_empty]
rw [h_eq_ite]
exact Measurable.ite ht₁ (kernel.measurable_coe κ ht₂) measurable_const
· -- we assume that the result is true for `t` and we prove it for `tᶜ`
intro t' ht' h_meas
have h_eq_sdiff : ∀ a, Prod.mk a ⁻¹' t'ᶜ = Set.univ \ Prod.mk a ⁻¹' t' := by
intro a
ext1 b
simp only [mem_compl_iff, mem_preimage, mem_diff, mem_univ, true_and_iff]
simp_rw [h_eq_sdiff]
have :
(fun a => κ a (Set.univ \ Prod.mk a ⁻¹' t')) = fun a =>
κ a Set.univ - κ a (Prod.mk a ⁻¹' t') := by
ext1 a
rw [← Set.diff_inter_self_eq_diff, Set.inter_univ, measure_diff (Set.subset_univ _)]
· exact (@measurable_prod_mk_left α β _ _ a) ht'
· exact measure_ne_top _ _
rw [this]
exact Measurable.sub (kernel.measurable_coe κ MeasurableSet.univ) h_meas
· -- we assume that the result is true for a family of disjoint sets and prove it for their union
intro f h_disj hf_meas hf
have h_Union :
(fun a => κ a (Prod.mk a ⁻¹' ⋃ i, f i)) = fun a => κ a (⋃ i, Prod.mk a ⁻¹' f i) := by
ext1 a
congr with b
simp only [mem_iUnion, mem_preimage]
rw [h_Union]
have h_tsum :
(fun a => κ a (⋃ i, Prod.mk a ⁻¹' f i)) = fun a => ∑' i, κ a (Prod.mk a ⁻¹' f i) := by
ext1 a
rw [measure_iUnion]
· intro i j hij s hsi hsj b hbs
have habi : {(a, b)} ⊆ f i := by rw [Set.singleton_subset_iff]; exact hsi hbs
have habj : {(a, b)} ⊆ f j := by rw [Set.singleton_subset_iff]; exact hsj hbs
simpa only [Set.bot_eq_empty, Set.le_eq_subset, Set.singleton_subset_iff,
Set.mem_empty_iff_false] using h_disj hij habi habj
· exact fun i => (@measurable_prod_mk_left α β _ _ a) (hf_meas i)
rw [h_tsum]
exact Measurable.ennreal_tsum hf
#align probability_theory.kernel.measurable_kernel_prod_mk_left_of_finite ProbabilityTheory.kernel.measurable_kernel_prod_mk_left_of_finite
theorem measurable_kernel_prod_mk_left [IsSFiniteKernel κ] {t : Set (α × β)}
(ht : MeasurableSet t) : Measurable fun a => κ a (Prod.mk a ⁻¹' t) := by
rw [← kernel.kernel_sum_seq κ]
have : ∀ a, kernel.sum (kernel.seq κ) a (Prod.mk a ⁻¹' t) =
∑' n, kernel.seq κ n a (Prod.mk a ⁻¹' t) := fun a =>
kernel.sum_apply' _ _ (measurable_prod_mk_left ht)
simp_rw [this]
refine Measurable.ennreal_tsum fun n => ?_
exact measurable_kernel_prod_mk_left_of_finite ht inferInstance
#align probability_theory.kernel.measurable_kernel_prod_mk_left ProbabilityTheory.kernel.measurable_kernel_prod_mk_left
theorem measurable_kernel_prod_mk_left' [IsSFiniteKernel η] {s : Set (β × γ)} (hs : MeasurableSet s)
(a : α) : Measurable fun b => η (a, b) (Prod.mk b ⁻¹' s) := by
have : ∀ b, Prod.mk b ⁻¹' s = {c | ((a, b), c) ∈ {p : (α × β) × γ | (p.1.2, p.2) ∈ s}} := by
intro b; rfl
simp_rw [this]
refine (measurable_kernel_prod_mk_left ?_).comp measurable_prod_mk_left
exact (measurable_fst.snd.prod_mk measurable_snd) hs
#align probability_theory.kernel.measurable_kernel_prod_mk_left' ProbabilityTheory.kernel.measurable_kernel_prod_mk_left'
theorem measurable_kernel_prod_mk_right [IsSFiniteKernel κ] {s : Set (β × α)}
(hs : MeasurableSet s) : Measurable fun y => κ y ((fun x => (x, y)) ⁻¹' s) :=
measurable_kernel_prod_mk_left (measurableSet_swap_iff.mpr hs)
#align probability_theory.kernel.measurable_kernel_prod_mk_right ProbabilityTheory.kernel.measurable_kernel_prod_mk_right
end kernel
open ProbabilityTheory.kernel
section Lintegral
variable [IsSFiniteKernel κ] [IsSFiniteKernel η]
/-- Auxiliary lemma for `Measurable.lintegral_kernel_prod_right`. -/
theorem kernel.measurable_lintegral_indicator_const {t : Set (α × β)} (ht : MeasurableSet t)
(c : ℝ≥0∞) : Measurable fun a => ∫⁻ b, t.indicator (Function.const (α × β) c) (a, b) ∂κ a := by
-- Porting note: was originally by
-- `simp_rw [lintegral_indicator_const_comp measurable_prod_mk_left ht _]`
-- but this has no effect, so added the `conv` below
conv =>
congr
ext
erw [lintegral_indicator_const_comp measurable_prod_mk_left ht _]
exact Measurable.const_mul (measurable_kernel_prod_mk_left ht) c
#align probability_theory.kernel.measurable_lintegral_indicator_const ProbabilityTheory.kernel.measurable_lintegral_indicator_const
/-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is measurable when seen as a
map from `α × β` (hypothesis `Measurable (uncurry f)`), the integral `a ↦ ∫⁻ b, f a b ∂(κ a)` is
measurable. -/
theorem _root_.Measurable.lintegral_kernel_prod_right {f : α → β → ℝ≥0∞}
(hf : Measurable (uncurry f)) : Measurable fun a => ∫⁻ b, f a b ∂κ a := by
let F : ℕ → SimpleFunc (α × β) ℝ≥0∞ := SimpleFunc.eapprox (uncurry f)
have h : ∀ a, ⨆ n, F n a = uncurry f a := SimpleFunc.iSup_eapprox_apply (uncurry f) hf
simp only [Prod.forall, uncurry_apply_pair] at h
simp_rw [← h]
have : ∀ a, (∫⁻ b, ⨆ n, F n (a, b) ∂κ a) = ⨆ n, ∫⁻ b, F n (a, b) ∂κ a := by
intro a
rw [lintegral_iSup]
· exact fun n => (F n).measurable.comp measurable_prod_mk_left
· exact fun i j hij b => SimpleFunc.monotone_eapprox (uncurry f) hij _
simp_rw [this]
refine measurable_iSup fun n => ?_
refine SimpleFunc.induction
(P := fun f => Measurable (fun (a : α) => ∫⁻ (b : β), f (a, b) ∂κ a)) ?_ ?_ (F n)
· intro c t ht
simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const,
SimpleFunc.coe_zero, Set.piecewise_eq_indicator]
exact kernel.measurable_lintegral_indicator_const (κ := κ) ht c
· intro g₁ g₂ _ hm₁ hm₂
simp only [SimpleFunc.coe_add, Pi.add_apply]
have h_add :
(fun a => ∫⁻ b, g₁ (a, b) + g₂ (a, b) ∂κ a) =
(fun a => ∫⁻ b, g₁ (a, b) ∂κ a) + fun a => ∫⁻ b, g₂ (a, b) ∂κ a := by
ext1 a
rw [Pi.add_apply]
-- Porting note (#10691): was `rw` (`Function.comp` reducibility)
erw [lintegral_add_left (g₁.measurable.comp measurable_prod_mk_left)]
simp_rw [Function.comp_apply]
rw [h_add]
exact Measurable.add hm₁ hm₂
#align measurable.lintegral_kernel_prod_right Measurable.lintegral_kernel_prod_right
theorem _root_.Measurable.lintegral_kernel_prod_right' {f : α × β → ℝ≥0∞} (hf : Measurable f) :
Measurable fun a => ∫⁻ b, f (a, b) ∂κ a := by
refine Measurable.lintegral_kernel_prod_right ?_
have : (uncurry fun (a : α) (b : β) => f (a, b)) = f := by
ext x; rw [uncurry_apply_pair]
rwa [this]
#align measurable.lintegral_kernel_prod_right' Measurable.lintegral_kernel_prod_right'
theorem _root_.Measurable.lintegral_kernel_prod_right'' {f : β × γ → ℝ≥0∞} (hf : Measurable f) :
Measurable fun x => ∫⁻ y, f (x, y) ∂η (a, x) := by
-- Porting note: used `Prod.mk a` instead of `fun x => (a, x)` below
change
Measurable
((fun x => ∫⁻ y, (fun u : (α × β) × γ => f (u.1.2, u.2)) (x, y) ∂η x) ∘ Prod.mk a)
-- Porting note: specified `κ`, `f`.
refine (Measurable.lintegral_kernel_prod_right' (κ := η)
(f := (fun u ↦ f (u.fst.snd, u.snd))) ?_).comp measurable_prod_mk_left
exact hf.comp (measurable_fst.snd.prod_mk measurable_snd)
#align measurable.lintegral_kernel_prod_right'' Measurable.lintegral_kernel_prod_right''
theorem _root_.Measurable.set_lintegral_kernel_prod_right {f : α → β → ℝ≥0∞}
(hf : Measurable (uncurry f)) {s : Set β} (hs : MeasurableSet s) :
Measurable fun a => ∫⁻ b in s, f a b ∂κ a := by
simp_rw [← lintegral_restrict κ hs]; exact hf.lintegral_kernel_prod_right
#align measurable.set_lintegral_kernel_prod_right Measurable.set_lintegral_kernel_prod_right
theorem _root_.Measurable.lintegral_kernel_prod_left' {f : β × α → ℝ≥0∞} (hf : Measurable f) :
Measurable fun y => ∫⁻ x, f (x, y) ∂κ y :=
(measurable_swap_iff.mpr hf).lintegral_kernel_prod_right'
#align measurable.lintegral_kernel_prod_left' Measurable.lintegral_kernel_prod_left'
theorem _root_.Measurable.lintegral_kernel_prod_left {f : β → α → ℝ≥0∞}
(hf : Measurable (uncurry f)) : Measurable fun y => ∫⁻ x, f x y ∂κ y :=
hf.lintegral_kernel_prod_left'
#align measurable.lintegral_kernel_prod_left Measurable.lintegral_kernel_prod_left
theorem _root_.Measurable.set_lintegral_kernel_prod_left {f : β → α → ℝ≥0∞}
(hf : Measurable (uncurry f)) {s : Set β} (hs : MeasurableSet s) :
Measurable fun b => ∫⁻ a in s, f a b ∂κ b := by
simp_rw [← lintegral_restrict κ hs]; exact hf.lintegral_kernel_prod_left
#align measurable.set_lintegral_kernel_prod_left Measurable.set_lintegral_kernel_prod_left
theorem _root_.Measurable.lintegral_kernel {f : β → ℝ≥0∞} (hf : Measurable f) :
Measurable fun a => ∫⁻ b, f b ∂κ a :=
Measurable.lintegral_kernel_prod_right (hf.comp measurable_snd)
#align measurable.lintegral_kernel Measurable.lintegral_kernel
theorem _root_.Measurable.set_lintegral_kernel {f : β → ℝ≥0∞} (hf : Measurable f) {s : Set β}
(hs : MeasurableSet s) : Measurable fun a => ∫⁻ b in s, f b ∂κ a := by
-- Porting note: was term mode proof (`Function.comp` reducibility)
refine Measurable.set_lintegral_kernel_prod_right ?_ hs
convert hf.comp measurable_snd
#align measurable.set_lintegral_kernel Measurable.set_lintegral_kernel
end Lintegral
variable {E : Type*} [NormedAddCommGroup E] [IsSFiniteKernel κ] [IsSFiniteKernel η]
theorem measurableSet_kernel_integrable ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) :
MeasurableSet {x | Integrable (f x) (κ x)} := by
simp_rw [Integrable, hf.of_uncurry_left.aestronglyMeasurable, true_and_iff]
exact measurableSet_lt (Measurable.lintegral_kernel_prod_right hf.ennnorm) measurable_const
#align probability_theory.measurable_set_kernel_integrable ProbabilityTheory.measurableSet_kernel_integrable
end ProbabilityTheory
open ProbabilityTheory ProbabilityTheory.kernel
namespace MeasureTheory
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [IsSFiniteKernel κ]
[IsSFiniteKernel η]
theorem StronglyMeasurable.integral_kernel_prod_right ⦃f : α → β → E⦄
(hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun x => ∫ y, f x y ∂κ x := by
classical
by_cases hE : CompleteSpace E; swap
· simp [integral, hE, stronglyMeasurable_const]
borelize E
haveI : TopologicalSpace.SeparableSpace (range (uncurry f) ∪ {0} : Set E) :=
hf.separableSpace_range_union_singleton
let s : ℕ → SimpleFunc (α × β) E :=
SimpleFunc.approxOn _ hf.measurable (range (uncurry f) ∪ {0}) 0 (by simp)
let s' : ℕ → α → SimpleFunc β E := fun n x => (s n).comp (Prod.mk x) measurable_prod_mk_left
let f' : ℕ → α → E := fun n =>
{x | Integrable (f x) (κ x)}.indicator fun x => (s' n x).integral (κ x)
have hf' : ∀ n, StronglyMeasurable (f' n) := by
intro n; refine StronglyMeasurable.indicator ?_ (measurableSet_kernel_integrable hf)
have : ∀ x, ((s' n x).range.filter fun x => x ≠ 0) ⊆ (s n).range := by
intro x; refine Finset.Subset.trans (Finset.filter_subset _ _) ?_; intro y
simp_rw [SimpleFunc.mem_range]; rintro ⟨z, rfl⟩; exact ⟨(x, z), rfl⟩
simp only [SimpleFunc.integral_eq_sum_of_subset (this _)]
refine Finset.stronglyMeasurable_sum _ fun x _ => ?_
refine (Measurable.ennreal_toReal ?_).stronglyMeasurable.smul_const _
simp only [s', SimpleFunc.coe_comp, preimage_comp]
apply kernel.measurable_kernel_prod_mk_left
exact (s n).measurableSet_fiber x
have h2f' : Tendsto f' atTop (𝓝 fun x : α => ∫ y : β, f x y ∂κ x) := by
rw [tendsto_pi_nhds]; intro x
by_cases hfx : Integrable (f x) (κ x)
· have (n) : Integrable (s' n x) (κ x) := by
apply (hfx.norm.add hfx.norm).mono' (s' n x).aestronglyMeasurable
filter_upwards with y
simp_rw [s', SimpleFunc.coe_comp]; exact SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n
simp only [f', hfx, SimpleFunc.integral_eq_integral _ (this _), indicator_of_mem,
mem_setOf_eq]
refine
tendsto_integral_of_dominated_convergence (fun y => ‖f x y‖ + ‖f x y‖)
(fun n => (s' n x).aestronglyMeasurable) (hfx.norm.add hfx.norm) ?_ ?_
· -- Porting note: was
-- exact fun n => eventually_of_forall fun y =>
-- SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n
exact fun n => eventually_of_forall fun y =>
SimpleFunc.norm_approxOn_zero_le hf.measurable (by simp) (x, y) n
· refine eventually_of_forall fun y => SimpleFunc.tendsto_approxOn hf.measurable (by simp) ?_
apply subset_closure
simp [-uncurry_apply_pair]
· simp [f', hfx, integral_undef]
exact stronglyMeasurable_of_tendsto _ hf' h2f'
#align measure_theory.strongly_measurable.integral_kernel_prod_right MeasureTheory.StronglyMeasurable.integral_kernel_prod_right
| Mathlib/Probability/Kernel/MeasurableIntegral.lean | 305 | 308 | theorem StronglyMeasurable.integral_kernel_prod_right' ⦃f : α × β → E⦄ (hf : StronglyMeasurable f) :
StronglyMeasurable fun x => ∫ y, f (x, y) ∂κ x := by |
rw [← uncurry_curry f] at hf
exact hf.integral_kernel_prod_right
|
/-
Copyright (c) 2020 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma
-/
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.Ideal.Over
import Mathlib.RingTheory.JacobsonIdeal
#align_import ring_theory.jacobson from "leanprover-community/mathlib"@"a7c017d750512a352b623b1824d75da5998457d0"
/-!
# Jacobson Rings
The following conditions are equivalent for a ring `R`:
1. Every radical ideal `I` is equal to its Jacobson radical
2. Every radical ideal `I` can be written as an intersection of maximal ideals
3. Every prime ideal `I` is equal to its Jacobson radical
Any ring satisfying any of these equivalent conditions is said to be Jacobson.
Some particular examples of Jacobson rings are also proven.
`isJacobson_quotient` says that the quotient of a Jacobson ring is Jacobson.
`isJacobson_localization` says the localization of a Jacobson ring to a single element is Jacobson.
`isJacobson_polynomial_iff_isJacobson` says polynomials over a Jacobson ring form a Jacobson ring.
## Main definitions
Let `R` be a commutative ring. Jacobson rings are defined using the first of the above conditions
* `IsJacobson R` is the proposition that `R` is a Jacobson ring. It is a class,
implemented as the predicate that for any ideal, `I.isRadical` implies `I.jacobson = I`.
## Main statements
* `isJacobson_iff_prime_eq` is the equivalence between conditions 1 and 3 above.
* `isJacobson_iff_sInf_maximal` is the equivalence between conditions 1 and 2 above.
* `isJacobson_of_surjective` says that if `R` is a Jacobson ring and `f : R →+* S` is surjective,
then `S` is also a Jacobson ring
* `MvPolynomial.isJacobson` says that multi-variate polynomials over a Jacobson ring are Jacobson.
## Tags
Jacobson, Jacobson Ring
-/
set_option autoImplicit true
universe u
namespace Ideal
open Polynomial
open Polynomial
section IsJacobson
variable {R S : Type*} [CommRing R] [CommRing S] {I : Ideal R}
/-- A ring is a Jacobson ring if for every radical ideal `I`,
the Jacobson radical of `I` is equal to `I`.
See `isJacobson_iff_prime_eq` and `isJacobson_iff_sInf_maximal` for equivalent definitions. -/
class IsJacobson (R : Type*) [CommRing R] : Prop where
out' : ∀ I : Ideal R, I.IsRadical → I.jacobson = I
#align ideal.is_jacobson Ideal.IsJacobson
theorem isJacobson_iff {R} [CommRing R] :
IsJacobson R ↔ ∀ I : Ideal R, I.IsRadical → I.jacobson = I :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
#align ideal.is_jacobson_iff Ideal.isJacobson_iff
theorem IsJacobson.out {R} [CommRing R] :
IsJacobson R → ∀ {I : Ideal R}, I.IsRadical → I.jacobson = I :=
isJacobson_iff.1
#align ideal.is_jacobson.out Ideal.IsJacobson.out
/-- A ring is a Jacobson ring if and only if for all prime ideals `P`,
the Jacobson radical of `P` is equal to `P`. -/
theorem isJacobson_iff_prime_eq : IsJacobson R ↔ ∀ P : Ideal R, IsPrime P → P.jacobson = P := by
refine isJacobson_iff.trans ⟨fun h I hI => h I hI.isRadical, ?_⟩
refine fun h I hI ↦ le_antisymm (fun x hx ↦ ?_) (fun x hx ↦ mem_sInf.mpr fun _ hJ ↦ hJ.left hx)
rw [← hI.radical, radical_eq_sInf I, mem_sInf]
intro P hP
rw [Set.mem_setOf_eq] at hP
erw [mem_sInf] at hx
erw [← h P hP.right, mem_sInf]
exact fun J hJ => hx ⟨le_trans hP.left hJ.left, hJ.right⟩
#align ideal.is_jacobson_iff_prime_eq Ideal.isJacobson_iff_prime_eq
/-- A ring `R` is Jacobson if and only if for every prime ideal `I`,
`I` can be written as the infimum of some collection of maximal ideals.
Allowing ⊤ in the set `M` of maximal ideals is equivalent, but makes some proofs cleaner. -/
theorem isJacobson_iff_sInf_maximal : IsJacobson R ↔ ∀ {I : Ideal R}, I.IsPrime →
∃ M : Set (Ideal R), (∀ J ∈ M, IsMaximal J ∨ J = ⊤) ∧ I = sInf M :=
⟨fun H _I h => eq_jacobson_iff_sInf_maximal.1 (H.out h.isRadical), fun H =>
isJacobson_iff_prime_eq.2 fun _P hP => eq_jacobson_iff_sInf_maximal.2 (H hP)⟩
#align ideal.is_jacobson_iff_Inf_maximal Ideal.isJacobson_iff_sInf_maximal
theorem isJacobson_iff_sInf_maximal' : IsJacobson R ↔ ∀ {I : Ideal R}, I.IsPrime →
∃ M : Set (Ideal R), (∀ J ∈ M, ∀ (K : Ideal R), J < K → K = ⊤) ∧ I = sInf M :=
⟨fun H _I h => eq_jacobson_iff_sInf_maximal'.1 (H.out h.isRadical), fun H =>
isJacobson_iff_prime_eq.2 fun _P hP => eq_jacobson_iff_sInf_maximal'.2 (H hP)⟩
#align ideal.is_jacobson_iff_Inf_maximal' Ideal.isJacobson_iff_sInf_maximal'
theorem radical_eq_jacobson [H : IsJacobson R] (I : Ideal R) : I.radical = I.jacobson :=
le_antisymm (le_sInf fun _J ⟨hJ, hJ_max⟩ => (IsPrime.radical_le_iff hJ_max.isPrime).mpr hJ)
(H.out (radical_isRadical I) ▸ jacobson_mono le_radical)
#align ideal.radical_eq_jacobson Ideal.radical_eq_jacobson
/-- Fields have only two ideals, and the condition holds for both of them. -/
instance (priority := 100) isJacobson_field {K : Type*} [Field K] : IsJacobson K :=
⟨fun I _ => Or.recOn (eq_bot_or_top I)
(fun h => le_antisymm (sInf_le ⟨le_rfl, h.symm ▸ bot_isMaximal⟩) (h.symm ▸ bot_le)) fun h =>
by rw [h, jacobson_eq_top_iff]⟩
#align ideal.is_jacobson_field Ideal.isJacobson_field
theorem isJacobson_of_surjective [H : IsJacobson R] :
(∃ f : R →+* S, Function.Surjective ↑f) → IsJacobson S := by
rintro ⟨f, hf⟩
rw [isJacobson_iff_sInf_maximal]
intro p hp
use map f '' { J : Ideal R | comap f p ≤ J ∧ J.IsMaximal }
use fun j ⟨J, hJ, hmap⟩ => hmap ▸ (map_eq_top_or_isMaximal_of_surjective f hf hJ.right).symm
have : p = map f (comap f p).jacobson :=
(IsJacobson.out' _ <| hp.isRadical.comap f).symm ▸ (map_comap_of_surjective f hf p).symm
exact this.trans (map_sInf hf fun J ⟨hJ, _⟩ => le_trans (Ideal.ker_le_comap f) hJ)
#align ideal.is_jacobson_of_surjective Ideal.isJacobson_of_surjective
instance (priority := 100) isJacobson_quotient [IsJacobson R] : IsJacobson (R ⧸ I) :=
isJacobson_of_surjective ⟨Quotient.mk I, by
rintro ⟨x⟩
use x
rfl⟩
#align ideal.is_jacobson_quotient Ideal.isJacobson_quotient
theorem isJacobson_iso (e : R ≃+* S) : IsJacobson R ↔ IsJacobson S :=
⟨fun h => @isJacobson_of_surjective _ _ _ _ h ⟨(e : R →+* S), e.surjective⟩, fun h =>
@isJacobson_of_surjective _ _ _ _ h ⟨(e.symm : S →+* R), e.symm.surjective⟩⟩
#align ideal.is_jacobson_iso Ideal.isJacobson_iso
theorem isJacobson_of_isIntegral [Algebra R S] [Algebra.IsIntegral R S] (hR : IsJacobson R) :
IsJacobson S := by
rw [isJacobson_iff_prime_eq]
intro P hP
by_cases hP_top : comap (algebraMap R S) P = ⊤
· simp [comap_eq_top_iff.1 hP_top]
· haveI : Nontrivial (R ⧸ comap (algebraMap R S) P) := Quotient.nontrivial hP_top
rw [jacobson_eq_iff_jacobson_quotient_eq_bot]
refine eq_bot_of_comap_eq_bot (R := R ⧸ comap (algebraMap R S) P) ?_
rw [eq_bot_iff, ← jacobson_eq_iff_jacobson_quotient_eq_bot.1
((isJacobson_iff_prime_eq.1 hR) (comap (algebraMap R S) P) (comap_isPrime _ _)),
comap_jacobson]
refine sInf_le_sInf fun J hJ => ?_
simp only [true_and_iff, Set.mem_image, bot_le, Set.mem_setOf_eq]
have : J.IsMaximal := by simpa using hJ
exact exists_ideal_over_maximal_of_isIntegral J
(comap_bot_le_of_injective _ algebraMap_quotient_injective)
#align ideal.is_jacobson_of_is_integral Ideal.isJacobson_of_isIntegral
theorem isJacobson_of_isIntegral' (f : R →+* S) (hf : f.IsIntegral) (hR : IsJacobson R) :
IsJacobson S :=
let _ : Algebra R S := f.toAlgebra
have : Algebra.IsIntegral R S := ⟨hf⟩
isJacobson_of_isIntegral hR
#align ideal.is_jacobson_of_is_integral' Ideal.isJacobson_of_isIntegral'
end IsJacobson
section Localization
open IsLocalization Submonoid
variable {R S : Type*} [CommRing R] [CommRing S] {I : Ideal R}
variable (y : R) [Algebra R S] [IsLocalization.Away y S]
variable (S)
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y`.
This lemma gives the correspondence in the particular case of an ideal and its comap.
See `le_relIso_of_maximal` for the more general relation isomorphism -/
theorem isMaximal_iff_isMaximal_disjoint [H : IsJacobson R] (J : Ideal S) :
J.IsMaximal ↔ (comap (algebraMap R S) J).IsMaximal ∧ y ∉ Ideal.comap (algebraMap R S) J := by
constructor
· refine fun h => ⟨?_, fun hy =>
h.ne_top (Ideal.eq_top_of_isUnit_mem _ hy (map_units _ ⟨y, Submonoid.mem_powers _⟩))⟩
have hJ : J.IsPrime := IsMaximal.isPrime h
rw [isPrime_iff_isPrime_disjoint (Submonoid.powers y)] at hJ
have : y ∉ (comap (algebraMap R S) J).1 := Set.disjoint_left.1 hJ.right (Submonoid.mem_powers _)
erw [← H.out hJ.left.isRadical, mem_sInf] at this
push_neg at this
rcases this with ⟨I, hI, hI'⟩
convert hI.right
by_cases hJ : J = map (algebraMap R S) I
· rw [hJ, comap_map_of_isPrime_disjoint (powers y) S I (IsMaximal.isPrime hI.right)]
rwa [disjoint_powers_iff_not_mem y hI.right.isPrime.isRadical]
· have hI_p : (map (algebraMap R S) I).IsPrime := by
refine isPrime_of_isPrime_disjoint (powers y) _ I hI.right.isPrime ?_
rwa [disjoint_powers_iff_not_mem y hI.right.isPrime.isRadical]
have : J ≤ map (algebraMap R S) I := map_comap (Submonoid.powers y) S J ▸ map_mono hI.left
exact absurd (h.1.2 _ (lt_of_le_of_ne this hJ)) hI_p.1
· refine fun h => ⟨⟨fun hJ => h.1.ne_top (eq_top_iff.2 ?_), fun I hI => ?_⟩⟩
· rwa [eq_top_iff, ← (IsLocalization.orderEmbedding (powers y) S).le_iff_le] at hJ
· have := congr_arg (map (algebraMap R S)) (h.1.1.2 _ ⟨comap_mono (le_of_lt hI), ?_⟩)
· rwa [map_comap (powers y) S I, map_top] at this
refine fun hI' => hI.right ?_
rw [← map_comap (powers y) S I, ← map_comap (powers y) S J]
exact map_mono hI'
#align ideal.is_maximal_iff_is_maximal_disjoint Ideal.isMaximal_iff_isMaximal_disjoint
variable {S}
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y`.
This lemma gives the correspondence in the particular case of an ideal and its map.
See `le_relIso_of_maximal` for the more general statement, and the reverse of this implication -/
theorem isMaximal_of_isMaximal_disjoint [IsJacobson R] (I : Ideal R) (hI : I.IsMaximal)
(hy : y ∉ I) : (map (algebraMap R S) I).IsMaximal := by
rw [isMaximal_iff_isMaximal_disjoint S y,
comap_map_of_isPrime_disjoint (powers y) S I (IsMaximal.isPrime hI)
((disjoint_powers_iff_not_mem y hI.isPrime.isRadical).2 hy)]
exact ⟨hI, hy⟩
#align ideal.is_maximal_of_is_maximal_disjoint Ideal.isMaximal_of_isMaximal_disjoint
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y` -/
def orderIsoOfMaximal [IsJacobson R] :
{ p : Ideal S // p.IsMaximal } ≃o { p : Ideal R // p.IsMaximal ∧ y ∉ p } where
toFun p := ⟨Ideal.comap (algebraMap R S) p.1, (isMaximal_iff_isMaximal_disjoint S y p.1).1 p.2⟩
invFun p := ⟨Ideal.map (algebraMap R S) p.1, isMaximal_of_isMaximal_disjoint y p.1 p.2.1 p.2.2⟩
left_inv J := Subtype.eq (map_comap (powers y) S J)
right_inv I := Subtype.eq (comap_map_of_isPrime_disjoint _ _ I.1 (IsMaximal.isPrime I.2.1)
((disjoint_powers_iff_not_mem y I.2.1.isPrime.isRadical).2 I.2.2))
map_rel_iff' {I I'} := ⟨fun h => show I.val ≤ I'.val from
map_comap (powers y) S I.val ▸ map_comap (powers y) S I'.val ▸ Ideal.map_mono h,
fun h _ hx => h hx⟩
#align ideal.order_iso_of_maximal Ideal.orderIsoOfMaximal
/-- If `S` is the localization of the Jacobson ring `R` at the submonoid generated by `y : R`, then
`S` is Jacobson. -/
theorem isJacobson_localization [H : IsJacobson R] : IsJacobson S := by
rw [isJacobson_iff_prime_eq]
refine fun P' hP' => le_antisymm ?_ le_jacobson
obtain ⟨hP', hPM⟩ := (IsLocalization.isPrime_iff_isPrime_disjoint (powers y) S P').mp hP'
have hP := H.out hP'.isRadical
refine (IsLocalization.map_comap (powers y) S P'.jacobson).ge.trans
((map_mono ?_).trans (IsLocalization.map_comap (powers y) S P').le)
have : sInf { I : Ideal R | comap (algebraMap R S) P' ≤ I ∧ I.IsMaximal ∧ y ∉ I } ≤
comap (algebraMap R S) P' := by
intro x hx
have hxy : x * y ∈ (comap (algebraMap R S) P').jacobson := by
rw [Ideal.jacobson, mem_sInf]
intro J hJ
by_cases h : y ∈ J
· exact J.mul_mem_left x h
· exact J.mul_mem_right y ((mem_sInf.1 hx) ⟨hJ.left, ⟨hJ.right, h⟩⟩)
rw [hP] at hxy
cases' hP'.mem_or_mem hxy with hxy hxy
· exact hxy
· exact (hPM.le_bot ⟨Submonoid.mem_powers _, hxy⟩).elim
refine le_trans ?_ this
rw [Ideal.jacobson, comap_sInf', sInf_eq_iInf]
refine iInf_le_iInf_of_subset fun I hI => ⟨map (algebraMap R S) I, ⟨?_, ?_⟩⟩
· exact ⟨le_trans (le_of_eq (IsLocalization.map_comap (powers y) S P').symm) (map_mono hI.1),
isMaximal_of_isMaximal_disjoint y _ hI.2.1 hI.2.2⟩
· exact IsLocalization.comap_map_of_isPrime_disjoint _ S I (IsMaximal.isPrime hI.2.1)
((disjoint_powers_iff_not_mem y hI.2.1.isPrime.isRadical).2 hI.2.2)
#align ideal.is_jacobson_localization Ideal.isJacobson_localization
end Localization
namespace Polynomial
open Polynomial
section CommRing
-- Porting note: move to better place
-- Porting note: make `S` and `T` universe polymorphic
lemma Subring.mem_closure_image_of {S T : Type*} [CommRing S] [CommRing T] (g : S →+* T)
(u : Set S) (x : S) (hx : x ∈ Subring.closure u) : g x ∈ Subring.closure (g '' u) := by
rw [Subring.mem_closure] at hx ⊢
intro T₁ h₁
rw [← Subring.mem_comap]
apply hx
simp only [Subring.coe_comap, ← Set.image_subset_iff, SetLike.mem_coe]
exact h₁
-- Porting note: move to better place
lemma mem_closure_X_union_C {R : Type*} [Ring R] (p : R[X]) :
p ∈ Subring.closure (insert X {f | f.degree ≤ 0} : Set R[X]) := by
refine Polynomial.induction_on p ?_ ?_ ?_
· intro r
apply Subring.subset_closure
apply Set.mem_insert_of_mem
exact degree_C_le
· intros p1 p2 h1 h2
exact Subring.add_mem _ h1 h2
· intros n r hr
rw [pow_succ, ← mul_assoc]
apply Subring.mul_mem _ hr
apply Subring.subset_closure
apply Set.mem_insert
variable {R S : Type*} [CommRing R] [CommRing S] [IsDomain S]
variable {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ]
/-- If `I` is a prime ideal of `R[X]` and `pX ∈ I` is a non-constant polynomial,
then the map `R →+* R[x]/I` descends to an integral map when localizing at `pX.leadingCoeff`.
In particular `X` is integral because it satisfies `pX`, and constants are trivially integral,
so integrality of the entire extension follows by closure under addition and multiplication. -/
theorem isIntegral_isLocalization_polynomial_quotient
(P : Ideal R[X]) (pX : R[X]) (hpX : pX ∈ P) [Algebra (R ⧸ P.comap (C : R →+* R[X])) Rₘ]
[IsLocalization.Away (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff Rₘ]
[Algebra (R[X] ⧸ P) Sₘ] [IsLocalization ((Submonoid.powers (pX.map (Quotient.mk (P.comap
(C : R →+* R[X])))).leadingCoeff).map (quotientMap P C le_rfl) : Submonoid (R[X] ⧸ P)) Sₘ] :
(IsLocalization.map Sₘ (quotientMap P C le_rfl) (Submonoid.powers (pX.map (Quotient.mk (P.comap
(C : R →+* R[X])))).leadingCoeff).le_comap_map : Rₘ →+* Sₘ).IsIntegral := by
let P' : Ideal R := P.comap C
let M : Submonoid (R ⧸ P') :=
Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff
let M' : Submonoid (R[X] ⧸ P) :=
(Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff).map
(quotientMap P C le_rfl)
let φ : R ⧸ P' →+* R[X] ⧸ P := quotientMap P C le_rfl
let φ' : Rₘ →+* Sₘ := IsLocalization.map Sₘ φ M.le_comap_map
have hφ' : φ.comp (Quotient.mk P') = (Quotient.mk P).comp C := rfl
intro p
obtain ⟨⟨p', ⟨q, hq⟩⟩, hp⟩ := IsLocalization.surj M' p
suffices φ'.IsIntegralElem (algebraMap (R[X] ⧸ P) Sₘ p') by
obtain ⟨q', hq', rfl⟩ := hq
obtain ⟨q'', hq''⟩ := isUnit_iff_exists_inv'.1 (IsLocalization.map_units Rₘ (⟨q', hq'⟩ : M))
refine (hp.symm ▸ this).of_mul_unit φ' p (algebraMap (R[X] ⧸ P) Sₘ (φ q')) q'' ?_
rw [← φ'.map_one, ← congr_arg φ' hq'', φ'.map_mul, ← φ'.comp_apply]
simp only [IsLocalization.map_comp _]
rw [RingHom.comp_apply]
dsimp at hp
refine @IsIntegral.of_mem_closure'' Rₘ _ Sₘ _ φ'
((algebraMap (R[X] ⧸ P) Sₘ).comp (Quotient.mk P) '' insert X { p | p.degree ≤ 0 }) ?_
((algebraMap (R[X] ⧸ P) Sₘ) p') ?_
· rintro x ⟨p, hp, rfl⟩
simp only [Set.mem_insert_iff] at hp
cases' hp with hy hy
· rw [hy]
refine φ.isIntegralElem_localization_at_leadingCoeff ((Quotient.mk P) X)
(pX.map (Quotient.mk P')) ?_ M ?_
· rwa [eval₂_map, hφ', ← hom_eval₂, Quotient.eq_zero_iff_mem, eval₂_C_X]
· use 1
simp only [pow_one]
· rw [Set.mem_setOf_eq, degree_le_zero_iff] at hy
-- Porting note: was `refine' hy.symm ▸`
-- `⟨X - C (algebraMap _ _ ((Quotient.mk P') (p.coeff 0))), monic_X_sub_C _, _⟩`
rw [hy]
use X - C (algebraMap (R ⧸ P') Rₘ ((Quotient.mk P') (p.coeff 0)))
constructor
· apply monic_X_sub_C
· simp only [eval₂_sub, eval₂_X, eval₂_C]
rw [sub_eq_zero, ← φ'.comp_apply]
simp only [IsLocalization.map_comp _]
rfl
· obtain ⟨p, rfl⟩ := Quotient.mk_surjective p'
rw [← RingHom.comp_apply]
apply Subring.mem_closure_image_of
apply Polynomial.mem_closure_X_union_C
#align ideal.polynomial.is_integral_is_localization_polynomial_quotient Ideal.Polynomial.isIntegral_isLocalization_polynomial_quotient
/-- If `f : R → S` descends to an integral map in the localization at `x`,
and `R` is a Jacobson ring, then the intersection of all maximal ideals in `S` is trivial -/
theorem jacobson_bot_of_integral_localization {R : Type*} [CommRing R] [IsDomain R] [IsJacobson R]
(Rₘ Sₘ : Type*) [CommRing Rₘ] [CommRing Sₘ] (φ : R →+* S) (hφ : Function.Injective ↑φ) (x : R)
(hx : x ≠ 0) [Algebra R Rₘ] [IsLocalization.Away x Rₘ] [Algebra S Sₘ]
[IsLocalization ((Submonoid.powers x).map φ : Submonoid S) Sₘ]
(hφ' :
RingHom.IsIntegral (IsLocalization.map Sₘ φ (Submonoid.powers x).le_comap_map : Rₘ →+* Sₘ)) :
(⊥ : Ideal S).jacobson = (⊥ : Ideal S) := by
have hM : ((Submonoid.powers x).map φ : Submonoid S) ≤ nonZeroDivisors S :=
map_le_nonZeroDivisors_of_injective φ hφ (powers_le_nonZeroDivisors_of_noZeroDivisors hx)
letI : IsDomain Sₘ := IsLocalization.isDomain_of_le_nonZeroDivisors _ hM
let φ' : Rₘ →+* Sₘ := IsLocalization.map _ φ (Submonoid.powers x).le_comap_map
suffices ∀ I : Ideal Sₘ, I.IsMaximal → (I.comap (algebraMap S Sₘ)).IsMaximal by
have hϕ' : comap (algebraMap S Sₘ) (⊥ : Ideal Sₘ) = (⊥ : Ideal S) := by
rw [← RingHom.ker_eq_comap_bot, ← RingHom.injective_iff_ker_eq_bot]
exact IsLocalization.injective Sₘ hM
have hSₘ : IsJacobson Sₘ := isJacobson_of_isIntegral' φ' hφ' (isJacobson_localization x)
refine eq_bot_iff.mpr (le_trans ?_ (le_of_eq hϕ'))
rw [← hSₘ.out isRadical_bot_of_noZeroDivisors, comap_jacobson]
exact sInf_le_sInf fun j hj => ⟨bot_le,
let ⟨J, hJ⟩ := hj
hJ.2 ▸ this J hJ.1.2⟩
intro I hI
-- Remainder of the proof is pulling and pushing ideals around the square and the quotient square
haveI : (I.comap (algebraMap S Sₘ)).IsPrime := comap_isPrime _ I
haveI : (I.comap φ').IsPrime := comap_isPrime φ' I
haveI : (⊥ : Ideal (S ⧸ I.comap (algebraMap S Sₘ))).IsPrime := bot_prime
have hcomm : φ'.comp (algebraMap R Rₘ) = (algebraMap S Sₘ).comp φ := IsLocalization.map_comp _
let f := quotientMap (I.comap (algebraMap S Sₘ)) φ le_rfl
let g := quotientMap I (algebraMap S Sₘ) le_rfl
have := isMaximal_comap_of_isIntegral_of_isMaximal' φ' hφ' I
have := ((isMaximal_iff_isMaximal_disjoint Rₘ x _).1 this).left
have : ((I.comap (algebraMap S Sₘ)).comap φ).IsMaximal := by
rwa [comap_comap, hcomm, ← comap_comap] at this
rw [← bot_quotient_isMaximal_iff] at this ⊢
refine isMaximal_of_isIntegral_of_isMaximal_comap' f ?_ ⊥
((eq_bot_iff.2 (comap_bot_le_of_injective f quotientMap_injective)).symm ▸ this)
exact RingHom.IsIntegral.tower_bot f g quotientMap_injective
((comp_quotientMap_eq_of_comp_eq hcomm I).symm ▸
(RingHom.isIntegral_of_surjective _
(IsLocalization.surjective_quotientMap_of_maximal_of_localization (Submonoid.powers x) Rₘ
(by rwa [comap_comap, hcomm, ← bot_quotient_isMaximal_iff]))).trans _ _ (hφ'.quotient _))
#align ideal.polynomial.jacobson_bot_of_integral_localization Ideal.Polynomial.jacobson_bot_of_integral_localization
/-- Used to bootstrap the proof of `isJacobson_polynomial_iff_isJacobson`.
That theorem is more general and should be used instead of this one. -/
private theorem isJacobson_polynomial_of_domain (R : Type*) [CommRing R] [IsDomain R]
[hR : IsJacobson R] (P : Ideal R[X]) [IsPrime P] (hP : ∀ x : R, C x ∈ P → x = 0) :
P.jacobson = P := by
by_cases Pb : P = ⊥
· exact Pb.symm ▸
jacobson_bot_polynomial_of_jacobson_bot (hR.out isRadical_bot_of_noZeroDivisors)
· rw [jacobson_eq_iff_jacobson_quotient_eq_bot]
let P' := P.comap (C : R →+* R[X])
haveI : P'.IsPrime := comap_isPrime C P
haveI hR' : IsJacobson (R ⧸ P') := by infer_instance
obtain ⟨p, pP, p0⟩ := exists_nonzero_mem_of_ne_bot Pb hP
let x := (Polynomial.map (Quotient.mk P') p).leadingCoeff
have hx : x ≠ 0 := by rwa [Ne, leadingCoeff_eq_zero]
let φ : R ⧸ P' →+* R[X] ⧸ P := Ideal.quotientMap P (C : R →+* R[X]) le_rfl
let hφ : Function.Injective ↑φ := quotientMap_injective
let Rₘ := Localization.Away x
let Sₘ := (Localization ((Submonoid.powers x).map φ : Submonoid (R[X] ⧸ P)))
refine jacobson_bot_of_integral_localization (S := R[X] ⧸ P) (R := R ⧸ P') Rₘ Sₘ _ hφ _ hx ?_
haveI islocSₘ : IsLocalization (Submonoid.map φ (Submonoid.powers x)) Sₘ := by infer_instance
exact @isIntegral_isLocalization_polynomial_quotient R _ Rₘ Sₘ _ _ P p pP _ _ _ islocSₘ
theorem isJacobson_polynomial_of_isJacobson (hR : IsJacobson R) : IsJacobson R[X] := by
rw [isJacobson_iff_prime_eq]
intro I hI
let R' : Subring (R[X] ⧸ I) := ((Quotient.mk I).comp C).range
let i : R →+* R' := ((Quotient.mk I).comp C).rangeRestrict
have hi : Function.Surjective ↑i := ((Quotient.mk I).comp C).rangeRestrict_surjective
have hi' : RingHom.ker (mapRingHom i) ≤ I := by
intro f hf
apply polynomial_mem_ideal_of_coeff_mem_ideal I f
intro n
replace hf := congrArg (fun g : Polynomial ((Quotient.mk I).comp C).range => g.coeff n) hf
change (Polynomial.map ((Quotient.mk I).comp C).rangeRestrict f).coeff n = 0 at hf
rw [coeff_map, Subtype.ext_iff] at hf
rwa [mem_comap, ← Quotient.eq_zero_iff_mem, ← RingHom.comp_apply]
have R'_jacob : IsJacobson R' := isJacobson_of_surjective ⟨i, hi⟩
let J := map (mapRingHom i) I
-- Porting note: moved ↓ this up a few lines, so that it can be used in the `have`
have h_surj : Function.Surjective (mapRingHom i) := Polynomial.map_surjective i hi
have : IsPrime J := map_isPrime_of_surjective h_surj hi'
suffices h : J.jacobson = J by
replace h := congrArg (comap (Polynomial.mapRingHom i)) h
rw [← map_jacobson_of_surjective h_surj hi', comap_map_of_surjective _ h_surj,
comap_map_of_surjective _ h_surj] at h
refine le_antisymm ?_ le_jacobson
exact le_trans (le_sup_of_le_left le_rfl) (le_trans (le_of_eq h) (sup_le le_rfl hi'))
apply isJacobson_polynomial_of_domain R' J
exact eq_zero_of_polynomial_mem_map_range I
#align ideal.polynomial.is_jacobson_polynomial_of_is_jacobson Ideal.Polynomial.isJacobson_polynomial_of_isJacobson
theorem isJacobson_polynomial_iff_isJacobson : IsJacobson R[X] ↔ IsJacobson R := by
refine ⟨?_, isJacobson_polynomial_of_isJacobson⟩
intro H
exact isJacobson_of_surjective ⟨eval₂RingHom (RingHom.id _) 1, fun x =>
⟨C x, by simp only [coe_eval₂RingHom, RingHom.id_apply, eval₂_C]⟩⟩
#align ideal.polynomial.is_jacobson_polynomial_iff_is_jacobson Ideal.Polynomial.isJacobson_polynomial_iff_isJacobson
instance [IsJacobson R] : IsJacobson R[X] :=
isJacobson_polynomial_iff_isJacobson.mpr ‹IsJacobson R›
end CommRing
section
variable {R : Type*} [CommRing R] [IsJacobson R]
variable (P : Ideal R[X]) [hP : P.IsMaximal]
theorem isMaximal_comap_C_of_isMaximal [Nontrivial R] (hP' : ∀ x : R, C x ∈ P → x = 0) :
IsMaximal (comap (C : R →+* R[X]) P : Ideal R) := by
let P' := comap (C : R →+* R[X]) P
haveI hP'_prime : P'.IsPrime := comap_isPrime C P
obtain ⟨⟨m, hmem_P⟩, hm⟩ :=
Submodule.nonzero_mem_of_bot_lt (bot_lt_of_maximal P polynomial_not_isField)
have hm' : m ≠ 0 := by
simpa [Submodule.coe_eq_zero] using hm
let φ : R ⧸ P' →+* R[X] ⧸ P := quotientMap P (C : R →+* R[X]) le_rfl
let a : R ⧸ P' := (m.map (Quotient.mk P')).leadingCoeff
let M : Submonoid (R ⧸ P') := Submonoid.powers a
rw [← bot_quotient_isMaximal_iff]
have hp0 : a ≠ 0 := fun hp0' =>
hm' <| map_injective (Quotient.mk (P.comap (C : R →+* R[X]) : Ideal R))
((injective_iff_map_eq_zero (Quotient.mk (P.comap (C : R →+* R[X]) : Ideal R))).2
fun x hx => by
rwa [Quotient.eq_zero_iff_mem, (by rwa [eq_bot_iff] : (P.comap C : Ideal R) = ⊥)] at hx)
(by simpa only [a, leadingCoeff_eq_zero, Polynomial.map_zero] using hp0')
have hM : (0 : R ⧸ P') ∉ M := fun ⟨n, hn⟩ => hp0 (pow_eq_zero hn)
suffices (⊥ : Ideal (Localization M)).IsMaximal by
rw [← IsLocalization.comap_map_of_isPrime_disjoint M (Localization M) ⊥ bot_prime
(disjoint_iff_inf_le.mpr fun x hx => hM (hx.2 ▸ hx.1))]
exact ((isMaximal_iff_isMaximal_disjoint (Localization M) a _).mp (by rwa [map_bot])).1
let M' : Submonoid (R[X] ⧸ P) := M.map φ
have hM' : (0 : R[X] ⧸ P) ∉ M' := fun ⟨z, hz⟩ =>
hM (quotientMap_injective (_root_.trans hz.2 φ.map_zero.symm) ▸ hz.1)
haveI : IsDomain (Localization M') :=
IsLocalization.isDomain_localization (le_nonZeroDivisors_of_noZeroDivisors hM')
suffices (⊥ : Ideal (Localization M')).IsMaximal by
rw [le_antisymm bot_le (comap_bot_le_of_injective _
(IsLocalization.map_injective_of_injective M (Localization M) (Localization M')
quotientMap_injective))]
refine isMaximal_comap_of_isIntegral_of_isMaximal' _ ?_ ⊥
have isloc : IsLocalization (Submonoid.map φ M) (Localization M') := by infer_instance
exact @isIntegral_isLocalization_polynomial_quotient R _
(Localization M) (Localization M') _ _ P m hmem_P _ _ _ isloc
rw [(map_bot.symm :
(⊥ : Ideal (Localization M')) = map (algebraMap (R[X] ⧸ P) (Localization M')) ⊥)]
let bot_maximal := (bot_quotient_isMaximal_iff _).mpr hP
refine map.isMaximal (algebraMap (R[X] ⧸ P) (Localization M')) ?_ bot_maximal
apply IsField.localization_map_bijective hM'
rwa [← Quotient.maximal_ideal_iff_isField_quotient, ← bot_quotient_isMaximal_iff]
set_option linter.uppercaseLean3 false in
#align ideal.polynomial.is_maximal_comap_C_of_is_maximal Ideal.Polynomial.isMaximal_comap_C_of_isMaximal
/-- Used to bootstrap the more general `quotient_mk_comp_C_isIntegral_of_jacobson` -/
private theorem quotient_mk_comp_C_isIntegral_of_jacobson' [Nontrivial R] (hR : IsJacobson R)
(hP' : ∀ x : R, C x ∈ P → x = 0) : ((Quotient.mk P).comp C : R →+* R[X] ⧸ P).IsIntegral := by
refine (isIntegral_quotientMap_iff _).mp ?_
let P' : Ideal R := P.comap C
obtain ⟨pX, hpX, hp0⟩ :=
exists_nonzero_mem_of_ne_bot (ne_of_lt (bot_lt_of_maximal P polynomial_not_isField)).symm hP'
let a : R ⧸ P' := (pX.map (Quotient.mk P')).leadingCoeff
let M : Submonoid (R ⧸ P') := Submonoid.powers a
let φ : R ⧸ P' →+* R[X] ⧸ P := quotientMap P C le_rfl
haveI hP'_prime : P'.IsPrime := comap_isPrime C P
have hM : (0 : R ⧸ P') ∉ M := fun ⟨n, hn⟩ => hp0 <| leadingCoeff_eq_zero.mp (pow_eq_zero hn)
let M' : Submonoid (R[X] ⧸ P) := M.map φ
refine RingHom.IsIntegral.tower_bot φ (algebraMap _ (Localization M')) ?_ ?_
· refine IsLocalization.injective (Localization M')
(show M' ≤ _ from le_nonZeroDivisors_of_noZeroDivisors fun hM' => hM ?_)
exact
let ⟨z, zM, z0⟩ := hM'
quotientMap_injective (_root_.trans z0 φ.map_zero.symm) ▸ zM
· suffices RingHom.comp (algebraMap (R[X] ⧸ P) (Localization M')) φ =
(IsLocalization.map (Localization M') φ M.le_comap_map).comp
(algebraMap (R ⧸ P') (Localization M)) by
rw [this]
refine RingHom.IsIntegral.trans (algebraMap (R ⧸ P') (Localization M))
(IsLocalization.map (Localization M') φ M.le_comap_map) ?_ ?_
· exact (algebraMap (R ⧸ P') (Localization M)).isIntegral_of_surjective
(IsField.localization_map_bijective hM ((Quotient.maximal_ideal_iff_isField_quotient _).mp
(isMaximal_comap_C_of_isMaximal P hP'))).2
· -- `convert` here is faster than `exact`, and this proof is near the time limit.
-- convert isIntegral_isLocalization_polynomial_quotient P pX hpX
have isloc : IsLocalization M' (Localization M') := by infer_instance
exact @isIntegral_isLocalization_polynomial_quotient R _
(Localization M) (Localization M') _ _ P pX hpX _ _ _ isloc
rw [IsLocalization.map_comp M.le_comap_map]
/-- If `R` is a Jacobson ring, and `P` is a maximal ideal of `R[X]`,
then `R → R[X]/P` is an integral map. -/
theorem quotient_mk_comp_C_isIntegral_of_jacobson :
((Quotient.mk P).comp C : R →+* R[X] ⧸ P).IsIntegral := by
let P' : Ideal R := P.comap C
haveI : P'.IsPrime := comap_isPrime C P
let f : R[X] →+* Polynomial (R ⧸ P') := Polynomial.mapRingHom (Quotient.mk P')
have hf : Function.Surjective ↑f := map_surjective (Quotient.mk P') Quotient.mk_surjective
have hPJ : P = (P.map f).comap f := by
rw [comap_map_of_surjective _ hf]
refine le_antisymm (le_sup_of_le_left le_rfl) (sup_le le_rfl ?_)
refine fun p hp =>
polynomial_mem_ideal_of_coeff_mem_ideal P p fun n => Quotient.eq_zero_iff_mem.mp ?_
simpa only [f, coeff_map, coe_mapRingHom] using (Polynomial.ext_iff.mp hp) n
refine RingHom.IsIntegral.tower_bot _ _ (injective_quotient_le_comap_map P) ?_
rw [← quotient_mk_maps_eq]
refine ((Quotient.mk P').isIntegral_of_surjective Quotient.mk_surjective).trans _ _ ?_
have : IsMaximal (map (mapRingHom (Quotient.mk (comap C P))) P) :=
Or.recOn (map_eq_top_or_isMaximal_of_surjective f hf hP)
(fun h => absurd (_root_.trans (h ▸ hPJ : P = comap f ⊤) comap_top : P = ⊤) hP.ne_top) id
apply quotient_mk_comp_C_isIntegral_of_jacobson' _ ?_ (fun x hx => ?_)
any_goals exact Ideal.isJacobson_quotient
obtain ⟨z, rfl⟩ := Quotient.mk_surjective x
rwa [Quotient.eq_zero_iff_mem, mem_comap, hPJ, mem_comap, coe_mapRingHom, map_C]
set_option linter.uppercaseLean3 false in
#align ideal.polynomial.quotient_mk_comp_C_is_integral_of_jacobson Ideal.Polynomial.quotient_mk_comp_C_isIntegral_of_jacobson
| Mathlib/RingTheory/Jacobson.lean | 579 | 583 | theorem isMaximal_comap_C_of_isJacobson : (P.comap (C : R →+* R[X])).IsMaximal := by |
rw [← @mk_ker _ _ P, RingHom.ker_eq_comap_bot, comap_comap]
have := (bot_quotient_isMaximal_iff _).mpr hP
exact isMaximal_comap_of_isIntegral_of_isMaximal' _ (quotient_mk_comp_C_isIntegral_of_jacobson P)
⊥
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.SetTheory.Game.State
#align_import set_theory.game.domineering from "leanprover-community/mathlib"@"b134b2f5cf6dd25d4bbfd3c498b6e36c11a17225"
/-!
# Domineering as a combinatorial game.
We define the game of Domineering, played on a chessboard of arbitrary shape
(possibly even disconnected).
Left moves by placing a domino vertically, while Right moves by placing a domino horizontally.
This is only a fragment of a full development;
in order to successfully analyse positions we would need some more theorems.
Most importantly, we need a general statement that allows us to discard irrelevant moves.
Specifically to domineering, we need the fact that
disjoint parts of the chessboard give sums of games.
-/
namespace SetTheory
namespace PGame
namespace Domineering
open Function
/-- The equivalence `(x, y) ↦ (x, y+1)`. -/
@[simps!]
def shiftUp : ℤ × ℤ ≃ ℤ × ℤ :=
(Equiv.refl ℤ).prodCongr (Equiv.addRight (1 : ℤ))
#align pgame.domineering.shift_up SetTheory.PGame.Domineering.shiftUp
/-- The equivalence `(x, y) ↦ (x+1, y)`. -/
@[simps!]
def shiftRight : ℤ × ℤ ≃ ℤ × ℤ :=
(Equiv.addRight (1 : ℤ)).prodCongr (Equiv.refl ℤ)
#align pgame.domineering.shift_right SetTheory.PGame.Domineering.shiftRight
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
-- Porting note: reducibility cannot be `local`. For now there are no dependents of this file so
-- being globally reducible is fine.
abbrev Board :=
Finset (ℤ × ℤ)
#align pgame.domineering.board SetTheory.PGame.Domineering.Board
/-- Left can play anywhere that a square and the square below it are open. -/
def left (b : Board) : Finset (ℤ × ℤ) :=
b ∩ b.map shiftUp
#align pgame.domineering.left SetTheory.PGame.Domineering.left
/-- Right can play anywhere that a square and the square to the left are open. -/
def right (b : Board) : Finset (ℤ × ℤ) :=
b ∩ b.map shiftRight
#align pgame.domineering.right SetTheory.PGame.Domineering.right
theorem mem_left {b : Board} (x : ℤ × ℤ) : x ∈ left b ↔ x ∈ b ∧ (x.1, x.2 - 1) ∈ b :=
Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv)
#align pgame.domineering.mem_left SetTheory.PGame.Domineering.mem_left
theorem mem_right {b : Board} (x : ℤ × ℤ) : x ∈ right b ↔ x ∈ b ∧ (x.1 - 1, x.2) ∈ b :=
Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv)
#align pgame.domineering.mem_right SetTheory.PGame.Domineering.mem_right
/-- After Left moves, two vertically adjacent squares are removed from the board. -/
def moveLeft (b : Board) (m : ℤ × ℤ) : Board :=
(b.erase m).erase (m.1, m.2 - 1)
#align pgame.domineering.move_left SetTheory.PGame.Domineering.moveLeft
/-- After Left moves, two horizontally adjacent squares are removed from the board. -/
def moveRight (b : Board) (m : ℤ × ℤ) : Board :=
(b.erase m).erase (m.1 - 1, m.2)
#align pgame.domineering.move_right SetTheory.PGame.Domineering.moveRight
theorem fst_pred_mem_erase_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) :
(m.1 - 1, m.2) ∈ b.erase m := by
rw [mem_right] at h
apply Finset.mem_erase_of_ne_of_mem _ h.2
exact ne_of_apply_ne Prod.fst (pred_ne_self m.1)
#align pgame.domineering.fst_pred_mem_erase_of_mem_right SetTheory.PGame.Domineering.fst_pred_mem_erase_of_mem_right
theorem snd_pred_mem_erase_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) :
(m.1, m.2 - 1) ∈ b.erase m := by
rw [mem_left] at h
apply Finset.mem_erase_of_ne_of_mem _ h.2
exact ne_of_apply_ne Prod.snd (pred_ne_self m.2)
#align pgame.domineering.snd_pred_mem_erase_of_mem_left SetTheory.PGame.Domineering.snd_pred_mem_erase_of_mem_left
theorem card_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) : 2 ≤ Finset.card b := by
have w₁ : m ∈ b := (Finset.mem_inter.1 h).1
have w₂ : (m.1, m.2 - 1) ∈ b.erase m := snd_pred_mem_erase_of_mem_left h
have i₁ := Finset.card_erase_lt_of_mem w₁
have i₂ := Nat.lt_of_le_of_lt (Nat.zero_le _) (Finset.card_erase_lt_of_mem w₂)
exact Nat.lt_of_le_of_lt i₂ i₁
#align pgame.domineering.card_of_mem_left SetTheory.PGame.Domineering.card_of_mem_left
theorem card_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) : 2 ≤ Finset.card b := by
have w₁ : m ∈ b := (Finset.mem_inter.1 h).1
have w₂ := fst_pred_mem_erase_of_mem_right h
have i₁ := Finset.card_erase_lt_of_mem w₁
have i₂ := Nat.lt_of_le_of_lt (Nat.zero_le _) (Finset.card_erase_lt_of_mem w₂)
exact Nat.lt_of_le_of_lt i₂ i₁
#align pgame.domineering.card_of_mem_right SetTheory.PGame.Domineering.card_of_mem_right
theorem moveLeft_card {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) :
Finset.card (moveLeft b m) + 2 = Finset.card b := by
dsimp [moveLeft]
rw [Finset.card_erase_of_mem (snd_pred_mem_erase_of_mem_left h)]
rw [Finset.card_erase_of_mem (Finset.mem_of_mem_inter_left h)]
exact tsub_add_cancel_of_le (card_of_mem_left h)
#align pgame.domineering.move_left_card SetTheory.PGame.Domineering.moveLeft_card
| Mathlib/SetTheory/Game/Domineering.lean | 117 | 122 | theorem moveRight_card {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) :
Finset.card (moveRight b m) + 2 = Finset.card b := by |
dsimp [moveRight]
rw [Finset.card_erase_of_mem (fst_pred_mem_erase_of_mem_right h)]
rw [Finset.card_erase_of_mem (Finset.mem_of_mem_inter_left h)]
exact tsub_add_cancel_of_le (card_of_mem_right h)
|
/-
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.Analysis.Convex.Basic
import Mathlib.Topology.Algebra.Group.Basic
import Mathlib.Topology.Order.Basic
#align_import analysis.convex.strict from "leanprover-community/mathlib"@"84dc0bd6619acaea625086d6f53cb35cdd554219"
/-!
# Strictly convex sets
This file defines strictly convex sets.
A set is strictly convex if the open segment between any two distinct points lies in its interior.
-/
open Set
open Convex Pointwise
variable {𝕜 𝕝 E F β : Type*}
open Function Set
open Convex
section OrderedSemiring
variable [OrderedSemiring 𝕜] [TopologicalSpace E] [TopologicalSpace F]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F]
section SMul
variable (𝕜)
variable [SMul 𝕜 E] [SMul 𝕜 F] (s : Set E)
/-- A set is strictly convex if the open segment between any two distinct points lies is in its
interior. This basically means "convex and not flat on the boundary". -/
def StrictConvex : Prop :=
s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ interior s
#align strict_convex StrictConvex
variable {𝕜 s}
variable {x y : E} {a b : 𝕜}
theorem strictConvex_iff_openSegment_subset :
StrictConvex 𝕜 s ↔ s.Pairwise fun x y => openSegment 𝕜 x y ⊆ interior s :=
forall₅_congr fun _ _ _ _ _ => (openSegment_subset_iff 𝕜).symm
#align strict_convex_iff_open_segment_subset strictConvex_iff_openSegment_subset
theorem StrictConvex.openSegment_subset (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s)
(h : x ≠ y) : openSegment 𝕜 x y ⊆ interior s :=
strictConvex_iff_openSegment_subset.1 hs hx hy h
#align strict_convex.open_segment_subset StrictConvex.openSegment_subset
theorem strictConvex_empty : StrictConvex 𝕜 (∅ : Set E) :=
pairwise_empty _
#align strict_convex_empty strictConvex_empty
theorem strictConvex_univ : StrictConvex 𝕜 (univ : Set E) := by
intro x _ y _ _ a b _ _ _
rw [interior_univ]
exact mem_univ _
#align strict_convex_univ strictConvex_univ
protected nonrec theorem StrictConvex.eq (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s)
(ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (h : a • x + b • y ∉ interior s) : x = y :=
hs.eq hx hy fun H => h <| H ha hb hab
#align strict_convex.eq StrictConvex.eq
protected theorem StrictConvex.inter {t : Set E} (hs : StrictConvex 𝕜 s) (ht : StrictConvex 𝕜 t) :
StrictConvex 𝕜 (s ∩ t) := by
intro x hx y hy hxy a b ha hb hab
rw [interior_inter]
exact ⟨hs hx.1 hy.1 hxy ha hb hab, ht hx.2 hy.2 hxy ha hb hab⟩
#align strict_convex.inter StrictConvex.inter
theorem Directed.strictConvex_iUnion {ι : Sort*} {s : ι → Set E} (hdir : Directed (· ⊆ ·) s)
(hs : ∀ ⦃i : ι⦄, StrictConvex 𝕜 (s i)) : StrictConvex 𝕜 (⋃ i, s i) := by
rintro x hx y hy hxy a b ha hb hab
rw [mem_iUnion] at hx hy
obtain ⟨i, hx⟩ := hx
obtain ⟨j, hy⟩ := hy
obtain ⟨k, hik, hjk⟩ := hdir i j
exact interior_mono (subset_iUnion s k) (hs (hik hx) (hjk hy) hxy ha hb hab)
#align directed.strict_convex_Union Directed.strictConvex_iUnion
theorem DirectedOn.strictConvex_sUnion {S : Set (Set E)} (hdir : DirectedOn (· ⊆ ·) S)
(hS : ∀ s ∈ S, StrictConvex 𝕜 s) : StrictConvex 𝕜 (⋃₀ S) := by
rw [sUnion_eq_iUnion]
exact (directedOn_iff_directed.1 hdir).strictConvex_iUnion fun s => hS _ s.2
#align directed_on.strict_convex_sUnion DirectedOn.strictConvex_sUnion
end SMul
section Module
variable [Module 𝕜 E] [Module 𝕜 F] {s : Set E}
protected theorem StrictConvex.convex (hs : StrictConvex 𝕜 s) : Convex 𝕜 s :=
convex_iff_pairwise_pos.2 fun _ hx _ hy hxy _ _ ha hb hab =>
interior_subset <| hs hx hy hxy ha hb hab
#align strict_convex.convex StrictConvex.convex
/-- An open convex set is strictly convex. -/
protected theorem Convex.strictConvex_of_isOpen (h : IsOpen s) (hs : Convex 𝕜 s) :
StrictConvex 𝕜 s :=
fun _ hx _ hy _ _ _ ha hb hab => h.interior_eq.symm ▸ hs hx hy ha.le hb.le hab
#align convex.strict_convex_of_open Convex.strictConvex_of_isOpen
theorem IsOpen.strictConvex_iff (h : IsOpen s) : StrictConvex 𝕜 s ↔ Convex 𝕜 s :=
⟨StrictConvex.convex, Convex.strictConvex_of_isOpen h⟩
#align is_open.strict_convex_iff IsOpen.strictConvex_iff
theorem strictConvex_singleton (c : E) : StrictConvex 𝕜 ({c} : Set E) :=
pairwise_singleton _ _
#align strict_convex_singleton strictConvex_singleton
theorem Set.Subsingleton.strictConvex (hs : s.Subsingleton) : StrictConvex 𝕜 s :=
hs.pairwise _
#align set.subsingleton.strict_convex Set.Subsingleton.strictConvex
theorem StrictConvex.linear_image [Semiring 𝕝] [Module 𝕝 E] [Module 𝕝 F]
[LinearMap.CompatibleSMul E F 𝕜 𝕝] (hs : StrictConvex 𝕜 s) (f : E →ₗ[𝕝] F) (hf : IsOpenMap f) :
StrictConvex 𝕜 (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ hxy a b ha hb hab
refine hf.image_interior_subset _ ⟨a • x + b • y, hs hx hy (ne_of_apply_ne _ hxy) ha hb hab, ?_⟩
rw [map_add, f.map_smul_of_tower a, f.map_smul_of_tower b]
#align strict_convex.linear_image StrictConvex.linear_image
theorem StrictConvex.is_linear_image (hs : StrictConvex 𝕜 s) {f : E → F} (h : IsLinearMap 𝕜 f)
(hf : IsOpenMap f) : StrictConvex 𝕜 (f '' s) :=
hs.linear_image (h.mk' f) hf
#align strict_convex.is_linear_image StrictConvex.is_linear_image
theorem StrictConvex.linear_preimage {s : Set F} (hs : StrictConvex 𝕜 s) (f : E →ₗ[𝕜] F)
(hf : Continuous f) (hfinj : Injective f) : StrictConvex 𝕜 (s.preimage f) := by
intro x hx y hy hxy a b ha hb hab
refine preimage_interior_subset_interior_preimage hf ?_
rw [mem_preimage, f.map_add, f.map_smul, f.map_smul]
exact hs hx hy (hfinj.ne hxy) ha hb hab
#align strict_convex.linear_preimage StrictConvex.linear_preimage
theorem StrictConvex.is_linear_preimage {s : Set F} (hs : StrictConvex 𝕜 s) {f : E → F}
(h : IsLinearMap 𝕜 f) (hf : Continuous f) (hfinj : Injective f) :
StrictConvex 𝕜 (s.preimage f) :=
hs.linear_preimage (h.mk' f) hf hfinj
#align strict_convex.is_linear_preimage StrictConvex.is_linear_preimage
section LinearOrderedCancelAddCommMonoid
variable [TopologicalSpace β] [LinearOrderedCancelAddCommMonoid β] [OrderTopology β] [Module 𝕜 β]
[OrderedSMul 𝕜 β]
protected theorem Set.OrdConnected.strictConvex {s : Set β} (hs : OrdConnected s) :
StrictConvex 𝕜 s := by
refine strictConvex_iff_openSegment_subset.2 fun x hx y hy hxy => ?_
cases' hxy.lt_or_lt with hlt hlt <;> [skip; rw [openSegment_symm]] <;>
exact
(openSegment_subset_Ioo hlt).trans
(isOpen_Ioo.subset_interior_iff.2 <| Ioo_subset_Icc_self.trans <| hs.out ‹_› ‹_›)
#align set.ord_connected.strict_convex Set.OrdConnected.strictConvex
theorem strictConvex_Iic (r : β) : StrictConvex 𝕜 (Iic r) :=
ordConnected_Iic.strictConvex
#align strict_convex_Iic strictConvex_Iic
theorem strictConvex_Ici (r : β) : StrictConvex 𝕜 (Ici r) :=
ordConnected_Ici.strictConvex
#align strict_convex_Ici strictConvex_Ici
theorem strictConvex_Iio (r : β) : StrictConvex 𝕜 (Iio r) :=
ordConnected_Iio.strictConvex
#align strict_convex_Iio strictConvex_Iio
theorem strictConvex_Ioi (r : β) : StrictConvex 𝕜 (Ioi r) :=
ordConnected_Ioi.strictConvex
#align strict_convex_Ioi strictConvex_Ioi
theorem strictConvex_Icc (r s : β) : StrictConvex 𝕜 (Icc r s) :=
ordConnected_Icc.strictConvex
#align strict_convex_Icc strictConvex_Icc
theorem strictConvex_Ioo (r s : β) : StrictConvex 𝕜 (Ioo r s) :=
ordConnected_Ioo.strictConvex
#align strict_convex_Ioo strictConvex_Ioo
theorem strictConvex_Ico (r s : β) : StrictConvex 𝕜 (Ico r s) :=
ordConnected_Ico.strictConvex
#align strict_convex_Ico strictConvex_Ico
theorem strictConvex_Ioc (r s : β) : StrictConvex 𝕜 (Ioc r s) :=
ordConnected_Ioc.strictConvex
#align strict_convex_Ioc strictConvex_Ioc
theorem strictConvex_uIcc (r s : β) : StrictConvex 𝕜 (uIcc r s) :=
strictConvex_Icc _ _
#align strict_convex_uIcc strictConvex_uIcc
theorem strictConvex_uIoc (r s : β) : StrictConvex 𝕜 (uIoc r s) :=
strictConvex_Ioc _ _
#align strict_convex_uIoc strictConvex_uIoc
end LinearOrderedCancelAddCommMonoid
end Module
end AddCommMonoid
section AddCancelCommMonoid
variable [AddCancelCommMonoid E] [ContinuousAdd E] [Module 𝕜 E] {s : Set E}
/-- The translation of a strictly convex set is also strictly convex. -/
theorem StrictConvex.preimage_add_right (hs : StrictConvex 𝕜 s) (z : E) :
StrictConvex 𝕜 ((fun x => z + x) ⁻¹' s) := by
intro x hx y hy hxy a b ha hb hab
refine preimage_interior_subset_interior_preimage (continuous_add_left _) ?_
have h := hs hx hy ((add_right_injective _).ne hxy) ha hb hab
rwa [smul_add, smul_add, add_add_add_comm, ← _root_.add_smul, hab, one_smul] at h
#align strict_convex.preimage_add_right StrictConvex.preimage_add_right
/-- The translation of a strictly convex set is also strictly convex. -/
| Mathlib/Analysis/Convex/Strict.lean | 231 | 233 | theorem StrictConvex.preimage_add_left (hs : StrictConvex 𝕜 s) (z : E) :
StrictConvex 𝕜 ((fun x => x + z) ⁻¹' s) := by |
simpa only [add_comm] using hs.preimage_add_right z
|
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Init.Data.List.Basic
import Mathlib.Init.Data.List.Instances
import Mathlib.Init.Data.List.Lemmas
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
#align_import data.list.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83"
/-!
# Basic properties of lists
-/
assert_not_exists Set.range
assert_not_exists GroupWithZero
assert_not_exists Ring
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
-- Porting note: Delete this attribute
-- attribute [inline] List.head!
/-- There is only one list of an empty type -/
instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) :=
{ instInhabitedList with
uniq := fun l =>
match l with
| [] => rfl
| a :: _ => isEmptyElim a }
#align list.unique_of_is_empty List.uniqueOfIsEmpty
instance : Std.LawfulIdentity (α := List α) Append.append [] where
left_id := nil_append
right_id := append_nil
instance : Std.Associative (α := List α) Append.append where
assoc := append_assoc
#align list.cons_ne_nil List.cons_ne_nil
#align list.cons_ne_self List.cons_ne_self
#align list.head_eq_of_cons_eq List.head_eq_of_cons_eqₓ -- implicits order
#align list.tail_eq_of_cons_eq List.tail_eq_of_cons_eqₓ -- implicits order
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
#align list.cons_injective List.cons_injective
#align list.cons_inj List.cons_inj
#align list.cons_eq_cons List.cons_eq_cons
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
#align list.singleton_injective List.singleton_injective
theorem singleton_inj {a b : α} : [a] = [b] ↔ a = b :=
singleton_injective.eq_iff
#align list.singleton_inj List.singleton_inj
#align list.exists_cons_of_ne_nil List.exists_cons_of_ne_nil
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
#align list.set_of_mem_cons List.set_of_mem_cons
/-! ### mem -/
#align list.mem_singleton_self List.mem_singleton_self
#align list.eq_of_mem_singleton List.eq_of_mem_singleton
#align list.mem_singleton List.mem_singleton
#align list.mem_of_mem_cons_of_mem List.mem_of_mem_cons_of_mem
theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α]
{a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by
by_cases hab : a = b
· exact Or.inl hab
· exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩))
#align decidable.list.eq_or_ne_mem_of_mem Decidable.List.eq_or_ne_mem_of_mem
#align list.eq_or_ne_mem_of_mem List.eq_or_ne_mem_of_mem
#align list.not_mem_append List.not_mem_append
#align list.ne_nil_of_mem List.ne_nil_of_mem
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
@[deprecated (since := "2024-03-23")] alias mem_split := append_of_mem
#align list.mem_split List.append_of_mem
#align list.mem_of_ne_of_mem List.mem_of_ne_of_mem
#align list.ne_of_not_mem_cons List.ne_of_not_mem_cons
#align list.not_mem_of_not_mem_cons List.not_mem_of_not_mem_cons
#align list.not_mem_cons_of_ne_of_not_mem List.not_mem_cons_of_ne_of_not_mem
#align list.ne_and_not_mem_of_not_mem_cons List.ne_and_not_mem_of_not_mem_cons
#align list.mem_map List.mem_map
#align list.exists_of_mem_map List.exists_of_mem_map
#align list.mem_map_of_mem List.mem_map_of_memₓ -- implicits order
-- The simpNF linter says that the LHS can be simplified via `List.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 : Injective f) {a : α} {l : List α} :
f a ∈ map f l ↔ a ∈ l :=
⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem _⟩
#align list.mem_map_of_injective List.mem_map_of_injective
@[simp]
theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α}
(hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l :=
⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩
#align function.involutive.exists_mem_and_apply_eq_iff Function.Involutive.exists_mem_and_apply_eq_iff
theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} :
a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff]
#align list.mem_map_of_involutive List.mem_map_of_involutive
#align list.forall_mem_map_iff List.forall_mem_map_iffₓ -- universe order
#align list.map_eq_nil List.map_eq_nilₓ -- universe order
attribute [simp] List.mem_join
#align list.mem_join List.mem_join
#align list.exists_of_mem_join List.exists_of_mem_join
#align list.mem_join_of_mem List.mem_join_of_memₓ -- implicits order
attribute [simp] List.mem_bind
#align list.mem_bind List.mem_bindₓ -- implicits order
-- Porting note: bExists in Lean3, And in Lean4
#align list.exists_of_mem_bind List.exists_of_mem_bindₓ -- implicits order
#align list.mem_bind_of_mem List.mem_bind_of_memₓ -- implicits order
#align list.bind_map List.bind_mapₓ -- implicits order
theorem map_bind (g : β → List γ) (f : α → β) :
∀ l : List α, (List.map f l).bind g = l.bind fun a => g (f a)
| [] => rfl
| a :: l => by simp only [cons_bind, map_cons, map_bind _ _ l]
#align list.map_bind List.map_bind
/-! ### length -/
#align list.length_eq_zero List.length_eq_zero
#align list.length_singleton List.length_singleton
#align list.length_pos_of_mem List.length_pos_of_mem
#align list.exists_mem_of_length_pos List.exists_mem_of_length_pos
#align list.length_pos_iff_exists_mem List.length_pos_iff_exists_mem
alias ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ := length_pos
#align list.ne_nil_of_length_pos List.ne_nil_of_length_pos
#align list.length_pos_of_ne_nil List.length_pos_of_ne_nil
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
#align list.length_pos_iff_ne_nil List.length_pos_iff_ne_nil
#align list.exists_mem_of_ne_nil List.exists_mem_of_ne_nil
#align list.length_eq_one List.length_eq_one
theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t
| [], H => absurd H.symm <| succ_ne_zero n
| h :: t, _ => ⟨h, t, rfl⟩
#align list.exists_of_length_succ List.exists_of_length_succ
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
constructor
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl
· intros hα l1 l2 hl
induction l1 generalizing l2 <;> cases l2
· rfl
· cases hl
· cases hl
· next ih _ _ =>
congr
· exact Subsingleton.elim _ _
· apply ih; simpa using hl
#align list.length_injective_iff List.length_injective_iff
@[simp default+1] -- Porting note: this used to be just @[simp]
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
#align list.length_injective List.length_injective
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
#align list.length_eq_two List.length_eq_two
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
#align list.length_eq_three List.length_eq_three
#align list.sublist.length_le List.Sublist.length_le
/-! ### set-theoretic notation of lists -/
-- ADHOC Porting note: instance from Lean3 core
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
#align list.has_singleton List.instSingletonList
-- ADHOC Porting note: instance from Lean3 core
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
-- ADHOC Porting note: instance from Lean3 core
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_emptyc_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg (not_mem_nil _) }
#align list.empty_eq List.empty_eq
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
#align list.singleton_eq List.singleton_eq
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
#align list.insert_neg List.insert_neg
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
#align list.insert_pos List.insert_pos
theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by
rw [insert_neg, singleton_eq]
rwa [singleton_eq, mem_singleton]
#align list.doubleton_eq List.doubleton_eq
/-! ### bounded quantifiers over lists -/
#align list.forall_mem_nil List.forall_mem_nil
#align list.forall_mem_cons List.forall_mem_cons
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x := (forall_mem_cons.1 h).2
#align list.forall_mem_of_forall_mem_cons List.forall_mem_of_forall_mem_cons
#align list.forall_mem_singleton List.forall_mem_singleton
#align list.forall_mem_append List.forall_mem_append
#align list.not_exists_mem_nil List.not_exists_mem_nilₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self _ _, h⟩
#align list.exists_mem_cons_of List.exists_mem_cons_ofₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) →
∃ x ∈ a :: l, p x :=
fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩
#align list.exists_mem_cons_of_exists List.exists_mem_cons_of_existsₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) →
p a ∨ ∃ x ∈ l, p x :=
fun ⟨x, xal, px⟩ =>
Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px)
fun h : x ∈ l => Or.inr ⟨x, h, px⟩
#align list.or_exists_of_exists_mem_cons List.or_exists_of_exists_mem_consₓ -- bExists change
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
Iff.intro or_exists_of_exists_mem_cons fun h =>
Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists
#align list.exists_mem_cons_iff List.exists_mem_cons_iff
/-! ### list subset -/
instance : IsTrans (List α) Subset where
trans := fun _ _ _ => List.Subset.trans
#align list.subset_def List.subset_def
#align list.subset_append_of_subset_left List.subset_append_of_subset_left
#align list.subset_append_of_subset_right List.subset_append_of_subset_right
#align list.cons_subset List.cons_subset
theorem cons_subset_of_subset_of_mem {a : α} {l m : List α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
#align list.cons_subset_of_subset_of_mem List.cons_subset_of_subset_of_mem
theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
#align list.append_subset_of_subset_of_subset List.append_subset_of_subset_of_subset
-- Porting note: in Batteries
#align list.append_subset_iff List.append_subset
alias ⟨eq_nil_of_subset_nil, _⟩ := subset_nil
#align list.eq_nil_of_subset_nil List.eq_nil_of_subset_nil
#align list.eq_nil_iff_forall_not_mem List.eq_nil_iff_forall_not_mem
#align list.map_subset List.map_subset
theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by
refine ⟨?_, map_subset f⟩; intro h2 x hx
rcases mem_map.1 (h2 (mem_map_of_mem f hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
#align list.map_subset_iff List.map_subset_iff
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
#align list.append_eq_has_append List.append_eq_has_append
#align list.singleton_append List.singleton_append
#align list.append_ne_nil_of_ne_nil_left List.append_ne_nil_of_ne_nil_left
#align list.append_ne_nil_of_ne_nil_right List.append_ne_nil_of_ne_nil_right
#align list.append_eq_nil List.append_eq_nil
-- Porting note: in Batteries
#align list.nil_eq_append_iff List.nil_eq_append
@[deprecated (since := "2024-03-24")] alias append_eq_cons_iff := append_eq_cons
#align list.append_eq_cons_iff List.append_eq_cons
@[deprecated (since := "2024-03-24")] alias cons_eq_append_iff := cons_eq_append
#align list.cons_eq_append_iff List.cons_eq_append
#align list.append_eq_append_iff List.append_eq_append_iff
#align list.take_append_drop List.take_append_drop
#align list.append_inj List.append_inj
#align list.append_inj_right List.append_inj_rightₓ -- implicits order
#align list.append_inj_left List.append_inj_leftₓ -- implicits order
#align list.append_inj' List.append_inj'ₓ -- implicits order
#align list.append_inj_right' List.append_inj_right'ₓ -- implicits order
#align list.append_inj_left' List.append_inj_left'ₓ -- implicits order
@[deprecated (since := "2024-01-18")] alias append_left_cancel := append_cancel_left
#align list.append_left_cancel List.append_cancel_left
@[deprecated (since := "2024-01-18")] alias append_right_cancel := append_cancel_right
#align list.append_right_cancel List.append_cancel_right
@[simp] theorem append_left_eq_self {x y : List α} : x ++ y = y ↔ x = [] := by
rw [← append_left_inj (s₁ := x), nil_append]
@[simp] theorem self_eq_append_left {x y : List α} : y = x ++ y ↔ x = [] := by
rw [eq_comm, append_left_eq_self]
@[simp] theorem append_right_eq_self {x y : List α} : x ++ y = x ↔ y = [] := by
rw [← append_right_inj (t₁ := y), append_nil]
@[simp] theorem self_eq_append_right {x y : List α} : x = x ++ y ↔ y = [] := by
rw [eq_comm, append_right_eq_self]
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
#align list.append_right_injective List.append_right_injective
#align list.append_right_inj List.append_right_inj
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
#align list.append_left_injective List.append_left_injective
#align list.append_left_inj List.append_left_inj
#align list.map_eq_append_split List.map_eq_append_split
/-! ### replicate -/
@[simp] lemma replicate_zero (a : α) : replicate 0 a = [] := rfl
#align list.replicate_zero List.replicate_zero
attribute [simp] replicate_succ
#align list.replicate_succ List.replicate_succ
lemma replicate_one (a : α) : replicate 1 a = [a] := rfl
#align list.replicate_one List.replicate_one
#align list.length_replicate List.length_replicate
#align list.mem_replicate List.mem_replicate
#align list.eq_of_mem_replicate List.eq_of_mem_replicate
theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a
| [] => by simp
| (b :: l) => by simp [eq_replicate_length]
#align list.eq_replicate_length List.eq_replicate_length
#align list.eq_replicate_of_mem List.eq_replicate_of_mem
#align list.eq_replicate List.eq_replicate
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
induction m <;> simp [*, succ_add, replicate]
#align list.replicate_add List.replicate_add
theorem replicate_succ' (n) (a : α) : replicate (n + 1) a = replicate n a ++ [a] :=
replicate_add n 1 a
#align list.replicate_succ' List.replicate_succ'
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
#align list.replicate_subset_singleton List.replicate_subset_singleton
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate, subset_def, mem_singleton, exists_eq_left']
#align list.subset_singleton_iff List.subset_singleton_iff
@[simp] theorem map_replicate (f : α → β) (n) (a : α) :
map f (replicate n a) = replicate n (f a) := by
induction n <;> [rfl; simp only [*, replicate, map]]
#align list.map_replicate List.map_replicate
@[simp] theorem tail_replicate (a : α) (n) :
tail (replicate n a) = replicate (n - 1) a := by cases n <;> rfl
#align list.tail_replicate List.tail_replicate
@[simp] theorem join_replicate_nil (n : ℕ) : join (replicate n []) = @nil α := by
induction n <;> [rfl; simp only [*, replicate, join, append_nil]]
#align list.join_replicate_nil List.join_replicate_nil
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
#align list.replicate_right_injective List.replicate_right_injective
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
#align list.replicate_right_inj List.replicate_right_inj
@[simp] theorem replicate_right_inj' {a b : α} : ∀ {n},
replicate n a = replicate n b ↔ n = 0 ∨ a = b
| 0 => by simp
| n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or]
#align list.replicate_right_inj' List.replicate_right_inj'
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate · a)
#align list.replicate_left_injective List.replicate_left_injective
@[simp] theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
#align list.replicate_left_inj List.replicate_left_inj
@[simp] theorem head_replicate (n : ℕ) (a : α) (h) : head (replicate n a) h = a := by
cases n <;> simp at h ⊢
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
#align list.mem_pure List.mem_pure
/-! ### bind -/
@[simp]
theorem bind_eq_bind {α β} (f : α → List β) (l : List α) : l >>= f = l.bind f :=
rfl
#align list.bind_eq_bind List.bind_eq_bind
#align list.bind_append List.append_bind
/-! ### concat -/
#align list.concat_nil List.concat_nil
#align list.concat_cons List.concat_cons
#align list.concat_eq_append List.concat_eq_append
#align list.init_eq_of_concat_eq List.init_eq_of_concat_eq
#align list.last_eq_of_concat_eq List.last_eq_of_concat_eq
#align list.concat_ne_nil List.concat_ne_nil
#align list.concat_append List.concat_append
#align list.length_concat List.length_concat
#align list.append_concat List.append_concat
/-! ### reverse -/
#align list.reverse_nil List.reverse_nil
#align list.reverse_core List.reverseAux
-- Porting note: Do we need this?
attribute [local simp] reverseAux
#align list.reverse_cons List.reverse_cons
#align list.reverse_core_eq List.reverseAux_eq
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
#align list.reverse_cons' List.reverse_cons'
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
#align list.reverse_singleton List.reverse_singleton
#align list.reverse_append List.reverse_append
#align list.reverse_concat List.reverse_concat
#align list.reverse_reverse List.reverse_reverse
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
#align list.reverse_involutive List.reverse_involutive
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
#align list.reverse_injective List.reverse_injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
#align list.reverse_surjective List.reverse_surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
#align list.reverse_bijective List.reverse_bijective
@[simp]
theorem reverse_inj {l₁ l₂ : List α} : reverse l₁ = reverse l₂ ↔ l₁ = l₂ :=
reverse_injective.eq_iff
#align list.reverse_inj List.reverse_inj
theorem reverse_eq_iff {l l' : List α} : l.reverse = l' ↔ l = l'.reverse :=
reverse_involutive.eq_iff
#align list.reverse_eq_iff List.reverse_eq_iff
#align list.reverse_eq_nil List.reverse_eq_nil_iff
theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by
simp only [concat_eq_append, reverse_cons, reverse_reverse]
#align list.concat_eq_reverse_cons List.concat_eq_reverse_cons
#align list.length_reverse List.length_reverse
-- Porting note: This one was @[simp] in mathlib 3,
-- but Lean contains a competing simp lemma reverse_map.
-- For now we remove @[simp] to avoid simplification loops.
-- TODO: Change Lean lemma to match mathlib 3?
theorem map_reverse (f : α → β) (l : List α) : map f (reverse l) = reverse (map f l) :=
(reverse_map f l).symm
#align list.map_reverse List.map_reverse
theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) :
map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by
simp only [reverseAux_eq, map_append, map_reverse]
#align list.map_reverse_core List.map_reverseAux
#align list.mem_reverse List.mem_reverse
@[simp] theorem reverse_replicate (n) (a : α) : reverse (replicate n a) = replicate n a :=
eq_replicate.2
⟨by rw [length_reverse, length_replicate],
fun b h => eq_of_mem_replicate (mem_reverse.1 h)⟩
#align list.reverse_replicate List.reverse_replicate
/-! ### empty -/
-- Porting note: this does not work as desired
-- attribute [simp] List.isEmpty
theorem isEmpty_iff_eq_nil {l : List α} : l.isEmpty ↔ l = [] := by cases l <;> simp [isEmpty]
#align list.empty_iff_eq_nil List.isEmpty_iff_eq_nil
/-! ### dropLast -/
#align list.length_init List.length_dropLast
/-! ### getLast -/
@[simp]
theorem getLast_cons {a : α} {l : List α} :
∀ h : l ≠ nil, getLast (a :: l) (cons_ne_nil a l) = getLast l h := by
induction l <;> intros
· contradiction
· rfl
#align list.last_cons List.getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_ne_nil_right l _ (cons_ne_nil a _)) = a := by
simp only [getLast_append]
#align list.last_append_singleton List.getLast_append_singleton
-- Porting note: name should be fixed upstream
theorem getLast_append' (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_ne_nil_right l₁ l₂ h) = getLast l₂ h := by
induction' l₁ with _ _ ih
· simp
· simp only [cons_append]
rw [List.getLast_cons]
exact ih
#align list.last_append List.getLast_append'
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (concat_ne_nil a l) = a :=
getLast_concat ..
#align list.last_concat List.getLast_concat'
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
#align list.last_singleton List.getLast_singleton'
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) :
getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) :=
rfl
#align list.last_cons_cons List.getLast_cons_cons
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [a], h => rfl
| a :: b :: l, h => by
rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)]
congr
exact dropLast_append_getLast (cons_ne_nil b l)
#align list.init_append_last List.dropLast_append_getLast
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
#align list.last_congr List.getLast_congr
#align list.last_mem List.getLast_mem
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_succ (length_replicate _ _)) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
#align list.last_replicate_succ List.getLast_replicate_succ
/-! ### getLast? -/
-- Porting note: Moved earlier in file, for use in subsequent lemmas.
@[simp]
theorem getLast?_cons_cons (a b : α) (l : List α) :
getLast? (a :: b :: l) = getLast? (b :: l) := rfl
@[simp]
theorem getLast?_isNone : ∀ {l : List α}, (getLast? l).isNone ↔ l = []
| [] => by simp
| [a] => by simp
| a :: b :: l => by simp [@getLast?_isNone (b :: l)]
#align list.last'_is_none List.getLast?_isNone
@[simp]
theorem getLast?_isSome : ∀ {l : List α}, l.getLast?.isSome ↔ l ≠ []
| [] => by simp
| [a] => by simp
| a :: b :: l => by simp [@getLast?_isSome (b :: l)]
#align list.last'_is_some List.getLast?_isSome
theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h
| [], x, hx => False.elim <| by simp at hx
| [a], x, hx =>
have : a = x := by simpa using hx
this ▸ ⟨cons_ne_nil a [], rfl⟩
| a :: b :: l, x, hx => by
rw [getLast?_cons_cons] at hx
rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩
use cons_ne_nil _ _
assumption
#align list.mem_last'_eq_last List.mem_getLast?_eq_getLast
theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
| [], h => (h rfl).elim
| [_], _ => rfl
| _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _)
#align list.last'_eq_last_of_ne_nil List.getLast?_eq_getLast_of_ne_nil
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
#align list.mem_last'_cons List.mem_getLast?_cons
theorem mem_of_mem_getLast? {l : List α} {a : α} (ha : a ∈ l.getLast?) : a ∈ l :=
let ⟨_, h₂⟩ := mem_getLast?_eq_getLast ha
h₂.symm ▸ getLast_mem _
#align list.mem_of_mem_last' List.mem_of_mem_getLast?
theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l
| [], a, ha => (Option.not_mem_none a ha).elim
| [a], _, rfl => rfl
| a :: b :: l, c, hc => by
rw [getLast?_cons_cons] at hc
rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc]
#align list.init_append_last' List.dropLast_append_getLast?
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [a] => rfl
| [a, b] => rfl
| [a, b, c] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
#align list.ilast_eq_last' List.getLastI_eq_getLast?
@[simp]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], a, l₂ => rfl
| [b], a, l₂ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
#align list.last'_append_cons List.getLast?_append_cons
#align list.last'_cons_cons List.getLast?_cons_cons
theorem getLast?_append_of_ne_nil (l₁ : List α) :
∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂
| [], hl₂ => by contradiction
| b :: l₂, _ => getLast?_append_cons l₁ b l₂
#align list.last'_append_of_ne_nil List.getLast?_append_of_ne_nil
theorem getLast?_append {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
#align list.last'_append List.getLast?_append
/-! ### head(!?) and tail -/
@[simp]
theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl
@[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by
cases x <;> simp at h ⊢
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
#align list.head_eq_head' List.head!_eq_head?
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
#align list.surjective_head List.surjective_head!
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
#align list.surjective_head' List.surjective_head?
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
#align list.surjective_tail List.surjective_tail
theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l
| [], h => (Option.not_mem_none _ h).elim
| a :: l, h => by
simp only [head?, Option.mem_def, Option.some_inj] at h
exact h ▸ rfl
#align list.eq_cons_of_mem_head' List.eq_cons_of_mem_head?
theorem mem_of_mem_head? {x : α} {l : List α} (h : x ∈ l.head?) : x ∈ l :=
(eq_cons_of_mem_head? h).symm ▸ mem_cons_self _ _
#align list.mem_of_mem_head' List.mem_of_mem_head?
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
#align list.head_cons List.head!_cons
#align list.tail_nil List.tail_nil
#align list.tail_cons List.tail_cons
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
#align list.head_append List.head!_append
theorem head?_append {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
#align list.head'_append List.head?_append
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
#align list.head'_append_of_ne_nil List.head?_append_of_ne_nil
theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] := by
induction l
· contradiction
· rw [tail, cons_append, tail]
#align list.tail_append_singleton_of_ne_nil List.tail_append_singleton_of_ne_nil
theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l
| [], a, h => by contradiction
| b :: l, a, h => by
simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h
simp [h]
#align list.cons_head'_tail List.cons_head?_tail
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| a :: l, _ => rfl
#align list.head_mem_head' List.head!_mem_head?
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
#align list.cons_head_tail List.cons_head!_tail
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' := mem_cons_self l.head! l.tail
rwa [cons_head!_tail h] at h'
#align list.head_mem_self List.head!_mem_self
theorem head_mem {l : List α} : ∀ (h : l ≠ nil), l.head h ∈ l := by
cases l <;> simp
@[simp]
theorem head?_map (f : α → β) (l) : head? (map f l) = (head? l).map f := by cases l <;> rfl
#align list.head'_map List.head?_map
theorem tail_append_of_ne_nil (l l' : List α) (h : l ≠ []) : (l ++ l').tail = l.tail ++ l' := by
cases l
· contradiction
· simp
#align list.tail_append_of_ne_nil List.tail_append_of_ne_nil
#align list.nth_le_eq_iff List.get_eq_iff
theorem get_eq_get? (l : List α) (i : Fin l.length) :
l.get i = (l.get? i).get (by simp [get?_eq_get]) := by
simp [get_eq_iff]
#align list.some_nth_le_eq List.get?_eq_get
section deprecated
set_option linter.deprecated false -- TODO(Mario): make replacements for theorems in this section
/-- nth element of a list `l` given `n < l.length`. -/
@[deprecated get (since := "2023-01-05")]
def nthLe (l : List α) (n) (h : n < l.length) : α := get l ⟨n, h⟩
#align list.nth_le List.nthLe
@[simp] theorem nthLe_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.nthLe i h = l.nthLe (i + 1) h' := by
cases l <;> [cases h; rfl]
#align list.nth_le_tail List.nthLe_tail
theorem nthLe_cons_aux {l : List α} {a : α} {n} (hn : n ≠ 0) (h : n < (a :: l).length) :
n - 1 < l.length := by
contrapose! h
rw [length_cons]
omega
#align list.nth_le_cons_aux List.nthLe_cons_aux
theorem nthLe_cons {l : List α} {a : α} {n} (hl) :
(a :: l).nthLe n hl = if hn : n = 0 then a else l.nthLe (n - 1) (nthLe_cons_aux hn hl) := by
split_ifs with h
· simp [nthLe, h]
cases l
· rw [length_singleton, Nat.lt_succ_iff] at hl
omega
cases n
· contradiction
rfl
#align list.nth_le_cons List.nthLe_cons
end deprecated
-- Porting note: List.modifyHead has @[simp], and Lean 4 treats this as
-- an invitation to unfold modifyHead in any context,
-- not just use the equational lemmas.
-- @[simp]
@[simp 1100, nolint simpNF]
theorem modifyHead_modifyHead (l : List α) (f g : α → α) :
(l.modifyHead f).modifyHead g = l.modifyHead (g ∘ f) := by cases l <;> simp
#align list.modify_head_modify_head List.modifyHead_modifyHead
/-! ### Induction from the right -/
/-- Induction principle from the right for lists: if a property holds for the empty list, and
for `l ++ [a]` if it holds for `l`, then it holds for all lists. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
@[elab_as_elim]
def reverseRecOn {motive : List α → Sort*} (l : List α) (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) : motive l :=
match h : reverse l with
| [] => cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <|
nil
| head :: tail =>
cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <|
append_singleton _ head <| reverseRecOn (reverse tail) nil append_singleton
termination_by l.length
decreasing_by
simp_wf
rw [← length_reverse l, h, length_cons]
simp [Nat.lt_succ]
#align list.reverse_rec_on List.reverseRecOn
@[simp]
theorem reverseRecOn_nil {motive : List α → Sort*} (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) :
reverseRecOn [] nil append_singleton = nil := reverseRecOn.eq_1 ..
-- `unusedHavesSuffices` is getting confused by the unfolding of `reverseRecOn`
@[simp, nolint unusedHavesSuffices]
theorem reverseRecOn_concat {motive : List α → Sort*} (x : α) (xs : List α) (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) :
reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton =
append_singleton _ _ (reverseRecOn (motive := motive) xs nil append_singleton) := by
suffices ∀ ys (h : reverse (reverse xs) = ys),
reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton =
cast (by simp [(reverse_reverse _).symm.trans h])
(append_singleton _ x (reverseRecOn (motive := motive) ys nil append_singleton)) by
exact this _ (reverse_reverse xs)
intros ys hy
conv_lhs => unfold reverseRecOn
split
next h => simp at h
next heq =>
revert heq
simp only [reverse_append, reverse_cons, reverse_nil, nil_append, singleton_append, cons.injEq]
rintro ⟨rfl, rfl⟩
subst ys
rfl
/-- Bidirectional induction principle for lists: if a property holds for the empty list, the
singleton list, and `a :: (l ++ [b])` from `l`, then it holds for all lists. This can be used to
prove statements about palindromes. The principle is given for a `Sort`-valued predicate, i.e., it
can also be used to construct data. -/
@[elab_as_elim]
def bidirectionalRec {motive : List α → Sort*} (nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) :
∀ l, motive l
| [] => nil
| [a] => singleton a
| a :: b :: l =>
let l' := dropLast (b :: l)
let b' := getLast (b :: l) (cons_ne_nil _ _)
cast (by rw [← dropLast_append_getLast (cons_ne_nil b l)]) <|
cons_append a l' b' (bidirectionalRec nil singleton cons_append l')
termination_by l => l.length
#align list.bidirectional_rec List.bidirectionalRecₓ -- universe order
@[simp]
theorem bidirectionalRec_nil {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) :
bidirectionalRec nil singleton cons_append [] = nil := bidirectionalRec.eq_1 ..
@[simp]
theorem bidirectionalRec_singleton {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) (a : α):
bidirectionalRec nil singleton cons_append [a] = singleton a := by
simp [bidirectionalRec]
@[simp]
theorem bidirectionalRec_cons_append {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b])))
(a : α) (l : List α) (b : α) :
bidirectionalRec nil singleton cons_append (a :: (l ++ [b])) =
cons_append a l b (bidirectionalRec nil singleton cons_append l) := by
conv_lhs => unfold bidirectionalRec
cases l with
| nil => rfl
| cons x xs =>
simp only [List.cons_append]
dsimp only [← List.cons_append]
suffices ∀ (ys init : List α) (hinit : init = ys) (last : α) (hlast : last = b),
(cons_append a init last
(bidirectionalRec nil singleton cons_append init)) =
cast (congr_arg motive <| by simp [hinit, hlast])
(cons_append a ys b (bidirectionalRec nil singleton cons_append ys)) by
rw [this (x :: xs) _ (by rw [dropLast_append_cons, dropLast_single, append_nil]) _ (by simp)]
simp
rintro ys init rfl last rfl
rfl
/-- Like `bidirectionalRec`, but with the list parameter placed first. -/
@[elab_as_elim]
abbrev bidirectionalRecOn {C : List α → Sort*} (l : List α) (H0 : C []) (H1 : ∀ a : α, C [a])
(Hn : ∀ (a : α) (l : List α) (b : α), C l → C (a :: (l ++ [b]))) : C l :=
bidirectionalRec H0 H1 Hn l
#align list.bidirectional_rec_on List.bidirectionalRecOn
/-! ### sublists -/
attribute [refl] List.Sublist.refl
#align list.nil_sublist List.nil_sublist
#align list.sublist.refl List.Sublist.refl
#align list.sublist.trans List.Sublist.trans
#align list.sublist_cons List.sublist_cons
#align list.sublist_of_cons_sublist List.sublist_of_cons_sublist
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
#align list.sublist.cons_cons List.Sublist.cons_cons
#align list.sublist_append_left List.sublist_append_left
#align list.sublist_append_right List.sublist_append_right
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
#align list.sublist_cons_of_sublist List.sublist_cons_of_sublist
#align list.sublist_append_of_sublist_left List.sublist_append_of_sublist_left
#align list.sublist_append_of_sublist_right List.sublist_append_of_sublist_right
theorem tail_sublist : ∀ l : List α, tail l <+ l
| [] => .slnil
| a::l => sublist_cons a l
#align list.tail_sublist List.tail_sublist
@[gcongr] protected theorem Sublist.tail : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → tail l₁ <+ tail l₂
| _, _, slnil => .slnil
| _, _, Sublist.cons _ h => (tail_sublist _).trans h
| _, _, Sublist.cons₂ _ h => h
theorem Sublist.of_cons_cons {l₁ l₂ : List α} {a b : α} (h : a :: l₁ <+ b :: l₂) : l₁ <+ l₂ :=
h.tail
#align list.sublist_of_cons_sublist_cons List.Sublist.of_cons_cons
@[deprecated (since := "2024-04-07")]
theorem sublist_of_cons_sublist_cons {a} (h : a :: l₁ <+ a :: l₂) : l₁ <+ l₂ := h.of_cons_cons
attribute [simp] cons_sublist_cons
@[deprecated (since := "2024-04-07")] alias cons_sublist_cons_iff := cons_sublist_cons
#align list.cons_sublist_cons_iff List.cons_sublist_cons_iff
#align list.append_sublist_append_left List.append_sublist_append_left
#align list.sublist.append_right List.Sublist.append_right
#align list.sublist_or_mem_of_sublist List.sublist_or_mem_of_sublist
#align list.sublist.reverse List.Sublist.reverse
#align list.reverse_sublist_iff List.reverse_sublist
#align list.append_sublist_append_right List.append_sublist_append_right
#align list.sublist.append List.Sublist.append
#align list.sublist.subset List.Sublist.subset
#align list.singleton_sublist List.singleton_sublist
theorem eq_nil_of_sublist_nil {l : List α} (s : l <+ []) : l = [] :=
eq_nil_of_subset_nil <| s.subset
#align list.eq_nil_of_sublist_nil List.eq_nil_of_sublist_nil
-- Porting note: this lemma seems to have been renamed on the occasion of its move to Batteries
alias sublist_nil_iff_eq_nil := sublist_nil
#align list.sublist_nil_iff_eq_nil List.sublist_nil_iff_eq_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
#align list.replicate_sublist_replicate List.replicate_sublist_replicate
theorem sublist_replicate_iff {l : List α} {a : α} {n : ℕ} :
l <+ replicate n a ↔ ∃ k ≤ n, l = replicate k a :=
⟨fun h =>
⟨l.length, h.length_le.trans_eq (length_replicate _ _),
eq_replicate_length.mpr fun b hb => eq_of_mem_replicate (h.subset hb)⟩,
by rintro ⟨k, h, rfl⟩; exact (replicate_sublist_replicate _).mpr h⟩
#align list.sublist_replicate_iff List.sublist_replicate_iff
#align list.sublist.eq_of_length List.Sublist.eq_of_length
#align list.sublist.eq_of_length_le List.Sublist.eq_of_length_le
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
#align list.sublist.antisymm List.Sublist.antisymm
instance decidableSublist [DecidableEq α] : ∀ l₁ l₂ : List α, Decidable (l₁ <+ l₂)
| [], _ => isTrue <| nil_sublist _
| _ :: _, [] => isFalse fun h => List.noConfusion <| eq_nil_of_sublist_nil h
| a :: l₁, b :: l₂ =>
if h : a = b then
@decidable_of_decidable_of_iff _ _ (decidableSublist l₁ l₂) <| h ▸ cons_sublist_cons.symm
else
@decidable_of_decidable_of_iff _ _ (decidableSublist (a :: l₁) l₂)
⟨sublist_cons_of_sublist _, fun s =>
match a, l₁, s, h with
| _, _, Sublist.cons _ s', h => s'
| _, _, Sublist.cons₂ t _, h => absurd rfl h⟩
#align list.decidable_sublist List.decidableSublist
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
#align list.index_of_nil List.indexOf_nil
/-
Porting note: The following proofs were simpler prior to the port. These proofs use the low-level
`findIdx.go`.
* `indexOf_cons_self`
* `indexOf_cons_eq`
* `indexOf_cons_ne`
* `indexOf_cons`
The ported versions of the earlier proofs are given in comments.
-/
-- indexOf_cons_eq _ rfl
@[simp]
theorem indexOf_cons_self (a : α) (l : List α) : indexOf a (a :: l) = 0 := by
rw [indexOf, findIdx_cons, beq_self_eq_true, cond]
#align list.index_of_cons_self List.indexOf_cons_self
-- fun e => if_pos e
theorem indexOf_cons_eq {a b : α} (l : List α) : b = a → indexOf a (b :: l) = 0
| e => by rw [← e]; exact indexOf_cons_self b l
#align list.index_of_cons_eq List.indexOf_cons_eq
-- fun n => if_neg n
@[simp]
theorem indexOf_cons_ne {a b : α} (l : List α) : b ≠ a → indexOf a (b :: l) = succ (indexOf a l)
| h => by simp only [indexOf, findIdx_cons, Bool.cond_eq_ite, beq_iff_eq, h, ite_false]
#align list.index_of_cons_ne List.indexOf_cons_ne
#align list.index_of_cons List.indexOf_cons
theorem indexOf_eq_length {a : α} {l : List α} : indexOf a l = length l ↔ a ∉ l := by
induction' l with b l ih
· exact iff_of_true rfl (not_mem_nil _)
simp only [length, mem_cons, indexOf_cons, eq_comm]
rw [cond_eq_if]
split_ifs with h <;> simp at h
· exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm
· simp only [Ne.symm h, false_or_iff]
rw [← ih]
exact succ_inj'
#align list.index_of_eq_length List.indexOf_eq_length
@[simp]
theorem indexOf_of_not_mem {l : List α} {a : α} : a ∉ l → indexOf a l = length l :=
indexOf_eq_length.2
#align list.index_of_of_not_mem List.indexOf_of_not_mem
theorem indexOf_le_length {a : α} {l : List α} : indexOf a l ≤ length l := by
induction' l with b l ih; · rfl
simp only [length, indexOf_cons, cond_eq_if, beq_iff_eq]
by_cases h : b = a
· rw [if_pos h]; exact Nat.zero_le _
· rw [if_neg h]; exact succ_le_succ ih
#align list.index_of_le_length List.indexOf_le_length
theorem indexOf_lt_length {a} {l : List α} : indexOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.by_contradiction fun al => Nat.ne_of_lt h <| indexOf_eq_length.2 al,
fun al => (lt_of_le_of_ne indexOf_le_length) fun h => indexOf_eq_length.1 h al⟩
#align list.index_of_lt_length List.indexOf_lt_length
theorem indexOf_append_of_mem {a : α} (h : a ∈ l₁) : indexOf a (l₁ ++ l₂) = indexOf a l₁ := by
induction' l₁ with d₁ t₁ ih
· exfalso
exact not_mem_nil a h
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [indexOf_cons_eq _ hh]
rw [indexOf_cons_ne _ hh, indexOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
#align list.index_of_append_of_mem List.indexOf_append_of_mem
theorem indexOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
indexOf a (l₁ ++ l₂) = l₁.length + indexOf a l₂ := by
induction' l₁ with d₁ t₁ ih
· rw [List.nil_append, List.length, Nat.zero_add]
rw [List.cons_append, indexOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
#align list.index_of_append_of_not_mem List.indexOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
set_option linter.deprecated false
@[deprecated get_of_mem (since := "2023-01-05")]
theorem nthLe_of_mem {a} {l : List α} (h : a ∈ l) : ∃ n h, nthLe l n h = a :=
let ⟨i, h⟩ := get_of_mem h; ⟨i.1, i.2, h⟩
#align list.nth_le_of_mem List.nthLe_of_mem
@[deprecated get?_eq_get (since := "2023-01-05")]
theorem nthLe_get? {l : List α} {n} (h) : get? l n = some (nthLe l n h) := get?_eq_get _
#align list.nth_le_nth List.nthLe_get?
#align list.nth_len_le List.get?_len_le
@[simp]
theorem get?_length (l : List α) : l.get? l.length = none := get?_len_le le_rfl
#align list.nth_length List.get?_length
#align list.nth_eq_some List.get?_eq_some
#align list.nth_eq_none_iff List.get?_eq_none
#align list.nth_of_mem List.get?_of_mem
@[deprecated get_mem (since := "2023-01-05")]
theorem nthLe_mem (l : List α) (n h) : nthLe l n h ∈ l := get_mem ..
#align list.nth_le_mem List.nthLe_mem
#align list.nth_mem List.get?_mem
@[deprecated mem_iff_get (since := "2023-01-05")]
theorem mem_iff_nthLe {a} {l : List α} : a ∈ l ↔ ∃ n h, nthLe l n h = a :=
mem_iff_get.trans ⟨fun ⟨⟨n, h⟩, e⟩ => ⟨n, h, e⟩, fun ⟨n, h, e⟩ => ⟨⟨n, h⟩, e⟩⟩
#align list.mem_iff_nth_le List.mem_iff_nthLe
#align list.mem_iff_nth List.mem_iff_get?
#align list.nth_zero List.get?_zero
@[deprecated (since := "2024-05-03")] alias get?_injective := get?_inj
#align list.nth_injective List.get?_inj
#align list.nth_map List.get?_map
@[deprecated get_map (since := "2023-01-05")]
theorem nthLe_map (f : α → β) {l n} (H1 H2) : nthLe (map f l) n H1 = f (nthLe l n H2) := get_map ..
#align list.nth_le_map List.nthLe_map
/-- A version of `get_map` that can be used for rewriting. -/
theorem get_map_rev (f : α → β) {l n} :
f (get l n) = get (map f l) ⟨n.1, (l.length_map f).symm ▸ n.2⟩ := Eq.symm (get_map _)
/-- A version of `nthLe_map` that can be used for rewriting. -/
@[deprecated get_map_rev (since := "2023-01-05")]
theorem nthLe_map_rev (f : α → β) {l n} (H) :
f (nthLe l n H) = nthLe (map f l) n ((l.length_map f).symm ▸ H) :=
(nthLe_map f _ _).symm
#align list.nth_le_map_rev List.nthLe_map_rev
@[simp, deprecated get_map (since := "2023-01-05")]
theorem nthLe_map' (f : α → β) {l n} (H) :
nthLe (map f l) n H = f (nthLe l n (l.length_map f ▸ H)) := nthLe_map f _ _
#align list.nth_le_map' List.nthLe_map'
#align list.nth_le_of_eq List.get_of_eq
@[simp, deprecated get_singleton (since := "2023-01-05")]
theorem nthLe_singleton (a : α) {n : ℕ} (hn : n < 1) : nthLe [a] n hn = a := get_singleton ..
#align list.nth_le_singleton List.get_singleton
#align list.nth_le_zero List.get_mk_zero
#align list.nth_le_append List.get_append
@[deprecated get_append_right' (since := "2023-01-05")]
theorem nthLe_append_right {l₁ l₂ : List α} {n : ℕ} (h₁ : l₁.length ≤ n) (h₂) :
(l₁ ++ l₂).nthLe n h₂ = l₂.nthLe (n - l₁.length) (get_append_right_aux h₁ h₂) :=
get_append_right' h₁ h₂
#align list.nth_le_append_right_aux List.get_append_right_aux
#align list.nth_le_append_right List.nthLe_append_right
#align list.nth_le_replicate List.get_replicate
#align list.nth_append List.get?_append
#align list.nth_append_right List.get?_append_right
#align list.last_eq_nth_le List.getLast_eq_get
theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) :
l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) :=
(getLast_eq_get l _).symm
#align list.nth_le_length_sub_one List.get_length_sub_one
#align list.nth_concat_length List.get?_concat_length
@[deprecated get_cons_length (since := "2023-01-05")]
theorem nthLe_cons_length : ∀ (x : α) (xs : List α) (n : ℕ) (h : n = xs.length),
(x :: xs).nthLe n (by simp [h]) = (x :: xs).getLast (cons_ne_nil x xs) := get_cons_length
#align list.nth_le_cons_length List.nthLe_cons_length
theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) :
(l.drop n).take 1 = [l.get ⟨n, h⟩] := by
rw [drop_eq_get_cons h, take, take]
#align list.take_one_drop_eq_of_lt_length List.take_one_drop_eq_of_lt_length
#align list.ext List.ext
-- TODO one may rename ext in the standard library, and it is also not clear
-- which of ext_get?, ext_get?', ext_get should be @[ext], if any
alias ext_get? := ext
theorem ext_get?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n) :
l₁ = l₂ := by
apply ext
intro n
rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn
· exact h' n hn
· simp_all [Nat.max_le, get?_eq_none.mpr]
theorem ext_get?_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n, l₁.get? n = l₂.get? n :=
⟨by rintro rfl _; rfl, ext_get?⟩
theorem ext_get_iff {l₁ l₂ : List α} :
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by
constructor
· rintro rfl
exact ⟨rfl, fun _ _ _ ↦ rfl⟩
· intro ⟨h₁, h₂⟩
exact ext_get h₁ h₂
theorem ext_get?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n :=
⟨by rintro rfl _ _; rfl, ext_get?'⟩
@[deprecated ext_get (since := "2023-01-05")]
theorem ext_nthLe {l₁ l₂ : List α} (hl : length l₁ = length l₂)
(h : ∀ n h₁ h₂, nthLe l₁ n h₁ = nthLe l₂ n h₂) : l₁ = l₂ :=
ext_get hl h
#align list.ext_le List.ext_nthLe
@[simp]
theorem indexOf_get [DecidableEq α] {a : α} : ∀ {l : List α} (h), get l ⟨indexOf a l, h⟩ = a
| b :: l, h => by
by_cases h' : b = a <;>
simp only [h', if_pos, if_false, indexOf_cons, get, @indexOf_get _ _ l, cond_eq_if, beq_iff_eq]
#align list.index_of_nth_le List.indexOf_get
@[simp]
theorem indexOf_get? [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
get? l (indexOf a l) = some a := by rw [get?_eq_get, indexOf_get (indexOf_lt_length.2 h)]
#align list.index_of_nth List.indexOf_get?
@[deprecated (since := "2023-01-05")]
theorem get_reverse_aux₁ :
∀ (l r : List α) (i h1 h2), get (reverseAux l r) ⟨i + length l, h1⟩ = get r ⟨i, h2⟩
| [], r, i => fun h1 _ => rfl
| a :: l, r, i => by
rw [show i + length (a :: l) = i + 1 + length l from Nat.add_right_comm i (length l) 1]
exact fun h1 h2 => get_reverse_aux₁ l (a :: r) (i + 1) h1 (succ_lt_succ h2)
#align list.nth_le_reverse_aux1 List.get_reverse_aux₁
theorem indexOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
indexOf x l = indexOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨indexOf x l, indexOf_lt_length.2 hx⟩ =
get l ⟨indexOf y l, indexOf_lt_length.2 hy⟩ := by
simp only [h]
simp only [indexOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
#align list.index_of_inj List.indexOf_inj
theorem get_reverse_aux₂ :
∀ (l r : List α) (i : Nat) (h1) (h2),
get (reverseAux l r) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩
| [], r, i, h1, h2 => absurd h2 (Nat.not_lt_zero _)
| a :: l, r, 0, h1, _ => by
have aux := get_reverse_aux₁ l (a :: r) 0
rw [Nat.zero_add] at aux
exact aux _ (zero_lt_succ _)
| a :: l, r, i + 1, h1, h2 => by
have aux := get_reverse_aux₂ l (a :: r) i
have heq : length (a :: l) - 1 - (i + 1) = length l - 1 - i := by rw [length]; omega
rw [← heq] at aux
apply aux
#align list.nth_le_reverse_aux2 List.get_reverse_aux₂
@[simp] theorem get_reverse (l : List α) (i : Nat) (h1 h2) :
get (reverse l) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩ :=
get_reverse_aux₂ _ _ _ _ _
@[simp, deprecated get_reverse (since := "2023-01-05")]
theorem nthLe_reverse (l : List α) (i : Nat) (h1 h2) :
nthLe (reverse l) (length l - 1 - i) h1 = nthLe l i h2 :=
get_reverse ..
#align list.nth_le_reverse List.nthLe_reverse
theorem nthLe_reverse' (l : List α) (n : ℕ) (hn : n < l.reverse.length) (hn') :
l.reverse.nthLe n hn = l.nthLe (l.length - 1 - n) hn' := by
rw [eq_comm]
convert nthLe_reverse l.reverse n (by simpa) hn using 1
simp
#align list.nth_le_reverse' List.nthLe_reverse'
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := nthLe_reverse' ..
-- FIXME: prove it the other way around
attribute [deprecated get_reverse' (since := "2023-01-05")] nthLe_reverse'
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) :
l = [l.nthLe 0 (by omega)] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp only [get_singleton]
congr
omega
#align list.eq_cons_of_length_one List.eq_cons_of_length_one
end deprecated
theorem modifyNthTail_modifyNthTail {f g : List α → List α} (m : ℕ) :
∀ (n) (l : List α),
(l.modifyNthTail f n).modifyNthTail g (m + n) =
l.modifyNthTail (fun l => (f l).modifyNthTail g m) n
| 0, _ => rfl
| _ + 1, [] => rfl
| n + 1, a :: l => congr_arg (List.cons a) (modifyNthTail_modifyNthTail m n l)
#align list.modify_nth_tail_modify_nth_tail List.modifyNthTail_modifyNthTail
theorem modifyNthTail_modifyNthTail_le {f g : List α → List α} (m n : ℕ) (l : List α)
(h : n ≤ m) :
(l.modifyNthTail f n).modifyNthTail g m =
l.modifyNthTail (fun l => (f l).modifyNthTail g (m - n)) n := by
rcases Nat.exists_eq_add_of_le h with ⟨m, rfl⟩
rw [Nat.add_comm, modifyNthTail_modifyNthTail, Nat.add_sub_cancel]
#align list.modify_nth_tail_modify_nth_tail_le List.modifyNthTail_modifyNthTail_le
theorem modifyNthTail_modifyNthTail_same {f g : List α → List α} (n : ℕ) (l : List α) :
(l.modifyNthTail f n).modifyNthTail g n = l.modifyNthTail (g ∘ f) n := by
rw [modifyNthTail_modifyNthTail_le n n l (le_refl n), Nat.sub_self]; rfl
#align list.modify_nth_tail_modify_nth_tail_same List.modifyNthTail_modifyNthTail_same
#align list.modify_nth_tail_id List.modifyNthTail_id
#align list.remove_nth_eq_nth_tail List.eraseIdx_eq_modifyNthTail
#align list.update_nth_eq_modify_nth List.set_eq_modifyNth
@[deprecated (since := "2024-05-04")] alias removeNth_eq_nthTail := eraseIdx_eq_modifyNthTail
theorem modifyNth_eq_set (f : α → α) :
∀ (n) (l : List α), modifyNth f n l = ((fun a => set l n (f a)) <$> get? l n).getD l
| 0, l => by cases l <;> rfl
| n + 1, [] => rfl
| n + 1, b :: l =>
(congr_arg (cons b) (modifyNth_eq_set f n l)).trans <| by cases h : get? l n <;> simp [h]
#align list.modify_nth_eq_update_nth List.modifyNth_eq_set
#align list.nth_modify_nth List.get?_modifyNth
theorem length_modifyNthTail (f : List α → List α) (H : ∀ l, length (f l) = length l) :
∀ n l, length (modifyNthTail f n l) = length l
| 0, _ => H _
| _ + 1, [] => rfl
| _ + 1, _ :: _ => @congr_arg _ _ _ _ (· + 1) (length_modifyNthTail _ H _ _)
#align list.modify_nth_tail_length List.length_modifyNthTail
-- Porting note: Duplicate of `modify_get?_length`
-- (but with a substantially better name?)
-- @[simp]
theorem length_modifyNth (f : α → α) : ∀ n l, length (modifyNth f n l) = length l :=
modify_get?_length f
#align list.modify_nth_length List.length_modifyNth
#align list.update_nth_length List.length_set
#align list.nth_modify_nth_eq List.get?_modifyNth_eq
#align list.nth_modify_nth_ne List.get?_modifyNth_ne
#align list.nth_update_nth_eq List.get?_set_eq
#align list.nth_update_nth_of_lt List.get?_set_eq_of_lt
#align list.nth_update_nth_ne List.get?_set_ne
#align list.update_nth_nil List.set_nil
#align list.update_nth_succ List.set_succ
#align list.update_nth_comm List.set_comm
#align list.nth_le_update_nth_eq List.get_set_eq
@[simp]
theorem get_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a).get ⟨j, hj⟩ = l.get ⟨j, by simpa using hj⟩ := by
rw [← Option.some_inj, ← List.get?_eq_get, List.get?_set_ne _ _ h, List.get?_eq_get]
#align list.nth_le_update_nth_of_ne List.get_set_of_ne
#align list.mem_or_eq_of_mem_update_nth List.mem_or_eq_of_mem_set
/-! ### map -/
#align list.map_nil List.map_nil
theorem map_eq_foldr (f : α → β) (l : List α) : map f l = foldr (fun a bs => f a :: bs) [] l := by
induction l <;> simp [*]
#align list.map_eq_foldr List.map_eq_foldr
theorem map_congr {f g : α → β} : ∀ {l : List α}, (∀ x ∈ l, f x = g x) → map f l = map g l
| [], _ => rfl
| a :: l, h => by
let ⟨h₁, h₂⟩ := forall_mem_cons.1 h
rw [map, map, h₁, map_congr h₂]
#align list.map_congr List.map_congr
theorem map_eq_map_iff {f g : α → β} {l : List α} : map f l = map g l ↔ ∀ x ∈ l, f x = g x := by
refine ⟨?_, map_congr⟩; intro h x hx
rw [mem_iff_get] at hx; rcases hx with ⟨n, hn, rfl⟩
rw [get_map_rev f, get_map_rev g]
congr!
#align list.map_eq_map_iff List.map_eq_map_iff
theorem map_concat (f : α → β) (a : α) (l : List α) :
map f (concat l a) = concat (map f l) (f a) := by
induction l <;> [rfl; simp only [*, concat_eq_append, cons_append, map, map_append]]
#align list.map_concat List.map_concat
#align list.map_id'' List.map_id'
theorem map_id'' {f : α → α} (h : ∀ x, f x = x) (l : List α) : map f l = l := by
simp [show f = id from funext h]
#align list.map_id' List.map_id''
theorem eq_nil_of_map_eq_nil {f : α → β} {l : List α} (h : map f l = nil) : l = nil :=
eq_nil_of_length_eq_zero <| by rw [← length_map l f, h]; rfl
#align list.eq_nil_of_map_eq_nil List.eq_nil_of_map_eq_nil
@[simp]
theorem map_join (f : α → β) (L : List (List α)) : map f (join L) = join (map (map f) L) := by
induction L <;> [rfl; simp only [*, join, map, map_append]]
#align list.map_join List.map_join
theorem bind_pure_eq_map (f : α → β) (l : List α) : l.bind (pure ∘ f) = map f l :=
.symm <| map_eq_bind ..
#align list.bind_ret_eq_map List.bind_pure_eq_map
set_option linter.deprecated false in
@[deprecated bind_pure_eq_map (since := "2024-03-24")]
theorem bind_ret_eq_map (f : α → β) (l : List α) : l.bind (List.ret ∘ f) = map f l :=
bind_pure_eq_map f l
theorem bind_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
List.bind l f = List.bind l g :=
(congr_arg List.join <| map_congr h : _)
#align list.bind_congr List.bind_congr
theorem infix_bind_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.bind f :=
List.infix_of_mem_join (List.mem_map_of_mem f h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
#align list.map_eq_map List.map_eq_map
@[simp]
theorem map_tail (f : α → β) (l) : map f (tail l) = tail (map f l) := by cases l <;> rfl
#align list.map_tail List.map_tail
/-- A single `List.map` of a composition of functions is equal to
composing a `List.map` with another `List.map`, fully applied.
This is the reverse direction of `List.map_map`.
-/
theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) :=
(map_map _ _ _).symm
#align list.comp_map List.comp_map
/-- Composing a `List.map` with another `List.map` is equal to
a single `List.map` of composed functions.
-/
@[simp]
theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by
ext l; rw [comp_map, Function.comp_apply]
#align list.map_comp_map List.map_comp_map
section map_bijectivity
theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) :
LeftInverse (map f) (map g)
| [] => by simp_rw [map_nil]
| x :: xs => by simp_rw [map_cons, h x, h.list_map xs]
nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α}
(h : RightInverse f g) : RightInverse (map f) (map g) :=
h.list_map
nonrec theorem _root_.Function.Involutive.list_map {f : α → α}
(h : Involutive f) : Involutive (map f) :=
Function.LeftInverse.list_map h
@[simp]
theorem map_leftInverse_iff {f : α → β} {g : β → α} :
LeftInverse (map f) (map g) ↔ LeftInverse f g :=
⟨fun h x => by injection h [x], (·.list_map)⟩
@[simp]
theorem map_rightInverse_iff {f : α → β} {g : β → α} :
RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff
@[simp]
theorem map_involutive_iff {f : α → α} :
Involutive (map f) ↔ Involutive f := map_leftInverse_iff
theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) :
Injective (map f)
| [], [], _ => rfl
| x :: xs, y :: ys, hxy => by
injection hxy with hxy hxys
rw [h hxy, h.list_map hxys]
@[simp]
theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by
refine ⟨fun h x y hxy => ?_, (·.list_map)⟩
suffices [x] = [y] by simpa using this
apply h
simp [hxy]
#align list.map_injective_iff List.map_injective_iff
theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) :
Surjective (map f) :=
let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective
@[simp]
theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by
refine ⟨fun h x => ?_, (·.list_map)⟩
let ⟨[y], hxy⟩ := h [x]
exact ⟨_, List.singleton_injective hxy⟩
theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) :=
⟨h.1.list_map, h.2.list_map⟩
@[simp]
theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by
simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff]
end map_bijectivity
theorem map_filter_eq_foldr (f : α → β) (p : α → Bool) (as : List α) :
map f (filter p as) = foldr (fun a bs => bif p a then f a :: bs else bs) [] as := by
induction' as with head tail
· rfl
· simp only [foldr]
cases hp : p head <;> simp [filter, *]
#align list.map_filter_eq_foldr List.map_filter_eq_foldr
theorem getLast_map (f : α → β) {l : List α} (hl : l ≠ []) :
(l.map f).getLast (mt eq_nil_of_map_eq_nil hl) = f (l.getLast hl) := by
induction' l with l_hd l_tl l_ih
· apply (hl rfl).elim
· cases l_tl
· simp
· simpa using l_ih _
#align list.last_map List.getLast_map
theorem map_eq_replicate_iff {l : List α} {f : α → β} {b : β} :
l.map f = replicate l.length b ↔ ∀ x ∈ l, f x = b := by
simp [eq_replicate]
#align list.map_eq_replicate_iff List.map_eq_replicate_iff
@[simp] theorem map_const (l : List α) (b : β) : map (const α b) l = replicate l.length b :=
map_eq_replicate_iff.mpr fun _ _ => rfl
#align list.map_const List.map_const
@[simp] theorem map_const' (l : List α) (b : β) : map (fun _ => b) l = replicate l.length b :=
map_const l b
#align list.map_const' List.map_const'
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) :
b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h
#align list.eq_of_mem_map_const List.eq_of_mem_map_const
/-! ### zipWith -/
theorem nil_zipWith (f : α → β → γ) (l : List β) : zipWith f [] l = [] := by cases l <;> rfl
#align list.nil_map₂ List.nil_zipWith
theorem zipWith_nil (f : α → β → γ) (l : List α) : zipWith f l [] = [] := by cases l <;> rfl
#align list.map₂_nil List.zipWith_nil
@[simp]
theorem zipWith_flip (f : α → β → γ) : ∀ as bs, zipWith (flip f) bs as = zipWith f as bs
| [], [] => rfl
| [], b :: bs => rfl
| a :: as, [] => rfl
| a :: as, b :: bs => by
simp! [zipWith_flip]
rfl
#align list.map₂_flip List.zipWith_flip
/-! ### take, drop -/
#align list.take_zero List.take_zero
#align list.take_nil List.take_nil
theorem take_cons (n) (a : α) (l : List α) : take (succ n) (a :: l) = a :: take n l :=
rfl
#align list.take_cons List.take_cons
#align list.take_length List.take_length
#align list.take_all_of_le List.take_all_of_le
#align list.take_left List.take_left
#align list.take_left' List.take_left'
#align list.take_take List.take_take
#align list.take_replicate List.take_replicate
#align list.map_take List.map_take
#align list.take_append_eq_append_take List.take_append_eq_append_take
#align list.take_append_of_le_length List.take_append_of_le_length
#align list.take_append List.take_append
#align list.nth_le_take List.get_take
#align list.nth_le_take' List.get_take'
#align list.nth_take List.get?_take
#align list.nth_take_of_succ List.nth_take_of_succ
#align list.take_succ List.take_succ
#align list.take_eq_nil_iff List.take_eq_nil_iff
#align list.take_eq_take List.take_eq_take
#align list.take_add List.take_add
#align list.init_eq_take List.dropLast_eq_take
#align list.init_take List.dropLast_take
#align list.init_cons_of_ne_nil List.dropLast_cons_of_ne_nil
#align list.init_append_of_ne_nil List.dropLast_append_of_ne_nil
#align list.drop_eq_nil_of_le List.drop_eq_nil_of_le
#align list.drop_eq_nil_iff_le List.drop_eq_nil_iff_le
#align list.tail_drop List.tail_drop
@[simp]
theorem drop_tail (l : List α) (n : ℕ) : l.tail.drop n = l.drop (n + 1) := by
rw [drop_add, drop_one]
theorem cons_get_drop_succ {l : List α} {n} :
l.get n :: l.drop (n.1 + 1) = l.drop n.1 :=
(drop_eq_get_cons n.2).symm
#align list.cons_nth_le_drop_succ List.cons_get_drop_succ
#align list.drop_nil List.drop_nil
#align list.drop_one List.drop_one
#align list.drop_add List.drop_add
#align list.drop_left List.drop_left
#align list.drop_left' List.drop_left'
#align list.drop_eq_nth_le_cons List.drop_eq_get_consₓ -- nth_le vs get
#align list.drop_length List.drop_length
#align list.drop_length_cons List.drop_length_cons
#align list.drop_append_eq_append_drop List.drop_append_eq_append_drop
#align list.drop_append_of_le_length List.drop_append_of_le_length
#align list.drop_append List.drop_append
#align list.drop_sizeof_le List.drop_sizeOf_le
#align list.nth_le_drop List.get_drop
#align list.nth_le_drop' List.get_drop'
#align list.nth_drop List.get?_drop
#align list.drop_drop List.drop_drop
#align list.drop_take List.drop_take
#align list.map_drop List.map_drop
#align list.modify_nth_tail_eq_take_drop List.modifyNthTail_eq_take_drop
#align list.modify_nth_eq_take_drop List.modifyNth_eq_take_drop
#align list.modify_nth_eq_take_cons_drop List.modifyNth_eq_take_cons_drop
#align list.update_nth_eq_take_cons_drop List.set_eq_take_cons_drop
#align list.reverse_take List.reverse_take
#align list.update_nth_eq_nil List.set_eq_nil
section TakeI
variable [Inhabited α]
@[simp]
theorem takeI_length : ∀ n l, length (@takeI α _ n l) = n
| 0, _ => rfl
| _ + 1, _ => congr_arg succ (takeI_length _ _)
#align list.take'_length List.takeI_length
@[simp]
theorem takeI_nil : ∀ n, takeI n (@nil α) = replicate n default
| 0 => rfl
| _ + 1 => congr_arg (cons _) (takeI_nil _)
#align list.take'_nil List.takeI_nil
theorem takeI_eq_take : ∀ {n} {l : List α}, n ≤ length l → takeI n l = take n l
| 0, _, _ => rfl
| _ + 1, _ :: _, h => congr_arg (cons _) <| takeI_eq_take <| le_of_succ_le_succ h
#align list.take'_eq_take List.takeI_eq_take
@[simp]
theorem takeI_left (l₁ l₂ : List α) : takeI (length l₁) (l₁ ++ l₂) = l₁ :=
(takeI_eq_take (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _)
#align list.take'_left List.takeI_left
theorem takeI_left' {l₁ l₂ : List α} {n} (h : length l₁ = n) : takeI n (l₁ ++ l₂) = l₁ := by
rw [← h]; apply takeI_left
#align list.take'_left' List.takeI_left'
end TakeI
/- Porting note: in mathlib3 we just had `take` and `take'`. Now we have `take`, `takeI`, and
`takeD`. The following section replicates the theorems above but for `takeD`. -/
section TakeD
@[simp]
theorem takeD_length : ∀ n l a, length (@takeD α n l a) = n
| 0, _, _ => rfl
| _ + 1, _, _ => congr_arg succ (takeD_length _ _ _)
-- Porting note: `takeD_nil` is already in std
theorem takeD_eq_take : ∀ {n} {l : List α} a, n ≤ length l → takeD n l a = take n l
| 0, _, _, _ => rfl
| _ + 1, _ :: _, a, h => congr_arg (cons _) <| takeD_eq_take a <| le_of_succ_le_succ h
@[simp]
theorem takeD_left (l₁ l₂ : List α) (a : α) : takeD (length l₁) (l₁ ++ l₂) a = l₁ :=
(takeD_eq_take a (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _)
theorem takeD_left' {l₁ l₂ : List α} {n} {a} (h : length l₁ = n) : takeD n (l₁ ++ l₂) a = l₁ := by
rw [← h]; apply takeD_left
end TakeD
/-! ### foldl, foldr -/
theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l := by
induction l generalizing a with
| nil => rfl
| cons hd tl ih =>
unfold foldl
rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd (mem_cons_self _ _)]
#align list.foldl_ext List.foldl_ext
theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l := by
induction' l with hd tl ih; · rfl
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
#align list.foldr_ext List.foldr_ext
#align list.foldl_nil List.foldl_nil
#align list.foldl_cons List.foldl_cons
#align list.foldr_nil List.foldr_nil
#align list.foldr_cons List.foldr_cons
#align list.foldl_append List.foldl_append
#align list.foldr_append List.foldr_append
theorem foldl_concat
(f : β → α → β) (b : β) (x : α) (xs : List α) :
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by
simp only [List.foldl_append, List.foldl]
theorem foldr_concat
(f : α → β → β) (b : β) (x : α) (xs : List α) :
List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by
simp only [List.foldr_append, List.foldr]
theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a
| [] => rfl
| b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l]
#align list.foldl_fixed' List.foldl_fixed'
theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b
| [] => rfl
| a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a]
#align list.foldr_fixed' List.foldr_fixed'
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
#align list.foldl_fixed List.foldl_fixed
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
#align list.foldr_fixed List.foldr_fixed
@[simp]
theorem foldl_join (f : α → β → α) :
∀ (a : α) (L : List (List β)), foldl f a (join L) = foldl (foldl f) a L
| a, [] => rfl
| a, l :: L => by simp only [join, foldl_append, foldl_cons, foldl_join f (foldl f a l) L]
#align list.foldl_join List.foldl_join
@[simp]
theorem foldr_join (f : α → β → β) :
∀ (b : β) (L : List (List α)), foldr f b (join L) = foldr (fun l b => foldr f b l) b L
| a, [] => rfl
| a, l :: L => by simp only [join, foldr_append, foldr_join f a L, foldr_cons]
#align list.foldr_join List.foldr_join
#align list.foldl_reverse List.foldl_reverse
#align list.foldr_reverse List.foldr_reverse
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem foldr_eta : ∀ l : List α, foldr cons [] l = l := by
simp only [foldr_self_append, append_nil, forall_const]
#align list.foldr_eta List.foldr_eta
@[simp]
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
rw [← foldr_reverse]; simp only [foldr_self_append, append_nil, reverse_reverse]
#align list.reverse_foldl List.reverse_foldl
#align list.foldl_map List.foldl_map
#align list.foldr_map List.foldr_map
theorem foldl_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α)
(h : ∀ x y, f' (g x) (g y) = g (f x y)) :
List.foldl f' (g a) (l.map g) = g (List.foldl f a l) := by
induction l generalizing a
· simp
· simp [*, h]
#align list.foldl_map' List.foldl_map'
theorem foldr_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α)
(h : ∀ x y, f' (g x) (g y) = g (f x y)) :
List.foldr f' (g a) (l.map g) = g (List.foldr f a l) := by
induction l generalizing a
· simp
· simp [*, h]
#align list.foldr_map' List.foldr_map'
#align list.foldl_hom List.foldl_hom
#align list.foldr_hom List.foldr_hom
theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) :
foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) :=
Eq.symm <| by
revert a b
induction l <;> intros <;> [rfl; simp only [*, foldl]]
#align list.foldl_hom₂ List.foldl_hom₂
theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) :
foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by
revert a
induction l <;> intros <;> [rfl; simp only [*, foldr]]
#align list.foldr_hom₂ List.foldr_hom₂
theorem injective_foldl_comp {l : List (α → α)} {f : α → α}
(hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) :
Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by
induction' l with lh lt l_ih generalizing f
· exact hf
· apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ (List.mem_cons_self _ _)
#align list.injective_foldl_comp List.injective_foldl_comp
/-- Induction principle for values produced by a `foldr`: if a property holds
for the seed element `b : β` and for all incremental `op : α → β → β`
performed on the elements `(a : α) ∈ l`. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
def foldrRecOn {C : β → Sort*} (l : List α) (op : α → β → β) (b : β) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ l, C (op a b)) : C (foldr op b l) := by
induction l with
| nil => exact hb
| cons hd tl IH =>
refine hl _ ?_ hd (mem_cons_self hd tl)
refine IH ?_
intro y hy x hx
exact hl y hy x (mem_cons_of_mem hd hx)
#align list.foldr_rec_on List.foldrRecOn
/-- Induction principle for values produced by a `foldl`: if a property holds
for the seed element `b : β` and for all incremental `op : β → α → β`
performed on the elements `(a : α) ∈ l`. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
def foldlRecOn {C : β → Sort*} (l : List α) (op : β → α → β) (b : β) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ l, C (op b a)) : C (foldl op b l) := by
induction l generalizing b with
| nil => exact hb
| cons hd tl IH =>
refine IH _ ?_ ?_
· exact hl b hb hd (mem_cons_self hd tl)
· intro y hy x hx
exact hl y hy x (mem_cons_of_mem hd hx)
#align list.foldl_rec_on List.foldlRecOn
@[simp]
theorem foldrRecOn_nil {C : β → Sort*} (op : α → β → β) (b) (hb : C b) (hl) :
foldrRecOn [] op b hb hl = hb :=
rfl
#align list.foldr_rec_on_nil List.foldrRecOn_nil
@[simp]
theorem foldrRecOn_cons {C : β → Sort*} (x : α) (l : List α) (op : α → β → β) (b) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ x :: l, C (op a b)) :
foldrRecOn (x :: l) op b hb hl =
hl _ (foldrRecOn l op b hb fun b hb a ha => hl b hb a (mem_cons_of_mem _ ha)) x
(mem_cons_self _ _) :=
rfl
#align list.foldr_rec_on_cons List.foldrRecOn_cons
@[simp]
theorem foldlRecOn_nil {C : β → Sort*} (op : β → α → β) (b) (hb : C b) (hl) :
foldlRecOn [] op b hb hl = hb :=
rfl
#align list.foldl_rec_on_nil List.foldlRecOn_nil
/-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them:
`l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`.
Assume the designated element `a₂` is present in neither `x₁` nor `z₁`.
We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal
(`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/
lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α}
(notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) :
x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by
constructor
· simp only [append_eq_append_iff, cons_eq_append, cons_eq_cons]
rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ |
⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all
· rintro ⟨rfl, rfl, rfl⟩
rfl
section Scanl
variable {f : β → α → β} {b : β} {a : α} {l : List α}
theorem length_scanl : ∀ a l, length (scanl f a l) = l.length + 1
| a, [] => rfl
| a, x :: l => by
rw [scanl, length_cons, length_cons, ← succ_eq_add_one, congr_arg succ]
exact length_scanl _ _
#align list.length_scanl List.length_scanl
@[simp]
theorem scanl_nil (b : β) : scanl f b nil = [b] :=
rfl
#align list.scanl_nil List.scanl_nil
@[simp]
theorem scanl_cons : scanl f b (a :: l) = [b] ++ scanl f (f b a) l := by
simp only [scanl, eq_self_iff_true, singleton_append, and_self_iff]
#align list.scanl_cons List.scanl_cons
@[simp]
theorem get?_zero_scanl : (scanl f b l).get? 0 = some b := by
cases l
· simp only [get?, scanl_nil]
· simp only [get?, scanl_cons, singleton_append]
#align list.nth_zero_scanl List.get?_zero_scanl
@[simp]
theorem get_zero_scanl {h : 0 < (scanl f b l).length} : (scanl f b l).get ⟨0, h⟩ = b := by
cases l
· simp only [get, scanl_nil]
· simp only [get, scanl_cons, singleton_append]
set_option linter.deprecated false in
@[simp, deprecated get_zero_scanl (since := "2023-01-05")]
theorem nthLe_zero_scanl {h : 0 < (scanl f b l).length} : (scanl f b l).nthLe 0 h = b :=
get_zero_scanl
#align list.nth_le_zero_scanl List.nthLe_zero_scanl
theorem get?_succ_scanl {i : ℕ} : (scanl f b l).get? (i + 1) =
((scanl f b l).get? i).bind fun x => (l.get? i).map fun y => f x y := by
induction' l with hd tl hl generalizing b i
· symm
simp only [Option.bind_eq_none', get?, forall₂_true_iff, not_false_iff, Option.map_none',
scanl_nil, Option.not_mem_none, forall_true_iff]
· simp only [scanl_cons, singleton_append]
cases i
· simp only [Option.map_some', get?_zero_scanl, get?, Option.some_bind']
· simp only [hl, get?]
#align list.nth_succ_scanl List.get?_succ_scanl
set_option linter.deprecated false in
theorem nthLe_succ_scanl {i : ℕ} {h : i + 1 < (scanl f b l).length} :
(scanl f b l).nthLe (i + 1) h =
f ((scanl f b l).nthLe i (Nat.lt_of_succ_lt h))
(l.nthLe i (Nat.lt_of_succ_lt_succ (lt_of_lt_of_le h (le_of_eq (length_scanl b l))))) := by
induction i generalizing b l with
| zero =>
cases l
· simp only [length, zero_eq, lt_self_iff_false] at h
· simp [scanl_cons, singleton_append, nthLe_zero_scanl, nthLe_cons]
| succ i hi =>
cases l
· simp only [length] at h
exact absurd h (by omega)
· simp_rw [scanl_cons]
rw [nthLe_append_right]
· simp only [length, Nat.zero_add 1, succ_add_sub_one, hi]; rfl
· simp only [length_singleton]; omega
#align list.nth_le_succ_scanl List.nthLe_succ_scanl
theorem get_succ_scanl {i : ℕ} {h : i + 1 < (scanl f b l).length} :
(scanl f b l).get ⟨i + 1, h⟩ =
f ((scanl f b l).get ⟨i, Nat.lt_of_succ_lt h⟩)
(l.get ⟨i, Nat.lt_of_succ_lt_succ (lt_of_lt_of_le h (le_of_eq (length_scanl b l)))⟩) :=
nthLe_succ_scanl
-- FIXME: we should do the proof the other way around
attribute [deprecated get_succ_scanl (since := "2023-01-05")] nthLe_succ_scanl
end Scanl
-- scanr
@[simp]
theorem scanr_nil (f : α → β → β) (b : β) : scanr f b [] = [b] :=
rfl
#align list.scanr_nil List.scanr_nil
#noalign list.scanr_aux_cons
@[simp]
theorem scanr_cons (f : α → β → β) (b : β) (a : α) (l : List α) :
scanr f b (a :: l) = foldr f b (a :: l) :: scanr f b l := by
simp only [scanr, foldr, cons.injEq, and_true]
induction l generalizing a with
| nil => rfl
| cons hd tl ih => simp only [foldr, ih]
#align list.scanr_cons List.scanr_cons
section FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α} (hcomm : Commutative f) (hassoc : Associative f)
theorem foldl1_eq_foldr1 : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| a, b, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]; rw [hassoc]
#align list.foldl1_eq_foldr1 List.foldl1_eq_foldr1
theorem foldl_eq_of_comm_of_assoc : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm a b
| a, b, c :: l => by
simp only [foldl_cons]
rw [← foldl_eq_of_comm_of_assoc .., right_comm _ hcomm hassoc]; rfl
#align list.foldl_eq_of_comm_of_assoc List.foldl_eq_of_comm_of_assoc
theorem foldl_eq_foldr : ∀ a l, foldl f a l = foldr f a l
| a, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc hcomm hassoc]; rw [foldl_eq_foldr a l]
#align list.foldl_eq_foldr List.foldl_eq_foldr
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| a, b, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
#align list.foldl_eq_of_comm' List.foldl_eq_of_comm'
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| a, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
#align list.foldl_eq_foldr' List.foldl_eq_foldr'
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
variable (hf : ∀ a b c, f a (f b c) = f b (f a c))
theorem foldr_eq_of_comm' : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| a, b, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' ..]; rfl
#align list.foldr_eq_of_comm' List.foldr_eq_of_comm'
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op] [hc : Std.Commutative op]
/-- Notation for `op a b`. -/
local notation a " ⋆ " b => op a b
/-- Notation for `foldl op a l`. -/
local notation l " <*> " a => foldl op a l
theorem foldl_assoc : ∀ {l : List α} {a₁ a₂}, (l <*> a₁ ⋆ a₂) = a₁ ⋆ l <*> a₂
| [], a₁, a₂ => rfl
| a :: l, a₁, a₂ =>
calc
((a :: l) <*> a₁ ⋆ a₂) = l <*> a₁ ⋆ a₂ ⋆ a := by simp only [foldl_cons, ha.assoc]
_ = a₁ ⋆ (a :: l) <*> a₂ := by rw [foldl_assoc, foldl_cons]
#align list.foldl_assoc List.foldl_assoc
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], a₁, a₂ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
#align list.foldl_op_eq_op_foldr_assoc List.foldl_op_eq_op_foldr_assoc
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
#align list.foldl_assoc_comm_cons List.foldl_assoc_comm_cons
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
#align list.mfoldl_nil List.foldlM_nil
-- Porting note: now in std
#align list.mfoldr_nil List.foldrM_nil
#align list.mfoldl_cons List.foldlM_cons
/- Porting note: now in std; now assumes an instance of `LawfulMonad m`, so we make everything
`foldrM_eq_foldr` depend on one as well. (An instance of `LawfulMonad m` was already present for
everything following; this just moves it a few lines up.) -/
#align list.mfoldr_cons List.foldrM_cons
variable [LawfulMonad m]
theorem foldrM_eq_foldr (f : α → β → m β) (b l) :
foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*]
#align list.mfoldr_eq_foldr List.foldrM_eq_foldr
attribute [simp] mapM mapM'
theorem foldlM_eq_foldl (f : β → α → m β) (b l) :
List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by
suffices h :
∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
by simp [← h (pure b)]
induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
#align list.mfoldl_eq_foldl List.foldlM_eq_foldl
-- Porting note: now in std
#align list.mfoldl_append List.foldlM_append
-- Porting note: now in std
#align list.mfoldr_append List.foldrM_append
end FoldlMFoldrM
/-! ### intersperse -/
#align list.intersperse_nil List.intersperse_nil
@[simp]
theorem intersperse_singleton (a b : α) : intersperse a [b] = [b] :=
rfl
#align list.intersperse_singleton List.intersperse_singleton
@[simp]
theorem intersperse_cons_cons (a b c : α) (tl : List α) :
intersperse a (b :: c :: tl) = b :: a :: intersperse a (c :: tl) :=
rfl
#align list.intersperse_cons_cons List.intersperse_cons_cons
/-! ### splitAt and splitOn -/
section SplitAtOn
/- Porting note: the new version of `splitOnP` uses a `Bool`-valued predicate instead of a
`Prop`-valued one. All downstream definitions have been updated to match. -/
variable (p : α → Bool) (xs ys : List α) (ls : List (List α)) (f : List α → List α)
/- Porting note: this had to be rewritten because of the new implementation of `splitAt`. It's
long in large part because `splitAt.go` (`splitAt`'s auxiliary function) works differently
in the case where n ≥ length l, requiring two separate cases (and two separate inductions). Still,
this can hopefully be golfed. -/
@[simp]
theorem splitAt_eq_take_drop (n : ℕ) (l : List α) : splitAt n l = (take n l, drop n l) := by
by_cases h : n < l.length <;> rw [splitAt, go_eq_take_drop]
· rw [if_pos h]; rfl
· rw [if_neg h, take_all_of_le <| le_of_not_lt h, drop_eq_nil_of_le <| le_of_not_lt h]
where
go_eq_take_drop (n : ℕ) (l xs : List α) (acc : Array α) : splitAt.go l xs n acc =
if n < xs.length then (acc.toList ++ take n xs, drop n xs) else (l, []) := by
split_ifs with h
· induction n generalizing xs acc with
| zero =>
rw [splitAt.go, take, drop, append_nil]
· intros h₁; rw [h₁] at h; contradiction
· intros; contradiction
| succ _ ih =>
cases xs with
| nil => contradiction
| cons hd tl =>
rw [length] at h
rw [splitAt.go, take, drop, append_cons, Array.toList_eq, ← Array.push_data,
← Array.toList_eq]
exact ih _ _ <| (by omega)
· induction n generalizing xs acc with
| zero =>
replace h : xs.length = 0 := by omega
rw [eq_nil_of_length_eq_zero h, splitAt.go]
| succ _ ih =>
cases xs with
| nil => rw [splitAt.go]
| cons hd tl =>
rw [length] at h
rw [splitAt.go]
exact ih _ _ <| not_imp_not.mpr (Nat.add_lt_add_right · 1) h
#align list.split_at_eq_take_drop List.splitAt_eq_take_drop
@[simp]
theorem splitOn_nil [DecidableEq α] (a : α) : [].splitOn a = [[]] :=
rfl
#align list.split_on_nil List.splitOn_nil
@[simp]
theorem splitOnP_nil : [].splitOnP p = [[]] :=
rfl
#align list.split_on_p_nil List.splitOnP_nilₓ
/- Porting note: `split_on_p_aux` and `split_on_p_aux'` were used to prove facts about
`split_on_p`. `splitOnP` has a different structure, and we need different facts about
`splitOnP.go`. Theorems involving `split_on_p_aux` have been omitted where possible. -/
#noalign list.split_on_p_aux_ne_nil
#noalign list.split_on_p_aux_spec
#noalign list.split_on_p_aux'
#noalign list.split_on_p_aux_eq
#noalign list.split_on_p_aux_nil
theorem splitOnP.go_ne_nil (xs acc : List α) : splitOnP.go p xs acc ≠ [] := by
induction xs generalizing acc <;> simp [go]; split <;> simp [*]
theorem splitOnP.go_acc (xs acc : List α) :
splitOnP.go p xs acc = modifyHead (acc.reverse ++ ·) (splitOnP p xs) := by
induction xs generalizing acc with
| nil => simp only [go, modifyHead, splitOnP_nil, append_nil]
| cons hd tl ih =>
simp only [splitOnP, go]; split
· simp only [modifyHead, reverse_nil, append_nil]
· rw [ih [hd], modifyHead_modifyHead, ih]
congr; funext x; simp only [reverse_cons, append_assoc]; rfl
theorem splitOnP_ne_nil (xs : List α) : xs.splitOnP p ≠ [] := splitOnP.go_ne_nil _ _ _
#align list.split_on_p_ne_nil List.splitOnP_ne_nilₓ
@[simp]
theorem splitOnP_cons (x : α) (xs : List α) :
(x :: xs).splitOnP p =
if p x then [] :: xs.splitOnP p else (xs.splitOnP p).modifyHead (cons x) := by
rw [splitOnP, splitOnP.go]; split <;> [rfl; simp [splitOnP.go_acc]]
#align list.split_on_p_cons List.splitOnP_consₓ
/-- The original list `L` can be recovered by joining the lists produced by `splitOnP p L`,
interspersed with the elements `L.filter p`. -/
theorem splitOnP_spec (as : List α) :
join (zipWith (· ++ ·) (splitOnP p as) (((as.filter p).map fun x => [x]) ++ [[]])) = as := by
induction as with
| nil => rfl
| cons a as' ih =>
rw [splitOnP_cons, filter]
by_cases h : p a
· rw [if_pos h, h, map, cons_append, zipWith, nil_append, join, cons_append, cons_inj]
exact ih
· rw [if_neg h, eq_false_of_ne_true h, join_zipWith (splitOnP_ne_nil _ _)
(append_ne_nil_of_ne_nil_right _ [[]] (cons_ne_nil [] [])), cons_inj]
exact ih
where
join_zipWith {xs ys : List (List α)} {a : α} (hxs : xs ≠ []) (hys : ys ≠ []) :
join (zipWith (fun x x_1 ↦ x ++ x_1) (modifyHead (cons a) xs) ys) =
a :: join (zipWith (fun x x_1 ↦ x ++ x_1) xs ys) := by
cases xs with | nil => contradiction | cons =>
cases ys with | nil => contradiction | cons => rfl
#align list.split_on_p_spec List.splitOnP_specₓ
/-- If no element satisfies `p` in the list `xs`, then `xs.splitOnP p = [xs]` -/
theorem splitOnP_eq_single (h : ∀ x ∈ xs, ¬p x) : xs.splitOnP p = [xs] := by
induction xs with
| nil => rfl
| cons hd tl ih =>
simp only [splitOnP_cons, h hd (mem_cons_self hd tl), if_neg]
rw [ih <| forall_mem_of_forall_mem_cons h]
rfl
#align list.split_on_p_eq_single List.splitOnP_eq_singleₓ
/-- When a list of the form `[...xs, sep, ...as]` is split on `p`, the first element is `xs`,
assuming no element in `xs` satisfies `p` but `sep` does satisfy `p` -/
theorem splitOnP_first (h : ∀ x ∈ xs, ¬p x) (sep : α) (hsep : p sep) (as : List α) :
(xs ++ sep :: as).splitOnP p = xs :: as.splitOnP p := by
induction xs with
| nil => simp [hsep]
| cons hd tl ih => simp [h hd _, ih <| forall_mem_of_forall_mem_cons h]
#align list.split_on_p_first List.splitOnP_firstₓ
/-- `intercalate [x]` is the left inverse of `splitOn x` -/
theorem intercalate_splitOn (x : α) [DecidableEq α] : [x].intercalate (xs.splitOn x) = xs := by
simp only [intercalate, splitOn]
induction' xs with hd tl ih; · simp [join]
cases' h' : splitOnP (· == x) tl with hd' tl'; · exact (splitOnP_ne_nil _ tl h').elim
rw [h'] at ih
rw [splitOnP_cons]
split_ifs with h
· rw [beq_iff_eq] at h
subst h
simp [ih, join, h']
cases tl' <;> simpa [join, h'] using ih
#align list.intercalate_split_on List.intercalate_splitOn
/-- `splitOn x` is the left inverse of `intercalate [x]`, on the domain
consisting of each nonempty list of lists `ls` whose elements do not contain `x` -/
theorem splitOn_intercalate [DecidableEq α] (x : α) (hx : ∀ l ∈ ls, x ∉ l) (hls : ls ≠ []) :
([x].intercalate ls).splitOn x = ls := by
simp only [intercalate]
induction' ls with hd tl ih; · contradiction
cases tl
· suffices hd.splitOn x = [hd] by simpa [join]
refine splitOnP_eq_single _ _ ?_
intro y hy H
rw [eq_of_beq H] at hy
refine hx hd ?_ hy
simp
· simp only [intersperse_cons_cons, singleton_append, join]
specialize ih _ _
· intro l hl
apply hx l
simp only [mem_cons] at hl ⊢
exact Or.inr hl
· exact List.noConfusion
have := splitOnP_first (· == x) hd ?h x (beq_self_eq_true _)
case h =>
intro y hy H
rw [eq_of_beq H] at hy
exact hx hd (.head _) hy
simp only [splitOn] at ih ⊢
rw [this, ih]
#align list.split_on_intercalate List.splitOn_intercalate
end SplitAtOn
/- Porting note: new; here tentatively -/
/-! ### modifyLast -/
section ModifyLast
theorem modifyLast.go_append_one (f : α → α) (a : α) (tl : List α) (r : Array α) :
modifyLast.go f (tl ++ [a]) r = (r.toListAppend <| modifyLast.go f (tl ++ [a]) #[]) := by
cases tl with
| nil =>
simp only [nil_append, modifyLast.go]; rfl
| cons hd tl =>
simp only [cons_append]
rw [modifyLast.go, modifyLast.go]
case x_3 | x_3 => exact append_ne_nil_of_ne_nil_right tl [a] (cons_ne_nil a [])
rw [modifyLast.go_append_one _ _ tl _, modifyLast.go_append_one _ _ tl (Array.push #[] hd)]
simp only [Array.toListAppend_eq, Array.push_data, Array.data_toArray, nil_append, append_assoc]
theorem modifyLast_append_one (f : α → α) (a : α) (l : List α) :
modifyLast f (l ++ [a]) = l ++ [f a] := by
cases l with
| nil =>
simp only [nil_append, modifyLast, modifyLast.go, Array.toListAppend_eq, Array.data_toArray]
| cons _ tl =>
simp only [cons_append, modifyLast]
rw [modifyLast.go]
case x_3 => exact append_ne_nil_of_ne_nil_right tl [a] (cons_ne_nil a [])
rw [modifyLast.go_append_one, Array.toListAppend_eq, Array.push_data, Array.data_toArray,
nil_append, cons_append, nil_append, cons_inj]
exact modifyLast_append_one _ _ tl
theorem modifyLast_append (f : α → α) (l₁ l₂ : List α) (_ : l₂ ≠ []) :
modifyLast f (l₁ ++ l₂) = l₁ ++ modifyLast f l₂ := by
cases l₂ with
| nil => contradiction
| cons hd tl =>
cases tl with
| nil => exact modifyLast_append_one _ hd _
| cons hd' tl' =>
rw [append_cons, ← nil_append (hd :: hd' :: tl'), append_cons [], nil_append,
modifyLast_append _ (l₁ ++ [hd]) (hd' :: tl') _, modifyLast_append _ [hd] (hd' :: tl') _,
append_assoc]
all_goals { exact cons_ne_nil _ _ }
end ModifyLast
/-! ### map for partial functions -/
#align list.pmap List.pmap
#align list.attach List.attach
@[simp] lemma attach_nil : ([] : List α).attach = [] := rfl
#align list.attach_nil List.attach_nil
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction' l with h t ih <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
#align list.sizeof_lt_sizeof_of_mem List.sizeOf_lt_sizeOf_of_mem
@[simp]
theorem pmap_eq_map (p : α → Prop) (f : α → β) (l : List α) (H) :
@pmap _ _ p (fun a _ => f a) l H = map f l := by
induction l <;> [rfl; simp only [*, pmap, map]]
#align list.pmap_eq_map List.pmap_eq_map
theorem pmap_congr {p q : α → Prop} {f : ∀ a, p a → β} {g : ∀ a, q a → β} (l : List α) {H₁ H₂}
(h : ∀ a ∈ l, ∀ (h₁ h₂), f a h₁ = g a h₂) : pmap f l H₁ = pmap g l H₂ := by
induction' l with _ _ ih
· rfl
· rw [pmap, pmap, h _ (mem_cons_self _ _), ih fun a ha => h a (mem_cons_of_mem _ ha)]
#align list.pmap_congr List.pmap_congr
theorem map_pmap {p : α → Prop} (g : β → γ) (f : ∀ a, p a → β) (l H) :
map g (pmap f l H) = pmap (fun a h => g (f a h)) l H := by
induction l <;> [rfl; simp only [*, pmap, map]]
#align list.map_pmap List.map_pmap
theorem pmap_map {p : β → Prop} (g : ∀ b, p b → γ) (f : α → β) (l H) :
pmap g (map f l) H = pmap (fun a h => g (f a) h) l fun a h => H _ (mem_map_of_mem _ h) := by
induction l <;> [rfl; simp only [*, pmap, map]]
#align list.pmap_map List.pmap_map
theorem pmap_eq_map_attach {p : α → Prop} (f : ∀ a, p a → β) (l H) :
pmap f l H = l.attach.map fun x => f x.1 (H _ x.2) := by
rw [attach, attachWith, map_pmap]; exact pmap_congr l fun _ _ _ _ => rfl
#align list.pmap_eq_map_attach List.pmap_eq_map_attach
-- @[simp] -- Porting note (#10959): lean 4 simp can't rewrite with this
theorem attach_map_coe' (l : List α) (f : α → β) :
(l.attach.map fun (i : {i // i ∈ l}) => f i) = l.map f := by
rw [attach, attachWith, map_pmap]; exact pmap_eq_map _ _ _ _
#align list.attach_map_coe' List.attach_map_coe'
theorem attach_map_val' (l : List α) (f : α → β) : (l.attach.map fun i => f i.val) = l.map f :=
attach_map_coe' _ _
#align list.attach_map_val' List.attach_map_val'
@[simp]
theorem attach_map_val (l : List α) : l.attach.map Subtype.val = l :=
(attach_map_coe' _ _).trans l.map_id
-- Porting note: coe is expanded eagerly, so "attach_map_coe" would have the same syntactic form.
#align list.attach_map_coe List.attach_map_val
#align list.attach_map_val List.attach_map_val
@[simp]
theorem mem_attach (l : List α) : ∀ x, x ∈ l.attach
| ⟨a, h⟩ => by
have := mem_map.1 (by rw [attach_map_val] <;> exact h)
rcases this with ⟨⟨_, _⟩, m, rfl⟩
exact m
#align list.mem_attach List.mem_attach
@[simp]
theorem mem_pmap {p : α → Prop} {f : ∀ a, p a → β} {l H b} :
b ∈ pmap f l H ↔ ∃ (a : _) (h : a ∈ l), f a (H a h) = b := by
simp only [pmap_eq_map_attach, mem_map, mem_attach, true_and_iff, Subtype.exists, eq_comm]
#align list.mem_pmap List.mem_pmap
@[simp]
theorem length_pmap {p : α → Prop} {f : ∀ a, p a → β} {l H} : length (pmap f l H) = length l := by
induction l <;> [rfl; simp only [*, pmap, length]]
#align list.length_pmap List.length_pmap
@[simp]
theorem length_attach (L : List α) : L.attach.length = L.length :=
length_pmap
#align list.length_attach List.length_attach
@[simp]
theorem pmap_eq_nil {p : α → Prop} {f : ∀ a, p a → β} {l H} : pmap f l H = [] ↔ l = [] := by
rw [← length_eq_zero, length_pmap, length_eq_zero]
#align list.pmap_eq_nil List.pmap_eq_nil
@[simp]
theorem attach_eq_nil (l : List α) : l.attach = [] ↔ l = [] :=
pmap_eq_nil
#align list.attach_eq_nil List.attach_eq_nil
theorem getLast_pmap (p : α → Prop) (f : ∀ a, p a → β) (l : List α)
(hl₁ : ∀ a ∈ l, p a) (hl₂ : l ≠ []) :
(l.pmap f hl₁).getLast (mt List.pmap_eq_nil.1 hl₂) =
f (l.getLast hl₂) (hl₁ _ (List.getLast_mem hl₂)) := by
induction' l with l_hd l_tl l_ih
· apply (hl₂ rfl).elim
· by_cases hl_tl : l_tl = []
· simp [hl_tl]
· simp only [pmap]
rw [getLast_cons, l_ih _ hl_tl]
simp only [getLast_cons hl_tl]
#align list.last_pmap List.getLast_pmap
theorem get?_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) (n : ℕ) :
get? (pmap f l h) n = Option.pmap f (get? l n) fun x H => h x (get?_mem H) := by
induction' l with hd tl hl generalizing n
· simp
· cases' n with n
· simp
· simp [hl]
#align list.nth_pmap List.get?_pmap
theorem get_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) {n : ℕ}
(hn : n < (pmap f l h).length) :
get (pmap f l h) ⟨n, hn⟩ =
f (get l ⟨n, @length_pmap _ _ p f l h ▸ hn⟩)
(h _ (get_mem l n (@length_pmap _ _ p f l h ▸ hn))) := by
induction' l with hd tl hl generalizing n
· simp only [length, pmap] at hn
exact absurd hn (not_lt_of_le n.zero_le)
· cases n
· simp
· simp [hl]
set_option linter.deprecated false in
@[deprecated get_pmap (since := "2023-01-05")]
theorem nthLe_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) {n : ℕ}
(hn : n < (pmap f l h).length) :
nthLe (pmap f l h) n hn =
f (nthLe l n (@length_pmap _ _ p f l h ▸ hn))
(h _ (get_mem l n (@length_pmap _ _ p f l h ▸ hn))) :=
get_pmap ..
#align list.nth_le_pmap List.nthLe_pmap
theorem pmap_append {p : ι → Prop} (f : ∀ a : ι, p a → α) (l₁ l₂ : List ι)
(h : ∀ a ∈ l₁ ++ l₂, p a) :
(l₁ ++ l₂).pmap f h =
(l₁.pmap f fun a ha => h a (mem_append_left l₂ ha)) ++
l₂.pmap f fun a ha => h a (mem_append_right l₁ ha) := by
induction' l₁ with _ _ ih
· rfl
· dsimp only [pmap, cons_append]
rw [ih]
#align list.pmap_append List.pmap_append
theorem pmap_append' {p : α → Prop} (f : ∀ a : α, p a → β) (l₁ l₂ : List α)
(h₁ : ∀ a ∈ l₁, p a) (h₂ : ∀ a ∈ l₂, p a) :
((l₁ ++ l₂).pmap f fun a ha => (List.mem_append.1 ha).elim (h₁ a) (h₂ a)) =
l₁.pmap f h₁ ++ l₂.pmap f h₂ :=
pmap_append f l₁ l₂ _
#align list.pmap_append' List.pmap_append'
/-! ### find -/
section find?
variable {p : α → Bool} {l : List α} {a : α}
#align list.find_nil List.find?_nil
-- @[simp]
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] find?_cons_of_pos
#align list.find_cons_of_pos List.find?_cons_of_pos
-- @[simp]
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] find?_cons_of_neg
#align list.find_cons_of_neg List.find?_cons_of_neg
attribute [simp] find?_eq_none
#align list.find_eq_none List.find?_eq_none
#align list.find_some List.find?_some
@[deprecated (since := "2024-05-05")] alias find?_mem := mem_of_find?_eq_some
#align list.find_mem List.mem_of_find?_eq_some
end find?
/-! ### lookmap -/
section Lookmap
variable (f : α → Option α)
/- Porting note: need a helper theorem for lookmap.go. -/
theorem lookmap.go_append (l : List α) (acc : Array α) :
lookmap.go f l acc = acc.toListAppend (lookmap f l) := by
cases l with
| nil => rfl
| cons hd tl =>
rw [lookmap, go, go]
cases f hd with
| none => simp only [go_append tl _, Array.toListAppend_eq, append_assoc, Array.push_data]; rfl
| some a => rfl
@[simp]
theorem lookmap_nil : [].lookmap f = [] :=
rfl
#align list.lookmap_nil List.lookmap_nil
@[simp]
theorem lookmap_cons_none {a : α} (l : List α) (h : f a = none) :
(a :: l).lookmap f = a :: l.lookmap f := by
simp only [lookmap, lookmap.go, Array.toListAppend_eq, Array.data_toArray, nil_append]
rw [lookmap.go_append, h]; rfl
#align list.lookmap_cons_none List.lookmap_cons_none
@[simp]
theorem lookmap_cons_some {a b : α} (l : List α) (h : f a = some b) :
(a :: l).lookmap f = b :: l := by
simp only [lookmap, lookmap.go, Array.toListAppend_eq, Array.data_toArray, nil_append]
rw [h]
#align list.lookmap_cons_some List.lookmap_cons_some
theorem lookmap_some : ∀ l : List α, l.lookmap some = l
| [] => rfl
| _ :: _ => rfl
#align list.lookmap_some List.lookmap_some
theorem lookmap_none : ∀ l : List α, (l.lookmap fun _ => none) = l
| [] => rfl
| a :: l => (lookmap_cons_none _ l rfl).trans (congr_arg (cons a) (lookmap_none l))
#align list.lookmap_none List.lookmap_none
theorem lookmap_congr {f g : α → Option α} :
∀ {l : List α}, (∀ a ∈ l, f a = g a) → l.lookmap f = l.lookmap g
| [], _ => rfl
| a :: l, H => by
cases' forall_mem_cons.1 H with H₁ H₂
cases' h : g a with b
· simp [h, H₁.trans h, lookmap_congr H₂]
· simp [lookmap_cons_some _ _ h, lookmap_cons_some _ _ (H₁.trans h)]
#align list.lookmap_congr List.lookmap_congr
theorem lookmap_of_forall_not {l : List α} (H : ∀ a ∈ l, f a = none) : l.lookmap f = l :=
(lookmap_congr H).trans (lookmap_none l)
#align list.lookmap_of_forall_not List.lookmap_of_forall_not
theorem lookmap_map_eq (g : α → β) (h : ∀ (a), ∀ b ∈ f a, g a = g b) :
∀ l : List α, map g (l.lookmap f) = map g l
| [] => rfl
| a :: l => by
cases' h' : f a with b
· simpa [h'] using lookmap_map_eq _ h l
· simp [lookmap_cons_some _ _ h', h _ _ h']
#align list.lookmap_map_eq List.lookmap_map_eq
theorem lookmap_id' (h : ∀ (a), ∀ b ∈ f a, a = b) (l : List α) : l.lookmap f = l := by
rw [← map_id (l.lookmap f), lookmap_map_eq, map_id]; exact h
#align list.lookmap_id' List.lookmap_id'
theorem length_lookmap (l : List α) : length (l.lookmap f) = length l := by
rw [← length_map, lookmap_map_eq _ fun _ => (), length_map]; simp
#align list.length_lookmap List.length_lookmap
end Lookmap
/-! ### filter -/
theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) :
l.length = (l.filter f).length + (l.filter (! f ·)).length := by
simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true,
Bool.decide_eq_false]
/-! ### filterMap -/
#align list.filter_map_nil List.filterMap_nil
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] filterMap_cons_none
#align list.filter_map_cons_none List.filterMap_cons_none
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] filterMap_cons_some
#align list.filter_map_cons_some List.filterMap_cons_some
#align list.filter_map_cons List.filterMap_cons
#align list.filter_map_append List.filterMap_append
#align list.filter_map_eq_map List.filterMap_eq_map
#align list.filter_map_eq_filter List.filterMap_eq_filter
#align list.filter_map_filter_map List.filterMap_filterMap
#align list.map_filter_map List.map_filterMap
#align list.filter_map_map List.filterMap_map
#align list.filter_filter_map List.filter_filterMap
#align list.filter_map_filter List.filterMap_filter
#align list.filter_map_some List.filterMap_some
#align list.map_filter_map_some_eq_filter_map_is_some List.map_filterMap_some_eq_filter_map_is_some
#align list.mem_filter_map List.mem_filterMap
#align list.filter_map_join List.filterMap_join
#align list.map_filter_map_of_inv List.map_filterMap_of_inv
#align list.length_filter_le List.length_filter_leₓ
#align list.length_filter_map_le List.length_filterMap_le
#align list.sublist.filter_map List.Sublist.filterMap
theorem Sublist.map (f : α → β) {l₁ l₂ : List α} (s : l₁ <+ l₂) : map f l₁ <+ map f l₂ :=
filterMap_eq_map f ▸ s.filterMap _
#align list.sublist.map List.Sublist.map
theorem filterMap_eq_bind_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.bind fun a ↦ (f a).toList := by
induction' l with a l ih <;> simp
rcases f a <;> simp [ih]
theorem filterMap_congr {f g : α → Option β} {l : List α}
(h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by
induction' l with a l ih <;> simp
simp [ih (fun x hx ↦ h x (List.mem_cons_of_mem a hx))]
cases' hfa : f a with b
· have : g a = none := Eq.symm (by simpa [hfa] using h a (by simp))
simp [this]
· have : g a = some b := Eq.symm (by simpa [hfa] using h a (by simp))
simp [this]
theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} :
l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where
mp := by
induction' l with a l ih
· simp
cases' ha : f a with b <;> simp [ha]
· intro h
simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff]
using List.length_filterMap_le f l
· rintro rfl h
exact ⟨rfl, ih h⟩
mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun (List.filterMap_eq_map _) _)
/-! ### filter -/
section Filter
-- Porting note: Lemmas for `filter` are stated in terms of `p : α → Bool`
-- rather than `p : α → Prop` with `DecidablePred p`, since `filter` itself is.
-- Likewise, `if` sometimes becomes `bif`.
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
#align list.filter_singleton List.filter_singleton
theorem filter_eq_foldr (p : α → Bool) (l : List α) :
filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by
induction l <;> simp [*, filter]; rfl
#align list.filter_eq_foldr List.filter_eq_foldr
#align list.filter_congr' List.filter_congr'
@[simp]
theorem filter_subset (l : List α) : filter p l ⊆ l :=
(filter_sublist l).subset
#align list.filter_subset List.filter_subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
#align list.of_mem_filter List.of_mem_filter
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset l h
#align list.mem_of_mem_filter List.mem_of_mem_filter
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
#align list.mem_filter_of_mem List.mem_filter_of_mem
#align list.mem_filter List.mem_filter
theorem monotone_filter_left (p : α → Bool) ⦃l l' : List α⦄ (h : l ⊆ l') :
filter p l ⊆ filter p l' := by
intro x hx
rw [mem_filter] at hx ⊢
exact ⟨h hx.left, hx.right⟩
#align list.monotone_filter_left List.monotone_filter_left
#align list.filter_eq_self List.filter_eq_self
#align list.filter_length_eq_length List.filter_length_eq_length
#align list.filter_eq_nil List.filter_eq_nil
variable (p)
#align list.sublist.filter List.Sublist.filter
theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄
(h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by
induction' l with hd tl IH
· rfl
· by_cases hp : p hd
· rw [filter_cons_of_pos _ hp, filter_cons_of_pos _ (h _ hp)]
exact IH.cons_cons hd
· rw [filter_cons_of_neg _ hp]
by_cases hq : q hd
· rw [filter_cons_of_pos _ hq]
exact sublist_cons_of_sublist hd IH
· rw [filter_cons_of_neg _ hq]
exact IH
#align list.monotone_filter_right List.monotone_filter_right
#align list.map_filter List.map_filter
lemma map_filter' {f : α → β} (hf : Injective f) (l : List α)
[DecidablePred fun b => ∃ a, p a ∧ f a = b] :
(l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [(· ∘ ·), map_filter, hf.eq_iff]
#align list.map_filter' List.map_filter'
lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] :
l.attach.filter p =
(l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun x => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [(· ∘ ·), map_filter' _ Subtype.coe_injective]
#align list.filter_attach' List.filter_attach'
-- Porting note: `Lean.Internal.coeM` forces us to type-ascript `{x // x ∈ l}`
lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) =
(l.filter p).attach.map (Subtype.map id fun x => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, (· ∘ ·), Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← map_filter, attach_map_val]
#align list.filter_attach List.filter_attach
#align list.filter_filter List.filter_filter
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [and_comm]
#align list.filter_comm List.filter_comm
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
#align list.filter_true List.filter_true
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
#align list.filter_false List.filter_false
/- Porting note: need a helper theorem for span.loop. -/
theorem span.loop_eq_take_drop :
∀ l₁ l₂ : List α, span.loop p l₁ l₂ = (l₂.reverse ++ takeWhile p l₁, dropWhile p l₁)
| [], l₂ => by simp [span.loop, takeWhile, dropWhile]
| (a :: l), l₂ => by
cases hp : p a <;> simp [hp, span.loop, span.loop_eq_take_drop, takeWhile, dropWhile]
@[simp]
theorem span_eq_take_drop (l : List α) : span p l = (takeWhile p l, dropWhile p l) := by
simpa using span.loop_eq_take_drop p l []
#align list.span_eq_take_drop List.span_eq_take_drop
#align list.take_while_append_drop List.takeWhile_append_dropWhile
-- TODO update to use `get` instead of `nthLe`
set_option linter.deprecated false in
theorem dropWhile_nthLe_zero_not (l : List α) (hl : 0 < (l.dropWhile p).length) :
¬p ((l.dropWhile p).nthLe 0 hl) := by
induction' l with hd tl IH
· cases hl
· simp only [dropWhile]
by_cases hp : p hd
· simp [hp, IH]
· simp [hp, nthLe_cons]
-- Porting note: How did the Lean 3 proof work,
-- without mentioning nthLe_cons?
-- Same question for takeWhile_eq_nil_iff below
#align list.drop_while_nth_le_zero_not List.dropWhile_nthLe_zero_not
variable {p} {l : List α}
@[simp]
theorem dropWhile_eq_nil_iff : dropWhile p l = [] ↔ ∀ x ∈ l, p x := by
induction' l with x xs IH
· simp [dropWhile]
· by_cases hp : p x <;> simp [hp, dropWhile, IH]
#align list.drop_while_eq_nil_iff List.dropWhile_eq_nil_iff
@[simp] theorem takeWhile_nil : List.takeWhile p [] = [] := rfl
theorem takeWhile_cons {x : α} :
List.takeWhile p (x :: l) = (match p x with
| true => x :: takeWhile p l
| false => []) :=
rfl
theorem takeWhile_cons_of_pos {x : α} (h : p x) :
List.takeWhile p (x :: l) = x :: takeWhile p l := by
simp [takeWhile_cons, h]
theorem takeWhile_cons_of_neg {x : α} (h : ¬ p x) :
List.takeWhile p (x :: l) = [] := by
simp [takeWhile_cons, h]
@[simp]
theorem takeWhile_eq_self_iff : takeWhile p l = l ↔ ∀ x ∈ l, p x := by
induction' l with x xs IH
· simp
· by_cases hp : p x <;> simp [hp, takeWhile_cons, IH]
#align list.take_while_eq_self_iff List.takeWhile_eq_self_iff
-- TODO update to use `get` instead of `nthLe`
set_option linter.deprecated false in
@[simp]
theorem takeWhile_eq_nil_iff : takeWhile p l = [] ↔ ∀ hl : 0 < l.length, ¬p (l.nthLe 0 hl) := by
induction' l with x xs IH
· simp only [takeWhile_nil, Bool.not_eq_true, true_iff]
intro h
simp at h
· by_cases hp : p x <;> simp [hp, takeWhile_cons, IH, nthLe_cons]
#align list.take_while_eq_nil_iff List.takeWhile_eq_nil_iff
theorem mem_takeWhile_imp {x : α} (hx : x ∈ takeWhile p l) : p x := by
induction l with simp [takeWhile] at hx
| cons hd tl IH =>
cases hp : p hd
· simp [hp] at hx
· rw [hp, mem_cons] at hx
rcases hx with (rfl | hx)
· exact hp
· exact IH hx
#align list.mem_take_while_imp List.mem_takeWhile_imp
theorem takeWhile_takeWhile (p q : α → Bool) (l : List α) :
takeWhile p (takeWhile q l) = takeWhile (fun a => p a ∧ q a) l := by
induction' l with hd tl IH
· simp
· by_cases hp : p hd <;> by_cases hq : q hd <;> simp [takeWhile, hp, hq, IH]
#align list.take_while_take_while List.takeWhile_takeWhile
theorem takeWhile_idem : takeWhile p (takeWhile p l) = takeWhile p l := by
simp_rw [takeWhile_takeWhile, and_self_iff, Bool.decide_coe]
#align list.take_while_idem List.takeWhile_idem
end Filter
/-! ### erasep -/
section eraseP
variable {p : α → Bool}
#align list.erasep_nil List.eraseP_nilₓ -- prop -> bool
#align list.erasep_cons List.eraseP_consₓ -- prop -> bool
#align list.erasep_cons_of_pos List.eraseP_cons_of_posₓ -- prop -> bool
#align list.erasep_cons_of_neg List.eraseP_cons_of_negₓ -- prop -> bool
#align list.erasep_of_forall_not List.eraseP_of_forall_notₓ -- prop -> bool
#align list.exists_of_erasep List.exists_of_erasePₓ -- prop -> bool
#align list.exists_or_eq_self_of_erasep List.exists_or_eq_self_of_erasePₓ -- prop -> bool
#align list.length_erasep_of_mem List.length_eraseP_of_memₓ -- prop -> bool
@[simp]
theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) :
(l.eraseP p).length + 1 = l.length := by
let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa
rw [h₂, h₁, length_append, length_append]
rfl
#align list.length_erasep_add_one List.length_eraseP_add_oneₓ -- prop -> bool
#align list.erasep_append_left List.eraseP_append_leftₓ -- prop -> bool
#align list.erasep_append_right List.eraseP_append_rightₓ -- prop -> bool
#align list.erasep_sublist List.eraseP_sublistₓ -- prop -> bool
#align list.erasep_subset List.eraseP_subsetₓ -- prop -> bool
#align list.sublist.erasep List.Sublist.erasePₓ -- prop -> bool
#align list.mem_of_mem_erasep List.mem_of_mem_erasePₓ -- prop -> bool
#align list.mem_erasep_of_neg List.mem_eraseP_of_negₓ -- prop -> bool
#align list.erasep_map List.eraseP_mapₓ -- prop -> bool
#align list.extractp_eq_find_erasep List.extractP_eq_find?_erasePₓ -- prop -> bool
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
#align list.erase_nil List.erase_nil
#align list.erase_cons List.erase_consₓ -- DecidableEq -> BEq
#align list.erase_cons_head List.erase_cons_headₓ -- DecidableEq -> BEq
#align list.erase_cons_tail List.erase_cons_tailₓ -- DecidableEq -> BEq
#align list.erase_eq_erasep List.erase_eq_erasePₓ -- DecidableEq -> BEq
#align list.erase_of_not_mem List.erase_of_not_memₓ -- DecidableEq -> BEq
#align list.exists_erase_eq List.exists_erase_eqₓ -- DecidableEq -> BEq
#align list.length_erase_of_mem List.length_erase_of_memₓ -- DecidableEq -> BEq
@[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) :
(l.erase a).length + 1 = l.length := by
rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)]
#align list.length_erase_add_one List.length_erase_add_oneₓ -- DecidableEq -> BEq
#align list.erase_append_left List.erase_append_leftₓ -- DecidableEq -> BEq
#align list.erase_append_right List.erase_append_rightₓ -- DecidableEq -> BEq
#align list.erase_sublist List.erase_sublistₓ -- DecidableEq -> BEq
#align list.erase_subset List.erase_subsetₓ -- DecidableEq -> BEq
#align list.sublist.erase List.Sublist.eraseₓ -- DecidableEq -> BEq
#align list.mem_of_mem_erase List.mem_of_mem_eraseₓ -- DecidableEq -> BEq
#align list.mem_erase_of_ne List.mem_erase_of_neₓ -- DecidableEq -> BEq
#align list.erase_comm List.erase_commₓ -- DecidableEq -> BEq
| Mathlib/Data/List/Basic.lean | 3,125 | 3,128 | theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) :
map f (l.erase a) = (map f l).erase (f a) := by |
have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff]
rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl
|
/-
Copyright (c) 2021 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Star.Subalgebra
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.Tactic.NoncommRing
#align_import algebra.algebra.spectrum from "leanprover-community/mathlib"@"58a272265b5e05f258161260dd2c5d247213cbd3"
/-!
# Spectrum of an element in an algebra
This file develops the basic theory of the spectrum of an element of an algebra.
This theory will serve as the foundation for spectral theory in Banach algebras.
## Main definitions
* `resolventSet a : Set R`: the resolvent set of an element `a : A` where
`A` is an `R`-algebra.
* `spectrum a : Set R`: the spectrum of an element `a : A` where
`A` is an `R`-algebra.
* `resolvent : R → A`: the resolvent function is `fun r ↦ Ring.inverse (↑ₐr - a)`, and hence
when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - a)`.
## Main statements
* `spectrum.unit_smul_eq_smul` and `spectrum.smul_eq_smul`: units in the scalar ring commute
(multiplication) with the spectrum, and over a field even `0` commutes with the spectrum.
* `spectrum.left_add_coset_eq`: elements of the scalar ring commute (addition) with the spectrum.
* `spectrum.unit_mem_mul_iff_mem_swap_mul` and `spectrum.preimage_units_mul_eq_swap_mul`: the
units (of `R`) in `σ (a*b)` coincide with those in `σ (b*a)`.
* `spectrum.scalar_eq`: in a nontrivial algebra over a field, the spectrum of a scalar is
a singleton.
## Notations
* `σ a` : `spectrum R a` of `a : A`
-/
open Set
open scoped Pointwise
universe u v
section Defs
variable (R : Type u) {A : Type v}
variable [CommSemiring R] [Ring A] [Algebra R A]
local notation "↑ₐ" => algebraMap R A
-- definition and basic properties
/-- Given a commutative ring `R` and an `R`-algebra `A`, the *resolvent set* of `a : A`
is the `Set R` consisting of those `r : R` for which `r•1 - a` is a unit of the
algebra `A`. -/
def resolventSet (a : A) : Set R :=
{r : R | IsUnit (↑ₐ r - a)}
#align resolvent_set resolventSet
/-- Given a commutative ring `R` and an `R`-algebra `A`, the *spectrum* of `a : A`
is the `Set R` consisting of those `r : R` for which `r•1 - a` is not a unit of the
algebra `A`.
The spectrum is simply the complement of the resolvent set. -/
def spectrum (a : A) : Set R :=
(resolventSet R a)ᶜ
#align spectrum spectrum
variable {R}
/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is
a map `R → A` which sends `r : R` to `(algebraMap R A r - a)⁻¹` when
`r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/
noncomputable def resolvent (a : A) (r : R) : A :=
Ring.inverse (↑ₐ r - a)
#align resolvent resolvent
/-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/
@[simps]
noncomputable def IsUnit.subInvSMul {r : Rˣ} {s : R} {a : A} (h : IsUnit <| r • ↑ₐ s - a) : Aˣ where
val := ↑ₐ s - r⁻¹ • a
inv := r • ↑h.unit⁻¹
val_inv := by rw [mul_smul_comm, ← smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_val_inv]
inv_val := by rw [smul_mul_assoc, ← mul_smul_comm, smul_sub, smul_inv_smul, h.val_inv_mul]
#align is_unit.sub_inv_smul IsUnit.subInvSMul
#align is_unit.coe_sub_inv_smul IsUnit.val_subInvSMul
#align is_unit.coe_inv_sub_inv_smul IsUnit.val_inv_subInvSMul
end Defs
namespace spectrum
section ScalarSemiring
variable {R : Type u} {A : Type v}
variable [CommSemiring R] [Ring A] [Algebra R A]
local notation "σ" => spectrum R
local notation "↑ₐ" => algebraMap R A
theorem mem_iff {r : R} {a : A} : r ∈ σ a ↔ ¬IsUnit (↑ₐ r - a) :=
Iff.rfl
#align spectrum.mem_iff spectrum.mem_iff
theorem not_mem_iff {r : R} {a : A} : r ∉ σ a ↔ IsUnit (↑ₐ r - a) := by
apply not_iff_not.mp
simp [Set.not_not_mem, mem_iff]
#align spectrum.not_mem_iff spectrum.not_mem_iff
variable (R)
theorem zero_mem_iff {a : A} : (0 : R) ∈ σ a ↔ ¬IsUnit a := by
rw [mem_iff, map_zero, zero_sub, IsUnit.neg_iff]
#align spectrum.zero_mem_iff spectrum.zero_mem_iff
alias ⟨not_isUnit_of_zero_mem, zero_mem⟩ := spectrum.zero_mem_iff
theorem zero_not_mem_iff {a : A} : (0 : R) ∉ σ a ↔ IsUnit a := by
rw [zero_mem_iff, Classical.not_not]
#align spectrum.zero_not_mem_iff spectrum.zero_not_mem_iff
alias ⟨isUnit_of_zero_not_mem, zero_not_mem⟩ := spectrum.zero_not_mem_iff
lemma subset_singleton_zero_compl {a : A} (ha : IsUnit a) : spectrum R a ⊆ {0}ᶜ :=
Set.subset_compl_singleton_iff.mpr <| spectrum.zero_not_mem R ha
variable {R}
theorem mem_resolventSet_of_left_right_inverse {r : R} {a b c : A} (h₁ : (↑ₐ r - a) * b = 1)
(h₂ : c * (↑ₐ r - a) = 1) : r ∈ resolventSet R a :=
Units.isUnit ⟨↑ₐ r - a, b, h₁, by rwa [← left_inv_eq_right_inv h₂ h₁]⟩
#align spectrum.mem_resolvent_set_of_left_right_inverse spectrum.mem_resolventSet_of_left_right_inverse
theorem mem_resolventSet_iff {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (↑ₐ r - a) :=
Iff.rfl
#align spectrum.mem_resolvent_set_iff spectrum.mem_resolventSet_iff
@[simp]
theorem algebraMap_mem_iff (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S]
[Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} {r : R} :
algebraMap R S r ∈ spectrum S a ↔ r ∈ spectrum R a := by
simp only [spectrum.mem_iff, Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul]
protected alias ⟨of_algebraMap_mem, algebraMap_mem⟩ := spectrum.algebraMap_mem_iff
@[simp]
theorem preimage_algebraMap (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S]
[Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} :
algebraMap R S ⁻¹' spectrum S a = spectrum R a :=
Set.ext fun _ => spectrum.algebraMap_mem_iff _
@[simp]
theorem resolventSet_of_subsingleton [Subsingleton A] (a : A) : resolventSet R a = Set.univ := by
simp_rw [resolventSet, Subsingleton.elim (algebraMap R A _ - a) 1, isUnit_one, Set.setOf_true]
#align spectrum.resolvent_set_of_subsingleton spectrum.resolventSet_of_subsingleton
@[simp]
theorem of_subsingleton [Subsingleton A] (a : A) : spectrum R a = ∅ := by
rw [spectrum, resolventSet_of_subsingleton, Set.compl_univ]
#align spectrum.of_subsingleton spectrum.of_subsingleton
theorem resolvent_eq {a : A} {r : R} (h : r ∈ resolventSet R a) : resolvent a r = ↑h.unit⁻¹ :=
Ring.inverse_unit h.unit
#align spectrum.resolvent_eq spectrum.resolvent_eq
theorem units_smul_resolvent {r : Rˣ} {s : R} {a : A} :
r • resolvent a (s : R) = resolvent (r⁻¹ • a) (r⁻¹ • s : R) := by
by_cases h : s ∈ spectrum R a
· rw [mem_iff] at h
simp only [resolvent, Algebra.algebraMap_eq_smul_one] at *
rw [smul_assoc, ← smul_sub]
have h' : ¬IsUnit (r⁻¹ • (s • (1 : A) - a)) := fun hu =>
h (by simpa only [smul_inv_smul] using IsUnit.smul r hu)
simp only [Ring.inverse_non_unit _ h, Ring.inverse_non_unit _ h', smul_zero]
· simp only [resolvent]
have h' : IsUnit (r • algebraMap R A (r⁻¹ • s) - a) := by
simpa [Algebra.algebraMap_eq_smul_one, smul_assoc] using not_mem_iff.mp h
rw [← h'.val_subInvSMul, ← (not_mem_iff.mp h).unit_spec, Ring.inverse_unit, Ring.inverse_unit,
h'.val_inv_subInvSMul]
simp only [Algebra.algebraMap_eq_smul_one, smul_assoc, smul_inv_smul]
#align spectrum.units_smul_resolvent spectrum.units_smul_resolvent
theorem units_smul_resolvent_self {r : Rˣ} {a : A} :
r • resolvent a (r : R) = resolvent (r⁻¹ • a) (1 : R) := by
simpa only [Units.smul_def, Algebra.id.smul_eq_mul, Units.inv_mul] using
@units_smul_resolvent _ _ _ _ _ r r a
#align spectrum.units_smul_resolvent_self spectrum.units_smul_resolvent_self
/-- The resolvent is a unit when the argument is in the resolvent set. -/
theorem isUnit_resolvent {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (resolvent a r) :=
isUnit_ring_inverse.symm
#align spectrum.is_unit_resolvent spectrum.isUnit_resolvent
theorem inv_mem_resolventSet {r : Rˣ} {a : Aˣ} (h : (r : R) ∈ resolventSet R (a : A)) :
(↑r⁻¹ : R) ∈ resolventSet R (↑a⁻¹ : A) := by
rw [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one, ← Units.smul_def] at h ⊢
rw [IsUnit.smul_sub_iff_sub_inv_smul, inv_inv, IsUnit.sub_iff]
have h₁ : (a : A) * (r • (↑a⁻¹ : A) - 1) = r • (1 : A) - a := by
rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one]
have h₂ : (r • (↑a⁻¹ : A) - 1) * a = r • (1 : A) - a := by
rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul]
have hcomm : Commute (a : A) (r • (↑a⁻¹ : A) - 1) := by rwa [← h₂] at h₁
exact (hcomm.isUnit_mul_iff.mp (h₁.symm ▸ h)).2
#align spectrum.inv_mem_resolvent_set spectrum.inv_mem_resolventSet
theorem inv_mem_iff {r : Rˣ} {a : Aˣ} : (r : R) ∈ σ (a : A) ↔ (↑r⁻¹ : R) ∈ σ (↑a⁻¹ : A) :=
not_iff_not.2 <| ⟨inv_mem_resolventSet, inv_mem_resolventSet⟩
#align spectrum.inv_mem_iff spectrum.inv_mem_iff
theorem zero_mem_resolventSet_of_unit (a : Aˣ) : 0 ∈ resolventSet R (a : A) := by
simpa only [mem_resolventSet_iff, ← not_mem_iff, zero_not_mem_iff] using a.isUnit
#align spectrum.zero_mem_resolvent_set_of_unit spectrum.zero_mem_resolventSet_of_unit
theorem ne_zero_of_mem_of_unit {a : Aˣ} {r : R} (hr : r ∈ σ (a : A)) : r ≠ 0 := fun hn =>
(hn ▸ hr) (zero_mem_resolventSet_of_unit a)
#align spectrum.ne_zero_of_mem_of_unit spectrum.ne_zero_of_mem_of_unit
theorem add_mem_iff {a : A} {r s : R} : r + s ∈ σ a ↔ r ∈ σ (-↑ₐ s + a) := by
simp only [mem_iff, sub_neg_eq_add, ← sub_sub, map_add]
#align spectrum.add_mem_iff spectrum.add_mem_iff
| Mathlib/Algebra/Algebra/Spectrum.lean | 226 | 227 | theorem add_mem_add_iff {a : A} {r s : R} : r + s ∈ σ (↑ₐ s + a) ↔ r ∈ σ a := by |
rw [add_mem_iff, neg_add_cancel_left]
|
/-
Copyright (c) 2022 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Data.Complex.Basic
import Mathlib.MeasureTheory.Integral.CircleIntegral
#align_import measure_theory.integral.circle_transform from "leanprover-community/mathlib"@"d11893b411025250c8e61ff2f12ccbd7ee35ab15"
/-!
# Circle integral transform
In this file we define the circle integral transform of a function `f` with complex domain. This is
defined as $(2πi)^{-1}\frac{f(x)}{x-w}$ where `x` moves along a circle. We then prove some basic
facts about these functions.
These results are useful for proving that the uniform limit of a sequence of holomorphic functions
is holomorphic.
-/
open Set MeasureTheory Metric Filter Function
open scoped Interval Real
noncomputable section
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] (R : ℝ) (z w : ℂ)
namespace Complex
/-- Given a function `f : ℂ → E`, `circleTransform R z w f` is the function mapping `θ` to
`(2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • ((circleMap z R θ) - w)⁻¹ • f (circleMap z R θ)`.
If `f` is differentiable and `w` is in the interior of the ball, then the integral from `0` to
`2 * π` of this gives the value `f(w)`. -/
def circleTransform (f : ℂ → E) (θ : ℝ) : E :=
(2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • (circleMap z R θ - w)⁻¹ • f (circleMap z R θ)
#align complex.circle_transform Complex.circleTransform
/-- The derivative of `circleTransform` w.r.t `w`. -/
def circleTransformDeriv (f : ℂ → E) (θ : ℝ) : E :=
(2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • ((circleMap z R θ - w) ^ 2)⁻¹ • f (circleMap z R θ)
#align complex.circle_transform_deriv Complex.circleTransformDeriv
theorem circleTransformDeriv_periodic (f : ℂ → E) :
Periodic (circleTransformDeriv R z w f) (2 * π) := by
have := periodic_circleMap
simp_rw [Periodic] at *
intro x
simp_rw [circleTransformDeriv, this]
congr 2
simp [this]
#align complex.circle_transform_deriv_periodic Complex.circleTransformDeriv_periodic
theorem circleTransformDeriv_eq (f : ℂ → E) : circleTransformDeriv R z w f =
fun θ => (circleMap z R θ - w)⁻¹ • circleTransform R z w f θ := by
ext
simp_rw [circleTransformDeriv, circleTransform, ← mul_smul, ← mul_assoc]
ring_nf
rw [inv_pow]
congr
ring
#align complex.circle_transform_deriv_eq Complex.circleTransformDeriv_eq
theorem integral_circleTransform (f : ℂ → E) :
(∫ θ : ℝ in (0)..2 * π, circleTransform R z w f θ) =
(2 * ↑π * I)⁻¹ • ∮ z in C(z, R), (z - w)⁻¹ • f z := by
simp_rw [circleTransform, circleIntegral, deriv_circleMap, circleMap]
simp
#align complex.integral_circle_transform Complex.integral_circleTransform
theorem continuous_circleTransform {R : ℝ} (hR : 0 < R) {f : ℂ → E} {z w : ℂ}
(hf : ContinuousOn f <| sphere z R) (hw : w ∈ ball z R) :
Continuous (circleTransform R z w f) := by
apply_rules [Continuous.smul, continuous_const]
· simp_rw [deriv_circleMap]
apply_rules [Continuous.mul, continuous_circleMap 0 R, continuous_const]
· exact continuous_circleMap_inv hw
· apply ContinuousOn.comp_continuous hf (continuous_circleMap z R)
exact fun _ => (circleMap_mem_sphere _ hR.le) _
#align complex.continuous_circle_transform Complex.continuous_circleTransform
theorem continuous_circleTransformDeriv {R : ℝ} (hR : 0 < R) {f : ℂ → E} {z w : ℂ}
(hf : ContinuousOn f (sphere z R)) (hw : w ∈ ball z R) :
Continuous (circleTransformDeriv R z w f) := by
rw [circleTransformDeriv_eq]
exact (continuous_circleMap_inv hw).smul (continuous_circleTransform hR hf hw)
#align complex.continuous_circle_transform_deriv Complex.continuous_circleTransformDeriv
/-- A useful bound for circle integrals (with complex codomain)-/
def circleTransformBoundingFunction (R : ℝ) (z : ℂ) (w : ℂ × ℝ) : ℂ :=
circleTransformDeriv R z w.1 (fun _ => 1) w.2
#align complex.circle_transform_bounding_function Complex.circleTransformBoundingFunction
theorem continuousOn_prod_circle_transform_function {R r : ℝ} (hr : r < R) {z : ℂ} :
ContinuousOn (fun w : ℂ × ℝ => (circleMap z R w.snd - w.fst)⁻¹ ^ 2)
(closedBall z r ×ˢ univ) := by
simp_rw [← one_div]
apply_rules [ContinuousOn.pow, ContinuousOn.div, continuousOn_const]
· exact ((continuous_circleMap z R).comp_continuousOn continuousOn_snd).sub continuousOn_fst
· rintro ⟨a, b⟩ ⟨ha, -⟩
have ha2 : a ∈ ball z R := closedBall_subset_ball hr ha
exact sub_ne_zero.2 (circleMap_ne_mem_ball ha2 b)
#align complex.continuous_on_prod_circle_transform_function Complex.continuousOn_prod_circle_transform_function
theorem continuousOn_abs_circleTransformBoundingFunction {R r : ℝ} (hr : r < R) (z : ℂ) :
ContinuousOn (abs ∘ circleTransformBoundingFunction R z) (closedBall z r ×ˢ univ) := by
have : ContinuousOn (circleTransformBoundingFunction R z) (closedBall z r ×ˢ univ) := by
apply_rules [ContinuousOn.smul, continuousOn_const]
· simp only [deriv_circleMap]
apply_rules [ContinuousOn.mul, (continuous_circleMap 0 R).comp_continuousOn continuousOn_snd,
continuousOn_const]
· simpa only [inv_pow] using continuousOn_prod_circle_transform_function hr
exact this.norm
#align complex.continuous_on_abs_circle_transform_bounding_function Complex.continuousOn_abs_circleTransformBoundingFunction
theorem abs_circleTransformBoundingFunction_le {R r : ℝ} (hr : r < R) (hr' : 0 ≤ r) (z : ℂ) :
∃ x : closedBall z r ×ˢ [[0, 2 * π]], ∀ y : closedBall z r ×ˢ [[0, 2 * π]],
abs (circleTransformBoundingFunction R z y) ≤ abs (circleTransformBoundingFunction R z x) := by
have cts := continuousOn_abs_circleTransformBoundingFunction hr z
have comp : IsCompact (closedBall z r ×ˢ [[0, 2 * π]]) := by
apply_rules [IsCompact.prod, ProperSpace.isCompact_closedBall z r, isCompact_uIcc]
have none : (closedBall z r ×ˢ [[0, 2 * π]]).Nonempty :=
(nonempty_closedBall.2 hr').prod nonempty_uIcc
have := IsCompact.exists_isMaxOn comp none (cts.mono <| prod_mono_right (subset_univ _))
simpa [isMaxOn_iff] using this
#align complex.abs_circle_transform_bounding_function_le Complex.abs_circleTransformBoundingFunction_le
/-- The derivative of a `circleTransform` is locally bounded. -/
| Mathlib/MeasureTheory/Integral/CircleTransform.lean | 133 | 152 | theorem circleTransformDeriv_bound {R : ℝ} (hR : 0 < R) {z x : ℂ} {f : ℂ → ℂ} (hx : x ∈ ball z R)
(hf : ContinuousOn f (sphere z R)) : ∃ B ε : ℝ, 0 < ε ∧
ball x ε ⊆ ball z R ∧ ∀ (t : ℝ), ∀ y ∈ ball x ε, ‖circleTransformDeriv R z y f t‖ ≤ B := by |
obtain ⟨r, hr, hrx⟩ := exists_lt_mem_ball_of_mem_ball hx
obtain ⟨ε', hε', H⟩ := exists_ball_subset_ball hrx
obtain ⟨⟨⟨a, b⟩, ⟨ha, hb⟩⟩, hab⟩ :=
abs_circleTransformBoundingFunction_le hr (pos_of_mem_ball hrx).le z
let V : ℝ → ℂ → ℂ := fun θ w => circleTransformDeriv R z w (fun _ => 1) θ
obtain ⟨X, -, HX2⟩ := (isCompact_sphere z R).exists_isMaxOn
(NormedSpace.sphere_nonempty.2 hR.le) hf.norm
refine ⟨abs (V b a) * abs (f X), ε', hε', H.trans (ball_subset_ball hr.le), fun y v hv ↦ ?_⟩
obtain ⟨y1, hy1, hfun⟩ :=
Periodic.exists_mem_Ico₀ (circleTransformDeriv_periodic R z v f) Real.two_pi_pos y
have hy2 : y1 ∈ [[0, 2 * π]] := Icc_subset_uIcc <| Ico_subset_Icc_self hy1
simp only [isMaxOn_iff, mem_sphere_iff_norm, norm_eq_abs] at HX2
have := mul_le_mul (hab ⟨⟨v, y1⟩, ⟨ball_subset_closedBall (H hv), hy2⟩⟩)
(HX2 (circleMap z R y1) (circleMap_mem_sphere z hR.le y1)) (Complex.abs.nonneg _)
(Complex.abs.nonneg _)
rw [hfun]
simpa [V, circleTransformBoundingFunction, circleTransformDeriv, mul_assoc] using this
|
/-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Alexey Soloyev, Junyan Xu, Kamila Szewczyk
-/
import Mathlib.Data.Real.Irrational
import Mathlib.Data.Nat.Fib.Basic
import Mathlib.Data.Fin.VecNotation
import Mathlib.Algebra.LinearRecurrence
import Mathlib.Tactic.NormNum.NatFib
import Mathlib.Tactic.NormNum.Prime
#align_import data.real.golden_ratio from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2"
/-!
# The golden ratio and its conjugate
This file defines the golden ratio `φ := (1 + √5)/2` and its conjugate
`ψ := (1 - √5)/2`, which are the two real roots of `X² - X - 1`.
Along with various computational facts about them, we prove their
irrationality, and we link them to the Fibonacci sequence by proving
Binet's formula.
-/
noncomputable section
open Polynomial
/-- The golden ratio `φ := (1 + √5)/2`. -/
abbrev goldenRatio : ℝ := (1 + √5) / 2
#align golden_ratio goldenRatio
/-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/
abbrev goldenConj : ℝ := (1 - √5) / 2
#align golden_conj goldenConj
@[inherit_doc goldenRatio] scoped[goldenRatio] notation "φ" => goldenRatio
@[inherit_doc goldenConj] scoped[goldenRatio] notation "ψ" => goldenConj
open Real goldenRatio
/-- The inverse of the golden ratio is the opposite of its conjugate. -/
theorem inv_gold : φ⁻¹ = -ψ := by
have : 1 + √5 ≠ 0 := ne_of_gt (add_pos (by norm_num) <| Real.sqrt_pos.mpr (by norm_num))
field_simp [sub_mul, mul_add]
norm_num
#align inv_gold inv_gold
/-- The opposite of the golden ratio is the inverse of its conjugate. -/
theorem inv_goldConj : ψ⁻¹ = -φ := by
rw [inv_eq_iff_eq_inv, ← neg_inv, ← neg_eq_iff_eq_neg]
exact inv_gold.symm
#align inv_gold_conj inv_goldConj
@[simp]
theorem gold_mul_goldConj : φ * ψ = -1 := by
field_simp
rw [← sq_sub_sq]
norm_num
#align gold_mul_gold_conj gold_mul_goldConj
@[simp]
theorem goldConj_mul_gold : ψ * φ = -1 := by
rw [mul_comm]
exact gold_mul_goldConj
#align gold_conj_mul_gold goldConj_mul_gold
@[simp]
| Mathlib/Data/Real/GoldenRatio.lean | 70 | 72 | theorem gold_add_goldConj : φ + ψ = 1 := by |
rw [goldenRatio, goldenConj]
ring
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Scott Morrison
-/
import Mathlib.AlgebraicGeometry.PrimeSpectrum.Basic
import Mathlib.Algebra.Category.Ring.Colimits
import Mathlib.Algebra.Category.Ring.Limits
import Mathlib.Topology.Sheaves.LocalPredicate
import Mathlib.RingTheory.Localization.AtPrime
import Mathlib.Algebra.Ring.Subring.Basic
#align_import algebraic_geometry.structure_sheaf from "leanprover-community/mathlib"@"5dc6092d09e5e489106865241986f7f2ad28d4c8"
/-!
# The structure sheaf on `PrimeSpectrum R`.
We define the structure sheaf on `TopCat.of (PrimeSpectrum R)`, for a commutative ring `R` and prove
basic properties about it. We define this as a subsheaf of the sheaf of dependent functions into the
localizations, cut out by the condition that the function must be locally equal to a ratio of
elements of `R`.
Because the condition "is equal to a fraction" passes to smaller open subsets,
the subset of functions satisfying this condition is automatically a subpresheaf.
Because the condition "is locally equal to a fraction" is local,
it is also a subsheaf.
(It may be helpful to refer back to `Mathlib/Topology/Sheaves/SheafOfFunctions.lean`,
where we show that dependent functions into any type family form a sheaf,
and also `Mathlib/Topology/Sheaves/LocalPredicate.lean`, where we characterise the predicates
which pick out sub-presheaves and sub-sheaves of these sheaves.)
We also set up the ring structure, obtaining
`structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R)`.
We then construct two basic isomorphisms, relating the structure sheaf to the underlying ring `R`.
First, `StructureSheaf.stalkIso` gives an isomorphism between the stalk of the structure sheaf
at a point `p` and the localization of `R` at the prime ideal `p`. Second,
`StructureSheaf.basicOpenIso` gives an isomorphism between the structure sheaf on `basicOpen f`
and the localization of `R` at the submonoid of powers of `f`.
## References
* [Robin Hartshorne, *Algebraic Geometry*][Har77]
-/
universe u
noncomputable section
variable (R : Type u) [CommRing R]
open TopCat
open TopologicalSpace
open CategoryTheory
open Opposite
namespace AlgebraicGeometry
/-- The prime spectrum, just as a topological space.
-/
def PrimeSpectrum.Top : TopCat :=
TopCat.of (PrimeSpectrum R)
set_option linter.uppercaseLean3 false in
#align algebraic_geometry.prime_spectrum.Top AlgebraicGeometry.PrimeSpectrum.Top
namespace StructureSheaf
/-- The type family over `PrimeSpectrum R` consisting of the localization over each point.
-/
def Localizations (P : PrimeSpectrum.Top R) : Type u :=
Localization.AtPrime P.asIdeal
#align algebraic_geometry.structure_sheaf.localizations AlgebraicGeometry.StructureSheaf.Localizations
-- Porting note: can't derive `CommRingCat`
instance commRingLocalizations (P : PrimeSpectrum.Top R) : CommRing <| Localizations R P :=
inferInstanceAs <| CommRing <| Localization.AtPrime P.asIdeal
-- Porting note: can't derive `LocalRing`
instance localRingLocalizations (P : PrimeSpectrum.Top R) : LocalRing <| Localizations R P :=
inferInstanceAs <| LocalRing <| Localization.AtPrime P.asIdeal
instance (P : PrimeSpectrum.Top R) : Inhabited (Localizations R P) :=
⟨1⟩
instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : Algebra R (Localizations R x) :=
inferInstanceAs <| Algebra R (Localization.AtPrime x.1.asIdeal)
instance (U : Opens (PrimeSpectrum.Top R)) (x : U) :
IsLocalization.AtPrime (Localizations R x) (x : PrimeSpectrum.Top R).asIdeal :=
Localization.isLocalization
variable {R}
/-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction
`r / s` in each of the stalks (which are localizations at various prime ideals).
-/
def IsFraction {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : Prop :=
∃ r s : R, ∀ x : U, ¬s ∈ x.1.asIdeal ∧ f x * algebraMap _ _ s = algebraMap _ _ r
#align algebraic_geometry.structure_sheaf.is_fraction AlgebraicGeometry.StructureSheaf.IsFraction
theorem IsFraction.eq_mk' {U : Opens (PrimeSpectrum.Top R)} {f : ∀ x : U, Localizations R x}
(hf : IsFraction f) :
∃ r s : R,
∀ x : U,
∃ hs : s ∉ x.1.asIdeal,
f x =
IsLocalization.mk' (Localization.AtPrime _) r
(⟨s, hs⟩ : (x : PrimeSpectrum.Top R).asIdeal.primeCompl) := by
rcases hf with ⟨r, s, h⟩
refine ⟨r, s, fun x => ⟨(h x).1, (IsLocalization.mk'_eq_iff_eq_mul.mpr ?_).symm⟩⟩
exact (h x).2.symm
#align algebraic_geometry.structure_sheaf.is_fraction.eq_mk' AlgebraicGeometry.StructureSheaf.IsFraction.eq_mk'
variable (R)
/-- The predicate `IsFraction` is "prelocal",
in the sense that if it holds on `U` it holds on any open subset `V` of `U`.
-/
def isFractionPrelocal : PrelocalPredicate (Localizations R) where
pred {U} f := IsFraction f
res := by rintro V U i f ⟨r, s, w⟩; exact ⟨r, s, fun x => w (i x)⟩
#align algebraic_geometry.structure_sheaf.is_fraction_prelocal AlgebraicGeometry.StructureSheaf.isFractionPrelocal
/-- We will define the structure sheaf as
the subsheaf of all dependent functions in `Π x : U, Localizations R x`
consisting of those functions which can locally be expressed as a ratio of
(the images in the localization of) elements of `R`.
Quoting Hartshorne:
For an open set $U ⊆ Spec A$, we define $𝒪(U)$ to be the set of functions
$s : U → ⨆_{𝔭 ∈ U} A_𝔭$, such that $s(𝔭) ∈ A_𝔭$ for each $𝔭$,
and such that $s$ is locally a quotient of elements of $A$:
to be precise, we require that for each $𝔭 ∈ U$, there is a neighborhood $V$ of $𝔭$,
contained in $U$, and elements $a, f ∈ A$, such that for each $𝔮 ∈ V, f ∉ 𝔮$,
and $s(𝔮) = a/f$ in $A_𝔮$.
Now Hartshorne had the disadvantage of not knowing about dependent functions,
so we replace his circumlocution about functions into a disjoint union with
`Π x : U, Localizations x`.
-/
def isLocallyFraction : LocalPredicate (Localizations R) :=
(isFractionPrelocal R).sheafify
#align algebraic_geometry.structure_sheaf.is_locally_fraction AlgebraicGeometry.StructureSheaf.isLocallyFraction
@[simp]
theorem isLocallyFraction_pred {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) :
(isLocallyFraction R).pred f =
∀ x : U,
∃ (V : _) (_ : x.1 ∈ V) (i : V ⟶ U),
∃ r s : R,
∀ y : V, ¬s ∈ y.1.asIdeal ∧ f (i y : U) * algebraMap _ _ s = algebraMap _ _ r :=
rfl
#align algebraic_geometry.structure_sheaf.is_locally_fraction_pred AlgebraicGeometry.StructureSheaf.isLocallyFraction_pred
/-- The functions satisfying `isLocallyFraction` form a subring.
-/
def sectionsSubring (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) :
Subring (∀ x : U.unop, Localizations R x) where
carrier := { f | (isLocallyFraction R).pred f }
zero_mem' := by
refine fun x => ⟨unop U, x.2, 𝟙 _, 0, 1, fun y => ⟨?_, ?_⟩⟩
· rw [← Ideal.ne_top_iff_one]; exact y.1.IsPrime.1
· simp
one_mem' := by
refine fun x => ⟨unop U, x.2, 𝟙 _, 1, 1, fun y => ⟨?_, ?_⟩⟩
· rw [← Ideal.ne_top_iff_one]; exact y.1.IsPrime.1
· simp
add_mem' := by
intro a b ha hb x
rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩
rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩
refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * sb + rb * sa, sa * sb, ?_⟩
intro y
rcases wa (Opens.infLELeft _ _ y) with ⟨nma, wa⟩
rcases wb (Opens.infLERight _ _ y) with ⟨nmb, wb⟩
fconstructor
· intro H; cases y.1.IsPrime.mem_or_mem H <;> contradiction
· simp only [add_mul, RingHom.map_add, Pi.add_apply, RingHom.map_mul]
erw [← wa, ← wb]
simp only [mul_assoc]
congr 2
rw [mul_comm]
neg_mem' := by
intro a ha x
rcases ha x with ⟨V, m, i, r, s, w⟩
refine ⟨V, m, i, -r, s, ?_⟩
intro y
rcases w y with ⟨nm, w⟩
fconstructor
· exact nm
· simp only [RingHom.map_neg, Pi.neg_apply]
erw [← w]
simp only [neg_mul]
mul_mem' := by
intro a b ha hb x
rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩
rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩
refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * rb, sa * sb, ?_⟩
intro y
rcases wa (Opens.infLELeft _ _ y) with ⟨nma, wa⟩
rcases wb (Opens.infLERight _ _ y) with ⟨nmb, wb⟩
fconstructor
· intro H; cases y.1.IsPrime.mem_or_mem H <;> contradiction
· simp only [Pi.mul_apply, RingHom.map_mul]
erw [← wa, ← wb]
simp only [mul_left_comm, mul_assoc, mul_comm]
#align algebraic_geometry.structure_sheaf.sections_subring AlgebraicGeometry.StructureSheaf.sectionsSubring
end StructureSheaf
open StructureSheaf
/-- The structure sheaf (valued in `Type`, not yet `CommRingCat`) is the subsheaf consisting of
functions satisfying `isLocallyFraction`.
-/
def structureSheafInType : Sheaf (Type u) (PrimeSpectrum.Top R) :=
subsheafToTypes (isLocallyFraction R)
#align algebraic_geometry.structure_sheaf_in_Type AlgebraicGeometry.structureSheafInType
instance commRingStructureSheafInTypeObj (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) :
CommRing ((structureSheafInType R).1.obj U) :=
(sectionsSubring R U).toCommRing
#align algebraic_geometry.comm_ring_structure_sheaf_in_Type_obj AlgebraicGeometry.commRingStructureSheafInTypeObj
open PrimeSpectrum
/-- The structure presheaf, valued in `CommRingCat`, constructed by dressing up the `Type` valued
structure presheaf.
-/
@[simps]
def structurePresheafInCommRing : Presheaf CommRingCat (PrimeSpectrum.Top R) where
obj U := CommRingCat.of ((structureSheafInType R).1.obj U)
map {U V} i :=
{ toFun := (structureSheafInType R).1.map i
map_zero' := rfl
map_add' := fun x y => rfl
map_one' := rfl
map_mul' := fun x y => rfl }
set_option linter.uppercaseLean3 false in
#align algebraic_geometry.structure_presheaf_in_CommRing AlgebraicGeometry.structurePresheafInCommRing
-- These lemmas have always been bad (#7657), but leanprover/lean4#2644 made `simp` start noticing
attribute [nolint simpNF] AlgebraicGeometry.structurePresheafInCommRing_map_apply
/-- Some glue, verifying that the structure presheaf valued in `CommRingCat` agrees
with the `Type` valued structure presheaf.
-/
def structurePresheafCompForget :
structurePresheafInCommRing R ⋙ forget CommRingCat ≅ (structureSheafInType R).1 :=
NatIso.ofComponents fun U => Iso.refl _
set_option linter.uppercaseLean3 false in
#align algebraic_geometry.structure_presheaf_comp_forget AlgebraicGeometry.structurePresheafCompForget
open TopCat.Presheaf
/-- The structure sheaf on $Spec R$, valued in `CommRingCat`.
This is provided as a bundled `SheafedSpace` as `Spec.SheafedSpace R` later.
-/
def Spec.structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R) :=
⟨structurePresheafInCommRing R,
(-- We check the sheaf condition under `forget CommRingCat`.
isSheaf_iff_isSheaf_comp
_ _).mpr
(isSheaf_of_iso (structurePresheafCompForget R).symm (structureSheafInType R).cond)⟩
set_option linter.uppercaseLean3 false in
#align algebraic_geometry.Spec.structure_sheaf AlgebraicGeometry.Spec.structureSheaf
open Spec (structureSheaf)
namespace StructureSheaf
@[simp]
theorem res_apply (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U)
(s : (structureSheaf R).1.obj (op U)) (x : V) :
((structureSheaf R).1.map i.op s).1 x = (s.1 (i x) : _) :=
rfl
#align algebraic_geometry.structure_sheaf.res_apply AlgebraicGeometry.StructureSheaf.res_apply
/-
Notation in this comment
X = Spec R
OX = structure sheaf
In the following we construct an isomorphism between OX_p and R_p given any point p corresponding
to a prime ideal in R.
We do this via 8 steps:
1. def const (f g : R) (V) (hv : V ≤ D_g) : OX(V) [for api]
2. def toOpen (U) : R ⟶ OX(U)
3. [2] def toStalk (p : Spec R) : R ⟶ OX_p
4. [2] def toBasicOpen (f : R) : R_f ⟶ OX(D_f)
5. [3] def localizationToStalk (p : Spec R) : R_p ⟶ OX_p
6. def openToLocalization (U) (p) (hp : p ∈ U) : OX(U) ⟶ R_p
7. [6] def stalkToFiberRingHom (p : Spec R) : OX_p ⟶ R_p
8. [5,7] def stalkIso (p : Spec R) : OX_p ≅ R_p
In the square brackets we list the dependencies of a construction on the previous steps.
-/
/-- The section of `structureSheaf R` on an open `U` sending each `x ∈ U` to the element
`f/g` in the localization of `R` at `x`. -/
def const (f g : R) (U : Opens (PrimeSpectrum.Top R))
(hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) :
(structureSheaf R).1.obj (op U) :=
⟨fun x => IsLocalization.mk' _ f ⟨g, hu x x.2⟩, fun x =>
⟨U, x.2, 𝟙 _, f, g, fun y => ⟨hu y y.2, IsLocalization.mk'_spec _ _ _⟩⟩⟩
#align algebraic_geometry.structure_sheaf.const AlgebraicGeometry.StructureSheaf.const
@[simp]
theorem const_apply (f g : R) (U : Opens (PrimeSpectrum.Top R))
(hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) :
(const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hu x x.2⟩ :=
rfl
#align algebraic_geometry.structure_sheaf.const_apply AlgebraicGeometry.StructureSheaf.const_apply
theorem const_apply' (f g : R) (U : Opens (PrimeSpectrum.Top R))
(hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U)
(hx : g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) :
(const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hx⟩ :=
rfl
#align algebraic_geometry.structure_sheaf.const_apply' AlgebraicGeometry.StructureSheaf.const_apply'
theorem exists_const (U) (s : (structureSheaf R).1.obj (op U)) (x : PrimeSpectrum.Top R)
(hx : x ∈ U) :
∃ (V : Opens (PrimeSpectrum.Top R)) (_ : x ∈ V) (i : V ⟶ U) (f g : R) (hg : _),
const R f g V hg = (structureSheaf R).1.map i.op s :=
let ⟨V, hxV, iVU, f, g, hfg⟩ := s.2 ⟨x, hx⟩
⟨V, hxV, iVU, f, g, fun y hyV => (hfg ⟨y, hyV⟩).1,
Subtype.eq <| funext fun y => IsLocalization.mk'_eq_iff_eq_mul.2 <| Eq.symm <| (hfg y).2⟩
#align algebraic_geometry.structure_sheaf.exists_const AlgebraicGeometry.StructureSheaf.exists_const
@[simp]
theorem res_const (f g : R) (U hu V hv i) :
(structureSheaf R).1.map i (const R f g U hu) = const R f g V hv :=
rfl
#align algebraic_geometry.structure_sheaf.res_const AlgebraicGeometry.StructureSheaf.res_const
theorem res_const' (f g : R) (V hv) :
(structureSheaf R).1.map (homOfLE hv).op (const R f g (PrimeSpectrum.basicOpen g) fun _ => id) =
const R f g V hv :=
rfl
#align algebraic_geometry.structure_sheaf.res_const' AlgebraicGeometry.StructureSheaf.res_const'
theorem const_zero (f : R) (U hu) : const R 0 f U hu = 0 :=
Subtype.eq <| funext fun x => IsLocalization.mk'_eq_iff_eq_mul.2 <| by
rw [RingHom.map_zero]
exact (mul_eq_zero_of_left rfl ((algebraMap R (Localizations R x)) _)).symm
#align algebraic_geometry.structure_sheaf.const_zero AlgebraicGeometry.StructureSheaf.const_zero
theorem const_self (f : R) (U hu) : const R f f U hu = 1 :=
Subtype.eq <| funext fun _ => IsLocalization.mk'_self _ _
#align algebraic_geometry.structure_sheaf.const_self AlgebraicGeometry.StructureSheaf.const_self
theorem const_one (U) : (const R 1 1 U fun _ _ => Submonoid.one_mem _) = 1 :=
const_self R 1 U _
#align algebraic_geometry.structure_sheaf.const_one AlgebraicGeometry.StructureSheaf.const_one
theorem const_add (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) :
const R f₁ g₁ U hu₁ + const R f₂ g₂ U hu₂ =
const R (f₁ * g₂ + f₂ * g₁) (g₁ * g₂) U fun x hx =>
Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) :=
Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_add _ _
⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩
#align algebraic_geometry.structure_sheaf.const_add AlgebraicGeometry.StructureSheaf.const_add
theorem const_mul (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) :
const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂ =
const R (f₁ * f₂) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) :=
Subtype.eq <|
funext fun x =>
Eq.symm <| IsLocalization.mk'_mul _ f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩
#align algebraic_geometry.structure_sheaf.const_mul AlgebraicGeometry.StructureSheaf.const_mul
theorem const_ext {f₁ f₂ g₁ g₂ : R} {U hu₁ hu₂} (h : f₁ * g₂ = f₂ * g₁) :
const R f₁ g₁ U hu₁ = const R f₂ g₂ U hu₂ :=
Subtype.eq <|
funext fun x =>
IsLocalization.mk'_eq_of_eq (by rw [mul_comm, Subtype.coe_mk, ← h, mul_comm, Subtype.coe_mk])
#align algebraic_geometry.structure_sheaf.const_ext AlgebraicGeometry.StructureSheaf.const_ext
theorem const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) :
const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by substs hf hg; rfl
#align algebraic_geometry.structure_sheaf.const_congr AlgebraicGeometry.StructureSheaf.const_congr
theorem const_mul_rev (f g : R) (U hu₁ hu₂) : const R f g U hu₁ * const R g f U hu₂ = 1 := by
rw [const_mul, const_congr R rfl (mul_comm g f), const_self]
#align algebraic_geometry.structure_sheaf.const_mul_rev AlgebraicGeometry.StructureSheaf.const_mul_rev
theorem const_mul_cancel (f g₁ g₂ : R) (U hu₁ hu₂) :
const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂ := by
rw [const_mul, const_ext]; rw [mul_assoc]
#align algebraic_geometry.structure_sheaf.const_mul_cancel AlgebraicGeometry.StructureSheaf.const_mul_cancel
theorem const_mul_cancel' (f g₁ g₂ : R) (U hu₁ hu₂) :
const R g₁ g₂ U hu₂ * const R f g₁ U hu₁ = const R f g₂ U hu₂ := by
rw [mul_comm, const_mul_cancel]
#align algebraic_geometry.structure_sheaf.const_mul_cancel' AlgebraicGeometry.StructureSheaf.const_mul_cancel'
/-- The canonical ring homomorphism interpreting an element of `R` as
a section of the structure sheaf. -/
def toOpen (U : Opens (PrimeSpectrum.Top R)) :
CommRingCat.of R ⟶ (structureSheaf R).1.obj (op U) where
toFun f :=
⟨fun x => algebraMap R _ f, fun x =>
⟨U, x.2, 𝟙 _, f, 1, fun y =>
⟨(Ideal.ne_top_iff_one _).1 y.1.2.1, by rw [RingHom.map_one, mul_one]⟩⟩⟩
map_one' := Subtype.eq <| funext fun x => RingHom.map_one _
map_mul' f g := Subtype.eq <| funext fun x => RingHom.map_mul _ _ _
map_zero' := Subtype.eq <| funext fun x => RingHom.map_zero _
map_add' f g := Subtype.eq <| funext fun x => RingHom.map_add _ _ _
#align algebraic_geometry.structure_sheaf.to_open AlgebraicGeometry.StructureSheaf.toOpen
@[simp]
theorem toOpen_res (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U) :
toOpen R U ≫ (structureSheaf R).1.map i.op = toOpen R V :=
rfl
#align algebraic_geometry.structure_sheaf.to_open_res AlgebraicGeometry.StructureSheaf.toOpen_res
@[simp]
theorem toOpen_apply (U : Opens (PrimeSpectrum.Top R)) (f : R) (x : U) :
(toOpen R U f).1 x = algebraMap _ _ f :=
rfl
#align algebraic_geometry.structure_sheaf.to_open_apply AlgebraicGeometry.StructureSheaf.toOpen_apply
theorem toOpen_eq_const (U : Opens (PrimeSpectrum.Top R)) (f : R) :
toOpen R U f = const R f 1 U fun x _ => (Ideal.ne_top_iff_one _).1 x.2.1 :=
Subtype.eq <| funext fun _ => Eq.symm <| IsLocalization.mk'_one _ f
#align algebraic_geometry.structure_sheaf.to_open_eq_const AlgebraicGeometry.StructureSheaf.toOpen_eq_const
/-- The canonical ring homomorphism interpreting an element of `R` as an element of
the stalk of `structureSheaf R` at `x`. -/
def toStalk (x : PrimeSpectrum.Top R) : CommRingCat.of R ⟶ (structureSheaf R).presheaf.stalk x :=
(toOpen R ⊤ ≫ (structureSheaf R).presheaf.germ ⟨x, by trivial⟩)
#align algebraic_geometry.structure_sheaf.to_stalk AlgebraicGeometry.StructureSheaf.toStalk
@[simp]
theorem toOpen_germ (U : Opens (PrimeSpectrum.Top R)) (x : U) :
toOpen R U ≫ (structureSheaf R).presheaf.germ x = toStalk R x := by
rw [← toOpen_res R ⊤ U (homOfLE le_top : U ⟶ ⊤), Category.assoc, Presheaf.germ_res]; rfl
#align algebraic_geometry.structure_sheaf.to_open_germ AlgebraicGeometry.StructureSheaf.toOpen_germ
@[simp]
theorem germ_toOpen (U : Opens (PrimeSpectrum.Top R)) (x : U) (f : R) :
(structureSheaf R).presheaf.germ x (toOpen R U f) = toStalk R x f := by rw [← toOpen_germ]; rfl
#align algebraic_geometry.structure_sheaf.germ_to_open AlgebraicGeometry.StructureSheaf.germ_toOpen
theorem germ_to_top (x : PrimeSpectrum.Top R) (f : R) :
(structureSheaf R).presheaf.germ (⟨x, trivial⟩ : (⊤ : Opens (PrimeSpectrum.Top R)))
(toOpen R ⊤ f) =
toStalk R x f :=
rfl
#align algebraic_geometry.structure_sheaf.germ_to_top AlgebraicGeometry.StructureSheaf.germ_to_top
theorem isUnit_to_basicOpen_self (f : R) : IsUnit (toOpen R (PrimeSpectrum.basicOpen f) f) :=
isUnit_of_mul_eq_one _ (const R 1 f (PrimeSpectrum.basicOpen f) fun _ => id) <| by
rw [toOpen_eq_const, const_mul_rev]
#align algebraic_geometry.structure_sheaf.is_unit_to_basic_open_self AlgebraicGeometry.StructureSheaf.isUnit_to_basicOpen_self
theorem isUnit_toStalk (x : PrimeSpectrum.Top R) (f : x.asIdeal.primeCompl) :
IsUnit (toStalk R x (f : R)) := by
erw [← germ_toOpen R (PrimeSpectrum.basicOpen (f : R)) ⟨x, f.2⟩ (f : R)]
exact RingHom.isUnit_map _ (isUnit_to_basicOpen_self R f)
#align algebraic_geometry.structure_sheaf.is_unit_to_stalk AlgebraicGeometry.StructureSheaf.isUnit_toStalk
/-- The canonical ring homomorphism from the localization of `R` at `p` to the stalk
of the structure sheaf at the point `p`. -/
def localizationToStalk (x : PrimeSpectrum.Top R) :
CommRingCat.of (Localization.AtPrime x.asIdeal) ⟶ (structureSheaf R).presheaf.stalk x :=
show Localization.AtPrime x.asIdeal →+* _ from IsLocalization.lift (isUnit_toStalk R x)
#align algebraic_geometry.structure_sheaf.localization_to_stalk AlgebraicGeometry.StructureSheaf.localizationToStalk
@[simp]
theorem localizationToStalk_of (x : PrimeSpectrum.Top R) (f : R) :
localizationToStalk R x (algebraMap _ (Localization _) f) = toStalk R x f :=
IsLocalization.lift_eq (S := Localization x.asIdeal.primeCompl) _ f
#align algebraic_geometry.structure_sheaf.localization_to_stalk_of AlgebraicGeometry.StructureSheaf.localizationToStalk_of
@[simp]
theorem localizationToStalk_mk' (x : PrimeSpectrum.Top R) (f : R) (s : x.asIdeal.primeCompl) :
localizationToStalk R x (IsLocalization.mk' (Localization.AtPrime x.asIdeal) f s) =
(structureSheaf R).presheaf.germ (⟨x, s.2⟩ : PrimeSpectrum.basicOpen (s : R))
(const R f s (PrimeSpectrum.basicOpen s) fun _ => id) :=
(IsLocalization.lift_mk'_spec (S := Localization.AtPrime x.asIdeal) _ _ _ _).2 <| by
erw [← germ_toOpen R (PrimeSpectrum.basicOpen s) ⟨x, s.2⟩,
← germ_toOpen R (PrimeSpectrum.basicOpen s) ⟨x, s.2⟩, ← RingHom.map_mul, toOpen_eq_const,
toOpen_eq_const, const_mul_cancel']
#align algebraic_geometry.structure_sheaf.localization_to_stalk_mk' AlgebraicGeometry.StructureSheaf.localizationToStalk_mk'
/-- The ring homomorphism that takes a section of the structure sheaf of `R` on the open set `U`,
implemented as a subtype of dependent functions to localizations at prime ideals, and evaluates
the section on the point corresponding to a given prime ideal. -/
def openToLocalization (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) :
(structureSheaf R).1.obj (op U) ⟶ CommRingCat.of (Localization.AtPrime x.asIdeal) where
toFun s := (s.1 ⟨x, hx⟩ : _)
map_one' := rfl
map_mul' _ _ := rfl
map_zero' := rfl
map_add' _ _ := rfl
#align algebraic_geometry.structure_sheaf.open_to_localization AlgebraicGeometry.StructureSheaf.openToLocalization
@[simp]
theorem coe_openToLocalization (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R)
(hx : x ∈ U) :
(openToLocalization R U x hx :
(structureSheaf R).1.obj (op U) → Localization.AtPrime x.asIdeal) =
fun s => (s.1 ⟨x, hx⟩ : _) :=
rfl
#align algebraic_geometry.structure_sheaf.coe_open_to_localization AlgebraicGeometry.StructureSheaf.coe_openToLocalization
theorem openToLocalization_apply (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R)
(hx : x ∈ U) (s : (structureSheaf R).1.obj (op U)) :
openToLocalization R U x hx s = (s.1 ⟨x, hx⟩ : _) :=
rfl
#align algebraic_geometry.structure_sheaf.open_to_localization_apply AlgebraicGeometry.StructureSheaf.openToLocalization_apply
/-- The ring homomorphism from the stalk of the structure sheaf of `R` at a point corresponding to
a prime ideal `p` to the localization of `R` at `p`,
formed by gluing the `openToLocalization` maps. -/
def stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
(structureSheaf R).presheaf.stalk x ⟶ CommRingCat.of (Localization.AtPrime x.asIdeal) :=
Limits.colimit.desc ((OpenNhds.inclusion x).op ⋙ (structureSheaf R).1)
{ pt := _
ι := { app := fun U =>
openToLocalization R ((OpenNhds.inclusion _).obj (unop U)) x (unop U).2 } }
#align algebraic_geometry.structure_sheaf.stalk_to_fiber_ring_hom AlgebraicGeometry.StructureSheaf.stalkToFiberRingHom
@[simp]
theorem germ_comp_stalkToFiberRingHom (U : Opens (PrimeSpectrum.Top R)) (x : U) :
(structureSheaf R).presheaf.germ x ≫ stalkToFiberRingHom R x = openToLocalization R U x x.2 :=
Limits.colimit.ι_desc _ _
#align algebraic_geometry.structure_sheaf.germ_comp_stalk_to_fiber_ring_hom AlgebraicGeometry.StructureSheaf.germ_comp_stalkToFiberRingHom
@[simp]
theorem stalkToFiberRingHom_germ' (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R)
(hx : x ∈ U) (s : (structureSheaf R).1.obj (op U)) :
stalkToFiberRingHom R x ((structureSheaf R).presheaf.germ ⟨x, hx⟩ s) = (s.1 ⟨x, hx⟩ : _) :=
RingHom.ext_iff.1 (germ_comp_stalkToFiberRingHom R U ⟨x, hx⟩ : _) s
#align algebraic_geometry.structure_sheaf.stalk_to_fiber_ring_hom_germ' AlgebraicGeometry.StructureSheaf.stalkToFiberRingHom_germ'
@[simp]
theorem stalkToFiberRingHom_germ (U : Opens (PrimeSpectrum.Top R)) (x : U)
(s : (structureSheaf R).1.obj (op U)) :
stalkToFiberRingHom R x ((structureSheaf R).presheaf.germ x s) = s.1 x := by
cases x; exact stalkToFiberRingHom_germ' R U _ _ _
#align algebraic_geometry.structure_sheaf.stalk_to_fiber_ring_hom_germ AlgebraicGeometry.StructureSheaf.stalkToFiberRingHom_germ
@[simp]
theorem toStalk_comp_stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
-- Porting note: now `algebraMap _ _` needs to be explicitly typed
toStalk R x ≫ stalkToFiberRingHom R x = algebraMap R (Localization.AtPrime x.asIdeal) := by
erw [toStalk, Category.assoc, germ_comp_stalkToFiberRingHom]; rfl
#align algebraic_geometry.structure_sheaf.to_stalk_comp_stalk_to_fiber_ring_hom AlgebraicGeometry.StructureSheaf.toStalk_comp_stalkToFiberRingHom
@[simp]
theorem stalkToFiberRingHom_toStalk (x : PrimeSpectrum.Top R) (f : R) :
-- Porting note: now `algebraMap _ _` needs to be explicitly typed
stalkToFiberRingHom R x (toStalk R x f) = algebraMap R (Localization.AtPrime x.asIdeal) f :=
RingHom.ext_iff.1 (toStalk_comp_stalkToFiberRingHom R x) _
#align algebraic_geometry.structure_sheaf.stalk_to_fiber_ring_hom_to_stalk AlgebraicGeometry.StructureSheaf.stalkToFiberRingHom_toStalk
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
(structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
hom := stalkToFiberRingHom R x
inv := localizationToStalk R x
hom_inv_id := by
ext U hxU s
-- Note: this `simp` was longer, but the line below had to become an `erw`
simp only [Category.comp_id]
erw [comp_apply, comp_apply, stalkToFiberRingHom_germ']
obtain ⟨V, hxV, iVU, f, g, (hg : V ≤ PrimeSpectrum.basicOpen _), hs⟩ :=
exists_const _ _ s x hxU
erw [← res_apply R U V iVU s ⟨x, hxV⟩, ← hs, const_apply, localizationToStalk_mk']
refine (structureSheaf R).presheaf.germ_ext V hxV (homOfLE hg) iVU ?_
dsimp
erw [← hs, res_const']
inv_hom_id :=
@IsLocalization.ringHom_ext R _ x.asIdeal.primeCompl (Localization.AtPrime x.asIdeal) _ _
(Localization.AtPrime x.asIdeal) _ _
(RingHom.comp (stalkToFiberRingHom R x) (localizationToStalk R x))
(RingHom.id (Localization.AtPrime _)) <| by
ext f
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
rw [RingHom.comp_apply, RingHom.comp_apply]; erw [localizationToStalk_of,
stalkToFiberRingHom_toStalk]; rw [RingHom.comp_apply, RingHom.id_apply]
#align algebraic_geometry.structure_sheaf.stalk_iso AlgebraicGeometry.StructureSheaf.stalkIso
instance (x : PrimeSpectrum R) : IsIso (stalkToFiberRingHom R x) :=
(stalkIso R x).isIso_hom
instance (x : PrimeSpectrum R) : IsIso (localizationToStalk R x) :=
(stalkIso R x).isIso_inv
@[simp, reassoc]
theorem stalkToFiberRingHom_localizationToStalk (x : PrimeSpectrum.Top R) :
stalkToFiberRingHom R x ≫ localizationToStalk R x = 𝟙 _ :=
(stalkIso R x).hom_inv_id
#align algebraic_geometry.structure_sheaf.stalk_to_fiber_ring_hom_localization_to_stalk AlgebraicGeometry.StructureSheaf.stalkToFiberRingHom_localizationToStalk
@[simp, reassoc]
theorem localizationToStalk_stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
localizationToStalk R x ≫ stalkToFiberRingHom R x = 𝟙 _ :=
(stalkIso R x).inv_hom_id
#align algebraic_geometry.structure_sheaf.localization_to_stalk_stalk_to_fiber_ring_hom AlgebraicGeometry.StructureSheaf.localizationToStalk_stalkToFiberRingHom
/-- The canonical ring homomorphism interpreting `s ∈ R_f` as a section of the structure sheaf
on the basic open defined by `f ∈ R`. -/
def toBasicOpen (f : R) :
Localization.Away f →+* (structureSheaf R).1.obj (op <| PrimeSpectrum.basicOpen f) :=
IsLocalization.Away.lift f (isUnit_to_basicOpen_self R f)
#align algebraic_geometry.structure_sheaf.to_basic_open AlgebraicGeometry.StructureSheaf.toBasicOpen
@[simp]
theorem toBasicOpen_mk' (s f : R) (g : Submonoid.powers s) :
toBasicOpen R s (IsLocalization.mk' (Localization.Away s) f g) =
const R f g (PrimeSpectrum.basicOpen s) fun x hx => Submonoid.powers_le.2 hx g.2 :=
(IsLocalization.lift_mk'_spec _ _ _ _).2 <| by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [toOpen_eq_const, toOpen_eq_const]; rw [const_mul_cancel']
#align algebraic_geometry.structure_sheaf.to_basic_open_mk' AlgebraicGeometry.StructureSheaf.toBasicOpen_mk'
@[simp]
theorem localization_toBasicOpen (f : R) :
RingHom.comp (toBasicOpen R f) (algebraMap R (Localization.Away f)) =
toOpen R (PrimeSpectrum.basicOpen f) :=
RingHom.ext fun g => by
rw [toBasicOpen, IsLocalization.Away.lift, RingHom.comp_apply, IsLocalization.lift_eq]
#align algebraic_geometry.structure_sheaf.localization_to_basic_open AlgebraicGeometry.StructureSheaf.localization_toBasicOpen
@[simp]
theorem toBasicOpen_to_map (s f : R) :
toBasicOpen R s (algebraMap R (Localization.Away s) f) =
const R f 1 (PrimeSpectrum.basicOpen s) fun _ _ => Submonoid.one_mem _ :=
(IsLocalization.lift_eq _ _).trans <| toOpen_eq_const _ _ _
#align algebraic_geometry.structure_sheaf.to_basic_open_to_map AlgebraicGeometry.StructureSheaf.toBasicOpen_to_map
-- The proof here follows the argument in Hartshorne's Algebraic Geometry, Proposition II.2.2.
theorem toBasicOpen_injective (f : R) : Function.Injective (toBasicOpen R f) := by
intro s t h_eq
obtain ⟨a, ⟨b, hb⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers f) s
obtain ⟨c, ⟨d, hd⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers f) t
simp only [toBasicOpen_mk'] at h_eq
rw [IsLocalization.eq]
-- We know that the fractions `a/b` and `c/d` are equal as sections of the structure sheaf on
-- `basicOpen f`. We need to show that they agree as elements in the localization of `R` at `f`.
-- This amounts showing that `r * (d * a) = r * (b * c)`, for some power `r = f ^ n` of `f`.
-- We define `I` as the ideal of *all* elements `r` satisfying the above equation.
let I : Ideal R :=
{ carrier := { r : R | r * (d * a) = r * (b * c) }
zero_mem' := by simp only [Set.mem_setOf_eq, zero_mul]
add_mem' := fun {r₁ r₂} hr₁ hr₂ => by dsimp at hr₁ hr₂ ⊢; simp only [add_mul, hr₁, hr₂]
smul_mem' := fun {r₁ r₂} hr₂ => by dsimp at hr₂ ⊢; simp only [mul_assoc, hr₂] }
-- Our claim now reduces to showing that `f` is contained in the radical of `I`
suffices f ∈ I.radical by
cases' this with n hn
exact ⟨⟨f ^ n, n, rfl⟩, hn⟩
rw [← PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical, PrimeSpectrum.mem_vanishingIdeal]
intro p hfp
contrapose hfp
rw [PrimeSpectrum.mem_zeroLocus, Set.not_subset]
have := congr_fun (congr_arg Subtype.val h_eq) ⟨p, hfp⟩
dsimp at this
-- Porting note: need to tell Lean what `S` is and need to change to `erw`
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [IsLocalization.eq (S := Localization.AtPrime p.asIdeal)] at this
cases' this with r hr
exact ⟨r.1, hr, r.2⟩
#align algebraic_geometry.structure_sheaf.to_basic_open_injective AlgebraicGeometry.StructureSheaf.toBasicOpen_injective
/-
Auxiliary lemma for surjectivity of `toBasicOpen`.
Every section can locally be represented on basic opens `basicOpen g` as a fraction `f/g`
-/
theorem locally_const_basicOpen (U : Opens (PrimeSpectrum.Top R))
(s : (structureSheaf R).1.obj (op U)) (x : U) :
∃ (f g : R) (i : PrimeSpectrum.basicOpen g ⟶ U), x.1 ∈ PrimeSpectrum.basicOpen g ∧
(const R f g (PrimeSpectrum.basicOpen g) fun y hy => hy) =
(structureSheaf R).1.map i.op s := by
-- First, any section `s` can be represented as a fraction `f/g` on some open neighborhood of `x`
-- and we may pass to a `basicOpen h`, since these form a basis
obtain ⟨V, hxV : x.1 ∈ V.1, iVU, f, g, hVDg : V ≤ PrimeSpectrum.basicOpen g, s_eq⟩ :=
exists_const R U s x.1 x.2
obtain ⟨_, ⟨h, rfl⟩, hxDh, hDhV : PrimeSpectrum.basicOpen h ≤ V⟩ :=
PrimeSpectrum.isTopologicalBasis_basic_opens.exists_subset_of_mem_open hxV V.2
-- The problem is of course, that `g` and `h` don't need to coincide.
-- But, since `basicOpen h ≤ basicOpen g`, some power of `h` must be a multiple of `g`
cases' (PrimeSpectrum.basicOpen_le_basicOpen_iff h g).mp (Set.Subset.trans hDhV hVDg) with n hn
-- Actually, we will need a *nonzero* power of `h`.
-- This is because we will need the equality `basicOpen (h ^ n) = basicOpen h`, which only
-- holds for a nonzero power `n`. We therefore artificially increase `n` by one.
replace hn := Ideal.mul_mem_right h (Ideal.span {g}) hn
rw [← pow_succ, Ideal.mem_span_singleton'] at hn
cases' hn with c hc
have basic_opens_eq := PrimeSpectrum.basicOpen_pow h (n + 1) (by omega)
have i_basic_open := eqToHom basic_opens_eq ≫ homOfLE hDhV
-- We claim that `(f * c) / h ^ (n+1)` is our desired representation
use f * c, h ^ (n + 1), i_basic_open ≫ iVU, (basic_opens_eq.symm.le : _) hxDh
rw [op_comp, Functor.map_comp] --, comp_apply, ← s_eq, res_const]
-- Porting note: `comp_apply` can't be rewritten, so use a change
change const R _ _ _ _ = (structureSheaf R).1.map i_basic_open.op
((structureSheaf R).1.map iVU.op s)
rw [← s_eq, res_const]
-- Note that the last rewrite here generated an additional goal, which was a parameter
-- of `res_const`. We prove this goal first
swap
· intro y hy
rw [basic_opens_eq] at hy
exact (Set.Subset.trans hDhV hVDg : _) hy
-- All that is left is a simple calculation
apply const_ext
rw [mul_assoc f c g, hc]
#align algebraic_geometry.structure_sheaf.locally_const_basic_open AlgebraicGeometry.StructureSheaf.locally_const_basicOpen
/-
Auxiliary lemma for surjectivity of `toBasicOpen`.
A local representation of a section `s` as fractions `a i / h i` on finitely many basic opens
`basicOpen (h i)` can be "normalized" in such a way that `a i * h j = h i * a j` for all `i, j`
-/
theorem normalize_finite_fraction_representation (U : Opens (PrimeSpectrum.Top R))
(s : (structureSheaf R).1.obj (op U)) {ι : Type*} (t : Finset ι) (a h : ι → R)
(iDh : ∀ i : ι, PrimeSpectrum.basicOpen (h i) ⟶ U)
(h_cover : U ≤ ⨆ i ∈ t, PrimeSpectrum.basicOpen (h i))
(hs :
∀ i : ι,
(const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) fun y hy => hy) =
(structureSheaf R).1.map (iDh i).op s) :
∃ (a' h' : ι → R) (iDh' : ∀ i : ι, PrimeSpectrum.basicOpen (h' i) ⟶ U),
(U ≤ ⨆ i ∈ t, PrimeSpectrum.basicOpen (h' i)) ∧
(∀ (i) (_ : i ∈ t) (j) (_ : j ∈ t), a' i * h' j = h' i * a' j) ∧
∀ i ∈ t,
(structureSheaf R).1.map (iDh' i).op s =
const R (a' i) (h' i) (PrimeSpectrum.basicOpen (h' i)) fun y hy => hy := by
-- First we show that the fractions `(a i * h j) / (h i * h j)` and `(h i * a j) / (h i * h j)`
-- coincide in the localization of `R` at `h i * h j`
have fractions_eq :
∀ i j : ι,
IsLocalization.mk' (Localization.Away (h i * h j))
(a i * h j) ⟨h i * h j, Submonoid.mem_powers _⟩ =
IsLocalization.mk' _ (h i * a j) ⟨h i * h j, Submonoid.mem_powers _⟩ := by
intro i j
let D := PrimeSpectrum.basicOpen (h i * h j)
let iDi : D ⟶ PrimeSpectrum.basicOpen (h i) := homOfLE (PrimeSpectrum.basicOpen_mul_le_left _ _)
let iDj : D ⟶ PrimeSpectrum.basicOpen (h j) :=
homOfLE (PrimeSpectrum.basicOpen_mul_le_right _ _)
-- Crucially, we need injectivity of `toBasicOpen`
apply toBasicOpen_injective R (h i * h j)
rw [toBasicOpen_mk', toBasicOpen_mk']
simp only []
-- Here, both sides of the equation are equal to a restriction of `s`
trans
on_goal 1 =>
convert congr_arg ((structureSheaf R).1.map iDj.op) (hs j).symm using 1
convert congr_arg ((structureSheaf R).1.map iDi.op) (hs i) using 1
all_goals rw [res_const]; apply const_ext; ring
-- The remaining two goals were generated during the rewrite of `res_const`
-- These can be solved immediately
exacts [PrimeSpectrum.basicOpen_mul_le_left _ _, PrimeSpectrum.basicOpen_mul_le_right _ _]
-- From the equality in the localization, we obtain for each `(i,j)` some power `(h i * h j) ^ n`
-- which equalizes `a i * h j` and `h i * a j`
have exists_power :
∀ i j : ι, ∃ n : ℕ, a i * h j * (h i * h j) ^ n = h i * a j * (h i * h j) ^ n := by
intro i j
obtain ⟨⟨c, n, rfl⟩, hc⟩ := IsLocalization.eq.mp (fractions_eq i j)
use n + 1
rw [pow_succ]
dsimp at hc
convert hc using 1 <;> ring
let n := fun p : ι × ι => (exists_power p.1 p.2).choose
have n_spec := fun p : ι × ι => (exists_power p.fst p.snd).choose_spec
-- We need one power `(h i * h j) ^ N` that works for *all* pairs `(i,j)`
-- Since there are only finitely many indices involved, we can pick the supremum.
let N := (t ×ˢ t).sup n
have basic_opens_eq : ∀ i : ι, PrimeSpectrum.basicOpen (h i ^ (N + 1)) =
PrimeSpectrum.basicOpen (h i) := fun i => PrimeSpectrum.basicOpen_pow _ _ (by omega)
-- Expanding the fraction `a i / h i` by the power `(h i) ^ n` gives the desired normalization
refine
⟨fun i => a i * h i ^ N, fun i => h i ^ (N + 1), fun i => eqToHom (basic_opens_eq i) ≫ iDh i,
?_, ?_, ?_⟩
· simpa only [basic_opens_eq] using h_cover
· intro i hi j hj
-- Here we need to show that our new fractions `a i / h i` satisfy the normalization condition
-- Of course, the power `N` we used to expand the fractions might be bigger than the power
-- `n (i, j)` which was originally chosen. We denote their difference by `k`
have n_le_N : n (i, j) ≤ N := Finset.le_sup (Finset.mem_product.mpr ⟨hi, hj⟩)
cases' Nat.le.dest n_le_N with k hk
simp only [← hk, pow_add, pow_one]
-- To accommodate for the difference `k`, we multiply both sides of the equation `n_spec (i, j)`
-- by `(h i * h j) ^ k`
convert congr_arg (fun z => z * (h i * h j) ^ k) (n_spec (i, j)) using 1 <;>
· simp only [n, mul_pow]; ring
-- Lastly, we need to show that the new fractions still represent our original `s`
intro i _
rw [op_comp, Functor.map_comp]
-- Porting note: `comp_apply` can't be rewritten, so use a change
change (structureSheaf R).1.map (eqToHom (basic_opens_eq _)).op
((structureSheaf R).1.map (iDh i).op s) = _
rw [← hs, res_const]
-- additional goal spit out by `res_const`
swap
· exact (basic_opens_eq i).le
apply const_ext
dsimp
rw [pow_succ]
ring
#align algebraic_geometry.structure_sheaf.normalize_finite_fraction_representation AlgebraicGeometry.StructureSheaf.normalize_finite_fraction_representation
open scoped Classical
-- Porting note: in the following proof there are two places where `⋃ i, ⋃ (hx : i ∈ _), ... `
-- though `hx` is not used in `...` part, it is still required to maintain the structure of
-- the original proof in mathlib3.
set_option linter.unusedVariables false in
-- The proof here follows the argument in Hartshorne's Algebraic Geometry, Proposition II.2.2.
theorem toBasicOpen_surjective (f : R) : Function.Surjective (toBasicOpen R f) := by
intro s
-- In this proof, `basicOpen f` will play two distinct roles: Firstly, it is an open set in the
-- prime spectrum. Secondly, it is used as an indexing type for various families of objects
-- (open sets, ring elements, ...). In order to make the distinction clear, we introduce a type
-- alias `ι` that is used whenever we want think of it as an indexing type.
let ι : Type u := PrimeSpectrum.basicOpen f
-- First, we pick some cover of basic opens, on which we can represent `s` as a fraction
choose a' h' iDh' hxDh' s_eq' using locally_const_basicOpen R (PrimeSpectrum.basicOpen f) s
-- Since basic opens are compact, we can pass to a finite subcover
obtain ⟨t, ht_cover'⟩ :=
(PrimeSpectrum.isCompact_basicOpen f).elim_finite_subcover
(fun i : ι => PrimeSpectrum.basicOpen (h' i)) (fun i => PrimeSpectrum.isOpen_basicOpen)
-- Here, we need to show that our basic opens actually form a cover of `basicOpen f`
fun x hx => by rw [Set.mem_iUnion]; exact ⟨⟨x, hx⟩, hxDh' ⟨x, hx⟩⟩
simp only [← Opens.coe_iSup, SetLike.coe_subset_coe] at ht_cover'
-- We use the normalization lemma from above to obtain the relation `a i * h j = h i * a j`
obtain ⟨a, h, iDh, ht_cover, ah_ha, s_eq⟩ :=
normalize_finite_fraction_representation R (PrimeSpectrum.basicOpen f)
s t a' h' iDh' ht_cover' s_eq'
clear s_eq' iDh' hxDh' ht_cover' a' h'
-- Porting note: simp with `[← SetLike.coe_subset_coe, Opens.coe_iSup]` does not result in
-- desired form
rw [← SetLike.coe_subset_coe, Opens.coe_iSup] at ht_cover
replace ht_cover : (PrimeSpectrum.basicOpen f : Set <| PrimeSpectrum R) ⊆
⋃ (i : ι) (x : i ∈ t), (PrimeSpectrum.basicOpen (h i) : Set _) := by
convert ht_cover using 2
exact funext fun j => by rw [Opens.coe_iSup]
-- Next we show that some power of `f` is a linear combination of the `h i`
obtain ⟨n, hn⟩ : f ∈ (Ideal.span (h '' ↑t)).radical := by
rw [← PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical, PrimeSpectrum.zeroLocus_span]
-- Porting note: simp with `PrimeSpectrum.basicOpen_eq_zeroLocus_compl` does not work
replace ht_cover : (PrimeSpectrum.zeroLocus {f})ᶜ ⊆
⋃ (i : ι) (x : i ∈ t), (PrimeSpectrum.zeroLocus {h i})ᶜ := by
convert ht_cover
· rw [PrimeSpectrum.basicOpen_eq_zeroLocus_compl]
· simp only [Opens.iSup_mk, Opens.carrier_eq_coe, PrimeSpectrum.basicOpen_eq_zeroLocus_compl]
rw [Set.compl_subset_comm] at ht_cover
-- Why doesn't `simp_rw` do this?
simp_rw [Set.compl_iUnion, compl_compl, ← PrimeSpectrum.zeroLocus_iUnion,
← Finset.set_biUnion_coe, ← Set.image_eq_iUnion] at ht_cover
apply PrimeSpectrum.vanishingIdeal_anti_mono ht_cover
exact PrimeSpectrum.subset_vanishingIdeal_zeroLocus {f} (Set.mem_singleton f)
replace hn := Ideal.mul_mem_right f _ hn
erw [← pow_succ, Finsupp.mem_span_image_iff_total] at hn
rcases hn with ⟨b, b_supp, hb⟩
rw [Finsupp.total_apply_of_mem_supported R b_supp] at hb
dsimp at hb
-- Finally, we have all the ingredients.
-- We claim that our preimage is given by `(∑ (i : ι) ∈ t, b i * a i) / f ^ (n+1)`
use
IsLocalization.mk' (Localization.Away f) (∑ i ∈ t, b i * a i)
(⟨f ^ (n + 1), n + 1, rfl⟩ : Submonoid.powers _)
rw [toBasicOpen_mk']
-- Since the structure sheaf is a sheaf, we can show the desired equality locally.
-- Annoyingly, `Sheaf.eq_of_locally_eq'` requires an open cover indexed by a *type*, so we need to
-- coerce our finset `t` to a type first.
let tt := ((t : Set (PrimeSpectrum.basicOpen f)) : Type u)
apply
(structureSheaf R).eq_of_locally_eq' (fun i : tt => PrimeSpectrum.basicOpen (h i))
(PrimeSpectrum.basicOpen f) fun i : tt => iDh i
· -- This feels a little redundant, since already have `ht_cover` as a hypothesis
-- Unfortunately, `ht_cover` uses a bounded union over the set `t`, while here we have the
-- Union indexed by the type `tt`, so we need some boilerplate to translate one to the other
intro x hx
erw [TopologicalSpace.Opens.mem_iSup]
have := ht_cover hx
rw [← Finset.set_biUnion_coe, Set.mem_iUnion₂] at this
rcases this with ⟨i, i_mem, x_mem⟩
exact ⟨⟨i, i_mem⟩, x_mem⟩
rintro ⟨i, hi⟩
dsimp
change (structureSheaf R).1.map _ _ = (structureSheaf R).1.map _ _
rw [s_eq i hi, res_const]
-- Again, `res_const` spits out an additional goal
swap
· intro y hy
change y ∈ PrimeSpectrum.basicOpen (f ^ (n + 1))
rw [PrimeSpectrum.basicOpen_pow f (n + 1) (by omega)]
exact (leOfHom (iDh i) : _) hy
-- The rest of the proof is just computation
apply const_ext
rw [← hb, Finset.sum_mul, Finset.mul_sum]
apply Finset.sum_congr rfl
intro j hj
rw [mul_assoc, ah_ha j hj i hi]
ring
#align algebraic_geometry.structure_sheaf.to_basic_open_surjective AlgebraicGeometry.StructureSheaf.toBasicOpen_surjective
instance isIso_toBasicOpen (f : R) :
IsIso (show CommRingCat.of (Localization.Away f) ⟶ _ from toBasicOpen R f) :=
haveI : IsIso ((forget CommRingCat).map
(show CommRingCat.of (Localization.Away f) ⟶ _ from toBasicOpen R f)) :=
(isIso_iff_bijective _).mpr ⟨toBasicOpen_injective R f, toBasicOpen_surjective R f⟩
isIso_of_reflects_iso _ (forget CommRingCat)
#align algebraic_geometry.structure_sheaf.is_iso_to_basic_open AlgebraicGeometry.StructureSheaf.isIso_toBasicOpen
/-- The ring isomorphism between the structure sheaf on `basicOpen f` and the localization of `R`
at the submonoid of powers of `f`. -/
def basicOpenIso (f : R) :
(structureSheaf R).1.obj (op (PrimeSpectrum.basicOpen f)) ≅
CommRingCat.of (Localization.Away f) :=
(asIso (show CommRingCat.of (Localization.Away f) ⟶ _ from toBasicOpen R f)).symm
#align algebraic_geometry.structure_sheaf.basic_open_iso AlgebraicGeometry.StructureSheaf.basicOpenIso
instance stalkAlgebra (p : PrimeSpectrum R) : Algebra R ((structureSheaf R).presheaf.stalk p) :=
(toStalk R p).toAlgebra
#align algebraic_geometry.structure_sheaf.stalk_algebra AlgebraicGeometry.StructureSheaf.stalkAlgebra
@[simp]
theorem stalkAlgebra_map (p : PrimeSpectrum R) (r : R) :
algebraMap R ((structureSheaf R).presheaf.stalk p) r = toStalk R p r :=
rfl
#align algebraic_geometry.structure_sheaf.stalk_algebra_map AlgebraicGeometry.StructureSheaf.stalkAlgebra_map
/-- Stalk of the structure sheaf at a prime p as localization of R -/
instance IsLocalization.to_stalk (p : PrimeSpectrum R) :
IsLocalization.AtPrime ((structureSheaf R).presheaf.stalk p) p.asIdeal := by
convert (IsLocalization.isLocalization_iff_of_ringEquiv (S := Localization.AtPrime p.asIdeal) _
(stalkIso R p).symm.commRingCatIsoToRingEquiv).mp
Localization.isLocalization
apply Algebra.algebra_ext
intro
rw [stalkAlgebra_map]
congr 1
change toStalk R p = _ ≫ (stalkIso R p).inv
erw [Iso.eq_comp_inv]
exact toStalk_comp_stalkToFiberRingHom R p
#align algebraic_geometry.structure_sheaf.is_localization.to_stalk AlgebraicGeometry.StructureSheaf.IsLocalization.to_stalk
instance openAlgebra (U : (Opens (PrimeSpectrum R))ᵒᵖ) : Algebra R ((structureSheaf R).val.obj U) :=
(toOpen R (unop U)).toAlgebra
#align algebraic_geometry.structure_sheaf.open_algebra AlgebraicGeometry.StructureSheaf.openAlgebra
@[simp]
theorem openAlgebra_map (U : (Opens (PrimeSpectrum R))ᵒᵖ) (r : R) :
algebraMap R ((structureSheaf R).val.obj U) r = toOpen R (unop U) r :=
rfl
#align algebraic_geometry.structure_sheaf.open_algebra_map AlgebraicGeometry.StructureSheaf.openAlgebra_map
/-- Sections of the structure sheaf of Spec R on a basic open as localization of R -/
instance IsLocalization.to_basicOpen (r : R) :
IsLocalization.Away r ((structureSheaf R).val.obj (op <| PrimeSpectrum.basicOpen r)) := by
convert (IsLocalization.isLocalization_iff_of_ringEquiv (S := Localization.Away r) _
(basicOpenIso R r).symm.commRingCatIsoToRingEquiv).mp
Localization.isLocalization
apply Algebra.algebra_ext
intro x
congr 1
exact (localization_toBasicOpen R r).symm
#align algebraic_geometry.structure_sheaf.is_localization.to_basic_open AlgebraicGeometry.StructureSheaf.IsLocalization.to_basicOpen
instance to_basicOpen_epi (r : R) : Epi (toOpen R (PrimeSpectrum.basicOpen r)) :=
⟨fun _ _ h => IsLocalization.ringHom_ext (Submonoid.powers r) h⟩
#align algebraic_geometry.structure_sheaf.to_basic_open_epi AlgebraicGeometry.StructureSheaf.to_basicOpen_epi
@[elementwise]
theorem to_global_factors :
toOpen R ⊤ =
CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R))) ≫
toBasicOpen R (1 : R) ≫
(structureSheaf R).1.map (eqToHom PrimeSpectrum.basicOpen_one.symm).op := by
rw [← Category.assoc]
change toOpen R ⊤ =
(CommRingCat.ofHom <| (toBasicOpen R 1).comp (algebraMap R (Localization.Away 1))) ≫
(structureSheaf R).1.map (eqToHom _).op
unfold CommRingCat.ofHom
rw [localization_toBasicOpen R, toOpen_res]
#align algebraic_geometry.structure_sheaf.to_global_factors AlgebraicGeometry.StructureSheaf.to_global_factors
instance isIso_to_global : IsIso (toOpen R ⊤) := by
let hom := CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R)))
haveI : IsIso hom :=
(IsLocalization.atOne R (Localization.Away (1 : R))).toRingEquiv.toCommRingCatIso.isIso_hom
rw [to_global_factors R]
infer_instance
#align algebraic_geometry.structure_sheaf.is_iso_to_global AlgebraicGeometry.StructureSheaf.isIso_to_global
/-- The ring isomorphism between the ring `R` and the global sections `Γ(X, 𝒪ₓ)`. -/
-- Porting note: was @[simps (config := { rhsMd := Tactic.Transparency.semireducible })]
@[simps!]
def globalSectionsIso : CommRingCat.of R ≅ (structureSheaf R).1.obj (op ⊤) :=
asIso (toOpen R ⊤)
#align algebraic_geometry.structure_sheaf.global_sections_iso AlgebraicGeometry.StructureSheaf.globalSectionsIso
-- These lemmas have always been bad (#7657), but leanprover/lean4#2644 made `simp` start noticing
attribute [nolint simpNF] AlgebraicGeometry.StructureSheaf.globalSectionsIso_hom_apply_coe
@[simp]
theorem globalSectionsIso_hom (R : CommRingCat) : (globalSectionsIso R).hom = toOpen R ⊤ :=
rfl
#align algebraic_geometry.structure_sheaf.global_sections_iso_hom AlgebraicGeometry.StructureSheaf.globalSectionsIso_hom
@[simp, reassoc, elementwise]
theorem toStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R} (h : x ⤳ y) :
toStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h = toStalk R x := by
dsimp [toStalk]; simp [-toOpen_germ]
#align algebraic_geometry.structure_sheaf.to_stalk_stalk_specializes AlgebraicGeometry.StructureSheaf.toStalk_stalkSpecializes
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
(h : x ⤳ y) :
StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
StructureSheaf.localizationToStalk R x := by
apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
erw [RingHom.comp_assoc]
conv_rhs => erw [RingHom.comp_assoc]
dsimp [CommRingCat.ofHom, localizationToStalk, PrimeSpectrum.localizationMapOfSpecializes]
rw [IsLocalization.lift_comp, IsLocalization.lift_comp, IsLocalization.lift_comp]
exact toStalk_stalkSpecializes h
set_option linter.uppercaseLean3 false in
#align algebraic_geometry.structure_sheaf.localizationToStalk_stalk_specializes AlgebraicGeometry.StructureSheaf.localizationToStalk_stalkSpecializes
@[simp, reassoc, elementwise]
theorem stalkSpecializes_stalk_to_fiber {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
(h : x ⤳ y) :
(structureSheaf R).presheaf.stalkSpecializes h ≫ StructureSheaf.stalkToFiberRingHom R x =
StructureSheaf.stalkToFiberRingHom R y ≫
-- Porting note: `PrimeSpectrum.localizationMapOfSpecializes h` by itself is interpreted as a
-- ring homomorphism, so it is changed in a way to force it being interpreted as categorical
-- arrow.
(show CommRingCat.of (Localization.AtPrime y.asIdeal) ⟶
CommRingCat.of (Localization.AtPrime x.asIdeal)
from PrimeSpectrum.localizationMapOfSpecializes h) := by
change _ ≫ (StructureSheaf.stalkIso R x).hom = (StructureSheaf.stalkIso R y).hom ≫ _
rw [← Iso.eq_comp_inv, Category.assoc, ← Iso.inv_comp_eq]
exact localizationToStalk_stalkSpecializes h
#align algebraic_geometry.structure_sheaf.stalk_specializes_stalk_to_fiber AlgebraicGeometry.StructureSheaf.stalkSpecializes_stalk_to_fiber
section Comap
variable {R} {S : Type u} [CommRing S] {P : Type u} [CommRing P]
/--
Given a ring homomorphism `f : R →+* S`, an open set `U` of the prime spectrum of `R` and an open
set `V` of the prime spectrum of `S`, such that `V ⊆ (comap f) ⁻¹' U`, we can push a section `s`
on `U` to a section on `V`, by composing with `Localization.localRingHom _ _ f` from the left and
`comap f` from the right. Explicitly, if `s` evaluates on `comap f p` to `a / b`, its image on `V`
evaluates on `p` to `f(a) / f(b)`.
At the moment, we work with arbitrary dependent functions `s : Π x : U, Localizations R x`. Below,
we prove the predicate `isLocallyFraction` is preserved by this map, hence it can be extended to
a morphism between the structure sheaves of `R` and `S`.
-/
def comapFun (f : R →+* S) (U : Opens (PrimeSpectrum.Top R)) (V : Opens (PrimeSpectrum.Top S))
(hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1) (s : ∀ x : U, Localizations R x) (y : V) :
Localizations S y :=
Localization.localRingHom (PrimeSpectrum.comap f y.1).asIdeal _ f rfl
(s ⟨PrimeSpectrum.comap f y.1, hUV y.2⟩ : _)
#align algebraic_geometry.structure_sheaf.comap_fun AlgebraicGeometry.StructureSheaf.comapFun
| Mathlib/AlgebraicGeometry/StructureSheaf.lean | 1,080 | 1,097 | theorem comapFunIsLocallyFraction (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
(V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1)
(s : ∀ x : U, Localizations R x) (hs : (isLocallyFraction R).toPrelocalPredicate.pred s) :
(isLocallyFraction S).toPrelocalPredicate.pred (comapFun f U V hUV s) := by |
rintro ⟨p, hpV⟩
-- Since `s` is locally fraction, we can find a neighborhood `W` of `PrimeSpectrum.comap f p`
-- in `U`, such that `s = a / b` on `W`, for some ring elements `a, b : R`.
rcases hs ⟨PrimeSpectrum.comap f p, hUV hpV⟩ with ⟨W, m, iWU, a, b, h_frac⟩
-- We claim that we can write our new section as the fraction `f a / f b` on the neighborhood
-- `(comap f) ⁻¹ W ⊓ V` of `p`.
refine ⟨Opens.comap (PrimeSpectrum.comap f) W ⊓ V, ⟨m, hpV⟩, Opens.infLERight _ _, f a, f b, ?_⟩
rintro ⟨q, ⟨hqW, hqV⟩⟩
specialize h_frac ⟨PrimeSpectrum.comap f q, hqW⟩
refine ⟨h_frac.1, ?_⟩
dsimp only [comapFun]
erw [← Localization.localRingHom_to_map (PrimeSpectrum.comap f q).asIdeal, ← RingHom.map_mul,
h_frac.2, Localization.localRingHom_to_map]
rfl
|
/-
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, Sophie Morel, Yury Kudryashov
-/
import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace
import Mathlib.Logic.Embedding.Basic
import Mathlib.Data.Fintype.CardEmbedding
import Mathlib.Topology.Algebra.Module.Multilinear.Topology
#align_import analysis.normed_space.multilinear from "leanprover-community/mathlib"@"f40476639bac089693a489c9e354ebd75dc0f886"
/-!
# Operator norm on the space of continuous multilinear maps
When `f` is a continuous multilinear map in finitely many variables, we define its norm `‖f‖` as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`.
We show that it is indeed a norm, and prove its basic properties.
## Main results
Let `f` be a multilinear map in finitely many variables.
* `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0`
with `‖f m‖ ≤ C * ∏ i, ‖m i‖` for all `m`.
* `continuous_of_bound`, conversely, asserts that this bound implies continuity.
* `mkContinuous` constructs the associated continuous multilinear map.
Let `f` be a continuous multilinear map in finitely many variables.
* `‖f‖` is its norm, i.e., the smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for
all `m`.
* `le_opNorm f m` asserts the fundamental inequality `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖`.
* `norm_image_sub_le f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of
`‖f‖` and `‖m₁ - m₂‖`.
## Implementation notes
We mostly follow the API (and the proofs) of `OperatorNorm.lean`, with the additional complexity
that we should deal with multilinear maps in several variables. The currying/uncurrying
constructions are based on those in `Multilinear.lean`.
From the mathematical point of view, all the results follow from the results on operator norm in
one variable, by applying them to one variable after the other through currying. However, this
is only well defined when there is an order on the variables (for instance on `Fin n`) although
the final result is independent of the order. While everything could be done following this
approach, it turns out that direct proofs are easier and more efficient.
-/
suppress_compilation
noncomputable section
open scoped NNReal Topology Uniformity
open Finset Metric Function Filter
/-
Porting note: These lines are not required in Mathlib4.
```lean
attribute [local instance 1001]
AddCommGroup.toAddCommMonoid NormedAddCommGroup.toAddCommGroup NormedSpace.toModule'
```
-/
/-!
### Type variables
We use the following type variables in this file:
* `𝕜` : a `NontriviallyNormedField`;
* `ι`, `ι'` : finite index types with decidable equality;
* `E`, `E₁` : families of normed vector spaces over `𝕜` indexed by `i : ι`;
* `E'` : a family of normed vector spaces over `𝕜` indexed by `i' : ι'`;
* `Ei` : a family of normed vector spaces over `𝕜` indexed by `i : Fin (Nat.succ n)`;
* `G`, `G'` : normed vector spaces over `𝕜`.
-/
universe u v v' wE wE₁ wE' wG wG'
section Seminorm
variable {𝕜 : Type u} {ι : Type v} {ι' : Type v'} {E : ι → Type wE} {E₁ : ι → Type wE₁}
{E' : ι' → Type wE'} {G : Type wG} {G' : Type wG'} [Fintype ι]
[Fintype ι'] [NontriviallyNormedField 𝕜] [∀ i, SeminormedAddCommGroup (E i)]
[∀ i, NormedSpace 𝕜 (E i)] [∀ i, SeminormedAddCommGroup (E₁ i)] [∀ i, NormedSpace 𝕜 (E₁ i)]
[∀ i, SeminormedAddCommGroup (E' i)] [∀ i, NormedSpace 𝕜 (E' i)]
[SeminormedAddCommGroup G] [NormedSpace 𝕜 G] [SeminormedAddCommGroup G'] [NormedSpace 𝕜 G']
/-!
### Continuity properties of multilinear maps
We relate continuity of multilinear maps to the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, in
both directions. Along the way, we prove useful bounds on the difference `‖f m₁ - f m₂‖`.
-/
namespace MultilinearMap
variable (f : MultilinearMap 𝕜 E G)
/-- If `f` is a continuous multilinear map in finitely many variables on `E` and `m` is an element
of `∀ i, E i` such that one of the `m i` has norm `0`, then `f m` has norm `0`.
Note that we cannot drop the continuity assumption because `f (m : Unit → E) = f (m ())`,
where the domain has zero norm and the codomain has a nonzero norm
does not satisfy this condition. -/
lemma norm_map_coord_zero (hf : Continuous f) {m : ∀ i, E i} {i : ι} (hi : ‖m i‖ = 0) :
‖f m‖ = 0 := by
classical
rw [← inseparable_zero_iff_norm] at hi ⊢
have : Inseparable (update m i 0) m := inseparable_pi.2 <|
(forall_update_iff m fun i a ↦ Inseparable a (m i)).2 ⟨hi.symm, fun _ _ ↦ rfl⟩
simpa only [map_update_zero] using this.symm.map hf
theorem bound_of_shell_of_norm_map_coord_zero (hf₀ : ∀ {m i}, ‖m i‖ = 0 → ‖f m‖ = 0)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
rcases em (∃ i, ‖m i‖ = 0) with (⟨i, hi⟩ | hm)
· rw [hf₀ hi, prod_eq_zero (mem_univ i) hi, mul_zero]
push_neg at hm
choose δ hδ0 hδm_lt hle_δm _ using fun i => rescale_to_shell_semi_normed (hc i) (hε i) (hm i)
have hδ0 : 0 < ∏ i, ‖δ i‖ := prod_pos fun i _ => norm_pos_iff.2 (hδ0 i)
simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hδ0] using
hf (fun i => δ i • m i) hle_δm hδm_lt
/-- If a continuous multilinear map in finitely many variables on normed spaces satisfies
the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i` for some positive
numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`, then it satisfies this inequality for all `m`. -/
theorem bound_of_shell_of_continuous (hfc : Continuous f)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
bound_of_shell_of_norm_map_coord_zero f (norm_map_coord_zero f hfc) hε hc hf m
/-- If a multilinear map in finitely many variables on normed spaces is continuous, then it
satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, for some `C` which can be chosen to be
positive. -/
theorem exists_bound_of_continuous (hf : Continuous f) :
∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
cases isEmpty_or_nonempty ι
· refine ⟨‖f 0‖ + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, fun m => ?_⟩
obtain rfl : m = 0 := funext (IsEmpty.elim ‹_›)
simp [univ_eq_empty, zero_le_one]
obtain ⟨ε : ℝ, ε0 : 0 < ε, hε : ∀ m : ∀ i, E i, ‖m - 0‖ < ε → ‖f m - f 0‖ < 1⟩ :=
NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one
simp only [sub_zero, f.map_zero] at hε
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
have : 0 < (‖c‖ / ε) ^ Fintype.card ι := pow_pos (div_pos (zero_lt_one.trans hc) ε0) _
refine ⟨_, this, ?_⟩
refine f.bound_of_shell_of_continuous hf (fun _ => ε0) (fun _ => hc) fun m hcm hm => ?_
refine (hε m ((pi_norm_lt_iff ε0).2 hm)).le.trans ?_
rw [← div_le_iff' this, one_div, ← inv_pow, inv_div, Fintype.card, ← prod_const]
exact prod_le_prod (fun _ _ => div_nonneg ε0.le (norm_nonneg _)) fun i _ => hcm i
#align multilinear_map.exists_bound_of_continuous MultilinearMap.exists_bound_of_continuous
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a precise but hard to use version. See
`norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads
`‖f m - f m'‖ ≤
C * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
theorem norm_image_sub_le_of_bound' [DecidableEq ι] {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A :
∀ s : Finset ι,
‖f m₁ - f (s.piecewise m₂ m₁)‖ ≤
C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
intro s
induction' s using Finset.induction with i s his Hrec
· simp
have I :
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ ≤
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A : (insert i s).piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₂ i) :=
s.piecewise_insert _ _ _
have B : s.piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₁ i) := by
simp [eq_update_iff, his]
rw [B, A, ← f.map_sub]
apply le_trans (H _)
gcongr with j
· exact fun j _ => norm_nonneg _
by_cases h : j = i
· rw [h]
simp
· by_cases h' : j ∈ s <;> simp [h', h, le_refl]
calc
‖f m₁ - f ((insert i s).piecewise m₂ m₁)‖ ≤
‖f m₁ - f (s.piecewise m₂ m₁)‖ +
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ := by
rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm]
exact dist_triangle _ _ _
_ ≤ (C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) +
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
(add_le_add Hrec I)
_ = C * ∑ i ∈ insert i s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
simp [his, add_comm, left_distrib]
convert A univ
simp
#align multilinear_map.norm_image_sub_le_of_bound' MultilinearMap.norm_image_sub_le_of_bound'
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a usable but not very precise version. See
`norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is
`‖f m - f m'‖ ≤ C * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/
theorem norm_image_sub_le_of_bound {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
classical
have A :
∀ i : ι,
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
intro i
calc
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
∏ j : ι, Function.update (fun _ => max ‖m₁‖ ‖m₂‖) i ‖m₁ - m₂‖ j := by
apply Finset.prod_le_prod
· intro j _
by_cases h : j = i <;> simp [h, norm_nonneg]
· intro j _
by_cases h : j = i
· rw [h]
simp only [ite_true, Function.update_same]
exact norm_le_pi_norm (m₁ - m₂) i
· simp [h, -le_max_iff, -max_le_iff, max_le_max, norm_le_pi_norm (_ : ∀ i, E i)]
_ = ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
rw [prod_update_of_mem (Finset.mem_univ _)]
simp [card_univ_diff]
calc
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
f.norm_image_sub_le_of_bound' hC H m₁ m₂
_ ≤ C * ∑ _i, ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by gcongr; apply A
_ = C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
rw [sum_const, card_univ, nsmul_eq_mul]
ring
#align multilinear_map.norm_image_sub_le_of_bound MultilinearMap.norm_image_sub_le_of_bound
/-- If a multilinear map satisfies an inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, then it is
continuous. -/
theorem continuous_of_bound (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : Continuous f := by
let D := max C 1
have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _)
replace H (m) : ‖f m‖ ≤ D * ∏ i, ‖m i‖ :=
(H m).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity)
refine continuous_iff_continuousAt.2 fun m => ?_
refine
continuousAt_of_locally_lipschitz zero_lt_one
(D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1)) fun m' h' => ?_
rw [dist_eq_norm, dist_eq_norm]
have : max ‖m'‖ ‖m‖ ≤ ‖m‖ + 1 := by
simp [zero_le_one, norm_le_of_mem_closedBall (le_of_lt h')]
calc
‖f m' - f m‖ ≤ D * Fintype.card ι * max ‖m'‖ ‖m‖ ^ (Fintype.card ι - 1) * ‖m' - m‖ :=
f.norm_image_sub_le_of_bound D_pos H m' m
_ ≤ D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1) * ‖m' - m‖ := by gcongr
#align multilinear_map.continuous_of_bound MultilinearMap.continuous_of_bound
/-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness
condition. -/
def mkContinuous (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ContinuousMultilinearMap 𝕜 E G :=
{ f with cont := f.continuous_of_bound C H }
#align multilinear_map.mk_continuous MultilinearMap.mkContinuous
@[simp]
theorem coe_mkContinuous (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ⇑(f.mkContinuous C H) = f :=
rfl
#align multilinear_map.coe_mk_continuous MultilinearMap.coe_mkContinuous
/-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on
the other coordinates, then the resulting restricted function satisfies an inequality
`‖f.restr v‖ ≤ C * ‖z‖^(n-k) * Π ‖v i‖` if the original function satisfies `‖f v‖ ≤ C * Π ‖v i‖`. -/
theorem restr_norm_le {k n : ℕ} (f : (MultilinearMap 𝕜 (fun _ : Fin n => G) G' : _))
(s : Finset (Fin n)) (hk : s.card = k) (z : G) {C : ℝ} (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(v : Fin k → G) : ‖f.restr s hk z v‖ ≤ C * ‖z‖ ^ (n - k) * ∏ i, ‖v i‖ := by
rw [mul_right_comm, mul_assoc]
convert H _ using 2
simp only [apply_dite norm, Fintype.prod_dite, prod_const ‖z‖, Finset.card_univ,
Fintype.card_of_subtype sᶜ fun _ => mem_compl, card_compl, Fintype.card_fin, hk, mk_coe, ←
(s.orderIsoOfFin hk).symm.bijective.prod_comp fun x => ‖v x‖]
convert rfl
#align multilinear_map.restr_norm_le MultilinearMap.restr_norm_le
end MultilinearMap
/-!
### Continuous multilinear maps
We define the norm `‖f‖` of a continuous multilinear map `f` in finitely many variables as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. We show that this
defines a normed space structure on `ContinuousMultilinearMap 𝕜 E G`.
-/
namespace ContinuousMultilinearMap
variable (c : 𝕜) (f g : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i)
theorem bound : ∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
f.toMultilinearMap.exists_bound_of_continuous f.2
#align continuous_multilinear_map.bound ContinuousMultilinearMap.bound
open Real
/-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/
def opNorm :=
sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ }
#align continuous_multilinear_map.op_norm ContinuousMultilinearMap.opNorm
instance hasOpNorm : Norm (ContinuousMultilinearMap 𝕜 E G) :=
⟨opNorm⟩
#align continuous_multilinear_map.has_op_norm ContinuousMultilinearMap.hasOpNorm
/-- An alias of `ContinuousMultilinearMap.hasOpNorm` with non-dependent types to help typeclass
search. -/
instance hasOpNorm' : Norm (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.hasOpNorm
#align continuous_multilinear_map.has_op_norm' ContinuousMultilinearMap.hasOpNorm'
theorem norm_def : ‖f‖ = sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
rfl
#align continuous_multilinear_map.norm_def ContinuousMultilinearMap.norm_def
-- So that invocations of `le_csInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
theorem bounds_nonempty {f : ContinuousMultilinearMap 𝕜 E G} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
let ⟨M, hMp, hMb⟩ := f.bound
⟨M, le_of_lt hMp, hMb⟩
#align continuous_multilinear_map.bounds_nonempty ContinuousMultilinearMap.bounds_nonempty
theorem bounds_bddBelow {f : ContinuousMultilinearMap 𝕜 E G} :
BddBelow { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
#align continuous_multilinear_map.bounds_bdd_below ContinuousMultilinearMap.bounds_bddBelow
theorem isLeast_opNorm : IsLeast {c : ℝ | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} ‖f‖ := by
refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow
simp only [Set.setOf_and, Set.setOf_forall]
exact isClosed_Ici.inter (isClosed_iInter fun m ↦
isClosed_le continuous_const (continuous_id.mul continuous_const))
@[deprecated (since := "2024-02-02")] alias isLeast_op_norm := isLeast_opNorm
theorem opNorm_nonneg : 0 ≤ ‖f‖ :=
Real.sInf_nonneg _ fun _ ⟨hx, _⟩ => hx
#align continuous_multilinear_map.op_norm_nonneg ContinuousMultilinearMap.opNorm_nonneg
@[deprecated (since := "2024-02-02")] alias op_norm_nonneg := opNorm_nonneg
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`. -/
theorem le_opNorm : ‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖ := f.isLeast_opNorm.1.2 m
#align continuous_multilinear_map.le_op_norm ContinuousMultilinearMap.le_opNorm
@[deprecated (since := "2024-02-02")] alias le_op_norm := le_opNorm
variable {f m}
theorem le_mul_prod_of_le_opNorm_of_le {C : ℝ} {b : ι → ℝ} (hC : ‖f‖ ≤ C) (hm : ∀ i, ‖m i‖ ≤ b i) :
‖f m‖ ≤ C * ∏ i, b i :=
(f.le_opNorm m).trans <| mul_le_mul hC (prod_le_prod (fun _ _ ↦ norm_nonneg _) fun _ _ ↦ hm _)
(by positivity) ((opNorm_nonneg _).trans hC)
@[deprecated (since := "2024-02-02")]
alias le_mul_prod_of_le_op_norm_of_le := le_mul_prod_of_le_opNorm_of_le
variable (f)
theorem le_opNorm_mul_prod_of_le {b : ι → ℝ} (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ ‖f‖ * ∏ i, b i :=
le_mul_prod_of_le_opNorm_of_le le_rfl hm
#align continuous_multilinear_map.le_op_norm_mul_prod_of_le ContinuousMultilinearMap.le_opNorm_mul_prod_of_le
@[deprecated (since := "2024-02-02")] alias le_op_norm_mul_prod_of_le := le_opNorm_mul_prod_of_le
theorem le_opNorm_mul_pow_card_of_le {b : ℝ} (hm : ‖m‖ ≤ b) :
‖f m‖ ≤ ‖f‖ * b ^ Fintype.card ι := by
simpa only [prod_const] using f.le_opNorm_mul_prod_of_le fun i => (norm_le_pi_norm m i).trans hm
#align continuous_multilinear_map.le_op_norm_mul_pow_card_of_le ContinuousMultilinearMap.le_opNorm_mul_pow_card_of_le
@[deprecated (since := "2024-02-02")]
alias le_op_norm_mul_pow_card_of_le := le_opNorm_mul_pow_card_of_le
theorem le_opNorm_mul_pow_of_le {n : ℕ} {Ei : Fin n → Type*} [∀ i, SeminormedAddCommGroup (Ei i)]
[∀ i, NormedSpace 𝕜 (Ei i)] (f : ContinuousMultilinearMap 𝕜 Ei G) {m : ∀ i, Ei i} {b : ℝ}
(hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ n := by
simpa only [Fintype.card_fin] using f.le_opNorm_mul_pow_card_of_le hm
#align continuous_multilinear_map.le_op_norm_mul_pow_of_le ContinuousMultilinearMap.le_opNorm_mul_pow_of_le
@[deprecated (since := "2024-02-02")] alias le_op_norm_mul_pow_of_le := le_opNorm_mul_pow_of_le
variable {f} (m)
theorem le_of_opNorm_le {C : ℝ} (h : ‖f‖ ≤ C) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
le_mul_prod_of_le_opNorm_of_le h fun _ ↦ le_rfl
#align continuous_multilinear_map.le_of_op_norm_le ContinuousMultilinearMap.le_of_opNorm_le
@[deprecated (since := "2024-02-02")] alias le_of_op_norm_le := le_of_opNorm_le
variable (f)
theorem ratio_le_opNorm : (‖f m‖ / ∏ i, ‖m i‖) ≤ ‖f‖ :=
div_le_of_nonneg_of_le_mul (by positivity) (opNorm_nonneg _) (f.le_opNorm m)
#align continuous_multilinear_map.ratio_le_op_norm ContinuousMultilinearMap.ratio_le_opNorm
@[deprecated (since := "2024-02-02")] alias ratio_le_op_norm := ratio_le_opNorm
/-- The image of the unit ball under a continuous multilinear map is bounded. -/
theorem unit_le_opNorm (h : ‖m‖ ≤ 1) : ‖f m‖ ≤ ‖f‖ :=
(le_opNorm_mul_pow_card_of_le f h).trans <| by simp
#align continuous_multilinear_map.unit_le_op_norm ContinuousMultilinearMap.unit_le_opNorm
@[deprecated (since := "2024-02-02")] alias unit_le_op_norm := unit_le_opNorm
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
theorem opNorm_le_bound {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ m, ‖f m‖ ≤ M * ∏ i, ‖m i‖) : ‖f‖ ≤ M :=
csInf_le bounds_bddBelow ⟨hMp, hM⟩
#align continuous_multilinear_map.op_norm_le_bound ContinuousMultilinearMap.opNorm_le_bound
@[deprecated (since := "2024-02-02")] alias op_norm_le_bound := opNorm_le_bound
theorem opNorm_le_iff {C : ℝ} (hC : 0 ≤ C) : ‖f‖ ≤ C ↔ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
⟨fun h _ ↦ le_of_opNorm_le _ h, opNorm_le_bound _ hC⟩
@[deprecated (since := "2024-02-02")] alias op_norm_le_iff := opNorm_le_iff
/-- The operator norm satisfies the triangle inequality. -/
theorem opNorm_add_le : ‖f + g‖ ≤ ‖f‖ + ‖g‖ :=
opNorm_le_bound _ (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) fun x => by
rw [add_mul]
exact norm_add_le_of_le (le_opNorm _ _) (le_opNorm _ _)
#align continuous_multilinear_map.op_norm_add_le ContinuousMultilinearMap.opNorm_add_le
@[deprecated (since := "2024-02-02")] alias op_norm_add_le := opNorm_add_le
theorem opNorm_zero : ‖(0 : ContinuousMultilinearMap 𝕜 E G)‖ = 0 :=
(opNorm_nonneg _).antisymm' <| opNorm_le_bound 0 le_rfl fun m => by simp
#align continuous_multilinear_map.op_norm_zero ContinuousMultilinearMap.opNorm_zero
@[deprecated (since := "2024-02-02")] alias op_norm_zero := opNorm_zero
section
variable {𝕜' : Type*} [NormedField 𝕜'] [NormedSpace 𝕜' G] [SMulCommClass 𝕜 𝕜' G]
theorem opNorm_smul_le (c : 𝕜') : ‖c • f‖ ≤ ‖c‖ * ‖f‖ :=
(c • f).opNorm_le_bound (mul_nonneg (norm_nonneg _) (opNorm_nonneg _)) fun m ↦ by
rw [smul_apply, norm_smul, mul_assoc]
exact mul_le_mul_of_nonneg_left (le_opNorm _ _) (norm_nonneg _)
#align continuous_multilinear_map.op_norm_smul_le ContinuousMultilinearMap.opNorm_smul_le
@[deprecated (since := "2024-02-02")] alias op_norm_smul_le := opNorm_smul_le
theorem opNorm_neg : ‖-f‖ = ‖f‖ := by
rw [norm_def]
apply congr_arg
ext
simp
#align continuous_multilinear_map.op_norm_neg ContinuousMultilinearMap.opNorm_neg
@[deprecated (since := "2024-02-02")] alias op_norm_neg := opNorm_neg
variable (𝕜 E G) in
/-- Operator seminorm on the space of continuous multilinear maps, as `Seminorm`.
We use this seminorm
to define a `SeminormedAddCommGroup` structure on `ContinuousMultilinearMap 𝕜 E G`,
but we have to override the projection `UniformSpace`
so that it is definitionally equal to the one coming from the topologies on `E` and `G`. -/
protected def seminorm : Seminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G) :=
.ofSMulLE norm opNorm_zero opNorm_add_le fun c f ↦ opNorm_smul_le f c
private lemma uniformity_eq_seminorm :
𝓤 (ContinuousMultilinearMap 𝕜 E G) = ⨅ r > 0, 𝓟 {f | ‖f.1 - f.2‖ < r} := by
refine (ContinuousMultilinearMap.seminorm 𝕜 E G).uniformity_eq_of_hasBasis
(ContinuousMultilinearMap.hasBasis_nhds_zero_of_basis Metric.nhds_basis_closedBall)
?_ fun (s, r) ⟨hs, hr⟩ ↦ ?_
· rcases NormedField.exists_lt_norm 𝕜 1 with ⟨c, hc⟩
have hc₀ : 0 < ‖c‖ := one_pos.trans hc
simp only [hasBasis_nhds_zero.mem_iff, Prod.exists]
use 1, closedBall 0 ‖c‖, closedBall 0 1
suffices ∀ f : ContinuousMultilinearMap 𝕜 E G, (∀ x, ‖x‖ ≤ ‖c‖ → ‖f x‖ ≤ 1) → ‖f‖ ≤ 1 by
simpa [NormedSpace.isVonNBounded_closedBall, closedBall_mem_nhds, Set.subset_def, Set.MapsTo]
intro f hf
refine opNorm_le_bound _ (by positivity) <|
f.1.bound_of_shell_of_continuous f.2 (fun _ ↦ hc₀) (fun _ ↦ hc) fun x hcx hx ↦ ?_
calc
‖f x‖ ≤ 1 := hf _ <| (pi_norm_le_iff_of_nonneg (norm_nonneg c)).2 fun i ↦ (hx i).le
_ = ∏ i : ι, 1 := by simp
_ ≤ ∏ i, ‖x i‖ := Finset.prod_le_prod (fun _ _ ↦ zero_le_one) fun i _ ↦ by
simpa only [div_self hc₀.ne'] using hcx i
_ = 1 * ∏ i, ‖x i‖ := (one_mul _).symm
· rcases (NormedSpace.isVonNBounded_iff' _).1 hs with ⟨ε, hε⟩
rcases exists_pos_mul_lt hr (ε ^ Fintype.card ι) with ⟨δ, hδ₀, hδ⟩
refine ⟨δ, hδ₀, fun f hf x hx ↦ ?_⟩
simp only [Seminorm.mem_ball_zero, mem_closedBall_zero_iff] at hf ⊢
replace hf : ‖f‖ ≤ δ := hf.le
replace hx : ‖x‖ ≤ ε := hε x hx
calc
‖f x‖ ≤ ‖f‖ * ε ^ Fintype.card ι := le_opNorm_mul_pow_card_of_le f hx
_ ≤ δ * ε ^ Fintype.card ι := by have := (norm_nonneg x).trans hx; gcongr
_ ≤ r := (mul_comm _ _).trans_le hδ.le
instance instPseudoMetricSpace : PseudoMetricSpace (ContinuousMultilinearMap 𝕜 E G) :=
.replaceUniformity
(ContinuousMultilinearMap.seminorm 𝕜 E G).toSeminormedAddCommGroup.toPseudoMetricSpace
uniformity_eq_seminorm
/-- Continuous multilinear maps themselves form a seminormed space with respect to
the operator norm. -/
instance seminormedAddCommGroup :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 E G) := ⟨fun _ _ ↦ rfl⟩
/-- An alias of `ContinuousMultilinearMap.seminormedAddCommGroup` with non-dependent types to help
typeclass search. -/
instance seminormedAddCommGroup' :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.seminormedAddCommGroup
instance normedSpace : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 E G) :=
⟨fun c f => f.opNorm_smul_le c⟩
#align continuous_multilinear_map.normed_space ContinuousMultilinearMap.normedSpace
/-- An alias of `ContinuousMultilinearMap.normedSpace` with non-dependent types to help typeclass
search. -/
instance normedSpace' : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 (fun _ : ι => G') G) :=
ContinuousMultilinearMap.normedSpace
#align continuous_multilinear_map.normed_space' ContinuousMultilinearMap.normedSpace'
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`, `nnnorm` version. -/
theorem le_opNNNorm : ‖f m‖₊ ≤ ‖f‖₊ * ∏ i, ‖m i‖₊ :=
NNReal.coe_le_coe.1 <| by
push_cast
exact f.le_opNorm m
#align continuous_multilinear_map.le_op_nnnorm ContinuousMultilinearMap.le_opNNNorm
@[deprecated (since := "2024-02-02")] alias le_op_nnnorm := le_opNNNorm
theorem le_of_opNNNorm_le {C : ℝ≥0} (h : ‖f‖₊ ≤ C) : ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ :=
(f.le_opNNNorm m).trans <| mul_le_mul' h le_rfl
#align continuous_multilinear_map.le_of_op_nnnorm_le ContinuousMultilinearMap.le_of_opNNNorm_le
@[deprecated (since := "2024-02-02")] alias le_of_op_nnnorm_le := le_of_opNNNorm_le
theorem opNNNorm_le_iff {C : ℝ≥0} : ‖f‖₊ ≤ C ↔ ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := by
simp only [← NNReal.coe_le_coe]; simp [opNorm_le_iff _ C.coe_nonneg, NNReal.coe_prod]
@[deprecated (since := "2024-02-02")] alias op_nnnorm_le_iff := opNNNorm_le_iff
theorem isLeast_opNNNorm : IsLeast {C : ℝ≥0 | ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊} ‖f‖₊ := by
simpa only [← opNNNorm_le_iff] using isLeast_Ici
@[deprecated (since := "2024-02-02")] alias isLeast_op_nnnorm := isLeast_opNNNorm
theorem opNNNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖₊ = max ‖f‖₊ ‖g‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by
simp only [opNNNorm_le_iff, prod_apply, Prod.nnnorm_def', max_le_iff, forall_and]
@[deprecated (since := "2024-02-02")] alias op_nnnorm_prod := opNNNorm_prod
theorem opNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖ = max ‖f‖ ‖g‖ :=
congr_arg NNReal.toReal (opNNNorm_prod f g)
#align continuous_multilinear_map.op_norm_prod ContinuousMultilinearMap.opNorm_prod
@[deprecated (since := "2024-02-02")] alias op_norm_prod := opNorm_prod
theorem opNNNorm_pi
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) : ‖pi f‖₊ = ‖f‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by simpa [opNNNorm_le_iff, pi_nnnorm_le_iff] using forall_swap
theorem opNorm_pi {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'}
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) :
‖pi f‖ = ‖f‖ :=
congr_arg NNReal.toReal (opNNNorm_pi f)
#align continuous_multilinear_map.norm_pi ContinuousMultilinearMap.opNorm_pi
@[deprecated (since := "2024-02-02")] alias op_norm_pi := opNorm_pi
section
@[simp]
theorem norm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') :
‖ofSubsingleton 𝕜 G G' i f‖ = ‖f‖ := by
letI : Unique ι := uniqueOfSubsingleton i
simp [norm_def, ContinuousLinearMap.norm_def, (Equiv.funUnique _ _).symm.surjective.forall]
@[simp]
theorem nnnorm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') :
‖ofSubsingleton 𝕜 G G' i f‖₊ = ‖f‖₊ :=
NNReal.eq <| norm_ofSubsingleton i f
variable (𝕜 G)
/-- Linear isometry between continuous linear maps from `G` to `G'`
and continuous `1`-multilinear maps from `G` to `G'`. -/
@[simps apply symm_apply]
def ofSubsingletonₗᵢ [Subsingleton ι] (i : ι) :
(G →L[𝕜] G') ≃ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ G) G' :=
{ ofSubsingleton 𝕜 G G' i with
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl
norm_map' := norm_ofSubsingleton i }
theorem norm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) :
‖ofSubsingleton 𝕜 G G i (.id _ _)‖ ≤ 1 := by
rw [norm_ofSubsingleton]
apply ContinuousLinearMap.norm_id_le
#align continuous_multilinear_map.norm_of_subsingleton_le ContinuousMultilinearMap.norm_ofSubsingleton_id_le
theorem nnnorm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) :
‖ofSubsingleton 𝕜 G G i (.id _ _)‖₊ ≤ 1 :=
norm_ofSubsingleton_id_le _ _ _
#align continuous_multilinear_map.nnnorm_of_subsingleton_le ContinuousMultilinearMap.nnnorm_ofSubsingleton_id_le
variable {G} (E)
@[simp]
theorem norm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖ = ‖x‖ := by
apply le_antisymm
· refine opNorm_le_bound _ (norm_nonneg _) fun x => ?_
rw [Fintype.prod_empty, mul_one, constOfIsEmpty_apply]
· simpa using (constOfIsEmpty 𝕜 E x).le_opNorm 0
#align continuous_multilinear_map.norm_const_of_is_empty ContinuousMultilinearMap.norm_constOfIsEmpty
@[simp]
theorem nnnorm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖₊ = ‖x‖₊ :=
NNReal.eq <| norm_constOfIsEmpty _ _ _
#align continuous_multilinear_map.nnnorm_const_of_is_empty ContinuousMultilinearMap.nnnorm_constOfIsEmpty
end
section
variable (𝕜 E E' G G')
/-- `ContinuousMultilinearMap.prod` as a `LinearIsometryEquiv`. -/
def prodL :
ContinuousMultilinearMap 𝕜 E G × ContinuousMultilinearMap 𝕜 E G' ≃ₗᵢ[𝕜]
ContinuousMultilinearMap 𝕜 E (G × G') where
toFun f := f.1.prod f.2
invFun f :=
((ContinuousLinearMap.fst 𝕜 G G').compContinuousMultilinearMap f,
(ContinuousLinearMap.snd 𝕜 G G').compContinuousMultilinearMap f)
map_add' f g := rfl
map_smul' c f := rfl
left_inv f := by ext <;> rfl
right_inv f := by ext <;> rfl
norm_map' f := opNorm_prod f.1 f.2
set_option linter.uppercaseLean3 false in
#align continuous_multilinear_map.prodL ContinuousMultilinearMap.prodL
/-- `ContinuousMultilinearMap.pi` as a `LinearIsometryEquiv`. -/
def piₗᵢ {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'} [∀ i', NormedAddCommGroup (E' i')]
[∀ i', NormedSpace 𝕜 (E' i')] :
@LinearIsometryEquiv 𝕜 𝕜 _ _ (RingHom.id 𝕜) _ _ _ (∀ i', ContinuousMultilinearMap 𝕜 E (E' i'))
(ContinuousMultilinearMap 𝕜 E (∀ i, E' i)) _ _ (@Pi.module ι' _ 𝕜 _ _ fun _ => inferInstance)
_ where
toLinearEquiv := piLinearEquiv
norm_map' := opNorm_pi
#align continuous_multilinear_map.piₗᵢ ContinuousMultilinearMap.piₗᵢ
end
end
section RestrictScalars
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜]
variable [NormedSpace 𝕜' G] [IsScalarTower 𝕜' 𝕜 G]
variable [∀ i, NormedSpace 𝕜' (E i)] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)]
@[simp]
theorem norm_restrictScalars : ‖f.restrictScalars 𝕜'‖ = ‖f‖ := rfl
#align continuous_multilinear_map.norm_restrict_scalars ContinuousMultilinearMap.norm_restrictScalars
variable (𝕜')
/-- `ContinuousMultilinearMap.restrictScalars` as a `LinearIsometry`. -/
def restrictScalarsₗᵢ : ContinuousMultilinearMap 𝕜 E G →ₗᵢ[𝕜'] ContinuousMultilinearMap 𝕜' E G where
toFun := restrictScalars 𝕜'
map_add' _ _ := rfl
map_smul' _ _ := rfl
norm_map' _ := rfl
#align continuous_multilinear_map.restrict_scalarsₗᵢ ContinuousMultilinearMap.restrictScalarsₗᵢ
/-- `ContinuousMultilinearMap.restrictScalars` as a `ContinuousLinearMap`. -/
def restrictScalarsLinear : ContinuousMultilinearMap 𝕜 E G →L[𝕜'] ContinuousMultilinearMap 𝕜' E G :=
(restrictScalarsₗᵢ 𝕜').toContinuousLinearMap
#align continuous_multilinear_map.restrict_scalars_linear ContinuousMultilinearMap.restrictScalarsLinear
variable {𝕜'}
theorem continuous_restrictScalars :
Continuous
(restrictScalars 𝕜' : ContinuousMultilinearMap 𝕜 E G → ContinuousMultilinearMap 𝕜' E G) :=
(restrictScalarsLinear 𝕜').continuous
#align continuous_multilinear_map.continuous_restrict_scalars ContinuousMultilinearMap.continuous_restrictScalars
end RestrictScalars
/-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, precise version.
For a less precise but more usable version, see `norm_image_sub_le`. The bound reads
`‖f m - f m'‖ ≤
‖f‖ * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
theorem norm_image_sub_le' [DecidableEq ι] (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ ‖f‖ * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
f.toMultilinearMap.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_opNorm _ _
#align continuous_multilinear_map.norm_image_sub_le' ContinuousMultilinearMap.norm_image_sub_le'
/-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, less precise
version. For a more precise but less usable version, see `norm_image_sub_le'`.
The bound is `‖f m - f m'‖ ≤ ‖f‖ * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/
theorem norm_image_sub_le (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ ‖f‖ * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ :=
f.toMultilinearMap.norm_image_sub_le_of_bound (norm_nonneg _) f.le_opNorm _ _
#align continuous_multilinear_map.norm_image_sub_le ContinuousMultilinearMap.norm_image_sub_le
/-- Applying a multilinear map to a vector is continuous in both coordinates. -/
theorem continuous_eval : Continuous
fun p : ContinuousMultilinearMap 𝕜 E G × ∀ i, E i => p.1 p.2 := by
apply continuous_iff_continuousAt.2 fun p => ?_
apply
continuousAt_of_locally_lipschitz zero_lt_one
((‖p‖ + 1) * Fintype.card ι * (‖p‖ + 1) ^ (Fintype.card ι - 1) + ∏ i, ‖p.2 i‖) fun q hq => ?_
have : 0 ≤ max ‖q.2‖ ‖p.2‖ := by simp
have : 0 ≤ ‖p‖ + 1 := zero_le_one.trans ((le_add_iff_nonneg_left 1).2 <| norm_nonneg p)
have A : ‖q‖ ≤ ‖p‖ + 1 := norm_le_of_mem_closedBall hq.le
have : max ‖q.2‖ ‖p.2‖ ≤ ‖p‖ + 1 :=
(max_le_max (norm_snd_le q) (norm_snd_le p)).trans (by simp [A, zero_le_one])
have : ∀ i : ι, i ∈ univ → 0 ≤ ‖p.2 i‖ := fun i _ => norm_nonneg _
calc
dist (q.1 q.2) (p.1 p.2) ≤ dist (q.1 q.2) (q.1 p.2) + dist (q.1 p.2) (p.1 p.2) :=
dist_triangle _ _ _
_ = ‖q.1 q.2 - q.1 p.2‖ + ‖q.1 p.2 - p.1 p.2‖ := by rw [dist_eq_norm, dist_eq_norm]
_ ≤ ‖q.1‖ * Fintype.card ι * max ‖q.2‖ ‖p.2‖ ^ (Fintype.card ι - 1) * ‖q.2 - p.2‖ +
‖q.1 - p.1‖ * ∏ i, ‖p.2 i‖ :=
(add_le_add (norm_image_sub_le _ _ _) ((q.1 - p.1).le_opNorm p.2))
_ ≤ (‖p‖ + 1) * Fintype.card ι * (‖p‖ + 1) ^ (Fintype.card ι - 1) * ‖q - p‖ +
‖q - p‖ * ∏ i, ‖p.2 i‖ := by
apply_rules [add_le_add, mul_le_mul, le_refl, le_trans (norm_fst_le q) A, Nat.cast_nonneg,
mul_nonneg, pow_le_pow_left, pow_nonneg, norm_snd_le (q - p), norm_nonneg,
norm_fst_le (q - p), prod_nonneg]
_ = ((‖p‖ + 1) * Fintype.card ι * (‖p‖ + 1) ^ (Fintype.card ι - 1) + ∏ i, ‖p.2 i‖)
* dist q p := by
rw [dist_eq_norm]
ring
#align continuous_multilinear_map.continuous_eval ContinuousMultilinearMap.continuous_eval
end ContinuousMultilinearMap
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mkContinuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
theorem MultilinearMap.mkContinuous_norm_le (f : MultilinearMap 𝕜 E G) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ C :=
ContinuousMultilinearMap.opNorm_le_bound _ hC fun m => H m
#align multilinear_map.mk_continuous_norm_le MultilinearMap.mkContinuous_norm_le
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mkContinuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
theorem MultilinearMap.mkContinuous_norm_le' (f : MultilinearMap 𝕜 E G) {C : ℝ}
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ max C 0 :=
ContinuousMultilinearMap.opNorm_le_bound _ (le_max_right _ _) fun m ↦ (H m).trans <|
mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity
#align multilinear_map.mk_continuous_norm_le' MultilinearMap.mkContinuous_norm_le'
namespace ContinuousMultilinearMap
/-- Given a continuous multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset
`s` of `k` of these variables, one gets a new continuous multilinear map on `Fin k` by varying
these variables, and fixing the other ones equal to a given value `z`. It is denoted by
`f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit
identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/
def restr {k n : ℕ} (f : (G[×n]→L[𝕜] G' : _)) (s : Finset (Fin n)) (hk : s.card = k) (z : G) :
G[×k]→L[𝕜] G' :=
(f.toMultilinearMap.restr s hk z).mkContinuous (‖f‖ * ‖z‖ ^ (n - k)) fun _ =>
MultilinearMap.restr_norm_le _ _ _ _ f.le_opNorm _
#align continuous_multilinear_map.restr ContinuousMultilinearMap.restr
theorem norm_restr {k n : ℕ} (f : G[×n]→L[𝕜] G') (s : Finset (Fin n)) (hk : s.card = k) (z : G) :
‖f.restr s hk z‖ ≤ ‖f‖ * ‖z‖ ^ (n - k) := by
apply MultilinearMap.mkContinuous_norm_le
exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _)
#align continuous_multilinear_map.norm_restr ContinuousMultilinearMap.norm_restr
section
variable {A : Type*} [NormedCommRing A] [NormedAlgebra 𝕜 A]
@[simp]
theorem norm_mkPiAlgebra_le [Nonempty ι] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ ≤ 1 := by
refine opNorm_le_bound _ zero_le_one fun m => ?_
simp only [ContinuousMultilinearMap.mkPiAlgebra_apply, one_mul]
exact norm_prod_le' _ univ_nonempty _
#align continuous_multilinear_map.norm_mk_pi_algebra_le ContinuousMultilinearMap.norm_mkPiAlgebra_le
theorem norm_mkPiAlgebra_of_empty [IsEmpty ι] :
‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = ‖(1 : A)‖ := by
apply le_antisymm
· apply opNorm_le_bound <;> simp
· -- Porting note: have to annotate types to get mvars to unify
convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => (1 : A)
simp [eq_empty_of_isEmpty (univ : Finset ι)]
#align continuous_multilinear_map.norm_mk_pi_algebra_of_empty ContinuousMultilinearMap.norm_mkPiAlgebra_of_empty
@[simp]
theorem norm_mkPiAlgebra [NormOneClass A] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = 1 := by
cases isEmpty_or_nonempty ι
· simp [norm_mkPiAlgebra_of_empty]
· refine le_antisymm norm_mkPiAlgebra_le ?_
convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => 1
simp
#align continuous_multilinear_map.norm_mk_pi_algebra ContinuousMultilinearMap.norm_mkPiAlgebra
end
section
variable {n : ℕ} {A : Type*} [NormedRing A] [NormedAlgebra 𝕜 A]
theorem norm_mkPiAlgebraFin_succ_le : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n.succ A‖ ≤ 1 := by
refine opNorm_le_bound _ zero_le_one fun m => ?_
simp only [ContinuousMultilinearMap.mkPiAlgebraFin_apply, one_mul, List.ofFn_eq_map,
Fin.prod_univ_def, Multiset.map_coe, Multiset.prod_coe]
refine (List.norm_prod_le' ?_).trans_eq ?_
· rw [Ne, List.map_eq_nil, List.finRange_eq_nil]
exact Nat.succ_ne_zero _
rw [List.map_map, Function.comp_def]
#align continuous_multilinear_map.norm_mk_pi_algebra_fin_succ_le ContinuousMultilinearMap.norm_mkPiAlgebraFin_succ_le
theorem norm_mkPiAlgebraFin_le_of_pos (hn : 0 < n) :
‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n A‖ ≤ 1 := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'
exact norm_mkPiAlgebraFin_succ_le
#align continuous_multilinear_map.norm_mk_pi_algebra_fin_le_of_pos ContinuousMultilinearMap.norm_mkPiAlgebraFin_le_of_pos
theorem norm_mkPiAlgebraFin_zero : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 0 A‖ = ‖(1 : A)‖ := by
refine le_antisymm ?_ ?_
· refine opNorm_le_bound _ (norm_nonneg (1 : A)) ?_
simp
· convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 0 A) fun _ => (1 : A)
simp
#align continuous_multilinear_map.norm_mk_pi_algebra_fin_zero ContinuousMultilinearMap.norm_mkPiAlgebraFin_zero
@[simp]
theorem norm_mkPiAlgebraFin [NormOneClass A] :
‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n A‖ = 1 := by
cases n
· rw [norm_mkPiAlgebraFin_zero]
simp
· refine le_antisymm norm_mkPiAlgebraFin_succ_le ?_
refine le_of_eq_of_le ?_ <|
ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 (Nat.succ _) A) fun _ => 1
simp
#align continuous_multilinear_map.norm_mk_pi_algebra_fin ContinuousMultilinearMap.norm_mkPiAlgebraFin
end
@[simp]
theorem nnnorm_smulRight (f : ContinuousMultilinearMap 𝕜 E 𝕜) (z : G) :
‖f.smulRight z‖₊ = ‖f‖₊ * ‖z‖₊ := by
refine le_antisymm ?_ ?_
· refine (opNNNorm_le_iff _ |>.2 fun m => (nnnorm_smul_le _ _).trans ?_)
rw [mul_right_comm]
gcongr
exact le_opNNNorm _ _
· obtain hz | hz := eq_or_ne ‖z‖₊ 0
· simp [hz]
rw [← NNReal.le_div_iff hz, opNNNorm_le_iff]
intro m
rw [div_mul_eq_mul_div, NNReal.le_div_iff hz]
refine le_trans ?_ ((f.smulRight z).le_opNNNorm m)
rw [smulRight_apply, nnnorm_smul]
@[simp]
theorem norm_smulRight (f : ContinuousMultilinearMap 𝕜 E 𝕜) (z : G) :
‖f.smulRight z‖ = ‖f‖ * ‖z‖ :=
congr_arg NNReal.toReal (nnnorm_smulRight f z)
@[simp]
theorem norm_mkPiRing (z : G) : ‖ContinuousMultilinearMap.mkPiRing 𝕜 ι z‖ = ‖z‖ := by
rw [ContinuousMultilinearMap.mkPiRing, norm_smulRight, norm_mkPiAlgebra, one_mul]
#align continuous_multilinear_map.norm_mk_pi_field ContinuousMultilinearMap.norm_mkPiRing
variable (𝕜 E G) in
/-- Continuous bilinear map realizing `(f, z) ↦ f.smulRight z`. -/
def smulRightL : ContinuousMultilinearMap 𝕜 E 𝕜 →L[𝕜] G →L[𝕜] ContinuousMultilinearMap 𝕜 E G :=
LinearMap.mkContinuous₂
{ toFun := fun f ↦
{ toFun := fun z ↦ f.smulRight z
map_add' := fun x y ↦ by ext; simp
map_smul' := fun c x ↦ by ext; simp [smul_smul, mul_comm] }
map_add' := fun f g ↦ by ext; simp [add_smul]
map_smul' := fun c f ↦ by ext; simp [smul_smul] }
1 (fun f z ↦ by simp [norm_smulRight])
@[simp] lemma smulRightL_apply (f : ContinuousMultilinearMap 𝕜 E 𝕜) (z : G) :
smulRightL 𝕜 E G f z = f.smulRight z := rfl
#adaptation_note
/--
Before https://github.com/leanprover/lean4/pull/4119 we had to create a local instance:
```
letI : SeminormedAddCommGroup
(ContinuousMultilinearMap 𝕜 E 𝕜 →L[𝕜] G →L[𝕜] ContinuousMultilinearMap 𝕜 E G) :=
ContinuousLinearMap.toSeminormedAddCommGroup
(F := G →L[𝕜] ContinuousMultilinearMap 𝕜 E G) (σ₁₂ := RingHom.id 𝕜)
```
-/
set_option maxSynthPendingDepth 2 in
lemma norm_smulRightL_le : ‖smulRightL 𝕜 E G‖ ≤ 1 :=
LinearMap.mkContinuous₂_norm_le _ zero_le_one _
variable (𝕜 ι G)
/-- Continuous multilinear maps on `𝕜^n` with values in `G` are in bijection with `G`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a linear isometry in
`ContinuousMultilinearMap.piFieldEquiv`. -/
protected def piFieldEquiv : G ≃ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 (fun _ : ι => 𝕜) G where
toFun z := ContinuousMultilinearMap.mkPiRing 𝕜 ι z
invFun f := f fun i => 1
map_add' z z' := by
ext m
simp [smul_add]
map_smul' c z := by
ext m
simp [smul_smul, mul_comm]
left_inv z := by simp
right_inv f := f.mkPiRing_apply_one_eq_self
norm_map' := norm_mkPiRing
#align continuous_multilinear_map.pi_field_equiv ContinuousMultilinearMap.piFieldEquiv
end ContinuousMultilinearMap
namespace ContinuousLinearMap
theorem norm_compContinuousMultilinearMap_le (g : G →L[𝕜] G') (f : ContinuousMultilinearMap 𝕜 E G) :
‖g.compContinuousMultilinearMap f‖ ≤ ‖g‖ * ‖f‖ :=
ContinuousMultilinearMap.opNorm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) fun m =>
calc
‖g (f m)‖ ≤ ‖g‖ * (‖f‖ * ∏ i, ‖m i‖) := g.le_opNorm_of_le <| f.le_opNorm _
_ = _ := (mul_assoc _ _ _).symm
#align continuous_linear_map.norm_comp_continuous_multilinear_map_le ContinuousLinearMap.norm_compContinuousMultilinearMap_le
variable (𝕜 E G G')
set_option linter.uppercaseLean3 false
/-- `ContinuousLinearMap.compContinuousMultilinearMap` as a bundled continuous bilinear map. -/
def compContinuousMultilinearMapL :
(G →L[𝕜] G') →L[𝕜] ContinuousMultilinearMap 𝕜 E G →L[𝕜] ContinuousMultilinearMap 𝕜 E G' :=
LinearMap.mkContinuous₂
(LinearMap.mk₂ 𝕜 compContinuousMultilinearMap (fun f₁ f₂ g => rfl) (fun c f g => rfl)
(fun f g₁ g₂ => by ext1; apply f.map_add)
(fun c f g => by ext1; simp))
1
fun f g => by rw [one_mul]; exact f.norm_compContinuousMultilinearMap_le g
#align continuous_linear_map.comp_continuous_multilinear_mapL ContinuousLinearMap.compContinuousMultilinearMapL
variable {𝕜 G G'}
/-- `ContinuousLinearMap.compContinuousMultilinearMap` as a bundled
continuous linear equiv. -/
nonrec
def _root_.ContinuousLinearEquiv.compContinuousMultilinearMapL (g : G ≃L[𝕜] G') :
ContinuousMultilinearMap 𝕜 E G ≃L[𝕜] ContinuousMultilinearMap 𝕜 E G' :=
{ compContinuousMultilinearMapL 𝕜 E G G' g.toContinuousLinearMap with
invFun := compContinuousMultilinearMapL 𝕜 E G' G g.symm.toContinuousLinearMap
left_inv := by
intro f
ext1 m
simp [compContinuousMultilinearMapL]
right_inv := by
intro f
ext1 m
simp [compContinuousMultilinearMapL]
continuous_toFun := (compContinuousMultilinearMapL 𝕜 E G G' g.toContinuousLinearMap).continuous
continuous_invFun :=
(compContinuousMultilinearMapL 𝕜 E G' G g.symm.toContinuousLinearMap).continuous }
#align continuous_linear_equiv.comp_continuous_multilinear_mapL ContinuousLinearEquiv.compContinuousMultilinearMapL
@[simp]
theorem _root_.ContinuousLinearEquiv.compContinuousMultilinearMapL_symm (g : G ≃L[𝕜] G') :
(g.compContinuousMultilinearMapL E).symm = g.symm.compContinuousMultilinearMapL E :=
rfl
#align continuous_linear_equiv.comp_continuous_multilinear_mapL_symm ContinuousLinearEquiv.compContinuousMultilinearMapL_symm
variable {E}
@[simp]
theorem _root_.ContinuousLinearEquiv.compContinuousMultilinearMapL_apply (g : G ≃L[𝕜] G')
(f : ContinuousMultilinearMap 𝕜 E G) :
g.compContinuousMultilinearMapL E f = (g : G →L[𝕜] G').compContinuousMultilinearMap f :=
rfl
#align continuous_linear_equiv.comp_continuous_multilinear_mapL_apply ContinuousLinearEquiv.compContinuousMultilinearMapL_apply
/-- Flip arguments in `f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E G'` to get
`ContinuousMultilinearMap 𝕜 E (G →L[𝕜] G')` -/
@[simps! apply_apply]
def flipMultilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E G') :
ContinuousMultilinearMap 𝕜 E (G →L[𝕜] G') :=
MultilinearMap.mkContinuous
{ toFun := fun m =>
LinearMap.mkContinuous
{ toFun := fun x => f x m
map_add' := fun x y => by simp only [map_add, ContinuousMultilinearMap.add_apply]
map_smul' := fun c x => by
simp only [ContinuousMultilinearMap.smul_apply, map_smul, RingHom.id_apply] }
(‖f‖ * ∏ i, ‖m i‖) fun x => by
rw [mul_right_comm]
exact (f x).le_of_opNorm_le _ (f.le_opNorm x)
map_add' := fun m i x y => by
ext1
simp only [add_apply, ContinuousMultilinearMap.map_add, LinearMap.coe_mk,
LinearMap.mkContinuous_apply, AddHom.coe_mk]
map_smul' := fun m i c x => by
ext1
simp only [coe_smul', ContinuousMultilinearMap.map_smul, LinearMap.coe_mk,
LinearMap.mkContinuous_apply, Pi.smul_apply, AddHom.coe_mk] }
‖f‖ fun m => by
dsimp only [MultilinearMap.coe_mk]
exact LinearMap.mkContinuous_norm_le _ (by positivity) _
#align continuous_linear_map.flip_multilinear ContinuousLinearMap.flipMultilinear
#align continuous_linear_map.flip_multilinear_apply_apply ContinuousLinearMap.flipMultilinear_apply_apply
end ContinuousLinearMap
theorem LinearIsometry.norm_compContinuousMultilinearMap (g : G →ₗᵢ[𝕜] G')
(f : ContinuousMultilinearMap 𝕜 E G) :
‖g.toContinuousLinearMap.compContinuousMultilinearMap f‖ = ‖f‖ := by
simp only [ContinuousLinearMap.compContinuousMultilinearMap_coe,
LinearIsometry.coe_toContinuousLinearMap, LinearIsometry.norm_map,
ContinuousMultilinearMap.norm_def, Function.comp_apply]
#align linear_isometry.norm_comp_continuous_multilinear_map LinearIsometry.norm_compContinuousMultilinearMap
open ContinuousMultilinearMap
namespace MultilinearMap
/-- Given a map `f : G →ₗ[𝕜] MultilinearMap 𝕜 E G'` and an estimate
`H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖`, construct a continuous linear
map from `G` to `ContinuousMultilinearMap 𝕜 E G'`.
In order to lift, e.g., a map `f : (MultilinearMap 𝕜 E G) →ₗ[𝕜] MultilinearMap 𝕜 E' G'`
to a map `(ContinuousMultilinearMap 𝕜 E G) →L[𝕜] ContinuousMultilinearMap 𝕜 E' G'`,
one can apply this construction to `f.comp ContinuousMultilinearMap.toMultilinearMapLinear`
which is a linear map from `ContinuousMultilinearMap 𝕜 E G` to `MultilinearMap 𝕜 E' G'`. -/
def mkContinuousLinear (f : G →ₗ[𝕜] MultilinearMap 𝕜 E G') (C : ℝ)
(H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : G →L[𝕜] ContinuousMultilinearMap 𝕜 E G' :=
LinearMap.mkContinuous
{ toFun := fun x => (f x).mkContinuous (C * ‖x‖) <| H x
map_add' := fun x y => by
ext1
simp only [_root_.map_add]
rfl
map_smul' := fun c x => by
ext1
simp only [_root_.map_smul]
rfl }
(max C 0) fun x => by
rw [LinearMap.coe_mk, AddHom.coe_mk] -- Porting note: added
exact ((f x).mkContinuous_norm_le' _).trans_eq <| by
rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul]
#align multilinear_map.mk_continuous_linear MultilinearMap.mkContinuousLinear
theorem mkContinuousLinear_norm_le' (f : G →ₗ[𝕜] MultilinearMap 𝕜 E G') (C : ℝ)
(H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : ‖mkContinuousLinear f C H‖ ≤ max C 0 := by
dsimp only [mkContinuousLinear]
exact LinearMap.mkContinuous_norm_le _ (le_max_right _ _) _
#align multilinear_map.mk_continuous_linear_norm_le' MultilinearMap.mkContinuousLinear_norm_le'
theorem mkContinuousLinear_norm_le (f : G →ₗ[𝕜] MultilinearMap 𝕜 E G') {C : ℝ} (hC : 0 ≤ C)
(H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : ‖mkContinuousLinear f C H‖ ≤ C :=
(mkContinuousLinear_norm_le' f C H).trans_eq (max_eq_left hC)
#align multilinear_map.mk_continuous_linear_norm_le MultilinearMap.mkContinuousLinear_norm_le
/-- Given a map `f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)` and an estimate
`H : ∀ m m', ‖f m m'‖ ≤ C * ∏ i, ‖m i‖ * ∏ i, ‖m' i‖`, upgrade all `MultilinearMap`s in the type to
`ContinuousMultilinearMap`s. -/
def mkContinuousMultilinear (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) (C : ℝ)
(H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) :
ContinuousMultilinearMap 𝕜 E (ContinuousMultilinearMap 𝕜 E' G) :=
mkContinuous
{ toFun := fun m => mkContinuous (f m) (C * ∏ i, ‖m i‖) <| H m
map_add' := fun m i x y => by
ext1
simp
map_smul' := fun m i c x => by
ext1
simp }
(max C 0) fun m => by
simp only [coe_mk]
refine ((f m).mkContinuous_norm_le' _).trans_eq ?_
rw [max_mul_of_nonneg, zero_mul]
positivity
#align multilinear_map.mk_continuous_multilinear MultilinearMap.mkContinuousMultilinear
@[simp]
theorem mkContinuousMultilinear_apply (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) {C : ℝ}
(H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) (m : ∀ i, E i) :
⇑(mkContinuousMultilinear f C H m) = f m :=
rfl
#align multilinear_map.mk_continuous_multilinear_apply MultilinearMap.mkContinuousMultilinear_apply
theorem mkContinuousMultilinear_norm_le' (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) (C : ℝ)
(H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) :
‖mkContinuousMultilinear f C H‖ ≤ max C 0 := by
dsimp only [mkContinuousMultilinear]
exact mkContinuous_norm_le _ (le_max_right _ _) _
#align multilinear_map.mk_continuous_multilinear_norm_le' MultilinearMap.mkContinuousMultilinear_norm_le'
theorem mkContinuousMultilinear_norm_le (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) {C : ℝ}
(hC : 0 ≤ C) (H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) :
‖mkContinuousMultilinear f C H‖ ≤ C :=
(mkContinuousMultilinear_norm_le' f C H).trans_eq (max_eq_left hC)
#align multilinear_map.mk_continuous_multilinear_norm_le MultilinearMap.mkContinuousMultilinear_norm_le
end MultilinearMap
namespace ContinuousMultilinearMap
set_option linter.uppercaseLean3 false
theorem norm_compContinuousLinearMap_le (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i →L[𝕜] E₁ i) : ‖g.compContinuousLinearMap f‖ ≤ ‖g‖ * ∏ i, ‖f i‖ :=
opNorm_le_bound _ (by positivity) fun m =>
calc
‖g fun i => f i (m i)‖ ≤ ‖g‖ * ∏ i, ‖f i (m i)‖ := g.le_opNorm _
_ ≤ ‖g‖ * ∏ i, ‖f i‖ * ‖m i‖ :=
(mul_le_mul_of_nonneg_left
(prod_le_prod (fun _ _ => norm_nonneg _) fun i _ => (f i).le_opNorm (m i))
(norm_nonneg g))
_ = (‖g‖ * ∏ i, ‖f i‖) * ∏ i, ‖m i‖ := by rw [prod_mul_distrib, mul_assoc]
#align continuous_multilinear_map.norm_comp_continuous_linear_le ContinuousMultilinearMap.norm_compContinuousLinearMap_le
theorem norm_compContinuous_linearIsometry_le (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i →ₗᵢ[𝕜] E₁ i) :
‖g.compContinuousLinearMap fun i => (f i).toContinuousLinearMap‖ ≤ ‖g‖ := by
refine opNorm_le_bound _ (norm_nonneg _) fun m => ?_
apply (g.le_opNorm _).trans _
simp only [ContinuousLinearMap.coe_coe, LinearIsometry.coe_toContinuousLinearMap,
LinearIsometry.norm_map, le_rfl]
#align continuous_multilinear_map.norm_comp_continuous_linear_isometry_le ContinuousMultilinearMap.norm_compContinuous_linearIsometry_le
theorem norm_compContinuous_linearIsometryEquiv (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i ≃ₗᵢ[𝕜] E₁ i) :
‖g.compContinuousLinearMap fun i => (f i : E i →L[𝕜] E₁ i)‖ = ‖g‖ := by
apply le_antisymm (g.norm_compContinuous_linearIsometry_le fun i => (f i).toLinearIsometry)
have : g = (g.compContinuousLinearMap fun i => (f i : E i →L[𝕜] E₁ i)).compContinuousLinearMap
fun i => ((f i).symm : E₁ i →L[𝕜] E i) := by
ext1 m
simp only [compContinuousLinearMap_apply, LinearIsometryEquiv.coe_coe'',
LinearIsometryEquiv.apply_symm_apply]
conv_lhs => rw [this]
apply (g.compContinuousLinearMap fun i =>
(f i : E i →L[𝕜] E₁ i)).norm_compContinuous_linearIsometry_le
fun i => (f i).symm.toLinearIsometry
#align continuous_multilinear_map.norm_comp_continuous_linear_isometry_equiv ContinuousMultilinearMap.norm_compContinuous_linearIsometryEquiv
/-- `ContinuousMultilinearMap.compContinuousLinearMap` as a bundled continuous linear map.
This implementation fixes `f : Π i, E i →L[𝕜] E₁ i`.
Actually, the map is multilinear in `f`,
see `ContinuousMultilinearMap.compContinuousLinearMapContinuousMultilinear`.
For a version fixing `g` and varying `f`, see `compContinuousLinearMapLRight`. -/
def compContinuousLinearMapL (f : ∀ i, E i →L[𝕜] E₁ i) :
ContinuousMultilinearMap 𝕜 E₁ G →L[𝕜] ContinuousMultilinearMap 𝕜 E G :=
LinearMap.mkContinuous
{ toFun := fun g => g.compContinuousLinearMap f
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
(∏ i, ‖f i‖)
fun _ => (norm_compContinuousLinearMap_le _ _).trans_eq (mul_comm _ _)
#align continuous_multilinear_map.comp_continuous_linear_mapL ContinuousMultilinearMap.compContinuousLinearMapL
@[simp]
theorem compContinuousLinearMapL_apply (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i →L[𝕜] E₁ i) : compContinuousLinearMapL f g = g.compContinuousLinearMap f :=
rfl
#align continuous_multilinear_map.comp_continuous_linear_mapL_apply ContinuousMultilinearMap.compContinuousLinearMapL_apply
variable (G) in
theorem norm_compContinuousLinearMapL_le (f : ∀ i, E i →L[𝕜] E₁ i) :
‖compContinuousLinearMapL (G := G) f‖ ≤ ∏ i, ‖f i‖ :=
LinearMap.mkContinuous_norm_le _ (by positivity) _
#align continuous_multilinear_map.norm_comp_continuous_linear_mapL_le ContinuousMultilinearMap.norm_compContinuousLinearMapL_le
/-- `ContinuousMultilinearMap.compContinuousLinearMap` as a bundled continuous linear map.
This implementation fixes `g : ContinuousMultilinearMap 𝕜 E₁ G`.
Actually, the map is linear in `g`,
see `ContinuousMultilinearMap.compContinuousLinearMapContinuousMultilinear`.
For a version fixing `f` and varying `g`, see `compContinuousLinearMapL`. -/
def compContinuousLinearMapLRight (g : ContinuousMultilinearMap 𝕜 E₁ G) :
ContinuousMultilinearMap 𝕜 (fun i ↦ E i →L[𝕜] E₁ i) (ContinuousMultilinearMap 𝕜 E G) :=
MultilinearMap.mkContinuous
{ toFun := fun f => g.compContinuousLinearMap f
map_add' := by
intro h f i f₁ f₂
ext x
simp only [compContinuousLinearMap_apply, add_apply]
convert g.map_add (fun j ↦ f j (x j)) i (f₁ (x i)) (f₂ (x i)) <;>
exact apply_update (fun (i : ι) (f : E i →L[𝕜] E₁ i) ↦ f (x i)) f i _ _
map_smul' := by
intro h f i a f₀
ext x
simp only [compContinuousLinearMap_apply, smul_apply]
convert g.map_smul (fun j ↦ f j (x j)) i a (f₀ (x i)) <;>
exact apply_update (fun (i : ι) (f : E i →L[𝕜] E₁ i) ↦ f (x i)) f i _ _ }
(‖g‖) (fun f ↦ by simp [norm_compContinuousLinearMap_le])
@[simp]
theorem compContinuousLinearMapLRight_apply (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i →L[𝕜] E₁ i) : compContinuousLinearMapLRight g f = g.compContinuousLinearMap f :=
rfl
variable (E) in
theorem norm_compContinuousLinearMapLRight_le (g : ContinuousMultilinearMap 𝕜 E₁ G) :
‖compContinuousLinearMapLRight (E := E) g‖ ≤ ‖g‖ :=
MultilinearMap.mkContinuous_norm_le _ (norm_nonneg _) _
variable (𝕜 E E₁ G)
open Function in
/-- If `f` is a collection of continuous linear maps, then the construction
`ContinuousMultilinearMap.compContinuousLinearMap`
sending a continuous multilinear map `g` to `g (f₁ ·, ..., fₙ ·)`
is continuous-linear in `g` and multilinear in `f₁, ..., fₙ`. -/
noncomputable def compContinuousLinearMapMultilinear :
MultilinearMap 𝕜 (fun i ↦ E i →L[𝕜] E₁ i)
((ContinuousMultilinearMap 𝕜 E₁ G) →L[𝕜] ContinuousMultilinearMap 𝕜 E G) where
toFun := compContinuousLinearMapL
map_add' f i f₁ f₂ := by
ext g x
change (g fun j ↦ update f i (f₁ + f₂) j <| x j) =
(g fun j ↦ update f i f₁ j <| x j) + g fun j ↦ update f i f₂ j (x j)
convert g.map_add (fun j ↦ f j (x j)) i (f₁ (x i)) (f₂ (x i)) <;>
exact apply_update (fun (i : ι) (f : E i →L[𝕜] E₁ i) ↦ f (x i)) f i _ _
map_smul' f i a f₀ := by
ext g x
change (g fun j ↦ update f i (a • f₀) j <| x j) = a • g fun j ↦ update f i f₀ j (x j)
convert g.map_smul (fun j ↦ f j (x j)) i a (f₀ (x i)) <;>
exact apply_update (fun (i : ι) (f : E i →L[𝕜] E₁ i) ↦ f (x i)) f i _ _
/-- If `f` is a collection of continuous linear maps, then the construction
`ContinuousMultilinearMap.compContinuousLinearMap`
sending a continuous multilinear map `g` to `g (f₁ ·, ..., fₙ ·)` is continuous-linear in `g` and
continuous-multilinear in `f₁, ..., fₙ`. -/
noncomputable def compContinuousLinearMapContinuousMultilinear :
ContinuousMultilinearMap 𝕜 (fun i ↦ E i →L[𝕜] E₁ i)
((ContinuousMultilinearMap 𝕜 E₁ G) →L[𝕜] ContinuousMultilinearMap 𝕜 E G) :=
@MultilinearMap.mkContinuous 𝕜 ι (fun i ↦ E i →L[𝕜] E₁ i)
((ContinuousMultilinearMap 𝕜 E₁ G) →L[𝕜] ContinuousMultilinearMap 𝕜 E G) _ _
(fun _ ↦ ContinuousLinearMap.toSeminormedAddCommGroup)
(fun _ ↦ ContinuousLinearMap.toNormedSpace) _ _
(compContinuousLinearMapMultilinear 𝕜 E E₁ G) 1
fun f ↦ by simpa using norm_compContinuousLinearMapL_le G f
variable {𝕜 E E₁}
/-- `ContinuousMultilinearMap.compContinuousLinearMap` as a bundled continuous linear equiv,
given `f : Π i, E i ≃L[𝕜] E₁ i`. -/
def compContinuousLinearMapEquivL (f : ∀ i, E i ≃L[𝕜] E₁ i) :
ContinuousMultilinearMap 𝕜 E₁ G ≃L[𝕜] ContinuousMultilinearMap 𝕜 E G :=
{ compContinuousLinearMapL fun i => (f i : E i →L[𝕜] E₁ i) with
invFun := compContinuousLinearMapL fun i => ((f i).symm : E₁ i →L[𝕜] E i)
continuous_toFun := (compContinuousLinearMapL fun i => (f i : E i →L[𝕜] E₁ i)).continuous
continuous_invFun :=
(compContinuousLinearMapL fun i => ((f i).symm : E₁ i →L[𝕜] E i)).continuous
left_inv := by
intro g
ext1 m
simp only [LinearMap.toFun_eq_coe, ContinuousLinearMap.coe_coe,
compContinuousLinearMapL_apply, compContinuousLinearMap_apply,
ContinuousLinearEquiv.coe_coe, ContinuousLinearEquiv.apply_symm_apply]
right_inv := by
intro g
ext1 m
simp only [compContinuousLinearMapL_apply, LinearMap.toFun_eq_coe,
ContinuousLinearMap.coe_coe, compContinuousLinearMap_apply,
ContinuousLinearEquiv.coe_coe, ContinuousLinearEquiv.symm_apply_apply] }
#align continuous_multilinear_map.comp_continuous_linear_map_equivL ContinuousMultilinearMap.compContinuousLinearMapEquivL
@[simp]
theorem compContinuousLinearMapEquivL_symm (f : ∀ i, E i ≃L[𝕜] E₁ i) :
(compContinuousLinearMapEquivL G f).symm =
compContinuousLinearMapEquivL G fun i : ι => (f i).symm :=
rfl
#align continuous_multilinear_map.comp_continuous_linear_map_equivL_symm ContinuousMultilinearMap.compContinuousLinearMapEquivL_symm
variable {G}
@[simp]
theorem compContinuousLinearMapEquivL_apply (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i ≃L[𝕜] E₁ i) :
compContinuousLinearMapEquivL G f g =
g.compContinuousLinearMap fun i => (f i : E i →L[𝕜] E₁ i) :=
rfl
#align continuous_multilinear_map.comp_continuous_linear_map_equivL_apply ContinuousMultilinearMap.compContinuousLinearMapEquivL_apply
/-- One of the components of the iterated derivative of a continuous multilinear map. Given a
bijection `e` between a type `α` (typically `Fin k`) and a subset `s` of `ι`, this component is a
continuous multilinear map of `k` vectors `v₁, ..., vₖ`, mapping them
to `f (x₁, (v_{e.symm 2})₂, x₃, ...)`, where at indices `i` in `s` one uses the `i`-th coordinate of
the vector `v_{e.symm i}` and otherwise one uses the `i`-th coordinate of a reference vector `x`.
This is continuous multilinear in the components of `x` outside of `s`, and in the `v_j`. -/
noncomputable def iteratedFDerivComponent {α : Type*} [Fintype α] [DecidableEq ι]
(f : ContinuousMultilinearMap 𝕜 E₁ G) {s : Set ι} (e : α ≃ s) [DecidablePred (· ∈ s)] :
ContinuousMultilinearMap 𝕜 (fun (i : {a : ι // a ∉ s}) ↦ E₁ i)
(ContinuousMultilinearMap 𝕜 (fun (_ : α) ↦ (∀ i, E₁ i)) G) :=
(f.toMultilinearMap.iteratedFDerivComponent e).mkContinuousMultilinear ‖f‖ <| by
intro x m
simp only [MultilinearMap.iteratedFDerivComponent, MultilinearMap.domDomRestrictₗ,
MultilinearMap.coe_mk, MultilinearMap.domDomRestrict_apply, coe_coe]
apply (f.le_opNorm _).trans _
rw [← prod_compl_mul_prod s.toFinset, mul_assoc]
gcongr
· apply le_of_eq
have : ∀ x, x ∈ s.toFinsetᶜ ↔ (fun x ↦ x ∉ s) x := by simp
rw [prod_subtype _ this]
congr with i
simp [i.2]
· rw [prod_subtype _ (fun _ ↦ s.mem_toFinset), ← Equiv.prod_comp e.symm]
apply Finset.prod_le_prod (fun i _ ↦ norm_nonneg _) (fun i _ ↦ ?_)
simpa only [i.2, ↓reduceDite, Subtype.coe_eta] using norm_le_pi_norm (m (e.symm i)) ↑i
@[simp] lemma iteratedFDerivComponent_apply {α : Type*} [Fintype α] [DecidableEq ι]
(f : ContinuousMultilinearMap 𝕜 E₁ G) {s : Set ι} (e : α ≃ s) [DecidablePred (· ∈ s)]
(v : ∀ i : {a : ι // a ∉ s}, E₁ i) (w : α → (∀ i, E₁ i)) :
f.iteratedFDerivComponent e v w =
f (fun j ↦ if h : j ∈ s then w (e.symm ⟨j, h⟩) j else v ⟨j, h⟩) := by
simp [iteratedFDerivComponent, MultilinearMap.iteratedFDerivComponent,
MultilinearMap.domDomRestrictₗ]
lemma norm_iteratedFDerivComponent_le {α : Type*} [Fintype α] [DecidableEq ι]
(f : ContinuousMultilinearMap 𝕜 E₁ G) {s : Set ι} (e : α ≃ s) [DecidablePred (· ∈ s)]
(x : (i : ι) → E₁ i) :
‖f.iteratedFDerivComponent e (x ·)‖ ≤ ‖f‖ * ‖x‖ ^ (Fintype.card ι - Fintype.card α) := calc
‖f.iteratedFDerivComponent e (fun i ↦ x i)‖
≤ ‖f.iteratedFDerivComponent e‖ * ∏ i : {a : ι // a ∉ s}, ‖x i‖ :=
ContinuousMultilinearMap.le_opNorm _ _
_ ≤ ‖f‖ * ∏ _i : {a : ι // a ∉ s}, ‖x‖ := by
gcongr
· exact MultilinearMap.mkContinuousMultilinear_norm_le _ (norm_nonneg _) _
· exact fun _ _ ↦ norm_nonneg _
· exact norm_le_pi_norm _ _
_ = ‖f‖ * ‖x‖ ^ (Fintype.card {a : ι // a ∉ s}) := by rw [prod_const, card_univ]
_ = ‖f‖ * ‖x‖ ^ (Fintype.card ι - Fintype.card α) := by simp [Fintype.card_congr e]
open Classical in
/-- The `k`-th iterated derivative of a continuous multilinear map `f` at the point `x`. It is a
continuous multilinear map of `k` vectors `v₁, ..., vₖ` (with the same type as `x`), mapping them
to `∑ f (x₁, (v_{i₁})₂, x₃, ...)`, where at each index `j` one uses either `xⱼ` or one
of the `(vᵢ)ⱼ`, and each `vᵢ` has to be used exactly once.
The sum is parameterized by the embeddings of `Fin k` in the index type `ι` (or, equivalently,
by the subsets `s` of `ι` of cardinality `k` and then the bijections between `Fin k` and `s`).
The fact that this is indeed the iterated Fréchet derivative is proved in
`ContinuousMultilinearMap.iteratedFDeriv_eq`.
-/
protected def iteratedFDeriv (f : ContinuousMultilinearMap 𝕜 E₁ G) (k : ℕ) (x : (i : ι) → E₁ i) :
ContinuousMultilinearMap 𝕜 (fun (_ : Fin k) ↦ (∀ i, E₁ i)) G :=
∑ e : Fin k ↪ ι, iteratedFDerivComponent f e.toEquivRange (Pi.compRightL 𝕜 _ Subtype.val x)
/-- Controlling the norm of `f.iteratedFDeriv` when `f` is continuous multilinear. For the same
bound on the iterated derivative of `f` in the calculus sense,
see `ContinuousMultilinearMap.norm_iteratedFDeriv_le`. -/
lemma norm_iteratedFDeriv_le' (f : ContinuousMultilinearMap 𝕜 E₁ G) (k : ℕ) (x : (i : ι) → E₁ i) :
‖f.iteratedFDeriv k x‖
≤ Nat.descFactorial (Fintype.card ι) k * ‖f‖ * ‖x‖ ^ (Fintype.card ι - k) := by
classical
calc ‖f.iteratedFDeriv k x‖
_ ≤ ∑ e : Fin k ↪ ι, ‖iteratedFDerivComponent f e.toEquivRange (fun i ↦ x i)‖ := norm_sum_le _ _
_ ≤ ∑ _ : Fin k ↪ ι, ‖f‖ * ‖x‖ ^ (Fintype.card ι - k) := by
gcongr with e _
simpa using norm_iteratedFDerivComponent_le f e.toEquivRange x
_ = Nat.descFactorial (Fintype.card ι) k * ‖f‖ * ‖x‖ ^ (Fintype.card ι - k) := by
simp [card_univ, mul_assoc]
end ContinuousMultilinearMap
end Seminorm
section Norm
namespace ContinuousMultilinearMap
/-! Results that are only true if the target space is a `NormedAddCommGroup` (and not just a
`SeminormedAddCommGroup`). -/
variable {𝕜 : Type u} {ι : Type v} {E : ι → Type wE} {G : Type wG} {G' : Type wG'} [Fintype ι]
[NontriviallyNormedField 𝕜] [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)]
[NormedAddCommGroup G] [NormedSpace 𝕜 G] [SeminormedAddCommGroup G'] [NormedSpace 𝕜 G']
variable (f : ContinuousMultilinearMap 𝕜 E G)
/-- A continuous linear map is zero iff its norm vanishes. -/
theorem opNorm_zero_iff : ‖f‖ = 0 ↔ f = 0 := by
simp [← (opNorm_nonneg f).le_iff_eq, opNorm_le_iff f le_rfl, ext_iff]
#align continuous_multilinear_map.op_norm_zero_iff ContinuousMultilinearMap.opNorm_zero_iff
@[deprecated (since := "2024-02-02")] alias op_norm_zero_iff := opNorm_zero_iff
/-- Continuous multilinear maps themselves form a normed group with respect to
the operator norm. -/
instance normedAddCommGroup : NormedAddCommGroup (ContinuousMultilinearMap 𝕜 E G) :=
NormedAddCommGroup.ofSeparation (fun f ↦ (opNorm_zero_iff f).mp)
#align continuous_multilinear_map.normed_add_comm_group ContinuousMultilinearMap.normedAddCommGroup
/-- An alias of `ContinuousMultilinearMap.normedAddCommGroup` with non-dependent types to help
typeclass search. -/
instance normedAddCommGroup' :
NormedAddCommGroup (ContinuousMultilinearMap 𝕜 (fun _ : ι => G') G) :=
ContinuousMultilinearMap.normedAddCommGroup
#align continuous_multilinear_map.normed_add_comm_group' ContinuousMultilinearMap.normedAddCommGroup'
variable (𝕜 G)
| Mathlib/Analysis/NormedSpace/Multilinear/Basic.lean | 1,428 | 1,429 | theorem norm_ofSubsingleton_id [Subsingleton ι] [Nontrivial G] (i : ι) :
‖ofSubsingleton 𝕜 G G i (.id _ _)‖ = 1 := by | simp
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Topology.Algebra.Constructions
import Mathlib.Topology.Bases
import Mathlib.Topology.UniformSpace.Basic
#align_import topology.uniform_space.cauchy from "leanprover-community/mathlib"@"22131150f88a2d125713ffa0f4693e3355b1eb49"
/-!
# Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets.
-/
universe u v
open scoped Classical
open Filter TopologicalSpace Set UniformSpace Function
open scoped Classical
open Uniformity Topology Filter
variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α]
/-- A filter `f` is Cauchy if for every entourage `r`, there exists an
`s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy
sequences, because if `a : ℕ → α` then the filter of sets containing
cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/
def Cauchy (f : Filter α) :=
NeBot f ∧ f ×ˢ f ≤ 𝓤 α
#align cauchy Cauchy
/-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f`
has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/
def IsComplete (s : Set α) :=
∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x
#align is_complete IsComplete
theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s)
{f : Filter α} :
Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i :=
and_congr Iff.rfl <|
(f.basis_sets.prod_self.le_basis_iff h).trans <| by
simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm]
#align filter.has_basis.cauchy_iff Filter.HasBasis.cauchy_iff
theorem cauchy_iff' {f : Filter α} :
Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s :=
(𝓤 α).basis_sets.cauchy_iff
#align cauchy_iff' cauchy_iff'
theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s :=
cauchy_iff'.trans <| by
simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm]
#align cauchy_iff cauchy_iff
lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] :
Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by
simp only [Cauchy, hl, true_and]
theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) :
Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by
haveI := h.1
have := Ultrafilter.of_le l
exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩
#align cauchy.ultrafilter_of Cauchy.ultrafilter_of
theorem cauchy_map_iff {l : Filter β} {f : β → α} :
Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by
rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto]
#align cauchy_map_iff cauchy_map_iff
theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} :
Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) :=
cauchy_map_iff.trans <| and_iff_right hl
#align cauchy_map_iff' cauchy_map_iff'
theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g :=
⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩
#align cauchy.mono Cauchy.mono
theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g :=
h_c.mono h_le
#align cauchy.mono' Cauchy.mono'
theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) :=
⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩
#align cauchy_nhds cauchy_nhds
theorem cauchy_pure {a : α} : Cauchy (pure a) :=
cauchy_nhds.mono (pure_le_nhds a)
#align cauchy_pure cauchy_pure
theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α}
(h : Tendsto f l (𝓝 a)) : Cauchy (map f l) :=
cauchy_nhds.mono h
#align filter.tendsto.cauchy_map Filter.Tendsto.cauchy_map
lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v)
(hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F :=
⟨hF.1, hF.2.trans huv⟩
lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} :
Cauchy (uniformSpace := u ⊓ v) F ↔
Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by
unfold Cauchy
rw [inf_uniformity (u := u), le_inf_iff, and_and_left]
lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β}
{l : Filter β} :
Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by
unfold Cauchy
rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const]
lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β}
{l : Filter β} [l.NeBot] :
Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by
simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff]
lemma cauchy_comap_uniformSpace {u : UniformSpace β} {f : α → β} {l : Filter α} :
Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by
simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap]
rfl
lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} :
Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by
simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace]
| Mathlib/Topology/UniformSpace/Cauchy.lean | 131 | 134 | theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) :
Cauchy (f ×ˢ g) := by |
have := hf.1; have := hg.1
simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩
|
/-
Copyright (c) 2022 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Kevin Klinge, Andrew Yang
-/
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Field.Defs
import Mathlib.RingTheory.OreLocalization.Basic
#align_import ring_theory.ore_localization.basic from "leanprover-community/mathlib"@"861a26926586cd46ff80264d121cdb6fa0e35cc1"
/-!
# Module and Ring instances of Ore Localizations
The `Monoid` and `DistribMulAction` instances and additive versions are provided in
`RingTheory/OreLocalization/Basic.lean`.
-/
universe u
namespace OreLocalization
section Module
variable {R : Type*} [Semiring R] {S : Submonoid R} [OreSet S]
variable {X : Type*} [AddCommMonoid X] [Module R X]
protected theorem zero_smul (x : X[S⁻¹]) : (0 : R[S⁻¹]) • x = 0 := by
induction' x using OreLocalization.ind with r s
rw [OreLocalization.zero_def, oreDiv_smul_char 0 r 1 s 0 1 (by simp)]; simp
protected theorem add_smul (y z : R[S⁻¹]) (x : X[S⁻¹]) :
(y + z) • x = y • x + z • x := by
induction' x using OreLocalization.ind with r₁ s₁
induction' y using OreLocalization.ind with r₂ s₂
induction' z using OreLocalization.ind with r₃ s₃
rcases oreDivAddChar' r₂ r₃ s₂ s₃ with ⟨ra, sa, ha, q⟩
rw [q]
clear q
rw [OreLocalization.expand' r₂ s₂ sa]
rcases oreDivSMulChar' (sa • r₂) r₁ (sa * s₂) s₁ with ⟨rb, sb, hb, q⟩
rw [q]
clear q
have hs₃rasb : sb * ra * s₃ ∈ S := by
rw [mul_assoc, ← ha]
norm_cast
apply SetLike.coe_mem
rw [OreLocalization.expand _ _ _ hs₃rasb]
have ha' : ↑((sb * sa) * s₂) = sb * ra * s₃ := by simp [ha, mul_assoc]
rw [← Subtype.coe_eq_of_eq_mk ha']
rcases oreDivSMulChar' ((sb * ra) • r₃) r₁ (sb * sa * s₂) s₁ with ⟨rc, sc, hc, hc'⟩
rw [hc']
rw [oreDiv_add_char _ _ 1 sc (by simp [mul_assoc])]
rw [OreLocalization.expand' (sa • r₂ + ra • r₃) (sa * s₂) (sc * sb)]
simp only [smul_eq_mul, one_smul, Submonoid.smul_def, mul_add, Submonoid.coe_mul] at hb hc ⊢
rw [mul_assoc, hb, mul_assoc, ← mul_assoc _ ra, hc, ← mul_assoc, ← add_mul]
rw [OreLocalization.smul_cancel']
simp only [add_smul, ← mul_assoc, smul_smul]
end Module
section Semiring
variable {R : Type*} [Semiring R] {S : Submonoid R} [OreSet S]
attribute [local instance] OreLocalization.oreEqv
protected theorem zero_mul (x : R[S⁻¹]) : 0 * x = 0 :=
OreLocalization.zero_smul x
#align ore_localization.zero_mul OreLocalization.zero_mul
protected theorem mul_zero (x : R[S⁻¹]) : x * 0 = 0 :=
OreLocalization.smul_zero x
#align ore_localization.mul_zero OreLocalization.mul_zero
protected theorem left_distrib (x y z : R[S⁻¹]) : x * (y + z) = x * y + x * z :=
OreLocalization.smul_add _ _ _
#align ore_localization.left_distrib OreLocalization.left_distrib
theorem right_distrib (x y z : R[S⁻¹]) : (x + y) * z = x * z + y * z :=
OreLocalization.add_smul _ _ _
#align ore_localization.right_distrib OreLocalization.right_distrib
instance : Semiring R[S⁻¹] where
__ := inferInstanceAs (Monoid (R[S⁻¹]))
zero_mul := OreLocalization.zero_mul
mul_zero := OreLocalization.mul_zero
left_distrib := OreLocalization.left_distrib
right_distrib := right_distrib
variable {X : Type*} [AddCommMonoid X] [Module R X]
instance : Module R[S⁻¹] X[S⁻¹] where
add_smul := OreLocalization.add_smul
zero_smul := OreLocalization.zero_smul
section UMP
variable {T : Type*} [Semiring T]
variable (f : R →+* T) (fS : S →* Units T)
variable (hf : ∀ s : S, f s = fS s)
/-- The universal lift from a ring homomorphism `f : R →+* T`, which maps elements in `S` to
units of `T`, to a ring homomorphism `R[S⁻¹] →+* T`. This extends the construction on
monoids. -/
def universalHom : R[S⁻¹] →+* T :=
{
universalMulHom f.toMonoidHom fS
hf with
map_zero' := by
-- Porting note: `change` required because of new `Coe`
change (universalMulHom f.toMonoidHom fS hf : R[S⁻¹] → T) 0 = 0
rw [OreLocalization.zero_def, universalMulHom_apply]
simp
map_add' := fun x y => by
-- Porting note: `change` required because of new `Coe`
change (universalMulHom f.toMonoidHom fS hf : R[S⁻¹] → T) (x + y)
= (universalMulHom f.toMonoidHom fS hf : R[S⁻¹] → T) x
+ (universalMulHom f.toMonoidHom fS hf : R[S⁻¹] → T) y
induction' x using OreLocalization.ind with r₁ s₁
induction' y using OreLocalization.ind with r₂ s₂
rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟨r₃, s₃, h₃, h₃'⟩
rw [h₃']
clear h₃'
simp only [RingHom.toMonoidHom_eq_coe, smul_eq_mul, universalMulHom_apply, MonoidHom.coe_coe,
Submonoid.smul_def]
simp only [mul_inv_rev, MonoidHom.map_mul, RingHom.map_add, RingHom.map_mul, Units.val_mul]
rw [mul_add, mul_assoc, ← mul_assoc _ (f s₃), hf, ← Units.val_mul]
simp only [one_mul, mul_left_inv, Units.val_one]
congr 1
rw [← mul_assoc]
congr 1
norm_cast at h₃
have h₃' := Subtype.coe_eq_of_eq_mk h₃
rw [← Units.val_mul, ← mul_inv_rev, ← fS.map_mul, h₃']
rw [Units.inv_mul_eq_iff_eq_mul, Units.eq_mul_inv_iff_mul_eq, ← hf, ← hf]
simp only [map_mul] }
#align ore_localization.universal_hom OreLocalization.universalHom
theorem universalHom_apply {r : R} {s : S} :
universalHom f fS hf (r /ₒ s) = ((fS s)⁻¹ : Units T) * f r :=
rfl
#align ore_localization.universal_hom_apply OreLocalization.universalHom_apply
theorem universalHom_commutes {r : R} : universalHom f fS hf (numeratorHom r) = f r := by
simp [numeratorHom_apply, universalHom_apply]
#align ore_localization.universal_hom_commutes OreLocalization.universalHom_commutes
theorem universalHom_unique (φ : R[S⁻¹] →+* T) (huniv : ∀ r : R, φ (numeratorHom r) = f r) :
φ = universalHom f fS hf :=
RingHom.coe_monoidHom_injective <| universalMulHom_unique (RingHom.toMonoidHom f) fS hf (↑φ) huniv
#align ore_localization.universal_hom_unique OreLocalization.universalHom_unique
end UMP
end Semiring
section Ring
variable {R : Type*} [Ring R] {S : Submonoid R} [OreSet S]
instance : Ring R[S⁻¹] where
__ := inferInstanceAs (Semiring R[S⁻¹])
__ := inferInstanceAs (AddGroup R[S⁻¹])
open nonZeroDivisors
theorem numeratorHom_inj (hS : S ≤ nonZeroDivisorsRight R) :
Function.Injective (numeratorHom : R → R[S⁻¹]) :=
fun r₁ r₂ h => by
rw [numeratorHom_apply, numeratorHom_apply, oreDiv_eq_iff] at h
rcases h with ⟨u, v, h₁, h₂⟩
simp only [S.coe_one, mul_one, Submonoid.smul_def, smul_eq_mul] at h₁ h₂
rw [← h₂, ← sub_eq_zero, ← mul_sub] at h₁
exact (sub_eq_zero.mp (hS u.2 _ h₁)).symm
#align ore_localization.numerator_hom_inj OreLocalization.numeratorHom_inj
| Mathlib/RingTheory/OreLocalization/Ring.lean | 182 | 186 | theorem subsingleton_iff :
Subsingleton R[S⁻¹] ↔ 0 ∈ S := by |
rw [← subsingleton_iff_zero_eq_one, OreLocalization.one_def,
OreLocalization.zero_def, oreDiv_eq_iff]
simp
|
/-
Copyright (c) 2022 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.Polynomial.Mirror
import Mathlib.Analysis.Complex.Polynomial
#align_import data.polynomial.unit_trinomial from "leanprover-community/mathlib"@"302eab4f46abb63de520828de78c04cb0f9b5836"
/-!
# Unit Trinomials
This file defines irreducible trinomials and proves an irreducibility criterion.
## Main definitions
- `Polynomial.IsUnitTrinomial`
## Main results
- `Polynomial.IsUnitTrinomial.irreducible_of_coprime`: An irreducibility criterion for unit
trinomials.
-/
namespace Polynomial
open scoped Polynomial
open Finset
section Semiring
variable {R : Type*} [Semiring R] (k m n : ℕ) (u v w : R)
/-- Shorthand for a trinomial -/
noncomputable def trinomial :=
C u * X ^ k + C v * X ^ m + C w * X ^ n
#align polynomial.trinomial Polynomial.trinomial
theorem trinomial_def : trinomial k m n u v w = C u * X ^ k + C v * X ^ m + C w * X ^ n :=
rfl
#align polynomial.trinomial_def Polynomial.trinomial_def
variable {k m n u v w}
| Mathlib/Algebra/Polynomial/UnitTrinomial.lean | 49 | 52 | theorem trinomial_leading_coeff' (hkm : k < m) (hmn : m < n) :
(trinomial k m n u v w).coeff n = w := by |
rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow,
if_neg (hkm.trans hmn).ne', if_neg hmn.ne', if_pos rfl, zero_add, zero_add]
|
/-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Order.Lattice
import Mathlib.Data.List.Sort
import Mathlib.Logic.Equiv.Fin
import Mathlib.Logic.Equiv.Functor
import Mathlib.Data.Fintype.Card
import Mathlib.Order.RelSeries
#align_import order.jordan_holder from "leanprover-community/mathlib"@"91288e351d51b3f0748f0a38faa7613fb0ae2ada"
/-!
# Jordan-Hölder Theorem
This file proves the Jordan Hölder theorem for a `JordanHolderLattice`, a class also defined in
this file. Examples of `JordanHolderLattice` include `Subgroup G` if `G` is a group, and
`Submodule R M` if `M` is an `R`-module. Using this approach the theorem need not be proved
separately for both groups and modules, the proof in this file can be applied to both.
## Main definitions
The main definitions in this file are `JordanHolderLattice` and `CompositionSeries`,
and the relation `Equivalent` on `CompositionSeries`
A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion
of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that
`H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`.
A `CompositionSeries X` is a finite nonempty series of elements of the lattice `X` such that
each element is maximal inside the next. The length of a `CompositionSeries X` is
one less than the number of elements in the series. Note that there is no stipulation
that a series start from the bottom of the lattice and finish at the top.
For a composition series `s`, `s.last` is the largest element of the series,
and `s.head` is the least element.
Two `CompositionSeries X`, `s₁` and `s₂` are equivalent if there is a bijection
`e : Fin s₁.length ≃ Fin s₂.length` such that for any `i`,
`Iso (s₁ i, s₁ i.succ) (s₂ (e i), s₂ (e i.succ))`
## Main theorems
The main theorem is `CompositionSeries.jordan_holder`, which says that if two composition
series have the same least element and the same largest element,
then they are `Equivalent`.
## TODO
Provide instances of `JordanHolderLattice` for subgroups, and potentially for modular lattices.
It is not entirely clear how this should be done. Possibly there should be no global instances
of `JordanHolderLattice`, and the instances should only be defined locally in order to prove
the Jordan-Hölder theorem for modules/groups and the API should be transferred because many of the
theorems in this file will have stronger versions for modules. There will also need to be an API for
mapping composition series across homomorphisms. It is also probably possible to
provide an instance of `JordanHolderLattice` for any `ModularLattice`, and in this case the
Jordan-Hölder theorem will say that there is a well defined notion of length of a modular lattice.
However an instance of `JordanHolderLattice` for a modular lattice will not be able to contain
the correct notion of isomorphism for modules, so a separate instance for modules will still be
required and this will clash with the instance for modular lattices, and so at least one of these
instances should not be a global instance.
> [!NOTE]
> The previous paragraph indicates that the instance of `JordanHolderLattice` for submodules should
> be obtained via `ModularLattice`. This is not the case in `mathlib4`.
> See `JordanHolderModule.instJordanHolderLattice`.
-/
universe u
open Set RelSeries
/-- A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion
of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that
`H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`.
Examples include `Subgroup G` if `G` is a group, and `Submodule R M` if `M` is an `R`-module.
-/
class JordanHolderLattice (X : Type u) [Lattice X] where
IsMaximal : X → X → Prop
lt_of_isMaximal : ∀ {x y}, IsMaximal x y → x < y
sup_eq_of_isMaximal : ∀ {x y z}, IsMaximal x z → IsMaximal y z → x ≠ y → x ⊔ y = z
isMaximal_inf_left_of_isMaximal_sup :
∀ {x y}, IsMaximal x (x ⊔ y) → IsMaximal y (x ⊔ y) → IsMaximal (x ⊓ y) x
Iso : X × X → X × X → Prop
iso_symm : ∀ {x y}, Iso x y → Iso y x
iso_trans : ∀ {x y z}, Iso x y → Iso y z → Iso x z
second_iso : ∀ {x y}, IsMaximal x (x ⊔ y) → Iso (x, x ⊔ y) (x ⊓ y, y)
#align jordan_holder_lattice JordanHolderLattice
namespace JordanHolderLattice
variable {X : Type u} [Lattice X] [JordanHolderLattice X]
theorem isMaximal_inf_right_of_isMaximal_sup {x y : X} (hxz : IsMaximal x (x ⊔ y))
(hyz : IsMaximal y (x ⊔ y)) : IsMaximal (x ⊓ y) y := by
rw [inf_comm]
rw [sup_comm] at hxz hyz
exact isMaximal_inf_left_of_isMaximal_sup hyz hxz
#align jordan_holder_lattice.is_maximal_inf_right_of_is_maximal_sup JordanHolderLattice.isMaximal_inf_right_of_isMaximal_sup
theorem isMaximal_of_eq_inf (x b : X) {a y : X} (ha : x ⊓ y = a) (hxy : x ≠ y) (hxb : IsMaximal x b)
(hyb : IsMaximal y b) : IsMaximal a y := by
have hb : x ⊔ y = b := sup_eq_of_isMaximal hxb hyb hxy
substs a b
exact isMaximal_inf_right_of_isMaximal_sup hxb hyb
#align jordan_holder_lattice.is_maximal_of_eq_inf JordanHolderLattice.isMaximal_of_eq_inf
| Mathlib/Order/JordanHolder.lean | 116 | 117 | theorem second_iso_of_eq {x y a b : X} (hm : IsMaximal x a) (ha : x ⊔ y = a) (hb : x ⊓ y = b) :
Iso (x, a) (b, y) := by | substs a b; exact second_iso hm
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.HausdorffDistance
import Mathlib.Topology.Sets.Compacts
#align_import topology.metric_space.closeds from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982"
/-!
# Closed subsets
This file defines the metric and emetric space structure on the types of closed subsets and nonempty
compact subsets of a metric or emetric space.
The Hausdorff distance induces an emetric space structure on the type of closed subsets
of an emetric space, called `Closeds`. Its completeness, resp. compactness, resp.
second-countability, follow from the corresponding properties of the original space.
In a metric space, the type of nonempty compact subsets (called `NonemptyCompacts`) also
inherits a metric space structure from the Hausdorff distance, as the Hausdorff edistance is
always finite in this context.
-/
noncomputable section
open scoped Classical
open Topology ENNReal
universe u
open scoped Classical
open Set Function TopologicalSpace Filter
namespace EMetric
section
variable {α : Type u} [EMetricSpace α] {s : Set α}
/-- In emetric spaces, the Hausdorff edistance defines an emetric space structure
on the type of closed subsets -/
instance Closeds.emetricSpace : EMetricSpace (Closeds α) where
edist s t := hausdorffEdist (s : Set α) t
edist_self s := hausdorffEdist_self
edist_comm s t := hausdorffEdist_comm
edist_triangle s t u := hausdorffEdist_triangle
eq_of_edist_eq_zero {s t} h :=
Closeds.ext <| (hausdorffEdist_zero_iff_eq_of_closed s.closed t.closed).1 h
#align emetric.closeds.emetric_space EMetric.Closeds.emetricSpace
/-- The edistance to a closed set depends continuously on the point and the set -/
theorem continuous_infEdist_hausdorffEdist :
Continuous fun p : α × Closeds α => infEdist p.1 p.2 := by
refine continuous_of_le_add_edist 2 (by simp) ?_
rintro ⟨x, s⟩ ⟨y, t⟩
calc
infEdist x s ≤ infEdist x t + hausdorffEdist (t : Set α) s :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ infEdist y t + edist x y + hausdorffEdist (t : Set α) s :=
(add_le_add_right infEdist_le_infEdist_add_edist _)
_ = infEdist y t + (edist x y + hausdorffEdist (s : Set α) t) := by
rw [add_assoc, hausdorffEdist_comm]
_ ≤ infEdist y t + (edist (x, s) (y, t) + edist (x, s) (y, t)) :=
(add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _)
_ = infEdist y t + 2 * edist (x, s) (y, t) := by rw [← mul_two, mul_comm]
set_option linter.uppercaseLean3 false in
#align emetric.continuous_infEdist_hausdorffEdist EMetric.continuous_infEdist_hausdorffEdist
/-- Subsets of a given closed subset form a closed set -/
theorem isClosed_subsets_of_isClosed (hs : IsClosed s) :
IsClosed { t : Closeds α | (t : Set α) ⊆ s } := by
refine isClosed_of_closure_subset fun
(t : Closeds α) (ht : t ∈ closure {t : Closeds α | (t : Set α) ⊆ s}) (x : α) (hx : x ∈ t) => ?_
have : x ∈ closure s := by
refine mem_closure_iff.2 fun ε εpos => ?_
obtain ⟨u : Closeds α, hu : u ∈ {t : Closeds α | (t : Set α) ⊆ s}, Dtu : edist t u < ε⟩ :=
mem_closure_iff.1 ht ε εpos
obtain ⟨y : α, hy : y ∈ u, Dxy : edist x y < ε⟩ := exists_edist_lt_of_hausdorffEdist_lt hx Dtu
exact ⟨y, hu hy, Dxy⟩
rwa [hs.closure_eq] at this
#align emetric.is_closed_subsets_of_is_closed EMetric.isClosed_subsets_of_isClosed
/-- By definition, the edistance on `Closeds α` is given by the Hausdorff edistance -/
theorem Closeds.edist_eq {s t : Closeds α} : edist s t = hausdorffEdist (s : Set α) t :=
rfl
#align emetric.closeds.edist_eq EMetric.Closeds.edist_eq
/-- In a complete space, the type of closed subsets is complete for the
Hausdorff edistance. -/
instance Closeds.completeSpace [CompleteSpace α] : CompleteSpace (Closeds α) := by
/- We will show that, if a sequence of sets `s n` satisfies
`edist (s n) (s (n+1)) < 2^{-n}`, then it converges. This is enough to guarantee
completeness, by a standard completeness criterion.
We use the shorthand `B n = 2^{-n}` in ennreal. -/
let B : ℕ → ℝ≥0∞ := fun n => 2⁻¹ ^ n
have B_pos : ∀ n, (0 : ℝ≥0∞) < B n := by simp [B, ENNReal.pow_pos]
have B_ne_top : ∀ n, B n ≠ ⊤ := by simp [B, ENNReal.pow_ne_top]
/- Consider a sequence of closed sets `s n` with `edist (s n) (s (n+1)) < B n`.
We will show that it converges. The limit set is `t0 = ⋂n, closure (⋃m≥n, s m)`.
We will have to show that a point in `s n` is close to a point in `t0`, and a point
in `t0` is close to a point in `s n`. The completeness then follows from a
standard criterion. -/
refine complete_of_convergent_controlled_sequences B B_pos fun s hs => ?_
let t0 := ⋂ n, closure (⋃ m ≥ n, s m : Set α)
let t : Closeds α := ⟨t0, isClosed_iInter fun _ => isClosed_closure⟩
use t
-- The inequality is written this way to agree with `edist_le_of_edist_le_geometric_of_tendsto₀`
have I1 : ∀ n, ∀ x ∈ s n, ∃ y ∈ t0, edist x y ≤ 2 * B n := by
/- This is the main difficulty of the proof. Starting from `x ∈ s n`, we want
to find a point in `t0` which is close to `x`. Define inductively a sequence of
points `z m` with `z n = x` and `z m ∈ s m` and `edist (z m) (z (m+1)) ≤ B m`. This is
possible since the Hausdorff distance between `s m` and `s (m+1)` is at most `B m`.
This sequence is a Cauchy sequence, therefore converging as the space is complete, to
a limit which satisfies the required properties. -/
intro n x hx
obtain ⟨z, hz₀, hz⟩ :
∃ z : ∀ l, s (n + l), (z 0 : α) = x ∧ ∀ k, edist (z k : α) (z (k + 1) : α) ≤ B n / 2 ^ k := by
-- We prove existence of the sequence by induction.
have : ∀ (l) (z : s (n + l)), ∃ z' : s (n + l + 1), edist (z : α) z' ≤ B n / 2 ^ l := by
intro l z
obtain ⟨z', z'_mem, hz'⟩ : ∃ z' ∈ s (n + l + 1), edist (z : α) z' < B n / 2 ^ l := by
refine exists_edist_lt_of_hausdorffEdist_lt (s := s (n + l)) z.2 ?_
simp only [ENNReal.inv_pow, div_eq_mul_inv]
rw [← pow_add]
apply hs <;> simp
exact ⟨⟨z', z'_mem⟩, le_of_lt hz'⟩
use fun k => Nat.recOn k ⟨x, hx⟩ fun l z => (this l z).choose
simp only [Nat.add_zero, Nat.zero_eq, Nat.rec_zero, Nat.rec_add_one, true_and]
exact fun k => (this k _).choose_spec
-- it follows from the previous bound that `z` is a Cauchy sequence
have : CauchySeq fun k => (z k : α) := cauchySeq_of_edist_le_geometric_two (B n) (B_ne_top n) hz
-- therefore, it converges
rcases cauchySeq_tendsto_of_complete this with ⟨y, y_lim⟩
use y
-- the limit point `y` will be the desired point, in `t0` and close to our initial point `x`.
-- First, we check it belongs to `t0`.
have : y ∈ t0 :=
mem_iInter.2 fun k =>
mem_closure_of_tendsto y_lim
(by
simp only [exists_prop, Set.mem_iUnion, Filter.eventually_atTop, Set.mem_preimage,
Set.preimage_iUnion]
exact ⟨k, fun m hm => ⟨n + m, zero_add k ▸ add_le_add (zero_le n) hm, (z m).2⟩⟩)
use this
-- Then, we check that `y` is close to `x = z n`. This follows from the fact that `y`
-- is the limit of `z k`, and the distance between `z n` and `z k` has already been estimated.
rw [← hz₀]
exact edist_le_of_edist_le_geometric_two_of_tendsto₀ (B n) hz y_lim
have I2 : ∀ n, ∀ x ∈ t0, ∃ y ∈ s n, edist x y ≤ 2 * B n := by
/- For the (much easier) reverse inequality, we start from a point `x ∈ t0` and we want
to find a point `y ∈ s n` which is close to `x`.
`x` belongs to `t0`, the intersection of the closures. In particular, it is well
approximated by a point `z` in `⋃m≥n, s m`, say in `s m`. Since `s m` and
`s n` are close, this point is itself well approximated by a point `y` in `s n`,
as required. -/
intro n x xt0
have : x ∈ closure (⋃ m ≥ n, s m : Set α) := by apply mem_iInter.1 xt0 n
obtain ⟨z : α, hz, Dxz : edist x z < B n⟩ := mem_closure_iff.1 this (B n) (B_pos n)
simp only [exists_prop, Set.mem_iUnion] at hz
obtain ⟨m : ℕ, m_ge_n : m ≥ n, hm : z ∈ (s m : Set α)⟩ := hz
have : hausdorffEdist (s m : Set α) (s n) < B n := hs n m n m_ge_n (le_refl n)
obtain ⟨y : α, hy : y ∈ (s n : Set α), Dzy : edist z y < B n⟩ :=
exists_edist_lt_of_hausdorffEdist_lt hm this
exact
⟨y, hy,
calc
edist x y ≤ edist x z + edist z y := edist_triangle _ _ _
_ ≤ B n + B n := add_le_add (le_of_lt Dxz) (le_of_lt Dzy)
_ = 2 * B n := (two_mul _).symm
⟩
-- Deduce from the above inequalities that the distance between `s n` and `t0` is at most `2 B n`.
have main : ∀ n : ℕ, edist (s n) t ≤ 2 * B n := fun n =>
hausdorffEdist_le_of_mem_edist (I1 n) (I2 n)
-- from this, the convergence of `s n` to `t0` follows.
refine tendsto_atTop.2 fun ε εpos => ?_
have : Tendsto (fun n => 2 * B n) atTop (𝓝 (2 * 0)) :=
ENNReal.Tendsto.const_mul (ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one <|
by simp [ENNReal.one_lt_two]) (Or.inr <| by simp)
rw [mul_zero] at this
obtain ⟨N, hN⟩ : ∃ N, ∀ b ≥ N, ε > 2 * B b :=
((tendsto_order.1 this).2 ε εpos).exists_forall_of_atTop
exact ⟨N, fun n hn => lt_of_le_of_lt (main n) (hN n hn)⟩
#align emetric.closeds.complete_space EMetric.Closeds.completeSpace
/-- In a compact space, the type of closed subsets is compact. -/
instance Closeds.compactSpace [CompactSpace α] : CompactSpace (Closeds α) :=
⟨by
/- by completeness, it suffices to show that it is totally bounded,
i.e., for all ε>0, there is a finite set which is ε-dense.
start from a set `s` which is ε-dense in α. Then the subsets of `s`
are finitely many, and ε-dense for the Hausdorff distance. -/
refine
isCompact_of_totallyBounded_isClosed (EMetric.totallyBounded_iff.2 fun ε εpos => ?_)
isClosed_univ
rcases exists_between εpos with ⟨δ, δpos, δlt⟩
obtain ⟨s : Set α, fs : s.Finite, hs : univ ⊆ ⋃ y ∈ s, ball y δ⟩ :=
EMetric.totallyBounded_iff.1
(isCompact_iff_totallyBounded_isComplete.1 (@isCompact_univ α _ _)).1 δ δpos
-- we first show that any set is well approximated by a subset of `s`.
have main : ∀ u : Set α, ∃ v ⊆ s, hausdorffEdist u v ≤ δ := by
intro u
let v := { x : α | x ∈ s ∧ ∃ y ∈ u, edist x y < δ }
exists v, (fun x hx => hx.1 : v ⊆ s)
refine hausdorffEdist_le_of_mem_edist ?_ ?_
· intro x hx
have : x ∈ ⋃ y ∈ s, ball y δ := hs (by simp)
rcases mem_iUnion₂.1 this with ⟨y, ys, dy⟩
have : edist y x < δ := by simp at dy; rwa [edist_comm] at dy
exact ⟨y, ⟨ys, ⟨x, hx, this⟩⟩, le_of_lt dy⟩
· rintro x ⟨_, ⟨y, yu, hy⟩⟩
exact ⟨y, yu, le_of_lt hy⟩
-- introduce the set F of all subsets of `s` (seen as members of `Closeds α`).
let F := { f : Closeds α | (f : Set α) ⊆ s }
refine ⟨F, ?_, fun u _ => ?_⟩
-- `F` is finite
· apply @Finite.of_finite_image _ _ F _
· apply fs.finite_subsets.subset fun b => _
· exact fun s => (s : Set α)
simp only [F, and_imp, Set.mem_image, Set.mem_setOf_eq, exists_imp]
intro _ x hx hx'
rwa [hx'] at hx
· exact SetLike.coe_injective.injOn
-- `F` is ε-dense
· obtain ⟨t0, t0s, Dut0⟩ := main u
have : IsClosed t0 := (fs.subset t0s).isCompact.isClosed
let t : Closeds α := ⟨t0, this⟩
have : t ∈ F := t0s
have : edist u t < ε := lt_of_le_of_lt Dut0 δlt
apply mem_iUnion₂.2
exact ⟨t, ‹t ∈ F›, this⟩⟩
#align emetric.closeds.compact_space EMetric.Closeds.compactSpace
/-- In an emetric space, the type of non-empty compact subsets is an emetric space,
where the edistance is the Hausdorff edistance -/
instance NonemptyCompacts.emetricSpace : EMetricSpace (NonemptyCompacts α) where
edist s t := hausdorffEdist (s : Set α) t
edist_self s := hausdorffEdist_self
edist_comm s t := hausdorffEdist_comm
edist_triangle s t u := hausdorffEdist_triangle
eq_of_edist_eq_zero {s t} h := NonemptyCompacts.ext <| by
have : closure (s : Set α) = closure t := hausdorffEdist_zero_iff_closure_eq_closure.1 h
rwa [s.isCompact.isClosed.closure_eq, t.isCompact.isClosed.closure_eq] at this
#align emetric.nonempty_compacts.emetric_space EMetric.NonemptyCompacts.emetricSpace
/-- `NonemptyCompacts.toCloseds` is a uniform embedding (as it is an isometry) -/
theorem NonemptyCompacts.ToCloseds.uniformEmbedding :
UniformEmbedding (@NonemptyCompacts.toCloseds α _ _) :=
Isometry.uniformEmbedding fun _ _ => rfl
#align emetric.nonempty_compacts.to_closeds.uniform_embedding EMetric.NonemptyCompacts.ToCloseds.uniformEmbedding
/-- The range of `NonemptyCompacts.toCloseds` is closed in a complete space -/
| Mathlib/Topology/MetricSpace/Closeds.lean | 256 | 291 | theorem NonemptyCompacts.isClosed_in_closeds [CompleteSpace α] :
IsClosed (range <| @NonemptyCompacts.toCloseds α _ _) := by |
have :
range NonemptyCompacts.toCloseds =
{ s : Closeds α | (s : Set α).Nonempty ∧ IsCompact (s : Set α) } := by
ext s
refine ⟨?_, fun h => ⟨⟨⟨s, h.2⟩, h.1⟩, Closeds.ext rfl⟩⟩
rintro ⟨s, hs, rfl⟩
exact ⟨s.nonempty, s.isCompact⟩
rw [this]
refine isClosed_of_closure_subset fun s hs => ⟨?_, ?_⟩
· -- take a set t which is nonempty and at a finite distance of s
rcases mem_closure_iff.1 hs ⊤ ENNReal.coe_lt_top with ⟨t, ht, Dst⟩
rw [edist_comm] at Dst
-- since `t` is nonempty, so is `s`
exact nonempty_of_hausdorffEdist_ne_top ht.1 (ne_of_lt Dst)
· refine isCompact_iff_totallyBounded_isComplete.2 ⟨?_, s.closed.isComplete⟩
refine totallyBounded_iff.2 fun ε (εpos : 0 < ε) => ?_
-- we have to show that s is covered by finitely many eballs of radius ε
-- pick a nonempty compact set t at distance at most ε/2 of s
rcases mem_closure_iff.1 hs (ε / 2) (ENNReal.half_pos εpos.ne') with ⟨t, ht, Dst⟩
-- cover this space with finitely many balls of radius ε/2
rcases totallyBounded_iff.1 (isCompact_iff_totallyBounded_isComplete.1 ht.2).1 (ε / 2)
(ENNReal.half_pos εpos.ne') with
⟨u, fu, ut⟩
refine ⟨u, ⟨fu, fun x hx => ?_⟩⟩
-- u : set α, fu : u.finite, ut : t ⊆ ⋃ (y : α) (H : y ∈ u), eball y (ε / 2)
-- then s is covered by the union of the balls centered at u of radius ε
rcases exists_edist_lt_of_hausdorffEdist_lt hx Dst with ⟨z, hz, Dxz⟩
rcases mem_iUnion₂.1 (ut hz) with ⟨y, hy, Dzy⟩
have : edist x y < ε :=
calc
edist x y ≤ edist x z + edist z y := edist_triangle _ _ _
_ < ε / 2 + ε / 2 := ENNReal.add_lt_add Dxz Dzy
_ = ε := ENNReal.add_halves _
exact mem_biUnion hy this
|
/-
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.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Tactic.NthRewrite
#align_import data.nat.gcd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Definitions and properties of `Nat.gcd`, `Nat.lcm`, and `Nat.coprime`
Generalizations of these are provided in a later file as `GCDMonoid.gcd` and
`GCDMonoid.lcm`.
Note that the global `IsCoprime` is not a straightforward generalization of `Nat.coprime`, see
`Nat.isCoprime_iff_coprime` for the connection between the two.
-/
namespace Nat
/-! ### `gcd` -/
theorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ d) :
d = a.gcd b :=
(dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm
#align nat.gcd_greatest Nat.gcd_greatest
/-! Lemmas where one argument consists of addition of a multiple of the other -/
@[simp]
theorem gcd_add_mul_right_right (m n k : ℕ) : gcd m (n + k * m) = gcd m n := by
simp [gcd_rec m (n + k * m), gcd_rec m n]
#align nat.gcd_add_mul_right_right Nat.gcd_add_mul_right_right
@[simp]
theorem gcd_add_mul_left_right (m n k : ℕ) : gcd m (n + m * k) = gcd m n := by
simp [gcd_rec m (n + m * k), gcd_rec m n]
#align nat.gcd_add_mul_left_right Nat.gcd_add_mul_left_right
@[simp]
theorem gcd_mul_right_add_right (m n k : ℕ) : gcd m (k * m + n) = gcd m n := by simp [add_comm _ n]
#align nat.gcd_mul_right_add_right Nat.gcd_mul_right_add_right
@[simp]
theorem gcd_mul_left_add_right (m n k : ℕ) : gcd m (m * k + n) = gcd m n := by simp [add_comm _ n]
#align nat.gcd_mul_left_add_right Nat.gcd_mul_left_add_right
@[simp]
theorem gcd_add_mul_right_left (m n k : ℕ) : gcd (m + k * n) n = gcd m n := by
rw [gcd_comm, gcd_add_mul_right_right, gcd_comm]
#align nat.gcd_add_mul_right_left Nat.gcd_add_mul_right_left
@[simp]
theorem gcd_add_mul_left_left (m n k : ℕ) : gcd (m + n * k) n = gcd m n := by
rw [gcd_comm, gcd_add_mul_left_right, gcd_comm]
#align nat.gcd_add_mul_left_left Nat.gcd_add_mul_left_left
@[simp]
theorem gcd_mul_right_add_left (m n k : ℕ) : gcd (k * n + m) n = gcd m n := by
rw [gcd_comm, gcd_mul_right_add_right, gcd_comm]
#align nat.gcd_mul_right_add_left Nat.gcd_mul_right_add_left
@[simp]
theorem gcd_mul_left_add_left (m n k : ℕ) : gcd (n * k + m) n = gcd m n := by
rw [gcd_comm, gcd_mul_left_add_right, gcd_comm]
#align nat.gcd_mul_left_add_left Nat.gcd_mul_left_add_left
/-! Lemmas where one argument consists of an addition of the other -/
@[simp]
theorem gcd_add_self_right (m n : ℕ) : gcd m (n + m) = gcd m n :=
Eq.trans (by rw [one_mul]) (gcd_add_mul_right_right m n 1)
#align nat.gcd_add_self_right Nat.gcd_add_self_right
@[simp]
theorem gcd_add_self_left (m n : ℕ) : gcd (m + n) n = gcd m n := by
rw [gcd_comm, gcd_add_self_right, gcd_comm]
#align nat.gcd_add_self_left Nat.gcd_add_self_left
@[simp]
theorem gcd_self_add_left (m n : ℕ) : gcd (m + n) m = gcd n m := by rw [add_comm, gcd_add_self_left]
#align nat.gcd_self_add_left Nat.gcd_self_add_left
@[simp]
theorem gcd_self_add_right (m n : ℕ) : gcd m (m + n) = gcd m n := by
rw [add_comm, gcd_add_self_right]
#align nat.gcd_self_add_right Nat.gcd_self_add_right
/-! Lemmas where one argument consists of a subtraction of the other -/
@[simp]
theorem gcd_sub_self_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) m = gcd n m := by
calc
gcd (n - m) m = gcd (n - m + m) m := by rw [← gcd_add_self_left (n - m) m]
_ = gcd n m := by rw [Nat.sub_add_cancel h]
@[simp]
theorem gcd_sub_self_right {m n : ℕ} (h : m ≤ n) : gcd m (n - m) = gcd m n := by
rw [gcd_comm, gcd_sub_self_left h, gcd_comm]
@[simp]
theorem gcd_self_sub_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) n = gcd m n := by
have := Nat.sub_add_cancel h
rw [gcd_comm m n, ← this, gcd_add_self_left (n - m) m]
have : gcd (n - m) n = gcd (n - m) m := by
nth_rw 2 [← Nat.add_sub_cancel' h]
rw [gcd_add_self_right, gcd_comm]
convert this
@[simp]
theorem gcd_self_sub_right {m n : ℕ} (h : m ≤ n) : gcd n (n - m) = gcd n m := by
rw [gcd_comm, gcd_self_sub_left h, gcd_comm]
/-! ### `lcm` -/
theorem lcm_dvd_mul (m n : ℕ) : lcm m n ∣ m * n :=
lcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _)
#align nat.lcm_dvd_mul Nat.lcm_dvd_mul
theorem lcm_dvd_iff {m n k : ℕ} : lcm m n ∣ k ↔ m ∣ k ∧ n ∣ k :=
⟨fun h => ⟨(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h⟩, and_imp.2 lcm_dvd⟩
#align nat.lcm_dvd_iff Nat.lcm_dvd_iff
theorem lcm_pos {m n : ℕ} : 0 < m → 0 < n → 0 < m.lcm n := by
simp_rw [pos_iff_ne_zero]
exact lcm_ne_zero
#align nat.lcm_pos Nat.lcm_pos
theorem lcm_mul_left {m n k : ℕ} : (m * n).lcm (m * k) = m * n.lcm k := by
apply dvd_antisymm
· exact lcm_dvd (mul_dvd_mul_left m (dvd_lcm_left n k)) (mul_dvd_mul_left m (dvd_lcm_right n k))
· have h : m ∣ lcm (m * n) (m * k) := (dvd_mul_right m n).trans (dvd_lcm_left (m * n) (m * k))
rw [← dvd_div_iff h, lcm_dvd_iff, dvd_div_iff h, dvd_div_iff h, ← lcm_dvd_iff]
theorem lcm_mul_right {m n k : ℕ} : (m * n).lcm (k * n) = m.lcm k * n := by
rw [mul_comm, mul_comm k n, lcm_mul_left, mul_comm]
/-!
### `Coprime`
See also `Nat.coprime_of_dvd` and `Nat.coprime_of_dvd'` to prove `Nat.Coprime m n`.
-/
instance (m n : ℕ) : Decidable (Coprime m n) := inferInstanceAs (Decidable (gcd m n = 1))
theorem Coprime.lcm_eq_mul {m n : ℕ} (h : Coprime m n) : lcm m n = m * n := by
rw [← one_mul (lcm m n), ← h.gcd_eq_one, gcd_mul_lcm]
#align nat.coprime.lcm_eq_mul Nat.Coprime.lcm_eq_mul
theorem Coprime.symmetric : Symmetric Coprime := fun _ _ => Coprime.symm
#align nat.coprime.symmetric Nat.Coprime.symmetric
theorem Coprime.dvd_mul_right {m n k : ℕ} (H : Coprime k n) : k ∣ m * n ↔ k ∣ m :=
⟨H.dvd_of_dvd_mul_right, fun h => dvd_mul_of_dvd_left h n⟩
#align nat.coprime.dvd_mul_right Nat.Coprime.dvd_mul_right
theorem Coprime.dvd_mul_left {m n k : ℕ} (H : Coprime k m) : k ∣ m * n ↔ k ∣ n :=
⟨H.dvd_of_dvd_mul_left, fun h => dvd_mul_of_dvd_right h m⟩
#align nat.coprime.dvd_mul_left Nat.Coprime.dvd_mul_left
@[simp]
theorem coprime_add_self_right {m n : ℕ} : Coprime m (n + m) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_self_right]
#align nat.coprime_add_self_right Nat.coprime_add_self_right
@[simp]
theorem coprime_self_add_right {m n : ℕ} : Coprime m (m + n) ↔ Coprime m n := by
rw [add_comm, coprime_add_self_right]
#align nat.coprime_self_add_right Nat.coprime_self_add_right
@[simp]
theorem coprime_add_self_left {m n : ℕ} : Coprime (m + n) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_self_left]
#align nat.coprime_add_self_left Nat.coprime_add_self_left
@[simp]
theorem coprime_self_add_left {m n : ℕ} : Coprime (m + n) m ↔ Coprime n m := by
rw [Coprime, Coprime, gcd_self_add_left]
#align nat.coprime_self_add_left Nat.coprime_self_add_left
@[simp]
theorem coprime_add_mul_right_right (m n k : ℕ) : Coprime m (n + k * m) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_right_right]
#align nat.coprime_add_mul_right_right Nat.coprime_add_mul_right_right
@[simp]
theorem coprime_add_mul_left_right (m n k : ℕ) : Coprime m (n + m * k) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_left_right]
#align nat.coprime_add_mul_left_right Nat.coprime_add_mul_left_right
@[simp]
theorem coprime_mul_right_add_right (m n k : ℕ) : Coprime m (k * m + n) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_right_add_right]
#align nat.coprime_mul_right_add_right Nat.coprime_mul_right_add_right
@[simp]
theorem coprime_mul_left_add_right (m n k : ℕ) : Coprime m (m * k + n) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_left_add_right]
#align nat.coprime_mul_left_add_right Nat.coprime_mul_left_add_right
@[simp]
theorem coprime_add_mul_right_left (m n k : ℕ) : Coprime (m + k * n) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_right_left]
#align nat.coprime_add_mul_right_left Nat.coprime_add_mul_right_left
@[simp]
theorem coprime_add_mul_left_left (m n k : ℕ) : Coprime (m + n * k) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_left_left]
#align nat.coprime_add_mul_left_left Nat.coprime_add_mul_left_left
@[simp]
theorem coprime_mul_right_add_left (m n k : ℕ) : Coprime (k * n + m) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_right_add_left]
#align nat.coprime_mul_right_add_left Nat.coprime_mul_right_add_left
@[simp]
theorem coprime_mul_left_add_left (m n k : ℕ) : Coprime (n * k + m) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_mul_left_add_left]
#align nat.coprime_mul_left_add_left Nat.coprime_mul_left_add_left
@[simp]
theorem coprime_sub_self_left {m n : ℕ} (h : m ≤ n) : Coprime (n - m) m ↔ Coprime n m := by
rw [Coprime, Coprime, gcd_sub_self_left h]
@[simp]
theorem coprime_sub_self_right {m n : ℕ} (h : m ≤ n) : Coprime m (n - m) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_sub_self_right h]
@[simp]
theorem coprime_self_sub_left {m n : ℕ} (h : m ≤ n) : Coprime (n - m) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_self_sub_left h]
@[simp]
theorem coprime_self_sub_right {m n : ℕ} (h : m ≤ n) : Coprime n (n - m) ↔ Coprime n m := by
rw [Coprime, Coprime, gcd_self_sub_right h]
@[simp]
theorem coprime_pow_left_iff {n : ℕ} (hn : 0 < n) (a b : ℕ) :
Nat.Coprime (a ^ n) b ↔ Nat.Coprime a b := by
obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero hn.ne'
rw [Nat.pow_succ, Nat.coprime_mul_iff_left]
exact ⟨And.right, fun hab => ⟨hab.pow_left _, hab⟩⟩
#align nat.coprime_pow_left_iff Nat.coprime_pow_left_iff
@[simp]
theorem coprime_pow_right_iff {n : ℕ} (hn : 0 < n) (a b : ℕ) :
Nat.Coprime a (b ^ n) ↔ Nat.Coprime a b := by
rw [Nat.coprime_comm, coprime_pow_left_iff hn, Nat.coprime_comm]
#align nat.coprime_pow_right_iff Nat.coprime_pow_right_iff
theorem not_coprime_zero_zero : ¬Coprime 0 0 := by simp
#align nat.not_coprime_zero_zero Nat.not_coprime_zero_zero
theorem coprime_one_left_iff (n : ℕ) : Coprime 1 n ↔ True := by simp [Coprime]
#align nat.coprime_one_left_iff Nat.coprime_one_left_iff
theorem coprime_one_right_iff (n : ℕ) : Coprime n 1 ↔ True := by simp [Coprime]
#align nat.coprime_one_right_iff Nat.coprime_one_right_iff
| Mathlib/Data/Nat/GCD/Basic.lean | 264 | 269 | theorem gcd_mul_of_coprime_of_dvd {a b c : ℕ} (hac : Coprime a c) (b_dvd_c : b ∣ c) :
gcd (a * b) c = b := by |
rcases exists_eq_mul_left_of_dvd b_dvd_c with ⟨d, rfl⟩
rw [gcd_mul_right]
convert one_mul b
exact Coprime.coprime_mul_right_right hac
|
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang
-/
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.BigOperators.RingEquiv
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.Algebra.Module.Pi
import Mathlib.Algebra.Star.BigOperators
import Mathlib.Algebra.Star.Module
import Mathlib.Algebra.Star.Pi
import Mathlib.Data.Fintype.BigOperators
import Mathlib.GroupTheory.GroupAction.BigOperators
#align_import data.matrix.basic from "leanprover-community/mathlib"@"eba5bb3155cab51d80af00e8d7d69fa271b1302b"
/-!
# Matrices
This file defines basic properties of matrices.
Matrices with rows indexed by `m`, columns indexed by `n`, and entries of type `α` are represented
with `Matrix m n α`. For the typical approach of counting rows and columns,
`Matrix (Fin m) (Fin n) α` can be used.
## Notation
The locale `Matrix` gives the following notation:
* `⬝ᵥ` for `Matrix.dotProduct`
* `*ᵥ` for `Matrix.mulVec`
* `ᵥ*` for `Matrix.vecMul`
* `ᵀ` for `Matrix.transpose`
* `ᴴ` for `Matrix.conjTranspose`
## Implementation notes
For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix
to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the
form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n α)`, as these are not recognized by Lean
as having the right type. Instead, `Matrix.of` should be used.
## TODO
Under various conditions, multiplication of infinite matrices makes sense.
These have not yet been implemented.
-/
universe u u' v w
/-- `Matrix m n R` is the type of matrices with entries in `R`, whose rows are indexed by `m`
and whose columns are indexed by `n`. -/
def Matrix (m : Type u) (n : Type u') (α : Type v) : Type max u u' v :=
m → n → α
#align matrix Matrix
variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*}
variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*}
namespace Matrix
section Ext
variable {M N : Matrix m n α}
theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N :=
⟨fun h => funext fun i => funext <| h i, fun h => by simp [h]⟩
#align matrix.ext_iff Matrix.ext_iff
@[ext]
theorem ext : (∀ i j, M i j = N i j) → M = N :=
ext_iff.mp
#align matrix.ext Matrix.ext
end Ext
/-- Cast a function into a matrix.
The two sides of the equivalence are definitionally equal types. We want to use an explicit cast
to distinguish the types because `Matrix` has different instances to pi types (such as `Pi.mul`,
which performs elementwise multiplication, vs `Matrix.mul`).
If you are defining a matrix, in terms of its entries, use `of (fun i j ↦ _)`. The
purpose of this approach is to ensure that terms of the form `(fun i j ↦ _) * (fun i j ↦ _)` do not
appear, as the type of `*` can be misleading.
Porting note: In Lean 3, it is also safe to use pattern matching in a definition as `| i j := _`,
which can only be unfolded when fully-applied. leanprover/lean4#2042 means this does not
(currently) work in Lean 4.
-/
def of : (m → n → α) ≃ Matrix m n α :=
Equiv.refl _
#align matrix.of Matrix.of
@[simp]
theorem of_apply (f : m → n → α) (i j) : of f i j = f i j :=
rfl
#align matrix.of_apply Matrix.of_apply
@[simp]
theorem of_symm_apply (f : Matrix m n α) (i j) : of.symm f i j = f i j :=
rfl
#align matrix.of_symm_apply Matrix.of_symm_apply
/-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`.
This is available in bundled forms as:
* `AddMonoidHom.mapMatrix`
* `LinearMap.mapMatrix`
* `RingHom.mapMatrix`
* `AlgHom.mapMatrix`
* `Equiv.mapMatrix`
* `AddEquiv.mapMatrix`
* `LinearEquiv.mapMatrix`
* `RingEquiv.mapMatrix`
* `AlgEquiv.mapMatrix`
-/
def map (M : Matrix m n α) (f : α → β) : Matrix m n β :=
of fun i j => f (M i j)
#align matrix.map Matrix.map
@[simp]
theorem map_apply {M : Matrix m n α} {f : α → β} {i : m} {j : n} : M.map f i j = f (M i j) :=
rfl
#align matrix.map_apply Matrix.map_apply
@[simp]
theorem map_id (M : Matrix m n α) : M.map id = M := by
ext
rfl
#align matrix.map_id Matrix.map_id
@[simp]
theorem map_id' (M : Matrix m n α) : M.map (·) = M := map_id M
@[simp]
theorem map_map {M : Matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} :
(M.map f).map g = M.map (g ∘ f) := by
ext
rfl
#align matrix.map_map Matrix.map_map
theorem map_injective {f : α → β} (hf : Function.Injective f) :
Function.Injective fun M : Matrix m n α => M.map f := fun _ _ h =>
ext fun i j => hf <| ext_iff.mpr h i j
#align matrix.map_injective Matrix.map_injective
/-- The transpose of a matrix. -/
def transpose (M : Matrix m n α) : Matrix n m α :=
of fun x y => M y x
#align matrix.transpose Matrix.transpose
-- TODO: set as an equation lemma for `transpose`, see mathlib4#3024
@[simp]
theorem transpose_apply (M : Matrix m n α) (i j) : transpose M i j = M j i :=
rfl
#align matrix.transpose_apply Matrix.transpose_apply
@[inherit_doc]
scoped postfix:1024 "ᵀ" => Matrix.transpose
/-- The conjugate transpose of a matrix defined in term of `star`. -/
def conjTranspose [Star α] (M : Matrix m n α) : Matrix n m α :=
M.transpose.map star
#align matrix.conj_transpose Matrix.conjTranspose
@[inherit_doc]
scoped postfix:1024 "ᴴ" => Matrix.conjTranspose
instance inhabited [Inhabited α] : Inhabited (Matrix m n α) :=
inferInstanceAs <| Inhabited <| m → n → α
-- Porting note: new, Lean3 found this automatically
instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) :=
Fintype.decidablePiFintype
instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] :
Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α))
instance {n m} [Finite m] [Finite n] (α) [Finite α] :
Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α))
instance add [Add α] : Add (Matrix m n α) :=
Pi.instAdd
instance addSemigroup [AddSemigroup α] : AddSemigroup (Matrix m n α) :=
Pi.addSemigroup
instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (Matrix m n α) :=
Pi.addCommSemigroup
instance zero [Zero α] : Zero (Matrix m n α) :=
Pi.instZero
instance addZeroClass [AddZeroClass α] : AddZeroClass (Matrix m n α) :=
Pi.addZeroClass
instance addMonoid [AddMonoid α] : AddMonoid (Matrix m n α) :=
Pi.addMonoid
instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (Matrix m n α) :=
Pi.addCommMonoid
instance neg [Neg α] : Neg (Matrix m n α) :=
Pi.instNeg
instance sub [Sub α] : Sub (Matrix m n α) :=
Pi.instSub
instance addGroup [AddGroup α] : AddGroup (Matrix m n α) :=
Pi.addGroup
instance addCommGroup [AddCommGroup α] : AddCommGroup (Matrix m n α) :=
Pi.addCommGroup
instance unique [Unique α] : Unique (Matrix m n α) :=
Pi.unique
instance subsingleton [Subsingleton α] : Subsingleton (Matrix m n α) :=
inferInstanceAs <| Subsingleton <| m → n → α
instance nonempty [Nonempty m] [Nonempty n] [Nontrivial α] : Nontrivial (Matrix m n α) :=
Function.nontrivial
instance smul [SMul R α] : SMul R (Matrix m n α) :=
Pi.instSMul
instance smulCommClass [SMul R α] [SMul S α] [SMulCommClass R S α] :
SMulCommClass R S (Matrix m n α) :=
Pi.smulCommClass
instance isScalarTower [SMul R S] [SMul R α] [SMul S α] [IsScalarTower R S α] :
IsScalarTower R S (Matrix m n α) :=
Pi.isScalarTower
instance isCentralScalar [SMul R α] [SMul Rᵐᵒᵖ α] [IsCentralScalar R α] :
IsCentralScalar R (Matrix m n α) :=
Pi.isCentralScalar
instance mulAction [Monoid R] [MulAction R α] : MulAction R (Matrix m n α) :=
Pi.mulAction _
instance distribMulAction [Monoid R] [AddMonoid α] [DistribMulAction R α] :
DistribMulAction R (Matrix m n α) :=
Pi.distribMulAction _
instance module [Semiring R] [AddCommMonoid α] [Module R α] : Module R (Matrix m n α) :=
Pi.module _ _ _
-- Porting note (#10756): added the following section with simp lemmas because `simp` fails
-- to apply the corresponding lemmas in the namespace `Pi`.
-- (e.g. `Pi.zero_apply` used on `OfNat.ofNat 0 i j`)
section
@[simp]
theorem zero_apply [Zero α] (i : m) (j : n) : (0 : Matrix m n α) i j = 0 := rfl
@[simp]
theorem add_apply [Add α] (A B : Matrix m n α) (i : m) (j : n) :
(A + B) i j = (A i j) + (B i j) := rfl
@[simp]
theorem smul_apply [SMul β α] (r : β) (A : Matrix m n α) (i : m) (j : n) :
(r • A) i j = r • (A i j) := rfl
@[simp]
theorem sub_apply [Sub α] (A B : Matrix m n α) (i : m) (j : n) :
(A - B) i j = (A i j) - (B i j) := rfl
@[simp]
theorem neg_apply [Neg α] (A : Matrix m n α) (i : m) (j : n) :
(-A) i j = -(A i j) := rfl
end
/-! simp-normal form pulls `of` to the outside. -/
@[simp]
theorem of_zero [Zero α] : of (0 : m → n → α) = 0 :=
rfl
#align matrix.of_zero Matrix.of_zero
@[simp]
theorem of_add_of [Add α] (f g : m → n → α) : of f + of g = of (f + g) :=
rfl
#align matrix.of_add_of Matrix.of_add_of
@[simp]
theorem of_sub_of [Sub α] (f g : m → n → α) : of f - of g = of (f - g) :=
rfl
#align matrix.of_sub_of Matrix.of_sub_of
@[simp]
theorem neg_of [Neg α] (f : m → n → α) : -of f = of (-f) :=
rfl
#align matrix.neg_of Matrix.neg_of
@[simp]
theorem smul_of [SMul R α] (r : R) (f : m → n → α) : r • of f = of (r • f) :=
rfl
#align matrix.smul_of Matrix.smul_of
@[simp]
protected theorem map_zero [Zero α] [Zero β] (f : α → β) (h : f 0 = 0) :
(0 : Matrix m n α).map f = 0 := by
ext
simp [h]
#align matrix.map_zero Matrix.map_zero
protected theorem map_add [Add α] [Add β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂)
(M N : Matrix m n α) : (M + N).map f = M.map f + N.map f :=
ext fun _ _ => hf _ _
#align matrix.map_add Matrix.map_add
protected theorem map_sub [Sub α] [Sub β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ - a₂) = f a₁ - f a₂)
(M N : Matrix m n α) : (M - N).map f = M.map f - N.map f :=
ext fun _ _ => hf _ _
#align matrix.map_sub Matrix.map_sub
theorem map_smul [SMul R α] [SMul R β] (f : α → β) (r : R) (hf : ∀ a, f (r • a) = r • f a)
(M : Matrix m n α) : (r • M).map f = r • M.map f :=
ext fun _ _ => hf _
#align matrix.map_smul Matrix.map_smul
/-- The scalar action via `Mul.toSMul` is transformed by the same map as the elements
of the matrix, when `f` preserves multiplication. -/
theorem map_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α)
(hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (r • A).map f = f r • A.map f :=
ext fun _ _ => hf _ _
#align matrix.map_smul' Matrix.map_smul'
/-- The scalar action via `mul.toOppositeSMul` is transformed by the same map as the
elements of the matrix, when `f` preserves multiplication. -/
theorem map_op_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α)
(hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) :
(MulOpposite.op r • A).map f = MulOpposite.op (f r) • A.map f :=
ext fun _ _ => hf _ _
#align matrix.map_op_smul' Matrix.map_op_smul'
theorem _root_.IsSMulRegular.matrix [SMul R S] {k : R} (hk : IsSMulRegular S k) :
IsSMulRegular (Matrix m n S) k :=
IsSMulRegular.pi fun _ => IsSMulRegular.pi fun _ => hk
#align is_smul_regular.matrix IsSMulRegular.matrix
theorem _root_.IsLeftRegular.matrix [Mul α] {k : α} (hk : IsLeftRegular k) :
IsSMulRegular (Matrix m n α) k :=
hk.isSMulRegular.matrix
#align is_left_regular.matrix IsLeftRegular.matrix
instance subsingleton_of_empty_left [IsEmpty m] : Subsingleton (Matrix m n α) :=
⟨fun M N => by
ext i
exact isEmptyElim i⟩
#align matrix.subsingleton_of_empty_left Matrix.subsingleton_of_empty_left
instance subsingleton_of_empty_right [IsEmpty n] : Subsingleton (Matrix m n α) :=
⟨fun M N => by
ext i j
exact isEmptyElim j⟩
#align matrix.subsingleton_of_empty_right Matrix.subsingleton_of_empty_right
end Matrix
open Matrix
namespace Matrix
section Diagonal
variable [DecidableEq n]
/-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0`
if `i ≠ j`.
Note that bundled versions exist as:
* `Matrix.diagonalAddMonoidHom`
* `Matrix.diagonalLinearMap`
* `Matrix.diagonalRingHom`
* `Matrix.diagonalAlgHom`
-/
def diagonal [Zero α] (d : n → α) : Matrix n n α :=
of fun i j => if i = j then d i else 0
#align matrix.diagonal Matrix.diagonal
-- TODO: set as an equation lemma for `diagonal`, see mathlib4#3024
theorem diagonal_apply [Zero α] (d : n → α) (i j) : diagonal d i j = if i = j then d i else 0 :=
rfl
#align matrix.diagonal_apply Matrix.diagonal_apply
@[simp]
theorem diagonal_apply_eq [Zero α] (d : n → α) (i : n) : (diagonal d) i i = d i := by
simp [diagonal]
#align matrix.diagonal_apply_eq Matrix.diagonal_apply_eq
@[simp]
theorem diagonal_apply_ne [Zero α] (d : n → α) {i j : n} (h : i ≠ j) : (diagonal d) i j = 0 := by
simp [diagonal, h]
#align matrix.diagonal_apply_ne Matrix.diagonal_apply_ne
theorem diagonal_apply_ne' [Zero α] (d : n → α) {i j : n} (h : j ≠ i) : (diagonal d) i j = 0 :=
diagonal_apply_ne d h.symm
#align matrix.diagonal_apply_ne' Matrix.diagonal_apply_ne'
@[simp]
theorem diagonal_eq_diagonal_iff [Zero α] {d₁ d₂ : n → α} :
diagonal d₁ = diagonal d₂ ↔ ∀ i, d₁ i = d₂ i :=
⟨fun h i => by simpa using congr_arg (fun m : Matrix n n α => m i i) h, fun h => by
rw [show d₁ = d₂ from funext h]⟩
#align matrix.diagonal_eq_diagonal_iff Matrix.diagonal_eq_diagonal_iff
theorem diagonal_injective [Zero α] : Function.Injective (diagonal : (n → α) → Matrix n n α) :=
fun d₁ d₂ h => funext fun i => by simpa using Matrix.ext_iff.mpr h i i
#align matrix.diagonal_injective Matrix.diagonal_injective
@[simp]
theorem diagonal_zero [Zero α] : (diagonal fun _ => 0 : Matrix n n α) = 0 := by
ext
simp [diagonal]
#align matrix.diagonal_zero Matrix.diagonal_zero
@[simp]
theorem diagonal_transpose [Zero α] (v : n → α) : (diagonal v)ᵀ = diagonal v := by
ext i j
by_cases h : i = j
· simp [h, transpose]
· simp [h, transpose, diagonal_apply_ne' _ h]
#align matrix.diagonal_transpose Matrix.diagonal_transpose
@[simp]
theorem diagonal_add [AddZeroClass α] (d₁ d₂ : n → α) :
diagonal d₁ + diagonal d₂ = diagonal fun i => d₁ i + d₂ i := by
ext i j
by_cases h : i = j <;>
simp [h]
#align matrix.diagonal_add Matrix.diagonal_add
@[simp]
theorem diagonal_smul [Zero α] [SMulZeroClass R α] (r : R) (d : n → α) :
diagonal (r • d) = r • diagonal d := by
ext i j
by_cases h : i = j <;> simp [h]
#align matrix.diagonal_smul Matrix.diagonal_smul
@[simp]
theorem diagonal_neg [NegZeroClass α] (d : n → α) :
-diagonal d = diagonal fun i => -d i := by
ext i j
by_cases h : i = j <;>
simp [h]
#align matrix.diagonal_neg Matrix.diagonal_neg
@[simp]
theorem diagonal_sub [SubNegZeroMonoid α] (d₁ d₂ : n → α) :
diagonal d₁ - diagonal d₂ = diagonal fun i => d₁ i - d₂ i := by
ext i j
by_cases h : i = j <;>
simp [h]
instance [Zero α] [NatCast α] : NatCast (Matrix n n α) where
natCast m := diagonal fun _ => m
@[norm_cast]
theorem diagonal_natCast [Zero α] [NatCast α] (m : ℕ) : diagonal (fun _ : n => (m : α)) = m := rfl
@[norm_cast]
theorem diagonal_natCast' [Zero α] [NatCast α] (m : ℕ) : diagonal ((m : n → α)) = m := rfl
-- See note [no_index around OfNat.ofNat]
theorem diagonal_ofNat [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] :
diagonal (fun _ : n => no_index (OfNat.ofNat m : α)) = OfNat.ofNat m := rfl
-- See note [no_index around OfNat.ofNat]
theorem diagonal_ofNat' [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] :
diagonal (no_index (OfNat.ofNat m : n → α)) = OfNat.ofNat m := rfl
instance [Zero α] [IntCast α] : IntCast (Matrix n n α) where
intCast m := diagonal fun _ => m
@[norm_cast]
theorem diagonal_intCast [Zero α] [IntCast α] (m : ℤ) : diagonal (fun _ : n => (m : α)) = m := rfl
@[norm_cast]
theorem diagonal_intCast' [Zero α] [IntCast α] (m : ℤ) : diagonal ((m : n → α)) = m := rfl
variable (n α)
/-- `Matrix.diagonal` as an `AddMonoidHom`. -/
@[simps]
def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where
toFun := diagonal
map_zero' := diagonal_zero
map_add' x y := (diagonal_add x y).symm
#align matrix.diagonal_add_monoid_hom Matrix.diagonalAddMonoidHom
variable (R)
/-- `Matrix.diagonal` as a `LinearMap`. -/
@[simps]
def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α :=
{ diagonalAddMonoidHom n α with map_smul' := diagonal_smul }
#align matrix.diagonal_linear_map Matrix.diagonalLinearMap
variable {n α R}
@[simp]
theorem diagonal_map [Zero α] [Zero β] {f : α → β} (h : f 0 = 0) {d : n → α} :
(diagonal d).map f = diagonal fun m => f (d m) := by
ext
simp only [diagonal_apply, map_apply]
split_ifs <;> simp [h]
#align matrix.diagonal_map Matrix.diagonal_map
@[simp]
| Mathlib/Data/Matrix/Basic.lean | 519 | 522 | theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α) :
(diagonal v)ᴴ = diagonal (star v) := by |
rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)]
rfl
|
/-
Copyright (c) 2023 Josha Dekker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Josha Dekker
-/
import Mathlib.Topology.Bases
import Mathlib.Order.Filter.CountableInter
import Mathlib.Topology.Compactness.SigmaCompact
/-!
# Lindelöf sets and Lindelöf spaces
## Main definitions
We define the following properties for sets in a topological space:
* `IsLindelof s`: Two definitions are possible here. The more standard definition is that
every open cover that contains `s` contains a countable subcover. We choose for the equivalent
definition where we require that every nontrivial filter on `s` with the countable intersection
property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`.
* `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set.
* `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line.
## Main results
* `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a
countable subcover.
## Implementation details
* This API is mainly based on the API for IsCompact and follows notation and style as much
as possible.
-/
open Set Filter Topology TopologicalSpace
universe u v
variable {X : Type u} {Y : Type v} {ι : Type*}
variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X}
section Lindelof
/-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection
property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by
`isLindelof_iff_countable_subcover`. -/
def IsLindelof (s : Set X) :=
∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f
/-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection
property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/
theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f]
(hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by
contrapose! hf
simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢
exact hs inf_le_right
/-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection
property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/
theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X}
[CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by
refine hs.compl_mem_sets fun x hx ↦ ?_
rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left]
exact hf x hx
/-- If `p : Set X → Prop` is stable under restriction and union, and each point `x`
of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/
@[elab_as_elim]
theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop}
(hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s)
(hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S))
(hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by
let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht)
have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds)
rwa [← compl_compl s]
/-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/
theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by
intro f hnf _ hstf
rw [← inf_principal, le_inf_iff] at hstf
obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1
have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2
exact ⟨x, ⟨hsx, hxt⟩, hx⟩
/-- The intersection of a closed set and a Lindelöf set is a Lindelöf set. -/
theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
/-- The set difference of a Lindelöf set and an open set is a Lindelöf set. -/
theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) :=
hs.inter_right (isClosed_compl_iff.mpr ht)
/-- A closed subset of a Lindelöf set is a Lindelöf set. -/
theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t ⊆ s) :
IsLindelof t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht
/-- A continuous image of a Lindelöf set is a Lindelöf set. -/
theorem IsLindelof.image_of_continuousOn {f : X → Y} (hs : IsLindelof s) (hf : ContinuousOn f s) :
IsLindelof (f '' s) := by
intro l lne _ ls
have : NeBot (l.comap f ⊓ 𝓟 s) :=
comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls)
obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this _ inf_le_right
haveI := hx.neBot
use f x, mem_image_of_mem f hxs
have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by
convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1
rw [nhdsWithin]
ac_rfl
exact this.neBot
/-- A continuous image of a Lindelöf set is a Lindelöf set within the codomain. -/
theorem IsLindelof.image {f : X → Y} (hs : IsLindelof s) (hf : Continuous f) :
IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn
/-- A filter with the countable intersection property that is finer than the principal filter on
a Lindelöf set `s` contains any open set that contains all clusterpoints of `s`. -/
theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s)
(hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f :=
(eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦
let ⟨x, hx, hfx⟩ := @hs (f ⊓ 𝓟 tᶜ) _ _ <| inf_le_of_left_le hf₂
have : x ∈ t := ht₂ x hx hfx.of_inf_left
have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this)
have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this
have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne
absurd A this
/-- For every open cover of a Lindelöf set, there exists a countable subcover. -/
theorem IsLindelof.elim_countable_subcover {ι : Type v} (hs : IsLindelof s) (U : ι → Set X)
(hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) :
∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i) := by
have hmono : ∀ ⦃s t : Set X⦄, s ⊆ t → (∃ r : Set ι, r.Countable ∧ t ⊆ ⋃ i ∈ r, U i)
→ (∃ r : Set ι, r.Countable ∧ s ⊆ ⋃ i ∈ r, U i) := by
intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩
exact ⟨r, hrcountable, Subset.trans hst hsub⟩
have hcountable_union : ∀ (S : Set (Set X)), S.Countable
→ (∀ s ∈ S, ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i))
→ ∃ r : Set ι, r.Countable ∧ (⋃₀ S ⊆ ⋃ i ∈ r, U i) := by
intro S hS hsr
choose! r hr using hsr
refine ⟨⋃ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩
refine sUnion_subset ?h.right.h
simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and']
exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx)
have h_nhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∃ r : Set ι, r.Countable ∧ (t ⊆ ⋃ i ∈ r, U i) := by
intro x hx
let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx)
refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩
simp only [mem_singleton_iff, iUnion_iUnion_eq_left]
exact Subset.refl _
exact hs.induction_on hmono hcountable_union h_nhds
theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) :
∃ t : Set s, t.Countable ∧ s ⊆ ⋃ x ∈ t, U (x : s) x.2 := by
have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior)
fun x hx ↦
mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩
rcases this with ⟨r, ⟨hr, hs⟩⟩
use r, hr
apply Subset.trans hs
apply iUnion₂_subset
intro i hi
apply Subset.trans interior_subset
exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _))
theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X → Set X)
(hU : ∀ x ∈ s, U x ∈ 𝓝 x) :
∃ t : Set X, t.Countable ∧ (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by
let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU
refine ⟨↑t, Countable.image htc Subtype.val, ?_⟩
constructor
· intro _
simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index]
tauto
· have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm
rwa [← this]
/-- The neighborhood filter of a Lindelöf set is disjoint with a filter `l` with the countable
intersection property if and only if the neighborhood filter of each point of this set
is disjoint with `l`. -/
theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l]
(hs : IsLindelof s) :
Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by
refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩
choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx)
choose hxU hUo using hxU
rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩
refine (hasBasis_nhdsSet _).disjoint_iff_left.2
⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩
rw [compl_iUnion₂]
exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi))
/-- A filter `l` with the countable intersection property is disjoint with the neighborhood
filter of a Lindelöf set if and only if it is disjoint with the neighborhood filter of each point
of this set. -/
theorem IsLindelof.disjoint_nhdsSet_right {l : Filter X} [CountableInterFilter l]
(hs : IsLindelof s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by
simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left
/-- For every family of closed sets whose intersection avoids a Lindelö set,
there exists a countable subfamily whose intersection avoids this Lindelöf set. -/
theorem IsLindelof.elim_countable_subfamily_closed {ι : Type v} (hs : IsLindelof s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) :
∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := by
let U := tᶜ
have hUo : ∀ i, IsOpen (U i) := by simp only [U, Pi.compl_apply, isOpen_compl_iff]; exact htc
have hsU : s ⊆ ⋃ i, U i := by
simp only [U, Pi.compl_apply]
rw [← compl_iInter]
apply disjoint_compl_left_iff_subset.mp
simp only [compl_iInter, compl_iUnion, compl_compl]
apply Disjoint.symm
exact disjoint_iff_inter_eq_empty.mpr hst
rcases hs.elim_countable_subcover U hUo hsU with ⟨u, ⟨hucount, husub⟩⟩
use u, hucount
rw [← disjoint_compl_left_iff_subset] at husub
simp only [U, Pi.compl_apply, compl_iUnion, compl_compl] at husub
exact disjoint_iff_inter_eq_empty.mp (Disjoint.symm husub)
/-- To show that a Lindelöf set intersects the intersection of a family of closed sets,
it is sufficient to show that it intersects every countable subfamily. -/
theorem IsLindelof.inter_iInter_nonempty {ι : Type v} (hs : IsLindelof s) (t : ι → Set X)
(htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i).Nonempty) :
(s ∩ ⋂ i, t i).Nonempty := by
contrapose! hst
rcases hs.elim_countable_subfamily_closed t htc hst with ⟨u, ⟨_, husub⟩⟩
exact ⟨u, fun _ ↦ husub⟩
/-- For every open cover of a Lindelöf set, there exists a countable subcover. -/
| Mathlib/Topology/Compactness/Lindelof.lean | 231 | 238 | theorem IsLindelof.elim_countable_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsLindelof s)
(hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) :
∃ b', b' ⊆ b ∧ Set.Countable b' ∧ s ⊆ ⋃ i ∈ b', c i := by |
simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂
rcases hs.elim_countable_subcover (fun i ↦ c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩
refine ⟨Subtype.val '' d, by simp, Countable.image hd.1 Subtype.val, ?_⟩
rw [biUnion_image]
exact hd.2
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.RepresentationTheory.Rep
import Mathlib.Algebra.Category.FGModuleCat.Limits
import Mathlib.CategoryTheory.Preadditive.Schur
import Mathlib.RepresentationTheory.Basic
#align_import representation_theory.fdRep from "leanprover-community/mathlib"@"19a70dceb9dff0994b92d2dd049de7d84d28112b"
/-!
# `FdRep k G` is the category of finite dimensional `k`-linear representations of `G`.
If `V : FdRep k G`, there is a coercion that allows you to treat `V` as a type,
and this type comes equipped with `Module k V` and `FiniteDimensional k V` instances.
Also `V.ρ` gives the homomorphism `G →* (V →ₗ[k] V)`.
Conversely, given a homomorphism `ρ : G →* (V →ₗ[k] V)`,
you can construct the bundled representation as `Rep.of ρ`.
We prove Schur's Lemma: the dimension of the `Hom`-space between two irreducible representation is
`0` if they are not isomorphic, and `1` if they are.
This is the content of `finrank_hom_simple_simple`
We verify that `FdRep k G` is a `k`-linear monoidal category, and rigid when `G` is a group.
`FdRep k G` has all finite limits.
## TODO
* `FdRep k G ≌ FullSubcategory (FiniteDimensional k)`
* Upgrade the right rigid structure to a rigid structure
(this just needs to be done for `FGModuleCat`).
* `FdRep k G` has all finite colimits.
* `FdRep k G` is abelian.
* `FdRep k G ≌ FGModuleCat (MonoidAlgebra k G)`.
-/
suppress_compilation
universe u
open CategoryTheory
open CategoryTheory.Limits
set_option linter.uppercaseLean3 false -- `FdRep`
/-- The category of finite dimensional `k`-linear representations of a monoid `G`. -/
abbrev FdRep (k G : Type u) [Field k] [Monoid G] :=
Action (FGModuleCat.{u} k) (MonCat.of G)
#align fdRep FdRep
namespace FdRep
variable {k G : Type u} [Field k] [Monoid G]
-- Porting note: `@[derive]` didn't work for `FdRep`. Add the 4 instances here.
instance : LargeCategory (FdRep k G) := inferInstance
instance : ConcreteCategory (FdRep k G) := inferInstance
instance : Preadditive (FdRep k G) := inferInstance
instance : HasFiniteLimits (FdRep k G) := inferInstance
instance : Linear k (FdRep k G) := by infer_instance
instance : CoeSort (FdRep k G) (Type u) :=
ConcreteCategory.hasCoeToSort _
instance (V : FdRep k G) : AddCommGroup V := by
change AddCommGroup ((forget₂ (FdRep k G) (FGModuleCat k)).obj V).obj; infer_instance
instance (V : FdRep k G) : Module k V := by
change Module k ((forget₂ (FdRep k G) (FGModuleCat k)).obj V).obj; infer_instance
instance (V : FdRep k G) : FiniteDimensional k V := by
change FiniteDimensional k ((forget₂ (FdRep k G) (FGModuleCat k)).obj V); infer_instance
/-- All hom spaces are finite dimensional. -/
instance (V W : FdRep k G) : FiniteDimensional k (V ⟶ W) :=
FiniteDimensional.of_injective ((forget₂ (FdRep k G) (FGModuleCat k)).mapLinearMap k)
(Functor.map_injective (forget₂ (FdRep k G) (FGModuleCat k)))
/-- The monoid homomorphism corresponding to the action of `G` onto `V : FdRep k G`. -/
def ρ (V : FdRep k G) : G →* V →ₗ[k] V :=
Action.ρ V
#align fdRep.ρ FdRep.ρ
/-- The underlying `LinearEquiv` of an isomorphism of representations. -/
def isoToLinearEquiv {V W : FdRep k G} (i : V ≅ W) : V ≃ₗ[k] W :=
FGModuleCat.isoToLinearEquiv ((Action.forget (FGModuleCat k) (MonCat.of G)).mapIso i)
#align fdRep.iso_to_linear_equiv FdRep.isoToLinearEquiv
| Mathlib/RepresentationTheory/FdRep.lean | 95 | 100 | theorem Iso.conj_ρ {V W : FdRep k G} (i : V ≅ W) (g : G) :
W.ρ g = (FdRep.isoToLinearEquiv i).conj (V.ρ g) := by |
-- Porting note: Changed `rw` to `erw`
erw [FdRep.isoToLinearEquiv, ← FGModuleCat.Iso.conj_eq_conj, Iso.conj_apply]
rw [Iso.eq_inv_comp ((Action.forget (FGModuleCat k) (MonCat.of G)).mapIso i)]
exact (i.hom.comm g).symm
|
/-
Copyright (c) 2020 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Polynomial.Degree.TrailingDegree
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Algebra.Polynomial.Eval
#align_import data.polynomial.reverse from "leanprover-community/mathlib"@"44de64f183393284a16016dfb2a48ac97382f2bd"
/-!
# Reverse of a univariate polynomial
The main definition is `reverse`. Applying `reverse` to a polynomial `f : R[X]` produces
the polynomial with a reversed list of coefficients, equivalent to `X^f.natDegree * f(1/X)`.
The main result is that `reverse (f * g) = reverse f * reverse g`, provided the leading
coefficients of `f` and `g` do not multiply to zero.
-/
namespace Polynomial
open Polynomial Finsupp Finset
open Polynomial
section Semiring
variable {R : Type*} [Semiring R] {f : R[X]}
/-- If `i ≤ N`, then `revAtFun N i` returns `N - i`, otherwise it returns `i`.
This is the map used by the embedding `revAt`.
-/
def revAtFun (N i : ℕ) : ℕ :=
ite (i ≤ N) (N - i) i
#align polynomial.rev_at_fun Polynomial.revAtFun
theorem revAtFun_invol {N i : ℕ} : revAtFun N (revAtFun N i) = i := by
unfold revAtFun
split_ifs with h j
· exact tsub_tsub_cancel_of_le h
· exfalso
apply j
exact Nat.sub_le N i
· rfl
#align polynomial.rev_at_fun_invol Polynomial.revAtFun_invol
theorem revAtFun_inj {N : ℕ} : Function.Injective (revAtFun N) := by
intro a b hab
rw [← @revAtFun_invol N a, hab, revAtFun_invol]
#align polynomial.rev_at_fun_inj Polynomial.revAtFun_inj
/-- If `i ≤ N`, then `revAt N i` returns `N - i`, otherwise it returns `i`.
Essentially, this embedding is only used for `i ≤ N`.
The advantage of `revAt N i` over `N - i` is that `revAt` is an involution.
-/
def revAt (N : ℕ) : Function.Embedding ℕ ℕ where
toFun i := ite (i ≤ N) (N - i) i
inj' := revAtFun_inj
#align polynomial.rev_at Polynomial.revAt
/-- We prefer to use the bundled `revAt` over unbundled `revAtFun`. -/
@[simp]
theorem revAtFun_eq (N i : ℕ) : revAtFun N i = revAt N i :=
rfl
#align polynomial.rev_at_fun_eq Polynomial.revAtFun_eq
@[simp]
theorem revAt_invol {N i : ℕ} : (revAt N) (revAt N i) = i :=
revAtFun_invol
#align polynomial.rev_at_invol Polynomial.revAt_invol
@[simp]
theorem revAt_le {N i : ℕ} (H : i ≤ N) : revAt N i = N - i :=
if_pos H
#align polynomial.rev_at_le Polynomial.revAt_le
lemma revAt_eq_self_of_lt {N i : ℕ} (h : N < i) : revAt N i = i := by simp [revAt, Nat.not_le.mpr h]
theorem revAt_add {N O n o : ℕ} (hn : n ≤ N) (ho : o ≤ O) :
revAt (N + O) (n + o) = revAt N n + revAt O o := by
rcases Nat.le.dest hn with ⟨n', rfl⟩
rcases Nat.le.dest ho with ⟨o', rfl⟩
repeat' rw [revAt_le (le_add_right rfl.le)]
rw [add_assoc, add_left_comm n' o, ← add_assoc, revAt_le (le_add_right rfl.le)]
repeat' rw [add_tsub_cancel_left]
#align polynomial.rev_at_add Polynomial.revAt_add
-- @[simp] -- Porting note (#10618): simp can prove this
theorem revAt_zero (N : ℕ) : revAt N 0 = N := by simp
#align polynomial.rev_at_zero Polynomial.revAt_zero
/-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (revAt N i)`.
In other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`.
In practice, `reflect` is only used when `N` is at least as large as the degree of `f`.
Eventually, it will be used with `N` exactly equal to the degree of `f`. -/
noncomputable def reflect (N : ℕ) : R[X] → R[X]
| ⟨f⟩ => ⟨Finsupp.embDomain (revAt N) f⟩
#align polynomial.reflect Polynomial.reflect
theorem reflect_support (N : ℕ) (f : R[X]) :
(reflect N f).support = Finset.image (revAt N) f.support := by
rcases f with ⟨⟩
ext1
simp only [reflect, support_ofFinsupp, support_embDomain, Finset.mem_map, Finset.mem_image]
#align polynomial.reflect_support Polynomial.reflect_support
@[simp]
theorem coeff_reflect (N : ℕ) (f : R[X]) (i : ℕ) : coeff (reflect N f) i = f.coeff (revAt N i) := by
rcases f with ⟨f⟩
simp only [reflect, coeff]
calc
Finsupp.embDomain (revAt N) f i = Finsupp.embDomain (revAt N) f (revAt N (revAt N i)) := by
rw [revAt_invol]
_ = f (revAt N i) := Finsupp.embDomain_apply _ _ _
#align polynomial.coeff_reflect Polynomial.coeff_reflect
@[simp]
theorem reflect_zero {N : ℕ} : reflect N (0 : R[X]) = 0 :=
rfl
#align polynomial.reflect_zero Polynomial.reflect_zero
@[simp]
theorem reflect_eq_zero_iff {N : ℕ} {f : R[X]} : reflect N (f : R[X]) = 0 ↔ f = 0 := by
rw [ofFinsupp_eq_zero, reflect, embDomain_eq_zero, ofFinsupp_eq_zero]
#align polynomial.reflect_eq_zero_iff Polynomial.reflect_eq_zero_iff
@[simp]
theorem reflect_add (f g : R[X]) (N : ℕ) : reflect N (f + g) = reflect N f + reflect N g := by
ext
simp only [coeff_add, coeff_reflect]
#align polynomial.reflect_add Polynomial.reflect_add
@[simp]
theorem reflect_C_mul (f : R[X]) (r : R) (N : ℕ) : reflect N (C r * f) = C r * reflect N f := by
ext
simp only [coeff_reflect, coeff_C_mul]
set_option linter.uppercaseLean3 false in
#align polynomial.reflect_C_mul Polynomial.reflect_C_mul
-- @[simp] -- Porting note (#10618): simp can prove this (once `reflect_monomial` is in simp scope)
theorem reflect_C_mul_X_pow (N n : ℕ) {c : R} : reflect N (C c * X ^ n) = C c * X ^ revAt N n := by
ext
rw [reflect_C_mul, coeff_C_mul, coeff_C_mul, coeff_X_pow, coeff_reflect]
split_ifs with h
· rw [h, revAt_invol, coeff_X_pow_self]
· rw [not_mem_support_iff.mp]
intro a
rw [← one_mul (X ^ n), ← C_1] at a
apply h
rw [← mem_support_C_mul_X_pow a, revAt_invol]
set_option linter.uppercaseLean3 false in
#align polynomial.reflect_C_mul_X_pow Polynomial.reflect_C_mul_X_pow
@[simp]
theorem reflect_C (r : R) (N : ℕ) : reflect N (C r) = C r * X ^ N := by
conv_lhs => rw [← mul_one (C r), ← pow_zero X, reflect_C_mul_X_pow, revAt_zero]
set_option linter.uppercaseLean3 false in
#align polynomial.reflect_C Polynomial.reflect_C
@[simp]
theorem reflect_monomial (N n : ℕ) : reflect N ((X : R[X]) ^ n) = X ^ revAt N n := by
rw [← one_mul (X ^ n), ← one_mul (X ^ revAt N n), ← C_1, reflect_C_mul_X_pow]
#align polynomial.reflect_monomial Polynomial.reflect_monomial
@[simp] lemma reflect_one_X : reflect 1 (X : R[X]) = 1 := by
simpa using reflect_monomial 1 1 (R := R)
theorem reflect_mul_induction (cf cg : ℕ) :
∀ N O : ℕ,
∀ f g : R[X],
f.support.card ≤ cf.succ →
g.support.card ≤ cg.succ →
f.natDegree ≤ N →
g.natDegree ≤ O → reflect (N + O) (f * g) = reflect N f * reflect O g := by
induction' cf with cf hcf
--first induction (left): base case
· induction' cg with cg hcg
-- second induction (right): base case
· intro N O f g Cf Cg Nf Og
rw [← C_mul_X_pow_eq_self Cf, ← C_mul_X_pow_eq_self Cg]
simp_rw [mul_assoc, X_pow_mul, mul_assoc, ← pow_add (X : R[X]), reflect_C_mul,
reflect_monomial, add_comm, revAt_add Nf Og, mul_assoc, X_pow_mul, mul_assoc, ←
pow_add (X : R[X]), add_comm]
-- second induction (right): induction step
· intro N O f g Cf Cg Nf Og
by_cases g0 : g = 0
· rw [g0, reflect_zero, mul_zero, mul_zero, reflect_zero]
rw [← eraseLead_add_C_mul_X_pow g, mul_add, reflect_add, reflect_add, mul_add, hcg, hcg] <;>
try assumption
· exact le_add_left card_support_C_mul_X_pow_le_one
· exact le_trans (natDegree_C_mul_X_pow_le g.leadingCoeff g.natDegree) Og
· exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cg (eraseLead_support_card_lt g0))
· exact le_trans eraseLead_natDegree_le_aux Og
--first induction (left): induction step
· intro N O f g Cf Cg Nf Og
by_cases f0 : f = 0
· rw [f0, reflect_zero, zero_mul, zero_mul, reflect_zero]
rw [← eraseLead_add_C_mul_X_pow f, add_mul, reflect_add, reflect_add, add_mul, hcf, hcf] <;>
try assumption
· exact le_add_left card_support_C_mul_X_pow_le_one
· exact le_trans (natDegree_C_mul_X_pow_le f.leadingCoeff f.natDegree) Nf
· exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cf (eraseLead_support_card_lt f0))
· exact le_trans eraseLead_natDegree_le_aux Nf
#align polynomial.reflect_mul_induction Polynomial.reflect_mul_induction
@[simp]
theorem reflect_mul (f g : R[X]) {F G : ℕ} (Ff : f.natDegree ≤ F) (Gg : g.natDegree ≤ G) :
reflect (F + G) (f * g) = reflect F f * reflect G g :=
reflect_mul_induction _ _ F G f g f.support.card.le_succ g.support.card.le_succ Ff Gg
#align polynomial.reflect_mul Polynomial.reflect_mul
section Eval₂
variable {S : Type*} [CommSemiring S]
theorem eval₂_reflect_mul_pow (i : R →+* S) (x : S) [Invertible x] (N : ℕ) (f : R[X])
(hf : f.natDegree ≤ N) : eval₂ i (⅟ x) (reflect N f) * x ^ N = eval₂ i x f := by
refine
induction_with_natDegree_le (fun f => eval₂ i (⅟ x) (reflect N f) * x ^ N = eval₂ i x f) _ ?_ ?_
?_ f hf
· simp
· intro n r _ hnN
simp only [revAt_le hnN, reflect_C_mul_X_pow, eval₂_X_pow, eval₂_C, eval₂_mul]
conv in x ^ N => rw [← Nat.sub_add_cancel hnN]
rw [pow_add, ← mul_assoc, mul_assoc (i r), ← mul_pow, invOf_mul_self, one_pow, mul_one]
· intros
simp [*, add_mul]
#align polynomial.eval₂_reflect_mul_pow Polynomial.eval₂_reflect_mul_pow
theorem eval₂_reflect_eq_zero_iff (i : R →+* S) (x : S) [Invertible x] (N : ℕ) (f : R[X])
(hf : f.natDegree ≤ N) : eval₂ i (⅟ x) (reflect N f) = 0 ↔ eval₂ i x f = 0 := by
conv_rhs => rw [← eval₂_reflect_mul_pow i x N f hf]
constructor
· intro h
rw [h, zero_mul]
· intro h
rw [← mul_one (eval₂ i (⅟ x) _), ← one_pow N, ← mul_invOf_self x, mul_pow, ← mul_assoc, h,
zero_mul]
#align polynomial.eval₂_reflect_eq_zero_iff Polynomial.eval₂_reflect_eq_zero_iff
end Eval₂
/-- The reverse of a polynomial f is the polynomial obtained by "reading f backwards".
Even though this is not the actual definition, `reverse f = f (1/X) * X ^ f.natDegree`. -/
noncomputable def reverse (f : R[X]) : R[X] :=
reflect f.natDegree f
#align polynomial.reverse Polynomial.reverse
theorem coeff_reverse (f : R[X]) (n : ℕ) : f.reverse.coeff n = f.coeff (revAt f.natDegree n) := by
rw [reverse, coeff_reflect]
#align polynomial.coeff_reverse Polynomial.coeff_reverse
@[simp]
theorem coeff_zero_reverse (f : R[X]) : coeff (reverse f) 0 = leadingCoeff f := by
rw [coeff_reverse, revAt_le (zero_le f.natDegree), tsub_zero, leadingCoeff]
#align polynomial.coeff_zero_reverse Polynomial.coeff_zero_reverse
@[simp]
theorem reverse_zero : reverse (0 : R[X]) = 0 :=
rfl
#align polynomial.reverse_zero Polynomial.reverse_zero
@[simp]
theorem reverse_eq_zero : f.reverse = 0 ↔ f = 0 := by simp [reverse]
#align polynomial.reverse_eq_zero Polynomial.reverse_eq_zero
theorem reverse_natDegree_le (f : R[X]) : f.reverse.natDegree ≤ f.natDegree := by
rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero]
intro n hn
rw [Nat.cast_lt] at hn
rw [coeff_reverse, revAt, Function.Embedding.coeFn_mk, if_neg (not_le_of_gt hn),
coeff_eq_zero_of_natDegree_lt hn]
#align polynomial.reverse_nat_degree_le Polynomial.reverse_natDegree_le
theorem natDegree_eq_reverse_natDegree_add_natTrailingDegree (f : R[X]) :
f.natDegree = f.reverse.natDegree + f.natTrailingDegree := by
by_cases hf : f = 0
· rw [hf, reverse_zero, natDegree_zero, natTrailingDegree_zero]
apply le_antisymm
· refine tsub_le_iff_right.mp ?_
apply le_natDegree_of_ne_zero
rw [reverse, coeff_reflect, ← revAt_le f.natTrailingDegree_le_natDegree, revAt_invol]
exact trailingCoeff_nonzero_iff_nonzero.mpr hf
· rw [← le_tsub_iff_left f.reverse_natDegree_le]
apply natTrailingDegree_le_of_ne_zero
have key := mt leadingCoeff_eq_zero.mp (mt reverse_eq_zero.mp hf)
rwa [leadingCoeff, coeff_reverse, revAt_le f.reverse_natDegree_le] at key
#align polynomial.nat_degree_eq_reverse_nat_degree_add_nat_trailing_degree Polynomial.natDegree_eq_reverse_natDegree_add_natTrailingDegree
theorem reverse_natDegree (f : R[X]) : f.reverse.natDegree = f.natDegree - f.natTrailingDegree := by
rw [f.natDegree_eq_reverse_natDegree_add_natTrailingDegree, add_tsub_cancel_right]
#align polynomial.reverse_nat_degree Polynomial.reverse_natDegree
theorem reverse_leadingCoeff (f : R[X]) : f.reverse.leadingCoeff = f.trailingCoeff := by
rw [leadingCoeff, reverse_natDegree, ← revAt_le f.natTrailingDegree_le_natDegree,
coeff_reverse, revAt_invol, trailingCoeff]
#align polynomial.reverse_leading_coeff Polynomial.reverse_leadingCoeff
theorem natTrailingDegree_reverse (f : R[X]) : f.reverse.natTrailingDegree = 0 := by
rw [natTrailingDegree_eq_zero, reverse_eq_zero, coeff_zero_reverse, leadingCoeff_ne_zero]
exact eq_or_ne _ _
#align polynomial.reverse_nat_trailing_degree Polynomial.natTrailingDegree_reverse
theorem reverse_trailingCoeff (f : R[X]) : f.reverse.trailingCoeff = f.leadingCoeff := by
rw [trailingCoeff, natTrailingDegree_reverse, coeff_zero_reverse]
#align polynomial.reverse_trailing_coeff Polynomial.reverse_trailingCoeff
theorem reverse_mul {f g : R[X]} (fg : f.leadingCoeff * g.leadingCoeff ≠ 0) :
reverse (f * g) = reverse f * reverse g := by
unfold reverse
rw [natDegree_mul' fg, reflect_mul f g rfl.le rfl.le]
#align polynomial.reverse_mul Polynomial.reverse_mul
@[simp]
theorem reverse_mul_of_domain {R : Type*} [Ring R] [NoZeroDivisors R] (f g : R[X]) :
reverse (f * g) = reverse f * reverse g := by
by_cases f0 : f = 0
· simp only [f0, zero_mul, reverse_zero]
by_cases g0 : g = 0
· rw [g0, mul_zero, reverse_zero, mul_zero]
simp [reverse_mul, *]
#align polynomial.reverse_mul_of_domain Polynomial.reverse_mul_of_domain
theorem trailingCoeff_mul {R : Type*} [Ring R] [NoZeroDivisors R] (p q : R[X]) :
(p * q).trailingCoeff = p.trailingCoeff * q.trailingCoeff := by
rw [← reverse_leadingCoeff, reverse_mul_of_domain, leadingCoeff_mul, reverse_leadingCoeff,
reverse_leadingCoeff]
#align polynomial.trailing_coeff_mul Polynomial.trailingCoeff_mul
@[simp]
theorem coeff_one_reverse (f : R[X]) : coeff (reverse f) 1 = nextCoeff f := by
rw [coeff_reverse, nextCoeff]
split_ifs with hf
· have : coeff f 1 = 0 := coeff_eq_zero_of_natDegree_lt (by simp only [hf, zero_lt_one])
simp [*, revAt]
· rw [revAt_le]
exact Nat.succ_le_iff.2 (pos_iff_ne_zero.2 hf)
#align polynomial.coeff_one_reverse Polynomial.coeff_one_reverse
@[simp] lemma reverse_C (t : R) :
reverse (C t) = C t := by
simp [reverse]
@[simp] lemma reverse_mul_X (p : R[X]) : reverse (p * X) = reverse p := by
nontriviality R
rcases eq_or_ne p 0 with rfl | hp
· simp
· simp [reverse, hp]
@[simp] lemma reverse_X_mul (p : R[X]) : reverse (X * p) = reverse p := by
rw [commute_X p, reverse_mul_X]
@[simp] lemma reverse_mul_X_pow (p : R[X]) (n : ℕ) : reverse (p * X ^ n) = reverse p := by
induction' n with n ih
· simp
rw [pow_succ, ← mul_assoc, reverse_mul_X, ih]
@[simp] lemma reverse_X_pow_mul (p : R[X]) (n : ℕ) : reverse (X ^ n * p) = reverse p := by
rw [commute_X_pow p, reverse_mul_X_pow]
@[simp] lemma reverse_add_C (p : R[X]) (t : R) :
reverse (p + C t) = reverse p + C t * X ^ p.natDegree := by
simp [reverse]
@[simp] lemma reverse_C_add (p : R[X]) (t : R) :
reverse (C t + p) = C t * X ^ p.natDegree + reverse p := by
rw [add_comm, reverse_add_C, add_comm]
section Eval₂
variable {S : Type*} [CommSemiring S]
theorem eval₂_reverse_mul_pow (i : R →+* S) (x : S) [Invertible x] (f : R[X]) :
eval₂ i (⅟ x) (reverse f) * x ^ f.natDegree = eval₂ i x f :=
eval₂_reflect_mul_pow i _ _ f le_rfl
#align polynomial.eval₂_reverse_mul_pow Polynomial.eval₂_reverse_mul_pow
@[simp]
theorem eval₂_reverse_eq_zero_iff (i : R →+* S) (x : S) [Invertible x] (f : R[X]) :
eval₂ i (⅟ x) (reverse f) = 0 ↔ eval₂ i x f = 0 :=
eval₂_reflect_eq_zero_iff i x _ _ le_rfl
#align polynomial.eval₂_reverse_eq_zero_iff Polynomial.eval₂_reverse_eq_zero_iff
end Eval₂
end Semiring
section Ring
variable {R : Type*} [Ring R]
@[simp]
| Mathlib/Algebra/Polynomial/Reverse.lean | 398 | 399 | theorem reflect_neg (f : R[X]) (N : ℕ) : reflect N (-f) = -reflect N f := by |
rw [neg_eq_neg_one_mul, ← C_1, ← C_neg, reflect_C_mul, C_neg, C_1, ← neg_eq_neg_one_mul]
|
/-
Copyright (c) 2021 Jakob Scholbach. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob Scholbach
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.CharP.Algebra
import Mathlib.Data.Nat.Prime
#align_import algebra.char_p.exp_char from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a"
/-!
# Exponential characteristic
This file defines the exponential characteristic, which is defined to be 1 for a ring with
characteristic 0 and the same as the ordinary characteristic, if the ordinary characteristic is
prime. This concept is useful to simplify some theorem statements.
This file establishes a few basic results relating it to the (ordinary characteristic).
The definition is stated for a semiring, but the actual results are for nontrivial rings
(as far as exponential characteristic one is concerned), respectively a ring without zero-divisors
(for prime characteristic).
## Main results
- `ExpChar`: the definition of exponential characteristic
- `expChar_is_prime_or_one`: the exponential characteristic is a prime or one
- `char_eq_expChar_iff`: the characteristic equals the exponential characteristic iff the
characteristic is prime
## Tags
exponential characteristic, characteristic
-/
universe u
variable (R : Type u)
section Semiring
variable [Semiring R]
/-- The definition of the exponential characteristic of a semiring. -/
class inductive ExpChar (R : Type u) [Semiring R] : ℕ → Prop
| zero [CharZero R] : ExpChar R 1
| prime {q : ℕ} (hprime : q.Prime) [hchar : CharP R q] : ExpChar R q
#align exp_char ExpChar
#align exp_char.prime ExpChar.prime
instance expChar_prime (p) [CharP R p] [Fact p.Prime] : ExpChar R p := ExpChar.prime Fact.out
instance expChar_zero [CharZero R] : ExpChar R 1 := ExpChar.zero
instance (S : Type*) [Semiring S] (p) [ExpChar R p] [ExpChar S p] : ExpChar (R × S) p := by
obtain hp | ⟨hp⟩ := ‹ExpChar R p›
· have := Prod.charZero_of_left R S; exact .zero
obtain _ | _ := ‹ExpChar S p›
· exact (Nat.not_prime_one hp).elim
· have := Prod.charP R S p; exact .prime hp
variable {R} in
/-- The exponential characteristic is unique. -/
theorem ExpChar.eq {p q : ℕ} (hp : ExpChar R p) (hq : ExpChar R q) : p = q := by
cases' hp with hp _ hp' hp
· cases' hq with hq _ hq' hq
exacts [rfl, False.elim (Nat.not_prime_zero (CharP.eq R hq (CharP.ofCharZero R) ▸ hq'))]
· cases' hq with hq _ hq' hq
exacts [False.elim (Nat.not_prime_zero (CharP.eq R hp (CharP.ofCharZero R) ▸ hp')),
CharP.eq R hp hq]
theorem ExpChar.congr {p : ℕ} (q : ℕ) [hq : ExpChar R q] (h : q = p) : ExpChar R p := h ▸ hq
/-- Noncomputable function that outputs the unique exponential characteristic of a semiring. -/
noncomputable def ringExpChar (R : Type*) [NonAssocSemiring R] : ℕ := max (ringChar R) 1
theorem ringExpChar.eq (q : ℕ) [h : ExpChar R q] : ringExpChar R = q := by
cases' h with _ _ h _
· haveI := CharP.ofCharZero R
rw [ringExpChar, ringChar.eq R 0]; rfl
rw [ringExpChar, ringChar.eq R q]
exact Nat.max_eq_left h.one_lt.le
@[simp]
theorem ringExpChar.eq_one (R : Type*) [NonAssocSemiring R] [CharZero R] : ringExpChar R = 1 := by
rw [ringExpChar, ringChar.eq_zero, max_eq_right zero_le_one]
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem expChar_one_of_char_zero (q : ℕ) [hp : CharP R 0] [hq : ExpChar R q] : q = 1 := by
cases' hq with q hq_one hq_prime hq_hchar
· rfl
· exact False.elim <| hq_prime.ne_zero <| hq_hchar.eq R hp
#align exp_char_one_of_char_zero expChar_one_of_char_zero
/-- The characteristic equals the exponential characteristic iff the former is prime. -/
theorem char_eq_expChar_iff (p q : ℕ) [hp : CharP R p] [hq : ExpChar R q] : p = q ↔ p.Prime := by
cases' hq with q hq_one hq_prime hq_hchar
· rw [(CharP.eq R hp inferInstance : p = 0)]
decide
· exact ⟨fun hpq => hpq.symm ▸ hq_prime, fun _ => CharP.eq R hp hq_hchar⟩
#align char_eq_exp_char_iff char_eq_expChar_iff
section Nontrivial
variable [Nontrivial R]
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem char_zero_of_expChar_one (p : ℕ) [hp : CharP R p] [hq : ExpChar R 1] : p = 0 := by
cases hq
· exact CharP.eq R hp inferInstance
· exact False.elim (CharP.char_ne_one R 1 rfl)
#align char_zero_of_exp_char_one char_zero_of_expChar_one
-- This could be an instance, but there are no `ExpChar R 1` instances in mathlib.
/-- The characteristic is zero if the exponential characteristic is one. -/
theorem charZero_of_expChar_one' [hq : ExpChar R 1] : CharZero R := by
cases hq
· assumption
· exact False.elim (CharP.char_ne_one R 1 rfl)
#align char_zero_of_exp_char_one' charZero_of_expChar_one'
/-- The exponential characteristic is one iff the characteristic is zero. -/
| Mathlib/Algebra/CharP/ExpChar.lean | 120 | 125 | theorem expChar_one_iff_char_zero (p q : ℕ) [CharP R p] [ExpChar R q] : q = 1 ↔ p = 0 := by |
constructor
· rintro rfl
exact char_zero_of_expChar_one R p
· rintro rfl
exact expChar_one_of_char_zero R q
|
/-
Copyright (c) 2020 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.GCDMonoid.Multiset
import Mathlib.Combinatorics.Enumerative.Partition
import Mathlib.Data.List.Rotate
import Mathlib.GroupTheory.Perm.Cycle.Factors
import Mathlib.GroupTheory.Perm.Closure
import Mathlib.Algebra.GCDMonoid.Nat
import Mathlib.Tactic.NormNum.GCD
#align_import group_theory.perm.cycle.type from "leanprover-community/mathlib"@"47adfab39a11a072db552f47594bf8ed2cf8a722"
/-!
# Cycle Types
In this file we define the cycle type of a permutation.
## Main definitions
- `Equiv.Perm.cycleType σ` where `σ` is a permutation of a `Fintype`
- `Equiv.Perm.partition σ` where `σ` is a permutation of a `Fintype`
## Main results
- `sum_cycleType` : The sum of `σ.cycleType` equals `σ.support.card`
- `lcm_cycleType` : The lcm of `σ.cycleType` equals `orderOf σ`
- `isConj_iff_cycleType_eq` : Two permutations are conjugate if and only if they have the same
cycle type.
- `exists_prime_orderOf_dvd_card`: For every prime `p` dividing the order of a finite group `G`
there exists an element of order `p` in `G`. This is known as Cauchy's theorem.
-/
namespace Equiv.Perm
open Equiv List Multiset
variable {α : Type*} [Fintype α]
section CycleType
variable [DecidableEq α]
/-- The cycle type of a permutation -/
def cycleType (σ : Perm α) : Multiset ℕ :=
σ.cycleFactorsFinset.1.map (Finset.card ∘ support)
#align equiv.perm.cycle_type Equiv.Perm.cycleType
theorem cycleType_def (σ : Perm α) :
σ.cycleType = σ.cycleFactorsFinset.1.map (Finset.card ∘ support) :=
rfl
#align equiv.perm.cycle_type_def Equiv.Perm.cycleType_def
theorem cycleType_eq' {σ : Perm α} (s : Finset (Perm α)) (h1 : ∀ f : Perm α, f ∈ s → f.IsCycle)
(h2 : (s : Set (Perm α)).Pairwise Disjoint)
(h0 : s.noncommProd id (h2.imp fun _ _ => Disjoint.commute) = σ) :
σ.cycleType = s.1.map (Finset.card ∘ support) := by
rw [cycleType_def]
congr
rw [cycleFactorsFinset_eq_finset]
exact ⟨h1, h2, h0⟩
#align equiv.perm.cycle_type_eq' Equiv.Perm.cycleType_eq'
theorem cycleType_eq {σ : Perm α} (l : List (Perm α)) (h0 : l.prod = σ)
(h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) :
σ.cycleType = l.map (Finset.card ∘ support) := by
have hl : l.Nodup := nodup_of_pairwise_disjoint_cycles h1 h2
rw [cycleType_eq' l.toFinset]
· simp [List.dedup_eq_self.mpr hl, (· ∘ ·)]
· simpa using h1
· simpa [hl] using h2
· simp [hl, h0]
#align equiv.perm.cycle_type_eq Equiv.Perm.cycleType_eq
@[simp] -- Porting note: new attr
theorem cycleType_eq_zero {σ : Perm α} : σ.cycleType = 0 ↔ σ = 1 := by
simp [cycleType_def, cycleFactorsFinset_eq_empty_iff]
#align equiv.perm.cycle_type_eq_zero Equiv.Perm.cycleType_eq_zero
@[simp] -- Porting note: new attr
theorem cycleType_one : (1 : Perm α).cycleType = 0 := cycleType_eq_zero.2 rfl
#align equiv.perm.cycle_type_one Equiv.Perm.cycleType_one
theorem card_cycleType_eq_zero {σ : Perm α} : Multiset.card σ.cycleType = 0 ↔ σ = 1 := by
rw [card_eq_zero, cycleType_eq_zero]
#align equiv.perm.card_cycle_type_eq_zero Equiv.Perm.card_cycleType_eq_zero
theorem card_cycleType_pos {σ : Perm α} : 0 < Multiset.card σ.cycleType ↔ σ ≠ 1 :=
pos_iff_ne_zero.trans card_cycleType_eq_zero.not
theorem two_le_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 2 ≤ n := by
simp only [cycleType_def, ← Finset.mem_def, Function.comp_apply, Multiset.mem_map,
mem_cycleFactorsFinset_iff] at h
obtain ⟨_, ⟨hc, -⟩, rfl⟩ := h
exact hc.two_le_card_support
#align equiv.perm.two_le_of_mem_cycle_type Equiv.Perm.two_le_of_mem_cycleType
theorem one_lt_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 1 < n :=
two_le_of_mem_cycleType h
#align equiv.perm.one_lt_of_mem_cycle_type Equiv.Perm.one_lt_of_mem_cycleType
theorem IsCycle.cycleType {σ : Perm α} (hσ : IsCycle σ) : σ.cycleType = [σ.support.card] :=
cycleType_eq [σ] (mul_one σ) (fun _τ hτ => (congr_arg IsCycle (List.mem_singleton.mp hτ)).mpr hσ)
(List.pairwise_singleton Disjoint σ)
#align equiv.perm.is_cycle.cycle_type Equiv.Perm.IsCycle.cycleType
theorem card_cycleType_eq_one {σ : Perm α} : Multiset.card σ.cycleType = 1 ↔ σ.IsCycle := by
rw [card_eq_one]
simp_rw [cycleType_def, Multiset.map_eq_singleton, ← Finset.singleton_val, Finset.val_inj,
cycleFactorsFinset_eq_singleton_iff]
constructor
· rintro ⟨_, _, ⟨h, -⟩, -⟩
exact h
· intro h
use σ.support.card, σ
simp [h]
#align equiv.perm.card_cycle_type_eq_one Equiv.Perm.card_cycleType_eq_one
theorem Disjoint.cycleType {σ τ : Perm α} (h : Disjoint σ τ) :
(σ * τ).cycleType = σ.cycleType + τ.cycleType := by
rw [cycleType_def, cycleType_def, cycleType_def, h.cycleFactorsFinset_mul_eq_union, ←
Multiset.map_add, Finset.union_val, Multiset.add_eq_union_iff_disjoint.mpr _]
exact Finset.disjoint_val.2 h.disjoint_cycleFactorsFinset
#align equiv.perm.disjoint.cycle_type Equiv.Perm.Disjoint.cycleType
@[simp] -- Porting note: new attr
theorem cycleType_inv (σ : Perm α) : σ⁻¹.cycleType = σ.cycleType :=
cycle_induction_on (P := fun τ : Perm α => τ⁻¹.cycleType = τ.cycleType) σ rfl
(fun σ hσ => by simp only [hσ.cycleType, hσ.inv.cycleType, support_inv])
fun σ τ hστ _ hσ hτ => by
simp only [mul_inv_rev, hστ.cycleType, hστ.symm.inv_left.inv_right.cycleType, hσ, hτ,
add_comm]
#align equiv.perm.cycle_type_inv Equiv.Perm.cycleType_inv
@[simp] -- Porting note: new attr
theorem cycleType_conj {σ τ : Perm α} : (τ * σ * τ⁻¹).cycleType = σ.cycleType := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => rw [hσ.cycleType, hσ.conj.cycleType, card_support_conj]
| induction_disjoint σ π hd _ hσ hπ =>
rw [← conj_mul, hd.cycleType, (hd.conj _).cycleType, hσ, hπ]
#align equiv.perm.cycle_type_conj Equiv.Perm.cycleType_conj
theorem sum_cycleType (σ : Perm α) : σ.cycleType.sum = σ.support.card := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => rw [hσ.cycleType, sum_coe, List.sum_singleton]
| induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, sum_add, hσ, hτ, hd.card_support_mul]
#align equiv.perm.sum_cycle_type Equiv.Perm.sum_cycleType
theorem sign_of_cycleType' (σ : Perm α) :
sign σ = (σ.cycleType.map fun n => -(-1 : ℤˣ) ^ n).prod := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => simp [hσ.cycleType, hσ.sign]
| induction_disjoint σ τ hd _ hσ hτ => simp [hσ, hτ, hd.cycleType]
#align equiv.perm.sign_of_cycle_type' Equiv.Perm.sign_of_cycleType'
theorem sign_of_cycleType (f : Perm α) :
sign f = (-1 : ℤˣ) ^ (f.cycleType.sum + Multiset.card f.cycleType) := by
rw [sign_of_cycleType']
induction' f.cycleType using Multiset.induction_on with a s ihs
· rfl
· rw [Multiset.map_cons, Multiset.prod_cons, Multiset.sum_cons, Multiset.card_cons, ihs]
simp only [pow_add, pow_one, mul_neg_one, neg_mul, mul_neg, mul_assoc, mul_one]
#align equiv.perm.sign_of_cycle_type Equiv.Perm.sign_of_cycleType
@[simp] -- Porting note: new attr
theorem lcm_cycleType (σ : Perm α) : σ.cycleType.lcm = orderOf σ := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => simp [hσ.cycleType, hσ.orderOf]
| induction_disjoint σ τ hd _ hσ hτ => simp [hd.cycleType, hd.orderOf, lcm_eq_nat_lcm, hσ, hτ]
#align equiv.perm.lcm_cycle_type Equiv.Perm.lcm_cycleType
theorem dvd_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : n ∣ orderOf σ := by
rw [← lcm_cycleType]
exact dvd_lcm h
#align equiv.perm.dvd_of_mem_cycle_type Equiv.Perm.dvd_of_mem_cycleType
| Mathlib/GroupTheory/Perm/Cycle/Type.lean | 184 | 192 | theorem orderOf_cycleOf_dvd_orderOf (f : Perm α) (x : α) : orderOf (cycleOf f x) ∣ orderOf f := by |
by_cases hx : f x = x
· rw [← cycleOf_eq_one_iff] at hx
simp [hx]
· refine dvd_of_mem_cycleType ?_
rw [cycleType, Multiset.mem_map]
refine ⟨f.cycleOf x, ?_, ?_⟩
· rwa [← Finset.mem_def, cycleOf_mem_cycleFactorsFinset_iff, mem_support]
· simp [(isCycle_cycleOf _ hx).orderOf]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Data.ENat.Lattice
import Mathlib.Data.Part
import Mathlib.Tactic.NormNum
#align_import data.nat.part_enat from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8"
/-!
# Natural numbers with infinity
The natural numbers and an extra `top` element `⊤`. This implementation uses `Part ℕ` as an
implementation. Use `ℕ∞` instead unless you care about computability.
## Main definitions
The following instances are defined:
* `OrderedAddCommMonoid PartENat`
* `CanonicallyOrderedAddCommMonoid PartENat`
* `CompleteLinearOrder PartENat`
There is no additive analogue of `MonoidWithZero`; if there were then `PartENat` could
be an `AddMonoidWithTop`.
* `toWithTop` : the map from `PartENat` to `ℕ∞`, with theorems that it plays well
with `+` and `≤`.
* `withTopAddEquiv : PartENat ≃+ ℕ∞`
* `withTopOrderIso : PartENat ≃o ℕ∞`
## Implementation details
`PartENat` is defined to be `Part ℕ`.
`+` and `≤` are defined on `PartENat`, but there is an issue with `*` because it's not
clear what `0 * ⊤` should be. `mul` is hence left undefined. Similarly `⊤ - ⊤` is ambiguous
so there is no `-` defined on `PartENat`.
Before the `open scoped Classical` line, various proofs are made with decidability assumptions.
This can cause issues -- see for example the non-simp lemma `toWithTopZero` proved by `rfl`,
followed by `@[simp] lemma toWithTopZero'` whose proof uses `convert`.
## Tags
PartENat, ℕ∞
-/
open Part hiding some
/-- Type of natural numbers with infinity (`⊤`) -/
def PartENat : Type :=
Part ℕ
#align part_enat PartENat
namespace PartENat
/-- The computable embedding `ℕ → PartENat`.
This coincides with the coercion `coe : ℕ → PartENat`, see `PartENat.some_eq_natCast`. -/
@[coe]
def some : ℕ → PartENat :=
Part.some
#align part_enat.some PartENat.some
instance : Zero PartENat :=
⟨some 0⟩
instance : Inhabited PartENat :=
⟨0⟩
instance : One PartENat :=
⟨some 1⟩
instance : Add PartENat :=
⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => get x h.1 + get y h.2⟩⟩
instance (n : ℕ) : Decidable (some n).Dom :=
isTrue trivial
@[simp]
theorem dom_some (x : ℕ) : (some x).Dom :=
trivial
#align part_enat.dom_some PartENat.dom_some
instance addCommMonoid : AddCommMonoid PartENat where
add := (· + ·)
zero := 0
add_comm x y := Part.ext' and_comm fun _ _ => add_comm _ _
zero_add x := Part.ext' (true_and_iff _) fun _ _ => zero_add _
add_zero x := Part.ext' (and_true_iff _) fun _ _ => add_zero _
add_assoc x y z := Part.ext' and_assoc fun _ _ => add_assoc _ _ _
nsmul := nsmulRec
instance : AddCommMonoidWithOne PartENat :=
{ PartENat.addCommMonoid with
one := 1
natCast := some
natCast_zero := rfl
natCast_succ := fun _ => Part.ext' (true_and_iff _).symm fun _ _ => rfl }
theorem some_eq_natCast (n : ℕ) : some n = n :=
rfl
#align part_enat.some_eq_coe PartENat.some_eq_natCast
instance : CharZero PartENat where
cast_injective := Part.some_injective
/-- Alias of `Nat.cast_inj` specialized to `PartENat` --/
theorem natCast_inj {x y : ℕ} : (x : PartENat) = y ↔ x = y :=
Nat.cast_inj
#align part_enat.coe_inj PartENat.natCast_inj
@[simp]
theorem dom_natCast (x : ℕ) : (x : PartENat).Dom :=
trivial
#align part_enat.dom_coe PartENat.dom_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem dom_ofNat (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)).Dom :=
trivial
@[simp]
theorem dom_zero : (0 : PartENat).Dom :=
trivial
@[simp]
theorem dom_one : (1 : PartENat).Dom :=
trivial
instance : CanLift PartENat ℕ (↑) Dom :=
⟨fun n hn => ⟨n.get hn, Part.some_get _⟩⟩
instance : LE PartENat :=
⟨fun x y => ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy⟩
instance : Top PartENat :=
⟨none⟩
instance : Bot PartENat :=
⟨0⟩
instance : Sup PartENat :=
⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => x.get h.1 ⊔ y.get h.2⟩⟩
theorem le_def (x y : PartENat) :
x ≤ y ↔ ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy :=
Iff.rfl
#align part_enat.le_def PartENat.le_def
@[elab_as_elim]
protected theorem casesOn' {P : PartENat → Prop} :
∀ a : PartENat, P ⊤ → (∀ n : ℕ, P (some n)) → P a :=
Part.induction_on
#align part_enat.cases_on' PartENat.casesOn'
@[elab_as_elim]
protected theorem casesOn {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P n) → P a := by
exact PartENat.casesOn'
#align part_enat.cases_on PartENat.casesOn
-- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later
theorem top_add (x : PartENat) : ⊤ + x = ⊤ :=
Part.ext' (false_and_iff _) fun h => h.left.elim
#align part_enat.top_add PartENat.top_add
-- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later
theorem add_top (x : PartENat) : x + ⊤ = ⊤ := by rw [add_comm, top_add]
#align part_enat.add_top PartENat.add_top
@[simp]
theorem natCast_get {x : PartENat} (h : x.Dom) : (x.get h : PartENat) = x := by
exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl
#align part_enat.coe_get PartENat.natCast_get
@[simp, norm_cast]
theorem get_natCast' (x : ℕ) (h : (x : PartENat).Dom) : get (x : PartENat) h = x := by
rw [← natCast_inj, natCast_get]
#align part_enat.get_coe' PartENat.get_natCast'
theorem get_natCast {x : ℕ} : get (x : PartENat) (dom_natCast x) = x :=
get_natCast' _ _
#align part_enat.get_coe PartENat.get_natCast
theorem coe_add_get {x : ℕ} {y : PartENat} (h : ((x : PartENat) + y).Dom) :
get ((x : PartENat) + y) h = x + get y h.2 := by
rfl
#align part_enat.coe_add_get PartENat.coe_add_get
@[simp]
theorem get_add {x y : PartENat} (h : (x + y).Dom) : get (x + y) h = x.get h.1 + y.get h.2 :=
rfl
#align part_enat.get_add PartENat.get_add
@[simp]
theorem get_zero (h : (0 : PartENat).Dom) : (0 : PartENat).get h = 0 :=
rfl
#align part_enat.get_zero PartENat.get_zero
@[simp]
theorem get_one (h : (1 : PartENat).Dom) : (1 : PartENat).get h = 1 :=
rfl
#align part_enat.get_one PartENat.get_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem get_ofNat' (x : ℕ) [x.AtLeastTwo] (h : (no_index (OfNat.ofNat x : PartENat)).Dom) :
Part.get (no_index (OfNat.ofNat x : PartENat)) h = (no_index (OfNat.ofNat x)) :=
get_natCast' x h
nonrec theorem get_eq_iff_eq_some {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = some b :=
get_eq_iff_eq_some
#align part_enat.get_eq_iff_eq_some PartENat.get_eq_iff_eq_some
theorem get_eq_iff_eq_coe {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = b := by
rw [get_eq_iff_eq_some]
rfl
#align part_enat.get_eq_iff_eq_coe PartENat.get_eq_iff_eq_coe
theorem dom_of_le_of_dom {x y : PartENat} : x ≤ y → y.Dom → x.Dom := fun ⟨h, _⟩ => h
#align part_enat.dom_of_le_of_dom PartENat.dom_of_le_of_dom
theorem dom_of_le_some {x : PartENat} {y : ℕ} (h : x ≤ some y) : x.Dom :=
dom_of_le_of_dom h trivial
#align part_enat.dom_of_le_some PartENat.dom_of_le_some
theorem dom_of_le_natCast {x : PartENat} {y : ℕ} (h : x ≤ y) : x.Dom := by
exact dom_of_le_some h
#align part_enat.dom_of_le_coe PartENat.dom_of_le_natCast
instance decidableLe (x y : PartENat) [Decidable x.Dom] [Decidable y.Dom] : Decidable (x ≤ y) :=
if hx : x.Dom then
decidable_of_decidable_of_iff (by rw [le_def])
else
if hy : y.Dom then isFalse fun h => hx <| dom_of_le_of_dom h hy
else isTrue ⟨fun h => (hy h).elim, fun h => (hy h).elim⟩
#align part_enat.decidable_le PartENat.decidableLe
-- Porting note: Removed. Use `Nat.castAddMonoidHom` instead.
#noalign part_enat.coe_hom
#noalign part_enat.coe_coe_hom
instance partialOrder : PartialOrder PartENat where
le := (· ≤ ·)
le_refl _ := ⟨id, fun _ => le_rfl⟩
le_trans := fun _ _ _ ⟨hxy₁, hxy₂⟩ ⟨hyz₁, hyz₂⟩ =>
⟨hxy₁ ∘ hyz₁, fun _ => le_trans (hxy₂ _) (hyz₂ _)⟩
lt_iff_le_not_le _ _ := Iff.rfl
le_antisymm := fun _ _ ⟨hxy₁, hxy₂⟩ ⟨hyx₁, hyx₂⟩ =>
Part.ext' ⟨hyx₁, hxy₁⟩ fun _ _ => le_antisymm (hxy₂ _) (hyx₂ _)
theorem lt_def (x y : PartENat) : x < y ↔ ∃ hx : x.Dom, ∀ hy : y.Dom, x.get hx < y.get hy := by
rw [lt_iff_le_not_le, le_def, le_def, not_exists]
constructor
· rintro ⟨⟨hyx, H⟩, h⟩
by_cases hx : x.Dom
· use hx
intro hy
specialize H hy
specialize h fun _ => hy
rw [not_forall] at h
cases' h with hx' h
rw [not_le] at h
exact h
· specialize h fun hx' => (hx hx').elim
rw [not_forall] at h
cases' h with hx' h
exact (hx hx').elim
· rintro ⟨hx, H⟩
exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩
#align part_enat.lt_def PartENat.lt_def
noncomputable instance orderedAddCommMonoid : OrderedAddCommMonoid PartENat :=
{ PartENat.partialOrder, PartENat.addCommMonoid with
add_le_add_left := fun a b ⟨h₁, h₂⟩ c =>
PartENat.casesOn c (by simp [top_add]) fun c =>
⟨fun h => And.intro (dom_natCast _) (h₁ h.2), fun h => by
simpa only [coe_add_get] using add_le_add_left (h₂ _) c⟩ }
instance semilatticeSup : SemilatticeSup PartENat :=
{ PartENat.partialOrder with
sup := (· ⊔ ·)
le_sup_left := fun _ _ => ⟨And.left, fun _ => le_sup_left⟩
le_sup_right := fun _ _ => ⟨And.right, fun _ => le_sup_right⟩
sup_le := fun _ _ _ ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ =>
⟨fun hz => ⟨hx₁ hz, hy₁ hz⟩, fun _ => sup_le (hx₂ _) (hy₂ _)⟩ }
#align part_enat.semilattice_sup PartENat.semilatticeSup
instance orderBot : OrderBot PartENat where
bot := ⊥
bot_le _ := ⟨fun _ => trivial, fun _ => Nat.zero_le _⟩
#align part_enat.order_bot PartENat.orderBot
instance orderTop : OrderTop PartENat where
top := ⊤
le_top _ := ⟨fun h => False.elim h, fun hy => False.elim hy⟩
#align part_enat.order_top PartENat.orderTop
instance : ZeroLEOneClass PartENat where
zero_le_one := bot_le
/-- Alias of `Nat.cast_le` specialized to `PartENat` --/
theorem coe_le_coe {x y : ℕ} : (x : PartENat) ≤ y ↔ x ≤ y := Nat.cast_le
#align part_enat.coe_le_coe PartENat.coe_le_coe
/-- Alias of `Nat.cast_lt` specialized to `PartENat` --/
theorem coe_lt_coe {x y : ℕ} : (x : PartENat) < y ↔ x < y := Nat.cast_lt
#align part_enat.coe_lt_coe PartENat.coe_lt_coe
@[simp]
theorem get_le_get {x y : PartENat} {hx : x.Dom} {hy : y.Dom} : x.get hx ≤ y.get hy ↔ x ≤ y := by
conv =>
lhs
rw [← coe_le_coe, natCast_get, natCast_get]
#align part_enat.get_le_get PartENat.get_le_get
theorem le_coe_iff (x : PartENat) (n : ℕ) : x ≤ n ↔ ∃ h : x.Dom, x.get h ≤ n := by
show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n
simp only [forall_prop_of_true, dom_natCast, get_natCast']
#align part_enat.le_coe_iff PartENat.le_coe_iff
theorem lt_coe_iff (x : PartENat) (n : ℕ) : x < n ↔ ∃ h : x.Dom, x.get h < n := by
simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast]
#align part_enat.lt_coe_iff PartENat.lt_coe_iff
theorem coe_le_iff (n : ℕ) (x : PartENat) : (n : PartENat) ≤ x ↔ ∀ h : x.Dom, n ≤ x.get h := by
rw [← some_eq_natCast]
simp only [le_def, exists_prop_of_true, dom_some, forall_true_iff]
rfl
#align part_enat.coe_le_iff PartENat.coe_le_iff
theorem coe_lt_iff (n : ℕ) (x : PartENat) : (n : PartENat) < x ↔ ∀ h : x.Dom, n < x.get h := by
rw [← some_eq_natCast]
simp only [lt_def, exists_prop_of_true, dom_some, forall_true_iff]
rfl
#align part_enat.coe_lt_iff PartENat.coe_lt_iff
nonrec theorem eq_zero_iff {x : PartENat} : x = 0 ↔ x ≤ 0 :=
eq_bot_iff
#align part_enat.eq_zero_iff PartENat.eq_zero_iff
theorem ne_zero_iff {x : PartENat} : x ≠ 0 ↔ ⊥ < x :=
bot_lt_iff_ne_bot.symm
#align part_enat.ne_zero_iff PartENat.ne_zero_iff
theorem dom_of_lt {x y : PartENat} : x < y → x.Dom :=
PartENat.casesOn x not_top_lt fun _ _ => dom_natCast _
#align part_enat.dom_of_lt PartENat.dom_of_lt
theorem top_eq_none : (⊤ : PartENat) = Part.none :=
rfl
#align part_enat.top_eq_none PartENat.top_eq_none
@[simp]
theorem natCast_lt_top (x : ℕ) : (x : PartENat) < ⊤ :=
Ne.lt_top fun h => absurd (congr_arg Dom h) <| by simp only [dom_natCast]; exact true_ne_false
#align part_enat.coe_lt_top PartENat.natCast_lt_top
@[simp]
theorem zero_lt_top : (0 : PartENat) < ⊤ :=
natCast_lt_top 0
@[simp]
theorem one_lt_top : (1 : PartENat) < ⊤ :=
natCast_lt_top 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_lt_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) < ⊤ :=
natCast_lt_top x
@[simp]
theorem natCast_ne_top (x : ℕ) : (x : PartENat) ≠ ⊤ :=
ne_of_lt (natCast_lt_top x)
#align part_enat.coe_ne_top PartENat.natCast_ne_top
@[simp]
theorem zero_ne_top : (0 : PartENat) ≠ ⊤ :=
natCast_ne_top 0
@[simp]
theorem one_ne_top : (1 : PartENat) ≠ ⊤ :=
natCast_ne_top 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_ne_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) ≠ ⊤ :=
natCast_ne_top x
theorem not_isMax_natCast (x : ℕ) : ¬IsMax (x : PartENat) :=
not_isMax_of_lt (natCast_lt_top x)
#align part_enat.not_is_max_coe PartENat.not_isMax_natCast
theorem ne_top_iff {x : PartENat} : x ≠ ⊤ ↔ ∃ n : ℕ, x = n := by
simpa only [← some_eq_natCast] using Part.ne_none_iff
#align part_enat.ne_top_iff PartENat.ne_top_iff
theorem ne_top_iff_dom {x : PartENat} : x ≠ ⊤ ↔ x.Dom := by
classical exact not_iff_comm.1 Part.eq_none_iff'.symm
#align part_enat.ne_top_iff_dom PartENat.ne_top_iff_dom
theorem not_dom_iff_eq_top {x : PartENat} : ¬x.Dom ↔ x = ⊤ :=
Iff.not_left ne_top_iff_dom.symm
#align part_enat.not_dom_iff_eq_top PartENat.not_dom_iff_eq_top
theorem ne_top_of_lt {x y : PartENat} (h : x < y) : x ≠ ⊤ :=
ne_of_lt <| lt_of_lt_of_le h le_top
#align part_enat.ne_top_of_lt PartENat.ne_top_of_lt
theorem eq_top_iff_forall_lt (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) < x := by
constructor
· rintro rfl n
exact natCast_lt_top _
· contrapose!
rw [ne_top_iff]
rintro ⟨n, rfl⟩
exact ⟨n, irrefl _⟩
#align part_enat.eq_top_iff_forall_lt PartENat.eq_top_iff_forall_lt
theorem eq_top_iff_forall_le (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) ≤ x :=
(eq_top_iff_forall_lt x).trans
⟨fun h n => (h n).le, fun h n => lt_of_lt_of_le (coe_lt_coe.mpr n.lt_succ_self) (h (n + 1))⟩
#align part_enat.eq_top_iff_forall_le PartENat.eq_top_iff_forall_le
theorem pos_iff_one_le {x : PartENat} : 0 < x ↔ 1 ≤ x :=
PartENat.casesOn x
(by simp only [iff_true_iff, le_top, natCast_lt_top, ← @Nat.cast_zero PartENat])
fun n => by
rw [← Nat.cast_zero, ← Nat.cast_one, PartENat.coe_lt_coe, PartENat.coe_le_coe]
rfl
#align part_enat.pos_iff_one_le PartENat.pos_iff_one_le
instance isTotal : IsTotal PartENat (· ≤ ·) where
total x y :=
PartENat.casesOn (P := fun z => z ≤ y ∨ y ≤ z) x (Or.inr le_top)
(PartENat.casesOn y (fun _ => Or.inl le_top) fun x y =>
(le_total x y).elim (Or.inr ∘ coe_le_coe.2) (Or.inl ∘ coe_le_coe.2))
noncomputable instance linearOrder : LinearOrder PartENat :=
{ PartENat.partialOrder with
le_total := IsTotal.total
decidableLE := Classical.decRel _
max := (· ⊔ ·)
-- Porting note: was `max_def := @sup_eq_maxDefault _ _ (id _) _ }`
max_def := fun a b => by
change (fun a b => a ⊔ b) a b = _
rw [@sup_eq_maxDefault PartENat _ (id _) _]
rfl }
instance boundedOrder : BoundedOrder PartENat :=
{ PartENat.orderTop, PartENat.orderBot with }
noncomputable instance lattice : Lattice PartENat :=
{ PartENat.semilatticeSup with
inf := min
inf_le_left := min_le_left
inf_le_right := min_le_right
le_inf := fun _ _ _ => le_min }
noncomputable instance : CanonicallyOrderedAddCommMonoid PartENat :=
{ PartENat.semilatticeSup, PartENat.orderBot,
PartENat.orderedAddCommMonoid with
le_self_add := fun a b =>
PartENat.casesOn b (le_top.trans_eq (add_top _).symm) fun b =>
PartENat.casesOn a (top_add _).ge fun a =>
(coe_le_coe.2 le_self_add).trans_eq (Nat.cast_add _ _)
exists_add_of_le := fun {a b} =>
PartENat.casesOn b (fun _ => ⟨⊤, (add_top _).symm⟩) fun b =>
PartENat.casesOn a (fun h => ((natCast_lt_top _).not_le h).elim) fun a h =>
⟨(b - a : ℕ), by
rw [← Nat.cast_add, natCast_inj, add_comm, tsub_add_cancel_of_le (coe_le_coe.1 h)]⟩ }
theorem eq_natCast_sub_of_add_eq_natCast {x y : PartENat} {n : ℕ} (h : x + y = n) :
x = ↑(n - y.get (dom_of_le_natCast ((le_add_left le_rfl).trans_eq h))) := by
lift x to ℕ using dom_of_le_natCast ((le_add_right le_rfl).trans_eq h)
lift y to ℕ using dom_of_le_natCast ((le_add_left le_rfl).trans_eq h)
rw [← Nat.cast_add, natCast_inj] at h
rw [get_natCast, natCast_inj, eq_tsub_of_add_eq h]
#align part_enat.eq_coe_sub_of_add_eq_coe PartENat.eq_natCast_sub_of_add_eq_natCast
protected theorem add_lt_add_right {x y z : PartENat} (h : x < y) (hz : z ≠ ⊤) : x + z < y + z := by
rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩
rcases ne_top_iff.mp hz with ⟨k, rfl⟩
induction' y using PartENat.casesOn with n
· rw [top_add]
-- Porting note: was apply_mod_cast natCast_lt_top
norm_cast; apply natCast_lt_top
norm_cast at h
-- Porting note: was `apply_mod_cast add_lt_add_right h`
norm_cast; apply add_lt_add_right h
#align part_enat.add_lt_add_right PartENat.add_lt_add_right
protected theorem add_lt_add_iff_right {x y z : PartENat} (hz : z ≠ ⊤) : x + z < y + z ↔ x < y :=
⟨lt_of_add_lt_add_right, fun h => PartENat.add_lt_add_right h hz⟩
#align part_enat.add_lt_add_iff_right PartENat.add_lt_add_iff_right
protected theorem add_lt_add_iff_left {x y z : PartENat} (hz : z ≠ ⊤) : z + x < z + y ↔ x < y := by
rw [add_comm z, add_comm z, PartENat.add_lt_add_iff_right hz]
#align part_enat.add_lt_add_iff_left PartENat.add_lt_add_iff_left
protected theorem lt_add_iff_pos_right {x y : PartENat} (hx : x ≠ ⊤) : x < x + y ↔ 0 < y := by
conv_rhs => rw [← PartENat.add_lt_add_iff_left hx]
rw [add_zero]
#align part_enat.lt_add_iff_pos_right PartENat.lt_add_iff_pos_right
theorem lt_add_one {x : PartENat} (hx : x ≠ ⊤) : x < x + 1 := by
rw [PartENat.lt_add_iff_pos_right hx]
norm_cast
#align part_enat.lt_add_one PartENat.lt_add_one
theorem le_of_lt_add_one {x y : PartENat} (h : x < y + 1) : x ≤ y := by
induction' y using PartENat.casesOn with n
· apply le_top
rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩
-- Porting note: was `apply_mod_cast Nat.le_of_lt_succ; apply_mod_cast h`
norm_cast; apply Nat.le_of_lt_succ; norm_cast at h
#align part_enat.le_of_lt_add_one PartENat.le_of_lt_add_one
theorem add_one_le_of_lt {x y : PartENat} (h : x < y) : x + 1 ≤ y := by
induction' y using PartENat.casesOn with n
· apply le_top
rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩
-- Porting note: was `apply_mod_cast Nat.succ_le_of_lt; apply_mod_cast h`
norm_cast; apply Nat.succ_le_of_lt; norm_cast at h
#align part_enat.add_one_le_of_lt PartENat.add_one_le_of_lt
theorem add_one_le_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x + 1 ≤ y ↔ x < y := by
refine ⟨fun h => ?_, add_one_le_of_lt⟩
rcases ne_top_iff.mp hx with ⟨m, rfl⟩
induction' y using PartENat.casesOn with n
· apply natCast_lt_top
-- Porting note: was `apply_mod_cast Nat.lt_of_succ_le; apply_mod_cast h`
norm_cast; apply Nat.lt_of_succ_le; norm_cast at h
#align part_enat.add_one_le_iff_lt PartENat.add_one_le_iff_lt
theorem coe_succ_le_iff {n : ℕ} {e : PartENat} : ↑n.succ ≤ e ↔ ↑n < e := by
rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, add_one_le_iff_lt (natCast_ne_top n)]
#align part_enat.coe_succ_le_succ_iff PartENat.coe_succ_le_iff
theorem lt_add_one_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x < y + 1 ↔ x ≤ y := by
refine ⟨le_of_lt_add_one, fun h => ?_⟩
rcases ne_top_iff.mp hx with ⟨m, rfl⟩
induction' y using PartENat.casesOn with n
· rw [top_add]
apply natCast_lt_top
-- Porting note: was `apply_mod_cast Nat.lt_succ_of_le; apply_mod_cast h`
norm_cast; apply Nat.lt_succ_of_le; norm_cast at h
#align part_enat.lt_add_one_iff_lt PartENat.lt_add_one_iff_lt
lemma lt_coe_succ_iff_le {x : PartENat} {n : ℕ} (hx : x ≠ ⊤) : x < n.succ ↔ x ≤ n := by
rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, lt_add_one_iff_lt hx]
#align part_enat.lt_coe_succ_iff_le PartENat.lt_coe_succ_iff_le
theorem add_eq_top_iff {a b : PartENat} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by
refine PartENat.casesOn a ?_ ?_
<;> refine PartENat.casesOn b ?_ ?_
<;> simp [top_add, add_top]
simp only [← Nat.cast_add, PartENat.natCast_ne_top, forall_const, not_false_eq_true]
#align part_enat.add_eq_top_iff PartENat.add_eq_top_iff
protected theorem add_right_cancel_iff {a b c : PartENat} (hc : c ≠ ⊤) : a + c = b + c ↔ a = b := by
rcases ne_top_iff.1 hc with ⟨c, rfl⟩
refine PartENat.casesOn a ?_ ?_
<;> refine PartENat.casesOn b ?_ ?_
<;> simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat), top_add]
simp only [← Nat.cast_add, add_left_cancel_iff, PartENat.natCast_inj, add_comm, forall_const]
#align part_enat.add_right_cancel_iff PartENat.add_right_cancel_iff
protected theorem add_left_cancel_iff {a b c : PartENat} (ha : a ≠ ⊤) : a + b = a + c ↔ b = c := by
rw [add_comm a, add_comm a, PartENat.add_right_cancel_iff ha]
#align part_enat.add_left_cancel_iff PartENat.add_left_cancel_iff
section WithTop
/-- Computably converts a `PartENat` to a `ℕ∞`. -/
def toWithTop (x : PartENat) [Decidable x.Dom] : ℕ∞ :=
x.toOption
#align part_enat.to_with_top PartENat.toWithTop
theorem toWithTop_top :
have : Decidable (⊤ : PartENat).Dom := Part.noneDecidable
toWithTop ⊤ = ⊤ :=
rfl
#align part_enat.to_with_top_top PartENat.toWithTop_top
@[simp]
theorem toWithTop_top' {h : Decidable (⊤ : PartENat).Dom} : toWithTop ⊤ = ⊤ := by
convert toWithTop_top
#align part_enat.to_with_top_top' PartENat.toWithTop_top'
theorem toWithTop_zero :
have : Decidable (0 : PartENat).Dom := someDecidable 0
toWithTop 0 = 0 :=
rfl
#align part_enat.to_with_top_zero PartENat.toWithTop_zero
@[simp]
theorem toWithTop_zero' {h : Decidable (0 : PartENat).Dom} : toWithTop 0 = 0 := by
convert toWithTop_zero
#align part_enat.to_with_top_zero' PartENat.toWithTop_zero'
theorem toWithTop_one :
have : Decidable (1 : PartENat).Dom := someDecidable 1
toWithTop 1 = 1 :=
rfl
@[simp]
theorem toWithTop_one' {h : Decidable (1 : PartENat).Dom} : toWithTop 1 = 1 := by
convert toWithTop_one
theorem toWithTop_some (n : ℕ) : toWithTop (some n) = n :=
rfl
#align part_enat.to_with_top_some PartENat.toWithTop_some
theorem toWithTop_natCast (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop n = n := by
simp only [← toWithTop_some]
congr
#align part_enat.to_with_top_coe PartENat.toWithTop_natCast
@[simp]
theorem toWithTop_natCast' (n : ℕ) {_ : Decidable (n : PartENat).Dom} :
toWithTop (n : PartENat) = n := by
rw [toWithTop_natCast n]
#align part_enat.to_with_top_coe' PartENat.toWithTop_natCast'
@[simp]
theorem toWithTop_ofNat (n : ℕ) [n.AtLeastTwo] {_ : Decidable (OfNat.ofNat n : PartENat).Dom} :
toWithTop (no_index (OfNat.ofNat n : PartENat)) = OfNat.ofNat n := toWithTop_natCast' n
-- Porting note: statement changed. Mathlib 3 statement was
-- ```
-- @[simp] lemma to_with_top_le {x y : part_enat} :
-- Π [decidable x.dom] [decidable y.dom], by exactI to_with_top x ≤ to_with_top y ↔ x ≤ y :=
-- ```
-- This used to be really slow to typecheck when the definition of `ENat`
-- was still `deriving AddCommMonoidWithOne`. Now that I removed that it is fine.
-- (The problem was that the last `simp` got stuck at `CharZero ℕ∞ ≟ CharZero ℕ∞` where
-- one side used `instENatAddCommMonoidWithOne` and the other used
-- `NonAssocSemiring.toAddCommMonoidWithOne`. Now the former doesn't exist anymore.)
@[simp]
theorem toWithTop_le {x y : PartENat} [hx : Decidable x.Dom] [hy : Decidable y.Dom] :
toWithTop x ≤ toWithTop y ↔ x ≤ y := by
induction y using PartENat.casesOn generalizing hy
· simp
induction x using PartENat.casesOn generalizing hx
· simp
· simp -- Porting note: this takes too long.
#align part_enat.to_with_top_le PartENat.toWithTop_le
/-
Porting note: As part of the investigation above, I noticed that Lean4 does not
find the following two instances which it could find in Lean3 automatically:
```
#synth Decidable (⊤ : PartENat).Dom
variable {n : ℕ}
#synth Decidable (n : PartENat).Dom
```
-/
@[simp]
theorem toWithTop_lt {x y : PartENat} [Decidable x.Dom] [Decidable y.Dom] :
toWithTop x < toWithTop y ↔ x < y :=
lt_iff_lt_of_le_iff_le toWithTop_le
#align part_enat.to_with_top_lt PartENat.toWithTop_lt
end WithTop
-- Porting note: new, extracted from `withTopEquiv`.
/-- Coercion from `ℕ∞` to `PartENat`. -/
@[coe]
def ofENat : ℕ∞ → PartENat :=
fun x => match x with
| Option.none => none
| Option.some n => some n
-- Porting note (#10754): new instance
instance : Coe ℕ∞ PartENat := ⟨ofENat⟩
-- Porting note: new. This could probably be moved to tests or removed.
example (n : ℕ) : ((n : ℕ∞) : PartENat) = ↑n := rfl
-- Porting note (#10756): new lemma
@[simp, norm_cast]
lemma ofENat_top : ofENat ⊤ = ⊤ := rfl
-- Porting note (#10756): new lemma
@[simp, norm_cast]
lemma ofENat_coe (n : ℕ) : ofENat n = n := rfl
@[simp, norm_cast]
theorem ofENat_zero : ofENat 0 = 0 := rfl
@[simp, norm_cast]
theorem ofENat_one : ofENat 1 = 1 := rfl
@[simp, norm_cast]
theorem ofENat_ofNat (n : Nat) [n.AtLeastTwo] : ofENat (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
rfl
-- Porting note (#10756): new theorem
@[simp, norm_cast]
theorem toWithTop_ofENat (n : ℕ∞) {_ : Decidable (n : PartENat).Dom} : toWithTop (↑n) = n := by
cases n with
| top => simp
| coe n => simp
@[simp, norm_cast]
theorem ofENat_toWithTop (x : PartENat) {_ : Decidable (x : PartENat).Dom} : toWithTop x = x := by
induction x using PartENat.casesOn <;> simp
@[simp, norm_cast]
theorem ofENat_le {x y : ℕ∞} : ofENat x ≤ ofENat y ↔ x ≤ y := by
classical
rw [← toWithTop_le, toWithTop_ofENat, toWithTop_ofENat]
@[simp, norm_cast]
theorem ofENat_lt {x y : ℕ∞} : ofENat x < ofENat y ↔ x < y := by
classical
rw [← toWithTop_lt, toWithTop_ofENat, toWithTop_ofENat]
section WithTopEquiv
open scoped Classical
@[simp]
theorem toWithTop_add {x y : PartENat} : toWithTop (x + y) = toWithTop x + toWithTop y := by
refine PartENat.casesOn y ?_ ?_ <;> refine PartENat.casesOn x ?_ ?_
-- Porting note: was `simp [← Nat.cast_add, ← ENat.coe_add]`
· simp only [add_top, toWithTop_top', _root_.add_top]
· simp only [add_top, toWithTop_top', toWithTop_natCast', _root_.add_top, forall_const]
· simp only [top_add, toWithTop_top', toWithTop_natCast', _root_.top_add, forall_const]
· simp_rw [toWithTop_natCast', ← Nat.cast_add, toWithTop_natCast', forall_const]
#align part_enat.to_with_top_add PartENat.toWithTop_add
/-- `Equiv` between `PartENat` and `ℕ∞` (for the order isomorphism see
`withTopOrderIso`). -/
@[simps]
noncomputable def withTopEquiv : PartENat ≃ ℕ∞ where
toFun x := toWithTop x
invFun x := ↑x
left_inv x := by simp
right_inv x := by simp
#align part_enat.with_top_equiv PartENat.withTopEquiv
theorem withTopEquiv_top : withTopEquiv ⊤ = ⊤ := by
simp
#align part_enat.with_top_equiv_top PartENat.withTopEquiv_top
theorem withTopEquiv_natCast (n : Nat) : withTopEquiv n = n := by
simp
#align part_enat.with_top_equiv_coe PartENat.withTopEquiv_natCast
theorem withTopEquiv_zero : withTopEquiv 0 = 0 := by
simp
#align part_enat.with_top_equiv_zero PartENat.withTopEquiv_zero
theorem withTopEquiv_one : withTopEquiv 1 = 1 := by
simp
theorem withTopEquiv_ofNat (n : Nat) [n.AtLeastTwo] :
withTopEquiv (no_index (OfNat.ofNat n)) = OfNat.ofNat n := by
simp
theorem withTopEquiv_le {x y : PartENat} : withTopEquiv x ≤ withTopEquiv y ↔ x ≤ y := by
simp
#align part_enat.with_top_equiv_le PartENat.withTopEquiv_le
theorem withTopEquiv_lt {x y : PartENat} : withTopEquiv x < withTopEquiv y ↔ x < y := by
simp
#align part_enat.with_top_equiv_lt PartENat.withTopEquiv_lt
theorem withTopEquiv_symm_top : withTopEquiv.symm ⊤ = ⊤ := by
simp
#align part_enat.with_top_equiv_symm_top PartENat.withTopEquiv_symm_top
theorem withTopEquiv_symm_coe (n : Nat) : withTopEquiv.symm n = n := by
simp
#align part_enat.with_top_equiv_symm_coe PartENat.withTopEquiv_symm_coe
theorem withTopEquiv_symm_zero : withTopEquiv.symm 0 = 0 := by
simp
#align part_enat.with_top_equiv_symm_zero PartENat.withTopEquiv_symm_zero
theorem withTopEquiv_symm_one : withTopEquiv.symm 1 = 1 := by
simp
theorem withTopEquiv_symm_ofNat (n : Nat) [n.AtLeastTwo] :
withTopEquiv.symm (no_index (OfNat.ofNat n)) = OfNat.ofNat n := by
simp
theorem withTopEquiv_symm_le {x y : ℕ∞} : withTopEquiv.symm x ≤ withTopEquiv.symm y ↔ x ≤ y := by
simp
#align part_enat.with_top_equiv_symm_le PartENat.withTopEquiv_symm_le
theorem withTopEquiv_symm_lt {x y : ℕ∞} : withTopEquiv.symm x < withTopEquiv.symm y ↔ x < y := by
simp
#align part_enat.with_top_equiv_symm_lt PartENat.withTopEquiv_symm_lt
/-- `toWithTop` induces an order isomorphism between `PartENat` and `ℕ∞`. -/
noncomputable def withTopOrderIso : PartENat ≃o ℕ∞ :=
{ withTopEquiv with map_rel_iff' := @fun _ _ => withTopEquiv_le }
#align part_enat.with_top_order_iso PartENat.withTopOrderIso
/-- `toWithTop` induces an additive monoid isomorphism between `PartENat` and `ℕ∞`. -/
noncomputable def withTopAddEquiv : PartENat ≃+ ℕ∞ :=
{ withTopEquiv with
map_add' := fun x y => by
simp only [withTopEquiv]
exact toWithTop_add }
#align part_enat.with_top_add_equiv PartENat.withTopAddEquiv
end WithTopEquiv
theorem lt_wf : @WellFounded PartENat (· < ·) := by
classical
change WellFounded fun a b : PartENat => a < b
simp_rw [← withTopEquiv_lt]
exact InvImage.wf _ wellFounded_lt
#align part_enat.lt_wf PartENat.lt_wf
instance : WellFoundedLT PartENat :=
⟨lt_wf⟩
instance isWellOrder : IsWellOrder PartENat (· < ·) := {}
instance wellFoundedRelation : WellFoundedRelation PartENat :=
⟨(· < ·), lt_wf⟩
section Find
variable (P : ℕ → Prop) [DecidablePred P]
/-- The smallest `PartENat` satisfying a (decidable) predicate `P : ℕ → Prop` -/
def find : PartENat :=
⟨∃ n, P n, Nat.find⟩
#align part_enat.find PartENat.find
@[simp]
theorem find_get (h : (find P).Dom) : (find P).get h = Nat.find h :=
rfl
#align part_enat.find_get PartENat.find_get
theorem find_dom (h : ∃ n, P n) : (find P).Dom :=
h
#align part_enat.find_dom PartENat.find_dom
| Mathlib/Data/Nat/PartENat.lean | 854 | 861 | theorem lt_find (n : ℕ) (h : ∀ m ≤ n, ¬P m) : (n : PartENat) < find P := by |
rw [coe_lt_iff]
intro h₁
rw [find_get]
have h₂ := @Nat.find_spec P _ h₁
revert h₂
contrapose!
exact h _
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Andrew Yang
-/
import Mathlib.AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf
import Mathlib.AlgebraicGeometry.GammaSpecAdjunction
import Mathlib.RingTheory.GradedAlgebra.Radical
#align_import algebraic_geometry.projective_spectrum.scheme from "leanprover-community/mathlib"@"d39590fc8728fbf6743249802486f8c91ffe07bc"
/-!
# Proj as a scheme
This file is to prove that `Proj` is a scheme.
## Notation
* `Proj` : `Proj` as a locally ringed space
* `Proj.T` : the underlying topological space of `Proj`
* `Proj| U` : `Proj` restricted to some open set `U`
* `Proj.T| U` : the underlying topological space of `Proj` restricted to open set `U`
* `pbo f` : basic open set at `f` in `Proj`
* `Spec` : `Spec` as a locally ringed space
* `Spec.T` : the underlying topological space of `Spec`
* `sbo g` : basic open set at `g` in `Spec`
* `A⁰_x` : the degree zero part of localized ring `Aₓ`
## Implementation
In `AlgebraicGeometry/ProjectiveSpectrum/StructureSheaf.lean`, we have given `Proj` a
structure sheaf so that `Proj` is a locally ringed space. In this file we will prove that `Proj`
equipped with this structure sheaf is a scheme. We achieve this by using an affine cover by basic
open sets in `Proj`, more specifically:
1. We prove that `Proj` can be covered by basic open sets at homogeneous element of positive degree.
2. We prove that for any homogeneous element `f : A` of positive degree `m`, `Proj.T | (pbo f)` is
homeomorphic to `Spec.T A⁰_f`:
- forward direction `toSpec`:
for any `x : pbo f`, i.e. a relevant homogeneous prime ideal `x`, send it to
`A⁰_f ∩ span {g / 1 | g ∈ x}` (see `ProjIsoSpecTopComponent.IoSpec.carrier`). This ideal is
prime, the proof is in `ProjIsoSpecTopComponent.ToSpec.toFun`. The fact that this function
is continuous is found in `ProjIsoSpecTopComponent.toSpec`
- backward direction `fromSpec`:
for any `q : Spec A⁰_f`, we send it to `{a | ∀ i, aᵢᵐ/fⁱ ∈ q}`; we need this to be a
homogeneous prime ideal that is relevant.
* This is in fact an ideal, the proof can be found in
`ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal`;
* This ideal is also homogeneous, the proof can be found in
`ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal.homogeneous`;
* This ideal is relevant, the proof can be found in
`ProjIsoSpecTopComponent.FromSpec.carrier.relevant`;
* This ideal is prime, the proof can be found in
`ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal.prime`.
Hence we have a well defined function `Spec.T A⁰_f → Proj.T | (pbo f)`, this function is called
`ProjIsoSpecTopComponent.FromSpec.toFun`. But to prove the continuity of this function, we need
to prove `fromSpec ∘ toSpec` and `toSpec ∘ fromSpec` are both identities; these are achieved in
`ProjIsoSpecTopComponent.fromSpec_toSpec` and `ProjIsoSpecTopComponent.toSpec_fromSpec`.
3. Then we construct a morphism of locally ringed spaces `α : Proj| (pbo f) ⟶ Spec.T A⁰_f` as the
following: by the Gamma-Spec adjunction, it is sufficient to construct a ring map
`A⁰_f → Γ(Proj, pbo f)` from the ring of homogeneous localization of `A` away from `f` to the
local sections of structure sheaf of projective spectrum on the basic open set around `f`.
The map `A⁰_f → Γ(Proj, pbo f)` is constructed in `awayToΓ` and is defined by sending
`s ∈ A⁰_f` to the section `x ↦ s` on `pbo f`.
## Main Definitions and Statements
For a homogeneous element `f` of degree `m`
* `ProjIsoSpecTopComponent.toSpec`: the continuous map between `Proj.T| pbo f` and `Spec.T A⁰_f`
defined by sending `x : Proj| (pbo f)` to `A⁰_f ∩ span {g / 1 | g ∈ x}`. We also denote this map
as `ψ`.
* `ProjIsoSpecTopComponent.ToSpec.preimage_eq`: for any `a: A`, if `a/f^m` has degree zero,
then the preimage of `sbo a/f^m` under `to_Spec f` is `pbo f ∩ pbo a`.
If we further assume `m` is positive
* `ProjIsoSpecTopComponent.fromSpec`: the continuous map between `Spec.T A⁰_f` and `Proj.T| pbo f`
defined by sending `q` to `{a | aᵢᵐ/fⁱ ∈ q}` where `aᵢ` is the `i`-th coordinate of `a`.
We also denote this map as `φ`
* `projIsoSpecTopComponent`: the homeomorphism `Proj.T| pbo f ≅ Spec.T A⁰_f` obtained by `φ` and
`ψ`.
* `ProjectiveSpectrum.Proj.toSpec`: the morphism of locally ringed spaces between `Proj| pbo f`
and `Spec A⁰_f` corresponding to the ring map `A⁰_f → Γ(Proj, pbo f)` under the Gamma-Spec
adjunction defined by sending `s` to the section `x ↦ s` on `pbo f`.
## Reference
* [Robin Hartshorne, *Algebraic Geometry*][Har77]: Chapter II.2 Proposition 2.5
-/
noncomputable section
set_option linter.uppercaseLean3 false
namespace AlgebraicGeometry
open scoped DirectSum Pointwise
open DirectSum SetLike.GradedMonoid Localization
open Finset hiding mk_zero
variable {R A : Type*}
variable [CommRing R] [CommRing A] [Algebra R A]
variable (𝒜 : ℕ → Submodule R A)
variable [GradedAlgebra 𝒜]
open TopCat TopologicalSpace
open CategoryTheory Opposite
open ProjectiveSpectrum.StructureSheaf
-- Porting note: currently require lack of hygiene to use in variable declarations
-- maybe all make into notation3?
set_option hygiene false
/-- `Proj` as a locally ringed space -/
local notation3 "Proj" => Proj.toLocallyRingedSpace 𝒜
/-- The underlying topological space of `Proj` -/
local notation3 "Proj.T" => PresheafedSpace.carrier <| SheafedSpace.toPresheafedSpace
<| LocallyRingedSpace.toSheafedSpace <| Proj.toLocallyRingedSpace 𝒜
/-- `Proj` restrict to some open set -/
macro "Proj| " U:term : term =>
`((Proj.toLocallyRingedSpace 𝒜).restrict (Opens.openEmbedding (X := Proj.T) ($U : Opens Proj.T)))
/-- the underlying topological space of `Proj` restricted to some open set -/
local notation "Proj.T| " U => PresheafedSpace.carrier <| SheafedSpace.toPresheafedSpace
<| LocallyRingedSpace.toSheafedSpace
<| (LocallyRingedSpace.restrict Proj (Opens.openEmbedding (X := Proj.T) (U : Opens Proj.T)))
/-- basic open sets in `Proj` -/
local notation "pbo " x => ProjectiveSpectrum.basicOpen 𝒜 x
/-- basic open sets in `Spec` -/
local notation "sbo " f => PrimeSpectrum.basicOpen f
/-- `Spec` as a locally ringed space -/
local notation3 "Spec " ring => Spec.locallyRingedSpaceObj (CommRingCat.of ring)
/-- the underlying topological space of `Spec` -/
local notation "Spec.T " ring =>
(Spec.locallyRingedSpaceObj (CommRingCat.of ring)).toSheafedSpace.toPresheafedSpace.1
local notation3 "A⁰_ " f => HomogeneousLocalization.Away 𝒜 f
namespace ProjIsoSpecTopComponent
/-
This section is to construct the homeomorphism between `Proj` restricted at basic open set at
a homogeneous element `x` and `Spec A⁰ₓ` where `A⁰ₓ` is the degree zero part of the localized
ring `Aₓ`.
-/
namespace ToSpec
open Ideal
-- This section is to construct the forward direction :
-- So for any `x` in `Proj| (pbo f)`, we need some point in `Spec A⁰_f`, i.e. a prime ideal,
-- and we need this correspondence to be continuous in their Zariski topology.
variable {𝒜} {f : A} {m : ℕ} (f_deg : f ∈ 𝒜 m) (x : Proj| (pbo f))
/--
For any `x` in `Proj| (pbo f)`, the corresponding ideal in `Spec A⁰_f`. This fact that this ideal
is prime is proven in `TopComponent.Forward.toFun`-/
def carrier : Ideal (A⁰_ f) :=
Ideal.comap (algebraMap (A⁰_ f) (Away f))
(x.val.asHomogeneousIdeal.toIdeal.map (algebraMap A (Away f)))
#align algebraic_geometry.Proj_iso_Spec_Top_component.to_Spec.carrier AlgebraicGeometry.ProjIsoSpecTopComponent.ToSpec.carrier
@[simp]
theorem mk_mem_carrier (z : HomogeneousLocalization.NumDenSameDeg 𝒜 (.powers f)) :
HomogeneousLocalization.mk z ∈ carrier x ↔ z.num.1 ∈ x.1.asHomogeneousIdeal := by
rw [carrier, Ideal.mem_comap, HomogeneousLocalization.algebraMap_apply,
HomogeneousLocalization.val_mk, Localization.mk_eq_mk', IsLocalization.mk'_eq_mul_mk'_one,
mul_comm, Ideal.unit_mul_mem_iff_mem, ← Ideal.mem_comap,
IsLocalization.comap_map_of_isPrime_disjoint (.powers f)]
· rfl
· infer_instance
· exact (disjoint_powers_iff_not_mem _ (Ideal.IsPrime.isRadical inferInstance)).mpr x.2
· exact isUnit_of_invertible _
theorem isPrime_carrier : Ideal.IsPrime (carrier x) := by
refine Ideal.IsPrime.comap _ (hK := ?_)
exact IsLocalization.isPrime_of_isPrime_disjoint
(Submonoid.powers f) _ _ inferInstance
((disjoint_powers_iff_not_mem _ (Ideal.IsPrime.isRadical inferInstance)).mpr x.2)
variable (f)
/-- The function between the basic open set `D(f)` in `Proj` to the corresponding basic open set in
`Spec A⁰_f`. This is bundled into a continuous map in `TopComponent.forward`.
-/
@[simps (config := .lemmasOnly)]
def toFun (x : Proj.T| pbo f) : Spec.T A⁰_ f :=
⟨carrier x, isPrime_carrier x⟩
#align algebraic_geometry.Proj_iso_Spec_Top_component.to_Spec.to_fun AlgebraicGeometry.ProjIsoSpecTopComponent.ToSpec.toFun
/-
The preimage of basic open set `D(a/f^n)` in `Spec A⁰_f` under the forward map from `Proj A` to
`Spec A⁰_f` is the basic open set `D(a) ∩ D(f)` in `Proj A`. This lemma is used to prove that the
forward map is continuous.
-/
theorem preimage_basicOpen (z : HomogeneousLocalization.NumDenSameDeg 𝒜 (.powers f)) :
toFun f ⁻¹' (sbo (HomogeneousLocalization.mk z) : Set (PrimeSpectrum (A⁰_ f))) =
Subtype.val ⁻¹' (pbo z.num.1 : Set (ProjectiveSpectrum 𝒜)) :=
Set.ext fun y ↦ (mk_mem_carrier y z).not
#align algebraic_geometry.Proj_iso_Spec_Top_component.to_Spec.preimage_eq AlgebraicGeometry.ProjIsoSpecTopComponent.ToSpec.preimage_basicOpen
end ToSpec
section
/-- The continuous function from the basic open set `D(f)` in `Proj`
to the corresponding basic open set in `Spec A⁰_f`. -/
@[simps! (config := .lemmasOnly) apply_asIdeal]
def toSpec (f : A) : (Proj.T| pbo f) ⟶ Spec.T A⁰_ f where
toFun := ToSpec.toFun f
continuous_toFun := by
rw [PrimeSpectrum.isTopologicalBasis_basic_opens.continuous_iff]
rintro _ ⟨x, rfl⟩
obtain ⟨x, rfl⟩ := Quotient.surjective_Quotient_mk'' x
rw [ToSpec.preimage_basicOpen]
exact (pbo x.num).2.preimage continuous_subtype_val
#align algebraic_geometry.Proj_iso_Spec_Top_component.to_Spec AlgebraicGeometry.ProjIsoSpecTopComponent.toSpec
variable {𝒜} in
lemma toSpec_preimage_basicOpen {f} (z : HomogeneousLocalization.NumDenSameDeg 𝒜 (.powers f)) :
toSpec 𝒜 f ⁻¹' (sbo (HomogeneousLocalization.mk z) : Set (PrimeSpectrum (A⁰_ f))) =
Subtype.val ⁻¹' (pbo z.num.1 : Set (ProjectiveSpectrum 𝒜)) :=
ToSpec.preimage_basicOpen f z
end
namespace FromSpec
open GradedAlgebra SetLike
open Finset hiding mk_zero
-- Porting note: _root_ doesn't work here
open HomogeneousLocalization
variable {𝒜} {f : A} {m : ℕ} (f_deg : f ∈ 𝒜 m)
open Lean Meta Elab Tactic
macro "mem_tac_aux" : tactic =>
`(tactic| first | exact pow_mem_graded _ (Submodule.coe_mem _) | exact natCast_mem_graded _ _ |
exact pow_mem_graded _ f_deg)
macro "mem_tac" : tactic =>
`(tactic| first | mem_tac_aux |
repeat (all_goals (apply SetLike.GradedMonoid.toGradedMul.mul_mem)); mem_tac_aux)
/-- The function from `Spec A⁰_f` to `Proj|D(f)` is defined by `q ↦ {a | aᵢᵐ/fⁱ ∈ q}`, i.e. sending
`q` a prime ideal in `A⁰_f` to the homogeneous prime relevant ideal containing only and all the
elements `a : A` such that for every `i`, the degree 0 element formed by dividing the `m`-th power
of the `i`-th projection of `a` by the `i`-th power of the degree-`m` homogeneous element `f`,
lies in `q`.
The set `{a | aᵢᵐ/fⁱ ∈ q}`
* is an ideal, as proved in `carrier.asIdeal`;
* is homogeneous, as proved in `carrier.asHomogeneousIdeal`;
* is prime, as proved in `carrier.asIdeal.prime`;
* is relevant, as proved in `carrier.relevant`.
-/
def carrier (q : Spec.T A⁰_ f) : Set A :=
{a | ∀ i, (HomogeneousLocalization.mk ⟨m * i, ⟨proj 𝒜 i a ^ m, by mem_tac⟩,
⟨f ^ i, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.1}
#align algebraic_geometry.Proj_iso_Spec_Top_component.from_Spec.carrier AlgebraicGeometry.ProjIsoSpecTopComponent.FromSpec.carrier
theorem mem_carrier_iff (q : Spec.T A⁰_ f) (a : A) :
a ∈ carrier f_deg q ↔ ∀ i, (HomogeneousLocalization.mk ⟨m * i, ⟨proj 𝒜 i a ^ m, by mem_tac⟩,
⟨f ^ i, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.1 :=
Iff.rfl
#align algebraic_geometry.Proj_iso_Spec_Top_component.from_Spec.mem_carrier_iff AlgebraicGeometry.ProjIsoSpecTopComponent.FromSpec.mem_carrier_iff
theorem mem_carrier_iff' (q : Spec.T A⁰_ f) (a : A) :
a ∈ carrier f_deg q ↔
∀ i, (Localization.mk (proj 𝒜 i a ^ m) ⟨f ^ i, ⟨i, rfl⟩⟩ : Localization.Away f) ∈
algebraMap (HomogeneousLocalization.Away 𝒜 f) (Localization.Away f) '' { s | s ∈ q.1 } :=
(mem_carrier_iff f_deg q a).trans
(by
constructor <;> intro h i <;> specialize h i
· rw [Set.mem_image]; refine ⟨_, h, rfl⟩
· rw [Set.mem_image] at h; rcases h with ⟨x, h, hx⟩
change x ∈ q.asIdeal at h
convert h
rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk]
dsimp only [Subtype.coe_mk]; rw [← hx]; rfl)
#align algebraic_geometry.Proj_iso_Spec_Top_component.from_Spec.mem_carrier_iff' AlgebraicGeometry.ProjIsoSpecTopComponent.FromSpec.mem_carrier_iff'
| Mathlib/AlgebraicGeometry/ProjectiveSpectrum/Scheme.lean | 294 | 305 | theorem mem_carrier_iff_of_mem (hm : 0 < m) (q : Spec.T A⁰_ f) (a : A) {n} (hn : a ∈ 𝒜 n) :
a ∈ carrier f_deg q ↔
(HomogeneousLocalization.mk ⟨m * n, ⟨a ^ m, pow_mem_graded m hn⟩,
⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal := by |
trans (HomogeneousLocalization.mk ⟨m * n, ⟨proj 𝒜 n a ^ m, by mem_tac⟩,
⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal
· refine ⟨fun h ↦ h n, fun h i ↦ if hi : i = n then hi ▸ h else ?_⟩
convert zero_mem q.asIdeal
apply HomogeneousLocalization.val_injective
simp only [proj_apply, decompose_of_mem_ne _ hn (Ne.symm hi), zero_pow hm.ne',
HomogeneousLocalization.val_mk, Localization.mk_zero, HomogeneousLocalization.val_zero]
· simp only [proj_apply, decompose_of_mem_same _ hn]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.