Context stringlengths 295 65.3k | file_name stringlengths 21 74 | start int64 14 1.41k | end int64 20 1.41k | theorem stringlengths 27 1.42k | proof stringlengths 0 4.57k |
|---|---|---|---|---|---|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Basic
/-!
# Maps between real and extended non-negative real numbers
This file focuses on the functions `ENNReal.toReal : ℝ≥0∞ → ℝ` and `ENNReal.ofReal : ℝ → ℝ≥0∞` which
were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between
these functions and the algebraic and lattice operations, although a few may appear in earlier
files.
This file provides a `positivity` extension for `ENNReal.ofReal`.
# Main theorems
- `trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp`
- `dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal`: often used for `WithLp` and `lp`
- `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between
indexed or set infima and suprema in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. This is especially useful because
`ℝ≥0∞` is a complete lattice.
-/
assert_not_exists Finset
open Set NNReal ENNReal
namespace ENNReal
section Real
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
theorem toReal_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a + b).toReal = a.toReal + b.toReal := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
rfl
theorem toReal_add_le : (a + b).toReal ≤ a.toReal + b.toReal :=
if ha : a = ∞ then by simp only [ha, top_add, toReal_top, zero_add, toReal_nonneg]
else
if hb : b = ∞ then by simp only [hb, add_top, toReal_top, add_zero, toReal_nonneg]
else le_of_eq (toReal_add ha hb)
theorem ofReal_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by
rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj,
Real.toNNReal_add hp hq]
theorem ofReal_add_le {p q : ℝ} : ENNReal.ofReal (p + q) ≤ ENNReal.ofReal p + ENNReal.ofReal q :=
coe_le_coe.2 Real.toNNReal_add_le
@[simp]
theorem toReal_le_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal ≤ b.toReal ↔ a ≤ b := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
norm_cast
@[gcongr]
theorem toReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toReal ≤ b.toReal :=
(toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h
theorem toReal_mono' (h : a ≤ b) (ht : b = ∞ → a = ∞) : a.toReal ≤ b.toReal := by
rcases eq_or_ne a ∞ with rfl | ha
· exact toReal_nonneg
· exact toReal_mono (mt ht ha) h
@[simp]
theorem toReal_lt_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal < b.toReal ↔ a < b := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
norm_cast
@[gcongr]
theorem toReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toReal < b.toReal :=
(toReal_lt_toReal h.ne_top hb).2 h
@[gcongr]
theorem toNNReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toNNReal ≤ b.toNNReal :=
toReal_mono hb h
theorem le_toNNReal_of_coe_le (h : p ≤ a) (ha : a ≠ ∞) : p ≤ a.toNNReal :=
@toNNReal_coe p ▸ toNNReal_mono ha h
@[simp]
theorem toNNReal_le_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal ≤ b.toNNReal ↔ a ≤ b :=
⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_le_coe], toNNReal_mono hb⟩
@[gcongr]
theorem toNNReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toNNReal < b.toNNReal := by
simpa [← ENNReal.coe_lt_coe, hb, h.ne_top]
@[simp]
theorem toNNReal_lt_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal < b.toNNReal ↔ a < b :=
⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hb⟩
theorem toNNReal_lt_of_lt_coe (h : a < p) : a.toNNReal < p :=
@toNNReal_coe p ▸ toNNReal_strict_mono coe_ne_top h
theorem toReal_max (hr : a ≠ ∞) (hp : b ≠ ∞) :
ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) :=
(le_total a b).elim
(fun h => by simp only [h, ENNReal.toReal_mono hp h, max_eq_right]) fun h => by
simp only [h, ENNReal.toReal_mono hr h, max_eq_left]
theorem toReal_min {a b : ℝ≥0∞} (hr : a ≠ ∞) (hp : b ≠ ∞) :
ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) :=
(le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, min_eq_left])
fun h => by simp only [h, ENNReal.toReal_mono hr h, min_eq_right]
theorem toReal_sup {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊔ b).toReal = a.toReal ⊔ b.toReal :=
toReal_max
theorem toReal_inf {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊓ b).toReal = a.toReal ⊓ b.toReal :=
toReal_min
theorem toNNReal_pos_iff : 0 < a.toNNReal ↔ 0 < a ∧ a < ∞ := by
induction a <;> simp
theorem toNNReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toNNReal :=
toNNReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩
theorem toReal_pos_iff : 0 < a.toReal ↔ 0 < a ∧ a < ∞ :=
NNReal.coe_pos.trans toNNReal_pos_iff
theorem toReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toReal :=
toReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩
@[gcongr, bound]
theorem ofReal_le_ofReal {p q : ℝ} (h : p ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q := by
simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h]
theorem ofReal_le_of_le_toReal {a : ℝ} {b : ℝ≥0∞} (h : a ≤ ENNReal.toReal b) :
ENNReal.ofReal a ≤ b :=
(ofReal_le_ofReal h).trans ofReal_toReal_le
@[simp]
theorem ofReal_le_ofReal_iff {p q : ℝ} (h : 0 ≤ q) :
ENNReal.ofReal p ≤ ENNReal.ofReal q ↔ p ≤ q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_le_coe, Real.toNNReal_le_toNNReal_iff h]
lemma ofReal_le_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p ≤ .ofReal q ↔ p ≤ q ∨ p ≤ 0 :=
coe_le_coe.trans Real.toNNReal_le_toNNReal_iff'
lemma ofReal_lt_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p < .ofReal q ↔ p < q ∧ 0 < q :=
coe_lt_coe.trans Real.toNNReal_lt_toNNReal_iff'
@[simp]
theorem ofReal_eq_ofReal_iff {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ENNReal.ofReal p = ENNReal.ofReal q ↔ p = q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_inj, Real.toNNReal_eq_toNNReal_iff hp hq]
@[simp]
theorem ofReal_lt_ofReal_iff {p q : ℝ} (h : 0 < q) :
ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff h]
theorem ofReal_lt_ofReal_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) :
ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff_of_nonneg hp]
@[simp]
theorem ofReal_pos {p : ℝ} : 0 < ENNReal.ofReal p ↔ 0 < p := by simp [ENNReal.ofReal]
@[bound] private alias ⟨_, Bound.ofReal_pos_of_pos⟩ := ofReal_pos
@[simp]
theorem ofReal_eq_zero {p : ℝ} : ENNReal.ofReal p = 0 ↔ p ≤ 0 := by simp [ENNReal.ofReal]
theorem ofReal_ne_zero_iff {r : ℝ} : ENNReal.ofReal r ≠ 0 ↔ 0 < r := by
rw [← zero_lt_iff, ENNReal.ofReal_pos]
@[simp]
theorem zero_eq_ofReal {p : ℝ} : 0 = ENNReal.ofReal p ↔ p ≤ 0 :=
eq_comm.trans ofReal_eq_zero
alias ⟨_, ofReal_of_nonpos⟩ := ofReal_eq_zero
@[simp]
lemma ofReal_lt_natCast {p : ℝ} {n : ℕ} (hn : n ≠ 0) : ENNReal.ofReal p < n ↔ p < n := by
exact mod_cast ofReal_lt_ofReal_iff (Nat.cast_pos.2 hn.bot_lt)
@[simp]
lemma ofReal_lt_one {p : ℝ} : ENNReal.ofReal p < 1 ↔ p < 1 := by
exact mod_cast ofReal_lt_natCast one_ne_zero
@[simp]
lemma ofReal_lt_ofNat {p : ℝ} {n : ℕ} [n.AtLeastTwo] :
ENNReal.ofReal p < ofNat(n) ↔ p < OfNat.ofNat n :=
ofReal_lt_natCast (NeZero.ne n)
@[simp]
lemma natCast_le_ofReal {n : ℕ} {p : ℝ} (hn : n ≠ 0) : n ≤ ENNReal.ofReal p ↔ n ≤ p := by
simp only [← not_lt, ofReal_lt_natCast hn]
@[simp]
lemma one_le_ofReal {p : ℝ} : 1 ≤ ENNReal.ofReal p ↔ 1 ≤ p := by
exact mod_cast natCast_le_ofReal one_ne_zero
@[simp]
lemma ofNat_le_ofReal {n : ℕ} [n.AtLeastTwo] {p : ℝ} :
ofNat(n) ≤ ENNReal.ofReal p ↔ OfNat.ofNat n ≤ p :=
natCast_le_ofReal (NeZero.ne n)
@[simp, norm_cast]
lemma ofReal_le_natCast {r : ℝ} {n : ℕ} : ENNReal.ofReal r ≤ n ↔ r ≤ n :=
coe_le_coe.trans Real.toNNReal_le_natCast
@[simp]
lemma ofReal_le_one {r : ℝ} : ENNReal.ofReal r ≤ 1 ↔ r ≤ 1 :=
coe_le_coe.trans Real.toNNReal_le_one
@[simp]
lemma ofReal_le_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] :
ENNReal.ofReal r ≤ ofNat(n) ↔ r ≤ OfNat.ofNat n :=
ofReal_le_natCast
@[simp]
lemma natCast_lt_ofReal {n : ℕ} {r : ℝ} : n < ENNReal.ofReal r ↔ n < r :=
coe_lt_coe.trans Real.natCast_lt_toNNReal
@[simp]
lemma one_lt_ofReal {r : ℝ} : 1 < ENNReal.ofReal r ↔ 1 < r := coe_lt_coe.trans Real.one_lt_toNNReal
@[simp]
lemma ofNat_lt_ofReal {n : ℕ} [n.AtLeastTwo] {r : ℝ} :
ofNat(n) < ENNReal.ofReal r ↔ OfNat.ofNat n < r :=
natCast_lt_ofReal
@[simp]
lemma ofReal_eq_natCast {r : ℝ} {n : ℕ} (h : n ≠ 0) : ENNReal.ofReal r = n ↔ r = n :=
ENNReal.coe_inj.trans <| Real.toNNReal_eq_natCast h
@[simp]
lemma ofReal_eq_one {r : ℝ} : ENNReal.ofReal r = 1 ↔ r = 1 :=
ENNReal.coe_inj.trans Real.toNNReal_eq_one
@[simp]
lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] :
ENNReal.ofReal r = ofNat(n) ↔ r = OfNat.ofNat n :=
ofReal_eq_natCast (NeZero.ne n)
theorem ofReal_le_iff_le_toReal {a : ℝ} {b : ℝ≥0∞} (hb : b ≠ ∞) :
ENNReal.ofReal a ≤ b ↔ a ≤ ENNReal.toReal b := by
lift b to ℝ≥0 using hb
simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_le_iff_le_coe
theorem ofReal_lt_iff_lt_toReal {a : ℝ} {b : ℝ≥0∞} (ha : 0 ≤ a) (hb : b ≠ ∞) :
ENNReal.ofReal a < b ↔ a < ENNReal.toReal b := by
lift b to ℝ≥0 using hb
simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_lt_iff_lt_coe ha
theorem ofReal_lt_coe_iff {a : ℝ} {b : ℝ≥0} (ha : 0 ≤ a) : ENNReal.ofReal a < b ↔ a < b :=
(ofReal_lt_iff_lt_toReal ha coe_ne_top).trans <| by rw [coe_toReal]
theorem le_ofReal_iff_toReal_le {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) (hb : 0 ≤ b) :
a ≤ ENNReal.ofReal b ↔ ENNReal.toReal a ≤ b := by
lift a to ℝ≥0 using ha
simpa [ENNReal.ofReal, ENNReal.toReal] using Real.le_toNNReal_iff_coe_le hb
theorem toReal_le_of_le_ofReal {a : ℝ≥0∞} {b : ℝ} (hb : 0 ≤ b) (h : a ≤ ENNReal.ofReal b) :
ENNReal.toReal a ≤ b :=
have ha : a ≠ ∞ := ne_top_of_le_ne_top ofReal_ne_top h
(le_ofReal_iff_toReal_le ha hb).1 h
theorem lt_ofReal_iff_toReal_lt {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) :
a < ENNReal.ofReal b ↔ ENNReal.toReal a < b := by
lift a to ℝ≥0 using ha
simpa [ENNReal.ofReal, ENNReal.toReal] using Real.lt_toNNReal_iff_coe_lt
theorem toReal_lt_of_lt_ofReal {b : ℝ} (h : a < ENNReal.ofReal b) : ENNReal.toReal a < b :=
(lt_ofReal_iff_toReal_lt h.ne_top).1 h
theorem ofReal_mul {p q : ℝ} (hp : 0 ≤ p) :
ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by
simp only [ENNReal.ofReal, ← coe_mul, Real.toNNReal_mul hp]
theorem ofReal_mul' {p q : ℝ} (hq : 0 ≤ q) :
ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by
rw [mul_comm, ofReal_mul hq, mul_comm]
theorem ofReal_pow {p : ℝ} (hp : 0 ≤ p) (n : ℕ) :
ENNReal.ofReal (p ^ n) = ENNReal.ofReal p ^ n := by
rw [ofReal_eq_coe_nnreal hp, ← coe_pow, ← ofReal_coe_nnreal, NNReal.coe_pow, NNReal.coe_mk]
theorem ofReal_nsmul {x : ℝ} {n : ℕ} : ENNReal.ofReal (n • x) = n • ENNReal.ofReal x := by
simp only [nsmul_eq_mul, ← ofReal_natCast n, ← ofReal_mul n.cast_nonneg]
@[simp]
theorem toNNReal_mul {a b : ℝ≥0∞} : (a * b).toNNReal = a.toNNReal * b.toNNReal :=
WithTop.untopD_zero_mul a b
theorem toNNReal_mul_top (a : ℝ≥0∞) : ENNReal.toNNReal (a * ∞) = 0 := by simp
theorem toNNReal_top_mul (a : ℝ≥0∞) : ENNReal.toNNReal (∞ * a) = 0 := by simp
/-- `ENNReal.toNNReal` as a `MonoidHom`. -/
def toNNRealHom : ℝ≥0∞ →*₀ ℝ≥0 where
toFun := ENNReal.toNNReal
map_one' := toNNReal_coe _
map_mul' _ _ := toNNReal_mul
map_zero' := toNNReal_zero
@[simp]
theorem toNNReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toNNReal = a.toNNReal ^ n :=
toNNRealHom.map_pow a n
/-- `ENNReal.toReal` as a `MonoidHom`. -/
def toRealHom : ℝ≥0∞ →*₀ ℝ :=
(NNReal.toRealHom : ℝ≥0 →*₀ ℝ).comp toNNRealHom
@[simp]
theorem toReal_mul : (a * b).toReal = a.toReal * b.toReal :=
toRealHom.map_mul a b
theorem toReal_nsmul (a : ℝ≥0∞) (n : ℕ) : (n • a).toReal = n • a.toReal := by simp
@[simp]
theorem toReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toReal = a.toReal ^ n :=
toRealHom.map_pow a n
theorem toReal_ofReal_mul (c : ℝ) (a : ℝ≥0∞) (h : 0 ≤ c) :
ENNReal.toReal (ENNReal.ofReal c * a) = c * ENNReal.toReal a := by
rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal h]
theorem toReal_mul_top (a : ℝ≥0∞) : ENNReal.toReal (a * ∞) = 0 := by
rw [toReal_mul, toReal_top, mul_zero]
theorem toReal_top_mul (a : ℝ≥0∞) : ENNReal.toReal (∞ * a) = 0 := by
rw [mul_comm]
exact toReal_mul_top _
theorem toReal_eq_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal = b.toReal ↔ a = b := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
simp only [coe_inj, NNReal.coe_inj, coe_toReal]
protected theorem trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal := by
simpa only [or_iff_not_imp_left] using toReal_pos
protected theorem trichotomy₂ {p q : ℝ≥0∞} (hpq : p ≤ q) :
p = 0 ∧ q = 0 ∨
p = 0 ∧ q = ∞ ∨
p = 0 ∧ 0 < q.toReal ∨
p = ∞ ∧ q = ∞ ∨
0 < p.toReal ∧ q = ∞ ∨ 0 < p.toReal ∧ 0 < q.toReal ∧ p.toReal ≤ q.toReal := by
rcases eq_or_lt_of_le (bot_le : 0 ≤ p) with ((rfl : 0 = p) | (hp : 0 < p))
· simpa using q.trichotomy
rcases eq_or_lt_of_le (le_top : q ≤ ∞) with (rfl | hq)
· simpa using p.trichotomy
repeat' right
have hq' : 0 < q := lt_of_lt_of_le hp hpq
have hp' : p < ∞ := lt_of_le_of_lt hpq hq
simp [ENNReal.toReal_mono hq.ne hpq, ENNReal.toReal_pos_iff, hp, hp', hq', hq]
protected theorem dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal :=
haveI : p = ⊤ ∨ 0 < p.toReal ∧ 1 ≤ p.toReal := by
simpa using ENNReal.trichotomy₂ (Fact.out : 1 ≤ p)
this.imp_right fun h => h.2
theorem toReal_pos_iff_ne_top (p : ℝ≥0∞) [Fact (1 ≤ p)] : 0 < p.toReal ↔ p ≠ ∞ :=
⟨fun h hp =>
have : (0 : ℝ) ≠ 0 := toReal_top ▸ (hp ▸ h.ne : 0 ≠ ∞.toReal)
this rfl,
fun h => zero_lt_one.trans_le (p.dichotomy.resolve_left h)⟩
end Real
section iInf
variable {ι : Sort*} {f g : ι → ℝ≥0∞}
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
theorem toNNReal_iInf (hf : ∀ i, f i ≠ ∞) : (iInf f).toNNReal = ⨅ i, (f i).toNNReal := by
cases isEmpty_or_nonempty ι
· rw [iInf_of_empty, toNNReal_top, NNReal.iInf_empty]
· lift f to ι → ℝ≥0 using hf
simp_rw [← coe_iInf, toNNReal_coe]
theorem toNNReal_sInf (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) :
(sInf s).toNNReal = sInf (ENNReal.toNNReal '' s) := by
have hf : ∀ i, ((↑) : s → ℝ≥0∞) i ≠ ∞ := fun ⟨r, rs⟩ => hs r rs
simpa only [← sInf_range, ← image_eq_range, Subtype.range_coe_subtype] using (toNNReal_iInf hf)
theorem toNNReal_iSup (hf : ∀ i, f i ≠ ∞) : (iSup f).toNNReal = ⨆ i, (f i).toNNReal := by
lift f to ι → ℝ≥0 using hf
simp_rw [toNNReal_coe]
by_cases h : BddAbove (range f)
· rw [← coe_iSup h, toNNReal_coe]
· rw [NNReal.iSup_of_not_bddAbove h, iSup_coe_eq_top.2 h, toNNReal_top]
theorem toNNReal_sSup (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) :
(sSup s).toNNReal = sSup (ENNReal.toNNReal '' s) := by
have hf : ∀ i, ((↑) : s → ℝ≥0∞) i ≠ ∞ := fun ⟨r, rs⟩ => hs r rs
simpa only [← sSup_range, ← image_eq_range, Subtype.range_coe_subtype] using (toNNReal_iSup hf)
theorem toReal_iInf (hf : ∀ i, f i ≠ ∞) : (iInf f).toReal = ⨅ i, (f i).toReal := by
simp only [ENNReal.toReal, toNNReal_iInf hf, NNReal.coe_iInf]
theorem toReal_sInf (s : Set ℝ≥0∞) (hf : ∀ r ∈ s, r ≠ ∞) :
(sInf s).toReal = sInf (ENNReal.toReal '' s) := by
simp only [ENNReal.toReal, toNNReal_sInf s hf, NNReal.coe_sInf, Set.image_image]
theorem toReal_iSup (hf : ∀ i, f i ≠ ∞) : (iSup f).toReal = ⨆ i, (f i).toReal := by
simp only [ENNReal.toReal, toNNReal_iSup hf, NNReal.coe_iSup]
theorem toReal_sSup (s : Set ℝ≥0∞) (hf : ∀ r ∈ s, r ≠ ∞) :
(sSup s).toReal = sSup (ENNReal.toReal '' s) := by
simp only [ENNReal.toReal, toNNReal_sSup s hf, NNReal.coe_sSup, Set.image_image]
@[simp] lemma ofReal_iInf [Nonempty ι] (f : ι → ℝ) :
ENNReal.ofReal (⨅ i, f i) = ⨅ i, ENNReal.ofReal (f i) := by
obtain ⟨i, hi⟩ | h := em (∃ i, f i ≤ 0)
· rw [(iInf_eq_bot _).2 fun _ _ ↦ ⟨i, by simpa [ofReal_of_nonpos hi]⟩]
simp [Real.iInf_nonpos' ⟨i, hi⟩]
replace h i : 0 ≤ f i := le_of_not_le fun hi ↦ h ⟨i, hi⟩
refine eq_of_forall_le_iff fun a ↦ ?_
obtain rfl | ha := eq_or_ne a ∞
· simp
rw [le_iInf_iff, le_ofReal_iff_toReal_le ha, le_ciInf_iff ⟨0, by simpa [mem_lowerBounds]⟩]
· exact forall_congr' fun i ↦ (le_ofReal_iff_toReal_le ha (h _)).symm
· exact Real.iInf_nonneg h
theorem iInf_add : iInf f + a = ⨅ i, f i + a :=
le_antisymm (le_iInf fun _ => add_le_add (iInf_le _ _) <| le_rfl)
(tsub_le_iff_right.1 <| le_iInf fun _ => tsub_le_iff_right.2 <| iInf_le _ _)
theorem iSup_sub : (⨆ i, f i) - a = ⨆ i, f i - a :=
le_antisymm (tsub_le_iff_right.2 <| iSup_le fun i => tsub_le_iff_right.1 <| le_iSup (f · - a) i)
(iSup_le fun _ => tsub_le_tsub (le_iSup _ _) (le_refl a))
theorem sub_iInf : (a - ⨅ i, f i) = ⨆ i, a - f i := by
refine eq_of_forall_ge_iff fun c => ?_
rw [tsub_le_iff_right, add_comm, iInf_add]
simp [tsub_le_iff_right, sub_eq_add_neg, add_comm]
theorem sInf_add {s : Set ℝ≥0∞} : sInf s + a = ⨅ b ∈ s, b + a := by simp [sInf_eq_iInf, iInf_add]
| Mathlib/Data/ENNReal/Real.lean | 442 | 444 | theorem add_iInf {a : ℝ≥0∞} : a + iInf f = ⨅ b, a + f b := by | rw [add_comm, iInf_add]; simp [add_comm] |
/-
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.Data.Nat.Totient
import Mathlib.Data.ZMod.Aut
import Mathlib.Data.ZMod.QuotientGroup
import Mathlib.GroupTheory.Exponent
import Mathlib.GroupTheory.Subgroup.Simple
import Mathlib.Tactic.Group
/-!
# Cyclic groups
A group `G` is called cyclic if there exists an element `g : G` such that every element of `G` is of
the form `g ^ n` for some `n : ℕ`. This file only deals with the predicate on a group to be cyclic.
For the concrete cyclic group of order `n`, see `Data.ZMod.Basic`.
## Main definitions
* `IsCyclic` is a predicate on a group stating that the group is cyclic.
## Main statements
* `isCyclic_of_prime_card` proves that a finite group of prime order is cyclic.
* `isSimpleGroup_of_prime_card`, `IsSimpleGroup.isCyclic`,
and `IsSimpleGroup.prime_card` classify finite simple abelian groups.
* `IsCyclic.exponent_eq_card`: For a finite cyclic group `G`, the exponent is equal to
the group's cardinality.
* `IsCyclic.exponent_eq_zero_of_infinite`: Infinite cyclic groups have exponent zero.
* `IsCyclic.iff_exponent_eq_card`: A finite commutative group is cyclic iff its exponent
is equal to its cardinality.
## Tags
cyclic group
-/
assert_not_exists Ideal TwoSidedIdeal
variable {α G G' : Type*} {a : α}
section Cyclic
open Subgroup
@[to_additive]
theorem IsCyclic.exists_generator [Group α] [IsCyclic α] : ∃ g : α, ∀ x, x ∈ zpowers g :=
exists_zpow_surjective α
@[to_additive]
theorem isCyclic_iff_exists_zpowers_eq_top [Group α] : IsCyclic α ↔ ∃ g : α, zpowers g = ⊤ := by
simp only [eq_top_iff', mem_zpowers_iff]
exact ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩
@[to_additive]
protected theorem Subgroup.isCyclic_iff_exists_zpowers_eq_top [Group α] (H : Subgroup α) :
IsCyclic H ↔ ∃ g : α, Subgroup.zpowers g = H := by
rw [isCyclic_iff_exists_zpowers_eq_top]
simp_rw [← (map_injective H.subtype_injective).eq_iff, ← MonoidHom.range_eq_map,
H.range_subtype, MonoidHom.map_zpowers, Subtype.exists, coe_subtype, exists_prop]
exact exists_congr fun g ↦ and_iff_right_of_imp fun h ↦ h ▸ mem_zpowers g
@[to_additive]
instance (priority := 100) isCyclic_of_subsingleton [Group α] [Subsingleton α] : IsCyclic α :=
⟨⟨1, fun _ => ⟨0, Subsingleton.elim _ _⟩⟩⟩
@[simp]
theorem isCyclic_multiplicative_iff [SubNegMonoid α] :
IsCyclic (Multiplicative α) ↔ IsAddCyclic α :=
⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩
instance isCyclic_multiplicative [AddGroup α] [IsAddCyclic α] : IsCyclic (Multiplicative α) :=
isCyclic_multiplicative_iff.mpr inferInstance
@[simp]
theorem isAddCyclic_additive_iff [DivInvMonoid α] : IsAddCyclic (Additive α) ↔ IsCyclic α :=
⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩
instance isAddCyclic_additive [Group α] [IsCyclic α] : IsAddCyclic (Additive α) :=
isAddCyclic_additive_iff.mpr inferInstance
@[to_additive]
instance IsCyclic.commutative [Group α] [IsCyclic α] :
Std.Commutative (· * · : α → α → α) where
comm x y :=
let ⟨_, hg⟩ := IsCyclic.exists_generator (α := α)
let ⟨_, hx⟩ := hg x
let ⟨_, hy⟩ := hg y
hy ▸ hx ▸ zpow_mul_comm _ _ _
/-- A cyclic group is always commutative. This is not an `instance` because often we have a better
proof of `CommGroup`. -/
@[to_additive
"A cyclic group is always commutative. This is not an `instance` because often we have
a better proof of `AddCommGroup`."]
def IsCyclic.commGroup [hg : Group α] [IsCyclic α] : CommGroup α :=
{ hg with mul_comm := commutative.comm }
instance [Group G] (H : Subgroup G) [IsCyclic H] : IsMulCommutative H :=
⟨IsCyclic.commutative⟩
variable [Group α] [Group G] [Group G']
/-- A non-cyclic multiplicative group is non-trivial. -/
@[to_additive "A non-cyclic additive group is non-trivial."]
theorem Nontrivial.of_not_isCyclic (nc : ¬IsCyclic α) : Nontrivial α := by
contrapose! nc
exact @isCyclic_of_subsingleton _ _ (not_nontrivial_iff_subsingleton.mp nc)
@[to_additive]
theorem MonoidHom.map_cyclic [h : IsCyclic G] (σ : G →* G) :
∃ m : ℤ, ∀ g : G, σ g = g ^ m := by
obtain ⟨h, hG⟩ := IsCyclic.exists_generator (α := G)
obtain ⟨m, hm⟩ := hG (σ h)
refine ⟨m, fun g => ?_⟩
obtain ⟨n, rfl⟩ := hG g
rw [MonoidHom.map_zpow, ← hm, ← zpow_mul, ← zpow_mul']
@[to_additive]
lemma isCyclic_iff_exists_orderOf_eq_natCard [Finite α] :
IsCyclic α ↔ ∃ g : α, orderOf g = Nat.card α := by
simp_rw [isCyclic_iff_exists_zpowers_eq_top, ← card_eq_iff_eq_top, Nat.card_zpowers]
@[to_additive]
lemma isCyclic_iff_exists_natCard_le_orderOf [Finite α] :
IsCyclic α ↔ ∃ g : α, Nat.card α ≤ orderOf g := by
rw [isCyclic_iff_exists_orderOf_eq_natCard]
apply exists_congr
intro g
exact ⟨Eq.ge, le_antisymm orderOf_le_card⟩
@[deprecated (since := "2024-12-20")]
alias isCyclic_iff_exists_ofOrder_eq_natCard := isCyclic_iff_exists_orderOf_eq_natCard
@[deprecated (since := "2024-12-20")]
alias isAddCyclic_iff_exists_ofOrder_eq_natCard := isAddCyclic_iff_exists_addOrderOf_eq_natCard
@[deprecated (since := "2024-12-20")]
alias IsCyclic.iff_exists_ofOrder_eq_natCard_of_Fintype :=
isCyclic_iff_exists_orderOf_eq_natCard
@[deprecated (since := "2024-12-20")]
alias IsAddCyclic.iff_exists_ofOrder_eq_natCard_of_Fintype :=
isAddCyclic_iff_exists_addOrderOf_eq_natCard
@[to_additive]
theorem isCyclic_of_orderOf_eq_card [Finite α] (x : α) (hx : orderOf x = Nat.card α) :
IsCyclic α :=
isCyclic_iff_exists_orderOf_eq_natCard.mpr ⟨x, hx⟩
@[to_additive]
theorem isCyclic_of_card_le_orderOf [Finite α] (x : α) (hx : Nat.card α ≤ orderOf x) :
IsCyclic α :=
isCyclic_iff_exists_natCard_le_orderOf.mpr ⟨x, hx⟩
@[to_additive]
theorem Subgroup.eq_bot_or_eq_top_of_prime_card
(H : Subgroup G) [hp : Fact (Nat.card G).Prime] : H = ⊥ ∨ H = ⊤ := by
have : Finite G := Nat.finite_of_card_ne_zero hp.1.ne_zero
have := card_subgroup_dvd_card H
rwa [Nat.dvd_prime hp.1, ← eq_bot_iff_card, card_eq_iff_eq_top] at this
/-- Any non-identity element of a finite group of prime order generates the group. -/
@[to_additive "Any non-identity element of a finite group of prime order generates the group."]
theorem zpowers_eq_top_of_prime_card {p : ℕ}
[hp : Fact p.Prime] (h : Nat.card G = p) {g : G} (hg : g ≠ 1) : zpowers g = ⊤ := by
subst h
have := (zpowers g).eq_bot_or_eq_top_of_prime_card
rwa [zpowers_eq_bot, or_iff_right hg] at this
@[to_additive]
theorem mem_zpowers_of_prime_card {p : ℕ} [hp : Fact p.Prime]
(h : Nat.card G = p) {g g' : G} (hg : g ≠ 1) : g' ∈ zpowers g := by
simp_rw [zpowers_eq_top_of_prime_card h hg, Subgroup.mem_top]
@[to_additive]
theorem mem_powers_of_prime_card {p : ℕ} [hp : Fact p.Prime]
(h : Nat.card G = p) {g g' : G} (hg : g ≠ 1) : g' ∈ Submonoid.powers g := by
have : Finite G := Nat.finite_of_card_ne_zero (h ▸ hp.1.ne_zero)
rw [mem_powers_iff_mem_zpowers]
exact mem_zpowers_of_prime_card h hg
@[to_additive]
theorem powers_eq_top_of_prime_card {p : ℕ}
[hp : Fact p.Prime] (h : Nat.card G = p) {g : G} (hg : g ≠ 1) : Submonoid.powers g = ⊤ := by
ext x
simp [mem_powers_of_prime_card h hg]
/-- A finite group of prime order is cyclic. -/
@[to_additive "A finite group of prime order is cyclic."]
theorem isCyclic_of_prime_card {p : ℕ} [hp : Fact p.Prime]
(h : Nat.card α = p) : IsCyclic α := by
have : Finite α := Nat.finite_of_card_ne_zero (h ▸ hp.1.ne_zero)
have : Nontrivial α := Finite.one_lt_card_iff_nontrivial.mp (h ▸ hp.1.one_lt)
obtain ⟨g, hg⟩ : ∃ g : α, g ≠ 1 := exists_ne 1
exact ⟨g, fun g' ↦ mem_zpowers_of_prime_card h hg⟩
/-- A finite group of order dividing a prime is cyclic. -/
@[to_additive "A finite group of order dividing a prime is cyclic."]
theorem isCyclic_of_card_dvd_prime {p : ℕ} [hp : Fact p.Prime]
(h : Nat.card α ∣ p) : IsCyclic α := by
rcases (Nat.dvd_prime hp.out).mp h with h | h
· exact @isCyclic_of_subsingleton α _ (Nat.card_eq_one_iff_unique.mp h).1
· exact isCyclic_of_prime_card h
@[to_additive]
theorem isCyclic_of_surjective {F : Type*} [hH : IsCyclic G']
[FunLike F G' G] [MonoidHomClass F G' G] (f : F) (hf : Function.Surjective f) :
IsCyclic G := by
obtain ⟨x, hx⟩ := hH
refine ⟨f x, fun a ↦ ?_⟩
obtain ⟨a, rfl⟩ := hf a
obtain ⟨n, rfl⟩ := hx a
exact ⟨n, (map_zpow _ _ _).symm⟩
@[to_additive]
theorem orderOf_eq_card_of_forall_mem_zpowers {g : α} (hx : ∀ x, x ∈ zpowers g) :
orderOf g = Nat.card α := by
rw [← Nat.card_zpowers, (zpowers g).eq_top_iff'.mpr hx, card_top]
@[deprecated (since := "2024-11-15")]
alias orderOf_generator_eq_natCard := orderOf_eq_card_of_forall_mem_zpowers
@[deprecated (since := "2024-11-15")]
alias addOrderOf_generator_eq_natCard := addOrderOf_eq_card_of_forall_mem_zmultiples
@[to_additive]
theorem exists_pow_ne_one_of_isCyclic [G_cyclic : IsCyclic G]
{k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Nat.card G) : ∃ a : G, a ^ k ≠ 1 := by
have : Finite G := Nat.finite_of_card_ne_zero (Nat.ne_zero_of_lt k_lt_card_G)
rcases G_cyclic with ⟨a, ha⟩
use a
contrapose! k_lt_card_G
convert orderOf_le_of_pow_eq_one k_pos.bot_lt k_lt_card_G
rw [← Nat.card_zpowers, eq_comm, card_eq_iff_eq_top, eq_top_iff]
exact fun x _ ↦ ha x
@[to_additive]
theorem Infinite.orderOf_eq_zero_of_forall_mem_zpowers [Infinite α] {g : α}
(h : ∀ x, x ∈ zpowers g) : orderOf g = 0 := by
rw [orderOf_eq_card_of_forall_mem_zpowers h, Nat.card_eq_zero_of_infinite]
@[to_additive]
instance Bot.isCyclic : IsCyclic (⊥ : Subgroup α) :=
⟨⟨1, fun x => ⟨0, Subtype.eq <| (zpow_zero (1 : α)).trans <| Eq.symm (Subgroup.mem_bot.1 x.2)⟩⟩⟩
@[to_additive]
instance Subgroup.isCyclic [IsCyclic α] (H : Subgroup α) : IsCyclic H :=
haveI := Classical.propDecidable
let ⟨g, hg⟩ := IsCyclic.exists_generator (α := α)
if hx : ∃ x : α, x ∈ H ∧ x ≠ (1 : α) then
let ⟨x, hx₁, hx₂⟩ := hx
let ⟨k, hk⟩ := hg x
have hk : g ^ k = x := hk
have hex : ∃ n : ℕ, 0 < n ∧ g ^ n ∈ H :=
⟨k.natAbs,
Nat.pos_of_ne_zero fun h => hx₂ <| by
rw [← hk, Int.natAbs_eq_zero.mp h, zpow_zero], by
rcases k with k | k
· rw [Int.ofNat_eq_coe, Int.natAbs_cast k, ← zpow_natCast, ← Int.ofNat_eq_coe, hk]
exact hx₁
· rw [Int.natAbs_negSucc, ← Subgroup.inv_mem_iff H]; simp_all⟩
⟨⟨⟨g ^ Nat.find hex, (Nat.find_spec hex).2⟩, fun ⟨x, hx⟩ =>
let ⟨k, hk⟩ := hg x
have hk : g ^ k = x := hk
have hk₂ : g ^ ((Nat.find hex : ℤ) * (k / Nat.find hex : ℤ)) ∈ H := by
rw [zpow_mul]
apply H.zpow_mem
exact mod_cast (Nat.find_spec hex).2
have hk₃ : g ^ (k % Nat.find hex : ℤ) ∈ H :=
(Subgroup.mul_mem_cancel_right H hk₂).1 <| by
rw [← zpow_add, Int.emod_add_ediv, hk]; exact hx
have hk₄ : k % Nat.find hex = (k % Nat.find hex).natAbs := by
rw [Int.natAbs_of_nonneg
(Int.emod_nonneg _ (Int.natCast_ne_zero_iff_pos.2 (Nat.find_spec hex).1))]
have hk₅ : g ^ (k % Nat.find hex).natAbs ∈ H := by rwa [← zpow_natCast, ← hk₄]
have hk₆ : (k % (Nat.find hex : ℤ)).natAbs = 0 :=
by_contradiction fun h =>
Nat.find_min hex
(Int.ofNat_lt.1 <| by
rw [← hk₄]; exact Int.emod_lt_of_pos _ (Int.natCast_pos.2 (Nat.find_spec hex).1))
⟨Nat.pos_of_ne_zero h, hk₅⟩
⟨k / (Nat.find hex : ℤ),
Subtype.ext_iff_val.2
(by
suffices g ^ ((Nat.find hex : ℤ) * (k / Nat.find hex : ℤ)) = x by simpa [zpow_mul]
rw [Int.mul_ediv_cancel'
(Int.dvd_of_emod_eq_zero (Int.natAbs_eq_zero.mp hk₆)),
hk])⟩⟩⟩
else by
have : H = (⊥ : Subgroup α) :=
Subgroup.ext fun x =>
⟨fun h => by simp at *; tauto, fun h => by rw [Subgroup.mem_bot.1 h]; exact H.one_mem⟩
subst this; infer_instance
@[to_additive]
theorem isCyclic_of_injective [IsCyclic G'] (f : G →* G') (hf : Function.Injective f) :
IsCyclic G :=
isCyclic_of_surjective (MonoidHom.ofInjective hf).symm (MonoidHom.ofInjective hf).symm.surjective
@[to_additive]
lemma Subgroup.isCyclic_of_le {H H' : Subgroup G} (h : H ≤ H') [IsCyclic H'] : IsCyclic H :=
isCyclic_of_injective (Subgroup.inclusion h) (Subgroup.inclusion_injective h)
open Finset Nat
section Classical
open scoped Classical in
@[to_additive IsAddCyclic.card_nsmul_eq_zero_le]
theorem IsCyclic.card_pow_eq_one_le [DecidableEq α] [Fintype α] [IsCyclic α] {n : ℕ} (hn0 : 0 < n) :
#{a : α | a ^ n = 1} ≤ n :=
let ⟨g, hg⟩ := IsCyclic.exists_generator (α := α)
calc
#{a : α | a ^ n = 1} ≤
#(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) : Set α).toFinset :=
card_le_card fun x hx =>
let ⟨m, hm⟩ := show x ∈ Submonoid.powers g from mem_powers_iff_mem_zpowers.2 <| hg x
Set.mem_toFinset.2
⟨(m / (Fintype.card α / Nat.gcd n (Fintype.card α)) : ℕ), by
dsimp at hm
have hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 := by
rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2
dsimp only
rw [zpow_natCast, ← pow_mul, Nat.mul_div_cancel_left', hm]
refine Nat.dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (Fintype.card α) hn0) ?_
conv_lhs =>
rw [Nat.div_mul_cancel (Nat.gcd_dvd_right _ _), ← Nat.card_eq_fintype_card,
← orderOf_eq_card_of_forall_mem_zpowers hg]
exact orderOf_dvd_of_pow_eq_one hgmn⟩
_ ≤ n := by
let ⟨m, hm⟩ := Nat.gcd_dvd_right n (Fintype.card α)
have hm0 : 0 < m :=
Nat.pos_of_ne_zero fun hm0 => by
rw [hm0, mul_zero, Fintype.card_eq_zero_iff] at hm
exact hm.elim' 1
simp only [Set.toFinset_card, SetLike.coe_sort_coe]
rw [Fintype.card_zpowers, orderOf_pow g, orderOf_eq_card_of_forall_mem_zpowers hg,
Nat.card_eq_fintype_card]
nth_rw 2 [hm]; nth_rw 3 [hm]
rw [Nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left, hm,
Nat.mul_div_cancel _ hm0]
exact le_of_dvd hn0 (Nat.gcd_dvd_left _ _)
end Classical
@[to_additive]
theorem IsCyclic.exists_monoid_generator [Finite α] [IsCyclic α] :
∃ x : α, ∀ y : α, y ∈ Submonoid.powers x := by
simp_rw [mem_powers_iff_mem_zpowers]
exact IsCyclic.exists_generator
@[to_additive]
lemma IsCyclic.exists_ofOrder_eq_natCard [h : IsCyclic α] : ∃ g : α, orderOf g = Nat.card α := by
obtain ⟨g, hg⟩ := h.exists_generator
use g
rw [← card_zpowers g, (eq_top_iff' (zpowers g)).mpr hg]
exact Nat.card_congr (Equiv.Set.univ α)
variable (G) in
/-- A distributive action of a monoid on a finite cyclic group of order `n` factors through an
action on `ZMod n`. -/
noncomputable def MulDistribMulAction.toMonoidHomZModOfIsCyclic (M : Type*) [Monoid M]
[IsCyclic G] [MulDistribMulAction M G] {n : ℕ} (hn : Nat.card G = n) : M →* ZMod n where
toFun m := (MulDistribMulAction.toMonoidHom G m).map_cyclic.choose
map_one' := by
obtain ⟨g, hg⟩ := IsCyclic.exists_ofOrder_eq_natCard (α := G)
rw [← Int.cast_one, ZMod.intCast_eq_intCast_iff, ← hn, ← hg, ← zpow_eq_zpow_iff_modEq,
zpow_one, ← (MulDistribMulAction.toMonoidHom G 1).map_cyclic.choose_spec,
MulDistribMulAction.toMonoidHom_apply, one_smul]
map_mul' m n := by
obtain ⟨g, hg⟩ := IsCyclic.exists_ofOrder_eq_natCard (α := G)
rw [← Int.cast_mul, ZMod.intCast_eq_intCast_iff, ← hn, ← hg, ← zpow_eq_zpow_iff_modEq,
zpow_mul', ← (MulDistribMulAction.toMonoidHom G m).map_cyclic.choose_spec,
← (MulDistribMulAction.toMonoidHom G n).map_cyclic.choose_spec,
← (MulDistribMulAction.toMonoidHom G (m * n)).map_cyclic.choose_spec,
MulDistribMulAction.toMonoidHom_apply, MulDistribMulAction.toMonoidHom_apply,
MulDistribMulAction.toMonoidHom_apply, mul_smul]
theorem MulDistribMulAction.toMonoidHomZModOfIsCyclic_apply {M : Type*} [Monoid M] [IsCyclic G]
[MulDistribMulAction M G] {n : ℕ} (hn : Nat.card G = n) (m : M) (g : G) (k : ℤ)
(h : toMonoidHomZModOfIsCyclic G M hn m = k) : m • g = g ^ k := by
rw [← MulDistribMulAction.toMonoidHom_apply,
(MulDistribMulAction.toMonoidHom G m).map_cyclic.choose_spec g, zpow_eq_zpow_iff_modEq]
apply Int.ModEq.of_dvd (Int.natCast_dvd_natCast.mpr (orderOf_dvd_natCard g))
rwa [hn, ← ZMod.intCast_eq_intCast_iff]
section
variable [Fintype α]
@[to_additive]
theorem IsCyclic.unique_zpow_zmod (ha : ∀ x : α, x ∈ zpowers a) (x : α) :
∃! n : ZMod (Fintype.card α), x = a ^ n.val := by
obtain ⟨n, rfl⟩ := ha x
refine ⟨n, (?_ : a ^ n = _), fun y (hy : a ^ n = _) ↦ ?_⟩
· rw [← zpow_natCast, zpow_eq_zpow_iff_modEq, orderOf_eq_card_of_forall_mem_zpowers ha,
Int.modEq_comm, Int.modEq_iff_add_fac, Nat.card_eq_fintype_card, ← ZMod.intCast_eq_iff]
· rw [← zpow_natCast, zpow_eq_zpow_iff_modEq, orderOf_eq_card_of_forall_mem_zpowers ha,
Nat.card_eq_fintype_card, ← ZMod.intCast_eq_intCast_iff] at hy
simp [hy]
variable [DecidableEq α]
@[to_additive]
theorem IsCyclic.image_range_orderOf (ha : ∀ x : α, x ∈ zpowers a) :
Finset.image (fun i => a ^ i) (range (orderOf a)) = univ := by
simp_rw [← SetLike.mem_coe] at ha
simp only [_root_.image_range_orderOf, Set.eq_univ_iff_forall.mpr ha, Set.toFinset_univ]
@[to_additive]
| Mathlib/GroupTheory/SpecificGroups/Cyclic.lean | 414 | 433 | theorem IsCyclic.image_range_card (ha : ∀ x : α, x ∈ zpowers a) :
Finset.image (fun i => a ^ i) (range (Nat.card α)) = univ := by | rw [← orderOf_eq_card_of_forall_mem_zpowers ha, IsCyclic.image_range_orderOf ha]
@[to_additive]
lemma IsCyclic.ext [Finite G] [IsCyclic G] {d : ℕ} {a b : ZMod d}
(hGcard : Nat.card G = d) (h : ∀ t : G, t ^ a.val = t ^ b.val) : a = b := by
have : NeZero (Nat.card G) := ⟨Nat.card_pos.ne'⟩
obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := G)
specialize h g
subst hGcard
rw [pow_eq_pow_iff_modEq, orderOf_eq_card_of_forall_mem_zpowers hg,
← ZMod.natCast_eq_natCast_iff] at h
simpa [ZMod.natCast_val, ZMod.cast_id'] using h
end
section Totient
variable [DecidableEq α] [Fintype α] (hn : ∀ n : ℕ, 0 < n → #{a : α | a ^ n = 1} ≤ n) |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Basic
/-!
# Maps between real and extended non-negative real numbers
This file focuses on the functions `ENNReal.toReal : ℝ≥0∞ → ℝ` and `ENNReal.ofReal : ℝ → ℝ≥0∞` which
were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between
these functions and the algebraic and lattice operations, although a few may appear in earlier
files.
This file provides a `positivity` extension for `ENNReal.ofReal`.
# Main theorems
- `trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp`
- `dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal`: often used for `WithLp` and `lp`
- `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between
indexed or set infima and suprema in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. This is especially useful because
`ℝ≥0∞` is a complete lattice.
-/
assert_not_exists Finset
open Set NNReal ENNReal
namespace ENNReal
section Real
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
theorem toReal_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a + b).toReal = a.toReal + b.toReal := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
rfl
theorem toReal_add_le : (a + b).toReal ≤ a.toReal + b.toReal :=
if ha : a = ∞ then by simp only [ha, top_add, toReal_top, zero_add, toReal_nonneg]
else
if hb : b = ∞ then by simp only [hb, add_top, toReal_top, add_zero, toReal_nonneg]
else le_of_eq (toReal_add ha hb)
theorem ofReal_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by
rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj,
Real.toNNReal_add hp hq]
theorem ofReal_add_le {p q : ℝ} : ENNReal.ofReal (p + q) ≤ ENNReal.ofReal p + ENNReal.ofReal q :=
coe_le_coe.2 Real.toNNReal_add_le
@[simp]
theorem toReal_le_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal ≤ b.toReal ↔ a ≤ b := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
norm_cast
@[gcongr]
theorem toReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toReal ≤ b.toReal :=
(toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h
theorem toReal_mono' (h : a ≤ b) (ht : b = ∞ → a = ∞) : a.toReal ≤ b.toReal := by
rcases eq_or_ne a ∞ with rfl | ha
· exact toReal_nonneg
· exact toReal_mono (mt ht ha) h
@[simp]
theorem toReal_lt_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal < b.toReal ↔ a < b := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
norm_cast
@[gcongr]
theorem toReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toReal < b.toReal :=
(toReal_lt_toReal h.ne_top hb).2 h
@[gcongr]
theorem toNNReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toNNReal ≤ b.toNNReal :=
toReal_mono hb h
theorem le_toNNReal_of_coe_le (h : p ≤ a) (ha : a ≠ ∞) : p ≤ a.toNNReal :=
@toNNReal_coe p ▸ toNNReal_mono ha h
@[simp]
theorem toNNReal_le_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal ≤ b.toNNReal ↔ a ≤ b :=
⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_le_coe], toNNReal_mono hb⟩
@[gcongr]
theorem toNNReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toNNReal < b.toNNReal := by
simpa [← ENNReal.coe_lt_coe, hb, h.ne_top]
@[simp]
theorem toNNReal_lt_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal < b.toNNReal ↔ a < b :=
⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hb⟩
theorem toNNReal_lt_of_lt_coe (h : a < p) : a.toNNReal < p :=
@toNNReal_coe p ▸ toNNReal_strict_mono coe_ne_top h
theorem toReal_max (hr : a ≠ ∞) (hp : b ≠ ∞) :
ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) :=
(le_total a b).elim
(fun h => by simp only [h, ENNReal.toReal_mono hp h, max_eq_right]) fun h => by
simp only [h, ENNReal.toReal_mono hr h, max_eq_left]
theorem toReal_min {a b : ℝ≥0∞} (hr : a ≠ ∞) (hp : b ≠ ∞) :
ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) :=
(le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, min_eq_left])
fun h => by simp only [h, ENNReal.toReal_mono hr h, min_eq_right]
theorem toReal_sup {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊔ b).toReal = a.toReal ⊔ b.toReal :=
toReal_max
theorem toReal_inf {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊓ b).toReal = a.toReal ⊓ b.toReal :=
toReal_min
theorem toNNReal_pos_iff : 0 < a.toNNReal ↔ 0 < a ∧ a < ∞ := by
induction a <;> simp
theorem toNNReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toNNReal :=
toNNReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩
theorem toReal_pos_iff : 0 < a.toReal ↔ 0 < a ∧ a < ∞ :=
NNReal.coe_pos.trans toNNReal_pos_iff
theorem toReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toReal :=
toReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩
@[gcongr, bound]
theorem ofReal_le_ofReal {p q : ℝ} (h : p ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q := by
simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h]
theorem ofReal_le_of_le_toReal {a : ℝ} {b : ℝ≥0∞} (h : a ≤ ENNReal.toReal b) :
ENNReal.ofReal a ≤ b :=
(ofReal_le_ofReal h).trans ofReal_toReal_le
@[simp]
theorem ofReal_le_ofReal_iff {p q : ℝ} (h : 0 ≤ q) :
ENNReal.ofReal p ≤ ENNReal.ofReal q ↔ p ≤ q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_le_coe, Real.toNNReal_le_toNNReal_iff h]
lemma ofReal_le_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p ≤ .ofReal q ↔ p ≤ q ∨ p ≤ 0 :=
coe_le_coe.trans Real.toNNReal_le_toNNReal_iff'
lemma ofReal_lt_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p < .ofReal q ↔ p < q ∧ 0 < q :=
coe_lt_coe.trans Real.toNNReal_lt_toNNReal_iff'
@[simp]
theorem ofReal_eq_ofReal_iff {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ENNReal.ofReal p = ENNReal.ofReal q ↔ p = q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_inj, Real.toNNReal_eq_toNNReal_iff hp hq]
@[simp]
theorem ofReal_lt_ofReal_iff {p q : ℝ} (h : 0 < q) :
ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff h]
theorem ofReal_lt_ofReal_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) :
ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff_of_nonneg hp]
@[simp]
theorem ofReal_pos {p : ℝ} : 0 < ENNReal.ofReal p ↔ 0 < p := by simp [ENNReal.ofReal]
@[bound] private alias ⟨_, Bound.ofReal_pos_of_pos⟩ := ofReal_pos
@[simp]
theorem ofReal_eq_zero {p : ℝ} : ENNReal.ofReal p = 0 ↔ p ≤ 0 := by simp [ENNReal.ofReal]
theorem ofReal_ne_zero_iff {r : ℝ} : ENNReal.ofReal r ≠ 0 ↔ 0 < r := by
rw [← zero_lt_iff, ENNReal.ofReal_pos]
@[simp]
theorem zero_eq_ofReal {p : ℝ} : 0 = ENNReal.ofReal p ↔ p ≤ 0 :=
eq_comm.trans ofReal_eq_zero
alias ⟨_, ofReal_of_nonpos⟩ := ofReal_eq_zero
@[simp]
lemma ofReal_lt_natCast {p : ℝ} {n : ℕ} (hn : n ≠ 0) : ENNReal.ofReal p < n ↔ p < n := by
exact mod_cast ofReal_lt_ofReal_iff (Nat.cast_pos.2 hn.bot_lt)
@[simp]
lemma ofReal_lt_one {p : ℝ} : ENNReal.ofReal p < 1 ↔ p < 1 := by
exact mod_cast ofReal_lt_natCast one_ne_zero
@[simp]
lemma ofReal_lt_ofNat {p : ℝ} {n : ℕ} [n.AtLeastTwo] :
ENNReal.ofReal p < ofNat(n) ↔ p < OfNat.ofNat n :=
ofReal_lt_natCast (NeZero.ne n)
@[simp]
lemma natCast_le_ofReal {n : ℕ} {p : ℝ} (hn : n ≠ 0) : n ≤ ENNReal.ofReal p ↔ n ≤ p := by
simp only [← not_lt, ofReal_lt_natCast hn]
@[simp]
lemma one_le_ofReal {p : ℝ} : 1 ≤ ENNReal.ofReal p ↔ 1 ≤ p := by
exact mod_cast natCast_le_ofReal one_ne_zero
@[simp]
lemma ofNat_le_ofReal {n : ℕ} [n.AtLeastTwo] {p : ℝ} :
ofNat(n) ≤ ENNReal.ofReal p ↔ OfNat.ofNat n ≤ p :=
natCast_le_ofReal (NeZero.ne n)
@[simp, norm_cast]
lemma ofReal_le_natCast {r : ℝ} {n : ℕ} : ENNReal.ofReal r ≤ n ↔ r ≤ n :=
coe_le_coe.trans Real.toNNReal_le_natCast
@[simp]
lemma ofReal_le_one {r : ℝ} : ENNReal.ofReal r ≤ 1 ↔ r ≤ 1 :=
coe_le_coe.trans Real.toNNReal_le_one
@[simp]
lemma ofReal_le_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] :
ENNReal.ofReal r ≤ ofNat(n) ↔ r ≤ OfNat.ofNat n :=
ofReal_le_natCast
@[simp]
lemma natCast_lt_ofReal {n : ℕ} {r : ℝ} : n < ENNReal.ofReal r ↔ n < r :=
coe_lt_coe.trans Real.natCast_lt_toNNReal
@[simp]
lemma one_lt_ofReal {r : ℝ} : 1 < ENNReal.ofReal r ↔ 1 < r := coe_lt_coe.trans Real.one_lt_toNNReal
@[simp]
lemma ofNat_lt_ofReal {n : ℕ} [n.AtLeastTwo] {r : ℝ} :
ofNat(n) < ENNReal.ofReal r ↔ OfNat.ofNat n < r :=
natCast_lt_ofReal
@[simp]
lemma ofReal_eq_natCast {r : ℝ} {n : ℕ} (h : n ≠ 0) : ENNReal.ofReal r = n ↔ r = n :=
ENNReal.coe_inj.trans <| Real.toNNReal_eq_natCast h
@[simp]
lemma ofReal_eq_one {r : ℝ} : ENNReal.ofReal r = 1 ↔ r = 1 :=
ENNReal.coe_inj.trans Real.toNNReal_eq_one
@[simp]
lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] :
ENNReal.ofReal r = ofNat(n) ↔ r = OfNat.ofNat n :=
ofReal_eq_natCast (NeZero.ne n)
| Mathlib/Data/ENNReal/Real.lean | 246 | 248 | theorem ofReal_le_iff_le_toReal {a : ℝ} {b : ℝ≥0∞} (hb : b ≠ ∞) :
ENNReal.ofReal a ≤ b ↔ a ≤ ENNReal.toReal b := by | lift b to ℝ≥0 using hb |
/-
Copyright (c) 2020 Paul van Wamelen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul van Wamelen
-/
import Mathlib.Data.Nat.Factors
import Mathlib.NumberTheory.FLT.Basic
import Mathlib.NumberTheory.PythagoreanTriples
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.Tactic.LinearCombination
/-!
# Fermat's Last Theorem for the case n = 4
There are no non-zero integers `a`, `b` and `c` such that `a ^ 4 + b ^ 4 = c ^ 4`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
/-- Shorthand for three non-zero integers `a`, `b`, and `c` satisfying `a ^ 4 + b ^ 4 = c ^ 2`.
We will show that no integers satisfy this equation. Clearly Fermat's Last theorem for n = 4
follows. -/
def Fermat42 (a b c : ℤ) : Prop :=
a ≠ 0 ∧ b ≠ 0 ∧ a ^ 4 + b ^ 4 = c ^ 2
namespace Fermat42
theorem comm {a b c : ℤ} : Fermat42 a b c ↔ Fermat42 b a c := by
delta Fermat42
rw [add_comm]
tauto
theorem mul {a b c k : ℤ} (hk0 : k ≠ 0) :
Fermat42 a b c ↔ Fermat42 (k * a) (k * b) (k ^ 2 * c) := by
delta Fermat42
constructor
· intro f42
constructor
· exact mul_ne_zero hk0 f42.1
constructor
· exact mul_ne_zero hk0 f42.2.1
· have H : a ^ 4 + b ^ 4 = c ^ 2 := f42.2.2
linear_combination k ^ 4 * H
· intro f42
constructor
· exact right_ne_zero_of_mul f42.1
constructor
· exact right_ne_zero_of_mul f42.2.1
apply (mul_right_inj' (pow_ne_zero 4 hk0)).mp
linear_combination f42.2.2
theorem ne_zero {a b c : ℤ} (h : Fermat42 a b c) : c ≠ 0 := by
apply ne_zero_pow two_ne_zero _; apply ne_of_gt
rw [← h.2.2, (by ring : a ^ 4 + b ^ 4 = (a ^ 2) ^ 2 + (b ^ 2) ^ 2)]
exact
add_pos (sq_pos_of_ne_zero (pow_ne_zero 2 h.1)) (sq_pos_of_ne_zero (pow_ne_zero 2 h.2.1))
/-- We say a solution to `a ^ 4 + b ^ 4 = c ^ 2` is minimal if there is no other solution with
a smaller `c` (in absolute value). -/
def Minimal (a b c : ℤ) : Prop :=
Fermat42 a b c ∧ ∀ a1 b1 c1 : ℤ, Fermat42 a1 b1 c1 → Int.natAbs c ≤ Int.natAbs c1
/-- if we have a solution to `a ^ 4 + b ^ 4 = c ^ 2` then there must be a minimal one. -/
theorem exists_minimal {a b c : ℤ} (h : Fermat42 a b c) : ∃ a0 b0 c0, Minimal a0 b0 c0 := by
classical
let S : Set ℕ := { n | ∃ s : ℤ × ℤ × ℤ, Fermat42 s.1 s.2.1 s.2.2 ∧ n = Int.natAbs s.2.2 }
have S_nonempty : S.Nonempty := by
use Int.natAbs c
rw [Set.mem_setOf_eq]
use ⟨a, ⟨b, c⟩⟩
let m : ℕ := Nat.find S_nonempty
have m_mem : m ∈ S := Nat.find_spec S_nonempty
rcases m_mem with ⟨s0, hs0, hs1⟩
use s0.1, s0.2.1, s0.2.2, hs0
intro a1 b1 c1 h1
rw [← hs1]
apply Nat.find_min'
use ⟨a1, ⟨b1, c1⟩⟩
/-- a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` must have `a` and `b` coprime. -/
theorem coprime_of_minimal {a b c : ℤ} (h : Minimal a b c) : IsCoprime a b := by
apply Int.isCoprime_iff_gcd_eq_one.mpr
by_contra hab
obtain ⟨p, hp, hpa, hpb⟩ := Nat.Prime.not_coprime_iff_dvd.mp hab
obtain ⟨a1, rfl⟩ := Int.natCast_dvd.mpr hpa
obtain ⟨b1, rfl⟩ := Int.natCast_dvd.mpr hpb
have hpc : (p : ℤ) ^ 2 ∣ c := by
rw [← Int.pow_dvd_pow_iff two_ne_zero, ← h.1.2.2]
apply Dvd.intro (a1 ^ 4 + b1 ^ 4)
ring
obtain ⟨c1, rfl⟩ := hpc
have hf : Fermat42 a1 b1 c1 :=
(Fermat42.mul (Int.natCast_ne_zero.mpr (Nat.Prime.ne_zero hp))).mpr h.1
apply Nat.le_lt_asymm (h.2 _ _ _ hf)
rw [Int.natAbs_mul, lt_mul_iff_one_lt_left, Int.natAbs_pow, Int.natAbs_natCast]
· exact Nat.one_lt_pow two_ne_zero (Nat.Prime.one_lt hp)
· exact Nat.pos_of_ne_zero (Int.natAbs_ne_zero.2 (ne_zero hf))
/-- We can swap `a` and `b` in a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2`. -/
theorem minimal_comm {a b c : ℤ} : Minimal a b c → Minimal b a c := fun ⟨h1, h2⟩ =>
⟨Fermat42.comm.mp h1, h2⟩
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has positive `c`. -/
theorem neg_of_minimal {a b c : ℤ} : Minimal a b c → Minimal a b (-c) := by
rintro ⟨⟨ha, hb, heq⟩, h2⟩
constructor
· apply And.intro ha (And.intro hb _)
rw [heq]
exact (neg_sq c).symm
rwa [Int.natAbs_neg c]
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has `a` odd. -/
theorem exists_odd_minimal {a b c : ℤ} (h : Fermat42 a b c) :
∃ a0 b0 c0, Minimal a0 b0 c0 ∧ a0 % 2 = 1 := by
obtain ⟨a0, b0, c0, hf⟩ := exists_minimal h
rcases Int.emod_two_eq_zero_or_one a0 with hap | hap
· rcases Int.emod_two_eq_zero_or_one b0 with hbp | hbp
· exfalso
have h1 : 2 ∣ (Int.gcd a0 b0 : ℤ) :=
Int.dvd_coe_gcd (Int.dvd_of_emod_eq_zero hap) (Int.dvd_of_emod_eq_zero hbp)
rw [Int.isCoprime_iff_gcd_eq_one.mp (coprime_of_minimal hf)] at h1
revert h1
decide
· exact ⟨b0, ⟨a0, ⟨c0, minimal_comm hf, hbp⟩⟩⟩
exact ⟨a0, ⟨b0, ⟨c0, hf, hap⟩⟩⟩
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has
`a` odd and `c` positive. -/
theorem exists_pos_odd_minimal {a b c : ℤ} (h : Fermat42 a b c) :
∃ a0 b0 c0, Minimal a0 b0 c0 ∧ a0 % 2 = 1 ∧ 0 < c0 := by
obtain ⟨a0, b0, c0, hf, hc⟩ := exists_odd_minimal h
rcases lt_trichotomy 0 c0 with (h1 | h1 | h1)
· use a0, b0, c0
· exfalso
exact ne_zero hf.1 h1.symm
· use a0, b0, -c0, neg_of_minimal hf, hc
exact neg_pos.mpr h1
end Fermat42
theorem Int.isCoprime_of_sq_sum {r s : ℤ} (h2 : IsCoprime s r) : IsCoprime (r ^ 2 + s ^ 2) r := by
rw [sq, sq]
exact (IsCoprime.mul_left h2 h2).mul_add_left_left r
@[deprecated (since := "2025-01-23")] alias Int.coprime_of_sq_sum := Int.isCoprime_of_sq_sum
theorem Int.isCoprime_of_sq_sum' {r s : ℤ} (h : IsCoprime r s) :
IsCoprime (r ^ 2 + s ^ 2) (r * s) := by
apply IsCoprime.mul_right (Int.isCoprime_of_sq_sum (isCoprime_comm.mp h))
rw [add_comm]; apply Int.isCoprime_of_sq_sum h
@[deprecated (since := "2025-01-23")] alias Int.coprime_of_sq_sum' := Int.isCoprime_of_sq_sum'
namespace Fermat42
-- If we have a solution to a ^ 4 + b ^ 4 = c ^ 2, we can construct a smaller one. This
-- implies there can't be a smallest solution.
theorem not_minimal {a b c : ℤ} (h : Minimal a b c) (ha2 : a % 2 = 1) (hc : 0 < c) : False := by
-- Use the fact that a ^ 2, b ^ 2, c form a pythagorean triple to obtain m and n such that
-- a ^ 2 = m ^ 2 - n ^ 2, b ^ 2 = 2 * m * n and c = m ^ 2 + n ^ 2
-- first the formula:
have ht : PythagoreanTriple (a ^ 2) (b ^ 2) c := by
delta PythagoreanTriple
linear_combination h.1.2.2
-- coprime requirement:
have h2 : Int.gcd (a ^ 2) (b ^ 2) = 1 :=
Int.isCoprime_iff_gcd_eq_one.mp (coprime_of_minimal h).pow
-- in order to reduce the possibilities we get from the classification of pythagorean triples
-- it helps if we know the parity of a ^ 2 (and the sign of c):
have ha22 : a ^ 2 % 2 = 1 := by
rw [sq, Int.mul_emod, ha2]
decide
obtain ⟨m, n, ht1, ht2, ht3, ht4, ht5, ht6⟩ := ht.coprime_classification' h2 ha22 hc
-- Now a, n, m form a pythagorean triple and so we can obtain r and s such that
-- a = r ^ 2 - s ^ 2, n = 2 * r * s and m = r ^ 2 + s ^ 2
-- formula:
have htt : PythagoreanTriple a n m := by
delta PythagoreanTriple
linear_combination ht1
-- a and n are coprime, because a ^ 2 = m ^ 2 - n ^ 2 and m and n are coprime.
have h3 : Int.gcd a n = 1 := by
apply Int.isCoprime_iff_gcd_eq_one.mp
apply @IsCoprime.of_mul_left_left _ _ _ a
rw [← sq, ht1, (by ring : m ^ 2 - n ^ 2 = m ^ 2 + -n * n)]
exact (Int.isCoprime_iff_gcd_eq_one.mpr ht4).pow_left.add_mul_right_left (-n)
-- m is positive because b is non-zero and b ^ 2 = 2 * m * n and we already have 0 ≤ m.
have hb20 : b ^ 2 ≠ 0 := mt pow_eq_zero h.1.2.1
have h4 : 0 < m := by
apply lt_of_le_of_ne ht6
rintro rfl
revert hb20
rw [ht2]
simp
obtain ⟨r, s, _, htt2, htt3, htt4, htt5, htt6⟩ := htt.coprime_classification' h3 ha2 h4
-- Now use the fact that (b / 2) ^ 2 = m * r * s, and m, r and s are pairwise coprime to obtain
-- i, j and k such that m = i ^ 2, r = j ^ 2 and s = k ^ 2.
-- m and r * s are coprime because m = r ^ 2 + s ^ 2 and r and s are coprime.
have hcp : Int.gcd m (r * s) = 1 := by
rw [htt3]
exact Int.isCoprime_iff_gcd_eq_one.mp
(Int.isCoprime_of_sq_sum' (Int.isCoprime_iff_gcd_eq_one.mpr htt4))
-- b is even because b ^ 2 = 2 * m * n.
have hb2 : 2 ∣ b := by
apply @Int.Prime.dvd_pow' _ 2 _ Nat.prime_two
rw [ht2, mul_assoc]
exact dvd_mul_right 2 (m * n)
obtain ⟨b', hb2'⟩ := hb2
have hs : b' ^ 2 = m * (r * s) := by
apply (mul_right_inj' (by norm_num : (4 : ℤ) ≠ 0)).mp
linear_combination (-b - 2 * b') * hb2' + ht2 + 2 * m * htt2
have hrsz : r * s ≠ 0 := by
-- because b ^ 2 is not zero and (b / 2) ^ 2 = m * (r * s)
by_contra hrsz
revert hb20
rw [ht2, htt2, mul_assoc, @mul_assoc _ _ _ r s, hrsz]
simp
have h2b0 : b' ≠ 0 := by
apply ne_zero_pow two_ne_zero
rw [hs]
apply mul_ne_zero
· exact ne_of_gt h4
· exact hrsz
obtain ⟨i, hi⟩ := Int.sq_of_gcd_eq_one hcp hs.symm
-- use m is positive to exclude m = - i ^ 2
have hi' : ¬m = -i ^ 2 := by
by_contra h1
have hit : -i ^ 2 ≤ 0 := neg_nonpos.mpr (sq_nonneg i)
rw [← h1] at hit
apply absurd h4 (not_lt.mpr hit)
replace hi : m = i ^ 2 := Or.resolve_right hi hi'
rw [mul_comm] at hs
rw [Int.gcd_comm] at hcp
-- obtain d such that r * s = d ^ 2
obtain ⟨d, hd⟩ := Int.sq_of_gcd_eq_one hcp hs.symm
-- (b / 2) ^ 2 and m are positive so r * s is positive
have hd' : ¬r * s = -d ^ 2 := by
by_contra h1
rw [h1] at hs
have h2 : b' ^ 2 ≤ 0 := by
rw [hs, (by ring : -d ^ 2 * m = -(d ^ 2 * m))]
exact neg_nonpos.mpr ((mul_nonneg_iff_of_pos_right h4).mpr (sq_nonneg d))
have h2' : 0 ≤ b' ^ 2 := by apply sq_nonneg b'
exact absurd (lt_of_le_of_ne h2' (Ne.symm (pow_ne_zero _ h2b0))) (not_lt.mpr h2)
replace hd : r * s = d ^ 2 := Or.resolve_right hd hd'
-- r = +/- j ^ 2
obtain ⟨j, hj⟩ := Int.sq_of_gcd_eq_one htt4 hd
have hj0 : j ≠ 0 := by
intro h0
rw [h0, zero_pow two_ne_zero, neg_zero, or_self_iff] at hj
apply left_ne_zero_of_mul hrsz hj
rw [mul_comm] at hd
rw [Int.gcd_comm] at htt4
-- s = +/- k ^ 2
obtain ⟨k, hk⟩ := Int.sq_of_gcd_eq_one htt4 hd
have hk0 : k ≠ 0 := by
intro h0
rw [h0, zero_pow two_ne_zero, neg_zero, or_self_iff] at hk
apply right_ne_zero_of_mul hrsz hk
have hj2 : r ^ 2 = j ^ 4 := by
rcases hj with hjp | hjp <;>
· rw [hjp]
ring
have hk2 : s ^ 2 = k ^ 4 := by
rcases hk with hkp | hkp <;>
· rw [hkp]
ring
-- from m = r ^ 2 + s ^ 2 we now get a new solution to a ^ 4 + b ^ 4 = c ^ 2:
have hh : i ^ 2 = j ^ 4 + k ^ 4 := by rw [← hi, htt3, hj2, hk2]
have hn : n ≠ 0 := by
rw [ht2] at hb20
apply right_ne_zero_of_mul hb20
-- and it has a smaller c: from c = m ^ 2 + n ^ 2 we see that m is smaller than c, and i ^ 2 = m.
have hic : Int.natAbs i < Int.natAbs c := by
apply Int.ofNat_lt.mp
rw [← Int.eq_natAbs_of_nonneg (le_of_lt hc)]
apply gt_of_gt_of_ge _ (Int.natAbs_le_self_sq i)
rw [← hi, ht3]
apply gt_of_gt_of_ge _ (Int.le_self_sq m)
exact lt_add_of_pos_right (m ^ 2) (sq_pos_of_ne_zero hn)
have hic' : Int.natAbs c ≤ Int.natAbs i := by
apply h.2 j k i
exact ⟨hj0, hk0, hh.symm⟩
apply absurd (not_le_of_lt hic) (not_not.mpr hic')
end Fermat42
theorem not_fermat_42 {a b c : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) : a ^ 4 + b ^ 4 ≠ c ^ 2 := by
intro h
obtain ⟨a0, b0, c0, ⟨hf, h2, hp⟩⟩ :=
Fermat42.exists_pos_odd_minimal (And.intro ha (And.intro hb h))
apply Fermat42.not_minimal hf h2 hp
/--
Fermat's Last Theorem for $n=4$: if `a b c : ℕ` are all non-zero
then `a ^ 4 + b ^ 4 ≠ c ^ 4`.
-/
| Mathlib/NumberTheory/FLT/Four.lean | 298 | 302 | theorem fermatLastTheoremFour : FermatLastTheoremFor 4 := by | rw [fermatLastTheoremFor_iff_int]
intro a b c ha hb _ heq
apply @not_fermat_42 _ _ (c ^ 2) ha hb
rw [heq]; ring |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ι α β : Type*}
section LinearOrderedSemifield
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d e : α} {m n : ℤ}
/-!
### Relating two divisions.
-/
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := div_le_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")]
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b :=
div_lt_div_iff_of_pos_left ha hb hc
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b :=
div_le_div_iff_of_pos_left ha hb hc
@[deprecated div_lt_div_iff₀ (since := "2024-11-12")]
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b :=
div_lt_div_iff₀ b0 d0
@[deprecated div_le_div_iff₀ (since := "2024-11-12")]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b :=
div_le_div_iff₀ b0 d0
@[deprecated div_le_div₀ (since := "2024-11-12")]
theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d :=
div_le_div₀ hc hac hd hbd
@[deprecated div_lt_div₀ (since := "2024-11-12")]
theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀ hac hbd c0 d0
@[deprecated div_lt_div₀' (since := "2024-11-12")]
theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀' hac hbd c0 d0
/-!
### Relating one division and involving `1`
-/
@[bound]
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
@[bound]
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
@[bound]
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₁
theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff₀ hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff₀ hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff₀ hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff₀ hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by
simpa using inv_le_comm₀ ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by
simpa using inv_lt_comm₀ ha hb
theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by
simpa using le_inv_comm₀ ha hb
theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by
simpa using lt_inv_comm₀ ha hb
@[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr
@[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr
/-!
### Relating two divisions, involving `1`
-/
theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by
simpa using inv_anti₀ ha h
theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by
rwa [lt_div_iff₀' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)]
theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h
theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h
/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and
`le_of_one_div_le_one_div` -/
theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a :=
div_le_div_iff_of_pos_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a :=
div_lt_div_iff_of_pos_left zero_lt_one ha hb
theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by
rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by
rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
/-!
### Results about halving.
The equalities also hold in semifields of characteristic `0`.
-/
theorem half_pos (h : 0 < a) : 0 < a / 2 :=
div_pos h zero_lt_two
theorem one_half_pos : (0 : α) < 1 / 2 :=
half_pos zero_lt_one
@[simp]
theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by
rw [div_le_iff₀ (zero_lt_two' α), mul_two, le_add_iff_nonneg_left]
@[simp]
theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by
rw [div_lt_iff₀ (zero_lt_two' α), mul_two, lt_add_iff_pos_left]
alias ⟨_, half_le_self⟩ := half_le_self_iff
alias ⟨_, half_lt_self⟩ := half_lt_self_iff
alias div_two_lt_of_pos := half_lt_self
theorem one_half_lt_one : (1 / 2 : α) < 1 :=
half_lt_self zero_lt_one
theorem two_inv_lt_one : (2⁻¹ : α) < 1 :=
(one_div _).symm.trans_lt one_half_lt_one
theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff₀, mul_two]
theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff₀, mul_two]
theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by
rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three,
mul_div_cancel_left₀ a three_ne_zero]
/-!
### Miscellaneous lemmas
-/
@[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos]
@[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)]
theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by
rw [← mul_div_assoc] at h
rwa [mul_comm b, ← div_le_iff₀ hc]
theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) :
a / (b * e) ≤ c / (d * e) := by
rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div]
exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he)
theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by
have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one))
refine ⟨a / max (b + 1) 1, this, ?_⟩
rw [← lt_div_iff₀ this, div_div_cancel₀ h.ne']
exact lt_max_iff.2 (Or.inl <| lt_add_one _)
theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a :=
let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b;
⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff₀ hc₀]⟩
lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) :=
fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha
lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) :=
fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha
theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α}
(hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf
theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α}
(hc : 0 < c) : StrictMono fun x => f x / c := by
simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc)
-- see Note [lower instance priority]
instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where
dense a₁ a₂ h :=
⟨(a₁ + a₂) / 2,
calc
a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm
_ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two
,
calc
(a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two
_ = a₂ := add_self_div_two a₂
⟩
theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c :=
(monotone_div_right_of_nonneg hc).map_min.symm
theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c :=
(monotone_div_right_of_nonneg hc).map_max.symm
theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) :=
fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy
theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) :
1 / a ^ n ≤ 1 / a ^ m := by
refine (one_div_le_one_div ?_ ?_).mpr (pow_right_mono₀ a1 mn) <;>
exact pow_pos (zero_lt_one.trans_le a1) _
theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) :
1 / a ^ n < 1 / a ^ m := by
refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right₀ a1 mn) <;>
exact pow_pos (zero_lt_one.trans a1) _
theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_le_one_div_pow_of_le a1
theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_lt_one_div_pow_of_lt a1
theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy =>
(inv_lt_inv₀ hy hx).2 xy
theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by
convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp
theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by
convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp
theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_le_inv_pow_of_le a1
theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_lt_inv_pow_of_lt a1
| Mathlib/Algebra/Order/Field/Basic.lean | 272 | 275 | theorem le_iff_forall_one_lt_le_mul₀ {α : Type*}
[Semifield α] [LinearOrder α] [IsStrictOrderedRing α]
{a b : α} (hb : 0 ≤ b) : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := by | refine ⟨fun h _ hε ↦ h.trans <| le_mul_of_one_le_right hb hε.le, fun h ↦ ?_⟩ |
/-
Copyright (c) 2020 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Batteries.Tactic.Lint.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Order.ZeroLEOne
import Mathlib.Data.Nat.Cast.Order.Ring
import Mathlib.Data.Int.Order.Basic
import Mathlib.Data.Ineq
/-!
# Lemmas for `linarith`.
Those in the `Linarith` namespace should stay here.
Those outside the `Linarith` namespace may be deleted as they are ported to mathlib4.
-/
namespace Linarith
universe u
theorem lt_irrefl {α : Type u} [Preorder α] {a : α} : ¬a < a := _root_.lt_irrefl a
theorem eq_of_eq_of_eq {α} [Semiring α] {a b : α} (ha : a = 0) (hb : b = 0) : a + b = 0 := by
simp [*]
section Semiring
variable {α : Type u} [Semiring α] [PartialOrder α]
theorem zero_lt_one [IsStrictOrderedRing α] : (0:α) < 1 :=
_root_.zero_lt_one
theorem le_of_eq_of_le {a b : α} (ha : a = 0) (hb : b ≤ 0) : a + b ≤ 0 := by
simp [*]
theorem lt_of_eq_of_lt {a b : α} (ha : a = 0) (hb : b < 0) : a + b < 0 := by
simp [*]
| Mathlib/Tactic/Linarith/Lemmas.lean | 42 | 44 | theorem le_of_le_of_eq {a b : α} (ha : a ≤ 0) (hb : b = 0) : a + b ≤ 0 := by | simp [*] |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Floris van Doorn, Gabriel Ebner, Yury Kudryashov
-/
import Mathlib.Data.Set.Accumulate
import Mathlib.Order.ConditionallyCompleteLattice.Finset
import Mathlib.Order.Interval.Finset.Nat
/-!
# Conditionally complete linear order structure on `ℕ`
In this file we
* define a `ConditionallyCompleteLinearOrderBot` structure on `ℕ`;
* prove a few lemmas about `iSup`/`iInf`/`Set.iUnion`/`Set.iInter` and natural numbers.
-/
assert_not_exists MonoidWithZero
open Set
namespace Nat
open scoped Classical in
noncomputable instance : InfSet ℕ :=
⟨fun s ↦ if h : ∃ n, n ∈ s then @Nat.find (fun n ↦ n ∈ s) _ h else 0⟩
open scoped Classical in
noncomputable instance : SupSet ℕ :=
⟨fun s ↦ if h : ∃ n, ∀ a ∈ s, a ≤ n then @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h else 0⟩
open scoped Classical in
theorem sInf_def {s : Set ℕ} (h : s.Nonempty) : sInf s = @Nat.find (fun n ↦ n ∈ s) _ h :=
dif_pos _
open scoped Classical in
theorem sSup_def {s : Set ℕ} (h : ∃ n, ∀ a ∈ s, a ≤ n) :
sSup s = @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h :=
dif_pos _
theorem _root_.Set.Infinite.Nat.sSup_eq_zero {s : Set ℕ} (h : s.Infinite) : sSup s = 0 :=
dif_neg fun ⟨n, hn⟩ ↦
let ⟨k, hks, hk⟩ := h.exists_gt n
(hn k hks).not_lt hk
@[simp]
theorem sInf_eq_zero {s : Set ℕ} : sInf s = 0 ↔ 0 ∈ s ∨ s = ∅ := by
cases eq_empty_or_nonempty s with
| inl h => subst h
simp only [or_true, eq_self_iff_true, iInf, InfSet.sInf,
mem_empty_iff_false, exists_false, dif_neg, not_false_iff]
| inr h => simp only [h.ne_empty, or_false, Nat.sInf_def, h, Nat.find_eq_zero]
@[simp]
theorem sInf_empty : sInf ∅ = 0 := by
rw [sInf_eq_zero]
right
rfl
@[simp]
theorem iInf_of_empty {ι : Sort*} [IsEmpty ι] (f : ι → ℕ) : iInf f = 0 := by
rw [iInf_of_isEmpty, sInf_empty]
/-- This combines `Nat.iInf_of_empty` with `ciInf_const`. -/
@[simp]
lemma iInf_const_zero {ι : Sort*} : ⨅ _ : ι, 0 = 0 :=
(isEmpty_or_nonempty ι).elim (fun h ↦ by simp) fun h ↦ sInf_eq_zero.2 <| by simp
theorem sInf_mem {s : Set ℕ} (h : s.Nonempty) : sInf s ∈ s := by
classical
rw [Nat.sInf_def h]
exact Nat.find_spec h
theorem not_mem_of_lt_sInf {s : Set ℕ} {m : ℕ} (hm : m < sInf s) : m ∉ s := by
classical
cases eq_empty_or_nonempty s with
| inl h => subst h; apply not_mem_empty
| inr h => rw [Nat.sInf_def h] at hm; exact Nat.find_min h hm
protected theorem sInf_le {s : Set ℕ} {m : ℕ} (hm : m ∈ s) : sInf s ≤ m := by
classical
rw [Nat.sInf_def ⟨m, hm⟩]
exact Nat.find_min' ⟨m, hm⟩ hm
| Mathlib/Data/Nat/Lattice.lean | 86 | 88 | theorem nonempty_of_pos_sInf {s : Set ℕ} (h : 0 < sInf s) : s.Nonempty := by | by_contra contra
rw [Set.not_nonempty_iff_eq_empty] at contra |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
/-!
# Grönwall's inequality
The main technical result of this file is the Grönwall-like inequality
`norm_le_gronwallBound_of_norm_deriv_right_le`. It states that if `f : ℝ → E` satisfies `‖f a‖ ≤ δ`
and `∀ x ∈ [a, b), ‖f' x‖ ≤ K * ‖f x‖ + ε`, then for all `x ∈ [a, b]` we have `‖f x‖ ≤ δ * exp (K *
x) + (ε / K) * (exp (K * x) - 1)`.
Then we use this inequality to prove some estimates on the possible rate of growth of the distance
between two approximate or exact solutions of an ordinary differential equation.
The proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*,
Sec. 4.5][HubbardWest-ode], where `norm_le_gronwallBound_of_norm_deriv_right_le` is called
“Fundamental Inequality”.
## TODO
- Once we have FTC, prove an inequality for a function satisfying `‖f' x‖ ≤ K x * ‖f x‖ + ε`,
or more generally `liminf_{y→x+0} (f y - f x)/(y - x) ≤ K x * f x + ε` with any sign
of `K x` and `f x`.
-/
open Metric Set Asymptotics Filter Real
open scoped Topology NNReal
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
/-! ### Technical lemmas about `gronwallBound` -/
/-- Upper bound used in several Grönwall-like inequalities. -/
noncomputable def gronwallBound (δ K ε x : ℝ) : ℝ :=
if K = 0 then δ + ε * x else δ * exp (K * x) + ε / K * (exp (K * x) - 1)
theorem gronwallBound_K0 (δ ε : ℝ) : gronwallBound δ 0 ε = fun x => δ + ε * x :=
funext fun _ => if_pos rfl
theorem gronwallBound_of_K_ne_0 {δ K ε : ℝ} (hK : K ≠ 0) :
gronwallBound δ K ε = fun x => δ * exp (K * x) + ε / K * (exp (K * x) - 1) :=
funext fun _ => if_neg hK
theorem hasDerivAt_gronwallBound (δ K ε x : ℝ) :
HasDerivAt (gronwallBound δ K ε) (K * gronwallBound δ K ε x + ε) x := by
by_cases hK : K = 0
· subst K
simp only [gronwallBound_K0, zero_mul, zero_add]
convert ((hasDerivAt_id x).const_mul ε).const_add δ
rw [mul_one]
· simp only [gronwallBound_of_K_ne_0 hK]
convert (((hasDerivAt_id x).const_mul K).exp.const_mul δ).add
((((hasDerivAt_id x).const_mul K).exp.sub_const 1).const_mul (ε / K)) using 1
simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel₀ _ hK]
ring
theorem hasDerivAt_gronwallBound_shift (δ K ε x a : ℝ) :
HasDerivAt (fun y => gronwallBound δ K ε (y - a)) (K * gronwallBound δ K ε (x - a) + ε) x := by
convert (hasDerivAt_gronwallBound δ K ε _).comp x ((hasDerivAt_id x).sub_const a) using 1
rw [id, mul_one]
theorem gronwallBound_x0 (δ K ε : ℝ) : gronwallBound δ K ε 0 = δ := by
by_cases hK : K = 0
· simp only [gronwallBound, if_pos hK, mul_zero, add_zero]
· simp only [gronwallBound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one,
add_zero]
| Mathlib/Analysis/ODE/Gronwall.lean | 73 | 76 | theorem gronwallBound_ε0 (δ K x : ℝ) : gronwallBound δ K 0 x = δ * exp (K * x) := by | by_cases hK : K = 0
· simp only [gronwallBound_K0, hK, zero_mul, exp_zero, add_zero, mul_one]
· simp only [gronwallBound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] |
/-
Copyright (c) 2021 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer
-/
import Mathlib.LinearAlgebra.Basis.Basic
import Mathlib.LinearAlgebra.DirectSum.Finsupp
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
import Mathlib.LinearAlgebra.FreeModule.Basic
/-!
# Bases and dimensionality of tensor products of modules
This file defines various bases on the tensor product of modules,
and shows that the tensor product of free modules is again free.
-/
noncomputable section
open Set LinearMap Submodule
open scoped TensorProduct
section CommSemiring
variable {R : Type*} {S : Type*} {M : Type*} {N : Type*} {ι : Type*} {κ : Type*}
[CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M]
[IsScalarTower R S M] [AddCommMonoid N] [Module R N]
/-- If `b : ι → M` and `c : κ → N` are bases then so is `fun i ↦ b i.1 ⊗ₜ c i.2 : ι × κ → M ⊗ N`. -/
def Basis.tensorProduct (b : Basis ι S M) (c : Basis κ R N) :
Basis (ι × κ) S (M ⊗[R] N) :=
Finsupp.basisSingleOne.map
((TensorProduct.AlgebraTensorModule.congr b.repr c.repr).trans <|
(finsuppTensorFinsupp R S _ _ _ _).trans <|
Finsupp.lcongr (Equiv.refl _) (TensorProduct.AlgebraTensorModule.rid R S S)).symm
@[simp]
theorem Basis.tensorProduct_apply (b : Basis ι S M) (c : Basis κ R N) (i : ι) (j : κ) :
Basis.tensorProduct b c (i, j) = b i ⊗ₜ c j := by
simp [Basis.tensorProduct]
| Mathlib/LinearAlgebra/TensorProduct/Basis.lean | 44 | 46 | theorem Basis.tensorProduct_apply' (b : Basis ι S M) (c : Basis κ R N) (i : ι × κ) :
Basis.tensorProduct b c i = b i.1 ⊗ₜ c i.2 := by | simp [Basis.tensorProduct] |
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Data.Set.Finite.Powerset
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = ENat.card α := by
rw [encard, ENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
@[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl
theorem toENat_cardinalMk_subtype (P : α → Prop) :
(Cardinal.mk {x // P x}).toENat = {x | P x}.encard :=
rfl
@[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by
simp [encard_eq_coe_toFinset_card]
@[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) :
encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
@[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
simp [encard, ENat.card_congr (Equiv.Set.union h)]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
induction s, h using Set.Finite.induction_on with
| empty => simp
| insert hat _ ht' =>
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
@[simp]
theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by
simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)]
section Lattice
theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
@[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_encard
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_inj h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts
theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le)
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_encard inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_eq_add_one_iff {k : ℕ∞} :
s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩
rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h,
encard_diff_singleton_add_one ha]
rintro ⟨a, t, h, rfl, rfl⟩
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
(s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq)))
rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one
end InsertErase
section SmallSets
theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
WithTop.add_right_inj WithTop.one_ne_top, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩
theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
encard_eq_one]
theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
refine ⟨fun h a b has hbs ↦ ?_,
fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
obtain ⟨x, rfl⟩ := h ⟨_, has⟩
rw [(has : a = x), (hbs : b = x)]
theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by
rw [encard_le_one_iff, Set.Subsingleton]
tauto
theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by
rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton]
theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
by_contra! h'
obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
apply hne
rw [h' b hb, h' b' hb']
theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h
obtain ⟨y, h⟩ := h
refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩
rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
theorem encard_eq_three {α : Type u_1} {s : Set α} :
encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩
· obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton,
encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h
obtain ⟨y, z, hne, hs⟩ := h
refine ⟨x, y, z, ?_, ?_, hne, ?_⟩
· rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
· rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
rw [← hs, insert_diff_singleton, insert_eq_of_mem hx]
rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1
· rw [Finset.coe_range, Iio_def]
rw [Finset.card_range]
end SmallSets
theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
(hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne,
encard_eq_one] at hst
obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
revert hk
refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_
· obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
simp only [Nat.cast_succ] at *
have hne : t₀ ≠ s := by
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
simp only [top_le_iff, encard_eq_top_iff]
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
theorem exists_superset_subset_encard_eq {k : ℕ∞}
(hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
obtain (hs | hs) := eq_or_ne s.encard ⊤
· rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
obtain ⟨k, rfl⟩ := exists_add_of_le hsk
obtain ⟨k', hk'⟩ := exists_add_of_le hkt
have hk : k ≤ encard (t \ s) := by
rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
exact WithTop.le_of_add_le_add_right hs hkt
obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩
rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
section Function
variable {s : Set α} {t : Set β} {f : α → β}
theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
rw [encard, ENat.card_image_of_injOn h, encard]
theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e]
theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) :
(f '' s).encard = s.encard :=
hf.injOn.encard_image
theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by
rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
exact encard_mono (by simp)
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
obtain (h | h) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image]
apply encard_le_encard
exact f.invFunOn_image_image_subset s
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
InjOn f s := by
obtain (h' | hne) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image] at h
rw [injOn_iff_invFunOn_image_image_eq_self]
exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le
theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) :
(f ⁻¹' t).encard = t.encard := by
rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht]
lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard :=
encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq])
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
s.encard ≤ t.encard := by
rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx
theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
(hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
classical
obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt
· simp
· exact (encard_ne_top_iff.mpr hs h).elim
obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by
rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle'
simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s
use Function.update f₀ a b
rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def,
mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
· rintro x hx; split_ifs with h
· assumption
· exact (hf₀s x hx h).1
exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne])
termination_by encard s
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
∃ (f : α → β), BijOn f s t := by
obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
convert hinj.bijOn_image
rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf)
(h.symm.trans hinj.encard_image.symm).le]
end Function
section ncard
open Nat
/-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite`
term. -/
syntax "toFinite_tac" : tactic
macro_rules
| `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite)
/-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/
syntax "to_encard_tac" : tactic
macro_rules
| `(tactic| to_encard_tac) => `(tactic|
simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one])
/-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/
noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard
theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl
theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]
lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
obtain (h | h) := s.finite_or_infinite
· have := h.fintype
rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
toFinite_toFinset, toFinset_card, ENat.toNat_coe]
have := infinite_coe_iff.2 h
rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top]
theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
s.ncard = hs.toFinset.card := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
@Finite.card_toFinset _ _ hs.fintype hs]
theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
s.ncard = s.toFinset.card := by
simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
lemma cast_ncard {s : Set α} (hs : s.Finite) :
(s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
rw [encard_le_coe_iff, and_congr_right_iff]
exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe],
fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
@[gcongr]
theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
s.ncard ≤ t.ncard := by
rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
exact encard_mono hst
theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard
@[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
s.ncard = 0 ↔ s = ∅ := by
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
@[simp, norm_cast] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
rcases finite_or_infinite α with h | h
· have hft := Fintype.ofFinite α
rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
rw [Nat.card_eq_zero_of_infinite, Infinite.ncard]
exact infinite_univ
@[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by
rw [ncard_eq_zero]
theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty]
protected alias ⟨_, Nonempty.ncard_pos⟩ := ncard_pos
theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 :=
((ncard_pos hs).mpr ⟨a, h⟩).ne.symm
theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim
theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
finite_of_ncard_ne_zero hs.ne.symm
theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs
@[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by
simp [ncard]
theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
apply encard_singleton_inter
@[simp]
theorem ncard_prod : (s ×ˢ t).ncard = s.ncard * t.ncard := by
simp [ncard, ENat.toNat_mul]
@[simp]
theorem ncard_powerset (s : Set α) (hs : s.Finite := by toFinite_tac) :
(𝒫 s).ncard = 2 ^ s.ncard := by
have h := Cardinal.mk_powerset s
rw [← cast_ncard hs.powerset, ← cast_ncard hs] at h
norm_cast at h
section InsertErase
@[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
(insert a s).ncard = s.ncard + 1 := by
rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
hs.cast_ncard_eq, encard_insert_of_not_mem h]
theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by
rw [insert_eq_of_mem h]
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
obtain hs | hs := s.finite_or_infinite
· to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le
rw [(hs.mono (subset_insert a s)).ncard]
exact Nat.zero_le _
theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by
by_cases h : a ∈ s
· rw [ncard_insert_of_mem h, if_pos h]
· rw [ncard_insert_of_not_mem h hs, if_neg h]
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
classical
refine
s.finite_or_infinite.elim (fun h ↦ ?_) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
rw [ncard_insert_eq_ite h]; split_ifs <;> simp
@[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
rw [ncard_insert_of_not_mem, ncard_singleton]; simpa
@[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s)
(hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, hs.diff.cast_ncard_eq,
encard_diff_singleton_add_one h]
@[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
(s \ {a}).ncard = s.ncard - 1 :=
eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs)
theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
(s \ {a}).ncard < s.ncard := by
rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
obtain hs | hs := s.finite_or_infinite
· apply ncard_le_ncard diff_subset hs
convert zero_le (α := ℕ) _
exact (hs.diff (by simp : Set.Finite {a})).ncard
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
rcases s.finite_or_infinite with hs | hs
· by_cases h : a ∈ s
· rw [ncard_diff_singleton_of_mem h hs]
rw [diff_singleton_eq_self h]
apply Nat.pred_le
convert Nat.zero_le _
rw [hs.ncard]
theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard :=
congr_arg ENat.toNat <| encard_exchange ha hb
theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) :
(insert a s \ {b}).ncard = s.ncard := by
rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib,
@diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])]
lemma odd_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) :
Odd (insert a s).ncard ↔ Even s.ncard := by
rw [ncard_insert_of_not_mem ha hs, Nat.odd_add]
simp only [Nat.odd_add, ← Nat.not_even_iff_odd, Nat.not_even_one, iff_false, Decidable.not_not]
lemma even_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) :
Even (insert a s).ncard ↔ Odd s.ncard := by
rw [ncard_insert_of_not_mem ha hs, Nat.even_add_one, Nat.not_even_iff_odd]
end InsertErase
variable {f : α → β}
theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le
theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
congr_arg ENat.toNat <| H.encard_image
theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) :
Set.InjOn f s := by
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h
exact hs.injOn_of_encard_image_eq h
theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) :
(f '' s).ncard = s.ncard ↔ Set.InjOn f s :=
⟨fun h ↦ injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩
theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
ncard_image_of_injOn fun _ _ _ _ h ↦ H h
theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective)
(hs : s ⊆ Set.range f) :
(f ⁻¹' s).ncard = s.ncard := by
rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite_tac) :
{ x ∈ s | f x = y }.ncard ≠ 0 ↔ y ∈ f '' s := by
refine ⟨nonempty_of_ncard_ne_zero, ?_⟩
rintro ⟨z, hz, rfl⟩
exact @ncard_ne_zero_of_mem _ ({ x ∈ s | f x = f z }) z (mem_sep hz rfl)
(hs.subset (sep_subset _ _))
@[simp] theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
ncard_image_of_injective _ f.inj'
@[simp] theorem ncard_subtype (P : α → Prop) (s : Set α) :
{ x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard := by
convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
ext x
simp [← and_assoc, exists_eq_right]
theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) :
(s ∩ t).ncard ≤ s.ncard :=
ncard_le_ncard inter_subset_left hs
theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_tac) :
(s ∩ t).ncard ≤ t.ncard :=
ncard_le_ncard inter_subset_right ht
theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
(ht : t.Finite := by toFinite_tac) : s = t :=
ht.eq_of_subset_of_encard_le' h
(by rwa [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h')
theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) :
s ⊆ t ↔ s = t :=
⟨fun hst ↦ eq_of_subset_of_ncard_le hst h ht, Eq.subset'⟩
theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s) (hs : s.Finite := by toFinite_tac) :
f '' s = s :=
eq_of_subset_of_ncard_le h (ncard_map _).ge hs
theorem sep_of_ncard_eq {a : α} {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s)
(hs : s.Finite := by toFinite_tac) : P a :=
sep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha
theorem ncard_lt_ncard (h : s ⊂ t) (ht : t.Finite := by toFinite_tac) :
s.ncard < t.ncard := by
rw [← Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq]
exact (ht.subset h.subset).encard_lt_encard h
theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard :=
fun _ _ h ↦ ncard_lt_ncard h
theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
(hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s)
(f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : s.ncard = n := by
let f' : Fin n → α := fun i ↦ f i.val i.is_lt
suffices himage : s = f' '' Set.univ by
rw [← Fintype.card_fin n, ← Nat.card_eq_fintype_card, ← Set.ncard_univ, himage]
exact ncard_image_of_injOn <| fun i _hi j _hj h ↦ Fin.ext <| f_inj i.val j.val i.is_lt j.is_lt h
ext x
simp only [image_univ, mem_range]
refine ⟨fun hx ↦ ?_, fun ⟨⟨i, hi⟩, hx⟩ ↦ hx ▸ hf' i hi⟩
obtain ⟨i, hi, rfl⟩ := hf x hx
use ⟨i, hi⟩
theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t)
(h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) :
s.ncard = t.ncard := by
set f' : s → t := fun x ↦ ⟨f x.1 x.2, h₁ _ _⟩
have hbij : f'.Bijective := by
constructor
· rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
simp only [f', Subtype.mk.injEq] at hxy ⊢
exact h₂ _ _ hx hy hxy
rintro ⟨y, hy⟩
obtain ⟨a, ha, rfl⟩ := h₃ y hy
simp only [Subtype.mk.injEq, Subtype.exists]
exact ⟨_, ha, rfl⟩
simp_rw [← Nat.card_coe_set_eq]
exact Nat.card_congr (Equiv.ofBijective f' hbij)
theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s)
(ht : t.Finite := by toFinite_tac) :
s.ncard ≤ t.ncard := by
have hle := encard_le_encard_of_injOn hf f_inj
to_encard_tac; rwa [ht.cast_ncard_eq, (ht.finite_of_encard_le hle).cast_ncard_eq]
theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β}
(hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) :
∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
by_contra h'
simp only [Ne, exists_prop, not_exists, not_and, not_imp_not] at h'
exact (ncard_le_ncard_of_injOn f hf h' ht).not_lt hc
theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i ∈ s)
(f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) (hs : s.Finite := by toFinite_tac) :
n ≤ s.ncard := by
rw [ncard_eq_toFinset_card _ hs]
apply Finset.le_card_of_inj_on_range <;> simpa
theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard)
(ht : t.Finite := by toFinite_tac) :
∀ b ∈ t, ∃ a ha, b = f a ha := by
intro b hb
set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩
have finj : f'.Injective := by
rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
simp only [f', Subtype.mk.injEq] at hxy ⊢
apply hinj _ _ hx hy hxy
have hft := ht.fintype
have hft' := Fintype.ofInjective f' finj
set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ _ (by simpa) using 1
· simp [f'']
· simp [f'', hf]
· intros a₁ a₂ ha₁ ha₂ h
rw [mem_toFinset] at ha₁ ha₂
exact hinj _ _ ha₁ ha₂ h
rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card']
theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hsurj : ∀ b ∈ t, ∃ a ha, f a ha = b) (hst : s.ncard ≤ t.ncard) ⦃a₁⦄ (ha₁ : a₁ ∈ s) ⦃a₂⦄
(ha₂ : a₂ ∈ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂) (hs : s.Finite := by toFinite_tac) :
a₁ = a₂ := by
classical
set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩
have hsurj : f'.Surjective := by
rintro ⟨y, hy⟩
obtain ⟨a, ha, rfl⟩ := hsurj y hy
simp only [Subtype.mk.injEq, Subtype.exists]
exact ⟨_, ha, rfl⟩
haveI := hs.fintype
haveI := Fintype.ofSurjective _ hsurj
set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
exact
@Finset.inj_on_of_surj_on_of_card_le _ _ _ t.toFinset f''
(fun a ha ↦ by { rw [mem_toFinset] at ha ⊢; exact hf a ha }) (by simpa)
(by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁
(by simpa) a₂ (by simpa) (by simpa)
@[simp] theorem ncard_coe {α : Type*} (s : Set α) :
Set.ncard (Set.univ : Set (Set.Elem s)) = s.ncard :=
Set.ncard_congr (fun a ha ↦ ↑a) (fun a ha ↦ a.prop) (by simp) (by simp)
@[simp] lemma ncard_graphOn (s : Set α) (f : α → β) : (s.graphOn f).ncard = s.ncard := by
rw [← ncard_image_of_injOn fst_injOn_graph, image_fst_graphOn]
section Lattice
theorem ncard_union_add_ncard_inter (s t : Set α) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq,
(hs.subset inter_subset_left).cast_ncard_eq, encard_union_add_encard_inter]
theorem ncard_inter_add_ncard_union (s t : Set α) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : (s ∩ t).ncard + (s ∪ t).ncard = s.ncard + t.ncard := by
rw [add_comm, ncard_union_add_ncard_inter _ _ hs ht]
theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
obtain (h | h) := (s ∪ t).finite_or_infinite
· to_encard_tac
rw [h.cast_ncard_eq, (h.subset subset_union_left).cast_ncard_eq,
(h.subset subset_union_right).cast_ncard_eq]
apply encard_union_le
rw [h.ncard]
apply zero_le
theorem ncard_union_eq (h : Disjoint s t) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard = s.ncard + t.ncard := by
to_encard_tac
rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, encard_union_eq h]
theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
(t \ s).ncard + s.ncard = t.ncard := by
to_encard_tac
rw [ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq, ht.diff.cast_ncard_eq,
encard_diff_add_encard_of_subset h]
theorem ncard_diff (hst : s ⊆ t) (hs : s.Finite := by toFinite_tac) :
(t \ s).ncard = t.ncard - s.ncard := by
obtain ht | ht := t.finite_or_infinite
· rw [← ncard_diff_add_ncard_of_subset hst ht, add_tsub_cancel_right]
· rw [ht.ncard, Nat.zero_sub, (ht.diff hs).ncard]
lemma cast_ncard_sdiff {R : Type*} [AddGroupWithOne R] (hst : s ⊆ t) (ht : t.Finite) :
((t \ s).ncard : R) = t.ncard - s.ncard := by
rw [ncard_diff hst (ht.subset hst), Nat.cast_sub (ncard_le_ncard hst ht)]
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
s.ncard ≤ (s \ t).ncard + t.ncard := by
rcases s.finite_or_infinite with hs | hs
· to_encard_tac
rw [ht.cast_ncard_eq, hs.cast_ncard_eq, hs.diff.cast_ncard_eq]
apply encard_le_encard_diff_add_encard
convert Nat.zero_le _
rw [hs.ncard]
theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) :
t.ncard - s.ncard ≤ (t \ s).ncard :=
tsub_le_iff_left.mpr (by rw [add_comm]; apply ncard_le_ncard_diff_add_ncard _ _ hs)
theorem ncard_diff_add_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) :
(s \ t).ncard + t.ncard = (s ∪ t).ncard := by
rw [← ncard_union_eq disjoint_sdiff_left hs.diff ht, diff_union_self]
theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) :
(t \ s).Nonempty := by
rw [Set.nonempty_iff_ne_empty, Ne, diff_eq_empty]
exact fun h' ↦ h.not_le (ncard_le_ncard h' hs)
theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
(hs : s.Finite := by toFinite_tac) : ∃ e, e ∈ t ∧ e ∉ s :=
diff_nonempty_of_ncard_lt_ncard h hs
@[simp] theorem ncard_inter_add_ncard_diff_eq_ncard (s t : Set α)
(hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard + (s \ t).ncard = s.ncard := by
rw [← ncard_union_eq (disjoint_of_subset_left inter_subset_right disjoint_sdiff_right)
(hs.inter_of_left _) hs.diff, union_comm, diff_union_inter]
| Mathlib/Data/Set/Card.lean | 916 | 919 | theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.Finite := by | toFinite_tac)
(ht : t.Finite := by toFinite_tac) : s.ncard = t.ncard ↔ (s \ t).ncard = (t \ s).ncard := by
rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht,
inter_comm, add_right_inj] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell
-/
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Order.Monotone.Defs
/-!
# Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
For the lemma that `n.choose k` counts the `k`-element-subsets of an `n`-element set,
see `Fintype.card_powersetCard` in `Mathlib.Data.Finset.Powerset`.
## Main definition and results
* `Nat.choose`: binomial coefficients, defined inductively
* `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`
* `Nat.choose_symm`: symmetry of binomial coefficients
* `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`
* `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`
* `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending
factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements
for the ascending factorial.
* `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations.
The fact that this is indeed the correct counting function for multisets is proved in
`Sym.card_sym_eq_multichoose` in `Data.Sym.Card`.
* `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`.
This is central to the "stars and bars" technique in informal mathematics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail.
## Tags
binomial coefficient, combination, multicombination, stars and bars
-/
open Nat
namespace Nat
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
coefficients. For the fact that this is the number of `k`-element-subsets of an `n`-element
set, see `Fintype.card_powersetCard`. -/
def choose : ℕ → ℕ → ℕ
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 => choose n k + choose n (k + 1)
@[simp]
theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl
@[simp]
theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 :=
rfl
theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) :=
rfl
theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) :=
rfl
theorem choose_succ_left (n k : ℕ) (hk : 0 < k) :
choose (n + 1) k = choose n (k - 1) + choose n k := by
obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk
rfl
theorem choose_succ_right (n k : ℕ) (hn : 0 < n) :
choose n (k + 1) = choose (n - 1) k + choose (n - 1) (k + 1) := by
obtain ⟨l, rfl⟩ : ∃ l, n = l + 1 := Nat.exists_eq_add_of_le' hn
rfl
theorem choose_eq_choose_pred_add {n k : ℕ} (hn : 0 < n) (hk : 0 < k) :
choose n k = choose (n - 1) (k - 1) + choose (n - 1) k := by
obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk
rw [choose_succ_right _ _ hn, Nat.add_one_sub_one]
theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0
| _, 0, hk => absurd hk (Nat.not_lt_zero _)
| 0, _ + 1, _ => choose_zero_succ _
| n + 1, k + 1, hk => by
have hnk : n < k := lt_of_succ_lt_succ hk
have hnk1 : n < k + 1 := lt_of_succ_lt hk
rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]
@[simp]
theorem choose_self (n : ℕ) : choose n n = 1 := by
induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]
@[simp]
theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 :=
choose_eq_zero_of_lt (lt_succ_self _)
@[simp]
lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm]
-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number
theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by
rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm]
cases n <;> rfl; apply zero_lt_succ
/-- `choose n 2` is the `n`-th triangle number. -/
theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by
induction' n with n ih
· simp
· rw [triangle_succ n, choose, ih]
simp [Nat.add_comm]
theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k
| 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide
| n + 1, 0, _ => by simp
| _ + 1, _ + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _
theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k :=
⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩
theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k
| 0, 0 => by decide
| 0, k + 1 => by simp [choose]
| n + 1, 0 => by simp [choose, mul_succ, Nat.add_comm]
| n + 1, k + 1 => by
rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ←
succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul]
theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n !
| 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]
| n + 1, 0, _ => by simp
| n + 1, succ k, hk => by
rcases lt_or_eq_of_le hk with hk₁ | hk₁
· have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by
rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ]
have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk)
rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul,
Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc,
← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm]
· rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self]
theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) :
n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=
have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos]
Nat.mul_right_cancel h <|
calc
n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) =
n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by
rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc,
Nat.mul_comm (n - k)!, Nat.mul_comm s !]
_ = n ! := by
rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]
_ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by
rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _),
choose_mul_factorial_mul_factorial (hsk.trans hkn)]
_ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by
rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc,
Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc]
theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) :
choose n k = n ! / (k ! * (n - k)!) := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]
exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm
theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by
rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right,
Nat.mul_comm]
theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) :
(i + j).choose j * i ! * j ! = (i + j)! := by
rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right,
Nat.mul_right_comm]
theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _
theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by
suffices i ! * (i + j - i) ! ∣ (i + j)! by
rwa [Nat.add_sub_cancel_left i j] at this
exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _)
@[simp]
theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by
rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _),
Nat.sub_sub_self hk, Nat.mul_comm]
theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by
suffices choose n (n - b) = choose n b by
rw [h, Nat.add_sub_cancel_right] at this; rwa [h]
exact choose_symm (h ▸ le_add_left _ _)
| Mathlib/Data/Nat/Choose/Basic.lean | 197 | 200 | theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b :=
choose_symm_of_eq_add rfl
theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by | |
/-
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.Ring.Parity
import Mathlib.Combinatorics.SimpleGraph.Path
/-!
# Trails and Eulerian trails
This module contains additional theory about trails, including Eulerian trails (also known
as Eulerian circuits).
## Main definitions
* `SimpleGraph.Walk.IsEulerian` is the predicate that a trail is an Eulerian trail.
* `SimpleGraph.Walk.IsTrail.even_countP_edges_iff` gives a condition on the number of edges
in a trail that can be incident to a given vertex.
* `SimpleGraph.Walk.IsEulerian.even_degree_iff` gives a condition on the degrees of vertices
when there exists an Eulerian trail.
* `SimpleGraph.Walk.IsEulerian.card_odd_degree` gives the possible numbers of odd-degree
vertices when there exists an Eulerian trail.
## TODO
* Prove that there exists an Eulerian trail when the conclusion to
`SimpleGraph.Walk.IsEulerian.card_odd_degree` holds.
## Tags
Eulerian trails
-/
namespace SimpleGraph
variable {V : Type*} {G : SimpleGraph V}
namespace Walk
/-- The edges of a trail as a finset, since each edge in a trail appears exactly once. -/
abbrev IsTrail.edgesFinset {u v : V} {p : G.Walk u v} (h : p.IsTrail) : Finset (Sym2 V) :=
⟨p.edges, h.edges_nodup⟩
variable [DecidableEq V]
theorem IsTrail.even_countP_edges_iff {u v : V} {p : G.Walk u v} (ht : p.IsTrail) (x : V) :
Even (p.edges.countP fun e => x ∈ e) ↔ u ≠ v → x ≠ u ∧ x ≠ v := by
induction p with
| nil => simp
| cons huv p ih =>
rw [cons_isTrail_iff] at ht
specialize ih ht.1
simp only [List.countP_cons, Ne, edges_cons, Sym2.mem_iff]
split_ifs with h
· rw [decide_eq_true_eq] at h
obtain (rfl | rfl) := h
· rw [Nat.even_add_one, ih]
simp only [huv.ne, imp_false, Ne, not_false_iff, true_and, not_forall,
Classical.not_not, exists_prop, eq_self_iff_true, not_true, false_and,
and_iff_right_iff_imp]
rintro rfl rfl
exact G.loopless _ huv
· rw [Nat.even_add_one, ih, ← not_iff_not]
simp only [huv.ne.symm, Ne, eq_self_iff_true, not_true, false_and, not_forall,
not_false_iff, exists_prop, and_true, Classical.not_not, true_and, iff_and_self]
rintro rfl
exact huv.ne
· rw [decide_eq_true_eq, not_or] at h
simp only [h.1, h.2, not_false_iff, true_and, add_zero, Ne] at ih ⊢
rw [ih]
constructor <;>
· rintro h' h'' rfl
simp only [imp_false, eq_self_iff_true, not_true, Classical.not_not] at h'
cases h'
simp only [not_true, and_false, false_and] at h
/-- An *Eulerian trail* (also known as an "Eulerian path") is a walk
`p` that visits every edge exactly once. The lemma `SimpleGraph.Walk.IsEulerian.IsTrail` shows
that these are trails.
Combine with `p.IsCircuit` to get an Eulerian circuit (also known as an "Eulerian cycle"). -/
def IsEulerian {u v : V} (p : G.Walk u v) : Prop :=
∀ e, e ∈ G.edgeSet → p.edges.count e = 1
theorem IsEulerian.isTrail {u v : V} {p : G.Walk u v} (h : p.IsEulerian) : p.IsTrail := by
rw [isTrail_def, List.nodup_iff_count_le_one]
intro e
by_cases he : e ∈ p.edges
· exact (h e (edges_subset_edgeSet _ he)).le
· simp [List.count_eq_zero_of_not_mem he]
theorem IsEulerian.mem_edges_iff {u v : V} {p : G.Walk u v} (h : p.IsEulerian) {e : Sym2 V} :
e ∈ p.edges ↔ e ∈ G.edgeSet :=
⟨ fun h => p.edges_subset_edgeSet h
, fun he => by simpa [Nat.succ_le] using (h e he).ge ⟩
/-- The edge set of an Eulerian graph is finite. -/
def IsEulerian.fintypeEdgeSet {u v : V} {p : G.Walk u v} (h : p.IsEulerian) :
Fintype G.edgeSet :=
Fintype.ofFinset h.isTrail.edgesFinset fun e => by
simp only [Finset.mem_mk, Multiset.mem_coe, h.mem_edges_iff]
theorem IsTrail.isEulerian_of_forall_mem {u v : V} {p : G.Walk u v} (h : p.IsTrail)
(hc : ∀ e, e ∈ G.edgeSet → e ∈ p.edges) : p.IsEulerian := fun e he =>
List.count_eq_one_of_mem h.edges_nodup (hc e he)
theorem isEulerian_iff {u v : V} (p : G.Walk u v) :
p.IsEulerian ↔ p.IsTrail ∧ ∀ e, e ∈ G.edgeSet → e ∈ p.edges := by
constructor
· intro h
exact ⟨h.isTrail, fun _ => h.mem_edges_iff.mpr⟩
· rintro ⟨h, hl⟩
exact h.isEulerian_of_forall_mem hl
| Mathlib/Combinatorics/SimpleGraph/Trails.lean | 119 | 125 | theorem IsEulerian.edgesFinset_eq [Fintype G.edgeSet] {u v : V} {p : G.Walk u v}
(h : p.IsEulerian) : h.isTrail.edgesFinset = G.edgeFinset := by | ext e
simp [h.mem_edges_iff]
theorem IsEulerian.even_degree_iff {x u v : V} {p : G.Walk u v} (ht : p.IsEulerian) [Fintype V]
[DecidableRel G.Adj] : Even (G.degree x) ↔ u ≠ v → x ≠ u ∧ x ≠ v := by |
/-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.Normal.Closure
import Mathlib.RingTheory.AlgebraicIndependent.Adjoin
import Mathlib.RingTheory.AlgebraicIndependent.TranscendenceBasis
import Mathlib.RingTheory.Polynomial.SeparableDegree
import Mathlib.RingTheory.Polynomial.UniqueFactorization
/-!
# Separable degree
This file contains basics about the separable degree of a field extension.
## Main definitions
- `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`
(the algebraic closure of `F` is usually used in the literature, but our definition has the
advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F`
and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks.
- `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an extension `E / F`
of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic
closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense.
**Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E`
for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is
the separable closure of `F` in `E`, which is not defined in this file yet. Later we
will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two
definitions coincide. If `E / F` is algebraic with infinite separable degree, we have
`#(Field.Emb F E) = 2 ^ Field.sepDegree F E` instead.
(See `Field.Emb.cardinal_eq_two_pow_sepDegree` in another file.) For example, if
$F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$
is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to
$\mathbb{Z}_p^\times$, which is uncountable, whereas $ [E:F] $ is countable.
- `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
## Main results
- `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`:
a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. In particular, they have the same cardinality (so their
`Field.finSepDegree` are equal).
- `Field.embEquivOfAdjoinSplits`,
`Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F`
and whose minimal polynomial splits in `K`. In particular, they have the same cardinality.
- `Field.embEquivOfIsAlgClosed`,
`Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed.
In particular, they have the same cardinality.
- `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`:
if `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`.
In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$
(see also `Module.finrank_mul_finrank`).
- `Field.infinite_emb_of_transcendental`: `Field.Emb` is infinite for transcendental extensions.
- `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than
its degree.
- `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is
equal to its degree if and only if it is separable.
- `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree
is equal to the number of distinct roots of it over `E`.
- `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field.
- `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic
`q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree.
- `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable
contraction, then its separable degree is equal to its separable contraction degree.
- `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible
polynomial divides its degree.
- `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of
`F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`.
- `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then
the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a
separable element.
- `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides
the degree of `E / F`.
- `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller
than the degree of `E / F`.
- `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree
is equal to its degree if and only if it is a separable extension.
- `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension
if and only if `x` is a separable element.
- `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also
separable.
## Tags
separable degree, degree, polynomial
-/
open Module Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
namespace Field
/-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure
of `E`. -/
abbrev Emb := E →ₐ[F] AlgebraicClosure E
/-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F`
is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`,
as a natural number. It is defined to be zero if there are infinitely many of them.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/
def finSepDegree : ℕ := Nat.card (Emb F E)
instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩
instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) :=
⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩
/-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. -/
def embEquivOfEquiv (i : E ≃ₐ[F] K) :
Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by
let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra
have : Algebra.IsAlgebraic E K := by
constructor
intro x
have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x)
rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h
simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h
apply AlgEquiv.restrictScalars (R := F) (S := E)
exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree`
over `F`. -/
theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i)
@[simp]
theorem finSepDegree_self : finSepDegree F F = 1 := by
have : Cardinal.mk (Emb F F) = 1 := le_antisymm
(Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton)
(Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _)
rw [finSepDegree, Nat.card, this, Cardinal.one_toNat]
end Field
namespace IntermediateField
@[simp]
theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by
rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self]
section Tower
variable {F}
variable [Algebra E K] [IsScalarTower F E K]
@[simp]
theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E :=
finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
@[simp]
theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K :=
finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
end Tower
end IntermediateField
namespace Field
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every
element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`.
Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of
`IntermediateField.nonempty_algHom_of_adjoin_splits`. -/
def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
Emb F E ≃ (E →ₐ[F] K) :=
have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) :=
(hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1)
have halg := (topEquiv (F := F) (E := E)).isAlgebraic
Classical.choice <| Function.Embedding.antisymm
(halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F E (S := S) hK (hS ▸ mem_top)) _)
(halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _)
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K`
if `E = F(S)` such that every element
`s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/
theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK)
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic
and `K / F` is algebraically closed. -/
def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
Emb F E ≃ (E →ₐ[F] K) :=
embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦
⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number,
when `E / F` is algebraic and `K / F` is algebraically closed. -/
@[stacks 09HJ "We use `finSepDegree` to state a more general result."]
theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K)
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection
`Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/
def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
Emb F E × Emb E K ≃ Emb F K :=
let e : ∀ f : E →ₐ[F] AlgebraicClosure K,
@AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦
(@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm
(algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans
(Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <|
fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <|
(IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K)
(AlgebraicClosure E)).restrictScalars F).symm
/-- If the field extension `E / F` is transcendental, then `Field.Emb F E` is infinite. -/
instance infinite_emb_of_transcendental [H : Algebra.Transcendental F E] : Infinite (Emb F E) := by
obtain ⟨ι, x, hx⟩ := exists_isTranscendenceBasis' F E
have := hx.isAlgebraic_field
rw [← (embProdEmbOfIsAlgebraic F (adjoin F (Set.range x)) E).infinite_iff]
refine @Prod.infinite_of_left _ _ ?_ _
rw [← (embEquivOfEquiv _ _ _ hx.1.aevalEquivField).infinite_iff]
obtain ⟨i⟩ := hx.nonempty_iff_transcendental.2 H
let K := FractionRing (MvPolynomial ι F)
let i1 := IsScalarTower.toAlgHom F (MvPolynomial ι F) (AlgebraicClosure K)
have hi1 : Function.Injective i1 := by
rw [IsScalarTower.coe_toAlgHom', IsScalarTower.algebraMap_eq _ K]
exact (algebraMap K (AlgebraicClosure K)).injective.comp (IsFractionRing.injective _ _)
let f (n : ℕ) : Emb F K := IsFractionRing.liftAlgHom
(g := i1.comp <| MvPolynomial.aeval fun i : ι ↦ MvPolynomial.X i ^ (n + 1)) <| hi1.comp <| by
simpa [algebraicIndependent_iff_injective_aeval] using
MvPolynomial.algebraicIndependent_polynomial_aeval_X _
fun i : ι ↦ (Polynomial.transcendental_X F).pow n.succ_pos
refine Infinite.of_injective f fun m n h ↦ ?_
replace h : (MvPolynomial.X i) ^ (m + 1) = (MvPolynomial.X i) ^ (n + 1) := hi1 <| by
simpa [f, -map_pow] using congr($h (algebraMap _ K (MvPolynomial.X (R := F) i)))
simpa using congr(MvPolynomial.totalDegree $h)
/-- If the field extension `E / F` is transcendental, then `Field.finSepDegree F E = 0`, which
actually means that `Field.Emb F E` is infinite (see `Field.infinite_emb_of_transcendental`). -/
theorem finSepDegree_eq_zero_of_transcendental [Algebra.Transcendental F E] :
finSepDegree F E = 0 := Nat.card_eq_zero_of_infinite
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their
separable degrees satisfy the tower law
$[E:F]_s [K:E]_s = [K:F]_s$. See also `Module.finrank_mul_finrank`. -/
@[stacks 09HK "Part 1, `finSepDegree` variant"]
theorem finSepDegree_mul_finSepDegree_of_isAlgebraic
[Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
finSepDegree F E * finSepDegree E K = finSepDegree F K := by
simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K)
end Field
namespace Polynomial
variable {F E}
variable (f : F[X])
open Classical in
/-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable
degree of `0` is `0`, not negative infinity. -/
def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card
/-- The separable degree of a polynomial is smaller than its degree. -/
theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by
have := f.map (algebraMap F f.SplittingField) |>.card_roots'
rw [← aroots_def, natDegree_map] at this
classical
exact (f.aroots f.SplittingField).toFinset_card_le.trans this
@[simp]
theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton]
@[simp]
theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton]
/-- A constant polynomial has zero separable degree. -/
theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by
linarith only [natSepDegree_le_natDegree f, h]
@[simp]
theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _)
@[simp]
theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by
rw [← C_0, natSepDegree_C]
@[simp]
theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by
rw [← C_1, natSepDegree_C]
/-- A non-constant polynomial has non-zero separable degree. -/
theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by
rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty]
use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)
classical
rw [Multiset.mem_toFinset, mem_aroots]
exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩
/-- A polynomial has zero separable degree if and only if it is constant. -/
theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 :=
⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩
/-- A polynomial has non-zero separable degree if and only if it is non-constant. -/
theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 :=
Iff.not <| natSepDegree_eq_zero_iff f
/-- The separable degree of a non-zero polynomial is equal to its degree if and only if
it is separable. -/
theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) :
f.natSepDegree = f.natDegree ↔ f.Separable := by
classical
simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f),
rootSet_def, Finset.coe_sort_coe, Fintype.card_coe]
rfl
/-- If a polynomial is separable, then its separable degree is equal to its degree. -/
theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) :
f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h
variable {f} in
/-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of
dot notation. -/
theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) :
f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h
/-- If a polynomial splits over `E`, then its separable degree is equal to
the number of distinct roots of it over `E`. -/
theorem natSepDegree_eq_of_splits [DecidableEq E] (h : f.Splits (algebraMap F E)) :
f.natSepDegree = (f.aroots E).toFinset.card := by
classical
rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map,
roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f),
Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree]
variable (E) in
/-- The separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field. -/
theorem natSepDegree_eq_of_isAlgClosed [DecidableEq E] [IsAlgClosed E] :
f.natSepDegree = (f.aroots E).toFinset.card :=
natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f)
theorem natSepDegree_map (f : E[X]) (i : E →+* K) : (f.map i).natSepDegree = f.natSepDegree := by
classical
let _ := i.toAlgebra
simp_rw [show i = algebraMap E K by rfl, natSepDegree_eq_of_isAlgClosed (AlgebraicClosure K),
aroots_def, map_map, ← IsScalarTower.algebraMap_eq]
@[simp]
theorem natSepDegree_C_mul {x : F} (hx : x ≠ 0) :
(C x * f).natSepDegree = f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_C_mul _ hx]
@[simp]
theorem natSepDegree_smul_nonzero {x : F} (hx : x ≠ 0) :
(x • f).natSepDegree = f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_smul_nonzero _ hx]
@[simp]
theorem natSepDegree_pow {n : ℕ} : (f ^ n).natSepDegree = if n = 0 then 0 else f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_pow]
by_cases h : n = 0
· simp only [h, zero_smul, Multiset.toFinset_zero, Finset.card_empty, ite_true]
simp only [h, Multiset.toFinset_nsmul _ n h, ite_false]
theorem natSepDegree_pow_of_ne_zero {n : ℕ} (hn : n ≠ 0) :
(f ^ n).natSepDegree = f.natSepDegree := by simp_rw [natSepDegree_pow, hn, ite_false]
theorem natSepDegree_X_pow {n : ℕ} : (X ^ n : F[X]).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_pow, natSepDegree_X]
theorem natSepDegree_X_sub_C_pow {x : F} {n : ℕ} :
((X - C x) ^ n).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_pow, natSepDegree_X_sub_C]
theorem natSepDegree_C_mul_X_sub_C_pow {x y : F} {n : ℕ} (hx : x ≠ 0) :
(C x * (X - C y) ^ n).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_C_mul _ hx, natSepDegree_X_sub_C_pow]
theorem natSepDegree_mul (g : F[X]) :
(f * g).natSepDegree ≤ f.natSepDegree + g.natSepDegree := by
by_cases h : f * g = 0
· simp only [h, natSepDegree_zero, zero_le]
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add]
exact Finset.card_union_le _ _
theorem natSepDegree_mul_eq_iff (g : F[X]) :
(f * g).natSepDegree = f.natSepDegree + g.natSepDegree ↔ (f = 0 ∧ g = 0) ∨ IsCoprime f g := by
by_cases h : f * g = 0
· rw [mul_eq_zero] at h
wlog hf : f = 0 generalizing f g
· simpa only [mul_comm, add_comm, and_comm,
isCoprime_comm] using this g f h.symm (h.resolve_left hf)
rw [hf, zero_mul, natSepDegree_zero, zero_add, isCoprime_zero_left, isUnit_iff, eq_comm,
natSepDegree_eq_zero_iff, natDegree_eq_zero]
refine ⟨fun ⟨x, h⟩ ↦ ?_, ?_⟩
· by_cases hx : x = 0
· exact .inl ⟨rfl, by rw [← h, hx, map_zero]⟩
exact .inr ⟨x, Ne.isUnit hx, h⟩
rintro (⟨-, h⟩ | ⟨x, -, h⟩)
· exact ⟨0, by rw [h, map_zero]⟩
exact ⟨x, h⟩
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add,
Finset.card_union_eq_card_add_card, Finset.disjoint_iff_ne, Multiset.mem_toFinset, mem_aroots]
rw [mul_eq_zero, not_or] at h
refine ⟨fun H ↦ .inr (isCoprime_of_irreducible_dvd (not_and.2 fun _ ↦ h.2)
fun u hu ⟨v, hf⟩ ⟨w, hg⟩ ↦ ?_), ?_⟩
· obtain ⟨x, hx⟩ := IsAlgClosed.exists_aeval_eq_zero
(AlgebraicClosure F) _ (degree_pos_of_irreducible hu).ne'
exact H x ⟨h.1, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hf)⟩
x ⟨h.2, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hg)⟩ rfl
rintro (⟨rfl, rfl⟩ | hc)
· exact (h.1 rfl).elim
rintro x hf _ hg rfl
obtain ⟨u, v, hfg⟩ := hc
simpa only [map_add, map_mul, map_one, hf.2, hg.2, mul_zero, add_zero,
zero_ne_one] using congr(aeval x $hfg)
theorem natSepDegree_mul_of_isCoprime (g : F[X]) (hc : IsCoprime f g) :
(f * g).natSepDegree = f.natSepDegree + g.natSepDegree :=
(natSepDegree_mul_eq_iff f g).2 (.inr hc)
theorem natSepDegree_le_of_dvd (g : F[X]) (h1 : f ∣ g) (h2 : g ≠ 0) :
f.natSepDegree ≤ g.natSepDegree := by
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F)]
exact Finset.card_le_card <| Multiset.toFinset_subset.mpr <|
Multiset.Le.subset <| roots.le_of_dvd (map_ne_zero h2) <| map_dvd _ h1
/-- If a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f`
and `f` have the same separable degree. -/
theorem natSepDegree_expand (q : ℕ) [hF : ExpChar F q] {n : ℕ} :
(expand F (q ^ n) f).natSepDegree = f.natSepDegree := by
obtain - | hprime := hF
· simp only [one_pow, expand_one]
haveI := Fact.mk hprime
classical
simpa only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_def, map_expand,
Fintype.card_coe] using Fintype.card_eq.2
⟨(f.map (algebraMap F (AlgebraicClosure F))).rootsExpandPowEquivRoots q n⟩
theorem natSepDegree_X_pow_char_pow_sub_C (q : ℕ) [ExpChar F q] (n : ℕ) (y : F) :
(X ^ q ^ n - C y).natSepDegree = 1 := by
rw [← expand_X, ← expand_C (q ^ n), ← map_sub, natSepDegree_expand, natSepDegree_X_sub_C]
variable {f} in
/-- If `g` is a separable contraction of `f`, then the separable degree of `f` is equal to
the degree of `g`. -/
theorem IsSeparableContraction.natSepDegree_eq {g : Polynomial F} {q : ℕ} [ExpChar F q]
(h : IsSeparableContraction q f g) : f.natSepDegree = g.natDegree := by
obtain ⟨h1, m, h2⟩ := h
rw [← h2, natSepDegree_expand, h1.natSepDegree_eq_natDegree]
variable {f} in
/-- If a polynomial has separable contraction, then its separable degree is equal to the degree of
the given separable contraction. -/
theorem HasSeparableContraction.natSepDegree_eq
{q : ℕ} [ExpChar F q] (hf : f.HasSeparableContraction q) :
f.natSepDegree = hf.degree := hf.isSeparableContraction.natSepDegree_eq
end Polynomial
namespace Irreducible
variable {F}
variable {f : F[X]}
/-- The separable degree of an irreducible polynomial divides its degree. -/
theorem natSepDegree_dvd_natDegree (h : Irreducible f) :
f.natSepDegree ∣ f.natDegree := by
obtain ⟨q, _⟩ := ExpChar.exists F
have hf := h.hasSeparableContraction q
rw [hf.natSepDegree_eq]
exact hf.dvd_degree
/-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one if and only if it is of the form `Polynomial.expand F (q ^ n) (X - C y)`
for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_of_monic' (q : ℕ) [ExpChar F q] (hm : f.Monic)
(hi : Irreducible f) : f.natSepDegree = 1 ↔
∃ (n : ℕ) (y : F), f = expand F (q ^ n) (X - C y) := by
refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩
· obtain ⟨g, h1, n, rfl⟩ := hi.hasSeparableContraction q
have h2 : g.natDegree = 1 := by
rwa [natSepDegree_expand _ q, h1.natSepDegree_eq_natDegree] at h
rw [((monic_expand_iff <| expChar_pow_pos F q n).mp hm).eq_X_add_C h2]
exact ⟨n, -(g.coeff 0), by rw [map_neg, sub_neg_eq_add]⟩
rw [h, natSepDegree_expand _ q, natSepDegree_X_sub_C]
/-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one if and only if it is of the form `X ^ (q ^ n) - C y`
for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_of_monic (q : ℕ) [ExpChar F q] (hm : f.Monic)
(hi : Irreducible f) : f.natSepDegree = 1 ↔ ∃ (n : ℕ) (y : F), f = X ^ q ^ n - C y := by
simp_rw [hi.natSepDegree_eq_one_iff_of_monic' q hm, map_sub, expand_X, expand_C]
end Irreducible
namespace Polynomial
namespace Monic
variable {F}
variable {f : F[X]}
alias natSepDegree_eq_one_iff_of_irreducible' := Irreducible.natSepDegree_eq_one_iff_of_monic'
alias natSepDegree_eq_one_iff_of_irreducible := Irreducible.natSepDegree_eq_one_iff_of_monic
/-- If a monic polynomial of separable degree one splits, then it is of form `(X - C y) ^ m` for
some non-zero natural number `m` and some element `y` of `F`. -/
theorem eq_X_sub_C_pow_of_natSepDegree_eq_one_of_splits (hm : f.Monic)
(hs : f.Splits (RingHom.id F))
(h : f.natSepDegree = 1) : ∃ (m : ℕ) (y : F), m ≠ 0 ∧ f = (X - C y) ^ m := by
classical
have h1 := eq_prod_roots_of_monic_of_splits_id hm hs
have h2 := (natSepDegree_eq_of_splits f hs).symm
rw [h, aroots_def, Algebra.id.map_eq_id, map_id, Multiset.toFinset_card_eq_one_iff] at h2
obtain ⟨h2, y, h3⟩ := h2
exact ⟨_, y, h2, by rwa [h3, Multiset.map_nsmul, Multiset.map_singleton, Multiset.prod_nsmul,
Multiset.prod_singleton] at h1⟩
/-- If a monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one, then it is of the form `X ^ (q ^ n) - C y` for some natural number `n`,
and some element `y` of `F`, such that either `n = 0` or `y` has no `q`-th root in `F`. -/
theorem eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible (q : ℕ) [ExpChar F q]
(hm : f.Monic) (hi : Irreducible f) (h : f.natSepDegree = 1) : ∃ (n : ℕ) (y : F),
(n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = X ^ q ^ n - C y := by
obtain ⟨n, y, hf⟩ := (hm.natSepDegree_eq_one_iff_of_irreducible q hi).1 h
cases id ‹ExpChar F q› with
| zero =>
simp_rw [one_pow, pow_one] at hf ⊢
exact ⟨0, y, .inl rfl, hf⟩
| prime hq =>
refine ⟨n, y, (em _).imp id fun hn ⟨z, hy⟩ ↦ ?_, hf⟩
haveI := expChar_of_injective_ringHom (R := F) C_injective q
rw [hf, ← Nat.succ_pred hn, pow_succ, pow_mul, ← hy, frobenius_def, map_pow,
← sub_pow_expChar] at hi
exact not_irreducible_pow hq.ne_one hi
/-- If a monic polynomial over a field `F` of exponential characteristic `q` has separable degree
one, then it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`,
some natural number `n`, and some element `y` of `F`, such that either `n = 0` or `y` has no
`q`-th root in `F`. -/
theorem eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one (q : ℕ) [ExpChar F q] (hm : f.Monic)
(h : f.natSepDegree = 1) : ∃ (m n : ℕ) (y : F),
m ≠ 0 ∧ (n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = (X ^ q ^ n - C y) ^ m := by
obtain ⟨p, hM, hI, hf⟩ := exists_monic_irreducible_factor _ <| not_isUnit_of_natDegree_pos _
<| Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).1 (h.symm ▸ Nat.one_ne_zero)
have hD := (h ▸ natSepDegree_le_of_dvd p f hf hm.ne_zero).antisymm <|
Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).2 hI.natDegree_pos.ne'
obtain ⟨n, y, H, hp⟩ := hM.eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible q hI hD
have hF := finiteMultiplicity_of_degree_pos_of_monic (degree_pos_of_irreducible hI) hM hm.ne_zero
classical
have hne := (multiplicity_pos_of_dvd hf).ne'
refine ⟨_, n, y, hne, H, ?_⟩
obtain ⟨c, hf, H⟩ := hF.exists_eq_pow_mul_and_not_dvd
rw [hf, natSepDegree_mul_of_isCoprime _ c <| IsCoprime.pow_left <|
(hI.isCoprime_or_dvd c).resolve_right H, natSepDegree_pow_of_ne_zero _ hne, hD,
add_eq_left, natSepDegree_eq_zero_iff] at h
simpa only [eq_one_of_monic_natDegree_zero ((hM.pow _).of_mul_monic_left (hf ▸ hm)) h,
mul_one, ← hp] using hf
/-- A monic polynomial over a field `F` of exponential characteristic `q` has separable degree one
if and only if it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`,
some natural number `n`, and some element `y` of `F`. -/
theorem natSepDegree_eq_one_iff (q : ℕ) [ExpChar F q] (hm : f.Monic) :
f.natSepDegree = 1 ↔ ∃ (m n : ℕ) (y : F), m ≠ 0 ∧ f = (X ^ q ^ n - C y) ^ m := by
refine ⟨fun h ↦ ?_, fun ⟨m, n, y, hm, h⟩ ↦ ?_⟩
· obtain ⟨m, n, y, hm, -, h⟩ := hm.eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one q h
exact ⟨m, n, y, hm, h⟩
simp_rw [h, natSepDegree_pow, hm, ite_false, natSepDegree_X_pow_char_pow_sub_C]
end Monic
end Polynomial
namespace minpoly
variable {F : Type u} {E : Type v} [Field F] [Ring E] [IsDomain E] [Algebra F E]
variable (q : ℕ) [hF : ExpChar F q] {x : E}
/-- The minimal polynomial of an element of `E / F` of exponential characteristic `q` has
separable degree one if and only if the minimal polynomial is of the form
`Polynomial.expand F (q ^ n) (X - C y)` for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_eq_expand_X_sub_C : (minpoly F x).natSepDegree = 1 ↔
∃ (n : ℕ) (y : F), minpoly F x = expand F (q ^ n) (X - C y) := by
refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩
· have halg : IsIntegral F x := by_contra fun h' ↦ by
simp only [eq_zero h', natSepDegree_zero, zero_ne_one] at h
exact (minpoly.irreducible halg).natSepDegree_eq_one_iff_of_monic' q
(minpoly.monic halg) |>.1 h
rw [h, natSepDegree_expand _ q, natSepDegree_X_sub_C]
/-- The minimal polynomial of an element of `E / F` of exponential characteristic `q` has
separable degree one if and only if the minimal polynomial is of the form
`X ^ (q ^ n) - C y` for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_eq_X_pow_sub_C : (minpoly F x).natSepDegree = 1 ↔
∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := by
simp only [minpoly.natSepDegree_eq_one_iff_eq_expand_X_sub_C q, map_sub, expand_X, expand_C]
/-- The minimal polynomial of an element `x` of `E / F` of exponential characteristic `q` has
separable degree one if and only if `x ^ (q ^ n) ∈ F` for some `n : ℕ`. -/
theorem natSepDegree_eq_one_iff_pow_mem : (minpoly F x).natSepDegree = 1 ↔
∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by
convert_to _ ↔ ∃ (n : ℕ) (y : F), Polynomial.aeval x (X ^ q ^ n - C y) = 0
· simp_rw [RingHom.mem_range, map_sub, map_pow, aeval_C, aeval_X, sub_eq_zero, eq_comm]
refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩
· obtain ⟨n, y, hx⟩ := (minpoly.natSepDegree_eq_one_iff_eq_X_pow_sub_C q).1 h
exact ⟨n, y, hx ▸ aeval F x⟩
have hnezero := X_pow_sub_C_ne_zero (expChar_pow_pos F q n) y
refine ((natSepDegree_le_of_dvd _ _ (minpoly.dvd F x h) hnezero).trans_eq <|
natSepDegree_X_pow_char_pow_sub_C q n y).antisymm ?_
rw [Nat.one_le_iff_ne_zero, natSepDegree_ne_zero_iff, ← Nat.one_le_iff_ne_zero]
exact minpoly.natDegree_pos <| IsAlgebraic.isIntegral ⟨_, hnezero, h⟩
/-- The minimal polynomial of an element `x` of `E / F` of exponential characteristic `q` has
separable degree one if and only if the minimal polynomial is of the form
`(X - x) ^ (q ^ n)` for some `n : ℕ`. -/
theorem natSepDegree_eq_one_iff_eq_X_sub_C_pow : (minpoly F x).natSepDegree = 1 ↔
∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := by
haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q
haveI := expChar_of_injective_ringHom (C_injective (R := E)) q
refine ⟨fun h ↦ ?_, fun ⟨n, h⟩ ↦ (natSepDegree_eq_one_iff_pow_mem q).2 ?_⟩
· obtain ⟨n, y, h⟩ := (natSepDegree_eq_one_iff_eq_X_pow_sub_C q).1 h
have hx := congr_arg (Polynomial.aeval x) h.symm
rw [minpoly.aeval, map_sub, map_pow, aeval_X, aeval_C, sub_eq_zero, eq_comm] at hx
use n
rw [h, Polynomial.map_sub, Polynomial.map_pow, map_X, map_C, hx, map_pow,
← sub_pow_expChar_pow_of_commute _ _ (commute_X _)]
apply_fun constantCoeff at h
simp_rw [map_pow, map_sub, constantCoeff_apply, coeff_map, coeff_X_zero, coeff_C_zero] at h
rw [zero_sub, neg_pow, neg_one_pow_expChar_pow] at h
exact ⟨n, -(minpoly F x).coeff 0, by rw [map_neg, h, neg_mul, one_mul, neg_neg]⟩
end minpoly
namespace IntermediateField
/-- The separable degree of `F⟮α⟯ / F` is equal to the separable degree of the
minimal polynomial of `α` over `F`. -/
theorem finSepDegree_adjoin_simple_eq_natSepDegree {α : E} (halg : IsAlgebraic F α) :
finSepDegree F F⟮α⟯ = (minpoly F α).natSepDegree := by
have : finSepDegree F F⟮α⟯ = _ := Nat.card_congr
(algHomAdjoinIntegralEquiv F (K := AlgebraicClosure F⟮α⟯) halg.isIntegral)
classical
rw [this, Nat.card_eq_fintype_card, natSepDegree_eq_of_isAlgClosed (E := AlgebraicClosure F⟮α⟯),
← Fintype.card_coe]
simp_rw [Multiset.mem_toFinset]
-- The separable degree of `F⟮α⟯ / F` divides the degree of `F⟮α⟯ / F`.
-- Marked as `private` because it is a special case of `finSepDegree_dvd_finrank`.
private theorem finSepDegree_adjoin_simple_dvd_finrank (α : E) :
finSepDegree F F⟮α⟯ ∣ finrank F F⟮α⟯ := by
by_cases halg : IsAlgebraic F α
· rw [finSepDegree_adjoin_simple_eq_natSepDegree F E halg, adjoin.finrank halg.isIntegral]
exact (minpoly.irreducible halg.isIntegral).natSepDegree_dvd_natDegree
have : finrank F F⟮α⟯ = 0 := finrank_of_infinite_dimensional fun _ ↦
halg ((AdjoinSimple.isIntegral_gen F α).1 (IsIntegral.of_finite F _)).isAlgebraic
rw [this]
exact dvd_zero _
/-- The separable degree of `F⟮α⟯ / F` is smaller than the degree of `F⟮α⟯ / F` if `α` is
algebraic over `F`. -/
theorem finSepDegree_adjoin_simple_le_finrank (α : E) (halg : IsAlgebraic F α) :
finSepDegree F F⟮α⟯ ≤ finrank F F⟮α⟯ := by
haveI := adjoin.finiteDimensional halg.isIntegral
exact Nat.le_of_dvd finrank_pos <| finSepDegree_adjoin_simple_dvd_finrank F E α
/-- If `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree
of `F⟮α⟯ / F` if and only if `α` is a separable element. -/
theorem finSepDegree_adjoin_simple_eq_finrank_iff (α : E) (halg : IsAlgebraic F α) :
finSepDegree F F⟮α⟯ = finrank F F⟮α⟯ ↔ IsSeparable F α := by
rw [finSepDegree_adjoin_simple_eq_natSepDegree F E halg, adjoin.finrank halg.isIntegral,
natSepDegree_eq_natDegree_iff _ (minpoly.ne_zero halg.isIntegral), IsSeparable]
end IntermediateField
namespace Field
/-- The separable degree of any field extension `E / F` divides the degree of `E / F`. -/
theorem finSepDegree_dvd_finrank : finSepDegree F E ∣ finrank F E := by
by_cases hfd : FiniteDimensional F E
· rw [← finSepDegree_top F, ← finrank_top F E]
refine induction_on_adjoin (fun K : IntermediateField F E ↦ finSepDegree F K ∣ finrank F K)
(by simp_rw [finSepDegree_bot, IntermediateField.finrank_bot, one_dvd]) (fun L x h ↦ ?_) ⊤
simp only at h ⊢
have hdvd := mul_dvd_mul h <| finSepDegree_adjoin_simple_dvd_finrank L E x
set M := L⟮x⟯
have := Algebra.IsAlgebraic.of_finite L M
rwa [finSepDegree_mul_finSepDegree_of_isAlgebraic F L M,
Module.finrank_mul_finrank F L M] at hdvd
rw [finrank_of_infinite_dimensional hfd]
exact dvd_zero _
/-- The separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. -/
@[stacks 09HA "The inequality"]
theorem finSepDegree_le_finrank [FiniteDimensional F E] :
finSepDegree F E ≤ finrank F E := Nat.le_of_dvd finrank_pos <| finSepDegree_dvd_finrank F E
/-- If `E / F` is a separable extension, then its separable degree is equal to its degree.
When `E / F` is infinite, it means that `Field.Emb F E` has infinitely many elements.
(But the cardinality of `Field.Emb F E` is not equal to `Module.rank F E` in general!) -/
theorem finSepDegree_eq_finrank_of_isSeparable [Algebra.IsSeparable F E] :
finSepDegree F E = finrank F E := by
wlog hfd : FiniteDimensional F E generalizing E with H
· rw [finrank_of_infinite_dimensional hfd]
have halg := Algebra.IsSeparable.isAlgebraic F E
obtain ⟨L, h, h'⟩ := exists_lt_finrank_of_infinite_dimensional hfd (finSepDegree F E)
have : Algebra.IsSeparable F L := Algebra.isSeparable_tower_bot_of_isSeparable F L E
have := (halg.tower_top L)
have hd := finSepDegree_mul_finSepDegree_of_isAlgebraic F L E
rw [H L h] at hd
by_cases hd' : finSepDegree L E = 0
· rw [← hd, hd', mul_zero]
linarith only [h', hd, Nat.le_mul_of_pos_right (finrank F L) (Nat.pos_of_ne_zero hd')]
rw [← finSepDegree_top F, ← finrank_top F E]
refine induction_on_adjoin (fun K : IntermediateField F E ↦ finSepDegree F K = finrank F K)
(by simp_rw [finSepDegree_bot, IntermediateField.finrank_bot]) (fun L x h ↦ ?_) ⊤
simp only at h ⊢
have heq : _ * _ = _ * _ := congr_arg₂ (· * ·) h <|
(finSepDegree_adjoin_simple_eq_finrank_iff L E x (IsAlgebraic.of_finite L x)).2 <|
IsSeparable.tower_top L (Algebra.IsSeparable.isSeparable F x)
set M := L⟮x⟯
have := Algebra.IsAlgebraic.of_finite L M
rwa [finSepDegree_mul_finSepDegree_of_isAlgebraic F L M,
Module.finrank_mul_finrank F L M] at heq
alias Algebra.IsSeparable.finSepDegree_eq := finSepDegree_eq_finrank_of_isSeparable
/-- If `E / F` is a finite extension, then its separable degree is equal to its degree if and
only if it is a separable extension. -/
@[stacks 09HA "The equality condition"]
theorem finSepDegree_eq_finrank_iff [FiniteDimensional F E] :
finSepDegree F E = finrank F E ↔ Algebra.IsSeparable F E :=
⟨fun heq ↦ ⟨fun x ↦ by
have halg := IsAlgebraic.of_finite F x
refine (finSepDegree_adjoin_simple_eq_finrank_iff F E x halg).1 <| le_antisymm
(finSepDegree_adjoin_simple_le_finrank F E x halg) <| le_of_not_lt fun h ↦ ?_
have := Nat.mul_lt_mul_of_lt_of_le' h (finSepDegree_le_finrank F⟮x⟯ E) Fin.pos'
rw [finSepDegree_mul_finSepDegree_of_isAlgebraic F F⟮x⟯ E,
Module.finrank_mul_finrank F F⟮x⟯ E] at this
linarith only [heq, this]⟩, fun _ ↦ finSepDegree_eq_finrank_of_isSeparable F E⟩
end Field
lemma IntermediateField.isSeparable_of_mem_isSeparable {L : IntermediateField F E}
[Algebra.IsSeparable F L] {x : E} (h : x ∈ L) : IsSeparable F x := by
simpa only [IsSeparable, minpoly_eq] using Algebra.IsSeparable.isSeparable F (K := L) ⟨x, h⟩
/-- `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element.
As a consequence, any rational function of `x` is also a separable element. -/
theorem IntermediateField.isSeparable_adjoin_simple_iff_isSeparable {x : E} :
Algebra.IsSeparable F F⟮x⟯ ↔ IsSeparable F x := by
refine ⟨fun _ ↦ ?_, fun hsep ↦ ?_⟩
· exact isSeparable_of_mem_isSeparable F E <| mem_adjoin_simple_self F x
· have h := IsSeparable.isIntegral hsep
haveI := adjoin.finiteDimensional h
rwa [← finSepDegree_eq_finrank_iff,
finSepDegree_adjoin_simple_eq_finrank_iff F E x h.isAlgebraic]
variable {E K} in
/-- If `K / E / F` is an extension tower such that `E / F` is separable,
`x : K` is separable over `E`, then it's also separable over `F`. -/
| Mathlib/FieldTheory/SeparableDegree.lean | 807 | 809 | theorem IsSeparable.of_algebra_isSeparable_of_isSeparable [Algebra E K] [IsScalarTower F E K]
[Algebra.IsSeparable F E] {x : K} (hsep : IsSeparable E x) : IsSeparable F x := by | set f := minpoly E x with hf |
/-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.Algebra.Equiv.TransferInstance
import Mathlib.RingTheory.Finiteness.Cardinality
/-!
# Orzech property of rings
In this file we define the following property of rings:
- `OrzechProperty R` is a type class stating that `R` satisfies the following property:
for any finitely generated `R`-module `M`, any surjective homomorphism `f : N → M`
from a submodule `N` of `M` to `M` is injective.
It was introduced in papers by Orzech [orzech1971], Djoković [djokovic1973] and
Ribenboim [ribenboim1971], under the names `Π`-ring or `Π₁`-ring.
It implies the strong rank condition (that is, the existence of an injective linear map
`(Fin n → R) →ₗ[R] (Fin m → R)` implies `n ≤ m`)
if the ring is nontrivial (see `Mathlib/LinearAlgebra/InvariantBasisNumber.lean`).
It's proved in the above papers that
- a left Noetherian ring (not necessarily commutative) satisfies the `OrzechProperty`,
which in particular includes the division ring case
(see `Mathlib/RingTheory/Noetherian.lean`);
- a commutative ring satisfies the `OrzechProperty`
(see `Mathlib/RingTheory/FiniteType.lean`).
## References
* [Orzech, Morris. *Onto endomorphisms are isomorphisms*][orzech1971]
* [Djoković, D. Ž. *Epimorphisms of modules which must be isomorphisms*][djokovic1973]
* [Ribenboim, Paulo.
*Épimorphismes de modules qui sont nécessairement des isomorphismes*][ribenboim1971]
## Tags
free module, rank, Orzech property, (strong) rank condition, invariant basis number, IBN
-/
universe u v w
open Function
variable (R : Type u) [Semiring R]
/-- A ring `R` satisfies the Orzech property, if for any finitely generated `R`-module `M`,
any surjective homomorphism `f : N → M` from a submodule `N` of `M` to `M` is injective.
NOTE: In the definition we need to assume that `M` has the same universe level as `R`, but it
in fact implies the universe polymorphic versions
`OrzechProperty.injective_of_surjective_of_injective`
and `OrzechProperty.injective_of_surjective_of_submodule`. -/
@[mk_iff]
class OrzechProperty : Prop where
injective_of_surjective_of_submodule' : ∀ {M : Type u} [AddCommMonoid M] [Module R M]
[Module.Finite R M] {N : Submodule R M} (f : N →ₗ[R] M), Surjective f → Injective f
namespace OrzechProperty
variable {R}
variable [OrzechProperty R] {M : Type v} [AddCommMonoid M] [Module R M] [Module.Finite R M]
| Mathlib/RingTheory/OrzechProperty.lean | 69 | 82 | theorem injective_of_surjective_of_injective
{N : Type w} [AddCommMonoid N] [Module R N]
(i f : N →ₗ[R] M) (hi : Injective i) (hf : Surjective f) : Injective f := by | obtain ⟨n, g, hg⟩ := Module.Finite.exists_fin' R M
haveI := small_of_surjective hg
letI := Equiv.addCommMonoid (equivShrink M).symm
letI := Equiv.module R (equivShrink M).symm
let j : Shrink.{u} M ≃ₗ[R] M := Equiv.linearEquiv R (equivShrink M).symm
haveI := Module.Finite.equiv j.symm
let i' := j.symm.toLinearMap ∘ₗ i
replace hi : Injective i' := by simpa [i'] using hi
let f' := j.symm.toLinearMap ∘ₗ f ∘ₗ (LinearEquiv.ofInjective i' hi).symm.toLinearMap
replace hf : Surjective f' := by simpa [f'] using hf
simpa [f'] using injective_of_surjective_of_submodule' f' hf |
/-
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.Finite.Prod
import Mathlib.Data.Matroid.Init
import Mathlib.Data.Set.Card
import Mathlib.Data.Set.Finite.Powerset
import Mathlib.Order.UpperLower.Closure
/-!
# 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.IsBase 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.IsBasis 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.
* `RankFinite M` means that the bases of `M` are finite.
* `RankInfinite M` means that the bases of `M` are infinite.
* `RankPos 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 `[RankFinite 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.
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 few 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_isBase_dual` is one of the many examples of this.
Finally, in theorem names, matroid predicates that apply to sets
(such as `Base`, `Indep`, `IsBasis`) are typically used as suffixes rather than prefixes.
For instance, we have `ground_indep_iff_isBase` rather than `indep_ground_iff_isBase`.
## References
* [J. Oxley, Matroid Theory][oxley2011]
* [H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids,
Adv. Math 239 (2013), 18-46][bruhnDiestelKriesselPendavinghWollan2013]
* [N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets,
Proc. Amer. Math. Soc. 144 (2016), 459-471][bowlerGeschke2015]
-/
assert_not_exists Field
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 → ∃ J, I ⊆ J ∧ Maximal (fun K ↦ P K ∧ K ⊆ X) J
/-- 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`.
-/
structure Matroid (α : Type*) where
/-- `M` has a ground set `E`. -/
(E : Set α)
/-- `M` has a predicate `Base` defining its bases. -/
(IsBase : 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, IsBase B ∧ I ⊆ B)
/-- There is at least one `Base`. -/
(exists_isBase : ∃ B, IsBase B)
/-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f`
is a base. -/
(isBase_exchange : Matroid.ExchangeProperty IsBase)
/-- 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, IsBase B → B ⊆ E)
attribute [local ext] Matroid
namespace Matroid
variable {α : Type*} {M : Matroid α}
@[deprecated (since := "2025-02-14")] alias Base := IsBase
instance (M : Matroid α) : Nonempty {B // M.IsBase B} :=
nonempty_subtype.2 M.exists_isBase
/-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`. -/
@[mk_iff] 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⟩
lemma nonempty_type (M : Matroid α) [h : M.Nonempty] : Nonempty α :=
⟨M.ground_nonempty.some⟩
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 `RankFinite` matroid is one whose bases are finite -/
@[mk_iff] class RankFinite (M : Matroid α) : Prop where
/-- There is a finite base -/
exists_finite_isBase : ∃ B, M.IsBase B ∧ B.Finite
@[deprecated (since := "2025-02-09")] alias FiniteRk := RankFinite
instance rankFinite_of_finite (M : Matroid α) [M.Finite] : RankFinite M :=
⟨M.exists_isBase.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩
/-- An `RankInfinite` matroid is one whose bases are infinite. -/
@[mk_iff] class RankInfinite (M : Matroid α) : Prop where
/-- There is an infinite base -/
exists_infinite_isBase : ∃ B, M.IsBase B ∧ B.Infinite
@[deprecated (since := "2025-02-09")] alias InfiniteRk := RankInfinite
/-- A `RankPos` matroid is one whose bases are nonempty. -/
@[mk_iff] class RankPos (M : Matroid α) : Prop where
/-- The empty set isn't a base -/
empty_not_isBase : ¬M.IsBase ∅
@[deprecated (since := "2025-02-09")] alias RkPos := RankPos
instance rankPos_nonempty {M : Matroid α} [M.RankPos] : M.Nonempty := by
obtain ⟨B, hB⟩ := M.exists_isBase
obtain rfl | ⟨e, heB⟩ := B.eq_empty_or_nonempty
· exact False.elim <| RankPos.empty_not_isBase hB
exact ⟨e, M.subset_ground B hB heB ⟩
@[deprecated (since := "2025-01-20")] alias rkPos_iff_empty_not_base := rankPos_iff
section exchange
namespace ExchangeProperty
variable {IsBase : Set α → Prop} {B B' : Set α}
/-- A family of sets with the exchange property is an antichain. -/
theorem antichain (exch : ExchangeProperty IsBase) (hB : IsBase B) (hB' : IsBase 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 {B₁ B₂ : Set α}
(exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase 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
variable {B₁ B₂ : Set α}
/-- 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 (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase 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_isBase_eq (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase 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`. -/
variable {X Y : Set α} {e : α}
@[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 IsBase
variable {B B₁ B₂ : Set α}
@[aesop unsafe 10% (rule_sets := [Matroid])]
theorem IsBase.subset_ground (hB : M.IsBase B) : B ⊆ M.E :=
M.subset_ground B hB
theorem IsBase.exchange {e : α} (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hx : e ∈ B₁ \ B₂) :
∃ y ∈ B₂ \ B₁, M.IsBase (insert y (B₁ \ {e})) :=
M.isBase_exchange B₁ B₂ hB₁ hB₂ _ hx
theorem IsBase.exchange_mem {e : α}
(hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hxB₁ : e ∈ B₁) (hxB₂ : e ∉ B₂) :
∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.IsBase (insert y (B₁ \ {e})) := by
simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩
theorem IsBase.eq_of_subset_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hB₁B₂ : B₁ ⊆ B₂) :
B₁ = B₂ :=
M.isBase_exchange.antichain hB₁ hB₂ hB₁B₂
theorem IsBase.not_isBase_of_ssubset {X : Set α} (hB : M.IsBase B) (hX : X ⊂ B) : ¬ M.IsBase X :=
fun h ↦ hX.ne (h.eq_of_subset_isBase hB hX.subset)
theorem IsBase.insert_not_isBase {e : α} (hB : M.IsBase B) (heB : e ∉ B) :
¬ M.IsBase (insert e B) :=
fun h ↦ h.not_isBase_of_ssubset (ssubset_insert heB) hB
theorem IsBase.encard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).encard = (B₂ \ B₁).encard :=
M.isBase_exchange.encard_diff_eq hB₁ hB₂
theorem IsBase.ncard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).ncard = (B₂ \ B₁).ncard := by
rw [ncard_def, hB₁.encard_diff_comm hB₂, ← ncard_def]
theorem IsBase.encard_eq_encard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
B₁.encard = B₂.encard := by
rw [M.isBase_exchange.encard_isBase_eq hB₁ hB₂]
theorem IsBase.ncard_eq_ncard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
B₁.ncard = B₂.ncard := by
rw [ncard_def B₁, hB₁.encard_eq_encard_of_isBase hB₂, ← ncard_def]
theorem IsBase.finite_of_finite {B' : Set α}
(hB : M.IsBase B) (h : B.Finite) (hB' : M.IsBase B') : B'.Finite :=
(finite_iff_finite_of_encard_eq_encard (hB.encard_eq_encard_of_isBase hB')).mp h
theorem IsBase.infinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) (hB₁ : M.IsBase B₁) :
B₁.Infinite :=
by_contra (fun hB_inf ↦ (hB₁.finite_of_finite (not_infinite.mp hB_inf) hB).not_infinite h)
theorem IsBase.finite [RankFinite M] (hB : M.IsBase B) : B.Finite :=
let ⟨_,hB₀⟩ := ‹RankFinite M›.exists_finite_isBase
hB₀.1.finite_of_finite hB₀.2 hB
theorem IsBase.infinite [RankInfinite M] (hB : M.IsBase B) : B.Infinite :=
let ⟨_,hB₀⟩ := ‹RankInfinite M›.exists_infinite_isBase
hB₀.1.infinite_of_infinite hB₀.2 hB
theorem empty_not_isBase [h : RankPos M] : ¬M.IsBase ∅ :=
h.empty_not_isBase
theorem IsBase.nonempty [RankPos M] (hB : M.IsBase B) : B.Nonempty := by
rw [nonempty_iff_ne_empty]; rintro rfl; exact M.empty_not_isBase hB
theorem IsBase.rankPos_of_nonempty (hB : M.IsBase B) (h : B.Nonempty) : M.RankPos := by
rw [rankPos_iff]
intro he
obtain rfl := he.eq_of_subset_isBase hB (empty_subset B)
simp at h
theorem IsBase.rankFinite_of_finite (hB : M.IsBase B) (hfin : B.Finite) : RankFinite M :=
⟨⟨B, hB, hfin⟩⟩
theorem IsBase.rankInfinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) : RankInfinite M :=
⟨⟨B, hB, h⟩⟩
theorem not_rankFinite (M : Matroid α) [RankInfinite M] : ¬ RankFinite M := by
intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite
theorem not_rankInfinite (M : Matroid α) [RankFinite M] : ¬ RankInfinite M := by
intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite
theorem rankFinite_or_rankInfinite (M : Matroid α) : RankFinite M ∨ RankInfinite M :=
let ⟨B, hB⟩ := M.exists_isBase
B.finite_or_infinite.imp hB.rankFinite_of_finite hB.rankInfinite_of_infinite
@[deprecated (since := "2025-03-27")] alias finite_or_rankInfinite := rankFinite_or_rankInfinite
@[simp]
theorem not_rankFinite_iff (M : Matroid α) : ¬ RankFinite M ↔ RankInfinite M :=
M.rankFinite_or_rankInfinite.elim (fun h ↦ iff_of_false (by simpa) M.not_rankInfinite)
fun h ↦ iff_of_true M.not_rankFinite h
@[simp]
theorem not_rankInfinite_iff (M : Matroid α) : ¬ RankInfinite M ↔ RankFinite M := by
rw [← not_rankFinite_iff, not_not]
theorem IsBase.diff_finite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).Finite ↔ (B₂ \ B₁).Finite :=
finite_iff_finite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂)
theorem IsBase.diff_infinite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite :=
infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂)
theorem ext_isBase {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B)) : M₁ = M₂ := by
have h' : ∀ B, M₁.IsBase B ↔ M₂.IsBase 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']
@[deprecated (since := "2024-12-25")] alias eq_of_isBase_iff_isBase_forall := ext_isBase
theorem ext_iff_isBase {M₁ M₂ : Matroid α} :
M₁ = M₂ ↔ M₁.E = M₂.E ∧ ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B) :=
⟨fun h ↦ by simp [h], fun ⟨hE, h⟩ ↦ ext_isBase hE h⟩
theorem isBase_compl_iff_maximal_disjoint_isBase (hB : B ⊆ M.E := by aesop_mat) :
M.IsBase (M.E \ B) ↔ Maximal (fun I ↦ I ⊆ M.E ∧ ∃ B, M.IsBase B ∧ Disjoint I B) B := by
simp_rw [maximal_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_isBase 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 IsBase
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
variable {B B' I J D X : Set α} {e f : α}
theorem indep_iff : M.Indep I ↔ ∃ B, M.IsBase B ∧ I ⊆ B :=
M.indep_iff' (I := I)
theorem setOf_indep_eq (M : Matroid α) : {I | M.Indep I} = lowerClosure ({B | M.IsBase B}) := by
simp_rw [indep_iff, lowerClosure, LowerSet.coe_mk, mem_setOf, le_eq_subset]
theorem Indep.exists_isBase_superset (hI : M.Indep I) : ∃ B, M.IsBase 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_isBase_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_isBase_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 IsBase.indep (hB : M.IsBase B) : M.Indep B :=
indep_iff.2 ⟨B, hB, subset_rfl⟩
@[simp] theorem empty_indep (M : Matroid α) : M.Indep ∅ :=
Exists.elim M.exists_isBase (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 [RankFinite M] (hI : M.Indep I) : I.Finite :=
let ⟨_, hB, hIB⟩ := hI.exists_isBase_superset
hB.finite.subset hIB
theorem Indep.rankPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RankPos := by
obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset
exact hB.rankPos_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 IsBase.eq_of_subset_indep (hB : M.IsBase B) (hI : M.Indep I) (hBI : B ⊆ I) : B = I :=
let ⟨B', hB', hB'I⟩ := hI.exists_isBase_superset
hBI.antisymm (by rwa [hB.eq_of_subset_isBase hB' (hBI.trans hB'I)])
theorem isBase_iff_maximal_indep : M.IsBase B ↔ Maximal M.Indep B := by
rw [maximal_subset_iff]
refine ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep⟩, fun ⟨h, h'⟩ ↦ ?_⟩
obtain ⟨B', hB', hBB'⟩ := h.exists_isBase_superset
rwa [h' hB'.indep hBB']
theorem Indep.isBase_of_maximal (hI : M.Indep I) (h : ∀ ⦃J⦄, M.Indep J → I ⊆ J → I = J) :
M.IsBase I := by
rwa [isBase_iff_maximal_indep, maximal_subset_iff, and_iff_right hI]
theorem IsBase.dep_of_ssubset (hB : M.IsBase 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 IsBase.dep_of_insert (hB : M.IsBase 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 IsBase.mem_of_insert_indep (hB : M.IsBase 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 IsBases is a singleton, then they differ by an insertion/removal -/
theorem IsBase.eq_exchange_of_diff_eq_singleton (hB : M.IsBase B) (hB' : M.IsBase 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_isBase 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 IsBase.exchange_isBase_of_indep (hB : M.IsBase B) (hf : f ∉ B)
(hI : M.Indep (insert f (B \ {e}))) : M.IsBase (insert f (B \ {e})) := by
obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_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 IsBase.exchange_isBase_of_indep' (hB : M.IsBase B) (he : e ∈ B) (hf : f ∉ B)
(hI : M.Indep (insert f B \ {e})) : M.IsBase (insert f B \ {e}) := by
have hfe : f ≠ e := ne_of_mem_of_not_mem he hf |>.symm
rw [← insert_diff_singleton_comm hfe] at *
exact hB.exchange_isBase_of_indep hf hI
lemma insert_isBase_of_insert_indep {M : Matroid α} {I : Set α} {e f : α}
(he : e ∉ I) (hf : f ∉ I) (heI : M.IsBase (insert e I)) (hfI : M.Indep (insert f I)) :
M.IsBase (insert f I) := by
obtain rfl | hef := eq_or_ne e f
· assumption
simpa [diff_singleton_eq_self he, hfI]
using heI.exchange_isBase_of_indep (e := e) (f := f) (by simp [hef.symm, hf])
theorem IsBase.insert_dep (hB : M.IsBase 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_isBase (hI : M.Indep I) (hI' : ¬M.IsBase I) (hB : M.IsBase B) :
∃ e ∈ B \ I, M.Indep (insert e I) := by
obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_superset
obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB')))
by_cases hxB : 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_isBase`, but phrased so that
it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_maximal (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
(hInotmax : ¬ Maximal M.Indep I) (hB : Maximal M.Indep B) :
∃ x ∈ B \ I, M.Indep (insert x I) := by
simp only [maximal_subset_iff, hI, not_and, not_forall, exists_prop, true_imp_iff] at hB hInotmax
refine hI.exists_insert_of_not_isBase (fun hIb ↦ ?_) ?_
· obtain ⟨I', hII', hI', hne⟩ := hInotmax
exact hne <| hIb.eq_of_subset_indep hII' hI'
exact hB.1.isBase_of_maximal fun J hJ hBJ ↦ hB.2 hJ hBJ
theorem Indep.isBase_of_forall_insert (hB : M.Indep B)
(hBmax : ∀ e ∈ M.E \ B, ¬ M.Indep (insert e B)) : M.IsBase B := by
refine by_contra fun hnb ↦ ?_
obtain ⟨B', hB'⟩ := M.exists_isBase
obtain ⟨e, he, h⟩ := hB.exists_insert_of_not_isBase hnb hB'
exact hBmax e ⟨hB'.subset_ground he.1, he.2⟩ h
theorem ground_indep_iff_isBase : M.Indep M.E ↔ M.IsBase M.E :=
⟨fun h ↦ h.isBase_of_maximal (fun _ hJ hEJ ↦ hEJ.antisymm hJ.subset_ground), IsBase.indep⟩
theorem IsBase.exists_insert_of_ssubset (hB : M.IsBase B) (hIB : I ⊂ B) (hB' : M.IsBase B') :
∃ e ∈ B' \ I, M.Indep (insert e I) :=
(hB.indep.subset hIB.subset).exists_insert_of_not_isBase
(fun hI ↦ hIB.ne (hI.eq_of_subset_isBase hB hIB.subset)) hB'
@[ext] theorem ext_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(h : ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ :=
have h' : M₁.Indep = M₂.Indep := by
ext I
by_cases hI : I ⊆ M₁.E
· rwa [h]
exact iff_of_false (fun hi ↦ hI hi.subset_ground)
(fun hi ↦ hI (hi.subset_ground.trans_eq hE.symm))
ext_isBase hE (fun B _ ↦ by simp_rw [isBase_iff_maximal_indep, h'])
@[deprecated (since := "2024-12-25")] alias eq_of_indep_iff_indep_forall := ext_indep
theorem ext_iff_indep {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 ↦ ext_indep h.1 h.2⟩
@[deprecated (since := "2024-12-25")] alias eq_iff_indep_iff_indep_forall := ext_iff_indep
/-- If every base of `M₁` is independent in `M₂` and vice versa, then `M₁ = M₂`. -/
lemma ext_isBase_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(hM₁ : ∀ ⦃B⦄, M₁.IsBase B → M₂.Indep B) (hM₂ : ∀ ⦃B⦄, M₂.IsBase B → M₁.Indep B) : M₁ = M₂ := by
refine ext_indep hE fun I hIE ↦ ⟨fun hI ↦ ?_, fun hI ↦ ?_⟩
· obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset
exact (hM₁ hB).subset hIB
obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset
exact (hM₂ hB).subset hIB
/-- 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. -/
@[mk_iff] 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_rankFinite {M : Matroid α} [RankFinite M] : Finitary M where
indep_of_forall_finite I hI := by
refine I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
obtain ⟨B, hB⟩ := M.exists_isBase
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_isBase_superset
have hle := ncard_le_ncard hI₀B' hB'.finite
rw [hI₀card, hB'.ncard_eq_ncard_of_isBase 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 copy
/-- create a copy of `M : Matroid α` with independence and base predicates and ground set defeq
to supplied arguments that are provably equal to those of `M`. -/
@[simps] def copy (M : Matroid α) (E : Set α) (IsBase Indep : Set α → Prop) (hE : E = M.E)
(hB : ∀ B, IsBase B ↔ M.IsBase B) (hI : ∀ I, Indep I ↔ M.Indep I) : Matroid α where
E := E
IsBase := IsBase
Indep := Indep
indep_iff' _ := by simp_rw [hI, hB, M.indep_iff]
exists_isBase := by
simp_rw [hB]
exact M.exists_isBase
isBase_exchange := by
simp_rw [show IsBase = M.IsBase from funext (by simp [hB])]
exact M.isBase_exchange
maximality := by
simp_rw [hE, show Indep = M.Indep from funext (by simp [hI])]
exact M.maximality
subset_ground := by
simp_rw [hE, hB]
exact M.subset_ground
/-- create a copy of `M : Matroid α` with an independence predicate and ground set defeq
to supplied arguments that are provably equal to those of `M`. -/
@[simps!] def copyIndep (M : Matroid α) (E : Set α) (Indep : Set α → Prop)
(hE : E = M.E) (h : ∀ I, Indep I ↔ M.Indep I) : Matroid α :=
M.copy E M.IsBase Indep hE (fun _ ↦ Iff.rfl) h
/-- create a copy of `M : Matroid α` with a base predicate and ground set defeq
to supplied arguments that are provably equal to those of `M`. -/
@[simps!] def copyBase (M : Matroid α) (E : Set α) (IsBase : Set α → Prop)
(hE : E = M.E) (h : ∀ B, IsBase B ↔ M.IsBase B) : Matroid α :=
M.copy E IsBase M.Indep hE h (fun _ ↦ Iff.rfl)
end copy
section IsBasis
/-- 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 IsBasis (M : Matroid α) (I X : Set α) : Prop :=
Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I ∧ X ⊆ M.E
@[deprecated (since := "2025-02-14")] alias Basis := IsBasis
/-- `Matroid.IsBasis' I X` is the same as `Matroid.IsBasis I X`,
without the requirement that `X ⊆ M.E`. This is convenient for some
API building, especially when working with rank and closure. -/
def IsBasis' (M : Matroid α) (I X : Set α) : Prop :=
Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I
@[deprecated (since := "2025-02-14")] alias Basis' := IsBasis'
variable {B I J X Y : Set α} {e : α}
theorem IsBasis'.indep (hI : M.IsBasis' I X) : M.Indep I :=
hI.1.1
theorem IsBasis.indep (hI : M.IsBasis I X) : M.Indep I :=
hI.1.1.1
theorem IsBasis.subset (hI : M.IsBasis I X) : I ⊆ X :=
hI.1.1.2
theorem IsBasis.isBasis' (hI : M.IsBasis I X) : M.IsBasis' I X :=
hI.1
theorem IsBasis'.isBasis (hI : M.IsBasis' I X) (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X :=
⟨hI, hX⟩
theorem IsBasis'.subset (hI : M.IsBasis' I X) : I ⊆ X :=
hI.1.2
@[aesop unsafe 15% (rule_sets := [Matroid])]
theorem IsBasis.subset_ground (hI : M.IsBasis I X) : X ⊆ M.E :=
hI.2
theorem IsBasis.isBasis_inter_ground (hI : M.IsBasis I X) : M.IsBasis I (X ∩ M.E) := by
convert hI
rw [inter_eq_self_of_subset_left hI.subset_ground]
@[aesop unsafe 15% (rule_sets := [Matroid])]
theorem IsBasis.left_subset_ground (hI : M.IsBasis I X) : I ⊆ M.E :=
hI.indep.subset_ground
theorem IsBasis.eq_of_subset_indep (hI : M.IsBasis I X) (hJ : M.Indep J) (hIJ : I ⊆ J)
(hJX : J ⊆ X) : I = J :=
hIJ.antisymm (hI.1.2 ⟨hJ, hJX⟩ hIJ)
theorem IsBasis.Finite (hI : M.IsBasis I X) [RankFinite M] : I.Finite := hI.indep.finite
theorem isBasis_iff' :
M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E := by
rw [IsBasis, maximal_subset_iff]
tauto
theorem isBasis_iff (hX : X ⊆ M.E := by aesop_mat) :
M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) := by
rw [isBasis_iff', and_iff_left hX]
theorem isBasis'_iff_isBasis_inter_ground : M.IsBasis' I X ↔ M.IsBasis I (X ∩ M.E) := by
rw [IsBasis', IsBasis, and_iff_left inter_subset_right, maximal_iff_maximal_of_imp_of_forall]
· exact fun I hI ↦ ⟨hI.1, hI.2.trans inter_subset_left⟩
exact fun I hI ↦ ⟨I, rfl.le, hI.1, subset_inter hI.2 hI.1.subset_ground⟩
theorem isBasis'_iff_isBasis (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis' I X ↔ M.IsBasis I X := by
rw [isBasis'_iff_isBasis_inter_ground, inter_eq_self_of_subset_left hX]
theorem isBasis_iff_isBasis'_subset_ground : M.IsBasis I X ↔ M.IsBasis' I X ∧ X ⊆ M.E :=
⟨fun h ↦ ⟨h.isBasis', h.subset_ground⟩, fun h ↦ (isBasis'_iff_isBasis h.2).mp h.1⟩
theorem IsBasis'.isBasis_inter_ground (hIX : M.IsBasis' I X) : M.IsBasis I (X ∩ M.E) :=
isBasis'_iff_isBasis_inter_ground.mp hIX
theorem IsBasis'.eq_of_subset_indep (hI : M.IsBasis' I X) (hJ : M.Indep J) (hIJ : I ⊆ J)
(hJX : J ⊆ X) : I = J :=
hIJ.antisymm (hI.2 ⟨hJ, hJX⟩ hIJ)
theorem IsBasis'.insert_not_indep (hI : M.IsBasis' 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 isBasis_iff_maximal (hX : X ⊆ M.E := by aesop_mat) :
M.IsBasis I X ↔ Maximal (fun I ↦ M.Indep I ∧ I ⊆ X) I := by
rw [IsBasis, and_iff_left hX]
theorem Indep.isBasis_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.IsBasis I X := by
rw [isBasis_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 IsBasis.isBasis_subset (hI : M.IsBasis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) :
M.IsBasis I Y := by
rw [isBasis_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 isBasis_self_iff_indep : M.IsBasis I I ↔ M.Indep I := by
rw [isBasis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp]
exact fun hi ↦ ⟨fun _ _ ↦ subset_antisymm, hi.subset_ground⟩
theorem Indep.isBasis_self (h : M.Indep I) : M.IsBasis I I :=
isBasis_self_iff_indep.mpr h
@[simp] theorem isBasis_empty_iff (M : Matroid α) : M.IsBasis I ∅ ↔ I = ∅ :=
⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (rw [h]; exact M.empty_indep.isBasis_self)⟩
theorem IsBasis.dep_of_ssubset (hI : M.IsBasis 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 IsBasis.insert_dep (hI : M.IsBasis 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 IsBasis.mem_of_insert_indep (hI : M.IsBasis 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 IsBasis'.mem_of_insert_indep (hI : M.IsBasis' I X) (he : e ∈ X)
(hIe : M.Indep (insert e I)) : e ∈ I :=
hI.isBasis_inter_ground.mem_of_insert_indep ⟨he, hIe.subset_ground (mem_insert _ _)⟩ hIe
theorem IsBasis.not_isBasis_of_ssubset (hI : M.IsBasis I X) (hJI : J ⊂ I) : ¬ M.IsBasis J X :=
fun h ↦ hJI.ne (h.eq_of_subset_indep hI.indep hJI.subset hI.subset)
theorem Indep.subset_isBasis_of_subset (hI : M.Indep I) (hIX : I ⊆ X)
(hX : X ⊆ M.E := by aesop_mat) : ∃ J, M.IsBasis J X ∧ I ⊆ J := by
obtain ⟨J, hJ, hJmax⟩ := M.maximality X hX I hI hIX
exact ⟨J, ⟨hJmax, hX⟩, hJ⟩
theorem Indep.subset_isBasis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) :
∃ J, M.IsBasis' J X ∧ I ⊆ J := by
simp_rw [isBasis'_iff_isBasis_inter_ground]
exact hI.subset_isBasis_of_subset (subset_inter hIX hI.subset_ground)
theorem exists_isBasis (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) :
∃ I, M.IsBasis I X :=
let ⟨_, hI, _⟩ := M.empty_indep.subset_isBasis_of_subset (empty_subset X)
⟨_, hI⟩
theorem exists_isBasis' (M : Matroid α) (X : Set α) : ∃ I, M.IsBasis' I X :=
let ⟨_, hI, _⟩ := M.empty_indep.subset_isBasis'_of_subset (empty_subset X)
⟨_, hI⟩
theorem exists_isBasis_subset_isBasis (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) :
∃ I J, M.IsBasis I X ∧ M.IsBasis J Y ∧ I ⊆ J := by
obtain ⟨I, hI⟩ := M.exists_isBasis X (hXY.trans hY)
obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_isBasis_of_subset (hI.subset.trans hXY)
exact ⟨_, _, hI, hJ, hIJ⟩
theorem IsBasis.exists_isBasis_inter_eq_of_superset (hI : M.IsBasis I X) (hXY : X ⊆ Y)
(hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.IsBasis J Y ∧ J ∩ X = I := by
obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_isBasis_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 | 969 | 972 | theorem exists_isBasis_union_inter_isBasis (M : Matroid α) (X Y : Set α)
(hX : X ⊆ M.E := by | aesop_mat) (hY : Y ⊆ M.E := by aesop_mat) :
∃ I, M.IsBasis I (X ∪ Y) ∧ M.IsBasis (I ∩ Y) Y :=
let ⟨J, hJ⟩ := M.exists_isBasis Y |
/-
Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Maps
import Mathlib.Data.Finset.Max
import Mathlib.Data.Sym.Card
/-!
# Definitions for finite and locally finite graphs
This file defines finite versions of `edgeSet`, `neighborSet` and `incidenceSet` and proves some
of their basic properties. It also defines the notion of a locally finite graph, which is one
whose vertices have finite degree.
The design for finiteness is that each definition takes the smallest finiteness assumption
necessary. For example, `SimpleGraph.neighborFinset v` only requires that `v` have
finitely many neighbors.
## Main definitions
* `SimpleGraph.edgeFinset` is the `Finset` of edges in a graph, if `edgeSet` is finite
* `SimpleGraph.neighborFinset` is the `Finset` of vertices adjacent to a given vertex,
if `neighborSet` is finite
* `SimpleGraph.incidenceFinset` is the `Finset` of edges containing a given vertex,
if `incidenceSet` is finite
## Naming conventions
If the vertex type of a graph is finite, we refer to its cardinality as `CardVerts`
or `card_verts`.
## Implementation notes
* A locally finite graph is one with instances `Π v, Fintype (G.neighborSet v)`.
* Given instances `DecidableRel G.Adj` and `Fintype V`, then the graph
is locally finite, too.
-/
open Finset Function
namespace SimpleGraph
variable {V : Type*} (G : SimpleGraph V) {e : Sym2 V}
section EdgeFinset
variable {G₁ G₂ : SimpleGraph V} [Fintype G.edgeSet] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet]
/-- The `edgeSet` of the graph as a `Finset`. -/
abbrev edgeFinset : Finset (Sym2 V) :=
Set.toFinset G.edgeSet
@[norm_cast]
theorem coe_edgeFinset : (G.edgeFinset : Set (Sym2 V)) = G.edgeSet :=
Set.coe_toFinset _
variable {G}
theorem mem_edgeFinset : e ∈ G.edgeFinset ↔ e ∈ G.edgeSet :=
Set.mem_toFinset
theorem not_isDiag_of_mem_edgeFinset : e ∈ G.edgeFinset → ¬e.IsDiag :=
not_isDiag_of_mem_edgeSet _ ∘ mem_edgeFinset.1
theorem edgeFinset_inj : G₁.edgeFinset = G₂.edgeFinset ↔ G₁ = G₂ := by simp
theorem edgeFinset_subset_edgeFinset : G₁.edgeFinset ⊆ G₂.edgeFinset ↔ G₁ ≤ G₂ := by simp
theorem edgeFinset_ssubset_edgeFinset : G₁.edgeFinset ⊂ G₂.edgeFinset ↔ G₁ < G₂ := by simp
@[gcongr] alias ⟨_, edgeFinset_mono⟩ := edgeFinset_subset_edgeFinset
alias ⟨_, edgeFinset_strict_mono⟩ := edgeFinset_ssubset_edgeFinset
attribute [mono] edgeFinset_mono edgeFinset_strict_mono
@[simp]
theorem edgeFinset_bot : (⊥ : SimpleGraph V).edgeFinset = ∅ := by simp [edgeFinset]
@[simp]
theorem edgeFinset_sup [Fintype (edgeSet (G₁ ⊔ G₂))] [DecidableEq V] :
(G₁ ⊔ G₂).edgeFinset = G₁.edgeFinset ∪ G₂.edgeFinset := by simp [edgeFinset]
@[simp]
theorem edgeFinset_inf [DecidableEq V] : (G₁ ⊓ G₂).edgeFinset = G₁.edgeFinset ∩ G₂.edgeFinset := by
simp [edgeFinset]
@[simp]
theorem edgeFinset_sdiff [DecidableEq V] :
(G₁ \ G₂).edgeFinset = G₁.edgeFinset \ G₂.edgeFinset := by simp [edgeFinset]
lemma disjoint_edgeFinset : Disjoint G₁.edgeFinset G₂.edgeFinset ↔ Disjoint G₁ G₂ := by
simp_rw [← Finset.disjoint_coe, coe_edgeFinset, disjoint_edgeSet]
lemma edgeFinset_eq_empty : G.edgeFinset = ∅ ↔ G = ⊥ := by
rw [← edgeFinset_bot, edgeFinset_inj]
lemma edgeFinset_nonempty : G.edgeFinset.Nonempty ↔ G ≠ ⊥ := by
rw [Finset.nonempty_iff_ne_empty, edgeFinset_eq_empty.ne]
theorem edgeFinset_card : #G.edgeFinset = Fintype.card G.edgeSet :=
Set.toFinset_card _
@[simp]
theorem edgeSet_univ_card : #(univ : Finset G.edgeSet) = #G.edgeFinset :=
Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset
variable [Fintype V]
@[simp]
theorem edgeFinset_top [DecidableEq V] :
(⊤ : SimpleGraph V).edgeFinset = ({e | ¬e.IsDiag} : Finset _) := by simp [← coe_inj]
/-- The complete graph on `n` vertices has `n.choose 2` edges. -/
theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] :
#(⊤ : SimpleGraph V).edgeFinset = (Fintype.card V).choose 2 := by
simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag]
/-- Any graph on `n` vertices has at most `n.choose 2` edges. -/
theorem card_edgeFinset_le_card_choose_two : #G.edgeFinset ≤ (Fintype.card V).choose 2 := by
classical
rw [← card_edgeFinset_top_eq_card_choose_two]
exact card_le_card (edgeFinset_mono le_top)
end EdgeFinset
section FiniteAt
/-!
## Finiteness at a vertex
This section contains definitions and lemmas concerning vertices that
have finitely many adjacent vertices. We denote this condition by
`Fintype (G.neighborSet v)`.
We define `G.neighborFinset v` to be the `Finset` version of `G.neighborSet v`.
Use `neighborFinset_eq_filter` to rewrite this definition as a `Finset.filter` expression.
-/
variable (v) [Fintype (G.neighborSet v)]
/-- `G.neighbors v` is the `Finset` version of `G.Adj v` in case `G` is
locally finite at `v`. -/
def neighborFinset : Finset V :=
(G.neighborSet v).toFinset
theorem neighborFinset_def : G.neighborFinset v = (G.neighborSet v).toFinset :=
rfl
@[simp]
theorem mem_neighborFinset (w : V) : w ∈ G.neighborFinset v ↔ G.Adj v w :=
Set.mem_toFinset
theorem not_mem_neighborFinset_self : v ∉ G.neighborFinset v := by simp
theorem neighborFinset_disjoint_singleton : Disjoint (G.neighborFinset v) {v} :=
Finset.disjoint_singleton_right.mpr <| not_mem_neighborFinset_self _ _
theorem singleton_disjoint_neighborFinset : Disjoint {v} (G.neighborFinset v) :=
Finset.disjoint_singleton_left.mpr <| not_mem_neighborFinset_self _ _
/-- `G.degree v` is the number of vertices adjacent to `v`. -/
def degree : ℕ := #(G.neighborFinset v)
@[simp]
theorem card_neighborFinset_eq_degree : #(G.neighborFinset v) = G.degree v := rfl
@[simp]
theorem card_neighborSet_eq_degree : Fintype.card (G.neighborSet v) = G.degree v :=
(Set.toFinset_card _).symm
theorem degree_pos_iff_exists_adj : 0 < G.degree v ↔ ∃ w, G.Adj v w := by
simp only [degree, card_pos, Finset.Nonempty, mem_neighborFinset]
theorem degree_pos_iff_mem_support : 0 < G.degree v ↔ v ∈ G.support := by
rw [G.degree_pos_iff_exists_adj v, mem_support]
theorem degree_eq_zero_iff_not_mem_support : G.degree v = 0 ↔ v ∉ G.support := by
rw [← G.degree_pos_iff_mem_support v, Nat.pos_iff_ne_zero, not_ne_iff]
theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] :
Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by
classical
rw [← card_neighborSet_union_compl_neighborSet G v, Set.toFinset_union]
simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v))]
instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) :=
Fintype.ofEquiv (G.neighborSet v) (G.incidenceSetEquivNeighborSet v).symm
/-- This is the `Finset` version of `incidenceSet`. -/
def incidenceFinset [DecidableEq V] : Finset (Sym2 V) :=
(G.incidenceSet v).toFinset
@[simp]
theorem card_incidenceSet_eq_degree [DecidableEq V] :
Fintype.card (G.incidenceSet v) = G.degree v := by
rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v)]
simp
@[simp]
theorem card_incidenceFinset_eq_degree [DecidableEq V] : #(G.incidenceFinset v) = G.degree v := by
rw [← G.card_incidenceSet_eq_degree]
apply Set.toFinset_card
@[simp]
theorem mem_incidenceFinset [DecidableEq V] (e : Sym2 V) :
e ∈ G.incidenceFinset v ↔ e ∈ G.incidenceSet v :=
Set.mem_toFinset
theorem incidenceFinset_eq_filter [DecidableEq V] [Fintype G.edgeSet] :
G.incidenceFinset v = {e ∈ G.edgeFinset | v ∈ e} := by
ext e
induction e
simp [mk'_mem_incidenceSet_iff]
variable {G v}
/-- If `G ≤ H` then `G.degree v ≤ H.degree v` for any vertex `v`. -/
lemma degree_le_of_le {H : SimpleGraph V} [Fintype (H.neighborSet v)] (hle : G ≤ H) :
G.degree v ≤ H.degree v := by
simp_rw [← card_neighborSet_eq_degree]
exact Set.card_le_card fun v hv => hle hv
end FiniteAt
section LocallyFinite
/-- A graph is locally finite if every vertex has a finite neighbor set. -/
abbrev LocallyFinite :=
∀ v : V, Fintype (G.neighborSet v)
variable [LocallyFinite G]
/-- A locally finite simple graph is regular of degree `d` if every vertex has degree `d`. -/
def IsRegularOfDegree (d : ℕ) : Prop :=
∀ v : V, G.degree v = d
variable {G}
theorem IsRegularOfDegree.degree_eq {d : ℕ} (h : G.IsRegularOfDegree d) (v : V) : G.degree v = d :=
h v
theorem IsRegularOfDegree.compl [Fintype V] [DecidableEq V] {G : SimpleGraph V} [DecidableRel G.Adj]
{k : ℕ} (h : G.IsRegularOfDegree k) : Gᶜ.IsRegularOfDegree (Fintype.card V - 1 - k) := by
intro v
rw [degree_compl, h v]
end LocallyFinite
section Finite
variable [Fintype V]
instance neighborSetFintype [DecidableRel G.Adj] (v : V) : Fintype (G.neighborSet v) :=
@Subtype.fintype _ (· ∈ G.neighborSet v)
(by
simp_rw [mem_neighborSet]
infer_instance)
_
theorem neighborFinset_eq_filter {v : V} [DecidableRel G.Adj] :
G.neighborFinset v = ({w | G.Adj v w} : Finset _) := by ext; simp
theorem neighborFinset_compl [DecidableEq V] [DecidableRel G.Adj] (v : V) :
Gᶜ.neighborFinset v = (G.neighborFinset v)ᶜ \ {v} := by
simp only [neighborFinset, neighborSet_compl, Set.toFinset_diff, Set.toFinset_compl,
Set.toFinset_singleton]
@[simp]
theorem complete_graph_degree [DecidableEq V] (v : V) :
(⊤ : SimpleGraph V).degree v = Fintype.card V - 1 := by
simp_rw [degree, neighborFinset_eq_filter, top_adj, filter_ne]
rw [card_erase_of_mem (mem_univ v), card_univ]
theorem bot_degree (v : V) : (⊥ : SimpleGraph V).degree v = 0 := by
simp_rw [degree, neighborFinset_eq_filter, bot_adj, filter_False]
exact Finset.card_empty
theorem IsRegularOfDegree.top [DecidableEq V] :
(⊤ : SimpleGraph V).IsRegularOfDegree (Fintype.card V - 1) := by
intro v
simp
/-- The minimum degree of all vertices (and `0` if there are no vertices).
The key properties of this are given in `exists_minimal_degree_vertex`, `minDegree_le_degree`
and `le_minDegree_of_forall_le_degree`. -/
def minDegree [DecidableRel G.Adj] : ℕ :=
WithTop.untopD 0 (univ.image fun v => G.degree v).min
/-- There exists a vertex of minimal degree. Note the assumption of being nonempty is necessary, as
the lemma implies there exists a vertex. -/
theorem exists_minimal_degree_vertex [DecidableRel G.Adj] [Nonempty V] :
∃ v, G.minDegree = G.degree v := by
obtain ⟨t, ht : _ = _⟩ := min_of_nonempty (univ_nonempty.image fun v => G.degree v)
obtain ⟨v, _, rfl⟩ := mem_image.mp (mem_of_min ht)
exact ⟨v, by simp [minDegree, ht]⟩
/-- The minimum degree in the graph is at most the degree of any particular vertex. -/
theorem minDegree_le_degree [DecidableRel G.Adj] (v : V) : G.minDegree ≤ G.degree v := by
obtain ⟨t, ht⟩ := Finset.min_of_mem (mem_image_of_mem (fun v => G.degree v) (mem_univ v))
have := Finset.min_le_of_eq (mem_image_of_mem _ (mem_univ v)) ht
rwa [minDegree, ht]
/-- In a nonempty graph, if `k` is at most the degree of every vertex, it is at most the minimum
degree. Note the assumption that the graph is nonempty is necessary as long as `G.minDegree` is
defined to be a natural. -/
theorem le_minDegree_of_forall_le_degree [DecidableRel G.Adj] [Nonempty V] (k : ℕ)
(h : ∀ v, k ≤ G.degree v) : k ≤ G.minDegree := by
rcases G.exists_minimal_degree_vertex with ⟨v, hv⟩
rw [hv]
apply h
/-- If there are no vertices then the `minDegree` is zero. -/
@[simp]
lemma minDegree_of_isEmpty [DecidableRel G.Adj] [IsEmpty V] : G.minDegree = 0 := by
rw [minDegree, WithTop.untopD_eq_self_iff]
simp
variable {G} in
/-- If `G` is a subgraph of `H` then `G.minDegree ≤ H.minDegree`. -/
lemma minDegree_le_minDegree {H : SimpleGraph V} [DecidableRel G.Adj] [DecidableRel H.Adj]
(hle : G ≤ H) : G.minDegree ≤ H.minDegree := by
by_cases hne : Nonempty V
· apply le_minDegree_of_forall_le_degree
exact fun v ↦ (G.minDegree_le_degree v).trans (G.degree_le_of_le hle)
· rw [not_nonempty_iff] at hne
simp
/-- The maximum degree of all vertices (and `0` if there are no vertices).
The key properties of this are given in `exists_maximal_degree_vertex`, `degree_le_maxDegree`
and `maxDegree_le_of_forall_degree_le`. -/
def maxDegree [DecidableRel G.Adj] : ℕ :=
Option.getD (univ.image fun v => G.degree v).max 0
/-- There exists a vertex of maximal degree. Note the assumption of being nonempty is necessary, as
the lemma implies there exists a vertex. -/
theorem exists_maximal_degree_vertex [DecidableRel G.Adj] [Nonempty V] :
∃ v, G.maxDegree = G.degree v := by
obtain ⟨t, ht⟩ := max_of_nonempty (univ_nonempty.image fun v => G.degree v)
have ht₂ := mem_of_max ht
simp only [mem_image, mem_univ, exists_prop_of_true] at ht₂
rcases ht₂ with ⟨v, _, rfl⟩
refine ⟨v, ?_⟩
rw [maxDegree, ht]
rfl
/-- The maximum degree in the graph is at least the degree of any particular vertex. -/
| Mathlib/Combinatorics/SimpleGraph/Finite.lean | 351 | 354 | theorem degree_le_maxDegree [DecidableRel G.Adj] (v : V) : G.degree v ≤ G.maxDegree := by | obtain ⟨t, ht : _ = _⟩ := Finset.max_of_mem (mem_image_of_mem (fun v => G.degree v) (mem_univ v))
have := Finset.le_max_of_eq (mem_image_of_mem _ (mem_univ v)) ht
rwa [maxDegree, ht] |
/-
Copyright (c) 2022 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster
-/
import Mathlib.Algebra.CharP.LocalRing
import Mathlib.RingTheory.Ideal.Quotient.Basic
import Mathlib.Tactic.FieldSimp
/-!
# Equal and mixed characteristic
In commutative algebra, some statements are simpler when working over a `ℚ`-algebra `R`, in which
case one also says that the ring has "equal characteristic zero". A ring that is not a
`ℚ`-algebra has either positive characteristic or there exists a prime ideal `I ⊂ R` such that
the quotient `R ⧸ I` has positive characteristic `p > 0`. In this case one speaks of
"mixed characteristic `(0, p)`", where `p` is only unique if `R` is local.
Examples of mixed characteristic rings are `ℤ` or the `p`-adic integers/numbers.
This file provides the main theorem `split_by_characteristic` that splits any proposition `P` into
the following three cases:
1) Positive characteristic: `CharP R p` (where `p ≠ 0`)
2) Equal characteristic zero: `Algebra ℚ R`
3) Mixed characteristic: `MixedCharZero R p` (where `p` is prime)
## Main definitions
- `MixedCharZero` : A ring has mixed characteristic `(0, p)` if it has characteristic zero
and there exists an ideal such that the quotient `R ⧸ I` has characteristic `p`.
## Main results
- `split_equalCharZero_mixedCharZero` : Split a statement into equal/mixed characteristic zero.
This main theorem has the following three corollaries which include the positive
characteristic case for convenience:
- `split_by_characteristic` : Generally consider positive char `p ≠ 0`.
- `split_by_characteristic_domain` : In a domain we can assume that `p` is prime.
- `split_by_characteristic_localRing` : In a local ring we can assume that `p` is a prime power.
## Implementation Notes
We use the terms `EqualCharZero` and `AlgebraRat` despite not being such definitions in mathlib.
The former refers to the statement `∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)`, the latter
refers to the existence of an instance `[Algebra ℚ R]`. The two are shown to be
equivalent conditions.
## TODO
- Relate mixed characteristic in a local ring to p-adic numbers [NumberTheory.PAdics].
-/
variable (R : Type*) [CommRing R]
/-!
### Mixed characteristic
-/
/--
A ring of characteristic zero is of "mixed characteristic `(0, p)`" if there exists an ideal
such that the quotient `R ⧸ I` has characteristic `p`.
**Remark:** For `p = 0`, `MixedChar R 0` is a meaningless definition (i.e. satisfied by any ring)
as `R ⧸ ⊥ ≅ R` has by definition always characteristic zero.
One could require `(I ≠ ⊥)` in the definition, but then `MixedChar R 0` would mean something
like `ℤ`-algebra of extension degree `≥ 1` and would be completely independent from
whether something is a `ℚ`-algebra or not (e.g. `ℚ[X]` would satisfy it but `ℚ` wouldn't).
-/
class MixedCharZero (p : ℕ) : Prop where
[toCharZero : CharZero R]
charP_quotient : ∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p
namespace MixedCharZero
/--
Reduction to `p` prime: When proving any statement `P` about mixed characteristic rings we
can always assume that `p` is prime.
-/
theorem reduce_to_p_prime {P : Prop} :
(∀ p > 0, MixedCharZero R p → P) ↔ ∀ p : ℕ, p.Prime → MixedCharZero R p → P := by
constructor
· intro h q q_prime q_mixedChar
exact h q (Nat.Prime.pos q_prime) q_mixedChar
· intro h q q_pos q_mixedChar
rcases q_mixedChar.charP_quotient with ⟨I, hI_ne_top, _⟩
-- Krull's Thm: There exists a prime ideal `P` such that `I ≤ P`
rcases Ideal.exists_le_maximal I hI_ne_top with ⟨M, hM_max, h_IM⟩
let r := ringChar (R ⧸ M)
have r_pos : r ≠ 0 := by
have q_zero :=
congr_arg (Ideal.Quotient.factor h_IM) (CharP.cast_eq_zero (R ⧸ I) q)
simp only [map_natCast, map_zero] at q_zero
apply ne_zero_of_dvd_ne_zero (ne_of_gt q_pos)
exact (CharP.cast_eq_zero_iff (R ⧸ M) r q).mp q_zero
have r_prime : Nat.Prime r :=
or_iff_not_imp_right.1 (CharP.char_is_prime_or_zero (R ⧸ M) r) r_pos
apply h r r_prime
have : CharZero R := q_mixedChar.toCharZero
exact ⟨⟨M, hM_max.ne_top, ringChar.of_eq rfl⟩⟩
/--
Reduction to `I` prime ideal: When proving statements about mixed characteristic rings,
after we reduced to `p` prime, we can assume that the ideal `I` in the definition is maximal.
-/
theorem reduce_to_maximal_ideal {p : ℕ} (hp : Nat.Prime p) :
(∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p) ↔ ∃ I : Ideal R, I.IsMaximal ∧ CharP (R ⧸ I) p := by
constructor
· intro g
rcases g with ⟨I, ⟨hI_not_top, _⟩⟩
-- Krull's Thm: There exists a prime ideal `M` such that `I ≤ M`.
rcases Ideal.exists_le_maximal I hI_not_top with ⟨M, ⟨hM_max, hM_ge⟩⟩
use M
constructor
· exact hM_max
· cases CharP.exists (R ⧸ M) with
| intro r hr =>
convert hr
have r_dvd_p : r ∣ p := by
rw [← CharP.cast_eq_zero_iff (R ⧸ M) r p]
convert congr_arg (Ideal.Quotient.factor hM_ge) (CharP.cast_eq_zero (R ⧸ I) p)
symm
apply (Nat.Prime.eq_one_or_self_of_dvd hp r r_dvd_p).resolve_left
exact CharP.char_ne_one (R ⧸ M) r
· intro ⟨I, hI_max, h_charP⟩
use I
exact ⟨Ideal.IsMaximal.ne_top hI_max, h_charP⟩
end MixedCharZero
/-!
### Equal characteristic zero
A commutative ring `R` has "equal characteristic zero" if it satisfies one of the following
equivalent properties:
1) `R` is a `ℚ`-algebra.
2) The quotient `R ⧸ I` has characteristic zero for any proper ideal `I ⊂ R`.
3) `R` has characteristic zero and does not have mixed characteristic for any prime `p`.
We show `(1) ↔ (2) ↔ (3)`, and most of the following is concerned with constructing
an explicit algebra map `ℚ →+* R` (given by `x ↦ (x.num : R) /ₚ ↑x.pnatDen`)
for the direction `(1) ← (2)`.
Note: Property `(2)` is denoted as `EqualCharZero` in the statement names below.
-/
namespace EqualCharZero
/-- `ℚ`-algebra implies equal characteristic. -/
theorem of_algebraRat [Algebra ℚ R] : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by
intro I hI
constructor
intro a b h_ab
contrapose! hI
-- `↑a - ↑b` is a unit contained in `I`, which contradicts `I ≠ ⊤`.
refine I.eq_top_of_isUnit_mem ?_ (IsUnit.map (algebraMap ℚ R) (IsUnit.mk0 (a - b : ℚ) ?_))
· simpa only [← Ideal.Quotient.eq_zero_iff_mem, map_sub, sub_eq_zero, map_natCast]
simpa only [Ne, sub_eq_zero] using (@Nat.cast_injective ℚ _ _).ne hI
section ConstructionAlgebraRat
variable {R}
/-- Internal: Not intended to be used outside this local construction. -/
theorem PNat.isUnit_natCast [h : Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))]
(n : ℕ+) : IsUnit (n : R) := by
-- `n : R` is a unit iff `(n)` is not a proper ideal in `R`.
rw [← Ideal.span_singleton_eq_top]
-- So by contrapositive, we should show the quotient does not have characteristic zero.
apply not_imp_comm.mp (h.elim (Ideal.span {↑n}))
intro h_char_zero
-- In particular, the image of `n` in the quotient should be nonzero.
apply h_char_zero.cast_injective.ne n.ne_zero
-- But `n` generates the ideal, so its image is clearly zero.
rw [← map_natCast (Ideal.Quotient.mk _), Nat.cast_zero, Ideal.Quotient.eq_zero_iff_mem]
exact Ideal.subset_span (Set.mem_singleton _)
@[coe]
noncomputable def pnatCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ℕ+ → Rˣ :=
fun n => (PNat.isUnit_natCast n).unit
/-- Internal: Not intended to be used outside this local construction. -/
noncomputable instance coePNatUnits
[Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : Coe ℕ+ Rˣ :=
⟨EqualCharZero.pnatCast⟩
/-- Internal: Not intended to be used outside this local construction. -/
@[simp]
theorem pnatCast_one [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ((1 : ℕ+) : Rˣ) = 1 := by
apply Units.ext
rw [Units.val_one]
change ((PNat.isUnit_natCast (R := R) 1).unit : R) = 1
rw [IsUnit.unit_spec (PNat.isUnit_natCast 1)]
rw [PNat.one_coe, Nat.cast_one]
/-- Internal: Not intended to be used outside this local construction. -/
@[simp]
| Mathlib/Algebra/CharP/MixedCharZero.lean | 201 | 206 | theorem pnatCast_eq_natCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] (n : ℕ+) :
((n : Rˣ) : R) = ↑n := by | change ((PNat.isUnit_natCast (R := R) n).unit : R) = ↑n
simp only [IsUnit.unit_spec]
/-- Equal characteristic implies `ℚ`-algebra. -/ |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
-/
import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Nat.Init
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.SplitIfs
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {α β G M : Type*}
section ite
variable [Pow α β]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup α]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`."]
theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`."]
theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩
section MulOneClass
variable [MulOneClass M]
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * ·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [← mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : ℕ}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"]
lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ', mul_right_iterate]
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a ↔ b = 1 := calc
a * b = a ↔ a * b = a * 1 := by rw [mul_one]
_ ↔ b = 1 := mul_left_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left
@[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_eq_self
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b ↔ b = 1 :=
eq_comm.trans mul_eq_left
@[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_right
@[to_additive]
theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not
@[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left
@[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_ne_self
@[to_additive]
theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_right
end LeftCancelMonoid
section RightCancelMonoid
variable [RightCancelMonoid M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b ↔ a = 1 := calc
a * b = b ↔ a * b = 1 * b := by rw [one_mul]
_ ↔ a = 1 := mul_right_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right
@[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_eq_self
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b ↔ a = 1 :=
eq_comm.trans mul_eq_right
@[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_left
@[to_additive]
theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not
@[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right
@[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_ne_self
@[to_additive]
theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_left
end RightCancelMonoid
section CancelCommMonoid
variable [CancelCommMonoid α] {a b c d : α}
@[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop
@[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop
end CancelCommMonoid
section InvolutiveInv
variable [InvolutiveInv G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_involutive : Function.Involutive (Inv.inv : G → G) :=
inv_inv
@[to_additive (attr := simp)]
theorem inv_surjective : Function.Surjective (Inv.inv : G → G) :=
inv_involutive.surjective
@[to_additive]
theorem inv_injective : Function.Injective (Inv.inv : G → G) :=
inv_involutive.injective
@[to_additive (attr := simp)]
theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b :=
inv_injective.eq_iff
@[to_additive]
theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ :=
⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩
variable (G)
@[to_additive]
theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G :=
inv_involutive.comp_self
@[to_additive]
theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
@[to_additive]
theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
end InvolutiveInv
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by
rw [div_eq_mul_inv, one_mul, div_eq_mul_inv]
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c :=
(mul_div_assoc _ _ _).symm
@[to_additive]
theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv]
@[to_additive]
theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div]
end DivInvMonoid
section DivInvOneMonoid
variable [DivInvOneMonoid G]
@[to_additive (attr := simp)]
theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv]
@[to_additive]
theorem one_div_one : (1 : G) / 1 = 1 :=
div_one _
end DivInvOneMonoid
section DivisionMonoid
variable [DivisionMonoid α] {a b c d : α}
attribute [local simp] mul_assoc div_eq_mul_inv
@[to_additive]
theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ :=
(inv_eq_of_mul_eq_one_right h).symm
@[to_additive]
theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_left h, one_div]
@[to_additive]
theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_right h, one_div]
@[to_additive]
theorem eq_of_div_eq_one (h : a / b = 1) : a = b :=
inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv]
@[to_additive]
lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 :=
mt eq_of_div_eq_one
variable (a b c)
@[to_additive]
theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp
@[to_additive]
theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp
@[to_additive (attr := simp)]
theorem inv_div : (a / b)⁻¹ = b / a := by simp
@[to_additive]
theorem one_div_div : 1 / (a / b) = b / a := by simp
@[to_additive]
theorem one_div_one_div : 1 / (1 / a) = a := by simp
@[to_additive]
theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c :=
inv_inj.symm.trans <| by simp only [inv_div]
@[to_additive]
instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α :=
{ DivisionMonoid.toDivInvMonoid with
inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm }
@[to_additive (attr := simp)]
lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹
| 0 => by rw [pow_zero, pow_zero, inv_one]
| n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev]
-- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`.
@[to_additive zsmul_zero, simp]
lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1
| (n : ℕ) => by rw [zpow_natCast, one_pow]
| .negSucc n => by rw [zpow_negSucc, one_pow, inv_one]
@[to_additive (attr := simp) neg_zsmul]
lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹
| (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _
| 0 => by simp
| Int.negSucc n => by
rw [zpow_negSucc, inv_inv, ← zpow_natCast]
rfl
@[to_additive neg_one_zsmul_add]
lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by
simp only [zpow_neg, zpow_one, mul_inv_rev]
@[to_additive zsmul_neg]
lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow]
| .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow]
@[to_additive (attr := simp) zsmul_neg']
lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg]
@[to_additive nsmul_zero_sub]
lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow]
@[to_additive zsmul_zero_sub]
lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow]
variable {a b c}
@[to_additive (attr := simp)]
theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=
inv_injective.eq_iff' inv_one
@[to_additive (attr := simp)]
theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 :=
eq_comm.trans inv_eq_one
@[to_additive]
theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=
inv_eq_one.not
@[to_additive]
theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by
rw [← one_div_one_div a, h, one_div_one_div]
-- Note that `mul_zsmul` and `zpow_mul` have the primes swapped
-- when additivised since their argument order,
-- and therefore the more "natural" choice of lemma, is reversed.
@[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ), (n : ℕ) => by
rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast]
rfl
| (m : ℕ), .negSucc n => by
rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj,
← zpow_natCast]
| .negSucc m, (n : ℕ) => by
rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow,
inv_inj, ← zpow_natCast]
| .negSucc m, .negSucc n => by
rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ←
zpow_natCast]
rfl
@[to_additive mul_zsmul]
lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul]
@[to_additive]
theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul']
variable (a b c)
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp
@[to_additive (attr := simp)]
theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp
@[to_additive]
theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by
simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α] (a b c d : α)
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive neg_add]
theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp
@[to_additive]
theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp
@[to_additive]
theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp
@[to_additive]
theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp
@[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp
@[to_additive]
theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp
@[to_additive]
theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp
@[to_additive]
theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp
@[to_additive]
theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp
@[to_additive]
theorem div_right_comm : a / b / c = a / c / b := by simp
@[to_additive, field_simps]
| Mathlib/Algebra/Group/Basic.lean | 569 | 570 | theorem div_div : a / b / c = a / (b * c) := by | simp |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.Dynamics.Minimal
import Mathlib.GroupTheory.GroupAction.Hom
import Mathlib.MeasureTheory.Group.MeasurableEquiv
import Mathlib.MeasureTheory.Measure.Regular
import Mathlib.MeasureTheory.Group.Defs
import Mathlib.Order.Filter.EventuallyConst
/-!
# Measures invariant under group actions
A measure `μ : Measure α` is said to be *invariant* under an action of a group `G` if scalar
multiplication by `c : G` is a measure preserving map for all `c`. In this file we define a
typeclass for measures invariant under action of an (additive or multiplicative) group and prove
some basic properties of such measures.
-/
open scoped ENNReal NNReal Pointwise Topology
open MeasureTheory.Measure Set Function Filter
namespace MeasureTheory
universe u v w
variable {G : Type u} {M : Type v} {α : Type w}
namespace SMulInvariantMeasure
@[to_additive]
instance zero [MeasurableSpace α] [SMul M α] : SMulInvariantMeasure M α (0 : Measure α) :=
⟨fun _ _ _ => rfl⟩
variable [SMul M α] {m : MeasurableSpace α} {μ ν : Measure α}
@[to_additive]
instance add [SMulInvariantMeasure M α μ] [SMulInvariantMeasure M α ν] :
SMulInvariantMeasure M α (μ + ν) :=
⟨fun c _s hs =>
show _ + _ = _ + _ from
congr_arg₂ (· + ·) (measure_preimage_smul c hs) (measure_preimage_smul c hs)⟩
@[to_additive]
instance smul [SMulInvariantMeasure M α μ] (c : ℝ≥0∞) : SMulInvariantMeasure M α (c • μ) :=
⟨fun a _s hs => show c • _ = c • _ from congr_arg (c • ·) (measure_preimage_smul a hs)⟩
@[to_additive]
instance smul_nnreal [SMulInvariantMeasure M α μ] (c : ℝ≥0) : SMulInvariantMeasure M α (c • μ) :=
SMulInvariantMeasure.smul c
end SMulInvariantMeasure
section AE_smul
variable {m : MeasurableSpace α} [SMul G α]
(μ : Measure α) [SMulInvariantMeasure G α μ] {s : Set α}
/-- See also `measure_preimage_smul_of_nullMeasurableSet` and `measure_preimage_smul`. -/
@[to_additive "See also `measure_preimage_smul_of_nullMeasurableSet` and `measure_preimage_smul`."]
theorem measure_preimage_smul_le (c : G) (s : Set α) : μ ((c • ·) ⁻¹' s) ≤ μ s :=
(outerMeasure_le_iff (m := .map (c • ·) μ.1)).2
(fun _s hs ↦ (SMulInvariantMeasure.measure_preimage_smul _ hs).le) _
/-- See also `smul_ae`. -/
@[to_additive "See also `vadd_ae`."]
theorem tendsto_smul_ae (c : G) : Filter.Tendsto (c • ·) (ae μ) (ae μ) := fun _s hs ↦
eq_bot_mono (measure_preimage_smul_le μ c _) hs
variable {μ}
@[to_additive]
theorem measure_preimage_smul_null (h : μ s = 0) (c : G) : μ ((c • ·) ⁻¹' s) = 0 :=
eq_bot_mono (measure_preimage_smul_le μ c _) h
@[to_additive]
theorem measure_preimage_smul_of_nullMeasurableSet (hs : NullMeasurableSet s μ) (c : G) :
μ ((c • ·) ⁻¹' s) = μ s := by
rw [← measure_toMeasurable s,
← SMulInvariantMeasure.measure_preimage_smul c (measurableSet_toMeasurable μ s)]
exact measure_congr (tendsto_smul_ae μ c hs.toMeasurable_ae_eq) |>.symm
end AE_smul
section AE
variable {m : MeasurableSpace α} [Group G] [MulAction G α]
(μ : Measure α) [SMulInvariantMeasure G α μ]
@[to_additive (attr := simp)]
theorem measure_preimage_smul (c : G) (s : Set α) : μ ((c • ·) ⁻¹' s) = μ s :=
(measure_preimage_smul_le μ c s).antisymm <| by
simpa [preimage_preimage] using measure_preimage_smul_le μ c⁻¹ ((c • ·) ⁻¹' s)
@[to_additive (attr := simp)]
theorem measure_smul (c : G) (s : Set α) : μ (c • s) = μ s := by
simpa only [preimage_smul_inv] using measure_preimage_smul μ c⁻¹ s
variable {μ}
@[to_additive]
theorem measure_smul_eq_zero_iff {s} (c : G) : μ (c • s) = 0 ↔ μ s = 0 := by
rw [measure_smul]
@[to_additive]
theorem measure_smul_null {s} (h : μ s = 0) (c : G) : μ (c • s) = 0 :=
(measure_smul_eq_zero_iff _).2 h
@[to_additive (attr := simp)]
theorem smul_mem_ae (c : G) {s : Set α} : c • s ∈ ae μ ↔ s ∈ ae μ := by
simp only [mem_ae_iff, ← smul_set_compl, measure_smul_eq_zero_iff]
@[to_additive (attr := simp)]
theorem smul_ae (c : G) : c • ae μ = ae μ := by
ext s
simp only [mem_smul_filter, preimage_smul, smul_mem_ae]
@[to_additive (attr := simp)]
theorem eventuallyConst_smul_set_ae (c : G) {s : Set α} :
EventuallyConst (c • s : Set α) (ae μ) ↔ EventuallyConst s (ae μ) := by
rw [← preimage_smul_inv, eventuallyConst_preimage, Filter.map_smul, smul_ae]
@[to_additive (attr := simp)]
theorem smul_set_ae_le (c : G) {s t : Set α} : c • s ≤ᵐ[μ] c • t ↔ s ≤ᵐ[μ] t := by
simp only [ae_le_set, ← smul_set_sdiff, measure_smul_eq_zero_iff]
@[to_additive (attr := simp)]
theorem smul_set_ae_eq (c : G) {s t : Set α} : c • s =ᵐ[μ] c • t ↔ s =ᵐ[μ] t := by
simp only [Filter.eventuallyLE_antisymm_iff, smul_set_ae_le]
end AE
section MeasurableSMul
variable {m : MeasurableSpace α} [MeasurableSpace M] [SMul M α] [MeasurableSMul M α] (c : M)
(μ : Measure α) [SMulInvariantMeasure M α μ]
@[to_additive (attr := simp)]
theorem measurePreserving_smul : MeasurePreserving (c • ·) μ μ :=
{ measurable := measurable_const_smul c
map_eq := by
ext1 s hs
rw [map_apply (measurable_const_smul c) hs]
exact SMulInvariantMeasure.measure_preimage_smul c hs }
@[to_additive (attr := simp)]
protected theorem map_smul : map (c • ·) μ = μ :=
(measurePreserving_smul c μ).map_eq
end MeasurableSMul
@[to_additive]
theorem MeasurePreserving.smulInvariantMeasure_iterateMulAct
{f : α → α} {_ : MeasurableSpace α} {μ : Measure α} (hf : MeasurePreserving f μ μ) :
SMulInvariantMeasure (IterateMulAct f) α μ :=
⟨fun n _s hs ↦ (hf.iterate n.val).measure_preimage hs.nullMeasurableSet⟩
@[to_additive]
theorem smulInvariantMeasure_iterateMulAct
{f : α → α} {_ : MeasurableSpace α} {μ : Measure α} (hf : Measurable f) :
SMulInvariantMeasure (IterateMulAct f) α μ ↔ MeasurePreserving f μ μ :=
⟨fun _ ↦
have := hf.measurableSMul₂_iterateMulAct
measurePreserving_smul (IterateMulAct.mk (f := f) 1) μ,
MeasurePreserving.smulInvariantMeasure_iterateMulAct⟩
section SMulHomClass
universe uM uN uα uβ
variable {M : Type uM} {N : Type uN} {α : Type uα} {β : Type uβ}
[MeasurableSpace M] [MeasurableSpace N] [MeasurableSpace α] [MeasurableSpace β]
@[to_additive]
theorem smulInvariantMeasure_map [SMul M α] [SMul M β]
[MeasurableSMul M β]
(μ : Measure α) [SMulInvariantMeasure M α μ] (f : α → β)
(hsmul : ∀ (m : M) a, f (m • a) = m • f a) (hf : Measurable f) :
SMulInvariantMeasure M β (map f μ) where
measure_preimage_smul m S hS := calc
map f μ ((m • ·) ⁻¹' S)
_ = μ (f ⁻¹' ((m • ·) ⁻¹' S)) := map_apply hf <| hS.preimage (measurable_const_smul _)
_ = μ ((m • f ·) ⁻¹' S) := by rw [preimage_preimage]
_ = μ ((f <| m • ·) ⁻¹' S) := by simp_rw [hsmul]
_ = μ ((m • ·) ⁻¹' (f ⁻¹' S)) := by rw [← preimage_preimage]
_ = μ (f ⁻¹' S) := by rw [SMulInvariantMeasure.measure_preimage_smul m (hS.preimage hf)]
_ = map f μ S := (map_apply hf hS).symm
@[to_additive]
instance smulInvariantMeasure_map_smul [SMul M α] [SMul N α] [SMulCommClass N M α]
[MeasurableSMul M α] [MeasurableSMul N α]
(μ : Measure α) [SMulInvariantMeasure M α μ] (n : N) :
SMulInvariantMeasure M α (map (n • ·) μ) :=
smulInvariantMeasure_map μ _ (smul_comm n) <| measurable_const_smul _
end SMulHomClass
variable (G) {m : MeasurableSpace α} [Group G] [MulAction G α] (μ : Measure α)
variable [MeasurableSpace G] [MeasurableSMul G α] in
/-- Equivalent definitions of a measure invariant under a multiplicative action of a group.
- 0: `SMulInvariantMeasure G α μ`;
- 1: for every `c : G` and a measurable set `s`, the measure of the preimage of `s` under scalar
multiplication by `c` is equal to the measure of `s`;
- 2: for every `c : G` and a measurable set `s`, the measure of the image `c • s` of `s` under
scalar multiplication by `c` is equal to the measure of `s`;
- 3, 4: properties 2, 3 for any set, including non-measurable ones;
- 5: for any `c : G`, scalar multiplication by `c` maps `μ` to `μ`;
- 6: for any `c : G`, scalar multiplication by `c` is a measure preserving map. -/
@[to_additive]
theorem smulInvariantMeasure_tfae :
List.TFAE
[SMulInvariantMeasure G α μ,
∀ (c : G) (s), MeasurableSet s → μ ((c • ·) ⁻¹' s) = μ s,
∀ (c : G) (s), MeasurableSet s → μ (c • s) = μ s,
∀ (c : G) (s), μ ((c • ·) ⁻¹' s) = μ s,
∀ (c : G) (s), μ (c • s) = μ s,
∀ c : G, Measure.map (c • ·) μ = μ,
∀ c : G, MeasurePreserving (c • ·) μ μ] := by
tfae_have 1 ↔ 2 := ⟨fun h => h.1, fun h => ⟨h⟩⟩
tfae_have 1 → 6 := fun h c => (measurePreserving_smul c μ).map_eq
tfae_have 6 → 7 := fun H c => ⟨measurable_const_smul c, H c⟩
tfae_have 7 → 4 := fun H c => (H c).measure_preimage_emb (measurableEmbedding_const_smul c)
tfae_have 4 → 5
| H, c, s => by
rw [← preimage_smul_inv]
apply H
tfae_have 5 → 3 := fun H c s _ => H c s
tfae_have 3 → 2
| H, c, s, hs => by
rw [preimage_smul]
exact H c⁻¹ s hs
tfae_finish
/-- Equivalent definitions of a measure invariant under an additive action of a group.
- 0: `VAddInvariantMeasure G α μ`;
- 1: for every `c : G` and a measurable set `s`, the measure of the preimage of `s` under
vector addition `(c +ᵥ ·)` is equal to the measure of `s`;
- 2: for every `c : G` and a measurable set `s`, the measure of the image `c +ᵥ s` of `s` under
vector addition `(c +ᵥ ·)` is equal to the measure of `s`;
- 3, 4: properties 2, 3 for any set, including non-measurable ones;
- 5: for any `c : G`, vector addition of `c` maps `μ` to `μ`;
- 6: for any `c : G`, vector addition of `c` is a measure preserving map. -/
add_decl_doc vaddInvariantMeasure_tfae
variable {G}
variable [SMulInvariantMeasure G α μ]
variable {μ}
variable [MeasurableSpace G] [MeasurableSMul G α] in
@[to_additive]
theorem NullMeasurableSet.smul {s} (hs : NullMeasurableSet s μ) (c : G) :
NullMeasurableSet (c • s) μ := by
simpa only [← preimage_smul_inv] using
hs.preimage (measurePreserving_smul _ _).quasiMeasurePreserving
section IsMinimal
variable (G)
variable [TopologicalSpace α] [ContinuousConstSMul G α] [MulAction.IsMinimal G α] {K U : Set α}
include G in
/-- If measure `μ` is invariant under a group action and is nonzero on a compact set `K`, then it is
positive on any nonempty open set. In case of a regular measure, one can assume `μ ≠ 0` instead of
`μ K ≠ 0`, see `MeasureTheory.measure_isOpen_pos_of_smulInvariant_of_ne_zero`. -/
@[to_additive]
theorem measure_isOpen_pos_of_smulInvariant_of_compact_ne_zero (hK : IsCompact K) (hμK : μ K ≠ 0)
(hU : IsOpen U) (hne : U.Nonempty) : 0 < μ U :=
let ⟨t, ht⟩ := hK.exists_finite_cover_smul G hU hne
pos_iff_ne_zero.2 fun hμU =>
hμK <|
measure_mono_null ht <|
(measure_biUnion_null_iff t.countable_toSet).2 fun _ _ => by rwa [measure_smul]
/-- If measure `μ` is invariant under an additive group action and is nonzero on a compact set `K`,
then it is positive on any nonempty open set. In case of a regular measure, one can assume `μ ≠ 0`
instead of `μ K ≠ 0`, see `MeasureTheory.measure_isOpen_pos_of_vaddInvariant_of_ne_zero`. -/
add_decl_doc measure_isOpen_pos_of_vaddInvariant_of_compact_ne_zero
include G
@[to_additive]
theorem isLocallyFiniteMeasure_of_smulInvariant (hU : IsOpen U) (hne : U.Nonempty) (hμU : μ U ≠ ∞) :
IsLocallyFiniteMeasure μ :=
⟨fun x =>
let ⟨g, hg⟩ := hU.exists_smul_mem G x hne
⟨(g • ·) ⁻¹' U, (hU.preimage (continuous_id.const_smul _)).mem_nhds hg,
Ne.lt_top <| by rwa [measure_preimage_smul]⟩⟩
variable [Measure.Regular μ]
@[to_additive]
| Mathlib/MeasureTheory/Group/Action.lean | 308 | 321 | theorem measure_isOpen_pos_of_smulInvariant_of_ne_zero (hμ : μ ≠ 0) (hU : IsOpen U)
(hne : U.Nonempty) : 0 < μ U :=
let ⟨_K, hK, hμK⟩ := Regular.exists_isCompact_not_null.mpr hμ
measure_isOpen_pos_of_smulInvariant_of_compact_ne_zero G hK hμK hU hne
@[to_additive]
theorem measure_pos_iff_nonempty_of_smulInvariant (hμ : μ ≠ 0) (hU : IsOpen U) :
0 < μ U ↔ U.Nonempty :=
⟨fun h => nonempty_of_measure_ne_zero h.ne',
measure_isOpen_pos_of_smulInvariant_of_ne_zero G hμ hU⟩
@[to_additive]
theorem measure_eq_zero_iff_eq_empty_of_smulInvariant (hμ : μ ≠ 0) (hU : IsOpen U) :
μ U = 0 ↔ U = ∅ := by | |
/-
Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import Mathlib.Order.Filter.Cofinite
import Mathlib.RingTheory.DedekindDomain.Ideal
import Mathlib.RingTheory.UniqueFactorizationDomain.Finite
/-!
# Factorization of ideals and fractional ideals of Dedekind domains
Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the
maximal ideals of `R`, where the exponents `n_v` are natural numbers.
Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product
`∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define
`FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we
prove some of its properties. If `I = 0`, we define `val_v(I) = 0`.
## Main definitions
- `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of
`R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we
set `val_v(I) = 0`.
## Main results
- `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal.
- `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod
`∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I`
and `v` runs over the maximal ideals of `R`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal,
`a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product
`∏_v v^(val_v(J) - val_v(a))`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional
ideal, then `I` is equal to the product `∏_v v^(val_v(I))`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`,
the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`.
- `FractionalIdeal.finite_factors` : If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many
maximal ideals of `R`.
## Implementation notes
Since we are only interested in the factorization of nonzero fractional ideals, we define
`val_v(0) = 0` so that every `val_v` is in `ℤ` and we can avoid having to use `WithTop ℤ`.
## Tags
dedekind domain, fractional ideal, ideal, factorization
-/
noncomputable section
open scoped nonZeroDivisors
open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum
variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K]
/-! ### Factorization of ideals of Dedekind domains -/
variable [IsDedekindDomain R] (v : HeightOneSpectrum R)
open scoped Classical in
/-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal
power of `v` dividing `I`. -/
def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R :=
v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors
/-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/
theorem Ideal.finite_factors {I : Ideal R} (hI : I ≠ 0) :
{v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by
rw [← Set.finite_coe_iff, Set.coe_setOf]
haveI h_fin := fintypeSubtypeDvd I hI
refine
Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_
intro v w hvw
simp? at hvw says simp only [Subtype.mk.injEq] at hvw
exact Subtype.coe_injective (HeightOneSpectrum.ext hvw)
open scoped Classical in
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the
multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/
theorem Associates.finite_factors {I : Ideal R} (hI : I ≠ 0) :
∀ᶠ v : HeightOneSpectrum R in Filter.cofinite,
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0 := by
have h_supp : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count
(Associates.mk I).factors : ℤ) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by
ext v
simp_rw [Int.natCast_eq_zero]
exact Associates.count_ne_zero_iff_dvd hI v.irreducible
rw [Filter.eventually_cofinite, h_supp]
exact Ideal.finite_factors hI
namespace Ideal
open scoped Classical in
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^(val_v(I))` is not the unit ideal. -/
theorem finite_mulSupport {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite :=
haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I ≠ 1} ⊆
{v : HeightOneSpectrum R |
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) ≠ 0} := by
intro v hv h_zero
have hv' : v.maxPowDividing I = 1 := by
rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero,
pow_zero _]
exact hv hv'
Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset
open scoped Classical in
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/
theorem finite_mulSupport_coe {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)).Finite := by
rw [mulSupport]
simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one]
exact finite_mulSupport hI
open scoped Classical in
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^-(val_v(I))` is not the unit ideal. -/
theorem finite_mulSupport_inv {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^
(-((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ))).Finite := by
rw [mulSupport]
simp_rw [zpow_neg, Ne, inv_eq_one]
exact finite_mulSupport_coe hI
open scoped Classical in
/-- For every nonzero ideal `I` of `v`, `v^(val_v(I) + 1)` does not divide `∏_v v^(val_v(I))`. -/
theorem finprod_not_dvd (I : Ideal R) (hI : I ≠ 0) :
¬v.asIdeal ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors + 1) ∣
∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I := by
have hf := finite_mulSupport hI
have h_ne_zero : v.maxPowDividing I ≠ 0 := pow_ne_zero _ v.ne_bot
rw [← mul_finprod_cond_ne v hf, pow_add, pow_one, finprod_cond_ne _ _ hf]
intro h_contr
have hv_prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime
obtain ⟨w, hw, hvw'⟩ :=
Prime.exists_mem_finset_dvd hv_prime ((mul_dvd_mul_iff_left h_ne_zero).mp h_contr)
have hw_prime : Prime w.asIdeal := Ideal.prime_of_isPrime w.ne_bot w.isPrime
have hvw := Prime.dvd_of_dvd_pow hv_prime hvw'
rw [Prime.dvd_prime_iff_associated hv_prime hw_prime, associated_iff_eq] at hvw
exact (Finset.mem_erase.mp hw).1 (HeightOneSpectrum.ext hvw.symm)
end Ideal
theorem Associates.finprod_ne_zero (I : Ideal R) :
Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I) ≠ 0 := by
classical
rw [Associates.mk_ne_zero, finprod_def]
split_ifs
· rw [Finset.prod_ne_zero_iff]
intro v _
apply pow_ne_zero _ v.ne_bot
· exact one_ne_zero
namespace Ideal
open scoped Classical in
/-- The multiplicity of `v` in `∏_v v^(val_v(I))` equals `val_v(I)`. -/
theorem finprod_count (I : Ideal R) (hI : I ≠ 0) : (Associates.mk v.asIdeal).count
(Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I)).factors =
(Associates.mk v.asIdeal).count (Associates.mk I).factors := by
have h_ne_zero := Associates.finprod_ne_zero I
have hv : Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible
have h_dvd := finprod_mem_dvd v (Ideal.finite_mulSupport hI)
have h_not_dvd := Ideal.finprod_not_dvd v I hI
simp only [IsDedekindDomain.HeightOneSpectrum.maxPowDividing] at h_dvd h_ne_zero h_not_dvd
rw [← Associates.mk_dvd_mk] at h_dvd h_not_dvd
simp only [Associates.dvd_eq_le] at h_dvd h_not_dvd
rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le h_ne_zero hv] at h_dvd h_not_dvd
rw [not_le] at h_not_dvd
apply Nat.eq_of_le_of_lt_succ h_dvd h_not_dvd
/-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`. -/
theorem finprod_heightOneSpectrum_factorization {I : Ideal R} (hI : I ≠ 0) :
∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I = I := by
rw [← associated_iff_eq, ← Associates.mk_eq_mk_iff_associated]
classical
apply Associates.eq_of_eq_counts
· apply Associates.finprod_ne_zero I
· apply Associates.mk_ne_zero.mpr hI
intro v hv
obtain ⟨J, hJv⟩ := Associates.exists_rep v
rw [← hJv, Associates.irreducible_mk] at hv
rw [← hJv]
apply Ideal.finprod_count
⟨J, Ideal.isPrime_of_prime (irreducible_iff_prime.mp hv), Irreducible.ne_zero hv⟩ I hI
variable (K)
open scoped Classical in
/-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`, when both sides are regarded as fractional
ideals of `R`. -/
theorem finprod_heightOneSpectrum_factorization_coe {I : Ideal R} (hI : I ≠ 0) :
(∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)) = I := by
conv_rhs => rw [← Ideal.finprod_heightOneSpectrum_factorization hI]
rw [FractionalIdeal.coeIdeal_finprod R⁰ K (le_refl _)]
simp_rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, FractionalIdeal.coeIdeal_pow,
zpow_natCast]
end Ideal
/-! ### Factorization of fractional ideals of Dedekind domains -/
namespace FractionalIdeal
open Int IsLocalization
open scoped Classical in
/-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that
`I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. -/
theorem finprod_heightOneSpectrum_factorization {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R}
{J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk J).factors -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) = I := by
have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ
have hJ := Ideal.finprod_heightOneSpectrum_factorization_coe K hJ_ne_zero
have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ
have ha := Ideal.finprod_heightOneSpectrum_factorization_coe K ha_ne_zero
rw [haJ, ← div_spanSingleton, div_eq_mul_inv, ← coeIdeal_span_singleton, ← hJ, ← ha,
← finprod_inv_distrib]
simp_rw [← zpow_neg]
rw [← finprod_mul_distrib (Ideal.finite_mulSupport_coe hJ_ne_zero)
(Ideal.finite_mulSupport_inv ha_ne_zero)]
apply finprod_congr
intro v
rw [← zpow_add₀ ((@coeIdeal_ne_zero R _ K _ _ _ _).mpr v.ne_bot), sub_eq_add_neg]
open scoped Classical in
/-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product
`∏_v v^(val_v(r) - val_v(s))`. -/
| Mathlib/RingTheory/DedekindDomain/Factorization.lean | 235 | 250 | theorem finprod_heightOneSpectrum_factorization_principal_fraction {n : R} (hn : n ≠ 0) (d : ↥R⁰) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {n} : Ideal R)).factors -
(Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑d : R)}) :
Ideal R)).factors : ℤ) = spanSingleton R⁰ (mk' K n d) := by | have hd_ne_zero : (algebraMap R K) (d : R) ≠ 0 :=
map_ne_zero_of_mem_nonZeroDivisors _ (IsFractionRing.injective R K) d.property
have h0 : spanSingleton R⁰ (mk' K n d) ≠ 0 := by
rw [spanSingleton_ne_zero_iff, IsFractionRing.mk'_eq_div, ne_eq, div_eq_zero_iff, not_or]
exact ⟨(map_ne_zero_iff (algebraMap R K) (IsFractionRing.injective R K)).mpr hn, hd_ne_zero⟩
have hI : spanSingleton R⁰ (mk' K n d) =
spanSingleton R⁰ ((algebraMap R K) d)⁻¹ * ↑(Ideal.span {n} : Ideal R) := by
rw [coeIdeal_span_singleton, spanSingleton_mul_spanSingleton]
apply congr_arg
rw [IsFractionRing.mk'_eq_div, div_eq_mul_inv, mul_comm]
exact finprod_heightOneSpectrum_factorization h0 hI |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Order.Nonneg.Field
import Mathlib.Data.Rat.Cast.Defs
import Mathlib.Tactic.Positivity.Basic
/-!
# Some exiled lemmas about casting
These lemmas have been removed from `Mathlib.Data.Rat.Cast.Defs`
to avoiding needing to import `Mathlib.Algebra.Field.Basic` there.
In fact, these lemmas don't appear to be used anywhere in Mathlib,
so perhaps this file can simply be deleted.
-/
namespace Rat
variable {α : Type*} [DivisionRing α]
-- Note that this is more general than `(Rat.castHom α).map_pow`.
@[simp, norm_cast]
lemma cast_pow (p : ℚ) (n : ℕ) : ↑(p ^ n) = (p ^ n : α) := by
rw [cast_def, cast_def, den_pow, num_pow, Nat.cast_pow, Int.cast_pow, div_eq_mul_inv, ← inv_pow,
← (Int.cast_commute _ _).mul_pow, ← div_eq_mul_inv]
@[simp]
theorem cast_inv_nat (n : ℕ) : ((n⁻¹ : ℚ) : α) = (n : α)⁻¹ := by
rcases n with - | n
· simp
rw [cast_def, inv_natCast_num, inv_natCast_den, if_neg n.succ_ne_zero,
Int.sign_eq_one_of_pos (Int.ofNat_succ_pos n), Int.cast_one, one_div]
@[simp]
theorem cast_inv_int (n : ℤ) : ((n⁻¹ : ℚ) : α) = (n : α)⁻¹ := by
rcases n with n | n
· simp [ofInt_eq_cast, cast_inv_nat]
· simp only [ofInt_eq_cast, Int.cast_negSucc, ← Nat.cast_succ, cast_neg, inv_neg, cast_inv_nat]
@[simp, norm_cast]
| Mathlib/Data/Rat/Cast/Lemmas.lean | 44 | 51 | theorem cast_nnratCast {K} [DivisionRing K] (q : ℚ≥0) :
((q : ℚ) : K) = (q : K) := by | rw [Rat.cast_def, NNRat.cast_def, NNRat.cast_def]
have hn := @num_div_eq_of_coprime q.num q.den ?hdp q.coprime_num_den
on_goal 1 => have hd := @den_div_eq_of_coprime q.num q.den ?hdp q.coprime_num_den
case hdp => simpa only [Int.ofNat_pos] using q.den_pos
simp only [Int.cast_natCast, Nat.cast_inj] at hn hd
rw [hn, hd, Int.cast_natCast] |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang, Fangming Li
-/
import Mathlib.Algebra.DirectSum.Algebra
import Mathlib.Algebra.DirectSum.Decomposition
import Mathlib.Algebra.DirectSum.Internal
import Mathlib.Algebra.DirectSum.Ring
/-!
# Internally-graded rings and algebras
This file defines the typeclass `GradedAlgebra 𝒜`, for working with an algebra `A` that is
internally graded by a collection of submodules `𝒜 : ι → Submodule R A`.
See the docstring of that typeclass for more information.
## Main definitions
* `GradedRing 𝒜`: the typeclass, which is a combination of `SetLike.GradedMonoid`, and
`DirectSum.Decomposition 𝒜`.
* `GradedAlgebra 𝒜`: A convenience alias for `GradedRing` when `𝒜` is a family of submodules.
* `DirectSum.decomposeRingEquiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of
`DirectSum.decompose 𝒜`.
* `DirectSum.decomposeAlgEquiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of
`DirectSum.decompose 𝒜`.
* `GradedAlgebra.proj 𝒜 i` is the linear map from `A` to its degree `i : ι` component, such that
`proj 𝒜 i x = decompose 𝒜 x i`.
## Implementation notes
For now, we do not have internally-graded semirings and internally-graded rings; these can be
represented with `𝒜 : ι → Submodule ℕ A` and `𝒜 : ι → Submodule ℤ A` respectively, since all
`Semiring`s are ℕ-algebras via `Semiring.toNatAlgebra`, and all `Ring`s are `ℤ`-algebras via
`Ring.toIntAlgebra`.
## Tags
graded algebra, graded ring, graded semiring, decomposition
-/
open DirectSum
variable {ι R A σ : Type*}
section GradedRing
variable [DecidableEq ι] [AddMonoid ι] [CommSemiring R] [Semiring A] [Algebra R A]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
open DirectSum
/-- An internally-graded `R`-algebra `A` is one that can be decomposed into a collection
of `Submodule R A`s indexed by `ι` such that the canonical map `A → ⨁ i, 𝒜 i` is bijective and
respects multiplication, i.e. the product of an element of degree `i` and an element of degree `j`
is an element of degree `i + j`.
Note that the fact that `A` is internally-graded, `GradedAlgebra 𝒜`, implies an externally-graded
algebra structure `DirectSum.GAlgebra R (fun i ↦ ↥(𝒜 i))`, which in turn makes available an
`Algebra R (⨁ i, 𝒜 i)` instance.
-/
class GradedRing (𝒜 : ι → σ) extends SetLike.GradedMonoid 𝒜, DirectSum.Decomposition 𝒜
variable [GradedRing 𝒜]
namespace DirectSum
/-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as
a ring to a direct sum of components. -/
def decomposeRingEquiv : A ≃+* ⨁ i, 𝒜 i :=
RingEquiv.symm
{ (decomposeAddEquiv 𝒜).symm with
map_mul' := (coeRingHom 𝒜).map_mul }
@[simp]
theorem decompose_one : decompose 𝒜 (1 : A) = 1 :=
map_one (decomposeRingEquiv 𝒜)
@[simp]
theorem decompose_symm_one : (decompose 𝒜).symm 1 = (1 : A) :=
map_one (decomposeRingEquiv 𝒜).symm
@[simp]
theorem decompose_mul (x y : A) : decompose 𝒜 (x * y) = decompose 𝒜 x * decompose 𝒜 y :=
map_mul (decomposeRingEquiv 𝒜) x y
@[simp]
theorem decompose_symm_mul (x y : ⨁ i, 𝒜 i) :
(decompose 𝒜).symm (x * y) = (decompose 𝒜).symm x * (decompose 𝒜).symm y :=
map_mul (decomposeRingEquiv 𝒜).symm x y
end DirectSum
/-- The projection maps of a graded ring -/
def GradedRing.proj (i : ι) : A →+ A :=
(AddSubmonoidClass.subtype (𝒜 i)).comp <|
(DFinsupp.evalAddMonoidHom i).comp <|
RingHom.toAddMonoidHom <| RingEquiv.toRingHom <| DirectSum.decomposeRingEquiv 𝒜
@[simp]
theorem GradedRing.proj_apply (i : ι) (r : A) :
GradedRing.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i :=
rfl
theorem GradedRing.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) :
GradedRing.proj 𝒜 i ((decompose 𝒜).symm a) = (decompose 𝒜).symm (DirectSum.of _ i (a i)) := by
rw [GradedRing.proj_apply, decompose_symm_of, Equiv.apply_symm_apply]
theorem GradedRing.mem_support_iff [∀ (i) (x : 𝒜 i), Decidable (x ≠ 0)] (r : A) (i : ι) :
i ∈ (decompose 𝒜 r).support ↔ GradedRing.proj 𝒜 i r ≠ 0 :=
DFinsupp.mem_support_iff.trans ZeroMemClass.coe_eq_zero.not.symm
end GradedRing
section AddCancelMonoid
open DirectSum
variable [DecidableEq ι] [Semiring A] [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
variable {i j : ι}
namespace DirectSum
theorem coe_decompose_mul_add_of_left_mem [AddLeftCancelMonoid ι] [GradedRing 𝒜] {a b : A}
(a_mem : a ∈ 𝒜 i) : (decompose 𝒜 (a * b) (i + j) : A) = a * decompose 𝒜 b j := by
lift a to 𝒜 i using a_mem
rw [decompose_mul, decompose_coe, coe_of_mul_apply_add]
theorem coe_decompose_mul_add_of_right_mem [AddRightCancelMonoid ι] [GradedRing 𝒜] {a b : A}
(b_mem : b ∈ 𝒜 j) : (decompose 𝒜 (a * b) (i + j) : A) = decompose 𝒜 a i * b := by
lift b to 𝒜 j using b_mem
rw [decompose_mul, decompose_coe, coe_mul_of_apply_add]
theorem decompose_mul_add_left [AddLeftCancelMonoid ι] [GradedRing 𝒜] (a : 𝒜 i) {b : A} :
decompose 𝒜 (↑a * b) (i + j) =
@GradedMonoid.GMul.mul ι (fun i => 𝒜 i) _ _ _ _ a (decompose 𝒜 b j) :=
Subtype.ext <| coe_decompose_mul_add_of_left_mem 𝒜 a.2
theorem decompose_mul_add_right [AddRightCancelMonoid ι] [GradedRing 𝒜] {a : A} (b : 𝒜 j) :
decompose 𝒜 (a * ↑b) (i + j) =
@GradedMonoid.GMul.mul ι (fun i => 𝒜 i) _ _ _ _ (decompose 𝒜 a i) b :=
Subtype.ext <| coe_decompose_mul_add_of_right_mem 𝒜 b.2
theorem coe_decompose_mul_of_left_mem_zero [AddMonoid ι] [GradedRing 𝒜] {a b : A}
(a_mem : a ∈ 𝒜 0) : (decompose 𝒜 (a * b) j : A) = a * decompose 𝒜 b j := by
lift a to 𝒜 0 using a_mem
rw [decompose_mul, decompose_coe, coe_of_mul_apply_of_mem_zero]
theorem coe_decompose_mul_of_right_mem_zero [AddMonoid ι] [GradedRing 𝒜] {a b : A}
(b_mem : b ∈ 𝒜 0) : (decompose 𝒜 (a * b) i : A) = decompose 𝒜 a i * b := by
lift b to 𝒜 0 using b_mem
rw [decompose_mul, decompose_coe, coe_mul_of_apply_of_mem_zero]
end DirectSum
end AddCancelMonoid
section GradedAlgebra
variable [DecidableEq ι] [AddMonoid ι] [CommSemiring R] [Semiring A] [Algebra R A]
variable (𝒜 : ι → Submodule R A)
/-- A special case of `GradedRing` with `σ = Submodule R A`. This is useful both because it
can avoid typeclass search, and because it provides a more concise name. -/
abbrev GradedAlgebra :=
GradedRing 𝒜
/-- A helper to construct a `GradedAlgebra` when the `SetLike.GradedMonoid` structure is already
available. This makes the `left_inv` condition easier to prove, and phrases the `right_inv`
condition in a way that allows custom `@[ext]` lemmas to apply.
See note [reducible non-instances]. -/
abbrev GradedAlgebra.ofAlgHom [SetLike.GradedMonoid 𝒜] (decompose : A →ₐ[R] ⨁ i, 𝒜 i)
(right_inv : (DirectSum.coeAlgHom 𝒜).comp decompose = AlgHom.id R A)
(left_inv : ∀ i (x : 𝒜 i), decompose (x : A) = DirectSum.of (fun i => ↥(𝒜 i)) i x) :
GradedAlgebra 𝒜 where
decompose' := decompose
left_inv := AlgHom.congr_fun right_inv
right_inv := by
suffices decompose.comp (DirectSum.coeAlgHom 𝒜) = AlgHom.id _ _ from AlgHom.congr_fun this
ext i x : 2
exact (decompose.congr_arg <| DirectSum.coeAlgHom_of _ _ _).trans (left_inv i x)
variable [GradedAlgebra 𝒜]
namespace DirectSum
/-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as
an algebra to a direct sum of components. -/
-- Porting note: deleted [simps] and added the corresponding lemmas by hand
def decomposeAlgEquiv : A ≃ₐ[R] ⨁ i, 𝒜 i :=
AlgEquiv.symm
{ (decomposeAddEquiv 𝒜).symm with
map_mul' := map_mul (coeAlgHom 𝒜)
commutes' := (coeAlgHom 𝒜).commutes }
@[simp]
lemma decomposeAlgEquiv_apply (a : A) :
decomposeAlgEquiv 𝒜 a = decompose 𝒜 a := rfl
@[simp]
lemma decomposeAlgEquiv_symm_apply (a : ⨁ i, 𝒜 i) :
(decomposeAlgEquiv 𝒜).symm a = (decompose 𝒜).symm a := rfl
@[simp]
lemma decompose_algebraMap (r : R) :
decompose 𝒜 (algebraMap R A r) = algebraMap R (⨁ i, 𝒜 i) r :=
(decomposeAlgEquiv 𝒜).commutes r
@[simp]
lemma decompose_symm_algebraMap (r : R) :
(decompose 𝒜).symm (algebraMap R (⨁ i, 𝒜 i) r) = algebraMap R A r :=
(decomposeAlgEquiv 𝒜).symm.commutes r
end DirectSum
open DirectSum
/-- The projection maps of graded algebra -/
def GradedAlgebra.proj (𝒜 : ι → Submodule R A) [GradedAlgebra 𝒜] (i : ι) : A →ₗ[R] A :=
(𝒜 i).subtype.comp <| (DFinsupp.lapply i).comp <| (decomposeAlgEquiv 𝒜).toAlgHom.toLinearMap
@[simp]
theorem GradedAlgebra.proj_apply (i : ι) (r : A) :
GradedAlgebra.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i :=
rfl
theorem GradedAlgebra.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) :
GradedAlgebra.proj 𝒜 i ((decompose 𝒜).symm a) = (decompose 𝒜).symm (of _ i (a i)) := by
rw [GradedAlgebra.proj_apply, decompose_symm_of, Equiv.apply_symm_apply]
theorem GradedAlgebra.mem_support_iff [DecidableEq A] (r : A) (i : ι) :
i ∈ (decompose 𝒜 r).support ↔ GradedAlgebra.proj 𝒜 i r ≠ 0 :=
DFinsupp.mem_support_iff.trans Submodule.coe_eq_zero.not.symm
end GradedAlgebra
section CanonicalOrder
open SetLike.GradedMonoid DirectSum
variable [Semiring A] [DecidableEq ι]
variable [AddCommMonoid ι] [PartialOrder ι] [CanonicallyOrderedAdd ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
/-- If `A` is graded by a canonically ordered add monoid, then the projection map `x ↦ x₀` is a ring
homomorphism.
-/
@[simps]
def GradedRing.projZeroRingHom : A →+* A where
toFun a := decompose 𝒜 a 0
map_one' :=
-- Porting note: qualified `one_mem`
decompose_of_mem_same 𝒜 SetLike.GradedOne.one_mem
map_zero' := by
simp only -- Porting note: added
rw [decompose_zero]
rfl
map_add' _ _ := by
simp only -- Porting note: added
rw [decompose_add]
rfl
map_mul' := by
refine DirectSum.Decomposition.inductionOn 𝒜 (fun x => ?_) ?_ ?_
· simp only [zero_mul, decompose_zero, zero_apply, ZeroMemClass.coe_zero]
· rintro i ⟨c, hc⟩
refine DirectSum.Decomposition.inductionOn 𝒜 ?_ ?_ ?_
· simp only [mul_zero, decompose_zero, zero_apply, ZeroMemClass.coe_zero]
· rintro j ⟨c', hc'⟩
simp only [Subtype.coe_mk]
by_cases h : i + j = 0
· rw [decompose_of_mem_same 𝒜
(show c * c' ∈ 𝒜 0 from h ▸ SetLike.GradedMul.mul_mem hc hc'),
decompose_of_mem_same 𝒜 (show c ∈ 𝒜 0 from (add_eq_zero.mp h).1 ▸ hc),
decompose_of_mem_same 𝒜 (show c' ∈ 𝒜 0 from (add_eq_zero.mp h).2 ▸ hc')]
· rw [decompose_of_mem_ne 𝒜 (SetLike.GradedMul.mul_mem hc hc') h]
rcases show i ≠ 0 ∨ j ≠ 0 by rwa [add_eq_zero, not_and_or] at h with h' | h'
· simp only [decompose_of_mem_ne 𝒜 hc h', zero_mul]
· simp only [decompose_of_mem_ne 𝒜 hc' h', mul_zero]
· intro _ _ hd he
simp only at hd he -- Porting note: added
simp only [mul_add, decompose_add, add_apply, AddMemClass.coe_add, hd, he]
· rintro _ _ ha hb _
simp only at ha hb -- Porting note: added
simp only [add_mul, decompose_add, add_apply, AddMemClass.coe_add, ha, hb]
section GradeZero
/-- The ring homomorphism from `A` to `𝒜 0` sending every `a : A` to `a₀`. -/
def GradedRing.projZeroRingHom' : A →+* 𝒜 0 :=
((GradedRing.projZeroRingHom 𝒜).codRestrict _ fun _x => SetLike.coe_mem _ :
A →+* SetLike.GradeZero.subsemiring 𝒜)
@[simp] lemma GradedRing.coe_projZeroRingHom'_apply (a : A) :
(GradedRing.projZeroRingHom' 𝒜 a : A) = GradedRing.projZeroRingHom 𝒜 a := rfl
@[simp] lemma GradedRing.projZeroRingHom'_apply_coe (a : 𝒜 0) :
GradedRing.projZeroRingHom' 𝒜 a = a := by
ext; simp only [coe_projZeroRingHom'_apply, projZeroRingHom_apply, decompose_coe, of_eq_same]
/-- The ring homomorphism `GradedRing.projZeroRingHom' 𝒜` is surjective. -/
lemma GradedRing.projZeroRingHom'_surjective :
Function.Surjective (GradedRing.projZeroRingHom' 𝒜) :=
Function.RightInverse.surjective (GradedRing.projZeroRingHom'_apply_coe 𝒜)
end GradeZero
variable {a b : A} {n i : ι}
namespace DirectSum
theorem coe_decompose_mul_of_left_mem_of_not_le (a_mem : a ∈ 𝒜 i) (h : ¬i ≤ n) :
(decompose 𝒜 (a * b) n : A) = 0 := by
lift a to 𝒜 i using a_mem
rwa [decompose_mul, decompose_coe, coe_of_mul_apply_of_not_le]
theorem coe_decompose_mul_of_right_mem_of_not_le (b_mem : b ∈ 𝒜 i) (h : ¬i ≤ n) :
(decompose 𝒜 (a * b) n : A) = 0 := by
lift b to 𝒜 i using b_mem
rwa [decompose_mul, decompose_coe, coe_mul_of_apply_of_not_le]
variable [Sub ι] [OrderedSub ι] [AddLeftReflectLE ι]
theorem coe_decompose_mul_of_left_mem_of_le (a_mem : a ∈ 𝒜 i) (h : i ≤ n) :
(decompose 𝒜 (a * b) n : A) = a * decompose 𝒜 b (n - i) := by
lift a to 𝒜 i using a_mem
rwa [decompose_mul, decompose_coe, coe_of_mul_apply_of_le]
theorem coe_decompose_mul_of_right_mem_of_le (b_mem : b ∈ 𝒜 i) (h : i ≤ n) :
(decompose 𝒜 (a * b) n : A) = decompose 𝒜 a (n - i) * b := by
lift b to 𝒜 i using b_mem
rwa [decompose_mul, decompose_coe, coe_mul_of_apply_of_le]
theorem coe_decompose_mul_of_left_mem (n) [Decidable (i ≤ n)] (a_mem : a ∈ 𝒜 i) :
(decompose 𝒜 (a * b) n : A) = if i ≤ n then a * decompose 𝒜 b (n - i) else 0 := by
lift a to 𝒜 i using a_mem
rw [decompose_mul, decompose_coe, coe_of_mul_apply]
| Mathlib/RingTheory/GradedAlgebra/Basic.lean | 340 | 343 | theorem coe_decompose_mul_of_right_mem (n) [Decidable (i ≤ n)] (b_mem : b ∈ 𝒜 i) :
(decompose 𝒜 (a * b) n : A) = if i ≤ n then decompose 𝒜 a (n - i) * b else 0 := by | lift b to 𝒜 i using b_mem
rw [decompose_mul, decompose_coe, coe_mul_of_apply] |
/-
Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Algebra.Polynomial.Splits
import Mathlib.Tactic.IntervalCases
/-!
# Cubics and discriminants
This file defines cubic polynomials over a semiring and their discriminants over a splitting field.
## Main definitions
* `Cubic`: the structure representing a cubic polynomial.
* `Cubic.disc`: the discriminant of a cubic polynomial.
## Main statements
* `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if
the cubic has no duplicate roots.
## References
* https://en.wikipedia.org/wiki/Cubic_equation
* https://en.wikipedia.org/wiki/Discriminant
## Tags
cubic, discriminant, polynomial, root
-/
noncomputable section
/-- The structure representing a cubic polynomial. -/
@[ext]
structure Cubic (R : Type*) where
/-- The degree-3 coefficient -/
a : R
/-- The degree-2 coefficient -/
b : R
/-- The degree-1 coefficient -/
c : R
/-- The degree-0 coefficient -/
d : R
namespace Cubic
open Polynomial
variable {R S F K : Type*}
instance [Inhabited R] : Inhabited (Cubic R) :=
⟨⟨default, default, default, default⟩⟩
instance [Zero R] : Zero (Cubic R) :=
⟨⟨0, 0, 0, 0⟩⟩
section Basic
variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R]
/-- Convert a cubic polynomial to a polynomial. -/
def toPoly (P : Cubic R) : R[X] :=
C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d
theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} :
C w * (X - C x) * (X - C y) * (X - C z) =
toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by
simp only [toPoly, C_neg, C_add, C_mul]
ring1
theorem prod_X_sub_C_eq [CommRing S] {x y z : S} :
(X - C x) * (X - C y) * (X - C z) =
toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by
rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul]
/-! ### Coefficients -/
section Coeff
private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧
P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by
simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow]
norm_num
intro n hn
repeat' rw [if_neg]
any_goals omega
repeat' rw [zero_add]
@[simp]
theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 :=
coeffs.1 n hn
@[simp]
theorem coeff_eq_a : P.toPoly.coeff 3 = P.a :=
coeffs.2.1
@[simp]
theorem coeff_eq_b : P.toPoly.coeff 2 = P.b :=
coeffs.2.2.1
@[simp]
theorem coeff_eq_c : P.toPoly.coeff 1 = P.c :=
coeffs.2.2.2.1
@[simp]
theorem coeff_eq_d : P.toPoly.coeff 0 = P.d :=
coeffs.2.2.2.2
theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a]
theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b]
theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c]
theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d]
theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q :=
⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩
theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by
rw [toPoly, ha, C_0, zero_mul, zero_add]
theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d :=
of_a_eq_zero rfl
theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by
rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add]
theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d :=
of_b_eq_zero rfl rfl
theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by
rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add]
theorem of_c_eq_zero' : toPoly ⟨0, 0, 0, d⟩ = C d :=
of_c_eq_zero rfl rfl rfl
theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly = 0 := by
rw [of_c_eq_zero ha hb hc, hd, C_0]
theorem of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly = 0 :=
of_d_eq_zero rfl rfl rfl rfl
theorem zero : (0 : Cubic R).toPoly = 0 :=
of_d_eq_zero'
theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 ↔ P = 0 := by
rw [← zero, toPoly_injective]
private theorem ne_zero (h0 : P.a ≠ 0 ∨ P.b ≠ 0 ∨ P.c ≠ 0 ∨ P.d ≠ 0) : P.toPoly ≠ 0 := by
contrapose! h0
rw [(toPoly_eq_zero_iff P).mp h0]
exact ⟨rfl, rfl, rfl, rfl⟩
theorem ne_zero_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp ne_zero).1 ha
theorem ne_zero_of_b_ne_zero (hb : P.b ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp ne_zero).2).1 hb
theorem ne_zero_of_c_ne_zero (hc : P.c ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc
theorem ne_zero_of_d_ne_zero (hd : P.d ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd
@[simp]
theorem leadingCoeff_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.leadingCoeff = P.a :=
leadingCoeff_cubic ha
@[simp]
theorem leadingCoeff_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).leadingCoeff = a :=
leadingCoeff_of_a_ne_zero ha
@[simp]
theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.leadingCoeff = P.b := by
rw [of_a_eq_zero ha, leadingCoeff_quadratic hb]
@[simp]
theorem leadingCoeff_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).leadingCoeff = b :=
leadingCoeff_of_b_ne_zero rfl hb
@[simp]
theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) :
P.toPoly.leadingCoeff = P.c := by
rw [of_b_eq_zero ha hb, leadingCoeff_linear hc]
@[simp]
theorem leadingCoeff_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).leadingCoeff = c :=
leadingCoeff_of_c_ne_zero rfl rfl hc
@[simp]
theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.leadingCoeff = P.d := by
rw [of_c_eq_zero ha hb hc, leadingCoeff_C]
theorem leadingCoeff_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).leadingCoeff = d :=
leadingCoeff_of_c_eq_zero rfl rfl rfl
theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_a_ne_zero (ha ▸ one_ne_zero), ha]
theorem monic_of_a_eq_one' : (toPoly ⟨1, b, c, d⟩).Monic :=
monic_of_a_eq_one rfl
theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_b_ne_zero ha (hb ▸ one_ne_zero), hb]
theorem monic_of_b_eq_one' : (toPoly ⟨0, 1, c, d⟩).Monic :=
monic_of_b_eq_one rfl rfl
| Mathlib/Algebra/CubicDiscriminant.lean | 220 | 222 | theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by | nontriviality R
rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc ▸ one_ne_zero), hc] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Complex
import Qq
/-! # Power function on `ℝ`
We construct the power functions `x ^ y`, where `x` and `y` are real numbers.
-/
noncomputable section
open Real ComplexConjugate Finset Set
/-
## Definitions
-/
namespace Real
variable {x y z : ℝ}
/-- The real power function `x ^ y`, defined as the real part of the complex power function.
For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for
`y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex
determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/
noncomputable def rpow (x y : ℝ) :=
((x : ℂ) ^ (y : ℂ)).re
noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl
theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl
theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by
simp only [rpow_def, Complex.cpow_def]; split_ifs <;>
simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul,
(Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero]
theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by
rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]
theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp]
@[simp, norm_cast]
theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast,
Complex.ofReal_re]
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n
@[simp]
theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul]
@[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow]
theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
simp only [rpow_def_of_nonneg hx]
split_ifs <;> simp [*, exp_ne_zero]
@[simp]
lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by
simp [rpow_eq_zero_iff_of_nonneg, *]
@[simp]
lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 :=
Real.rpow_eq_zero hx hy |>.not
open Real
theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by
rw [rpow_def, Complex.cpow_def, if_neg]
· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by
simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log,
Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul]
ring
rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ←
Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul,
Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im,
Real.log_neg_eq_log]
ring
· rw [Complex.ofReal_eq_zero]
exact ne_of_lt hx
theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by
split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _
@[bound]
theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by
rw [rpow_def_of_pos hx]; apply exp_pos
@[simp]
theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def]
theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *]
theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
constructor
· intro hyp
simp only [rpow_def, Complex.ofReal_zero] at hyp
by_cases h : x = 0
· subst h
simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp
exact Or.inr ⟨rfl, hyp.symm⟩
· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp
exact Or.inl ⟨h, hyp.symm⟩
· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩)
· exact zero_rpow h
· exact rpow_zero _
theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
rw [← zero_rpow_eq_iff, eq_comm]
@[simp]
theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def]
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def]
theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
@[bound]
theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by
rw [rpow_def_of_nonneg hx]; split_ifs <;>
simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)]
theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by
have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _
rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg]
@[bound]
theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by
rcases le_or_lt 0 x with hx | hx
· rw [abs_rpow_of_nonneg hx]
· rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul,
abs_of_pos (exp_pos _)]
exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _)
theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by
refine (abs_rpow_le_abs_rpow x y).trans ?_
by_cases hx : x = 0
· by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one]
· rw [rpow_def_of_pos (abs_pos.2 hx), log_abs]
lemma rpow_inv_log (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ (log x)⁻¹ = exp 1 := by
rw [rpow_def_of_pos hx₀, mul_inv_cancel₀]
exact log_ne_zero.2 ⟨hx₀.ne', hx₁, (hx₀.trans' <| by norm_num).ne'⟩
/-- See `Real.rpow_inv_log` for the equality when `x ≠ 1` is strictly positive. -/
lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≤ exp 1 := by
calc
_ ≤ |x ^ (log x)⁻¹| := le_abs_self _
_ ≤ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow ..
rw [← log_abs]
obtain hx | hx := (abs_nonneg x).eq_or_gt
· simp [hx]
· rw [rpow_def_of_pos hx]
gcongr
exact mul_inv_le_one
theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by
simp_rw [Real.norm_eq_abs]
exact abs_rpow_of_nonneg hx_nonneg
variable {w x y z : ℝ}
theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by
simp only [rpow_def_of_pos hx, mul_add, exp_add]
theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by
rcases hx.eq_or_lt with (rfl | pos)
· rw [zero_rpow h, zero_eq_mul]
have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0
exact this.imp zero_rpow zero_rpow
· exact rpow_add pos _ _
/-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add' hx]; rwa [h]
theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
rcases hy.eq_or_lt with (rfl | hy)
· rw [zero_add, rpow_zero, one_mul]
exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz)
/-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for
`x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish.
The inequality is always true, though, and given in this lemma. -/
theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by
rcases le_iff_eq_or_lt.1 hx with (H | pos)
· by_cases h : y + z = 0
· simp only [H.symm, h, rpow_zero]
calc
(0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 :=
mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one
_ = 1 := by simp
· simp [rpow_add', ← H, h]
· simp [rpow_add pos]
theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) :
(a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x :=
map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s
theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ}
(h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by
induction' s using Finset.cons_induction with i s hi ihs
· rw [sum_empty, Finset.prod_empty, rpow_zero]
· rw [forall_mem_cons] at h
rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)]
theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg]
theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv]
theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg] at h ⊢
simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv]
protected theorem _root_.HasCompactSupport.rpow_const {α : Type*} [TopologicalSpace α] {f : α → ℝ}
(hf : HasCompactSupport f) {r : ℝ} (hr : r ≠ 0) : HasCompactSupport (fun x ↦ f x ^ r) :=
hf.comp_left (g := (· ^ r)) (Real.zero_rpow hr)
end Real
/-!
## Comparing real and complex powers
-/
namespace Complex
theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by
simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;>
simp [Complex.ofReal_log hx]
theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) :
(x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by
rcases hx.eq_or_lt with (rfl | hlt)
· rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*]
have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne
rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log,
log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx),
ofReal_zero, zero_mul, add_zero]
lemma cpow_ofReal (x : ℂ) (y : ℝ) :
x ^ (y : ℂ) = ↑(‖x‖ ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by
rcases eq_or_ne x 0 with rfl | hx
· simp [ofReal_cpow le_rfl]
· rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)]
norm_cast
rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul,
Real.exp_log]
rwa [norm_pos_iff]
lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = ‖x‖ ^ y * Real.cos (arg x * y) := by
rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos]
lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = ‖x‖ ^ y * Real.sin (arg x * y) := by
rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin]
theorem norm_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) :
‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by
rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub,
Real.rpow_def_of_pos (norm_pos_iff.mpr hz)]
theorem norm_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) :
‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by
rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]]
rcases eq_or_ne w.re 0 with hw | hw
· simp [hw, h rfl hw]
· rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero]
exact ne_of_apply_ne re hw
theorem norm_cpow_le (z w : ℂ) : ‖z ^ w‖ ≤ ‖z‖ ^ w.re / Real.exp (arg z * im w) := by
by_cases h : z = 0 → w.re = 0 → w = 0
· exact (norm_cpow_of_imp h).le
· push_neg at h
simp [h]
@[simp]
theorem norm_cpow_real (x : ℂ) (y : ℝ) : ‖x ^ (y : ℂ)‖ = ‖x‖ ^ y := by
rw [norm_cpow_of_imp] <;> simp
@[simp]
theorem norm_cpow_inv_nat (x : ℂ) (n : ℕ) : ‖x ^ (n⁻¹ : ℂ)‖ = ‖x‖ ^ (n⁻¹ : ℝ) := by
rw [← norm_cpow_real]; simp
theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : ‖(x : ℂ) ^ y‖ = x ^ y.re := by
rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le,
zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le]
theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) :
‖(x : ℂ) ^ y‖ = x ^ re y := by
rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg]
@[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero
@[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp
@[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le
@[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real
@[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat
@[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos :=
norm_cpow_eq_rpow_re_of_pos
@[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg :=
norm_cpow_eq_rpow_re_of_nonneg
open Filter in
lemma norm_ofReal_cpow_eventually_eq_atTop (c : ℂ) :
(fun t : ℝ ↦ ‖(t : ℂ) ^ c‖) =ᶠ[atTop] fun t ↦ t ^ c.re := by
filter_upwards [eventually_gt_atTop 0] with t ht
rw [norm_cpow_eq_rpow_re_of_pos ht]
lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) :
‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by
rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs]
lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) :
‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by
rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _]
lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ :=
(norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _
theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) :
(x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by
rw [cpow_mul, ofReal_cpow hx]
· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos
· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le
end Complex
/-! ### Positivity extension -/
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
/-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1)
when the exponent is zero. The other cases are done in `evalRpow`. -/
@[positivity (_ : ℝ) ^ (0 : ℝ)]
def evalRpowZero : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) =>
assertInstancesCommute
pure (.positive q(Real.rpow_zero_pos $a))
| _, _, _ => throwError "not Real.rpow"
/-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when
the base is nonnegative and positive when the base is positive. -/
@[positivity (_ : ℝ) ^ (_ : ℝ)]
def evalRpow : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa =>
pure (.positive q(Real.rpow_pos_of_pos $pa $b))
| .nonnegative pa =>
pure (.nonnegative q(Real.rpow_nonneg $pa $b))
| _ => pure .none
| _, _, _ => throwError "not Real.rpow"
end Mathlib.Meta.Positivity
/-!
## Further algebraic properties of `rpow`
-/
namespace Real
variable {x y z : ℝ} {n : ℕ}
theorem rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by
rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _),
Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;>
simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im,
neg_lt_zero, pi_pos, le_of_lt pi_pos]
lemma rpow_pow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : (x ^ y) ^ n = (x ^ n) ^ y := by
simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y]
lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : (x ^ y) ^ n = (x ^ n) ^ y := by
simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y]
lemma rpow_add_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_def, rpow_def, Complex.ofReal_add,
Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast,
Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm]
lemma rpow_add_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by
simpa using rpow_add_intCast hx y n
lemma rpow_sub_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
simpa using rpow_add_intCast hx y (-n)
lemma rpow_sub_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
simpa using rpow_sub_intCast hx y n
lemma rpow_add_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_add' hx h, rpow_intCast]
lemma rpow_add_natCast' (hx : 0 ≤ x) (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_add' hx h, rpow_natCast]
lemma rpow_sub_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by
rw [rpow_sub' hx h, rpow_intCast]
lemma rpow_sub_natCast' (hx : 0 ≤ x) (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by
rw [rpow_sub' hx h, rpow_natCast]
theorem rpow_add_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by
simpa using rpow_add_natCast hx y 1
theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by
simpa using rpow_sub_natCast hx y 1
lemma rpow_add_one' (hx : 0 ≤ x) (h : y + 1 ≠ 0) : x ^ (y + 1) = x ^ y * x := by
rw [rpow_add' hx h, rpow_one]
lemma rpow_one_add' (hx : 0 ≤ x) (h : 1 + y ≠ 0) : x ^ (1 + y) = x * x ^ y := by
rw [rpow_add' hx h, rpow_one]
lemma rpow_sub_one' (hx : 0 ≤ x) (h : y - 1 ≠ 0) : x ^ (y - 1) = x ^ y / x := by
rw [rpow_sub' hx h, rpow_one]
lemma rpow_one_sub' (hx : 0 ≤ x) (h : 1 - y ≠ 0) : x ^ (1 - y) = x / x ^ y := by
rw [rpow_sub' hx h, rpow_one]
@[simp]
theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by
rw [← rpow_natCast]
simp only [Nat.cast_ofNat]
theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by
suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H
simp only [rpow_intCast, zpow_one, zpow_neg]
theorem mul_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) : (x * y) ^ z = x ^ z * y ^ z := by
iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all
· rw [log_mul ‹_› ‹_›, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' ‹_›)]
all_goals positivity
theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by
simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm]
theorem div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by
simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy]
theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by
apply exp_injective
rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y]
theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) :
y * log x = log z ↔ x ^ y = z :=
⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h,
by rintro rfl; rw [log_rpow hx]⟩
@[simp] lemma rpow_rpow_inv (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul hx, mul_inv_cancel₀ hy, rpow_one]
@[simp] lemma rpow_inv_rpow (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul hx, inv_mul_cancel₀ hy, rpow_one]
theorem pow_rpow_inv_natCast (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn
rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancel₀ hn0, rpow_one]
theorem rpow_inv_natCast_pow (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn
rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancel₀ hn0, rpow_one]
lemma rpow_natCast_mul (hx : 0 ≤ x) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul hx, rpow_natCast]
lemma rpow_mul_natCast (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul hx, rpow_natCast]
lemma rpow_intCast_mul (hx : 0 ≤ x) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul hx, rpow_intCast]
lemma rpow_mul_intCast (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul hx, rpow_intCast]
/-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved
in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/
/-!
## Order and monotonicity
-/
@[gcongr, bound]
theorem rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by
rw [le_iff_eq_or_lt] at hx; rcases hx with hx | hx
· rw [← hx, zero_rpow (ne_of_gt hz)]
exact rpow_pos_of_pos (by rwa [← hx] at hxy) _
· rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp]
exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz
theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) :
StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) :=
fun _ ha _ _ hab => rpow_lt_rpow ha hab hr
@[gcongr, bound]
theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := by
rcases eq_or_lt_of_le h₁ with (rfl | h₁'); · rfl
rcases eq_or_lt_of_le h₂ with (rfl | h₂'); · simp
exact le_of_lt (rpow_lt_rpow h h₁' h₂')
theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≤ r) :
MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) :=
fun _ ha _ _ hab => rpow_le_rpow ha hab hr
lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by
have := hx.trans hxy
rw [← inv_lt_inv₀, ← rpow_neg, ← rpow_neg]
on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz)
all_goals positivity
lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := by
have := hx.trans_le hxy
rw [← inv_le_inv₀, ← rpow_neg, ← rpow_neg]
on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz)
all_goals positivity
theorem rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩
theorem rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz
lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x :=
⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le,
fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩
lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x :=
le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz
lemma le_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity
lemma rpow_inv_le_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity
lemma lt_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y :=
lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz
lemma rpow_inv_lt_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z :=
lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz
theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := by
rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x < y ^ z⁻¹ ↔ y < x ^ z := by
rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x ^ z⁻¹ < y ↔ y ^ z < x := by
rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := by
rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by
repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)]
rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx)
@[gcongr]
theorem rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by
repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)]
rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx)
theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) :
x ^ z < y ^ z := by
have hx : 0 < x := hy.trans hxy
rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z),
inv_lt_inv₀ (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)]
exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz
theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) :
StrictAntiOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) :=
fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr
theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≤ x) (hz : z ≤ 0) :
x ^ z ≤ y ^ z := by
rcases ne_or_eq z 0 with hz_zero | rfl
case inl =>
rcases ne_or_eq x y with hxy' | rfl
case inl =>
exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy)
(Ne.lt_of_le hz_zero hz)
case inr => simp
case inr => simp
theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≤ 0) :
AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) :=
fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr
@[simp]
theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≤ x ^ z ↔ y ≤ z := by
have x_pos : 0 < x := lt_trans zero_lt_one hx
rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos,
log_rpow x_pos, mul_le_mul_right (log_pos hx)]
@[simp]
theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by
rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le]
theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by
repeat' rw [rpow_def_of_pos hx0]
rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1)
theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by
repeat' rw [rpow_def_of_pos hx0]
rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1)
@[simp]
theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :
x ^ y ≤ x ^ z ↔ z ≤ y := by
rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0,
mul_le_mul_right_of_neg (log_neg hx0 hx1)]
@[simp]
| Mathlib/Analysis/SpecialFunctions/Pow/Real.lean | 647 | 656 | theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :
x ^ y < x ^ z ↔ z < y := by | rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le]
theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by
rw [← one_rpow z]
exact rpow_lt_rpow hx1 hx2 hz
theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by
rw [← one_rpow z] |
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Data.List.Rotate
import Mathlib.GroupTheory.Perm.Support
/-!
# Permutations from a list
A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list
is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`,
we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that
`formPerm l` is rotationally invariant, in `formPerm_rotate`.
When there are duplicate elements in `l`, how and in what arrangement with respect to the other
elements they appear in the list determines the formed permutation.
This is because `List.formPerm` is implemented as a product of `Equiv.swap`s.
That means that presence of a sublist of two adjacent duplicates like `[..., x, x, ...]`
will produce the same permutation as if the adjacent duplicates were not present.
The `List.formPerm` definition is meant to primarily be used with `Nodup l`, so that
the resulting permutation is cyclic (if `l` has at least two elements).
The presence of duplicates in a particular placement can lead `List.formPerm` to produce a
nontrivial permutation that is noncyclic.
-/
namespace List
variable {α β : Type*}
section FormPerm
variable [DecidableEq α] (l : List α)
open Equiv Equiv.Perm
/-- A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list
is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`,
we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that
`formPerm l` is rotationally invariant, in `formPerm_rotate`.
-/
def formPerm : Equiv.Perm α :=
(zipWith Equiv.swap l l.tail).prod
@[simp]
theorem formPerm_nil : formPerm ([] : List α) = 1 :=
rfl
@[simp]
theorem formPerm_singleton (x : α) : formPerm [x] = 1 :=
rfl
@[simp]
theorem formPerm_cons_cons (x y : α) (l : List α) :
formPerm (x :: y :: l) = swap x y * formPerm (y :: l) :=
prod_cons
theorem formPerm_pair (x y : α) : formPerm [x, y] = swap x y :=
rfl
theorem mem_or_mem_of_zipWith_swap_prod_ne : ∀ {l l' : List α} {x : α},
(zipWith swap l l').prod x ≠ x → x ∈ l ∨ x ∈ l'
| [], _, _ => by simp
| _, [], _ => by simp
| a::l, b::l', x => fun hx ↦
if h : (zipWith swap l l').prod x = x then
(eq_or_eq_of_swap_apply_ne_self (a := a) (b := b) (x := x) (by simpa [h] using hx)).imp
(by rintro rfl; exact .head _) (by rintro rfl; exact .head _)
else
(mem_or_mem_of_zipWith_swap_prod_ne h).imp (.tail _) (.tail _)
theorem zipWith_swap_prod_support' (l l' : List α) :
{ x | (zipWith swap l l').prod x ≠ x } ≤ l.toFinset ⊔ l'.toFinset := fun _ h ↦ by
simpa using mem_or_mem_of_zipWith_swap_prod_ne h
theorem zipWith_swap_prod_support [Fintype α] (l l' : List α) :
(zipWith swap l l').prod.support ≤ l.toFinset ⊔ l'.toFinset := by
intro x hx
have hx' : x ∈ { x | (zipWith swap l l').prod x ≠ x } := by simpa using hx
simpa using zipWith_swap_prod_support' _ _ hx'
theorem support_formPerm_le' : { x | formPerm l x ≠ x } ≤ l.toFinset := by
refine (zipWith_swap_prod_support' l l.tail).trans ?_
simpa [Finset.subset_iff] using tail_subset l
theorem support_formPerm_le [Fintype α] : support (formPerm l) ≤ l.toFinset := by
intro x hx
have hx' : x ∈ { x | formPerm l x ≠ x } := by simpa using hx
simpa using support_formPerm_le' _ hx'
variable {l} {x : α}
theorem mem_of_formPerm_apply_ne (h : l.formPerm x ≠ x) : x ∈ l := by
simpa [or_iff_left_of_imp mem_of_mem_tail] using mem_or_mem_of_zipWith_swap_prod_ne h
| Mathlib/GroupTheory/Perm/List.lean | 100 | 103 | theorem formPerm_apply_of_not_mem (h : x ∉ l) : formPerm l x = x :=
not_imp_comm.1 mem_of_formPerm_apply_ne h
theorem formPerm_apply_mem_of_mem (h : x ∈ l) : formPerm l x ∈ l := by | |
/-
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.Algebra.GCDMonoid.Nat
import Mathlib.Algebra.Group.TypeTags.Finite
import Mathlib.Combinatorics.Enumerative.Partition
import Mathlib.Data.List.Rotate
import Mathlib.GroupTheory.Perm.Closure
import Mathlib.GroupTheory.Perm.Cycle.Factors
import Mathlib.Tactic.NormNum.GCD
/-!
# 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.
-/
open scoped Finset
namespace Equiv.Perm
open List (Vector)
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)
theorem cycleType_def (σ : Perm α) :
σ.cycleType = σ.cycleFactorsFinset.1.map (Finset.card ∘ support) :=
rfl
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⟩
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, Function.comp_def]
· simpa using h1
· simpa [hl] using h2
· simp [hl, h0]
theorem CycleType.count_def {σ : Perm α} (n : ℕ) :
σ.cycleType.count n =
Fintype.card {c : σ.cycleFactorsFinset // #(c : Perm α).support = n } := by
-- work on the LHS
rw [cycleType, Multiset.count_eq_card_filter_eq]
-- rewrite the `Fintype.card` as a `Finset.card`
rw [Fintype.subtype_card, Finset.univ_eq_attach, Finset.filter_attach',
Finset.card_map, Finset.card_attach]
simp only [Function.comp_apply, Finset.card, Finset.filter_val,
Multiset.filter_map, Multiset.card_map]
congr 1
apply Multiset.filter_congr
intro d h
simp only [Function.comp_apply, eq_comm, Finset.mem_val.mp h, exists_const]
@[simp]
theorem cycleType_eq_zero {σ : Perm α} : σ.cycleType = 0 ↔ σ = 1 := by
simp [cycleType_def, cycleFactorsFinset_eq_empty_iff]
@[simp]
theorem cycleType_one : (1 : Perm α).cycleType = 0 := cycleType_eq_zero.2 rfl
theorem card_cycleType_eq_zero {σ : Perm α} : Multiset.card σ.cycleType = 0 ↔ σ = 1 := by
rw [card_eq_zero, 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
theorem one_lt_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 1 < n :=
two_le_of_mem_cycleType h
theorem IsCycle.cycleType {σ : Perm α} (hσ : IsCycle σ) : σ.cycleType = {#σ.support} :=
cycleType_eq [σ] (mul_one σ) (fun _τ hτ => (congr_arg IsCycle (List.mem_singleton.mp hτ)).mpr hσ)
(List.pairwise_singleton Disjoint σ)
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, σ
simp [h]
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
@[simp]
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]
@[simp]
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π]
theorem sum_cycleType (σ : Perm α) : σ.cycleType.sum = #σ.support := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => rw [hσ.cycleType, Multiset.sum_singleton]
| induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, sum_add, hσ, hτ, hd.card_support_mul]
theorem card_fixedPoints (σ : Equiv.Perm α) :
Fintype.card (Function.fixedPoints σ) = Fintype.card α - σ.cycleType.sum := by
rw [Equiv.Perm.sum_cycleType, ← Finset.card_compl, Fintype.card_ofFinset]
congr; aesop
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]
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]
@[simp]
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τ]
theorem dvd_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : n ∣ orderOf σ := by
rw [← lcm_cycleType]
exact dvd_lcm h
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]
theorem two_dvd_card_support {σ : Perm α} (hσ : σ ^ 2 = 1) : 2 ∣ #σ.support :=
(congr_arg (Dvd.dvd 2) σ.sum_cycleType).mp
(Multiset.dvd_sum fun n hn => by
rw [_root_.le_antisymm
(Nat.le_of_dvd zero_lt_two <|
(dvd_of_mem_cycleType hn).trans <| orderOf_dvd_of_pow_eq_one hσ)
(two_le_of_mem_cycleType hn)])
| Mathlib/GroupTheory/Perm/Cycle/Type.lean | 204 | 211 | theorem cycleType_prime_order {σ : Perm α} (hσ : (orderOf σ).Prime) :
∃ n : ℕ, σ.cycleType = Multiset.replicate (n + 1) (orderOf σ) := by | refine ⟨Multiset.card σ.cycleType - 1, eq_replicate.2 ⟨?_, fun n hn ↦ ?_⟩⟩
· rw [tsub_add_cancel_of_le]
rw [Nat.succ_le_iff, card_cycleType_pos, Ne, ← orderOf_eq_one_iff]
exact hσ.ne_one
· exact (hσ.eq_one_or_self_of_dvd n (dvd_of_mem_cycleType hn)).resolve_left
(one_lt_of_mem_cycleType hn).ne' |
/-
Copyright (c) 2023 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck, Ruben Van de Velde
-/
import Mathlib.Analysis.Calculus.ContDiff.Operations
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Shift
import Mathlib.Analysis.Calculus.IteratedDeriv.Defs
/-!
# One-dimensional iterated derivatives
This file contains a number of further results on `iteratedDerivWithin` that need more imports
than are available in `Mathlib/Analysis/Calculus/IteratedDeriv/Defs.lean`.
-/
section one_dimensional
variable
{𝕜 : Type*} [NontriviallyNormedField 𝕜]
{F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
{R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F]
{n : ℕ} {x : 𝕜} {s : Set 𝕜} (hx : x ∈ s) (h : UniqueDiffOn 𝕜 s) {f g : 𝕜 → F}
section
theorem iteratedDerivWithin_congr (hfg : Set.EqOn f g s) :
Set.EqOn (iteratedDerivWithin n f s) (iteratedDerivWithin n g s) s := by
induction n generalizing f g with
| zero => rwa [iteratedDerivWithin_zero]
| succ n IH =>
intro y hy
rw [iteratedDerivWithin_succ, iteratedDerivWithin_succ]
exact derivWithin_congr (IH hfg) (IH hfg hy)
include h hx in
theorem iteratedDerivWithin_add
(hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) :
iteratedDerivWithin n (f + g) s x =
iteratedDerivWithin n f s x + iteratedDerivWithin n g s x := by
simp_rw [iteratedDerivWithin, iteratedFDerivWithin_add_apply hf hg h hx,
ContinuousMultilinearMap.add_apply]
theorem iteratedDerivWithin_const_add (hn : 0 < n) (c : F) :
iteratedDerivWithin n (fun z => c + f z) s x = iteratedDerivWithin n f s x := by
obtain ⟨n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne'
rw [iteratedDerivWithin_succ', iteratedDerivWithin_succ']
congr with y
exact derivWithin_const_add _
theorem iteratedDerivWithin_const_sub (hn : 0 < n) (c : F) :
iteratedDerivWithin n (fun z => c - f z) s x = iteratedDerivWithin n (fun z => -f z) s x := by
obtain ⟨n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne'
rw [iteratedDerivWithin_succ', iteratedDerivWithin_succ']
congr with y
rw [derivWithin.neg]
exact derivWithin_const_sub _
@[deprecated (since := "2024-12-10")]
alias iteratedDerivWithin_const_neg := iteratedDerivWithin_const_sub
include h hx in
| Mathlib/Analysis/Calculus/IteratedDeriv/Lemmas.lean | 64 | 66 | theorem iteratedDerivWithin_const_smul (c : R) (hf : ContDiffWithinAt 𝕜 n f s x) :
iteratedDerivWithin n (c • f) s x = c • iteratedDerivWithin n f s x := by | simp_rw [iteratedDerivWithin] |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker
-/
import Mathlib.Algebra.Ring.Associated
import Mathlib.Algebra.Ring.Regular
/-!
# Monoids with normalization functions, `gcd`, and `lcm`
This file defines extra structures on `CancelCommMonoidWithZero`s, including `IsDomain`s.
## Main Definitions
* `NormalizationMonoid`
* `GCDMonoid`
* `NormalizedGCDMonoid`
* `gcdMonoidOfGCD`, `gcdMonoidOfExistsGCD`, `normalizedGCDMonoidOfGCD`,
`normalizedGCDMonoidOfExistsGCD`
* `gcdMonoidOfLCM`, `gcdMonoidOfExistsLCM`, `normalizedGCDMonoidOfLCM`,
`normalizedGCDMonoidOfExistsLCM`
For the `NormalizedGCDMonoid` instances on `ℕ` and `ℤ`, see `Mathlib.Algebra.GCDMonoid.Nat`.
## Implementation Notes
* `NormalizationMonoid` is defined by assigning to each element a `normUnit` such that multiplying
by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This
definition as currently implemented does casework on `0`.
* `GCDMonoid` contains the definitions of `gcd` and `lcm` with the usual properties. They are
both determined up to a unit.
* `NormalizedGCDMonoid` extends `NormalizationMonoid`, so the `gcd` and `lcm` are always
normalized. This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains,
and monoids without zero.
* `gcdMonoidOfGCD` and `normalizedGCDMonoidOfGCD` noncomputably construct a `GCDMonoid`
(resp. `NormalizedGCDMonoid`) structure just from the `gcd` and its properties.
* `gcdMonoidOfExistsGCD` and `normalizedGCDMonoidOfExistsGCD` noncomputably construct a
`GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements
have a (not necessarily normalized) `gcd`.
* `gcdMonoidOfLCM` and `normalizedGCDMonoidOfLCM` noncomputably construct a `GCDMonoid`
(resp. `NormalizedGCDMonoid`) structure just from the `lcm` and its properties.
* `gcdMonoidOfExistsLCM` and `normalizedGCDMonoidOfExistsLCM` noncomputably construct a
`GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements
have a (not necessarily normalized) `lcm`.
## TODO
* Port GCD facts about nats, definition of coprime
* Generalize normalization monoids to commutative (cancellative) monoids with or without zero
## Tags
divisibility, gcd, lcm, normalize
-/
variable {α : Type*}
/-- Normalization monoid: multiplying with `normUnit` gives a normal form for associated
elements. -/
class NormalizationMonoid (α : Type*) [CancelCommMonoidWithZero α] where
/-- `normUnit` assigns to each element of the monoid a unit of the monoid. -/
normUnit : α → αˣ
/-- The proposition that `normUnit` maps `0` to the identity. -/
normUnit_zero : normUnit 0 = 1
/-- The proposition that `normUnit` respects multiplication of non-zero elements. -/
normUnit_mul : ∀ {a b}, a ≠ 0 → b ≠ 0 → normUnit (a * b) = normUnit a * normUnit b
/-- The proposition that `normUnit` maps units to their inverses. -/
normUnit_coe_units : ∀ u : αˣ, normUnit u = u⁻¹
export NormalizationMonoid (normUnit normUnit_zero normUnit_mul normUnit_coe_units)
attribute [simp] normUnit_coe_units normUnit_zero normUnit_mul
section NormalizationMonoid
variable [CancelCommMonoidWithZero α] [NormalizationMonoid α]
@[simp]
theorem normUnit_one : normUnit (1 : α) = 1 :=
normUnit_coe_units 1
/-- Chooses an element of each associate class, by multiplying by `normUnit` -/
def normalize : α →*₀ α where
toFun x := x * normUnit x
map_zero' := by
simp only [normUnit_zero]
exact mul_one (0 : α)
map_one' := by rw [normUnit_one, one_mul]; rfl
map_mul' x y :=
(by_cases fun hx : x = 0 => by rw [hx, zero_mul, zero_mul, zero_mul]) fun hx =>
(by_cases fun hy : y = 0 => by rw [hy, mul_zero, zero_mul, mul_zero]) fun hy => by
simp only [normUnit_mul hx hy, Units.val_mul]; simp only [mul_assoc, mul_left_comm y]
theorem associated_normalize (x : α) : Associated x (normalize x) :=
⟨_, rfl⟩
theorem normalize_associated (x : α) : Associated (normalize x) x :=
(associated_normalize _).symm
theorem associated_normalize_iff {x y : α} : Associated x (normalize y) ↔ Associated x y :=
⟨fun h => h.trans (normalize_associated y), fun h => h.trans (associated_normalize y)⟩
theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Associated x y :=
⟨fun h => (associated_normalize _).trans h, fun h => (normalize_associated _).trans h⟩
theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x :=
Associates.mk_eq_mk_iff_associated.2 (normalize_associated _)
theorem normalize_apply (x : α) : normalize x = x * normUnit x :=
rfl
theorem normalize_zero : normalize (0 : α) = 0 :=
normalize.map_zero
theorem normalize_one : normalize (1 : α) = 1 :=
normalize.map_one
theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp [normalize_apply]
theorem normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 :=
⟨fun hx => (associated_zero_iff_eq_zero x).1 <| hx ▸ associated_normalize _, by
rintro rfl; exact normalize_zero⟩
theorem normalize_eq_one {x : α} : normalize x = 1 ↔ IsUnit x :=
⟨fun hx => isUnit_iff_exists_inv.2 ⟨_, hx⟩, fun ⟨u, hu⟩ => hu ▸ normalize_coe_units u⟩
@[simp]
theorem normUnit_mul_normUnit (a : α) : normUnit (a * normUnit a) = 1 := by
nontriviality α using Subsingleton.elim a 0
obtain rfl | h := eq_or_ne a 0
· rw [normUnit_zero, zero_mul, normUnit_zero]
· rw [normUnit_mul h (Units.ne_zero _), normUnit_coe_units, mul_inv_eq_one]
@[simp]
theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp [normalize_apply]
theorem normalize_eq_normalize {a b : α} (hab : a ∣ b) (hba : b ∣ a) :
normalize a = normalize b := by
nontriviality α
rcases associated_of_dvd_dvd hab hba with ⟨u, rfl⟩
refine by_cases (by rintro rfl; simp only [zero_mul]) fun ha : a ≠ 0 => ?_
suffices a * ↑(normUnit a) = a * ↑u * ↑(normUnit a) * ↑u⁻¹ by
simpa only [normalize_apply, mul_assoc, normUnit_mul ha u.ne_zero, normUnit_coe_units]
calc
a * ↑(normUnit a) = a * ↑(normUnit a) * ↑u * ↑u⁻¹ := (Units.mul_inv_cancel_right _ _).symm
_ = a * ↑u * ↑(normUnit a) * ↑u⁻¹ := by rw [mul_right_comm a]
theorem normalize_eq_normalize_iff {x y : α} : normalize x = normalize y ↔ x ∣ y ∧ y ∣ x :=
⟨fun h => ⟨Units.dvd_mul_right.1 ⟨_, h.symm⟩, Units.dvd_mul_right.1 ⟨_, h⟩⟩, fun ⟨hxy, hyx⟩ =>
normalize_eq_normalize hxy hyx⟩
theorem dvd_antisymm_of_normalize_eq {a b : α} (ha : normalize a = a) (hb : normalize b = b)
(hab : a ∣ b) (hba : b ∣ a) : a = b :=
ha ▸ hb ▸ normalize_eq_normalize hab hba
theorem Associated.eq_of_normalized
{a b : α} (h : Associated a b) (ha : normalize a = a) (hb : normalize b = b) :
a = b :=
dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd'
@[simp]
theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b :=
Units.dvd_mul_right
@[simp]
theorem normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b :=
Units.mul_right_dvd
end NormalizationMonoid
namespace Associates
variable [CancelCommMonoidWithZero α] [NormalizationMonoid α]
/-- Maps an element of `Associates` back to the normalized element of its associate class -/
protected def out : Associates α → α :=
(Quotient.lift (normalize : α → α)) fun a _ ⟨_, hu⟩ =>
hu ▸ normalize_eq_normalize ⟨_, rfl⟩ (Units.mul_right_dvd.2 <| dvd_refl a)
@[simp]
theorem out_mk (a : α) : (Associates.mk a).out = normalize a :=
rfl
@[simp]
theorem out_one : (1 : Associates α).out = 1 :=
normalize_one
theorem out_mul (a b : Associates α) : (a * b).out = a.out * b.out :=
Quotient.inductionOn₂ a b fun _ _ => by
simp only [Associates.quotient_mk_eq_mk, out_mk, mk_mul_mk, normalize.map_mul]
theorem dvd_out_iff (a : α) (b : Associates α) : a ∣ b.out ↔ Associates.mk a ≤ b :=
Quotient.inductionOn b <| by
simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd]
theorem out_dvd_iff (a : α) (b : Associates α) : b.out ∣ a ↔ b ≤ Associates.mk a :=
Quotient.inductionOn b <| by
simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd]
@[simp]
theorem out_top : (⊤ : Associates α).out = 0 :=
normalize_zero
@[simp]
theorem normalize_out (a : Associates α) : normalize a.out = a.out :=
Quotient.inductionOn a normalize_idem
@[simp]
theorem mk_out (a : Associates α) : Associates.mk a.out = a :=
Quotient.inductionOn a mk_normalize
theorem out_injective : Function.Injective (Associates.out : _ → α) :=
Function.LeftInverse.injective mk_out
end Associates
/-- GCD monoid: a `CancelCommMonoidWithZero` with `gcd` (greatest common divisor) and
`lcm` (least common multiple) operations, determined up to a unit. The type class focuses on `gcd`
and we derive the corresponding `lcm` facts from `gcd`.
-/
class GCDMonoid (α : Type*) [CancelCommMonoidWithZero α] where
/-- The greatest common divisor between two elements. -/
gcd : α → α → α
/-- The least common multiple between two elements. -/
lcm : α → α → α
/-- The GCD is a divisor of the first element. -/
gcd_dvd_left : ∀ a b, gcd a b ∣ a
/-- The GCD is a divisor of the second element. -/
gcd_dvd_right : ∀ a b, gcd a b ∣ b
/-- Any common divisor of both elements is a divisor of the GCD. -/
dvd_gcd : ∀ {a b c}, a ∣ c → a ∣ b → a ∣ gcd c b
/-- The product of two elements is `Associated` with the product of their GCD and LCM. -/
gcd_mul_lcm : ∀ a b, Associated (gcd a b * lcm a b) (a * b)
/-- `0` is left-absorbing. -/
lcm_zero_left : ∀ a, lcm 0 a = 0
/-- `0` is right-absorbing. -/
lcm_zero_right : ∀ a, lcm a 0 = 0
/-- Normalized GCD monoid: a `CancelCommMonoidWithZero` with normalization and `gcd`
(greatest common divisor) and `lcm` (least common multiple) operations. In this setting `gcd` and
`lcm` form a bounded lattice on the associated elements where `gcd` is the infimum, `lcm` is the
supremum, `1` is bottom, and `0` is top. The type class focuses on `gcd` and we derive the
corresponding `lcm` facts from `gcd`.
-/
class NormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] extends NormalizationMonoid α,
GCDMonoid α where
/-- The GCD is normalized to itself. -/
normalize_gcd : ∀ a b, normalize (gcd a b) = gcd a b
/-- The LCM is normalized to itself. -/
normalize_lcm : ∀ a b, normalize (lcm a b) = lcm a b
export GCDMonoid (gcd lcm gcd_dvd_left gcd_dvd_right dvd_gcd lcm_zero_left lcm_zero_right)
attribute [simp] lcm_zero_left lcm_zero_right
section GCDMonoid
variable [CancelCommMonoidWithZero α]
instance [NormalizationMonoid α] : Nonempty (NormalizationMonoid α) := ⟨‹_›⟩
instance [GCDMonoid α] : Nonempty (GCDMonoid α) := ⟨‹_›⟩
instance [NormalizedGCDMonoid α] : Nonempty (NormalizedGCDMonoid α) := ⟨‹_›⟩
instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (NormalizationMonoid α) :=
h.elim fun _ ↦ inferInstance
instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (GCDMonoid α) :=
h.elim fun _ ↦ inferInstance
theorem gcd_isUnit_iff_isRelPrime [GCDMonoid α] {a b : α} :
IsUnit (gcd a b) ↔ IsRelPrime a b :=
⟨fun h _ ha hb ↦ isUnit_of_dvd_unit (dvd_gcd ha hb) h, (· (gcd_dvd_left a b) (gcd_dvd_right a b))⟩
@[simp]
theorem normalize_gcd [NormalizedGCDMonoid α] : ∀ a b : α, normalize (gcd a b) = gcd a b :=
NormalizedGCDMonoid.normalize_gcd
theorem gcd_mul_lcm [GCDMonoid α] : ∀ a b : α, Associated (gcd a b * lcm a b) (a * b) :=
GCDMonoid.gcd_mul_lcm
section GCD
theorem dvd_gcd_iff [GCDMonoid α] (a b c : α) : a ∣ gcd b c ↔ a ∣ b ∧ a ∣ c :=
Iff.intro (fun h => ⟨h.trans (gcd_dvd_left _ _), h.trans (gcd_dvd_right _ _)⟩) fun ⟨hab, hac⟩ =>
dvd_gcd hab hac
theorem gcd_comm [NormalizedGCDMonoid α] (a b : α) : gcd a b = gcd b a :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
theorem gcd_comm' [GCDMonoid α] (a b : α) : Associated (gcd a b) (gcd b a) :=
associated_of_dvd_dvd (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
theorem gcd_assoc [NormalizedGCDMonoid α] (m n k : α) : gcd (gcd m n) k = gcd m (gcd n k) :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n))
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k)))
(dvd_gcd
(dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k)))
((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k)))
theorem gcd_assoc' [GCDMonoid α] (m n k : α) : Associated (gcd (gcd m n) k) (gcd m (gcd n k)) :=
associated_of_dvd_dvd
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n))
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k)))
(dvd_gcd
(dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k)))
((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k)))
instance [NormalizedGCDMonoid α] : Std.Commutative (α := α) gcd where
comm := gcd_comm
instance [NormalizedGCDMonoid α] : Std.Associative (α := α) gcd where
assoc := gcd_assoc
theorem gcd_eq_normalize [NormalizedGCDMonoid α] {a b c : α} (habc : gcd a b ∣ c)
(hcab : c ∣ gcd a b) : gcd a b = normalize c :=
normalize_gcd a b ▸ normalize_eq_normalize habc hcab
@[simp]
theorem gcd_zero_left [NormalizedGCDMonoid α] (a : α) : gcd 0 a = normalize a :=
gcd_eq_normalize (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a))
theorem gcd_zero_left' [GCDMonoid α] (a : α) : Associated (gcd 0 a) a :=
associated_of_dvd_dvd (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a))
@[simp]
theorem gcd_zero_right [NormalizedGCDMonoid α] (a : α) : gcd a 0 = normalize a :=
gcd_eq_normalize (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _))
theorem gcd_zero_right' [GCDMonoid α] (a : α) : Associated (gcd a 0) a :=
associated_of_dvd_dvd (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _))
@[simp]
theorem gcd_eq_zero_iff [GCDMonoid α] (a b : α) : gcd a b = 0 ↔ a = 0 ∧ b = 0 :=
Iff.intro
(fun h => by
let ⟨ca, ha⟩ := gcd_dvd_left a b
let ⟨cb, hb⟩ := gcd_dvd_right a b
rw [h, zero_mul] at ha hb
exact ⟨ha, hb⟩)
fun ⟨ha, hb⟩ => by
rw [ha, hb, ← zero_dvd_iff]
apply dvd_gcd <;> rfl
theorem gcd_ne_zero_of_left [GCDMonoid α] {a b : α} (ha : a ≠ 0) : gcd a b ≠ 0 := by
simp_all
theorem gcd_ne_zero_of_right [GCDMonoid α] {a b : α} (hb : b ≠ 0) : gcd a b ≠ 0 := by
simp_all
@[simp]
theorem gcd_one_left [NormalizedGCDMonoid α] (a : α) : gcd 1 a = 1 :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_left _ _) (one_dvd _)
@[simp]
theorem isUnit_gcd_one_left [GCDMonoid α] (a : α) : IsUnit (gcd 1 a) :=
isUnit_of_dvd_one (gcd_dvd_left _ _)
theorem gcd_one_left' [GCDMonoid α] (a : α) : Associated (gcd 1 a) 1 := by simp
@[simp]
theorem gcd_one_right [NormalizedGCDMonoid α] (a : α) : gcd a 1 = 1 :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_right _ _) (one_dvd _)
@[simp]
theorem isUnit_gcd_one_right [GCDMonoid α] (a : α) : IsUnit (gcd a 1) :=
isUnit_of_dvd_one (gcd_dvd_right _ _)
theorem gcd_one_right' [GCDMonoid α] (a : α) : Associated (gcd a 1) 1 := by simp
theorem gcd_dvd_gcd [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : gcd a c ∣ gcd b d :=
dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd)
protected theorem Associated.gcd [GCDMonoid α]
{a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) :
Associated (gcd a₁ b₁) (gcd a₂ b₂) :=
associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.dvd' hb.dvd')
@[simp]
theorem gcd_same [NormalizedGCDMonoid α] (a : α) : gcd a a = normalize a :=
gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a))
@[simp]
theorem gcd_mul_left [NormalizedGCDMonoid α] (a b c : α) :
gcd (a * b) (a * c) = normalize a * gcd b c :=
(by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero]))
fun ha : a ≠ 0 =>
suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa
let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c)
gcd_eq_normalize
(eq.symm ▸ mul_dvd_mul_left a
(show d ∣ gcd b c from
dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _)
((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _)))
(dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _))
theorem gcd_mul_left' [GCDMonoid α] (a b c : α) :
Associated (gcd (a * b) (a * c)) (a * gcd b c) := by
obtain rfl | ha := eq_or_ne a 0
· simp only [zero_mul, gcd_zero_left']
obtain ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c)
apply associated_of_dvd_dvd
· rw [eq]
apply mul_dvd_mul_left
exact
dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _)
((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _)
· exact dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _)
@[simp]
theorem gcd_mul_right [NormalizedGCDMonoid α] (a b c : α) :
gcd (b * a) (c * a) = gcd b c * normalize a := by simp only [mul_comm, gcd_mul_left]
@[simp]
theorem gcd_mul_right' [GCDMonoid α] (a b c : α) :
Associated (gcd (b * a) (c * a)) (gcd b c * a) := by
simp only [mul_comm, gcd_mul_left']
theorem gcd_eq_left_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize a = a) :
gcd a b = a ↔ a ∣ b :=
(Iff.intro fun eq => eq ▸ gcd_dvd_right _ _) fun hab =>
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) h (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) hab)
theorem gcd_eq_right_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize b = b) :
gcd a b = b ↔ b ∣ a := by simpa only [gcd_comm a b] using gcd_eq_left_iff b a h
theorem gcd_dvd_gcd_mul_left [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (k * m) n :=
gcd_dvd_gcd (dvd_mul_left _ _) dvd_rfl
theorem gcd_dvd_gcd_mul_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (m * k) n :=
gcd_dvd_gcd (dvd_mul_right _ _) dvd_rfl
theorem gcd_dvd_gcd_mul_left_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (k * n) :=
gcd_dvd_gcd dvd_rfl (dvd_mul_left _ _)
theorem gcd_dvd_gcd_mul_right_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (n * k) :=
gcd_dvd_gcd dvd_rfl (dvd_mul_right _ _)
theorem Associated.gcd_eq_left [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) :
gcd m k = gcd n k :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd h.dvd dvd_rfl)
(gcd_dvd_gcd h.symm.dvd dvd_rfl)
theorem Associated.gcd_eq_right [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) :
gcd k m = gcd k n :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd dvd_rfl h.dvd)
(gcd_dvd_gcd dvd_rfl h.symm.dvd)
theorem dvd_gcd_mul_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ gcd k m * n :=
(dvd_gcd (dvd_mul_right _ n) H).trans (gcd_mul_right' n k m).dvd
theorem dvd_gcd_mul_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ gcd k m * n ↔ k ∣ m * n :=
⟨fun h => h.trans (mul_dvd_mul (gcd_dvd_right k m) dvd_rfl), dvd_gcd_mul_of_dvd_mul⟩
theorem dvd_mul_gcd_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ m * gcd k n := by
rw [mul_comm] at H ⊢
exact dvd_gcd_mul_of_dvd_mul H
| Mathlib/Algebra/GCDMonoid/Basic.lean | 468 | 479 | theorem dvd_mul_gcd_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ m * gcd k n ↔ k ∣ m * n :=
⟨fun h => h.trans (mul_dvd_mul dvd_rfl (gcd_dvd_right k n)), dvd_mul_gcd_of_dvd_mul⟩
/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`.
Note: In general, this representation is highly non-unique.
See `Nat.dvdProdDvdOfDvdProd` for a constructive version on `ℕ`. -/
instance [h : Nonempty (GCDMonoid α)] : DecompositionMonoid α where
primal k m n H := by | cases h
by_cases h0 : gcd k m = 0 |
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Cover
import Mathlib.Order.Iterate
/-!
# Successor and predecessor
This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is
the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples
include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor
order...
## Typeclasses
* `SuccOrder`: Order equipped with a sensible successor function.
* `PredOrder`: Order equipped with a sensible predecessor function.
## Implementation notes
Maximal elements don't have a sensible successor. Thus the naïve typeclass
```lean
class NaiveSuccOrder (α : Type*) [Preorder α] where
(succ : α → α)
(succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b)
(lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b)
```
can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and
`lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`).
The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a`
for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of
`max_of_succ_le`).
The stricter condition of every element having a sensible successor can be obtained through the
combination of `SuccOrder α` and `NoMaxOrder α`.
-/
open Function OrderDual Set
variable {α β : Type*}
/-- Order equipped with a sensible successor function. -/
@[ext]
class SuccOrder (α : Type*) [Preorder α] where
/-- Successor function -/
succ : α → α
/-- Proof of basic ordering with respect to `succ` -/
le_succ : ∀ a, a ≤ succ a
/-- Proof of interaction between `succ` and maximal element -/
max_of_succ_le {a} : succ a ≤ a → IsMax a
/-- Proof that `succ a` is the least element greater than `a` -/
succ_le_of_lt {a b} : a < b → succ a ≤ b
/-- Order equipped with a sensible predecessor function. -/
@[ext]
class PredOrder (α : Type*) [Preorder α] where
/-- Predecessor function -/
pred : α → α
/-- Proof of basic ordering with respect to `pred` -/
pred_le : ∀ a, pred a ≤ a
/-- Proof of interaction between `pred` and minimal element -/
min_of_le_pred {a} : a ≤ pred a → IsMin a
/-- Proof that `pred b` is the greatest element less than `b` -/
le_pred_of_lt {a b} : a < b → a ≤ pred b
instance [Preorder α] [SuccOrder α] :
PredOrder αᵒᵈ where
pred := toDual ∘ SuccOrder.succ ∘ ofDual
pred_le := by
simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual,
SuccOrder.le_succ, implies_true]
min_of_le_pred h := by apply SuccOrder.max_of_succ_le h
le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h
instance [Preorder α] [PredOrder α] :
SuccOrder αᵒᵈ where
succ := toDual ∘ PredOrder.pred ∘ ofDual
le_succ := by
simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual,
PredOrder.pred_le, implies_true]
max_of_succ_le h := by apply PredOrder.min_of_le_pred h
succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h
section Preorder
variable [Preorder α]
/-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/
def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) :
SuccOrder α :=
{ succ
le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le
max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim
succ_le_of_lt := fun h => hsucc_le_iff.2 h }
/-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/
def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) :
PredOrder α :=
{ pred
pred_le := fun _ => (hle_pred_iff.1 le_rfl).le
min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim
le_pred_of_lt := fun h => hle_pred_iff.2 h }
end Preorder
section LinearOrder
variable [LinearOrder α]
/-- A constructor for `SuccOrder α` for `α` a linear order. -/
@[simps]
def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b)
(hm : ∀ a, IsMax a → succ a = a) : SuccOrder α :=
{ succ
succ_le_of_lt := fun {a b} =>
by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp
le_succ := fun a =>
by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not
max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not }
/-- A constructor for `PredOrder α` for `α` a linear order. -/
@[simps]
def PredOrder.ofCore (pred : α → α)
(hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) :
PredOrder α :=
{ pred
le_pred_of_lt := fun {a b} =>
by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr
pred_le := fun a =>
by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not
min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not }
variable (α)
open Classical in
/-- A well-order is a `SuccOrder`. -/
noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α :=
ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a)
(fun ha _ ↦ by
rw [not_isMax_iff] at ha
simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha]
exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩)
fun _ ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·)
/-- A linear order with well-founded greater-than relation is a `PredOrder`. -/
noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] :
PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ)
end LinearOrder
/-! ### Successor order -/
namespace Order
section Preorder
variable [Preorder α] [SuccOrder α] {a b : α}
/-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater
than `a`. If `a` is maximal, then `succ a = a`. -/
def succ : α → α :=
SuccOrder.succ
theorem le_succ : ∀ a : α, a ≤ succ a :=
SuccOrder.le_succ
theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a :=
SuccOrder.max_of_succ_le
theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b :=
SuccOrder.succ_le_of_lt
alias _root_.LT.lt.succ_le := succ_le_of_lt
@[simp]
theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a :=
⟨max_of_succ_le, fun h => h <| le_succ _⟩
alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax
@[simp]
theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a :=
⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩
alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax
theorem wcovBy_succ (a : α) : a ⩿ succ a :=
⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩
theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a :=
(wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h
theorem lt_succ_of_le_of_not_isMax (hab : b ≤ a) (ha : ¬IsMax a) : b < succ a :=
hab.trans_lt <| lt_succ_of_not_isMax ha
theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b :=
⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩
lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b :=
lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb
@[simp, mono, gcongr]
theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by
by_cases hb : IsMax b
· by_cases hba : b ≤ a
· exact (hb <| hba.trans <| le_succ _).trans (le_succ _)
· exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b)
· rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h]
apply lt_succ_of_le_of_not_isMax h hb
theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ
/-- See also `Order.succ_eq_of_covBy`. -/
lemma le_succ_of_wcovBy (h : a ⩿ b) : b ≤ succ a := by
obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le
· by_contra hba
exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_le hba
· exact hba.trans (le_succ _)
alias _root_.WCovBy.le_succ := le_succ_of_wcovBy
theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x :=
id_le_iterate_of_id_le le_succ _ _
theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a)
(h_lt : n < m) : IsMax (succ^[n] a) := by
refine max_of_succ_le (le_trans ?_ h_eq.symm.le)
rw [← iterate_succ_apply' succ]
have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt
exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le
theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a)
(h_ne : n ≠ m) : IsMax (succ^[n] a) := by
rcases le_total n m with h | h
· exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne)
· rw [h_eq]
exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm)
theorem Iic_subset_Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iic a ⊆ Iio (succ a) :=
fun _ => (lt_succ_of_le_of_not_isMax · ha)
theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a :=
Set.ext fun _ => succ_le_iff_of_not_isMax ha
theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Icc a b ⊆ Ico a (succ b) := by
rw [← Ici_inter_Iio, ← Ici_inter_Iic]
gcongr
intro _ h
apply lt_succ_of_le_of_not_isMax h hb
theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioc a b ⊆ Ioo a (succ b) := by
rw [← Ioi_inter_Iio, ← Ioi_inter_Iic]
gcongr
intro _ h
apply Iic_subset_Iio_succ_of_not_isMax hb h
theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by
rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic]
theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by
rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio]
section NoMaxOrder
variable [NoMaxOrder α]
theorem lt_succ (a : α) : a < succ a :=
lt_succ_of_not_isMax <| not_isMax a
@[simp]
theorem lt_succ_of_le : a ≤ b → a < succ b :=
(lt_succ_of_le_of_not_isMax · <| not_isMax b)
@[simp]
theorem succ_le_iff : succ a ≤ b ↔ a < b :=
succ_le_iff_of_not_isMax <| not_isMax a
@[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab]
theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ
theorem covBy_succ (a : α) : a ⋖ succ a :=
covBy_succ_of_not_isMax <| not_isMax a
theorem Iic_subset_Iio_succ (a : α) : Iic a ⊆ Iio (succ a) := by simp
@[simp]
theorem Ici_succ (a : α) : Ici (succ a) = Ioi a :=
Ici_succ_of_not_isMax <| not_isMax _
@[simp]
theorem Icc_subset_Ico_succ_right (a b : α) : Icc a b ⊆ Ico a (succ b) :=
Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem Ioc_subset_Ioo_succ_right (a b : α) : Ioc a b ⊆ Ioo a (succ b) :=
Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b :=
Icc_succ_left_of_not_isMax <| not_isMax _
@[simp]
theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b :=
Ico_succ_left_of_not_isMax <| not_isMax _
end NoMaxOrder
end Preorder
section PartialOrder
variable [PartialOrder α] [SuccOrder α] {a b : α}
@[simp]
theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a :=
⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩
alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax
lemma le_iff_eq_or_succ_le : a ≤ b ↔ a = b ∨ succ a ≤ b := by
by_cases ha : IsMax a
· simpa [ha.succ_eq] using le_of_eq
· rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt]
theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by
refine
⟨fun h =>
or_iff_not_imp_left.2 fun hba : b ≠ a =>
h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm),
?_⟩
rintro (rfl | rfl)
· exact ⟨le_rfl, le_succ b⟩
· exact ⟨le_succ a, le_rfl⟩
/-- See also `Order.le_succ_of_wcovBy`. -/
lemma succ_eq_of_covBy (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ
alias _root_.CovBy.succ_eq := succ_eq_of_covBy
theorem _root_.OrderIso.map_succ [PartialOrder β] [SuccOrder β] (f : α ≃o β) (a : α) :
f (succ a) = succ (f a) := by
by_cases h : IsMax a
· rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq]
· exact (f.map_covBy.2 <| covBy_succ_of_not_isMax h).succ_eq.symm
section NoMaxOrder
variable [NoMaxOrder α]
theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b :=
⟨by rintro rfl; exact covBy_succ _, CovBy.succ_eq⟩
end NoMaxOrder
section OrderTop
variable [OrderTop α]
@[simp]
theorem succ_top : succ (⊤ : α) = ⊤ := by
rw [succ_eq_iff_isMax, isMax_iff_eq_top]
theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ :=
succ_le_iff_isMax.trans isMax_iff_eq_top
theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ :=
lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top
end OrderTop
section OrderBot
variable [OrderBot α] [Nontrivial α]
theorem bot_lt_succ (a : α) : ⊥ < succ a :=
(lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le
theorem succ_ne_bot (a : α) : succ a ≠ ⊥ :=
(bot_lt_succ a).ne'
end OrderBot
end PartialOrder
section LinearOrder
variable [LinearOrder α] [SuccOrder α] {a b : α}
theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := fun h ↦ by
by_contra! nh
exact (h.trans_le (succ_le_of_lt nh)).false
theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a :=
⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩
theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) :
succ a < succ b ↔ a < b := by
rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha]
theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) :
succ a ≤ succ b ↔ a ≤ b := by
rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb]
theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a :=
Set.ext fun _ => lt_succ_iff_of_not_isMax ha
theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by
rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic]
theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by
rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic]
theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) :
succ a = succ b ↔ a = b := by
rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb,
succ_lt_succ_iff_of_not_isMax ha hb]
theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by
by_cases hb : IsMax b
· rw [hb.succ_eq, or_iff_right_of_imp le_of_eq]
· rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt]
theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b :=
(lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt
theorem not_isMin_succ [Nontrivial α] (a : α) : ¬ IsMin (succ a) := by
obtain ha | ha := (le_succ a).eq_or_lt
· exact (ha ▸ succ_eq_iff_isMax.1 ha.symm).not_isMin
· exact not_isMin_of_lt ha
theorem Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) :=
ext fun _ => le_succ_iff_eq_or_le
theorem Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by
simp_rw [← Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)]
theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by
simp_rw [← Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)]
theorem Iio_succ_eq_insert_of_not_isMax (h : ¬IsMax a) : Iio (succ a) = insert a (Iio a) :=
ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h
theorem Ico_succ_right_eq_insert_of_not_isMax (h₁ : a ≤ b) (h₂ : ¬IsMax b) :
Ico a (succ b) = insert b (Ico a b) := by
simp_rw [← Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ici.2 h₁)]
| Mathlib/Order/SuccPred/Basic.lean | 452 | 455 | theorem Ioo_succ_right_eq_insert_of_not_isMax (h₁ : a < b) (h₂ : ¬IsMax b) :
Ioo a (succ b) = insert b (Ioo a b) := by | simp_rw [← Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ioi.2 h₁)] |
/-
Copyright (c) 2024 Jeremy Tan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Tan
-/
import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds
/-!
# Complex arctangent
This file defines the complex arctangent `Complex.arctan` as
$$\arctan z = -\frac i2 \log \frac{1 + zi}{1 - zi}$$
and shows that it extends `Real.arctan` to the complex plane. Its Taylor series expansion
$$\arctan z = \frac{(-1)^n}{2n + 1} z^{2n + 1},\ |z|<1$$
is proved in `Complex.hasSum_arctan`.
-/
namespace Complex
open scoped Real
/-- The complex arctangent, defined via the complex logarithm. -/
noncomputable def arctan (z : ℂ) : ℂ := -I / 2 * log ((1 + z * I) / (1 - z * I))
theorem tan_arctan {z : ℂ} (h₁ : z ≠ I) (h₂ : z ≠ -I) : tan (arctan z) = z := by
unfold tan sin cos
rw [div_div_eq_mul_div, div_mul_cancel₀ _ two_ne_zero, ← div_mul_eq_mul_div,
-- multiply top and bottom by `exp (arctan z * I)`
← mul_div_mul_right _ _ (exp_ne_zero (arctan z * I)), sub_mul, add_mul,
← exp_add, neg_mul, neg_add_cancel, exp_zero, ← exp_add, ← two_mul]
have z₁ : 1 + z * I ≠ 0 := by
contrapose! h₁
rw [add_eq_zero_iff_neg_eq, ← div_eq_iff I_ne_zero, div_I, neg_one_mul, neg_neg] at h₁
exact h₁.symm
have z₂ : 1 - z * I ≠ 0 := by
contrapose! h₂
rw [sub_eq_zero, ← div_eq_iff I_ne_zero, div_I, one_mul] at h₂
exact h₂.symm
have key : exp (2 * (arctan z * I)) = (1 + z * I) / (1 - z * I) := by
rw [arctan, ← mul_rotate, ← mul_assoc,
show 2 * (I * (-I / 2)) = 1 by field_simp, one_mul, exp_log]
· exact div_ne_zero z₁ z₂
-- multiply top and bottom by `1 - z * I`
rw [key, ← mul_div_mul_right _ _ z₂, sub_mul, add_mul, div_mul_cancel₀ _ z₂, one_mul,
show _ / _ * I = -(I * I) * z by ring, I_mul_I, neg_neg, one_mul]
/-- `cos z` is nonzero when the bounds in `arctan_tan` are met (`z` lies in the vertical strip
`-π / 2 < z.re < π / 2` and `z ≠ π / 2`). -/
lemma cos_ne_zero_of_arctan_bounds {z : ℂ} (h₀ : z ≠ π / 2) (h₁ : -(π / 2) < z.re)
(h₂ : z.re ≤ π / 2) : cos z ≠ 0 := by
refine cos_ne_zero_iff.mpr (fun k ↦ ?_)
rw [ne_eq, Complex.ext_iff, not_and_or] at h₀ ⊢
norm_cast at h₀ ⊢
rcases h₀ with nr | ni
· left; contrapose! nr
rw [nr, mul_div_assoc, neg_eq_neg_one_mul, mul_lt_mul_iff_of_pos_right (by positivity)] at h₁
rw [nr, ← one_mul (π / 2), mul_div_assoc, mul_le_mul_iff_of_pos_right (by positivity)] at h₂
norm_cast at h₁ h₂
change -1 < _ at h₁
rwa [show 2 * k + 1 = 1 by omega, Int.cast_one, one_mul] at nr
· exact Or.inr ni
| Mathlib/Analysis/SpecialFunctions/Complex/Arctan.lean | 64 | 77 | theorem arctan_tan {z : ℂ} (h₀ : z ≠ π / 2) (h₁ : -(π / 2) < z.re) (h₂ : z.re ≤ π / 2) :
arctan (tan z) = z := by | have h := cos_ne_zero_of_arctan_bounds h₀ h₁ h₂
unfold arctan tan
-- multiply top and bottom by `cos z`
rw [← mul_div_mul_right (1 + _) _ h, add_mul, sub_mul, one_mul, ← mul_rotate, mul_div_cancel₀ _ h]
conv_lhs =>
enter [2, 1, 2]
rw [sub_eq_add_neg, ← neg_mul, ← sin_neg, ← cos_neg]
rw [← exp_mul_I, ← exp_mul_I, ← exp_sub, show z * I - -z * I = 2 * (I * z) by ring, log_exp,
show -I / 2 * (2 * (I * z)) = -(I * I) * z by ring, I_mul_I, neg_neg, one_mul]
all_goals norm_num
· rwa [← div_lt_iff₀' two_pos, neg_div]
· rwa [← le_div_iff₀' two_pos] |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Eric Wieser
-/
import Mathlib.Algebra.Group.Fin.Tuple
import Mathlib.Data.Matrix.RowCol
import Mathlib.Data.Fin.VecNotation
import Mathlib.Tactic.FinCases
import Mathlib.Algebra.BigOperators.Fin
/-!
# Matrix and vector notation
This file includes `simp` lemmas for applying operations in `Data.Matrix.Basic` to values built out
of the matrix notation `![a, b] = vecCons a (vecCons b vecEmpty)` defined in
`Data.Fin.VecNotation`.
This also provides the new notation `!![a, b; c, d] = Matrix.of ![![a, b], ![c, d]]`.
This notation also works for empty matrices; `!![,,,] : Matrix (Fin 0) (Fin 3)` and
`!![;;;] : Matrix (Fin 3) (Fin 0)`.
## Implementation notes
The `simp` lemmas require that one of the arguments is of the form `vecCons _ _`.
This ensures `simp` works with entries only when (some) entries are already given.
In other words, this notation will only appear in the output of `simp` if it
already appears in the input.
## Notations
This file provide notation `!![a, b; c, d]` for matrices, which corresponds to
`Matrix.of ![![a, b], ![c, d]]`.
## Examples
Examples of usage can be found in the `MathlibTest/matrix.lean` file.
-/
namespace Matrix
universe u uₘ uₙ uₒ
variable {α : Type u} {o n m : ℕ} {m' : Type uₘ} {n' : Type uₙ} {o' : Type uₒ}
open Matrix
section toExpr
open Lean Qq
open Qq in
/-- `Matrix.mkLiteralQ !![a, b; c, d]` produces the term `q(!![$a, $b; $c, $d])`. -/
def mkLiteralQ {u : Level} {α : Q(Type u)} {m n : Nat} (elems : Matrix (Fin m) (Fin n) Q($α)) :
Q(Matrix (Fin $m) (Fin $n) $α) :=
let elems := PiFin.mkLiteralQ (α := q(Fin $n → $α)) fun i => PiFin.mkLiteralQ fun j => elems i j
q(Matrix.of $elems)
/-- Matrices can be reflected whenever their entries can. We insert a `Matrix.of` to
prevent immediate decay to a function. -/
protected instance toExpr [ToLevel.{u}] [ToLevel.{uₘ}] [ToLevel.{uₙ}]
[Lean.ToExpr α] [Lean.ToExpr m'] [Lean.ToExpr n'] [Lean.ToExpr (m' → n' → α)] :
Lean.ToExpr (Matrix m' n' α) :=
have eα : Q(Type $(toLevel.{u})) := toTypeExpr α
have em' : Q(Type $(toLevel.{uₘ})) := toTypeExpr m'
have en' : Q(Type $(toLevel.{uₙ})) := toTypeExpr n'
{ toTypeExpr :=
q(Matrix $eα $em' $en')
toExpr := fun M =>
have eM : Q($em' → $en' → $eα) := toExpr (show m' → n' → α from M)
q(Matrix.of $eM) }
end toExpr
section Parser
open Lean Meta Elab Term Macro TSyntax PrettyPrinter.Delaborator SubExpr
/-- Notation for m×n matrices, aka `Matrix (Fin m) (Fin n) α`.
For instance:
* `!![a, b, c; d, e, f]` is the matrix with two rows and three columns, of type
`Matrix (Fin 2) (Fin 3) α`
* `!![a, b, c]` is a row vector of type `Matrix (Fin 1) (Fin 3) α` (see also `Matrix.row`).
* `!![a; b; c]` is a column vector of type `Matrix (Fin 3) (Fin 1) α` (see also `Matrix.col`).
This notation implements some special cases:
* `![,,]`, with `n` `,`s, is a term of type `Matrix (Fin 0) (Fin n) α`
* `![;;]`, with `m` `;`s, is a term of type `Matrix (Fin m) (Fin 0) α`
* `![]` is the 0×0 matrix
Note that vector notation is provided elsewhere (by `Matrix.vecNotation`) as `![a, b, c]`.
Under the hood, `!![a, b, c; d, e, f]` is syntax for `Matrix.of ![![a, b, c], ![d, e, f]]`.
-/
syntax (name := matrixNotation)
"!![" ppRealGroup(sepBy1(ppGroup(term,+,?), ";", "; ", allowTrailingSep)) "]" : term
@[inherit_doc matrixNotation]
syntax (name := matrixNotationRx0) "!![" ";"+ "]" : term
@[inherit_doc matrixNotation]
syntax (name := matrixNotation0xC) "!![" ","* "]" : term
macro_rules
| `(!![$[$[$rows],*];*]) => do
let m := rows.size
let n := if h : 0 < m then rows[0].size else 0
let rowVecs ← rows.mapM fun row : Array Term => do
unless row.size = n do
Macro.throwErrorAt (mkNullNode row) s!"\
Rows must be of equal length; this row has {row.size} items, \
the previous rows have {n}"
`(![$row,*])
`(@Matrix.of (Fin $(quote m)) (Fin $(quote n)) _ ![$rowVecs,*])
| `(!![$[;%$semicolons]*]) => do
let emptyVec ← `(![])
let emptyVecs := semicolons.map (fun _ => emptyVec)
`(@Matrix.of (Fin $(quote semicolons.size)) (Fin 0) _ ![$emptyVecs,*])
| `(!![$[,%$commas]*]) => `(@Matrix.of (Fin 0) (Fin $(quote commas.size)) _ ![])
/-- Delaborator for the `!![]` notation. -/
@[app_delab DFunLike.coe]
def delabMatrixNotation : Delab := whenNotPPOption getPPExplicit <| whenPPOption getPPNotation <|
withOverApp 6 do
let mkApp3 (.const ``Matrix.of _) (.app (.const ``Fin _) em) (.app (.const ``Fin _) en) _ :=
(← getExpr).appFn!.appArg! | failure
let some m ← withNatValue em (pure ∘ some) | failure
let some n ← withNatValue en (pure ∘ some) | failure
withAppArg do
if m = 0 then
guard <| (← getExpr).isAppOfArity ``vecEmpty 1
let commas := .replicate n (mkAtom ",")
`(!![$[,%$commas]*])
else
if n = 0 then
let `(![$[![]%$evecs],*]) ← delab | failure
`(!![$[;%$evecs]*])
else
let `(![$[![$[$melems],*]],*]) ← delab | failure
`(!![$[$[$melems],*];*])
end Parser
variable (a b : ℕ)
/-- Use `![...]` notation for displaying a `Fin`-indexed matrix, for example:
```
#eval !![1, 2; 3, 4] + !![3, 4; 5, 6] -- !![4, 6; 8, 10]
```
-/
instance repr [Repr α] : Repr (Matrix (Fin m) (Fin n) α) where
reprPrec f _p :=
(Std.Format.bracket "!![" · "]") <|
(Std.Format.joinSep · (";" ++ Std.Format.line)) <|
(List.finRange m).map fun i =>
Std.Format.fill <| -- wrap line in a single place rather than all at once
(Std.Format.joinSep · ("," ++ Std.Format.line)) <|
(List.finRange n).map fun j => _root_.repr (f i j)
@[simp]
theorem cons_val' (v : n' → α) (B : Fin m → n' → α) (i j) :
vecCons v B i j = vecCons (v j) (fun i => B i j) i := by refine Fin.cases ?_ ?_ i <;> simp
@[simp]
theorem head_val' (B : Fin m.succ → n' → α) (j : n') : (vecHead fun i => B i j) = vecHead B j :=
rfl
@[simp]
theorem tail_val' (B : Fin m.succ → n' → α) (j : n') :
(vecTail fun i => B i j) = fun i => vecTail B i j := rfl
section DotProduct
variable [AddCommMonoid α] [Mul α]
@[simp]
theorem dotProduct_empty (v w : Fin 0 → α) : dotProduct v w = 0 :=
Finset.sum_empty
@[simp]
theorem cons_dotProduct (x : α) (v : Fin n → α) (w : Fin n.succ → α) :
dotProduct (vecCons x v) w = x * vecHead w + dotProduct v (vecTail w) := by
simp [dotProduct, Fin.sum_univ_succ, vecHead, vecTail]
@[simp]
theorem dotProduct_cons (v : Fin n.succ → α) (x : α) (w : Fin n → α) :
dotProduct v (vecCons x w) = vecHead v * x + dotProduct (vecTail v) w := by
simp [dotProduct, Fin.sum_univ_succ, vecHead, vecTail]
| Mathlib/Data/Matrix/Notation.lean | 190 | 193 | theorem cons_dotProduct_cons (x : α) (v : Fin n → α) (y : α) (w : Fin n → α) :
dotProduct (vecCons x v) (vecCons y w) = x * y + dotProduct v w := by | simp
end DotProduct |
/-
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.Data.Nat.ModEq
/-!
# Congruences modulo an integer
This file defines the equivalence relation `a ≡ b [ZMOD n]` on the integers, similarly to how
`Data.Nat.ModEq` defines them for the natural numbers. The notation is short for `n.ModEq a b`,
which is defined to be `a % n = b % n` for integers `a b n`.
## Tags
modeq, congruence, mod, MOD, modulo, integers
-/
namespace Int
/-- `a ≡ b [ZMOD n]` when `a % n = b % n`. -/
def ModEq (n a b : ℤ) :=
a % n = b % n
@[inherit_doc]
notation:50 a " ≡ " b " [ZMOD " n "]" => ModEq n a b
variable {m n a b c d : ℤ}
instance : Decidable (ModEq n a b) := decEq (a % n) (b % n)
namespace ModEq
@[refl, simp]
protected theorem refl (a : ℤ) : a ≡ a [ZMOD n] :=
@rfl _ _
protected theorem rfl : a ≡ a [ZMOD n] :=
ModEq.refl _
instance : IsRefl _ (ModEq n) :=
⟨ModEq.refl⟩
@[symm]
protected theorem symm : a ≡ b [ZMOD n] → b ≡ a [ZMOD n] :=
Eq.symm
@[trans]
protected theorem trans : a ≡ b [ZMOD n] → b ≡ c [ZMOD n] → a ≡ c [ZMOD n] :=
Eq.trans
instance : IsTrans ℤ (ModEq n) where
trans := @Int.ModEq.trans n
protected theorem eq : a ≡ b [ZMOD n] → a % n = b % n := id
end ModEq
theorem modEq_comm : a ≡ b [ZMOD n] ↔ b ≡ a [ZMOD n] := ⟨ModEq.symm, ModEq.symm⟩
theorem natCast_modEq_iff {a b n : ℕ} : a ≡ b [ZMOD n] ↔ a ≡ b [MOD n] := by
unfold ModEq Nat.ModEq; rw [← Int.ofNat_inj]; simp [natCast_mod]
theorem modEq_zero_iff_dvd : a ≡ 0 [ZMOD n] ↔ n ∣ a := by
rw [ModEq, zero_emod, dvd_iff_emod_eq_zero]
theorem _root_.Dvd.dvd.modEq_zero_int (h : n ∣ a) : a ≡ 0 [ZMOD n] :=
modEq_zero_iff_dvd.2 h
theorem _root_.Dvd.dvd.zero_modEq_int (h : n ∣ a) : 0 ≡ a [ZMOD n] :=
h.modEq_zero_int.symm
| Mathlib/Data/Int/ModEq.lean | 77 | 78 | theorem modEq_iff_dvd : a ≡ b [ZMOD n] ↔ n ∣ b - a := by | rw [ModEq, eq_comm] |
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SetFamily.Shadow
/-!
# UV-compressions
This file defines UV-compression. It is an operation on a set family that reduces its shadow.
UV-compressing `a : α` along `u v : α` means replacing `a` by `(a ⊔ u) \ v` if `a` and `u` are
disjoint and `v ≤ a`. In some sense, it's moving `a` from `v` to `u`.
UV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that
compressing a set family might decrease the size of its shadow, so iterated compressions hopefully
minimise the shadow.
## Main declarations
* `UV.compress`: `compress u v a` is `a` compressed along `u` and `v`.
* `UV.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`.
It is the compressions of the elements of `s` whose compression is not already in `s` along with
the element whose compression is already in `s`. This way of splitting into what moves and what
does not ensures the compression doesn't squash the set family, which is proved by
`UV.card_compression`.
* `UV.card_shadow_compression_le`: Compressing reduces the size of the shadow. This is a key fact in
the proof of Kruskal-Katona.
## Notation
`𝓒` (typed with `\MCC`) is notation for `UV.compression` in locale `FinsetFamily`.
## Notes
Even though our emphasis is on `Finset α`, we define UV-compressions more generally in a generalized
boolean algebra, so that one can use it for `Set α`.
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
## Tags
compression, UV-compression, shadow
-/
open Finset
variable {α : Type*}
/-- UV-compression is injective on the elements it moves. See `UV.compress`. -/
theorem sup_sdiff_injOn [GeneralizedBooleanAlgebra α] (u v : α) :
{ x | Disjoint u x ∧ v ≤ x }.InjOn fun x => (x ⊔ u) \ v := by
rintro a ha b hb hab
have h : ((a ⊔ u) \ v) \ u ⊔ v = ((b ⊔ u) \ v) \ u ⊔ v := by
dsimp at hab
rw [hab]
rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm,
hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h
-- The namespace is here to distinguish from other compressions.
namespace UV
/-! ### UV-compression in generalized boolean algebras -/
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α] [DecidableRel (@Disjoint α _ _)]
[DecidableLE α] {s : Finset α} {u v a : α}
/-- UV-compressing `a` means removing `v` from it and adding `u` if `a` and `u` are disjoint and
`v ≤ a` (it replaces the `v` part of `a` by the `u` part). Else, UV-compressing `a` doesn't do
anything. This is most useful when `u` and `v` are disjoint finsets of the same size. -/
def compress (u v a : α) : α :=
if Disjoint u a ∧ v ≤ a then (a ⊔ u) \ v else a
theorem compress_of_disjoint_of_le (hua : Disjoint u a) (hva : v ≤ a) :
compress u v a = (a ⊔ u) \ v :=
if_pos ⟨hua, hva⟩
theorem compress_of_disjoint_of_le' (hva : Disjoint v a) (hua : u ≤ a) :
compress u v ((a ⊔ v) \ u) = a := by
rw [compress_of_disjoint_of_le disjoint_sdiff_self_right
(le_sdiff.2 ⟨(le_sup_right : v ≤ a ⊔ v), hva.mono_right hua⟩),
sdiff_sup_cancel (le_sup_of_le_left hua), hva.symm.sup_sdiff_cancel_right]
@[simp]
theorem compress_self (u a : α) : compress u u a = a := by
unfold compress
split_ifs with h
· exact h.1.symm.sup_sdiff_cancel_right
· rfl
/-- An element can be compressed to any other element by removing/adding the differences. -/
@[simp]
theorem compress_sdiff_sdiff (a b : α) : compress (a \ b) (b \ a) b = a := by
refine (compress_of_disjoint_of_le disjoint_sdiff_self_left sdiff_le).trans ?_
rw [sup_sdiff_self_right, sup_sdiff, disjoint_sdiff_self_right.sdiff_eq_left, sup_eq_right]
exact sdiff_sdiff_le
/-- Compressing an element is idempotent. -/
@[simp]
theorem compress_idem (u v a : α) : compress u v (compress u v a) = compress u v a := by
unfold compress
split_ifs with h h'
· rw [le_sdiff_right.1 h'.2, sdiff_bot, sdiff_bot, sup_assoc, sup_idem]
· rfl
· rfl
variable [DecidableEq α]
/-- To UV-compress a set family, we compress each of its elements, except that we don't want to
reduce the cardinality, so we keep all elements whose compression is already present. -/
def compression (u v : α) (s : Finset α) :=
{a ∈ s | compress u v a ∈ s} ∪ {a ∈ s.image <| compress u v | a ∉ s}
@[inherit_doc]
scoped[FinsetFamily] notation "𝓒 " => UV.compression
open scoped FinsetFamily
/-- `IsCompressed u v s` expresses that `s` is UV-compressed. -/
def IsCompressed (u v : α) (s : Finset α) :=
𝓒 u v s = s
/-- UV-compression is injective on the sets that are not UV-compressed. -/
theorem compress_injOn : Set.InjOn (compress u v) ↑{a ∈ s | compress u v a ∉ s} := by
intro a ha b hb hab
rw [mem_coe, mem_filter] at ha hb
rw [compress] at ha hab
split_ifs at ha hab with has
· rw [compress] at hb hab
split_ifs at hb hab with hbs
· exact sup_sdiff_injOn u v has hbs hab
· exact (hb.2 hb.1).elim
· exact (ha.2 ha.1).elim
/-- `a` is in the UV-compressed family iff it's in the original and its compression is in the
original, or it's not in the original but it's the compression of something in the original. -/
theorem mem_compression :
a ∈ 𝓒 u v s ↔ a ∈ s ∧ compress u v a ∈ s ∨ a ∉ s ∧ ∃ b ∈ s, compress u v b = a := by
simp_rw [compression, mem_union, mem_filter, mem_image, and_comm]
protected theorem IsCompressed.eq (h : IsCompressed u v s) : 𝓒 u v s = s := h
@[simp]
theorem compression_self (u : α) (s : Finset α) : 𝓒 u u s = s := by
unfold compression
convert union_empty s
· ext a
rw [mem_filter, compress_self, and_self_iff]
· refine eq_empty_of_forall_not_mem fun a ha ↦ ?_
simp_rw [mem_filter, mem_image, compress_self] at ha
obtain ⟨⟨b, hb, rfl⟩, hb'⟩ := ha
exact hb' hb
/-- Any family is compressed along two identical elements. -/
theorem isCompressed_self (u : α) (s : Finset α) : IsCompressed u u s := compression_self u s
theorem compress_disjoint :
Disjoint {a ∈ s | compress u v a ∈ s} {a ∈ s.image <| compress u v | a ∉ s} :=
disjoint_left.2 fun _a ha₁ ha₂ ↦ (mem_filter.1 ha₂).2 (mem_filter.1 ha₁).1
theorem compress_mem_compression (ha : a ∈ s) : compress u v a ∈ 𝓒 u v s := by
rw [mem_compression]
by_cases h : compress u v a ∈ s
· rw [compress_idem]
exact Or.inl ⟨h, h⟩
· exact Or.inr ⟨h, a, ha, rfl⟩
-- This is a special case of `compress_mem_compression` once we have `compression_idem`.
theorem compress_mem_compression_of_mem_compression (ha : a ∈ 𝓒 u v s) :
compress u v a ∈ 𝓒 u v s := by
rw [mem_compression] at ha ⊢
simp only [compress_idem, exists_prop]
obtain ⟨_, ha⟩ | ⟨_, b, hb, rfl⟩ := ha
· exact Or.inl ⟨ha, ha⟩
· exact Or.inr ⟨by rwa [compress_idem], b, hb, (compress_idem _ _ _).symm⟩
/-- Compressing a family is idempotent. -/
@[simp]
theorem compression_idem (u v : α) (s : Finset α) : 𝓒 u v (𝓒 u v s) = 𝓒 u v s := by
have h : {a ∈ 𝓒 u v s | compress u v a ∉ 𝓒 u v s} = ∅ :=
filter_false_of_mem fun a ha h ↦ h <| compress_mem_compression_of_mem_compression ha
rw [compression, filter_image, h, image_empty, ← h]
exact filter_union_filter_neg_eq _ (compression u v s)
/-- Compressing a family doesn't change its size. -/
@[simp]
| Mathlib/Combinatorics/SetFamily/Compression/UV.lean | 194 | 200 | theorem card_compression (u v : α) (s : Finset α) : #(𝓒 u v s) = #s := by | rw [compression, card_union_of_disjoint compress_disjoint, filter_image,
card_image_of_injOn compress_injOn, ← card_union_of_disjoint (disjoint_filter_filter_neg s _ _),
filter_union_filter_neg_eq]
theorem le_of_mem_compression_of_not_mem (h : a ∈ 𝓒 u v s) (ha : a ∉ s) : u ≤ a := by
rw [mem_compression] at 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, Yury Kudryashov
-/
import Mathlib.Data.Finset.Fin
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Order.Interval.Set.Fin
/-!
# Finite intervals in `Fin n`
This file proves that `Fin n` is a `LocallyFiniteOrder` and calculates the cardinality of its
intervals as Finsets and Fintypes.
-/
assert_not_exists MonoidWithZero
open Finset Function
namespace Fin
variable (n : ℕ)
/-!
### Locally finite order etc instances
-/
instance instLocallyFiniteOrder (n : ℕ) : LocallyFiniteOrder (Fin n) where
finsetIcc a b := attachFin (Icc a b) fun x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2
finsetIco a b := attachFin (Ico a b) fun x hx ↦ (mem_Ico.mp hx).2.trans b.2
finsetIoc a b := attachFin (Ioc a b) fun x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2
finsetIoo a b := attachFin (Ioo a b) fun x hx ↦ (mem_Ioo.mp hx).2.trans b.2
finset_mem_Icc a b := by simp
finset_mem_Ico a b := by simp
finset_mem_Ioc a b := by simp
finset_mem_Ioo a b := by simp
instance instLocallyFiniteOrderBot : ∀ n, LocallyFiniteOrderBot (Fin n)
| 0 => IsEmpty.toLocallyFiniteOrderBot
| _ + 1 => inferInstance
instance instLocallyFiniteOrderTop : ∀ n, LocallyFiniteOrderTop (Fin n)
| 0 => IsEmpty.toLocallyFiniteOrderTop
| _ + 1 => inferInstance
variable {n}
variable {m : ℕ} (a b : Fin n)
@[simp]
theorem attachFin_Icc :
attachFin (Icc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2) = Icc a b :=
rfl
@[simp]
theorem attachFin_Ico :
attachFin (Ico a b) (fun _x hx ↦ (mem_Ico.mp hx).2.trans b.2) = Ico a b :=
rfl
@[simp]
theorem attachFin_Ioc :
attachFin (Ioc a b) (fun _x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2) = Ioc a b :=
rfl
@[simp]
theorem attachFin_Ioo :
attachFin (Ioo a b) (fun _x hx ↦ (mem_Ioo.mp hx).2.trans b.2) = Ioo a b :=
rfl
@[simp]
theorem attachFin_uIcc :
attachFin (uIcc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt (max a b).2) = uIcc a b :=
rfl
@[simp]
theorem attachFin_Ico_eq_Ici : attachFin (Ico a n) (fun _x hx ↦ (mem_Ico.mp hx).2) = Ici a := by
ext; simp
@[simp]
theorem attachFin_Ioo_eq_Ioi : attachFin (Ioo a n) (fun _x hx ↦ (mem_Ioo.mp hx).2) = Ioi a := by
ext; simp
@[simp]
theorem attachFin_Iic : attachFin (Iic a) (fun _x hx ↦ (mem_Iic.mp hx).trans_lt a.2) = Iic a := by
ext; simp
@[simp]
theorem attachFin_Iio : attachFin (Iio a) (fun _x hx ↦ (mem_Iio.mp hx).trans a.2) = Iio a := by
ext; simp
section deprecated
set_option linter.deprecated false in
@[deprecated attachFin_Icc (since := "2025-04-06")]
theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).fin n := attachFin_eq_fin _
set_option linter.deprecated false in
@[deprecated attachFin_Ico (since := "2025-04-06")]
theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).fin n := attachFin_eq_fin _
set_option linter.deprecated false in
@[deprecated attachFin_Ioc (since := "2025-04-06")]
theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).fin n := attachFin_eq_fin _
set_option linter.deprecated false in
@[deprecated attachFin_Ioo (since := "2025-04-06")]
theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).fin n := attachFin_eq_fin _
set_option linter.deprecated false in
@[deprecated attachFin_uIcc (since := "2025-04-06")]
theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).fin n := Icc_eq_finset_subtype _ _
set_option linter.deprecated false in
@[deprecated attachFin_Ico_eq_Ici (since := "2025-04-06")]
theorem Ici_eq_finset_subtype : Ici a = (Ico (a : ℕ) n).fin n := by ext; simp
set_option linter.deprecated false in
@[deprecated attachFin_Ioo_eq_Ioi (since := "2025-04-06")]
theorem Ioi_eq_finset_subtype : Ioi a = (Ioo (a : ℕ) n).fin n := by ext; simp
set_option linter.deprecated false in
@[deprecated attachFin_Iic (since := "2025-04-06")]
theorem Iic_eq_finset_subtype : Iic b = (Iic (b : ℕ)).fin n := by ext; simp
set_option linter.deprecated false in
@[deprecated attachFin_Iio (since := "2025-04-06")]
theorem Iio_eq_finset_subtype : Iio b = (Iio (b : ℕ)).fin n := by ext; simp
end deprecated
section val
/-!
### Images under `Fin.val`
-/
@[simp]
theorem finsetImage_val_Icc : (Icc a b).image val = Icc (a : ℕ) b :=
image_val_attachFin _
@[simp]
theorem finsetImage_val_Ico : (Ico a b).image val = Ico (a : ℕ) b :=
image_val_attachFin _
@[simp]
theorem finsetImage_val_Ioc : (Ioc a b).image val = Ioc (a : ℕ) b :=
image_val_attachFin _
@[simp]
theorem finsetImage_val_Ioo : (Ioo a b).image val = Ioo (a : ℕ) b :=
image_val_attachFin _
@[simp]
theorem finsetImage_val_uIcc : (uIcc a b).image val = uIcc (a : ℕ) b :=
finsetImage_val_Icc _ _
@[simp]
theorem finsetImage_val_Ici : (Ici a).image val = Ico (a : ℕ) n := by simp [← coe_inj]
@[simp]
theorem finsetImage_val_Ioi : (Ioi a).image val = Ioo (a : ℕ) n := by simp [← coe_inj]
@[simp]
theorem finsetImage_val_Iic : (Iic a).image val = Iic (a : ℕ) := by simp [← coe_inj]
@[simp]
theorem finsetImage_val_Iio : (Iio b).image val = Iio (b : ℕ) := by simp [← coe_inj]
/-!
### `Finset.map` along `Fin.valEmbedding`
-/
@[simp]
theorem map_valEmbedding_Icc : (Icc a b).map Fin.valEmbedding = Icc (a : ℕ) b :=
map_valEmbedding_attachFin _
@[simp]
theorem map_valEmbedding_Ico : (Ico a b).map Fin.valEmbedding = Ico (a : ℕ) b :=
map_valEmbedding_attachFin _
@[simp]
theorem map_valEmbedding_Ioc : (Ioc a b).map Fin.valEmbedding = Ioc (a : ℕ) b :=
map_valEmbedding_attachFin _
@[simp]
theorem map_valEmbedding_Ioo : (Ioo a b).map Fin.valEmbedding = Ioo (a : ℕ) b :=
map_valEmbedding_attachFin _
@[simp]
theorem map_valEmbedding_uIcc : (uIcc a b).map valEmbedding = uIcc (a : ℕ) b :=
map_valEmbedding_Icc _ _
@[deprecated (since := "2025-04-08")]
alias map_subtype_embedding_uIcc := map_valEmbedding_uIcc
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Ico (a : ℕ) n := by
rw [← attachFin_Ico_eq_Ici, map_valEmbedding_attachFin]
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioo (a : ℕ) n := by
rw [← attachFin_Ioo_eq_Ioi, map_valEmbedding_attachFin]
@[simp]
theorem map_valEmbedding_Iic : (Iic a).map Fin.valEmbedding = Iic (a : ℕ) := by
rw [← attachFin_Iic, map_valEmbedding_attachFin]
@[simp]
theorem map_valEmbedding_Iio : (Iio a).map Fin.valEmbedding = Iio (a : ℕ) := by
rw [← attachFin_Iio, map_valEmbedding_attachFin]
end val
section castLE
/-!
### Image under `Fin.castLE`
-/
@[simp]
theorem finsetImage_castLE_Icc (h : n ≤ m) :
(Icc a b).image (castLE h) = Icc (castLE h a) (castLE h b) := by simp [← coe_inj]
@[simp]
theorem finsetImage_castLE_Ico (h : n ≤ m) :
(Ico a b).image (castLE h) = Ico (castLE h a) (castLE h b) := by simp [← coe_inj]
@[simp]
theorem finsetImage_castLE_Ioc (h : n ≤ m) :
(Ioc a b).image (castLE h) = Ioc (castLE h a) (castLE h b) := by simp [← coe_inj]
@[simp]
theorem finsetImage_castLE_Ioo (h : n ≤ m) :
(Ioo a b).image (castLE h) = Ioo (castLE h a) (castLE h b) := by simp [← coe_inj]
@[simp]
theorem finsetImage_castLE_uIcc (h : n ≤ m) :
(uIcc a b).image (castLE h) = uIcc (castLE h a) (castLE h b) := by simp [← coe_inj]
@[simp]
| Mathlib/Order/Interval/Finset/Fin.lean | 241 | 242 | theorem finsetImage_castLE_Iic (h : n ≤ m) :
(Iic a).image (castLE h) = Iic (castLE h a) := by | simp [← coe_inj] |
/-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.LineDeriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Measurable
/-! # Measurability of the line derivative
We prove in `measurable_lineDeriv` that the line derivative of a function (with respect to a
locally compact scalar field) is measurable, provided the function is continuous.
In `measurable_lineDeriv_uncurry`, assuming additionally that the source space is second countable,
we show that `(x, v) ↦ lineDeriv 𝕜 f x v` is also measurable.
An assumption such as continuity is necessary, as otherwise one could alternate in a non-measurable
way between differentiable and non-differentiable functions along the various lines
directed by `v`.
-/
open MeasureTheory
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [LocallyCompactSpace 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [MeasurableSpace E] [OpensMeasurableSpace E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F]
{f : E → F} {v : E}
/-!
Measurability of the line derivative `lineDeriv 𝕜 f x v` with respect to a fixed direction `v`.
-/
| Mathlib/Analysis/Calculus/LineDeriv/Measurable.lean | 33 | 38 | theorem measurableSet_lineDifferentiableAt (hf : Continuous f) :
MeasurableSet {x : E | LineDifferentiableAt 𝕜 f x v} := by | borelize 𝕜
let g : E → 𝕜 → F := fun x t ↦ f (x + t • v)
have hg : Continuous g.uncurry := by fun_prop
exact measurable_prodMk_right (measurableSet_of_differentiableAt_with_param 𝕜 hg) |
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Topology.UniformSpace.UniformConvergenceTopology
/-!
# Equicontinuity of a family of functions
Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α`
is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a
neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to
`F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`.
For maps between metric spaces, this corresponds to
`∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`.
`F` is said to be *equicontinuous* if it is equicontinuous at each point.
A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions
`F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an
entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and
`F i y` are `U`-close. In other words, one has
`∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`.
For maps between metric spaces, this corresponds to
`∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`.
## Main definitions
* `EquicontinuousAt`: equicontinuity of a family of functions at a point
* `Equicontinuous`: equicontinuity of a family of functions on the whole domain
* `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain
We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and
`UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn`
respectively.
## Main statements
* `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity
condition between well-chosen function spaces. This is really useful for building up the theory.
* `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure
*for the topology of pointwise convergence* is also equicontinuous.
## Notations
Throughout this file, we use :
- `ι`, `κ` for indexing types
- `X`, `Y`, `Z` for topological spaces
- `α`, `β`, `γ` for uniform spaces
## Implementation details
We choose to express equicontinuity as a properties of indexed families of functions rather
than sets of functions for the following reasons:
- it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just
equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around
would require working with the range of the family, which is always annoying because it
introduces useless existentials.
- in most applications, one doesn't work with bare functions but with a more specific hom type
`hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity
of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families,
because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity
of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials.
To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous`
and `Set.UniformEquicontinuous` asserting the corresponding fact about the family
`(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom
types, and in that case one should go back to the family definition rather than using `Set.image`.
## References
* [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966]
## Tags
equicontinuity, uniform convergence, ascoli
-/
section
open UniformSpace Filter Set Uniformity Topology UniformConvergence Function
variable {ι κ X X' Y α α' β β' γ : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y]
[uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ]
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀`
such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/
def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family
`(↑) : ↥H → (X → α)` is equicontinuous at that point. -/
protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop :=
EquicontinuousAt ((↑) : H → X → α) x₀
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a
neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is
`U`-close to `F i x₀`. -/
def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset
if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/
protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop :=
EquicontinuousWithinAt ((↑) : H → X → α) S x₀
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/
def Equicontinuous (F : ι → X → α) : Prop :=
∀ x₀, EquicontinuousAt F x₀
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family
`(↑) : ↥H → (X → α)` is equicontinuous. -/
protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop :=
Equicontinuous ((↑) : H → X → α)
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/
def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop :=
∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family
`(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/
protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop :=
EquicontinuousOn ((↑) : H → X → α) S
/-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if,
for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are
`V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/
def UniformEquicontinuous (F : ι → β → α) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family
`(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/
protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop :=
UniformEquicontinuous ((↑) : H → β → α)
/-- A family `F : ι → β → α` of functions between uniform spaces is
*uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative
entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that,
*for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/
def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the
family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/
protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop :=
UniformEquicontinuousOn ((↑) : H → β → α) S
lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀)
(S : Set X) : EquicontinuousWithinAt F S x₀ :=
fun U hU ↦ (H U hU).filter_mono inf_le_left
lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X}
(H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ :=
fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST
@[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) :
EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by
rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ]
lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) :
EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by
simp [EquicontinuousWithinAt, EquicontinuousAt,
← eventually_nhds_subtype_iff]
lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F)
(S : Set X) : EquicontinuousOn F S :=
fun x _ ↦ (H x).equicontinuousWithinAt S
lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X}
(H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S :=
fun x hx ↦ (H x (hST hx)).mono hST
lemma equicontinuousOn_univ (F : ι → X → α) :
EquicontinuousOn F univ ↔ Equicontinuous F := by
simp [EquicontinuousOn, Equicontinuous]
lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} :
Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by
simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff]
lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F)
(S : Set β) : UniformEquicontinuousOn F S :=
fun U hU ↦ (H U hU).filter_mono inf_le_left
lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β}
(H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S :=
fun U hU ↦ (H U hU).filter_mono <| by gcongr
lemma uniformEquicontinuousOn_univ (F : ι → β → α) :
UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by
simp [UniformEquicontinuousOn, UniformEquicontinuous]
lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} :
UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by
rw [UniformEquicontinuous, UniformEquicontinuousOn]
conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prodMap, ← map_comap]
rfl
/-!
### Empty index type
-/
@[simp]
lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) :
EquicontinuousAt F x₀ :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
@[simp]
lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) :
EquicontinuousWithinAt F S x₀ :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
@[simp]
lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) :
Equicontinuous F :=
equicontinuousAt_empty F
@[simp]
lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) :
EquicontinuousOn F S :=
fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀
@[simp]
lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) :
UniformEquicontinuous F :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
@[simp]
lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) :
UniformEquicontinuousOn F S :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
/-!
### Finite index type
-/
theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by
simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff,
UniformSpace.ball, @forall_swap _ ι]
theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} :
EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by
simp [EquicontinuousWithinAt, ContinuousWithinAt,
(nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball,
@forall_swap _ ι]
theorem equicontinuous_finite [Finite ι] {F : ι → X → α} :
Equicontinuous F ↔ ∀ i, Continuous (F i) := by
simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι]
theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by
simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι]
theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} :
UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by
simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl
theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by
simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl
/-!
### Index type with a unique element
-/
theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} :
EquicontinuousAt F x ↔ ContinuousAt (F default) x :=
equicontinuousAt_finite.trans Unique.forall_iff
theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} :
EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x :=
equicontinuousWithinAt_finite.trans Unique.forall_iff
theorem equicontinuous_unique [Unique ι] {F : ι → X → α} :
Equicontinuous F ↔ Continuous (F default) :=
equicontinuous_finite.trans Unique.forall_iff
theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ ContinuousOn (F default) S :=
equicontinuousOn_finite.trans Unique.forall_iff
theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} :
UniformEquicontinuous F ↔ UniformContinuous (F default) :=
uniformEquicontinuous_finite.trans Unique.forall_iff
theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S :=
uniformEquicontinuousOn_finite.trans Unique.forall_iff
/-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀`
instead of comparing only one with `x₀`. -/
theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) :
EquicontinuousWithinAt F S x₀ ↔
∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by
constructor <;> intro H U hU
· rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩
refine ⟨_, H V hV, fun x hx y hy i => hVU (prodMk_mem_compRel ?_ (hy i))⟩
exact hVsymm.mk_mem_comm.mp (hx i)
· rcases H U hU with ⟨V, hV, hVU⟩
filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i
/-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing
only one with `x₀`. -/
theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔
∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by
simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀),
nhdsWithin_univ]
/-- Uniform equicontinuity implies equicontinuity. -/
theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) :
Equicontinuous F := fun x₀ U hU ↦
mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i
/-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/
theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β}
(h : UniformEquicontinuousOn F S) :
EquicontinuousOn F S := fun _ hx₀ U hU ↦
mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i
/-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/
theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) :
ContinuousAt (F i) x₀ :=
(UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i
/-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/
theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X}
(h : EquicontinuousWithinAt F S x₀) (i : ι) :
ContinuousWithinAt (F i) S x₀ :=
(UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i
protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X}
(h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ :=
h.continuousAt ⟨f, hf⟩
protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α}
{S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) :
ContinuousWithinAt f S x₀ :=
h.continuousWithinAt ⟨f, hf⟩
/-- Each function of an equicontinuous family is continuous. -/
theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) :
Continuous (F i) :=
continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i
/-- Each function of a family equicontinuous on `S` is continuous on `S`. -/
theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S)
(i : ι) : ContinuousOn (F i) S :=
fun x hx ↦ (h x hx).continuousWithinAt i
protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous)
{f : X → α} (hf : f ∈ H) : Continuous f :=
h.continuous ⟨f, hf⟩
protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X}
(h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S :=
h.continuousOn ⟨f, hf⟩
/-- Each function of a uniformly equicontinuous family is uniformly continuous. -/
theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F)
(i : ι) : UniformContinuous (F i) := fun U hU =>
mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i)
/-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/
theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β}
(h : UniformEquicontinuousOn F S) (i : ι) :
UniformContinuousOn (F i) S := fun U hU =>
mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i)
protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α}
(h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f :=
h.uniformContinuous ⟨f, hf⟩
protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α}
{S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) :
UniformContinuousOn f S :=
h.uniformContinuousOn ⟨f, hf⟩
/-- Taking sub-families preserves equicontinuity at a point. -/
theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) :
EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k)
/-- Taking sub-families preserves equicontinuity at a point within a subset. -/
theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X}
(h : EquicontinuousWithinAt F S x₀) (u : κ → ι) :
EquicontinuousWithinAt (F ∘ u) S x₀ :=
fun U hU ↦ (h U hU).mono fun _ H k => H (u k)
protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X}
(h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ :=
h.comp (inclusion hH)
protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X}
(h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ :=
h.comp (inclusion hH)
/-- Taking sub-families preserves equicontinuity. -/
theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) :
Equicontinuous (F ∘ u) := fun x => (h x).comp u
/-- Taking sub-families preserves equicontinuity on a subset. -/
theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) :
EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u
protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous)
(hH : H' ⊆ H) : H'.Equicontinuous :=
h.comp (inclusion hH)
protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X}
(h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S :=
h.comp (inclusion hH)
/-- Taking sub-families preserves uniform equicontinuity. -/
theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) :
UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k)
/-- Taking sub-families preserves uniform equicontinuity on a subset. -/
theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S)
(u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S :=
fun U hU ↦ (h U hU).mono fun _ H k => H (u k)
protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous)
(hH : H' ⊆ H) : H'.UniformEquicontinuous :=
h.comp (inclusion hH)
protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β}
(h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S :=
h.comp (inclusion hH)
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`,
i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/
theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by
simp only [EquicontinuousAt, forall_subtype_range_iff]
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous
at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/
theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} :
EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by
simp only [EquicontinuousWithinAt, forall_subtype_range_iff]
/-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous,
i.e the family `(↑) : range F → X → α` is equicontinuous. -/
theorem equicontinuous_iff_range {F : ι → X → α} :
Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) :=
forall_congr' fun _ => equicontinuousAt_iff_range
/-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`,
i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/
theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S :=
forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous,
i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/
theorem uniformEquicontinuous_iff_range {F : ι → β → α} :
UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) :=
⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h =>
h.comp (rangeFactorization F)⟩
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly
equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/
theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S :=
⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h =>
h.comp (rangeFactorization F)⟩
section
open UniformFun
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is
continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is
very useful for developing the equicontinuity API, but it should not be used directly for other
purposes. -/
theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by
rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff]
rfl
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function
`swap 𝓕 : X → ι → α` is continuous at `x₀` within `S`
*when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for
developing the equicontinuity API, but it should not be used directly for other purposes. -/
theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} :
EquicontinuousWithinAt F S x₀ ↔
ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by
rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff]
rfl
/-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is
continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is
very useful for developing the equicontinuity API, but it should not be used directly for other
purposes. -/
theorem equicontinuous_iff_continuous {F : ι → X → α} :
Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by
simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt]
/-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is
continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is
very useful for developing the equicontinuity API, but it should not be used directly for other
purposes. -/
theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by
simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt]
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is
uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*.
This is very useful for developing the equicontinuity API, but it should not be used directly
for other purposes. -/
theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} :
UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by
rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff]
rfl
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff the function
`swap 𝓕 : β → ι → α` is uniformly continuous on `S`
*when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful
for developing the equicontinuity API, but it should not be used directly for other purposes. -/
theorem uniformEquicontinuousOn_iff_uniformContinuousOn {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ UniformContinuousOn (ofFun ∘ Function.swap F : β → ι →ᵤ α) S := by
rw [UniformContinuousOn, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff]
rfl
theorem equicontinuousWithinAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'}
{S : Set X} {x₀ : X} : EquicontinuousWithinAt (uα := ⨅ k, u k) F S x₀ ↔
∀ k, EquicontinuousWithinAt (uα := u k) F S x₀ := by
simp only [equicontinuousWithinAt_iff_continuousWithinAt (uα := _), topologicalSpace]
unfold ContinuousWithinAt
rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, nhds_iInf, tendsto_iInf]
theorem equicontinuousAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'}
{x₀ : X} :
EquicontinuousAt (uα := ⨅ k, u k) F x₀ ↔ ∀ k, EquicontinuousAt (uα := u k) F x₀ := by
simp only [← equicontinuousWithinAt_univ (uα := _), equicontinuousWithinAt_iInf_rng]
theorem equicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} :
Equicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, Equicontinuous (uα := u k) F := by
simp_rw [equicontinuous_iff_continuous (uα := _), UniformFun.topologicalSpace]
rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, continuous_iInf_rng]
theorem equicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'}
{S : Set X} :
EquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, EquicontinuousOn (uα := u k) F S := by
simp_rw [EquicontinuousOn, equicontinuousWithinAt_iInf_rng, @forall_swap _ κ]
theorem uniformEquicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} :
UniformEquicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, UniformEquicontinuous (uα := u k) F := by
simp_rw [uniformEquicontinuous_iff_uniformContinuous (uα := _)]
rw [UniformFun.iInf_eq, uniformContinuous_iInf_rng]
theorem uniformEquicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'}
{S : Set β} : UniformEquicontinuousOn (uα := ⨅ k, u k) F S ↔
∀ k, UniformEquicontinuousOn (uα := u k) F S := by
simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uα := _)]
unfold UniformContinuousOn
rw [UniformFun.iInf_eq, iInf_uniformity, tendsto_iInf]
theorem equicontinuousWithinAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α}
{S : Set X'} {x₀ : X'} {k : κ} (hk : EquicontinuousWithinAt (tX := t k) F S x₀) :
EquicontinuousWithinAt (tX := ⨅ k, t k) F S x₀ := by
simp only [equicontinuousWithinAt_iff_continuousWithinAt (tX := _)] at hk ⊢
unfold ContinuousWithinAt nhdsWithin at hk ⊢
rw [nhds_iInf]
exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k
theorem equicontinuousAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α}
{x₀ : X'} {k : κ} (hk : EquicontinuousAt (tX := t k) F x₀) :
EquicontinuousAt (tX := ⨅ k, t k) F x₀ := by
rw [← equicontinuousWithinAt_univ (tX := _)] at hk ⊢
exact equicontinuousWithinAt_iInf_dom hk
theorem equicontinuous_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α}
{k : κ} (hk : Equicontinuous (tX := t k) F) :
Equicontinuous (tX := ⨅ k, t k) F :=
fun x ↦ equicontinuousAt_iInf_dom (hk x)
theorem equicontinuousOn_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α}
{S : Set X'} {k : κ} (hk : EquicontinuousOn (tX := t k) F S) :
EquicontinuousOn (tX := ⨅ k, t k) F S :=
fun x hx ↦ equicontinuousWithinAt_iInf_dom (hk x hx)
theorem uniformEquicontinuous_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α}
{k : κ} (hk : UniformEquicontinuous (uβ := u k) F) :
UniformEquicontinuous (uβ := ⨅ k, u k) F := by
simp_rw [uniformEquicontinuous_iff_uniformContinuous (uβ := _)] at hk ⊢
exact uniformContinuous_iInf_dom hk
theorem uniformEquicontinuousOn_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α}
{S : Set β'} {k : κ} (hk : UniformEquicontinuousOn (uβ := u k) F S) :
UniformEquicontinuousOn (uβ := ⨅ k, u k) F S := by
simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uβ := _)] at hk ⊢
unfold UniformContinuousOn
rw [iInf_uniformity]
exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k
theorem Filter.HasBasis.equicontinuousAt_iff_left {p : κ → Prop} {s : κ → Set X}
{F : ι → X → α} {x₀ : X} (hX : (𝓝 x₀).HasBasis p s) :
EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x ∈ s k, ∀ i, (F i x₀, F i x) ∈ U := by
rw [equicontinuousAt_iff_continuousAt, ContinuousAt,
hX.tendsto_iff (UniformFun.hasBasis_nhds ι α _)]
rfl
theorem Filter.HasBasis.equicontinuousWithinAt_iff_left {p : κ → Prop} {s : κ → Set X}
{F : ι → X → α} {S : Set X} {x₀ : X} (hX : (𝓝[S] x₀).HasBasis p s) :
EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x ∈ s k, ∀ i, (F i x₀, F i x) ∈ U := by
rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt,
hX.tendsto_iff (UniformFun.hasBasis_nhds ι α _)]
rfl
theorem Filter.HasBasis.equicontinuousAt_iff_right {p : κ → Prop} {s : κ → Set (α × α)}
{F : ι → X → α} {x₀ : X} (hα : (𝓤 α).HasBasis p s) :
EquicontinuousAt F x₀ ↔ ∀ k, p k → ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ s k := by
rw [equicontinuousAt_iff_continuousAt, ContinuousAt,
(UniformFun.hasBasis_nhds_of_basis ι α _ hα).tendsto_right_iff]
rfl
theorem Filter.HasBasis.equicontinuousWithinAt_iff_right {p : κ → Prop}
{s : κ → Set (α × α)} {F : ι → X → α} {S : Set X} {x₀ : X} (hα : (𝓤 α).HasBasis p s) :
EquicontinuousWithinAt F S x₀ ↔ ∀ k, p k → ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ s k := by
rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt,
(UniformFun.hasBasis_nhds_of_basis ι α _ hα).tendsto_right_iff]
rfl
| Mathlib/Topology/UniformSpace/Equicontinuity.lean | 633 | 638 | theorem Filter.HasBasis.equicontinuousAt_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set X}
{p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → X → α} {x₀ : X} (hX : (𝓝 x₀).HasBasis p₁ s₁)
(hα : (𝓤 α).HasBasis p₂ s₂) :
EquicontinuousAt F x₀ ↔
∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x ∈ s₁ k₁, ∀ i, (F i x₀, F i x) ∈ s₂ k₂ := by | rw [equicontinuousAt_iff_continuousAt, ContinuousAt, |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Topology.Order.IsLUB
/-!
# Order topology on a densely ordered set
-/
open Set Filter TopologicalSpace Topology Function
open OrderDual (toDual ofDual)
variable {α β : Type*}
section DenselyOrdered
variable [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [DenselyOrdered α] {a b : α}
{s : Set α}
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top
element. -/
theorem closure_Ioi' {a : α} (h : (Ioi a).Nonempty) : closure (Ioi a) = Ici a := by
apply Subset.antisymm
· exact closure_minimal Ioi_subset_Ici_self isClosed_Ici
· rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff]
exact isGLB_Ioi.mem_closure h
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/
@[simp]
theorem closure_Ioi (a : α) [NoMaxOrder α] : closure (Ioi a) = Ici a :=
closure_Ioi' nonempty_Ioi
/-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom
element. -/
theorem closure_Iio' (h : (Iio a).Nonempty) : closure (Iio a) = Iic a :=
closure_Ioi' (α := αᵒᵈ) h
/-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/
@[simp]
theorem closure_Iio (a : α) [NoMinOrder α] : closure (Iio a) = Iic a :=
closure_Iio' nonempty_Iio
/-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ioo {a b : α} (hab : a ≠ b) : closure (Ioo a b) = Icc a b := by
apply Subset.antisymm
· exact closure_minimal Ioo_subset_Icc_self isClosed_Icc
· rcases hab.lt_or_lt with hab | hab
· rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le]
have hab' : (Ioo a b).Nonempty := nonempty_Ioo.2 hab
simp only [insert_subset_iff, singleton_subset_iff]
exact ⟨(isGLB_Ioo hab).mem_closure hab', (isLUB_Ioo hab).mem_closure hab'⟩
· rw [Icc_eq_empty_of_lt hab]
exact empty_subset _
/-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ioc {a b : α} (hab : a ≠ b) : closure (Ioc a b) = Icc a b := by
apply Subset.antisymm
· exact closure_minimal Ioc_subset_Icc_self isClosed_Icc
· apply Subset.trans _ (closure_mono Ioo_subset_Ioc_self)
rw [closure_Ioo hab]
/-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ico {a b : α} (hab : a ≠ b) : closure (Ico a b) = Icc a b := by
apply Subset.antisymm
· exact closure_minimal Ico_subset_Icc_self isClosed_Icc
· apply Subset.trans _ (closure_mono Ioo_subset_Ico_self)
rw [closure_Ioo hab]
@[simp]
theorem interior_Ici' {a : α} (ha : (Iio a).Nonempty) : interior (Ici a) = Ioi a := by
rw [← compl_Iio, interior_compl, closure_Iio' ha, compl_Iic]
theorem interior_Ici [NoMinOrder α] {a : α} : interior (Ici a) = Ioi a :=
interior_Ici' nonempty_Iio
@[simp]
theorem interior_Iic' {a : α} (ha : (Ioi a).Nonempty) : interior (Iic a) = Iio a :=
interior_Ici' (α := αᵒᵈ) ha
theorem interior_Iic [NoMaxOrder α] {a : α} : interior (Iic a) = Iio a :=
interior_Iic' nonempty_Ioi
@[simp]
theorem interior_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} : interior (Icc a b) = Ioo a b := by
rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio]
@[simp]
theorem Icc_mem_nhds_iff [NoMinOrder α] [NoMaxOrder α] {a b x : α} :
Icc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by
rw [← interior_Icc, mem_interior_iff_mem_nhds]
@[simp]
theorem interior_Ico [NoMinOrder α] {a b : α} : interior (Ico a b) = Ioo a b := by
rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio]
@[simp]
theorem Ico_mem_nhds_iff [NoMinOrder α] {a b x : α} : Ico a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by
rw [← interior_Ico, mem_interior_iff_mem_nhds]
@[simp]
theorem interior_Ioc [NoMaxOrder α] {a b : α} : interior (Ioc a b) = Ioo a b := by
rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio]
@[simp]
theorem Ioc_mem_nhds_iff [NoMaxOrder α] {a b x : α} : Ioc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by
rw [← interior_Ioc, mem_interior_iff_mem_nhds]
theorem closure_interior_Icc {a b : α} (h : a ≠ b) : closure (interior (Icc a b)) = Icc a b :=
(closure_minimal interior_subset isClosed_Icc).antisymm <|
calc
Icc a b = closure (Ioo a b) := (closure_Ioo h).symm
_ ⊆ closure (interior (Icc a b)) :=
closure_mono (interior_maximal Ioo_subset_Icc_self isOpen_Ioo)
theorem Ioc_subset_closure_interior (a b : α) : Ioc a b ⊆ closure (interior (Ioc a b)) := by
rcases eq_or_ne a b with (rfl | h)
· simp
· calc
Ioc a b ⊆ Icc a b := Ioc_subset_Icc_self
_ = closure (Ioo a b) := (closure_Ioo h).symm
_ ⊆ closure (interior (Ioc a b)) :=
closure_mono (interior_maximal Ioo_subset_Ioc_self isOpen_Ioo)
theorem Ico_subset_closure_interior (a b : α) : Ico a b ⊆ closure (interior (Ico a b)) := by
simpa only [Ioc_toDual] using
Ioc_subset_closure_interior (OrderDual.toDual b) (OrderDual.toDual a)
@[simp]
theorem frontier_Ici' {a : α} (ha : (Iio a).Nonempty) : frontier (Ici a) = {a} := by
simp [frontier, ha]
theorem frontier_Ici [NoMinOrder α] {a : α} : frontier (Ici a) = {a} :=
frontier_Ici' nonempty_Iio
@[simp]
theorem frontier_Iic' {a : α} (ha : (Ioi a).Nonempty) : frontier (Iic a) = {a} := by
simp [frontier, ha]
theorem frontier_Iic [NoMaxOrder α] {a : α} : frontier (Iic a) = {a} :=
frontier_Iic' nonempty_Ioi
@[simp]
theorem frontier_Ioi' {a : α} (ha : (Ioi a).Nonempty) : frontier (Ioi a) = {a} := by
simp [frontier, closure_Ioi' ha, Iic_diff_Iio, Icc_self]
theorem frontier_Ioi [NoMaxOrder α] {a : α} : frontier (Ioi a) = {a} :=
frontier_Ioi' nonempty_Ioi
@[simp]
theorem frontier_Iio' {a : α} (ha : (Iio a).Nonempty) : frontier (Iio a) = {a} := by
simp [frontier, closure_Iio' ha, Iic_diff_Iio, Icc_self]
theorem frontier_Iio [NoMinOrder α] {a : α} : frontier (Iio a) = {a} :=
frontier_Iio' nonempty_Iio
@[simp]
theorem frontier_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} (h : a ≤ b) :
frontier (Icc a b) = {a, b} := by simp [frontier, h, Icc_diff_Ioo_same]
@[simp]
theorem frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} := by
rw [frontier, closure_Ioo h.ne, interior_Ioo, Icc_diff_Ioo_same h.le]
@[simp]
theorem frontier_Ico [NoMinOrder α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} := by
rw [frontier, closure_Ico h.ne, interior_Ico, Icc_diff_Ioo_same h.le]
@[simp]
theorem frontier_Ioc [NoMaxOrder α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} := by
rw [frontier, closure_Ioc h.ne, interior_Ioc, Icc_diff_Ioo_same h.le]
theorem nhdsWithin_Ioi_neBot' {a b : α} (H₁ : (Ioi a).Nonempty) (H₂ : a ≤ b) :
NeBot (𝓝[Ioi a] b) :=
mem_closure_iff_nhdsWithin_neBot.1 <| by rwa [closure_Ioi' H₁]
theorem nhdsWithin_Ioi_neBot [NoMaxOrder α] {a b : α} (H : a ≤ b) : NeBot (𝓝[Ioi a] b) :=
nhdsWithin_Ioi_neBot' nonempty_Ioi H
theorem nhdsGT_neBot_of_exists_gt {a : α} (H : ∃ b, a < b) : NeBot (𝓝[>] a) :=
nhdsWithin_Ioi_neBot' H (le_refl a)
@[deprecated (since := "2024-12-22")]
alias nhdsWithin_Ioi_self_neBot' := nhdsGT_neBot_of_exists_gt
instance nhdsGT_neBot [NoMaxOrder α] (a : α) : NeBot (𝓝[>] a) := nhdsWithin_Ioi_neBot le_rfl
@[deprecated nhdsGT_neBot (since := "2024-12-22")]
theorem nhdsWithin_Ioi_self_neBot [NoMaxOrder α] (a : α) : NeBot (𝓝[>] a) := nhdsGT_neBot a
theorem nhdsWithin_Iio_neBot' {b c : α} (H₁ : (Iio c).Nonempty) (H₂ : b ≤ c) :
NeBot (𝓝[Iio c] b) :=
mem_closure_iff_nhdsWithin_neBot.1 <| by rwa [closure_Iio' H₁]
theorem nhdsWithin_Iio_neBot [NoMinOrder α] {a b : α} (H : a ≤ b) : NeBot (𝓝[Iio b] a) :=
nhdsWithin_Iio_neBot' nonempty_Iio H
theorem nhdsWithin_Iio_self_neBot' {b : α} (H : (Iio b).Nonempty) : NeBot (𝓝[<] b) :=
nhdsWithin_Iio_neBot' H (le_refl b)
instance nhdsLT_neBot [NoMinOrder α] (a : α) : NeBot (𝓝[<] a) := nhdsWithin_Iio_neBot (le_refl a)
@[deprecated nhdsLT_neBot (since := "2024-12-22")]
theorem nhdsWithin_Iio_self_neBot [NoMinOrder α] (a : α) : NeBot (𝓝[<] a) := nhdsLT_neBot a
theorem right_nhdsWithin_Ico_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ico a b] b) :=
(isLUB_Ico H).nhdsWithin_neBot (nonempty_Ico.2 H)
theorem left_nhdsWithin_Ioc_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioc a b] a) :=
(isGLB_Ioc H).nhdsWithin_neBot (nonempty_Ioc.2 H)
theorem left_nhdsWithin_Ioo_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioo a b] a) :=
(isGLB_Ioo H).nhdsWithin_neBot (nonempty_Ioo.2 H)
theorem right_nhdsWithin_Ioo_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioo a b] b) :=
(isLUB_Ioo H).nhdsWithin_neBot (nonempty_Ioo.2 H)
theorem comap_coe_nhdsLT_of_Ioo_subset (hb : s ⊆ Iio b) (hs : s.Nonempty → ∃ a < b, Ioo a b ⊆ s) :
comap ((↑) : s → α) (𝓝[<] b) = atTop := by
nontriviality
haveI : Nonempty s := nontrivial_iff_nonempty.1 ‹_›
rcases hs (nonempty_subtype.1 ‹_›) with ⟨a, h, hs⟩
ext u; constructor
· rintro ⟨t, ht, hts⟩
obtain ⟨x, ⟨hxa : a ≤ x, hxb : x < b⟩, hxt : Ioo x b ⊆ t⟩ :=
(mem_nhdsLT_iff_exists_mem_Ico_Ioo_subset h).mp ht
obtain ⟨y, hxy, hyb⟩ := exists_between hxb
refine mem_of_superset (mem_atTop ⟨y, hs ⟨hxa.trans_lt hxy, hyb⟩⟩) ?_
rintro ⟨z, hzs⟩ (hyz : y ≤ z)
exact hts (hxt ⟨hxy.trans_le hyz, hb hzs⟩)
· intro hu
obtain ⟨x : s, hx : ∀ z, x ≤ z → z ∈ u⟩ := mem_atTop_sets.1 hu
exact ⟨Ioo x b, Ioo_mem_nhdsLT (hb x.2), fun z hz => hx _ hz.1.le⟩
@[deprecated (since := "2024-12-22")]
alias comap_coe_nhdsWithin_Iio_of_Ioo_subset := comap_coe_nhdsLT_of_Ioo_subset
theorem comap_coe_nhdsGT_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : s.Nonempty → ∃ b > a, Ioo a b ⊆ s) :
comap ((↑) : s → α) (𝓝[>] a) = atBot := by
apply comap_coe_nhdsLT_of_Ioo_subset (show ofDual ⁻¹' s ⊆ Iio (toDual a) from ha)
simp only [OrderDual.exists, Ioo_toDual]
exact hs
@[deprecated (since := "2024-12-22")]
alias comap_coe_nhdsWithin_Ioi_of_Ioo_subset := comap_coe_nhdsGT_of_Ioo_subset
theorem map_coe_atTop_of_Ioo_subset (hb : s ⊆ Iio b) (hs : ∀ a' < b, ∃ a < b, Ioo a b ⊆ s) :
map ((↑) : s → α) atTop = 𝓝[<] b := by
rcases eq_empty_or_nonempty (Iio b) with (hb' | ⟨a, ha⟩)
· have : IsEmpty s := ⟨fun x => hb'.subset (hb x.2)⟩
rw [filter_eq_bot_of_isEmpty atTop, Filter.map_bot, hb', nhdsWithin_empty]
· rw [← comap_coe_nhdsLT_of_Ioo_subset hb fun _ => hs a ha, map_comap_of_mem]
rw [Subtype.range_val]
exact (mem_nhdsLT_iff_exists_Ioo_subset' ha).2 (hs a ha)
theorem map_coe_atBot_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : ∀ b' > a, ∃ b > a, Ioo a b ⊆ s) :
map ((↑) : s → α) atBot = 𝓝[>] a := by
-- the elaborator gets stuck without `(... :)`
refine (map_coe_atTop_of_Ioo_subset (show ofDual ⁻¹' s ⊆ Iio (toDual a) from ha)
fun b' hb' => ?_ :)
simpa using hs b' hb'
/-- The `atTop` filter for an open interval `Ioo a b` comes from the left-neighbourhoods filter at
the right endpoint in the ambient order. -/
theorem comap_coe_Ioo_nhdsLT (a b : α) : comap ((↑) : Ioo a b → α) (𝓝[<] b) = atTop :=
comap_coe_nhdsLT_of_Ioo_subset Ioo_subset_Iio_self fun h => ⟨a, nonempty_Ioo.1 h, Subset.refl _⟩
@[deprecated (since := "2024-12-22")]
alias comap_coe_Ioo_nhdsWithin_Iio := comap_coe_Ioo_nhdsLT
/-- The `atBot` filter for an open interval `Ioo a b` comes from the right-neighbourhoods filter at
the left endpoint in the ambient order. -/
theorem comap_coe_Ioo_nhdsGT (a b : α) : comap ((↑) : Ioo a b → α) (𝓝[>] a) = atBot :=
comap_coe_nhdsGT_of_Ioo_subset Ioo_subset_Ioi_self fun h => ⟨b, nonempty_Ioo.1 h, Subset.refl _⟩
@[deprecated (since := "2024-12-22")]
alias comap_coe_Ioo_nhdsWithin_Ioi := comap_coe_Ioo_nhdsGT
theorem comap_coe_Ioi_nhdsGT (a : α) : comap ((↑) : Ioi a → α) (𝓝[>] a) = atBot :=
comap_coe_nhdsGT_of_Ioo_subset (Subset.refl _) fun ⟨x, hx⟩ => ⟨x, hx, Ioo_subset_Ioi_self⟩
@[deprecated (since := "2024-12-22")]
alias comap_coe_Ioi_nhdsWithin_Ioi := comap_coe_Ioi_nhdsGT
theorem comap_coe_Iio_nhdsLT (a : α) : comap ((↑) : Iio a → α) (𝓝[<] a) = atTop :=
comap_coe_Ioi_nhdsGT (α := αᵒᵈ) a
@[deprecated (since := "2024-12-22")]
alias comap_coe_Iio_nhdsWithin_Iio := comap_coe_Iio_nhdsLT
@[simp]
theorem map_coe_Ioo_atTop {a b : α} (h : a < b) : map ((↑) : Ioo a b → α) atTop = 𝓝[<] b :=
map_coe_atTop_of_Ioo_subset Ioo_subset_Iio_self fun _ _ => ⟨_, h, Subset.refl _⟩
@[simp]
theorem map_coe_Ioo_atBot {a b : α} (h : a < b) : map ((↑) : Ioo a b → α) atBot = 𝓝[>] a :=
map_coe_atBot_of_Ioo_subset Ioo_subset_Ioi_self fun _ _ => ⟨_, h, Subset.refl _⟩
@[simp]
theorem map_coe_Ioi_atBot (a : α) : map ((↑) : Ioi a → α) atBot = 𝓝[>] a :=
map_coe_atBot_of_Ioo_subset (Subset.refl _) fun b hb => ⟨b, hb, Ioo_subset_Ioi_self⟩
@[simp]
theorem map_coe_Iio_atTop (a : α) : map ((↑) : Iio a → α) atTop = 𝓝[<] a :=
map_coe_Ioi_atBot (α := αᵒᵈ) _
variable {l : Filter β} {f : α → β}
@[simp]
theorem tendsto_comp_coe_Ioo_atTop (h : a < b) :
Tendsto (fun x : Ioo a b => f x) atTop l ↔ Tendsto f (𝓝[<] b) l := by
rw [← map_coe_Ioo_atTop h, tendsto_map'_iff]; rfl
@[simp]
theorem tendsto_comp_coe_Ioo_atBot (h : a < b) :
Tendsto (fun x : Ioo a b => f x) atBot l ↔ Tendsto f (𝓝[>] a) l := by
rw [← map_coe_Ioo_atBot h, tendsto_map'_iff]; rfl
@[simp]
theorem tendsto_comp_coe_Ioi_atBot :
Tendsto (fun x : Ioi a => f x) atBot l ↔ Tendsto f (𝓝[>] a) l := by
rw [← map_coe_Ioi_atBot, tendsto_map'_iff]; rfl
@[simp]
theorem tendsto_comp_coe_Iio_atTop :
Tendsto (fun x : Iio a => f x) atTop l ↔ Tendsto f (𝓝[<] a) l := by
rw [← map_coe_Iio_atTop, tendsto_map'_iff]; rfl
@[simp]
theorem tendsto_Ioo_atTop {f : β → Ioo a b} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l (𝓝[<] b) := by
rw [← comap_coe_Ioo_nhdsLT, tendsto_comap_iff]; rfl
@[simp]
theorem tendsto_Ioo_atBot {f : β → Ioo a b} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l (𝓝[>] a) := by
rw [← comap_coe_Ioo_nhdsGT, tendsto_comap_iff]; rfl
@[simp]
theorem tendsto_Ioi_atBot {f : β → Ioi a} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l (𝓝[>] a) := by
rw [← comap_coe_Ioi_nhdsGT, tendsto_comap_iff]; rfl
@[simp]
| Mathlib/Topology/Order/DenselyOrdered.lean | 350 | 352 | theorem tendsto_Iio_atTop {f : β → Iio a} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l (𝓝[<] a) := by | rw [← comap_coe_Iio_nhdsLT, tendsto_comap_iff]; rfl |
/-
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
-/
import Mathlib.Data.Set.Prod
/-!
# N-ary images of sets
This file defines `Set.image2`, the binary image of sets.
This is mostly useful to define pointwise operations and `Set.seq`.
## Notes
This file is very similar to `Data.Finset.NAry`, to `Order.Filter.NAry`, and to
`Data.Option.NAry`. Please keep them in sync.
-/
open Function
namespace Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} {f f' : α → β → γ}
variable {s s' : Set α} {t t' : Set β} {u : Set γ} {v : Set δ} {a : α} {b : β}
theorem mem_image2_iff (hf : Injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t :=
⟨by
rintro ⟨a', ha', b', hb', h⟩
rcases hf h with ⟨rfl, rfl⟩
exact ⟨ha', hb'⟩, fun ⟨ha, hb⟩ => mem_image2_of_mem ha hb⟩
/-- image2 is monotone with respect to `⊆`. -/
@[gcongr]
theorem image2_subset (hs : s ⊆ s') (ht : t ⊆ t') : image2 f s t ⊆ image2 f s' t' := by
rintro _ ⟨a, ha, b, hb, rfl⟩
exact mem_image2_of_mem (hs ha) (ht hb)
@[gcongr]
theorem image2_subset_left (ht : t ⊆ t') : image2 f s t ⊆ image2 f s t' :=
image2_subset Subset.rfl ht
@[gcongr]
theorem image2_subset_right (hs : s ⊆ s') : image2 f s t ⊆ image2 f s' t :=
image2_subset hs Subset.rfl
theorem image_subset_image2_left (hb : b ∈ t) : (fun a => f a b) '' s ⊆ image2 f s t :=
forall_mem_image.2 fun _ ha => mem_image2_of_mem ha hb
theorem image_subset_image2_right (ha : a ∈ s) : f a '' t ⊆ image2 f s t :=
forall_mem_image.2 fun _ => mem_image2_of_mem ha
lemma forall_mem_image2 {p : γ → Prop} :
(∀ z ∈ image2 f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by aesop
lemma exists_mem_image2 {p : γ → Prop} :
(∃ z ∈ image2 f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by aesop
@[deprecated (since := "2024-11-23")] alias forall_image2_iff := forall_mem_image2
@[simp]
theorem image2_subset_iff {u : Set γ} : image2 f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u :=
forall_mem_image2
theorem image2_subset_iff_left : image2 f s t ⊆ u ↔ ∀ a ∈ s, (fun b => f a b) '' t ⊆ u := by
simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage]
theorem image2_subset_iff_right : image2 f s t ⊆ u ↔ ∀ b ∈ t, (fun a => f a b) '' s ⊆ u := by
simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage, @forall₂_swap α]
variable (f)
@[simp]
lemma image_prod : (fun x : α × β ↦ f x.1 x.2) '' s ×ˢ t = image2 f s t :=
ext fun _ ↦ by simp [and_assoc]
@[simp] lemma image_uncurry_prod (s : Set α) (t : Set β) : uncurry f '' s ×ˢ t = image2 f s t :=
image_prod _
@[simp] lemma image2_mk_eq_prod : image2 Prod.mk s t = s ×ˢ t := ext <| by simp
@[simp]
lemma image2_curry (f : α × β → γ) (s : Set α) (t : Set β) :
image2 (fun a b ↦ f (a, b)) s t = f '' s ×ˢ t := by
simp [← image_uncurry_prod, uncurry]
theorem image2_swap (s : Set α) (t : Set β) : image2 f s t = image2 (fun a b => f b a) t s := by
ext
constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨b, hb, a, ha, rfl⟩
variable {f}
theorem image2_union_left : image2 f (s ∪ s') t = image2 f s t ∪ image2 f s' t := by
simp_rw [← image_prod, union_prod, image_union]
theorem image2_union_right : image2 f s (t ∪ t') = image2 f s t ∪ image2 f s t' := by
rw [← image2_swap, image2_union_left, image2_swap f, image2_swap f]
lemma image2_inter_left (hf : Injective2 f) :
image2 f (s ∩ s') t = image2 f s t ∩ image2 f s' t := by
simp_rw [← image_uncurry_prod, inter_prod, image_inter hf.uncurry]
lemma image2_inter_right (hf : Injective2 f) :
image2 f s (t ∩ t') = image2 f s t ∩ image2 f s t' := by
simp_rw [← image_uncurry_prod, prod_inter, image_inter hf.uncurry]
@[simp]
theorem image2_empty_left : image2 f ∅ t = ∅ :=
ext <| by simp
@[simp]
theorem image2_empty_right : image2 f s ∅ = ∅ :=
ext <| by simp
theorem Nonempty.image2 : s.Nonempty → t.Nonempty → (image2 f s t).Nonempty :=
fun ⟨_, ha⟩ ⟨_, hb⟩ => ⟨_, mem_image2_of_mem ha hb⟩
@[simp]
theorem image2_nonempty_iff : (image2 f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
⟨fun ⟨_, a, ha, b, hb, _⟩ => ⟨⟨a, ha⟩, b, hb⟩, fun h => h.1.image2 h.2⟩
theorem Nonempty.of_image2_left (h : (Set.image2 f s t).Nonempty) : s.Nonempty :=
(image2_nonempty_iff.1 h).1
theorem Nonempty.of_image2_right (h : (Set.image2 f s t).Nonempty) : t.Nonempty :=
(image2_nonempty_iff.1 h).2
@[simp]
theorem image2_eq_empty_iff : image2 f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
rw [← not_nonempty_iff_eq_empty, image2_nonempty_iff, not_and_or]
simp [not_nonempty_iff_eq_empty]
theorem Subsingleton.image2 (hs : s.Subsingleton) (ht : t.Subsingleton) (f : α → β → γ) :
(image2 f s t).Subsingleton := by
rw [← image_prod]
apply (hs.prod ht).image
theorem image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t :=
Monotone.map_inf_le (fun _ _ ↦ image2_subset_right) s s'
theorem image2_inter_subset_right : image2 f s (t ∩ t') ⊆ image2 f s t ∩ image2 f s t' :=
Monotone.map_inf_le (fun _ _ ↦ image2_subset_left) t t'
@[simp]
theorem image2_singleton_left : image2 f {a} t = f a '' t :=
ext fun x => by simp
@[simp]
theorem image2_singleton_right : image2 f s {b} = (fun a => f a b) '' s :=
ext fun x => by simp
theorem image2_singleton : image2 f {a} {b} = {f a b} := by simp
@[simp]
theorem image2_insert_left : image2 f (insert a s) t = (fun b => f a b) '' t ∪ image2 f s t := by
rw [insert_eq, image2_union_left, image2_singleton_left]
@[simp]
theorem image2_insert_right : image2 f s (insert b t) = (fun a => f a b) '' s ∪ image2 f s t := by
rw [insert_eq, image2_union_right, image2_singleton_right]
@[congr]
theorem image2_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image2 f s t = image2 f' s t := by
ext
constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨a, ha, b, hb, by rw [h a ha b hb]⟩
/-- A common special case of `image2_congr` -/
theorem image2_congr' (h : ∀ a b, f a b = f' a b) : image2 f s t = image2 f' s t :=
image2_congr fun a _ b _ => h a b
theorem image_image2 (f : α → β → γ) (g : γ → δ) :
g '' image2 f s t = image2 (fun a b => g (f a b)) s t := by
simp only [← image_prod, image_image]
theorem image2_image_left (f : γ → β → δ) (g : α → γ) :
image2 f (g '' s) t = image2 (fun a b => f (g a) b) s t := by
ext; simp
theorem image2_image_right (f : α → γ → δ) (g : β → γ) :
image2 f s (g '' t) = image2 (fun a b => f a (g b)) s t := by
ext; simp
@[simp]
theorem image2_left (h : t.Nonempty) : image2 (fun x _ => x) s t = s := by
simp [nonempty_def.mp h, Set.ext_iff]
@[simp]
theorem image2_right (h : s.Nonempty) : image2 (fun _ y => y) s t = t := by
simp [nonempty_def.mp h, Set.ext_iff]
lemma image2_range (f : α' → β' → γ) (g : α → α') (h : β → β') :
image2 f (range g) (range h) = range fun x : α × β ↦ f (g x.1) (h x.2) := by
simp_rw [← image_univ, image2_image_left, image2_image_right, ← image_prod, univ_prod_univ]
theorem image2_assoc {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'}
(h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
image2 f (image2 g s t) u = image2 f' s (image2 g' t u) :=
eq_of_forall_subset_iff fun _ ↦ by simp only [image2_subset_iff, forall_mem_image2, h_assoc]
theorem image2_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image2 f s t = image2 g t s :=
(image2_swap _ _ _).trans <| by simp_rw [h_comm]
theorem image2_left_comm {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε}
(h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
image2 f s (image2 g t u) = image2 g' t (image2 f' s u) := by
rw [image2_swap f', image2_swap f]
exact image2_assoc fun _ _ _ => h_left_comm _ _ _
theorem image2_right_comm {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε}
(h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
image2 f (image2 g s t) u = image2 g' (image2 f' s u) t := by
rw [image2_swap g, image2_swap g']
exact image2_assoc fun _ _ _ => h_right_comm _ _ _
theorem image2_image2_image2_comm {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ} {f' : ε' → ζ' → ν}
{g' : α → γ → ε'} {h' : β → δ → ζ'}
(h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) :
image2 f (image2 g s t) (image2 h u v) = image2 f' (image2 g' s u) (image2 h' t v) := by
ext; constructor
· rintro ⟨_, ⟨a, ha, b, hb, rfl⟩, _, ⟨c, hc, d, hd, rfl⟩, rfl⟩
exact ⟨_, ⟨a, ha, c, hc, rfl⟩, _, ⟨b, hb, d, hd, rfl⟩, (h_comm _ _ _ _).symm⟩
· rintro ⟨_, ⟨a, ha, c, hc, rfl⟩, _, ⟨b, hb, d, hd, rfl⟩, rfl⟩
exact ⟨_, ⟨a, ha, b, hb, rfl⟩, _, ⟨c, hc, d, hd, rfl⟩, h_comm _ _ _ _⟩
theorem image_image2_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
(image2 f s t).image g = image2 f' (s.image g₁) (t.image g₂) := by
simp_rw [image_image2, image2_image_left, image2_image_right, h_distrib]
/-- Symmetric statement to `Set.image2_image_left_comm`. -/
theorem image_image2_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
(image2 f s t).image g = image2 f' (s.image g') t :=
(image_image2_distrib h_distrib).trans <| by rw [image_id']
/-- Symmetric statement to `Set.image_image2_right_comm`. -/
theorem image_image2_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' a (g' b)) :
(image2 f s t).image g = image2 f' s (t.image g') :=
(image_image2_distrib h_distrib).trans <| by rw [image_id']
/-- Symmetric statement to `Set.image_image2_distrib_left`. -/
theorem image2_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ}
(h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) :
image2 f (s.image g) t = (image2 f' s t).image g' :=
(image_image2_distrib_left fun a b => (h_left_comm a b).symm).symm
/-- Symmetric statement to `Set.image_image2_distrib_right`. -/
theorem image_image2_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ}
(h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) :
image2 f s (t.image g) = (image2 f' s t).image g' :=
(image_image2_distrib_right fun a b => (h_right_comm a b).symm).symm
/-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/
theorem image2_distrib_subset_left {f : α → δ → ε} {g : β → γ → δ} {f₁ : α → β → β'}
{f₂ : α → γ → γ'} {g' : β' → γ' → ε} (h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) :
image2 f s (image2 g t u) ⊆ image2 g' (image2 f₁ s t) (image2 f₂ s u) := by
rintro _ ⟨a, ha, _, ⟨b, hb, c, hc, rfl⟩, rfl⟩
rw [h_distrib]
exact mem_image2_of_mem (mem_image2_of_mem ha hb) (mem_image2_of_mem ha hc)
/-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
theorem image2_distrib_subset_right {f : δ → γ → ε} {g : α → β → δ} {f₁ : α → γ → α'}
{f₂ : β → γ → β'} {g' : α' → β' → ε} (h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) :
image2 f (image2 g s t) u ⊆ image2 g' (image2 f₁ s u) (image2 f₂ t u) := by
rintro _ ⟨_, ⟨a, ha, b, hb, rfl⟩, c, hc, rfl⟩
rw [h_distrib]
exact mem_image2_of_mem (mem_image2_of_mem ha hc) (mem_image2_of_mem hb hc)
theorem image_image2_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) :
(image2 f s t).image g = image2 f' (t.image g₁) (s.image g₂) := by
rw [image2_swap f]
exact image_image2_distrib fun _ _ => h_antidistrib _ _
/-- Symmetric statement to `Set.image2_image_left_anticomm`. -/
theorem image_image2_antidistrib_left {g : γ → δ} {f' : β' → α → δ} {g' : β → β'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g' b) a) :
(image2 f s t).image g = image2 f' (t.image g') s :=
(image_image2_antidistrib h_antidistrib).trans <| by rw [image_id']
/-- Symmetric statement to `Set.image_image2_right_anticomm`. -/
theorem image_image2_antidistrib_right {g : γ → δ} {f' : β → α' → δ} {g' : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' b (g' a)) :
(image2 f s t).image g = image2 f' t (s.image g') :=
(image_image2_antidistrib h_antidistrib).trans <| by rw [image_id']
/-- Symmetric statement to `Set.image_image2_antidistrib_left`. -/
theorem image2_image_left_anticomm {f : α' → β → γ} {g : α → α'} {f' : β → α → δ} {g' : δ → γ}
(h_left_anticomm : ∀ a b, f (g a) b = g' (f' b a)) :
image2 f (s.image g) t = (image2 f' t s).image g' :=
(image_image2_antidistrib_left fun a b => (h_left_anticomm b a).symm).symm
/-- Symmetric statement to `Set.image_image2_antidistrib_right`. -/
theorem image_image2_right_anticomm {f : α → β' → γ} {g : β → β'} {f' : β → α → δ} {g' : δ → γ}
(h_right_anticomm : ∀ a b, f a (g b) = g' (f' b a)) :
image2 f s (t.image g) = (image2 f' t s).image g' :=
(image_image2_antidistrib_right fun a b => (h_right_anticomm b a).symm).symm
/-- If `a` is a left identity for `f : α → β → β`, then `{a}` is a left identity for
`Set.image2 f`. -/
lemma image2_left_identity {f : α → β → β} {a : α} (h : ∀ b, f a b = b) (t : Set β) :
image2 f {a} t = t := by
rw [image2_singleton_left, show f a = id from funext h, image_id]
/-- If `b` is a right identity for `f : α → β → α`, then `{b}` is a right identity for
`Set.image2 f`. -/
lemma image2_right_identity {f : α → β → α} {b : β} (h : ∀ a, f a b = a) (s : Set α) :
image2 f s {b} = s := by
rw [image2_singleton_right, funext h, image_id']
theorem image2_inter_union_subset_union :
image2 f (s ∩ s') (t ∪ t') ⊆ image2 f s t ∪ image2 f s' t' := by
rw [image2_union_right]
exact
union_subset_union (image2_subset_right inter_subset_left)
(image2_subset_right inter_subset_right)
theorem image2_union_inter_subset_union :
image2 f (s ∪ s') (t ∩ t') ⊆ image2 f s t ∪ image2 f s' t' := by
rw [image2_union_left]
exact
union_subset_union (image2_subset_left inter_subset_left)
(image2_subset_left inter_subset_right)
| Mathlib/Data/Set/NAry.lean | 325 | 329 | theorem image2_inter_union_subset {f : α → α → β} {s t : Set α} (hf : ∀ a b, f a b = f b a) :
image2 f (s ∩ t) (s ∪ t) ⊆ image2 f s t := by | rw [inter_comm]
exact image2_inter_union_subset_union.trans (union_subset (image2_comm hf).subset Subset.rfl) |
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Sub.Unbundled.Basic
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Even
/-!
# Lemmas about subtraction in unbundled canonically ordered monoids
-/
variable {α : Type*}
section CanonicallyOrderedAddCommMonoid
variable [AddCommMonoid α] [PartialOrder α] [CanonicallyOrderedAdd α]
[Sub α] [OrderedSub α] {a b c : α}
theorem add_tsub_cancel_iff_le : a + (b - a) = b ↔ a ≤ b :=
⟨fun h => le_iff_exists_add.mpr ⟨b - a, h.symm⟩, add_tsub_cancel_of_le⟩
| Mathlib/Algebra/Order/Sub/Basic.lean | 25 | 28 | theorem tsub_add_cancel_iff_le : b - a + a = b ↔ a ≤ b := by | rw [add_comm]
exact add_tsub_cancel_iff_le |
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap
import Mathlib.MeasureTheory.Covering.BesicovitchVectorSpace
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
import Mathlib.Analysis.NormedSpace.Pointwise
import Mathlib.MeasureTheory.Constructions.Polish.Basic
import Mathlib.Analysis.Calculus.InverseFunctionTheorem.ApproximatesLinearOn
import Mathlib.Topology.Algebra.Module.Determinant
/-!
# Change of variables in higher-dimensional integrals
Let `μ` be a Lebesgue measure on a finite-dimensional real vector space `E`.
Let `f : E → E` be a function which is injective and differentiable on a measurable set `s`,
with derivative `f'`. Then we prove that `f '' s` is measurable, and
its measure is given by the formula `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ` (where `(f' x).det`
is almost everywhere measurable, but not Borel-measurable in general). This formula is proved in
`lintegral_abs_det_fderiv_eq_addHaar_image`. We deduce the change of variables
formula for the Lebesgue and Bochner integrals, in `lintegral_image_eq_lintegral_abs_det_fderiv_mul`
and `integral_image_eq_integral_abs_det_fderiv_smul` respectively.
## Main results
* `addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero`: if `f` is differentiable on a
set `s` with zero measure, then `f '' s` also has zero measure.
* `addHaar_image_eq_zero_of_det_fderivWithin_eq_zero`: if `f` is differentiable on a set `s`, and
its derivative is never invertible, then `f '' s` has zero measure (a version of Sard's lemma).
* `aemeasurable_fderivWithin`: if `f` is differentiable on a measurable set `s`, then `f'`
is almost everywhere measurable on `s`.
For the next statements, `s` is a measurable set and `f` is differentiable on `s`
(with a derivative `f'`) and injective on `s`.
* `measurable_image_of_fderivWithin`: the image `f '' s` is measurable.
* `measurableEmbedding_of_fderivWithin`: the function `s.restrict f` is a measurable embedding.
* `lintegral_abs_det_fderiv_eq_addHaar_image`: the image measure is given by
`μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ`.
* `lintegral_image_eq_lintegral_abs_det_fderiv_mul`: for `g : E → ℝ≥0∞`, one has
`∫⁻ x in f '' s, g x ∂μ = ∫⁻ x in s, ENNReal.ofReal |(f' x).det| * g (f x) ∂μ`.
* `integral_image_eq_integral_abs_det_fderiv_smul`: for `g : E → F`, one has
`∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ`.
* `integrableOn_image_iff_integrableOn_abs_det_fderiv_smul`: for `g : E → F`, the function `g` is
integrable on `f '' s` if and only if `|(f' x).det| • g (f x))` is integrable on `s`.
## Implementation
Typical versions of these results in the literature have much stronger assumptions: `s` would
typically be open, and the derivative `f' x` would depend continuously on `x` and be invertible
everywhere, to have the local inverse theorem at our disposal. The proof strategy under our weaker
assumptions is more involved. We follow [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2].
The first remark is that, if `f` is sufficiently well approximated by a linear map `A` on a set
`s`, then `f` expands the volume of `s` by at least `A.det - ε` and at most `A.det + ε`, where
the closeness condition depends on `A` in a non-explicit way (see `addHaar_image_le_mul_of_det_lt`
and `mul_le_addHaar_image_of_lt_det`). This fact holds for balls by a simple inclusion argument,
and follows for general sets using the Besicovitch covering theorem to cover the set by balls with
measures adding up essentially to `μ s`.
When `f` is differentiable on `s`, one may partition `s` into countably many subsets `s ∩ t n`
(where `t n` is measurable), on each of which `f` is well approximated by a linear map, so that the
above results apply. See `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, which
follows from the pointwise differentiability (in a non-completely trivial way, as one should ensure
a form of uniformity on the sets of the partition).
Combining the above two results would give the conclusion, except for two difficulties: it is not
obvious why `f '' s` and `f'` should be measurable, which prevents us from using countable
additivity for the measure and the integral. It turns out that `f '' s` is indeed measurable,
and that `f'` is almost everywhere measurable, which is enough to recover countable additivity.
The measurability of `f '' s` follows from the deep Lusin-Souslin theorem ensuring that, in a
Polish space, a continuous injective image of a measurable set is measurable.
The key point to check the almost everywhere measurability of `f'` is that, if `f` is approximated
up to `δ` by a linear map on a set `s`, then `f'` is within `δ` of `A` on a full measure subset
of `s` (namely, its density points). With the above approximation argument, it follows that `f'`
is the almost everywhere limit of a sequence of measurable functions (which are constant on the
pieces of the good discretization), and is therefore almost everywhere measurable.
## Tags
Change of variables in integrals
## References
[Fremlin, *Measure Theory* (volume 2)][fremlin_vol2]
-/
open MeasureTheory MeasureTheory.Measure Metric Filter Set Module Asymptotics
TopologicalSpace
open scoped NNReal ENNReal Topology Pointwise
variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] {s : Set E} {f : E → E} {f' : E → E →L[ℝ] E}
/-!
### Decomposition lemmas
We state lemmas ensuring that a differentiable function can be approximated, on countably many
measurable pieces, by linear maps (with a prescribed precision depending on the linear map).
-/
/-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may cover `s`
with countably many closed sets `t n` on which `f` is well approximated by linear maps `A n`. -/
theorem exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F]
(f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x)
(r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) :
∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F),
(∀ n, IsClosed (t n)) ∧
(s ⊆ ⋃ n, t n) ∧
(∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧
(s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by
/- Choose countably many linear maps `f' z`. For every such map, if `f` has a derivative at `x`
close enough to `f' z`, then `f y - f x` is well approximated by `f' z (y - x)` for `y` close
enough to `x`, say on a ball of radius `r` (or even `u n` for some `n`, where `u` is a fixed
sequence tending to `0`).
Let `M n z` be the points where this happens. Then this set is relatively closed inside `s`,
and moreover in every closed ball of radius `u n / 3` inside it the map is well approximated by
`f' z`. Using countably many closed balls to split `M n z` into small diameter subsets
`K n z p`, one obtains the desired sets `t q` after reindexing.
-/
-- exclude the trivial case where `s` is empty
rcases eq_empty_or_nonempty s with (rfl | hs)
· refine ⟨fun _ => ∅, fun _ => 0, ?_, ?_, ?_, ?_⟩ <;> simp
-- we will use countably many linear maps. Select these from all the derivatives since the
-- space of linear maps is second-countable
obtain ⟨T, T_count, hT⟩ :
∃ T : Set s,
T.Countable ∧ ⋃ x ∈ T, ball (f' (x : E)) (r (f' x)) = ⋃ x : s, ball (f' x) (r (f' x)) :=
TopologicalSpace.isOpen_iUnion_countable _ fun x => isOpen_ball
-- fix a sequence `u` of positive reals tending to zero.
obtain ⟨u, _, u_pos, u_lim⟩ :
∃ u : ℕ → ℝ, StrictAnti u ∧ (∀ n : ℕ, 0 < u n) ∧ Tendsto u atTop (𝓝 0) :=
exists_seq_strictAnti_tendsto (0 : ℝ)
-- `M n z` is the set of points `x` such that `f y - f x` is close to `f' z (y - x)` for `y`
-- in the ball of radius `u n` around `x`.
let M : ℕ → T → Set E := fun n z =>
{x | x ∈ s ∧ ∀ y ∈ s ∩ ball x (u n), ‖f y - f x - f' z (y - x)‖ ≤ r (f' z) * ‖y - x‖}
-- As `f` is differentiable everywhere on `s`, the sets `M n z` cover `s` by design.
have s_subset : ∀ x ∈ s, ∃ (n : ℕ) (z : T), x ∈ M n z := by
intro x xs
obtain ⟨z, zT, hz⟩ : ∃ z ∈ T, f' x ∈ ball (f' (z : E)) (r (f' z)) := by
have : f' x ∈ ⋃ z ∈ T, ball (f' (z : E)) (r (f' z)) := by
rw [hT]
refine mem_iUnion.2 ⟨⟨x, xs⟩, ?_⟩
simpa only [mem_ball, Subtype.coe_mk, dist_self] using (rpos (f' x)).bot_lt
rwa [mem_iUnion₂, bex_def] at this
obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ ‖f' x - f' z‖ + ε ≤ r (f' z) := by
refine ⟨r (f' z) - ‖f' x - f' z‖, ?_, le_of_eq (by abel)⟩
simpa only [sub_pos] using mem_ball_iff_norm.mp hz
obtain ⟨δ, δpos, hδ⟩ :
∃ (δ : ℝ), 0 < δ ∧ ball x δ ∩ s ⊆ {y | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} :=
Metric.mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos)
obtain ⟨n, hn⟩ : ∃ n, u n < δ := ((tendsto_order.1 u_lim).2 _ δpos).exists
refine ⟨n, ⟨z, zT⟩, ⟨xs, ?_⟩⟩
intro y hy
calc
‖f y - f x - (f' z) (y - x)‖ = ‖f y - f x - (f' x) (y - x) + (f' x - f' z) (y - x)‖ := by
congr 1
simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply]
abel
_ ≤ ‖f y - f x - (f' x) (y - x)‖ + ‖(f' x - f' z) (y - x)‖ := norm_add_le _ _
_ ≤ ε * ‖y - x‖ + ‖f' x - f' z‖ * ‖y - x‖ := by
refine add_le_add (hδ ?_) (ContinuousLinearMap.le_opNorm _ _)
rw [inter_comm]
exact inter_subset_inter_right _ (ball_subset_ball hn.le) hy
_ ≤ r (f' z) * ‖y - x‖ := by
rw [← add_mul, add_comm]
gcongr
-- the sets `M n z` are relatively closed in `s`, as all the conditions defining it are clearly
-- closed
have closure_M_subset : ∀ n z, s ∩ closure (M n z) ⊆ M n z := by
rintro n z x ⟨xs, hx⟩
refine ⟨xs, fun y hy => ?_⟩
obtain ⟨a, aM, a_lim⟩ : ∃ a : ℕ → E, (∀ k, a k ∈ M n z) ∧ Tendsto a atTop (𝓝 x) :=
mem_closure_iff_seq_limit.1 hx
have L1 :
Tendsto (fun k : ℕ => ‖f y - f (a k) - (f' z) (y - a k)‖) atTop
(𝓝 ‖f y - f x - (f' z) (y - x)‖) := by
apply Tendsto.norm
have L : Tendsto (fun k => f (a k)) atTop (𝓝 (f x)) := by
apply (hf' x xs).continuousWithinAt.tendsto.comp
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ a_lim
exact Eventually.of_forall fun k => (aM k).1
apply Tendsto.sub (tendsto_const_nhds.sub L)
exact ((f' z).continuous.tendsto _).comp (tendsto_const_nhds.sub a_lim)
have L2 : Tendsto (fun k : ℕ => (r (f' z) : ℝ) * ‖y - a k‖) atTop (𝓝 (r (f' z) * ‖y - x‖)) :=
(tendsto_const_nhds.sub a_lim).norm.const_mul _
have I : ∀ᶠ k in atTop, ‖f y - f (a k) - (f' z) (y - a k)‖ ≤ r (f' z) * ‖y - a k‖ := by
have L : Tendsto (fun k => dist y (a k)) atTop (𝓝 (dist y x)) :=
tendsto_const_nhds.dist a_lim
filter_upwards [(tendsto_order.1 L).2 _ hy.2]
intro k hk
exact (aM k).2 y ⟨hy.1, hk⟩
exact le_of_tendsto_of_tendsto L1 L2 I
-- choose a dense sequence `d p`
rcases TopologicalSpace.exists_dense_seq E with ⟨d, hd⟩
-- split `M n z` into subsets `K n z p` of small diameters by intersecting with the ball
-- `closedBall (d p) (u n / 3)`.
let K : ℕ → T → ℕ → Set E := fun n z p => closure (M n z) ∩ closedBall (d p) (u n / 3)
-- on the sets `K n z p`, the map `f` is well approximated by `f' z` by design.
have K_approx : ∀ (n) (z : T) (p), ApproximatesLinearOn f (f' z) (s ∩ K n z p) (r (f' z)) := by
intro n z p x hx y hy
have yM : y ∈ M n z := closure_M_subset _ _ ⟨hy.1, hy.2.1⟩
refine yM.2 _ ⟨hx.1, ?_⟩
calc
dist x y ≤ dist x (d p) + dist y (d p) := dist_triangle_right _ _ _
_ ≤ u n / 3 + u n / 3 := add_le_add hx.2.2 hy.2.2
_ < u n := by linarith [u_pos n]
-- the sets `K n z p` are also closed, again by design.
have K_closed : ∀ (n) (z : T) (p), IsClosed (K n z p) := fun n z p =>
isClosed_closure.inter isClosed_closedBall
-- reindex the sets `K n z p`, to let them only depend on an integer parameter `q`.
obtain ⟨F, hF⟩ : ∃ F : ℕ → ℕ × T × ℕ, Function.Surjective F := by
haveI : Encodable T := T_count.toEncodable
have : Nonempty T := by
rcases hs with ⟨x, xs⟩
rcases s_subset x xs with ⟨n, z, _⟩
exact ⟨z⟩
inhabit ↥T
exact ⟨_, Encodable.surjective_decode_iget (ℕ × T × ℕ)⟩
-- these sets `t q = K n z p` will do
refine
⟨fun q => K (F q).1 (F q).2.1 (F q).2.2, fun q => f' (F q).2.1, fun n => K_closed _ _ _,
fun x xs => ?_, fun q => K_approx _ _ _, fun _ q => ⟨(F q).2.1, (F q).2.1.1.2, rfl⟩⟩
-- the only fact that needs further checking is that they cover `s`.
-- we already know that any point `x ∈ s` belongs to a set `M n z`.
obtain ⟨n, z, hnz⟩ : ∃ (n : ℕ) (z : T), x ∈ M n z := s_subset x xs
-- by density, it also belongs to a ball `closedBall (d p) (u n / 3)`.
obtain ⟨p, hp⟩ : ∃ p : ℕ, x ∈ closedBall (d p) (u n / 3) := by
have : Set.Nonempty (ball x (u n / 3)) := by simp only [nonempty_ball]; linarith [u_pos n]
obtain ⟨p, hp⟩ : ∃ p : ℕ, d p ∈ ball x (u n / 3) := hd.exists_mem_open isOpen_ball this
exact ⟨p, (mem_ball'.1 hp).le⟩
-- choose `q` for which `t q = K n z p`.
obtain ⟨q, hq⟩ : ∃ q, F q = (n, z, p) := hF _
-- then `x` belongs to `t q`.
apply mem_iUnion.2 ⟨q, _⟩
simp -zeta only [K, hq, mem_inter_iff, hp, and_true]
exact subset_closure hnz
variable [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ]
open scoped Function -- required for scoped `on` notation
/-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may
partition `s` into countably many disjoint relatively measurable sets (i.e., intersections
of `s` with measurable sets `t n`) on which `f` is well approximated by linear maps `A n`. -/
theorem exists_partition_approximatesLinearOn_of_hasFDerivWithinAt [SecondCountableTopology F]
(f : E → F) (s : Set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x)
(r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) :
∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] F),
Pairwise (Disjoint on t) ∧
(∀ n, MeasurableSet (t n)) ∧
(s ⊆ ⋃ n, t n) ∧
(∀ n, ApproximatesLinearOn f (A n) (s ∩ t n) (r (A n))) ∧
(s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) := by
rcases exists_closed_cover_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' r rpos with
⟨t, A, t_closed, st, t_approx, ht⟩
refine
⟨disjointed t, A, disjoint_disjointed _,
MeasurableSet.disjointed fun n => (t_closed n).measurableSet, ?_, ?_, ht⟩
· rw [iUnion_disjointed]; exact st
· intro n; exact (t_approx n).mono_set (inter_subset_inter_right _ (disjointed_subset _ _))
namespace MeasureTheory
/-!
### Local lemmas
We check that a function which is well enough approximated by a linear map expands the volume
essentially like this linear map, and that its derivative (if it exists) is almost everywhere close
to the approximating linear map.
-/
/-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear
map `A`. Then it expands the volume of any set by at most `m` for any `m > det A`. -/
theorem addHaar_image_le_mul_of_det_lt (A : E →L[ℝ] E) {m : ℝ≥0}
(hm : ENNReal.ofReal |A.det| < m) :
∀ᶠ δ in 𝓝[>] (0 : ℝ≥0),
∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → μ (f '' s) ≤ m * μ s := by
apply nhdsWithin_le_nhds
let d := ENNReal.ofReal |A.det|
-- construct a small neighborhood of `A '' (closedBall 0 1)` with measure comparable to
-- the determinant of `A`.
obtain ⟨ε, hε, εpos⟩ :
∃ ε : ℝ, μ (closedBall 0 ε + A '' closedBall 0 1) < m * μ (closedBall 0 1) ∧ 0 < ε := by
have HC : IsCompact (A '' closedBall 0 1) :=
(ProperSpace.isCompact_closedBall _ _).image A.continuous
have L0 :
Tendsto (fun ε => μ (cthickening ε (A '' closedBall 0 1))) (𝓝[>] 0)
(𝓝 (μ (A '' closedBall 0 1))) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
exact tendsto_measure_cthickening_of_isCompact HC
have L1 :
Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0)
(𝓝 (μ (A '' closedBall 0 1))) := by
apply L0.congr' _
filter_upwards [self_mem_nhdsWithin] with r hr
rw [← HC.add_closedBall_zero (le_of_lt hr), add_comm]
have L2 :
Tendsto (fun ε => μ (closedBall 0 ε + A '' closedBall 0 1)) (𝓝[>] 0)
(𝓝 (d * μ (closedBall 0 1))) := by
convert L1
exact (addHaar_image_continuousLinearMap _ _ _).symm
have I : d * μ (closedBall 0 1) < m * μ (closedBall 0 1) :=
(ENNReal.mul_lt_mul_right (measure_closedBall_pos μ _ zero_lt_one).ne'
measure_closedBall_lt_top.ne).2
hm
have H :
∀ᶠ b : ℝ in 𝓝[>] 0, μ (closedBall 0 b + A '' closedBall 0 1) < m * μ (closedBall 0 1) :=
(tendsto_order.1 L2).2 _ I
exact (H.and self_mem_nhdsWithin).exists
have : Iio (⟨ε, εpos.le⟩ : ℝ≥0) ∈ 𝓝 (0 : ℝ≥0) := by apply Iio_mem_nhds; exact εpos
filter_upwards [this]
-- fix a function `f` which is close enough to `A`.
intro δ hδ s f hf
simp only [mem_Iio, ← NNReal.coe_lt_coe, NNReal.coe_mk] at hδ
-- This function expands the volume of any ball by at most `m`
have I : ∀ x r, x ∈ s → 0 ≤ r → μ (f '' (s ∩ closedBall x r)) ≤ m * μ (closedBall x r) := by
intro x r xs r0
have K : f '' (s ∩ closedBall x r) ⊆ A '' closedBall 0 r + closedBall (f x) (ε * r) := by
rintro y ⟨z, ⟨zs, zr⟩, rfl⟩
rw [mem_closedBall_iff_norm] at zr
apply Set.mem_add.2 ⟨A (z - x), _, f z - f x - A (z - x) + f x, _, _⟩
· apply mem_image_of_mem
simpa only [dist_eq_norm, mem_closedBall, mem_closedBall_zero_iff, sub_zero] using zr
· rw [mem_closedBall_iff_norm, add_sub_cancel_right]
calc
‖f z - f x - A (z - x)‖ ≤ δ * ‖z - x‖ := hf _ zs _ xs
_ ≤ ε * r := by gcongr
· simp only [map_sub, Pi.sub_apply]
abel
have :
A '' closedBall 0 r + closedBall (f x) (ε * r) =
{f x} + r • (A '' closedBall 0 1 + closedBall 0 ε) := by
rw [smul_add, ← add_assoc, add_comm {f x}, add_assoc, smul_closedBall _ _ εpos.le, smul_zero,
singleton_add_closedBall_zero, ← image_smul_set, _root_.smul_closedBall _ _ zero_le_one,
smul_zero, Real.norm_eq_abs, abs_of_nonneg r0, mul_one, mul_comm]
rw [this] at K
calc
μ (f '' (s ∩ closedBall x r)) ≤ μ ({f x} + r • (A '' closedBall 0 1 + closedBall 0 ε)) :=
measure_mono K
_ = ENNReal.ofReal (r ^ finrank ℝ E) * μ (A '' closedBall 0 1 + closedBall 0 ε) := by
simp only [abs_of_nonneg r0, addHaar_smul, image_add_left, abs_pow, singleton_add,
measure_preimage_add]
_ ≤ ENNReal.ofReal (r ^ finrank ℝ E) * (m * μ (closedBall 0 1)) := by
rw [add_comm]; gcongr
_ = m * μ (closedBall x r) := by simp only [addHaar_closedBall' μ _ r0]; ring
-- covering `s` by closed balls with total measure very close to `μ s`, one deduces that the
-- measure of `f '' s` is at most `m * (μ s + a)` for any positive `a`.
have J : ∀ᶠ a in 𝓝[>] (0 : ℝ≥0∞), μ (f '' s) ≤ m * (μ s + a) := by
filter_upwards [self_mem_nhdsWithin] with a ha
rw [mem_Ioi] at ha
obtain ⟨t, r, t_count, ts, rpos, st, μt⟩ :
∃ (t : Set E) (r : E → ℝ),
t.Countable ∧
t ⊆ s ∧
(∀ x : E, x ∈ t → 0 < r x) ∧
(s ⊆ ⋃ x ∈ t, closedBall x (r x)) ∧
(∑' x : ↥t, μ (closedBall (↑x) (r ↑x))) ≤ μ s + a :=
Besicovitch.exists_closedBall_covering_tsum_measure_le μ ha.ne' (fun _ => Ioi 0) s
fun x _ δ δpos => ⟨δ / 2, by simp [half_pos δpos, δpos]⟩
haveI : Encodable t := t_count.toEncodable
calc
μ (f '' s) ≤ μ (⋃ x : t, f '' (s ∩ closedBall x (r x))) := by
rw [biUnion_eq_iUnion] at st
apply measure_mono
rw [← image_iUnion, ← inter_iUnion]
exact image_subset _ (subset_inter (Subset.refl _) st)
_ ≤ ∑' x : t, μ (f '' (s ∩ closedBall x (r x))) := measure_iUnion_le _
_ ≤ ∑' x : t, m * μ (closedBall x (r x)) :=
(ENNReal.tsum_le_tsum fun x => I x (r x) (ts x.2) (rpos x x.2).le)
_ ≤ m * (μ s + a) := by rw [ENNReal.tsum_mul_left]; gcongr
-- taking the limit in `a`, one obtains the conclusion
have L : Tendsto (fun a => (m : ℝ≥0∞) * (μ s + a)) (𝓝[>] 0) (𝓝 (m * (μ s + 0))) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
apply ENNReal.Tendsto.const_mul (tendsto_const_nhds.add tendsto_id)
simp only [ENNReal.coe_ne_top, Ne, or_true, not_false_iff]
rw [add_zero] at L
exact ge_of_tendsto L J
/-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear
map `A`. Then it expands the volume of any set by at least `m` for any `m < det A`. -/
theorem mul_le_addHaar_image_of_lt_det (A : E →L[ℝ] E) {m : ℝ≥0}
(hm : (m : ℝ≥0∞) < ENNReal.ofReal |A.det|) :
∀ᶠ δ in 𝓝[>] (0 : ℝ≥0),
∀ (s : Set E) (f : E → E), ApproximatesLinearOn f A s δ → (m : ℝ≥0∞) * μ s ≤ μ (f '' s) := by
apply nhdsWithin_le_nhds
-- The assumption `hm` implies that `A` is invertible. If `f` is close enough to `A`, it is also
-- invertible. One can then pass to the inverses, and deduce the estimate from
-- `addHaar_image_le_mul_of_det_lt` applied to `f⁻¹` and `A⁻¹`.
-- exclude first the trivial case where `m = 0`.
rcases eq_or_lt_of_le (zero_le m) with (rfl | mpos)
· filter_upwards
simp only [forall_const, zero_mul, imp_true_iff, zero_le, ENNReal.coe_zero]
have hA : A.det ≠ 0 := by
intro h; simp only [h, ENNReal.not_lt_zero, ENNReal.ofReal_zero, abs_zero] at hm
-- let `B` be the continuous linear equiv version of `A`.
let B := A.toContinuousLinearEquivOfDetNeZero hA
-- the determinant of `B.symm` is bounded by `m⁻¹`
have I : ENNReal.ofReal |(B.symm : E →L[ℝ] E).det| < (m⁻¹ : ℝ≥0) := by
simp only [ENNReal.ofReal, abs_inv, Real.toNNReal_inv, ContinuousLinearEquiv.det_coe_symm,
ContinuousLinearMap.coe_toContinuousLinearEquivOfDetNeZero, ENNReal.coe_lt_coe] at hm ⊢
exact NNReal.inv_lt_inv mpos.ne' hm
-- therefore, we may apply `addHaar_image_le_mul_of_det_lt` to `B.symm` and `m⁻¹`.
obtain ⟨δ₀, δ₀pos, hδ₀⟩ :
∃ δ : ℝ≥0,
0 < δ ∧
∀ (t : Set E) (g : E → E),
ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t := by
have :
∀ᶠ δ : ℝ≥0 in 𝓝[>] 0,
∀ (t : Set E) (g : E → E),
ApproximatesLinearOn g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t :=
addHaar_image_le_mul_of_det_lt μ B.symm I
rcases (this.and self_mem_nhdsWithin).exists with ⟨δ₀, h, h'⟩
exact ⟨δ₀, h', h⟩
-- record smallness conditions for `δ` that will be needed to apply `hδ₀` below.
have L1 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), Subsingleton E ∨ δ < ‖(B.symm : E →L[ℝ] E)‖₊⁻¹ := by
by_cases h : Subsingleton E
· simp only [h, true_or, eventually_const]
simp only [h, false_or]
apply Iio_mem_nhds
simpa only [h, false_or, inv_pos] using B.subsingleton_or_nnnorm_symm_pos
have L2 :
∀ᶠ δ in 𝓝 (0 : ℝ≥0), ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ < δ₀ := by
have :
Tendsto (fun δ => ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ) (𝓝 0)
(𝓝 (‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - 0)⁻¹ * 0)) := by
rcases eq_or_ne ‖(B.symm : E →L[ℝ] E)‖₊ 0 with (H | H)
· simpa only [H, zero_mul] using tendsto_const_nhds
refine Tendsto.mul (tendsto_const_nhds.mul ?_) tendsto_id
refine (Tendsto.sub tendsto_const_nhds tendsto_id).inv₀ ?_
simpa only [tsub_zero, inv_eq_zero, Ne] using H
simp only [mul_zero] at this
exact (tendsto_order.1 this).2 δ₀ δ₀pos
-- let `δ` be small enough, and `f` approximated by `B` up to `δ`.
filter_upwards [L1, L2]
intro δ h1δ h2δ s f hf
have hf' : ApproximatesLinearOn f (B : E →L[ℝ] E) s δ := by convert hf
let F := hf'.toPartialEquiv h1δ
-- the condition to be checked can be reformulated in terms of the inverse maps
suffices H : μ (F.symm '' F.target) ≤ (m⁻¹ : ℝ≥0) * μ F.target by
change (m : ℝ≥0∞) * μ F.source ≤ μ F.target
rwa [← F.symm_image_target_eq_source, mul_comm, ← ENNReal.le_div_iff_mul_le, div_eq_mul_inv,
mul_comm, ← ENNReal.coe_inv mpos.ne']
· apply Or.inl
simpa only [ENNReal.coe_eq_zero, Ne] using mpos.ne'
· simp only [ENNReal.coe_ne_top, true_or, Ne, not_false_iff]
-- as `f⁻¹` is well approximated by `B⁻¹`, the conclusion follows from `hδ₀`
-- and our choice of `δ`.
exact hδ₀ _ _ ((hf'.to_inv h1δ).mono_num h2δ.le)
/-- If a differentiable function `f` is approximated by a linear map `A` on a set `s`, up to `δ`,
then at almost every `x` in `s` one has `‖f' x - A‖ ≤ δ`. -/
theorem _root_.ApproximatesLinearOn.norm_fderiv_sub_le {A : E →L[ℝ] E} {δ : ℝ≥0}
(hf : ApproximatesLinearOn f A s δ) (hs : MeasurableSet s) (f' : E → E →L[ℝ] E)
(hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : ∀ᵐ x ∂μ.restrict s, ‖f' x - A‖₊ ≤ δ := by
/- The conclusion will hold at the Lebesgue density points of `s` (which have full measure).
At such a point `x`, for any `z` and any `ε > 0` one has for small `r`
that `{x} + r • closedBall z ε` intersects `s`. At a point `y` in the intersection,
`f y - f x` is close both to `f' x (r z)` (by differentiability) and to `A (r z)`
(by linear approximation), so these two quantities are close, i.e., `(f' x - A) z` is small. -/
filter_upwards [Besicovitch.ae_tendsto_measure_inter_div μ s, ae_restrict_mem hs]
-- start from a Lebesgue density point `x`, belonging to `s`.
intro x hx xs
-- consider an arbitrary vector `z`.
apply ContinuousLinearMap.opNorm_le_bound _ δ.2 fun z => ?_
-- to show that `‖(f' x - A) z‖ ≤ δ ‖z‖`, it suffices to do it up to some error that vanishes
-- asymptotically in terms of `ε > 0`.
suffices H : ∀ ε, 0 < ε → ‖(f' x - A) z‖ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε by
have :
Tendsto (fun ε : ℝ => ((δ : ℝ) + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε) (𝓝[>] 0)
(𝓝 ((δ + 0) * (‖z‖ + 0) + ‖f' x - A‖ * 0)) :=
Tendsto.mono_left (Continuous.tendsto (by fun_prop) 0) nhdsWithin_le_nhds
simp only [add_zero, mul_zero] at this
apply le_of_tendsto_of_tendsto tendsto_const_nhds this
filter_upwards [self_mem_nhdsWithin]
exact H
-- fix a positive `ε`.
intro ε εpos
-- for small enough `r`, the rescaled ball `r • closedBall z ε` intersects `s`, as `x` is a
-- density point
have B₁ : ∀ᶠ r in 𝓝[>] (0 : ℝ), (s ∩ ({x} + r • closedBall z ε)).Nonempty :=
eventually_nonempty_inter_smul_of_density_one μ s x hx _ measurableSet_closedBall
(measure_closedBall_pos μ z εpos).ne'
obtain ⟨ρ, ρpos, hρ⟩ :
∃ ρ > 0, ball x ρ ∩ s ⊆ {y : E | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} :=
mem_nhdsWithin_iff.1 ((hf' x xs).isLittleO.def εpos)
-- for small enough `r`, the rescaled ball `r • closedBall z ε` is included in the set where
-- `f y - f x` is well approximated by `f' x (y - x)`.
have B₂ : ∀ᶠ r in 𝓝[>] (0 : ℝ), {x} + r • closedBall z ε ⊆ ball x ρ := by
apply nhdsWithin_le_nhds
exact eventually_singleton_add_smul_subset isBounded_closedBall (ball_mem_nhds x ρpos)
-- fix a small positive `r` satisfying the above properties, as well as a corresponding `y`.
obtain ⟨r, ⟨y, ⟨ys, hy⟩⟩, rρ, rpos⟩ :
∃ r : ℝ,
(s ∩ ({x} + r • closedBall z ε)).Nonempty ∧ {x} + r • closedBall z ε ⊆ ball x ρ ∧ 0 < r :=
(B₁.and (B₂.and self_mem_nhdsWithin)).exists
-- write `y = x + r a` with `a ∈ closedBall z ε`.
obtain ⟨a, az, ya⟩ : ∃ a, a ∈ closedBall z ε ∧ y = x + r • a := by
simp only [mem_smul_set, image_add_left, mem_preimage, singleton_add] at hy
rcases hy with ⟨a, az, ha⟩
exact ⟨a, az, by simp only [ha, add_neg_cancel_left]⟩
have norm_a : ‖a‖ ≤ ‖z‖ + ε :=
calc
‖a‖ = ‖z + (a - z)‖ := by simp only [add_sub_cancel]
_ ≤ ‖z‖ + ‖a - z‖ := norm_add_le _ _
_ ≤ ‖z‖ + ε := add_le_add_left (mem_closedBall_iff_norm.1 az) _
-- use the approximation properties to control `(f' x - A) a`, and then `(f' x - A) z` as `z` is
-- close to `a`.
have I : r * ‖(f' x - A) a‖ ≤ r * (δ + ε) * (‖z‖ + ε) :=
calc
r * ‖(f' x - A) a‖ = ‖(f' x - A) (r • a)‖ := by
simp only [ContinuousLinearMap.map_smul, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le]
_ = ‖f y - f x - A (y - x) - (f y - f x - (f' x) (y - x))‖ := by
congr 1
simp only [ya, add_sub_cancel_left, sub_sub_sub_cancel_left, ContinuousLinearMap.coe_sub',
eq_self_iff_true, sub_left_inj, Pi.sub_apply, ContinuousLinearMap.map_smul, smul_sub]
_ ≤ ‖f y - f x - A (y - x)‖ + ‖f y - f x - (f' x) (y - x)‖ := norm_sub_le _ _
_ ≤ δ * ‖y - x‖ + ε * ‖y - x‖ := (add_le_add (hf _ ys _ xs) (hρ ⟨rρ hy, ys⟩))
_ = r * (δ + ε) * ‖a‖ := by
simp only [ya, add_sub_cancel_left, norm_smul, Real.norm_eq_abs, abs_of_nonneg rpos.le]
ring
_ ≤ r * (δ + ε) * (‖z‖ + ε) := by gcongr
calc
‖(f' x - A) z‖ = ‖(f' x - A) a + (f' x - A) (z - a)‖ := by
congr 1
simp only [ContinuousLinearMap.coe_sub', map_sub, Pi.sub_apply]
abel
_ ≤ ‖(f' x - A) a‖ + ‖(f' x - A) (z - a)‖ := norm_add_le _ _
_ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ‖z - a‖ := by
apply add_le_add
· rw [mul_assoc] at I; exact (mul_le_mul_left rpos).1 I
· apply ContinuousLinearMap.le_opNorm
_ ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε := by
rw [mem_closedBall_iff_norm'] at az
gcongr
/-!
### Measure zero of the image, over non-measurable sets
If a set has measure `0`, then its image under a differentiable map has measure zero. This doesn't
require the set to be measurable. In the same way, if `f` is differentiable on a set `s` with
non-invertible derivative everywhere, then `f '' s` has measure `0`, again without measurability
assumptions.
-/
/-- A differentiable function maps sets of measure zero to sets of measure zero. -/
theorem addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero (hf : DifferentiableOn ℝ f s)
(hs : μ s = 0) : μ (f '' s) = 0 := by
refine le_antisymm ?_ (zero_le _)
have :
∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧
∀ (t : Set E), ApproximatesLinearOn f A t δ →
μ (f '' t) ≤ (Real.toNNReal |A.det| + 1 : ℝ≥0) * μ t := by
intro A
let m : ℝ≥0 := Real.toNNReal |A.det| + 1
have I : ENNReal.ofReal |A.det| < m := by
simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, zero_lt_one, ENNReal.coe_lt_coe]
rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩
exact ⟨δ, h', fun t ht => h t f ht⟩
choose δ hδ using this
obtain ⟨t, A, _, _, t_cover, ht, -⟩ :
∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E),
Pairwise (Disjoint on t) ∧
(∀ n : ℕ, MeasurableSet (t n)) ∧
(s ⊆ ⋃ n : ℕ, t n) ∧
(∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧
(s.Nonempty → ∀ n, ∃ y ∈ s, A n = fderivWithin ℝ f s y) :=
exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s (fderivWithin ℝ f s)
(fun x xs => (hf x xs).hasFDerivWithinAt) δ fun A => (hδ A).1.ne'
calc
μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by
apply measure_mono
rw [← image_iUnion, ← inter_iUnion]
exact image_subset f (subset_inter Subset.rfl t_cover)
_ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _
_ ≤ ∑' n, (Real.toNNReal |(A n).det| + 1 : ℝ≥0) * μ (s ∩ t n) := by
apply ENNReal.tsum_le_tsum fun n => ?_
apply (hδ (A n)).2
exact ht n
_ ≤ ∑' n, ((Real.toNNReal |(A n).det| + 1 : ℝ≥0) : ℝ≥0∞) * 0 := by
refine ENNReal.tsum_le_tsum fun n => mul_le_mul_left' ?_ _
exact le_trans (measure_mono inter_subset_left) (le_of_eq hs)
_ = 0 := by simp only [tsum_zero, mul_zero]
/-- A version of **Sard's lemma** in fixed dimension: given a differentiable function from `E`
to `E` and a set where the differential is not invertible, then the image of this set has
zero measure. Here, we give an auxiliary statement towards this result. -/
theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux
(hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (R : ℝ) (hs : s ⊆ closedBall 0 R) (ε : ℝ≥0)
(εpos : 0 < ε) (h'f' : ∀ x ∈ s, (f' x).det = 0) : μ (f '' s) ≤ ε * μ (closedBall 0 R) := by
rcases eq_empty_or_nonempty s with (rfl | h's); · simp only [measure_empty, zero_le, image_empty]
have :
∀ A : E →L[ℝ] E, ∃ δ : ℝ≥0, 0 < δ ∧
∀ (t : Set E), ApproximatesLinearOn f A t δ →
μ (f '' t) ≤ (Real.toNNReal |A.det| + ε : ℝ≥0) * μ t := by
intro A
let m : ℝ≥0 := Real.toNNReal |A.det| + ε
have I : ENNReal.ofReal |A.det| < m := by
simp only [m, ENNReal.ofReal, lt_add_iff_pos_right, εpos, ENNReal.coe_lt_coe]
rcases ((addHaar_image_le_mul_of_det_lt μ A I).and self_mem_nhdsWithin).exists with ⟨δ, h, h'⟩
exact ⟨δ, h', fun t ht => h t f ht⟩
choose δ hδ using this
obtain ⟨t, A, t_disj, t_meas, t_cover, ht, Af'⟩ :
∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E),
Pairwise (Disjoint on t) ∧
(∀ n : ℕ, MeasurableSet (t n)) ∧
(s ⊆ ⋃ n : ℕ, t n) ∧
(∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) (δ (A n))) ∧
(s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' δ fun A => (hδ A).1.ne'
calc
μ (f '' s) ≤ μ (⋃ n, f '' (s ∩ t n)) := by
rw [← image_iUnion, ← inter_iUnion]
gcongr
exact subset_inter Subset.rfl t_cover
_ ≤ ∑' n, μ (f '' (s ∩ t n)) := measure_iUnion_le _
_ ≤ ∑' n, (Real.toNNReal |(A n).det| + ε : ℝ≥0) * μ (s ∩ t n) := by
gcongr
exact (hδ (A _)).2 _ (ht _)
_ = ∑' n, ε * μ (s ∩ t n) := by
congr with n
rcases Af' h's n with ⟨y, ys, hy⟩
simp only [hy, h'f' y ys, Real.toNNReal_zero, abs_zero, zero_add]
_ ≤ ε * ∑' n, μ (closedBall 0 R ∩ t n) := by
rw [ENNReal.tsum_mul_left]
gcongr
_ = ε * μ (⋃ n, closedBall 0 R ∩ t n) := by
rw [measure_iUnion]
· exact pairwise_disjoint_mono t_disj fun n => inter_subset_right
· intro n
exact measurableSet_closedBall.inter (t_meas n)
_ ≤ ε * μ (closedBall 0 R) := by
rw [← inter_iUnion]
exact mul_le_mul_left' (measure_mono inter_subset_left) _
/-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and
a set where the differential is not invertible, then the image of this set has zero measure. -/
theorem addHaar_image_eq_zero_of_det_fderivWithin_eq_zero
(hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (h'f' : ∀ x ∈ s, (f' x).det = 0) :
μ (f '' s) = 0 := by
suffices H : ∀ R, μ (f '' (s ∩ closedBall 0 R)) = 0 by
apply le_antisymm _ (zero_le _)
rw [← iUnion_inter_closedBall_nat s 0]
calc
μ (f '' ⋃ n : ℕ, s ∩ closedBall 0 n) ≤ ∑' n : ℕ, μ (f '' (s ∩ closedBall 0 n)) := by
rw [image_iUnion]; exact measure_iUnion_le _
_ ≤ 0 := by simp only [H, tsum_zero, nonpos_iff_eq_zero]
intro R
have A : ∀ (ε : ℝ≥0), 0 < ε → μ (f '' (s ∩ closedBall 0 R)) ≤ ε * μ (closedBall 0 R) :=
fun ε εpos =>
addHaar_image_eq_zero_of_det_fderivWithin_eq_zero_aux μ
(fun x hx => (hf' x hx.1).mono inter_subset_left) R inter_subset_right ε εpos
fun x hx => h'f' x hx.1
have B : Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝[>] 0) (𝓝 0) := by
have :
Tendsto (fun ε : ℝ≥0 => (ε : ℝ≥0∞) * μ (closedBall 0 R)) (𝓝 0)
(𝓝 (((0 : ℝ≥0) : ℝ≥0∞) * μ (closedBall 0 R))) :=
ENNReal.Tendsto.mul_const (ENNReal.tendsto_coe.2 tendsto_id)
(Or.inr measure_closedBall_lt_top.ne)
simp only [zero_mul, ENNReal.coe_zero] at this
exact Tendsto.mono_left this nhdsWithin_le_nhds
apply le_antisymm _ (zero_le _)
apply ge_of_tendsto B
filter_upwards [self_mem_nhdsWithin]
exact A
/-!
### Weak measurability statements
We show that the derivative of a function on a set is almost everywhere measurable, and that the
image `f '' s` is measurable if `f` is injective on `s`. The latter statement follows from the
Lusin-Souslin theorem.
-/
/-- The derivative of a function on a measurable set is almost everywhere measurable on this set
with respect to Lebesgue measure. Note that, in general, it is not genuinely measurable there,
as `f'` is not unique (but only on a set of measure `0`, as the argument shows). -/
theorem aemeasurable_fderivWithin (hs : MeasurableSet s)
(hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) : AEMeasurable f' (μ.restrict s) := by
/- It suffices to show that `f'` can be uniformly approximated by a measurable function.
Fix `ε > 0`. Thanks to `exists_partition_approximatesLinearOn_of_hasFDerivWithinAt`, one
can find a countable measurable partition of `s` into sets `s ∩ t n` on which `f` is well
approximated by linear maps `A n`. On almost all of `s ∩ t n`, it follows from
`ApproximatesLinearOn.norm_fderiv_sub_le` that `f'` is uniformly approximated by `A n`, which
gives the conclusion. -/
-- fix a precision `ε`
refine aemeasurable_of_unif_approx fun ε εpos => ?_
let δ : ℝ≥0 := ⟨ε, le_of_lt εpos⟩
have δpos : 0 < δ := εpos
-- partition `s` into sets `s ∩ t n` on which `f` is approximated by linear maps `A n`.
obtain ⟨t, A, t_disj, t_meas, t_cover, ht, _⟩ :
∃ (t : ℕ → Set E) (A : ℕ → E →L[ℝ] E),
Pairwise (Disjoint on t) ∧
(∀ n : ℕ, MeasurableSet (t n)) ∧
(s ⊆ ⋃ n : ℕ, t n) ∧
(∀ n : ℕ, ApproximatesLinearOn f (A n) (s ∩ t n) δ) ∧
(s.Nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
exists_partition_approximatesLinearOn_of_hasFDerivWithinAt f s f' hf' (fun _ => δ) fun _ =>
δpos.ne'
-- define a measurable function `g` which coincides with `A n` on `t n`.
obtain ⟨g, g_meas, hg⟩ :
∃ g : E → E →L[ℝ] E, Measurable g ∧ ∀ (n : ℕ) (x : E), x ∈ t n → g x = A n :=
exists_measurable_piecewise t t_meas (fun n _ => A n) (fun n => measurable_const) <|
t_disj.mono fun i j h => by simp only [h.inter_eq, eqOn_empty]
refine ⟨g, g_meas.aemeasurable, ?_⟩
-- reduce to checking that `f'` and `g` are close on almost all of `s ∩ t n`, for all `n`.
suffices H : ∀ᵐ x : E ∂sum fun n ↦ μ.restrict (s ∩ t n), dist (g x) (f' x) ≤ ε by
have : μ.restrict s ≤ sum fun n => μ.restrict (s ∩ t n) := by
have : s = ⋃ n, s ∩ t n := by
rw [← inter_iUnion]
exact Subset.antisymm (subset_inter Subset.rfl t_cover) inter_subset_left
conv_lhs => rw [this]
exact restrict_iUnion_le
exact ae_mono this H
-- fix such an `n`.
refine ae_sum_iff.2 fun n => ?_
-- on almost all `s ∩ t n`, `f' x` is close to `A n` thanks to
-- `ApproximatesLinearOn.norm_fderiv_sub_le`.
have E₁ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), ‖f' x - A n‖₊ ≤ δ :=
(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f' fun x hx =>
(hf' x hx.1).mono inter_subset_left
-- moreover, `g x` is equal to `A n` there.
have E₂ : ∀ᵐ x : E ∂μ.restrict (s ∩ t n), g x = A n := by
suffices H : ∀ᵐ x : E ∂μ.restrict (t n), g x = A n from
ae_mono (restrict_mono inter_subset_right le_rfl) H
filter_upwards [ae_restrict_mem (t_meas n)]
exact hg n
-- putting these two properties together gives the conclusion.
filter_upwards [E₁, E₂] with x hx1 hx2
rw [← nndist_eq_nnnorm] at hx1
rw [hx2, dist_comm]
exact hx1
theorem aemeasurable_ofReal_abs_det_fderivWithin (hs : MeasurableSet s)
(hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) :
AEMeasurable (fun x => ENNReal.ofReal |(f' x).det|) (μ.restrict s) := by
apply ENNReal.measurable_ofReal.comp_aemeasurable
refine continuous_abs.measurable.comp_aemeasurable ?_
refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_
exact aemeasurable_fderivWithin μ hs hf'
| Mathlib/MeasureTheory/Function/Jacobian.lean | 751 | 757 | theorem aemeasurable_toNNReal_abs_det_fderivWithin (hs : MeasurableSet s)
(hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) :
AEMeasurable (fun x => |(f' x).det|.toNNReal) (μ.restrict s) := by | apply measurable_real_toNNReal.comp_aemeasurable
refine continuous_abs.measurable.comp_aemeasurable ?_
refine ContinuousLinearMap.continuous_det.measurable.comp_aemeasurable ?_
exact aemeasurable_fderivWithin μ hs hf' |
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Heather Macbeth
-/
import Mathlib.Geometry.Manifold.VectorBundle.Basic
/-! # Tangent bundles
This file defines the tangent bundle as a `C^n` vector bundle.
Let `M` be a manifold with model `I` on `(E, H)`. The tangent space `TangentSpace I (x : M)` has
already been defined as a type synonym for `E`, and the tangent bundle `TangentBundle I M` as an
abbrev of `Bundle.TotalSpace E (TangentSpace I : M → Type _)`.
In this file, when `M` is `C^1`, we construct a vector bundle structure
on `TangentBundle I M` using the `VectorBundleCore` construction indexed by the charts of `M`
with fibers `E`. Given two charts `i, j : PartialHomeomorph M H`, the coordinate change
between `i` and `j` at a point `x : M` is the derivative of the composite
```
I.symm i.symm j I
E -----> H -----> M --> H --> E
```
within the set `range I ⊆ E` at `I (i x) : E`.
This defines a vector bundle `TangentBundle` with fibers `TangentSpace`.
## Main definitions and results
* `tangentBundleCore I M` is the vector bundle core for the tangent bundle over `M`.
* When `M` is a `C^{n+1}` manifold, `TangentBundle I M` has a `C^n` vector bundle
structure over `M`. In particular, it is a topological space, a vector bundle, a fiber bundle,
and a `C^n` manifold.
-/
open Bundle Set IsManifold PartialHomeomorph ContinuousLinearMap
open scoped Manifold Topology Bundle ContDiff
noncomputable section
section General
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {n : WithTop ℕ∞} {E : Type*} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H : Type*}
[TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners 𝕜 E' H'} {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
{M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
{F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
/-- Auxiliary lemma for tangent spaces: the derivative of a coordinate change between two charts is
`C^n` on its source. -/
| Mathlib/Geometry/Manifold/VectorBundle/Tangent.lean | 54 | 63 | theorem contDiffOn_fderiv_coord_change [IsManifold I (n + 1) M]
(i j : atlas H M) :
ContDiffOn 𝕜 n (fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I))
((i.1.extend I).symm ≫ j.1.extend I).source := by | have h : ((i.1.extend I).symm ≫ j.1.extend I).source ⊆ range I := by
rw [i.1.extend_coord_change_source]; apply image_subset_range
intro x hx
refine (ContDiffWithinAt.fderivWithin_right ?_ I.uniqueDiffOn le_rfl
<| h hx).mono h
refine (PartialHomeomorph.contDiffOn_extend_coord_change (subset_maximalAtlas j.2) |
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Support
import Mathlib.Data.Set.SymmDiff
/-!
# Indicator function
- `Set.indicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise.
- `Set.mulIndicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise.
## Implementation note
In mathematics, an indicator function or a characteristic function is a function
used to indicate membership of an element in a set `s`,
having the value `1` for all elements of `s` and the value `0` otherwise.
But since it is usually used to restrict a function to a certain set `s`,
we let the indicator function take the value `f x` for some function `f`, instead of `1`.
If the usual indicator function is needed, just set `f` to be the constant function `fun _ ↦ 1`.
The indicator function is implemented non-computably, to avoid having to pass around `Decidable`
arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`.
## Tags
indicator, characteristic
-/
assert_not_exists MonoidWithZero
open Function
variable {α β M N : Type*}
namespace Set
section One
variable [One M] [One N] {s t : Set α} {f g : α → M} {a : α}
/-- `Set.mulIndicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/
@[to_additive "`Set.indicator s f a` is `f a` if `a ∈ s`, `0` otherwise."]
noncomputable def mulIndicator (s : Set α) (f : α → M) (x : α) : M :=
haveI := Classical.decPred (· ∈ s)
if x ∈ s then f x else 1
@[to_additive (attr := simp)]
theorem piecewise_eq_mulIndicator [DecidablePred (· ∈ s)] : s.piecewise f 1 = s.mulIndicator f :=
funext fun _ => @if_congr _ _ _ _ (id _) _ _ _ _ Iff.rfl rfl rfl
@[to_additive]
theorem mulIndicator_apply (s : Set α) (f : α → M) (a : α) [Decidable (a ∈ s)] :
mulIndicator s f a = if a ∈ s then f a else 1 := by
unfold mulIndicator
congr
@[to_additive (attr := simp)]
theorem mulIndicator_of_mem (h : a ∈ s) (f : α → M) : mulIndicator s f a = f a :=
if_pos h
@[to_additive (attr := simp)]
theorem mulIndicator_of_not_mem (h : a ∉ s) (f : α → M) : mulIndicator s f a = 1 :=
if_neg h
@[to_additive]
theorem mulIndicator_eq_one_or_self (s : Set α) (f : α → M) (a : α) :
mulIndicator s f a = 1 ∨ mulIndicator s f a = f a := by
by_cases h : a ∈ s
· exact Or.inr (mulIndicator_of_mem h f)
· exact Or.inl (mulIndicator_of_not_mem h f)
@[to_additive (attr := simp)]
theorem mulIndicator_apply_eq_self : s.mulIndicator f a = f a ↔ a ∉ s → f a = 1 :=
letI := Classical.dec (a ∈ s)
ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)])
@[to_additive (attr := simp)]
theorem mulIndicator_eq_self : s.mulIndicator f = f ↔ mulSupport f ⊆ s := by
simp only [funext_iff, subset_def, mem_mulSupport, mulIndicator_apply_eq_self, not_imp_comm]
@[to_additive]
theorem mulIndicator_eq_self_of_superset (h1 : s.mulIndicator f = f) (h2 : s ⊆ t) :
t.mulIndicator f = f := by
rw [mulIndicator_eq_self] at h1 ⊢
exact Subset.trans h1 h2
@[to_additive (attr := simp)]
theorem mulIndicator_apply_eq_one : mulIndicator s f a = 1 ↔ a ∈ s → f a = 1 :=
letI := Classical.dec (a ∈ s)
ite_eq_right_iff
@[to_additive (attr := simp)]
theorem mulIndicator_eq_one : (mulIndicator s f = fun _ => 1) ↔ Disjoint (mulSupport f) s := by
simp only [funext_iff, mulIndicator_apply_eq_one, Set.disjoint_left, mem_mulSupport,
not_imp_not]
@[to_additive (attr := simp)]
theorem mulIndicator_eq_one' : mulIndicator s f = 1 ↔ Disjoint (mulSupport f) s :=
mulIndicator_eq_one
@[to_additive]
theorem mulIndicator_apply_ne_one {a : α} : s.mulIndicator f a ≠ 1 ↔ a ∈ s ∩ mulSupport f := by
simp only [Ne, mulIndicator_apply_eq_one, Classical.not_imp, mem_inter_iff, mem_mulSupport]
@[to_additive (attr := simp)]
theorem mulSupport_mulIndicator :
Function.mulSupport (s.mulIndicator f) = s ∩ Function.mulSupport f :=
ext fun x => by simp [Function.mem_mulSupport, mulIndicator_apply_eq_one]
/-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the
set. -/
@[to_additive
"If an additive indicator function is not equal to `0` at a point, then that point is
in the set."]
theorem mem_of_mulIndicator_ne_one (h : mulIndicator s f a ≠ 1) : a ∈ s :=
not_imp_comm.1 (fun hn => mulIndicator_of_not_mem hn f) h
/-- See `Set.eqOn_mulIndicator'` for the version with `sᶜ`. -/
@[to_additive
"See `Set.eqOn_indicator'` for the version with `sᶜ`"]
theorem eqOn_mulIndicator : EqOn (mulIndicator s f) f s := fun _ hx => mulIndicator_of_mem hx f
/-- See `Set.eqOn_mulIndicator` for the version with `s`. -/
@[to_additive
"See `Set.eqOn_indicator` for the version with `s`."]
theorem eqOn_mulIndicator' : EqOn (mulIndicator s f) 1 sᶜ :=
fun _ hx => mulIndicator_of_not_mem hx f
@[to_additive]
theorem mulSupport_mulIndicator_subset : mulSupport (s.mulIndicator f) ⊆ s := fun _ hx =>
hx.imp_symm fun h => mulIndicator_of_not_mem h f
@[to_additive (attr := simp)]
theorem mulIndicator_mulSupport : mulIndicator (mulSupport f) f = f :=
mulIndicator_eq_self.2 Subset.rfl
@[to_additive (attr := simp)]
theorem mulIndicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) :
mulIndicator (range f) g ∘ f = g ∘ f :=
letI := Classical.decPred (· ∈ range f)
piecewise_range_comp _ _ _
@[to_additive]
theorem mulIndicator_congr (h : EqOn f g s) : mulIndicator s f = mulIndicator s g :=
funext fun x => by
simp only [mulIndicator]
split_ifs with h_1
· exact h h_1
rfl
@[to_additive]
theorem mulIndicator_eq_mulIndicator {t : Set β} {g : β → M} {b : β}
(h1 : a ∈ s ↔ b ∈ t) (h2 : f a = g b) :
s.mulIndicator f a = t.mulIndicator g b := by
by_cases a ∈ s <;> simp_all
@[to_additive]
theorem mulIndicator_const_eq_mulIndicator_const {t : Set β} {b : β} {c : M} (h : a ∈ s ↔ b ∈ t) :
s.mulIndicator (fun _ ↦ c) a = t.mulIndicator (fun _ ↦ c) b :=
mulIndicator_eq_mulIndicator h rfl
@[to_additive (attr := simp)]
theorem mulIndicator_univ (f : α → M) : mulIndicator (univ : Set α) f = f :=
mulIndicator_eq_self.2 <| subset_univ _
@[to_additive (attr := simp)]
theorem mulIndicator_empty (f : α → M) : mulIndicator (∅ : Set α) f = fun _ => 1 :=
mulIndicator_eq_one.2 <| disjoint_empty _
@[to_additive]
theorem mulIndicator_empty' (f : α → M) : mulIndicator (∅ : Set α) f = 1 :=
mulIndicator_empty f
variable (M)
@[to_additive (attr := simp)]
theorem mulIndicator_one (s : Set α) : (mulIndicator s fun _ => (1 : M)) = fun _ => (1 : M) :=
mulIndicator_eq_one.2 <| by simp only [mulSupport_one, empty_disjoint]
@[to_additive (attr := simp)]
theorem mulIndicator_one' {s : Set α} : s.mulIndicator (1 : α → M) = 1 :=
mulIndicator_one M s
variable {M}
@[to_additive]
theorem mulIndicator_mulIndicator (s t : Set α) (f : α → M) :
mulIndicator s (mulIndicator t f) = mulIndicator (s ∩ t) f :=
funext fun x => by
simp only [mulIndicator]
split_ifs <;> simp_all +contextual
@[to_additive (attr := simp)]
theorem mulIndicator_inter_mulSupport (s : Set α) (f : α → M) :
mulIndicator (s ∩ mulSupport f) f = mulIndicator s f := by
rw [← mulIndicator_mulIndicator, mulIndicator_mulSupport]
@[to_additive]
theorem comp_mulIndicator (h : M → β) (f : α → M) {s : Set α} {x : α} [DecidablePred (· ∈ s)] :
h (s.mulIndicator f x) = s.piecewise (h ∘ f) (const α (h 1)) x := by
letI := Classical.decPred (· ∈ s)
convert s.apply_piecewise f (const α 1) (fun _ => h) (x := x) using 2
@[to_additive]
theorem mulIndicator_comp_right {s : Set α} (f : β → α) {g : α → M} {x : β} :
mulIndicator (f ⁻¹' s) (g ∘ f) x = mulIndicator s g (f x) := by
simp only [mulIndicator, Function.comp]
split_ifs with h h' h'' <;> first | rfl | contradiction
@[to_additive]
theorem mulIndicator_image {s : Set α} {f : β → M} {g : α → β} (hg : Injective g) {x : α} :
mulIndicator (g '' s) f (g x) = mulIndicator s (f ∘ g) x := by
rw [← mulIndicator_comp_right, preimage_image_eq _ hg]
@[to_additive]
theorem mulIndicator_comp_of_one {g : M → N} (hg : g 1 = 1) :
mulIndicator s (g ∘ f) = g ∘ mulIndicator s f := by
funext
simp only [mulIndicator]
split_ifs <;> simp [*]
@[to_additive]
theorem comp_mulIndicator_const (c : M) (f : M → N) (hf : f 1 = 1) :
(fun x => f (s.mulIndicator (fun _ => c) x)) = s.mulIndicator fun _ => f c :=
(mulIndicator_comp_of_one hf).symm
@[to_additive]
theorem mulIndicator_preimage (s : Set α) (f : α → M) (B : Set M) :
mulIndicator s f ⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) :=
letI := Classical.decPred (· ∈ s)
piecewise_preimage s f 1 B
@[to_additive]
theorem mulIndicator_one_preimage (s : Set M) :
t.mulIndicator 1 ⁻¹' s ∈ ({Set.univ, ∅} : Set (Set α)) := by
classical
rw [mulIndicator_one', preimage_one]
split_ifs <;> simp
@[to_additive]
theorem mulIndicator_const_preimage_eq_union (U : Set α) (s : Set M) (a : M) [Decidable (a ∈ s)]
[Decidable ((1 : M) ∈ s)] : (U.mulIndicator fun _ => a) ⁻¹' s =
(if a ∈ s then U else ∅) ∪ if (1 : M) ∈ s then Uᶜ else ∅ := by
rw [mulIndicator_preimage, preimage_one, preimage_const]
split_ifs <;> simp [← compl_eq_univ_diff]
@[to_additive]
theorem mulIndicator_const_preimage (U : Set α) (s : Set M) (a : M) :
(U.mulIndicator fun _ => a) ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) := by
classical
rw [mulIndicator_const_preimage_eq_union]
split_ifs <;> simp
theorem indicator_one_preimage [Zero M] (U : Set α) (s : Set M) :
U.indicator 1 ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) :=
indicator_const_preimage _ _ 1
@[to_additive]
theorem mulIndicator_preimage_of_not_mem (s : Set α) (f : α → M) {t : Set M} (ht : (1 : M) ∉ t) :
mulIndicator s f ⁻¹' t = f ⁻¹' t ∩ s := by
simp [mulIndicator_preimage, Pi.one_def, Set.preimage_const_of_not_mem ht]
@[to_additive]
theorem mem_range_mulIndicator {r : M} {s : Set α} {f : α → M} :
r ∈ range (mulIndicator s f) ↔ r = 1 ∧ s ≠ univ ∨ r ∈ f '' s := by
simp [mulIndicator, ite_eq_iff, exists_or, eq_univ_iff_forall, and_comm, or_comm,
@eq_comm _ r 1]
@[to_additive]
theorem mulIndicator_rel_mulIndicator {r : M → M → Prop} (h1 : r 1 1) (ha : a ∈ s → r (f a) (g a)) :
r (mulIndicator s f a) (mulIndicator s g a) := by
simp only [mulIndicator]
split_ifs with has
exacts [ha has, h1]
end One
section Monoid
variable [MulOneClass M] {s t : Set α} {a : α}
@[to_additive]
theorem mulIndicator_union_mul_inter_apply (f : α → M) (s t : Set α) (a : α) :
mulIndicator (s ∪ t) f a * mulIndicator (s ∩ t) f a
= mulIndicator s f a * mulIndicator t f a := by
by_cases hs : a ∈ s <;> by_cases ht : a ∈ t <;> simp [*]
@[to_additive]
theorem mulIndicator_union_mul_inter (f : α → M) (s t : Set α) :
mulIndicator (s ∪ t) f * mulIndicator (s ∩ t) f = mulIndicator s f * mulIndicator t f :=
funext <| mulIndicator_union_mul_inter_apply f s t
@[to_additive]
theorem mulIndicator_union_of_not_mem_inter (h : a ∉ s ∩ t) (f : α → M) :
mulIndicator (s ∪ t) f a = mulIndicator s f a * mulIndicator t f a := by
rw [← mulIndicator_union_mul_inter_apply f s t, mulIndicator_of_not_mem h, mul_one]
@[to_additive]
theorem mulIndicator_union_of_disjoint (h : Disjoint s t) (f : α → M) :
mulIndicator (s ∪ t) f = fun a => mulIndicator s f a * mulIndicator t f a :=
funext fun _ => mulIndicator_union_of_not_mem_inter (fun ha => h.le_bot ha) _
open scoped symmDiff in
@[to_additive]
theorem mulIndicator_symmDiff (s t : Set α) (f : α → M) :
mulIndicator (s ∆ t) f = mulIndicator (s \ t) f * mulIndicator (t \ s) f :=
mulIndicator_union_of_disjoint (disjoint_sdiff_self_right.mono_left sdiff_le) _
@[to_additive]
theorem mulIndicator_mul (s : Set α) (f g : α → M) :
(mulIndicator s fun a => f a * g a) = fun a => mulIndicator s f a * mulIndicator s g a := by
funext
simp only [mulIndicator]
split_ifs
· rfl
rw [mul_one]
@[to_additive]
theorem mulIndicator_mul' (s : Set α) (f g : α → M) :
mulIndicator s (f * g) = mulIndicator s f * mulIndicator s g :=
mulIndicator_mul s f g
@[to_additive (attr := simp)]
theorem mulIndicator_compl_mul_self_apply (s : Set α) (f : α → M) (a : α) :
mulIndicator sᶜ f a * mulIndicator s f a = f a :=
by_cases (fun ha : a ∈ s => by simp [ha]) fun ha => by simp [ha]
@[to_additive (attr := simp)]
theorem mulIndicator_compl_mul_self (s : Set α) (f : α → M) :
mulIndicator sᶜ f * mulIndicator s f = f :=
funext <| mulIndicator_compl_mul_self_apply s f
@[to_additive (attr := simp)]
theorem mulIndicator_self_mul_compl_apply (s : Set α) (f : α → M) (a : α) :
mulIndicator s f a * mulIndicator sᶜ f a = f a :=
by_cases (fun ha : a ∈ s => by simp [ha]) fun ha => by simp [ha]
@[to_additive (attr := simp)]
theorem mulIndicator_self_mul_compl (s : Set α) (f : α → M) :
mulIndicator s f * mulIndicator sᶜ f = f :=
funext <| mulIndicator_self_mul_compl_apply s f
@[to_additive]
| Mathlib/Algebra/Group/Indicator.lean | 348 | 351 | theorem mulIndicator_mul_eq_left {f g : α → M} (h : Disjoint (mulSupport f) (mulSupport g)) :
(mulSupport f).mulIndicator (f * g) = f := by | refine (mulIndicator_congr fun x hx => ?_).trans mulIndicator_mulSupport
have : g x = 1 := nmem_mulSupport.1 (disjoint_left.1 h hx) |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Robert Y. Lewis
-/
import Mathlib.Algebra.Order.CauSeq.Basic
import Mathlib.Algebra.Ring.Action.Rat
import Mathlib.Tactic.FastInstance
/-!
# Cauchy completion
This file generalizes the Cauchy completion of `(ℚ, abs)` to the completion of a ring
with absolute value.
-/
namespace CauSeq.Completion
open CauSeq
section
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
variable {β : Type*} [Ring β] (abv : β → α) [IsAbsoluteValue abv]
-- TODO: rename this to `CauSeq.Completion` instead of `CauSeq.Completion.Cauchy`.
/-- The Cauchy completion of a ring with absolute value. -/
def Cauchy :=
@Quotient (CauSeq _ abv) CauSeq.equiv
variable {abv}
/-- The map from Cauchy sequences into the Cauchy completion. -/
def mk : CauSeq _ abv → Cauchy abv :=
Quotient.mk''
@[simp]
theorem mk_eq_mk (f : CauSeq _ abv) : @Eq (Cauchy abv) ⟦f⟧ (mk f) :=
rfl
theorem mk_eq {f g : CauSeq _ abv} : mk f = mk g ↔ f ≈ g :=
Quotient.eq
/-- The map from the original ring into the Cauchy completion. -/
def ofRat (x : β) : Cauchy abv :=
mk (const abv x)
instance : Zero (Cauchy abv) :=
⟨ofRat 0⟩
instance : One (Cauchy abv) :=
⟨ofRat 1⟩
instance : Inhabited (Cauchy abv) :=
⟨0⟩
theorem ofRat_zero : (ofRat 0 : Cauchy abv) = 0 :=
rfl
theorem ofRat_one : (ofRat 1 : Cauchy abv) = 1 :=
rfl
@[simp]
theorem mk_eq_zero {f : CauSeq _ abv} : mk f = 0 ↔ LimZero f := by
have : mk f = 0 ↔ LimZero (f - 0) := Quotient.eq
rwa [sub_zero] at this
instance : Add (Cauchy abv) :=
⟨(Quotient.map₂ (· + ·)) fun _ _ hf _ _ hg => add_equiv_add hf hg⟩
@[simp]
theorem mk_add (f g : CauSeq β abv) : mk f + mk g = mk (f + g) :=
rfl
instance : Neg (Cauchy abv) :=
⟨(Quotient.map Neg.neg) fun _ _ hf => neg_equiv_neg hf⟩
@[simp]
theorem mk_neg (f : CauSeq β abv) : -mk f = mk (-f) :=
rfl
instance : Mul (Cauchy abv) :=
⟨(Quotient.map₂ (· * ·)) fun _ _ hf _ _ hg => mul_equiv_mul hf hg⟩
@[simp]
theorem mk_mul (f g : CauSeq β abv) : mk f * mk g = mk (f * g) :=
rfl
instance : Sub (Cauchy abv) :=
⟨(Quotient.map₂ Sub.sub) fun _ _ hf _ _ hg => sub_equiv_sub hf hg⟩
@[simp]
theorem mk_sub (f g : CauSeq β abv) : mk f - mk g = mk (f - g) :=
rfl
instance {γ : Type*} [SMul γ β] [IsScalarTower γ β β] : SMul γ (Cauchy abv) :=
⟨fun c => (Quotient.map (c • ·)) fun _ _ hf => smul_equiv_smul _ hf⟩
@[simp]
theorem mk_smul {γ : Type*} [SMul γ β] [IsScalarTower γ β β] (c : γ) (f : CauSeq β abv) :
c • mk f = mk (c • f) :=
rfl
instance : Pow (Cauchy abv) ℕ :=
⟨fun x n => Quotient.map (· ^ n) (fun _ _ hf => pow_equiv_pow hf _) x⟩
@[simp]
theorem mk_pow (n : ℕ) (f : CauSeq β abv) : mk f ^ n = mk (f ^ n) :=
rfl
instance : NatCast (Cauchy abv) :=
⟨fun n => mk n⟩
instance : IntCast (Cauchy abv) :=
⟨fun n => mk n⟩
@[simp]
theorem ofRat_natCast (n : ℕ) : (ofRat n : Cauchy abv) = n :=
rfl
@[simp]
theorem ofRat_intCast (z : ℤ) : (ofRat z : Cauchy abv) = z :=
rfl
theorem ofRat_add (x y : β) :
ofRat (x + y) = (ofRat x + ofRat y : Cauchy abv) :=
congr_arg mk (const_add _ _)
theorem ofRat_neg (x : β) : ofRat (-x) = (-ofRat x : Cauchy abv) :=
congr_arg mk (const_neg _)
theorem ofRat_mul (x y : β) :
ofRat (x * y) = (ofRat x * ofRat y : Cauchy abv) :=
congr_arg mk (const_mul _ _)
private theorem zero_def : 0 = mk (abv := abv) 0 :=
rfl
private theorem one_def : 1 = mk (abv := abv) 1 :=
rfl
instance Cauchy.ring : Ring (Cauchy abv) := fast_instance%
Function.Surjective.ring mk Quotient.mk'_surjective zero_def.symm one_def.symm
(fun _ _ => (mk_add _ _).symm) (fun _ _ => (mk_mul _ _).symm) (fun _ => (mk_neg _).symm)
(fun _ _ => (mk_sub _ _).symm) (fun _ _ => (mk_smul _ _).symm) (fun _ _ => (mk_smul _ _).symm)
(fun _ _ => (mk_pow _ _).symm) (fun _ => rfl) fun _ => rfl
/-- `CauSeq.Completion.ofRat` as a `RingHom` -/
@[simps]
def ofRatRingHom : β →+* (Cauchy abv) where
toFun := ofRat
map_zero' := ofRat_zero
map_one' := ofRat_one
map_add' := ofRat_add
map_mul' := ofRat_mul
theorem ofRat_sub (x y : β) : ofRat (x - y) = (ofRat x - ofRat y : Cauchy abv) :=
congr_arg mk (const_sub _ _)
end
section
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
variable {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv]
instance Cauchy.commRing : CommRing (Cauchy abv) := fast_instance%
Function.Surjective.commRing mk Quotient.mk'_surjective zero_def.symm one_def.symm
(fun _ _ => (mk_add _ _).symm) (fun _ _ => (mk_mul _ _).symm) (fun _ => (mk_neg _).symm)
(fun _ _ => (mk_sub _ _).symm) (fun _ _ => (mk_smul _ _).symm) (fun _ _ => (mk_smul _ _).symm)
(fun _ _ => (mk_pow _ _).symm) (fun _ => rfl) fun _ => rfl
end
section
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
variable {β : Type*} [DivisionRing β] {abv : β → α} [IsAbsoluteValue abv]
instance instNNRatCast : NNRatCast (Cauchy abv) where nnratCast q := ofRat q
instance instRatCast : RatCast (Cauchy abv) where ratCast q := ofRat q
@[simp, norm_cast] lemma ofRat_nnratCast (q : ℚ≥0) : ofRat (q : β) = (q : Cauchy abv) := rfl
@[simp, norm_cast] lemma ofRat_ratCast (q : ℚ) : ofRat (q : β) = (q : Cauchy abv) := rfl
open Classical in
noncomputable instance : Inv (Cauchy abv) :=
⟨fun x =>
(Quotient.liftOn x fun f => mk <| if h : LimZero f then 0 else inv f h) fun f g fg => by
have := limZero_congr fg
by_cases hf : LimZero f
· simp [hf, this.1 hf, Setoid.refl]
· have hg := mt this.2 hf
simp only [hf, dite_false, hg]
have If : mk (inv f hf) * mk f = 1 := mk_eq.2 (inv_mul_cancel hf)
have Ig : mk (inv g hg) * mk g = 1 := mk_eq.2 (inv_mul_cancel hg)
have Ig' : mk g * mk (inv g hg) = 1 := mk_eq.2 (mul_inv_cancel hg)
rw [mk_eq.2 fg, ← Ig] at If
rw [← mul_one (mk (inv f hf)), ← Ig', ← mul_assoc, If, mul_assoc, Ig', mul_one]⟩
theorem inv_zero : (0 : (Cauchy abv))⁻¹ = 0 :=
congr_arg mk <| by rw [dif_pos] <;> [rfl; exact zero_limZero]
@[simp]
theorem inv_mk {f} (hf) : (mk (abv := abv) f)⁻¹ = mk (inv f hf) :=
congr_arg mk <| by rw [dif_neg]
theorem cau_seq_zero_ne_one : ¬(0 : CauSeq _ abv) ≈ 1 := fun h =>
have : LimZero (1 - 0 : CauSeq _ abv) := Setoid.symm h
have : LimZero (1 : CauSeq _ abv) := by simpa
by apply one_ne_zero <| const_limZero.1 this
theorem zero_ne_one : (0 : (Cauchy abv)) ≠ 1 := fun h => cau_seq_zero_ne_one <| mk_eq.1 h
protected theorem inv_mul_cancel {x : (Cauchy abv)} : x ≠ 0 → x⁻¹ * x = 1 :=
Quotient.inductionOn x fun f hf => by
simp only [mk_eq_mk, ne_eq, mk_eq_zero] at hf
simp only [mk_eq_mk, hf, not_false_eq_true, inv_mk, mk_mul]
exact Quotient.sound (CauSeq.inv_mul_cancel hf)
protected theorem mul_inv_cancel {x : (Cauchy abv)} : x ≠ 0 → x * x⁻¹ = 1 :=
Quotient.inductionOn x fun f hf => by
simp only [mk_eq_mk, ne_eq, mk_eq_zero] at hf
simp only [mk_eq_mk, hf, not_false_eq_true, inv_mk, mk_mul]
exact Quotient.sound (CauSeq.mul_inv_cancel hf)
theorem ofRat_inv (x : β) : ofRat x⁻¹ = ((ofRat x)⁻¹ : (Cauchy abv)) :=
congr_arg mk <| by split_ifs with h <;>
[simp only [const_limZero.1 h, GroupWithZero.inv_zero, const_zero]; rfl]
noncomputable instance instDivInvMonoid : DivInvMonoid (Cauchy abv) where
lemma ofRat_div (x y : β) : ofRat (x / y) = (ofRat x / ofRat y : Cauchy abv) := by
simp only [div_eq_mul_inv, ofRat_inv, ofRat_mul]
/-- The Cauchy completion forms a division ring. -/
noncomputable instance Cauchy.divisionRing : DivisionRing (Cauchy abv) where
exists_pair_ne := ⟨0, 1, zero_ne_one⟩
inv_zero := inv_zero
mul_inv_cancel _ := CauSeq.Completion.mul_inv_cancel
nnqsmul := (· • ·)
qsmul := (· • ·)
nnratCast_def q := by simp_rw [← ofRat_nnratCast, NNRat.cast_def, ofRat_div, ofRat_natCast]
ratCast_def q := by rw [← ofRat_ratCast, Rat.cast_def, ofRat_div, ofRat_natCast, ofRat_intCast]
nnqsmul_def _ x := Quotient.inductionOn x fun _ ↦ congr_arg mk <| ext fun _ ↦ NNRat.smul_def _ _
qsmul_def _ x := Quotient.inductionOn x fun _ ↦ congr_arg mk <| ext fun _ ↦ Rat.smul_def _ _
/-- Show the first 10 items of a representative of this equivalence class of cauchy sequences.
The representative chosen is the one passed in the VM to `Quot.mk`, so two cauchy sequences
converging to the same number may be printed differently.
-/
unsafe instance [Repr β] : Repr (Cauchy abv) where
reprPrec r _ :=
let N := 10
let seq := r.unquot
"(sorry /- " ++ Std.Format.joinSep ((List.range N).map <| repr ∘ seq) ", " ++ ", ... -/)"
end
section
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
variable {β : Type*} [Field β] {abv : β → α} [IsAbsoluteValue abv]
/-- The Cauchy completion forms a field. -/
noncomputable instance Cauchy.field : Field (Cauchy abv) :=
{ Cauchy.divisionRing, Cauchy.commRing with }
end
end CauSeq.Completion
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
namespace CauSeq
section
variable (β : Type*) [Ring β] (abv : β → α) [IsAbsoluteValue abv]
/-- A class stating that a ring with an absolute value is complete, i.e. every Cauchy
sequence has a limit. -/
class IsComplete : Prop where
/-- Every Cauchy sequence has a limit. -/
isComplete : ∀ s : CauSeq β abv, ∃ b : β, s ≈ const abv b
end
section
variable {β : Type*} [Ring β] {abv : β → α} [IsAbsoluteValue abv]
variable [IsComplete β abv]
theorem complete : ∀ s : CauSeq β abv, ∃ b : β, s ≈ const abv b :=
IsComplete.isComplete
/-- The limit of a Cauchy sequence in a complete ring. Chosen non-computably. -/
noncomputable def lim (s : CauSeq β abv) : β :=
Classical.choose (complete s)
theorem equiv_lim (s : CauSeq β abv) : s ≈ const abv (lim s) :=
Classical.choose_spec (complete s)
theorem eq_lim_of_const_equiv {f : CauSeq β abv} {x : β} (h : CauSeq.const abv x ≈ f) : x = lim f :=
const_equiv.mp <| Setoid.trans h <| equiv_lim f
theorem lim_eq_of_equiv_const {f : CauSeq β abv} {x : β} (h : f ≈ CauSeq.const abv x) : lim f = x :=
(eq_lim_of_const_equiv <| Setoid.symm h).symm
theorem lim_eq_lim_of_equiv {f g : CauSeq β abv} (h : f ≈ g) : lim f = lim g :=
lim_eq_of_equiv_const <| Setoid.trans h <| equiv_lim g
@[simp]
theorem lim_const (x : β) : lim (const abv x) = x :=
lim_eq_of_equiv_const <| Setoid.refl _
theorem lim_add (f g : CauSeq β abv) : lim f + lim g = lim (f + g) :=
eq_lim_of_const_equiv <|
show LimZero (const abv (lim f + lim g) - (f + g)) by
rw [const_add, add_sub_add_comm]
exact add_limZero (Setoid.symm (equiv_lim f)) (Setoid.symm (equiv_lim g))
theorem lim_mul_lim (f g : CauSeq β abv) : lim f * lim g = lim (f * g) :=
eq_lim_of_const_equiv <|
show LimZero (const abv (lim f * lim g) - f * g) by
have h :
const abv (lim f * lim g) - f * g =
(const abv (lim f) - f) * g + const abv (lim f) * (const abv (lim g) - g) := by
apply Subtype.ext
rw [coe_add]
simp [sub_mul, mul_sub]
rw [h]
exact
add_limZero (mul_limZero_left _ (Setoid.symm (equiv_lim _)))
(mul_limZero_right _ (Setoid.symm (equiv_lim _)))
theorem lim_mul (f : CauSeq β abv) (x : β) : lim f * x = lim (f * const abv x) := by
rw [← lim_mul_lim, lim_const]
theorem lim_neg (f : CauSeq β abv) : lim (-f) = -lim f :=
lim_eq_of_equiv_const
(show LimZero (-f - const abv (-lim f)) by
rw [const_neg, sub_neg_eq_add, add_comm, ← sub_eq_add_neg]
exact Setoid.symm (equiv_lim f))
theorem lim_eq_zero_iff (f : CauSeq β abv) : lim f = 0 ↔ LimZero f :=
⟨fun h => by
have hf := equiv_lim f
rw [h] at hf
exact (limZero_congr hf).mpr (const_limZero.mpr rfl),
fun h => by
have h₁ : f = f - const abv 0 := ext fun n => by simp [sub_apply, const_apply]
rw [h₁] at h
exact lim_eq_of_equiv_const h⟩
end
section
variable {β : Type*} [Field β] {abv : β → α} [IsAbsoluteValue abv] [IsComplete β abv]
| Mathlib/Algebra/Order/CauSeq/Completion.lean | 364 | 368 | theorem lim_inv {f : CauSeq β abv} (hf : ¬LimZero f) : lim (inv f hf) = (lim f)⁻¹ :=
have hl : lim f ≠ 0 := by | rwa [← lim_eq_zero_iff] at hf
lim_eq_of_equiv_const <|
show LimZero (inv f hf - const abv (lim f)⁻¹) from
have h₁ : ∀ (g f : CauSeq β abv) (hf : ¬LimZero f), LimZero (g - f * inv f hf * g) := |
/-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Kim Morrison, Apurva Nakade, Yuyang Zhao
-/
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.SetTheory.PGame.Algebra
import Mathlib.Tactic.Abel
/-!
# Combinatorial games.
In this file we construct an instance `OrderedAddCommGroup SetTheory.Game`.
## Multiplication on pre-games
We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems
about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x ≈ y` does not
imply `x * z ≈ y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless,
the abelian group structure on games allows us to simplify many proofs for pre-games.
-/
-- Porting note: many definitions here are noncomputable as the compiler does not support PGame.rec
noncomputable section
namespace SetTheory
open Function PGame
universe u
-- Porting note: moved the setoid instance to PGame.lean
/-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from
two sets of combinatorial games that have been constructed at an earlier
stage. To do this in type theory, we say that a combinatorial pre-game is built
inductively from two families of combinatorial games indexed over any type
in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`,
reflecting that it is a proper class in ZFC.
A combinatorial game is then constructed by quotienting by the equivalence
`x ≈ y ↔ x ≤ y ∧ y ≤ x`. -/
abbrev Game :=
Quotient PGame.setoid
namespace Game
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11445): added this definition
/-- Negation of games. -/
instance : Neg Game where
neg := Quot.map Neg.neg <| fun _ _ => (neg_equiv_neg_iff).2
instance : Zero Game where zero := ⟦0⟧
instance : Add Game where
add := Quotient.map₂ HAdd.hAdd <| fun _ _ hx _ _ hy => PGame.add_congr hx hy
instance instAddCommGroupWithOneGame : AddCommGroupWithOne Game where
zero := ⟦0⟧
one := ⟦1⟧
add_zero := by
rintro ⟨x⟩
exact Quot.sound (add_zero_equiv x)
zero_add := by
rintro ⟨x⟩
exact Quot.sound (zero_add_equiv x)
add_assoc := by
rintro ⟨x⟩ ⟨y⟩ ⟨z⟩
exact Quot.sound add_assoc_equiv
neg_add_cancel := Quotient.ind <| fun x => Quot.sound (neg_add_cancel_equiv x)
add_comm := by
rintro ⟨x⟩ ⟨y⟩
exact Quot.sound add_comm_equiv
nsmul := nsmulRec
zsmul := zsmulRec
instance : Inhabited Game :=
⟨0⟩
theorem zero_def : (0 : Game) = ⟦0⟧ :=
rfl
instance instPartialOrderGame : PartialOrder Game where
le := Quotient.lift₂ (· ≤ ·) fun _ _ _ _ hx hy => propext (le_congr hx hy)
le_refl := by
rintro ⟨x⟩
exact le_refl x
le_trans := by
rintro ⟨x⟩ ⟨y⟩ ⟨z⟩
exact @le_trans _ _ x y z
le_antisymm := by
rintro ⟨x⟩ ⟨y⟩ h₁ h₂
apply Quot.sound
exact ⟨h₁, h₂⟩
lt := Quotient.lift₂ (· < ·) fun _ _ _ _ hx hy => propext (lt_congr hx hy)
lt_iff_le_not_le := by
rintro ⟨x⟩ ⟨y⟩
exact @lt_iff_le_not_le _ _ x y
/-- The less or fuzzy relation on games.
If `0 ⧏ x` (less or fuzzy with), then Left can win `x` as the first player. -/
def LF : Game → Game → Prop :=
Quotient.lift₂ PGame.LF fun _ _ _ _ hx hy => propext (lf_congr hx hy)
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
theorem not_le : ∀ {x y : Game}, ¬x ≤ y ↔ Game.LF y x := by
rintro ⟨x⟩ ⟨y⟩
exact PGame.not_le
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
| Mathlib/SetTheory/Game/Basic.lean | 112 | 114 | theorem not_lf : ∀ {x y : Game}, ¬Game.LF x y ↔ y ≤ x := by | rintro ⟨x⟩ ⟨y⟩
exact PGame.not_lf |
/-
Copyright (c) 2024 Emilie Burgun. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Emilie Burgun
-/
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Commute.Basic
import Mathlib.Dynamics.PeriodicPts.Defs
import Mathlib.GroupTheory.GroupAction.Defs
/-!
# Properties of `fixedPoints` and `fixedBy`
This module contains some useful properties of `MulAction.fixedPoints` and `MulAction.fixedBy`
that don't directly belong to `Mathlib.GroupTheory.GroupAction.Basic`.
## Main theorems
* `MulAction.fixedBy_mul`: `fixedBy α (g * h) ⊆ fixedBy α g ∪ fixedBy α h`
* `MulAction.fixedBy_conj` and `MulAction.smul_fixedBy`: the pointwise group action of `h` on
`fixedBy α g` is equal to the `fixedBy` set of the conjugation of `h` with `g`
(`fixedBy α (h * g * h⁻¹)`).
* `MulAction.set_mem_fixedBy_of_movedBy_subset` shows that if a set `s` is a superset of
`(fixedBy α g)ᶜ`, then the group action of `g` cannot send elements of `s` outside of `s`.
This is expressed as `s ∈ fixedBy (Set α) g`, and `MulAction.set_mem_fixedBy_iff` allows one
to convert the relationship back to `g • x ∈ s ↔ x ∈ s`.
* `MulAction.not_commute_of_disjoint_smul_movedBy` allows one to prove that `g` and `h`
do not commute from the disjointness of the `(fixedBy α g)ᶜ` set and `h • (fixedBy α g)ᶜ`,
which is a property used in the proof of Rubin's theorem.
The theorems above are also available for `AddAction`.
## Pointwise group action and `fixedBy (Set α) g`
Since `fixedBy α g = { x | g • x = x }` by definition, properties about the pointwise action of
a set `s : Set α` can be expressed using `fixedBy (Set α) g`.
To properly use theorems using `fixedBy (Set α) g`, you should `open Pointwise` in your file.
`s ∈ fixedBy (Set α) g` means that `g • s = s`, which is equivalent to say that
`∀ x, g • x ∈ s ↔ x ∈ s` (the translation can be done using `MulAction.set_mem_fixedBy_iff`).
`s ∈ fixedBy (Set α) g` is a weaker statement than `s ⊆ fixedBy α g`: the latter requires that
all points in `s` are fixed by `g`, whereas the former only requires that `g • x ∈ s`.
-/
namespace MulAction
open Pointwise
variable {α : Type*}
variable {G : Type*} [Group G] [MulAction G α]
variable {M : Type*} [Monoid M] [MulAction M α]
section FixedPoints
variable (α) in
/-- In a multiplicative group action, the points fixed by `g` are also fixed by `g⁻¹` -/
@[to_additive (attr := simp)
"In an additive group action, the points fixed by `g` are also fixed by `g⁻¹`"]
theorem fixedBy_inv (g : G) : fixedBy α g⁻¹ = fixedBy α g := by
ext
rw [mem_fixedBy, mem_fixedBy, inv_smul_eq_iff, eq_comm]
@[to_additive]
theorem smul_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} :
g • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by
rw [mem_fixedBy, smul_left_cancel_iff]
rfl
@[to_additive]
theorem smul_inv_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} :
g⁻¹ • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by
rw [← fixedBy_inv, smul_mem_fixedBy_iff_mem_fixedBy, fixedBy_inv]
@[to_additive minimalPeriod_eq_one_iff_fixedBy]
theorem minimalPeriod_eq_one_iff_fixedBy {a : α} {g : G} :
Function.minimalPeriod (fun x => g • x) a = 1 ↔ a ∈ fixedBy α g :=
Function.minimalPeriod_eq_one_iff_isFixedPt
variable (α) in
@[to_additive]
theorem fixedBy_subset_fixedBy_zpow (g : G) (j : ℤ) :
fixedBy α g ⊆ fixedBy α (g ^ j) := by
intro a a_in_fixedBy
rw [mem_fixedBy, zpow_smul_eq_iff_minimalPeriod_dvd,
minimalPeriod_eq_one_iff_fixedBy.mpr a_in_fixedBy, Int.natCast_one]
exact one_dvd j
variable (M α) in
@[to_additive (attr := simp)]
theorem fixedBy_one_eq_univ : fixedBy α (1 : M) = Set.univ :=
Set.eq_univ_iff_forall.mpr <| one_smul M
variable (α) in
@[to_additive]
| Mathlib/GroupTheory/GroupAction/FixedPoints.lean | 96 | 98 | theorem fixedBy_mul (m₁ m₂ : M) : fixedBy α m₁ ∩ fixedBy α m₂ ⊆ fixedBy α (m₁ * m₂) := by | intro a ⟨h₁, h₂⟩
rw [mem_fixedBy, mul_smul, h₂, h₁] |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Filter.Prod
/-!
# N-ary maps of filter
This file defines the binary and ternary maps of filters. This is mostly useful to define pointwise
operations on filters.
## Main declarations
* `Filter.map₂`: Binary map of filters.
## Notes
This file is very similar to `Data.Set.NAry`, `Data.Finset.NAry` and `Data.Option.NAry`. Please
keep them in sync.
-/
open Function Set
open Filter
namespace Filter
variable {α α' β β' γ γ' δ δ' ε ε' : Type*} {m : α → β → γ} {f f₁ f₂ : Filter α}
{g g₁ g₂ : Filter β} {h : Filter γ} {s : Set α} {t : Set β} {u : Set γ}
{a : α} {b : β}
/-- The image of a binary function `m : α → β → γ` as a function `Filter α → Filter β → Filter γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def map₂ (m : α → β → γ) (f : Filter α) (g : Filter β) : Filter γ :=
((f ×ˢ g).map (uncurry m)).copy { s | ∃ u ∈ f, ∃ v ∈ g, image2 m u v ⊆ s } fun _ ↦ by
simp only [mem_map, mem_prod_iff, image2_subset_iff, prod_subset_iff]; rfl
@[simp 900]
theorem mem_map₂_iff : u ∈ map₂ m f g ↔ ∃ s ∈ f, ∃ t ∈ g, image2 m s t ⊆ u :=
Iff.rfl
theorem image2_mem_map₂ (hs : s ∈ f) (ht : t ∈ g) : image2 m s t ∈ map₂ m f g :=
⟨_, hs, _, ht, Subset.rfl⟩
theorem map_prod_eq_map₂ (m : α → β → γ) (f : Filter α) (g : Filter β) :
Filter.map (fun p : α × β => m p.1 p.2) (f ×ˢ g) = map₂ m f g := by
rw [map₂, copy_eq, uncurry_def]
theorem map_prod_eq_map₂' (m : α × β → γ) (f : Filter α) (g : Filter β) :
Filter.map m (f ×ˢ g) = map₂ (fun a b => m (a, b)) f g :=
map_prod_eq_map₂ m.curry f g
@[simp]
theorem map₂_mk_eq_prod (f : Filter α) (g : Filter β) : map₂ Prod.mk f g = f ×ˢ g := by
simp only [← map_prod_eq_map₂, map_id']
-- lemma image2_mem_map₂_iff (hm : injective2 m) : image2 m s t ∈ map₂ m f g ↔ s ∈ f ∧ t ∈ g :=
-- ⟨by { rintro ⟨u, v, hu, hv, h⟩, rw image2_subset_image2_iff hm at h,
-- exact ⟨mem_of_superset hu h.1, mem_of_superset hv h.2⟩ }, fun h ↦ image2_mem_map₂ h.1 h.2⟩
@[gcongr]
theorem map₂_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : map₂ m f₁ g₁ ≤ map₂ m f₂ g₂ :=
fun _ ⟨s, hs, t, ht, hst⟩ => ⟨s, hf hs, t, hg ht, hst⟩
@[gcongr]
theorem map₂_mono_left (h : g₁ ≤ g₂) : map₂ m f g₁ ≤ map₂ m f g₂ :=
map₂_mono Subset.rfl h
@[gcongr]
theorem map₂_mono_right (h : f₁ ≤ f₂) : map₂ m f₁ g ≤ map₂ m f₂ g :=
map₂_mono h Subset.rfl
@[simp]
theorem le_map₂_iff {h : Filter γ} :
h ≤ map₂ m f g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → image2 m s t ∈ h :=
⟨fun H _ hs _ ht => H <| image2_mem_map₂ hs ht, fun H _ ⟨_, hs, _, ht, hu⟩ =>
mem_of_superset (H hs ht) hu⟩
@[simp]
theorem map₂_eq_bot_iff : map₂ m f g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by simp [← map_prod_eq_map₂]
@[simp]
theorem map₂_bot_left : map₂ m ⊥ g = ⊥ := map₂_eq_bot_iff.2 <| .inl rfl
@[simp]
theorem map₂_bot_right : map₂ m f ⊥ = ⊥ := map₂_eq_bot_iff.2 <| .inr rfl
@[simp]
| Mathlib/Order/Filter/NAry.lean | 91 | 91 | theorem map₂_neBot_iff : (map₂ m f g).NeBot ↔ f.NeBot ∧ g.NeBot := by | simp [neBot_iff, not_or] |
/-
Copyright (c) 2024 Jeremy Tan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Tan
-/
import Mathlib.Combinatorics.SimpleGraph.Clique
import Mathlib.Order.Partition.Equipartition
/-!
# Turán's theorem
In this file we prove Turán's theorem, the first important result of extremal graph theory,
which states that the `r + 1`-cliquefree graph on `n` vertices with the most edges is the complete
`r`-partite graph with part sizes as equal as possible (`turanGraph n r`).
The forward direction of the proof performs "Zykov symmetrisation", which first shows
constructively that non-adjacency is an equivalence relation in a maximal graph, so it must be
complete multipartite with the parts being the equivalence classes. Then basic manipulations
show that the graph is isomorphic to the Turán graph for the given parameters.
For the reverse direction we first show that a Turán-maximal graph exists, then transfer
the property through `turanGraph n r` using the isomorphism provided by the forward direction.
## Main declarations
* `SimpleGraph.IsTuranMaximal`: `G.IsTuranMaximal r` means that `G` has the most number of edges for
its number of vertices while still being `r + 1`-cliquefree.
* `SimpleGraph.turanGraph n r`: The canonical `r + 1`-cliquefree Turán graph on `n` vertices.
* `SimpleGraph.IsTuranMaximal.finpartition`: The result of Zykov symmetrisation, a finpartition of
the vertices such that two vertices are in the same part iff they are non-adjacent.
* `SimpleGraph.IsTuranMaximal.nonempty_iso_turanGraph`: The forward direction, an isomorphism
between `G` satisfying `G.IsTuranMaximal r` and `turanGraph n r`.
* `isTuranMaximal_of_iso`: the reverse direction, `G.IsTuranMaximal r` given the isomorphism.
* `isTuranMaximal_iff_nonempty_iso_turanGraph`: Turán's theorem in full.
## References
* https://en.wikipedia.org/wiki/Turán%27s_theorem
-/
open Finset
namespace SimpleGraph
variable {V : Type*} [Fintype V] {G : SimpleGraph V} [DecidableRel G.Adj] {n r : ℕ}
variable (G) in
/-- An `r + 1`-cliquefree graph is `r`-Turán-maximal if any other `r + 1`-cliquefree graph on
the same vertex set has the same or fewer number of edges. -/
def IsTuranMaximal (r : ℕ) : Prop :=
G.CliqueFree (r + 1) ∧ ∀ (H : SimpleGraph V) [DecidableRel H.Adj],
H.CliqueFree (r + 1) → #H.edgeFinset ≤ #G.edgeFinset
section Defs
variable {H : SimpleGraph V}
lemma IsTuranMaximal.le_iff_eq (hG : G.IsTuranMaximal r) (hH : H.CliqueFree (r + 1)) :
G ≤ H ↔ G = H := by
classical exact ⟨fun hGH ↦ edgeFinset_inj.1 <| eq_of_subset_of_card_le
(edgeFinset_subset_edgeFinset.2 hGH) (hG.2 _ hH), le_of_eq⟩
/-- The canonical `r + 1`-cliquefree Turán graph on `n` vertices. -/
def turanGraph (n r : ℕ) : SimpleGraph (Fin n) where Adj v w := v % r ≠ w % r
instance turanGraph.instDecidableRelAdj : DecidableRel (turanGraph n r).Adj := by
dsimp only [turanGraph]; infer_instance
@[simp]
lemma turanGraph_zero : turanGraph n 0 = ⊤ := by
ext a b; simp_rw [turanGraph, top_adj, Nat.mod_zero, not_iff_not, Fin.val_inj]
@[simp]
| Mathlib/Combinatorics/SimpleGraph/Turan.lean | 74 | 82 | theorem turanGraph_eq_top : turanGraph n r = ⊤ ↔ r = 0 ∨ n ≤ r := by | simp_rw [SimpleGraph.ext_iff, funext_iff, turanGraph, top_adj, eq_iff_iff, not_iff_not]
refine ⟨fun h ↦ ?_, ?_⟩
· contrapose! h
use ⟨0, (Nat.pos_of_ne_zero h.1).trans h.2⟩, ⟨r, h.2⟩
simp [h.1.symm]
· rintro (rfl | h) a b
· simp [Fin.val_inj]
· rw [Nat.mod_eq_of_lt (a.2.trans_le h), Nat.mod_eq_of_lt (b.2.trans_le h), Fin.val_inj] |
/-
Copyright (c) 2022 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Yury Kudryashov, Kevin H. Wilson, Heather Macbeth
-/
import Mathlib.Order.Filter.Tendsto
/-!
# Product and coproduct filters
In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product
of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and
`Filter.Tendsto Prod.snd l g`.
## Implementation details
The product filter cannot be defined using the monad structure on filters. For example:
```lean
F := do {x ← seq, y ← top, return (x, y)}
G := do {y ← top, x ← seq, return (x, y)}
```
hence:
```lean
s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s
s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s
```
Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`.
As product filter we want to have `F` as result.
## Notations
* `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`.
-/
open Set
open Filter
namespace Filter
variable {α β γ δ : Type*} {ι : Sort*}
section Prod
variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β}
theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g :=
inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht)
theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} :
s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by
constructor
· rintro ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, rfl⟩
exact ⟨s₁, hs₁, s₂, hs₂, fun p ⟨h, h'⟩ => ⟨hts₁ h, hts₂ h'⟩⟩
· rintro ⟨t₁, ht₁, t₂, ht₂, h⟩
exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h
@[simp]
theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by
simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint]
@[simp]
theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g :=
⟨fun h =>
let ⟨_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h
(prod_subset_prod_iff.1 H).elim
(fun ⟨hs's, ht't⟩ => ⟨mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h =>
h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e =>
absurd ht'e (nonempty_of_mem ht').ne_empty,
fun h => prod_mem_prod h.1 h.2⟩
theorem mem_prod_principal {s : Set (α × β)} :
s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by
rw [← @exists_mem_subset_iff _ f, mem_prod_iff]
refine exists_congr fun u => Iff.rfl.and ⟨?_, fun h => ⟨t, mem_principal_self t, ?_⟩⟩
· rintro ⟨v, v_in, hv⟩ a a_in b b_in
exact hv (mk_mem_prod a_in <| v_in b_in)
· rintro ⟨x, y⟩ ⟨hx, hy⟩
exact h hx y hy
theorem mem_prod_top {s : Set (α × β)} :
s ∈ f ×ˢ (⊤ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by
rw [← principal_univ, mem_prod_principal]
simp only [mem_univ, forall_true_left]
theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} :
(∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by
rw [eventually_iff, eventually_iff, mem_prod_principal]
simp only [mem_setOf_eq]
theorem comap_prod (f : α → β × γ) (b : Filter β) (c : Filter γ) :
comap f (b ×ˢ c) = comap (Prod.fst ∘ f) b ⊓ comap (Prod.snd ∘ f) c := by
rw [prod_eq_inf, comap_inf, Filter.comap_comap, Filter.comap_comap]
theorem comap_prodMap_prod (f : α → β) (g : γ → δ) (lb : Filter β) (ld : Filter δ) :
comap (Prod.map f g) (lb ×ˢ ld) = comap f lb ×ˢ comap g ld := by
simp [prod_eq_inf, comap_comap, Function.comp_def]
theorem prod_top : f ×ˢ (⊤ : Filter β) = f.comap Prod.fst := by
rw [prod_eq_inf, comap_top, inf_top_eq]
theorem top_prod : (⊤ : Filter α) ×ˢ g = g.comap Prod.snd := by
rw [prod_eq_inf, comap_top, top_inf_eq]
theorem sup_prod (f₁ f₂ : Filter α) (g : Filter β) : (f₁ ⊔ f₂) ×ˢ g = (f₁ ×ˢ g) ⊔ (f₂ ×ˢ g) := by
simp only [prod_eq_inf, comap_sup, inf_sup_right]
theorem prod_sup (f : Filter α) (g₁ g₂ : Filter β) : f ×ˢ (g₁ ⊔ g₂) = (f ×ˢ g₁) ⊔ (f ×ˢ g₂) := by
simp only [prod_eq_inf, comap_sup, inf_sup_left]
theorem eventually_prod_iff {p : α × β → Prop} :
(∀ᶠ x in f ×ˢ g, p x) ↔
∃ pa : α → Prop, (∀ᶠ x in f, pa x) ∧ ∃ pb : β → Prop, (∀ᶠ y in g, pb y) ∧
∀ {x}, pa x → ∀ {y}, pb y → p (x, y) := by
simpa only [Set.prod_subset_iff] using @mem_prod_iff α β p f g
theorem tendsto_fst : Tendsto Prod.fst (f ×ˢ g) f :=
tendsto_inf_left tendsto_comap
theorem tendsto_snd : Tendsto Prod.snd (f ×ˢ g) g :=
tendsto_inf_right tendsto_comap
/-- If a function tends to a product `g ×ˢ h` of filters, then its first component tends to
`g`. See also `Filter.Tendsto.fst_nhds` for the special case of converging to a point in a
product of two topological spaces. -/
theorem Tendsto.fst {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) :
Tendsto (fun a ↦ (m a).1) f g :=
tendsto_fst.comp H
/-- If a function tends to a product `g ×ˢ h` of filters, then its second component tends to
`h`. See also `Filter.Tendsto.snd_nhds` for the special case of converging to a point in a
product of two topological spaces. -/
theorem Tendsto.snd {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) :
Tendsto (fun a ↦ (m a).2) f h :=
tendsto_snd.comp H
theorem Tendsto.prodMk {h : Filter γ} {m₁ : α → β} {m₂ : α → γ}
(h₁ : Tendsto m₁ f g) (h₂ : Tendsto m₂ f h) : Tendsto (fun x => (m₁ x, m₂ x)) f (g ×ˢ h) :=
tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
@[deprecated (since := "2025-03-10")]
alias Tendsto.prod_mk := Tendsto.prodMk
theorem tendsto_prod_swap : Tendsto (Prod.swap : α × β → β × α) (f ×ˢ g) (g ×ˢ f) :=
tendsto_snd.prodMk tendsto_fst
theorem Eventually.prod_inl {la : Filter α} {p : α → Prop} (h : ∀ᶠ x in la, p x) (lb : Filter β) :
∀ᶠ x in la ×ˢ lb, p (x : α × β).1 :=
tendsto_fst.eventually h
theorem Eventually.prod_inr {lb : Filter β} {p : β → Prop} (h : ∀ᶠ x in lb, p x) (la : Filter α) :
∀ᶠ x in la ×ˢ lb, p (x : α × β).2 :=
tendsto_snd.eventually h
theorem Eventually.prod_mk {la : Filter α} {pa : α → Prop} (ha : ∀ᶠ x in la, pa x) {lb : Filter β}
{pb : β → Prop} (hb : ∀ᶠ y in lb, pb y) : ∀ᶠ p in la ×ˢ lb, pa (p : α × β).1 ∧ pb p.2 :=
(ha.prod_inl lb).and (hb.prod_inr la)
theorem EventuallyEq.prodMap {δ} {la : Filter α} {fa ga : α → γ} (ha : fa =ᶠ[la] ga)
{lb : Filter β} {fb gb : β → δ} (hb : fb =ᶠ[lb] gb) :
Prod.map fa fb =ᶠ[la ×ˢ lb] Prod.map ga gb :=
(Eventually.prod_mk ha hb).mono fun _ h => Prod.ext h.1 h.2
@[deprecated (since := "2025-03-10")]
alias EventuallyEq.prod_map := EventuallyEq.prodMap
theorem EventuallyLE.prodMap {δ} [LE γ] [LE δ] {la : Filter α} {fa ga : α → γ} (ha : fa ≤ᶠ[la] ga)
{lb : Filter β} {fb gb : β → δ} (hb : fb ≤ᶠ[lb] gb) :
Prod.map fa fb ≤ᶠ[la ×ˢ lb] Prod.map ga gb :=
Eventually.prod_mk ha hb
@[deprecated (since := "2025-03-10")]
alias EventuallyLE.prod_map := EventuallyLE.prodMap
theorem Eventually.curry {la : Filter α} {lb : Filter β} {p : α × β → Prop}
(h : ∀ᶠ x in la ×ˢ lb, p x) : ∀ᶠ x in la, ∀ᶠ y in lb, p (x, y) := by
rcases eventually_prod_iff.1 h with ⟨pa, ha, pb, hb, h⟩
exact ha.mono fun a ha => hb.mono fun b hb => h ha hb
protected lemma Frequently.uncurry {la : Filter α} {lb : Filter β} {p : α → β → Prop}
(h : ∃ᶠ x in la, ∃ᶠ y in lb, p x y) : ∃ᶠ xy in la ×ˢ lb, p xy.1 xy.2 :=
mt (fun h ↦ by simpa only [not_frequently] using h.curry) h
lemma Frequently.of_curry {la : Filter α} {lb : Filter β} {p : α × β → Prop}
(h : ∃ᶠ x in la, ∃ᶠ y in lb, p (x, y)) : ∃ᶠ xy in la ×ˢ lb, p xy :=
h.uncurry
/-- A fact that is eventually true about all pairs `l ×ˢ l` is eventually true about
all diagonal pairs `(i, i)` -/
theorem Eventually.diag_of_prod {p : α × α → Prop} (h : ∀ᶠ i in f ×ˢ f, p i) :
∀ᶠ i in f, p (i, i) := by
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
apply (ht.and hs).mono fun x hx => hst hx.1 hx.2
theorem Eventually.diag_of_prod_left {f : Filter α} {g : Filter γ} {p : (α × α) × γ → Prop} :
(∀ᶠ x in (f ×ˢ f) ×ˢ g, p x) → ∀ᶠ x : α × γ in f ×ˢ g, p ((x.1, x.1), x.2) := by
intro h
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
exact (ht.diag_of_prod.prod_mk hs).mono fun x hx => by simp only [hst hx.1 hx.2]
theorem Eventually.diag_of_prod_right {f : Filter α} {g : Filter γ} {p : α × γ × γ → Prop} :
(∀ᶠ x in f ×ˢ (g ×ˢ g), p x) → ∀ᶠ x : α × γ in f ×ˢ g, p (x.1, x.2, x.2) := by
intro h
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
exact (ht.prod_mk hs.diag_of_prod).mono fun x hx => by simp only [hst hx.1 hx.2]
theorem tendsto_diag : Tendsto (fun i => (i, i)) f (f ×ˢ f) :=
tendsto_iff_eventually.mpr fun _ hpr => hpr.diag_of_prod
theorem prod_iInf_left [Nonempty ι] {f : ι → Filter α} {g : Filter β} :
(⨅ i, f i) ×ˢ g = ⨅ i, f i ×ˢ g := by
simp only [prod_eq_inf, comap_iInf, iInf_inf]
theorem prod_iInf_right [Nonempty ι] {f : Filter α} {g : ι → Filter β} :
(f ×ˢ ⨅ i, g i) = ⨅ i, f ×ˢ g i := by
simp only [prod_eq_inf, comap_iInf, inf_iInf]
@[mono, gcongr]
theorem prod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ :=
inf_le_inf (comap_mono hf) (comap_mono hg)
@[gcongr]
theorem prod_mono_left (g : Filter β) {f₁ f₂ : Filter α} (hf : f₁ ≤ f₂) : f₁ ×ˢ g ≤ f₂ ×ˢ g :=
Filter.prod_mono hf rfl.le
@[gcongr]
theorem prod_mono_right (f : Filter α) {g₁ g₂ : Filter β} (hf : g₁ ≤ g₂) : f ×ˢ g₁ ≤ f ×ˢ g₂ :=
Filter.prod_mono rfl.le hf
theorem prod_comap_comap_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} :
comap m₁ f₁ ×ˢ comap m₂ f₂ = comap (fun p : β₁ × β₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := by
simp only [prod_eq_inf, comap_comap, comap_inf, Function.comp_def]
theorem prod_comm' : f ×ˢ g = comap Prod.swap (g ×ˢ f) := by
simp only [prod_eq_inf, comap_comap, Function.comp_def, inf_comm, Prod.swap, comap_inf]
theorem prod_comm : f ×ˢ g = map (fun p : β × α => (p.2, p.1)) (g ×ˢ f) := by
rw [prod_comm', ← map_swap_eq_comap_swap]
rfl
theorem mem_prod_iff_left {s : Set (α × β)} :
s ∈ f ×ˢ g ↔ ∃ t ∈ f, ∀ᶠ y in g, ∀ x ∈ t, (x, y) ∈ s := by
simp only [mem_prod_iff, prod_subset_iff]
refine exists_congr fun _ => Iff.rfl.and <| Iff.trans ?_ exists_mem_subset_iff
exact exists_congr fun _ => Iff.rfl.and forall₂_swap
theorem mem_prod_iff_right {s : Set (α × β)} :
s ∈ f ×ˢ g ↔ ∃ t ∈ g, ∀ᶠ x in f, ∀ y ∈ t, (x, y) ∈ s := by
rw [prod_comm, mem_map, mem_prod_iff_left]; rfl
@[simp]
theorem map_fst_prod (f : Filter α) (g : Filter β) [NeBot g] : map Prod.fst (f ×ˢ g) = f := by
ext s
simp only [mem_map, mem_prod_iff_left, mem_preimage, eventually_const, ← subset_def,
exists_mem_subset_iff]
@[simp]
theorem map_snd_prod (f : Filter α) (g : Filter β) [NeBot f] : map Prod.snd (f ×ˢ g) = g := by
rw [prod_comm, map_map]; apply map_fst_prod
@[simp]
theorem prod_le_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] :
f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ ↔ f₁ ≤ f₂ ∧ g₁ ≤ g₂ :=
⟨fun h =>
⟨map_fst_prod f₁ g₁ ▸ tendsto_fst.mono_left h, map_snd_prod f₁ g₁ ▸ tendsto_snd.mono_left h⟩,
fun h => prod_mono h.1 h.2⟩
@[simp]
theorem prod_inj {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] :
f₁ ×ˢ g₁ = f₂ ×ˢ g₂ ↔ f₁ = f₂ ∧ g₁ = g₂ := by
refine ⟨fun h => ?_, fun h => h.1 ▸ h.2 ▸ rfl⟩
have hle : f₁ ≤ f₂ ∧ g₁ ≤ g₂ := prod_le_prod.1 h.le
haveI := neBot_of_le hle.1; haveI := neBot_of_le hle.2
exact ⟨hle.1.antisymm <| (prod_le_prod.1 h.ge).1, hle.2.antisymm <| (prod_le_prod.1 h.ge).2⟩
theorem eventually_swap_iff {p : α × β → Prop} :
(∀ᶠ x : α × β in f ×ˢ g, p x) ↔ ∀ᶠ y : β × α in g ×ˢ f, p y.swap := by
rw [prod_comm]; rfl
theorem prod_assoc (f : Filter α) (g : Filter β) (h : Filter γ) :
map (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) = f ×ˢ (g ×ˢ h) := by
simp_rw [← comap_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc,
Function.comp_def, Equiv.prodAssoc_symm_apply]
theorem prod_assoc_symm (f : Filter α) (g : Filter β) (h : Filter γ) :
map (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) = (f ×ˢ g) ×ˢ h := by
simp_rw [map_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc,
Function.comp_def, Equiv.prodAssoc_apply]
theorem tendsto_prodAssoc {h : Filter γ} :
Tendsto (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) (f ×ˢ (g ×ˢ h)) :=
(prod_assoc f g h).le
theorem tendsto_prodAssoc_symm {h : Filter γ} :
Tendsto (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) ((f ×ˢ g) ×ˢ h) :=
(prod_assoc_symm f g h).le
/-- A useful lemma when dealing with uniformities. -/
theorem map_swap4_prod {h : Filter γ} {k : Filter δ} :
map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) =
(f ×ˢ h) ×ˢ (g ×ˢ k) := by
simp_rw [map_swap4_eq_comap, prod_eq_inf, comap_inf, comap_comap]; ac_rfl
theorem tendsto_swap4_prod {h : Filter γ} {k : Filter δ} :
Tendsto (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k))
((f ×ˢ h) ×ˢ (g ×ˢ k)) :=
map_swap4_prod.le
theorem prod_map_map_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} :
map m₁ f₁ ×ˢ map m₂ f₂ = map (fun p : α₁ × α₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) :=
le_antisymm
(fun s hs =>
let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs
mem_of_superset (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) <|
by rwa [prod_image_image_eq, image_subset_iff])
((tendsto_map.comp tendsto_fst).prodMk (tendsto_map.comp tendsto_snd))
theorem prod_map_map_eq' {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} (f : α₁ → α₂)
(g : β₁ → β₂) (F : Filter α₁) (G : Filter β₁) :
map f F ×ˢ map g G = map (Prod.map f g) (F ×ˢ G) :=
prod_map_map_eq
theorem prod_map_left (f : α → β) (F : Filter α) (G : Filter γ) :
map f F ×ˢ G = map (Prod.map f id) (F ×ˢ G) := by
rw [← prod_map_map_eq', map_id]
theorem prod_map_right (f : β → γ) (F : Filter α) (G : Filter β) :
F ×ˢ map f G = map (Prod.map id f) (F ×ˢ G) := by
rw [← prod_map_map_eq', map_id]
theorem le_prod_map_fst_snd {f : Filter (α × β)} : f ≤ map Prod.fst f ×ˢ map Prod.snd f :=
le_inf le_comap_map le_comap_map
theorem Tendsto.prodMap {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β}
{c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) :
Tendsto (Prod.map f g) (a ×ˢ b) (c ×ˢ d) := by
rw [Tendsto, Prod.map_def, ← prod_map_map_eq]
exact Filter.prod_mono hf hg
@[deprecated (since := "2025-03-10")]
alias Tendsto.prod_map := Tendsto.prodMap
protected theorem map_prod (m : α × β → γ) (f : Filter α) (g : Filter β) :
map m (f ×ˢ g) = (f.map fun a b => m (a, b)).seq g := by
simp only [Filter.ext_iff, mem_map, mem_prod_iff, mem_map_seq_iff, exists_and_left]
intro s
constructor
· exact fun ⟨t, ht, s, hs, h⟩ => ⟨s, hs, t, ht, fun x hx y hy => @h ⟨x, y⟩ ⟨hx, hy⟩⟩
· exact fun ⟨s, hs, t, ht, h⟩ => ⟨t, ht, s, hs, fun ⟨x, y⟩ ⟨hx, hy⟩ => h x hx y hy⟩
theorem prod_eq : f ×ˢ g = (f.map Prod.mk).seq g := f.map_prod id g
theorem prod_inf_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} :
(f₁ ×ˢ g₁) ⊓ (f₂ ×ˢ g₂) = (f₁ ⊓ f₂) ×ˢ (g₁ ⊓ g₂) := by
simp only [prod_eq_inf, comap_inf, inf_comm, inf_assoc, inf_left_comm]
theorem inf_prod {f₁ f₂ : Filter α} : (f₁ ⊓ f₂) ×ˢ g = (f₁ ×ˢ g) ⊓ (f₂ ×ˢ g) := by
rw [prod_inf_prod, inf_idem]
theorem prod_inf {g₁ g₂ : Filter β} : f ×ˢ (g₁ ⊓ g₂) = (f ×ˢ g₁) ⊓ (f ×ˢ g₂) := by
rw [prod_inf_prod, inf_idem]
@[simp]
theorem prod_principal_principal {s : Set α} {t : Set β} : 𝓟 s ×ˢ 𝓟 t = 𝓟 (s ×ˢ t) := by
simp only [prod_eq_inf, comap_principal, principal_eq_iff_eq, comap_principal, inf_principal]; rfl
@[simp]
theorem pure_prod {a : α} {f : Filter β} : pure a ×ˢ f = map (Prod.mk a) f := by
rw [prod_eq, map_pure, pure_seq_eq_map]
theorem map_pure_prod (f : α → β → γ) (a : α) (B : Filter β) :
map (Function.uncurry f) (pure a ×ˢ B) = map (f a) B := by
rw [Filter.pure_prod]; rfl
@[simp]
theorem prod_pure {b : β} : f ×ˢ pure b = map (fun a => (a, b)) f := by
rw [prod_eq, seq_pure, map_map]; rfl
theorem prod_pure_pure {a : α} {b : β} :
(pure a : Filter α) ×ˢ (pure b : Filter β) = pure (a, b) := by simp
@[simp]
theorem prod_eq_bot : f ×ˢ g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by
simp_rw [← empty_mem_iff_bot, mem_prod_iff, subset_empty_iff, prod_eq_empty_iff, ← exists_prop,
Subtype.exists', exists_or, exists_const, Subtype.exists, exists_prop, exists_eq_right]
@[simp] theorem prod_bot : f ×ˢ (⊥ : Filter β) = ⊥ := prod_eq_bot.2 <| Or.inr rfl
@[simp] theorem bot_prod : (⊥ : Filter α) ×ˢ g = ⊥ := prod_eq_bot.2 <| Or.inl rfl
theorem prod_neBot : NeBot (f ×ˢ g) ↔ NeBot f ∧ NeBot g := by
simp only [neBot_iff, Ne, prod_eq_bot, not_or]
protected theorem NeBot.prod (hf : NeBot f) (hg : NeBot g) : NeBot (f ×ˢ g) := prod_neBot.2 ⟨hf, hg⟩
instance prod.instNeBot [hf : NeBot f] [hg : NeBot g] : NeBot (f ×ˢ g) := hf.prod hg
@[simp]
lemma disjoint_prod {f' : Filter α} {g' : Filter β} :
Disjoint (f ×ˢ g) (f' ×ˢ g') ↔ Disjoint f f' ∨ Disjoint g g' := by
simp only [disjoint_iff, prod_inf_prod, prod_eq_bot]
/-- `p ∧ q` occurs frequently along the product of two filters
iff both `p` and `q` occur frequently along the corresponding filters. -/
theorem frequently_prod_and {p : α → Prop} {q : β → Prop} :
(∃ᶠ x in f ×ˢ g, p x.1 ∧ q x.2) ↔ (∃ᶠ a in f, p a) ∧ ∃ᶠ b in g, q b := by
simp only [frequently_iff_neBot, ← prod_neBot, ← prod_inf_prod, prod_principal_principal]
rfl
theorem tendsto_prod_iff {f : α × β → γ} {x : Filter α} {y : Filter β} {z : Filter γ} :
Tendsto f (x ×ˢ y) z ↔ ∀ W ∈ z, ∃ U ∈ x, ∃ V ∈ y, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W := by
simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff, exists_prop]
theorem tendsto_prod_iff' {g' : Filter γ} {s : α → β × γ} :
Tendsto s f (g ×ˢ g') ↔ Tendsto (fun n => (s n).1) f g ∧ Tendsto (fun n => (s n).2) f g' := by
simp only [prod_eq_inf, tendsto_inf, tendsto_comap_iff, Function.comp_def]
theorem le_prod {f : Filter (α × β)} {g : Filter α} {g' : Filter β} :
(f ≤ g ×ˢ g') ↔ Tendsto Prod.fst f g ∧ Tendsto Prod.snd f g' :=
tendsto_prod_iff'
end Prod
/-! ### Coproducts of filters -/
section Coprod
variable {f : Filter α} {g : Filter β}
theorem coprod_eq_prod_top_sup_top_prod (f : Filter α) (g : Filter β) :
Filter.coprod f g = f ×ˢ ⊤ ⊔ ⊤ ×ˢ g := by
rw [prod_top, top_prod]
rfl
theorem mem_coprod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} :
s ∈ f.coprod g ↔ (∃ t₁ ∈ f, Prod.fst ⁻¹' t₁ ⊆ s) ∧ ∃ t₂ ∈ g, Prod.snd ⁻¹' t₂ ⊆ s := by
simp [Filter.coprod]
@[simp]
theorem bot_coprod (l : Filter β) : (⊥ : Filter α).coprod l = comap Prod.snd l := by
simp [Filter.coprod]
@[simp]
theorem coprod_bot (l : Filter α) : l.coprod (⊥ : Filter β) = comap Prod.fst l := by
simp [Filter.coprod]
| Mathlib/Order/Filter/Prod.lean | 452 | 453 | theorem bot_coprod_bot : (⊥ : Filter α).coprod (⊥ : Filter β) = ⊥ := by | simp |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Algebra.Order.Interval.Set.Group
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.Convex.Segment
import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional
import Mathlib.Tactic.FieldSimp
/-!
# Betweenness in affine spaces
This file defines notions of a point in an affine space being between two given points.
## Main definitions
* `affineSegment R x y`: The segment of points weakly between `x` and `y`.
* `Wbtw R x y z`: The point `y` is weakly between `x` and `z`.
* `Sbtw R x y z`: The point `y` is strictly between `x` and `z`.
-/
variable (R : Type*) {V V' P P' : Type*}
open AffineEquiv AffineMap
section OrderedRing
/-- The segment of points weakly between `x` and `y`. When convexity is refactored to support
abstract affine combination spaces, this will no longer need to be a separate definition from
`segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a
refactoring, as distinct from versions involving `+` or `-` in a module. -/
def affineSegment [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V]
[AddTorsor V P] (x y : P) :=
lineMap x y '' Set.Icc (0 : R) 1
variable [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P]
variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
variable {R} in
@[simp]
theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) :
f '' affineSegment R x y = affineSegment R (f x) (f y) := by
rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap]
rfl
@[simp]
theorem affineSegment_const_vadd_image (x y : P) (v : V) :
(v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) :=
affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y
@[simp]
theorem affineSegment_vadd_const_image (x y : V) (p : P) :
(· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) :=
affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y
@[simp]
theorem affineSegment_const_vsub_image (x y p : P) :
(p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) :=
affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y
@[simp]
theorem affineSegment_vsub_const_image (x y p : P) :
(· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) :=
affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y
variable {R}
@[simp]
theorem mem_const_vadd_affineSegment {x y z : P} (v : V) :
v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image]
@[simp]
theorem mem_vadd_const_affineSegment {x y z : V} (p : P) :
z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image]
@[simp]
theorem mem_const_vsub_affineSegment {x y z : P} (p : P) :
p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image]
@[simp]
theorem mem_vsub_const_affineSegment {x y z : P} (p : P) :
z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image]
variable (R)
section OrderedRing
variable [IsOrderedRing R]
theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by
rw [segment_eq_image_lineMap, affineSegment]
theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by
refine Set.ext fun z => ?_
constructor <;>
· rintro ⟨t, ht, hxy⟩
refine ⟨1 - t, ?_, ?_⟩
· rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero]
· rwa [lineMap_apply_one_sub]
theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y :=
⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩
theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y :=
⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩
@[simp]
theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by
simp_rw [affineSegment, lineMap_same, AffineMap.coe_const, Function.const,
(Set.nonempty_Icc.mpr zero_le_one).image_const]
end OrderedRing
/-- The point `y` is weakly between `x` and `z`. -/
def Wbtw (x y z : P) : Prop :=
y ∈ affineSegment R x z
/-- The point `y` is strictly between `x` and `z`. -/
def Sbtw (x y z : P) : Prop :=
Wbtw R x y z ∧ y ≠ x ∧ y ≠ z
variable {R}
section OrderedRing
variable [IsOrderedRing R]
lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by
rw [Wbtw, affineSegment_eq_segment]
alias ⟨_, Wbtw.mem_segment⟩ := mem_segment_iff_wbtw
lemma Convex.mem_of_wbtw {p₀ p₁ p₂ : V} {s : Set V} (hs : Convex R s) (h₀₁₂ : Wbtw R p₀ p₁ p₂)
(h₀ : p₀ ∈ s) (h₂ : p₂ ∈ s) : p₁ ∈ s := hs.segment_subset h₀ h₂ h₀₁₂.mem_segment
theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by
rw [Wbtw, Wbtw, affineSegment_comm]
alias ⟨Wbtw.symm, _⟩ := wbtw_comm
theorem sbtw_comm {x y z : P} : Sbtw R x y z ↔ Sbtw R z y x := by
rw [Sbtw, Sbtw, wbtw_comm, ← and_assoc, ← and_assoc, and_right_comm]
alias ⟨Sbtw.symm, _⟩ := sbtw_comm
end OrderedRing
lemma AffineSubspace.mem_of_wbtw {s : AffineSubspace R P} {x y z : P} (hxyz : Wbtw R x y z)
(hx : x ∈ s) (hz : z ∈ s) : y ∈ s := by obtain ⟨ε, -, rfl⟩ := hxyz; exact lineMap_mem _ hx hz
theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by
rw [Wbtw, ← affineSegment_image]
exact Set.mem_image_of_mem _ h
theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) :
Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h
theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) :
Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by
simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff]
@[simp]
theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') :
Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by
have : Function.Injective f.toAffineMap := f.injective
-- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing.
apply this.wbtw_map_iff
@[simp]
theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') :
Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by
have : Function.Injective f.toAffineMap := f.injective
-- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing.
apply this.sbtw_map_iff
@[simp]
theorem wbtw_const_vadd_iff {x y z : P} (v : V) :
Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z :=
mem_const_vadd_affineSegment _
@[simp]
theorem wbtw_vadd_const_iff {x y z : V} (p : P) :
Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z :=
mem_vadd_const_affineSegment _
@[simp]
theorem wbtw_const_vsub_iff {x y z : P} (p : P) :
Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z :=
mem_const_vsub_affineSegment _
@[simp]
theorem wbtw_vsub_const_iff {x y z : P} (p : P) :
Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z :=
mem_vsub_const_affineSegment _
@[simp]
theorem sbtw_const_vadd_iff {x y z : P} (v : V) :
Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff,
(AddAction.injective v).ne_iff]
@[simp]
theorem sbtw_vadd_const_iff {x y z : V} (p : P) :
Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff,
(vadd_right_injective p).ne_iff]
@[simp]
theorem sbtw_const_vsub_iff {x y z : P} (p : P) :
Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff,
(vsub_right_injective p).ne_iff]
@[simp]
theorem sbtw_vsub_const_iff {x y z : P} (p : P) :
Sbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_vsub_const_iff, (vsub_left_injective p).ne_iff,
(vsub_left_injective p).ne_iff]
theorem Sbtw.wbtw {x y z : P} (h : Sbtw R x y z) : Wbtw R x y z :=
h.1
theorem Sbtw.ne_left {x y z : P} (h : Sbtw R x y z) : y ≠ x :=
h.2.1
theorem Sbtw.left_ne {x y z : P} (h : Sbtw R x y z) : x ≠ y :=
h.2.1.symm
theorem Sbtw.ne_right {x y z : P} (h : Sbtw R x y z) : y ≠ z :=
h.2.2
theorem Sbtw.right_ne {x y z : P} (h : Sbtw R x y z) : z ≠ y :=
h.2.2.symm
theorem Sbtw.mem_image_Ioo {x y z : P} (h : Sbtw R x y z) :
y ∈ lineMap x z '' Set.Ioo (0 : R) 1 := by
rcases h with ⟨⟨t, ht, rfl⟩, hyx, hyz⟩
rcases Set.eq_endpoints_or_mem_Ioo_of_mem_Icc ht with (rfl | rfl | ho)
· exfalso
exact hyx (lineMap_apply_zero _ _)
· exfalso
exact hyz (lineMap_apply_one _ _)
· exact ⟨t, ho, rfl⟩
theorem Wbtw.mem_affineSpan {x y z : P} (h : Wbtw R x y z) : y ∈ line[R, x, z] := by
rcases h with ⟨r, ⟨-, rfl⟩⟩
exact lineMap_mem_affineSpan_pair _ _ _
variable (R)
section OrderedRing
variable [IsOrderedRing R]
@[simp]
theorem wbtw_self_left (x y : P) : Wbtw R x x y :=
left_mem_affineSegment _ _ _
@[simp]
theorem wbtw_self_right (x y : P) : Wbtw R x y y :=
right_mem_affineSegment _ _ _
@[simp]
theorem wbtw_self_iff {x y : P} : Wbtw R x y x ↔ y = x := by
refine ⟨fun h => ?_, fun h => ?_⟩
· simpa [Wbtw, affineSegment] using h
· rw [h]
exact wbtw_self_left R x x
end OrderedRing
@[simp]
theorem not_sbtw_self_left (x y : P) : ¬Sbtw R x x y :=
fun h => h.ne_left rfl
@[simp]
theorem not_sbtw_self_right (x y : P) : ¬Sbtw R x y y :=
fun h => h.ne_right rfl
variable {R}
variable [IsOrderedRing R]
theorem Wbtw.left_ne_right_of_ne_left {x y z : P} (h : Wbtw R x y z) (hne : y ≠ x) : x ≠ z := by
rintro rfl
rw [wbtw_self_iff] at h
exact hne h
theorem Wbtw.left_ne_right_of_ne_right {x y z : P} (h : Wbtw R x y z) (hne : y ≠ z) : x ≠ z := by
rintro rfl
rw [wbtw_self_iff] at h
exact hne h
theorem Sbtw.left_ne_right {x y z : P} (h : Sbtw R x y z) : x ≠ z :=
h.wbtw.left_ne_right_of_ne_left h.2.1
theorem sbtw_iff_mem_image_Ioo_and_ne [NoZeroSMulDivisors R V] {x y z : P} :
Sbtw R x y z ↔ y ∈ lineMap x z '' Set.Ioo (0 : R) 1 ∧ x ≠ z := by
refine ⟨fun h => ⟨h.mem_image_Ioo, h.left_ne_right⟩, fun h => ?_⟩
rcases h with ⟨⟨t, ht, rfl⟩, hxz⟩
refine ⟨⟨t, Set.mem_Icc_of_Ioo ht, rfl⟩, ?_⟩
rw [lineMap_apply, ← @vsub_ne_zero V, ← @vsub_ne_zero V _ _ _ _ z, vadd_vsub_assoc, vsub_self,
vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z x, ← @neg_one_smul R, ← add_smul, ← sub_eq_add_neg]
simp [smul_ne_zero, sub_eq_zero, ht.1.ne.symm, ht.2.ne, hxz.symm]
variable (R)
@[simp]
theorem not_sbtw_self (x y : P) : ¬Sbtw R x y x :=
fun h => h.left_ne_right rfl
theorem wbtw_swap_left_iff [NoZeroSMulDivisors R V] {x y : P} (z : P) :
Wbtw R x y z ∧ Wbtw R y x z ↔ x = y := by
constructor
· rintro ⟨hxyz, hyxz⟩
rcases hxyz with ⟨ty, hty, rfl⟩
rcases hyxz with ⟨tx, htx, hx⟩
rw [lineMap_apply, lineMap_apply, ← add_vadd] at hx
rw [← @vsub_eq_zero_iff_eq V, vadd_vsub, vsub_vadd_eq_vsub_sub, smul_sub, smul_smul, ← sub_smul,
← add_smul, smul_eq_zero] at hx
rcases hx with (h | h)
· nth_rw 1 [← mul_one tx] at h
rw [← mul_sub, add_eq_zero_iff_neg_eq] at h
have h' : ty = 0 := by
refine le_antisymm ?_ hty.1
rw [← h, Left.neg_nonpos_iff]
exact mul_nonneg htx.1 (sub_nonneg.2 hty.2)
simp [h']
· rw [vsub_eq_zero_iff_eq] at h
rw [h, lineMap_same_apply]
· rintro rfl
exact ⟨wbtw_self_left _ _ _, wbtw_self_left _ _ _⟩
theorem wbtw_swap_right_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} :
Wbtw R x y z ∧ Wbtw R x z y ↔ y = z := by
rw [wbtw_comm, wbtw_comm (z := y), eq_comm]
exact wbtw_swap_left_iff R x
theorem wbtw_rotate_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} :
Wbtw R x y z ∧ Wbtw R z x y ↔ x = y := by rw [wbtw_comm, wbtw_swap_right_iff, eq_comm]
variable {R}
theorem Wbtw.swap_left_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R y x z ↔ x = y := by rw [← wbtw_swap_left_iff R z, and_iff_right h]
theorem Wbtw.swap_right_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R x z y ↔ y = z := by rw [← wbtw_swap_right_iff R x, and_iff_right h]
theorem Wbtw.rotate_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R z x y ↔ x = y := by rw [← wbtw_rotate_iff R x, and_iff_right h]
theorem Sbtw.not_swap_left [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) :
¬Wbtw R y x z := fun hs => h.left_ne (h.wbtw.swap_left_iff.1 hs)
theorem Sbtw.not_swap_right [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) :
¬Wbtw R x z y := fun hs => h.ne_right (h.wbtw.swap_right_iff.1 hs)
theorem Sbtw.not_rotate [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R z x y :=
fun hs => h.left_ne (h.wbtw.rotate_iff.1 hs)
@[simp]
theorem wbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} :
Wbtw R x (lineMap x y r) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := by
by_cases hxy : x = y
· rw [hxy, lineMap_same_apply]
simp
rw [or_iff_right hxy, Wbtw, affineSegment, (lineMap_injective R hxy).mem_set_image]
@[simp]
theorem sbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} :
Sbtw R x (lineMap x y r) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := by
rw [sbtw_iff_mem_image_Ioo_and_ne, and_comm, and_congr_right]
intro hxy
rw [(lineMap_injective R hxy).mem_set_image]
@[simp]
theorem wbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} :
Wbtw R x (r * (y - x) + x) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 :=
wbtw_lineMap_iff
@[simp]
theorem sbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} :
Sbtw R x (r * (y - x) + x) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 :=
sbtw_lineMap_iff
omit [IsOrderedRing R] in
@[simp]
theorem wbtw_zero_one_iff {x : R} : Wbtw R 0 x 1 ↔ x ∈ Set.Icc (0 : R) 1 := by
rw [Wbtw, affineSegment, Set.mem_image]
simp_rw [lineMap_apply_ring]
simp
@[simp]
theorem wbtw_one_zero_iff {x : R} : Wbtw R 1 x 0 ↔ x ∈ Set.Icc (0 : R) 1 := by
rw [wbtw_comm, wbtw_zero_one_iff]
omit [IsOrderedRing R] in
@[simp]
theorem sbtw_zero_one_iff {x : R} : Sbtw R 0 x 1 ↔ x ∈ Set.Ioo (0 : R) 1 := by
rw [Sbtw, wbtw_zero_one_iff, Set.mem_Icc, Set.mem_Ioo]
exact
⟨fun h => ⟨h.1.1.lt_of_ne (Ne.symm h.2.1), h.1.2.lt_of_ne h.2.2⟩, fun h =>
⟨⟨h.1.le, h.2.le⟩, h.1.ne', h.2.ne⟩⟩
@[simp]
theorem sbtw_one_zero_iff {x : R} : Sbtw R 1 x 0 ↔ x ∈ Set.Ioo (0 : R) 1 := by
rw [sbtw_comm, sbtw_zero_one_iff]
theorem Wbtw.trans_left {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) : Wbtw R w x z := by
rcases h₁ with ⟨t₁, ht₁, rfl⟩
rcases h₂ with ⟨t₂, ht₂, rfl⟩
refine ⟨t₂ * t₁, ⟨mul_nonneg ht₂.1 ht₁.1, mul_le_one₀ ht₂.2 ht₁.1 ht₁.2⟩, ?_⟩
rw [lineMap_apply, lineMap_apply, lineMap_vsub_left, smul_smul]
theorem Wbtw.trans_right {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) : Wbtw R w y z := by
rw [wbtw_comm] at *
exact h₁.trans_left h₂
theorem Wbtw.trans_sbtw_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z)
(h₂ : Sbtw R w x y) : Sbtw R w x z := by
refine ⟨h₁.trans_left h₂.wbtw, h₂.ne_left, ?_⟩
rintro rfl
exact h₂.right_ne ((wbtw_swap_right_iff R w).1 ⟨h₁, h₂.wbtw⟩)
theorem Wbtw.trans_sbtw_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z)
(h₂ : Sbtw R x y z) : Sbtw R w y z := by
rw [wbtw_comm] at *
rw [sbtw_comm] at *
exact h₁.trans_sbtw_left h₂
theorem Sbtw.trans_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z)
(h₂ : Sbtw R w x y) : Sbtw R w x z :=
h₁.wbtw.trans_sbtw_left h₂
theorem Sbtw.trans_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z)
(h₂ : Sbtw R x y z) : Sbtw R w y z :=
h₁.wbtw.trans_sbtw_right h₂
theorem Wbtw.trans_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z)
(h₂ : Wbtw R w x y) (h : y ≠ z) : x ≠ z := by
rintro rfl
exact h (h₁.swap_right_iff.1 h₂)
theorem Wbtw.trans_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z)
(h₂ : Wbtw R x y z) (h : w ≠ x) : w ≠ y := by
rintro rfl
exact h (h₁.swap_left_iff.1 h₂)
theorem Sbtw.trans_wbtw_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z)
(h₂ : Wbtw R w x y) : x ≠ z :=
h₁.wbtw.trans_left_ne h₂ h₁.ne_right
theorem Sbtw.trans_wbtw_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z)
(h₂ : Wbtw R x y z) : w ≠ y :=
h₁.wbtw.trans_right_ne h₂ h₁.left_ne
theorem Sbtw.affineCombination_of_mem_affineSpan_pair [NoZeroDivisors R] [NoZeroSMulDivisors R V]
{ι : Type*} {p : ι → P} (ha : AffineIndependent R p) {w w₁ w₂ : ι → R} {s : Finset ι}
(hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1)
(h : s.affineCombination R p w ∈
line[R, s.affineCombination R p w₁, s.affineCombination R p w₂])
{i : ι} (his : i ∈ s) (hs : Sbtw R (w₁ i) (w i) (w₂ i)) :
Sbtw R (s.affineCombination R p w₁) (s.affineCombination R p w)
(s.affineCombination R p w₂) := by
rw [affineCombination_mem_affineSpan_pair ha hw hw₁ hw₂] at h
rcases h with ⟨r, hr⟩
rw [hr i his, sbtw_mul_sub_add_iff] at hs
change ∀ i ∈ s, w i = (r • (w₂ - w₁) + w₁) i at hr
rw [s.affineCombination_congr hr fun _ _ => rfl]
rw [← s.weightedVSub_vadd_affineCombination, s.weightedVSub_const_smul,
← s.affineCombination_vsub, ← lineMap_apply, sbtw_lineMap_iff, and_iff_left hs.2,
← @vsub_ne_zero V, s.affineCombination_vsub]
intro hz
have hw₁w₂ : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by
simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, hw₁, hw₂, sub_self]
refine hs.1 ?_
have ha' := ha s (w₁ - w₂) hw₁w₂ hz i his
rwa [Pi.sub_apply, sub_eq_zero] at ha'
end OrderedRing
section StrictOrderedCommRing
variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P]
variable {R}
| Mathlib/Analysis/Convex/Between.lean | 498 | 501 | theorem Wbtw.sameRay_vsub {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ y) := by | rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩
simp_rw [lineMap_apply]
rcases ht0.lt_or_eq with (ht0' | rfl); swap; · simp |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth
-/
import Mathlib.MeasureTheory.Group.Action
import Mathlib.MeasureTheory.Group.Pointwise
import Mathlib.MeasureTheory.Integral.Lebesgue.Map
import Mathlib.MeasureTheory.Integral.Bochner.Set
/-!
# Fundamental domain of a group action
A set `s` is said to be a *fundamental domain* of an action of a group `G` on a measurable space `α`
with respect to a measure `μ` if
* `s` is a measurable set;
* the sets `g • s` over all `g : G` cover almost all points of the whole space;
* the sets `g • s`, are pairwise a.e. disjoint, i.e., `μ (g₁ • s ∩ g₂ • s) = 0` whenever `g₁ ≠ g₂`;
we require this for `g₂ = 1` in the definition, then deduce it for any two `g₁ ≠ g₂`.
In this file we prove that in case of a countable group `G` and a measure preserving action, any two
fundamental domains have the same measure, and for a `G`-invariant function, its integrals over any
two fundamental domains are equal to each other.
We also generate additive versions of all theorems in this file using the `to_additive` attribute.
* We define the `HasFundamentalDomain` typeclass, in particular to be able to define the `covolume`
of a quotient of `α` by a group `G`, which under reasonable conditions does not depend on the choice
of fundamental domain.
* We define the `QuotientMeasureEqMeasurePreimage` typeclass to describe a situation in which a
measure `μ` on `α ⧸ G` can be computed by taking a measure `ν` on `α` of the intersection of the
pullback with a fundamental domain.
## Main declarations
* `MeasureTheory.IsFundamentalDomain`: Predicate for a set to be a fundamental domain of the
action of a group
* `MeasureTheory.fundamentalFrontier`: Fundamental frontier of a set under the action of a group.
Elements of `s` that belong to some other translate of `s`.
* `MeasureTheory.fundamentalInterior`: Fundamental interior of a set under the action of a group.
Elements of `s` that do not belong to any other translate of `s`.
-/
open scoped ENNReal Pointwise Topology NNReal ENNReal MeasureTheory
open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Filter
namespace MeasureTheory
/-- A measurable set `s` is a *fundamental domain* for an additive action of an additive group `G`
on a measurable space `α` with respect to a measure `α` if the sets `g +ᵥ s`, `g : G`, are pairwise
a.e. disjoint and cover the whole space. -/
structure IsAddFundamentalDomain (G : Type*) {α : Type*} [Zero G] [VAdd G α] [MeasurableSpace α]
(s : Set α) (μ : Measure α := by volume_tac) : Prop where
protected nullMeasurableSet : NullMeasurableSet s μ
protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g +ᵥ x ∈ s
protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g +ᵥ s)
/-- A measurable set `s` is a *fundamental domain* for an action of a group `G` on a measurable
space `α` with respect to a measure `α` if the sets `g • s`, `g : G`, are pairwise a.e. disjoint and
cover the whole space. -/
@[to_additive IsAddFundamentalDomain]
structure IsFundamentalDomain (G : Type*) {α : Type*} [One G] [SMul G α] [MeasurableSpace α]
(s : Set α) (μ : Measure α := by volume_tac) : Prop where
protected nullMeasurableSet : NullMeasurableSet s μ
protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s
protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g • s)
variable {G H α β E : Type*}
namespace IsFundamentalDomain
variable [Group G] [Group H] [MulAction G α] [MeasurableSpace α] [MulAction H β] [MeasurableSpace β]
[NormedAddCommGroup E] {s t : Set α} {μ : Measure α}
/-- If for each `x : α`, exactly one of `g • x`, `g : G`, belongs to a measurable set `s`, then `s`
is a fundamental domain for the action of `G` on `α`. -/
@[to_additive "If for each `x : α`, exactly one of `g +ᵥ x`, `g : G`, belongs to a measurable set
`s`, then `s` is a fundamental domain for the additive action of `G` on `α`."]
theorem mk' (h_meas : NullMeasurableSet s μ) (h_exists : ∀ x : α, ∃! g : G, g • x ∈ s) :
IsFundamentalDomain G s μ where
nullMeasurableSet := h_meas
ae_covers := Eventually.of_forall fun x => (h_exists x).exists
aedisjoint a b hab := Disjoint.aedisjoint <| disjoint_left.2 fun x hxa hxb => by
rw [mem_smul_set_iff_inv_smul_mem] at hxa hxb
exact hab (inv_injective <| (h_exists x).unique hxa hxb)
/-- For `s` to be a fundamental domain, it's enough to check
`MeasureTheory.AEDisjoint (g • s) s` for `g ≠ 1`. -/
@[to_additive "For `s` to be a fundamental domain, it's enough to check
`MeasureTheory.AEDisjoint (g +ᵥ s) s` for `g ≠ 0`."]
theorem mk'' (h_meas : NullMeasurableSet s μ) (h_ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s)
(h_ae_disjoint : ∀ g, g ≠ (1 : G) → AEDisjoint μ (g • s) s)
(h_qmp : ∀ g : G, QuasiMeasurePreserving ((g • ·) : α → α) μ μ) :
IsFundamentalDomain G s μ where
nullMeasurableSet := h_meas
ae_covers := h_ae_covers
aedisjoint := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp
/-- If a measurable space has a finite measure `μ` and a countable group `G` acts
quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient
to check that its translates `g • s` are (almost) disjoint and that the sum `∑' g, μ (g • s)` is
sufficiently large. -/
@[to_additive
"If a measurable space has a finite measure `μ` and a countable additive group `G` acts
quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient
to check that its translates `g +ᵥ s` are (almost) disjoint and that the sum `∑' g, μ (g +ᵥ s)` is
sufficiently large."]
theorem mk_of_measure_univ_le [IsFiniteMeasure μ] [Countable G] (h_meas : NullMeasurableSet s μ)
(h_ae_disjoint : ∀ g ≠ (1 : G), AEDisjoint μ (g • s) s)
(h_qmp : ∀ g : G, QuasiMeasurePreserving (g • · : α → α) μ μ)
(h_measure_univ_le : μ (univ : Set α) ≤ ∑' g : G, μ (g • s)) : IsFundamentalDomain G s μ :=
have aedisjoint : Pairwise (AEDisjoint μ on fun g : G => g • s) :=
pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp
{ nullMeasurableSet := h_meas
aedisjoint
ae_covers := by
replace h_meas : ∀ g : G, NullMeasurableSet (g • s) μ := fun g => by
rw [← inv_inv g, ← preimage_smul]; exact h_meas.preimage (h_qmp g⁻¹)
have h_meas' : NullMeasurableSet {a | ∃ g : G, g • a ∈ s} μ := by
rw [← iUnion_smul_eq_setOf_exists]; exact .iUnion h_meas
rw [ae_iff_measure_eq h_meas', ← iUnion_smul_eq_setOf_exists]
refine le_antisymm (measure_mono <| subset_univ _) ?_
rw [measure_iUnion₀ aedisjoint h_meas]
exact h_measure_univ_le }
@[to_additive]
theorem iUnion_smul_ae_eq (h : IsFundamentalDomain G s μ) : ⋃ g : G, g • s =ᵐ[μ] univ :=
eventuallyEq_univ.2 <| h.ae_covers.mono fun _ ⟨g, hg⟩ =>
mem_iUnion.2 ⟨g⁻¹, _, hg, inv_smul_smul _ _⟩
@[to_additive]
theorem measure_ne_zero [Countable G] [SMulInvariantMeasure G α μ]
(hμ : μ ≠ 0) (h : IsFundamentalDomain G s μ) : μ s ≠ 0 := by
have hc := measure_univ_pos.mpr hμ
contrapose! hc
rw [← measure_congr h.iUnion_smul_ae_eq]
refine le_trans (measure_iUnion_le _) ?_
simp_rw [measure_smul, hc, tsum_zero, le_refl]
@[to_additive]
theorem mono (h : IsFundamentalDomain G s μ) {ν : Measure α} (hle : ν ≪ μ) :
IsFundamentalDomain G s ν :=
⟨h.1.mono_ac hle, hle h.2, h.aedisjoint.mono fun _ _ h => hle h⟩
@[to_additive]
theorem preimage_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) {f : β → α}
(hf : QuasiMeasurePreserving f ν μ) {e : G → H} (he : Bijective e)
(hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f ⁻¹' s) ν where
nullMeasurableSet := h.nullMeasurableSet.preimage hf
ae_covers := (hf.ae h.ae_covers).mono fun x ⟨g, hg⟩ => ⟨e g, by rwa [mem_preimage, hef g x]⟩
aedisjoint a b hab := by
lift e to G ≃ H using he
have : (e.symm a⁻¹)⁻¹ ≠ (e.symm b⁻¹)⁻¹ := by simp [hab]
have := (h.aedisjoint this).preimage hf
simp only [Semiconj] at hef
simpa only [onFun, ← preimage_smul_inv, preimage_preimage, ← hef, e.apply_symm_apply, inv_inv]
using this
@[to_additive]
| Mathlib/MeasureTheory/Group/FundamentalDomain.lean | 166 | 177 | theorem image_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) (f : α ≃ β)
(hf : QuasiMeasurePreserving f.symm ν μ) (e : H ≃ G)
(hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f '' s) ν := by | rw [f.image_eq_preimage]
refine h.preimage_of_equiv hf e.symm.bijective fun g x => ?_
rcases f.surjective x with ⟨x, rfl⟩
rw [← hef _ _, f.symm_apply_apply, f.symm_apply_apply, e.apply_symm_apply]
@[to_additive]
theorem pairwise_aedisjoint_of_ac {ν} (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) :
Pairwise fun g₁ g₂ : G => AEDisjoint ν (g₁ • s) (g₂ • s) :=
h.aedisjoint.mono fun _ _ H => hν H |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
/-!
# Changing the index type of a matrix
This file concerns the map `Matrix.reindex`, mapping a `m` by `n` matrix
to an `m'` by `n'` matrix, as long as `m ≃ m'` and `n ≃ n'`.
## Main definitions
* `Matrix.reindexLinearEquiv R A`: `Matrix.reindex` is an `R`-linear equivalence between
`A`-matrices.
* `Matrix.reindexAlgEquiv R`: `Matrix.reindex` is an `R`-algebra equivalence between `R`-matrices.
## Tags
matrix, reindex
-/
namespace Matrix
open Equiv Matrix
variable {l m n o : Type*} {l' m' n' o' : Type*} {m'' n'' : Type*}
variable (R A : Type*)
section AddCommMonoid
variable [Semiring R] [AddCommMonoid A] [Module R A]
/-- The natural map that reindexes a matrix's rows and columns with equivalent types,
`Matrix.reindex`, is a linear equivalence. -/
def reindexLinearEquiv (eₘ : m ≃ m') (eₙ : n ≃ n') : Matrix m n A ≃ₗ[R] Matrix m' n' A :=
{ reindex eₘ eₙ with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
@[simp]
theorem reindexLinearEquiv_apply (eₘ : m ≃ m') (eₙ : n ≃ n') (M : Matrix m n A) :
reindexLinearEquiv R A eₘ eₙ M = reindex eₘ eₙ M :=
rfl
@[simp]
theorem reindexLinearEquiv_symm (eₘ : m ≃ m') (eₙ : n ≃ n') :
(reindexLinearEquiv R A eₘ eₙ).symm = reindexLinearEquiv R A eₘ.symm eₙ.symm :=
rfl
@[simp]
theorem reindexLinearEquiv_refl_refl :
reindexLinearEquiv R A (Equiv.refl m) (Equiv.refl n) = LinearEquiv.refl R _ :=
LinearEquiv.ext fun _ => rfl
theorem reindexLinearEquiv_trans (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'') (e₂' : n' ≃ n'') :
(reindexLinearEquiv R A e₁ e₂).trans (reindexLinearEquiv R A e₁' e₂') =
(reindexLinearEquiv R A (e₁.trans e₁') (e₂.trans e₂') : _ ≃ₗ[R] _) := by
ext
rfl
| Mathlib/LinearAlgebra/Matrix/Reindex.lean | 66 | 70 | theorem reindexLinearEquiv_comp (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'') (e₂' : n' ≃ n'') :
reindexLinearEquiv R A e₁' e₂' ∘ reindexLinearEquiv R A e₁ e₂ =
reindexLinearEquiv R A (e₁.trans e₁') (e₂.trans e₂') := by | rw [← reindexLinearEquiv_trans]
rfl |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau, Kim Morrison, Alex Keizer
-/
import Mathlib.Data.List.OfFn
import Batteries.Data.List.Perm
import Mathlib.Data.List.Nodup
/-!
# Lists of elements of `Fin n`
This file develops some results on `finRange n`.
-/
assert_not_exists Monoid
universe u
namespace List
variable {α : Type u}
| Mathlib/Data/List/FinRange.lean | 25 | 27 | theorem finRange_eq_pmap_range (n : ℕ) : finRange n = (range n).pmap Fin.mk (by simp) := by | apply List.ext_getElem <;> simp [finRange] |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Algebra.BigOperators.NatAntidiagonal
import Mathlib.Topology.Algebra.InfiniteSum.Constructions
import Mathlib.Topology.Algebra.Ring.Basic
/-!
# Infinite sum in a ring
This file provides lemmas about the interaction between infinite sums and multiplication.
## Main results
* `tsum_mul_tsum_eq_tsum_sum_antidiagonal`: Cauchy product formula
-/
open Filter Finset Function
variable {ι κ α : Type*}
section NonUnitalNonAssocSemiring
variable [NonUnitalNonAssocSemiring α] [TopologicalSpace α] [IsTopologicalSemiring α] {f : ι → α}
{a₁ : α}
theorem HasSum.mul_left (a₂) (h : HasSum f a₁) : HasSum (fun i ↦ a₂ * f i) (a₂ * a₁) := by
simpa only using h.map (AddMonoidHom.mulLeft a₂) (continuous_const.mul continuous_id)
theorem HasSum.mul_right (a₂) (hf : HasSum f a₁) : HasSum (fun i ↦ f i * a₂) (a₁ * a₂) := by
simpa only using hf.map (AddMonoidHom.mulRight a₂) (continuous_id.mul continuous_const)
theorem Summable.mul_left (a) (hf : Summable f) : Summable fun i ↦ a * f i :=
(hf.hasSum.mul_left _).summable
theorem Summable.mul_right (a) (hf : Summable f) : Summable fun i ↦ f i * a :=
(hf.hasSum.mul_right _).summable
section tsum
variable [T2Space α]
protected theorem Summable.tsum_mul_left (a) (hf : Summable f) : ∑' i, a * f i = a * ∑' i, f i :=
(hf.hasSum.mul_left _).tsum_eq
protected theorem Summable.tsum_mul_right (a) (hf : Summable f) : ∑' i, f i * a = (∑' i, f i) * a :=
(hf.hasSum.mul_right _).tsum_eq
theorem Commute.tsum_right (a) (h : ∀ i, Commute a (f i)) : Commute a (∑' i, f i) := by
classical
by_cases hf : Summable f
· exact (hf.tsum_mul_left a).symm.trans ((congr_arg _ <| funext h).trans (hf.tsum_mul_right a))
· exact (tsum_eq_zero_of_not_summable hf).symm ▸ Commute.zero_right _
theorem Commute.tsum_left (a) (h : ∀ i, Commute (f i) a) : Commute (∑' i, f i) a :=
(Commute.tsum_right _ fun i ↦ (h i).symm).symm
end tsum
end NonUnitalNonAssocSemiring
section DivisionSemiring
variable [DivisionSemiring α] [TopologicalSpace α] [IsTopologicalSemiring α]
{f : ι → α} {a a₁ a₂ : α}
theorem HasSum.div_const (h : HasSum f a) (b : α) : HasSum (fun i ↦ f i / b) (a / b) := by
simp only [div_eq_mul_inv, h.mul_right b⁻¹]
theorem Summable.div_const (h : Summable f) (b : α) : Summable fun i ↦ f i / b :=
(h.hasSum.div_const _).summable
theorem hasSum_mul_left_iff (h : a₂ ≠ 0) : HasSum (fun i ↦ a₂ * f i) (a₂ * a₁) ↔ HasSum f a₁ :=
⟨fun H ↦ by simpa only [inv_mul_cancel_left₀ h] using H.mul_left a₂⁻¹, HasSum.mul_left _⟩
theorem hasSum_mul_right_iff (h : a₂ ≠ 0) : HasSum (fun i ↦ f i * a₂) (a₁ * a₂) ↔ HasSum f a₁ :=
⟨fun H ↦ by simpa only [mul_inv_cancel_right₀ h] using H.mul_right a₂⁻¹, HasSum.mul_right _⟩
| Mathlib/Topology/Algebra/InfiniteSum/Ring.lean | 81 | 82 | theorem hasSum_div_const_iff (h : a₂ ≠ 0) : HasSum (fun i ↦ f i / a₂) (a₁ / a₂) ↔ HasSum f a₁ := by | simpa only [div_eq_mul_inv] using hasSum_mul_right_iff (inv_ne_zero h) |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot
-/
import Mathlib.Data.Set.Image
import Mathlib.Data.SProd
/-!
# Sets in product and pi types
This file proves basic properties of product of sets in `α × β` and in `Π i, α i`, and of the
diagonal of a type.
## Main declarations
This file contains basic results on the following notions, which are defined in `Set.Operations`.
* `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have
`s.prod t : Set (α × β)`. Denoted by `s ×ˢ t`.
* `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`.
* `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal.
* `Set.pi`: Arbitrary product of sets.
-/
open Function
namespace Set
/-! ### Cartesian binary product of sets -/
section Prod
variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β}
theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) :
(s ×ˢ t).Subsingleton := fun _x hx _y hy ↦
Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2)
noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] :
DecidablePred (· ∈ s ×ˢ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t))
@[gcongr]
theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ :=
fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩
@[gcongr]
theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t :=
prod_mono hs Subset.rfl
@[gcongr]
theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ :=
prod_mono Subset.rfl ht
@[simp]
theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ :=
⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩
@[simp]
theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ :=
and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self
theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P :=
⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩
theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) :=
prod_subset_iff
theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by
simp [and_assoc]
@[simp]
theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by
ext
exact iff_of_eq (and_false _)
@[simp]
theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by
ext
exact iff_of_eq (false_and _)
@[simp, mfld_simps]
theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by
ext
exact iff_of_eq (true_and _)
theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq]
theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq]
@[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by
simp [eq_univ_iff_forall, forall_and]
theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
@[simp]
theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by ext ⟨c, d⟩; simp
@[simp]
theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp [or_and_right]
@[simp]
theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp [and_or_left]
theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp only [← and_and_right, mem_inter_iff, mem_prod]
theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp only [← and_and_left, mem_inter_iff, mem_prod]
@[mfld_simps]
theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by
ext ⟨x, y⟩
simp [and_assoc, and_left_comm]
lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) :
(s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by
ext p
simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and]
constructor <;> intro h
· by_cases fst_in_s : p.fst ∈ s
· exact Or.inr (h fst_in_s)
· exact Or.inl fst_in_s
· intro fst_in_s
simpa only [fst_in_s, not_true, false_or] using h
@[simp]
theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by
simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ←
@forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)]
theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂
theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂
theorem prodMap_image_prod (f : α → β) (g : γ → δ) (s : Set α) (t : Set γ) :
(Prod.map f g) '' (s ×ˢ t) = (f '' s) ×ˢ (g '' t) := by
ext
aesop
theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by
simp only [insert_eq, union_prod, singleton_prod]
theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by
simp only [insert_eq, prod_union, prod_singleton]
theorem prod_preimage_eq {f : γ → α} {g : δ → β} :
(f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_left {f : γ → α} :
(f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_right {g : δ → β} :
s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) :
Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) :=
rfl
theorem mk_preimage_prod (f : γ → α) (g : γ → β) :
(fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t :=
rfl
@[simp]
theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by
ext b
simp [ha]
@[simp]
theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by
ext b
simp [ha]
theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] :
(fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] :
Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) :
(fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by
rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage]
theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) :
(fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by
rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage]
@[simp]
theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by
ext ⟨x, y⟩
simp [and_comm]
@[simp]
theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by
rw [image_swap_eq_preimage_swap, preimage_swap_prod]
theorem mapsTo_swap_prod (s : Set α) (t : Set β) : MapsTo Prod.swap (s ×ˢ t) (t ×ˢ s) :=
fun _ ⟨hx, hy⟩ ↦ ⟨hy, hx⟩
theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} :
(m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t :=
ext <| by
simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm]
theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} :
range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) :=
ext <| by simp [range]
@[simp, mfld_simps]
theorem range_prodMap {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ :=
prod_range_range_eq.symm
@[deprecated (since := "2025-04-10")] alias range_prod_map := range_prodMap
theorem prod_range_univ_eq {m₁ : α → γ} :
range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) :=
ext <| by simp [range]
theorem prod_univ_range_eq {m₂ : β → δ} :
(univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) :=
ext <| by simp [range]
theorem range_pair_subset (f : α → β) (g : α → γ) :
(range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by
have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl
rw [this, ← range_prodMap]
apply range_comp_subset_range
theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ =>
⟨(x, y), ⟨hx, hy⟩⟩
theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩
theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩
@[simp]
theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩
@[simp]
theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or]
theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} :
s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def]
theorem image_prodMk_subset_prod {f : α → β} {g : α → γ} {s : Set α} :
(fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by
rintro _ ⟨x, hx, rfl⟩
exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx)
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod := image_prodMk_subset_prod
theorem image_prodMk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by
rintro _ ⟨a, ha, rfl⟩
exact ⟨ha, hb⟩
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod_left := image_prodMk_subset_prod_left
| Mathlib/Data/Set/Prod.lean | 293 | 295 | theorem image_prodMk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by | rintro _ ⟨b, hb, rfl⟩
exact ⟨ha, hb⟩ |
/-
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
/-!
# 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 θ)
/-- 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 θ)
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]
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
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
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]
· rw [funext <| 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) _
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)
/-- A useful bound for circle integrals (with complex codomain) -/
def circleTransformBoundingFunction (R : ℝ) (z : ℂ) (w : ℂ × ℝ) : ℂ :=
circleTransformDeriv R z w.1 (fun _ => 1) w.2
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)
| Mathlib/MeasureTheory/Integral/CircleTransform.lean | 98 | 106 | theorem continuousOn_norm_circleTransformBoundingFunction {R r : ℝ} (hr : r < R) (z : ℂ) :
ContinuousOn ((‖·‖) ∘ 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 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.MonoidAlgebra.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Ring.Action.Rat
import Mathlib.Data.Finset.Sort
import Mathlib.Tactic.FastInstance
/-!
# Theory of univariate polynomials
This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds
a semiring structure on it, and gives basic definitions that are expanded in other files in this
directory.
## Main definitions
* `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map.
* `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism.
* `X` is the polynomial `X`, i.e., `monomial 1 1`.
* `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied
to coefficients of the polynomial `p`.
* `p.erase n` is the polynomial `p` in which one removes the `c X^n` term.
There are often two natural variants of lemmas involving sums, depending on whether one acts on the
polynomials, or on the function. The naming convention is that one adds `index` when acting on
the polynomials. For instance,
* `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`;
* `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`.
* Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`.
## Implementation
Polynomials are defined using `R[ℕ]`, where `R` is a semiring.
The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity
`X * p = p * X`. The relationship to `R[ℕ]` is through a structure
to make polynomials irreducible from the point of view of the kernel. Most operations
are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two
exceptions that we make semireducible:
* The zero polynomial, so that its coefficients are definitionally equal to `0`.
* The scalar action, to permit typeclass search to unfold it to resolve potential instance
diamonds.
The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is
done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial
gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The
equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should
in general not be used once the basic API for polynomials is constructed.
-/
noncomputable section
/-- `Polynomial R` is the type of univariate polynomials over `R`,
denoted as `R[X]` within the `Polynomial` namespace.
Polynomials should be seen as (semi-)rings with the additional constructor `X`.
The embedding from `R` is called `C`. -/
structure Polynomial (R : Type*) [Semiring R] where ofFinsupp ::
toFinsupp : AddMonoidAlgebra R ℕ
@[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R
open AddMonoidAlgebra Finset
open Finsupp hiding single
open Function hiding Commute
namespace Polynomial
universe u
variable {R : Type u} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
theorem forall_iff_forall_finsupp (P : R[X] → Prop) :
(∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ :=
⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩
theorem exists_iff_exists_finsupp (P : R[X] → Prop) :
(∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ :=
⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩
@[simp]
theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl
/-! ### Conversions to and from `AddMonoidAlgebra`
Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping
it, we have to copy across all the arithmetic operators manually, along with the lemmas about how
they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`.
-/
section AddMonoidAlgebra
private irreducible_def add : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a + b⟩
private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X]
| ⟨a⟩ => ⟨-a⟩
private irreducible_def mul : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a * b⟩
instance zero : Zero R[X] :=
⟨⟨0⟩⟩
instance one : One R[X] :=
⟨⟨1⟩⟩
instance add' : Add R[X] :=
⟨add⟩
instance neg' {R : Type u} [Ring R] : Neg R[X] :=
⟨neg⟩
instance sub {R : Type u} [Ring R] : Sub R[X] :=
⟨fun a b => a + -b⟩
instance mul' : Mul R[X] :=
⟨mul⟩
-- If the private definitions are accidentally exposed, simplify them away.
@[simp] theorem add_eq_add : add p q = p + q := rfl
@[simp] theorem mul_eq_mul : mul p q = p * q := rfl
instance instNSMul : SMul ℕ R[X] where
smul r p := ⟨r • p.toFinsupp⟩
instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where
smul r p := ⟨r • p.toFinsupp⟩
smul_zero a := congr_arg ofFinsupp (smul_zero a)
instance {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] :
NoZeroSMulDivisors S R[X] where
eq_zero_or_eq_zero_of_smul_eq_zero eq :=
(eq_zero_or_eq_zero_of_smul_eq_zero <| congr_arg toFinsupp eq).imp id (congr_arg ofFinsupp)
-- to avoid a bug in the `ring` tactic
instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p
@[simp]
theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 :=
rfl
@[simp]
theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 :=
rfl
@[simp]
theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ :=
show _ = add _ _ by rw [add_def]
@[simp]
theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ :=
show _ = neg _ by rw [neg_def]
@[simp]
theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by
rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg]
rfl
@[simp]
theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ :=
show _ = mul _ _ by rw [mul_def]
@[simp]
theorem ofFinsupp_nsmul (a : ℕ) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by
change _ = npowRec n _
induction n with
| zero => simp [npowRec]
| succ n n_ih => simp [npowRec, n_ih, pow_succ]
@[simp]
theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 :=
rfl
@[simp]
theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 :=
rfl
@[simp]
theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_add]
@[simp]
theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by
cases a
rw [← ofFinsupp_neg]
@[simp]
theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) :
(a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by
rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add]
rfl
@[simp]
theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_mul]
@[simp]
theorem toFinsupp_nsmul (a : ℕ) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by
cases a
rw [← ofFinsupp_pow]
theorem _root_.IsSMulRegular.polynomial {S : Type*} [SMulZeroClass S R] {a : S}
(ha : IsSMulRegular R a) : IsSMulRegular R[X] a
| ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h)
theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) :=
fun ⟨_x⟩ ⟨_y⟩ => congr_arg _
@[simp]
theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b :=
toFinsupp_injective.eq_iff
@[simp]
theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by
rw [← toFinsupp_zero, toFinsupp_inj]
@[simp]
theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by
rw [← toFinsupp_one, toFinsupp_inj]
/-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/
theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b :=
iff_of_eq (ofFinsupp.injEq _ _)
@[simp]
theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by
rw [← ofFinsupp_zero, ofFinsupp_inj]
@[simp]
theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj]
instance inhabited : Inhabited R[X] :=
⟨0⟩
instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n
@[simp]
theorem ofFinsupp_natCast (n : ℕ) : (⟨n⟩ : R[X]) = n := rfl
@[simp]
theorem toFinsupp_natCast (n : ℕ) : (n : R[X]).toFinsupp = n := rfl
@[simp]
theorem ofFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (⟨ofNat(n)⟩ : R[X]) = ofNat(n) := rfl
@[simp]
theorem toFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R[X]).toFinsupp = ofNat(n) := rfl
instance semiring : Semiring R[X] :=
fast_instance% Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero
toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_nsmul _ _) toFinsupp_pow
fun _ => rfl
instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] :=
fast_instance% Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] :=
fast_instance% Function.Injective.distribMulAction
⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul
instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where
eq_of_smul_eq_smul {_s₁ _s₂} h :=
eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩)
instance module {S} [Semiring S] [Module S R] : Module S R[X] :=
fast_instance% Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] :
SMulCommClass S₁ S₂ R[X] :=
⟨by
rintro m n ⟨f⟩
simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩
instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R]
[IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] :=
⟨by
rintro _ _ ⟨⟩
simp_rw [← ofFinsupp_smul, smul_assoc]⟩
instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] :
IsScalarTower α K[X] K[X] :=
⟨by
rintro _ ⟨⟩ ⟨⟩
simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩
instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] :
IsCentralScalar S R[X] :=
⟨by
rintro _ ⟨⟩
simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩
instance unique [Subsingleton R] : Unique R[X] :=
{ Polynomial.inhabited with
uniq := by
rintro ⟨x⟩
apply congr_arg ofFinsupp
simp [eq_iff_true_of_subsingleton] }
variable (R)
/-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps apply symm_apply]
def toFinsuppIso : R[X] ≃+* R[ℕ] where
toFun := toFinsupp
invFun := ofFinsupp
left_inv := fun ⟨_p⟩ => rfl
right_inv _p := rfl
map_mul' := toFinsupp_mul
map_add' := toFinsupp_add
instance [DecidableEq R] : DecidableEq R[X] :=
@Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq)
/-- Linear isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps!]
def toFinsuppIsoLinear : R[X] ≃ₗ[R] R[ℕ] where
__ := toFinsuppIso R
map_smul' _ _ := rfl
end AddMonoidAlgebra
theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) :
(⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ :=
map_sum (toFinsuppIso R).symm f s
theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) :
(∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp :=
map_sum (toFinsuppIso R) f s
/-- The set of all `n` such that `X^n` has a non-zero coefficient. -/
def support : R[X] → Finset ℕ
| ⟨p⟩ => p.support
@[simp]
theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support]
theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support]
@[simp]
theorem support_zero : (0 : R[X]).support = ∅ :=
rfl
@[simp]
theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by
rcases p with ⟨⟩
simp [support]
@[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 :=
Finset.nonempty_iff_ne_empty.trans support_eq_empty.not
theorem card_support_eq_zero : #p.support = 0 ↔ p = 0 := by simp
/-- `monomial s a` is the monomial `a * X^s` -/
def monomial (n : ℕ) : R →ₗ[R] R[X] where
toFun t := ⟨Finsupp.single n t⟩
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp`.
map_add' x y := by simp; rw [ofFinsupp_add]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [← ofFinsupp_smul]`.
map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single']
@[simp]
theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by
simp [monomial]
@[simp]
theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by
simp [monomial]
@[simp]
theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 :=
(monomial n).map_zero
-- This is not a `simp` lemma as `monomial_zero_left` is more general.
theorem monomial_zero_one : monomial 0 (1 : R) = 1 :=
rfl
-- TODO: can't we just delete this one?
theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s :=
(monomial n).map_add _ _
theorem monomial_mul_monomial (n m : ℕ) (r s : R) :
monomial n r * monomial m s = monomial (n + m) (r * s) :=
toFinsupp_injective <| by
simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single]
@[simp]
theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by
induction k with
| zero => simp [pow_zero, monomial_zero_one]
| succ k ih => simp [pow_succ, ih, monomial_mul_monomial, mul_add, add_comm]
theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) :
a • monomial n b = monomial n (a • b) :=
toFinsupp_injective <| AddMonoidAlgebra.smul_single _ _ _
theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) :=
(toFinsuppIso R).symm.injective.comp (single_injective n)
@[simp]
theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 :=
LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n)
theorem monomial_eq_monomial_iff {m n : ℕ} {a b : R} :
monomial m a = monomial n b ↔ m = n ∧ a = b ∨ a = 0 ∧ b = 0 := by
rw [← toFinsupp_inj, toFinsupp_monomial, toFinsupp_monomial, Finsupp.single_eq_single_iff]
theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by
simpa [support] using Finsupp.support_add
/-- `C a` is the constant polynomial `a`.
`C` is provided as a ring homomorphism.
-/
def C : R →+* R[X] :=
{ monomial 0 with
map_one' := by simp [monomial_zero_one]
map_mul' := by simp [monomial_mul_monomial]
map_zero' := by simp }
@[simp]
theorem monomial_zero_left (a : R) : monomial 0 a = C a :=
rfl
@[simp]
theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a :=
rfl
theorem C_0 : C (0 : R) = 0 := by simp
theorem C_1 : C (1 : R) = 1 :=
rfl
theorem C_mul : C (a * b) = C a * C b :=
C.map_mul a b
theorem C_add : C (a + b) = C a + C b :=
C.map_add a b
@[simp]
theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) :=
smul_monomial _ _ r
theorem C_pow : C (a ^ n) = C a ^ n :=
C.map_pow a n
theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) :=
map_natCast C n
@[simp]
theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, zero_add]
@[simp]
theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, add_zero]
/-- `X` is the polynomial variable (aka indeterminate). -/
def X : R[X] :=
monomial 1 1
theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X :=
rfl
theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by
induction n with
| zero => simp [monomial_zero_one]
| succ n ih => rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one]
@[simp]
theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) :=
rfl
theorem X_ne_C [Nontrivial R] (a : R) : X ≠ C a := by
intro he
simpa using monomial_eq_monomial_iff.1 he
/-- `X` commutes with everything, even when the coefficients are noncommutative. -/
theorem X_mul : X * p = p * X := by
rcases p with ⟨⟩
simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, LinearMap.coe_mk, ofFinsupp.injEq]
ext
simp [AddMonoidAlgebra.mul_apply, AddMonoidAlgebra.sum_single_index, add_comm]
theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by
induction n with
| zero => simp
| succ n ih =>
conv_lhs => rw [pow_succ]
rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ]
/-- Prefer putting constants to the left of `X`.
This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/
@[simp]
theorem X_mul_C (r : R) : X * C r = C r * X :=
X_mul
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/
@[simp]
theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n :=
X_pow_mul
theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by
rw [mul_assoc, X_pow_mul, ← mul_assoc]
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/
@[simp]
theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n :=
X_pow_mul_assoc
theorem commute_X (p : R[X]) : Commute X p :=
X_mul
theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p :=
X_pow_mul
@[simp]
theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by
rw [X, monomial_mul_monomial, mul_one]
@[simp]
theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) :
monomial n r * X ^ k = monomial (n + k) r := by
induction k with
| zero => simp
| succ k ih => simp [ih, pow_succ, ← mul_assoc, add_assoc]
@[simp]
theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by
rw [X_mul, monomial_mul_X]
@[simp]
theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by
rw [X_pow_mul, monomial_mul_X_pow]
/-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/
def coeff : R[X] → ℕ → R
| ⟨p⟩ => p
@[simp]
theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff]
theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by
rintro ⟨p⟩ ⟨q⟩
simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq]
@[simp]
theorem coeff_inj : p.coeff = q.coeff ↔ p = q :=
coeff_injective.eq_iff
theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl
theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by
simp [coeff, Finsupp.single_apply]
@[simp]
theorem coeff_monomial_same (n : ℕ) (c : R) : (monomial n c).coeff n = c :=
Finsupp.single_eq_same
theorem coeff_monomial_of_ne {m n : ℕ} (c : R) (h : n ≠ m) : (monomial n c).coeff m = 0 :=
Finsupp.single_eq_of_ne h
@[simp]
theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 :=
rfl
theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by
simp_rw [eq_comm (a := n) (b := 0)]
exact coeff_monomial
@[simp]
theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by
simp [coeff_one]
@[simp]
theorem coeff_X_one : coeff (X : R[X]) 1 = 1 :=
coeff_monomial
@[simp]
theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 :=
coeff_monomial
@[simp]
theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial]
theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 :=
coeff_monomial
theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by
rw [coeff_X, if_neg hn.symm]
@[simp]
theorem mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 := by
rcases p with ⟨⟩
simp
theorem not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 := by simp
theorem coeff_C : coeff (C a) n = ite (n = 0) a 0 := by
convert coeff_monomial (a := a) (m := n) (n := 0) using 2
simp [eq_comm]
@[simp]
theorem coeff_C_zero : coeff (C a) 0 = a :=
coeff_monomial
theorem coeff_C_ne_zero (h : n ≠ 0) : (C a).coeff n = 0 := by rw [coeff_C, if_neg h]
@[simp]
lemma coeff_C_succ {r : R} {n : ℕ} : coeff (C r) (n + 1) = 0 := by simp [coeff_C]
@[simp]
theorem coeff_natCast_ite : (Nat.cast m : R[X]).coeff n = ite (n = 0) m 0 := by
simp only [← C_eq_natCast, coeff_C, Nat.cast_ite, Nat.cast_zero]
@[simp]
theorem coeff_ofNat_zero (a : ℕ) [a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) 0 = ofNat(a) :=
coeff_monomial
@[simp]
theorem coeff_ofNat_succ (a n : ℕ) [h : a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) (n + 1) = 0 := by
rw [← Nat.cast_ofNat]
simp [-Nat.cast_ofNat]
theorem C_mul_X_pow_eq_monomial : ∀ {n : ℕ}, C a * X ^ n = monomial n a
| 0 => mul_one _
| n + 1 => by
rw [pow_succ, ← mul_assoc, C_mul_X_pow_eq_monomial, X, monomial_mul_monomial, mul_one]
@[simp high]
theorem toFinsupp_C_mul_X_pow (a : R) (n : ℕ) :
Polynomial.toFinsupp (C a * X ^ n) = Finsupp.single n a := by
rw [C_mul_X_pow_eq_monomial, toFinsupp_monomial]
theorem C_mul_X_eq_monomial : C a * X = monomial 1 a := by rw [← C_mul_X_pow_eq_monomial, pow_one]
@[simp high]
theorem toFinsupp_C_mul_X (a : R) : Polynomial.toFinsupp (C a * X) = Finsupp.single 1 a := by
rw [C_mul_X_eq_monomial, toFinsupp_monomial]
theorem C_injective : Injective (C : R → R[X]) :=
monomial_injective 0
@[simp]
theorem C_inj : C a = C b ↔ a = b :=
C_injective.eq_iff
@[simp]
theorem C_eq_zero : C a = 0 ↔ a = 0 :=
C_injective.eq_iff' (map_zero C)
theorem C_ne_zero : C a ≠ 0 ↔ a ≠ 0 :=
C_eq_zero.not
theorem subsingleton_iff_subsingleton : Subsingleton R[X] ↔ Subsingleton R :=
⟨@Injective.subsingleton _ _ _ C_injective, by
intro
infer_instance⟩
theorem Nontrivial.of_polynomial_ne (h : p ≠ q) : Nontrivial R :=
(subsingleton_or_nontrivial R).resolve_left fun _hI => h <| Subsingleton.elim _ _
theorem forall_eq_iff_forall_eq : (∀ f g : R[X], f = g) ↔ ∀ a b : R, a = b := by
simpa only [← subsingleton_iff] using subsingleton_iff_subsingleton
theorem ext_iff {p q : R[X]} : p = q ↔ ∀ n, coeff p n = coeff q n := by
rcases p with ⟨f : ℕ →₀ R⟩
rcases q with ⟨g : ℕ →₀ R⟩
simpa [coeff] using DFunLike.ext_iff (f := f) (g := g)
@[ext]
theorem ext {p q : R[X]} : (∀ n, coeff p n = coeff q n) → p = q :=
ext_iff.2
/-- Monomials generate the additive monoid of polynomials. -/
theorem addSubmonoid_closure_setOf_eq_monomial :
AddSubmonoid.closure { p : R[X] | ∃ n a, p = monomial n a } = ⊤ := by
apply top_unique
rw [← AddSubmonoid.map_equiv_top (toFinsuppIso R).symm.toAddEquiv, ←
Finsupp.add_closure_setOf_eq_single, AddMonoidHom.map_mclosure]
refine AddSubmonoid.closure_mono (Set.image_subset_iff.2 ?_)
rintro _ ⟨n, a, rfl⟩
exact ⟨n, a, Polynomial.ofFinsupp_single _ _⟩
theorem addHom_ext {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n a, f (monomial n a) = g (monomial n a)) : f = g :=
AddMonoidHom.eq_of_eqOn_denseM addSubmonoid_closure_setOf_eq_monomial <| by
rintro p ⟨n, a, rfl⟩
exact h n a
@[ext high]
theorem addHom_ext' {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n, f.comp (monomial n).toAddMonoidHom = g.comp (monomial n).toAddMonoidHom) : f = g :=
addHom_ext fun n => DFunLike.congr_fun (h n)
@[ext high]
theorem lhom_ext' {M : Type*} [AddCommMonoid M] [Module R M] {f g : R[X] →ₗ[R] M}
(h : ∀ n, f.comp (monomial n) = g.comp (monomial n)) : f = g :=
LinearMap.toAddMonoidHom_injective <| addHom_ext fun n => LinearMap.congr_fun (h n)
-- this has the same content as the subsingleton
theorem eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : R[X]) : p = 0 := by
rw [← one_smul R p, ← h, zero_smul]
section Fewnomials
theorem support_monomial (n) {a : R} (H : a ≠ 0) : (monomial n a).support = singleton n := by
rw [← ofFinsupp_single, support]; exact Finsupp.support_single_ne_zero _ H
theorem support_monomial' (n) (a : R) : (monomial n a).support ⊆ singleton n := by
rw [← ofFinsupp_single, support]
exact Finsupp.support_single_subset
theorem support_C {a : R} (h : a ≠ 0) : (C a).support = singleton 0 :=
support_monomial 0 h
theorem support_C_subset (a : R) : (C a).support ⊆ singleton 0 :=
support_monomial' 0 a
theorem support_C_mul_X {c : R} (h : c ≠ 0) : Polynomial.support (C c * X) = singleton 1 := by
rw [C_mul_X_eq_monomial, support_monomial 1 h]
theorem support_C_mul_X' (c : R) : Polynomial.support (C c * X) ⊆ singleton 1 := by
simpa only [C_mul_X_eq_monomial] using support_monomial' 1 c
theorem support_C_mul_X_pow (n : ℕ) {c : R} (h : c ≠ 0) :
Polynomial.support (C c * X ^ n) = singleton n := by
rw [C_mul_X_pow_eq_monomial, support_monomial n h]
theorem support_C_mul_X_pow' (n : ℕ) (c : R) : Polynomial.support (C c * X ^ n) ⊆ singleton n := by
simpa only [C_mul_X_pow_eq_monomial] using support_monomial' n c
open Finset
theorem support_binomial' (k m : ℕ) (x y : R) :
Polynomial.support (C x * X ^ k + C y * X ^ m) ⊆ {k, m} :=
support_add.trans
(union_subset
((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m})))
((support_C_mul_X_pow' m y).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_singleton_self m)))))
theorem support_trinomial' (k m n : ℕ) (x y z : R) :
Polynomial.support (C x * X ^ k + C y * X ^ m + C z * X ^ n) ⊆ {k, m, n} :=
support_add.trans
(union_subset
(support_add.trans
(union_subset
((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m, n})))
((support_C_mul_X_pow' m y).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_self m {n}))))))
((support_C_mul_X_pow' n z).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_of_mem (mem_singleton_self n))))))
end Fewnomials
theorem X_pow_eq_monomial (n) : X ^ n = monomial n (1 : R) := by
induction n with
| zero => rw [pow_zero, monomial_zero_one]
| succ n hn => rw [pow_succ, hn, X, monomial_mul_monomial, one_mul]
@[simp high]
theorem toFinsupp_X_pow (n : ℕ) : (X ^ n).toFinsupp = Finsupp.single n (1 : R) := by
rw [X_pow_eq_monomial, toFinsupp_monomial]
theorem smul_X_eq_monomial {n} : a • X ^ n = monomial n (a : R) := by
rw [X_pow_eq_monomial, smul_monomial, smul_eq_mul, mul_one]
theorem support_X_pow (H : ¬(1 : R) = 0) (n : ℕ) : (X ^ n : R[X]).support = singleton n := by
convert support_monomial n H
exact X_pow_eq_monomial n
theorem support_X_empty (H : (1 : R) = 0) : (X : R[X]).support = ∅ := by
rw [X, H, monomial_zero_right, support_zero]
theorem support_X (H : ¬(1 : R) = 0) : (X : R[X]).support = singleton 1 := by
rw [← pow_one X, support_X_pow H 1]
| Mathlib/Algebra/Polynomial/Basic.lean | 822 | 826 | theorem monomial_left_inj {a : R} (ha : a ≠ 0) {i j : ℕ} :
monomial i a = monomial j a ↔ i = j := by | simp only [← ofFinsupp_single, ofFinsupp.injEq, Finsupp.single_left_inj ha]
theorem binomial_eq_binomial {k l m n : ℕ} {u v : R} (hu : u ≠ 0) (hv : v ≠ 0) : |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Ring.Rat
import Mathlib.Algebra.Ring.Int.Parity
import Mathlib.Data.PNat.Defs
/-!
# Further lemmas for the Rational Numbers
-/
namespace Rat
theorem num_dvd (a) {b : ℤ} (b0 : b ≠ 0) : (a /. b).num ∣ a := by
rcases e : a /. b with ⟨n, d, h, c⟩
rw [Rat.mk'_eq_divInt, divInt_eq_iff b0 (mod_cast h)] at e
refine Int.natAbs_dvd.1 <| Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <|
c.dvd_of_dvd_mul_right ?_
have := congr_arg Int.natAbs e
simp only [Int.natAbs_mul, Int.natAbs_natCast] at this; simp [this]
theorem den_dvd (a b : ℤ) : ((a /. b).den : ℤ) ∣ b := by
by_cases b0 : b = 0; · simp [b0]
rcases e : a /. b with ⟨n, d, h, c⟩
rw [mk'_eq_divInt, divInt_eq_iff b0 (ne_of_gt (Int.natCast_pos.2 (Nat.pos_of_ne_zero h)))] at e
refine Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.symm.dvd_of_dvd_mul_left ?_
rw [← Int.natAbs_mul, ← Int.natCast_dvd_natCast, Int.dvd_natAbs, ← e]; simp
theorem num_den_mk {q : ℚ} {n d : ℤ} (hd : d ≠ 0) (qdf : q = n /. d) :
∃ c : ℤ, n = c * q.num ∧ d = c * q.den := by
obtain rfl | hn := eq_or_ne n 0
· simp [qdf]
have : q.num * d = n * ↑q.den := by
refine (divInt_eq_iff ?_ hd).mp ?_
· exact Int.natCast_ne_zero.mpr (Rat.den_nz _)
· rwa [num_divInt_den]
have hqdn : q.num ∣ n := by
rw [qdf]
exact Rat.num_dvd _ hd
refine ⟨n / q.num, ?_, ?_⟩
· rw [Int.ediv_mul_cancel hqdn]
· refine Int.eq_mul_div_of_mul_eq_mul_of_dvd_left ?_ hqdn this
rw [qdf]
exact Rat.num_ne_zero.2 ((divInt_ne_zero hd).mpr hn)
theorem num_mk (n d : ℤ) : (n /. d).num = d.sign * n / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
rw [← Int.tdiv_eq_ediv_of_dvd] <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
Int.zero_ediv, Int.ofNat_dvd_left, Nat.gcd_dvd_left, this]
theorem den_mk (n d : ℤ) : (n /. d).den = if d = 0 then 1 else d.natAbs / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
if_neg (Nat.cast_add_one_ne_zero _), this]
theorem add_den_dvd_lcm (q₁ q₂ : ℚ) : (q₁ + q₂).den ∣ q₁.den.lcm q₂.den := by
rw [add_def, normalize_eq, Nat.div_dvd_iff_dvd_mul (Nat.gcd_dvd_right _ _)
(Nat.gcd_ne_zero_right (by simp)), ← Nat.gcd_mul_lcm,
mul_dvd_mul_iff_right (Nat.lcm_ne_zero (by simp) (by simp)), Nat.dvd_gcd_iff]
refine ⟨?_, dvd_mul_right _ _⟩
rw [← Int.natCast_dvd_natCast, Int.dvd_natAbs]
apply Int.dvd_add
<;> apply dvd_mul_of_dvd_right <;> rw [Int.natCast_dvd_natCast]
<;> [exact Nat.gcd_dvd_right _ _; exact Nat.gcd_dvd_left _ _]
theorem add_den_dvd (q₁ q₂ : ℚ) : (q₁ + q₂).den ∣ q₁.den * q₂.den := by
rw [add_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_den_dvd (q₁ q₂ : ℚ) : (q₁ * q₂).den ∣ q₁.den * q₂.den := by
rw [mul_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_num (q₁ q₂ : ℚ) :
(q₁ * q₂).num = q₁.num * q₂.num / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
theorem mul_den (q₁ q₂ : ℚ) :
(q₁ * q₂).den =
q₁.den * q₂.den / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
theorem mul_self_num (q : ℚ) : (q * q).num = q.num * q.num := by
rw [mul_num, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Int.ofNat_one, Int.ediv_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem mul_self_den (q : ℚ) : (q * q).den = q.den * q.den := by
rw [Rat.mul_den, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Nat.div_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem add_num_den (q r : ℚ) :
q + r = (q.num * r.den + q.den * r.num : ℤ) /. (↑q.den * ↑r.den : ℤ) := by
have hqd : (q.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 q.den_pos
have hrd : (r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 r.den_pos
conv_lhs => rw [← num_divInt_den q, ← num_divInt_den r, divInt_add_divInt _ _ hqd hrd]
rw [mul_comm r.num q.den]
theorem isSquare_iff {q : ℚ} : IsSquare q ↔ IsSquare q.num ∧ IsSquare q.den := by
constructor
· rintro ⟨qr, rfl⟩
rw [Rat.mul_self_num, mul_self_den]
simp only [IsSquare.mul_self, and_self]
· rintro ⟨⟨nr, hnr⟩, ⟨dr, hdr⟩⟩
refine ⟨nr / dr, ?_⟩
rw [div_mul_div_comm, ← Int.cast_mul, ← Nat.cast_mul, ← hnr, ← hdr, num_div_den]
@[norm_cast, simp]
theorem isSquare_natCast_iff {n : ℕ} : IsSquare (n : ℚ) ↔ IsSquare n := by
simp_rw [isSquare_iff, num_natCast, den_natCast, IsSquare.one, and_true, Int.isSquare_natCast_iff]
@[norm_cast, simp]
theorem isSquare_intCast_iff {z : ℤ} : IsSquare (z : ℚ) ↔ IsSquare z := by
simp_rw [isSquare_iff, intCast_num, intCast_den, IsSquare.one, and_true]
@[simp]
theorem isSquare_ofNat_iff {n : ℕ} :
IsSquare (ofNat(n) : ℚ) ↔ IsSquare (OfNat.ofNat n : ℕ) :=
isSquare_natCast_iff
section Casts
theorem exists_eq_mul_div_num_and_eq_mul_div_den (n : ℤ) {d : ℤ} (d_ne_zero : d ≠ 0) :
∃ c : ℤ, n = c * ((n : ℚ) / d).num ∧ (d : ℤ) = c * ((n : ℚ) / d).den :=
haveI : (n : ℚ) / d = Rat.divInt n d := by rw [← Rat.divInt_eq_div]
Rat.num_den_mk d_ne_zero this
theorem mul_num_den' (q r : ℚ) :
(q * r).num * q.den * r.den = q.num * r.num * (q * r).den := by
let s := q.num * r.num /. (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (Nat.mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.num) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
rw [Int.mul_assoc, Int.mul_assoc, mul_eq_mul_left_iff, or_iff_not_imp_right]
intro
have h : _ = s := divInt_mul_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero)
rw [num_divInt_den, num_divInt_den] at h
rw [h, mul_comm, ← Rat.eq_iff_mul_eq_mul, ← divInt_eq_div]
theorem add_num_den' (q r : ℚ) :
(q + r).num * q.den * r.den = (q.num * r.den + r.num * q.den) * (q + r).den := by
let s := divInt (q.num * r.den + r.num * q.den) (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (Nat.mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.den + r.num * q.den) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
repeat rw [Int.mul_assoc]
apply mul_eq_mul_left_iff.2
rw [or_iff_not_imp_right]
intro
have h : _ = s := divInt_add_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero)
rw [num_divInt_den, num_divInt_den] at h
rw [h]
rw [mul_comm]
apply Rat.eq_iff_mul_eq_mul.mp
rw [← divInt_eq_div]
theorem substr_num_den' (q r : ℚ) :
(q - r).num * q.den * r.den = (q.num * r.den - r.num * q.den) * (q - r).den := by
rw [sub_eq_add_neg, sub_eq_add_neg, ← neg_mul, ← num_neg_eq_neg_num, ← den_neg_eq_den r,
add_num_den' q (-r)]
end Casts
protected theorem inv_neg (q : ℚ) : (-q)⁻¹ = -q⁻¹ := by
rw [← num_divInt_den q]
simp only [Rat.neg_divInt, Rat.inv_divInt', eq_self_iff_true, Rat.divInt_neg]
theorem num_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : Nat.Coprime a.natAbs b.natAbs) :
(a / b : ℚ).num = a := by
lift b to ℕ using hb0.le
simp only [Int.natAbs_natCast, Int.ofNat_pos] at h hb0
rw [← Rat.divInt_eq_div, ← mk_eq_divInt _ _ hb0.ne' h]
theorem den_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : Nat.Coprime a.natAbs b.natAbs) :
((a / b : ℚ).den : ℤ) = b := by
lift b to ℕ using hb0.le
simp only [Int.natAbs_natCast, Int.ofNat_pos] at h hb0
rw [← Rat.divInt_eq_div, ← mk_eq_divInt _ _ hb0.ne' h]
theorem div_int_inj {a b c d : ℤ} (hb0 : 0 < b) (hd0 : 0 < d) (h1 : Nat.Coprime a.natAbs b.natAbs)
(h2 : Nat.Coprime c.natAbs d.natAbs) (h : (a : ℚ) / b = (c : ℚ) / d) : a = c ∧ b = d := by
apply And.intro
· rw [← num_div_eq_of_coprime hb0 h1, h, num_div_eq_of_coprime hd0 h2]
· rw [← den_div_eq_of_coprime hb0 h1, h, den_div_eq_of_coprime hd0 h2]
@[norm_cast]
theorem intCast_div_self (n : ℤ) : ((n / n : ℤ) : ℚ) = n / n := by
by_cases hn : n = 0
· subst hn
simp only [Int.cast_zero, Int.zero_tdiv, zero_div, Int.ediv_zero]
· have : (n : ℚ) ≠ 0 := by rwa [← coe_int_inj] at hn
simp only [Int.ediv_self hn, Int.cast_one, Ne, not_false_iff, div_self this]
@[norm_cast]
theorem natCast_div_self (n : ℕ) : ((n / n : ℕ) : ℚ) = n / n :=
intCast_div_self n
theorem intCast_div (a b : ℤ) (h : b ∣ a) : ((a / b : ℤ) : ℚ) = a / b := by
rcases h with ⟨c, rfl⟩
rw [mul_comm b, Int.mul_ediv_assoc c (dvd_refl b), Int.cast_mul,
intCast_div_self, Int.cast_mul, mul_div_assoc]
theorem natCast_div (a b : ℕ) (h : b ∣ a) : ((a / b : ℕ) : ℚ) = a / b :=
intCast_div a b (Int.ofNat_dvd.mpr h)
theorem den_div_intCast_eq_one_iff (m n : ℤ) (hn : n ≠ 0) : ((m : ℚ) / n).den = 1 ↔ n ∣ m := by
replace hn : (n : ℚ) ≠ 0 := num_ne_zero.mp hn
constructor
· rw [Rat.den_eq_one_iff, eq_div_iff hn]
exact mod_cast (Dvd.intro_left _)
· exact (intCast_div _ _ · ▸ rfl)
theorem den_div_natCast_eq_one_iff (m n : ℕ) (hn : n ≠ 0) : ((m : ℚ) / n).den = 1 ↔ n ∣ m :=
(den_div_intCast_eq_one_iff m n (Int.ofNat_ne_zero.mpr hn)).trans Int.ofNat_dvd
theorem inv_intCast_num_of_pos {a : ℤ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 := by
rw [← ofInt_eq_cast, ofInt, mk_eq_divInt, Rat.inv_divInt', divInt_eq_div, Nat.cast_one]
apply num_div_eq_of_coprime ha0
rw [Int.natAbs_one]
exact Nat.coprime_one_left _
theorem inv_natCast_num_of_pos {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 :=
inv_intCast_num_of_pos (mod_cast ha0 : 0 < (a : ℤ))
theorem inv_intCast_den_of_pos {a : ℤ} (ha0 : 0 < a) : ((a : ℚ)⁻¹.den : ℤ) = a := by
rw [← ofInt_eq_cast, ofInt, mk_eq_divInt, Rat.inv_divInt', divInt_eq_div, Nat.cast_one]
apply den_div_eq_of_coprime ha0
rw [Int.natAbs_one]
exact Nat.coprime_one_left _
| Mathlib/Data/Rat/Lemmas.lean | 247 | 252 | theorem inv_natCast_den_of_pos {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.den = a := by | rw [← Int.ofNat_inj, ← Int.cast_natCast a, inv_intCast_den_of_pos]
rwa [Int.natCast_pos]
@[simp]
theorem inv_intCast_num (a : ℤ) : (a : ℚ)⁻¹.num = Int.sign a := by |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.RingTheory.Ideal.Operations
/-!
# Maps on modules and ideals
Main definitions include `Ideal.map`, `Ideal.comap`, `RingHom.ker`, `Module.annihilator`
and `Submodule.annihilator`.
-/
assert_not_exists Basis -- See `RingTheory.Ideal.Basis`
Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations`
universe u v w x
open Pointwise
namespace Ideal
section MapAndComap
variable {R : Type u} {S : Type v}
section Semiring
variable {F : Type*} [Semiring R] [Semiring S]
variable [FunLike F R S]
variable (f : F)
variable {I J : Ideal R} {K L : Ideal S}
/-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than
the image itself. -/
def map (I : Ideal R) : Ideal S :=
span (f '' I)
/-- `I.comap f` is the preimage of `I` under `f`. -/
def comap [RingHomClass F R S] (I : Ideal S) : Ideal R where
carrier := f ⁻¹' I
add_mem' {x y} hx hy := by
simp only [Set.mem_preimage, SetLike.mem_coe, map_add f] at hx hy ⊢
exact add_mem hx hy
zero_mem' := by simp only [Set.mem_preimage, map_zero, SetLike.mem_coe, Submodule.zero_mem]
smul_mem' c x hx := by
simp only [smul_eq_mul, Set.mem_preimage, map_mul, SetLike.mem_coe] at *
exact mul_mem_left I _ hx
@[simp]
theorem coe_comap [RingHomClass F R S] (I : Ideal S) : (comap f I : Set R) = f ⁻¹' I := rfl
lemma comap_coe [RingHomClass F R S] (I : Ideal S) : I.comap (f : R →+* S) = I.comap f := rfl
lemma map_coe [RingHomClass F R S] (I : Ideal R) : I.map (f : R →+* S) = I.map f := rfl
variable {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono <| Set.image_subset _ h
theorem mem_map_of_mem (f : F) {I : Ideal R} {x : R} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem apply_coe_mem_map (f : F) (I : Ideal R) (x : I) : f x ∈ I.map f :=
mem_map_of_mem f x.2
theorem map_le_iff_le_comap [RingHomClass F R S] : map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans Set.image_subset_iff
@[simp]
theorem mem_comap [RingHomClass F R S] {x} : x ∈ comap f K ↔ f x ∈ K :=
Iff.rfl
theorem comap_mono [RingHomClass F R S] (h : K ≤ L) : comap f K ≤ comap f L :=
Set.preimage_mono fun _ hx => h hx
variable (f)
theorem comap_ne_top [RingHomClass F R S] (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 <| by rw [mem_comap, map_one]; exact (ne_top_iff_one _).1 hK
lemma exists_ideal_comap_le_prime {S} [CommSemiring S] [FunLike F R S] [RingHomClass F R S]
{f : F} (P : Ideal R) [P.IsPrime] (I : Ideal S) (le : I.comap f ≤ P) :
∃ Q ≥ I, Q.IsPrime ∧ Q.comap f ≤ P :=
have ⟨Q, hQ, hIQ, disj⟩ := I.exists_le_prime_disjoint (P.primeCompl.map f) <|
Set.disjoint_left.mpr fun _ ↦ by rintro hI ⟨r, hp, rfl⟩; exact hp (le hI)
⟨Q, hIQ, hQ, fun r hp' ↦ of_not_not fun hp ↦ Set.disjoint_left.mp disj hp' ⟨_, hp, rfl⟩⟩
variable {G : Type*} [FunLike G S R]
theorem map_le_comap_of_inv_on [RingHomClass G S R] (g : G) (I : Ideal R)
(hf : Set.LeftInvOn g f I) :
I.map f ≤ I.comap g := by
refine Ideal.span_le.2 ?_
rintro x ⟨x, hx, rfl⟩
rw [SetLike.mem_coe, mem_comap, hf hx]
exact hx
theorem comap_le_map_of_inv_on [RingHomClass F R S] (g : G) (I : Ideal S)
(hf : Set.LeftInvOn g f (f ⁻¹' I)) :
I.comap f ≤ I.map g :=
fun x (hx : f x ∈ I) => hf hx ▸ Ideal.mem_map_of_mem g hx
/-- The `Ideal` version of `Set.image_subset_preimage_of_inverse`. -/
theorem map_le_comap_of_inverse [RingHomClass G S R] (g : G) (I : Ideal R)
(h : Function.LeftInverse g f) :
I.map f ≤ I.comap g :=
map_le_comap_of_inv_on _ _ _ <| h.leftInvOn _
variable [RingHomClass F R S]
instance (priority := low) [K.IsTwoSided] : (comap f K).IsTwoSided :=
⟨fun b ha ↦ by rw [mem_comap, map_mul]; exact mul_mem_right _ _ ha⟩
/-- The `Ideal` version of `Set.preimage_subset_image_of_inverse`. -/
theorem comap_le_map_of_inverse (g : G) (I : Ideal S) (h : Function.LeftInverse g f) :
I.comap f ≤ I.map g :=
comap_le_map_of_inv_on _ _ _ <| h.leftInvOn _
instance IsPrime.comap [hK : K.IsPrime] : (comap f K).IsPrime :=
⟨comap_ne_top _ hK.1, fun {x y} => by simp only [mem_comap, map_mul]; apply hK.2⟩
variable (I J K L)
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 <| subset_span ⟨1, trivial, map_one f⟩
theorem gc_map_comap : GaloisConnection (Ideal.map f) (Ideal.comap f) := fun _ _ =>
Ideal.map_le_iff_le_comap
@[simp]
theorem comap_id : I.comap (RingHom.id R) = I :=
Ideal.ext fun _ => Iff.rfl
@[simp]
lemma comap_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.comap (AlgHom.id R S) I = I :=
I.comap_id
@[simp]
theorem map_id : I.map (RingHom.id R) = I :=
(gc_map_comap (RingHom.id R)).l_unique GaloisConnection.id comap_id
@[simp]
lemma map_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.map (AlgHom.id R S) I = I :=
I.map_id
theorem comap_comap {T : Type*} [Semiring T] {I : Ideal T} (f : R →+* S) (g : S →+* T) :
(I.comap g).comap f = I.comap (g.comp f) :=
rfl
lemma comap_comapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal C} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.comap g).comap f = I.comap (g.comp f) :=
I.comap_comap f.toRingHom g.toRingHom
theorem map_map {T : Type*} [Semiring T] {I : Ideal R} (f : R →+* S) (g : S →+* T) :
(I.map f).map g = I.map (g.comp f) :=
((gc_map_comap f).compose (gc_map_comap g)).l_unique (gc_map_comap (g.comp f)) fun _ =>
comap_comap _ _
lemma map_mapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal A} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.map f).map g = I.map (g.comp f) :=
I.map_map f.toRingHom g.toRingHom
theorem map_span (f : F) (s : Set R) : map f (span s) = span (f '' s) := by
refine (Submodule.span_eq_of_le _ ?_ ?_).symm
· rintro _ ⟨x, hx, rfl⟩; exact mem_map_of_mem f (subset_span hx)
· rw [map_le_iff_le_comap, span_le, coe_comap, ← Set.image_subset_iff]
exact subset_span
variable {f I J K L}
theorem map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K :=
(gc_map_comap f).l_le
theorem le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f :=
(gc_map_comap f).le_u
theorem le_comap_map : I ≤ (I.map f).comap f :=
(gc_map_comap f).le_u_l _
theorem map_comap_le : (K.comap f).map f ≤ K :=
(gc_map_comap f).l_u_le _
@[simp]
theorem comap_top : (⊤ : Ideal S).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp]
theorem comap_eq_top_iff {I : Ideal S} : I.comap f = ⊤ ↔ I = ⊤ :=
⟨fun h => I.eq_top_iff_one.mpr (map_one f ▸ mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)),
fun h => by rw [h, comap_top]⟩
@[simp]
theorem map_bot : (⊥ : Ideal R).map f = ⊥ :=
(gc_map_comap f).l_bot
theorem ne_bot_of_map_ne_bot (hI : map f I ≠ ⊥) : I ≠ ⊥ :=
fun h => hI (Eq.mpr (congrArg (fun I ↦ map f I = ⊥) h) map_bot)
variable (f I J K L)
@[simp]
theorem map_comap_map : ((I.map f).comap f).map f = I.map f :=
(gc_map_comap f).l_u_l_eq_l I
@[simp]
theorem comap_map_comap : ((K.comap f).map f).comap f = K.comap f :=
(gc_map_comap f).u_l_u_eq_u K
theorem map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L :=
rfl
variable {ι : Sort*}
theorem map_iSup (K : ι → Ideal R) : (iSup K).map f = ⨆ i, (K i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
theorem comap_iInf (K : ι → Ideal S) : (iInf K).comap f = ⨅ i, (K i).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
theorem map_sSup (s : Set (Ideal R)) : (sSup s).map f = ⨆ I ∈ s, (I : Ideal R).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sSup
theorem comap_sInf (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ s, (I : Ideal S).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_sInf
theorem comap_sInf' (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ comap f '' s, I :=
_root_.trans (comap_sInf f s) (by rw [iInf_image])
/-- Variant of `Ideal.IsPrime.comap` where ideal is explicit rather than implicit. -/
theorem comap_isPrime [H : IsPrime K] : IsPrime (comap f K) :=
H.comap f
variable {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_l.map_inf_le _ _
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_u.le_map_sup _ _
-- TODO: Should these be simp lemmas?
theorem _root_.element_smul_restrictScalars {R S M}
[CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M]
[Module R M] [Module S M] [IsScalarTower R S M] (r : R) (N : Submodule S M) :
(algebraMap R S r • N).restrictScalars R = r • N.restrictScalars R :=
SetLike.coe_injective (congrArg (· '' _) (funext (algebraMap_smul S r)))
theorem smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S]
[Algebra R S] [AddCommMonoid M] [Module R M] [Module S M]
[IsScalarTower R S M] (I : Ideal R) (N : Submodule S M) :
(I.map (algebraMap R S) • N).restrictScalars R = I • N.restrictScalars R := by
simp_rw [map, Submodule.span_smul_eq, ← Submodule.coe_set_smul,
Submodule.set_smul_eq_iSup, ← element_smul_restrictScalars, iSup_image]
exact map_iSup₂ (Submodule.restrictScalarsLatticeHom R S M) _
@[simp]
theorem smul_top_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S]
(I : Ideal R) : I • (⊤ : Submodule R S) = (I.map (algebraMap R S)).restrictScalars R :=
Eq.trans (smul_restrictScalars I (⊤ : Ideal S)).symm <|
congrArg _ <| Eq.trans (Ideal.smul_eq_mul _ _) (Ideal.mul_top _)
@[simp]
theorem coe_restrictScalars {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I : Ideal S) : (I.restrictScalars R : Set S) = ↑I :=
rfl
/-- The smallest `S`-submodule that contains all `x ∈ I * y ∈ J`
is also the smallest `R`-submodule that does so. -/
@[simp]
theorem restrictScalars_mul {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I J : Ideal S) :
(I * J).restrictScalars R = I.restrictScalars R * J.restrictScalars R :=
rfl
section Surjective
section
variable (hf : Function.Surjective f)
include hf
open Function
theorem map_comap_of_surjective (I : Ideal S) : map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 le_rfl) fun s hsi =>
let ⟨r, hfrs⟩ := hf s
hfrs ▸ (mem_map_of_mem f <| show f r ∈ I from hfrs.symm ▸ hsi)
/-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the
identity -/
def giMapComap : GaloisInsertion (map f) (comap f) :=
GaloisInsertion.monotoneIntro (gc_map_comap f).monotone_u (gc_map_comap f).monotone_l
(fun _ => le_comap_map) (map_comap_of_surjective _ hf)
theorem map_surjective_of_surjective : Surjective (map f) :=
(giMapComap f hf).l_surjective
theorem comap_injective_of_surjective : Injective (comap f) :=
(giMapComap f hf).u_injective
theorem map_sup_comap_of_surjective (I J : Ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J :=
(giMapComap f hf).l_sup_u _ _
theorem map_iSup_comap_of_surjective (K : ι → Ideal S) : (⨆ i, (K i).comap f).map f = iSup K :=
(giMapComap f hf).l_iSup_u _
theorem map_inf_comap_of_surjective (I J : Ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J :=
(giMapComap f hf).l_inf_u _ _
theorem map_iInf_comap_of_surjective (K : ι → Ideal S) : (⨅ i, (K i).comap f).map f = iInf K :=
(giMapComap f hf).l_iInf_u _
theorem mem_image_of_mem_map_of_surjective {I : Ideal R} {y} (H : y ∈ map f I) : y ∈ f '' I :=
Submodule.span_induction (hx := H) (fun _ => id) ⟨0, I.zero_mem, map_zero f⟩
(fun _ _ _ _ ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩ =>
⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ map_add f _ _⟩)
fun c _ _ ⟨x, hxi, hxy⟩ =>
let ⟨d, hdc⟩ := hf c
⟨d * x, I.mul_mem_left _ hxi, hdc ▸ hxy ▸ map_mul f _ _⟩
theorem mem_map_iff_of_surjective {I : Ideal R} {y} : y ∈ map f I ↔ ∃ x, x ∈ I ∧ f x = y :=
⟨fun h => (Set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h), fun ⟨_, hx⟩ =>
hx.right ▸ mem_map_of_mem f hx.left⟩
theorem le_map_of_comap_le_of_surjective : comap f K ≤ I → K ≤ map f I := fun h =>
map_comap_of_surjective f hf K ▸ map_mono h
end
theorem map_comap_eq_self_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
(I : Ideal S) : map e (comap e I) = I :=
I.map_comap_of_surjective e (EquivLike.surjective e)
theorem map_eq_submodule_map (f : R →+* S) [h : RingHomSurjective f] (I : Ideal R) :
I.map f = Submodule.map f.toSemilinearMap I :=
Submodule.ext fun _ => mem_map_iff_of_surjective f h.1
instance (priority := low) (f : R →+* S) [RingHomSurjective f] (I : Ideal R) [I.IsTwoSided] :
(I.map f).IsTwoSided where
mul_mem_of_left b ha := by
rw [map_eq_submodule_map] at ha ⊢
obtain ⟨a, ha, rfl⟩ := ha
obtain ⟨b, rfl⟩ := f.surjective b
rw [RingHom.coe_toSemilinearMap, ← map_mul]
exact ⟨_, I.mul_mem_right _ ha, rfl⟩
open Function in
theorem IsMaximal.comap_piEvalRingHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
{i : ι} {I : Ideal (R i)} (h : I.IsMaximal) : (I.comap <| Pi.evalRingHom R i).IsMaximal := by
refine isMaximal_iff.mpr ⟨I.ne_top_iff_one.mp h.ne_top, fun J x le hxI hxJ ↦ ?_⟩
have ⟨r, y, hy, eq⟩ := h.exists_inv hxI
classical
convert J.add_mem (J.mul_mem_left (update 0 i r) hxJ)
(b := update 1 i y) (le <| by apply update_self i y 1 ▸ hy)
ext j
obtain rfl | ne := eq_or_ne j i
· simpa [eq_comm] using eq
· simp [update_of_ne ne]
theorem comap_le_comap_iff_of_surjective (hf : Function.Surjective f) (I J : Ideal S) :
comap f I ≤ comap f J ↔ I ≤ J :=
⟨fun h => (map_comap_of_surjective f hf I).symm.le.trans (map_le_of_le_comap h), fun h =>
le_comap_of_map_le ((map_comap_of_surjective f hf I).le.trans h)⟩
/-- The map on ideals induced by a surjective map preserves inclusion. -/
def orderEmbeddingOfSurjective (hf : Function.Surjective f) : Ideal S ↪o Ideal R where
toFun := comap f
inj' _ _ eq := SetLike.ext' (Set.preimage_injective.mpr hf <| SetLike.ext'_iff.mp eq)
map_rel_iff' := comap_le_comap_iff_of_surjective _ hf ..
theorem map_eq_top_or_isMaximal_of_surjective (hf : Function.Surjective f) {I : Ideal R}
(H : IsMaximal I) : map f I = ⊤ ∨ IsMaximal (map f I) :=
or_iff_not_imp_left.2 fun ne_top ↦ ⟨⟨ne_top, fun _J hJ ↦ comap_injective_of_surjective f hf <|
H.1.2 _ (le_comap_map.trans_lt <| (orderEmbeddingOfSurjective f hf).strictMono hJ)⟩⟩
end Surjective
section Injective
theorem comap_bot_le_of_injective (hf : Function.Injective f) : comap f ⊥ ≤ I := by
refine le_trans (fun x hx => ?_) bot_le
rw [mem_comap, Submodule.mem_bot, ← map_zero f] at hx
exact Eq.symm (hf hx) ▸ Submodule.zero_mem ⊥
theorem comap_bot_of_injective (hf : Function.Injective f) : Ideal.comap f ⊥ = ⊥ :=
le_bot_iff.mp (Ideal.comap_bot_le_of_injective f hf)
end Injective
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm (map f I) = I`. -/
@[simp]
theorem map_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.map (f : R →+* S)).map (f.symm : S →+* R) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, map_map,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, map_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`,
then `comap f (comap f.symm I) = I`. -/
@[simp]
theorem comap_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.comap (f.symm : S →+* R)).comap (f : R →+* S) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, comap_comap,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, comap_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f I = comap f.symm I`. -/
theorem map_comap_of_equiv {I : Ideal R} (f : R ≃+* S) : I.map (f : R →+* S) = I.comap f.symm :=
le_antisymm (Ideal.map_le_comap_of_inverse _ _ _ (Equiv.left_inv' _))
(Ideal.comap_le_map_of_inverse _ _ _ (Equiv.right_inv' _))
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f.symm I = map f I`. -/
@[simp]
theorem comap_symm {I : Ideal R} (f : R ≃+* S) : I.comap f.symm = I.map f :=
(map_comap_of_equiv f).symm
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm I = comap f I`. -/
@[simp]
theorem map_symm {I : Ideal S} (f : R ≃+* S) : I.map f.symm = I.comap f :=
map_comap_of_equiv (RingEquiv.symm f)
@[simp]
theorem symm_apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {y : S} :
f.symm y ∈ I ↔ y ∈ I.map f := by
rw [← comap_symm, mem_comap]
@[simp]
theorem apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {x : R} :
f x ∈ I.map f ↔ x ∈ I := by
rw [← comap_symm, Ideal.mem_comap, f.symm_apply_apply]
theorem mem_map_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{I : Ideal R} (y : S) : y ∈ map e I ↔ ∃ x ∈ I, e x = y := by
constructor
· intro h
simp_rw [show map e I = _ from map_comap_of_equiv (e : R ≃+* S)] at h
exact ⟨(e : R ≃+* S).symm y, h, (e : R ≃+* S).apply_symm_apply y⟩
· rintro ⟨x, hx, rfl⟩
exact mem_map_of_mem e hx
section Bijective
variable (hf : Function.Bijective f) {I : Ideal R} {K : Ideal S}
include hf
/-- Special case of the correspondence theorem for isomorphic rings -/
def relIsoOfBijective : Ideal S ≃o Ideal R where
toFun := comap f
invFun := map f
left_inv := map_comap_of_surjective _ hf.2
right_inv J :=
le_antisymm
(fun _ h ↦ have ⟨y, hy, eq⟩ := (mem_map_iff_of_surjective _ hf.2).mp h; hf.1 eq ▸ hy)
le_comap_map
map_rel_iff' {_ _} := by
refine ⟨fun h ↦ ?_, comap_mono⟩
have := map_mono (f := f) h
simpa only [Equiv.coe_fn_mk, map_comap_of_surjective f hf.2] using this
theorem comap_le_iff_le_map : comap f K ≤ I ↔ K ≤ map f I :=
⟨fun h => le_map_of_comap_le_of_surjective f hf.right h, fun h =>
(relIsoOfBijective f hf).right_inv I ▸ comap_mono h⟩
lemma comap_map_of_bijective : (I.map f).comap f = I :=
le_antisymm ((comap_le_iff_le_map f hf).mpr fun _ ↦ id) le_comap_map
theorem isMaximal_map_iff_of_bijective : IsMaximal (map f I) ↔ IsMaximal I := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).symm.isCoatom_iff _
theorem isMaximal_comap_iff_of_bijective : IsMaximal (comap f K) ↔ IsMaximal K := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).isCoatom_iff _
alias ⟨_, IsMaximal.map_bijective⟩ := isMaximal_map_iff_of_bijective
alias ⟨_, IsMaximal.comap_bijective⟩ := isMaximal_comap_iff_of_bijective
/-- A ring isomorphism sends a maximal ideal to a maximal ideal. -/
instance map_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal R} [hp : p.IsMaximal] : (map e p).IsMaximal :=
hp.map_bijective e (EquivLike.bijective e)
/-- The pullback of a maximal ideal under a ring isomorphism is a maximal ideal. -/
instance comap_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal S} [hp : p.IsMaximal] : (comap e p).IsMaximal :=
hp.comap_bijective e (EquivLike.bijective e)
theorem isMaximal_iff_of_bijective : (⊥ : Ideal R).IsMaximal ↔ (⊥ : Ideal S).IsMaximal :=
⟨fun h ↦ map_bot (f := f) ▸ h.map_bijective f hf, fun h ↦ have e := RingEquiv.ofBijective f hf
map_bot (f := e.symm) ▸ h.map_bijective _ e.symm.bijective⟩
@[deprecated (since := "2024-12-07")] alias map.isMaximal := IsMaximal.map_bijective
@[deprecated (since := "2024-12-07")] alias comap.isMaximal := IsMaximal.comap_bijective
@[deprecated (since := "2024-12-07")] alias RingEquiv.bot_maximal_iff := isMaximal_iff_of_bijective
end Bijective
end Semiring
section Ring
variable {F : Type*} [Ring R] [Ring S]
variable [FunLike F R S] [RingHomClass F R S] (f : F) {I : Ideal R}
section Surjective
theorem comap_map_of_surjective (hf : Function.Surjective f) (I : Ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm
(fun r h =>
let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h
Submodule.mem_sup.2
⟨s, hsi, r - s, (Submodule.mem_bot S).2 <| by rw [map_sub, hfsr, sub_self],
add_sub_cancel s r⟩)
(sup_le (map_le_iff_le_comap.1 le_rfl) (comap_mono bot_le))
/-- Correspondence theorem -/
def relIsoOfSurjective (hf : Function.Surjective f) :
Ideal S ≃o { p : Ideal R // comap f ⊥ ≤ p } where
toFun J := ⟨comap f J, comap_mono bot_le⟩
invFun I := map f I.1
left_inv J := map_comap_of_surjective f hf J
right_inv I :=
Subtype.eq <|
show comap f (map f I.1) = I.1 from
(comap_map_of_surjective f hf I).symm ▸ le_antisymm (sup_le le_rfl I.2) le_sup_left
map_rel_iff' {I1 I2} :=
⟨fun H => map_comap_of_surjective f hf I1 ▸ map_comap_of_surjective f hf I2 ▸ map_mono H,
comap_mono⟩
-- May not hold if `R` is a semiring: consider `ℕ →+* ZMod 2`.
theorem comap_isMaximal_of_surjective (hf : Function.Surjective f) {K : Ideal S} [H : IsMaximal K] :
IsMaximal (comap f K) := by
refine ⟨⟨comap_ne_top _ H.1.1, fun J hJ => ?_⟩⟩
suffices map f J = ⊤ by
have := congr_arg (comap f) this
rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this
rw [eq_top_iff]
exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono bot_le) (le_of_lt hJ)))
refine
H.1.2 (map f J)
(lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ)) fun h =>
ne_of_lt hJ (_root_.trans (congr_arg (comap f) h) ?_))
rw [comap_map_of_surjective _ hf, sup_eq_left]
exact le_trans (comap_mono bot_le) (le_of_lt hJ)
end Surjective
end Ring
section CommRing
variable {F : Type*} [CommSemiring R] [CommSemiring S]
variable [FunLike F R S] [rc : RingHomClass F R S]
variable (f : F)
variable (I J : Ideal R) (K L : Ideal S)
protected theorem map_mul {R} [Semiring R] [FunLike F R S] [RingHomClass F R S]
(f : F) (I J : Ideal R) :
map f (I * J) = map f I * map f J :=
le_antisymm
(map_le_iff_le_comap.2 <|
mul_le.2 fun r hri s hsj =>
show (f (r * s)) ∈ map f I * map f J by
rw [map_mul]; exact mul_mem_mul (mem_map_of_mem f hri) (mem_map_of_mem f hsj))
(span_mul_span (↑f '' ↑I) (↑f '' ↑J) ▸ (span_le.2 <|
Set.iUnion₂_subset fun _ ⟨r, hri, hfri⟩ =>
Set.iUnion₂_subset fun _ ⟨s, hsj, hfsj⟩ =>
Set.singleton_subset_iff.2 <|
hfri ▸ hfsj ▸ by rw [← map_mul]; exact mem_map_of_mem f (mul_mem_mul hri hsj)))
/-- The pushforward `Ideal.map` as a (semi)ring homomorphism. -/
@[simps]
def mapHom : Ideal R →+* Ideal S where
toFun := map f
map_mul' := Ideal.map_mul f
map_one' := by simp only [one_eq_top]; exact Ideal.map_top f
map_add' I J := Ideal.map_sup f I J
map_zero' := Ideal.map_bot
protected theorem map_pow (n : ℕ) : map f (I ^ n) = map f I ^ n :=
map_pow (mapHom f) I n
theorem comap_radical : comap f (radical K) = radical (comap f K) := by
ext
simp [radical]
variable {K}
theorem IsRadical.comap (hK : K.IsRadical) : (comap f K).IsRadical := by
rw [← hK.radical, comap_radical]
apply radical_isRadical
variable {I J L}
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 fun r ⟨n, hrni⟩ => ⟨n, map_pow f r n ▸ mem_map_of_mem f hrni⟩
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 <|
(Ideal.map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 <| le_rfl) (map_le_iff_le_comap.2 <| le_rfl)
theorem le_comap_pow (n : ℕ) : K.comap f ^ n ≤ (K ^ n).comap f := by
induction' n with n n_ih
· rw [pow_zero, pow_zero, Ideal.one_eq_top, Ideal.one_eq_top]
exact rfl.le
· rw [pow_succ, pow_succ]
exact (Ideal.mul_mono_left n_ih).trans (Ideal.le_comap_mul f)
lemma disjoint_map_primeCompl_iff_comap_le {S : Type*} [Semiring S] {f : R →+* S}
{p : Ideal R} {I : Ideal S} [p.IsPrime] :
Disjoint (I : Set S) (p.primeCompl.map f) ↔ I.comap f ≤ p := by
rw [disjoint_comm]
simp [Set.disjoint_iff, Set.ext_iff, Ideal.primeCompl, not_imp_not, SetLike.le_def]
/-- For a prime ideal `p` of `R`, `p` extended to `S` and
restricted back to `R` is `p` if and only if `p` is the restriction of a prime in `S`. -/
lemma comap_map_eq_self_iff_of_isPrime {S : Type*} [CommSemiring S] {f : R →+* S}
(p : Ideal R) [p.IsPrime] :
(p.map f).comap f = p ↔ (∃ (q : Ideal S), q.IsPrime ∧ q.comap f = p) := by
refine ⟨fun hp ↦ ?_, ?_⟩
· obtain ⟨q, hq₁, hq₂, hq₃⟩ := Ideal.exists_le_prime_disjoint _ _
(disjoint_map_primeCompl_iff_comap_le.mpr hp.le)
exact ⟨q, hq₁, le_antisymm (disjoint_map_primeCompl_iff_comap_le.mp hq₃)
(map_le_iff_le_comap.mp hq₂)⟩
· rintro ⟨q, hq, rfl⟩
simp
end CommRing
end MapAndComap
end Ideal
namespace RingHom
variable {R : Type u} {S : Type v} {T : Type w}
section Semiring
variable {F : Type*} {G : Type*} [Semiring R] [Semiring S] [Semiring T]
variable [FunLike F R S] [rcf : RingHomClass F R S] [FunLike G T S] [rcg : RingHomClass G T S]
variable (f : F) (g : G)
/-- Kernel of a ring homomorphism as an ideal of the domain. -/
def ker : Ideal R :=
Ideal.comap f ⊥
instance (priority := low) : (ker f).IsTwoSided := inferInstanceAs (Ideal.comap f ⊥).IsTwoSided
variable {f} in
/-- An element is in the kernel if and only if it maps to zero. -/
@[simp] theorem mem_ker {r} : r ∈ ker f ↔ f r = 0 := by rw [ker, Ideal.mem_comap, Submodule.mem_bot]
theorem ker_eq : (ker f : Set R) = Set.preimage f {0} :=
rfl
theorem ker_eq_comap_bot (f : F) : ker f = Ideal.comap f ⊥ :=
rfl
theorem comap_ker (f : S →+* R) (g : T →+* S) : (ker f).comap g = ker (f.comp g) := by
rw [RingHom.ker_eq_comap_bot, Ideal.comap_comap, RingHom.ker_eq_comap_bot]
/-- If the target is not the zero ring, then one is not in the kernel. -/
theorem not_one_mem_ker [Nontrivial S] (f : F) : (1 : R) ∉ ker f := by
rw [mem_ker, map_one]
exact one_ne_zero
theorem ker_ne_top [Nontrivial S] (f : F) : ker f ≠ ⊤ :=
(Ideal.ne_top_iff_one _).mpr <| not_one_mem_ker f
lemma _root_.Pi.ker_ringHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
(φ : ∀ i, S →+* R i) : ker (Pi.ringHom φ) = ⨅ i, ker (φ i) := by
ext x
simp [mem_ker, Ideal.mem_iInf, funext_iff]
@[simp]
theorem ker_rangeSRestrict (f : R →+* S) : ker f.rangeSRestrict = ker f :=
Ideal.ext fun _ ↦ Subtype.ext_iff
@[simp]
| Mathlib/RingTheory/Ideal/Maps.lean | 691 | 702 | theorem ker_coe_equiv (f : R ≃+* S) : ker (f : R →+* S) = ⊥ := by | ext; simp
theorem ker_coe_toRingHom : ker (f : R →+* S) = ker f := rfl
@[simp]
theorem ker_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') :
ker f = ⊥ := by
ext; simp
lemma ker_equiv_comp (f : R →+* S) (e : S ≃+* T) :
ker (e.toRingHom.comp f) = RingHom.ker f := by |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Operations
import Mathlib.Analysis.SpecificLimits.Basic
/-!
# Outer measures from functions
Given an arbitrary function `m : Set α → ℝ≥0∞` that sends `∅` to `0` we can define an outer
measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets
`sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function.
Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that
for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space.
## Main definitions and statements
* `OuterMeasure.boundedBy` is the greatest outer measure that is at most the given function.
If you know that the given function sends `∅` to `0`, then `OuterMeasure.ofFunction` is a
special case.
* `sInf_eq_boundedBy_sInfGen` is a characterization of the infimum of outer measures.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
* <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion>
## Tags
outer measure, Carathéodory-measurable, Carathéodory's criterion
-/
assert_not_exists Basis
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section OfFunction
variable {α : Type*}
/-- Given any function `m` assigning measures to sets satisfying `m ∅ = 0`, there is
a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. -/
protected def ofFunction (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0) : OuterMeasure α :=
let μ s := ⨅ (f : ℕ → Set α) (_ : s ⊆ ⋃ i, f i), ∑' i, m (f i)
{ measureOf := μ
empty :=
le_antisymm
((iInf_le_of_le fun _ => ∅) <| iInf_le_of_le (empty_subset _) <| by simp [m_empty])
(zero_le _)
mono := fun {_ _} hs => iInf_mono fun _ => iInf_mono' fun hb => ⟨hs.trans hb, le_rfl⟩
iUnion_nat := fun s _ =>
ENNReal.le_of_forall_pos_le_add <| by
intro ε hε (hb : (∑' i, μ (s i)) < ∞)
rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 hε).ne' ℕ with ⟨ε', hε', hl⟩
refine le_trans ?_ (add_le_add_left (le_of_lt hl) _)
rw [← ENNReal.tsum_add]
choose f hf using
show ∀ i, ∃ f : ℕ → Set α, (s i ⊆ ⋃ i, f i) ∧ (∑' i, m (f i)) < μ (s i) + ε' i by
intro i
have : μ (s i) < μ (s i) + ε' i :=
ENNReal.lt_add_right (ne_top_of_le_ne_top hb.ne <| ENNReal.le_tsum _)
(by simpa using (hε' i).ne')
rcases iInf_lt_iff.mp this with ⟨t, ht⟩
exists t
contrapose! ht
exact le_iInf ht
refine le_trans ?_ (ENNReal.tsum_le_tsum fun i => le_of_lt (hf i).2)
rw [← ENNReal.tsum_prod, ← Nat.pairEquiv.symm.tsum_eq]
refine iInf_le_of_le _ (iInf_le _ ?_)
apply iUnion_subset
intro i
apply Subset.trans (hf i).1
apply iUnion_subset
simp only [Nat.pairEquiv_symm_apply]
rw [iUnion_unpair]
intro j
apply subset_iUnion₂ i }
variable (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0)
/-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets
`tᵢ` that cover `s`. -/
theorem ofFunction_apply (s : Set α) :
OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, m (t n) :=
rfl
/-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets
`tᵢ` that cover `s`, with all `tᵢ` satisfying a predicate `P` such that `m` is infinite for sets
that don't satisfy `P`.
This is similar to `ofFunction_apply`, except that the sets `tᵢ` satisfy `P`.
The hypothesis `m_top` applies in particular to a function of the form `extend m'`. -/
theorem ofFunction_eq_iInf_mem {P : Set α → Prop} (m_top : ∀ s, ¬ P s → m s = ∞) (s : Set α) :
OuterMeasure.ofFunction m m_empty s =
⨅ (t : ℕ → Set α) (_ : ∀ i, P (t i)) (_ : s ⊆ ⋃ i, t i), ∑' i, m (t i) := by
rw [OuterMeasure.ofFunction_apply]
apply le_antisymm
· exact le_iInf fun t ↦ le_iInf fun _ ↦ le_iInf fun h ↦ iInf₂_le _ (by exact h)
· simp_rw [le_iInf_iff]
refine fun t ht_subset ↦ iInf_le_of_le t ?_
by_cases ht : ∀ i, P (t i)
· exact iInf_le_of_le ht (iInf_le_of_le ht_subset le_rfl)
· simp only [ht, not_false_eq_true, iInf_neg, top_le_iff]
push_neg at ht
obtain ⟨i, hti_not_mem⟩ := ht
have hfi_top : m (t i) = ∞ := m_top _ hti_not_mem
exact ENNReal.tsum_eq_top_of_eq_top ⟨i, hfi_top⟩
variable {m m_empty}
theorem ofFunction_le (s : Set α) : OuterMeasure.ofFunction m m_empty s ≤ m s :=
let f : ℕ → Set α := fun i => Nat.casesOn i s fun _ => ∅
iInf_le_of_le f <|
iInf_le_of_le (subset_iUnion f 0) <|
le_of_eq <| tsum_eq_single 0 <| by
rintro (_ | i)
· simp
· simp [f, m_empty]
theorem ofFunction_eq (s : Set α) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) :
OuterMeasure.ofFunction m m_empty s = m s :=
le_antisymm (ofFunction_le s) <|
le_iInf fun f => le_iInf fun hf => le_trans (m_mono hf) (m_subadd f)
theorem le_ofFunction {μ : OuterMeasure α} :
μ ≤ OuterMeasure.ofFunction m m_empty ↔ ∀ s, μ s ≤ m s :=
⟨fun H s => le_trans (H s) (ofFunction_le s), fun H _ =>
le_iInf fun f =>
le_iInf fun hs =>
le_trans (μ.mono hs) <| le_trans (measure_iUnion_le f) <| ENNReal.tsum_le_tsum fun _ => H _⟩
theorem isGreatest_ofFunction :
IsGreatest { μ : OuterMeasure α | ∀ s, μ s ≤ m s } (OuterMeasure.ofFunction m m_empty) :=
⟨fun _ => ofFunction_le _, fun _ => le_ofFunction.2⟩
theorem ofFunction_eq_sSup : OuterMeasure.ofFunction m m_empty = sSup { μ | ∀ s, μ s ≤ m s } :=
(@isGreatest_ofFunction α m m_empty).isLUB.sSup_eq.symm
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.ofFunction m m_empty`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem ofFunction_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
OuterMeasure.ofFunction m m_empty (s ∪ t) =
OuterMeasure.ofFunction m m_empty s + OuterMeasure.ofFunction m m_empty t := by
refine le_antisymm (measure_union_le _ _) (le_iInf₂ fun f hf ↦ ?_)
set μ := OuterMeasure.ofFunction m m_empty
rcases Classical.em (∃ i, (s ∩ f i).Nonempty ∧ (t ∩ f i).Nonempty) with (⟨i, hs, ht⟩ | he)
· calc
μ s + μ t ≤ ∞ := le_top
_ = m (f i) := (h (f i) hs ht).symm
_ ≤ ∑' i, m (f i) := ENNReal.le_tsum i
set I := fun s => { i : ℕ | (s ∩ f i).Nonempty }
have hd : Disjoint (I s) (I t) := disjoint_iff_inf_le.mpr fun i hi => he ⟨i, hi⟩
have hI : ∀ u ⊆ s ∪ t, μ u ≤ ∑' i : I u, μ (f i) := fun u hu =>
calc
μ u ≤ μ (⋃ i : I u, f i) :=
μ.mono fun x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hf (hu hx))
mem_iUnion.2 ⟨⟨i, ⟨x, hx, hi⟩⟩, hi⟩
_ ≤ ∑' i : I u, μ (f i) := measure_iUnion_le _
calc
μ s + μ t ≤ (∑' i : I s, μ (f i)) + ∑' i : I t, μ (f i) :=
add_le_add (hI _ subset_union_left) (hI _ subset_union_right)
_ = ∑' i : ↑(I s ∪ I t), μ (f i) :=
(ENNReal.summable.tsum_union_disjoint (f := fun i => μ (f i)) hd ENNReal.summable).symm
_ ≤ ∑' i, μ (f i) :=
(ENNReal.summable.tsum_le_tsum_of_inj (↑) Subtype.coe_injective (fun _ _ => zero_le _)
(fun _ => le_rfl) ENNReal.summable)
_ ≤ ∑' i, m (f i) := ENNReal.tsum_le_tsum fun i => ofFunction_le _
theorem comap_ofFunction {β} (f : β → α) (h : Monotone m ∨ Surjective f) :
comap f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f '' s)) (by simp; simp [m_empty]) := by
refine le_antisymm (le_ofFunction.2 fun s => ?_) fun s => ?_
· rw [comap_apply]
apply ofFunction_le
· rw [comap_apply, ofFunction_apply, ofFunction_apply]
refine iInf_mono' fun t => ⟨fun k => f ⁻¹' t k, ?_⟩
refine iInf_mono' fun ht => ?_
rw [Set.image_subset_iff, preimage_iUnion] at ht
refine ⟨ht, ENNReal.tsum_le_tsum fun n => ?_⟩
rcases h with hl | hr
exacts [hl (image_preimage_subset _ _), (congr_arg m (hr.image_preimage (t n))).le]
theorem map_ofFunction_le {β} (f : α → β) :
map f (OuterMeasure.ofFunction m m_empty) ≤
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty :=
le_ofFunction.2 fun s => by
rw [map_apply]
apply ofFunction_le
theorem map_ofFunction {β} {f : α → β} (hf : Injective f) :
map f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty := by
refine (map_ofFunction_le _).antisymm fun s => ?_
simp only [ofFunction_apply, map_apply, le_iInf_iff]
intro t ht
refine iInf_le_of_le (fun n => (range f)ᶜ ∪ f '' t n) (iInf_le_of_le ?_ ?_)
· rw [← union_iUnion, ← inter_subset, ← image_preimage_eq_inter_range, ← image_iUnion]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => le_of_eq ?_
simp [hf.preimage_image]
-- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)`
theorem restrict_ofFunction (s : Set α) (hm : Monotone m) :
restrict s (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun t => m (t ∩ s)) (by simp; simp [m_empty]) := by
rw [restrict]
simp only [inter_comm _ s, LinearMap.comp_apply]
rw [comap_ofFunction _ (Or.inl hm)]
simp only [map_ofFunction Subtype.coe_injective, Subtype.image_preimage_coe]
theorem smul_ofFunction {c : ℝ≥0∞} (hc : c ≠ ∞) : c • OuterMeasure.ofFunction m m_empty =
OuterMeasure.ofFunction (c • m) (by simp [m_empty]) := by
ext1 s
haveI : Nonempty { t : ℕ → Set α // s ⊆ ⋃ i, t i } := ⟨⟨fun _ => s, subset_iUnion (fun _ => s) 0⟩⟩
simp only [smul_apply, ofFunction_apply, ENNReal.tsum_mul_left, Pi.smul_apply, smul_eq_mul,
iInf_subtype']
rw [ENNReal.mul_iInf fun h => (hc h).elim]
end OfFunction
section BoundedBy
variable {α : Type*} (m : Set α → ℝ≥0∞)
/-- Given any function `m` assigning measures to sets, there is a unique maximal outer measure `μ`
satisfying `μ s ≤ m s` for all `s : Set α`. This is the same as `OuterMeasure.ofFunction`,
except that it doesn't require `m ∅ = 0`. -/
def boundedBy : OuterMeasure α :=
OuterMeasure.ofFunction (fun s => ⨆ _ : s.Nonempty, m s) (by simp [Set.not_nonempty_empty])
variable {m}
theorem boundedBy_le (s : Set α) : boundedBy m s ≤ m s :=
(ofFunction_le _).trans iSup_const_le
theorem boundedBy_eq_ofFunction (m_empty : m ∅ = 0) (s : Set α) :
boundedBy m s = OuterMeasure.ofFunction m m_empty s := by
have : (fun s : Set α => ⨆ _ : s.Nonempty, m s) = m := by
ext1 t
rcases t.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty, m_empty]
simp [boundedBy, this]
theorem boundedBy_apply (s : Set α) :
boundedBy m s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t),
∑' n, ⨆ _ : (t n).Nonempty, m (t n) := by
simp [boundedBy, ofFunction_apply]
theorem boundedBy_eq (s : Set α) (m_empty : m ∅ = 0) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) : boundedBy m s = m s := by
rw [boundedBy_eq_ofFunction m_empty, ofFunction_eq s m_mono m_subadd]
@[simp]
theorem boundedBy_eq_self (m : OuterMeasure α) : boundedBy m = m :=
ext fun _ => boundedBy_eq _ measure_empty (fun _ ht => measure_mono ht) measure_iUnion_le
theorem le_boundedBy {μ : OuterMeasure α} : μ ≤ boundedBy m ↔ ∀ s, μ s ≤ m s := by
rw [boundedBy , le_ofFunction, forall_congr']; intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty]
theorem le_boundedBy' {μ : OuterMeasure α} :
μ ≤ boundedBy m ↔ ∀ s : Set α, s.Nonempty → μ s ≤ m s := by
rw [le_boundedBy, forall_congr']
intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h]
@[simp]
theorem boundedBy_top : boundedBy (⊤ : Set α → ℝ≥0∞) = ⊤ := by
rw [eq_top_iff, le_boundedBy']
intro s hs
rw [top_apply hs]
exact le_rfl
@[simp]
theorem boundedBy_zero : boundedBy (0 : Set α → ℝ≥0∞) = 0 := by
rw [← coe_bot, eq_bot_iff]
apply boundedBy_le
theorem smul_boundedBy {c : ℝ≥0∞} (hc : c ≠ ∞) : c • boundedBy m = boundedBy (c • m) := by
simp only [boundedBy , smul_ofFunction hc]
congr 1 with s : 1
rcases s.eq_empty_or_nonempty with (rfl | hs) <;> simp [*]
theorem comap_boundedBy {β} (f : β → α)
(h : (Monotone fun s : { s : Set α // s.Nonempty } => m s) ∨ Surjective f) :
comap f (boundedBy m) = boundedBy fun s => m (f '' s) := by
refine (comap_ofFunction _ ?_).trans ?_
· refine h.imp (fun H s t hst => iSup_le fun hs => ?_) id
have ht : t.Nonempty := hs.mono hst
exact (@H ⟨s, hs⟩ ⟨t, ht⟩ hst).trans (le_iSup (fun _ : t.Nonempty => m t) ht)
· dsimp only [boundedBy]
congr with s : 1
rw [image_nonempty]
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.boundedBy m`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem boundedBy_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
boundedBy m (s ∪ t) = boundedBy m s + boundedBy m t :=
ofFunction_union_of_top_of_nonempty_inter fun u hs ht =>
top_unique <| (h u hs ht).ge.trans <| le_iSup (fun _ => m u) (hs.mono inter_subset_right)
end BoundedBy
section sInfGen
variable {α : Type*}
/-- Given a set of outer measures, we define a new function that on a set `s` is defined to be the
infimum of `μ(s)` for the outer measures `μ` in the collection. We ensure that this
function is defined to be `0` on `∅`, even if the collection of outer measures is empty.
The outer measure generated by this function is the infimum of the given outer measures. -/
def sInfGen (m : Set (OuterMeasure α)) (s : Set α) : ℝ≥0∞ :=
⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ s
theorem sInfGen_def (m : Set (OuterMeasure α)) (t : Set α) :
sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t :=
rfl
theorem sInf_eq_boundedBy_sInfGen (m : Set (OuterMeasure α)) :
sInf m = OuterMeasure.boundedBy (sInfGen m) := by
refine le_antisymm ?_ ?_
· refine le_boundedBy.2 fun s => le_iInf₂ fun μ hμ => ?_
apply sInf_le hμ
· refine le_sInf ?_
intro μ hμ t
exact le_trans (boundedBy_le t) (iInf₂_le μ hμ)
theorem iSup_sInfGen_nonempty {m : Set (OuterMeasure α)} (h : m.Nonempty) (t : Set α) :
⨆ _ : t.Nonempty, sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t := by
rcases t.eq_empty_or_nonempty with (rfl | ht)
· simp [biInf_const h]
· simp [ht, sInfGen_def]
/-- The value of the Infimum of a nonempty set of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply {m : Set (OuterMeasure α)} {s : Set α} (h : m.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) := by
simp_rw [sInf_eq_boundedBy_sInfGen, boundedBy_apply, iSup_sInfGen_nonempty h]
/-- The value of the Infimum of a set of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply' {m : Set (OuterMeasure α)} {s : Set α} (h : s.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) :=
m.eq_empty_or_nonempty.elim (fun hm => by simp [hm, h]) sInf_apply
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply {ι} [Nonempty ι] (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply (range_nonempty m)]
simp only [iInf_range]
/-- The value of the Infimum of a family of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply' {ι} (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply' hs]
simp only [iInf_range]
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply {ι} {I : Set ι} (hI : I.Nonempty) (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
haveI := hI.to_subtype
simp only [← iInf_subtype'', iInf_apply]
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply' {ι} (I : Set ι) (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
simp only [← iInf_subtype'', iInf_apply' _ hs]
theorem map_iInf_le {ι β} (f : α → β) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) ≤ ⨅ i, map f (m i) :=
(map_mono f).map_iInf_le
theorem comap_iInf {ι β} (f : α → β) (m : ι → OuterMeasure β) :
comap f (⨅ i, m i) = ⨅ i, comap f (m i) := by
refine ext_nonempty fun s hs => ?_
refine ((comap_mono f).map_iInf_le s).antisymm ?_
simp only [comap_apply, iInf_apply' _ hs, iInf_apply' _ (hs.image _), le_iInf_iff,
Set.image_subset_iff, preimage_iUnion]
refine fun t ht => iInf_le_of_le _ (iInf_le_of_le ht <| ENNReal.tsum_le_tsum fun k => ?_)
exact iInf_mono fun i => (m i).mono (image_preimage_subset _ _)
theorem map_iInf {ι β} {f : α → β} (hf : Injective f) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) = restrict (range f) (⨅ i, map f (m i)) := by
refine Eq.trans ?_ (map_comap _ _)
simp only [comap_iInf, comap_map hf]
theorem map_iInf_comap {ι β} [Nonempty ι] {f : α → β} (m : ι → OuterMeasure β) :
map f (⨅ i, comap f (m i)) = ⨅ i, map f (comap f (m i)) := by
refine (map_iInf_le _ _).antisymm fun s => ?_
simp only [map_apply, comap_apply, iInf_apply, le_iInf_iff]
refine fun t ht => iInf_le_of_le (fun n => f '' t n ∪ (range f)ᶜ) (iInf_le_of_le ?_ ?_)
· rw [← iUnion_union, Set.union_comm, ← inter_subset, ← image_iUnion, ←
image_preimage_eq_inter_range]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => iInf_mono fun i => (m i).mono ?_
simp only [preimage_union, preimage_compl, preimage_range, compl_univ, union_empty,
image_subset_iff]
exact subset_refl _
theorem map_biInf_comap {ι β} {I : Set ι} (hI : I.Nonempty) {f : α → β} (m : ι → OuterMeasure β) :
map f (⨅ i ∈ I, comap f (m i)) = ⨅ i ∈ I, map f (comap f (m i)) := by
haveI := hI.to_subtype
rw [← iInf_subtype'', ← iInf_subtype'']
exact map_iInf_comap _
theorem restrict_iInf_restrict {ι} (s : Set α) (m : ι → OuterMeasure α) :
restrict s (⨅ i, restrict s (m i)) = restrict s (⨅ i, m i) :=
calc restrict s (⨅ i, restrict s (m i))
_ = restrict (range ((↑) : s → α)) (⨅ i, restrict s (m i)) := by rw [Subtype.range_coe]
_ = map ((↑) : s → α) (⨅ i, comap (↑) (m i)) := (map_iInf Subtype.coe_injective _).symm
_ = restrict s (⨅ i, m i) := congr_arg (map ((↑) : s → α)) (comap_iInf _ _).symm
theorem restrict_iInf {ι} [Nonempty ι] (s : Set α) (m : ι → OuterMeasure α) :
restrict s (⨅ i, m i) = ⨅ i, restrict s (m i) :=
(congr_arg (map ((↑) : s → α)) (comap_iInf _ _)).trans (map_iInf_comap _)
| Mathlib/MeasureTheory/OuterMeasure/OfFunction.lean | 451 | 455 | theorem restrict_biInf {ι} {I : Set ι} (hI : I.Nonempty) (s : Set α) (m : ι → OuterMeasure α) :
restrict s (⨅ i ∈ I, m i) = ⨅ i ∈ I, restrict s (m i) := by | haveI := hI.to_subtype
rw [← iInf_subtype'', ← iInf_subtype'']
exact restrict_iInf _ _ |
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, Eric Wieser
-/
import Mathlib.Analysis.Normed.Lp.PiLp
import Mathlib.Analysis.InnerProductSpace.PiL2
/-!
# Matrices as a normed space
In this file we provide the following non-instances for norms on matrices:
* The elementwise norm:
* `Matrix.seminormedAddCommGroup`
* `Matrix.normedAddCommGroup`
* `Matrix.normedSpace`
* `Matrix.isBoundedSMul`
* The Frobenius norm:
* `Matrix.frobeniusSeminormedAddCommGroup`
* `Matrix.frobeniusNormedAddCommGroup`
* `Matrix.frobeniusNormedSpace`
* `Matrix.frobeniusNormedRing`
* `Matrix.frobeniusNormedAlgebra`
* `Matrix.frobeniusIsBoundedSMul`
* The $L^\infty$ operator norm:
* `Matrix.linftyOpSeminormedAddCommGroup`
* `Matrix.linftyOpNormedAddCommGroup`
* `Matrix.linftyOpNormedSpace`
* `Matrix.linftyOpIsBoundedSMul`
* `Matrix.linftyOpNonUnitalSemiNormedRing`
* `Matrix.linftyOpSemiNormedRing`
* `Matrix.linftyOpNonUnitalNormedRing`
* `Matrix.linftyOpNormedRing`
* `Matrix.linftyOpNormedAlgebra`
These are not declared as instances because there are several natural choices for defining the norm
of a matrix.
The norm induced by the identification of `Matrix m n 𝕜` with
`EuclideanSpace n 𝕜 →L[𝕜] EuclideanSpace m 𝕜` (i.e., the ℓ² operator norm) can be found in
`Analysis.CStarAlgebra.Matrix`. It is separated to avoid extraneous imports in this file.
-/
noncomputable section
open scoped NNReal Matrix
namespace Matrix
variable {R l m n α β ι : Type*} [Fintype l] [Fintype m] [Fintype n] [Unique ι]
/-! ### The elementwise supremum norm -/
section LinfLinf
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β]
/-- Seminormed group instance (using sup norm of sup norm) for matrices over a seminormed group. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
protected def seminormedAddCommGroup : SeminormedAddCommGroup (Matrix m n α) :=
Pi.seminormedAddCommGroup
attribute [local instance] Matrix.seminormedAddCommGroup
theorem norm_def (A : Matrix m n α) : ‖A‖ = ‖fun i j => A i j‖ := rfl
/-- The norm of a matrix is the sup of the sup of the nnnorm of the entries -/
lemma norm_eq_sup_sup_nnnorm (A : Matrix m n α) :
‖A‖ = Finset.sup Finset.univ fun i ↦ Finset.sup Finset.univ fun j ↦ ‖A i j‖₊ := by
simp_rw [Matrix.norm_def, Pi.norm_def, Pi.nnnorm_def]
theorem nnnorm_def (A : Matrix m n α) : ‖A‖₊ = ‖fun i j => A i j‖₊ := rfl
theorem norm_le_iff {r : ℝ} (hr : 0 ≤ r) {A : Matrix m n α} : ‖A‖ ≤ r ↔ ∀ i j, ‖A i j‖ ≤ r := by
simp_rw [norm_def, pi_norm_le_iff_of_nonneg hr]
| Mathlib/Analysis/Matrix.lean | 88 | 89 | theorem nnnorm_le_iff {r : ℝ≥0} {A : Matrix m n α} : ‖A‖₊ ≤ r ↔ ∀ i j, ‖A i j‖₊ ≤ r := by | simp_rw [nnnorm_def, pi_nnnorm_le_iff] |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Module.BigOperators
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Squarefree
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.Nat.Factorization.Induction
import Mathlib.Tactic.ArithMult
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `IsMultiplicative` when `x.Coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
* `ω n` is the number of distinct prime factors of `n`.
* `Ω n` is the number of prime factors of `n` counted with multiplicity.
* `μ` is the Möbius function (spelled `moebius` in code).
## Main Results
* Several forms of Möbius inversion:
* `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero`
* And variants that apply when the equalities only hold on a set `S : Set ℕ` such that
`m ∣ n → n ∈ S → m ∈ S`:
* `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero`
## Notation
All notation is localized in the namespace `ArithmeticFunction`.
The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names.
In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`,
`ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`,
`ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`,
to allow for selective access to these notations.
The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation
`∏ᵖ p ∣ n, f p` when applied to `n`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open Finset
open Nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by
Dirichlet convolution. -/
def ArithmeticFunction [Zero R] :=
ZeroHom ℕ R
instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) :=
inferInstanceAs (Zero (ZeroHom ℕ R))
instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R))
variable {R}
namespace ArithmeticFunction
section Zero
variable [Zero R]
instance : FunLike (ArithmeticFunction R) ℕ R :=
inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R)
@[simp]
theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl
@[simp]
theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _
(ZeroHom.mk f hf) = f := rfl
@[simp]
theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 :=
ZeroHom.map_zero' f
theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g :=
DFunLike.coe_fn_eq
@[simp]
theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 :=
ZeroHom.zero_apply x
@[ext]
theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g :=
ZeroHom.ext h
section One
variable [One R]
instance one : One (ArithmeticFunction R) :=
⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩
theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 :=
rfl
@[simp]
theorem one_one : (1 : ArithmeticFunction R) 1 = 1 :=
rfl
@[simp]
theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 :=
if_neg h
end One
end Zero
/-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline
this in `natCoe` because it gets unfolded too much. -/
@[coe]
def natToArithmeticFunction [AddMonoidWithOne R] :
(ArithmeticFunction ℕ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) :=
⟨natToArithmeticFunction⟩
@[simp]
theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f :=
ext fun _ => cast_id _
@[simp]
theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x :=
rfl
/-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline
this in `intCoe` because it gets unfolded too much. -/
@[coe]
def ofInt [AddGroupWithOne R] :
(ArithmeticFunction ℤ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) :=
⟨ofInt⟩
@[simp]
theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f :=
ext fun _ => Int.cast_id
@[simp]
theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x := rfl
@[simp]
theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} :
((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by
ext
simp
@[simp]
theorem natCoe_one [AddMonoidWithOne R] :
((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
@[simp]
theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) :
ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
section AddMonoid
variable [AddMonoid R]
instance add : Add (ArithmeticFunction R) :=
⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩
@[simp]
theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n :=
rfl
instance instAddMonoid : AddMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.zero R,
ArithmeticFunction.add with
add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _
zero_add := fun _ => ext fun _ => zero_add _
add_zero := fun _ => ext fun _ => add_zero _
nsmul := nsmulRec }
end AddMonoid
instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid,
ArithmeticFunction.one with
natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩
natCast_zero := by ext; simp
natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] }
instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ }
instance [NegZeroClass R] : Neg (ArithmeticFunction R) where
neg f := ⟨fun n => -f n, by simp⟩
instance [AddGroup R] : AddGroup (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with
neg_add_cancel := fun _ => ext fun _ => neg_add_cancel _
zsmul := zsmulRec }
instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) :=
{ show AddGroup (ArithmeticFunction R) by infer_instance with
add_comm := fun _ _ ↦ add_comm _ _ }
section SMul
variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) :=
⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩
@[simp]
theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} :
(f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd :=
rfl
end SMul
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance [Semiring R] : Mul (ArithmeticFunction R) :=
⟨(· • ·)⟩
@[simp]
theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} :
(f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd :=
rfl
theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp
@[simp, norm_cast]
theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} :
(↑(f * g) : ArithmeticFunction R) = f * g := by
ext n
simp
@[simp, norm_cast]
theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} :
(↑(f * g) : ArithmeticFunction R) = ↑f * g := by
ext n
simp
section Module
variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) :
(f * g) • h = f • g • h := by
ext n
simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma']
apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩)
(fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc)
theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by
ext x
rw [smul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y1ne : y.fst ≠ 1 := fun con => by simp_all [Prod.ext_iff]
simp [y1ne]
end Module
section Semiring
variable [Semiring R]
instance instMonoid : Monoid (ArithmeticFunction R) :=
{ one := One.one
mul := Mul.mul
one_mul := one_smul'
mul_one := fun f => by
ext x
rw [mul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro ⟨y₁, y₂⟩ ymem ynmem
have y2ne : y₂ ≠ 1 := by
intro con
simp_all
simp [y2ne]
mul_assoc := mul_smul' }
instance instSemiring : Semiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoidWithOne,
ArithmeticFunction.instMonoid,
ArithmeticFunction.instAddCommMonoid with
zero_mul := fun f => by
ext
simp
mul_zero := fun f => by
ext
simp
left_distrib := fun a b c => by
ext
simp [← sum_add_distrib, mul_add]
right_distrib := fun a b c => by
ext
simp [← sum_add_distrib, add_mul] }
end Semiring
instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
mul_comm := fun f g => by
ext
rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map]
simp [mul_comm] }
instance [CommRing R] : CommRing (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
neg_add_cancel := neg_add_cancel
mul_comm := mul_comm
zsmul := (· • ·) }
instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] :
Module (ArithmeticFunction R) (ArithmeticFunction M) where
one_smul := one_smul'
mul_smul := mul_smul'
smul_add r x y := by
ext
simp only [sum_add_distrib, smul_add, smul_apply, add_apply]
smul_zero r := by
ext
simp only [smul_apply, sum_const_zero, smul_zero, zero_apply]
add_smul r s x := by
ext
simp only [add_smul, sum_add_distrib, smul_apply, add_apply]
zero_smul r := by
ext
simp only [smul_apply, sum_const_zero, zero_smul, zero_apply]
section Zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/
def zeta : ArithmeticFunction ℕ :=
⟨fun x => ite (x = 0) 0 1, rfl⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta
@[inherit_doc]
scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta
@[simp]
theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 :=
rfl
theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 :=
if_neg h
-- Porting note: removed `@[simp]`, LHS not in normal form
theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [MulAction R M]
{f : ArithmeticFunction M} {x : ℕ} :
((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by
rw [smul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.snd
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul]
· rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(↑ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_smul_apply
theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [mul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.1
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one]
· rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_zeta_mul_apply]
theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_mul_zeta_apply]
end Zeta
open ArithmeticFunction
section Pmul
/-- This is the pointwise product of `ArithmeticFunction`s. -/
def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun x => f x * g x, by simp⟩
@[simp]
theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x :=
rfl
theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by
ext
simp [mul_comm]
lemma pmul_assoc [SemigroupWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) :
pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by
ext
simp only [pmul_apply, mul_assoc]
section NonAssocSemiring
variable [NonAssocSemiring R]
@[simp]
theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
@[simp]
theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
end NonAssocSemiring
variable [Semiring R]
/-- This is the pointwise power of `ArithmeticFunction`s. -/
def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R :=
if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩
@[simp]
theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl]
@[simp]
theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by
rw [ppow, dif_neg (Nat.ne_of_gt kpos), coe_mk]
theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ']
induction k <;> simp
theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ]
induction k <;> simp
end Pmul
section Pdiv
/-- This is the pointwise division of `ArithmeticFunction`s. -/
def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩
@[simp]
theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) :
pdiv f g n = f n / g n := rfl
/-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes
values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/
@[simp]
theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) :
pdiv f zeta = f := by
ext n
cases n <;> simp [succ_ne_zero]
end Pdiv
section ProdPrimeFactors
/-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/
def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where
toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p
map_zero' := if_pos rfl
open Batteries.ExtendedBinder
/-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/
scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term
scoped macro_rules (kind := bigproddvd)
| `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n)
@[simp]
theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f : ℕ → R} {n : ℕ} (hn : n ≠ 0) :
∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p :=
if_neg hn
end ProdPrimeFactors
/-- Multiplicative functions -/
def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop :=
f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n
namespace IsMultiplicative
section MonoidWithZero
variable [MonoidWithZero R]
@[simp, arith_mult]
theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 :=
h.1
@[simp]
theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ}
(h : m.Coprime n) : f (m * n) = f m * f n :=
hf.2 h
end MonoidWithZero
open scoped Function in -- required for scoped `on` notation
theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) :
f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by
classical
induction s using Finset.induction_on with
| empty => simp [hf]
| insert _ _ has ih =>
rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs
rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1]
exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm
theorem map_prod_of_prime [CommMonoidWithZero R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f)
(t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy
theorem map_prod_of_subset_primeFactors [CommMonoidWithZero R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ)
(t : Finset ℕ) (ht : t ⊆ l.primeFactors) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a)
| Mathlib/NumberTheory/ArithmeticFunction.lean | 577 | 580 | theorem map_div_of_coprime [GroupWithZero R] {f : ArithmeticFunction R}
(hf : IsMultiplicative f) {l d : ℕ} (hdl : d ∣ l) (hl : (l / d).Coprime d) (hd : f d ≠ 0) :
f (l / d) = f l / f d := by | apply (div_eq_of_eq_mul hd ..).symm |
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Antoine Chambert-Loir
-/
import Mathlib.Algebra.Group.Hom.CompTypeclasses
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Notation.Prod
import Mathlib.Algebra.Ring.Action.Basic
/-!
# Equivariant homomorphisms
## Main definitions
* `MulActionHom φ X Y`, the type of equivariant functions from `X` to `Y`,
where `φ : M → N` is a map, `M` acting on the type `X` and `N` acting on the type of `Y`.
`AddActionHom φ X Y` is its additive version.
* `DistribMulActionHom φ A B`,
the type of equivariant additive monoid homomorphisms from `A` to `B`,
where `φ : M → N` is a morphism of monoids,
`M` acting on the additive monoid `A` and `N` acting on the additive monoid of `B`
* `SMulSemiringHom φ R S`, the type of equivariant ring homomorphisms
from `R` to `S`, where `φ : M → N` is a morphism of monoids,
`M` acting on the ring `R` and `N` acting on the ring `S`.
The above types have corresponding classes:
* `MulActionHomClass F φ X Y` states that `F` is a type of bundled `X → Y` homs
which are `φ`-equivariant;
`AddActionHomClass F φ X Y` is its additive version.
* `DistribMulActionHomClass F φ A B` states that `F` is a type of bundled `A → B` homs
preserving the additive monoid structure and `φ`-equivariant
* `SMulSemiringHomClass F φ R S` states that `F` is a type of bundled `R → S` homs
preserving the ring structure and `φ`-equivariant
## Notation
We introduce the following notation to code equivariant maps
(the subscript index `ₑ` is for *equivariant*) :
* `X →ₑ[φ] Y` is `MulActionHom φ X Y` and `AddActionHom φ X Y`
* `A →ₑ+[φ] B` is `DistribMulActionHom φ A B`.
* `R →ₑ+*[φ] S` is `MulSemiringActionHom φ R S`.
When `M = N` and `φ = MonoidHom.id M`, we provide the backward compatible notation :
* `X →[M] Y` is `MulActionHom (@id M) X Y` and `AddActionHom (@id M) X Y`
* `A →+[M] B` is `DistribMulActionHom (MonoidHom.id M) A B`
* `R →+*[M] S` is `MulSemiringActionHom (MonoidHom.id M) R S`
The notation for `MulActionHom` and `AddActionHom` is the same, because it is unlikely
that it could lead to confusion — unless one needs types `M` and `X` with simultaneous
instances of `Mul M`, `Add M`, `SMul M X` and `VAdd M X`…
-/
assert_not_exists Submonoid
section MulActionHom
variable {M' : Type*}
variable {M : Type*} {N : Type*} {P : Type*}
variable (φ : M → N) (ψ : N → P) (χ : M → P)
variable (X : Type*) [SMul M X] [SMul M' X]
variable (Y : Type*) [SMul N Y] [SMul M' Y]
variable (Z : Type*) [SMul P Z]
/-- Equivariant functions :
When `φ : M → N` is a function, and types `X` and `Y` are endowed with additive actions
of `M` and `N`, a function `f : X → Y` is `φ`-equivariant if `f (m +ᵥ x) = (φ m) +ᵥ (f x)`. -/
structure AddActionHom {M N : Type*} (φ: M → N) (X : Type*) [VAdd M X] (Y : Type*) [VAdd N Y] where
/-- The underlying function. -/
protected toFun : X → Y
/-- The proposition that the function commutes with the additive actions. -/
protected map_vadd' : ∀ (m : M) (x : X), toFun (m +ᵥ x) = (φ m) +ᵥ toFun x
/-- Equivariant functions :
When `φ : M → N` is a function, and types `X` and `Y` are endowed with actions of `M` and `N`,
a function `f : X → Y` is `φ`-equivariant if `f (m • x) = (φ m) • (f x)`. -/
@[to_additive]
structure MulActionHom where
/-- The underlying function. -/
protected toFun : X → Y
/-- The proposition that the function commutes with the actions. -/
protected map_smul' : ∀ (m : M) (x : X), toFun (m • x) = (φ m) • toFun x
/- Porting note: local notation given a name, conflict with Algebra.Hom.GroupAction
see https://github.com/leanprover/lean4/issues/2000 -/
/-- `φ`-equivariant functions `X → Y`,
where `φ : M → N`, where `M` and `N` act on `X` and `Y` respectively. -/
notation:25 (name := «MulActionHomLocal≺») X " →ₑ[" φ:25 "] " Y:0 => MulActionHom φ X Y
/-- `M`-equivariant functions `X → Y` with respect to the action of `M`.
This is the same as `X →ₑ[@id M] Y`. -/
notation:25 (name := «MulActionHomIdLocal≺») X " →[" M:25 "] " Y:0 => MulActionHom (@id M) X Y
/-- `φ`-equivariant functions `X → Y`,
where `φ : M → N`, where `M` and `N` act additively on `X` and `Y` respectively
We use the same notation as for multiplicative actions, as conflicts are unlikely. -/
notation:25 (name := «AddActionHomLocal≺») X " →ₑ[" φ:25 "] " Y:0 => AddActionHom φ X Y
/-- `M`-equivariant functions `X → Y` with respect to the additive action of `M`.
This is the same as `X →ₑ[@id M] Y`.
We use the same notation as for multiplicative actions, as conflicts are unlikely. -/
notation:25 (name := «AddActionHomIdLocal≺») X " →[" M:25 "] " Y:0 => AddActionHom (@id M) X Y
/-- `AddActionSemiHomClass F φ X Y` states that
`F` is a type of morphisms which are `φ`-equivariant.
You should extend this class when you extend `AddActionHom`. -/
class AddActionSemiHomClass (F : Type*)
{M N : outParam Type*} (φ : outParam (M → N))
(X Y : outParam Type*) [VAdd M X] [VAdd N Y] [FunLike F X Y] : Prop where
/-- The proposition that the function preserves the action. -/
map_vaddₛₗ : ∀ (f : F) (c : M) (x : X), f (c +ᵥ x) = (φ c) +ᵥ (f x)
/-- `MulActionSemiHomClass F φ X Y` states that
`F` is a type of morphisms which are `φ`-equivariant.
You should extend this class when you extend `MulActionHom`. -/
@[to_additive]
class MulActionSemiHomClass (F : Type*)
{M N : outParam Type*} (φ : outParam (M → N))
(X Y : outParam Type*) [SMul M X] [SMul N Y] [FunLike F X Y] : Prop where
/-- The proposition that the function preserves the action. -/
map_smulₛₗ : ∀ (f : F) (c : M) (x : X), f (c • x) = (φ c) • (f x)
export MulActionSemiHomClass (map_smulₛₗ)
export AddActionSemiHomClass (map_vaddₛₗ)
/-- `MulActionHomClass F M X Y` states that `F` is a type of
morphisms which are equivariant with respect to actions of `M`
This is an abbreviation of `MulActionSemiHomClass`. -/
@[to_additive "`MulActionHomClass F M X Y` states that `F` is a type of
morphisms which are equivariant with respect to actions of `M`
This is an abbreviation of `MulActionSemiHomClass`."]
abbrev MulActionHomClass (F : Type*) (M : outParam Type*)
(X Y : outParam Type*) [SMul M X] [SMul M Y] [FunLike F X Y] :=
MulActionSemiHomClass F (@id M) X Y
@[to_additive] instance : FunLike (MulActionHom φ X Y) X Y where
coe := MulActionHom.toFun
coe_injective' f g h := by cases f; cases g; congr
@[to_additive (attr := simp)]
theorem map_smul {F M X Y : Type*} [SMul M X] [SMul M Y]
[FunLike F X Y] [MulActionHomClass F M X Y]
(f : F) (c : M) (x : X) : f (c • x) = c • f x :=
map_smulₛₗ f c x
@[to_additive]
instance : MulActionSemiHomClass (X →ₑ[φ] Y) φ X Y where
map_smulₛₗ := MulActionHom.map_smul'
initialize_simps_projections MulActionHom (toFun → apply)
initialize_simps_projections AddActionHom (toFun → apply)
namespace MulActionHom
variable {φ X Y}
variable {F : Type*} [FunLike F X Y]
/-- Turn an element of a type `F` satisfying `MulActionSemiHomClass F φ X Y`
into an actual `MulActionHom`.
This is declared as the default coercion from `F` to `MulActionSemiHom φ X Y`. -/
@[to_additive (attr := coe)
"Turn an element of a type `F` satisfying `AddActionSemiHomClass F φ X Y`
into an actual `AddActionHom`.
This is declared as the default coercion from `F` to `AddActionSemiHom φ X Y`."]
def _root_.MulActionSemiHomClass.toMulActionHom [MulActionSemiHomClass F φ X Y] (f : F) :
X →ₑ[φ] Y where
toFun := DFunLike.coe f
map_smul' := map_smulₛₗ f
/-- Any type satisfying `MulActionSemiHomClass` can be cast into `MulActionHom` via
`MulActionHomSemiClass.toMulActionHom`. -/
@[to_additive]
instance [MulActionSemiHomClass F φ X Y] : CoeTC F (X →ₑ[φ] Y) :=
⟨MulActionSemiHomClass.toMulActionHom⟩
variable (M' X Y F) in
/-- If Y/X/M forms a scalar tower, any map X → Y preserving X-action also preserves M-action. -/
@[to_additive]
theorem _root_.IsScalarTower.smulHomClass [MulOneClass X] [SMul X Y] [IsScalarTower M' X Y]
[MulActionHomClass F X X Y] : MulActionHomClass F M' X Y where
map_smulₛₗ f m x := by
rw [← mul_one (m • x), ← smul_eq_mul, map_smul, smul_assoc, ← map_smul,
smul_eq_mul, mul_one, id_eq]
@[to_additive]
protected theorem map_smul (f : X →[M'] Y) (m : M') (x : X) : f (m • x) = m • f x :=
map_smul f m x
@[to_additive (attr := ext)]
theorem ext {f g : X →ₑ[φ] Y} :
(∀ x, f x = g x) → f = g :=
DFunLike.ext f g
@[to_additive]
protected theorem congr_fun {f g : X →ₑ[φ] Y} (h : f = g) (x : X) :
f x = g x :=
DFunLike.congr_fun h _
/-- Two equal maps on scalars give rise to an equivariant map for identity -/
@[to_additive "Two equal maps on scalars give rise to an equivariant map for identity"]
def ofEq {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) : X →ₑ[φ'] Y where
toFun := f.toFun
map_smul' m a := h ▸ f.map_smul' m a
@[to_additive (attr := simp)]
theorem ofEq_coe {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) :
(f.ofEq h).toFun = f.toFun := rfl
@[to_additive (attr := simp)]
theorem ofEq_apply {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) (a : X) :
(f.ofEq h) a = f a :=
rfl
lemma _root_.FaithfulSMul.of_injective
[FaithfulSMul M' X] [MulActionHomClass F M' X Y] (f : F)
(hf : Function.Injective f) :
FaithfulSMul M' Y where
eq_of_smul_eq_smul {_ _} h := eq_of_smul_eq_smul fun m ↦ hf <| by simp_rw [map_smul, h]
variable {ψ χ} (M N)
/-- The identity map as an equivariant map. -/
@[to_additive "The identity map as an equivariant map."]
protected def id : X →[M] X :=
⟨id, fun _ _ => rfl⟩
variable {M N Z}
@[to_additive (attr := simp)]
theorem id_apply (x : X) :
MulActionHom.id M x = x :=
rfl
end MulActionHom
namespace MulActionHom
open MulActionHom
variable {φ ψ χ X Y Z}
-- attribute [instance] CompTriple.id_comp CompTriple.comp_id
/-- Composition of two equivariant maps. -/
@[to_additive "Composition of two equivariant maps."]
def comp (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [κ : CompTriple φ ψ χ] :
X →ₑ[χ] Z :=
⟨g ∘ f, fun m x =>
calc
g (f (m • x)) = g (φ m • f x) := by rw [map_smulₛₗ]
_ = ψ (φ m) • g (f x) := by rw [map_smulₛₗ]
_ = (ψ ∘ φ) m • g (f x) := rfl
_ = χ m • g (f x) := by rw [κ.comp_eq] ⟩
@[to_additive (attr := simp)]
theorem comp_apply
(g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [CompTriple φ ψ χ] (x : X) :
g.comp f x = g (f x) := rfl
@[to_additive (attr := simp)]
theorem id_comp (f : X →ₑ[φ] Y) :
(MulActionHom.id N).comp f = f :=
ext fun x => by rw [comp_apply, id_apply]
@[to_additive (attr := simp)]
theorem comp_id (f : X →ₑ[φ] Y) :
f.comp (MulActionHom.id M) = f :=
ext fun x => by rw [comp_apply, id_apply]
@[to_additive (attr := simp)]
theorem comp_assoc {Q T : Type*} [SMul Q T]
{η : P → Q} {θ : M → Q} {ζ : N → Q}
(h : Z →ₑ[η] T) (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y)
[CompTriple φ ψ χ] [CompTriple χ η θ]
[CompTriple ψ η ζ] [CompTriple φ ζ θ] :
h.comp (g.comp f) = (h.comp g).comp f :=
ext fun _ => rfl
variable {φ' : N → M}
variable {Y₁ : Type*} [SMul M Y₁]
/-- The inverse of a bijective equivariant map is equivariant. -/
@[to_additive (attr := simps) "The inverse of a bijective equivariant map is equivariant."]
def inverse (f : X →[M] Y₁) (g : Y₁ → X)
(h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : Y₁ →[M] X where
toFun := g
map_smul' m x :=
calc
g (m • x) = g (m • f (g x)) := by rw [h₂]
_ = g (f (m • g x)) := by simp only [map_smul, id_eq]
_ = m • g x := by rw [h₁]
/-- The inverse of a bijective equivariant map is equivariant. -/
@[to_additive (attr := simps) "The inverse of a bijective equivariant map is equivariant."]
def inverse' (f : X →ₑ[φ] Y) (g : Y → X) (k : Function.RightInverse φ' φ)
(h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) :
Y →ₑ[φ'] X where
toFun := g
map_smul' m x :=
calc
g (m • x) = g (m • f (g x)) := by rw [h₂]
_ = g ((φ (φ' m)) • f (g x)) := by rw [k]
_ = g (f (φ' m • g x)) := by rw [map_smulₛₗ]
_ = φ' m • g x := by rw [h₁]
@[to_additive]
lemma inverse_eq_inverse' (f : X →[M] Y₁) (g : Y₁ → X)
(h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) :
inverse f g h₁ h₂ = inverse' f g (congrFun rfl) h₁ h₂ := by
rfl
@[to_additive]
theorem inverse'_inverse'
{f : X →ₑ[φ] Y} {g : Y → X}
{k₁ : Function.LeftInverse φ' φ} {k₂ : Function.RightInverse φ' φ}
{h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} :
inverse' (inverse' f g k₂ h₁ h₂) f k₁ h₂ h₁ = f :=
ext fun _ => rfl
@[to_additive]
theorem comp_inverse' {f : X →ₑ[φ] Y} {g : Y → X}
{k₁ : Function.LeftInverse φ' φ} {k₂ : Function.RightInverse φ' φ}
{h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} :
(inverse' f g k₂ h₁ h₂).comp f (κ := CompTriple.comp_inv k₁)
= MulActionHom.id M := by
rw [MulActionHom.ext_iff]
intro x
simp only [comp_apply, inverse_apply, id_apply]
exact h₁ x
@[to_additive]
theorem inverse'_comp {f : X →ₑ[φ] Y} {g : Y → X}
{k₂ : Function.RightInverse φ' φ}
{h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} :
f.comp (inverse' f g k₂ h₁ h₂) (κ := CompTriple.comp_inv k₂) = MulActionHom.id N := by
rw [MulActionHom.ext_iff]
intro x
simp only [comp_apply, inverse_apply, id_apply]
exact h₂ x
/-- If actions of `M` and `N` on `α` commute,
then for `c : M`, `(c • · : α → α)` is an `N`-action homomorphism. -/
@[to_additive (attr := simps) "If additive actions of `M` and `N` on `α` commute,
then for `c : M`, `(c • · : α → α)` is an `N`-additive action homomorphism."]
def _root_.SMulCommClass.toMulActionHom {M} (N α : Type*)
[SMul M α] [SMul N α] [SMulCommClass M N α] (c : M) :
α →[N] α where
toFun := (c • ·)
map_smul' := smul_comm _
end MulActionHom
end MulActionHom
/-- Evaluation at a point as a `MulActionHom`. -/
@[to_additive (attr := simps) "Evaluation at a point as an `AddActionHom`."]
def Pi.evalMulActionHom {ι M : Type*} {X : ι → Type*} [∀ i, SMul M (X i)] (i : ι) :
(∀ i, X i) →[M] X i where
toFun := Function.eval i
map_smul' _ _ := rfl
namespace MulActionHom
section FstSnd
variable {M α β : Type*} [SMul M α] [SMul M β]
variable (M α β) in
/-- `Prod.fst` as a bundled `MulActionHom`. -/
@[to_additive (attr := simps -fullyApplied) "`Prod.fst` as a bundled `AddActionHom`."]
def fst : α × β →[M] α where
toFun := Prod.fst
map_smul' _ _ := rfl
variable (M α β) in
/-- `Prod.snd` as a bundled `MulActionHom`. -/
@[to_additive (attr := simps -fullyApplied) "`Prod.snd` as a bundled `AddActionHom`."]
def snd : α × β →[M] β where
toFun := Prod.snd
map_smul' _ _ := rfl
end FstSnd
variable {M N α β γ δ : Type*} [SMul M α] [SMul M β] [SMul N γ] [SMul N δ] {σ : M → N}
/-- If `f` and `g` are equivariant maps, then so is `x ↦ (f x, g x)`. -/
@[to_additive (attr := simps -fullyApplied) prod
"If `f` and `g` are equivariant maps, then so is `x ↦ (f x, g x)`."]
def prod (f : α →ₑ[σ] γ) (g : α →ₑ[σ] δ) : α →ₑ[σ] γ × δ where
toFun x := (f x, g x)
map_smul' _ _ := Prod.ext (map_smulₛₗ f _ _) (map_smulₛₗ g _ _)
@[to_additive (attr := simp) fst_comp_prod]
lemma fst_comp_prod (f : α →ₑ[σ] γ) (g : α →ₑ[σ] δ) : (fst _ _ _).comp (prod f g) = f := rfl
@[to_additive (attr := simp) snd_comp_prod]
lemma snd_comp_prod (f : α →ₑ[σ] γ) (g : α →ₑ[σ] δ) : (snd _ _ _).comp (prod f g) = g := rfl
@[to_additive (attr := simp) prod_fst_snd]
lemma prod_fst_snd : prod (fst M α β) (snd M α β) = .id .. := rfl
/-- If `f` and `g` are equivariant maps, then so is `(x, y) ↦ (f x, g y)`. -/
@[to_additive (attr := simps -fullyApplied) prodMap
"If `f` and `g` are equivariant maps, then so is `(x, y) ↦ (f x, g y)`."]
def prodMap (f : α →ₑ[σ] γ) (g : β →ₑ[σ] δ) : α × β →ₑ[σ] γ × δ where
toFun := Prod.map f g
__ := (f.comp (fst ..)).prod (g.comp (snd ..))
end MulActionHom
section DistribMulAction
variable {M : Type*} [Monoid M]
variable {N : Type*} [Monoid N]
variable {P : Type*} [Monoid P]
variable (φ : M →* N) (φ' : N →* M) (ψ : N →* P) (χ : M →* P)
variable (A : Type*) [AddMonoid A] [DistribMulAction M A]
variable (B : Type*) [AddMonoid B] [DistribMulAction N B]
variable (B₁ : Type*) [AddMonoid B₁] [DistribMulAction M B₁]
variable (C : Type*) [AddMonoid C] [DistribMulAction P C]
variable (A' : Type*) [AddGroup A'] [DistribMulAction M A']
variable (B' : Type*) [AddGroup B'] [DistribMulAction N B']
/-- Equivariant additive monoid homomorphisms. -/
structure DistribMulActionHom extends A →ₑ[φ] B, A →+ B
/-- Reinterpret an equivariant additive monoid homomorphism as an additive monoid homomorphism. -/
add_decl_doc DistribMulActionHom.toAddMonoidHom
/-- Reinterpret an equivariant additive monoid homomorphism as an equivariant function. -/
add_decl_doc DistribMulActionHom.toMulActionHom
/- Porting note: local notation given a name, conflict with Algebra.Hom.Freiman
see https://github.com/leanprover/lean4/issues/2000 -/
@[inherit_doc]
notation:25 (name := «DistribMulActionHomLocal≺»)
A " →ₑ+[" φ:25 "] " B:0 => DistribMulActionHom φ A B
@[inherit_doc]
notation:25 (name := «DistribMulActionHomIdLocal≺»)
A " →+[" M:25 "] " B:0 => DistribMulActionHom (MonoidHom.id M) A B
-- QUESTION/TODO : Impose that `φ` is a morphism of monoids?
/-- `DistribMulActionSemiHomClass F φ A B` states that `F` is a type of morphisms
preserving the additive monoid structure and equivariant with respect to `φ`.
You should extend this class when you extend `DistribMulActionSemiHom`. -/
class DistribMulActionSemiHomClass (F : Type*)
{M N : outParam Type*} (φ : outParam (M → N))
(A B : outParam Type*)
[Monoid M] [Monoid N]
[AddMonoid A] [AddMonoid B] [DistribMulAction M A] [DistribMulAction N B]
[FunLike F A B] : Prop
extends MulActionSemiHomClass F φ A B, AddMonoidHomClass F A B
/-- `DistribMulActionHomClass F M A B` states that `F` is a type of morphisms preserving
the additive monoid structure and equivariant with respect to the action of `M`.
It is an abbreviation to `DistribMulActionHomClass F (MonoidHom.id M) A B`
You should extend this class when you extend `DistribMulActionHom`. -/
abbrev DistribMulActionHomClass (F : Type*) (M : outParam Type*)
(A B : outParam Type*) [Monoid M] [AddMonoid A] [AddMonoid B]
[DistribMulAction M A] [DistribMulAction M B] [FunLike F A B] :=
DistribMulActionSemiHomClass F (MonoidHom.id M) A B
namespace DistribMulActionHom
instance : FunLike (A →ₑ+[φ] B) A B where
coe m := m.toFun
coe_injective' f g h := by
rcases f with ⟨tF, _, _⟩; rcases g with ⟨tG, _, _⟩
cases tF; cases tG; congr
instance : DistribMulActionSemiHomClass (A →ₑ+[φ] B) φ A B where
map_smulₛₗ m := m.map_smul'
map_zero := DistribMulActionHom.map_zero'
map_add := DistribMulActionHom.map_add'
variable {φ φ' A B B₁}
variable {F : Type*} [FunLike F A B]
/-- Turn an element of a type `F` satisfying `MulActionHomClass F M X Y` into an actual
`MulActionHom`. This is declared as the default coercion from `F` to `MulActionHom M X Y`. -/
@[coe]
def _root_.DistribMulActionSemiHomClass.toDistribMulActionHom
[DistribMulActionSemiHomClass F φ A B]
(f : F) : A →ₑ+[φ] B :=
{ (f : A →+ B), (f : A →ₑ[φ] B) with }
/-- Any type satisfying `MulActionHomClass` can be cast into `MulActionHom`
via `MulActionHomClass.toMulActionHom`. -/
instance [DistribMulActionSemiHomClass F φ A B] :
CoeTC F (A →ₑ+[φ] B) :=
⟨DistribMulActionSemiHomClass.toDistribMulActionHom⟩
/-- If `DistribMulAction` of `M` and `N` on `A` commute,
then for each `c : M`, `(c • ·)` is an `N`-action additive homomorphism. -/
@[simps]
def _root_.SMulCommClass.toDistribMulActionHom {M} (N A : Type*) [Monoid N] [AddMonoid A]
[DistribSMul M A] [DistribMulAction N A] [SMulCommClass M N A] (c : M) : A →+[N] A :=
{ SMulCommClass.toMulActionHom N A c,
DistribSMul.toAddMonoidHom _ c with
toFun := (c • ·) }
@[simp]
theorem toFun_eq_coe (f : A →ₑ+[φ] B) : f.toFun = f := rfl
@[norm_cast]
theorem coe_fn_coe (f : A →ₑ+[φ] B) : ⇑(f : A →+ B) = f :=
rfl
@[norm_cast]
theorem coe_fn_coe' (f : A →ₑ+[φ] B) : ⇑(f : A →ₑ[φ] B) = f :=
rfl
@[ext]
theorem ext {f g : A →ₑ+[φ] B} : (∀ x, f x = g x) → f = g :=
DFunLike.ext f g
protected theorem congr_fun {f g : A →ₑ+[φ] B} (h : f = g) (x : A) : f x = g x :=
DFunLike.congr_fun h _
theorem toMulActionHom_injective {f g : A →ₑ+[φ] B} (h : (f : A →ₑ[φ] B) = (g : A →ₑ[φ] B)) :
f = g := by
ext a
exact MulActionHom.congr_fun h a
theorem toAddMonoidHom_injective {f g : A →ₑ+[φ] B} (h : (f : A →+ B) = (g : A →+ B)) : f = g := by
ext a
exact DFunLike.congr_fun h a
protected theorem map_zero (f : A →ₑ+[φ] B) : f 0 = 0 :=
map_zero f
protected theorem map_add (f : A →ₑ+[φ] B) (x y : A) : f (x + y) = f x + f y :=
map_add f x y
protected theorem map_neg (f : A' →ₑ+[φ] B') (x : A') : f (-x) = -f x :=
map_neg f x
protected theorem map_sub (f : A' →ₑ+[φ] B') (x y : A') : f (x - y) = f x - f y :=
map_sub f x y
protected theorem map_smulₑ (f : A →ₑ+[φ] B) (m : M) (x : A) : f (m • x) = (φ m) • f x :=
map_smulₛₗ f m x
variable (M)
/-- The identity map as an equivariant additive monoid homomorphism. -/
protected def id : A →+[M] A :=
⟨MulActionHom.id _, rfl, fun _ _ => rfl⟩
@[simp]
| Mathlib/GroupTheory/GroupAction/Hom.lean | 560 | 561 | theorem id_apply (x : A) : DistribMulActionHom.id M x = x := by | rfl |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Shing Tak Lam, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.BigOperators.Ring.List
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Log
import Mathlib.Data.List.Palindrome
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
/-!
# Digits of a natural number
This provides a basic API for extracting the digits of a natural number in a given base,
and reconstructing numbers from their digits.
We also prove some divisibility tests based on digits, in particular completing
Theorem #85 from https://www.cs.ru.nl/~freek/100/.
Also included is a bound on the length of `Nat.toDigits` from core.
## TODO
A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b`
are numerals is not yet ported.
-/
namespace Nat
variable {n : ℕ}
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux0 : ℕ → List ℕ
| 0 => []
| n + 1 => [n + 1]
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux1 (n : ℕ) : List ℕ :=
List.replicate n 1
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ
| 0 => []
| n + 1 =>
((n + 1) % b) :: digitsAux b h ((n + 1) / b)
decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h
@[simp]
theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux]
theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) :
digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by
cases n
· cases w
· rw [digitsAux]
/-- `digits b n` gives the digits, in little-endian order,
of a natural number `n` in a specified base `b`.
In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`.
* For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`,
and the last digit is not zero.
This uniquely specifies the behaviour of `digits b`.
* For `b = 1`, we define `digits 1 n = List.replicate n 1`.
* For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`.
Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals.
In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`.
-/
def digits : ℕ → ℕ → List ℕ
| 0 => digitsAux0
| 1 => digitsAux1
| b + 2 => digitsAux (b + 2) (by norm_num)
@[simp]
theorem digits_zero (b : ℕ) : digits b 0 = [] := by
rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1]
theorem digits_zero_zero : digits 0 0 = [] :=
rfl
@[simp]
theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] :=
rfl
theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n]
| 0, h => (h rfl).elim
| _ + 1, _ => rfl
@[simp]
theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 :=
rfl
-- no `@[simp]`: dsimp can prove this
theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n :=
rfl
theorem digits_add_two_add_one (b n : ℕ) :
digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by
simp [digits, digitsAux_def]
@[simp]
lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) :
Nat.digits b n = n % b :: Nat.digits b (n / b) := by
rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one]
theorem digits_def' :
∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b)
| 0, h => absurd h (by decide)
| 1, h => absurd h (by decide)
| b + 2, _ => digitsAux_def _ (by simp) _
@[simp]
theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by
rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩
rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩
rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb]
theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) :
digits b (x + b * y) = x :: digits b y := by
rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩
cases y
· simp [hxb, hxy.resolve_right (absurd rfl)]
dsimp [digits]
rw [digitsAux_def]
· congr
· simp [Nat.add_mod, mod_eq_of_lt hxb]
· simp [add_mul_div_left, div_eq_of_lt hxb]
· apply Nat.succ_pos
-- If we had a function converting a list into a polynomial,
-- and appropriate lemmas about that function,
-- we could rewrite this in terms of that.
/-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them
as a number in semiring, as the little-endian digits in base `b`.
-/
def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α
| [] => 0
| h :: t => h + b * ofDigits b t
theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) :
ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by
induction' L with d L ih
· rfl
· dsimp [ofDigits]
rw [ih]
theorem ofDigits_eq_sum_mapIdx_aux (b : ℕ) (l : List ℕ) :
(l.zipWith ((fun a i : ℕ => a * b ^ (i + 1))) (List.range l.length)).sum =
b * (l.zipWith (fun a i => a * b ^ i) (List.range l.length)).sum := by
suffices
l.zipWith (fun a i : ℕ => a * b ^ (i + 1)) (List.range l.length) =
l.zipWith (fun a i=> b * (a * b ^ i)) (List.range l.length)
by simp [this]
congr; ext; simp [pow_succ]; ring
theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) :
ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by
rw [List.mapIdx_eq_zipIdx_map, List.zipIdx_eq_zip_range', List.map_zip_eq_zipWith,
ofDigits_eq_foldr, ← List.range_eq_range']
induction' L with hd tl hl
· simp
· simpa [List.range_succ_eq_map, List.zipWith_map_right, ofDigits_eq_sum_mapIdx_aux] using
Or.inl hl
@[simp]
theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl
@[simp]
theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits]
@[simp]
theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) :
ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits]
theorem ofDigits_cons {b hd} {tl : List ℕ} :
ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl
theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} :
ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by
induction' l1 with hd tl IH
· simp [ofDigits]
· rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ']
ring
@[norm_cast]
theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) :
((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by
induction' L with d L ih
· simp [ofDigits]
· dsimp [ofDigits]; push_cast; rw [ih]
@[norm_cast]
theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by
induction' L with d L _
· rfl
· dsimp [ofDigits]; push_cast; simp only
theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) :
∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0
| _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0
| _ :: _, h0, _, List.Mem.tail _ hL =>
digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL
theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b)
(w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by
induction' L with d L ih
· dsimp [ofDigits]
simp
· dsimp [ofDigits]
replace w₂ := w₂ (by simp)
rw [digits_add b h]
· rw [ih]
· intro l m
apply w₁
exact List.mem_cons_of_mem _ m
· intro h
rw [List.getLast_cons h] at w₂
convert w₂
· exact w₁ d List.mem_cons_self
· by_cases h' : L = []
· rcases h' with rfl
left
simpa using w₂
· right
contrapose! w₂
refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_
rw [List.getLast_cons h']
exact List.getLast_mem h'
theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by
rcases b with - | b
· rcases n with - | n
· rfl
· simp
· rcases b with - | b
· induction' n with n ih
· rfl
· rw [Nat.zero_add] at ih ⊢
simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ]
· induction n using Nat.strongRecOn with | ind n h => ?_
cases n
· rw [digits_zero]
rfl
· simp only [Nat.succ_eq_add_one, digits_add_two_add_one]
dsimp [ofDigits]
rw [h _ (Nat.div_lt_self' _ b)]
rw [Nat.mod_add_div]
theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by
induction L with
| nil => rfl
| cons _ _ ih => simp [ofDigits, List.sum_cons, ih]
/-!
### Properties
This section contains various lemmas of properties relating to `digits` and `ofDigits`.
-/
| Mathlib/Data/Nat/Digits.lean | 267 | 287 | theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by | constructor
· intro h
have : ofDigits b (digits b n) = ofDigits b [] := by rw [h]
convert this
rw [ofDigits_digits]
· rintro rfl
simp
theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 :=
not_congr digits_eq_nil_iff_eq_zero
theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) :
digits b n = (n % b) :: digits b (n / b) := by
rcases b with (_ | _ | b)
· rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero]
· norm_num at h
rcases n with (_ | n)
· norm_num at w
· simp only [digits_add_two_add_one, ne_eq] |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.PropInstances
import Mathlib.Order.GaloisConnection.Defs
/-!
# Heyting algebras
This file defines Heyting, co-Heyting and bi-Heyting algebras.
A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that
`a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`.
Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬`
such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`.
Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras.
From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean
algebras model classical logic.
Heyting algebras are the order theoretic equivalent of cartesian-closed categories.
## Main declarations
* `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation).
* `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement).
* `HeytingAlgebra`: Heyting algebra.
* `CoheytingAlgebra`: Co-Heyting algebra.
* `BiheytingAlgebra`: bi-Heyting algebra.
## References
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
## Tags
Heyting, Brouwer, algebra, implication, negation, intuitionistic
-/
assert_not_exists RelIso
open Function OrderDual
universe u
variable {ι α β : Type*}
/-! ### Notation -/
section
variable (α β)
instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) :=
⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩
instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) :=
⟨fun a => (¬a.1, ¬a.2)⟩
instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) :=
⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩
instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) :=
⟨fun a => (a.1ᶜ, a.2ᶜ)⟩
end
@[simp]
theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 :=
rfl
@[simp]
theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 :=
rfl
@[simp]
theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 :=
rfl
@[simp]
theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 :=
rfl
@[simp]
theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 :=
rfl
@[simp]
theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 :=
rfl
@[simp]
theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ :=
rfl
@[simp]
theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ :=
rfl
namespace Pi
variable {π : ι → Type*}
instance [∀ i, HImp (π i)] : HImp (∀ i, π i) :=
⟨fun a b i => a i ⇨ b i⟩
instance [∀ i, HNot (π i)] : HNot (∀ i, π i) :=
⟨fun a i => ¬a i⟩
theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i :=
rfl
theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i :=
rfl
@[simp]
theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i :=
rfl
@[simp]
theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i :=
rfl
end Pi
/-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called
Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`.
This generalizes `HeytingAlgebra` by not requiring a bottom element. -/
class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where
/-- `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)` -/
le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c
/-- A generalized co-Heyting algebra is a lattice with an additional binary
difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`.
This generalizes `CoheytingAlgebra` by not requiring a top element. -/
class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where
/-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting
implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. -/
class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where
/-- `aᶜ` is defined as `a ⇨ ⊥` -/
himp_bot (a : α) : a ⇨ ⊥ = aᶜ
/-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\`
such that `(· \ a)` is left adjoint to `(· ⊔ a)`. -/
class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
/-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/
class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where
/-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
-- See note [lower instance priority]
attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop
attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot
-- See note [lower instance priority]
instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α :=
{ bot_le := ‹HeytingAlgebra α›.bot_le }
-- See note [lower instance priority]
instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α :=
{ ‹CoheytingAlgebra α› with }
-- See note [lower instance priority]
instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] :
CoheytingAlgebra α :=
{ ‹BiheytingAlgebra α› with }
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/
abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α)
(le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
himp,
compl := fun a => himp a ⊥,
le_himp_iff,
himp_bot := fun _ => rfl }
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/
abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α)
(le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where
himp := (compl · ⊔ ·)
compl := compl
le_himp_iff := le_himp_iff
himp_bot _ := sup_bot_eq _
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/
abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α)
(sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
sdiff,
hnot := fun a => sdiff ⊤ a,
sdiff_le_iff,
top_sdiff := fun _ => rfl }
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/
abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α)
(sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where
sdiff a b := a ⊓ hnot b
hnot := hnot
sdiff_le_iff := sdiff_le_iff
top_sdiff _ := top_inf_eq _
/-! In this section, we'll give interpretations of these results in the Heyting algebra model of
intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and",
`⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are
the same in this logic.
See also `Prop.heytingAlgebra`. -/
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] {a b c d : α}
/-- `p → q → r ↔ p ∧ q → r` -/
@[simp]
theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c :=
GeneralizedHeytingAlgebra.le_himp_iff _ _ _
/-- `p → q → r ↔ q ∧ p → r` -/
theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm]
/-- `p → q → r ↔ q → p → r` -/
theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff']
/-- `p → q → p` -/
theorem le_himp : a ≤ b ⇨ a :=
le_himp_iff.2 inf_le_left
/-- `p → p → q ↔ p → q` -/
theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem]
/-- `p → p` -/
@[simp]
theorem himp_self : a ⇨ a = ⊤ :=
top_le_iff.1 <| le_himp_iff.2 inf_le_right
/-- `(p → q) ∧ p → q` -/
theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b :=
le_himp_iff.1 le_rfl
/-- `p ∧ (p → q) → q` -/
theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff]
/-- `p ∧ (p → q) ↔ p ∧ q` -/
@[simp]
theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b :=
le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp
/-- `(p → q) ∧ p ↔ q ∧ p` -/
@[simp]
theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm]
/-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic:
an implication holds iff the conclusion follows from the hypothesis. -/
@[simp]
theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq]
/-- `p → true`, `true → p ↔ p` -/
@[simp]
theorem himp_top : a ⇨ ⊤ = ⊤ :=
himp_eq_top_iff.2 le_top
@[simp]
theorem top_himp : ⊤ ⇨ a = a :=
eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq]
/-- `p → q → r ↔ p ∧ q → r` -/
theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c :=
eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc]
/-- `(q → r) → (p → q) → q → r` -/
theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by
rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc]
exact inf_le_left
@[simp]
theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by
simpa using @himp_le_himp_himp_himp
/-- `p → q → r ↔ q → p → r` -/
theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm]
@[simp]
theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem]
theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) :=
eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff]
theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) :=
eq_of_forall_le_iff fun d => by
rw [le_inf_iff, le_himp_comm, sup_le_iff]
simp_rw [le_himp_comm]
theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b :=
le_himp_iff.2 <| himp_inf_le.trans h
theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c :=
le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le
theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d :=
(himp_le_himp_right hab).trans <| himp_le_himp_left hcd
@[simp]
theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by
rw [sup_himp_distrib, himp_self, top_inf_eq]
@[simp]
theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by
rw [sup_himp_distrib, himp_self, inf_top_eq]
theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by
conv_rhs => rw [← @top_himp _ _ a]
rw [← h.eq_top, sup_himp_self_left]
theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b :=
h.symm.himp_eq_right
theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by
rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left]
| Mathlib/Order/Heyting/Basic.lean | 336 | 336 | theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by | |
/-
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.Algebra.Order.Group.Nat
import Mathlib.Topology.UniformSpace.Basic
/-!
# Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets.
-/
universe u v
open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity
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 ≤ 𝓤 α
/-- 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
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]
theorem cauchy_iff' {f : Filter α} :
Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s :=
(𝓤 α).basis_sets.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]
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⟩
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]
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
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⟩
theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g :=
h_c.mono h_le
theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) :=
⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩
theorem cauchy_pure {a : α} : Cauchy (pure a) :=
cauchy_nhds.mono (pure_le_nhds a)
theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α}
(h : Tendsto f l (𝓝 a)) : Cauchy (map f l) :=
cauchy_nhds.mono h
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]
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⟩
/-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and
`SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s`
one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y`
with `(x, y) ∈ s`, then `f` converges to `x`. -/
theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α}
(adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by
-- Consider a neighborhood `s` of `x`
intro s hs
-- Take an entourage twice smaller than `s`
rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩
-- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U`
rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩
apply mem_of_superset t_mem
-- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s`
exact fun z hz => hU (prodMk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl
/-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point
for `f`. -/
theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) :
f ≤ 𝓝 x :=
le_nhds_of_cauchy_adhp_aux
(fun s hs => by
obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs
use t, t_mem, ht
exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem))
theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) :
f ≤ 𝓝 x ↔ ClusterPt x f :=
⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩
nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f)
(hm : UniformContinuous m) : Cauchy (map m f) :=
⟨hf.1.map _,
calc
map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq
_ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right
_ ≤ 𝓤 β := hm⟩
nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f)
(hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] :
Cauchy (comap m f) :=
⟨‹_›,
calc
comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq
_ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right
_ ≤ 𝓤 α := hm⟩
theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f)
(hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α)
(_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) :=
hf.comap hm
/-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function
defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that
is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/
def CauchySeq [Preorder β] (u : β → α) :=
Cauchy (atTop.map u)
theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) :
Tendsto (Prod.map u u) atTop (𝓤 α) := by
simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right
theorem CauchySeq.nonempty [Preorder β] {u : β → α} (hu : CauchySeq u) : Nonempty β :=
@nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1
theorem CauchySeq.mem_entourage {β : Type*} [SemilatticeSup β] {u : β → α} (h : CauchySeq u)
{V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := by
haveI := h.nonempty
have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this
simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV
theorem Filter.Tendsto.cauchySeq [SemilatticeSup β] [Nonempty β] {f : β → α} {x}
(hx : Tendsto f atTop (𝓝 x)) : CauchySeq f :=
hx.cauchy_map
theorem cauchySeq_const [SemilatticeSup β] [Nonempty β] (x : α) : CauchySeq fun _ : β => x :=
tendsto_const_nhds.cauchySeq
theorem cauchySeq_iff_tendsto [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓤 α) :=
cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def]
theorem CauchySeq.comp_tendsto {γ} [Preorder β] [SemilatticeSup γ] [Nonempty γ] {f : β → α}
(hf : CauchySeq f) {g : γ → β} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) :=
⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩
theorem CauchySeq.comp_injective [SemilatticeSup β] [NoMaxOrder β] [Nonempty β] {u : ℕ → α}
(hu : CauchySeq u) {f : β → ℕ} (hf : Injective f) : CauchySeq (u ∘ f) :=
hu.comp_tendsto <| Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite.mono_left atTop_le_cofinite
theorem Function.Bijective.cauchySeq_comp_iff {f : ℕ → ℕ} (hf : Bijective f) (u : ℕ → α) :
CauchySeq (u ∘ f) ↔ CauchySeq u := by
refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩
lift f to ℕ ≃ ℕ using hf
simpa only [Function.comp_def, f.apply_symm_apply] using H.comp_injective f.symm.injective
theorem CauchySeq.subseq_subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α}
(hu : CauchySeq u) {f g : ℕ → ℕ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, ((u ∘ f ∘ φ) n, (u ∘ g ∘ φ) n) ∈ V n := by
rw [cauchySeq_iff_tendsto] at hu
exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV
-- todo: generalize this and other lemmas to a nonempty semilattice
theorem cauchySeq_iff' {u : ℕ → α} :
CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∀ᶠ k in atTop, k ∈ Prod.map u u ⁻¹' V :=
cauchySeq_iff_tendsto
theorem cauchySeq_iff {u : ℕ → α} :
CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∃ N, ∀ k ≥ N, ∀ l ≥ N, (u k, u l) ∈ V := by
simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply]
theorem CauchySeq.prodMap {γ δ} [UniformSpace β] [Preorder γ] [Preorder δ] {u : γ → α} {v : δ → β}
(hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by
simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv
@[deprecated (since := "2025-03-10")]
alias CauchySeq.prod_map := CauchySeq.prodMap
theorem CauchySeq.prodMk {γ} [UniformSpace β] [Preorder γ] {u : γ → α} {v : γ → β}
(hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) :=
haveI := hu.1.of_map
(Cauchy.prod hu hv).mono (tendsto_map.prodMk tendsto_map)
@[deprecated (since := "2025-03-10")]
alias CauchySeq.prod := CauchySeq.prodMk
theorem CauchySeq.eventually_eventually [Preorder β] {u : β → α} (hu : CauchySeq u)
{V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, (u k, u l) ∈ V :=
eventually_atTop_curry <| hu.tendsto_uniformity hV
theorem UniformContinuous.comp_cauchySeq {γ} [UniformSpace β] [Preorder γ] {f : α → β}
(hf : UniformContinuous f) {u : γ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) :=
hu.map hf
theorem CauchySeq.subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α}
(hu : CauchySeq u) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V n := by
have : ∀ n, ∃ N, ∀ k ≥ N, ∀ l ≥ k, (u l, u k) ∈ V n := fun n => by
rw [cauchySeq_iff] at hu
rcases hu _ (hV n) with ⟨N, H⟩
exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩
obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ∀ l ≥ φ n, (u l, u <| φ n) ∈ V n⟩ :=
extraction_forall_of_eventually' this
exact ⟨φ, φ_extr, fun n => hφ _ _ (φ_extr <| Nat.lt_add_one n).le⟩
theorem Filter.Tendsto.subseq_mem_entourage {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α}
{a : α} (hu : Tendsto u atTop (𝓝 a)) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ (u (φ 0), a) ∈ V 0 ∧
∀ n, (u <| φ (n + 1), u <| φ n) ∈ V (n + 1) := by
rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with ⟨n, hn⟩
rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with
⟨φ, φ_mono, hφV⟩
exact ⟨fun k => φ k + n, φ_mono.add_const _, hn _ le_add_self, hφV⟩
/-- If a Cauchy sequence has a convergent subsequence, then it converges. -/
theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder β] {u : β → α} (hu : CauchySeq u)
{ι : Type*} {f : ι → β} {p : Filter ι} [NeBot p] (hf : Tendsto f p atTop) {a : α}
(ha : Tendsto (u ∘ f) p (𝓝 a)) : Tendsto u atTop (𝓝 a) :=
le_nhds_of_cauchy_adhp hu (ha.mapClusterPt.of_comp hf)
/-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/
theorem cauchySeq_shift {u : ℕ → α} (k : ℕ) : CauchySeq (fun n ↦ u (n + k)) ↔ CauchySeq u := by
constructor <;> intro h
· rw [cauchySeq_iff] at h ⊢
intro V mV
obtain ⟨N, h⟩ := h V mV
use N + k
intro a ha b hb
convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega
· exact h.comp_tendsto (tendsto_add_atTop_nat k)
theorem Filter.HasBasis.cauchySeq_iff {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop}
{s : γ → Set (α × α)} (h : (𝓤 α).HasBasis p s) :
CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → (u m, u n) ∈ s i := by
rw [cauchySeq_iff_tendsto, ← prod_atTop_atTop_eq]
refine (atTop_basis.prod_self.tendsto_iff h).trans ?_
simp only [exists_prop, true_and, MapsTo, preimage, subset_def, Prod.forall, mem_prod_eq,
mem_setOf_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ ≤ _) β]
theorem Filter.HasBasis.cauchySeq_iff' {γ} [Nonempty β] [SemilatticeSup β] {u : β → α}
{p : γ → Prop} {s : γ → Set (α × α)} (H : (𝓤 α).HasBasis p s) :
CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ n ≥ N, (u n, u N) ∈ s i := by
refine H.cauchySeq_iff.trans ⟨fun h i hi => ?_, fun h i hi => ?_⟩
· exact (h i hi).imp fun N hN n hn => hN n hn N le_rfl
· rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩
rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩
refine (h j hj).imp fun N hN m hm n hn => hts ⟨u N, hjt ?_, ht' <| hjt ?_⟩
exacts [hN m hm, hN n hn]
theorem cauchySeq_of_controlled [SemilatticeSup β] [Nonempty β] (U : β → Set (α × α))
(hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) {f : β → α}
(hf : ∀ ⦃N m n : β⦄, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : CauchySeq f :=
cauchySeq_iff_tendsto.2
(by
intro s hs
rw [mem_map, mem_atTop_sets]
obtain ⟨N, hN⟩ := hU s hs
refine ⟨(N, N), fun mn hmn => ?_⟩
obtain ⟨m, n⟩ := mn
exact hN (hf hmn.1 hmn.2))
| Mathlib/Topology/UniformSpace/Cauchy.lean | 316 | 324 | theorem isComplete_iff_clusterPt {s : Set α} :
IsComplete s ↔ ∀ l, Cauchy l → l ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x l :=
forall₃_congr fun _ hl _ => exists_congr fun _ => and_congr_right fun _ =>
le_nhds_iff_adhp_of_cauchy hl
theorem isComplete_iff_ultrafilter {s : Set α} :
IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ↑l ≤ 𝓟 s → ∃ x ∈ s, ↑l ≤ 𝓝 x := by | refine ⟨fun h l => h l, fun H => isComplete_iff_clusterPt.2 fun l hl hls => ?_⟩
haveI := hl.1 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.RingTheory.Ideal.Operations
/-!
# Maps on modules and ideals
Main definitions include `Ideal.map`, `Ideal.comap`, `RingHom.ker`, `Module.annihilator`
and `Submodule.annihilator`.
-/
assert_not_exists Basis -- See `RingTheory.Ideal.Basis`
Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations`
universe u v w x
open Pointwise
namespace Ideal
section MapAndComap
variable {R : Type u} {S : Type v}
section Semiring
variable {F : Type*} [Semiring R] [Semiring S]
variable [FunLike F R S]
variable (f : F)
variable {I J : Ideal R} {K L : Ideal S}
/-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than
the image itself. -/
def map (I : Ideal R) : Ideal S :=
span (f '' I)
/-- `I.comap f` is the preimage of `I` under `f`. -/
def comap [RingHomClass F R S] (I : Ideal S) : Ideal R where
carrier := f ⁻¹' I
add_mem' {x y} hx hy := by
simp only [Set.mem_preimage, SetLike.mem_coe, map_add f] at hx hy ⊢
exact add_mem hx hy
zero_mem' := by simp only [Set.mem_preimage, map_zero, SetLike.mem_coe, Submodule.zero_mem]
smul_mem' c x hx := by
simp only [smul_eq_mul, Set.mem_preimage, map_mul, SetLike.mem_coe] at *
exact mul_mem_left I _ hx
@[simp]
theorem coe_comap [RingHomClass F R S] (I : Ideal S) : (comap f I : Set R) = f ⁻¹' I := rfl
lemma comap_coe [RingHomClass F R S] (I : Ideal S) : I.comap (f : R →+* S) = I.comap f := rfl
lemma map_coe [RingHomClass F R S] (I : Ideal R) : I.map (f : R →+* S) = I.map f := rfl
variable {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono <| Set.image_subset _ h
theorem mem_map_of_mem (f : F) {I : Ideal R} {x : R} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem apply_coe_mem_map (f : F) (I : Ideal R) (x : I) : f x ∈ I.map f :=
mem_map_of_mem f x.2
theorem map_le_iff_le_comap [RingHomClass F R S] : map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans Set.image_subset_iff
@[simp]
theorem mem_comap [RingHomClass F R S] {x} : x ∈ comap f K ↔ f x ∈ K :=
Iff.rfl
theorem comap_mono [RingHomClass F R S] (h : K ≤ L) : comap f K ≤ comap f L :=
Set.preimage_mono fun _ hx => h hx
variable (f)
theorem comap_ne_top [RingHomClass F R S] (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 <| by rw [mem_comap, map_one]; exact (ne_top_iff_one _).1 hK
lemma exists_ideal_comap_le_prime {S} [CommSemiring S] [FunLike F R S] [RingHomClass F R S]
{f : F} (P : Ideal R) [P.IsPrime] (I : Ideal S) (le : I.comap f ≤ P) :
∃ Q ≥ I, Q.IsPrime ∧ Q.comap f ≤ P :=
have ⟨Q, hQ, hIQ, disj⟩ := I.exists_le_prime_disjoint (P.primeCompl.map f) <|
Set.disjoint_left.mpr fun _ ↦ by rintro hI ⟨r, hp, rfl⟩; exact hp (le hI)
⟨Q, hIQ, hQ, fun r hp' ↦ of_not_not fun hp ↦ Set.disjoint_left.mp disj hp' ⟨_, hp, rfl⟩⟩
variable {G : Type*} [FunLike G S R]
theorem map_le_comap_of_inv_on [RingHomClass G S R] (g : G) (I : Ideal R)
(hf : Set.LeftInvOn g f I) :
I.map f ≤ I.comap g := by
refine Ideal.span_le.2 ?_
rintro x ⟨x, hx, rfl⟩
rw [SetLike.mem_coe, mem_comap, hf hx]
exact hx
theorem comap_le_map_of_inv_on [RingHomClass F R S] (g : G) (I : Ideal S)
(hf : Set.LeftInvOn g f (f ⁻¹' I)) :
I.comap f ≤ I.map g :=
fun x (hx : f x ∈ I) => hf hx ▸ Ideal.mem_map_of_mem g hx
/-- The `Ideal` version of `Set.image_subset_preimage_of_inverse`. -/
theorem map_le_comap_of_inverse [RingHomClass G S R] (g : G) (I : Ideal R)
(h : Function.LeftInverse g f) :
I.map f ≤ I.comap g :=
map_le_comap_of_inv_on _ _ _ <| h.leftInvOn _
variable [RingHomClass F R S]
instance (priority := low) [K.IsTwoSided] : (comap f K).IsTwoSided :=
⟨fun b ha ↦ by rw [mem_comap, map_mul]; exact mul_mem_right _ _ ha⟩
/-- The `Ideal` version of `Set.preimage_subset_image_of_inverse`. -/
theorem comap_le_map_of_inverse (g : G) (I : Ideal S) (h : Function.LeftInverse g f) :
I.comap f ≤ I.map g :=
comap_le_map_of_inv_on _ _ _ <| h.leftInvOn _
instance IsPrime.comap [hK : K.IsPrime] : (comap f K).IsPrime :=
⟨comap_ne_top _ hK.1, fun {x y} => by simp only [mem_comap, map_mul]; apply hK.2⟩
variable (I J K L)
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 <| subset_span ⟨1, trivial, map_one f⟩
theorem gc_map_comap : GaloisConnection (Ideal.map f) (Ideal.comap f) := fun _ _ =>
Ideal.map_le_iff_le_comap
@[simp]
theorem comap_id : I.comap (RingHom.id R) = I :=
Ideal.ext fun _ => Iff.rfl
@[simp]
lemma comap_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.comap (AlgHom.id R S) I = I :=
I.comap_id
@[simp]
theorem map_id : I.map (RingHom.id R) = I :=
(gc_map_comap (RingHom.id R)).l_unique GaloisConnection.id comap_id
@[simp]
lemma map_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.map (AlgHom.id R S) I = I :=
I.map_id
theorem comap_comap {T : Type*} [Semiring T] {I : Ideal T} (f : R →+* S) (g : S →+* T) :
(I.comap g).comap f = I.comap (g.comp f) :=
rfl
lemma comap_comapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal C} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.comap g).comap f = I.comap (g.comp f) :=
I.comap_comap f.toRingHom g.toRingHom
theorem map_map {T : Type*} [Semiring T] {I : Ideal R} (f : R →+* S) (g : S →+* T) :
(I.map f).map g = I.map (g.comp f) :=
((gc_map_comap f).compose (gc_map_comap g)).l_unique (gc_map_comap (g.comp f)) fun _ =>
comap_comap _ _
lemma map_mapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal A} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.map f).map g = I.map (g.comp f) :=
I.map_map f.toRingHom g.toRingHom
theorem map_span (f : F) (s : Set R) : map f (span s) = span (f '' s) := by
refine (Submodule.span_eq_of_le _ ?_ ?_).symm
· rintro _ ⟨x, hx, rfl⟩; exact mem_map_of_mem f (subset_span hx)
· rw [map_le_iff_le_comap, span_le, coe_comap, ← Set.image_subset_iff]
exact subset_span
variable {f I J K L}
theorem map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K :=
(gc_map_comap f).l_le
theorem le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f :=
(gc_map_comap f).le_u
theorem le_comap_map : I ≤ (I.map f).comap f :=
(gc_map_comap f).le_u_l _
theorem map_comap_le : (K.comap f).map f ≤ K :=
(gc_map_comap f).l_u_le _
@[simp]
theorem comap_top : (⊤ : Ideal S).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp]
theorem comap_eq_top_iff {I : Ideal S} : I.comap f = ⊤ ↔ I = ⊤ :=
⟨fun h => I.eq_top_iff_one.mpr (map_one f ▸ mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)),
fun h => by rw [h, comap_top]⟩
@[simp]
theorem map_bot : (⊥ : Ideal R).map f = ⊥ :=
(gc_map_comap f).l_bot
theorem ne_bot_of_map_ne_bot (hI : map f I ≠ ⊥) : I ≠ ⊥ :=
fun h => hI (Eq.mpr (congrArg (fun I ↦ map f I = ⊥) h) map_bot)
variable (f I J K L)
@[simp]
theorem map_comap_map : ((I.map f).comap f).map f = I.map f :=
(gc_map_comap f).l_u_l_eq_l I
@[simp]
theorem comap_map_comap : ((K.comap f).map f).comap f = K.comap f :=
(gc_map_comap f).u_l_u_eq_u K
theorem map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L :=
rfl
variable {ι : Sort*}
theorem map_iSup (K : ι → Ideal R) : (iSup K).map f = ⨆ i, (K i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
theorem comap_iInf (K : ι → Ideal S) : (iInf K).comap f = ⨅ i, (K i).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
theorem map_sSup (s : Set (Ideal R)) : (sSup s).map f = ⨆ I ∈ s, (I : Ideal R).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sSup
theorem comap_sInf (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ s, (I : Ideal S).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_sInf
theorem comap_sInf' (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ comap f '' s, I :=
_root_.trans (comap_sInf f s) (by rw [iInf_image])
/-- Variant of `Ideal.IsPrime.comap` where ideal is explicit rather than implicit. -/
theorem comap_isPrime [H : IsPrime K] : IsPrime (comap f K) :=
H.comap f
variable {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_l.map_inf_le _ _
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_u.le_map_sup _ _
-- TODO: Should these be simp lemmas?
theorem _root_.element_smul_restrictScalars {R S M}
[CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M]
[Module R M] [Module S M] [IsScalarTower R S M] (r : R) (N : Submodule S M) :
(algebraMap R S r • N).restrictScalars R = r • N.restrictScalars R :=
SetLike.coe_injective (congrArg (· '' _) (funext (algebraMap_smul S r)))
theorem smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S]
[Algebra R S] [AddCommMonoid M] [Module R M] [Module S M]
[IsScalarTower R S M] (I : Ideal R) (N : Submodule S M) :
(I.map (algebraMap R S) • N).restrictScalars R = I • N.restrictScalars R := by
simp_rw [map, Submodule.span_smul_eq, ← Submodule.coe_set_smul,
Submodule.set_smul_eq_iSup, ← element_smul_restrictScalars, iSup_image]
exact map_iSup₂ (Submodule.restrictScalarsLatticeHom R S M) _
@[simp]
theorem smul_top_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S]
(I : Ideal R) : I • (⊤ : Submodule R S) = (I.map (algebraMap R S)).restrictScalars R :=
Eq.trans (smul_restrictScalars I (⊤ : Ideal S)).symm <|
congrArg _ <| Eq.trans (Ideal.smul_eq_mul _ _) (Ideal.mul_top _)
@[simp]
theorem coe_restrictScalars {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I : Ideal S) : (I.restrictScalars R : Set S) = ↑I :=
rfl
/-- The smallest `S`-submodule that contains all `x ∈ I * y ∈ J`
is also the smallest `R`-submodule that does so. -/
@[simp]
theorem restrictScalars_mul {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I J : Ideal S) :
(I * J).restrictScalars R = I.restrictScalars R * J.restrictScalars R :=
rfl
section Surjective
section
variable (hf : Function.Surjective f)
include hf
open Function
theorem map_comap_of_surjective (I : Ideal S) : map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 le_rfl) fun s hsi =>
let ⟨r, hfrs⟩ := hf s
hfrs ▸ (mem_map_of_mem f <| show f r ∈ I from hfrs.symm ▸ hsi)
/-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the
identity -/
def giMapComap : GaloisInsertion (map f) (comap f) :=
GaloisInsertion.monotoneIntro (gc_map_comap f).monotone_u (gc_map_comap f).monotone_l
(fun _ => le_comap_map) (map_comap_of_surjective _ hf)
theorem map_surjective_of_surjective : Surjective (map f) :=
(giMapComap f hf).l_surjective
theorem comap_injective_of_surjective : Injective (comap f) :=
(giMapComap f hf).u_injective
theorem map_sup_comap_of_surjective (I J : Ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J :=
(giMapComap f hf).l_sup_u _ _
theorem map_iSup_comap_of_surjective (K : ι → Ideal S) : (⨆ i, (K i).comap f).map f = iSup K :=
(giMapComap f hf).l_iSup_u _
theorem map_inf_comap_of_surjective (I J : Ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J :=
(giMapComap f hf).l_inf_u _ _
theorem map_iInf_comap_of_surjective (K : ι → Ideal S) : (⨅ i, (K i).comap f).map f = iInf K :=
(giMapComap f hf).l_iInf_u _
theorem mem_image_of_mem_map_of_surjective {I : Ideal R} {y} (H : y ∈ map f I) : y ∈ f '' I :=
Submodule.span_induction (hx := H) (fun _ => id) ⟨0, I.zero_mem, map_zero f⟩
(fun _ _ _ _ ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩ =>
⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ map_add f _ _⟩)
fun c _ _ ⟨x, hxi, hxy⟩ =>
let ⟨d, hdc⟩ := hf c
⟨d * x, I.mul_mem_left _ hxi, hdc ▸ hxy ▸ map_mul f _ _⟩
theorem mem_map_iff_of_surjective {I : Ideal R} {y} : y ∈ map f I ↔ ∃ x, x ∈ I ∧ f x = y :=
⟨fun h => (Set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h), fun ⟨_, hx⟩ =>
hx.right ▸ mem_map_of_mem f hx.left⟩
theorem le_map_of_comap_le_of_surjective : comap f K ≤ I → K ≤ map f I := fun h =>
map_comap_of_surjective f hf K ▸ map_mono h
end
theorem map_comap_eq_self_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
(I : Ideal S) : map e (comap e I) = I :=
I.map_comap_of_surjective e (EquivLike.surjective e)
theorem map_eq_submodule_map (f : R →+* S) [h : RingHomSurjective f] (I : Ideal R) :
I.map f = Submodule.map f.toSemilinearMap I :=
Submodule.ext fun _ => mem_map_iff_of_surjective f h.1
instance (priority := low) (f : R →+* S) [RingHomSurjective f] (I : Ideal R) [I.IsTwoSided] :
(I.map f).IsTwoSided where
mul_mem_of_left b ha := by
rw [map_eq_submodule_map] at ha ⊢
obtain ⟨a, ha, rfl⟩ := ha
obtain ⟨b, rfl⟩ := f.surjective b
rw [RingHom.coe_toSemilinearMap, ← map_mul]
exact ⟨_, I.mul_mem_right _ ha, rfl⟩
open Function in
theorem IsMaximal.comap_piEvalRingHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
{i : ι} {I : Ideal (R i)} (h : I.IsMaximal) : (I.comap <| Pi.evalRingHom R i).IsMaximal := by
refine isMaximal_iff.mpr ⟨I.ne_top_iff_one.mp h.ne_top, fun J x le hxI hxJ ↦ ?_⟩
have ⟨r, y, hy, eq⟩ := h.exists_inv hxI
classical
convert J.add_mem (J.mul_mem_left (update 0 i r) hxJ)
(b := update 1 i y) (le <| by apply update_self i y 1 ▸ hy)
ext j
obtain rfl | ne := eq_or_ne j i
· simpa [eq_comm] using eq
· simp [update_of_ne ne]
theorem comap_le_comap_iff_of_surjective (hf : Function.Surjective f) (I J : Ideal S) :
comap f I ≤ comap f J ↔ I ≤ J :=
⟨fun h => (map_comap_of_surjective f hf I).symm.le.trans (map_le_of_le_comap h), fun h =>
le_comap_of_map_le ((map_comap_of_surjective f hf I).le.trans h)⟩
/-- The map on ideals induced by a surjective map preserves inclusion. -/
def orderEmbeddingOfSurjective (hf : Function.Surjective f) : Ideal S ↪o Ideal R where
toFun := comap f
inj' _ _ eq := SetLike.ext' (Set.preimage_injective.mpr hf <| SetLike.ext'_iff.mp eq)
map_rel_iff' := comap_le_comap_iff_of_surjective _ hf ..
theorem map_eq_top_or_isMaximal_of_surjective (hf : Function.Surjective f) {I : Ideal R}
(H : IsMaximal I) : map f I = ⊤ ∨ IsMaximal (map f I) :=
or_iff_not_imp_left.2 fun ne_top ↦ ⟨⟨ne_top, fun _J hJ ↦ comap_injective_of_surjective f hf <|
H.1.2 _ (le_comap_map.trans_lt <| (orderEmbeddingOfSurjective f hf).strictMono hJ)⟩⟩
end Surjective
section Injective
theorem comap_bot_le_of_injective (hf : Function.Injective f) : comap f ⊥ ≤ I := by
refine le_trans (fun x hx => ?_) bot_le
rw [mem_comap, Submodule.mem_bot, ← map_zero f] at hx
exact Eq.symm (hf hx) ▸ Submodule.zero_mem ⊥
theorem comap_bot_of_injective (hf : Function.Injective f) : Ideal.comap f ⊥ = ⊥ :=
le_bot_iff.mp (Ideal.comap_bot_le_of_injective f hf)
end Injective
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm (map f I) = I`. -/
@[simp]
theorem map_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.map (f : R →+* S)).map (f.symm : S →+* R) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, map_map,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, map_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`,
then `comap f (comap f.symm I) = I`. -/
@[simp]
theorem comap_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.comap (f.symm : S →+* R)).comap (f : R →+* S) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, comap_comap,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, comap_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f I = comap f.symm I`. -/
theorem map_comap_of_equiv {I : Ideal R} (f : R ≃+* S) : I.map (f : R →+* S) = I.comap f.symm :=
le_antisymm (Ideal.map_le_comap_of_inverse _ _ _ (Equiv.left_inv' _))
(Ideal.comap_le_map_of_inverse _ _ _ (Equiv.right_inv' _))
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f.symm I = map f I`. -/
@[simp]
theorem comap_symm {I : Ideal R} (f : R ≃+* S) : I.comap f.symm = I.map f :=
(map_comap_of_equiv f).symm
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm I = comap f I`. -/
@[simp]
theorem map_symm {I : Ideal S} (f : R ≃+* S) : I.map f.symm = I.comap f :=
map_comap_of_equiv (RingEquiv.symm f)
@[simp]
theorem symm_apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {y : S} :
f.symm y ∈ I ↔ y ∈ I.map f := by
rw [← comap_symm, mem_comap]
@[simp]
theorem apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {x : R} :
f x ∈ I.map f ↔ x ∈ I := by
rw [← comap_symm, Ideal.mem_comap, f.symm_apply_apply]
theorem mem_map_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{I : Ideal R} (y : S) : y ∈ map e I ↔ ∃ x ∈ I, e x = y := by
constructor
· intro h
simp_rw [show map e I = _ from map_comap_of_equiv (e : R ≃+* S)] at h
exact ⟨(e : R ≃+* S).symm y, h, (e : R ≃+* S).apply_symm_apply y⟩
· rintro ⟨x, hx, rfl⟩
exact mem_map_of_mem e hx
section Bijective
variable (hf : Function.Bijective f) {I : Ideal R} {K : Ideal S}
include hf
/-- Special case of the correspondence theorem for isomorphic rings -/
def relIsoOfBijective : Ideal S ≃o Ideal R where
toFun := comap f
invFun := map f
left_inv := map_comap_of_surjective _ hf.2
right_inv J :=
le_antisymm
(fun _ h ↦ have ⟨y, hy, eq⟩ := (mem_map_iff_of_surjective _ hf.2).mp h; hf.1 eq ▸ hy)
le_comap_map
map_rel_iff' {_ _} := by
refine ⟨fun h ↦ ?_, comap_mono⟩
have := map_mono (f := f) h
simpa only [Equiv.coe_fn_mk, map_comap_of_surjective f hf.2] using this
theorem comap_le_iff_le_map : comap f K ≤ I ↔ K ≤ map f I :=
⟨fun h => le_map_of_comap_le_of_surjective f hf.right h, fun h =>
(relIsoOfBijective f hf).right_inv I ▸ comap_mono h⟩
lemma comap_map_of_bijective : (I.map f).comap f = I :=
le_antisymm ((comap_le_iff_le_map f hf).mpr fun _ ↦ id) le_comap_map
theorem isMaximal_map_iff_of_bijective : IsMaximal (map f I) ↔ IsMaximal I := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).symm.isCoatom_iff _
theorem isMaximal_comap_iff_of_bijective : IsMaximal (comap f K) ↔ IsMaximal K := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).isCoatom_iff _
alias ⟨_, IsMaximal.map_bijective⟩ := isMaximal_map_iff_of_bijective
alias ⟨_, IsMaximal.comap_bijective⟩ := isMaximal_comap_iff_of_bijective
/-- A ring isomorphism sends a maximal ideal to a maximal ideal. -/
instance map_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal R} [hp : p.IsMaximal] : (map e p).IsMaximal :=
hp.map_bijective e (EquivLike.bijective e)
/-- The pullback of a maximal ideal under a ring isomorphism is a maximal ideal. -/
instance comap_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal S} [hp : p.IsMaximal] : (comap e p).IsMaximal :=
hp.comap_bijective e (EquivLike.bijective e)
theorem isMaximal_iff_of_bijective : (⊥ : Ideal R).IsMaximal ↔ (⊥ : Ideal S).IsMaximal :=
⟨fun h ↦ map_bot (f := f) ▸ h.map_bijective f hf, fun h ↦ have e := RingEquiv.ofBijective f hf
map_bot (f := e.symm) ▸ h.map_bijective _ e.symm.bijective⟩
@[deprecated (since := "2024-12-07")] alias map.isMaximal := IsMaximal.map_bijective
@[deprecated (since := "2024-12-07")] alias comap.isMaximal := IsMaximal.comap_bijective
@[deprecated (since := "2024-12-07")] alias RingEquiv.bot_maximal_iff := isMaximal_iff_of_bijective
end Bijective
end Semiring
section Ring
variable {F : Type*} [Ring R] [Ring S]
variable [FunLike F R S] [RingHomClass F R S] (f : F) {I : Ideal R}
section Surjective
theorem comap_map_of_surjective (hf : Function.Surjective f) (I : Ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm
(fun r h =>
let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h
Submodule.mem_sup.2
⟨s, hsi, r - s, (Submodule.mem_bot S).2 <| by rw [map_sub, hfsr, sub_self],
add_sub_cancel s r⟩)
(sup_le (map_le_iff_le_comap.1 le_rfl) (comap_mono bot_le))
/-- Correspondence theorem -/
def relIsoOfSurjective (hf : Function.Surjective f) :
Ideal S ≃o { p : Ideal R // comap f ⊥ ≤ p } where
toFun J := ⟨comap f J, comap_mono bot_le⟩
invFun I := map f I.1
left_inv J := map_comap_of_surjective f hf J
right_inv I :=
Subtype.eq <|
show comap f (map f I.1) = I.1 from
(comap_map_of_surjective f hf I).symm ▸ le_antisymm (sup_le le_rfl I.2) le_sup_left
map_rel_iff' {I1 I2} :=
⟨fun H => map_comap_of_surjective f hf I1 ▸ map_comap_of_surjective f hf I2 ▸ map_mono H,
comap_mono⟩
-- May not hold if `R` is a semiring: consider `ℕ →+* ZMod 2`.
theorem comap_isMaximal_of_surjective (hf : Function.Surjective f) {K : Ideal S} [H : IsMaximal K] :
IsMaximal (comap f K) := by
refine ⟨⟨comap_ne_top _ H.1.1, fun J hJ => ?_⟩⟩
suffices map f J = ⊤ by
have := congr_arg (comap f) this
rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this
rw [eq_top_iff]
exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono bot_le) (le_of_lt hJ)))
refine
H.1.2 (map f J)
(lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ)) fun h =>
ne_of_lt hJ (_root_.trans (congr_arg (comap f) h) ?_))
rw [comap_map_of_surjective _ hf, sup_eq_left]
exact le_trans (comap_mono bot_le) (le_of_lt hJ)
end Surjective
end Ring
section CommRing
variable {F : Type*} [CommSemiring R] [CommSemiring S]
variable [FunLike F R S] [rc : RingHomClass F R S]
variable (f : F)
variable (I J : Ideal R) (K L : Ideal S)
protected theorem map_mul {R} [Semiring R] [FunLike F R S] [RingHomClass F R S]
(f : F) (I J : Ideal R) :
map f (I * J) = map f I * map f J :=
le_antisymm
(map_le_iff_le_comap.2 <|
mul_le.2 fun r hri s hsj =>
show (f (r * s)) ∈ map f I * map f J by
rw [map_mul]; exact mul_mem_mul (mem_map_of_mem f hri) (mem_map_of_mem f hsj))
(span_mul_span (↑f '' ↑I) (↑f '' ↑J) ▸ (span_le.2 <|
Set.iUnion₂_subset fun _ ⟨r, hri, hfri⟩ =>
Set.iUnion₂_subset fun _ ⟨s, hsj, hfsj⟩ =>
Set.singleton_subset_iff.2 <|
hfri ▸ hfsj ▸ by rw [← map_mul]; exact mem_map_of_mem f (mul_mem_mul hri hsj)))
/-- The pushforward `Ideal.map` as a (semi)ring homomorphism. -/
@[simps]
def mapHom : Ideal R →+* Ideal S where
toFun := map f
map_mul' := Ideal.map_mul f
map_one' := by simp only [one_eq_top]; exact Ideal.map_top f
map_add' I J := Ideal.map_sup f I J
map_zero' := Ideal.map_bot
protected theorem map_pow (n : ℕ) : map f (I ^ n) = map f I ^ n :=
map_pow (mapHom f) I n
theorem comap_radical : comap f (radical K) = radical (comap f K) := by
ext
simp [radical]
variable {K}
theorem IsRadical.comap (hK : K.IsRadical) : (comap f K).IsRadical := by
rw [← hK.radical, comap_radical]
apply radical_isRadical
variable {I J L}
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 fun r ⟨n, hrni⟩ => ⟨n, map_pow f r n ▸ mem_map_of_mem f hrni⟩
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 <|
(Ideal.map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 <| le_rfl) (map_le_iff_le_comap.2 <| le_rfl)
theorem le_comap_pow (n : ℕ) : K.comap f ^ n ≤ (K ^ n).comap f := by
induction' n with n n_ih
· rw [pow_zero, pow_zero, Ideal.one_eq_top, Ideal.one_eq_top]
exact rfl.le
· rw [pow_succ, pow_succ]
exact (Ideal.mul_mono_left n_ih).trans (Ideal.le_comap_mul f)
lemma disjoint_map_primeCompl_iff_comap_le {S : Type*} [Semiring S] {f : R →+* S}
{p : Ideal R} {I : Ideal S} [p.IsPrime] :
Disjoint (I : Set S) (p.primeCompl.map f) ↔ I.comap f ≤ p := by
rw [disjoint_comm]
simp [Set.disjoint_iff, Set.ext_iff, Ideal.primeCompl, not_imp_not, SetLike.le_def]
/-- For a prime ideal `p` of `R`, `p` extended to `S` and
restricted back to `R` is `p` if and only if `p` is the restriction of a prime in `S`. -/
lemma comap_map_eq_self_iff_of_isPrime {S : Type*} [CommSemiring S] {f : R →+* S}
(p : Ideal R) [p.IsPrime] :
(p.map f).comap f = p ↔ (∃ (q : Ideal S), q.IsPrime ∧ q.comap f = p) := by
refine ⟨fun hp ↦ ?_, ?_⟩
· obtain ⟨q, hq₁, hq₂, hq₃⟩ := Ideal.exists_le_prime_disjoint _ _
(disjoint_map_primeCompl_iff_comap_le.mpr hp.le)
exact ⟨q, hq₁, le_antisymm (disjoint_map_primeCompl_iff_comap_le.mp hq₃)
(map_le_iff_le_comap.mp hq₂)⟩
· rintro ⟨q, hq, rfl⟩
simp
end CommRing
end MapAndComap
end Ideal
namespace RingHom
variable {R : Type u} {S : Type v} {T : Type w}
section Semiring
variable {F : Type*} {G : Type*} [Semiring R] [Semiring S] [Semiring T]
variable [FunLike F R S] [rcf : RingHomClass F R S] [FunLike G T S] [rcg : RingHomClass G T S]
variable (f : F) (g : G)
/-- Kernel of a ring homomorphism as an ideal of the domain. -/
def ker : Ideal R :=
Ideal.comap f ⊥
instance (priority := low) : (ker f).IsTwoSided := inferInstanceAs (Ideal.comap f ⊥).IsTwoSided
variable {f} in
/-- An element is in the kernel if and only if it maps to zero. -/
@[simp] theorem mem_ker {r} : r ∈ ker f ↔ f r = 0 := by rw [ker, Ideal.mem_comap, Submodule.mem_bot]
theorem ker_eq : (ker f : Set R) = Set.preimage f {0} :=
rfl
theorem ker_eq_comap_bot (f : F) : ker f = Ideal.comap f ⊥ :=
rfl
theorem comap_ker (f : S →+* R) (g : T →+* S) : (ker f).comap g = ker (f.comp g) := by
rw [RingHom.ker_eq_comap_bot, Ideal.comap_comap, RingHom.ker_eq_comap_bot]
/-- If the target is not the zero ring, then one is not in the kernel. -/
theorem not_one_mem_ker [Nontrivial S] (f : F) : (1 : R) ∉ ker f := by
rw [mem_ker, map_one]
exact one_ne_zero
theorem ker_ne_top [Nontrivial S] (f : F) : ker f ≠ ⊤ :=
(Ideal.ne_top_iff_one _).mpr <| not_one_mem_ker f
lemma _root_.Pi.ker_ringHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
(φ : ∀ i, S →+* R i) : ker (Pi.ringHom φ) = ⨅ i, ker (φ i) := by
ext x
simp [mem_ker, Ideal.mem_iInf, funext_iff]
@[simp]
theorem ker_rangeSRestrict (f : R →+* S) : ker f.rangeSRestrict = ker f :=
Ideal.ext fun _ ↦ Subtype.ext_iff
@[simp]
theorem ker_coe_equiv (f : R ≃+* S) : ker (f : R →+* S) = ⊥ := by
ext; simp
theorem ker_coe_toRingHom : ker (f : R →+* S) = ker f := rfl
@[simp]
theorem ker_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') :
ker f = ⊥ := by
ext; simp
lemma ker_equiv_comp (f : R →+* S) (e : S ≃+* T) :
ker (e.toRingHom.comp f) = RingHom.ker f := by
rw [← RingHom.comap_ker, RingEquiv.toRingHom_eq_coe, RingHom.ker_coe_equiv, RingHom.ker]
end Semiring
section Ring
variable {F : Type*} [Ring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F)
theorem injective_iff_ker_eq_bot : Function.Injective f ↔ ker f = ⊥ := by
rw [SetLike.ext'_iff, ker_eq, Set.ext_iff]
exact injective_iff_map_eq_zero' f
| Mathlib/RingTheory/Ideal/Maps.lean | 715 | 716 | theorem ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 := by | rw [← injective_iff_map_eq_zero f, injective_iff_ker_eq_bot] |
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Analysis.Calculus.ContDiff.Basic
import Mathlib.Analysis.Calculus.ParametricIntegral
import Mathlib.MeasureTheory.Integral.Prod
import Mathlib.MeasureTheory.Function.LocallyIntegrable
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.MeasureTheory.Group.Prod
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
/-!
# Convolution of functions
This file defines the convolution on two functions, i.e. `x ↦ ∫ f(t)g(x - t) ∂t`.
In the general case, these functions can be vector-valued, and have an arbitrary (additive)
group as domain. We use a continuous bilinear operation `L` on these function values as
"multiplication". The domain must be equipped with a Haar measure `μ`
(though many individual results have weaker conditions on `μ`).
For many applications we can take `L = ContinuousLinearMap.lsmul ℝ ℝ` or
`L = ContinuousLinearMap.mul ℝ ℝ`.
We also define `ConvolutionExists` and `ConvolutionExistsAt` to state that the convolution is
well-defined (everywhere or at a single point). These conditions are needed for pointwise
computations (e.g. `ConvolutionExistsAt.distrib_add`), but are generally not strong enough for any
local (or global) properties of the convolution. For this we need stronger assumptions on `f`
and/or `g`, and generally if we impose stronger conditions on one of the functions, we can impose
weaker conditions on the other.
We have proven many of the properties of the convolution assuming one of these functions
has compact support (in which case the other function only needs to be locally integrable).
We still need to prove the properties for other pairs of conditions (e.g. both functions are
rapidly decreasing)
# Design Decisions
We use a bilinear map `L` to "multiply" the two functions in the integrand.
This generality has several advantages
* This allows us to compute the total derivative of the convolution, in case the functions are
multivariate. The total derivative is again a convolution, but where the codomains of the
functions can be higher-dimensional. See `HasCompactSupport.hasFDerivAt_convolution_right`.
* This allows us to use `@[to_additive]` everywhere (which would not be possible if we would use
`mul`/`smul` in the integral, since `@[to_additive]` will incorrectly also try to additivize
those definitions).
* We need to support the case where at least one of the functions is vector-valued, but if we use
`smul` to multiply the functions, that would be an asymmetric definition.
# Main Definitions
* `MeasureTheory.convolution f g L μ x = (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ`
is the convolution of `f` and `g` w.r.t. the continuous bilinear map `L` and measure `μ`.
* `MeasureTheory.ConvolutionExistsAt f g x L μ` states that the convolution `(f ⋆[L, μ] g) x`
is well-defined (i.e. the integral exists).
* `MeasureTheory.ConvolutionExists f g L μ` states that the convolution `f ⋆[L, μ] g`
is well-defined at each point.
# Main Results
* `HasCompactSupport.hasFDerivAt_convolution_right` and
`HasCompactSupport.hasFDerivAt_convolution_left`: we can compute the total derivative
of the convolution as a convolution with the total derivative of the right (left) function.
* `HasCompactSupport.contDiff_convolution_right` and
`HasCompactSupport.contDiff_convolution_left`: the convolution is `𝒞ⁿ` if one of the functions
is `𝒞ⁿ` with compact support and the other function in locally integrable.
Versions of these statements for functions depending on a parameter are also given.
* `MeasureTheory.convolution_tendsto_right`: Given a sequence of nonnegative normalized functions
whose support tends to a small neighborhood around `0`, the convolution tends to the right
argument. This is specialized to bump functions in `ContDiffBump.convolution_tendsto_right`.
# Notation
The following notations are localized in the locale `Convolution`:
* `f ⋆[L, μ] g` for the convolution. Note: you have to use parentheses to apply the convolution
to an argument: `(f ⋆[L, μ] g) x`.
* `f ⋆[L] g := f ⋆[L, volume] g`
* `f ⋆ g := f ⋆[lsmul ℝ ℝ] g`
# To do
* Existence and (uniform) continuity of the convolution if
one of the maps is in `ℒ^p` and the other in `ℒ^q` with `1 / p + 1 / q = 1`.
This might require a generalization of `MeasureTheory.MemLp.smul` where `smul` is generalized
to a continuous bilinear map.
(see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255K)
* The convolution is an `AEStronglyMeasurable` function
(see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255I).
* Prove properties about the convolution if both functions are rapidly decreasing.
* Use `@[to_additive]` everywhere (this likely requires changes in `to_additive`)
-/
open Set Function Filter MeasureTheory MeasureTheory.Measure TopologicalSpace
open Bornology ContinuousLinearMap Metric Topology
open scoped Pointwise NNReal Filter
universe u𝕜 uG uE uE' uE'' uF uF' uF'' uP
variable {𝕜 : Type u𝕜} {G : Type uG} {E : Type uE} {E' : Type uE'} {E'' : Type uE''} {F : Type uF}
{F' : Type uF'} {F'' : Type uF''} {P : Type uP}
variable [NormedAddCommGroup E] [NormedAddCommGroup E'] [NormedAddCommGroup E'']
[NormedAddCommGroup F] {f f' : G → E} {g g' : G → E'} {x x' : G} {y y' : E}
namespace MeasureTheory
section NontriviallyNormedField
variable [NontriviallyNormedField 𝕜]
variable [NormedSpace 𝕜 E] [NormedSpace 𝕜 E'] [NormedSpace 𝕜 E''] [NormedSpace 𝕜 F]
variable (L : E →L[𝕜] E' →L[𝕜] F)
section NoMeasurability
variable [AddGroup G] [TopologicalSpace G]
theorem convolution_integrand_bound_right_of_le_of_subset {C : ℝ} (hC : ∀ i, ‖g i‖ ≤ C) {x t : G}
{s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) :
‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * C) t := by
-- Porting note: had to add `f := _`
refine le_indicator (f := fun t ↦ ‖L (f t) (g (x - t))‖) (fun t _ => ?_) (fun t ht => ?_) t
· apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl]
· have : x - t ∉ support g := by
refine mt (fun hxt => hu ?_) ht
refine ⟨_, Set.neg_mem_neg.mpr (subset_closure hxt), _, hx, ?_⟩
simp only [neg_sub, sub_add_cancel]
simp only [nmem_support.mp this, (L _).map_zero, norm_zero, le_rfl]
theorem _root_.HasCompactSupport.convolution_integrand_bound_right_of_subset
(hcg : HasCompactSupport g) (hg : Continuous g)
{x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) :
‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t := by
refine convolution_integrand_bound_right_of_le_of_subset _ (fun i => ?_) hx hu
exact le_ciSup (hg.norm.bddAbove_range_of_hasCompactSupport hcg.norm) _
theorem _root_.HasCompactSupport.convolution_integrand_bound_right (hcg : HasCompactSupport g)
(hg : Continuous g) {x t : G} {s : Set G} (hx : x ∈ s) :
‖L (f t) (g (x - t))‖ ≤ (-tsupport g + s).indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t :=
hcg.convolution_integrand_bound_right_of_subset L hg hx Subset.rfl
theorem _root_.Continuous.convolution_integrand_fst [ContinuousSub G] (hg : Continuous g) (t : G) :
Continuous fun x => L (f t) (g (x - t)) :=
L.continuous₂.comp₂ continuous_const <| hg.comp <| continuous_id.sub continuous_const
theorem _root_.HasCompactSupport.convolution_integrand_bound_left (hcf : HasCompactSupport f)
(hf : Continuous f) {x t : G} {s : Set G} (hx : x ∈ s) :
‖L (f (x - t)) (g t)‖ ≤
(-tsupport f + s).indicator (fun t => (‖L‖ * ⨆ i, ‖f i‖) * ‖g t‖) t := by
convert hcf.convolution_integrand_bound_right L.flip hf hx using 1
simp_rw [L.opNorm_flip, mul_right_comm]
end NoMeasurability
section Measurability
variable [MeasurableSpace G] {μ ν : Measure G}
/-- The convolution of `f` and `g` exists at `x` when the function `t ↦ L (f t) (g (x - t))` is
integrable. There are various conditions on `f` and `g` to prove this. -/
def ConvolutionExistsAt [Sub G] (f : G → E) (g : G → E') (x : G) (L : E →L[𝕜] E' →L[𝕜] F)
(μ : Measure G := by volume_tac) : Prop :=
Integrable (fun t => L (f t) (g (x - t))) μ
/-- The convolution of `f` and `g` exists when the function `t ↦ L (f t) (g (x - t))` is integrable
for all `x : G`. There are various conditions on `f` and `g` to prove this. -/
def ConvolutionExists [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F)
(μ : Measure G := by volume_tac) : Prop :=
∀ x : G, ConvolutionExistsAt f g x L μ
section ConvolutionExists
variable {L} in
theorem ConvolutionExistsAt.integrable [Sub G] {x : G} (h : ConvolutionExistsAt f g x L μ) :
Integrable (fun t => L (f t) (g (x - t))) μ :=
h
section Group
variable [AddGroup G]
theorem AEStronglyMeasurable.convolution_integrand' [MeasurableAdd₂ G]
[MeasurableNeg G] (hf : AEStronglyMeasurable f ν)
(hg : AEStronglyMeasurable g <| map (fun p : G × G => p.1 - p.2) (μ.prod ν)) :
AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) :=
L.aestronglyMeasurable_comp₂ hf.snd <| hg.comp_measurable measurable_sub
section
variable [MeasurableAdd G] [MeasurableNeg G]
theorem AEStronglyMeasurable.convolution_integrand_snd'
(hf : AEStronglyMeasurable f μ) {x : G}
(hg : AEStronglyMeasurable g <| map (fun t => x - t) μ) :
AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ :=
L.aestronglyMeasurable_comp₂ hf <| hg.comp_measurable <| measurable_id.const_sub x
theorem AEStronglyMeasurable.convolution_integrand_swap_snd' {x : G}
(hf : AEStronglyMeasurable f <| map (fun t => x - t) μ) (hg : AEStronglyMeasurable g μ) :
AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ :=
L.aestronglyMeasurable_comp₂ (hf.comp_measurable <| measurable_id.const_sub x) hg
/-- A sufficient condition to prove that `f ⋆[L, μ] g` exists.
We assume that `f` is integrable on a set `s` and `g` is bounded and ae strongly measurable
on `x₀ - s` (note that both properties hold if `g` is continuous with compact support). -/
theorem _root_.BddAbove.convolutionExistsAt' {x₀ : G} {s : Set G}
(hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => -t + x₀) ⁻¹' s))) (hs : MeasurableSet s)
(h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ)
(hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) (μ.restrict s)) :
ConvolutionExistsAt f g x₀ L μ := by
rw [ConvolutionExistsAt]
rw [← integrableOn_iff_integrable_of_support_subset h2s]
set s' := (fun t => -t + x₀) ⁻¹' s
have : ∀ᵐ t : G ∂μ.restrict s,
‖L (f t) (g (x₀ - t))‖ ≤ s.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i : s', ‖g i‖) t := by
filter_upwards
refine le_indicator (fun t ht => ?_) fun t ht => ?_
· apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl]
refine (le_ciSup_set hbg <| mem_preimage.mpr ?_)
rwa [neg_sub, sub_add_cancel]
· have : t ∉ support fun t => L (f t) (g (x₀ - t)) := mt (fun h => h2s h) ht
rw [nmem_support.mp this, norm_zero]
refine Integrable.mono' ?_ ?_ this
· rw [integrable_indicator_iff hs]; exact ((hf.norm.const_mul _).mul_const _).integrableOn
· exact hf.aestronglyMeasurable.convolution_integrand_snd' L hmg
/-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/
theorem ConvolutionExistsAt.of_norm' {x₀ : G}
(h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ)
(hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) μ) :
ConvolutionExistsAt f g x₀ L μ := by
refine (h.const_mul ‖L‖).mono'
(hmf.convolution_integrand_snd' L hmg) (Eventually.of_forall fun x => ?_)
rw [mul_apply', ← mul_assoc]
apply L.le_opNorm₂
@[deprecated (since := "2025-02-07")]
alias ConvolutionExistsAt.ofNorm' := ConvolutionExistsAt.of_norm'
end
section Left
variable [MeasurableAdd₂ G] [MeasurableNeg G] [SFinite μ] [IsAddRightInvariant μ]
theorem AEStronglyMeasurable.convolution_integrand_snd (hf : AEStronglyMeasurable f μ)
(hg : AEStronglyMeasurable g μ) (x : G) :
AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ :=
hf.convolution_integrand_snd' L <|
hg.mono_ac <| (quasiMeasurePreserving_sub_left_of_right_invariant μ x).absolutelyContinuous
theorem AEStronglyMeasurable.convolution_integrand_swap_snd
(hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (x : G) :
AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ :=
(hf.mono_ac
(quasiMeasurePreserving_sub_left_of_right_invariant μ
x).absolutelyContinuous).convolution_integrand_swap_snd'
L hg
/-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/
theorem ConvolutionExistsAt.of_norm {x₀ : G}
(h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ)
(hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g μ) :
ConvolutionExistsAt f g x₀ L μ :=
h.of_norm' L hmf <|
hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous
@[deprecated (since := "2025-02-07")]
alias ConvolutionExistsAt.ofNorm := ConvolutionExistsAt.of_norm
end Left
section Right
variable [MeasurableAdd₂ G] [MeasurableNeg G] [SFinite μ] [IsAddRightInvariant μ] [SFinite ν]
theorem AEStronglyMeasurable.convolution_integrand (hf : AEStronglyMeasurable f ν)
(hg : AEStronglyMeasurable g μ) :
AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) :=
hf.convolution_integrand' L <|
hg.mono_ac (quasiMeasurePreserving_sub_of_right_invariant μ ν).absolutelyContinuous
theorem Integrable.convolution_integrand (hf : Integrable f ν) (hg : Integrable g μ) :
Integrable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := by
have h_meas : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) :=
hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable
have h2_meas : AEStronglyMeasurable (fun y : G => ∫ x : G, ‖L (f y) (g (x - y))‖ ∂μ) ν :=
h_meas.prod_swap.norm.integral_prod_right'
simp_rw [integrable_prod_iff' h_meas]
refine ⟨Eventually.of_forall fun t => (L (f t)).integrable_comp (hg.comp_sub_right t), ?_⟩
refine Integrable.mono' ?_ h2_meas
(Eventually.of_forall fun t => (?_ : _ ≤ ‖L‖ * ‖f t‖ * ∫ x, ‖g (x - t)‖ ∂μ))
· simp only [integral_sub_right_eq_self (‖g ·‖)]
exact (hf.norm.const_mul _).mul_const _
· simp_rw [← integral_const_mul]
rw [Real.norm_of_nonneg (by positivity)]
exact integral_mono_of_nonneg (Eventually.of_forall fun t => norm_nonneg _)
((hg.comp_sub_right t).norm.const_mul _) (Eventually.of_forall fun t => L.le_opNorm₂ _ _)
theorem Integrable.ae_convolution_exists (hf : Integrable f ν) (hg : Integrable g μ) :
∀ᵐ x ∂μ, ConvolutionExistsAt f g x L ν :=
((integrable_prod_iff <|
hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable).mp <|
hf.convolution_integrand L hg).1
end Right
variable [TopologicalSpace G] [IsTopologicalAddGroup G] [BorelSpace G]
theorem _root_.HasCompactSupport.convolutionExistsAt {x₀ : G}
(h : HasCompactSupport fun t => L (f t) (g (x₀ - t))) (hf : LocallyIntegrable f μ)
(hg : Continuous g) : ConvolutionExistsAt f g x₀ L μ := by
let u := (Homeomorph.neg G).trans (Homeomorph.addRight x₀)
let v := (Homeomorph.neg G).trans (Homeomorph.addLeft x₀)
apply ((u.isCompact_preimage.mpr h).bddAbove_image hg.norm.continuousOn).convolutionExistsAt' L
isClosed_closure.measurableSet subset_closure (hf.integrableOn_isCompact h)
have A : AEStronglyMeasurable (g ∘ v)
(μ.restrict (tsupport fun t : G => L (f t) (g (x₀ - t)))) := by
apply (hg.comp v.continuous).continuousOn.aestronglyMeasurable_of_isCompact h
exact (isClosed_tsupport _).measurableSet
convert ((v.continuous.measurable.measurePreserving
(μ.restrict (tsupport fun t => L (f t) (g (x₀ - t))))).aestronglyMeasurable_comp_iff
v.measurableEmbedding).1 A
ext x
simp only [v, Homeomorph.neg, sub_eq_add_neg, val_toAddUnits_apply, Homeomorph.trans_apply,
Equiv.neg_apply, Equiv.toFun_as_coe, Homeomorph.homeomorph_mk_coe, Equiv.coe_fn_mk,
Homeomorph.coe_addLeft]
theorem _root_.HasCompactSupport.convolutionExists_right (hcg : HasCompactSupport g)
(hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExists f g L μ := by
intro x₀
refine HasCompactSupport.convolutionExistsAt L ?_ hf hg
refine (hcg.comp_homeomorph (Homeomorph.subLeft x₀)).mono ?_
refine fun t => mt fun ht : g (x₀ - t) = 0 => ?_
simp_rw [ht, (L _).map_zero]
theorem _root_.HasCompactSupport.convolutionExists_left_of_continuous_right
(hcf : HasCompactSupport f) (hf : LocallyIntegrable f μ) (hg : Continuous g) :
ConvolutionExists f g L μ := by
intro x₀
refine HasCompactSupport.convolutionExistsAt L ?_ hf hg
refine hcf.mono ?_
refine fun t => mt fun ht : f t = 0 => ?_
simp_rw [ht, L.map_zero₂]
end Group
section CommGroup
variable [AddCommGroup G]
section MeasurableGroup
variable [MeasurableNeg G] [IsAddLeftInvariant μ]
/-- A sufficient condition to prove that `f ⋆[L, μ] g` exists.
We assume that the integrand has compact support and `g` is bounded on this support (note that
both properties hold if `g` is continuous with compact support). We also require that `f` is
integrable on the support of the integrand, and that both functions are strongly measurable.
This is a variant of `BddAbove.convolutionExistsAt'` in an abelian group with a left-invariant
measure. This allows us to state the boundedness and measurability of `g` in a more natural way. -/
theorem _root_.BddAbove.convolutionExistsAt [MeasurableAdd₂ G] [SFinite μ] {x₀ : G} {s : Set G}
(hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => x₀ - t) ⁻¹' s))) (hs : MeasurableSet s)
(h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ)
(hmg : AEStronglyMeasurable g μ) : ConvolutionExistsAt f g x₀ L μ := by
refine BddAbove.convolutionExistsAt' L ?_ hs h2s hf ?_
· simp_rw [← sub_eq_neg_add, hbg]
· have : AEStronglyMeasurable g (map (fun t : G => x₀ - t) μ) :=
hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous
apply this.mono_measure
exact map_mono restrict_le_self (measurable_const.sub measurable_id')
variable {L} [MeasurableAdd G] [IsNegInvariant μ]
theorem convolutionExistsAt_flip :
ConvolutionExistsAt g f x L.flip μ ↔ ConvolutionExistsAt f g x L μ := by
simp_rw [ConvolutionExistsAt, ← integrable_comp_sub_left (fun t => L (f t) (g (x - t))) x,
sub_sub_cancel, flip_apply]
theorem ConvolutionExistsAt.integrable_swap (h : ConvolutionExistsAt f g x L μ) :
Integrable (fun t => L (f (x - t)) (g t)) μ := by
convert h.comp_sub_left x
simp_rw [sub_sub_self]
theorem convolutionExistsAt_iff_integrable_swap :
ConvolutionExistsAt f g x L μ ↔ Integrable (fun t => L (f (x - t)) (g t)) μ :=
convolutionExistsAt_flip.symm
end MeasurableGroup
variable [TopologicalSpace G] [IsTopologicalAddGroup G] [BorelSpace G]
variable [IsAddLeftInvariant μ] [IsNegInvariant μ]
theorem _root_.HasCompactSupport.convolutionExists_left
(hcf : HasCompactSupport f) (hf : Continuous f)
(hg : LocallyIntegrable g μ) : ConvolutionExists f g L μ := fun x₀ =>
convolutionExistsAt_flip.mp <| hcf.convolutionExists_right L.flip hg hf x₀
@[deprecated (since := "2025-02-06")]
alias _root_.HasCompactSupport.convolutionExistsLeft := HasCompactSupport.convolutionExists_left
theorem _root_.HasCompactSupport.convolutionExists_right_of_continuous_left
(hcg : HasCompactSupport g) (hf : Continuous f) (hg : LocallyIntegrable g μ) :
ConvolutionExists f g L μ := fun x₀ =>
convolutionExistsAt_flip.mp <| hcg.convolutionExists_left_of_continuous_right L.flip hg hf x₀
@[deprecated (since := "2025-02-06")]
alias _root_.HasCompactSupport.convolutionExistsRightOfContinuousLeft :=
HasCompactSupport.convolutionExists_right_of_continuous_left
end CommGroup
end ConvolutionExists
variable [NormedSpace ℝ F]
/-- The convolution of two functions `f` and `g` with respect to a continuous bilinear map `L` and
measure `μ`. It is defined to be `(f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ`. -/
noncomputable def convolution [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F)
(μ : Measure G := by volume_tac) : G → F := fun x =>
∫ t, L (f t) (g (x - t)) ∂μ
/-- The convolution of two functions with respect to a bilinear operation `L` and a measure `μ`. -/
scoped[Convolution] notation:67 f " ⋆[" L:67 ", " μ:67 "] " g:66 => convolution f g L μ
/-- The convolution of two functions with respect to a bilinear operation `L` and the volume. -/
scoped[Convolution]
notation:67 f " ⋆[" L:67 "]" g:66 => convolution f g L MeasureSpace.volume
/-- The convolution of two real-valued functions with respect to volume. -/
scoped[Convolution]
notation:67 f " ⋆ " g:66 =>
convolution f g (ContinuousLinearMap.lsmul ℝ ℝ) MeasureSpace.volume
open scoped Convolution
theorem convolution_def [Sub G] : (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ :=
rfl
/-- The definition of convolution where the bilinear operator is scalar multiplication.
Note: it often helps the elaborator to give the type of the convolution explicitly. -/
theorem convolution_lsmul [Sub G] {f : G → 𝕜} {g : G → F} :
(f ⋆[lsmul 𝕜 𝕜, μ] g : G → F) x = ∫ t, f t • g (x - t) ∂μ :=
rfl
/-- The definition of convolution where the bilinear operator is multiplication. -/
theorem convolution_mul [Sub G] [NormedSpace ℝ 𝕜] {f : G → 𝕜} {g : G → 𝕜} :
(f ⋆[mul 𝕜 𝕜, μ] g) x = ∫ t, f t * g (x - t) ∂μ :=
rfl
section Group
variable {L} [AddGroup G]
theorem smul_convolution [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : y • f ⋆[L, μ] g = y • (f ⋆[L, μ] g) := by
ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, L.map_smul₂]
theorem convolution_smul [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : f ⋆[L, μ] y • g = y • (f ⋆[L, μ] g) := by
ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, (L _).map_smul]
@[simp]
theorem zero_convolution : 0 ⋆[L, μ] g = 0 := by
ext
simp_rw [convolution_def, Pi.zero_apply, L.map_zero₂, integral_zero]
@[simp]
theorem convolution_zero : f ⋆[L, μ] 0 = 0 := by
ext
simp_rw [convolution_def, Pi.zero_apply, (L _).map_zero, integral_zero]
theorem ConvolutionExistsAt.distrib_add {x : G} (hfg : ConvolutionExistsAt f g x L μ)
(hfg' : ConvolutionExistsAt f g' x L μ) :
(f ⋆[L, μ] (g + g')) x = (f ⋆[L, μ] g) x + (f ⋆[L, μ] g') x := by
simp only [convolution_def, (L _).map_add, Pi.add_apply, integral_add hfg hfg']
theorem ConvolutionExists.distrib_add (hfg : ConvolutionExists f g L μ)
(hfg' : ConvolutionExists f g' L μ) : f ⋆[L, μ] (g + g') = f ⋆[L, μ] g + f ⋆[L, μ] g' := by
ext x
exact (hfg x).distrib_add (hfg' x)
theorem ConvolutionExistsAt.add_distrib {x : G} (hfg : ConvolutionExistsAt f g x L μ)
(hfg' : ConvolutionExistsAt f' g x L μ) :
((f + f') ⋆[L, μ] g) x = (f ⋆[L, μ] g) x + (f' ⋆[L, μ] g) x := by
simp only [convolution_def, L.map_add₂, Pi.add_apply, integral_add hfg hfg']
theorem ConvolutionExists.add_distrib (hfg : ConvolutionExists f g L μ)
(hfg' : ConvolutionExists f' g L μ) : (f + f') ⋆[L, μ] g = f ⋆[L, μ] g + f' ⋆[L, μ] g := by
ext x
exact (hfg x).add_distrib (hfg' x)
theorem convolution_mono_right {f g g' : G → ℝ} (hfg : ConvolutionExistsAt f g x (lsmul ℝ ℝ) μ)
(hfg' : ConvolutionExistsAt f g' x (lsmul ℝ ℝ) μ) (hf : ∀ x, 0 ≤ f x) (hg : ∀ x, g x ≤ g' x) :
(f ⋆[lsmul ℝ ℝ, μ] g) x ≤ (f ⋆[lsmul ℝ ℝ, μ] g') x := by
apply integral_mono hfg hfg'
simp only [lsmul_apply, Algebra.id.smul_eq_mul]
intro t
apply mul_le_mul_of_nonneg_left (hg _) (hf _)
theorem convolution_mono_right_of_nonneg {f g g' : G → ℝ}
(hfg' : ConvolutionExistsAt f g' x (lsmul ℝ ℝ) μ) (hf : ∀ x, 0 ≤ f x) (hg : ∀ x, g x ≤ g' x)
(hg' : ∀ x, 0 ≤ g' x) : (f ⋆[lsmul ℝ ℝ, μ] g) x ≤ (f ⋆[lsmul ℝ ℝ, μ] g') x := by
by_cases H : ConvolutionExistsAt f g x (lsmul ℝ ℝ) μ
· exact convolution_mono_right H hfg' hf hg
have : (f ⋆[lsmul ℝ ℝ, μ] g) x = 0 := integral_undef H
rw [this]
exact integral_nonneg fun y => mul_nonneg (hf y) (hg' (x - y))
variable (L)
theorem convolution_congr [MeasurableAdd₂ G] [MeasurableNeg G] [SFinite μ]
[IsAddRightInvariant μ] (h1 : f =ᵐ[μ] f') (h2 : g =ᵐ[μ] g') : f ⋆[L, μ] g = f' ⋆[L, μ] g' := by
ext x
apply integral_congr_ae
exact (h1.prodMk <| h2.comp_tendsto
(quasiMeasurePreserving_sub_left_of_right_invariant μ x).tendsto_ae).fun_comp ↿fun x y ↦ L x y
theorem support_convolution_subset_swap : support (f ⋆[L, μ] g) ⊆ support g + support f := by
intro x h2x
by_contra hx
apply h2x
simp_rw [Set.mem_add, ← exists_and_left, not_exists, not_and_or, nmem_support] at hx
rw [convolution_def]
convert integral_zero G F using 2
ext t
rcases hx (x - t) t with (h | h | h)
· rw [h, (L _).map_zero]
· rw [h, L.map_zero₂]
· exact (h <| sub_add_cancel x t).elim
section
variable [MeasurableAdd₂ G] [MeasurableNeg G] [SFinite μ] [IsAddRightInvariant μ]
theorem Integrable.integrable_convolution (hf : Integrable f μ)
(hg : Integrable g μ) : Integrable (f ⋆[L, μ] g) μ :=
(hf.convolution_integrand L hg).integral_prod_left
end
variable [TopologicalSpace G]
variable [IsTopologicalAddGroup G]
protected theorem _root_.HasCompactSupport.convolution [T2Space G] (hcf : HasCompactSupport f)
(hcg : HasCompactSupport g) : HasCompactSupport (f ⋆[L, μ] g) :=
(hcg.isCompact.add hcf).of_isClosed_subset isClosed_closure <|
closure_minimal
((support_convolution_subset_swap L).trans <| add_subset_add subset_closure subset_closure)
(hcg.isCompact.add hcf).isClosed
variable [BorelSpace G] [TopologicalSpace P]
/-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and
compactly supported. Version where `g` depends on an additional parameter in a subset `s` of
a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). -/
theorem continuousOn_convolution_right_with_param {g : P → G → E'} {s : Set P} {k : Set G}
(hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0)
(hf : LocallyIntegrable f μ) (hg : ContinuousOn (↿g) (s ×ˢ univ)) :
ContinuousOn (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (s ×ˢ univ) := by
/- First get rid of the case where the space is not locally compact. Then `g` vanishes everywhere
and the conclusion is trivial. -/
by_cases H : ∀ p ∈ s, ∀ x, g p x = 0
· apply (continuousOn_const (c := 0)).congr
rintro ⟨p, x⟩ ⟨hp, -⟩
apply integral_eq_zero_of_ae (Eventually.of_forall (fun y ↦ ?_))
simp [H p hp _]
have : LocallyCompactSpace G := by
push_neg at H
rcases H with ⟨p, hp, x, hx⟩
have A : support (g p) ⊆ k := support_subset_iff'.2 (fun y hy ↦ hgs p y hp hy)
have B : Continuous (g p) := by
refine hg.comp_continuous (.prodMk_right _) fun x => ?_
simpa only [prodMk_mem_set_prod_eq, mem_univ, and_true] using hp
rcases eq_zero_or_locallyCompactSpace_of_support_subset_isCompact_of_addGroup hk A B with H|H
· simp [H] at hx
· exact H
/- Since `G` is locally compact, one may thicken `k` a little bit into a larger compact set
`(-k) + t`, outside of which all functions that appear in the convolution vanish. Then we can
apply a continuity statement for integrals depending on a parameter, with respect to
locally integrable functions and compactly supported continuous functions. -/
rintro ⟨q₀, x₀⟩ ⟨hq₀, -⟩
obtain ⟨t, t_comp, ht⟩ : ∃ t, IsCompact t ∧ t ∈ 𝓝 x₀ := exists_compact_mem_nhds x₀
let k' : Set G := (-k) +ᵥ t
have k'_comp : IsCompact k' := IsCompact.vadd_set hk.neg t_comp
let g' : (P × G) → G → E' := fun p x ↦ g p.1 (p.2 - x)
let s' : Set (P × G) := s ×ˢ t
have A : ContinuousOn g'.uncurry (s' ×ˢ univ) := by
have : g'.uncurry = g.uncurry ∘ (fun w ↦ (w.1.1, w.1.2 - w.2)) := by ext y; rfl
rw [this]
refine hg.comp (by fun_prop) ?_
simp +contextual [s', MapsTo]
have B : ContinuousOn (fun a ↦ ∫ x, L (f x) (g' a x) ∂μ) s' := by
apply continuousOn_integral_bilinear_of_locally_integrable_of_compact_support L k'_comp A _
(hf.integrableOn_isCompact k'_comp)
rintro ⟨p, x⟩ y ⟨hp, hx⟩ hy
apply hgs p _ hp
contrapose! hy
exact ⟨y - x, by simpa using hy, x, hx, by simp⟩
apply ContinuousWithinAt.mono_of_mem_nhdsWithin (B (q₀, x₀) ⟨hq₀, mem_of_mem_nhds ht⟩)
exact mem_nhdsWithin_prod_iff.2 ⟨s, self_mem_nhdsWithin, t, nhdsWithin_le_nhds ht, Subset.rfl⟩
/-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and
compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of
a parameter space `P` (and the compact support `k` is independent of the parameter in `s`),
given in terms of compositions with an additional continuous map. -/
theorem continuousOn_convolution_right_with_param_comp {s : Set P} {v : P → G}
(hv : ContinuousOn v s) {g : P → G → E'} {k : Set G} (hk : IsCompact k)
(hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ)
(hg : ContinuousOn (↿g) (s ×ˢ univ)) : ContinuousOn (fun x => (f ⋆[L, μ] g x) (v x)) s := by
apply
(continuousOn_convolution_right_with_param L hk hgs hf hg).comp (continuousOn_id.prodMk hv)
intro x hx
simp only [hx, prodMk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id]
/-- The convolution is continuous if one function is locally integrable and the other has compact
support and is continuous. -/
theorem _root_.HasCompactSupport.continuous_convolution_right (hcg : HasCompactSupport g)
(hf : LocallyIntegrable f μ) (hg : Continuous g) : Continuous (f ⋆[L, μ] g) := by
rw [continuous_iff_continuousOn_univ]
let g' : G → G → E' := fun _ q => g q
have : ContinuousOn (↿g') (univ ×ˢ univ) := (hg.comp continuous_snd).continuousOn
exact continuousOn_convolution_right_with_param_comp L
(continuous_iff_continuousOn_univ.1 continuous_id) hcg
(fun p x _ hx => image_eq_zero_of_nmem_tsupport hx) hf this
/-- The convolution is continuous if one function is integrable and the other is bounded and
continuous. -/
theorem _root_.BddAbove.continuous_convolution_right_of_integrable
[FirstCountableTopology G] [SecondCountableTopologyEither G E']
(hbg : BddAbove (range fun x => ‖g x‖)) (hf : Integrable f μ) (hg : Continuous g) :
Continuous (f ⋆[L, μ] g) := by
refine continuous_iff_continuousAt.mpr fun x₀ => ?_
have : ∀ᶠ x in 𝓝 x₀, ∀ᵐ t : G ∂μ, ‖L (f t) (g (x - t))‖ ≤ ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖ := by
filter_upwards with x; filter_upwards with t
apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl, le_ciSup hbg (x - t)]
refine continuousAt_of_dominated ?_ this ?_ ?_
· exact Eventually.of_forall fun x =>
hf.aestronglyMeasurable.convolution_integrand_snd' L hg.aestronglyMeasurable
· exact (hf.norm.const_mul _).mul_const _
· exact Eventually.of_forall fun t => (L.continuous₂.comp₂ continuous_const <|
hg.comp <| continuous_id.sub continuous_const).continuousAt
end Group
section CommGroup
variable [AddCommGroup G]
theorem support_convolution_subset : support (f ⋆[L, μ] g) ⊆ support f + support g :=
(support_convolution_subset_swap L).trans (add_comm _ _).subset
variable [IsAddLeftInvariant μ] [IsNegInvariant μ]
section Measurable
variable [MeasurableNeg G]
variable [MeasurableAdd G]
/-- Commutativity of convolution -/
theorem convolution_flip : g ⋆[L.flip, μ] f = f ⋆[L, μ] g := by
ext1 x
simp_rw [convolution_def]
rw [← integral_sub_left_eq_self _ μ x]
simp_rw [sub_sub_self, flip_apply]
/-- The symmetric definition of convolution. -/
theorem convolution_eq_swap : (f ⋆[L, μ] g) x = ∫ t, L (f (x - t)) (g t) ∂μ := by
rw [← convolution_flip]; rfl
/-- The symmetric definition of convolution where the bilinear operator is scalar multiplication. -/
theorem convolution_lsmul_swap {f : G → 𝕜} {g : G → F} :
(f ⋆[lsmul 𝕜 𝕜, μ] g : G → F) x = ∫ t, f (x - t) • g t ∂μ :=
convolution_eq_swap _
/-- The symmetric definition of convolution where the bilinear operator is multiplication. -/
theorem convolution_mul_swap [NormedSpace ℝ 𝕜] {f : G → 𝕜} {g : G → 𝕜} :
(f ⋆[mul 𝕜 𝕜, μ] g) x = ∫ t, f (x - t) * g t ∂μ :=
convolution_eq_swap _
/-- The convolution of two even functions is also even. -/
theorem convolution_neg_of_neg_eq (h1 : ∀ᵐ x ∂μ, f (-x) = f x) (h2 : ∀ᵐ x ∂μ, g (-x) = g x) :
(f ⋆[L, μ] g) (-x) = (f ⋆[L, μ] g) x :=
calc
∫ t : G, (L (f t)) (g (-x - t)) ∂μ = ∫ t : G, (L (f (-t))) (g (x + t)) ∂μ := by
apply integral_congr_ae
filter_upwards [h1, (eventually_add_left_iff μ x).2 h2] with t ht h't
simp_rw [ht, ← h't, neg_add']
_ = ∫ t : G, (L (f t)) (g (x - t)) ∂μ := by
rw [← integral_neg_eq_self]
simp only [neg_neg, ← sub_eq_add_neg]
end Measurable
variable [TopologicalSpace G]
variable [IsTopologicalAddGroup G]
variable [BorelSpace G]
theorem _root_.HasCompactSupport.continuous_convolution_left
(hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g μ) :
Continuous (f ⋆[L, μ] g) := by
rw [← convolution_flip]
exact hcf.continuous_convolution_right L.flip hg hf
theorem _root_.BddAbove.continuous_convolution_left_of_integrable
[FirstCountableTopology G] [SecondCountableTopologyEither G E]
(hbf : BddAbove (range fun x => ‖f x‖)) (hf : Continuous f) (hg : Integrable g μ) :
Continuous (f ⋆[L, μ] g) := by
rw [← convolution_flip]
exact hbf.continuous_convolution_right_of_integrable L.flip hg hf
end CommGroup
section NormedAddCommGroup
variable [SeminormedAddCommGroup G]
/-- Compute `(f ⋆ g) x₀` if the support of the `f` is within `Metric.ball 0 R`, and `g` is constant
on `Metric.ball x₀ R`.
We can simplify the RHS further if we assume `f` is integrable, but also if `L = (•)` or more
generally if `L` has an `AntilipschitzWith`-condition. -/
theorem convolution_eq_right' {x₀ : G} {R : ℝ} (hf : support f ⊆ ball (0 : G) R)
(hg : ∀ x ∈ ball x₀ R, g x = g x₀) : (f ⋆[L, μ] g) x₀ = ∫ t, L (f t) (g x₀) ∂μ := by
have h2 : ∀ t, L (f t) (g (x₀ - t)) = L (f t) (g x₀) := fun t ↦ by
by_cases ht : t ∈ support f
· have h2t := hf ht
rw [mem_ball_zero_iff] at h2t
specialize hg (x₀ - t)
rw [sub_eq_add_neg, add_mem_ball_iff_norm, norm_neg, ← sub_eq_add_neg] at hg
rw [hg h2t]
· rw [nmem_support] at ht
simp_rw [ht, L.map_zero₂]
simp_rw [convolution_def, h2]
variable [BorelSpace G] [SecondCountableTopology G]
variable [IsAddLeftInvariant μ] [SFinite μ]
/-- Approximate `(f ⋆ g) x₀` if the support of the `f` is bounded within a ball, and `g` is near
`g x₀` on a ball with the same radius around `x₀`. See `dist_convolution_le` for a special case.
We can simplify the second argument of `dist` further if we add some extra type-classes on `E`
and `𝕜` or if `L` is scalar multiplication. -/
theorem dist_convolution_le' {x₀ : G} {R ε : ℝ} {z₀ : E'} (hε : 0 ≤ ε) (hif : Integrable f μ)
(hf : support f ⊆ ball (0 : G) R) (hmg : AEStronglyMeasurable g μ)
(hg : ∀ x ∈ ball x₀ R, dist (g x) z₀ ≤ ε) :
dist ((f ⋆[L, μ] g : G → F) x₀) (∫ t, L (f t) z₀ ∂μ) ≤ (‖L‖ * ∫ x, ‖f x‖ ∂μ) * ε := by
have hfg : ConvolutionExistsAt f g x₀ L μ := by
refine BddAbove.convolutionExistsAt L ?_ Metric.isOpen_ball.measurableSet (Subset.trans ?_ hf)
hif.integrableOn hmg
swap; · refine fun t => mt fun ht : f t = 0 => ?_; simp_rw [ht, L.map_zero₂]
rw [bddAbove_def]
refine ⟨‖z₀‖ + ε, ?_⟩
rintro _ ⟨x, hx, rfl⟩
refine norm_le_norm_add_const_of_dist_le (hg x ?_)
rwa [mem_ball_iff_norm, norm_sub_rev, ← mem_ball_zero_iff]
have h2 : ∀ t, dist (L (f t) (g (x₀ - t))) (L (f t) z₀) ≤ ‖L (f t)‖ * ε := by
intro t; by_cases ht : t ∈ support f
· have h2t := hf ht
rw [mem_ball_zero_iff] at h2t
specialize hg (x₀ - t)
rw [sub_eq_add_neg, add_mem_ball_iff_norm, norm_neg, ← sub_eq_add_neg] at hg
refine ((L (f t)).dist_le_opNorm _ _).trans ?_
exact mul_le_mul_of_nonneg_left (hg h2t) (norm_nonneg _)
· rw [nmem_support] at ht
simp_rw [ht, L.map_zero₂, L.map_zero, norm_zero, zero_mul, dist_self]
rfl
simp_rw [convolution_def]
simp_rw [dist_eq_norm] at h2 ⊢
rw [← integral_sub hfg.integrable]; swap; · exact (L.flip z₀).integrable_comp hif
refine (norm_integral_le_of_norm_le ((L.integrable_comp hif).norm.mul_const ε)
(Eventually.of_forall h2)).trans ?_
rw [integral_mul_const]
refine mul_le_mul_of_nonneg_right ?_ hε
have h3 : ∀ t, ‖L (f t)‖ ≤ ‖L‖ * ‖f t‖ := by
intro t
exact L.le_opNorm (f t)
refine (integral_mono (L.integrable_comp hif).norm (hif.norm.const_mul _) h3).trans_eq ?_
rw [integral_const_mul]
variable [NormedSpace ℝ E] [NormedSpace ℝ E'] [CompleteSpace E']
/-- Approximate `f ⋆ g` if the support of the `f` is bounded within a ball, and `g` is near `g x₀`
on a ball with the same radius around `x₀`.
This is a special case of `dist_convolution_le'` where `L` is `(•)`, `f` has integral 1 and `f` is
nonnegative. -/
theorem dist_convolution_le {f : G → ℝ} {x₀ : G} {R ε : ℝ} {z₀ : E'} (hε : 0 ≤ ε)
(hf : support f ⊆ ball (0 : G) R) (hnf : ∀ x, 0 ≤ f x) (hintf : ∫ x, f x ∂μ = 1)
(hmg : AEStronglyMeasurable g μ) (hg : ∀ x ∈ ball x₀ R, dist (g x) z₀ ≤ ε) :
dist ((f ⋆[lsmul ℝ ℝ, μ] g : G → E') x₀) z₀ ≤ ε := by
have hif : Integrable f μ := integrable_of_integral_eq_one hintf
convert (dist_convolution_le' (lsmul ℝ ℝ) hε hif hf hmg hg).trans _
· simp_rw [lsmul_apply, integral_smul_const, hintf, one_smul]
· simp_rw [Real.norm_of_nonneg (hnf _), hintf, mul_one]
exact (mul_le_mul_of_nonneg_right opNorm_lsmul_le hε).trans_eq (one_mul ε)
/-- `(φ i ⋆ g i) (k i)` tends to `z₀` as `i` tends to some filter `l` if
* `φ` is a sequence of nonnegative functions with integral `1` as `i` tends to `l`;
* The support of `φ` tends to small neighborhoods around `(0 : G)` as `i` tends to `l`;
* `g i` is `mu`-a.e. strongly measurable as `i` tends to `l`;
* `g i x` tends to `z₀` as `(i, x)` tends to `l ×ˢ 𝓝 x₀`;
* `k i` tends to `x₀`.
See also `ContDiffBump.convolution_tendsto_right`.
-/
theorem convolution_tendsto_right {ι} {g : ι → G → E'} {l : Filter ι} {x₀ : G} {z₀ : E'}
{φ : ι → G → ℝ} {k : ι → G} (hnφ : ∀ᶠ i in l, ∀ x, 0 ≤ φ i x)
(hiφ : ∀ᶠ i in l, ∫ x, φ i x ∂μ = 1)
-- todo: we could weaken this to "the integral tends to 1"
(hφ : Tendsto (fun n => support (φ n)) l (𝓝 0).smallSets)
(hmg : ∀ᶠ i in l, AEStronglyMeasurable (g i) μ) (hcg : Tendsto (uncurry g) (l ×ˢ 𝓝 x₀) (𝓝 z₀))
(hk : Tendsto k l (𝓝 x₀)) :
Tendsto (fun i : ι => (φ i ⋆[lsmul ℝ ℝ, μ] g i : G → E') (k i)) l (𝓝 z₀) := by
simp_rw [tendsto_smallSets_iff] at hφ
rw [Metric.tendsto_nhds] at hcg ⊢
simp_rw [Metric.eventually_prod_nhds_iff] at hcg
intro ε hε
have h2ε : 0 < ε / 3 := div_pos hε (by norm_num)
obtain ⟨p, hp, δ, hδ, hgδ⟩ := hcg _ h2ε
dsimp only [uncurry] at hgδ
have h2k := hk.eventually (ball_mem_nhds x₀ <| half_pos hδ)
have h2φ := hφ (ball (0 : G) _) <| ball_mem_nhds _ (half_pos hδ)
filter_upwards [hp, h2k, h2φ, hnφ, hiφ, hmg] with i hpi hki hφi hnφi hiφi hmgi
have hgi : dist (g i (k i)) z₀ < ε / 3 := hgδ hpi (hki.trans <| half_lt_self hδ)
have h1 : ∀ x' ∈ ball (k i) (δ / 2), dist (g i x') (g i (k i)) ≤ ε / 3 + ε / 3 := by
intro x' hx'
refine (dist_triangle_right _ _ _).trans (add_le_add (hgδ hpi ?_).le hgi.le)
exact ((dist_triangle _ _ _).trans_lt (add_lt_add hx'.out hki)).trans_eq (add_halves δ)
have := dist_convolution_le (add_pos h2ε h2ε).le hφi hnφi hiφi hmgi h1
refine ((dist_triangle _ _ _).trans_lt (add_lt_add_of_le_of_lt this hgi)).trans_eq ?_
field_simp; ring_nf
end NormedAddCommGroup
end Measurability
end NontriviallyNormedField
open scoped Convolution
section RCLike
variable [RCLike 𝕜]
variable [NormedSpace 𝕜 E]
variable [NormedSpace 𝕜 E']
variable [NormedSpace 𝕜 E'']
variable [NormedSpace ℝ F] [NormedSpace 𝕜 F]
variable {n : ℕ∞}
variable [MeasurableSpace G] {μ ν : Measure G}
variable (L : E →L[𝕜] E' →L[𝕜] F)
section Assoc
variable [CompleteSpace F]
variable [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedSpace 𝕜 F'] [CompleteSpace F']
variable [NormedAddCommGroup F''] [NormedSpace ℝ F''] [NormedSpace 𝕜 F''] [CompleteSpace F'']
variable {k : G → E''}
variable (L₂ : F →L[𝕜] E'' →L[𝕜] F')
variable (L₃ : E →L[𝕜] F'' →L[𝕜] F')
variable (L₄ : E' →L[𝕜] E'' →L[𝕜] F'')
variable [AddGroup G]
variable [SFinite μ] [SFinite ν] [IsAddRightInvariant μ]
theorem integral_convolution [MeasurableAdd₂ G] [MeasurableNeg G] [NormedSpace ℝ E]
[NormedSpace ℝ E'] [CompleteSpace E] [CompleteSpace E'] (hf : Integrable f ν)
(hg : Integrable g μ) : ∫ x, (f ⋆[L, ν] g) x ∂μ = L (∫ x, f x ∂ν) (∫ x, g x ∂μ) := by
refine (integral_integral_swap (by apply hf.convolution_integrand L hg)).trans ?_
simp_rw [integral_comp_comm _ (hg.comp_sub_right _), integral_sub_right_eq_self]
exact (L.flip (∫ x, g x ∂μ)).integral_comp_comm hf
variable [MeasurableAdd₂ G] [IsAddRightInvariant ν] [MeasurableNeg G]
/-- Convolution is associative. This has a weak but inconvenient integrability condition.
See also `MeasureTheory.convolution_assoc`. -/
theorem convolution_assoc' (hL : ∀ (x : E) (y : E') (z : E''), L₂ (L x y) z = L₃ x (L₄ y z))
{x₀ : G} (hfg : ∀ᵐ y ∂μ, ConvolutionExistsAt f g y L ν)
(hgk : ∀ᵐ x ∂ν, ConvolutionExistsAt g k x L₄ μ)
(hi : Integrable (uncurry fun x y => (L₃ (f y)) ((L₄ (g (x - y))) (k (x₀ - x)))) (μ.prod ν)) :
((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ :=
calc
((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = ∫ t, L₂ (∫ s, L (f s) (g (t - s)) ∂ν) (k (x₀ - t)) ∂μ := rfl
_ = ∫ t, ∫ s, L₂ (L (f s) (g (t - s))) (k (x₀ - t)) ∂ν ∂μ :=
(integral_congr_ae (hfg.mono fun t ht => ((L₂.flip (k (x₀ - t))).integral_comp_comm ht).symm))
_ = ∫ t, ∫ s, L₃ (f s) (L₄ (g (t - s)) (k (x₀ - t))) ∂ν ∂μ := by simp_rw [hL]
_ = ∫ s, ∫ t, L₃ (f s) (L₄ (g (t - s)) (k (x₀ - t))) ∂μ ∂ν := by rw [integral_integral_swap hi]
_ = ∫ s, ∫ u, L₃ (f s) (L₄ (g u) (k (x₀ - s - u))) ∂μ ∂ν := by
congr; ext t
rw [eq_comm, ← integral_sub_right_eq_self _ t]
simp_rw [sub_sub_sub_cancel_right]
_ = ∫ s, L₃ (f s) (∫ u, L₄ (g u) (k (x₀ - s - u)) ∂μ) ∂ν := by
refine integral_congr_ae ?_
refine ((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => ?_
exact (L₃ (f t)).integral_comp_comm ht
_ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := rfl
/-- Convolution is associative. This requires that
* all maps are a.e. strongly measurable w.r.t one of the measures
* `f ⋆[L, ν] g` exists almost everywhere
* `‖g‖ ⋆[μ] ‖k‖` exists almost everywhere
* `‖f‖ ⋆[ν] (‖g‖ ⋆[μ] ‖k‖)` exists at `x₀` -/
theorem convolution_assoc (hL : ∀ (x : E) (y : E') (z : E''), L₂ (L x y) z = L₃ x (L₄ y z)) {x₀ : G}
(hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g μ) (hk : AEStronglyMeasurable k μ)
(hfg : ∀ᵐ y ∂μ, ConvolutionExistsAt f g y L ν)
(hgk : ∀ᵐ x ∂ν, ConvolutionExistsAt (fun x => ‖g x‖) (fun x => ‖k x‖) x (mul ℝ ℝ) μ)
(hfgk :
ConvolutionExistsAt (fun x => ‖f x‖) ((fun x => ‖g x‖) ⋆[mul ℝ ℝ, μ] fun x => ‖k x‖) x₀
(mul ℝ ℝ) ν) :
((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := by
refine convolution_assoc' L L₂ L₃ L₄ hL hfg (hgk.mono fun x hx => hx.of_norm L₄ hg hk) ?_
-- the following is similar to `Integrable.convolution_integrand`
have h_meas :
AEStronglyMeasurable (uncurry fun x y => L₃ (f y) (L₄ (g x) (k (x₀ - y - x))))
(μ.prod ν) := by
refine L₃.aestronglyMeasurable_comp₂ hf.snd ?_
refine L₄.aestronglyMeasurable_comp₂ hg.fst ?_
refine (hk.mono_ac ?_).comp_measurable
((measurable_const.sub measurable_snd).sub measurable_fst)
refine QuasiMeasurePreserving.absolutelyContinuous ?_
refine QuasiMeasurePreserving.prod_of_left
((measurable_const.sub measurable_snd).sub measurable_fst) (Eventually.of_forall fun y => ?_)
dsimp only
exact quasiMeasurePreserving_sub_left_of_right_invariant μ _
have h2_meas :
AEStronglyMeasurable (fun y => ∫ x, ‖L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))‖ ∂μ) ν :=
h_meas.prod_swap.norm.integral_prod_right'
have h3 : map (fun z : G × G => (z.1 - z.2, z.2)) (μ.prod ν) = μ.prod ν :=
(measurePreserving_sub_prod μ ν).map_eq
suffices Integrable (uncurry fun x y => L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))) (μ.prod ν) by
rw [← h3] at this
convert this.comp_measurable (measurable_sub.prodMk measurable_snd)
ext ⟨x, y⟩
simp +unfoldPartialApp only [uncurry, Function.comp_apply,
sub_sub_sub_cancel_right]
simp_rw [integrable_prod_iff' h_meas]
refine ⟨((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht =>
(L₃ (f t)).integrable_comp <| ht.of_norm L₄ hg hk, ?_⟩
refine (hfgk.const_mul (‖L₃‖ * ‖L₄‖)).mono' h2_meas
(((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => ?_)
simp_rw [convolution_def, mul_apply', mul_mul_mul_comm ‖L₃‖ ‖L₄‖, ← integral_const_mul]
rw [Real.norm_of_nonneg (by positivity)]
refine integral_mono_of_nonneg (Eventually.of_forall fun t => norm_nonneg _)
((ht.const_mul _).const_mul _) (Eventually.of_forall fun s => ?_)
simp only [← mul_assoc ‖L₄‖]
apply_rules [ContinuousLinearMap.le_of_opNorm₂_le_of_le, le_rfl]
end Assoc
variable [NormedAddCommGroup G] [BorelSpace G]
theorem convolution_precompR_apply {g : G → E'' →L[𝕜] E'} (hf : LocallyIntegrable f μ)
(hcg : HasCompactSupport g) (hg : Continuous g) (x₀ : G) (x : E'') :
(f ⋆[L.precompR E'', μ] g) x₀ x = (f ⋆[L, μ] fun a => g a x) x₀ := by
have := hcg.convolutionExists_right (L.precompR E'' :) hf hg x₀
simp_rw [convolution_def, ContinuousLinearMap.integral_apply this]
rfl
variable [NormedSpace 𝕜 G] [SFinite μ] [IsAddLeftInvariant μ]
/-- Compute the total derivative of `f ⋆ g` if `g` is `C^1` with compact support and `f` is locally
integrable. To write down the total derivative as a convolution, we use
`ContinuousLinearMap.precompR`. -/
| Mathlib/Analysis/Convolution.lean | 956 | 999 | theorem _root_.HasCompactSupport.hasFDerivAt_convolution_right (hcg : HasCompactSupport g)
(hf : LocallyIntegrable f μ) (hg : ContDiff 𝕜 1 g) (x₀ : G) :
HasFDerivAt (f ⋆[L, μ] g) ((f ⋆[L.precompR G, μ] fderiv 𝕜 g) x₀) x₀ := by | rcases hcg.eq_zero_or_finiteDimensional 𝕜 hg.continuous with (rfl | fin_dim)
· have : fderiv 𝕜 (0 : G → E') = 0 := fderiv_const (0 : E')
simp only [this, convolution_zero, Pi.zero_apply]
exact hasFDerivAt_const (0 : F) x₀
have : ProperSpace G := FiniteDimensional.proper_rclike 𝕜 G
set L' := L.precompR G
have h1 : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ :=
Eventually.of_forall
(hf.aestronglyMeasurable.convolution_integrand_snd L hg.continuous.aestronglyMeasurable)
have h2 : ∀ x, AEStronglyMeasurable (fun t => L' (f t) (fderiv 𝕜 g (x - t))) μ :=
hf.aestronglyMeasurable.convolution_integrand_snd L'
(hg.continuous_fderiv le_rfl).aestronglyMeasurable
have h3 : ∀ x t, HasFDerivAt (fun x => g (x - t)) (fderiv 𝕜 g (x - t)) x := fun x t ↦ by
simpa using
(hg.differentiable le_rfl).differentiableAt.hasFDerivAt.comp x
((hasFDerivAt_id x).sub (hasFDerivAt_const t x))
let K' := -tsupport (fderiv 𝕜 g) + closedBall x₀ 1
have hK' : IsCompact K' := (hcg.fderiv 𝕜).neg.add (isCompact_closedBall x₀ 1)
apply hasFDerivAt_integral_of_dominated_of_fderiv_le zero_lt_one h1 _ (h2 x₀)
· filter_upwards with t x hx using
(hcg.fderiv 𝕜).convolution_integrand_bound_right L' (hg.continuous_fderiv le_rfl)
(ball_subset_closedBall hx)
· rw [integrable_indicator_iff hK'.measurableSet]
exact ((hf.integrableOn_isCompact hK').norm.const_mul _).mul_const _
· exact Eventually.of_forall fun t x _ => (L _).hasFDerivAt.comp x (h3 x t)
· exact hcg.convolutionExists_right L hf hg.continuous x₀
theorem _root_.HasCompactSupport.hasFDerivAt_convolution_left [IsNegInvariant μ]
(hcf : HasCompactSupport f) (hf : ContDiff 𝕜 1 f) (hg : LocallyIntegrable g μ) (x₀ : G) :
HasFDerivAt (f ⋆[L, μ] g) ((fderiv 𝕜 f ⋆[L.precompL G, μ] g) x₀) x₀ := by
simp +singlePass only [← convolution_flip]
exact hcf.hasFDerivAt_convolution_right L.flip hg hf x₀
end RCLike
section Real
/-! The one-variable case -/
variable [RCLike 𝕜]
variable [NormedSpace 𝕜 E] |
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Dynamics.BirkhoffSum.Average
/-!
# Birkhoff average in a normed space
In this file we prove some lemmas about the Birkhoff average (`birkhoffAverage`)
of a function which takes values in a normed space over `ℝ` or `ℂ`.
At the time of writing, all lemmas in this file
are motivated by the proof of the von Neumann Mean Ergodic Theorem,
see `LinearIsometry.tendsto_birkhoffAverage_orthogonalProjection`.
-/
open Function Set Filter
open scoped Topology ENNReal Uniformity
section
variable {α E : Type*}
/-- The Birkhoff averages of a function `g` over the orbit of a fixed point `x` of `f`
tend to `g x` as `N → ∞`. In fact, they are equal to `g x` for all `N ≠ 0`,
see `Function.IsFixedPt.birkhoffAverage_eq`.
TODO: add a version for a periodic orbit. -/
theorem Function.IsFixedPt.tendsto_birkhoffAverage
(R : Type*) [DivisionSemiring R] [CharZero R]
[AddCommMonoid E] [TopologicalSpace E] [Module R E]
{f : α → α} {x : α} (h : f.IsFixedPt x) (g : α → E) :
Tendsto (birkhoffAverage R f g · x) atTop (𝓝 (g x)) :=
tendsto_const_nhds.congr' <| (eventually_ne_atTop 0).mono fun _n hn ↦
(h.birkhoffAverage_eq R g hn).symm
variable [NormedAddCommGroup E]
theorem dist_birkhoffSum_apply_birkhoffSum (f : α → α) (g : α → E) (n : ℕ) (x : α) :
dist (birkhoffSum f g n (f x)) (birkhoffSum f g n x) = dist (g (f^[n] x)) (g x) := by
simp only [dist_eq_norm, birkhoffSum_apply_sub_birkhoffSum]
theorem dist_birkhoffSum_birkhoffSum_le (f : α → α) (g : α → E) (n : ℕ) (x y : α) :
dist (birkhoffSum f g n x) (birkhoffSum f g n y) ≤
∑ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y)) :=
dist_sum_sum_le _ _ _
variable (𝕜 : Type*) [RCLike 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
theorem dist_birkhoffAverage_birkhoffAverage (f : α → α) (g : α → E) (n : ℕ) (x y : α) :
dist (birkhoffAverage 𝕜 f g n x) (birkhoffAverage 𝕜 f g n y) =
dist (birkhoffSum f g n x) (birkhoffSum f g n y) / n := by
simp [birkhoffAverage, dist_smul₀, div_eq_inv_mul]
theorem dist_birkhoffAverage_birkhoffAverage_le (f : α → α) (g : α → E) (n : ℕ) (x y : α) :
dist (birkhoffAverage 𝕜 f g n x) (birkhoffAverage 𝕜 f g n y) ≤
(∑ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y))) / n :=
(dist_birkhoffAverage_birkhoffAverage _ _ _ _ _ _).trans_le <| by
gcongr; apply dist_birkhoffSum_birkhoffSum_le
theorem dist_birkhoffAverage_apply_birkhoffAverage (f : α → α) (g : α → E) (n : ℕ) (x : α) :
dist (birkhoffAverage 𝕜 f g n (f x)) (birkhoffAverage 𝕜 f g n x) =
dist (g (f^[n] x)) (g x) / n := by
simp [dist_birkhoffAverage_birkhoffAverage, dist_birkhoffSum_apply_birkhoffSum]
/-- If a function `g` is bounded along the positive orbit of `x` under `f`,
then the difference between Birkhoff averages of `g`
along the orbit of `f x` and along the orbit of `x`
tends to zero.
See also `tendsto_birkhoffAverage_apply_sub_birkhoffAverage'`. -/
| Mathlib/Dynamics/BirkhoffSum/NormedSpace.lean | 75 | 84 | theorem tendsto_birkhoffAverage_apply_sub_birkhoffAverage {f : α → α} {g : α → E} {x : α}
(h : Bornology.IsBounded (range (g <| f^[·] x))) :
Tendsto (fun n ↦ birkhoffAverage 𝕜 f g n (f x) - birkhoffAverage 𝕜 f g n x) atTop (𝓝 0) := by | rcases Metric.isBounded_range_iff.1 h with ⟨C, hC⟩
have : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop
refine squeeze_zero_norm (fun n ↦ ?_) this
rw [← dist_eq_norm, dist_birkhoffAverage_apply_birkhoffAverage]
gcongr
exact hC n 0 |
/-
Copyright (c) 2022 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Data.Countable.Basic
import Mathlib.Data.Finset.Max
import Mathlib.Data.Fintype.Pigeonhole
import Mathlib.Logic.Encodable.Basic
import Mathlib.Order.Interval.Finset.Defs
import Mathlib.Order.SuccPred.Archimedean
/-!
# Linear locally finite orders
We prove that a `LinearOrder` which is a `LocallyFiniteOrder` also verifies
* `SuccOrder`
* `PredOrder`
* `IsSuccArchimedean`
* `IsPredArchimedean`
* `Countable`
Furthermore, we show that there is an `OrderIso` between such an order and a subset of `ℤ`.
## Main definitions
* `toZ i0 i`: in a linear order on which we can define predecessors and successors and which is
succ-archimedean, we can assign a unique integer `toZ i0 i` to each element `i : ι` while
respecting the order, starting from `toZ i0 i0 = 0`.
## Main results
Results about linear locally finite orders:
* `LinearLocallyFiniteOrder.SuccOrder`: a linear locally finite order has a successor function.
* `LinearLocallyFiniteOrder.PredOrder`: a linear locally finite order has a predecessor
function.
* `LinearLocallyFiniteOrder.isSuccArchimedean`: a linear locally finite order is
succ-archimedean.
* `LinearOrder.pred_archimedean_of_succ_archimedean`: a succ-archimedean linear order is also
pred-archimedean.
* `countable_of_linear_succ_pred_arch` : a succ-archimedean linear order is countable.
About `toZ`:
* `orderIsoRangeToZOfLinearSuccPredArch`: `toZ` defines an `OrderIso` between `ι` and its
range.
* `orderIsoNatOfLinearSuccPredArch`: if the order has a bot but no top, `toZ` defines an
`OrderIso` between `ι` and `ℕ`.
* `orderIsoIntOfLinearSuccPredArch`: if the order has neither bot nor top, `toZ` defines an
`OrderIso` between `ι` and `ℤ`.
* `orderIsoRangeOfLinearSuccPredArch`: if the order has both a bot and a top, `toZ` gives an
`OrderIso` between `ι` and `Finset.range ((toZ ⊥ ⊤).toNat + 1)`.
-/
open Order
variable {ι : Type*} [LinearOrder ι]
namespace LinearOrder
variable [SuccOrder ι] [PredOrder ι]
instance (priority := 100) isPredArchimedean_of_isSuccArchimedean [IsSuccArchimedean ι] :
IsPredArchimedean ι where
exists_pred_iterate_of_le {i j} hij := by
have h_exists := exists_succ_iterate_of_le hij
obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j :=
⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩
refine ⟨n, ?_⟩
rw [← hn_eq]
cases n with
| zero => simp only [Function.iterate_zero, id]
| succ n =>
rw [pred_succ_iterate_of_not_isMax]
rw [Nat.succ_sub_succ_eq_sub, tsub_zero]
suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this
refine lt_of_le_of_ne ?_ ?_
· rw [Function.iterate_succ_apply']
exact le_succ _
· rw [hn_eq]
exact hn_lt_ne _ (Nat.lt_succ_self n)
instance isSuccArchimedean_of_isPredArchimedean [IsPredArchimedean ι] : IsSuccArchimedean ι :=
inferInstanceAs (IsSuccArchimedean ιᵒᵈᵒᵈ)
/-- In a linear `SuccOrder` that's also a `PredOrder`, `IsSuccArchimedean` and `IsPredArchimedean`
are equivalent. -/
theorem isSuccArchimedean_iff_isPredArchimedean : IsSuccArchimedean ι ↔ IsPredArchimedean ι where
mp _ := isPredArchimedean_of_isSuccArchimedean
mpr _ := isSuccArchimedean_of_isPredArchimedean
end LinearOrder
namespace LinearLocallyFiniteOrder
/-- Successor in a linear order. This defines a true successor only when `i` is isolated from above,
i.e. when `i` is not the greatest lower bound of `(i, ∞)`. -/
noncomputable def succFn (i : ι) : ι :=
(exists_glb_Ioi i).choose
| Mathlib/Order/SuccPred/LinearLocallyFinite.lean | 103 | 106 | theorem succFn_spec (i : ι) : IsGLB (Set.Ioi i) (succFn i) :=
(exists_glb_Ioi i).choose_spec
theorem le_succFn (i : ι) : i ≤ succFn i := by | |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps
import Mathlib.Analysis.Normed.Module.FiniteDimension
import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap
import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable
/-!
# Derivative is measurable
In this file we prove that the derivative of any function with complete codomain is a measurable
function. Namely, we prove:
* `measurableSet_of_differentiableAt`: the set `{x | DifferentiableAt 𝕜 f x}` is measurable;
* `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable;
* `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `fun x ↦ fderiv 𝕜 f x y`
is measurable;
* `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → F`).
We also show the same results for the right derivative on the real line
(see `measurable_derivWithin_Ici` and `measurable_derivWithin_Ioi`), following the same
proof strategy.
We also prove measurability statements for functions depending on a parameter: for `f : α → E → F`,
we show the measurability of `(p : α × E) ↦ fderiv 𝕜 (f p.1) p.2`. This requires additional
assumptions. We give versions of the above statements (appending `with_param` to their names) when
`f` is continuous and `E` is locally compact.
## Implementation
We give a proof that avoids second-countability issues, by expressing the differentiability set
as a function of open sets in the following way. Define `A (L, r, ε)` to be the set of points
where, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the
linear map `L`, up to `ε r`. It is an open set.
Let also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: we require that at two possibly different
scales `r` and `s`, the function is well approximated by the linear map `L`. It is also open.
We claim that the differentiability set of `f` is exactly
`D = ⋂ ε > 0, ⋃ δ > 0, ⋂ r, s < δ, ⋃ L, B (L, r, s, ε)`.
In other words, for any `ε > 0`, we require that there is a size `δ` such that, for any two scales
below this size, the function is well approximated by a linear map, common to the two scales.
The set `⋃ L, B (L, r, s, ε)` is open, as a union of open sets. Converting the intersections and
unions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the
differentiability set is measurable.
To prove the claim, there are two inclusions. One is trivial: if the function is differentiable
at `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the
differentiability exactly says that the map is well approximated by `L`). This is proved in
`mem_A_of_differentiable` and `differentiable_set_subset_D`.
For the other direction, the difficulty is that `L` in the union may depend on `ε, r, s`. The key
point is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to
`A (L, r, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus
`‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps
`L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, one deduces that `L` is
close to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a
linear map `L₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as
`x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s`
w.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is
close to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (as they are
close on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed.
It follows that the different approximating linear maps that show up form a Cauchy sequence when
`ε` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`.
With the same kind of arguments, one checks that `f` is differentiable with derivative `f'`.
To show that the derivative itself is measurable, add in the definition of `B` and `D` a set
`K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K`
is exactly the set of points where `f` is differentiable with a derivative in `K`.
## Tags
derivative, measurable function, Borel σ-algebra
-/
noncomputable section
open Set Metric Asymptotics Filter ContinuousLinearMap MeasureTheory TopologicalSpace
open scoped Topology
namespace ContinuousLinearMap
variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E]
[NormedAddCommGroup F] [NormedSpace 𝕜 F]
theorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E]
[SecondCountableTopologyEither (E →L[𝕜] F) E]
[MeasurableSpace F] [BorelSpace F] : Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 :=
isBoundedBilinearMap_apply.continuous.measurable
end ContinuousLinearMap
section fderiv
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f : E → F} (K : Set (E →L[𝕜] F))
namespace FDerivMeasurableAux
/-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated
at scale `r` by the linear map `L`, up to an error `ε`. We tweak the definition to make sure that
this is an open set. -/
def A (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E :=
{ x | ∃ r' ∈ Ioc (r / 2) r, ∀ y ∈ ball x r', ∀ z ∈ ball x r', ‖f z - f y - L (z - y)‖ < ε * r }
/-- The set `B f K r s ε` is the set of points `x` around which there exists a continuous linear map
`L` belonging to `K` (a given set of continuous linear maps) that approximates well the
function `f` (up to an error `ε`), simultaneously at scales `r` and `s`. -/
def B (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E :=
⋃ L ∈ K, A f L r ε ∩ A f L s ε
/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its
main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,
with a derivative in `K`. -/
def D (f : E → F) (K : Set (E →L[𝕜] F)) : Set E :=
⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e)
theorem isOpen_A (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (A f L r ε) := by
rw [Metric.isOpen_iff]
rintro x ⟨r', r'_mem, hr'⟩
obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1
have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩
refine ⟨r' - s, by linarith, fun x' hx' => ⟨s, this, ?_⟩⟩
have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx')
intro y hy z hz
exact hr' y (B hy) z (B hz)
theorem isOpen_B {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (B f K r s ε) := by
simp [B, isOpen_biUnion, IsOpen.inter, isOpen_A]
theorem A_mono (L : E →L[𝕜] F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by
rintro x ⟨r', r'r, hr'⟩
refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans_le (mul_le_mul_of_nonneg_right h ?_)⟩
linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x]
theorem le_of_mem_A {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ A f L r ε) {y z : E}
(hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) :
‖f z - f y - L (z - y)‖ ≤ ε * r := by
rcases hx with ⟨r', r'mem, hr'⟩
apply le_of_lt
exact hr' _ ((mem_closedBall.1 hy).trans_lt r'mem.1) _ ((mem_closedBall.1 hz).trans_lt r'mem.1)
theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) :
∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (fderiv 𝕜 f x) r ε := by
let δ := (ε / 2) / 2
obtain ⟨R, R_pos, hR⟩ :
∃ R > 0, ∀ y ∈ ball x R, ‖f y - f x - fderiv 𝕜 f x (y - x)‖ ≤ δ * ‖y - x‖ :=
eventually_nhds_iff_ball.1 <| hx.hasFDerivAt.isLittleO.bound <| by positivity
refine ⟨R, R_pos, fun r hr => ?_⟩
have : r ∈ Ioc (r / 2) r := right_mem_Ioc.2 <| half_lt_self hr.1
refine ⟨r, this, fun y hy z hz => ?_⟩
calc
‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ =
‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ := by
simp only [map_sub]; abel_nf
_ ≤ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ :=
norm_sub_le _ _
_ ≤ δ * ‖z - x‖ + δ * ‖y - x‖ :=
add_le_add (hR _ (ball_subset_ball hr.2.le hz)) (hR _ (ball_subset_ball hr.2.le hy))
_ ≤ δ * r + δ * r := by rw [mem_ball_iff_norm] at hz hy; gcongr
_ = (ε / 2) * r := by ring
_ < ε * r := by gcongr; exacts [hr.1, half_lt_self hε]
theorem norm_sub_le_of_mem_A {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E}
{L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ‖c‖ * ε := by
refine opNorm_le_of_shell (half_pos hr) (by positivity) hc ?_
intro y ley ylt
rw [div_div, div_le_iff₀' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley
calc
‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by
simp
_ ≤ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := norm_sub_le _ _
_ ≤ ε * r + ε * r := by
apply add_le_add
· apply le_of_mem_A h₂
· simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self]
· simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le]
· apply le_of_mem_A h₁
· simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self]
· simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le]
_ = 2 * ε * r := by ring
_ ≤ 2 * ε * (2 * ‖c‖ * ‖y‖) := by gcongr
_ = 4 * ‖c‖ * ε * ‖y‖ := by ring
/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/
theorem differentiable_set_subset_D :
{ x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ D f K := by
intro x hx
rw [D, mem_iInter]
intro e
have : (0 : ℝ) < (1 / 2) ^ e := by positivity
rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩
obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R :=
exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1)
simp only [mem_iUnion, mem_iInter, B, mem_inter_iff]
refine ⟨n, fun p hp q hq => ⟨fderiv 𝕜 f x, hx.2, ⟨?_, ?_⟩⟩⟩ <;>
· refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩
exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption)
/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/
theorem D_subset_differentiable_set {K : Set (E →L[𝕜] F)} (hK : IsComplete K) :
D f K ⊆ { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by
have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
intro x hx
have :
∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q →
∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by
intro e
have := mem_iInter.1 hx e
rcases mem_iUnion.1 this with ⟨n, hn⟩
refine ⟨n, fun p q hp hq => ?_⟩
simp only [mem_iInter] at hn
rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩
exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩
/- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`
such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and
`2 ^ (-q)`, with an error `2 ^ (-e)`. -/
choose! n L hn using this
/- All the operators `L e p q` that show up are close to each other. To prove this, we argue
that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at
scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale
`2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale
`2 ^ (- p')`. -/
have M :
∀ e p q e' p' q',
n e ≤ p →
n e ≤ q →
n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by
intro e p q e' p' q' hp hq hp' hq' he'
let r := max (n e) (n e')
have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e :=
pow_le_pow_of_le_one (by norm_num) (by norm_num) he'
have J1 : ‖L e p q - L e p r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1
have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1
exact norm_sub_le_of_mem_A hc P P I1 I2
have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2
have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.2
exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2)
have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.1
have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1
exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2)
calc
‖L e p q - L e' p' q'‖ =
‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by
congr 1; abel
_ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ :=
norm_add₃_le
_ ≤ 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e := by gcongr
_ = 12 * ‖c‖ * (1 / 2) ^ e := by ring
/- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this
is a Cauchy sequence. -/
let L0 : ℕ → E →L[𝕜] F := fun e => L e (n e) (n e)
have : CauchySeq L0 := by
rw [Metric.cauchySeq_iff']
intro ε εpos
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (12 * ‖c‖) :=
exists_pow_lt_of_lt_one (by positivity) (by norm_num)
refine ⟨e, fun e' he' => ?_⟩
rw [dist_comm, dist_eq_norm]
calc
‖L0 e - L0 e'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'
_ < 12 * ‖c‖ * (ε / (12 * ‖c‖)) := by gcongr
_ = ε := by field_simp
-- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.
obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') :=
cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this
have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by
intro e p hp
apply le_of_tendsto (tendsto_const_nhds.sub hf').norm
rw [eventually_atTop]
exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩
-- Let us show that `f` has derivative `f'` at `x`.
have : HasFDerivAt f f' x := by
simp only [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff]
/- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for
some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,
this makes it possible to cover all scales, and thus to obtain a good linear approximation in
the whole ball of radius `(1/2)^(n e)`. -/
intro ε εpos
have pos : 0 < 4 + 12 * ‖c‖ := by positivity
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (4 + 12 * ‖c‖) :=
exists_pow_lt_of_lt_one (div_pos εpos pos) (by norm_num)
rw [eventually_nhds_iff_ball]
refine ⟨(1 / 2) ^ (n e + 1), P, fun y hy => ?_⟩
-- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale
-- `k` where `k` is chosen with `‖y‖ ∼ 2 ^ (-k)`.
by_cases y_pos : y = 0
· simp [y_pos]
have yzero : 0 < ‖y‖ := norm_pos_iff.mpr y_pos
have y_lt : ‖y‖ < (1 / 2) ^ (n e + 1) := by simpa using mem_ball_iff_norm.1 hy
have yone : ‖y‖ ≤ 1 := le_trans y_lt.le (pow_le_one₀ (by norm_num) (by norm_num))
-- define the scale `k`.
obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < ‖y‖ ∧ ‖y‖ ≤ (1 / 2) ^ k :=
exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2)
(by norm_num : (1 : ℝ) / 2 < 1)
-- the scale is large enough (as `y` is small enough)
have k_gt : n e < k := by
have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_trans hk y_lt
rw [pow_lt_pow_iff_right_of_lt_one₀ (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this
omega
set m := k - 1
have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt
have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm
rw [km] at hk h'k
-- `f` is well approximated by `L e (n e) k` at the relevant scale
-- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).
have J1 : ‖f (x + y) - f x - L e (n e) m (x + y - x)‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by
apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2
· simp only [mem_closedBall, dist_self]
positivity
· simpa only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, pow_succ, mul_one_div] using
h'k
have J2 : ‖f (x + y) - f x - L e (n e) m y‖ ≤ 4 * (1 / 2) ^ e * ‖y‖ :=
calc
‖f (x + y) - f x - L e (n e) m y‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by
simpa only [add_sub_cancel_left] using J1
_ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring
_ ≤ 4 * (1 / 2) ^ e * ‖y‖ := by gcongr
-- use the previous estimates to see that `f (x + y) - f x - f' y` is small.
calc
‖f (x + y) - f x - f' y‖ = ‖f (x + y) - f x - L e (n e) m y + (L e (n e) m - f') y‖ :=
congr_arg _ (by simp)
_ ≤ 4 * (1 / 2) ^ e * ‖y‖ + 12 * ‖c‖ * (1 / 2) ^ e * ‖y‖ :=
norm_add_le_of_le J2 <| (le_opNorm _ _).trans <| by gcongr; exact Lf' _ _ m_ge
_ = (4 + 12 * ‖c‖) * ‖y‖ * (1 / 2) ^ e := by ring
_ ≤ (4 + 12 * ‖c‖) * ‖y‖ * (ε / (4 + 12 * ‖c‖)) := by gcongr
_ = ε * ‖y‖ := by field_simp [ne_of_gt pos]; ring
rw [← this.fderiv] at f'K
exact ⟨this.differentiableAt, f'K⟩
theorem differentiable_set_eq_D (hK : IsComplete K) :
{ x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } = D f K :=
Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)
end FDerivMeasurableAux
open FDerivMeasurableAux
variable [MeasurableSpace E] [OpensMeasurableSpace E]
variable (𝕜 f)
/-- The set of differentiability points of a function, with derivative in a given complete set,
is Borel-measurable. -/
theorem measurableSet_of_differentiableAt_of_isComplete {K : Set (E →L[𝕜] F)} (hK : IsComplete K) :
MeasurableSet { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by
-- Porting note: was
-- simp [differentiable_set_eq_D K hK, D, isOpen_B.measurableSet, MeasurableSet.iInter,
-- MeasurableSet.iUnion]
simp only [D, differentiable_set_eq_D K hK]
repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro
exact isOpen_B.measurableSet
variable [CompleteSpace F]
/-- The set of differentiability points of a function taking values in a complete space is
Borel-measurable. -/
theorem measurableSet_of_differentiableAt : MeasurableSet { x | DifferentiableAt 𝕜 f x } := by
have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ
convert measurableSet_of_differentiableAt_of_isComplete 𝕜 f this
simp
@[measurability, fun_prop]
theorem measurable_fderiv : Measurable (fderiv 𝕜 f) := by
refine measurable_of_isClosed fun s hs => ?_
have :
fderiv 𝕜 f ⁻¹' s =
{ x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s } ∪
{ x | ¬DifferentiableAt 𝕜 f x } ∩ { _x | (0 : E →L[𝕜] F) ∈ s } :=
Set.ext fun x => mem_preimage.trans fderiv_mem_iff
rw [this]
exact
(measurableSet_of_differentiableAt_of_isComplete _ _ hs.isComplete).union
((measurableSet_of_differentiableAt _ _).compl.inter (MeasurableSet.const _))
@[measurability, fun_prop]
theorem measurable_fderiv_apply_const [MeasurableSpace F] [BorelSpace F] (y : E) :
Measurable fun x => fderiv 𝕜 f x y :=
(ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv 𝕜 f)
variable {𝕜}
@[measurability, fun_prop]
theorem measurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F]
[BorelSpace F] (f : 𝕜 → F) : Measurable (deriv f) := by
simpa only [fderiv_deriv] using measurable_fderiv_apply_const 𝕜 f 1
theorem stronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜]
[h : SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) : StronglyMeasurable (deriv f) := by
borelize F
rcases h.out with h𝕜|hF
· exact stronglyMeasurable_iff_measurable_separable.2
⟨measurable_deriv f, isSeparable_range_deriv _⟩
· exact (measurable_deriv f).stronglyMeasurable
theorem aemeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F]
[BorelSpace F] (f : 𝕜 → F) (μ : Measure 𝕜) : AEMeasurable (deriv f) μ :=
(measurable_deriv f).aemeasurable
theorem aestronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜]
[SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) (μ : Measure 𝕜) :
AEStronglyMeasurable (deriv f) μ :=
(stronglyMeasurable_deriv f).aestronglyMeasurable
end fderiv
section RightDeriv
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
variable {f : ℝ → F} (K : Set F)
namespace RightDerivMeasurableAux
/-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated
at scale `r` by the linear map `h ↦ h • L`, up to an error `ε`. We tweak the definition to
make sure that this is open on the right. -/
def A (f : ℝ → F) (L : F) (r ε : ℝ) : Set ℝ :=
{ x | ∃ r' ∈ Ioc (r / 2) r, ∀ᵉ (y ∈ Icc x (x + r')) (z ∈ Icc x (x + r')),
‖f z - f y - (z - y) • L‖ ≤ ε * r }
/-- The set `B f K r s ε` is the set of points `x` around which there exists a vector
`L` belonging to `K` (a given set of vectors) such that `h • L` approximates well `f (x + h)`
(up to an error `ε`), simultaneously at scales `r` and `s`. -/
def B (f : ℝ → F) (K : Set F) (r s ε : ℝ) : Set ℝ :=
⋃ L ∈ K, A f L r ε ∩ A f L s ε
/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its
main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,
with a derivative in `K`. -/
def D (f : ℝ → F) (K : Set F) : Set ℝ :=
⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e)
theorem A_mem_nhdsGT {L : F} {r ε x : ℝ} (hx : x ∈ A f L r ε) : A f L r ε ∈ 𝓝[>] x := by
rcases hx with ⟨r', rr', hr'⟩
obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between rr'.1
have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le rr'.2)⟩
filter_upwards [Ioo_mem_nhdsGT <| show x < x + r' - s by linarith] with x' hx'
use s, this
have A : Icc x' (x' + s) ⊆ Icc x (x + r') := by
apply Icc_subset_Icc hx'.1.le
linarith [hx'.2]
intro y hy z hz
exact hr' y (A hy) z (A hz)
theorem B_mem_nhdsGT {K : Set F} {r s ε x : ℝ} (hx : x ∈ B f K r s ε) :
B f K r s ε ∈ 𝓝[>] x := by
obtain ⟨L, LK, hL₁, hL₂⟩ : ∃ L : F, L ∈ K ∧ x ∈ A f L r ε ∧ x ∈ A f L s ε := by
simpa only [B, mem_iUnion, mem_inter_iff, exists_prop] using hx
filter_upwards [A_mem_nhdsGT hL₁, A_mem_nhdsGT hL₂] with y hy₁ hy₂
simp only [B, mem_iUnion, mem_inter_iff, exists_prop]
exact ⟨L, LK, hy₁, hy₂⟩
theorem measurableSet_B {K : Set F} {r s ε : ℝ} : MeasurableSet (B f K r s ε) :=
.of_mem_nhdsGT fun _ hx => B_mem_nhdsGT hx
theorem A_mono (L : F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by
rintro x ⟨r', r'r, hr'⟩
refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h ?_)⟩
linarith [hy.1, hy.2, r'r.2]
theorem le_of_mem_A {r ε : ℝ} {L : F} {x : ℝ} (hx : x ∈ A f L r ε) {y z : ℝ}
(hy : y ∈ Icc x (x + r / 2)) (hz : z ∈ Icc x (x + r / 2)) :
‖f z - f y - (z - y) • L‖ ≤ ε * r := by
rcases hx with ⟨r', r'mem, hr'⟩
have A : x + r / 2 ≤ x + r' := by linarith [r'mem.1]
exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz)
theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : ℝ}
(hx : DifferentiableWithinAt ℝ f (Ici x) x) :
∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (derivWithin f (Ici x) x) r ε := by
have := hx.hasDerivWithinAt
simp_rw [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] at this
rcases mem_nhdsGE_iff_exists_Ico_subset.1 (this (half_pos hε)) with ⟨m, xm, hm⟩
refine ⟨m - x, by linarith [show x < m from xm], fun r hr => ?_⟩
have : r ∈ Ioc (r / 2) r := ⟨half_lt_self hr.1, le_rfl⟩
refine ⟨r, this, fun y hy z hz => ?_⟩
calc
‖f z - f y - (z - y) • derivWithin f (Ici x) x‖ =
‖f z - f x - (z - x) • derivWithin f (Ici x) x -
(f y - f x - (y - x) • derivWithin f (Ici x) x)‖ := by
congr 1; simp only [sub_smul]; abel
_ ≤
‖f z - f x - (z - x) • derivWithin f (Ici x) x‖ +
‖f y - f x - (y - x) • derivWithin f (Ici x) x‖ :=
(norm_sub_le _ _)
_ ≤ ε / 2 * ‖z - x‖ + ε / 2 * ‖y - x‖ :=
(add_le_add (hm ⟨hz.1, hz.2.trans_lt (by linarith [hr.2])⟩)
(hm ⟨hy.1, hy.2.trans_lt (by linarith [hr.2])⟩))
_ ≤ ε / 2 * r + ε / 2 * r := by
gcongr
· rw [Real.norm_of_nonneg] <;> linarith [hz.1, hz.2]
· rw [Real.norm_of_nonneg] <;> linarith [hy.1, hy.2]
_ = ε * r := by ring
theorem norm_sub_le_of_mem_A {r x : ℝ} (hr : 0 < r) (ε : ℝ) {L₁ L₂ : F} (h₁ : x ∈ A f L₁ r ε)
(h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ε := by
suffices H : ‖(r / 2) • (L₁ - L₂)‖ ≤ r / 2 * (4 * ε) by
rwa [norm_smul, Real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H
calc
‖(r / 2) • (L₁ - L₂)‖ =
‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂ -
(f (x + r / 2) - f x - (x + r / 2 - x) • L₁)‖ := by
simp [smul_sub]
_ ≤ ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂‖ +
‖f (x + r / 2) - f x - (x + r / 2 - x) • L₁‖ :=
norm_sub_le _ _
_ ≤ ε * r + ε * r := by
apply add_le_add
· apply le_of_mem_A h₂ <;> simp [(half_pos hr).le]
· apply le_of_mem_A h₁ <;> simp [(half_pos hr).le]
_ = r / 2 * (4 * ε) := by ring
/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/
theorem differentiable_set_subset_D :
{ x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } ⊆ D f K := by
intro x hx
rw [D, mem_iInter]
intro e
have : (0 : ℝ) < (1 / 2) ^ e := pow_pos (by norm_num) _
rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩
obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R :=
exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1)
simp only [mem_iUnion, mem_iInter, B, mem_inter_iff]
refine ⟨n, fun p hp q hq => ⟨derivWithin f (Ici x) x, hx.2, ⟨?_, ?_⟩⟩⟩ <;>
· refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩
exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption)
/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/
theorem D_subset_differentiable_set {K : Set F} (hK : IsComplete K) :
D f K ⊆ { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by
have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n
intro x hx
have :
∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q →
∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by
intro e
have := mem_iInter.1 hx e
rcases mem_iUnion.1 this with ⟨n, hn⟩
refine ⟨n, fun p q hp hq => ?_⟩
simp only [mem_iInter] at hn
rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩
exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩
/- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`
such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and
`2 ^ (-q)`, with an error `2 ^ (-e)`. -/
choose! n L hn using this
/- All the operators `L e p q` that show up are close to each other. To prove this, we argue
that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at
scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale
`2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale
`2 ^ (- p')`. -/
have M :
∀ e p q e' p' q',
n e ≤ p →
n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * (1 / 2) ^ e := by
intro e p q e' p' q' hp hq hp' hq' he'
let r := max (n e) (n e')
have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e :=
pow_le_pow_of_le_one (by norm_num) (by norm_num) he'
have J1 : ‖L e p q - L e p r‖ ≤ 4 * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1
have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1
exact norm_sub_le_of_mem_A P _ I1 I2
have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2
have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.2
exact norm_sub_le_of_mem_A P _ I1 (A_mono _ _ I I2)
have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.1
have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1
exact norm_sub_le_of_mem_A P _ (A_mono _ _ I I1) (A_mono _ _ I I2)
calc
‖L e p q - L e' p' q'‖ =
‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by
congr 1; abel
_ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ :=
(le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _))
_ ≤ 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e := by gcongr
_ = 12 * (1 / 2) ^ e := by ring
/- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this
is a Cauchy sequence. -/
let L0 : ℕ → F := fun e => L e (n e) (n e)
have : CauchySeq L0 := by
rw [Metric.cauchySeq_iff']
intro ε εpos
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 12 :=
exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num)
refine ⟨e, fun e' he' => ?_⟩
rw [dist_comm, dist_eq_norm]
calc
‖L0 e - L0 e'‖ ≤ 12 * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'
_ < 12 * (ε / 12) := mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num)
_ = ε := by field_simp [(by norm_num : (12 : ℝ) ≠ 0)]
-- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.
obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') :=
cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this
have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * (1 / 2) ^ e := by
intro e p hp
apply le_of_tendsto (tendsto_const_nhds.sub hf').norm
rw [eventually_atTop]
exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩
-- Let us show that `f` has right derivative `f'` at `x`.
have : HasDerivWithinAt f f' (Ici x) x := by
simp only [hasDerivWithinAt_iff_isLittleO, isLittleO_iff]
/- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for
some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,
this makes it possible to cover all scales, and thus to obtain a good linear approximation in
the whole interval of length `(1/2)^(n e)`. -/
intro ε εpos
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 16 :=
exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num)
filter_upwards [Icc_mem_nhdsGE <| show x < x + (1 / 2) ^ (n e + 1) by simp] with y hy
-- We need to show that `f y - f x - f' (y - x)` is small. For this, we will work at scale
-- `k` where `k` is chosen with `‖y - x‖ ∼ 2 ^ (-k)`.
rcases eq_or_lt_of_le hy.1 with (rfl | xy)
· simp only [sub_self, zero_smul, norm_zero, mul_zero, le_rfl]
have yzero : 0 < y - x := sub_pos.2 xy
have y_le : y - x ≤ (1 / 2) ^ (n e + 1) := by linarith [hy.2]
have yone : y - x ≤ 1 := le_trans y_le (pow_le_one₀ (by norm_num) (by norm_num))
-- define the scale `k`.
obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < y - x ∧ y - x ≤ (1 / 2) ^ k :=
exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2)
(by norm_num : (1 : ℝ) / 2 < 1)
-- the scale is large enough (as `y - x` is small enough)
have k_gt : n e < k := by
have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_of_lt_of_le hk y_le
rw [pow_lt_pow_iff_right_of_lt_one₀ (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this
omega
set m := k - 1
have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt
have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm
rw [km] at hk h'k
-- `f` is well approximated by `L e (n e) k` at the relevant scale
-- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).
have J : ‖f y - f x - (y - x) • L e (n e) m‖ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ :=
calc
‖f y - f x - (y - x) • L e (n e) m‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by
apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2
· simp only [one_div, inv_pow, left_mem_Icc, le_add_iff_nonneg_right]
positivity
· simp only [pow_add, tsub_le_iff_left] at h'k
simpa only [hy.1, mem_Icc, true_and, one_div, pow_one] using h'k
_ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring
_ ≤ 4 * (1 / 2) ^ e * (y - x) := by gcongr
_ = 4 * (1 / 2) ^ e * ‖y - x‖ := by rw [Real.norm_of_nonneg yzero.le]
calc
‖f y - f x - (y - x) • f'‖ =
‖f y - f x - (y - x) • L e (n e) m + (y - x) • (L e (n e) m - f')‖ := by
simp only [smul_sub, sub_add_sub_cancel]
_ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ + ‖y - x‖ * (12 * (1 / 2) ^ e) :=
norm_add_le_of_le J <| by rw [norm_smul]; gcongr; exact Lf' _ _ m_ge
_ = 16 * ‖y - x‖ * (1 / 2) ^ e := by ring
_ ≤ 16 * ‖y - x‖ * (ε / 16) := by gcongr
_ = ε * ‖y - x‖ := by ring
rw [← this.derivWithin (uniqueDiffOn_Ici x x Set.left_mem_Ici)] at f'K
exact ⟨this.differentiableWithinAt, f'K⟩
theorem differentiable_set_eq_D (hK : IsComplete K) :
{ x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } = D f K :=
Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)
end RightDerivMeasurableAux
open RightDerivMeasurableAux
variable (f)
/-- The set of right differentiability points of a function, with derivative in a given complete
set, is Borel-measurable. -/
theorem measurableSet_of_differentiableWithinAt_Ici_of_isComplete {K : Set F} (hK : IsComplete K) :
MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by
-- simp [differentiable_set_eq_d K hK, D, measurableSet_b, MeasurableSet.iInter,
-- MeasurableSet.iUnion]
simp only [differentiable_set_eq_D K hK, D]
repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro
exact measurableSet_B
variable [CompleteSpace F]
/-- The set of right differentiability points of a function taking values in a complete space is
Borel-measurable. -/
theorem measurableSet_of_differentiableWithinAt_Ici :
MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x } := by
have : IsComplete (univ : Set F) := complete_univ
convert measurableSet_of_differentiableWithinAt_Ici_of_isComplete f this
simp
@[measurability, fun_prop]
theorem measurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] :
Measurable fun x => derivWithin f (Ici x) x := by
refine measurable_of_isClosed fun s hs => ?_
have :
(fun x => derivWithin f (Ici x) x) ⁻¹' s =
{ x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ s } ∪
{ x | ¬DifferentiableWithinAt ℝ f (Ici x) x } ∩ { _x | (0 : F) ∈ s } :=
Set.ext fun x => mem_preimage.trans derivWithin_mem_iff
rw [this]
exact
(measurableSet_of_differentiableWithinAt_Ici_of_isComplete _ hs.isComplete).union
((measurableSet_of_differentiableWithinAt_Ici _).compl.inter (MeasurableSet.const _))
theorem stronglyMeasurable_derivWithin_Ici :
StronglyMeasurable (fun x ↦ derivWithin f (Ici x) x) := by
borelize F
apply stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_derivWithin_Ici f, ?_⟩
obtain ⟨t, t_count, ht⟩ : ∃ t : Set ℝ, t.Countable ∧ Dense t := exists_countable_dense ℝ
suffices H : range (fun x ↦ derivWithin f (Ici x) x) ⊆ closure (Submodule.span ℝ (f '' t)) from
IsSeparable.mono (t_count.image f).isSeparable.span.closure H
rintro - ⟨x, rfl⟩
suffices H' : range (fun y ↦ derivWithin f (Ici x) y) ⊆ closure (Submodule.span ℝ (f '' t)) from
H' (mem_range_self _)
apply range_derivWithin_subset_closure_span_image
calc Ici x
= closure (Ioi x ∩ closure t) := by simp [dense_iff_closure_eq.1 ht]
_ ⊆ closure (closure (Ioi x ∩ t)) := by
apply closure_mono
simpa [inter_comm] using (isOpen_Ioi (a := x)).closure_inter (s := t)
_ ⊆ closure (Ici x ∩ t) := by
rw [closure_closure]
exact closure_mono (inter_subset_inter_left _ Ioi_subset_Ici_self)
theorem aemeasurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) :
AEMeasurable (fun x => derivWithin f (Ici x) x) μ :=
(measurable_derivWithin_Ici f).aemeasurable
theorem aestronglyMeasurable_derivWithin_Ici (μ : Measure ℝ) :
AEStronglyMeasurable (fun x => derivWithin f (Ici x) x) μ :=
(stronglyMeasurable_derivWithin_Ici f).aestronglyMeasurable
/-- The set of right differentiability points of a function taking values in a complete space is
Borel-measurable. -/
| Mathlib/Analysis/Calculus/FDeriv/Measurable.lean | 751 | 762 | theorem measurableSet_of_differentiableWithinAt_Ioi :
MeasurableSet { x | DifferentiableWithinAt ℝ f (Ioi x) x } := by | simpa [differentiableWithinAt_Ioi_iff_Ici] using measurableSet_of_differentiableWithinAt_Ici f
@[measurability, fun_prop]
theorem measurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] :
Measurable fun x => derivWithin f (Ioi x) x := by
simpa [derivWithin_Ioi_eq_Ici] using measurable_derivWithin_Ici f
theorem stronglyMeasurable_derivWithin_Ioi :
StronglyMeasurable (fun x ↦ derivWithin f (Ioi x) x) := by
simpa [derivWithin_Ioi_eq_Ici] using stronglyMeasurable_derivWithin_Ici f |
/-
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.Measure.Decomposition.RadonNikodym
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
import Mathlib.Probability.Independence.Basic
/-!
# Probability density function
This file defines the probability density function of random variables, by which we mean
measurable functions taking values in a Borel space. The probability density function is defined
as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f`
is said to the probability density function of a random variable `X` if for all measurable
sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing
the distribution of a random variable, and are useful for calculating probabilities and
finding moments (although the latter is better achieved with moment generating functions).
This file also defines the continuous uniform distribution and proves some properties about
random variables with this distribution.
## Main definitions
* `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with
respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X`
is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`.
* `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X`
is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`.
* `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform
distribution if it has a constant probability density function with a compact, non-null support.
## Main results
* `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician,
i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for
all measurable `g : E → F`.
* `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with
pdf `f` has expectation `∫ x, x * f x dx`.
* `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with
its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ`
is the Lebesgue measure.
## TODO
Ultimately, we would also like to define characteristic functions to describe distributions as
it exists for all random variables. However, to define this, we will need Fourier transforms
which we currently do not have.
-/
open scoped MeasureTheory NNReal ENNReal
open TopologicalSpace MeasureTheory.Measure
noncomputable section
namespace MeasureTheory
variable {Ω E : Type*} [MeasurableSpace E]
/-- A random variable `X : Ω → E` is said to have a probability density function (`HasPDF`)
with respect to the measure `ℙ` on `Ω` and `μ` on `E`
if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ`
and they have a Lebesgue decomposition (`HaveLebesgueDecomposition`). -/
class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :
Prop where
protected aemeasurable' : AEMeasurable X ℙ
protected haveLebesgueDecomposition' : (map X ℙ).HaveLebesgueDecomposition μ
protected absolutelyContinuous' : map X ℙ ≪ μ
section HasPDF
variable {_ : MeasurableSpace Ω} {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E}
theorem hasPDF_iff :
HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ :=
⟨fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩, fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩⟩
theorem hasPDF_iff_of_aemeasurable (hX : AEMeasurable X ℙ) :
HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by
rw [hasPDF_iff]
simp only [hX, true_and]
variable (X ℙ μ) in
@[measurability]
theorem HasPDF.aemeasurable [HasPDF X ℙ μ] : AEMeasurable X ℙ := HasPDF.aemeasurable' μ
instance HasPDF.haveLebesgueDecomposition [HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ :=
HasPDF.haveLebesgueDecomposition'
theorem HasPDF.absolutelyContinuous [HasPDF X ℙ μ] : map X ℙ ≪ μ := HasPDF.absolutelyContinuous'
/-- A random variable that `HasPDF` is quasi-measure preserving. -/
theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E)
[HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ :=
{ measurable := h
absolutelyContinuous := HasPDF.absolutelyContinuous .. }
theorem HasPDF.congr (hXY : X =ᵐ[ℙ] Y) [hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ :=
⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition,
ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩
theorem HasPDF.congr_iff (hXY : X =ᵐ[ℙ] Y) : HasPDF X ℙ μ ↔ HasPDF Y ℙ μ :=
⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩
@[deprecated (since := "2024-10-28")] alias HasPDF.congr' := HasPDF.congr_iff
/-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/
theorem hasPDF_of_map_eq_withDensity (hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ)
(h : map X ℙ = μ.withDensity f) : HasPDF X ℙ μ := by
refine ⟨hX, ?_, ?_⟩ <;> rw [h]
· rw [withDensity_congr_ae hf.ae_eq_mk]
exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk
· exact withDensity_absolutelyContinuous μ f
end HasPDF
/-- If `X` is a random variable, then `pdf X ℙ μ`
is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. -/
def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :
E → ℝ≥0∞ :=
(map X ℙ).rnDeriv μ
theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} :
pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl
theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
{X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by
rw [pdf_def, map_of_not_aemeasurable hX]
exact rnDeriv_zero μ
theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
{μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 :=
rnDeriv_of_not_haveLebesgueDecomposition h
theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
(X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by
contrapose! h
exact pdf_of_not_aemeasurable h
theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E}
(hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by
refine ⟨?_, ?_, hac⟩
· exact aemeasurable_of_pdf_ne_zero X hpdf
· contrapose! hpdf
have := pdf_of_not_haveLebesgueDecomposition hpdf
filter_upwards using congrFun this
@[measurability]
theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by
exact measurable_rnDeriv _ _
theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ :=
withDensity_rnDeriv_le _ _
theorem setLIntegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) (s : Set E) :
∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by
apply (withDensity_apply_le _ s).trans
exact withDensity_pdf_le_map _ _ _ s
theorem map_eq_withDensity_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] :
map X ℙ = μ.withDensity (pdf X ℙ μ) := by
rw [pdf_def, withDensity_rnDeriv_eq _ _ hX.absolutelyContinuous]
theorem map_eq_setLIntegral_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] {s : Set E}
(hs : MeasurableSet s) : map X ℙ s = ∫⁻ x in s, pdf X ℙ μ x ∂μ := by
rw [← withDensity_apply _ hs, map_eq_withDensity_pdf X ℙ μ]
namespace pdf
variable {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
protected theorem congr {X Y : Ω → E} (hXY : X =ᵐ[ℙ] Y) : pdf X ℙ μ = pdf Y ℙ μ := by
rw [pdf_def, pdf_def, map_congr hXY]
theorem lintegral_eq_measure_univ {X : Ω → E} [HasPDF X ℙ μ] :
∫⁻ x, pdf X ℙ μ x ∂μ = ℙ Set.univ := by
rw [← setLIntegral_univ, ← map_eq_setLIntegral_pdf X ℙ μ MeasurableSet.univ,
map_apply_of_aemeasurable (HasPDF.aemeasurable X ℙ μ) MeasurableSet.univ, Set.preimage_univ]
theorem eq_of_map_eq_withDensity [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := by
rw [map_eq_withDensity_pdf X ℙ μ]
apply withDensity_eq_iff (measurable_pdf X ℙ μ).aemeasurable hmf
rw [lintegral_eq_measure_univ]
exact measure_ne_top _ _
theorem eq_of_map_eq_withDensity' [SigmaFinite μ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f :=
map_eq_withDensity_pdf X ℙ μ ▸
withDensity_eq_iff_of_sigmaFinite (measurable_pdf X ℙ μ).aemeasurable hmf
nonrec theorem ae_lt_top [IsFiniteMeasure ℙ] {μ : Measure E} {X : Ω → E} :
∀ᵐ x ∂μ, pdf X ℙ μ x < ∞ :=
rnDeriv_lt_top (map X ℙ) μ
nonrec theorem ofReal_toReal_ae_eq [IsFiniteMeasure ℙ] {X : Ω → E} :
(fun x => ENNReal.ofReal (pdf X ℙ μ x).toReal) =ᵐ[μ] pdf X ℙ μ :=
ofReal_toReal_ae_eq ae_lt_top
section IntegralPDFMul
/-- **The Law of the Unconscious Statistician** for nonnegative random variables. -/
theorem lintegral_pdf_mul {X : Ω → E} [HasPDF X ℙ μ] {f : E → ℝ≥0∞}
(hf : AEMeasurable f μ) : ∫⁻ x, pdf X ℙ μ x * f x ∂μ = ∫⁻ x, f (X x) ∂ℙ := by
rw [pdf_def,
← lintegral_map' (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ),
lintegral_rnDeriv_mul HasPDF.absolutelyContinuous hf]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
theorem integrable_pdf_smul_iff [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) :
Integrable (fun x => (pdf X ℙ μ x).toReal • f x) μ ↔ Integrable (fun x => f (X x)) ℙ := by
rw [← Function.comp_def,
← integrable_map_measure (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integrable_rnDeriv_smul_iff HasPDF.absolutelyContinuous]
rw [withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
/-- **The Law of the Unconscious Statistician**: Given a random variable `X` and a measurable
function `f`, `f ∘ X` is a random variable with expectation `∫ x, pdf X x • f x ∂μ`
where `μ` is a measure on the codomain of `X`. -/
theorem integral_pdf_smul [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) : ∫ x, (pdf X ℙ μ x).toReal • f x ∂μ = ∫ x, f (X x) ∂ℙ := by
rw [← integral_map (HasPDF.aemeasurable X ℙ μ) (hf.mono_ac HasPDF.absolutelyContinuous),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integral_rnDeriv_smul HasPDF.absolutelyContinuous,
withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
end IntegralPDFMul
section
variable {F : Type*} [MeasurableSpace F] {ν : Measure F} (X : Ω → E) [HasPDF X ℙ μ] {g : E → F}
/-- A random variable that `HasPDF` transformed under a `QuasiMeasurePreserving`
map also `HasPDF` if `(map g (map X ℙ)).HaveLebesgueDecomposition μ`.
`quasiMeasurePreserving_hasPDF` is more useful in the case we are working with a
probability measure and a real-valued random variable. -/
| Mathlib/Probability/Density.lean | 247 | 255 | theorem quasiMeasurePreserving_hasPDF (hg : QuasiMeasurePreserving g μ ν)
(hmap : (map g (map X ℙ)).HaveLebesgueDecomposition ν) : HasPDF (g ∘ X) ℙ ν := by | have hgm : AEMeasurable g (map X ℙ) := hg.aemeasurable.mono_ac HasPDF.absolutelyContinuous
rw [hasPDF_iff, ← AEMeasurable.map_map_of_aemeasurable hgm (HasPDF.aemeasurable X ℙ μ)]
refine ⟨hg.measurable.comp_aemeasurable (HasPDF.aemeasurable _ _ μ), hmap, ?_⟩
exact (HasPDF.absolutelyContinuous.map hg.1).trans hg.2
theorem quasiMeasurePreserving_hasPDF' [SFinite ℙ] [SigmaFinite ν]
(hg : QuasiMeasurePreserving g μ ν) : HasPDF (g ∘ X) ℙ ν := |
/-
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, Violeta Hernández Palacios, Grayson Burton, Floris van Doorn
-/
import Mathlib.Order.Antisymmetrization
import Mathlib.Order.Hom.WithTopBot
import Mathlib.Order.Interval.Set.OrdConnected
import Mathlib.Order.Interval.Set.WithBotTop
/-!
# The covering relation
This file proves properties of the covering relation in an order.
We say that `b` *covers* `a` if `a < b` and there is no element in between.
We say that `b` *weakly covers* `a` if `a ≤ b` and there is no element between `a` and `b`.
In a partial order this is equivalent to `a ⋖ b ∨ a = b`,
in a preorder this is equivalent to `a ⋖ b ∨ (a ≤ b ∧ b ≤ a)`
## Notation
* `a ⋖ b` means that `b` covers `a`.
* `a ⩿ b` means that `b` weakly covers `a`.
-/
open Set OrderDual
variable {α β : Type*}
section WeaklyCovers
section Preorder
variable [Preorder α] [Preorder β] {a b c : α}
theorem WCovBy.le (h : a ⩿ b) : a ≤ b :=
h.1
theorem WCovBy.refl (a : α) : a ⩿ a :=
⟨le_rfl, fun _ hc => hc.not_lt⟩
@[simp] lemma WCovBy.rfl : a ⩿ a := WCovBy.refl a
protected theorem Eq.wcovBy (h : a = b) : a ⩿ b :=
h ▸ WCovBy.rfl
theorem wcovBy_of_le_of_le (h1 : a ≤ b) (h2 : b ≤ a) : a ⩿ b :=
⟨h1, fun _ hac hcb => (hac.trans hcb).not_le h2⟩
alias LE.le.wcovBy_of_le := wcovBy_of_le_of_le
theorem AntisymmRel.wcovBy (h : AntisymmRel (· ≤ ·) a b) : a ⩿ b :=
wcovBy_of_le_of_le h.1 h.2
theorem WCovBy.wcovBy_iff_le (hab : a ⩿ b) : b ⩿ a ↔ b ≤ a :=
⟨fun h => h.le, fun h => h.wcovBy_of_le hab.le⟩
theorem wcovBy_of_eq_or_eq (hab : a ≤ b) (h : ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b) : a ⩿ b :=
⟨hab, fun c ha hb => (h c ha.le hb.le).elim ha.ne' hb.ne⟩
theorem AntisymmRel.trans_wcovBy (hab : AntisymmRel (· ≤ ·) a b) (hbc : b ⩿ c) : a ⩿ c :=
⟨hab.1.trans hbc.le, fun _ had hdc => hbc.2 (hab.2.trans_lt had) hdc⟩
theorem wcovBy_congr_left (hab : AntisymmRel (· ≤ ·) a b) : a ⩿ c ↔ b ⩿ c :=
⟨hab.symm.trans_wcovBy, hab.trans_wcovBy⟩
theorem WCovBy.trans_antisymm_rel (hab : a ⩿ b) (hbc : AntisymmRel (· ≤ ·) b c) : a ⩿ c :=
⟨hab.le.trans hbc.1, fun _ had hdc => hab.2 had <| hdc.trans_le hbc.2⟩
theorem wcovBy_congr_right (hab : AntisymmRel (· ≤ ·) a b) : c ⩿ a ↔ c ⩿ b :=
⟨fun h => h.trans_antisymm_rel hab, fun h => h.trans_antisymm_rel hab.symm⟩
/-- If `a ≤ b`, then `b` does not cover `a` iff there's an element in between. -/
theorem not_wcovBy_iff (h : a ≤ b) : ¬a ⩿ b ↔ ∃ c, a < c ∧ c < b := by
simp_rw [WCovBy, h, true_and, not_forall, exists_prop, not_not]
instance WCovBy.isRefl : IsRefl α (· ⩿ ·) :=
⟨WCovBy.refl⟩
theorem WCovBy.Ioo_eq (h : a ⩿ b) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ hx => h.2 hx.1 hx.2
theorem wcovBy_iff_Ioo_eq : a ⩿ b ↔ a ≤ b ∧ Ioo a b = ∅ :=
and_congr_right' <| by simp [eq_empty_iff_forall_not_mem]
lemma WCovBy.of_le_of_le (hac : a ⩿ c) (hab : a ≤ b) (hbc : b ≤ c) : b ⩿ c :=
⟨hbc, fun _x hbx hxc ↦ hac.2 (hab.trans_lt hbx) hxc⟩
lemma WCovBy.of_le_of_le' (hac : a ⩿ c) (hab : a ≤ b) (hbc : b ≤ c) : a ⩿ b :=
⟨hab, fun _x hax hxb ↦ hac.2 hax <| hxb.trans_le hbc⟩
theorem WCovBy.of_image (f : α ↪o β) (h : f a ⩿ f b) : a ⩿ b :=
⟨f.le_iff_le.mp h.le, fun _ hac hcb => h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩
theorem WCovBy.image (f : α ↪o β) (hab : a ⩿ b) (h : (range f).OrdConnected) : f a ⩿ f b := by
refine ⟨f.monotone hab.le, fun c ha hb => ?_⟩
obtain ⟨c, rfl⟩ := h.out (mem_range_self _) (mem_range_self _) ⟨ha.le, hb.le⟩
rw [f.lt_iff_lt] at ha hb
exact hab.2 ha hb
theorem Set.OrdConnected.apply_wcovBy_apply_iff (f : α ↪o β) (h : (range f).OrdConnected) :
f a ⩿ f b ↔ a ⩿ b :=
⟨fun h2 => h2.of_image f, fun hab => hab.image f h⟩
@[simp]
theorem apply_wcovBy_apply_iff {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) :
e a ⩿ e b ↔ a ⩿ b :=
(ordConnected_range (e : α ≃o β)).apply_wcovBy_apply_iff ((e : α ≃o β) : α ↪o β)
@[simp]
theorem toDual_wcovBy_toDual_iff : toDual b ⩿ toDual a ↔ a ⩿ b :=
and_congr_right' <| forall_congr' fun _ => forall_swap
@[simp]
theorem ofDual_wcovBy_ofDual_iff {a b : αᵒᵈ} : ofDual a ⩿ ofDual b ↔ b ⩿ a :=
and_congr_right' <| forall_congr' fun _ => forall_swap
alias ⟨_, WCovBy.toDual⟩ := toDual_wcovBy_toDual_iff
alias ⟨_, WCovBy.ofDual⟩ := ofDual_wcovBy_ofDual_iff
theorem OrderEmbedding.wcovBy_of_apply {α β : Type*} [Preorder α] [Preorder β]
(f : α ↪o β) {x y : α} (h : f x ⩿ f y) : x ⩿ y := by
use f.le_iff_le.1 h.1
intro a
rw [← f.lt_iff_lt, ← f.lt_iff_lt]
apply h.2
theorem OrderIso.map_wcovBy {α β : Type*} [Preorder α] [Preorder β]
(f : α ≃o β) {x y : α} : f x ⩿ f y ↔ x ⩿ y := by
use f.toOrderEmbedding.wcovBy_of_apply
conv_lhs => rw [← f.symm_apply_apply x, ← f.symm_apply_apply y]
exact f.symm.toOrderEmbedding.wcovBy_of_apply
end Preorder
section PartialOrder
variable [PartialOrder α] {a b c : α}
theorem WCovBy.eq_or_eq (h : a ⩿ b) (h2 : a ≤ c) (h3 : c ≤ b) : c = a ∨ c = b := by
rcases h2.eq_or_lt with (h2 | h2); · exact Or.inl h2.symm
rcases h3.eq_or_lt with (h3 | h3); · exact Or.inr h3
exact (h.2 h2 h3).elim
/-- An `iff` version of `WCovBy.eq_or_eq` and `wcovBy_of_eq_or_eq`. -/
theorem wcovBy_iff_le_and_eq_or_eq : a ⩿ b ↔ a ≤ b ∧ ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b :=
⟨fun h => ⟨h.le, fun _ => h.eq_or_eq⟩, And.rec wcovBy_of_eq_or_eq⟩
theorem WCovBy.le_and_le_iff (h : a ⩿ b) : a ≤ c ∧ c ≤ b ↔ c = a ∨ c = b := by
refine ⟨fun h2 => h.eq_or_eq h2.1 h2.2, ?_⟩; rintro (rfl | rfl)
exacts [⟨le_rfl, h.le⟩, ⟨h.le, le_rfl⟩]
theorem WCovBy.Icc_eq (h : a ⩿ b) : Icc a b = {a, b} := by
ext c
exact h.le_and_le_iff
theorem WCovBy.Ico_subset (h : a ⩿ b) : Ico a b ⊆ {a} := by
rw [← Icc_diff_right, h.Icc_eq, diff_singleton_subset_iff, pair_comm]
theorem WCovBy.Ioc_subset (h : a ⩿ b) : Ioc a b ⊆ {b} := by
rw [← Icc_diff_left, h.Icc_eq, diff_singleton_subset_iff]
end PartialOrder
section SemilatticeSup
variable [SemilatticeSup α] {a b c : α}
theorem WCovBy.sup_eq (hac : a ⩿ c) (hbc : b ⩿ c) (hab : a ≠ b) : a ⊔ b = c :=
(sup_le hac.le hbc.le).eq_of_not_lt fun h =>
hab.lt_sup_or_lt_sup.elim (fun h' => hac.2 h' h) fun h' => hbc.2 h' h
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] {a b c : α}
theorem WCovBy.inf_eq (hca : c ⩿ a) (hcb : c ⩿ b) (hab : a ≠ b) : a ⊓ b = c :=
(le_inf hca.le hcb.le).eq_of_not_gt fun h => hab.inf_lt_or_inf_lt.elim (hca.2 h) (hcb.2 h)
end SemilatticeInf
end WeaklyCovers
section LT
variable [LT α] {a b : α}
theorem CovBy.lt (h : a ⋖ b) : a < b :=
h.1
/-- If `a < b`, then `b` does not cover `a` iff there's an element in between. -/
theorem not_covBy_iff (h : a < b) : ¬a ⋖ b ↔ ∃ c, a < c ∧ c < b := by
simp_rw [CovBy, h, true_and, not_forall, exists_prop, not_not]
alias ⟨exists_lt_lt_of_not_covBy, _⟩ := not_covBy_iff
alias LT.lt.exists_lt_lt := exists_lt_lt_of_not_covBy
/-- In a dense order, nothing covers anything. -/
theorem not_covBy [DenselyOrdered α] : ¬a ⋖ b := fun h =>
let ⟨_, hc⟩ := exists_between h.1
h.2 hc.1 hc.2
theorem denselyOrdered_iff_forall_not_covBy : DenselyOrdered α ↔ ∀ a b : α, ¬a ⋖ b :=
⟨fun h _ _ => @not_covBy _ _ _ _ h, fun h =>
⟨fun _ _ hab => exists_lt_lt_of_not_covBy hab <| h _ _⟩⟩
@[simp]
theorem toDual_covBy_toDual_iff : toDual b ⋖ toDual a ↔ a ⋖ b :=
and_congr_right' <| forall_congr' fun _ => forall_swap
@[simp]
theorem ofDual_covBy_ofDual_iff {a b : αᵒᵈ} : ofDual a ⋖ ofDual b ↔ b ⋖ a :=
and_congr_right' <| forall_congr' fun _ => forall_swap
alias ⟨_, CovBy.toDual⟩ := toDual_covBy_toDual_iff
alias ⟨_, CovBy.ofDual⟩ := ofDual_covBy_ofDual_iff
end LT
section Preorder
variable [Preorder α] [Preorder β] {a b c : α}
theorem CovBy.le (h : a ⋖ b) : a ≤ b :=
h.1.le
protected theorem CovBy.ne (h : a ⋖ b) : a ≠ b :=
h.lt.ne
theorem CovBy.ne' (h : a ⋖ b) : b ≠ a :=
h.lt.ne'
protected theorem CovBy.wcovBy (h : a ⋖ b) : a ⩿ b :=
⟨h.le, h.2⟩
theorem WCovBy.covBy_of_not_le (h : a ⩿ b) (h2 : ¬b ≤ a) : a ⋖ b :=
⟨h.le.lt_of_not_le h2, h.2⟩
theorem WCovBy.covBy_of_lt (h : a ⩿ b) (h2 : a < b) : a ⋖ b :=
⟨h2, h.2⟩
lemma CovBy.of_le_of_lt (hac : a ⋖ c) (hab : a ≤ b) (hbc : b < c) : b ⋖ c :=
⟨hbc, fun _x hbx hxc ↦ hac.2 (hab.trans_lt hbx) hxc⟩
lemma CovBy.of_lt_of_le (hac : a ⋖ c) (hab : a < b) (hbc : b ≤ c) : a ⋖ b :=
⟨hab, fun _x hax hxb ↦ hac.2 hax <| hxb.trans_le hbc⟩
theorem not_covBy_of_lt_of_lt (h₁ : a < b) (h₂ : b < c) : ¬a ⋖ c :=
(not_covBy_iff (h₁.trans h₂)).2 ⟨b, h₁, h₂⟩
theorem covBy_iff_wcovBy_and_lt : a ⋖ b ↔ a ⩿ b ∧ a < b :=
⟨fun h => ⟨h.wcovBy, h.lt⟩, fun h => h.1.covBy_of_lt h.2⟩
theorem covBy_iff_wcovBy_and_not_le : a ⋖ b ↔ a ⩿ b ∧ ¬b ≤ a :=
⟨fun h => ⟨h.wcovBy, h.lt.not_le⟩, fun h => h.1.covBy_of_not_le h.2⟩
theorem wcovBy_iff_covBy_or_le_and_le : a ⩿ b ↔ a ⋖ b ∨ a ≤ b ∧ b ≤ a :=
⟨fun h => or_iff_not_imp_right.mpr fun h' => h.covBy_of_not_le fun hba => h' ⟨h.le, hba⟩,
fun h' => h'.elim (fun h => h.wcovBy) fun h => h.1.wcovBy_of_le h.2⟩
alias ⟨WCovBy.covBy_or_le_and_le, _⟩ := wcovBy_iff_covBy_or_le_and_le
theorem AntisymmRel.trans_covBy (hab : AntisymmRel (· ≤ ·) a b) (hbc : b ⋖ c) : a ⋖ c :=
⟨hab.1.trans_lt hbc.lt, fun _ had hdc => hbc.2 (hab.2.trans_lt had) hdc⟩
theorem covBy_congr_left (hab : AntisymmRel (· ≤ ·) a b) : a ⋖ c ↔ b ⋖ c :=
⟨hab.symm.trans_covBy, hab.trans_covBy⟩
theorem CovBy.trans_antisymmRel (hab : a ⋖ b) (hbc : AntisymmRel (· ≤ ·) b c) : a ⋖ c :=
⟨hab.lt.trans_le hbc.1, fun _ had hdb => hab.2 had <| hdb.trans_le hbc.2⟩
theorem covBy_congr_right (hab : AntisymmRel (· ≤ ·) a b) : c ⋖ a ↔ c ⋖ b :=
⟨fun h => h.trans_antisymmRel hab, fun h => h.trans_antisymmRel hab.symm⟩
instance : IsNonstrictStrictOrder α (· ⩿ ·) (· ⋖ ·) :=
⟨fun _ _ =>
covBy_iff_wcovBy_and_not_le.trans <| and_congr_right fun h => h.wcovBy_iff_le.not.symm⟩
instance CovBy.isIrrefl : IsIrrefl α (· ⋖ ·) :=
⟨fun _ ha => ha.ne rfl⟩
theorem CovBy.Ioo_eq (h : a ⋖ b) : Ioo a b = ∅ :=
h.wcovBy.Ioo_eq
theorem covBy_iff_Ioo_eq : a ⋖ b ↔ a < b ∧ Ioo a b = ∅ :=
and_congr_right' <| by simp [eq_empty_iff_forall_not_mem]
theorem CovBy.of_image (f : α ↪o β) (h : f a ⋖ f b) : a ⋖ b :=
⟨f.lt_iff_lt.mp h.lt, fun _ hac hcb => h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩
theorem CovBy.image (f : α ↪o β) (hab : a ⋖ b) (h : (range f).OrdConnected) : f a ⋖ f b :=
(hab.wcovBy.image f h).covBy_of_lt <| f.strictMono hab.lt
theorem Set.OrdConnected.apply_covBy_apply_iff (f : α ↪o β) (h : (range f).OrdConnected) :
f a ⋖ f b ↔ a ⋖ b :=
⟨CovBy.of_image f, fun hab => hab.image f h⟩
@[simp]
theorem apply_covBy_apply_iff {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) :
e a ⋖ e b ↔ a ⋖ b :=
(ordConnected_range (e : α ≃o β)).apply_covBy_apply_iff ((e : α ≃o β) : α ↪o β)
theorem covBy_of_eq_or_eq (hab : a < b) (h : ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b) : a ⋖ b :=
⟨hab, fun c ha hb => (h c ha.le hb.le).elim ha.ne' hb.ne⟩
theorem OrderEmbedding.covBy_of_apply {α β : Type*} [Preorder α] [Preorder β]
(f : α ↪o β) {x y : α} (h : f x ⋖ f y) : x ⋖ y := by
use f.lt_iff_lt.1 h.1
intro a
rw [← f.lt_iff_lt, ← f.lt_iff_lt]
apply h.2
theorem OrderIso.map_covBy {α β : Type*} [Preorder α] [Preorder β]
(f : α ≃o β) {x y : α} : f x ⋖ f y ↔ x ⋖ y := by
use f.toOrderEmbedding.covBy_of_apply
conv_lhs => rw [← f.symm_apply_apply x, ← f.symm_apply_apply y]
exact f.symm.toOrderEmbedding.covBy_of_apply
end Preorder
section PartialOrder
variable [PartialOrder α] {a b c : α}
theorem WCovBy.covBy_of_ne (h : a ⩿ b) (h2 : a ≠ b) : a ⋖ b :=
⟨h.le.lt_of_ne h2, h.2⟩
theorem covBy_iff_wcovBy_and_ne : a ⋖ b ↔ a ⩿ b ∧ a ≠ b :=
⟨fun h => ⟨h.wcovBy, h.ne⟩, fun h => h.1.covBy_of_ne h.2⟩
theorem wcovBy_iff_covBy_or_eq : a ⩿ b ↔ a ⋖ b ∨ a = b := by
rw [le_antisymm_iff, wcovBy_iff_covBy_or_le_and_le]
theorem wcovBy_iff_eq_or_covBy : a ⩿ b ↔ a = b ∨ a ⋖ b :=
wcovBy_iff_covBy_or_eq.trans or_comm
alias ⟨WCovBy.covBy_or_eq, _⟩ := wcovBy_iff_covBy_or_eq
alias ⟨WCovBy.eq_or_covBy, _⟩ := wcovBy_iff_eq_or_covBy
theorem CovBy.eq_or_eq (h : a ⋖ b) (h2 : a ≤ c) (h3 : c ≤ b) : c = a ∨ c = b :=
h.wcovBy.eq_or_eq h2 h3
/-- An `iff` version of `CovBy.eq_or_eq` and `covBy_of_eq_or_eq`. -/
theorem covBy_iff_lt_and_eq_or_eq : a ⋖ b ↔ a < b ∧ ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b :=
⟨fun h => ⟨h.lt, fun _ => h.eq_or_eq⟩, And.rec covBy_of_eq_or_eq⟩
theorem CovBy.Ico_eq (h : a ⋖ b) : Ico a b = {a} := by
rw [← Ioo_union_left h.lt, h.Ioo_eq, empty_union]
theorem CovBy.Ioc_eq (h : a ⋖ b) : Ioc a b = {b} := by
rw [← Ioo_union_right h.lt, h.Ioo_eq, empty_union]
theorem CovBy.Icc_eq (h : a ⋖ b) : Icc a b = {a, b} :=
h.wcovBy.Icc_eq
end PartialOrder
section LinearOrder
variable [LinearOrder α] {a b c : α}
theorem CovBy.Ioi_eq (h : a ⋖ b) : Ioi a = Ici b := by
rw [← Ioo_union_Ici_eq_Ioi h.lt, h.Ioo_eq, empty_union]
theorem CovBy.Iio_eq (h : a ⋖ b) : Iio b = Iic a := by
rw [← Iic_union_Ioo_eq_Iio h.lt, h.Ioo_eq, union_empty]
theorem WCovBy.le_of_lt (hab : a ⩿ b) (hcb : c < b) : c ≤ a :=
not_lt.1 fun hac => hab.2 hac hcb
theorem WCovBy.ge_of_gt (hab : a ⩿ b) (hac : a < c) : b ≤ c :=
not_lt.1 <| hab.2 hac
theorem CovBy.le_of_lt (hab : a ⋖ b) : c < b → c ≤ a :=
hab.wcovBy.le_of_lt
theorem CovBy.ge_of_gt (hab : a ⋖ b) : a < c → b ≤ c :=
hab.wcovBy.ge_of_gt
theorem CovBy.unique_left (ha : a ⋖ c) (hb : b ⋖ c) : a = b :=
(hb.le_of_lt ha.lt).antisymm <| ha.le_of_lt hb.lt
theorem CovBy.unique_right (hb : a ⋖ b) (hc : a ⋖ c) : b = c :=
(hb.ge_of_gt hc.lt).antisymm <| hc.ge_of_gt hb.lt
/-- If `a`, `b`, `c` are consecutive and `a < x < c` then `x = b`. -/
theorem CovBy.eq_of_between {x : α} (hab : a ⋖ b) (hbc : b ⋖ c) (hax : a < x) (hxc : x < c) :
x = b :=
le_antisymm (le_of_not_lt fun h => hbc.2 h hxc) (le_of_not_lt <| hab.2 hax)
theorem covBy_iff_lt_iff_le_left {x y : α} : x ⋖ y ↔ ∀ {z}, z < y ↔ z ≤ x where
mp := fun hx _z ↦ ⟨hx.le_of_lt, fun hz ↦ hz.trans_lt hx.lt⟩
mpr := fun H ↦ ⟨H.2 le_rfl, fun _z hx hz ↦ (H.1 hz).not_lt hx⟩
theorem covBy_iff_le_iff_lt_left {x y : α} : x ⋖ y ↔ ∀ {z}, z ≤ x ↔ z < y := by
simp_rw [covBy_iff_lt_iff_le_left, iff_comm]
theorem covBy_iff_lt_iff_le_right {x y : α} : x ⋖ y ↔ ∀ {z}, x < z ↔ y ≤ z := by
trans ∀ {z}, ¬ z ≤ x ↔ ¬ z < y
· simp_rw [covBy_iff_le_iff_lt_left, not_iff_not]
· simp
theorem covBy_iff_le_iff_lt_right {x y : α} : x ⋖ y ↔ ∀ {z}, y ≤ z ↔ x < z := by
simp_rw [covBy_iff_lt_iff_le_right, iff_comm]
alias ⟨CovBy.lt_iff_le_left, _⟩ := covBy_iff_lt_iff_le_left
alias ⟨CovBy.le_iff_lt_left, _⟩ := covBy_iff_le_iff_lt_left
alias ⟨CovBy.lt_iff_le_right, _⟩ := covBy_iff_lt_iff_le_right
alias ⟨CovBy.le_iff_lt_right, _⟩ := covBy_iff_le_iff_lt_right
/-- If `a < b` then there exist `a' > a` and `b' < b` such that `Set.Iio a'` is strictly to the left
of `Set.Ioi b'`. -/
lemma LT.lt.exists_disjoint_Iio_Ioi (h : a < b) :
∃ a' > a, ∃ b' < b, ∀ x < a', ∀ y > b', x < y := by
by_cases h' : a ⋖ b
· exact ⟨b, h, a, h, fun x hx y hy => hx.trans_le <| h'.ge_of_gt hy⟩
· rcases h.exists_lt_lt h' with ⟨c, ha, hb⟩
exact ⟨c, ha, c, hb, fun _ h₁ _ => lt_trans h₁⟩
end LinearOrder
namespace Bool
@[simp] theorem wcovBy_iff : ∀ {a b : Bool}, a ⩿ b ↔ a ≤ b := by unfold WCovBy; decide
@[simp] theorem covBy_iff : ∀ {a b : Bool}, a ⋖ b ↔ a < b := by unfold CovBy; decide
instance instDecidableRelWCovBy : DecidableRel (· ⩿ · : Bool → Bool → Prop) := fun _ _ ↦
decidable_of_iff _ wcovBy_iff.symm
instance instDecidableRelCovBy : DecidableRel (· ⋖ · : Bool → Bool → Prop) := fun _ _ ↦
decidable_of_iff _ covBy_iff.symm
end Bool
namespace Set
variable {s t : Set α} {a : α}
@[simp] lemma wcovBy_insert (x : α) (s : Set α) : s ⩿ insert x s := by
refine wcovBy_of_eq_or_eq (subset_insert x s) fun t hst h2t => ?_
by_cases h : x ∈ t
· exact Or.inr (subset_antisymm h2t <| insert_subset_iff.mpr ⟨h, hst⟩)
· refine Or.inl (subset_antisymm ?_ hst)
rwa [← diff_singleton_eq_self h, diff_singleton_subset_iff]
@[simp] lemma sdiff_singleton_wcovBy (s : Set α) (a : α) : s \ {a} ⩿ s := by
by_cases ha : a ∈ s
· convert wcovBy_insert a _
ext
simp [ha]
· simp [ha]
@[simp] lemma covBy_insert (ha : a ∉ s) : s ⋖ insert a s :=
(wcovBy_insert _ _).covBy_of_lt <| ssubset_insert ha
@[simp] lemma sdiff_singleton_covBy (ha : a ∈ s) : s \ {a} ⋖ s :=
⟨sdiff_lt (singleton_subset_iff.2 ha) <| singleton_ne_empty _, (sdiff_singleton_wcovBy _ _).2⟩
lemma _root_.CovBy.exists_set_insert (h : s ⋖ t) : ∃ a ∉ s, insert a s = t :=
let ⟨a, ha, hst⟩ := ssubset_iff_insert.1 h.lt
⟨a, ha, (hst.eq_of_not_ssuperset <| h.2 <| ssubset_insert ha).symm⟩
lemma _root_.CovBy.exists_set_sdiff_singleton (h : s ⋖ t) : ∃ a ∈ t, t \ {a} = s :=
let ⟨a, ha, hst⟩ := ssubset_iff_sdiff_singleton.1 h.lt
⟨a, ha, (hst.eq_of_not_ssubset fun h' ↦ h.2 h' <|
sdiff_lt (singleton_subset_iff.2 ha) <| singleton_ne_empty _).symm⟩
lemma covBy_iff_exists_insert : s ⋖ t ↔ ∃ a ∉ s, insert a s = t :=
⟨CovBy.exists_set_insert, by rintro ⟨a, ha, rfl⟩; exact covBy_insert ha⟩
lemma covBy_iff_exists_sdiff_singleton : s ⋖ t ↔ ∃ a ∈ t, t \ {a} = s :=
⟨CovBy.exists_set_sdiff_singleton, by rintro ⟨a, ha, rfl⟩; exact sdiff_singleton_covBy ha⟩
end Set
section Relation
open Relation
lemma wcovBy_eq_reflGen_covBy [PartialOrder α] : ((· : α) ⩿ ·) = ReflGen (· ⋖ ·) := by
ext x y; simp_rw [wcovBy_iff_eq_or_covBy, @eq_comm _ x, reflGen_iff]
lemma transGen_wcovBy_eq_reflTransGen_covBy [PartialOrder α] :
TransGen ((· : α) ⩿ ·) = ReflTransGen (· ⋖ ·) := by
rw [wcovBy_eq_reflGen_covBy, transGen_reflGen]
lemma reflTransGen_wcovBy_eq_reflTransGen_covBy [PartialOrder α] :
ReflTransGen ((· : α) ⩿ ·) = ReflTransGen (· ⋖ ·) := by
rw [wcovBy_eq_reflGen_covBy, reflTransGen_reflGen]
end Relation
namespace Prod
variable [PartialOrder α] [PartialOrder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β}
@[simp]
theorem swap_wcovBy_swap : x.swap ⩿ y.swap ↔ x ⩿ y :=
apply_wcovBy_apply_iff (OrderIso.prodComm : α × β ≃o β × α)
@[simp]
theorem swap_covBy_swap : x.swap ⋖ y.swap ↔ x ⋖ y :=
apply_covBy_apply_iff (OrderIso.prodComm : α × β ≃o β × α)
theorem fst_eq_or_snd_eq_of_wcovBy : x ⩿ y → x.1 = y.1 ∨ x.2 = y.2 := by
refine fun h => of_not_not fun hab => ?_
push_neg at hab
exact
h.2 (mk_lt_mk.2 <| Or.inl ⟨hab.1.lt_of_le h.1.1, le_rfl⟩)
(mk_lt_mk.2 <| Or.inr ⟨le_rfl, hab.2.lt_of_le h.1.2⟩)
theorem _root_.WCovBy.fst (h : x ⩿ y) : x.1 ⩿ y.1 :=
⟨h.1.1, fun _ h₁ h₂ => h.2 (mk_lt_mk_iff_left.2 h₁) ⟨⟨h₂.le, h.1.2⟩, fun hc => h₂.not_le hc.1⟩⟩
theorem _root_.WCovBy.snd (h : x ⩿ y) : x.2 ⩿ y.2 :=
⟨h.1.2, fun _ h₁ h₂ => h.2 (mk_lt_mk_iff_right.2 h₁) ⟨⟨h.1.1, h₂.le⟩, fun hc => h₂.not_le hc.2⟩⟩
theorem mk_wcovBy_mk_iff_left : (a₁, b) ⩿ (a₂, b) ↔ a₁ ⩿ a₂ := by
refine ⟨WCovBy.fst, (And.imp mk_le_mk_iff_left.2) fun h c h₁ h₂ => ?_⟩
have : c.2 = b := h₂.le.2.antisymm h₁.le.2
rw [← @Prod.mk.eta _ _ c, this, mk_lt_mk_iff_left] at h₁ h₂
exact h h₁ h₂
theorem mk_wcovBy_mk_iff_right : (a, b₁) ⩿ (a, b₂) ↔ b₁ ⩿ b₂ :=
swap_wcovBy_swap.trans mk_wcovBy_mk_iff_left
theorem mk_covBy_mk_iff_left : (a₁, b) ⋖ (a₂, b) ↔ a₁ ⋖ a₂ := by
simp_rw [covBy_iff_wcovBy_and_lt, mk_wcovBy_mk_iff_left, mk_lt_mk_iff_left]
theorem mk_covBy_mk_iff_right : (a, b₁) ⋖ (a, b₂) ↔ b₁ ⋖ b₂ := by
simp_rw [covBy_iff_wcovBy_and_lt, mk_wcovBy_mk_iff_right, mk_lt_mk_iff_right]
theorem mk_wcovBy_mk_iff : (a₁, b₁) ⩿ (a₂, b₂) ↔ a₁ ⩿ a₂ ∧ b₁ = b₂ ∨ b₁ ⩿ b₂ ∧ a₁ = a₂ := by
refine ⟨fun h => ?_, ?_⟩
· obtain rfl | rfl : a₁ = a₂ ∨ b₁ = b₂ := fst_eq_or_snd_eq_of_wcovBy h
· exact Or.inr ⟨mk_wcovBy_mk_iff_right.1 h, rfl⟩
· exact Or.inl ⟨mk_wcovBy_mk_iff_left.1 h, rfl⟩
· rintro (⟨h, rfl⟩ | ⟨h, rfl⟩)
· exact mk_wcovBy_mk_iff_left.2 h
· exact mk_wcovBy_mk_iff_right.2 h
theorem mk_covBy_mk_iff : (a₁, b₁) ⋖ (a₂, b₂) ↔ a₁ ⋖ a₂ ∧ b₁ = b₂ ∨ b₁ ⋖ b₂ ∧ a₁ = a₂ := by
refine ⟨fun h => ?_, ?_⟩
· obtain rfl | rfl : a₁ = a₂ ∨ b₁ = b₂ := fst_eq_or_snd_eq_of_wcovBy h.wcovBy
· exact Or.inr ⟨mk_covBy_mk_iff_right.1 h, rfl⟩
· exact Or.inl ⟨mk_covBy_mk_iff_left.1 h, rfl⟩
· rintro (⟨h, rfl⟩ | ⟨h, rfl⟩)
· exact mk_covBy_mk_iff_left.2 h
· exact mk_covBy_mk_iff_right.2 h
| Mathlib/Order/Cover.lean | 557 | 562 | theorem wcovBy_iff : x ⩿ y ↔ x.1 ⩿ y.1 ∧ x.2 = y.2 ∨ x.2 ⩿ y.2 ∧ x.1 = y.1 := by | cases x
cases y
exact mk_wcovBy_mk_iff
theorem covBy_iff : x ⋖ y ↔ x.1 ⋖ y.1 ∧ x.2 = y.2 ∨ x.2 ⋖ y.2 ∧ x.1 = y.1 := by |
/-
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
/-!
# 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.
* `memLp_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 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}
theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) :
IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.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
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]
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)
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 _ => ?_
classical
rw [Set.iUnion_eq_if]
split_ifs with hji
· exact f.mono hji.le _ (hτ.measurableSet_le j)
· exact @MeasurableSet.empty _ (f i)
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
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)
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
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
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
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
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]
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))
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
rcases 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')
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
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, Set.mem_inter_iff, le_antisymm_iff]
rw [this]
exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i)
theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) :
MeasurableSet[f j] {ω | τ ω = i} :=
f.mono hle _ <| hτ.measurableSet_eq i
theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) :
MeasurableSet[f j] {ω | τ ω < i} :=
f.mono hle _ <| hτ.measurableSet_lt i
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)
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)
protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι}
(hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i :=
hτ.max (isStoppingTime_const f i)
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)
protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι}
(hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i :=
hτ.min (isStoppingTime_const f i)
theorem add_const [AddGroup ι] [Preorder ι] [AddRightMono ι]
[AddLeftMono ι] {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))
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, Set.mem_setOf]
omega
-- 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
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)
protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) :
MeasurableSet[hτ.measurableSpace] s ↔ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) :=
Iff.rfl
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'
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
theorem measurableSpace_le [IsCountablyGenerated (atTop : Filter ι)] [IsDirected ι (· ≤ ·)]
(hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by
intro s hs
cases isEmpty_or_nonempty ι
· haveI : IsEmpty Ω := ⟨fun ω => IsEmpty.false (τ ω)⟩
apply Subsingleton.measurableSet
· 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
@[deprecated (since := "2024-12-25")] alias measurableSpace_le' := 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)]
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
· simp [hij]
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
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)
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)
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
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
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τ _)
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
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
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)
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)
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
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
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)
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
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)
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
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
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
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
| Mathlib/Probability/Process/Stopping.lean | 526 | 534 | 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] |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Cofinality
This file contains the definition of cofinality of an order and an ordinal number.
## Main Definitions
* `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset
`s` that is *cofinal*, i.e. `∀ x, ∃ y ∈ s, r x y`.
* `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order.
## Main Statements
* `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for
`c ≥ ℵ₀`.
## Implementation Notes
* The cofinality is defined for ordinals.
If `c` is a cardinal number, its cofinality is `c.ord.cof`.
-/
noncomputable section
open Function Cardinal Set Order
open scoped Ordinal
universe u v w
variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
/-! ### Cofinality of orders -/
attribute [local instance] IsRefl.swap
namespace Order
/-- Cofinality of a reflexive order `≼`. This is the smallest cardinality
of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/
def cof (r : α → α → Prop) : Cardinal :=
sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }
/-- The set in the definition of `Order.cof` is nonempty. -/
private theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] :
{ c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty :=
⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩
theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S :=
csInf_le' ⟨S, h, rfl⟩
theorem le_cof [IsRefl α r] (c : Cardinal) :
c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by
rw [cof, le_csInf_iff'' (cof_nonempty r)]
use fun H S h => H _ ⟨S, h, rfl⟩
rintro H d ⟨S, h, rfl⟩
exact H h
end Order
namespace RelIso
private theorem cof_le_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) ≤ Cardinal.lift.{u} (Order.cof s) := by
rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)]
rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩
apply csInf_le'
refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩
rcases H (f a) with ⟨b, hb, hb'⟩
refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩
rwa [RelIso.apply_symm_apply]
theorem cof_eq_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) :=
have := f.toRelEmbedding.isRefl
(f.cof_le_lift).antisymm (f.symm.cof_le_lift)
theorem cof_eq {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) :
Order.cof r = Order.cof s :=
lift_inj.1 (f.cof_eq_lift)
end RelIso
/-! ### Cofinality of ordinals -/
namespace Ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is
unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`.
In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/
def cof (o : Ordinal.{u}) : Cardinal.{u} :=
o.liftOn (fun a ↦ Order.cof (swap a.rᶜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq
theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = Order.cof (swap rᶜ) :=
rfl
theorem cof_type_lt [LinearOrder α] [IsWellOrder α (· < ·)] :
(@type α (· < ·) _).cof = @Order.cof α (· ≤ ·) := by
rw [cof_type, compl_lt, swap_ge]
theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (· ≤ ·) := by
conv_lhs => rw [← type_toType o, cof_type_lt]
theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S :=
(le_csInf_iff'' (Order.cof_nonempty _)).trans
⟨fun H S h => H _ ⟨S, h, rfl⟩, by
rintro H d ⟨S, h, rfl⟩
exact H _ h⟩
theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S :=
le_cof_type.1 le_rfl S h
theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by
simpa using not_imp_not.2 cof_type_le
theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) :=
csInf_mem (Order.cof_nonempty (swap rᶜ))
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord := by
let ⟨S, hS, e⟩ := cof_eq r
let ⟨s, _, e'⟩ := Cardinal.ord_eq S
let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
suffices Unbounded r T by
refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩
rw [← e, e']
refine
(RelEmbedding.ofMonotone
(fun a : T =>
(⟨a,
let ⟨aS, _⟩ := a.2
aS⟩ :
S))
fun a b h => ?_).ordinal_type_le
rcases a with ⟨a, aS, ha⟩
rcases b with ⟨b, bS, hb⟩
change s ⟨a, _⟩ ⟨b, _⟩
refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_
· exact asymm h (ha _ hn)
· intro e
injection e with e
subst b
exact irrefl _ h
intro a
have : { b : S | ¬r b a }.Nonempty :=
let ⟨b, bS, ba⟩ := hS a
⟨⟨b, bS⟩, ba⟩
let b := (IsWellFounded.wf : WellFounded s).min _ this
have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩
rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
/-! ### Cofinality of suprema and least strict upper bounds -/
private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card :=
⟨_, _, lsub_typein o, mk_toType o⟩
/-- The set in the `lsub` characterization of `cof` is nonempty. -/
theorem cof_lsub_def_nonempty (o) :
{ a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty :=
⟨_, card_mem_cof⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_)
· rintro a ⟨ι, f, hf, rfl⟩
rw [← type_toType o]
refine
(cof_type_le fun a => ?_).trans
(@mk_le_of_injective _ _
(fun s : typein ((· < ·) : o.toType → o.toType → Prop) ⁻¹' Set.range f =>
Classical.choose s.prop)
fun s t hst => by
let H := congr_arg f hst
rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
Subtype.coe_inj] at H)
have := typein_lt_self a
simp_rw [← hf, lt_lsub_iff] at this
obtain ⟨i, hi⟩ := this
refine ⟨enum (α := o.toType) (· < ·) ⟨f i, ?_⟩, ?_, ?_⟩
· rw [type_toType, ← hf]
apply lt_lsub
· rw [mem_preimage, typein_enum]
exact mem_range_self i
· rwa [← typein_le_typein, typein_enum]
· rcases cof_eq (α := o.toType) (· < ·) with ⟨S, hS, hS'⟩
let f : S → Ordinal := fun s => typein LT.lt s.val
refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i)
(le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩
rw [← type_toType o] at ha
rcases hS (enum (· < ·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩
rw [← typein_le_typein, typein_enum] at hb'
exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩)
@[simp]
theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by
refine inductionOn o fun α r _ ↦ ?_
rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _),
← Cardinal.lift_umax]
apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩
simp [swap]
theorem cof_le_card (o) : cof o ≤ card o := by
rw [cof_eq_sInf_lsub]
exact csInf_le' card_mem_cof
theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord
theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o :=
(ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o)
theorem exists_lsub_cof (o : Ordinal) :
∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by
rw [cof_eq_sInf_lsub]
exact csInf_mem (cof_lsub_def_nonempty o)
theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact csInf_le' ⟨ι, f, rfl, rfl⟩
theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) :
cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← mk_uLift.{u, v}]
convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down
exact
lsub_eq_of_range_eq.{u, max u v, max u v}
(Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩)
theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} :
a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact
(le_csInf_iff'' (cof_lsub_def_nonempty o)).trans
⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by
rw [← hb]
exact H _ hf⟩
theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal}
(hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : lsub.{u, v} f < c :=
lt_of_le_of_ne (lsub_le hf) fun h => by
subst h
exact (cof_lsub_le_lift.{u, v} f).not_lt hι
theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → lsub.{u, u} f < c :=
lsub_lt_ord_lift (by rwa [(#ι).lift_id])
theorem cof_iSup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← Ordinal.sup] at *
rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H
rw [H]
exact cof_lsub_le_lift f
theorem cof_iSup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ #ι := by
rw [← (#ι).lift_id]
exact cof_iSup_le_lift H
theorem iSup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : iSup f < c :=
(sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf)
theorem iSup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_ord_lift (by rwa [(#ι).lift_id])
theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal}
(hι : Cardinal.lift.{v, u} #ι < c.ord.cof)
(hf : ∀ i, f i < c) : iSup f < c := by
rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)]
refine iSup_lt_ord_lift hι fun i => ?_
rw [ord_lt_ord]
apply hf
theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_lift (by rwa [(#ι).lift_id])
theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c)
(hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) :
nfpFamily f a < c := by
refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_
· rw [lift_max]
apply max_lt _ hc'
rwa [Cardinal.lift_aleph0]
· induction' l with i l H
· exact ha
· exact hf _ _ H
theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c)
(hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c :=
nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf
theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} :
a < c → nfp f a < c :=
nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf
theorem exists_blsub_cof (o : Ordinal) :
∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by
rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
rw [← hι, hι']
exact ⟨_, hf⟩
theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} :
a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card :=
le_cof_iff_lsub.trans
⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
simpa using H _ hf⟩
theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) :
cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← mk_toType o]
exact cof_lsub_le_lift _
theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_blsub_le_lift f
theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c :=
lt_of_le_of_ne (blsub_le hf) fun h =>
ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f)
theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof)
(hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c :=
blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf
theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) :
cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H
rw [H]
exact cof_blsub_le_lift.{u, v} f
theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} :
(∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_bsup_le_lift
theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c :=
(bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf)
theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) :
(∀ i hi, f i hi < c) → bsup.{u, u} o f < c :=
bsup_lt_ord_lift (by rwa [o.card.lift_id])
/-! ### Basic results -/
@[simp]
theorem cof_zero : cof 0 = 0 := by
refine LE.le.antisymm ?_ (Cardinal.zero_le _)
rw [← card_zero]
exact cof_le_card 0
@[simp]
theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 :=
⟨inductionOn o fun _ r _ z =>
let ⟨_, hl, e⟩ := cof_eq r
type_eq_zero_iff_isEmpty.2 <|
⟨fun a =>
let ⟨_, h, _⟩ := hl a
(mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩,
fun e => by simp [e]⟩
theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 :=
cof_eq_zero.not
@[simp]
theorem cof_succ (o) : cof (succ o) = 1 := by
apply le_antisymm
· refine inductionOn o fun α r _ => ?_
change cof (type _) ≤ _
rw [← (_ : #_ = 1)]
· apply cof_type_le
refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩
rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation]
· rw [Cardinal.mk_fintype, Set.card_singleton]
simp
· rw [← Cardinal.succ_zero, succ_le_iff]
simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h =>
succ_ne_zero o (cof_eq_zero.1 (Eq.symm h))
@[simp]
theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a :=
⟨inductionOn o fun α r _ z => by
rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e
obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero)
refine
⟨typein r a,
Eq.symm <|
Quotient.sound
⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩
· apply Sum.rec <;> [exact Subtype.val; exact fun _ => a]
· rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;>
simp [Subrel, Order.Preimage, EmptyRelation]
exact x.2
· suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by
convert this
dsimp [RelEmbedding.ofMonotone]; simp
rcases trichotomous_of r x a with (h | h | h)
· exact Or.inl h
· exact Or.inr ⟨PUnit.unit, h.symm⟩
· rcases hl x with ⟨a', aS, hn⟩
refine absurd h ?_
convert hn
change (a : α) = ↑(⟨a', aS⟩ : S)
have := le_one_iff_subsingleton.1 (le_of_eq e)
congr!,
fun ⟨a, e⟩ => by simp [e]⟩
/-! ### Fundamental sequences -/
-- TODO: move stuff about fundamental sequences to their own file.
/-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at
`a`. We provide `o` explicitly in order to avoid type rewrites. -/
def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop :=
o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a
namespace IsFundamentalSequence
variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}}
protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o :=
hf.1.antisymm' <| by
rw [← hf.2.2]
exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o)
protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} :
∀ hi hj, i < j → f i hi < f j hj :=
hf.2.1
theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a :=
hf.2.2
| Mathlib/SetTheory/Cardinal/Cofinality.lean | 451 | 455 | theorem ord_cof (hf : IsFundamentalSequence a o f) :
IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by | have H := hf.cof_eq
subst H
exact hf |
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Order.Group.Pointwise.Interval
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.Rat.Cardinal
import Mathlib.SetTheory.Cardinal.Continuum
/-!
# The cardinality of the reals
This file shows that the real numbers have cardinality continuum, i.e. `#ℝ = 𝔠`.
We show that `#ℝ ≤ 𝔠` by noting that every real number is determined by a Cauchy-sequence of the
form `ℕ → ℚ`, which has cardinality `𝔠`. To show that `#ℝ ≥ 𝔠` we define an injection from
`{0, 1} ^ ℕ` to `ℝ` with `f ↦ Σ n, f n * (1 / 3) ^ n`.
We conclude that all intervals with distinct endpoints have cardinality continuum.
## Main definitions
* `Cardinal.cantorFunction` is the function that sends `f` in `{0, 1} ^ ℕ` to `ℝ` by
`f ↦ Σ' n, f n * (1 / 3) ^ n`
## Main statements
* `Cardinal.mk_real : #ℝ = 𝔠`: the reals have cardinality continuum.
* `Cardinal.not_countable_real`: the universal set of real numbers is not countable.
We can use this same proof to show that all the other sets in this file are not countable.
* 8 lemmas of the form `mk_Ixy_real` for `x,y ∈ {i,o,c}` state that intervals on the reals
have cardinality continuum.
## Notation
* `𝔠` : notation for `Cardinal.continuum` in locale `Cardinal`, defined in `SetTheory.Continuum`.
## Tags
continuum, cardinality, reals, cardinality of the reals
-/
open Nat Set
open Cardinal
noncomputable section
namespace Cardinal
variable {c : ℝ} {f g : ℕ → Bool} {n : ℕ}
/-- The body of the sum in `cantorFunction`.
`cantorFunctionAux c f n = c ^ n` if `f n = true`;
`cantorFunctionAux c f n = 0` if `f n = false`. -/
def cantorFunctionAux (c : ℝ) (f : ℕ → Bool) (n : ℕ) : ℝ :=
cond (f n) (c ^ n) 0
@[simp]
theorem cantorFunctionAux_true (h : f n = true) : cantorFunctionAux c f n = c ^ n := by
simp [cantorFunctionAux, h]
@[simp]
theorem cantorFunctionAux_false (h : f n = false) : cantorFunctionAux c f n = 0 := by
simp [cantorFunctionAux, h]
theorem cantorFunctionAux_nonneg (h : 0 ≤ c) : 0 ≤ cantorFunctionAux c f n := by
cases h' : f n
· simp [h']
· simpa [h'] using pow_nonneg h _
theorem cantorFunctionAux_eq (h : f n = g n) :
cantorFunctionAux c f n = cantorFunctionAux c g n := by simp [cantorFunctionAux, h]
theorem cantorFunctionAux_zero (f : ℕ → Bool) : cantorFunctionAux c f 0 = cond (f 0) 1 0 := by
cases h : f 0 <;> simp [h]
theorem cantorFunctionAux_succ (f : ℕ → Bool) :
(fun n => cantorFunctionAux c f (n + 1)) = fun n =>
c * cantorFunctionAux c (fun n => f (n + 1)) n := by
ext n
cases h : f (n + 1) <;> simp [h, _root_.pow_succ']
theorem summable_cantor_function (f : ℕ → Bool) (h1 : 0 ≤ c) (h2 : c < 1) :
Summable (cantorFunctionAux c f) := by
apply (summable_geometric_of_lt_one h1 h2).summable_of_eq_zero_or_self
intro n; cases h : f n <;> simp [h]
/-- `cantorFunction c (f : ℕ → Bool)` is `Σ n, f n * c ^ n`, where `true` is interpreted as `1` and
`false` is interpreted as `0`. It is implemented using `cantorFunctionAux`. -/
def cantorFunction (c : ℝ) (f : ℕ → Bool) : ℝ :=
∑' n, cantorFunctionAux c f n
theorem cantorFunction_le (h1 : 0 ≤ c) (h2 : c < 1) (h3 : ∀ n, f n → g n) :
cantorFunction c f ≤ cantorFunction c g := by
apply (summable_cantor_function f h1 h2).tsum_le_tsum _ (summable_cantor_function g h1 h2)
intro n; cases h : f n
· simp [h, cantorFunctionAux_nonneg h1]
replace h3 : g n = true := h3 n h; simp [h, h3]
theorem cantorFunction_succ (f : ℕ → Bool) (h1 : 0 ≤ c) (h2 : c < 1) :
cantorFunction c f = cond (f 0) 1 0 + c * cantorFunction c fun n => f (n + 1) := by
rw [cantorFunction, (summable_cantor_function f h1 h2).tsum_eq_zero_add]
rw [cantorFunctionAux_succ, tsum_mul_left, cantorFunctionAux, pow_zero, cantorFunction]
/-- `cantorFunction c` is strictly increasing with if `0 < c < 1/2`, if we endow `ℕ → Bool` with a
lexicographic order. The lexicographic order doesn't exist for these infinitary products, so we
explicitly write out what it means. -/
theorem increasing_cantorFunction (h1 : 0 < c) (h2 : c < 1 / 2) {n : ℕ} {f g : ℕ → Bool}
(hn : ∀ k < n, f k = g k) (fn : f n = false) (gn : g n = true) :
cantorFunction c f < cantorFunction c g := by
have h3 : c < 1 := by
apply h2.trans
norm_num
induction' n with n ih generalizing f g
· let f_max : ℕ → Bool := fun n => Nat.rec false (fun _ _ => true) n
have hf_max : ∀ n, f n → f_max n := by
intro n hn
cases n
· rw [fn] at hn
contradiction
simp [f_max]
let g_min : ℕ → Bool := fun n => Nat.rec true (fun _ _ => false) n
have hg_min : ∀ n, g_min n → g n := by
intro n hn
cases n
· rw [gn]
simp at hn
apply (cantorFunction_le (le_of_lt h1) h3 hf_max).trans_lt
refine lt_of_lt_of_le ?_ (cantorFunction_le (le_of_lt h1) h3 hg_min)
have : c / (1 - c) < 1 := by
rw [div_lt_one, lt_sub_iff_add_lt]
· convert _root_.add_lt_add h2 h2
norm_num
rwa [sub_pos]
convert this
· rw [cantorFunction_succ _ (le_of_lt h1) h3, div_eq_mul_inv, ←
tsum_geometric_of_lt_one (le_of_lt h1) h3]
apply zero_add
· refine (tsum_eq_single 0 ?_).trans ?_
· intro n hn
cases n
· contradiction
simp [g_min]
· exact cantorFunctionAux_zero _
rw [cantorFunction_succ f (le_of_lt h1) h3, cantorFunction_succ g (le_of_lt h1) h3]
rw [hn 0 <| zero_lt_succ n]
apply add_lt_add_left
rw [mul_lt_mul_left h1]
exact ih (fun k hk => hn _ <| Nat.succ_lt_succ hk) fn gn
/-- `cantorFunction c` is injective if `0 < c < 1/2`. -/
theorem cantorFunction_injective (h1 : 0 < c) (h2 : c < 1 / 2) :
Function.Injective (cantorFunction c) := by
intro f g hfg
classical
contrapose hfg with h
have : ∃ n, f n ≠ g n := Function.ne_iff.mp h
let n := Nat.find this
have hn : ∀ k : ℕ, k < n → f k = g k := by
intro k hk
apply of_not_not
exact Nat.find_min this hk
cases fn : f n
· apply _root_.ne_of_lt
refine increasing_cantorFunction h1 h2 hn fn ?_
apply Bool.eq_true_of_not_eq_false
rw [← fn]
apply Ne.symm
exact Nat.find_spec this
· apply _root_.ne_of_gt
refine increasing_cantorFunction h1 h2 (fun k hk => (hn k hk).symm) ?_ fn
apply Bool.eq_false_of_not_eq_true
rw [← fn]
apply Ne.symm
exact Nat.find_spec this
/-- The cardinality of the reals, as a type. -/
theorem mk_real : #ℝ = 𝔠 := by
apply le_antisymm
· rw [Real.equivCauchy.cardinal_eq]
apply mk_quotient_le.trans
apply (mk_subtype_le _).trans_eq
rw [← power_def, mk_nat, mkRat, aleph0_power_aleph0]
· convert mk_le_of_injective (cantorFunction_injective _ _)
· rw [← power_def, mk_bool, mk_nat, two_power_aleph0]
· exact 1 / 3
· norm_num
· norm_num
/-- The cardinality of the reals, as a set. -/
theorem mk_univ_real : #(Set.univ : Set ℝ) = 𝔠 := by rw [mk_univ, mk_real]
/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/
instance : Uncountable ℝ := by
rw [← aleph0_lt_mk_iff, mk_real]
exact aleph0_lt_continuum
theorem not_countable_real : ¬(Set.univ : Set ℝ).Countable :=
not_countable_univ
/-- The cardinality of the interval (a, ∞). -/
theorem mk_Ioi_real (a : ℝ) : #(Ioi a) = 𝔠 := by
refine le_antisymm (mk_real ▸ mk_set_le _) ?_
rw [← not_lt]
intro h
refine _root_.ne_of_lt ?_ mk_univ_real
have hu : Iio a ∪ {a} ∪ Ioi a = Set.univ := by
convert @Iic_union_Ioi ℝ _ _
exact Iio_union_right
rw [← hu]
refine lt_of_le_of_lt (mk_union_le _ _) ?_
refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) ?_
have h2 : (fun x => a + a - x) '' Ioi a = Iio a := by
convert @image_const_sub_Ioi ℝ _ _ _
simp
rw [← h2]
refine add_lt_of_lt (cantor _).le ?_ h
refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) ?_
rw [mk_singleton]
exact one_lt_aleph0.trans (cantor _)
/-- The cardinality of the interval [a, ∞). -/
| Mathlib/Data/Real/Cardinality.lean | 225 | 243 | theorem mk_Ici_real (a : ℝ) : #(Ici a) = 𝔠 :=
le_antisymm (mk_real ▸ mk_set_le _) (mk_Ioi_real a ▸ mk_le_mk_of_subset Ioi_subset_Ici_self)
/-- The cardinality of the interval (-∞, a). -/
theorem mk_Iio_real (a : ℝ) : #(Iio a) = 𝔠 := by | refine le_antisymm (mk_real ▸ mk_set_le _) ?_
have h2 : (fun x => a + a - x) '' Iio a = Ioi a := by
simp only [image_const_sub_Iio, add_sub_cancel_right]
exact mk_Ioi_real a ▸ h2 ▸ mk_image_le
/-- The cardinality of the interval (-∞, a]. -/
theorem mk_Iic_real (a : ℝ) : #(Iic a) = 𝔠 :=
le_antisymm (mk_real ▸ mk_set_le _) (mk_Iio_real a ▸ mk_le_mk_of_subset Iio_subset_Iic_self)
/-- The cardinality of the interval (a, b). -/
theorem mk_Ioo_real {a b : ℝ} (h : a < b) : #(Ioo a b) = 𝔠 := by
refine le_antisymm (mk_real ▸ mk_set_le _) ?_
have h1 : #((fun x => x - a) '' Ioo a b) ≤ #(Ioo a b) := mk_image_le
refine le_trans ?_ h1 |
/-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton
-/
import Mathlib.Topology.Hom.ContinuousEval
import Mathlib.Topology.ContinuousMap.Basic
import Mathlib.Topology.Separation.Regular
/-!
# The compact-open topology
In this file, we define the compact-open topology on the set of continuous maps between two
topological spaces.
## Main definitions
* `ContinuousMap.compactOpen` is the compact-open topology on `C(X, Y)`.
It is declared as an instance.
* `ContinuousMap.coev` is the coevaluation map `Y → C(X, Y × X)`. It is always continuous.
* `ContinuousMap.curry` is the currying map `C(X × Y, Z) → C(X, C(Y, Z))`. This map always exists
and it is continuous as long as `X × Y` is locally compact.
* `ContinuousMap.uncurry` is the uncurrying map `C(X, C(Y, Z)) → C(X × Y, Z)`. For this map to
exist, we need `Y` to be locally compact. If `X` is also locally compact, then this map is
continuous.
* `Homeomorph.curry` combines the currying and uncurrying operations into a homeomorphism
`C(X × Y, Z) ≃ₜ C(X, C(Y, Z))`. This homeomorphism exists if `X` and `Y` are locally compact.
## Tags
compact-open, curry, function space
-/
open Set Filter TopologicalSpace Topology
namespace ContinuousMap
section CompactOpen
variable {α X Y Z T : Type*}
variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace T]
variable {K : Set X} {U : Set Y}
/-- The compact-open topology on the space of continuous maps `C(X, Y)`. -/
instance compactOpen : TopologicalSpace C(X, Y) :=
.generateFrom <| image2 (fun K U ↦ {f | MapsTo f K U}) {K | IsCompact K} {U | IsOpen U}
/-- Definition of `ContinuousMap.compactOpen`. -/
theorem compactOpen_eq : @compactOpen X Y _ _ =
.generateFrom (image2 (fun K U ↦ {f | MapsTo f K U}) {K | IsCompact K} {t | IsOpen t}) :=
rfl
theorem isOpen_setOf_mapsTo (hK : IsCompact K) (hU : IsOpen U) :
IsOpen {f : C(X, Y) | MapsTo f K U} :=
isOpen_generateFrom_of_mem <| mem_image2_of_mem hK hU
lemma eventually_mapsTo {f : C(X, Y)} (hK : IsCompact K) (hU : IsOpen U) (h : MapsTo f K U) :
∀ᶠ g : C(X, Y) in 𝓝 f, MapsTo g K U :=
(isOpen_setOf_mapsTo hK hU).mem_nhds h
lemma nhds_compactOpen (f : C(X, Y)) :
𝓝 f = ⨅ (K : Set X) (_ : IsCompact K) (U : Set Y) (_ : IsOpen U) (_ : MapsTo f K U),
𝓟 {g : C(X, Y) | MapsTo g K U} := by
simp_rw [compactOpen_eq, nhds_generateFrom, mem_setOf_eq, @and_comm (f ∈ _), iInf_and,
← image_prod, iInf_image, biInf_prod, mem_setOf_eq]
lemma tendsto_nhds_compactOpen {l : Filter α} {f : α → C(Y, Z)} {g : C(Y, Z)} :
Tendsto f l (𝓝 g) ↔
∀ K, IsCompact K → ∀ U, IsOpen U → MapsTo g K U → ∀ᶠ a in l, MapsTo (f a) K U := by
simp [nhds_compactOpen]
lemma continuous_compactOpen {f : X → C(Y, Z)} :
Continuous f ↔ ∀ K, IsCompact K → ∀ U, IsOpen U → IsOpen {x | MapsTo (f x) K U} :=
continuous_generateFrom_iff.trans forall_mem_image2
protected lemma hasBasis_nhds (f : C(X, Y)) :
(𝓝 f).HasBasis
(fun S : Set (Set X × Set Y) ↦
S.Finite ∧ ∀ K U, (K, U) ∈ S → IsCompact K ∧ IsOpen U ∧ MapsTo f K U)
(⋂ KU ∈ ·, {g : C(X, Y) | MapsTo g KU.1 KU.2}) := by
refine ⟨fun s ↦ ?_⟩
simp_rw [nhds_compactOpen, iInf_comm.{_, 0, _ + 1}, iInf_prod', iInf_and']
simp [mem_biInf_principal, and_assoc]
protected lemma mem_nhds_iff {f : C(X, Y)} {s : Set C(X, Y)} :
s ∈ 𝓝 f ↔ ∃ S : Set (Set X × Set Y), S.Finite ∧
(∀ K U, (K, U) ∈ S → IsCompact K ∧ IsOpen U ∧ MapsTo f K U) ∧
{g : C(X, Y) | ∀ K U, (K, U) ∈ S → MapsTo g K U} ⊆ s := by
simp [f.hasBasis_nhds.mem_iff, ← setOf_forall, and_assoc]
section Functorial
/-- `C(X, ·)` is a functor. -/
theorem continuous_postcomp (g : C(Y, Z)) : Continuous (ContinuousMap.comp g : C(X, Y) → C(X, Z)) :=
continuous_compactOpen.2 fun _K hK _U hU ↦ isOpen_setOf_mapsTo hK (hU.preimage g.2)
/-- If `g : C(Y, Z)` is a topology inducing map,
then the composition `ContinuousMap.comp g : C(X, Y) → C(X, Z)` is a topology inducing map too. -/
theorem isInducing_postcomp (g : C(Y, Z)) (hg : IsInducing g) :
IsInducing (g.comp : C(X, Y) → C(X, Z)) where
eq_induced := by
simp only [compactOpen_eq, induced_generateFrom_eq, image_image2, hg.setOf_isOpen,
image2_image_right, MapsTo, mem_preimage, preimage_setOf_eq, comp_apply]
@[deprecated (since := "2024-10-28")] alias inducing_postcomp := isInducing_postcomp
/-- If `g : C(Y, Z)` is a topological embedding,
then the composition `ContinuousMap.comp g : C(X, Y) → C(X, Z)` is an embedding too. -/
theorem isEmbedding_postcomp (g : C(Y, Z)) (hg : IsEmbedding g) :
IsEmbedding (g.comp : C(X, Y) → C(X, Z)) :=
⟨isInducing_postcomp g hg.1, fun _ _ ↦ (cancel_left hg.2).1⟩
@[deprecated (since := "2024-10-26")]
alias embedding_postcomp := isEmbedding_postcomp
/-- `C(·, Z)` is a functor. -/
@[continuity, fun_prop]
theorem continuous_precomp (f : C(X, Y)) : Continuous (fun g => g.comp f : C(Y, Z) → C(X, Z)) :=
continuous_compactOpen.2 fun K hK U hU ↦ by
simpa only [mapsTo_image_iff] using isOpen_setOf_mapsTo (hK.image f.2) hU
variable (Z) in
/-- Precomposition by a continuous map is itself a continuous map between spaces of continuous maps.
-/
@[simps apply]
def compRightContinuousMap (f : C(X, Y)) :
C(C(Y, Z), C(X, Z)) where
toFun g := g.comp f
/-- Any pair of homeomorphisms `X ≃ₜ Z` and `Y ≃ₜ T` gives rise to a homeomorphism
`C(X, Y) ≃ₜ C(Z, T)`. -/
protected def _root_.Homeomorph.arrowCongr (φ : X ≃ₜ Z) (ψ : Y ≃ₜ T) :
C(X, Y) ≃ₜ C(Z, T) where
toFun f := .comp ψ <| f.comp φ.symm
invFun f := .comp ψ.symm <| f.comp φ
left_inv f := ext fun _ ↦ ψ.left_inv (f _) |>.trans <| congrArg f <| φ.left_inv _
right_inv f := ext fun _ ↦ ψ.right_inv (f _) |>.trans <| congrArg f <| φ.right_inv _
continuous_toFun := continuous_postcomp _ |>.comp <| continuous_precomp _
continuous_invFun := continuous_postcomp _ |>.comp <| continuous_precomp _
variable [LocallyCompactPair Y Z]
/-- Composition is a continuous map from `C(X, Y) × C(Y, Z)` to `C(X, Z)`,
provided that `Y` is locally compact.
This is Prop. 9 of Chap. X, §3, №. 4 of Bourbaki's *Topologie Générale*. -/
theorem continuous_comp' : Continuous fun x : C(X, Y) × C(Y, Z) => x.2.comp x.1 := by
simp_rw [continuous_iff_continuousAt, ContinuousAt, tendsto_nhds_compactOpen]
intro ⟨f, g⟩ K hK U hU (hKU : MapsTo (g ∘ f) K U)
obtain ⟨L, hKL, hLc, hLU⟩ : ∃ L ∈ 𝓝ˢ (f '' K), IsCompact L ∧ MapsTo g L U :=
exists_mem_nhdsSet_isCompact_mapsTo g.continuous (hK.image f.continuous) hU
(mapsTo_image_iff.2 hKU)
rw [← subset_interior_iff_mem_nhdsSet, ← mapsTo'] at hKL
exact ((eventually_mapsTo hK isOpen_interior hKL).prod_nhds
(eventually_mapsTo hLc hU hLU)).mono fun ⟨f', g'⟩ ⟨hf', hg'⟩ ↦
hg'.comp <| hf'.mono_right interior_subset
lemma _root_.Filter.Tendsto.compCM {α : Type*} {l : Filter α} {g : α → C(Y, Z)} {g₀ : C(Y, Z)}
{f : α → C(X, Y)} {f₀ : C(X, Y)} (hg : Tendsto g l (𝓝 g₀)) (hf : Tendsto f l (𝓝 f₀)) :
Tendsto (fun a ↦ (g a).comp (f a)) l (𝓝 (g₀.comp f₀)) :=
(continuous_comp'.tendsto (f₀, g₀)).comp (hf.prodMk_nhds hg)
variable {X' : Type*} [TopologicalSpace X'] {a : X'} {g : X' → C(Y, Z)} {f : X' → C(X, Y)}
{s : Set X'}
nonrec lemma _root_.ContinuousAt.compCM (hg : ContinuousAt g a) (hf : ContinuousAt f a) :
ContinuousAt (fun x ↦ (g x).comp (f x)) a :=
hg.compCM hf
nonrec lemma _root_.ContinuousWithinAt.compCM (hg : ContinuousWithinAt g s a)
(hf : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x ↦ (g x).comp (f x)) s a :=
hg.compCM hf
lemma _root_.ContinuousOn.compCM (hg : ContinuousOn g s) (hf : ContinuousOn f s) :
ContinuousOn (fun x ↦ (g x).comp (f x)) s := fun a ha ↦
(hg a ha).compCM (hf a ha)
lemma _root_.Continuous.compCM (hg : Continuous g) (hf : Continuous f) :
Continuous fun x => (g x).comp (f x) :=
continuous_comp'.comp (hf.prodMk hg)
end Functorial
section Ev
/-- The evaluation map `C(X, Y) × X → Y` is continuous
if `X, Y` is a locally compact pair of spaces. -/
instance [LocallyCompactPair X Y] : ContinuousEval C(X, Y) X Y where
continuous_eval := by
simp_rw [continuous_iff_continuousAt, ContinuousAt, (nhds_basis_opens _).tendsto_right_iff]
rintro ⟨f, x⟩ U ⟨hx : f x ∈ U, hU : IsOpen U⟩
rcases exists_mem_nhds_isCompact_mapsTo f.continuous (hU.mem_nhds hx) with ⟨K, hxK, hK, hKU⟩
filter_upwards [prod_mem_nhds (eventually_mapsTo hK hU hKU) hxK] using fun _ h ↦ h.1 h.2
instance : ContinuousEvalConst C(X, Y) X Y where
continuous_eval_const x :=
continuous_def.2 fun U hU ↦ by simpa using isOpen_setOf_mapsTo isCompact_singleton hU
lemma isClosed_setOf_mapsTo {t : Set Y} (ht : IsClosed t) (s : Set X) :
IsClosed {f : C(X, Y) | MapsTo f s t} :=
ht.setOf_mapsTo fun _ _ ↦ continuous_eval_const _
lemma isClopen_setOf_mapsTo (hK : IsCompact K) (hU : IsClopen U) :
IsClopen {f : C(X, Y) | MapsTo f K U} :=
⟨isClosed_setOf_mapsTo hU.isClosed K, isOpen_setOf_mapsTo hK hU.isOpen⟩
@[norm_cast]
lemma specializes_coe {f g : C(X, Y)} : ⇑f ⤳ ⇑g ↔ f ⤳ g := by
refine ⟨fun h ↦ ?_, fun h ↦ h.map continuous_coeFun⟩
suffices ∀ K, IsCompact K → ∀ U, IsOpen U → MapsTo g K U → MapsTo f K U by
simpa [specializes_iff_pure, nhds_compactOpen]
exact fun K _ U hU hg x hx ↦ (h.map (continuous_apply x)).mem_open hU (hg hx)
@[norm_cast]
lemma inseparable_coe {f g : C(X, Y)} : Inseparable (f : X → Y) g ↔ Inseparable f g := by
simp only [inseparable_iff_specializes_and, specializes_coe]
instance [T0Space Y] : T0Space C(X, Y) :=
t0Space_of_injective_of_continuous DFunLike.coe_injective continuous_coeFun
instance [R0Space Y] : R0Space C(X, Y) where
specializes_symmetric f g h := by
rw [← specializes_coe] at h ⊢
exact h.symm
instance [T1Space Y] : T1Space C(X, Y) :=
t1Space_of_injective_of_continuous DFunLike.coe_injective continuous_coeFun
instance [R1Space Y] : R1Space C(X, Y) :=
.of_continuous_specializes_imp continuous_coeFun fun _ _ ↦ specializes_coe.1
instance [T2Space Y] : T2Space C(X, Y) := inferInstance
instance [RegularSpace Y] : RegularSpace C(X, Y) :=
.of_lift'_closure_le fun f ↦ by
rw [← tendsto_id', tendsto_nhds_compactOpen]
intro K hK U hU hf
rcases (hK.image f.continuous).exists_isOpen_closure_subset (hU.mem_nhdsSet.2 hf.image_subset)
with ⟨V, hVo, hKV, hVU⟩
filter_upwards [mem_lift' (eventually_mapsTo hK hVo (mapsTo'.2 hKV))] with g hg
refine ((isClosed_setOf_mapsTo isClosed_closure K).closure_subset ?_).mono_right hVU
exact closure_mono (fun _ h ↦ h.mono_right subset_closure) hg
instance [T3Space Y] : T3Space C(X, Y) := inferInstance
end Ev
section InfInduced
/-- For any subset `s` of `X`, the restriction of continuous functions to `s` is continuous
as a function from `C(X, Y)` to `C(s, Y)` with their respective compact-open topologies. -/
theorem continuous_restrict (s : Set X) : Continuous fun F : C(X, Y) => F.restrict s :=
continuous_precomp <| restrict s <| .id X
theorem compactOpen_le_induced (s : Set X) :
(ContinuousMap.compactOpen : TopologicalSpace C(X, Y)) ≤
.induced (restrict s) ContinuousMap.compactOpen :=
(continuous_restrict s).le_induced
/-- The compact-open topology on `C(X, Y)`
is equal to the infimum of the compact-open topologies on `C(s, Y)` for `s` a compact subset of `X`.
The key point of the proof is that for every compact set `K`,
the universal set `Set.univ : Set K` is a compact set as well. -/
theorem compactOpen_eq_iInf_induced :
(ContinuousMap.compactOpen : TopologicalSpace C(X, Y)) =
⨅ (K : Set X) (_ : IsCompact K), .induced (.restrict K) ContinuousMap.compactOpen := by
refine le_antisymm (le_iInf₂ fun s _ ↦ compactOpen_le_induced s) ?_
refine le_generateFrom <| forall_mem_image2.2 fun K (hK : IsCompact K) U hU ↦ ?_
refine TopologicalSpace.le_def.1 (iInf₂_le K hK) _ ?_
convert isOpen_induced (isOpen_setOf_mapsTo (isCompact_iff_isCompact_univ.1 hK) hU)
simp [mapsTo_univ_iff, Subtype.forall, MapsTo]
| Mathlib/Topology/CompactOpen.lean | 274 | 282 | theorem nhds_compactOpen_eq_iInf_nhds_induced (f : C(X, Y)) :
𝓝 f = ⨅ (s) (_ : IsCompact s), (𝓝 (f.restrict s)).comap (ContinuousMap.restrict s) := by | rw [compactOpen_eq_iInf_induced]
simp only [nhds_iInf, nhds_induced]
theorem tendsto_compactOpen_restrict {ι : Type*} {l : Filter ι} {F : ι → C(X, Y)} {f : C(X, Y)}
(hFf : Filter.Tendsto F l (𝓝 f)) (s : Set X) :
Tendsto (fun i => (F i).restrict s) l (𝓝 (f.restrict s)) :=
(continuous_restrict s).continuousAt.tendsto.comp hFf |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau
-/
import Mathlib.Data.List.Forall2
/-!
# Lists with no duplicates
`List.Nodup` is defined in `Data/List/Basic`. In this file we prove various properties of this
predicate.
-/
universe u v
open Function
variable {α : Type u} {β : Type v} {l l₁ l₂ : List α} {r : α → α → Prop} {a : α}
namespace List
protected theorem Pairwise.nodup {l : List α} {r : α → α → Prop} [IsIrrefl α r] (h : Pairwise r l) :
Nodup l :=
h.imp ne_of_irrefl
open scoped Relator in
theorem rel_nodup {r : α → β → Prop} (hr : Relator.BiUnique r) : (Forall₂ r ⇒ (· ↔ ·)) Nodup Nodup
| _, _, Forall₂.nil => by simp only [nodup_nil]
| _, _, Forall₂.cons hab h => by
simpa only [nodup_cons] using
Relator.rel_and (Relator.rel_not (rel_mem hr hab h)) (rel_nodup hr h)
protected theorem Nodup.cons (ha : a ∉ l) (hl : Nodup l) : Nodup (a :: l) :=
nodup_cons.2 ⟨ha, hl⟩
theorem nodup_singleton (a : α) : Nodup [a] :=
pairwise_singleton _ _
theorem Nodup.of_cons (h : Nodup (a :: l)) : Nodup l :=
(nodup_cons.1 h).2
theorem Nodup.not_mem (h : (a :: l).Nodup) : a ∉ l :=
(nodup_cons.1 h).1
theorem not_nodup_cons_of_mem : a ∈ l → ¬Nodup (a :: l) :=
imp_not_comm.1 Nodup.not_mem
theorem not_nodup_pair (a : α) : ¬Nodup [a, a] :=
not_nodup_cons_of_mem <| mem_singleton_self _
theorem nodup_iff_sublist {l : List α} : Nodup l ↔ ∀ a, ¬[a, a] <+ l :=
⟨fun d a h => not_nodup_pair a (d.sublist h),
by
induction l <;> intro h; · exact nodup_nil
case cons a l IH =>
exact (IH fun a s => h a <| sublist_cons_of_sublist _ s).cons
fun al => h a <| (singleton_sublist.2 al).cons_cons _⟩
@[simp]
theorem nodup_mergeSort {l : List α} {le : α → α → Bool} : (l.mergeSort le).Nodup ↔ l.Nodup :=
(mergeSort_perm l le).nodup_iff
protected alias ⟨_, Nodup.mergeSort⟩ := nodup_mergeSort
theorem nodup_iff_injective_getElem {l : List α} :
Nodup l ↔ Function.Injective (fun i : Fin l.length => l[i.1]) :=
pairwise_iff_getElem.trans
⟨fun h i j hg => by
obtain ⟨i, hi⟩ := i; obtain ⟨j, hj⟩ := j
rcases lt_trichotomy i j with (hij | rfl | hji)
· exact (h i j hi hj hij hg).elim
· rfl
· exact (h j i hj hi hji hg.symm).elim,
fun hinj i j hi hj hij h => Nat.ne_of_lt hij (Fin.val_eq_of_eq (@hinj ⟨i, hi⟩ ⟨j, hj⟩ h))⟩
theorem nodup_iff_injective_get {l : List α} :
Nodup l ↔ Function.Injective l.get := by
rw [nodup_iff_injective_getElem]
change _ ↔ Injective (fun i => l.get i)
simp
theorem Nodup.get_inj_iff {l : List α} (h : Nodup l) {i j : Fin l.length} :
l.get i = l.get j ↔ i = j :=
(nodup_iff_injective_get.1 h).eq_iff
theorem Nodup.getElem_inj_iff {l : List α} (h : Nodup l)
{i : Nat} {hi : i < l.length} {j : Nat} {hj : j < l.length} :
l[i] = l[j] ↔ i = j := by
have := @Nodup.get_inj_iff _ _ h ⟨i, hi⟩ ⟨j, hj⟩
simpa
theorem nodup_iff_getElem?_ne_getElem? {l : List α} :
l.Nodup ↔ ∀ i j : ℕ, i < j → j < l.length → l[i]? ≠ l[j]? := by
rw [Nodup, pairwise_iff_getElem]
constructor
· intro h i j hij hj
rw [getElem?_eq_getElem (lt_trans hij hj), getElem?_eq_getElem hj, Ne, Option.some_inj]
exact h _ _ (by omega) hj hij
· intro h i j hi hj hij
rw [Ne, ← Option.some_inj, ← getElem?_eq_getElem, ← getElem?_eq_getElem]
exact h i j hij hj
set_option linter.deprecated false in
@[deprecated nodup_iff_getElem?_ne_getElem? (since := "2025-02-17")]
theorem nodup_iff_get?_ne_get? {l : List α} :
l.Nodup ↔ ∀ i j : ℕ, i < j → j < l.length → l.get? i ≠ l.get? j := by
simp [nodup_iff_getElem?_ne_getElem?]
theorem Nodup.ne_singleton_iff {l : List α} (h : Nodup l) (x : α) :
l ≠ [x] ↔ l = [] ∨ ∃ y ∈ l, y ≠ x := by
induction l with
| nil => simp
| cons hd tl hl =>
specialize hl h.of_cons
by_cases hx : tl = [x]
· simpa [hx, and_comm, and_or_left] using h
· rw [← Ne, hl] at hx
rcases hx with (rfl | ⟨y, hy, hx⟩)
· simp
· suffices ∃ y ∈ hd :: tl, y ≠ x by simpa [ne_nil_of_mem hy]
exact ⟨y, mem_cons_of_mem _ hy, hx⟩
theorem not_nodup_of_get_eq_of_ne (xs : List α) (n m : Fin xs.length)
(h : xs.get n = xs.get m) (hne : n ≠ m) : ¬Nodup xs := by
rw [nodup_iff_injective_get]
exact fun hinj => hne (hinj h)
theorem idxOf_getElem [DecidableEq α] {l : List α} (H : Nodup l) (i : Nat) (h : i < l.length) :
idxOf l[i] l = i :=
suffices (⟨idxOf l[i] l, idxOf_lt_length_iff.2 (getElem_mem _)⟩ : Fin l.length) = ⟨i, h⟩
from Fin.val_eq_of_eq this
nodup_iff_injective_get.1 H (by simp)
@[deprecated (since := "2025-01-30")] alias indexOf_getElem := idxOf_getElem
-- This is incorrectly named and should be `idxOf_get`;
-- this already exists, so will require a deprecation dance.
theorem get_idxOf [DecidableEq α] {l : List α} (H : Nodup l) (i : Fin l.length) :
idxOf (get l i) l = i := by
simp [idxOf_getElem, H]
@[deprecated (since := "2025-01-30")] alias get_indexOf := get_idxOf
theorem nodup_iff_count_le_one [DecidableEq α] {l : List α} : Nodup l ↔ ∀ a, count a l ≤ 1 :=
nodup_iff_sublist.trans <|
forall_congr' fun a =>
have : replicate 2 a <+ l ↔ 1 < count a l := (le_count_iff_replicate_sublist ..).symm
(not_congr this).trans not_lt
theorem nodup_iff_count_eq_one [DecidableEq α] : Nodup l ↔ ∀ a ∈ l, count a l = 1 :=
nodup_iff_count_le_one.trans <| forall_congr' fun _ =>
⟨fun H h => H.antisymm (count_pos_iff.mpr h),
fun H => if h : _ then (H h).le else (count_eq_zero.mpr h).trans_le (Nat.zero_le 1)⟩
@[simp]
theorem count_eq_one_of_mem [DecidableEq α] {a : α} {l : List α} (d : Nodup l) (h : a ∈ l) :
count a l = 1 :=
_root_.le_antisymm (nodup_iff_count_le_one.1 d a) (Nat.succ_le_of_lt (count_pos_iff.2 h))
theorem count_eq_of_nodup [DecidableEq α] {a : α} {l : List α} (d : Nodup l) :
count a l = if a ∈ l then 1 else 0 := by
split_ifs with h
· exact count_eq_one_of_mem d h
· exact count_eq_zero_of_not_mem h
theorem Nodup.of_append_left : Nodup (l₁ ++ l₂) → Nodup l₁ :=
Nodup.sublist (sublist_append_left l₁ l₂)
theorem Nodup.of_append_right : Nodup (l₁ ++ l₂) → Nodup l₂ :=
Nodup.sublist (sublist_append_right l₁ l₂)
theorem nodup_append {l₁ l₂ : List α} :
Nodup (l₁ ++ l₂) ↔ Nodup l₁ ∧ Nodup l₂ ∧ Disjoint l₁ l₂ := by
simp only [Nodup, pairwise_append, disjoint_iff_ne]
theorem disjoint_of_nodup_append {l₁ l₂ : List α} (d : Nodup (l₁ ++ l₂)) : Disjoint l₁ l₂ :=
(nodup_append.1 d).2.2
theorem Nodup.append (d₁ : Nodup l₁) (d₂ : Nodup l₂) (dj : Disjoint l₁ l₂) : Nodup (l₁ ++ l₂) :=
nodup_append.2 ⟨d₁, d₂, dj⟩
theorem nodup_append_comm {l₁ l₂ : List α} : Nodup (l₁ ++ l₂) ↔ Nodup (l₂ ++ l₁) := by
simp only [nodup_append, and_left_comm, disjoint_comm]
theorem nodup_middle {a : α} {l₁ l₂ : List α} :
Nodup (l₁ ++ a :: l₂) ↔ Nodup (a :: (l₁ ++ l₂)) := by
simp only [nodup_append, not_or, and_left_comm, and_assoc, nodup_cons, mem_append,
disjoint_cons_right]
theorem Nodup.of_map (f : α → β) {l : List α} : Nodup (map f l) → Nodup l :=
(Pairwise.of_map f) fun _ _ => mt <| congr_arg f
theorem Nodup.map_on {f : α → β} (H : ∀ x ∈ l, ∀ y ∈ l, f x = f y → x = y) (d : Nodup l) :
(map f l).Nodup :=
Pairwise.map _ (fun a b ⟨ma, mb, n⟩ e => n (H a ma b mb e)) (Pairwise.and_mem.1 d)
theorem inj_on_of_nodup_map {f : α → β} {l : List α} (d : Nodup (map f l)) :
∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → f x = f y → x = y := by
induction l with
| nil => simp
| cons hd tl ih =>
simp only [map, nodup_cons, mem_map, not_exists, not_and, ← Ne.eq_def] at d
simp only [mem_cons]
rintro _ (rfl | h₁) _ (rfl | h₂) h₃
· rfl
· apply (d.1 _ h₂ h₃.symm).elim
· apply (d.1 _ h₁ h₃).elim
· apply ih d.2 h₁ h₂ h₃
theorem nodup_map_iff_inj_on {f : α → β} {l : List α} (d : Nodup l) :
Nodup (map f l) ↔ ∀ x ∈ l, ∀ y ∈ l, f x = f y → x = y :=
⟨inj_on_of_nodup_map, fun h => d.map_on h⟩
protected theorem Nodup.map {f : α → β} (hf : Injective f) : Nodup l → Nodup (map f l) :=
Nodup.map_on fun _ _ _ _ h => hf h
theorem nodup_map_iff {f : α → β} {l : List α} (hf : Injective f) : Nodup (map f l) ↔ Nodup l :=
⟨Nodup.of_map _, Nodup.map hf⟩
@[simp]
theorem nodup_attach {l : List α} : Nodup (attach l) ↔ Nodup l :=
⟨fun h => attach_map_subtype_val l ▸ h.map fun _ _ => Subtype.eq, fun h =>
Nodup.of_map Subtype.val ((attach_map_subtype_val l).symm ▸ h)⟩
protected alias ⟨Nodup.of_attach, Nodup.attach⟩ := nodup_attach
theorem Nodup.pmap {p : α → Prop} {f : ∀ a, p a → β} {l : List α} {H}
(hf : ∀ a ha b hb, f a ha = f b hb → a = b) (h : Nodup l) : Nodup (pmap f l H) := by
rw [pmap_eq_map_attach]
exact h.attach.map fun ⟨a, ha⟩ ⟨b, hb⟩ h => by congr; exact hf a (H _ ha) b (H _ hb) h
theorem Nodup.filter (p : α → Bool) {l} : Nodup l → Nodup (filter p l) := by
simpa using Pairwise.filter p
@[simp]
theorem nodup_reverse {l : List α} : Nodup (reverse l) ↔ Nodup l :=
pairwise_reverse.trans <| by simp only [Nodup, Ne, eq_comm]
lemma nodup_tail_reverse (l : List α) (h : l[0]? = l.getLast?) :
Nodup l.reverse.tail ↔ Nodup l.tail := by
induction l with
| nil => simp
| cons a l ih =>
by_cases hl : l = []
· aesop
· simp_all only [List.tail_reverse, List.nodup_reverse,
List.dropLast_cons_of_ne_nil hl, List.tail_cons]
simp only [length_cons, Nat.zero_lt_succ, getElem?_eq_getElem, getElem_cons_zero,
Nat.add_one_sub_one, Nat.lt_add_one, Option.some.injEq, List.getElem_cons,
show l.length ≠ 0 by aesop, ↓reduceDIte, getLast?_eq_getElem?] at h
rw [h,
show l.Nodup = (l.dropLast ++ [l.getLast hl]).Nodup by
simp [List.dropLast_eq_take],
List.nodup_append_comm]
simp [List.getLast_eq_getElem]
theorem Nodup.erase_getElem [DecidableEq α] {l : List α} (hl : l.Nodup)
(i : Nat) (h : i < l.length) : l.erase l[i] = l.eraseIdx ↑i := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
rw [nodup_cons] at hl
rw [erase_cons_tail]
· simp [IH hl.2]
· rw [beq_iff_eq]
simp only [getElem_cons_succ]
simp only [length_cons, Nat.succ_eq_add_one, Nat.add_lt_add_iff_right] at h
exact mt (· ▸ getElem_mem h) hl.1
theorem Nodup.erase_get [DecidableEq α] {l : List α} (hl : l.Nodup) (i : Fin l.length) :
l.erase (l.get i) = l.eraseIdx ↑i := by
simp [erase_getElem, hl]
theorem Nodup.diff [DecidableEq α] : l₁.Nodup → (l₁.diff l₂).Nodup :=
Nodup.sublist <| diff_sublist _ _
theorem nodup_flatten {L : List (List α)} :
Nodup (flatten L) ↔ (∀ l ∈ L, Nodup l) ∧ Pairwise Disjoint L := by
simp only [Nodup, pairwise_flatten, disjoint_left.symm, forall_mem_ne]
@[deprecated (since := "2025-10-15")] alias nodup_join := nodup_flatten
theorem nodup_flatMap {l₁ : List α} {f : α → List β} :
Nodup (l₁.flatMap f) ↔
(∀ x ∈ l₁, Nodup (f x)) ∧ Pairwise (Disjoint on f) l₁ := by
simp only [List.flatMap, nodup_flatten, pairwise_map, and_comm, and_left_comm, mem_map,
exists_imp, and_imp]
rw [show (∀ (l : List β) (x : α), f x = l → x ∈ l₁ → Nodup l) ↔ ∀ x : α, x ∈ l₁ → Nodup (f x)
from forall_swap.trans <| forall_congr' fun _ => forall_eq']
@[deprecated (since := "2025-10-16")] alias nodup_bind := nodup_flatMap
protected theorem Nodup.product {l₂ : List β} (d₁ : l₁.Nodup) (d₂ : l₂.Nodup) :
(l₁ ×ˢ l₂).Nodup :=
nodup_flatMap.2
⟨fun a _ => d₂.map <| LeftInverse.injective fun b => (rfl : (a, b).2 = b),
d₁.imp fun {a₁ a₂} n x h₁ h₂ => by
rcases mem_map.1 h₁ with ⟨b₁, _, rfl⟩
rcases mem_map.1 h₂ with ⟨b₂, mb₂, ⟨⟩⟩
exact n rfl⟩
theorem Nodup.sigma {σ : α → Type*} {l₂ : ∀ a, List (σ a)} (d₁ : Nodup l₁)
(d₂ : ∀ a, Nodup (l₂ a)) : (l₁.sigma l₂).Nodup :=
nodup_flatMap.2
⟨fun a _ => (d₂ a).map fun b b' h => by injection h with _ h,
d₁.imp fun {a₁ a₂} n x h₁ h₂ => by
rcases mem_map.1 h₁ with ⟨b₁, _, rfl⟩
rcases mem_map.1 h₂ with ⟨b₂, mb₂, ⟨⟩⟩
exact n rfl⟩
protected theorem Nodup.filterMap {f : α → Option β} (h : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a') :
Nodup l → Nodup (filterMap f l) :=
(Pairwise.filterMap f) @fun a a' n b bm b' bm' e => n <| h a a' b' (by rw [← e]; exact bm) bm'
protected theorem Nodup.concat (h : a ∉ l) (h' : l.Nodup) : (l.concat a).Nodup := by
rw [concat_eq_append]; exact h'.append (nodup_singleton _) (disjoint_singleton.2 h)
protected theorem Nodup.insert [DecidableEq α] (h : l.Nodup) : (l.insert a).Nodup :=
if h' : a ∈ l then by rw [insert_of_mem h']; exact h
else by rw [insert_of_not_mem h', nodup_cons]; constructor <;> assumption
| Mathlib/Data/List/Nodup.lean | 330 | 344 | theorem Nodup.union [DecidableEq α] (l₁ : List α) (h : Nodup l₂) : (l₁ ∪ l₂).Nodup := by | induction l₁ generalizing l₂ with
| nil => exact h
| cons a l₁ ih => exact (ih h).insert
theorem Nodup.inter [DecidableEq α] (l₂ : List α) : Nodup l₁ → Nodup (l₁ ∩ l₂) :=
Nodup.filter _
theorem Nodup.diff_eq_filter [BEq α] [LawfulBEq α] :
∀ {l₁ l₂ : List α} (_ : l₁.Nodup), l₁.diff l₂ = l₁.filter (· ∉ l₂)
| l₁, [], _ => by simp
| l₁, a :: l₂, hl₁ => by
rw [diff_cons, (hl₁.erase _).diff_eq_filter, hl₁.erase_eq_filter, filter_filter]
simp only [decide_not, bne, Bool.and_comm, mem_cons, not_or, decide_mem_cons, Bool.not_or] |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Filter.Prod
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Filter.Finite
import Mathlib.Order.Filter.Bases.Basic
/-!
# Lift filters along filter and set functions
-/
open Set Filter Function
namespace Filter
variable {α β γ : Type*} {ι : Sort*}
section lift
variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Set α → Filter β}
@[simp]
theorem lift_top (g : Set α → Filter β) : (⊤ : Filter α).lift g = g univ := by simp [Filter.lift]
/-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function
`Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis
of the filter `g (s i)`, then
`(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)` is a basis
of the filter `f.lift g`.
This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using
`Filter.HasBasis` one has to use `Σ i, β i` as the index type, see `Filter.HasBasis.lift`.
This lemma states the corresponding `mem_iff` statement without using a sigma type. -/
theorem HasBasis.mem_lift_iff {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α}
(hf : f.HasBasis p s) {β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ}
{g : Set α → Filter γ} (hg : ∀ i, (g <| s i).HasBasis (pg i) (sg i)) (gm : Monotone g)
{s : Set γ} : s ∈ f.lift g ↔ ∃ i, p i ∧ ∃ x, pg i x ∧ sg i x ⊆ s := by
refine (mem_biInf_of_directed ?_ ⟨univ, univ_sets _⟩).trans ?_
· intro t₁ ht₁ t₂ ht₂
exact ⟨t₁ ∩ t₂, inter_mem ht₁ ht₂, gm inter_subset_left, gm inter_subset_right⟩
· simp only [← (hg _).mem_iff]
exact hf.exists_iff fun t₁ t₂ ht H => gm ht H
/-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function
`Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis
of the filter `g (s i)`, then
`(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)`
is a basis of the filter `f.lift g`.
This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using
`has_basis` one has to use `Σ i, β i` as the index type. See also `Filter.HasBasis.mem_lift_iff`
for the corresponding `mem_iff` statement formulated without using a sigma type. -/
theorem HasBasis.lift {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α} (hf : f.HasBasis p s)
{β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ} {g : Set α → Filter γ}
(hg : ∀ i, (g (s i)).HasBasis (pg i) (sg i)) (gm : Monotone g) :
(f.lift g).HasBasis (fun i : Σi, β i => p i.1 ∧ pg i.1 i.2) fun i : Σi, β i => sg i.1 i.2 := by
refine ⟨fun t => (hf.mem_lift_iff hg gm).trans ?_⟩
simp [Sigma.exists, and_assoc, exists_and_left]
theorem mem_lift_sets (hg : Monotone g) {s : Set β} : s ∈ f.lift g ↔ ∃ t ∈ f, s ∈ g t :=
(f.basis_sets.mem_lift_iff (fun s => (g s).basis_sets) hg).trans <| by
simp only [id, exists_mem_subset_iff]
theorem sInter_lift_sets (hg : Monotone g) :
⋂₀ { s | s ∈ f.lift g } = ⋂ s ∈ f, ⋂₀ { t | t ∈ g s } := by
simp only [sInter_eq_biInter, mem_setOf_eq, Filter.mem_sets, mem_lift_sets hg, iInter_exists,
iInter_and, @iInter_comm _ (Set β)]
theorem mem_lift {s : Set β} {t : Set α} (ht : t ∈ f) (hs : s ∈ g t) : s ∈ f.lift g :=
le_principal_iff.mp <|
show f.lift g ≤ 𝓟 s from iInf_le_of_le t <| iInf_le_of_le ht <| le_principal_iff.mpr hs
theorem lift_le {f : Filter α} {g : Set α → Filter β} {h : Filter β} {s : Set α} (hs : s ∈ f)
(hg : g s ≤ h) : f.lift g ≤ h :=
iInf₂_le_of_le s hs hg
theorem le_lift {f : Filter α} {g : Set α → Filter β} {h : Filter β} :
h ≤ f.lift g ↔ ∀ s ∈ f, h ≤ g s :=
le_iInf₂_iff
theorem lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.lift g₁ ≤ f₂.lift g₂ :=
iInf_mono fun s => iInf_mono' fun hs => ⟨hf hs, hg s⟩
theorem lift_mono' (hg : ∀ s ∈ f, g₁ s ≤ g₂ s) : f.lift g₁ ≤ f.lift g₂ := iInf₂_mono hg
theorem tendsto_lift {m : γ → β} {l : Filter γ} :
Tendsto m l (f.lift g) ↔ ∀ s ∈ f, Tendsto m l (g s) := by
simp only [Filter.lift, tendsto_iInf]
theorem map_lift_eq {m : β → γ} (hg : Monotone g) : map m (f.lift g) = f.lift (map m ∘ g) :=
have : Monotone (map m ∘ g) := map_mono.comp hg
Filter.ext fun s => by
simp only [mem_lift_sets hg, mem_lift_sets this, exists_prop, mem_map, Function.comp_apply]
theorem comap_lift_eq {m : γ → β} : comap m (f.lift g) = f.lift (comap m ∘ g) := by
simp only [Filter.lift, comap_iInf]; rfl
theorem comap_lift_eq2 {m : β → α} {g : Set β → Filter γ} (hg : Monotone g) :
(comap m f).lift g = f.lift (g ∘ preimage m) :=
le_antisymm (le_iInf₂ fun s hs => iInf₂_le (m ⁻¹' s) ⟨s, hs, Subset.rfl⟩)
(le_iInf₂ fun _s ⟨s', hs', h_sub⟩ => iInf₂_le_of_le s' hs' <| hg h_sub)
theorem lift_map_le {g : Set β → Filter γ} {m : α → β} : (map m f).lift g ≤ f.lift (g ∘ image m) :=
le_lift.2 fun _s hs => lift_le (image_mem_map hs) le_rfl
theorem map_lift_eq2 {g : Set β → Filter γ} {m : α → β} (hg : Monotone g) :
(map m f).lift g = f.lift (g ∘ image m) :=
lift_map_le.antisymm <| le_lift.2 fun _s hs => lift_le hs <| hg <| image_preimage_subset _ _
theorem lift_comm {g : Filter β} {h : Set α → Set β → Filter γ} :
(f.lift fun s => g.lift (h s)) = g.lift fun t => f.lift fun s => h s t :=
le_antisymm
(le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj =>
iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi)
(le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj =>
iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi)
theorem lift_assoc {h : Set β → Filter γ} (hg : Monotone g) :
(f.lift g).lift h = f.lift fun s => (g s).lift h :=
le_antisymm
(le_iInf₂ fun _s hs => le_iInf₂ fun t ht =>
iInf_le_of_le t <| iInf_le _ <| (mem_lift_sets hg).mpr ⟨_, hs, ht⟩)
(le_iInf₂ fun t ht =>
let ⟨s, hs, h'⟩ := (mem_lift_sets hg).mp ht
iInf_le_of_le s <| iInf_le_of_le hs <| iInf_le_of_le t <| iInf_le _ h')
theorem lift_lift_same_le_lift {g : Set α → Set α → Filter β} :
(f.lift fun s => f.lift (g s)) ≤ f.lift fun s => g s s :=
le_lift.2 fun _s hs => lift_le hs <| lift_le hs le_rfl
theorem lift_lift_same_eq_lift {g : Set α → Set α → Filter β} (hg₁ : ∀ s, Monotone fun t => g s t)
(hg₂ : ∀ t, Monotone fun s => g s t) : (f.lift fun s => f.lift (g s)) = f.lift fun s => g s s :=
lift_lift_same_le_lift.antisymm <|
le_lift.2 fun s hs => le_lift.2 fun t ht => lift_le (inter_mem hs ht) <|
calc
g (s ∩ t) (s ∩ t) ≤ g s (s ∩ t) := hg₂ (s ∩ t) inter_subset_left
_ ≤ g s t := hg₁ s inter_subset_right
theorem lift_principal {s : Set α} (hg : Monotone g) : (𝓟 s).lift g = g s :=
(lift_le (mem_principal_self _) le_rfl).antisymm (le_lift.2 fun _t ht => hg ht)
theorem monotone_lift [Preorder γ] {f : γ → Filter α} {g : γ → Set α → Filter β} (hf : Monotone f)
(hg : Monotone g) : Monotone fun c => (f c).lift (g c) := fun _ _ h => lift_mono (hf h) (hg h)
theorem lift_neBot_iff (hm : Monotone g) : (NeBot (f.lift g)) ↔ ∀ s ∈ f, NeBot (g s) := by
simp only [neBot_iff, Ne, ← empty_mem_iff_bot, mem_lift_sets hm, not_exists, not_and]
@[simp]
theorem lift_const {f : Filter α} {g : Filter β} : (f.lift fun _ => g) = g :=
iInf_subtype'.trans iInf_const
@[simp]
theorem lift_inf {f : Filter α} {g h : Set α → Filter β} :
(f.lift fun x => g x ⊓ h x) = f.lift g ⊓ f.lift h := by simp only [Filter.lift, iInf_inf_eq]
@[simp]
theorem lift_principal2 {f : Filter α} : f.lift 𝓟 = f :=
le_antisymm (fun s hs => mem_lift hs (mem_principal_self s))
(le_iInf fun s => le_iInf fun hs => by simp only [hs, le_principal_iff])
theorem lift_iInf_le {f : ι → Filter α} {g : Set α → Filter β} :
(iInf f).lift g ≤ ⨅ i, (f i).lift g :=
le_iInf fun _ => lift_mono (iInf_le _ _) le_rfl
theorem lift_iInf [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β}
(hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) : (iInf f).lift g = ⨅ i, (f i).lift g := by
refine lift_iInf_le.antisymm fun s => ?_
have H : ∀ t ∈ iInf f, ⨅ i, (f i).lift g ≤ g t := by
intro t ht
refine iInf_sets_induct ht ?_ fun hs ht => ?_
· inhabit ι
exact iInf₂_le_of_le default univ (iInf_le _ univ_mem)
· rw [hg]
exact le_inf (iInf₂_le_of_le _ _ <| iInf_le _ hs) ht
simp only [mem_lift_sets (Monotone.of_map_inf hg), exists_imp, and_imp]
exact fun t ht hs => H t ht hs
theorem lift_iInf_of_directed [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β}
(hf : Directed (· ≥ ·) f) (hg : Monotone g) : (iInf f).lift g = ⨅ i, (f i).lift g :=
lift_iInf_le.antisymm fun s => by
simp only [mem_lift_sets hg, exists_imp, and_imp, mem_iInf_of_directed hf]
exact fun t i ht hs => mem_iInf_of_mem i <| mem_lift ht hs
theorem lift_iInf_of_map_univ {f : ι → Filter α} {g : Set α → Filter β}
(hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) (hg' : g univ = ⊤) :
(iInf f).lift g = ⨅ i, (f i).lift g := by
cases isEmpty_or_nonempty ι
· simp [iInf_of_empty, hg']
· exact lift_iInf hg
end lift
section Lift'
variable {f f₁ f₂ : Filter α} {h h₁ h₂ : Set α → Set β}
@[simp]
theorem lift'_top (h : Set α → Set β) : (⊤ : Filter α).lift' h = 𝓟 (h univ) :=
lift_top _
theorem mem_lift' {t : Set α} (ht : t ∈ f) : h t ∈ f.lift' h :=
le_principal_iff.mp <| show f.lift' h ≤ 𝓟 (h t) from iInf_le_of_le t <| iInf_le_of_le ht <| le_rfl
theorem tendsto_lift' {m : γ → β} {l : Filter γ} :
Tendsto m l (f.lift' h) ↔ ∀ s ∈ f, ∀ᶠ a in l, m a ∈ h s := by
simp only [Filter.lift', tendsto_lift, tendsto_principal, comp]
theorem HasBasis.lift' {ι} {p : ι → Prop} {s} (hf : f.HasBasis p s) (hh : Monotone h) :
(f.lift' h).HasBasis p (h ∘ s) :=
⟨fun t => (hf.mem_lift_iff (fun i => hasBasis_principal (h (s i)))
(monotone_principal.comp hh)).trans <| by simp only [exists_const, true_and, comp]⟩
theorem mem_lift'_sets (hh : Monotone h) {s : Set β} : s ∈ f.lift' h ↔ ∃ t ∈ f, h t ⊆ s :=
mem_lift_sets <| monotone_principal.comp hh
theorem eventually_lift'_iff (hh : Monotone h) {p : β → Prop} :
(∀ᶠ y in f.lift' h, p y) ↔ ∃ t ∈ f, ∀ y ∈ h t, p y :=
mem_lift'_sets hh
theorem sInter_lift'_sets (hh : Monotone h) : ⋂₀ { s | s ∈ f.lift' h } = ⋂ s ∈ f, h s :=
(sInter_lift_sets (monotone_principal.comp hh)).trans <| iInter₂_congr fun _ _ => csInf_Ici
theorem lift'_le {f : Filter α} {g : Set α → Set β} {h : Filter β} {s : Set α} (hs : s ∈ f)
(hg : 𝓟 (g s) ≤ h) : f.lift' g ≤ h :=
lift_le hs hg
theorem lift'_mono (hf : f₁ ≤ f₂) (hh : h₁ ≤ h₂) : f₁.lift' h₁ ≤ f₂.lift' h₂ :=
lift_mono hf fun s => principal_mono.mpr <| hh s
theorem lift'_mono' (hh : ∀ s ∈ f, h₁ s ⊆ h₂ s) : f.lift' h₁ ≤ f.lift' h₂ :=
iInf₂_mono fun s hs => principal_mono.mpr <| hh s hs
theorem lift'_cong (hh : ∀ s ∈ f, h₁ s = h₂ s) : f.lift' h₁ = f.lift' h₂ :=
le_antisymm (lift'_mono' fun s hs => le_of_eq <| hh s hs)
(lift'_mono' fun s hs => le_of_eq <| (hh s hs).symm)
theorem map_lift'_eq {m : β → γ} (hh : Monotone h) : map m (f.lift' h) = f.lift' (image m ∘ h) :=
calc
map m (f.lift' h) = f.lift (map m ∘ 𝓟 ∘ h) := map_lift_eq <| monotone_principal.comp hh
_ = f.lift' (image m ∘ h) := by simp only [comp_def, Filter.lift', map_principal]
theorem lift'_map_le {g : Set β → Set γ} {m : α → β} : (map m f).lift' g ≤ f.lift' (g ∘ image m) :=
lift_map_le
theorem map_lift'_eq2 {g : Set β → Set γ} {m : α → β} (hg : Monotone g) :
(map m f).lift' g = f.lift' (g ∘ image m) :=
map_lift_eq2 <| monotone_principal.comp hg
| Mathlib/Order/Filter/Lift.lean | 252 | 254 | theorem comap_lift'_eq {m : γ → β} : comap m (f.lift' h) = f.lift' (preimage m ∘ h) := by | simp only [Filter.lift', comap_lift_eq, comp_def, comap_principal] |
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, Eric Wieser
-/
import Mathlib.Analysis.Normed.Lp.PiLp
import Mathlib.Analysis.InnerProductSpace.PiL2
/-!
# Matrices as a normed space
In this file we provide the following non-instances for norms on matrices:
* The elementwise norm:
* `Matrix.seminormedAddCommGroup`
* `Matrix.normedAddCommGroup`
* `Matrix.normedSpace`
* `Matrix.isBoundedSMul`
* The Frobenius norm:
* `Matrix.frobeniusSeminormedAddCommGroup`
* `Matrix.frobeniusNormedAddCommGroup`
* `Matrix.frobeniusNormedSpace`
* `Matrix.frobeniusNormedRing`
* `Matrix.frobeniusNormedAlgebra`
* `Matrix.frobeniusIsBoundedSMul`
* The $L^\infty$ operator norm:
* `Matrix.linftyOpSeminormedAddCommGroup`
* `Matrix.linftyOpNormedAddCommGroup`
* `Matrix.linftyOpNormedSpace`
* `Matrix.linftyOpIsBoundedSMul`
* `Matrix.linftyOpNonUnitalSemiNormedRing`
* `Matrix.linftyOpSemiNormedRing`
* `Matrix.linftyOpNonUnitalNormedRing`
* `Matrix.linftyOpNormedRing`
* `Matrix.linftyOpNormedAlgebra`
These are not declared as instances because there are several natural choices for defining the norm
of a matrix.
The norm induced by the identification of `Matrix m n 𝕜` with
`EuclideanSpace n 𝕜 →L[𝕜] EuclideanSpace m 𝕜` (i.e., the ℓ² operator norm) can be found in
`Analysis.CStarAlgebra.Matrix`. It is separated to avoid extraneous imports in this file.
-/
noncomputable section
open scoped NNReal Matrix
namespace Matrix
variable {R l m n α β ι : Type*} [Fintype l] [Fintype m] [Fintype n] [Unique ι]
/-! ### The elementwise supremum norm -/
section LinfLinf
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β]
/-- Seminormed group instance (using sup norm of sup norm) for matrices over a seminormed group. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
protected def seminormedAddCommGroup : SeminormedAddCommGroup (Matrix m n α) :=
Pi.seminormedAddCommGroup
attribute [local instance] Matrix.seminormedAddCommGroup
theorem norm_def (A : Matrix m n α) : ‖A‖ = ‖fun i j => A i j‖ := rfl
/-- The norm of a matrix is the sup of the sup of the nnnorm of the entries -/
lemma norm_eq_sup_sup_nnnorm (A : Matrix m n α) :
‖A‖ = Finset.sup Finset.univ fun i ↦ Finset.sup Finset.univ fun j ↦ ‖A i j‖₊ := by
simp_rw [Matrix.norm_def, Pi.norm_def, Pi.nnnorm_def]
theorem nnnorm_def (A : Matrix m n α) : ‖A‖₊ = ‖fun i j => A i j‖₊ := rfl
theorem norm_le_iff {r : ℝ} (hr : 0 ≤ r) {A : Matrix m n α} : ‖A‖ ≤ r ↔ ∀ i j, ‖A i j‖ ≤ r := by
simp_rw [norm_def, pi_norm_le_iff_of_nonneg hr]
theorem nnnorm_le_iff {r : ℝ≥0} {A : Matrix m n α} : ‖A‖₊ ≤ r ↔ ∀ i j, ‖A i j‖₊ ≤ r := by
simp_rw [nnnorm_def, pi_nnnorm_le_iff]
theorem norm_lt_iff {r : ℝ} (hr : 0 < r) {A : Matrix m n α} : ‖A‖ < r ↔ ∀ i j, ‖A i j‖ < r := by
simp_rw [norm_def, pi_norm_lt_iff hr]
theorem nnnorm_lt_iff {r : ℝ≥0} (hr : 0 < r) {A : Matrix m n α} :
‖A‖₊ < r ↔ ∀ i j, ‖A i j‖₊ < r := by
simp_rw [nnnorm_def, pi_nnnorm_lt_iff hr]
theorem norm_entry_le_entrywise_sup_norm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖ ≤ ‖A‖ :=
(norm_le_pi_norm (A i) j).trans (norm_le_pi_norm A i)
theorem nnnorm_entry_le_entrywise_sup_nnnorm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖₊ ≤ ‖A‖₊ :=
(nnnorm_le_pi_nnnorm (A i) j).trans (nnnorm_le_pi_nnnorm A i)
@[simp]
theorem nnnorm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖₊ = ‖a‖₊) :
‖A.map f‖₊ = ‖A‖₊ := by
simp only [nnnorm_def, Pi.nnnorm_def, Matrix.map_apply, hf]
@[simp]
theorem norm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖ = ‖a‖) : ‖A.map f‖ = ‖A‖ :=
(congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_map_eq A f fun a => Subtype.ext <| hf a :)
@[simp]
theorem nnnorm_transpose (A : Matrix m n α) : ‖Aᵀ‖₊ = ‖A‖₊ :=
Finset.sup_comm _ _ _
@[simp]
theorem norm_transpose (A : Matrix m n α) : ‖Aᵀ‖ = ‖A‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_transpose A
@[simp]
theorem nnnorm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) :
‖Aᴴ‖₊ = ‖A‖₊ :=
(nnnorm_map_eq _ _ nnnorm_star).trans A.nnnorm_transpose
@[simp]
theorem norm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖ = ‖A‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_conjTranspose A
instance [StarAddMonoid α] [NormedStarGroup α] : NormedStarGroup (Matrix m m α) :=
⟨(le_of_eq <| norm_conjTranspose ·)⟩
@[simp]
theorem nnnorm_replicateCol (v : m → α) : ‖replicateCol ι v‖₊ = ‖v‖₊ := by
simp [nnnorm_def, Pi.nnnorm_def]
@[deprecated (since := "2025-03-20")] alias nnnorm_col := nnnorm_replicateCol
@[simp]
theorem norm_replicateCol (v : m → α) : ‖replicateCol ι v‖ = ‖v‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_replicateCol v
@[deprecated (since := "2025-03-20")] alias norm_col := norm_replicateCol
@[simp]
theorem nnnorm_replicateRow (v : n → α) : ‖replicateRow ι v‖₊ = ‖v‖₊ := by
simp [nnnorm_def, Pi.nnnorm_def]
@[deprecated (since := "2025-03-20")] alias nnnorm_row := nnnorm_replicateRow
@[simp]
theorem norm_replicateRow (v : n → α) : ‖replicateRow ι v‖ = ‖v‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_replicateRow v
@[deprecated (since := "2025-03-20")] alias norm_row := norm_replicateRow
@[simp]
theorem nnnorm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖₊ = ‖v‖₊ := by
simp_rw [nnnorm_def, Pi.nnnorm_def]
congr 1 with i : 1
refine le_antisymm (Finset.sup_le fun j hj => ?_) ?_
· obtain rfl | hij := eq_or_ne i j
· rw [diagonal_apply_eq]
· rw [diagonal_apply_ne _ hij, nnnorm_zero]
exact zero_le _
· refine Eq.trans_le ?_ (Finset.le_sup (Finset.mem_univ i))
rw [diagonal_apply_eq]
@[simp]
theorem norm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖ = ‖v‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_diagonal v
/-- Note this is safe as an instance as it carries no data. -/
-- Porting note: not yet implemented: `@[nolint fails_quickly]`
instance [Nonempty n] [DecidableEq n] [One α] [NormOneClass α] : NormOneClass (Matrix n n α) :=
⟨(norm_diagonal _).trans <| norm_one⟩
end SeminormedAddCommGroup
/-- Normed group instance (using sup norm of sup norm) for matrices over a normed group. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
protected def normedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) :=
Pi.normedAddCommGroup
section NormedSpace
attribute [local instance] Matrix.seminormedAddCommGroup
/-- This applies to the sup norm of sup norm. -/
protected theorem isBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α]
[IsBoundedSMul R α] : IsBoundedSMul R (Matrix m n α) :=
Pi.instIsBoundedSMul
@[deprecated (since := "2025-03-10")] protected alias boundedSMul := Matrix.isBoundedSMul
variable [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α]
/-- Normed space instance (using sup norm of sup norm) for matrices over a normed space. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
protected def normedSpace : NormedSpace R (Matrix m n α) :=
Pi.normedSpace
end NormedSpace
end LinfLinf
/-! ### The $L_\infty$ operator norm
This section defines the matrix norm $\|A\|_\infty = \operatorname{sup}_i (\sum_j \|A_{ij}\|)$.
Note that this is equivalent to the operator norm, considering $A$ as a linear map between two
$L^\infty$ spaces.
-/
section LinftyOp
/-- Seminormed group instance (using sup norm of L1 norm) for matrices over a seminormed group. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
protected def linftyOpSeminormedAddCommGroup [SeminormedAddCommGroup α] :
SeminormedAddCommGroup (Matrix m n α) :=
(by infer_instance : SeminormedAddCommGroup (m → PiLp 1 fun j : n => α))
/-- Normed group instance (using sup norm of L1 norm) for matrices over a normed ring. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
protected def linftyOpNormedAddCommGroup [NormedAddCommGroup α] :
NormedAddCommGroup (Matrix m n α) :=
(by infer_instance : NormedAddCommGroup (m → PiLp 1 fun j : n => α))
/-- This applies to the sup norm of L1 norm. -/
@[local instance]
protected theorem linftyOpIsBoundedSMul
[SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [IsBoundedSMul R α] :
IsBoundedSMul R (Matrix m n α) :=
(by infer_instance : IsBoundedSMul R (m → PiLp 1 fun j : n => α))
/-- Normed space instance (using sup norm of L1 norm) for matrices over a normed space. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
protected def linftyOpNormedSpace [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] :
NormedSpace R (Matrix m n α) :=
(by infer_instance : NormedSpace R (m → PiLp 1 fun j : n => α))
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup α]
theorem linfty_opNorm_def (A : Matrix m n α) :
‖A‖ = ((Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ : ℝ≥0) := by
-- Porting note: added
change ‖fun i => (WithLp.equiv 1 _).symm (A i)‖ = _
simp [Pi.norm_def, PiLp.nnnorm_eq_of_L1]
theorem linfty_opNNNorm_def (A : Matrix m n α) :
‖A‖₊ = (Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ :=
Subtype.ext <| linfty_opNorm_def A
@[simp]
theorem linfty_opNNNorm_replicateCol (v : m → α) : ‖replicateCol ι v‖₊ = ‖v‖₊ := by
rw [linfty_opNNNorm_def, Pi.nnnorm_def]
simp
@[deprecated (since := "2025-03-20")] alias linfty_opNNNorm_col := linfty_opNNNorm_replicateCol
@[simp]
theorem linfty_opNorm_replicateCol (v : m → α) : ‖replicateCol ι v‖ = ‖v‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_replicateCol v
@[deprecated (since := "2025-03-20")] alias linfty_opNorm_col := linfty_opNorm_replicateCol
@[simp]
theorem linfty_opNNNorm_replicateRow (v : n → α) : ‖replicateRow ι v‖₊ = ∑ i, ‖v i‖₊ := by
simp [linfty_opNNNorm_def]
@[deprecated (since := "2025-03-20")] alias linfty_opNNNorm_row := linfty_opNNNorm_replicateRow
@[simp]
theorem linfty_opNorm_replicateRow (v : n → α) : ‖replicateRow ι v‖ = ∑ i, ‖v i‖ :=
(congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_replicateRow v).trans <| by simp [NNReal.coe_sum]
@[deprecated (since := "2025-03-20")] alias linfty_opNorm_row := linfty_opNNNorm_replicateRow
@[simp]
theorem linfty_opNNNorm_diagonal [DecidableEq m] (v : m → α) : ‖diagonal v‖₊ = ‖v‖₊ := by
rw [linfty_opNNNorm_def, Pi.nnnorm_def]
congr 1 with i : 1
refine (Finset.sum_eq_single_of_mem _ (Finset.mem_univ i) fun j _hj hij => ?_).trans ?_
· rw [diagonal_apply_ne' _ hij, nnnorm_zero]
· rw [diagonal_apply_eq]
@[simp]
theorem linfty_opNorm_diagonal [DecidableEq m] (v : m → α) : ‖diagonal v‖ = ‖v‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_diagonal v
end SeminormedAddCommGroup
section NonUnitalSeminormedRing
variable [NonUnitalSeminormedRing α]
theorem linfty_opNNNorm_mul (A : Matrix l m α) (B : Matrix m n α) : ‖A * B‖₊ ≤ ‖A‖₊ * ‖B‖₊ := by
simp_rw [linfty_opNNNorm_def, Matrix.mul_apply]
calc
(Finset.univ.sup fun i => ∑ k, ‖∑ j, A i j * B j k‖₊) ≤
Finset.univ.sup fun i => ∑ k, ∑ j, ‖A i j‖₊ * ‖B j k‖₊ :=
Finset.sup_mono_fun fun i _hi =>
Finset.sum_le_sum fun k _hk => nnnorm_sum_le_of_le _ fun j _hj => nnnorm_mul_le _ _
_ = Finset.univ.sup fun i => ∑ j, ‖A i j‖₊ * ∑ k, ‖B j k‖₊ := by
simp_rw [@Finset.sum_comm m, Finset.mul_sum]
_ ≤ Finset.univ.sup fun i => ∑ j, ‖A i j‖₊ * Finset.univ.sup fun i => ∑ j, ‖B i j‖₊ := by
refine Finset.sup_mono_fun fun i _hi => ?_
gcongr with j hj
exact Finset.le_sup (f := fun i ↦ ∑ k : n, ‖B i k‖₊) hj
_ ≤ (Finset.univ.sup fun i => ∑ j, ‖A i j‖₊) * Finset.univ.sup fun i => ∑ j, ‖B i j‖₊ := by
simp_rw [← Finset.sum_mul, ← NNReal.finset_sup_mul]
rfl
theorem linfty_opNorm_mul (A : Matrix l m α) (B : Matrix m n α) : ‖A * B‖ ≤ ‖A‖ * ‖B‖ :=
linfty_opNNNorm_mul _ _
theorem linfty_opNNNorm_mulVec (A : Matrix l m α) (v : m → α) : ‖A *ᵥ v‖₊ ≤ ‖A‖₊ * ‖v‖₊ := by
rw [← linfty_opNNNorm_replicateCol (ι := Fin 1) (A *ᵥ v),
← linfty_opNNNorm_replicateCol v (ι := Fin 1)]
exact linfty_opNNNorm_mul A (replicateCol (Fin 1) v)
theorem linfty_opNorm_mulVec (A : Matrix l m α) (v : m → α) : ‖A *ᵥ v‖ ≤ ‖A‖ * ‖v‖ :=
linfty_opNNNorm_mulVec _ _
end NonUnitalSeminormedRing
/-- Seminormed non-unital ring instance (using sup norm of L1 norm) for matrices over a semi normed
non-unital ring. Not declared as an instance because there are several natural choices for defining
the norm of a matrix. -/
@[local instance]
protected def linftyOpNonUnitalSemiNormedRing [NonUnitalSeminormedRing α] :
NonUnitalSeminormedRing (Matrix n n α) :=
{ Matrix.linftyOpSeminormedAddCommGroup, Matrix.instNonUnitalRing with
norm_mul_le := linfty_opNorm_mul }
/-- The `L₁-L∞` norm preserves one on non-empty matrices. Note this is safe as an instance, as it
carries no data. -/
instance linfty_opNormOneClass [SeminormedRing α] [NormOneClass α] [DecidableEq n] [Nonempty n] :
NormOneClass (Matrix n n α) where norm_one := (linfty_opNorm_diagonal _).trans norm_one
/-- Seminormed ring instance (using sup norm of L1 norm) for matrices over a semi normed ring. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
protected def linftyOpSemiNormedRing [SeminormedRing α] [DecidableEq n] :
SeminormedRing (Matrix n n α) :=
{ Matrix.linftyOpNonUnitalSemiNormedRing, Matrix.instRing with }
/-- Normed non-unital ring instance (using sup norm of L1 norm) for matrices over a normed
non-unital ring. Not declared as an instance because there are several natural choices for defining
the norm of a matrix. -/
@[local instance]
protected def linftyOpNonUnitalNormedRing [NonUnitalNormedRing α] :
NonUnitalNormedRing (Matrix n n α) :=
{ Matrix.linftyOpNonUnitalSemiNormedRing with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
/-- Normed ring instance (using sup norm of L1 norm) for matrices over a normed ring. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
protected def linftyOpNormedRing [NormedRing α] [DecidableEq n] : NormedRing (Matrix n n α) :=
{ Matrix.linftyOpSemiNormedRing with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
/-- Normed algebra instance (using sup norm of L1 norm) for matrices over a normed algebra. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
protected def linftyOpNormedAlgebra [NormedField R] [SeminormedRing α] [NormedAlgebra R α]
[DecidableEq n] : NormedAlgebra R (Matrix n n α) :=
{ Matrix.linftyOpNormedSpace, Matrix.instAlgebra with }
section
variable [NormedDivisionRing α] [NormedAlgebra ℝ α]
/-- Auxiliary construction; an element of norm 1 such that `a * unitOf a = ‖a‖`. -/
private def unitOf (a : α) : α := by classical exact if a = 0 then 1 else ‖a‖ • a⁻¹
private theorem norm_unitOf (a : α) : ‖unitOf a‖₊ = 1 := by
rw [unitOf]
split_ifs with h
· simp
· rw [← nnnorm_eq_zero] at h
rw [nnnorm_smul, nnnorm_inv, nnnorm_norm, mul_inv_cancel₀ h]
private theorem mul_unitOf (a : α) : a * unitOf a = algebraMap _ _ (‖a‖₊ : ℝ) := by
simp only [unitOf, coe_nnnorm]
split_ifs with h
· simp [h]
· rw [mul_smul_comm, mul_inv_cancel₀ h, Algebra.algebraMap_eq_smul_one]
end
/-!
For a matrix over a field, the norm defined in this section agrees with the operator norm on
`ContinuousLinearMap`s between function types (which have the infinity norm).
-/
section
variable [NontriviallyNormedField α] [NormedAlgebra ℝ α]
lemma linfty_opNNNorm_eq_opNNNorm (A : Matrix m n α) :
‖A‖₊ = ‖ContinuousLinearMap.mk (Matrix.mulVecLin A)‖₊ := by
rw [ContinuousLinearMap.opNNNorm_eq_of_bounds _ (linfty_opNNNorm_mulVec _) fun N hN => ?_]
rw [linfty_opNNNorm_def]
refine Finset.sup_le fun i _ => ?_
cases isEmpty_or_nonempty n
· simp
classical
let x : n → α := fun j => unitOf (A i j)
have hxn : ‖x‖₊ = 1 := by
simp_rw [x, Pi.nnnorm_def, norm_unitOf, Finset.sup_const Finset.univ_nonempty]
specialize hN x
rw [hxn, mul_one, Pi.nnnorm_def, Finset.sup_le_iff] at hN
replace hN := hN i (Finset.mem_univ _)
dsimp [mulVec, dotProduct] at hN
simp_rw [x, mul_unitOf, ← map_sum, nnnorm_algebraMap, ← NNReal.coe_sum, NNReal.nnnorm_eq,
nnnorm_one, mul_one] at hN
exact hN
lemma linfty_opNorm_eq_opNorm (A : Matrix m n α) :
‖A‖ = ‖ContinuousLinearMap.mk (Matrix.mulVecLin A)‖ :=
congr_arg NNReal.toReal (linfty_opNNNorm_eq_opNNNorm A)
variable [DecidableEq n]
@[simp] lemma linfty_opNNNorm_toMatrix (f : (n → α) →L[α] (m → α)) :
‖LinearMap.toMatrix' (↑f : (n → α) →ₗ[α] (m → α))‖₊ = ‖f‖₊ := by
rw [linfty_opNNNorm_eq_opNNNorm]
simp only [← toLin'_apply', toLin'_toMatrix']
@[simp] lemma linfty_opNorm_toMatrix (f : (n → α) →L[α] (m → α)) :
‖LinearMap.toMatrix' (↑f : (n → α) →ₗ[α] (m → α))‖ = ‖f‖ :=
congr_arg NNReal.toReal (linfty_opNNNorm_toMatrix f)
end
end LinftyOp
/-! ### The Frobenius norm
This is defined as $\|A\| = \sqrt{\sum_{i,j} \|A_{ij}\|^2}$.
When the matrix is over the real or complex numbers, this norm is submultiplicative.
-/
section frobenius
open scoped Matrix
/-- Seminormed group instance (using frobenius norm) for matrices over a seminormed group. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
def frobeniusSeminormedAddCommGroup [SeminormedAddCommGroup α] :
SeminormedAddCommGroup (Matrix m n α) :=
inferInstanceAs (SeminormedAddCommGroup (PiLp 2 fun _i : m => PiLp 2 fun _j : n => α))
/-- Normed group instance (using frobenius norm) for matrices over a normed group. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
def frobeniusNormedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) :=
(by infer_instance : NormedAddCommGroup (PiLp 2 fun i : m => PiLp 2 fun j : n => α))
/-- This applies to the frobenius norm. -/
@[local instance]
theorem frobeniusIsBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α]
[IsBoundedSMul R α] :
IsBoundedSMul R (Matrix m n α) :=
(by infer_instance : IsBoundedSMul R (PiLp 2 fun i : m => PiLp 2 fun j : n => α))
@[deprecated (since := "2025-03-10")] alias frobeniusBoundedSMul := frobeniusIsBoundedSMul
/-- Normed space instance (using frobenius norm) for matrices over a normed space. Not
declared as an instance because there are several natural choices for defining the norm of a
matrix. -/
@[local instance]
def frobeniusNormedSpace [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] :
NormedSpace R (Matrix m n α) :=
(by infer_instance : NormedSpace R (PiLp 2 fun i : m => PiLp 2 fun j : n => α))
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β]
theorem frobenius_nnnorm_def (A : Matrix m n α) :
‖A‖₊ = (∑ i, ∑ j, ‖A i j‖₊ ^ (2 : ℝ)) ^ (1 / 2 : ℝ) := by
-- Porting note: added, along with `WithLp.equiv_symm_pi_apply` below
change ‖(WithLp.equiv 2 _).symm fun i => (WithLp.equiv 2 _).symm fun j => A i j‖₊ = _
simp_rw [PiLp.nnnorm_eq_of_L2, NNReal.sq_sqrt, NNReal.sqrt_eq_rpow, NNReal.rpow_two,
WithLp.equiv_symm_pi_apply]
theorem frobenius_norm_def (A : Matrix m n α) :
‖A‖ = (∑ i, ∑ j, ‖A i j‖ ^ (2 : ℝ)) ^ (1 / 2 : ℝ) :=
(congr_arg ((↑) : ℝ≥0 → ℝ) (frobenius_nnnorm_def A)).trans <| by simp [NNReal.coe_sum]
@[simp]
theorem frobenius_nnnorm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖₊ = ‖a‖₊) :
‖A.map f‖₊ = ‖A‖₊ := by simp_rw [frobenius_nnnorm_def, Matrix.map_apply, hf]
@[simp]
theorem frobenius_norm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖ = ‖a‖) :
‖A.map f‖ = ‖A‖ :=
(congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_map_eq A f fun a => Subtype.ext <| hf a :)
@[simp]
theorem frobenius_nnnorm_transpose (A : Matrix m n α) : ‖Aᵀ‖₊ = ‖A‖₊ := by
rw [frobenius_nnnorm_def, frobenius_nnnorm_def, Finset.sum_comm]
simp_rw [Matrix.transpose_apply]
@[simp]
theorem frobenius_norm_transpose (A : Matrix m n α) : ‖Aᵀ‖ = ‖A‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_transpose A
@[simp]
theorem frobenius_nnnorm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) :
‖Aᴴ‖₊ = ‖A‖₊ :=
(frobenius_nnnorm_map_eq _ _ nnnorm_star).trans A.frobenius_nnnorm_transpose
@[simp]
theorem frobenius_norm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) :
‖Aᴴ‖ = ‖A‖ :=
congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_conjTranspose A
instance frobenius_normedStarGroup [StarAddMonoid α] [NormedStarGroup α] :
NormedStarGroup (Matrix m m α) :=
⟨(le_of_eq <| frobenius_norm_conjTranspose ·)⟩
@[simp]
theorem frobenius_norm_replicateRow (v : m → α) :
‖replicateRow ι v‖ = ‖(WithLp.equiv 2 _).symm v‖ := by
rw [frobenius_norm_def, Fintype.sum_unique, PiLp.norm_eq_of_L2, Real.sqrt_eq_rpow]
simp only [replicateRow_apply, Real.rpow_two, WithLp.equiv_symm_pi_apply]
@[deprecated (since := "2025-03-20")] alias frobenius_norm_row := frobenius_norm_replicateRow
@[simp]
theorem frobenius_nnnorm_replicateRow (v : m → α) :
‖replicateRow ι v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ :=
Subtype.ext <| frobenius_norm_replicateRow v
@[deprecated (since := "2025-03-20")] alias frobenius_nnnorm_row := frobenius_nnnorm_replicateRow
@[simp]
theorem frobenius_norm_replicateCol (v : n → α) :
‖replicateCol ι v‖ = ‖(WithLp.equiv 2 _).symm v‖ := by
simp_rw [frobenius_norm_def, Fintype.sum_unique, PiLp.norm_eq_of_L2, Real.sqrt_eq_rpow]
simp only [replicateCol_apply, Real.rpow_two, WithLp.equiv_symm_pi_apply]
@[deprecated (since := "2025-03-20")] alias frobenius_norm_col := frobenius_norm_replicateCol
@[simp]
theorem frobenius_nnnorm_replicateCol (v : n → α) :
‖replicateCol ι v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ :=
Subtype.ext <| frobenius_norm_replicateCol v
@[deprecated (since := "2025-03-20")] alias frobenius_nnnorm_col := frobenius_nnnorm_replicateCol
@[simp]
| Mathlib/Analysis/Matrix.lean | 573 | 574 | theorem frobenius_nnnorm_diagonal [DecidableEq n] (v : n → α) :
‖diagonal v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ := by | |
/-
Copyright (c) 2022 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction
import Mathlib.Topology.MetricSpace.ThickenedIndicator
/-!
# Spaces where indicators of closed sets have decreasing approximations by continuous functions
In this file we define a typeclass `HasOuterApproxClosed` for topological spaces in which indicator
functions of closed sets have sequences of bounded continuous functions approximating them from
above. All pseudo-emetrizable spaces have this property, see `instHasOuterApproxClosed`.
In spaces with the `HasOuterApproxClosed` property, finite Borel measures are uniquely characterized
by the integrals of bounded continuous functions. Also weak convergence of finite measures and
convergence in distribution for random variables behave somewhat well in spaces with this property.
## Main definitions
* `HasOuterApproxClosed`: the typeclass for topological spaces in which indicator functions of
closed sets have sequences of bounded continuous functions approximating them.
* `IsClosed.apprSeq`: a (non-constructive) choice of an approximating sequence to the indicator
function of a closed set.
## Main results
* `instHasOuterApproxClosed`: Any pseudo-emetrizable space has the property `HasOuterApproxClosed`.
* `tendsto_lintegral_apprSeq`: The integrals of the approximating functions to the indicator of a
closed set tend to the measure of the set.
* `ext_of_forall_lintegral_eq_of_IsFiniteMeasure`: Two finite measures are equal if the integrals
of all bounded continuous functions with respect to both agree.
-/
open BoundedContinuousFunction MeasureTheory Topology Metric Filter Set ENNReal NNReal
open scoped Topology ENNReal NNReal BoundedContinuousFunction
section auxiliary
namespace MeasureTheory
variable {Ω : Type*} [TopologicalSpace Ω] [MeasurableSpace Ω] [OpensMeasurableSpace Ω]
/-- A bounded convergence theorem for a finite measure:
If bounded continuous non-negative functions are uniformly bounded by a constant and tend to a
limit, then their integrals against the finite measure tend to the integral of the limit.
This formulation assumes:
* the functions tend to a limit along a countably generated filter;
* the limit is in the almost everywhere sense;
* boundedness holds almost everywhere;
* integration is `MeasureTheory.lintegral`, i.e., the functions and their integrals are
`ℝ≥0∞`-valued.
-/
| Mathlib/MeasureTheory/Measure/HasOuterApproxClosed.lean | 56 | 65 | theorem tendsto_lintegral_nn_filter_of_le_const {ι : Type*} {L : Filter ι} [L.IsCountablyGenerated]
(μ : Measure Ω) [IsFiniteMeasure μ] {fs : ι → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂μ, fs i ω ≤ c) {f : Ω → ℝ≥0}
(fs_lim : ∀ᵐ ω : Ω ∂μ, Tendsto (fun i ↦ fs i ω) L (𝓝 (f ω))) :
Tendsto (fun i ↦ ∫⁻ ω, fs i ω ∂μ) L (𝓝 (∫⁻ ω, f ω ∂μ)) := by | refine tendsto_lintegral_filter_of_dominated_convergence (fun _ ↦ c)
(Eventually.of_forall fun i ↦ (ENNReal.continuous_coe.comp (fs i).continuous).measurable) ?_
(@lintegral_const_lt_top _ _ μ _ _ (@ENNReal.coe_ne_top c)).ne ?_
· simpa only [Function.comp_apply, ENNReal.coe_le_coe] using fs_le_const
· simpa only [Function.comp_apply, ENNReal.tendsto_coe] using fs_lim |
/-
Copyright (c) 2023 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.Lemmas
/-!
# `compute_degree` and `monicity`: tactics for explicit polynomials
This file defines two related tactics: `compute_degree` and `monicity`.
Using `compute_degree` when the goal is of one of the five forms
* `natDegree f ≤ d`,
* `degree f ≤ d`,
* `natDegree f = d`,
* `degree f = d`,
* `coeff f d = r`, if `d` is the degree of `f`,
tries to solve the goal.
It may leave side-goals, in case it is not entirely successful.
Using `monicity` when the goal is of the form `Monic f` tries to solve the goal.
It may leave side-goals, in case it is not entirely successful.
Both tactics admit a `!` modifier (`compute_degree!` and `monicity!`) instructing
Lean to try harder to close the goal.
See the doc-strings for more details.
## Future work
* Currently, `compute_degree` does not deal correctly with some edge cases. For instance,
```lean
example [Semiring R] : natDegree (C 0 : R[X]) = 0 := by
compute_degree
-- ⊢ 0 ≠ 0
```
Still, it may not be worth to provide special support for `natDegree f = 0`.
* Make sure that numerals in coefficients are treated correctly.
* Make sure that `compute_degree` works with goals of the form `degree f ≤ ↑d`, with an
explicit coercion from `ℕ` on the RHS.
* Add support for proving goals of the from `natDegree f ≠ 0` and `degree f ≠ 0`.
* Make sure that `degree`, `natDegree` and `coeff` are equally supported.
## Implementation details
Assume that `f : R[X]` is a polynomial with coefficients in a semiring `R` and
`d` is either in `ℕ` or in `WithBot ℕ`.
If the goal has the form `natDegree f = d`, then we convert it to three separate goals:
* `natDegree f ≤ d`;
* `coeff f d = r`;
* `r ≠ 0`.
Similarly, an initial goal of the form `degree f = d` gives rise to goals of the form
* `degree f ≤ d`;
* `coeff f d = r`;
* `r ≠ 0`.
Next, we apply successively lemmas whose side-goals all have the shape
* `natDegree f ≤ d`;
* `degree f ≤ d`;
* `coeff f d = r`;
plus possibly "numerical" identities and choices of elements in `ℕ`, `WithBot ℕ`, and `R`.
Recursing into `f`, we break apart additions, multiplications, powers, subtractions,...
The leaves of the process are
* numerals, `C a`, `X` and `monomial a n`, to which we assign degree `0`, `1` and `a` respectively;
* `fvar`s `f`, to which we tautologically assign degree `natDegree f`.
-/
open Polynomial
namespace Mathlib.Tactic.ComputeDegree
section recursion_lemmas
/-!
### Simple lemmas about `natDegree`
The lemmas in this section all have the form `natDegree <some form of cast> ≤ 0`.
Their proofs are weakenings of the stronger lemmas `natDegree <same> = 0`.
These are the lemmas called by `compute_degree` on (almost) all the leaves of its recursion.
-/
variable {R : Type*}
section semiring
variable [Semiring R]
theorem natDegree_C_le (a : R) : natDegree (C a) ≤ 0 := (natDegree_C a).le
theorem natDegree_natCast_le (n : ℕ) : natDegree (n : R[X]) ≤ 0 := (natDegree_natCast _).le
theorem natDegree_zero_le : natDegree (0 : R[X]) ≤ 0 := natDegree_zero.le
theorem natDegree_one_le : natDegree (1 : R[X]) ≤ 0 := natDegree_one.le
theorem coeff_add_of_eq {n : ℕ} {a b : R} {f g : R[X]}
(h_add_left : f.coeff n = a) (h_add_right : g.coeff n = b) :
(f + g).coeff n = a + b := by subst ‹_› ‹_›; apply coeff_add
theorem coeff_mul_add_of_le_natDegree_of_eq_ite {d df dg : ℕ} {a b : R} {f g : R[X]}
(h_mul_left : natDegree f ≤ df) (h_mul_right : natDegree g ≤ dg)
(h_mul_left : f.coeff df = a) (h_mul_right : g.coeff dg = b) (ddf : df + dg ≤ d) :
(f * g).coeff d = if d = df + dg then a * b else 0 := by
split_ifs with h
· subst h_mul_left h_mul_right h
exact coeff_mul_of_natDegree_le ‹_› ‹_›
· apply coeff_eq_zero_of_natDegree_lt
apply lt_of_le_of_lt ?_ (lt_of_le_of_ne ddf ?_)
· exact natDegree_mul_le_of_le ‹_› ‹_›
· exact ne_comm.mp h
theorem coeff_pow_of_natDegree_le_of_eq_ite' {m n o : ℕ} {a : R} {p : R[X]}
(h_pow : natDegree p ≤ n) (h_exp : m * n ≤ o) (h_pow_bas : coeff p n = a) :
coeff (p ^ m) o = if o = m * n then a ^ m else 0 := by
split_ifs with h
· subst h h_pow_bas
exact coeff_pow_of_natDegree_le ‹_›
· apply coeff_eq_zero_of_natDegree_lt
apply lt_of_le_of_lt ?_ (lt_of_le_of_ne ‹_› ?_)
· exact natDegree_pow_le_of_le m ‹_›
· exact Iff.mp ne_comm h
theorem natDegree_smul_le_of_le {n : ℕ} {a : R} {f : R[X]} (hf : natDegree f ≤ n) :
natDegree (a • f) ≤ n :=
(natDegree_smul_le a f).trans hf
theorem degree_smul_le_of_le {n : ℕ} {a : R} {f : R[X]} (hf : degree f ≤ n) :
degree (a • f) ≤ n :=
(degree_smul_le a f).trans hf
theorem coeff_smul {n : ℕ} {a : R} {f : R[X]} : (a • f).coeff n = a * f.coeff n := rfl
section congr_lemmas
/-- The following two lemmas should be viewed as a hand-made "congr"-lemmas.
They achieve the following goals.
* They introduce *two* fresh metavariables replacing the given one `deg`,
one for the `natDegree ≤` computation and one for the `coeff =` computation.
This helps `compute_degree`, since it does not "pre-estimate" the degree,
but it "picks it up along the way".
* They split checking the inequality `coeff p n ≠ 0` into the task of
finding a value `c` for the `coeff` and then
proving that this value is non-zero by `coeff_ne_zero`.
-/
theorem natDegree_eq_of_le_of_coeff_ne_zero' {deg m o : ℕ} {c : R} {p : R[X]}
(h_natDeg_le : natDegree p ≤ m) (coeff_eq : coeff p o = c)
(coeff_ne_zero : c ≠ 0) (deg_eq_deg : m = deg) (coeff_eq_deg : o = deg) :
natDegree p = deg := by
subst coeff_eq deg_eq_deg coeff_eq_deg
exact natDegree_eq_of_le_of_coeff_ne_zero ‹_› ‹_›
theorem degree_eq_of_le_of_coeff_ne_zero' {deg m o : WithBot ℕ} {c : R} {p : R[X]}
(h_deg_le : degree p ≤ m) (coeff_eq : coeff p (WithBot.unbotD 0 deg) = c)
(coeff_ne_zero : c ≠ 0) (deg_eq_deg : m = deg) (coeff_eq_deg : o = deg) :
degree p = deg := by
subst coeff_eq coeff_eq_deg deg_eq_deg
rcases eq_or_ne m ⊥ with rfl|hh
· exact bot_unique h_deg_le
· obtain ⟨m, rfl⟩ := WithBot.ne_bot_iff_exists.mp hh
exact degree_eq_of_le_of_coeff_ne_zero ‹_› ‹_›
variable {m n : ℕ} {f : R[X]} {r : R}
theorem coeff_congr_lhs (h : coeff f m = r) (natDeg_eq_coeff : m = n) : coeff f n = r :=
natDeg_eq_coeff ▸ h
theorem coeff_congr (h : coeff f m = r) (natDeg_eq_coeff : m = n) {s : R} (rs : r = s) :
coeff f n = s :=
natDeg_eq_coeff ▸ rs ▸ h
end congr_lemmas
end semiring
section ring
variable [Ring R]
theorem natDegree_intCast_le (n : ℤ) : natDegree (n : R[X]) ≤ 0 := (natDegree_intCast _).le
theorem coeff_sub_of_eq {n : ℕ} {a b : R} {f g : R[X]} (hf : f.coeff n = a) (hg : g.coeff n = b) :
(f - g).coeff n = a - b := by subst hf hg; apply coeff_sub
| Mathlib/Tactic/ComputeDegree.lean | 184 | 185 | theorem coeff_intCast_ite {n : ℕ} {a : ℤ} : (Int.cast a : R[X]).coeff n = ite (n = 0) a 0 := by | simp only [← C_eq_intCast, coeff_C, Int.cast_ite, Int.cast_zero] |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Real
/-!
# Properties of addition, multiplication and subtraction on extended non-negative real numbers
In this file we prove elementary properties of algebraic operations on `ℝ≥0∞`, including addition,
multiplication, natural powers and truncated subtraction, as well as how these interact with the
order structure on `ℝ≥0∞`. Notably excluded from this list are inversion and division, the
definitions and properties of which can be found in `Mathlib.Data.ENNReal.Inv`.
Note: the definitions of the operations included in this file can be found in
`Mathlib.Data.ENNReal.Basic`.
-/
assert_not_exists Finset
open Set NNReal ENNReal
namespace ENNReal
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
section Mul
@[mono, gcongr]
theorem mul_lt_mul (ac : a < c) (bd : b < d) : a * b < c * d := WithTop.mul_lt_mul ac bd
protected lemma pow_right_strictMono {n : ℕ} (hn : n ≠ 0) : StrictMono fun a : ℝ≥0∞ ↦ a ^ n :=
WithTop.pow_right_strictMono hn
@[gcongr] protected lemma pow_lt_pow_left (hab : a < b) {n : ℕ} (hn : n ≠ 0) : a ^ n < b ^ n :=
WithTop.pow_lt_pow_left hab hn
-- TODO: generalize to `WithTop`
theorem mul_left_strictMono (h0 : a ≠ 0) (hinf : a ≠ ∞) : StrictMono (a * ·) := by
lift a to ℝ≥0 using hinf
rw [coe_ne_zero] at h0
intro x y h
contrapose! h
simpa only [← mul_assoc, ← coe_mul, inv_mul_cancel₀ h0, coe_one, one_mul]
using mul_le_mul_left' h (↑a⁻¹)
@[gcongr] protected theorem mul_lt_mul_left' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) :
a * b < a * c :=
ENNReal.mul_left_strictMono h0 hinf bc
@[gcongr] protected theorem mul_lt_mul_right' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) :
b * a < c * a :=
mul_comm b a ▸ mul_comm c a ▸ ENNReal.mul_left_strictMono h0 hinf bc
-- TODO: generalize to `WithTop`
protected theorem mul_right_inj (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b = a * c ↔ b = c :=
(mul_left_strictMono h0 hinf).injective.eq_iff
@[deprecated (since := "2025-01-20")]
alias mul_eq_mul_left := ENNReal.mul_right_inj
-- TODO: generalize to `WithTop`
protected theorem mul_left_inj (h0 : c ≠ 0) (hinf : c ≠ ∞) : a * c = b * c ↔ a = b :=
mul_comm c a ▸ mul_comm c b ▸ ENNReal.mul_right_inj h0 hinf
@[deprecated (since := "2025-01-20")]
alias mul_eq_mul_right := ENNReal.mul_left_inj
-- TODO: generalize to `WithTop`
theorem mul_le_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b ≤ a * c ↔ b ≤ c :=
(mul_left_strictMono h0 hinf).le_iff_le
-- TODO: generalize to `WithTop`
theorem mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left
-- TODO: generalize to `WithTop`
theorem mul_lt_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b < a * c ↔ b < c :=
(mul_left_strictMono h0 hinf).lt_iff_lt
-- TODO: generalize to `WithTop`
theorem mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left
protected lemma mul_eq_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * b = a ↔ b = 1 := by
simpa using ENNReal.mul_right_inj ha₀ ha (c := 1)
protected lemma mul_eq_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b = b ↔ a = 1 := by
simpa using ENNReal.mul_left_inj hb₀ hb (b := 1)
end Mul
section OperationsAndOrder
protected theorem pow_pos : 0 < a → ∀ n : ℕ, 0 < a ^ n :=
CanonicallyOrderedAdd.pow_pos
protected theorem pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a ^ n ≠ 0 := by
simpa only [pos_iff_ne_zero] using ENNReal.pow_pos
theorem not_lt_zero : ¬a < 0 := by simp
protected theorem le_of_add_le_add_left : a ≠ ∞ → a + b ≤ a + c → b ≤ c :=
WithTop.le_of_add_le_add_left
protected theorem le_of_add_le_add_right : a ≠ ∞ → b + a ≤ c + a → b ≤ c :=
WithTop.le_of_add_le_add_right
@[gcongr] protected theorem add_lt_add_left : a ≠ ∞ → b < c → a + b < a + c :=
WithTop.add_lt_add_left
@[gcongr] protected theorem add_lt_add_right : a ≠ ∞ → b < c → b + a < c + a :=
WithTop.add_lt_add_right
protected theorem add_le_add_iff_left : a ≠ ∞ → (a + b ≤ a + c ↔ b ≤ c) :=
WithTop.add_le_add_iff_left
protected theorem add_le_add_iff_right : a ≠ ∞ → (b + a ≤ c + a ↔ b ≤ c) :=
WithTop.add_le_add_iff_right
protected theorem add_lt_add_iff_left : a ≠ ∞ → (a + b < a + c ↔ b < c) :=
WithTop.add_lt_add_iff_left
protected theorem add_lt_add_iff_right : a ≠ ∞ → (b + a < c + a ↔ b < c) :=
WithTop.add_lt_add_iff_right
protected theorem add_lt_add_of_le_of_lt : a ≠ ∞ → a ≤ b → c < d → a + c < b + d :=
WithTop.add_lt_add_of_le_of_lt
protected theorem add_lt_add_of_lt_of_le : c ≠ ∞ → a < b → c ≤ d → a + c < b + d :=
WithTop.add_lt_add_of_lt_of_le
instance addLeftReflectLT : AddLeftReflectLT ℝ≥0∞ :=
WithTop.addLeftReflectLT
theorem lt_add_right (ha : a ≠ ∞) (hb : b ≠ 0) : a < a + b := by
rwa [← pos_iff_ne_zero, ← ENNReal.add_lt_add_iff_left ha, add_zero] at hb
end OperationsAndOrder
section OperationsAndInfty
variable {α : Type*} {n : ℕ}
@[simp] theorem add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := WithTop.add_eq_top
@[simp] theorem add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := WithTop.add_lt_top
theorem toNNReal_add {r₁ r₂ : ℝ≥0∞} (h₁ : r₁ ≠ ∞) (h₂ : r₂ ≠ ∞) :
(r₁ + r₂).toNNReal = r₁.toNNReal + r₂.toNNReal := by
lift r₁ to ℝ≥0 using h₁
lift r₂ to ℝ≥0 using h₂
rfl
/-- If `a ≤ b + c` and `a = ∞` whenever `b = ∞` or `c = ∞`, then
`ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer
triangle-like inequalities from `ENNReal`s to `Real`s. -/
theorem toReal_le_add' (hle : a ≤ b + c) (hb : b = ∞ → a = ∞) (hc : c = ∞ → a = ∞) :
a.toReal ≤ b.toReal + c.toReal := by
refine le_trans (toReal_mono' hle ?_) toReal_add_le
simpa only [add_eq_top, or_imp] using And.intro hb hc
/-- If `a ≤ b + c`, `b ≠ ∞`, and `c ≠ ∞`, then
`ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer
triangle-like inequalities from `ENNReal`s to `Real`s. -/
theorem toReal_le_add (hle : a ≤ b + c) (hb : b ≠ ∞) (hc : c ≠ ∞) :
a.toReal ≤ b.toReal + c.toReal :=
toReal_le_add' hle (flip absurd hb) (flip absurd hc)
theorem not_lt_top {x : ℝ≥0∞} : ¬x < ∞ ↔ x = ∞ := by rw [lt_top_iff_ne_top, Classical.not_not]
theorem add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using add_lt_top
@[aesop (rule_sets := [finiteness]) safe apply]
protected lemma Finiteness.add_ne_top {a b : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≠ ∞) : a + b ≠ ∞ :=
ENNReal.add_ne_top.2 ⟨ha, hb⟩
theorem mul_top' : a * ∞ = if a = 0 then 0 else ∞ := by convert WithTop.mul_top' a
@[simp] theorem mul_top (h : a ≠ 0) : a * ∞ = ∞ := WithTop.mul_top h
theorem top_mul' : ∞ * a = if a = 0 then 0 else ∞ := by convert WithTop.top_mul' a
@[simp] theorem top_mul (h : a ≠ 0) : ∞ * a = ∞ := WithTop.top_mul h
theorem top_mul_top : ∞ * ∞ = ∞ := WithTop.top_mul_top
theorem mul_eq_top : a * b = ∞ ↔ a ≠ 0 ∧ b = ∞ ∨ a = ∞ ∧ b ≠ 0 :=
WithTop.mul_eq_top_iff
theorem mul_lt_top : a < ∞ → b < ∞ → a * b < ∞ := WithTop.mul_lt_top
-- This is unsafe because we could have `a = ∞` and `b = 0` or vice-versa
@[aesop (rule_sets := [finiteness]) unsafe 75% apply]
theorem mul_ne_top : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ := WithTop.mul_ne_top
theorem lt_top_of_mul_ne_top_left (h : a * b ≠ ∞) (hb : b ≠ 0) : a < ∞ :=
lt_top_iff_ne_top.2 fun ha => h <| mul_eq_top.2 (Or.inr ⟨ha, hb⟩)
theorem lt_top_of_mul_ne_top_right (h : a * b ≠ ∞) (ha : a ≠ 0) : b < ∞ :=
lt_top_of_mul_ne_top_left (by rwa [mul_comm]) ha
theorem mul_lt_top_iff {a b : ℝ≥0∞} : a * b < ∞ ↔ a < ∞ ∧ b < ∞ ∨ a = 0 ∨ b = 0 := by
constructor
· intro h
rw [← or_assoc, or_iff_not_imp_right, or_iff_not_imp_right]
intro hb ha
exact ⟨lt_top_of_mul_ne_top_left h.ne hb, lt_top_of_mul_ne_top_right h.ne ha⟩
· rintro (⟨ha, hb⟩ | rfl | rfl) <;> [exact mul_lt_top ha hb; simp; simp]
| Mathlib/Data/ENNReal/Operations.lean | 212 | 212 | theorem mul_self_lt_top_iff {a : ℝ≥0∞} : a * a < ⊤ ↔ a < ⊤ := by | |
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Data.List.Rotate
import Mathlib.GroupTheory.Perm.Support
/-!
# Permutations from a list
A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list
is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`,
we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that
`formPerm l` is rotationally invariant, in `formPerm_rotate`.
When there are duplicate elements in `l`, how and in what arrangement with respect to the other
elements they appear in the list determines the formed permutation.
This is because `List.formPerm` is implemented as a product of `Equiv.swap`s.
That means that presence of a sublist of two adjacent duplicates like `[..., x, x, ...]`
will produce the same permutation as if the adjacent duplicates were not present.
The `List.formPerm` definition is meant to primarily be used with `Nodup l`, so that
the resulting permutation is cyclic (if `l` has at least two elements).
The presence of duplicates in a particular placement can lead `List.formPerm` to produce a
nontrivial permutation that is noncyclic.
-/
namespace List
variable {α β : Type*}
section FormPerm
variable [DecidableEq α] (l : List α)
open Equiv Equiv.Perm
/-- A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list
is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`,
we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that
`formPerm l` is rotationally invariant, in `formPerm_rotate`.
-/
def formPerm : Equiv.Perm α :=
(zipWith Equiv.swap l l.tail).prod
@[simp]
theorem formPerm_nil : formPerm ([] : List α) = 1 :=
rfl
@[simp]
theorem formPerm_singleton (x : α) : formPerm [x] = 1 :=
rfl
@[simp]
theorem formPerm_cons_cons (x y : α) (l : List α) :
formPerm (x :: y :: l) = swap x y * formPerm (y :: l) :=
prod_cons
theorem formPerm_pair (x y : α) : formPerm [x, y] = swap x y :=
rfl
theorem mem_or_mem_of_zipWith_swap_prod_ne : ∀ {l l' : List α} {x : α},
(zipWith swap l l').prod x ≠ x → x ∈ l ∨ x ∈ l'
| [], _, _ => by simp
| _, [], _ => by simp
| a::l, b::l', x => fun hx ↦
if h : (zipWith swap l l').prod x = x then
(eq_or_eq_of_swap_apply_ne_self (a := a) (b := b) (x := x) (by simpa [h] using hx)).imp
(by rintro rfl; exact .head _) (by rintro rfl; exact .head _)
else
(mem_or_mem_of_zipWith_swap_prod_ne h).imp (.tail _) (.tail _)
theorem zipWith_swap_prod_support' (l l' : List α) :
{ x | (zipWith swap l l').prod x ≠ x } ≤ l.toFinset ⊔ l'.toFinset := fun _ h ↦ by
simpa using mem_or_mem_of_zipWith_swap_prod_ne h
theorem zipWith_swap_prod_support [Fintype α] (l l' : List α) :
(zipWith swap l l').prod.support ≤ l.toFinset ⊔ l'.toFinset := by
intro x hx
have hx' : x ∈ { x | (zipWith swap l l').prod x ≠ x } := by simpa using hx
simpa using zipWith_swap_prod_support' _ _ hx'
theorem support_formPerm_le' : { x | formPerm l x ≠ x } ≤ l.toFinset := by
refine (zipWith_swap_prod_support' l l.tail).trans ?_
simpa [Finset.subset_iff] using tail_subset l
theorem support_formPerm_le [Fintype α] : support (formPerm l) ≤ l.toFinset := by
intro x hx
have hx' : x ∈ { x | formPerm l x ≠ x } := by simpa using hx
simpa using support_formPerm_le' _ hx'
variable {l} {x : α}
theorem mem_of_formPerm_apply_ne (h : l.formPerm x ≠ x) : x ∈ l := by
simpa [or_iff_left_of_imp mem_of_mem_tail] using mem_or_mem_of_zipWith_swap_prod_ne h
theorem formPerm_apply_of_not_mem (h : x ∉ l) : formPerm l x = x :=
not_imp_comm.1 mem_of_formPerm_apply_ne h
theorem formPerm_apply_mem_of_mem (h : x ∈ l) : formPerm l x ∈ l := by
rcases l with - | ⟨y, l⟩
· simp at h
induction' l with z l IH generalizing x y
· simpa using h
· by_cases hx : x ∈ z :: l
· rw [formPerm_cons_cons, mul_apply, swap_apply_def]
split_ifs
· simp [IH _ hx]
· simp
· simp [*]
· replace h : x = y := Or.resolve_right (mem_cons.1 h) hx
simp [formPerm_apply_of_not_mem hx, ← h]
theorem mem_of_formPerm_apply_mem (h : l.formPerm x ∈ l) : x ∈ l := by
contrapose h
rwa [formPerm_apply_of_not_mem h]
@[simp]
theorem formPerm_mem_iff_mem : l.formPerm x ∈ l ↔ x ∈ l :=
⟨l.mem_of_formPerm_apply_mem, l.formPerm_apply_mem_of_mem⟩
@[simp]
theorem formPerm_cons_concat_apply_last (x y : α) (xs : List α) :
formPerm (x :: (xs ++ [y])) y = x := by
induction' xs with z xs IH generalizing x y
· simp
· simp [IH]
@[simp]
theorem formPerm_apply_getLast (x : α) (xs : List α) :
formPerm (x :: xs) ((x :: xs).getLast (cons_ne_nil x xs)) = x := by
induction' xs using List.reverseRecOn with xs y _ generalizing x <;> simp
@[simp]
theorem formPerm_apply_getElem_length (x : α) (xs : List α) :
formPerm (x :: xs) (x :: xs)[xs.length] = x := by
rw [getElem_cons_length rfl, formPerm_apply_getLast]
theorem formPerm_apply_head (x y : α) (xs : List α) (h : Nodup (x :: y :: xs)) :
formPerm (x :: y :: xs) x = y := by simp [formPerm_apply_of_not_mem h.not_mem]
theorem formPerm_apply_getElem_zero (l : List α) (h : Nodup l) (hl : 1 < l.length) :
formPerm l l[0] = l[1] := by
rcases l with (_ | ⟨x, _ | ⟨y, tl⟩⟩)
· simp at hl
· simp at hl
· rw [getElem_cons_zero, formPerm_apply_head _ _ _ h, getElem_cons_succ, getElem_cons_zero]
variable (l)
theorem formPerm_eq_head_iff_eq_getLast (x y : α) :
formPerm (y :: l) x = y ↔ x = getLast (y :: l) (cons_ne_nil _ _) :=
Iff.trans (by rw [formPerm_apply_getLast]) (formPerm (y :: l)).injective.eq_iff
theorem formPerm_apply_lt_getElem (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n + 1 < xs.length) :
formPerm xs xs[n] = xs[n + 1] := by
induction' n with n IH generalizing xs
· simpa using formPerm_apply_getElem_zero _ h _
· rcases xs with (_ | ⟨x, _ | ⟨y, l⟩⟩)
· simp at hn
· rw [formPerm_singleton, getElem_singleton, getElem_singleton, one_apply]
· specialize IH (y :: l) h.of_cons _
· simpa [Nat.succ_lt_succ_iff] using hn
simp only [swap_apply_eq_iff, coe_mul, formPerm_cons_cons, Function.comp]
simp only [getElem_cons_succ] at *
rw [← IH, swap_apply_of_ne_of_ne] <;>
· intro hx
rw [← hx, IH] at h
simp [getElem_mem] at h
theorem formPerm_apply_getElem (xs : List α) (w : Nodup xs) (i : ℕ) (h : i < xs.length) :
formPerm xs xs[i] =
xs[(i + 1) % xs.length]'(Nat.mod_lt _ (i.zero_le.trans_lt h)) := by
rcases xs with - | ⟨x, xs⟩
· simp at h
· have : i ≤ xs.length := by
refine Nat.le_of_lt_succ ?_
simpa using h
rcases this.eq_or_lt with (rfl | hn')
· simp
· rw [formPerm_apply_lt_getElem (x :: xs) w _ (Nat.succ_lt_succ hn')]
congr
rw [Nat.mod_eq_of_lt]; simpa [Nat.succ_eq_add_one]
theorem support_formPerm_of_nodup' (l : List α) (h : Nodup l) (h' : ∀ x : α, l ≠ [x]) :
{ x | formPerm l x ≠ x } = l.toFinset := by
apply _root_.le_antisymm
· exact support_formPerm_le' l
· intro x hx
simp only [Finset.mem_coe, mem_toFinset] at hx
obtain ⟨n, hn, rfl⟩ := getElem_of_mem hx
rw [Set.mem_setOf_eq, formPerm_apply_getElem _ h]
intro H
rw [nodup_iff_injective_get, Function.Injective] at h
specialize h H
rcases (Nat.succ_le_of_lt hn).eq_or_lt with hn' | hn'
· simp only [← hn', Nat.mod_self] at h
refine not_exists.mpr h' ?_
rw [← length_eq_one_iff, ← hn', (Fin.mk.inj_iff.mp h).symm]
· simp [Nat.mod_eq_of_lt hn'] at h
theorem support_formPerm_of_nodup [Fintype α] (l : List α) (h : Nodup l) (h' : ∀ x : α, l ≠ [x]) :
support (formPerm l) = l.toFinset := by
rw [← Finset.coe_inj]
convert support_formPerm_of_nodup' _ h h'
simp [Set.ext_iff]
theorem formPerm_rotate_one (l : List α) (h : Nodup l) : formPerm (l.rotate 1) = formPerm l := by
have h' : Nodup (l.rotate 1) := by simpa using h
ext x
by_cases hx : x ∈ l.rotate 1
· obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx
rw [formPerm_apply_getElem _ h', getElem_rotate l, getElem_rotate l, formPerm_apply_getElem _ h]
simp
· rw [formPerm_apply_of_not_mem hx, formPerm_apply_of_not_mem]
simpa using hx
theorem formPerm_rotate (l : List α) (h : Nodup l) (n : ℕ) :
formPerm (l.rotate n) = formPerm l := by
induction n with
| zero => simp
| succ n hn =>
rw [← rotate_rotate, formPerm_rotate_one, hn]
rwa [IsRotated.nodup_iff]
exact IsRotated.forall l n
theorem formPerm_eq_of_isRotated {l l' : List α} (hd : Nodup l) (h : l ~r l') :
formPerm l = formPerm l' := by
obtain ⟨n, rfl⟩ := h
exact (formPerm_rotate l hd n).symm
theorem formPerm_append_pair : ∀ (l : List α) (a b : α),
formPerm (l ++ [a, b]) = formPerm (l ++ [a]) * swap a b
| [], _, _ => rfl
| [_], _, _ => rfl
| x::y::l, a, b => by
simpa [mul_assoc] using formPerm_append_pair (y::l) a b
theorem formPerm_reverse : ∀ l : List α, formPerm l.reverse = (formPerm l)⁻¹
| [] => rfl
| [_] => rfl
| a::b::l => by
simp [formPerm_append_pair, swap_comm, ← formPerm_reverse (b::l)]
theorem formPerm_pow_apply_getElem (l : List α) (w : Nodup l) (n : ℕ) (i : ℕ) (h : i < l.length) :
(formPerm l ^ n) l[i] =
l[(i + n) % l.length]'(Nat.mod_lt _ (i.zero_le.trans_lt h)) := by
induction n with
| zero => simp [Nat.mod_eq_of_lt h]
| succ n hn =>
simp [pow_succ', mul_apply, hn, formPerm_apply_getElem _ w, Nat.succ_eq_add_one,
← Nat.add_assoc]
theorem formPerm_pow_apply_head (x : α) (l : List α) (h : Nodup (x :: l)) (n : ℕ) :
(formPerm (x :: l) ^ n) x =
(x :: l)[(n % (x :: l).length)]'(Nat.mod_lt _ (Nat.zero_lt_succ _)) := by
convert formPerm_pow_apply_getElem _ h n 0 (Nat.succ_pos _)
simp
theorem formPerm_ext_iff {x y x' y' : α} {l l' : List α} (hd : Nodup (x :: y :: l))
(hd' : Nodup (x' :: y' :: l')) :
formPerm (x :: y :: l) = formPerm (x' :: y' :: l') ↔ (x :: y :: l) ~r (x' :: y' :: l') := by
refine ⟨fun h => ?_, fun hr => formPerm_eq_of_isRotated hd hr⟩
rw [Equiv.Perm.ext_iff] at h
have hx : x' ∈ x :: y :: l := by
have : x' ∈ { z | formPerm (x :: y :: l) z ≠ z } := by
rw [Set.mem_setOf_eq, h x', formPerm_apply_head _ _ _ hd']
simp only [mem_cons, nodup_cons] at hd'
push_neg at hd'
exact hd'.left.left.symm
simpa using support_formPerm_le' _ this
obtain ⟨⟨n, hn⟩, hx'⟩ := get_of_mem hx
have hl : (x :: y :: l).length = (x' :: y' :: l').length := by
rw [← dedup_eq_self.mpr hd, ← dedup_eq_self.mpr hd', ← card_toFinset, ← card_toFinset]
refine congr_arg Finset.card ?_
rw [← Finset.coe_inj, ← support_formPerm_of_nodup' _ hd (by simp), ←
support_formPerm_of_nodup' _ hd' (by simp)]
simp only [h]
use n
apply List.ext_getElem
· rw [length_rotate, hl]
· intro k hk hk'
rw [getElem_rotate]
induction' k with k IH
· refine Eq.trans ?_ hx'
congr
simpa using hn
· conv => congr <;> · arg 2; (rw [← Nat.mod_eq_of_lt hk'])
rw [← formPerm_apply_getElem _ hd' k (k.lt_succ_self.trans hk'),
← IH (k.lt_succ_self.trans hk), ← h, formPerm_apply_getElem _ hd]
congr 1
rw [hl, Nat.mod_eq_of_lt hk', add_right_comm]
apply Nat.add_mod
theorem formPerm_apply_mem_eq_self_iff (hl : Nodup l) (x : α) (hx : x ∈ l) :
formPerm l x = x ↔ length l ≤ 1 := by
obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx
rw [formPerm_apply_getElem _ hl k hk, hl.getElem_inj_iff]
cases hn : l.length
· exact absurd k.zero_le (hk.trans_le hn.le).not_le
· rw [hn] at hk
rcases (Nat.le_of_lt_succ hk).eq_or_lt with hk' | hk'
· simp [← hk', Nat.succ_le_succ_iff, eq_comm]
· simpa [Nat.mod_eq_of_lt (Nat.succ_lt_succ hk'), Nat.succ_lt_succ_iff] using
(k.zero_le.trans_lt hk').ne.symm
theorem formPerm_apply_mem_ne_self_iff (hl : Nodup l) (x : α) (hx : x ∈ l) :
formPerm l x ≠ x ↔ 2 ≤ l.length := by
rw [Ne, formPerm_apply_mem_eq_self_iff _ hl x hx, not_le]
exact ⟨Nat.succ_le_of_lt, Nat.lt_of_succ_le⟩
| Mathlib/GroupTheory/Perm/List.lean | 315 | 319 | theorem mem_of_formPerm_ne_self (l : List α) (x : α) (h : formPerm l x ≠ x) : x ∈ l := by | suffices x ∈ { y | formPerm l y ≠ y } by
rw [← mem_toFinset]
exact support_formPerm_le' _ this
simpa using h |
/-
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
import Mathlib.Topology.Instances.ZMultiples
/-!
# 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 [AddCommGroup 𝕜] [LinearOrder 𝕜] [IsOrderedAddMonoid 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜]
{p : 𝕜} (hp : 0 < p) (a x : 𝕜)
| Mathlib/Topology/Instances/AddCircle.lean | 64 | 79 | 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⟩] |
/-
Copyright (c) 2022 Dylan MacKenzie. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dylan MacKenzie
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.Module.Defs
import Mathlib.Tactic.Abel
/-!
# Summation by parts
-/
namespace Finset
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] (f : ℕ → R) (g : ℕ → M) {m n : ℕ}
-- The partial sum of `g`, starting from zero
local notation "G " n:80 => ∑ i ∈ range n, g i
/-- **Summation by parts**, also known as **Abel's lemma** or an **Abel transformation** -/
| Mathlib/Algebra/BigOperators/Module.lean | 21 | 57 | theorem sum_Ico_by_parts (hmn : m < n) :
∑ i ∈ Ico m n, f i • g i =
f (n - 1) • G n - f m • G m - ∑ i ∈ Ico m (n - 1), (f (i + 1) - f i) • G (i + 1) := by | have h₁ : (∑ i ∈ Ico (m + 1) n, f i • G i) = ∑ i ∈ Ico m (n - 1), f (i + 1) • G (i + 1) := by
rw [← Nat.sub_add_cancel (Nat.one_le_of_lt hmn), ← sum_Ico_add']
simp only [tsub_le_iff_right, add_le_iff_nonpos_left, nonpos_iff_eq_zero,
tsub_eq_zero_iff_le, add_tsub_cancel_right]
have h₂ :
(∑ i ∈ Ico (m + 1) n, f i • G (i + 1)) =
(∑ i ∈ Ico m (n - 1), f i • G (i + 1)) + f (n - 1) • G n - f m • G (m + 1) := by
rw [← sum_Ico_sub_bot _ hmn, ← sum_Ico_succ_sub_top _ (Nat.le_sub_one_of_lt hmn),
Nat.sub_add_cancel (pos_of_gt hmn), sub_add_cancel]
rw [sum_eq_sum_Ico_succ_bot hmn]
conv in (occs := 3) (f _ • g _) => rw [← sum_range_succ_sub_sum g]
simp_rw [smul_sub, sum_sub_distrib, h₂, h₁]
conv_lhs => congr; rfl; rw [← add_sub, add_comm, ← add_sub, ← sum_sub_distrib]
have : ∀ i, f i • G (i + 1) - f (i + 1) • G (i + 1) = -((f (i + 1) - f i) • G (i + 1)) := by
intro i
rw [sub_smul]
abel
simp_rw [this, sum_neg_distrib, sum_range_succ, smul_add]
abel
theorem sum_Ioc_by_parts (hmn : m < n) :
∑ i ∈ Ioc m n, f i • g i =
f n • G (n + 1) - f (m + 1) • G (m + 1)
- ∑ i ∈ Ioc m (n - 1), (f (i + 1) - f i) • G (i + 1) := by
simpa only [← Nat.Ico_succ_succ, Nat.succ_eq_add_one, Nat.sub_add_cancel (Nat.one_le_of_lt hmn),
add_tsub_cancel_right] using sum_Ico_by_parts f g (Nat.succ_lt_succ hmn)
variable (n)
/-- **Summation by parts** for ranges -/
theorem sum_range_by_parts :
∑ i ∈ range n, f i • g i =
f (n - 1) • G n - ∑ i ∈ range (n - 1), (f (i + 1) - f i) • G (i + 1) := by
by_cases hn : n = 0 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Neil Strickland
-/
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.PNat.Basic
/-!
# Primality and GCD on pnat
This file extends the theory of `ℕ+` with `gcd`, `lcm` and `Prime` functions, analogous to those on
`Nat`.
-/
namespace Nat.Primes
/-- The canonical map from `Nat.Primes` to `ℕ+` -/
@[coe] def toPNat : Nat.Primes → ℕ+ :=
fun p => ⟨(p : ℕ), p.property.pos⟩
instance coePNat : Coe Nat.Primes ℕ+ :=
⟨toPNat⟩
@[norm_cast]
theorem coe_pnat_nat (p : Nat.Primes) : ((p : ℕ+) : ℕ) = p :=
rfl
theorem coe_pnat_injective : Function.Injective ((↑) : Nat.Primes → ℕ+) := fun p q h =>
Subtype.ext (by injection h)
@[norm_cast]
theorem coe_pnat_inj (p q : Nat.Primes) : (p : ℕ+) = (q : ℕ+) ↔ p = q :=
coe_pnat_injective.eq_iff
end Nat.Primes
namespace PNat
open Nat
/-- The greatest common divisor (gcd) of two positive natural numbers,
viewed as positive natural number. -/
def gcd (n m : ℕ+) : ℕ+ :=
⟨Nat.gcd (n : ℕ) (m : ℕ), Nat.gcd_pos_of_pos_left (m : ℕ) n.pos⟩
/-- The least common multiple (lcm) of two positive natural numbers,
viewed as positive natural number. -/
def lcm (n m : ℕ+) : ℕ+ :=
⟨Nat.lcm (n : ℕ) (m : ℕ), by
let h := mul_pos n.pos m.pos
rw [← gcd_mul_lcm (n : ℕ) (m : ℕ), mul_comm] at h
exact pos_of_dvd_of_pos (Dvd.intro (Nat.gcd (n : ℕ) (m : ℕ)) rfl) h⟩
@[simp, norm_cast]
theorem gcd_coe (n m : ℕ+) : (gcd n m : ℕ) = Nat.gcd n m :=
rfl
@[simp, norm_cast]
theorem lcm_coe (n m : ℕ+) : (lcm n m : ℕ) = Nat.lcm n m :=
rfl
theorem gcd_dvd_left (n m : ℕ+) : gcd n m ∣ n :=
dvd_iff.2 (Nat.gcd_dvd_left (n : ℕ) (m : ℕ))
theorem gcd_dvd_right (n m : ℕ+) : gcd n m ∣ m :=
dvd_iff.2 (Nat.gcd_dvd_right (n : ℕ) (m : ℕ))
theorem dvd_gcd {m n k : ℕ+} (hm : k ∣ m) (hn : k ∣ n) : k ∣ gcd m n :=
dvd_iff.2 (Nat.dvd_gcd (dvd_iff.1 hm) (dvd_iff.1 hn))
theorem dvd_lcm_left (n m : ℕ+) : n ∣ lcm n m :=
dvd_iff.2 (Nat.dvd_lcm_left (n : ℕ) (m : ℕ))
theorem dvd_lcm_right (n m : ℕ+) : m ∣ lcm n m :=
dvd_iff.2 (Nat.dvd_lcm_right (n : ℕ) (m : ℕ))
theorem lcm_dvd {m n k : ℕ+} (hm : m ∣ k) (hn : n ∣ k) : lcm m n ∣ k :=
dvd_iff.2 (@Nat.lcm_dvd (m : ℕ) (n : ℕ) (k : ℕ) (dvd_iff.1 hm) (dvd_iff.1 hn))
theorem gcd_mul_lcm (n m : ℕ+) : gcd n m * lcm n m = n * m :=
Subtype.eq (Nat.gcd_mul_lcm (n : ℕ) (m : ℕ))
theorem eq_one_of_lt_two {n : ℕ+} : n < 2 → n = 1 := by
intro h; apply le_antisymm; swap
· apply PNat.one_le
· exact PNat.lt_add_one_iff.1 h
section Prime
/-! ### Prime numbers -/
/-- Primality predicate for `ℕ+`, defined in terms of `Nat.Prime`. -/
def Prime (p : ℕ+) : Prop :=
(p : ℕ).Prime
theorem Prime.one_lt {p : ℕ+} : p.Prime → 1 < p :=
Nat.Prime.one_lt
theorem prime_two : (2 : ℕ+).Prime :=
Nat.prime_two
instance {p : ℕ+} [h : Fact p.Prime] : Fact (p : ℕ).Prime := h
instance fact_prime_two : Fact (2 : ℕ+).Prime :=
⟨prime_two⟩
theorem prime_three : (3 : ℕ+).Prime :=
Nat.prime_three
instance fact_prime_three : Fact (3 : ℕ+).Prime :=
⟨prime_three⟩
theorem prime_five : (5 : ℕ+).Prime :=
Nat.prime_five
instance fact_prime_five : Fact (5 : ℕ+).Prime :=
⟨prime_five⟩
theorem dvd_prime {p m : ℕ+} (pp : p.Prime) : m ∣ p ↔ m = 1 ∨ m = p := by
rw [PNat.dvd_iff]
rw [Nat.dvd_prime pp]
simp
theorem Prime.ne_one {p : ℕ+} : p.Prime → p ≠ 1 := by
intro pp
intro contra
apply Nat.Prime.ne_one pp
rw [PNat.coe_eq_one_iff]
apply contra
@[simp]
theorem not_prime_one : ¬(1 : ℕ+).Prime :=
Nat.not_prime_one
theorem Prime.not_dvd_one {p : ℕ+} : p.Prime → ¬p ∣ 1 := fun pp : p.Prime => by
rw [dvd_iff]
apply Nat.Prime.not_dvd_one pp
theorem exists_prime_and_dvd {n : ℕ+} (hn : n ≠ 1) : ∃ p : ℕ+, p.Prime ∧ p ∣ n := by
obtain ⟨p, hp⟩ := Nat.exists_prime_and_dvd (mt coe_eq_one_iff.mp hn)
exists (⟨p, Nat.Prime.pos hp.left⟩ : ℕ+); rw [dvd_iff]; apply hp
end Prime
section Coprime
/-! ### Coprime numbers and gcd -/
/-- Two pnats are coprime if their gcd is 1. -/
def Coprime (m n : ℕ+) : Prop :=
m.gcd n = 1
@[simp, norm_cast]
theorem coprime_coe {m n : ℕ+} : Nat.Coprime ↑m ↑n ↔ m.Coprime n := by
unfold Nat.Coprime Coprime
rw [← coe_inj]
simp
theorem Coprime.mul {k m n : ℕ+} : m.Coprime k → n.Coprime k → (m * n).Coprime k := by
repeat rw [← coprime_coe]
rw [mul_coe]
apply Nat.Coprime.mul
theorem Coprime.mul_right {k m n : ℕ+} : k.Coprime m → k.Coprime n → k.Coprime (m * n) := by
repeat rw [← coprime_coe]
rw [mul_coe]
apply Nat.Coprime.mul_right
theorem gcd_comm {m n : ℕ+} : m.gcd n = n.gcd m := by
apply eq
simp only [gcd_coe]
apply Nat.gcd_comm
theorem gcd_eq_left_iff_dvd {m n : ℕ+} : m.gcd n = m ↔ m ∣ n := by
rw [dvd_iff, ← Nat.gcd_eq_left_iff_dvd, ← coe_inj]
simp
theorem gcd_eq_right_iff_dvd {m n : ℕ+} : n.gcd m = m ↔ m ∣ n := by
rw [gcd_comm]
apply gcd_eq_left_iff_dvd
theorem Coprime.gcd_mul_left_cancel (m : ℕ+) {n k : ℕ+} :
k.Coprime n → (k * m).gcd n = m.gcd n := by
intro h; apply eq; simp only [gcd_coe, mul_coe]
apply Nat.Coprime.gcd_mul_left_cancel; simpa
theorem Coprime.gcd_mul_right_cancel (m : ℕ+) {n k : ℕ+} :
k.Coprime n → (m * k).gcd n = m.gcd n := by rw [mul_comm]; apply Coprime.gcd_mul_left_cancel
theorem Coprime.gcd_mul_left_cancel_right (m : ℕ+) {n k : ℕ+} :
k.Coprime m → m.gcd (k * n) = m.gcd n := by
intro h; iterate 2 rw [gcd_comm]; symm
apply Coprime.gcd_mul_left_cancel _ h
theorem Coprime.gcd_mul_right_cancel_right (m : ℕ+) {n k : ℕ+} :
k.Coprime m → m.gcd (n * k) = m.gcd n := by
rw [mul_comm]
apply Coprime.gcd_mul_left_cancel_right
@[simp]
theorem one_gcd {n : ℕ+} : gcd 1 n = 1 := by
rw [gcd_eq_left_iff_dvd]
apply one_dvd
@[simp]
theorem gcd_one {n : ℕ+} : gcd n 1 = 1 := by
rw [gcd_comm]
apply one_gcd
@[symm]
theorem Coprime.symm {m n : ℕ+} : m.Coprime n → n.Coprime m := by
unfold Coprime
rw [gcd_comm]
simp
@[simp]
theorem one_coprime {n : ℕ+} : (1 : ℕ+).Coprime n :=
one_gcd
@[simp]
theorem coprime_one {n : ℕ+} : n.Coprime 1 :=
Coprime.symm one_coprime
theorem Coprime.coprime_dvd_left {m k n : ℕ+} : m ∣ k → k.Coprime n → m.Coprime n := by
rw [dvd_iff]
repeat rw [← coprime_coe]
apply Nat.Coprime.coprime_dvd_left
theorem Coprime.factor_eq_gcd_left {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) :
a = (a * b).gcd m := by
rw [← gcd_eq_left_iff_dvd] at am
conv_lhs => rw [← am]
rw [eq_comm]
apply Coprime.gcd_mul_right_cancel a
apply Coprime.coprime_dvd_left bn cop.symm
theorem Coprime.factor_eq_gcd_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) :
a = (b * a).gcd m := by rw [mul_comm]; apply Coprime.factor_eq_gcd_left cop am bn
theorem Coprime.factor_eq_gcd_left_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m)
(bn : b ∣ n) : a = m.gcd (a * b) := by rw [gcd_comm]; apply Coprime.factor_eq_gcd_left cop am bn
theorem Coprime.factor_eq_gcd_right_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m)
(bn : b ∣ n) : a = m.gcd (b * a) := by
rw [gcd_comm]
apply Coprime.factor_eq_gcd_right cop am bn
theorem Coprime.gcd_mul (k : ℕ+) {m n : ℕ+} (h : m.Coprime n) :
k.gcd (m * n) = k.gcd m * k.gcd n := by
rw [← coprime_coe] at h; apply eq
simp only [gcd_coe, mul_coe]; apply Nat.Coprime.gcd_mul k h
| Mathlib/Data/PNat/Prime.lean | 257 | 260 | theorem gcd_eq_left {m n : ℕ+} : m ∣ n → m.gcd n = m := by | rw [dvd_iff]
intro h
apply eq |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Option.NAry
import Mathlib.Data.Seq.Computation
import Mathlib.Tactic.ApplyFun
import Mathlib.Data.List.Basic
/-!
# Possibly infinite lists
This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`.
-/
namespace Stream'
universe u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
/-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`.
-/
def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop :=
∀ {n : ℕ}, s n = none → s (n + 1) = none
/-- `Seq α` is the type of possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`. -/
def Seq (α : Type u) : Type u :=
{ f : Stream' (Option α) // f.IsSeq }
/-- `Seq1 α` is the type of nonempty sequences. -/
def Seq1 (α) :=
α × Seq α
namespace Seq
variable {α : Type u} {β : Type v} {γ : Type w}
/-- The empty sequence -/
def nil : Seq α :=
⟨Stream'.const none, fun {_} _ => rfl⟩
instance : Inhabited (Seq α) :=
⟨nil⟩
/-- Prepend an element to a sequence -/
def cons (a : α) (s : Seq α) : Seq α :=
⟨some a::s.1, by
rintro (n | _) h
· contradiction
· exact s.2 h⟩
@[simp]
theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val :=
rfl
/-- Get the nth element of a sequence (if it exists) -/
def get? : Seq α → ℕ → Option α :=
Subtype.val
@[simp]
theorem val_eq_get (s : Seq α) (n : ℕ) : s.val n = s.get? n := by
rfl
@[simp]
theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f :=
rfl
@[simp]
theorem get?_nil (n : ℕ) : (@nil α).get? n = none :=
rfl
@[simp]
theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a :=
rfl
@[simp]
theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n :=
rfl
@[ext]
protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t :=
Subtype.eq <| funext h
theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h =>
⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero],
Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩
theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_right_injective (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
/-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/
def TerminatedAt (s : Seq α) (n : ℕ) : Prop :=
s.get? n = none
/-- It is decidable whether a sequence terminates at a given position. -/
instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) :=
decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp
/-- A sequence terminates if there is some position `n` at which it has terminated. -/
def Terminates (s : Seq α) : Prop :=
∃ n : ℕ, s.TerminatedAt n
theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by
simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self]
/-- Functorial action of the functor `Option (α × _)` -/
@[simp]
def omap (f : β → γ) : Option (α × β) → Option (α × γ)
| none => none
| some (a, b) => some (a, f b)
/-- Get the first element of a sequence -/
def head (s : Seq α) : Option α :=
get? s 0
/-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/
def tail (s : Seq α) : Seq α :=
⟨s.1.tail, fun n' => by
obtain ⟨f, al⟩ := s
exact al n'⟩
/-- member definition for `Seq` -/
protected def Mem (s : Seq α) (a : α) :=
some a ∈ s.1
instance : Membership α (Seq α) :=
⟨Seq.Mem⟩
theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by
obtain ⟨f, al⟩ := s
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
/-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/
theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n :=
le_stable
/-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such
that `s.get? = some aₘ` for `m ≤ n`.
-/
theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n)
(s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ :=
have : s.get? n ≠ none := by simp [s_nth_eq_some]
have : s.get? m ≠ none := mt (s.le_stable m_le_n) this
Option.ne_none_iff_exists'.mp this
theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h
theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s
| ⟨_, _⟩ => Stream'.mem_cons (some a) _
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : Seq α}, a ∈ s → a ∈ cons y s
| ⟨_, _⟩ => Stream'.mem_cons_of_mem (some y)
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : Seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨_, _⟩, h => (Stream'.eq_or_mem_of_mem_cons h).imp_left fun h => by injection h
@[simp]
theorem mem_cons_iff {a b : α} {s : Seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, by rintro (rfl | m) <;> [apply mem_cons; exact mem_cons_of_mem _ m]⟩
@[simp]
theorem get?_mem {s : Seq α} {n : ℕ} {x : α} (h : s.get? n = .some x) : x ∈ s := ⟨n, h.symm⟩
/-- Destructor for a sequence, resulting in either `none` (for `nil`) or
`some (a, s)` (for `cons a s`). -/
def destruct (s : Seq α) : Option (Seq1 α) :=
(fun a' => (a', s.tail)) <$> get? s 0
theorem destruct_eq_none {s : Seq α} : destruct s = none → s = nil := by
dsimp [destruct]
induction' f0 : get? s 0 <;> intro h
· apply Subtype.eq
funext n
induction' n with n IH
exacts [f0, s.2 IH]
· contradiction
theorem destruct_eq_cons {s : Seq α} {a s'} : destruct s = some (a, s') → s = cons a s' := by
dsimp [destruct]
induction' f0 : get? s 0 with a' <;> intro h
· contradiction
· obtain ⟨f, al⟩ := s
injections _ h1 h2
rw [← h2]
apply Subtype.eq
dsimp [tail, cons]
rw [h1] at f0
rw [← f0]
exact (Stream'.eta f).symm
@[simp]
theorem destruct_nil : destruct (nil : Seq α) = none :=
rfl
@[simp]
theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ => by
unfold cons destruct Functor.map
apply congr_arg fun s => some (a, s)
apply Subtype.eq; dsimp [tail]
-- Porting note: needed universe annotation to avoid universe issues
theorem head_eq_destruct (s : Seq α) : head.{u} s = Prod.fst.{u} <$> destruct.{u} s := by
unfold destruct head; cases get? s 0 <;> rfl
@[simp]
theorem head_nil : head (nil : Seq α) = none :=
rfl
@[simp]
theorem head_cons (a : α) (s) : head (cons a s) = some a := by
rw [head_eq_destruct, destruct_cons, Option.map_eq_map, Option.map_some']
@[simp]
theorem tail_nil : tail (nil : Seq α) = nil :=
rfl
@[simp]
theorem tail_cons (a : α) (s) : tail (cons a s) = s := by
obtain ⟨f, al⟩ := s
apply Subtype.eq
dsimp [tail, cons]
@[simp]
theorem get?_tail (s : Seq α) (n) : get? (tail s) n = get? s (n + 1) :=
rfl
/-- Recursion principle for sequences, compare with `List.recOn`. -/
@[cases_eliminator]
def recOn {motive : Seq α → Sort v} (s : Seq α) (nil : motive nil)
(cons : ∀ x s, motive (cons x s)) :
motive s := by
rcases H : destruct s with - | v
· rw [destruct_eq_none H]
apply nil
· obtain ⟨a, s'⟩ := v
rw [destruct_eq_cons H]
apply cons
@[simp]
theorem cons_ne_nil {x : α} {s : Seq α} : (cons x s) ≠ .nil := by
intro h
apply_fun head at h
simp at h
@[simp]
theorem nil_ne_cons {x : α} {s : Seq α} : .nil ≠ (cons x s) := cons_ne_nil.symm
theorem cons_eq_cons {x x' : α} {s s' : Seq α} :
(cons x s = cons x' s') ↔ (x = x' ∧ s = s') := by
constructor
· intro h
constructor
· apply_fun head at h
simpa using h
· apply_fun tail at h
simpa using h
· intro ⟨_, _⟩
congr
theorem head_eq_some {s : Seq α} {x : α} (h : s.head = some x) :
s = cons x s.tail := by
cases s <;> simp at h
simpa [cons_eq_cons]
theorem head_eq_none {s : Seq α} (h : s.head = none) : s = nil := by
cases s
· rfl
· simp at h
@[simp]
theorem head_eq_none_iff {s : Seq α} : s.head = none ↔ s = nil := by
constructor
· apply head_eq_none
· intro h
simp [h]
theorem mem_rec_on {C : Seq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', a = b ∨ C s' → C (cons b s')) : C s := by
obtain ⟨k, e⟩ := M; unfold Stream'.get at e
induction' k with k IH generalizing s
· have TH : s = cons a (tail s) := by
apply destruct_eq_cons
unfold destruct get? Functor.map
rw [← e]
rfl
rw [TH]
apply h1 _ _ (Or.inl rfl)
cases s with
| nil => injection e
| cons b s' =>
have h_eq : (cons b s').val (Nat.succ k) = s'.val k := by cases s' using Subtype.recOn; rfl
rw [h_eq] at e
apply h1 _ _ (Or.inr (IH e))
/-- Corecursor over pairs of `Option` values -/
def Corec.f (f : β → Option (α × β)) : Option β → Option α × Option β
| none => (none, none)
| some b =>
match f b with
| none => (none, none)
| some (a, b') => (some a, some b')
/-- Corecursor for `Seq α` as a coinductive type. Iterates `f` to produce new elements
of the sequence until `none` is obtained. -/
def corec (f : β → Option (α × β)) (b : β) : Seq α := by
refine ⟨Stream'.corec' (Corec.f f) (some b), fun {n} h => ?_⟩
rw [Stream'.corec'_eq]
change Stream'.corec' (Corec.f f) (Corec.f f (some b)).2 n = none
revert h; generalize some b = o; revert o
induction' n with n IH <;> intro o
· change (Corec.f f o).1 = none → (Corec.f f (Corec.f f o).2).1 = none
rcases o with - | b <;> intro h
· rfl
dsimp [Corec.f] at h
dsimp [Corec.f]
revert h; rcases h₁ : f b with - | s <;> intro h
· rfl
· obtain ⟨a, b'⟩ := s
contradiction
· rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o]
exact IH (Corec.f f o).2
@[simp]
theorem corec_eq (f : β → Option (α × β)) (b : β) :
destruct (corec f b) = omap (corec f) (f b) := by
dsimp [corec, destruct, get]
rw [show Stream'.corec' (Corec.f f) (some b) 0 = (Corec.f f (some b)).1 from rfl]
dsimp [Corec.f]
induction' h : f b with s; · rfl
obtain ⟨a, b'⟩ := s; dsimp [Corec.f]
apply congr_arg fun b' => some (a, b')
apply Subtype.eq
dsimp [corec, tail]
rw [Stream'.corec'_eq, Stream'.tail_cons]
dsimp [Corec.f]; rw [h]
theorem corec_nil (f : β → Option (α × β)) (b : β)
(h : f b = .none) : corec f b = nil := by
apply destruct_eq_none
simp [h]
theorem corec_cons {f : β → Option (α × β)} {b : β} {x : α} {s : β}
(h : f b = .some (x, s)) : corec f b = cons x (corec f s) := by
apply destruct_eq_cons
simp [h]
section Bisim
variable (R : Seq α → Seq α → Prop)
local infixl:50 " ~ " => R
/-- Bisimilarity relation over `Option` of `Seq1 α` -/
def BisimO : Option (Seq1 α) → Option (Seq1 α) → Prop
| none, none => True
| some (a, s), some (a', s') => a = a' ∧ R s s'
| _, _ => False
attribute [simp] BisimO
attribute [nolint simpNF] BisimO.eq_3
/-- a relation is bisimilar if it meets the `BisimO` test -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂)
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq
apply Stream'.eq_of_bisim fun x y => ∃ s s' : Seq α, s.1 = x ∧ s'.1 = y ∧ R s s'
· dsimp [Stream'.IsBisimulation]
intro t₁ t₂ e
exact
match t₁, t₂, e with
| _, _, ⟨s, s', rfl, rfl, r⟩ => by
suffices head s = head s' ∧ R (tail s) (tail s') from
And.imp id (fun r => ⟨tail s, tail s', by cases s using Subtype.recOn; rfl,
by cases s' using Subtype.recOn; rfl, r⟩) this
have := bisim r; revert r this
cases s <;> cases s'
· intro r _
constructor
· rfl
· assumption
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_cons, destruct_cons] at this
rw [head_cons, head_cons, tail_cons, tail_cons]
obtain ⟨h1, h2⟩ := this
constructor
· rw [h1]
· exact h2
· exact ⟨s₁, s₂, rfl, rfl, r⟩
end Bisim
theorem coinduction :
∀ {s₁ s₂ : Seq α},
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Seq α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂
| _, _, hh, ht =>
Subtype.eq (Stream'.coinduction hh fun β fr => ht β fun s => fr s.1)
theorem coinduction2 (s) (f g : Seq α → Seq β)
(H :
∀ s,
BisimO (fun s1 s2 : Seq β => ∃ s : Seq α, s1 = f s ∧ s2 = g s) (destruct (f s))
(destruct (g s))) :
f s = g s := by
refine eq_of_bisim (fun s1 s2 => ∃ s, s1 = f s ∧ s2 = g s) ?_ ⟨s, rfl, rfl⟩
intro s1 s2 h; rcases h with ⟨s, h1, h2⟩
rw [h1, h2]; apply H
/-- Embed a list as a sequence -/
@[coe]
def ofList (l : List α) : Seq α :=
⟨(l[·]?), fun {n} h => by
rw [List.getElem?_eq_none_iff] at h ⊢
exact h.trans (Nat.le_succ n)⟩
instance coeList : Coe (List α) (Seq α) :=
⟨ofList⟩
@[simp]
theorem ofList_nil : ofList [] = (nil : Seq α) :=
rfl
@[simp]
theorem ofList_get? (l : List α) (n : ℕ) : (ofList l).get? n = l[n]? :=
rfl
@[deprecated (since := "2025-02-21")]
alias ofList_get := ofList_get?
@[simp]
theorem ofList_cons (a : α) (l : List α) : ofList (a::l) = cons a (ofList l) := by
ext1 (_ | n) <;> simp
theorem ofList_injective : Function.Injective (ofList : List α → _) :=
fun _ _ h => List.ext_getElem? fun _ => congr_fun (Subtype.ext_iff.1 h) _
/-- Embed an infinite stream as a sequence -/
@[coe]
def ofStream (s : Stream' α) : Seq α :=
⟨s.map some, fun {n} h => by contradiction⟩
instance coeStream : Coe (Stream' α) (Seq α) :=
⟨ofStream⟩
section MLList
/-- Embed a `MLList α` as a sequence. Note that even though this
is non-meta, it will produce infinite sequences if used with
cyclic `MLList`s created by meta constructions. -/
def ofMLList : MLList Id α → Seq α :=
corec fun l =>
match l.uncons with
| .none => none
| .some (a, l') => some (a, l')
instance coeMLList : Coe (MLList Id α) (Seq α) :=
⟨ofMLList⟩
/-- Translate a sequence into a `MLList`. -/
unsafe def toMLList : Seq α → MLList Id α
| s =>
match destruct s with
| none => .nil
| some (a, s') => .cons a (toMLList s')
end MLList
/-- Translate a sequence to a list. This function will run forever if
run on an infinite sequence. -/
unsafe def forceToList (s : Seq α) : List α :=
(toMLList s).force
/-- The sequence of natural numbers some 0, some 1, ... -/
def nats : Seq ℕ :=
Stream'.nats
@[simp]
theorem nats_get? (n : ℕ) : nats.get? n = some n :=
rfl
/-- Append two sequences. If `s₁` is infinite, then `s₁ ++ s₂ = s₁`,
otherwise it puts `s₂` at the location of the `nil` in `s₁`. -/
def append (s₁ s₂ : Seq α) : Seq α :=
@corec α (Seq α × Seq α)
(fun ⟨s₁, s₂⟩ =>
match destruct s₁ with
| none => omap (fun s₂ => (nil, s₂)) (destruct s₂)
| some (a, s₁') => some (a, s₁', s₂))
(s₁, s₂)
/-- Map a function over a sequence. -/
def map (f : α → β) : Seq α → Seq β
| ⟨s, al⟩ =>
⟨s.map (Option.map f), fun {n} => by
dsimp [Stream'.map, Stream'.get]
induction' e : s n with e <;> intro
· rw [al e]
assumption
· contradiction⟩
/-- Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of `nil`, the first element is never
generated.) -/
def join : Seq (Seq1 α) → Seq α :=
corec fun S =>
match destruct S with
| none => none
| some ((a, s), S') =>
some
(a,
match destruct s with
| none => S'
| some s' => cons s' S')
/-- Remove the first `n` elements from the sequence. -/
def drop (s : Seq α) : ℕ → Seq α
| 0 => s
| n + 1 => tail (drop s n)
/-- Take the first `n` elements of the sequence (producing a list) -/
def take : ℕ → Seq α → List α
| 0, _ => []
| n + 1, s =>
match destruct s with
| none => []
| some (x, r) => List.cons x (take n r)
/-- Split a sequence at `n`, producing a finite initial segment
and an infinite tail. -/
def splitAt : ℕ → Seq α → List α × Seq α
| 0, s => ([], s)
| n + 1, s =>
match destruct s with
| none => ([], nil)
| some (x, s') =>
let (l, r) := splitAt n s'
(List.cons x l, r)
/-- Folds a sequence using `f`, producing a sequence of intermediate values, i.e.
`[init, f init s.head, f (f init s.head) s.tail.head, ...]`. -/
def fold (s : Seq α) (init : β) (f : β → α → β) : Seq β :=
let f : β × Seq α → Option (β × (β × Seq α)) := fun (acc, x) =>
match destruct x with
| none => .none
| some (x, s) => .some (f acc x, f acc x, s)
cons init <| corec f (init, s)
section ZipWith
/-- Combine two sequences with a function -/
def zipWith (f : α → β → γ) (s₁ : Seq α) (s₂ : Seq β) : Seq γ :=
⟨fun n => Option.map₂ f (s₁.get? n) (s₂.get? n), fun {_} hn =>
Option.map₂_eq_none_iff.2 <| (Option.map₂_eq_none_iff.1 hn).imp s₁.2 s₂.2⟩
@[simp]
theorem get?_zipWith (f : α → β → γ) (s s' n) :
(zipWith f s s').get? n = Option.map₂ f (s.get? n) (s'.get? n) :=
rfl
end ZipWith
/-- Pair two sequences into a sequence of pairs -/
def zip : Seq α → Seq β → Seq (α × β) :=
zipWith Prod.mk
@[simp]
theorem get?_zip (s : Seq α) (t : Seq β) (n : ℕ) :
get? (zip s t) n = Option.map₂ Prod.mk (get? s n) (get? t n) :=
get?_zipWith _ _ _ _
/-- Separate a sequence of pairs into two sequences -/
def unzip (s : Seq (α × β)) : Seq α × Seq β :=
(map Prod.fst s, map Prod.snd s)
/-- Enumerate a sequence by tagging each element with its index. -/
def enum (s : Seq α) : Seq (ℕ × α) :=
Seq.zip nats s
@[simp]
theorem get?_enum (s : Seq α) (n : ℕ) : get? (enum s) n = Option.map (Prod.mk n) (get? s n) :=
get?_zip _ _ _
@[simp]
theorem enum_nil : enum (nil : Seq α) = nil :=
rfl
/-- The length of a terminating sequence. -/
def length (s : Seq α) (h : s.Terminates) : ℕ :=
Nat.find h
/-- Convert a sequence which is known to terminate into a list -/
def toList (s : Seq α) (h : s.Terminates) : List α :=
take (length s h) s
/-- Convert a sequence which is known not to terminate into a stream -/
def toStream (s : Seq α) (h : ¬s.Terminates) : Stream' α := fun n =>
Option.get _ <| not_terminates_iff.1 h n
/-- Convert a sequence into either a list or a stream depending on whether
it is finite or infinite. (Without decidability of the infiniteness predicate,
this is not constructively possible.) -/
def toListOrStream (s : Seq α) [Decidable s.Terminates] : List α ⊕ Stream' α :=
if h : s.Terminates then Sum.inl (toList s h) else Sum.inr (toStream s h)
@[simp]
theorem nil_append (s : Seq α) : append nil s = s := by
apply coinduction2; intro s
dsimp [append]; rw [corec_eq]
dsimp [append]
cases s
· trivial
· rw [destruct_cons]
dsimp
exact ⟨rfl, _, rfl, rfl⟩
@[simp]
theorem take_nil {n : ℕ} : (nil (α := α)).take n = List.nil := by
cases n <;> rfl
@[simp]
theorem take_zero {s : Seq α} : s.take 0 = [] := by
cases s <;> rfl
@[simp]
theorem take_succ_cons {n : ℕ} {x : α} {s : Seq α} :
(cons x s).take (n + 1) = x :: s.take n := by
rfl
@[simp]
theorem getElem?_take : ∀ (n k : ℕ) (s : Seq α),
(s.take k)[n]? = if n < k then s.get? n else none
| n, 0, s => by simp [take]
| n, k+1, s => by
rw [take]
cases h : destruct s with
| none =>
simp [destruct_eq_none h]
| some a =>
match a with
| (x, r) =>
rw [destruct_eq_cons h]
match n with
| 0 => simp
| n+1 =>
simp [List.getElem?_cons_succ, Nat.add_lt_add_iff_right, getElem?_take]
theorem get?_mem_take {s : Seq α} {m n : ℕ} (h_mn : m < n) {x : α}
(h_get : s.get? m = .some x) : x ∈ s.take n := by
induction m generalizing n s with
| zero =>
obtain ⟨l, hl⟩ := Nat.exists_add_one_eq.mpr h_mn
rw [← hl, take, head_eq_some h_get]
simp
| succ k ih =>
obtain ⟨l, hl⟩ := Nat.exists_eq_add_of_lt h_mn
subst hl
have : ∃ y, s.get? 0 = .some y := by
apply ge_stable _ _ h_get
simp
obtain ⟨y, hy⟩ := this
rw [take, head_eq_some hy]
simp
right
apply ih (by omega)
rwa [get?_tail]
theorem terminatedAt_ofList (l : List α) :
(ofList l).TerminatedAt l.length := by
simp [ofList, TerminatedAt]
theorem terminates_ofList (l : List α) : (ofList l).Terminates :=
⟨_, terminatedAt_ofList l⟩
@[simp]
theorem terminatedAt_nil {n : ℕ} : TerminatedAt (nil : Seq α) n := rfl
@[simp]
theorem cons_not_terminatedAt_zero {x : α} {s : Seq α} :
¬(cons x s).TerminatedAt 0 := by
simp [TerminatedAt]
@[simp]
theorem cons_terminatedAt_succ_iff {x : α} {s : Seq α} {n : ℕ} :
(cons x s).TerminatedAt (n + 1) ↔ s.TerminatedAt n := by
simp [TerminatedAt]
@[simp]
theorem terminates_nil : Terminates (nil : Seq α) := ⟨0, rfl⟩
@[simp]
theorem terminates_cons_iff {x : α} {s : Seq α} :
(cons x s).Terminates ↔ s.Terminates := by
constructor <;> intro ⟨n, h⟩
· exact ⟨n, cons_terminatedAt_succ_iff.mp (terminated_stable _ (Nat.le_succ _) h)⟩
· exact ⟨n + 1, cons_terminatedAt_succ_iff.mpr h⟩
@[simp]
theorem length_nil : length (nil : Seq α) terminates_nil = 0 := rfl
@[simp]
theorem get?_zero_eq_none {s : Seq α} : s.get? 0 = none ↔ s = nil := by
refine ⟨fun h => ?_, fun h => h ▸ rfl⟩
ext1 n
exact le_stable s (Nat.zero_le _) h
@[simp] theorem length_eq_zero {s : Seq α} {h : s.Terminates} :
s.length h = 0 ↔ s = nil := by
simp [length, TerminatedAt]
theorem terminatedAt_zero_iff {s : Seq α} : s.TerminatedAt 0 ↔ s = nil := by
refine ⟨?_, ?_⟩
· intro h
ext n
rw [le_stable _ (Nat.zero_le _) h]
simp
· rintro rfl
simp [TerminatedAt]
/-- The statement of `length_le_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `length_le_iff` -/
theorem length_le_iff' {s : Seq α} {n : ℕ} :
(∃ h, s.length h ≤ n) ↔ s.TerminatedAt n := by
simp only [length, Nat.find_le_iff, TerminatedAt, Terminates, exists_prop]
refine ⟨?_, ?_⟩
· rintro ⟨_, k, hkn, hk⟩
exact le_stable s hkn hk
· intro hn
exact ⟨⟨n, hn⟩, ⟨n, le_rfl, hn⟩⟩
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem length_le_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
s.length h ≤ n ↔ s.TerminatedAt n := by
rw [← length_le_iff']; simp [h]
/-- The statement of `lt_length_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `lt_length_iff` -/
theorem lt_length_iff' {s : Seq α} {n : ℕ} :
(∀ h : s.Terminates, n < s.length h) ↔ ∃ a, a ∈ s.get? n := by
simp only [Terminates, TerminatedAt, length, Nat.lt_find_iff, forall_exists_index, Option.mem_def,
← Option.ne_none_iff_exists', ne_eq]
refine ⟨?_, ?_⟩
· intro h hn
exact h n hn n le_rfl hn
· intro hn _ _ k hkn hk
exact hn <| le_stable s hkn hk
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem lt_length_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
n < s.length h ↔ ∃ a, a ∈ s.get? n := by
rw [← lt_length_iff']; simp [h]
theorem length_take_le {s : Seq α} {n : ℕ} : (s.take n).length ≤ n := by
induction n generalizing s with
| zero => simp
| succ m ih =>
rw [take]
cases s.destruct with
| none => simp
| some v =>
obtain ⟨x, r⟩ := v
simpa using ih
theorem length_take_of_le_length {s : Seq α} {n : ℕ}
(hle : ∀ h : s.Terminates, n ≤ s.length h) : (s.take n).length = n := by
induction n generalizing s with
| zero => simp [take]
| succ n ih =>
rw [take, destruct]
let ⟨a, ha⟩ := lt_length_iff'.1 (fun ht => lt_of_lt_of_le (Nat.succ_pos _) (hle ht))
simp [Option.mem_def.1 ha]
rw [ih]
intro h
simp only [length, tail, Nat.le_find_iff, TerminatedAt, get?_mk, Stream'.tail]
intro m hmn hs
have := lt_length_iff'.1 (fun ht => (Nat.lt_of_succ_le (hle ht)))
rw [le_stable s (Nat.succ_le_of_lt hmn) hs] at this
simp at this
@[simp]
| Mathlib/Data/Seq/Seq.lean | 806 | 807 | theorem length_toList (s : Seq α) (h : s.Terminates) : (toList s h).length = length s h := by | rw [toList, length_take_of_le_length] |
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Data.Int.Range
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.MulChar.Basic
/-!
# Quadratic characters on ℤ/nℤ
This file defines some quadratic characters on the rings ℤ/4ℤ and ℤ/8ℤ.
We set them up to be of type `MulChar (ZMod n) ℤ`, where `n` is `4` or `8`.
## Tags
quadratic character, zmod
-/
/-!
### Quadratic characters mod 4 and 8
We define the primitive quadratic characters `χ₄`on `ZMod 4`
and `χ₈`, `χ₈'` on `ZMod 8`.
-/
namespace ZMod
section QuadCharModP
/-- Define the nontrivial quadratic character on `ZMod 4`, `χ₄`.
It corresponds to the extension `ℚ(√-1)/ℚ`. -/
@[simps]
def χ₄ : MulChar (ZMod 4) ℤ where
toFun a :=
match a with
| 0 | 2 => 0
| 1 => 1
| 3 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₄` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₄ : χ₄.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- The value of `χ₄ n`, for `n : ℕ`, depends only on `n % 4`. -/
theorem χ₄_nat_mod_four (n : ℕ) : χ₄ n = χ₄ (n % 4 : ℕ) := by
rw [← ZMod.natCast_mod n 4]
/-- The value of `χ₄ n`, for `n : ℤ`, depends only on `n % 4`. -/
theorem χ₄_int_mod_four (n : ℤ) : χ₄ n = χ₄ (n % 4 : ℤ) := by
rw [← ZMod.intCast_mod n 4, Nat.cast_ofNat]
/-- An explicit description of `χ₄` on integers / naturals -/
theorem χ₄_int_eq_if_mod_four (n : ℤ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 := by
have help : ∀ m : ℤ, 0 ≤ m → m < 4 → χ₄ m = if m % 2 = 0 then 0 else if m = 1 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by omega : (2 : ℤ) ∣ 4), ← ZMod.intCast_mod n 4]
exact help (n % 4) (Int.emod_nonneg n (by omega)) (Int.emod_lt_abs n (by omega))
theorem χ₄_nat_eq_if_mod_four (n : ℕ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 :=
mod_cast χ₄_int_eq_if_mod_four n
/-- Alternative description of `χ₄ n` for odd `n : ℕ` in terms of powers of `-1` -/
theorem χ₄_eq_neg_one_pow {n : ℕ} (hn : n % 2 = 1) : χ₄ n = (-1) ^ (n / 2) := by
rw [χ₄_nat_eq_if_mod_four]
simp only [hn, Nat.one_ne_zero, if_false]
nth_rewrite 3 [← Nat.div_add_mod n 4]
nth_rewrite 3 [show 4 = 2 * 2 by omega]
rw [mul_assoc, add_comm, Nat.add_mul_div_left _ _ zero_lt_two, pow_add, pow_mul,
neg_one_sq, one_pow, mul_one]
have help : ∀ m : ℕ, m < 4 → m % 2 = 1 → ite (m = 1) (1 : ℤ) (-1) = (-1) ^ (m / 2) := by decide
exact help _ (Nat.mod_lt n (by omega)) <| (Nat.mod_mod_of_dvd n (by omega : 2 ∣ 4)).trans hn
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_nat_one_mod_four {n : ℕ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
theorem χ₄_nat_three_mod_four {n : ℕ} (hn : n % 4 = 3) : χ₄ n = -1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_int_one_mod_four {n : ℤ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_int_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
| Mathlib/NumberTheory/LegendreSymbol/ZModChar.lean | 100 | 102 | theorem χ₄_int_three_mod_four {n : ℤ} (hn : n % 4 = 3) : χ₄ n = -1 := by | rw [χ₄_int_mod_four, hn]
rfl |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury Kudryashov
-/
import Mathlib.MeasureTheory.OuterMeasure.Basic
/-!
# The “almost everywhere” filter of co-null sets.
If `μ` is an outer measure or a measure on `α`,
then `MeasureTheory.ae μ` is the filter of co-null sets: `s ∈ ae μ ↔ μ sᶜ = 0`.
In this file we define the filter and prove some basic theorems about it.
## Notation
- `∀ᵐ x ∂μ, p x`: the predicate `p` holds for `μ`-a.e. all `x`;
- `∃ᶠ x ∂μ, p x`: the predicate `p` holds on a set of nonzero measure;
- `f =ᵐ[μ] g`: `f x = g x` for `μ`-a.e. all `x`;
- `f ≤ᵐ[μ] g`: `f x ≤ g x` for `μ`-a.e. all `x`.
## Implementation details
All notation introduced in this file
reducibly unfolds to the corresponding definitions about filters,
so generic lemmas about `Filter.Eventually`, `Filter.EventuallyEq` etc apply.
However, we restate some lemmas specifically for `ae`.
## Tags
outer measure, measure, almost everywhere
-/
open Filter Set
open scoped ENNReal
namespace MeasureTheory
variable {α β F : Type*} [FunLike F (Set α) ℝ≥0∞] [OuterMeasureClass F α] {μ : F} {s t : Set α}
/-- The “almost everywhere” filter of co-null sets. -/
def ae (μ : F) : Filter α :=
.ofCountableUnion (μ · = 0) (fun _S hSc ↦ (measure_sUnion_null_iff hSc).2) fun _t ht _s hs ↦
measure_mono_null hs ht
/-- `∀ᵐ a ∂μ, p a` means that `p a` for a.e. `a`, i.e. `p` holds true away from a null set.
This is notation for `Filter.Eventually p (MeasureTheory.ae μ)`. -/
notation3 "∀ᵐ "(...)" ∂"μ", "r:(scoped p => Filter.Eventually p <| MeasureTheory.ae μ) => r
/-- `∃ᵐ a ∂μ, p a` means that `p` holds `∂μ`-frequently,
i.e. `p` holds on a set of positive measure.
This is notation for `Filter.Frequently p (MeasureTheory.ae μ)`. -/
notation3 "∃ᵐ "(...)" ∂"μ", "r:(scoped P => Filter.Frequently P <| MeasureTheory.ae μ) => r
/-- `f =ᵐ[μ] g` means `f` and `g` are eventually equal along the a.e. filter,
i.e. `f=g` away from a null set.
This is notation for `Filter.EventuallyEq (MeasureTheory.ae μ) f g`. -/
notation:50 f " =ᵐ[" μ:50 "] " g:50 => Filter.EventuallyEq (MeasureTheory.ae μ) f g
/-- `f ≤ᵐ[μ] g` means `f` is eventually less than `g` along the a.e. filter,
i.e. `f ≤ g` away from a null set.
This is notation for `Filter.EventuallyLE (MeasureTheory.ae μ) f g`. -/
notation:50 f " ≤ᵐ[" μ:50 "] " g:50 => Filter.EventuallyLE (MeasureTheory.ae μ) f g
theorem mem_ae_iff {s : Set α} : s ∈ ae μ ↔ μ sᶜ = 0 :=
Iff.rfl
theorem ae_iff {p : α → Prop} : (∀ᵐ a ∂μ, p a) ↔ μ { a | ¬p a } = 0 :=
Iff.rfl
theorem compl_mem_ae_iff {s : Set α} : sᶜ ∈ ae μ ↔ μ s = 0 := by simp only [mem_ae_iff, compl_compl]
theorem frequently_ae_iff {p : α → Prop} : (∃ᵐ a ∂μ, p a) ↔ μ { a | p a } ≠ 0 :=
not_congr compl_mem_ae_iff
theorem frequently_ae_mem_iff {s : Set α} : (∃ᵐ a ∂μ, a ∈ s) ↔ μ s ≠ 0 :=
not_congr compl_mem_ae_iff
theorem measure_zero_iff_ae_nmem {s : Set α} : μ s = 0 ↔ ∀ᵐ a ∂μ, a ∉ s :=
compl_mem_ae_iff.symm
theorem ae_of_all {p : α → Prop} (μ : F) : (∀ a, p a) → ∀ᵐ a ∂μ, p a :=
Eventually.of_forall
instance instCountableInterFilter : CountableInterFilter (ae μ) := by
unfold ae; infer_instance
theorem ae_all_iff {ι : Sort*} [Countable ι] {p : α → ι → Prop} :
(∀ᵐ a ∂μ, ∀ i, p a i) ↔ ∀ i, ∀ᵐ a ∂μ, p a i :=
eventually_countable_forall
theorem all_ae_of {ι : Sort*} {p : α → ι → Prop} (hp : ∀ᵐ a ∂μ, ∀ i, p a i) (i : ι) :
∀ᵐ a ∂μ, p a i := by
filter_upwards [hp] with a ha using ha i
lemma ae_iff_of_countable [Countable α] {p : α → Prop} : (∀ᵐ x ∂μ, p x) ↔ ∀ x, μ {x} ≠ 0 → p x := by
rw [ae_iff, measure_null_iff_singleton]
exacts [forall_congr' fun _ ↦ not_imp_comm, Set.to_countable _]
theorem ae_ball_iff {ι : Type*} {S : Set ι} (hS : S.Countable) {p : α → ∀ i ∈ S, Prop} :
(∀ᵐ x ∂μ, ∀ i (hi : i ∈ S), p x i hi) ↔ ∀ i (hi : i ∈ S), ∀ᵐ x ∂μ, p x i hi :=
eventually_countable_ball hS
lemma ae_eq_refl (f : α → β) : f =ᵐ[μ] f := EventuallyEq.rfl
lemma ae_eq_rfl {f : α → β} : f =ᵐ[μ] f := EventuallyEq.rfl
lemma ae_eq_comm {f g : α → β} : f =ᵐ[μ] g ↔ g =ᵐ[μ] f := eventuallyEq_comm
theorem ae_eq_symm {f g : α → β} (h : f =ᵐ[μ] g) : g =ᵐ[μ] f :=
h.symm
theorem ae_eq_trans {f g h : α → β} (h₁ : f =ᵐ[μ] g) (h₂ : g =ᵐ[μ] h) : f =ᵐ[μ] h :=
h₁.trans h₂
@[simp] lemma ae_eq_top : ae μ = ⊤ ↔ ∀ a, μ {a} ≠ 0 := by
simp only [Filter.ext_iff, mem_ae_iff, mem_top, ne_eq]
refine ⟨fun h a ha ↦ by simpa [ha] using (h {a}ᶜ).1, fun h s ↦ ⟨fun hs ↦ ?_, ?_⟩⟩
· rw [← compl_empty_iff, ← not_nonempty_iff_eq_empty]
rintro ⟨a, ha⟩
exact h _ <| measure_mono_null (singleton_subset_iff.2 ha) hs
· rintro rfl
simp
theorem ae_le_of_ae_lt {β : Type*} [Preorder β] {f g : α → β} (h : ∀ᵐ x ∂μ, f x < g x) :
f ≤ᵐ[μ] g :=
h.mono fun _ ↦ le_of_lt
@[simp]
theorem ae_eq_empty : s =ᵐ[μ] (∅ : Set α) ↔ μ s = 0 :=
eventuallyEq_empty.trans <| by simp only [ae_iff, Classical.not_not, setOf_mem_eq]
-- The priority should be higher than `eventuallyEq_univ`.
@[simp high]
theorem ae_eq_univ : s =ᵐ[μ] (univ : Set α) ↔ μ sᶜ = 0 :=
eventuallyEq_univ
theorem ae_le_set : s ≤ᵐ[μ] t ↔ μ (s \ t) = 0 :=
calc
s ≤ᵐ[μ] t ↔ ∀ᵐ x ∂μ, x ∈ s → x ∈ t := Iff.rfl
_ ↔ μ (s \ t) = 0 := by simp [ae_iff]; rfl
theorem ae_le_set_inter {s' t' : Set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') :
(s ∩ s' : Set α) ≤ᵐ[μ] (t ∩ t' : Set α) :=
h.inter h'
theorem ae_le_set_union {s' t' : Set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') :
(s ∪ s' : Set α) ≤ᵐ[μ] (t ∪ t' : Set α) :=
h.union h'
theorem union_ae_eq_right : (s ∪ t : Set α) =ᵐ[μ] t ↔ μ (s \ t) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set, union_diff_right,
diff_eq_empty.2 Set.subset_union_right]
theorem diff_ae_eq_self : (s \ t : Set α) =ᵐ[μ] s ↔ μ (s ∩ t) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set, diff_diff_right, diff_diff,
diff_eq_empty.2 Set.subset_union_right]
theorem diff_null_ae_eq_self (ht : μ t = 0) : (s \ t : Set α) =ᵐ[μ] s :=
diff_ae_eq_self.mpr (measure_mono_null inter_subset_right ht)
theorem ae_eq_set {s t : Set α} : s =ᵐ[μ] t ↔ μ (s \ t) = 0 ∧ μ (t \ s) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set]
open scoped symmDiff in
@[simp]
theorem measure_symmDiff_eq_zero_iff {s t : Set α} : μ (s ∆ t) = 0 ↔ s =ᵐ[μ] t := by
simp [ae_eq_set, symmDiff_def]
@[simp]
theorem ae_eq_set_compl_compl {s t : Set α} : sᶜ =ᵐ[μ] tᶜ ↔ s =ᵐ[μ] t := by
simp only [← measure_symmDiff_eq_zero_iff, compl_symmDiff_compl]
theorem ae_eq_set_compl {s t : Set α} : sᶜ =ᵐ[μ] t ↔ s =ᵐ[μ] tᶜ := by
rw [← ae_eq_set_compl_compl, compl_compl]
theorem ae_eq_set_inter {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
(s ∩ s' : Set α) =ᵐ[μ] (t ∩ t' : Set α) :=
h.inter h'
theorem ae_eq_set_union {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
(s ∪ s' : Set α) =ᵐ[μ] (t ∪ t' : Set α) :=
h.union h'
theorem ae_eq_set_diff {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
s \ s' =ᵐ[μ] t \ t' :=
h.diff h'
open scoped symmDiff in
theorem ae_eq_set_symmDiff {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
s ∆ s' =ᵐ[μ] t ∆ t' :=
h.symmDiff h'
theorem union_ae_eq_univ_of_ae_eq_univ_left (h : s =ᵐ[μ] univ) : (s ∪ t : Set α) =ᵐ[μ] univ :=
(ae_eq_set_union h (ae_eq_refl t)).trans <| by rw [univ_union]
theorem union_ae_eq_univ_of_ae_eq_univ_right (h : t =ᵐ[μ] univ) : (s ∪ t : Set α) =ᵐ[μ] univ := by
convert ae_eq_set_union (ae_eq_refl s) h
rw [union_univ]
theorem union_ae_eq_right_of_ae_eq_empty (h : s =ᵐ[μ] (∅ : Set α)) : (s ∪ t : Set α) =ᵐ[μ] t := by
convert ae_eq_set_union h (ae_eq_refl t)
rw [empty_union]
theorem union_ae_eq_left_of_ae_eq_empty (h : t =ᵐ[μ] (∅ : Set α)) : (s ∪ t : Set α) =ᵐ[μ] s := by
convert ae_eq_set_union (ae_eq_refl s) h
rw [union_empty]
theorem inter_ae_eq_right_of_ae_eq_univ (h : s =ᵐ[μ] univ) : (s ∩ t : Set α) =ᵐ[μ] t := by
convert ae_eq_set_inter h (ae_eq_refl t)
rw [univ_inter]
theorem inter_ae_eq_left_of_ae_eq_univ (h : t =ᵐ[μ] univ) : (s ∩ t : Set α) =ᵐ[μ] s := by
convert ae_eq_set_inter (ae_eq_refl s) h
rw [inter_univ]
theorem inter_ae_eq_empty_of_ae_eq_empty_left (h : s =ᵐ[μ] (∅ : Set α)) :
(s ∩ t : Set α) =ᵐ[μ] (∅ : Set α) := by
convert ae_eq_set_inter h (ae_eq_refl t)
rw [empty_inter]
theorem inter_ae_eq_empty_of_ae_eq_empty_right (h : t =ᵐ[μ] (∅ : Set α)) :
(s ∩ t : Set α) =ᵐ[μ] (∅ : Set α) := by
convert ae_eq_set_inter (ae_eq_refl s) h
rw [inter_empty]
@[to_additive]
| Mathlib/MeasureTheory/OuterMeasure/AE.lean | 231 | 233 | theorem _root_.Set.mulIndicator_ae_eq_one {M : Type*} [One M] {f : α → M} {s : Set α} :
s.mulIndicator f =ᵐ[μ] 1 ↔ μ (s ∩ f.mulSupport) = 0 := by | simp [EventuallyEq, eventually_iff, ae, compl_setOf]; rfl |
/-
Copyright (c) 2019 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Regular.Basic
import Mathlib.GroupTheory.MonoidLocalization.Basic
import Mathlib.LinearAlgebra.Matrix.MvPolynomial
import Mathlib.LinearAlgebra.Matrix.Polynomial
import Mathlib.RingTheory.Polynomial.Basic
/-!
# Cramer's rule and adjugate matrices
The adjugate matrix is the transpose of the cofactor matrix.
It is calculated with Cramer's rule, which we introduce first.
The vectors returned by Cramer's rule are given by the linear map `cramer`,
which sends a matrix `A` and vector `b` to the vector consisting of the
determinant of replacing the `i`th column of `A` with `b` at index `i`
(written as `(A.update_column i b).det`).
Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`.
The entries of the adjugate are the minors of `A`.
Instead of defining a minor by deleting row `i` and column `j` of `A`, we
replace the `i`th row of `A` with the `j`th basis vector; the resulting matrix
has the same determinant but more importantly equals Cramer's rule applied
to `A` and the `j`th basis vector, simplifying the subsequent proofs.
We prove the adjugate behaves like `det A • A⁻¹`.
## Main definitions
* `Matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`.
* `Matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`.
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
cramer, cramer's rule, adjugate
-/
namespace Matrix
universe u v w
variable {m : Type u} {n : Type v} {α : Type w}
variable [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] [CommRing α]
open Matrix Polynomial Equiv Equiv.Perm Finset
section Cramer
/-!
### `cramer` section
Introduce the linear map `cramer` with values defined by `cramerMap`.
After defining `cramerMap` and showing it is linear,
we will restrict our proofs to using `cramer`.
-/
variable (A : Matrix n n α) (b : n → α)
/-- `cramerMap A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,
and thus `cramerMap A b` is the vector output by Cramer's rule on `A` and `b`.
If `A * x = b` has a unique solution in `x`, `cramerMap A` sends the vector `b` to `A.det • x`.
Otherwise, the outcome of `cramerMap` is well-defined but not necessarily useful.
-/
def cramerMap (i : n) : α :=
(A.updateCol i b).det
theorem cramerMap_is_linear (i : n) : IsLinearMap α fun b => cramerMap A b i :=
{ map_add := det_updateCol_add _ _
map_smul := det_updateCol_smul _ _ }
theorem cramer_is_linear : IsLinearMap α (cramerMap A) := by
constructor <;> intros <;> ext i
· apply (cramerMap_is_linear A i).1
· apply (cramerMap_is_linear A i).2
/-- `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,
and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`.
If `A * x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det • x`.
Otherwise, the outcome of `cramer` is well-defined but not necessarily useful.
-/
def cramer (A : Matrix n n α) : (n → α) →ₗ[α] (n → α) :=
IsLinearMap.mk' (cramerMap A) (cramer_is_linear A)
theorem cramer_apply (i : n) : cramer A b i = (A.updateCol i b).det :=
rfl
theorem cramer_transpose_apply (i : n) : cramer Aᵀ b i = (A.updateRow i b).det := by
rw [cramer_apply, updateCol_transpose, det_transpose]
theorem cramer_transpose_row_self (i : n) : Aᵀ.cramer (A i) = Pi.single i A.det := by
ext j
rw [cramer_apply, Pi.single_apply]
split_ifs with h
· -- i = j: this entry should be `A.det`
subst h
simp only [updateCol_transpose, det_transpose, updateRow_eq_self]
· -- i ≠ j: this entry should be 0
rw [updateCol_transpose, det_transpose]
apply det_zero_of_row_eq h
rw [updateRow_self, updateRow_ne (Ne.symm h)]
theorem cramer_row_self (i : n) (h : ∀ j, b j = A j i) : A.cramer b = Pi.single i A.det := by
rw [← transpose_transpose A, det_transpose]
convert cramer_transpose_row_self Aᵀ i
exact funext h
@[simp]
theorem cramer_one : cramer (1 : Matrix n n α) = 1 := by
ext i j
convert congr_fun (cramer_row_self (1 : Matrix n n α) (Pi.single i 1) i _) j
· simp
· intro j
rw [Matrix.one_eq_pi_single, Pi.single_comm]
theorem cramer_smul (r : α) (A : Matrix n n α) :
cramer (r • A) = r ^ (Fintype.card n - 1) • cramer A :=
LinearMap.ext fun _ => funext fun _ => det_updateCol_smul_left _ _ _ _
@[simp]
theorem cramer_subsingleton_apply [Subsingleton n] (A : Matrix n n α) (b : n → α) (i : n) :
cramer A b i = b i := by rw [cramer_apply, det_eq_elem_of_subsingleton _ i, updateCol_self]
theorem cramer_zero [Nontrivial n] : cramer (0 : Matrix n n α) = 0 := by
ext i j
obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j
apply det_eq_zero_of_column_eq_zero j'
intro j''
simp [updateCol_ne hj']
/-- Use linearity of `cramer` to take it out of a summation. -/
theorem sum_cramer {β} (s : Finset β) (f : β → n → α) :
(∑ x ∈ s, cramer A (f x)) = cramer A (∑ x ∈ s, f x) :=
(map_sum (cramer A) ..).symm
/-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/
theorem sum_cramer_apply {β} (s : Finset β) (f : n → β → α) (i : n) :
(∑ x ∈ s, cramer A (fun j => f j x) i) = cramer A (fun j : n => ∑ x ∈ s, f j x) i :=
calc
(∑ x ∈ s, cramer A (fun j => f j x) i) = (∑ x ∈ s, cramer A fun j => f j x) i :=
(Finset.sum_apply i s _).symm
_ = cramer A (fun j : n => ∑ x ∈ s, f j x) i := by
rw [sum_cramer, cramer_apply, cramer_apply]
simp only [updateCol]
congr with j
congr
apply Finset.sum_apply
theorem cramer_submatrix_equiv (A : Matrix m m α) (e : n ≃ m) (b : n → α) :
cramer (A.submatrix e e) b = cramer A (b ∘ e.symm) ∘ e := by
ext i
simp_rw [Function.comp_apply, cramer_apply, updateCol_submatrix_equiv,
det_submatrix_equiv_self e, Function.comp_def]
theorem cramer_reindex (e : m ≃ n) (A : Matrix m m α) (b : n → α) :
cramer (reindex e e A) b = cramer A (b ∘ e) ∘ e.symm :=
cramer_submatrix_equiv _ _ _
end Cramer
section Adjugate
/-!
### `adjugate` section
Define the `adjugate` matrix and a few equations.
These will hold for any matrix over a commutative ring.
-/
/-- The adjugate matrix is the transpose of the cofactor matrix.
Typically, the cofactor matrix is defined by taking minors,
i.e. the determinant of the matrix with a row and column removed.
However, the proof of `mul_adjugate` becomes a lot easier if we use the
matrix replacing a column with a basis vector, since it allows us to use
facts about the `cramer` map.
-/
def adjugate (A : Matrix n n α) : Matrix n n α :=
of fun i => cramer Aᵀ (Pi.single i 1)
theorem adjugate_def (A : Matrix n n α) : adjugate A = of fun i => cramer Aᵀ (Pi.single i 1) :=
rfl
theorem adjugate_apply (A : Matrix n n α) (i j : n) :
adjugate A i j = (A.updateRow j (Pi.single i 1)).det := by
rw [adjugate_def, of_apply, cramer_apply, updateCol_transpose, det_transpose]
theorem adjugate_transpose (A : Matrix n n α) : (adjugate A)ᵀ = adjugate Aᵀ := by
ext i j
rw [transpose_apply, adjugate_apply, adjugate_apply, updateRow_transpose, det_transpose]
rw [det_apply', det_apply']
apply Finset.sum_congr rfl
intro σ _
congr 1
by_cases h : i = σ j
· -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`.
congr
ext j'
subst h
have : σ j' = σ j ↔ j' = j := σ.injective.eq_iff
rw [updateRow_apply, updateCol_apply]
simp_rw [this]
rw [← dite_eq_ite, ← dite_eq_ite]
congr 1 with rfl
rw [Pi.single_eq_same, Pi.single_eq_same]
· -- Otherwise, we need to show that there is a `0` somewhere in the product.
have : (∏ j' : n, updateCol A j (Pi.single i 1) (σ j') j') = 0 := by
apply prod_eq_zero (mem_univ j)
rw [updateCol_self, Pi.single_eq_of_ne' h]
rw [this]
apply prod_eq_zero (mem_univ (σ⁻¹ i))
erw [apply_symm_apply σ i, updateRow_self]
apply Pi.single_eq_of_ne
intro h'
exact h ((symm_apply_eq σ).mp h')
@[simp]
theorem adjugate_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m α) :
adjugate (A.submatrix e e) = (adjugate A).submatrix e e := by
ext i j
have : (fun j ↦ Pi.single i 1 <| e.symm j) = Pi.single (e i) 1 :=
Function.update_comp_equiv (0 : n → α) e.symm i 1
rw [adjugate_apply, submatrix_apply, adjugate_apply, ← det_submatrix_equiv_self e,
updateRow_submatrix_equiv, this]
theorem adjugate_reindex (e : m ≃ n) (A : Matrix m m α) :
adjugate (reindex e e A) = reindex e e (adjugate A) :=
adjugate_submatrix_equiv_self _ _
/-- Since the map `b ↦ cramer A b` is linear in `b`, it must be multiplication by some matrix. This
matrix is `A.adjugate`. -/
theorem cramer_eq_adjugate_mulVec (A : Matrix n n α) (b : n → α) :
cramer A b = A.adjugate *ᵥ b := by
nth_rw 2 [← A.transpose_transpose]
rw [← adjugate_transpose, adjugate_def]
have : b = ∑ i, b i • (Pi.single i 1 : n → α) := by
refine (pi_eq_sum_univ b).trans ?_
congr with j
simp [Pi.single_apply, eq_comm]
conv_lhs =>
rw [this]
ext k
simp [mulVec, dotProduct, mul_comm]
theorem mul_adjugate_apply (A : Matrix n n α) (i j k) :
A i k * adjugate A k j = cramer Aᵀ (Pi.single k (A i k)) j := by
rw [← smul_eq_mul, adjugate, of_apply, ← Pi.smul_apply, ← LinearMap.map_smul, ← Pi.single_smul',
smul_eq_mul, mul_one]
theorem mul_adjugate (A : Matrix n n α) : A * adjugate A = A.det • (1 : Matrix n n α) := by
ext i j
rw [mul_apply, Pi.smul_apply, Pi.smul_apply, one_apply, smul_eq_mul, mul_boole]
simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, Pi.single_apply, eq_comm]
theorem adjugate_mul (A : Matrix n n α) : adjugate A * A = A.det • (1 : Matrix n n α) :=
calc
adjugate A * A = (Aᵀ * adjugate Aᵀ)ᵀ := by
rw [← adjugate_transpose, ← transpose_mul, transpose_transpose]
_ = _ := by rw [mul_adjugate Aᵀ, det_transpose, transpose_smul, transpose_one]
theorem adjugate_smul (r : α) (A : Matrix n n α) :
adjugate (r • A) = r ^ (Fintype.card n - 1) • adjugate A := by
rw [adjugate, adjugate, transpose_smul, cramer_smul]
rfl
/-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A * x = b` even
if the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det`
divides `b`. -/
@[simp]
theorem mulVec_cramer (A : Matrix n n α) (b : n → α) : A *ᵥ cramer A b = A.det • b := by
rw [cramer_eq_adjugate_mulVec, mulVec_mulVec, mul_adjugate, smul_mulVec_assoc, one_mulVec]
theorem adjugate_subsingleton [Subsingleton n] (A : Matrix n n α) : adjugate A = 1 := by
ext i j
simp [Subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i, one_apply]
theorem adjugate_eq_one_of_card_eq_one {A : Matrix n n α} (h : Fintype.card n = 1) :
adjugate A = 1 :=
haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le
adjugate_subsingleton _
@[simp]
theorem adjugate_zero [Nontrivial n] : adjugate (0 : Matrix n n α) = 0 := by
ext i j
obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j
apply det_eq_zero_of_column_eq_zero j'
intro j''
simp [updateCol_ne hj']
@[simp]
theorem adjugate_one : adjugate (1 : Matrix n n α) = 1 := by
ext
simp [adjugate_def, Matrix.one_apply, Pi.single_apply, eq_comm]
@[simp]
theorem adjugate_diagonal (v : n → α) :
adjugate (diagonal v) = diagonal fun i => ∏ j ∈ Finset.univ.erase i, v j := by
ext i j
simp only [adjugate_def, cramer_apply, diagonal_transpose, of_apply]
obtain rfl | hij := eq_or_ne i j
· rw [diagonal_apply_eq, diagonal_updateCol_single, det_diagonal,
prod_update_of_mem (Finset.mem_univ _), sdiff_singleton_eq_erase, one_mul]
· rw [diagonal_apply_ne _ hij]
refine det_eq_zero_of_row_eq_zero j fun k => ?_
obtain rfl | hjk := eq_or_ne k j
· rw [updateCol_self, Pi.single_eq_of_ne' hij]
· rw [updateCol_ne hjk, diagonal_apply_ne' _ hjk]
theorem _root_.RingHom.map_adjugate {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S)
(M : Matrix n n R) : f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) := by
ext i k
have : Pi.single i (1 : S) = f ∘ Pi.single i 1 := by
rw [← f.map_one]
exact Pi.single_op (fun _ => f) (fun _ => f.map_zero) i (1 : R)
rw [adjugate_apply, RingHom.mapMatrix_apply, map_apply, RingHom.mapMatrix_apply, this, ←
map_updateRow, ← RingHom.mapMatrix_apply, ← RingHom.map_det, ← adjugate_apply]
| Mathlib/LinearAlgebra/Matrix/Adjugate.lean | 327 | 332 | theorem _root_.AlgHom.map_adjugate {R A B : Type*} [CommSemiring R] [CommRing A] [CommRing B]
[Algebra R A] [Algebra R B] (f : A →ₐ[R] B) (M : Matrix n n A) :
f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) :=
f.toRingHom.map_adjugate _
theorem det_adjugate (A : Matrix n n α) : (adjugate A).det = A.det ^ (Fintype.card n - 1) := by | |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov, Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
import Mathlib.MeasureTheory.Measure.Typeclasses.Probability
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Order.LeftRightLim
/-!
# Stieltjes measures on the real line
Consider a function `f : ℝ → ℝ` which is monotone and right-continuous. Then one can define a
corresponding measure, giving mass `f b - f a` to the interval `(a, b]`.
## Main definitions
* `StieltjesFunction` is a structure containing a function from `ℝ → ℝ`, together with the
assertions that it is monotone and right-continuous. To `f : StieltjesFunction`, one associates
a Borel measure `f.measure`.
* `f.measure_Ioc` asserts that `f.measure (Ioc a b) = ofReal (f b - f a)`
* `f.measure_Ioo` asserts that `f.measure (Ioo a b) = ofReal (leftLim f b - f a)`.
* `f.measure_Icc` and `f.measure_Ico` are analogous.
-/
noncomputable section
open Set Filter Function ENNReal NNReal Topology MeasureTheory
open ENNReal (ofReal)
/-! ### Basic properties of Stieltjes functions -/
/-- Bundled monotone right-continuous real functions, used to construct Stieltjes measures. -/
structure StieltjesFunction where
toFun : ℝ → ℝ
mono' : Monotone toFun
right_continuous' : ∀ x, ContinuousWithinAt toFun (Ici x) x
namespace StieltjesFunction
attribute [coe] toFun
instance instCoeFun : CoeFun StieltjesFunction fun _ => ℝ → ℝ :=
⟨toFun⟩
initialize_simps_projections StieltjesFunction (toFun → apply)
@[ext] lemma ext {f g : StieltjesFunction} (h : ∀ x, f x = g x) : f = g := by
exact (StieltjesFunction.mk.injEq ..).mpr (funext h)
variable (f : StieltjesFunction)
theorem mono : Monotone f :=
f.mono'
theorem right_continuous (x : ℝ) : ContinuousWithinAt f (Ici x) x :=
f.right_continuous' x
theorem rightLim_eq (f : StieltjesFunction) (x : ℝ) : Function.rightLim f x = f x := by
rw [← f.mono.continuousWithinAt_Ioi_iff_rightLim_eq, continuousWithinAt_Ioi_iff_Ici]
exact f.right_continuous' x
theorem iInf_Ioi_eq (f : StieltjesFunction) (x : ℝ) : ⨅ r : Ioi x, f r = f x := by
suffices Function.rightLim f x = ⨅ r : Ioi x, f r by rw [← this, f.rightLim_eq]
rw [f.mono.rightLim_eq_sInf, sInf_image']
rw [← neBot_iff]
infer_instance
theorem iInf_rat_gt_eq (f : StieltjesFunction) (x : ℝ) :
⨅ r : { r' : ℚ // x < r' }, f r = f x := by
rw [← iInf_Ioi_eq f x]
refine (Real.iInf_Ioi_eq_iInf_rat_gt _ ?_ f.mono).symm
refine ⟨f x, fun y => ?_⟩
rintro ⟨y, hy_mem, rfl⟩
exact f.mono (le_of_lt hy_mem)
/-- The identity of `ℝ` as a Stieltjes function, used to construct Lebesgue measure. -/
@[simps]
protected def id : StieltjesFunction where
toFun := id
mono' _ _ := id
right_continuous' _ := continuousWithinAt_id
@[simp]
theorem id_leftLim (x : ℝ) : leftLim StieltjesFunction.id x = x :=
tendsto_nhds_unique (StieltjesFunction.id.mono.tendsto_leftLim x) <|
continuousAt_id.tendsto.mono_left nhdsWithin_le_nhds
instance instInhabited : Inhabited StieltjesFunction :=
⟨StieltjesFunction.id⟩
/-- Constant functions are Stieltjes function. -/
protected def const (c : ℝ) : StieltjesFunction where
toFun := fun _ ↦ c
mono' _ _ := by simp
right_continuous' _ := continuousWithinAt_const
@[simp] lemma const_apply (c x : ℝ) : (StieltjesFunction.const c) x = c := rfl
/-- The sum of two Stieltjes functions is a Stieltjes function. -/
protected def add (f g : StieltjesFunction) : StieltjesFunction where
toFun := fun x => f x + g x
mono' := f.mono.add g.mono
right_continuous' := fun x => (f.right_continuous x).add (g.right_continuous x)
instance : AddZeroClass StieltjesFunction where
add := StieltjesFunction.add
zero := StieltjesFunction.const 0
zero_add _ := ext fun _ ↦ zero_add _
add_zero _ := ext fun _ ↦ add_zero _
instance : AddCommMonoid StieltjesFunction where
nsmul n f := nsmulRec n f
add_assoc _ _ _ := ext fun _ ↦ add_assoc _ _ _
add_comm _ _ := ext fun _ ↦ add_comm _ _
__ := StieltjesFunction.instAddZeroClass
instance : Module ℝ≥0 StieltjesFunction where
smul c f := {
toFun := fun x ↦ c * f x
mono' := f.mono.const_mul c.2
right_continuous' := fun x ↦ (f.right_continuous x).const_smul c.1}
one_smul _ := ext fun _ ↦ one_mul _
mul_smul _ _ _ := ext fun _ ↦ mul_assoc _ _ _
smul_zero _ := ext fun _ ↦ mul_zero _
smul_add _ _ _ := ext fun _ ↦ mul_add _ _ _
add_smul _ _ _ := ext fun _ ↦ add_mul _ _ _
zero_smul _ := ext fun _ ↦ zero_mul _
@[simp] lemma zero_apply (x : ℝ) : (0 : StieltjesFunction) x = 0 := rfl
@[simp] lemma add_apply (f g : StieltjesFunction) (x : ℝ) : (f + g) x = f x + g x := rfl
/-- If a function `f : ℝ → ℝ` is monotone, then the function mapping `x` to the right limit of `f`
at `x` is a Stieltjes function, i.e., it is monotone and right-continuous. -/
noncomputable def _root_.Monotone.stieltjesFunction {f : ℝ → ℝ} (hf : Monotone f) :
StieltjesFunction where
toFun := rightLim f
mono' _ _ hxy := hf.rightLim hxy
right_continuous' := by
intro x s hs
obtain ⟨l, u, hlu, lus⟩ : ∃ l u : ℝ, rightLim f x ∈ Ioo l u ∧ Ioo l u ⊆ s :=
mem_nhds_iff_exists_Ioo_subset.1 hs
obtain ⟨y, xy, h'y⟩ : ∃ (y : ℝ), x < y ∧ Ioc x y ⊆ f ⁻¹' Ioo l u :=
mem_nhdsGT_iff_exists_Ioc_subset.1 (hf.tendsto_rightLim x (Ioo_mem_nhds hlu.1 hlu.2))
change ∀ᶠ y in 𝓝[≥] x, rightLim f y ∈ s
filter_upwards [Ico_mem_nhdsGE xy] with z hz
apply lus
refine ⟨hlu.1.trans_le (hf.rightLim hz.1), ?_⟩
obtain ⟨a, za, ay⟩ : ∃ a : ℝ, z < a ∧ a < y := exists_between hz.2
calc
rightLim f z ≤ f a := hf.rightLim_le za
_ < u := (h'y ⟨hz.1.trans_lt za, ay.le⟩).2
theorem _root_.Monotone.stieltjesFunction_eq {f : ℝ → ℝ} (hf : Monotone f) (x : ℝ) :
hf.stieltjesFunction x = rightLim f x :=
rfl
theorem countable_leftLim_ne (f : StieltjesFunction) : Set.Countable { x | leftLim f x ≠ f x } := by
refine Countable.mono ?_ f.mono.countable_not_continuousAt
intro x hx h'x
apply hx
exact tendsto_nhds_unique (f.mono.tendsto_leftLim x) (h'x.tendsto.mono_left nhdsWithin_le_nhds)
/-! ### The outer measure associated to a Stieltjes function -/
/-- Length of an interval. This is the largest monotone function which correctly measures all
intervals. -/
def length (s : Set ℝ) : ℝ≥0∞ :=
⨅ (a) (b) (_ : s ⊆ Ioc a b), ofReal (f b - f a)
@[simp]
theorem length_empty : f.length ∅ = 0 :=
nonpos_iff_eq_zero.1 <| iInf_le_of_le 0 <| iInf_le_of_le 0 <| by simp
@[simp]
theorem length_Ioc (a b : ℝ) : f.length (Ioc a b) = ofReal (f b - f a) := by
refine
le_antisymm (iInf_le_of_le a <| iInf₂_le b Subset.rfl)
(le_iInf fun a' => le_iInf fun b' => le_iInf fun h => ENNReal.coe_le_coe.2 ?_)
rcases le_or_lt b a with ab | ab
· rw [Real.toNNReal_of_nonpos (sub_nonpos.2 (f.mono ab))]
apply zero_le
obtain ⟨h₁, h₂⟩ := (Ioc_subset_Ioc_iff ab).1 h
exact Real.toNNReal_le_toNNReal (sub_le_sub (f.mono h₁) (f.mono h₂))
theorem length_mono {s₁ s₂ : Set ℝ} (h : s₁ ⊆ s₂) : f.length s₁ ≤ f.length s₂ :=
iInf_mono fun _ => biInf_mono fun _ => h.trans
open MeasureTheory
/-- The Stieltjes outer measure associated to a Stieltjes function. -/
protected def outer : OuterMeasure ℝ :=
OuterMeasure.ofFunction f.length f.length_empty
theorem outer_le_length (s : Set ℝ) : f.outer s ≤ f.length s :=
OuterMeasure.ofFunction_le _
/-- If a compact interval `[a, b]` is covered by a union of open interval `(c i, d i)`, then
`f b - f a ≤ ∑ f (d i) - f (c i)`. This is an auxiliary technical statement to prove the same
statement for half-open intervals, the point of the current statement being that one can use
compactness to reduce it to a finite sum, and argue by induction on the size of the covering set. -/
theorem length_subadditive_Icc_Ioo {a b : ℝ} {c d : ℕ → ℝ} (ss : Icc a b ⊆ ⋃ i, Ioo (c i) (d i)) :
ofReal (f b - f a) ≤ ∑' i, ofReal (f (d i) - f (c i)) := by
suffices
∀ (s : Finset ℕ) (b), Icc a b ⊆ (⋃ i ∈ (s : Set ℕ), Ioo (c i) (d i)) →
(ofReal (f b - f a) : ℝ≥0∞) ≤ ∑ i ∈ s, ofReal (f (d i) - f (c i)) by
rcases isCompact_Icc.elim_finite_subcover_image
(fun (i : ℕ) (_ : i ∈ univ) => @isOpen_Ioo _ _ _ _ (c i) (d i)) (by simpa using ss) with
⟨s, _, hf, hs⟩
have e : ⋃ i ∈ (hf.toFinset : Set ℕ), Ioo (c i) (d i) = ⋃ i ∈ s, Ioo (c i) (d i) := by
simp only [Set.ext_iff, exists_prop, Finset.set_biUnion_coe, mem_iUnion, forall_const,
Finite.mem_toFinset]
rw [ENNReal.tsum_eq_iSup_sum]
refine le_trans ?_ (le_iSup _ hf.toFinset)
exact this hf.toFinset _ (by simpa only [e] )
clear ss b
refine fun s => Finset.strongInductionOn s fun s IH b cv => ?_
rcases le_total b a with ab | ab
· rw [ENNReal.ofReal_eq_zero.2 (sub_nonpos.2 (f.mono ab))]
exact zero_le _
have := cv ⟨ab, le_rfl⟩
simp only [Finset.mem_coe, gt_iff_lt, not_lt, mem_iUnion, mem_Ioo, exists_and_left,
exists_prop] at this
rcases this with ⟨i, cb, is, bd⟩
rw [← Finset.insert_erase is] at cv ⊢
rw [Finset.coe_insert, biUnion_insert] at cv
rw [Finset.sum_insert (Finset.not_mem_erase _ _)]
refine le_trans ?_ (add_le_add_left (IH _ (Finset.erase_ssubset is) (c i) ?_) _)
· refine le_trans (ENNReal.ofReal_le_ofReal ?_) ENNReal.ofReal_add_le
rw [sub_add_sub_cancel]
exact sub_le_sub_right (f.mono bd.le) _
· rintro x ⟨h₁, h₂⟩
exact (cv ⟨h₁, le_trans h₂ (le_of_lt cb)⟩).resolve_left (mt And.left (not_lt_of_le h₂))
@[simp]
theorem outer_Ioc (a b : ℝ) : f.outer (Ioc a b) = ofReal (f b - f a) := by
/- It suffices to show that, if `(a, b]` is covered by sets `s i`, then `f b - f a` is bounded
by `∑ f.length (s i) + ε`. The difficulty is that `f.length` is expressed in terms of half-open
intervals, while we would like to have a compact interval covered by open intervals to use
compactness and finite sums, as provided by `length_subadditive_Icc_Ioo`. The trick is to use
the right-continuity of `f`. If `a'` is close enough to `a` on its right, then `[a', b]` is
still covered by the sets `s i` and moreover `f b - f a'` is very close to `f b - f a`
(up to `ε/2`).
Also, by definition one can cover `s i` by a half-closed interval `(p i, q i]` with `f`-length
very close to that of `s i` (within a suitably small `ε' i`, say). If one moves `q i` very
slightly to the right, then the `f`-length will change very little by right continuity, and we
will get an open interval `(p i, q' i)` covering `s i` with `f (q' i) - f (p i)` within `ε' i`
of the `f`-length of `s i`. -/
refine
le_antisymm
(by
rw [← f.length_Ioc]
apply outer_le_length)
(le_iInf₂ fun s hs => ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_)
let δ := ε / 2
have δpos : 0 < (δ : ℝ≥0∞) := by simpa [δ] using εpos.ne'
rcases ENNReal.exists_pos_sum_of_countable δpos.ne' ℕ with ⟨ε', ε'0, hε⟩
obtain ⟨a', ha', aa'⟩ : ∃ a', f a' - f a < δ ∧ a < a' := by
have A : ContinuousWithinAt (fun r => f r - f a) (Ioi a) a := by
refine ContinuousWithinAt.sub ?_ continuousWithinAt_const
exact (f.right_continuous a).mono Ioi_subset_Ici_self
have B : f a - f a < δ := by rwa [sub_self, NNReal.coe_pos, ← ENNReal.coe_pos]
exact (((tendsto_order.1 A).2 _ B).and self_mem_nhdsWithin).exists
have : ∀ i, ∃ p : ℝ × ℝ, s i ⊆ Ioo p.1 p.2 ∧
(ofReal (f p.2 - f p.1) : ℝ≥0∞) < f.length (s i) + ε' i := by
intro i
have hl :=
ENNReal.lt_add_right ((ENNReal.le_tsum i).trans_lt h).ne (ENNReal.coe_ne_zero.2 (ε'0 i).ne')
conv at hl =>
lhs
rw [length]
simp only [iInf_lt_iff, exists_prop] at hl
rcases hl with ⟨p, q', spq, hq'⟩
have : ContinuousWithinAt (fun r => ofReal (f r - f p)) (Ioi q') q' := by
apply ENNReal.continuous_ofReal.continuousAt.comp_continuousWithinAt
refine ContinuousWithinAt.sub ?_ continuousWithinAt_const
exact (f.right_continuous q').mono Ioi_subset_Ici_self
rcases (((tendsto_order.1 this).2 _ hq').and self_mem_nhdsWithin).exists with ⟨q, hq, q'q⟩
exact ⟨⟨p, q⟩, spq.trans (Ioc_subset_Ioo_right q'q), hq⟩
choose g hg using this
have I_subset : Icc a' b ⊆ ⋃ i, Ioo (g i).1 (g i).2 :=
calc
Icc a' b ⊆ Ioc a b := fun x hx => ⟨aa'.trans_le hx.1, hx.2⟩
_ ⊆ ⋃ i, s i := hs
_ ⊆ ⋃ i, Ioo (g i).1 (g i).2 := iUnion_mono fun i => (hg i).1
calc
ofReal (f b - f a) = ofReal (f b - f a' + (f a' - f a)) := by rw [sub_add_sub_cancel]
_ ≤ ofReal (f b - f a') + ofReal (f a' - f a) := ENNReal.ofReal_add_le
_ ≤ ∑' i, ofReal (f (g i).2 - f (g i).1) + ofReal δ :=
(add_le_add (f.length_subadditive_Icc_Ioo I_subset) (ENNReal.ofReal_le_ofReal ha'.le))
_ ≤ ∑' i, (f.length (s i) + ε' i) + δ :=
(add_le_add (ENNReal.tsum_le_tsum fun i => (hg i).2.le)
(by simp only [ENNReal.ofReal_coe_nnreal, le_rfl]))
_ = ∑' i, f.length (s i) + ∑' i, (ε' i : ℝ≥0∞) + δ := by rw [ENNReal.tsum_add]
_ ≤ ∑' i, f.length (s i) + δ + δ := add_le_add (add_le_add le_rfl hε.le) le_rfl
_ = ∑' i : ℕ, f.length (s i) + ε := by simp [δ, add_assoc, ENNReal.add_halves]
theorem measurableSet_Ioi {c : ℝ} : MeasurableSet[f.outer.caratheodory] (Ioi c) := by
refine OuterMeasure.ofFunction_caratheodory fun t => ?_
refine le_iInf fun a => le_iInf fun b => le_iInf fun h => ?_
refine
le_trans
(add_le_add (f.length_mono <| inter_subset_inter_left _ h)
(f.length_mono <| diff_subset_diff_left h)) ?_
rcases le_total a c with hac | hac <;> rcases le_total b c with hbc | hbc
· simp only [Ioc_inter_Ioi, f.length_Ioc, hac, hbc, le_refl, Ioc_eq_empty,
max_eq_right, min_eq_left, Ioc_diff_Ioi, f.length_empty, zero_add, not_lt]
· simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right,
← ENNReal.ofReal_add, f.mono hac, f.mono hbc, sub_nonneg,
sub_add_sub_cancel, le_refl,
max_eq_right]
· simp only [hbc, le_refl, Ioc_eq_empty, Ioc_inter_Ioi, min_eq_left, Ioc_diff_Ioi, f.length_empty,
zero_add, or_true, le_sup_iff, f.length_Ioc, not_lt]
· simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right,
le_refl, Ioc_eq_empty, add_zero, max_eq_left, f.length_empty, not_lt]
theorem outer_trim : f.outer.trim = f.outer := by
refine le_antisymm (fun s => ?_) (OuterMeasure.le_trim _)
rw [OuterMeasure.trim_eq_iInf]
refine le_iInf fun t => le_iInf fun ht => ENNReal.le_of_forall_pos_le_add fun ε ε0 h => ?_
rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 ε0).ne' ℕ with ⟨ε', ε'0, hε⟩
refine le_trans ?_ (add_le_add_left (le_of_lt hε) _)
rw [← ENNReal.tsum_add]
choose g hg using
show ∀ i, ∃ s, t i ⊆ s ∧ MeasurableSet s ∧ f.outer s ≤ f.length (t i) + ofReal (ε' i) by
intro i
have hl :=
ENNReal.lt_add_right ((ENNReal.le_tsum i).trans_lt h).ne (ENNReal.coe_pos.2 (ε'0 i)).ne'
conv at hl =>
lhs
rw [length]
simp only [iInf_lt_iff] at hl
rcases hl with ⟨a, b, h₁, h₂⟩
rw [← f.outer_Ioc] at h₂
exact ⟨_, h₁, measurableSet_Ioc, le_of_lt <| by simpa using h₂⟩
simp only [ofReal_coe_nnreal] at hg
apply iInf_le_of_le (iUnion g) _
apply iInf_le_of_le (ht.trans <| iUnion_mono fun i => (hg i).1) _
apply iInf_le_of_le (MeasurableSet.iUnion fun i => (hg i).2.1) _
exact le_trans (measure_iUnion_le _) (ENNReal.tsum_le_tsum fun i => (hg i).2.2)
theorem borel_le_measurable : borel ℝ ≤ f.outer.caratheodory := by
rw [borel_eq_generateFrom_Ioi]
refine MeasurableSpace.generateFrom_le ?_
simp +contextual [f.measurableSet_Ioi]
/-! ### The measure associated to a Stieltjes function -/
/-- The measure associated to a Stieltjes function, giving mass `f b - f a` to the
interval `(a, b]`. -/
protected irreducible_def measure : Measure ℝ where
toOuterMeasure := f.outer
m_iUnion _s hs := f.outer.iUnion_eq_of_caratheodory fun i => f.borel_le_measurable _ (hs i)
trim_le := f.outer_trim.le
@[simp]
theorem measure_Ioc (a b : ℝ) : f.measure (Ioc a b) = ofReal (f b - f a) := by
rw [StieltjesFunction.measure]
exact f.outer_Ioc a b
@[simp]
theorem measure_singleton (a : ℝ) : f.measure {a} = ofReal (f a - leftLim f a) := by
obtain ⟨u, u_mono, u_lt_a, u_lim⟩ :
∃ u : ℕ → ℝ, StrictMono u ∧ (∀ n : ℕ, u n < a) ∧ Tendsto u atTop (𝓝 a) :=
exists_seq_strictMono_tendsto a
have A : {a} = ⋂ n, Ioc (u n) a := by
refine Subset.antisymm (fun x hx => by simp [mem_singleton_iff.1 hx, u_lt_a]) fun x hx => ?_
simp? at hx says simp only [mem_iInter, mem_Ioc] at hx
have : a ≤ x := le_of_tendsto' u_lim fun n => (hx n).1.le
simp [le_antisymm this (hx 0).2]
have L1 : Tendsto (fun n => f.measure (Ioc (u n) a)) atTop (𝓝 (f.measure {a})) := by
rw [A]
refine tendsto_measure_iInter_atTop (fun n => nullMeasurableSet_Ioc)
(fun m n hmn => ?_) ?_
· exact Ioc_subset_Ioc_left (u_mono.monotone hmn)
· exact ⟨0, by simpa only [measure_Ioc] using ENNReal.ofReal_ne_top⟩
have L2 :
Tendsto (fun n => f.measure (Ioc (u n) a)) atTop (𝓝 (ofReal (f a - leftLim f a))) := by
simp only [measure_Ioc]
have : Tendsto (fun n => f (u n)) atTop (𝓝 (leftLim f a)) := by
apply (f.mono.tendsto_leftLim a).comp
exact
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ u_lim
(Eventually.of_forall fun n => u_lt_a n)
exact ENNReal.continuous_ofReal.continuousAt.tendsto.comp (tendsto_const_nhds.sub this)
exact tendsto_nhds_unique L1 L2
@[simp]
theorem measure_Icc (a b : ℝ) : f.measure (Icc a b) = ofReal (f b - leftLim f a) := by
rcases le_or_lt a b with (hab | hab)
· have A : Disjoint {a} (Ioc a b) := by simp
simp [← Icc_union_Ioc_eq_Icc le_rfl hab, -singleton_union, ← ENNReal.ofReal_add,
f.mono.leftLim_le, measure_union A measurableSet_Ioc, f.mono hab]
· simp only [hab, measure_empty, Icc_eq_empty, not_le]
symm
simp [ENNReal.ofReal_eq_zero, f.mono.le_leftLim hab]
@[simp]
theorem measure_Ioo {a b : ℝ} : f.measure (Ioo a b) = ofReal (leftLim f b - f a) := by
rcases le_or_lt b a with (hab | hab)
· simp only [hab, measure_empty, Ioo_eq_empty, not_lt]
symm
simp [ENNReal.ofReal_eq_zero, f.mono.leftLim_le hab]
· have A : Disjoint (Ioo a b) {b} := by simp
have D : f b - f a = f b - leftLim f b + (leftLim f b - f a) := by abel
have := f.measure_Ioc a b
simp only [← Ioo_union_Icc_eq_Ioc hab le_rfl, measure_singleton,
measure_union A (measurableSet_singleton b), Icc_self] at this
rw [D, ENNReal.ofReal_add, add_comm] at this
· simpa only [ENNReal.add_right_inj ENNReal.ofReal_ne_top]
· simp only [f.mono.leftLim_le le_rfl, sub_nonneg]
· simp only [f.mono.le_leftLim hab, sub_nonneg]
@[simp]
theorem measure_Ico (a b : ℝ) : f.measure (Ico a b) = ofReal (leftLim f b - leftLim f a) := by
rcases le_or_lt b a with (hab | hab)
· simp only [hab, measure_empty, Ico_eq_empty, not_lt]
symm
simp [ENNReal.ofReal_eq_zero, f.mono.leftLim hab]
· have A : Disjoint {a} (Ioo a b) := by simp
simp [← Icc_union_Ioo_eq_Ico le_rfl hab, -singleton_union, hab.ne, f.mono.leftLim_le,
measure_union A measurableSet_Ioo, f.mono.le_leftLim hab, ← ENNReal.ofReal_add]
theorem measure_Iic {l : ℝ} (hf : Tendsto f atBot (𝓝 l)) (x : ℝ) :
f.measure (Iic x) = ofReal (f x - l) := by
refine tendsto_nhds_unique (tendsto_measure_Ioc_atBot _ _) ?_
simp_rw [measure_Ioc]
exact ENNReal.tendsto_ofReal (Tendsto.const_sub _ hf)
lemma measure_Iio {l : ℝ} (hf : Tendsto f atBot (𝓝 l)) (x : ℝ) :
f.measure (Iio x) = ofReal (leftLim f x - l) := by
rw [← Iic_diff_right, measure_diff _ (nullMeasurableSet_singleton x), measure_singleton,
f.measure_Iic hf, ← ofReal_sub _ (sub_nonneg.mpr <| Monotone.leftLim_le f.mono' le_rfl)]
<;> simp
theorem measure_Ici {l : ℝ} (hf : Tendsto f atTop (𝓝 l)) (x : ℝ) :
f.measure (Ici x) = ofReal (l - leftLim f x) := by
refine tendsto_nhds_unique (tendsto_measure_Ico_atTop _ _) ?_
simp_rw [measure_Ico]
refine ENNReal.tendsto_ofReal (Tendsto.sub_const ?_ _)
have h_le1 : ∀ x, f (x - 1) ≤ leftLim f x := fun x => Monotone.le_leftLim f.mono (sub_one_lt x)
have h_le2 : ∀ x, leftLim f x ≤ f x := fun x => Monotone.leftLim_le f.mono le_rfl
refine tendsto_of_tendsto_of_tendsto_of_le_of_le (hf.comp ?_) hf h_le1 h_le2
rw [tendsto_atTop_atTop]
exact fun y => ⟨y + 1, fun z hyz => by rwa [le_sub_iff_add_le]⟩
lemma measure_Ioi {l : ℝ} (hf : Tendsto f atTop (𝓝 l)) (x : ℝ) :
f.measure (Ioi x) = ofReal (l - f x) := by
rw [← Ici_diff_left, measure_diff _ (nullMeasurableSet_singleton x), measure_singleton,
f.measure_Ici hf, ← ofReal_sub _ (sub_nonneg.mpr <| Monotone.leftLim_le f.mono' le_rfl)]
<;> simp
lemma measure_Ioi_of_tendsto_atTop_atTop (hf : Tendsto f atTop atTop) (x : ℝ) :
f.measure (Ioi x) = ∞ := by
refine ENNReal.eq_top_of_forall_nnreal_le fun r ↦ ?_
obtain ⟨N, hN⟩ := eventually_atTop.mp (tendsto_atTop.mp hf (r + f x))
exact (f.measure_Ioc x (max x N) ▸ ENNReal.coe_nnreal_eq r ▸ (ENNReal.ofReal_le_ofReal <|
le_tsub_of_add_le_right <| hN _ (le_max_right x N))).trans (measure_mono Ioc_subset_Ioi_self)
lemma measure_Ici_of_tendsto_atTop_atTop (hf : Tendsto f atTop atTop) (x : ℝ) :
f.measure (Ici x) = ∞ := by
rw [← top_le_iff, ← f.measure_Ioi_of_tendsto_atTop_atTop hf x]
exact measure_mono Ioi_subset_Ici_self
lemma measure_Iic_of_tendsto_atBot_atBot (hf : Tendsto f atBot atBot) (x : ℝ) :
f.measure (Iic x) = ∞ := by
refine ENNReal.eq_top_of_forall_nnreal_le fun r ↦ ?_
obtain ⟨N, hN⟩ := eventually_atBot.mp (tendsto_atBot.mp hf (f x - r))
exact (f.measure_Ioc (min x N) x ▸ ENNReal.coe_nnreal_eq r ▸ (ENNReal.ofReal_le_ofReal <|
le_sub_comm.mp <| hN _ (min_le_right x N))).trans (measure_mono Ioc_subset_Iic_self)
lemma measure_Iio_of_tendsto_atBot_atBot (hf : Tendsto f atBot atBot) (x : ℝ) :
f.measure (Iio x) = ∞ := by
rw [← top_le_iff, ← f.measure_Iic_of_tendsto_atBot_atBot hf (x - 1)]
exact measure_mono <| Set.Iic_subset_Iio.mpr <| sub_one_lt x
| Mathlib/MeasureTheory/Measure/Stieltjes.lean | 484 | 488 | theorem measure_univ {l u : ℝ} (hfl : Tendsto f atBot (𝓝 l)) (hfu : Tendsto f atTop (𝓝 u)) :
f.measure univ = ofReal (u - l) := by | refine tendsto_nhds_unique (tendsto_measure_Iic_atTop _) ?_
simp_rw [measure_Iic f hfl]
exact ENNReal.tendsto_ofReal (Tendsto.sub_const hfu _) |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sort
/-!
# Compositions
A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum
of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into
non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks.
This notion is closely related to that of a partition of `n`, but in a composition of `n` the
order of the `iⱼ`s matters.
We implement two different structures covering these two viewpoints on compositions. The first
one, made of a list of positive integers summing to `n`, is the main one and is called
`Composition n`. The second one is useful for combinatorial arguments (for instance to show that
the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`
containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost
points of each block. The main API is built on `Composition n`, and we provide an equivalence
between the two types.
## Main functions
* `c : Composition n` is a structure, made of a list of integers which are all positive and
add up to `n`.
* `composition_card` states that the cardinality of `Composition n` is exactly
`2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which
is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is
nat subtraction).
Let `c : Composition n` be a composition of `n`. Then
* `c.blocks` is the list of blocks in `c`.
* `c.length` is the number of blocks in the composition.
* `c.blocksFun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on
`Fin c.length`. This is the main object when using compositions to understand the composition of
analytic functions.
* `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.;
* `c.embedding i : Fin (c.blocksFun i) → Fin n` is the increasing embedding of the `i`-th block in
`Fin n`;
* `c.index j`, for `j : Fin n`, is the index of the block containing `j`.
* `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.
* `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.
Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition
of `n`.
* `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the
blocks of `c`.
* `join_splitWrtComposition` states that splitting a list and then joining it gives back the
original list.
* `splitWrtComposition_join` states that joining a list of lists, and then splitting it back
according to the right composition, gives back the original list of lists.
We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`.
`c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries`
and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not
make sense in the edge case `n = 0`, while the previous description works in all cases).
The elements of this set (other than `n`) correspond to leftmost points of blocks.
Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We
only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able
to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv
between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`
from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that
`CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)`
(see `compositionAsSet_card` and `composition_card`).
## Implementation details
The main motivation for this structure and its API is in the construction of the composition of
formal multilinear series, and the proof that the composition of analytic functions is analytic.
The representation of a composition as a list is very handy as lists are very flexible and already
have a well-developed API.
## Tags
Composition, partition
## References
<https://en.wikipedia.org/wiki/Composition_(combinatorics)>
-/
assert_not_exists Field
open List
variable {n : ℕ}
/-- A composition of `n` is a list of positive integers summing to `n`. -/
@[ext]
structure Composition (n : ℕ) where
/-- List of positive integers summing to `n` -/
blocks : List ℕ
/-- Proof of positivity for `blocks` -/
blocks_pos : ∀ {i}, i ∈ blocks → 0 < i
/-- Proof that `blocks` sums to `n` -/
blocks_sum : blocks.sum = n
deriving DecidableEq
attribute [simp] Composition.blocks_sum
/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of
consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding
a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and
get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure
`CompositionAsSet n`. -/
@[ext]
structure CompositionAsSet (n : ℕ) where
/-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}` -/
boundaries : Finset (Fin n.succ)
/-- Proof that `0` is a member of `boundaries` -/
zero_mem : (0 : Fin n.succ) ∈ boundaries
/-- Last element of the composition -/
getLast_mem : Fin.last n ∈ boundaries
deriving DecidableEq
instance {n : ℕ} : Inhabited (CompositionAsSet n) :=
⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩
attribute [simp] CompositionAsSet.zero_mem CompositionAsSet.getLast_mem
/-!
### Compositions
A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of
positive integers.
-/
namespace Composition
variable (c : Composition n)
instance (n : ℕ) : ToString (Composition n) :=
⟨fun c => toString c.blocks⟩
/-- The length of a composition, i.e., the number of blocks in the composition. -/
abbrev length : ℕ :=
c.blocks.length
theorem blocks_length : c.blocks.length = c.length :=
rfl
/-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic
functions using compositions, this is the main player. -/
def blocksFun : Fin c.length → ℕ := c.blocks.get
@[simp]
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
@[simp]
theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]
@[simp]
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h
theorem blocks_le {i : ℕ} (h : i ∈ c.blocks) : i ≤ n := by
rw [← c.blocks_sum]
exact List.le_sum_of_mem h
@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks[i] :=
c.one_le_blocks (get_mem (blocks c) _)
@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks[i] :=
c.one_le_blocks' h
@[simp]
theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
@[simp]
theorem blocksFun_le {n} (c : Composition n) (i : Fin c.length) :
c.blocksFun i ≤ n :=
c.blocks_le <| getElem_mem _
@[simp]
theorem length_le : c.length ≤ n := by
conv_rhs => rw [← c.blocks_sum]
exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi
@[simp]
theorem blocks_eq_nil : c.blocks = [] ↔ n = 0 := by
constructor
· intro h
simpa using congr(List.sum $h)
· rintro rfl
rw [← length_eq_zero_iff, ← nonpos_iff_eq_zero]
exact c.length_le
protected theorem length_eq_zero : c.length = 0 ↔ n = 0 := by
simp
@[simp]
theorem length_pos_iff : 0 < c.length ↔ 0 < n := by
simp [pos_iff_ne_zero]
alias ⟨_, length_pos_of_pos⟩ := length_pos_iff
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : ℕ) : ℕ :=
(c.blocks.take i).sum
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_of_length_le h
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by
conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i]
exact Nat.le_add_right _ _
theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i] := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundary : Fin (c.length + 1) ↪o Fin (n + 1) :=
(OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <|
Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi
@[simp]
| Mathlib/Combinatorics/Enumerative/Composition.lean | 256 | 257 | theorem boundary_zero : c.boundary 0 = 0 := by | simp [boundary, Fin.ext_iff] |
/-
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.Module.Submodule.Map
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.RingTheory.Ideal.Quotient.Defs
/-!
# modular equivalence for submodule
-/
open Submodule
open Polynomial
variable {R : Type*} [Ring R]
variable {A : Type*} [CommRing A]
variable {M : Type*} [AddCommGroup M] [Module R M] (U U₁ U₂ : Submodule R M)
variable {x x₁ x₂ y y₁ y₂ z z₁ z₂ : M}
variable {N : Type*} [AddCommGroup N] [Module R N] (V V₁ V₂ : Submodule R N)
/-- A predicate saying two elements of a module are equivalent modulo a submodule. -/
def SModEq (x y : M) : Prop :=
(Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y
@[inherit_doc] notation:50 x " ≡ " y " [SMOD " N "]" => SModEq N x y
variable {U U₁ U₂}
protected theorem SModEq.def :
x ≡ y [SMOD U] ↔ (Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y :=
Iff.rfl
namespace SModEq
theorem sub_mem : x ≡ y [SMOD U] ↔ x - y ∈ U := by rw [SModEq.def, Submodule.Quotient.eq]
@[simp]
theorem top : x ≡ y [SMOD (⊤ : Submodule R M)] :=
(Submodule.Quotient.eq ⊤).2 mem_top
@[simp]
theorem bot : x ≡ y [SMOD (⊥ : Submodule R M)] ↔ x = y := by
rw [SModEq.def, Submodule.Quotient.eq, mem_bot, sub_eq_zero]
@[mono]
theorem mono (HU : U₁ ≤ U₂) (hxy : x ≡ y [SMOD U₁]) : x ≡ y [SMOD U₂] :=
(Submodule.Quotient.eq U₂).2 <| HU <| (Submodule.Quotient.eq U₁).1 hxy
@[refl]
protected theorem refl (x : M) : x ≡ x [SMOD U] :=
@rfl _ _
protected theorem rfl : x ≡ x [SMOD U] :=
SModEq.refl _
instance : IsRefl _ (SModEq U) :=
⟨SModEq.refl⟩
@[symm]
nonrec theorem symm (hxy : x ≡ y [SMOD U]) : y ≡ x [SMOD U] :=
hxy.symm
@[trans]
nonrec theorem trans (hxy : x ≡ y [SMOD U]) (hyz : y ≡ z [SMOD U]) : x ≡ z [SMOD U] :=
hxy.trans hyz
instance instTrans : Trans (SModEq U) (SModEq U) (SModEq U) where
trans := trans
theorem add (hxy₁ : x₁ ≡ y₁ [SMOD U]) (hxy₂ : x₂ ≡ y₂ [SMOD U]) : x₁ + x₂ ≡ y₁ + y₂ [SMOD U] := by
rw [SModEq.def] at hxy₁ hxy₂ ⊢
simp_rw [Quotient.mk_add, hxy₁, hxy₂]
theorem smul (hxy : x ≡ y [SMOD U]) (c : R) : c • x ≡ c • y [SMOD U] := by
rw [SModEq.def] at hxy ⊢
simp_rw [Quotient.mk_smul, hxy]
lemma nsmul (hxy : x ≡ y [SMOD U]) (n : ℕ) : n • x ≡ n • y [SMOD U] := by
rw [SModEq.def] at hxy ⊢
simp_rw [Quotient.mk_smul, hxy]
lemma zsmul (hxy : x ≡ y [SMOD U]) (n : ℤ) : n • x ≡ n • y [SMOD U] := by
rw [SModEq.def] at hxy ⊢
simp_rw [Quotient.mk_smul, hxy]
| Mathlib/LinearAlgebra/SModEq.lean | 90 | 92 | theorem mul {I : Ideal A} {x₁ x₂ y₁ y₂ : A} (hxy₁ : x₁ ≡ y₁ [SMOD I])
(hxy₂ : x₂ ≡ y₂ [SMOD I]) : x₁ * x₂ ≡ y₁ * y₂ [SMOD I] := by | simp only [SModEq.def, Ideal.Quotient.mk_eq_mk, map_mul] at hxy₁ hxy₂ ⊢ |
/-
Copyright (c) 2022 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Function.ConditionalExpectation.Basic
/-!
# Conditional expectation of indicator functions
This file proves some results about the conditional expectation of an indicator function and
as a corollary, also proves several results about the behaviour of the conditional expectation on
a restricted measure.
## Main result
* `MeasureTheory.condExp_indicator`: If `s` is an `m`-measurable set, then the conditional
expectation of the indicator function of `s` is almost everywhere equal to the indicator
of `s` of the conditional expectation. Namely, `𝔼[s.indicator f | m] = s.indicator 𝔼[f | m]` a.e.
-/
noncomputable section
open TopologicalSpace MeasureTheory.Lp Filter ContinuousLinearMap
open scoped NNReal ENNReal Topology MeasureTheory
namespace MeasureTheory
variable {α E : Type*} {m m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E]
[CompleteSpace E] {μ : Measure α} {f : α → E} {s : Set α}
theorem condExp_ae_eq_restrict_zero (hs : MeasurableSet[m] s) (hf : f =ᵐ[μ.restrict s] 0) :
μ[f|m] =ᵐ[μ.restrict s] 0 := by
by_cases hm : m ≤ m0
swap; · simp_rw [condExp_of_not_le hm]; rfl
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · simp_rw [condExp_of_not_sigmaFinite hm hμm]; rfl
haveI : SigmaFinite (μ.trim hm) := hμm
have : SigmaFinite ((μ.restrict s).trim hm) := by
rw [← restrict_trim hm _ hs]
exact Restrict.sigmaFinite _ s
by_cases hf_int : Integrable f μ
swap; · rw [condExp_of_not_integrable hf_int]
refine ae_eq_of_forall_setIntegral_eq_of_sigmaFinite' hm ?_ ?_ ?_ ?_ ?_
· exact fun t _ _ => integrable_condExp.integrableOn.integrableOn
· exact fun t _ _ => (integrable_zero _ _ _).integrableOn
· intro t ht _
rw [Measure.restrict_restrict (hm _ ht), setIntegral_condExp hm hf_int (ht.inter hs), ←
Measure.restrict_restrict (hm _ ht)]
refine setIntegral_congr_ae (hm _ ht) ?_
filter_upwards [hf] with x hx _ using hx
· exact stronglyMeasurable_condExp.aestronglyMeasurable
· exact stronglyMeasurable_zero.aestronglyMeasurable
@[deprecated (since := "2025-01-21")]
alias condexp_ae_eq_restrict_zero := condExp_ae_eq_restrict_zero
/-- Auxiliary lemma for `condExp_indicator`. -/
| Mathlib/MeasureTheory/Function/ConditionalExpectation/Indicator.lean | 63 | 70 | theorem condExp_indicator_aux (hs : MeasurableSet[m] s) (hf : f =ᵐ[μ.restrict sᶜ] 0) :
μ[s.indicator f|m] =ᵐ[μ] s.indicator (μ[f|m]) := by | by_cases hm : m ≤ m0
swap; · simp_rw [condExp_of_not_le hm, Set.indicator_zero']; rfl
have hsf_zero : ∀ g : α → E, g =ᵐ[μ.restrict sᶜ] 0 → s.indicator g =ᵐ[μ] g := fun g =>
indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs)
refine ((hsf_zero (μ[f|m]) (condExp_ae_eq_restrict_zero hs.compl hf)).trans ?_).symm
exact condExp_congr_ae (hsf_zero f hf).symm |
/-
Copyright (c) 2022 Antoine Labelle. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Labelle
-/
import Mathlib.RepresentationTheory.FDRep
import Mathlib.LinearAlgebra.Trace
import Mathlib.RepresentationTheory.Invariants
/-!
# Characters of representations
This file introduces characters of representation and proves basic lemmas about how characters
behave under various operations on representations.
A key result is the orthogonality of characters for irreducible representations of finite group
over an algebraically closed field whose characteristic doesn't divide the order of the group. It
is the theorem `char_orthonormal`
## Implementation notes
Irreducible representations are implemented categorically, using the `CategoryTheory.Simple` class
defined in `Mathlib.CategoryTheory.Simple`
## TODO
* Once we have the monoidal closed structure on `FdRep k G` and a better API for the rigid
structure, `char_dual` and `char_linHom` should probably be stated in terms of `Vᘁ` and `ihom V W`.
-/
noncomputable section
universe u
open CategoryTheory LinearMap CategoryTheory.MonoidalCategory Representation Module
variable {k : Type u} [Field k]
namespace FDRep
section Monoid
variable {G : Type u} [Monoid G]
/-- The character of a representation `V : FDRep k G` is the function associating to `g : G` the
trace of the linear map `V.ρ g`. -/
def character (V : FDRep k G) (g : G) :=
LinearMap.trace k V (V.ρ g)
theorem char_mul_comm (V : FDRep k G) (g : G) (h : G) :
V.character (h * g) = V.character (g * h) := by simp only [trace_mul_comm, character, map_mul]
@[simp]
theorem char_one (V : FDRep k G) : V.character 1 = Module.finrank k V := by
simp only [character, map_one, trace_one]
/-- The character is multiplicative under the tensor product. -/
@[simp]
theorem char_tensor (V W : FDRep k G) : (V ⊗ W).character = V.character * W.character := by
ext g; convert trace_tensorProduct' (V.ρ g) (W.ρ g)
/-- The character of isomorphic representations is the same. -/
theorem char_iso {V W : FDRep k G} (i : V ≅ W) : V.character = W.character := by
ext g
simp only [character, FDRep.Iso.conj_ρ i]
exact (trace_conj' (V.ρ g) _).symm
end Monoid
section Group
variable {G : Type u} [Group G]
/-- The character of a representation is constant on conjugacy classes. -/
@[simp]
theorem char_conj (V : FDRep k G) (g : G) (h : G) : V.character (h * g * h⁻¹) = V.character g := by
rw [char_mul_comm, inv_mul_cancel_left]
@[simp]
theorem char_dual (V : FDRep k G) (g : G) : (of (dual V.ρ)).character g = V.character g⁻¹ :=
trace_transpose' (V.ρ g⁻¹)
@[simp]
theorem char_linHom (V W : FDRep k G) (g : G) :
(of (linHom V.ρ W.ρ)).character g = V.character g⁻¹ * W.character g := by
rw [← char_iso (dualTensorIsoLinHom _ _), char_tensor, Pi.mul_apply, char_dual]
variable [Fintype G] [Invertible (Fintype.card G : k)]
theorem average_char_eq_finrank_invariants (V : FDRep k G) :
⅟ (Fintype.card G : k) • ∑ g : G, V.character g = finrank k (invariants V.ρ) := by
rw [← (isProj_averageMap V.ρ).trace]
simp [character, GroupAlgebra.average, _root_.map_sum]
end Group
section Orthogonality
variable {G : Type u} [Group G] [IsAlgClosed k]
variable [Fintype G] [Invertible (Fintype.card G : k)]
open scoped Classical in
/-- Orthogonality of characters for irreducible representations of finite group over an
algebraically closed field whose characteristic doesn't divide the order of the group. -/
| Mathlib/RepresentationTheory/Character.lean | 106 | 109 | theorem char_orthonormal (V W : FDRep k G) [Simple V] [Simple W] :
⅟ (Fintype.card G : k) • ∑ g : G, V.character g * W.character g⁻¹ =
if Nonempty (V ≅ W) then ↑1 else ↑0 := by | -- First, we can rewrite the summand `V.character g * W.character g⁻¹` as the character |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Yaël Dillies
-/
import Mathlib.Order.Cover
import Mathlib.Order.Interval.Finset.Defs
/-!
# Intervals as finsets
This file provides basic results about all the `Finset.Ixx`, which are defined in
`Order.Interval.Finset.Defs`.
In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of,
respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly
functions whose domain is a locally finite order. In particular, this file proves:
* `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿`
* `lt_iff_transGen_covBy`: `<` is the transitive closure of `⋖`
* `monotone_iff_forall_wcovBy`: Characterization of monotone functions
* `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions
## TODO
This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to
generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general,
what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure.
Complete the API. See
https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235
for some ideas.
-/
assert_not_exists MonoidWithZero Finset.sum
open Function OrderDual
open FinsetInterval
variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α}
namespace Finset
section Preorder
variable [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α]
@[simp]
theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by
rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc
@[simp]
theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico
@[simp]
theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo]
@[simp]
theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by
rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff]
@[simp]
theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff]
@[simp]
theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff]
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff]
alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff
alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff
alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff
@[simp]
theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2)
@[simp]
theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ :=
Icc_eq_empty h.not_le
@[simp]
theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ :=
Ico_eq_empty h.not_lt
@[simp]
theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ :=
Ioc_eq_empty h.not_lt
@[simp]
theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ :=
Ioo_eq_empty h.not_lt
theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl]
theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl]
theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl]
theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl]
theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1
theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1
theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2
theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2
@[gcongr]
theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by
simpa [← coe_subset] using Set.Icc_subset_Icc ha hb
@[gcongr]
theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by
simpa [← coe_subset] using Set.Ico_subset_Ico ha hb
@[gcongr]
theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by
simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb
@[gcongr]
theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by
simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb
@[gcongr]
theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b :=
Icc_subset_Icc h le_rfl
@[gcongr]
theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b :=
Ico_subset_Ico h le_rfl
@[gcongr]
theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b :=
Ioc_subset_Ioc h le_rfl
@[gcongr]
theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b :=
Ioo_subset_Ioo h le_rfl
@[gcongr]
theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ :=
Icc_subset_Icc le_rfl h
@[gcongr]
theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ :=
Ico_subset_Ico le_rfl h
@[gcongr]
theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ :=
Ioc_subset_Ioc le_rfl h
@[gcongr]
theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ :=
Ioo_subset_Ioo le_rfl h
theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by
rw [← coe_subset, coe_Ico, coe_Ioo]
exact Set.Ico_subset_Ioo_left h
theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by
rw [← coe_subset, coe_Ioc, coe_Ioo]
exact Set.Ioc_subset_Ioo_right h
theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by
rw [← coe_subset, coe_Icc, coe_Ico]
exact Set.Icc_subset_Ico_right h
theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by
rw [← coe_subset, coe_Ioo, coe_Ico]
exact Set.Ioo_subset_Ico_self
theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by
rw [← coe_subset, coe_Ioo, coe_Ioc]
exact Set.Ioo_subset_Ioc_self
theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by
rw [← coe_subset, coe_Ico, coe_Icc]
exact Set.Ico_subset_Icc_self
theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by
rw [← coe_subset, coe_Ioc, coe_Icc]
exact Set.Ioc_subset_Icc_self
theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b :=
Ioo_subset_Ico_self.trans Ico_subset_Icc_self
theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by
rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁]
| Mathlib/Order/Interval/Finset/Basic.lean | 220 | 222 | theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by | rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] |
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Trifunctor
import Mathlib.CategoryTheory.Products.Basic
/-!
# Monoidal categories
A monoidal category is a category equipped with a tensor product, unitors, and an associator.
In the definition, we provide the tensor product as a pair of functions
* `tensorObj : C → C → C`
* `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))`
and allow use of the overloaded notation `⊗` for both.
The unitors and associator are provided componentwise.
The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`.
The unitors and associator are gathered together as natural
isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`.
Some consequences of the definition are proved in other files after proving the coherence theorem,
e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`.
## Implementation notes
In the definition of monoidal categories, we also provide the whiskering operators:
* `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`,
* `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`.
These are products of an object and a morphism (the terminology "whiskering"
is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined
in terms of the whiskerings. There are two possible such definitions, which are related by
the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def`
and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds
definitionally.
If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it,
you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`.
The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories.
### Simp-normal form for 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 morphisms into the simp-normal
form defined below. Rewriting into simp-normal form is especially useful in preprocessing
performed by the `coherence` tactic.
The simp-normal form of morphisms is defined to be an expression that has the minimal number of
parentheses. More precisely,
1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is
either a structural morphisms (morphisms made up only of identities, associators, unitors)
or non-structural morphisms, and
2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`,
where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural
morphisms that is not the identity or a composite.
Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`.
Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`,
respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon.
## References
* Tensor categories, Etingof, Gelaki, Nikshych, Ostrik,
http://www-math.mit.edu/~etingof/egnobookfinal.pdf
* <https://stacks.math.columbia.edu/tag/0FFK>.
-/
universe v u
open CategoryTheory.Category
open CategoryTheory.Iso
namespace CategoryTheory
/-- Auxiliary structure to carry only the data fields of (and provide notation for)
`MonoidalCategory`. -/
class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where
/-- curried tensor product of objects -/
tensorObj : C → C → C
/-- left whiskering for morphisms -/
whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂
/-- right whiskering for morphisms -/
whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
-- By default, it is defined in terms of whiskerings.
tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) :=
whiskerRight f X₂ ≫ whiskerLeft Y₁ g
/-- The tensor unity in the monoidal structure `𝟙_ C` -/
tensorUnit (C) : C
/-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z)
/-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/
leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X
/-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/
rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X
namespace MonoidalCategory
export MonoidalCategoryStruct
(tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor)
end MonoidalCategory
namespace MonoidalCategory
/-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj
/-- Notation for the `whiskerLeft` operator of monoidal categories -/
scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft
/-- Notation for the `whiskerRight` operator of monoidal categories -/
scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight
/-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom
/-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/
scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C
/-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
scoped notation "α_" => MonoidalCategoryStruct.associator
/-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/
scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor
/-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/
scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor
/-- The property that the pentagon relation is satisfied by four objects
in a category equipped with a `MonoidalCategoryStruct`. -/
def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C]
(Y₁ Y₂ Y₃ Y₄ : C) : Prop :=
(α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom =
(α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom
end MonoidalCategory
open MonoidalCategory
/--
In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`.
Tensor product does not need to be strictly associative on objects, but there is a
specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`,
with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`.
These associators and unitors satisfy the pentagon and triangle equations. -/
@[stacks 0FFK]
-- Porting note: The Mathport did not translate the temporary notation
class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where
tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by
aesop_cat
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat
/--
Tensor product of compositions is composition of tensor products:
`(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)`
-/
tensor_comp :
∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂),
(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by
aesop_cat
whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by
aesop_cat
id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by
aesop_cat
/-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/
associator_naturality :
∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃),
((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by
aesop_cat
/--
Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y`
-/
leftUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by
aesop_cat
/--
Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y`
-/
rightUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by
aesop_cat
/--
The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W`
-/
pentagon :
∀ W X Y Z : C,
(α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom =
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by
aesop_cat
/--
The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y`
-/
triangle :
∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by
aesop_cat
attribute [reassoc] MonoidalCategory.tensorHom_def
attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id
attribute [reassoc, simp] MonoidalCategory.id_whiskerRight
attribute [reassoc] MonoidalCategory.tensor_comp
attribute [simp] MonoidalCategory.tensor_comp
attribute [reassoc] MonoidalCategory.associator_naturality
attribute [reassoc] MonoidalCategory.leftUnitor_naturality
attribute [reassoc] MonoidalCategory.rightUnitor_naturality
attribute [reassoc (attr := simp)] MonoidalCategory.pentagon
attribute [reassoc (attr := simp)] MonoidalCategory.triangle
namespace MonoidalCategory
variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C]
@[simp]
theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) :
𝟙 X ⊗ f = X ◁ f := by
simp [tensorHom_def]
@[simp]
theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) :
f ⊗ 𝟙 Y = f ▷ Y := by
simp [tensorHom_def]
@[reassoc, simp]
theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) :
W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by
simp only [← id_tensorHom, ← tensor_comp, comp_id]
@[reassoc, simp]
theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) :
𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by
rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom]
@[reassoc, simp]
theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') :
(X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [← assoc, ← associator_naturality]
simp
@[reassoc, simp]
| Mathlib/CategoryTheory/Monoidal/Category.lean | 246 | 250 | theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) :
(f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by | simp only [← tensorHom_id, ← tensor_comp, id_comp]
@[reassoc, simp] |
/-
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.Complex.Log
/-! # Power function on `ℂ`
We construct the power functions `x ^ y`, where `x` and `y` are complex numbers.
-/
open Real Topology Filter ComplexConjugate Finset Set
namespace Complex
/-- The complex power function `x ^ y`, given by `x ^ y = exp(y log x)` (where `log` is the
principal determination of the logarithm), unless `x = 0` where one sets `0 ^ 0 = 1` and
`0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def cpow (x y : ℂ) : ℂ :=
if x = 0 then if y = 0 then 1 else 0 else exp (log x * y)
noncomputable instance : Pow ℂ ℂ :=
⟨cpow⟩
@[simp]
theorem cpow_eq_pow (x y : ℂ) : cpow x y = x ^ y :=
rfl
theorem cpow_def (x y : ℂ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) :=
rfl
theorem cpow_def_of_ne_zero {x : ℂ} (hx : x ≠ 0) (y : ℂ) : x ^ y = exp (log x * y) :=
if_neg hx
@[simp]
theorem cpow_zero (x : ℂ) : x ^ (0 : ℂ) = 1 := by simp [cpow_def]
@[simp]
theorem cpow_eq_zero_iff (x y : ℂ) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
simp only [cpow_def]
split_ifs <;> simp [*, exp_ne_zero]
theorem cpow_ne_zero_iff {x y : ℂ} :
x ^ y ≠ 0 ↔ x ≠ 0 ∨ y = 0 := by
rw [ne_eq, cpow_eq_zero_iff, not_and_or, ne_eq, not_not]
| Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean | 49 | 51 | theorem cpow_ne_zero_iff_of_exponent_ne_zero {x y : ℂ} (hy : y ≠ 0) :
x ^ y ≠ 0 ↔ x ≠ 0 := by | simp [hy] |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Order.Nonneg.Field
import Mathlib.Data.Rat.Cast.Defs
import Mathlib.Tactic.Positivity.Basic
/-!
# Some exiled lemmas about casting
These lemmas have been removed from `Mathlib.Data.Rat.Cast.Defs`
to avoiding needing to import `Mathlib.Algebra.Field.Basic` there.
In fact, these lemmas don't appear to be used anywhere in Mathlib,
so perhaps this file can simply be deleted.
-/
namespace Rat
variable {α : Type*} [DivisionRing α]
-- Note that this is more general than `(Rat.castHom α).map_pow`.
@[simp, norm_cast]
lemma cast_pow (p : ℚ) (n : ℕ) : ↑(p ^ n) = (p ^ n : α) := by
rw [cast_def, cast_def, den_pow, num_pow, Nat.cast_pow, Int.cast_pow, div_eq_mul_inv, ← inv_pow,
← (Int.cast_commute _ _).mul_pow, ← div_eq_mul_inv]
@[simp]
theorem cast_inv_nat (n : ℕ) : ((n⁻¹ : ℚ) : α) = (n : α)⁻¹ := by
rcases n with - | n
· simp
rw [cast_def, inv_natCast_num, inv_natCast_den, if_neg n.succ_ne_zero,
Int.sign_eq_one_of_pos (Int.ofNat_succ_pos n), Int.cast_one, one_div]
@[simp]
theorem cast_inv_int (n : ℤ) : ((n⁻¹ : ℚ) : α) = (n : α)⁻¹ := by
rcases n with n | n
· simp [ofInt_eq_cast, cast_inv_nat]
· simp only [ofInt_eq_cast, Int.cast_negSucc, ← Nat.cast_succ, cast_neg, inv_neg, cast_inv_nat]
@[simp, norm_cast]
theorem cast_nnratCast {K} [DivisionRing K] (q : ℚ≥0) :
((q : ℚ) : K) = (q : K) := by
rw [Rat.cast_def, NNRat.cast_def, NNRat.cast_def]
have hn := @num_div_eq_of_coprime q.num q.den ?hdp q.coprime_num_den
on_goal 1 => have hd := @den_div_eq_of_coprime q.num q.den ?hdp q.coprime_num_den
case hdp => simpa only [Int.ofNat_pos] using q.den_pos
simp only [Int.cast_natCast, Nat.cast_inj] at hn hd
rw [hn, hd, Int.cast_natCast]
/-- Casting a scientific literal via `ℚ` is the same as casting directly. -/
@[simp, norm_cast]
| Mathlib/Data/Rat/Cast/Lemmas.lean | 55 | 57 | theorem cast_ofScientific {K} [DivisionRing K] (m : ℕ) (s : Bool) (e : ℕ) :
(OfScientific.ofScientific m s e : ℚ) = (OfScientific.ofScientific m s e : K) := by | rw [← NNRat.cast_ofScientific (K := K), ← NNRat.cast_ofScientific, cast_nnratCast] |
/-
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.Finite.Prod
import Mathlib.Data.Matroid.Init
import Mathlib.Data.Set.Card
import Mathlib.Data.Set.Finite.Powerset
import Mathlib.Order.UpperLower.Closure
/-!
# 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.IsBase 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.IsBasis 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.
* `RankFinite M` means that the bases of `M` are finite.
* `RankInfinite M` means that the bases of `M` are infinite.
* `RankPos 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 `[RankFinite 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.
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 few 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_isBase_dual` is one of the many examples of this.
Finally, in theorem names, matroid predicates that apply to sets
(such as `Base`, `Indep`, `IsBasis`) are typically used as suffixes rather than prefixes.
For instance, we have `ground_indep_iff_isBase` rather than `indep_ground_iff_isBase`.
## References
* [J. Oxley, Matroid Theory][oxley2011]
* [H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids,
Adv. Math 239 (2013), 18-46][bruhnDiestelKriesselPendavinghWollan2013]
* [N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets,
Proc. Amer. Math. Soc. 144 (2016), 459-471][bowlerGeschke2015]
-/
assert_not_exists Field
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 → ∃ J, I ⊆ J ∧ Maximal (fun K ↦ P K ∧ K ⊆ X) J
/-- 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`.
-/
structure Matroid (α : Type*) where
/-- `M` has a ground set `E`. -/
(E : Set α)
/-- `M` has a predicate `Base` defining its bases. -/
(IsBase : 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, IsBase B ∧ I ⊆ B)
/-- There is at least one `Base`. -/
(exists_isBase : ∃ B, IsBase B)
/-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f`
is a base. -/
(isBase_exchange : Matroid.ExchangeProperty IsBase)
/-- 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, IsBase B → B ⊆ E)
attribute [local ext] Matroid
namespace Matroid
variable {α : Type*} {M : Matroid α}
@[deprecated (since := "2025-02-14")] alias Base := IsBase
instance (M : Matroid α) : Nonempty {B // M.IsBase B} :=
nonempty_subtype.2 M.exists_isBase
/-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`. -/
@[mk_iff] 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⟩
lemma nonempty_type (M : Matroid α) [h : M.Nonempty] : Nonempty α :=
⟨M.ground_nonempty.some⟩
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 `RankFinite` matroid is one whose bases are finite -/
@[mk_iff] class RankFinite (M : Matroid α) : Prop where
/-- There is a finite base -/
exists_finite_isBase : ∃ B, M.IsBase B ∧ B.Finite
@[deprecated (since := "2025-02-09")] alias FiniteRk := RankFinite
instance rankFinite_of_finite (M : Matroid α) [M.Finite] : RankFinite M :=
⟨M.exists_isBase.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩
/-- An `RankInfinite` matroid is one whose bases are infinite. -/
@[mk_iff] class RankInfinite (M : Matroid α) : Prop where
/-- There is an infinite base -/
exists_infinite_isBase : ∃ B, M.IsBase B ∧ B.Infinite
@[deprecated (since := "2025-02-09")] alias InfiniteRk := RankInfinite
/-- A `RankPos` matroid is one whose bases are nonempty. -/
@[mk_iff] class RankPos (M : Matroid α) : Prop where
/-- The empty set isn't a base -/
empty_not_isBase : ¬M.IsBase ∅
@[deprecated (since := "2025-02-09")] alias RkPos := RankPos
instance rankPos_nonempty {M : Matroid α} [M.RankPos] : M.Nonempty := by
obtain ⟨B, hB⟩ := M.exists_isBase
obtain rfl | ⟨e, heB⟩ := B.eq_empty_or_nonempty
· exact False.elim <| RankPos.empty_not_isBase hB
exact ⟨e, M.subset_ground B hB heB ⟩
@[deprecated (since := "2025-01-20")] alias rkPos_iff_empty_not_base := rankPos_iff
section exchange
namespace ExchangeProperty
variable {IsBase : Set α → Prop} {B B' : Set α}
/-- A family of sets with the exchange property is an antichain. -/
theorem antichain (exch : ExchangeProperty IsBase) (hB : IsBase B) (hB' : IsBase 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 {B₁ B₂ : Set α}
(exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase 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
variable {B₁ B₂ : Set α}
/-- 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 (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase 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_isBase_eq (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase 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`. -/
variable {X Y : Set α} {e : α}
@[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 IsBase
variable {B B₁ B₂ : Set α}
@[aesop unsafe 10% (rule_sets := [Matroid])]
theorem IsBase.subset_ground (hB : M.IsBase B) : B ⊆ M.E :=
M.subset_ground B hB
theorem IsBase.exchange {e : α} (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hx : e ∈ B₁ \ B₂) :
∃ y ∈ B₂ \ B₁, M.IsBase (insert y (B₁ \ {e})) :=
M.isBase_exchange B₁ B₂ hB₁ hB₂ _ hx
theorem IsBase.exchange_mem {e : α}
(hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hxB₁ : e ∈ B₁) (hxB₂ : e ∉ B₂) :
∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.IsBase (insert y (B₁ \ {e})) := by
simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩
theorem IsBase.eq_of_subset_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hB₁B₂ : B₁ ⊆ B₂) :
B₁ = B₂ :=
M.isBase_exchange.antichain hB₁ hB₂ hB₁B₂
theorem IsBase.not_isBase_of_ssubset {X : Set α} (hB : M.IsBase B) (hX : X ⊂ B) : ¬ M.IsBase X :=
fun h ↦ hX.ne (h.eq_of_subset_isBase hB hX.subset)
theorem IsBase.insert_not_isBase {e : α} (hB : M.IsBase B) (heB : e ∉ B) :
¬ M.IsBase (insert e B) :=
fun h ↦ h.not_isBase_of_ssubset (ssubset_insert heB) hB
theorem IsBase.encard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).encard = (B₂ \ B₁).encard :=
M.isBase_exchange.encard_diff_eq hB₁ hB₂
theorem IsBase.ncard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).ncard = (B₂ \ B₁).ncard := by
rw [ncard_def, hB₁.encard_diff_comm hB₂, ← ncard_def]
theorem IsBase.encard_eq_encard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
B₁.encard = B₂.encard := by
rw [M.isBase_exchange.encard_isBase_eq hB₁ hB₂]
theorem IsBase.ncard_eq_ncard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
B₁.ncard = B₂.ncard := by
rw [ncard_def B₁, hB₁.encard_eq_encard_of_isBase hB₂, ← ncard_def]
theorem IsBase.finite_of_finite {B' : Set α}
(hB : M.IsBase B) (h : B.Finite) (hB' : M.IsBase B') : B'.Finite :=
(finite_iff_finite_of_encard_eq_encard (hB.encard_eq_encard_of_isBase hB')).mp h
theorem IsBase.infinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) (hB₁ : M.IsBase B₁) :
B₁.Infinite :=
by_contra (fun hB_inf ↦ (hB₁.finite_of_finite (not_infinite.mp hB_inf) hB).not_infinite h)
theorem IsBase.finite [RankFinite M] (hB : M.IsBase B) : B.Finite :=
let ⟨_,hB₀⟩ := ‹RankFinite M›.exists_finite_isBase
hB₀.1.finite_of_finite hB₀.2 hB
theorem IsBase.infinite [RankInfinite M] (hB : M.IsBase B) : B.Infinite :=
let ⟨_,hB₀⟩ := ‹RankInfinite M›.exists_infinite_isBase
hB₀.1.infinite_of_infinite hB₀.2 hB
theorem empty_not_isBase [h : RankPos M] : ¬M.IsBase ∅ :=
h.empty_not_isBase
theorem IsBase.nonempty [RankPos M] (hB : M.IsBase B) : B.Nonempty := by
rw [nonempty_iff_ne_empty]; rintro rfl; exact M.empty_not_isBase hB
theorem IsBase.rankPos_of_nonempty (hB : M.IsBase B) (h : B.Nonempty) : M.RankPos := by
rw [rankPos_iff]
intro he
obtain rfl := he.eq_of_subset_isBase hB (empty_subset B)
simp at h
theorem IsBase.rankFinite_of_finite (hB : M.IsBase B) (hfin : B.Finite) : RankFinite M :=
⟨⟨B, hB, hfin⟩⟩
theorem IsBase.rankInfinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) : RankInfinite M :=
⟨⟨B, hB, h⟩⟩
theorem not_rankFinite (M : Matroid α) [RankInfinite M] : ¬ RankFinite M := by
intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite
theorem not_rankInfinite (M : Matroid α) [RankFinite M] : ¬ RankInfinite M := by
intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite
theorem rankFinite_or_rankInfinite (M : Matroid α) : RankFinite M ∨ RankInfinite M :=
let ⟨B, hB⟩ := M.exists_isBase
B.finite_or_infinite.imp hB.rankFinite_of_finite hB.rankInfinite_of_infinite
@[deprecated (since := "2025-03-27")] alias finite_or_rankInfinite := rankFinite_or_rankInfinite
@[simp]
theorem not_rankFinite_iff (M : Matroid α) : ¬ RankFinite M ↔ RankInfinite M :=
M.rankFinite_or_rankInfinite.elim (fun h ↦ iff_of_false (by simpa) M.not_rankInfinite)
fun h ↦ iff_of_true M.not_rankFinite h
@[simp]
theorem not_rankInfinite_iff (M : Matroid α) : ¬ RankInfinite M ↔ RankFinite M := by
rw [← not_rankFinite_iff, not_not]
theorem IsBase.diff_finite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).Finite ↔ (B₂ \ B₁).Finite :=
finite_iff_finite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂)
theorem IsBase.diff_infinite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) :
(B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite :=
infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂)
theorem ext_isBase {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B)) : M₁ = M₂ := by
have h' : ∀ B, M₁.IsBase B ↔ M₂.IsBase 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']
@[deprecated (since := "2024-12-25")] alias eq_of_isBase_iff_isBase_forall := ext_isBase
theorem ext_iff_isBase {M₁ M₂ : Matroid α} :
M₁ = M₂ ↔ M₁.E = M₂.E ∧ ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B) :=
⟨fun h ↦ by simp [h], fun ⟨hE, h⟩ ↦ ext_isBase hE h⟩
theorem isBase_compl_iff_maximal_disjoint_isBase (hB : B ⊆ M.E := by aesop_mat) :
M.IsBase (M.E \ B) ↔ Maximal (fun I ↦ I ⊆ M.E ∧ ∃ B, M.IsBase B ∧ Disjoint I B) B := by
simp_rw [maximal_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_isBase 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 IsBase
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
variable {B B' I J D X : Set α} {e f : α}
theorem indep_iff : M.Indep I ↔ ∃ B, M.IsBase B ∧ I ⊆ B :=
M.indep_iff' (I := I)
theorem setOf_indep_eq (M : Matroid α) : {I | M.Indep I} = lowerClosure ({B | M.IsBase B}) := by
simp_rw [indep_iff, lowerClosure, LowerSet.coe_mk, mem_setOf, le_eq_subset]
theorem Indep.exists_isBase_superset (hI : M.Indep I) : ∃ B, M.IsBase 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_isBase_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_isBase_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 IsBase.indep (hB : M.IsBase B) : M.Indep B :=
indep_iff.2 ⟨B, hB, subset_rfl⟩
@[simp] theorem empty_indep (M : Matroid α) : M.Indep ∅ :=
Exists.elim M.exists_isBase (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 [RankFinite M] (hI : M.Indep I) : I.Finite :=
let ⟨_, hB, hIB⟩ := hI.exists_isBase_superset
hB.finite.subset hIB
theorem Indep.rankPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RankPos := by
obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset
exact hB.rankPos_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 IsBase.eq_of_subset_indep (hB : M.IsBase B) (hI : M.Indep I) (hBI : B ⊆ I) : B = I :=
let ⟨B', hB', hB'I⟩ := hI.exists_isBase_superset
hBI.antisymm (by rwa [hB.eq_of_subset_isBase hB' (hBI.trans hB'I)])
theorem isBase_iff_maximal_indep : M.IsBase B ↔ Maximal M.Indep B := by
rw [maximal_subset_iff]
refine ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep⟩, fun ⟨h, h'⟩ ↦ ?_⟩
obtain ⟨B', hB', hBB'⟩ := h.exists_isBase_superset
rwa [h' hB'.indep hBB']
theorem Indep.isBase_of_maximal (hI : M.Indep I) (h : ∀ ⦃J⦄, M.Indep J → I ⊆ J → I = J) :
M.IsBase I := by
rwa [isBase_iff_maximal_indep, maximal_subset_iff, and_iff_right hI]
theorem IsBase.dep_of_ssubset (hB : M.IsBase 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 IsBase.dep_of_insert (hB : M.IsBase 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 IsBase.mem_of_insert_indep (hB : M.IsBase 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 IsBases is a singleton, then they differ by an insertion/removal -/
theorem IsBase.eq_exchange_of_diff_eq_singleton (hB : M.IsBase B) (hB' : M.IsBase 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_isBase 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 IsBase.exchange_isBase_of_indep (hB : M.IsBase B) (hf : f ∉ B)
(hI : M.Indep (insert f (B \ {e}))) : M.IsBase (insert f (B \ {e})) := by
obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_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 IsBase.exchange_isBase_of_indep' (hB : M.IsBase B) (he : e ∈ B) (hf : f ∉ B)
(hI : M.Indep (insert f B \ {e})) : M.IsBase (insert f B \ {e}) := by
have hfe : f ≠ e := ne_of_mem_of_not_mem he hf |>.symm
rw [← insert_diff_singleton_comm hfe] at *
exact hB.exchange_isBase_of_indep hf hI
lemma insert_isBase_of_insert_indep {M : Matroid α} {I : Set α} {e f : α}
(he : e ∉ I) (hf : f ∉ I) (heI : M.IsBase (insert e I)) (hfI : M.Indep (insert f I)) :
M.IsBase (insert f I) := by
obtain rfl | hef := eq_or_ne e f
· assumption
simpa [diff_singleton_eq_self he, hfI]
using heI.exchange_isBase_of_indep (e := e) (f := f) (by simp [hef.symm, hf])
theorem IsBase.insert_dep (hB : M.IsBase 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_isBase (hI : M.Indep I) (hI' : ¬M.IsBase I) (hB : M.IsBase B) :
∃ e ∈ B \ I, M.Indep (insert e I) := by
obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_superset
obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB')))
by_cases hxB : 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_isBase`, but phrased so that
it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_maximal (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
(hInotmax : ¬ Maximal M.Indep I) (hB : Maximal M.Indep B) :
∃ x ∈ B \ I, M.Indep (insert x I) := by
simp only [maximal_subset_iff, hI, not_and, not_forall, exists_prop, true_imp_iff] at hB hInotmax
refine hI.exists_insert_of_not_isBase (fun hIb ↦ ?_) ?_
· obtain ⟨I', hII', hI', hne⟩ := hInotmax
exact hne <| hIb.eq_of_subset_indep hII' hI'
exact hB.1.isBase_of_maximal fun J hJ hBJ ↦ hB.2 hJ hBJ
theorem Indep.isBase_of_forall_insert (hB : M.Indep B)
(hBmax : ∀ e ∈ M.E \ B, ¬ M.Indep (insert e B)) : M.IsBase B := by
refine by_contra fun hnb ↦ ?_
obtain ⟨B', hB'⟩ := M.exists_isBase
obtain ⟨e, he, h⟩ := hB.exists_insert_of_not_isBase hnb hB'
exact hBmax e ⟨hB'.subset_ground he.1, he.2⟩ h
theorem ground_indep_iff_isBase : M.Indep M.E ↔ M.IsBase M.E :=
⟨fun h ↦ h.isBase_of_maximal (fun _ hJ hEJ ↦ hEJ.antisymm hJ.subset_ground), IsBase.indep⟩
theorem IsBase.exists_insert_of_ssubset (hB : M.IsBase B) (hIB : I ⊂ B) (hB' : M.IsBase B') :
∃ e ∈ B' \ I, M.Indep (insert e I) :=
(hB.indep.subset hIB.subset).exists_insert_of_not_isBase
(fun hI ↦ hIB.ne (hI.eq_of_subset_isBase hB hIB.subset)) hB'
@[ext] theorem ext_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(h : ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ :=
have h' : M₁.Indep = M₂.Indep := by
ext I
by_cases hI : I ⊆ M₁.E
· rwa [h]
exact iff_of_false (fun hi ↦ hI hi.subset_ground)
(fun hi ↦ hI (hi.subset_ground.trans_eq hE.symm))
ext_isBase hE (fun B _ ↦ by simp_rw [isBase_iff_maximal_indep, h'])
@[deprecated (since := "2024-12-25")] alias eq_of_indep_iff_indep_forall := ext_indep
theorem ext_iff_indep {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 ↦ ext_indep h.1 h.2⟩
@[deprecated (since := "2024-12-25")] alias eq_iff_indep_iff_indep_forall := ext_iff_indep
/-- If every base of `M₁` is independent in `M₂` and vice versa, then `M₁ = M₂`. -/
lemma ext_isBase_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
(hM₁ : ∀ ⦃B⦄, M₁.IsBase B → M₂.Indep B) (hM₂ : ∀ ⦃B⦄, M₂.IsBase B → M₁.Indep B) : M₁ = M₂ := by
refine ext_indep hE fun I hIE ↦ ⟨fun hI ↦ ?_, fun hI ↦ ?_⟩
· obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset
exact (hM₁ hB).subset hIB
obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset
exact (hM₂ hB).subset hIB
/-- 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. -/
@[mk_iff] 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_rankFinite {M : Matroid α} [RankFinite M] : Finitary M where
indep_of_forall_finite I hI := by
refine I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
obtain ⟨B, hB⟩ := M.exists_isBase
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_isBase_superset
have hle := ncard_le_ncard hI₀B' hB'.finite
rw [hI₀card, hB'.ncard_eq_ncard_of_isBase 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 copy
/-- create a copy of `M : Matroid α` with independence and base predicates and ground set defeq
to supplied arguments that are provably equal to those of `M`. -/
@[simps] def copy (M : Matroid α) (E : Set α) (IsBase Indep : Set α → Prop) (hE : E = M.E)
(hB : ∀ B, IsBase B ↔ M.IsBase B) (hI : ∀ I, Indep I ↔ M.Indep I) : Matroid α where
E := E
IsBase := IsBase
Indep := Indep
indep_iff' _ := by simp_rw [hI, hB, M.indep_iff]
exists_isBase := by
simp_rw [hB]
exact M.exists_isBase
isBase_exchange := by
simp_rw [show IsBase = M.IsBase from funext (by simp [hB])]
exact M.isBase_exchange
maximality := by
simp_rw [hE, show Indep = M.Indep from funext (by simp [hI])]
exact M.maximality
subset_ground := by
simp_rw [hE, hB]
exact M.subset_ground
/-- create a copy of `M : Matroid α` with an independence predicate and ground set defeq
to supplied arguments that are provably equal to those of `M`. -/
@[simps!] def copyIndep (M : Matroid α) (E : Set α) (Indep : Set α → Prop)
(hE : E = M.E) (h : ∀ I, Indep I ↔ M.Indep I) : Matroid α :=
M.copy E M.IsBase Indep hE (fun _ ↦ Iff.rfl) h
/-- create a copy of `M : Matroid α` with a base predicate and ground set defeq
to supplied arguments that are provably equal to those of `M`. -/
@[simps!] def copyBase (M : Matroid α) (E : Set α) (IsBase : Set α → Prop)
(hE : E = M.E) (h : ∀ B, IsBase B ↔ M.IsBase B) : Matroid α :=
M.copy E IsBase M.Indep hE h (fun _ ↦ Iff.rfl)
end copy
section IsBasis
/-- 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 IsBasis (M : Matroid α) (I X : Set α) : Prop :=
Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I ∧ X ⊆ M.E
@[deprecated (since := "2025-02-14")] alias Basis := IsBasis
/-- `Matroid.IsBasis' I X` is the same as `Matroid.IsBasis I X`,
without the requirement that `X ⊆ M.E`. This is convenient for some
API building, especially when working with rank and closure. -/
def IsBasis' (M : Matroid α) (I X : Set α) : Prop :=
Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I
@[deprecated (since := "2025-02-14")] alias Basis' := IsBasis'
variable {B I J X Y : Set α} {e : α}
theorem IsBasis'.indep (hI : M.IsBasis' I X) : M.Indep I :=
hI.1.1
theorem IsBasis.indep (hI : M.IsBasis I X) : M.Indep I :=
hI.1.1.1
theorem IsBasis.subset (hI : M.IsBasis I X) : I ⊆ X :=
hI.1.1.2
theorem IsBasis.isBasis' (hI : M.IsBasis I X) : M.IsBasis' I X :=
hI.1
theorem IsBasis'.isBasis (hI : M.IsBasis' I X) (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X :=
⟨hI, hX⟩
theorem IsBasis'.subset (hI : M.IsBasis' I X) : I ⊆ X :=
hI.1.2
@[aesop unsafe 15% (rule_sets := [Matroid])]
theorem IsBasis.subset_ground (hI : M.IsBasis I X) : X ⊆ M.E :=
hI.2
theorem IsBasis.isBasis_inter_ground (hI : M.IsBasis I X) : M.IsBasis I (X ∩ M.E) := by
convert hI
rw [inter_eq_self_of_subset_left hI.subset_ground]
@[aesop unsafe 15% (rule_sets := [Matroid])]
theorem IsBasis.left_subset_ground (hI : M.IsBasis I X) : I ⊆ M.E :=
hI.indep.subset_ground
theorem IsBasis.eq_of_subset_indep (hI : M.IsBasis I X) (hJ : M.Indep J) (hIJ : I ⊆ J)
(hJX : J ⊆ X) : I = J :=
hIJ.antisymm (hI.1.2 ⟨hJ, hJX⟩ hIJ)
theorem IsBasis.Finite (hI : M.IsBasis I X) [RankFinite M] : I.Finite := hI.indep.finite
theorem isBasis_iff' :
M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E := by
rw [IsBasis, maximal_subset_iff]
tauto
theorem isBasis_iff (hX : X ⊆ M.E := by aesop_mat) :
M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) := by
rw [isBasis_iff', and_iff_left hX]
theorem isBasis'_iff_isBasis_inter_ground : M.IsBasis' I X ↔ M.IsBasis I (X ∩ M.E) := by
rw [IsBasis', IsBasis, and_iff_left inter_subset_right, maximal_iff_maximal_of_imp_of_forall]
· exact fun I hI ↦ ⟨hI.1, hI.2.trans inter_subset_left⟩
exact fun I hI ↦ ⟨I, rfl.le, hI.1, subset_inter hI.2 hI.1.subset_ground⟩
theorem isBasis'_iff_isBasis (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis' I X ↔ M.IsBasis I X := by
rw [isBasis'_iff_isBasis_inter_ground, inter_eq_self_of_subset_left hX]
theorem isBasis_iff_isBasis'_subset_ground : M.IsBasis I X ↔ M.IsBasis' I X ∧ X ⊆ M.E :=
⟨fun h ↦ ⟨h.isBasis', h.subset_ground⟩, fun h ↦ (isBasis'_iff_isBasis h.2).mp h.1⟩
theorem IsBasis'.isBasis_inter_ground (hIX : M.IsBasis' I X) : M.IsBasis I (X ∩ M.E) :=
isBasis'_iff_isBasis_inter_ground.mp hIX
theorem IsBasis'.eq_of_subset_indep (hI : M.IsBasis' I X) (hJ : M.Indep J) (hIJ : I ⊆ J)
(hJX : J ⊆ X) : I = J :=
hIJ.antisymm (hI.2 ⟨hJ, hJX⟩ hIJ)
theorem IsBasis'.insert_not_indep (hI : M.IsBasis' 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 isBasis_iff_maximal (hX : X ⊆ M.E := by aesop_mat) :
M.IsBasis I X ↔ Maximal (fun I ↦ M.Indep I ∧ I ⊆ X) I := by
rw [IsBasis, and_iff_left hX]
theorem Indep.isBasis_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.IsBasis I X := by
rw [isBasis_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 IsBasis.isBasis_subset (hI : M.IsBasis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) :
M.IsBasis I Y := by
rw [isBasis_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 isBasis_self_iff_indep : M.IsBasis I I ↔ M.Indep I := by
rw [isBasis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp]
exact fun hi ↦ ⟨fun _ _ ↦ subset_antisymm, hi.subset_ground⟩
theorem Indep.isBasis_self (h : M.Indep I) : M.IsBasis I I :=
isBasis_self_iff_indep.mpr h
@[simp] theorem isBasis_empty_iff (M : Matroid α) : M.IsBasis I ∅ ↔ I = ∅ :=
⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (rw [h]; exact M.empty_indep.isBasis_self)⟩
theorem IsBasis.dep_of_ssubset (hI : M.IsBasis 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 IsBasis.insert_dep (hI : M.IsBasis 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 IsBasis.mem_of_insert_indep (hI : M.IsBasis 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 IsBasis'.mem_of_insert_indep (hI : M.IsBasis' I X) (he : e ∈ X)
(hIe : M.Indep (insert e I)) : e ∈ I :=
hI.isBasis_inter_ground.mem_of_insert_indep ⟨he, hIe.subset_ground (mem_insert _ _)⟩ hIe
theorem IsBasis.not_isBasis_of_ssubset (hI : M.IsBasis I X) (hJI : J ⊂ I) : ¬ M.IsBasis J X :=
fun h ↦ hJI.ne (h.eq_of_subset_indep hI.indep hJI.subset hI.subset)
theorem Indep.subset_isBasis_of_subset (hI : M.Indep I) (hIX : I ⊆ X)
(hX : X ⊆ M.E := by aesop_mat) : ∃ J, M.IsBasis J X ∧ I ⊆ J := by
obtain ⟨J, hJ, hJmax⟩ := M.maximality X hX I hI hIX
exact ⟨J, ⟨hJmax, hX⟩, hJ⟩
theorem Indep.subset_isBasis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) :
∃ J, M.IsBasis' J X ∧ I ⊆ J := by
simp_rw [isBasis'_iff_isBasis_inter_ground]
exact hI.subset_isBasis_of_subset (subset_inter hIX hI.subset_ground)
theorem exists_isBasis (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) :
∃ I, M.IsBasis I X :=
let ⟨_, hI, _⟩ := M.empty_indep.subset_isBasis_of_subset (empty_subset X)
⟨_, hI⟩
theorem exists_isBasis' (M : Matroid α) (X : Set α) : ∃ I, M.IsBasis' I X :=
let ⟨_, hI, _⟩ := M.empty_indep.subset_isBasis'_of_subset (empty_subset X)
⟨_, hI⟩
theorem exists_isBasis_subset_isBasis (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) :
∃ I J, M.IsBasis I X ∧ M.IsBasis J Y ∧ I ⊆ J := by
obtain ⟨I, hI⟩ := M.exists_isBasis X (hXY.trans hY)
obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_isBasis_of_subset (hI.subset.trans hXY)
exact ⟨_, _, hI, hJ, hIJ⟩
theorem IsBasis.exists_isBasis_inter_eq_of_superset (hI : M.IsBasis I X) (hXY : X ⊆ Y)
(hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.IsBasis J Y ∧ J ∩ X = I := by
obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_isBasis_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))
theorem exists_isBasis_union_inter_isBasis (M : Matroid α) (X Y : Set α)
(hX : X ⊆ M.E := by aesop_mat) (hY : Y ⊆ M.E := by aesop_mat) :
∃ I, M.IsBasis I (X ∪ Y) ∧ M.IsBasis (I ∩ Y) Y :=
let ⟨J, hJ⟩ := M.exists_isBasis Y
(hJ.exists_isBasis_inter_eq_of_superset subset_union_right).imp
(fun I hI ↦ ⟨hI.1, by rwa [hI.2]⟩)
theorem Indep.eq_of_isBasis (hI : M.Indep I) (hJ : M.IsBasis J I) : J = I :=
hJ.eq_of_subset_indep hI hJ.subset rfl.subset
| Mathlib/Data/Matroid/Basic.lean | 979 | 985 | theorem IsBasis.exists_isBase (hI : M.IsBasis I X) : ∃ B, M.IsBase B ∧ I = B ∩ X :=
let ⟨B,hB, hIB⟩ := hI.indep.exists_isBase_superset
⟨B, hB, subset_antisymm (subset_inter hIB hI.subset)
(by rw [hI.eq_of_subset_indep (hB.indep.inter_right X) (subset_inter hIB hI.subset)
inter_subset_right])⟩
@[simp] theorem isBasis_ground_iff : M.IsBasis B M.E ↔ M.IsBase B := by |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.