Context stringlengths 227 76.5k | target stringlengths 0 11.6k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 16 3.69k |
|---|---|---|---|---|
/-
Copyright (c) 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∞}
| Mathlib/Data/ENNReal/Real.lean | 372 | 374 |
/-
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, Johan Commelin, Mario Carneiro
-/
import Mathlib.Data.Finsupp.Lex
import Mathlib.Algebra.MvPolynomial.Degrees
/-!
# Variables of polynomials
This file establishes many results about the variable sets of a multivariate polynomial.
The *variable set* of a polynomial $P \in R[X]$ is a `Finset` containing each $x \in X$
that appears in a monomial in $P$.
## Main declarations
* `MvPolynomial.vars p` : the finset of variables occurring in `p`.
For example if `p = x⁴y+yz` then `vars p = {x, y, z}`
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v w
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
section Vars
/-! ### `vars` -/
/-- `vars p` is the set of variables appearing in the polynomial `p` -/
def vars (p : MvPolynomial σ R) : Finset σ :=
letI := Classical.decEq σ
p.degrees.toFinset
theorem vars_def [DecidableEq σ] (p : MvPolynomial σ R) : p.vars = p.degrees.toFinset := by
rw [vars]
convert rfl
@[simp]
theorem vars_0 : (0 : MvPolynomial σ R).vars = ∅ := by
classical rw [vars_def, degrees_zero, Multiset.toFinset_zero]
@[simp]
theorem vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support := by
classical rw [vars_def, degrees_monomial_eq _ _ h, Finsupp.toFinset_toMultiset]
@[simp]
theorem vars_C : (C r : MvPolynomial σ R).vars = ∅ := by
classical rw [vars_def, degrees_C, Multiset.toFinset_zero]
@[simp]
theorem vars_X [Nontrivial R] : (X n : MvPolynomial σ R).vars = {n} := by
rw [X, vars_monomial (one_ne_zero' R), Finsupp.support_single_ne_zero _ (one_ne_zero' ℕ)]
theorem mem_vars (i : σ) : i ∈ p.vars ↔ ∃ d ∈ p.support, i ∈ d.support := by
classical simp only [vars_def, Multiset.mem_toFinset, mem_degrees, mem_support_iff, exists_prop]
theorem mem_support_not_mem_vars_zero {f : MvPolynomial σ R} {x : σ →₀ ℕ} (H : x ∈ f.support)
{v : σ} (h : v ∉ vars f) : x v = 0 := by
contrapose! h
exact (mem_vars v).mpr ⟨x, H, Finsupp.mem_support_iff.mpr h⟩
theorem vars_add_subset [DecidableEq σ] (p q : MvPolynomial σ R) :
(p + q).vars ⊆ p.vars ∪ q.vars := by
intro x hx
simp only [vars_def, Finset.mem_union, Multiset.mem_toFinset] at hx ⊢
simpa using Multiset.mem_of_le degrees_add_le hx
theorem vars_add_of_disjoint [DecidableEq σ] (h : Disjoint p.vars q.vars) :
(p + q).vars = p.vars ∪ q.vars := by
refine (vars_add_subset p q).antisymm fun x hx => ?_
simp only [vars_def, Multiset.disjoint_toFinset] at h hx ⊢
rwa [degrees_add_of_disjoint h, Multiset.toFinset_union]
|
section Mul
theorem vars_mul [DecidableEq σ] (φ ψ : MvPolynomial σ R) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars := by
simp_rw [vars_def, ← Multiset.toFinset_add, Multiset.toFinset_subset]
| Mathlib/Algebra/MvPolynomial/Variables.lean | 108 | 112 |
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Sites.Sheaf
/-!
# Coverages
A coverage `K` on a category `C` is a set of presieves associated to every object `X : C`,
called "covering presieves".
This collection must satisfy a certain "pullback compatibility" condition, saying that
whenever `S` is a covering presieve on `X` and `f : Y ⟶ X` is a morphism, then there exists
some covering sieve `T` on `Y` such that `T` factors through `S` along `f`.
The main difference between a coverage and a Grothendieck pretopology is that we *do not*
require `C` to have pullbacks.
This is useful, for example, when we want to consider the Grothendieck topology on the category
of extremally disconnected sets in the context of condensed mathematics.
A more concrete example: If `ℬ` is a basis for a topology on a type `X` (in the sense of
`TopologicalSpace.IsTopologicalBasis`) then it naturally induces a coverage on `Opens X`
whose associated Grothendieck topology is the one induced by the topology
on `X` generated by `ℬ`. (Project: Formalize this!)
## Main Definitions and Results:
All definitions are in the `CategoryTheory` namespace.
- `Coverage C`: The type of coverages on `C`.
- `Coverage.ofGrothendieck C`: A function which associates a coverage to any Grothendieck topology.
- `Coverage.toGrothendieck C`: A function which associates a Grothendieck topology to any coverage.
- `Coverage.gi`: The two functions above form a Galois insertion.
- `Presieve.isSheaf_coverage`: Given `K : Coverage C` with associated
Grothendieck topology `J`, a `Type*`-valued presheaf on `C` is a sheaf for `K` if and only if
it is a sheaf for `J`.
# References
We don't follow any particular reference, but the arguments can probably be distilled from
the following sources:
- [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1.
- [nLab, *Coverage*](https://ncatlab.org/nlab/show/coverage)
-/
namespace CategoryTheory
variable {C D : Type _} [Category C] [Category D]
open Limits
namespace Presieve
/--
Given a morphism `f : Y ⟶ X`, a presieve `S` on `Y` and presieve `T` on `X`,
we say that *`S` factors through `T` along `f`*, written `S.FactorsThruAlong T f`,
provided that for any morphism `g : Z ⟶ Y` in `S`, there exists some
morphism `e : W ⟶ X` in `T` and some morphism `i : Z ⟶ W` such that the obvious
square commutes: `i ≫ e = g ≫ f`.
This is used in the definition of a coverage.
-/
def FactorsThruAlong {X Y : C} (S : Presieve Y) (T : Presieve X) (f : Y ⟶ X) : Prop :=
∀ ⦃Z : C⦄ ⦃g : Z ⟶ Y⦄, S g →
∃ (W : C) (i : Z ⟶ W) (e : W ⟶ X), T e ∧ i ≫ e = g ≫ f
/--
Given `S T : Presieve X`, we say that `S` factors through `T` if any morphism in `S`
factors through some morphism in `T`.
The lemma `Presieve.isSheafFor_of_factorsThru` gives a *sufficient* condition for a
presheaf to be a sheaf for a presieve `T`, in terms of `S.FactorsThru T`, provided
that the presheaf is a sheaf for `S`.
-/
def FactorsThru {X : C} (S T : Presieve X) : Prop :=
∀ ⦃Z : C⦄ ⦃g : Z ⟶ X⦄, S g →
∃ (W : C) (i : Z ⟶ W) (e : W ⟶ X), T e ∧ i ≫ e = g
@[simp]
lemma factorsThruAlong_id {X : C} (S T : Presieve X) :
S.FactorsThruAlong T (𝟙 X) ↔ S.FactorsThru T := by
simp [FactorsThruAlong, FactorsThru]
lemma factorsThru_of_le {X : C} (S T : Presieve X) (h : S ≤ T) :
S.FactorsThru T :=
fun Y g hg => ⟨Y, 𝟙 _, g, h _ hg, by simp⟩
lemma le_of_factorsThru_sieve {X : C} (S : Presieve X) (T : Sieve X) (h : S.FactorsThru T) :
S ≤ T := by
rintro Y f hf
obtain ⟨W, i, e, h1, rfl⟩ := h hf
exact T.downward_closed h1 _
lemma factorsThru_top {X : C} (S : Presieve X) : S.FactorsThru ⊤ :=
factorsThru_of_le _ _ le_top
lemma isSheafFor_of_factorsThru
{X : C} {S T : Presieve X}
(P : Cᵒᵖ ⥤ Type*)
(H : S.FactorsThru T) (hS : S.IsSheafFor P)
(h : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, T f → ∃ (R : Presieve Y),
R.IsSeparatedFor P ∧ R.FactorsThruAlong S f) :
T.IsSheafFor P := by
simp only [← Presieve.isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] at *
choose W i e h1 h2 using H
refine ⟨?_, fun x hx => ?_⟩
· intro x y₁ y₂ h₁ h₂
refine hS.1.ext (fun Y g hg => ?_)
simp only [← h2 hg, op_comp, P.map_comp, types_comp_apply, h₁ _ (h1 _ ), h₂ _ (h1 _)]
let y : S.FamilyOfElements P := fun Y g hg => P.map (i _).op (x (e hg) (h1 _))
have hy : y.Compatible := by
intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ h
rw [← types_comp_apply (P.map (i h₁).op) (P.map g₁.op),
← types_comp_apply (P.map (i h₂).op) (P.map g₂.op),
← P.map_comp, ← op_comp, ← P.map_comp, ← op_comp]
apply hx
simp only [h2, h, Category.assoc]
let ⟨_, h2'⟩ := hS
obtain ⟨z, hz⟩ := h2' y hy
refine ⟨z, fun Y g hg => ?_⟩
obtain ⟨R, hR1, hR2⟩ := h hg
choose WW ii ee hh1 hh2 using hR2
refine hR1.ext (fun Q t ht => ?_)
rw [← types_comp_apply (P.map g.op) (P.map t.op), ← P.map_comp, ← op_comp, ← hh2 ht,
op_comp, P.map_comp, types_comp_apply, hz _ (hh1 _),
← types_comp_apply _ (P.map (ii ht).op), ← P.map_comp, ← op_comp]
apply hx
simp only [Category.assoc, h2, hh2]
end Presieve
variable (C) in
/--
The type `Coverage C` of coverages on `C`.
A coverage is a collection of *covering* presieves on every object `X : C`,
which satisfies a *pullback compatibility* condition.
Explicitly, this condition says that whenever `S` is a covering presieve for `X` and
`f : Y ⟶ X` is a morphism, then there exists some covering presieve `T` for `Y`
such that `T` factors through `S` along `f`.
-/
@[ext]
structure Coverage where
/-- The collection of covering presieves for an object `X`. -/
covering : ∀ (X : C), Set (Presieve X)
/-- Given any covering sieve `S` on `X` and a morphism `f : Y ⟶ X`, there exists
some covering sieve `T` on `Y` such that `T` factors through `S` along `f`. -/
pullback : ∀ ⦃X Y : C⦄ (f : Y ⟶ X) (S : Presieve X) (_ : S ∈ covering X),
∃ (T : Presieve Y), T ∈ covering Y ∧ T.FactorsThruAlong S f
namespace Coverage
instance : CoeFun (Coverage C) (fun _ => (X : C) → Set (Presieve X)) where
coe := covering
variable (C) in
/--
Associate a coverage to any Grothendieck topology.
If `J` is a Grothendieck topology, and `K` is the associated coverage, then a presieve
`S` is a covering presieve for `K` if and only if the sieve that it generates is a
covering sieve for `J`.
-/
def ofGrothendieck (J : GrothendieckTopology C) : Coverage C where
covering X := { S | Sieve.generate S ∈ J X }
pullback := by
intro X Y f S (hS : Sieve.generate S ∈ J X)
refine ⟨(Sieve.generate S).pullback f, ?_, fun Z g h => h⟩
dsimp
rw [Sieve.generate_sieve]
exact J.pullback_stable _ hS
lemma ofGrothendieck_iff {X : C} {S : Presieve X} (J : GrothendieckTopology C) :
S ∈ ofGrothendieck _ J X ↔ Sieve.generate S ∈ J X := Iff.rfl
/--
An auxiliary definition used to define the Grothendieck topology associated to a
coverage. See `Coverage.toGrothendieck`.
-/
inductive Saturate (K : Coverage C) : (X : C) → Sieve X → Prop where
| of (X : C) (S : Presieve X) (hS : S ∈ K X) : Saturate K X (Sieve.generate S)
| top (X : C) : Saturate K X ⊤
| transitive (X : C) (R S : Sieve X) :
Saturate K X R →
(∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, R f → Saturate K Y (S.pullback f)) →
Saturate K X S
lemma eq_top_pullback {X Y : C} {S T : Sieve X} (h : S ≤ T) (f : Y ⟶ X) (hf : S f) :
T.pullback f = ⊤ := by
ext Z g
simp only [Sieve.pullback_apply, Sieve.top_apply, iff_true]
apply h
apply S.downward_closed
exact hf
lemma saturate_of_superset (K : Coverage C) {X : C} {S T : Sieve X} (h : S ≤ T)
(hS : Saturate K X S) : Saturate K X T := by
apply Saturate.transitive _ _ _ hS
intro Y g hg
rw [eq_top_pullback (h := h)]
· apply Saturate.top
· assumption
variable (C) in
/--
The Grothendieck topology associated to a coverage `K`.
It is defined *inductively* as follows:
1. If `S` is a covering presieve for `K`, then the sieve generated by `S` is a covering
sieve for the associated Grothendieck topology.
2. The top sieves are in the associated Grothendieck topology.
3. Add all sieves required by the *local character* axiom of a Grothendieck topology.
The pullback compatibility condition for a coverage ensures that the
associated Grothendieck topology is pullback stable, and so an additional constructor
in the inductive construction is not needed.
-/
def toGrothendieck (K : Coverage C) : GrothendieckTopology C where
sieves := Saturate K
top_mem' := .top
pullback_stable' := by
intro X Y S f hS
induction hS generalizing Y with
| of X S hS =>
obtain ⟨R,hR1,hR2⟩ := K.pullback f S hS
suffices Sieve.generate R ≤ (Sieve.generate S).pullback f from
saturate_of_superset _ this (Saturate.of _ _ hR1)
rintro Z g ⟨W, i, e, h1, h2⟩
obtain ⟨WW, ii, ee, hh1, hh2⟩ := hR2 h1
refine ⟨WW, i ≫ ii, ee, hh1, ?_⟩
simp only [hh2, reassoc_of% h2, Category.assoc]
| top X => apply Saturate.top
| transitive X R S _ hS H1 _ =>
apply Saturate.transitive
· apply H1 f
intro Z g hg
rw [← Sieve.pullback_comp]
exact hS hg
transitive' _ _ hS _ hR := .transitive _ _ _ hS hR
instance : PartialOrder (Coverage C) where
le A B := A.covering ≤ B.covering
le_refl _ _ := le_refl _
le_trans _ _ _ h1 h2 X := le_trans (h1 X) (h2 X)
le_antisymm _ _ h1 h2 := Coverage.ext <| funext <|
fun X => le_antisymm (h1 X) (h2 X)
variable (C) in
/--
The two constructions `Coverage.toGrothendieck` and `Coverage.ofGrothendieck` form
a Galois insertion.
-/
def gi : GaloisInsertion (toGrothendieck C) (ofGrothendieck C) where
choice K _ := toGrothendieck _ K
choice_eq := fun _ _ => rfl
le_l_u J X S hS := by
rw [← Sieve.generate_sieve S]
apply Saturate.of
dsimp [ofGrothendieck]
rwa [Sieve.generate_sieve S]
gc K J := by
constructor
· intro H X S hS
exact H _ <| Saturate.of _ _ hS
· intro H X S hS
induction hS with
| of X S hS => exact H _ hS
| top => apply J.top_mem
| transitive X R S _ _ H1 H2 => exact J.transitive H1 _ H2
/--
An alternative characterization of the Grothendieck topology associated to a coverage `K`:
it is the infimum of all Grothendieck topologies whose associated coverage contains `K`.
-/
theorem toGrothendieck_eq_sInf (K : Coverage C) : toGrothendieck _ K =
sInf {J | K ≤ ofGrothendieck _ J } := by
apply le_antisymm
· apply le_sInf; intro J hJ
intro X S hS
induction hS with
| of X S hS => apply hJ; assumption
| top => apply J.top_mem
| transitive X R S _ _ H1 H2 => exact J.transitive H1 _ H2
· apply sInf_le
intro X S hS
apply Saturate.of _ _ hS
instance : SemilatticeSup (Coverage C) where
sup x y :=
{ covering := fun B ↦ x.covering B ∪ y.covering B
pullback := by
rintro X Y f S (hx | hy)
· obtain ⟨T, hT⟩ := x.pullback f S hx
exact ⟨T, Or.inl hT.1, hT.2⟩
· obtain ⟨T, hT⟩ := y.pullback f S hy
exact ⟨T, Or.inr hT.1, hT.2⟩ }
toPartialOrder := inferInstance
le_sup_left _ _ _ := Set.subset_union_left
le_sup_right _ _ _ := Set.subset_union_right
sup_le _ _ _ hx hy X := Set.union_subset_iff.mpr ⟨hx X, hy X⟩
@[simp]
lemma sup_covering (x y : Coverage C) (B : C) :
(x ⊔ y).covering B = x.covering B ∪ y.covering B :=
rfl
/--
Any sieve that contains a covering presieve for a coverage is a covering sieve for the associated
Grothendieck topology.
-/
theorem mem_toGrothendieck_sieves_of_superset (K : Coverage C) {X : C} {S : Sieve X}
{R : Presieve X} (h : R ≤ S) (hR : R ∈ K.covering X) : S ∈ (K.toGrothendieck C) X :=
K.saturate_of_superset ((Sieve.generate_le_iff _ _).mpr h) (Coverage.Saturate.of X _ hR)
end Coverage
open Coverage
namespace Presieve
/--
The main theorem of this file: Given a coverage `K` on `C`,
a `Type*`-valued presheaf on `C` is a sheaf for `K` if and only if it is a sheaf for
the associated Grothendieck topology.
-/
theorem isSheaf_coverage (K : Coverage C) (P : Cᵒᵖ ⥤ Type*) :
Presieve.IsSheaf (toGrothendieck _ K) P ↔
(∀ {X : C} (R : Presieve X), R ∈ K X → Presieve.IsSheafFor P R) := by
constructor
· intro H X R hR
rw [Presieve.isSheafFor_iff_generate]
apply H _ <| Saturate.of _ _ hR
· intro H X S hS
-- This is the key point of the proof:
-- We must generalize the induction in the correct way.
suffices ∀ ⦃Y : C⦄ (f : Y ⟶ X), Presieve.IsSheafFor P (S.pullback f).arrows by
simpa using this (f := 𝟙 _)
induction hS with
| of X S hS =>
intro Y f
obtain ⟨T, hT1, hT2⟩ := K.pullback f S hS
apply Presieve.isSheafFor_of_factorsThru (S := T)
· intro Z g hg
obtain ⟨W, i, e, h1, h2⟩ := hT2 hg
exact ⟨Z, 𝟙 _, g, ⟨W, i, e, h1, h2⟩, by simp⟩
· apply H; assumption
· intro Z g _
obtain ⟨R, hR1, hR2⟩ := K.pullback g _ hT1
exact ⟨R, (H _ hR1).isSeparatedFor, hR2⟩
| top => intros; simpa using Presieve.isSheafFor_top_sieve _
| transitive X R S _ _ H1 H2 =>
intro Y f
simp only [← Presieve.isSeparatedFor_and_exists_isAmalgamation_iff_isSheafFor] at *
choose H1 H1' using H1
choose H2 H2' using H2
refine ⟨?_, fun x hx => ?_⟩
· intro x t₁ t₂ h₁ h₂
refine (H1 f).ext (fun Z g hg => ?_)
refine (H2 hg (𝟙 _)).ext (fun ZZ gg hgg => ?_)
simp only [Sieve.pullback_id, Sieve.pullback_apply] at hgg
simp only [← types_comp_apply]
rw [← P.map_comp, ← op_comp, h₁, h₂]
simpa only [Sieve.pullback_apply, Category.assoc] using hgg
let y : ∀ ⦃Z : C⦄ (g : Z ⟶ Y),
((S.pullback (g ≫ f)).pullback (𝟙 _)).arrows.FamilyOfElements P :=
fun Z g ZZ gg hgg => x (gg ≫ g) (by simpa using hgg)
have hy : ∀ ⦃Z : C⦄ (g : Z ⟶ Y), (y g).Compatible := by
intro Z g Y₁ Y₂ ZZ g₁ g₂ f₁ f₂ h₁ h₂ h
rw [hx]
rw [reassoc_of% h]
choose z hz using fun ⦃Z : C⦄ ⦃g : Z ⟶ Y⦄ (hg : R.pullback f g) =>
H2' hg (𝟙 _) (y g) (hy g)
let q : (R.pullback f).arrows.FamilyOfElements P := fun Z g hg => z hg
have hq : q.Compatible := by
intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ h
apply (H2 h₁ g₁).ext
intro ZZ gg hgg
simp only [← types_comp_apply]
rw [← P.map_comp, ← P.map_comp, ← op_comp, ← op_comp, hz, hz]
· dsimp [y]; congr 1; simp only [Category.assoc, h]
· simpa [reassoc_of% h] using hgg
· simpa using hgg
obtain ⟨t, ht⟩ := H1' f q hq
refine ⟨t, fun Z g hg => ?_⟩
refine (H1 (g ≫ f)).ext (fun ZZ gg hgg => ?_)
rw [← types_comp_apply _ (P.map gg.op), ← P.map_comp, ← op_comp, ht]
on_goal 2 => simpa using hgg
refine (H2 hgg (𝟙 _)).ext (fun ZZZ ggg hggg => ?_)
rw [← types_comp_apply _ (P.map ggg.op), ← P.map_comp, ← op_comp, hz]
on_goal 2 => simpa using hggg
refine (H2 hgg ggg).ext (fun ZZZZ gggg _ => ?_)
rw [← types_comp_apply _ (P.map gggg.op), ← P.map_comp, ← op_comp]
apply hx
simp
/--
A presheaf is a sheaf for the Grothendieck topology generated by a union of coverages iff it is a
sheaf for the Grothendieck topology generated by each coverage separately.
-/
theorem isSheaf_sup (K L : Coverage C) (P : Cᵒᵖ ⥤ Type*) :
(Presieve.IsSheaf ((K ⊔ L).toGrothendieck C)) P ↔
(Presieve.IsSheaf (K.toGrothendieck C)) P ∧ (Presieve.IsSheaf (L.toGrothendieck C)) P := by
refine ⟨fun h ↦ ⟨Presieve.isSheaf_of_le _ ((gi C).gc.monotone_l le_sup_left) h,
Presieve.isSheaf_of_le _ ((gi C).gc.monotone_l le_sup_right) h⟩, fun h ↦ ?_⟩
rw [isSheaf_coverage, isSheaf_coverage] at h
rw [isSheaf_coverage]
intro X R hR
rcases hR with hR | hR
· exact h.1 R hR
· exact h.2 R hR
end Presieve
namespace Presheaf
| theorem isSheaf_iff_isLimit_coverage (K : Coverage C) (P : Cᵒᵖ ⥤ D) :
Presheaf.IsSheaf (toGrothendieck _ K) P ↔ ∀ ⦃X : C⦄ (R : Presieve X),
R ∈ K.covering X →
Nonempty (IsLimit (P.mapCone (Sieve.generate R).arrows.cocone.op)) := by
simp only [Presheaf.IsSheaf, Presieve.isSheaf_coverage, isLimit_iff_isSheafFor,
← Presieve.isSheafFor_iff_generate]
aesop
| Mathlib/CategoryTheory/Sites/Coverage.lean | 416 | 422 |
/-
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, Jeremy Avigad
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Notation.Pi
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Filter.Defs
/-!
# Theory of filters on sets
A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`,
is upwards-closed, and is stable under intersection. They are mostly used to
abstract two related kinds of ideas:
* *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions
at a point or at infinity, etc...
* *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough
a point `x`, or for close enough pairs of points, or things happening almost everywhere in the
sense of measure theory. Dually, filters can also express the idea of *things happening often*:
for arbitrarily large `n`, or at a point in any neighborhood of given a point etc...
## Main definitions
In this file, we endow `Filter α` it with a complete lattice structure.
This structure is lifted from the lattice structure on `Set (Set X)` using the Galois
insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to
the smallest filter containing it in the other direction.
We also prove `Filter` is a monadic functor, with a push-forward operation
`Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the
order on filters.
The examples of filters appearing in the description of the two motivating ideas are:
* `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N`
* `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic)
* `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces
defined in `Mathlib/Topology/UniformSpace/Basic.lean`)
* `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ`
(defined in `Mathlib/MeasureTheory/OuterMeasure/AE`)
The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is
`Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come
rather late in this file in order to immediately relate them to the lattice structure).
## Notations
* `∀ᶠ x in f, p x` : `f.Eventually p`;
* `∃ᶠ x in f, p x` : `f.Frequently p`;
* `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`;
* `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`;
* `𝓟 s` : `Filter.Principal s`, localized in `Filter`.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which
we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element
`⊥` for its lattice structure, at the cost of including the assumption
`[NeBot f]` in a number of lemmas and definitions.
-/
assert_not_exists OrderedSemiring Fintype
open Function Set Order
open scoped symmDiff
universe u v w x y
namespace Filter
variable {α : Type u} {f g : Filter α} {s t : Set α}
instance inhabitedMem : Inhabited { s : Set α // s ∈ f } :=
⟨⟨univ, f.univ_sets⟩⟩
theorem filter_eq_iff : f = g ↔ f.sets = g.sets :=
⟨congr_arg _, filter_eq⟩
@[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl
@[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl
/-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g.,
`Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/
protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g :=
Filter.ext <| compl_surjective.forall.2 h
instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where
trans h₁ h₂ := mem_of_superset h₂ h₁
instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where
trans h₁ h₂ := mem_of_superset h₁ h₂
@[simp]
theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f :=
⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩,
and_imp.2 inter_mem⟩
theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f :=
inter_mem hs ht
theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f :=
⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs =>
mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩
lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem
/-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/
theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) :
(⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by
apply Subsingleton.induction_on hf <;> simp
/-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/
theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] :
(⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by
rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range]
theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f :=
⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩
theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h =>
mem_of_superset h hst
theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P)
(hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by
constructor
· rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩
exact
⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩
· rintro ⟨u, huf, hPu, hQu⟩
exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩
theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} :
(∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b :=
Set.forall_in_swap
end Filter
namespace Filter
variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x}
theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl
section Lattice
variable {f g : Filter α} {s t : Set α}
protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop]
/-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/
inductive GenerateSets (g : Set (Set α)) : Set α → Prop
| basic {s : Set α} : s ∈ g → GenerateSets g s
| univ : GenerateSets g univ
| superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t
| inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t)
/-- `generate g` is the largest filter containing the sets `g`. -/
def generate (g : Set (Set α)) : Filter α where
sets := {s | GenerateSets g s}
univ_sets := GenerateSets.univ
sets_of_superset := GenerateSets.superset
inter_sets := GenerateSets.inter
lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) :
U ∈ generate s := GenerateSets.basic h
theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets :=
Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu =>
hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy =>
inter_mem hx hy
@[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s :=
le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <|
le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl
/-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly
`s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/
protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where
sets := s
univ_sets := hs ▸ univ_mem
sets_of_superset := hs ▸ mem_of_superset
inter_sets := hs ▸ inter_mem
theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} :
Filter.mkOfClosure s hs = generate s :=
Filter.ext fun u =>
show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl
/-- Galois insertion from sets of sets into filters. -/
def giGenerate (α : Type*) :
@GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where
gc _ _ := le_generate_iff
le_l_u _ _ h := GenerateSets.basic h
choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl)
choice_eq _ _ := mkOfClosure_sets
theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ :=
Iff.rfl
theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g :=
⟨s, h, univ, univ_mem, (inter_univ s).symm⟩
theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g :=
⟨univ, univ_mem, s, h, (univ_inter s).symm⟩
theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) :
s ∩ t ∈ f ⊓ g :=
⟨s, hs, t, ht, rfl⟩
theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g)
(h : s ∩ t ⊆ u) : u ∈ f ⊓ g :=
mem_of_superset (inter_mem_inf hs ht) h
theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} :
s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s :=
⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ =>
mem_inf_of_inter h₁ h₂ sub⟩
section CompleteLattice
/-- Complete lattice structure on `Filter α`. -/
instance instCompleteLatticeFilter : CompleteLattice (Filter α) where
inf a b := min a b
sup a b := max a b
le_sup_left _ _ _ h := h.1
le_sup_right _ _ _ h := h.2
sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩
inf_le_left _ _ _ := mem_inf_of_left
inf_le_right _ _ _ := mem_inf_of_right
le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb)
le_sSup _ _ h₁ _ h₂ := h₂ h₁
sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂
sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂
le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁
le_top _ _ := univ_mem'
bot_le _ _ _ := trivial
instance : Inhabited (Filter α) := ⟨⊥⟩
end CompleteLattice
theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne'
@[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left
theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g :=
⟨ne_bot_of_le_ne_bot hf.1 hg⟩
theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g :=
hf.mono hg
@[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by
simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff]
theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff]
theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl
/-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot`
as the second alternative, to be used as an instance. -/
theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk
theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets :=
(giGenerate α).gc.u_inf
theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets :=
(giGenerate α).gc.u_sInf
theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets :=
(giGenerate α).gc.u_iInf
theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) :=
(giGenerate α).gc.l_bot
theorem generate_univ : Filter.generate univ = (⊥ : Filter α) :=
bot_unique fun _ _ => GenerateSets.basic (mem_univ _)
theorem generate_union {s t : Set (Set α)} :
Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t :=
(giGenerate α).gc.l_sup
theorem generate_iUnion {s : ι → Set (Set α)} :
Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) :=
(giGenerate α).gc.l_iSup
@[simp]
theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g :=
Iff.rfl
theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g :=
⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩
@[simp]
theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by
simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter]
@[simp]
theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by
simp [neBot_iff]
theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) :=
eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff]
theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i :=
iInf_le f i hs
@[simp]
theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f :=
⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩
theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } :=
Set.ext fun _ => le_principal_iff
theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by
simp only [le_principal_iff, mem_principal]
@[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono
@[mono]
theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2
@[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by
simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl
@[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl
@[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ :=
top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true]
@[simp]
theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ :=
bot_unique fun _ _ => empty_subset _
theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s :=
eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def]
/-! ### Lattice equations -/
theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ :=
⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩
theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id
theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty :=
@Filter.nonempty_of_mem α f hf s hs
@[simp]
theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl
theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α :=
nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f)
theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc =>
(nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s
theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ :=
empty_mem_iff_bot.mp <| univ_mem' isEmptyElim
protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by
simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty,
@eq_comm _ ∅]
theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f)
(ht : t ∈ g) : Disjoint f g :=
Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩
theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h =>
not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩
theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by
simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty]
/-- There is exactly one filter on an empty type. -/
instance unique [IsEmpty α] : Unique (Filter α) where
default := ⊥
uniq := filter_eq_bot_of_isEmpty
theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α :=
not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _)
/-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are
equal. -/
theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by
refine top_unique fun s hs => ?_
obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs)
exact univ_mem
theorem forall_mem_nonempty_iff_neBot {f : Filter α} :
(∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f :=
⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩
instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) :=
forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]
instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) :=
⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩
theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α :=
⟨fun _ =>
by_contra fun h' =>
haveI := not_nonempty_iff.1 h'
not_subsingleton (Filter α) inferInstance,
@Filter.instNontrivialFilter α⟩
theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S :=
le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩)
fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs
theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f :=
eq_sInf_of_mem_iff_exists_mem <| h.trans (exists_range_iff (p := (_ ∈ ·))).symm
theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by
rw [iInf_subtype']
exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop]
theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] :
(iInf f).sets = ⋃ i, (f i).sets :=
let ⟨i⟩ := ne
let u :=
{ sets := ⋃ i, (f i).sets
univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩
sets_of_superset := by
simp only [mem_iUnion, exists_imp]
exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩
inter_sets := by
simp only [mem_iUnion, exists_imp]
intro x y a hx b hy
rcases h a b with ⟨c, ha, hb⟩
exact ⟨c, inter_mem (ha hx) (hb hy)⟩ }
have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion
congr_arg Filter.sets this.symm
theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) :
s ∈ iInf f ↔ ∃ i, s ∈ f i := by
simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion]
theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by
haveI := ne.to_subtype
simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop]
theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets :=
ext fun t => by simp [mem_biInf_of_directed h ne]
@[simp]
theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) :=
Filter.ext fun x => by simp only [mem_sup, mem_join]
@[simp]
theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) :=
Filter.ext fun x => by simp only [mem_iSup, mem_join]
instance : DistribLattice (Filter α) :=
{ Filter.instCompleteLatticeFilter with
le_sup_inf := by
intro x y z s
simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp]
rintro hs t₁ ht₁ t₂ ht₂ rfl
exact
⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂,
x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ }
/-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/
theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
(∀ i, NeBot (f i)) → NeBot (iInf f) :=
not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot,
mem_iInf_of_directed hd] using id
/-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/
theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f)
(hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by
cases isEmpty_or_nonempty ι
· constructor
simp [iInf_of_empty f, top_ne_bot]
· exact iInf_neBot_of_directed' hd hb
theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
@iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ =>
⟨ne_of_mem_of_not_mem hf hbot⟩
theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩
theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩
theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩
/-! #### `principal` equations -/
@[simp]
theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) :=
le_antisymm
(by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩)
(by simp [le_inf_iff, inter_subset_left, inter_subset_right])
@[simp]
theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) :=
Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal]
@[simp]
theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) :=
Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff]
@[simp]
theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ :=
empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff
@[simp]
theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty :=
neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm
alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff
theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) :=
IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by
rw [sup_principal, union_compl_self, principal_univ]
theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by
simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal,
← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl]
lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by
simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq]
lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by
ext
simp only [mem_iSup, mem_inf_principal]
theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by
rw [← empty_mem_iff_bot, mem_inf_principal]
simp only [mem_empty_iff_false, imp_false, compl_def]
theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by
rwa [inf_principal_eq_bot, compl_compl] at h
theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) :
s \ t ∈ f ⊓ 𝓟 tᶜ :=
inter_mem_inf hs <| mem_principal_self tᶜ
theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by
simp_rw [le_def, mem_principal]
end Lattice
@[mono, gcongr]
theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs
/-! ### Eventually -/
theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f :=
Iff.rfl
@[simp]
theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l :=
Iff.rfl
protected theorem ext' {f₁ f₂ : Filter α}
(h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ :=
Filter.ext h
theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop}
(hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x :=
h hp
theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f)
(h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x :=
mem_of_superset hU h
protected theorem Eventually.and {p q : α → Prop} {f : Filter α} :
f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x :=
inter_mem
@[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem
theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x :=
univ_mem' hp
@[simp]
theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ :=
empty_mem_iff_bot
@[simp]
theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by
by_cases h : p <;> simp [h, t.ne]
theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y :=
exists_mem_subset_iff.symm
theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) :
∃ v ∈ f, ∀ y ∈ v, p y :=
eventually_iff_exists_mem.1 hp
theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x :=
mp_mem hp hq
theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x :=
hp.mp (Eventually.of_forall hq)
theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop}
(h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y :=
fun y => h.mono fun _ h => h y
@[simp]
theorem eventually_and {p q : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x :=
inter_mem_iff
theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x)
(h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x :=
h'.mp (h.mono fun _ hx => hx.mp)
theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) :
(∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x :=
⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩
@[simp]
theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x :=
by_cases (fun h : p => by simp [h]) fun h => by simp [h]
@[simp]
theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by
simp only [@or_comm _ q, eventually_or_distrib_left]
theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by
simp only [imp_iff_not_or, eventually_or_distrib_left]
@[simp]
theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x :=
⟨⟩
@[simp]
theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x :=
Iff.rfl
@[simp]
theorem eventually_sup {p : α → Prop} {f g : Filter α} :
(∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x :=
Iff.rfl
@[simp]
theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x :=
Iff.rfl
@[simp]
theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} :
(∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x :=
mem_iSup
@[simp]
theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x :=
Iff.rfl
theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop}
(hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x :=
Filter.eventually_principal.mp (hP.filter_mono hf)
theorem eventually_inf {f g : Filter α} {p : α → Prop} :
(∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x :=
mem_inf_iff_superset
theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} :
(∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x :=
mem_inf_principal
theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} :
(∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where
mp h _ := by filter_upwards [h] with _ pa _ using pa
mpr h := by filter_upwards [h univ] with _ pa using pa (by simp)
/-! ### Frequently -/
theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) :
∃ᶠ x in f, p x :=
compl_not_mem h
theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) :
∃ᶠ x in f, p x :=
Eventually.frequently (Eventually.of_forall h)
theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x :=
mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h
lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) :
(∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x :=
⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩
theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) :
∃ᶠ x in g, p x :=
mt (fun h' => h'.filter_mono hle) h
theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x :=
h.mp (Eventually.of_forall hpq)
theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x)
(hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
refine mt (fun h => hq.mp <| h.mono ?_) hp
exact fun x hpq hq hp => hpq ⟨hp, hq⟩
theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
simpa only [and_comm] using hq.and_eventually hp
theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by
by_contra H
replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H)
exact hp H
theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) :
∃ x, p x :=
hp.frequently.exists
lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} :
(∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by
rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl
lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) :=
frequently_iff_neBot
theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} :
(∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x :=
⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by
simpa only [and_not_self_iff, exists_false] using H hp⟩
theorem frequently_iff {f : Filter α} {P : α → Prop} :
(∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by
simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)]
rfl
@[simp]
theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by
simp [Filter.Frequently]
@[simp]
theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by
simp only [Filter.Frequently, not_not]
@[simp]
theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by
simp [frequently_iff_neBot]
@[simp]
theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp
@[simp]
theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by
by_cases p <;> simp [*]
@[simp]
theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and]
theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp
theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp
theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by
simp [imp_iff_not_or]
theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib]
theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by
simp only [frequently_imp_distrib, frequently_const]
theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by
simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently]
@[simp]
theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp]
@[simp]
theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by
simp only [@and_comm _ q, frequently_and_distrib_left]
@[simp]
theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp
@[simp]
theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently]
@[simp]
theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by
simp [Filter.Frequently, not_forall]
theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} :
| (∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by
simp only [Filter.Frequently, eventually_inf_principal, not_and]
alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal
| Mathlib/Order/Filter/Basic.lean | 821 | 824 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.Module.End
import Mathlib.Algebra.Ring.Prod
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Tactic.FinCases
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `ZMod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
* A coercion `cast` is defined from `ZMod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
assert_not_exists Field Submodule TwoSidedIdeal
open Function ZMod
namespace ZMod
/-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/
def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n
| 0, h => (h.ne _ rfl).elim
| _ + 1, _ => .refl _
instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ)
/-- `val a` is a natural number defined as:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
See `ZMod.valMinAbs` for a variant that takes values in the integers.
-/
def val : ∀ {n : ℕ}, ZMod n → ℕ
| 0 => Int.natAbs
| n + 1 => ((↑) : Fin (n + 1) → ℕ)
theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by
cases n
· cases NeZero.ne 0 rfl
exact Fin.is_lt a
theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n :=
a.val_lt.le
@[simp]
theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0
| 0 => rfl
| _ + 1 => rfl
@[simp]
theorem val_one' : (1 : ZMod 0).val = 1 :=
rfl
@[simp]
theorem val_neg' {n : ZMod 0} : (-n).val = n.val :=
Int.natAbs_neg n
@[simp]
theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val :=
Int.natAbs_mul m n
@[simp]
theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by
cases n
· rw [Nat.mod_zero]
exact Int.natAbs_natCast a
· apply Fin.val_natCast
lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rwa [val_natCast, Nat.mod_eq_of_lt]
lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast ..
lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) :=
val_natCast_of_lt han
theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by
simp only [val]
rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one]
lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by
rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h]
instance charP (n : ℕ) : CharP (ZMod n) n where
cast_eq_zero_iff := by
intro k
rcases n with - | n
· simp [zero_dvd_iff, Int.natCast_eq_zero]
· exact Fin.natCast_eq_zero
@[simp]
theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n :=
CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n)
/-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version
where `a ≠ 0` is `addOrderOf_coe'`. -/
@[simp]
theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rcases a with - | a
· simp only [Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right,
Nat.pos_of_ne_zero n0, Nat.div_self]
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one]
/-- This lemma works in the case in which `a ≠ 0`. The version where
`ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/
@[simp]
theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one]
/-- We have that `ringChar (ZMod n) = n`. -/
theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by
rw [ringChar.eq_iff]
exact ZMod.charP n
theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 :=
CharP.cast_eq_zero (ZMod n) n
@[simp]
theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by
rw [← Nat.cast_add_one, natCast_self (n + 1)]
section UniversalProperty
variable {n : ℕ} {R : Type*}
section
variable [AddGroupWithOne R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `ZMod.castHom` for a bundled version. -/
def cast : ∀ {n : ℕ}, ZMod n → R
| 0 => Int.cast
| _ + 1 => fun i => i.val
@[simp]
theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by
delta ZMod.cast
cases n
· exact Int.cast_zero
· simp
theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by
cases n
· cases NeZero.ne 0 rfl
rfl
variable {S : Type*} [AddGroupWithOne S]
@[simp]
theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by
cases n
· rfl
· simp [ZMod.cast]
@[simp]
theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by
cases n
· rfl
· simp [ZMod.cast]
end
/-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring,
see `ZMod.natCast_val`. -/
theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.cast_val_eq_self
theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) :=
natCast_zmod_val
theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) :=
natCast_rightInverse.surjective
/-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary
ring, see `ZMod.intCast_cast`. -/
@[norm_cast]
theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by
cases n
· simp [ZMod.cast, ZMod]
· dsimp [ZMod.cast]
rw [Int.cast_natCast, natCast_zmod_val]
theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) :=
intCast_zmod_cast
theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) :=
intCast_rightInverse.surjective
lemma «forall» {P : ZMod n → Prop} : (∀ x, P x) ↔ ∀ x : ℤ, P x := intCast_surjective.forall
lemma «exists» {P : ZMod n → Prop} : (∃ x, P x) ↔ ∃ x : ℤ, P x := intCast_surjective.exists
theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i
| 0, _ => Int.cast_id
| _ + 1, i => natCast_zmod_val i
@[simp]
theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id :=
funext (cast_id n)
variable (R) [Ring R]
/-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/
@[simp]
theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by
cases n
· cases NeZero.ne 0 rfl
rfl
/-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/
@[simp]
theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by
cases n
· exact congr_arg (Int.cast ∘ ·) ZMod.cast_id'
· ext
simp [ZMod, ZMod.cast]
variable {R}
@[simp]
theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i :=
congr_fun (natCast_comp_val R) i
@[simp]
theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i :=
congr_fun (intCast_comp_cast R) i
theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) :
(cast (a + b) : ℤ) =
if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by
rcases n with - | n
· simp; rfl
change Fin (n + 1) at a b
change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
simp only [Fin.val_add_eq_ite, Int.natCast_succ, Int.ofNat_le]
norm_cast
split_ifs with h
· rw [Nat.cast_sub h]
congr
· rfl
section CharDvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variable {m : ℕ} [CharP R m]
@[simp]
theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by
rcases n with - | n
· exact Int.cast_one
show ((1 % (n + 1) : ℕ) : R) = 1
cases n
· rw [Nat.dvd_one] at h
subst m
subsingleton [CharP.CharOne.subsingleton]
rw [Nat.mod_eq_of_lt]
· exact Nat.cast_one
exact Nat.lt_of_sub_eq_succ rfl
theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by
cases n
· apply Int.cast_add
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_add, Fin.val_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by
cases n
· apply Int.cast_mul
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_mul, Fin.val_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
/-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`.
See also `ZMod.lift` for a generalized version working in `AddGroup`s.
-/
def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where
toFun := cast
map_zero' := cast_zero
map_one' := cast_one h
map_add' := cast_add h
map_mul' := cast_mul h
@[simp]
theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i :=
rfl
@[simp]
theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
(castHom h R).map_sub a b
@[simp]
theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) :=
(castHom h R).map_neg a
@[simp]
theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k :=
(castHom h R).map_pow a k
@[simp, norm_cast]
theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k :=
map_natCast (castHom h R) k
@[simp, norm_cast]
theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k :=
map_intCast (castHom h R) k
end CharDvd
section CharEq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [CharP R n]
@[simp]
theorem cast_one' : (cast (1 : ZMod n) : R) = 1 :=
cast_one dvd_rfl
@[simp]
theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b :=
cast_add dvd_rfl a b
@[simp]
theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b :=
cast_mul dvd_rfl a b
@[simp]
theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
cast_sub dvd_rfl a b
@[simp]
theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k :=
cast_natCast dvd_rfl k
@[simp, norm_cast]
theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k :=
cast_intCast dvd_rfl k
variable (R)
theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by
rw [injective_iff_map_eq_zero]
intro x
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x
rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n]
exact id
theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) :
Function.Bijective (ZMod.castHom (dvd_refl n) R) := by
haveI : NeZero n :=
⟨by
intro hn
rw [hn] at h
exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩
rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true]
apply ZMod.castHom_injective
/-- The unique ring isomorphism between `ZMod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R :=
RingEquiv.ofBijective _ (ZMod.castHom_bijective R h)
/-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`.
If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv`
below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/
noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) :
ZMod p ≃+* R :=
have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt)
-- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`.
have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R)
ZMod.ringEquiv R hR
@[simp]
lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime)
(hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl
/-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/
def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by
rcases m with - | m <;> rcases n with - | n
· exact RingEquiv.refl _
· exfalso
exact n.succ_ne_zero h.symm
· exfalso
exact m.succ_ne_zero h
· exact
{ finCongr h with
map_mul' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h]
map_add' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] }
@[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by
cases a <;> rfl
lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by
rw [ringEquivCongr_refl]
rfl
lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) :
(ringEquivCongr hab).symm = ringEquivCongr hab.symm := by
subst hab
cases a <;> rfl
lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) :
(ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by
subst hab hbc
cases a <;> rfl
lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) :
ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by
rw [← ringEquivCongr_trans hab hbc]
rfl
lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) :
ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by
subst h
cases a <;> rfl
lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) :
ZMod.ringEquivCongr h z = z := by
subst h
cases a <;> rfl
end CharEq
end UniversalProperty
variable {m n : ℕ}
@[simp]
theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0
| 0, _ => Int.natAbs_eq_zero
| n + 1, a => by
rw [Fin.ext_iff]
exact Iff.rfl
theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] :=
CharP.intCast_eq_intCast (ZMod c) c
theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.intCast_eq_intCast_iff a b c
theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by
have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _
have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a)
refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_
rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id]
theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by
simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c
theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.natCast_eq_natCast_iff a b c
theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by
rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd]
theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by
rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd]
theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by
rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd]
theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by
cases n
· rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl
· rw [← val_intCast, val]; rfl
lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by
rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by
rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast]
@[simp]
theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by
dsimp [val, Fin.coe_neg]
cases n
· simp [Nat.mod_one]
· dsimp [ZMod, ZMod.cast]
rw [Fin.coe_neg_one]
/-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/
theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by
rcases n with - | n
· dsimp [ZMod, ZMod.cast]; simp
· rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right]
theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) :
(cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by
split_ifs with hk
· rw [hk, zero_sub, ZMod.cast_neg_one]
· cases n
· dsimp [ZMod, ZMod.cast]
rw [Int.cast_sub, Int.cast_one]
· dsimp [ZMod, ZMod.cast, ZMod.val]
rw [Fin.coe_sub_one, if_neg]
· rw [Nat.cast_sub, Nat.cast_one]
rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk
· exact hk
theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_natCast, Nat.mod_add_div]
· rintro ⟨k, rfl⟩
rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul,
add_zero]
theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_intCast, Int.emod_add_ediv]
· rintro ⟨k, rfl⟩
rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val,
ZMod.natCast_self, zero_mul, add_zero, cast_id]
@[push_cast, simp]
theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by
rw [ZMod.intCast_eq_intCast_iff]
apply Int.mod_modEq
theorem ker_intCastAddHom (n : ℕ) :
(Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by
ext
rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom,
intCast_zmod_eq_zero_iff_dvd]
theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) :
Function.Injective (@cast (ZMod n) _ m) := by
cases m with
| zero => cases nzm; simp_all
| succ m =>
rintro ⟨x, hx⟩ ⟨y, hy⟩ f
simp only [cast, val, natCast_eq_natCast_iff',
Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f
apply Fin.ext
exact f
theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast a : ZMod n) = 0 ↔ a = 0 := by
rw [← ZMod.cast_zero (n := m)]
exact Injective.eq_iff' (cast_injective_of_le h) rfl
|
@[simp]
| Mathlib/Data/ZMod/Basic.lean | 595 | 596 |
/-
Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Eric Wieser
-/
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.RingTheory.PowerBasis
/-!
# The minimal polynomial divides the characteristic polynomial of a matrix.
This also includes some miscellaneous results about `minpoly` on matrices.
-/
noncomputable section
universe u v w
open Polynomial Matrix
variable {R : Type u} [CommRing R]
variable {n : Type v} [DecidableEq n] [Fintype n]
variable {N : Type w} [AddCommGroup N] [Module R N]
open Finset
namespace Matrix
variable (M : Matrix n n R)
@[simp]
theorem minpoly_toLin' : minpoly R (toLin' M) = minpoly R M :=
minpoly.algEquiv_eq (toLinAlgEquiv' : Matrix n n R ≃ₐ[R] _) M
@[simp]
theorem minpoly_toLin (b : Basis n R N) (M : Matrix n n R) :
minpoly R (toLin b b M) = minpoly R M :=
minpoly.algEquiv_eq (toLinAlgEquiv b : Matrix n n R ≃ₐ[R] _) M
theorem isIntegral : IsIntegral R M :=
⟨M.charpoly, ⟨charpoly_monic M, aeval_self_charpoly M⟩⟩
theorem minpoly_dvd_charpoly {K : Type*} [Field K] (M : Matrix n n K) : minpoly K M ∣ M.charpoly :=
minpoly.dvd _ _ (aeval_self_charpoly M)
end Matrix
namespace LinearMap
@[simp]
theorem minpoly_toMatrix' (f : (n → R) →ₗ[R] n → R) : minpoly R (toMatrix' f) = minpoly R f :=
minpoly.algEquiv_eq (toMatrixAlgEquiv' : _ ≃ₐ[R] Matrix n n R) f
@[simp]
theorem minpoly_toMatrix (b : Basis n R N) (f : N →ₗ[R] N) :
minpoly R (toMatrix b b f) = minpoly R f :=
minpoly.algEquiv_eq (toMatrixAlgEquiv b : _ ≃ₐ[R] Matrix n n R) f
end LinearMap
section PowerBasis
open Algebra
/-- The characteristic polynomial of the map `fun x => a * x` is the minimal polynomial of `a`.
In combination with `det_eq_sign_charpoly_coeff` or `trace_eq_neg_charpoly_coeff`
and a bit of rewriting, this will allow us to conclude the
field norm resp. trace of `x` is the product resp. sum of `x`'s conjugates.
-/
theorem charpoly_leftMulMatrix {S : Type*} [Ring S] [Algebra R S] (h : PowerBasis R S) :
(leftMulMatrix h.basis h.gen).charpoly = minpoly R h.gen := by
cases subsingleton_or_nontrivial R; · subsingleton
apply minpoly.unique' R h.gen (charpoly_monic _)
· apply (injective_iff_map_eq_zero (G := S) (leftMulMatrix _)).mp
(leftMulMatrix_injective h.basis)
rw [← Polynomial.aeval_algHom_apply, aeval_self_charpoly]
refine fun q hq => or_iff_not_imp_left.2 fun h0 => ?_
rw [Matrix.charpoly_degree_eq_dim, Fintype.card_fin] at hq
contrapose! hq; exact h.dim_le_degree_of_root h0 hq
|
end PowerBasis
| Mathlib/LinearAlgebra/Matrix/Charpoly/Minpoly.lean | 83 | 92 |
/-
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
/-!
# Monotone functions on an order topology
This file contains lemmas about limits and continuity for monotone / antitone functions on
linearly-ordered sets (with the order topology). For example, we prove that a monotone function
has left and right limits at any point (`Monotone.tendsto_nhdsLT`, `Monotone.tendsto_nhdsGT`).
-/
open Set Filter TopologicalSpace Topology Function
open OrderDual (toDual ofDual)
variable {α β : Type*}
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderClosedTopology β]
/-- A monotone function continuous at the supremum of a nonempty set sends this supremum to
the supremum of the image of this set. -/
theorem MonotoneOn.map_csSup_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sSup A))
(Mf : MonotoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) :
f (sSup A) = sSup (f '' A) :=
--This is a particular case of the more general `IsLUB.isLUB_of_tendsto`
.symm <| ((isLUB_csSup A_nonemp A_bdd).isLUB_of_tendsto Mf A_nonemp <|
Cf.mono_left fun ⦃_⦄ a ↦ a).csSup_eq (A_nonemp.image f)
/-- A monotone function continuous at the supremum of a nonempty set sends this supremum to
the supremum of the image of this set. -/
theorem Monotone.map_csSup_of_continuousAt {f : α → β} {A : Set α}
(Cf : ContinuousAt f (sSup A)) (Mf : Monotone f) (A_nonemp : A.Nonempty)
(A_bdd : BddAbove A := by bddDefault) : f (sSup A) = sSup (f '' A) :=
MonotoneOn.map_csSup_of_continuousWithinAt Cf.continuousWithinAt
(Mf.monotoneOn _) A_nonemp A_bdd
/-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed
supremum to the indexed supremum of the composition. -/
theorem Monotone.map_ciSup_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Mf : Monotone f)
(bdd : BddAbove (range g) := by bddDefault) : f (⨆ i, g i) = ⨆ i, f (g i) := by
rw [iSup, Monotone.map_csSup_of_continuousAt Cf Mf (range_nonempty g) bdd, ← range_comp, iSup,
comp_def]
/-- A monotone function continuous at the infimum of a nonempty set sends this infimum to
the infimum of the image of this set. -/
theorem MonotoneOn.map_csInf_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sInf A))
(Mf : MonotoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sInf (f '' A) :=
MonotoneOn.map_csSup_of_continuousWithinAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual A_nonemp A_bdd
/-- A monotone function continuous at the infimum of a nonempty set sends this infimum to
the infimum of the image of this set. -/
theorem Monotone.map_csInf_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A))
(Mf : Monotone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sInf (f '' A) :=
Monotone.map_csSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual A_nonemp A_bdd
/-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed
infimum to the indexed infimum of the composition. -/
theorem Monotone.map_ciInf_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Mf : Monotone f)
(bdd : BddBelow (range g) := by bddDefault) : f (⨅ i, g i) = ⨅ i, f (g i) := by
rw [iInf, Monotone.map_csInf_of_continuousAt Cf Mf (range_nonempty g) bdd, ← range_comp, iInf,
comp_def]
/-- An antitone function continuous at the infimum of a nonempty set sends this infimum to
the supremum of the image of this set. -/
theorem AntitoneOn.map_csInf_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sInf A))
(Af : AntitoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sSup (f '' A) :=
MonotoneOn.map_csInf_of_continuousWithinAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the infimum of a nonempty set sends this infimum to
the supremum of the image of this set. -/
theorem Antitone.map_csInf_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A))
(Af : Antitone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sSup (f '' A) :=
Monotone.map_csInf_of_continuousAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed
infimum to the indexed supremum of the composition. -/
theorem Antitone.map_ciInf_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Af : Antitone f)
(bdd : BddBelow (range g) := by bddDefault) : f (⨅ i, g i) = ⨆ i, f (g i) := by
rw [iInf, Antitone.map_csInf_of_continuousAt Cf Af (range_nonempty g) bdd, ← range_comp, iSup,
comp_def]
/-- An antitone function continuous at the supremum of a nonempty set sends this supremum to
the infimum of the image of this set. -/
theorem AntitoneOn.map_csSup_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sSup A))
(Af : AntitoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) :
f (sSup A) = sInf (f '' A) :=
MonotoneOn.map_csSup_of_continuousWithinAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the supremum of a nonempty set sends this supremum to
the infimum of the image of this set. -/
theorem Antitone.map_csSup_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sSup A))
(Af : Antitone f) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) :
f (sSup A) = sInf (f '' A) :=
Monotone.map_csSup_of_continuousAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the indexed supremum over a nonempty `Sort` sends this
indexed supremum to the indexed infimum of the composition. -/
theorem Antitone.map_ciSup_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Af : Antitone f)
(bdd : BddAbove (range g) := by bddDefault) : f (⨆ i, g i) = ⨅ i, f (g i) := by
rw [iSup, Antitone.map_csSup_of_continuousAt Cf Af (range_nonempty g) bdd, ← range_comp, iInf,
comp_def]
end ConditionallyCompleteLinearOrder
section CompleteLinearOrder
variable [CompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [CompleteLinearOrder β]
[TopologicalSpace β] [OrderClosedTopology β]
theorem sSup_mem_closure {s : Set α} (hs : s.Nonempty) : sSup s ∈ closure s :=
(isLUB_sSup s).mem_closure hs
theorem sInf_mem_closure {s : Set α} (hs : s.Nonempty) : sInf s ∈ closure s :=
(isGLB_sInf s).mem_closure hs
theorem IsClosed.sSup_mem {s : Set α} (hs : s.Nonempty) (hc : IsClosed s) : sSup s ∈ s :=
(isLUB_sSup s).mem_of_isClosed hs hc
theorem IsClosed.sInf_mem {s : Set α} (hs : s.Nonempty) (hc : IsClosed s) : sInf s ∈ s :=
(isGLB_sInf s).mem_of_isClosed hs hc
/-- A monotone function `f` sending `bot` to `bot` and continuous at the supremum of a set sends
this supremum to the supremum of the image of this set. -/
theorem MonotoneOn.map_sSup_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sSup s))
(Mf : MonotoneOn f s) (fbot : f ⊥ = ⊥) : f (sSup s) = sSup (f '' s) := by
rcases s.eq_empty_or_nonempty with h | h
· simp [h, fbot]
· exact Mf.map_csSup_of_continuousWithinAt Cf h
/-- A monotone function `f` sending `bot` to `bot` and continuous at the supremum of a set sends
this supremum to the supremum of the image of this set. -/
theorem Monotone.map_sSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s))
(Mf : Monotone f) (fbot : f ⊥ = ⊥) : f (sSup s) = sSup (f '' s) :=
MonotoneOn.map_sSup_of_continuousWithinAt Cf.continuousWithinAt (Mf.monotoneOn _) fbot
/-- If a monotone function sending `bot` to `bot` is continuous at the indexed supremum over
a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/
theorem Monotone.map_iSup_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Mf : Monotone f) (fbot : f ⊥ = ⊥) :
f (⨆ i, g i) = ⨆ i, f (g i) := by
rw [iSup, Mf.map_sSup_of_continuousAt Cf fbot, ← range_comp, iSup, comp_def]
/-- A monotone function `f` sending `top` to `top` and continuous at the infimum of a set sends
this infimum to the infimum of the image of this set. -/
theorem MonotoneOn.map_sInf_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sInf s)) (Mf : MonotoneOn f s) (ftop : f ⊤ = ⊤) :
f (sInf s) = sInf (f '' s) :=
MonotoneOn.map_sSup_of_continuousWithinAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop
/-- A monotone function `f` sending `top` to `top` and continuous at the infimum of a set sends
this infimum to the infimum of the image of this set. -/
theorem Monotone.map_sInf_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sInf s))
(Mf : Monotone f) (ftop : f ⊤ = ⊤) : f (sInf s) = sInf (f '' s) :=
Monotone.map_sSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop
/-- If a monotone function sending `top` to `top` is continuous at the indexed infimum over
a `Sort`, then it sends this indexed infimum to the indexed infimum of the composition. -/
theorem Monotone.map_iInf_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Mf : Monotone f) (ftop : f ⊤ = ⊤) : f (iInf g) = iInf (f ∘ g) :=
Monotone.map_iSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop
/-- An antitone function `f` sending `bot` to `top` and continuous at the supremum of a set sends
this supremum to the infimum of the image of this set. -/
theorem AntitoneOn.map_sSup_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sSup s)) (Af : AntitoneOn f s) (fbot : f ⊥ = ⊤) :
f (sSup s) = sInf (f '' s) :=
MonotoneOn.map_sSup_of_continuousWithinAt
(show ContinuousWithinAt (OrderDual.toDual ∘ f) s (sSup s) from Cf) Af fbot
/-- An antitone function `f` sending `bot` to `top` and continuous at the supremum of a set sends
this supremum to the infimum of the image of this set. -/
theorem Antitone.map_sSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s))
(Af : Antitone f) (fbot : f ⊥ = ⊤) : f (sSup s) = sInf (f '' s) :=
Monotone.map_sSup_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (sSup s) from Cf) Af
fbot
/-- An antitone function sending `bot` to `top` is continuous at the indexed supremum over
a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/
theorem Antitone.map_iSup_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Af : Antitone f) (fbot : f ⊥ = ⊤) :
f (⨆ i, g i) = ⨅ i, f (g i) :=
Monotone.map_iSup_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (iSup g) from Cf) Af
fbot
/-- An antitone function `f` sending `top` to `bot` and continuous at the infimum of a set sends
this infimum to the supremum of the image of this set. -/
theorem AntitoneOn.map_sInf_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sInf s)) (Af : AntitoneOn f s) (ftop : f ⊤ = ⊥) :
f (sInf s) = sSup (f '' s) :=
MonotoneOn.map_sInf_of_continuousWithinAt
(show ContinuousWithinAt (OrderDual.toDual ∘ f) s (sInf s) from Cf) Af ftop
/-- An antitone function `f` sending `top` to `bot` and continuous at the infimum of a set sends
this infimum to the supremum of the image of this set. -/
theorem Antitone.map_sInf_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sInf s))
(Af : Antitone f) (ftop : f ⊤ = ⊥) : f (sInf s) = sSup (f '' s) :=
Monotone.map_sInf_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (sInf s) from Cf) Af
ftop
/-- If an antitone function sending `top` to `bot` is continuous at the indexed infimum over
a `Sort`, then it sends this indexed infimum to the indexed supremum of the composition. -/
theorem Antitone.map_iInf_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Af : Antitone f) (ftop : f ⊤ = ⊥) : f (iInf g) = iSup (f ∘ g) :=
Monotone.map_iInf_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (iInf g) from Cf) Af
ftop
end CompleteLinearOrder
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α]
theorem csSup_mem_closure {s : Set α} (hs : s.Nonempty) (B : BddAbove s) : sSup s ∈ closure s :=
(isLUB_csSup hs B).mem_closure hs
theorem csInf_mem_closure {s : Set α} (hs : s.Nonempty) (B : BddBelow s) : sInf s ∈ closure s :=
(isGLB_csInf hs B).mem_closure hs
theorem IsClosed.csSup_mem {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddAbove s) :
sSup s ∈ s :=
(isLUB_csSup hs B).mem_of_isClosed hs hc
theorem IsClosed.csInf_mem {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddBelow s) :
sInf s ∈ s :=
(isGLB_csInf hs B).mem_of_isClosed hs hc
theorem IsClosed.isLeast_csInf {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddBelow s) :
IsLeast s (sInf s) :=
⟨hc.csInf_mem hs B, (isGLB_csInf hs B).1⟩
theorem IsClosed.isGreatest_csSup {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddAbove s) :
IsGreatest s (sSup s) :=
IsClosed.isLeast_csInf (α := αᵒᵈ) hc hs B
lemma MonotoneOn.tendsto_nhdsWithin_Ioo_left {α β : Type*} [LinearOrder α] [TopologicalSpace α]
[OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
{f : α → β} {x y : α} (h_nonempty : (Ioo y x).Nonempty) (Mf : MonotoneOn f (Ioo y x))
(h_bdd : BddAbove (f '' Ioo y x)) :
Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Ioo y x))) := by
refine tendsto_order.2 ⟨fun l hl => ?_, fun m hm => ?_⟩
· obtain ⟨z, ⟨yz, zx⟩, lz⟩ : ∃ a : α, a ∈ Ioo y x ∧ l < f a := by
simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
exists_lt_of_lt_csSup (h_nonempty.image _) hl
filter_upwards [Ioo_mem_nhdsLT zx] with w hw
exact lz.trans_le <| Mf ⟨yz, zx⟩ ⟨yz.trans_le hw.1.le, hw.2⟩ hw.1.le
· rcases h_nonempty with ⟨_, hy, hx⟩
filter_upwards [Ioo_mem_nhdsLT (hy.trans hx)] with w hw
exact (le_csSup h_bdd (mem_image_of_mem _ hw)).trans_lt hm
lemma MonotoneOn.tendsto_nhdsWithin_Ioo_right {α β : Type*} [LinearOrder α] [TopologicalSpace α]
[OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
{f : α → β} {x y : α} (h_nonempty : (Ioo x y).Nonempty) (Mf : MonotoneOn f (Ioo x y))
(h_bdd : BddBelow (f '' Ioo x y)) :
Tendsto f (𝓝[>] x) (𝓝 (sInf (f '' Ioo x y))) := by
refine tendsto_order.2 ⟨fun l hl => ?_, fun m hm => ?_⟩
· rcases h_nonempty with ⟨p, hy, hx⟩
filter_upwards [Ioo_mem_nhdsGT (hy.trans hx)] with w hw
exact hl.trans_le <| csInf_le h_bdd (mem_image_of_mem _ hw)
· obtain ⟨z, ⟨xz, zy⟩, zm⟩ : ∃ a : α, a ∈ Ioo x y ∧ f a < m := by
simpa [mem_image, exists_prop, exists_exists_and_eq_and] using
| exists_lt_of_csInf_lt (h_nonempty.image _) hm
filter_upwards [Ioo_mem_nhdsGT xz] with w hw
exact (Mf ⟨hw.1, hw.2.trans zy⟩ ⟨xz, zy⟩ hw.2.le).trans_lt zm
lemma MonotoneOn.tendsto_nhdsLT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} {x : α}
(Mf : MonotoneOn f (Iio x)) (h_bdd : BddAbove (f '' Iio x)) :
Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
refine tendsto_order.2 ⟨fun l hl => ?_, fun m hm => ?_⟩
· obtain ⟨z, zx, lz⟩ : ∃ a : α, a < x ∧ l < f a := by
| Mathlib/Topology/Order/Monotone.lean | 282 | 292 |
/-
Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.AlgebraicGeometry.EllipticCurve.Group
import Mathlib.NumberTheory.EllipticDivisibilitySequence
/-!
# Division polynomials of Weierstrass curves
This file defines certain polynomials associated to division polynomials of Weierstrass curves.
These are defined in terms of the auxiliary sequences for normalised elliptic divisibility sequences
(EDS) as defined in `Mathlib.NumberTheory.EllipticDivisibilitySequence`.
## Mathematical background
Let `W` be a Weierstrass curve over a commutative ring `R`. The sequence of `n`-division polynomials
`ψₙ ∈ R[X, Y]` of `W` is the normalised EDS with initial values
* `ψ₀ := 0`,
* `ψ₁ := 1`,
* `ψ₂ := 2Y + a₁X + a₃`,
* `ψ₃ := 3X⁴ + b₂X³ + 3b₄X² + 3b₆X + b₈`, and
* `ψ₄ := ψ₂ ⬝ (2X⁶ + b₂X⁵ + 5b₄X⁴ + 10b₆X³ + 10b₈X² + (b₂b₈ - b₄b₆)X + (b₄b₈ - b₆²))`.
Furthermore, define the associated sequences `φₙ, ωₙ ∈ R[X, Y]` by
* `φₙ := Xψₙ² - ψₙ₊₁ ⬝ ψₙ₋₁`, and
* `ωₙ := (ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)) / 2`.
Note that `ωₙ` is always well-defined as a polynomial in `R[X, Y]`. As a start, it can be shown by
induction that `ψₙ` always divides `ψ₂ₙ` in `R[X, Y]`, so that `ψ₂ₙ / ψₙ` is always well-defined as
a polynomial, while division by `2` is well-defined when `R` has characteristic different from `2`.
In general, it can be shown that `2` always divides the polynomial `ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)`
in the characteristic `0` universal ring `𝓡[X, Y] := ℤ[A₁, A₂, A₃, A₄, A₆][X, Y]` of `W`, where the
`Aᵢ` are indeterminates. Then `ωₙ` can be equivalently defined as the image of this division under
the associated universal morphism `𝓡[X, Y] → R[X, Y]` mapping `Aᵢ` to `aᵢ`.
Now, in the coordinate ring `R[W]`, note that `ψ₂²` is congruent to the polynomial
`Ψ₂Sq := 4X³ + b₂X² + 2b₄X + b₆ ∈ R[X]`. As such, the recurrences of a normalised EDS show that
`ψₙ / ψ₂` are congruent to certain polynomials in `R[W]`. In particular, define `preΨₙ ∈ R[X]` as
the auxiliary sequence for a normalised EDS with extra parameter `Ψ₂Sq²` and initial values
* `preΨ₀ := 0`,
* `preΨ₁ := 1`,
* `preΨ₂ := 1`,
* `preΨ₃ := ψ₃`, and
* `preΨ₄ := ψ₄ / ψ₂`.
The corresponding normalised EDS `Ψₙ ∈ R[X, Y]` is then given by
* `Ψₙ := preΨₙ ⬝ ψ₂` if `n` is even, and
* `Ψₙ := preΨₙ` if `n` is odd.
Furthermore, define the associated sequences `ΨSqₙ, Φₙ ∈ R[X]` by
* `ΨSqₙ := preΨₙ² ⬝ Ψ₂Sq` if `n` is even,
* `ΨSqₙ := preΨₙ²` if `n` is odd,
* `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁` if `n` is even, and
* `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁ ⬝ Ψ₂Sq` if `n` is odd.
With these definitions, `ψₙ ∈ R[X, Y]` and `φₙ ∈ R[X, Y]` are congruent in `R[W]` to `Ψₙ ∈ R[X, Y]`
and `Φₙ ∈ R[X]` respectively, which are defined in terms of `Ψ₂Sq ∈ R[X]` and `preΨₙ ∈ R[X]`.
## Main definitions
* `WeierstrassCurve.preΨ`: the univariate polynomials `preΨₙ`.
* `WeierstrassCurve.ΨSq`: the univariate polynomials `ΨSqₙ`.
* `WeierstrassCurve.Ψ`: the bivariate polynomials `Ψₙ`.
* `WeierstrassCurve.Φ`: the univariate polynomials `Φₙ`.
* `WeierstrassCurve.ψ`: the bivariate `n`-division polynomials `ψₙ`.
* `WeierstrassCurve.φ`: the bivariate polynomials `φₙ`.
* TODO: the bivariate polynomials `ωₙ`.
## Implementation notes
Analogously to `Mathlib.NumberTheory.EllipticDivisibilitySequence`, the bivariate polynomials
`Ψₙ` are defined in terms of the univariate polynomials `preΨₙ`. This is done partially to avoid
ring division, but more crucially to allow the definition of `ΨSqₙ` and `Φₙ` as univariate
polynomials without needing to work under the coordinate ring, and to allow the computation of their
leading terms without ambiguity. Furthermore, evaluating these polynomials at a rational point on
`W` recovers their original definition up to linear combinations of the Weierstrass equation of `W`,
hence also avoiding the need to work in the coordinate ring.
TODO: implementation notes for the definition of `ωₙ`.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, division polynomial, torsion point
-/
open Polynomial
open scoped Polynomial.Bivariate
local macro "C_simp" : tactic =>
`(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow])
local macro "map_simp" : tactic =>
`(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀,
Polynomial.map_ofNat, Polynomial.map_one, map_C, map_X, Polynomial.map_neg, Polynomial.map_add,
Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom,
apply_ite <| mapRingHom _, WeierstrassCurve.map])
universe r s u v
namespace WeierstrassCurve
variable {R : Type r} {S : Type s} [CommRing R] [CommRing S] (W : WeierstrassCurve R)
section Ψ₂Sq
/-! ### The univariate polynomial `Ψ₂Sq` -/
/-- The `2`-division polynomial `ψ₂ = Ψ₂`. -/
noncomputable def ψ₂ : R[X][Y] :=
W.toAffine.polynomialY
/-- The univariate polynomial `Ψ₂Sq` congruent to `ψ₂²`. -/
noncomputable def Ψ₂Sq : R[X] :=
C 4 * X ^ 3 + C W.b₂ * X ^ 2 + C (2 * W.b₄) * X + C W.b₆
lemma C_Ψ₂Sq : C W.Ψ₂Sq = W.ψ₂ ^ 2 - 4 * W.toAffine.polynomial := by
rw [Ψ₂Sq, ψ₂, b₂, b₄, b₆, Affine.polynomialY, Affine.polynomial]
C_simp
ring1
lemma ψ₂_sq : W.ψ₂ ^ 2 = C W.Ψ₂Sq + 4 * W.toAffine.polynomial := by
rw [C_Ψ₂Sq, sub_add_cancel]
lemma Affine.CoordinateRing.mk_ψ₂_sq : mk W W.ψ₂ ^ 2 = mk W (C W.Ψ₂Sq) := by
rw [C_Ψ₂Sq, map_sub, map_mul, AdjoinRoot.mk_self, mul_zero, sub_zero, map_pow]
-- TODO: remove `twoTorsionPolynomial` in favour of `Ψ₂Sq`
lemma Ψ₂Sq_eq : W.Ψ₂Sq = W.twoTorsionPolynomial.toPoly :=
rfl
end Ψ₂Sq
section preΨ'
/-! ### The univariate polynomials `preΨₙ` for `n ∈ ℕ` -/
/-- The `3`-division polynomial `ψ₃ = Ψ₃`. -/
noncomputable def Ψ₃ : R[X] :=
3 * X ^ 4 + C W.b₂ * X ^ 3 + 3 * C W.b₄ * X ^ 2 + 3 * C W.b₆ * X + C W.b₈
/-- The univariate polynomial `preΨ₄`, which is auxiliary to the 4-division polynomial
`ψ₄ = Ψ₄ = preΨ₄ψ₂`. -/
noncomputable def preΨ₄ : R[X] :=
2 * X ^ 6 + C W.b₂ * X ^ 5 + 5 * C W.b₄ * X ^ 4 + 10 * C W.b₆ * X ^ 3 + 10 * C W.b₈ * X ^ 2 +
C (W.b₂ * W.b₈ - W.b₄ * W.b₆) * X + C (W.b₄ * W.b₈ - W.b₆ ^ 2)
/-- The univariate polynomials `preΨₙ` for `n ∈ ℕ`, which are auxiliary to the bivariate polynomials
`Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/
noncomputable def preΨ' (n : ℕ) : R[X] :=
preNormEDS' (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n
@[simp]
lemma preΨ'_zero : W.preΨ' 0 = 0 :=
preNormEDS'_zero ..
@[simp]
lemma preΨ'_one : W.preΨ' 1 = 1 :=
preNormEDS'_one ..
@[simp]
lemma preΨ'_two : W.preΨ' 2 = 1 :=
preNormEDS'_two ..
@[simp]
lemma preΨ'_three : W.preΨ' 3 = W.Ψ₃ :=
preNormEDS'_three ..
@[simp]
lemma preΨ'_four : W.preΨ' 4 = W.preΨ₄ :=
preNormEDS'_four ..
lemma preΨ'_even (m : ℕ) : W.preΨ' (2 * (m + 3)) =
W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2 :=
preNormEDS'_even ..
lemma preΨ'_odd (m : ℕ) : W.preΨ' (2 * (m + 2) + 1) =
W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS'_odd ..
end preΨ'
section preΨ
/-! ### The univariate polynomials `preΨₙ` for `n ∈ ℤ` -/
/-- The univariate polynomials `preΨₙ` for `n ∈ ℤ`, which are auxiliary to the bivariate polynomials
`Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/
noncomputable def preΨ (n : ℤ) : R[X] :=
preNormEDS (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n
@[simp]
lemma preΨ_ofNat (n : ℕ) : W.preΨ n = W.preΨ' n :=
preNormEDS_ofNat ..
@[simp]
lemma preΨ_zero : W.preΨ 0 = 0 :=
preNormEDS_zero ..
@[simp]
lemma preΨ_one : W.preΨ 1 = 1 :=
preNormEDS_one ..
@[simp]
lemma preΨ_two : W.preΨ 2 = 1 :=
preNormEDS_two ..
@[simp]
lemma preΨ_three : W.preΨ 3 = W.Ψ₃ :=
preNormEDS_three ..
@[simp]
lemma preΨ_four : W.preΨ 4 = W.preΨ₄ :=
preNormEDS_four ..
lemma preΨ_even_ofNat (m : ℕ) : W.preΨ (2 * (m + 3)) =
W.preΨ (m + 2) ^ 2 * W.preΨ (m + 3) * W.preΨ (m + 5) -
W.preΨ (m + 1) * W.preΨ (m + 3) * W.preΨ (m + 4) ^ 2 :=
preNormEDS_even_ofNat ..
lemma preΨ_odd_ofNat (m : ℕ) : W.preΨ (2 * (m + 2) + 1) =
W.preΨ (m + 4) * W.preΨ (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m + 1) * W.preΨ (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS_odd_ofNat ..
@[simp]
lemma preΨ_neg (n : ℤ) : W.preΨ (-n) = -W.preΨ n :=
preNormEDS_neg ..
lemma preΨ_even (m : ℤ) : W.preΨ (2 * m) =
W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) -
W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2 :=
preNormEDS_even ..
lemma preΨ_odd (m : ℤ) : W.preΨ (2 * m + 1) =
W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS_odd ..
end preΨ
section ΨSq
/-! ### The univariate polynomials `ΨSqₙ` -/
/-- The univariate polynomials `ΨSqₙ` congruent to `ψₙ²`. -/
noncomputable def ΨSq (n : ℤ) : R[X] :=
W.preΨ n ^ 2 * if Even n then W.Ψ₂Sq else 1
@[simp]
lemma ΨSq_ofNat (n : ℕ) : W.ΨSq n = W.preΨ' n ^ 2 * if Even n then W.Ψ₂Sq else 1 := by
simp only [ΨSq, preΨ_ofNat, Int.even_coe_nat]
@[simp]
lemma ΨSq_zero : W.ΨSq 0 = 0 := by
rw [← Nat.cast_zero, ΨSq_ofNat, preΨ'_zero, zero_pow two_ne_zero, zero_mul]
@[simp]
lemma ΨSq_one : W.ΨSq 1 = 1 := by
rw [← Nat.cast_one, ΨSq_ofNat, preΨ'_one, one_pow, one_mul, if_neg Nat.not_even_one]
@[simp]
lemma ΨSq_two : W.ΨSq 2 = W.Ψ₂Sq := by
rw [← Nat.cast_two, ΨSq_ofNat, preΨ'_two, one_pow, one_mul, if_pos even_two]
@[simp]
lemma ΨSq_three : W.ΨSq 3 = W.Ψ₃ ^ 2 := by
rw [← Nat.cast_three, ΨSq_ofNat, preΨ'_three, if_neg <| by decide, mul_one]
@[simp]
lemma ΨSq_four : W.ΨSq 4 = W.preΨ₄ ^ 2 * W.Ψ₂Sq := by
rw [← Nat.cast_four, ΨSq_ofNat, preΨ'_four, if_pos <| by decide]
lemma ΨSq_even_ofNat (m : ℕ) : W.ΨSq (2 * (m + 3)) =
(W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2) ^ 2 * W.Ψ₂Sq := by
rw_mod_cast [ΨSq_ofNat, preΨ'_even, if_pos <| even_two_mul _]
lemma ΨSq_odd_ofNat (m : ℕ) : W.ΨSq (2 * (m + 2) + 1) =
(W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by
rw_mod_cast [ΨSq_ofNat, preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, mul_one]
@[simp]
lemma ΨSq_neg (n : ℤ) : W.ΨSq (-n) = W.ΨSq n := by
simp only [ΨSq, preΨ_neg, neg_sq, even_neg]
lemma ΨSq_even (m : ℤ) : W.ΨSq (2 * m) =
(W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) -
W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2) ^ 2 * W.Ψ₂Sq := by
rw [ΨSq, preΨ_even, if_pos <| even_two_mul _]
lemma ΨSq_odd (m : ℤ) : W.ΨSq (2 * m + 1) =
(W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by
rw [ΨSq, preΨ_odd, if_neg m.not_even_two_mul_add_one, mul_one]
end ΨSq
section Ψ
/-! ### The bivariate polynomials `Ψₙ` -/
/-- The bivariate polynomials `Ψₙ` congruent to the `n`-division polynomials `ψₙ`. -/
protected noncomputable def Ψ (n : ℤ) : R[X][Y] :=
C (W.preΨ n) * if Even n then W.ψ₂ else 1
open WeierstrassCurve (Ψ)
@[simp]
lemma Ψ_ofNat (n : ℕ) : W.Ψ n = C (W.preΨ' n) * if Even n then W.ψ₂ else 1 := by
simp only [Ψ, preΨ_ofNat, Int.even_coe_nat]
@[simp]
lemma Ψ_zero : W.Ψ 0 = 0 := by
rw [← Nat.cast_zero, Ψ_ofNat, preΨ'_zero, C_0, zero_mul]
@[simp]
lemma Ψ_one : W.Ψ 1 = 1 := by
rw [← Nat.cast_one, Ψ_ofNat, preΨ'_one, C_1, if_neg Nat.not_even_one, mul_one]
@[simp]
lemma Ψ_two : W.Ψ 2 = W.ψ₂ := by
rw [← Nat.cast_two, Ψ_ofNat, preΨ'_two, C_1, one_mul, if_pos even_two]
@[simp]
lemma Ψ_three : W.Ψ 3 = C W.Ψ₃ := by
rw [← Nat.cast_three, Ψ_ofNat, preΨ'_three, if_neg <| by decide, mul_one]
@[simp]
lemma Ψ_four : W.Ψ 4 = C W.preΨ₄ * W.ψ₂ := by
rw [← Nat.cast_four, Ψ_ofNat, preΨ'_four, if_pos <| by decide]
lemma Ψ_even_ofNat (m : ℕ) : W.Ψ (2 * (m + 3)) * W.ψ₂ =
W.Ψ (m + 2) ^ 2 * W.Ψ (m + 3) * W.Ψ (m + 5) - W.Ψ (m + 1) * W.Ψ (m + 3) * W.Ψ (m + 4) ^ 2 := by
repeat rw_mod_cast [Ψ_ofNat]
simp_rw [preΨ'_even, if_pos <| even_two_mul _, Nat.even_add_one, ite_not]
split_ifs <;> C_simp <;> ring1
lemma Ψ_odd_ofNat (m : ℕ) : W.Ψ (2 * (m + 2) + 1) =
W.Ψ (m + 4) * W.Ψ (m + 2) ^ 3 - W.Ψ (m + 1) * W.Ψ (m + 3) ^ 3 +
W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) *
C (if Even m then W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3
else -W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3) := by
repeat rw_mod_cast [Ψ_ofNat]
simp_rw [preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, Nat.even_add_one, ite_not]
split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1
@[simp]
lemma Ψ_neg (n : ℤ) : W.Ψ (-n) = -W.Ψ n := by
simp only [Ψ, preΨ_neg, C_neg, neg_mul (α := R[X][Y]), even_neg]
lemma Ψ_even (m : ℤ) : W.Ψ (2 * m) * W.ψ₂ =
W.Ψ (m - 1) ^ 2 * W.Ψ m * W.Ψ (m + 2) - W.Ψ (m - 2) * W.Ψ m * W.Ψ (m + 1) ^ 2 := by
repeat rw [Ψ]
simp_rw [preΨ_even, if_pos <| even_two_mul _, Int.even_add_one, show m + 2 = m + 1 + 1 by ring1,
Int.even_add_one, show m - 2 = m - 1 - 1 by ring1, Int.even_sub_one, ite_not]
split_ifs <;> C_simp <;> ring1
lemma Ψ_odd (m : ℤ) : W.Ψ (2 * m + 1) =
W.Ψ (m + 2) * W.Ψ m ^ 3 - W.Ψ (m - 1) * W.Ψ (m + 1) ^ 3 +
W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) *
C (if Even m then W.preΨ (m + 2) * W.preΨ m ^ 3
else -W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3) := by
repeat rw [Ψ]
simp_rw [preΨ_odd, if_neg m.not_even_two_mul_add_one, show m + 2 = m + 1 + 1 by ring1,
Int.even_add_one, Int.even_sub_one, ite_not]
split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1
lemma Affine.CoordinateRing.mk_Ψ_sq (n : ℤ) : mk W (W.Ψ n) ^ 2 = mk W (C <| W.ΨSq n) := by
simp only [Ψ, ΨSq, map_one, map_mul, map_pow, one_pow, mul_pow, ite_pow, apply_ite C,
apply_ite <| mk W, mk_ψ₂_sq]
end Ψ
section Φ
/-! ### The univariate polynomials `Φₙ` -/
/-- The univariate polynomials `Φₙ` congruent to `φₙ`. -/
protected noncomputable def Φ (n : ℤ) : R[X] :=
X * W.ΨSq n - W.preΨ (n + 1) * W.preΨ (n - 1) * if Even n then 1 else W.Ψ₂Sq
open WeierstrassCurve (Φ)
@[simp]
lemma Φ_ofNat (n : ℕ) : W.Φ (n + 1) =
X * W.preΨ' (n + 1) ^ 2 * (if Even n then 1 else W.Ψ₂Sq) -
W.preΨ' (n + 2) * W.preΨ' n * (if Even n then W.Ψ₂Sq else 1) := by
rw [Φ, ← Nat.cast_one, ← Nat.cast_add, ΨSq_ofNat, ← mul_assoc, ← Nat.cast_add, preΨ_ofNat,
Nat.cast_add, add_sub_cancel_right, preΨ_ofNat, ← Nat.cast_add]
simp only [Nat.even_add_one, Int.even_add_one, Int.even_coe_nat, ite_not]
@[simp]
lemma Φ_zero : W.Φ 0 = 1 := by
rw [Φ, ΨSq_zero, mul_zero, zero_sub, zero_add, preΨ_one, one_mul, zero_sub, preΨ_neg, preΨ_one,
neg_one_mul, neg_neg, if_pos Even.zero]
@[simp]
lemma Φ_one : W.Φ 1 = X := by
rw [show 1 = ((0 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_one, one_pow, mul_one, if_pos Even.zero,
mul_one, preΨ'_zero, mul_zero, zero_mul, sub_zero]
@[simp]
lemma Φ_two : W.Φ 2 = X ^ 4 - C W.b₄ * X ^ 2 - C (2 * W.b₆) * X - C W.b₈ := by
rw [show 2 = ((1 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_two, if_neg Nat.not_even_one, Ψ₂Sq,
preΨ'_three, preΨ'_one, if_neg Nat.not_even_one, Ψ₃]
C_simp
ring1
@[simp]
lemma Φ_three : W.Φ 3 = X * W.Ψ₃ ^ 2 - W.preΨ₄ * W.Ψ₂Sq := by
rw [show 3 = ((2 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_three, if_pos <| by decide, mul_one,
preΨ'_four, preΨ'_two, mul_one, if_pos even_two]
@[simp]
lemma Φ_four : W.Φ 4 = X * W.preΨ₄ ^ 2 * W.Ψ₂Sq - W.Ψ₃ * (W.preΨ₄ * W.Ψ₂Sq ^ 2 - W.Ψ₃ ^ 3) := by
rw [show 4 = ((3 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_four, if_neg <| by decide,
show 3 + 2 = 2 * 2 + 1 by rfl, preΨ'_odd, preΨ'_four, preΨ'_two, if_pos Even.zero, preΨ'_one,
preΨ'_three, if_pos Even.zero, if_neg <| by decide]
ring1
@[simp]
lemma Φ_neg (n : ℤ) : W.Φ (-n) = W.Φ n := by
simp only [Φ, ΨSq_neg, neg_add_eq_sub, ← neg_sub n, preΨ_neg, ← neg_add', preΨ_neg, neg_mul_neg,
mul_comm <| W.preΨ <| n - 1, even_neg]
end Φ
section ψ
/-! ### The bivariate polynomials `ψₙ` -/
/-- The bivariate `n`-division polynomials `ψₙ`. -/
protected noncomputable def ψ (n : ℤ) : R[X][Y] :=
normEDS W.ψ₂ (C W.Ψ₃) (C W.preΨ₄) n
open WeierstrassCurve (Ψ ψ)
@[simp]
lemma ψ_zero : W.ψ 0 = 0 :=
normEDS_zero ..
@[simp]
lemma ψ_one : W.ψ 1 = 1 :=
normEDS_one ..
@[simp]
lemma ψ_two : W.ψ 2 = W.ψ₂ :=
normEDS_two ..
@[simp]
lemma ψ_three : W.ψ 3 = C W.Ψ₃ :=
normEDS_three ..
@[simp]
lemma ψ_four : W.ψ 4 = C W.preΨ₄ * W.ψ₂ :=
normEDS_four ..
lemma ψ_even_ofNat (m : ℕ) : W.ψ (2 * (m + 3)) * W.ψ₂ =
W.ψ (m + 2) ^ 2 * W.ψ (m + 3) * W.ψ (m + 5) - W.ψ (m + 1) * W.ψ (m + 3) * W.ψ (m + 4) ^ 2 :=
normEDS_even_ofNat ..
lemma ψ_odd_ofNat (m : ℕ) : W.ψ (2 * (m + 2) + 1) =
W.ψ (m + 4) * W.ψ (m + 2) ^ 3 - W.ψ (m + 1) * W.ψ (m + 3) ^ 3 :=
normEDS_odd_ofNat ..
@[simp]
lemma ψ_neg (n : ℤ) : W.ψ (-n) = -W.ψ n :=
normEDS_neg ..
lemma ψ_even (m : ℤ) : W.ψ (2 * m) * W.ψ₂ =
W.ψ (m - 1) ^ 2 * W.ψ m * W.ψ (m + 2) - W.ψ (m - 2) * W.ψ m * W.ψ (m + 1) ^ 2 :=
normEDS_even ..
lemma ψ_odd (m : ℤ) : W.ψ (2 * m + 1) =
W.ψ (m + 2) * W.ψ m ^ 3 - W.ψ (m - 1) * W.ψ (m + 1) ^ 3 :=
normEDS_odd ..
lemma Affine.CoordinateRing.mk_ψ (n : ℤ) : mk W (W.ψ n) = mk W (W.Ψ n) := by
simp only [ψ, normEDS, Ψ, preΨ, map_mul, map_pow, map_preNormEDS, ← mk_ψ₂_sq, ← pow_mul]
end ψ
section φ
/-! ### The bivariate polynomials `φₙ` -/
/-- The bivariate polynomials `φₙ`. -/
protected noncomputable def φ (n : ℤ) : R[X][Y] :=
C X * W.ψ n ^ 2 - W.ψ (n + 1) * W.ψ (n - 1)
open WeierstrassCurve (Ψ Φ φ)
| @[simp]
lemma φ_zero : W.φ 0 = 1 := by
rw [φ, ψ_zero, zero_pow two_ne_zero, mul_zero, zero_sub, zero_add, ψ_one, one_mul, zero_sub,
| Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean | 502 | 504 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Joël Riou
-/
import Mathlib.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.Shift.Basic
import Mathlib.Data.Set.Subsingleton
import Mathlib.Algebra.Group.Int.Defs
/-!
# The category of graded objects
For any type `β`, a `β`-graded object over some category `C` is just
a function `β → C` into the objects of `C`.
We put the "pointwise" category structure on these, as the non-dependent specialization of
`CategoryTheory.Pi`.
We describe the `comap` functors obtained by precomposing with functions `β → γ`.
As a consequence a fixed element (e.g. `1`) in an additive group `β` provides a shift
functor on `β`-graded objects
When `C` has coproducts we construct the `total` functor `GradedObject β C ⥤ C`,
show that it is faithful, and deduce that when `C` is concrete so is `GradedObject β C`.
A covariant functoriality of `GradedObject β C` with respect to the index set `β` is also
introduced: if `p : I → J` is a map such that `C` has coproducts indexed by `p ⁻¹' {j}`, we
have a functor `map : GradedObject I C ⥤ GradedObject J C`.
-/
namespace CategoryTheory
open Category Limits
universe w v u
/-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`. -/
def GradedObject (β : Type w) (C : Type u) : Type max w u :=
β → C
-- Satisfying the inhabited linter...
instance inhabitedGradedObject (β : Type w) (C : Type u) [Inhabited C] :
Inhabited (GradedObject β C) :=
⟨fun _ => Inhabited.default⟩
-- `s` is here to distinguish type synonyms asking for different shifts
/-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`
with a shift functor given by translation by `s`.
-/
@[nolint unusedArguments]
abbrev GradedObjectWithShift {β : Type w} [AddCommGroup β] (_ : β) (C : Type u) : Type max w u :=
GradedObject β C
namespace GradedObject
variable {C : Type u} [Category.{v} C]
@[simps!]
instance categoryOfGradedObjects (β : Type w) : Category.{max w v} (GradedObject β C) :=
CategoryTheory.pi fun _ => C
@[ext]
lemma hom_ext {β : Type*} {X Y : GradedObject β C} (f g : X ⟶ Y) (h : ∀ x, f x = g x) : f = g := by
funext
apply h
/-- The projection of a graded object to its `i`-th component. -/
@[simps]
def eval {β : Type w} (b : β) : GradedObject β C ⥤ C where
obj X := X b
map f := f b
section
variable {β : Type*} (X Y : GradedObject β C)
/-- Constructor for isomorphisms in `GradedObject` -/
@[simps]
def isoMk (e : ∀ i, X i ≅ Y i) : X ≅ Y where
hom i := (e i).hom
inv i := (e i).inv
variable {X Y}
-- this lemma is not an instance as it may create a loop with `isIso_apply_of_isIso`
lemma isIso_of_isIso_apply (f : X ⟶ Y) [hf : ∀ i, IsIso (f i)] :
IsIso f := by
change IsIso (isoMk X Y (fun i => asIso (f i))).hom
infer_instance
instance isIso_apply_of_isIso (f : X ⟶ Y) [IsIso f] (i : β) : IsIso (f i) := by
change IsIso ((eval i).map f)
infer_instance
end
end GradedObject
namespace Iso
variable {C D E J : Type*} [Category C] [Category D] [Category E]
{X Y : GradedObject J C}
@[reassoc (attr := simp)]
lemma hom_inv_id_eval (e : X ≅ Y) (j : J) :
e.hom j ≫ e.inv j = 𝟙 _ := by
rw [← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id,
GradedObject.categoryOfGradedObjects_id]
@[reassoc (attr := simp)]
lemma inv_hom_id_eval (e : X ≅ Y) (j : J) :
e.inv j ≫ e.hom j = 𝟙 _ := by
rw [← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id,
GradedObject.categoryOfGradedObjects_id]
@[reassoc (attr := simp)]
lemma map_hom_inv_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) :
F.map (e.hom j) ≫ F.map (e.inv j) = 𝟙 _ := by
rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id,
GradedObject.categoryOfGradedObjects_id, Functor.map_id]
@[reassoc (attr := simp)]
lemma map_inv_hom_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) :
F.map (e.inv j) ≫ F.map (e.hom j) = 𝟙 _ := by
rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id,
GradedObject.categoryOfGradedObjects_id, Functor.map_id]
@[reassoc (attr := simp)]
lemma map_hom_inv_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) :
(F.map (e.hom j)).app Y ≫ (F.map (e.inv j)).app Y = 𝟙 _ := by
rw [← NatTrans.comp_app, ← F.map_comp, hom_inv_id_eval,
Functor.map_id, NatTrans.id_app]
@[reassoc (attr := simp)]
lemma map_inv_hom_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) :
(F.map (e.inv j)).app Y ≫ (F.map (e.hom j)).app Y = 𝟙 _ := by
rw [← NatTrans.comp_app, ← F.map_comp, inv_hom_id_eval,
Functor.map_id, NatTrans.id_app]
end Iso
namespace GradedObject
variable {C : Type u} [Category.{v} C]
section
variable (C)
/-- Pull back an `I`-graded object in `C` to a `J`-graded object along a function `J → I`. -/
abbrev comap {I J : Type*} (h : J → I) : GradedObject I C ⥤ GradedObject J C :=
Pi.comap (fun _ => C) h
@[simp]
theorem eqToHom_proj {I : Type*} {x x' : GradedObject I C} (h : x = x') (i : I) :
(eqToHom h : x ⟶ x') i = eqToHom (funext_iff.mp h i) := by
subst h
rfl
/-- The natural isomorphism comparing between
pulling back along two propositionally equal functions.
-/
@[simps]
def comapEq {β γ : Type w} {f g : β → γ} (h : f = g) : comap C f ≅ comap C g where
hom := { app := fun X b => eqToHom (by dsimp; simp only [h]) }
inv := { app := fun X b => eqToHom (by dsimp; simp only [h]) }
theorem comapEq_symm {β γ : Type w} {f g : β → γ} (h : f = g) :
comapEq C h.symm = (comapEq C h).symm := by aesop_cat
theorem comapEq_trans {β γ : Type w} {f g h : β → γ} (k : f = g) (l : g = h) :
comapEq C (k.trans l) = comapEq C k ≪≫ comapEq C l := by aesop_cat
theorem eqToHom_apply {β : Type w} {X Y : β → C} (h : X = Y) (b : β) :
(eqToHom h : X ⟶ Y) b = eqToHom (by rw [h]) := by
subst h
rfl
/-- The equivalence between β-graded objects and γ-graded objects,
given an equivalence between β and γ.
-/
@[simps]
def comapEquiv {β γ : Type w} (e : β ≃ γ) : GradedObject β C ≌ GradedObject γ C where
functor := comap C (e.symm : γ → β)
inverse := comap C (e : β → γ)
counitIso :=
(Pi.comapComp (fun _ => C) _ _).trans (comapEq C (by ext; simp))
unitIso :=
(comapEq C (by ext; simp)).trans (Pi.comapComp _ _ _).symm
end
instance hasShift {β : Type*} [AddCommGroup β] (s : β) : HasShift (GradedObjectWithShift s C) ℤ :=
hasShiftMk _ _
{ F := fun n => comap C fun b : β => b + n • s
zero := comapEq C (by aesop_cat) ≪≫ Pi.comapId β fun _ => C
add := fun m n => comapEq C (by ext; dsimp; rw [add_comm m n, add_zsmul, add_assoc]) ≪≫
(Pi.comapComp _ _ _).symm }
@[simp]
theorem shiftFunctor_obj_apply {β : Type*} [AddCommGroup β] (s : β) (X : β → C) (t : β) (n : ℤ) :
(shiftFunctor (GradedObjectWithShift s C) n).obj X t = X (t + n • s) :=
rfl
@[simp]
theorem shiftFunctor_map_apply {β : Type*} [AddCommGroup β] (s : β)
{X Y : GradedObjectWithShift s C} (f : X ⟶ Y) (t : β) (n : ℤ) :
(shiftFunctor (GradedObjectWithShift s C) n).map f t = f (t + n • s) :=
rfl
instance [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) :
Zero (X ⟶ Y) := ⟨fun _ => 0⟩
@[simp]
theorem zero_apply [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) (b : β) :
(0 : X ⟶ Y) b = 0 :=
rfl
instance hasZeroMorphisms [HasZeroMorphisms C] (β : Type w) :
HasZeroMorphisms.{max w v} (GradedObject β C) where
section
open ZeroObject
instance hasZeroObject [HasZeroObject C] [HasZeroMorphisms C] (β : Type w) :
HasZeroObject.{max w v} (GradedObject β C) := by
refine ⟨⟨fun _ => 0, fun X => ⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩, fun X =>
⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩⟩⟩ <;> aesop_cat
end
end GradedObject
namespace GradedObject
-- The universes get a little hairy here, so we restrict the universe level for the grading to 0.
-- Since we're typically interested in grading by ℤ or a finite group, this should be okay.
-- If you're grading by things in higher universes, have fun!
variable (β : Type)
variable (C : Type u) [Category.{v} C]
variable [HasCoproducts.{0} C]
section
/-- The total object of a graded object is the coproduct of the graded components.
-/
noncomputable def total : GradedObject β C ⥤ C where
obj X := ∐ fun i : β => X i
map f := Limits.Sigma.map fun i => f i
end
variable [HasZeroMorphisms C]
/--
The `total` functor taking a graded object to the coproduct of its graded components is faithful.
To prove this, we need to know that the coprojections into the coproduct are monomorphisms,
which follows from the fact we have zero morphisms and decidable equality for the grading.
-/
instance : (total β C).Faithful where
map_injective {X Y} f g w := by
ext i
replace w := Sigma.ι (fun i : β => X i) i ≫= w
erw [colimit.ι_map, colimit.ι_map] at w
simp? at * says simp only [Discrete.functor_obj_eq_as, Discrete.natTrans_app] at *
exact Mono.right_cancellation _ _ w
end GradedObject
namespace GradedObject
noncomputable section
variable (β : Type)
variable (C : Type (u + 1)) [LargeCategory C] [HasForget C] [HasCoproducts.{0} C]
[HasZeroMorphisms C]
instance : HasForget (GradedObject β C) where forget := total β C ⋙ forget C
instance : HasForget₂ (GradedObject β C) C where forget₂ := total β C
end
end GradedObject
namespace GradedObject
variable {I J K : Type*} {C : Type*} [Category C]
(X Y Z : GradedObject I C) (φ : X ⟶ Y) (e : X ≅ Y) (ψ : Y ⟶ Z) (p : I → J)
/-- If `X : GradedObject I C` and `p : I → J`, `X.mapObjFun p j` is the family of objects `X i`
for `i : I` such that `p i = j`. -/
abbrev mapObjFun (j : J) (i : p ⁻¹' {j}) : C := X i
variable (j : J)
/-- Given `X : GradedObject I C` and `p : I → J`, `X.HasMap p` is the condition that
for all `j : J`, the coproduct of all `X i` such `p i = j` exists. -/
abbrev HasMap : Prop := ∀ (j : J), HasCoproduct (X.mapObjFun p j)
variable {X Y} in
lemma hasMap_of_iso (e : X ≅ Y) (p: I → J) [HasMap X p] : HasMap Y p := fun j => by
have α : Discrete.functor (X.mapObjFun p j) ≅ Discrete.functor (Y.mapObjFun p j) :=
Discrete.natIso (fun ⟨i, _⟩ => (GradedObject.eval i).mapIso e)
exact hasColimit_of_iso α.symm
section
variable [X.HasMap p] [Y.HasMap p]
/-- Given `X : GradedObject I C` and `p : I → J`, `X.mapObj p` is the graded object by `J`
which in degree `j` consists of the coproduct of the `X i` such that `p i = j`. -/
noncomputable def mapObj : GradedObject J C := fun j => ∐ (X.mapObjFun p j)
/-- The canonical inclusion `X i ⟶ X.mapObj p j` when `i : I` and `j : J` are such
that `p i = j`. -/
noncomputable def ιMapObj (i : I) (j : J) (hij : p i = j) : X i ⟶ X.mapObj p j :=
Sigma.ι (X.mapObjFun p j) ⟨i, hij⟩
/-- Given `X : GradedObject I C`, `p : I → J` and `j : J`,
`CofanMapObjFun X p j` is the type `Cofan (X.mapObjFun p j)`. The point object of
such colimits cofans are isomorphic to `X.mapObj p j`, see `CofanMapObjFun.iso`. -/
abbrev CofanMapObjFun (j : J) : Type _ := Cofan (X.mapObjFun p j)
-- in order to use the cofan API, some definitions below
-- have a `simp` attribute rather than `simps`
/-- Constructor for `CofanMapObjFun X p j`. -/
@[simp]
def CofanMapObjFun.mk (j : J) (pt : C) (ι' : ∀ (i : I) (_ : p i = j), X i ⟶ pt) :
CofanMapObjFun X p j :=
Cofan.mk pt (fun ⟨i, hi⟩ => ι' i hi)
/-- The tautological cofan corresponding to the coproduct decomposition of `X.mapObj p j`. -/
@[simp]
noncomputable def cofanMapObj (j : J) : CofanMapObjFun X p j :=
CofanMapObjFun.mk X p j (X.mapObj p j) (fun i hi => X.ιMapObj p i j hi)
/-- Given `X : GradedObject I C`, `p : I → J` and `j : J`, `X.mapObj p j` satisfies
the universal property of the coproduct of those `X i` such that `p i = j`. -/
noncomputable def isColimitCofanMapObj (j : J) : IsColimit (X.cofanMapObj p j) :=
colimit.isColimit _
@[ext]
lemma mapObj_ext {A : C} {j : J} (f g : X.mapObj p j ⟶ A)
(hfg : ∀ (i : I) (hij : p i = j), X.ιMapObj p i j hij ≫ f = X.ιMapObj p i j hij ≫ g) :
f = g :=
Cofan.IsColimit.hom_ext (X.isColimitCofanMapObj p j) _ _ (fun ⟨i, hij⟩ => hfg i hij)
/-- This is the morphism `X.mapObj p j ⟶ A` constructed from a family of
morphisms `X i ⟶ A` for all `i : I` such that `p i = j`. -/
noncomputable def descMapObj {A : C} {j : J} (φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) :
X.mapObj p j ⟶ A :=
Cofan.IsColimit.desc (X.isColimitCofanMapObj p j) (fun ⟨i, hi⟩ => φ i hi)
@[reassoc (attr := simp)]
lemma ι_descMapObj {A : C} {j : J}
(φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) (i : I) (hi : p i = j) :
X.ιMapObj p i j hi ≫ X.descMapObj p φ = φ i hi := by
apply Cofan.IsColimit.fac
end
namespace CofanMapObjFun
lemma hasMap (c : ∀ j, CofanMapObjFun X p j) (hc : ∀ j, IsColimit (c j)) :
X.HasMap p := fun j => ⟨_, hc j⟩
variable {j X p}
variable [X.HasMap p]
variable {c : CofanMapObjFun X p j} (hc : IsColimit c)
/-- If `c : CofanMapObjFun X p j` is a colimit cofan, this is the induced
isomorphism `c.pt ≅ X.mapObj p j`. -/
noncomputable def iso : c.pt ≅ X.mapObj p j :=
IsColimit.coconePointUniqueUpToIso hc (X.isColimitCofanMapObj p j)
@[reassoc (attr := simp)]
lemma inj_iso_hom (i : I) (hi : p i = j) :
c.inj ⟨i, hi⟩ ≫ (c.iso hc).hom = X.ιMapObj p i j hi := by
apply IsColimit.comp_coconePointUniqueUpToIso_hom
@[reassoc (attr := simp)]
lemma ιMapObj_iso_inv (i : I) (hi : p i = j) :
X.ιMapObj p i j hi ≫ (c.iso hc).inv = c.inj ⟨i, hi⟩ := by
apply IsColimit.comp_coconePointUniqueUpToIso_inv
end CofanMapObjFun
variable {X Y}
variable [X.HasMap p] [Y.HasMap p]
/-- The canonical morphism of `J`-graded objects `X.mapObj p ⟶ Y.mapObj p` induced by
a morphism `X ⟶ Y` of `I`-graded objects and a map `p : I → J`. -/
noncomputable def mapMap : X.mapObj p ⟶ Y.mapObj p := fun j =>
X.descMapObj p (fun i hi => φ i ≫ Y.ιMapObj p i j hi)
@[reassoc (attr := simp)]
lemma ι_mapMap (i : I) (j : J) (hij : p i = j) :
X.ιMapObj p i j hij ≫ mapMap φ p j = φ i ≫ Y.ιMapObj p i j hij := by
simp only [mapMap, ι_descMapObj]
lemma congr_mapMap (φ₁ φ₂ : X ⟶ Y) (h : φ₁ = φ₂) : mapMap φ₁ p = mapMap φ₂ p := by
subst h
rfl
variable (X)
@[simp]
lemma mapMap_id : mapMap (𝟙 X) p = 𝟙 _ := by aesop_cat
variable {X Z}
@[simp, reassoc]
lemma mapMap_comp [Z.HasMap p] : mapMap (φ ≫ ψ) p = mapMap φ p ≫ mapMap ψ p := by aesop_cat
/-- The isomorphism of `J`-graded objects `X.mapObj p ≅ Y.mapObj p` induced by an
isomorphism `X ≅ Y` of graded objects and a map `p : I → J`. -/
@[simps]
noncomputable def mapIso : X.mapObj p ≅ Y.mapObj p where
hom := mapMap e.hom p
inv := mapMap e.inv p
variable (C)
/-- Given a map `p : I → J`, this is the functor `GradedObject I C ⥤ GradedObject J C` which
sends an `I`-object `X` to the graded object `X.mapObj p` which in degree `j : J` is given
by the coproduct of those `X i` such that `p i = j`. -/
@[simps]
noncomputable def map [∀ (j : J), HasColimitsOfShape (Discrete (p ⁻¹' {j})) C] :
GradedObject I C ⥤ GradedObject J C where
| obj X := X.mapObj p
map φ := mapMap φ p
| Mathlib/CategoryTheory/GradedObject.lean | 432 | 433 |
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Control.Basic
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.List.Monad
import Mathlib.Logic.OpClass
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
/-!
# Basic properties of lists
-/
assert_not_exists GroupWithZero
assert_not_exists Lattice
assert_not_exists Prod.swap_eq_iff_eq_swap
assert_not_exists Ring
assert_not_exists Set.range
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
/-- There is only one list of an empty type -/
instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) :=
{ instInhabitedList with
uniq := fun l =>
match l with
| [] => rfl
| a :: _ => isEmptyElim a }
instance : Std.LawfulIdentity (α := List α) Append.append [] where
left_id := nil_append
right_id := append_nil
instance : Std.Associative (α := List α) Append.append where
assoc := append_assoc
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
/-! ### mem -/
theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α]
{a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by
by_cases hab : a = b
· exact Or.inl hab
· exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩))
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
-- The simpNF linter says that the LHS can be simplified via `List.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} :
f a ∈ map f l ↔ a ∈ l :=
⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩
@[simp]
theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α}
(hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l :=
⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩
theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} :
a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff]
/-! ### length -/
alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t
| [], H => absurd H.symm <| succ_ne_zero n
| h :: t, _ => ⟨h, t, rfl⟩
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
constructor
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl
· intros hα l1 l2 hl
induction l1 generalizing l2 <;> cases l2
· rfl
· cases hl
· cases hl
· next ih _ _ =>
congr
· subsingleton
· apply ih; simpa using hl
@[simp default+1] -- Raise priority above `length_injective_iff`.
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
/-! ### set-theoretic notation of lists -/
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_empty_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil }
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by
rw [insert_neg, singleton_eq]
rwa [singleton_eq, mem_singleton]
/-! ### bounded quantifiers over lists -/
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x := (forall_mem_cons.1 h).2
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self, h⟩
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) →
∃ x ∈ a :: l, p x :=
fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) →
p a ∨ ∃ x ∈ l, p x :=
fun ⟨x, xal, px⟩ =>
Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px)
fun h : x ∈ l => Or.inr ⟨x, h, px⟩
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
Iff.intro or_exists_of_exists_mem_cons fun h =>
Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists
/-! ### list subset -/
theorem cons_subset_of_subset_of_mem {a : α} {l m : List α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by
refine ⟨?_, map_subset f⟩; intro h2 x hx
rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
/-! ### replicate -/
theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a
| [] => by simp
| (b :: l) => by simp [eq_replicate_length, replicate_succ]
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
rw [replicate_append_replicate]
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left']
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
theorem replicate_right_inj' {a b : α} : ∀ {n},
replicate n a = replicate n b ↔ n = 0 ∨ a = b
| 0 => by simp
| n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or]
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate (n := ·))
theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
@[simp]
theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.head? = l.head? := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
induction l <;> simp [replicate]
@[simp]
theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.getLast? = l.getLast? := by
rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate,
List.reverse_replicate, head?_flatten_replicate h]
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
/-! ### bind -/
@[simp]
theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f :=
rfl
/-! ### concat -/
/-! ### reverse -/
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
@[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by
simp only [concat_eq_append, reverse_cons, reverse_reverse]
theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) :
map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by
simp only [reverseAux_eq, map_append, map_reverse]
-- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self`
@[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where
mp := l₁.reverse_perm.symm.trans
mpr := l₁.reverse_perm.trans
@[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where
mp hl := hl.trans l₂.reverse_perm
mpr hl := hl.trans l₂.reverse_perm.symm
/-! ### getLast -/
attribute [simp] getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by
simp [getLast_append]
theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by
induction l₁ with
| nil => simp
| cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih
@[deprecated (since := "2025-02-06")]
alias getLast_append' := getLast_append_of_right_ne_nil
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by
simp
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
@[simp]
theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) :
getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) :=
rfl
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [_], _ => rfl
| a :: b :: l, h => by
rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)]
congr
exact dropLast_append_getLast (cons_ne_nil b l)
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
@[deprecated (since := "2025-02-07")]
alias getLast_filter' := getLast_filter_of_pos
/-! ### getLast? -/
theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h
| [], x, hx => False.elim <| by simp at hx
| [a], x, hx =>
have : a = x := by simpa using hx
this ▸ ⟨cons_ne_nil a [], rfl⟩
| a :: b :: l, x, hx => by
rw [getLast?_cons_cons] at hx
rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩
use cons_ne_nil _ _
assumption
theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
| [], h => (h rfl).elim
| [_], _ => rfl
| _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _)
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l
| [], a, ha => (Option.not_mem_none a ha).elim
| [a], _, rfl => rfl
| a :: b :: l, c, hc => by
rw [getLast?_cons_cons] at hc
rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc]
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [_] => rfl
| [_, _] => rfl
| [_, _, _] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], _, _ => rfl
| [_], _, _ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
theorem getLast?_append_of_ne_nil (l₁ : List α) :
∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂
| [], hl₂ => by contradiction
| b :: l₂, _ => getLast?_append_cons l₁ b l₂
theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
/-! ### head(!?) and tail -/
@[simp]
theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl
@[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by
cases x <;> simp at h ⊢
theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) :
l.head hl = l[0]'(length_pos_iff.2 hl) :=
(getElem_zero _).symm
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l
| [], h => (Option.not_mem_none _ h).elim
| a :: l, h => by
simp only [head?, Option.mem_def, Option.some_inj] at h
exact h ▸ rfl
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) :
x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] := by
induction l
· contradiction
· rw [tail, cons_append, tail]
theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l
| [], a, h => by contradiction
| b :: l, a, h => by
simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h
simp [h]
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| _ :: _, _ => rfl
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self
rwa [cons_head!_tail h] at h'
theorem get_eq_getElem? (l : List α) (i : Fin l.length) :
l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by
simp
@[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem?
theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} :
(∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by
simp only [mem_iff_getElem]
exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩
theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} :
(∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by
simp [mem_iff_getElem, @forall_swap α]
theorem get_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by
cases l <;> [cases h; rfl]
/-! ### sublists -/
attribute [refl] List.Sublist.refl
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by
constructor
· rintro (_ | _)
· exact Or.inl ‹_›
· exact Or.inr ⟨rfl, ‹_›⟩
· rintro (h | ⟨rfl, h⟩)
· exact h.cons _
· rwa [cons_sublist_cons]
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
@[deprecated (since := "2025-02-07")]
alias sublist_nil_iff_eq_nil := sublist_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
/-- If the first element of two lists are different, then a sublist relation can be reduced. -/
theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ :=
match h₁, h₂ with
| _, .cons _ h => h
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0
| e => by rw [← e]; exact idxOf_cons_self
@[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq
@[simp]
theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l)
| h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h]
@[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne
theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by
induction l with
| nil => exact iff_of_true rfl not_mem_nil
| cons b l ih =>
simp only [length, mem_cons, idxOf_cons, eq_comm]
rw [cond_eq_if]
split_ifs with h <;> simp at h
· exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm
· simp only [Ne.symm h, false_or]
rw [← ih]
exact succ_inj
@[simp]
theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l :=
idxOf_eq_length_iff.2
@[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem
theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by
induction l with | nil => rfl | cons b l ih => ?_
simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq]
by_cases h : b = a
· rw [if_pos h]; exact Nat.zero_le _
· rw [if_neg h]; exact succ_le_succ ih
@[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length
theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al,
fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩
@[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff
theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by
induction l₁ with
| nil =>
exfalso
exact not_mem_nil h
| cons d₁ t₁ ih =>
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [idxOf_cons_eq _ hh]
rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem
theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by
induction l₁ with
| nil => rw [List.nil_append, List.length, Nat.zero_add]
| cons d₁ t₁ ih =>
rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
@[simp]
theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl
/-- A version of `getElem_map` that can be used for rewriting. -/
theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} :
f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _)
theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) :
l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) :=
(getLast_eq_getElem _).symm
theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) :
(l.drop n).take 1 = [l.get ⟨n, h⟩] := by
rw [drop_eq_getElem_cons h, take, take]
simp
theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) :
l₁ = l₂ := by
apply ext_getElem?
intro n
rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn
· exact h' n hn
· simp_all [Nat.max_le, getElem?_eq_none]
@[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?'
@[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff
theorem ext_get_iff {l₁ l₂ : List α} :
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by
constructor
· rintro rfl
exact ⟨rfl, fun _ _ _ ↦ rfl⟩
· intro ⟨h₁, h₂⟩
exact ext_get h₁ h₂
theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? :=
⟨by rintro rfl _ _; rfl, ext_getElem?'⟩
@[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff'
/-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`,
then the lists are equal. -/
theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) :
l₁ = l₂ :=
ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n
@[simp]
theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length),
l[idxOf a l] = a
| b :: l, h => by
by_cases h' : b = a <;>
simp [h', if_pos, if_false, getElem_idxOf]
@[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf
-- This is incorrectly named and should be `get_idxOf`;
-- this already exists, so will require a deprecation dance.
theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by
simp
@[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get
@[simp]
theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
l[idxOf a l]? = some a := by
rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)]
@[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf
@[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf
@[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf
theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
idxOf x l = idxOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ =
get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by
simp only [h]
simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
@[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by
simp
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp
congr
omega
end deprecated
@[simp]
theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a)[j] = l[j]'(by simpa using hj) := by
rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h,
List.getElem?_eq_getElem]
/-! ### map -/
-- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged
-- `simp` in Core
-- TODO: Upstream the tagging to Core?
attribute [simp] map_const'
theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l :=
.symm <| map_eq_flatMap ..
theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
l.flatMap f = l.flatMap g :=
(congr_arg List.flatten <| map_congr_left h :)
theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.flatMap f :=
infix_of_mem_flatten (mem_map_of_mem h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
/-- A single `List.map` of a composition of functions is equal to
composing a `List.map` with another `List.map`, fully applied.
This is the reverse direction of `List.map_map`.
-/
theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) :=
map_map.symm
/-- Composing a `List.map` with another `List.map` is equal to
a single `List.map` of composed functions.
-/
@[simp]
theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by
ext l; rw [comp_map, Function.comp_apply]
section map_bijectivity
theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) :
LeftInverse (map f) (map g)
| [] => by simp_rw [map_nil]
| x :: xs => by simp_rw [map_cons, h x, h.list_map xs]
nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α}
(h : RightInverse f g) : RightInverse (map f) (map g) :=
h.list_map
nonrec theorem _root_.Function.Involutive.list_map {f : α → α}
(h : Involutive f) : Involutive (map f) :=
Function.LeftInverse.list_map h
@[simp]
theorem map_leftInverse_iff {f : α → β} {g : β → α} :
LeftInverse (map f) (map g) ↔ LeftInverse f g :=
⟨fun h x => by injection h [x], (·.list_map)⟩
@[simp]
theorem map_rightInverse_iff {f : α → β} {g : β → α} :
RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff
@[simp]
theorem map_involutive_iff {f : α → α} :
Involutive (map f) ↔ Involutive f := map_leftInverse_iff
theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) :
Injective (map f)
| [], [], _ => rfl
| x :: xs, y :: ys, hxy => by
injection hxy with hxy hxys
rw [h hxy, h.list_map hxys]
@[simp]
theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by
refine ⟨fun h x y hxy => ?_, (·.list_map)⟩
suffices [x] = [y] by simpa using this
apply h
simp [hxy]
theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) :
Surjective (map f) :=
let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective
@[simp]
theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by
refine ⟨fun h x => ?_, (·.list_map)⟩
let ⟨[y], hxy⟩ := h [x]
exact ⟨_, List.singleton_injective hxy⟩
theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) :=
⟨h.1.list_map, h.2.list_map⟩
@[simp]
theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by
simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff]
end map_bijectivity
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) :
b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h
/-- `eq_nil_or_concat` in simp normal form -/
lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by
simpa using l.eq_nil_or_concat
/-! ### foldl, foldr -/
theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l := by
induction l generalizing a with
| nil => rfl
| cons hd tl ih =>
unfold foldl
rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self]
theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l := by
induction l with | nil => rfl | cons hd tl ih => ?_
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
theorem foldl_concat
(f : β → α → β) (b : β) (x : α) (xs : List α) :
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by
simp only [List.foldl_append, List.foldl]
theorem foldr_concat
(f : α → β → β) (b : β) (x : α) (xs : List α) :
List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by
simp only [List.foldr_append, List.foldr]
theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a
| [] => rfl
| b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l]
theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b
| [] => rfl
| a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a]
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
@[deprecated foldr_cons_nil (since := "2025-02-10")]
theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
simp
theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) :
foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) :=
Eq.symm <| by
revert a b
induction l <;> intros <;> [rfl; simp only [*, foldl]]
theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) :
foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by
revert a
induction l <;> intros <;> [rfl; simp only [*, foldr]]
theorem injective_foldl_comp {l : List (α → α)} {f : α → α}
(hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) :
Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by
induction l generalizing f with
| nil => exact hf
| cons lh lt l_ih =>
apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ mem_cons_self
/-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them:
`l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`.
Assume the designated element `a₂` is present in neither `x₁` nor `z₁`.
We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal
(`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/
lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α}
(notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) :
x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by
constructor
· simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons]
rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ |
⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all
· rintro ⟨rfl, rfl, rfl⟩
rfl
section FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α}
theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] :
∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| _, _, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]
rw [hassoc.assoc]
theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] :
∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm.comm a b
| a, b, c :: l => by
simp only [foldl_cons]
have : RightCommutative f := inferInstance
rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons]
theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] :
∀ a l, foldl f a l = foldr f a l
| _, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc]
rw [foldl_eq_foldr a l]
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
include hf
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| _, _, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| _, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) :
∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| _, _, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op]
/-- Notation for `op a b`. -/
local notation a " ⋆ " b => op a b
/-- Notation for `foldl op a l`. -/
local notation l " <*> " a => foldl op a l
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], _, _ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
variable [hc : Std.Commutative op]
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
variable [LawfulMonad m]
theorem foldrM_eq_foldr (f : α → β → m β) (b l) :
foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*]
theorem foldlM_eq_foldl (f : β → α → m β) (b l) :
List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by
suffices h :
∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
by simp [← h (pure b)]
induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
end FoldlMFoldrM
/-! ### intersperse -/
@[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single
@[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂
/-! ### map for partial functions -/
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
/-! ### filter -/
theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) :
l.length = (l.filter f).length + (l.filter (! f ·)).length := by
simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true,
Bool.decide_eq_false]
/-! ### filterMap -/
theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.flatMap fun a ↦ (f a).toList := by
induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons]
rcases f a <;> simp [ih]
theorem filterMap_congr {f g : α → Option β} {l : List α}
(h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by
induction l <;> simp_all [filterMap_cons]
theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} :
l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where
mp := by
induction l with | nil => simp | cons a l ih => ?_
rcases ha : f a with - | b <;> simp [ha, filterMap_cons]
· intro h
simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff]
using List.length_filterMap_le f l
· rintro rfl h
exact ⟨rfl, ih h⟩
mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _)
/-! ### filter -/
section Filter
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
theorem filter_eq_foldr (p : α → Bool) (l : List α) :
filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by
induction l <;> simp [*, filter]; rfl
#adaptation_note /-- nightly-2024-07-27
This has to be temporarily renamed to avoid an unintentional collision.
The prime should be removed at nightly-2024-07-27. -/
@[simp]
theorem filter_subset' (l : List α) : filter p l ⊆ l :=
filter_sublist.subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset' l h
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
@[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset
variable (p)
theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄
(h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by
induction l with
| nil => rfl
| cons hd tl IH =>
by_cases hp : p hd
· rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)]
exact IH.cons_cons hd
· rw [filter_cons_of_neg hp]
by_cases hq : q hd
· rw [filter_cons_of_pos hq]
exact sublist_cons_of_sublist hd IH
· rw [filter_cons_of_neg hq]
exact IH
lemma map_filter {f : α → β} (hf : Injective f) (l : List α)
[DecidablePred fun b => ∃ a, p a ∧ f a = b] :
(l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [comp_def, filter_map, hf.eq_iff]
@[deprecated (since := "2025-02-07")] alias map_filter' := map_filter
lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] :
l.attach.filter p =
(l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [comp_def, map_filter _ Subtype.coe_injective]
lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) =
(l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← filter_map, attach_map_subtype_val]
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [Bool.and_comm]
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
end Filter
/-! ### eraseP -/
section eraseP
variable {p : α → Bool}
@[simp]
theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) :
(l.eraseP p).length + 1 = l.length := by
let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa
rw [h₂, h₁, length_append, length_append]
rfl
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
@[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) :
(l.erase a).length + 1 = l.length := by
rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)]
theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) :
map f (l.erase a) = (map f l).erase (f a) := by
have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff]
rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl
theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by
induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]]
theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) :
Perm (l.erase l[i]) (l.eraseIdx i) := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
have hi' : i < l.length := by simpa using hi
if ha : a = l[i] then
simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi'))
else
simpa [ha] using IH hi'
theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) :
(l.eraseIdx i).length + 1 = l.length := by
rw [length_eraseIdx]
split <;> omega
end Erase
/-! ### diff -/
section Diff
variable [DecidableEq α]
@[simp]
theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by
simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj]
@[deprecated (since := "2025-04-10")]
alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist
end Diff
section Choose
variable (p : α → Prop) [DecidablePred p] (l : List α)
theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
/-! ### Forall -/
section Forall
variable {p q : α → Prop} {l : List α}
@[simp]
theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l
| [] => (and_iff_left_of_imp fun _ ↦ trivial).symm
| _ :: _ => Iff.rfl
@[simp]
theorem forall_append {p : α → Prop} : ∀ {xs ys : List α},
Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys
| [] => by simp
| _ :: _ => by simp [forall_append, and_assoc]
theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x
| [] => (iff_true_intro <| forall_mem_nil _).symm
| x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem]
theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l
| [] => id
| x :: l => by
simp only [forall_cons, and_imp]
rw [← and_imp]
exact And.imp (h x) (Forall.imp h)
@[simp]
theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by
induction l <;> simp [*]
instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ =>
decidable_of_iff' _ forall_iff_forall_mem
end Forall
/-! ### Miscellaneous lemmas -/
theorem get_attach (l : List α) (i) :
(l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp
section Disjoint
/-- The images of disjoint lists under a partially defined map are disjoint -/
theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α}
(hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a)
(hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a')
(h : Disjoint s t) :
Disjoint (s.pmap f hs) (t.pmap f ht) := by
simp only [Disjoint, mem_pmap]
rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩
apply h ha
rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm]
/-- The images of disjoint lists under an injective map are disjoint -/
theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f)
(h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by
rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)]
exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h
alias Disjoint.map := disjoint_map
theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) :
Disjoint s t := fun _a has hat ↦
h (mem_map_of_mem has) (mem_map_of_mem hat)
theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩
theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l₁ l ↔ Disjoint l₂ l := by
simp_rw [List.disjoint_left, p.mem_iff]
theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l l₁ ↔ Disjoint l l₂ := by
simp_rw [List.disjoint_right, p.mem_iff]
@[simp]
theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_left
@[simp]
theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_right
end Disjoint
section lookup
variable [BEq α] [LawfulBEq α]
lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) :
lookup a (as.map fun x => (x, f x)) = some (f a) := by
induction as with
| nil => exact (not_mem_nil h).elim
| cons a' as ih =>
by_cases ha : a = a'
· simp [ha, lookup_cons]
· simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h)
end lookup
section range'
@[simp]
lemma range'_0 (a b : ℕ) :
range' a b 0 = replicate b a := by
induction b with
| zero => simp
| succ b ih => simp [range'_succ, ih, replicate_succ]
lemma left_le_of_mem_range' {a b s x : ℕ}
(hx : x ∈ List.range' a b s) : a ≤ x := by
obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx
exact le_add_right a (s * i)
end range'
end List
| Mathlib/Data/List/Basic.lean | 2,527 | 2,529 | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.GDelta.Basic
/-!
# Baire spaces
A topological space is called a *Baire space*
if a countable intersection of dense open subsets is dense.
Baire theorems say that all completely metrizable spaces
and all locally compact regular spaces are Baire spaces.
We prove the theorems in `Mathlib/Topology/Baire/CompleteMetrizable`
and `Mathlib/Topology/Baire/LocallyCompactRegular`.
In this file we prove various corollaries of Baire theorems.
The good concept underlying the theorems is that of a Gδ set, i.e., a countable intersection
of open sets. Then Baire theorem can also be formulated as the fact that a countable
intersection of dense Gδ sets is a dense Gδ set. We deduce this version from Baire property.
We also prove the important consequence that, if the space is
covered by a countable union of closed sets, then the union of their interiors is dense.
We also prove that in Baire spaces, the `residual` sets are exactly those containing a dense Gδ set.
-/
noncomputable section
open scoped Topology
open Filter Set TopologicalSpace
variable {X α : Type*} {ι : Sort*}
section BaireTheorem
variable [TopologicalSpace X] [BaireSpace X]
/-- Definition of a Baire space. -/
theorem dense_iInter_of_isOpen_nat {f : ℕ → Set X} (ho : ∀ n, IsOpen (f n))
(hd : ∀ n, Dense (f n)) : Dense (⋂ n, f n) :=
BaireSpace.baire_property f ho hd
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with ⋂₀. -/
theorem dense_sInter_of_isOpen {S : Set (Set X)} (ho : ∀ s ∈ S, IsOpen s) (hS : S.Countable)
(hd : ∀ s ∈ S, Dense s) : Dense (⋂₀ S) := by
rcases S.eq_empty_or_nonempty with h | h
· simp [h]
· rcases hS.exists_eq_range h with ⟨f, rfl⟩
exact dense_iInter_of_isOpen_nat (forall_mem_range.1 ho) (forall_mem_range.1 hd)
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is a countable set in any type. -/
theorem dense_biInter_of_isOpen {S : Set α} {f : α → Set X} (ho : ∀ s ∈ S, IsOpen (f s))
(hS : S.Countable) (hd : ∀ s ∈ S, Dense (f s)) : Dense (⋂ s ∈ S, f s) := by
rw [← sInter_image]
refine dense_sInter_of_isOpen ?_ (hS.image _) ?_ <;> rwa [forall_mem_image]
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is a countable type. -/
theorem dense_iInter_of_isOpen [Countable ι] {f : ι → Set X} (ho : ∀ i, IsOpen (f i))
(hd : ∀ i, Dense (f i)) : Dense (⋂ s, f s) :=
dense_sInter_of_isOpen (forall_mem_range.2 ho) (countable_range _) (forall_mem_range.2 hd)
/-- A set is residual (comeagre) if and only if it includes a dense `Gδ` set. -/
theorem mem_residual {s : Set X} : s ∈ residual X ↔ ∃ t ⊆ s, IsGδ t ∧ Dense t := by
constructor
· rw [mem_residual_iff]
rintro ⟨S, hSo, hSd, Sct, Ss⟩
refine ⟨_, Ss, ⟨_, fun t ht => hSo _ ht, Sct, rfl⟩, ?_⟩
exact dense_sInter_of_isOpen hSo Sct hSd
| rintro ⟨t, ts, ho, hd⟩
exact mem_of_superset (residual_of_dense_Gδ ho hd) ts
/-- A property holds on a residual (comeagre) set if and only if it holds on some dense `Gδ` set. -/
theorem eventually_residual {p : X → Prop} :
(∀ᶠ x in residual X, p x) ↔ ∃ t : Set X, IsGδ t ∧ Dense t ∧ ∀ x ∈ t, p x := by
simp only [Filter.Eventually, mem_residual, subset_def, mem_setOf_eq]
tauto
| Mathlib/Topology/Baire/Lemmas.lean | 74 | 81 |
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang
-/
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.BigOperators.RingEquiv
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Matrix.Mul
import Mathlib.LinearAlgebra.Pi
/-!
# Matrices
This file contains basic results on matrices including bundled versions of matrix operators.
## Implementation notes
For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix
to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the
form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n α)`, as these are not recognized by Lean
as having the right type. Instead, `Matrix.of` should be used.
## TODO
Under various conditions, multiplication of infinite matrices makes sense.
These have not yet been implemented.
-/
assert_not_exists Star
universe u u' v w
variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*}
variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*}
namespace Matrix
instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) :=
Fintype.decidablePiFintype
instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] :
Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α))
instance {n m} [Finite m] [Finite n] (α) [Finite α] :
Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α))
section
variable (R)
/-- This is `Matrix.of` bundled as a linear equivalence. -/
def ofLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] : (m → n → α) ≃ₗ[R] Matrix m n α where
__ := ofAddEquiv
map_smul' _ _ := rfl
@[simp] lemma coe_ofLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] :
⇑(ofLinearEquiv _ : (m → n → α) ≃ₗ[R] Matrix m n α) = of := rfl
@[simp] lemma coe_ofLinearEquiv_symm [Semiring R] [AddCommMonoid α] [Module R α] :
⇑((ofLinearEquiv _).symm : Matrix m n α ≃ₗ[R] (m → n → α)) = of.symm := rfl
end
theorem sum_apply [AddCommMonoid α] (i : m) (j : n) (s : Finset β) (g : β → Matrix m n α) :
(∑ c ∈ s, g c) i j = ∑ c ∈ s, g c i j :=
(congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _)
end Matrix
open Matrix
namespace Matrix
section Diagonal
variable [DecidableEq n]
variable (n α)
/-- `Matrix.diagonal` as an `AddMonoidHom`. -/
@[simps]
def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where
toFun := diagonal
map_zero' := diagonal_zero
map_add' x y := (diagonal_add x y).symm
variable (R)
/-- `Matrix.diagonal` as a `LinearMap`. -/
@[simps]
def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α :=
{ diagonalAddMonoidHom n α with map_smul' := diagonal_smul }
variable {n α R}
section One
variable [Zero α] [One α]
lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) :
0 ≤ (1 : Matrix n n α) i j := by
by_cases hi : i = j
· subst hi
simp
· simp [hi]
lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) :
0 ≤ (1 : Matrix n n α) i :=
zero_le_one_elem i
end One
end Diagonal
section Diag
variable (n α)
/-- `Matrix.diag` as an `AddMonoidHom`. -/
@[simps]
def diagAddMonoidHom [AddZeroClass α] : Matrix n n α →+ n → α where
toFun := diag
map_zero' := diag_zero
map_add' := diag_add
variable (R)
/-- `Matrix.diag` as a `LinearMap`. -/
@[simps]
def diagLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : Matrix n n α →ₗ[R] n → α :=
{ diagAddMonoidHom n α with map_smul' := diag_smul }
variable {n α R}
@[simp]
theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum :=
map_list_sum (diagAddMonoidHom n α) l
@[simp]
theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) :
diag s.sum = (s.map diag).sum :=
map_multiset_sum (diagAddMonoidHom n α) s
@[simp]
theorem diag_sum {ι} [AddCommMonoid α] (s : Finset ι) (f : ι → Matrix n n α) :
diag (∑ i ∈ s, f i) = ∑ i ∈ s, diag (f i) :=
map_sum (diagAddMonoidHom n α) f s
end Diag
open Matrix
section AddCommMonoid
variable [AddCommMonoid α] [Mul α]
end AddCommMonoid
section NonAssocSemiring
variable [NonAssocSemiring α]
variable (α n)
/-- `Matrix.diagonal` as a `RingHom`. -/
@[simps]
def diagonalRingHom [Fintype n] [DecidableEq n] : (n → α) →+* Matrix n n α :=
{ diagonalAddMonoidHom n α with
toFun := diagonal
map_one' := diagonal_one
map_mul' := fun _ _ => (diagonal_mul_diagonal' _ _).symm }
end NonAssocSemiring
section Semiring
variable [Semiring α]
theorem diagonal_pow [Fintype n] [DecidableEq n] (v : n → α) (k : ℕ) :
diagonal v ^ k = diagonal (v ^ k) :=
(map_pow (diagonalRingHom n α) v k).symm
/-- The ring homomorphism `α →+* Matrix n n α`
sending `a` to the diagonal matrix with `a` on the diagonal.
-/
def scalar (n : Type u) [DecidableEq n] [Fintype n] : α →+* Matrix n n α :=
(diagonalRingHom n α).comp <| Pi.constRingHom n α
section Scalar
variable [DecidableEq n] [Fintype n]
@[simp]
theorem scalar_apply (a : α) : scalar n a = diagonal fun _ => a :=
rfl
theorem scalar_inj [Nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s :=
(diagonal_injective.comp Function.const_injective).eq_iff
theorem scalar_commute_iff {r : α} {M : Matrix n n α} :
Commute (scalar n r) M ↔ r • M = MulOpposite.op r • M := by
simp_rw [Commute, SemiconjBy, scalar_apply, ← smul_eq_diagonal_mul, ← op_smul_eq_mul_diagonal]
theorem scalar_commute (r : α) (hr : ∀ r', Commute r r') (M : Matrix n n α) :
Commute (scalar n r) M := scalar_commute_iff.2 <| ext fun _ _ => hr _
end Scalar
end Semiring
section Algebra
variable [Fintype n] [DecidableEq n]
variable [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β]
instance instAlgebra : Algebra R (Matrix n n α) where
algebraMap := (Matrix.scalar n).comp (algebraMap R α)
commutes' _ _ := scalar_commute _ (fun _ => Algebra.commutes _ _) _
smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r]
theorem algebraMap_matrix_apply {r : R} {i j : n} :
algebraMap R (Matrix n n α) r i j = if i = j then algebraMap R α r else 0 := by
dsimp [algebraMap, Algebra.algebraMap, Matrix.scalar]
split_ifs with h <;> simp [h, Matrix.one_apply_ne]
theorem algebraMap_eq_diagonal (r : R) :
algebraMap R (Matrix n n α) r = diagonal (algebraMap R (n → α) r) := rfl
theorem algebraMap_eq_diagonalRingHom :
algebraMap R (Matrix n n α) = (diagonalRingHom n α).comp (algebraMap R _) := rfl
@[simp]
theorem map_algebraMap (r : R) (f : α → β) (hf : f 0 = 0)
(hf₂ : f (algebraMap R α r) = algebraMap R β r) :
(algebraMap R (Matrix n n α) r).map f = algebraMap R (Matrix n n β) r := by
rw [algebraMap_eq_diagonal, algebraMap_eq_diagonal, diagonal_map hf]
simp [hf₂]
variable (R)
/-- `Matrix.diagonal` as an `AlgHom`. -/
@[simps]
def diagonalAlgHom : (n → α) →ₐ[R] Matrix n n α :=
{ diagonalRingHom n α with
toFun := diagonal
commutes' := fun r => (algebraMap_eq_diagonal r).symm }
end Algebra
section AddHom
variable [Add α]
variable (R α) in
/-- Extracting entries from a matrix as an additive homomorphism. -/
@[simps]
def entryAddHom (i : m) (j : n) : AddHom (Matrix m n α) α where
toFun M := M i j
map_add' _ _ := rfl
-- It is necessary to spell out the name of the coercion explicitly on the RHS
-- for unification to succeed
lemma entryAddHom_eq_comp {i : m} {j : n} :
entryAddHom α i j =
((Pi.evalAddHom (fun _ => α) j).comp (Pi.evalAddHom _ i)).comp
(AddHomClass.toAddHom ofAddEquiv.symm) :=
rfl
end AddHom
section AddMonoidHom
variable [AddZeroClass α]
variable (R α) in
/--
Extracting entries from a matrix as an additive monoid homomorphism. Note this cannot be upgraded to
a ring homomorphism, as it does not respect multiplication.
-/
@[simps]
def entryAddMonoidHom (i : m) (j : n) : Matrix m n α →+ α where
toFun M := M i j
map_add' _ _ := rfl
map_zero' := rfl
-- It is necessary to spell out the name of the coercion explicitly on the RHS
-- for unification to succeed
lemma entryAddMonoidHom_eq_comp {i : m} {j : n} :
entryAddMonoidHom α i j =
((Pi.evalAddMonoidHom (fun _ => α) j).comp (Pi.evalAddMonoidHom _ i)).comp
(AddMonoidHomClass.toAddMonoidHom ofAddEquiv.symm) := by
rfl
@[simp] lemma evalAddMonoidHom_comp_diagAddMonoidHom (i : m) :
(Pi.evalAddMonoidHom _ i).comp (diagAddMonoidHom m α) = entryAddMonoidHom α i i := by
simp [AddMonoidHom.ext_iff]
@[simp] lemma entryAddMonoidHom_toAddHom {i : m} {j : n} :
(entryAddMonoidHom α i j : AddHom _ _) = entryAddHom α i j := rfl
end AddMonoidHom
section LinearMap
variable [Semiring R] [AddCommMonoid α] [Module R α]
variable (R α) in
/--
Extracting entries from a matrix as a linear map. Note this cannot be upgraded to an algebra
homomorphism, as it does not respect multiplication.
-/
@[simps]
def entryLinearMap (i : m) (j : n) :
Matrix m n α →ₗ[R] α where
toFun M := M i j
map_add' _ _ := rfl
map_smul' _ _ := rfl
-- It is necessary to spell out the name of the coercion explicitly on the RHS
-- for unification to succeed
lemma entryLinearMap_eq_comp {i : m} {j : n} :
entryLinearMap R α i j =
LinearMap.proj j ∘ₗ LinearMap.proj i ∘ₗ (ofLinearEquiv R).symm.toLinearMap := by
rfl
@[simp] lemma proj_comp_diagLinearMap (i : m) :
LinearMap.proj i ∘ₗ diagLinearMap m R α = entryLinearMap R α i i := by
simp [LinearMap.ext_iff]
@[simp] lemma entryLinearMap_toAddMonoidHom {i : m} {j : n} :
(entryLinearMap R α i j : _ →+ _) = entryAddMonoidHom α i j := rfl
@[simp] lemma entryLinearMap_toAddHom {i : m} {j : n} :
(entryLinearMap R α i j : AddHom _ _) = entryAddHom α i j := rfl
end LinearMap
end Matrix
/-!
### Bundled versions of `Matrix.map`
-/
namespace Equiv
/-- The `Equiv` between spaces of matrices induced by an `Equiv` between their
coefficients. This is `Matrix.map` as an `Equiv`. -/
@[simps apply]
def mapMatrix (f : α ≃ β) : Matrix m n α ≃ Matrix m n β where
toFun M := M.map f
invFun M := M.map f.symm
left_inv _ := Matrix.ext fun _ _ => f.symm_apply_apply _
right_inv _ := Matrix.ext fun _ _ => f.apply_symm_apply _
@[simp]
theorem mapMatrix_refl : (Equiv.refl α).mapMatrix = Equiv.refl (Matrix m n α) :=
rfl
@[simp]
theorem mapMatrix_symm (f : α ≃ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : α ≃ β) (g : β ≃ γ) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ _) :=
rfl
end Equiv
namespace AddMonoidHom
variable [AddZeroClass α] [AddZeroClass β] [AddZeroClass γ]
/-- The `AddMonoidHom` between spaces of matrices induced by an `AddMonoidHom` between their
coefficients. This is `Matrix.map` as an `AddMonoidHom`. -/
@[simps]
def mapMatrix (f : α →+ β) : Matrix m n α →+ Matrix m n β where
toFun M := M.map f
map_zero' := Matrix.map_zero f f.map_zero
map_add' := Matrix.map_add f f.map_add
@[simp]
theorem mapMatrix_id : (AddMonoidHom.id α).mapMatrix = AddMonoidHom.id (Matrix m n α) :=
rfl
@[simp]
theorem mapMatrix_comp (f : β →+ γ) (g : α →+ β) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →+ _) :=
rfl
@[simp] lemma entryAddMonoidHom_comp_mapMatrix (f : α →+ β) (i : m) (j : n) :
(entryAddMonoidHom β i j).comp f.mapMatrix = f.comp (entryAddMonoidHom α i j) := rfl
end AddMonoidHom
namespace AddEquiv
variable [Add α] [Add β] [Add γ]
/-- The `AddEquiv` between spaces of matrices induced by an `AddEquiv` between their
coefficients. This is `Matrix.map` as an `AddEquiv`. -/
@[simps apply]
def mapMatrix (f : α ≃+ β) : Matrix m n α ≃+ Matrix m n β :=
{ f.toEquiv.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm
map_add' := Matrix.map_add f (map_add f) }
@[simp]
theorem mapMatrix_refl : (AddEquiv.refl α).mapMatrix = AddEquiv.refl (Matrix m n α) :=
rfl
@[simp]
theorem mapMatrix_symm (f : α ≃+ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃+ _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : α ≃+ β) (g : β ≃+ γ) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃+ _) :=
rfl
@[simp] lemma entryAddHom_comp_mapMatrix (f : α ≃+ β) (i : m) (j : n) :
(entryAddHom β i j).comp (AddHomClass.toAddHom f.mapMatrix) =
(f : AddHom α β).comp (entryAddHom _ i j) := rfl
end AddEquiv
namespace LinearMap
variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ]
variable [Module R α] [Module R β] [Module R γ]
/-- The `LinearMap` between spaces of matrices induced by a `LinearMap` between their
coefficients. This is `Matrix.map` as a `LinearMap`. -/
@[simps]
def mapMatrix (f : α →ₗ[R] β) : Matrix m n α →ₗ[R] Matrix m n β where
toFun M := M.map f
map_add' := Matrix.map_add f f.map_add
map_smul' r := Matrix.map_smul f r (f.map_smul r)
@[simp]
theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n α →ₗ[R] _) :=
rfl
@[simp]
theorem mapMatrix_comp (f : β →ₗ[R] γ) (g : α →ₗ[R] β) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →ₗ[R] _) :=
rfl
@[simp] lemma entryLinearMap_comp_mapMatrix (f : α →ₗ[R] β) (i : m) (j : n) :
entryLinearMap R _ i j ∘ₗ f.mapMatrix = f ∘ₗ entryLinearMap R _ i j := rfl
end LinearMap
namespace LinearEquiv
variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ]
variable [Module R α] [Module R β] [Module R γ]
/-- The `LinearEquiv` between spaces of matrices induced by a `LinearEquiv` between their
coefficients. This is `Matrix.map` as a `LinearEquiv`. -/
@[simps apply]
def mapMatrix (f : α ≃ₗ[R] β) : Matrix m n α ≃ₗ[R] Matrix m n β :=
{ f.toEquiv.mapMatrix,
f.toLinearMap.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm }
@[simp]
theorem mapMatrix_refl : (LinearEquiv.refl R α).mapMatrix = LinearEquiv.refl R (Matrix m n α) :=
rfl
@[simp]
theorem mapMatrix_symm (f : α ≃ₗ[R] β) :
f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ₗ[R] _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : α ≃ₗ[R] β) (g : β ≃ₗ[R] γ) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ₗ[R] _) :=
rfl
@[simp] lemma mapMatrix_toLinearMap (f : α ≃ₗ[R] β) :
(f.mapMatrix : _ ≃ₗ[R] Matrix m n β).toLinearMap = f.toLinearMap.mapMatrix := by
rfl
@[simp] lemma entryLinearMap_comp_mapMatrix (f : α ≃ₗ[R] β) (i : m) (j : n) :
entryLinearMap R _ i j ∘ₗ f.mapMatrix.toLinearMap =
f.toLinearMap ∘ₗ entryLinearMap R _ i j := by
simp only [mapMatrix_toLinearMap, LinearMap.entryLinearMap_comp_mapMatrix]
end LinearEquiv
namespace RingHom
variable [Fintype m] [DecidableEq m]
variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ]
/-- The `RingHom` between spaces of square matrices induced by a `RingHom` between their
coefficients. This is `Matrix.map` as a `RingHom`. -/
@[simps]
def mapMatrix (f : α →+* β) : Matrix m m α →+* Matrix m m β :=
{ f.toAddMonoidHom.mapMatrix with
toFun := fun M => M.map f
map_one' := by simp
map_mul' := fun _ _ => Matrix.map_mul }
@[simp]
theorem mapMatrix_id : (RingHom.id α).mapMatrix = RingHom.id (Matrix m m α) :=
rfl
@[simp]
theorem mapMatrix_comp (f : β →+* γ) (g : α →+* β) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →+* _) :=
rfl
end RingHom
namespace RingEquiv
variable [Fintype m] [DecidableEq m]
variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ]
/-- The `RingEquiv` between spaces of square matrices induced by a `RingEquiv` between their
coefficients. This is `Matrix.map` as a `RingEquiv`. -/
@[simps apply]
def mapMatrix (f : α ≃+* β) : Matrix m m α ≃+* Matrix m m β :=
{ f.toRingHom.mapMatrix,
f.toAddEquiv.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm }
@[simp]
theorem mapMatrix_refl : (RingEquiv.refl α).mapMatrix = RingEquiv.refl (Matrix m m α) :=
rfl
@[simp]
theorem mapMatrix_symm (f : α ≃+* β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃+* _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : α ≃+* β) (g : β ≃+* γ) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃+* _) :=
rfl
open MulOpposite in
/--
For any ring `R`, we have ring isomorphism `Matₙₓₙ(Rᵒᵖ) ≅ (Matₙₓₙ(R))ᵒᵖ` given by transpose.
-/
@[simps apply symm_apply]
def mopMatrix : Matrix m m αᵐᵒᵖ ≃+* (Matrix m m α)ᵐᵒᵖ where
toFun M := op (M.transpose.map unop)
invFun M := M.unop.transpose.map op
left_inv _ := by aesop
right_inv _ := by aesop
map_mul' _ _ := unop_injective <| by ext; simp [transpose, mul_apply]
map_add' _ _ := by aesop
end RingEquiv
namespace AlgHom
variable [Fintype m] [DecidableEq m]
variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ]
variable [Algebra R α] [Algebra R β] [Algebra R γ]
/-- The `AlgHom` between spaces of square matrices induced by an `AlgHom` between their
coefficients. This is `Matrix.map` as an `AlgHom`. -/
@[simps]
def mapMatrix (f : α →ₐ[R] β) : Matrix m m α →ₐ[R] Matrix m m β :=
{ f.toRingHom.mapMatrix with
toFun := fun M => M.map f
commutes' := fun r => Matrix.map_algebraMap r f (map_zero _) (f.commutes r) }
@[simp]
theorem mapMatrix_id : (AlgHom.id R α).mapMatrix = AlgHom.id R (Matrix m m α) :=
rfl
@[simp]
theorem mapMatrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →ₐ[R] _) :=
rfl
end AlgHom
namespace AlgEquiv
variable [Fintype m] [DecidableEq m]
variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ]
variable [Algebra R α] [Algebra R β] [Algebra R γ]
/-- The `AlgEquiv` between spaces of square matrices induced by an `AlgEquiv` between their
coefficients. This is `Matrix.map` as an `AlgEquiv`. -/
@[simps apply]
def mapMatrix (f : α ≃ₐ[R] β) : Matrix m m α ≃ₐ[R] Matrix m m β :=
{ f.toAlgHom.mapMatrix,
f.toRingEquiv.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm }
@[simp]
theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m α ≃ₐ[R] _) :=
rfl
@[simp]
theorem mapMatrix_symm (f : α ≃ₐ[R] β) :
f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃ₐ[R] _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃ₐ[R] _) :=
rfl
/-- For any algebra `α` over a ring `R`, we have an `R`-algebra isomorphism
`Matₙₓₙ(αᵒᵖ) ≅ (Matₙₓₙ(R))ᵒᵖ` given by transpose. If `α` is commutative,
we can get rid of the `ᵒᵖ` in the left-hand side, see `Matrix.transposeAlgEquiv`. -/
@[simps!] def mopMatrix : Matrix m m αᵐᵒᵖ ≃ₐ[R] (Matrix m m α)ᵐᵒᵖ where
__ := RingEquiv.mopMatrix
commutes' _ := MulOpposite.unop_injective <| by
ext; simp [algebraMap_matrix_apply, eq_comm, apply_ite MulOpposite.unop]
end AlgEquiv
open Matrix
namespace Matrix
section Transpose
open Matrix
variable (m n α)
/-- `Matrix.transpose` as an `AddEquiv` -/
@[simps apply]
def transposeAddEquiv [Add α] : Matrix m n α ≃+ Matrix n m α where
toFun := transpose
invFun := transpose
left_inv := transpose_transpose
right_inv := transpose_transpose
map_add' := transpose_add
@[simp]
theorem transposeAddEquiv_symm [Add α] : (transposeAddEquiv m n α).symm = transposeAddEquiv n m α :=
rfl
variable {m n α}
theorem transpose_list_sum [AddMonoid α] (l : List (Matrix m n α)) :
l.sumᵀ = (l.map transpose).sum :=
map_list_sum (transposeAddEquiv m n α) l
theorem transpose_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix m n α)) :
s.sumᵀ = (s.map transpose).sum :=
(transposeAddEquiv m n α).toAddMonoidHom.map_multiset_sum s
theorem transpose_sum [AddCommMonoid α] {ι : Type*} (s : Finset ι) (M : ι → Matrix m n α) :
(∑ i ∈ s, M i)ᵀ = ∑ i ∈ s, (M i)ᵀ :=
map_sum (transposeAddEquiv m n α) _ s
variable (m n R α)
/-- `Matrix.transpose` as a `LinearMap` -/
@[simps apply]
def transposeLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] :
Matrix m n α ≃ₗ[R] Matrix n m α :=
{ transposeAddEquiv m n α with map_smul' := transpose_smul }
@[simp]
theorem transposeLinearEquiv_symm [Semiring R] [AddCommMonoid α] [Module R α] :
(transposeLinearEquiv m n R α).symm = transposeLinearEquiv n m R α :=
rfl
variable {m n R α}
variable (m α)
/-- `Matrix.transpose` as a `RingEquiv` to the opposite ring -/
@[simps]
def transposeRingEquiv [AddCommMonoid α] [CommSemigroup α] [Fintype m] :
Matrix m m α ≃+* (Matrix m m α)ᵐᵒᵖ :=
{ (transposeAddEquiv m m α).trans MulOpposite.opAddEquiv with
toFun := fun M => MulOpposite.op Mᵀ
invFun := fun M => M.unopᵀ
map_mul' := fun M N =>
(congr_arg MulOpposite.op (transpose_mul M N)).trans (MulOpposite.op_mul _ _)
left_inv := fun M => transpose_transpose M
right_inv := fun M => MulOpposite.unop_injective <| transpose_transpose M.unop }
variable {m α}
@[simp]
theorem transpose_pow [CommSemiring α] [Fintype m] [DecidableEq m] (M : Matrix m m α) (k : ℕ) :
(M ^ k)ᵀ = Mᵀ ^ k :=
MulOpposite.op_injective <| map_pow (transposeRingEquiv m α) M k
theorem transpose_list_prod [CommSemiring α] [Fintype m] [DecidableEq m] (l : List (Matrix m m α)) :
l.prodᵀ = (l.map transpose).reverse.prod :=
(transposeRingEquiv m α).unop_map_list_prod l
variable (R m α)
/-- `Matrix.transpose` as an `AlgEquiv` to the opposite ring -/
@[simps]
def transposeAlgEquiv [CommSemiring R] [CommSemiring α] [Fintype m] [DecidableEq m] [Algebra R α] :
Matrix m m α ≃ₐ[R] (Matrix m m α)ᵐᵒᵖ :=
{ (transposeAddEquiv m m α).trans MulOpposite.opAddEquiv,
transposeRingEquiv m α with
toFun := fun M => MulOpposite.op Mᵀ
commutes' := fun r => by
simp only [algebraMap_eq_diagonal, diagonal_transpose, MulOpposite.algebraMap_apply] }
variable {R m α}
end Transpose
end Matrix
| Mathlib/Data/Matrix/Basic.lean | 2,866 | 2,868 | |
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
-/
import Mathlib.Algebra.BigOperators.Group.Multiset.Basic
import Mathlib.Data.PNat.Prime
import Mathlib.Data.Nat.Factors
import Mathlib.Data.Multiset.OrderedMonoid
import Mathlib.Data.Multiset.Sort
/-!
# Prime factors of nonzero naturals
This file defines the factorization of a nonzero natural number `n` as a multiset of primes,
the multiplicity of `p` in this factors multiset being the p-adic valuation of `n`.
## Main declarations
* `PrimeMultiset`: Type of multisets of prime numbers.
* `FactorMultiset n`: Multiset of prime factors of `n`.
-/
/-- The type of multisets of prime numbers. Unique factorization
gives an equivalence between this set and ℕ+, as we will formalize
below. -/
def PrimeMultiset :=
Multiset Nat.Primes deriving Inhabited, AddCommMonoid, DistribLattice,
SemilatticeSup, Sub
-- The `CanonicallyOrderedAdd, OrderBot, OrderedSub` instances should be constructed by a deriving
-- handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : IsOrderedCancelAddMonoid PrimeMultiset :=
inferInstanceAs (IsOrderedCancelAddMonoid (Multiset Nat.Primes))
instance : CanonicallyOrderedAdd PrimeMultiset :=
inferInstanceAs (CanonicallyOrderedAdd (Multiset Nat.Primes))
instance : OrderBot PrimeMultiset :=
inferInstanceAs (OrderBot (Multiset Nat.Primes))
instance : OrderedSub PrimeMultiset :=
inferInstanceAs (OrderedSub (Multiset Nat.Primes))
namespace PrimeMultiset
-- `@[derive]` doesn't work for `meta` instances
unsafe instance : Repr PrimeMultiset := by delta PrimeMultiset; infer_instance
/-- The multiset consisting of a single prime -/
def ofPrime (p : Nat.Primes) : PrimeMultiset :=
({p} : Multiset Nat.Primes)
theorem card_ofPrime (p : Nat.Primes) : Multiset.card (ofPrime p) = 1 :=
rfl
/-- We can forget the primality property and regard a multiset
of primes as just a multiset of positive integers, or a multiset
of natural numbers. In the opposite direction, if we have a
multiset of positive integers or natural numbers, together with
a proof that all the elements are prime, then we can regard it
as a multiset of primes. The next block of results records
obvious properties of these coercions.
-/
def toNatMultiset : PrimeMultiset → Multiset ℕ := fun v => v.map (↑)
instance coeNat : Coe PrimeMultiset (Multiset ℕ) :=
⟨toNatMultiset⟩
/-- `PrimeMultiset.coe`, the coercion from a multiset of primes to a multiset of
naturals, promoted to an `AddMonoidHom`. -/
def coeNatMonoidHom : PrimeMultiset →+ Multiset ℕ :=
Multiset.mapAddMonoidHom (↑)
@[simp]
theorem coe_coeNatMonoidHom : (coeNatMonoidHom : PrimeMultiset → Multiset ℕ) = (↑) :=
rfl
theorem coeNat_injective : Function.Injective ((↑) : PrimeMultiset → Multiset ℕ) :=
Multiset.map_injective Nat.Primes.coe_nat_injective
theorem coeNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset ℕ) = {(p : ℕ)} :=
rfl
theorem coeNat_prime (v : PrimeMultiset) (p : ℕ) (h : p ∈ (v : Multiset ℕ)) : p.Prime := by
rcases Multiset.mem_map.mp h with ⟨⟨_, hp'⟩, ⟨_, h_eq⟩⟩
exact h_eq ▸ hp'
/-- Converts a `PrimeMultiset` to a `Multiset ℕ+`. -/
def toPNatMultiset : PrimeMultiset → Multiset ℕ+ := fun v => v.map (↑)
instance coePNat : Coe PrimeMultiset (Multiset ℕ+) :=
⟨toPNatMultiset⟩
/-- `coePNat`, the coercion from a multiset of primes to a multiset of positive
naturals, regarded as an `AddMonoidHom`. -/
def coePNatMonoidHom : PrimeMultiset →+ Multiset ℕ+ :=
Multiset.mapAddMonoidHom (↑)
@[simp]
theorem coe_coePNatMonoidHom : (coePNatMonoidHom : PrimeMultiset → Multiset ℕ+) = (↑) :=
rfl
theorem coePNat_injective : Function.Injective ((↑) : PrimeMultiset → Multiset ℕ+) :=
Multiset.map_injective Nat.Primes.coe_pnat_injective
theorem coePNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset ℕ+) = {(p : ℕ+)} :=
rfl
theorem coePNat_prime (v : PrimeMultiset) (p : ℕ+) (h : p ∈ (v : Multiset ℕ+)) : p.Prime := by
rcases Multiset.mem_map.mp h with ⟨⟨_, hp'⟩, ⟨_, h_eq⟩⟩
exact h_eq ▸ hp'
instance coeMultisetPNatNat : Coe (Multiset ℕ+) (Multiset ℕ) :=
⟨fun v => v.map (↑)⟩
theorem coePNat_nat (v : PrimeMultiset) : ((v : Multiset ℕ+) : Multiset ℕ) = (v : Multiset ℕ) := by
change (v.map ((↑) : Nat.Primes → ℕ+)).map Subtype.val = v.map Subtype.val
rw [Multiset.map_map]
congr
/-- The product of a `PrimeMultiset`, as a `ℕ+`. -/
def prod (v : PrimeMultiset) : ℕ+ :=
(v : Multiset PNat).prod
theorem coe_prod (v : PrimeMultiset) : (v.prod : ℕ) = (v : Multiset ℕ).prod := by
have h : (v.prod : ℕ) = ((v.map (↑) : Multiset ℕ+).map (↑)).prod :=
PNat.coeMonoidHom.map_multiset_prod v.toPNatMultiset
simpa [Multiset.map_map] using h
theorem prod_ofPrime (p : Nat.Primes) : (ofPrime p).prod = (p : ℕ+) :=
Multiset.prod_singleton _
/-- If a `Multiset ℕ` consists only of primes, it can be recast as a `PrimeMultiset`. -/
def ofNatMultiset (v : Multiset ℕ) (h : ∀ p : ℕ, p ∈ v → p.Prime) : PrimeMultiset :=
@Multiset.pmap ℕ Nat.Primes Nat.Prime (fun p hp => ⟨p, hp⟩) v h
theorem to_ofNatMultiset (v : Multiset ℕ) (h) : (ofNatMultiset v h : Multiset ℕ) = v := by
dsimp [ofNatMultiset, toNatMultiset]
rw [Multiset.map_pmap, Multiset.pmap_eq_map, Multiset.map_id']
theorem prod_ofNatMultiset (v : Multiset ℕ) (h) :
((ofNatMultiset v h).prod : ℕ) = (v.prod : ℕ) := by rw [coe_prod, to_ofNatMultiset]
/-- If a `Multiset ℕ+` consists only of primes, it can be recast as a `PrimeMultiset`. -/
def ofPNatMultiset (v : Multiset ℕ+) (h : ∀ p : ℕ+, p ∈ v → p.Prime) : PrimeMultiset :=
@Multiset.pmap ℕ+ Nat.Primes PNat.Prime (fun p hp => ⟨(p : ℕ), hp⟩) v h
theorem to_ofPNatMultiset (v : Multiset ℕ+) (h) : (ofPNatMultiset v h : Multiset ℕ+) = v := by
dsimp [ofPNatMultiset, toPNatMultiset]
have : (fun (p : ℕ+) (h : p.Prime) => ((↑) : Nat.Primes → ℕ+) ⟨p, h⟩) = fun p _ => id p := by
funext p h
apply Subtype.eq
rfl
rw [Multiset.map_pmap, this, Multiset.pmap_eq_map, Multiset.map_id]
theorem prod_ofPNatMultiset (v : Multiset ℕ+) (h) : ((ofPNatMultiset v h).prod : ℕ+) = v.prod := by
dsimp [prod]
rw [to_ofPNatMultiset]
/-- Lists can be coerced to multisets; here we have some results
about how this interacts with our constructions on multisets. -/
def ofNatList (l : List ℕ) (h : ∀ p : ℕ, p ∈ l → p.Prime) : PrimeMultiset :=
ofNatMultiset (l : Multiset ℕ) h
theorem prod_ofNatList (l : List ℕ) (h) : ((ofNatList l h).prod : ℕ) = l.prod := by
have := prod_ofNatMultiset (l : Multiset ℕ) h
rw [Multiset.prod_coe] at this
exact this
/-- If a `List ℕ+` consists only of primes, it can be recast as a `PrimeMultiset` with
the coercion from lists to multisets. -/
def ofPNatList (l : List ℕ+) (h : ∀ p : ℕ+, p ∈ l → p.Prime) : PrimeMultiset :=
ofPNatMultiset (l : Multiset ℕ+) h
theorem prod_ofPNatList (l : List ℕ+) (h) : (ofPNatList l h).prod = l.prod := by
have := prod_ofPNatMultiset (l : Multiset ℕ+) h
rw [Multiset.prod_coe] at this
exact this
/-- The product map gives a homomorphism from the additive monoid
of multisets to the multiplicative monoid ℕ+. -/
| theorem prod_zero : (0 : PrimeMultiset).prod = 1 := by
exact Multiset.prod_zero
| Mathlib/Data/PNat/Factors.lean | 184 | 186 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Data.Nat.Cast.WithTop
/-!
# `WithBot ℕ`
Lemmas about the type of natural numbers with a bottom element adjoined.
-/
namespace Nat
namespace WithBot
instance : WellFoundedRelation (WithBot ℕ) where
rel := (· < ·)
wf := IsWellFounded.wf
theorem add_eq_zero_iff {n m : WithBot ℕ} : n + m = 0 ↔ n = 0 ∧ m = 0 := by
cases n
· simp [WithBot.bot_add]
| cases m
· simp [WithBot.add_bot]
simp [← WithBot.coe_add, add_eq_zero_iff_of_nonneg]
theorem add_eq_one_iff {n m : WithBot ℕ} : n + m = 1 ↔ n = 0 ∧ m = 1 ∨ n = 1 ∧ m = 0 := by
cases n
| Mathlib/Data/Nat/WithBot.lean | 28 | 33 |
/-
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 Aesop
import Mathlib.Order.BoundedOrder.Lattice
/-!
# Disjointness and complements
This file defines `Disjoint`, `Codisjoint`, and the `IsCompl` predicate.
## Main declarations
* `Disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element.
* `Codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element.
* `IsCompl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a
non distributive lattice, an element can have several complements.
* `ComplementedLattice α`: Typeclass stating that any element of a lattice has a complement.
-/
open Function
variable {α : Type*}
section Disjoint
section PartialOrderBot
variable [PartialOrder α] [OrderBot α] {a b c d : α}
/-- Two elements of a lattice are disjoint if their inf is the bottom element.
(This generalizes disjoint sets, viewed as members of the subset lattice.)
Note that we define this without reference to `⊓`, as this allows us to talk about orders where
the infimum is not unique, or where implementing `Inf` would require additional `Decidable`
arguments. -/
def Disjoint (a b : α) : Prop :=
∀ ⦃x⦄, x ≤ a → x ≤ b → x ≤ ⊥
@[simp]
theorem disjoint_of_subsingleton [Subsingleton α] : Disjoint a b :=
fun x _ _ ↦ le_of_eq (Subsingleton.elim x ⊥)
theorem disjoint_comm : Disjoint a b ↔ Disjoint b a :=
forall_congr' fun _ ↦ forall_swap
@[symm]
theorem Disjoint.symm ⦃a b : α⦄ : Disjoint a b → Disjoint b a :=
disjoint_comm.1
theorem symmetric_disjoint : Symmetric (Disjoint : α → α → Prop) :=
Disjoint.symm
@[simp]
theorem disjoint_bot_left : Disjoint ⊥ a := fun _ hbot _ ↦ hbot
@[simp]
theorem disjoint_bot_right : Disjoint a ⊥ := fun _ _ hbot ↦ hbot
theorem Disjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Disjoint b d → Disjoint a c :=
fun h _ ha hc ↦ h (ha.trans h₁) (hc.trans h₂)
theorem Disjoint.mono_left (h : a ≤ b) : Disjoint b c → Disjoint a c :=
Disjoint.mono h le_rfl
theorem Disjoint.mono_right : b ≤ c → Disjoint a c → Disjoint a b :=
Disjoint.mono le_rfl
@[simp]
theorem disjoint_self : Disjoint a a ↔ a = ⊥ :=
⟨fun hd ↦ bot_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ ha.trans_eq h⟩
/- TODO: Rename `Disjoint.eq_bot` to `Disjoint.inf_eq` and `Disjoint.eq_bot_of_self` to
`Disjoint.eq_bot` -/
alias ⟨Disjoint.eq_bot_of_self, _⟩ := disjoint_self
theorem Disjoint.ne (ha : a ≠ ⊥) (hab : Disjoint a b) : a ≠ b :=
fun h ↦ ha <| disjoint_self.1 <| by rwa [← h] at hab
theorem Disjoint.eq_bot_of_le (hab : Disjoint a b) (h : a ≤ b) : a = ⊥ :=
eq_bot_iff.2 <| hab le_rfl h
theorem Disjoint.eq_bot_of_ge (hab : Disjoint a b) : b ≤ a → b = ⊥ :=
hab.symm.eq_bot_of_le
lemma Disjoint.eq_iff (hab : Disjoint a b) : a = b ↔ a = ⊥ ∧ b = ⊥ := by aesop
lemma Disjoint.ne_iff (hab : Disjoint a b) : a ≠ b ↔ a ≠ ⊥ ∨ b ≠ ⊥ :=
hab.eq_iff.not.trans not_and_or
theorem disjoint_of_le_iff_left_eq_bot (h : a ≤ b) :
Disjoint a b ↔ a = ⊥ :=
⟨fun hd ↦ hd.eq_bot_of_le h, fun h ↦ h ▸ disjoint_bot_left⟩
end PartialOrderBot
section PartialBoundedOrder
variable [PartialOrder α] [BoundedOrder α] {a : α}
@[simp]
theorem disjoint_top : Disjoint a ⊤ ↔ a = ⊥ :=
⟨fun h ↦ bot_unique <| h le_rfl le_top, fun h _ ha _ ↦ ha.trans_eq h⟩
@[simp]
theorem top_disjoint : Disjoint ⊤ a ↔ a = ⊥ :=
⟨fun h ↦ bot_unique <| h le_top le_rfl, fun h _ _ ha ↦ ha.trans_eq h⟩
end PartialBoundedOrder
section SemilatticeInfBot
variable [SemilatticeInf α] [OrderBot α] {a b c : α}
theorem disjoint_iff_inf_le : Disjoint a b ↔ a ⊓ b ≤ ⊥ :=
⟨fun hd ↦ hd inf_le_left inf_le_right, fun h _ ha hb ↦ (le_inf ha hb).trans h⟩
theorem disjoint_iff : Disjoint a b ↔ a ⊓ b = ⊥ :=
disjoint_iff_inf_le.trans le_bot_iff
theorem Disjoint.le_bot : Disjoint a b → a ⊓ b ≤ ⊥ :=
disjoint_iff_inf_le.mp
theorem Disjoint.eq_bot : Disjoint a b → a ⊓ b = ⊥ :=
bot_unique ∘ Disjoint.le_bot
theorem disjoint_assoc : Disjoint (a ⊓ b) c ↔ Disjoint a (b ⊓ c) := by
rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc]
theorem disjoint_left_comm : Disjoint a (b ⊓ c) ↔ Disjoint b (a ⊓ c) := by
simp_rw [disjoint_iff_inf_le, inf_left_comm]
theorem disjoint_right_comm : Disjoint (a ⊓ b) c ↔ Disjoint (a ⊓ c) b := by
simp_rw [disjoint_iff_inf_le, inf_right_comm]
variable (c)
theorem Disjoint.inf_left (h : Disjoint a b) : Disjoint (a ⊓ c) b :=
h.mono_left inf_le_left
theorem Disjoint.inf_left' (h : Disjoint a b) : Disjoint (c ⊓ a) b :=
h.mono_left inf_le_right
theorem Disjoint.inf_right (h : Disjoint a b) : Disjoint a (b ⊓ c) :=
h.mono_right inf_le_left
theorem Disjoint.inf_right' (h : Disjoint a b) : Disjoint a (c ⊓ b) :=
h.mono_right inf_le_right
variable {c}
theorem Disjoint.of_disjoint_inf_of_le (h : Disjoint (a ⊓ b) c) (hle : a ≤ c) : Disjoint a b :=
disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_left_le hle
theorem Disjoint.of_disjoint_inf_of_le' (h : Disjoint (a ⊓ b) c) (hle : b ≤ c) : Disjoint a b :=
disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_right_le hle
end SemilatticeInfBot
theorem Disjoint.right_lt_sup_of_left_ne_bot [SemilatticeSup α] [OrderBot α] {a b : α}
(h : Disjoint a b) (ha : a ≠ ⊥) : b < a ⊔ b :=
le_sup_right.lt_of_ne fun eq ↦ ha (le_bot_iff.mp <| h le_rfl <| sup_eq_right.mp eq.symm)
section DistribLatticeBot
variable [DistribLattice α] [OrderBot α] {a b c : α}
@[simp]
theorem disjoint_sup_left : Disjoint (a ⊔ b) c ↔ Disjoint a c ∧ Disjoint b c := by
simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff]
@[simp]
theorem disjoint_sup_right : Disjoint a (b ⊔ c) ↔ Disjoint a b ∧ Disjoint a c := by
simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff]
theorem Disjoint.sup_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ⊔ b) c :=
disjoint_sup_left.2 ⟨ha, hb⟩
theorem Disjoint.sup_right (hb : Disjoint a b) (hc : Disjoint a c) : Disjoint a (b ⊔ c) :=
disjoint_sup_right.2 ⟨hb, hc⟩
theorem Disjoint.left_le_of_le_sup_right (h : a ≤ b ⊔ c) (hd : Disjoint a c) : a ≤ b :=
le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) <| sup_le h le_sup_right
theorem Disjoint.left_le_of_le_sup_left (h : a ≤ c ⊔ b) (hd : Disjoint a c) : a ≤ b :=
hd.left_le_of_le_sup_right <| by rwa [sup_comm]
end DistribLatticeBot
end Disjoint
section Codisjoint
section PartialOrderTop
variable [PartialOrder α] [OrderTop α] {a b c d : α}
/-- Two elements of a lattice are codisjoint if their sup is the top element.
Note that we define this without reference to `⊔`, as this allows us to talk about orders where
the supremum is not unique, or where implement `Sup` would require additional `Decidable`
arguments. -/
def Codisjoint (a b : α) : Prop :=
∀ ⦃x⦄, a ≤ x → b ≤ x → ⊤ ≤ x
theorem codisjoint_comm : Codisjoint a b ↔ Codisjoint b a :=
forall_congr' fun _ ↦ forall_swap
@[deprecated (since := "2024-11-23")] alias Codisjoint_comm := codisjoint_comm
@[symm]
theorem Codisjoint.symm ⦃a b : α⦄ : Codisjoint a b → Codisjoint b a :=
codisjoint_comm.1
theorem symmetric_codisjoint : Symmetric (Codisjoint : α → α → Prop) :=
Codisjoint.symm
@[simp]
theorem codisjoint_top_left : Codisjoint ⊤ a := fun _ htop _ ↦ htop
@[simp]
theorem codisjoint_top_right : Codisjoint a ⊤ := fun _ _ htop ↦ htop
theorem Codisjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Codisjoint a c → Codisjoint b d :=
fun h _ ha hc ↦ h (h₁.trans ha) (h₂.trans hc)
theorem Codisjoint.mono_left (h : a ≤ b) : Codisjoint a c → Codisjoint b c :=
Codisjoint.mono h le_rfl
theorem Codisjoint.mono_right : b ≤ c → Codisjoint a b → Codisjoint a c :=
Codisjoint.mono le_rfl
@[simp]
theorem codisjoint_self : Codisjoint a a ↔ a = ⊤ :=
⟨fun hd ↦ top_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ h.symm.trans_le ha⟩
/- TODO: Rename `Codisjoint.eq_top` to `Codisjoint.sup_eq` and `Codisjoint.eq_top_of_self` to
`Codisjoint.eq_top` -/
alias ⟨Codisjoint.eq_top_of_self, _⟩ := codisjoint_self
theorem Codisjoint.ne (ha : a ≠ ⊤) (hab : Codisjoint a b) : a ≠ b :=
fun h ↦ ha <| codisjoint_self.1 <| by rwa [← h] at hab
theorem Codisjoint.eq_top_of_le (hab : Codisjoint a b) (h : b ≤ a) : a = ⊤ :=
eq_top_iff.2 <| hab le_rfl h
theorem Codisjoint.eq_top_of_ge (hab : Codisjoint a b) : a ≤ b → b = ⊤ :=
hab.symm.eq_top_of_le
lemma Codisjoint.eq_iff (hab : Codisjoint a b) : a = b ↔ a = ⊤ ∧ b = ⊤ := by aesop
lemma Codisjoint.ne_iff (hab : Codisjoint a b) : a ≠ b ↔ a ≠ ⊤ ∨ b ≠ ⊤ :=
hab.eq_iff.not.trans not_and_or
end PartialOrderTop
section PartialBoundedOrder
variable [PartialOrder α] [BoundedOrder α] {a b : α}
@[simp]
theorem codisjoint_bot : Codisjoint a ⊥ ↔ a = ⊤ :=
⟨fun h ↦ top_unique <| h le_rfl bot_le, fun h _ ha _ ↦ h.symm.trans_le ha⟩
@[simp]
theorem bot_codisjoint : Codisjoint ⊥ a ↔ a = ⊤ :=
⟨fun h ↦ top_unique <| h bot_le le_rfl, fun h _ _ ha ↦ h.symm.trans_le ha⟩
lemma Codisjoint.ne_bot_of_ne_top (h : Codisjoint a b) (ha : a ≠ ⊤) : b ≠ ⊥ := by
rintro rfl; exact ha <| by simpa using h
lemma Codisjoint.ne_bot_of_ne_top' (h : Codisjoint a b) (hb : b ≠ ⊤) : a ≠ ⊥ := by
rintro rfl; exact hb <| by simpa using h
end PartialBoundedOrder
section SemilatticeSupTop
variable [SemilatticeSup α] [OrderTop α] {a b c : α}
theorem codisjoint_iff_le_sup : Codisjoint a b ↔ ⊤ ≤ a ⊔ b :=
@disjoint_iff_inf_le αᵒᵈ _ _ _ _
theorem codisjoint_iff : Codisjoint a b ↔ a ⊔ b = ⊤ :=
@disjoint_iff αᵒᵈ _ _ _ _
theorem Codisjoint.top_le : Codisjoint a b → ⊤ ≤ a ⊔ b :=
@Disjoint.le_bot αᵒᵈ _ _ _ _
theorem Codisjoint.eq_top : Codisjoint a b → a ⊔ b = ⊤ :=
@Disjoint.eq_bot αᵒᵈ _ _ _ _
theorem codisjoint_assoc : Codisjoint (a ⊔ b) c ↔ Codisjoint a (b ⊔ c) :=
@disjoint_assoc αᵒᵈ _ _ _ _ _
theorem codisjoint_left_comm : Codisjoint a (b ⊔ c) ↔ Codisjoint b (a ⊔ c) :=
@disjoint_left_comm αᵒᵈ _ _ _ _ _
theorem codisjoint_right_comm : Codisjoint (a ⊔ b) c ↔ Codisjoint (a ⊔ c) b :=
@disjoint_right_comm αᵒᵈ _ _ _ _ _
variable (c)
theorem Codisjoint.sup_left (h : Codisjoint a b) : Codisjoint (a ⊔ c) b :=
h.mono_left le_sup_left
theorem Codisjoint.sup_left' (h : Codisjoint a b) : Codisjoint (c ⊔ a) b :=
h.mono_left le_sup_right
theorem Codisjoint.sup_right (h : Codisjoint a b) : Codisjoint a (b ⊔ c) :=
h.mono_right le_sup_left
theorem Codisjoint.sup_right' (h : Codisjoint a b) : Codisjoint a (c ⊔ b) :=
h.mono_right le_sup_right
variable {c}
theorem Codisjoint.of_codisjoint_sup_of_le (h : Codisjoint (a ⊔ b) c) (hle : c ≤ a) :
Codisjoint a b :=
@Disjoint.of_disjoint_inf_of_le αᵒᵈ _ _ _ _ _ h hle
theorem Codisjoint.of_codisjoint_sup_of_le' (h : Codisjoint (a ⊔ b) c) (hle : c ≤ b) :
Codisjoint a b :=
@Disjoint.of_disjoint_inf_of_le' αᵒᵈ _ _ _ _ _ h hle
end SemilatticeSupTop
section DistribLatticeTop
variable [DistribLattice α] [OrderTop α] {a b c : α}
@[simp]
theorem codisjoint_inf_left : Codisjoint (a ⊓ b) c ↔ Codisjoint a c ∧ Codisjoint b c := by
simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff]
@[simp]
theorem codisjoint_inf_right : Codisjoint a (b ⊓ c) ↔ Codisjoint a b ∧ Codisjoint a c := by
simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff]
theorem Codisjoint.inf_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⊓ b) c :=
codisjoint_inf_left.2 ⟨ha, hb⟩
theorem Codisjoint.inf_right (hb : Codisjoint a b) (hc : Codisjoint a c) : Codisjoint a (b ⊓ c) :=
codisjoint_inf_right.2 ⟨hb, hc⟩
theorem Codisjoint.left_le_of_le_inf_right (h : a ⊓ b ≤ c) (hd : Codisjoint b c) : a ≤ c :=
@Disjoint.left_le_of_le_sup_right αᵒᵈ _ _ _ _ _ h hd.symm
theorem Codisjoint.left_le_of_le_inf_left (h : b ⊓ a ≤ c) (hd : Codisjoint b c) : a ≤ c :=
hd.left_le_of_le_inf_right <| by rwa [inf_comm]
end DistribLatticeTop
end Codisjoint
open OrderDual
theorem Disjoint.dual [PartialOrder α] [OrderBot α] {a b : α} :
Disjoint a b → Codisjoint (toDual a) (toDual b) :=
id
theorem Codisjoint.dual [PartialOrder α] [OrderTop α] {a b : α} :
Codisjoint a b → Disjoint (toDual a) (toDual b) :=
id
@[simp]
theorem disjoint_toDual_iff [PartialOrder α] [OrderTop α] {a b : α} :
Disjoint (toDual a) (toDual b) ↔ Codisjoint a b :=
Iff.rfl
@[simp]
theorem disjoint_ofDual_iff [PartialOrder α] [OrderBot α] {a b : αᵒᵈ} :
Disjoint (ofDual a) (ofDual b) ↔ Codisjoint a b :=
Iff.rfl
@[simp]
theorem codisjoint_toDual_iff [PartialOrder α] [OrderBot α] {a b : α} :
Codisjoint (toDual a) (toDual b) ↔ Disjoint a b :=
Iff.rfl
@[simp]
theorem codisjoint_ofDual_iff [PartialOrder α] [OrderTop α] {a b : αᵒᵈ} :
Codisjoint (ofDual a) (ofDual b) ↔ Disjoint a b :=
Iff.rfl
section DistribLattice
variable [DistribLattice α] [BoundedOrder α] {a b c : α}
theorem Disjoint.le_of_codisjoint (hab : Disjoint a b) (hbc : Codisjoint b c) : a ≤ c := by
rw [← @inf_top_eq _ _ _ a, ← @bot_sup_eq _ _ _ c, ← hab.eq_bot, ← hbc.eq_top, sup_inf_right]
exact inf_le_inf_right _ le_sup_left
end DistribLattice
section IsCompl
/-- Two elements `x` and `y` are complements of each other if `x ⊔ y = ⊤` and `x ⊓ y = ⊥`. -/
structure IsCompl [PartialOrder α] [BoundedOrder α] (x y : α) : Prop where
/-- If `x` and `y` are to be complementary in an order, they should be disjoint. -/
protected disjoint : Disjoint x y
/-- If `x` and `y` are to be complementary in an order, they should be codisjoint. -/
protected codisjoint : Codisjoint x y
theorem isCompl_iff [PartialOrder α] [BoundedOrder α] {a b : α} :
IsCompl a b ↔ Disjoint a b ∧ Codisjoint a b :=
⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩
namespace IsCompl
section BoundedPartialOrder
variable [PartialOrder α] [BoundedOrder α] {x y : α}
@[symm]
protected theorem symm (h : IsCompl x y) : IsCompl y x :=
⟨h.1.symm, h.2.symm⟩
lemma _root_.isCompl_comm : IsCompl x y ↔ IsCompl y x := ⟨IsCompl.symm, IsCompl.symm⟩
theorem dual (h : IsCompl x y) : IsCompl (toDual x) (toDual y) :=
⟨h.2, h.1⟩
theorem ofDual {a b : αᵒᵈ} (h : IsCompl a b) : IsCompl (ofDual a) (ofDual b) :=
⟨h.2, h.1⟩
end BoundedPartialOrder
section BoundedLattice
variable [Lattice α] [BoundedOrder α] {x y : α}
theorem of_le (h₁ : x ⊓ y ≤ ⊥) (h₂ : ⊤ ≤ x ⊔ y) : IsCompl x y :=
⟨disjoint_iff_inf_le.mpr h₁, codisjoint_iff_le_sup.mpr h₂⟩
theorem of_eq (h₁ : x ⊓ y = ⊥) (h₂ : x ⊔ y = ⊤) : IsCompl x y :=
⟨disjoint_iff.mpr h₁, codisjoint_iff.mpr h₂⟩
theorem inf_eq_bot (h : IsCompl x y) : x ⊓ y = ⊥ :=
h.disjoint.eq_bot
theorem sup_eq_top (h : IsCompl x y) : x ⊔ y = ⊤ :=
h.codisjoint.eq_top
end BoundedLattice
variable [DistribLattice α] [BoundedOrder α] {a b x y z : α}
theorem inf_left_le_of_le_sup_right (h : IsCompl x y) (hle : a ≤ b ⊔ y) : a ⊓ x ≤ b :=
calc
a ⊓ x ≤ (b ⊔ y) ⊓ x := inf_le_inf hle le_rfl
_ = b ⊓ x ⊔ y ⊓ x := inf_sup_right _ _ _
_ = b ⊓ x := by rw [h.symm.inf_eq_bot, sup_bot_eq]
_ ≤ b := inf_le_left
theorem le_sup_right_iff_inf_left_le {a b} (h : IsCompl x y) : a ≤ b ⊔ y ↔ a ⊓ x ≤ b :=
⟨h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right⟩
theorem inf_left_eq_bot_iff (h : IsCompl y z) : x ⊓ y = ⊥ ↔ x ≤ z := by
rw [← le_bot_iff, ← h.le_sup_right_iff_inf_left_le, bot_sup_eq]
theorem inf_right_eq_bot_iff (h : IsCompl y z) : x ⊓ z = ⊥ ↔ x ≤ y :=
h.symm.inf_left_eq_bot_iff
theorem disjoint_left_iff (h : IsCompl y z) : Disjoint x y ↔ x ≤ z := by
rw [disjoint_iff]
exact h.inf_left_eq_bot_iff
theorem disjoint_right_iff (h : IsCompl y z) : Disjoint x z ↔ x ≤ y :=
h.symm.disjoint_left_iff
theorem le_left_iff (h : IsCompl x y) : z ≤ x ↔ Disjoint z y :=
h.disjoint_right_iff.symm
theorem le_right_iff (h : IsCompl x y) : z ≤ y ↔ Disjoint z x :=
h.symm.le_left_iff
theorem left_le_iff (h : IsCompl x y) : x ≤ z ↔ Codisjoint z y :=
h.dual.le_left_iff
theorem right_le_iff (h : IsCompl x y) : y ≤ z ↔ Codisjoint z x :=
h.symm.left_le_iff
protected theorem Antitone {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') (hx : x ≤ x') : y' ≤ y :=
h'.right_le_iff.2 <| h.symm.codisjoint.mono_right hx
theorem right_unique (hxy : IsCompl x y) (hxz : IsCompl x z) : y = z :=
le_antisymm (hxz.Antitone hxy <| le_refl x) (hxy.Antitone hxz <| le_refl x)
theorem left_unique (hxz : IsCompl x z) (hyz : IsCompl y z) : x = y :=
hxz.symm.right_unique hyz.symm
theorem sup_inf {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊔ x') (y ⊓ y') :=
of_eq
(by rw [inf_sup_right, ← inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm,
h'.inf_eq_bot, inf_bot_eq])
(by rw [sup_inf_left, sup_comm x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq,
sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq])
theorem inf_sup {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊓ x') (y ⊔ y') :=
(h.symm.sup_inf h'.symm).symm
end IsCompl
namespace Prod
variable {β : Type*} [PartialOrder α] [PartialOrder β]
protected theorem disjoint_iff [OrderBot α] [OrderBot β] {x y : α × β} :
Disjoint x y ↔ Disjoint x.1 y.1 ∧ Disjoint x.2 y.2 := by
constructor
· intro h
refine ⟨fun a hx hy ↦ (@h (a, ⊥) ⟨hx, ?_⟩ ⟨hy, ?_⟩).1,
fun b hx hy ↦ (@h (⊥, b) ⟨?_, hx⟩ ⟨?_, hy⟩).2⟩
all_goals exact bot_le
· rintro ⟨ha, hb⟩ z hza hzb
exact ⟨ha hza.1 hzb.1, hb hza.2 hzb.2⟩
protected theorem codisjoint_iff [OrderTop α] [OrderTop β] {x y : α × β} :
Codisjoint x y ↔ Codisjoint x.1 y.1 ∧ Codisjoint x.2 y.2 :=
@Prod.disjoint_iff αᵒᵈ βᵒᵈ _ _ _ _ _ _
protected theorem isCompl_iff [BoundedOrder α] [BoundedOrder β] {x y : α × β} :
IsCompl x y ↔ IsCompl x.1 y.1 ∧ IsCompl x.2 y.2 := by
simp_rw [isCompl_iff, Prod.disjoint_iff, Prod.codisjoint_iff, and_and_and_comm]
end Prod
section
variable [Lattice α] [BoundedOrder α] {a b x : α}
@[simp]
theorem isCompl_toDual_iff : IsCompl (toDual a) (toDual b) ↔ IsCompl a b :=
⟨IsCompl.ofDual, IsCompl.dual⟩
@[simp]
theorem isCompl_ofDual_iff {a b : αᵒᵈ} : IsCompl (ofDual a) (ofDual b) ↔ IsCompl a b :=
⟨IsCompl.dual, IsCompl.ofDual⟩
theorem isCompl_bot_top : IsCompl (⊥ : α) ⊤ :=
IsCompl.of_eq (bot_inf_eq _) (sup_top_eq _)
theorem isCompl_top_bot : IsCompl (⊤ : α) ⊥ :=
IsCompl.of_eq (inf_bot_eq _) (top_sup_eq _)
theorem eq_top_of_isCompl_bot (h : IsCompl x ⊥) : x = ⊤ := by rw [← sup_bot_eq x, h.sup_eq_top]
theorem eq_top_of_bot_isCompl (h : IsCompl ⊥ x) : x = ⊤ :=
eq_top_of_isCompl_bot h.symm
theorem eq_bot_of_isCompl_top (h : IsCompl x ⊤) : x = ⊥ :=
eq_top_of_isCompl_bot h.dual
theorem eq_bot_of_top_isCompl (h : IsCompl ⊤ x) : x = ⊥ :=
eq_top_of_bot_isCompl h.dual
end
section IsComplemented
section Lattice
variable [Lattice α] [BoundedOrder α]
/-- An element is *complemented* if it has a complement. -/
def IsComplemented (a : α) : Prop :=
∃ b, IsCompl a b
theorem isComplemented_bot : IsComplemented (⊥ : α) :=
⟨⊤, isCompl_bot_top⟩
theorem isComplemented_top : IsComplemented (⊤ : α) :=
⟨⊥, isCompl_top_bot⟩
end Lattice
variable [DistribLattice α] [BoundedOrder α] {a b : α}
theorem IsComplemented.sup : IsComplemented a → IsComplemented b → IsComplemented (a ⊔ b) :=
fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊓ b', ha.sup_inf hb⟩
theorem IsComplemented.inf : IsComplemented a → IsComplemented b → IsComplemented (a ⊓ b) :=
fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊔ b', ha.inf_sup hb⟩
end IsComplemented
/-- A complemented bounded lattice is one where every element has a (not necessarily unique)
complement. -/
class ComplementedLattice (α) [Lattice α] [BoundedOrder α] : Prop where
/-- In a `ComplementedLattice`, every element admits a complement. -/
exists_isCompl : ∀ a : α, ∃ b : α, IsCompl a b
lemma complementedLattice_iff (α) [Lattice α] [BoundedOrder α] :
ComplementedLattice α ↔ ∀ a : α, ∃ b : α, IsCompl a b :=
⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩
export ComplementedLattice (exists_isCompl)
instance Subsingleton.instComplementedLattice
[Lattice α] [BoundedOrder α] [Subsingleton α] : ComplementedLattice α := by
refine ⟨fun a ↦ ⟨⊥, disjoint_bot_right, ?_⟩⟩
rw [Subsingleton.elim ⊥ ⊤]
exact codisjoint_top_right
namespace ComplementedLattice
variable [Lattice α] [BoundedOrder α] [ComplementedLattice α]
instance : ComplementedLattice αᵒᵈ :=
⟨fun a ↦
let ⟨b, hb⟩ := exists_isCompl (show α from a)
⟨b, hb.dual⟩⟩
end ComplementedLattice
-- TODO: Define as a sublattice?
| /-- The sublattice of complemented elements. -/
abbrev Complementeds (α : Type*) [Lattice α] [BoundedOrder α] : Type _ :=
{a : α // IsComplemented a}
| Mathlib/Order/Disjoint.lean | 619 | 621 |
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Sites.SheafOfTypes
import Mathlib.Order.Closure
/-!
# Closed sieves
A natural closure operator on sieves is a closure operator on `Sieve X` for each `X` which commutes
with pullback.
We show that a Grothendieck topology `J` induces a natural closure operator, and define what the
closed sieves are. The collection of `J`-closed sieves forms a presheaf which is a sheaf for `J`,
and further this presheaf can be used to determine the Grothendieck topology from the sheaf
predicate.
Finally we show that a natural closure operator on sieves induces a Grothendieck topology, and hence
that natural closure operators are in bijection with Grothendieck topologies.
## Main definitions
* `CategoryTheory.GrothendieckTopology.close`: Sends a sieve `S` on `X` to the set of arrows
which it covers. This has all the usual properties of a closure operator, as well as commuting
with pullback.
* `CategoryTheory.GrothendieckTopology.closureOperator`: The bundled `ClosureOperator` given
by `CategoryTheory.GrothendieckTopology.close`.
* `CategoryTheory.GrothendieckTopology.IsClosed`: A sieve `S` on `X` is closed for the topology `J`
if it contains every arrow it covers.
* `CategoryTheory.Functor.closedSieves`: The presheaf sending `X` to the collection of `J`-closed
sieves on `X`. This is additionally shown to be a sheaf for `J`, and if this is a sheaf for a
different topology `J'`, then `J' ≤ J`.
* `CategoryTheory.topologyOfClosureOperator`: A closure operator on the
set of sieves on every object which commutes with pullback additionally induces a Grothendieck
topology, giving a bijection with `CategoryTheory.GrothendieckTopology.closureOperator`.
## Tags
closed sieve, closure, Grothendieck topology
## References
* [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92]
-/
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
variable (J₁ J₂ : GrothendieckTopology C)
namespace GrothendieckTopology
/-- The `J`-closure of a sieve is the collection of arrows which it covers. -/
@[simps]
def close {X : C} (S : Sieve X) : Sieve X where
arrows _ f := J₁.Covers S f
downward_closed hS := J₁.arrow_stable _ _ hS
/-- Any sieve is smaller than its closure. -/
theorem le_close {X : C} (S : Sieve X) : S ≤ J₁.close S :=
fun _ _ hg => J₁.covering_of_eq_top (S.pullback_eq_top_of_mem hg)
/-- A sieve is closed for the Grothendieck topology if it contains every arrow it covers.
In the case of the usual topology on a topological space, this means that the open cover contains
every open set which it covers.
Note this has no relation to a closed subset of a topological space.
-/
def IsClosed {X : C} (S : Sieve X) : Prop :=
∀ ⦃Y : C⦄ (f : Y ⟶ X), J₁.Covers S f → S f
/-- If `S` is `J₁`-closed, then `S` covers exactly the arrows it contains. -/
theorem covers_iff_mem_of_isClosed {X : C} {S : Sieve X} (h : J₁.IsClosed S) {Y : C} (f : Y ⟶ X) :
J₁.Covers S f ↔ S f :=
⟨h _, J₁.arrow_max _ _⟩
/-- Being `J`-closed is stable under pullback. -/
theorem isClosed_pullback {X Y : C} (f : Y ⟶ X) (S : Sieve X) :
J₁.IsClosed S → J₁.IsClosed (S.pullback f) :=
fun hS Z g hg => hS (g ≫ f) (by rwa [J₁.covers_iff, Sieve.pullback_comp])
/-- The closure of a sieve `S` is the largest closed sieve which contains `S` (justifying the name
"closure").
-/
theorem le_close_of_isClosed {X : C} {S T : Sieve X} (h : S ≤ T) (hT : J₁.IsClosed T) :
J₁.close S ≤ T :=
fun _ f hf => hT _ (J₁.superset_covering (Sieve.pullback_monotone f h) hf)
/-- The closure of a sieve is closed. -/
theorem close_isClosed {X : C} (S : Sieve X) : J₁.IsClosed (J₁.close S) :=
fun _ g hg => J₁.arrow_trans g _ S hg fun _ hS => hS
/-- A Grothendieck topology induces a natural family of closure operators on sieves. -/
@[simps! isClosed]
def closureOperator (X : C) : ClosureOperator (Sieve X) :=
.ofPred J₁.close J₁.IsClosed J₁.le_close J₁.close_isClosed fun _ _ ↦ J₁.le_close_of_isClosed
/-- The sieve `S` is closed iff its closure is equal to itself. -/
theorem isClosed_iff_close_eq_self {X : C} (S : Sieve X) : J₁.IsClosed S ↔ J₁.close S = S :=
(J₁.closureOperator _).isClosed_iff
theorem close_eq_self_of_isClosed {X : C} {S : Sieve X} (hS : J₁.IsClosed S) : J₁.close S = S :=
(J₁.isClosed_iff_close_eq_self S).1 hS
/-- Closing under `J` is stable under pullback. -/
theorem pullback_close {X Y : C} (f : Y ⟶ X) (S : Sieve X) :
J₁.close (S.pullback f) = (J₁.close S).pullback f := by
apply le_antisymm
· refine J₁.le_close_of_isClosed (Sieve.pullback_monotone _ (J₁.le_close S)) ?_
apply J₁.isClosed_pullback _ _ (J₁.close_isClosed _)
· intro Z g hg
change _ ∈ J₁ _
rw [← Sieve.pullback_comp]
apply hg
@[mono]
theorem monotone_close {X : C} : Monotone (J₁.close : Sieve X → Sieve X) :=
(J₁.closureOperator _).monotone
@[simp]
theorem close_close {X : C} (S : Sieve X) : J₁.close (J₁.close S) = J₁.close S :=
(J₁.closureOperator _).idempotent _
/--
The sieve `S` is in the topology iff its closure is the maximal sieve. This shows that the closure
operator determines the topology.
-/
theorem close_eq_top_iff_mem {X : C} (S : Sieve X) : J₁.close S = ⊤ ↔ S ∈ J₁ X := by
constructor
· intro h
apply J₁.transitive (J₁.top_mem X)
intro Y f hf
change J₁.close S f
rwa [h]
· intro hS
rw [eq_top_iff]
intro Y f _
apply J₁.pullback_stable _ hS
end GrothendieckTopology
/--
The presheaf sending each object to the set of `J`-closed sieves on it. This presheaf is a `J`-sheaf
(and will turn out to be a subobject classifier for the category of `J`-sheaves).
| -/
@[simps]
def Functor.closedSieves : Cᵒᵖ ⥤ Type max v u where
obj X := { S : Sieve X.unop // J₁.IsClosed S }
map f S := ⟨S.1.pullback f.unop, J₁.isClosed_pullback f.unop _ S.2⟩
/-- The presheaf of `J`-closed sieves is a `J`-sheaf.
The proof of this is adapted from [MM92], Chapter III, Section 7, Lemma 1.
-/
theorem classifier_isSheaf : Presieve.IsSheaf J₁ (Functor.closedSieves J₁) := by
intro X S hS
| Mathlib/CategoryTheory/Sites/Closed.lean | 149 | 159 |
/-
Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Judith Ludwig, Christian Merten
-/
import Mathlib.Algebra.Exact
import Mathlib.RingTheory.AdicCompletion.Functoriality
import Mathlib.RingTheory.Filtration
/-!
# Exactness of adic completion
In this file we establish exactness properties of adic completions. In particular we show:
## Main results
- `AdicCompletion.map_surjective`: Adic completion preserves surjectivity.
- `AdicCompletion.map_injective`: Adic completion preserves injectivity
of maps between finite modules over a Noetherian ring.
- `AdicCompletion.map_exact`: Over a noetherian ring adic completion is exact on finite
modules.
## Implementation details
All results are proven directly without using Mittag-Leffler systems.
-/
universe u v w t
open LinearMap
namespace AdicCompletion
variable {R : Type u} [CommRing R] {I : Ideal R}
section Surjectivity
variable {M : Type v} [AddCommGroup M] [Module R M]
variable {N : Type w} [AddCommGroup N] [Module R N]
variable {f : M →ₗ[R] N}
/- In each step, a preimage is constructed from the preimage of the previous step by
subtracting this delta. -/
private noncomputable def mapPreimageDelta (hf : Function.Surjective f) (x : AdicCauchySequence I N)
{n : ℕ} {y yₙ : M} (hy : f y = x (n + 1)) (hyₙ : f yₙ = x n) :
{d : (I ^ n • ⊤ : Submodule R M) | f d = f (yₙ - y) } :=
have h : f (yₙ - y) ∈ Submodule.map f (I ^ n • ⊤ : Submodule R M) := by
rw [Submodule.map_smul'', Submodule.map_top, LinearMap.range_eq_top.2 hf,
map_sub, hyₙ, hy, ← Submodule.neg_mem_iff, neg_sub, ← SModEq.sub_mem]
exact AdicCauchySequence.mk_eq_mk (Nat.le_succ n) x
⟨⟨h.choose, h.choose_spec.1⟩, h.choose_spec.2⟩
/- Inductively construct preimage of cauchy sequence. -/
private noncomputable def mapPreimage (hf : Function.Surjective f) (x : AdicCauchySequence I N) :
(n : ℕ) → f ⁻¹' {x n}
| .zero => ⟨(hf (x 0)).choose, (hf (x 0)).choose_spec⟩
| .succ n =>
let y := (hf (x (n + 1))).choose
have hy := (hf (x (n + 1))).choose_spec
let ⟨yₙ, (hyₙ : f yₙ = x n)⟩ := mapPreimage hf x n
let ⟨⟨d, _⟩, (p : f d = f (yₙ - y))⟩ := mapPreimageDelta hf x hy hyₙ
⟨yₙ - d, by simpa [p]⟩
variable (I) in
/-- Adic completion preserves surjectivity -/
theorem map_surjective (hf : Function.Surjective f) : Function.Surjective (map I f) := fun y ↦ by
apply AdicCompletion.induction_on I N y (fun b ↦ ?_)
let a := mapPreimage hf b
refine ⟨AdicCompletion.mk I M (AdicCauchySequence.mk I M (fun n ↦ (a n : M)) ?_), ?_⟩
· refine fun n ↦ SModEq.symm ?_
simp only [SModEq.symm, SModEq, mapPreimage, Submodule.Quotient.mk_sub,
sub_eq_self, Submodule.Quotient.mk_eq_zero, SetLike.coe_mem, a]
· exact _root_.AdicCompletion.ext fun n ↦ congrArg _ ((a n).property)
end Surjectivity
variable {M : Type u} [AddCommGroup M] [Module R M]
variable {N : Type u} [AddCommGroup N] [Module R N]
variable {P : Type u} [AddCommGroup P] [Module R P]
section Injectivity
variable [IsNoetherianRing R] [Module.Finite R N] (I)
open LinearMap
/-- Adic completion preserves injectivity of finite modules over a Noetherian ring. -/
theorem map_injective {f : M →ₗ[R] N} (hf : Function.Injective f) :
Function.Injective (map I f) := by
obtain ⟨k, hk⟩ := Ideal.exists_pow_inf_eq_pow_smul I (range f)
rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot']
intro x
apply AdicCompletion.induction_on I M x (fun a ↦ ?_)
intro hx
refine AdicCompletion.mk_zero_of _ _ _ ⟨42, fun n _ ↦ ⟨n + k, by omega, n, by omega, ?_⟩⟩
rw [← Submodule.comap_map_eq_of_injective hf (I ^ n • ⊤ : Submodule R M),
Submodule.map_smul'', Submodule.map_top]
apply (smul_mono_right _ inf_le_right : I ^ n • (I ^ k • ⊤ ⊓ (range f)) ≤ _)
nth_rw 1 [show n = n + k - k by omega]
rw [← hk (n + k) (show n + k ≥ k by omega)]
exact ⟨by simpa using congrArg (fun x ↦ x.val (n + k)) hx, ⟨a (n + k), rfl⟩⟩
end Injectivity
section
variable [IsNoetherianRing R] [Module.Finite R N]
variable {f : M →ₗ[R] N} {g : N →ₗ[R] P} (hf : Function.Injective f)
(hfg : Function.Exact f g) (hg : Function.Surjective g)
section
variable {k : ℕ}
(hkn : ∀ n ≥ k, I ^ n • ⊤ ⊓ LinearMap.range f = I ^ (n - k) • (I ^ k • ⊤ ⊓ LinearMap.range f))
(x : AdicCauchySequence I N) (hker : ∀ (n : ℕ), g (x n) ∈ (I ^ n • ⊤ : Submodule R P))
/- In each step, a preimage is constructed from the preimage of the previous step by
adding this delta. -/
private noncomputable def mapExactAuxDelta {n : ℕ} {d : N}
(hdmem : d ∈ (I ^ (k + n + 1) • ⊤ : Submodule R N)) {y yₙ : M}
(hd : f y = x (k + n + 1) - d) (hyₙ : f yₙ - x (k + n) ∈ (I ^ (k + n) • ⊤ : Submodule R N)) :
{ d : (I ^ n • ⊤ : Submodule R M)
| f (yₙ + d) - x (k + n + 1) ∈ (I ^ (k + n + 1) • ⊤ : Submodule R N) } :=
have h : f (y - yₙ) ∈ (I ^ (k + n) • ⊤ : Submodule R N) := by
simp only [map_sub, hd]
convert_to x (k + n + 1) - x (k + n) - d - (f yₙ - x (k + n)) ∈ I ^ (k + n) • ⊤
· abel
· refine Submodule.sub_mem _ (Submodule.sub_mem _ ?_ ?_) hyₙ
· rw [← Submodule.Quotient.eq]
exact AdicCauchySequence.mk_eq_mk (by omega) _
· exact (Submodule.smul_mono_left (Ideal.pow_le_pow_right (by omega))) hdmem
have hincl : I ^ (k + n - k) • (I ^ k • ⊤ ⊓ range f) ≤ I ^ (k + n - k) • (range f) :=
smul_mono_right _ inf_le_right
have hyyₙ : y - yₙ ∈ (I ^ n • ⊤ : Submodule R M) := by
convert_to y - yₙ ∈ (I ^ (k + n - k) • ⊤ : Submodule R M)
· simp
· rw [← Submodule.comap_map_eq_of_injective hf (I ^ (k + n - k) • ⊤ : Submodule R M),
Submodule.map_smul'', Submodule.map_top]
apply hincl
rw [← hkn (k + n) (by omega)]
exact ⟨h, ⟨y - yₙ, rfl⟩⟩
⟨⟨y - yₙ, hyyₙ⟩, by simpa [hd, Nat.succ_eq_add_one, Nat.add_assoc]⟩
open Submodule
include hfg in
/-- Inductively construct preimage of cauchy sequence in kernel of `g.adicCompletion I`. -/
private noncomputable def mapExactAux :
(n : ℕ) → { a : M | f a - x (k + n) ∈ (I ^ (k + n) • ⊤ : Submodule R N) }
| .zero =>
let d := (h2 0).choose
let y := (h2 0).choose_spec.choose
have hdy : f y = x (k + 0) - d := (h2 0).choose_spec.choose_spec.right
have hdmem := (h2 0).choose_spec.choose_spec.left
⟨y, by simpa [hdy]⟩
| .succ n =>
let d := (h2 <| n + 1).choose
let y := (h2 <| n + 1).choose_spec.choose
have hdy : f y = x (k + (n + 1)) - d := (h2 <| n + 1).choose_spec.choose_spec.right
have hdmem := (h2 <| n + 1).choose_spec.choose_spec.left
let ⟨yₙ, (hyₙ : f yₙ - x (k + n) ∈ (I ^ (k + n) • ⊤ : Submodule R N))⟩ :=
mapExactAux n
let ⟨d, hd⟩ := mapExactAuxDelta hf hkn x hdmem hdy hyₙ
⟨yₙ + d, hd⟩
where
h1 (n : ℕ) : g (x (k + n)) ∈ Submodule.map g (I ^ (k + n) • ⊤ : Submodule R N) := by
rw [map_smul'', Submodule.map_top, range_eq_top.mpr hg]
exact hker (k + n)
h2 (n : ℕ) : ∃ (d : N) (y : M),
d ∈ (I ^ (k + n) • ⊤ : Submodule R N) ∧ f y = x (k + n) - d := by
obtain ⟨d, hdmem, hd⟩ := h1 n
obtain ⟨y, hdy⟩ := (hfg (x (k + n) - d)).mp (by simp [hd])
exact ⟨d, y, hdmem, hdy⟩
end
include hf hfg hg in
| /-- `AdicCompletion` over a Noetherian ring is exact on finitely generated modules. -/
theorem map_exact : Function.Exact (map I f) (map I g) := by
refine LinearMap.exact_of_comp_eq_zero_of_ker_le_range ?_ (fun y ↦ ?_)
· rw [map_comp, hfg.linearMap_comp_eq_zero, AdicCompletion.map_zero]
· apply AdicCompletion.induction_on I N y (fun b ↦ ?_)
intro hz
obtain ⟨k, hk⟩ := Ideal.exists_pow_inf_eq_pow_smul I (LinearMap.range f)
have hb (n : ℕ) : g (b n) ∈ (I ^ n • ⊤ : Submodule R P) := by
simpa using congrArg (fun x ↦ x.val n) hz
let a := mapExactAux hf hfg hg hk b hb
refine ⟨AdicCompletion.mk I M (AdicCauchySequence.mk I M (fun n ↦ (a n : M)) ?_), ?_⟩
· refine fun n ↦ SModEq.symm ?_
simp [a, mapExactAux, SModEq]
· ext n
suffices h : Submodule.Quotient.mk (p := (I ^ n • ⊤ : Submodule R N)) (f (a n)) =
Submodule.Quotient.mk (p := (I ^ n • ⊤ : Submodule R N)) (b (k + n)) by
simp [h, AdicCauchySequence.mk_eq_mk (show n ≤ k + n by omega)]
rw [Submodule.Quotient.eq]
have hle : (I ^ (k + n) • ⊤ : Submodule R N) ≤ (I ^ n • ⊤ : Submodule R N) :=
Submodule.smul_mono_left (Ideal.pow_le_pow_right (by omega))
| Mathlib/RingTheory/AdicCompletion/Exactness.lean | 181 | 200 |
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SimpleGraph.Path
import Mathlib.Combinatorics.SimpleGraph.Operations
import Mathlib.Data.Finset.Pairwise
import Mathlib.Data.Fintype.Pigeonhole
import Mathlib.Data.Fintype.Powerset
import Mathlib.Data.Nat.Lattice
import Mathlib.SetTheory.Cardinal.Finite
/-!
# Graph cliques
This file defines cliques in simple graphs.
A clique is a set of vertices that are pairwise adjacent.
## Main declarations
* `SimpleGraph.IsClique`: Predicate for a set of vertices to be a clique.
* `SimpleGraph.IsNClique`: Predicate for a set of vertices to be an `n`-clique.
* `SimpleGraph.cliqueFinset`: Finset of `n`-cliques of a graph.
* `SimpleGraph.CliqueFree`: Predicate for a graph to have no `n`-cliques.
-/
open Finset Fintype Function SimpleGraph.Walk
namespace SimpleGraph
variable {α β : Type*} (G H : SimpleGraph α)
/-! ### Cliques -/
section Clique
variable {s t : Set α}
/-- A clique in a graph is a set of vertices that are pairwise adjacent. -/
abbrev IsClique (s : Set α) : Prop :=
s.Pairwise G.Adj
theorem isClique_iff : G.IsClique s ↔ s.Pairwise G.Adj :=
Iff.rfl
/-- A clique is a set of vertices whose induced graph is complete. -/
theorem isClique_iff_induce_eq : G.IsClique s ↔ G.induce s = ⊤ := by
rw [isClique_iff]
constructor
· intro h
ext ⟨v, hv⟩ ⟨w, hw⟩
simp only [comap_adj, Subtype.coe_mk, top_adj, Ne, Subtype.mk_eq_mk]
exact ⟨Adj.ne, h hv hw⟩
· intro h v hv w hw hne
have h2 : (G.induce s).Adj ⟨v, hv⟩ ⟨w, hw⟩ = _ := rfl
conv_lhs at h2 => rw [h]
simp only [top_adj, ne_eq, Subtype.mk.injEq, eq_iff_iff] at h2
exact h2.1 hne
instance [DecidableEq α] [DecidableRel G.Adj] {s : Finset α} : Decidable (G.IsClique s) :=
decidable_of_iff' _ G.isClique_iff
variable {G H} {a b : α}
lemma isClique_empty : G.IsClique ∅ := by simp
lemma isClique_singleton (a : α) : G.IsClique {a} := by simp
theorem IsClique.of_subsingleton {G : SimpleGraph α} (hs : s.Subsingleton) : G.IsClique s :=
hs.pairwise G.Adj
lemma isClique_pair : G.IsClique {a, b} ↔ a ≠ b → G.Adj a b := Set.pairwise_pair_of_symmetric G.symm
@[simp]
lemma isClique_insert : G.IsClique (insert a s) ↔ G.IsClique s ∧ ∀ b ∈ s, a ≠ b → G.Adj a b :=
Set.pairwise_insert_of_symmetric G.symm
lemma isClique_insert_of_not_mem (ha : a ∉ s) :
G.IsClique (insert a s) ↔ G.IsClique s ∧ ∀ b ∈ s, G.Adj a b :=
Set.pairwise_insert_of_symmetric_of_not_mem G.symm ha
lemma IsClique.insert (hs : G.IsClique s) (h : ∀ b ∈ s, a ≠ b → G.Adj a b) :
G.IsClique (insert a s) := hs.insert_of_symmetric G.symm h
theorem IsClique.mono (h : G ≤ H) : G.IsClique s → H.IsClique s := Set.Pairwise.mono' h
theorem IsClique.subset (h : t ⊆ s) : G.IsClique s → G.IsClique t := Set.Pairwise.mono h
@[simp]
theorem isClique_bot_iff : (⊥ : SimpleGraph α).IsClique s ↔ (s : Set α).Subsingleton :=
Set.pairwise_bot_iff
alias ⟨IsClique.subsingleton, _⟩ := isClique_bot_iff
protected theorem IsClique.map (h : G.IsClique s) {f : α ↪ β} : (G.map f).IsClique (f '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ hab
exact ⟨a, b, h ha hb <| ne_of_apply_ne _ hab, rfl, rfl⟩
theorem isClique_map_iff_of_nontrivial {f : α ↪ β} {t : Set β} (ht : t.Nontrivial) :
(G.map f).IsClique t ↔ ∃ (s : Set α), G.IsClique s ∧ f '' s = t := by
refine ⟨fun h ↦ ⟨f ⁻¹' t, ?_, ?_⟩, by rintro ⟨x, hs, rfl⟩; exact hs.map⟩
· rintro x (hx : f x ∈ t) y (hy : f y ∈ t) hne
obtain ⟨u,v, huv, hux, hvy⟩ := h hx hy (by simpa)
rw [EmbeddingLike.apply_eq_iff_eq] at hux hvy
rwa [← hux, ← hvy]
rw [Set.image_preimage_eq_iff]
intro x hxt
obtain ⟨y,hyt, hyne⟩ := ht.exists_ne x
obtain ⟨u,v, -, rfl, rfl⟩ := h hyt hxt hyne
exact Set.mem_range_self _
theorem isClique_map_iff {f : α ↪ β} {t : Set β} :
(G.map f).IsClique t ↔ t.Subsingleton ∨ ∃ (s : Set α), G.IsClique s ∧ f '' s = t := by
obtain (ht | ht) := t.subsingleton_or_nontrivial
· simp [IsClique.of_subsingleton, ht]
simp [isClique_map_iff_of_nontrivial ht, ht.not_subsingleton]
@[simp] theorem isClique_map_image_iff {f : α ↪ β} :
(G.map f).IsClique (f '' s) ↔ G.IsClique s := by
rw [isClique_map_iff, f.injective.subsingleton_image_iff]
obtain (hs | hs) := s.subsingleton_or_nontrivial
· simp [hs, IsClique.of_subsingleton]
simp [or_iff_right hs.not_subsingleton, Set.image_eq_image f.injective]
variable {f : α ↪ β} {t : Finset β}
theorem isClique_map_finset_iff_of_nontrivial (ht : t.Nontrivial) :
(G.map f).IsClique t ↔ ∃ (s : Finset α), G.IsClique s ∧ s.map f = t := by
constructor
· rw [isClique_map_iff_of_nontrivial (by simpa)]
rintro ⟨s, hs, hst⟩
obtain ⟨s, rfl⟩ := Set.Finite.exists_finset_coe <|
(show s.Finite from Set.Finite.of_finite_image (by simp [hst]) f.injective.injOn)
exact ⟨s,hs, Finset.coe_inj.1 (by simpa)⟩
rintro ⟨s, hs, rfl⟩
simpa using hs.map (f := f)
theorem isClique_map_finset_iff :
(G.map f).IsClique t ↔ #t ≤ 1 ∨ ∃ (s : Finset α), G.IsClique s ∧ s.map f = t := by
obtain (ht | ht) := le_or_lt #t 1
· simp only [ht, true_or, iff_true]
exact IsClique.of_subsingleton <| card_le_one.1 ht
rw [isClique_map_finset_iff_of_nontrivial, ← not_lt]
· simp [ht, Finset.map_eq_image]
exact Finset.one_lt_card_iff_nontrivial.mp ht
protected theorem IsClique.finsetMap {f : α ↪ β} {s : Finset α} (h : G.IsClique s) :
(G.map f).IsClique (s.map f) := by
simpa
/-- If a set of vertices `A` is a clique in subgraph of `G` induced by a superset of `A`,
its embedding is a clique in `G`. -/
theorem IsClique.of_induce {S : Subgraph G} {F : Set α} {A : Set F}
(c : (S.induce F).coe.IsClique A) : G.IsClique (Subtype.val '' A) := by
simp only [Set.Pairwise, Set.mem_image, Subtype.exists, exists_and_right, exists_eq_right]
intro _ ⟨_, ainA⟩ _ ⟨_, binA⟩ anb
exact S.adj_sub (c ainA binA (Subtype.coe_ne_coe.mp anb)).2.2
lemma IsClique.sdiff_of_sup_edge {v w : α} {s : Set α} (hc : (G ⊔ edge v w).IsClique s) :
G.IsClique (s \ {v}) := by
intro _ hx _ hy hxy
have := hc hx.1 hy.1 hxy
simp_all [sup_adj, edge_adj]
lemma isClique_sup_edge_of_ne_sdiff {v w : α} {s : Set α} (h : v ≠ w ) (hv : G.IsClique (s \ {v}))
(hw : G.IsClique (s \ {w})) : (G ⊔ edge v w).IsClique s := by
intro x hx y hy hxy
by_cases h' : x ∈ s \ {v} ∧ y ∈ s \ {v} ∨ x ∈ s \ {w} ∧ y ∈ s \ {w}
· obtain (⟨hx, hy⟩ | ⟨hx, hy⟩) := h'
· exact hv.mono le_sup_left hx hy hxy
· exact hw.mono le_sup_left hx hy hxy
· exact Or.inr ⟨by by_cases x = v <;> aesop, hxy⟩
lemma isClique_sup_edge_of_ne_iff {v w : α} {s : Set α} (h : v ≠ w) :
(G ⊔ edge v w).IsClique s ↔ G.IsClique (s \ {v}) ∧ G.IsClique (s \ {w}) :=
⟨fun h' ↦ ⟨h'.sdiff_of_sup_edge, (edge_comm .. ▸ h').sdiff_of_sup_edge⟩,
fun h' ↦ isClique_sup_edge_of_ne_sdiff h h'.1 h'.2⟩
end Clique
/-! ### `n`-cliques -/
section NClique
variable {n : ℕ} {s : Finset α}
/-- An `n`-clique in a graph is a set of `n` vertices which are pairwise connected. -/
structure IsNClique (n : ℕ) (s : Finset α) : Prop where
isClique : G.IsClique s
card_eq : #s = n
theorem isNClique_iff : G.IsNClique n s ↔ G.IsClique s ∧ #s = n :=
⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩
instance [DecidableEq α] [DecidableRel G.Adj] {n : ℕ} {s : Finset α} :
Decidable (G.IsNClique n s) :=
decidable_of_iff' _ G.isNClique_iff
variable {G H} {a b c : α}
@[simp] lemma isNClique_empty : G.IsNClique n ∅ ↔ n = 0 := by simp [isNClique_iff, eq_comm]
@[simp]
lemma isNClique_singleton : G.IsNClique n {a} ↔ n = 1 := by simp [isNClique_iff, eq_comm]
theorem IsNClique.mono (h : G ≤ H) : G.IsNClique n s → H.IsNClique n s := by
simp_rw [isNClique_iff]
exact And.imp_left (IsClique.mono h)
protected theorem IsNClique.map (h : G.IsNClique n s) {f : α ↪ β} :
(G.map f).IsNClique n (s.map f) :=
⟨by rw [coe_map]; exact h.1.map, (card_map _).trans h.2⟩
theorem isNClique_map_iff (hn : 1 < n) {t : Finset β} {f : α ↪ β} :
(G.map f).IsNClique n t ↔ ∃ s : Finset α, G.IsNClique n s ∧ s.map f = t := by
rw [isNClique_iff, isClique_map_finset_iff, or_and_right,
or_iff_right (by rintro ⟨h', rfl⟩; exact h'.not_lt hn)]
constructor
· rintro ⟨⟨s, hs, rfl⟩, rfl⟩
simp [isNClique_iff, hs]
rintro ⟨s, hs, rfl⟩
simp [hs.card_eq, hs.isClique]
@[simp]
theorem isNClique_bot_iff : (⊥ : SimpleGraph α).IsNClique n s ↔ n ≤ 1 ∧ #s = n := by
rw [isNClique_iff, isClique_bot_iff]
refine and_congr_left ?_
rintro rfl
exact card_le_one.symm
@[simp]
theorem isNClique_zero : G.IsNClique 0 s ↔ s = ∅ := by
simp only [isNClique_iff, Finset.card_eq_zero, and_iff_right_iff_imp]; rintro rfl; simp
@[simp]
theorem isNClique_one : G.IsNClique 1 s ↔ ∃ a, s = {a} := by
simp only [isNClique_iff, card_eq_one, and_iff_right_iff_imp]; rintro ⟨a, rfl⟩; simp
section DecidableEq
variable [DecidableEq α]
protected theorem IsNClique.insert (hs : G.IsNClique n s) (h : ∀ b ∈ s, G.Adj a b) :
G.IsNClique (n + 1) (insert a s) := by
constructor
· push_cast
exact hs.1.insert fun b hb _ => h _ hb
· rw [card_insert_of_not_mem fun ha => (h _ ha).ne rfl, hs.2]
lemma IsNClique.erase_of_mem (hs : G.IsNClique n s) (ha : a ∈ s) :
G.IsNClique (n - 1) (s.erase a) where
isClique := hs.isClique.subset <| by simp
card_eq := by rw [card_erase_of_mem ha, hs.2]
protected lemma IsNClique.insert_erase
(hs : G.IsNClique n s) (ha : ∀ w ∈ s \ {b}, G.Adj a w) (hb : b ∈ s) :
G.IsNClique n (insert a (erase s b)) := by
cases n with
| zero => exact False.elim <| not_mem_empty _ (isNClique_zero.1 hs ▸ hb)
| succ _ => exact (hs.erase_of_mem hb).insert fun w h ↦ by aesop
theorem is3Clique_triple_iff : G.IsNClique 3 {a, b, c} ↔ G.Adj a b ∧ G.Adj a c ∧ G.Adj b c := by
simp only [isNClique_iff, isClique_iff, Set.pairwise_insert_of_symmetric G.symm, coe_insert]
by_cases hab : a = b <;> by_cases hbc : b = c <;> by_cases hac : a = c <;> subst_vars <;>
simp [G.ne_of_adj, and_rotate, *]
theorem is3Clique_iff :
G.IsNClique 3 s ↔ ∃ a b c, G.Adj a b ∧ G.Adj a c ∧ G.Adj b c ∧ s = {a, b, c} := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, b, c, -, -, -, hs⟩ := card_eq_three.1 h.card_eq
refine ⟨a, b, c, ?_⟩
rwa [hs, eq_self_iff_true, and_true, is3Clique_triple_iff.symm, ← hs]
· rintro ⟨a, b, c, hab, hbc, hca, rfl⟩
exact is3Clique_triple_iff.2 ⟨hab, hbc, hca⟩
end DecidableEq
theorem is3Clique_iff_exists_cycle_length_three :
(∃ s : Finset α, G.IsNClique 3 s) ↔ ∃ (u : α) (w : G.Walk u u), w.IsCycle ∧ w.length = 3 := by
classical
simp_rw [is3Clique_iff, isCycle_def]
exact
⟨(fun ⟨_, a, _, _, hab, hac, hbc, _⟩ => ⟨a, cons hab (cons hbc (cons hac.symm nil)), by aesop⟩),
(fun ⟨_, .cons hab (.cons hbc (.cons hca nil)), _, _⟩ => ⟨_, _, _, _, hab, hca.symm, hbc, rfl⟩)⟩
/-- If a set of vertices `A` is an `n`-clique in subgraph of `G` induced by a superset of `A`,
its embedding is an `n`-clique in `G`. -/
theorem IsNClique.of_induce {S : Subgraph G} {F : Set α} {s : Finset { x // x ∈ F }} {n : ℕ}
(cc : (S.induce F).coe.IsNClique n s) :
G.IsNClique n (Finset.map ⟨Subtype.val, Subtype.val_injective⟩ s) := by
rw [isNClique_iff] at cc ⊢
simp only [Subgraph.induce_verts, coe_map, card_map]
exact ⟨cc.left.of_induce, cc.right⟩
lemma IsNClique.erase_of_sup_edge_of_mem [DecidableEq α] {v w : α} {s : Finset α} {n : ℕ}
(hc : (G ⊔ edge v w).IsNClique n s) (hx : v ∈ s) : G.IsNClique (n - 1) (s.erase v) where
isClique := coe_erase v _ ▸ hc.1.sdiff_of_sup_edge
card_eq := by rw [card_erase_of_mem hx, hc.2]
end NClique
/-! ### Graphs without cliques -/
section CliqueFree
variable {m n : ℕ}
/-- `G.CliqueFree n` means that `G` has no `n`-cliques. -/
def CliqueFree (n : ℕ) : Prop :=
∀ t, ¬G.IsNClique n t
variable {G H} {s : Finset α}
theorem IsNClique.not_cliqueFree (hG : G.IsNClique n s) : ¬G.CliqueFree n :=
fun h ↦ h _ hG
theorem not_cliqueFree_of_top_embedding {n : ℕ} (f : (⊤ : SimpleGraph (Fin n)) ↪g G) :
¬G.CliqueFree n := by
simp only [CliqueFree, isNClique_iff, isClique_iff_induce_eq, not_forall, Classical.not_not]
use Finset.univ.map f.toEmbedding
simp only [card_map, Finset.card_fin, eq_self_iff_true, and_true]
ext ⟨v, hv⟩ ⟨w, hw⟩
simp only [coe_map, Set.mem_image, coe_univ, Set.mem_univ, true_and] at hv hw
obtain ⟨v', rfl⟩ := hv
obtain ⟨w', rfl⟩ := hw
simp_rw [RelEmbedding.coe_toEmbedding, comap_adj, Function.Embedding.coe_subtype, f.map_adj_iff,
top_adj, ne_eq, Subtype.mk.injEq, RelEmbedding.inj]
/-- An embedding of a complete graph that witnesses the fact that the graph is not clique-free. -/
noncomputable def topEmbeddingOfNotCliqueFree {n : ℕ} (h : ¬G.CliqueFree n) :
(⊤ : SimpleGraph (Fin n)) ↪g G := by
simp only [CliqueFree, isNClique_iff, isClique_iff_induce_eq, not_forall, Classical.not_not] at h
obtain ⟨ha, hb⟩ := h.choose_spec
have : (⊤ : SimpleGraph (Fin #h.choose)) ≃g (⊤ : SimpleGraph h.choose) := by
apply Iso.completeGraph
simpa using (Fintype.equivFin h.choose).symm
rw [← ha] at this
convert (Embedding.induce ↑h.choose.toSet).comp this.toEmbedding
exact hb.symm
theorem not_cliqueFree_iff (n : ℕ) : ¬G.CliqueFree n ↔ Nonempty ((⊤ : SimpleGraph (Fin n)) ↪g G) :=
⟨fun h ↦ ⟨topEmbeddingOfNotCliqueFree h⟩, fun ⟨f⟩ ↦ not_cliqueFree_of_top_embedding f⟩
theorem cliqueFree_iff {n : ℕ} : G.CliqueFree n ↔ IsEmpty ((⊤ : SimpleGraph (Fin n)) ↪g G) := by
rw [← not_iff_not, not_cliqueFree_iff, not_isEmpty_iff]
theorem not_cliqueFree_card_of_top_embedding [Fintype α] (f : (⊤ : SimpleGraph α) ↪g G) :
¬G.CliqueFree (card α) := by
rw [not_cliqueFree_iff]
exact ⟨(Iso.completeGraph (Fintype.equivFin α)).symm.toEmbedding.trans f⟩
@[simp] lemma not_cliqueFree_zero : ¬ G.CliqueFree 0 :=
fun h ↦ h ∅ <| isNClique_empty.mpr rfl
@[simp]
theorem cliqueFree_bot (h : 2 ≤ n) : (⊥ : SimpleGraph α).CliqueFree n := by
intro t ht
have := le_trans h (isNClique_bot_iff.1 ht).1
contradiction
theorem CliqueFree.mono (h : m ≤ n) : G.CliqueFree m → G.CliqueFree n := by
intro hG s hs
obtain ⟨t, hts, ht⟩ := exists_subset_card_eq (h.trans hs.card_eq.ge)
exact hG _ ⟨hs.isClique.subset hts, ht⟩
theorem CliqueFree.anti (h : G ≤ H) : H.CliqueFree n → G.CliqueFree n :=
forall_imp fun _ ↦ mt <| IsNClique.mono h
/-- If a graph is cliquefree, any graph that embeds into it is also cliquefree. -/
theorem CliqueFree.comap {H : SimpleGraph β} (f : H ↪g G) : G.CliqueFree n → H.CliqueFree n := by
intro h; contrapose h
exact not_cliqueFree_of_top_embedding <| f.comp (topEmbeddingOfNotCliqueFree h)
@[simp] theorem cliqueFree_map_iff {f : α ↪ β} [Nonempty α] :
(G.map f).CliqueFree n ↔ G.CliqueFree n := by
obtain (hle | hlt) := le_or_lt n 1
· obtain (rfl | rfl) := Nat.le_one_iff_eq_zero_or_eq_one.1 hle
· simp [CliqueFree]
simp [CliqueFree, show ∃ (_ : β), True from ⟨f (Classical.arbitrary _), trivial⟩]
simp [CliqueFree, isNClique_map_iff hlt]
/-- See `SimpleGraph.cliqueFree_of_chromaticNumber_lt` for a tighter bound. -/
theorem cliqueFree_of_card_lt [Fintype α] (hc : card α < n) : G.CliqueFree n := by
by_contra h
refine Nat.lt_le_asymm hc ?_
rw [cliqueFree_iff, not_isEmpty_iff] at h
simpa only [Fintype.card_fin] using Fintype.card_le_of_embedding h.some.toEmbedding
/-- A complete `r`-partite graph has no `n`-cliques for `r < n`. -/
theorem cliqueFree_completeMultipartiteGraph {ι : Type*} [Fintype ι] (V : ι → Type*)
(hc : card ι < n) : (completeMultipartiteGraph V).CliqueFree n := by
rw [cliqueFree_iff, isEmpty_iff]
intro f
obtain ⟨v, w, hn, he⟩ := exists_ne_map_eq_of_card_lt (Sigma.fst ∘ f) (by simp [hc])
rw [← top_adj, ← f.map_adj_iff, comap_adj, top_adj] at hn
exact absurd he hn
namespace completeMultipartiteGraph
variable {ι : Type*} (V : ι → Type*)
/-- Embedding of the complete graph on `ι` into `completeMultipartiteGraph` on `ι` nonempty parts -/
@[simps]
def topEmbedding (f : ∀ (i : ι), V i) :
(⊤ : SimpleGraph ι) ↪g completeMultipartiteGraph V where
toFun := fun i ↦ ⟨i, f i⟩
inj' := fun _ _ h ↦ (Sigma.mk.inj_iff.1 h).1
map_rel_iff' := by simp
theorem not_cliqueFree_of_le_card [Fintype ι] (f : ∀ (i : ι), V i) (hc : n ≤ Fintype.card ι) :
¬ (completeMultipartiteGraph V).CliqueFree n :=
fun hf ↦ (cliqueFree_iff.1 <| hf.mono hc).elim' <|
(topEmbedding V f).comp (Iso.completeGraph (Fintype.equivFin ι).symm).toEmbedding
theorem not_cliqueFree_of_infinite [Infinite ι] (f : ∀ (i : ι), V i) :
¬ (completeMultipartiteGraph V).CliqueFree n :=
fun hf ↦ not_cliqueFree_of_top_embedding (topEmbedding V f |>.comp
<| Embedding.completeGraph <| Fin.valEmbedding.trans <| Infinite.natEmbedding ι) hf
theorem not_cliqueFree_of_le_enatCard (f : ∀ (i : ι), V i) (hc : n ≤ ENat.card ι) :
¬ (completeMultipartiteGraph V).CliqueFree n := by
by_cases h : Infinite ι
· exact not_cliqueFree_of_infinite V f
· have : Fintype ι := fintypeOfNotInfinite h
rw [ENat.card_eq_coe_fintype_card, Nat.cast_le] at hc
exact not_cliqueFree_of_le_card V f hc
end completeMultipartiteGraph
/-- Clique-freeness is preserved by `replaceVertex`. -/
protected theorem CliqueFree.replaceVertex [DecidableEq α] (h : G.CliqueFree n) (s t : α) :
(G.replaceVertex s t).CliqueFree n := by
contrapose h
obtain ⟨φ, hφ⟩ := topEmbeddingOfNotCliqueFree h
rw [not_cliqueFree_iff]
by_cases mt : t ∈ Set.range φ
· obtain ⟨x, hx⟩ := mt
by_cases ms : s ∈ Set.range φ
· obtain ⟨y, hy⟩ := ms
have e := @hφ x y
simp_rw [hx, hy, adj_comm, not_adj_replaceVertex_same, top_adj, false_iff, not_ne_iff] at e
rwa [← hx, e, hy, replaceVertex_self, not_cliqueFree_iff] at h
· unfold replaceVertex at hφ
use φ.setValue x s
intro a b
simp only [Embedding.coeFn_mk, Embedding.setValue, not_exists.mp ms, ite_false]
rw [apply_ite (G.Adj · _), apply_ite (G.Adj _ ·), apply_ite (G.Adj _ ·)]
convert @hφ a b <;> simp only [← φ.apply_eq_iff_eq, SimpleGraph.irrefl, hx]
· use φ
simp_rw [Set.mem_range, not_exists, ← ne_eq] at mt
conv at hφ => enter [a, b]; rw [G.adj_replaceVertex_iff_of_ne _ (mt a) (mt b)]
exact hφ
@[simp]
lemma cliqueFree_one : G.CliqueFree 1 ↔ IsEmpty α := by
simp [CliqueFree, isEmpty_iff]
@[simp]
theorem cliqueFree_two : G.CliqueFree 2 ↔ G = ⊥ := by
classical
constructor
· simp_rw [← edgeSet_eq_empty, Set.eq_empty_iff_forall_not_mem, Sym2.forall, mem_edgeSet]
exact fun h a b hab => h _ ⟨by simpa [hab.ne], card_pair hab.ne⟩
· rintro rfl
exact cliqueFree_bot le_rfl
lemma CliqueFree.mem_of_sup_edge_isNClique {x y : α} {t : Finset α} {n : ℕ} (h : G.CliqueFree n)
(hc : (G ⊔ edge x y).IsNClique n t) : x ∈ t := by
by_contra! hf
have ht : (t : Set α) \ {x} = t := sdiff_eq_left.mpr <| Set.disjoint_singleton_right.mpr hf
exact h t ⟨ht ▸ hc.1.sdiff_of_sup_edge, hc.2⟩
open Classical in
/-- Adding an edge increases the clique number by at most one. -/
protected theorem CliqueFree.sup_edge (h : G.CliqueFree n) (v w : α) :
(G ⊔ edge v w).CliqueFree (n + 1) :=
fun _ hs ↦ (hs.erase_of_sup_edge_of_mem <|
(h.mono n.le_succ).mem_of_sup_edge_isNClique hs).not_cliqueFree h
end CliqueFree
section CliqueFreeOn
variable {s s₁ s₂ : Set α} {a : α} {m n : ℕ}
/-- `G.CliqueFreeOn s n` means that `G` has no `n`-cliques contained in `s`. -/
def CliqueFreeOn (G : SimpleGraph α) (s : Set α) (n : ℕ) : Prop :=
∀ ⦃t⦄, ↑t ⊆ s → ¬G.IsNClique n t
theorem CliqueFreeOn.subset (hs : s₁ ⊆ s₂) (h₂ : G.CliqueFreeOn s₂ n) : G.CliqueFreeOn s₁ n :=
fun _t hts => h₂ <| hts.trans hs
theorem CliqueFreeOn.mono (hmn : m ≤ n) (hG : G.CliqueFreeOn s m) : G.CliqueFreeOn s n := by
rintro t hts ht
obtain ⟨u, hut, hu⟩ := exists_subset_card_eq (hmn.trans ht.card_eq.ge)
exact hG ((coe_subset.2 hut).trans hts) ⟨ht.isClique.subset hut, hu⟩
theorem CliqueFreeOn.anti (hGH : G ≤ H) (hH : H.CliqueFreeOn s n) : G.CliqueFreeOn s n :=
fun _t hts ht => hH hts <| ht.mono hGH
@[simp]
theorem cliqueFreeOn_empty : G.CliqueFreeOn ∅ n ↔ n ≠ 0 := by
simp [CliqueFreeOn, Set.subset_empty_iff]
@[simp]
theorem cliqueFreeOn_singleton : G.CliqueFreeOn {a} n ↔ 1 < n := by
obtain _ | _ | n := n <;>
simp [CliqueFreeOn, isNClique_iff, ← subset_singleton_iff', (Nat.succ_ne_zero _).symm]
@[simp]
theorem cliqueFreeOn_univ : G.CliqueFreeOn Set.univ n ↔ G.CliqueFree n := by
simp [CliqueFree, CliqueFreeOn]
protected theorem CliqueFree.cliqueFreeOn (hG : G.CliqueFree n) : G.CliqueFreeOn s n :=
fun _t _ ↦ hG _
theorem cliqueFreeOn_of_card_lt {s : Finset α} (h : #s < n) : G.CliqueFreeOn s n :=
fun _t hts ht => h.not_le <| ht.2.symm.trans_le <| card_mono hts
-- TODO: Restate using `SimpleGraph.IndepSet` once we have it
@[simp]
theorem cliqueFreeOn_two : G.CliqueFreeOn s 2 ↔ s.Pairwise (G.Adjᶜ) := by
classical
refine ⟨fun h a ha b hb _ hab => h ?_ ⟨by simpa [hab.ne], card_pair hab.ne⟩, ?_⟩
· push_cast
exact Set.insert_subset_iff.2 ⟨ha, Set.singleton_subset_iff.2 hb⟩
simp only [CliqueFreeOn, isNClique_iff, card_eq_two, coe_subset, not_and, not_exists]
rintro h t hst ht a b hab rfl
simp only [coe_insert, coe_singleton, Set.insert_subset_iff, Set.singleton_subset_iff] at hst
refine h hst.1 hst.2 hab (ht ?_ ?_ hab) <;> simp
theorem CliqueFreeOn.of_succ (hs : G.CliqueFreeOn s (n + 1)) (ha : a ∈ s) :
G.CliqueFreeOn (s ∩ G.neighborSet a) n := by
classical
refine fun t hts ht => hs ?_ (ht.insert fun b hb => (hts hb).2)
push_cast
exact Set.insert_subset_iff.2 ⟨ha, hts.trans Set.inter_subset_left⟩
end CliqueFreeOn
/-! ### Set of cliques -/
section CliqueSet
variable {n : ℕ} {s : Finset α}
/-- The `n`-cliques in a graph as a set. -/
def cliqueSet (n : ℕ) : Set (Finset α) :=
{ s | G.IsNClique n s }
variable {G H}
@[simp]
theorem mem_cliqueSet_iff : s ∈ G.cliqueSet n ↔ G.IsNClique n s :=
Iff.rfl
@[simp]
theorem cliqueSet_eq_empty_iff : G.cliqueSet n = ∅ ↔ G.CliqueFree n := by
simp_rw [CliqueFree, Set.eq_empty_iff_forall_not_mem, mem_cliqueSet_iff]
protected alias ⟨_, CliqueFree.cliqueSet⟩ := cliqueSet_eq_empty_iff
@[gcongr, mono]
theorem cliqueSet_mono (h : G ≤ H) : G.cliqueSet n ⊆ H.cliqueSet n :=
fun _ ↦ IsNClique.mono h
theorem cliqueSet_mono' (h : G ≤ H) : G.cliqueSet ≤ H.cliqueSet :=
fun _ ↦ cliqueSet_mono h
@[simp]
theorem cliqueSet_zero (G : SimpleGraph α) : G.cliqueSet 0 = {∅} := Set.ext fun s => by simp
@[simp]
theorem cliqueSet_one (G : SimpleGraph α) : G.cliqueSet 1 = Set.range singleton :=
Set.ext fun s => by simp [eq_comm]
@[simp]
theorem cliqueSet_bot (hn : 1 < n) : (⊥ : SimpleGraph α).cliqueSet n = ∅ :=
(cliqueFree_bot hn).cliqueSet
@[simp]
theorem cliqueSet_map (hn : n ≠ 1) (G : SimpleGraph α) (f : α ↪ β) :
(G.map f).cliqueSet n = map f '' G.cliqueSet n := by
ext s
constructor
· rintro ⟨hs, rfl⟩
have hs' : (s.preimage f f.injective.injOn).map f = s := by
classical
rw [map_eq_image, image_preimage, filter_true_of_mem]
rintro a ha
obtain ⟨b, hb, hba⟩ := exists_mem_ne (hn.lt_of_le' <| Finset.card_pos.2 ⟨a, ha⟩) a
obtain ⟨c, _, _, hc, _⟩ := hs ha hb hba.symm
exact ⟨c, hc⟩
refine ⟨s.preimage f f.injective.injOn, ⟨?_, by rw [← card_map f, hs']⟩, hs'⟩
rw [coe_preimage]
exact fun a ha b hb hab => map_adj_apply.1 (hs ha hb <| f.injective.ne hab)
· rintro ⟨s, hs, rfl⟩
exact hs.map
@[simp]
theorem cliqueSet_map_of_equiv (G : SimpleGraph α) (e : α ≃ β) (n : ℕ) :
(G.map e.toEmbedding).cliqueSet n = map e.toEmbedding '' G.cliqueSet n := by
obtain rfl | hn := eq_or_ne n 1
· ext
simp [e.exists_congr_left]
· exact cliqueSet_map hn _ _
end CliqueSet
/-! ### Clique number -/
section CliqueNumber
variable {α : Type*} {G : SimpleGraph α}
/-- The maximum number of vertices in a clique of a graph `G`. -/
noncomputable def cliqueNum (G : SimpleGraph α) : ℕ := sSup {n | ∃ s, G.IsNClique n s}
private lemma fintype_cliqueNum_bddAbove [Fintype α] : BddAbove {n | ∃ s, G.IsNClique n s} := by
use Fintype.card α
rintro y ⟨s, syc⟩
rw [isNClique_iff] at syc
rw [← syc.right]
exact Finset.card_le_card (Finset.subset_univ s)
lemma IsClique.card_le_cliqueNum [Finite α] {t : Finset α} {tc : G.IsClique t} :
#t ≤ G.cliqueNum := by
cases nonempty_fintype α
exact le_csSup G.fintype_cliqueNum_bddAbove (Exists.intro t ⟨tc, rfl⟩)
lemma exists_isNClique_cliqueNum [Finite α] : ∃ s, G.IsNClique G.cliqueNum s := by
cases nonempty_fintype α
exact Nat.sSup_mem ⟨0, by simp [isNClique_empty.mpr rfl]⟩ G.fintype_cliqueNum_bddAbove
/-- A maximum clique in a graph `G` is a clique with the largest possible size. -/
| structure IsMaximumClique [Fintype α] (G : SimpleGraph α) (s : Finset α) : Prop where
(isClique : G.IsClique s)
(maximum : ∀ t : Finset α, G.IsClique t → #t ≤ #s)
| Mathlib/Combinatorics/SimpleGraph/Clique.lean | 641 | 644 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Group.Subgroup.Map
import Mathlib.Algebra.Module.Submodule.Basic
import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.Algebra.Module.Submodule.LinearMap
/-!
# `map` and `comap` for `Submodule`s
## Main declarations
* `Submodule.map`: The pushforward of a submodule `p ⊆ M` by `f : M → M₂`
* `Submodule.comap`: The pullback of a submodule `p ⊆ M₂` along `f : M → M₂`
* `Submodule.giMapComap`: `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective.
* `Submodule.gciMapComap`: `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective.
## Tags
submodule, subspace, linear map, pushforward, pullback
-/
open Function Pointwise Set
variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*}
variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
namespace Submodule
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable (p p' : Submodule R M) (q q' : Submodule R₂ M₂)
variable {x : M}
section
variable [RingHomSurjective σ₁₂] {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
/-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/
def map (f : F) (p : Submodule R M) : Submodule R₂ M₂ :=
{ p.toAddSubmonoid.map f with
carrier := f '' p
smul_mem' := by
rintro c x ⟨y, hy, rfl⟩
obtain ⟨a, rfl⟩ := σ₁₂.surjective c
exact ⟨_, p.smul_mem a hy, map_smulₛₗ f _ _⟩ }
@[simp]
theorem map_coe (f : F) (p : Submodule R M) : (map f p : Set M₂) = f '' p :=
rfl
@[simp]
theorem map_coe_toLinearMap (f : F) (p : Submodule R M) : map (f : M →ₛₗ[σ₁₂] M₂) p = map f p := rfl
theorem map_toAddSubmonoid (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) :
(p.map f).toAddSubmonoid = p.toAddSubmonoid.map (f : M →+ M₂) :=
SetLike.coe_injective rfl
theorem map_toAddSubmonoid' (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) :
(p.map f).toAddSubmonoid = p.toAddSubmonoid.map f :=
SetLike.coe_injective rfl
@[simp]
theorem _root_.AddMonoidHom.coe_toIntLinearMap_map {A A₂ : Type*} [AddCommGroup A] [AddCommGroup A₂]
(f : A →+ A₂) (s : AddSubgroup A) :
(AddSubgroup.toIntSubmodule s).map f.toIntLinearMap =
AddSubgroup.toIntSubmodule (s.map f) := rfl
@[simp]
theorem _root_.MonoidHom.coe_toAdditive_map {G G₂ : Type*} [Group G] [Group G₂] (f : G →* G₂)
(s : Subgroup G) :
s.toAddSubgroup.map (MonoidHom.toAdditive f) = Subgroup.toAddSubgroup (s.map f) := rfl
@[simp]
theorem _root_.AddMonoidHom.coe_toMultiplicative_map {G G₂ : Type*} [AddGroup G] [AddGroup G₂]
(f : G →+ G₂) (s : AddSubgroup G) :
s.toSubgroup.map (AddMonoidHom.toMultiplicative f) = AddSubgroup.toSubgroup (s.map f) := rfl
@[simp]
theorem mem_map {f : F} {p : Submodule R M} {x : M₂} : x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x :=
Iff.rfl
theorem mem_map_of_mem {f : F} {p : Submodule R M} {r} (h : r ∈ p) : f r ∈ map f p :=
Set.mem_image_of_mem _ h
theorem apply_coe_mem_map (f : F) {p : Submodule R M} (r : p) : f r ∈ map f p :=
mem_map_of_mem r.prop
@[simp]
theorem map_id : map (LinearMap.id : M →ₗ[R] M) p = p :=
Submodule.ext fun a => by simp
theorem map_comp [RingHomSurjective σ₂₃] [RingHomSurjective σ₁₃] (f : M →ₛₗ[σ₁₂] M₂)
(g : M₂ →ₛₗ[σ₂₃] M₃) (p : Submodule R M) : map (g.comp f : M →ₛₗ[σ₁₃] M₃) p = map g (map f p) :=
SetLike.coe_injective <| by simp only [← image_comp, map_coe, LinearMap.coe_comp, comp_apply]
@[gcongr]
theorem map_mono {f : F} {p p' : Submodule R M} : p ≤ p' → map f p ≤ map f p' :=
image_subset _
@[simp]
protected theorem map_zero : map (0 : M →ₛₗ[σ₁₂] M₂) p = ⊥ :=
have : ∃ x : M, x ∈ p := ⟨0, p.zero_mem⟩
ext <| by simp [this, eq_comm]
theorem map_add_le (f g : M →ₛₗ[σ₁₂] M₂) : map (f + g) p ≤ map f p ⊔ map g p := by
rintro x ⟨m, hm, rfl⟩
exact add_mem_sup (mem_map_of_mem hm) (mem_map_of_mem hm)
theorem map_inf_le (f : F) {p q : Submodule R M} :
(p ⊓ q).map f ≤ p.map f ⊓ q.map f :=
image_inter_subset f p q
theorem map_inf (f : F) {p q : Submodule R M} (hf : Injective f) :
(p ⊓ q).map f = p.map f ⊓ q.map f :=
SetLike.coe_injective <| Set.image_inter hf
lemma map_iInf {ι : Type*} [Nonempty ι] {p : ι → Submodule R M} (f : F) (hf : Injective f) :
(⨅ i, p i).map f = ⨅ i, (p i).map f :=
SetLike.coe_injective <| by simpa only [map_coe, iInf_coe] using hf.injOn.image_iInter_eq
theorem range_map_nonempty (N : Submodule R M) :
(Set.range (fun ϕ => Submodule.map ϕ N : (M →ₛₗ[σ₁₂] M₂) → Submodule R₂ M₂)).Nonempty :=
⟨_, Set.mem_range.mpr ⟨0, rfl⟩⟩
end
section SemilinearMap
variable {σ₂₁ : R₂ →+* R} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
/-- The pushforward of a submodule by an injective linear map is
linearly equivalent to the original submodule. See also `LinearEquiv.submoduleMap` for a
computable version when `f` has an explicit inverse. -/
noncomputable def equivMapOfInjective (f : F) (i : Injective f) (p : Submodule R M) :
p ≃ₛₗ[σ₁₂] p.map f :=
{ Equiv.Set.image f p i with
map_add' := by
intros
simp only [coe_add, map_add, Equiv.toFun_as_coe, Equiv.Set.image_apply]
rfl
map_smul' := by
intros
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 changed `map_smulₛₗ` into `map_smulₛₗ _`
simp only [coe_smul_of_tower, map_smulₛₗ _, Equiv.toFun_as_coe, Equiv.Set.image_apply]
rfl }
@[simp]
theorem coe_equivMapOfInjective_apply (f : F) (i : Injective f) (p : Submodule R M) (x : p) :
(equivMapOfInjective f i p x : M₂) = f x :=
rfl
@[simp]
theorem map_equivMapOfInjective_symm_apply (f : F) (i : Injective f) (p : Submodule R M)
(x : p.map f) : f ((equivMapOfInjective f i p).symm x) = x := by
rw [← LinearEquiv.apply_symm_apply (equivMapOfInjective f i p) x, coe_equivMapOfInjective_apply,
i.eq_iff, LinearEquiv.apply_symm_apply]
/-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/
def comap [SemilinearMapClass F σ₁₂ M M₂] (f : F) (p : Submodule R₂ M₂) : Submodule R M :=
{ p.toAddSubmonoid.comap f with
carrier := f ⁻¹' p
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 added `map_smulₛₗ _`
smul_mem' := fun a x h => by simp [p.smul_mem (σ₁₂ a) h, map_smulₛₗ _] }
@[simp]
theorem comap_coe (f : F) (p : Submodule R₂ M₂) : (comap f p : Set M) = f ⁻¹' p :=
rfl
@[simp] theorem comap_coe_toLinearMap (f : F) (p : Submodule R₂ M₂) :
comap (f : M →ₛₗ[σ₁₂] M₂) p = comap f p := rfl
@[simp]
theorem AddMonoidHom.coe_toIntLinearMap_comap {A A₂ : Type*} [AddCommGroup A] [AddCommGroup A₂]
(f : A →+ A₂) (s : AddSubgroup A₂) :
(AddSubgroup.toIntSubmodule s).comap f.toIntLinearMap =
AddSubgroup.toIntSubmodule (s.comap f) := rfl
@[simp]
theorem mem_comap {f : F} {p : Submodule R₂ M₂} : x ∈ comap f p ↔ f x ∈ p :=
Iff.rfl
@[simp]
theorem comap_id : comap (LinearMap.id : M →ₗ[R] M) p = p :=
SetLike.coe_injective rfl
theorem comap_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃) (p : Submodule R₃ M₃) :
comap (g.comp f : M →ₛₗ[σ₁₃] M₃) p = comap f (comap g p) :=
rfl
@[gcongr]
theorem comap_mono {f : F} {q q' : Submodule R₂ M₂} : q ≤ q' → comap f q ≤ comap f q' :=
preimage_mono
theorem le_comap_pow_of_le_comap (p : Submodule R M) {f : M →ₗ[R] M}
(h : p ≤ p.comap f) (k : ℕ) : p ≤ p.comap (f ^ k) := by
induction k with
| zero => simp [Module.End.one_eq_id]
| succ k ih => simp [Module.End.iterate_succ, comap_comp, h.trans (comap_mono ih)]
section
variable [RingHomSurjective σ₁₂]
theorem map_le_iff_le_comap {f : F} {p : Submodule R M} {q : Submodule R₂ M₂} :
map f p ≤ q ↔ p ≤ comap f q :=
image_subset_iff
theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f)
| _, _ => map_le_iff_le_comap
@[simp]
theorem map_bot (f : F) : map f ⊥ = ⊥ :=
(gc_map_comap f).l_bot
@[simp]
theorem map_sup (f : F) : map f (p ⊔ p') = map f p ⊔ map f p' :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
@[simp]
theorem map_iSup {ι : Sort*} (f : F) (p : ι → Submodule R M) :
map f (⨆ i, p i) = ⨆ i, map f (p i) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
end
@[simp]
theorem comap_top (f : F) : comap f ⊤ = ⊤ :=
rfl
@[simp]
theorem comap_inf (f : F) : comap f (q ⊓ q') = comap f q ⊓ comap f q' :=
rfl
@[simp]
theorem comap_iInf [RingHomSurjective σ₁₂] {ι : Sort*} (f : F) (p : ι → Submodule R₂ M₂) :
comap f (⨅ i, p i) = ⨅ i, comap f (p i) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
@[simp]
theorem comap_zero : comap (0 : M →ₛₗ[σ₁₂] M₂) q = ⊤ :=
ext <| by simp
theorem map_comap_le [RingHomSurjective σ₁₂] (f : F) (q : Submodule R₂ M₂) :
map f (comap f q) ≤ q :=
(gc_map_comap f).l_u_le _
theorem le_comap_map [RingHomSurjective σ₁₂] (f : F) (p : Submodule R M) : p ≤ comap f (map f p) :=
(gc_map_comap f).le_u_l _
section submoduleOf
/-- For any `R` submodules `p` and `q`, `p ⊓ q` as a submodule of `q`. -/
def submoduleOf (p q : Submodule R M) : Submodule R q :=
Submodule.comap q.subtype p
/-- If `p ≤ q`, then `p` as a subgroup of `q` is isomorphic to `p`. -/
| def submoduleOfEquivOfLe {p q : Submodule R M} (h : p ≤ q) : p.submoduleOf q ≃ₗ[R] p where
toFun m := ⟨m.1, m.2⟩
| Mathlib/Algebra/Module/Submodule/Map.lean | 268 | 269 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl, Damiano Testa,
Yuyang Zhao
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.Defs
import Mathlib.Data.Ordering.Basic
import Mathlib.Order.MinMax
import Mathlib.Tactic.Contrapose
import Mathlib.Tactic.Use
/-!
# Ordered monoids
This file develops the basics of ordered monoids.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
## Remark
Almost no monoid is actually present in this file: most assumptions have been generalized to
`Mul` or `MulOneClass`.
-/
-- TODO: If possible, uniformize lemma names, taking special care of `'`,
-- after the `ordered`-refactor is done.
open Function
section Nat
instance Nat.instMulLeftMono : MulLeftMono ℕ where
elim := fun _ _ _ h => mul_le_mul_left _ h
end Nat
section Int
instance Int.instAddLeftMono : AddLeftMono ℤ where
elim := fun _ _ _ h => Int.add_le_add_left h _
end Int
variable {α β : Type*}
section Mul
variable [Mul α]
section LE
variable [LE α]
/- The prime on this lemma is present only on the multiplicative version. The unprimed version
is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/
@[to_additive (attr := gcongr) add_le_add_left]
theorem mul_le_mul_left' [MulLeftMono α] {b c : α} (bc : b ≤ c) (a : α) :
a * b ≤ a * c :=
CovariantClass.elim _ bc
@[to_additive le_of_add_le_add_left]
theorem le_of_mul_le_mul_left' [MulLeftReflectLE α] {a b c : α}
(bc : a * b ≤ a * c) :
b ≤ c :=
ContravariantClass.elim _ bc
/- The prime on this lemma is present only on the multiplicative version. The unprimed version
is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/
@[to_additive (attr := gcongr) add_le_add_right]
theorem mul_le_mul_right' [i : MulRightMono α] {b c : α} (bc : b ≤ c)
(a : α) :
b * a ≤ c * a :=
i.elim a bc
@[to_additive le_of_add_le_add_right]
theorem le_of_mul_le_mul_right' [i : MulRightReflectLE α] {a b c : α}
(bc : b * a ≤ c * a) :
b ≤ c :=
i.elim a bc
@[to_additive (attr := simp)]
theorem mul_le_mul_iff_left [MulLeftMono α]
[MulLeftReflectLE α] (a : α) {b c : α} :
a * b ≤ a * c ↔ b ≤ c :=
rel_iff_cov α α (· * ·) (· ≤ ·) a
@[to_additive (attr := simp)]
theorem mul_le_mul_iff_right [MulRightMono α]
[MulRightReflectLE α] (a : α) {b c : α} :
b * a ≤ c * a ↔ b ≤ c :=
rel_iff_cov α α (swap (· * ·)) (· ≤ ·) a
end LE
section LT
variable [LT α]
@[to_additive (attr := simp)]
theorem mul_lt_mul_iff_left [MulLeftStrictMono α]
[MulLeftReflectLT α] (a : α) {b c : α} :
a * b < a * c ↔ b < c :=
rel_iff_cov α α (· * ·) (· < ·) a
@[to_additive (attr := simp)]
theorem mul_lt_mul_iff_right [MulRightStrictMono α]
[MulRightReflectLT α] (a : α) {b c : α} :
b * a < c * a ↔ b < c :=
rel_iff_cov α α (swap (· * ·)) (· < ·) a
@[to_additive (attr := gcongr) add_lt_add_left]
theorem mul_lt_mul_left' [MulLeftStrictMono α] {b c : α} (bc : b < c) (a : α) :
a * b < a * c :=
CovariantClass.elim _ bc
@[to_additive lt_of_add_lt_add_left]
theorem lt_of_mul_lt_mul_left' [MulLeftReflectLT α] {a b c : α}
(bc : a * b < a * c) :
b < c :=
ContravariantClass.elim _ bc
@[to_additive (attr := gcongr) add_lt_add_right]
theorem mul_lt_mul_right' [i : MulRightStrictMono α] {b c : α} (bc : b < c)
(a : α) :
b * a < c * a :=
i.elim a bc
@[to_additive lt_of_add_lt_add_right]
theorem lt_of_mul_lt_mul_right' [i : MulRightReflectLT α] {a b c : α}
(bc : b * a < c * a) :
b < c :=
i.elim a bc
end LT
section Preorder
variable [Preorder α]
@[to_additive]
lemma mul_left_mono [MulLeftMono α] {a : α} : Monotone (a * ·) :=
fun _ _ h ↦ mul_le_mul_left' h _
@[to_additive]
lemma mul_right_mono [MulRightMono α] {a : α} : Monotone (· * a) :=
fun _ _ h ↦ mul_le_mul_right' h _
@[to_additive]
lemma mul_left_strictMono [MulLeftStrictMono α] {a : α} : StrictMono (a * ·) :=
fun _ _ h ↦ mul_lt_mul_left' h _
@[to_additive]
lemma mul_right_strictMono [MulRightStrictMono α] {a : α} : StrictMono (· * a) :=
fun _ _ h ↦ mul_lt_mul_right' h _
@[to_additive (attr := gcongr)]
theorem mul_lt_mul_of_lt_of_lt [MulLeftStrictMono α]
[MulRightStrictMono α]
{a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d :=
calc
a * c < a * d := mul_lt_mul_left' h₂ a
_ < b * d := mul_lt_mul_right' h₁ d
alias add_lt_add := add_lt_add_of_lt_of_lt
@[to_additive]
theorem mul_lt_mul_of_le_of_lt [MulLeftStrictMono α]
[MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c < d) :
a * c < b * d :=
(mul_le_mul_right' h₁ _).trans_lt (mul_lt_mul_left' h₂ b)
@[to_additive]
theorem mul_lt_mul_of_lt_of_le [MulLeftMono α]
[MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c ≤ d) :
a * c < b * d :=
(mul_le_mul_left' h₂ _).trans_lt (mul_lt_mul_right' h₁ d)
/-- Only assumes left strict covariance. -/
@[to_additive "Only assumes left strict covariance"]
theorem Left.mul_lt_mul [MulLeftStrictMono α]
[MulRightMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) :
a * c < b * d :=
mul_lt_mul_of_le_of_lt h₁.le h₂
/-- Only assumes right strict covariance. -/
@[to_additive "Only assumes right strict covariance"]
theorem Right.mul_lt_mul [MulLeftMono α]
[MulRightStrictMono α] {a b c d : α}
(h₁ : a < b) (h₂ : c < d) :
a * c < b * d :=
mul_lt_mul_of_lt_of_le h₁ h₂.le
@[to_additive (attr := gcongr) add_le_add]
theorem mul_le_mul' [MulLeftMono α] [MulRightMono α]
{a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) :
a * c ≤ b * d :=
(mul_le_mul_left' h₂ _).trans (mul_le_mul_right' h₁ d)
@[to_additive]
theorem mul_le_mul_three [MulLeftMono α]
[MulRightMono α] {a b c d e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e)
(h₃ : c ≤ f) :
a * b * c ≤ d * e * f :=
mul_le_mul' (mul_le_mul' h₁ h₂) h₃
@[to_additive]
theorem mul_lt_of_mul_lt_left [MulLeftMono α] {a b c d : α} (h : a * b < c)
(hle : d ≤ b) :
a * d < c :=
(mul_le_mul_left' hle a).trans_lt h
@[to_additive]
theorem mul_le_of_mul_le_left [MulLeftMono α] {a b c d : α} (h : a * b ≤ c)
(hle : d ≤ b) :
a * d ≤ c :=
@act_rel_of_rel_of_act_rel _ _ _ (· ≤ ·) _ _ a _ _ _ hle h
@[to_additive]
theorem mul_lt_of_mul_lt_right [MulRightMono α] {a b c d : α}
(h : a * b < c) (hle : d ≤ a) :
d * b < c :=
(mul_le_mul_right' hle b).trans_lt h
@[to_additive]
theorem mul_le_of_mul_le_right [MulRightMono α] {a b c d : α}
(h : a * b ≤ c) (hle : d ≤ a) :
d * b ≤ c :=
(mul_le_mul_right' hle b).trans h
@[to_additive]
theorem lt_mul_of_lt_mul_left [MulLeftMono α] {a b c d : α} (h : a < b * c)
(hle : c ≤ d) :
a < b * d :=
h.trans_le (mul_le_mul_left' hle b)
@[to_additive]
theorem le_mul_of_le_mul_left [MulLeftMono α] {a b c d : α} (h : a ≤ b * c)
(hle : c ≤ d) :
a ≤ b * d :=
@rel_act_of_rel_of_rel_act _ _ _ (· ≤ ·) _ _ b _ _ _ hle h
@[to_additive]
theorem lt_mul_of_lt_mul_right [MulRightMono α] {a b c d : α}
(h : a < b * c) (hle : b ≤ d) :
a < d * c :=
h.trans_le (mul_le_mul_right' hle c)
@[to_additive]
theorem le_mul_of_le_mul_right [MulRightMono α] {a b c d : α}
(h : a ≤ b * c) (hle : b ≤ d) :
a ≤ d * c :=
h.trans (mul_le_mul_right' hle c)
end Preorder
section PartialOrder
variable [PartialOrder α]
@[to_additive]
theorem mul_left_cancel'' [MulLeftReflectLE α] {a b c : α} (h : a * b = a * c) :
b = c :=
(le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge)
@[to_additive]
theorem mul_right_cancel'' [MulRightReflectLE α] {a b c : α}
(h : a * b = c * b) :
a = c :=
(le_of_mul_le_mul_right' h.le).antisymm (le_of_mul_le_mul_right' h.ge)
@[to_additive] lemma mul_le_mul_iff_of_ge [MulLeftStrictMono α]
[MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) :
a₂ * b₂ ≤ a₁ * b₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by
haveI := mulLeftMono_of_mulLeftStrictMono α
haveI := mulRightMono_of_mulRightStrictMono α
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
simp only [eq_iff_le_not_lt, ha, hb, true_and]
refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩
exacts [mul_lt_mul_of_lt_of_le ha hb, mul_lt_mul_of_le_of_lt ha hb]
@[to_additive] theorem mul_eq_mul_iff_eq_and_eq [MulLeftStrictMono α]
[MulRightStrictMono α] {a b c d : α} (hac : a ≤ c) (hbd : b ≤ d) :
a * b = c * d ↔ a = c ∧ b = d := by
haveI := mulLeftMono_of_mulLeftStrictMono α
haveI := mulRightMono_of_mulRightStrictMono α
rw [le_antisymm_iff, eq_true (mul_le_mul' hac hbd), true_and, mul_le_mul_iff_of_ge hac hbd]
@[to_additive]
lemma mul_left_inj_of_comparable [MulRightStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) :
c * a = b * a ↔ c = b := by
refine ⟨fun h' => ?_, (· ▸ rfl)⟩
contrapose h'
obtain h | h := h
· exact mul_lt_mul_right' (h.lt_of_ne' h') a |>.ne'
· exact mul_lt_mul_right' (h.lt_of_ne h') a |>.ne
@[to_additive]
lemma mul_right_inj_of_comparable [MulLeftStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) :
a * c = a * b ↔ c = b := by
refine ⟨fun h' => ?_, (· ▸ rfl)⟩
contrapose h'
obtain h | h := h
· exact mul_lt_mul_left' (h.lt_of_ne' h') a |>.ne'
· exact mul_lt_mul_left' (h.lt_of_ne h') a |>.ne
end PartialOrder
section LinearOrder
variable [LinearOrder α] {a b c d : α}
@[to_additive]
theorem trichotomy_of_mul_eq_mul
[MulLeftStrictMono α] [MulRightStrictMono α]
(h : a * b = c * d) : (a = c ∧ b = d) ∨ a < c ∨ b < d := by
obtain hac | rfl | hca := lt_trichotomy a c
· right; left; exact hac
· left; simpa using mul_right_inj_of_comparable (LinearOrder.le_total d b)|>.1 h
· obtain hbd | rfl | hdb := lt_trichotomy b d
· right; right; exact hbd
· exact False.elim <| ne_of_lt (mul_lt_mul_right' hca b) h.symm
· exact False.elim <| ne_of_lt (mul_lt_mul_of_lt_of_lt hca hdb) h.symm
@[to_additive]
lemma mul_max [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :
a * max b c = max (a * b) (a * c) := mul_left_mono.map_max
@[to_additive]
lemma max_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
max a b * c = max (a * c) (b * c) := mul_right_mono.map_max
@[to_additive]
lemma mul_min [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :
a * min b c = min (a * b) (a * c) := mul_left_mono.map_min
@[to_additive]
lemma min_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
min a b * c = min (a * c) (b * c) := mul_right_mono.map_min
@[to_additive] lemma min_lt_max_of_mul_lt_mul
[MulLeftMono α] [MulRightMono α]
(h : a * b < c * d) : min a b < max c d := by
simp_rw [min_lt_iff, lt_max_iff]; contrapose! h; exact mul_le_mul' h.1.1 h.2.2
@[to_additive] lemma Left.min_le_max_of_mul_le_mul
[MulLeftStrictMono α] [MulRightMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d := by
simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_le_of_lt h.1.1.le h.2.2
@[to_additive] lemma Right.min_le_max_of_mul_le_mul
[MulLeftMono α] [MulRightStrictMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d := by
simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_lt_of_le h.1.1 h.2.2.le
@[to_additive] lemma min_le_max_of_mul_le_mul
[MulLeftStrictMono α] [MulRightStrictMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d :=
haveI := mulRightMono_of_mulRightStrictMono α
Left.min_le_max_of_mul_le_mul h
/-- Not an instance, to avoid loops with `IsLeftCancelMul.mulLeftStrictMono_of_mulLeftMono`. -/
@[to_additive]
theorem MulLeftStrictMono.toIsLeftCancelMul [MulLeftStrictMono α] : IsLeftCancelMul α where
mul_left_cancel _ _ _ h := mul_left_strictMono.injective h
/-- Not an instance, to avoid loops with `IsRightCancelMul.mulRightStrictMono_of_mulRightMono`. -/
@[to_additive]
theorem MulRightStrictMono.toIsRightCancelMul [MulRightStrictMono α] : IsRightCancelMul α where
mul_right_cancel _ _ _ h := mul_right_strictMono.injective h
end LinearOrder
section LinearOrder
variable [LinearOrder α] [MulLeftMono α] [MulRightMono α] {a b c d : α}
@[to_additive max_add_add_le_max_add_max]
theorem max_mul_mul_le_max_mul_max' : max (a * b) (c * d) ≤ max a c * max b d :=
max_le (mul_le_mul' (le_max_left _ _) <| le_max_left _ _) <|
mul_le_mul' (le_max_right _ _) <| le_max_right _ _
@[to_additive min_add_min_le_min_add_add]
theorem min_mul_min_le_min_mul_mul' : min a c * min b d ≤ min (a * b) (c * d) :=
le_min (mul_le_mul' (min_le_left _ _) <| min_le_left _ _) <|
mul_le_mul' (min_le_right _ _) <| min_le_right _ _
end LinearOrder
end Mul
-- using one
section MulOneClass
variable [MulOneClass α]
section LE
variable [LE α]
@[to_additive le_add_of_nonneg_right]
theorem le_mul_of_one_le_right' [MulLeftMono α] {a b : α} (h : 1 ≤ b) :
a ≤ a * b :=
calc
a = a * 1 := (mul_one a).symm
_ ≤ a * b := mul_le_mul_left' h a
@[to_additive add_le_of_nonpos_right]
theorem mul_le_of_le_one_right' [MulLeftMono α] {a b : α} (h : b ≤ 1) :
a * b ≤ a :=
calc
a * b ≤ a * 1 := mul_le_mul_left' h a
_ = a := mul_one a
@[to_additive le_add_of_nonneg_left]
theorem le_mul_of_one_le_left' [MulRightMono α] {a b : α} (h : 1 ≤ b) :
a ≤ b * a :=
calc
a = 1 * a := (one_mul a).symm
_ ≤ b * a := mul_le_mul_right' h a
@[to_additive add_le_of_nonpos_left]
theorem mul_le_of_le_one_left' [MulRightMono α] {a b : α} (h : b ≤ 1) :
b * a ≤ a :=
calc
b * a ≤ 1 * a := mul_le_mul_right' h a
_ = a := one_mul a
@[to_additive]
theorem one_le_of_le_mul_right [MulLeftReflectLE α] {a b : α} (h : a ≤ a * b) :
1 ≤ b :=
le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one]
@[to_additive]
theorem le_one_of_mul_le_right [MulLeftReflectLE α] {a b : α} (h : a * b ≤ a) :
b ≤ 1 :=
le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one]
@[to_additive]
| theorem one_le_of_le_mul_left [MulRightReflectLE α] {a b : α}
(h : b ≤ a * b) :
1 ≤ a :=
le_of_mul_le_mul_right' (a := b) <| by simpa only [one_mul]
| Mathlib/Algebra/Order/Monoid/Unbundled/Basic.lean | 442 | 445 |
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Topology.Algebra.Module.Basic
/-!
# Group and ring filter bases
A `GroupFilterBasis` is a `FilterBasis` on a group with some properties relating
the basis to the group structure. The main theorem is that a `GroupFilterBasis`
on a group gives a topology on the group which makes it into a topological group
with neighborhoods of the neutral element generated by the given basis.
## Main definitions and results
Given a group `G` and a ring `R`:
* `GroupFilterBasis G`: the type of filter bases that will become neighborhood of `1`
for a topology on `G` compatible with the group structure
* `GroupFilterBasis.topology`: the associated topology
* `GroupFilterBasis.isTopologicalGroup`: the compatibility between the above topology
and the group structure
* `RingFilterBasis R`: the type of filter bases that will become neighborhood of `0`
for a topology on `R` compatible with the ring structure
* `RingFilterBasis.topology`: the associated topology
* `RingFilterBasis.isTopologicalRing`: the compatibility between the above topology
and the ring structure
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
-/
open Filter Set TopologicalSpace Function
open Topology Filter Pointwise
universe u
/-- A `GroupFilterBasis` on a group is a `FilterBasis` satisfying some additional axioms.
Example : if `G` is a topological group then the neighbourhoods of the identity are a
`GroupFilterBasis`. Conversely given a `GroupFilterBasis` one can define a topology
compatible with the group structure on `G`. -/
class GroupFilterBasis (G : Type u) [Group G] extends FilterBasis G where
one' : ∀ {U}, U ∈ sets → (1 : G) ∈ U
mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U
inv' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U
conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U
/-- An `AddGroupFilterBasis` on an additive group is a `FilterBasis` satisfying some additional
axioms. Example : if `G` is a topological group then the neighbourhoods of the identity are an
`AddGroupFilterBasis`. Conversely given an `AddGroupFilterBasis` one can define a topology
compatible with the group structure on `G`. -/
class AddGroupFilterBasis (A : Type u) [AddGroup A] extends FilterBasis A where
zero' : ∀ {U}, U ∈ sets → (0 : A) ∈ U
add' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V + V ⊆ U
neg' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ -x) ⁻¹' U
conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ + x + -x₀) ⁻¹' U
attribute [to_additive existing] GroupFilterBasis GroupFilterBasis.conj'
GroupFilterBasis.toFilterBasis
/-- `GroupFilterBasis` constructor in the commutative group case. -/
@[to_additive "`AddGroupFilterBasis` constructor in the additive commutative group case."]
def groupFilterBasisOfComm {G : Type*} [CommGroup G] (sets : Set (Set G))
(nonempty : sets.Nonempty) (inter_sets : ∀ x y, x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y)
(one : ∀ U ∈ sets, (1 : G) ∈ U) (mul : ∀ U ∈ sets, ∃ V ∈ sets, V * V ⊆ U)
(inv : ∀ U ∈ sets, ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U) : GroupFilterBasis G :=
{ sets := sets
nonempty := nonempty
inter_sets := inter_sets _ _
one' := one _
mul' := mul _
inv' := inv _
conj' := fun x U U_in ↦ ⟨U, U_in, by simp only [mul_inv_cancel_comm, preimage_id']; rfl⟩ }
namespace GroupFilterBasis
variable {G : Type u} [Group G] {B : GroupFilterBasis G}
@[to_additive]
instance : Membership (Set G) (GroupFilterBasis G) :=
⟨fun f s ↦ s ∈ f.sets⟩
@[to_additive]
theorem one {U : Set G} : U ∈ B → (1 : G) ∈ U :=
GroupFilterBasis.one'
@[to_additive]
theorem mul {U : Set G} : U ∈ B → ∃ V ∈ B, V * V ⊆ U :=
GroupFilterBasis.mul'
@[to_additive]
theorem inv {U : Set G} : U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U :=
GroupFilterBasis.inv'
@[to_additive]
theorem conj : ∀ x₀, ∀ {U}, U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U :=
GroupFilterBasis.conj'
/-- The trivial group filter basis consists of `{1}` only. The associated topology
is discrete. -/
@[to_additive "The trivial additive group filter basis consists of `{0}` only. The associated
topology is discrete."]
instance : Inhabited (GroupFilterBasis G) where
default := {
sets := {{1}}
nonempty := singleton_nonempty _
inter_sets := by simp
one' := by simp
mul' := by simp
inv' := by simp
conj' := by simp }
@[to_additive]
theorem subset_mul_self (B : GroupFilterBasis G) {U : Set G} (h : U ∈ B) : U ⊆ U * U :=
fun x x_in ↦ ⟨1, one h, x, x_in, one_mul x⟩
/-- The neighborhood function of a `GroupFilterBasis`. -/
@[to_additive "The neighborhood function of an `AddGroupFilterBasis`."]
def N (B : GroupFilterBasis G) : G → Filter G :=
fun x ↦ map (fun y ↦ x * y) B.toFilterBasis.filter
@[to_additive (attr := simp)]
theorem N_one (B : GroupFilterBasis G) : B.N 1 = B.toFilterBasis.filter := by
simp only [N, one_mul, map_id']
@[to_additive]
protected theorem hasBasis (B : GroupFilterBasis G) (x : G) :
HasBasis (B.N x) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x * y) '' V :=
HasBasis.map (fun y ↦ x * y) toFilterBasis.hasBasis
/-- The topological space structure coming from a group filter basis. -/
@[to_additive "The topological space structure coming from an additive group filter basis."]
def topology (B : GroupFilterBasis G) : TopologicalSpace G :=
TopologicalSpace.mkOfNhds B.N
@[to_additive]
theorem nhds_eq (B : GroupFilterBasis G) {x₀ : G} : @nhds G B.topology x₀ = B.N x₀ := by
apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun x ↦ (FilterBasis.hasBasis _).map _)
· intro a U U_in
exact ⟨1, B.one U_in, mul_one a⟩
· intro a U U_in
rcases GroupFilterBasis.mul U_in with ⟨V, V_in, hVU⟩
filter_upwards [image_mem_map (B.mem_filter_of_mem V_in)]
rintro _ ⟨x, hx, rfl⟩
calc
(a * x) • V ∈ (a * x) • B.filter := smul_set_mem_smul_filter <| B.mem_filter_of_mem V_in
_ = a • x • V := smul_smul .. |>.symm
_ ⊆ a • (V * V) := smul_set_mono <| smul_set_subset_smul hx
_ ⊆ a • U := smul_set_mono hVU
@[to_additive]
theorem nhds_one_eq (B : GroupFilterBasis G) :
@nhds G B.topology (1 : G) = B.toFilterBasis.filter := by
rw [B.nhds_eq]
simp only [N, one_mul]
exact map_id
@[to_additive]
theorem nhds_hasBasis (B : GroupFilterBasis G) (x₀ : G) :
HasBasis (@nhds G B.topology x₀) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x₀ * y) '' V := by
rw [B.nhds_eq]
apply B.hasBasis
@[to_additive]
theorem nhds_one_hasBasis (B : GroupFilterBasis G) :
HasBasis (@nhds G B.topology 1) (fun V : Set G ↦ V ∈ B) id := by
rw [B.nhds_one_eq]
exact B.toFilterBasis.hasBasis
@[to_additive]
theorem mem_nhds_one (B : GroupFilterBasis G) {U : Set G} (hU : U ∈ B) :
U ∈ @nhds G B.topology 1 := by
rw [B.nhds_one_hasBasis.mem_iff]
exact ⟨U, hU, rfl.subset⟩
-- See note [lower instance priority]
/-- If a group is endowed with a topological structure coming from a group filter basis then it's a
topological group. -/
@[to_additive "If a group is endowed with a topological structure coming from a group filter basis
then it's a topological group."]
instance (priority := 100) isTopologicalGroup (B : GroupFilterBasis G) :
@IsTopologicalGroup G B.topology _ := by
letI := B.topology
have basis := B.nhds_one_hasBasis
have basis' := basis.prod basis
refine IsTopologicalGroup.of_nhds_one ?_ ?_ ?_ ?_
· rw [basis'.tendsto_iff basis]
suffices ∀ U ∈ B, ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa
intro U U_in
rcases mul U_in with ⟨V, V_in, hV⟩
refine ⟨V, V, ⟨V_in, V_in⟩, ?_⟩
intro a b a_in b_in
exact hV <| mul_mem_mul a_in b_in
· rw [basis.tendsto_iff basis]
intro U U_in
simpa using inv U_in
· intro x₀
rw [nhds_eq, nhds_one_eq]
rfl
· intro x₀
rw [basis.tendsto_iff basis]
intro U U_in
exact conj x₀ U_in
end GroupFilterBasis
/-- A `RingFilterBasis` on a ring is a `FilterBasis` satisfying some additional axioms.
Example : if `R` is a topological ring then the neighbourhoods of the identity are a
`RingFilterBasis`. Conversely given a `RingFilterBasis` on a ring `R`, one can define a
topology on `R` which is compatible with the ring structure. -/
class RingFilterBasis (R : Type u) [Ring R] extends AddGroupFilterBasis R where
mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U
mul_left' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x) ⁻¹' U
mul_right' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x * x₀) ⁻¹' U
namespace RingFilterBasis
variable {R : Type u} [Ring R] (B : RingFilterBasis R)
instance : Membership (Set R) (RingFilterBasis R) :=
⟨fun B s ↦ s ∈ B.sets⟩
theorem mul {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V * V ⊆ U :=
mul' hU
theorem mul_left (x₀ : R) {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x) ⁻¹' U :=
mul_left' x₀ hU
theorem mul_right (x₀ : R) {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x * x₀) ⁻¹' U :=
mul_right' x₀ hU
/-- The topology associated to a ring filter basis.
It has the given basis as a basis of neighborhoods of zero. -/
def topology : TopologicalSpace R :=
B.toAddGroupFilterBasis.topology
/-- If a ring is endowed with a topological structure coming from
a ring filter basis then it's a topological ring. -/
instance (priority := 100) isTopologicalRing {R : Type u} [Ring R] (B : RingFilterBasis R) :
@IsTopologicalRing R B.topology _ := by
let B' := B.toAddGroupFilterBasis
letI := B'.topology
have basis := B'.nhds_zero_hasBasis
have basis' := basis.prod basis
haveI := B'.isTopologicalAddGroup
apply IsTopologicalRing.of_addGroup_of_nhds_zero
· rw [basis'.tendsto_iff basis]
suffices ∀ U ∈ B', ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa
intro U U_in
rcases B.mul U_in with ⟨V, V_in, hV⟩
refine ⟨V, V, ⟨V_in, V_in⟩, ?_⟩
intro a b a_in b_in
exact hV <| mul_mem_mul a_in b_in
· intro x₀
rw [basis.tendsto_iff basis]
intro U
simpa using B.mul_left x₀
· intro x₀
rw [basis.tendsto_iff basis]
intro U
simpa using B.mul_right x₀
end RingFilterBasis
/-- A `ModuleFilterBasis` on a module is a `FilterBasis` satisfying some additional axioms.
Example : if `M` is a topological module then the neighbourhoods of zero are a
`ModuleFilterBasis`. Conversely given a `ModuleFilterBasis` one can define a topology
compatible with the module structure on `M`. -/
structure ModuleFilterBasis (R M : Type*) [CommRing R] [TopologicalSpace R] [AddCommGroup M]
[Module R M] extends AddGroupFilterBasis M where
smul' : ∀ {U}, U ∈ sets → ∃ V ∈ 𝓝 (0 : R), ∃ W ∈ sets, V • W ⊆ U
smul_left' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U
smul_right' : ∀ (m₀ : M) {U}, U ∈ sets → ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ U
namespace ModuleFilterBasis
variable {R M : Type*} [CommRing R] [TopologicalSpace R] [AddCommGroup M] [Module R M]
(B : ModuleFilterBasis R M)
instance GroupFilterBasis.hasMem : Membership (Set M) (ModuleFilterBasis R M) :=
⟨fun B s ↦ s ∈ B.sets⟩
theorem smul {U : Set M} (hU : U ∈ B) : ∃ V ∈ 𝓝 (0 : R), ∃ W ∈ B, V • W ⊆ U :=
B.smul' hU
theorem smul_left (x₀ : R) {U : Set M} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U :=
B.smul_left' x₀ hU
theorem smul_right (m₀ : M) {U : Set M} (hU : U ∈ B) : ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ U :=
B.smul_right' m₀ hU
/-- If `R` is discrete then the trivial additive group filter basis on any `R`-module is a
module filter basis. -/
instance [DiscreteTopology R] : Inhabited (ModuleFilterBasis R M) :=
⟨{
show AddGroupFilterBasis M from
default with
smul' := by
rintro U (rfl : U ∈ {{(0 : M)}})
use univ, univ_mem, {0}, rfl
rintro a ⟨x, -, m, rfl, rfl⟩
simp only [smul_zero, mem_singleton_iff]
smul_left' := by
rintro x₀ U (h : U ∈ {{(0 : M)}})
rw [mem_singleton_iff] at h
use {0}, rfl
simp [h]
smul_right' := by
rintro m₀ U (h : U ∈ (0 : Set (Set M)))
rw [Set.mem_zero] at h
simp [h, nhds_discrete] }⟩
/-- The topology associated to a module filter basis on a module over a topological ring.
It has the given basis as a basis of neighborhoods of zero. -/
def topology : TopologicalSpace M :=
B.toAddGroupFilterBasis.topology
/-- The topology associated to a module filter basis on a module over a topological ring.
It has the given basis as a basis of neighborhoods of zero. This version gets the ring
topology by unification instead of type class inference. -/
def topology' {R M : Type*} [CommRing R] {_ : TopologicalSpace R} [AddCommGroup M] [Module R M]
(B : ModuleFilterBasis R M) : TopologicalSpace M :=
B.toAddGroupFilterBasis.topology
/-- A topological add group with a basis of `𝓝 0` satisfying the axioms of `ModuleFilterBasis`
is a topological module.
This lemma is mathematically useless because one could obtain such a result by applying
`ModuleFilterBasis.continuousSMul` and use the fact that group topologies are characterized
by their neighborhoods of 0 to obtain the `ContinuousSMul` on the pre-existing topology.
But it turns out it's just easier to get it as a byproduct of the proof, so this is just a free
quality-of-life improvement. -/
theorem _root_.ContinuousSMul.of_basis_zero {ι : Type*} [IsTopologicalRing R] [TopologicalSpace M]
[IsTopologicalAddGroup M] {p : ι → Prop} {b : ι → Set M} (h : HasBasis (𝓝 0) p b)
(hsmul : ∀ {i}, p i → ∃ V ∈ 𝓝 (0 : R), ∃ j, p j ∧ V • b j ⊆ b i)
(hsmul_left : ∀ (x₀ : R) {i}, p i → ∃ j, p j ∧ MapsTo (x₀ • ·) (b j) (b i))
(hsmul_right : ∀ (m₀ : M) {i}, p i → ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ b i) : ContinuousSMul R M := by
apply ContinuousSMul.of_nhds_zero
· rw [h.tendsto_right_iff]
intro i hi
rcases hsmul hi with ⟨V, V_in, j, hj, hVj⟩
apply mem_of_superset (prod_mem_prod V_in <| h.mem_of_mem hj)
rintro ⟨v, w⟩ ⟨v_in : v ∈ V, w_in : w ∈ b j⟩
exact hVj (Set.smul_mem_smul v_in w_in)
· intro m₀
rw [h.tendsto_right_iff]
intro i hi
exact hsmul_right m₀ hi
· intro x₀
rw [h.tendsto_right_iff]
intro i hi
rcases hsmul_left x₀ hi with ⟨j, hj, hji⟩
exact mem_of_superset (h.mem_of_mem hj) hji
/-- If a module is endowed with a topological structure coming from
a module filter basis then it's a topological module. -/
instance (priority := 100) continuousSMul [IsTopologicalRing R] :
@ContinuousSMul R M _ _ B.topology := by
let B' := B.toAddGroupFilterBasis
let _ := B'.topology
have _ := B'.isTopologicalAddGroup
exact ContinuousSMul.of_basis_zero B'.nhds_zero_hasBasis
(fun {_} => by simpa using B.smul)
(by simpa using B.smul_left) B.smul_right
/-- Build a module filter basis from compatible ring and additive group filter bases. -/
def ofBases {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (BR : RingFilterBasis R)
(BM : AddGroupFilterBasis M) (smul : ∀ {U}, U ∈ BM → ∃ V ∈ BR, ∃ W ∈ BM, V • W ⊆ U)
(smul_left : ∀ (x₀ : R) {U}, U ∈ BM → ∃ V ∈ BM, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U)
(smul_right : ∀ (m₀ : M) {U}, U ∈ BM → ∃ V ∈ BR, V ⊆ (fun x ↦ x • m₀) ⁻¹' U) :
@ModuleFilterBasis R M _ BR.topology _ _ :=
let _ := BR.topology
{ BM with
smul' := by
intro U U_in
rcases smul U_in with ⟨V, V_in, W, W_in, H⟩
exact ⟨V, BR.toAddGroupFilterBasis.mem_nhds_zero V_in, W, W_in, H⟩
smul_left' := smul_left
smul_right' := by
intro m₀ U U_in
rcases smul_right m₀ U_in with ⟨V, V_in, H⟩
exact mem_of_superset (BR.toAddGroupFilterBasis.mem_nhds_zero V_in) H }
end ModuleFilterBasis
| Mathlib/Topology/Algebra/FilterBasis.lean | 393 | 413 | |
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import Mathlib.Algebra.Field.Subfield.Defs
import Mathlib.Algebra.Order.Group.Pointwise.Interval
import Mathlib.Analysis.Normed.Ring.Basic
/-!
# Normed division rings and fields
In this file we define normed fields, and (more generally) normed division rings. We also prove
some theorems about these definitions.
Some useful results that relate the topology of the normed field to the discrete topology include:
* `norm_eq_one_iff_ne_zero_of_discrete`
Methods for constructing a normed field instance from a given real absolute value on a field are
given in:
* AbsoluteValue.toNormedField
-/
-- Guard against import creep.
assert_not_exists AddChar comap_norm_atTop DilationEquiv Finset.sup_mul_le_mul_sup_of_nonneg
IsOfFinOrder Isometry.norm_map_of_map_one NNReal.isOpen_Ico_zero Rat.norm_cast_real
RestrictScalars
variable {G α β ι : Type*}
open Filter
open scoped Topology NNReal ENNReal
/-- A normed division ring is a division ring endowed with a seminorm which satisfies the equality
`‖x y‖ = ‖x‖ ‖y‖`. -/
class NormedDivisionRing (α : Type*) extends Norm α, DivisionRing α, MetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is multiplicative. -/
protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b
-- see Note [lower instance priority]
/-- A normed division ring is a normed ring. -/
instance (priority := 100) NormedDivisionRing.toNormedRing [β : NormedDivisionRing α] :
NormedRing α :=
{ β with norm_mul_le a b := (NormedDivisionRing.norm_mul a b).le }
-- see Note [lower instance priority]
/-- The norm on a normed division ring is strictly multiplicative. -/
instance (priority := 100) NormedDivisionRing.toNormMulClass [NormedDivisionRing α] :
NormMulClass α where
norm_mul := NormedDivisionRing.norm_mul
section NormedDivisionRing
variable [NormedDivisionRing α] {a b : α}
instance (priority := 900) NormedDivisionRing.to_normOneClass : NormOneClass α :=
⟨mul_left_cancel₀ (mt norm_eq_zero.1 (one_ne_zero' α)) <| by rw [← norm_mul, mul_one, mul_one]⟩
@[simp]
theorem norm_div (a b : α) : ‖a / b‖ = ‖a‖ / ‖b‖ :=
map_div₀ (normHom : α →*₀ ℝ) a b
@[simp]
theorem nnnorm_div (a b : α) : ‖a / b‖₊ = ‖a‖₊ / ‖b‖₊ :=
map_div₀ (nnnormHom : α →*₀ ℝ≥0) a b
@[simp]
theorem norm_inv (a : α) : ‖a⁻¹‖ = ‖a‖⁻¹ :=
map_inv₀ (normHom : α →*₀ ℝ) a
@[simp]
theorem nnnorm_inv (a : α) : ‖a⁻¹‖₊ = ‖a‖₊⁻¹ :=
NNReal.eq <| by simp
@[simp]
lemma enorm_inv {a : α} (ha : a ≠ 0) : ‖a⁻¹‖ₑ = ‖a‖ₑ⁻¹ := by simp [enorm, ENNReal.coe_inv, ha]
@[simp]
theorem norm_zpow : ∀ (a : α) (n : ℤ), ‖a ^ n‖ = ‖a‖ ^ n :=
map_zpow₀ (normHom : α →*₀ ℝ)
@[simp]
theorem nnnorm_zpow : ∀ (a : α) (n : ℤ), ‖a ^ n‖₊ = ‖a‖₊ ^ n :=
map_zpow₀ (nnnormHom : α →*₀ ℝ≥0)
theorem dist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) :
dist z⁻¹ w⁻¹ = dist z w / (‖z‖ * ‖w‖) := by
rw [dist_eq_norm, inv_sub_inv' hz hw, norm_mul, norm_mul, norm_inv, norm_inv, mul_comm ‖z‖⁻¹,
mul_assoc, dist_eq_norm', div_eq_mul_inv, mul_inv]
theorem nndist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) :
nndist z⁻¹ w⁻¹ = nndist z w / (‖z‖₊ * ‖w‖₊) :=
NNReal.eq <| dist_inv_inv₀ hz hw
lemma norm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) :
‖a * b * a⁻¹ * b⁻¹ - 1‖ ≤ 2 * ‖a‖⁻¹ * ‖b‖⁻¹ * ‖a - 1‖ * ‖b - 1‖ := by
simpa using norm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb)
lemma nnnorm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) :
‖a * b * a⁻¹ * b⁻¹ - 1‖₊ ≤ 2 * ‖a‖₊⁻¹ * ‖b‖₊⁻¹ * ‖a - 1‖₊ * ‖b - 1‖₊ := by
simpa using nnnorm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb)
namespace NormedDivisionRing
section Discrete
variable {𝕜 : Type*} [NormedDivisionRing 𝕜] [DiscreteTopology 𝕜]
lemma norm_eq_one_iff_ne_zero_of_discrete {x : 𝕜} : ‖x‖ = 1 ↔ x ≠ 0 := by
constructor <;> intro hx
· contrapose! hx
simp [hx]
· have : IsOpen {(0 : 𝕜)} := isOpen_discrete {0}
simp_rw [Metric.isOpen_singleton_iff, dist_eq_norm, sub_zero] at this
obtain ⟨ε, εpos, h'⟩ := this
wlog h : ‖x‖ < 1 generalizing 𝕜 with H
· push_neg at h
rcases h.eq_or_lt with h|h
· rw [h]
replace h := norm_inv x ▸ inv_lt_one_of_one_lt₀ h
rw [← inv_inj, inv_one, ← norm_inv]
exact H (by simpa) h' h
obtain ⟨k, hk⟩ : ∃ k : ℕ, ‖x‖ ^ k < ε := exists_pow_lt_of_lt_one εpos h
rw [← norm_pow] at hk
specialize h' _ hk
simp [hx] at h'
@[simp]
lemma norm_le_one_of_discrete
(x : 𝕜) : ‖x‖ ≤ 1 := by
rcases eq_or_ne x 0 with rfl|hx
· simp
· simp [norm_eq_one_iff_ne_zero_of_discrete.mpr hx]
lemma unitClosedBall_eq_univ_of_discrete : (Metric.closedBall 0 1 : Set 𝕜) = Set.univ := by
ext
simp
@[deprecated (since := "2024-12-01")]
alias discreteTopology_unit_closedBall_eq_univ := unitClosedBall_eq_univ_of_discrete
end Discrete
end NormedDivisionRing
end NormedDivisionRing
/-- A normed field is a field with a norm satisfying ‖x y‖ = ‖x‖ ‖y‖. -/
class NormedField (α : Type*) extends Norm α, Field α, MetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is multiplicative. -/
protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b
/-- A nontrivially normed field is a normed field in which there is an element of norm different
from `0` and `1`. This makes it possible to bring any element arbitrarily close to `0` by
multiplication by the powers of any element, and thus to relate algebra and topology. -/
class NontriviallyNormedField (α : Type*) extends NormedField α where
/-- The norm attains a value exceeding 1. -/
non_trivial : ∃ x : α, 1 < ‖x‖
/-- A densely normed field is a normed field for which the image of the norm is dense in `ℝ≥0`,
which means it is also nontrivially normed. However, not all nontrivally normed fields are densely
normed; in particular, the `Padic`s exhibit this fact. -/
class DenselyNormedField (α : Type*) extends NormedField α where
/-- The range of the norm is dense in the collection of nonnegative real numbers. -/
lt_norm_lt : ∀ x y : ℝ, 0 ≤ x → x < y → ∃ a : α, x < ‖a‖ ∧ ‖a‖ < y
section NormedField
/-- A densely normed field is always a nontrivially normed field.
See note [lower instance priority]. -/
instance (priority := 100) DenselyNormedField.toNontriviallyNormedField [DenselyNormedField α] :
NontriviallyNormedField α where
non_trivial :=
let ⟨a, h, _⟩ := DenselyNormedField.lt_norm_lt 1 2 zero_le_one one_lt_two
⟨a, h⟩
variable [NormedField α]
-- see Note [lower instance priority]
instance (priority := 100) NormedField.toNormedDivisionRing : NormedDivisionRing α :=
{ ‹NormedField α› with }
-- see Note [lower instance priority]
instance (priority := 100) NormedField.toNormedCommRing : NormedCommRing α :=
{ ‹NormedField α› with norm_mul_le a b := (norm_mul a b).le }
end NormedField
namespace NormedField
section Nontrivially
variable (α) [NontriviallyNormedField α]
theorem exists_one_lt_norm : ∃ x : α, 1 < ‖x‖ :=
‹NontriviallyNormedField α›.non_trivial
theorem exists_one_lt_nnnorm : ∃ x : α, 1 < ‖x‖₊ := exists_one_lt_norm α
theorem exists_one_lt_enorm : ∃ x : α, 1 < ‖x‖ₑ :=
exists_one_lt_nnnorm α |>.imp fun _ => ENNReal.coe_lt_coe.mpr
theorem exists_lt_norm (r : ℝ) : ∃ x : α, r < ‖x‖ :=
let ⟨w, hw⟩ := exists_one_lt_norm α
let ⟨n, hn⟩ := pow_unbounded_of_one_lt r hw
⟨w ^ n, by rwa [norm_pow]⟩
theorem exists_lt_nnnorm (r : ℝ≥0) : ∃ x : α, r < ‖x‖₊ := exists_lt_norm α r
theorem exists_lt_enorm {r : ℝ≥0∞} (hr : r ≠ ∞) : ∃ x : α, r < ‖x‖ₑ := by
lift r to ℝ≥0 using hr
exact mod_cast exists_lt_nnnorm α r
theorem exists_norm_lt {r : ℝ} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < r :=
let ⟨w, hw⟩ := exists_lt_norm α r⁻¹
⟨w⁻¹, by rwa [← Set.mem_Ioo, norm_inv, ← Set.mem_inv, Set.inv_Ioo_0_left hr]⟩
theorem exists_nnnorm_lt {r : ℝ≥0} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < r :=
exists_norm_lt α hr
/-- TODO: merge with `_root_.exists_enorm_lt`. -/
theorem exists_enorm_lt {r : ℝ≥0∞} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < r :=
match r with
| ∞ => exists_one_lt_enorm α |>.imp fun _ hx => ⟨zero_le_one.trans_lt hx, ENNReal.coe_lt_top⟩
| (r : ℝ≥0) => exists_nnnorm_lt α (ENNReal.coe_pos.mp hr) |>.imp fun _ =>
And.imp ENNReal.coe_pos.mpr ENNReal.coe_lt_coe.mpr
theorem exists_norm_lt_one : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < 1 :=
exists_norm_lt α one_pos
theorem exists_nnnorm_lt_one : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < 1 := exists_norm_lt_one _
theorem exists_enorm_lt_one : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < 1 := exists_enorm_lt _ one_pos
variable {α}
@[instance]
theorem nhdsNE_neBot (x : α) : NeBot (𝓝[≠] x) := by
rw [← mem_closure_iff_nhdsWithin_neBot, Metric.mem_closure_iff]
rintro ε ε0
rcases exists_norm_lt α ε0 with ⟨b, hb0, hbε⟩
refine ⟨x + b, mt (Set.mem_singleton_iff.trans add_eq_left).1 <| norm_pos_iff.1 hb0, ?_⟩
rwa [dist_comm, dist_eq_norm, add_sub_cancel_left]
@[deprecated (since := "2025-03-02")]
alias punctured_nhds_neBot := nhdsNE_neBot
@[instance]
theorem nhdsWithin_isUnit_neBot : NeBot (𝓝[{ x : α | IsUnit x }] 0) := by
simpa only [isUnit_iff_ne_zero] using nhdsNE_neBot (0 : α)
end Nontrivially
section Densely
variable (α) [DenselyNormedField α]
theorem exists_lt_norm_lt {r₁ r₂ : ℝ} (h₀ : 0 ≤ r₁) (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖ ∧ ‖x‖ < r₂ :=
DenselyNormedField.lt_norm_lt r₁ r₂ h₀ h
theorem exists_lt_nnnorm_lt {r₁ r₂ : ℝ≥0} (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖₊ ∧ ‖x‖₊ < r₂ :=
mod_cast exists_lt_norm_lt α r₁.prop h
instance denselyOrdered_range_norm : DenselyOrdered (Set.range (norm : α → ℝ)) where
dense := by
rintro ⟨-, x, rfl⟩ ⟨-, y, rfl⟩ hxy
let ⟨z, h⟩ := exists_lt_norm_lt α (norm_nonneg _) hxy
exact ⟨⟨‖z‖, z, rfl⟩, h⟩
instance denselyOrdered_range_nnnorm : DenselyOrdered (Set.range (nnnorm : α → ℝ≥0)) where
dense := by
rintro ⟨-, x, rfl⟩ ⟨-, y, rfl⟩ hxy
let ⟨z, h⟩ := exists_lt_nnnorm_lt α hxy
exact ⟨⟨‖z‖₊, z, rfl⟩, h⟩
end Densely
end NormedField
/-- A normed field is nontrivially normed
provided that the norm of some nonzero element is not one. -/
def NontriviallyNormedField.ofNormNeOne {𝕜 : Type*} [h' : NormedField 𝕜]
(h : ∃ x : 𝕜, x ≠ 0 ∧ ‖x‖ ≠ 1) : NontriviallyNormedField 𝕜 where
toNormedField := h'
non_trivial := by
rcases h with ⟨x, hx, hx1⟩
rcases hx1.lt_or_lt with hlt | hlt
· use x⁻¹
rw [norm_inv]
exact (one_lt_inv₀ (norm_pos_iff.2 hx)).2 hlt
· exact ⟨x, hlt⟩
noncomputable instance Real.normedField : NormedField ℝ :=
{ Real.normedAddCommGroup, Real.field with
norm_mul := abs_mul }
noncomputable instance Real.denselyNormedField : DenselyNormedField ℝ where
lt_norm_lt _ _ h₀ hr :=
let ⟨x, h⟩ := exists_between hr
⟨x, by rwa [Real.norm_eq_abs, abs_of_nonneg (h₀.trans h.1.le)]⟩
namespace Real
theorem toNNReal_mul_nnnorm {x : ℝ} (y : ℝ) (hx : 0 ≤ x) : x.toNNReal * ‖y‖₊ = ‖x * y‖₊ := by
ext
simp only [NNReal.coe_mul, nnnorm_mul, coe_nnnorm, Real.toNNReal_of_nonneg, norm_of_nonneg, hx,
NNReal.coe_mk]
theorem nnnorm_mul_toNNReal (x : ℝ) {y : ℝ} (hy : 0 ≤ y) : ‖x‖₊ * y.toNNReal = ‖x * y‖₊ := by
rw [mul_comm, mul_comm x, toNNReal_mul_nnnorm x hy]
end Real
/-! ### Induced normed structures -/
section Induced
variable {F : Type*} (R S : Type*) [FunLike F R S]
/-- An injective non-unital ring homomorphism from a `DivisionRing` to a `NormedRing` induces a
`NormedDivisionRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NormedDivisionRing.induced [DivisionRing R] [NormedDivisionRing S]
[NonUnitalRingHomClass F R S] (f : F) (hf : Function.Injective f) : NormedDivisionRing R :=
{ NormedAddCommGroup.induced R S f hf, ‹DivisionRing R› with
norm_mul x y := show ‖f _‖ = _ from (map_mul f x y).symm ▸ norm_mul (f x) (f y) }
/-- An injective non-unital ring homomorphism from a `Field` to a `NormedRing` induces a
`NormedField` structure on the domain.
See note [reducible non-instances] -/
abbrev NormedField.induced [Field R] [NormedField S] [NonUnitalRingHomClass F R S] (f : F)
(hf : Function.Injective f) : NormedField R :=
{ NormedDivisionRing.induced R S f hf with
mul_comm := mul_comm }
end Induced
namespace SubfieldClass
variable {S F : Type*} [SetLike S F]
/--
If `s` is a subfield of a normed field `F`, then `s` is equipped with an induced normed
field structure.
-/
instance toNormedField [NormedField F] [SubfieldClass S F] (s : S) : NormedField s :=
NormedField.induced s F (SubringClass.subtype s) Subtype.val_injective
end SubfieldClass
namespace AbsoluteValue
/-- A real absolute value on a field determines a `NormedField` structure. -/
noncomputable def toNormedField {K : Type*} [Field K] (v : AbsoluteValue K ℝ) : NormedField K where
toField := inferInstanceAs (Field K)
__ := v.toNormedRing
norm_mul := v.map_mul
end AbsoluteValue
| Mathlib/Analysis/Normed/Field/Basic.lean | 996 | 997 | |
/-
Copyright (c) 2020 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import Mathlib.Dynamics.Flow
import Mathlib.Tactic.Monotonicity
/-!
# ω-limits
For a function `ϕ : τ → α → β` where `β` is a topological space, we
define the ω-limit under `ϕ` of a set `s` in `α` with respect to
filter `f` on `τ`: an element `y : β` is in the ω-limit of `s` if the
forward images of `s` intersect arbitrarily small neighbourhoods of
`y` frequently "in the direction of `f`".
In practice `ϕ` is often a continuous monoid-act, but the definition
requires only that `ϕ` has a coercion to the appropriate function
type. In the case where `τ` is `ℕ` or `ℝ` and `f` is `atTop`, we
recover the usual definition of the ω-limit set as the set of all `y`
such that there exist sequences `(tₙ)`, `(xₙ)` such that `ϕ tₙ xₙ ⟶ y`
as `n ⟶ ∞`.
## Notations
The `omegaLimit` locale provides the localised notation `ω` for
`omegaLimit`, as well as `ω⁺` and `ω⁻` for `omegaLimit atTop` and
`omegaLimit atBot` respectively for when the acting monoid is
endowed with an order.
-/
open Set Function Filter Topology
/-!
### Definition and notation
-/
section omegaLimit
variable {τ : Type*} {α : Type*} {β : Type*} {ι : Type*}
/-- The ω-limit of a set `s` under `ϕ` with respect to a filter `f` is `⋂ u ∈ f, cl (ϕ u s)`. -/
def omegaLimit [TopologicalSpace β] (f : Filter τ) (ϕ : τ → α → β) (s : Set α) : Set β :=
⋂ u ∈ f, closure (image2 ϕ u s)
@[inherit_doc]
scoped[omegaLimit] notation "ω" => omegaLimit
/-- The ω-limit w.r.t. `Filter.atTop`. -/
scoped[omegaLimit] notation "ω⁺" => omegaLimit Filter.atTop
/-- The ω-limit w.r.t. `Filter.atBot`. -/
scoped[omegaLimit] notation "ω⁻" => omegaLimit Filter.atBot
variable [TopologicalSpace β]
variable (f : Filter τ) (ϕ : τ → α → β) (s s₁ s₂ : Set α)
/-!
### Elementary properties
-/
open omegaLimit
theorem omegaLimit_def : ω f ϕ s = ⋂ u ∈ f, closure (image2 ϕ u s) := rfl
theorem omegaLimit_subset_of_tendsto {m : τ → τ} {f₁ f₂ : Filter τ} (hf : Tendsto m f₁ f₂) :
ω f₁ (fun t x ↦ ϕ (m t) x) s ⊆ ω f₂ ϕ s := by
refine iInter₂_mono' fun u hu ↦ ⟨m ⁻¹' u, tendsto_def.mp hf _ hu, ?_⟩
rw [← image2_image_left]
exact closure_mono (image2_subset (image_preimage_subset _ _) Subset.rfl)
theorem omegaLimit_mono_left {f₁ f₂ : Filter τ} (hf : f₁ ≤ f₂) : ω f₁ ϕ s ⊆ ω f₂ ϕ s :=
omegaLimit_subset_of_tendsto ϕ s (tendsto_id'.2 hf)
theorem omegaLimit_mono_right {s₁ s₂ : Set α} (hs : s₁ ⊆ s₂) : ω f ϕ s₁ ⊆ ω f ϕ s₂ :=
iInter₂_mono fun _u _hu ↦ closure_mono (image2_subset Subset.rfl hs)
theorem isClosed_omegaLimit : IsClosed (ω f ϕ s) :=
isClosed_iInter fun _u ↦ isClosed_iInter fun _hu ↦ isClosed_closure
theorem mapsTo_omegaLimit' {α' β' : Type*} [TopologicalSpace β'] {f : Filter τ} {ϕ : τ → α → β}
{ϕ' : τ → α' → β'} {ga : α → α'} {s' : Set α'} (hs : MapsTo ga s s') {gb : β → β'}
(hg : ∀ᶠ t in f, EqOn (gb ∘ ϕ t) (ϕ' t ∘ ga) s) (hgc : Continuous gb) :
MapsTo gb (ω f ϕ s) (ω f ϕ' s') := by
simp only [omegaLimit_def, mem_iInter, MapsTo]
intro y hy u hu
refine map_mem_closure hgc (hy _ (inter_mem hu hg)) (forall_mem_image2.2 fun t ht x hx ↦ ?_)
calc
ϕ' t (ga x) ∈ image2 ϕ' u s' := mem_image2_of_mem ht.1 (hs hx)
_ = gb (ϕ t x) := ht.2 hx |>.symm
theorem mapsTo_omegaLimit {α' β' : Type*} [TopologicalSpace β'] {f : Filter τ} {ϕ : τ → α → β}
{ϕ' : τ → α' → β'} {ga : α → α'} {s' : Set α'} (hs : MapsTo ga s s') {gb : β → β'}
(hg : ∀ t x, gb (ϕ t x) = ϕ' t (ga x)) (hgc : Continuous gb) :
MapsTo gb (ω f ϕ s) (ω f ϕ' s') :=
mapsTo_omegaLimit' _ hs (Eventually.of_forall fun t x _hx ↦ hg t x) hgc
theorem omegaLimit_image_eq {α' : Type*} (ϕ : τ → α' → β) (f : Filter τ) (g : α → α') :
ω f ϕ (g '' s) = ω f (fun t x ↦ ϕ t (g x)) s := by simp only [omegaLimit, image2_image_right]
theorem omegaLimit_preimage_subset {α' : Type*} (ϕ : τ → α' → β) (s : Set α') (f : Filter τ)
(g : α → α') : ω f (fun t x ↦ ϕ t (g x)) (g ⁻¹' s) ⊆ ω f ϕ s :=
mapsTo_omegaLimit _ (mapsTo_preimage _ _) (fun _t _x ↦ rfl) continuous_id
/-!
### Equivalent definitions of the omega limit
The next few lemmas are various versions of the property
characterising ω-limits:
-/
/-- An element `y` is in the ω-limit set of `s` w.r.t. `f` if the
preimages of an arbitrary neighbourhood of `y` frequently
(w.r.t. `f`) intersects of `s`. -/
theorem mem_omegaLimit_iff_frequently (y : β) :
y ∈ ω f ϕ s ↔ ∀ n ∈ 𝓝 y, ∃ᶠ t in f, (s ∩ ϕ t ⁻¹' n).Nonempty := by
simp_rw [frequently_iff, omegaLimit_def, mem_iInter, mem_closure_iff_nhds]
constructor
· intro h _ hn _ hu
rcases h _ hu _ hn with ⟨_, _, _, ht, _, hx, rfl⟩
exact ⟨_, ht, _, hx, by rwa [mem_preimage]⟩
· intro h _ hu _ hn
rcases h _ hn hu with ⟨_, ht, _, hx, hϕtx⟩
exact ⟨_, hϕtx, _, ht, _, hx, rfl⟩
/-- An element `y` is in the ω-limit set of `s` w.r.t. `f` if the
forward images of `s` frequently (w.r.t. `f`) intersect arbitrary
neighbourhoods of `y`. -/
theorem mem_omegaLimit_iff_frequently₂ (y : β) :
y ∈ ω f ϕ s ↔ ∀ n ∈ 𝓝 y, ∃ᶠ t in f, (ϕ t '' s ∩ n).Nonempty := by
simp_rw [mem_omegaLimit_iff_frequently, image_inter_nonempty_iff]
/-- An element `y` is in the ω-limit of `x` w.r.t. `f` if the forward
images of `x` frequently (w.r.t. `f`) falls within an arbitrary
neighbourhood of `y`. -/
theorem mem_omegaLimit_singleton_iff_map_cluster_point (x : α) (y : β) :
y ∈ ω f ϕ {x} ↔ MapClusterPt y f fun t ↦ ϕ t x := by
simp_rw [mem_omegaLimit_iff_frequently, mapClusterPt_iff_frequently, singleton_inter_nonempty,
mem_preimage]
/-!
### Set operations and omega limits
-/
theorem omegaLimit_inter : ω f ϕ (s₁ ∩ s₂) ⊆ ω f ϕ s₁ ∩ ω f ϕ s₂ :=
subset_inter (omegaLimit_mono_right _ _ inter_subset_left)
(omegaLimit_mono_right _ _ inter_subset_right)
theorem omegaLimit_iInter (p : ι → Set α) : ω f ϕ (⋂ i, p i) ⊆ ⋂ i, ω f ϕ (p i) :=
subset_iInter fun _i ↦ omegaLimit_mono_right _ _ (iInter_subset _ _)
theorem omegaLimit_union : ω f ϕ (s₁ ∪ s₂) = ω f ϕ s₁ ∪ ω f ϕ s₂ := by
ext y; constructor
· simp only [mem_union, mem_omegaLimit_iff_frequently, union_inter_distrib_right, union_nonempty,
frequently_or_distrib]
contrapose!
simp only [not_frequently, not_nonempty_iff_eq_empty, ← subset_empty_iff]
rintro ⟨⟨n₁, hn₁, h₁⟩, ⟨n₂, hn₂, h₂⟩⟩
refine ⟨n₁ ∩ n₂, inter_mem hn₁ hn₂, h₁.mono fun t ↦ ?_, h₂.mono fun t ↦ ?_⟩
exacts [Subset.trans <| inter_subset_inter_right _ <| preimage_mono inter_subset_left,
Subset.trans <| inter_subset_inter_right _ <| preimage_mono inter_subset_right]
· rintro (hy | hy)
exacts [omegaLimit_mono_right _ _ subset_union_left hy,
omegaLimit_mono_right _ _ subset_union_right hy]
theorem omegaLimit_iUnion (p : ι → Set α) : ⋃ i, ω f ϕ (p i) ⊆ ω f ϕ (⋃ i, p i) := by
rw [iUnion_subset_iff]
exact fun i ↦ omegaLimit_mono_right _ _ (subset_iUnion _ _)
/-!
Different expressions for omega limits, useful for rewrites. In
particular, one may restrict the intersection to sets in `f` which are
subsets of some set `v` also in `f`.
-/
theorem omegaLimit_eq_iInter : ω f ϕ s = ⋂ u : ↥f.sets, closure (image2 ϕ u s) :=
biInter_eq_iInter _ _
theorem omegaLimit_eq_biInter_inter {v : Set τ} (hv : v ∈ f) :
ω f ϕ s = ⋂ u ∈ f, closure (image2 ϕ (u ∩ v) s) :=
Subset.antisymm (iInter₂_mono' fun u hu ↦ ⟨u ∩ v, inter_mem hu hv, Subset.rfl⟩)
(iInter₂_mono fun _u _hu ↦ closure_mono <| image2_subset inter_subset_left Subset.rfl)
theorem omegaLimit_eq_iInter_inter {v : Set τ} (hv : v ∈ f) :
ω f ϕ s = ⋂ u : ↥f.sets, closure (image2 ϕ (u ∩ v) s) := by
rw [omegaLimit_eq_biInter_inter _ _ _ hv]
apply biInter_eq_iInter
theorem omegaLimit_subset_closure_fw_image {u : Set τ} (hu : u ∈ f) :
ω f ϕ s ⊆ closure (image2 ϕ u s) := by
rw [omegaLimit_eq_iInter]
intro _ hx
rw [mem_iInter] at hx
exact hx ⟨u, hu⟩
-- An instance with better keys
instance : Inhabited f.sets := Filter.inhabitedMem
/-!
### ω-limits and compactness
-/
/-- A set is eventually carried into any open neighbourhood of its ω-limit:
if `c` is a compact set such that `closure {ϕ t x | t ∈ v, x ∈ s} ⊆ c` for some `v ∈ f`
and `n` is an open neighbourhood of `ω f ϕ s`, then for some `u ∈ f` we have
`closure {ϕ t x | t ∈ u, x ∈ s} ⊆ n`. -/
theorem eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset' {c : Set β}
(hc₁ : IsCompact c) (hc₂ : ∃ v ∈ f, closure (image2 ϕ v s) ⊆ c) {n : Set β} (hn₁ : IsOpen n)
(hn₂ : ω f ϕ s ⊆ n) : ∃ u ∈ f, closure (image2 ϕ u s) ⊆ n := by
rcases hc₂ with ⟨v, hv₁, hv₂⟩
let k := closure (image2 ϕ v s)
have hk : IsCompact (k \ n) :=
(hc₁.of_isClosed_subset isClosed_closure hv₂).diff hn₁
let j u := (closure (image2 ϕ (u ∩ v) s))ᶜ
have hj₁ : ∀ u ∈ f, IsOpen (j u) := fun _ _ ↦ isOpen_compl_iff.mpr isClosed_closure
have hj₂ : k \ n ⊆ ⋃ u ∈ f, j u := by
have : ⋃ u ∈ f, j u = ⋃ u : (↥f.sets), j u := biUnion_eq_iUnion _ _
rw [this, diff_subset_comm, diff_iUnion]
rw [omegaLimit_eq_iInter_inter _ _ _ hv₁] at hn₂
simp_rw [j, diff_compl]
rw [← inter_iInter]
exact Subset.trans inter_subset_right hn₂
rcases hk.elim_finite_subcover_image hj₁ hj₂ with ⟨g, hg₁ : ∀ u ∈ g, u ∈ f, hg₂, hg₃⟩
let w := (⋂ u ∈ g, u) ∩ v
have hw₂ : w ∈ f := by simpa [w, *]
have hw₃ : k \ n ⊆ (closure (image2 ϕ w s))ᶜ := by
apply Subset.trans hg₃
simp only [j, iUnion_subset_iff, compl_subset_compl]
intros u hu
unfold w
gcongr
refine iInter_subset_of_subset u (iInter_subset_of_subset hu ?_)
all_goals exact Subset.rfl
have hw₄ : kᶜ ⊆ (closure (image2 ϕ w s))ᶜ := by
simp only [compl_subset_compl]
exact closure_mono (image2_subset inter_subset_right Subset.rfl)
have hnc : nᶜ ⊆ k \ n ∪ kᶜ := by rw [union_comm, ← inter_subset, diff_eq, inter_comm]
have hw : closure (image2 ϕ w s) ⊆ n :=
compl_subset_compl.mp (Subset.trans hnc (union_subset hw₃ hw₄))
exact ⟨_, hw₂, hw⟩
/-- A set is eventually carried into any open neighbourhood of its ω-limit:
if `c` is a compact set such that `closure {ϕ t x | t ∈ v, x ∈ s} ⊆ c` for some `v ∈ f`
and `n` is an open neighbourhood of `ω f ϕ s`, then for some `u ∈ f` we have
`closure {ϕ t x | t ∈ u, x ∈ s} ⊆ n`. -/
theorem eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset [T2Space β]
{c : Set β} (hc₁ : IsCompact c) (hc₂ : ∀ᶠ t in f, MapsTo (ϕ t) s c) {n : Set β} (hn₁ : IsOpen n)
(hn₂ : ω f ϕ s ⊆ n) : ∃ u ∈ f, closure (image2 ϕ u s) ⊆ n :=
eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset' f ϕ _ hc₁
⟨_, hc₂, closure_minimal (image2_subset_iff.2 fun _t ↦ id) hc₁.isClosed⟩ hn₁ hn₂
theorem eventually_mapsTo_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset [T2Space β]
{c : Set β} (hc₁ : IsCompact c) (hc₂ : ∀ᶠ t in f, MapsTo (ϕ t) s c) {n : Set β} (hn₁ : IsOpen n)
(hn₂ : ω f ϕ s ⊆ n) : ∀ᶠ t in f, MapsTo (ϕ t) s n := by
rcases eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset f ϕ s hc₁
hc₂ hn₁ hn₂ with
⟨u, hu_mem, hu⟩
refine mem_of_superset hu_mem fun t ht x hx ↦ ?_
exact hu (subset_closure <| mem_image2_of_mem ht hx)
theorem eventually_closure_subset_of_isOpen_of_omegaLimit_subset [CompactSpace β] {v : Set β}
(hv₁ : IsOpen v) (hv₂ : ω f ϕ s ⊆ v) : ∃ u ∈ f, closure (image2 ϕ u s) ⊆ v :=
eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset' _ _ _
isCompact_univ ⟨univ, univ_mem, subset_univ _⟩ hv₁ hv₂
theorem eventually_mapsTo_of_isOpen_of_omegaLimit_subset [CompactSpace β] {v : Set β}
(hv₁ : IsOpen v) (hv₂ : ω f ϕ s ⊆ v) : ∀ᶠ t in f, MapsTo (ϕ t) s v := by
rcases eventually_closure_subset_of_isOpen_of_omegaLimit_subset f ϕ s hv₁ hv₂ with ⟨u, hu_mem, hu⟩
refine mem_of_superset hu_mem fun t ht x hx ↦ ?_
exact hu (subset_closure <| mem_image2_of_mem ht hx)
/-- The ω-limit of a nonempty set w.r.t. a nontrivial filter is nonempty. -/
theorem nonempty_omegaLimit_of_isCompact_absorbing [NeBot f] {c : Set β} (hc₁ : IsCompact c)
(hc₂ : ∃ v ∈ f, closure (image2 ϕ v s) ⊆ c) (hs : s.Nonempty) : (ω f ϕ s).Nonempty := by
rcases hc₂ with ⟨v, hv₁, hv₂⟩
rw [omegaLimit_eq_iInter_inter _ _ _ hv₁]
apply IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
· rintro ⟨u₁, hu₁⟩ ⟨u₂, hu₂⟩
use ⟨u₁ ∩ u₂, inter_mem hu₁ hu₂⟩
constructor
all_goals exact closure_mono (image2_subset (inter_subset_inter_left _ (by simp)) Subset.rfl)
· intro u
have hn : (image2 ϕ (u ∩ v) s).Nonempty :=
Nonempty.image2 (Filter.nonempty_of_mem (inter_mem u.prop hv₁)) hs
exact hn.mono subset_closure
· intro
apply hc₁.of_isClosed_subset isClosed_closure
calc
_ ⊆ closure (image2 ϕ v s) := closure_mono (image2_subset inter_subset_right Subset.rfl)
_ ⊆ c := hv₂
· exact fun _ ↦ isClosed_closure
theorem nonempty_omegaLimit [CompactSpace β] [NeBot f] (hs : s.Nonempty) : (ω f ϕ s).Nonempty :=
nonempty_omegaLimit_of_isCompact_absorbing _ _ _ isCompact_univ ⟨univ, univ_mem, subset_univ _⟩ hs
| end omegaLimit
/-!
### ω-limits of flows by a monoid
-/
namespace Flow
variable {τ : Type*} [TopologicalSpace τ] [AddMonoid τ] [ContinuousAdd τ] {α : Type*}
[TopologicalSpace α] (f : Filter τ) (ϕ : Flow τ α) (s : Set α)
open omegaLimit
theorem isInvariant_omegaLimit (hf : ∀ t, Tendsto (t + ·) f f) : IsInvariant ϕ (ω f ϕ s) := by
refine fun t ↦ MapsTo.mono_right ?_ (omegaLimit_subset_of_tendsto ϕ s (hf t))
exact
mapsTo_omegaLimit _ (mapsTo_id _) (fun t' x ↦ (ϕ.map_add _ _ _).symm)
(continuous_const.flow ϕ continuous_id)
theorem omegaLimit_image_subset (t : τ) (ht : Tendsto (· + t) f f) :
| Mathlib/Dynamics/OmegaLimit.lean | 296 | 314 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov
-/
import Mathlib.Data.Set.Prod
import Mathlib.Data.Set.Restrict
/-!
# Functions over sets
This file contains basic results on the following predicates of functions and sets:
* `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`;
* `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`;
* `Set.InjOn f s` : restriction of `f` to `s` is injective;
* `Set.SurjOn f s t` : every point in `s` has a preimage in `s`;
* `Set.BijOn f s t` : `f` is a bijection between `s` and `t`;
* `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`;
* `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`;
* `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e.
we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`.
-/
variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*}
open Equiv Equiv.Perm Function
namespace Set
/-! ### Equality on a set -/
section equality
variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α}
/-- This lemma exists for use by `aesop` as a forward rule. -/
@[aesop safe forward]
lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a :=
h ha
@[simp]
theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim
@[simp]
theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by
simp [Set.EqOn]
@[simp]
theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by
simp [EqOn, funext_iff]
@[symm]
theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm
theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s :=
⟨EqOn.symm, EqOn.symm⟩
-- This can not be tagged as `@[refl]` with the current argument order.
-- See note below at `EqOn.trans`.
theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl
-- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it
-- the `trans` tactic could not use it.
-- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute.
-- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`.
-- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581).
theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx =>
(h₁ hx).trans (h₂ hx)
theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s :=
image_congr heq
/-- Variant of `EqOn.image_eq`, for one function being the identity. -/
theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by
rw [h.image_eq, image_id]
theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t :=
ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx]
theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx)
@[simp]
theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ :=
forall₂_or_left
theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) :=
eqOn_union.2 ⟨h₁, h₂⟩
theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha =>
congr_arg _ <| h ha
@[simp]
theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} :
EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f :=
forall_mem_range.trans <| funext_iff.symm
alias ⟨EqOn.comp_eq, _⟩ := eqOn_range
end equality
variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ}
{f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β}
section MapsTo
theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t :=
image_subset_iff.symm
theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) :=
diagonal_subset_iff.2 fun _ => rfl
@[deprecated (since := "2025-04-18")]
alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal
theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf
theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl
@[simp]
theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t :=
singleton_subset_iff
theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t :=
empty_subset _
@[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by
simp [mapsTo', subset_empty_iff]
/-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/
theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty :=
(hs.image f).mono (mapsTo'.mp h)
theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t :=
mapsTo'.1 h
theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx =>
h hx ▸ h₁ hx
theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) :=
fun _ ha => hg <| hf ha
theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h =>
h₁ (h₂ h)
theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id
theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s
| 0 => fun _ => id
| n + 1 => (MapsTo.iterate h n).comp h
theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) :
(h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by
funext x
rw [Subtype.ext_iff, MapsTo.val_restrict_apply]
induction n generalizing x with
| zero => rfl
| succ n ihn => simp [Nat.iterate, ihn]
lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) :
MapsTo f s t :=
fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩
lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s :=
mapsTo_of_subsingleton' _ id
theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ :=
fun _ hx => ht (hf <| hs hx)
theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx =>
hf (hs hx)
theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx =>
ht (hf hx)
theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) :
MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx =>
hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx
theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t :=
union_self t ▸ h₁.union_union h₂
@[simp]
theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t :=
⟨fun h =>
⟨h.mono subset_union_left (Subset.refl t),
h.mono subset_union_right (Subset.refl t)⟩,
| fun h => h.1.union h.2⟩
| Mathlib/Data/Set/Function.lean | 190 | 191 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yaël Dillies
-/
import Mathlib.Algebra.Module.BigOperators
import Mathlib.GroupTheory.Perm.Basic
import Mathlib.GroupTheory.Perm.Finite
import Mathlib.GroupTheory.Perm.List
import Mathlib.GroupTheory.Perm.Sign
/-!
# Cycles of a permutation
This file starts the theory of cycles in permutations.
## Main definitions
In the following, `f : Equiv.Perm β`.
* `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`.
* `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated
applications of `f`, and `f` is not the identity.
* `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by
repeated applications of `f`.
## Notes
`Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways:
* `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set.
* `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton).
* `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them.
-/
open Equiv Function Finset
variable {ι α β : Type*}
namespace Equiv.Perm
/-! ### `SameCycle` -/
section SameCycle
variable {f g : Perm α} {p : α → Prop} {x y z : α}
/-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/
def SameCycle (f : Perm α) (x y : α) : Prop :=
∃ i : ℤ, (f ^ i) x = y
@[refl]
theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x :=
⟨0, rfl⟩
theorem SameCycle.rfl : SameCycle f x x :=
SameCycle.refl _ _
protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h]
@[symm]
theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ =>
⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩
theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x :=
⟨SameCycle.symm, SameCycle.symm⟩
@[trans]
theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z :=
fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩
variable (f) in
theorem SameCycle.equivalence : Equivalence (SameCycle f) :=
⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩
/-- The setoid defined by the `SameCycle` relation. -/
def SameCycle.setoid (f : Perm α) : Setoid α where
r := f.SameCycle
iseqv := SameCycle.equivalence f
@[simp]
theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle]
@[simp]
theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y :=
(Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle]
alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv
@[simp]
theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) :=
exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq]
theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by
simp [sameCycle_conj]
theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by
rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply,
(f ^ i).injective.eq_iff]
theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y :=
let ⟨_, hn⟩ := h
(hx.perm_zpow _).eq.symm.trans hn
theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y :=
h.eq_of_left <| h.apply_eq_self_iff.2 hy
@[simp]
theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y :=
(Equiv.addRight 1).exists_congr_left.trans <| by
simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp]
@[simp]
theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm]
@[simp]
theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by
rw [← sameCycle_apply_left, apply_inv_self]
@[simp]
theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by
rw [← sameCycle_apply_right, apply_inv_self]
@[simp]
theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y :=
(Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add]
@[simp]
theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm]
@[simp]
theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_left]
@[simp]
theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_right]
alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left
alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right
alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left
alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right
alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left
alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right
alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left
alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right
theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
@[simp]
theorem sameCycle_subtypePerm {h} {x y : { x // p x }} :
(f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y :=
exists_congr fun n => by simp [Subtype.ext_iff]
alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm
@[simp]
theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} :
SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y :=
exists_congr fun n => by
rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff]
alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain
theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by
rintro ⟨k, rfl⟩
use (k % orderOf f).natAbs
have h₀ := Int.natCast_pos.mpr (orderOf_pos f)
have h₁ := Int.emod_nonneg k h₀.ne'
rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf]
refine ⟨?_, by rfl⟩
rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁]
exact Int.emod_lt_of_pos _ h₀
theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by
obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq'
· refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩
rw [pow_orderOf_eq_one, pow_zero]
· exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩
theorem SameCycle.exists_fin_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : Fin (orderOf f), (f ^ (i : ℕ)) x = y := by
obtain ⟨i, hi, hx⟩ := SameCycle.exists_pow_eq' h
exact ⟨⟨i, hi⟩, hx⟩
theorem SameCycle.exists_nat_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, (f ^ i) x = y := by
obtain ⟨i, _, hi⟩ := h.exists_pow_eq'
exact ⟨i, hi⟩
instance (f : Perm α) [DecidableRel (SameCycle f)] :
DecidableRel (SameCycle f⁻¹) := fun x y =>
decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm
instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y =>
decidable_of_iff (x = y) sameCycle_one.symm
end SameCycle
/-!
### `IsCycle`
-/
section IsCycle
variable {f g : Perm α} {x y : α}
/-- A cycle is a non identity permutation where any two nonfixed points of the permutation are
related by repeated application of the permutation. -/
def IsCycle (f : Perm α) : Prop :=
∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y
theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h
@[simp]
theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl
protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
SameCycle f x y :=
let ⟨g, hg⟩ := hf
let ⟨a, ha⟩ := hg.2 hx
let ⟨b, hb⟩ := hg.2 hy
⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩
theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y :=
IsCycle.sameCycle
theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ :=
hf.imp fun _ ⟨hx, h⟩ =>
⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩
@[simp]
theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f :=
⟨fun h => h.inv, IsCycle.inv⟩
theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by
rintro ⟨x, hx, h⟩
refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩
rw [← apply_inv_self g y]
exact (h <| eq_inv_iff_eq.not.2 hy).conj
protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) :
IsCycle g → IsCycle (g.extendDomain f) := by
rintro ⟨a, ha, ha'⟩
refine ⟨f a, ?_, fun b hb => ?_⟩
· rw [extendDomain_apply_image]
exact Subtype.coe_injective.ne (f.injective.ne ha)
have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by
rw [apply_symm_apply, Subtype.coe_mk]
rw [h] at hb ⊢
simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb
exact (ha' hb).extendDomain
theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y :=
⟨fun hf y =>
⟨fun ⟨i, hi⟩ hy =>
hx <| by
rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi
rw [hi, hy],
hf.exists_zpow_eq hx⟩,
fun h => ⟨x, hx, fun _ hy => h.2 hy⟩⟩
section Finite
variable [Finite α]
theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
∃ i : ℕ, (f ^ i) x = y := by
let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy
classical exact
⟨(n % orderOf f).toNat, by
{have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f)))
rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩
end Finite
variable [DecidableEq α]
theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) :=
⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) =>
if hya : y = a then ⟨0, hya⟩
else
⟨1, by
rw [zpow_one, swap_apply_def]
split_ifs at * <;> tauto⟩⟩
protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by
rintro ⟨x, y, hxy, rfl⟩
exact isCycle_swap hxy
variable [Fintype α]
theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ #f.support :=
two_le_card_support_of_ne_one h.ne_one
/-- The subgroup generated by a cycle is in bijection with its support -/
noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) :
(Subgroup.zpowers σ) ≃ σ.support :=
Equiv.ofBijective
(fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) =>
⟨(τ : Perm α) (Classical.choose hσ), by
obtain ⟨τ, n, rfl⟩ := τ
rw [Subtype.coe_mk, zpow_apply_mem_support, mem_support]
exact (Classical.choose_spec hσ).1⟩)
(by
constructor
· rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h
ext y
by_cases hy : σ y = y
· simp_rw [zpow_apply_eq_self_of_apply_eq_self hy]
· obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy
rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i]
exact congr_arg _ (Subtype.ext_iff.mp h)
· rintro ⟨y, hy⟩
rw [mem_support] at hy
obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy
exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩)
@[simp]
theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} :
hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ =
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ :=
rfl
@[simp]
theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) :
hσ.zpowersEquivSupport.symm
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ =
⟨σ ^ n, n, rfl⟩ :=
(Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply
protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = #f.support := by
rw [← Fintype.card_zpowers, ← Fintype.card_coe]
convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf)
theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] :
∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
induction n with
| zero => exact fun _ h => ⟨0, h⟩
| succ n hn =>
intro b x f hb h
exact if hfbx : f x = b then ⟨0, hfbx⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ←
f.injective.eq_iff, apply_inv_self]
exact this.1
let ⟨i, hi⟩ := hn hb' (f.injective <| by
rw [apply_inv_self]; rwa [pow_succ', mul_apply] at h)
⟨i + 1, by
rw [add_comm, zpow_add, mul_apply, hi, zpow_one, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (Ne.symm hfbx)]⟩
theorem isCycle_swap_mul_aux₂ {α : Type*} [DecidableEq α] :
∀ (n : ℤ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
cases n with
| ofNat n => exact isCycle_swap_mul_aux₁ n
| negSucc n =>
intro b x f hb h
exact if hfbx' : f x = b then ⟨0, hfbx'⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, swap_apply_def]
split_ifs <;>
simp only [inv_eq_iff_eq, Perm.mul_apply, zpow_negSucc, Ne, Perm.apply_inv_self] at *
<;> tauto
let ⟨i, hi⟩ :=
isCycle_swap_mul_aux₁ n hb
(show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b by
rw [← zpow_natCast, ← h, ← mul_apply, ← mul_apply, ← mul_apply, zpow_negSucc,
← inv_pow, pow_succ, mul_assoc, mul_assoc, inv_mul_cancel, mul_one, zpow_natCast,
← pow_succ', ← pow_succ])
have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x := by
rw [mul_apply, inv_apply_self, swap_apply_left]
⟨-i, by
rw [← add_sub_cancel_right i 1, neg_sub, sub_eq_add_neg, zpow_add, zpow_one, zpow_neg,
← inv_zpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x,
zpow_add, zpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx')]⟩
theorem IsCycle.eq_swap_of_apply_apply_eq_self {α : Type*} [DecidableEq α] {f : Perm α}
(hf : IsCycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) :=
Equiv.ext fun y =>
let ⟨z, hz⟩ := hf
let ⟨i, hi⟩ := hz.2 hfx
if hyx : y = x then by simp [hyx]
else
if hfyx : y = f x then by simp [hfyx, hffx]
else by
rw [swap_apply_of_ne_of_ne hyx hfyx]
refine by_contradiction fun hy => ?_
obtain ⟨j, hj⟩ := hz.2 hy
rw [← sub_add_cancel j i, zpow_add, mul_apply, hi] at hj
rcases zpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji | hji
· rw [← hj, hji] at hyx
tauto
· rw [← hj, hji] at hfyx
tauto
theorem IsCycle.swap_mul {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α}
(hx : f x ≠ x) (hffx : f (f x) ≠ x) : IsCycle (swap x (f x) * f) :=
⟨f x, by simp [swap_apply_def, mul_apply, if_neg hffx, f.injective.eq_iff, if_neg hx, hx],
fun y hy =>
let ⟨i, hi⟩ := hf.exists_zpow_eq hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1
have hi : (f ^ (i - 1)) (f x) = y :=
calc
(f ^ (i - 1) : Perm α) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ) : Perm α) x := by simp
_ = y := by rwa [← zpow_add, sub_add_cancel]
isCycle_swap_mul_aux₂ (i - 1) hy hi⟩
theorem IsCycle.sign {f : Perm α} (hf : IsCycle f) : sign f = -(-1) ^ #f.support :=
let ⟨x, hx⟩ := hf
calc
Perm.sign f = Perm.sign (swap x (f x) * (swap x (f x) * f)) := by
{rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl]}
_ = -(-1) ^ #f.support :=
if h1 : f (f x) = x then by
have h : swap x (f x) * f = 1 := by
simp only [mul_def, one_def]
rw [hf.eq_swap_of_apply_apply_eq_self hx.1 h1, swap_apply_left, swap_swap]
rw [sign_mul, sign_swap hx.1.symm, h, sign_one,
hf.eq_swap_of_apply_apply_eq_self hx.1 h1, card_support_swap hx.1.symm]
rfl
else by
have h : #(swap x (f x) * f).support + 1 = #f.support := by
rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq _ _ h1,
card_insert_of_not_mem (not_mem_erase _ _), sdiff_singleton_eq_erase]
have : #(swap x (f x) * f).support < #f.support := card_support_swap_mul hx.1
rw [sign_mul, sign_swap hx.1.symm, (hf.swap_mul hx.1 h1).sign, ← h]
simp only [mul_neg, neg_mul, one_mul, neg_neg, pow_add, pow_one, mul_one]
termination_by #f.support
theorem IsCycle.of_pow {n : ℕ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
have key : ∀ x : α, (f ^ n) x ≠ x ↔ f x ≠ x := by
simp_rw [← mem_support, ← Finset.ext_iff]
exact (support_pow_le _ n).antisymm h2
obtain ⟨x, hx1, hx2⟩ := h1
refine ⟨x, (key x).mp hx1, fun y hy => ?_⟩
obtain ⟨i, _⟩ := hx2 ((key y).mpr hy)
exact ⟨n * i, by rwa [zpow_mul]⟩
-- The lemma `support_zpow_le` is relevant. It means that `h2` is equivalent to
-- `σ.support = (σ ^ n).support`, as well as to `#σ.support ≤ #(σ ^ n).support`.
theorem IsCycle.of_zpow {n : ℤ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
cases n
· exact h1.of_pow h2
· simp only [le_eq_subset, zpow_negSucc, Perm.support_inv] at h1 h2
exact (inv_inv (f ^ _) ▸ h1.inv).of_pow h2
theorem nodup_of_pairwise_disjoint_cycles {l : List (Perm β)} (h1 : ∀ f ∈ l, IsCycle f)
(h2 : l.Pairwise Disjoint) : l.Nodup :=
nodup_of_pairwise_disjoint (fun h => (h1 1 h).ne_one rfl) h2
/-- Unlike `support_congr`, which assumes that `∀ (x ∈ g.support), f x = g x)`, here
we have the weaker assumption that `∀ (x ∈ f.support), f x = g x`. -/
theorem IsCycle.support_congr (hf : IsCycle f) (hg : IsCycle g) (h : f.support ⊆ g.support)
(h' : ∀ x ∈ f.support, f x = g x) : f = g := by
have : f.support = g.support := by
refine le_antisymm h ?_
intro z hz
obtain ⟨x, hx, _⟩ := id hf
have hx' : g x ≠ x := by rwa [← h' x (mem_support.mpr hx)]
obtain ⟨m, hm⟩ := hg.exists_pow_eq hx' (mem_support.mp hz)
have h'' : ∀ x ∈ f.support ∩ g.support, f x = g x := by
intro x hx
exact h' x (mem_of_mem_inter_left hx)
rwa [← hm, ←
pow_eq_on_of_mem_support h'' _ x
(mem_inter_of_mem (mem_support.mpr hx) (mem_support.mpr hx')),
pow_apply_mem_support, mem_support]
refine Equiv.Perm.support_congr h ?_
simpa [← this] using h'
/-- If two cyclic permutations agree on all terms in their intersection,
and that intersection is not empty, then the two cyclic permutations must be equal. -/
theorem IsCycle.eq_on_support_inter_nonempty_congr (hf : IsCycle f) (hg : IsCycle g)
(h : ∀ x ∈ f.support ∩ g.support, f x = g x)
(hx : f x = g x) (hx' : x ∈ f.support) : f = g := by
have hx'' : x ∈ g.support := by rwa [mem_support, ← hx, ← mem_support]
have : f.support ⊆ g.support := by
intro y hy
obtain ⟨k, rfl⟩ := hf.exists_pow_eq (mem_support.mp hx') (mem_support.mp hy)
rwa [pow_eq_on_of_mem_support h _ _ (mem_inter_of_mem hx' hx''), pow_apply_mem_support]
rw [inter_eq_left.mpr this] at h
exact hf.support_congr hg this h
theorem IsCycle.support_pow_eq_iff (hf : IsCycle f) {n : ℕ} :
support (f ^ n) = support f ↔ ¬orderOf f ∣ n := by
rw [orderOf_dvd_iff_pow_eq_one]
constructor
· intro h H
refine hf.ne_one ?_
rw [← support_eq_empty_iff, ← h, H, support_one]
· intro H
apply le_antisymm (support_pow_le _ n) _
intro x hx
contrapose! H
ext z
by_cases hz : f z = z
· rw [pow_apply_eq_self_of_apply_eq_self hz, one_apply]
· obtain ⟨k, rfl⟩ := hf.exists_pow_eq hz (mem_support.mp hx)
apply (f ^ k).injective
rw [← mul_apply, (Commute.pow_pow_self _ _ _).eq, mul_apply]
simpa using H
theorem IsCycle.support_pow_of_pos_of_lt_orderOf (hf : IsCycle f) {n : ℕ} (npos : 0 < n)
(hn : n < orderOf f) : (f ^ n).support = f.support :=
hf.support_pow_eq_iff.2 <| Nat.not_dvd_of_pos_of_lt npos hn
theorem IsCycle.pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
IsCycle (f ^ n) ↔ n.Coprime (orderOf f) := by
classical
cases nonempty_fintype β
constructor
· intro h
have hr : support (f ^ n) = support f := by
rw [hf.support_pow_eq_iff]
rintro ⟨k, rfl⟩
refine h.ne_one ?_
simp [pow_mul, pow_orderOf_eq_one]
have : orderOf (f ^ n) = orderOf f := by rw [h.orderOf, hr, hf.orderOf]
rw [orderOf_pow, Nat.div_eq_self] at this
rcases this with h | _
· exact absurd h (orderOf_pos _).ne'
· rwa [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm]
· intro h
obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime h
have hf' : IsCycle ((f ^ n) ^ m) := by rwa [hm]
refine hf'.of_pow fun x hx => ?_
rw [hm]
exact support_pow_le _ n hx
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
f ^ n = 1 ↔ ∃ x, f x ≠ x ∧ (f ^ n) x = x := by
classical
cases nonempty_fintype β
constructor
· intro h
obtain ⟨x, hx, -⟩ := id hf
exact ⟨x, hx, by simp [h]⟩
· rintro ⟨x, hx, hx'⟩
by_cases h : support (f ^ n) = support f
· rw [← mem_support, ← h, mem_support] at hx
contradiction
· rw [hf.support_pow_eq_iff, Classical.not_not] at h
obtain ⟨k, rfl⟩ := h
rw [pow_mul, pow_orderOf_eq_one, one_pow]
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} {x : β}
(hx : f x ≠ x) : f ^ n = 1 ↔ (f ^ n) x = x :=
⟨fun h => DFunLike.congr_fun h x, fun h => hf.pow_eq_one_iff.2 ⟨x, hx, h⟩⟩
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff'' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
f ^ n = 1 ↔ ∀ x, f x ≠ x → (f ^ n) x = x :=
⟨fun h _ hx => (hf.pow_eq_one_iff' hx).1 h, fun h =>
let ⟨_, hx, _⟩ := id hf
(hf.pow_eq_one_iff' hx).2 (h _ hx)⟩
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {a b : ℕ} :
f ^ a = f ^ b ↔ ∃ x, f x ≠ x ∧ (f ^ a) x = (f ^ b) x := by
classical
cases nonempty_fintype β
constructor
· intro h
obtain ⟨x, hx, -⟩ := id hf
exact ⟨x, hx, by simp [h]⟩
· rintro ⟨x, hx, hx'⟩
wlog hab : a ≤ b generalizing a b
· exact (this hx'.symm (le_of_not_le hab)).symm
suffices f ^ (b - a) = 1 by
rw [pow_sub _ hab, mul_inv_eq_one] at this
rw [this]
rw [hf.pow_eq_one_iff]
by_cases hfa : (f ^ a) x ∈ f.support
· refine ⟨(f ^ a) x, mem_support.mp hfa, ?_⟩
simp only [pow_sub _ hab, Equiv.Perm.coe_mul, Function.comp_apply, inv_apply_self, ← hx']
· have h := @Equiv.Perm.zpow_apply_comm _ f 1 a x
simp only [zpow_one, zpow_natCast] at h
rw [not_mem_support, h, Function.Injective.eq_iff (f ^ a).injective] at hfa
contradiction
theorem IsCycle.isCycle_pow_pos_of_lt_prime_order [Finite β] {f : Perm β} (hf : IsCycle f)
(hf' : (orderOf f).Prime) (n : ℕ) (hn : 0 < n) (hn' : n < orderOf f) : IsCycle (f ^ n) := by
classical
cases nonempty_fintype β
have : n.Coprime (orderOf f) := by
refine Nat.Coprime.symm ?_
rw [Nat.Prime.coprime_iff_not_dvd hf']
exact Nat.not_dvd_of_pos_of_lt hn hn'
obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime this
have hf'' := hf
rw [← hm] at hf''
refine hf''.of_pow ?_
rw [hm]
exact support_pow_le f n
end IsCycle
open Equiv
theorem _root_.Int.addLeft_one_isCycle : (Equiv.addLeft 1 : Perm ℤ).IsCycle :=
⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩
theorem _root_.Int.addRight_one_isCycle : (Equiv.addRight 1 : Perm ℤ).IsCycle :=
⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩
section Conjugation
variable [Fintype α] [DecidableEq α] {σ τ : Perm α}
theorem IsCycle.isConj (hσ : IsCycle σ) (hτ : IsCycle τ) (h : #σ.support = #τ.support) :
IsConj σ τ := by
refine
isConj_of_support_equiv
(hσ.zpowersEquivSupport.symm.trans <|
(zpowersEquivZPowers <| by rw [hσ.orderOf, h, hτ.orderOf]).trans hτ.zpowersEquivSupport)
?_
| intro x hx
simp only [Perm.mul_apply, Equiv.trans_apply, Equiv.sumCongr_apply]
obtain ⟨n, rfl⟩ := hσ.exists_pow_eq (Classical.choose_spec hσ).1 (mem_support.1 hx)
simp [← Perm.mul_apply, ← pow_succ']
theorem IsCycle.isConj_iff (hσ : IsCycle σ) (hτ : IsCycle τ) :
IsConj σ τ ↔ #σ.support = #τ.support where
mp h := by
obtain ⟨π, rfl⟩ := (_root_.isConj_iff).1 h
refine Finset.card_bij (fun a _ => π a) (fun _ ha => ?_) (fun _ _ _ _ ab => π.injective ab)
fun b hb ↦ ⟨π⁻¹ b, ?_, π.apply_inv_self b⟩
· simp [mem_support.1 ha]
contrapose! hb
rw [mem_support, Classical.not_not] at hb
rw [mem_support, Classical.not_not, Perm.mul_apply, Perm.mul_apply, hb, Perm.apply_inv_self]
| Mathlib/GroupTheory/Perm/Cycle/Basic.lean | 648 | 662 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.Field.IsField
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.GroupTheory.MonoidLocalization.MonoidWithZero
import Mathlib.RingTheory.Localization.Defs
import Mathlib.RingTheory.OreLocalization.Ring
/-!
# Localizations of commutative rings
This file contains various basic results on localizations.
We characterize the localization of a commutative ring `R` at a submonoid `M` up to
isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a
ring homomorphism `f : R →+* S` satisfying 3 properties:
1. For all `y ∈ M`, `f y` is a unit;
2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`;
3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`.
(The converse is a consequence of 1.)
In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras
and `M, T` be submonoids of `R` and `P` respectively, e.g.:
```
variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q]
variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P)
```
## Main definitions
* `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q`
are isomorphic as `R`-algebras
## Implementation notes
In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one
structure with an isomorphic one; one way around this is to isolate a predicate characterizing
a structure up to isomorphism, and reason about things that satisfy the predicate.
A previous version of this file used a fully bundled type of ring localization maps,
then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the
`R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already
defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`,
we can ensure the localization map commutes nicely with other `algebraMap`s.
To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the
corresponding proof for the underlying `CommMonoid` localization map
`IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization`
and the namespace `Submonoid.LocalizationMap`.
To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas.
These show the quotient map `mk : R → M → Localization M` equals the surjection
`LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`.
The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file,
which are about the `LocalizationMap.mk'` induced by any localization map.
The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}`
is a field" is a `def` rather than an `instance`, so if you want to reason about a field of
fractions `K`, assume `[Field K]` instead of just `[CommRing K]`.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
assert_not_exists Ideal
open Function
namespace Localization
open IsLocalization
variable {ι : Type*} {R : ι → Type*} [∀ i, CommSemiring (R i)]
variable {i : ι} (S : Submonoid (R i))
/-- `IsLocalization.map` applied to a projection homomorphism from a product ring. -/
noncomputable abbrev mapPiEvalRingHom :
Localization (S.comap <| Pi.evalRingHom R i) →+* Localization S :=
map (T := S) _ (Pi.evalRingHom R i) le_rfl
open Function in
theorem mapPiEvalRingHom_bijective : Bijective (mapPiEvalRingHom S) := by
let T := S.comap (Pi.evalRingHom R i)
classical
refine ⟨fun x₁ x₂ eq ↦ ?_, fun x ↦ ?_⟩
· obtain ⟨r₁, s₁, rfl⟩ := mk'_surjective T x₁
obtain ⟨r₂, s₂, rfl⟩ := mk'_surjective T x₂
simp_rw [map_mk'] at eq
rw [IsLocalization.eq] at eq ⊢
obtain ⟨s, hs⟩ := eq
refine ⟨⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩, funext fun j ↦ ?_⟩
obtain rfl | ne := eq_or_ne j i
· simpa using hs
· simp [update_of_ne ne]
· obtain ⟨r, s, rfl⟩ := mk'_surjective S x
exact ⟨mk' (M := T) _ (update 0 i r) ⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩,
by simp [map_mk']⟩
end Localization
section CommSemiring
variable {R : Type*} [CommSemiring R] {M N : Submonoid R} {S : Type*} [CommSemiring S]
variable [Algebra R S] {P : Type*} [CommSemiring P]
namespace IsLocalization
section IsLocalization
variable [IsLocalization M S]
variable (M S) in
include M in
theorem linearMap_compatibleSMul (N₁ N₂) [AddCommMonoid N₁] [AddCommMonoid N₂] [Module R N₁]
[Module S N₁] [Module R N₂] [Module S N₂] [IsScalarTower R S N₁] [IsScalarTower R S N₂] :
LinearMap.CompatibleSMul N₁ N₂ S R where
map_smul f s s' := by
obtain ⟨r, m, rfl⟩ := mk'_surjective M s
rw [← (map_units S m).smul_left_cancel]
simp_rw [algebraMap_smul, ← map_smul, ← smul_assoc, smul_mk'_self, algebraMap_smul, map_smul]
variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y))
variable (M) in
include M in
-- This is not an instance since the submonoid `M` would become a metavariable in typeclass search.
theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) :=
⟨fun f g =>
AlgHom.coe_ringHom_injective <|
IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩
section AlgEquiv
variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q]
section
variable (M S Q)
/-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively,
there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/
@[simps!]
noncomputable def algEquiv : S ≃ₐ[R] Q :=
{ ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with
commutes' := ringEquivOfRingEquiv_eq _ }
end
theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by
simp
theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp
variable (M) in
include M in
protected lemma bijective (f : S →+* Q) (hf : f.comp (algebraMap R S) = algebraMap R Q) :
Function.Bijective f :=
(show f = IsLocalization.algEquiv M S Q by
apply IsLocalization.ringHom_ext M; rw [hf]; ext; simp) ▸
(IsLocalization.algEquiv M S Q).toEquiv.bijective
end AlgEquiv
section liftAlgHom
variable {A : Type*} [CommSemiring A]
{R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R}
{S : Type*} [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S]
{P : Type*} [CommSemiring P] [Algebra A P] [IsLocalization M S]
{f : R →ₐ[A] P} (hf : ∀ y : M, IsUnit (f y)) (x : S)
include hf
/-- `AlgHom` version of `IsLocalization.lift`. -/
noncomputable def liftAlgHom : S →ₐ[A] P where
__ := lift hf
commutes' r := show lift hf (algebraMap A S r) = _ by
simp [IsScalarTower.algebraMap_apply A R S]
theorem liftAlgHom_toRingHom : (liftAlgHom hf : S →ₐ[A] P).toRingHom = lift hf := rfl
@[simp]
theorem coe_liftAlgHom : ⇑(liftAlgHom hf : S →ₐ[A] P) = lift hf := rfl
theorem liftAlgHom_apply : liftAlgHom hf x = lift hf x := rfl
end liftAlgHom
section AlgEquivOfAlgEquiv
variable {A : Type*} [CommSemiring A]
{R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} (S : Type*)
[CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] [IsLocalization M S]
{P : Type*} [CommSemiring P] [Algebra A P] {T : Submonoid P} (Q : Type*)
[CommSemiring Q] [Algebra A Q] [Algebra P Q] [IsScalarTower A P Q] [IsLocalization T Q]
(h : R ≃ₐ[A] P) (H : Submonoid.map h M = T)
include H
/-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M`, `T` respectively,
an isomorphism `h : R ≃ₐ[A] P` such that `h(M) = T` induces an isomorphism of localizations
`S ≃ₐ[A] Q`. -/
@[simps!]
noncomputable def algEquivOfAlgEquiv : S ≃ₐ[A] Q where
__ := ringEquivOfRingEquiv S Q h.toRingEquiv H
commutes' _ := by dsimp; rw [IsScalarTower.algebraMap_apply A R S, map_eq,
RingHom.coe_coe, AlgEquiv.commutes, IsScalarTower.algebraMap_apply A P Q]
variable {S Q h}
theorem algEquivOfAlgEquiv_eq_map :
(algEquivOfAlgEquiv S Q h H : S →+* Q) =
map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) :=
rfl
theorem algEquivOfAlgEquiv_eq (x : R) :
algEquivOfAlgEquiv S Q h H ((algebraMap R S) x) = algebraMap P Q (h x) := by
simp
set_option linter.docPrime false in
theorem algEquivOfAlgEquiv_mk' (x : R) (y : M) :
algEquivOfAlgEquiv S Q h H (mk' S x y) =
mk' Q (h x) ⟨h y, show h y ∈ T from H ▸ Set.mem_image_of_mem h y.2⟩ := by
simp [map_mk']
theorem algEquivOfAlgEquiv_symm : (algEquivOfAlgEquiv S Q h H).symm =
algEquivOfAlgEquiv Q S h.symm (show Submonoid.map h.symm T = M by
rw [← H, ← Submonoid.map_coe_toMulEquiv, AlgEquiv.symm_toMulEquiv,
← Submonoid.comap_equiv_eq_map_symm, ← Submonoid.map_coe_toMulEquiv,
Submonoid.comap_map_eq_of_injective (h : R ≃* P).injective]) := rfl
end AlgEquivOfAlgEquiv
section at_units
variable (R M)
/-- The localization at a module of units is isomorphic to the ring. -/
noncomputable def atUnits (H : M ≤ IsUnit.submonoid R) : R ≃ₐ[R] S := by
refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩
· intro x y hxy
obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy
obtain ⟨u, hu⟩ := H c.prop
rwa [← hu, Units.mul_right_inj] at eq
· intro y
obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y
obtain ⟨u, hu⟩ := H s.prop
use x * u.inv
dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks]
rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul]
simp
end at_units
end IsLocalization
section
variable (M N)
theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) :
IsLocalization M P := by
constructor
· intro y
convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom
exact (h.commutes y).symm
· intro y
obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y)
apply_fun (show S → P from h) at e
simp only [map_mul, h.apply_symm_apply, h.commutes] at e
exact ⟨⟨x, s⟩, e⟩
· intro x y
rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ←
h.symm.commutes]
exact id
theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) :
IsLocalization M S ↔ IsLocalization M P :=
⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩
theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) :
IsLocalization M S ↔
haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P :=
letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra
isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl }
variable (S) in
/-- If an algebra is simultaneously localizations for two submonoids, then an arbitrary algebra
is a localization of one submonoid iff it is a localization of the other. -/
theorem isLocalization_iff_of_isLocalization [IsLocalization M S] [IsLocalization N S]
[Algebra R P] : IsLocalization M P ↔ IsLocalization N P :=
⟨fun _ ↦ isLocalization_of_algEquiv N (algEquiv M S P),
fun _ ↦ isLocalization_of_algEquiv M (algEquiv N S P)⟩
theorem iff_of_le_of_exists_dvd (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ n ∈ N, ∃ m ∈ M, n ∣ m) :
IsLocalization M S ↔ IsLocalization N S :=
have : IsLocalization N (Localization M) := of_le_of_exists_dvd _ _ h₁ h₂
isLocalization_iff_of_isLocalization _ _ (Localization M)
end
variable (M)
/-- If `S₁` is the localization of `R` at `M₁` and `S₂` is the localization of
`R` at `M₂`, then every localization `T` of `S₂` at `M₁` is also a localization of
`S₁` at `M₂`, in other words `M₁⁻¹M₂⁻¹R` can be identified with `M₂⁻¹M₁⁻¹R`. -/
lemma commutes (S₁ S₂ T : Type*) [CommSemiring S₁]
[CommSemiring S₂] [CommSemiring T] [Algebra R S₁] [Algebra R S₂] [Algebra R T] [Algebra S₁ T]
[Algebra S₂ T] [IsScalarTower R S₁ T] [IsScalarTower R S₂ T] (M₁ M₂ : Submonoid R)
[IsLocalization M₁ S₁] [IsLocalization M₂ S₂]
[IsLocalization (Algebra.algebraMapSubmonoid S₂ M₁) T] :
IsLocalization (Algebra.algebraMapSubmonoid S₁ M₂) T where
map_units' := by
rintro ⟨m, ⟨a, ha, rfl⟩⟩
rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T]
exact IsUnit.map _ (IsLocalization.map_units' ⟨a, ha⟩)
surj' a := by
obtain ⟨⟨y, -, m, hm, rfl⟩, hy⟩ := surj (M := Algebra.algebraMapSubmonoid S₂ M₁) a
rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₁ T] at hy
obtain ⟨⟨z, n, hn⟩, hz⟩ := IsLocalization.surj (M := M₂) y
have hunit : IsUnit (algebraMap R S₁ m) := map_units' ⟨m, hm⟩
use ⟨algebraMap R S₁ z * hunit.unit⁻¹, ⟨algebraMap R S₁ n, n, hn, rfl⟩⟩
rw [map_mul, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T]
conv_rhs => rw [← IsScalarTower.algebraMap_apply]
rw [IsScalarTower.algebraMap_apply R S₂ T, ← hz, map_mul, ← hy]
convert_to _ = a * (algebraMap S₂ T) ((algebraMap R S₂) n) *
(algebraMap S₁ T) (((algebraMap R S₁) m) * hunit.unit⁻¹.val)
· rw [map_mul]
ring
simp
exists_of_eq {x y} hxy := by
obtain ⟨r, s, d, hr, hs⟩ := IsLocalization.surj₂ M₁ S₁ x y
apply_fun (· * algebraMap S₁ T (algebraMap R S₁ d)) at hxy
simp_rw [← map_mul, hr, hs, ← IsScalarTower.algebraMap_apply,
IsScalarTower.algebraMap_apply R S₂ T] at hxy
obtain ⟨⟨-, c, hmc, rfl⟩, hc⟩ := exists_of_eq (M := Algebra.algebraMapSubmonoid S₂ M₁) hxy
simp_rw [← map_mul] at hc
obtain ⟨a, ha⟩ := IsLocalization.exists_of_eq (M := M₂) hc
use ⟨algebraMap R S₁ a, a, a.property, rfl⟩
apply (map_units S₁ d).mul_right_cancel
rw [mul_assoc, hr, mul_assoc, hs]
apply (map_units S₁ ⟨c, hmc⟩).mul_right_cancel
rw [← map_mul, ← map_mul, mul_assoc, mul_comm _ c, ha, map_mul, map_mul]
ring
end IsLocalization
namespace Localization
open IsLocalization
theorem mk_natCast (m : ℕ) : (mk m 1 : Localization M) = m := by
simpa using mk_algebraMap (R := R) (A := ℕ) _
variable [IsLocalization M S]
section
variable (S) (M)
/-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/
@[simps!]
noncomputable def algEquiv : Localization M ≃ₐ[R] S :=
IsLocalization.algEquiv M _ _
/-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/
noncomputable def _root_.IsLocalization.unique (R Rₘ) [CommSemiring R] [CommSemiring Rₘ]
(M : Submonoid R) [Subsingleton R] [Algebra R Rₘ] [IsLocalization M Rₘ] : Unique Rₘ :=
have : Inhabited Rₘ := ⟨1⟩
(algEquiv M Rₘ).symm.injective.unique
end
nonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y :=
algEquiv_mk' _ _
nonrec theorem algEquiv_symm_mk' (x : R) (y : M) :
(algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y :=
algEquiv_symm_mk' _ _
theorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk']
theorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by
rw [mk_eq_mk', algEquiv_symm_mk']
lemma coe_algEquiv :
(Localization.algEquiv M S : Localization M →+* S) =
IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl
lemma coe_algEquiv_symm :
((Localization.algEquiv M S).symm : S →+* Localization M) =
IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl
end Localization
end CommSemiring
section CommRing
variable {R : Type*} [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S]
variable [Algebra R S] {P : Type*} [CommRing P]
namespace Localization
theorem mk_intCast (m : ℤ) : (mk m 1 : Localization M) = m := by
simpa using mk_algebraMap (R := R) (A := ℤ) _
end Localization
open IsLocalization
/-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/
theorem IsField.localization_map_bijective {R Rₘ : Type*} [CommRing R] [CommRing Rₘ]
{M : Submonoid R} (hM : (0 : R) ∉ M) (hR : IsField R) [Algebra R Rₘ] [IsLocalization M Rₘ] :
Function.Bijective (algebraMap R Rₘ) := by
letI := hR.toField
replace hM := le_nonZeroDivisors_of_noZeroDivisors hM
refine ⟨IsLocalization.injective _ hM, fun x => ?_⟩
obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x
obtain ⟨n, hn⟩ := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm)
exact ⟨r * n, by rw [eq_mk'_iff_mul_eq, ← map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]⟩
/-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/
theorem Field.localization_map_bijective {K Kₘ : Type*} [Field K] [CommRing Kₘ] {M : Submonoid K}
(hM : (0 : K) ∉ M) [Algebra K Kₘ] [IsLocalization M Kₘ] :
Function.Bijective (algebraMap K Kₘ) :=
(Field.toIsField K).localization_map_bijective hM
-- this looks weird due to the `letI` inside the above lemma, but trying to do it the other
-- way round causes issues with defeq of instances, so this is actually easier.
section Algebra
variable {S} {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ]
variable [Algebra R Rₘ] [IsLocalization M Rₘ]
variable [Algebra S Sₘ] [i : IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ]
include S
section
|
variable (S M)
| Mathlib/RingTheory/Localization/Basic.lean | 442 | 443 |
/-
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]
| Mathlib/Data/Set/Prod.lean | 104 | 104 |
/-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Thickenings in pseudo-metric spaces
## Main definitions
* `Metric.thickening δ s`, the open thickening by radius `δ` of a set `s` in a pseudo emetric space.
* `Metric.cthickening δ s`, the closed thickening by radius `δ` of a set `s` in a pseudo emetric
space.
## Main results
* `Disjoint.exists_thickenings`: two disjoint sets admit disjoint thickenings
* `Disjoint.exists_cthickenings`: two disjoint sets admit disjoint closed thickenings
* `IsCompact.exists_cthickening_subset_open`: if `s` is compact, `t` is open and `s ⊆ t`,
some `cthickening` of `s` is contained in `t`.
* `Metric.hasBasis_nhdsSet_cthickening`: the `cthickening`s of a compact set `K` form a basis
of the neighbourhoods of `K`
* `Metric.closure_eq_iInter_cthickening'`: the closure of a set equals the intersection
of its closed thickenings of positive radii accumulating at zero.
The same holds for open thickenings.
* `IsCompact.cthickening_eq_biUnion_closedBall`: if `s` is compact, `cthickening δ s` is the union
of `closedBall`s of radius `δ` around `x : E`.
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Bornology
universe u v w
variable {ι : Sort*} {α : Type u}
namespace Metric
section Thickening
variable [PseudoEMetricSpace α] {δ : ℝ} {s : Set α} {x : α}
open EMetric
/-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a pseudo emetric space
consists of those points that are at distance less than `δ` from some point of `E`. -/
def thickening (δ : ℝ) (E : Set α) : Set α :=
{ x : α | infEdist x E < ENNReal.ofReal δ }
theorem mem_thickening_iff_infEdist_lt : x ∈ thickening δ s ↔ infEdist x s < ENNReal.ofReal δ :=
Iff.rfl
/-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the
(open) `δ`-thickening of `E` for small enough positive `δ`. -/
lemma eventually_not_mem_thickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) :
∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.thickening δ E := by
obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h
filter_upwards [eventually_lt_nhds ε_pos] with δ hδ
simp only [thickening, mem_setOf_eq, not_lt]
exact (ENNReal.ofReal_le_ofReal hδ.le).trans ε_lt.le
/-- The (open) thickening equals the preimage of an open interval under `EMetric.infEdist`. -/
theorem thickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) :
thickening δ E = (infEdist · E) ⁻¹' Iio (ENNReal.ofReal δ) :=
rfl
/-- The (open) thickening is an open set. -/
theorem isOpen_thickening {δ : ℝ} {E : Set α} : IsOpen (thickening δ E) :=
Continuous.isOpen_preimage continuous_infEdist _ isOpen_Iio
/-- The (open) thickening of the empty set is empty. -/
@[simp]
theorem thickening_empty (δ : ℝ) : thickening δ (∅ : Set α) = ∅ := by
simp only [thickening, setOf_false, infEdist_empty, not_top_lt]
theorem thickening_of_nonpos (hδ : δ ≤ 0) (s : Set α) : thickening δ s = ∅ :=
eq_empty_of_forall_not_mem fun _ => ((ENNReal.ofReal_of_nonpos hδ).trans_le bot_le).not_lt
/-- The (open) thickening `Metric.thickening δ E` of a fixed subset `E` is an increasing function of
the thickening radius `δ`. -/
@[gcongr]
theorem thickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
thickening δ₁ E ⊆ thickening δ₂ E :=
preimage_mono (Iio_subset_Iio (ENNReal.ofReal_le_ofReal hle))
/-- The (open) thickening `Metric.thickening δ E` with a fixed thickening radius `δ` is
an increasing function of the subset `E`. -/
theorem thickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) :
thickening δ E₁ ⊆ thickening δ E₂ := fun _ hx => lt_of_le_of_lt (infEdist_anti h) hx
theorem mem_thickening_iff_exists_edist_lt {δ : ℝ} (E : Set α) (x : α) :
x ∈ thickening δ E ↔ ∃ z ∈ E, edist x z < ENNReal.ofReal δ :=
infEdist_lt_iff
/-- The frontier of the (open) thickening of a set is contained in an `EMetric.infEdist` level
set. -/
theorem frontier_thickening_subset (E : Set α) {δ : ℝ} :
frontier (thickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } :=
frontier_lt_subset_eq continuous_infEdist continuous_const
open scoped Function in -- required for scoped `on` notation
theorem frontier_thickening_disjoint (A : Set α) :
Pairwise (Disjoint on fun r : ℝ => frontier (thickening r A)) := by
refine (pairwise_disjoint_on _).2 fun r₁ r₂ hr => ?_
rcases le_total r₁ 0 with h₁ | h₁
· simp [thickening_of_nonpos h₁]
refine ((disjoint_singleton.2 fun h => hr.ne ?_).preimage _).mono (frontier_thickening_subset _)
(frontier_thickening_subset _)
apply_fun ENNReal.toReal at h
rwa [ENNReal.toReal_ofReal h₁, ENNReal.toReal_ofReal (h₁.trans hr.le)] at h
/-- Any set is contained in the complement of the δ-thickening of the complement of its
δ-thickening. -/
lemma subset_compl_thickening_compl_thickening_self (δ : ℝ) (E : Set α) :
E ⊆ (thickening δ (thickening δ E)ᶜ)ᶜ := by
intro x x_in_E
simp only [thickening, mem_compl_iff, mem_setOf_eq, not_lt]
apply EMetric.le_infEdist.mpr fun y hy ↦ ?_
simp only [mem_compl_iff, mem_setOf_eq, not_lt] at hy
simpa only [edist_comm] using le_trans hy <| EMetric.infEdist_le_edist_of_mem x_in_E
/-- The δ-thickening of the complement of the δ-thickening of a set is contained in the complement
of the set. -/
lemma thickening_compl_thickening_self_subset_compl (δ : ℝ) (E : Set α) :
thickening δ (thickening δ E)ᶜ ⊆ Eᶜ := by
apply compl_subset_compl.mp
simpa only [compl_compl] using subset_compl_thickening_compl_thickening_self δ E
variable {X : Type u} [PseudoMetricSpace X]
theorem mem_thickening_iff_infDist_lt {E : Set X} {x : X} (h : E.Nonempty) :
x ∈ thickening δ E ↔ infDist x E < δ :=
lt_ofReal_iff_toReal_lt (infEdist_ne_top h)
/-- A point in a metric space belongs to the (open) `δ`-thickening of a subset `E` if and only if
it is at distance less than `δ` from some point of `E`. -/
theorem mem_thickening_iff {E : Set X} {x : X} : x ∈ thickening δ E ↔ ∃ z ∈ E, dist x z < δ := by
have key_iff : ∀ z : X, edist x z < ENNReal.ofReal δ ↔ dist x z < δ := fun z ↦ by
rw [dist_edist, lt_ofReal_iff_toReal_lt (edist_ne_top _ _)]
simp_rw [mem_thickening_iff_exists_edist_lt, key_iff]
@[simp]
theorem thickening_singleton (δ : ℝ) (x : X) : thickening δ ({x} : Set X) = ball x δ := by
ext
simp [mem_thickening_iff]
theorem ball_subset_thickening {x : X} {E : Set X} (hx : x ∈ E) (δ : ℝ) :
ball x δ ⊆ thickening δ E :=
Subset.trans (by simp [Subset.rfl]) (thickening_subset_of_subset δ <| singleton_subset_iff.mpr hx)
/-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a metric space equals the
union of balls of radius `δ` centered at points of `E`. -/
theorem thickening_eq_biUnion_ball {δ : ℝ} {E : Set X} : thickening δ E = ⋃ x ∈ E, ball x δ := by
ext x
simp only [mem_iUnion₂, exists_prop]
exact mem_thickening_iff
protected theorem _root_.Bornology.IsBounded.thickening {δ : ℝ} {E : Set X} (h : IsBounded E) :
IsBounded (thickening δ E) := by
rcases E.eq_empty_or_nonempty with rfl | ⟨x, hx⟩
· simp
· refine (isBounded_iff_subset_closedBall x).2 ⟨δ + diam E, fun y hy ↦ ?_⟩
calc
dist y x ≤ infDist y E + diam E := dist_le_infDist_add_diam (x := y) h hx
_ ≤ δ + diam E := add_le_add_right ((mem_thickening_iff_infDist_lt ⟨x, hx⟩).1 hy).le _
end Thickening
section Cthickening
variable [PseudoEMetricSpace α] {δ ε : ℝ} {s t : Set α} {x : α}
open EMetric
/-- The closed `δ`-thickening `Metric.cthickening δ E` of a subset `E` in a pseudo emetric space
consists of those points that are at infimum distance at most `δ` from `E`. -/
def cthickening (δ : ℝ) (E : Set α) : Set α :=
{ x : α | infEdist x E ≤ ENNReal.ofReal δ }
@[simp]
theorem mem_cthickening_iff : x ∈ cthickening δ s ↔ infEdist x s ≤ ENNReal.ofReal δ :=
Iff.rfl
/-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the
closed `δ`-thickening of `E` for small enough positive `δ`. -/
lemma eventually_not_mem_cthickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) :
∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.cthickening δ E := by
obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h
filter_upwards [eventually_lt_nhds ε_pos] with δ hδ
simp only [cthickening, mem_setOf_eq, not_le]
exact ((ofReal_lt_ofReal_iff ε_pos).mpr hδ).trans ε_lt
theorem mem_cthickening_of_edist_le (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E)
(h' : edist x y ≤ ENNReal.ofReal δ) : x ∈ cthickening δ E :=
(infEdist_le_edist_of_mem h).trans h'
theorem mem_cthickening_of_dist_le {α : Type*} [PseudoMetricSpace α] (x y : α) (δ : ℝ) (E : Set α)
(h : y ∈ E) (h' : dist x y ≤ δ) : x ∈ cthickening δ E := by
apply mem_cthickening_of_edist_le x y δ E h
rw [edist_dist]
exact ENNReal.ofReal_le_ofReal h'
theorem cthickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) :
cthickening δ E = (fun x => infEdist x E) ⁻¹' Iic (ENNReal.ofReal δ) :=
rfl
/-- The closed thickening is a closed set. -/
theorem isClosed_cthickening {δ : ℝ} {E : Set α} : IsClosed (cthickening δ E) :=
IsClosed.preimage continuous_infEdist isClosed_Iic
/-- The closed thickening of the empty set is empty. -/
@[simp]
theorem cthickening_empty (δ : ℝ) : cthickening δ (∅ : Set α) = ∅ := by
simp only [cthickening, ENNReal.ofReal_ne_top, setOf_false, infEdist_empty, top_le_iff]
theorem cthickening_of_nonpos {δ : ℝ} (hδ : δ ≤ 0) (E : Set α) : cthickening δ E = closure E := by
ext x
simp [mem_closure_iff_infEdist_zero, cthickening, ENNReal.ofReal_eq_zero.2 hδ]
/-- The closed thickening with radius zero is the closure of the set. -/
@[simp]
theorem cthickening_zero (E : Set α) : cthickening 0 E = closure E :=
cthickening_of_nonpos le_rfl E
theorem cthickening_max_zero (δ : ℝ) (E : Set α) : cthickening (max 0 δ) E = cthickening δ E := by
cases le_total δ 0 <;> simp [cthickening_of_nonpos, *]
/-- The closed thickening `Metric.cthickening δ E` of a fixed subset `E` is an increasing function
of the thickening radius `δ`. -/
theorem cthickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
cthickening δ₁ E ⊆ cthickening δ₂ E :=
preimage_mono (Iic_subset_Iic.mpr (ENNReal.ofReal_le_ofReal hle))
@[simp]
theorem cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) {δ : ℝ} (hδ : 0 ≤ δ) :
cthickening δ ({x} : Set α) = closedBall x δ := by
ext y
simp [cthickening, edist_dist, ENNReal.ofReal_le_ofReal_iff hδ]
theorem closedBall_subset_cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) (δ : ℝ) :
closedBall x δ ⊆ cthickening δ ({x} : Set α) := by
rcases lt_or_le δ 0 with (hδ | hδ)
· simp only [closedBall_eq_empty.mpr hδ, empty_subset]
· simp only [cthickening_singleton x hδ, Subset.rfl]
/-- The closed thickening `Metric.cthickening δ E` with a fixed thickening radius `δ` is
an increasing function of the subset `E`. -/
theorem cthickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) :
cthickening δ E₁ ⊆ cthickening δ E₂ := fun _ hx => le_trans (infEdist_anti h) hx
theorem cthickening_subset_thickening {δ₁ : ℝ≥0} {δ₂ : ℝ} (hlt : (δ₁ : ℝ) < δ₂) (E : Set α) :
cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx =>
hx.out.trans_lt ((ENNReal.ofReal_lt_ofReal_iff (lt_of_le_of_lt δ₁.prop hlt)).mpr hlt)
/-- The closed thickening `Metric.cthickening δ₁ E` is contained in the open thickening
`Metric.thickening δ₂ E` if the radius of the latter is positive and larger. -/
theorem cthickening_subset_thickening' {δ₁ δ₂ : ℝ} (δ₂_pos : 0 < δ₂) (hlt : δ₁ < δ₂) (E : Set α) :
cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx =>
lt_of_le_of_lt hx.out ((ENNReal.ofReal_lt_ofReal_iff δ₂_pos).mpr hlt)
/-- The open thickening `Metric.thickening δ E` is contained in the closed thickening
`Metric.cthickening δ E` with the same radius. -/
theorem thickening_subset_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ cthickening δ E := by
intro x hx
rw [thickening, mem_setOf_eq] at hx
exact hx.le
theorem thickening_subset_cthickening_of_le {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
thickening δ₁ E ⊆ cthickening δ₂ E :=
(thickening_subset_cthickening δ₁ E).trans (cthickening_mono hle E)
theorem _root_.Bornology.IsBounded.cthickening {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α}
(h : IsBounded E) : IsBounded (cthickening δ E) := by
have : IsBounded (thickening (max (δ + 1) 1) E) := h.thickening
apply this.subset
exact cthickening_subset_thickening' (zero_lt_one.trans_le (le_max_right _ _))
((lt_add_one _).trans_le (le_max_left _ _)) _
protected theorem _root_.IsCompact.cthickening
{α : Type*} [PseudoMetricSpace α] [ProperSpace α] {s : Set α}
(hs : IsCompact s) {r : ℝ} : IsCompact (cthickening r s) :=
isCompact_of_isClosed_isBounded isClosed_cthickening hs.isBounded.cthickening
theorem thickening_subset_interior_cthickening (δ : ℝ) (E : Set α) :
thickening δ E ⊆ interior (cthickening δ E) :=
(subset_interior_iff_isOpen.mpr isOpen_thickening).trans
(interior_mono (thickening_subset_cthickening δ E))
theorem closure_thickening_subset_cthickening (δ : ℝ) (E : Set α) :
closure (thickening δ E) ⊆ cthickening δ E :=
(closure_mono (thickening_subset_cthickening δ E)).trans isClosed_cthickening.closure_subset
/-- The closed thickening of a set contains the closure of the set. -/
theorem closure_subset_cthickening (δ : ℝ) (E : Set α) : closure E ⊆ cthickening δ E := by
rw [← cthickening_of_nonpos (min_le_right δ 0)]
exact cthickening_mono (min_le_left δ 0) E
/-- The (open) thickening of a set contains the closure of the set. -/
theorem closure_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) :
closure E ⊆ thickening δ E := by
rw [← cthickening_zero]
exact cthickening_subset_thickening' δ_pos δ_pos E
/-- A set is contained in its own (open) thickening. -/
theorem self_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : E ⊆ thickening δ E :=
(@subset_closure _ _ E).trans (closure_subset_thickening δ_pos E)
/-- A set is contained in its own closed thickening. -/
theorem self_subset_cthickening {δ : ℝ} (E : Set α) : E ⊆ cthickening δ E :=
subset_closure.trans (closure_subset_cthickening δ E)
theorem thickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : thickening δ E ∈ 𝓝ˢ E :=
isOpen_thickening.mem_nhdsSet.2 <| self_subset_thickening hδ E
theorem cthickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : cthickening δ E ∈ 𝓝ˢ E :=
mem_of_superset (thickening_mem_nhdsSet E hδ) (thickening_subset_cthickening _ _)
@[simp]
theorem thickening_union (δ : ℝ) (s t : Set α) :
thickening δ (s ∪ t) = thickening δ s ∪ thickening δ t := by
simp_rw [thickening, infEdist_union, min_lt_iff, setOf_or]
@[simp]
theorem cthickening_union (δ : ℝ) (s t : Set α) :
cthickening δ (s ∪ t) = cthickening δ s ∪ cthickening δ t := by
simp_rw [cthickening, infEdist_union, min_le_iff, setOf_or]
@[simp]
theorem thickening_iUnion (δ : ℝ) (f : ι → Set α) :
thickening δ (⋃ i, f i) = ⋃ i, thickening δ (f i) := by
simp_rw [thickening, infEdist_iUnion, iInf_lt_iff, setOf_exists]
lemma thickening_biUnion {ι : Type*} (δ : ℝ) (f : ι → Set α) (I : Set ι) :
thickening δ (⋃ i ∈ I, f i) = ⋃ i ∈ I, thickening δ (f i) := by simp only [thickening_iUnion]
theorem ediam_cthickening_le (ε : ℝ≥0) :
EMetric.diam (cthickening ε s) ≤ EMetric.diam s + 2 * ε := by
refine diam_le fun x hx y hy => ENNReal.le_of_forall_pos_le_add fun δ hδ _ => ?_
rw [mem_cthickening_iff, ENNReal.ofReal_coe_nnreal] at hx hy
have hε : (ε : ℝ≥0∞) < ε + δ := ENNReal.coe_lt_coe.2 (lt_add_of_pos_right _ hδ)
replace hx := hx.trans_lt hε
obtain ⟨x', hx', hxx'⟩ := infEdist_lt_iff.mp hx
calc
edist x y ≤ edist x x' + edist y x' := edist_triangle_right _ _ _
_ ≤ ε + δ + (infEdist y s + EMetric.diam s) :=
add_le_add hxx'.le (edist_le_infEdist_add_ediam hx')
_ ≤ ε + δ + (ε + EMetric.diam s) := add_le_add_left (add_le_add_right hy _) _
_ = _ := by rw [two_mul]; ac_rfl
theorem ediam_thickening_le (ε : ℝ≥0) : EMetric.diam (thickening ε s) ≤ EMetric.diam s + 2 * ε :=
(EMetric.diam_mono <| thickening_subset_cthickening _ _).trans <| ediam_cthickening_le _
theorem diam_cthickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) :
diam (cthickening ε s) ≤ diam s + 2 * ε := by
lift ε to ℝ≥0 using hε
refine (toReal_le_add' (ediam_cthickening_le _) ?_ ?_).trans_eq ?_
· exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono (self_subset_cthickening _)
· simp [mul_eq_top]
· simp [diam]
theorem diam_thickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) :
diam (thickening ε s) ≤ diam s + 2 * ε := by
by_cases hs : IsBounded s
· exact (diam_mono (thickening_subset_cthickening _ _) hs.cthickening).trans
(diam_cthickening_le _ hε)
obtain rfl | hε := hε.eq_or_lt
· simp [thickening_of_nonpos, diam_nonneg]
· rw [diam_eq_zero_of_unbounded (mt (IsBounded.subset · <| self_subset_thickening hε _) hs)]
positivity
@[simp]
theorem thickening_closure : thickening δ (closure s) = thickening δ s := by
simp_rw [thickening, infEdist_closure]
@[simp]
theorem cthickening_closure : cthickening δ (closure s) = cthickening δ s := by
simp_rw [cthickening, infEdist_closure]
open ENNReal
theorem _root_.Disjoint.exists_thickenings (hst : Disjoint s t) (hs : IsCompact s)
(ht : IsClosed t) :
∃ δ, 0 < δ ∧ Disjoint (thickening δ s) (thickening δ t) := by
obtain ⟨r, hr, h⟩ := exists_pos_forall_lt_edist hs ht hst
refine ⟨r / 2, half_pos (NNReal.coe_pos.2 hr), ?_⟩
rw [disjoint_iff_inf_le]
rintro z ⟨hzs, hzt⟩
rw [mem_thickening_iff_exists_edist_lt] at hzs hzt
rw [← NNReal.coe_two, ← NNReal.coe_div, ENNReal.ofReal_coe_nnreal] at hzs hzt
obtain ⟨x, hx, hzx⟩ := hzs
obtain ⟨y, hy, hzy⟩ := hzt
refine (h x hx y hy).not_le ?_
calc
edist x y ≤ edist z x + edist z y := edist_triangle_left _ _ _
_ ≤ ↑(r / 2) + ↑(r / 2) := add_le_add hzx.le hzy.le
_ = r := by rw [← ENNReal.coe_add, add_halves]
theorem _root_.Disjoint.exists_cthickenings (hst : Disjoint s t) (hs : IsCompact s)
(ht : IsClosed t) :
∃ δ, 0 < δ ∧ Disjoint (cthickening δ s) (cthickening δ t) := by
obtain ⟨δ, hδ, h⟩ := hst.exists_thickenings hs ht
refine ⟨δ / 2, half_pos hδ, h.mono ?_ ?_⟩ <;>
exact cthickening_subset_thickening' hδ (half_lt_self hδ) _
/-- If `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. -/
theorem _root_.IsCompact.exists_cthickening_subset_open (hs : IsCompact s) (ht : IsOpen t)
(hst : s ⊆ t) :
∃ δ, 0 < δ ∧ cthickening δ s ⊆ t :=
(hst.disjoint_compl_right.exists_cthickenings hs ht.isClosed_compl).imp fun _ h =>
⟨h.1, disjoint_compl_right_iff_subset.1 <| h.2.mono_right <| self_subset_cthickening _⟩
theorem _root_.IsCompact.exists_isCompact_cthickening [LocallyCompactSpace α] (hs : IsCompact s) :
∃ δ, 0 < δ ∧ IsCompact (cthickening δ s) := by
rcases exists_compact_superset hs with ⟨K, K_compact, hK⟩
rcases hs.exists_cthickening_subset_open isOpen_interior hK with ⟨δ, δpos, hδ⟩
refine ⟨δ, δpos, ?_⟩
exact K_compact.of_isClosed_subset isClosed_cthickening (hδ.trans interior_subset)
theorem _root_.IsCompact.exists_thickening_subset_open (hs : IsCompact s) (ht : IsOpen t)
(hst : s ⊆ t) : ∃ δ, 0 < δ ∧ thickening δ s ⊆ t :=
let ⟨δ, h₀, hδ⟩ := hs.exists_cthickening_subset_open ht hst
⟨δ, h₀, (thickening_subset_cthickening _ _).trans hδ⟩
theorem hasBasis_nhdsSet_thickening {K : Set α} (hK : IsCompact K) :
(𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => thickening δ K :=
(hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_thickening_subset_open hU.1 hU.2)
fun _ => thickening_mem_nhdsSet K
theorem hasBasis_nhdsSet_cthickening {K : Set α} (hK : IsCompact K) :
(𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => cthickening δ K :=
(hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_cthickening_subset_open hU.1 hU.2)
fun _ => cthickening_mem_nhdsSet K
theorem cthickening_eq_iInter_cthickening' {δ : ℝ} (s : Set ℝ) (hsδ : s ⊆ Ioi δ)
(hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) :
cthickening δ E = ⋂ ε ∈ s, cthickening ε E := by
apply Subset.antisymm
· exact subset_iInter₂ fun _ hε => cthickening_mono (le_of_lt (hsδ hε)) E
· unfold cthickening
intro x hx
simp only [mem_iInter, mem_setOf_eq] at *
apply ENNReal.le_of_forall_pos_le_add
intro η η_pos _
rcases hs (δ + η) (lt_add_of_pos_right _ (NNReal.coe_pos.mpr η_pos)) with ⟨ε, ⟨hsε, hε⟩⟩
apply ((hx ε hsε).trans (ENNReal.ofReal_le_ofReal hε.2)).trans
rw [ENNReal.coe_nnreal_eq η]
exact ENNReal.ofReal_add_le
theorem cthickening_eq_iInter_cthickening {δ : ℝ} (E : Set α) :
cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), cthickening ε E := by
apply cthickening_eq_iInter_cthickening' (Ioi δ) rfl.subset
simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self]
exact fun _ hε => nonempty_Ioc.mpr hε
theorem cthickening_eq_iInter_thickening' {δ : ℝ} (δ_nn : 0 ≤ δ) (s : Set ℝ) (hsδ : s ⊆ Ioi δ)
(hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) :
cthickening δ E = ⋂ ε ∈ s, thickening ε E := by
refine (subset_iInter₂ fun ε hε => ?_).antisymm ?_
· obtain ⟨ε', -, hε'⟩ := hs ε (hsδ hε)
have ss := cthickening_subset_thickening' (lt_of_le_of_lt δ_nn hε'.1) hε'.1 E
exact ss.trans (thickening_mono hε'.2 E)
· rw [cthickening_eq_iInter_cthickening' s hsδ hs E]
exact iInter₂_mono fun ε _ => thickening_subset_cthickening ε E
theorem cthickening_eq_iInter_thickening {δ : ℝ} (δ_nn : 0 ≤ δ) (E : Set α) :
cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), thickening ε E := by
apply cthickening_eq_iInter_thickening' δ_nn (Ioi δ) rfl.subset
simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self]
exact fun _ hε => nonempty_Ioc.mpr hε
theorem cthickening_eq_iInter_thickening'' (δ : ℝ) (E : Set α) :
cthickening δ E = ⋂ (ε : ℝ) (_ : max 0 δ < ε), thickening ε E := by
rw [← cthickening_max_zero, cthickening_eq_iInter_thickening]
exact le_max_left _ _
/-- The closure of a set equals the intersection of its closed thickenings of positive radii
accumulating at zero. -/
theorem closure_eq_iInter_cthickening' (E : Set α) (s : Set ℝ)
(hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, cthickening δ E := by
by_cases hs₀ : s ⊆ Ioi 0
· rw [← cthickening_zero]
apply cthickening_eq_iInter_cthickening' _ hs₀ hs
obtain ⟨δ, hδs, δ_nonpos⟩ := not_subset.mp hs₀
rw [Set.mem_Ioi, not_lt] at δ_nonpos
apply Subset.antisymm
· exact subset_iInter₂ fun ε _ => closure_subset_cthickening ε E
· rw [← cthickening_of_nonpos δ_nonpos E]
exact biInter_subset_of_mem hδs
/-- The closure of a set equals the intersection of its closed thickenings of positive radii. -/
theorem closure_eq_iInter_cthickening (E : Set α) :
closure E = ⋂ (δ : ℝ) (_ : 0 < δ), cthickening δ E := by
rw [← cthickening_zero]
exact cthickening_eq_iInter_cthickening E
/-- The closure of a set equals the intersection of its open thickenings of positive radii
accumulating at zero. -/
theorem closure_eq_iInter_thickening' (E : Set α) (s : Set ℝ) (hs₀ : s ⊆ Ioi 0)
(hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, thickening δ E := by
rw [← cthickening_zero]
apply cthickening_eq_iInter_thickening' le_rfl _ hs₀ hs
/-- The closure of a set equals the intersection of its (open) thickenings of positive radii. -/
theorem closure_eq_iInter_thickening (E : Set α) :
closure E = ⋂ (δ : ℝ) (_ : 0 < δ), thickening δ E := by
rw [← cthickening_zero]
exact cthickening_eq_iInter_thickening rfl.ge E
/-- The frontier of the closed thickening of a set is contained in an `EMetric.infEdist` level
set. -/
theorem frontier_cthickening_subset (E : Set α) {δ : ℝ} :
frontier (cthickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } :=
frontier_le_subset_eq continuous_infEdist continuous_const
/-- The closed ball of radius `δ` centered at a point of `E` is included in the closed
thickening of `E`. -/
theorem closedBall_subset_cthickening {α : Type*} [PseudoMetricSpace α] {x : α} {E : Set α}
(hx : x ∈ E) (δ : ℝ) : closedBall x δ ⊆ cthickening δ E := by
refine (closedBall_subset_cthickening_singleton _ _).trans (cthickening_subset_of_subset _ ?_)
simpa using hx
theorem cthickening_subset_iUnion_closedBall_of_lt {α : Type*} [PseudoMetricSpace α] (E : Set α)
{δ δ' : ℝ} (hδ₀ : 0 < δ') (hδδ' : δ < δ') : cthickening δ E ⊆ ⋃ x ∈ E, closedBall x δ' := by
refine (cthickening_subset_thickening' hδ₀ hδδ' E).trans fun x hx => ?_
obtain ⟨y, hy₁, hy₂⟩ := mem_thickening_iff.mp hx
exact mem_iUnion₂.mpr ⟨y, hy₁, hy₂.le⟩
/-- The closed thickening of a compact set `E` is the union of the balls `Metric.closedBall x δ`
over `x ∈ E`.
See also `Metric.cthickening_eq_biUnion_closedBall`. -/
theorem _root_.IsCompact.cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α]
{δ : ℝ} {E : Set α} (hE : IsCompact E) (hδ : 0 ≤ δ) :
cthickening δ E = ⋃ x ∈ E, closedBall x δ := by
rcases eq_empty_or_nonempty E with (rfl | hne)
· simp only [cthickening_empty, biUnion_empty]
refine Subset.antisymm (fun x hx ↦ ?_)
(iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _)
obtain ⟨y, yE, hy⟩ : ∃ y ∈ E, infEdist x E = edist x y := hE.exists_infEdist_eq_edist hne _
have D1 : edist x y ≤ ENNReal.ofReal δ := (le_of_eq hy.symm).trans hx
have D2 : dist x y ≤ δ := by
rw [edist_dist] at D1
exact (ENNReal.ofReal_le_ofReal_iff hδ).1 D1
exact mem_biUnion yE D2
theorem cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α] [ProperSpace α]
(E : Set α) (hδ : 0 ≤ δ) : cthickening δ E = ⋃ x ∈ closure E, closedBall x δ := by
rcases eq_empty_or_nonempty E with (rfl | hne)
· simp only [cthickening_empty, biUnion_empty, closure_empty]
rw [← cthickening_closure]
refine Subset.antisymm (fun x hx ↦ ?_)
(iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _)
obtain ⟨y, yE, hy⟩ : ∃ y ∈ closure E, infDist x (closure E) = dist x y :=
isClosed_closure.exists_infDist_eq_dist (closure_nonempty_iff.mpr hne) x
replace hy : dist x y ≤ δ :=
(ENNReal.ofReal_le_ofReal_iff hδ).mp
(((congr_arg ENNReal.ofReal hy.symm).le.trans ENNReal.ofReal_toReal_le).trans hx)
exact mem_biUnion yE hy
nonrec theorem _root_.IsClosed.cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α]
[ProperSpace α] {E : Set α} (hE : IsClosed E) (hδ : 0 ≤ δ) :
cthickening δ E = ⋃ x ∈ E, closedBall x δ := by
rw [cthickening_eq_biUnion_closedBall E hδ, hE.closure_eq]
/-- For the equality, see `infEdist_cthickening`. -/
theorem infEdist_le_infEdist_cthickening_add :
infEdist x s ≤ infEdist x (cthickening δ s) + ENNReal.ofReal δ := by
refine le_of_forall_lt' fun r h => ?_
simp_rw [← lt_tsub_iff_right, infEdist_lt_iff, mem_cthickening_iff] at h
obtain ⟨y, hy, hxy⟩ := h
exact infEdist_le_edist_add_infEdist.trans_lt
((ENNReal.add_lt_add_of_lt_of_le (hy.trans_lt ENNReal.ofReal_lt_top).ne hxy hy).trans_eq
(tsub_add_cancel_of_le <| le_self_add.trans (lt_tsub_iff_left.1 hxy).le))
/-- For the equality, see `infEdist_thickening`. -/
theorem infEdist_le_infEdist_thickening_add :
infEdist x s ≤ infEdist x (thickening δ s) + ENNReal.ofReal δ :=
infEdist_le_infEdist_cthickening_add.trans <|
add_le_add_right (infEdist_anti <| thickening_subset_cthickening _ _) _
/-- For the equality, see `thickening_thickening`. -/
@[simp]
theorem thickening_thickening_subset (ε δ : ℝ) (s : Set α) :
thickening ε (thickening δ s) ⊆ thickening (ε + δ) s := by
obtain hε | hε := le_total ε 0
· simp only [thickening_of_nonpos hε, empty_subset]
obtain hδ | hδ := le_total δ 0
· simp only [thickening_of_nonpos hδ, thickening_empty, empty_subset]
intro x
simp_rw [mem_thickening_iff_exists_edist_lt, ENNReal.ofReal_add hε hδ]
exact fun ⟨y, ⟨z, hz, hy⟩, hx⟩ =>
⟨z, hz, (edist_triangle _ _ _).trans_lt <| ENNReal.add_lt_add hx hy⟩
/-- For the equality, see `thickening_cthickening`. -/
@[simp]
theorem thickening_cthickening_subset (ε : ℝ) (hδ : 0 ≤ δ) (s : Set α) :
thickening ε (cthickening δ s) ⊆ thickening (ε + δ) s := by
obtain hε | hε := le_total ε 0
· simp only [thickening_of_nonpos hε, empty_subset]
intro x
simp_rw [mem_thickening_iff_exists_edist_lt, mem_cthickening_iff, ← infEdist_lt_iff,
ENNReal.ofReal_add hε hδ]
rintro ⟨y, hy, hxy⟩
exact infEdist_le_edist_add_infEdist.trans_lt
(ENNReal.add_lt_add_of_lt_of_le (hy.trans_lt ENNReal.ofReal_lt_top).ne hxy hy)
/-- For the equality, see `cthickening_thickening`. -/
@[simp]
theorem cthickening_thickening_subset (hε : 0 ≤ ε) (δ : ℝ) (s : Set α) :
cthickening ε (thickening δ s) ⊆ cthickening (ε + δ) s := by
obtain hδ | hδ := le_total δ 0
· simp only [thickening_of_nonpos hδ, cthickening_empty, empty_subset]
intro x
simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ]
exact fun hx => infEdist_le_infEdist_thickening_add.trans (add_le_add_right hx _)
/-- For the equality, see `cthickening_cthickening`. -/
@[simp]
theorem cthickening_cthickening_subset (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (s : Set α) :
cthickening ε (cthickening δ s) ⊆ cthickening (ε + δ) s := by
intro x
simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ]
exact fun hx => infEdist_le_infEdist_cthickening_add.trans (add_le_add_right hx _)
open scoped Function in -- required for scoped `on` notation
theorem frontier_cthickening_disjoint (A : Set α) :
Pairwise (Disjoint on fun r : ℝ≥0 => frontier (cthickening r A)) := fun r₁ r₂ hr =>
((disjoint_singleton.2 <| by simpa).preimage _).mono (frontier_cthickening_subset _)
(frontier_cthickening_subset _)
end Cthickening
theorem thickening_ball [PseudoMetricSpace α] (x : α) (ε δ : ℝ) :
thickening ε (ball x δ) ⊆ ball x (ε + δ) := by
rw [← thickening_singleton, ← thickening_singleton]
apply thickening_thickening_subset
end Metric
|
open Metric in
theorem IsCompact.exists_thickening_image_subset
[PseudoEMetricSpace α] {β : Type*} [PseudoEMetricSpace β]
{f : α → β} {K : Set α} {U : Set β} (hK : IsCompact K) (ho : IsOpen U)
(hf : ∀ x ∈ K, ContinuousAt f x) (hKU : MapsTo f K U) :
∃ ε > 0, ∃ V ∈ 𝓝ˢ K, thickening ε (f '' V) ⊆ U := by
apply hK.induction_on (p := fun K ↦ ∃ ε > 0, ∃ V ∈ 𝓝ˢ K, thickening ε (f '' V) ⊆ U)
| Mathlib/Topology/MetricSpace/Thickening.lean | 641 | 648 |
/-
Copyright (c) 2024 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.NumberTheory.DirichletCharacter.Bounds
import Mathlib.NumberTheory.LSeries.Convolution
import Mathlib.NumberTheory.LSeries.Deriv
import Mathlib.NumberTheory.LSeries.RiemannZeta
import Mathlib.NumberTheory.SumPrimeReciprocals
import Mathlib.NumberTheory.VonMangoldt
/-!
# L-series of Dirichlet characters and arithmetic functions
We collect some results on L-series of specific (arithmetic) functions, for example,
the Möbius function `μ` or the von Mangoldt function `Λ`. In particular, we show that
`L ↗Λ` is the negative of the logarithmic derivative of the Riemann zeta function
on `re s > 1`; see `LSeries_vonMangoldt_eq_deriv_riemannZeta_div`.
We also prove some general results on L-series associated to Dirichlet characters
(i.e., Dirichlet L-series). For example, we show that the abscissa of absolute convergence
equals `1` (see `DirichletCharacter.absicssaOfAbsConv`) and that the L-series does not
vanish on the open half-plane `re s > 1` (see `DirichletCharacter.LSeries_ne_zero_of_one_lt_re`).
We deduce results on the Riemann zeta function (which is `L 1` or `L ↗ζ` on `re s > 1`)
as special cases.
## Tags
Dirichlet L-series, Möbius function, von Mangoldt function, Riemann zeta function
-/
open scoped LSeries.notation
/-- `δ` is the function underlying the arithmetic function `1`. -/
lemma ArithmeticFunction.one_eq_delta : ↗(1 : ArithmeticFunction ℂ) = δ := by
ext
simp [one_apply, LSeries.delta]
section Moebius
/-!
### The L-series of the Möbius function
We show that `L μ s` converges absolutely if and only if `re s > 1`.
-/
namespace ArithmeticFunction
open LSeries Nat Complex
lemma not_LSeriesSummable_moebius_at_one : ¬ LSeriesSummable ↗μ 1 := by
refine fun h ↦ not_summable_one_div_on_primes <| summable_ofReal.mp <| .of_neg ?_
refine (h.indicator {n | n.Prime}).congr fun n ↦ ?_
by_cases hn : n.Prime
· simp [hn, hn.ne_zero, moebius_apply_prime hn, push_cast, neg_div]
· simp [hn]
/-- The L-series of the Möbius function converges absolutely at `s` if and only if `re s > 1`. -/
lemma LSeriesSummable_moebius_iff {s : ℂ} : LSeriesSummable ↗μ s ↔ 1 < s.re := by
refine ⟨fun H ↦ ?_, LSeriesSummable_of_bounded_of_one_lt_re (m := 1) fun n _ ↦ ?_⟩
· by_contra! h
exact not_LSeriesSummable_moebius_at_one <| LSeriesSummable.of_re_le_re (by simpa) H
· norm_cast
exact abs_moebius_le_one
/-- The abscissa of absolute convergence of the L-series of the Möbius function is `1`. -/
lemma abscissaOfAbsConv_moebius : abscissaOfAbsConv ↗μ = 1 := by
simpa [abscissaOfAbsConv, LSeriesSummable_moebius_iff, Set.Ioi_def, EReal.image_coe_Ioi]
using csInf_Ioo <| EReal.coe_lt_top 1
end ArithmeticFunction
end Moebius
/-!
### L-series of Dirichlet characters
-/
open Nat
open scoped ArithmeticFunction.zeta in
lemma ArithmeticFunction.const_one_eq_zeta {R : Type*} [AddMonoidWithOne R] {n : ℕ} (hn : n ≠ 0) :
(1 : ℕ → R) n = (ζ ·) n := by
simp [hn]
lemma LSeries.one_convolution_eq_zeta_convolution {R : Type*} [Semiring R] (f : ℕ → R) :
(1 : ℕ → R) ⍟ f = ((ArithmeticFunction.zeta ·) : ℕ → R) ⍟ f :=
convolution_congr ArithmeticFunction.const_one_eq_zeta fun _ ↦ rfl
lemma LSeries.convolution_one_eq_convolution_zeta {R : Type*} [Semiring R] (f : ℕ → R) :
f ⍟ (1 : ℕ → R) = f ⍟ ((ArithmeticFunction.zeta ·) : ℕ → R) :=
convolution_congr (fun _ ↦ rfl) ArithmeticFunction.const_one_eq_zeta
/-- `χ₁` is (local) notation for the (necessarily trivial) Dirichlet character modulo `1`. -/
local notation (name := Dchar_one) "χ₁" => (1 : DirichletCharacter ℂ 1)
namespace DirichletCharacter
open ArithmeticFunction in
/-- The arithmetic function associated to a Dirichlet character is multiplicative. -/
lemma isMultiplicative_toArithmeticFunction {N : ℕ} {R : Type*} [CommMonoidWithZero R]
(χ : DirichletCharacter R N) :
(toArithmeticFunction (χ ·)).IsMultiplicative := by
refine IsMultiplicative.iff_ne_zero.mpr ⟨?_, fun {m} {n} hm hn _ ↦ ?_⟩
· simp [toArithmeticFunction]
· simp [toArithmeticFunction, hm, hn]
lemma apply_eq_toArithmeticFunction_apply {N : ℕ} {R : Type*} [CommMonoidWithZero R]
(χ : DirichletCharacter R N) {n : ℕ} (hn : n ≠ 0) :
χ n = toArithmeticFunction (χ ·) n := by
simp [toArithmeticFunction, hn]
open LSeries Nat Complex
/-- Twisting by a Dirichlet character `χ` distributes over convolution. -/
lemma mul_convolution_distrib {R : Type*} [CommSemiring R] {n : ℕ} (χ : DirichletCharacter R n)
(f g : ℕ → R) :
(((χ ·) : ℕ → R) * f) ⍟ (((χ ·) : ℕ → R) * g) = ((χ ·) : ℕ → R) * (f ⍟ g) := by
ext n
simp only [Pi.mul_apply, LSeries.convolution_def, Finset.mul_sum]
refine Finset.sum_congr rfl fun p hp ↦ ?_
rw [(mem_divisorsAntidiagonal.mp hp).1.symm, cast_mul, map_mul]
exact mul_mul_mul_comm ..
lemma mul_delta {n : ℕ} (χ : DirichletCharacter ℂ n) : ↗χ * δ = δ :=
LSeries.mul_delta <| by rw [cast_one, map_one]
lemma delta_mul {n : ℕ} (χ : DirichletCharacter ℂ n) : δ * ↗χ = δ :=
mul_comm δ _ ▸ mul_delta ..
open ArithmeticFunction in
/-- The convolution of a Dirichlet character `χ` with the twist `χ * μ` is `δ`,
the indicator function of `{1}`. -/
lemma convolution_mul_moebius {n : ℕ} (χ : DirichletCharacter ℂ n) : ↗χ ⍟ (↗χ * ↗μ) = δ := by
have : (1 : ℕ → ℂ) ⍟ (μ ·) = δ := by
rw [one_convolution_eq_zeta_convolution, ← one_eq_delta]
simp_rw [← natCoe_apply, ← intCoe_apply, coe_mul, coe_zeta_mul_coe_moebius]
nth_rewrite 1 [← mul_one ↗χ]
simpa only [mul_convolution_distrib χ 1 ↗μ, this] using mul_delta _
/-- The Dirichlet character mod `0` corresponds to `δ`. -/
lemma modZero_eq_delta {χ : DirichletCharacter ℂ 0} : ↗χ = δ := by
ext n
rcases eq_or_ne n 0 with rfl | hn
· simp_rw [cast_zero, χ.map_nonunit not_isUnit_zero, delta, reduceCtorEq, if_false]
rcases eq_or_ne n 1 with rfl | hn'
· simp [delta]
have : ¬ IsUnit (n : ZMod 0) := fun h ↦ hn' <| ZMod.eq_one_of_isUnit_natCast h
simp_all [χ.map_nonunit this, delta]
/-- The Dirichlet character mod `1` corresponds to the constant function `1`. -/
lemma modOne_eq_one {R : Type*} [CommMonoidWithZero R] {χ : DirichletCharacter R 1} :
((χ ·) : ℕ → R) = 1 := by
ext
rw [χ.level_one, MulChar.one_apply (isUnit_of_subsingleton _), Pi.one_apply]
lemma LSeries_modOne_eq : L ↗χ₁ = L 1 :=
congr_arg L modOne_eq_one
/-- The L-series of a Dirichlet character mod `N > 0` does not converge absolutely at `s = 1`. -/
lemma not_LSeriesSummable_at_one {N : ℕ} (hN : N ≠ 0) (χ : DirichletCharacter ℂ N) :
¬ LSeriesSummable ↗χ 1 := by
refine fun h ↦ (Real.not_summable_indicator_one_div_natCast hN 1) ?_
refine h.norm.of_nonneg_of_le (fun m ↦ Set.indicator_apply_nonneg (fun _ ↦ by positivity))
(fun n ↦ ?_)
simp only [norm_term_eq, Set.indicator, Set.mem_setOf_eq]
split_ifs with h₁ h₂
· simp [h₂]
· simp [h₁, χ.map_one]
all_goals positivity
/-- The L-series of a Dirichlet character converges absolutely at `s` if `re s > 1`. -/
lemma LSeriesSummable_of_one_lt_re {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) :
LSeriesSummable ↗χ s :=
LSeriesSummable_of_bounded_of_one_lt_re (fun _ _ ↦ χ.norm_le_one _) hs
/-- The L-series of a Dirichlet character mod `N > 0` converges absolutely at `s` if and only if
`re s > 1`. -/
lemma LSeriesSummable_iff {N : ℕ} (hN : N ≠ 0) (χ : DirichletCharacter ℂ N) {s : ℂ} :
LSeriesSummable ↗χ s ↔ 1 < s.re := by
refine ⟨fun H ↦ ?_, LSeriesSummable_of_one_lt_re χ⟩
by_contra! h
exact not_LSeriesSummable_at_one hN χ <| LSeriesSummable.of_re_le_re (by simp [h]) H
/-- The abscissa of absolute convergence of the L-series of a Dirichlet character mod `N > 0`
is `1`. -/
lemma absicssaOfAbsConv_eq_one {N : ℕ} (hn : N ≠ 0) (χ : DirichletCharacter ℂ N) :
abscissaOfAbsConv ↗χ = 1 := by
simpa [abscissaOfAbsConv, LSeriesSummable_iff hn χ, Set.Ioi_def, EReal.image_coe_Ioi]
using csInf_Ioo <| EReal.coe_lt_top 1
/-- The L-series of the twist of `f` by a Dirichlet character converges at `s` if the L-series
of `f` does. -/
lemma LSeriesSummable_mul {N : ℕ} (χ : DirichletCharacter ℂ N) {f : ℕ → ℂ} {s : ℂ}
(h : LSeriesSummable f s) :
LSeriesSummable (↗χ * f) s := by
refine .of_norm <| h.norm.of_nonneg_of_le (fun _ ↦ norm_nonneg _) fun n ↦ norm_term_le s ?_
simpa using mul_le_of_le_one_left (norm_nonneg <| f n) <| χ.norm_le_one n
open scoped ArithmeticFunction.Moebius in
/-- The L-series of a Dirichlet character `χ` and of the twist of `μ` by `χ` are multiplicative
inverses. -/
lemma LSeries.mul_mu_eq_one {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ}
(hs : 1 < s.re) : L ↗χ s * L (↗χ * ↗μ) s = 1 := by
rw [← LSeries_convolution' (LSeriesSummable_of_one_lt_re χ hs) <|
LSeriesSummable_mul χ <| ArithmeticFunction.LSeriesSummable_moebius_iff.mpr hs,
convolution_mul_moebius, LSeries_delta, Pi.one_apply]
/-!
### L-series of Dirichlet characters do not vanish on re s > 1
-/
/-- The L-series of a Dirichlet character does not vanish on the right half-plane `re s > 1`. -/
lemma LSeries_ne_zero_of_one_lt_re {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) :
L ↗χ s ≠ 0 :=
fun h ↦ by simpa [h] using LSeries.mul_mu_eq_one χ hs
end DirichletCharacter
section zeta
/-!
### The L-series of the constant sequence 1 / the arithmetic function ζ
Both give the same L-series (since the difference in values at zero has no effect;
see `ArithmeticFunction.LSeries_zeta_eq`), which agrees with the Riemann zeta function
on `re s > 1`. We state most results in two versions, one for `1` and one for `↗ζ`.
-/
open LSeries Nat Complex DirichletCharacter
/-- The abscissa of (absolute) convergence of the constant sequence `1` is `1`. -/
lemma LSeries.abscissaOfAbsConv_one : abscissaOfAbsConv 1 = 1 :=
modOne_eq_one (χ := χ₁) ▸ absicssaOfAbsConv_eq_one one_ne_zero χ₁
/-- The `LSeries` of the constant sequence `1` converges at `s` if and only if `re s > 1`. -/
theorem LSeriesSummable_one_iff {s : ℂ} : LSeriesSummable 1 s ↔ 1 < s.re :=
modOne_eq_one (χ := χ₁) ▸ LSeriesSummable_iff one_ne_zero χ₁
namespace ArithmeticFunction
/-- The `LSeries` of the arithmetic function `ζ` is the same as the `LSeries` associated
to the constant sequence `1`. -/
lemma LSeries_zeta_eq : L ↗ζ = L 1 := by
ext s
exact (LSeries_congr s const_one_eq_zeta).symm
/-- The `LSeries` associated to the arithmetic function `ζ` converges at `s` if and only if
`re s > 1`. -/
theorem LSeriesSummable_zeta_iff {s : ℂ} : LSeriesSummable (ζ ·) s ↔ 1 < s.re :=
(LSeriesSummable_congr s const_one_eq_zeta).symm.trans <| LSeriesSummable_one_iff
| /-- The abscissa of (absolute) convergence of the arithmetic function `ζ` is `1`. -/
lemma abscissaOfAbsConv_zeta : abscissaOfAbsConv ↗ζ = 1 := by
rw [abscissaOfAbsConv_congr (g := 1) fun hn ↦ by simp [hn], abscissaOfAbsConv_one]
/-- The L-series of the arithmetic function `ζ` equals the Riemann Zeta Function on its
domain of convergence `1 < re s`. -/
lemma LSeries_zeta_eq_riemannZeta {s : ℂ} (hs : 1 < s.re) : L ↗ζ s = riemannZeta s := by
suffices ∑' n, term (fun n ↦ if n = 0 then 0 else 1) s n = ∑' n : ℕ, 1 / (n : ℂ) ^ s by
simpa [LSeries, zeta_eq_tsum_one_div_nat_cpow hs]
| Mathlib/NumberTheory/LSeries/Dirichlet.lean | 260 | 268 |
/-
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]
| Mathlib/Algebra/Group/Basic.lean | 153 | 155 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Size
import Batteries.Data.Int
/-!
# Bitwise operations on integers
Possibly only of archaeological significance.
## Recursors
* `Int.bitCasesOn`: Parity disjunction. Something is true/defined on `ℤ` if it's true/defined for
even and for odd values.
-/
namespace Int
/-- `div2 n = n/2` -/
def div2 : ℤ → ℤ
| (n : ℕ) => n.div2
| -[n +1] => negSucc n.div2
/-- `bodd n` returns `true` if `n` is odd -/
def bodd : ℤ → Bool
| (n : ℕ) => n.bodd
| -[n +1] => not (n.bodd)
/-- `bit b` appends the digit `b` to the binary representation of
its integer input. -/
def bit (b : Bool) : ℤ → ℤ :=
cond b (2 * · + 1) (2 * ·)
/-- `Int.natBitwise` is an auxiliary definition for `Int.bitwise`. -/
def natBitwise (f : Bool → Bool → Bool) (m n : ℕ) : ℤ :=
cond (f false false) -[ Nat.bitwise (fun x y => not (f x y)) m n +1] (Nat.bitwise f m n)
/-- `Int.bitwise` applies the function `f` to pairs of bits in the same position in
the binary representations of its inputs. -/
def bitwise (f : Bool → Bool → Bool) : ℤ → ℤ → ℤ
| (m : ℕ), (n : ℕ) => natBitwise f m n
| (m : ℕ), -[n +1] => natBitwise (fun x y => f x (not y)) m n
| -[m +1], (n : ℕ) => natBitwise (fun x y => f (not x) y) m n
| -[m +1], -[n +1] => natBitwise (fun x y => f (not x) (not y)) m n
/-- `lnot` flips all the bits in the binary representation of its input -/
def lnot : ℤ → ℤ
| (m : ℕ) => -[m +1]
| -[m +1] => m
/-- `lor` takes two integers and returns their bitwise `or` -/
def lor : ℤ → ℤ → ℤ
| (m : ℕ), (n : ℕ) => m ||| n
| (m : ℕ), -[n +1] => -[Nat.ldiff n m +1]
| -[m +1], (n : ℕ) => -[Nat.ldiff m n +1]
| -[m +1], -[n +1] => -[m &&& n +1]
/-- `land` takes two integers and returns their bitwise `and` -/
def land : ℤ → ℤ → ℤ
| (m : ℕ), (n : ℕ) => m &&& n
| (m : ℕ), -[n +1] => Nat.ldiff m n
| -[m +1], (n : ℕ) => Nat.ldiff n m
| -[m +1], -[n +1] => -[m ||| n +1]
/-- `ldiff a b` performs bitwise set difference. For each corresponding
pair of bits taken as booleans, say `aᵢ` and `bᵢ`, it applies the
boolean operation `aᵢ ∧ bᵢ` to obtain the `iᵗʰ` bit of the result. -/
def ldiff : ℤ → ℤ → ℤ
| (m : ℕ), (n : ℕ) => Nat.ldiff m n
| (m : ℕ), -[n +1] => m &&& n
| -[m +1], (n : ℕ) => -[m ||| n +1]
| -[m +1], -[n +1] => Nat.ldiff n m
/-- `xor` computes the bitwise `xor` of two natural numbers -/
protected def xor : ℤ → ℤ → ℤ
| (m : ℕ), (n : ℕ) => (m ^^^ n)
| (m : ℕ), -[n +1] => -[(m ^^^ n) +1]
| -[m +1], (n : ℕ) => -[(m ^^^ n) +1]
| -[m +1], -[n +1] => (m ^^^ n)
/-- `m <<< n` produces an integer whose binary representation
is obtained by left-shifting the binary representation of `m` by `n` places -/
instance : ShiftLeft ℤ where
shiftLeft
| (m : ℕ), (n : ℕ) => Nat.shiftLeft' false m n
| (m : ℕ), -[n +1] => m >>> (Nat.succ n)
| -[m +1], (n : ℕ) => -[Nat.shiftLeft' true m n +1]
| -[m +1], -[n +1] => -[m >>> (Nat.succ n) +1]
/-- `m >>> n` produces an integer whose binary representation
is obtained by right-shifting the binary representation of `m` by `n` places -/
instance : ShiftRight ℤ where
shiftRight m n := m <<< (-n)
/-! ### bitwise ops -/
@[simp]
theorem bodd_zero : bodd 0 = false :=
rfl
@[simp]
theorem bodd_one : bodd 1 = true :=
rfl
theorem bodd_two : bodd 2 = false :=
rfl
@[simp, norm_cast]
theorem bodd_coe (n : ℕ) : Int.bodd n = Nat.bodd n :=
rfl
@[simp]
theorem bodd_subNatNat (m n : ℕ) : bodd (subNatNat m n) = xor m.bodd n.bodd := by
apply subNatNat_elim m n fun m n i => bodd i = xor m.bodd n.bodd <;>
intros i j <;>
simp only [Int.bodd, Int.bodd_coe, Nat.bodd_add] <;>
cases Nat.bodd i <;> simp
@[simp]
theorem bodd_negOfNat (n : ℕ) : bodd (negOfNat n) = n.bodd := by
cases n <;> simp +decide
rfl
@[simp]
theorem bodd_neg (n : ℤ) : bodd (-n) = bodd n := by
cases n <;> simp only [← negOfNat_eq, bodd_negOfNat, neg_negSucc] <;> simp [bodd]
@[simp]
theorem bodd_add (m n : ℤ) : bodd (m + n) = xor (bodd m) (bodd n) := by
rcases m with m | m <;>
rcases n with n | n <;>
simp only [ofNat_eq_coe, ofNat_add_negSucc, negSucc_add_ofNat,
negSucc_add_negSucc, bodd_subNatNat, ← Nat.cast_add] <;>
simp [bodd, Bool.xor_comm]
@[simp]
theorem bodd_mul (m n : ℤ) : bodd (m * n) = (bodd m && bodd n) := by
rcases m with m | m <;> rcases n with n | n <;>
simp only [ofNat_eq_coe, ofNat_mul_negSucc, negSucc_mul_ofNat, ofNat_mul_ofNat,
negSucc_mul_negSucc] <;>
simp only [negSucc_eq, ← Int.natCast_succ, bodd_neg, bodd_coe, Nat.bodd_mul]
theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
| (n : ℕ) => by
rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ) by cases bodd n <;> rfl]
exact congr_arg ofNat n.bodd_add_div2
| -[n+1] => by
refine Eq.trans ?_ (congr_arg negSucc n.bodd_add_div2)
dsimp [bodd]; cases Nat.bodd n <;> dsimp [cond, not, div2, Int.mul]
· change -[2 * Nat.div2 n+1] = _
rw [zero_add]
· rw [zero_add, add_comm]
rfl
theorem div2_val : ∀ n, div2 n = n / 2
| (n : ℕ) => congr_arg ofNat n.div2_val
| -[n+1] => congr_arg negSucc n.div2_val
theorem bit_val (b n) : bit b n = 2 * n + cond b 1 0 := by
cases b
· apply (add_zero _).symm
· rfl
theorem bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans <| (add_comm _ _).trans <| bodd_add_div2 _
/-- Defines a function from `ℤ` conditionally, if it is defined for odd and even integers separately
using `bit`. -/
def bitCasesOn.{u} {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n := by
rw [← bit_decomp n]
apply h
@[simp]
theorem bit_zero : bit false 0 = 0 :=
rfl
@[simp]
theorem bit_coe_nat (b) (n : ℕ) : bit b n = Nat.bit b n := by
rw [bit_val, Nat.bit_val]
cases b <;> rfl
@[simp]
theorem bit_negSucc (b) (n : ℕ) : bit b -[n+1] = -[Nat.bit (not b) n+1] := by
rw [bit_val, Nat.bit_val]
cases b <;> rfl
@[simp]
theorem bodd_bit (b n) : bodd (bit b n) = b := by
rw [bit_val]
cases b <;> cases bodd n <;> simp [(show bodd 2 = false by rfl)]
@[simp]
theorem testBit_bit_zero (b) : ∀ n, testBit (bit b n) 0 = b
| (n : ℕ) => by rw [bit_coe_nat]; apply Nat.testBit_bit_zero
| -[n+1] => by
rw [bit_negSucc]; dsimp [testBit]; rw [Nat.testBit_bit_zero]; clear testBit_bit_zero
cases b <;>
rfl
@[simp]
theorem testBit_bit_succ (m b) : ∀ n, testBit (bit b n) (Nat.succ m) = testBit n m
| (n : ℕ) => by rw [bit_coe_nat]; apply Nat.testBit_bit_succ
| -[n+1] => by
dsimp only [testBit]
simp only [bit_negSucc]
cases b <;> simp only [Bool.not_false, Bool.not_true, Nat.testBit_bit_succ]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO
-- private unsafe def bitwise_tac : tactic Unit :=
-- sorry
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_or : bitwise or = lor := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false, Bool.or_true, cond_true, lor, Nat.ldiff,
negSucc.injEq, Bool.true_or, Nat.land]
· rw [Nat.bitwise_swap, Function.swap]
congr
funext x y
cases x <;> cases y <;> rfl
· congr
funext x y
cases x <;> cases y <;> rfl
· congr
funext x y
cases x <;> cases y <;> rfl
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_and : bitwise and = land := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false, Bool.or_true,
cond_false, cond_true, lor, Nat.ldiff, Bool.and_true, negSucc.injEq,
Bool.and_false, Nat.land]
· rw [Nat.bitwise_swap, Function.swap]
congr
funext x y
cases x <;> cases y <;> rfl
· congr
funext x y
cases x <;> cases y <;> rfl
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_diff : (bitwise fun a b => a && not b) = ldiff := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false, Bool.or_true,
cond_false, cond_true, lor, Nat.ldiff, Bool.and_true, negSucc.injEq,
Bool.and_false, Nat.land, Bool.not_true, ldiff, Nat.lor]
· congr
funext x y
cases x <;> cases y <;> rfl
· congr
funext x y
cases x <;> cases y <;> rfl
· rw [Nat.bitwise_swap, Function.swap]
congr
funext x y
cases x <;> cases y <;> rfl
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_xor : bitwise xor = Int.xor := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false, Bool.or_true, Bool.bne_eq_xor,
cond_false, cond_true, lor, Nat.ldiff, Bool.and_true, negSucc.injEq, Bool.false_xor,
Bool.true_xor, Bool.and_false, Nat.land, Bool.not_true, ldiff,
HOr.hOr, OrOp.or, Nat.lor, Int.xor, HXor.hXor, Xor.xor, Nat.xor]
· congr
funext x y
cases x <;> cases y <;> rfl
· congr
funext x y
cases x <;> cases y <;> rfl
· congr
funext x y
cases x <;> cases y <;> rfl
@[simp]
theorem bitwise_bit (f : Bool → Bool → Bool) (a m b n) :
bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by
rcases m with m | m <;> rcases n with n | n <;>
simp [bitwise, ofNat_eq_coe, bit_coe_nat, natBitwise, Bool.not_false, Bool.not_eq_false',
bit_negSucc]
· by_cases h : f false false <;> simp +decide [h]
· by_cases h : f false true <;> simp +decide [h]
· by_cases h : f true false <;> simp +decide [h]
· by_cases h : f true true <;> simp +decide [h]
@[simp]
theorem lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) := by
rw [← bitwise_or, bitwise_bit]
@[simp]
theorem land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) := by
rw [← bitwise_and, bitwise_bit]
@[simp]
theorem ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && not b) (ldiff m n) := by
rw [← bitwise_diff, bitwise_bit]
@[simp]
theorem lxor_bit (a m b n) : Int.xor (bit a m) (bit b n) = bit (xor a b) (Int.xor m n) := by
rw [← bitwise_xor, bitwise_bit]
@[simp]
theorem lnot_bit (b) : ∀ n, lnot (bit b n) = bit (not b) (lnot n)
| (n : ℕ) => by simp [lnot]
| -[n+1] => by simp [lnot]
@[simp]
theorem testBit_bitwise (f : Bool → Bool → Bool) (m n k) :
testBit (bitwise f m n) k = f (testBit m k) (testBit n k) := by
cases m <;> cases n <;> simp only [testBit, bitwise, natBitwise]
· by_cases h : f false false <;> simp [h]
· by_cases h : f false true <;> simp [h]
· by_cases h : f true false <;> simp [h]
· by_cases h : f true true <;> simp [h]
@[simp]
theorem testBit_lor (m n k) : testBit (lor m n) k = (testBit m k || testBit n k) := by
rw [← bitwise_or, testBit_bitwise]
@[simp]
theorem testBit_land (m n k) : testBit (land m n) k = (testBit m k && testBit n k) := by
rw [← bitwise_and, testBit_bitwise]
@[simp]
theorem testBit_ldiff (m n k) : testBit (ldiff m n) k = (testBit m k && not (testBit n k)) := by
rw [← bitwise_diff, testBit_bitwise]
@[simp]
theorem testBit_lxor (m n k) : testBit (Int.xor m n) k = xor (testBit m k) (testBit n k) := by
rw [← bitwise_xor, testBit_bitwise]
@[simp]
theorem testBit_lnot : ∀ n k, testBit (lnot n) k = not (testBit n k)
| (n : ℕ), k => by simp [lnot, testBit]
| -[n+1], k => by simp [lnot, testBit]
@[simp]
theorem shiftLeft_neg (m n : ℤ) : m <<< (-n) = m >>> n :=
rfl
@[simp]
theorem shiftRight_neg (m n : ℤ) : m >>> (-n) = m <<< n := by rw [← shiftLeft_neg, neg_neg]
@[simp]
theorem shiftLeft_natCast (m n : ℕ) : (m : ℤ) <<< (n : ℤ) = ↑(m <<< n) := by
unfold_projs; simp
@[simp]
theorem shiftRight_natCast (m n : ℕ) : (m : ℤ) >>> (n : ℤ) = m >>> n := by cases n <;> rfl
@[deprecated (since := "2025-03-10")] alias shiftLeft_coe_nat := shiftLeft_natCast
@[deprecated (since := "2025-03-10")] alias shiftRight_coe_nat := shiftRight_natCast
@[simp]
theorem shiftLeft_negSucc (m n : ℕ) : -[m+1] <<< (n : ℤ) = -[Nat.shiftLeft' true m n+1] :=
rfl
@[simp]
theorem shiftRight_negSucc (m n : ℕ) : -[m+1] >>> (n : ℤ) = -[m >>> n+1] := by cases n <;> rfl
/-- Compare with `Int.shiftRight_add`, which doesn't have the coercions `ℕ → ℤ`. -/
theorem shiftRight_add' : ∀ (m : ℤ) (n k : ℕ), m >>> (n + k : ℤ) = (m >>> (n : ℤ)) >>> (k : ℤ)
| (m : ℕ), n, k => by
rw [shiftRight_natCast, shiftRight_natCast, ← Int.natCast_add, shiftRight_natCast,
Nat.shiftRight_add]
| -[m+1], n, k => by
rw [shiftRight_negSucc, shiftRight_negSucc, ← Int.natCast_add, shiftRight_negSucc,
Nat.shiftRight_add]
/-! ### bitwise ops -/
theorem shiftLeft_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), m <<< (n + k) = (m <<< (n : ℤ)) <<< k
| (m : ℕ), n, (k : ℕ) =>
congr_arg ofNat (by simp [Nat.shiftLeft_eq, Nat.pow_add, mul_assoc])
| -[_+1], _, (k : ℕ) => congr_arg negSucc (Nat.shiftLeft'_add _ _ _ _)
| (m : ℕ), n, -[k+1] =>
subNatNat_elim n k.succ (fun n k i => (↑m) <<< i = (Nat.shiftLeft' false m n) >>> k)
(fun (i n : ℕ) =>
by dsimp; simp [← Nat.shiftLeft_sub _ , Nat.add_sub_cancel_left])
fun i n => by
dsimp
simp_rw [negSucc_eq, shiftLeft_neg, Nat.shiftLeft'_false, Nat.shiftRight_add,
← Nat.shiftLeft_sub _ le_rfl, Nat.sub_self, Nat.shiftLeft_zero, ← shiftRight_natCast,
← shiftRight_add', Nat.cast_one]
| -[m+1], n, -[k+1] =>
subNatNat_elim n k.succ
(fun n k i => -[m+1] <<< i = -[(Nat.shiftLeft' true m n) >>> k+1])
(fun i n =>
congr_arg negSucc <| by
rw [← Nat.shiftLeft'_sub, Nat.add_sub_cancel_left]; apply Nat.le_add_right)
fun i n =>
congr_arg negSucc <| by rw [add_assoc, Nat.shiftRight_add, ← Nat.shiftLeft'_sub _ _ le_rfl,
Nat.sub_self, Nat.shiftLeft']
theorem shiftLeft_sub (m : ℤ) (n : ℕ) (k : ℤ) : m <<< (n - k) = (m <<< (n : ℤ)) >>> k :=
shiftLeft_add _ _ _
theorem shiftLeft_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), m <<< (n : ℤ) = m * (2 ^ n : ℕ)
| (m : ℕ), _ => congr_arg ((↑) : ℕ → ℤ) (by simp [Nat.shiftLeft_eq])
| -[_+1], _ => @congr_arg ℕ ℤ _ _ (fun i => -i) (Nat.shiftLeft'_tt_eq_mul_pow _ _)
theorem one_shiftLeft (n : ℕ) : 1 <<< (n : ℤ) = (2 ^ n : ℕ) :=
congr_arg ((↑) : ℕ → ℤ) (by simp [Nat.shiftLeft_eq])
@[simp]
theorem zero_shiftLeft : ∀ n : ℤ, 0 <<< n = 0
| (n : ℕ) => congr_arg ((↑) : ℕ → ℤ) (by simp)
| -[_+1] => congr_arg ((↑) : ℕ → ℤ) (by simp)
/-- Compare with `Int.zero_shiftRight`, which has `n : ℕ`. -/
@[simp]
theorem zero_shiftRight' (n : ℤ) : 0 >>> n = 0 :=
zero_shiftLeft _
end Int
| Mathlib/Data/Int/Bitwise.lean | 541 | 542 | |
/-
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]
| Mathlib/SetTheory/Cardinal/Cofinality.lean | 180 | 213 |
/-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Finset.Basic
import Mathlib.ModelTheory.Syntax
import Mathlib.Data.List.ProdSigma
/-!
# Basics on First-Order Semantics
This file defines the interpretations of first-order terms, formulas, sentences, and theories
in a style inspired by the [Flypitch project](https://flypitch.github.io/).
## Main Definitions
- `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at
variables `v`.
- `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded
formula `φ` evaluated at tuples of variables `v` and `xs`.
- `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ`
evaluated at variables `v`.
- `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ`
evaluated in the structure `M`. Also denoted `M ⊨ φ`.
- `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every
sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`.
## Main Results
- Several results in this file show that syntactic constructions such as `relabel`, `castLE`,
`liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas,
sentences, and theories.
## Implementation Notes
- Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n`
is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some
indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula
`∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by
`n : Fin (n + 1)`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {L' : Language}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'} {γ : Type*}
open FirstOrder Cardinal
open Structure Cardinal Fin
namespace Term
/-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/
def realize (v : α → M) : ∀ _t : L.Term α, M
| var k => v k
| func f ts => funMap f fun i => (ts i).realize v
@[simp]
theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl
@[simp]
theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) :
realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl
@[simp]
theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} :
(t.relabel g).realize v = t.realize (v ∘ g) := by
induction t with
| var => rfl
| func f ts ih => simp [ih]
@[simp]
theorem realize_liftAt {n n' m : ℕ} {t : L.Term (α ⊕ (Fin n))} {v : α ⊕ (Fin (n + n')) → M} :
(t.liftAt n' m).realize v =
t.realize (v ∘ Sum.map id fun i : Fin _ =>
if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') :=
realize_relabel
@[simp]
theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c :=
funMap_eq_coe_constants
@[simp]
theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} :
(f.apply₁ t).realize v = funMap f ![t.realize v] := by
rw [Functions.apply₁, Term.realize]
refine congr rfl (funext fun i => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} :
(f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by
rw [Functions.apply₂, Term.realize]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a :=
rfl
@[simp]
theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} :
(t.subst tf).realize v = t.realize fun a => (tf a).realize v := by
induction t with
| var => rfl
| func _ _ ih => simp [ih]
theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {f : t.varFinset → β}
{v : β → M} (v' : α → M) (hv' : ∀ a, v (f a) = v' a) :
(t.restrictVar f).realize v = t.realize v' := by
induction t with
| var => simp [restrictVar, hv']
| func _ _ ih =>
| exact congr rfl (funext fun i => ih i ((by simp [Function.comp_apply, hv'])))
/-- A special case of `realize_restrictVar`, included because we can add the `simp` attribute
to it -/
@[simp]
| Mathlib/ModelTheory/Semantics.lean | 130 | 134 |
/-
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
| Mathlib/Data/Set/Prod.lean | 153 | 162 |
/-
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.IsPrimePow
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Data.Nat.Cast.Order.Ring
import Mathlib.Data.Nat.PrimeFin
import Mathlib.Order.Interval.Finset.Nat
/-!
# Divisor Finsets
This file defines sets of divisors of a natural number. This is particularly useful as background
for defining Dirichlet convolution.
## Main Definitions
Let `n : ℕ`. All of the following definitions are in the `Nat` namespace:
* `divisors n` is the `Finset` of natural numbers that divide `n`.
* `properDivisors n` is the `Finset` of natural numbers that divide `n`, other than `n`.
* `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`.
* `Perfect n` is true when `n` is positive and the sum of `properDivisors n` is `n`.
## Conventions
Since `0` has infinitely many divisors, none of the definitions in this file make sense for it.
Therefore we adopt the convention that `Nat.divisors 0`, `Nat.properDivisors 0`,
`Nat.divisorsAntidiagonal 0` and `Int.divisorsAntidiag 0` are all `∅`.
## Tags
divisors, perfect numbers
-/
open Finset
namespace Nat
variable (n : ℕ)
/-- `divisors n` is the `Finset` of divisors of `n`. By convention, we set `divisors 0 = ∅`. -/
def divisors : Finset ℕ := {d ∈ Ico 1 (n + 1) | d ∣ n}
/-- `properDivisors n` is the `Finset` of divisors of `n`, other than `n`.
By convention, we set `properDivisors 0 = ∅`. -/
def properDivisors : Finset ℕ := {d ∈ Ico 1 n | d ∣ n}
/-- Pairs of divisors of a natural number as a finset.
`n.divisorsAntidiagonal` is the finset of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`.
By convention, we set `Nat.divisorsAntidiagonal 0 = ∅`.
O(n). -/
def divisorsAntidiagonal : Finset (ℕ × ℕ) :=
(Icc 1 n).filterMap (fun x ↦ let y := n / x; if x * y = n then some (x, y) else none)
fun x₁ x₂ (x, y) hx₁ hx₂ ↦ by aesop
/-- Pairs of divisors of a natural number, as a list.
`n.divisorsAntidiagonalList` is the list of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`, ordered
by increasing `a`. By convention, we set `Nat.divisorsAntidiagonalList 0 = []`.
-/
def divisorsAntidiagonalList (n : ℕ) : List (ℕ × ℕ) :=
(List.range' 1 n).filterMap
| (fun x ↦ let y := n / x; if x * y = n then some (x, y) else none)
variable {n}
@[simp]
| Mathlib/NumberTheory/Divisors.lean | 68 | 72 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Data.Countable.Small
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Fintype.Powerset
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Set.Countable
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Logic.Small.Set
import Mathlib.Logic.UnivLE
import Mathlib.SetTheory.Cardinal.Order
/-!
# Basic results on cardinal numbers
We provide a collection of basic results on cardinal numbers, in particular focussing on
finite/countable/small types and sets.
## Main definitions
* `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`.
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, aleph,
Cantor's theorem, König's theorem, Konig's theorem
-/
assert_not_exists Field
open List (Vector)
open Function Order Set
noncomputable section
universe u v w v' w'
variable {α β : Type u}
namespace Cardinal
/-! ### Lifting cardinals to a higher universe -/
@[simp]
lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by
rw [← mk_uLift, Cardinal.eq]
constructor
let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x)
have : Function.Bijective f :=
ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective))
exact Equiv.ofBijective f this
-- `simp` can't figure out universe levels: normal form is `lift_mk_shrink'`.
theorem lift_mk_shrink (α : Type u) [Small.{v} α] :
Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α :=
lift_mk_eq.2 ⟨(equivShrink α).symm⟩
@[simp]
theorem lift_mk_shrink' (α : Type u) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α :=
lift_mk_shrink.{u, v, 0} α
@[simp]
theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = #α := by
rw [← lift_umax, lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id]
theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) :
prod f = Cardinal.lift.{u} (∏ i, f i) := by
revert f
refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h)
· intro α β hβ e h f
letI := Fintype.ofEquiv β e.symm
rw [← e.prod_comp f, ← h]
exact mk_congr (e.piCongrLeft _).symm
· intro f
rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one]
· intro α hα h f
rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax.{v, u}, mk_out, ←
Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)]
simp only [lift_id]
/-! ### Basic cardinals -/
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α :=
⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ =>
⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩
@[simp]
theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton :=
le_one_iff_subsingleton.trans s.subsingleton_coe
alias ⟨_, _root_.Set.Subsingleton.cardinalMk_le_one⟩ := mk_le_one_iff_set_subsingleton
@[deprecated (since := "2024-11-10")]
alias _root_.Set.Subsingleton.cardinal_mk_le_one := Set.Subsingleton.cardinalMk_le_one
private theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by
change #(ULift.{u} _) = #(ULift.{u} _) + 1
rw [← mk_option]
simp
/-! ### Order properties -/
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by
rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not]
lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases s.eq_empty_or_nonempty with rfl | hne
· exact Or.inl rfl
· exact Or.inr ⟨sInf s, csInf_mem hne, h⟩
· rcases h with rfl | ⟨a, ha, rfl⟩
· exact Cardinal.sInf_empty
· exact eq_bot_iff.2 (csInf_le' ha)
lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} :
(⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by
simp [iInf, sInf_eq_zero_iff]
/-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/
protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 :=
ciSup_of_empty f
@[simp]
theorem lift_sInf (s : Set Cardinal) : lift.{u, v} (sInf s) = sInf (lift.{u, v} '' s) := by
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp
· exact lift_monotone.map_csInf hs
@[simp]
theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u, v} (iInf f) = ⨅ i, lift.{u, v} (f i) := by
unfold iInf
convert lift_sInf (range f)
simp_rw [← comp_apply (f := lift), range_comp]
end Cardinal
/-! ### Small sets of cardinals -/
namespace Cardinal
instance small_Iic (a : Cardinal.{u}) : Small.{u} (Iic a) := by
rw [← mk_out a]
apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩
rintro ⟨x, hx⟩
simpa using le_mk_iff_exists_set.1 hx
instance small_Iio (a : Cardinal.{u}) : Small.{u} (Iio a) := small_subset Iio_subset_Iic_self
instance small_Icc (a b : Cardinal.{u}) : Small.{u} (Icc a b) := small_subset Icc_subset_Iic_self
instance small_Ico (a b : Cardinal.{u}) : Small.{u} (Ico a b) := small_subset Ico_subset_Iio_self
instance small_Ioc (a b : Cardinal.{u}) : Small.{u} (Ioc a b) := small_subset Ioc_subset_Iic_self
instance small_Ioo (a b : Cardinal.{u}) : Small.{u} (Ioo a b) := small_subset Ioo_subset_Iio_self
/-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/
theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun _ h => ha h) _, by
rintro ⟨ι, ⟨e⟩⟩
use sum.{u, u} fun x ↦ e.symm x
intro a ha
simpa using le_sum (fun x ↦ e.symm x) (e ⟨a, ha⟩)⟩
theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
theorem bddAbove_range {ι : Type*} [Small.{u} ι] (f : ι → Cardinal.{u}) : BddAbove (Set.range f) :=
bddAbove_of_small _
theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}}
(hs : BddAbove s) : BddAbove (f '' s) := by
rw [bddAbove_iff_small] at hs ⊢
exact small_lift _
theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f))
(g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by
rw [range_comp]
exact bddAbove_image g hf
/-- The type of cardinals in universe `u` is not `Small.{u}`. This is a version of the Burali-Forti
paradox. -/
theorem _root_.not_small_cardinal : ¬ Small.{u} Cardinal.{max u v} := by
intro h
have := small_lift.{_, v} Cardinal.{max u v}
rw [← small_univ_iff, ← bddAbove_iff_small] at this
exact not_bddAbove_univ this
instance uncountable : Uncountable Cardinal.{u} :=
Uncountable.of_not_small not_small_cardinal.{u}
/-! ### Bounds on suprema -/
theorem sum_le_iSup_lift {ι : Type u}
(f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift #ι * iSup f := by
rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const]
exact sum_le_sum _ _ (le_ciSup <| bddAbove_of_small _)
theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by
rw [← lift_id #ι]
exact sum_le_iSup_lift f
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) :
lift.{u} (sSup s) = sSup (lift.{u} '' s) := by
apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _)
· intro c hc
by_contra h
obtain ⟨d, rfl⟩ := Cardinal.mem_range_lift_of_le (not_le.1 h).le
simp_rw [lift_le] at h hc
rw [csSup_le_iff' hs] at h
exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha)
· rintro i ⟨j, hj, rfl⟩
exact lift_le.2 (le_csSup hs hj)
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) :
lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by
rw [iSup, iSup, lift_sSup hf, ← range_comp]
simp [Function.comp_def]
/-- To prove that the lift of a supremum is bounded by some cardinal `t`,
it suffices to show that the lift of each cardinal is bounded by `t`. -/
theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f))
(w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le' w
@[simp]
theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f))
{t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _)
/-- To prove an inequality between the lifts to a common universe of two different supremums,
it suffices to show that the lift of each cardinal from the smaller supremum
if bounded by the lift of some cardinal from the larger supremum.
-/
theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}}
{f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'}
(h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by
rw [lift_iSup hf, lift_iSup hf']
exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩
/-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`.
This is sometimes necessary to avoid universe unification issues. -/
theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}}
{f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι')
(h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') :=
lift_iSup_le_lift_iSup hf hf' h
/-! ### Properties about the cast from `ℕ` -/
theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by
simp [Pow.pow]
@[norm_cast]
theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by
rw [Nat.cast_succ]
refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_)
rw [← Nat.cast_succ]
exact Nat.cast_lt.2 (Nat.lt_succ_self _)
lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by
rw [← Cardinal.nat_succ]
norm_cast
lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by
rw [← Order.succ_le_iff, Cardinal.succ_natCast]
lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by
convert natCast_add_one_le_iff
norm_cast
@[simp]
theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast
-- This works generally to prove inequalities between numeric cardinals.
theorem one_lt_two : (1 : Cardinal) < 2 := by norm_cast
theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) :
∃ s : Finset α, n ≤ s.card := by
obtain hα|hα := finite_or_infinite α
· let hα := Fintype.ofFinite α
use Finset.univ
simpa only [mk_fintype, Nat.cast_le] using h
· obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n
exact ⟨s, hs.ge⟩
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by
contrapose! H
apply exists_finset_le_card α (n+1)
simpa only [nat_succ, succ_le_iff] using H
theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by
rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb
exact (cantor a).trans_le (power_le_power_right hb)
theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by
rw [← succ_zero, succ_le_iff]
theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by
rw [one_le_iff_pos, pos_iff_ne_zero]
@[simp]
theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by
simpa using lt_succ_bot_iff (a := c)
/-! ### Properties about `aleph0` -/
theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ :=
succ_le_iff.1
(by
rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}]
exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩)
@[simp]
theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1
@[simp]
theorem one_le_aleph0 : 1 ≤ ℵ₀ :=
one_lt_aleph0.le
theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n :=
⟨fun h => by
rcases lt_lift_iff.1 h with ⟨c, h', rfl⟩
rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩
suffices S.Finite by
lift S to Finset ℕ using this
simp
contrapose! h'
haveI := Infinite.to_subtype h'
exact ⟨Infinite.natEmbedding S⟩, fun ⟨_, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩
lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by
obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h
rw [hn, succ_natCast]
theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c :=
⟨fun h _ => (nat_lt_aleph0 _).le.trans h, fun h =>
le_of_not_lt fun hn => by
rcases lt_aleph0.1 hn with ⟨n, rfl⟩
exact (Nat.lt_succ_self _).not_le (Nat.cast_le.1 (h (n + 1)))⟩
theorem isSuccPrelimit_aleph0 : IsSuccPrelimit ℵ₀ :=
isSuccPrelimit_of_succ_lt fun a ha => by
rcases lt_aleph0.1 ha with ⟨n, rfl⟩
rw [← nat_succ]
apply nat_lt_aleph0
theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := by
rw [Cardinal.isSuccLimit_iff]
exact ⟨aleph0_ne_zero, isSuccPrelimit_aleph0⟩
lemma not_isSuccLimit_natCast : (n : ℕ) → ¬ IsSuccLimit (n : Cardinal.{u})
| 0, e => e.1 isMin_bot
| Nat.succ n, e => Order.not_isSuccPrelimit_succ _ (nat_succ n ▸ e.2)
theorem not_isSuccLimit_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ¬ IsSuccLimit c := by
obtain ⟨n, rfl⟩ := lt_aleph0.1 h
exact not_isSuccLimit_natCast n
theorem aleph0_le_of_isSuccLimit {c : Cardinal} (h : IsSuccLimit c) : ℵ₀ ≤ c := by
contrapose! h
exact not_isSuccLimit_of_lt_aleph0 h
theorem isStrongLimit_aleph0 : IsStrongLimit ℵ₀ := by
refine ⟨aleph0_ne_zero, fun x hx ↦ ?_⟩
obtain ⟨n, rfl⟩ := lt_aleph0.1 hx
exact_mod_cast nat_lt_aleph0 _
theorem IsStrongLimit.aleph0_le {c} (H : IsStrongLimit c) : ℵ₀ ≤ c :=
aleph0_le_of_isSuccLimit H.isSuccLimit
lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v})
(hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n :=
exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f hf (not_isSuccLimit_natCast n) h
@[simp]
theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ :=
ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0]
theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by
rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq']
theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by
simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin]
theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) :=
lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _)
theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ :=
lt_aleph0_iff_finite.2 ‹_›
theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite :=
lt_aleph0_iff_finite.trans finite_coe_iff
alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite
@[simp]
theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite :=
lt_aleph0_iff_set_finite
theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by
rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le']
@[simp]
theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ :=
mk_le_aleph0_iff.mpr ‹_›
theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff
alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable
@[simp]
theorem le_aleph0_iff_subtype_countable {p : α → Prop} :
#{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable :=
le_aleph0_iff_set_countable
theorem aleph0_lt_mk_iff : ℵ₀ < #α ↔ Uncountable α := by
rw [← not_le, ← not_countable_iff, not_iff_not, mk_le_aleph0_iff]
@[simp]
theorem aleph0_lt_mk [Uncountable α] : ℵ₀ < #α :=
aleph0_lt_mk_iff.mpr ‹_›
instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ :=
⟨fun _ hx =>
let ⟨n, hn⟩ := lt_aleph0.mp hx
⟨n, hn.symm⟩⟩
theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0
theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ :=
⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩,
fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩
theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by
simp only [← not_lt, add_lt_aleph0_iff, not_and_or]
/-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/
theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by
cases n with
| zero => simpa using nat_lt_aleph0 0
| succ n =>
simp only [Nat.succ_ne_zero, false_or]
induction' n with n ih
· simp
rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff]
/-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/
theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ :=
nsmul_lt_aleph0_iff.trans <| or_iff_right h
theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0
theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by
refine ⟨fun h => ?_, ?_⟩
· by_cases ha : a = 0
· exact Or.inl ha
right
by_cases hb : b = 0
· exact Or.inl hb
right
rw [← Ne, ← one_le_iff_ne_zero] at ha hb
constructor
· rw [← mul_one a]
exact (mul_le_mul' le_rfl hb).trans_lt h
· rw [← one_mul b]
exact (mul_le_mul' ha le_rfl).trans_lt h
rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero]
/-- See also `Cardinal.aleph0_le_mul_iff`. -/
theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by
let h := (@mul_lt_aleph0_iff a b).not
rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h
/-- See also `Cardinal.aleph0_le_mul_iff'`. -/
theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by
have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a
simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)]
simp only [and_comm, or_comm]
theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb]
theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [power_natCast, ← Nat.cast_pow]; apply nat_lt_aleph0
theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α :=
calc
#α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff
_ ↔ Subsingleton α ∧ Nonempty α :=
le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff)
theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by
rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite]
lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm
lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff]
@[simp] lemma mk_lt_aleph0 [Finite α] : #α < ℵ₀ := mk_lt_aleph0_iff.2 ‹_›
@[simp]
theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α :=
infinite_iff.1 ‹_›
@[simp]
theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ :=
mk_le_aleph0.antisymm <| aleph0_le_mk _
theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ :=
⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by
obtain ⟨f⟩ := Quotient.exact h
exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩
theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ :=
denumerable_iff.1 ⟨‹_›⟩
theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} :
s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by
rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff]
@[simp]
theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ :=
mk_denumerable _
theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ :=
mk_denumerable _
@[simp]
theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ :=
le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <|
le_mul_of_one_le_left (zero_le _) <| by
rwa [← Nat.cast_one, Nat.cast_le, Nat.one_le_iff_ne_zero]
@[simp]
theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn]
@[simp]
theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) * ℵ₀ = ℵ₀ :=
nat_mul_aleph0 (NeZero.ne n)
@[simp]
theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * ofNat(n) = ℵ₀ :=
aleph0_mul_nat (NeZero.ne n)
@[simp]
theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ :=
⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h =>
aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩
@[simp]
theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ :=
(add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add
@[simp]
theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat]
@[simp]
theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) + ℵ₀ = ℵ₀ :=
nat_add_aleph0 n
@[simp]
theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + ofNat(n) = ℵ₀ :=
aleph0_add_nat n
theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by
lift c to ℕ using h.trans_lt (nat_lt_aleph0 _)
exact ⟨c, mod_cast h, rfl⟩
theorem mk_int : #ℤ = ℵ₀ :=
mk_denumerable ℤ
theorem mk_pnat : #ℕ+ = ℵ₀ :=
mk_denumerable ℕ+
@[deprecated (since := "2025-04-27")]
alias mk_pNat := mk_pnat
/-! ### Cardinalities of basic sets and types -/
@[simp] theorem mk_additive : #(Additive α) = #α := rfl
@[simp] theorem mk_multiplicative : #(Multiplicative α) = #α := rfl
@[to_additive (attr := simp)] theorem mk_mulOpposite : #(MulOpposite α) = #α :=
mk_congr MulOpposite.opEquiv.symm
theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 :=
mk_eq_one _
@[simp]
theorem mk_vector (α : Type u) (n : ℕ) : #(List.Vector α n) = #α ^ n :=
(mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp
theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n :=
calc
#(List α) = #(Σn, List.Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm
_ = sum fun n : ℕ => #α ^ n := by simp
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α :=
mk_le_of_surjective Quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α :=
mk_quot_le
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
#(Subtype p) ≤ #(Subtype q) :=
⟨Embedding.subtypeMap (Embedding.refl α) h⟩
theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 :=
mk_eq_zero _
theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by
constructor
· intro h
rw [mk_eq_zero_iff] at h
exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩
· rintro rfl
exact mk_emptyCollection _
@[simp]
theorem mk_univ {α : Type u} : #(@univ α) = #α :=
mk_congr (Equiv.Set.univ α)
@[simp] lemma mk_setProd {α β : Type u} (s : Set α) (t : Set β) : #(s ×ˢ t) = #s * #t := by
rw [mul_def, mk_congr (Equiv.Set.prod ..)]
theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s :=
mk_le_of_surjective surjective_onto_image
lemma mk_image2_le {α β γ : Type u} {f : α → β → γ} {s : Set α} {t : Set β} :
#(image2 f s t) ≤ #s * #t := by
rw [← image_uncurry_prod, ← mk_setProd]
exact mk_image_le
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} :
lift.{u} #(f '' s) ≤ lift.{v} #s :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α :=
mk_le_of_surjective surjective_onto_range
theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} :
lift.{u} #(range f) ≤ lift.{v} #α :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩
theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α :=
mk_congr (Equiv.ofInjective f h).symm
theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{max u w} #(range f) = lift.{max v w} #α :=
lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩
theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{u} #(range f) = lift.{v} #α :=
lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩
lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by
rw [← Cardinal.mk_range_eq_of_injective hf]
exact Cardinal.lift_le.2 (Cardinal.mk_set_le _)
lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) :
Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) :=
lift_mk_le_lift_mk_of_injective (injective_surjInv hf)
theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) :
#(f '' s) = #s :=
mk_congr (Equiv.Set.imageOfInjOn f s h).symm
theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α)
(h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s :=
lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s :=
mk_image_eq_of_injOn _ _ hf.injOn
theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) :
lift.{u} #(f '' s) = lift.{v} #s :=
mk_image_eq_of_injOn_lift _ _ h.injOn
@[simp]
theorem mk_image_embedding_lift {β : Type v} (f : α ↪ β) (s : Set α) :
lift.{u} #(f '' s) = lift.{v} #s :=
mk_image_eq_lift _ _ f.injective
@[simp]
theorem mk_image_embedding (f : α ↪ β) (s : Set α) : #(f '' s) = #s := by
simpa using mk_image_embedding_lift f s
theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
#(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} :
lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) :=
mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α}
(h : Pairwise (Disjoint on f)) : #(⋃ i, f i) = sum fun i => #(f i) :=
calc
#(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α}
(h : Pairwise (Disjoint on f)) :
lift.{v} #(⋃ i, f i) = sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) = #(Σi, f i) :=
mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) :=
mk_iUnion_le_sum_mk.trans (sum_le_iSup _)
theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) :
lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by
refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _)
rw [← lift_sum, lift_id'.{_,u}]
theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by
rw [sUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) :
#(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) :
lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le_lift
theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ :=
lt_aleph0_of_finite _
theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} :
#s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by
constructor
· intro h
lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n)
simpa using h
· rintro ⟨t, rfl, rfl⟩
exact mk_coe_finset
theorem mk_eq_nat_iff_finset {n : ℕ} :
#α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by
rw [← mk_univ, mk_set_eq_nat_iff_finset]
theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by
rw [mk_eq_nat_iff_finset]
constructor
· rintro ⟨t, ht, hn⟩
exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩
· rintro ⟨⟨t, ht⟩, hn⟩
exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩
theorem mk_union_add_mk_inter {α : Type u} {S T : Set α} :
#(S ∪ T : Set α) + #(S ∩ T : Set α) = #S + #T := by
classical
exact Quot.sound ⟨Equiv.Set.unionSumInter S T⟩
/-- The cardinality of a union is at most the sum of the cardinalities
of the two sets. -/
theorem mk_union_le {α : Type u} (S T : Set α) : #(S ∪ T : Set α) ≤ #S + #T :=
@mk_union_add_mk_inter α S T ▸ self_le_add_right #(S ∪ T : Set α) #(S ∩ T : Set α)
theorem mk_union_of_disjoint {α : Type u} {S T : Set α} (H : Disjoint S T) :
#(S ∪ T : Set α) = #S + #T := by
classical
exact Quot.sound ⟨Equiv.Set.union H⟩
theorem mk_insert {α : Type u} {s : Set α} {a : α} (h : a ∉ s) :
#(insert a s : Set α) = #s + 1 := by
rw [← union_singleton, mk_union_of_disjoint, mk_singleton]
simpa
theorem mk_insert_le {α : Type u} {s : Set α} {a : α} : #(insert a s : Set α) ≤ #s + 1 := by
by_cases h : a ∈ s
· simp only [insert_eq_of_mem h, self_le_add_right]
· rw [mk_insert h]
theorem mk_sum_compl {α} (s : Set α) : #s + #(sᶜ : Set α) = #α := by
classical
exact mk_congr (Equiv.Set.sumCompl s)
theorem mk_le_mk_of_subset {α} {s t : Set α} (h : s ⊆ t) : #s ≤ #t :=
⟨Set.embeddingOfSubset s t h⟩
theorem mk_le_iff_forall_finset_subset_card_le {α : Type u} {n : ℕ} {t : Set α} :
#t ≤ n ↔ ∀ s : Finset α, (s : Set α) ⊆ t → s.card ≤ n := by
refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩
apply card_le_of (fun s ↦ ?_)
classical
let u : Finset α := s.image Subtype.val
have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn
rw [← this]
apply H
simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ]
theorem mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) :
#{ x // p x } ≤ #{ x // q x } :=
⟨embeddingOfSubset _ _ h⟩
theorem le_mk_diff_add_mk (S T : Set α) : #S ≤ #(S \ T : Set α) + #T :=
(mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _
theorem mk_diff_add_mk {S T : Set α} (h : T ⊆ S) : #(S \ T : Set α) + #T = #S := by
refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h]
exact disjoint_sdiff_self_left
theorem mk_union_le_aleph0 {α} {P Q : Set α} :
#(P ∪ Q : Set α) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ := by
simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def,
← countable_union]
theorem mk_sep (s : Set α) (t : α → Prop) : #({ x ∈ s | t x } : Set α) = #{ x : s | t x.1 } :=
mk_congr (Equiv.Set.sep s t)
theorem mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) : lift.{v} #(f ⁻¹' s) ≤ lift.{u} #s := by
rw [lift_mk_le.{0}]
-- Porting note: Needed to insert `mem_preimage.mp` below
use Subtype.coind (fun x => f x.1) fun x => mem_preimage.mp x.2
apply Subtype.coind_injective; exact h.comp Subtype.val_injective
theorem mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : s ⊆ range f) : lift.{u} #s ≤ lift.{v} #(f ⁻¹' s) := by
rw [← image_preimage_eq_iff] at h
nth_rewrite 1 [← h]
apply mk_image_le_lift
theorem mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) (h2 : s ⊆ range f) : lift.{v} #(f ⁻¹' s) = lift.{u} #s :=
le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2)
theorem mk_preimage_of_injective_of_subset_range (f : α → β) (s : Set β) (h : Injective f)
(h2 : s ⊆ range f) : #(f ⁻¹' s) = #s := by
convert mk_preimage_of_injective_of_subset_range_lift.{u, u} f s h h2 using 1 <;> rw [lift_id]
@[simp]
theorem mk_preimage_equiv_lift {β : Type v} (f : α ≃ β) (s : Set β) :
lift.{v} #(f ⁻¹' s) = lift.{u} #s := by
apply mk_preimage_of_injective_of_subset_range_lift _ _ f.injective
rw [f.range_eq_univ]
exact fun _ _ ↦ ⟨⟩
@[simp]
theorem mk_preimage_equiv (f : α ≃ β) (s : Set β) : #(f ⁻¹' s) = #s := by
simpa using mk_preimage_equiv_lift f s
theorem mk_preimage_of_injective (f : α → β) (s : Set β) (h : Injective f) :
#(f ⁻¹' s) ≤ #s := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_injective_lift f s h
theorem mk_preimage_of_subset_range (f : α → β) (s : Set β) (h : s ⊆ range f) :
#s ≤ #(f ⁻¹' s) := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_subset_range_lift f s h
theorem mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : Set α}
{t : Set β} (h : t ⊆ f '' s) : lift.{u} #t ≤ lift.{v} #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range_lift _ _ h using 1
rw [mk_sep]
rfl
theorem mk_subset_ge_of_subset_image (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) :
#t ≤ #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range _ _ h using 1
rw [mk_sep]
rfl
theorem le_mk_iff_exists_subset {c : Cardinal} {α : Type u} {s : Set α} :
c ≤ #s ↔ ∃ p : Set α, p ⊆ s ∧ #p = c := by
rw [le_mk_iff_exists_set, ← Subtype.exists_set_subtype]
apply exists_congr; intro t; rw [mk_image_eq]; apply Subtype.val_injective
@[simp]
theorem mk_range_inl {α : Type u} {β : Type v} : #(range (@Sum.inl α β)) = lift.{v} #α := by
rw [← lift_id'.{u, v} #_, (Equiv.Set.rangeInl α β).lift_cardinal_eq, lift_umax.{u, v}]
@[simp]
theorem mk_range_inr {α : Type u} {β : Type v} : #(range (@Sum.inr α β)) = lift.{u} #β := by
rw [← lift_id'.{v, u} #_, (Equiv.Set.rangeInr α β).lift_cardinal_eq, lift_umax.{v, u}]
theorem two_le_iff : (2 : Cardinal) ≤ #α ↔ ∃ x y : α, x ≠ y := by
rw [← Nat.cast_two, nat_succ, succ_le_iff, Nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff]
theorem two_le_iff' (x : α) : (2 : Cardinal) ≤ #α ↔ ∃ y : α, y ≠ x := by
rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x]
theorem mk_eq_two_iff : #α = 2 ↔ ∃ x y : α, x ≠ y ∧ ({x, y} : Set α) = univ := by
classical
simp only [← @Nat.cast_two Cardinal, mk_eq_nat_iff_finset, Finset.card_eq_two]
constructor
· rintro ⟨t, ht, x, y, hne, rfl⟩
exact ⟨x, y, hne, by simpa using ht⟩
· rintro ⟨x, y, hne, h⟩
exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩
theorem mk_eq_two_iff' (x : α) : #α = 2 ↔ ∃! y, y ≠ x := by
rw [mk_eq_two_iff]; constructor
· rintro ⟨a, b, hne, h⟩
simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h
rcases h x with (rfl | rfl)
exacts [⟨b, hne.symm, fun z => (h z).resolve_left⟩, ⟨a, hne, fun z => (h z).resolve_right⟩]
· rintro ⟨y, hne, hy⟩
exact ⟨x, y, hne.symm, eq_univ_of_forall fun z => or_iff_not_imp_left.2 (hy z)⟩
theorem exists_not_mem_of_length_lt {α : Type*} (l : List α) (h : ↑l.length < #α) :
∃ z : α, z ∉ l := by
classical
contrapose! h
calc
#α = #(Set.univ : Set α) := mk_univ.symm
_ ≤ #l.toFinset := mk_le_mk_of_subset fun x _ => List.mem_toFinset.mpr (h x)
_ = l.toFinset.card := Cardinal.mk_coe_finset
_ ≤ l.length := Nat.cast_le.mpr (List.toFinset_card_le l)
theorem three_le {α : Type*} (h : 3 ≤ #α) (x : α) (y : α) : ∃ z : α, z ≠ x ∧ z ≠ y := by
have : ↑(3 : ℕ) ≤ #α := by simpa using h
have : ↑(2 : ℕ) < #α := by rwa [← succ_le_iff, ← Cardinal.nat_succ]
have := exists_not_mem_of_length_lt [x, y] this
simpa [not_or] using this
/-! ### `powerlt` operation -/
/-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/
def powerlt (a b : Cardinal.{u}) : Cardinal.{u} :=
⨆ c : Iio b, a ^ (c : Cardinal)
@[inherit_doc]
infixl:80 " ^< " => powerlt
theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≤ a ^< b := by
refine le_ciSup (f := fun y : Iio b => a ^ (y : Cardinal)) ?_ ⟨c, h⟩
rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c := by
rw [powerlt, ciSup_le_iff']
· simp
· rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
powerlt_le.2 fun _ hx => le_powerlt a <| hx.trans_le h
theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left
theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = a ^ b :=
(powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <|
le_powerlt a (lt_succ b)
theorem powerlt_min {a b c : Cardinal} : a ^< min b c = min (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_min
theorem powerlt_max {a b c : Cardinal} : a ^< max b c = max (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_max
theorem zero_powerlt {a : Cardinal} (h : a ≠ 0) : 0 ^< a = 1 := by
apply (powerlt_le.2 fun c _ => zero_power_le _).antisymm
rw [← power_zero]
exact le_powerlt 0 (pos_iff_ne_zero.2 h)
@[simp]
theorem powerlt_zero {a : Cardinal} : a ^< 0 = 0 := by
convert Cardinal.iSup_of_empty _
exact Subtype.isEmpty_of_false fun x => mem_Iio.not.mpr (Cardinal.zero_le x).not_lt
end Cardinal
| Mathlib/SetTheory/Cardinal/Basic.lean | 1,534 | 1,534 | |
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Sites.CompatiblePlus
import Mathlib.CategoryTheory.Sites.ConcreteSheafification
/-!
In this file, we prove that sheafification is compatible with functors which
preserve the correct limits and colimits.
-/
namespace CategoryTheory.GrothendieckTopology
open CategoryTheory
open CategoryTheory.Limits
open Opposite
universe w₁ w₂ v u
variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C)
variable {D : Type w₁} [Category.{max v u} D]
variable {E : Type w₂} [Category.{max v u} E]
variable (F : D ⥤ E)
variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) D]
variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) E]
variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D]
variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ E]
variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ F]
variable [∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F]
variable (P : Cᵒᵖ ⥤ D)
/-- The isomorphism between the sheafification of `P` composed with `F` and
the sheafification of `P ⋙ F`.
Use the lemmas `whisker_right_to_sheafify_sheafify_comp_iso_hom`,
`to_sheafify_comp_sheafify_comp_iso_inv` and `sheafify_comp_iso_inv_eq_sheafify_lift` to reduce
the components of this isomorphisms to a state that can be handled using the universal property
of sheafification. -/
noncomputable def sheafifyCompIso : J.sheafify P ⋙ F ≅ J.sheafify (P ⋙ F) :=
J.plusCompIso _ _ ≪≫ (J.plusFunctor _).mapIso (J.plusCompIso _ _)
/-- The isomorphism between the sheafification of `P` composed with `F` and
the sheafification of `P ⋙ F`, functorially in `F`. -/
noncomputable def sheafificationWhiskerLeftIso (P : Cᵒᵖ ⥤ D)
[∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F]
[∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D),
PreservesLimit (W.index P).multicospan F] :
(whiskeringLeft _ _ E).obj (J.sheafify P) ≅
(whiskeringLeft _ _ _).obj P ⋙ J.sheafification E := by
refine J.plusFunctorWhiskerLeftIso _ ≪≫ ?_ ≪≫ Functor.associator _ _ _
refine isoWhiskerRight ?_ _
exact J.plusFunctorWhiskerLeftIso _
@[simp]
theorem sheafificationWhiskerLeftIso_hom_app (P : Cᵒᵖ ⥤ D) (F : D ⥤ E)
[∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F]
[∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D),
PreservesLimit (W.index P).multicospan F] :
(sheafificationWhiskerLeftIso J P).hom.app F = (J.sheafifyCompIso F P).hom := by
dsimp [sheafificationWhiskerLeftIso, sheafifyCompIso]
rw [Category.comp_id]
@[simp]
theorem sheafificationWhiskerLeftIso_inv_app (P : Cᵒᵖ ⥤ D) (F : D ⥤ E)
[∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F]
[∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D),
PreservesLimit (W.index P).multicospan F] :
(sheafificationWhiskerLeftIso J P).inv.app F = (J.sheafifyCompIso F P).inv := by
dsimp [sheafificationWhiskerLeftIso, sheafifyCompIso]
erw [Category.id_comp]
/-- The isomorphism between the sheafification of `P` composed with `F` and
the sheafification of `P ⋙ F`, functorially in `P`. -/
noncomputable def sheafificationWhiskerRightIso :
J.sheafification D ⋙ (whiskeringRight _ _ _).obj F ≅
(whiskeringRight _ _ _).obj F ⋙ J.sheafification E := by
refine Functor.associator _ _ _ ≪≫ ?_
refine isoWhiskerLeft (J.plusFunctor D) (J.plusFunctorWhiskerRightIso _) ≪≫ ?_
refine ?_ ≪≫ Functor.associator _ _ _
refine (Functor.associator _ _ _).symm ≪≫ ?_
exact isoWhiskerRight (J.plusFunctorWhiskerRightIso _) (J.plusFunctor E)
@[simp]
theorem sheafificationWhiskerRightIso_hom_app :
(J.sheafificationWhiskerRightIso F).hom.app P = (J.sheafifyCompIso F P).hom := by
dsimp [sheafificationWhiskerRightIso, sheafifyCompIso]
simp only [Category.id_comp, Category.comp_id]
erw [Category.id_comp]
@[simp]
theorem sheafificationWhiskerRightIso_inv_app :
(J.sheafificationWhiskerRightIso F).inv.app P = (J.sheafifyCompIso F P).inv := by
dsimp [sheafificationWhiskerRightIso, sheafifyCompIso]
simp only [Category.id_comp, Category.comp_id]
erw [Category.id_comp]
@[simp, reassoc]
theorem whiskerRight_toSheafify_sheafifyCompIso_hom :
whiskerRight (J.toSheafify _) _ ≫ (J.sheafifyCompIso F P).hom = J.toSheafify _ := by
dsimp [sheafifyCompIso]
erw [whiskerRight_comp, Category.assoc]
| slice_lhs 2 3 => rw [plusCompIso_whiskerRight]
rw [Category.assoc, ← J.plusMap_comp, whiskerRight_toPlus_comp_plusCompIso_hom, ←
Category.assoc, whiskerRight_toPlus_comp_plusCompIso_hom]
rfl
| Mathlib/CategoryTheory/Sites/CompatibleSheafification.lean | 110 | 114 |
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.Order.Module.Defs
/-!
# Ordered algebras
This file proves properties of algebras where both rings are ordered compatibly.
## TODO
`positivity` extension for `algebraMap`
-/
variable {α β : Type*} [CommSemiring α] [PartialOrder α]
section OrderedSemiring
variable (β)
variable [Semiring β] [PartialOrder β] [IsOrderedRing β] [Algebra α β] [SMulPosMono α β] {a : α}
@[mono] lemma algebraMap_mono : Monotone (algebraMap α β) :=
fun a₁ a₂ ha ↦ by
simpa only [Algebra.algebraMap_eq_smul_one] using smul_le_smul_of_nonneg_right ha zero_le_one
/-- A version of `algebraMap_mono` for use by `gcongr` since it currently does not preprocess
`Monotone` conclusions. -/
@[gcongr] protected lemma GCongr.algebraMap_le_algebraMap {a₁ a₂ : α} (ha : a₁ ≤ a₂) :
algebraMap α β a₁ ≤ algebraMap α β a₂ := algebraMap_mono _ ha
lemma algebraMap_nonneg (ha : 0 ≤ a) : 0 ≤ algebraMap α β a := by simpa using algebraMap_mono β ha
end OrderedSemiring
section StrictOrderedSemiring
variable [Semiring β] [PartialOrder β] [IsStrictOrderedRing β] [Algebra α β]
section SMulPosMono
variable [SMulPosMono α β] [SMulPosReflectLE α β] {a₁ a₂ : α}
@[simp] lemma algebraMap_le_algebraMap : algebraMap α β a₁ ≤ algebraMap α β a₂ ↔ a₁ ≤ a₂ := by
simp [Algebra.algebraMap_eq_smul_one]
end SMulPosMono
section SMulPosStrictMono
variable [SMulPosStrictMono α β] {a a₁ a₂ : α}
variable (β)
| @[mono] lemma algebraMap_strictMono : StrictMono (algebraMap α β) :=
fun a₁ a₂ ha ↦ by
simpa only [Algebra.algebraMap_eq_smul_one] using smul_lt_smul_of_pos_right ha zero_lt_one
| Mathlib/Algebra/Order/Module/Algebra.lean | 53 | 55 |
/-
Copyright (c) 2020 Jean Lo, Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Yury Kudryashov
-/
import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set
import Mathlib.Algebra.Ring.Action.Pointwise.Set
import Mathlib.Topology.Bornology.Basic
/-!
# Absorption of sets
Let `M` act on `α`, let `A` and `B` be sets in `α`.
We say that `A` *absorbs* `B` if for sufficiently large `a : M`, we have `B ⊆ a • A`.
Formally, "for sufficiently large `a : M`" means "for all but a bounded set of `a`".
Traditionally, this definition is formulated
for the action of a (semi)normed ring on a module over that ring.
We formulate it in a more general settings for two reasons:
- this way we don't have to depend on metric spaces, normed rings etc;
- some proofs look nicer with this definition than with something like
`∃ r : ℝ, ∀ a : R, r ≤ ‖a‖ → B ⊆ a • A`.
If `M` is a `GroupWithZero` (e.g., a division ring),
the sets absorbing a given set form a filter, see `Filter.absorbing`.
## Implementation notes
For now, all theorems assume that we deal with (a generalization of) a module over a division ring.
Some lemmas have multiplicative versions for `MulDistribMulAction`s.
They can be added later when someone needs them.
## Keywords
absorbs, absorbent
-/
assert_not_exists Real
open Set Bornology Filter
open scoped Pointwise
section Defs
variable (M : Type*) {α : Type*} [Bornology M] [SMul M α]
/-- A set `s` absorbs another set `t` if `t` is contained in all scalings of `s`
by all but a bounded set of elements. -/
def Absorbs (s t : Set α) : Prop :=
∀ᶠ a in cobounded M, t ⊆ a • s
/-- A set is *absorbent* if it absorbs every singleton. -/
def Absorbent (s : Set α) : Prop :=
∀ x, Absorbs M s {x}
end Defs
namespace Absorbs
section SMul
variable {M α : Type*} [Bornology M] [SMul M α] {s s₁ s₂ t t₁ t₂ : Set α} {S T : Set (Set α)}
protected lemma empty : Absorbs M s ∅ := by simp [Absorbs]
protected lemma eventually (h : Absorbs M s t) : ∀ᶠ a in cobounded M, t ⊆ a • s := h
@[simp] lemma of_boundedSpace [BoundedSpace M] : Absorbs M s t := by simp [Absorbs]
lemma mono_left (h : Absorbs M s₁ t) (hs : s₁ ⊆ s₂) : Absorbs M s₂ t :=
h.mono fun _a ha ↦ ha.trans <| smul_set_mono hs
lemma mono_right (h : Absorbs M s t₁) (ht : t₂ ⊆ t₁) : Absorbs M s t₂ :=
h.mono fun _ ↦ ht.trans
lemma mono (h : Absorbs M s₁ t₁) (hs : s₁ ⊆ s₂) (ht : t₂ ⊆ t₁) : Absorbs M s₂ t₂ :=
(h.mono_left hs).mono_right ht
@[simp]
lemma _root_.absorbs_union : Absorbs M s (t₁ ∪ t₂) ↔ Absorbs M s t₁ ∧ Absorbs M s t₂ := by
simp [Absorbs]
protected lemma union (h₁ : Absorbs M s t₁) (h₂ : Absorbs M s t₂) : Absorbs M s (t₁ ∪ t₂) :=
absorbs_union.2 ⟨h₁, h₂⟩
lemma _root_.Set.Finite.absorbs_sUnion {T : Set (Set α)} (hT : T.Finite) :
Absorbs M s (⋃₀ T) ↔ ∀ t ∈ T, Absorbs M s t := by
simp [Absorbs, hT]
protected lemma sUnion (hT : T.Finite) (hs : ∀ t ∈ T, Absorbs M s t) :
Absorbs M s (⋃₀ T) :=
hT.absorbs_sUnion.2 hs
@[simp]
| lemma _root_.absorbs_iUnion {ι : Sort*} [Finite ι] {t : ι → Set α} :
Absorbs M s (⋃ i, t i) ↔ ∀ i, Absorbs M s (t i) :=
(finite_range t).absorbs_sUnion.trans forall_mem_range
| Mathlib/Topology/Bornology/Absorbs.lean | 97 | 99 |
/-
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, Floris van Doorn
-/
import Mathlib.Geometry.Manifold.IsManifold.ExtChartAt
import Mathlib.Geometry.Manifold.LocalInvariantProperties
/-!
# `C^n` functions between manifolds
We define `Cⁿ` functions between manifolds, as functions which are `Cⁿ` in charts, and prove
basic properties of these notions. Here, `n` can be finite, or `∞`, or `ω`.
## Main definitions and statements
Let `M` and `M'` be two manifolds, with respect to models with corners `I` and `I'`. Let
`f : M → M'`.
* `ContMDiffWithinAt I I' n f s x` states that the function `f` is `Cⁿ` within the set `s`
around the point `x`.
* `ContMDiffAt I I' n f x` states that the function `f` is `Cⁿ` around `x`.
* `ContMDiffOn I I' n f s` states that the function `f` is `Cⁿ` on the set `s`
* `ContMDiff I I' n f` states that the function `f` is `Cⁿ`.
We also give some basic properties of `Cⁿ` functions between manifolds, following the API of
`C^n` functions between vector spaces.
See `Basic.lean` for further basic properties of `Cⁿ` functions between manifolds,
`NormedSpace.lean` for the equivalence of manifold-smoothness to usual smoothness,
`Product.lean` for smoothness results related to the product of manifolds and
`Atlas.lean` for smoothness of atlas members and local structomorphisms.
## Implementation details
Many properties follow for free from the corresponding properties of functions in vector spaces,
as being `Cⁿ` is a local property invariant under the `Cⁿ` groupoid. We take advantage of the
general machinery developed in `LocalInvariantProperties.lean` to get these properties
automatically. For instance, the fact that being `Cⁿ` does not depend on the chart one considers
is given by `liftPropWithinAt_indep_chart`.
For this to work, the definition of `ContMDiffWithinAt` and friends has to
follow definitionally the setup of local invariant properties. Still, we recast the definition
in terms of extended charts in `contMDiffOn_iff` and `contMDiff_iff`.
-/
open Set Function Filter ChartedSpace IsManifold
open scoped Topology Manifold ContDiff
/-! ### Definition of `Cⁿ` functions between manifolds -/
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
-- Prerequisite typeclasses to say that `M` is a manifold over the pair `(E, H)`
{E : Type*}
[NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H]
{I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
-- Prerequisite typeclasses to say that `M'` is a manifold over the pair `(E', H')`
{E' : Type*}
[NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
-- Prerequisite typeclasses to say that `M''` is a manifold over the pair `(E'', H'')`
{E'' : Type*}
[NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H'']
{I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M'']
-- declare functions, sets, points and smoothness indices
{e : PartialHomeomorph M H}
{e' : PartialHomeomorph M' H'} {f f₁ : M → M'} {s s₁ t : Set M} {x : M} {m n : WithTop ℕ∞}
variable (I I') in
/-- Property in the model space of a model with corners of being `C^n` within at set at a point,
when read in the model vector space. This property will be lifted to manifolds to define `C^n`
functions between manifolds. -/
def ContDiffWithinAtProp (n : WithTop ℕ∞) (f : H → H') (s : Set H) (x : H) : Prop :=
ContDiffWithinAt 𝕜 n (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x)
theorem contDiffWithinAtProp_self_source {f : E → H'} {s : Set E} {x : E} :
ContDiffWithinAtProp 𝓘(𝕜, E) I' n f s x ↔ ContDiffWithinAt 𝕜 n (I' ∘ f) s x := by
simp_rw [ContDiffWithinAtProp, modelWithCornersSelf_coe, range_id, inter_univ,
modelWithCornersSelf_coe_symm, CompTriple.comp_eq, preimage_id_eq, id_eq]
theorem contDiffWithinAtProp_self {f : E → E'} {s : Set E} {x : E} :
ContDiffWithinAtProp 𝓘(𝕜, E) 𝓘(𝕜, E') n f s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAtProp_self_source
theorem contDiffWithinAtProp_self_target {f : H → E'} {s : Set H} {x : H} :
ContDiffWithinAtProp I 𝓘(𝕜, E') n f s x ↔
ContDiffWithinAt 𝕜 n (f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) :=
Iff.rfl
/-- Being `Cⁿ` in the model space is a local property, invariant under `Cⁿ` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp_of_le (n m : WithTop ℕ∞) (hmn : m ≤ n) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' m) where
is_local {s x u f} u_open xu := by
have : I.symm ⁻¹' (s ∩ u) ∩ range I = I.symm ⁻¹' s ∩ range I ∩ I.symm ⁻¹' u := by
simp only [inter_right_comm, preimage_inter]
rw [ContDiffWithinAtProp, ContDiffWithinAtProp, this]
symm
apply contDiffWithinAt_inter
have : u ∈ 𝓝 (I.symm (I x)) := by
rw [ModelWithCorners.left_inv]
exact u_open.mem_nhds xu
apply ContinuousAt.preimage_mem_nhds I.continuous_symm.continuousAt this
right_invariance' {s x f e} he hx h := by
rw [ContDiffWithinAtProp] at h ⊢
have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)) := by simp only [hx, mfld_simps]
rw [this] at h
have : I (e x) ∈ I.symm ⁻¹' e.target ∩ range I := by simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he).2.contDiffWithinAt this
convert (h.comp_inter _ (this.of_le hmn)).mono_of_mem_nhdsWithin _
using 1
· ext y; simp only [mfld_simps]
refine mem_nhdsWithin.mpr
⟨I.symm ⁻¹' e.target, e.open_target.preimage I.continuous_symm, by
simp_rw [mem_preimage, I.left_inv, e.mapsTo hx], ?_⟩
mfld_set_tac
congr_of_forall {s x f g} h hx hf := by
apply hf.congr
· intro y hy
simp only [mfld_simps] at hy
simp only [h, hy, mfld_simps]
· simp only [hx, mfld_simps]
left_invariance' {s x f e'} he' hs hx h := by
rw [ContDiffWithinAtProp] at h ⊢
have A : (I' ∘ f ∘ I.symm) (I x) ∈ I'.symm ⁻¹' e'.source ∩ range I' := by
simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he').1.contDiffWithinAt A
convert (this.of_le hmn).comp _ h _
· ext y; simp only [mfld_simps]
· intro y hy; simp only [mfld_simps] at hy; simpa only [hy, mfld_simps] using hs hy.1
/-- Being `Cⁿ` in the model space is a local property, invariant under `C^n` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp (n : WithTop ℕ∞) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' n) :=
contDiffWithinAt_localInvariantProp_of_le n n le_rfl
theorem contDiffWithinAtProp_mono_of_mem_nhdsWithin
(n : WithTop ℕ∞) ⦃s x t⦄ ⦃f : H → H'⦄ (hts : s ∈ 𝓝[t] x)
(h : ContDiffWithinAtProp I I' n f s x) : ContDiffWithinAtProp I I' n f t x := by
refine h.mono_of_mem_nhdsWithin ?_
refine inter_mem ?_ (mem_of_superset self_mem_nhdsWithin inter_subset_right)
rwa [← Filter.mem_map, ← I.image_eq, I.symm_map_nhdsWithin_image]
@[deprecated (since := "2024-10-31")]
alias contDiffWithinAtProp_mono_of_mem := contDiffWithinAtProp_mono_of_mem_nhdsWithin
theorem contDiffWithinAtProp_id (x : H) : ContDiffWithinAtProp I I n id univ x := by
simp only [ContDiffWithinAtProp, id_comp, preimage_univ, univ_inter]
have : ContDiffWithinAt 𝕜 n id (range I) (I x) := contDiff_id.contDiffAt.contDiffWithinAt
refine this.congr (fun y hy => ?_) ?_
· simp only [ModelWithCorners.right_inv I hy, mfld_simps]
· simp only [mfld_simps]
variable (I I') in
/-- A function is `n` times continuously differentiable within a set at a point in a manifold if
it is continuous and it is `n` times continuously differentiable in this set around this point, when
read in the preferred chart at this point. -/
def ContMDiffWithinAt (n : WithTop ℕ∞) (f : M → M') (s : Set M) (x : M) :=
LiftPropWithinAt (ContDiffWithinAtProp I I' n) f s x
@[deprecated (since := "2024-11-21")] alias SmoothWithinAt := ContMDiffWithinAt
variable (I I') in
/-- A function is `n` times continuously differentiable at a point in a manifold if
it is continuous and it is `n` times continuously differentiable around this point, when
read in the preferred chart at this point. -/
def ContMDiffAt (n : WithTop ℕ∞) (f : M → M') (x : M) :=
ContMDiffWithinAt I I' n f univ x
theorem contMDiffAt_iff {n : WithTop ℕ∞} {f : M → M'} {x : M} :
ContMDiffAt I I' n f x ↔
ContinuousAt f x ∧
ContDiffWithinAt 𝕜 n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) (range I)
(extChartAt I x x) :=
liftPropAt_iff.trans <| by rw [ContDiffWithinAtProp, preimage_univ, univ_inter]; rfl
@[deprecated (since := "2024-11-21")] alias SmoothAt := ContMDiffAt
variable (I I') in
/-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable on this set in the charts
around these points. -/
def ContMDiffOn (n : WithTop ℕ∞) (f : M → M') (s : Set M) :=
∀ x ∈ s, ContMDiffWithinAt I I' n f s x
@[deprecated (since := "2024-11-21")] alias SmoothOn := ContMDiffOn
variable (I I') in
/-- A function is `n` times continuously differentiable in a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable in the charts
around these points. -/
def ContMDiff (n : WithTop ℕ∞) (f : M → M') :=
∀ x, ContMDiffAt I I' n f x
@[deprecated (since := "2024-11-21")] alias Smooth := ContMDiff
/-! ### Deducing smoothness from higher smoothness -/
theorem ContMDiffWithinAt.of_le (hf : ContMDiffWithinAt I I' n f s x) (le : m ≤ n) :
ContMDiffWithinAt I I' m f s x := by
simp only [ContMDiffWithinAt, LiftPropWithinAt] at hf ⊢
exact ⟨hf.1, hf.2.of_le (mod_cast le)⟩
theorem ContMDiffAt.of_le (hf : ContMDiffAt I I' n f x) (le : m ≤ n) : ContMDiffAt I I' m f x :=
ContMDiffWithinAt.of_le hf le
theorem ContMDiffOn.of_le (hf : ContMDiffOn I I' n f s) (le : m ≤ n) : ContMDiffOn I I' m f s :=
fun x hx => (hf x hx).of_le le
theorem ContMDiff.of_le (hf : ContMDiff I I' n f) (le : m ≤ n) : ContMDiff I I' m f := fun x =>
(hf x).of_le le
/-! ### Basic properties of `C^n` functions between manifolds -/
@[deprecated (since := "2024-11-20")] alias ContMDiff.smooth := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias Smooth.contMDiff := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffOn.smoothOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias SmoothOn.contMDiffOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffAt.smoothAt := ContMDiffAt.of_le
@[deprecated (since := "2024-11-20")] alias SmoothAt.contMDiffAt := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")]
alias ContMDiffWithinAt.smoothWithinAt := ContMDiffWithinAt.of_le
@[deprecated (since := "2024-11-20")]
alias SmoothWithinAt.contMDiffWithinAt := ContMDiffWithinAt.of_le
| theorem ContMDiff.contMDiffAt (h : ContMDiff I I' n f) : ContMDiffAt I I' n f x :=
h x
@[deprecated (since := "2024-11-20")] alias Smooth.smoothAt := ContMDiff.contMDiffAt
| Mathlib/Geometry/Manifold/ContMDiff/Defs.lean | 239 | 242 |
/-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Eric Wieser
-/
import Mathlib.LinearAlgebra.Multilinear.TensorProduct
import Mathlib.Tactic.AdaptationNote
import Mathlib.LinearAlgebra.Multilinear.Curry
/-!
# Tensor product of an indexed family of modules over commutative semirings
We define the tensor product of an indexed family `s : ι → Type*` of modules over commutative
semirings. We denote this space by `⨂[R] i, s i` and define it as `FreeAddMonoid (R × Π i, s i)`
quotiented by the appropriate equivalence relation. The treatment follows very closely that of the
binary tensor product in `LinearAlgebra/TensorProduct.lean`.
## Main definitions
* `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor product
of all the `s i`'s. This is denoted by `⨂[R] i, s i`.
* `tprod R f` with `f : Π i, s i` is the tensor product of the vectors `f i` over all `i : ι`.
This is bundled as a multilinear map from `Π i, s i` to `⨂[R] i, s i`.
* `liftAddHom` constructs an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a
function `φ : (R × Π i, s i) → F` with the appropriate properties.
* `lift φ` with `φ : MultilinearMap R s E` is the corresponding linear map
`(⨂[R] i, s i) →ₗ[R] E`. This is bundled as a linear equivalence.
* `PiTensorProduct.reindex e` re-indexes the components of `⨂[R] i : ι, M` along `e : ι ≃ ι₂`.
* `PiTensorProduct.tmulEquiv` equivalence between a `TensorProduct` of `PiTensorProduct`s and
a single `PiTensorProduct`.
## Notations
* `⨂[R] i, s i` is defined as localized notation in locale `TensorProduct`.
* `⨂ₜ[R] i, f i` with `f : ∀ i, s i` is defined globally as the tensor product of all the `f i`'s.
## Implementation notes
* We define it via `FreeAddMonoid (R × Π i, s i)` with the `R` representing a "hidden" tensor
factor, rather than `FreeAddMonoid (Π i, s i)` to ensure that, if `ι` is an empty type,
the space is isomorphic to the base ring `R`.
* We have not restricted the index type `ι` to be a `Fintype`, as nothing we do here strictly
requires it. However, problems may arise in the case where `ι` is infinite; use at your own
caution.
* Instead of requiring `DecidableEq ι` as an argument to `PiTensorProduct` itself, we include it
as an argument in the constructors of the relation. A decidability instance still has to come
from somewhere due to the use of `Function.update`, but this hides it from the downstream user.
See the implementation notes for `MultilinearMap` for an extended discussion of this choice.
## TODO
* Define tensor powers, symmetric subspace, etc.
* API for the various ways `ι` can be split into subsets; connect this with the binary
tensor product.
* Include connection with holors.
* Port more of the API from the binary tensor product over to this case.
## Tags
multilinear, tensor, tensor product
-/
suppress_compilation
open Function
section Semiring
variable {ι ι₂ ι₃ : Type*}
variable {R : Type*} [CommSemiring R]
variable {R₁ R₂ : Type*}
variable {s : ι → Type*} [∀ i, AddCommMonoid (s i)] [∀ i, Module R (s i)]
variable {M : Type*} [AddCommMonoid M] [Module R M]
variable {E : Type*} [AddCommMonoid E] [Module R E]
variable {F : Type*} [AddCommMonoid F]
namespace PiTensorProduct
variable (R) (s)
/-- The relation on `FreeAddMonoid (R × Π i, s i)` that generates a congruence whose quotient is
the tensor product. -/
inductive Eqv : FreeAddMonoid (R × Π i, s i) → FreeAddMonoid (R × Π i, s i) → Prop
| of_zero : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), Eqv (FreeAddMonoid.of (r, f)) 0
| of_zero_scalar : ∀ f : Π i, s i, Eqv (FreeAddMonoid.of (0, f)) 0
| of_add : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i),
Eqv (FreeAddMonoid.of (r, update f i m₁) + FreeAddMonoid.of (r, update f i m₂))
(FreeAddMonoid.of (r, update f i (m₁ + m₂)))
| of_add_scalar : ∀ (r r' : R) (f : Π i, s i),
Eqv (FreeAddMonoid.of (r, f) + FreeAddMonoid.of (r', f)) (FreeAddMonoid.of (r + r', f))
| of_smul : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (r' : R),
Eqv (FreeAddMonoid.of (r, update f i (r' • f i))) (FreeAddMonoid.of (r' * r, f))
| add_comm : ∀ x y, Eqv (x + y) (y + x)
end PiTensorProduct
variable (R) (s)
/-- `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor
product of all the `s i`'s. This is denoted by `⨂[R] i, s i`. -/
def PiTensorProduct : Type _ :=
(addConGen (PiTensorProduct.Eqv R s)).Quotient
variable {R}
unsuppress_compilation in
/-- This enables the notation `⨂[R] i : ι, s i` for the pi tensor product `PiTensorProduct`,
given an indexed family of types `s : ι → Type*`. -/
scoped[TensorProduct] notation3:100"⨂["R"] "(...)", "r:(scoped f => PiTensorProduct R f) => r
open TensorProduct
namespace PiTensorProduct
section Module
instance : AddCommMonoid (⨂[R] i, s i) :=
{ (addConGen (PiTensorProduct.Eqv R s)).addMonoid with
add_comm := fun x y ↦
AddCon.induction_on₂ x y fun _ _ ↦
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ }
instance : Inhabited (⨂[R] i, s i) := ⟨0⟩
variable (R) {s}
/-- `tprodCoeff R r f` with `r : R` and `f : Π i, s i` is the tensor product of the vectors `f i`
over all `i : ι`, multiplied by the coefficient `r`. Note that this is meant as an auxiliary
definition for this file alone, and that one should use `tprod` defined below for most purposes. -/
def tprodCoeff (r : R) (f : Π i, s i) : ⨂[R] i, s i :=
AddCon.mk' _ <| FreeAddMonoid.of (r, f)
variable {R}
theorem zero_tprodCoeff (f : Π i, s i) : tprodCoeff R 0 f = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_scalar _
theorem zero_tprodCoeff' (z : R) (f : Π i, s i) (i : ι) (hf : f i = 0) : tprodCoeff R z f = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero _ _ i hf
theorem add_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i) :
tprodCoeff R z (update f i m₁) + tprodCoeff R z (update f i m₂) =
tprodCoeff R z (update f i (m₁ + m₂)) :=
Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add _ z f i m₁ m₂)
theorem add_tprodCoeff' (z₁ z₂ : R) (f : Π i, s i) :
tprodCoeff R z₁ f + tprodCoeff R z₂ f = tprodCoeff R (z₁ + z₂) f :=
Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add_scalar z₁ z₂ f)
theorem smul_tprodCoeff_aux [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R) :
tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r * z) f :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _ _ _
theorem smul_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R₁) [SMul R₁ R]
[IsScalarTower R₁ R R] [SMul R₁ (s i)] [IsScalarTower R₁ R (s i)] :
tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r • z) f := by
have h₁ : r • z = r • (1 : R) * z := by rw [smul_mul_assoc, one_mul]
have h₂ : r • f i = (r • (1 : R)) • f i := (smul_one_smul _ _ _).symm
rw [h₁, h₂]
exact smul_tprodCoeff_aux z f i _
/-- Construct an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a function
`φ : (R × Π i, s i) → F` with the appropriate properties. -/
def liftAddHom (φ : (R × Π i, s i) → F)
(C0 : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), φ (r, f) = 0)
(C0' : ∀ f : Π i, s i, φ (0, f) = 0)
(C_add : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i),
φ (r, update f i m₁) + φ (r, update f i m₂) = φ (r, update f i (m₁ + m₂)))
(C_add_scalar : ∀ (r r' : R) (f : Π i, s i), φ (r, f) + φ (r', f) = φ (r + r', f))
(C_smul : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (r' : R),
φ (r, update f i (r' • f i)) = φ (r' * r, f)) :
(⨂[R] i, s i) →+ F :=
(addConGen (PiTensorProduct.Eqv R s)).lift (FreeAddMonoid.lift φ) <|
AddCon.addConGen_le fun x y hxy ↦
match hxy with
| Eqv.of_zero r' f i hf =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0 r' f i hf]
| Eqv.of_zero_scalar f =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0']
| Eqv.of_add inst z f i m₁ m₂ =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_add inst]
| Eqv.of_add_scalar z₁ z₂ f =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C_add_scalar]
| Eqv.of_smul inst z f i r' =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_smul inst]
| Eqv.add_comm x y =>
(AddCon.ker_rel _).2 <| by simp_rw [AddMonoidHom.map_add, add_comm]
/-- Induct using `tprodCoeff` -/
@[elab_as_elim]
protected theorem induction_on' {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i)
(tprodCoeff : ∀ (r : R) (f : Π i, s i), motive (tprodCoeff R r f))
(add : ∀ x y, motive x → motive y → motive (x + y)) :
motive z := by
have C0 : motive 0 := by
have h₁ := tprodCoeff 0 0
rwa [zero_tprodCoeff] at h₁
refine AddCon.induction_on z fun x ↦ FreeAddMonoid.recOn x C0 ?_
simp_rw [AddCon.coe_add]
refine fun f y ih ↦ add _ _ ?_ ih
convert tprodCoeff f.1 f.2
section DistribMulAction
variable [Monoid R₁] [DistribMulAction R₁ R] [SMulCommClass R₁ R R]
variable [Monoid R₂] [DistribMulAction R₂ R] [SMulCommClass R₂ R R]
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance hasSMul' : SMul R₁ (⨂[R] i, s i) :=
⟨fun r ↦
liftAddHom (fun f : R × Π i, s i ↦ tprodCoeff R (r • f.1) f.2)
(fun r' f i hf ↦ by simp_rw [zero_tprodCoeff' _ f i hf])
(fun f ↦ by simp [zero_tprodCoeff]) (fun r' f i m₁ m₂ ↦ by simp [add_tprodCoeff])
(fun r' r'' f ↦ by simp [add_tprodCoeff', mul_add]) fun z f i r' ↦ by
simp [smul_tprodCoeff, mul_smul_comm]⟩
instance : SMul R (⨂[R] i, s i) :=
PiTensorProduct.hasSMul'
theorem smul_tprodCoeff' (r : R₁) (z : R) (f : Π i, s i) :
r • tprodCoeff R z f = tprodCoeff R (r • z) f := rfl
protected theorem smul_add (r : R₁) (x y : ⨂[R] i, s i) : r • (x + y) = r • x + r • y :=
AddMonoidHom.map_add _ _ _
instance distribMulAction' : DistribMulAction R₁ (⨂[R] i, s i) where
smul := (· • ·)
smul_add _ _ _ := AddMonoidHom.map_add _ _ _
mul_smul r r' x :=
PiTensorProduct.induction_on' x (fun {r'' f} ↦ by simp [smul_tprodCoeff', smul_smul])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy]
one_smul x :=
PiTensorProduct.induction_on' x (fun {r f} ↦ by rw [smul_tprodCoeff', one_smul])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]
smul_zero _ := AddMonoidHom.map_zero _
instance smulCommClass' [SMulCommClass R₁ R₂ R] : SMulCommClass R₁ R₂ (⨂[R] i, s i) :=
⟨fun {r' r''} x ↦
PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_comm])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩
instance isScalarTower' [SMul R₁ R₂] [IsScalarTower R₁ R₂ R] :
IsScalarTower R₁ R₂ (⨂[R] i, s i) :=
⟨fun {r' r''} x ↦
PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_assoc])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩
end DistribMulAction
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance module' [Semiring R₁] [Module R₁ R] [SMulCommClass R₁ R R] : Module R₁ (⨂[R] i, s i) :=
{ PiTensorProduct.distribMulAction' with
add_smul := fun r r' x ↦
PiTensorProduct.induction_on' x
(fun {r f} ↦ by simp_rw [smul_tprodCoeff', add_smul, add_tprodCoeff'])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_add_add_comm]
zero_smul := fun x ↦
PiTensorProduct.induction_on' x
(fun {r f} ↦ by simp_rw [smul_tprodCoeff', zero_smul, zero_tprodCoeff])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_zero] }
-- shortcut instances
instance : Module R (⨂[R] i, s i) :=
PiTensorProduct.module'
instance : SMulCommClass R R (⨂[R] i, s i) :=
PiTensorProduct.smulCommClass'
instance : IsScalarTower R R (⨂[R] i, s i) :=
PiTensorProduct.isScalarTower'
variable (R) in
/-- The canonical `MultilinearMap R s (⨂[R] i, s i)`.
`tprod R fun i => f i` has notation `⨂ₜ[R] i, f i`. -/
def tprod : MultilinearMap R s (⨂[R] i, s i) where
toFun := tprodCoeff R 1
map_update_add' {_ f} i x y := (add_tprodCoeff (1 : R) f i x y).symm
map_update_smul' {_ f} i r x := by
rw [smul_tprodCoeff', ← smul_tprodCoeff (1 : R) _ i, update_idem, update_self]
unsuppress_compilation in
@[inherit_doc tprod]
notation3:100 "⨂ₜ["R"] "(...)", "r:(scoped f => tprod R f) => r
theorem tprod_eq_tprodCoeff_one :
⇑(tprod R : MultilinearMap R s (⨂[R] i, s i)) = tprodCoeff R 1 := rfl
@[simp]
theorem tprodCoeff_eq_smul_tprod (z : R) (f : Π i, s i) : tprodCoeff R z f = z • tprod R f := by
have : z = z • (1 : R) := by simp only [mul_one, Algebra.id.smul_eq_mul]
conv_lhs => rw [this]
rfl
/-- The image of an element `p` of `FreeAddMonoid (R × Π i, s i)` in the `PiTensorProduct` is
equal to the sum of `a • ⨂ₜ[R] i, m i` over all the entries `(a, m)` of `p`.
-/
lemma _root_.FreeAddMonoid.toPiTensorProduct (p : FreeAddMonoid (R × Π i, s i)) :
AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p =
List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p.toList) := by
-- TODO: this is defeq abuse: `p` is not a `List`.
match p with
| [] => rw [FreeAddMonoid.toList_nil, List.map_nil, List.sum_nil]; rfl
| x :: ps =>
rw [FreeAddMonoid.toList_cons, List.map_cons, List.sum_cons, ← List.singleton_append,
← toPiTensorProduct ps, ← tprodCoeff_eq_smul_tprod]
rfl
/-- The set of lifts of an element `x` of `⨂[R] i, s i` in `FreeAddMonoid (R × Π i, s i)`. -/
def lifts (x : ⨂[R] i, s i) : Set (FreeAddMonoid (R × Π i, s i)) :=
{p | AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p = x}
/-- An element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i`
if and only if `x` is equal to the sum of `a • ⨂ₜ[R] i, m i` over all the entries
`(a, m)` of `p`.
-/
lemma mem_lifts_iff (x : ⨂[R] i, s i) (p : FreeAddMonoid (R × Π i, s i)) :
p ∈ lifts x ↔ List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p.toList) = x := by
simp only [lifts, Set.mem_setOf_eq, FreeAddMonoid.toPiTensorProduct]
/-- Every element of `⨂[R] i, s i` has a lift in `FreeAddMonoid (R × Π i, s i)`.
-/
lemma nonempty_lifts (x : ⨂[R] i, s i) : Set.Nonempty (lifts x) := by
existsi @Quotient.out _ (addConGen (PiTensorProduct.Eqv R s)).toSetoid x
simp only [lifts, Set.mem_setOf_eq]
rw [← AddCon.quot_mk_eq_coe]
erw [Quot.out_eq]
/-- The empty list lifts the element `0` of `⨂[R] i, s i`.
-/
lemma lifts_zero : 0 ∈ lifts (0 : ⨂[R] i, s i) := by
rw [mem_lifts_iff]; erw [List.map_nil]; rw [List.sum_nil]
/-- If elements `p,q` of `FreeAddMonoid (R × Π i, s i)` lift elements `x,y` of `⨂[R] i, s i`
respectively, then `p + q` lifts `x + y`.
-/
lemma lifts_add {x y : ⨂[R] i, s i} {p q : FreeAddMonoid (R × Π i, s i)}
(hp : p ∈ lifts x) (hq : q ∈ lifts y) : p + q ∈ lifts (x + y) := by
simp only [lifts, Set.mem_setOf_eq, AddCon.coe_add]
rw [hp, hq]
/-- If an element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i`,
and if `a` is an element of `R`, then the list obtained by multiplying the first entry of each
element of `p` by `a` lifts `a • x`.
-/
lemma lifts_smul {x : ⨂[R] i, s i} {p : FreeAddMonoid (R × Π i, s i)} (h : p ∈ lifts x) (a : R) :
p.map (fun (y : R × Π i, s i) ↦ (a * y.1, y.2)) ∈ lifts (a • x) := by
rw [mem_lifts_iff] at h ⊢
rw [← h]
simp [Function.comp_def, mul_smul, List.smul_sum]
/-- Induct using scaled versions of `PiTensorProduct.tprod`. -/
@[elab_as_elim]
protected theorem induction_on {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i)
(smul_tprod : ∀ (r : R) (f : Π i, s i), motive (r • tprod R f))
(add : ∀ x y, motive x → motive y → motive (x + y)) :
motive z := by
simp_rw [← tprodCoeff_eq_smul_tprod] at smul_tprod
exact PiTensorProduct.induction_on' z smul_tprod add
@[ext]
theorem ext {φ₁ φ₂ : (⨂[R] i, s i) →ₗ[R] E}
(H : φ₁.compMultilinearMap (tprod R) = φ₂.compMultilinearMap (tprod R)) : φ₁ = φ₂ := by
refine LinearMap.ext ?_
refine fun z ↦
PiTensorProduct.induction_on' z ?_ fun {x y} hx hy ↦ by rw [φ₁.map_add, φ₂.map_add, hx, hy]
· intro r f
rw [tprodCoeff_eq_smul_tprod, φ₁.map_smul, φ₂.map_smul]
apply congr_arg
exact MultilinearMap.congr_fun H f
/-- The pure tensors (i.e. the elements of the image of `PiTensorProduct.tprod`) span
the tensor product. -/
theorem span_tprod_eq_top :
Submodule.span R (Set.range (tprod R)) = (⊤ : Submodule R (⨂[R] i, s i)) :=
Submodule.eq_top_iff'.mpr fun t ↦ t.induction_on
(fun _ _ ↦ Submodule.smul_mem _ _
(Submodule.subset_span (by simp only [Set.mem_range, exists_apply_eq_apply])))
(fun _ _ hx hy ↦ Submodule.add_mem _ hx hy)
end Module
section Multilinear
open MultilinearMap
variable {s}
section lift
/-- Auxiliary function to constructing a linear map `(⨂[R] i, s i) → E` given a
`MultilinearMap R s E` with the property that its composition with the canonical
`MultilinearMap R s (⨂[R] i, s i)` is the given multilinear map. -/
def liftAux (φ : MultilinearMap R s E) : (⨂[R] i, s i) →+ E :=
liftAddHom (fun p : R × Π i, s i ↦ p.1 • φ p.2)
(fun z f i hf ↦ by simp_rw [map_coord_zero φ i hf, smul_zero])
(fun f ↦ by simp_rw [zero_smul])
(fun z f i m₁ m₂ ↦ by simp_rw [← smul_add, φ.map_update_add])
(fun z₁ z₂ f ↦ by rw [← add_smul])
fun z f i r ↦ by simp [φ.map_update_smul, smul_smul, mul_comm]
theorem liftAux_tprod (φ : MultilinearMap R s E) (f : Π i, s i) : liftAux φ (tprod R f) = φ f := by
simp only [liftAux, liftAddHom, tprod_eq_tprodCoeff_one, tprodCoeff, AddCon.coe_mk']
-- The end of this proof was very different before https://github.com/leanprover/lean4/pull/2644:
-- rw [FreeAddMonoid.of, FreeAddMonoid.ofList, Equiv.refl_apply, AddCon.lift_coe]
-- dsimp [FreeAddMonoid.lift, FreeAddMonoid.sumAux]
-- show _ • _ = _
-- rw [one_smul]
erw [AddCon.lift_coe]
rw [FreeAddMonoid.of]
dsimp [FreeAddMonoid.ofList]
rw [← one_smul R (φ f)]
erw [Equiv.refl_apply]
convert one_smul R (φ f)
simp
theorem liftAux_tprodCoeff (φ : MultilinearMap R s E) (z : R) (f : Π i, s i) :
liftAux φ (tprodCoeff R z f) = z • φ f := rfl
theorem liftAux.smul {φ : MultilinearMap R s E} (r : R) (x : ⨂[R] i, s i) :
liftAux φ (r • x) = r • liftAux φ x := by
refine PiTensorProduct.induction_on' x ?_ ?_
· intro z f
rw [smul_tprodCoeff' r z f, liftAux_tprodCoeff, liftAux_tprodCoeff, smul_assoc]
· intro z y ihz ihy
rw [smul_add, (liftAux φ).map_add, ihz, ihy, (liftAux φ).map_add, smul_add]
/-- Constructing a linear map `(⨂[R] i, s i) → E` given a `MultilinearMap R s E` with the
property that its composition with the canonical `MultilinearMap R s E` is
the given multilinear map `φ`. -/
def lift : MultilinearMap R s E ≃ₗ[R] (⨂[R] i, s i) →ₗ[R] E where
toFun φ := { liftAux φ with map_smul' := liftAux.smul }
invFun φ' := φ'.compMultilinearMap (tprod R)
left_inv φ := by
ext
simp [liftAux_tprod, LinearMap.compMultilinearMap]
right_inv φ := by
ext
simp [liftAux_tprod]
map_add' φ₁ φ₂ := by
ext
simp [liftAux_tprod]
map_smul' r φ₂ := by
ext
simp [liftAux_tprod]
variable {φ : MultilinearMap R s E}
@[simp]
theorem lift.tprod (f : Π i, s i) : lift φ (tprod R f) = φ f :=
liftAux_tprod φ f
theorem lift.unique' {φ' : (⨂[R] i, s i) →ₗ[R] E}
(H : φ'.compMultilinearMap (PiTensorProduct.tprod R) = φ) : φ' = lift φ :=
ext <| H.symm ▸ (lift.symm_apply_apply φ).symm
theorem lift.unique {φ' : (⨂[R] i, s i) →ₗ[R] E} (H : ∀ f, φ' (PiTensorProduct.tprod R f) = φ f) :
φ' = lift φ :=
lift.unique' (MultilinearMap.ext H)
@[simp]
theorem lift_symm (φ' : (⨂[R] i, s i) →ₗ[R] E) : lift.symm φ' = φ'.compMultilinearMap (tprod R) :=
rfl
@[simp]
theorem lift_tprod : lift (tprod R : MultilinearMap R s _) = LinearMap.id :=
Eq.symm <| lift.unique' rfl
end lift
section map
variable {t t' : ι → Type*}
variable [∀ i, AddCommMonoid (t i)] [∀ i, Module R (t i)]
variable [∀ i, AddCommMonoid (t' i)] [∀ i, Module R (t' i)]
variable (g : Π i, t i →ₗ[R] t' i) (f : Π i, s i →ₗ[R] t i)
/--
Let `sᵢ` and `tᵢ` be two families of `R`-modules.
Let `f` be a family of `R`-linear maps between `sᵢ` and `tᵢ`, i.e. `f : Πᵢ sᵢ → tᵢ`,
then there is an induced map `⨂ᵢ sᵢ → ⨂ᵢ tᵢ` by `⨂ aᵢ ↦ ⨂ fᵢ aᵢ`.
This is `TensorProduct.map` for an arbitrary family of modules.
-/
def map : (⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i :=
lift <| (tprod R).compLinearMap f
@[simp] lemma map_tprod (x : Π i, s i) :
map f (tprod R x) = tprod R fun i ↦ f i (x i) :=
lift.tprod _
-- No lemmas about associativity, because we don't have associativity of `PiTensorProduct` yet.
theorem map_range_eq_span_tprod :
LinearMap.range (map f) =
Submodule.span R {t | ∃ (m : Π i, s i), tprod R (fun i ↦ f i (m i)) = t} := by
rw [← Submodule.map_top, ← span_tprod_eq_top, Submodule.map_span, ← Set.range_comp]
apply congrArg; ext x
simp only [Set.mem_range, comp_apply, map_tprod, Set.mem_setOf_eq]
/-- Given submodules `p i ⊆ s i`, this is the natural map: `⨂[R] i, p i → ⨂[R] i, s i`.
This is `TensorProduct.mapIncl` for an arbitrary family of modules.
-/
@[simp]
def mapIncl (p : Π i, Submodule R (s i)) : (⨂[R] i, p i) →ₗ[R] ⨂[R] i, s i :=
map fun (i : ι) ↦ (p i).subtype
theorem map_comp : map (fun (i : ι) ↦ g i ∘ₗ f i) = map g ∘ₗ map f := by
ext
simp only [LinearMap.compMultilinearMap_apply, map_tprod, LinearMap.coe_comp, Function.comp_apply]
theorem lift_comp_map (h : MultilinearMap R t E) :
lift h ∘ₗ map f = lift (h.compLinearMap f) := by
ext
simp only [LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, Function.comp_apply,
map_tprod, lift.tprod, MultilinearMap.compLinearMap_apply]
attribute [local ext high] ext
@[simp]
theorem map_id : map (fun i ↦ (LinearMap.id : s i →ₗ[R] s i)) = .id := by
ext
simp only [LinearMap.compMultilinearMap_apply, map_tprod, LinearMap.id_coe, id_eq]
@[simp]
protected theorem map_one : map (fun (i : ι) ↦ (1 : s i →ₗ[R] s i)) = 1 :=
map_id
protected theorem map_mul (f₁ f₂ : Π i, s i →ₗ[R] s i) :
map (fun i ↦ f₁ i * f₂ i) = map f₁ * map f₂ :=
map_comp f₁ f₂
/-- Upgrading `PiTensorProduct.map` to a `MonoidHom` when `s = t`. -/
@[simps]
def mapMonoidHom : (Π i, s i →ₗ[R] s i) →* ((⨂[R] i, s i) →ₗ[R] ⨂[R] i, s i) where
toFun := map
map_one' := PiTensorProduct.map_one
map_mul' := PiTensorProduct.map_mul
@[simp]
protected theorem map_pow (f : Π i, s i →ₗ[R] s i) (n : ℕ) :
map (f ^ n) = map f ^ n := MonoidHom.map_pow mapMonoidHom _ _
open Function in
private theorem map_add_smul_aux [DecidableEq ι] (i : ι) (x : Π i, s i) (u : s i →ₗ[R] t i) :
(fun j ↦ update f i u j (x j)) = update (fun j ↦ (f j) (x j)) i (u (x i)) := by
ext j
exact apply_update (fun i F => F (x i)) f i u j
open Function in
protected theorem map_update_add [DecidableEq ι] (i : ι) (u v : s i →ₗ[R] t i) :
map (update f i (u + v)) = map (update f i u) + map (update f i v) := by
ext x
simp only [LinearMap.compMultilinearMap_apply, map_tprod, map_add_smul_aux, LinearMap.add_apply,
MultilinearMap.map_update_add]
@[deprecated (since := "2024-11-03")] protected alias map_add := PiTensorProduct.map_update_add
open Function in
protected theorem map_update_smul [DecidableEq ι] (i : ι) (c : R) (u : s i →ₗ[R] t i) :
map (update f i (c • u)) = c • map (update f i u) := by
ext x
simp only [LinearMap.compMultilinearMap_apply, map_tprod, map_add_smul_aux, LinearMap.smul_apply,
MultilinearMap.map_update_smul]
@[deprecated (since := "2024-11-03")] protected alias map_smul := PiTensorProduct.map_update_smul
variable (R s t)
/-- The tensor of a family of linear maps from `sᵢ` to `tᵢ`, as a multilinear map of
the family.
-/
@[simps]
noncomputable def mapMultilinear :
MultilinearMap R (fun (i : ι) ↦ s i →ₗ[R] t i) ((⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i) where
toFun := map
map_update_smul' _ _ _ _ := PiTensorProduct.map_update_smul _ _ _ _
map_update_add' _ _ _ _ := PiTensorProduct.map_update_add _ _ _ _
variable {R s t}
/--
Let `sᵢ` and `tᵢ` be families of `R`-modules.
Then there is an `R`-linear map between `⨂ᵢ Hom(sᵢ, tᵢ)` and `Hom(⨂ᵢ sᵢ, ⨂ tᵢ)` defined by
`⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ fᵢ aᵢ`.
This is `TensorProduct.homTensorHomMap` for an arbitrary family of modules.
Note that `PiTensorProduct.piTensorHomMap (tprod R f)` is equal to `PiTensorProduct.map f`.
-/
def piTensorHomMap : (⨂[R] i, s i →ₗ[R] t i) →ₗ[R] (⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i :=
lift.toLinearMap ∘ₗ lift (MultilinearMap.piLinearMap <| tprod R)
@[simp] lemma piTensorHomMap_tprod_tprod (f : Π i, s i →ₗ[R] t i) (x : Π i, s i) :
piTensorHomMap (tprod R f) (tprod R x) = tprod R fun i ↦ f i (x i) := by
simp [piTensorHomMap]
lemma piTensorHomMap_tprod_eq_map (f : Π i, s i →ₗ[R] t i) :
piTensorHomMap (tprod R f) = map f := by
ext; simp
/-- If `s i` and `t i` are linearly equivalent for every `i` in `ι`, then `⨂[R] i, s i` and
`⨂[R] i, t i` are linearly equivalent.
This is the n-ary version of `TensorProduct.congr`
-/
noncomputable def congr (f : Π i, s i ≃ₗ[R] t i) :
(⨂[R] i, s i) ≃ₗ[R] ⨂[R] i, t i :=
.ofLinear
(map (fun i ↦ f i))
(map (fun i ↦ (f i).symm))
(by ext; simp)
(by ext; simp)
@[simp]
theorem congr_tprod (f : Π i, s i ≃ₗ[R] t i) (m : Π i, s i) :
congr f (tprod R m) = tprod R (fun (i : ι) ↦ (f i) (m i)) := by
simp only [congr, LinearEquiv.ofLinear_apply, map_tprod, LinearEquiv.coe_coe]
@[simp]
theorem congr_symm_tprod (f : Π i, s i ≃ₗ[R] t i) (p : Π i, t i) :
(congr f).symm (tprod R p) = tprod R (fun (i : ι) ↦ (f i).symm (p i)) := by
simp only [congr, LinearEquiv.ofLinear_symm_apply, map_tprod, LinearEquiv.coe_coe]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules, then `f : Πᵢ sᵢ → tᵢ → t'ᵢ` induces an
element of `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))` defined by `⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`.
This is `PiTensorProduct.map` for two arbitrary families of modules.
This is `TensorProduct.map₂` for families of modules.
-/
def map₂ (f : Π i, s i →ₗ[R] t i →ₗ[R] t' i) :
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] ⨂[R] i, t' i :=
lift <| LinearMap.compMultilinearMap piTensorHomMap <| (tprod R).compLinearMap f
lemma map₂_tprod_tprod (f : Π i, s i →ₗ[R] t i →ₗ[R] t' i) (x : Π i, s i) (y : Π i, t i) :
map₂ f (tprod R x) (tprod R y) = tprod R fun i ↦ f i (x i) (y i) := by
simp [map₂]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules.
Then there is a function from `⨂ᵢ Hom(sᵢ, Hom(tᵢ, t'ᵢ))` to `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))`
defined by `⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`. -/
def piTensorHomMapFun₂ : (⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) →
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] (⨂[R] i, t' i) :=
fun φ => lift <| LinearMap.compMultilinearMap piTensorHomMap <|
(lift <| MultilinearMap.piLinearMap <| tprod R) φ
theorem piTensorHomMapFun₂_add (φ ψ : ⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) :
piTensorHomMapFun₂ (φ + ψ) = piTensorHomMapFun₂ φ + piTensorHomMapFun₂ ψ := by
dsimp [piTensorHomMapFun₂]; ext; simp only [map_add, LinearMap.compMultilinearMap_apply,
lift.tprod, add_apply, LinearMap.add_apply]
theorem piTensorHomMapFun₂_smul (r : R) (φ : ⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) :
piTensorHomMapFun₂ (r • φ) = r • piTensorHomMapFun₂ φ := by
dsimp [piTensorHomMapFun₂]; ext; simp only [map_smul, LinearMap.compMultilinearMap_apply,
lift.tprod, smul_apply, LinearMap.smul_apply]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules.
Then there is an linear map from `⨂ᵢ Hom(sᵢ, Hom(tᵢ, t'ᵢ))` to `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))`
defined by `⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`.
This is `TensorProduct.homTensorHomMap` for two arbitrary families of modules.
-/
def piTensorHomMap₂ : (⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) →ₗ[R]
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] (⨂[R] i, t' i) where
toFun := piTensorHomMapFun₂
map_add' x y := piTensorHomMapFun₂_add x y
map_smul' x y := piTensorHomMapFun₂_smul x y
@[simp] lemma piTensorHomMap₂_tprod_tprod_tprod
(f : ∀ i, s i →ₗ[R] t i →ₗ[R] t' i) (a : ∀ i, s i) (b : ∀ i, t i) :
piTensorHomMap₂ (tprod R f) (tprod R a) (tprod R b) = tprod R (fun i ↦ f i (a i) (b i)) := by
simp [piTensorHomMapFun₂, piTensorHomMap₂]
end map
section
variable (R M)
variable (s) in
/-- Re-index the components of the tensor power by `e`. -/
def reindex (e : ι ≃ ι₂) : (⨂[R] i : ι, s i) ≃ₗ[R] ⨂[R] i : ι₂, s (e.symm i) :=
let f := domDomCongrLinearEquiv' R R s (⨂[R] (i : ι₂), s (e.symm i)) e
let g := domDomCongrLinearEquiv' R R s (⨂[R] (i : ι), s i) e
#adaptation_note /-- v4.7.0-rc1
An alternative to the last two proofs would be `aesop (simp_config := {zetaDelta := true})`
or a wrapper macro to that effect. -/
LinearEquiv.ofLinear (lift <| f.symm <| tprod R) (lift <| g <| tprod R)
(by aesop (add norm simp [f, g]))
(by aesop (add norm simp [f, g]))
end
@[simp]
theorem reindex_tprod (e : ι ≃ ι₂) (f : Π i, s i) :
reindex R s e (tprod R f) = tprod R fun i ↦ f (e.symm i) := by
dsimp [reindex]
exact liftAux_tprod _ f
@[simp]
theorem reindex_comp_tprod (e : ι ≃ ι₂) :
(reindex R s e).compMultilinearMap (tprod R) =
(domDomCongrLinearEquiv' R R s _ e).symm (tprod R) :=
MultilinearMap.ext <| reindex_tprod e
theorem lift_comp_reindex (e : ι ≃ ι₂) (φ : MultilinearMap R (fun i ↦ s (e.symm i)) E) :
lift φ ∘ₗ (reindex R s e) = lift ((domDomCongrLinearEquiv' R R s _ e).symm φ) := by
ext; simp [reindex]
@[simp]
theorem lift_comp_reindex_symm (e : ι ≃ ι₂) (φ : MultilinearMap R s E) :
lift φ ∘ₗ (reindex R s e).symm = lift (domDomCongrLinearEquiv' R R s _ e φ) := by
ext; simp [reindex]
theorem lift_reindex
(e : ι ≃ ι₂) (φ : MultilinearMap R (fun i ↦ s (e.symm i)) E) (x : ⨂[R] i, s i) :
lift φ (reindex R s e x) = lift ((domDomCongrLinearEquiv' R R s _ e).symm φ) x :=
LinearMap.congr_fun (lift_comp_reindex e φ) x
@[simp]
theorem lift_reindex_symm
(e : ι ≃ ι₂) (φ : MultilinearMap R s E) (x : ⨂[R] i, s (e.symm i)) :
lift φ (reindex R s e |>.symm x) = lift (domDomCongrLinearEquiv' R R s _ e φ) x :=
LinearMap.congr_fun (lift_comp_reindex_symm e φ) x
@[simp]
theorem reindex_trans (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) :
(reindex R s e).trans (reindex R _ e') = reindex R s (e.trans e') := by
apply LinearEquiv.toLinearMap_injective
ext f
simp only [LinearEquiv.trans_apply, LinearEquiv.coe_coe, reindex_tprod,
LinearMap.coe_compMultilinearMap, Function.comp_apply, MultilinearMap.domDomCongr_apply,
reindex_comp_tprod]
congr
theorem reindex_reindex (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) (x : ⨂[R] i, s i) :
reindex R _ e' (reindex R s e x) = reindex R s (e.trans e') x :=
LinearEquiv.congr_fun (reindex_trans e e' : _ = reindex R s (e.trans e')) x
/-- This lemma is impractical to state in the dependent case. -/
@[simp]
theorem reindex_symm (e : ι ≃ ι₂) :
(reindex R (fun _ ↦ M) e).symm = reindex R (fun _ ↦ M) e.symm := by
ext x
simp only [reindex, domDomCongrLinearEquiv', LinearEquiv.coe_symm_mk, LinearEquiv.coe_mk,
LinearEquiv.ofLinear_symm_apply, Equiv.symm_symm_apply, LinearEquiv.ofLinear_apply,
Equiv.piCongrLeft'_symm]
@[simp]
theorem reindex_refl : reindex R s (Equiv.refl ι) = LinearEquiv.refl R _ := by
apply LinearEquiv.toLinearMap_injective
ext
simp only [Equiv.refl_symm, Equiv.refl_apply, reindex, domDomCongrLinearEquiv',
LinearEquiv.coe_symm_mk, LinearMap.compMultilinearMap_apply, LinearEquiv.coe_coe,
LinearEquiv.refl_toLinearMap, LinearMap.id_coe, id_eq]
erw [lift.tprod]
congr
variable {t : ι → Type*}
variable [∀ i, AddCommMonoid (t i)] [∀ i, Module R (t i)]
/-- Re-indexing the components of the tensor product by an equivalence `e` is compatible
with `PiTensorProduct.map`. -/
theorem map_comp_reindex_eq (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) :
map (fun i ↦ f (e.symm i)) ∘ₗ reindex R s e = reindex R t e ∘ₗ map f := by
ext m
simp only [LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, LinearEquiv.coe_coe,
LinearMap.comp_apply, reindex_tprod, map_tprod]
theorem map_reindex (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) (x : ⨂[R] i, s i) :
map (fun i ↦ f (e.symm i)) (reindex R s e x) = reindex R t e (map f x) :=
DFunLike.congr_fun (map_comp_reindex_eq _ _) _
theorem map_comp_reindex_symm (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) :
map f ∘ₗ (reindex R s e).symm = (reindex R t e).symm ∘ₗ map (fun i => f (e.symm i)) := by
ext m
apply LinearEquiv.injective (reindex R t e)
simp only [LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, LinearEquiv.coe_coe,
comp_apply, ← map_reindex, LinearEquiv.apply_symm_apply, map_tprod]
theorem map_reindex_symm (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) (x : ⨂[R] i, s (e.symm i)) :
map f ((reindex R s e).symm x) = (reindex R t e).symm (map (fun i ↦ f (e.symm i)) x) :=
DFunLike.congr_fun (map_comp_reindex_symm _ _) _
variable (ι)
attribute [local simp] eq_iff_true_of_subsingleton in
/-- The tensor product over an empty index type `ι` is isomorphic to the base ring. -/
@[simps symm_apply]
def isEmptyEquiv [IsEmpty ι] : (⨂[R] i : ι, s i) ≃ₗ[R] R where
toFun := lift (constOfIsEmpty R _ 1)
invFun r := r • tprod R (@isEmptyElim _ _ _)
left_inv x := by
refine x.induction_on ?_ ?_
· intro x y
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `map_smulₛₗ` into `map_smulₛₗ _`
simp only [map_smulₛₗ _, RingHom.id_apply, lift.tprod, constOfIsEmpty_apply, const_apply,
smul_eq_mul, mul_one]
congr
aesop
· simp only
intro x y hx hy
rw [map_add, add_smul, hx, hy]
right_inv t := by simp
map_add' := LinearMap.map_add _
map_smul' := fun r x => by
exact LinearMap.map_smul _ r x
@[simp]
theorem isEmptyEquiv_apply_tprod [IsEmpty ι] (f : Π i, s i) :
isEmptyEquiv ι (tprod R f) = 1 :=
lift.tprod _
variable {ι}
| /--
Tensor product of `M` over a singleton set is equivalent to `M`
-/
@[simps symm_apply]
def subsingletonEquiv [Subsingleton ι] (i₀ : ι) : (⨂[R] _ : ι, M) ≃ₗ[R] M where
toFun := lift (MultilinearMap.ofSubsingleton R M M i₀ .id)
| Mathlib/LinearAlgebra/PiTensorProduct.lean | 821 | 826 |
/-
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, Bryan Gin-ge Chen
-/
import Mathlib.Order.Heyting.Basic
/-!
# (Generalized) Boolean algebras
A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras
generalize the (classical) logic of propositions and the lattice of subsets of a set.
Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which
do not necessarily have a top element (`⊤`) (and hence not all elements may have complements). One
example in mathlib is `Finset α`, the type of all finite subsets of an arbitrary
(not-necessarily-finite) type `α`.
`GeneralizedBooleanAlgebra α` is defined to be a distributive lattice with bottom (`⊥`) admitting
a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`).
For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra`
so that it is also bundled with a `\` operator.
(A terminological point: `x \ y` is the complement of `y` relative to the interval `[⊥, x]`. We do
not yet have relative complements for arbitrary intervals, as we do not even have lattice
intervals.)
## Main declarations
* `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras
* `BooleanAlgebra`: a type class for Boolean algebras.
* `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop`
## Implementation notes
The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in
`GeneralizedBooleanAlgebra` are taken from
[Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations).
[Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative
complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption
that for all `a, b : α` where `a ≤ b`, the equations `x ⊔ a = b` and `x ⊓ a = ⊥` have a solution
`x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`.
## References
* <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations>
* [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935]
* [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011]
## Tags
generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl
-/
assert_not_exists RelIso
open Function OrderDual
universe u v
variable {α : Type u} {β : Type*} {x y z : α}
/-!
### Generalized Boolean algebras
Some of the lemmas in this section are from:
* [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011]
* <https://ncatlab.org/nlab/show/relative+complement>
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
-/
/-- A generalized Boolean algebra is a distributive lattice with `⊥` and a relative complement
operation `\` (called `sdiff`, after "set difference") satisfying `(a ⊓ b) ⊔ (a \ b) = a` and
`(a ⊓ b) ⊓ (a \ b) = ⊥`, i.e. `a \ b` is the complement of `b` in `a`.
This is a generalization of Boolean algebras which applies to `Finset α` for arbitrary
(not-necessarily-`Fintype`) `α`. -/
class GeneralizedBooleanAlgebra (α : Type u) extends DistribLattice α, SDiff α, Bot α where
/-- For any `a`, `b`, `(a ⊓ b) ⊔ (a / b) = a` -/
sup_inf_sdiff : ∀ a b : α, a ⊓ b ⊔ a \ b = a
/-- For any `a`, `b`, `(a ⊓ b) ⊓ (a / b) = ⊥` -/
inf_inf_sdiff : ∀ a b : α, a ⊓ b ⊓ a \ b = ⊥
-- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`,
-- however we'd need another type class for lattices with bot, and all the API for that.
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α]
@[simp]
theorem sup_inf_sdiff (x y : α) : x ⊓ y ⊔ x \ y = x :=
GeneralizedBooleanAlgebra.sup_inf_sdiff _ _
@[simp]
theorem inf_inf_sdiff (x y : α) : x ⊓ y ⊓ x \ y = ⊥ :=
GeneralizedBooleanAlgebra.inf_inf_sdiff _ _
@[simp]
theorem sup_sdiff_inf (x y : α) : x \ y ⊔ x ⊓ y = x := by rw [sup_comm, sup_inf_sdiff]
@[simp]
theorem inf_sdiff_inf (x y : α) : x \ y ⊓ (x ⊓ y) = ⊥ := by rw [inf_comm, inf_inf_sdiff]
-- see Note [lower instance priority]
instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot α where
__ := GeneralizedBooleanAlgebra.toBot
bot_le a := by
rw [← inf_inf_sdiff a a, inf_assoc]
exact inf_le_left
theorem disjoint_inf_sdiff : Disjoint (x ⊓ y) (x \ y) :=
disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le
-- TODO: in distributive lattices, relative complements are unique when they exist
theorem sdiff_unique (s : x ⊓ y ⊔ z = x) (i : x ⊓ y ⊓ z = ⊥) : x \ y = z := by
conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm]
rw [sup_comm] at s
conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm]
rw [inf_comm] at i
exact (eq_of_inf_eq_sup_eq i s).symm
-- Use `sdiff_le`
private theorem sdiff_le' : x \ y ≤ x :=
calc
x \ y ≤ x ⊓ y ⊔ x \ y := le_sup_right
_ = x := sup_inf_sdiff x y
-- Use `sdiff_sup_self`
private theorem sdiff_sup_self' : y \ x ⊔ x = y ⊔ x :=
calc
y \ x ⊔ x = y \ x ⊔ (x ⊔ x ⊓ y) := by rw [sup_inf_self]
_ = y ⊓ x ⊔ y \ x ⊔ x := by ac_rfl
_ = y ⊔ x := by rw [sup_inf_sdiff]
@[simp]
theorem sdiff_inf_sdiff : x \ y ⊓ y \ x = ⊥ :=
Eq.symm <|
calc
⊥ = x ⊓ y ⊓ x \ y := by rw [inf_inf_sdiff]
_ = x ⊓ (y ⊓ x ⊔ y \ x) ⊓ x \ y := by rw [sup_inf_sdiff]
_ = (x ⊓ (y ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by rw [inf_sup_left]
_ = (y ⊓ (x ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by ac_rfl
_ = (y ⊓ x ⊔ x ⊓ y \ x) ⊓ x \ y := by rw [inf_idem]
_ = x ⊓ y ⊓ x \ y ⊔ x ⊓ y \ x ⊓ x \ y := by rw [inf_sup_right, inf_comm x y]
_ = x ⊓ y \ x ⊓ x \ y := by rw [inf_inf_sdiff, bot_sup_eq]
_ = x ⊓ x \ y ⊓ y \ x := by ac_rfl
_ = x \ y ⊓ y \ x := by rw [inf_of_le_right sdiff_le']
theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) :=
disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le
@[simp]
theorem inf_sdiff_self_right : x ⊓ y \ x = ⊥ :=
calc
x ⊓ y \ x = (x ⊓ y ⊔ x \ y) ⊓ y \ x := by rw [sup_inf_sdiff]
_ = x ⊓ y ⊓ y \ x ⊔ x \ y ⊓ y \ x := by rw [inf_sup_right]
_ = ⊥ := by rw [inf_comm x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq]
@[simp]
theorem inf_sdiff_self_left : y \ x ⊓ x = ⊥ := by rw [inf_comm, inf_sdiff_self_right]
-- see Note [lower instance priority]
instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra :
GeneralizedCoheytingAlgebra α where
__ := ‹GeneralizedBooleanAlgebra α›
__ := GeneralizedBooleanAlgebra.toOrderBot
sdiff := (· \ ·)
sdiff_le_iff y x z :=
⟨fun h =>
le_of_inf_le_sup_le
(le_of_eq
(calc
y ⊓ y \ x = y \ x := inf_of_le_right sdiff_le'
_ = x ⊓ y \ x ⊔ z ⊓ y \ x := by
rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq]
_ = (x ⊔ z) ⊓ y \ x := by rw [← inf_sup_right]))
(calc
y ⊔ y \ x = y := sup_of_le_left sdiff_le'
_ ≤ y ⊔ (x ⊔ z) := le_sup_left
_ = y \ x ⊔ x ⊔ z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y]
_ = x ⊔ z ⊔ y \ x := by ac_rfl),
fun h =>
le_of_inf_le_sup_le
(calc
y \ x ⊓ x = ⊥ := inf_sdiff_self_left
_ ≤ z ⊓ x := bot_le)
(calc
y \ x ⊔ x = y ⊔ x := sdiff_sup_self'
_ ≤ x ⊔ z ⊔ x := sup_le_sup_right h x
_ ≤ z ⊔ x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩
theorem disjoint_sdiff_self_left : Disjoint (y \ x) x :=
disjoint_iff_inf_le.mpr inf_sdiff_self_left.le
theorem disjoint_sdiff_self_right : Disjoint x (y \ x) :=
disjoint_iff_inf_le.mpr inf_sdiff_self_right.le
lemma le_sdiff : x ≤ y \ z ↔ x ≤ y ∧ Disjoint x z :=
⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦
by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩
@[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y :=
⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩
/- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using
`Disjoint x (y \ x)` and `x ⊔ (y \ x) = y` as axioms. -/
theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x ⊔ z = y) : y \ x = z :=
have h : y ⊓ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le
sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot])
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≤ y) (hs : y ≤ x ⊔ z) :
y \ x = z :=
sdiff_unique
| (by
rw [← inf_eq_right] at hs
rwa [sup_inf_right, inf_sup_right, sup_comm x, inf_sup_self, inf_comm, sup_comm z,
| Mathlib/Order/BooleanAlgebra.lean | 218 | 220 |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.Truncated
import Mathlib.RingTheory.WittVector.Identities
import Mathlib.NumberTheory.Padics.RingHoms
/-!
# Comparison isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`
We construct a ring isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`.
This isomorphism follows from the fact that both satisfy the universal property
of the inverse limit of `ZMod (p^n)`.
## Main declarations
* `WittVector.toZModPow`: a family of compatible ring homs `𝕎 (ZMod p) → ZMod (p^k)`
* `WittVector.equiv`: the isomorphism
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable section
variable {p : ℕ} [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
namespace TruncatedWittVector
variable (p) (n : ℕ) (R : Type*) [CommRing R]
theorem eq_of_le_of_cast_pow_eq_zero [CharP R p] (i : ℕ) (hin : i ≤ n)
(hpi : (p : TruncatedWittVector p n R) ^ i = 0) : i = n := by
contrapose! hpi
replace hin := lt_of_le_of_ne hin hpi; clear hpi
have : (p : TruncatedWittVector p n R) ^ i = WittVector.truncate n ((p : 𝕎 R) ^ i) := by
rw [RingHom.map_pow, map_natCast]
rw [this, ne_eq, TruncatedWittVector.ext_iff, not_forall]; clear this
use ⟨i, hin⟩
rw [WittVector.coeff_truncate, coeff_zero, Fin.val_mk, WittVector.coeff_p_pow]
haveI : Nontrivial R := CharP.nontrivial_of_char_ne_one hp.1.ne_one
exact one_ne_zero
section Iso
variable {R}
theorem card_zmod : Fintype.card (TruncatedWittVector p n (ZMod p)) = p ^ n := by
rw [card, ZMod.card]
| theorem charP_zmod : CharP (TruncatedWittVector p n (ZMod p)) (p ^ n) :=
charP_of_prime_pow_injective _ _ _ (card_zmod _ _) (eq_of_le_of_cast_pow_eq_zero p n (ZMod p))
| Mathlib/RingTheory/WittVector/Compare.lean | 60 | 61 |
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
import Mathlib.MeasureTheory.Integral.Bochner.FundThmCalculus
import Mathlib.MeasureTheory.Integral.Bochner.Set
deprecated_module (since := "2025-04-15")
| Mathlib/MeasureTheory/Integral/SetIntegral.lean | 227 | 232 | |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Algebra.Module.ZLattice.Basic
import Mathlib.Analysis.InnerProductSpace.ProdL2
import Mathlib.MeasureTheory.Measure.Haar.Unique
import Mathlib.NumberTheory.NumberField.FractionalIdeal
import Mathlib.NumberTheory.NumberField.Units.Basic
/-!
# Canonical embedding of a number field
The canonical embedding of a number field `K` of degree `n` is the ring homomorphism
`K →+* ℂ^n` that sends `x ∈ K` to `(φ_₁(x),...,φ_n(x))` where the `φ_i`'s are the complex
embeddings of `K`. Note that we do not choose an ordering of the embeddings, but instead map `K`
into the type `(K →+* ℂ) → ℂ` of `ℂ`-vectors indexed by the complex embeddings.
## Main definitions and results
* `NumberField.canonicalEmbedding`: the ring homomorphism `K →+* ((K →+* ℂ) → ℂ)` defined by
sending `x : K` to the vector `(φ x)` indexed by `φ : K →+* ℂ`.
* `NumberField.canonicalEmbedding.integerLattice.inter_ball_finite`: the intersection of the
image of the ring of integers by the canonical embedding and any ball centered at `0` of finite
radius is finite.
* `NumberField.mixedEmbedding`: the ring homomorphism from `K` to the mixed space
`K →+* ({ w // IsReal w } → ℝ) × ({ w // IsComplex w } → ℂ)` that sends `x ∈ K` to `(φ_w x)_w`
where `φ_w` is the embedding associated to the infinite place `w`. In particular, if `w` is real
then `φ_w : K →+* ℝ` and, if `w` is complex, `φ_w` is an arbitrary choice between the two complex
embeddings defining the place `w`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.canonicalEmbedding
/-- The canonical embedding of a number field `K` of degree `n` into `ℂ^n`. -/
def _root_.NumberField.canonicalEmbedding : K →+* ((K →+* ℂ) → ℂ) := Pi.ringHom fun φ => φ
theorem _root_.NumberField.canonicalEmbedding_injective [NumberField K] :
Function.Injective (NumberField.canonicalEmbedding K) := RingHom.injective _
variable {K}
@[simp]
theorem apply_at (φ : K →+* ℂ) (x : K) : (NumberField.canonicalEmbedding K x) φ = φ x := rfl
open scoped ComplexConjugate
/-- The image of `canonicalEmbedding` lives in the `ℝ`-submodule of the `x ∈ ((K →+* ℂ) → ℂ)` such
that `conj x_φ = x_(conj φ)` for all `∀ φ : K →+* ℂ`. -/
theorem conj_apply {x : ((K →+* ℂ) → ℂ)} (φ : K →+* ℂ)
(hx : x ∈ Submodule.span ℝ (Set.range (canonicalEmbedding K))) :
conj (x φ) = x (ComplexEmbedding.conjugate φ) := by
refine Submodule.span_induction ?_ ?_ (fun _ _ _ _ hx hy => ?_) (fun a _ _ hx => ?_) hx
· rintro _ ⟨x, rfl⟩
rw [apply_at, apply_at, ComplexEmbedding.conjugate_coe_eq]
· rw [Pi.zero_apply, Pi.zero_apply, map_zero]
· rw [Pi.add_apply, Pi.add_apply, map_add, hx, hy]
· rw [Pi.smul_apply, Complex.real_smul, map_mul, Complex.conj_ofReal]
exact congrArg ((a : ℂ) * ·) hx
theorem nnnorm_eq [NumberField K] (x : K) :
‖canonicalEmbedding K x‖₊ = Finset.univ.sup (fun φ : K →+* ℂ => ‖φ x‖₊) := by
simp_rw [Pi.nnnorm_def, apply_at]
theorem norm_le_iff [NumberField K] (x : K) (r : ℝ) :
‖canonicalEmbedding K x‖ ≤ r ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := by
obtain hr | hr := lt_or_le r 0
· obtain ⟨φ⟩ := (inferInstance : Nonempty (K →+* ℂ))
refine iff_of_false ?_ ?_
· exact (hr.trans_le (norm_nonneg _)).not_le
· exact fun h => hr.not_le (le_trans (norm_nonneg _) (h φ))
· lift r to NNReal using hr
simp_rw [← coe_nnnorm, nnnorm_eq, NNReal.coe_le_coe, Finset.sup_le_iff, Finset.mem_univ,
forall_true_left]
variable (K)
/-- The image of `𝓞 K` as a subring of `ℂ^n`. -/
def integerLattice : Subring ((K →+* ℂ) → ℂ) :=
(RingHom.range (algebraMap (𝓞 K) K)).map (canonicalEmbedding K)
theorem integerLattice.inter_ball_finite [NumberField K] (r : ℝ) :
((integerLattice K : Set ((K →+* ℂ) → ℂ)) ∩ Metric.closedBall 0 r).Finite := by
obtain hr | _ := lt_or_le r 0
· simp [Metric.closedBall_eq_empty.2 hr]
· have heq : ∀ x, canonicalEmbedding K x ∈ Metric.closedBall 0 r ↔
∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := by
intro x; rw [← norm_le_iff, mem_closedBall_zero_iff]
convert (Embeddings.finite_of_norm_le K ℂ r).image (canonicalEmbedding K)
ext; constructor
· rintro ⟨⟨_, ⟨x, rfl⟩, rfl⟩, hx⟩
exact ⟨x, ⟨SetLike.coe_mem x, fun φ => (heq _).mp hx φ⟩, rfl⟩
· rintro ⟨x, ⟨hx1, hx2⟩, rfl⟩
exact ⟨⟨x, ⟨⟨x, hx1⟩, rfl⟩, rfl⟩, (heq x).mpr hx2⟩
open Module Fintype Module
/-- A `ℂ`-basis of `ℂ^n` that is also a `ℤ`-basis of the `integerLattice`. -/
noncomputable def latticeBasis [NumberField K] :
Basis (Free.ChooseBasisIndex ℤ (𝓞 K)) ℂ ((K →+* ℂ) → ℂ) := by
classical
-- Let `B` be the canonical basis of `(K →+* ℂ) → ℂ`. We prove that the determinant of
-- the image by `canonicalEmbedding` of the integral basis of `K` is nonzero. This
-- will imply the result.
let B := Pi.basisFun ℂ (K →+* ℂ)
let e : (K →+* ℂ) ≃ Free.ChooseBasisIndex ℤ (𝓞 K) :=
equivOfCardEq ((Embeddings.card K ℂ).trans (finrank_eq_card_basis (integralBasis K)))
let M := B.toMatrix (fun i => canonicalEmbedding K (integralBasis K (e i)))
suffices M.det ≠ 0 by
rw [← isUnit_iff_ne_zero, ← Basis.det_apply, ← is_basis_iff_det] at this
exact (basisOfPiSpaceOfLinearIndependent this.1).reindex e
-- In order to prove that the determinant is nonzero, we show that it is equal to the
-- square of the discriminant of the integral basis and thus it is not zero
let N := Algebra.embeddingsMatrixReindex ℚ ℂ (fun i => integralBasis K (e i))
RingHom.equivRatAlgHom
rw [show M = N.transpose by { ext : 2; rfl }]
rw [Matrix.det_transpose, ← pow_ne_zero_iff two_ne_zero]
convert (map_ne_zero_iff _ (algebraMap ℚ ℂ).injective).mpr
(Algebra.discr_not_zero_of_basis ℚ (integralBasis K))
rw [← Algebra.discr_reindex ℚ (integralBasis K) e.symm]
exact (Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two ℚ ℂ
(fun i => integralBasis K (e i)) RingHom.equivRatAlgHom).symm
@[simp]
theorem latticeBasis_apply [NumberField K] (i : Free.ChooseBasisIndex ℤ (𝓞 K)) :
latticeBasis K i = (canonicalEmbedding K) (integralBasis K i) := by
simp [latticeBasis, integralBasis_apply, coe_basisOfPiSpaceOfLinearIndependent,
Function.comp_apply, Equiv.apply_symm_apply]
theorem mem_span_latticeBasis [NumberField K] {x : (K →+* ℂ) → ℂ} :
x ∈ Submodule.span ℤ (Set.range (latticeBasis K)) ↔
x ∈ ((canonicalEmbedding K).comp (algebraMap (𝓞 K) K)).range := by
rw [show Set.range (latticeBasis K) =
(canonicalEmbedding K).toIntAlgHom.toLinearMap '' (Set.range (integralBasis K)) by
rw [← Set.range_comp]; exact congrArg Set.range (funext (fun i => latticeBasis_apply K i))]
rw [← Submodule.map_span, ← SetLike.mem_coe, Submodule.map_coe]
rw [← RingHom.map_range, Subring.mem_map, Set.mem_image]
simp only [SetLike.mem_coe, mem_span_integralBasis K]
rfl
theorem mem_rat_span_latticeBasis [NumberField K] (x : K) :
canonicalEmbedding K x ∈ Submodule.span ℚ (Set.range (latticeBasis K)) := by
rw [← Basis.sum_repr (integralBasis K) x, map_sum]
simp_rw [map_rat_smul]
refine Submodule.sum_smul_mem _ _ (fun i _ ↦ Submodule.subset_span ?_)
rw [← latticeBasis_apply]
exact Set.mem_range_self i
theorem integralBasis_repr_apply [NumberField K] (x : K) (i : Free.ChooseBasisIndex ℤ (𝓞 K)) :
(latticeBasis K).repr (canonicalEmbedding K x) i = (integralBasis K).repr x i := by
rw [← Basis.restrictScalars_repr_apply ℚ _ ⟨_, mem_rat_span_latticeBasis K x⟩, eq_ratCast,
Rat.cast_inj]
let f := (canonicalEmbedding K).toRatAlgHom.toLinearMap.codRestrict _
| (fun x ↦ mem_rat_span_latticeBasis K x)
suffices ((latticeBasis K).restrictScalars ℚ).repr.toLinearMap ∘ₗ f =
(integralBasis K).repr.toLinearMap from DFunLike.congr_fun (LinearMap.congr_fun this x) i
refine Basis.ext (integralBasis K) (fun i ↦ ?_)
have : f (integralBasis K i) = ((latticeBasis K).restrictScalars ℚ) i := by
apply Subtype.val_injective
rw [LinearMap.codRestrict_apply, AlgHom.toLinearMap_apply, Basis.restrictScalars_apply,
latticeBasis_apply]
rfl
simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, this, Basis.repr_self]
end NumberField.canonicalEmbedding
namespace NumberField.mixedEmbedding
| Mathlib/NumberTheory/NumberField/CanonicalEmbedding/Basic.lean | 163 | 177 |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Julian Kuelshammer, Heather Macbeth, Mitchell Lee
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Ring.NegOnePow
import Mathlib.Tactic.LinearCombination
/-!
# Chebyshev polynomials
The Chebyshev polynomials are families of polynomials indexed by `ℤ`,
with integral coefficients.
## Main definitions
* `Polynomial.Chebyshev.T`: the Chebyshev polynomials of the first kind.
* `Polynomial.Chebyshev.U`: the Chebyshev polynomials of the second kind.
* `Polynomial.Chebyshev.C`: the rescaled Chebyshev polynomials of the first kind (also known as the
Vieta–Lucas polynomials), given by $C_n(2x) = 2T_n(x)$.
* `Polynomial.Chebyshev.S`: the rescaled Chebyshev polynomials of the second kind (also known as the
Vieta–Fibonacci polynomials), given by $S_n(2x) = U_n(x)$.
## Main statements
* The formal derivative of the Chebyshev polynomials of the first kind is a scalar multiple of the
Chebyshev polynomials of the second kind.
* `Polynomial.Chebyshev.T_mul_T`, twice the product of the `m`-th and `k`-th Chebyshev polynomials
of the first kind is the sum of the `m + k`-th and `m - k`-th Chebyshev polynomials of the first
kind. There is a similar statement `Polynomial.Chebyshev.C_mul_C` for the `C` polynomials.
* `Polynomial.Chebyshev.T_mul`, the `(m * n)`-th Chebyshev polynomial of the first kind is the
composition of the `m`-th and `n`-th Chebyshev polynomials of the first kind. There is a similar
statement `Polynomial.Chebyshev.C_mul` for the `C` polynomials.
## Implementation details
Since Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`,
we define them to have coefficients in an arbitrary commutative ring, even though
technically `ℤ` would suffice.
The benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean,
and do not have `map (Int.castRingHom R)` interfering all the time.
## References
[Lionel Ponton, _Roots of the Chebyshev polynomials: A purely algebraic approach_]
[ponton2020chebyshev]
## TODO
* Redefine and/or relate the definition of Chebyshev polynomials to `LinearRecurrence`.
* Add explicit formula involving square roots for Chebyshev polynomials
* Compute zeroes and extrema of Chebyshev polynomials.
* Prove that the roots of the Chebyshev polynomials (except 0) are irrational.
* Prove minimax properties of Chebyshev polynomials.
-/
namespace Polynomial.Chebyshev
open Polynomial
variable (R R' : Type*) [CommRing R] [CommRing R']
/-- `T n` is the `n`-th Chebyshev polynomial of the first kind. -/
-- Well-founded definitions are now irreducible by default;
-- as this was implemented before this change,
-- we just set it back to semireducible to avoid needing to change any proofs.
@[semireducible] noncomputable def T : ℤ → R[X]
| 0 => 1
| 1 => X
| (n : ℕ) + 2 => 2 * X * T (n + 1) - T n
| -((n : ℕ) + 1) => 2 * X * T (-n) - T (-n + 1)
termination_by n => Int.natAbs n + Int.natAbs (n - 1)
/-- Induction principle used for proving facts about Chebyshev polynomials. -/
@[elab_as_elim]
protected theorem induct (motive : ℤ → Prop)
(zero : motive 0)
(one : motive 1)
(add_two : ∀ (n : ℕ), motive (↑n + 1) → motive ↑n → motive (↑n + 2))
(neg_add_one : ∀ (n : ℕ), motive (-↑n) → motive (-↑n + 1) → motive (-↑n - 1)) :
∀ (a : ℤ), motive a :=
T.induct motive zero one add_two fun n hn hnm => by
simpa only [Int.negSucc_eq, neg_add] using neg_add_one n hn hnm
@[simp]
theorem T_add_two : ∀ n, T R (n + 2) = 2 * X * T R (n + 1) - T R n
| (k : ℕ) => T.eq_3 R k
| -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) T.eq_4 R k
theorem T_add_one (n : ℤ) : T R (n + 1) = 2 * X * T R n - T R (n - 1) := by
linear_combination (norm := ring_nf) T_add_two R (n - 1)
theorem T_sub_two (n : ℤ) : T R (n - 2) = 2 * X * T R (n - 1) - T R n := by
linear_combination (norm := ring_nf) T_add_two R (n - 2)
theorem T_sub_one (n : ℤ) : T R (n - 1) = 2 * X * T R n - T R (n + 1) := by
linear_combination (norm := ring_nf) T_add_two R (n - 1)
theorem T_eq (n : ℤ) : T R n = 2 * X * T R (n - 1) - T R (n - 2) := by
linear_combination (norm := ring_nf) T_add_two R (n - 2)
@[simp]
theorem T_zero : T R 0 = 1 := rfl
@[simp]
theorem T_one : T R 1 = X := rfl
theorem T_neg_one : T R (-1) = X := show 2 * X * 1 - X = X by ring
theorem T_two : T R 2 = 2 * X ^ 2 - 1 := by
simpa [pow_two, mul_assoc] using T_add_two R 0
@[simp]
theorem T_neg (n : ℤ) : T R (-n) = T R n := by
induction n using Polynomial.Chebyshev.induct with
| zero => rfl
| one => show 2 * X * 1 - X = X; ring
| add_two n ih1 ih2 =>
have h₁ := T_add_two R n
have h₂ := T_sub_two R (-n)
linear_combination (norm := ring_nf) (2 * (X : R[X])) * ih1 - ih2 - h₁ + h₂
| neg_add_one n ih1 ih2 =>
have h₁ := T_add_one R n
have h₂ := T_sub_one R (-n)
linear_combination (norm := ring_nf) (2 * (X : R[X])) * ih1 - ih2 + h₁ - h₂
theorem T_natAbs (n : ℤ) : T R n.natAbs = T R n := by
obtain h | h := Int.natAbs_eq n <;> nth_rw 2 [h]; simp
theorem T_neg_two : T R (-2) = 2 * X ^ 2 - 1 := by simp [T_two]
@[simp]
theorem T_eval_one (n : ℤ) : (T R n).eval 1 = 1 := by
induction n using Polynomial.Chebyshev.induct with
| zero => simp
| one => simp
| add_two n ih1 ih2 => simp [T_add_two, ih1, ih2]; norm_num
| neg_add_one n ih1 ih2 => simp [T_sub_one, -T_neg, ih1, ih2]; norm_num
@[simp]
theorem T_eval_neg_one (n : ℤ) : (T R n).eval (-1) = n.negOnePow := by
induction n using Polynomial.Chebyshev.induct with
| zero => simp
| one => simp
| add_two n ih1 ih2 =>
simp only [T_add_two, eval_sub, eval_mul, eval_ofNat, eval_X, mul_neg, mul_one, ih1,
Int.negOnePow_add, Int.negOnePow_one, Units.val_neg, Int.cast_neg, neg_mul, neg_neg, ih2,
Int.negOnePow_def 2]
norm_cast
norm_num
ring
| neg_add_one n ih1 ih2 =>
simp only [T_sub_one, eval_sub, eval_mul, eval_ofNat, eval_X, mul_neg, mul_one, ih1, neg_mul,
ih2, Int.negOnePow_add, Int.negOnePow_one, Units.val_neg, Int.cast_neg, sub_neg_eq_add,
Int.negOnePow_sub]
ring
/-- `U n` is the `n`-th Chebyshev polynomial of the second kind. -/
-- Well-founded definitions are now irreducible by default;
-- as this was implemented before this change,
-- we just set it back to semireducible to avoid needing to change any proofs.
@[semireducible] noncomputable def U : ℤ → R[X]
| 0 => 1
| 1 => 2 * X
| (n : ℕ) + 2 => 2 * X * U (n + 1) - U n
| -((n : ℕ) + 1) => 2 * X * U (-n) - U (-n + 1)
termination_by n => Int.natAbs n + Int.natAbs (n - 1)
@[simp]
theorem U_add_two : ∀ n, U R (n + 2) = 2 * X * U R (n + 1) - U R n
| (k : ℕ) => U.eq_3 R k
| -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) U.eq_4 R k
theorem U_add_one (n : ℤ) : U R (n + 1) = 2 * X * U R n - U R (n - 1) := by
linear_combination (norm := ring_nf) U_add_two R (n - 1)
theorem U_sub_two (n : ℤ) : U R (n - 2) = 2 * X * U R (n - 1) - U R n := by
linear_combination (norm := ring_nf) U_add_two R (n - 2)
theorem U_sub_one (n : ℤ) : U R (n - 1) = 2 * X * U R n - U R (n + 1) := by
linear_combination (norm := ring_nf) U_add_two R (n - 1)
theorem U_eq (n : ℤ) : U R n = 2 * X * U R (n - 1) - U R (n - 2) := by
linear_combination (norm := ring_nf) U_add_two R (n - 2)
@[simp]
theorem U_zero : U R 0 = 1 := rfl
@[simp]
theorem U_one : U R 1 = 2 * X := rfl
@[simp]
theorem U_neg_one : U R (-1) = 0 := by simpa using U_sub_one R 0
theorem U_two : U R 2 = 4 * X ^ 2 - 1 := by
have := U_add_two R 0
simp only [zero_add, U_one, U_zero] at this
linear_combination this
@[simp]
theorem U_neg_two : U R (-2) = -1 := by
simpa [zero_sub, Int.reduceNeg, U_neg_one, mul_zero, U_zero] using U_sub_two R 0
theorem U_neg_sub_one (n : ℤ) : U R (-n - 1) = -U R (n - 1) := by
induction n using Polynomial.Chebyshev.induct with
| zero => simp
| one => simp
| add_two n ih1 ih2 =>
have h₁ := U_add_one R n
have h₂ := U_sub_two R (-n - 1)
linear_combination (norm := ring_nf) 2 * (X : R[X]) * ih1 - ih2 + h₁ + h₂
| neg_add_one n ih1 ih2 =>
have h₁ := U_eq R n
have h₂ := U_sub_two R (-n)
linear_combination (norm := ring_nf) 2 * (X : R[X]) * ih1 - ih2 + h₁ + h₂
theorem U_neg (n : ℤ) : U R (-n) = -U R (n - 2) := by simpa [sub_sub] using U_neg_sub_one R (n - 1)
@[simp]
theorem U_neg_sub_two (n : ℤ) : U R (-n - 2) = -U R n := by
simpa [sub_eq_add_neg, add_comm] using U_neg R (n + 2)
@[simp]
| theorem U_eval_one (n : ℤ) : (U R n).eval 1 = n + 1 := by
induction n using Polynomial.Chebyshev.induct with
| zero => simp
| one => simp; norm_num
| add_two n ih1 ih2 =>
| Mathlib/RingTheory/Polynomial/Chebyshev.lean | 226 | 230 |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Xavier Roblot
-/
import Mathlib.Algebra.Algebra.Hom.Rat
import Mathlib.Analysis.Complex.Polynomial.Basic
import Mathlib.NumberTheory.NumberField.Norm
import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots
import Mathlib.Topology.Instances.Complex
/-!
# Embeddings of number fields
This file defines the embeddings of a number field into an algebraic closed field.
## Main Definitions and Results
* `NumberField.Embeddings.range_eval_eq_rootSet_minpoly`: let `x ∈ K` with `K` number field and
let `A` be an algebraic closed field of char. 0, then the images of `x` by the embeddings of `K`
in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`.
* `NumberField.Embeddings.pow_eq_one_of_norm_eq_one`: an algebraic integer whose conjugates are
all of norm one is a root of unity.
* `NumberField.InfinitePlace`: the type of infinite places of a number field `K`.
* `NumberField.InfinitePlace.mk_eq_iff`: two complex embeddings define the same infinite place iff
they are equal or complex conjugates.
* `NumberField.InfinitePlace.prod_eq_abs_norm`: the infinite part of the product formula, that is
for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where the product is over the infinite place `w` and
`‖·‖_w` is the normalized absolute value for `w`.
## Tags
number field, embeddings, places, infinite places
-/
open scoped Finset
namespace NumberField.Embeddings
section Fintype
open Module
variable (K : Type*) [Field K] [NumberField K]
variable (A : Type*) [Field A] [CharZero A]
/-- There are finitely many embeddings of a number field. -/
noncomputable instance : Fintype (K →+* A) :=
Fintype.ofEquiv (K →ₐ[ℚ] A) RingHom.equivRatAlgHom.symm
variable [IsAlgClosed A]
/-- The number of embeddings of a number field is equal to its finrank. -/
theorem card : Fintype.card (K →+* A) = finrank ℚ K := by
rw [Fintype.ofEquiv_card RingHom.equivRatAlgHom.symm, AlgHom.card]
instance : Nonempty (K →+* A) := by
rw [← Fintype.card_pos_iff, NumberField.Embeddings.card K A]
exact Module.finrank_pos
end Fintype
section Roots
open Set Polynomial
variable (K A : Type*) [Field K] [NumberField K] [Field A] [Algebra ℚ A] [IsAlgClosed A] (x : K)
/-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K` a number field.
The images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of
the minimal polynomial of `x` over `ℚ`. -/
theorem range_eval_eq_rootSet_minpoly :
(range fun φ : K →+* A => φ x) = (minpoly ℚ x).rootSet A := by
convert (NumberField.isAlgebraic K).range_eval_eq_rootSet_minpoly A x using 1
ext a
exact ⟨fun ⟨φ, hφ⟩ => ⟨φ.toRatAlgHom, hφ⟩, fun ⟨φ, hφ⟩ => ⟨φ.toRingHom, hφ⟩⟩
end Roots
section Bounded
open Module Polynomial Set
variable {K : Type*} [Field K] [NumberField K]
variable {A : Type*} [NormedField A] [IsAlgClosed A] [NormedAlgebra ℚ A]
theorem coeff_bdd_of_norm_le {B : ℝ} {x : K} (h : ∀ φ : K →+* A, ‖φ x‖ ≤ B) (i : ℕ) :
‖(minpoly ℚ x).coeff i‖ ≤ max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2) := by
have hx := Algebra.IsSeparable.isIntegral ℚ x
rw [← norm_algebraMap' A, ← coeff_map (algebraMap ℚ A)]
refine coeff_bdd_of_roots_le _ (minpoly.monic hx)
(IsAlgClosed.splits_codomain _) (minpoly.natDegree_le x) (fun z hz => ?_) i
classical
rw [← Multiset.mem_toFinset] at hz
obtain ⟨φ, rfl⟩ := (range_eval_eq_rootSet_minpoly K A x).symm.subset hz
exact h φ
variable (K A)
/-- Let `B` be a real number. The set of algebraic integers in `K` whose conjugates are all
smaller in norm than `B` is finite. -/
theorem finite_of_norm_le (B : ℝ) : {x : K | IsIntegral ℤ x ∧ ∀ φ : K →+* A, ‖φ x‖ ≤ B}.Finite := by
classical
let C := Nat.ceil (max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2))
have := bUnion_roots_finite (algebraMap ℤ K) (finrank ℚ K) (finite_Icc (-C : ℤ) C)
refine this.subset fun x hx => ?_; simp_rw [mem_iUnion]
have h_map_ℚ_minpoly := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx.1
refine ⟨_, ⟨?_, fun i => ?_⟩, mem_rootSet.2 ⟨minpoly.ne_zero hx.1, minpoly.aeval ℤ x⟩⟩
· rw [← (minpoly.monic hx.1).natDegree_map (algebraMap ℤ ℚ), ← h_map_ℚ_minpoly]
exact minpoly.natDegree_le x
rw [mem_Icc, ← abs_le, ← @Int.cast_le ℝ]
refine (Eq.trans_le ?_ <| coeff_bdd_of_norm_le hx.2 i).trans (Nat.le_ceil _)
rw [h_map_ℚ_minpoly, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs]
/-- An algebraic integer whose conjugates are all of norm one is a root of unity. -/
theorem pow_eq_one_of_norm_eq_one {x : K} (hxi : IsIntegral ℤ x) (hx : ∀ φ : K →+* A, ‖φ x‖ = 1) :
∃ (n : ℕ) (_ : 0 < n), x ^ n = 1 := by
obtain ⟨a, -, b, -, habne, h⟩ :=
@Set.Infinite.exists_ne_map_eq_of_mapsTo _ _ _ _ (x ^ · : ℕ → K) Set.infinite_univ
(by exact fun a _ => ⟨hxi.pow a, fun φ => by simp [hx φ]⟩) (finite_of_norm_le K A (1 : ℝ))
wlog hlt : b < a
· exact this K A hxi hx b a habne.symm h.symm (habne.lt_or_lt.resolve_right hlt)
refine ⟨a - b, tsub_pos_of_lt hlt, ?_⟩
rw [← Nat.sub_add_cancel hlt.le, pow_add, mul_left_eq_self₀] at h
refine h.resolve_right fun hp => ?_
specialize hx (IsAlgClosed.lift (R := ℚ)).toRingHom
rw [pow_eq_zero hp, map_zero, norm_zero] at hx; norm_num at hx
end Bounded
end NumberField.Embeddings
section Place
variable {K : Type*} [Field K] {A : Type*} [NormedDivisionRing A] [Nontrivial A] (φ : K →+* A)
/-- An embedding into a normed division ring defines a place of `K` -/
def NumberField.place : AbsoluteValue K ℝ :=
(IsAbsoluteValue.toAbsoluteValue (norm : A → ℝ)).comp φ.injective
@[simp]
theorem NumberField.place_apply (x : K) : (NumberField.place φ) x = norm (φ x) := rfl
end Place
namespace NumberField.ComplexEmbedding
open Complex NumberField
open scoped ComplexConjugate
variable {K : Type*} [Field K] {k : Type*} [Field k]
variable (K) in
/--
A (random) lift of the complex embedding `φ : k →+* ℂ` to an extension `K` of `k`.
-/
noncomputable def lift [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) : K →+* ℂ := by
letI := φ.toAlgebra
exact (IsAlgClosed.lift (R := k)).toRingHom
@[simp]
theorem lift_comp_algebraMap [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) :
(lift K φ).comp (algebraMap k K) = φ := by
unfold lift
letI := φ.toAlgebra
rw [AlgHom.toRingHom_eq_coe, AlgHom.comp_algebraMap_of_tower, RingHom.algebraMap_toAlgebra']
@[simp]
theorem lift_algebraMap_apply [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) (x : k) :
lift K φ (algebraMap k K x) = φ x :=
RingHom.congr_fun (lift_comp_algebraMap φ) x
/-- The conjugate of a complex embedding as a complex embedding. -/
abbrev conjugate (φ : K →+* ℂ) : K →+* ℂ := star φ
@[simp]
theorem conjugate_coe_eq (φ : K →+* ℂ) (x : K) : (conjugate φ) x = conj (φ x) := rfl
theorem place_conjugate (φ : K →+* ℂ) : place (conjugate φ) = place φ := by
ext; simp only [place_apply, norm_conj, conjugate_coe_eq]
/-- An embedding into `ℂ` is real if it is fixed by complex conjugation. -/
abbrev IsReal (φ : K →+* ℂ) : Prop := IsSelfAdjoint φ
theorem isReal_iff {φ : K →+* ℂ} : IsReal φ ↔ conjugate φ = φ := isSelfAdjoint_iff
theorem isReal_conjugate_iff {φ : K →+* ℂ} : IsReal (conjugate φ) ↔ IsReal φ :=
IsSelfAdjoint.star_iff
/-- A real embedding as a ring homomorphism from `K` to `ℝ` . -/
def IsReal.embedding {φ : K →+* ℂ} (hφ : IsReal φ) : K →+* ℝ where
toFun x := (φ x).re
map_one' := by simp only [map_one, one_re]
map_mul' := by
simp only [Complex.conj_eq_iff_im.mp (RingHom.congr_fun hφ _), map_mul, mul_re,
mul_zero, tsub_zero, eq_self_iff_true, forall_const]
map_zero' := by simp only [map_zero, zero_re]
map_add' := by simp only [map_add, add_re, eq_self_iff_true, forall_const]
@[simp]
theorem IsReal.coe_embedding_apply {φ : K →+* ℂ} (hφ : IsReal φ) (x : K) :
(hφ.embedding x : ℂ) = φ x := by
apply Complex.ext
· rfl
· rw [ofReal_im, eq_comm, ← Complex.conj_eq_iff_im]
exact RingHom.congr_fun hφ x
lemma IsReal.comp (f : k →+* K) {φ : K →+* ℂ} (hφ : IsReal φ) :
IsReal (φ.comp f) := by ext1 x; simpa using RingHom.congr_fun hφ (f x)
lemma isReal_comp_iff {f : k ≃+* K} {φ : K →+* ℂ} :
IsReal (φ.comp (f : k →+* K)) ↔ IsReal φ :=
⟨fun H ↦ by convert H.comp f.symm.toRingHom; ext1; simp, IsReal.comp _⟩
lemma exists_comp_symm_eq_of_comp_eq [Algebra k K] [IsGalois k K] (φ ψ : K →+* ℂ)
(h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) :
∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by
letI := (φ.comp (algebraMap k K)).toAlgebra
letI := φ.toAlgebra
have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl
let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm }
use (AlgHom.restrictNormal' ψ' K).symm
ext1 x
exact AlgHom.restrictNormal_commutes ψ' K x
variable [Algebra k K] (φ : K →+* ℂ) (σ : K ≃ₐ[k] K)
/--
`IsConj φ σ` states that `σ : K ≃ₐ[k] K` is the conjugation under the embedding `φ : K →+* ℂ`.
-/
def IsConj : Prop := conjugate φ = φ.comp σ
variable {φ σ}
lemma IsConj.eq (h : IsConj φ σ) (x) : φ (σ x) = star (φ x) := RingHom.congr_fun h.symm x
lemma IsConj.ext {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) (h₂ : IsConj φ σ₂) : σ₁ = σ₂ :=
AlgEquiv.ext fun x ↦ φ.injective ((h₁.eq x).trans (h₂.eq x).symm)
lemma IsConj.ext_iff {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) : σ₁ = σ₂ ↔ IsConj φ σ₂ :=
⟨fun e ↦ e ▸ h₁, h₁.ext⟩
lemma IsConj.isReal_comp (h : IsConj φ σ) : IsReal (φ.comp (algebraMap k K)) := by
ext1 x
simp only [conjugate_coe_eq, RingHom.coe_comp, Function.comp_apply, ← h.eq,
starRingEnd_apply, AlgEquiv.commutes]
lemma isConj_one_iff : IsConj φ (1 : K ≃ₐ[k] K) ↔ IsReal φ := Iff.rfl
alias ⟨_, IsReal.isConjGal_one⟩ := ComplexEmbedding.isConj_one_iff
lemma IsConj.symm (hσ : IsConj φ σ) :
IsConj φ σ.symm := RingHom.ext fun x ↦ by simpa using congr_arg star (hσ.eq (σ.symm x))
lemma isConj_symm : IsConj φ σ.symm ↔ IsConj φ σ :=
⟨IsConj.symm, IsConj.symm⟩
end NumberField.ComplexEmbedding
section InfinitePlace
open NumberField
variable {k : Type*} [Field k] (K : Type*) [Field K] {F : Type*} [Field F]
/-- An infinite place of a number field `K` is a place associated to a complex embedding. -/
def NumberField.InfinitePlace := { w : AbsoluteValue K ℝ // ∃ φ : K →+* ℂ, place φ = w }
instance [NumberField K] : Nonempty (NumberField.InfinitePlace K) := Set.instNonemptyRange _
variable {K}
/-- Return the infinite place defined by a complex embedding `φ`. -/
noncomputable def NumberField.InfinitePlace.mk (φ : K →+* ℂ) : NumberField.InfinitePlace K :=
⟨place φ, ⟨φ, rfl⟩⟩
namespace NumberField.InfinitePlace
open NumberField
instance {K : Type*} [Field K] : FunLike (InfinitePlace K) K ℝ where
coe w x := w.1 x
coe_injective' _ _ h := Subtype.eq (AbsoluteValue.ext fun x => congr_fun h x)
lemma coe_apply {K : Type*} [Field K] (v : InfinitePlace K) (x : K) :
v x = v.1 x := rfl
@[ext]
lemma ext {K : Type*} [Field K] (v₁ v₂ : InfinitePlace K) (h : ∀ k, v₁ k = v₂ k) : v₁ = v₂ :=
Subtype.ext <| AbsoluteValue.ext h
instance : MonoidWithZeroHomClass (InfinitePlace K) K ℝ where
map_mul w _ _ := w.1.map_mul _ _
map_one w := w.1.map_one
map_zero w := w.1.map_zero
instance : NonnegHomClass (InfinitePlace K) K ℝ where
apply_nonneg w _ := w.1.nonneg _
@[simp]
theorem apply (φ : K →+* ℂ) (x : K) : (mk φ) x = ‖φ x‖ := rfl
/-- For an infinite place `w`, return an embedding `φ` such that `w = infinite_place φ` . -/
noncomputable def embedding (w : InfinitePlace K) : K →+* ℂ := w.2.choose
@[simp]
theorem mk_embedding (w : InfinitePlace K) : mk (embedding w) = w := Subtype.ext w.2.choose_spec
@[simp]
theorem mk_conjugate_eq (φ : K →+* ℂ) : mk (ComplexEmbedding.conjugate φ) = mk φ := by
refine DFunLike.ext _ _ (fun x => ?_)
rw [apply, apply, ComplexEmbedding.conjugate_coe_eq, Complex.norm_conj]
theorem norm_embedding_eq (w : InfinitePlace K) (x : K) :
‖(embedding w) x‖ = w x := by
nth_rewrite 2 [← mk_embedding w]
rfl
theorem eq_iff_eq (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x = r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ = r :=
⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩
theorem le_iff_le (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x ≤ r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r :=
⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩
theorem pos_iff {w : InfinitePlace K} {x : K} : 0 < w x ↔ x ≠ 0 := AbsoluteValue.pos_iff w.1
@[simp]
theorem mk_eq_iff {φ ψ : K →+* ℂ} : mk φ = mk ψ ↔ φ = ψ ∨ ComplexEmbedding.conjugate φ = ψ := by
constructor
· -- We prove that the map ψ ∘ φ⁻¹ between φ(K) and ℂ is uniform continuous, thus it is either the
-- inclusion or the complex conjugation using `Complex.uniformContinuous_ringHom_eq_id_or_conj`
intro h₀
obtain ⟨j, hiφ⟩ := (φ.injective).hasLeftInverse
let ι := RingEquiv.ofLeftInverse hiφ
have hlip : LipschitzWith 1 (RingHom.comp ψ ι.symm.toRingHom) := by
change LipschitzWith 1 (ψ ∘ ι.symm)
apply LipschitzWith.of_dist_le_mul
intro x y
rw [NNReal.coe_one, one_mul, NormedField.dist_eq, Function.comp_apply, Function.comp_apply,
← map_sub, ← map_sub]
apply le_of_eq
suffices ‖φ (ι.symm (x - y))‖ = ‖ψ (ι.symm (x - y))‖ by
rw [← this, ← RingEquiv.ofLeftInverse_apply hiφ _, RingEquiv.apply_symm_apply ι _]
rfl
exact congrFun (congrArg (↑) h₀) _
cases
Complex.uniformContinuous_ringHom_eq_id_or_conj φ.fieldRange hlip.uniformContinuous with
| inl h =>
left; ext1 x
conv_rhs => rw [← hiφ x]
exact (congrFun h (ι x)).symm
| inr h =>
right; ext1 x
conv_rhs => rw [← hiφ x]
exact (congrFun h (ι x)).symm
· rintro (⟨h⟩ | ⟨h⟩)
· exact congr_arg mk h
· rw [← mk_conjugate_eq]
exact congr_arg mk h
/-- An infinite place is real if it is defined by a real embedding. -/
def IsReal (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ComplexEmbedding.IsReal φ ∧ mk φ = w
/-- An infinite place is complex if it is defined by a complex (ie. not real) embedding. -/
def IsComplex (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ¬ComplexEmbedding.IsReal φ ∧ mk φ = w
theorem embedding_mk_eq (φ : K →+* ℂ) :
embedding (mk φ) = φ ∨ embedding (mk φ) = ComplexEmbedding.conjugate φ := by
rw [@eq_comm _ _ φ, @eq_comm _ _ (ComplexEmbedding.conjugate φ), ← mk_eq_iff, mk_embedding]
@[simp]
theorem embedding_mk_eq_of_isReal {φ : K →+* ℂ} (h : ComplexEmbedding.IsReal φ) :
embedding (mk φ) = φ := by
have := embedding_mk_eq φ
rwa [ComplexEmbedding.isReal_iff.mp h, or_self] at this
theorem isReal_iff {w : InfinitePlace K} :
IsReal w ↔ ComplexEmbedding.IsReal (embedding w) := by
refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩
rintro ⟨φ, ⟨hφ, rfl⟩⟩
rwa [embedding_mk_eq_of_isReal hφ]
theorem isComplex_iff {w : InfinitePlace K} :
IsComplex w ↔ ¬ComplexEmbedding.IsReal (embedding w) := by
refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩
rintro ⟨φ, ⟨hφ, rfl⟩⟩
contrapose! hφ
cases mk_eq_iff.mp (mk_embedding (mk φ)) with
| inl h => rwa [h] at hφ
| inr h => rwa [← ComplexEmbedding.isReal_conjugate_iff, h] at hφ
@[simp]
theorem conjugate_embedding_eq_of_isReal {w : InfinitePlace K} (h : IsReal w) :
ComplexEmbedding.conjugate (embedding w) = embedding w :=
ComplexEmbedding.isReal_iff.mpr (isReal_iff.mp h)
@[simp]
theorem not_isReal_iff_isComplex {w : InfinitePlace K} : ¬IsReal w ↔ IsComplex w := by
rw [isComplex_iff, isReal_iff]
@[simp]
theorem not_isComplex_iff_isReal {w : InfinitePlace K} : ¬IsComplex w ↔ IsReal w := by
rw [isComplex_iff, isReal_iff, not_not]
theorem isReal_or_isComplex (w : InfinitePlace K) : IsReal w ∨ IsComplex w := by
rw [← not_isReal_iff_isComplex]; exact em _
theorem ne_of_isReal_isComplex {w w' : InfinitePlace K} (h : IsReal w) (h' : IsComplex w') :
w ≠ w' := fun h_eq ↦ not_isReal_iff_isComplex.mpr h' (h_eq ▸ h)
variable (K) in
theorem disjoint_isReal_isComplex :
Disjoint {(w : InfinitePlace K) | IsReal w} {(w : InfinitePlace K) | IsComplex w} :=
Set.disjoint_iff.2 <| fun _ hw ↦ not_isReal_iff_isComplex.2 hw.2 hw.1
/-- The real embedding associated to a real infinite place. -/
noncomputable def embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) : K →+* ℝ :=
ComplexEmbedding.IsReal.embedding (isReal_iff.mp hw)
@[simp]
theorem embedding_of_isReal_apply {w : InfinitePlace K} (hw : IsReal w) (x : K) :
((embedding_of_isReal hw) x : ℂ) = (embedding w) x :=
ComplexEmbedding.IsReal.coe_embedding_apply (isReal_iff.mp hw) x
theorem norm_embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) (x : K) :
‖embedding_of_isReal hw x‖ = w x := by
rw [← norm_embedding_eq, ← embedding_of_isReal_apply hw, Complex.norm_real]
@[simp]
theorem isReal_of_mk_isReal {φ : K →+* ℂ} (h : IsReal (mk φ)) :
ComplexEmbedding.IsReal φ := by
contrapose! h
rw [not_isReal_iff_isComplex]
exact ⟨φ, h, rfl⟩
lemma isReal_mk_iff {φ : K →+* ℂ} :
IsReal (mk φ) ↔ ComplexEmbedding.IsReal φ :=
⟨isReal_of_mk_isReal, fun H ↦ ⟨_, H, rfl⟩⟩
lemma isComplex_mk_iff {φ : K →+* ℂ} :
IsComplex (mk φ) ↔ ¬ ComplexEmbedding.IsReal φ :=
not_isReal_iff_isComplex.symm.trans isReal_mk_iff.not
@[simp]
theorem not_isReal_of_mk_isComplex {φ : K →+* ℂ} (h : IsComplex (mk φ)) :
¬ ComplexEmbedding.IsReal φ := by rwa [← isComplex_mk_iff]
open scoped Classical in
/-- The multiplicity of an infinite place, that is the number of distinct complex embeddings that
define it, see `card_filter_mk_eq`. -/
noncomputable def mult (w : InfinitePlace K) : ℕ := if (IsReal w) then 1 else 2
@[simp]
theorem mult_isReal (w : {w : InfinitePlace K // IsReal w}) :
mult w.1 = 1 := by
rw [mult, if_pos w.prop]
@[simp]
theorem mult_isComplex (w : {w : InfinitePlace K // IsComplex w}) :
mult w.1 = 2 := by
rw [mult, if_neg (not_isReal_iff_isComplex.mpr w.prop)]
theorem mult_pos {w : InfinitePlace K} : 0 < mult w := by
rw [mult]
split_ifs <;> norm_num
@[simp]
theorem mult_ne_zero {w : InfinitePlace K} : mult w ≠ 0 := ne_of_gt mult_pos
theorem mult_coe_ne_zero {w : InfinitePlace K} : (mult w : ℝ) ≠ 0 :=
Nat.cast_ne_zero.mpr mult_ne_zero
theorem one_le_mult {w : InfinitePlace K} : (1 : ℝ) ≤ mult w := by
rw [← Nat.cast_one, Nat.cast_le]
exact mult_pos
open scoped Classical in
theorem card_filter_mk_eq [NumberField K] (w : InfinitePlace K) : #{φ | mk φ = w} = mult w := by
conv_lhs =>
congr; congr; ext
rw [← mk_embedding w, mk_eq_iff, ComplexEmbedding.conjugate, star_involutive.eq_iff]
simp_rw [Finset.filter_or, Finset.filter_eq' _ (embedding w),
Finset.filter_eq' _ (ComplexEmbedding.conjugate (embedding w)),
Finset.mem_univ, ite_true, mult]
split_ifs with hw
· rw [ComplexEmbedding.isReal_iff.mp (isReal_iff.mp hw), Finset.union_idempotent,
Finset.card_singleton]
· refine Finset.card_pair ?_
rwa [Ne, eq_comm, ← ComplexEmbedding.isReal_iff, ← isReal_iff]
open scoped Classical in
noncomputable instance NumberField.InfinitePlace.fintype [NumberField K] :
Fintype (InfinitePlace K) := Set.fintypeRange _
open scoped Classical in
@[to_additive]
theorem prod_eq_prod_mul_prod {α : Type*} [CommMonoid α] [NumberField K] (f : InfinitePlace K → α) :
∏ w, f w = (∏ w : {w // IsReal w}, f w.1) * (∏ w : {w // IsComplex w}, f w.1) := by
rw [← Equiv.prod_comp (Equiv.subtypeEquivRight (fun _ ↦ not_isReal_iff_isComplex))]
simp [Fintype.prod_subtype_mul_prod_subtype]
theorem sum_mult_eq [NumberField K] :
∑ w : InfinitePlace K, mult w = Module.finrank ℚ K := by
classical
rw [← Embeddings.card K ℂ, Fintype.card, Finset.card_eq_sum_ones, ← Finset.univ.sum_fiberwise
(fun φ => InfinitePlace.mk φ)]
exact Finset.sum_congr rfl
(fun _ _ => by rw [Finset.sum_const, smul_eq_mul, mul_one, card_filter_mk_eq])
/-- The map from real embeddings to real infinite places as an equiv -/
noncomputable def mkReal :
{ φ : K →+* ℂ // ComplexEmbedding.IsReal φ } ≃ { w : InfinitePlace K // IsReal w } := by
refine (Equiv.ofBijective (fun φ => ⟨mk φ, ?_⟩) ⟨fun φ ψ h => ?_, fun w => ?_⟩)
· exact ⟨φ, φ.prop, rfl⟩
· rwa [Subtype.mk.injEq, mk_eq_iff, ComplexEmbedding.isReal_iff.mp φ.prop, or_self,
← Subtype.ext_iff] at h
· exact ⟨⟨embedding w, isReal_iff.mp w.prop⟩, by simp⟩
/-- The map from nonreal embeddings to complex infinite places -/
noncomputable def mkComplex :
{ φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } → { w : InfinitePlace K // IsComplex w } :=
Subtype.map mk fun φ hφ => ⟨φ, hφ, rfl⟩
@[simp]
theorem mkReal_coe (φ : { φ : K →+* ℂ // ComplexEmbedding.IsReal φ }) :
(mkReal φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl
@[simp]
theorem mkComplex_coe (φ : { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ }) :
(mkComplex φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl
section NumberField
variable [NumberField K]
/-- The infinite part of the product formula : for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where
`‖·‖_w` is the normalized absolute value for `w`. -/
theorem prod_eq_abs_norm (x : K) :
∏ w : InfinitePlace K, w x ^ mult w = abs (Algebra.norm ℚ x) := by
classical
convert (congr_arg (‖·‖) (@Algebra.norm_eq_prod_embeddings ℚ _ _ _ _ ℂ _ _ _ _ _ x)).symm
· rw [norm_prod, ← Fintype.prod_equiv RingHom.equivRatAlgHom (fun f => ‖f x‖)
(fun φ => ‖φ x‖) fun _ => by simp [RingHom.equivRatAlgHom_apply]]
rw [← Finset.prod_fiberwise Finset.univ mk (fun φ => ‖φ x‖)]
have (w : InfinitePlace K) (φ) (hφ : φ ∈ ({φ | mk φ = w} : Finset _)) :
‖φ x‖ = w x := by rw [← (Finset.mem_filter.mp hφ).2, apply]
simp_rw [Finset.prod_congr rfl (this _), Finset.prod_const, card_filter_mk_eq]
· rw [eq_ratCast, Rat.cast_abs, ← Real.norm_eq_abs, ← Complex.norm_real, Complex.ofReal_ratCast]
theorem one_le_of_lt_one {w : InfinitePlace K} {a : (𝓞 K)} (ha : a ≠ 0)
(h : ∀ ⦃z⦄, z ≠ w → z a < 1) : 1 ≤ w a := by
suffices (1 : ℝ) ≤ |Algebra.norm ℚ (a : K)| by
contrapose! this
rw [← InfinitePlace.prod_eq_abs_norm, ← Finset.prod_const_one]
refine Finset.prod_lt_prod_of_nonempty (fun _ _ ↦ ?_) (fun z _ ↦ ?_) Finset.univ_nonempty
· exact pow_pos (pos_iff.mpr ((Subalgebra.coe_eq_zero _).not.mpr ha)) _
· refine pow_lt_one₀ (apply_nonneg _ _) ?_ (by rw [mult]; split_ifs <;> norm_num)
by_cases hz : z = w
· rwa [hz]
· exact h hz
rw [← Algebra.coe_norm_int, ← Int.cast_one, ← Int.cast_abs, Rat.cast_intCast, Int.cast_le]
exact Int.one_le_abs (Algebra.norm_ne_zero_iff.mpr ha)
open scoped IntermediateField in
theorem _root_.NumberField.is_primitive_element_of_infinitePlace_lt {x : 𝓞 K}
{w : InfinitePlace K} (h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1)
(h₃ : IsReal w ∨ |(w.embedding x).re| < 1) : ℚ⟮(x : K)⟯ = ⊤ := by
rw [Field.primitive_element_iff_algHom_eq_of_eval ℚ ℂ ?_ _ w.embedding.toRatAlgHom]
· intro ψ hψ
have h : 1 ≤ w x := one_le_of_lt_one h₁ h₂
have main : w = InfinitePlace.mk ψ.toRingHom := by
simp at hψ
rw [← norm_embedding_eq, hψ] at h
contrapose! h
exact h₂ h.symm
rw [(mk_embedding w).symm, mk_eq_iff] at main
cases h₃ with
| inl hw =>
rw [conjugate_embedding_eq_of_isReal hw, or_self] at main
exact congr_arg RingHom.toRatAlgHom main
| inr hw =>
refine congr_arg RingHom.toRatAlgHom (main.resolve_right fun h' ↦ hw.not_le ?_)
have : (embedding w x).im = 0 := by
rw [← Complex.conj_eq_iff_im]
have := RingHom.congr_fun h' x
simp at this
rw [this]
exact hψ.symm
rwa [← norm_embedding_eq, ← Complex.re_add_im (embedding w x), this, Complex.ofReal_zero,
zero_mul, add_zero, Complex.norm_real] at h
· exact fun x ↦ IsAlgClosed.splits_codomain (minpoly ℚ x)
theorem _root_.NumberField.adjoin_eq_top_of_infinitePlace_lt {x : 𝓞 K} {w : InfinitePlace K}
(h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1) (h₃ : IsReal w ∨ |(w.embedding x).re| < 1) :
Algebra.adjoin ℚ {(x : K)} = ⊤ := by
rw [← IntermediateField.adjoin_simple_toSubalgebra_of_integral (IsIntegral.of_finite ℚ _)]
exact congr_arg IntermediateField.toSubalgebra <|
NumberField.is_primitive_element_of_infinitePlace_lt h₁ h₂ h₃
end NumberField
open Fintype Module
variable (K)
section NumberField
variable [NumberField K]
open scoped Classical in
/-- The number of infinite real places of the number field `K`. -/
noncomputable abbrev nrRealPlaces := card { w : InfinitePlace K // IsReal w }
@[deprecated (since := "2024-10-24")] alias NrRealPlaces := nrRealPlaces
open scoped Classical in
/-- The number of infinite complex places of the number field `K`. -/
noncomputable abbrev nrComplexPlaces := card { w : InfinitePlace K // IsComplex w }
@[deprecated (since := "2024-10-24")] alias NrComplexPlaces := nrComplexPlaces
open scoped Classical in
theorem card_real_embeddings :
card { φ : K →+* ℂ // ComplexEmbedding.IsReal φ } = nrRealPlaces K := Fintype.card_congr mkReal
theorem card_eq_nrRealPlaces_add_nrComplexPlaces :
Fintype.card (InfinitePlace K) = nrRealPlaces K + nrComplexPlaces K := by
classical
convert Fintype.card_subtype_or_disjoint (IsReal (K := K)) (IsComplex (K := K))
(disjoint_isReal_isComplex K) using 1
exact (Fintype.card_of_subtype _ (fun w ↦ ⟨fun _ ↦ isReal_or_isComplex w, fun _ ↦ by simp⟩)).symm
open scoped Classical in
theorem card_complex_embeddings :
card { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } = 2 * nrComplexPlaces K := by
suffices ∀ w : { w : InfinitePlace K // IsComplex w },
#{φ : {φ //¬ ComplexEmbedding.IsReal φ} | mkComplex φ = w} = 2 by
rw [Fintype.card, Finset.card_eq_sum_ones, ← Finset.sum_fiberwise _ (fun φ => mkComplex φ)]
simp_rw [Finset.sum_const, this, smul_eq_mul, mul_one, Fintype.card, Finset.card_eq_sum_ones,
Finset.mul_sum, Finset.sum_const, smul_eq_mul, mul_one]
rintro ⟨w, hw⟩
convert card_filter_mk_eq w
· rw [← Fintype.card_subtype, ← Fintype.card_subtype]
refine Fintype.card_congr (Equiv.ofBijective ?_ ⟨fun _ _ h => ?_, fun ⟨φ, hφ⟩ => ?_⟩)
· exact fun ⟨φ, hφ⟩ => ⟨φ.val, by rwa [Subtype.ext_iff] at hφ⟩
· rwa [Subtype.mk_eq_mk, ← Subtype.ext_iff, ← Subtype.ext_iff] at h
· refine ⟨⟨⟨φ, not_isReal_of_mk_isComplex (hφ.symm ▸ hw)⟩, ?_⟩, rfl⟩
rwa [Subtype.ext_iff, mkComplex_coe]
· simp_rw [mult, not_isReal_iff_isComplex.mpr hw, ite_false]
theorem card_add_two_mul_card_eq_rank :
nrRealPlaces K + 2 * nrComplexPlaces K = finrank ℚ K := by
classical
rw [← card_real_embeddings, ← card_complex_embeddings, Fintype.card_subtype_compl,
← Embeddings.card K ℂ, Nat.add_sub_of_le]
exact Fintype.card_subtype_le _
variable {K}
theorem nrComplexPlaces_eq_zero_of_finrank_eq_one (h : finrank ℚ K = 1) :
nrComplexPlaces K = 0 := by linarith [card_add_two_mul_card_eq_rank K]
theorem nrRealPlaces_eq_one_of_finrank_eq_one (h : finrank ℚ K = 1) :
nrRealPlaces K = 1 := by
have := card_add_two_mul_card_eq_rank K
rwa [nrComplexPlaces_eq_zero_of_finrank_eq_one h, h, mul_zero, add_zero] at this
theorem nrRealPlaces_pos_of_odd_finrank (h : Odd (finrank ℚ K)) :
0 < nrRealPlaces K := by
refine Nat.pos_of_ne_zero ?_
by_contra hc
refine (Nat.not_odd_iff_even.mpr ?_) h
rw [← card_add_two_mul_card_eq_rank, hc, zero_add]
exact even_two_mul (nrComplexPlaces K)
/-- The restriction of an infinite place along an embedding. -/
def comap (w : InfinitePlace K) (f : k →+* K) : InfinitePlace k :=
⟨w.1.comp f.injective, w.embedding.comp f,
by { ext x; show _ = w.1 (f x); rw [← w.2.choose_spec]; rfl }⟩
end NumberField
variable {K}
@[simp]
lemma comap_mk (φ : K →+* ℂ) (f : k →+* K) : (mk φ).comap f = mk (φ.comp f) := rfl
lemma comap_id (w : InfinitePlace K) : w.comap (RingHom.id K) = w := rfl
lemma comap_comp (w : InfinitePlace K) (f : F →+* K) (g : k →+* F) :
w.comap (f.comp g) = (w.comap f).comap g := rfl
lemma comap_mk_lift [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) :
(mk (ComplexEmbedding.lift K φ)).comap (algebraMap k K) = mk φ := by simp
lemma IsReal.comap (f : k →+* K) {w : InfinitePlace K} (hφ : IsReal w) :
IsReal (w.comap f) := by
rw [← mk_embedding w, comap_mk, isReal_mk_iff]
rw [← mk_embedding w, isReal_mk_iff] at hφ
exact hφ.comp f
lemma isReal_comap_iff (f : k ≃+* K) {w : InfinitePlace K} :
IsReal (w.comap (f : k →+* K)) ↔ IsReal w := by
rw [← mk_embedding w, comap_mk, isReal_mk_iff, isReal_mk_iff, ComplexEmbedding.isReal_comp_iff]
lemma comap_surjective [Algebra k K] [Algebra.IsAlgebraic k K] :
Function.Surjective (comap · (algebraMap k K)) := fun w ↦
⟨(mk (ComplexEmbedding.lift K w.embedding)), by simp⟩
lemma mult_comap_le (f : k →+* K) (w : InfinitePlace K) : mult (w.comap f) ≤ mult w := by
rw [mult, mult]
split_ifs with h₁ h₂ h₂
pick_goal 3
· exact (h₁ (h₂.comap _)).elim
all_goals decide
variable [Algebra k K] (σ : K ≃ₐ[k] K) (w : InfinitePlace K)
variable (k K)
lemma card_mono [NumberField k] [NumberField K] :
card (InfinitePlace k) ≤ card (InfinitePlace K) :=
have := Module.Finite.of_restrictScalars_finite ℚ k K
Fintype.card_le_of_surjective _ comap_surjective
variable {k K}
/-- The action of the galois group on infinite places. -/
@[simps! smul_coe_apply]
instance : MulAction (K ≃ₐ[k] K) (InfinitePlace K) where
smul := fun σ w ↦ w.comap σ.symm
one_smul := fun _ ↦ rfl
mul_smul := fun _ _ _ ↦ rfl
lemma smul_eq_comap : σ • w = w.comap σ.symm := rfl
@[simp] lemma smul_apply (x) : (σ • w) x = w (σ.symm x) := rfl
@[simp] lemma smul_mk (φ : K →+* ℂ) : σ • mk φ = mk (φ.comp σ.symm) := rfl
lemma comap_smul {f : F →+* K} : (σ • w).comap f = w.comap (RingHom.comp σ.symm f) := rfl
variable {σ w}
lemma isReal_smul_iff : IsReal (σ • w) ↔ IsReal w := isReal_comap_iff (f := σ.symm.toRingEquiv)
lemma isComplex_smul_iff : IsComplex (σ • w) ↔ IsComplex w := by
rw [← not_isReal_iff_isComplex, ← not_isReal_iff_isComplex, isReal_smul_iff]
lemma ComplexEmbedding.exists_comp_symm_eq_of_comp_eq [IsGalois k K] (φ ψ : K →+* ℂ)
(h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) :
∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by
letI := (φ.comp (algebraMap k K)).toAlgebra
letI := φ.toAlgebra
have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl
let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm }
use (AlgHom.restrictNormal' ψ' K).symm
ext1 x
exact AlgHom.restrictNormal_commutes ψ' K x
lemma exists_smul_eq_of_comap_eq [IsGalois k K] {w w' : InfinitePlace K}
(h : w.comap (algebraMap k K) = w'.comap (algebraMap k K)) : ∃ σ : K ≃ₐ[k] K, σ • w = w' := by
rw [← mk_embedding w, ← mk_embedding w', comap_mk, comap_mk, mk_eq_iff] at h
cases h with
| inl h =>
obtain ⟨σ, hσ⟩ := ComplexEmbedding.exists_comp_symm_eq_of_comp_eq w.embedding w'.embedding h
use σ
rw [← mk_embedding w, ← mk_embedding w', smul_mk, hσ]
| inr h =>
obtain ⟨σ, hσ⟩ := ComplexEmbedding.exists_comp_symm_eq_of_comp_eq
((starRingEnd ℂ).comp (embedding w)) w'.embedding h
use σ
rw [← mk_embedding w, ← mk_embedding w', smul_mk, mk_eq_iff]
exact Or.inr hσ
lemma mem_orbit_iff [IsGalois k K] {w w' : InfinitePlace K} :
w' ∈ MulAction.orbit (K ≃ₐ[k] K) w ↔ w.comap (algebraMap k K) = w'.comap (algebraMap k K) := by
refine ⟨?_, exists_smul_eq_of_comap_eq⟩
rintro ⟨σ, rfl : σ • w = w'⟩
rw [← mk_embedding w, comap_mk, smul_mk, comap_mk]
congr 1; ext1; simp
/-- The orbits of infinite places under the action of the galois group are indexed by
the infinite places of the base field. -/
noncomputable
def orbitRelEquiv [IsGalois k K] :
Quotient (MulAction.orbitRel (K ≃ₐ[k] K) (InfinitePlace K)) ≃ InfinitePlace k := by
refine Equiv.ofBijective (Quotient.lift (comap · (algebraMap k K))
fun _ _ e ↦ (mem_orbit_iff.mp e).symm) ⟨?_, ?_⟩
· rintro ⟨w⟩ ⟨w'⟩ e
exact Quotient.sound (mem_orbit_iff.mpr e.symm)
· intro w
obtain ⟨w', hw⟩ := comap_surjective (K := K) w
exact ⟨⟦w'⟧, hw⟩
lemma orbitRelEquiv_apply_mk'' [IsGalois k K] (w : InfinitePlace K) :
orbitRelEquiv (Quotient.mk'' w) = comap w (algebraMap k K) := rfl
variable (k w)
/--
An infinite place is unramified in a field extension if the restriction has the same multiplicity.
-/
def IsUnramified : Prop := mult (w.comap (algebraMap k K)) = mult w
variable {k}
lemma isUnramified_self : IsUnramified K w := rfl
variable {w}
lemma IsUnramified.eq (h : IsUnramified k w) : mult (w.comap (algebraMap k K)) = mult w := h
lemma isUnramified_iff_mult_le :
IsUnramified k w ↔ mult w ≤ mult (w.comap (algebraMap k K)) := by
rw [IsUnramified, le_antisymm_iff, and_iff_right]
exact mult_comap_le _ _
variable [Algebra k F]
lemma IsUnramified.comap_algHom {w : InfinitePlace F} (h : IsUnramified k w) (f : K →ₐ[k] F) :
IsUnramified k (w.comap (f : K →+* F)) := by
rw [InfinitePlace.isUnramified_iff_mult_le, ← InfinitePlace.comap_comp, f.comp_algebraMap, h.eq]
exact InfinitePlace.mult_comap_le _ _
variable (K)
variable [Algebra K F] [IsScalarTower k K F]
lemma IsUnramified.of_restrictScalars {w : InfinitePlace F} (h : IsUnramified k w) :
IsUnramified K w := by
rw [InfinitePlace.isUnramified_iff_mult_le, ← h.eq, IsScalarTower.algebraMap_eq k K F,
InfinitePlace.comap_comp]
exact InfinitePlace.mult_comap_le _ _
lemma IsUnramified.comap {w : InfinitePlace F} (h : IsUnramified k w) :
IsUnramified k (w.comap (algebraMap K F)) :=
h.comap_algHom (IsScalarTower.toAlgHom k K F)
variable {K}
lemma not_isUnramified_iff :
¬ IsUnramified k w ↔ IsComplex w ∧ IsReal (w.comap (algebraMap k K)) := by
rw [IsUnramified, mult, mult, ← not_isReal_iff_isComplex]
split_ifs with h₁ h₂ h₂ <;>
simp only [not_true_eq_false, false_iff, and_self, forall_true_left, IsEmpty.forall_iff,
not_and, OfNat.one_ne_ofNat, not_false_eq_true, true_iff, OfNat.ofNat_ne_one, h₁, h₂]
exact h₁ (h₂.comap _)
lemma isUnramified_iff :
IsUnramified k w ↔ IsReal w ∨ IsComplex (w.comap (algebraMap k K)) := by
rw [← not_iff_not, not_isUnramified_iff, not_or,
not_isReal_iff_isComplex, not_isComplex_iff_isReal]
variable (k)
lemma IsReal.isUnramified (h : IsReal w) : IsUnramified k w := isUnramified_iff.mpr (Or.inl h)
variable {k}
lemma _root_.NumberField.ComplexEmbedding.IsConj.isUnramified_mk_iff
{φ : K →+* ℂ} (h : ComplexEmbedding.IsConj φ σ) :
IsUnramified k (mk φ) ↔ σ = 1 := by
rw [h.ext_iff, ComplexEmbedding.isConj_one_iff, ← not_iff_not, not_isUnramified_iff,
← not_isReal_iff_isComplex, comap_mk, isReal_mk_iff, isReal_mk_iff, eq_true h.isReal_comp,
and_true]
lemma isUnramified_mk_iff_forall_isConj [IsGalois k K] {φ : K →+* ℂ} :
IsUnramified k (mk φ) ↔ ∀ σ : K ≃ₐ[k] K, ComplexEmbedding.IsConj φ σ → σ = 1 := by
refine ⟨fun H σ hσ ↦ hσ.isUnramified_mk_iff.mp H,
fun H ↦ ?_⟩
by_contra hφ
rw [not_isUnramified_iff] at hφ
rw [comap_mk, isReal_mk_iff, ← not_isReal_iff_isComplex, isReal_mk_iff,
← ComplexEmbedding.isConj_one_iff (k := k)] at hφ
letI := (φ.comp (algebraMap k K)).toAlgebra
letI := φ.toAlgebra
have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl
let φ' : K →ₐ[k] ℂ := { star φ with commutes' := fun r ↦ by simpa using RingHom.congr_fun hφ.2 r }
have : ComplexEmbedding.IsConj φ (AlgHom.restrictNormal' φ' K) :=
(RingHom.ext <| AlgHom.restrictNormal_commutes φ' K).symm
exact hφ.1 (H _ this ▸ this)
local notation "Stab" => MulAction.stabilizer (K ≃ₐ[k] K)
lemma mem_stabilizer_mk_iff (φ : K →+* ℂ) (σ : K ≃ₐ[k] K) :
σ ∈ Stab (mk φ) ↔ σ = 1 ∨ ComplexEmbedding.IsConj φ σ := by
simp only [MulAction.mem_stabilizer_iff, smul_mk, mk_eq_iff]
rw [← ComplexEmbedding.isConj_symm, ComplexEmbedding.conjugate, star_eq_iff_star_eq]
refine or_congr ⟨fun H ↦ ?_, fun H ↦ H ▸ rfl⟩ Iff.rfl
exact congr_arg AlgEquiv.symm
(AlgEquiv.ext (g := AlgEquiv.refl) fun x ↦ φ.injective (RingHom.congr_fun H x))
lemma IsUnramified.stabilizer_eq_bot (h : IsUnramified k w) : Stab w = ⊥ := by
rw [eq_bot_iff, ← mk_embedding w, SetLike.le_def]
simp only [mem_stabilizer_mk_iff, Subgroup.mem_bot, forall_eq_or_imp, true_and]
exact fun σ hσ ↦ hσ.isUnramified_mk_iff.mp ((mk_embedding w).symm ▸ h)
lemma _root_.NumberField.ComplexEmbedding.IsConj.coe_stabilzer_mk
{φ : K →+* ℂ} (h : ComplexEmbedding.IsConj φ σ) :
(Stab (mk φ) : Set (K ≃ₐ[k] K)) = {1, σ} := by
ext
rw [SetLike.mem_coe, mem_stabilizer_mk_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
← h.ext_iff, eq_comm (a := σ)]
variable (k w)
lemma nat_card_stabilizer_eq_one_or_two :
Nat.card (Stab w) = 1 ∨ Nat.card (Stab w) = 2 := by
classical
rw [← SetLike.coe_sort_coe, ← mk_embedding w]
by_cases h : ∃ σ, ComplexEmbedding.IsConj (k := k) (embedding w) σ
· obtain ⟨σ, hσ⟩ := h
simp only [hσ.coe_stabilzer_mk, Nat.card_eq_fintype_card, card_ofFinset, Set.toFinset_singleton]
by_cases 1 = σ
· left; simp [*]
· right; simp [*]
· push_neg at h
| left
trans Nat.card ({1} : Set (K ≃ₐ[k] K))
· congr with x
simp only [SetLike.mem_coe, mem_stabilizer_mk_iff, Set.mem_singleton_iff, or_iff_left_iff_imp,
h x, IsEmpty.forall_iff]
| Mathlib/NumberTheory/NumberField/Embeddings.lean | 915 | 919 |
/-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Small.Module
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.Isomorphisms
import Mathlib.LinearAlgebra.TensorProduct.RightExactness
import Mathlib.RingTheory.Finiteness.Projective
import Mathlib.RingTheory.Localization.BaseChange
import Mathlib.RingTheory.Noetherian.Basic
import Mathlib.RingTheory.TensorProduct.Finite
/-!
# Finitely Presented Modules
## Main definition
- `Module.FinitePresentation`: A module is finitely presented if it is generated by some
finite set `s` and the kernel of the presentation `Rˢ → M` is also finitely generated.
## Main results
- `Module.finitePresentation_iff_finite`: If `R` is noetherian, then f.p. iff f.g. on `R`-modules.
Suppose `0 → K → M → N → 0` is an exact sequence of `R`-modules.
- `Module.finitePresentation_of_surjective`: If `M` is f.p., `K` is f.g., then `N` is f.p.
- `Module.FinitePresentation.fg_ker`: If `M` is f.g., `N` is f.p., then `K` is f.g.
- `Module.finitePresentation_of_ker`: If `N` and `K` is f.p., then `M` is also f.p.
- `Module.FinitePresentation.isLocalizedModule_map`: If `M` and `N` are `R`-modules and `M` is f.p.,
and `S` is a submonoid of `R`, then `Hom(Mₛ, Nₛ)` is the localization of `Hom(M, N)`.
Also the instances finite + free => f.p. => finite are also provided
## TODO
Suppose `S` is an `R`-algebra, `M` is an `S`-module. Then
1. If `S` is f.p., then `M` is `R`-f.p. implies `M` is `S`-f.p.
2. If `S` is both f.p. (as an algebra) and finite (as a module),
then `M` is `S`-fp implies that `M` is `R`-f.p.
3. If `S` is f.p. as a module, then `S` is f.p. as an algebra.
In particular,
4. `S` is f.p. as an `R`-module iff it is f.p. as an algebra and is finite as a module.
For finitely presented algebras, see `Algebra.FinitePresentation`
in file `Mathlib.RingTheory.FinitePresentation`.
-/
open Finsupp
section Semiring
variable (R M) [Semiring R] [AddCommMonoid M] [Module R M]
/--
A module is finitely presented if it is finitely generated by some set `s`
and the kernel of the presentation `Rˢ → M` is also finitely generated.
-/
class Module.FinitePresentation : Prop where
out : ∃ (s : Finset M), Submodule.span R (s : Set M) = ⊤ ∧
(LinearMap.ker (Finsupp.linearCombination R ((↑) : s → M))).FG
instance (priority := 100) [h : Module.FinitePresentation R M] : Module.Finite R M := by
obtain ⟨s, hs₁, _⟩ := h
exact ⟨s, hs₁⟩
end Semiring
section Ring
section
universe u v
variable (R : Type u) (M : Type*) [Ring R] [AddCommGroup M] [Module R M]
theorem Module.FinitePresentation.exists_fin [fp : Module.FinitePresentation R M] :
∃ (n : ℕ) (K : Submodule R (Fin n → R)) (_ : M ≃ₗ[R] (Fin n → R) ⧸ K), K.FG := by
have ⟨ι, ⟨hι₁, hι₂⟩⟩ := fp
refine ⟨_, LinearMap.ker (linearCombination R Subtype.val ∘ₗ
(lcongr ι.equivFin (.refl ..) ≪≫ₗ linearEquivFunOnFinite R R _).symm.toLinearMap),
(LinearMap.quotKerEquivOfSurjective _ <| LinearMap.range_eq_top.mp ?_).symm, ?_⟩
· simpa [range_linearCombination] using hι₁
· simpa [LinearMap.ker_comp, Submodule.comap_equiv_eq_map_symm] using hι₂.map _
/-- A finitely presented module is isomorphic to the quotient of a finite free module by a finitely
generated submodule. -/
theorem Module.FinitePresentation.equiv_quotient [Module.FinitePresentation R M] [Small.{v} R] :
∃ (L : Type v) (_ : AddCommGroup L) (_ : Module R L) (K : Submodule R L)
(_ : M ≃ₗ[R] L ⧸ K), Module.Free R L ∧ Module.Finite R L ∧ K.FG :=
have ⟨_n, _K, e, fg⟩ := Module.FinitePresentation.exists_fin R M
let es := linearEquivShrink
⟨_, inferInstance, inferInstance, _, e ≪≫ₗ Submodule.Quotient.equiv _ _ (es ..) rfl,
.of_equiv (es ..), .equiv (es ..), fg.map (es ..).toLinearMap⟩
end
variable (R M N) [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
-- Ideally this should be an instance but it makes mathlib much slower.
lemma Module.finitePresentation_of_finite [IsNoetherianRing R] [h : Module.Finite R M] :
Module.FinitePresentation R M := by
obtain ⟨s, hs⟩ := h
exact ⟨s, hs, IsNoetherian.noetherian _⟩
lemma Module.finitePresentation_iff_finite [IsNoetherianRing R] :
Module.FinitePresentation R M ↔ Module.Finite R M :=
⟨fun _ ↦ inferInstance, fun _ ↦ finitePresentation_of_finite R M⟩
variable {R M N}
lemma Module.finitePresentation_of_free_of_surjective [Module.Free R M] [Module.Finite R M]
(l : M →ₗ[R] N)
(hl : Function.Surjective l) (hl' : (LinearMap.ker l).FG) :
Module.FinitePresentation R N := by
classical
let b := Module.Free.chooseBasis R M
let π : Free.ChooseBasisIndex R M → (Set.finite_range (l ∘ b)).toFinset :=
fun i ↦ ⟨l (b i), by simp⟩
have : π.Surjective := fun ⟨x, hx⟩ ↦ by
obtain ⟨y, rfl⟩ : ∃ a, l (b a) = x := by simpa using hx
exact ⟨y, rfl⟩
choose σ hσ using this
have hπ : Subtype.val ∘ π = l ∘ b := rfl
have hσ₁ : π ∘ σ = id := by ext i; exact congr_arg Subtype.val (hσ i)
have hσ₂ : l ∘ b ∘ σ = Subtype.val := by ext i; exact congr_arg Subtype.val (hσ i)
refine ⟨(Set.finite_range (l ∘ b)).toFinset,
by simpa [Set.range_comp, LinearMap.range_eq_top], ?_⟩
let f : M →ₗ[R] (Set.finite_range (l ∘ b)).toFinset →₀ R :=
Finsupp.lmapDomain _ _ π ∘ₗ b.repr.toLinearMap
convert hl'.map f
ext x; simp only [LinearMap.mem_ker, Submodule.mem_map]
constructor
· intro hx
refine ⟨b.repr.symm (x.mapDomain σ), ?_, ?_⟩
· simp [Finsupp.apply_linearCombination, hσ₂, hx]
· simp only [f, LinearMap.comp_apply, b.repr.apply_symm_apply,
LinearEquiv.coe_toLinearMap, Finsupp.lmapDomain_apply]
rw [← Finsupp.mapDomain_comp, hσ₁, Finsupp.mapDomain_id]
· rintro ⟨y, hy, rfl⟩
simp [f, hπ, ← Finsupp.apply_linearCombination, hy]
-- Ideally this should be an instance but it makes mathlib much slower.
variable (R M) in
lemma Module.finitePresentation_of_projective [Projective R M] [Module.Finite R M] :
FinitePresentation R M :=
have ⟨_n, _f, _g, surj, _, hfg⟩ := Finite.exists_comp_eq_id_of_projective R M
Module.finitePresentation_of_free_of_surjective _ surj
(Finite.iff_fg.mp <| LinearMap.ker_eq_range_of_comp_eq_id hfg ▸ inferInstance)
@[deprecated (since := "2024-11-06")]
alias Module.finitePresentation_of_free := Module.finitePresentation_of_projective
variable {ι} [Finite ι]
instance : Module.FinitePresentation R R := Module.finitePresentation_of_projective _ _
instance : Module.FinitePresentation R (ι →₀ R) := Module.finitePresentation_of_projective _ _
instance : Module.FinitePresentation R (ι → R) := Module.finitePresentation_of_projective _ _
lemma Module.finitePresentation_of_surjective [h : Module.FinitePresentation R M] (l : M →ₗ[R] N)
(hl : Function.Surjective l) (hl' : (LinearMap.ker l).FG) :
Module.FinitePresentation R N := by
classical
obtain ⟨s, hs, hs'⟩ := h
obtain ⟨t, ht⟩ := hl'
have H : Function.Surjective (Finsupp.linearCombination R ((↑) : s → M)) :=
LinearMap.range_eq_top.mp
(by rw [range_linearCombination, Subtype.range_val, ← hs]; rfl)
apply Module.finitePresentation_of_free_of_surjective (l ∘ₗ linearCombination R Subtype.val)
(hl.comp H)
choose σ hσ using (show _ from H)
have : Finsupp.linearCombination R Subtype.val '' (σ '' t) = t := by
simp only [Set.image_image, hσ, Set.image_id']
rw [LinearMap.ker_comp, ← ht, ← this, ← Submodule.map_span, Submodule.comap_map_eq,
← Finset.coe_image]
exact Submodule.FG.sup ⟨_, rfl⟩ hs'
lemma Module.FinitePresentation.fg_ker [Module.Finite R M]
[h : Module.FinitePresentation R N] (l : M →ₗ[R] N) (hl : Function.Surjective l) :
(LinearMap.ker l).FG := by
classical
obtain ⟨s, hs, hs'⟩ := h
have H : Function.Surjective (Finsupp.linearCombination R ((↑) : s → N)) :=
LinearMap.range_eq_top.mp
(by rw [range_linearCombination, Subtype.range_val, ← hs]; rfl)
obtain ⟨f, hf⟩ : ∃ f : (s →₀ R) →ₗ[R] M, l ∘ₗ f = (Finsupp.linearCombination R Subtype.val) := by
choose f hf using show _ from hl
exact ⟨Finsupp.linearCombination R (fun i ↦ f i), by ext; simp [hf]⟩
have : (LinearMap.ker l).map (LinearMap.range f).mkQ = ⊤ := by
rw [← top_le_iff]
rintro x -
obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x
obtain ⟨y, hy⟩ := H (l x)
rw [← hf, LinearMap.comp_apply, eq_comm, ← sub_eq_zero, ← map_sub] at hy
exact ⟨_, hy, by simp⟩
apply Submodule.fg_of_fg_map_of_fg_inf_ker (LinearMap.range f).mkQ
· rw [this]
exact Module.Finite.fg_top
· rw [Submodule.ker_mkQ, inf_comm, ← Submodule.map_comap_eq, ← LinearMap.ker_comp, hf]
exact hs'.map f
lemma Module.FinitePresentation.fg_ker_iff [Module.FinitePresentation R M]
(l : M →ₗ[R] N) (hl : Function.Surjective l) :
Submodule.FG (LinearMap.ker l) ↔ Module.FinitePresentation R N :=
⟨finitePresentation_of_surjective l hl, fun _ ↦ fg_ker l hl⟩
lemma Module.finitePresentation_of_ker [Module.FinitePresentation R N]
(l : M →ₗ[R] N) (hl : Function.Surjective l) [Module.FinitePresentation R (LinearMap.ker l)] :
Module.FinitePresentation R M := by
obtain ⟨s, hs⟩ : (⊤ : Submodule R M).FG := by
apply Submodule.fg_of_fg_map_of_fg_inf_ker l
· rw [Submodule.map_top, LinearMap.range_eq_top.mpr hl]; exact Module.Finite.fg_top
· rw [top_inf_eq, ← Submodule.fg_top]; exact Module.Finite.fg_top
refine ⟨s, hs, ?_⟩
let π := Finsupp.linearCombination R ((↑) : s → M)
have H : Function.Surjective π :=
LinearMap.range_eq_top.mp
(by rw [range_linearCombination, Subtype.range_val, ← hs]; rfl)
have inst : Module.Finite R (LinearMap.ker (l ∘ₗ π)) := by
constructor
| rw [Submodule.fg_top]; exact Module.FinitePresentation.fg_ker _ (hl.comp H)
letI : AddCommGroup (LinearMap.ker (l ∘ₗ π)) := inferInstance
let f : LinearMap.ker (l ∘ₗ π) →ₗ[R] LinearMap.ker l := LinearMap.restrict π (fun x ↦ id)
have e : π ∘ₗ Submodule.subtype _ = Submodule.subtype _ ∘ₗ f := by ext; rfl
have hf : Function.Surjective f := by
rw [← LinearMap.range_eq_top]
apply Submodule.map_injective_of_injective (Submodule.injective_subtype _)
rw [Submodule.map_top, Submodule.range_subtype, ← LinearMap.range_comp, ← e,
LinearMap.range_comp, Submodule.range_subtype, LinearMap.ker_comp,
Submodule.map_comap_eq_of_surjective H]
show (LinearMap.ker π).FG
have : LinearMap.ker π ≤ LinearMap.ker (l ∘ₗ π) :=
Submodule.comap_mono (f := π) (bot_le (a := LinearMap.ker l))
rw [← inf_eq_right.mpr this, ← Submodule.range_subtype (LinearMap.ker _),
← Submodule.map_comap_eq, ← LinearMap.ker_comp, e, LinearMap.ker_comp f,
LinearMap.ker_eq_bot.mpr (Submodule.injective_subtype (LinearMap.ker l)), Submodule.comap_bot]
exact (Module.FinitePresentation.fg_ker f hf).map (Submodule.subtype _)
/-- Given a split exact sequence `0 → M → N → P → 0` with `N` finitely presented,
then `M` is also finitely presented. -/
lemma Module.finitePresentation_of_split_exact
{P : Type*} [AddCommGroup P] [Module R P]
[Module.FinitePresentation R N]
(f : M →ₗ[R] N) (g : N →ₗ[R] P) (l : P →ₗ[R] N) (hl : g ∘ₗ l = .id)
(hf : Function.Injective f) (H : Function.Exact f g) :
Module.FinitePresentation R M := by
have hg : Function.Surjective g := Function.LeftInverse.surjective (DFunLike.congr_fun hl)
have := Module.Finite.of_surjective g hg
obtain ⟨e, rfl, rfl⟩ := ((Function.Exact.split_tfae' H).out 0 2 rfl rfl).mp
⟨hf, l, hl⟩
refine Module.finitePresentation_of_surjective (LinearMap.fst _ _ _ ∘ₗ e.toLinearMap)
(Prod.fst_surjective.comp e.surjective) ?_
rw [LinearMap.ker_comp, Submodule.comap_equiv_eq_map_symm,
LinearMap.exact_iff.mp Function.Exact.inr_fst, ← Submodule.map_top]
exact .map _ (.map _ (Module.Finite.fg_top))
/-- Given an exact sequence `0 → M → N → P → 0`
with `N` finitely presented and `P` projective, then `M` is also finitely presented. -/
lemma Module.finitePresentation_of_projective_of_exact
{P : Type*} [AddCommGroup P] [Module R P]
[Module.FinitePresentation R N] [Module.Projective R P]
(f : M →ₗ[R] N) (g : N →ₗ[R] P)
(hf : Function.Injective f) (hg : Function.Surjective g) (H : Function.Exact f g) :
Module.FinitePresentation R M :=
have ⟨l, hl⟩ := Module.projective_lifting_property g .id hg
Module.finitePresentation_of_split_exact f g l hl hf H
lemma Module.FinitePresentation.of_equiv (e : M ≃ₗ[R] N) [Module.FinitePresentation R M] :
| Mathlib/Algebra/Module/FinitePresentation.lean | 226 | 273 |
/-
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.Units.Basic
import Mathlib.Algebra.Ring.Basic
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Rat.Defs
import Mathlib.Algebra.Group.Nat.Defs
/-!
# The rational numbers are a commutative ring
This file contains the commutative ring instance on the rational numbers.
See note [foundational algebra order theory].
-/
assert_not_exists OrderedCommMonoid Field PNat Nat.gcd_greatest IsDomain.toCancelMonoidWithZero
namespace Rat
/-! ### Instances -/
instance commRing : CommRing ℚ where
__ := addCommGroup
__ := commMonoid
zero_mul := Rat.zero_mul
mul_zero := Rat.mul_zero
left_distrib := Rat.mul_add
right_distrib := Rat.add_mul
intCast := fun n => n
natCast n := Int.cast n
natCast_zero := rfl
natCast_succ n := by
simp only [intCast_eq_divInt, divInt_add_divInt _ _ Int.one_ne_zero Int.one_ne_zero,
← divInt_one_one, Int.natCast_add, Int.natCast_one, mul_one]
instance commGroupWithZero : CommGroupWithZero ℚ :=
{ exists_pair_ne := ⟨0, 1, Rat.zero_ne_one⟩
inv_zero := by
change Rat.inv 0 = 0
rw [Rat.inv_def]
rfl
mul_inv_cancel := Rat.mul_inv_cancel
mul_zero := mul_zero
zero_mul := zero_mul }
instance isDomain : IsDomain ℚ := NoZeroDivisors.to_isDomain _
/-- The characteristic of `ℚ` is 0. -/
@[stacks 09FS "Second part."]
instance instCharZero : CharZero ℚ where cast_injective a b hab := by simpa using congr_arg num hab
/-!
### Extra instances to short-circuit type class resolution
These also prevent non-computable instances being used to construct these instances non-computably.
-/
instance commSemiring : CommSemiring ℚ := by infer_instance
instance semiring : Semiring ℚ := by infer_instance
/-! ### Miscellaneous lemmas -/
lemma mkRat_eq_div (n : ℤ) (d : ℕ) : mkRat n d = n / d := by
simp only [mkRat_eq_divInt, divInt_eq_div, Int.cast_natCast]
lemma divInt_div_divInt_cancel_left {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
n /. x / (d /. x) = n /. d := by
rw [div_eq_mul_inv, inv_divInt', divInt_mul_divInt_cancel hx]
lemma divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) :
x /. n / (x /. d) = d /. n := by
rw [div_eq_mul_inv, inv_divInt', mul_comm, divInt_mul_divInt_cancel hx]
lemma num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by
rw [← Int.cast_natCast, ← divInt_eq_div, num_divInt_den]
@[simp] lemma divInt_pow (num : ℕ) (den : ℤ) (n : ℕ) : (num /. den) ^ n = num ^ n /. den ^ n := by
simp [divInt_eq_div, div_pow, Int.natCast_pow]
@[simp] lemma mkRat_pow (num den : ℕ) (n : ℕ) : mkRat num den ^ n = mkRat (num ^ n) (den ^ n) := by
rw [mkRat_eq_divInt, mkRat_eq_divInt, divInt_pow, Int.natCast_pow]
lemma natCast_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_natCast, intCast_eq_divInt]
@[simp] lemma mul_den_eq_num (q : ℚ) : q * q.den = q.num := by
suffices (q.num /. ↑q.den) * (↑q.den /. 1) = q.num /. 1 by
conv => pattern (occs := 1) q; (rw [← num_divInt_den q])
| simp only [intCast_eq_divInt, natCast_eq_divInt, num_divInt_den] at this ⊢; assumption
| Mathlib/Algebra/Ring/Rat.lean | 91 | 91 |
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Johan Commelin, Kim Morrison
-/
import Mathlib.CategoryTheory.Limits.Constructions.Pullbacks
import Mathlib.CategoryTheory.Preadditive.Biproducts
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels
import Mathlib.CategoryTheory.Limits.Shapes.Images
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
import Mathlib.CategoryTheory.Abelian.NonPreadditive
/-!
# Abelian categories
This file contains the definition and basic properties of abelian categories.
There are many definitions of abelian category. Our definition is as follows:
A category is called abelian if it is preadditive,
has a finite products, kernels and cokernels,
and if every monomorphism and epimorphism is normal.
It should be noted that if we also assume coproducts, then preadditivity is
actually a consequence of the other properties, as we show in
`NonPreadditiveAbelian.lean`. However, this fact is of little practical
relevance, since essentially all interesting abelian categories come with a
preadditive structure. In this way, by requiring preadditivity, we allow the
user to pass in the "native" preadditive structure for the specific category they are
working with.
## Main definitions
* `Abelian` is the type class indicating that a category is abelian. It extends `Preadditive`.
* `Abelian.image f` is `kernel (cokernel.π f)`, and
* `Abelian.coimage f` is `cokernel (kernel.ι f)`.
## Main results
* In an abelian category, mono + epi = iso.
* If `f : X ⟶ Y`, then the map `factorThruImage f : X ⟶ image f` is an epimorphism, and the map
`factorThruCoimage f : coimage f ⟶ Y` is a monomorphism.
* Factoring through the image and coimage is a strong epi-mono factorisation. This means that
* every abelian category has images. We provide the isomorphism
`imageIsoImage : abelian.image f ≅ limits.image f`.
* the canonical morphism `coimageImageComparison : coimage f ⟶ image f`
is an isomorphism.
* We provide the alternate characterisation of an abelian category as a category with
(co)kernels and finite products, and in which the canonical coimage-image comparison morphism
is always an isomorphism.
* Every epimorphism is a cokernel of its kernel. Every monomorphism is a kernel of its cokernel.
* The pullback of an epimorphism is an epimorphism. The pushout of a monomorphism is a monomorphism.
(This is not to be confused with the fact that the pullback of a monomorphism is a monomorphism,
which is true in any category).
## Implementation notes
The typeclass `Abelian` does not extend `NonPreadditiveAbelian`,
to avoid having to deal with comparing the two `HasZeroMorphisms` instances
(one from `Preadditive` in `Abelian`, and the other a field of `NonPreadditiveAbelian`).
As a consequence, at the beginning of this file we trivially build
a `NonPreadditiveAbelian` instance from an `Abelian` instance,
and use this to restate a number of theorems,
in each case just reusing the proof from `NonPreadditiveAbelian.lean`.
We don't show this yet, but abelian categories are finitely complete and finitely cocomplete.
However, the limits we can construct at this level of generality will most likely be less nice than
the ones that can be created in specific applications. For this reason, we adopt the following
convention:
* If the statement of a theorem involves limits, the existence of these limits should be made an
explicit typeclass parameter.
* If a limit only appears in a proof, but not in the statement of a theorem, the limit should not
be a typeclass parameter, but instead be created using `Abelian.hasPullbacks` or a similar
definition.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
* [P. Aluffi, *Algebra: Chapter 0*][aluffi2016]
-/
noncomputable section
open CategoryTheory
open CategoryTheory.Preadditive
open CategoryTheory.Limits
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
variable (C)
/-- A (preadditive) category `C` is called abelian if it has all finite products,
all kernels and cokernels, and if every monomorphism is the kernel of some morphism
and every epimorphism is the cokernel of some morphism.
(This definition implies the existence of zero objects:
finite products give a terminal object, and in a preadditive category
any terminal object is a zero object.)
-/
class Abelian extends Preadditive C, IsNormalMonoCategory C, IsNormalEpiCategory C where
[has_finite_products : HasFiniteProducts C]
[has_kernels : HasKernels C]
[has_cokernels : HasCokernels C]
attribute [instance 100] Abelian.has_finite_products
attribute [instance 90] Abelian.has_kernels Abelian.has_cokernels
end CategoryTheory
open CategoryTheory
/-!
We begin by providing an alternative constructor:
a preadditive category with kernels, cokernels, and finite products,
in which the coimage-image comparison morphism is always an isomorphism,
is an abelian category.
-/
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C] [Preadditive C]
variable [Limits.HasKernels C] [Limits.HasCokernels C]
namespace OfCoimageImageComparisonIsIso
/-- The factorisation of a morphism through its abelian image. -/
@[simps]
def imageMonoFactorisation {X Y : C} (f : X ⟶ Y) : MonoFactorisation f where
I := Abelian.image f
m := kernel.ι _
m_mono := inferInstance
e := kernel.lift _ f (cokernel.condition _)
fac := kernel.lift_ι _ _ _
theorem imageMonoFactorisation_e' {X Y : C} (f : X ⟶ Y) :
(imageMonoFactorisation f).e = cokernel.π _ ≫ Abelian.coimageImageComparison f := by
dsimp
ext
simp only [Abelian.coimageImageComparison, imageMonoFactorisation_e, Category.assoc,
cokernel.π_desc_assoc]
/-- If the coimage-image comparison morphism for a morphism `f` is an isomorphism,
we obtain an image factorisation of `f`. -/
def imageFactorisation {X Y : C} (f : X ⟶ Y) [IsIso (Abelian.coimageImageComparison f)] :
ImageFactorisation f where
F := imageMonoFactorisation f
isImage :=
{ lift := fun F => inv (Abelian.coimageImageComparison f) ≫ cokernel.desc _ F.e F.kernel_ι_comp
lift_fac := fun F => by
rw [imageMonoFactorisation_m]
simp only [Category.assoc]
rw [IsIso.inv_comp_eq]
ext
simp }
instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Mono f]
[IsIso (Abelian.coimageImageComparison f)] : IsIso (imageMonoFactorisation f).e := by
rw [imageMonoFactorisation_e']
exact IsIso.comp_isIso
instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Epi f] : IsIso (imageMonoFactorisation f).m := by
dsimp
infer_instance
variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)]
/-- A category in which coimage-image comparisons are all isomorphisms has images. -/
theorem hasImages : HasImages C :=
{ has_image := fun {_} {_} f => { exists_image := ⟨imageFactorisation f⟩ } }
variable [Limits.HasFiniteProducts C]
attribute [local instance] Limits.HasFiniteBiproducts.of_hasFiniteProducts
/-- A category with finite products in which coimage-image comparisons are all isomorphisms
is a normal mono category.
-/
lemma isNormalMonoCategory : IsNormalMonoCategory C where
normalMonoOfMono f m := ⟨{
Z := _
g := cokernel.π f
w := by simp
isLimit := by
haveI : Limits.HasImages C := hasImages
haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels
haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _
have aux : ∀ (s : KernelFork (cokernel.π f)), (limit.lift (parallelPair (cokernel.π f) 0) s
≫ inv (imageMonoFactorisation f).e) ≫ Fork.ι (KernelFork.ofι f (by simp))
= Fork.ι s := ?_
· refine isLimitAux _ (fun A => limit.lift _ _ ≫ inv (imageMonoFactorisation f).e) aux ?_
intro A g hg
rw [KernelFork.ι_ofι] at hg
rw [← cancel_mono f, hg, ← aux, KernelFork.ι_ofι]
· intro A
simp only [KernelFork.ι_ofι, Category.assoc]
convert limit.lift_π A WalkingParallelPair.zero using 2
rw [IsIso.inv_comp_eq, eq_comm]
exact (imageMonoFactorisation f).fac }⟩
/-- A category with finite products in which coimage-image comparisons are all isomorphisms
is a normal epi category.
-/
lemma isNormalEpiCategory : IsNormalEpiCategory C where
normalEpiOfEpi f m := ⟨{
W := kernel f
g := kernel.ι _
w := kernel.condition _
isColimit := by
haveI : Limits.HasImages C := hasImages
haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels
haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _
have aux : ∀ (s : CokernelCofork (kernel.ι f)), Cofork.π (CokernelCofork.ofπ f (by simp)) ≫
inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫
colimit.desc (parallelPair (kernel.ι f) 0) s = Cofork.π s := ?_
· refine isColimitAux _ (fun A => inv (imageMonoFactorisation f).m ≫
inv (Abelian.coimageImageComparison f) ≫ colimit.desc _ _) aux ?_
intro A g hg
rw [CokernelCofork.π_ofπ] at hg
rw [← cancel_epi f, hg, ← aux, CokernelCofork.π_ofπ]
· intro A
simp only [CokernelCofork.π_ofπ, ← Category.assoc]
convert colimit.ι_desc A WalkingParallelPair.one using 2
rw [IsIso.comp_inv_eq, IsIso.comp_inv_eq, eq_comm, ← imageMonoFactorisation_e']
exact (imageMonoFactorisation f).fac }⟩
end OfCoimageImageComparisonIsIso
variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)]
[Limits.HasFiniteProducts C]
attribute [local instance] OfCoimageImageComparisonIsIso.isNormalMonoCategory
attribute [local instance] OfCoimageImageComparisonIsIso.isNormalEpiCategory
/-- A preadditive category with kernels, cokernels, and finite products,
in which the coimage-image comparison morphism is always an isomorphism,
is an abelian category. -/
@[stacks 0109
"The Stacks project uses this characterisation at the definition of an abelian category."]
def ofCoimageImageComparisonIsIso : Abelian C where
end CategoryTheory.Abelian
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C] [Abelian C]
-- Porting note: the below porting note is from mathlib3!
-- Porting note: this should be an instance,
-- but triggers https://github.com/leanprover/lean4/issues/2055
-- We set it as a local instance instead.
-- instance (priority := 100)
-- Turning it into a global instance breaks `Mathlib.Algebra.Category.ModuleCat.Sheaf.Free`.
/-- An abelian category has finite biproducts. -/
theorem hasFiniteBiproducts : HasFiniteBiproducts C :=
Limits.HasFiniteBiproducts.of_hasFiniteProducts
attribute [local instance] hasFiniteBiproducts
instance (priority := 100) hasBinaryBiproducts : HasBinaryBiproducts C :=
Limits.hasBinaryBiproducts_of_finite_biproducts _
instance (priority := 100) hasZeroObject : HasZeroObject C :=
hasZeroObject_of_hasInitial_object
section ToNonPreadditiveAbelian
/-- Every abelian category is, in particular, `NonPreadditiveAbelian`. -/
def nonPreadditiveAbelian : NonPreadditiveAbelian C :=
{ ‹Abelian C› with }
end ToNonPreadditiveAbelian
section
/-! We now promote some instances that were constructed using `non_preadditive_abelian`. -/
attribute [local instance] nonPreadditiveAbelian
variable {P Q : C} (f : P ⟶ Q)
/-- The map `p : P ⟶ image f` is an epimorphism -/
instance : Epi (Abelian.factorThruImage f) := by infer_instance
instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := by infer_instance
/-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/
instance : Mono (Abelian.factorThruCoimage f) := by infer_instance
instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := by infer_instance
end
section Factor
attribute [local instance] nonPreadditiveAbelian
variable {P Q : C} (f : P ⟶ Q)
section
theorem mono_of_kernel_ι_eq_zero (h : kernel.ι f = 0) : Mono f :=
mono_of_kernel_zero h
theorem epi_of_cokernel_π_eq_zero (h : cokernel.π f = 0) : Epi f := by
apply NormalMonoCategory.epi_of_zero_cokernel _ (cokernel f)
simp_rw [← h]
exact IsColimit.ofIsoColimit (colimit.isColimit (parallelPair f 0)) (isoOfπ _)
end
section
variable {f}
theorem image_ι_comp_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : Abelian.image.ι f ≫ g = 0 :=
zero_of_epi_comp (Abelian.factorThruImage f) <| by simp [h]
theorem comp_coimage_π_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : f ≫ Abelian.coimage.π g = 0 :=
zero_of_comp_mono (Abelian.factorThruCoimage g) <| by simp [h]
end
/-- Factoring through the image is a strong epi-mono factorisation. -/
@[simps]
def imageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where
I := Abelian.image f
m := image.ι f
m_mono := by infer_instance
e := Abelian.factorThruImage f
e_strong_epi := strongEpi_of_epi _
/-- Factoring through the coimage is a strong epi-mono factorisation. -/
@[simps]
def coimageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where
I := Abelian.coimage f
m := Abelian.factorThruCoimage f
m_mono := by infer_instance
e := coimage.π f
e_strong_epi := strongEpi_of_epi _
end Factor
section HasStrongEpiMonoFactorisations
/-- An abelian category has strong epi-mono factorisations. -/
instance (priority := 100) : HasStrongEpiMonoFactorisations C :=
HasStrongEpiMonoFactorisations.mk fun f => imageStrongEpiMonoFactorisation f
-- In particular, this means that it has well-behaved images.
example : HasImages C := by infer_instance
example : HasImageMaps C := by infer_instance
end HasStrongEpiMonoFactorisations
section Images
variable {X Y : C} (f : X ⟶ Y)
/-- The coimage-image comparison morphism is always an isomorphism in an abelian category.
See `CategoryTheory.Abelian.ofCoimageImageComparisonIsIso` for the converse.
-/
instance : IsIso (coimageImageComparison f) := by
convert
Iso.isIso_hom
(IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage
(imageStrongEpiMonoFactorisation f).toMonoIsImage)
ext
change _ = _ ≫ (imageStrongEpiMonoFactorisation f).m
simp [-imageStrongEpiMonoFactorisation_m]
/-- There is a canonical isomorphism between the abelian coimage and the abelian image of a
morphism. -/
abbrev coimageIsoImage : Abelian.coimage f ≅ Abelian.image f :=
asIso (coimageImageComparison f)
/-- There is a canonical isomorphism between the abelian coimage and the categorical image of a
morphism. -/
abbrev coimageIsoImage' : Abelian.coimage f ≅ image f :=
IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f)
theorem coimageIsoImage'_hom :
(coimageIsoImage' f).hom =
cokernel.desc _ (factorThruImage f) (by simp [← cancel_mono (Limits.image.ι f)]) := by
ext
simp only [← cancel_mono (Limits.image.ι f), IsImage.isoExt_hom, cokernel.π_desc,
Category.assoc, IsImage.lift_ι, coimageStrongEpiMonoFactorisation_m,
Limits.image.fac]
theorem factorThruImage_comp_coimageIsoImage'_inv :
factorThruImage f ≫ (coimageIsoImage' f).inv = cokernel.π _ := by
simp only [IsImage.isoExt_inv, image.isImage_lift, image.fac_lift,
coimageStrongEpiMonoFactorisation_e]
/-- There is a canonical isomorphism between the abelian image and the categorical image of a
morphism. -/
abbrev imageIsoImage : Abelian.image f ≅ image f :=
IsImage.isoExt (imageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f)
theorem imageIsoImage_hom_comp_image_ι : (imageIsoImage f).hom ≫ Limits.image.ι _ = kernel.ι _ := by
simp only [IsImage.isoExt_hom, IsImage.lift_ι, imageStrongEpiMonoFactorisation_m]
theorem imageIsoImage_inv :
(imageIsoImage f).inv =
kernel.lift _ (Limits.image.ι f) (by simp [← cancel_epi (factorThruImage f)]) := by
ext
rw [IsImage.isoExt_inv, image.isImage_lift, Limits.image.fac_lift,
imageStrongEpiMonoFactorisation_e, Category.assoc, kernel.lift_ι, equalizer_as_kernel,
kernel.lift_ι, Limits.image.fac]
end Images
section CokernelOfKernel
variable {X Y : C} {f : X ⟶ Y}
attribute [local instance] nonPreadditiveAbelian
/-- In an abelian category, an epi is the cokernel of its kernel. More precisely:
If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel
of `fork.ι s`. -/
def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) :
IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) :=
NonPreadditiveAbelian.epiIsCokernelOfKernel s h
/-- In an abelian category, a mono is the kernel of its cokernel. More precisely:
If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel
of `cofork.π s`. -/
def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) :
IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) :=
NonPreadditiveAbelian.monoIsKernelOfCokernel s h
variable (f)
/-- In an abelian category, any morphism that turns to zero when precomposed with the kernel of an
epimorphism factors through that epimorphism. -/
def epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) : Y ⟶ T :=
(epiIsCokernelOfKernel _ (limit.isLimit _)).desc (CokernelCofork.ofπ _ hg)
@[reassoc (attr := simp)]
theorem comp_epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) :
f ≫ epiDesc f g hg = g :=
(epiIsCokernelOfKernel _ (limit.isLimit _)).fac (CokernelCofork.ofπ _ hg) WalkingParallelPair.one
/-- In an abelian category, any morphism that turns to zero when postcomposed with the cokernel of a
monomorphism factors through that monomorphism. -/
def monoLift [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) : T ⟶ X :=
(monoIsKernelOfCokernel _ (colimit.isColimit _)).lift (KernelFork.ofι _ hg)
@[reassoc (attr := simp)]
theorem monoLift_comp [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) :
monoLift f g hg ≫ f = g :=
(monoIsKernelOfCokernel _ (colimit.isColimit _)).fac (KernelFork.ofι _ hg)
WalkingParallelPair.zero
section
variable {D : Type*} [Category D] [HasZeroMorphisms D]
/-- If `F : D ⥤ C` is a functor to an abelian category, `i : X ⟶ Y` is a morphism
admitting a cokernel such that `F` preserves this cokernel and `F.map i` is a mono,
then `F.map X` identifies to the kernel of `F.map (cokernel.π i)`. -/
noncomputable def isLimitMapConeOfKernelForkOfι
{X Y : D} (i : X ⟶ Y) [HasCokernel i] (F : D ⥤ C)
[F.PreservesZeroMorphisms] [Mono (F.map i)]
[PreservesColimit (parallelPair i 0) F] :
IsLimit (F.mapCone (KernelFork.ofι i (cokernel.condition i))) := by
let e : parallelPair (cokernel.π (F.map i)) 0 ≅ parallelPair (cokernel.π i) 0 ⋙ F :=
parallelPair.ext (Iso.refl _) (asIso (cokernelComparison i F)) (by simp) (by simp)
refine IsLimit.postcomposeInvEquiv e _ ?_
let hi := Abelian.monoIsKernelOfCokernel _ (cokernelIsCokernel (F.map i))
refine IsLimit.ofIsoLimit hi (Fork.ext (Iso.refl _) ?_)
change 𝟙 _ ≫ F.map i ≫ 𝟙 _ = F.map i
rw [Category.comp_id, Category.id_comp]
/-- If `F : D ⥤ C` is a functor to an abelian category, `p : X ⟶ Y` is a morphisms
admitting a kernel such that `F` preserves this kernel and `F.map p` is an epi,
then `F.map Y` identifies to the cokernel of `F.map (kernel.ι p)`. -/
noncomputable def isColimitMapCoconeOfCokernelCoforkOfπ
{X Y : D} (p : X ⟶ Y) [HasKernel p] (F : D ⥤ C)
[F.PreservesZeroMorphisms] [Epi (F.map p)]
[PreservesLimit (parallelPair p 0) F] :
IsColimit (F.mapCocone (CokernelCofork.ofπ p (kernel.condition p))) := by
let e : parallelPair (kernel.ι p) 0 ⋙ F ≅ parallelPair (kernel.ι (F.map p)) 0 :=
parallelPair.ext (asIso (kernelComparison p F)) (Iso.refl _) (by simp) (by simp)
refine IsColimit.precomposeInvEquiv e _ ?_
let hp := Abelian.epiIsCokernelOfKernel _ (kernelIsKernel (F.map p))
refine IsColimit.ofIsoColimit hp (Cofork.ext (Iso.refl _) ?_)
change F.map p ≫ 𝟙 _ = 𝟙 _ ≫ F.map p
rw [Category.comp_id, Category.id_comp]
end
end CokernelOfKernel
section
instance (priority := 100) hasEqualizers : HasEqualizers C :=
Preadditive.hasEqualizers_of_hasKernels
/-- Any abelian category has pullbacks -/
instance (priority := 100) hasPullbacks : HasPullbacks C :=
hasPullbacks_of_hasBinaryProducts_of_hasEqualizers C
end
section
instance (priority := 100) hasCoequalizers : HasCoequalizers C :=
Preadditive.hasCoequalizers_of_hasCokernels
/-- Any abelian category has pushouts -/
instance (priority := 100) hasPushouts : HasPushouts C :=
hasPushouts_of_hasBinaryCoproducts_of_hasCoequalizers C
instance (priority := 100) hasFiniteLimits : HasFiniteLimits C :=
Limits.hasFiniteLimits_of_hasEqualizers_and_finite_products
instance (priority := 100) hasFiniteColimits : HasFiniteColimits C :=
Limits.hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts
end
namespace PullbackToBiproductIsKernel
variable [Limits.HasPullbacks C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
/-! This section contains a slightly technical result about pullbacks and biproducts.
We will need it in the proof that the pullback of an epimorphism is an epimorphism. -/
/-- The canonical map `pullback f g ⟶ X ⊞ Y` -/
abbrev pullbackToBiproduct : pullback f g ⟶ X ⊞ Y :=
biprod.lift (pullback.fst f g) (pullback.snd f g)
/-- The canonical map `pullback f g ⟶ X ⊞ Y` induces a kernel cone on the map
`biproduct X Y ⟶ Z` induced by `f` and `g`. A slightly more intuitive way to think of
this may be that it induces an equalizer fork on the maps induced by `(f, 0)` and
`(0, g)`. -/
abbrev pullbackToBiproductFork : KernelFork (biprod.desc f (-g)) :=
KernelFork.ofι (pullbackToBiproduct f g) <| by
rw [biprod.lift_desc, comp_neg, pullback.condition, add_neg_cancel]
/-- The canonical map `pullback f g ⟶ X ⊞ Y` is a kernel of the map induced by
`(f, -g)`. -/
def isLimitPullbackToBiproduct : IsLimit (pullbackToBiproductFork f g) :=
Fork.IsLimit.mk _
(fun s =>
pullback.lift (Fork.ι s ≫ biprod.fst) (Fork.ι s ≫ biprod.snd) <|
sub_eq_zero.1 <| by
rw [Category.assoc, Category.assoc, ← comp_sub, sub_eq_add_neg, ← comp_neg, ←
biprod.desc_eq, KernelFork.condition s])
(fun s => by
apply biprod.hom_ext <;> rw [Fork.ι_ofι, Category.assoc]
· rw [biprod.lift_fst, pullback.lift_fst]
· rw [biprod.lift_snd, pullback.lift_snd])
fun s m h => by apply pullback.hom_ext <;> simp [← h]
end PullbackToBiproductIsKernel
namespace BiproductToPushoutIsCokernel
variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
/-- The canonical map `Y ⊞ Z ⟶ pushout f g` -/
abbrev biproductToPushout : Y ⊞ Z ⟶ pushout f g :=
biprod.desc (pushout.inl _ _) (pushout.inr _ _)
/-- The canonical map `Y ⊞ Z ⟶ pushout f g` induces a cokernel cofork on the map
`X ⟶ Y ⊞ Z` induced by `f` and `-g`. -/
abbrev biproductToPushoutCofork : CokernelCofork (biprod.lift f (-g)) :=
CokernelCofork.ofπ (biproductToPushout f g) <| by
rw [biprod.lift_desc, neg_comp, pushout.condition, add_neg_cancel]
/-- The cofork induced by the canonical map `Y ⊞ Z ⟶ pushout f g` is in fact a colimit cokernel
cofork. -/
def isColimitBiproductToPushout : IsColimit (biproductToPushoutCofork f g) :=
Cofork.IsColimit.mk _
(fun s =>
pushout.desc (biprod.inl ≫ Cofork.π s) (biprod.inr ≫ Cofork.π s) <|
sub_eq_zero.1 <| by
rw [← Category.assoc, ← Category.assoc, ← sub_comp, sub_eq_add_neg, ← neg_comp, ←
biprod.lift_eq, Cofork.condition s, zero_comp])
(fun s => by apply biprod.hom_ext' <;> simp)
fun s m h => by apply pushout.hom_ext <;> simp [← h]
end BiproductToPushoutIsCokernel
section EpiPullback
variable [Limits.HasPullbacks C] {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
/-- In an abelian category, the pullback of an epimorphism is an epimorphism.
Proof from [aluffi2016, IX.2.3], cf. [borceux-vol2, 1.7.6] -/
instance epi_pullback_of_epi_f [Epi f] : Epi (pullback.snd f g) :=
-- It will suffice to consider some morphism e : Y ⟶ R such that
-- pullback.snd f g ≫ e = 0 and show that e = 0.
epi_of_cancel_zero _ fun {R} e h => by
-- Consider the morphism u := (0, e) : X ⊞ Y⟶ R.
let u := biprod.desc (0 : X ⟶ R) e
-- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption.
have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u]
-- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a
-- cokernel of pullbackToBiproduct f g
have :=
epiIsCokernelOfKernel _
(PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g)
-- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R.
obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu
dsimp at d; dsimp [u] at hd
-- But then f ≫ d = 0:
have : f ≫ d = 0 := calc
f ≫ d = (biprod.inl ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inl_desc]
_ = biprod.inl ≫ u := by rw [Category.assoc, hd]
_ = 0 := biprod.inl_desc _ _
-- But f is an epimorphism, so d = 0...
have : d = 0 := (cancel_epi f).1 (by simpa)
-- ...or, in other words, e = 0.
calc
e = biprod.inr ≫ biprod.desc (0 : X ⟶ R) e := by rw [biprod.inr_desc]
_ = biprod.inr ≫ biprod.desc f (-g) ≫ d := by rw [← hd]
_ = biprod.inr ≫ biprod.desc f (-g) ≫ 0 := by rw [this]
_ = (biprod.inr ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc]
_ = 0 := HasZeroMorphisms.comp_zero _ _
/-- In an abelian category, the pullback of an epimorphism is an epimorphism. -/
instance epi_pullback_of_epi_g [Epi g] : Epi (pullback.fst f g) :=
-- It will suffice to consider some morphism e : X ⟶ R such that
-- pullback.fst f g ≫ e = 0 and show that e = 0.
epi_of_cancel_zero _ fun {R} e h => by
-- Consider the morphism u := (e, 0) : X ⊞ Y ⟶ R.
let u := biprod.desc e (0 : Y ⟶ R)
-- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption.
have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u]
-- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a
-- cokernel of pullbackToBiproduct f g
have :=
epiIsCokernelOfKernel _
(PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g)
-- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R.
obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu
dsimp at d; dsimp [u] at hd
-- But then (-g) ≫ d = 0:
have : (-g) ≫ d = 0 := calc
(-g) ≫ d = (biprod.inr ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inr_desc]
_ = biprod.inr ≫ u := by rw [Category.assoc, hd]
_ = 0 := biprod.inr_desc _ _
-- But g is an epimorphism, thus so is -g, so d = 0...
have : d = 0 := (cancel_epi (-g)).1 (by simpa)
-- ...or, in other words, e = 0.
calc
e = biprod.inl ≫ biprod.desc e (0 : Y ⟶ R) := by rw [biprod.inl_desc]
_ = biprod.inl ≫ biprod.desc f (-g) ≫ d := by rw [← hd]
_ = biprod.inl ≫ biprod.desc f (-g) ≫ 0 := by rw [this]
_ = (biprod.inl ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc]
_ = 0 := HasZeroMorphisms.comp_zero _ _
theorem epi_snd_of_isLimit [Epi f] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.snd := by
haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.right) :=
Abelian.epi_pullback_of_epi_f f g
apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _)
theorem epi_fst_of_isLimit [Epi g] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.fst := by
haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.left) :=
Abelian.epi_pullback_of_epi_g f g
apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _)
/-- Suppose `f` and `g` are two morphisms with a common codomain and suppose we have written `g` as
an epimorphism followed by a monomorphism. If `f` factors through the mono part of this
factorization, then any pullback of `g` along `f` is an epimorphism. -/
theorem epi_fst_of_factor_thru_epi_mono_factorization (g₁ : Y ⟶ W) [Epi g₁] (g₂ : W ⟶ Z) [Mono g₂]
(hg : g₁ ≫ g₂ = g) (f' : X ⟶ W) (hf : f' ≫ g₂ = f) (t : PullbackCone f g) (ht : IsLimit t) :
Epi t.fst := by
apply epi_fst_of_isLimit _ _ (PullbackCone.isLimitOfFactors f g g₂ f' g₁ hf hg t ht)
end EpiPullback
section MonoPushout
variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
instance mono_pushout_of_mono_f [Mono f] : Mono (pushout.inr _ _ : Z ⟶ pushout f g) :=
mono_of_cancel_zero _ fun {R} e h => by
let u := biprod.lift (0 : R ⟶ Y) e
have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u]
have :=
monoIsKernelOfCokernel _
(BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g)
obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu
dsimp at d
dsimp [u] at hd
have : d ≫ f = 0 := calc
d ≫ f = d ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [biprod.lift_fst]
_ = u ≫ biprod.fst := by rw [← Category.assoc, hd]
_ = 0 := biprod.lift_fst _ _
have : d = 0 := (cancel_mono f).1 (by simpa)
calc
e = biprod.lift (0 : R ⟶ Y) e ≫ biprod.snd := by rw [biprod.lift_snd]
_ = (d ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [← hd]
_ = (0 ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [this]
_ = 0 ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [Category.assoc]
_ = 0 := zero_comp
instance mono_pushout_of_mono_g [Mono g] : Mono (pushout.inl f g) :=
mono_of_cancel_zero _ fun {R} e h => by
let u := biprod.lift e (0 : R ⟶ Z)
have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u]
have :=
monoIsKernelOfCokernel _
(BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g)
obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu
dsimp at d
dsimp [u] at hd
have : d ≫ (-g) = 0 := calc
d ≫ (-g) = d ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [biprod.lift_snd]
_ = biprod.lift e (0 : R ⟶ Z) ≫ biprod.snd := by rw [← Category.assoc, hd]
_ = 0 := biprod.lift_snd _ _
have : d = 0 := (cancel_mono (-g)).1 (by simpa)
calc
e = biprod.lift e (0 : R ⟶ Z) ≫ biprod.fst := by rw [biprod.lift_fst]
_ = (d ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [← hd]
_ = (0 ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [this]
_ = 0 ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [Category.assoc]
_ = 0 := zero_comp
theorem mono_inr_of_isColimit [Mono f] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inr := by
haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.right) :=
Abelian.mono_pushout_of_mono_f f g
apply
mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _)
theorem mono_inl_of_isColimit [Mono g] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inl := by
haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.left) :=
Abelian.mono_pushout_of_mono_g f g
apply
mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _)
/-- Suppose `f` and `g` are two morphisms with a common domain and suppose we have written `g` as
an epimorphism followed by a monomorphism. If `f` factors through the epi part of this
factorization, then any pushout of `g` along `f` is a monomorphism. -/
theorem mono_inl_of_factor_thru_epi_mono_factorization (f : X ⟶ Y) (g : X ⟶ Z) (g₁ : X ⟶ W) [Epi g₁]
(g₂ : W ⟶ Z) [Mono g₂] (hg : g₁ ≫ g₂ = g) (f' : W ⟶ Y) (hf : g₁ ≫ f' = f)
(t : PushoutCocone f g) (ht : IsColimit t) : Mono t.inl := by
apply mono_inl_of_isColimit _ _ (PushoutCocone.isColimitOfFactors _ _ _ _ _ hf hg t ht)
end MonoPushout
end CategoryTheory.Abelian
namespace CategoryTheory.NonPreadditiveAbelian
variable (C : Type u) [Category.{v} C] [NonPreadditiveAbelian C]
/-- Every NonPreadditiveAbelian category can be promoted to an abelian category. -/
def abelian : Abelian C where
toPreadditive := NonPreadditiveAbelian.preadditive
normalMonoOfMono := fun f _ ↦ ⟨normalMonoOfMono f⟩
normalEpiOfEpi := fun f _ ↦ ⟨normalEpiOfEpi f⟩
end CategoryTheory.NonPreadditiveAbelian
| Mathlib/CategoryTheory/Abelian/Basic.lean | 798 | 802 | |
/-
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.Dynamics.BirkhoffSum.Basic
import Mathlib.Algebra.Module.Basic
/-!
# Birkhoff average
In this file we define `birkhoffAverage f g n x` to be
$$
\frac{1}{n}\sum_{k=0}^{n-1}g(f^{[k]}(x)),
$$
where `f : α → α` is a self-map on some type `α`,
`g : α → M` is a function from `α` to a module over a division semiring `R`,
and `R` is used to formalize division by `n` as `(n : R)⁻¹ • _`.
While we need an auxiliary division semiring `R` to define `birkhoffAverage`,
the definition does not depend on the choice of `R`,
see `birkhoffAverage_congr_ring`.
-/
open Finset
section birkhoffAverage
variable (R : Type*) {α M : Type*} [DivisionSemiring R] [AddCommMonoid M] [Module R M]
/-- The average value of `g` on the first `n` points of the orbit of `x` under `f`,
i.e. the Birkhoff sum `∑ k ∈ Finset.range n, g (f^[k] x)` divided by `n`.
This average appears in many ergodic theorems
which say that `(birkhoffAverage R f g · x)`
converges to the "space average" `⨍ x, g x ∂μ` as `n → ∞`.
We use an auxiliary `[DivisionSemiring R]` to define division by `n`.
However, the definition does not depend on the choice of `R`,
see `birkhoffAverage_congr_ring`. -/
def birkhoffAverage (f : α → α) (g : α → M) (n : ℕ) (x : α) : M := (n : R)⁻¹ • birkhoffSum f g n x
theorem birkhoffAverage_zero (f : α → α) (g : α → M) (x : α) :
birkhoffAverage R f g 0 x = 0 := by simp [birkhoffAverage]
@[simp] theorem birkhoffAverage_zero' (f : α → α) (g : α → M) : birkhoffAverage R f g 0 = 0 :=
funext <| birkhoffAverage_zero _ _ _
| theorem birkhoffAverage_one (f : α → α) (g : α → M) (x : α) :
birkhoffAverage R f g 1 x = g x := by simp [birkhoffAverage]
| Mathlib/Dynamics/BirkhoffSum/Average.lean | 50 | 51 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Real
/-!
# Power function on `ℝ≥0` and `ℝ≥0∞`
We construct the power functions `x ^ y` where
* `x` is a nonnegative real number and `y` is a real number;
* `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number.
We also prove basic properties of these functions.
-/
noncomputable section
open Real NNReal ENNReal ComplexConjugate Finset Function Set
namespace NNReal
variable {x : ℝ≥0} {w y z : ℝ}
/-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the
restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`,
one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 :=
⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩
noncomputable instance : Pow ℝ≥0 ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp, norm_cast]
theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y :=
rfl
@[simp]
theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 :=
NNReal.eq <| Real.rpow_zero _
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero]
exact Real.rpow_eq_zero_iff_of_nonneg x.2
lemma rpow_eq_zero (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [hy]
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 :=
NNReal.eq <| Real.zero_rpow h
@[simp]
theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x :=
NNReal.eq <| Real.rpow_one _
lemma rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ :=
NNReal.eq <| Real.rpow_neg x.2 _
@[simp, norm_cast]
lemma rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n
@[simp, norm_cast]
lemma rpow_intCast (x : ℝ≥0) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast,
Int.cast_negSucc, rpow_neg, zpow_negSucc]
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 :=
NNReal.eq <| Real.one_rpow _
theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _
theorem rpow_add' (h : y + z ≠ 0) (x : ℝ≥0) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add' x.2 h
lemma rpow_add_intCast (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast (mod_cast hx) _ _
lemma rpow_add_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast (mod_cast hx) _ _
lemma rpow_sub_intCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _
lemma rpow_sub_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _
lemma rpow_add_intCast' {n : ℤ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast' (mod_cast x.2) h
lemma rpow_add_natCast' {n : ℕ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast' (mod_cast x.2) h
lemma rpow_sub_intCast' {n : ℤ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h
lemma rpow_sub_natCast' {n : ℕ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h
lemma rpow_add_one (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by
simpa using rpow_add_natCast hx y 1
lemma rpow_sub_one (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by
simpa using rpow_sub_natCast hx y 1
lemma rpow_add_one' (h : y + 1 ≠ 0) (x : ℝ≥0) : x ^ (y + 1) = x ^ y * x := by
rw [rpow_add' h, rpow_one]
lemma rpow_one_add' (h : 1 + y ≠ 0) (x : ℝ≥0) : x ^ (1 + y) = x * x ^ y := by
rw [rpow_add' h, rpow_one]
theorem rpow_add_of_nonneg (x : ℝ≥0) {y z : ℝ} (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
ext; exact Real.rpow_add_of_nonneg x.2 hy hz
/-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add']; rwa [h]
theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
NNReal.eq <| Real.rpow_mul x.2 y z
lemma rpow_natCast_mul (x : ℝ≥0) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_natCast]
lemma rpow_mul_natCast (x : ℝ≥0) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_natCast]
lemma rpow_intCast_mul (x : ℝ≥0) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_intCast]
lemma rpow_mul_intCast (x : ℝ≥0) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_intCast]
theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg]
theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z
theorem rpow_sub' (h : y - z ≠ 0) (x : ℝ≥0) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub' x.2 h
lemma rpow_sub_one' (h : y - 1 ≠ 0) (x : ℝ≥0) : x ^ (y - 1) = x ^ y / x := by
rw [rpow_sub' h, rpow_one]
lemma rpow_one_sub' (h : 1 - y ≠ 0) (x : ℝ≥0) : x ^ (1 - y) = x / x ^ y := by
rw [rpow_sub' h, rpow_one]
theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by
field_simp [← rpow_mul]
theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by
field_simp [← rpow_mul]
theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ :=
NNReal.eq <| Real.inv_rpow x.2 y
theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z :=
NNReal.eq <| Real.div_rpow x.2 y.2 z
theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by
refine NNReal.eq ?_
push_cast
exact Real.sqrt_eq_rpow x.1
@[simp]
lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] :
x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) :=
rpow_natCast x n
theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z :=
NNReal.eq <| Real.mul_rpow x.2 y.2
/-- `rpow` as a `MonoidHom` -/
@[simps]
def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where
toFun := (· ^ r)
map_one' := one_rpow _
map_mul' _x _y := mul_rpow
/-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0` -/
theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r :=
l.prod_hom (rpowMonoidHom r)
theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← list_prod_map_rpow, List.map_map]; rfl
/-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/
lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r :=
s.prod_hom' (rpowMonoidHom r) _
/-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/
lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
multiset_prod_map_rpow _ _ _
-- note: these don't really belong here, but they're much easier to prove in terms of the above
section Real
/-- `rpow` version of `List.prod_map_pow` for `Real`. -/
theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r := by
lift l to List ℝ≥0 using hl
have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r)
push_cast at this
rw [List.map_map] at this ⊢
exact mod_cast this
theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ)
(hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map]
· rfl
simpa using hl
/-- `rpow` version of `Multiset.prod_map_pow`. -/
theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ)
(hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r := by
induction' s using Quotient.inductionOn with l
simpa using Real.list_prod_map_rpow' l f hs r
/-- `rpow` version of `Finset.prod_pow`. -/
theorem _root_.Real.finset_prod_rpow
{ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
Real.multiset_prod_map_rpow s.val f hs r
end Real
@[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z :=
Real.rpow_le_rpow x.2 h₁ h₂
@[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z :=
Real.rpow_lt_rpow x.2 h₁ h₂
theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
Real.rpow_lt_rpow_iff x.2 y.2 hz
theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
Real.rpow_le_rpow_iff x.2 y.2 hz
theorem le_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem rpow_inv_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem lt_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by
simp only [← not_le, rpow_inv_le_iff hz]
theorem rpow_inv_lt_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by
simp only [← not_le, le_rpow_inv_iff hz]
section
variable {y : ℝ≥0}
lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z :=
Real.rpow_lt_rpow_of_neg hx hxy hz
lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z :=
Real.rpow_le_rpow_of_nonpos hx hxy hz
lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x :=
Real.rpow_lt_rpow_iff_of_neg hx hy hz
lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x :=
Real.rpow_le_rpow_iff_of_neg hx hy hz
lemma le_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y :=
Real.le_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_le_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z :=
Real.rpow_inv_le_iff_of_pos x.2 hy hz
lemma lt_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x < y ^ z⁻¹ ↔ x ^ z < y :=
Real.lt_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_lt_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ < y ↔ x < y ^ z :=
Real.rpow_inv_lt_iff_of_pos x.2 hy hz
lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z :=
Real.le_rpow_inv_iff_of_neg hx hy hz
lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z :=
Real.lt_rpow_inv_iff_of_neg hx hy hz
lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x :=
Real.rpow_inv_lt_iff_of_neg hx hy hz
lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x :=
Real.rpow_inv_le_iff_of_neg hx hy hz
end
@[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_lt hx hyz
@[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_le hx hyz
theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz
theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz
theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by
have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by
intro p hp_pos
rw [← zero_rpow hp_pos.ne']
exact rpow_lt_rpow hx_pos hp_pos
rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg)
· exact rpow_pos_of_nonneg hp_pos
· simp only [zero_lt_one, rpow_zero]
· rw [← neg_neg p, rpow_neg, inv_pos]
exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg)
theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 :=
Real.rpow_lt_one (coe_nonneg x) hx1 hz
| theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 :=
Real.rpow_le_one x.2 hx2 hz
| Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean | 340 | 341 |
/-
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.Asymptotics
/-!
# Continuity of power functions
This file contains lemmas about continuity of the power functions on `ℂ`, `ℝ`, `ℝ≥0`, and `ℝ≥0∞`.
-/
noncomputable section
open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set
section CpowLimits
/-!
## Continuity for complex powers
-/
open Complex
variable {α : Type*}
theorem zero_cpow_eq_nhds {b : ℂ} (hb : b ≠ 0) : (fun x : ℂ => (0 : ℂ) ^ x) =ᶠ[𝓝 b] 0 := by
suffices ∀ᶠ x : ℂ in 𝓝 b, x ≠ 0 from
this.mono fun x hx ↦ by
dsimp only
rw [zero_cpow hx, Pi.zero_apply]
exact IsOpen.eventually_mem isOpen_ne hb
theorem cpow_eq_nhds {a b : ℂ} (ha : a ≠ 0) :
(fun x => x ^ b) =ᶠ[𝓝 a] fun x => exp (log x * b) := by
suffices ∀ᶠ x : ℂ in 𝓝 a, x ≠ 0 from
this.mono fun x hx ↦ by
dsimp only
rw [cpow_def_of_ne_zero hx]
exact IsOpen.eventually_mem isOpen_ne ha
theorem cpow_eq_nhds' {p : ℂ × ℂ} (hp_fst : p.fst ≠ 0) :
(fun x => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) := by
suffices ∀ᶠ x : ℂ × ℂ in 𝓝 p, x.1 ≠ 0 from
this.mono fun x hx ↦ by
dsimp only
rw [cpow_def_of_ne_zero hx]
refine IsOpen.eventually_mem ?_ hp_fst
change IsOpen { x : ℂ × ℂ | x.1 = 0 }ᶜ
rw [isOpen_compl_iff]
exact isClosed_eq continuous_fst continuous_const
-- Continuity of `fun x => a ^ x`: union of these two lemmas is optimal.
theorem continuousAt_const_cpow {a b : ℂ} (ha : a ≠ 0) : ContinuousAt (fun x : ℂ => a ^ x) b := by
have cpow_eq : (fun x : ℂ => a ^ x) = fun x => exp (log a * x) := by
ext1 b
rw [cpow_def_of_ne_zero ha]
rw [cpow_eq]
exact continuous_exp.continuousAt.comp (ContinuousAt.mul continuousAt_const continuousAt_id)
theorem continuousAt_const_cpow' {a b : ℂ} (h : b ≠ 0) : ContinuousAt (fun x : ℂ => a ^ x) b := by
by_cases ha : a = 0
· rw [ha, continuousAt_congr (zero_cpow_eq_nhds h)]
exact continuousAt_const
· exact continuousAt_const_cpow ha
/-- The function `z ^ w` is continuous in `(z, w)` provided that `z` does not belong to the interval
`(-∞, 0]` on the real line. See also `Complex.continuousAt_cpow_zero_of_re_pos` for a version that
works for `z = 0` but assumes `0 < re w`. -/
theorem continuousAt_cpow {p : ℂ × ℂ} (hp_fst : p.fst ∈ slitPlane) :
ContinuousAt (fun x : ℂ × ℂ => x.1 ^ x.2) p := by
rw [continuousAt_congr (cpow_eq_nhds' <| slitPlane_ne_zero hp_fst)]
refine continuous_exp.continuousAt.comp ?_
exact
ContinuousAt.mul
(ContinuousAt.comp (continuousAt_clog hp_fst) continuous_fst.continuousAt)
continuous_snd.continuousAt
theorem continuousAt_cpow_const {a b : ℂ} (ha : a ∈ slitPlane) :
| ContinuousAt (· ^ b) a :=
Tendsto.comp (@continuousAt_cpow (a, b) ha) (continuousAt_id.prodMk continuousAt_const)
theorem Filter.Tendsto.cpow {l : Filter α} {f g : α → ℂ} {a b : ℂ} (hf : Tendsto f l (𝓝 a))
(hg : Tendsto g l (𝓝 b)) (ha : a ∈ slitPlane) :
Tendsto (fun x => f x ^ g x) l (𝓝 (a ^ b)) :=
(@continuousAt_cpow (a, b) ha).tendsto.comp (hf.prodMk_nhds hg)
| Mathlib/Analysis/SpecialFunctions/Pow/Continuity.lean | 84 | 91 |
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Basic
import Mathlib.Algebra.GroupWithZero.Basic
/-!
# Basic Translation Lemmas Between Functions Defined for Continued Fractions
## Summary
Some simple translation lemmas between the different definitions of functions defined in
`Algebra.ContinuedFractions.Basic`.
-/
namespace GenContFract
section General
/-!
### Translations Between General Access Functions
Here we give some basic translations that hold by definition between the various methods that allow
us to access the numerators and denominators of a continued fraction.
-/
variable {α : Type*} {g : GenContFract α} {n : ℕ}
theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl
theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl
theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq]
theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by
rw [terminatedAt_iff_s_none, partNum_none_iff_s_none]
theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq]
theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by
rw [terminatedAt_iff_s_none, partDen_none_iff_s_none]
theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) :
g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq]
theorem partDen_eq_s_b {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) :
g.partDens.get? n = some gp.b := by simp [partDens, s_nth_eq]
theorem exists_s_a_of_partNum {a : α} (nth_partNum_eq : g.partNums.get? n = some a) :
∃ gp, g.s.get? n = some gp ∧ gp.a = a := by
simpa [partNums, Stream'.Seq.map_get?] using nth_partNum_eq
|
theorem exists_s_b_of_partDen {b : α}
| Mathlib/Algebra/ContinuedFractions/Translations.lean | 58 | 59 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.TangentCone
import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics
import Mathlib.Analysis.Asymptotics.TVS
import Mathlib.Analysis.Asymptotics.Lemmas
/-!
# The Fréchet derivative
Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a
continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then
`HasFDerivWithinAt f f' s x`
says that `f` has derivative `f'` at `x`, where the domain of interest
is restricted to `s`. We also have
`HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ`
Finally,
`HasStrictFDerivAt f f' x`
means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability,
i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse
function theorem, and is defined here only to avoid proving theorems like
`IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for
`HasStrictFDerivAt`.
## Main results
In addition to the definition and basic properties of the derivative,
the folder `Analysis/Calculus/FDeriv/` contains the usual formulas
(and existence assertions) for the derivative of
* constants
* the identity
* bounded linear maps (`Linear.lean`)
* bounded bilinear maps (`Bilinear.lean`)
* sum of two functions (`Add.lean`)
* sum of finitely many functions (`Add.lean`)
* multiplication of a function by a scalar constant (`Add.lean`)
* negative of a function (`Add.lean`)
* subtraction of two functions (`Add.lean`)
* multiplication of a function by a scalar function (`Mul.lean`)
* multiplication of two scalar functions (`Mul.lean`)
* composition of functions (the chain rule) (`Comp.lean`)
* inverse function (`Mul.lean`)
(assuming that it exists; the inverse function theorem is in `../Inverse.lean`)
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier,
and they more frequently lead to the desired result.
One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying
a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are
translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The
derivative of polynomials is handled there, as it is naturally one-dimensional.
The simplifier is set up to prove automatically that some functions are differentiable, or
differentiable at a point (but not differentiable on a set or within a set at a point, as checking
automatically that the good domains are mapped one to the other when using composition is not
something the simplifier can easily do). This means that one can write
`example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`.
If there are divisions, one needs to supply to the simplifier proofs that the denominators do
not vanish, as in
```lean
example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by
simp [h]
```
Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be
differentiable, in `Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv`.
The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general
complicated multidimensional linear maps), but it will compute one-dimensional derivatives,
see `Deriv.lean`.
## Implementation details
The derivative is defined in terms of the `IsLittleOTVS` relation to ensure the definition does not
ingrain a choice of norm, and is then quickly translated to the more convenient `IsLittleO` in the
subsequent theorems.
It is also characterized in terms of the `Tendsto` relation.
We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field,
`f` the function to be differentiated, `x` the point at which the derivative is asserted to exist,
and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`,
`DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative.
To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x`
for some choice of a derivative if it exists, and the zero function otherwise. This choice only
behaves well along sets for which the derivative is unique, i.e., those for which the tangent
directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and
`UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed
they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular
for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very
beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever.
To make sure that the simplifier can prove automatically that functions are differentiable, we tag
many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable
functions is differentiable, as well as their product, their cartesian product, and so on. A notable
exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are
differentiable, then their composition also is: `simp` would always be able to match this lemma,
by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`),
we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding
some boilerplate lemmas, but these can also be useful in their own right.
Tests for this ability of the simplifier (with more examples) are provided in
`Tests/Differentiable.lean`.
## TODO
Generalize more results to topological vector spaces.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section TVS
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E]
variable {F : Type*} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F]
/-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition
is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion
of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to
the notion of Fréchet derivative along the set `s`. -/
@[mk_iff hasFDerivAtFilter_iff_isLittleOTVS]
structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where
of_isLittleOTVS ::
isLittleOTVS : (fun x' => f x' - f x - f' (x' - x)) =o[𝕜; L] (fun x' => x' - x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/
@[fun_prop]
def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) :=
HasFDerivAtFilter f f' x (𝓝[s] x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/
@[fun_prop]
def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
HasFDerivAtFilter f f' x (𝓝 x)
/-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability*
if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required,
e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly
differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/
@[fun_prop, mk_iff hasStrictFDerivAt_iff_isLittleOTVS]
structure HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) where
of_isLittleOTVS ::
isLittleOTVS :
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2))
=o[𝕜; 𝓝 (x, x)] (fun p : E × E => p.1 - p.2)
variable (𝕜)
/-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative
there (possibly non-unique). -/
@[fun_prop]
def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x
/-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly
non-unique). -/
@[fun_prop]
def DifferentiableAt (f : E → F) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivAt f f' x
open scoped Classical in
/-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative.
Otherwise, it is set to `0`. We also set it to be zero, if zero is one of possible derivatives. -/
irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F :=
if HasFDerivWithinAt f (0 : E →L[𝕜] F) s x
then 0
else if h : DifferentiableWithinAt 𝕜 f s x
then Classical.choose h
else 0
/-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is
set to `0`. -/
irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F :=
fderivWithin 𝕜 f univ x
/-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/
@[fun_prop]
def DifferentiableOn (f : E → F) (s : Set E) :=
∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x
/-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/
@[fun_prop]
def Differentiable (f : E → F) :=
∀ x, DifferentiableAt 𝕜 f x
variable {𝕜}
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) :
fderivWithin 𝕜 f s x = 0 := by
simp [fderivWithin, h]
@[simp]
theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by
ext
rw [fderiv]
end TVS
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem hasFDerivAtFilter_iff_isLittleO :
HasFDerivAtFilter f f' x L ↔ (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x :=
(hasFDerivAtFilter_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasFDerivAtFilter.isLittleO, HasFDerivAtFilter.of_isLittleO⟩ :=
hasFDerivAtFilter_iff_isLittleO
theorem hasStrictFDerivAt_iff_isLittleO :
HasStrictFDerivAt f f' x ↔
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
(hasStrictFDerivAt_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasStrictFDerivAt.isLittleO, HasStrictFDerivAt.of_isLittleO⟩ :=
hasStrictFDerivAt_iff_isLittleO
section DerivativeUniqueness
/- In this section, we discuss the uniqueness of the derivative.
We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the
uniqueness of the derivative. -/
/-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f',
i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity
and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses
this fact, for functions having a derivative within a set. Its specific formulation is useful for
tangent cone related discussions. -/
theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α)
{c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s)
(clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) :
Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by
have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by
conv in 𝓝[s] x => rw [← add_zero x]
rw [nhdsWithin, tendsto_inf]
constructor
· apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim)
· rwa [tendsto_principal]
have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO
have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x :=
this.comp_tendsto tendsto_arg
have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left]
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n :=
(isBigO_refl c l).smul_isLittleO this
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) :=
this.trans_isBigO (cdlim.isBigO_one ℝ)
have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) :=
(isLittleO_one_iff ℝ).1 this
have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) :=
Tendsto.comp f'.cont.continuousAt cdlim
have L3 :
Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) :=
L1.add L2
have :
(fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n =>
c n • (f (x + d n) - f x) := by
ext n
simp [smul_add, smul_sub]
rwa [this, zero_add] at L3
/-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the
tangent cone to `s` at `x` -/
theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) :=
fun _ ⟨_, _, dtop, clim, cdlim⟩ =>
tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim)
/-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/
theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
ContinuousLinearMap.ext_on H.1 (hf.unique_on hg)
theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x)
(h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
(H x hx).eq h h₁
end DerivativeUniqueness
section FDerivProperties
/-! ### Basic properties of the derivative -/
theorem hasFDerivAtFilter_iff_tendsto :
HasFDerivAtFilter f f' x L ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by
have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by
rw [sub_eq_zero.1 (norm_eq_zero.1 hx')]
simp
rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right,
isLittleO_iff_tendsto h]
exact tendsto_congr fun _ => div_eq_inv_mul _ _
theorem hasFDerivWithinAt_iff_tendsto :
HasFDerivWithinAt f f' s x ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_tendsto :
HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_isLittleO_nhds_zero :
HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by
rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map]
simp [Function.comp_def]
nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) :
HasFDerivAtFilter f f' x L₁ :=
.of_isLittleOTVS <| h.isLittleOTVS.mono hst
theorem HasFDerivWithinAt.mono_of_mem_nhdsWithin
(h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_le_iff.mpr hst
@[deprecated (since := "2024-10-31")]
alias HasFDerivWithinAt.mono_of_mem := HasFDerivWithinAt.mono_of_mem_nhdsWithin
nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_mono _ hst
theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) :
HasFDerivAtFilter f f' x L :=
h.mono hL
@[fun_prop]
theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x :=
h.hasFDerivAtFilter inf_le_left
@[fun_prop]
theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) :
DifferentiableWithinAt 𝕜 f s x :=
⟨f', h⟩
@[fun_prop]
theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x :=
⟨f', h⟩
@[simp]
theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by
simp only [HasFDerivWithinAt, nhdsWithin_univ, HasFDerivAt]
alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ
theorem differentiableWithinAt_univ :
DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt]
theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by
rw [fderiv, fderivWithin_zero_of_not_differentiableWithinAt]
rwa [differentiableWithinAt_univ]
theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by
rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h]
lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x :=
hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx)
@[simp]
theorem hasFDerivWithinAt_insert {y : E} :
HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by
rcases eq_or_ne x y with (rfl | h)
· simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
apply isLittleOTVS_insert
simp only [sub_self, map_zero]
refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem_nhdsWithin ?_⟩
simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin]
alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert
protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) :
HasFDerivWithinAt g g' (insert x s) x :=
h.insert'
@[simp]
theorem hasFDerivWithinAt_diff_singleton (y : E) :
HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by
rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert]
@[simp]
protected theorem HasFDerivWithinAt.empty : HasFDerivWithinAt f f' ∅ x := by
simp [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
@[simp]
protected theorem DifferentiableWithinAt.empty : DifferentiableWithinAt 𝕜 f ∅ x :=
⟨0, .empty⟩
theorem HasFDerivWithinAt.of_finite (h : s.Finite) : HasFDerivWithinAt f f' s x := by
induction s, h using Set.Finite.induction_on with
| empty => exact .empty
| insert _ _ ih => exact ih.insert'
theorem DifferentiableWithinAt.of_finite (h : s.Finite) : DifferentiableWithinAt 𝕜 f s x :=
⟨0, .of_finite h⟩
@[simp]
protected theorem HasFDerivWithinAt.singleton {y} : HasFDerivWithinAt f f' {x} y :=
.of_finite <| finite_singleton _
@[simp]
protected theorem DifferentiableWithinAt.singleton {y} : DifferentiableWithinAt 𝕜 f {x} y :=
⟨0, .singleton⟩
theorem HasFDerivWithinAt.of_subsingleton (h : s.Subsingleton) : HasFDerivWithinAt f f' s x :=
.of_finite h.finite
theorem DifferentiableWithinAt.of_subsingleton (h : s.Subsingleton) :
DifferentiableWithinAt 𝕜 f s x :=
.of_finite h.finite
theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) :
(fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
hf.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _)
theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) :
(fun x' => f x' - f x) =O[L] fun x' => x' - x :=
h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _)
@[fun_prop]
protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) :
HasFDerivAt f f' x :=
.of_isLittleOTVS <| by
simpa only using hf.isLittleOTVS.comp_tendsto (tendsto_id.prodMk_nhds tendsto_const_nhds)
protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) :
DifferentiableAt 𝕜 f x :=
hf.hasFDerivAt.differentiableAt
/-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is
`K`-Lipschitz in a neighborhood of `x`. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x)
(K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by
have := hf.isLittleO.add_isBigOWith (f'.isBigOWith_comp _ _) hK
simp only [sub_add_cancel, IsBigOWith] at this
rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩
exact
⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩
/-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a
neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a
more precise statement. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) :
∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s :=
(exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt
/-- Directional derivative agrees with `HasFDeriv`. -/
theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α}
(hc : Tendsto (fun n => ‖c n‖) l atTop) :
Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by
refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_
intro U hU
refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_
convert mem_of_mem_nhds hU
dsimp only
rw [← mul_smul, mul_inv_cancel₀ hy, one_smul]
theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by
rw [← hasFDerivWithinAt_univ] at h₀ h₁
exact uniqueDiffWithinAt_univ.eq h₀ h₁
theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h]
theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict' s h]
theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x)
(ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by
simp only [HasFDerivWithinAt, nhdsWithin_union]
exact .of_isLittleOTVS <| hs.isLittleOTVS.sup ht.isLittleOTVS
theorem HasFDerivWithinAt.hasFDerivAt (h : HasFDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) :
HasFDerivAt f f' x := by
rwa [← univ_inter s, hasFDerivWithinAt_inter hs, hasFDerivWithinAt_univ] at h
theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x)
(hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x :=
h.imp fun _ hf' => hf'.hasFDerivAt hs
/-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
theorem HasFDerivWithinAt.of_not_accPt (h : ¬AccPt x (𝓟 s)) : HasFDerivWithinAt f f' s x := by
rw [accPt_principal_iff_nhdsWithin, not_neBot] at h
rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h,
hasFDerivAtFilter_iff_isLittleOTVS]
exact .bot
/-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
@[deprecated HasFDerivWithinAt.of_not_accPt (since := "2025-04-20")]
theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s \ {x}] x = ⊥) :
HasFDerivWithinAt f f' s x :=
.of_not_accPt <| by rwa [accPt_principal_iff_nhdsWithin, not_neBot]
/-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
theorem HasFDerivWithinAt.of_not_mem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x :=
.of_not_accPt (h ·.clusterPt.mem_closure)
@[deprecated (since := "2025-04-20")]
alias hasFDerivWithinAt_of_nmem_closure := HasFDerivWithinAt.of_not_mem_closure
theorem fderivWithin_zero_of_not_accPt (h : ¬AccPt x (𝓟 s)) : fderivWithin 𝕜 f s x = 0 := by
rw [fderivWithin, if_pos (.of_not_accPt h)]
set_option linter.deprecated false in
@[deprecated fderivWithin_zero_of_not_accPt (since := "2025-04-20")]
theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by
rw [fderivWithin, if_pos (.of_nhdsWithin_eq_bot h)]
theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 :=
fderivWithin_zero_of_not_accPt (h ·.clusterPt.mem_closure)
theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) :
HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by
simp only [fderivWithin, dif_pos h]
split_ifs with h₀
exacts [h₀, Classical.choose_spec h]
theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) :
HasFDerivAt f (fderiv 𝕜 f x) x := by
rw [fderiv, ← hasFDerivWithinAt_univ]
rw [← differentiableWithinAt_univ] at h
exact h.hasFDerivWithinAt
theorem DifferentiableOn.hasFDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
HasFDerivAt f (fderiv 𝕜 f x) x :=
((h x (mem_of_mem_nhds hs)).differentiableAt hs).hasFDerivAt
theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
DifferentiableAt 𝕜 f x :=
(h.hasFDerivAt hs).differentiableAt
theorem DifferentiableOn.eventually_differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
∀ᶠ y in 𝓝 x, DifferentiableAt 𝕜 f y :=
(eventually_eventually_nhds.2 hs).mono fun _ => h.differentiableAt
protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by
ext
rw [h.unique h.differentiableAt.hasFDerivAt]
theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' :=
funext fun x => (h x).fderiv
protected theorem HasFDerivWithinAt.fderivWithin (h : HasFDerivWithinAt f f' s x)
(hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = f' :=
(hxs.eq h h.differentiableWithinAt.hasFDerivWithinAt).symm
theorem DifferentiableWithinAt.mono (h : DifferentiableWithinAt 𝕜 f t x) (st : s ⊆ t) :
DifferentiableWithinAt 𝕜 f s x := by
rcases h with ⟨f', hf'⟩
exact ⟨f', hf'.mono st⟩
theorem DifferentiableWithinAt.mono_of_mem_nhdsWithin
(h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) :
DifferentiableWithinAt 𝕜 f t x :=
(h.hasFDerivWithinAt.mono_of_mem_nhdsWithin hst).differentiableWithinAt
@[deprecated (since := "2024-10-31")]
alias DifferentiableWithinAt.mono_of_mem := DifferentiableWithinAt.mono_of_mem_nhdsWithin
theorem DifferentiableWithinAt.congr_nhds (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E}
(hst : 𝓝[s] x = 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x :=
h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin
theorem differentiableWithinAt_congr_nhds {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) :
DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x :=
⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩
theorem differentiableWithinAt_inter (ht : t ∈ 𝓝 x) :
DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter ht]
theorem differentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) :
DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter' ht]
theorem differentiableWithinAt_insert_self :
DifferentiableWithinAt 𝕜 f (insert x s) x ↔ DifferentiableWithinAt 𝕜 f s x :=
⟨fun h ↦ h.mono (subset_insert x s), fun h ↦ h.hasFDerivWithinAt.insert.differentiableWithinAt⟩
theorem differentiableWithinAt_insert {y : E} :
DifferentiableWithinAt 𝕜 f (insert y s) x ↔ DifferentiableWithinAt 𝕜 f s x := by
rcases eq_or_ne x y with (rfl | h)
· exact differentiableWithinAt_insert_self
apply differentiableWithinAt_congr_nhds
exact nhdsWithin_insert_of_ne h
alias ⟨DifferentiableWithinAt.of_insert, DifferentiableWithinAt.insert'⟩ :=
differentiableWithinAt_insert
protected theorem DifferentiableWithinAt.insert (h : DifferentiableWithinAt 𝕜 f s x) :
DifferentiableWithinAt 𝕜 f (insert x s) x :=
h.insert'
theorem DifferentiableAt.differentiableWithinAt (h : DifferentiableAt 𝕜 f x) :
DifferentiableWithinAt 𝕜 f s x :=
(differentiableWithinAt_univ.2 h).mono (subset_univ _)
@[fun_prop]
theorem Differentiable.differentiableAt (h : Differentiable 𝕜 f) : DifferentiableAt 𝕜 f x :=
h x
protected theorem DifferentiableAt.fderivWithin (h : DifferentiableAt 𝕜 f x)
(hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x :=
h.hasFDerivAt.hasFDerivWithinAt.fderivWithin hxs
theorem DifferentiableOn.mono (h : DifferentiableOn 𝕜 f t) (st : s ⊆ t) : DifferentiableOn 𝕜 f s :=
fun x hx => (h x (st hx)).mono st
theorem differentiableOn_univ : DifferentiableOn 𝕜 f univ ↔ Differentiable 𝕜 f := by
simp only [DifferentiableOn, Differentiable, differentiableWithinAt_univ, mem_univ,
forall_true_left]
@[fun_prop]
theorem Differentiable.differentiableOn (h : Differentiable 𝕜 f) : DifferentiableOn 𝕜 f s :=
(differentiableOn_univ.2 h).mono (subset_univ _)
theorem differentiableOn_of_locally_differentiableOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ DifferentiableOn 𝕜 f (s ∩ u)) :
DifferentiableOn 𝕜 f s := by
intro x xs
rcases h x xs with ⟨t, t_open, xt, ht⟩
exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩)
theorem fderivWithin_of_mem_nhdsWithin (st : t ∈ 𝓝[s] x) (ht : UniqueDiffWithinAt 𝕜 s x)
(h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x :=
((DifferentiableWithinAt.hasFDerivWithinAt h).mono_of_mem_nhdsWithin st).fderivWithin ht
@[deprecated (since := "2024-10-31")]
alias fderivWithin_of_mem := fderivWithin_of_mem_nhdsWithin
theorem fderivWithin_subset (st : s ⊆ t) (ht : UniqueDiffWithinAt 𝕜 s x)
(h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x :=
fderivWithin_of_mem_nhdsWithin (nhdsWithin_mono _ st self_mem_nhdsWithin) ht h
theorem fderivWithin_inter (ht : t ∈ 𝓝 x) : fderivWithin 𝕜 f (s ∩ t) x = fderivWithin 𝕜 f s x := by
classical
simp [fderivWithin, hasFDerivWithinAt_inter ht, DifferentiableWithinAt]
theorem fderivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by
rw [← fderivWithin_univ, ← univ_inter s, fderivWithin_inter h]
theorem fderivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x :=
fderivWithin_of_mem_nhds (hs.mem_nhds hx)
theorem fderivWithin_eq_fderiv (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableAt 𝕜 f x) :
fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by
rw [← fderivWithin_univ]
exact fderivWithin_subset (subset_univ _) hs h.differentiableWithinAt
theorem fderiv_mem_iff {f : E → F} {s : Set (E →L[𝕜] F)} {x : E} : fderiv 𝕜 f x ∈ s ↔
DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s ∨ ¬DifferentiableAt 𝕜 f x ∧ (0 : E →L[𝕜] F) ∈ s := by
by_cases hx : DifferentiableAt 𝕜 f x <;> simp [fderiv_zero_of_not_differentiableAt, *]
theorem fderivWithin_mem_iff {f : E → F} {t : Set E} {s : Set (E →L[𝕜] F)} {x : E} :
fderivWithin 𝕜 f t x ∈ s ↔
DifferentiableWithinAt 𝕜 f t x ∧ fderivWithin 𝕜 f t x ∈ s ∨
¬DifferentiableWithinAt 𝕜 f t x ∧ (0 : E →L[𝕜] F) ∈ s := by
by_cases hx : DifferentiableWithinAt 𝕜 f t x <;>
simp [fderivWithin_zero_of_not_differentiableWithinAt, *]
theorem Asymptotics.IsBigO.hasFDerivWithinAt {s : Set E} {x₀ : E} {n : ℕ}
(h : f =O[𝓝[s] x₀] fun x => ‖x - x₀‖ ^ n) (hx₀ : x₀ ∈ s) (hn : 1 < n) :
HasFDerivWithinAt f (0 : E →L[𝕜] F) s x₀ := by
simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO,
h.eq_zero_of_norm_pow_within hx₀ hn.ne_bot, zero_apply, sub_zero,
h.trans_isLittleO ((isLittleO_pow_sub_sub x₀ hn).mono nhdsWithin_le_nhds)]
theorem Asymptotics.IsBigO.hasFDerivAt {x₀ : E} {n : ℕ} (h : f =O[𝓝 x₀] fun x => ‖x - x₀‖ ^ n)
(hn : 1 < n) : HasFDerivAt f (0 : E →L[𝕜] F) x₀ := by
rw [← nhdsWithin_univ] at h
exact (h.hasFDerivWithinAt (mem_univ _) hn).hasFDerivAt_of_univ
nonrec theorem HasFDerivWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E} {f' : E →L[𝕜] F}
(h : HasFDerivWithinAt f f' s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) :=
h.isBigO_sub
lemma DifferentiableWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E}
(h : DifferentiableWithinAt 𝕜 f s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) :=
h.hasFDerivWithinAt.isBigO_sub
nonrec theorem HasFDerivAt.isBigO_sub {f : E → F} {x₀ : E} {f' : E →L[𝕜] F}
(h : HasFDerivAt f f' x₀) : (f · - f x₀) =O[𝓝 x₀] (· - x₀) :=
h.isBigO_sub
nonrec theorem DifferentiableAt.isBigO_sub {f : E → F} {x₀ : E} (h : DifferentiableAt 𝕜 f x₀) :
(f · - f x₀) =O[𝓝 x₀] (· - x₀) :=
h.hasFDerivAt.isBigO_sub
end FDerivProperties
section Continuous
/-! ### Deducing continuity from differentiability -/
theorem HasFDerivAtFilter.tendsto_nhds (hL : L ≤ 𝓝 x) (h : HasFDerivAtFilter f f' x L) :
Tendsto f L (𝓝 (f x)) := by
have : Tendsto (fun x' => f x' - f x) L (𝓝 0) := by
refine h.isBigO_sub.trans_tendsto (Tendsto.mono_left ?_ hL)
rw [← sub_self x]
exact tendsto_id.sub tendsto_const_nhds
have := this.add (tendsto_const_nhds (x := f x))
rw [zero_add (f x)] at this
exact this.congr (by simp only [sub_add_cancel, eq_self_iff_true, forall_const])
theorem HasFDerivWithinAt.continuousWithinAt (h : HasFDerivWithinAt f f' s x) :
ContinuousWithinAt f s x :=
HasFDerivAtFilter.tendsto_nhds inf_le_left h
theorem HasFDerivAt.continuousAt (h : HasFDerivAt f f' x) : ContinuousAt f x :=
HasFDerivAtFilter.tendsto_nhds le_rfl h
@[fun_prop]
theorem DifferentiableWithinAt.continuousWithinAt (h : DifferentiableWithinAt 𝕜 f s x) :
ContinuousWithinAt f s x :=
let ⟨_, hf'⟩ := h
hf'.continuousWithinAt
@[fun_prop]
theorem DifferentiableAt.continuousAt (h : DifferentiableAt 𝕜 f x) : ContinuousAt f x :=
let ⟨_, hf'⟩ := h
hf'.continuousAt
@[fun_prop]
theorem DifferentiableOn.continuousOn (h : DifferentiableOn 𝕜 f s) : ContinuousOn f s := fun x hx =>
(h x hx).continuousWithinAt
@[fun_prop]
theorem Differentiable.continuous (h : Differentiable 𝕜 f) : Continuous f :=
continuous_iff_continuousAt.2 fun x => (h x).continuousAt
protected theorem HasStrictFDerivAt.continuousAt (hf : HasStrictFDerivAt f f' x) :
ContinuousAt f x :=
hf.hasFDerivAt.continuousAt
theorem HasStrictFDerivAt.isBigO_sub_rev {f' : E ≃L[𝕜] F}
(hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) x) :
(fun p : E × E => p.1 - p.2) =O[𝓝 (x, x)] fun p : E × E => f p.1 - f p.2 :=
((f'.isBigO_comp_rev _ _).trans
(hf.isLittleO.trans_isBigO (f'.isBigO_comp_rev _ _)).right_isBigO_add).congr
(fun _ => rfl) fun _ => sub_add_cancel _ _
|
theorem HasFDerivAtFilter.isBigO_sub_rev (hf : HasFDerivAtFilter f f' x L) {C}
(hf' : AntilipschitzWith C f') : (fun x' => x' - x) =O[L] fun x' => f x' - f x :=
have : (fun x' => x' - x) =O[L] fun x' => f' (x' - x) :=
isBigO_iff.2 ⟨C, Eventually.of_forall fun _ => ZeroHomClass.bound_of_antilipschitz f' hf' _⟩
(this.trans (hf.isLittleO.trans_isBigO this).right_isBigO_add).congr (fun _ => rfl) fun _ =>
sub_add_cancel _ _
end Continuous
| Mathlib/Analysis/Calculus/FDeriv/Basic.lean | 780 | 788 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono
import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi
import Mathlib.CategoryTheory.MorphismProperty.Factorization
/-!
# Categorical images
We define the categorical image of `f` as a factorisation `f = e ≫ m` through a monomorphism `m`,
so that `m` factors through the `m'` in any other such factorisation.
## Main definitions
* A `MonoFactorisation` is a factorisation `f = e ≫ m`, where `m` is a monomorphism
* `IsImage F` means that a given mono factorisation `F` has the universal property of the image.
* `HasImage f` means that there is some image factorization for the morphism `f : X ⟶ Y`.
* In this case, `image f` is some image object (selected with choice), `image.ι f : image f ⟶ Y`
is the monomorphism `m` of the factorisation and `factorThruImage f : X ⟶ image f` is the
morphism `e`.
* `HasImages C` means that every morphism in `C` has an image.
* Let `f : X ⟶ Y` and `g : P ⟶ Q` be morphisms in `C`, which we will represent as objects of the
arrow category `Arrow C`. Then `sq : f ⟶ g` is a commutative square in `C`. If `f` and `g` have
images, then `HasImageMap sq` represents the fact that there is a morphism
`i : image f ⟶ image g` making the diagram
X ----→ image f ----→ Y
| | |
| | |
↓ ↓ ↓
P ----→ image g ----→ Q
commute, where the top row is the image factorisation of `f`, the bottom row is the image
factorisation of `g`, and the outer rectangle is the commutative square `sq`.
* If a category `HasImages`, then `HasImageMaps` means that every commutative square admits an
image map.
* If a category `HasImages`, then `HasStrongEpiImages` means that the morphism to the image is
always a strong epimorphism.
## Main statements
* When `C` has equalizers, the morphism `e` appearing in an image factorisation is an epimorphism.
* When `C` has strong epi images, then these images admit image maps.
## Future work
* TODO: coimages, and abelian categories.
* TODO: connect this with existing working in the group theory and ring theory libraries.
-/
noncomputable section
universe v u
open CategoryTheory
open CategoryTheory.Limits.WalkingParallelPair
namespace CategoryTheory.Limits
variable {C : Type u} [Category.{v} C]
variable {X Y : C} (f : X ⟶ Y)
/-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/
structure MonoFactorisation (f : X ⟶ Y) where
I : C -- Porting note: violates naming conventions but can't think a better replacement
m : I ⟶ Y
[m_mono : Mono m]
e : X ⟶ I
fac : e ≫ m = f := by aesop_cat
attribute [inherit_doc MonoFactorisation] MonoFactorisation.I MonoFactorisation.m
MonoFactorisation.m_mono MonoFactorisation.e MonoFactorisation.fac
attribute [reassoc (attr := simp)] MonoFactorisation.fac
attribute [instance] MonoFactorisation.m_mono
namespace MonoFactorisation
/-- The obvious factorisation of a monomorphism through itself. -/
def self [Mono f] : MonoFactorisation f where
I := X
m := f
e := 𝟙 X
-- I'm not sure we really need this, but the linter says that an inhabited instance
-- ought to exist...
instance [Mono f] : Inhabited (MonoFactorisation f) := ⟨self f⟩
variable {f}
/-- The morphism `m` in a factorisation `f = e ≫ m` through a monomorphism is uniquely
determined. -/
@[ext (iff := false)]
theorem ext {F F' : MonoFactorisation f} (hI : F.I = F'.I)
(hm : F.m = eqToHom hI ≫ F'.m) : F = F' := by
obtain ⟨_, Fm, _, Ffac⟩ := F; obtain ⟨_, Fm', _, Ffac'⟩ := F'
cases hI
simp? at hm says simp only [eqToHom_refl, Category.id_comp] at hm
congr
apply (cancel_mono Fm).1
rw [Ffac, hm, Ffac']
/-- Any mono factorisation of `f` gives a mono factorisation of `f ≫ g` when `g` is a mono. -/
@[simps]
def compMono (F : MonoFactorisation f) {Y' : C} (g : Y ⟶ Y') [Mono g] :
MonoFactorisation (f ≫ g) where
I := F.I
m := F.m ≫ g
m_mono := mono_comp _ _
e := F.e
/-- A mono factorisation of `f ≫ g`, where `g` is an isomorphism,
gives a mono factorisation of `f`. -/
@[simps]
def ofCompIso {Y' : C} {g : Y ⟶ Y'} [IsIso g] (F : MonoFactorisation (f ≫ g)) :
MonoFactorisation f where
I := F.I
m := F.m ≫ inv g
m_mono := mono_comp _ _
e := F.e
/-- Any mono factorisation of `f` gives a mono factorisation of `g ≫ f`. -/
@[simps]
def isoComp (F : MonoFactorisation f) {X' : C} (g : X' ⟶ X) : MonoFactorisation (g ≫ f) where
I := F.I
m := F.m
e := g ≫ F.e
/-- A mono factorisation of `g ≫ f`, where `g` is an isomorphism,
gives a mono factorisation of `f`. -/
@[simps]
def ofIsoComp {X' : C} (g : X' ⟶ X) [IsIso g] (F : MonoFactorisation (g ≫ f)) :
MonoFactorisation f where
I := F.I
m := F.m
e := inv g ≫ F.e
/-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f`
gives a mono factorisation of `g` -/
@[simps]
def ofArrowIso {f g : Arrow C} (F : MonoFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] :
MonoFactorisation g.hom where
I := F.I
m := F.m ≫ sq.right
e := inv sq.left ≫ F.e
m_mono := mono_comp _ _
fac := by simp only [fac_assoc, Arrow.w, IsIso.inv_comp_eq, Category.assoc]
end MonoFactorisation
variable {f}
/-- Data exhibiting that a given factorisation through a mono is initial. -/
structure IsImage (F : MonoFactorisation f) where
lift : ∀ F' : MonoFactorisation f, F.I ⟶ F'.I
lift_fac : ∀ F' : MonoFactorisation f, lift F' ≫ F'.m = F.m := by aesop_cat
attribute [inherit_doc IsImage] IsImage.lift IsImage.lift_fac
attribute [reassoc (attr := simp)] IsImage.lift_fac
namespace IsImage
@[reassoc (attr := simp)]
theorem fac_lift {F : MonoFactorisation f} (hF : IsImage F) (F' : MonoFactorisation f) :
F.e ≫ hF.lift F' = F'.e :=
(cancel_mono F'.m).1 <| by simp
variable (f)
/-- The trivial factorisation of a monomorphism satisfies the universal property. -/
@[simps]
def self [Mono f] : IsImage (MonoFactorisation.self f) where lift F' := F'.e
instance [Mono f] : Inhabited (IsImage (MonoFactorisation.self f)) :=
⟨self f⟩
variable {f}
| -- TODO this is another good candidate for a future `UniqueUpToCanonicalIso`.
/-- Two factorisations through monomorphisms satisfying the universal property
must factor through isomorphic objects. -/
| Mathlib/CategoryTheory/Limits/Shapes/Images.lean | 187 | 189 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent
import Mathlib.Analysis.Calculus.FDeriv.Linear
import Mathlib.Analysis.Calculus.FDeriv.Comp
/-!
# The derivative of a linear equivalence
For detailed documentation of the Fréchet derivative,
see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`.
This file contains the usual formulas (and existence assertions) for the derivative of
continuous linear equivalences.
We also prove the usual formula for the derivative of the inverse function, assuming it exists.
The inverse function theorem is in `Mathlib/Analysis/Calculus/InverseFunctionTheorem/FDeriv.lean`.
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G']
variable {f : E → F} {f' : E →L[𝕜] F} {x : E} {s : Set E} {c : F}
namespace ContinuousLinearEquiv
/-! ### Differentiability of linear equivs, and invariance of differentiability -/
variable (iso : E ≃L[𝕜] F)
@[fun_prop]
protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x :=
iso.toContinuousLinearMap.hasStrictFDerivAt
@[fun_prop]
protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x :=
iso.toContinuousLinearMap.hasFDerivWithinAt
@[fun_prop]
protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x :=
iso.toContinuousLinearMap.hasFDerivAtFilter
@[fun_prop]
protected theorem differentiableAt : DifferentiableAt 𝕜 iso x :=
iso.hasFDerivAt.differentiableAt
@[fun_prop]
protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x :=
iso.differentiableAt.differentiableWithinAt
protected theorem fderiv : fderiv 𝕜 iso x = iso :=
iso.hasFDerivAt.fderiv
protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso :=
iso.toContinuousLinearMap.fderivWithin hxs
@[fun_prop]
protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt
@[fun_prop]
protected theorem differentiableOn : DifferentiableOn 𝕜 iso s :=
iso.differentiable.differentiableOn
theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} :
DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x := by
refine
⟨fun H => ?_, fun H => iso.differentiable.differentiableAt.comp_differentiableWithinAt x H⟩
have : DifferentiableWithinAt 𝕜 (iso.symm ∘ iso ∘ f) s x :=
iso.symm.differentiable.differentiableAt.comp_differentiableWithinAt x H
rwa [← Function.comp_assoc iso.symm iso f, iso.symm_comp_self] at this
theorem comp_differentiableAt_iff {f : G → E} {x : G} :
DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x := by
rw [← differentiableWithinAt_univ, ← differentiableWithinAt_univ,
iso.comp_differentiableWithinAt_iff]
theorem comp_differentiableOn_iff {f : G → E} {s : Set G} :
DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s := by
rw [DifferentiableOn, DifferentiableOn]
simp only [iso.comp_differentiableWithinAt_iff]
theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f := by
rw [← differentiableOn_univ, ← differentiableOn_univ]
exact iso.comp_differentiableOn_iff
theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} :
HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x := by
refine ⟨fun H => ?_, fun H => iso.hasFDerivAt.comp_hasFDerivWithinAt x H⟩
have A : f = iso.symm ∘ iso ∘ f := by
rw [← Function.comp_assoc, iso.symm_comp_self]
rfl
have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f') := by
rw [← ContinuousLinearMap.comp_assoc, iso.coe_symm_comp_coe, ContinuousLinearMap.id_comp]
rw [A, B]
exact iso.symm.hasFDerivAt.comp_hasFDerivWithinAt x H
theorem comp_hasStrictFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasStrictFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasStrictFDerivAt f f' x := by
refine ⟨fun H => ?_, fun H => iso.hasStrictFDerivAt.comp x H⟩
convert iso.symm.hasStrictFDerivAt.comp x H using 1 <;>
ext z <;> apply (iso.symm_apply_apply _).symm
theorem comp_hasFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasFDerivAt f f' x := by
simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff]
theorem comp_hasFDerivWithinAt_iff' {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] F} :
HasFDerivWithinAt (iso ∘ f) f' s x ↔
HasFDerivWithinAt f ((iso.symm : F →L[𝕜] E).comp f') s x := by
rw [← iso.comp_hasFDerivWithinAt_iff, ← ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm,
ContinuousLinearMap.id_comp]
theorem comp_hasFDerivAt_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
HasFDerivAt (iso ∘ f) f' x ↔ HasFDerivAt f ((iso.symm : F →L[𝕜] E).comp f') x := by
simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff']
theorem comp_fderivWithin {f : G → E} {s : Set G} {x : G} (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderivWithin 𝕜 f s x) := by
by_cases h : DifferentiableWithinAt 𝕜 f s x
· rw [fderiv_comp_fderivWithin x iso.differentiableAt h hxs, iso.fderiv]
· have : ¬DifferentiableWithinAt 𝕜 (iso ∘ f) s x := mt iso.comp_differentiableWithinAt_iff.1 h
rw [fderivWithin_zero_of_not_differentiableWithinAt h,
fderivWithin_zero_of_not_differentiableWithinAt this, ContinuousLinearMap.comp_zero]
theorem comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := by
rw [← fderivWithin_univ, ← fderivWithin_univ]
exact iso.comp_fderivWithin uniqueDiffWithinAt_univ
lemma _root_.fderivWithin_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G))
(hs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) s x =
(((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderivWithin 𝕜 f s x) := by
change fderivWithin 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) s x = _
rw [ContinuousLinearEquiv.comp_fderivWithin _ hs]
lemma _root_.fderiv_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) (x : E) :
fderiv 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) x =
(((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by
change fderiv 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) x = _
rw [ContinuousLinearEquiv.comp_fderiv]
lemma _root_.fderiv_continuousLinearEquiv_comp' (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) :
fderiv 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) =
fun x ↦ (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by
ext x : 1
exact fderiv_continuousLinearEquiv_comp L f x
theorem comp_right_differentiableWithinAt_iff {f : F → G} {s : Set F} {x : E} :
DifferentiableWithinAt 𝕜 (f ∘ iso) (iso ⁻¹' s) x ↔ DifferentiableWithinAt 𝕜 f s (iso x) := by
refine ⟨fun H => ?_, fun H => H.comp x iso.differentiableWithinAt (mapsTo_preimage _ s)⟩
have : DifferentiableWithinAt 𝕜 ((f ∘ iso) ∘ iso.symm) s (iso x) := by
rw [← iso.symm_apply_apply x] at H
apply H.comp (iso x) iso.symm.differentiableWithinAt
intro y hy
simpa only [mem_preimage, apply_symm_apply] using hy
rwa [Function.comp_assoc, iso.self_comp_symm] at this
theorem comp_right_differentiableAt_iff {f : F → G} {x : E} :
DifferentiableAt 𝕜 (f ∘ iso) x ↔ DifferentiableAt 𝕜 f (iso x) := by
simp only [← differentiableWithinAt_univ, ← iso.comp_right_differentiableWithinAt_iff,
preimage_univ]
theorem comp_right_differentiableOn_iff {f : F → G} {s : Set F} :
DifferentiableOn 𝕜 (f ∘ iso) (iso ⁻¹' s) ↔ DifferentiableOn 𝕜 f s := by
refine ⟨fun H y hy => ?_, fun H y hy => iso.comp_right_differentiableWithinAt_iff.2 (H _ hy)⟩
rw [← iso.apply_symm_apply y, ← comp_right_differentiableWithinAt_iff]
apply H
simpa only [mem_preimage, apply_symm_apply] using hy
theorem comp_right_differentiable_iff {f : F → G} :
Differentiable 𝕜 (f ∘ iso) ↔ Differentiable 𝕜 f := by
simp only [← differentiableOn_univ, ← iso.comp_right_differentiableOn_iff, preimage_univ]
theorem comp_right_hasFDerivWithinAt_iff {f : F → G} {s : Set F} {x : E} {f' : F →L[𝕜] G} :
HasFDerivWithinAt (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) (iso ⁻¹' s) x ↔
HasFDerivWithinAt f f' s (iso x) := by
refine ⟨fun H => ?_, fun H => H.comp x iso.hasFDerivWithinAt (mapsTo_preimage _ s)⟩
rw [← iso.symm_apply_apply x] at H
have A : f = (f ∘ iso) ∘ iso.symm := by
rw [Function.comp_assoc, iso.self_comp_symm]
rfl
have B : f' = (f'.comp (iso : E →L[𝕜] F)).comp (iso.symm : F →L[𝕜] E) := by
rw [ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm, ContinuousLinearMap.comp_id]
rw [A, B]
apply H.comp (iso x) iso.symm.hasFDerivWithinAt
intro y hy
simpa only [mem_preimage, apply_symm_apply] using hy
theorem comp_right_hasFDerivAt_iff {f : F → G} {x : E} {f' : F →L[𝕜] G} :
HasFDerivAt (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) x ↔ HasFDerivAt f f' (iso x) := by
simp only [← hasFDerivWithinAt_univ, ← comp_right_hasFDerivWithinAt_iff, preimage_univ]
theorem comp_right_hasFDerivWithinAt_iff' {f : F → G} {s : Set F} {x : E} {f' : E →L[𝕜] G} :
HasFDerivWithinAt (f ∘ iso) f' (iso ⁻¹' s) x ↔
HasFDerivWithinAt f (f'.comp (iso.symm : F →L[𝕜] E)) s (iso x) := by
rw [← iso.comp_right_hasFDerivWithinAt_iff, ContinuousLinearMap.comp_assoc,
iso.coe_symm_comp_coe, ContinuousLinearMap.comp_id]
theorem comp_right_hasFDerivAt_iff' {f : F → G} {x : E} {f' : E →L[𝕜] G} :
HasFDerivAt (f ∘ iso) f' x ↔ HasFDerivAt f (f'.comp (iso.symm : F →L[𝕜] E)) (iso x) := by
simp only [← hasFDerivWithinAt_univ, ← iso.comp_right_hasFDerivWithinAt_iff', preimage_univ]
theorem comp_right_fderivWithin {f : F → G} {s : Set F} {x : E}
(hxs : UniqueDiffWithinAt 𝕜 (iso ⁻¹' s) x) :
fderivWithin 𝕜 (f ∘ iso) (iso ⁻¹' s) x =
(fderivWithin 𝕜 f s (iso x)).comp (iso : E →L[𝕜] F) := by
by_cases h : DifferentiableWithinAt 𝕜 f s (iso x)
· exact (iso.comp_right_hasFDerivWithinAt_iff.2 h.hasFDerivWithinAt).fderivWithin hxs
· have : ¬DifferentiableWithinAt 𝕜 (f ∘ iso) (iso ⁻¹' s) x := by
intro h'
exact h (iso.comp_right_differentiableWithinAt_iff.1 h')
rw [fderivWithin_zero_of_not_differentiableWithinAt h,
fderivWithin_zero_of_not_differentiableWithinAt this, ContinuousLinearMap.zero_comp]
theorem comp_right_fderiv {f : F → G} {x : E} :
fderiv 𝕜 (f ∘ iso) x = (fderiv 𝕜 f (iso x)).comp (iso : E →L[𝕜] F) := by
rw [← fderivWithin_univ, ← fderivWithin_univ, ← iso.comp_right_fderivWithin, preimage_univ]
exact uniqueDiffWithinAt_univ
end ContinuousLinearEquiv
namespace LinearIsometryEquiv
/-! ### Differentiability of linear isometry equivs, and invariance of differentiability -/
variable (iso : E ≃ₗᵢ[𝕜] F)
@[fun_prop]
protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x :=
(iso : E ≃L[𝕜] F).hasStrictFDerivAt
@[fun_prop]
protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x :=
(iso : E ≃L[𝕜] F).hasFDerivWithinAt
@[fun_prop]
protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x :=
(iso : E ≃L[𝕜] F).hasFDerivAt
@[fun_prop]
protected theorem differentiableAt : DifferentiableAt 𝕜 iso x :=
iso.hasFDerivAt.differentiableAt
@[fun_prop]
protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x :=
iso.differentiableAt.differentiableWithinAt
protected theorem fderiv : fderiv 𝕜 iso x = iso :=
iso.hasFDerivAt.fderiv
protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso :=
(iso : E ≃L[𝕜] F).fderivWithin hxs
@[fun_prop]
protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt
@[fun_prop]
protected theorem differentiableOn : DifferentiableOn 𝕜 iso s :=
iso.differentiable.differentiableOn
theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} :
DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x :=
(iso : E ≃L[𝕜] F).comp_differentiableWithinAt_iff
theorem comp_differentiableAt_iff {f : G → E} {x : G} :
DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x :=
(iso : E ≃L[𝕜] F).comp_differentiableAt_iff
theorem comp_differentiableOn_iff {f : G → E} {s : Set G} :
DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s :=
(iso : E ≃L[𝕜] F).comp_differentiableOn_iff
theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f :=
(iso : E ≃L[𝕜] F).comp_differentiable_iff
theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} :
HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x :=
(iso : E ≃L[𝕜] F).comp_hasFDerivWithinAt_iff
theorem comp_hasStrictFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasStrictFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasStrictFDerivAt f f' x :=
(iso : E ≃L[𝕜] F).comp_hasStrictFDerivAt_iff
theorem comp_hasFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasFDerivAt f f' x :=
(iso : E ≃L[𝕜] F).comp_hasFDerivAt_iff
theorem comp_hasFDerivWithinAt_iff' {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] F} :
HasFDerivWithinAt (iso ∘ f) f' s x ↔ HasFDerivWithinAt f ((iso.symm : F →L[𝕜] E).comp f') s x :=
(iso : E ≃L[𝕜] F).comp_hasFDerivWithinAt_iff'
theorem comp_hasFDerivAt_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
HasFDerivAt (iso ∘ f) f' x ↔ HasFDerivAt f ((iso.symm : F →L[𝕜] E).comp f') x :=
(iso : E ≃L[𝕜] F).comp_hasFDerivAt_iff'
theorem comp_fderivWithin {f : G → E} {s : Set G} {x : G} (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderivWithin 𝕜 f s x) :=
(iso : E ≃L[𝕜] F).comp_fderivWithin hxs
theorem comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) :=
(iso : E ≃L[𝕜] F).comp_fderiv
theorem comp_fderiv' {f : G → E} :
fderiv 𝕜 (iso ∘ f) = fun x ↦ (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := by
ext x : 1
exact LinearIsometryEquiv.comp_fderiv iso
end LinearIsometryEquiv
/-- If `f (g y) = y` for `y` in a neighborhood of `a` within `t`,
`g` maps a neighborhood of `a` within `t` to a neighborhood of `g a` within `s`,
and `f` has an invertible derivative `f'` at `g a` within `s`,
then `g` has the derivative `f'⁻¹` at `a` within `t`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have an
inverse function. -/
theorem HasFDerivWithinAt.of_local_left_inverse {g : F → E} {f' : E ≃L[𝕜] F} {a : F} {t : Set F}
(hg : Tendsto g (𝓝[t] a) (𝓝[s] (g a))) (hf : HasFDerivWithinAt f (f' : E →L[𝕜] F) s (g a))
(ha : a ∈ t) (hfg : ∀ᶠ y in 𝓝[t] a, f (g y) = y) :
HasFDerivWithinAt g (f'.symm : F →L[𝕜] E) t a := by
have : (fun x : F => g x - g a - f'.symm (x - a)) =O[𝓝[t] a]
fun x : F => f' (g x - g a) - (x - a) :=
((f'.symm : F →L[𝕜] E).isBigO_comp _ _).congr (fun x ↦ by simp) fun _ ↦ rfl
refine .of_isLittleO <| this.trans_isLittleO ?_
clear this
refine ((hf.isLittleO.comp_tendsto hg).symm.congr' (hfg.mono ?_) .rfl).trans_isBigO ?_
· intro p hp
simp [hp, hfg.self_of_nhdsWithin ha]
· refine ((hf.isBigO_sub_rev f'.antilipschitz).comp_tendsto hg).congr'
(Eventually.of_forall fun _ => rfl) (hfg.mono ?_)
rintro p hp
simp only [(· ∘ ·), hp, hfg.self_of_nhdsWithin ha]
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a`
in the strict sense.
This is one of the easy parts of the inverse function theorem: it assumes that we already have an
inverse function. -/
theorem HasStrictFDerivAt.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}
(hg : ContinuousAt g a) (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) (g a))
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasStrictFDerivAt g (f'.symm : F →L[𝕜] E) a := by
replace hg := hg.prodMap' hg
replace hfg := hfg.prodMk_nhds hfg
have :
(fun p : F × F => g p.1 - g p.2 - f'.symm (p.1 - p.2)) =O[𝓝 (a, a)] fun p : F × F =>
f' (g p.1 - g p.2) - (p.1 - p.2) := by
refine ((f'.symm : F →L[𝕜] E).isBigO_comp _ _).congr (fun x => ?_) fun _ => rfl
simp
refine .of_isLittleO <| this.trans_isLittleO ?_
clear this
refine ((hf.isLittleO.comp_tendsto hg).symm.congr'
(hfg.mono ?_) (Eventually.of_forall fun _ => rfl)).trans_isBigO ?_
· rintro p ⟨hp1, hp2⟩
simp [hp1, hp2]
· refine (hf.isBigO_sub_rev.comp_tendsto hg).congr' (Eventually.of_forall fun _ => rfl)
(hfg.mono ?_)
rintro p ⟨hp1, hp2⟩
simp only [(· ∘ ·), hp1, hp2, Prod.map]
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem HasFDerivAt.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}
(hg : ContinuousAt g a) (hf : HasFDerivAt f (f' : E →L[𝕜] F) (g a))
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasFDerivAt g (f'.symm : F →L[𝕜] E) a := by
simp only [← hasFDerivWithinAt_univ, ← nhdsWithin_univ] at hf hfg ⊢
exact hf.of_local_left_inverse (.inf hg (by simp)) (mem_univ _) hfg
/-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
invertible derivative `f'` in the sense of strict differentiability at `f.symm a`, then `f.symm` has
the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem PartialHomeomorph.hasStrictFDerivAt_symm (f : PartialHomeomorph E F) {f' : E ≃L[𝕜] F}
{a : F} (ha : a ∈ f.target) (htff' : HasStrictFDerivAt f (f' : E →L[𝕜] F) (f.symm a)) :
HasStrictFDerivAt f.symm (f'.symm : F →L[𝕜] E) a :=
htff'.of_local_left_inverse (f.symm.continuousAt ha) (f.eventually_right_inverse ha)
/-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
invertible derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem PartialHomeomorph.hasFDerivAt_symm (f : PartialHomeomorph E F) {f' : E ≃L[𝕜] F} {a : F}
(ha : a ∈ f.target) (htff' : HasFDerivAt f (f' : E →L[𝕜] F) (f.symm a)) :
HasFDerivAt f.symm (f'.symm : F →L[𝕜] E) a :=
htff'.of_local_left_inverse (f.symm.continuousAt ha) (f.eventually_right_inverse ha)
theorem HasFDerivWithinAt.eventually_ne (h : HasFDerivWithinAt f f' s x)
(hf' : ∃ C, ∀ z, ‖z‖ ≤ C * ‖f' z‖) : ∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ c := by
rcases eq_or_ne (f x) c with rfl | hc
· rw [nhdsWithin, diff_eq, ← inf_principal, ← inf_assoc, eventually_inf_principal]
have A : (fun z => z - x) =O[𝓝[s] x] fun z => f' (z - x) :=
isBigO_iff.2 <| hf'.imp fun C hC => Eventually.of_forall fun z => hC _
have : (fun z => f z - f x) ~[𝓝[s] x] fun z => f' (z - x) := h.isLittleO.trans_isBigO A
simpa [not_imp_not, sub_eq_zero] using (A.trans this.isBigO_symm).eq_zero_imp
· exact (h.continuousWithinAt.eventually_ne hc).filter_mono <| by gcongr; apply diff_subset
theorem HasFDerivAt.eventually_ne (h : HasFDerivAt f f' x) (hf' : ∃ C, ∀ z, ‖z‖ ≤ C * ‖f' z‖) :
∀ᶠ z in 𝓝[≠] x, f z ≠ c := by
simpa only [compl_eq_univ_diff] using (hasFDerivWithinAt_univ.2 h).eventually_ne hf'
end
section
/-
In the special case of a normed space over the reals,
we can use scalar multiplication in the `tendsto` characterization
of the Fréchet derivative.
-/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
variable {f : E → F} {f' : E →L[ℝ] F} {x : E}
theorem has_fderiv_at_filter_real_equiv {L : Filter E} :
Tendsto (fun x' : E => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) ↔
Tendsto (fun x' : E => ‖x' - x‖⁻¹ • (f x' - f x - f' (x' - x))) L (𝓝 0) := by
symm
rw [tendsto_iff_norm_sub_tendsto_zero]
refine tendsto_congr fun x' => ?_
simp [norm_smul]
theorem HasFDerivAt.lim_real (hf : HasFDerivAt f f' x) (v : E) :
Tendsto (fun c : ℝ => c • (f (x + c⁻¹ • v) - f x)) atTop (𝓝 (f' v)) := by
apply hf.lim v
rw [tendsto_atTop_atTop]
exact fun b => ⟨b, fun a ha => le_trans ha (le_abs_self _)⟩
end
section TangentCone
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {f : E → F} {s : Set E}
{f' : E →L[𝕜] F}
/-- The image of a tangent cone under the differential of a map is included in the tangent cone to
the image. -/
theorem HasFDerivWithinAt.mapsTo_tangent_cone {x : E} (h : HasFDerivWithinAt f f' s x) :
MapsTo f' (tangentConeAt 𝕜 s x) (tangentConeAt 𝕜 (f '' s) (f x)) := by
rintro v ⟨c, d, dtop, clim, cdlim⟩
refine
⟨c, fun n => f (x + d n) - f x, mem_of_superset dtop ?_, clim, h.lim atTop dtop clim cdlim⟩
simp +contextual [-mem_image, mem_image_of_mem]
/-- If a set has the unique differentiability property at a point x, then the image of this set
under a map with onto derivative has also the unique differentiability property at the image point.
-/
theorem HasFDerivWithinAt.uniqueDiffWithinAt {x : E} (h : HasFDerivWithinAt f f' s x)
(hs : UniqueDiffWithinAt 𝕜 s x) (h' : DenseRange f') : UniqueDiffWithinAt 𝕜 (f '' s) (f x) := by
refine ⟨h'.dense_of_mapsTo f'.continuous hs.1 ?_, h.continuousWithinAt.mem_closure_image hs.2⟩
show
Submodule.span 𝕜 (tangentConeAt 𝕜 s x) ≤
(Submodule.span 𝕜 (tangentConeAt 𝕜 (f '' s) (f x))).comap f'
rw [Submodule.span_le]
exact h.mapsTo_tangent_cone.mono Subset.rfl Submodule.subset_span
theorem UniqueDiffOn.image {f' : E → E →L[𝕜] F} (hs : UniqueDiffOn 𝕜 s)
(hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hd : ∀ x ∈ s, DenseRange (f' x)) :
UniqueDiffOn 𝕜 (f '' s) :=
forall_mem_image.2 fun x hx => (hf' x hx).uniqueDiffWithinAt (hs x hx) (hd x hx)
theorem HasFDerivWithinAt.uniqueDiffWithinAt_of_continuousLinearEquiv {x : E} (e' : E ≃L[𝕜] F)
(h : HasFDerivWithinAt f (e' : E →L[𝕜] F) s x) (hs : UniqueDiffWithinAt 𝕜 s x) :
UniqueDiffWithinAt 𝕜 (f '' s) (f x) :=
h.uniqueDiffWithinAt hs e'.surjective.denseRange
theorem ContinuousLinearEquiv.uniqueDiffOn_image (e : E ≃L[𝕜] F) (h : UniqueDiffOn 𝕜 s) :
UniqueDiffOn 𝕜 (e '' s) :=
h.image (fun _ _ => e.hasFDerivWithinAt) fun _ _ => e.surjective.denseRange
@[simp]
theorem ContinuousLinearEquiv.uniqueDiffOn_image_iff (e : E ≃L[𝕜] F) :
UniqueDiffOn 𝕜 (e '' s) ↔ UniqueDiffOn 𝕜 s :=
| ⟨fun h => e.symm_image_image s ▸ e.symm.uniqueDiffOn_image h, e.uniqueDiffOn_image⟩
@[simp]
theorem ContinuousLinearEquiv.uniqueDiffOn_preimage_iff (e : F ≃L[𝕜] E) :
UniqueDiffOn 𝕜 (e ⁻¹' s) ↔ UniqueDiffOn 𝕜 s := by
| Mathlib/Analysis/Calculus/FDeriv/Equiv.lean | 495 | 499 |
/-
Copyright (c) 2024 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul Lezeau, Calle Sönne
-/
import Mathlib.CategoryTheory.FiberedCategory.HomLift
import Mathlib.CategoryTheory.Bicategory.Strict
import Mathlib.CategoryTheory.Functor.Category
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic
/-!
# The bicategory of based categories
In this file we define the type `BasedCategory 𝒮`, and give it the structure of a strict
bicategory. Given a category `𝒮`, we define the type `BasedCategory 𝒮` as the type of categories
`𝒳` equipped with a functor `𝒳.p : 𝒳 ⥤ 𝒮`.
We also define a type of functors between based categories `𝒳` and `𝒴`, which we call
`BasedFunctor 𝒳 𝒴` and denote as `𝒳 ⥤ᵇ 𝒴`. These are defined as functors between the underlying
categories `𝒳.obj` and `𝒴.obj` which commute with the projections to `𝒮`.
Natural transformations between based functors `F G : 𝒳 ⥤ᵇ 𝒴 ` are given by the structure
`BasedNatTrans F G`. These are defined as natural transformations `α` between the functors
underlying `F` and `G` such that `α.app a` lifts `𝟙 S` whenever `𝒳.p.obj a = S`.
-/
universe v₅ u₅ v₄ u₄ v₃ u₃ v₂ u₂ v₁ u₁
namespace CategoryTheory
open Functor Category NatTrans IsHomLift
variable {𝒮 : Type u₁} [Category.{v₁} 𝒮]
/-- A based category over `𝒮` is a category `𝒳` together with a functor `p : 𝒳 ⥤ 𝒮`. -/
@[nolint checkUnivs]
structure BasedCategory (𝒮 : Type u₁) [Category.{v₁} 𝒮] where
/-- The type of objects in a `BasedCategory` -/
obj : Type u₂
/-- The underlying category of a `BasedCategory`. -/
category : Category.{v₂} obj := by infer_instance
/-- The functor to the base. -/
p : obj ⥤ 𝒮
instance (𝒳 : BasedCategory.{v₂, u₂} 𝒮) : Category 𝒳.obj := 𝒳.category
/-- The based category associated to a functor `p : 𝒳 ⥤ 𝒮`. -/
def BasedCategory.ofFunctor {𝒳 : Type u₂} [Category.{v₂} 𝒳] (p : 𝒳 ⥤ 𝒮) : BasedCategory 𝒮 where
obj := 𝒳
p := p
/-- A functor between based categories is a functor between the underlying categories that commutes
with the projections. -/
structure BasedFunctor (𝒳 : BasedCategory.{v₂, u₂} 𝒮) (𝒴 : BasedCategory.{v₃, u₃} 𝒮) extends
𝒳.obj ⥤ 𝒴.obj where
w : toFunctor ⋙ 𝒴.p = 𝒳.p := by aesop_cat
/-- Notation for `BasedFunctor`. -/
scoped infixr:26 " ⥤ᵇ " => BasedFunctor
namespace BasedFunctor
initialize_simps_projections BasedFunctor (+toFunctor, -obj, -map)
/-- The identity based functor. -/
@[simps]
def id (𝒳 : BasedCategory.{v₂, u₂} 𝒮) : 𝒳 ⥤ᵇ 𝒳 where
toFunctor := 𝟭 𝒳.obj
variable {𝒳 : BasedCategory.{v₂, u₂} 𝒮} {𝒴 : BasedCategory.{v₃, u₃} 𝒮}
/-- Notation for the identity functor on a based category. -/
scoped notation "𝟭" => BasedFunctor.id
/-- The composition of two based functors. -/
@[simps]
def comp {𝒵 : BasedCategory.{v₄, u₄} 𝒮} (F : 𝒳 ⥤ᵇ 𝒴) (G : 𝒴 ⥤ᵇ 𝒵) : 𝒳 ⥤ᵇ 𝒵 where
toFunctor := F.toFunctor ⋙ G.toFunctor
w := by rw [Functor.assoc, G.w, F.w]
/-- Notation for composition of based functors. -/
scoped infixr:80 " ⋙ " => BasedFunctor.comp
@[simp]
lemma comp_id (F : 𝒳 ⥤ᵇ 𝒴) : F ⋙ 𝟭 𝒴 = F :=
rfl
@[simp]
lemma id_comp (F : 𝒳 ⥤ᵇ 𝒴) : 𝟭 𝒳 ⋙ F = F :=
rfl
@[simp]
lemma comp_assoc {𝒵 : BasedCategory.{v₄, u₄} 𝒮} {𝒜 : BasedCategory.{v₅, u₅} 𝒮} (F : 𝒳 ⥤ᵇ 𝒴)
(G : 𝒴 ⥤ᵇ 𝒵) (H : 𝒵 ⥤ᵇ 𝒜) : (F ⋙ G) ⋙ H = F ⋙ (G ⋙ H) :=
rfl
@[simp]
lemma w_obj (F : 𝒳 ⥤ᵇ 𝒴) (a : 𝒳.obj) : 𝒴.p.obj (F.obj a) = 𝒳.p.obj a := by
rw [← Functor.comp_obj, F.w]
instance (F : 𝒳 ⥤ᵇ 𝒴) (a : 𝒳.obj) : IsHomLift 𝒴.p (𝟙 (𝒳.p.obj a)) (𝟙 (F.obj a)) :=
IsHomLift.id (w_obj F a)
section
variable (F : 𝒳 ⥤ᵇ 𝒴) {R S : 𝒮} {a b : 𝒳.obj} (f : R ⟶ S) (φ : a ⟶ b)
/-- For a based functor `F : 𝒳 ⟶ 𝒴`, then whenever an arrow `φ` in `𝒳` lifts some `f` in `𝒮`,
then `F(φ)` also lifts `f`. -/
instance preserves_isHomLift [IsHomLift 𝒳.p f φ] : IsHomLift 𝒴.p f (F.map φ) := by
apply of_fac 𝒴.p f (F.map φ) (Eq.trans (F.w_obj a) (domain_eq 𝒳.p f φ))
(Eq.trans (F.w_obj b) (codomain_eq 𝒳.p f φ))
rw [← Functor.comp_map, congr_hom F.w]
simpa using (fac 𝒳.p f φ)
| /-- For a based functor `F : 𝒳 ⟶ 𝒴`, and an arrow `φ` in `𝒳`, then `φ` lifts an arrow `f` in `𝒮`
if `F(φ)` does. -/
lemma isHomLift_map [IsHomLift 𝒴.p f (F.map φ)] : IsHomLift 𝒳.p f φ := by
apply of_fac 𝒳.p f φ (F.w_obj a ▸ domain_eq 𝒴.p f (F.map φ))
(F.w_obj b ▸ codomain_eq 𝒴.p f (F.map φ))
simp [congr_hom F.w.symm, fac 𝒴.p f (F.map φ)]
| Mathlib/CategoryTheory/FiberedCategory/BasedCategory.lean | 117 | 122 |
/-
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.NNReal
/-!
# Limits and asymptotics of power functions at `+∞`
This file contains results about the limiting behaviour of power functions at `+∞`. For convenience
some results on asymptotics as `x → 0` (those which are not just continuity statements) are also
located here.
-/
noncomputable section
open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set
/-!
## Limits at `+∞`
-/
section Limits
open Real Filter
/-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/
theorem tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ y) atTop atTop := by
rw [(atTop_basis' 0).tendsto_right_iff]
intro b hb
filter_upwards [eventually_ge_atTop 0, eventually_ge_atTop (b ^ (1 / y))] with x hx₀ hx
simpa (disch := positivity) [Real.rpow_inv_le_iff_of_pos] using hx
/-- The function `x ^ (-y)` tends to `0` at `+∞` for any positive real `y`. -/
theorem tendsto_rpow_neg_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ (-y)) atTop (𝓝 0) :=
Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop 0) fun _ hx => (rpow_neg (le_of_lt hx) y).symm)
(tendsto_rpow_atTop hy).inv_tendsto_atTop
open Asymptotics in
lemma tendsto_rpow_atTop_of_base_lt_one (b : ℝ) (hb₀ : -1 < b) (hb₁ : b < 1) :
Tendsto (b ^ · : ℝ → ℝ) atTop (𝓝 (0 : ℝ)) := by
rcases lt_trichotomy b 0 with hb|rfl|hb
case inl => -- b < 0
simp_rw [Real.rpow_def_of_nonpos hb.le, hb.ne, ite_false]
rw [← isLittleO_const_iff (c := (1 : ℝ)) one_ne_zero, (one_mul (1 : ℝ)).symm]
refine IsLittleO.mul_isBigO ?exp ?cos
case exp =>
rw [isLittleO_const_iff one_ne_zero]
refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id
rw [← log_neg_eq_log, log_neg_iff (by linarith)]
linarith
case cos =>
rw [isBigO_iff]
exact ⟨1, Eventually.of_forall fun x => by simp [Real.abs_cos_le_one]⟩
case inr.inl => -- b = 0
refine Tendsto.mono_right ?_ (Iff.mpr pure_le_nhds_iff rfl)
rw [tendsto_pure]
filter_upwards [eventually_ne_atTop 0] with _ hx
simp [hx]
case inr.inr => -- b > 0
simp_rw [Real.rpow_def_of_pos hb]
refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id
exact (log_neg_iff hb).mpr hb₁
lemma tendsto_rpow_atTop_of_base_gt_one (b : ℝ) (hb : 1 < b) :
Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 (0 : ℝ)) := by
simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)]
refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_pos ?_).mpr tendsto_id
exact (log_pos_iff (by positivity)).mpr <| by aesop
lemma tendsto_rpow_atBot_of_base_lt_one (b : ℝ) (hb₀ : 0 < b) (hb₁ : b < 1) :
Tendsto (b ^ · : ℝ → ℝ) atBot atTop := by
simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)]
refine tendsto_exp_atTop.comp <| (tendsto_const_mul_atTop_iff_neg <| tendsto_id (α := ℝ)).mpr ?_
exact (log_neg_iff hb₀).mpr hb₁
lemma tendsto_rpow_atBot_of_base_gt_one (b : ℝ) (hb : 1 < b) :
Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 0) := by
simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)]
refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_iff_pos <| tendsto_id (α := ℝ)).mpr ?_
exact (log_pos_iff (by positivity)).mpr <| by aesop
/-- The function `x ^ (a / (b * x + c))` tends to `1` at `+∞`, for any real numbers `a`, `b`, and
`c` such that `b` is nonzero. -/
theorem tendsto_rpow_div_mul_add (a b c : ℝ) (hb : 0 ≠ b) :
Tendsto (fun x => x ^ (a / (b * x + c))) atTop (𝓝 1) := by
refine
Tendsto.congr' ?_
((tendsto_exp_nhds_zero_nhds_one.comp
(by
simpa only [mul_zero, pow_one] using
(tendsto_const_nhds (x := a)).mul
(tendsto_div_pow_mul_exp_add_atTop b c 1 hb))).comp
tendsto_log_atTop)
apply eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ))
intro x hx
simp only [Set.mem_Ioi, Function.comp_apply] at hx ⊢
rw [exp_log hx, ← exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))]
field_simp
/-- The function `x ^ (1 / x)` tends to `1` at `+∞`. -/
theorem tendsto_rpow_div : Tendsto (fun x => x ^ ((1 : ℝ) / x)) atTop (𝓝 1) := by
convert tendsto_rpow_div_mul_add (1 : ℝ) _ (0 : ℝ) zero_ne_one
ring
/-- The function `x ^ (-1 / x)` tends to `1` at `+∞`. -/
theorem tendsto_rpow_neg_div : Tendsto (fun x => x ^ (-(1 : ℝ) / x)) atTop (𝓝 1) := by
convert tendsto_rpow_div_mul_add (-(1 : ℝ)) _ (0 : ℝ) zero_ne_one
ring
/-- The function `exp(x) / x ^ s` tends to `+∞` at `+∞`, for any real number `s`. -/
theorem tendsto_exp_div_rpow_atTop (s : ℝ) : Tendsto (fun x : ℝ => exp x / x ^ s) atTop atTop := by
obtain ⟨n, hn⟩ := archimedean_iff_nat_lt.1 Real.instArchimedean s
refine tendsto_atTop_mono' _ ?_ (tendsto_exp_div_pow_atTop n)
filter_upwards [eventually_gt_atTop (0 : ℝ), eventually_ge_atTop (1 : ℝ)] with x hx₀ hx₁
gcongr
simpa using rpow_le_rpow_of_exponent_le hx₁ hn.le
/-- The function `exp (b * x) / x ^ s` tends to `+∞` at `+∞`, for any real `s` and `b > 0`. -/
theorem tendsto_exp_mul_div_rpow_atTop (s : ℝ) (b : ℝ) (hb : 0 < b) :
Tendsto (fun x : ℝ => exp (b * x) / x ^ s) atTop atTop := by
refine ((tendsto_rpow_atTop hb).comp (tendsto_exp_div_rpow_atTop (s / b))).congr' ?_
filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx₀
simp [Real.div_rpow, (exp_pos x).le, rpow_nonneg, ← Real.rpow_mul, ← exp_mul,
mul_comm x, hb.ne', *]
/-- The function `x ^ s * exp (-b * x)` tends to `0` at `+∞`, for any real `s` and `b > 0`. -/
theorem tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (s : ℝ) (b : ℝ) (hb : 0 < b) :
Tendsto (fun x : ℝ => x ^ s * exp (-b * x)) atTop (𝓝 0) := by
refine (tendsto_exp_mul_div_rpow_atTop s b hb).inv_tendsto_atTop.congr' ?_
filter_upwards with x using by simp [exp_neg, inv_div, div_eq_mul_inv _ (exp _)]
nonrec theorem NNReal.tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) :
Tendsto (fun x : ℝ≥0 => x ^ y) atTop atTop := by
rw [Filter.tendsto_atTop_atTop]
intro b
obtain ⟨c, hc⟩ := tendsto_atTop_atTop.mp (tendsto_rpow_atTop hy) b
use c.toNNReal
intro a ha
exact mod_cast hc a (Real.toNNReal_le_iff_le_coe.mp ha)
theorem ENNReal.tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) :
Tendsto (fun x : ℝ≥0∞ => x ^ y) (𝓝 ⊤) (𝓝 ⊤) := by
rw [ENNReal.tendsto_nhds_top_iff_nnreal]
intro x
obtain ⟨c, _, hc⟩ :=
(atTop_basis_Ioi.tendsto_iff atTop_basis_Ioi).mp (NNReal.tendsto_rpow_atTop hy) x trivial
have hc' : Set.Ioi ↑c ∈ 𝓝 (⊤ : ℝ≥0∞) := Ioi_mem_nhds ENNReal.coe_lt_top
filter_upwards [hc'] with a ha
by_cases ha' : a = ⊤
· simp [ha', hy]
lift a to ℝ≥0 using ha'
simp only [Set.mem_Ioi, coe_lt_coe] at ha hc
rw [← ENNReal.coe_rpow_of_nonneg _ hy.le]
exact mod_cast hc a ha
end Limits
/-!
## Asymptotic results: `IsBigO`, `IsLittleO` and `IsTheta`
-/
namespace Complex
section
variable {α : Type*} {l : Filter α} {f g : α → ℂ}
open Asymptotics
theorem isTheta_exp_arg_mul_im (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) :
(fun x => Real.exp (arg (f x) * im (g x))) =Θ[l] fun _ => (1 : ℝ) := by
rcases hl with ⟨b, hb⟩
refine Real.isTheta_exp_comp_one.2 ⟨π * b, ?_⟩
rw [eventually_map] at hb ⊢
refine hb.mono fun x hx => ?_
rw [abs_mul]
exact mul_le_mul (abs_arg_le_pi _) hx (abs_nonneg _) Real.pi_pos.le
theorem isBigO_cpow_rpow (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) :
(fun x => f x ^ g x) =O[l] fun x => ‖f x‖ ^ (g x).re :=
calc
(fun x => f x ^ g x) =O[l]
(show α → ℝ from fun x => ‖f x‖ ^ (g x).re / Real.exp (arg (f x) * im (g x))) :=
isBigO_of_le _ fun _ => (norm_cpow_le _ _).trans (le_abs_self _)
_ =Θ[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re / (1 : ℝ)) :=
((isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl))
_ =ᶠ[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re) := by
simp only [ofReal_one, div_one, EventuallyEq.rfl]
theorem isTheta_cpow_rpow (hl_im : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|)
(hl : ∀ᶠ x in l, f x = 0 → re (g x) = 0 → g x = 0) :
(fun x => f x ^ g x) =Θ[l] fun x => ‖f x‖ ^ (g x).re :=
calc
(fun x => f x ^ g x) =Θ[l]
(fun x => ‖f x‖ ^ (g x).re / Real.exp (arg (f x) * im (g x))) :=
.of_norm_eventuallyEq <| hl.mono fun _ => norm_cpow_of_imp
_ =Θ[l] fun x => ‖f x‖ ^ (g x).re / (1 : ℝ) :=
(isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl_im)
_ =ᶠ[l] (fun x => ‖f x‖ ^ (g x).re) := by
simp only [ofReal_one, div_one, EventuallyEq.rfl]
theorem isTheta_cpow_const_rpow {b : ℂ} (hl : b.re = 0 → b ≠ 0 → ∀ᶠ x in l, f x ≠ 0) :
(fun x => f x ^ b) =Θ[l] fun x => ‖f x‖ ^ b.re :=
isTheta_cpow_rpow isBoundedUnder_const <| by
simpa only [eventually_imp_distrib_right, not_imp_not, Imp.swap (a := b.re = 0)] using hl
end
end Complex
open Real
namespace Asymptotics
variable {α : Type*} {r c : ℝ} {l : Filter α} {f g : α → ℝ}
theorem IsBigOWith.rpow (h : IsBigOWith c l f g) (hc : 0 ≤ c) (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) :
IsBigOWith (c ^ r) l (fun x => f x ^ r) fun x => g x ^ r := by
apply IsBigOWith.of_bound
filter_upwards [hg, h.bound] with x hgx hx
calc
|f x ^ r| ≤ |f x| ^ r := abs_rpow_le_abs_rpow _ _
_ ≤ (c * |g x|) ^ r := rpow_le_rpow (abs_nonneg _) hx hr
_ = c ^ r * |g x ^ r| := by rw [mul_rpow hc (abs_nonneg _), abs_rpow_of_nonneg hgx]
theorem IsBigO.rpow (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) (h : f =O[l] g) :
(fun x => f x ^ r) =O[l] fun x => g x ^ r :=
let ⟨_, hc, h'⟩ := h.exists_nonneg
(h'.rpow hc hr hg).isBigO
|
theorem IsTheta.rpow (hr : 0 ≤ r) (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) (h : f =Θ[l] g) :
(fun x => f x ^ r) =Θ[l] fun x => g x ^ r :=
⟨h.1.rpow hr hg, h.2.rpow hr hf⟩
theorem IsLittleO.rpow (hr : 0 < r) (hg : 0 ≤ᶠ[l] g) (h : f =o[l] g) :
(fun x => f x ^ r) =o[l] fun x => g x ^ r := by
refine .of_isBigOWith fun c hc ↦ ?_
rw [← rpow_inv_rpow hc.le hr.ne']
refine (h.forall_isBigOWith ?_).rpow ?_ ?_ hg <;> positivity
| Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean | 237 | 246 |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Algebra.GroupWithZero.Indicator
import Mathlib.Topology.Piecewise
import Mathlib.Topology.Instances.ENNReal.Lemmas
/-!
# Semicontinuous maps
A function `f` from a topological space `α` to an ordered space `β` is lower semicontinuous at a
point `x` if, for any `y < f x`, for any `x'` close enough to `x`, one has `f x' > y`. In other
words, `f` can jump up, but it can not jump down.
Upper semicontinuous functions are defined similarly.
This file introduces these notions, and a basic API around them mimicking the API for continuous
functions.
## Main definitions and results
We introduce 4 definitions related to lower semicontinuity:
* `LowerSemicontinuousWithinAt f s x`
* `LowerSemicontinuousAt f x`
* `LowerSemicontinuousOn f s`
* `LowerSemicontinuous f`
We build a basic API using dot notation around these notions, and we prove that
* constant functions are lower semicontinuous;
* `indicator s (fun _ ↦ y)` is lower semicontinuous when `s` is open and `0 ≤ y`,
or when `s` is closed and `y ≤ 0`;
* continuous functions are lower semicontinuous;
* left composition with a continuous monotone functions maps lower semicontinuous functions to lower
semicontinuous functions. If the function is anti-monotone, it instead maps lower semicontinuous
functions to upper semicontinuous functions;
* right composition with continuous functions preserves lower and upper semicontinuity;
* a sum of two (or finitely many) lower semicontinuous functions is lower semicontinuous;
* a supremum of a family of lower semicontinuous functions is lower semicontinuous;
* An infinite sum of `ℝ≥0∞`-valued lower semicontinuous functions is lower semicontinuous.
Similar results are stated and proved for upper semicontinuity.
We also prove that a function is continuous if and only if it is both lower and upper
semicontinuous.
We have some equivalent definitions of lower- and upper-semicontinuity (under certain
restrictions on the order on the codomain):
* `lowerSemicontinuous_iff_isOpen_preimage` in a linear order;
* `lowerSemicontinuous_iff_isClosed_preimage` in a linear order;
* `lowerSemicontinuousAt_iff_le_liminf` in a dense complete linear order;
* `lowerSemicontinuous_iff_isClosed_epigraph` in a dense complete linear order with the order
topology.
## Implementation details
All the nontrivial results for upper semicontinuous functions are deduced from the corresponding
ones for lower semicontinuous functions using `OrderDual`.
## References
* <https://en.wikipedia.org/wiki/Closed_convex_function>
* <https://en.wikipedia.org/wiki/Semi-continuity>
-/
open Topology ENNReal
open Set Function Filter
variable {α : Type*} [TopologicalSpace α] {β : Type*} [Preorder β] {f g : α → β} {x : α}
{s t : Set α} {y z : β}
/-! ### Main definitions -/
/-- A real function `f` is lower semicontinuous at `x` within a set `s` if, for any `ε > 0`, for all
`x'` close enough to `x` in `s`, then `f x'` is at least `f x - ε`. We formulate this in a general
preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/
def LowerSemicontinuousWithinAt (f : α → β) (s : Set α) (x : α) :=
∀ y < f x, ∀ᶠ x' in 𝓝[s] x, y < f x'
/-- A real function `f` is lower semicontinuous on a set `s` if, for any `ε > 0`, for any `x ∈ s`,
for all `x'` close enough to `x` in `s`, then `f x'` is at least `f x - ε`. We formulate this in
a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/
def LowerSemicontinuousOn (f : α → β) (s : Set α) :=
∀ x ∈ s, LowerSemicontinuousWithinAt f s x
/-- A real function `f` is lower semicontinuous at `x` if, for any `ε > 0`, for all `x'` close
enough to `x`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space,
using an arbitrary `y < f x` instead of `f x - ε`. -/
def LowerSemicontinuousAt (f : α → β) (x : α) :=
∀ y < f x, ∀ᶠ x' in 𝓝 x, y < f x'
/-- A real function `f` is lower semicontinuous if, for any `ε > 0`, for any `x`, for all `x'` close
enough to `x`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space,
using an arbitrary `y < f x` instead of `f x - ε`. -/
def LowerSemicontinuous (f : α → β) :=
∀ x, LowerSemicontinuousAt f x
/-- A real function `f` is upper semicontinuous at `x` within a set `s` if, for any `ε > 0`, for all
`x'` close enough to `x` in `s`, then `f x'` is at most `f x + ε`. We formulate this in a general
preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/
def UpperSemicontinuousWithinAt (f : α → β) (s : Set α) (x : α) :=
∀ y, f x < y → ∀ᶠ x' in 𝓝[s] x, f x' < y
/-- A real function `f` is upper semicontinuous on a set `s` if, for any `ε > 0`, for any `x ∈ s`,
for all `x'` close enough to `x` in `s`, then `f x'` is at most `f x + ε`. We formulate this in a
general preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/
def UpperSemicontinuousOn (f : α → β) (s : Set α) :=
∀ x ∈ s, UpperSemicontinuousWithinAt f s x
/-- A real function `f` is upper semicontinuous at `x` if, for any `ε > 0`, for all `x'` close
enough to `x`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space,
using an arbitrary `y > f x` instead of `f x + ε`. -/
def UpperSemicontinuousAt (f : α → β) (x : α) :=
∀ y, f x < y → ∀ᶠ x' in 𝓝 x, f x' < y
/-- A real function `f` is upper semicontinuous if, for any `ε > 0`, for any `x`, for all `x'`
close enough to `x`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered
space, using an arbitrary `y > f x` instead of `f x + ε`. -/
def UpperSemicontinuous (f : α → β) :=
∀ x, UpperSemicontinuousAt f x
/-!
### Lower semicontinuous functions
-/
/-! #### Basic dot notation interface for lower semicontinuity -/
theorem LowerSemicontinuousWithinAt.mono (h : LowerSemicontinuousWithinAt f s x) (hst : t ⊆ s) :
LowerSemicontinuousWithinAt f t x := fun y hy =>
Filter.Eventually.filter_mono (nhdsWithin_mono _ hst) (h y hy)
theorem lowerSemicontinuousWithinAt_univ_iff :
LowerSemicontinuousWithinAt f univ x ↔ LowerSemicontinuousAt f x := by
simp [LowerSemicontinuousWithinAt, LowerSemicontinuousAt, nhdsWithin_univ]
theorem LowerSemicontinuousAt.lowerSemicontinuousWithinAt (s : Set α)
(h : LowerSemicontinuousAt f x) : LowerSemicontinuousWithinAt f s x := fun y hy =>
Filter.Eventually.filter_mono nhdsWithin_le_nhds (h y hy)
theorem LowerSemicontinuousOn.lowerSemicontinuousWithinAt (h : LowerSemicontinuousOn f s)
(hx : x ∈ s) : LowerSemicontinuousWithinAt f s x :=
h x hx
theorem LowerSemicontinuousOn.mono (h : LowerSemicontinuousOn f s) (hst : t ⊆ s) :
LowerSemicontinuousOn f t := fun x hx => (h x (hst hx)).mono hst
theorem lowerSemicontinuousOn_univ_iff : LowerSemicontinuousOn f univ ↔ LowerSemicontinuous f := by
simp [LowerSemicontinuousOn, LowerSemicontinuous, lowerSemicontinuousWithinAt_univ_iff]
theorem LowerSemicontinuous.lowerSemicontinuousAt (h : LowerSemicontinuous f) (x : α) :
LowerSemicontinuousAt f x :=
h x
theorem LowerSemicontinuous.lowerSemicontinuousWithinAt (h : LowerSemicontinuous f) (s : Set α)
(x : α) : LowerSemicontinuousWithinAt f s x :=
(h x).lowerSemicontinuousWithinAt s
theorem LowerSemicontinuous.lowerSemicontinuousOn (h : LowerSemicontinuous f) (s : Set α) :
LowerSemicontinuousOn f s := fun x _hx => h.lowerSemicontinuousWithinAt s x
/-! #### Constants -/
theorem lowerSemicontinuousWithinAt_const : LowerSemicontinuousWithinAt (fun _x => z) s x :=
fun _y hy => Filter.Eventually.of_forall fun _x => hy
theorem lowerSemicontinuousAt_const : LowerSemicontinuousAt (fun _x => z) x := fun _y hy =>
Filter.Eventually.of_forall fun _x => hy
theorem lowerSemicontinuousOn_const : LowerSemicontinuousOn (fun _x => z) s := fun _x _hx =>
lowerSemicontinuousWithinAt_const
theorem lowerSemicontinuous_const : LowerSemicontinuous fun _x : α => z := fun _x =>
lowerSemicontinuousAt_const
/-! #### Indicators -/
section
variable [Zero β]
theorem IsOpen.lowerSemicontinuous_indicator (hs : IsOpen s) (hy : 0 ≤ y) :
LowerSemicontinuous (indicator s fun _x => y) := by
intro x z hz
by_cases h : x ∈ s <;> simp [h] at hz
· filter_upwards [hs.mem_nhds h]
simp +contextual [hz]
· refine Filter.Eventually.of_forall fun x' => ?_
by_cases h' : x' ∈ s <;> simp [h', hz.trans_le hy, hz]
theorem IsOpen.lowerSemicontinuousOn_indicator (hs : IsOpen s) (hy : 0 ≤ y) :
LowerSemicontinuousOn (indicator s fun _x => y) t :=
(hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousOn t
theorem IsOpen.lowerSemicontinuousAt_indicator (hs : IsOpen s) (hy : 0 ≤ y) :
LowerSemicontinuousAt (indicator s fun _x => y) x :=
(hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousAt x
theorem IsOpen.lowerSemicontinuousWithinAt_indicator (hs : IsOpen s) (hy : 0 ≤ y) :
LowerSemicontinuousWithinAt (indicator s fun _x => y) t x :=
(hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousWithinAt t x
theorem IsClosed.lowerSemicontinuous_indicator (hs : IsClosed s) (hy : y ≤ 0) :
LowerSemicontinuous (indicator s fun _x => y) := by
intro x z hz
by_cases h : x ∈ s <;> simp [h] at hz
· refine Filter.Eventually.of_forall fun x' => ?_
by_cases h' : x' ∈ s <;> simp [h', hz, hz.trans_le hy]
· filter_upwards [hs.isOpen_compl.mem_nhds h]
simp +contextual [hz]
theorem IsClosed.lowerSemicontinuousOn_indicator (hs : IsClosed s) (hy : y ≤ 0) :
LowerSemicontinuousOn (indicator s fun _x => y) t :=
(hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousOn t
theorem IsClosed.lowerSemicontinuousAt_indicator (hs : IsClosed s) (hy : y ≤ 0) :
LowerSemicontinuousAt (indicator s fun _x => y) x :=
(hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousAt x
theorem IsClosed.lowerSemicontinuousWithinAt_indicator (hs : IsClosed s) (hy : y ≤ 0) :
LowerSemicontinuousWithinAt (indicator s fun _x => y) t x :=
(hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousWithinAt t x
end
/-! #### Relationship with continuity -/
theorem lowerSemicontinuous_iff_isOpen_preimage :
LowerSemicontinuous f ↔ ∀ y, IsOpen (f ⁻¹' Ioi y) :=
⟨fun H y => isOpen_iff_mem_nhds.2 fun x hx => H x y hx, fun H _x y y_lt =>
IsOpen.mem_nhds (H y) y_lt⟩
theorem LowerSemicontinuous.isOpen_preimage (hf : LowerSemicontinuous f) (y : β) :
IsOpen (f ⁻¹' Ioi y) :=
lowerSemicontinuous_iff_isOpen_preimage.1 hf y
section
variable {γ : Type*} [LinearOrder γ]
theorem lowerSemicontinuous_iff_isClosed_preimage {f : α → γ} :
LowerSemicontinuous f ↔ ∀ y, IsClosed (f ⁻¹' Iic y) := by
rw [lowerSemicontinuous_iff_isOpen_preimage]
simp only [← isOpen_compl_iff, ← preimage_compl, compl_Iic]
theorem LowerSemicontinuous.isClosed_preimage {f : α → γ} (hf : LowerSemicontinuous f) (y : γ) :
IsClosed (f ⁻¹' Iic y) :=
lowerSemicontinuous_iff_isClosed_preimage.1 hf y
variable [TopologicalSpace γ] [OrderTopology γ]
theorem ContinuousWithinAt.lowerSemicontinuousWithinAt {f : α → γ} (h : ContinuousWithinAt f s x) :
LowerSemicontinuousWithinAt f s x := fun _y hy => h (Ioi_mem_nhds hy)
theorem ContinuousAt.lowerSemicontinuousAt {f : α → γ} (h : ContinuousAt f x) :
LowerSemicontinuousAt f x := fun _y hy => h (Ioi_mem_nhds hy)
theorem ContinuousOn.lowerSemicontinuousOn {f : α → γ} (h : ContinuousOn f s) :
LowerSemicontinuousOn f s := fun x hx => (h x hx).lowerSemicontinuousWithinAt
theorem Continuous.lowerSemicontinuous {f : α → γ} (h : Continuous f) : LowerSemicontinuous f :=
fun _x => h.continuousAt.lowerSemicontinuousAt
end
/-! #### Equivalent definitions -/
section
variable {γ : Type*} [CompleteLinearOrder γ] [DenselyOrdered γ]
theorem lowerSemicontinuousWithinAt_iff_le_liminf {f : α → γ} :
LowerSemicontinuousWithinAt f s x ↔ f x ≤ liminf f (𝓝[s] x) := by
constructor
· intro hf; unfold LowerSemicontinuousWithinAt at hf
contrapose! hf
obtain ⟨y, lty, ylt⟩ := exists_between hf; use y
exact ⟨ylt, fun h => lty.not_le
(le_liminf_of_le (by isBoundedDefault) (h.mono fun _ hx => le_of_lt hx))⟩
exact fun hf y ylt => eventually_lt_of_lt_liminf (ylt.trans_le hf)
alias ⟨LowerSemicontinuousWithinAt.le_liminf, _⟩ := lowerSemicontinuousWithinAt_iff_le_liminf
theorem lowerSemicontinuousAt_iff_le_liminf {f : α → γ} :
LowerSemicontinuousAt f x ↔ f x ≤ liminf f (𝓝 x) := by
rw [← lowerSemicontinuousWithinAt_univ_iff, lowerSemicontinuousWithinAt_iff_le_liminf,
← nhdsWithin_univ]
alias ⟨LowerSemicontinuousAt.le_liminf, _⟩ := lowerSemicontinuousAt_iff_le_liminf
theorem lowerSemicontinuous_iff_le_liminf {f : α → γ} :
LowerSemicontinuous f ↔ ∀ x, f x ≤ liminf f (𝓝 x) := by
simp only [← lowerSemicontinuousAt_iff_le_liminf, LowerSemicontinuous]
alias ⟨LowerSemicontinuous.le_liminf, _⟩ := lowerSemicontinuous_iff_le_liminf
theorem lowerSemicontinuousOn_iff_le_liminf {f : α → γ} :
LowerSemicontinuousOn f s ↔ ∀ x ∈ s, f x ≤ liminf f (𝓝[s] x) := by
simp only [← lowerSemicontinuousWithinAt_iff_le_liminf, LowerSemicontinuousOn]
alias ⟨LowerSemicontinuousOn.le_liminf, _⟩ := lowerSemicontinuousOn_iff_le_liminf
variable [TopologicalSpace γ] [OrderTopology γ]
theorem lowerSemicontinuous_iff_isClosed_epigraph {f : α → γ} :
LowerSemicontinuous f ↔ IsClosed {p : α × γ | f p.1 ≤ p.2} := by
constructor
· rw [lowerSemicontinuous_iff_le_liminf, isClosed_iff_forall_filter]
rintro hf ⟨x, y⟩ F F_ne h h'
rw [nhds_prod_eq, le_prod] at h'
calc f x ≤ liminf f (𝓝 x) := hf x
_ ≤ liminf f (map Prod.fst F) := liminf_le_liminf_of_le h'.1
_ = liminf (f ∘ Prod.fst) F := (Filter.liminf_comp _ _ _).symm
_ ≤ liminf Prod.snd F := liminf_le_liminf <| by
simpa using (eventually_principal.2 fun (_ : α × γ) ↦ id).filter_mono h
_ = y := h'.2.liminf_eq
· rw [lowerSemicontinuous_iff_isClosed_preimage]
exact fun hf y ↦ hf.preimage (.prodMk_left y)
alias ⟨LowerSemicontinuous.isClosed_epigraph, _⟩ := lowerSemicontinuous_iff_isClosed_epigraph
end
/-! ### Composition -/
section
variable {γ : Type*} [LinearOrder γ] [TopologicalSpace γ] [OrderTopology γ]
variable {δ : Type*} [LinearOrder δ] [TopologicalSpace δ] [OrderTopology δ]
variable {ι : Type*} [TopologicalSpace ι]
theorem ContinuousAt.comp_lowerSemicontinuousWithinAt {g : γ → δ} {f : α → γ}
(hg : ContinuousAt g (f x)) (hf : LowerSemicontinuousWithinAt f s x) (gmon : Monotone g) :
LowerSemicontinuousWithinAt (g ∘ f) s x := by
intro y hy
by_cases h : ∃ l, l < f x
· obtain ⟨z, zlt, hz⟩ : ∃ z < f x, Ioc z (f x) ⊆ g ⁻¹' Ioi y :=
exists_Ioc_subset_of_mem_nhds (hg (Ioi_mem_nhds hy)) h
filter_upwards [hf z zlt] with a ha
calc
y < g (min (f x) (f a)) := hz (by simp [zlt, ha, le_refl])
_ ≤ g (f a) := gmon (min_le_right _ _)
· simp only [not_exists, not_lt] at h
exact Filter.Eventually.of_forall fun a => hy.trans_le (gmon (h (f a)))
theorem ContinuousAt.comp_lowerSemicontinuousAt {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x))
(hf : LowerSemicontinuousAt f x) (gmon : Monotone g) : LowerSemicontinuousAt (g ∘ f) x := by
simp only [← lowerSemicontinuousWithinAt_univ_iff] at hf ⊢
exact hg.comp_lowerSemicontinuousWithinAt hf gmon
theorem Continuous.comp_lowerSemicontinuousOn {g : γ → δ} {f : α → γ} (hg : Continuous g)
(hf : LowerSemicontinuousOn f s) (gmon : Monotone g) : LowerSemicontinuousOn (g ∘ f) s :=
fun x hx => hg.continuousAt.comp_lowerSemicontinuousWithinAt (hf x hx) gmon
theorem Continuous.comp_lowerSemicontinuous {g : γ → δ} {f : α → γ} (hg : Continuous g)
(hf : LowerSemicontinuous f) (gmon : Monotone g) : LowerSemicontinuous (g ∘ f) := fun x =>
hg.continuousAt.comp_lowerSemicontinuousAt (hf x) gmon
theorem ContinuousAt.comp_lowerSemicontinuousWithinAt_antitone {g : γ → δ} {f : α → γ}
(hg : ContinuousAt g (f x)) (hf : LowerSemicontinuousWithinAt f s x) (gmon : Antitone g) :
UpperSemicontinuousWithinAt (g ∘ f) s x :=
@ContinuousAt.comp_lowerSemicontinuousWithinAt α _ x s γ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon
theorem ContinuousAt.comp_lowerSemicontinuousAt_antitone {g : γ → δ} {f : α → γ}
(hg : ContinuousAt g (f x)) (hf : LowerSemicontinuousAt f x) (gmon : Antitone g) :
UpperSemicontinuousAt (g ∘ f) x :=
@ContinuousAt.comp_lowerSemicontinuousAt α _ x γ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon
theorem Continuous.comp_lowerSemicontinuousOn_antitone {g : γ → δ} {f : α → γ} (hg : Continuous g)
(hf : LowerSemicontinuousOn f s) (gmon : Antitone g) : UpperSemicontinuousOn (g ∘ f) s :=
fun x hx => hg.continuousAt.comp_lowerSemicontinuousWithinAt_antitone (hf x hx) gmon
theorem Continuous.comp_lowerSemicontinuous_antitone {g : γ → δ} {f : α → γ} (hg : Continuous g)
(hf : LowerSemicontinuous f) (gmon : Antitone g) : UpperSemicontinuous (g ∘ f) := fun x =>
hg.continuousAt.comp_lowerSemicontinuousAt_antitone (hf x) gmon
theorem LowerSemicontinuousAt.comp_continuousAt {f : α → β} {g : ι → α} {x : ι}
(hf : LowerSemicontinuousAt f (g x)) (hg : ContinuousAt g x) :
LowerSemicontinuousAt (fun x ↦ f (g x)) x :=
fun _ lt ↦ hg.eventually (hf _ lt)
theorem LowerSemicontinuousAt.comp_continuousAt_of_eq {f : α → β} {g : ι → α} {y : α} {x : ι}
(hf : LowerSemicontinuousAt f y) (hg : ContinuousAt g x) (hy : g x = y) :
LowerSemicontinuousAt (fun x ↦ f (g x)) x := by
rw [← hy] at hf
exact comp_continuousAt hf hg
theorem LowerSemicontinuous.comp_continuous {f : α → β} {g : ι → α}
(hf : LowerSemicontinuous f) (hg : Continuous g) : LowerSemicontinuous fun x ↦ f (g x) :=
fun x ↦ (hf (g x)).comp_continuousAt hg.continuousAt
end
/-! #### Addition -/
section
variable {ι : Type*} {γ : Type*} [AddCommMonoid γ] [LinearOrder γ] [IsOrderedAddMonoid γ]
[TopologicalSpace γ] [OrderTopology γ]
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an
explicit continuity assumption on addition, for application to `EReal`. The unprimed version of
the lemma uses `[ContinuousAdd]`. -/
theorem LowerSemicontinuousWithinAt.add' {f g : α → γ} (hf : LowerSemicontinuousWithinAt f s x)
(hg : LowerSemicontinuousWithinAt g s x)
(hcont : ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) :
LowerSemicontinuousWithinAt (fun z => f z + g z) s x := by
intro y hy
obtain ⟨u, v, u_open, xu, v_open, xv, h⟩ :
∃ u v : Set γ,
IsOpen u ∧ f x ∈ u ∧ IsOpen v ∧ g x ∈ v ∧ u ×ˢ v ⊆ { p : γ × γ | y < p.fst + p.snd } :=
mem_nhds_prod_iff'.1 (hcont (isOpen_Ioi.mem_nhds hy))
by_cases hx₁ : ∃ l, l < f x
· obtain ⟨z₁, z₁lt, h₁⟩ : ∃ z₁ < f x, Ioc z₁ (f x) ⊆ u :=
exists_Ioc_subset_of_mem_nhds (u_open.mem_nhds xu) hx₁
by_cases hx₂ : ∃ l, l < g x
· obtain ⟨z₂, z₂lt, h₂⟩ : ∃ z₂ < g x, Ioc z₂ (g x) ⊆ v :=
exists_Ioc_subset_of_mem_nhds (v_open.mem_nhds xv) hx₂
filter_upwards [hf z₁ z₁lt, hg z₂ z₂lt] with z h₁z h₂z
have A1 : min (f z) (f x) ∈ u := by
by_cases H : f z ≤ f x
· simpa [H] using h₁ ⟨h₁z, H⟩
· simpa [le_of_not_le H]
have A2 : min (g z) (g x) ∈ v := by
by_cases H : g z ≤ g x
· simpa [H] using h₂ ⟨h₂z, H⟩
· simpa [le_of_not_le H]
have : (min (f z) (f x), min (g z) (g x)) ∈ u ×ˢ v := ⟨A1, A2⟩
calc
y < min (f z) (f x) + min (g z) (g x) := h this
_ ≤ f z + g z := add_le_add (min_le_left _ _) (min_le_left _ _)
· simp only [not_exists, not_lt] at hx₂
filter_upwards [hf z₁ z₁lt] with z h₁z
have A1 : min (f z) (f x) ∈ u := by
by_cases H : f z ≤ f x
· simpa [H] using h₁ ⟨h₁z, H⟩
· simpa [le_of_not_le H]
have : (min (f z) (f x), g x) ∈ u ×ˢ v := ⟨A1, xv⟩
calc
y < min (f z) (f x) + g x := h this
_ ≤ f z + g z := add_le_add (min_le_left _ _) (hx₂ (g z))
· simp only [not_exists, not_lt] at hx₁
by_cases hx₂ : ∃ l, l < g x
· obtain ⟨z₂, z₂lt, h₂⟩ : ∃ z₂ < g x, Ioc z₂ (g x) ⊆ v :=
exists_Ioc_subset_of_mem_nhds (v_open.mem_nhds xv) hx₂
filter_upwards [hg z₂ z₂lt] with z h₂z
have A2 : min (g z) (g x) ∈ v := by
by_cases H : g z ≤ g x
· simpa [H] using h₂ ⟨h₂z, H⟩
· simpa [le_of_not_le H] using h₂ ⟨z₂lt, le_rfl⟩
have : (f x, min (g z) (g x)) ∈ u ×ˢ v := ⟨xu, A2⟩
calc
y < f x + min (g z) (g x) := h this
_ ≤ f z + g z := add_le_add (hx₁ (f z)) (min_le_left _ _)
· simp only [not_exists, not_lt] at hx₁ hx₂
apply Filter.Eventually.of_forall
intro z
have : (f x, g x) ∈ u ×ˢ v := ⟨xu, xv⟩
calc
y < f x + g x := h this
_ ≤ f z + g z := add_le_add (hx₁ (f z)) (hx₂ (g z))
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an
explicit continuity assumption on addition, for application to `EReal`. The unprimed version of
the lemma uses `[ContinuousAdd]`. -/
theorem LowerSemicontinuousAt.add' {f g : α → γ} (hf : LowerSemicontinuousAt f x)
(hg : LowerSemicontinuousAt g x)
(hcont : ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) :
LowerSemicontinuousAt (fun z => f z + g z) x := by
simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at *
exact hf.add' hg hcont
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an
explicit continuity assumption on addition, for application to `EReal`. The unprimed version of
the lemma uses `[ContinuousAdd]`. -/
theorem LowerSemicontinuousOn.add' {f g : α → γ} (hf : LowerSemicontinuousOn f s)
(hg : LowerSemicontinuousOn g s)
(hcont : ∀ x ∈ s, ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) :
LowerSemicontinuousOn (fun z => f z + g z) s := fun x hx =>
(hf x hx).add' (hg x hx) (hcont x hx)
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an
explicit continuity assumption on addition, for application to `EReal`. The unprimed version of
the lemma uses `[ContinuousAdd]`. -/
theorem LowerSemicontinuous.add' {f g : α → γ} (hf : LowerSemicontinuous f)
(hg : LowerSemicontinuous g)
(hcont : ∀ x, ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) :
LowerSemicontinuous fun z => f z + g z := fun x => (hf x).add' (hg x) (hcont x)
variable [ContinuousAdd γ]
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with
`[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on
addition, for application to `EReal`. -/
theorem LowerSemicontinuousWithinAt.add {f g : α → γ} (hf : LowerSemicontinuousWithinAt f s x)
(hg : LowerSemicontinuousWithinAt g s x) :
LowerSemicontinuousWithinAt (fun z => f z + g z) s x :=
hf.add' hg continuous_add.continuousAt
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with
`[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on
addition, for application to `EReal`. -/
theorem LowerSemicontinuousAt.add {f g : α → γ} (hf : LowerSemicontinuousAt f x)
(hg : LowerSemicontinuousAt g x) : LowerSemicontinuousAt (fun z => f z + g z) x :=
hf.add' hg continuous_add.continuousAt
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with
`[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on
addition, for application to `EReal`. -/
theorem LowerSemicontinuousOn.add {f g : α → γ} (hf : LowerSemicontinuousOn f s)
(hg : LowerSemicontinuousOn g s) : LowerSemicontinuousOn (fun z => f z + g z) s :=
hf.add' hg fun _x _hx => continuous_add.continuousAt
/-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with
`[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on
addition, for application to `EReal`. -/
theorem LowerSemicontinuous.add {f g : α → γ} (hf : LowerSemicontinuous f)
(hg : LowerSemicontinuous g) : LowerSemicontinuous fun z => f z + g z :=
hf.add' hg fun _x => continuous_add.continuousAt
theorem lowerSemicontinuousWithinAt_sum {f : ι → α → γ} {a : Finset ι}
(ha : ∀ i ∈ a, LowerSemicontinuousWithinAt (f i) s x) :
LowerSemicontinuousWithinAt (fun z => ∑ i ∈ a, f i z) s x := by
classical
induction a using Finset.induction_on with
| empty => exact lowerSemicontinuousWithinAt_const
| insert _ _ ia IH =>
simp only [ia, Finset.sum_insert, not_false_iff]
exact
LowerSemicontinuousWithinAt.add (ha _ (Finset.mem_insert_self ..))
(IH fun j ja => ha j (Finset.mem_insert_of_mem ja))
theorem lowerSemicontinuousAt_sum {f : ι → α → γ} {a : Finset ι}
(ha : ∀ i ∈ a, LowerSemicontinuousAt (f i) x) :
LowerSemicontinuousAt (fun z => ∑ i ∈ a, f i z) x := by
simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at *
exact lowerSemicontinuousWithinAt_sum ha
theorem lowerSemicontinuousOn_sum {f : ι → α → γ} {a : Finset ι}
(ha : ∀ i ∈ a, LowerSemicontinuousOn (f i) s) :
LowerSemicontinuousOn (fun z => ∑ i ∈ a, f i z) s := fun x hx =>
lowerSemicontinuousWithinAt_sum fun i hi => ha i hi x hx
theorem lowerSemicontinuous_sum {f : ι → α → γ} {a : Finset ι}
(ha : ∀ i ∈ a, LowerSemicontinuous (f i)) : LowerSemicontinuous fun z => ∑ i ∈ a, f i z :=
fun x => lowerSemicontinuousAt_sum fun i hi => ha i hi x
end
/-! #### Supremum -/
section
variable {ι : Sort*} {δ δ' : Type*} [CompleteLinearOrder δ] [ConditionallyCompleteLinearOrder δ']
theorem lowerSemicontinuousWithinAt_ciSup {f : ι → α → δ'}
(bdd : ∀ᶠ y in 𝓝[s] x, BddAbove (range fun i => f i y))
(h : ∀ i, LowerSemicontinuousWithinAt (f i) s x) :
LowerSemicontinuousWithinAt (fun x' => ⨆ i, f i x') s x := by
cases isEmpty_or_nonempty ι
· simpa only [iSup_of_empty'] using lowerSemicontinuousWithinAt_const
· intro y hy
rcases exists_lt_of_lt_ciSup hy with ⟨i, hi⟩
filter_upwards [h i y hi, bdd] with y hy hy' using hy.trans_le (le_ciSup hy' i)
theorem lowerSemicontinuousWithinAt_iSup {f : ι → α → δ}
(h : ∀ i, LowerSemicontinuousWithinAt (f i) s x) :
LowerSemicontinuousWithinAt (fun x' => ⨆ i, f i x') s x :=
lowerSemicontinuousWithinAt_ciSup (by simp) h
theorem lowerSemicontinuousWithinAt_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ}
(h : ∀ i hi, LowerSemicontinuousWithinAt (f i hi) s x) :
LowerSemicontinuousWithinAt (fun x' => ⨆ (i) (hi), f i hi x') s x :=
lowerSemicontinuousWithinAt_iSup fun i => lowerSemicontinuousWithinAt_iSup fun hi => h i hi
theorem lowerSemicontinuousAt_ciSup {f : ι → α → δ'}
(bdd : ∀ᶠ y in 𝓝 x, BddAbove (range fun i => f i y)) (h : ∀ i, LowerSemicontinuousAt (f i) x) :
LowerSemicontinuousAt (fun x' => ⨆ i, f i x') x := by
simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at *
rw [← nhdsWithin_univ] at bdd
exact lowerSemicontinuousWithinAt_ciSup bdd h
theorem lowerSemicontinuousAt_iSup {f : ι → α → δ} (h : ∀ i, LowerSemicontinuousAt (f i) x) :
LowerSemicontinuousAt (fun x' => ⨆ i, f i x') x :=
lowerSemicontinuousAt_ciSup (by simp) h
theorem lowerSemicontinuousAt_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ}
(h : ∀ i hi, LowerSemicontinuousAt (f i hi) x) :
LowerSemicontinuousAt (fun x' => ⨆ (i) (hi), f i hi x') x :=
lowerSemicontinuousAt_iSup fun i => lowerSemicontinuousAt_iSup fun hi => h i hi
theorem lowerSemicontinuousOn_ciSup {f : ι → α → δ'}
(bdd : ∀ x ∈ s, BddAbove (range fun i => f i x)) (h : ∀ i, LowerSemicontinuousOn (f i) s) :
LowerSemicontinuousOn (fun x' => ⨆ i, f i x') s := fun x hx =>
lowerSemicontinuousWithinAt_ciSup (eventually_nhdsWithin_of_forall bdd) fun i => h i x hx
theorem lowerSemicontinuousOn_iSup {f : ι → α → δ} (h : ∀ i, LowerSemicontinuousOn (f i) s) :
LowerSemicontinuousOn (fun x' => ⨆ i, f i x') s :=
lowerSemicontinuousOn_ciSup (by simp) h
theorem lowerSemicontinuousOn_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ}
(h : ∀ i hi, LowerSemicontinuousOn (f i hi) s) :
LowerSemicontinuousOn (fun x' => ⨆ (i) (hi), f i hi x') s :=
lowerSemicontinuousOn_iSup fun i => lowerSemicontinuousOn_iSup fun hi => h i hi
theorem lowerSemicontinuous_ciSup {f : ι → α → δ'} (bdd : ∀ x, BddAbove (range fun i => f i x))
(h : ∀ i, LowerSemicontinuous (f i)) : LowerSemicontinuous fun x' => ⨆ i, f i x' := fun x =>
lowerSemicontinuousAt_ciSup (Eventually.of_forall bdd) fun i => h i x
theorem lowerSemicontinuous_iSup {f : ι → α → δ} (h : ∀ i, LowerSemicontinuous (f i)) :
LowerSemicontinuous fun x' => ⨆ i, f i x' :=
lowerSemicontinuous_ciSup (by simp) h
theorem lowerSemicontinuous_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ}
(h : ∀ i hi, LowerSemicontinuous (f i hi)) :
LowerSemicontinuous fun x' => ⨆ (i) (hi), f i hi x' :=
lowerSemicontinuous_iSup fun i => lowerSemicontinuous_iSup fun hi => h i hi
end
/-! #### Infinite sums -/
section
variable {ι : Type*}
theorem lowerSemicontinuousWithinAt_tsum {f : ι → α → ℝ≥0∞}
(h : ∀ i, LowerSemicontinuousWithinAt (f i) s x) :
LowerSemicontinuousWithinAt (fun x' => ∑' i, f i x') s x := by
simp_rw [ENNReal.tsum_eq_iSup_sum]
refine lowerSemicontinuousWithinAt_iSup fun b => ?_
exact lowerSemicontinuousWithinAt_sum fun i _hi => h i
theorem lowerSemicontinuousAt_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, LowerSemicontinuousAt (f i) x) :
LowerSemicontinuousAt (fun x' => ∑' i, f i x') x := by
simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at *
exact lowerSemicontinuousWithinAt_tsum h
theorem lowerSemicontinuousOn_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, LowerSemicontinuousOn (f i) s) :
LowerSemicontinuousOn (fun x' => ∑' i, f i x') s := fun x hx =>
lowerSemicontinuousWithinAt_tsum fun i => h i x hx
theorem lowerSemicontinuous_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, LowerSemicontinuous (f i)) :
LowerSemicontinuous fun x' => ∑' i, f i x' := fun x => lowerSemicontinuousAt_tsum fun i => h i x
end
/-!
### Upper semicontinuous functions
| -/
/-! #### Basic dot notation interface for upper semicontinuity -/
| Mathlib/Topology/Semicontinuous.lean | 666 | 671 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Operations
import Mathlib.Order.Basic
import Mathlib.Order.BooleanAlgebra
import Mathlib.Tactic.Tauto
import Mathlib.Tactic.ByContra
import Mathlib.Util.Delaborators
import Mathlib.Tactic.Lift
/-!
# Basic properties of sets
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not
be decidable. The definition is in the module `Mathlib.Data.Set.Defs`.
This file provides some basic definitions related to sets and functions not present in the
definitions file, as well as extra lemmas for functions defined in the definitions file and
`Mathlib.Data.Set.Operations` (empty set, univ, union, intersection, insert, singleton,
set-theoretic difference, complement, and powerset).
Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending
`s` to the corresponding subtype `↥s`.
See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean.
## Main definitions
Notation used here:
- `f : α → β` is a function,
- `s : Set α` and `s₁ s₂ : Set α` are subsets of `α`
- `t : Set β` is a subset of `β`.
Definitions in the file:
* `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the
fact that `s` has an element (see the Implementation Notes).
* `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`.
## Notation
* `sᶜ` for the complement of `s`
## Implementation notes
* `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that
the `s.Nonempty` dot notation can be used.
* For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`.
## Tags
set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset
-/
assert_not_exists RelIso
/-! ### Set coercion to a type -/
open Function
universe u v
namespace Set
variable {α : Type u} {s t : Set α}
instance instBooleanAlgebra : BooleanAlgebra (Set α) :=
{ (inferInstance : BooleanAlgebra (α → Prop)) with
sup := (· ∪ ·),
le := (· ≤ ·),
lt := fun s t => s ⊆ t ∧ ¬t ⊆ s,
inf := (· ∩ ·),
bot := ∅,
compl := (·ᶜ),
top := univ,
sdiff := (· \ ·) }
instance : HasSSubset (Set α) :=
⟨(· < ·)⟩
@[simp]
theorem top_eq_univ : (⊤ : Set α) = univ :=
rfl
@[simp]
theorem bot_eq_empty : (⊥ : Set α) = ∅ :=
rfl
@[simp]
theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) :=
rfl
@[simp]
theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) :=
rfl
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) :=
rfl
@[simp]
theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) :=
rfl
theorem le_iff_subset : s ≤ t ↔ s ⊆ t :=
Iff.rfl
theorem lt_iff_ssubset : s < t ↔ s ⊂ t :=
Iff.rfl
alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset
alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset
instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) :
CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True :=
PiSubtype.canLift ι α s
instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiSetCoe.canLift ι (fun _ => α) s
end Set
section SetCoe
variable {α : Type u}
instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩
theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } :=
rfl
@[simp]
theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } :=
rfl
theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
theorem SetCoe.exists {s : Set α} {p : s → Prop} :
(∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.exists
theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 :=
(@SetCoe.exists _ _ fun x => p x.1 x.2).symm
theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 :=
(@SetCoe.forall _ _ fun x => p x.1 x.2).symm
@[simp]
theorem set_coe_cast :
∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩
| _, _, rfl, _, _ => rfl
theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b :=
Subtype.eq
theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
Iff.intro SetCoe.ext fun h => h ▸ rfl
end SetCoe
/-- See also `Subtype.prop` -/
theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s :=
p.prop
/-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/
theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t :=
fun h₁ _ h₂ => by rw [← h₁]; exact h₂
namespace Set
variable {α : Type u} {β : Type v} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α}
instance : Inhabited (Set α) :=
⟨∅⟩
@[trans]
theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t :=
h hx
theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by
tauto
theorem setOf_injective : Function.Injective (@setOf α) := injective_id
theorem setOf_inj {p q : α → Prop} : { x | p x } = { x | q x } ↔ p = q := Iff.rfl
/-! ### Lemmas about `mem` and `setOf` -/
theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a :=
Iff.rfl
/-- This lemma is intended for use with `rw` where a membership predicate is needed,
hence the explicit argument and the equality in the reverse direction from normal.
See also `Set.mem_setOf_eq` for the reverse direction applied to an argument. -/
theorem eq_mem_setOf (p : α → Prop) : p = (· ∈ {a | p a}) := rfl
/-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can
nevertheless be useful for various reasons, e.g. to apply further projection notation or in an
argument to `simp`. -/
theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a :=
h
theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a :=
Iff.rfl
@[simp]
theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s :=
rfl
theorem setOf_set {s : Set α} : setOf s = s :=
rfl
theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x :=
Iff.rfl
theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a :=
Iff.rfl
theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) :=
bijective_id
theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x :=
Iff.rfl
theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s :=
Iff.rfl
@[simp]
theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a :=
Iff.rfl
theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } :=
rfl
theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } :=
rfl
/-! ### Subset and strict subset relations -/
instance : IsRefl (Set α) (· ⊆ ·) :=
show IsRefl (Set α) (· ≤ ·) by infer_instance
instance : IsTrans (Set α) (· ⊆ ·) :=
show IsTrans (Set α) (· ≤ ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) :=
show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance
instance : IsAntisymm (Set α) (· ⊆ ·) :=
show IsAntisymm (Set α) (· ≤ ·) by infer_instance
instance : IsIrrefl (Set α) (· ⊂ ·) :=
show IsIrrefl (Set α) (· < ·) by infer_instance
instance : IsTrans (Set α) (· ⊂ ·) :=
show IsTrans (Set α) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· < ·) (· < ·) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) :=
show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance
instance : IsAsymm (Set α) (· ⊂ ·) :=
show IsAsymm (Set α) (· < ·) by infer_instance
instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) :=
⟨fun _ _ => Iff.rfl⟩
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t :=
rfl
theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) :=
rfl
@[refl]
theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id
theorem Subset.rfl {s : Set α} : s ⊆ s :=
Subset.refl s
@[trans]
theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h
@[trans]
theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
hx.symm ▸ h
theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩
theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩
-- an alternative name
theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b :=
Subset.antisymm
theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ :=
@h _
theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s :=
mt <| mem_of_subset_of_mem h
theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by
simp only [subset_def, not_forall, exists_prop]
theorem not_top_subset : ¬⊤ ⊆ s ↔ ∃ a, a ∉ s := by
simp [not_subset]
lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h
/-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/
protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t :=
eq_or_lt_of_le h
theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s :=
not_subset.1 h.2
protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne (Set α) _ s t
theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s :=
⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩
theorem ssubset_iff_exists {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ ∃ x ∈ t, x ∉ s :=
⟨fun h ↦ ⟨h.le, Set.exists_of_ssubset h⟩, fun ⟨h1, h2⟩ ↦ (Set.ssubset_iff_of_subset h1).mpr h2⟩
protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂)
(hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩
protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂)
(hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩
theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) :=
id
theorem not_not_mem : ¬a ∉ s ↔ a ∈ s :=
not_not
/-! ### Non-empty sets -/
theorem nonempty_coe_sort {s : Set α} : Nonempty ↥s ↔ s.Nonempty :=
nonempty_subtype
alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort
theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s :=
Iff.rfl
theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty :=
⟨x, h⟩
theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅
| ⟨_, hx⟩, hs => hs hx
/-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/
protected noncomputable def Nonempty.some (h : s.Nonempty) : α :=
Classical.choose h
protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s :=
Classical.choose_spec h
theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
hs.imp ht
theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty :=
let ⟨x, xs, xt⟩ := not_subset.1 h
⟨x, xs, xt⟩
theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty :=
nonempty_of_not_subset ht.2
theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty :=
(nonempty_of_ssubset ht).of_diff
theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty :=
hs.imp fun _ => Or.inl
theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty :=
ht.imp fun _ => Or.inr
@[simp]
theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty :=
exists_or
theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty :=
h.imp fun _ => And.right
theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t :=
Iff.rfl
theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by
simp_rw [inter_nonempty]
theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by
simp_rw [inter_nonempty, and_comm]
theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty :=
⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩
@[simp]
theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty
| ⟨x⟩ => ⟨x, trivial⟩
theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) :=
nonempty_subtype.2
theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩
instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) :=
Set.univ_nonempty.to_subtype
-- Redeclare for refined keys
-- `Nonempty (@Subtype _ (@Membership.mem _ (Set _) _ (@Top.top (Set _) _)))`
instance instNonemptyTop [Nonempty α] : Nonempty (⊤ : Set α) :=
inferInstanceAs (Nonempty (univ : Set α))
theorem Nonempty.of_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_›
@[deprecated (since := "2024-11-23")] alias nonempty_of_nonempty_subtype := Nonempty.of_subtype
/-! ### Lemmas about the empty set -/
theorem empty_def : (∅ : Set α) = { _x : α | False } :=
rfl
@[simp]
theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False :=
Iff.rfl
@[simp]
theorem setOf_false : { _a : α | False } = ∅ :=
rfl
@[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl
@[simp]
theorem empty_subset (s : Set α) : ∅ ⊆ s :=
nofun
@[simp]
theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ :=
(Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm
theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s :=
subset_empty_iff.symm
theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ :=
subset_empty_iff.1 h
theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ :=
subset_empty_iff.1
theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ :=
eq_empty_of_subset_empty fun x _ => isEmptyElim x
/-- There is exactly one set of a type that is empty. -/
instance uniqueEmpty [IsEmpty α] : Unique (Set α) where
default := ∅
uniq := eq_empty_of_isEmpty
/-- See also `Set.nonempty_iff_ne_empty`. -/
theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by
simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem]
/-- See also `Set.not_nonempty_iff_eq_empty`. -/
theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty.not_right
/-- See also `nonempty_iff_ne_empty'`. -/
theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by
rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem]
/-- See also `not_nonempty_iff_eq_empty'`. -/
theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty'.not_right
alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty
@[simp]
theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx
@[simp]
theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ :=
not_iff_not.1 <| by simpa using nonempty_iff_ne_empty
theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty :=
or_iff_not_imp_left.2 nonempty_iff_ne_empty.2
theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ :=
subset_empty_iff.1 <| e ▸ h
theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True :=
iff_true_intro fun _ => False.elim
instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) :=
⟨fun x => x.2⟩
@[simp]
theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty :=
(@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm
alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset
/-!
### Universal set.
In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`.
Mathematically it is the same as `α` but it has a different type.
-/
@[simp]
theorem setOf_true : { _x : α | True } = univ :=
rfl
@[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl
@[simp]
theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α :=
eq_empty_iff_forall_not_mem.trans
⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩
theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e =>
not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm
@[simp]
theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial
@[simp]
theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ :=
@top_le_iff _ _ _ s
alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff
theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s :=
univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial
theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ :=
eq_univ_iff_forall.2
theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by
rintro ⟨x, hx⟩
exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x]
theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ :=
eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t)
theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α)
| ⟨x⟩ => ⟨x, trivial⟩
theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by
rw [← not_forall, ← eq_univ_iff_forall]
theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} :
¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def]
theorem univ_unique [Unique α] : @Set.univ α = {default} :=
Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default
theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ :=
lt_top_iff_ne_top
instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) :=
⟨⟨∅, univ, empty_ne_univ⟩⟩
/-! ### Lemmas about union -/
theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } :=
rfl
theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b :=
Or.inl
theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b :=
Or.inr
theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b :=
H
theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P)
(H₃ : x ∈ b → P) : P :=
Or.elim H₁ H₂ H₃
@[simp]
theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b :=
Iff.rfl
@[simp]
theorem union_self (a : Set α) : a ∪ a = a :=
ext fun _ => or_self_iff
@[simp]
theorem union_empty (a : Set α) : a ∪ ∅ = a :=
ext fun _ => iff_of_eq (or_false _)
@[simp]
theorem empty_union (a : Set α) : ∅ ∪ a = a :=
ext fun _ => iff_of_eq (false_or _)
theorem union_comm (a b : Set α) : a ∪ b = b ∪ a :=
ext fun _ => or_comm
theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) :=
ext fun _ => or_assoc
instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) :=
⟨union_assoc⟩
instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) :=
⟨union_comm⟩
theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
ext fun _ => or_left_comm
theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ :=
ext fun _ => or_right_comm
@[simp]
theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s :=
sup_eq_left
@[simp]
theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t :=
sup_eq_right
theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t :=
union_eq_right.mpr h
theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s :=
union_eq_left.mpr h
@[simp]
theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl
@[simp]
theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr
theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ =>
Or.rec (@sr _) (@tr _)
@[simp]
theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u :=
(forall_congr' fun _ => or_imp).trans forall_and
@[gcongr]
theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) :
s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _)
@[gcongr]
theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h Subset.rfl
@[gcongr]
theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union Subset.rfl h
theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_left
theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_right
theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u :=
sup_congr_left ht hu
theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u :=
sup_congr_right hs ht
theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t :=
sup_eq_sup_iff_left
theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u :=
sup_eq_sup_iff_right
@[simp]
theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by
simp only [← subset_empty_iff]
exact union_subset_iff
@[simp]
theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _
@[simp]
theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _
@[simp]
theorem ssubset_union_left_iff : s ⊂ s ∪ t ↔ ¬ t ⊆ s :=
left_lt_sup
@[simp]
theorem ssubset_union_right_iff : t ⊂ s ∪ t ↔ ¬ s ⊆ t :=
right_lt_sup
/-! ### Lemmas about intersection -/
theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } :=
rfl
@[simp, mfld_simps]
theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b :=
Iff.rfl
theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b :=
⟨ha, hb⟩
theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a :=
h.left
theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b :=
h.right
@[simp]
theorem inter_self (a : Set α) : a ∩ a = a :=
ext fun _ => and_self_iff
@[simp]
theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ :=
ext fun _ => iff_of_eq (and_false _)
@[simp]
theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ :=
ext fun _ => iff_of_eq (false_and _)
theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a :=
ext fun _ => and_comm
theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) :=
ext fun _ => and_assoc
instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) :=
⟨inter_assoc⟩
instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) :=
⟨inter_comm⟩
theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext fun _ => and_left_comm
theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ :=
ext fun _ => and_right_comm
@[simp, mfld_simps]
theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left
@[simp]
theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right
theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h =>
⟨rs h, rt h⟩
@[simp]
theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t :=
(forall_congr' fun _ => imp_and).trans forall_and
@[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left
@[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right
@[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf
@[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf
theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s :=
inter_eq_left.mpr
theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t :=
inter_eq_right.mpr
theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u :=
inf_congr_left ht hu
theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u :=
inf_congr_right hs ht
theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u :=
inf_eq_inf_iff_left
theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t :=
inf_eq_inf_iff_right
@[simp, mfld_simps]
theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _
@[simp, mfld_simps]
theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _
@[gcongr]
theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) :
s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _)
@[gcongr]
theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u :=
inter_subset_inter H Subset.rfl
@[gcongr]
theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t :=
inter_subset_inter Subset.rfl H
theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s :=
inter_eq_self_of_subset_right subset_union_left
theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t :=
inter_eq_self_of_subset_right subset_union_right
theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} :=
rfl
theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} :=
inter_comm _ _
@[simp]
theorem inter_ssubset_right_iff : s ∩ t ⊂ t ↔ ¬ t ⊆ s :=
inf_lt_right
@[simp]
theorem inter_ssubset_left_iff : s ∩ t ⊂ s ↔ ¬ s ⊆ t :=
inf_lt_left
/-! ### Distributivity laws -/
theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u :=
inf_sup_left _ _ _
theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u :=
inf_sup_right _ _ _
theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) :=
sup_inf_left _ _ _
theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) :=
sup_inf_right _ _ _
theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) :=
sup_sup_distrib_left _ _ _
theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) :=
sup_sup_distrib_right _ _ _
theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) :=
inf_inf_distrib_left _ _ _
theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) :=
inf_inf_distrib_right _ _ _
theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) :=
sup_sup_sup_comm _ _ _ _
theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) :=
inf_inf_inf_comm _ _ _ _
/-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/
section Sep
variable {p q : α → Prop} {x : α}
theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } :=
⟨xs, px⟩
@[simp]
theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t :=
rfl
@[simp]
theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x :=
Iff.rfl
theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_congr_right_iff]
theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s :=
inter_eq_self_of_subset_right h
@[simp]
theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left
@[simp]
theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_iff_left_iff_imp]
@[simp]
theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by
simp_rw [Set.ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false, not_and]
theorem sep_true : { x ∈ s | True } = s :=
inter_univ s
theorem sep_false : { x ∈ s | False } = ∅ :=
inter_empty s
theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ :=
empty_inter {x | p x}
theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } :=
univ_inter {x | p x}
@[simp]
theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } :=
union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p
@[simp]
theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } :=
inter_inter_distrib_right s t {x | p x}
@[simp]
theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } :=
inter_inter_distrib_left s {x | p x} {x | q x}
@[simp]
theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } :=
inter_union_distrib_left s p q
@[simp]
theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } :=
rfl
end Sep
/-- See also `Set.sdiff_inter_right_comm`. -/
lemma inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc ..
/-- See also `Set.inter_diff_assoc`. -/
lemma sdiff_inter_right_comm (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ t := sdiff_inf_right_comm ..
lemma inter_sdiff_left_comm (s t u : Set α) : s ∩ (t \ u) = t ∩ (s \ u) := inf_sdiff_left_comm ..
theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u :=
sdiff_sup_sdiff_cancel hts hut
/-- A version of `diff_union_diff_cancel` with more general hypotheses. -/
theorem diff_union_diff_cancel' (hi : s ∩ u ⊆ t) (hu : t ⊆ s ∪ u) : (s \ t) ∪ (t \ u) = s \ u :=
sdiff_sup_sdiff_cancel' hi hu
theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h
theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) :=
inf_sdiff_distrib_left _ _ _
theorem inter_diff_distrib_right (s t u : Set α) : (s \ t) ∩ u = (s ∩ u) \ (t ∩ u) :=
inf_sdiff_distrib_right _ _ _
theorem diff_inter_distrib_right (s t r : Set α) : (t ∩ r) \ s = (t \ s) ∩ (r \ s) :=
inf_sdiff
/-! ### Lemmas about complement -/
theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } :=
rfl
theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ :=
h
theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } :=
rfl
theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s :=
h
theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s :=
not_not
@[simp]
theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ :=
inf_compl_eq_bot
@[simp]
theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ :=
compl_inf_eq_bot
@[simp]
theorem compl_empty : (∅ : Set α)ᶜ = univ :=
compl_bot
@[simp]
theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ :=
compl_sup
theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ :=
compl_inf
@[simp]
theorem compl_univ : (univ : Set α)ᶜ = ∅ :=
compl_top
@[simp]
theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ :=
compl_eq_bot
@[simp]
theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ :=
compl_eq_top
theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty :=
compl_univ_iff.not.trans nonempty_iff_ne_empty.symm
lemma inl_compl_union_inr_compl {α β : Type*} {s : Set α} {t : Set β} :
Sum.inl '' sᶜ ∪ Sum.inr '' tᶜ = (Sum.inl '' s ∪ Sum.inr '' t)ᶜ := by
rw [compl_union]
aesop
theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ :=
(ne_univ_iff_exists_not_mem s).symm
theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ :=
ext fun _ => or_iff_not_and_not
theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ :=
ext fun _ => and_iff_not_or_not
@[simp]
theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ :=
eq_univ_iff_forall.2 fun _ => em _
@[simp]
theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self]
theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s :=
@compl_le_iff_compl_le _ s _ _
theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ :=
@le_compl_iff_le_compl _ _ _ t
@[simp]
theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s :=
@compl_le_compl_iff_le (Set α) _ _ _
@[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h
theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t :=
(@isCompl_compl _ u _).le_sup_right_iff_inf_left_le
theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ :=
Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left
theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c :=
forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or
theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t :=
(not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm
/-! ### Lemmas about set difference -/
theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx
theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s :=
h.left
theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t :=
h.right
theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm]
theorem diff_nonempty {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t :=
inter_compl_nonempty_iff
theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le
theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ :=
diff_eq_compl_inter ▸ inter_subset_left
theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u :=
sup_sdiff_cancel' h₁ h₂
theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t :=
sup_sdiff_cancel_right h
theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t :=
Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h
theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s :=
Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h
@[simp]
theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s :=
sup_sdiff_left_self
@[simp]
theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u :=
sup_sdiff
@[simp]
theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ :=
inf_sdiff_self_right
@[simp]
theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s :=
sup_inf_sdiff s t
@[simp]
theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by
rw [union_comm]
exact sup_inf_sdiff _ _
@[simp]
theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s :=
inter_union_diff _ _
@[gcongr]
theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ :=
show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff
@[gcongr]
theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t :=
sdiff_le_sdiff_right ‹s₁ ≤ s₂›
@[gcongr]
theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t :=
sdiff_le_sdiff_left ‹t ≤ u›
theorem diff_subset_diff_iff_subset {r : Set α} (hs : s ⊆ r) (ht : t ⊆ r) :
r \ s ⊆ r \ t ↔ t ⊆ s :=
sdiff_le_sdiff_iff_le hs ht
theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s :=
top_sdiff.symm
@[simp]
theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ :=
bot_sdiff
theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t :=
sdiff_eq_bot_iff
@[simp]
theorem diff_empty {s : Set α} : s \ ∅ = s :=
sdiff_bot
@[simp]
theorem diff_univ (s : Set α) : s \ univ = ∅ :=
diff_eq_empty.2 (subset_univ s)
theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) :=
sdiff_sdiff_left
-- the following statement contains parentheses to help the reader
theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t :=
sdiff_sdiff_comm
theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u :=
show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff
theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t :=
show s ≤ s \ t ∪ t from le_sdiff_sup
theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s :=
Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _)
theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t :=
show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm
theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u :=
sdiff_inf
theorem diff_inter_diff : s \ t ∩ (s \ u) = s \ (t ∪ u) :=
sdiff_sup.symm
theorem diff_compl : s \ tᶜ = s ∩ t :=
sdiff_compl
theorem compl_diff : (t \ s)ᶜ = s ∪ tᶜ :=
Eq.trans compl_sdiff himp_eq
theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u :=
sdiff_sdiff_right'
theorem inter_diff_right_comm : (s ∩ t) \ u = s \ u ∩ t := by
rw [diff_eq, diff_eq, inter_right_comm]
theorem diff_inter_right_comm : (s \ u) ∩ t = (s ∩ t) \ u := by
rw [diff_eq, diff_eq, inter_right_comm]
@[simp]
theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t :=
sup_sdiff_self _ _
@[simp]
theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t :=
sdiff_sup_self _ _
@[simp]
theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ :=
inf_sdiff_self_left
@[simp]
theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t :=
sdiff_inf_self_right _ _
@[simp]
theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t :=
sdiff_inf_self_left _ _
theorem diff_self {s : Set α} : s \ s = ∅ :=
sdiff_self
theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t :=
sdiff_sdiff_right_self
theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s :=
sdiff_sdiff_eq_self h
theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t :=
sup_eq_sdiff_sup_sdiff_sup_inf
/-! ### Powerset -/
theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h
theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h
@[simp]
theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s :=
Iff.rfl
theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t :=
ext fun _ => subset_inter_iff
@[simp]
theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t :=
⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩
theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2
@[simp]
theorem powerset_nonempty : (𝒫 s).Nonempty :=
⟨∅, fun _ h => empty_subset s h⟩
@[simp]
theorem powerset_empty : 𝒫(∅ : Set α) = {∅} :=
ext fun _ => subset_empty_iff
@[simp]
theorem powerset_univ : 𝒫(univ : Set α) = univ :=
eq_univ_of_forall subset_univ
/-! ### Sets defined as an if-then-else -/
@[deprecated _root_.mem_dite (since := "2025-01-30")]
protected theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) :
(x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h :=
_root_.mem_dite
theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by
simp [mem_dite]
@[simp]
theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t Set.univ ↔ p → x ∈ t :=
mem_dite_univ_right p (fun _ => t) x
theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by
split_ifs <;> simp_all
@[simp]
theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p Set.univ t ↔ ¬p → x ∈ t :=
mem_dite_univ_left p (fun _ => t) x
theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false, not_not]
exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩
@[simp]
theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t ∅ ↔ p ∧ x ∈ t :=
(mem_dite_empty_right p (fun _ => t) x).trans (by simp)
theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false]
exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩
@[simp]
theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t :=
(mem_dite_empty_left p (fun _ => t) x).trans (by simp)
/-! ### If-then-else for sets -/
/-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`.
Defined as `s ∩ t ∪ s' \ t`. -/
protected def ite (t s s' : Set α) : Set α :=
s ∩ t ∪ s' \ t
@[simp]
theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by
rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty]
@[simp]
theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by
rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq]
@[simp]
theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by
rw [← ite_compl, ite_inter_self]
@[simp]
theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t :=
ite_inter_compl_self t s s'
@[simp]
theorem ite_same (t s : Set α) : t.ite s s = s :=
inter_union_diff _ _
@[simp]
theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite]
@[simp]
theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite]
@[simp]
theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite]
@[simp]
theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite]
@[simp]
theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite]
@[simp]
theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite]
theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') :
t.ite s₁ s₁' ⊆ t.ite s₂ s₂' :=
union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')
theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' :=
union_subset_union inter_subset_left diff_subset
theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' :=
ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right
theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) :
t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by
ext x
simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union]
tauto
theorem ite_inter (t s₁ s₂ s : Set α) : t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s := by
rw [ite_inter_inter, ite_same]
theorem ite_inter_of_inter_eq (t : Set α) {s₁ s₂ s : Set α} (h : s₁ ∩ s = s₂ ∩ s) :
t.ite s₁ s₂ ∩ s = s₁ ∩ s := by rw [← ite_inter, ← h, ite_same]
theorem subset_ite {t s s' u : Set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' := by
simp only [subset_def, ← forall_and]
refine forall_congr' fun x => ?_
by_cases hx : x ∈ t <;> simp [*, Set.ite]
theorem ite_eq_of_subset_left (t : Set α) {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) :
t.ite s₁ s₂ = s₁ ∪ (s₂ \ t) := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_right_of_imp (@h x)]
theorem ite_eq_of_subset_right (t : Set α) {s₁ s₂ : Set α} (h : s₂ ⊆ s₁) :
t.ite s₁ s₂ = (s₁ ∩ t) ∪ s₂ := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_left_of_imp (@h x)]
end Set
open Set
namespace Function
variable {α : Type*} {β : Type*}
theorem Injective.nonempty_apply_iff {f : Set α → Set β} (hf : Injective f) (h2 : f ∅ = ∅)
{s : Set α} : (f s).Nonempty ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, ← h2, nonempty_iff_ne_empty, hf.ne_iff]
end Function
namespace Subsingleton
variable {α : Type*} [Subsingleton α]
theorem eq_univ_of_nonempty {s : Set α} : s.Nonempty → s = univ := fun ⟨x, hx⟩ =>
eq_univ_of_forall fun y => Subsingleton.elim x y ▸ hx
@[elab_as_elim]
theorem set_cases {p : Set α → Prop} (h0 : p ∅) (h1 : p univ) (s) : p s :=
(s.eq_empty_or_nonempty.elim fun h => h.symm ▸ h0) fun h => (eq_univ_of_nonempty h).symm ▸ h1
theorem mem_iff_nonempty {α : Type*} [Subsingleton α] {s : Set α} {x : α} : x ∈ s ↔ s.Nonempty :=
⟨fun hx => ⟨x, hx⟩, fun ⟨y, hy⟩ => Subsingleton.elim y x ▸ hy⟩
end Subsingleton
/-! ### Decidability instances for sets -/
namespace Set
variable {α : Type u} (s t : Set α) (a b : α)
instance decidableSdiff [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s \ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∉ t))
instance decidableInter [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∩ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∈ t))
instance decidableUnion [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∪ t) :=
inferInstanceAs (Decidable (a ∈ s ∨ a ∈ t))
instance decidableCompl [Decidable (a ∈ s)] : Decidable (a ∈ sᶜ) :=
inferInstanceAs (Decidable (a ∉ s))
instance decidableEmptyset : Decidable (a ∈ (∅ : Set α)) := Decidable.isFalse (by simp)
instance decidableUniv : Decidable (a ∈ univ) := Decidable.isTrue (by simp)
instance decidableInsert [Decidable (a = b)] [Decidable (a ∈ s)] : Decidable (a ∈ insert b s) :=
inferInstanceAs (Decidable (_ ∨ _))
instance decidableSetOf (p : α → Prop) [Decidable (p a)] : Decidable (a ∈ { a | p a }) := by
assumption
end Set
variable {α : Type*} {s t u : Set α}
namespace Equiv
/-- Given a predicate `p : α → Prop`, produces an equivalence between
`Set {a : α // p a}` and `{s : Set α // ∀ a ∈ s, p a}`. -/
protected def setSubtypeComm (p : α → Prop) :
Set {a : α // p a} ≃ {s : Set α // ∀ a ∈ s, p a} where
toFun s := ⟨{a | ∃ h : p a, s ⟨a, h⟩}, fun _ h ↦ h.1⟩
invFun s := {a | a.val ∈ s.val}
left_inv s := by ext a; exact ⟨fun h ↦ h.2, fun h ↦ ⟨a.property, h⟩⟩
right_inv s := by ext; exact ⟨fun h ↦ h.2, fun h ↦ ⟨s.property _ h, h⟩⟩
@[simp]
protected lemma setSubtypeComm_apply (p : α → Prop) (s : Set {a // p a}) :
(Equiv.setSubtypeComm p) s = ⟨{a | ∃ h : p a, ⟨a, h⟩ ∈ s}, fun _ h ↦ h.1⟩ :=
rfl
@[simp]
protected lemma setSubtypeComm_symm_apply (p : α → Prop) (s : {s // ∀ a ∈ s, p a}) :
(Equiv.setSubtypeComm p).symm s = {a | a.val ∈ s.val} :=
rfl
end Equiv
| Mathlib/Data/Set/Basic.lean | 1,954 | 1,956 | |
/-
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.Algebra.Module.Basic
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
/-!
# Midpoint of a segment
## Main definitions
* `midpoint R x y`: midpoint of the segment `[x, y]`. We define it for `x` and `y`
in a module over a ring `R` with invertible `2`.
* `AddMonoidHom.ofMapMidpoint`: construct an `AddMonoidHom` given a map `f` such that
`f` sends zero to zero and midpoints to midpoints.
## Main theorems
* `midpoint_eq_iff`: `z` is the midpoint of `[x, y]` if and only if `x + y = z + z`,
* `midpoint_unique`: `midpoint R x y` does not depend on `R`;
* `midpoint x y` is linear both in `x` and `y`;
* `pointReflection_midpoint_left`, `pointReflection_midpoint_right`:
`Equiv.pointReflection (midpoint R x y)` swaps `x` and `y`.
We do not mark most lemmas as `@[simp]` because it is hard to tell which side is simpler.
## Tags
midpoint, AddMonoidHom
-/
open AffineMap AffineEquiv
section
variable (R : Type*) {V V' P P' : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup V]
[Module R V] [AddTorsor V P] [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
/-- `midpoint x y` is the midpoint of the segment `[x, y]`. -/
def midpoint (x y : P) : P :=
lineMap x y (⅟ 2 : R)
variable {R} {x y z : P}
@[simp]
theorem AffineMap.map_midpoint (f : P →ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
@[simp]
theorem AffineEquiv.map_midpoint (f : P ≃ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
theorem AffineEquiv.pointReflection_midpoint_left (x y : P) :
pointReflection R (midpoint R x y) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
@[simp]
theorem Equiv.pointReflection_midpoint_left (x y : P) :
(Equiv.pointReflection (midpoint R x y)) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
theorem midpoint_comm (x y : P) : midpoint R x y = midpoint R y x := by
rw [midpoint, ← lineMap_apply_one_sub, one_sub_invOf_two, midpoint]
theorem AffineEquiv.pointReflection_midpoint_right (x y : P) :
pointReflection R (midpoint R x y) y = x := by
rw [midpoint_comm, AffineEquiv.pointReflection_midpoint_left]
@[simp]
theorem Equiv.pointReflection_midpoint_right (x y : P) :
(Equiv.pointReflection (midpoint R x y)) y = x := by
rw [midpoint_comm, Equiv.pointReflection_midpoint_left]
theorem midpoint_vsub_midpoint (p₁ p₂ p₃ p₄ : P) :
midpoint R p₁ p₂ -ᵥ midpoint R p₃ p₄ = midpoint R (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) :=
lineMap_vsub_lineMap _ _ _ _ _
|
theorem midpoint_vadd_midpoint (v v' : V) (p p' : P) :
midpoint R v v' +ᵥ midpoint R p p' = midpoint R (v +ᵥ p) (v' +ᵥ p') :=
| Mathlib/LinearAlgebra/AffineSpace/Midpoint.lean | 83 | 85 |
/-
Copyright (c) 2023 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.AlgebraicGeometry.EllipticCurve.Affine
import Mathlib.LinearAlgebra.FreeModule.Norm
import Mathlib.RingTheory.ClassGroup
import Mathlib.RingTheory.Polynomial.UniqueFactorization
/-!
# Group law on Weierstrass curves
This file proves that the nonsingular rational points on a Weierstrass curve form an abelian group
under the geometric group law defined in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`.
## Mathematical background
Let `W` be a Weierstrass curve over a field `F` given by a Weierstrass equation `W(X, Y) = 0` in
affine coordinates. As in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`, the set of
nonsingular rational points `W⟮F⟯` of `W` consist of the unique point at infinity `𝓞` and
nonsingular affine points `(x, y)`. With this description, there is an addition-preserving injection
between `W⟮F⟯` and the ideal class group of the *affine coordinate ring*
`F[W] := F[X, Y] / ⟨W(X, Y)⟩` of `W`. This is given by mapping `𝓞` to the trivial ideal class and a
nonsingular affine point `(x, y)` to the ideal class of the invertible ideal `⟨X - x, Y - y⟩`.
Proving that this is well-defined and preserves addition reduces to equalities of integral ideals
checked in `WeierstrassCurve.Affine.CoordinateRing.XYIdeal_neg_mul` and in
`WeierstrassCurve.Affine.CoordinateRing.XYIdeal_mul_XYIdeal` via explicit ideal computations.
Now `F[W]` is a free rank two `F[X]`-algebra with basis `{1, Y}`, so every element of `F[W]` is of
the form `p + qY` for some `p, q` in `F[X]`, and there is an algebra norm `N : F[W] → F[X]`.
Injectivity can then be shown by computing the degree of such a norm `N(p + qY)` in two different
ways, which is done in `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis` and in the
auxiliary lemmas in the proof of `WeierstrassCurve.Affine.Point.instAddCommGroup`.
## Main definitions
* `WeierstrassCurve.Affine.CoordinateRing`: the coordinate ring `F[W]` of a Weierstrass curve `W`.
* `WeierstrassCurve.Affine.CoordinateRing.basis`: the power basis of `F[W]` over `F[X]`.
## Main statements
* `WeierstrassCurve.Affine.CoordinateRing.instIsDomainCoordinateRing`: the affine coordinate ring
of a Weierstrass curve is an integral domain.
* `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis`: the degree of the norm of an
element in the affine coordinate ring in terms of its power basis.
* `WeierstrassCurve.Affine.Point.instAddCommGroup`: the type of nonsingular points `W⟮F⟯` in affine
coordinates forms an abelian group under addition.
## References
https://drops.dagstuhl.de/storage/00lipics/lipics-vol268-itp2023/LIPIcs.ITP.2023.6/LIPIcs.ITP.2023.6.pdf
## Tags
elliptic curve, group law, class group
-/
open Ideal Polynomial
open scoped nonZeroDivisors Polynomial.Bivariate
local macro "C_simp" : tactic =>
`(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow])
local macro "eval_simp" : tactic =>
`(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow])
universe u v
namespace WeierstrassCurve.Affine
/-! ## Weierstrass curves in affine coordinates -/
variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] (W : Affine R) (f : R →+* S)
-- Porting note: in Lean 3, this is a `def` under a `derive comm_ring` tag.
-- This generates a reducible instance of `comm_ring` for `coordinate_ring`. In certain
-- circumstances this might be extremely slow, because all instances in its definition are unified
-- exponentially many times. In this case, one solution is to manually add the local attribute
-- `local attribute [irreducible] coordinate_ring.comm_ring` to block this type-level unification.
-- In Lean 4, this is no longer an issue and is now an `abbrev`. See Zulip thread:
-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/.E2.9C.94.20class_group.2Emk
/-- The affine coordinate ring `R[W] := R[X, Y] / ⟨W(X, Y)⟩` of a Weierstrass curve `W`. -/
abbrev CoordinateRing : Type u :=
AdjoinRoot W.polynomial
/-- The function field `R(W) := Frac(R[W])` of a Weierstrass curve `W`. -/
abbrev FunctionField : Type u :=
FractionRing W.CoordinateRing
namespace CoordinateRing
section Algebra
/-! ### The coordinate ring as an `R[X]`-algebra -/
noncomputable instance : Algebra R W.CoordinateRing :=
Quotient.algebra R
noncomputable instance : Algebra R[X] W.CoordinateRing :=
Quotient.algebra R[X]
instance : IsScalarTower R R[X] W.CoordinateRing :=
Quotient.isScalarTower R R[X] _
instance [Subsingleton R] : Subsingleton W.CoordinateRing :=
Module.subsingleton R[X] _
/-- The natural ring homomorphism mapping `R[X][Y]` to `R[W]`. -/
noncomputable abbrev mk : R[X][Y] →+* W.CoordinateRing :=
AdjoinRoot.mk W.polynomial
/-- The power basis `{1, Y}` for `R[W]` over `R[X]`. -/
protected noncomputable def basis : Basis (Fin 2) R[X] W.CoordinateRing := by
classical exact (subsingleton_or_nontrivial R).by_cases (fun _ => default) fun _ =>
(AdjoinRoot.powerBasis' W.monic_polynomial).basis.reindex <| finCongr W.natDegree_polynomial
lemma basis_apply (n : Fin 2) :
CoordinateRing.basis W n = (AdjoinRoot.powerBasis' W.monic_polynomial).gen ^ (n : ℕ) := by
classical
nontriviality R
rw [CoordinateRing.basis, Or.by_cases, dif_neg <| not_subsingleton R, Basis.reindex_apply,
PowerBasis.basis_eq_pow]
rfl
@[simp]
lemma basis_zero : CoordinateRing.basis W 0 = 1 := by
simpa only [basis_apply] using pow_zero _
@[simp]
lemma basis_one : CoordinateRing.basis W 1 = mk W Y := by
simpa only [basis_apply] using pow_one _
lemma coe_basis : (CoordinateRing.basis W : Fin 2 → W.CoordinateRing) = ![1, mk W Y] := by
ext n
fin_cases n
exacts [basis_zero W, basis_one W]
variable {W} in
lemma smul (x : R[X]) (y : W.CoordinateRing) : x • y = mk W (C x) * y :=
(algebraMap_smul W.CoordinateRing x y).symm
variable {W} in
lemma smul_basis_eq_zero {p q : R[X]} (hpq : p • (1 : W.CoordinateRing) + q • mk W Y = 0) :
p = 0 ∧ q = 0 := by
have h := Fintype.linearIndependent_iff.mp (CoordinateRing.basis W).linearIndependent ![p, q]
rw [Fin.sum_univ_succ, basis_zero, Fin.sum_univ_one, Fin.succ_zero_eq_one, basis_one] at h
exact ⟨h hpq 0, h hpq 1⟩
variable {W} in
lemma exists_smul_basis_eq (x : W.CoordinateRing) :
∃ p q : R[X], p • (1 : W.CoordinateRing) + q • mk W Y = x := by
have h := (CoordinateRing.basis W).sum_equivFun x
rw [Fin.sum_univ_succ, Fin.sum_univ_one, basis_zero, Fin.succ_zero_eq_one, basis_one] at h
exact ⟨_, _, h⟩
lemma smul_basis_mul_C (y : R[X]) (p q : R[X]) :
(p • (1 : W.CoordinateRing) + q • mk W Y) * mk W (C y) =
(p * y) • (1 : W.CoordinateRing) + (q * y) • mk W Y := by
simp only [smul, map_mul]
ring1
lemma smul_basis_mul_Y (p q : R[X]) : (p • (1 : W.CoordinateRing) + q • mk W Y) * mk W Y =
(q * (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆)) • (1 : W.CoordinateRing) +
(p - q * (C W.a₁ * X + C W.a₃)) • mk W Y := by
have Y_sq : mk W Y ^ 2 =
mk W (C (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆) - C (C W.a₁ * X + C W.a₃) * Y) := by
exact AdjoinRoot.mk_eq_mk.mpr ⟨1, by rw [polynomial]; ring1⟩
simp only [smul, add_mul, mul_assoc, ← sq, Y_sq, C_sub, map_sub, C_mul, map_mul]
ring1
/-- The ring homomorphism `R[W] →+* S[W.map f]` induced by a ring homomorphism `f : R →+* S`. -/
noncomputable def map : W.CoordinateRing →+* (W.map f).toAffine.CoordinateRing :=
AdjoinRoot.lift ((AdjoinRoot.of _).comp <| mapRingHom f)
((AdjoinRoot.root (WeierstrassCurve.map W f).toAffine.polynomial)) <| by
rw [← eval₂_map, ← map_polynomial, AdjoinRoot.eval₂_root]
lemma map_mk (x : R[X][Y]) : map W f (mk W x) = mk (W.map f) (x.map <| mapRingHom f) := by
rw [map, AdjoinRoot.lift_mk, ← eval₂_map]
exact AdjoinRoot.aeval_eq <| x.map <| mapRingHom f
variable {W} in
protected lemma map_smul (x : R[X]) (y : W.CoordinateRing) :
map W f (x • y) = x.map f • map W f y := by
rw [smul, map_mul, map_mk, map_C, smul]
rfl
variable {f} in
lemma map_injective (hf : Function.Injective f) : Function.Injective <| map W f :=
(injective_iff_map_eq_zero _).mpr fun y hy => by
obtain ⟨p, q, rfl⟩ := exists_smul_basis_eq y
simp_rw [map_add, CoordinateRing.map_smul, map_one, map_mk, map_X] at hy
obtain ⟨hp, hq⟩ := smul_basis_eq_zero hy
rw [Polynomial.map_eq_zero_iff hf] at hp hq
simp_rw [hp, hq, zero_smul, add_zero]
instance [IsDomain R] : IsDomain W.CoordinateRing :=
have : IsDomain (W.map <| algebraMap R <| FractionRing R).toAffine.CoordinateRing :=
AdjoinRoot.isDomain_of_prime irreducible_polynomial.prime
(map_injective W <| IsFractionRing.injective R <| FractionRing R).isDomain
end Algebra
section Ring
/-! ### Ideals in the coordinate ring over a ring -/
/-- The class of the element `X - x` in `R[W]` for some `x` in `R`. -/
noncomputable def XClass (x : R) : W.CoordinateRing :=
mk W <| C <| X - C x
lemma XClass_ne_zero [Nontrivial R] (x : R) : XClass W x ≠ 0 :=
AdjoinRoot.mk_ne_zero_of_natDegree_lt W.monic_polynomial (C_ne_zero.mpr <| X_sub_C_ne_zero x) <|
by rw [natDegree_polynomial, natDegree_C]; norm_num1
/-- The class of the element `Y - y(X)` in `R[W]` for some `y(X)` in `R[X]`. -/
noncomputable def YClass (y : R[X]) : W.CoordinateRing :=
mk W <| Y - C y
lemma YClass_ne_zero [Nontrivial R] (y : R[X]) : YClass W y ≠ 0 :=
AdjoinRoot.mk_ne_zero_of_natDegree_lt W.monic_polynomial (X_sub_C_ne_zero y) <|
by rw [natDegree_polynomial, natDegree_X_sub_C]; norm_num1
lemma C_addPolynomial (x y L : R) : mk W (C <| W.addPolynomial x y L) =
mk W ((Y - C (linePolynomial x y L)) * (W.negPolynomial - C (linePolynomial x y L))) :=
AdjoinRoot.mk_eq_mk.mpr ⟨1, by rw [W.C_addPolynomial, add_sub_cancel_left, mul_one]⟩
/-- The ideal `⟨X - x⟩` of `R[W]` for some `x` in `R`. -/
noncomputable def XIdeal (x : R) : Ideal W.CoordinateRing :=
span {XClass W x}
/-- The ideal `⟨Y - y(X)⟩` of `R[W]` for some `y(X)` in `R[X]`. -/
noncomputable def YIdeal (y : R[X]) : Ideal W.CoordinateRing :=
span {YClass W y}
/-- The ideal `⟨X - x, Y - y(X)⟩` of `R[W]` for some `x` in `R` and `y(X)` in `R[X]`. -/
noncomputable def XYIdeal (x : R) (y : R[X]) : Ideal W.CoordinateRing :=
span {XClass W x, YClass W y}
lemma XYIdeal_eq₁ (x y L : R) : XYIdeal W x (C y) = XYIdeal W x (linePolynomial x y L) := by
simp only [XYIdeal, XClass, YClass, linePolynomial]
rw [← span_pair_add_mul_right <| mk W <| C <| C <| -L, ← map_mul, ← map_add]
apply congr_arg (_ ∘ _ ∘ _ ∘ _)
C_simp
ring1
lemma XYIdeal_add_eq (x₁ x₂ y₁ L : R) : XYIdeal W (W.addX x₁ x₂ L) (C <| W.addY x₁ x₂ y₁ L) =
span {mk W <| W.negPolynomial - C (linePolynomial x₁ y₁ L)} ⊔ XIdeal W (W.addX x₁ x₂ L) := by
simp only [XYIdeal, XIdeal, XClass, YClass, addY, negAddY, negY, negPolynomial, linePolynomial]
rw [sub_sub <| -(Y : R[X][Y]), neg_sub_left (Y : R[X][Y]), map_neg, span_singleton_neg, sup_comm,
← span_insert, ← span_pair_add_mul_right <| mk W <| C <| C <| W.a₁ + L, ← map_mul,
← map_add]
apply congr_arg (_ ∘ _ ∘ _ ∘ _)
C_simp
ring1
/-- The `R`-algebra isomorphism from `R[W] / ⟨X - x, Y - y(X)⟩` to `R` obtained by evaluation at
some `y(X)` in `R[X]` and at some `x` in `R` provided that `W(x, y(x)) = 0`. -/
noncomputable def quotientXYIdealEquiv {x : R} {y : R[X]} (h : (W.polynomial.eval y).eval x = 0) :
(W.CoordinateRing ⧸ XYIdeal W x y) ≃ₐ[R] R :=
((quotientEquivAlgOfEq R <| by
simp only [XYIdeal, XClass, YClass, ← Set.image_pair, ← map_span]; rfl).trans <|
DoubleQuot.quotQuotEquivQuotOfLEₐ R <| (span_singleton_le_iff_mem _).mpr <|
mem_span_C_X_sub_C_X_sub_C_iff_eval_eval_eq_zero.mpr h).trans
quotientSpanCXSubCXSubCAlgEquiv
end Ring
section Field
/-! ### Ideals in the coordinate ring over a field -/
variable {F : Type u} [Field F] {W : Affine F}
lemma C_addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
mk W (C <| W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) =
-(XClass W x₁ * XClass W x₂ * XClass W (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)) :=
congr_arg (mk W) <| W.C_addPolynomial_slope h₁ h₂ hxy
lemma XYIdeal_eq₂ {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁)
(h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
XYIdeal W x₂ (C y₂) = XYIdeal W x₂ (linePolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
have hy₂ : y₂ = (linePolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂).eval x₂ := by
by_cases hx : x₁ = x₂
· have hy : y₁ ≠ W.negY x₂ y₂ := fun h => hxy ⟨hx, h⟩
rcases hx, Y_eq_of_Y_ne h₁ h₂ hx hy with ⟨rfl, rfl⟩
field_simp [linePolynomial, sub_ne_zero_of_ne hy]
· field_simp [linePolynomial, slope_of_X_ne hx, sub_ne_zero_of_ne hx]
ring1
nth_rw 1 [hy₂]
simp only [XYIdeal, XClass, YClass, linePolynomial]
rw [← span_pair_add_mul_right <| mk W <| C <| C <| -W.slope x₁ x₂ y₁ y₂, ← map_mul,
← map_add]
apply congr_arg (_ ∘ _ ∘ _ ∘ _)
eval_simp
C_simp
ring1
lemma XYIdeal_neg_mul {x y : F} (h : W.Nonsingular x y) :
XYIdeal W x (C <| W.negY x y) * XYIdeal W x (C y) = XIdeal W x := by
have Y_rw : (Y - C (C y)) * (Y - C (C <| W.negY x y)) -
C (X - C x) * (C (X ^ 2 + C (x + W.a₂) * X + C (x ^ 2 + W.a₂ * x + W.a₄)) - C (C W.a₁) * Y) =
W.polynomial * 1 := by
linear_combination (norm := (rw [negY, polynomial]; C_simp; ring1))
congr_arg C (congr_arg C ((equation_iff ..).mp h.left).symm)
simp_rw [XYIdeal, XClass, YClass, span_pair_mul_span_pair, mul_comm, ← map_mul,
AdjoinRoot.mk_eq_mk.mpr ⟨1, Y_rw⟩, map_mul, span_insert,
← span_singleton_mul_span_singleton, ← Ideal.mul_sup, ← span_insert]
convert mul_top (_ : Ideal W.CoordinateRing) using 2
simp_rw [← Set.image_singleton (f := mk W), ← Set.image_insert_eq, ← map_span]
convert map_top (R := F[X][Y]) (mk W) using 1
apply congr_arg
simp_rw [eq_top_iff_one, mem_span_insert', mem_span_singleton']
rcases ((nonsingular_iff' ..).mp h).right with hx | hy
· let W_X := W.a₁ * y - (3 * x ^ 2 + 2 * W.a₂ * x + W.a₄)
refine
⟨C <| C W_X⁻¹ * -(X + C (2 * x + W.a₂)), C <| C <| W_X⁻¹ * W.a₁, 0, C <| C <| W_X⁻¹ * -1, ?_⟩
rw [← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hx]
simp only [W_X, mul_add, ← mul_assoc, ← C_mul, mul_inv_cancel₀ hx]
C_simp
ring1
· let W_Y := 2 * y + W.a₁ * x + W.a₃
refine ⟨0, C <| C W_Y⁻¹, C <| C <| W_Y⁻¹ * -1, 0, ?_⟩
rw [negY, ← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hy]
simp only [W_Y, mul_add, ← mul_assoc, ← C_mul, mul_inv_cancel₀ hy]
C_simp
ring1
private lemma XYIdeal'_mul_inv {x y : F} (h : W.Nonsingular x y) :
XYIdeal W x (C y) * (XYIdeal W x (C <| W.negY x y) *
(XIdeal W x : FractionalIdeal W.CoordinateRing⁰ W.FunctionField)⁻¹) = 1 := by
rw [← mul_assoc, ← FractionalIdeal.coeIdeal_mul, mul_comm <| XYIdeal W .., XYIdeal_neg_mul h,
XIdeal, FractionalIdeal.coe_ideal_span_singleton_mul_inv W.FunctionField <| XClass_ne_zero W x]
lemma XYIdeal_mul_XYIdeal {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
XIdeal W (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) * (XYIdeal W x₁ (C y₁) * XYIdeal W x₂ (C y₂)) =
YIdeal W (linePolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) *
XYIdeal W (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)
(C <| W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
have sup_rw : ∀ a b c d : Ideal W.CoordinateRing, a ⊔ (b ⊔ (c ⊔ d)) = a ⊔ d ⊔ b ⊔ c :=
fun _ _ c _ => by rw [← sup_assoc, sup_comm c, sup_sup_sup_comm, ← sup_assoc]
rw [XYIdeal_add_eq, XIdeal, mul_comm, XYIdeal_eq₁ W x₁ y₁ <| W.slope x₁ x₂ y₁ y₂, XYIdeal,
XYIdeal_eq₂ h₁ h₂ hxy, XYIdeal, span_pair_mul_span_pair]
simp_rw [span_insert, sup_rw, Ideal.sup_mul, span_singleton_mul_span_singleton]
rw [← neg_eq_iff_eq_neg.mpr <| C_addPolynomial_slope h₁ h₂ hxy, span_singleton_neg,
C_addPolynomial, map_mul, YClass]
simp_rw [mul_comm <| XClass W x₁, mul_assoc, ← span_singleton_mul_span_singleton, ← Ideal.mul_sup]
rw [span_singleton_mul_span_singleton, ← span_insert,
← span_pair_add_mul_right <| -(XClass W <| W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂), mul_neg,
← sub_eq_add_neg, ← sub_mul, ← map_sub <| mk W, sub_sub_sub_cancel_right, span_insert,
← span_singleton_mul_span_singleton, ← sup_rw, ← Ideal.sup_mul, ← Ideal.sup_mul]
apply congr_arg (_ ∘ _)
convert top_mul (_ : Ideal W.CoordinateRing)
simp_rw [XClass, ← Set.image_singleton (f := mk W), ← map_span, ← Ideal.map_sup, eq_top_iff_one,
mem_map_iff_of_surjective _ AdjoinRoot.mk_surjective, ← span_insert, mem_span_insert',
mem_span_singleton']
by_cases hx : x₁ = x₂
· have hy : y₁ ≠ W.negY x₂ y₂ := fun h => hxy ⟨hx, h⟩
rcases hx, Y_eq_of_Y_ne h₁ h₂ hx hy with ⟨rfl, rfl⟩
let y := (y₁ - W.negY x₁ y₁) ^ 2
replace hxy := pow_ne_zero 2 <| sub_ne_zero_of_ne hy
refine ⟨1 + C (C <| y⁻¹ * 4) * W.polynomial,
⟨C <| C y⁻¹ * (C 4 * X ^ 2 + C (4 * x₁ + W.b₂) * X + C (4 * x₁ ^ 2 + W.b₂ * x₁ + 2 * W.b₄)),
0, C (C y⁻¹) * (Y - W.negPolynomial), ?_⟩, by
rw [map_add, map_one, map_mul <| mk W, AdjoinRoot.mk_self, mul_zero, add_zero]⟩
rw [polynomial, negPolynomial, ← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hxy]
simp only [y, mul_add, ← mul_assoc, ← C_mul, mul_inv_cancel₀ hxy]
linear_combination (norm := (rw [b₂, b₄, negY]; C_simp; ring1))
-4 * congr_arg C (congr_arg C <| (equation_iff ..).mp h₁)
· replace hx := sub_ne_zero_of_ne hx
refine ⟨_, ⟨⟨C <| C (x₁ - x₂)⁻¹, C <| C <| (x₁ - x₂)⁻¹ * -1, 0, ?_⟩, map_one _⟩⟩
rw [← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hx]
simp only [← mul_assoc, mul_add, ← C_mul, mul_inv_cancel₀ hx]
C_simp
ring1
/-- The non-zero fractional ideal `⟨X - x, Y - y⟩` of `F(W)` for some `x` and `y` in `F`. -/
noncomputable def XYIdeal' {x y : F} (h : W.Nonsingular x y) :
(FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ :=
Units.mkOfMulEqOne _ _ <| XYIdeal'_mul_inv h
lemma XYIdeal'_eq {x y : F} (h : W.Nonsingular x y) :
(XYIdeal' h : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) = XYIdeal W x (C y) :=
rfl
lemma mk_XYIdeal'_neg_mul {x y : F} (h : W.Nonsingular x y) :
| ClassGroup.mk (XYIdeal' <| (nonsingular_neg ..).mpr h) * ClassGroup.mk (XYIdeal' h) = 1 := by
rw [← map_mul]
exact (ClassGroup.mk_eq_one_of_coe_ideal <| (FractionalIdeal.coeIdeal_mul ..).symm.trans <|
FractionalIdeal.coeIdeal_inj.mpr <| XYIdeal_neg_mul h).mpr ⟨_, XClass_ne_zero W _, rfl⟩
| Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean | 389 | 393 |
/-
Copyright (c) 2019 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Lu-Ming Zhang
-/
import Mathlib.Data.Matrix.Invertible
import Mathlib.Data.Matrix.Kronecker
import Mathlib.LinearAlgebra.FiniteDimensional.Basic
import Mathlib.LinearAlgebra.Matrix.Adjugate
import Mathlib.LinearAlgebra.Matrix.SemiringInverse
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.LinearAlgebra.Matrix.Trace
/-!
# Nonsingular inverses
In this file, we define an inverse for square matrices of invertible determinant.
For matrices that are not square or not of full rank, there is a more general notion of
pseudoinverses which we do not consider here.
The definition of inverse used in this file is the adjugate divided by the determinant.
We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`),
will result in a multiplicative inverse to `A`.
Note that there are at least three different inverses in mathlib:
* `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in
conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no
inverse exists.
* `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an
inverse exists.
* `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is
defined to be zero when no inverse exists.
We start by working with `Invertible`, and show the main results:
* `Matrix.invertibleOfDetInvertible`
* `Matrix.detInvertibleOfInvertible`
* `Matrix.isUnit_iff_isUnit_det`
* `Matrix.mul_eq_one_comm`
After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`.
The rest of the results in the file are then about `A⁻¹`
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
matrix inverse, cramer, cramer's rule, adjugate
-/
namespace Matrix
universe u u' v
variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v}
open Matrix Equiv Equiv.Perm Finset
/-! ### Matrices are `Invertible` iff their determinants are -/
section Invertible
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
/-- If `A.det` has a constructive inverse, produce one for `A`. -/
def invertibleOfDetInvertible [Invertible A.det] : Invertible A where
invOf := ⅟ A.det • A.adjugate
mul_invOf_self := by
rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul]
invOf_mul_self := by
rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul]
theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by
letI := invertibleOfDetInvertible A
convert (rfl : ⅟ A = _)
/-- `A.det` is invertible if `A` has a left inverse. -/
def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one]
invOf_mul_self := by rw [← det_mul, h, det_one]
/-- `A.det` is invertible if `A` has a right inverse. -/
def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [← det_mul, h, det_one]
invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one]
/-- If `A` has a constructive inverse, produce one for `A.det`. -/
def detInvertibleOfInvertible [Invertible A] : Invertible A.det :=
detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _)
theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by
letI := detInvertibleOfInvertible A
convert (rfl : _ = ⅟ A.det)
/-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an
equivalence, although both sides of the equiv are subsingleton anyway. -/
@[simps]
def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where
toFun := @detInvertibleOfInvertible _ _ _ _ _ A
invFun := @invertibleOfDetInvertible _ _ _ _ _ A
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ` -/
def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ :=
@unitOfInvertible _ _ A (invertibleOfDetInvertible A)
/-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/
theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by
simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr]
@[simp]
theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det :=
isUnit_iff_isUnit_det _ |>.mp A.isUnit
/-! #### Variants of the statements above with `IsUnit` -/
theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A)
variable {A B}
theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h)
theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h)
theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 :=
(isUnit_det_of_left_inverse h).ne_zero
theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 :=
(isUnit_det_of_right_inverse h).ne_zero
end Invertible
section Inv
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by
rw [det_transpose]
exact h
/-! ### A noncomputable `Inv` instance -/
/-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/
noncomputable instance inv : Inv (Matrix n n α) :=
⟨fun A => Ring.inverse A.det • A.adjugate⟩
theorem inv_def (A : Matrix n n α) : A⁻¹ = Ring.inverse A.det • A.adjugate :=
rfl
theorem nonsing_inv_apply_not_isUnit (h : ¬IsUnit A.det) : A⁻¹ = 0 := by
rw [inv_def, Ring.inverse_non_unit _ h, zero_smul]
theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by
rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec]
/-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/
@[simp]
theorem invOf_eq_nonsing_inv [Invertible A] : ⅟ A = A⁻¹ := by
letI := detInvertibleOfInvertible A
rw [inv_def, Ring.inverse_invertible, invOf_eq]
/-- Coercing the result of `Units.instInv` is the same as coercing first and applying the
nonsingular inverse. -/
@[simp, norm_cast]
theorem coe_units_inv (A : (Matrix n n α)ˣ) : ↑A⁻¹ = (A⁻¹ : Matrix n n α) := by
letI := A.invertible
rw [← invOf_eq_nonsing_inv, invOf_units]
/-- The nonsingular inverse is the same as the general `Ring.inverse`. -/
theorem nonsing_inv_eq_ringInverse : A⁻¹ = Ring.inverse A := by
by_cases h_det : IsUnit A.det
· cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible
rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible]
· have h := mt A.isUnit_iff_isUnit_det.mp h_det
rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det]
@[deprecated (since := "2025-04-22")]
alias nonsing_inv_eq_ring_inverse := nonsing_inv_eq_ringInverse
theorem transpose_nonsing_inv : A⁻¹ᵀ = Aᵀ⁻¹ := by
rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]
theorem conjTranspose_nonsing_inv [StarRing α] : A⁻¹ᴴ = Aᴴ⁻¹ := by
rw [inv_def, inv_def, conjTranspose_smul, det_conjTranspose, adjugate_conjTranspose,
Ring.inverse_star]
/-- The `nonsing_inv` of `A` is a right inverse. -/
@[simp]
theorem mul_nonsing_inv (h : IsUnit A.det) : A * A⁻¹ = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, mul_invOf_self]
/-- The `nonsing_inv` of `A` is a left inverse. -/
@[simp]
theorem nonsing_inv_mul (h : IsUnit A.det) : A⁻¹ * A = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, invOf_mul_self]
instance [Invertible A] : Invertible A⁻¹ := by
rw [← invOf_eq_nonsing_inv]
infer_instance
@[simp]
theorem inv_inv_of_invertible [Invertible A] : A⁻¹⁻¹ = A := by
simp only [← invOf_eq_nonsing_inv, invOf_invOf]
@[simp]
theorem mul_nonsing_inv_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A * A⁻¹ = B := by
simp [Matrix.mul_assoc, mul_nonsing_inv A h]
@[simp]
theorem mul_nonsing_inv_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A * (A⁻¹ * B) = B := by
simp [← Matrix.mul_assoc, mul_nonsing_inv A h]
@[simp]
theorem nonsing_inv_mul_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A⁻¹ * A = B := by
simp [Matrix.mul_assoc, nonsing_inv_mul A h]
@[simp]
theorem nonsing_inv_mul_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A⁻¹ * (A * B) = B := by
simp [← Matrix.mul_assoc, nonsing_inv_mul A h]
@[simp]
theorem mul_inv_of_invertible [Invertible A] : A * A⁻¹ = 1 :=
mul_nonsing_inv A (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_of_invertible [Invertible A] : A⁻¹ * A = 1 :=
nonsing_inv_mul A (isUnit_det_of_invertible A)
@[simp]
theorem mul_inv_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A * A⁻¹ = B :=
mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A)
@[simp]
theorem mul_inv_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A * (A⁻¹ * B) = B :=
mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A⁻¹ * A = B :=
| nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A)
@[simp]
| Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean | 257 | 259 |
/-
Copyright (c) 2021 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster, Eric Wieser
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.FreeAlgebra
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.SimpleRing.Basic
/-!
# Characteristics of algebras
In this file we describe the characteristic of `R`-algebras.
In particular we are interested in the characteristic of free algebras over `R`
and the fraction field `FractionRing R`.
## Main results
- `charP_of_injective_algebraMap` If `R →+* A` is an injective algebra map
then `A` has the same characteristic as `R`.
Instances constructed from this result:
- Any `FreeAlgebra R X` has the same characteristic as `R`.
- The `FractionRing R` of an integral domain `R` has the same characteristic as `R`.
-/
/-- Given `R →+* A`, then `char A ∣ char R`. -/
theorem CharP.dvd_of_ringHom {R A : Type*} [NonAssocSemiring R] [NonAssocSemiring A]
(f : R →+* A) (p q : ℕ) [CharP R p] [CharP A q] : q ∣ p := by
| refine (CharP.cast_eq_zero_iff A q p).mp ?_
rw [← map_natCast f p, CharP.cast_eq_zero, map_zero]
/-- Given `R →+* A`, where `R` is a domain with `char R > 0`, then `char A = char R`. -/
| Mathlib/Algebra/CharP/Algebra.lean | 34 | 37 |
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.LatticeIntervals
import Mathlib.Order.Interval.Set.OrdConnected
/-! # Subtypes of conditionally complete linear orders
In this file we give conditions on a subset of a conditionally complete linear order, to ensure that
the subtype is itself conditionally complete.
We check that an `OrdConnected` set satisfies these conditions.
## TODO
Add appropriate instances for all `Set.Ixx`. This requires a refactor that will allow different
default values for `sSup` and `sInf`.
-/
assert_not_exists Multiset
open Set
variable {ι : Sort*} {α : Type*} (s : Set α)
section SupSet
variable [Preorder α] [SupSet α]
open Classical in
/-- `SupSet` structure on a nonempty subset `s` of a preorder with `SupSet`. This definition is
non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the
construction of the `ConditionallyCompleteLinearOrder` structure. -/
noncomputable def subsetSupSet [Inhabited s] : SupSet s where
sSup t :=
if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s
then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩
else default
attribute [local instance] subsetSupSet
open Classical in
@[simp]
theorem subset_sSup_def [Inhabited s] :
@sSup s _ = fun t =>
if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s
then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩
else default :=
rfl
theorem subset_sSup_of_within [Inhabited s] {t : Set s}
(h' : t.Nonempty) (h'' : BddAbove t) (h : sSup ((↑) '' t : Set α) ∈ s) :
sSup ((↑) '' t : Set α) = (@sSup s _ t : α) := by simp [dif_pos, h, h', h'']
theorem subset_sSup_emptyset [Inhabited s] :
sSup (∅ : Set s) = default := by
simp [sSup]
theorem subset_sSup_of_not_bddAbove [Inhabited s] {t : Set s} (ht : ¬BddAbove t) :
sSup t = default := by
simp [sSup, ht]
end SupSet
section InfSet
variable [Preorder α] [InfSet α]
open Classical in
/-- `InfSet` structure on a nonempty subset `s` of a preorder with `InfSet`. This definition is
non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the
construction of the `ConditionallyCompleteLinearOrder` structure. -/
noncomputable def subsetInfSet [Inhabited s] : InfSet s where
sInf t :=
if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s
then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩
else default
attribute [local instance] subsetInfSet
open Classical in
@[simp]
theorem subset_sInf_def [Inhabited s] :
@sInf s _ = fun t =>
if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s
then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩ else
default :=
rfl
theorem subset_sInf_of_within [Inhabited s] {t : Set s}
(h' : t.Nonempty) (h'' : BddBelow t) (h : sInf ((↑) '' t : Set α) ∈ s) :
sInf ((↑) '' t : Set α) = (@sInf s _ t : α) := by simp [dif_pos, h, h', h'']
| theorem subset_sInf_emptyset [Inhabited s] :
sInf (∅ : Set s) = default := by
simp [sInf]
| Mathlib/Order/CompleteLatticeIntervals.lean | 97 | 99 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.BooleanAlgebra
/-!
# The set lattice
This file is a collection of results on the complete atomic boolean algebra structure of `Set α`.
Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`.
## Main declarations
* `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and
`⋃₀ s = ⋃ x ∈ s, x`.
* `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`,
`< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference.
See `Set.instBooleanAlgebra`.
* `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `⋃ i, s i` is called `iUnion`
* `⋂ i, s i` is called `iInter`
* `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`.
* `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`.
* `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂`
where `j : i ∈ s`.
* `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂`
where `j : i ∈ s`.
## Notation
* `⋃`: `Set.iUnion`
* `⋂`: `Set.iInter`
* `⋃₀`: `Set.sUnion`
* `⋂₀`: `Set.sInter`
-/
open Function Set
universe u
variable {α β γ δ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*}
namespace Set
/-! ### Complete lattice and complete Boolean algebra instances -/
theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by
simp_rw [mem_iUnion]
theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by
simp_rw [mem_iInter]
theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i :=
mem_iUnion.2 ⟨i, ha⟩
theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) :
a ∈ ⋃ (i) (j), s i j :=
mem_iUnion₂.2 ⟨i, j, ha⟩
theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i :=
mem_iInter.2 h
theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) :
a ∈ ⋂ (i) (j), s i j :=
mem_iInter₂.2 h
/-! ### Union and intersection over an indexed family of sets -/
@[congr]
theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ :=
iSup_congr_Prop pq f
@[congr]
theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ :=
iInf_congr_Prop pq f
theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i :=
iSup_plift_up _
theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i :=
iSup_plift_down _
theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i :=
iInf_plift_up _
theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i :=
iInf_plift_down _
theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ :=
iSup_eq_if _
theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋃ h : p, s h = if h : p then s h else ∅ :=
iSup_eq_dif _
theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ :=
iInf_eq_if _
theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋂ h : p, s h = if h : p then s h else univ :=
_root_.iInf_eq_dif _
theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β)
(w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by
have p : x ∈ ⊤ := Set.mem_univ x
rw [← w, Set.mem_iUnion] at p
simpa using p
theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α)
(H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by
obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some
exact ⟨x, m⟩
theorem nonempty_of_nonempty_iUnion
{s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by
obtain ⟨x, hx⟩ := h_Union
exact ⟨Classical.choose <| mem_iUnion.mp hx⟩
theorem nonempty_of_nonempty_iUnion_eq_univ
{s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι :=
nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty)
theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } :=
ext fun _ => mem_iUnion.symm
theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } :=
ext fun _ => mem_iInter.symm
theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t :=
iSup_le h
theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) :
⋃ (i) (j), s i j ⊆ t :=
iUnion_subset fun x => iUnion_subset (h x)
theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i :=
le_iInf h
theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) :
s ⊆ ⋂ (i) (j), t i j :=
subset_iInter fun x => subset_iInter <| h x
@[simp]
theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t :=
⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩
theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} :
⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff]
@[simp]
theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i :=
le_iInf_iff
theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} :
(s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff]
theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i :=
le_iSup
theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i :=
iInf_le
lemma iInter_subset_iUnion [Nonempty ι] {s : ι → Set α} : ⋂ i, s i ⊆ ⋃ i, s i := iInf_le_iSup
theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' :=
le_iSup₂ i j
theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j :=
iInf₂_le i j
/-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i :=
le_iSup_of_le i h
/-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) :
⋂ i, s i ⊆ t :=
iInf_le_of_le i h
/-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i)
(h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j :=
le_iSup₂_of_le i j h
/-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i)
(h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t :=
iInf₂_le_of_le i j h
theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono h
@[gcongr]
theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t :=
iSup_mono h
theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j :=
iSup₂_mono h
theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i :=
iInf_mono h
@[gcongr]
theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t :=
iInf_mono h
theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j :=
iInf₂_mono h
theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) :
⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono' h
theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' :=
iSup₂_mono' h
theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) :
⋂ i, s i ⊆ ⋂ j, t j :=
Set.subset_iInter fun j =>
let ⟨i, hi⟩ := h j
iInter_subset_of_subset i hi
theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' :=
subset_iInter₂_iff.2 fun i' j' =>
let ⟨_, _, hst⟩ := h i' j'
(iInter₂_subset _ _).trans hst
theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) :
⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i :=
iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl
theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) :
⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i :=
iInter_mono fun _ => subset_iInter fun _ => Subset.rfl
theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by
ext
exact mem_iUnion
theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by
ext
exact mem_iInter
theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y :=
h1.iSup_congr h h2
theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y :=
h1.iInf_congr h h2
lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h
lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h
lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋃ (i) (j), s i j = ⋃ (i) (j), t i j :=
iUnion_congr fun i => iUnion_congr <| h i
lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋂ (i) (j), s i j = ⋂ (i) (j), t i j :=
iInter_congr fun i => iInter_congr <| h i
section Nonempty
variable [Nonempty ι] {f : ι → Set α} {s : Set α}
lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const
lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const
lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s :=
(iUnion_congr hf).trans <| iUnion_const _
lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s :=
(iInter_congr hf).trans <| iInter_const _
end Nonempty
@[simp]
theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ :=
compl_iSup
theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iUnion]
@[simp]
theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ :=
compl_iInf
theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iInter]
-- classical -- complete_boolean_algebra
theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by
simp only [compl_iInter, compl_compl]
-- classical -- complete_boolean_algebra
theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by
simp only [compl_iUnion, compl_compl]
theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i :=
inf_iSup_eq _ _
theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s :=
iSup_inf_eq _ _
theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) :
⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i :=
iSup_sup_eq
theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) :
⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i :=
iInf_inf_eq
theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i :=
sup_iSup
theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s :=
iSup_sup
theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i :=
inf_iInf
theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s :=
iInf_inf
theorem insert_iUnion [Nonempty ι] (x : β) (t : ι → Set β) :
insert x (⋃ i, t i) = ⋃ i, insert x (t i) := by
simp_rw [← union_singleton, iUnion_union]
-- classical
theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i :=
sup_iInf_eq _ _
theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
theorem insert_iInter (x : β) (t : ι → Set β) : insert x (⋂ i, t i) = ⋂ i, insert x (t i) := by
simp_rw [← union_singleton, iInter_union]
theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s :=
iUnion_inter _ _
theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by
rw [diff_eq, compl_iUnion, inter_iInter]; rfl
theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by
rw [diff_eq, compl_iInter, inter_iUnion]; rfl
theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i :=
le_iSup_inf_iSup s t
theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_monotone hs ht
theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_antitone hs ht
theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_monotone hs ht
theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_antitone hs ht
/-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/
theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j :=
iSup_iInf_le_iInf_iSup (flip s)
theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) :=
iSup_option s
theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) :=
iInf_option s
section
variable (p : ι → Prop) [DecidablePred p]
theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h :=
iSup_dite _ _ _
theorem iUnion_ite (f g : ι → Set α) :
⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i :=
iUnion_dite _ _ _
theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h :=
iInf_dite _ _ _
theorem iInter_ite (f g : ι → Set α) :
⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i :=
iInter_dite _ _ _
end
/-! ### Unions and intersections indexed by `Prop` -/
theorem iInter_false {s : False → Set α} : iInter s = univ :=
iInf_false
theorem iUnion_false {s : False → Set α} : iUnion s = ∅ :=
iSup_false
@[simp]
theorem iInter_true {s : True → Set α} : iInter s = s trivial :=
iInf_true
@[simp]
theorem iUnion_true {s : True → Set α} : iUnion s = s trivial :=
iSup_true
@[simp]
theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} :
⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ :=
iInf_exists
@[simp]
theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} :
⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ :=
iSup_exists
@[simp]
theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ :=
iSup_bot
@[simp]
theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ :=
iInf_top
section
variable {s : ι → Set α}
@[simp]
theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ :=
iSup_eq_bot
@[simp]
theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ :=
iInf_eq_top
@[simp]
theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by
simp [nonempty_iff_ne_empty]
theorem nonempty_biUnion {t : Set α} {s : α → Set β} :
(⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp
theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) :
⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ :=
iSup_exists
end
@[simp]
theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋂ (x) (h : x = b), s x h = s b rfl :=
iInf_iInf_eq_left
@[simp]
theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋂ (x) (h : b = x), s x h = s b rfl :=
iInf_iInf_eq_right
@[simp]
theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋃ (x) (h : x = b), s x h = s b rfl :=
iSup_iSup_eq_left
@[simp]
theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋃ (x) (h : b = x), s x h = s b rfl :=
iSup_iSup_eq_right
theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) :
⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) :=
iInf_or
theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) :
⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) :=
iSup_or
theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ :=
iSup_and
theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ :=
iInf_and
theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' :=
iSup_comm
theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' :=
iInf_comm
theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_sigma
theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 :=
iSup_sigma' _
theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_sigma
theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 :=
iInf_sigma' _
theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iSup₂_comm _
theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iInf₂_comm _
@[simp]
theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι']
@[simp]
theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι]
@[simp]
theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iInter_and, @iInter_comm _ ι']
@[simp]
theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iInter_and, @iInter_comm _ ι]
@[simp]
theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by
simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left]
@[simp]
theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by
simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left]
lemma iUnion_sum {s : α ⊕ β → Set γ} : ⋃ x, s x = (⋃ x, s (.inl x)) ∪ ⋃ x, s (.inr x) := iSup_sum
lemma iInter_sum {s : α ⊕ β → Set γ} : ⋂ x, s x = (⋂ x, s (.inl x)) ∩ ⋂ x, s (.inr x) := iInf_sum
theorem iUnion_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_psigma _
/-- A reversed version of `iUnion_psigma` with a curried map. -/
theorem iUnion_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : PSigma γ, s ia.1 ia.2 :=
iSup_psigma' _
theorem iInter_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_psigma _
/-- A reversed version of `iInter_psigma` with a curried map. -/
theorem iInter_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : PSigma γ, s ia.1 ia.2 :=
iInf_psigma' _
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_iUnion₂`. -/
theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) :
y ∈ ⋃ x ∈ s, t x :=
mem_iUnion₂_of_mem xs ytx
/-- A specialization of `mem_iInter₂`. -/
theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) :
y ∈ ⋂ x ∈ s, t x :=
mem_iInter₂_of_mem h
/-- A specialization of `subset_iUnion₂`. -/
theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) :
u x ⊆ ⋃ x ∈ s, u x :=
subset_iUnion₂ (s := fun i _ => u i) x xs
/-- A specialization of `iInter₂_subset`. -/
theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) :
⋂ x ∈ s, t x ⊆ t x :=
iInter₂_subset x xs
lemma biInter_subset_biUnion {s : Set α} (hs : s.Nonempty) {t : α → Set β} :
⋂ x ∈ s, t x ⊆ ⋃ x ∈ s, t x := biInf_le_biSup hs
theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') :
⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x :=
iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx
theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) :
⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x :=
subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx
theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) :
⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x :=
(biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h
theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) :
⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x :=
(biInter_subset_biInter_left hs).trans <| iInter₂_mono h
theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) :
⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 :=
iSup_subtype'
theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) :
⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 :=
iInf_subtype'
@[simp] lemma biUnion_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋃ a ∈ s, t = t :=
biSup_const hs
@[simp] lemma biInter_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋂ a ∈ s, t = t :=
biInf_const hs
theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ :=
iSup_subtype
theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ :=
iInf_subtype
theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ :=
iInf_emptyset
theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x :=
iInf_univ
@[simp]
theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s :=
Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx
@[simp]
theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by
rw [iUnion_nonempty_index, biUnion_self]
theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a :=
iInf_singleton
theorem biInter_union (s t : Set α) (u : α → Set β) :
⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x :=
iInf_union
theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) :
⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp
theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by
rw [biInter_insert, biInter_singleton]
theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by
haveI : Nonempty s := hs.to_subtype
simp [biInter_eq_iInter, ← iInter_inter]
theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by
rw [inter_comm, ← biInter_inter hs]
simp [inter_comm]
theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ :=
iSup_emptyset
theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x :=
iSup_univ
theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a :=
iSup_singleton
@[simp]
theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s :=
ext <| by simp
theorem biUnion_union (s t : Set α) (u : α → Set β) :
⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x :=
iSup_union
@[simp]
theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iUnion_subtype _ _
@[simp]
theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iInter_subtype _ _
theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) :
⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp
theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by
simp
theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion]
theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) :
(⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter]
theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter]
theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union]
theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) :
x ∈ ⋃₀ S :=
⟨t, ht, hx⟩
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀ S)
(ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩
theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t :=
sInf_le tS
theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀ S :=
le_sSup tS
theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u)
(h₂ : u ∈ t) : s ⊆ ⋃₀ t :=
Subset.trans h₁ (subset_sUnion_of_mem h₂)
theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀ S ⊆ t :=
sSup_le h
@[simp]
theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀ s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t :=
sSup_le_iff
/-- `sUnion` is monotone under taking a subset of each set. -/
lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) :
⋃₀ s ⊆ ⋃₀ (f '' s) :=
fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩
/-- `sUnion` is monotone under taking a superset of each set. -/
lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) :
⋃₀ (f '' s) ⊆ ⋃₀ s :=
-- If t ∈ f '' s is arbitrary; t = f u for some u : Set α.
fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩
theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S :=
le_sInf h
@[simp]
theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' :=
le_sInf_iff
@[gcongr]
theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T :=
sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs)
@[gcongr]
theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S :=
subset_sInter fun _ hs => sInter_subset_of_mem (h hs)
@[simp]
theorem sUnion_empty : ⋃₀ ∅ = (∅ : Set α) :=
sSup_empty
@[simp]
theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) :=
sInf_empty
@[simp]
theorem sUnion_singleton (s : Set α) : ⋃₀ {s} = s :=
sSup_singleton
@[simp]
theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s :=
sInf_singleton
@[simp]
theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀ S = ∅ ↔ ∀ s ∈ S, s = ∅ :=
sSup_eq_bot
@[simp]
theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ :=
sInf_eq_top
theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t :=
sUnion_subset_iff.symm
/-- `⋃₀` and `𝒫` form a Galois connection. -/
theorem sUnion_powerset_gc :
GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gc_sSup_Iic
/-- `⋃₀` and `𝒫` form a Galois insertion. -/
def sUnionPowersetGI :
GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gi_sSup_Iic
@[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI
/-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/
theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) :
⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by
simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall]
rintro ⟨s, hs, hne⟩
obtain rfl : s = univ := (h hs).resolve_left hne
exact univ_subset_iff.1 <| subset_sUnion_of_mem hs
@[simp]
theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀ S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by
simp [nonempty_iff_ne_empty]
theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀ s).Nonempty) : s.Nonempty :=
let ⟨s, hs, _⟩ := nonempty_sUnion.1 h
⟨s, hs⟩
theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀ s = univ) : s.Nonempty :=
Nonempty.of_sUnion <| h.symm ▸ univ_nonempty
theorem sUnion_union (S T : Set (Set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T :=
sSup_union
theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T :=
sInf_union
@[simp]
theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀ insert s T = s ∪ ⋃₀ T :=
sSup_insert
@[simp]
theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T :=
sInf_insert
@[simp]
theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀ (s \ {∅}) = ⋃₀ s :=
sSup_diff_singleton_bot s
@[simp]
theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s :=
sInf_diff_singleton_top s
theorem sUnion_pair (s t : Set α) : ⋃₀ {s, t} = s ∪ t :=
sSup_pair
theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t :=
sInf_pair
@[simp]
theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀ (f '' s) = ⋃ a ∈ s, f a :=
sSup_image
@[simp]
theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ a ∈ s, f a :=
sInf_image
@[simp]
lemma sUnion_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) :
⋃₀ (image2 f s t) = ⋃ (a ∈ s) (b ∈ t), f a b := sSup_image2
@[simp]
lemma sInter_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) :
⋂₀ (image2 f s t) = ⋂ (a ∈ s) (b ∈ t), f a b := sInf_image2
@[simp]
theorem sUnion_range (f : ι → Set β) : ⋃₀ range f = ⋃ x, f x :=
rfl
@[simp]
theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x :=
rfl
theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by
simp only [eq_univ_iff_forall, mem_iUnion]
theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} :
⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by
simp only [iUnion_eq_univ_iff, mem_iUnion]
theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀ c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by
simp only [eq_univ_iff_forall, mem_sUnion]
-- classical
theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} :
⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by
simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall]
-- classical
theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
@[simp]
theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by
simp [nonempty_iff_ne_empty, iInter_eq_empty_iff]
-- classical
theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} :
(⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by
simp
-- classical
@[simp]
theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by
simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]
-- classical
theorem compl_sUnion (S : Set (Set α)) : (⋃₀ S)ᶜ = ⋂₀ (compl '' S) :=
ext fun x => by simp
-- classical
theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀ S = (⋂₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋃₀ S), compl_sUnion]
-- classical
theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀ (compl '' S) := by
rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
-- classical
theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋂₀ S), compl_sInter]
theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S)
(h : s ∩ ⋃₀ S = ∅) : s ∩ t = ∅ :=
eq_empty_of_subset_empty <| by
rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs)
theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) :
range f = ⋃ a, range fun b => f ⟨a, b⟩ :=
Set.ext <| by simp
theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) :
⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by
ext x
simp only [mem_iUnion, mem_image, mem_preimage]
constructor
· rintro ⟨i, a, h, rfl⟩
exact h
· intro h
obtain ⟨i, a⟩ := x
exact ⟨i, a, h, rfl⟩
theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) :=
Set.ext fun x =>
iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩
alias sUnion_mono := sUnion_subset_sUnion
alias sInter_mono := sInter_subset_sInter
theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s :=
iSup_const_mono (α := Set α) h
@[simp]
theorem iUnion_singleton_eq_range (f : α → β) : ⋃ x : α, {f x} = range f := by
ext x
simp [@eq_comm _ x]
theorem iUnion_insert_eq_range_union_iUnion {ι : Type*} (x : ι → β) (t : ι → Set β) :
⋃ i, insert (x i) (t i) = range x ∪ ⋃ i, t i := by
simp_rw [← union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range]
theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff]
theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp
theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀ s = ⋃ (i : Set α) (_ : i ∈ s), i := by
rw [← sUnion_image, image_id']
theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by
rw [← sInter_image, image_id']
theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀ s = ⋃ i : s, i := by
simp only [← sUnion_range, Subtype.range_coe]
theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by
simp only [← sInter_range, Subtype.range_coe]
@[simp]
theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ :=
iSup_of_empty _
@[simp]
theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ :=
iInf_of_empty _
theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ :=
sup_eq_iSup s₁ s₂
theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ :=
inf_eq_iInf s₁ s₂
theorem sInter_union_sInter {S T : Set (Set α)} :
⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 :=
sInf_sup_sInf
theorem sUnion_inter_sUnion {s t : Set (Set α)} :
⋃₀ s ∩ ⋃₀ t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 :=
sSup_inf_sSup
theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) :
⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι]
theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) :
⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι]
theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀ ⋃ i, s i = ⋃ i, ⋃₀ s i := by
simp only [sUnion_eq_biUnion, biUnion_iUnion]
theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by
simp only [sInter_eq_biInter, biInter_iUnion]
theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)}
(hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀ C := by
ext x; constructor
· rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩
refine ⟨_, hs, ?_⟩
exact (f ⟨s, hs⟩ y).2
· rintro ⟨s, hs, hx⟩
obtain ⟨y, hy⟩ := hf ⟨s, hs⟩ ⟨x, hx⟩
refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩
exact congr_arg Subtype.val hy
theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x}
(hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by
ext x; rw [mem_iUnion, mem_iUnion]; constructor
· rintro ⟨y, i, rfl⟩
exact ⟨i, (f i y).2⟩
· rintro ⟨i, hx⟩
obtain ⟨y, hy⟩ := hf i ⟨x, hx⟩
exact ⟨y, i, congr_arg Subtype.val hy⟩
theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i :=
sup_iInf_eq _ _
theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left]
theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right]
lemma biUnion_lt_eq_iUnion [LT α] [NoMaxOrder α] {s : α → Set β} :
⋃ (n) (m < n), s m = ⋃ n, s n := biSup_lt_eq_iSup
lemma biUnion_le_eq_iUnion [Preorder α] {s : α → Set β} :
⋃ (n) (m ≤ n), s m = ⋃ n, s n := biSup_le_eq_iSup
lemma biInter_lt_eq_iInter [LT α] [NoMaxOrder α] {s : α → Set β} :
⋂ (n) (m < n), s m = ⋂ (n), s n := biInf_lt_eq_iInf
lemma biInter_le_eq_iInter [Preorder α] {s : α → Set β} :
⋂ (n) (m ≤ n), s m = ⋂ (n), s n := biInf_le_eq_iInf
lemma biUnion_gt_eq_iUnion [LT α] [NoMinOrder α] {s : α → Set β} :
⋃ (n) (m > n), s m = ⋃ n, s n := biSup_gt_eq_iSup
lemma biUnion_ge_eq_iUnion [Preorder α] {s : α → Set β} :
⋃ (n) (m ≥ n), s m = ⋃ n, s n := biSup_ge_eq_iSup
lemma biInter_gt_eq_iInf [LT α] [NoMinOrder α] {s : α → Set β} :
⋂ (n) (m > n), s m = ⋂ n, s n := biInf_gt_eq_iInf
lemma biInter_ge_eq_iInf [Preorder α] {s : α → Set β} :
⋂ (n) (m ≥ n), s m = ⋂ n, s n := biInf_ge_eq_iInf
section le
variable {ι : Type*} [PartialOrder ι] (s : ι → Set α) (i : ι)
theorem biUnion_le : (⋃ j ≤ i, s j) = (⋃ j < i, s j) ∪ s i :=
biSup_le_eq_sup s i
theorem biInter_le : (⋂ j ≤ i, s j) = (⋂ j < i, s j) ∩ s i :=
biInf_le_eq_inf s i
theorem biUnion_ge : (⋃ j ≥ i, s j) = s i ∪ ⋃ j > i, s j :=
biSup_ge_eq_sup s i
theorem biInter_ge : (⋂ j ≥ i, s j) = s i ∩ ⋂ j > i, s j :=
biInf_ge_eq_inf s i
end le
section Pi
variable {π : α → Type*}
theorem pi_def (i : Set α) (s : ∀ a, Set (π a)) : pi i s = ⋂ a ∈ i, eval a ⁻¹' s a := by
ext
simp
theorem univ_pi_eq_iInter (t : ∀ i, Set (π i)) : pi univ t = ⋂ i, eval i ⁻¹' t i := by
simp only [pi_def, iInter_true, mem_univ]
theorem pi_diff_pi_subset (i : Set α) (s t : ∀ a, Set (π a)) :
pi i s \ pi i t ⊆ ⋃ a ∈ i, eval a ⁻¹' (s a \ t a) := by
refine diff_subset_comm.2 fun x hx a ha => ?_
simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not,
eval_apply] at hx
exact hx.2 _ ha (hx.1 _ ha)
theorem iUnion_univ_pi {ι : α → Type*} (t : (a : α) → ι a → Set (π a)) :
⋃ x : (a : α) → ι a, pi univ (fun a => t a (x a)) = pi univ fun a => ⋃ j : ι a, t a j := by
ext
simp [Classical.skolem]
end Pi
section Directed
theorem directedOn_iUnion {r} {f : ι → Set α} (hd : Directed (· ⊆ ·) f)
(h : ∀ x, DirectedOn r (f x)) : DirectedOn r (⋃ x, f x) := by
simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp]
exact fun a₁ b₁ fb₁ a₂ b₂ fb₂ =>
let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂
let ⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂)
⟨x, ⟨z, xf⟩, xa₁, xa₂⟩
theorem directedOn_sUnion {r} {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S)
(h : ∀ x ∈ S, DirectedOn r x) : DirectedOn r (⋃₀ S) := by
rw [sUnion_eq_iUnion]
exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i ↦ h i.1 i.2)
theorem pairwise_iUnion₂ {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S)
(r : α → α → Prop) (h : ∀ s ∈ S, s.Pairwise r) : (⋃ s ∈ S, s).Pairwise r := by
simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp]
intro x S hS hx y T hT hy hne
obtain ⟨U, hU, hSU, hTU⟩ := hd S hS T hT
exact h U hU (hSU hx) (hTU hy) hne
end Directed
end Set
namespace Function
namespace Surjective
theorem iUnion_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋃ x, g (f x) = ⋃ y, g y :=
hf.iSup_comp g
theorem iInter_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋂ x, g (f x) = ⋂ y, g y :=
hf.iInf_comp g
end Surjective
end Function
/-!
### Disjoint sets
-/
section Disjoint
variable {s t : Set α}
namespace Set
@[simp]
theorem disjoint_iUnion_left {ι : Sort*} {s : ι → Set α} :
Disjoint (⋃ i, s i) t ↔ ∀ i, Disjoint (s i) t :=
iSup_disjoint_iff
@[simp]
theorem disjoint_iUnion_right {ι : Sort*} {s : ι → Set α} :
Disjoint t (⋃ i, s i) ↔ ∀ i, Disjoint t (s i) :=
disjoint_iSup_iff
theorem disjoint_iUnion₂_left {s : ∀ i, κ i → Set α} {t : Set α} :
Disjoint (⋃ (i) (j), s i j) t ↔ ∀ i j, Disjoint (s i j) t :=
iSup₂_disjoint_iff
theorem disjoint_iUnion₂_right {s : Set α} {t : ∀ i, κ i → Set α} :
Disjoint s (⋃ (i) (j), t i j) ↔ ∀ i j, Disjoint s (t i j) :=
disjoint_iSup₂_iff
@[simp]
theorem disjoint_sUnion_left {S : Set (Set α)} {t : Set α} :
Disjoint (⋃₀ S) t ↔ ∀ s ∈ S, Disjoint s t :=
sSup_disjoint_iff
@[simp]
theorem disjoint_sUnion_right {s : Set α} {S : Set (Set α)} :
Disjoint s (⋃₀ S) ↔ ∀ t ∈ S, Disjoint s t :=
disjoint_sSup_iff
lemma biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ {ι : Type*} {Es : ι → Set α}
(Es_union : ⋃ i, Es i = univ) (Es_disj : Pairwise fun i j ↦ Disjoint (Es i) (Es j))
(I : Set ι) :
(⋃ i ∈ I, Es i)ᶜ = ⋃ i ∈ Iᶜ, Es i := by
ext x
obtain ⟨i, hix⟩ : ∃ i, x ∈ Es i := by simp [← mem_iUnion, Es_union]
have obs : ∀ (J : Set ι), x ∈ ⋃ j ∈ J, Es j ↔ i ∈ J := by
refine fun J ↦ ⟨?_, fun i_in_J ↦ by simpa only [mem_iUnion, exists_prop] using ⟨i, i_in_J, hix⟩⟩
intro x_in_U
simp only [mem_iUnion, exists_prop] at x_in_U
obtain ⟨j, j_in_J, hjx⟩ := x_in_U
rwa [show i = j by by_contra i_ne_j; exact Disjoint.ne_of_mem (Es_disj i_ne_j) hix hjx rfl]
have obs' : ∀ (J : Set ι), x ∈ (⋃ j ∈ J, Es j)ᶜ ↔ i ∉ J :=
fun J ↦ by simpa only [mem_compl_iff, not_iff_not] using obs J
rw [obs, obs', mem_compl_iff]
end Set
end Disjoint
/-! ### Intervals -/
namespace Set
lemma nonempty_iInter_Iic_iff [Preorder α] {f : ι → α} :
(⋂ i, Iic (f i)).Nonempty ↔ BddBelow (range f) := by
have : (⋂ (i : ι), Iic (f i)) = lowerBounds (range f) := by
ext c; simp [lowerBounds]
simp [this, BddBelow]
lemma nonempty_iInter_Ici_iff [Preorder α] {f : ι → α} :
(⋂ i, Ici (f i)).Nonempty ↔ BddAbove (range f) :=
nonempty_iInter_Iic_iff (α := αᵒᵈ)
variable [CompleteLattice α]
theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⋂ i, Ici (f i) :=
ext fun _ => by simp only [mem_Ici, iSup_le_iff, mem_iInter]
theorem Iic_iInf (f : ι → α) : Iic (⨅ i, f i) = ⋂ i, Iic (f i) :=
ext fun _ => by simp only [mem_Iic, le_iInf_iff, mem_iInter]
theorem Ici_iSup₂ (f : ∀ i, κ i → α) : Ici (⨆ (i) (j), f i j) = ⋂ (i) (j), Ici (f i j) := by
simp_rw [Ici_iSup]
theorem Iic_iInf₂ (f : ∀ i, κ i → α) : Iic (⨅ (i) (j), f i j) = ⋂ (i) (j), Iic (f i j) := by
simp_rw [Iic_iInf]
theorem Ici_sSup (s : Set α) : Ici (sSup s) = ⋂ a ∈ s, Ici a := by rw [sSup_eq_iSup, Ici_iSup₂]
theorem Iic_sInf (s : Set α) : Iic (sInf s) = ⋂ a ∈ s, Iic a := by rw [sInf_eq_iInf, Iic_iInf₂]
end Set
namespace Set
variable (t : α → Set β)
theorem biUnion_diff_biUnion_subset (s₁ s₂ : Set α) :
((⋃ x ∈ s₁, t x) \ ⋃ x ∈ s₂, t x) ⊆ ⋃ x ∈ s₁ \ s₂, t x := by
simp only [diff_subset_iff, ← biUnion_union]
apply biUnion_subset_biUnion_left
rw [union_diff_self]
apply subset_union_right
/-- If `t` is an indexed family of sets, then there is a natural map from `Σ i, t i` to `⋃ i, t i`
sending `⟨i, x⟩` to `x`. -/
def sigmaToiUnion (x : Σi, t i) : ⋃ i, t i :=
⟨x.2, mem_iUnion.2 ⟨x.1, x.2.2⟩⟩
theorem sigmaToiUnion_surjective : Surjective (sigmaToiUnion t)
| ⟨b, hb⟩ =>
have : ∃ a, b ∈ t a := by simpa using hb
let ⟨a, hb⟩ := this
⟨⟨a, b, hb⟩, rfl⟩
theorem sigmaToiUnion_injective (h : Pairwise (Disjoint on t)) :
Injective (sigmaToiUnion t)
| ⟨a₁, b₁, h₁⟩, ⟨a₂, b₂, h₂⟩, eq =>
have b_eq : b₁ = b₂ := congr_arg Subtype.val eq
have a_eq : a₁ = a₂ :=
by_contradiction fun ne =>
have : b₁ ∈ t a₁ ∩ t a₂ := ⟨h₁, b_eq.symm ▸ h₂⟩
(h ne).le_bot this
Sigma.eq a_eq <| Subtype.eq <| by subst b_eq; subst a_eq; rfl
theorem sigmaToiUnion_bijective (h : Pairwise (Disjoint on t)) :
Bijective (sigmaToiUnion t) :=
⟨sigmaToiUnion_injective t h, sigmaToiUnion_surjective t⟩
/-- Equivalence from the disjoint union of a family of sets forming a partition of `β`, to `β`
itself. -/
noncomputable def sigmaEquiv (s : α → Set β) (hs : ∀ b, ∃! i, b ∈ s i) :
(Σ i, s i) ≃ β where
toFun | ⟨_, b⟩ => b
invFun b := ⟨(hs b).choose, b, (hs b).choose_spec.1⟩
left_inv | ⟨i, b, hb⟩ => Sigma.subtype_ext ((hs b).choose_spec.2 i hb).symm rfl
right_inv _ := rfl
/-- Equivalence between a disjoint union and a dependent sum. -/
noncomputable def unionEqSigmaOfDisjoint {t : α → Set β}
(h : Pairwise (Disjoint on t)) :
(⋃ i, t i) ≃ Σi, t i :=
(Equiv.ofBijective _ <| sigmaToiUnion_bijective t h).symm
theorem iUnion_ge_eq_iUnion_nat_add (u : ℕ → Set α) (n : ℕ) : ⋃ i ≥ n, u i = ⋃ i, u (i + n) :=
iSup_ge_eq_iSup_nat_add u n
theorem iInter_ge_eq_iInter_nat_add (u : ℕ → Set α) (n : ℕ) : ⋂ i ≥ n, u i = ⋂ i, u (i + n) :=
iInf_ge_eq_iInf_nat_add u n
theorem _root_.Monotone.iUnion_nat_add {f : ℕ → Set α} (hf : Monotone f) (k : ℕ) :
⋃ n, f (n + k) = ⋃ n, f n :=
hf.iSup_nat_add k
theorem _root_.Antitone.iInter_nat_add {f : ℕ → Set α} (hf : Antitone f) (k : ℕ) :
⋂ n, f (n + k) = ⋂ n, f n :=
hf.iInf_nat_add k
@[simp]
theorem iUnion_iInter_ge_nat_add (f : ℕ → Set α) (k : ℕ) :
⋃ n, ⋂ i ≥ n, f (i + k) = ⋃ n, ⋂ i ≥ n, f i :=
iSup_iInf_ge_nat_add f k
theorem union_iUnion_nat_succ (u : ℕ → Set α) : (u 0 ∪ ⋃ i, u (i + 1)) = ⋃ i, u i :=
sup_iSup_nat_succ u
theorem inter_iInter_nat_succ (u : ℕ → Set α) : (u 0 ∩ ⋂ i, u (i + 1)) = ⋂ i, u i :=
inf_iInf_nat_succ u
end Set
open Set
variable [CompleteLattice β]
theorem iSup_iUnion (s : ι → Set α) (f : α → β) : ⨆ a ∈ ⋃ i, s i, f a = ⨆ (i) (a ∈ s i), f a := by
rw [iSup_comm]
simp_rw [mem_iUnion, iSup_exists]
theorem iInf_iUnion (s : ι → Set α) (f : α → β) : ⨅ a ∈ ⋃ i, s i, f a = ⨅ (i) (a ∈ s i), f a :=
iSup_iUnion (β := βᵒᵈ) s f
theorem sSup_iUnion (t : ι → Set β) : sSup (⋃ i, t i) = ⨆ i, sSup (t i) := by
simp_rw [sSup_eq_iSup, iSup_iUnion]
theorem sSup_sUnion (s : Set (Set β)) : sSup (⋃₀ s) = ⨆ t ∈ s, sSup t := by
simp only [sUnion_eq_biUnion, sSup_eq_iSup, iSup_iUnion]
theorem sInf_sUnion (s : Set (Set β)) : sInf (⋃₀ s) = ⨅ t ∈ s, sInf t :=
sSup_sUnion (β := βᵒᵈ) s
lemma iSup_sUnion (S : Set (Set α)) (f : α → β) :
(⨆ x ∈ ⋃₀ S, f x) = ⨆ (s ∈ S) (x ∈ s), f x := by
rw [sUnion_eq_iUnion, iSup_iUnion, ← iSup_subtype'']
lemma iInf_sUnion (S : Set (Set α)) (f : α → β) :
(⨅ x ∈ ⋃₀ S, f x) = ⨅ (s ∈ S) (x ∈ s), f x := by
rw [sUnion_eq_iUnion, iInf_iUnion, ← iInf_subtype'']
lemma forall_sUnion {S : Set (Set α)} {p : α → Prop} :
(∀ x ∈ ⋃₀ S, p x) ↔ ∀ s ∈ S, ∀ x ∈ s, p x := by
simp_rw [← iInf_Prop_eq, iInf_sUnion]
lemma exists_sUnion {S : Set (Set α)} {p : α → Prop} :
(∃ x ∈ ⋃₀ S, p x) ↔ ∃ s ∈ S, ∃ x ∈ s, p x := by
simp_rw [← exists_prop, ← iSup_Prop_eq, iSup_sUnion]
| Mathlib/Data/Set/Lattice.lean | 1,671 | 1,672 | |
/-
Copyright (c) 2023 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.Analysis.Calculus.Deriv.Shift
/-!
# Estimates for the complex logarithm
We show that `log (1+z)` differs from its Taylor polynomial up to degree `n` by at most
`‖z‖^(n+1)/((n+1)*(1-‖z‖))` when `‖z‖ < 1`; see `Complex.norm_log_sub_logTaylor_le`.
To this end, we derive the representation of `log (1+z)` as the integral of `1/(1+tz)`
over the unit interval (`Complex.log_eq_integral`) and introduce notation
`Complex.logTaylor n` for the Taylor polynomial up to degree `n-1`.
## TODO
Refactor using general Taylor series theory, once this exists in Mathlib.
-/
namespace Complex
/-!
### Integral representation of the complex log
-/
lemma continuousOn_one_add_mul_inv {z : ℂ} (hz : 1 + z ∈ slitPlane) :
ContinuousOn (fun t : ℝ ↦ (1 + t • z)⁻¹) (Set.Icc 0 1) :=
ContinuousOn.inv₀ (by fun_prop)
(fun _ ht ↦ slitPlane_ne_zero <| StarConvex.add_smul_mem starConvex_one_slitPlane hz ht.1 ht.2)
open intervalIntegral in
/-- Represent `log (1 + z)` as an integral over the unit interval -/
lemma log_eq_integral {z : ℂ} (hz : 1 + z ∈ slitPlane) :
log (1 + z) = z * ∫ (t : ℝ) in (0 : ℝ)..1, (1 + t • z)⁻¹ := by
convert (integral_unitInterval_deriv_eq_sub (continuousOn_one_add_mul_inv hz)
(fun _ ht ↦ hasDerivAt_log <|
StarConvex.add_smul_mem starConvex_one_slitPlane hz ht.1 ht.2)).symm using 1
simp only [log_one, sub_zero]
/-- Represent `log (1 - z)⁻¹` as an integral over the unit interval -/
lemma log_inv_eq_integral {z : ℂ} (hz : 1 - z ∈ slitPlane) :
log (1 - z)⁻¹ = z * ∫ (t : ℝ) in (0 : ℝ)..1, (1 - t • z)⁻¹ := by
rw [sub_eq_add_neg 1 z] at hz ⊢
rw [log_inv _ <| slitPlane_arg_ne_pi hz, neg_eq_iff_eq_neg, ← neg_mul]
convert log_eq_integral hz using 5
rw [sub_eq_add_neg, smul_neg]
/-!
### The Taylor polynomials of the logarithm
-/
/-- The `n`th Taylor polynomial of `log` at `1`, as a function `ℂ → ℂ` -/
noncomputable
def logTaylor (n : ℕ) : ℂ → ℂ := fun z ↦ ∑ j ∈ Finset.range n, (-1) ^ (j + 1) * z ^ j / j
lemma logTaylor_zero : logTaylor 0 = fun _ ↦ 0 := by
funext
simp only [logTaylor, Finset.range_zero, ← Nat.not_even_iff_odd, Int.cast_pow, Int.cast_neg,
Int.cast_one, Finset.sum_empty]
lemma logTaylor_succ (n : ℕ) :
logTaylor (n + 1) = logTaylor n + (fun z : ℂ ↦ (-1) ^ (n + 1) * z ^ n / n) := by
funext
simpa only [logTaylor] using Finset.sum_range_succ ..
lemma logTaylor_at_zero (n : ℕ) : logTaylor n 0 = 0 := by
induction n with
| zero => simp [logTaylor_zero]
| succ n ih => simpa [logTaylor_succ, ih] using ne_or_eq n 0
lemma hasDerivAt_logTaylor (n : ℕ) (z : ℂ) :
HasDerivAt (logTaylor (n + 1)) (∑ j ∈ Finset.range n, (-1) ^ j * z ^ j) z := by
induction n with
| zero => simp [logTaylor_succ, logTaylor_zero, Pi.add_def, hasDerivAt_const]
| succ n ih =>
rw [logTaylor_succ]
simp only [cpow_natCast, Nat.cast_add, Nat.cast_one, ← Nat.not_even_iff_odd,
Finset.sum_range_succ, (show (-1) ^ (n + 1 + 1) = (-1) ^ n by ring)]
refine HasDerivAt.add ih ?_
simp only [← Nat.not_even_iff_odd, Int.cast_pow, Int.cast_neg, Int.cast_one, mul_div_assoc]
have : HasDerivAt (fun x : ℂ ↦ (x ^ (n + 1) / (n + 1))) (z ^ n) z := by
simp_rw [div_eq_mul_inv]
convert HasDerivAt.mul_const (hasDerivAt_pow (n + 1) z) (((n : ℂ) + 1)⁻¹) using 1
field_simp [Nat.cast_add_one_ne_zero n]
convert HasDerivAt.const_mul _ this using 2
ring
/-!
### Bounds for the difference between log and its Taylor polynomials
-/
lemma hasDerivAt_log_sub_logTaylor (n : ℕ) {z : ℂ} (hz : 1 + z ∈ slitPlane) :
HasDerivAt (fun z : ℂ ↦ log (1 + z) - logTaylor (n + 1) z) ((-z) ^ n * (1 + z)⁻¹) z := by
convert ((hasDerivAt_log hz).comp_const_add 1 z).sub (hasDerivAt_logTaylor n z) using 1
have hz' : -z ≠ 1 := by
intro H
rw [neg_eq_iff_eq_neg] at H
simp only [H, add_neg_cancel] at hz
exact slitPlane_ne_zero hz rfl
simp_rw [← mul_pow, neg_one_mul, geom_sum_eq hz', ← neg_add', div_neg, add_comm z]
field_simp [slitPlane_ne_zero hz]
/-- Give a bound on `‖(1 + t * z)⁻¹‖` for `0 ≤ t ≤ 1` and `‖z‖ < 1`. -/
lemma norm_one_add_mul_inv_le {t : ℝ} (ht : t ∈ Set.Icc 0 1) {z : ℂ} (hz : ‖z‖ < 1) :
‖(1 + t * z)⁻¹‖ ≤ (1 - ‖z‖)⁻¹ := by
rw [Set.mem_Icc] at ht
rw [norm_inv]
refine inv_anti₀ (by linarith) ?_
calc 1 - ‖z‖
_ ≤ 1 - t * ‖z‖ := by
nlinarith [norm_nonneg z]
_ = 1 - ‖t * z‖ := by
rw [norm_mul, Complex.norm_of_nonneg ht.1]
_ ≤ ‖1 + t * z‖ := by
rw [← norm_neg (t * z), ← sub_neg_eq_add]
convert norm_sub_norm_le 1 (-(t * z))
exact norm_one.symm
lemma integrable_pow_mul_norm_one_add_mul_inv (n : ℕ) {z : ℂ} (hz : ‖z‖ < 1) :
IntervalIntegrable (fun t : ℝ ↦ t ^ n * ‖(1 + t * z)⁻¹‖) MeasureTheory.volume 0 1 := by
have := continuousOn_one_add_mul_inv <| mem_slitPlane_of_norm_lt_one hz
rw [← Set.uIcc_of_le zero_le_one] at this
exact ContinuousOn.intervalIntegrable (by fun_prop)
open intervalIntegral in
/-- The difference of `log (1+z)` and its `(n+1)`st Taylor polynomial can be bounded in
terms of `‖z‖`. -/
lemma norm_log_sub_logTaylor_le (n : ℕ) {z : ℂ} (hz : ‖z‖ < 1) :
‖log (1 + z) - logTaylor (n + 1) z‖ ≤ ‖z‖ ^ (n + 1) * (1 - ‖z‖)⁻¹ / (n + 1) := by
have help : IntervalIntegrable (fun t : ℝ ↦ t ^ n * (1 - ‖z‖)⁻¹) MeasureTheory.volume 0 1 :=
IntervalIntegrable.mul_const (Continuous.intervalIntegrable (by fun_prop) 0 1) (1 - ‖z‖)⁻¹
let f (z : ℂ) : ℂ := log (1 + z) - logTaylor (n + 1) z
let f' (z : ℂ) : ℂ := (-z) ^ n * (1 + z)⁻¹
have hderiv : ∀ t ∈ Set.Icc (0 : ℝ) 1, HasDerivAt f (f' (0 + t * z)) (0 + t * z) := by
intro t ht
rw [zero_add]
exact hasDerivAt_log_sub_logTaylor n <|
StarConvex.add_smul_mem starConvex_one_slitPlane (mem_slitPlane_of_norm_lt_one hz) ht.1 ht.2
have hcont : ContinuousOn (fun t : ℝ ↦ f' (0 + t * z)) (Set.Icc 0 1) := by
simp only [zero_add, zero_le_one, not_true_eq_false]
exact (Continuous.continuousOn (by fun_prop)).mul <|
continuousOn_one_add_mul_inv <| mem_slitPlane_of_norm_lt_one hz
have H : f z = z * ∫ t in (0 : ℝ)..1, (-(t * z)) ^ n * (1 + t * z)⁻¹ := by
convert (integral_unitInterval_deriv_eq_sub hcont hderiv).symm using 1
· simp only [f, zero_add, add_zero, log_one, logTaylor_at_zero, sub_self, sub_zero]
· simp only [f', add_zero, log_one, logTaylor_at_zero, sub_self, real_smul, zero_add,
smul_eq_mul]
unfold f at H
simp only [H, norm_mul]
simp_rw [neg_pow (_ * z) n, mul_assoc, intervalIntegral.integral_const_mul, mul_pow,
mul_comm _ (z ^ n), mul_assoc, intervalIntegral.integral_const_mul, norm_mul, norm_pow,
norm_neg, norm_one, one_pow, one_mul, ← mul_assoc, ← pow_succ', mul_div_assoc]
refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (norm_nonneg z) (n + 1))
calc ‖∫ t in (0 : ℝ)..1, (t : ℂ) ^ n * (1 + t * z)⁻¹‖
_ ≤ ∫ t in (0 : ℝ)..1, ‖(t : ℂ) ^ n * (1 + t * z)⁻¹‖ :=
intervalIntegral.norm_integral_le_integral_norm zero_le_one
_ = ∫ t in (0 : ℝ)..1, t ^ n * ‖(1 + t * z)⁻¹‖ := by
refine intervalIntegral.integral_congr <| fun t ht ↦ ?_
rw [Set.uIcc_of_le zero_le_one, Set.mem_Icc] at ht
simp_rw [norm_mul, norm_pow, Complex.norm_of_nonneg ht.1]
_ ≤ ∫ t in (0 : ℝ)..1, t ^ n * (1 - ‖z‖)⁻¹ :=
intervalIntegral.integral_mono_on zero_le_one
(integrable_pow_mul_norm_one_add_mul_inv n hz) help <|
fun t ht ↦ mul_le_mul_of_nonneg_left (norm_one_add_mul_inv_le ht hz)
(pow_nonneg ((Set.mem_Icc.mp ht).1) _)
_ = (1 - ‖z‖)⁻¹ / (n + 1) := by
rw [intervalIntegral.integral_mul_const, mul_comm, integral_pow]
field_simp
|
/-- The difference `log (1+z) - z` is bounded by `‖z‖^2/(2*(1-‖z‖))` when `‖z‖ < 1`. -/
lemma norm_log_one_add_sub_self_le {z : ℂ} (hz : ‖z‖ < 1) :
‖log (1 + z) - z‖ ≤ ‖z‖ ^ 2 * (1 - ‖z‖)⁻¹ / 2 := by
convert norm_log_sub_logTaylor_le 1 hz using 2
· simp [logTaylor_succ, logTaylor_zero, sub_eq_add_neg]
| Mathlib/Analysis/SpecialFunctions/Complex/LogBounds.lean | 174 | 179 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.HomologicalComplexBiprod
import Mathlib.Algebra.Homology.Homotopy
import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy
/-! The homotopy cofiber of a morphism of homological complexes
In this file, we construct the homotopy cofiber of a morphism `φ : F ⟶ G`
between homological complexes in `HomologicalComplex C c`. In degree `i`,
it is isomorphic to `(F.X j) ⊞ (G.X i)` if there is a `j` such that `c.Rel i j`,
and `G.X i` otherwise. (This is also known as the mapping cone of `φ`. Under
the name `CochainComplex.mappingCone`, a specific API shall be developed
for the case of cochain complexes indexed by `ℤ`.)
When we assume `hc : ∀ j, ∃ i, c.Rel i j` (which holds in the case of chain complexes,
or cochain complexes indexed by `ℤ`), then for any homological complex `K`,
there is a bijection `HomologicalComplex.homotopyCofiber.descEquiv φ K hc`
between `homotopyCofiber φ ⟶ K` and the tuples `(α, hα)` with
`α : G ⟶ K` and `hα : Homotopy (φ ≫ α) 0`.
We shall also study the cylinder of a homological complex `K`: this is the
homotopy cofiber of the morphism `biprod.lift (𝟙 K) (-𝟙 K) : K ⟶ K ⊞ K`.
Then, a morphism `K.cylinder ⟶ M` is determined by the data of two
morphisms `φ₀ φ₁ : K ⟶ M` and a homotopy `h : Homotopy φ₀ φ₁`,
see `cylinder.desc`. There is also a homotopy equivalence
`cylinder.homotopyEquiv K : HomotopyEquiv K.cylinder K`. From the construction of
the cylinder, we deduce the lemma `Homotopy.map_eq_of_inverts_homotopyEquivalences`
which assert that if a functor inverts homotopy equivalences, then the image of
two homotopic maps are equal.
-/
open CategoryTheory Category Limits Preadditive
variable {C : Type*} [Category C] [Preadditive C]
namespace HomologicalComplex
variable {ι : Type*} {c : ComplexShape ι} {F G K : HomologicalComplex C c} (φ : F ⟶ G)
/-- A morphism of homological complexes `φ : F ⟶ G` has a homotopy cofiber if for all
indices `i` and `j` such that `c.Rel i j`, the binary biproduct `F.X j ⊞ G.X i` exists. -/
class HasHomotopyCofiber (φ : F ⟶ G) : Prop where
hasBinaryBiproduct (i j : ι) (hij : c.Rel i j) : HasBinaryBiproduct (F.X j) (G.X i)
instance [HasBinaryBiproducts C] : HasHomotopyCofiber φ where
hasBinaryBiproduct _ _ _ := inferInstance
variable [HasHomotopyCofiber φ] [DecidableRel c.Rel]
namespace homotopyCofiber
/-- The `X` field of the homological complex `homotopyCofiber φ`. -/
noncomputable def X (i : ι) : C :=
if hi : c.Rel i (c.next i)
then
haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hi
(F.X (c.next i)) ⊞ (G.X i)
else G.X i
/-- The canonical isomorphism `(homotopyCofiber φ).X i ≅ F.X j ⊞ G.X i` when `c.Rel i j`. -/
noncomputable def XIsoBiprod (i j : ι) (hij : c.Rel i j) [HasBinaryBiproduct (F.X j) (G.X i)] :
X φ i ≅ F.X j ⊞ G.X i :=
eqToIso (by
obtain rfl := c.next_eq' hij
apply dif_pos hij)
/-- The canonical isomorphism `(homotopyCofiber φ).X i ≅ G.X i` when `¬ c.Rel i (c.next i)`. -/
noncomputable def XIso (i : ι) (hi : ¬ c.Rel i (c.next i)) :
X φ i ≅ G.X i :=
eqToIso (dif_neg hi)
/-- The second projection `(homotopyCofiber φ).X i ⟶ G.X i`. -/
noncomputable def sndX (i : ι) : X φ i ⟶ G.X i :=
if hi : c.Rel i (c.next i)
then
haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hi
(XIsoBiprod φ _ _ hi).hom ≫ biprod.snd
else
(XIso φ i hi).hom
/-- The right inclusion `G.X i ⟶ (homotopyCofiber φ).X i`. -/
noncomputable def inrX (i : ι) : G.X i ⟶ X φ i :=
if hi : c.Rel i (c.next i)
then
haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hi
biprod.inr ≫ (XIsoBiprod φ _ _ hi).inv
else
(XIso φ i hi).inv
@[reassoc (attr := simp)]
lemma inrX_sndX (i : ι) : inrX φ i ≫ sndX φ i = 𝟙 _ := by
dsimp [sndX, inrX]
split_ifs with hi <;> simp
@[reassoc]
lemma sndX_inrX (i : ι) (hi : ¬ c.Rel i (c.next i)) :
sndX φ i ≫ inrX φ i = 𝟙 _ := by
dsimp [sndX, inrX]
simp only [dif_neg hi, Iso.hom_inv_id]
/-- The first projection `(homotopyCofiber φ).X i ⟶ F.X j` when `c.Rel i j`. -/
noncomputable def fstX (i j : ι) (hij : c.Rel i j) : X φ i ⟶ F.X j :=
haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij
(XIsoBiprod φ i j hij).hom ≫ biprod.fst
/-- The left inclusion `F.X i ⟶ (homotopyCofiber φ).X j` when `c.Rel j i`. -/
noncomputable def inlX (i j : ι) (hij : c.Rel j i) : F.X i ⟶ X φ j :=
haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij
biprod.inl ≫ (XIsoBiprod φ j i hij).inv
@[reassoc (attr := simp)]
lemma inlX_fstX (i j : ι ) (hij : c.Rel j i) :
inlX φ i j hij ≫ fstX φ j i hij = 𝟙 _ := by
simp [inlX, fstX]
@[reassoc (attr := simp)]
lemma inlX_sndX (i j : ι) (hij : c.Rel j i) :
inlX φ i j hij ≫ sndX φ j = 0 := by
obtain rfl := c.next_eq' hij
simp [inlX, sndX, dif_pos hij]
@[reassoc (attr := simp)]
lemma inrX_fstX (i j : ι) (hij : c.Rel i j) :
inrX φ i ≫ fstX φ i j hij = 0 := by
obtain rfl := c.next_eq' hij
simp [inrX, fstX, dif_pos hij]
/-- The `d` field of the homological complex `homotopyCofiber φ`. -/
noncomputable def d (i j : ι) : X φ i ⟶ X φ j :=
if hij : c.Rel i j
then
(if hj : c.Rel j (c.next j) then -fstX φ i j hij ≫ F.d _ _ ≫ inlX φ _ _ hj else 0) +
fstX φ i j hij ≫ φ.f j ≫ inrX φ j + sndX φ i ≫ G.d i j ≫ inrX φ j
else
0
lemma ext_to_X (i j : ι) (hij : c.Rel i j) {A : C} {f g : A ⟶ X φ i}
(h₁ : f ≫ fstX φ i j hij = g ≫ fstX φ i j hij) (h₂ : f ≫ sndX φ i = g ≫ sndX φ i) :
f = g := by
haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij
rw [← cancel_mono (XIsoBiprod φ i j hij).hom]
apply biprod.hom_ext
· simpa using h₁
· obtain rfl := c.next_eq' hij
simpa [sndX, dif_pos hij] using h₂
lemma ext_to_X' (i : ι) (hi : ¬ c.Rel i (c.next i)) {A : C} {f g : A ⟶ X φ i}
(h : f ≫ sndX φ i = g ≫ sndX φ i) : f = g := by
rw [← cancel_mono (XIso φ i hi).hom]
simpa only [sndX, dif_neg hi] using h
lemma ext_from_X (i j : ι) (hij : c.Rel j i) {A : C} {f g : X φ j ⟶ A}
(h₁ : inlX φ i j hij ≫ f = inlX φ i j hij ≫ g) (h₂ : inrX φ j ≫ f = inrX φ j ≫ g) :
f = g := by
haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij
rw [← cancel_epi (XIsoBiprod φ j i hij).inv]
apply biprod.hom_ext'
· simpa [inlX] using h₁
· obtain rfl := c.next_eq' hij
simpa [inrX, dif_pos hij] using h₂
lemma ext_from_X' (i : ι) (hi : ¬ c.Rel i (c.next i)) {A : C} {f g : X φ i ⟶ A}
(h : inrX φ i ≫ f = inrX φ i ≫ g) : f = g := by
rw [← cancel_epi (XIso φ i hi).inv]
simpa only [inrX, dif_neg hi] using h
@[reassoc]
lemma d_fstX (i j k : ι) (hij : c.Rel i j) (hjk : c.Rel j k) :
d φ i j ≫ fstX φ j k hjk = -fstX φ i j hij ≫ F.d j k := by
obtain rfl := c.next_eq' hjk
simp [d, dif_pos hij, dif_pos hjk]
@[reassoc]
lemma d_sndX (i j : ι) (hij : c.Rel i j) :
d φ i j ≫ sndX φ j = fstX φ i j hij ≫ φ.f j + sndX φ i ≫ G.d i j := by
dsimp [d]
split_ifs with hij <;> simp
@[reassoc]
lemma inlX_d (i j k : ι) (hij : c.Rel i j) (hjk : c.Rel j k) :
inlX φ j i hij ≫ d φ i j = -F.d j k ≫ inlX φ k j hjk + φ.f j ≫ inrX φ j := by
apply ext_to_X φ j k hjk
· dsimp
simp [d_fstX φ _ _ _ hij hjk]
· simp [d_sndX φ _ _ hij]
@[reassoc]
lemma inlX_d' (i j : ι) (hij : c.Rel i j) (hj : ¬ c.Rel j (c.next j)) :
inlX φ j i hij ≫ d φ i j = φ.f j ≫ inrX φ j := by
apply ext_to_X' _ _ hj
simp [d_sndX φ i j hij]
lemma shape (i j : ι) (hij : ¬ c.Rel i j) :
d φ i j = 0 :=
dif_neg hij
@[reassoc (attr := simp)]
lemma inrX_d (i j : ι) :
inrX φ i ≫ d φ i j = G.d i j ≫ inrX φ j := by
by_cases hij : c.Rel i j
· by_cases hj : c.Rel j (c.next j)
· apply ext_to_X _ _ _ hj
· simp [d_fstX φ _ _ _ hij]
· simp [d_sndX φ _ _ hij]
· apply ext_to_X' _ _ hj
simp [d_sndX φ _ _ hij]
· rw [shape φ _ _ hij, G.shape _ _ hij, zero_comp, comp_zero]
end homotopyCofiber
/-- The homotopy cofiber of a morphism of homological complexes,
also known as the mapping cone. -/
@[simps]
noncomputable def homotopyCofiber : HomologicalComplex C c where
X i := homotopyCofiber.X φ i
d i j := homotopyCofiber.d φ i j
shape i j hij := homotopyCofiber.shape φ i j hij
d_comp_d' i j k hij hjk := by
apply homotopyCofiber.ext_from_X φ j i hij
· dsimp
simp only [comp_zero, homotopyCofiber.inlX_d_assoc φ i j k hij hjk,
add_comp, assoc, homotopyCofiber.inrX_d, Hom.comm_assoc, neg_comp]
by_cases hk : c.Rel k (c.next k)
· simp [homotopyCofiber.inlX_d φ j k _ hjk hk]
· simp [homotopyCofiber.inlX_d' φ j k hjk hk]
· simp
namespace homotopyCofiber
/-- The right inclusion `G ⟶ homotopyCofiber φ`. -/
@[simps!]
noncomputable def inr : G ⟶ homotopyCofiber φ where
f i := inrX φ i
section
/-- The composition `φ ≫ mappingCone.inr φ` is homotopic to `0`. -/
noncomputable def inrCompHomotopy (hc : ∀ j, ∃ i, c.Rel i j) :
Homotopy (φ ≫ inr φ) 0 where
hom i j :=
if hij : c.Rel j i then inlX φ i j hij else 0
zero _ _ hij := dif_neg hij
comm j := by
obtain ⟨i, hij⟩ := hc j
rw [prevD_eq _ hij, dif_pos hij]
by_cases hj : c.Rel j (c.next j)
· simp only [comp_f, homotopyCofiber_d, zero_f, add_zero,
inlX_d φ i j _ hij hj, dNext_eq _ hj, dif_pos hj,
add_neg_cancel_left, inr_f]
· rw [dNext_eq_zero _ _ hj, zero_add, zero_f, add_zero, homotopyCofiber_d,
inlX_d' _ _ _ _ hj, comp_f, inr_f]
variable (hc : ∀ j, ∃ i, c.Rel i j)
lemma inrCompHomotopy_hom (i j : ι) (hij : c.Rel j i) :
(inrCompHomotopy φ hc).hom i j = inlX φ i j hij := dif_pos hij
lemma inrCompHomotopy_hom_eq_zero (i j : ι) (hij : ¬ c.Rel j i) :
(inrCompHomotopy φ hc).hom i j = 0 := dif_neg hij
end
section
variable (α : G ⟶ K) (hα : Homotopy (φ ≫ α) 0)
/-- The morphism `homotopyCofiber φ ⟶ K` that is induced by a morphism `α : G ⟶ K`
and a homotopy `hα : Homotopy (φ ≫ α) 0`. -/
noncomputable def desc :
homotopyCofiber φ ⟶ K where
f j :=
if hj : c.Rel j (c.next j)
then fstX φ j _ hj ≫ hα.hom _ j + sndX φ j ≫ α.f j
else sndX φ j ≫ α.f j
comm' j k hjk := by
obtain rfl := c.next_eq' hjk
dsimp
simp [dif_pos hjk]
have H := hα.comm (c.next j)
simp only [comp_f, zero_f, add_zero, prevD_eq _ hjk] at H
split_ifs with hj
· simp only [comp_add, d_sndX_assoc _ _ _ hjk, add_comp, assoc, H,
d_fstX_assoc _ _ _ _ hjk, neg_comp, dNext, AddMonoidHom.mk'_apply]
abel
· simp only [d_sndX_assoc _ _ _ hjk, add_comp, assoc, add_left_inj, H,
dNext_eq_zero _ _ hj, zero_add]
lemma desc_f (j k : ι) (hjk : c.Rel j k) :
(desc φ α hα).f j = fstX φ j _ hjk ≫ hα.hom _ j + sndX φ j ≫ α.f j := by
obtain rfl := c.next_eq' hjk
apply dif_pos hjk
lemma desc_f' (j : ι) (hj : ¬ c.Rel j (c.next j)) :
(desc φ α hα).f j = sndX φ j ≫ α.f j := by
apply dif_neg hj
@[reassoc (attr := simp)]
lemma inlX_desc_f (i j : ι) (hjk : c.Rel j i) :
inlX φ i j hjk ≫ (desc φ α hα).f j = hα.hom i j := by
obtain rfl := c.next_eq' hjk
dsimp [desc]
rw [dif_pos hjk, comp_add, inlX_fstX_assoc, inlX_sndX_assoc, zero_comp, add_zero]
@[reassoc (attr := simp)]
lemma inrX_desc_f (i : ι) :
inrX φ i ≫ (desc φ α hα).f i = α.f i := by
dsimp [desc]
split_ifs <;> simp
@[reassoc (attr := simp)]
lemma inr_desc :
inr φ ≫ desc φ α hα = α := by aesop_cat
@[reassoc (attr := simp)]
lemma inrCompHomotopy_hom_desc_hom (hc : ∀ j, ∃ i, c.Rel i j) (i j : ι) :
(inrCompHomotopy φ hc).hom i j ≫ (desc φ α hα).f j = hα.hom i j := by
by_cases hij : c.Rel j i
· dsimp
simp only [inrCompHomotopy_hom φ hc i j hij, desc_f φ α hα _ _ hij,
comp_add, inlX_fstX_assoc, inlX_sndX_assoc, zero_comp, add_zero]
· simp only [Homotopy.zero _ _ _ hij, zero_comp]
lemma eq_desc (f : homotopyCofiber φ ⟶ K) (hc : ∀ j, ∃ i, c.Rel i j) :
f = desc φ (inr φ ≫ f) (Homotopy.trans (Homotopy.ofEq (by simp))
(((inrCompHomotopy φ hc).compRight f).trans (Homotopy.ofEq (by simp)))) := by
ext j
by_cases hj : c.Rel j (c.next j)
· apply ext_from_X φ _ _ hj
· simp [inrCompHomotopy_hom _ _ _ _ hj]
· simp
· apply ext_from_X' φ _ hj
simp
end
lemma descSigma_ext_iff {φ : F ⟶ G} {K : HomologicalComplex C c}
(x y : Σ (α : G ⟶ K), Homotopy (φ ≫ α) 0) :
x = y ↔ x.1 = y.1 ∧ (∀ (i j : ι) (_ : c.Rel j i), x.2.hom i j = y.2.hom i j) := by
constructor
· rintro rfl
tauto
· obtain ⟨x₁, x₂⟩ := x
obtain ⟨y₁, y₂⟩ := y
rintro ⟨rfl, h⟩
simp only [Sigma.mk.inj_iff, heq_eq_eq, true_and]
ext i j
by_cases hij : c.Rel j i
· exact h _ _ hij
· simp only [Homotopy.zero _ _ _ hij]
/-- Morphisms `homotopyCofiber φ ⟶ K` are uniquely determined by
a morphism `α : G ⟶ K` and a homotopy from `φ ≫ α` to `0`. -/
noncomputable def descEquiv (K : HomologicalComplex C c) (hc : ∀ j, ∃ i, c.Rel i j) :
(Σ (α : G ⟶ K), Homotopy (φ ≫ α) 0) ≃ (homotopyCofiber φ ⟶ K) where
toFun := fun ⟨α, hα⟩ => desc φ α hα
invFun f := ⟨inr φ ≫ f, Homotopy.trans (Homotopy.ofEq (by simp))
(((inrCompHomotopy φ hc).compRight f).trans (Homotopy.ofEq (by simp)))⟩
right_inv f := (eq_desc φ f hc).symm
left_inv := fun ⟨α, hα⟩ => by
rw [descSigma_ext_iff]
aesop_cat
end homotopyCofiber
section
variable (K)
variable [∀ i, HasBinaryBiproduct (K.X i) (K.X i)]
[HasHomotopyCofiber (biprod.lift (𝟙 K) (-𝟙 K))]
/-- The cylinder object of a homological complex `K` is the homotopy cofiber
of the morphism `biprod.lift (𝟙 K) (-𝟙 K) : K ⟶ K ⊞ K`. -/
noncomputable abbrev cylinder := homotopyCofiber (biprod.lift (𝟙 K) (-𝟙 K))
namespace cylinder
/-- The left inclusion `K ⟶ K.cylinder`. -/
noncomputable def ι₀ : K ⟶ K.cylinder := biprod.inl ≫ homotopyCofiber.inr _
/-- The right inclusion `K ⟶ K.cylinder`. -/
noncomputable def ι₁ : K ⟶ K.cylinder := biprod.inr ≫ homotopyCofiber.inr _
variable {K}
section
variable (φ₀ φ₁ : K ⟶ F) (h : Homotopy φ₀ φ₁)
/-- The morphism `K.cylinder ⟶ F` that is induced by two morphisms `φ₀ φ₁ : K ⟶ F`
and a homotopy `h : Homotopy φ₀ φ₁`. -/
noncomputable def desc : K.cylinder ⟶ F :=
homotopyCofiber.desc _ (biprod.desc φ₀ φ₁)
(Homotopy.trans (Homotopy.ofEq (by
simp only [biprod.lift_desc, id_comp, neg_comp, sub_eq_add_neg]))
((Homotopy.equivSubZero h)))
@[reassoc (attr := simp)]
lemma ι₀_desc : ι₀ K ≫ desc φ₀ φ₁ h = φ₀ := by simp [ι₀, desc]
@[reassoc (attr := simp)]
lemma ι₁_desc : ι₁ K ≫ desc φ₀ φ₁ h = φ₁ := by simp [ι₁, desc]
end
variable (K)
/-- The projection `π : K.cylinder ⟶ K`. -/
noncomputable def π : K.cylinder ⟶ K := desc (𝟙 K) (𝟙 K) (Homotopy.refl _)
@[reassoc (attr := simp)]
lemma ι₀_π : ι₀ K ≫ π K = 𝟙 K := by simp [π]
@[reassoc (attr := simp)]
lemma ι₁_π : ι₁ K ≫ π K = 𝟙 K := by simp [π]
/-- The left inclusion `K.X i ⟶ K.cylinder.X j` when `c.Rel j i`. -/
noncomputable abbrev inlX (i j : ι) (hij : c.Rel j i) : K.X i ⟶ K.cylinder.X j :=
homotopyCofiber.inlX (biprod.lift (𝟙 K) (-𝟙 K)) i j hij
/-- The right inclusion `(K ⊞ K).X i ⟶ K.cylinder.X i`. -/
noncomputable abbrev inrX (i : ι) : (K ⊞ K).X i ⟶ K.cylinder.X i :=
homotopyCofiber.inrX (biprod.lift (𝟙 K) (-𝟙 K)) i
@[reassoc (attr := simp)]
lemma inlX_π (i j : ι) (hij : c.Rel j i) :
inlX K i j hij ≫ (π K).f j = 0 := by
erw [homotopyCofiber.inlX_desc_f]
simp [Homotopy.equivSubZero]
@[reassoc (attr := simp)]
lemma inrX_π (i : ι) :
inrX K i ≫ (π K).f i = (biprod.desc (𝟙 _) (𝟙 K)).f i :=
homotopyCofiber.inrX_desc_f _ _ _ _
section
variable (hc : ∀ j, ∃ i, c.Rel i j)
namespace πCompι₀Homotopy
/-- A null homotopic map `K.cylinder ⟶ K.cylinder` which identifies to
`π K ≫ ι₀ K - 𝟙 _`, see `nullHomotopicMap_eq`. -/
noncomputable def nullHomotopicMap : K.cylinder ⟶ K.cylinder :=
Homotopy.nullHomotopicMap'
(fun i j hij => homotopyCofiber.sndX (biprod.lift (𝟙 K) (-𝟙 K)) i ≫
(biprod.snd : K ⊞ K ⟶ K).f i ≫ inlX K i j hij)
/-- The obvious homotopy from `nullHomotopicMap K` to zero. -/
noncomputable def nullHomotopy : Homotopy (nullHomotopicMap K) 0 :=
Homotopy.nullHomotopy' _
lemma inlX_nullHomotopy_f (i j : ι) (hij : c.Rel j i) :
inlX K i j hij ≫ (nullHomotopicMap K).f j =
inlX K i j hij ≫ (π K ≫ ι₀ K - 𝟙 _).f j := by
dsimp [nullHomotopicMap]
by_cases hj : ∃ (k : ι), c.Rel k j
· obtain ⟨k, hjk⟩ := hj
simp only [assoc, Homotopy.nullHomotopicMap'_f hjk hij, homotopyCofiber_X, homotopyCofiber_d,
homotopyCofiber.d_sndX_assoc _ _ _ hij, add_comp, comp_add, homotopyCofiber.inlX_fstX_assoc,
homotopyCofiber.inlX_sndX_assoc, zero_comp, add_zero, comp_sub, inlX_π_assoc, comp_id,
zero_sub, ← HomologicalComplex.comp_f_assoc, biprod.lift_snd, neg_f_apply, id_f,
neg_comp, id_comp]
· simp only [not_exists] at hj
simp only [Homotopy.nullHomotopicMap'_f_of_not_rel_right hij hj,
homotopyCofiber_X, homotopyCofiber_d, assoc, comp_sub, comp_id,
homotopyCofiber.d_sndX_assoc _ _ _ hij, add_comp, comp_add, zero_comp, add_zero,
homotopyCofiber.inlX_fstX_assoc, homotopyCofiber.inlX_sndX_assoc,
← HomologicalComplex.comp_f_assoc, biprod.lift_snd, neg_f_apply, id_f, neg_comp,
id_comp, inlX_π_assoc, zero_sub]
| include hc
| Mathlib/Algebra/Homology/HomotopyCofiber.lean | 477 | 478 |
/-
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.Pow.NNReal
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Analysis.SumOverResidueClass
/-!
# Convergence of `p`-series
In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`.
The proof is based on the
[Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k`
converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in
`NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove
`summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series.
## Tags
p-series, Cauchy condensation test
-/
/-!
### Schlömilch's generalization of the Cauchy condensation test
In this section we prove the Schlömilch's generalization of the Cauchy condensation test:
for a strictly increasing `u : ℕ → ℕ` with ratio of successive differences bounded and an
antitone `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`, `∑ k, f k` converges if and only if
so does `∑ k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it
into a series of lemmas with explicit estimates of partial sums of each series in terms of the
partial sums of the other series.
-/
/--
A sequence `u` has the property that its ratio of successive differences is bounded
when there is a positive real number `C` such that, for all n ∈ ℕ,
(u (n + 2) - u (n + 1)) ≤ C * (u (n + 1) - u n)
-/
def SuccDiffBounded (C : ℕ) (u : ℕ → ℕ) : Prop :=
∀ n : ℕ, u (n + 2) - u (n + 1) ≤ C • (u (n + 1) - u n)
namespace Finset
variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M]
{f : ℕ → M} {u : ℕ → ℕ}
theorem le_sum_schlomilch' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ Ico (u 0) (u n), f k) ≤ ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by
induction n with
| zero => simp
| succ n ihn =>
suffices (∑ k ∈ Ico (u n) (u (n + 1)), f k) ≤ (u (n + 1) - u n) • f (u n) by
rw [sum_range_succ, ← sum_Ico_consecutive]
· exact add_le_add ihn this
exacts [hu n.zero_le, hu n.le_succ]
have : ∀ k ∈ Ico (u n) (u (n + 1)), f k ≤ f (u n) := fun k hk =>
hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem le_sum_condensed' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ Ico 1 (2 ^ n), f k) ≤ ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by
convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_right_mono₀ one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
theorem le_sum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ range (u n), f k) ≤
∑ k ∈ range (u 0), f k + ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by
convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (∑ k ∈ range (u 0), f k)
rw [← sum_range_add_sum_Ico _ (hu n.zero_le)]
theorem le_sum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range (2 ^ n), f k) ≤ f 0 + ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by
convert add_le_add_left (le_sum_condensed' hf n) (f 0)
rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add]
theorem sum_schlomilch_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ range n, (u (k + 1) - u k) • f (u (k + 1))) ≤ ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by
induction n with
| zero => simp
| succ n ihn =>
suffices (u (n + 1) - u n) • f (u (n + 1)) ≤ ∑ k ∈ Ico (u n + 1) (u (n + 1) + 1), f k by
rw [sum_range_succ, ← sum_Ico_consecutive]
exacts [add_le_add ihn this,
(add_le_add_right (hu n.zero_le) _ : u 0 + 1 ≤ u n + 1),
add_le_add_right (hu n.le_succ) _]
have : ∀ k ∈ Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) ≤ f k := fun k hk =>
hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le
(mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2)
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem sum_condensed_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range n, 2 ^ k • f (2 ^ (k + 1))) ≤ ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by
convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_right_mono₀ one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
theorem sum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : ℕ) :
∑ k ∈ range (n + 1), (u (k + 1) - u k) • f (u k) ≤
(u 1 - u 0) • f (u 0) + C • ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by
rw [sum_range_succ', add_comm]
gcongr
suffices ∑ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤
C • ∑ k ∈ range n, ((u (k + 1) - u k) • f (u (k + 1))) by
refine this.trans (nsmul_le_nsmul_right ?_ _)
exact sum_schlomilch_le' hf h_pos hu n
have : ∀ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤
C • ((u (k + 1) - u k) • f (u (k + 1))) := by
intro k _
rw [smul_smul]
gcongr
· exact h_nonneg (u (k + 1))
exact mod_cast h_succ_diff k
convert sum_le_sum this
simp [smul_sum]
theorem sum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range (n + 1), 2 ^ k • f (2 ^ k)) ≤ f 1 + 2 • ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by
convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1)
simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul]
end Finset
namespace ENNReal
open Filter Finset
variable {u : ℕ → ℕ} {f : ℕ → ℝ≥0∞}
open NNReal in
theorem le_tsum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : StrictMono u) :
∑' k , f k ≤ ∑ k ∈ range (u 0), f k + ∑' k : ℕ, (u (k + 1) - u k) * f (u k) := by
rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop]
refine iSup_le fun n =>
(Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _)
have (k : ℕ) : (u (k + 1) - u k : ℝ≥0∞) = (u (k + 1) - (u k : ℕ) : ℕ) := by
simp [NNReal.coe_sub (Nat.cast_le (α := ℝ≥0).mpr <| (hu k.lt_succ_self).le)]
simp only [nsmul_eq_mul, this]
apply ENNReal.sum_le_tsum
theorem le_tsum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
∑' k, f k ≤ f 0 + ∑' k : ℕ, 2 ^ k * f (2 ^ k) := by
rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)]
refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _)
simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two]
apply ENNReal.sum_le_tsum
theorem tsum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) :
∑' k : ℕ, (u (k + 1) - u k) * f (u k) ≤ (u 1 - u 0) * f (u 0) + C * ∑' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _)
· simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n
· exact zero_le _
theorem tsum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) :
(∑' k : ℕ, 2 ^ k * f (2 ^ k)) ≤ f 1 + 2 * ∑' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id), two_mul, ← two_nsmul]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(nsmul_le_nsmul_right (ENNReal.sum_le_tsum <| Finset.Ico 2 (2 ^ n + 1)) _) _)
simpa using Finset.sum_condensed_le hf n
end ENNReal
namespace NNReal
open Finset
open ENNReal in
/-- for a series of `NNReal` version. -/
theorem summable_schlomilch_iff {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ≥0}
(hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m)
(h_pos : ∀ n, 0 < u n) (hu_strict : StrictMono u)
(hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : ℕ => (u (k + 1) - (u k : ℝ≥0)) * f (u k)) ↔ Summable f := by
simp only [← tsum_coe_ne_top_iff_summable, Ne, not_iff_not, ENNReal.coe_mul]
constructor <;> intro h
· replace hf : ∀ m n, 1 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn)
have h_nonneg : ∀ n, 0 ≤ (f n : ℝ≥0∞) := fun n =>
ENNReal.coe_le_coe.2 (f n).2
obtain hC := tsum_schlomilch_le hf h_pos h_nonneg hu_strict.monotone h_succ_diff
simpa [add_eq_top, mul_ne_top, mul_eq_top, hC_nonzero] using eq_top_mono hC h
· replace hf : ∀ m n, 0 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf hm hmn)
have : ∑ k ∈ range (u 0), (f k : ℝ≥0∞) ≠ ∞ := sum_ne_top.2 fun a _ => coe_ne_top
simpa [h, add_eq_top, this] using le_tsum_schlomilch hf h_pos hu_strict
open ENNReal in
theorem summable_condensed_iff {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
(Summable fun k : ℕ => (2 : ℝ≥0) ^ k * f (2 ^ k)) ↔ Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff hf (pow_pos zero_lt_two) (pow_right_strictMono₀ _root_.one_lt_two)
two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
end NNReal
open NNReal in
/-- for series of nonnegative real numbers. -/
theorem summable_schlomilch_iff_of_nonneg {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n)
(hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu_strict : StrictMono u) (hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : ℕ => (u (k + 1) - (u k : ℝ)) * f (u k)) ↔ Summable f := by
lift f to ℕ → ℝ≥0 using h_nonneg
simp only [NNReal.coe_le_coe] at *
have (k : ℕ) : (u (k + 1) - (u k : ℝ)) = ((u (k + 1) : ℝ≥0) - (u k : ℝ≥0) : ℝ≥0) := by
have := Nat.cast_le (α := ℝ≥0).mpr <| (hu_strict k.lt_succ_self).le
simp [NNReal.coe_sub this]
simp_rw [this]
exact_mod_cast NNReal.summable_schlomilch_iff hf h_pos hu_strict hC_nonzero h_succ_diff
/-- Cauchy condensation test for antitone series of nonnegative real numbers. -/
theorem summable_condensed_iff_of_nonneg {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n)
(h_mono : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
(Summable fun k : ℕ => (2 : ℝ) ^ k * f (2 ^ k)) ↔ Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff_of_nonneg h_nonneg h_mono (pow_pos zero_lt_two)
(pow_right_strictMono₀ one_lt_two) two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
section p_series
/-!
### Convergence of the `p`-series
In this section we prove that for a real number `p`, the series `∑' n : ℕ, 1 / (n ^ p)` converges if
and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the
Cauchy condensation test we formalized above. This test implies that `∑ n, 1 / (n ^ p)` converges if
and only if `∑ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with
common ratio `2 ^ {1 - p}`. -/
namespace Real
open Filter
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_rpow_inv {p : ℝ} :
Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by
rcases le_or_lt 0 p with hp | hp
/- Cauchy condensation test applies only to antitone sequences, so we consider the
cases `0 ≤ p` and `p < 0` separately. -/
· rw [← summable_condensed_iff_of_nonneg]
· simp_rw [Nat.cast_pow, Nat.cast_two, ← rpow_natCast, ← rpow_mul zero_lt_two.le, mul_comm _ p,
rpow_mul zero_lt_two.le, rpow_natCast, ← inv_pow, ← mul_pow,
summable_geometric_iff_norm_lt_one]
nth_rw 1 [← rpow_one 2]
rw [← division_def, ← rpow_sub zero_lt_two, norm_eq_abs,
abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le]
norm_num
· intro n
positivity
· intro m n hm hmn
gcongr
-- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges.
· suffices ¬Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) by
have : ¬1 < p := fun hp₁ => hp.not_le (zero_le_one.trans hp₁.le)
simpa only [this, iff_false]
intro h
obtain ⟨k : ℕ, hk₁ : ((k : ℝ) ^ p)⁻¹ < 1, hk₀ : k ≠ 0⟩ :=
((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and
(eventually_cofinite_ne 0)).exists
apply hk₀
rw [← pos_iff_ne_zero, ← @Nat.cast_pos ℝ] at hk₀
simpa [inv_lt_one₀ (rpow_pos_of_pos hk₀ _), one_lt_rpow_iff_of_pos hk₀, hp,
hp.not_lt, hk₀] using hk₁
@[simp]
theorem summable_nat_rpow {p : ℝ} : Summable (fun n => (n : ℝ) ^ p : ℕ → ℝ) ↔ p < -1 := by
rcases neg_surjective p with ⟨p, rfl⟩
simp [rpow_neg]
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem summable_one_div_nat_rpow {p : ℝ} :
Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by
simp
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_pow_inv {p : ℕ} :
Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by
simp only [← rpow_natCast, summable_nat_rpow_inv, Nat.one_lt_cast]
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem summable_one_div_nat_pow {p : ℕ} :
Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by
simp only [one_div, Real.summable_nat_pow_inv]
/-- Summability of the `p`-series over `ℤ`. -/
theorem summable_one_div_int_pow {p : ℕ} :
(Summable fun n : ℤ ↦ 1 / (n : ℝ) ^ p) ↔ 1 < p := by
refine ⟨fun h ↦ summable_one_div_nat_pow.mp (h.comp_injective Nat.cast_injective),
fun h ↦ .of_nat_of_neg (summable_one_div_nat_pow.mpr h)
(((summable_one_div_nat_pow.mpr h).mul_left <| 1 / (-1 : ℝ) ^ p).congr fun n ↦ ?_)⟩
rw [Int.cast_neg, Int.cast_natCast, neg_eq_neg_one_mul (n : ℝ), mul_pow, mul_one_div, div_div]
theorem summable_abs_int_rpow {b : ℝ} (hb : 1 < b) :
Summable fun n : ℤ => |(n : ℝ)| ^ (-b) := by
apply Summable.of_nat_of_neg
on_goal 2 => simp_rw [Int.cast_neg, abs_neg]
all_goals
simp_rw [Int.cast_natCast, fun n : ℕ => abs_of_nonneg (n.cast_nonneg : 0 ≤ (n : ℝ))]
rwa [summable_nat_rpow, neg_lt_neg_iff]
/-- Harmonic series is not unconditionally summable. -/
theorem not_summable_natCast_inv : ¬Summable (fun n => n⁻¹ : ℕ → ℝ) := by
have : ¬Summable (fun n => ((n : ℝ) ^ 1)⁻¹ : ℕ → ℝ) :=
mt (summable_nat_pow_inv (p := 1)).1 (lt_irrefl 1)
simpa
/-- Harmonic series is not unconditionally summable. -/
theorem not_summable_one_div_natCast : ¬Summable (fun n => 1 / n : ℕ → ℝ) := by
simpa only [inv_eq_one_div] using not_summable_natCast_inv
/-- **Divergence of the Harmonic Series** -/
theorem tendsto_sum_range_one_div_nat_succ_atTop :
Tendsto (fun n => ∑ i ∈ Finset.range n, (1 / (i + 1) : ℝ)) atTop atTop := by
rw [← not_summable_iff_tendsto_nat_atTop_of_nonneg]
· exact_mod_cast mt (_root_.summable_nat_add_iff 1).1 not_summable_one_div_natCast
· exact fun i => by positivity
end Real
namespace NNReal
@[simp]
theorem summable_rpow_inv {p : ℝ} :
Summable (fun n => ((n : ℝ≥0) ^ p)⁻¹ : ℕ → ℝ≥0) ↔ 1 < p := by
simp [← NNReal.summable_coe]
@[simp]
theorem summable_rpow {p : ℝ} : Summable (fun n => (n : ℝ≥0) ^ p : ℕ → ℝ≥0) ↔ p < -1 := by
simp [← NNReal.summable_coe]
theorem summable_one_div_rpow {p : ℝ} :
Summable (fun n => 1 / (n : ℝ≥0) ^ p : ℕ → ℝ≥0) ↔ 1 < p := by
simp
end NNReal
end p_series
section
open Finset
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
theorem sum_Ioc_inv_sq_le_sub {k n : ℕ} (hk : k ≠ 0) (h : k ≤ n) :
(∑ i ∈ Ioc k n, ((i : α) ^ 2)⁻¹) ≤ (k : α)⁻¹ - (n : α)⁻¹ := by
refine Nat.le_induction ?_ ?_ n h
· simp only [Ioc_self, sum_empty, sub_self, le_refl]
intro n hn IH
rw [sum_Ioc_succ_top hn]
apply (add_le_add IH le_rfl).trans
simp only [sub_eq_add_neg, add_assoc, Nat.cast_add, Nat.cast_one, le_add_neg_iff_add_le,
add_le_iff_nonpos_right, neg_add_le_iff_le_add, add_zero]
have A : 0 < (n : α) := by simpa using hk.bot_lt.trans_le hn
field_simp
rw [div_le_div_iff₀ _ A]
· linarith
· positivity
theorem sum_Ioo_inv_sq_le (k n : ℕ) : (∑ i ∈ Ioo k n, (i ^ 2 : α)⁻¹) ≤ 2 / (k + 1) :=
calc
(∑ i ∈ Ioo k n, ((i : α) ^ 2)⁻¹) ≤ ∑ i ∈ Ioc k (max (k + 1) n), ((i : α) ^ 2)⁻¹ := by
apply sum_le_sum_of_subset_of_nonneg
· intro x hx
simp only [mem_Ioo] at hx
simp only [hx, hx.2.le, mem_Ioc, le_max_iff, or_true, and_self_iff]
· intro i _hi _hident
positivity
_ ≤ ((k + 1 : α) ^ 2)⁻¹ + ∑ i ∈ Ioc k.succ (max (k + 1) n), ((i : α) ^ 2)⁻¹ := by
rw [← Nat.Icc_succ_left, ← Nat.Ico_succ_right, sum_eq_sum_Ico_succ_bot]
swap; · exact Nat.succ_lt_succ ((Nat.lt_succ_self k).trans_le (le_max_left _ _))
rw [Nat.Ico_succ_right, Nat.Icc_succ_left, Nat.cast_succ]
_ ≤ ((k + 1 : α) ^ 2)⁻¹ + (k + 1 : α)⁻¹ := by
refine add_le_add le_rfl ((sum_Ioc_inv_sq_le_sub ?_ (le_max_left _ _)).trans ?_)
· simp only [Ne, Nat.succ_ne_zero, not_false_iff]
· simp only [Nat.cast_succ, one_div, sub_le_self_iff, inv_nonneg, Nat.cast_nonneg]
_ ≤ 1 / (k + 1) + 1 / (k + 1) := by
have A : (1 : α) ≤ k + 1 := by simp only [le_add_iff_nonneg_left, Nat.cast_nonneg]
simp_rw [← one_div]
gcongr
simpa using pow_right_mono₀ A one_le_two
_ = 2 / (k + 1) := by ring
end
open Set Nat in
/-- The harmonic series restricted to a residue class is not summable. -/
lemma Real.not_summable_indicator_one_div_natCast {m : ℕ} (hm : m ≠ 0) (k : ZMod m) :
¬ Summable ({n : ℕ | (n : ZMod m) = k}.indicator fun n : ℕ ↦ (1 / n : ℝ)) := by
have : NeZero m := ⟨hm⟩ -- instance is needed below
rw [← summable_nat_add_iff 1] -- shift by one to avoid non-monotonicity at zero
have h (n : ℕ) : {n : ℕ | (n : ZMod m) = k - 1}.indicator (fun n : ℕ ↦ (1 / (n + 1 :) : ℝ)) n =
if (n : ZMod m) = k - 1 then (1 / (n + 1) : ℝ) else (0 : ℝ) := by
simp only [indicator_apply, mem_setOf_eq, cast_add, cast_one]
simp_rw [indicator_apply, mem_setOf, cast_add, cast_one, ← eq_sub_iff_add_eq, ← h]
rw [summable_indicator_mod_iff (fun n₁ n₂ h ↦ by gcongr) (k - 1)]
exact mt (summable_nat_add_iff (f := fun n : ℕ ↦ 1 / (n : ℝ)) 1).mp not_summable_one_div_natCast
/-!
## Translating the `p`-series by a real number
-/
section shifted
open Filter Asymptotics Topology
lemma Real.summable_one_div_nat_add_rpow (a : ℝ) (s : ℝ) :
Summable (fun n : ℕ ↦ 1 / |n + a| ^ s) ↔ 1 < s := by
suffices ∀ (b c : ℝ), Summable (fun n : ℕ ↦ 1 / |n + b| ^ s) →
Summable (fun n : ℕ ↦ 1 / |n + c| ^ s) by
simp_rw [← summable_one_div_nat_rpow, Iff.intro (this a 0) (this 0 a), add_zero, Nat.abs_cast]
refine fun b c h ↦ summable_of_isBigO_nat h (isBigO_of_div_tendsto_nhds ?_ 1 ?_)
· filter_upwards [eventually_gt_atTop (Nat.ceil |b|)] with n hn hx
have hna : 0 < n + b := by linarith [lt_of_abs_lt ((abs_neg b).symm ▸ Nat.lt_of_ceil_lt hn)]
exfalso
revert hx
positivity
· simp_rw [Pi.div_def, div_div, mul_one_div, one_div_div]
refine (?_ : Tendsto (fun x : ℝ ↦ |x + b| ^ s / |x + c| ^ s) atTop (𝓝 1)).comp
tendsto_natCast_atTop_atTop
have : Tendsto (fun x : ℝ ↦ 1 + (b - c) / x) atTop (𝓝 1) := by
simpa using tendsto_const_nhds.add ((tendsto_const_nhds (X := ℝ)).div_atTop tendsto_id)
have : Tendsto (fun x ↦ (x + b) / (x + c)) atTop (𝓝 1) := by
refine (this.comp (tendsto_id.atTop_add (tendsto_const_nhds (x := c)))).congr' ?_
filter_upwards [eventually_gt_atTop (-c)] with x hx
field_simp [(by linarith : 0 < x + c).ne']
apply (one_rpow s ▸ (continuousAt_rpow_const _ s (by simp)).tendsto.comp this).congr'
filter_upwards [eventually_gt_atTop (-b), eventually_gt_atTop (-c)] with x hb hc
rw [neg_lt_iff_pos_add] at hb hc
rw [Function.comp_apply, div_rpow hb.le hc.le, abs_of_pos hb, abs_of_pos hc]
lemma Real.summable_one_div_int_add_rpow (a : ℝ) (s : ℝ) :
Summable (fun n : ℤ ↦ 1 / |n + a| ^ s) ↔ 1 < s := by
simp_rw [summable_int_iff_summable_nat_and_neg, ← abs_neg (↑(-_ : ℤ) + a), neg_add,
Int.cast_neg, neg_neg, Int.cast_natCast, summable_one_div_nat_add_rpow, and_self]
theorem summable_pow_div_add {α : Type*} (x : α) [RCLike α] (q k : ℕ) (hq : 1 < q) :
Summable fun n : ℕ => ‖(x / (↑n + k) ^ q)‖ := by
simp_rw [norm_div]
| apply Summable.const_div
simpa [hq, Nat.cast_add, one_div, norm_inv, norm_pow, RCLike.norm_natCast,
Real.summable_nat_pow_inv, iff_true]
using summable_nat_add_iff (f := fun x => ‖1 / (x ^ q : α)‖) k
end shifted
| Mathlib/Analysis/PSeries.lean | 468 | 491 |
/-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bryan Gin-ge Chen, Yaël Dillies
-/
import Mathlib.Algebra.Group.Idempotent
import Mathlib.Algebra.Ring.Equiv
import Mathlib.Algebra.Ring.PUnit
import Mathlib.Order.Hom.BoundedLattice
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Ring
/-!
# Boolean rings
A Boolean ring is a ring where multiplication is idempotent. They are equivalent to Boolean
algebras.
## Main declarations
* `BooleanRing`: a typeclass for rings where multiplication is idempotent.
* `BooleanRing.toBooleanAlgebra`: Turn a Boolean ring into a Boolean algebra.
* `BooleanAlgebra.toBooleanRing`: Turn a Boolean algebra into a Boolean ring.
* `AsBoolAlg`: Type-synonym for the Boolean algebra associated to a Boolean ring.
* `AsBoolRing`: Type-synonym for the Boolean ring associated to a Boolean algebra.
## Implementation notes
We provide two ways of turning a Boolean algebra/ring into a Boolean ring/algebra:
* Instances on the same type accessible in locales `BooleanAlgebraOfBooleanRing` and
`BooleanRingOfBooleanAlgebra`.
* Type-synonyms `AsBoolAlg` and `AsBoolRing`.
At this point in time, it is not clear the first way is useful, but we keep it for educational
purposes and because it is easier than dealing with
`ofBoolAlg`/`toBoolAlg`/`ofBoolRing`/`toBoolRing` explicitly.
## Tags
boolean ring, boolean algebra
-/
open scoped symmDiff
variable {α β γ : Type*}
/-- A Boolean ring is a ring where multiplication is idempotent. -/
class BooleanRing (α) extends Ring α where
/-- Multiplication in a boolean ring is idempotent. -/
isIdempotentElem (a : α) : IsIdempotentElem a
namespace BooleanRing
variable [BooleanRing α] (a b : α)
@[scoped simp]
lemma mul_self : a * a = a := IsIdempotentElem.eq (isIdempotentElem a)
instance : Std.IdempotentOp (α := α) (· * ·) :=
⟨BooleanRing.mul_self⟩
@[scoped simp]
theorem add_self : a + a = 0 := by
have : a + a = a + a + (a + a) :=
calc
a + a = (a + a) * (a + a) := by rw [mul_self]
_ = a * a + a * a + (a * a + a * a) := by rw [add_mul, mul_add]
_ = a + a + (a + a) := by rw [mul_self]
rwa [right_eq_add] at this
@[scoped simp]
theorem neg_eq : -a = a :=
calc
-a = -a + 0 := by rw [add_zero]
_ = -a + -a + a := by rw [← neg_add_cancel, add_assoc]
_ = a := by rw [add_self, zero_add]
theorem add_eq_zero' : a + b = 0 ↔ a = b :=
calc
a + b = 0 ↔ a = -b := add_eq_zero_iff_eq_neg
_ ↔ a = b := by rw [neg_eq]
@[simp]
theorem mul_add_mul : a * b + b * a = 0 := by
have : a + b = a + b + (a * b + b * a) :=
calc
a + b = (a + b) * (a + b) := by rw [mul_self]
_ = a * a + a * b + (b * a + b * b) := by rw [add_mul, mul_add, mul_add]
_ = a + a * b + (b * a + b) := by simp only [mul_self]
_ = a + b + (a * b + b * a) := by abel
rwa [left_eq_add] at this
@[scoped simp]
theorem sub_eq_add : a - b = a + b := by rw [sub_eq_add_neg, add_right_inj, neg_eq]
@[simp]
theorem mul_one_add_self : a * (1 + a) = 0 := by rw [mul_add, mul_one, mul_self, add_self]
-- Note [lower instance priority]
instance (priority := 100) toCommRing : CommRing α :=
{ (inferInstance : BooleanRing α) with
mul_comm := fun a b => by rw [← add_eq_zero', mul_add_mul] }
end BooleanRing
instance : BooleanRing PUnit :=
⟨fun _ => Subsingleton.elim _ _⟩
/-! ### Turning a Boolean ring into a Boolean algebra -/
section RingToAlgebra
/-- Type synonym to view a Boolean ring as a Boolean algebra. -/
def AsBoolAlg (α : Type*) :=
α
/-- The "identity" equivalence between `AsBoolAlg α` and `α`. -/
def toBoolAlg : α ≃ AsBoolAlg α :=
Equiv.refl _
/-- The "identity" equivalence between `α` and `AsBoolAlg α`. -/
def ofBoolAlg : AsBoolAlg α ≃ α :=
Equiv.refl _
@[simp]
theorem toBoolAlg_symm_eq : (@toBoolAlg α).symm = ofBoolAlg :=
rfl
@[simp]
theorem ofBoolAlg_symm_eq : (@ofBoolAlg α).symm = toBoolAlg :=
rfl
@[simp]
theorem toBoolAlg_ofBoolAlg (a : AsBoolAlg α) : toBoolAlg (ofBoolAlg a) = a :=
rfl
@[simp]
theorem ofBoolAlg_toBoolAlg (a : α) : ofBoolAlg (toBoolAlg a) = a :=
rfl
theorem toBoolAlg_inj {a b : α} : toBoolAlg a = toBoolAlg b ↔ a = b :=
Iff.rfl
theorem ofBoolAlg_inj {a b : AsBoolAlg α} : ofBoolAlg a = ofBoolAlg b ↔ a = b :=
Iff.rfl
instance [Inhabited α] : Inhabited (AsBoolAlg α) :=
‹Inhabited α›
variable [BooleanRing α] [BooleanRing β] [BooleanRing γ]
namespace BooleanRing
/-- The join operation in a Boolean ring is `x + y + x * y`. -/
def sup : Max α :=
⟨fun x y => x + y + x * y⟩
/-- The meet operation in a Boolean ring is `x * y`. -/
def inf : Min α :=
⟨(· * ·)⟩
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: add priority 100. lower instance priority
scoped [BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.sup
scoped [BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.inf
open BooleanAlgebraOfBooleanRing
theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by
dsimp only [(· ⊔ ·)]
ring
theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := by
dsimp only [(· ⊓ ·)]
ring
theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := by
dsimp only [(· ⊔ ·)]
ring
theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := by
dsimp only [(· ⊓ ·)]
ring
theorem sup_inf_self (a b : α) : a ⊔ a ⊓ b = a := by
dsimp only [(· ⊔ ·), (· ⊓ ·)]
rw [← mul_assoc, mul_self, add_assoc, add_self, add_zero]
theorem inf_sup_self (a b : α) : a ⊓ (a ⊔ b) = a := by
dsimp only [(· ⊔ ·), (· ⊓ ·)]
rw [mul_add, mul_add, mul_self, ← mul_assoc, mul_self, add_assoc, add_self, add_zero]
theorem le_sup_inf_aux (a b c : α) : (a + b + a * b) * (a + c + a * c) = a + b * c + a * (b * c) :=
calc
(a + b + a * b) * (a + c + a * c) =
a * a + b * c + a * (b * c) + (a * b + a * a * b) + (a * c + a * a * c) +
(a * b * c + a * a * b * c) := by ring
_ = a + b * c + a * (b * c) := by simp only [mul_self, add_self, add_zero]
theorem le_sup_inf (a b c : α) : (a ⊔ b) ⊓ (a ⊔ c) ⊔ (a ⊔ b ⊓ c) = a ⊔ b ⊓ c := by
dsimp only [(· ⊔ ·), (· ⊓ ·)]
rw [le_sup_inf_aux, add_self, mul_self, zero_add]
/-- The Boolean algebra structure on a Boolean ring.
The data is defined so that:
* `a ⊔ b` unfolds to `a + b + a * b`
* `a ⊓ b` unfolds to `a * b`
* `a ≤ b` unfolds to `a + b + a * b = b`
* `⊥` unfolds to `0`
* `⊤` unfolds to `1`
* `aᶜ` unfolds to `1 + a`
* `a \ b` unfolds to `a * (1 + b)`
-/
def toBooleanAlgebra : BooleanAlgebra α :=
{ Lattice.mk' sup_comm sup_assoc inf_comm inf_assoc sup_inf_self inf_sup_self with
le_sup_inf := le_sup_inf
top := 1
le_top := fun a => show a + 1 + a * 1 = 1 by rw [mul_one, add_comm a 1,
add_assoc, add_self, add_zero]
bot := 0
bot_le := fun a => show 0 + a + 0 * a = a by rw [zero_mul, zero_add, add_zero]
compl := fun a => 1 + a
inf_compl_le_bot := fun a =>
show a * (1 + a) + 0 + a * (1 + a) * 0 = 0 by norm_num [mul_add, mul_self, add_self]
top_le_sup_compl := fun a => by
change
1 + (a + (1 + a) + a * (1 + a)) + 1 * (a + (1 + a) + a * (1 + a)) =
a + (1 + a) + a * (1 + a)
norm_num [mul_add, mul_self, add_self]
rw [← add_assoc, add_self] }
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: add priority 100. lower instance priority
scoped[BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.toBooleanAlgebra
end BooleanRing
open BooleanRing
instance : BooleanAlgebra (AsBoolAlg α) :=
@BooleanRing.toBooleanAlgebra α _
@[simp]
theorem ofBoolAlg_top : ofBoolAlg (⊤ : AsBoolAlg α) = 1 :=
rfl
@[simp]
theorem ofBoolAlg_bot : ofBoolAlg (⊥ : AsBoolAlg α) = 0 :=
rfl
@[simp]
theorem ofBoolAlg_sup (a b : AsBoolAlg α) :
ofBoolAlg (a ⊔ b) = ofBoolAlg a + ofBoolAlg b + ofBoolAlg a * ofBoolAlg b :=
rfl
@[simp]
theorem ofBoolAlg_inf (a b : AsBoolAlg α) : ofBoolAlg (a ⊓ b) = ofBoolAlg a * ofBoolAlg b :=
rfl
@[simp]
theorem ofBoolAlg_compl (a : AsBoolAlg α) : ofBoolAlg aᶜ = 1 + ofBoolAlg a :=
rfl
@[simp]
theorem ofBoolAlg_sdiff (a b : AsBoolAlg α) : ofBoolAlg (a \ b) = ofBoolAlg a * (1 + ofBoolAlg b) :=
rfl
private theorem of_boolalg_symmDiff_aux (a b : α) : (a + b + a * b) * (1 + a * b) = a + b :=
calc (a + b + a * b) * (1 + a * b)
_ = a + b + (a * b + a * b * (a * b)) + (a * (b * b) + a * a * b) := by ring
_ = a + b := by simp only [mul_self, add_self, add_zero]
@[simp]
theorem ofBoolAlg_symmDiff (a b : AsBoolAlg α) : ofBoolAlg (a ∆ b) = ofBoolAlg a + ofBoolAlg b := by
rw [symmDiff_eq_sup_sdiff_inf]
exact of_boolalg_symmDiff_aux _ _
@[simp]
theorem ofBoolAlg_mul_ofBoolAlg_eq_left_iff {a b : AsBoolAlg α} :
ofBoolAlg a * ofBoolAlg b = ofBoolAlg a ↔ a ≤ b :=
@inf_eq_left (AsBoolAlg α) _ _ _
@[simp]
theorem toBoolAlg_zero : toBoolAlg (0 : α) = ⊥ :=
rfl
@[simp]
theorem toBoolAlg_one : toBoolAlg (1 : α) = ⊤ :=
rfl
@[simp]
theorem toBoolAlg_mul (a b : α) : toBoolAlg (a * b) = toBoolAlg a ⊓ toBoolAlg b :=
rfl
@[simp]
theorem toBoolAlg_add_add_mul (a b : α) : toBoolAlg (a + b + a * b) = toBoolAlg a ⊔ toBoolAlg b :=
rfl
@[simp]
theorem toBoolAlg_add (a b : α) : toBoolAlg (a + b) = toBoolAlg a ∆ toBoolAlg b :=
(ofBoolAlg_symmDiff a b).symm
/-- Turn a ring homomorphism from Boolean rings `α` to `β` into a bounded lattice homomorphism
from `α` to `β` considered as Boolean algebras. -/
@[simps]
protected def RingHom.asBoolAlg (f : α →+* β) : BoundedLatticeHom (AsBoolAlg α) (AsBoolAlg β) where
toFun := toBoolAlg ∘ f ∘ ofBoolAlg
map_sup' a b := by
dsimp
simp_rw [map_add f, map_mul f, toBoolAlg_add_add_mul]
map_inf' := f.map_mul'
| map_top' := f.map_one'
map_bot' := f.map_zero'
| Mathlib/Algebra/Ring/BooleanRing.lean | 311 | 313 |
/-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Fin.VecNotation
import Mathlib.SetTheory.Cardinal.Basic
/-!
# Basics on First-Order Structures
This file defines first-order languages and structures in the style of the
[Flypitch project](https://flypitch.github.io/), as well as several important maps between
structures.
## Main Definitions
- A `FirstOrder.Language` defines a language as a pair of functions from the natural numbers to
`Type l`. One sends `n` to the type of `n`-ary functions, and the other sends `n` to the type of
`n`-ary relations.
- A `FirstOrder.Language.Structure` interprets the symbols of a given `FirstOrder.Language` in the
context of a given type.
- A `FirstOrder.Language.Hom`, denoted `M →[L] N`, is a map from the `L`-structure `M` to the
`L`-structure `N` that commutes with the interpretations of functions, and which preserves the
interpretations of relations (although only in the forward direction).
- A `FirstOrder.Language.Embedding`, denoted `M ↪[L] N`, is an embedding from the `L`-structure `M`
to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves
the interpretations of relations in both directions.
- A `FirstOrder.Language.Equiv`, denoted `M ≃[L] N`, is an equivalence from the `L`-structure `M`
to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves
the interpretations of relations in both directions.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v u' v' w w'
open Cardinal
namespace FirstOrder
/-! ### Languages and Structures -/
-- intended to be used with explicit universe parameters
/-- A first-order language consists of a type of functions of every natural-number arity and a
type of relations of every natural-number arity. -/
@[nolint checkUnivs]
structure Language where
/-- For every arity, a `Type*` of functions of that arity -/
Functions : ℕ → Type u
/-- For every arity, a `Type*` of relations of that arity -/
Relations : ℕ → Type v
namespace Language
variable (L : Language.{u, v})
/-- A language is relational when it has no function symbols. -/
abbrev IsRelational : Prop := ∀ n, IsEmpty (L.Functions n)
/-- A language is algebraic when it has no relation symbols. -/
abbrev IsAlgebraic : Prop := ∀ n, IsEmpty (L.Relations n)
/-- The empty language has no symbols. -/
protected def empty : Language :=
⟨fun _ => Empty, fun _ => Empty⟩
deriving IsAlgebraic, IsRelational
instance : Inhabited Language :=
⟨Language.empty⟩
/-- The sum of two languages consists of the disjoint union of their symbols. -/
protected def sum (L' : Language.{u', v'}) : Language :=
⟨fun n => L.Functions n ⊕ L'.Functions n, fun n => L.Relations n ⊕ L'.Relations n⟩
/-- The type of constants in a given language. -/
protected abbrev Constants :=
L.Functions 0
/-- The type of symbols in a given language. -/
abbrev Symbols :=
(Σ l, L.Functions l) ⊕ (Σ l, L.Relations l)
/-- The cardinality of a language is the cardinality of its type of symbols. -/
def card : Cardinal :=
#L.Symbols
variable {L} {L' : Language.{u', v'}}
theorem card_eq_card_functions_add_card_relations :
L.card =
(Cardinal.sum fun l => Cardinal.lift.{v} #(L.Functions l)) +
Cardinal.sum fun l => Cardinal.lift.{u} #(L.Relations l) := by
simp only [card, mk_sum, mk_sigma, lift_sum]
instance isRelational_sum [L.IsRelational] [L'.IsRelational] : IsRelational (L.sum L') :=
fun _ => instIsEmptySum
instance isAlgebraic_sum [L.IsAlgebraic] [L'.IsAlgebraic] : IsAlgebraic (L.sum L') :=
fun _ => instIsEmptySum
@[simp]
theorem card_empty : Language.empty.card = 0 := by simp only [card, mk_sum, mk_sigma, mk_eq_zero,
sum_const, mk_eq_aleph0, lift_id', mul_zero, add_zero]
@[deprecated (since := "2025-02-05")] alias empty_card := card_empty
instance isEmpty_empty : IsEmpty Language.empty.Symbols := by
simp only [Language.Symbols, isEmpty_sum, isEmpty_sigma]
exact ⟨fun _ => inferInstance, fun _ => inferInstance⟩
instance Countable.countable_functions [h : Countable L.Symbols] : Countable (Σl, L.Functions l) :=
@Function.Injective.countable _ _ h _ Sum.inl_injective
@[simp]
theorem card_functions_sum (i : ℕ) :
#((L.sum L').Functions i)
= (Cardinal.lift.{u'} #(L.Functions i) + Cardinal.lift.{u} #(L'.Functions i) : Cardinal) := by
simp [Language.sum]
@[simp]
theorem card_relations_sum (i : ℕ) :
#((L.sum L').Relations i) =
Cardinal.lift.{v'} #(L.Relations i) + Cardinal.lift.{v} #(L'.Relations i) := by
simp [Language.sum]
theorem card_sum :
(L.sum L').card = Cardinal.lift.{max u' v'} L.card + Cardinal.lift.{max u v} L'.card := by
simp only [card, mk_sum, mk_sigma, card_functions_sum, sum_add_distrib', lift_add, lift_sum,
lift_lift, card_relations_sum, add_assoc,
add_comm (Cardinal.sum fun i => (#(L'.Functions i)).lift)]
/-- Passes a `DecidableEq` instance on a type of function symbols through the `Language`
constructor. Despite the fact that this is proven by `inferInstance`, it is still needed -
see the `example`s in `ModelTheory/Ring/Basic`. -/
instance instDecidableEqFunctions {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (f n)] :
DecidableEq ((⟨f, R⟩ : Language).Functions n) := inferInstance
/-- Passes a `DecidableEq` instance on a type of relation symbols through the `Language`
constructor. Despite the fact that this is proven by `inferInstance`, it is still needed -
see the `example`s in `ModelTheory/Ring/Basic`. -/
instance instDecidableEqRelations {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (R n)] :
DecidableEq ((⟨f, R⟩ : Language).Relations n) := inferInstance
variable (L) (M : Type w)
/-- A first-order structure on a type `M` consists of interpretations of all the symbols in a given
language. Each function of arity `n` is interpreted as a function sending tuples of length `n`
(modeled as `(Fin n → M)`) to `M`, and a relation of arity `n` is a function from tuples of length
`n` to `Prop`. -/
@[ext]
class Structure where
/-- Interpretation of the function symbols -/
funMap : ∀ {n}, L.Functions n → (Fin n → M) → M := by
exact fun {n} => isEmptyElim
/-- Interpretation of the relation symbols -/
RelMap : ∀ {n}, L.Relations n → (Fin n → M) → Prop := by
exact fun {n} => isEmptyElim
variable (N : Type w') [L.Structure M] [L.Structure N]
open Structure
/-- Used for defining `FirstOrder.Language.Theory.ModelType.instInhabited`. -/
def Inhabited.trivialStructure {α : Type*} [Inhabited α] : L.Structure α :=
⟨default, default⟩
/-! ### Maps -/
/-- A homomorphism between first-order structures is a function that commutes with the
interpretations of functions and maps tuples in one structure where a given relation is true to
tuples in the second structure where that relation is still true. -/
structure Hom where
/-- The underlying function of a homomorphism of structures -/
toFun : M → N
/-- The homomorphism commutes with the interpretations of the function symbols -/
-- Porting note:
-- The autoparam here used to be `obviously`. We would like to replace it with `aesop`
-- but that isn't currently sufficient.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases
-- If that can be improved, we should change this to `by aesop` and remove the proofs below.
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
intros; trivial
/-- The homomorphism sends related elements to related elements -/
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r x → RelMap r (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " →[" L "] " B => FirstOrder.Language.Hom L A B
/-- An embedding of first-order structures is an embedding that commutes with the
interpretations of functions and relations. -/
structure Embedding extends M ↪ N where
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " ↪[" L "] " B => FirstOrder.Language.Embedding L A B
/-- An equivalence of first-order structures is an equivalence that commutes with the
interpretations of functions and relations. -/
structure Equiv extends M ≃ N where
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " ≃[" L "] " B => FirstOrder.Language.Equiv L A B
variable {L M N} {P : Type*} [L.Structure P] {Q : Type*} [L.Structure Q]
/-- Interpretation of a constant symbol -/
@[coe]
def constantMap (c : L.Constants) : M := funMap c default
instance : CoeTC L.Constants M :=
⟨constantMap⟩
theorem funMap_eq_coe_constants {c : L.Constants} {x : Fin 0 → M} : funMap c x = c :=
congr rfl (funext finZeroElim)
/-- Given a language with a nonempty type of constants, any structure will be nonempty. This cannot
be a global instance, because `L` becomes a metavariable. -/
theorem nonempty_of_nonempty_constants [h : Nonempty L.Constants] : Nonempty M :=
h.map (↑)
/-- `HomClass L F M N` states that `F` is a type of `L`-homomorphisms. You should extend this
typeclass when you extend `FirstOrder.Language.Hom`. -/
class HomClass (L : outParam Language) (F : Type*) (M N : outParam Type*)
[FunLike F M N] [L.Structure M] [L.Structure N] : Prop where
map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x)
map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r x → RelMap r (φ ∘ x)
/-- `StrongHomClass L F M N` states that `F` is a type of `L`-homomorphisms which preserve
relations in both directions. -/
class StrongHomClass (L : outParam Language) (F : Type*) (M N : outParam Type*)
[FunLike F M N] [L.Structure M] [L.Structure N] : Prop where
map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x)
map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r (φ ∘ x) ↔ RelMap r x
instance (priority := 100) StrongHomClass.homClass {F : Type*} [L.Structure M]
[L.Structure N] [FunLike F M N] [StrongHomClass L F M N] : HomClass L F M N where
map_fun := StrongHomClass.map_fun
map_rel φ _ R x := (StrongHomClass.map_rel φ R x).2
/-- Not an instance to avoid a loop. -/
theorem HomClass.strongHomClassOfIsAlgebraic [L.IsAlgebraic] {F M N} [L.Structure M] [L.Structure N]
[FunLike F M N] [HomClass L F M N] : StrongHomClass L F M N where
map_fun := HomClass.map_fun
map_rel _ _ := isEmptyElim
theorem HomClass.map_constants {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[HomClass L F M N] (φ : F) (c : L.Constants) : φ c = c :=
(HomClass.map_fun φ c default).trans (congr rfl (funext default))
attribute [inherit_doc FirstOrder.Language.Hom.map_fun'] FirstOrder.Language.Embedding.map_fun'
FirstOrder.Language.HomClass.map_fun FirstOrder.Language.StrongHomClass.map_fun
FirstOrder.Language.Equiv.map_fun'
attribute [inherit_doc FirstOrder.Language.Hom.map_rel'] FirstOrder.Language.Embedding.map_rel'
FirstOrder.Language.HomClass.map_rel FirstOrder.Language.StrongHomClass.map_rel
FirstOrder.Language.Equiv.map_rel'
namespace Hom
instance instFunLike : FunLike (M →[L] N) M N where
coe := Hom.toFun
coe_injective' f g h := by cases f; cases g; cases h; rfl
instance homClass : HomClass L (M →[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
instance [L.IsAlgebraic] : StrongHomClass L (M →[L] N) M N :=
HomClass.strongHomClassOfIsAlgebraic
@[simp]
theorem toFun_eq_coe {f : M →[L] N} : f.toFun = (f : M → N) :=
rfl
@[ext]
theorem ext ⦃f g : M →[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
@[simp]
theorem map_fun (φ : M →[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M →[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M →[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r x → RelMap r (φ ∘ x) :=
HomClass.map_rel φ r x
variable (L) (M)
/-- The identity map from a structure to itself. -/
@[refl]
def id : M →[L] M where
toFun m := m
variable {L} {M}
instance : Inhabited (M →[L] M) :=
⟨id L M⟩
@[simp]
theorem id_apply (x : M) : id L M x = x :=
rfl
/-- Composition of first-order homomorphisms. -/
@[trans]
def comp (hnp : N →[L] P) (hmn : M →[L] N) : M →[L] P where
toFun := hnp ∘ hmn
-- Porting note: should be done by autoparam?
map_fun' _ _ := by simp; rfl
-- Porting note: should be done by autoparam?
map_rel' _ _ h := map_rel _ _ _ (map_rel _ _ _ h)
@[simp]
theorem comp_apply (g : N →[L] P) (f : M →[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
/-- Composition of first-order homomorphisms is associative. -/
theorem comp_assoc (f : M →[L] N) (g : N →[L] P) (h : P →[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
@[simp]
theorem comp_id (f : M →[L] N) : f.comp (id L M) = f :=
rfl
@[simp]
theorem id_comp (f : M →[L] N) : (id L N).comp f = f :=
rfl
end Hom
/-- Any element of a `HomClass` can be realized as a first_order homomorphism. -/
@[simps] def HomClass.toHom {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[HomClass L F M N] : F → M →[L] N := fun φ =>
⟨φ, HomClass.map_fun φ, HomClass.map_rel φ⟩
namespace Embedding
instance funLike : FunLike (M ↪[L] N) M N where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
congr
ext x
exact funext_iff.1 h x
instance embeddingLike : EmbeddingLike (M ↪[L] N) M N where
injective' f := f.toEmbedding.injective
instance strongHomClass : StrongHomClass L (M ↪[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
@[simp]
theorem map_fun (φ : M ↪[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M ↪[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M ↪[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r (φ ∘ x) ↔ RelMap r x :=
StrongHomClass.map_rel φ r x
/-- A first-order embedding is also a first-order homomorphism. -/
def toHom : (M ↪[L] N) → M →[L] N :=
HomClass.toHom
@[simp]
theorem coe_toHom {f : M ↪[L] N} : (f.toHom : M → N) = f :=
rfl
theorem coe_injective : @Function.Injective (M ↪[L] N) (M → N) (↑)
| f, g, h => by
cases f
cases g
congr
ext x
exact funext_iff.1 h x
@[ext]
theorem ext ⦃f g : M ↪[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
coe_injective (funext h)
theorem toHom_injective : @Function.Injective (M ↪[L] N) (M →[L] N) (·.toHom) := by
intro f f' h
ext
exact congr_fun (congr_arg (↑) h) _
@[simp]
theorem toHom_inj {f g : M ↪[L] N} : f.toHom = g.toHom ↔ f = g :=
⟨fun h ↦ toHom_injective h, fun h ↦ congr_arg (·.toHom) h⟩
theorem injective (f : M ↪[L] N) : Function.Injective f :=
f.toEmbedding.injective
/-- In an algebraic language, any injective homomorphism is an embedding. -/
@[simps!]
def ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : M ↪[L] N :=
{ f with
inj' := hf
map_rel' := fun {_} r x => StrongHomClass.map_rel f r x }
@[simp]
theorem coeFn_ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) :
(ofInjective hf : M → N) = f :=
rfl
@[simp]
theorem ofInjective_toHom [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) :
(ofInjective hf).toHom = f := by
ext; simp
variable (L) (M)
/-- The identity embedding from a structure to itself. -/
@[refl]
def refl : M ↪[L] M where toEmbedding := Function.Embedding.refl M
variable {L} {M}
instance : Inhabited (M ↪[L] M) :=
⟨refl L M⟩
@[simp]
theorem refl_apply (x : M) : refl L M x = x :=
rfl
/-- Composition of first-order embeddings. -/
@[trans]
def comp (hnp : N ↪[L] P) (hmn : M ↪[L] N) : M ↪[L] P where
toFun := hnp ∘ hmn
inj' := hnp.injective.comp hmn.injective
-- Porting note: should be done by autoparam?
map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial
-- Porting note: should be done by autoparam?
map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel]
@[simp]
theorem comp_apply (g : N ↪[L] P) (f : M ↪[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
/-- Composition of first-order embeddings is associative. -/
theorem comp_assoc (f : M ↪[L] N) (g : N ↪[L] P) (h : P ↪[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
theorem comp_injective (h : N ↪[L] P) :
Function.Injective (h.comp : (M ↪[L] N) → (M ↪[L] P)) := by
intro f g hfg
ext x; exact h.injective (DFunLike.congr_fun hfg x)
@[simp]
theorem comp_inj (h : N ↪[L] P) (f g : M ↪[L] N) : h.comp f = h.comp g ↔ f = g :=
⟨fun eq ↦ h.comp_injective eq, congr_arg h.comp⟩
theorem toHom_comp_injective (h : N ↪[L] P) :
Function.Injective (h.toHom.comp : (M →[L] N) → (M →[L] P)) := by
intro f g hfg
ext x; exact h.injective (DFunLike.congr_fun hfg x)
@[simp]
theorem toHom_comp_inj (h : N ↪[L] P) (f g : M →[L] N) : h.toHom.comp f = h.toHom.comp g ↔ f = g :=
⟨fun eq ↦ h.toHom_comp_injective eq, congr_arg h.toHom.comp⟩
@[simp]
theorem comp_toHom (hnp : N ↪[L] P) (hmn : M ↪[L] N) :
(hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom :=
rfl
@[simp]
theorem comp_refl (f : M ↪[L] N) : f.comp (refl L M) = f := DFunLike.coe_injective rfl
@[simp]
theorem refl_comp (f : M ↪[L] N) : (refl L N).comp f = f := DFunLike.coe_injective rfl
@[simp]
theorem refl_toHom : (refl L M).toHom = Hom.id L M :=
rfl
end Embedding
/-- Any element of an injective `StrongHomClass` can be realized as a first_order embedding. -/
@[simps] def StrongHomClass.toEmbedding {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[EmbeddingLike F M N] [StrongHomClass L F M N] : F → M ↪[L] N := fun φ =>
⟨⟨φ, EmbeddingLike.injective φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩
namespace Equiv
instance : EquivLike (M ≃[L] N) M N where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' f g h₁ h₂ := by
cases f
cases g
simp only [mk.injEq]
ext x
exact funext_iff.1 h₁ x
instance : StrongHomClass L (M ≃[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
/-- The inverse of a first-order equivalence is a first-order equivalence. -/
@[symm]
def symm (f : M ≃[L] N) : N ≃[L] M :=
{ f.toEquiv.symm with
map_fun' := fun n f' {x} => by
simp only [Equiv.toFun_as_coe]
rw [Equiv.symm_apply_eq]
refine Eq.trans ?_ (f.map_fun' f' (f.toEquiv.symm ∘ x)).symm
rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp]
map_rel' := fun n r {x} => by
simp only [Equiv.toFun_as_coe]
refine (f.map_rel' r (f.toEquiv.symm ∘ x)).symm.trans ?_
rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] }
@[simp]
theorem symm_symm (f : M ≃[L] N) :
f.symm.symm = f :=
rfl
theorem symm_bijective : Function.Bijective (symm : (M ≃[L] N) → _) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp]
theorem apply_symm_apply (f : M ≃[L] N) (a : N) : f (f.symm a) = a :=
f.toEquiv.apply_symm_apply a
@[simp]
theorem symm_apply_apply (f : M ≃[L] N) (a : M) : f.symm (f a) = a :=
f.toEquiv.symm_apply_apply a
@[simp]
theorem map_fun (φ : M ≃[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M ≃[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M ≃[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r (φ ∘ x) ↔ RelMap r x :=
StrongHomClass.map_rel φ r x
/-- A first-order equivalence is also a first-order embedding. -/
def toEmbedding : (M ≃[L] N) → M ↪[L] N :=
StrongHomClass.toEmbedding
/-- A first-order equivalence is also a first-order homomorphism. -/
def toHom : (M ≃[L] N) → M →[L] N :=
HomClass.toHom
@[simp]
theorem toEmbedding_toHom (f : M ≃[L] N) : f.toEmbedding.toHom = f.toHom :=
rfl
@[simp]
theorem coe_toHom {f : M ≃[L] N} : (f.toHom : M → N) = (f : M → N) :=
rfl
@[simp]
theorem coe_toEmbedding (f : M ≃[L] N) : (f.toEmbedding : M → N) = (f : M → N) :=
rfl
theorem injective_toEmbedding : Function.Injective (toEmbedding : (M ≃[L] N) → M ↪[L] N) := by
intro _ _ h; apply DFunLike.coe_injective; exact congr_arg (DFunLike.coe ∘ Embedding.toHom) h
theorem coe_injective : @Function.Injective (M ≃[L] N) (M → N) (↑) :=
DFunLike.coe_injective
@[ext]
theorem ext ⦃f g : M ≃[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
coe_injective (funext h)
theorem bijective (f : M ≃[L] N) : Function.Bijective f :=
EquivLike.bijective f
theorem injective (f : M ≃[L] N) : Function.Injective f :=
EquivLike.injective f
theorem surjective (f : M ≃[L] N) : Function.Surjective f :=
EquivLike.surjective f
variable (L) (M)
/-- The identity equivalence from a structure to itself. -/
@[refl]
def refl : M ≃[L] M where toEquiv := _root_.Equiv.refl M
variable {L} {M}
instance : Inhabited (M ≃[L] M) :=
⟨refl L M⟩
@[simp]
theorem refl_apply (x : M) : refl L M x = x := by simp [refl]; rfl
/-- Composition of first-order equivalences. -/
@[trans]
def comp (hnp : N ≃[L] P) (hmn : M ≃[L] N) : M ≃[L] P :=
{ hmn.toEquiv.trans hnp.toEquiv with
toFun := hnp ∘ hmn
-- Porting note: should be done by autoparam?
map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial
-- Porting note: should be done by autoparam?
map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel] }
@[simp]
theorem comp_apply (g : N ≃[L] P) (f : M ≃[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
@[simp]
theorem comp_refl (g : M ≃[L] N) : g.comp (refl L M) = g :=
rfl
@[simp]
theorem refl_comp (g : M ≃[L] N) : (refl L N).comp g = g :=
rfl
@[simp]
theorem refl_toEmbedding : (refl L M).toEmbedding = Embedding.refl L M :=
rfl
@[simp]
theorem refl_toHom : (refl L M).toHom = Hom.id L M :=
rfl
/-- Composition of first-order homomorphisms is associative. -/
theorem comp_assoc (f : M ≃[L] N) (g : N ≃[L] P) (h : P ≃[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
theorem injective_comp (h : N ≃[L] P) :
Function.Injective (h.comp : (M ≃[L] N) → (M ≃[L] P)) := by
intro f g hfg
ext x; exact h.injective (congr_fun (congr_arg DFunLike.coe hfg) x)
@[simp]
theorem comp_toHom (hnp : N ≃[L] P) (hmn : M ≃[L] N) :
(hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom :=
rfl
@[simp]
theorem comp_toEmbedding (hnp : N ≃[L] P) (hmn : M ≃[L] N) :
(hnp.comp hmn).toEmbedding = hnp.toEmbedding.comp hmn.toEmbedding :=
rfl
@[simp]
theorem self_comp_symm (f : M ≃[L] N) : f.comp f.symm = refl L N := by
ext; rw [comp_apply, apply_symm_apply, refl_apply]
@[simp]
theorem symm_comp_self (f : M ≃[L] N) : f.symm.comp f = refl L M := by
ext; rw [comp_apply, symm_apply_apply, refl_apply]
@[simp]
theorem symm_comp_self_toEmbedding (f : M ≃[L] N) :
f.symm.toEmbedding.comp f.toEmbedding = Embedding.refl L M := by
rw [← comp_toEmbedding, symm_comp_self, refl_toEmbedding]
@[simp]
theorem self_comp_symm_toEmbedding (f : M ≃[L] N) :
f.toEmbedding.comp f.symm.toEmbedding = Embedding.refl L N := by
rw [← comp_toEmbedding, self_comp_symm, refl_toEmbedding]
@[simp]
theorem symm_comp_self_toHom (f : M ≃[L] N) :
f.symm.toHom.comp f.toHom = Hom.id L M := by
rw [← comp_toHom, symm_comp_self, refl_toHom]
@[simp]
theorem self_comp_symm_toHom (f : M ≃[L] N) :
f.toHom.comp f.symm.toHom = Hom.id L N := by
rw [← comp_toHom, self_comp_symm, refl_toHom]
@[simp]
theorem comp_symm (f : M ≃[L] N) (g : N ≃[L] P) : (g.comp f).symm = f.symm.comp g.symm :=
rfl
theorem comp_right_injective (h : M ≃[L] N) :
Function.Injective (fun f ↦ f.comp h : (N ≃[L] P) → (M ≃[L] P)) := by
intro f g hfg
convert (congr_arg (fun r : (M ≃[L] P) ↦ r.comp h.symm) hfg) <;>
rw [comp_assoc, self_comp_symm, comp_refl]
@[simp]
theorem comp_right_inj (h : M ≃[L] N) (f g : N ≃[L] P) : f.comp h = g.comp h ↔ f = g :=
⟨fun eq ↦ h.comp_right_injective eq, congr_arg (fun (r : N ≃[L] P) ↦ r.comp h)⟩
end Equiv
/-- Any element of a bijective `StrongHomClass` can be realized as a first_order isomorphism. -/
@[simps] def StrongHomClass.toEquiv {F M N} [L.Structure M] [L.Structure N] [EquivLike F M N]
[StrongHomClass L F M N] : F → M ≃[L] N := fun φ =>
⟨⟨φ, EquivLike.inv φ, EquivLike.left_inv φ, EquivLike.right_inv φ⟩, StrongHomClass.map_fun φ,
StrongHomClass.map_rel φ⟩
section SumStructure
variable (L₁ L₂ : Language) (S : Type*) [L₁.Structure S] [L₂.Structure S]
instance sumStructure : (L₁.sum L₂).Structure S where
funMap := Sum.elim funMap funMap
RelMap := Sum.elim RelMap RelMap
variable {L₁ L₂ S}
@[simp]
theorem funMap_sumInl {n : ℕ} (f : L₁.Functions n) :
@funMap (L₁.sum L₂) S _ n (Sum.inl f) = funMap f :=
rfl
@[simp]
theorem funMap_sumInr {n : ℕ} (f : L₂.Functions n) :
@funMap (L₁.sum L₂) S _ n (Sum.inr f) = funMap f :=
rfl
@[simp]
theorem relMap_sumInl {n : ℕ} (R : L₁.Relations n) :
@RelMap (L₁.sum L₂) S _ n (Sum.inl R) = RelMap R :=
rfl
@[simp]
theorem relMap_sumInr {n : ℕ} (R : L₂.Relations n) :
@RelMap (L₁.sum L₂) S _ n (Sum.inr R) = RelMap R :=
rfl
@[deprecated (since := "2025-02-21")] alias funMap_sum_inl := funMap_sumInl
@[deprecated (since := "2025-02-21")] alias funMap_sum_inr := funMap_sumInr
@[deprecated (since := "2025-02-21")] alias relMap_sum_inl := relMap_sumInl
@[deprecated (since := "2025-02-21")] alias relMap_sum_inr := relMap_sumInr
end SumStructure
section Empty
/-- Any type can be made uniquely into a structure over the empty language. -/
def emptyStructure : Language.empty.Structure M where
instance : Unique (Language.empty.Structure M) :=
⟨⟨Language.emptyStructure⟩, fun a => by
ext _ f <;> exact Empty.elim f⟩
variable [Language.empty.Structure M] [Language.empty.Structure N]
instance (priority := 100) strongHomClassEmpty {F} [FunLike F M N] :
StrongHomClass Language.empty F M N :=
⟨fun _ _ f => Empty.elim f, fun _ _ r => Empty.elim r⟩
@[simp]
theorem empty.nonempty_embedding_iff :
Nonempty (M ↪[Language.empty] N) ↔ Cardinal.lift.{w'} #M ≤ Cardinal.lift.{w} #N :=
_root_.trans ⟨Nonempty.map fun f => f.toEmbedding, Nonempty.map StrongHomClass.toEmbedding⟩
Cardinal.lift_mk_le'.symm
@[simp]
theorem empty.nonempty_equiv_iff :
Nonempty (M ≃[Language.empty] N) ↔ Cardinal.lift.{w'} #M = Cardinal.lift.{w} #N :=
_root_.trans ⟨Nonempty.map fun f => f.toEquiv, Nonempty.map fun f => { toEquiv := f }⟩
Cardinal.lift_mk_eq'.symm
/-- Makes a `Language.empty.Hom` out of any function.
This is only needed because there is no instance of `FunLike (M → N) M N`, and thus no instance of
`Language.empty.HomClass M N`. -/
@[simps]
def _root_.Function.emptyHom (f : M → N) : M →[Language.empty] N where toFun := f
end Empty
end Language
end FirstOrder
namespace Equiv
open FirstOrder FirstOrder.Language FirstOrder.Language.Structure
open FirstOrder
variable {L : Language} {M : Type*} {N : Type*} [L.Structure M]
/-- A structure induced by a bijection. -/
@[simps!]
def inducedStructure (e : M ≃ N) : L.Structure N :=
⟨fun f x => e (funMap f (e.symm ∘ x)), fun r x => RelMap r (e.symm ∘ x)⟩
/-- A bijection as a first-order isomorphism with the induced structure on the codomain. -/
def inducedStructureEquiv (e : M ≃ N) : @Language.Equiv L M N _ (inducedStructure e) := by
letI : L.Structure N := inducedStructure e
exact
{ e with
map_fun' := @fun n f x => by simp [← Function.comp_assoc e.symm e x]
map_rel' := @fun n r x => by simp [← Function.comp_assoc e.symm e x] }
@[simp]
theorem toEquiv_inducedStructureEquiv (e : M ≃ N) :
@Language.Equiv.toEquiv L M N _ (inducedStructure e) (inducedStructureEquiv e) = e :=
rfl
@[simp]
theorem toFun_inducedStructureEquiv (e : M ≃ N) :
DFunLike.coe (@inducedStructureEquiv L M N _ e) = e :=
rfl
@[simp]
theorem toFun_inducedStructureEquiv_Symm (e : M ≃ N) :
(by
letI : L.Structure N := inducedStructure e
exact DFunLike.coe (@inducedStructureEquiv L M N _ e).symm) = (e.symm : N → M) :=
rfl
end Equiv
| Mathlib/ModelTheory/Basic.lean | 994 | 996 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Data.Finite.Sum
import Mathlib.RingTheory.FiniteType
import Mathlib.RingTheory.Finiteness.Ideal
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.RingTheory.MvPolynomial.Tower
/-!
# Finiteness conditions in commutative algebra
In this file we define several notions of finiteness that are common in commutative algebra.
## Main declarations
- `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite`
all of these express that some object is finitely generated *as module* over some base ring.
- `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType`
all of these express that some object is finitely generated *as algebra* over some base ring.
- `Algebra.FinitePresentation`, `RingHom.FinitePresentation`, `AlgHom.FinitePresentation`
all of these express that some object is finitely presented *as algebra* over some base ring.
-/
open Function (Surjective)
open Polynomial
section ModuleAndAlgebra
universe w₁ w₂ w₃
-- Porting note: `M, N` is never used
variable (R : Type w₁) (A : Type w₂) (B : Type w₃)
/-- An algebra over a commutative semiring is `Algebra.FinitePresentation` if it is the quotient of
a polynomial ring in `n` variables by a finitely generated ideal. -/
class Algebra.FinitePresentation [CommSemiring R] [Semiring A] [Algebra R A] : Prop where
out : ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] A), Surjective f ∧ (RingHom.ker f.toRingHom).FG
namespace Algebra
variable [CommRing R] [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
namespace FiniteType
variable {R A B}
/-- A finitely presented algebra is of finite type. -/
instance of_finitePresentation [FinitePresentation R A] : FiniteType R A := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
apply FiniteType.iff_quotient_mvPolynomial''.2
exact ⟨n, f, hf.1⟩
end FiniteType
namespace FinitePresentation
variable {R A B}
/-- An algebra over a Noetherian ring is finitely generated if and only if it is finitely
presented. -/
theorem of_finiteType [IsNoetherianRing R] : FiniteType R A ↔ FinitePresentation R A := by
refine ⟨fun h => ?_, fun hfp => Algebra.FiniteType.of_finitePresentation⟩
obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.1 h
refine ⟨n, f, hf, ?_⟩
have hnoet : IsNoetherianRing (MvPolynomial (Fin n) R) := by infer_instance
-- Porting note: rewrote code to help typeclass inference
rw [isNoetherianRing_iff] at hnoet
letI : Module (MvPolynomial (Fin n) R) (MvPolynomial (Fin n) R) := Semiring.toModule
convert hnoet.noetherian (RingHom.ker f.toRingHom)
/-- If `e : A ≃ₐ[R] B` and `A` is finitely presented, then so is `B`. -/
theorem equiv [FinitePresentation R A] (e : A ≃ₐ[R] B) : FinitePresentation R B := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
use n, AlgHom.comp (↑e) f
constructor
· rw [AlgHom.coe_comp]
exact Function.Surjective.comp e.surjective hf.1
suffices (RingHom.ker (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom) = RingHom.ker f.toRingHom by
rw [this]
exact hf.2
have hco : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom = RingHom.comp (e.toRingEquiv : A ≃+* B)
f.toRingHom := by
have h : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom =
e.toAlgHom.toRingHom.comp f.toRingHom := rfl
have h1 : ↑e.toRingEquiv = e.toAlgHom.toRingHom := rfl
rw [h, h1]
rw [RingHom.ker_eq_comap_bot, hco, ← Ideal.comap_comap, ← RingHom.ker_eq_comap_bot,
RingHom.ker_coe_equiv (AlgEquiv.toRingEquiv e), RingHom.ker_eq_comap_bot]
variable (R)
/-- The ring of polynomials in finitely many variables is finitely presented. -/
protected instance mvPolynomial (ι : Type*) [Finite ι] :
FinitePresentation R (MvPolynomial ι R) where
out := by
cases nonempty_fintype ι
let eqv := (MvPolynomial.renameEquiv R <| Fintype.equivFin ι).symm
exact
⟨Fintype.card ι, eqv, eqv.surjective,
((RingHom.injective_iff_ker_eq_bot _).1 eqv.injective).symm ▸ Submodule.fg_bot⟩
/-- `R` is finitely presented as `R`-algebra. -/
instance self : FinitePresentation R R :=
-- Porting note: replaced `PEmpty` with `Empty`
equiv (MvPolynomial.isEmptyAlgEquiv R Empty)
/-- `R[X]` is finitely presented as `R`-algebra. -/
instance polynomial : FinitePresentation R R[X] :=
-- Porting note: replaced `PUnit` with `Unit`
letI := FinitePresentation.mvPolynomial R Unit
equiv (MvPolynomial.pUnitAlgEquiv R)
variable {R}
/-- The quotient of a finitely presented algebra by a finitely generated ideal is finitely
presented. -/
protected theorem quotient {I : Ideal A} (h : I.FG) [FinitePresentation R A] :
FinitePresentation R (A ⧸ I) where
out := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
refine ⟨n, (Ideal.Quotient.mkₐ R I).comp f, ?_, ?_⟩
· exact (Ideal.Quotient.mkₐ_surjective R I).comp hf.1
· refine Ideal.fg_ker_comp _ _ hf.2 ?_ hf.1
simp [h]
/-- If `f : A →ₐ[R] B` is surjective with finitely generated kernel and `A` is finitely presented,
then so is `B`. -/
theorem of_surjective {f : A →ₐ[R] B} (hf : Function.Surjective f)
(hker : (RingHom.ker f.toRingHom).FG)
[FinitePresentation R A] : FinitePresentation R B :=
letI : FinitePresentation R (A ⧸ RingHom.ker f) := FinitePresentation.quotient hker
equiv (Ideal.quotientKerAlgEquivOfSurjective hf)
theorem iff :
FinitePresentation R A ↔
∃ (n : _) (I : Ideal (MvPolynomial (Fin n) R)) (_ : (_ ⧸ I) ≃ₐ[R] A), I.FG := by
constructor
· rintro ⟨n, f, hf⟩
exact ⟨n, RingHom.ker f.toRingHom, Ideal.quotientKerAlgEquivOfSurjective hf.1, hf.2⟩
· rintro ⟨n, I, e, hfg⟩
letI := (FinitePresentation.mvPolynomial R _).quotient hfg
exact equiv e
|
/-- An algebra is finitely presented if and only if it is a quotient of a polynomial ring whose
variables are indexed by a fintype by a finitely generated ideal. -/
theorem iff_quotient_mvPolynomial' :
FinitePresentation R A ↔
∃ (ι : Type*) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] A),
Surjective f ∧ (RingHom.ker f.toRingHom).FG := by
constructor
· rintro ⟨n, f, hfs, hfk⟩
| Mathlib/RingTheory/FinitePresentation.lean | 148 | 156 |
/-
Copyright (c) 2018 Violeta Hernández Palacios, Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios, Mario Carneiro
-/
import Mathlib.Logic.Small.List
import Mathlib.SetTheory.Ordinal.Enum
import Mathlib.SetTheory.Ordinal.Exponential
/-!
# Fixed points of normal functions
We prove various statements about the fixed points of normal ordinal functions. We state them in
three forms: as statements about type-indexed families of normal functions, as statements about
ordinal-indexed families of normal functions, and as statements about a single normal function. For
the most part, the first case encompasses the others.
Moreover, we prove some lemmas about the fixed points of specific normal functions.
## Main definitions and results
* `nfpFamily`, `nfp`: the next fixed point of a (family of) normal function(s).
* `not_bddAbove_fp_family`, `not_bddAbove_fp`: the (common) fixed points of a (family of) normal
function(s) are unbounded in the ordinals.
* `deriv_add_eq_mul_omega0_add`: a characterization of the derivative of addition.
* `deriv_mul_eq_opow_omega0_mul`: a characterization of the derivative of multiplication.
-/
noncomputable section
universe u v
open Function Order
namespace Ordinal
/-! ### Fixed points of type-indexed families of ordinals -/
section
variable {ι : Type*} {f : ι → Ordinal.{u} → Ordinal.{u}}
/-- The next common fixed point, at least `a`, for a family of normal functions.
This is defined for any family of functions, as the supremum of all values reachable by applying
finitely many functions in the family to `a`.
`Ordinal.nfpFamily_fp` shows this is a fixed point, `Ordinal.le_nfpFamily` shows it's at
least `a`, and `Ordinal.nfpFamily_le_fp` shows this is the least ordinal with these properties. -/
def nfpFamily (f : ι → Ordinal.{u} → Ordinal.{u}) (a : Ordinal.{u}) : Ordinal :=
⨆ i, List.foldr f a i
theorem foldr_le_nfpFamily [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) (a l) :
List.foldr f a l ≤ nfpFamily f a :=
Ordinal.le_iSup _ _
theorem le_nfpFamily [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) (a) : a ≤ nfpFamily f a :=
foldr_le_nfpFamily f a []
theorem lt_nfpFamily_iff [Small.{u} ι] {a b} : a < nfpFamily f b ↔ ∃ l, a < List.foldr f b l :=
Ordinal.lt_iSup_iff
@[deprecated (since := "2025-02-16")]
alias lt_nfpFamily := lt_nfpFamily_iff
theorem nfpFamily_le_iff [Small.{u} ι] {a b} : nfpFamily f a ≤ b ↔ ∀ l, List.foldr f a l ≤ b :=
Ordinal.iSup_le_iff
theorem nfpFamily_le {a b} : (∀ l, List.foldr f a l ≤ b) → nfpFamily f a ≤ b :=
Ordinal.iSup_le
theorem nfpFamily_monotone [Small.{u} ι] (hf : ∀ i, Monotone (f i)) : Monotone (nfpFamily f) :=
fun _ _ h ↦ nfpFamily_le <| fun l ↦ (List.foldr_monotone hf l h).trans (foldr_le_nfpFamily _ _ l)
theorem apply_lt_nfpFamily [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a b}
(hb : b < nfpFamily f a) (i) : f i b < nfpFamily f a :=
let ⟨l, hl⟩ := lt_nfpFamily_iff.1 hb
lt_nfpFamily_iff.2 ⟨i::l, (H i).strictMono hl⟩
theorem apply_lt_nfpFamily_iff [Nonempty ι] [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∀ i, f i b < nfpFamily f a) ↔ b < nfpFamily f a := by
refine ⟨fun h ↦ ?_, apply_lt_nfpFamily H⟩
let ⟨l, hl⟩ := lt_nfpFamily_iff.1 (h (Classical.arbitrary ι))
exact lt_nfpFamily_iff.2 <| ⟨l, (H _).le_apply.trans_lt hl⟩
theorem nfpFamily_le_apply [Nonempty ι] [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∃ i, nfpFamily f a ≤ f i b) ↔ nfpFamily f a ≤ b := by
rw [← not_iff_not]
push_neg
exact apply_lt_nfpFamily_iff H
theorem nfpFamily_le_fp (H : ∀ i, Monotone (f i)) {a b} (ab : a ≤ b) (h : ∀ i, f i b ≤ b) :
nfpFamily f a ≤ b := by
apply Ordinal.iSup_le
intro l
induction' l with i l IH generalizing a
· exact ab
· exact (H i (IH ab)).trans (h i)
theorem nfpFamily_fp [Small.{u} ι] {i} (H : IsNormal (f i)) (a) :
f i (nfpFamily f a) = nfpFamily f a := by
rw [nfpFamily, H.map_iSup]
apply le_antisymm <;> refine Ordinal.iSup_le fun l => ?_
· exact Ordinal.le_iSup _ (i::l)
· exact H.le_apply.trans (Ordinal.le_iSup _ _)
theorem apply_le_nfpFamily [Small.{u} ι] [hι : Nonempty ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∀ i, f i b ≤ nfpFamily f a) ↔ b ≤ nfpFamily f a := by
refine ⟨fun h => ?_, fun h i => ?_⟩
· obtain ⟨i⟩ := hι
exact (H i).le_apply.trans (h i)
· rw [← nfpFamily_fp (H i)]
exact (H i).monotone h
theorem nfpFamily_eq_self [Small.{u} ι] {a} (h : ∀ i, f i a = a) : nfpFamily f a = a := by
apply (Ordinal.iSup_le ?_).antisymm (le_nfpFamily f a)
intro l
rw [List.foldr_fixed' h l]
-- Todo: This is actually a special case of the fact the intersection of club sets is a club set.
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
theorem not_bddAbove_fp_family [Small.{u} ι] (H : ∀ i, IsNormal (f i)) :
¬ BddAbove (⋂ i, Function.fixedPoints (f i)) := by
rw [not_bddAbove_iff]
refine fun a ↦ ⟨nfpFamily f (succ a), ?_, (lt_succ a).trans_le (le_nfpFamily f _)⟩
rintro _ ⟨i, rfl⟩
exact nfpFamily_fp (H i) _
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined for all functions such that `Ordinal.derivFamily_zero`,
`Ordinal.derivFamily_succ`, and `Ordinal.derivFamily_limit` are satisfied. -/
def derivFamily (f : ι → Ordinal.{u} → Ordinal.{u}) (o : Ordinal.{u}) : Ordinal.{u} :=
limitRecOn o (nfpFamily f 0) (fun _ IH => nfpFamily f (succ IH))
fun a _ g => ⨆ b : Set.Iio a, g _ b.2
@[simp]
theorem derivFamily_zero (f : ι → Ordinal → Ordinal) :
derivFamily f 0 = nfpFamily f 0 :=
limitRecOn_zero ..
@[simp]
theorem derivFamily_succ (f : ι → Ordinal → Ordinal) (o) :
derivFamily f (succ o) = nfpFamily f (succ (derivFamily f o)) :=
limitRecOn_succ ..
theorem derivFamily_limit (f : ι → Ordinal → Ordinal) {o} :
IsLimit o → derivFamily f o = ⨆ b : Set.Iio o, derivFamily f b :=
limitRecOn_limit _ _ _ _
theorem isNormal_derivFamily [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) :
IsNormal (derivFamily f) := by
refine ⟨fun o ↦ ?_, fun o h a ↦ ?_⟩
· rw [derivFamily_succ, ← succ_le_iff]
exact le_nfpFamily _ _
· simp_rw [derivFamily_limit _ h, Ordinal.iSup_le_iff, Subtype.forall, Set.mem_Iio]
theorem derivFamily_strictMono [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) :
StrictMono (derivFamily f) :=
(isNormal_derivFamily f).strictMono
theorem derivFamily_fp [Small.{u} ι] {i} (H : IsNormal (f i)) (o : Ordinal) :
f i (derivFamily f o) = derivFamily f o := by
induction' o using limitRecOn with o _ o l IH
· rw [derivFamily_zero]
exact nfpFamily_fp H 0
· rw [derivFamily_succ]
exact nfpFamily_fp H _
· have : Nonempty (Set.Iio o) := ⟨0, l.pos⟩
rw [derivFamily_limit _ l, H.map_iSup]
refine eq_of_forall_ge_iff fun c => ?_
rw [Ordinal.iSup_le_iff, Ordinal.iSup_le_iff]
refine forall_congr' fun a ↦ ?_
rw [IH _ a.2]
theorem le_iff_derivFamily [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a ≤ a) ↔ ∃ o, derivFamily f o = a :=
⟨fun ha => by
suffices ∀ (o), a ≤ derivFamily f o → ∃ o, derivFamily f o = a from
this a (isNormal_derivFamily _).le_apply
intro o
induction' o using limitRecOn with o IH o l IH
· intro h₁
refine ⟨0, le_antisymm ?_ h₁⟩
rw [derivFamily_zero]
exact nfpFamily_le_fp (fun i => (H i).monotone) (Ordinal.zero_le _) ha
· intro h₁
rcases le_or_lt a (derivFamily f o) with h | h
· exact IH h
refine ⟨succ o, le_antisymm ?_ h₁⟩
rw [derivFamily_succ]
exact nfpFamily_le_fp (fun i => (H i).monotone) (succ_le_of_lt h) ha
· intro h₁
rcases eq_or_lt_of_le h₁ with h | h
· exact ⟨_, h.symm⟩
rw [derivFamily_limit _ l, ← not_le, Ordinal.iSup_le_iff, not_forall] at h
obtain ⟨o', h⟩ := h
exact IH o' o'.2 (le_of_not_le h),
fun ⟨_, e⟩ i => e ▸ (derivFamily_fp (H i) _).le⟩
theorem fp_iff_derivFamily [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a = a) ↔ ∃ o, derivFamily f o = a :=
Iff.trans ⟨fun h i => le_of_eq (h i), fun h i => (H i).le_iff_eq.1 (h i)⟩ (le_iff_derivFamily H)
/-- For a family of normal functions, `Ordinal.derivFamily` enumerates the common fixed points. -/
theorem derivFamily_eq_enumOrd [Small.{u} ι] (H : ∀ i, IsNormal (f i)) :
derivFamily f = enumOrd (⋂ i, Function.fixedPoints (f i)) := by
rw [eq_comm, eq_enumOrd _ (not_bddAbove_fp_family H)]
use (isNormal_derivFamily f).strictMono
rw [Set.range_eq_iff]
refine ⟨?_, fun a ha => ?_⟩
· rintro a S ⟨i, hi⟩
rw [← hi]
exact derivFamily_fp (H i) a
rw [Set.mem_iInter] at ha
rwa [← fp_iff_derivFamily H]
end
/-! ### Fixed points of a single function -/
section
variable {f : Ordinal.{u} → Ordinal.{u}}
/-- The next fixed point function, the least fixed point of the normal function `f`, at least `a`.
This is defined as `nfpFamily` applied to a family consisting only of `f`. -/
def nfp (f : Ordinal → Ordinal) : Ordinal → Ordinal :=
nfpFamily fun _ : Unit => f
theorem nfp_eq_nfpFamily (f : Ordinal → Ordinal) : nfp f = nfpFamily fun _ : Unit => f :=
rfl
theorem iSup_iterate_eq_nfp (f : Ordinal.{u} → Ordinal.{u}) (a : Ordinal.{u}) :
⨆ n : ℕ, f^[n] a = nfp f a := by
apply le_antisymm
· rw [Ordinal.iSup_le_iff]
intro n
rw [← List.length_replicate (n := n) (a := Unit.unit), ← List.foldr_const f a]
exact Ordinal.le_iSup _ _
· apply Ordinal.iSup_le
intro l
rw [List.foldr_const f a l]
exact Ordinal.le_iSup _ _
theorem iterate_le_nfp (f a n) : f^[n] a ≤ nfp f a := by
rw [← iSup_iterate_eq_nfp]
exact Ordinal.le_iSup (fun n ↦ f^[n] a) n
theorem le_nfp (f a) : a ≤ nfp f a :=
iterate_le_nfp f a 0
theorem lt_nfp_iff {a b} : a < nfp f b ↔ ∃ n, a < f^[n] b := by
rw [← iSup_iterate_eq_nfp]
exact Ordinal.lt_iSup_iff
theorem nfp_le_iff {a b} : nfp f a ≤ b ↔ ∀ n, f^[n] a ≤ b := by
rw [← iSup_iterate_eq_nfp]
exact Ordinal.iSup_le_iff
theorem nfp_le {a b} : (∀ n, f^[n] a ≤ b) → nfp f a ≤ b :=
nfp_le_iff.2
@[simp]
theorem nfp_id : nfp id = id := by
ext
simp_rw [← iSup_iterate_eq_nfp, iterate_id]
exact ciSup_const
theorem nfp_monotone (hf : Monotone f) : Monotone (nfp f) :=
nfpFamily_monotone fun _ => hf
theorem IsNormal.apply_lt_nfp (H : IsNormal f) {a b} : f b < nfp f a ↔ b < nfp f a := by
unfold nfp
rw [← @apply_lt_nfpFamily_iff Unit (fun _ => f) _ _ (fun _ => H) a b]
exact ⟨fun h _ => h, fun h => h Unit.unit⟩
theorem IsNormal.nfp_le_apply (H : IsNormal f) {a b} : nfp f a ≤ f b ↔ nfp f a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.apply_lt_nfp
theorem nfp_le_fp (H : Monotone f) {a b} (ab : a ≤ b) (h : f b ≤ b) : nfp f a ≤ b :=
nfpFamily_le_fp (fun _ => H) ab fun _ => h
theorem IsNormal.nfp_fp (H : IsNormal f) : ∀ a, f (nfp f a) = nfp f a :=
@nfpFamily_fp Unit (fun _ => f) _ () H
theorem IsNormal.apply_le_nfp (H : IsNormal f) {a b} : f b ≤ nfp f a ↔ b ≤ nfp f a :=
⟨H.le_apply.trans, fun h => by simpa only [H.nfp_fp] using H.le_iff.2 h⟩
theorem nfp_eq_self {a} (h : f a = a) : nfp f a = a :=
nfpFamily_eq_self fun _ => h
/-- The fixed point lemma for normal functions: any normal function has an unbounded set of
fixed points. -/
theorem not_bddAbove_fp (H : IsNormal f) : ¬ BddAbove (Function.fixedPoints f) := by
convert not_bddAbove_fp_family fun _ : Unit => H
exact (Set.iInter_const _).symm
/-- The derivative of a normal function `f` is the sequence of fixed points of `f`.
This is defined as `Ordinal.derivFamily` applied to a trivial family consisting only of `f`. -/
def deriv (f : Ordinal → Ordinal) : Ordinal → Ordinal :=
derivFamily fun _ : Unit => f
theorem deriv_eq_derivFamily (f : Ordinal → Ordinal) : deriv f = derivFamily fun _ : Unit => f :=
rfl
@[simp]
theorem deriv_zero_right (f) : deriv f 0 = nfp f 0 :=
derivFamily_zero _
@[simp]
theorem deriv_succ (f o) : deriv f (succ o) = nfp f (succ (deriv f o)) :=
derivFamily_succ _ _
theorem deriv_limit (f) {o} : IsLimit o → deriv f o = ⨆ a : {a // a < o}, deriv f a :=
derivFamily_limit _
theorem isNormal_deriv (f) : IsNormal (deriv f) :=
isNormal_derivFamily _
theorem deriv_strictMono (f) : StrictMono (deriv f) :=
derivFamily_strictMono _
theorem deriv_id_of_nfp_id (h : nfp f = id) : deriv f = id :=
((isNormal_deriv _).eq_iff_zero_and_succ IsNormal.refl).2 (by simp [h])
theorem IsNormal.deriv_fp (H : IsNormal f) : ∀ o, f (deriv f o) = deriv f o :=
derivFamily_fp (i := ⟨⟩) H
theorem IsNormal.le_iff_deriv (H : IsNormal f) {a} : f a ≤ a ↔ ∃ o, deriv f o = a := by
unfold deriv
rw [← le_iff_derivFamily fun _ : Unit => H]
exact ⟨fun h _ => h, fun h => h Unit.unit⟩
theorem IsNormal.fp_iff_deriv (H : IsNormal f) {a} : f a = a ↔ ∃ o, deriv f o = a := by
rw [← H.le_iff_eq, H.le_iff_deriv]
/-- `Ordinal.deriv` enumerates the fixed points of a normal function. -/
theorem deriv_eq_enumOrd (H : IsNormal f) : deriv f = enumOrd (Function.fixedPoints f) := by
convert derivFamily_eq_enumOrd fun _ : Unit => H
exact (Set.iInter_const _).symm
theorem deriv_eq_id_of_nfp_eq_id (h : nfp f = id) : deriv f = id :=
(IsNormal.eq_iff_zero_and_succ (isNormal_deriv _) IsNormal.refl).2 <| by simp [h]
theorem nfp_zero_left (a) : nfp 0 a = a := by
rw [← iSup_iterate_eq_nfp]
apply (Ordinal.iSup_le ?_).antisymm (Ordinal.le_iSup _ 0)
intro n
cases n
· rfl
· rw [Function.iterate_succ']
simp
@[simp]
theorem nfp_zero : nfp 0 = id := by
ext
exact nfp_zero_left _
@[simp]
theorem deriv_zero : deriv 0 = id :=
deriv_eq_id_of_nfp_eq_id nfp_zero
theorem deriv_zero_left (a) : deriv 0 a = a := by
rw [deriv_zero, id_eq]
end
/-! ### Fixed points of addition -/
@[simp]
theorem nfp_add_zero (a) : nfp (a + ·) 0 = a * ω := by
simp_rw [← iSup_iterate_eq_nfp, ← iSup_mul_nat]
congr; funext n
induction' n with n hn
· rw [Nat.cast_zero, mul_zero, iterate_zero_apply]
· rw [iterate_succ_apply', Nat.add_comm, Nat.cast_add, Nat.cast_one, mul_one_add, hn]
theorem nfp_add_eq_mul_omega0 {a b} (hba : b ≤ a * ω) : nfp (a + ·) b = a * ω := by
apply le_antisymm (nfp_le_fp (isNormal_add_right a).monotone hba _)
· rw [← nfp_add_zero]
exact nfp_monotone (isNormal_add_right a).monotone (Ordinal.zero_le b)
· dsimp; rw [← mul_one_add, one_add_omega0]
theorem add_eq_right_iff_mul_omega0_le {a b : Ordinal} : a + b = b ↔ a * ω ≤ b := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [← nfp_add_zero a, ← deriv_zero_right]
obtain ⟨c, hc⟩ := (isNormal_add_right a).fp_iff_deriv.1 h
rw [← hc]
exact (isNormal_deriv _).monotone (Ordinal.zero_le _)
· have := Ordinal.add_sub_cancel_of_le h
nth_rw 1 [← this]
rwa [← add_assoc, ← mul_one_add, one_add_omega0]
theorem add_le_right_iff_mul_omega0_le {a b : Ordinal} : a + b ≤ b ↔ a * ω ≤ b := by
rw [← add_eq_right_iff_mul_omega0_le]
exact (isNormal_add_right a).le_iff_eq
theorem deriv_add_eq_mul_omega0_add (a b : Ordinal.{u}) : deriv (a + ·) b = a * ω + b := by
revert b
rw [← funext_iff, IsNormal.eq_iff_zero_and_succ (isNormal_deriv _) (isNormal_add_right _)]
refine ⟨?_, fun a h => ?_⟩
· rw [deriv_zero_right, add_zero]
exact nfp_add_zero a
· rw [deriv_succ, h, add_succ]
exact nfp_eq_self (add_eq_right_iff_mul_omega0_le.2 ((le_add_right _ _).trans (le_succ _)))
/-! ### Fixed points of multiplication -/
@[simp]
theorem nfp_mul_one {a : Ordinal} (ha : 0 < a) : nfp (a * ·) 1 = a ^ ω := by
rw [← iSup_iterate_eq_nfp, ← iSup_pow ha]
congr
funext n
induction' n with n hn
· rw [pow_zero, iterate_zero_apply]
· rw [iterate_succ_apply', Nat.add_comm, pow_add, pow_one, hn]
@[simp]
theorem nfp_mul_zero (a : Ordinal) : nfp (a * ·) 0 = 0 := by
rw [← Ordinal.le_zero, nfp_le_iff]
intro n
induction' n with n hn; · rfl
dsimp only; rwa [iterate_succ_apply, mul_zero]
theorem nfp_mul_eq_opow_omega0 {a b : Ordinal} (hb : 0 < b) (hba : b ≤ a ^ ω) :
nfp (a * ·) b = a ^ ω := by
rcases eq_zero_or_pos a with ha | ha
· rw [ha, zero_opow omega0_ne_zero] at hba ⊢
simp_rw [Ordinal.le_zero.1 hba, zero_mul]
| exact nfp_zero_left 0
apply le_antisymm
· apply nfp_le_fp (isNormal_mul_right ha).monotone hba
| Mathlib/SetTheory/Ordinal/FixedPoint.lean | 435 | 437 |
/-
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)
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
rw [← hf.right hl, Nat.div_mul_cancel hdl]
@[arith_mult]
theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[arith_mult]
theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[arith_mult]
theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by
refine ⟨by simp [hf.1, hg.1], ?_⟩
simp only [mul_apply]
intro m n cop
rw [sum_mul_sum, ← sum_product']
symm
apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l)
· rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h
simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne]
constructor
· ring
rw [Nat.mul_eq_zero] at *
apply not_or_intro ha hb
· simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk_inj]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h
simp only [Prod.mk_inj] at h
ext <;> dsimp only
· trans Nat.gcd (a1 * a2) (a1 * b1)
· rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.1, Nat.gcd_mul_left,
cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· trans Nat.gcd (a1 * a2) (a2 * b2)
· rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,
mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a1 * b1)
· rw [mul_comm, Nat.gcd_mul_right,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a2 * b2)
· rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one,
one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.2, Nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul]
· simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product,
Set.mem_image, exists_prop, Prod.mk_inj]
rintro ⟨b1, b2⟩ h
dsimp at h
use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n))
rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,
Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _]
· rw [Nat.mul_eq_zero, not_or] at h
simp [h.2.1, h.2.2]
rw [mul_comm n m, h.1]
· simp only [mem_divisorsAntidiagonal, Ne, mem_product]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
dsimp only
rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,
hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right]
ring
@[arith_mult]
theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop]
ring⟩
@[arith_mult]
theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f)
(hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop,
div_eq_mul_inv, mul_inv]
apply mul_mul_mul_comm ⟩
/-- For any multiplicative function `f` and any `n > 0`,
we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/
theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) :
f n = n.factorization.prod fun p k => f (p ^ k) :=
Nat.multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn
/-- A recapitulation of the definition of multiplicative that is simpler for proofs -/
theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} :
IsMultiplicative f ↔
f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by
refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩)
rcases eq_or_ne m 0 with (rfl | hm)
· simp
rcases eq_or_ne n 0 with (rfl | hn)
· simp
exact h hm hn hmn
/-- Two multiplicative functions `f` and `g` are equal if and only if
they agree on prime powers -/
theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) :
f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by
constructor
· intro h p i _
rw [h]
intro h
ext n
by_cases hn : n = 0
· rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero]
rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn]
exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp)
@[arith_mult]
theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) :
IsMultiplicative (prodPrimeFactors f) := by
rw [iff_ne_zero]
simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one,
prod_empty, true_and]
intro x y hx hy hxy
have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy
rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy,
Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors]
theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R}
(hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) :
∏ᵖ p ∣ n, (f + g) p = (f * g) n := by
rw [prodPrimeFactors_apply hn.ne_zero]
simp_rw [add_apply (f := f) (g := g)]
rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·),
← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero,
factors_eq]
apply Finset.sum_congr rfl
intro t ht
rw [t.prod_val, Function.id_def,
← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht),
hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht),
← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset]
theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} :
f (x.lcm y) * f (x.gcd y) = f x * f y := by
by_cases hx : x = 0
· simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left]
by_cases hy : y = 0
· simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul]
have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx
have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy
have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by
intro i; rw [Nat.pow_zero, hf.1]
iterate 4 rw [hf.multiplicative_factorization f (by assumption),
Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero)
(s := (x.primeFactors ∪ y.primeFactors))]
· rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro p _
rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;>
simp only [factorization_lcm hx hy, Finsupp.sup_apply, h, sup_of_le_right,
sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply,
inf_of_le_left, mul_comm]
· apply Finset.subset_union_right
· apply Finset.subset_union_left
· rw [factorization_gcd hx hy, Finsupp.support_inf]
apply Finset.inter_subset_union
· simp [factorization_lcm hx hy]
theorem map_gcd [CommGroupWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} (hf_lcm : f (x.lcm y) ≠ 0) :
f (x.gcd y) = f x * f y / f (x.lcm y) := by
rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_left₀ _ hf_lcm]
theorem map_lcm [CommGroupWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} (hf_gcd : f (x.gcd y) ≠ 0) :
f (x.lcm y) = f x * f y / f (x.gcd y) := by
rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_right₀ _ hf_gcd]
theorem eq_zero_of_squarefree_of_dvd_eq_zero [MonoidWithZero R] {f : ArithmeticFunction R}
(hf : IsMultiplicative f) {m n : ℕ} (hn : Squarefree n) (hmn : m ∣ n)
(h_zero : f m = 0) :
f n = 0 := by
rcases hmn with ⟨k, rfl⟩
simp only [MulZeroClass.zero_mul, eq_self_iff_true, hf.map_mul_of_coprime
(coprime_of_squarefree_mul hn), h_zero]
end IsMultiplicative
section SpecialFunctions
/-- The identity on `ℕ` as an `ArithmeticFunction`. -/
def id : ArithmeticFunction ℕ :=
⟨_root_.id, rfl⟩
@[simp]
theorem id_apply {x : ℕ} : id x = x :=
rfl
/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/
def pow (k : ℕ) : ArithmeticFunction ℕ :=
id.ppow k
@[simp]
theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by
cases k <;> simp [pow]
theorem pow_zero_eq_zeta : pow 0 = ζ := by
ext n
simp
/-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/
def sigma (k : ℕ) : ArithmeticFunction ℕ :=
⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma
@[inherit_doc]
scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma
theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k :=
rfl
theorem sigma_apply_prime_pow {k p i : ℕ} (hp : p.Prime) :
σ k (p ^ i) = ∑ j ∈ .range (i + 1), p ^ (j * k) := by
simp [sigma_apply, divisors_prime_pow hp, Nat.pow_mul]
theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply]
theorem sigma_one_apply_prime_pow {p i : ℕ} (hp : p.Prime) :
σ 1 (p ^ i) = ∑ k ∈ .range (i + 1), p ^ k := by
simp [sigma_apply_prime_pow hp]
theorem sigma_zero_apply (n : ℕ) : σ 0 n = #n.divisors := by simp [sigma_apply]
theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by
simp [sigma_apply_prime_pow hp]
theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by
ext
rw [sigma, zeta_mul_apply]
apply sum_congr rfl
intro x hx
rw [pow_apply, if_neg (not_and_of_not_right _ _)]
contrapose! hx
simp [hx]
@[arith_mult]
theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) :=
IsMultiplicative.iff_ne_zero.2
⟨by simp, by
intro m n hm _hn hmn
rcases eq_or_ne m 1 with (rfl | hm')
· simp
rw [one_apply_ne, one_apply_ne hm', zero_mul]
rw [Ne, mul_eq_one, not_and_or]
exact Or.inl hm'⟩
@[arith_mult]
theorem isMultiplicative_zeta : IsMultiplicative ζ :=
IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp +contextual⟩
@[arith_mult]
theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id :=
⟨rfl, fun {_ _} _ => rfl⟩
@[arith_mult]
theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative)
{k : ℕ} : IsMultiplicative (f.ppow k) := by
induction k with
| zero => exact isMultiplicative_zeta.natCast
| succ k hi => rw [ppow_succ']; apply hf.pmul hi
@[arith_mult]
theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) :=
isMultiplicative_id.ppow
@[arith_mult]
theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by
rw [← zeta_mul_pow_eq_sigma]
apply isMultiplicative_zeta.mul isMultiplicative_pow
/-- `Ω n` is the number of prime factors of `n`. -/
def cardFactors : ArithmeticFunction ℕ :=
⟨fun n => n.primeFactorsList.length, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors
@[inherit_doc]
scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors
theorem cardFactors_apply {n : ℕ} : Ω n = n.primeFactorsList.length :=
rfl
lemma cardFactors_zero : Ω 0 = 0 := by simp
@[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply]
@[simp]
theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by
refine ⟨fun h => ?_, fun h => List.length_eq_one_iff.2 ⟨n, primeFactorsList_prime h⟩⟩
cases n with | zero => simp at h | succ n =>
rcases List.length_eq_one_iff.1 h with ⟨x, hx⟩
rw [← prod_primeFactorsList n.add_one_ne_zero, hx, List.prod_singleton]
apply prime_of_mem_primeFactorsList
rw [hx, List.mem_singleton]
theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by
rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq,
UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq,
Multiset.card_add, Multiset.coe_card, Multiset.coe_card]
theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) :
Ω s.prod = (Multiset.map Ω s).sum := by
induction s using Multiset.induction_on with
| empty => simp
| cons ih => simp_all [cardFactors_mul, not_or]
@[simp]
theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 :=
cardFactors_eq_one_iff_prime.2 hp
@[simp]
theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by
rw [cardFactors_apply, hp.primeFactorsList_pow, List.length_replicate]
/-- `ω n` is the number of distinct prime factors of `n`. -/
def cardDistinctFactors : ArithmeticFunction ℕ :=
⟨fun n => n.primeFactorsList.dedup.length, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors
@[inherit_doc]
scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors
theorem cardDistinctFactors_zero : ω 0 = 0 := by simp
@[simp]
theorem cardDistinctFactors_one : ω 1 = 0 := by simp [cardDistinctFactors]
theorem cardDistinctFactors_apply {n : ℕ} : ω n = n.primeFactorsList.dedup.length :=
rfl
theorem cardDistinctFactors_eq_cardFactors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) :
ω n = Ω n ↔ Squarefree n := by
rw [squarefree_iff_nodup_primeFactorsList h0, cardDistinctFactors_apply]
constructor <;> intro h
· rw [← n.primeFactorsList.dedup_sublist.eq_of_length h]
apply List.nodup_dedup
· simp [h.dedup, cardFactors]
@[simp]
theorem cardDistinctFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
ω (p ^ k) = 1 := by
rw [cardDistinctFactors_apply, hp.primeFactorsList_pow, List.replicate_dedup hk,
List.length_singleton]
@[simp]
theorem cardDistinctFactors_apply_prime {p : ℕ} (hp : p.Prime) : ω p = 1 := by
rw [← pow_one p, cardDistinctFactors_apply_prime_pow hp one_ne_zero]
/-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors,
`μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`.
If `n` is not squarefree, `μ n = 0`. -/
def moebius : ArithmeticFunction ℤ :=
⟨fun n => if Squarefree n then (-1) ^ cardFactors n else 0, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "μ" => ArithmeticFunction.moebius
@[inherit_doc]
scoped[ArithmeticFunction.Moebius] notation "μ" => ArithmeticFunction.moebius
@[simp]
theorem moebius_apply_of_squarefree {n : ℕ} (h : Squarefree n) : μ n = (-1) ^ cardFactors n :=
if_pos h
@[simp]
theorem moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬Squarefree n) : μ n = 0 :=
if_neg h
theorem moebius_apply_one : μ 1 = 1 := by simp
theorem moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ Squarefree n := by
constructor <;> intro h
· contrapose! h
simp [h]
· simp [h, pow_ne_zero]
theorem moebius_eq_or (n : ℕ) : μ n = 0 ∨ μ n = 1 ∨ μ n = -1 := by
simp only [moebius, coe_mk]
split_ifs
· right
exact neg_one_pow_eq_or ..
· left
rfl
theorem moebius_ne_zero_iff_eq_or {n : ℕ} : μ n ≠ 0 ↔ μ n = 1 ∨ μ n = -1 := by
have := moebius_eq_or n
aesop
theorem moebius_sq_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : μ l ^ 2 = 1 := by
rw [moebius_apply_of_squarefree hl, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]
theorem abs_moebius_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : |μ l| = 1 := by
simp only [moebius_apply_of_squarefree hl, abs_pow, abs_neg, abs_one, one_pow]
theorem moebius_sq {n : ℕ} :
μ n ^ 2 = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact moebius_sq_eq_one_of_squarefree h
· simp only [pow_eq_zero_iff, moebius_eq_zero_of_not_squarefree h,
zero_pow (show 2 ≠ 0 by norm_num)]
theorem abs_moebius {n : ℕ} :
|μ n| = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact abs_moebius_eq_one_of_squarefree h
· simp only [moebius_eq_zero_of_not_squarefree h, abs_zero]
theorem abs_moebius_le_one {n : ℕ} : |μ n| ≤ 1 := by
rw [abs_moebius, apply_ite (· ≤ 1)]
simp
theorem moebius_apply_prime {p : ℕ} (hp : p.Prime) : μ p = -1 := by
rw [moebius_apply_of_squarefree hp.squarefree, cardFactors_apply_prime hp, pow_one]
theorem moebius_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
μ (p ^ k) = if k = 1 then -1 else 0 := by
split_ifs with h
· rw [h, pow_one, moebius_apply_prime hp]
rw [moebius_eq_zero_of_not_squarefree]
rw [squarefree_pow_iff hp.ne_one hk, not_and_or]
exact Or.inr h
theorem moebius_apply_isPrimePow_not_prime {n : ℕ} (hn : IsPrimePow n) (hn' : ¬n.Prime) :
μ n = 0 := by
obtain ⟨p, k, hp, hk, rfl⟩ := (isPrimePow_nat_iff _).1 hn
rw [moebius_apply_prime_pow hp hk.ne', if_neg]
rintro rfl
exact hn' (by simpa)
@[arith_mult]
theorem isMultiplicative_moebius : IsMultiplicative μ := by
rw [IsMultiplicative.iff_ne_zero]
refine ⟨by simp, fun {n m} hn hm hnm => ?_⟩
simp only [moebius, ZeroHom.coe_mk, coe_mk, ZeroHom.toFun_eq_coe, Eq.ndrec, ZeroHom.coe_mk,
IsUnit.mul_iff, Nat.isUnit_iff, squarefree_mul hnm, ite_zero_mul_ite_zero,
cardFactors_mul hn hm, pow_add]
theorem IsMultiplicative.prodPrimeFactors_one_add_of_squarefree [CommSemiring R]
{f : ArithmeticFunction R} (h_mult : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 + f p) = ∑ d ∈ n.divisors, f d := by
trans (∏ᵖ p ∣ n, ((ζ : ArithmeticFunction R) + f) p)
· simp_rw [prodPrimeFactors_apply hn.ne_zero, add_apply, natCoe_apply]
apply Finset.prod_congr rfl; intro p hp
rw [zeta_apply_ne (prime_of_mem_primeFactorsList <| List.mem_toFinset.mp hp).ne_zero, cast_one]
rw [isMultiplicative_zeta.natCast.prodPrimeFactors_add_of_squarefree h_mult hn,
coe_zeta_mul_apply]
theorem IsMultiplicative.prodPrimeFactors_one_sub_of_squarefree [CommRing R]
(f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 - f p) = ∑ d ∈ n.divisors, μ d * f d := by
trans (∏ p ∈ n.primeFactors, (1 + (ArithmeticFunction.pmul (μ : ArithmeticFunction R) f) p))
· apply Finset.prod_congr rfl; intro p hp
rw [pmul_apply, intCoe_apply, ArithmeticFunction.moebius_apply_prime
(prime_of_mem_primeFactorsList (List.mem_toFinset.mp hp))]
ring
· rw [(isMultiplicative_moebius.intCast.pmul hf).prodPrimeFactors_one_add_of_squarefree hn]
simp_rw [pmul_apply, intCoe_apply]
open UniqueFactorizationMonoid
@[simp]
theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by
ext n
refine recOnPosPrimePosCoprime ?_ ?_ ?_ ?_ n
· intro p n hp hn
rw [coe_mul_zeta_apply, sum_divisors_prime_pow hp, sum_range_succ']
simp_rw [Nat.pow_zero, moebius_apply_one,
moebius_apply_prime_pow hp (Nat.succ_ne_zero _), Nat.succ_inj, sum_ite_eq', mem_range,
if_pos hn, neg_add_cancel]
rw [one_apply_ne]
rw [Ne, pow_eq_one_iff]
· exact hp.ne_one
· exact hn.ne'
· rw [ZeroHom.map_zero, ZeroHom.map_zero]
· simp
· intro a b _ha _hb hab ha' hb'
rw [IsMultiplicative.map_mul_of_coprime _ hab, ha', hb',
IsMultiplicative.map_mul_of_coprime isMultiplicative_one hab]
exact isMultiplicative_moebius.mul isMultiplicative_zeta.natCast
@[simp]
theorem coe_zeta_mul_moebius : (ζ * μ : ArithmeticFunction ℤ) = 1 := by
rw [mul_comm, moebius_mul_coe_zeta]
@[simp]
theorem coe_moebius_mul_coe_zeta [Ring R] : (μ * ζ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, moebius_mul_coe_zeta, intCoe_one]
@[simp]
theorem coe_zeta_mul_coe_moebius [Ring R] : (ζ * μ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, coe_zeta_mul_moebius, intCoe_one]
section CommRing
variable [CommRing R]
instance : Invertible (ζ : ArithmeticFunction R) where
invOf := μ
invOf_mul_self := coe_moebius_mul_coe_zeta
mul_invOf_self := coe_zeta_mul_coe_moebius
/-- A unit in `ArithmeticFunction R` that evaluates to `ζ`, with inverse `μ`. -/
def zetaUnit : (ArithmeticFunction R)ˣ :=
⟨ζ, μ, coe_zeta_mul_coe_moebius, coe_moebius_mul_coe_zeta⟩
@[simp]
theorem coe_zetaUnit : ((zetaUnit : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = ζ :=
rfl
@[simp]
theorem inv_zetaUnit : ((zetaUnit⁻¹ : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = μ :=
rfl
end CommRing
/-- Möbius inversion for functions to an `AddCommGroup`. -/
theorem sum_eq_iff_sum_smul_moebius_eq [AddCommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd = f n := by
let f' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else f x, if_pos rfl⟩
let g' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else g x, if_pos rfl⟩
trans (ζ : ArithmeticFunction ℤ) • f' = g'
· rw [ArithmeticFunction.ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
rw [coe_zeta_smul_apply]
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', if_false, ZeroHom.coe_mk]
simp only [f', g', coe_mk, succ_ne_zero, ite_false]
rw [sum_congr rfl fun x hx => ?_]
rw [if_neg (Nat.pos_of_mem_divisors hx).ne']
trans μ • g' = f'
· constructor <;> intro h
· rw [← h, ← mul_smul, moebius_mul_coe_zeta, one_smul]
· rw [← h, ← mul_smul, coe_zeta_mul_moebius, one_smul]
· rw [ArithmeticFunction.ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
simp only [forall_prop_of_true, succ_pos', smul_apply, f', g', coe_mk, succ_ne_zero,
ite_false]
rw [sum_congr rfl fun x hx => ?_]
simp [if_neg (Nat.pos_of_mem_divisors (snd_mem_divisors_of_mem_antidiagonal hx)).ne']
/-- Möbius inversion for functions to a `Ring`. -/
theorem sum_eq_iff_sum_mul_moebius_eq [NonAssocRing R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd = f n := by
rw [sum_eq_iff_sum_smul_moebius_eq]
apply forall_congr'
refine fun a => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left
rw [zsmul_eq_mul]
/-- Möbius inversion for functions to a `CommGroup`. -/
theorem prod_eq_iff_prod_pow_moebius_eq [CommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n :=
@sum_eq_iff_sum_smul_moebius_eq (Additive R) _ _ _
/-- Möbius inversion for functions to a `CommGroupWithZero`. -/
theorem prod_eq_iff_prod_pow_moebius_eq_of_nonzero [CommGroupWithZero R] {f g : ℕ → R}
(hf : ∀ n : ℕ, 0 < n → f n ≠ 0) (hg : ∀ n : ℕ, 0 < n → g n ≠ 0) :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n := by
refine
Iff.trans
(Iff.trans (forall_congr' fun n => ?_)
(@prod_eq_iff_prod_pow_moebius_eq Rˣ _
(fun n => if h : 0 < n then Units.mk0 (f n) (hf n h) else 1) fun n =>
if h : 0 < n then Units.mk0 (g n) (hg n h) else 1))
(forall_congr' fun n => ?_) <;>
refine imp_congr_right fun hn => ?_
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors hx), Units.coeHom_apply, Units.val_mk0]
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal hx)),
Units.coeHom_apply, Units.val_zpow_eq_zpow_val, Units.val_mk0]
/-- Möbius inversion for functions to an `AddCommGroup`, where the equalities only hold on a
well-behaved set. -/
theorem sum_eq_iff_sum_smul_moebius_eq_on [AddCommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s → (∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd) = f n := by
constructor
· intro h
let G := fun (n : ℕ) => (∑ i ∈ n.divisors, f i)
intro n hn hnP
suffices ∑ d ∈ n.divisors, μ (n/d) • G d = f n by
rw [Nat.sum_divisorsAntidiagonal' (f := fun x y => μ x • g y), ← this, sum_congr rfl]
intro d hd
rw [← h d (Nat.pos_of_mem_divisors hd) <| hs d n (Nat.dvd_of_mem_divisors hd) hnP]
rw [← Nat.sum_divisorsAntidiagonal' (f := fun x y => μ x • G y)]
apply sum_eq_iff_sum_smul_moebius_eq.mp _ n hn
intro _ _; rfl
· intro h
let F := fun (n : ℕ) => ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd
intro n hn hnP
suffices ∑ d ∈ n.divisors, F d = g n by
rw [← this, sum_congr rfl]
intro d hd
rw [← h d (Nat.pos_of_mem_divisors hd) <| hs d n (Nat.dvd_of_mem_divisors hd) hnP]
apply sum_eq_iff_sum_smul_moebius_eq.mpr _ n hn
intro _ _; rfl
theorem sum_eq_iff_sum_smul_moebius_eq_on' [AddCommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) (hs₀ : 0 ∉ s) :
(∀ n ∈ s, (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n ∈ s, (∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd) = f n := by
have : ∀ P : ℕ → Prop, ((∀ n ∈ s, P n) ↔ (∀ n > 0, n ∈ s → P n)) := fun P ↦ by
refine forall_congr' (fun n ↦ ⟨fun h _ ↦ h, fun h hn ↦ h ?_ hn⟩)
contrapose! hs₀
simpa [nonpos_iff_eq_zero.mp hs₀] using hn
simpa only [this] using sum_eq_iff_sum_smul_moebius_eq_on s hs
/-- Möbius inversion for functions to a `Ring`, where the equalities only hold on a well-behaved
set. -/
theorem sum_eq_iff_sum_mul_moebius_eq_on [NonAssocRing R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s →
(∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd) = f n := by
rw [sum_eq_iff_sum_smul_moebius_eq_on s hs]
apply forall_congr'
intro a; refine imp_congr_right ?_
refine fun _ => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left
rw [zsmul_eq_mul]
/-- Möbius inversion for functions to a `CommGroup`, where the equalities only hold on a
well-behaved set. -/
theorem prod_eq_iff_prod_pow_moebius_eq_on [CommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∏ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s → (∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst) = f n :=
@sum_eq_iff_sum_smul_moebius_eq_on (Additive R) _ _ _ s hs
/-- Möbius inversion for functions to a `CommGroupWithZero`, where the equalities only hold on
a well-behaved set. -/
theorem prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero [CommGroupWithZero R]
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) {f g : ℕ → R}
(hf : ∀ n > 0, f n ≠ 0) (hg : ∀ n > 0, g n ≠ 0) :
(∀ n > 0, n ∈ s → (∏ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s → (∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst) = f n := by
refine
Iff.trans
(Iff.trans (forall_congr' fun n => ?_)
(@prod_eq_iff_prod_pow_moebius_eq_on Rˣ _
(fun n => if h : 0 < n then Units.mk0 (f n) (hf n h) else 1)
(fun n => if h : 0 < n then Units.mk0 (g n) (hg n h) else 1)
s hs) )
(forall_congr' fun n => ?_) <;>
refine imp_congr_right fun hn => ?_
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors hx), Units.coeHom_apply, Units.val_mk0]
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal hx)),
Units.coeHom_apply, Units.val_zpow_eq_zpow_val, Units.val_mk0]
end SpecialFunctions
theorem _root_.Nat.card_divisors {n : ℕ} (hn : n ≠ 0) :
#n.divisors = n.primeFactors.prod (n.factorization · + 1) := by
rw [← sigma_zero_apply, isMultiplicative_sigma.multiplicative_factorization _ hn]
exact Finset.prod_congr n.support_factorization fun _ h =>
sigma_zero_apply_prime_pow <| Nat.prime_of_mem_primeFactors h
theorem _root_.Nat.sum_divisors {n : ℕ} (hn : n ≠ 0) :
∑ d ∈ n.divisors, d = ∏ p ∈ n.primeFactors, ∑ k ∈ .range (n.factorization p + 1), p ^ k := by
rw [← sigma_one_apply, isMultiplicative_sigma.multiplicative_factorization _ hn]
exact Finset.prod_congr n.support_factorization fun _ h =>
sigma_one_apply_prime_pow <| Nat.prime_of_mem_primeFactors h
end ArithmeticFunction
namespace Nat.Coprime
open ArithmeticFunction
theorem card_divisors_mul {m n : ℕ} (hmn : m.Coprime n) :
#(m * n).divisors = #m.divisors * #n.divisors := by
simp only [← sigma_zero_apply, isMultiplicative_sigma.map_mul_of_coprime hmn]
theorem sum_divisors_mul {m n : ℕ} (hmn : m.Coprime n) :
∑ d ∈ (m * n).divisors, d = (∑ d ∈ m.divisors, d) * ∑ d ∈ n.divisors, d := by
simp only [← sigma_one_apply, isMultiplicative_sigma.map_mul_of_coprime hmn]
end Nat.Coprime
| Mathlib/NumberTheory/ArithmeticFunction.lean | 1,337 | 1,345 | |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.ContDiff.RCLike
import Mathlib.MeasureTheory.Measure.Hausdorff
/-!
# Hausdorff dimension
The Hausdorff dimension of a set `X` in an (extended) metric space is the unique number
`dimH s : ℝ≥0∞` such that for any `d : ℝ≥0` we have
- `μH[d] s = 0` if `dimH s < d`, and
- `μH[d] s = ∞` if `d < dimH s`.
In this file we define `dimH s` to be the Hausdorff dimension of `s`, then prove some basic
properties of Hausdorff dimension.
## Main definitions
* `MeasureTheory.dimH`: the Hausdorff dimension of a set. For the Hausdorff dimension of the whole
space we use `MeasureTheory.dimH (Set.univ : Set X)`.
## Main results
### Basic properties of Hausdorff dimension
* `hausdorffMeasure_of_lt_dimH`, `dimH_le_of_hausdorffMeasure_ne_top`,
`le_dimH_of_hausdorffMeasure_eq_top`, `hausdorffMeasure_of_dimH_lt`, `measure_zero_of_dimH_lt`,
`le_dimH_of_hausdorffMeasure_ne_zero`, `dimH_of_hausdorffMeasure_ne_zero_ne_top`: various forms
of the characteristic property of the Hausdorff dimension;
* `dimH_union`: the Hausdorff dimension of the union of two sets is the maximum of their Hausdorff
dimensions.
* `dimH_iUnion`, `dimH_bUnion`, `dimH_sUnion`: the Hausdorff dimension of a countable union of sets
is the supremum of their Hausdorff dimensions;
* `dimH_empty`, `dimH_singleton`, `Set.Subsingleton.dimH_zero`, `Set.Countable.dimH_zero` : `dimH s
= 0` whenever `s` is countable;
### (Pre)images under (anti)lipschitz and Hölder continuous maps
* `HolderWith.dimH_image_le` etc: if `f : X → Y` is Hölder continuous with exponent `r > 0`, then
for any `s`, `dimH (f '' s) ≤ dimH s / r`. We prove versions of this statement for `HolderWith`,
`HolderOnWith`, and locally Hölder maps, as well as for `Set.image` and `Set.range`.
* `LipschitzWith.dimH_image_le` etc: Lipschitz continuous maps do not increase the Hausdorff
dimension of sets.
* for a map that is known to be both Lipschitz and antilipschitz (e.g., for an `Isometry` or
a `ContinuousLinearEquiv`) we also prove `dimH (f '' s) = dimH s`.
### Hausdorff measure in `ℝⁿ`
* `Real.dimH_of_nonempty_interior`: if `s` is a set in a finite dimensional real vector space `E`
with nonempty interior, then the Hausdorff dimension of `s` is equal to the dimension of `E`.
* `dense_compl_of_dimH_lt_finrank`: if `s` is a set in a finite dimensional real vector space `E`
with Hausdorff dimension strictly less than the dimension of `E`, the `s` has a dense complement.
* `ContDiff.dense_compl_range_of_finrank_lt_finrank`: the complement to the range of a `C¹`
smooth map is dense provided that the dimension of the domain is strictly less than the dimension
of the codomain.
## Notations
We use the following notation localized in `MeasureTheory`. It is defined in
`MeasureTheory.Measure.Hausdorff`.
- `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d`
## Implementation notes
* The definition of `dimH` explicitly uses `borel X` as a measurable space structure. This way we
can formulate lemmas about Hausdorff dimension without assuming that the environment has a
`[MeasurableSpace X]` instance that is equal but possibly not defeq to `borel X`.
Lemma `dimH_def` unfolds this definition using whatever `[MeasurableSpace X]` instance we have in
the environment (as long as it is equal to `borel X`).
* The definition `dimH` is irreducible; use API lemmas or `dimH_def` instead.
## Tags
Hausdorff measure, Hausdorff dimension, dimension
-/
open scoped MeasureTheory ENNReal NNReal Topology
open MeasureTheory MeasureTheory.Measure Set TopologicalSpace Module Filter
variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y]
/-- Hausdorff dimension of a set in an (e)metric space. -/
@[irreducible] noncomputable def dimH (s : Set X) : ℝ≥0∞ := by
borelize X; exact ⨆ (d : ℝ≥0) (_ : @hausdorffMeasure X _ _ ⟨rfl⟩ d s = ∞), d
/-!
### Basic properties
-/
section Measurable
variable [MeasurableSpace X] [BorelSpace X]
/-- Unfold the definition of `dimH` using `[MeasurableSpace X] [BorelSpace X]` from the
environment. -/
theorem dimH_def (s : Set X) : dimH s = ⨆ (d : ℝ≥0) (_ : μH[d] s = ∞), (d : ℝ≥0∞) := by
borelize X; rw [dimH]
theorem hausdorffMeasure_of_lt_dimH {s : Set X} {d : ℝ≥0} (h : ↑d < dimH s) : μH[d] s = ∞ := by
simp only [dimH_def, lt_iSup_iff] at h
rcases h with ⟨d', hsd', hdd'⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hdd'
exact top_unique (hsd' ▸ hausdorffMeasure_mono hdd'.le _)
theorem dimH_le {s : Set X} {d : ℝ≥0∞} (H : ∀ d' : ℝ≥0, μH[d'] s = ∞ → ↑d' ≤ d) : dimH s ≤ d :=
(dimH_def s).trans_le <| iSup₂_le H
theorem dimH_le_of_hausdorffMeasure_ne_top {s : Set X} {d : ℝ≥0} (h : μH[d] s ≠ ∞) : dimH s ≤ d :=
le_of_not_lt <| mt hausdorffMeasure_of_lt_dimH h
theorem le_dimH_of_hausdorffMeasure_eq_top {s : Set X} {d : ℝ≥0} (h : μH[d] s = ∞) :
↑d ≤ dimH s := by
rw [dimH_def]; exact le_iSup₂ (α := ℝ≥0∞) d h
theorem hausdorffMeasure_of_dimH_lt {s : Set X} {d : ℝ≥0} (h : dimH s < d) : μH[d] s = 0 := by
rw [dimH_def] at h
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨d', hsd', hd'd⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hd'd
exact (hausdorffMeasure_zero_or_top hd'd s).resolve_right fun h₂ => hsd'.not_le <|
le_iSup₂ (α := ℝ≥0∞) d' h₂
theorem measure_zero_of_dimH_lt {μ : Measure X} {d : ℝ≥0} (h : μ ≪ μH[d]) {s : Set X}
(hd : dimH s < d) : μ s = 0 :=
h <| hausdorffMeasure_of_dimH_lt hd
theorem le_dimH_of_hausdorffMeasure_ne_zero {s : Set X} {d : ℝ≥0} (h : μH[d] s ≠ 0) : ↑d ≤ dimH s :=
le_of_not_lt <| mt hausdorffMeasure_of_dimH_lt h
theorem dimH_of_hausdorffMeasure_ne_zero_ne_top {d : ℝ≥0} {s : Set X} (h : μH[d] s ≠ 0)
(h' : μH[d] s ≠ ∞) : dimH s = d :=
le_antisymm (dimH_le_of_hausdorffMeasure_ne_top h') (le_dimH_of_hausdorffMeasure_ne_zero h)
end Measurable
@[mono]
theorem dimH_mono {s t : Set X} (h : s ⊆ t) : dimH s ≤ dimH t := by
borelize X
exact dimH_le fun d hd => le_dimH_of_hausdorffMeasure_eq_top <| top_unique <| hd ▸ measure_mono h
theorem dimH_subsingleton {s : Set X} (h : s.Subsingleton) : dimH s = 0 := by
borelize X
apply le_antisymm _ (zero_le _)
refine dimH_le_of_hausdorffMeasure_ne_top ?_
exact ((hausdorffMeasure_le_one_of_subsingleton h le_rfl).trans_lt ENNReal.one_lt_top).ne
alias Set.Subsingleton.dimH_zero := dimH_subsingleton
@[simp]
theorem dimH_empty : dimH (∅ : Set X) = 0 :=
subsingleton_empty.dimH_zero
@[simp]
theorem dimH_singleton (x : X) : dimH ({x} : Set X) = 0 :=
subsingleton_singleton.dimH_zero
@[simp]
theorem dimH_iUnion {ι : Sort*} [Countable ι] (s : ι → Set X) :
dimH (⋃ i, s i) = ⨆ i, dimH (s i) := by
borelize X
refine le_antisymm (dimH_le fun d hd => ?_) (iSup_le fun i => dimH_mono <| subset_iUnion _ _)
contrapose! hd
have : ∀ i, μH[d] (s i) = 0 := fun i =>
hausdorffMeasure_of_dimH_lt ((le_iSup (fun i => dimH (s i)) i).trans_lt hd)
rw [measure_iUnion_null this]
exact ENNReal.zero_ne_top
@[simp]
theorem dimH_bUnion {s : Set ι} (hs : s.Countable) (t : ι → Set X) :
dimH (⋃ i ∈ s, t i) = ⨆ i ∈ s, dimH (t i) := by
haveI := hs.toEncodable
rw [biUnion_eq_iUnion, dimH_iUnion, ← iSup_subtype'']
@[simp]
theorem dimH_sUnion {S : Set (Set X)} (hS : S.Countable) : dimH (⋃₀ S) = ⨆ s ∈ S, dimH s := by
rw [sUnion_eq_biUnion, dimH_bUnion hS]
@[simp]
theorem dimH_union (s t : Set X) : dimH (s ∪ t) = max (dimH s) (dimH t) := by
rw [union_eq_iUnion, dimH_iUnion, iSup_bool_eq, cond, cond]
theorem dimH_countable {s : Set X} (hs : s.Countable) : dimH s = 0 :=
biUnion_of_singleton s ▸ by simp only [dimH_bUnion hs, dimH_singleton, ENNReal.iSup_zero]
alias Set.Countable.dimH_zero := dimH_countable
theorem dimH_finite {s : Set X} (hs : s.Finite) : dimH s = 0 :=
hs.countable.dimH_zero
alias Set.Finite.dimH_zero := dimH_finite
@[simp]
theorem dimH_coe_finset (s : Finset X) : dimH (s : Set X) = 0 :=
s.finite_toSet.dimH_zero
alias Finset.dimH_zero := dimH_coe_finset
/-!
### Hausdorff dimension as the supremum of local Hausdorff dimensions
-/
section
variable [SecondCountableTopology X]
/-- If `r` is less than the Hausdorff dimension of a set `s` in an (extended) metric space with
second countable topology, then there exists a point `x ∈ s` such that every neighborhood
`t` of `x` within `s` has Hausdorff dimension greater than `r`. -/
theorem exists_mem_nhdsWithin_lt_dimH_of_lt_dimH {s : Set X} {r : ℝ≥0∞} (h : r < dimH s) :
∃ x ∈ s, ∀ t ∈ 𝓝[s] x, r < dimH t := by
contrapose! h; choose! t htx htr using h
rcases countable_cover_nhdsWithin htx with ⟨S, hSs, hSc, hSU⟩
calc
dimH s ≤ dimH (⋃ x ∈ S, t x) := dimH_mono hSU
_ = ⨆ x ∈ S, dimH (t x) := dimH_bUnion hSc _
_ ≤ r := iSup₂_le fun x hx => htr x <| hSs hx
/-- In an (extended) metric space with second countable topology, the Hausdorff dimension
of a set `s` is the supremum over `x ∈ s` of the limit superiors of `dimH t` along
`(𝓝[s] x).smallSets`. -/
theorem bsupr_limsup_dimH (s : Set X) : ⨆ x ∈ s, limsup dimH (𝓝[s] x).smallSets = dimH s := by
refine le_antisymm (iSup₂_le fun x _ => ?_) ?_
· refine limsup_le_of_le isCobounded_le_of_bot ?_
exact eventually_smallSets.2 ⟨s, self_mem_nhdsWithin, fun t => dimH_mono⟩
· refine le_of_forall_lt_imp_le_of_dense fun r hr => ?_
rcases exists_mem_nhdsWithin_lt_dimH_of_lt_dimH hr with ⟨x, hxs, hxr⟩
refine le_iSup₂_of_le x hxs ?_; rw [limsup_eq]; refine le_sInf fun b hb => ?_
rcases eventually_smallSets.1 hb with ⟨t, htx, ht⟩
exact (hxr t htx).le.trans (ht t Subset.rfl)
/-- In an (extended) metric space with second countable topology, the Hausdorff dimension
of a set `s` is the supremum over all `x` of the limit superiors of `dimH t` along
`(𝓝[s] x).smallSets`. -/
theorem iSup_limsup_dimH (s : Set X) : ⨆ x, limsup dimH (𝓝[s] x).smallSets = dimH s := by
refine le_antisymm (iSup_le fun x => ?_) ?_
· refine limsup_le_of_le isCobounded_le_of_bot ?_
exact eventually_smallSets.2 ⟨s, self_mem_nhdsWithin, fun t => dimH_mono⟩
· rw [← bsupr_limsup_dimH]; exact iSup₂_le_iSup _ _
end
/-!
### Hausdorff dimension and Hölder continuity
-/
variable {C K r : ℝ≥0} {f : X → Y} {s : Set X}
/-- If `f` is a Hölder continuous map with exponent `r > 0`, then `dimH (f '' s) ≤ dimH s / r`. -/
theorem HolderOnWith.dimH_image_le (h : HolderOnWith C r f s) (hr : 0 < r) :
dimH (f '' s) ≤ dimH s / r := by
borelize X Y
refine dimH_le fun d hd => ?_
have := h.hausdorffMeasure_image_le hr d.coe_nonneg
rw [hd, ← ENNReal.coe_rpow_of_nonneg _ d.coe_nonneg, top_le_iff] at this
have Hrd : μH[(r * d : ℝ≥0)] s = ⊤ := by
contrapose this
exact ENNReal.mul_ne_top ENNReal.coe_ne_top this
rw [ENNReal.le_div_iff_mul_le, mul_comm, ← ENNReal.coe_mul]
exacts [le_dimH_of_hausdorffMeasure_eq_top Hrd, Or.inl (mt ENNReal.coe_eq_zero.1 hr.ne'),
Or.inl ENNReal.coe_ne_top]
namespace HolderWith
/-- If `f : X → Y` is Hölder continuous with a positive exponent `r`, then the Hausdorff dimension
of the image of a set `s` is at most `dimH s / r`. -/
theorem dimH_image_le (h : HolderWith C r f) (hr : 0 < r) (s : Set X) :
dimH (f '' s) ≤ dimH s / r :=
(h.holderOnWith s).dimH_image_le hr
/-- If `f` is a Hölder continuous map with exponent `r > 0`, then the Hausdorff dimension of its
range is at most the Hausdorff dimension of its domain divided by `r`. -/
theorem dimH_range_le (h : HolderWith C r f) (hr : 0 < r) :
dimH (range f) ≤ dimH (univ : Set X) / r :=
@image_univ _ _ f ▸ h.dimH_image_le hr univ
end HolderWith
/-- If `s` is a set in a space `X` with second countable topology and `f : X → Y` is Hölder
continuous in a neighborhood within `s` of every point `x ∈ s` with the same positive exponent `r`
but possibly different coefficients, then the Hausdorff dimension of the image `f '' s` is at most
the Hausdorff dimension of `s` divided by `r`. -/
theorem dimH_image_le_of_locally_holder_on [SecondCountableTopology X] {r : ℝ≥0} {f : X → Y}
(hr : 0 < r) {s : Set X} (hf : ∀ x ∈ s, ∃ C : ℝ≥0, ∃ t ∈ 𝓝[s] x, HolderOnWith C r f t) :
dimH (f '' s) ≤ dimH s / r := by
choose! C t htn hC using hf
rcases countable_cover_nhdsWithin htn with ⟨u, hus, huc, huU⟩
replace huU := inter_eq_self_of_subset_left huU; rw [inter_iUnion₂] at huU
rw [← huU, image_iUnion₂, dimH_bUnion huc, dimH_bUnion huc]; simp only [ENNReal.iSup_div]
| exact iSup₂_mono fun x hx => ((hC x (hus hx)).mono inter_subset_right).dimH_image_le hr
/-- If `f : X → Y` is Hölder continuous in a neighborhood of every point `x : X` with the same
positive exponent `r` but possibly different coefficients, then the Hausdorff dimension of the range
of `f` is at most the Hausdorff dimension of `X` divided by `r`. -/
| Mathlib/Topology/MetricSpace/HausdorffDimension.lean | 300 | 304 |
/-
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, Wen Yang
-/
import Mathlib.LinearAlgebra.Matrix.Transvection
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.Tactic.FinCases
/-!
# Block matrices and their determinant
This file defines a predicate `Matrix.BlockTriangular` saying a matrix
is block triangular, and proves the value of the determinant for various
matrices built out of blocks.
## Main definitions
* `Matrix.BlockTriangular` expresses that an `o` by `o` matrix is block triangular,
if the rows and columns are ordered according to some order `b : o → α`
## Main results
* `Matrix.det_of_blockTriangular`: the determinant of a block triangular matrix
is equal to the product of the determinants of all the blocks
* `Matrix.det_of_upperTriangular` and `Matrix.det_of_lowerTriangular`: the determinant of
a triangular matrix is the product of the entries along the diagonal
## Tags
matrix, diagonal, det, block triangular
-/
open Finset Function OrderDual
open Matrix
universe v
variable {α β m n o : Type*} {m' n' : α → Type*}
variable {R : Type v} {M N : Matrix m m R} {b : m → α}
namespace Matrix
section LT
variable [LT α]
section Zero
variable [Zero R]
/-- Let `b` map rows and columns of a square matrix `M` to blocks indexed by `α`s. Then
`BlockTriangular M n b` says the matrix is block triangular. -/
def BlockTriangular (M : Matrix m m R) (b : m → α) : Prop :=
∀ ⦃i j⦄, b j < b i → M i j = 0
@[simp]
protected theorem BlockTriangular.submatrix {f : n → m} (h : M.BlockTriangular b) :
(M.submatrix f f).BlockTriangular (b ∘ f) := fun _ _ hij => h hij
theorem blockTriangular_reindex_iff {b : n → α} {e : m ≃ n} :
(reindex e e M).BlockTriangular b ↔ M.BlockTriangular (b ∘ e) := by
refine ⟨fun h => ?_, fun h => ?_⟩
· convert h.submatrix
simp only [reindex_apply, submatrix_submatrix, submatrix_id_id, Equiv.symm_comp_self]
· convert h.submatrix
simp only [comp_assoc b e e.symm, Equiv.self_comp_symm, comp_id]
protected theorem BlockTriangular.transpose :
M.BlockTriangular b → Mᵀ.BlockTriangular (toDual ∘ b) :=
swap
@[simp]
protected theorem blockTriangular_transpose_iff {b : m → αᵒᵈ} :
Mᵀ.BlockTriangular b ↔ M.BlockTriangular (ofDual ∘ b) :=
forall_swap
@[simp]
theorem blockTriangular_zero : BlockTriangular (0 : Matrix m m R) b := fun _ _ _ => rfl
end Zero
protected theorem BlockTriangular.neg [NegZeroClass R] {M : Matrix m m R}
(hM : BlockTriangular M b) : BlockTriangular (-M) b :=
fun _ _ h => by rw [neg_apply, hM h, neg_zero]
theorem BlockTriangular.add [AddZeroClass R] (hM : BlockTriangular M b) (hN : BlockTriangular N b) :
BlockTriangular (M + N) b := fun i j h => by simp_rw [Matrix.add_apply, hM h, hN h, zero_add]
theorem BlockTriangular.sub [SubNegZeroMonoid R]
(hM : BlockTriangular M b) (hN : BlockTriangular N b) :
BlockTriangular (M - N) b := fun i j h => by simp_rw [Matrix.sub_apply, hM h, hN h, sub_zero]
lemma BlockTriangular.add_iff_right [AddGroup R] (hM : BlockTriangular M b) :
BlockTriangular (M + N) b ↔ BlockTriangular N b := ⟨(by simpa using hM.neg.add ·), hM.add⟩
lemma BlockTriangular.add_iff_left [AddGroup R] (hN : BlockTriangular N b) :
BlockTriangular (M + N) b ↔ BlockTriangular M b := ⟨(by simpa using ·.sub hN), (·.add hN)⟩
lemma BlockTriangular.sub_iff_right [AddGroup R] (hM : BlockTriangular M b) :
BlockTriangular (M - N) b ↔ BlockTriangular N b := ⟨(by simpa using ·.neg.add hM), hM.sub⟩
lemma BlockTriangular.sub_iff_left [AddGroup R] (hN : BlockTriangular N b) :
BlockTriangular (M - N) b ↔ BlockTriangular M b := ⟨(by simpa using ·.add hN), (·.sub hN)⟩
lemma BlockTriangular.map {S F} [FunLike F R S] [Zero R] [Zero S] [ZeroHomClass F R S] (f : F)
(h : BlockTriangular M b) : BlockTriangular (M.map f) b :=
fun i j lt ↦ by simp [h lt]
lemma BlockTriangular.comp [Zero R] {M : Matrix m m (Matrix n n R)} (h : BlockTriangular M b) :
BlockTriangular (M.comp m m n n R) fun i ↦ b i.1 :=
fun i j lt ↦ by simp [h lt]
end LT
section Preorder
variable [Preorder α]
section Zero
variable [Zero R]
theorem blockTriangular_diagonal [DecidableEq m] (d : m → R) : BlockTriangular (diagonal d) b :=
fun _ _ h => diagonal_apply_ne' d fun h' => ne_of_lt h (congr_arg _ h')
theorem blockTriangular_blockDiagonal' [DecidableEq α] (d : ∀ i : α, Matrix (m' i) (m' i) R) :
BlockTriangular (blockDiagonal' d) Sigma.fst := by
rintro ⟨i, i'⟩ ⟨j, j'⟩ h
apply blockDiagonal'_apply_ne d i' j' fun h' => ne_of_lt h h'.symm
theorem blockTriangular_blockDiagonal [DecidableEq α] (d : α → Matrix m m R) :
BlockTriangular (blockDiagonal d) Prod.snd := by
rintro ⟨i, i'⟩ ⟨j, j'⟩ h
rw [blockDiagonal'_eq_blockDiagonal, blockTriangular_blockDiagonal']
exact h
variable [DecidableEq m]
theorem blockTriangular_one [One R] : BlockTriangular (1 : Matrix m m R) b :=
blockTriangular_diagonal _
theorem blockTriangular_stdBasisMatrix {i j : m} (hij : b i ≤ b j) (c : R) :
BlockTriangular (stdBasisMatrix i j c) b := by
intro r s hrs
apply StdBasisMatrix.apply_of_ne
rintro ⟨rfl, rfl⟩
exact (hij.trans_lt hrs).false
theorem blockTriangular_stdBasisMatrix' {i j : m} (hij : b j ≤ b i) (c : R) :
BlockTriangular (stdBasisMatrix i j c) (toDual ∘ b) :=
blockTriangular_stdBasisMatrix (by exact toDual_le_toDual.mpr hij) _
end Zero
variable [CommRing R] [DecidableEq m]
theorem blockTriangular_transvection {i j : m} (hij : b i ≤ b j) (c : R) :
BlockTriangular (transvection i j c) b :=
blockTriangular_one.add (blockTriangular_stdBasisMatrix hij c)
theorem blockTriangular_transvection' {i j : m} (hij : b j ≤ b i) (c : R) :
BlockTriangular (transvection i j c) (OrderDual.toDual ∘ b) :=
blockTriangular_one.add (blockTriangular_stdBasisMatrix' hij c)
end Preorder
section LinearOrder
variable [LinearOrder α]
theorem BlockTriangular.mul [Fintype m] [NonUnitalNonAssocSemiring R]
{M N : Matrix m m R} (hM : BlockTriangular M b)
(hN : BlockTriangular N b) : BlockTriangular (M * N) b := by
intro i j hij
apply Finset.sum_eq_zero
intro k _
by_cases hki : b k < b i
· simp_rw [hM hki, zero_mul]
· simp_rw [hN (lt_of_lt_of_le hij (le_of_not_lt hki)), mul_zero]
end LinearOrder
theorem upper_two_blockTriangular [Zero R] [Preorder α] (A : Matrix m m R) (B : Matrix m n R)
(D : Matrix n n R) {a b : α} (hab : a < b) :
BlockTriangular (fromBlocks A B 0 D) (Sum.elim (fun _ => a) fun _ => b) := by
rintro (c | c) (d | d) hcd <;> first | simp [hab.not_lt] at hcd ⊢
/-! ### Determinant -/
variable [CommRing R] [DecidableEq m] [Fintype m] [DecidableEq n] [Fintype n]
theorem equiv_block_det (M : Matrix m m R) {p q : m → Prop} [DecidablePred p] [DecidablePred q]
(e : ∀ x, q x ↔ p x) : (toSquareBlockProp M p).det = (toSquareBlockProp M q).det := by
convert Matrix.det_reindex_self (Equiv.subtypeEquivRight e) (toSquareBlockProp M q)
-- Removed `@[simp]` attribute,
-- as the LHS simplifies already to `M.toSquareBlock id i ⟨i, ⋯⟩ ⟨i, ⋯⟩`
theorem det_toSquareBlock_id (M : Matrix m m R) (i : m) : (M.toSquareBlock id i).det = M i i :=
letI : Unique { a // id a = i } := ⟨⟨⟨i, rfl⟩⟩, fun j => Subtype.ext j.property⟩
(det_unique _).trans rfl
theorem det_toBlock (M : Matrix m m R) (p : m → Prop) [DecidablePred p] :
M.det =
(fromBlocks (toBlock M p p) (toBlock M p fun j => ¬p j) (toBlock M (fun j => ¬p j) p) <|
toBlock M (fun j => ¬p j) fun j => ¬p j).det := by
rw [← Matrix.det_reindex_self (Equiv.sumCompl p).symm M]
rw [det_apply', det_apply']
congr; ext σ; congr; ext x
generalize hy : σ x = y
cases x <;> cases y <;>
simp only [Matrix.reindex_apply, toBlock_apply, Equiv.symm_symm, Equiv.sumCompl_apply_inr,
Equiv.sumCompl_apply_inl, fromBlocks_apply₁₁, fromBlocks_apply₁₂, fromBlocks_apply₂₁,
fromBlocks_apply₂₂, Matrix.submatrix_apply]
theorem twoBlockTriangular_det (M : Matrix m m R) (p : m → Prop) [DecidablePred p]
(h : ∀ i, ¬p i → ∀ j, p j → M i j = 0) :
M.det = (toSquareBlockProp M p).det * (toSquareBlockProp M fun i => ¬p i).det := by
rw [det_toBlock M p]
convert det_fromBlocks_zero₂₁ (toBlock M p p) (toBlock M p fun j => ¬p j)
(toBlock M (fun j => ¬p j) fun j => ¬p j)
ext i j
exact h (↑i) i.2 (↑j) j.2
theorem twoBlockTriangular_det' (M : Matrix m m R) (p : m → Prop) [DecidablePred p]
(h : ∀ i, p i → ∀ j, ¬p j → M i j = 0) :
M.det = (toSquareBlockProp M p).det * (toSquareBlockProp M fun i => ¬p i).det := by
rw [M.twoBlockTriangular_det fun i => ¬p i, mul_comm]
· congr 1
exact equiv_block_det _ fun _ => not_not.symm
· simpa only [Classical.not_not] using h
protected theorem BlockTriangular.det [DecidableEq α] [LinearOrder α] (hM : BlockTriangular M b) :
M.det = ∏ a ∈ univ.image b, (M.toSquareBlock b a).det := by
suffices ∀ hs : Finset α, univ.image b = hs → M.det = ∏ a ∈ hs, (M.toSquareBlock b a).det by
exact this _ rfl
intro s hs
induction s using Finset.strongInduction generalizing m with | H s ih =>
subst hs
cases isEmpty_or_nonempty m
· simp
let k := (univ.image b).max' (univ_nonempty.image _)
rw [twoBlockTriangular_det' M fun i => b i = k]
· have : univ.image b = insert k ((univ.image b).erase k) := by
rw [insert_erase]
apply max'_mem
rw [this, prod_insert (not_mem_erase _ _)]
refine congr_arg _ ?_
let b' := fun i : { a // b a ≠ k } => b ↑i
have h' : BlockTriangular (M.toSquareBlockProp fun i => b i ≠ k) b' := hM.submatrix
have hb' : image b' univ = (image b univ).erase k := by
convert image_subtype_ne_univ_eq_image_erase k b
rw [ih _ (erase_ssubset <| max'_mem _ _) h' hb']
refine Finset.prod_congr rfl fun l hl => ?_
let he : { a // b' a = l } ≃ { a // b a = l } :=
haveI hc : ∀ i, b i = l → b i ≠ k := fun i hi => ne_of_eq_of_ne hi (ne_of_mem_erase hl)
Equiv.subtypeSubtypeEquivSubtype @(hc)
simp only [toSquareBlock_def]
erw [← Matrix.det_reindex_self he.symm fun i j : { a // b a = l } => M ↑i ↑j]
rfl
· intro i hi j hj
apply hM
rw [hi]
apply lt_of_le_of_ne _ hj
exact Finset.le_max' (univ.image b) _ (mem_image_of_mem _ (mem_univ _))
theorem BlockTriangular.det_fintype [DecidableEq α] [Fintype α] [LinearOrder α]
(h : BlockTriangular M b) : M.det = ∏ k : α, (M.toSquareBlock b k).det := by
refine h.det.trans (prod_subset (subset_univ _) fun a _ ha => ?_)
have : IsEmpty { i // b i = a } := ⟨fun i => ha <| mem_image.2 ⟨i, mem_univ _, i.2⟩⟩
exact det_isEmpty
theorem det_of_upperTriangular [LinearOrder m] (h : M.BlockTriangular id) :
M.det = ∏ i : m, M i i := by
haveI : DecidableEq R := Classical.decEq _
simp_rw [h.det, image_id, det_toSquareBlock_id]
theorem det_of_lowerTriangular [LinearOrder m] (M : Matrix m m R) (h : M.BlockTriangular toDual) :
M.det = ∏ i : m, M i i := by
rw [← det_transpose]
exact det_of_upperTriangular h.transpose
open Polynomial
theorem matrixOfPolynomials_blockTriangular {R} [Semiring R] {n : ℕ} (p : Fin n → R[X])
(h_deg : ∀ i, (p i).natDegree ≤ i) :
Matrix.BlockTriangular (Matrix.of (fun (i j : Fin n) => (p j).coeff i)) id :=
fun _ j h => by
exact coeff_eq_zero_of_natDegree_lt <| Nat.lt_of_le_of_lt (h_deg j) h
theorem det_matrixOfPolynomials {n : ℕ} (p : Fin n → R[X])
(h_deg : ∀ i, (p i).natDegree = i) (h_monic : ∀ i, Monic <| p i) :
(Matrix.of (fun (i j : Fin n) => (p j).coeff i)).det = 1 := by
rw [Matrix.det_of_upperTriangular (Matrix.matrixOfPolynomials_blockTriangular p (fun i ↦
Nat.le_of_eq (h_deg i)))]
convert prod_const_one with x _
rw [Matrix.of_apply, ← h_deg, coeff_natDegree, (h_monic x).leadingCoeff]
/-! ### Invertible -/
theorem BlockTriangular.toBlock_inverse_mul_toBlock_eq_one [LinearOrder α] [Invertible M]
(hM : BlockTriangular M b) (k : α) :
((M⁻¹.toBlock (fun i => b i < k) fun i => b i < k) *
M.toBlock (fun i => b i < k) fun i => b i < k) =
1 := by
let p i := b i < k
have h_sum :
M⁻¹.toBlock p p * M.toBlock p p +
(M⁻¹.toBlock p fun i => ¬p i) * M.toBlock (fun i => ¬p i) p =
1 := by
rw [← toBlock_mul_eq_add, inv_mul_of_invertible M, toBlock_one_self]
have h_zero : M.toBlock (fun i => ¬p i) p = 0 := by
ext i j
simpa using hM (lt_of_lt_of_le j.2 (le_of_not_lt i.2))
simpa [h_zero] using h_sum
/-- The inverse of an upper-left subblock of a block-triangular matrix `M` is the upper-left
subblock of `M⁻¹`. -/
theorem BlockTriangular.inv_toBlock [LinearOrder α] [Invertible M] (hM : BlockTriangular M b)
(k : α) :
(M.toBlock (fun i => b i < k) fun i => b i < k)⁻¹ =
| M⁻¹.toBlock (fun i => b i < k) fun i => b i < k :=
inv_eq_left_inv <| hM.toBlock_inverse_mul_toBlock_eq_one k
/-- An upper-left subblock of an invertible block-triangular matrix is invertible. -/
def BlockTriangular.invertibleToBlock [LinearOrder α] [Invertible M] (hM : BlockTriangular M b)
(k : α) : Invertible (M.toBlock (fun i => b i < k) fun i => b i < k) :=
invertibleOfLeftInverse _ ((⅟ M).toBlock (fun i => b i < k) fun i => b i < k) <| by
simpa only [invOf_eq_nonsing_inv] using hM.toBlock_inverse_mul_toBlock_eq_one k
/-- A lower-left subblock of the inverse of a block-triangular matrix is zero. This is a first step
towards `BlockTriangular.inv_toBlock` below. -/
theorem toBlock_inverse_eq_zero [LinearOrder α] [Invertible M] (hM : BlockTriangular M b) (k : α) :
(M⁻¹.toBlock (fun i => k ≤ b i) fun i => b i < k) = 0 := by
let p i := b i < k
let q i := ¬b i < k
have h_sum : M⁻¹.toBlock q p * M.toBlock p p + M⁻¹.toBlock q q * M.toBlock q p = 0 := by
rw [← toBlock_mul_eq_add, inv_mul_of_invertible M, toBlock_one_disjoint]
rw [disjoint_iff_inf_le]
| Mathlib/LinearAlgebra/Matrix/Block.lean | 326 | 343 |
/-
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₁)]
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₁)]
section NoMaxOrder
variable [NoMaxOrder α]
@[simp]
theorem lt_succ_iff : a < succ b ↔ a ≤ b :=
lt_succ_iff_of_not_isMax <| not_isMax b
theorem succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp
theorem succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp
alias ⟨le_of_succ_le_succ, _⟩ := succ_le_succ_iff
alias ⟨lt_of_succ_lt_succ, _⟩ := succ_lt_succ_iff
-- TODO: prove for a succ-archimedean non-linear order with bottom
@[simp]
theorem Iio_succ (a : α) : Iio (succ a) = Iic a :=
Iio_succ_of_not_isMax <| not_isMax _
@[simp]
theorem Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b :=
Ico_succ_right_of_not_isMax <| not_isMax _
-- TODO: prove for a succ-archimedean non-linear order
@[simp]
theorem Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b :=
Ioo_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem succ_eq_succ_iff : succ a = succ b ↔ a = b :=
succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b)
theorem succ_injective : Injective (succ : α → α) := fun _ _ => succ_eq_succ_iff.1
theorem succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b :=
succ_injective.ne_iff
alias ⟨_, succ_ne_succ⟩ := succ_ne_succ_iff
theorem lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b :=
lt_succ_iff.trans le_iff_eq_or_lt
theorem Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) :=
Iio_succ_eq_insert_of_not_isMax <| not_isMax a
theorem Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) :=
Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b
theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) :=
Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b
@[simp]
theorem Ioo_eq_empty_iff_le_succ : Ioo a b = ∅ ↔ b ≤ succ a := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· contrapose! h
exact ⟨succ a, lt_succ_iff_not_isMax.mpr (not_isMax a), h⟩
· ext x
suffices a < x → b ≤ x by simpa
exact fun hx ↦ le_of_lt_succ <| lt_of_le_of_lt h <| succ_strictMono hx
end NoMaxOrder
section OrderBot
variable [OrderBot α]
theorem lt_succ_bot_iff [NoMaxOrder α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff]
theorem le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by
rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm]
end OrderBot
end LinearOrder
/-- There is at most one way to define the successors in a `PartialOrder`. -/
instance [PartialOrder α] : Subsingleton (SuccOrder α) :=
⟨by
intro h₀ h₁
ext a
by_cases ha : IsMax a
· exact (@IsMax.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm
· exact @CovBy.succ_eq _ _ h₀ _ _ (covBy_succ_of_not_isMax ha)⟩
theorem succ_eq_sInf [CompleteLattice α] [SuccOrder α] (a : α) :
succ a = sInf (Set.Ioi a) := by
apply (le_sInf fun b => succ_le_of_lt).antisymm
obtain rfl | ha := eq_or_ne a ⊤
· rw [succ_top]
exact le_top
· exact sInf_le (lt_succ_iff_ne_top.2 ha)
theorem succ_eq_iInf [CompleteLattice α] [SuccOrder α] (a : α) : succ a = ⨅ b > a, b := by
rw [succ_eq_sInf, iInf_subtype', iInf, Subtype.range_coe_subtype, Ioi]
theorem succ_eq_csInf [ConditionallyCompleteLattice α] [SuccOrder α] [NoMaxOrder α] (a : α) :
succ a = sInf (Set.Ioi a) := by
apply (le_csInf nonempty_Ioi fun b => succ_le_of_lt).antisymm
exact csInf_le ⟨a, fun b => le_of_lt⟩ <| lt_succ a
/-! ### Predecessor order -/
section Preorder
variable [Preorder α] [PredOrder α] {a b : α}
/-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less
than `a`. If `a` is minimal, then `pred a = a`. -/
def pred : α → α :=
PredOrder.pred
theorem pred_le : ∀ a : α, pred a ≤ a :=
PredOrder.pred_le
theorem min_of_le_pred {a : α} : a ≤ pred a → IsMin a :=
PredOrder.min_of_le_pred
theorem le_pred_of_lt {a b : α} : a < b → a ≤ pred b :=
PredOrder.le_pred_of_lt
alias _root_.LT.lt.le_pred := le_pred_of_lt
@[simp]
theorem le_pred_iff_isMin : a ≤ pred a ↔ IsMin a :=
⟨min_of_le_pred, fun h => h <| pred_le _⟩
alias ⟨_root_.IsMin.of_le_pred, _root_.IsMin.le_pred⟩ := le_pred_iff_isMin
@[simp]
theorem pred_lt_iff_not_isMin : pred a < a ↔ ¬IsMin a :=
⟨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_le fun h => ha <| min_of_le_pred h⟩
alias ⟨_, pred_lt_of_not_isMin⟩ := pred_lt_iff_not_isMin
theorem pred_wcovBy (a : α) : pred a ⩿ a :=
⟨pred_le a, fun _ hb nh => (le_pred_of_lt nh).not_lt hb⟩
theorem pred_covBy_of_not_isMin (h : ¬IsMin a) : pred a ⋖ a :=
(pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h
theorem pred_lt_of_not_isMin_of_le (ha : ¬IsMin a) : a ≤ b → pred a < b :=
(pred_lt_of_not_isMin ha).trans_le
theorem le_pred_iff_of_not_isMin (ha : ¬IsMin a) : b ≤ pred a ↔ b < a :=
⟨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_lt⟩
lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : ¬ IsMin a) : pred a < pred b :=
pred_lt_of_not_isMin_of_le ha <| le_pred_of_lt h
theorem pred_le_pred_of_not_isMin_of_le (ha : ¬IsMin a) (hb : ¬IsMin b) :
a ≤ b → pred a ≤ pred b := by
rw [le_pred_iff_of_not_isMin hb]
apply pred_lt_of_not_isMin_of_le ha
@[simp, mono, gcongr]
theorem pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b :=
succ_le_succ h.dual
theorem pred_mono : Monotone (pred : α → α) := fun _ _ => pred_le_pred
/-- See also `Order.pred_eq_of_covBy`. -/
lemma pred_le_of_wcovBy (h : a ⩿ b) : pred b ≤ a := by
obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le
· by_contra hba
exact h.2 (hab.lt.le_pred.lt_of_not_le hba) (pred_lt_of_not_isMin hab.lt.not_isMin)
· exact (pred_le _).trans hba
alias _root_.WCovBy.pred_le := pred_le_of_wcovBy
theorem pred_iterate_le (k : ℕ) (x : α) : pred^[k] x ≤ x := by
conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)]
exact Monotone.iterate_le_of_le pred_mono pred_le k x
theorem isMin_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a)
(h_lt : n < m) : IsMin (pred^[n] a) :=
@isMax_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt
theorem isMin_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a)
(h_ne : n ≠ m) : IsMin (pred^[n] a) :=
@isMax_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne
theorem Ici_subset_Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ici a ⊆ Ioi (pred a) :=
fun _ ↦ pred_lt_of_not_isMin_of_le ha
theorem Iic_pred_of_not_isMin (ha : ¬IsMin a) : Iic (pred a) = Iio a :=
Set.ext fun _ => le_pred_iff_of_not_isMin ha
theorem Icc_subset_Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Icc a b ⊆ Ioc (pred a) b := by
rw [← Ioi_inter_Iic, ← Ici_inter_Iic]
gcongr
apply Ici_subset_Ioi_pred_of_not_isMin ha
theorem Ico_subset_Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ico a b ⊆ Ioo (pred a) b := by
rw [← Ioi_inter_Iio, ← Ici_inter_Iio]
gcongr
apply Ici_subset_Ioi_pred_of_not_isMin ha
theorem Icc_pred_right_of_not_isMin (ha : ¬IsMin b) : Icc a (pred b) = Ico a b := by
rw [← Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio]
theorem Ioc_pred_right_of_not_isMin (ha : ¬IsMin b) : Ioc a (pred b) = Ioo a b := by
rw [← Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio]
section NoMinOrder
variable [NoMinOrder α]
theorem pred_lt (a : α) : pred a < a :=
pred_lt_of_not_isMin <| not_isMin a
@[simp]
theorem pred_lt_of_le : a ≤ b → pred a < b :=
pred_lt_of_not_isMin_of_le <| not_isMin a
@[simp]
theorem le_pred_iff : a ≤ pred b ↔ a < b :=
le_pred_iff_of_not_isMin <| not_isMin b
theorem pred_le_pred_of_le : a ≤ b → pred a ≤ pred b := by intro; simp_all
theorem pred_lt_pred : a < b → pred a < pred b := by intro; simp_all
theorem pred_strictMono : StrictMono (pred : α → α) := fun _ _ => pred_lt_pred
theorem pred_covBy (a : α) : pred a ⋖ a :=
pred_covBy_of_not_isMin <| not_isMin a
theorem Ici_subset_Ioi_pred (a : α) : Ici a ⊆ Ioi (pred a) := by simp
@[simp]
theorem Iic_pred (a : α) : Iic (pred a) = Iio a :=
Iic_pred_of_not_isMin <| not_isMin a
@[simp]
theorem Icc_subset_Ioc_pred_left (a b : α) : Icc a b ⊆ Ioc (pred a) b :=
Icc_subset_Ioc_pred_left_of_not_isMin <| not_isMin _
@[simp]
theorem Ico_subset_Ioo_pred_left (a b : α) : Ico a b ⊆ Ioo (pred a) b :=
Ico_subset_Ioo_pred_left_of_not_isMin <| not_isMin _
@[simp]
theorem Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b :=
Icc_pred_right_of_not_isMin <| not_isMin _
@[simp]
theorem Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b :=
Ioc_pred_right_of_not_isMin <| not_isMin _
end NoMinOrder
end Preorder
section PartialOrder
variable [PartialOrder α] [PredOrder α] {a b : α}
@[simp]
theorem pred_eq_iff_isMin : pred a = a ↔ IsMin a :=
⟨fun h => min_of_le_pred h.ge, fun h => h.eq_of_le <| pred_le _⟩
alias ⟨_, _root_.IsMin.pred_eq⟩ := pred_eq_iff_isMin
lemma le_iff_eq_or_le_pred : a ≤ b ↔ a = b ∨ a ≤ pred b := by
by_cases hb : IsMin b
· simpa [hb.pred_eq] using le_of_eq
· rw [le_pred_iff_of_not_isMin hb, le_iff_eq_or_lt]
theorem pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a := by
refine
⟨fun h =>
or_iff_not_imp_left.2 fun hba : b ≠ a => (le_pred_of_lt <| h.2.lt_of_ne hba).antisymm h.1, ?_⟩
rintro (rfl | rfl)
· exact ⟨pred_le b, le_rfl⟩
· exact ⟨le_rfl, pred_le a⟩
/-- See also `Order.pred_le_of_wcovBy`. -/
lemma pred_eq_of_covBy (h : a ⋖ b) : pred b = a := h.wcovBy.pred_le.antisymm (le_pred_of_lt h.lt)
alias _root_.CovBy.pred_eq := pred_eq_of_covBy
theorem _root_.OrderIso.map_pred {β : Type*} [PartialOrder β] [PredOrder β] (f : α ≃o β) (a : α) :
f (pred a) = pred (f a) :=
f.dual.map_succ a
section NoMinOrder
variable [NoMinOrder α]
theorem pred_eq_iff_covBy : pred b = a ↔ a ⋖ b :=
⟨by
rintro rfl
exact pred_covBy _, CovBy.pred_eq⟩
end NoMinOrder
section OrderBot
variable [OrderBot α]
@[simp]
theorem pred_bot : pred (⊥ : α) = ⊥ :=
isMin_bot.pred_eq
theorem le_pred_iff_eq_bot : a ≤ pred a ↔ a = ⊥ :=
@succ_le_iff_eq_top αᵒᵈ _ _ _ _
theorem pred_lt_iff_ne_bot : pred a < a ↔ a ≠ ⊥ :=
@lt_succ_iff_ne_top αᵒᵈ _ _ _ _
end OrderBot
section OrderTop
variable [OrderTop α] [Nontrivial α]
theorem pred_lt_top (a : α) : pred a < ⊤ :=
(pred_mono le_top).trans_lt <| pred_lt_of_not_isMin not_isMin_top
theorem pred_ne_top (a : α) : pred a ≠ ⊤ :=
(pred_lt_top a).ne
end OrderTop
end PartialOrder
section LinearOrder
variable [LinearOrder α] [PredOrder α] {a b : α}
theorem le_of_pred_lt {a b : α} : pred a < b → a ≤ b := fun h ↦ by
by_contra! nh
exact le_pred_of_lt nh |>.trans_lt h |>.false
theorem pred_lt_iff_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a ≤ b :=
⟨le_of_pred_lt, (pred_lt_of_not_isMin ha).trans_le⟩
theorem pred_lt_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) :
pred a < pred b ↔ a < b := by
rw [pred_lt_iff_of_not_isMin ha, le_pred_iff_of_not_isMin hb]
theorem pred_le_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) :
pred a ≤ pred b ↔ a ≤ b := by
rw [le_pred_iff_of_not_isMin hb, pred_lt_iff_of_not_isMin ha]
theorem Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = Ici a :=
Set.ext fun _ => pred_lt_iff_of_not_isMin ha
theorem Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioc (pred a) b = Icc a b := by
rw [← Ioi_inter_Iic, Ioi_pred_of_not_isMin ha, Ici_inter_Iic]
theorem Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioo (pred a) b = Ico a b := by
rw [← Ioi_inter_Iio, Ioi_pred_of_not_isMin ha, Ici_inter_Iio]
theorem pred_eq_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) :
pred a = pred b ↔ a = b := by
rw [eq_iff_le_not_lt, eq_iff_le_not_lt, pred_le_pred_iff_of_not_isMin ha hb,
pred_lt_pred_iff_of_not_isMin ha hb]
theorem pred_le_iff_eq_or_le : pred a ≤ b ↔ b = pred a ∨ a ≤ b := by
by_cases ha : IsMin a
· rw [ha.pred_eq, or_iff_right_of_imp ge_of_eq]
· rw [← pred_lt_iff_of_not_isMin ha, le_iff_eq_or_lt, eq_comm]
theorem pred_lt_iff_eq_or_lt_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a = b ∨ a < b :=
(pred_lt_iff_of_not_isMin ha).trans le_iff_eq_or_lt
theorem not_isMax_pred [Nontrivial α] (a : α) : ¬ IsMax (pred a) :=
not_isMin_succ (α := αᵒᵈ) a
theorem Ici_pred (a : α) : Ici (pred a) = insert (pred a) (Ici a) :=
ext fun _ => pred_le_iff_eq_or_le
theorem Ioi_pred_eq_insert_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = insert a (Ioi a) := by
ext x; simp only [insert, mem_setOf, @eq_comm _ x a, mem_Ioi, Set.insert]
exact pred_lt_iff_eq_or_lt_of_not_isMin ha
theorem Icc_pred_left (h : pred a ≤ b) : Icc (pred a) b = insert (pred a) (Icc a b) := by
simp_rw [← Ici_inter_Iic, Ici_pred, insert_inter_of_mem (mem_Iic.2 h)]
theorem Ico_pred_left (h : pred a < b) : Ico (pred a) b = insert (pred a) (Ico a b) := by
simp_rw [← Ici_inter_Iio, Ici_pred, insert_inter_of_mem (mem_Iio.2 h)]
section NoMinOrder
variable [NoMinOrder α]
@[simp]
| theorem pred_lt_iff : pred a < b ↔ a ≤ b :=
pred_lt_iff_of_not_isMin <| not_isMin a
| Mathlib/Order/SuccPred/Basic.lean | 844 | 846 |
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Emilie Uthaiwat, Oliver Nash
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Div
import Mathlib.Algebra.Polynomial.Identities
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.RingTheory.Polynomial.Tower
/-!
# Nilpotency in polynomial rings.
This file is a place for results related to nilpotency in (single-variable) polynomial rings.
## Main results:
* `Polynomial.isNilpotent_iff`
* `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent`
-/
namespace Polynomial
variable {R : Type*} {r : R}
section Semiring
variable [Semiring R] {P : R[X]}
lemma isNilpotent_C_mul_pow_X_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) :
IsNilpotent ((C r) * X ^ n) := by
refine Commute.isNilpotent_mul_left (commute_X_pow _ _).symm ?_
obtain ⟨m, hm⟩ := hnil
refine ⟨m, ?_⟩
rw [← C_pow, hm, C_0]
lemma isNilpotent_pow_X_mul_C_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) :
IsNilpotent (X ^ n * (C r)) := by
rw [commute_X_pow]
exact isNilpotent_C_mul_pow_X_of_isNilpotent n hnil
@[simp] lemma isNilpotent_monomial_iff {n : ℕ} :
IsNilpotent (monomial (R := R) n r) ↔ IsNilpotent r :=
exists_congr fun k ↦ by simp
@[simp] lemma isNilpotent_C_iff :
IsNilpotent (C r) ↔ IsNilpotent r :=
exists_congr fun k ↦ by simpa only [← C_pow] using C_eq_zero
@[simp] lemma isNilpotent_X_mul_iff :
IsNilpotent (X * P) ↔ IsNilpotent P := by
refine ⟨fun h ↦ ?_, ?_⟩
· rwa [Commute.isNilpotent_mul_right_iff (commute_X P) (by simp)] at h
· rintro ⟨k, hk⟩
exact ⟨k, by simp [(commute_X P).mul_pow, hk]⟩
@[simp] lemma isNilpotent_mul_X_iff :
IsNilpotent (P * X) ↔ IsNilpotent P := by
rw [← commute_X P]
exact isNilpotent_X_mul_iff
end Semiring
section CommRing
variable [CommRing R] {P : R[X]}
| protected lemma isNilpotent_iff :
IsNilpotent P ↔ ∀ i, IsNilpotent (coeff P i) := by
refine
⟨P.recOnHorner (by simp) (fun p r hp₀ _ hp hpr i ↦ ?_) (fun p _ hnp hpX i ↦ ?_), fun h ↦ ?_⟩
· rw [← sum_monomial_eq P]
exact isNilpotent_sum (fun i _ ↦ by simpa only [isNilpotent_monomial_iff] using h i)
· have hr : IsNilpotent (C r) := by
obtain ⟨k, hk⟩ := hpr
replace hp : eval 0 p = 0 := by rwa [coeff_zero_eq_aeval_zero] at hp₀
refine isNilpotent_C_iff.mpr ⟨k, ?_⟩
simpa [coeff_zero_eq_aeval_zero, hp] using congr_arg (fun q ↦ coeff q 0) hk
rcases i with - | i
· simpa [hp₀] using hr
simp only [coeff_add, coeff_C_succ, add_zero]
apply hp
simpa using Commute.isNilpotent_sub (Commute.all _ _) hpr hr
· rcases i with - | i
· simp
simpa using hnp (isNilpotent_mul_X_iff.mp hpX) i
| Mathlib/RingTheory/Polynomial/Nilpotent.lean | 71 | 89 |
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Fourier.AddCircle
import Mathlib.Analysis.Fourier.FourierTransform
import Mathlib.Analysis.PSeries
import Mathlib.Analysis.Distribution.FourierSchwartz
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import Mathlib.Topology.ContinuousMap.Periodic
/-!
# Poisson's summation formula
We prove Poisson's summation formula `∑ (n : ℤ), f n = ∑ (n : ℤ), 𝓕 f n`, where `𝓕 f` is the
Fourier transform of `f`, under the following hypotheses:
* `f` is a continuous function `ℝ → ℂ`.
* The sum `∑ (n : ℤ), 𝓕 f n` is convergent.
* For all compacts `K ⊂ ℝ`, the sum `∑ (n : ℤ), sup { ‖f(x + n)‖ | x ∈ K }` is convergent.
See `Real.tsum_eq_tsum_fourierIntegral` for this formulation.
These hypotheses are potentially a little awkward to apply, so we also provide the less general but
easier-to-use result `Real.tsum_eq_tsum_fourierIntegral_of_rpow_decay`, in which we assume `f` and
`𝓕 f` both decay as `|x| ^ (-b)` for some `b > 1`, and the even more specific result
`SchwartzMap.tsum_eq_tsum_fourierIntegral`, where we assume that both `f` and `𝓕 f` are Schwartz
functions.
-/
noncomputable section
open Function hiding comp_apply
open Set hiding restrict_apply
open Complex hiding abs_of_nonneg
open Real
open TopologicalSpace Filter MeasureTheory Asymptotics
open scoped Real Filter FourierTransform
open ContinuousMap
/-- The key lemma for Poisson summation: the `m`-th Fourier coefficient of the periodic function
`∑' n : ℤ, f (x + n)` is the value at `m` of the Fourier transform of `f`. -/
theorem Real.fourierCoeff_tsum_comp_add {f : C(ℝ, ℂ)}
(hf : ∀ K : Compacts ℝ, Summable fun n : ℤ => ‖(f.comp (ContinuousMap.addRight n)).restrict K‖)
(m : ℤ) : fourierCoeff (Periodic.lift <| f.periodic_tsum_comp_add_zsmul 1) m = 𝓕 f m := by
-- NB: This proof can be shortened somewhat by telescoping together some of the steps in the calc
-- block, but I think it's more legible this way. We start with preliminaries about the integrand.
let e : C(ℝ, ℂ) := (fourier (-m)).comp ⟨((↑) : ℝ → UnitAddCircle), continuous_quotient_mk'⟩
have neK : ∀ (K : Compacts ℝ) (g : C(ℝ, ℂ)), ‖(e * g).restrict K‖ = ‖g.restrict K‖ := by
have (x : ℝ) : ‖e x‖ = 1 := (AddCircle.toCircle (-m • x)).norm_coe
intro K g
simp_rw [norm_eq_iSup_norm, restrict_apply, mul_apply, norm_mul, this, one_mul]
have eadd : ∀ (n : ℤ), e.comp (ContinuousMap.addRight n) = e := by
intro n; ext1 x
have : Periodic e 1 := Periodic.comp (fun x => AddCircle.coe_add_period 1 x) (fourier (-m))
simpa only [mul_one] using this.int_mul n x
-- Now the main argument. First unwind some definitions.
calc
fourierCoeff (Periodic.lift <| f.periodic_tsum_comp_add_zsmul 1) m =
∫ x in (0 : ℝ)..1, e x * (∑' n : ℤ, f.comp (ContinuousMap.addRight n)) x := by
simp_rw [fourierCoeff_eq_intervalIntegral _ m 0, div_one, one_smul, zero_add, e, comp_apply,
coe_mk, Periodic.lift_coe, zsmul_one, smul_eq_mul]
-- Transform sum in C(ℝ, ℂ) evaluated at x into pointwise sum of values.
_ = ∫ x in (0 : ℝ)..1, ∑' n : ℤ, (e * f.comp (ContinuousMap.addRight n)) x := by
simp_rw [coe_mul, Pi.mul_apply,
← ContinuousMap.tsum_apply (summable_of_locally_summable_norm hf), tsum_mul_left]
-- Swap sum and integral.
_ = ∑' n : ℤ, ∫ x in (0 : ℝ)..1, (e * f.comp (ContinuousMap.addRight n)) x := by
refine (intervalIntegral.tsum_intervalIntegral_eq_of_summable_norm ?_).symm
convert hf ⟨uIcc 0 1, isCompact_uIcc⟩ using 1
exact funext fun n => neK _ _
_ = ∑' n : ℤ, ∫ x in (0 : ℝ)..1, (e * f).comp (ContinuousMap.addRight n) x := by
simp only [ContinuousMap.comp_apply, mul_comp] at eadd ⊢
simp_rw [eadd]
-- Rearrange sum of interval integrals into an integral over `ℝ`.
_ = ∫ x, e x * f x := by
suffices Integrable (e * f) from this.hasSum_intervalIntegral_comp_add_int.tsum_eq
apply integrable_of_summable_norm_Icc
convert hf ⟨Icc 0 1, isCompact_Icc⟩ using 1
simp_rw [mul_comp] at eadd ⊢
simp_rw [eadd]
exact funext fun n => neK ⟨Icc 0 1, isCompact_Icc⟩ _
-- Minor tidying to finish
_ = 𝓕 f m := by
rw [fourierIntegral_real_eq_integral_exp_smul]
congr 1 with x : 1
rw [smul_eq_mul, comp_apply, coe_mk, coe_mk, ContinuousMap.toFun_eq_coe, fourier_coe_apply]
congr 2
push_cast
ring
/-- **Poisson's summation formula**, most general form. -/
theorem Real.tsum_eq_tsum_fourierIntegral {f : C(ℝ, ℂ)}
(h_norm :
∀ K : Compacts ℝ, Summable fun n : ℤ => ‖(f.comp <| ContinuousMap.addRight n).restrict K‖)
(h_sum : Summable fun n : ℤ => 𝓕 f n) (x : ℝ) :
∑' n : ℤ, f (x + n) = ∑' n : ℤ, 𝓕 f n * fourier n (x : UnitAddCircle) := by
let F : C(UnitAddCircle, ℂ) :=
⟨(f.periodic_tsum_comp_add_zsmul 1).lift, continuous_coinduced_dom.mpr (map_continuous _)⟩
have : Summable (fourierCoeff F) := by
| convert h_sum
exact Real.fourierCoeff_tsum_comp_add h_norm _
convert (has_pointwise_sum_fourier_series_of_summable this x).tsum_eq.symm using 1
· simpa only [F, coe_mk, ← QuotientAddGroup.mk_zero, Periodic.lift_coe, zsmul_one, comp_apply,
coe_addRight, zero_add]
using (hasSum_apply (summable_of_locally_summable_norm h_norm).hasSum x).tsum_eq
· simp_rw [← Real.fourierCoeff_tsum_comp_add h_norm, smul_eq_mul, F, coe_mk]
section RpowDecay
variable {E : Type*} [NormedAddCommGroup E]
/-- If `f` is `O(x ^ (-b))` at infinity, then so is the function
`fun x ↦ ‖f.restrict (Icc (x + R) (x + S))‖` for any fixed `R` and `S`. -/
theorem isBigO_norm_Icc_restrict_atTop {f : C(ℝ, E)} {b : ℝ} (hb : 0 < b)
| Mathlib/Analysis/Fourier/PoissonSummation.lean | 107 | 121 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot
-/
import Mathlib.Data.Set.Function
import Mathlib.Order.Interval.Set.OrdConnected
/-!
# Projection of a line onto a closed interval
Given a linearly ordered type `α`, in this file we define
* `Set.projIci (a : α)` to be the map `α → [a, ∞)` sending `(-∞, a]` to `a`, and each point
`x ∈ [a, ∞)` to itself;
* `Set.projIic (b : α)` to be the map `α → (-∞, b[` sending `[b, ∞)` to `b`, and each point
`x ∈ (-∞, b]` to itself;
* `Set.projIcc (a b : α) (h : a ≤ b)` to be the map `α → [a, b]` sending `(-∞, a]` to `a`, `[b, ∞)`
to `b`, and each point `x ∈ [a, b]` to itself;
* `Set.IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β)` to be the extension of `f` to `α` defined
as `f ∘ projIcc a b h`.
* `Set.IciExtend {a : α} (f : Ici a → β)` to be the extension of `f` to `α` defined
as `f ∘ projIci a`.
* `Set.IicExtend {b : α} (f : Iic b → β)` to be the extension of `f` to `α` defined
as `f ∘ projIic b`.
We also prove some trivial properties of these maps.
-/
variable {α β : Type*} [LinearOrder α]
open Function
namespace Set
/-- Projection of `α` to the closed interval `[a, ∞)`. -/
def projIci (a x : α) : Ici a := ⟨max a x, le_max_left _ _⟩
/-- Projection of `α` to the closed interval `(-∞, b]`. -/
def projIic (b x : α) : Iic b := ⟨min b x, min_le_left _ _⟩
/-- Projection of `α` to the closed interval `[a, b]`. -/
def projIcc (a b : α) (h : a ≤ b) (x : α) : Icc a b :=
⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩
variable {a b : α} (h : a ≤ b) {x : α}
@[norm_cast]
theorem coe_projIci (a x : α) : (projIci a x : α) = max a x := rfl
@[norm_cast]
theorem coe_projIic (b x : α) : (projIic b x : α) = min b x := rfl
@[norm_cast]
theorem coe_projIcc (a b : α) (h : a ≤ b) (x : α) : (projIcc a b h x : α) = max a (min b x) := rfl
theorem projIci_of_le (hx : x ≤ a) : projIci a x = ⟨a, le_rfl⟩ := Subtype.ext <| max_eq_left hx
theorem projIic_of_le (hx : b ≤ x) : projIic b x = ⟨b, le_rfl⟩ := Subtype.ext <| min_eq_left hx
theorem projIcc_of_le_left (hx : x ≤ a) : projIcc a b h x = ⟨a, left_mem_Icc.2 h⟩ := by
simp [projIcc, hx, hx.trans h]
theorem projIcc_of_right_le (hx : b ≤ x) : projIcc a b h x = ⟨b, right_mem_Icc.2 h⟩ := by
simp [projIcc, hx, h]
@[simp]
theorem projIci_self (a : α) : projIci a a = ⟨a, le_rfl⟩ := projIci_of_le le_rfl
@[simp]
theorem projIic_self (b : α) : projIic b b = ⟨b, le_rfl⟩ := projIic_of_le le_rfl
@[simp]
theorem projIcc_left : projIcc a b h a = ⟨a, left_mem_Icc.2 h⟩ :=
projIcc_of_le_left h le_rfl
@[simp]
theorem projIcc_right : projIcc a b h b = ⟨b, right_mem_Icc.2 h⟩ :=
projIcc_of_right_le h le_rfl
theorem projIci_eq_self : projIci a x = ⟨a, le_rfl⟩ ↔ x ≤ a := by simp [projIci, Subtype.ext_iff]
theorem projIic_eq_self : projIic b x = ⟨b, le_rfl⟩ ↔ b ≤ x := by simp [projIic, Subtype.ext_iff]
theorem projIcc_eq_left (h : a < b) : projIcc a b h.le x = ⟨a, left_mem_Icc.mpr h.le⟩ ↔ x ≤ a := by
simp [projIcc, Subtype.ext_iff, h.not_le]
theorem projIcc_eq_right (h : a < b) : projIcc a b h.le x = ⟨b, right_mem_Icc.2 h.le⟩ ↔ b ≤ x := by
simp [projIcc, Subtype.ext_iff, max_min_distrib_left, h.le, h.not_le]
theorem projIci_of_mem (hx : x ∈ Ici a) : projIci a x = ⟨x, hx⟩ := by simpa [projIci]
theorem projIic_of_mem (hx : x ∈ Iic b) : projIic b x = ⟨x, hx⟩ := by simpa [projIic]
theorem projIcc_of_mem (hx : x ∈ Icc a b) : projIcc a b h x = ⟨x, hx⟩ := by
simp [projIcc, hx.1, hx.2]
@[simp]
theorem projIci_coe (x : Ici a) : projIci a x = x := by cases x; apply projIci_of_mem
@[simp]
theorem projIic_coe (x : Iic b) : projIic b x = x := by cases x; apply projIic_of_mem
@[simp]
theorem projIcc_val (x : Icc a b) : projIcc a b h x = x := by
cases x
apply projIcc_of_mem
theorem projIci_surjOn : SurjOn (projIci a) (Ici a) univ := fun x _ => ⟨x, x.2, projIci_coe x⟩
theorem projIic_surjOn : SurjOn (projIic b) (Iic b) univ := fun x _ => ⟨x, x.2, projIic_coe x⟩
theorem projIcc_surjOn : SurjOn (projIcc a b h) (Icc a b) univ := fun x _ =>
⟨x, x.2, projIcc_val h x⟩
theorem projIci_surjective : Surjective (projIci a) := fun x => ⟨x, projIci_coe x⟩
theorem projIic_surjective : Surjective (projIic b) := fun x => ⟨x, projIic_coe x⟩
theorem projIcc_surjective : Surjective (projIcc a b h) := fun x => ⟨x, projIcc_val h x⟩
@[simp]
theorem range_projIci : range (projIci a) = univ := projIci_surjective.range_eq
@[simp]
theorem range_projIic : range (projIic a) = univ := projIic_surjective.range_eq
@[simp]
theorem range_projIcc : range (projIcc a b h) = univ :=
(projIcc_surjective h).range_eq
theorem monotone_projIci : Monotone (projIci a) := fun _ _ => max_le_max le_rfl
theorem monotone_projIic : Monotone (projIic a) := fun _ _ => min_le_min le_rfl
theorem monotone_projIcc : Monotone (projIcc a b h) := fun _ _ hxy =>
max_le_max le_rfl <| min_le_min le_rfl hxy
theorem strictMonoOn_projIci : StrictMonoOn (projIci a) (Ici a) := fun x hx y hy hxy => by
simpa only [projIci_of_mem, hx, hy]
theorem strictMonoOn_projIic : StrictMonoOn (projIic b) (Iic b) := fun x hx y hy hxy => by
simpa only [projIic_of_mem, hx, hy]
theorem strictMonoOn_projIcc : StrictMonoOn (projIcc a b h) (Icc a b) := fun x hx y hy hxy => by
simpa only [projIcc_of_mem, hx, hy]
/-- Extend a function `[a, ∞) → β` to a map `α → β`. -/
def IciExtend (f : Ici a → β) : α → β :=
f ∘ projIci a
/-- Extend a function `(-∞, b] → β` to a map `α → β`. -/
def IicExtend (f : Iic b → β) : α → β :=
f ∘ projIic b
/-- Extend a function `[a, b] → β` to a map `α → β`. -/
def IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β) : α → β :=
f ∘ projIcc a b h
theorem IciExtend_apply (f : Ici a → β) (x : α) : IciExtend f x = f ⟨max a x, le_max_left _ _⟩ :=
rfl
theorem IicExtend_apply (f : Iic b → β) (x : α) : IicExtend f x = f ⟨min b x, min_le_left _ _⟩ :=
rfl
theorem IccExtend_apply (h : a ≤ b) (f : Icc a b → β) (x : α) :
IccExtend h f x = f ⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩ := rfl
@[simp]
theorem range_IciExtend (f : Ici a → β) : range (IciExtend f) = range f := by
simp only [IciExtend, range_comp f, range_projIci, range_id', image_univ]
@[simp]
theorem range_IicExtend (f : Iic b → β) : range (IicExtend f) = range f := by
simp only [IicExtend, range_comp f, range_projIic, range_id', image_univ]
@[simp]
| theorem IccExtend_range (f : Icc a b → β) : range (IccExtend h f) = range f := by
simp only [IccExtend, range_comp f, range_projIcc, image_univ]
| Mathlib/Order/Interval/Set/ProjIcc.lean | 179 | 180 |
/-
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
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]
theorem monic_of_c_eq_one' : (toPoly ⟨0, 0, 1, d⟩).Monic :=
monic_of_c_eq_one rfl rfl rfl
theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) :
P.toPoly.Monic := by
rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd]
theorem monic_of_d_eq_one' : (toPoly ⟨0, 0, 0, 1⟩).Monic :=
monic_of_d_eq_one rfl rfl rfl rfl
end Coeff
/-! ### Degrees -/
section Degree
/-- The equivalence between cubic polynomials and polynomials of degree at most three. -/
@[simps]
def equiv : Cubic R ≃ { p : R[X] // p.degree ≤ 3 } where
toFun P := ⟨P.toPoly, degree_cubic_le⟩
invFun f := ⟨coeff f 3, coeff f 2, coeff f 1, coeff f 0⟩
left_inv P := by ext <;> simp only [Subtype.coe_mk, coeffs]
right_inv f := by
ext n
obtain hn | hn := le_or_lt n 3
· interval_cases n <;> simp only [Nat.succ_eq_add_one] <;> ring_nf <;> try simp only [coeffs]
· rw [coeff_eq_zero hn, (degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2]
simpa using hn
@[simp]
theorem degree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.degree = 3 :=
degree_cubic ha
@[simp]
theorem degree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).degree = 3 :=
degree_of_a_ne_zero ha
theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree ≤ 2 := by
simpa only [of_a_eq_zero ha] using degree_quadratic_le
theorem degree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).degree ≤ 2 :=
degree_of_a_eq_zero rfl
@[simp]
theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.degree = 2 := by
rw [of_a_eq_zero ha, degree_quadratic hb]
@[simp]
theorem degree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).degree = 2 :=
degree_of_b_ne_zero rfl hb
theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree ≤ 1 := by
simpa only [of_b_eq_zero ha hb] using degree_linear_le
theorem degree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).degree ≤ 1 :=
degree_of_b_eq_zero rfl rfl
@[simp]
theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.degree = 1 := by
rw [of_b_eq_zero ha hb, degree_linear hc]
@[simp]
theorem degree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).degree = 1 :=
degree_of_c_ne_zero rfl rfl hc
theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree ≤ 0 := by
simpa only [of_c_eq_zero ha hb hc] using degree_C_le
theorem degree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).degree ≤ 0 :=
degree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d ≠ 0) :
P.toPoly.degree = 0 := by
rw [of_c_eq_zero ha hb hc, degree_C hd]
@[simp]
theorem degree_of_d_ne_zero' (hd : d ≠ 0) : (toPoly ⟨0, 0, 0, d⟩).degree = 0 :=
degree_of_d_ne_zero rfl rfl rfl hd
@[simp]
theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly.degree = ⊥ := by
rw [of_d_eq_zero ha hb hc hd, degree_zero]
theorem degree_of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly.degree = ⊥ :=
degree_of_d_eq_zero rfl rfl rfl rfl
@[simp]
theorem degree_of_zero : (0 : Cubic R).toPoly.degree = ⊥ :=
degree_of_d_eq_zero'
@[simp]
theorem natDegree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.natDegree = 3 :=
natDegree_cubic ha
@[simp]
theorem natDegree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).natDegree = 3 :=
natDegree_of_a_ne_zero ha
theorem natDegree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.natDegree ≤ 2 := by
simpa only [of_a_eq_zero ha] using natDegree_quadratic_le
theorem natDegree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).natDegree ≤ 2 :=
natDegree_of_a_eq_zero rfl
@[simp]
theorem natDegree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.natDegree = 2 := by
rw [of_a_eq_zero ha, natDegree_quadratic hb]
@[simp]
theorem natDegree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).natDegree = 2 :=
natDegree_of_b_ne_zero rfl hb
theorem natDegree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.natDegree ≤ 1 := by
simpa only [of_b_eq_zero ha hb] using natDegree_linear_le
theorem natDegree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).natDegree ≤ 1 :=
natDegree_of_b_eq_zero rfl rfl
@[simp]
theorem natDegree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) :
P.toPoly.natDegree = 1 := by
rw [of_b_eq_zero ha hb, natDegree_linear hc]
@[simp]
theorem natDegree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).natDegree = 1 :=
natDegree_of_c_ne_zero rfl rfl hc
@[simp]
theorem natDegree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.natDegree = 0 := by
rw [of_c_eq_zero ha hb hc, natDegree_C]
theorem natDegree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).natDegree = 0 :=
natDegree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem natDegree_of_zero : (0 : Cubic R).toPoly.natDegree = 0 :=
natDegree_of_c_eq_zero'
end Degree
/-! ### Map across a homomorphism -/
section Map
variable [Semiring S] {φ : R →+* S}
/-- Map a cubic polynomial across a semiring homomorphism. -/
def map (φ : R →+* S) (P : Cubic R) : Cubic S :=
⟨φ P.a, φ P.b, φ P.c, φ P.d⟩
theorem map_toPoly : (map φ P).toPoly = Polynomial.map φ P.toPoly := by
simp only [map, toPoly, map_C, map_X, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow]
end Map
end Basic
section Roots
open Multiset
/-! ### Roots over an extension -/
section Extension
variable {P : Cubic R} [CommRing R] [CommRing S] {φ : R →+* S}
/-- The roots of a cubic polynomial. -/
def roots [IsDomain R] (P : Cubic R) : Multiset R :=
P.toPoly.roots
|
theorem map_roots [IsDomain S] : (map φ P).roots = (Polynomial.map φ P.toPoly).roots := by
| Mathlib/Algebra/CubicDiscriminant.lean | 400 | 401 |
/-
Copyright (c) 2021 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.CategoryTheory.Action
import Mathlib.Combinatorics.Quiver.Arborescence
import Mathlib.Combinatorics.Quiver.ConnectedComponent
import Mathlib.GroupTheory.FreeGroup.IsFreeGroup
/-!
# The Nielsen-Schreier theorem
This file proves that a subgroup of a free group is itself free.
## Main result
- `subgroupIsFreeOfIsFree H`: an instance saying that a subgroup of a free group is free.
## Proof overview
The proof is analogous to the proof using covering spaces and fundamental groups of graphs,
but we work directly with groupoids instead of topological spaces. Under this analogy,
- `IsFreeGroupoid G` corresponds to saying that a space is a graph.
- `endMulEquivSubgroup H` plays the role of replacing 'subgroup of fundamental group' with
'fundamental group of covering space'.
- `actionGroupoidIsFree G A` corresponds to the fact that a covering of a (single-vertex)
graph is a graph.
- `endIsFree T` corresponds to the fact that, given a spanning tree `T` of a
graph, its fundamental group is free (generated by loops from the complement of the tree).
## Implementation notes
Our definition of `IsFreeGroupoid` is nonstandard. Normally one would require that functors
`G ⥤ X` to any _groupoid_ `X` are given by graph homomorphisms from the generators, but we only
consider _groups_ `X`. This simplifies the argument since functor equality is complicated in
general, but simple for functors to single object categories.
## References
https://ncatlab.org/nlab/show/Nielsen-Schreier+theorem
## Tags
free group, free groupoid, Nielsen-Schreier
-/
noncomputable section
universe v u
/- Porting note: ./././Mathport/Syntax/Translate/Command.lean:229:11:unsupported:
unusual advanced open style -/
open CategoryTheory CategoryTheory.ActionCategory CategoryTheory.SingleObj Quiver FreeGroup
/-- `IsFreeGroupoid.Generators G` is a type synonym for `G`. We think of this as
the vertices of the generating quiver of `G` when `G` is free. We can't use `G` directly,
since `G` already has a quiver instance from being a groupoid. -/
@[nolint unusedArguments]
def IsFreeGroupoid.Generators (G) [Groupoid G] :=
G
/-- A groupoid `G` is free when we have the following data:
- a quiver on `IsFreeGroupoid.Generators G` (a type synonym for `G`)
- a function `of` taking a generating arrow to a morphism in `G`
- such that a functor from `G` to any group `X` is uniquely determined
by assigning labels in `X` to the generating arrows.
This definition is nonstandard. Normally one would require that functors `G ⥤ X`
to any _groupoid_ `X` are given by graph homomorphisms from `generators`. -/
class IsFreeGroupoid (G) [Groupoid.{v} G] where
quiverGenerators : Quiver.{v + 1} (IsFreeGroupoid.Generators G)
of : ∀ {a b : IsFreeGroupoid.Generators G}, (a ⟶ b) → ((show G from a) ⟶ b)
unique_lift :
∀ {X : Type v} [Group X] (f : Labelling (IsFreeGroupoid.Generators G) X),
∃! F : G ⥤ CategoryTheory.SingleObj X, ∀ (a b) (g : a ⟶ b), F.map (of g) = f g
attribute [nolint docBlame] IsFreeGroupoid.of IsFreeGroupoid.unique_lift
namespace IsFreeGroupoid
attribute [instance] quiverGenerators
/-- Two functors from a free groupoid to a group are equal when they agree on the generating
quiver. -/
@[ext]
theorem ext_functor {G} [Groupoid.{v} G] [IsFreeGroupoid G] {X : Type v} [Group X]
(f g : G ⥤ CategoryTheory.SingleObj X) (h : ∀ (a b) (e : a ⟶ b), f.map (of e) = g.map (of e)) :
f = g :=
let ⟨_, _, u⟩ := @unique_lift G _ _ X _ fun (a b : Generators G) (e : a ⟶ b) => g.map (of e)
_root_.trans (u _ h) (u _ fun _ _ _ => rfl).symm
#adaptation_note /-- https://github.com/leanprover/lean4/pull/5338
The new unused variable linter flags `{ e // _ }`. -/
set_option linter.unusedVariables false in
/-- An action groupoid over a free group is free. More generally, one could show that the groupoid
of elements over a free groupoid is free, but this version is easier to prove and suffices for our
purposes.
Analogous to the fact that a covering space of a graph is a graph. (A free groupoid is like a graph,
and a groupoid of elements is like a covering space.) -/
instance actionGroupoidIsFree {G A : Type u} [Group G] [IsFreeGroup G] [MulAction G A] :
IsFreeGroupoid (ActionCategory G A) where
quiverGenerators :=
⟨fun a b => { e : IsFreeGroup.Generators G // IsFreeGroup.of e • a.back = b.back }⟩
of := fun (e : { e // _ }) => ⟨IsFreeGroup.of e, e.property⟩
unique_lift := by
intro X _ f
let f' : IsFreeGroup.Generators G → (A → X) ⋊[mulAutArrow] G := fun e =>
⟨fun b => @f ⟨(), _⟩ ⟨(), b⟩ ⟨e, smul_inv_smul _ b⟩, IsFreeGroup.of e⟩
rcases IsFreeGroup.unique_lift f' with ⟨F', hF', uF'⟩
refine ⟨uncurry F' ?_, ?_, ?_⟩
· suffices SemidirectProduct.rightHom.comp F' = MonoidHom.id _ by
exact DFunLike.ext_iff.mp this
apply IsFreeGroup.ext_hom (fun x ↦ ?_)
rw [MonoidHom.comp_apply, hF']
rfl
· rintro ⟨⟨⟩, a : A⟩ ⟨⟨⟩, b⟩ ⟨e, h : IsFreeGroup.of e • a = b⟩
change (F' (IsFreeGroup.of _)).left _ = _
rw [hF']
cases inv_smul_eq_iff.mpr h.symm
rfl
· intro E hE
have : curry E = F' := by
apply uF'
intro e
ext
· convert hE _ _ _
rfl
· rfl
apply Functor.hext
· intro
apply Unit.ext
· refine ActionCategory.cases ?_
intros
simp only [← this, uncurry_map, curry_apply_left, coe_back, homOfPair.val]
rfl
namespace SpanningTree
/- In this section, we suppose we have a free groupoid with a spanning tree for its generating
quiver. The goal is to prove that the vertex group at the root is free. A picture to have in mind
is that we are 'pulling' the endpoints of all the edges of the quiver along the spanning tree to
the root. -/
variable {G : Type u} [Groupoid.{u} G] [IsFreeGroupoid G]
(T : WideSubquiver (Symmetrify <| Generators G)) [Arborescence T]
/-- The root of `T`, except its type is `G` instead of the type synonym `T`. -/
private def root' : G :=
show T from root T
-- this has to be marked noncomputable, see issue https://github.com/leanprover-community/mathlib4/pull/451.
-- It might be nicer to define this in terms of `composePath`
/-- A path in the tree gives a hom, by composition. -/
-- Porting note: removed noncomputable. This is already declared at the beginning of the section.
def homOfPath : ∀ {a : G}, Path (root T) a → (root' T ⟶ a)
| _, Path.nil => 𝟙 _
| _, Path.cons p f => homOfPath p ≫ Sum.recOn f.val (fun e => of e) fun e => inv (of e)
/-- For every vertex `a`, there is a canonical hom from the root, given by the path in the tree. -/
def treeHom (a : G) : root' T ⟶ a :=
homOfPath T default
/-- Any path to `a` gives `treeHom T a`, since paths in the tree are unique. -/
theorem treeHom_eq {a : G} (p : Path (root T) a) : treeHom T a = homOfPath T p := by
rw [treeHom, Unique.default_eq]
@[simp]
theorem treeHom_root : treeHom T (root' T) = 𝟙 _ :=
-- this should just be `treeHom_eq T Path.nil`, but Lean treats `homOfPath` with suspicion.
_root_.trans
(treeHom_eq T Path.nil) rfl
/-- Any hom in `G` can be made into a loop, by conjugating with `treeHom`s. -/
| def loopOfHom {a b : G} (p : a ⟶ b) : End (root' T) :=
treeHom T a ≫ p ≫ inv (treeHom T b)
| Mathlib/GroupTheory/FreeGroup/NielsenSchreier.lean | 178 | 179 |
/-
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.Ordinal.Family
/-! # Ordinal exponential
In this file we define the power function and the logarithm function on ordinals. The two are
related by the lemma `Ordinal.opow_le_iff_le_log : b ^ c ≤ x ↔ c ≤ log b x` for nontrivial inputs
`b`, `c`.
-/
noncomputable section
open Function Set Equiv Order
open scoped Cardinal Ordinal
universe u v w
namespace Ordinal
/-- The ordinal exponential, defined by transfinite recursion.
We call this `opow` in theorems in order to disambiguate from other exponentials. -/
instance instPow : Pow Ordinal Ordinal :=
⟨fun a b ↦ if a = 0 then 1 - b else
limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2⟩
private theorem opow_of_ne_zero {a b : Ordinal} (h : a ≠ 0) : a ^ b =
limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2 :=
if_neg h
/-- `0 ^ a = 1` if `a = 0` and `0 ^ a = 0` otherwise. -/
theorem zero_opow' (a : Ordinal) : 0 ^ a = 1 - a :=
if_pos rfl
theorem zero_opow_le (a : Ordinal) : (0 : Ordinal) ^ a ≤ 1 := by
rw [zero_opow']
exact sub_le_self 1 a
@[simp]
theorem zero_opow {a : Ordinal} (a0 : a ≠ 0) : (0 : Ordinal) ^ a = 0 := by
rwa [zero_opow', Ordinal.sub_eq_zero_iff_le, one_le_iff_ne_zero]
@[simp]
theorem opow_zero (a : Ordinal) : a ^ (0 : Ordinal) = 1 := by
obtain rfl | h := eq_or_ne a 0
· rw [zero_opow', Ordinal.sub_zero]
· rw [opow_of_ne_zero h, limitRecOn_zero]
@[simp]
theorem opow_succ (a b : Ordinal) : a ^ succ b = a ^ b * a := by
obtain rfl | h := eq_or_ne a 0
· rw [zero_opow (succ_ne_zero b), mul_zero]
· rw [opow_of_ne_zero h, opow_of_ne_zero h, limitRecOn_succ]
theorem opow_limit {a b : Ordinal} (ha : a ≠ 0) (hb : IsLimit b) :
a ^ b = ⨆ x : Iio b, a ^ x.1 := by
simp_rw [opow_of_ne_zero ha, limitRecOn_limit _ _ _ _ hb]
theorem opow_le_of_limit {a b c : Ordinal} (a0 : a ≠ 0) (h : IsLimit b) :
a ^ b ≤ c ↔ ∀ b' < b, a ^ b' ≤ c := by
rw [opow_limit a0 h, Ordinal.iSup_le_iff, Subtype.forall]
rfl
theorem lt_opow_of_limit {a b c : Ordinal} (b0 : b ≠ 0) (h : IsLimit c) :
a < b ^ c ↔ ∃ c' < c, a < b ^ c' := by
rw [← not_iff_not, not_exists]
simp only [not_lt, opow_le_of_limit b0 h, exists_prop, not_and]
@[simp]
theorem opow_one (a : Ordinal) : a ^ (1 : Ordinal) = a := by
rw [← succ_zero, opow_succ]
simp only [opow_zero, one_mul]
@[simp]
theorem one_opow (a : Ordinal) : (1 : Ordinal) ^ a = 1 := by
induction a using limitRecOn with
| zero => simp only [opow_zero]
| succ _ ih =>
simp only [opow_succ, ih, mul_one]
| isLimit b l IH =>
refine eq_of_forall_ge_iff fun c => ?_
rw [opow_le_of_limit Ordinal.one_ne_zero l]
exact ⟨fun H => by simpa only [opow_zero] using H 0 l.pos, fun H b' h => by rwa [IH _ h]⟩
theorem opow_pos {a : Ordinal} (b : Ordinal) (a0 : 0 < a) : 0 < a ^ b := by
have h0 : 0 < a ^ (0 : Ordinal) := by simp only [opow_zero, zero_lt_one]
induction b using limitRecOn with
| zero => exact h0
| succ b IH =>
rw [opow_succ]
exact mul_pos IH a0
| isLimit b l _ =>
exact (lt_opow_of_limit (Ordinal.pos_iff_ne_zero.1 a0) l).2 ⟨0, l.pos, h0⟩
theorem opow_ne_zero {a : Ordinal} (b : Ordinal) (a0 : a ≠ 0) : a ^ b ≠ 0 :=
Ordinal.pos_iff_ne_zero.1 <| opow_pos b <| Ordinal.pos_iff_ne_zero.2 a0
@[simp]
theorem opow_eq_zero {a b : Ordinal} : a ^ b = 0 ↔ a = 0 ∧ b ≠ 0 := by
obtain rfl | ha := eq_or_ne a 0
· obtain rfl | hb := eq_or_ne b 0
· simp
· simp [hb]
· simp [opow_ne_zero b ha, ha]
@[simp, norm_cast]
theorem opow_natCast (a : Ordinal) (n : ℕ) : a ^ (n : Ordinal) = a ^ n := by
induction n with
| zero => rw [Nat.cast_zero, opow_zero, pow_zero]
| succ n IH => rw [Nat.cast_succ, add_one_eq_succ, opow_succ, pow_succ, IH]
theorem isNormal_opow {a : Ordinal} (h : 1 < a) : IsNormal (a ^ ·) :=
have a0 : 0 < a := zero_lt_one.trans h
⟨fun b => by simpa only [mul_one, opow_succ] using (mul_lt_mul_iff_left (opow_pos b a0)).2 h,
fun _ l _ => opow_le_of_limit (ne_of_gt a0) l⟩
theorem opow_lt_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b < a ^ c ↔ b < c :=
(isNormal_opow a1).lt_iff
theorem opow_le_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b ≤ a ^ c ↔ b ≤ c :=
(isNormal_opow a1).le_iff
theorem opow_right_inj {a b c : Ordinal} (a1 : 1 < a) : a ^ b = a ^ c ↔ b = c :=
(isNormal_opow a1).inj
theorem isLimit_opow {a b : Ordinal} (a1 : 1 < a) : IsLimit b → IsLimit (a ^ b) :=
(isNormal_opow a1).isLimit
theorem isLimit_opow_left {a b : Ordinal} (l : IsLimit a) (hb : b ≠ 0) : IsLimit (a ^ b) := by
rcases zero_or_succ_or_limit b with (e | ⟨b, rfl⟩ | l')
· exact absurd e hb
· rw [opow_succ]
exact isLimit_mul (opow_pos _ l.pos) l
· exact isLimit_opow l.one_lt l'
theorem opow_le_opow_right {a b c : Ordinal} (h₁ : 0 < a) (h₂ : b ≤ c) : a ^ b ≤ a ^ c := by
rcases lt_or_eq_of_le (one_le_iff_pos.2 h₁) with h₁ | h₁
· exact (opow_le_opow_iff_right h₁).2 h₂
· subst a
-- Porting note: `le_refl` is required.
simp only [one_opow, le_refl]
theorem opow_le_opow_left {a b : Ordinal} (c : Ordinal) (ab : a ≤ b) : a ^ c ≤ b ^ c := by
by_cases a0 : a = 0
-- Porting note: `le_refl` is required.
· subst a
by_cases c0 : c = 0
· subst c
simp only [opow_zero, le_refl]
· simp only [zero_opow c0, Ordinal.zero_le]
· induction c using limitRecOn with
| zero => simp only [opow_zero, le_refl]
| succ c IH =>
simpa only [opow_succ] using mul_le_mul' IH ab
| isLimit c l IH =>
exact
(opow_le_of_limit a0 l).2 fun b' h =>
(IH _ h).trans (opow_le_opow_right ((Ordinal.pos_iff_ne_zero.2 a0).trans_le ab) h.le)
theorem opow_le_opow {a b c d : Ordinal} (hac : a ≤ c) (hbd : b ≤ d) (hc : 0 < c) : a ^ b ≤ c ^ d :=
(opow_le_opow_left b hac).trans (opow_le_opow_right hc hbd)
theorem left_le_opow (a : Ordinal) {b : Ordinal} (b1 : 0 < b) : a ≤ a ^ b := by
nth_rw 1 [← opow_one a]
rcases le_or_gt a 1 with a1 | a1
· rcases lt_or_eq_of_le a1 with a0 | a1
· rw [lt_one_iff_zero] at a0
rw [a0, zero_opow Ordinal.one_ne_zero]
exact Ordinal.zero_le _
rw [a1, one_opow, one_opow]
rwa [opow_le_opow_iff_right a1, one_le_iff_pos]
theorem left_lt_opow {a b : Ordinal} (ha : 1 < a) (hb : 1 < b) : a < a ^ b := by
conv_lhs => rw [← opow_one a]
rwa [opow_lt_opow_iff_right ha]
theorem right_le_opow {a : Ordinal} (b : Ordinal) (a1 : 1 < a) : b ≤ a ^ b :=
(isNormal_opow a1).le_apply
theorem opow_lt_opow_left_of_succ {a b c : Ordinal} (ab : a < b) : a ^ succ c < b ^ succ c := by
rw [opow_succ, opow_succ]
exact
(mul_le_mul_right' (opow_le_opow_left c ab.le) a).trans_lt
(mul_lt_mul_of_pos_left ab (opow_pos c ((Ordinal.zero_le a).trans_lt ab)))
theorem opow_add (a b c : Ordinal) : a ^ (b + c) = a ^ b * a ^ c := by
rcases eq_or_ne a 0 with (rfl | a0)
· rcases eq_or_ne c 0 with (rfl | c0)
· simp
have : b + c ≠ 0 := ((Ordinal.pos_iff_ne_zero.2 c0).trans_le (le_add_left _ _)).ne'
simp only [zero_opow c0, zero_opow this, mul_zero]
rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with (rfl | a1)
· simp only [one_opow, mul_one]
induction c using limitRecOn with
| zero => simp
| succ c IH =>
rw [add_succ, opow_succ, IH, opow_succ, mul_assoc]
| isLimit c l IH =>
refine
eq_of_forall_ge_iff fun d =>
(((isNormal_opow a1).trans (isNormal_add_right b)).limit_le l).trans ?_
dsimp only [Function.comp_def]
simp +contextual only [IH]
exact
(((isNormal_mul_right <| opow_pos b (Ordinal.pos_iff_ne_zero.2 a0)).trans
(isNormal_opow a1)).limit_le
l).symm
theorem opow_one_add (a b : Ordinal) : a ^ (1 + b) = a * a ^ b := by rw [opow_add, opow_one]
theorem opow_dvd_opow (a : Ordinal) {b c : Ordinal} (h : b ≤ c) : a ^ b ∣ a ^ c :=
⟨a ^ (c - b), by rw [← opow_add, Ordinal.add_sub_cancel_of_le h]⟩
theorem opow_dvd_opow_iff {a b c : Ordinal} (a1 : 1 < a) : a ^ b ∣ a ^ c ↔ b ≤ c :=
⟨fun h =>
le_of_not_lt fun hn =>
not_le_of_lt ((opow_lt_opow_iff_right a1).2 hn) <|
le_of_dvd (opow_ne_zero _ <| one_le_iff_ne_zero.1 <| a1.le) h,
opow_dvd_opow _⟩
theorem opow_mul (a b c : Ordinal) : a ^ (b * c) = (a ^ b) ^ c := by
by_cases b0 : b = 0; · simp only [b0, zero_mul, opow_zero, one_opow]
by_cases a0 : a = 0
· subst a
by_cases c0 : c = 0
· simp only [c0, mul_zero, opow_zero]
simp only [zero_opow b0, zero_opow c0, zero_opow (mul_ne_zero b0 c0)]
rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 | a1
· subst a1
simp only [one_opow]
induction c using limitRecOn with
| zero => simp only [mul_zero, opow_zero]
| succ c IH =>
rw [mul_succ, opow_add, IH, opow_succ]
| isLimit c l IH =>
refine
eq_of_forall_ge_iff fun d =>
(((isNormal_opow a1).trans (isNormal_mul_right (Ordinal.pos_iff_ne_zero.2 b0))).limit_le
l).trans
?_
dsimp only [Function.comp_def]
simp +contextual only [IH]
exact (opow_le_of_limit (opow_ne_zero _ a0) l).symm
theorem opow_mul_add_pos {b v : Ordinal} (hb : b ≠ 0) (u : Ordinal) (hv : v ≠ 0) (w : Ordinal) :
0 < b ^ u * v + w :=
(opow_pos u <| Ordinal.pos_iff_ne_zero.2 hb).trans_le <|
(le_mul_left _ <| Ordinal.pos_iff_ne_zero.2 hv).trans <| le_add_right _ _
theorem opow_mul_add_lt_opow_mul_succ {b u w : Ordinal} (v : Ordinal) (hw : w < b ^ u) :
b ^ u * v + w < b ^ u * succ v := by
rwa [mul_succ, add_lt_add_iff_left]
theorem opow_mul_add_lt_opow_succ {b u v w : Ordinal} (hvb : v < b) (hw : w < b ^ u) :
b ^ u * v + w < b ^ succ u := by
convert (opow_mul_add_lt_opow_mul_succ v hw).trans_le
(mul_le_mul_left' (succ_le_of_lt hvb) _) using 1
exact opow_succ b u
/-! ### Ordinal logarithm -/
/-- The ordinal logarithm is the solution `u` to the equation `x = b ^ u * v + w` where `v < b` and
`w < b ^ u`. -/
@[pp_nodot]
def log (b : Ordinal) (x : Ordinal) : Ordinal :=
if 1 < b then pred (sInf { o | x < b ^ o }) else 0
/-- The set in the definition of `log` is nonempty. -/
private theorem log_nonempty {b x : Ordinal} (h : 1 < b) : { o : Ordinal | x < b ^ o }.Nonempty :=
⟨_, succ_le_iff.1 (right_le_opow _ h)⟩
theorem log_def {b : Ordinal} (h : 1 < b) (x : Ordinal) : log b x = pred (sInf { o | x < b ^ o }) :=
if_pos h
theorem log_of_left_le_one {b : Ordinal} (h : b ≤ 1) (x : Ordinal) : log b x = 0 :=
if_neg h.not_lt
@[simp]
theorem log_zero_left : ∀ b, log 0 b = 0 :=
log_of_left_le_one zero_le_one
@[simp]
theorem log_zero_right (b : Ordinal) : log b 0 = 0 := by
obtain hb | hb := lt_or_le 1 b
· rw [log_def hb, ← Ordinal.le_zero, pred_le, succ_zero]
apply csInf_le'
rw [mem_setOf, opow_one]
exact bot_lt_of_lt hb
· rw [log_of_left_le_one hb]
@[simp]
theorem log_one_left : ∀ b, log 1 b = 0 :=
log_of_left_le_one le_rfl
theorem succ_log_def {b x : Ordinal} (hb : 1 < b) (hx : x ≠ 0) :
succ (log b x) = sInf { o : Ordinal | x < b ^ o } := by
let t := sInf { o : Ordinal | x < b ^ o }
have : x < b ^ t := csInf_mem (log_nonempty hb)
rcases zero_or_succ_or_limit t with (h | h | h)
· refine ((one_le_iff_ne_zero.2 hx).not_lt ?_).elim
simpa only [h, opow_zero] using this
· rw [show log b x = pred t from log_def hb x, succ_pred_iff_is_succ.2 h]
· rcases (lt_opow_of_limit (zero_lt_one.trans hb).ne' h).1 this with ⟨a, h₁, h₂⟩
exact h₁.not_le.elim ((le_csInf_iff'' (log_nonempty hb)).1 le_rfl a h₂)
theorem lt_opow_succ_log_self {b : Ordinal} (hb : 1 < b) (x : Ordinal) :
x < b ^ succ (log b x) := by
rcases eq_or_ne x 0 with (rfl | hx)
· apply opow_pos _ (zero_lt_one.trans hb)
· rw [succ_log_def hb hx]
exact csInf_mem (log_nonempty hb)
theorem opow_log_le_self (b : Ordinal) {x : Ordinal} (hx : x ≠ 0) : b ^ log b x ≤ x := by
rcases eq_or_ne b 0 with (rfl | b0)
· exact (zero_opow_le _).trans (one_le_iff_ne_zero.2 hx)
rcases lt_or_eq_of_le (one_le_iff_ne_zero.2 b0) with (hb | rfl)
· refine le_of_not_lt fun h => (lt_succ (log b x)).not_le ?_
have := @csInf_le' _ _ { o | x < b ^ o } _ h
rwa [← succ_log_def hb hx] at this
· rwa [one_opow, one_le_iff_ne_zero]
/-- `opow b` and `log b` (almost) form a Galois connection.
See `opow_le_iff_le_log'` for a variant assuming `c ≠ 0` rather than `x ≠ 0`. See also
`le_log_of_opow_le` and `opow_le_of_le_log`, which are both separate implications under weaker
assumptions. -/
theorem opow_le_iff_le_log {b x c : Ordinal} (hb : 1 < b) (hx : x ≠ 0) :
b ^ c ≤ x ↔ c ≤ log b x := by
constructor <;>
intro h
· apply le_of_not_lt
intro hn
apply (lt_opow_succ_log_self hb x).not_le <|
((opow_le_opow_iff_right hb).2 <| succ_le_of_lt hn).trans h
· exact ((opow_le_opow_iff_right hb).2 h).trans <| opow_log_le_self b hx
/-- `opow b` and `log b` (almost) form a Galois connection.
See `opow_le_iff_le_log` for a variant assuming `x ≠ 0` rather than `c ≠ 0`. See also
`le_log_of_opow_le` and `opow_le_of_le_log`, which are both separate implications under weaker
assumptions. -/
theorem opow_le_iff_le_log' {b x c : Ordinal} (hb : 1 < b) (hc : c ≠ 0) :
b ^ c ≤ x ↔ c ≤ log b x := by
obtain rfl | hx := eq_or_ne x 0
· rw [log_zero_right, Ordinal.le_zero, Ordinal.le_zero, opow_eq_zero]
simp [hc, (zero_lt_one.trans hb).ne']
· exact opow_le_iff_le_log hb hx
theorem le_log_of_opow_le {b x c : Ordinal} (hb : 1 < b) (h : b ^ c ≤ x) : c ≤ log b x := by
obtain rfl | hx := eq_or_ne x 0
· rw [Ordinal.le_zero, opow_eq_zero] at h
exact (zero_lt_one.asymm <| h.1 ▸ hb).elim
· exact (opow_le_iff_le_log hb hx).1 h
theorem opow_le_of_le_log {b x c : Ordinal} (hc : c ≠ 0) (h : c ≤ log b x) : b ^ c ≤ x := by
obtain hb | hb := le_or_lt b 1
· rw [log_of_left_le_one hb] at h
exact (h.not_lt (Ordinal.pos_iff_ne_zero.2 hc)).elim
· rwa [opow_le_iff_le_log' hb hc]
/-- `opow b` and `log b` (almost) form a Galois connection.
See `lt_opow_iff_log_lt'` for a variant assuming `c ≠ 0` rather than `x ≠ 0`. See also
`lt_opow_of_log_lt` and `lt_log_of_lt_opow`, which are both separate implications under weaker
assumptions. -/
theorem lt_opow_iff_log_lt {b x c : Ordinal} (hb : 1 < b) (hx : x ≠ 0) : x < b ^ c ↔ log b x < c :=
lt_iff_lt_of_le_iff_le (opow_le_iff_le_log hb hx)
/-- `opow b` and `log b` (almost) form a Galois connection.
See `lt_opow_iff_log_lt` for a variant assuming `x ≠ 0` rather than `c ≠ 0`. See also
`lt_opow_of_log_lt` and `lt_log_of_lt_opow`, which are both separate implications under weaker
assumptions. -/
| theorem lt_opow_iff_log_lt' {b x c : Ordinal} (hb : 1 < b) (hc : c ≠ 0) : x < b ^ c ↔ log b x < c :=
lt_iff_lt_of_le_iff_le (opow_le_iff_le_log' hb hc)
theorem lt_opow_of_log_lt {b x c : Ordinal} (hb : 1 < b) : log b x < c → x < b ^ c :=
| Mathlib/SetTheory/Ordinal/Exponential.lean | 379 | 382 |
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.Algebra.Polynomial.Lifts
import Mathlib.FieldTheory.Minpoly.Basic
import Mathlib.RingTheory.Algebraic.Integral
import Mathlib.RingTheory.LocalRing.Basic
/-!
# Minimal polynomials on an algebra over a field
This file specializes the theory of minpoly to the setting of field extensions
and derives some well-known properties, amongst which the fact that minimal polynomials
are irreducible, and uniquely determined by their defining property.
-/
open Polynomial Set Function minpoly
namespace minpoly
variable {A B : Type*}
variable (A) [Field A]
section Ring
variable [Ring B] [Algebra A B] (x : B)
/-- If an element `x` is a root of a nonzero polynomial `p`, then the degree of `p` is at least the
degree of the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.degree_le_of_ne_zero`
which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/
theorem degree_le_of_ne_zero {p : A[X]} (pnz : p ≠ 0) (hp : Polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p :=
calc
degree (minpoly A x) ≤ degree (p * C (leadingCoeff p)⁻¹) :=
min A x (monic_mul_leadingCoeff_inv pnz) (by simp [hp])
_ = degree p := degree_mul_leadingCoeff_inv p pnz
theorem ne_zero_of_finite (e : B) [FiniteDimensional A B] : minpoly A e ≠ 0 :=
minpoly.ne_zero <| .of_finite A _
/-- The minimal polynomial of an element `x` is uniquely characterized by its defining property:
if there is another monic polynomial of minimal degree that has `x` as a root, then this polynomial
is equal to the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.Minpoly.unique`
which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/
theorem unique {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0)
(pmin : ∀ q : A[X], q.Monic → Polynomial.aeval x q = 0 → degree p ≤ degree q) :
p = minpoly A x := by
have hx : IsIntegral A x := ⟨p, pmonic, hp⟩
symm; apply eq_of_sub_eq_zero
by_contra hnz
apply degree_le_of_ne_zero A x hnz (by simp [hp]) |>.not_lt
apply degree_sub_lt _ (minpoly.ne_zero hx)
· rw [(monic hx).leadingCoeff, pmonic.leadingCoeff]
· exact le_antisymm (min A x pmonic hp) (pmin (minpoly A x) (monic hx) (aeval A x))
/-- If an element `x` is a root of a polynomial `p`, then the minimal polynomial of `x` divides `p`.
See also `minpoly.isIntegrallyClosed_dvd` which relaxes the assumptions on `A` in exchange for
stronger assumptions on `B`. -/
theorem dvd {p : A[X]} (hp : Polynomial.aeval x p = 0) : minpoly A x ∣ p := by
by_cases hp0 : p = 0
· simp only [hp0, dvd_zero]
have hx : IsIntegral A x := IsAlgebraic.isIntegral ⟨p, hp0, hp⟩
rw [← modByMonic_eq_zero_iff_dvd (monic hx)]
by_contra hnz
apply degree_le_of_ne_zero A x hnz
((aeval_modByMonic_eq_self_of_root (monic hx) (aeval _ _)).trans hp) |>.not_lt
exact degree_modByMonic_lt _ (monic hx)
variable {A x} in
lemma dvd_iff {p : A[X]} : minpoly A x ∣ p ↔ Polynomial.aeval x p = 0 :=
⟨fun ⟨q, hq⟩ ↦ by rw [hq, map_mul, aeval, zero_mul], minpoly.dvd A x⟩
theorem isRadical [IsReduced B] : IsRadical (minpoly A x) := fun n p dvd ↦ by
rw [dvd_iff] at dvd ⊢; rw [map_pow] at dvd; exact IsReduced.eq_zero _ ⟨n, dvd⟩
|
theorem dvd_map_of_isScalarTower (A K : Type*) {R : Type*} [CommRing A] [Field K] [Ring R]
| Mathlib/FieldTheory/Minpoly/Field.lean | 80 | 81 |
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Nat.PSub
import Mathlib.Data.Nat.Size
import Mathlib.Data.Num.Bitwise
/-!
# Properties of the binary representation of integers
-/
open Int
attribute [local simp] add_assoc
namespace PosNum
variable {α : Type*}
@[simp, norm_cast]
theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 :=
rfl
@[simp]
theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 :=
rfl
@[simp, norm_cast]
theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = (n : α) + n :=
rfl
@[simp, norm_cast]
theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = ((n : α) + n) + 1 :=
rfl
@[simp, norm_cast]
theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n
| 1 => Nat.cast_one
| bit0 p => by dsimp; rw [Nat.cast_add, p.cast_to_nat]
| bit1 p => by dsimp; rw [Nat.cast_add, Nat.cast_add, Nat.cast_one, p.cast_to_nat]
@[norm_cast]
theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n :=
cast_to_nat _
@[simp, norm_cast]
theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by
rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat]
theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1
| 1 => rfl
| bit0 _ => rfl
| bit1 p =>
(congr_arg (fun n ↦ n + n) (succ_to_nat p)).trans <|
show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm]
theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl
theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl
@[norm_cast]
theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n
| 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one]
| a, 1 => by rw [add_one a, succ_to_nat, cast_one]
| bit0 a, bit0 b => (congr_arg (fun n ↦ n + n) (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _
| bit0 a, bit1 b =>
(congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <|
show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm]
| bit1 a, bit0 b =>
(congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <|
show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm]
| bit1 a, bit1 b =>
show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by
rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm]
theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n)
| 1, b => by simp [one_add]
| bit0 a, 1 => congr_arg bit0 (add_one a)
| bit1 a, 1 => congr_arg bit1 (add_one a)
| bit0 _, bit0 _ => rfl
| bit0 a, bit1 b => congr_arg bit0 (add_succ a b)
| bit1 _, bit0 _ => rfl
| bit1 a, bit1 b => congr_arg bit1 (add_succ a b)
theorem bit0_of_bit0 : ∀ n, n + n = bit0 n
| 1 => rfl
| bit0 p => congr_arg bit0 (bit0_of_bit0 p)
| bit1 p => show bit0 (succ (p + p)) = _ by rw [bit0_of_bit0 p, succ]
theorem bit1_of_bit1 (n : PosNum) : (n + n) + 1 = bit1 n :=
show (n + n) + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ]
@[norm_cast]
theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n
| 1 => (mul_one _).symm
| bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib]
| bit1 p =>
(add_to_nat (bit0 (m * p)) m).trans <|
show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib]
theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ)
| 1 => Nat.zero_lt_one
| bit0 p =>
let h := to_nat_pos p
add_pos h h
| bit1 _p => Nat.succ_pos _
theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n :=
show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by
intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h
theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by
induction' m with m IH m IH <;> intro n <;> obtain - | n | n := n <;> unfold cmp <;>
try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl
theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop)
| 1, 1 => rfl
| bit0 a, 1 =>
let h : (1 : ℕ) ≤ a := to_nat_pos a
Nat.add_le_add h h
| bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a
| 1, bit0 b =>
let h : (1 : ℕ) ≤ b := to_nat_pos b
Nat.add_le_add h h
| 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b
| bit0 a, bit0 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.add_lt_add this this
· rw [this]
· exact Nat.add_lt_add this this
| bit0 a, bit1 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.le_succ_of_le (Nat.add_lt_add this this)
· rw [this]
apply Nat.lt_succ_self
· exact cmp_to_nat_lemma this
| bit1 a, bit0 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact cmp_to_nat_lemma this
· rw [this]
apply Nat.lt_succ_self
· exact Nat.le_succ_of_le (Nat.add_lt_add this this)
| bit1 a, bit1 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.succ_lt_succ (Nat.add_lt_add this this)
· rw [this]
· exact Nat.succ_lt_succ (Nat.add_lt_add this this)
@[norm_cast]
theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n :=
show (m : ℕ) < n ↔ cmp m n = Ordering.lt from
match cmp m n, cmp_to_nat m n with
| Ordering.lt, h => by simp only at h; simp [h]
| Ordering.eq, h => by simp only at h; simp [h, lt_irrefl]
| Ordering.gt, h => by simp [not_lt_of_gt h]
@[norm_cast]
theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr lt_to_nat
end PosNum
namespace Num
variable {α : Type*}
open PosNum
theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl
theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl
theorem add_one : ∀ n : Num, n + 1 = succ n
| 0 => rfl
| pos p => by cases p <;> rfl
theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n)
| 0, n => by simp [zero_add]
| pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ']
| pos _, pos _ => congr_arg pos (PosNum.add_succ _ _)
theorem bit0_of_bit0 : ∀ n : Num, n + n = n.bit0
| 0 => rfl
| pos p => congr_arg pos p.bit0_of_bit0
theorem bit1_of_bit1 : ∀ n : Num, (n + n) + 1 = n.bit1
| 0 => rfl
| pos p => congr_arg pos p.bit1_of_bit1
@[simp]
theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat']
theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) :=
Nat.binaryRec_eq _ _ (.inl rfl)
@[simp]
theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl
theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0
| 0 => rfl
| pos _n => rfl
theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 :=
@(Nat.binaryRec (by simp [zero_add]) fun b n ih => by
cases b
· erw [ofNat'_bit true n, ofNat'_bit]
simp only [← bit1_of_bit1, ← bit0_of_bit0, cond]
· rw [show n.bit true + 1 = (n + 1).bit false by simp [Nat.bit, mul_add],
ofNat'_bit, ofNat'_bit, ih]
simp only [cond, add_one, bit1_succ])
@[simp]
theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by
induction n
· simp only [Nat.add_zero, ofNat'_zero, add_zero]
· simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *]
@[simp, norm_cast]
theorem cast_zero [Zero α] [One α] [Add α] : ((0 : Num) : α) = 0 :=
rfl
@[simp]
theorem cast_zero' [Zero α] [One α] [Add α] : (Num.zero : α) = 0 :=
rfl
@[simp, norm_cast]
theorem cast_one [Zero α] [One α] [Add α] : ((1 : Num) : α) = 1 :=
rfl
@[simp]
theorem cast_pos [Zero α] [One α] [Add α] (n : PosNum) : (Num.pos n : α) = n :=
rfl
theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1
| 0 => (Nat.zero_add _).symm
| pos _p => PosNum.succ_to_nat _
theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 :=
succ'_to_nat n
@[simp, norm_cast]
theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : Num, ((n : ℕ) : α) = n
| 0 => Nat.cast_zero
| pos p => p.cast_to_nat
@[norm_cast]
theorem add_to_nat : ∀ m n, ((m + n : Num) : ℕ) = m + n
| 0, 0 => rfl
| 0, pos _q => (Nat.zero_add _).symm
| pos _p, 0 => rfl
| pos _p, pos _q => PosNum.add_to_nat _ _
@[norm_cast]
theorem mul_to_nat : ∀ m n, ((m * n : Num) : ℕ) = m * n
| 0, 0 => rfl
| 0, pos _q => (zero_mul _).symm
| pos _p, 0 => rfl
| pos _p, pos _q => PosNum.mul_to_nat _ _
theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop)
| 0, 0 => rfl
| 0, pos _ => to_nat_pos _
| pos _, 0 => to_nat_pos _
| pos a, pos b => by
have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b
exacts [id, congr_arg pos, id]
@[norm_cast]
theorem lt_to_nat {m n : Num} : (m : ℕ) < n ↔ m < n :=
show (m : ℕ) < n ↔ cmp m n = Ordering.lt from
match cmp m n, cmp_to_nat m n with
| Ordering.lt, h => by simp only at h; simp [h]
| Ordering.eq, h => by simp only at h; simp [h, lt_irrefl]
| Ordering.gt, h => by simp [not_lt_of_gt h]
@[norm_cast]
theorem le_to_nat {m n : Num} : (m : ℕ) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr lt_to_nat
end Num
namespace PosNum
@[simp]
theorem of_to_nat' : ∀ n : PosNum, Num.ofNat' (n : ℕ) = Num.pos n
| 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl
| bit0 p => by
simpa only [Nat.bit_false, cond_false, two_mul, of_to_nat' p] using Num.ofNat'_bit false p
| bit1 p => by
simpa only [Nat.bit_true, cond_true, two_mul, of_to_nat' p] using Num.ofNat'_bit true p
end PosNum
namespace Num
@[simp, norm_cast]
theorem of_to_nat' : ∀ n : Num, Num.ofNat' (n : ℕ) = n
| 0 => ofNat'_zero
| pos p => p.of_to_nat'
lemma toNat_injective : Function.Injective (castNum : Num → ℕ) :=
Function.LeftInverse.injective of_to_nat'
@[norm_cast]
theorem to_nat_inj {m n : Num} : (m : ℕ) = n ↔ m = n := toNat_injective.eq_iff
/-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting.
```lean
example (n : Num) (m : Num) : n ≤ n + m := by
transfer_rw
exact Nat.le_add_right _ _
```
-/
scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic|
(repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat]
repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero]))
/--
This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and
then trying to call `simp`.
```lean
example (n : Num) (m : Num) : n ≤ n + m := by transfer
```
-/
scoped macro (name := transfer) "transfer" : tactic => `(tactic|
(intros; transfer_rw; try simp))
instance addMonoid : AddMonoid Num where
add := (· + ·)
zero := 0
zero_add := zero_add
add_zero := add_zero
add_assoc := by transfer
nsmul := nsmulRec
instance addMonoidWithOne : AddMonoidWithOne Num :=
{ Num.addMonoid with
natCast := Num.ofNat'
one := 1
natCast_zero := ofNat'_zero
natCast_succ := fun _ => ofNat'_succ }
instance commSemiring : CommSemiring Num where
__ := Num.addMonoid
__ := Num.addMonoidWithOne
mul := (· * ·)
npow := @npowRec Num ⟨1⟩ ⟨(· * ·)⟩
mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero]
zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul]
mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one]
one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul]
add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm]
mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm]
mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc]
left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add]
right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul]
instance partialOrder : PartialOrder Num where
lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le]
le_refl := by transfer
le_trans a b c := by transfer_rw; apply le_trans
le_antisymm a b := by transfer_rw; apply le_antisymm
instance isOrderedCancelAddMonoid : IsOrderedCancelAddMonoid Num where
add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c
le_of_add_le_add_left a b c :=
show a + b ≤ a + c → b ≤ c by transfer_rw; apply le_of_add_le_add_left
instance linearOrder : LinearOrder Num :=
{ le_total := by
intro a b
transfer_rw
apply le_total
toDecidableLT := Num.decidableLT
toDecidableLE := Num.decidableLE
-- This is relying on an automatically generated instance name,
-- generated in a `deriving` handler.
-- See https://github.com/leanprover/lean4/issues/2343
toDecidableEq := instDecidableEqNum }
instance isStrictOrderedRing : IsStrictOrderedRing Num :=
{ zero_le_one := by decide
mul_lt_mul_of_pos_left := by
intro a b c
transfer_rw
apply mul_lt_mul_of_pos_left
mul_lt_mul_of_pos_right := by
intro a b c
transfer_rw
apply mul_lt_mul_of_pos_right
exists_pair_ne := ⟨0, 1, by decide⟩ }
@[norm_cast]
theorem add_of_nat (m n) : ((m + n : ℕ) : Num) = m + n :=
add_ofNat' _ _
@[norm_cast]
theorem to_nat_to_int (n : Num) : ((n : ℕ) : ℤ) = n :=
cast_to_nat _
@[simp, norm_cast]
theorem cast_to_int {α} [AddGroupWithOne α] (n : Num) : ((n : ℤ) : α) = n := by
rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat]
theorem to_of_nat : ∀ n : ℕ, ((n : Num) : ℕ) = n
| 0 => by rw [Nat.cast_zero, cast_zero]
| n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n]
@[simp, norm_cast]
theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by
rw [← cast_to_nat, to_of_nat]
@[norm_cast]
theorem of_nat_inj {m n : ℕ} : (m : Num) = n ↔ m = n :=
⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩
-- The priority should be `high`er than `cast_to_nat`.
@[simp high, norm_cast]
theorem of_to_nat : ∀ n : Num, ((n : ℕ) : Num) = n :=
of_to_nat'
@[norm_cast]
theorem dvd_to_nat (m n : Num) : (m : ℕ) ∣ n ↔ m ∣ n :=
⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩
end Num
namespace PosNum
variable {α : Type*}
open Num
-- The priority should be `high`er than `cast_to_nat`.
@[simp high, norm_cast]
theorem of_to_nat : ∀ n : PosNum, ((n : ℕ) : Num) = Num.pos n :=
of_to_nat'
@[norm_cast]
theorem to_nat_inj {m n : PosNum} : (m : ℕ) = n ↔ m = n :=
⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩
theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = Nat.pred n
| 1 => rfl
| bit0 n =>
have : Nat.succ ↑(pred' n) = ↑n := by
rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)]
match (motive :=
∀ k : Num, Nat.succ ↑k = ↑n → ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (n + n))
pred' n, this with
| 0, (h : ((1 : Num) : ℕ) = n) => by rw [← to_nat_inj.1 h]; rfl
| Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm
| bit1 _ => rfl
@[simp]
theorem pred'_succ' (n) : pred' (succ' n) = n :=
Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ]
@[simp]
theorem succ'_pred' (n) : succ' (pred' n) = n :=
to_nat_inj.1 <| by
rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)]
instance dvd : Dvd PosNum :=
⟨fun m n => pos m ∣ pos n⟩
@[norm_cast]
theorem dvd_to_nat {m n : PosNum} : (m : ℕ) ∣ n ↔ m ∣ n :=
Num.dvd_to_nat (pos m) (pos n)
theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n
| 1 => Nat.size_one.symm
| bit0 n => by
rw [size, succ_to_nat, size_to_nat n, cast_bit0, ← two_mul]
erw [@Nat.size_bit false n]
have := to_nat_pos n
dsimp [Nat.bit]; omega
| bit1 n => by
rw [size, succ_to_nat, size_to_nat n, cast_bit1, ← two_mul]
erw [@Nat.size_bit true n]
dsimp [Nat.bit]; omega
theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n
| 1 => rfl
| bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n]
| bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n]
theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat]
theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos
/-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting.
```lean
example (n : PosNum) (m : PosNum) : n ≤ n + m := by
transfer_rw
exact Nat.le_add_right _ _
```
-/
scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic|
(repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat]
repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero]))
/--
This tactic tries to prove (in)equalities about `PosNum`s by transferring them to the `Nat` world
and then trying to call `simp`.
```lean
example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer
```
-/
scoped macro (name := transfer) "transfer" : tactic => `(tactic|
(intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm]))
instance addCommSemigroup : AddCommSemigroup PosNum where
add := (· + ·)
add_assoc := by transfer
add_comm := by transfer
instance commMonoid : CommMonoid PosNum where
mul := (· * ·)
one := (1 : PosNum)
npow := @npowRec PosNum ⟨1⟩ ⟨(· * ·)⟩
mul_assoc := by transfer
one_mul := by transfer
mul_one := by transfer
mul_comm := by transfer
instance distrib : Distrib PosNum where
add := (· + ·)
mul := (· * ·)
left_distrib := by transfer; simp [mul_add]
right_distrib := by transfer; simp [mul_add, mul_comm]
instance linearOrder : LinearOrder PosNum where
lt := (· < ·)
lt_iff_le_not_le := by
intro a b
transfer_rw
apply lt_iff_le_not_le
le := (· ≤ ·)
le_refl := by transfer
le_trans := by
intro a b c
transfer_rw
apply le_trans
le_antisymm := by
intro a b
transfer_rw
apply le_antisymm
le_total := by
intro a b
transfer_rw
apply le_total
toDecidableLT := by infer_instance
toDecidableLE := by infer_instance
toDecidableEq := by infer_instance
@[simp]
theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n]
@[simp, norm_cast]
theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> simp [bit, two_mul]
@[simp, norm_cast]
theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : PosNum) : α) = m + n := by
rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat]
@[simp 500, norm_cast]
theorem cast_succ [AddMonoidWithOne α] (n : PosNum) : (succ n : α) = n + 1 := by
rw [← add_one, cast_add, cast_one]
@[simp, norm_cast]
theorem cast_inj [AddMonoidWithOne α] [CharZero α] {m n : PosNum} : (m : α) = n ↔ m = n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj]
@[simp]
theorem one_le_cast [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) :
(1 : α) ≤ n := by
rw [← cast_to_nat, ← Nat.cast_one, Nat.cast_le (α := α)]; apply to_nat_pos
@[simp]
theorem cast_pos [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) : 0 < (n : α) :=
lt_of_lt_of_le zero_lt_one (one_le_cast n)
@[simp, norm_cast]
theorem cast_mul [NonAssocSemiring α] (m n) : ((m * n : PosNum) : α) = m * n := by
rw [← cast_to_nat, mul_to_nat, Nat.cast_mul, cast_to_nat, cast_to_nat]
@[simp]
theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by
have := cmp_to_nat m n
-- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required.
revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;>
simp [show m ≠ n from fun e => by rw [e] at this;exact lt_irrefl _ this]
@[simp, norm_cast]
theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : PosNum} :
(m : α) < n ↔ m < n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat]
@[simp, norm_cast]
theorem cast_le [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {m n : PosNum} :
(m : α) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr cast_lt
end PosNum
namespace Num
variable {α : Type*}
open PosNum
theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by
cases b <;> cases n <;> simp [bit, two_mul] <;> rfl
theorem cast_succ' [AddMonoidWithOne α] (n) : (succ' n : α) = n + 1 := by
rw [← PosNum.cast_to_nat, succ'_to_nat, Nat.cast_add_one, cast_to_nat]
theorem cast_succ [AddMonoidWithOne α] (n) : (succ n : α) = n + 1 :=
cast_succ' n
@[simp, norm_cast]
theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : Num) : α) = m + n := by
rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat]
@[simp, norm_cast]
theorem cast_bit0 [NonAssocSemiring α] (n : Num) : (n.bit0 : α) = 2 * (n : α) := by
rw [← bit0_of_bit0, two_mul, cast_add]
@[simp, norm_cast]
theorem cast_bit1 [NonAssocSemiring α] (n : Num) : (n.bit1 : α) = 2 * (n : α) + 1 := by
rw [← bit1_of_bit1, bit0_of_bit0, cast_add, cast_bit0]; rfl
@[simp, norm_cast]
theorem cast_mul [NonAssocSemiring α] : ∀ m n, ((m * n : Num) : α) = m * n
| 0, 0 => (zero_mul _).symm
| 0, pos _q => (zero_mul _).symm
| pos _p, 0 => (mul_zero _).symm
| pos _p, pos _q => PosNum.cast_mul _ _
theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n
| 0 => Nat.size_zero.symm
| pos p => p.size_to_nat
theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n
| 0 => rfl
| pos p => p.size_eq_natSize
theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat]
@[simp 999]
theorem ofNat'_eq : ∀ n, Num.ofNat' n = n :=
Nat.binaryRec (by simp) fun b n IH => by tauto
theorem zneg_toZNum (n : Num) : -n.toZNum = n.toZNumNeg := by cases n <;> rfl
theorem zneg_toZNumNeg (n : Num) : -n.toZNumNeg = n.toZNum := by cases n <;> rfl
theorem toZNum_inj {m n : Num} : m.toZNum = n.toZNum ↔ m = n :=
⟨fun h => by cases m <;> cases n <;> cases h <;> rfl, congr_arg _⟩
@[simp]
theorem cast_toZNum [Zero α] [One α] [Add α] [Neg α] : ∀ n : Num, (n.toZNum : α) = n
| 0 => rfl
| Num.pos _p => rfl
@[simp]
theorem cast_toZNumNeg [SubtractionMonoid α] [One α] : ∀ n : Num, (n.toZNumNeg : α) = -n
| 0 => neg_zero.symm
| Num.pos _p => rfl
@[simp]
theorem add_toZNum (m n : Num) : Num.toZNum (m + n) = m.toZNum + n.toZNum := by
cases m <;> cases n <;> rfl
end Num
namespace PosNum
open Num
theorem pred_to_nat {n : PosNum} (h : 1 < n) : (pred n : ℕ) = Nat.pred n := by
unfold pred
cases e : pred' n
· have : (1 : ℕ) ≤ Nat.pred n := Nat.pred_le_pred ((@cast_lt ℕ _ _ _).2 h)
rw [← pred'_to_nat, e] at this
exact absurd this (by decide)
· rw [← pred'_to_nat, e]
rfl
theorem sub'_one (a : PosNum) : sub' a 1 = (pred' a).toZNum := by cases a <;> rfl
theorem one_sub' (a : PosNum) : sub' 1 a = (pred' a).toZNumNeg := by cases a <;> rfl
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt :=
Iff.rfl
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt :=
not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide
end PosNum
namespace Num
variable {α : Type*}
open PosNum
theorem pred_to_nat : ∀ n : Num, (pred n : ℕ) = Nat.pred n
| 0 => rfl
| pos p => by rw [pred, PosNum.pred'_to_nat]; rfl
theorem ppred_to_nat : ∀ n : Num, (↑) <$> ppred n = Nat.ppred n
| 0 => rfl
| pos p => by
rw [ppred, Option.map_some, Nat.ppred_eq_some.2]
rw [PosNum.pred'_to_nat, Nat.succ_pred_eq_of_pos (PosNum.to_nat_pos _)]
rfl
theorem cmp_swap (m n) : (cmp m n).swap = cmp n m := by
cases m <;> cases n <;> try { rfl }; apply PosNum.cmp_swap
theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by
have := cmp_to_nat m n
-- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required.
revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;>
simp [show m ≠ n from fun e => by rw [e] at this; exact lt_irrefl _ this]
@[simp, norm_cast]
theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : Num} :
(m : α) < n ↔ m < n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat]
@[simp, norm_cast]
theorem cast_le [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {m n : Num} :
(m : α) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr cast_lt
@[simp, norm_cast]
theorem cast_inj [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : Num} :
(m : α) = n ↔ m = n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj]
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt :=
Iff.rfl
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt :=
not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide
theorem castNum_eq_bitwise {f : Num → Num → Num} {g : Bool → Bool → Bool}
(p : PosNum → PosNum → Num)
(gff : g false false = false) (f00 : f 0 0 = 0)
(f0n : ∀ n, f 0 (pos n) = cond (g false true) (pos n) 0)
(fn0 : ∀ n, f (pos n) 0 = cond (g true false) (pos n) 0)
(fnn : ∀ m n, f (pos m) (pos n) = p m n) (p11 : p 1 1 = cond (g true true) 1 0)
(p1b : ∀ b n, p 1 (PosNum.bit b n) = bit (g true b) (cond (g false true) (pos n) 0))
(pb1 : ∀ a m, p (PosNum.bit a m) 1 = bit (g a true) (cond (g true false) (pos m) 0))
(pbb : ∀ a b m n, p (PosNum.bit a m) (PosNum.bit b n) = bit (g a b) (p m n)) :
∀ m n : Num, (f m n : ℕ) = Nat.bitwise g m n := by
intros m n
| obtain - | m := m <;> obtain - | n := n <;>
| Mathlib/Data/Num/Lemmas.lean | 771 | 771 |
/-
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
| Mathlib/Algebra/Polynomial/Basic.lean | 414 | 414 | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInf₂ fun i hi => ?_
calc
edist x y ≤ edist x i + edist i y := edist_triangle _ _ _
_ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff]
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_
have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 :=
ENNReal.lt_add_right h.ne ε0.ne'
obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ :=
infEdist_lt_iff.mp this
obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0
calc
infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves]
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 :=
⟨fun h => by
rw [← infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by
rw [← mem_closure_iff_infEdist_zero, h.closure_eq]
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x E ↔ x ∉ closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x (closure E) ↔ x ∉ closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) :
∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by
rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩
exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩
theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y
_ ≤ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
/-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
@[to_additive (attr := simp)]
| theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) :
infEdist (c • x) (c • s) = infEdist x s :=
infEdist_image (isometry_smul _ _)
theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) :
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 196 | 200 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yakov Pechersky
-/
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Infix
import Mathlib.Data.Quot
/-!
# List rotation
This file proves basic results about `List.rotate`, the list rotation.
## Main declarations
* `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`.
* `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`.
## Tags
rotated, rotation, permutation, cycle
-/
universe u
variable {α : Type u}
open Nat Function
namespace List
theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate]
@[simp]
theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate]
@[simp]
theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate]
theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by simp
@[simp]
theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl
theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) :
(a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate']
@[simp]
theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length
| [], _ => by simp
| _ :: _, 0 => rfl
| a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp
theorem rotate'_eq_drop_append_take :
∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n
| [], n, h => by simp [drop_append_of_le_length h]
| l, 0, h => by simp [take_append_of_le_length h]
| a :: l, n + 1, h => by
have hnl : n ≤ l.length := le_of_succ_le_succ h
have hnl' : n ≤ (l ++ [a]).length := by
rw [length_append, length_cons, List.length]; exact le_of_succ_le h
rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take,
drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp
theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m)
| a :: l, 0, m => by simp
| [], n, m => by simp
| a :: l, n + 1, m => by
rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ,
Nat.succ_eq_add_one]
@[simp]
theorem rotate'_length (l : List α) : rotate' l l.length = l := by
rw [rotate'_eq_drop_append_take le_rfl]; simp
@[simp]
theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l
| 0 => by simp
| n + 1 =>
calc
l.rotate' (l.length * (n + 1)) =
(l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by
simp [-rotate'_length, Nat.mul_succ, rotate'_rotate']
_ = l := by rw [rotate'_length, rotate'_length_mul l n]
| theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n :=
calc
| Mathlib/Data/List/Rotate.lean | 88 | 89 |
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Kim Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.Limits.IsLimit
import Mathlib.CategoryTheory.Category.ULift
import Mathlib.CategoryTheory.EssentiallySmall
import Mathlib.CategoryTheory.Functor.EpiMono
import Mathlib.Logic.Equiv.Basic
/-!
# Existence of limits and colimits
In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`,
the data showing that a cone `c` is a limit cone.
The two main structures defined in this file are:
* `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and
* `HasLimit F`, asserting the mere existence of some limit cone for `F`.
`HasLimit` is a propositional typeclass
(it's important that it is a proposition merely asserting the existence of a limit,
as otherwise we would have non-defeq problems from incompatible instances).
While `HasLimit` only asserts the existence of a limit cone,
we happily use the axiom of choice in mathlib,
so there are convenience functions all depending on `HasLimit F`:
* `limit F : C`, producing some limit object (of course all such are isomorphic)
* `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit,
* `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc.
Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that
to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j`
for every `j`.
This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using
automation (e.g. `tidy`).
There are abbreviations `HasLimitsOfShape J C` and `HasLimits C`
asserting the existence of classes of limits.
Later more are introduced, for finite limits, special shapes of limits, etc.
Ideally, many results about limits should be stated first in terms of `IsLimit`,
and then a result in terms of `HasLimit` derived from this.
At this point, however, this is far from uniformly achieved in mathlib ---
often statements are only written in terms of `HasLimit`.
## Implementation
At present we simply say everything twice, in order to handle both limits and colimits.
It would be highly desirable to have some automation support,
e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`.
## References
* [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D)
-/
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite
namespace CategoryTheory.Limits
-- morphism levels before object levels. See note [CategoryTheory universes].
universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u''
variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K]
variable {C : Type u} [Category.{v} C]
variable {F : J ⥤ C}
section Limit
/-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/
structure LimitCone (F : J ⥤ C) where
/-- The cone itself -/
cone : Cone F
/-- The proof that is the limit cone -/
isLimit : IsLimit cone
/-- `HasLimit F` represents the mere existence of a limit for `F`. -/
class HasLimit (F : J ⥤ C) : Prop where mk' ::
/-- There is some limit cone for `F` -/
exists_limit : Nonempty (LimitCone F)
theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F :=
⟨Nonempty.intro d⟩
/-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/
def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F :=
Classical.choice <| HasLimit.exists_limit
variable (J C)
/-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/
class HasLimitsOfShape : Prop where
/-- All functors `F : J ⥤ C` from `J` have limits -/
has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance
/-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`)
if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`.
-/
@[pp_with_univ]
class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where
/-- All functors `F : J ⥤ C` from all small `J` have limits -/
has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by
infer_instance
/-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/
abbrev HasLimits (C : Type u) [Category.{v} C] : Prop :=
HasLimitsOfSize.{v, v} C
theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v)
[Category.{v} J] : HasLimitsOfShape J C :=
HasLimitsOfSize.has_limits_of_shape J
variable {J C}
-- see Note [lower instance priority]
instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J]
[HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F :=
HasLimitsOfShape.has_limit F
-- see Note [lower instance priority]
instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J]
[HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C :=
HasLimitsOfSize.has_limits_of_shape J
-- Interface to the `HasLimit` class.
/-- An arbitrary choice of limit cone for a functor. -/
def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F :=
(getLimitCone F).cone
/-- An arbitrary choice of limit object of a functor. -/
def limit (F : J ⥤ C) [HasLimit F] :=
(limit.cone F).pt
/-- The projection from the limit object to a value of the functor. -/
def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j :=
(limit.cone F).π.app j
@[reassoc]
theorem limit.π_comp_eqToHom (F : J ⥤ C) [HasLimit F] {j j' : J} (hj : j = j') :
limit.π F j ≫ eqToHom (by subst hj; rfl) = limit.π F j' := by
subst hj
simp
@[simp]
theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F :=
rfl
@[simp]
theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ :=
rfl
@[reassoc (attr := simp)]
theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') :
limit.π F j ≫ F.map f = limit.π F j' :=
(limit.cone F).w f
/-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/
def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) :=
(getLimitCone F).isLimit
/-- The morphism from the cone point of any other cone to the limit object. -/
def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F :=
(limit.isLimit F).lift c
@[simp]
theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) :
(limit.isLimit F).lift c = limit.lift F c :=
rfl
@[reassoc (attr := simp)]
theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) :
limit.lift F c ≫ limit.π F j = c.π.app j :=
IsLimit.fac _ c j
/-- Functoriality of limits.
Usually this morphism should be accessed through `lim.map`,
but may be needed separately when you have specified limits for the source and target functors,
but not necessarily for all functors of shape `J`.
-/
def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G :=
IsLimit.map _ (limit.isLimit G) α
@[reassoc (attr := simp)]
theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) :
limMap α ≫ limit.π G j = limit.π F j ≫ α.app j :=
limit.lift_π _ j
/-- The cone morphism from any cone to the arbitrary choice of limit cone. -/
def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F :=
(limit.isLimit F).liftConeMorphism c
@[simp]
theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) :
(limit.coneMorphism c).hom = limit.lift F c :=
rfl
theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) :
(limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp
@[reassoc (attr := simp)]
theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c)
(j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j :=
IsLimit.conePointUniqueUpToIso_hom_comp _ _ _
@[reassoc (attr := simp)]
theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c)
(j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ _
theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) :
∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j :=
(limit.isLimit F).existsUnique _
/-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point.
-/
def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt :=
IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit
@[reassoc (attr := simp)]
theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) :
(limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by
dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso]
simp
@[reassoc (attr := simp)]
theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) :
(limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by
dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso]
simp
@[ext]
theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F}
(w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' :=
(limit.isLimit F).hom_ext w
@[reassoc (attr := simp)]
theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) :
limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by
ext
rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π]
rfl
@[simp]
theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) :=
(limit.isLimit _).lift_self
/-- The isomorphism (in `Type`) between
morphisms from a specified object `W` to the limit object,
and cones with cone point `W`.
-/
def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) :
ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) :=
(limit.isLimit F).homIso W
@[simp]
theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) :
(limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π :=
(limit.isLimit F).homIso_hom f
/-- The isomorphism (in `Type`) between
morphisms from a specified object `W` to the limit object,
and an explicit componentwise description of cones with cone point `W`.
-/
def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) :
ULift.{u₁} (W ⟶ limit F : Type v) ≅
{ p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } :=
(limit.isLimit F).homIso' W
theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) :
limit.lift F (c.extend f) = f ≫ limit.lift F c := by aesop_cat
/-- If a functor `F` has a limit, so does any naturally isomorphic functor.
-/
theorem hasLimit_of_iso {F G : J ⥤ C} [HasLimit F] (α : F ≅ G) : HasLimit G :=
HasLimit.mk
{ cone := (Cones.postcompose α.hom).obj (limit.cone F)
isLimit := (IsLimit.postcomposeHomEquiv _ _).symm (limit.isLimit F) }
@[deprecated (since := "2025-03-03")] alias hasLimitOfIso := hasLimit_of_iso
theorem hasLimit_iff_of_iso {F G : J ⥤ C} (α : F ≅ G) : HasLimit F ↔ HasLimit G :=
⟨fun _ ↦ hasLimit_of_iso α, fun _ ↦ hasLimit_of_iso α.symm⟩
-- See the construction of limits from products and equalizers
-- for an example usage.
/-- If a functor `G` has the same collection of cones as a functor `F`
which has a limit, then `G` also has a limit. -/
theorem HasLimit.ofConesIso {J K : Type u₁} [Category.{v₁} J] [Category.{v₂} K] (F : J ⥤ C)
(G : K ⥤ C) (h : F.cones ≅ G.cones) [HasLimit F] : HasLimit G :=
HasLimit.mk ⟨_, IsLimit.ofNatIso (IsLimit.natIso (limit.isLimit F) ≪≫ h)⟩
/-- The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic,
if the functors are naturally isomorphic.
-/
def HasLimit.isoOfNatIso {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) : limit F ≅ limit G :=
IsLimit.conePointsIsoOfNatIso (limit.isLimit F) (limit.isLimit G) w
@[reassoc (attr := simp)]
theorem HasLimit.isoOfNatIso_hom_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) :
(HasLimit.isoOfNatIso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j :=
IsLimit.conePointsIsoOfNatIso_hom_comp _ _ _ _
@[reassoc (attr := simp)]
theorem HasLimit.isoOfNatIso_inv_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) :
(HasLimit.isoOfNatIso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j :=
IsLimit.conePointsIsoOfNatIso_inv_comp _ _ _ _
@[reassoc (attr := simp)]
theorem HasLimit.lift_isoOfNatIso_hom {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone F)
(w : F ≅ G) :
limit.lift F t ≫ (HasLimit.isoOfNatIso w).hom =
limit.lift G ((Cones.postcompose w.hom).obj _) :=
IsLimit.lift_comp_conePointsIsoOfNatIso_hom _ _ _
@[reassoc (attr := simp)]
theorem HasLimit.lift_isoOfNatIso_inv {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone G)
(w : F ≅ G) :
limit.lift G t ≫ (HasLimit.isoOfNatIso w).inv =
limit.lift F ((Cones.postcompose w.inv).obj _) :=
IsLimit.lift_comp_conePointsIsoOfNatIso_inv _ _ _
/-- The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic,
if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism.
-/
def HasLimit.isoOfEquivalence {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K)
(w : e.functor ⋙ G ≅ F) : limit F ≅ limit G :=
IsLimit.conePointsIsoOfEquivalence (limit.isLimit F) (limit.isLimit G) e w
@[simp]
theorem HasLimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) :
(HasLimit.isoOfEquivalence e w).hom ≫ limit.π G k =
limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) := by
simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom]
dsimp
simp
@[simp]
theorem HasLimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) :
(HasLimit.isoOfEquivalence e w).inv ≫ limit.π F j =
limit.π G (e.functor.obj j) ≫ w.hom.app j := by
simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom]
dsimp
simp
section Pre
variable (F)
variable [HasLimit F] (E : K ⥤ J) [HasLimit (E ⋙ F)]
/-- The canonical morphism from the limit of `F` to the limit of `E ⋙ F`.
-/
def limit.pre : limit F ⟶ limit (E ⋙ F) :=
limit.lift (E ⋙ F) ((limit.cone F).whisker E)
@[reassoc (attr := simp)]
theorem limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by
erw [IsLimit.fac]
rfl
@[simp]
theorem limit.lift_pre (c : Cone F) :
limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp
variable {L : Type u₃} [Category.{v₃} L]
variable (D : L ⥤ K)
@[simp]
theorem limit.pre_pre [h : HasLimit (D ⋙ E ⋙ F)] : haveI : HasLimit ((D ⋙ E) ⋙ F) := h
limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by
haveI : HasLimit ((D ⋙ E) ⋙ F) := h
ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; rfl
variable {E F}
/-- -
If we have particular limit cones available for `E ⋙ F` and for `F`,
we obtain a formula for `limit.pre F E`.
-/
theorem limit.pre_eq (s : LimitCone (E ⋙ F)) (t : LimitCone F) :
limit.pre F E = (limit.isoLimitCone t).hom ≫ s.isLimit.lift (t.cone.whisker E) ≫
(limit.isoLimitCone s).inv := by aesop_cat
end Pre
section Post
variable {D : Type u'} [Category.{v'} D]
variable (F : J ⥤ C) [HasLimit F] (G : C ⥤ D) [HasLimit (F ⋙ G)]
/-- The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`.
-/
def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) :=
limit.lift (F ⋙ G) (G.mapCone (limit.cone F))
@[reassoc (attr := simp)]
theorem limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by
erw [IsLimit.fac]
rfl
@[simp]
theorem limit.lift_post (c : Cone F) :
G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.mapCone c) := by
ext
rw [assoc, limit.post_π, ← G.map_comp, limit.lift_π, limit.lift_π]
rfl
@[simp]
theorem limit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) [h : HasLimit ((F ⋙ G) ⋙ H)] :
-- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals
-- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H))
haveI : HasLimit (F ⋙ G ⋙ H) := h
H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by
haveI : HasLimit (F ⋙ G ⋙ H) := h
ext; erw [assoc, limit.post_π, ← H.map_comp, limit.post_π, limit.post_π]; rfl
end Post
theorem limit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D)
[HasLimit F] [HasLimit (E ⋙ F)] [HasLimit (F ⋙ G)]
[h : HasLimit ((E ⋙ F) ⋙ G)] :-- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs
-- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or
haveI : HasLimit (E ⋙ F ⋙ G) := h
G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by
| haveI : HasLimit (E ⋙ F ⋙ G) := h
ext; erw [assoc, limit.post_π, ← G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π]
| Mathlib/CategoryTheory/Limits/HasLimits.lean | 431 | 433 |
/-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Game.Basic
import Mathlib.SetTheory.Ordinal.NaturalOps
/-!
# Ordinals as games
We define the canonical map `Ordinal → SetTheory.PGame`, where every ordinal is mapped to the
game whose left set consists of all previous ordinals.
The map to surreals is defined in `Ordinal.toSurreal`.
# Main declarations
- `Ordinal.toPGame`: The canonical map between ordinals and pre-games.
- `Ordinal.toPGameEmbedding`: The order embedding version of the previous map.
-/
universe u
open SetTheory PGame
open scoped NaturalOps PGame
namespace Ordinal
/-- Converts an ordinal into the corresponding pre-game. -/
noncomputable def toPGame (o : Ordinal.{u}) : PGame.{u} :=
⟨o.toType, PEmpty, fun x => ((enumIsoToType o).symm x).val.toPGame, PEmpty.elim⟩
termination_by o
decreasing_by exact ((enumIsoToType o).symm x).prop
@[simp]
theorem toPGame_leftMoves (o : Ordinal) : o.toPGame.LeftMoves = o.toType := by
rw [toPGame, LeftMoves]
@[simp]
theorem toPGame_rightMoves (o : Ordinal) : o.toPGame.RightMoves = PEmpty := by
rw [toPGame, RightMoves]
instance isEmpty_zero_toPGame_leftMoves : IsEmpty (toPGame 0).LeftMoves := by
rw [toPGame_leftMoves]; infer_instance
instance isEmpty_toPGame_rightMoves (o : Ordinal) : IsEmpty o.toPGame.RightMoves := by
rw [toPGame_rightMoves]; infer_instance
/-- Converts an ordinal less than `o` into a move for the `PGame` corresponding to `o`, and vice
versa. -/
noncomputable def toLeftMovesToPGame {o : Ordinal} : Set.Iio o ≃ o.toPGame.LeftMoves :=
(enumIsoToType o).toEquiv.trans (Equiv.cast (toPGame_leftMoves o).symm)
@[simp]
theorem toLeftMovesToPGame_symm_lt {o : Ordinal} (i : o.toPGame.LeftMoves) :
↑(toLeftMovesToPGame.symm i) < o :=
(toLeftMovesToPGame.symm i).prop
@[nolint unusedHavesSuffices]
theorem toPGame_moveLeft_hEq {o : Ordinal} :
HEq o.toPGame.moveLeft fun x : o.toType => ((enumIsoToType o).symm x).val.toPGame := by
rw [toPGame]
rfl
@[simp]
theorem toPGame_moveLeft' {o : Ordinal} (i) :
o.toPGame.moveLeft i = (toLeftMovesToPGame.symm i).val.toPGame :=
(congr_heq toPGame_moveLeft_hEq.symm (cast_heq _ i)).symm
theorem toPGame_moveLeft {o : Ordinal} (i) :
o.toPGame.moveLeft (toLeftMovesToPGame i) = i.val.toPGame := by simp
/-- `0.toPGame` has the same moves as `0`. -/
noncomputable def zeroToPGameRelabelling : toPGame 0 ≡r 0 :=
Relabelling.isEmpty _
theorem toPGame_zero : toPGame 0 ≈ 0 :=
zeroToPGameRelabelling.equiv
noncomputable instance uniqueOneToPGameLeftMoves : Unique (toPGame 1).LeftMoves :=
(Equiv.cast <| toPGame_leftMoves 1).unique
@[simp]
theorem one_toPGame_leftMoves_default_eq :
(default : (toPGame 1).LeftMoves) = @toLeftMovesToPGame 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
@[simp]
theorem to_leftMoves_one_toPGame_symm (i) :
(@toLeftMovesToPGame 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
theorem one_toPGame_moveLeft (x) : (toPGame 1).moveLeft x = toPGame 0 := by simp
/-- `1.toPGame` has the same moves as `1`. -/
noncomputable def oneToPGameRelabelling : toPGame 1 ≡r 1 :=
⟨Equiv.ofUnique _ _, Equiv.equivOfIsEmpty _ _, fun i => by
simpa using zeroToPGameRelabelling, isEmptyElim⟩
theorem toPGame_one : toPGame 1 ≈ 1 :=
oneToPGameRelabelling.equiv
theorem toPGame_lf {a b : Ordinal} (h : a < b) : a.toPGame ⧏ b.toPGame := by
convert moveLeft_lf (toLeftMovesToPGame ⟨a, h⟩); rw [toPGame_moveLeft]
theorem toPGame_le {a b : Ordinal} (h : a ≤ b) : a.toPGame ≤ b.toPGame := by
refine le_iff_forall_lf.2 ⟨fun i => ?_, isEmptyElim⟩
rw [toPGame_moveLeft']
exact toPGame_lf ((toLeftMovesToPGame_symm_lt i).trans_le h)
theorem toPGame_lt {a b : Ordinal} (h : a < b) : a.toPGame < b.toPGame :=
⟨toPGame_le h.le, toPGame_lf h⟩
theorem toPGame_nonneg (a : Ordinal) : 0 ≤ a.toPGame :=
zeroToPGameRelabelling.ge.trans <| toPGame_le <| Ordinal.zero_le a
@[simp]
theorem toPGame_lf_iff {a b : Ordinal} : a.toPGame ⧏ b.toPGame ↔ a < b :=
⟨by contrapose; rw [not_lt, not_lf]; exact toPGame_le, toPGame_lf⟩
@[simp]
theorem toPGame_le_iff {a b : Ordinal} : a.toPGame ≤ b.toPGame ↔ a ≤ b :=
⟨by contrapose; rw [not_le, PGame.not_le]; exact toPGame_lf, toPGame_le⟩
@[simp]
theorem toPGame_lt_iff {a b : Ordinal} : a.toPGame < b.toPGame ↔ a < b :=
| ⟨by contrapose; rw [not_lt]; exact fun h => not_lt_of_le (toPGame_le h), toPGame_lt⟩
| Mathlib/SetTheory/Game/Ordinal.lean | 130 | 131 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.WSeq.Basic
import Mathlib.Data.WSeq.Defs
import Mathlib.Data.WSeq.Productive
import Mathlib.Data.WSeq.Relation
deprecated_module (since := "2025-04-13")
| Mathlib/Data/Seq/WSeq.lean | 1,384 | 1,385 | |
/-
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.Order.Bounds.Defs
import Mathlib.Order.Directed
import Mathlib.Order.BoundedOrder.Monotone
import Mathlib.Order.Interval.Set.Basic
/-!
# Upper / lower bounds
In this file we prove various lemmas about upper/lower bounds of a set:
monotonicity, behaviour under `∪`, `∩`, `insert`,
and provide formulas for `∅`, `univ`, and intervals.
-/
open Function Set
open OrderDual (toDual ofDual)
universe u v
variable {α : Type u} {γ : Type v}
section
variable [Preorder α] {s t : Set α} {a b : α}
theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a :=
Iff.rfl
theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x :=
Iff.rfl
lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl
lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl
theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x :=
Iff.rfl
theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y :=
Iff.rfl
theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le
theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top
@[simp]
theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s :=
and_iff_left <| bot_mem_lowerBounds _
@[simp]
theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s :=
and_iff_left <| top_mem_upperBounds _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x`
is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/
theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by
simp [BddAbove, upperBounds, Set.Nonempty]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x`
is not less than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/
theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y :=
@not_bddAbove_iff' αᵒᵈ _ _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater
than `x`. A version for preorders is called `not_bddAbove_iff'`. -/
theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by
simp only [not_bddAbove_iff', not_le]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less
than `x`. A version for preorders is called `not_bddBelow_iff'`. -/
theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x :=
@not_bddAbove_iff αᵒᵈ _ _
@[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
@[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} :
BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} :
BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) :=
h
theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) :=
h
theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) :=
h
/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/
abbrev IsLeast.orderBot (h : IsLeast s a) :
OrderBot s where
bot := ⟨a, h.1⟩
bot_le := Subtype.forall.2 h.2
/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/
abbrev IsGreatest.orderTop (h : IsGreatest s a) :
OrderTop s where
top := ⟨a, h.1⟩
le_top := Subtype.forall.2 h.2
theorem isLUB_congr (h : upperBounds s = upperBounds t) : IsLUB s a ↔ IsLUB t a := by
rw [IsLUB, IsLUB, h]
theorem isGLB_congr (h : lowerBounds s = lowerBounds t) : IsGLB s a ↔ IsGLB t a := by
rw [IsGLB, IsGLB, h]
/-!
### Monotonicity
-/
theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s :=
fun _ hb _ h => hb <| hst h
theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s :=
fun _ hb _ h => hb <| hst h
theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s :=
fun ha _ h => le_trans (ha h) hab
theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s :=
fun hb _ h => le_trans hab (hb h)
theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
a ∈ upperBounds t → b ∈ upperBounds s := fun ha =>
upperBounds_mono_set hst <| upperBounds_mono_mem hab ha
theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb =>
lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb
/-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/
theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s :=
Nonempty.mono <| upperBounds_mono_set h
/-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/
theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s :=
Nonempty.mono <| lowerBounds_mono_set h
/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsLUB t a :=
⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩
/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsGLB t a :=
hs.dual.of_subset_of_superset hp hst htp
theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a :=
hb.2 (hst ha.1)
theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b :=
hb.2 (hst ha.1)
theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b :=
IsLeast.mono hb ha <| upperBounds_mono_set hst
theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a :=
IsGreatest.mono hb ha <| lowerBounds_mono_set hst
theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) :=
fun _ hx _ hy => hy hx
theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) :=
fun _ hx _ hy => hy hx
theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) :=
hs.mono (subset_upperBounds_lowerBounds s)
theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) :=
hs.mono (subset_lowerBounds_upperBounds s)
/-!
### Conversions
-/
theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a :=
Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩
theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a :=
h.dual.upperBounds_eq
theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a :=
h.isGLB.lowerBounds_eq
theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a :=
h.isLUB.upperBounds_eq
theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b :=
⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩
theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x :=
h.dual.lt_iff
theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by
rw [h.upperBounds_eq]
rfl
theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by
rw [h.lowerBounds_eq]
rfl
theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s :=
⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩
theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s :=
@isLUB_iff_le_iff αᵒᵈ _ _ _
/-- If `s` has a least upper bound, then it is bounded above. -/
theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s :=
⟨a, h.1⟩
/-- If `s` has a greatest lower bound, then it is bounded below. -/
theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s :=
⟨a, h.1⟩
/-- If `s` has a greatest element, then it is bounded above. -/
theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s :=
⟨a, h.2⟩
/-- If `s` has a least element, then it is bounded below. -/
theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s :=
⟨a, h.2⟩
theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty :=
⟨a, h.1⟩
theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty :=
⟨a, h.1⟩
/-!
### Union and intersection
-/
@[simp]
theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t :=
Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩)
fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht
@[simp]
theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t :=
@upperBounds_union αᵒᵈ _ s t
theorem union_upperBounds_subset_upperBounds_inter :
upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) :=
union_subset (upperBounds_mono_set inter_subset_left)
(upperBounds_mono_set inter_subset_right)
theorem union_lowerBounds_subset_lowerBounds_inter :
lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) :=
@union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t
theorem isLeast_union_iff {a : α} {s t : Set α} :
IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by
simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc]
theorem isGreatest_union_iff :
IsGreatest (s ∪ t) a ↔
IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a :=
@isLeast_union_iff αᵒᵈ _ a s t
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) :=
h.mono inter_subset_right
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) :=
h.mono inter_subset_right
/-- In a directed order, the union of bounded above sets is bounded above. -/
theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove s → BddAbove t → BddAbove (s ∪ t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b
rw [BddAbove, upperBounds_union]
exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩
/-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/
theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t :=
⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h =>
h.1.union h.2⟩
/-- In a codirected order, the union of bounded below sets is bounded below. -/
theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow s → BddBelow t → BddBelow (s ∪ t) :=
@BddAbove.union αᵒᵈ _ _ _ _
/-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/
theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t :=
@bddAbove_union αᵒᵈ _ _ _ _
/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,
then `a ⊔ b` is the least upper bound of `s ∪ t`. -/
theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) :
IsLUB (s ∪ t) (a ⊔ b) :=
⟨fun _ h =>
h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h,
fun _ hc =>
sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩
/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,
then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/
theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁)
(ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) :=
hs.dual.union ht
/-- If `a` is the least element of `s` and `b` is the least element of `t`,
then `min a b` is the least element of `s ∪ t`. -/
theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a)
(hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩
/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,
then `max a b` is the greatest element of `s ∪ t`. -/
theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a)
(hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩
theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) :
IsLUB (s ∩ Ici b) a :=
⟨fun _ hx => ha.1 hx.1, fun c hc =>
have hbc : b ≤ c := hc ⟨hb, le_rfl⟩
ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩
theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) :
IsGLB (s ∩ Iic b) a :=
ha.dual.inter_Ici_of_mem hb
theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) :
BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by
rw [bddAbove_def, exists_ge_and_iff_exists]
exact Monotone.ball fun x _ => monotone_le
theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) :
BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
bddAbove_iff_exists_ge (toDual x₀)
theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) :
∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x :=
(bddAbove_iff_exists_ge x₀).mp hs
theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) :
∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
(bddBelow_iff_exists_le x₀).mp hs
/-!
### Specific sets
#### Unbounded intervals
-/
theorem isLeast_Ici : IsLeast (Ici a) a :=
⟨left_mem_Ici, fun _ => id⟩
theorem isGreatest_Iic : IsGreatest (Iic a) a :=
⟨right_mem_Iic, fun _ => id⟩
theorem isLUB_Iic : IsLUB (Iic a) a :=
isGreatest_Iic.isLUB
theorem isGLB_Ici : IsGLB (Ici a) a :=
isLeast_Ici.isGLB
theorem upperBounds_Iic : upperBounds (Iic a) = Ici a :=
isLUB_Iic.upperBounds_eq
theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a :=
isGLB_Ici.lowerBounds_eq
theorem bddAbove_Iic : BddAbove (Iic a) :=
isLUB_Iic.bddAbove
theorem bddBelow_Ici : BddBelow (Ici a) :=
isGLB_Ici.bddBelow
theorem bddAbove_Iio : BddAbove (Iio a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem bddBelow_Ioi : BddBelow (Ioi a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a :=
(isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk
theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b :=
@lub_Iio_le αᵒᵈ _ _ a hb
theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) :
j = i ∨ Iio i = Iic j := by
rcases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i | hj_lt_i
· exact Or.inl hj_eq_i
· right
exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩
theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) :
j = i ∨ Ioi i = Ici j :=
@lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj
section
variable [LinearOrder γ]
theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by
by_cases h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i
· obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt
exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩
· refine ⟨i, fun j hj => le_of_lt hj, ?_⟩
rw [mem_lowerBounds]
by_contra h
refine h_exists_lt ?_
push_neg at h
exact h
theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j :=
@exists_lub_Iio γᵒᵈ _ i
variable [DenselyOrdered γ]
theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a :=
⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_lt_imp_le_of_dense hy⟩
theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a :=
@isLUB_Iio γᵒᵈ _ _ a
theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a :=
isLUB_Iio.upperBounds_eq
theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a :=
isGLB_Ioi.lowerBounds_eq
end
/-!
#### Singleton
-/
@[simp] theorem isGreatest_singleton : IsGreatest {a} a :=
⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩
@[simp] theorem isLeast_singleton : IsLeast {a} a :=
@isGreatest_singleton αᵒᵈ _ a
@[simp] theorem isLUB_singleton : IsLUB {a} a :=
isGreatest_singleton.isLUB
@[simp] theorem isGLB_singleton : IsGLB {a} a :=
isLeast_singleton.isGLB
@[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove
@[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow
@[simp]
theorem upperBounds_singleton : upperBounds {a} = Ici a :=
isLUB_singleton.upperBounds_eq
@[simp]
theorem lowerBounds_singleton : lowerBounds {a} = Iic a :=
isGLB_singleton.lowerBounds_eq
/-!
#### Bounded intervals
-/
theorem bddAbove_Icc : BddAbove (Icc a b) :=
⟨b, fun _ => And.right⟩
theorem bddBelow_Icc : BddBelow (Icc a b) :=
⟨a, fun _ => And.left⟩
theorem bddAbove_Ico : BddAbove (Ico a b) :=
bddAbove_Icc.mono Ico_subset_Icc_self
theorem bddBelow_Ico : BddBelow (Ico a b) :=
bddBelow_Icc.mono Ico_subset_Icc_self
theorem bddAbove_Ioc : BddAbove (Ioc a b) :=
bddAbove_Icc.mono Ioc_subset_Icc_self
theorem bddBelow_Ioc : BddBelow (Ioc a b) :=
bddBelow_Icc.mono Ioc_subset_Icc_self
theorem bddAbove_Ioo : BddAbove (Ioo a b) :=
bddAbove_Icc.mono Ioo_subset_Icc_self
theorem bddBelow_Ioo : BddBelow (Ioo a b) :=
bddBelow_Icc.mono Ioo_subset_Icc_self
theorem isGreatest_Icc (h : a ≤ b) : IsGreatest (Icc a b) b :=
⟨right_mem_Icc.2 h, fun _ => And.right⟩
theorem isLUB_Icc (h : a ≤ b) : IsLUB (Icc a b) b :=
(isGreatest_Icc h).isLUB
theorem upperBounds_Icc (h : a ≤ b) : upperBounds (Icc a b) = Ici b :=
(isLUB_Icc h).upperBounds_eq
theorem isLeast_Icc (h : a ≤ b) : IsLeast (Icc a b) a :=
⟨left_mem_Icc.2 h, fun _ => And.left⟩
theorem isGLB_Icc (h : a ≤ b) : IsGLB (Icc a b) a :=
(isLeast_Icc h).isGLB
theorem lowerBounds_Icc (h : a ≤ b) : lowerBounds (Icc a b) = Iic a :=
(isGLB_Icc h).lowerBounds_eq
theorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b :=
⟨right_mem_Ioc.2 h, fun _ => And.right⟩
theorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b :=
(isGreatest_Ioc h).isLUB
theorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b :=
(isLUB_Ioc h).upperBounds_eq
theorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a :=
⟨left_mem_Ico.2 h, fun _ => And.left⟩
theorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a :=
(isLeast_Ico h).isGLB
theorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a :=
(isGLB_Ico h).lowerBounds_eq
section
variable [SemilatticeSup γ] [DenselyOrdered γ]
theorem isGLB_Ioo {a b : γ} (h : a < b) : IsGLB (Ioo a b) a :=
⟨fun _ hx => hx.1.le, fun x hx => by
rcases eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ | h₂
· exact h₁.symm ▸ le_sup_left
obtain ⟨y, lty, ylt⟩ := exists_between h₂
apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim
obtain ⟨u, au, ub⟩ := exists_between h
apply (hx ⟨au, ub⟩).trans ub.le⟩
theorem lowerBounds_Ioo {a b : γ} (hab : a < b) : lowerBounds (Ioo a b) = Iic a :=
(isGLB_Ioo hab).lowerBounds_eq
theorem isGLB_Ioc {a b : γ} (hab : a < b) : IsGLB (Ioc a b) a :=
(isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self
theorem lowerBounds_Ioc {a b : γ} (hab : a < b) : lowerBounds (Ioc a b) = Iic a :=
(isGLB_Ioc hab).lowerBounds_eq
end
section
variable [SemilatticeInf γ] [DenselyOrdered γ]
theorem isLUB_Ioo {a b : γ} (hab : a < b) : IsLUB (Ioo a b) b := by
simpa only [Ioo_toDual] using isGLB_Ioo hab.dual
theorem upperBounds_Ioo {a b : γ} (hab : a < b) : upperBounds (Ioo a b) = Ici b :=
(isLUB_Ioo hab).upperBounds_eq
theorem isLUB_Ico {a b : γ} (hab : a < b) : IsLUB (Ico a b) b := by
simpa only [Ioc_toDual] using isGLB_Ioc hab.dual
theorem upperBounds_Ico {a b : γ} (hab : a < b) : upperBounds (Ico a b) = Ici b :=
(isLUB_Ico hab).upperBounds_eq
end
theorem bddBelow_iff_subset_Ici : BddBelow s ↔ ∃ a, s ⊆ Ici a :=
Iff.rfl
theorem bddAbove_iff_subset_Iic : BddAbove s ↔ ∃ a, s ⊆ Iic a :=
Iff.rfl
theorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ Icc a b := by
simp [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici,
bddAbove_iff_subset_Iic, exists_and_left, exists_and_right]
/-!
#### Univ
-/
@[simp] theorem isGreatest_univ_iff : IsGreatest univ a ↔ IsTop a := by
simp [IsGreatest, mem_upperBounds, IsTop]
theorem isGreatest_univ [OrderTop α] : IsGreatest (univ : Set α) ⊤ :=
isGreatest_univ_iff.2 isTop_top
@[simp]
theorem OrderTop.upperBounds_univ [PartialOrder γ] [OrderTop γ] :
upperBounds (univ : Set γ) = {⊤} := by rw [isGreatest_univ.upperBounds_eq, Ici_top]
theorem isLUB_univ [OrderTop α] : IsLUB (univ : Set α) ⊤ :=
isGreatest_univ.isLUB
@[simp]
theorem OrderBot.lowerBounds_univ [PartialOrder γ] [OrderBot γ] :
lowerBounds (univ : Set γ) = {⊥} :=
@OrderTop.upperBounds_univ γᵒᵈ _ _
@[simp] theorem isLeast_univ_iff : IsLeast univ a ↔ IsBot a :=
@isGreatest_univ_iff αᵒᵈ _ _
theorem isLeast_univ [OrderBot α] : IsLeast (univ : Set α) ⊥ :=
@isGreatest_univ αᵒᵈ _ _
theorem isGLB_univ [OrderBot α] : IsGLB (univ : Set α) ⊥ :=
isLeast_univ.isGLB
@[simp]
theorem NoTopOrder.upperBounds_univ [NoTopOrder α] : upperBounds (univ : Set α) = ∅ :=
eq_empty_of_subset_empty fun b hb =>
not_isTop b fun x => hb (mem_univ x)
@[deprecated (since := "2025-04-18")]
alias NoMaxOrder.upperBounds_univ := NoTopOrder.upperBounds_univ
@[simp]
theorem NoBotOrder.lowerBounds_univ [NoBotOrder α] : lowerBounds (univ : Set α) = ∅ :=
@NoTopOrder.upperBounds_univ αᵒᵈ _ _
@[deprecated (since := "2025-04-18")]
alias NoMinOrder.lowerBounds_univ := NoBotOrder.lowerBounds_univ
@[simp]
theorem not_bddAbove_univ [NoTopOrder α] : ¬BddAbove (univ : Set α) := by simp [BddAbove]
@[simp]
theorem not_bddBelow_univ [NoBotOrder α] : ¬BddBelow (univ : Set α) :=
@not_bddAbove_univ αᵒᵈ _ _
/-!
#### Empty set
-/
@[simp]
theorem upperBounds_empty : upperBounds (∅ : Set α) = univ := by
simp only [upperBounds, eq_univ_iff_forall, mem_setOf_eq, forall_mem_empty, forall_true_iff]
@[simp]
theorem lowerBounds_empty : lowerBounds (∅ : Set α) = univ :=
@upperBounds_empty αᵒᵈ _
@[simp]
theorem bddAbove_empty [Nonempty α] : BddAbove (∅ : Set α) := by
simp only [BddAbove, upperBounds_empty, univ_nonempty]
@[simp]
theorem bddBelow_empty [Nonempty α] : BddBelow (∅ : Set α) := by
simp only [BddBelow, lowerBounds_empty, univ_nonempty]
@[simp] theorem isGLB_empty_iff : IsGLB ∅ a ↔ IsTop a := by
simp [IsGLB]
@[simp] theorem isLUB_empty_iff : IsLUB ∅ a ↔ IsBot a :=
@isGLB_empty_iff αᵒᵈ _ _
theorem isGLB_empty [OrderTop α] : IsGLB ∅ (⊤ : α) :=
isGLB_empty_iff.2 isTop_top
theorem isLUB_empty [OrderBot α] : IsLUB ∅ (⊥ : α) :=
@isGLB_empty αᵒᵈ _ _
theorem IsLUB.nonempty [NoBotOrder α] (hs : IsLUB s a) : s.Nonempty :=
nonempty_iff_ne_empty.2 fun h =>
not_isBot a fun _ => hs.right <| by rw [h, upperBounds_empty]; exact mem_univ _
theorem IsGLB.nonempty [NoTopOrder α] (hs : IsGLB s a) : s.Nonempty :=
hs.dual.nonempty
theorem nonempty_of_not_bddAbove [ha : Nonempty α] (h : ¬BddAbove s) : s.Nonempty :=
(Nonempty.elim ha) fun x => (not_bddAbove_iff'.1 h x).imp fun _ ha => ha.1
theorem nonempty_of_not_bddBelow [Nonempty α] (h : ¬BddBelow s) : s.Nonempty :=
@nonempty_of_not_bddAbove αᵒᵈ _ _ _ h
/-!
#### insert
-/
/-- Adding a point to a set preserves its boundedness above. -/
@[simp]
theorem bddAbove_insert [IsDirected α (· ≤ ·)] {s : Set α} {a : α} :
BddAbove (insert a s) ↔ BddAbove s := by
simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and]
protected theorem BddAbove.insert [IsDirected α (· ≤ ·)] {s : Set α} (a : α) :
BddAbove s → BddAbove (insert a s) :=
bddAbove_insert.2
/-- Adding a point to a set preserves its boundedness below. -/
@[simp]
theorem bddBelow_insert [IsDirected α (· ≥ ·)] {s : Set α} {a : α} :
BddBelow (insert a s) ↔ BddBelow s := by
simp only [insert_eq, bddBelow_union, bddBelow_singleton, true_and]
protected theorem BddBelow.insert [IsDirected α (· ≥ ·)] {s : Set α} (a : α) :
BddBelow s → BddBelow (insert a s) :=
bddBelow_insert.2
protected theorem IsLUB.insert [SemilatticeSup γ] (a) {b} {s : Set γ} (hs : IsLUB s b) :
IsLUB (insert a s) (a ⊔ b) := by
rw [insert_eq]
exact isLUB_singleton.union hs
protected theorem IsGLB.insert [SemilatticeInf γ] (a) {b} {s : Set γ} (hs : IsGLB s b) :
IsGLB (insert a s) (a ⊓ b) := by
rw [insert_eq]
exact isGLB_singleton.union hs
protected theorem IsGreatest.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsGreatest s b) :
IsGreatest (insert a s) (max a b) := by
rw [insert_eq]
exact isGreatest_singleton.union hs
protected theorem IsLeast.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsLeast s b) :
IsLeast (insert a s) (min a b) := by
rw [insert_eq]
exact isLeast_singleton.union hs
@[simp]
theorem upperBounds_insert (a : α) (s : Set α) :
upperBounds (insert a s) = Ici a ∩ upperBounds s := by
rw [insert_eq, upperBounds_union, upperBounds_singleton]
@[simp]
theorem lowerBounds_insert (a : α) (s : Set α) :
lowerBounds (insert a s) = Iic a ∩ lowerBounds s := by
rw [insert_eq, lowerBounds_union, lowerBounds_singleton]
/-- When there is a global maximum, every set is bounded above. -/
@[simp]
protected theorem OrderTop.bddAbove [OrderTop α] (s : Set α) : BddAbove s :=
⟨⊤, fun a _ => OrderTop.le_top a⟩
/-- When there is a global minimum, every set is bounded below. -/
@[simp]
protected theorem OrderBot.bddBelow [OrderBot α] (s : Set α) : BddBelow s :=
⟨⊥, fun a _ => OrderBot.bot_le a⟩
/-- Sets are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `bddDefault` in the statements,
in the form `(hA : BddAbove A := by bddDefault)`. -/
macro "bddDefault" : tactic =>
`(tactic| first
| apply OrderTop.bddAbove
| apply OrderBot.bddBelow)
/-!
#### Pair
-/
theorem isLUB_pair [SemilatticeSup γ] {a b : γ} : IsLUB {a, b} (a ⊔ b) :=
isLUB_singleton.insert _
theorem isGLB_pair [SemilatticeInf γ] {a b : γ} : IsGLB {a, b} (a ⊓ b) :=
isGLB_singleton.insert _
theorem isLeast_pair [LinearOrder γ] {a b : γ} : IsLeast {a, b} (min a b) :=
isLeast_singleton.insert _
theorem isGreatest_pair [LinearOrder γ] {a b : γ} : IsGreatest {a, b} (max a b) :=
isGreatest_singleton.insert _
/-!
#### Lower/upper bounds
-/
@[simp]
theorem isLUB_lowerBounds : IsLUB (lowerBounds s) a ↔ IsGLB s a :=
⟨fun H => ⟨fun _ hx => H.2 <| subset_upperBounds_lowerBounds s hx, H.1⟩, IsGreatest.isLUB⟩
| @[simp]
theorem isGLB_upperBounds : IsGLB (upperBounds s) a ↔ IsLUB s a :=
| Mathlib/Order/Bounds/Basic.lean | 820 | 821 |
/-
Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu
-/
import Mathlib.Analysis.Complex.Basic
import Mathlib.Data.Fintype.Parity
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs
/-!
# The upper half plane and its automorphisms
This file defines `UpperHalfPlane` to be the upper half plane in `ℂ`.
We furthermore equip it with the structure of a `GLPos 2 ℝ` action by
fractional linear transformations.
We define the notation `ℍ` for the upper half plane available in the locale
`UpperHalfPlane` so as not to conflict with the quaternions.
-/
noncomputable section
open Matrix Matrix.SpecialLinearGroup
open scoped MatrixGroups
/-- The open upper half plane, denoted as `ℍ` within the `UpperHalfPlane` namespace -/
def UpperHalfPlane :=
{ point : ℂ // 0 < point.im }
@[inherit_doc] scoped[UpperHalfPlane] notation "ℍ" => UpperHalfPlane
open UpperHalfPlane
namespace UpperHalfPlane
/-- The coercion first into an element of `GL(2, ℝ)⁺`, then `GL(2, ℝ)` and finally a 2 × 2
matrix.
This notation is scoped in namespace `UpperHalfPlane`. -/
scoped notation:1024 "↑ₘ" A:1024 =>
(((A : GL(2, ℝ)⁺) : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) _)
instance instCoeFun : CoeFun GL(2, ℝ)⁺ fun _ => Fin 2 → Fin 2 → ℝ where coe A := ↑ₘA
/-- The coercion into an element of `GL(2, R)` and finally a 2 × 2 matrix over `R`. This is
similar to `↑ₘ`, but without positivity requirements, and allows the user to specify the ring `R`,
which can be useful to help Lean elaborate correctly.
This notation is scoped in namespace `UpperHalfPlane`. -/
scoped notation:1024 "↑ₘ[" R "]" A:1024 =>
((A : GL (Fin 2) R) : Matrix (Fin 2) (Fin 2) R)
/-- Canonical embedding of the upper half-plane into `ℂ`. -/
@[coe] protected def coe (z : ℍ) : ℂ := z.1
instance : CoeOut ℍ ℂ := ⟨UpperHalfPlane.coe⟩
instance : Inhabited ℍ :=
⟨⟨Complex.I, by simp⟩⟩
@[ext] theorem ext {a b : ℍ} (h : (a : ℂ) = b) : a = b := Subtype.eq h
@[simp, norm_cast] theorem ext_iff' {a b : ℍ} : (a : ℂ) = b ↔ a = b := UpperHalfPlane.ext_iff.symm
instance canLift : CanLift ℂ ℍ ((↑) : ℍ → ℂ) fun z => 0 < z.im :=
Subtype.canLift fun (z : ℂ) => 0 < z.im
/-- Imaginary part -/
def im (z : ℍ) :=
(z : ℂ).im
/-- Real part -/
def re (z : ℍ) :=
(z : ℂ).re
/-- Extensionality lemma in terms of `UpperHalfPlane.re` and `UpperHalfPlane.im`. -/
theorem ext' {a b : ℍ} (hre : a.re = b.re) (him : a.im = b.im) : a = b :=
ext <| Complex.ext hre him
/-- Constructor for `UpperHalfPlane`. It is useful if `⟨z, h⟩` makes Lean use a wrong
typeclass instance. -/
def mk (z : ℂ) (h : 0 < z.im) : ℍ :=
⟨z, h⟩
@[simp]
theorem coe_im (z : ℍ) : (z : ℂ).im = z.im :=
rfl
@[simp]
theorem coe_re (z : ℍ) : (z : ℂ).re = z.re :=
rfl
@[simp]
theorem mk_re (z : ℂ) (h : 0 < z.im) : (mk z h).re = z.re :=
rfl
@[simp]
theorem mk_im (z : ℂ) (h : 0 < z.im) : (mk z h).im = z.im :=
rfl
@[simp]
theorem coe_mk (z : ℂ) (h : 0 < z.im) : (mk z h : ℂ) = z :=
rfl
@[simp]
lemma coe_mk_subtype {z : ℂ} (hz : 0 < z.im) :
UpperHalfPlane.coe ⟨z, hz⟩ = z := by
rfl
@[simp]
theorem mk_coe (z : ℍ) (h : 0 < (z : ℂ).im := z.2) : mk z h = z :=
rfl
theorem re_add_im (z : ℍ) : (z.re + z.im * Complex.I : ℂ) = z :=
Complex.re_add_im z
theorem im_pos (z : ℍ) : 0 < z.im :=
z.2
theorem im_ne_zero (z : ℍ) : z.im ≠ 0 :=
z.im_pos.ne'
theorem ne_zero (z : ℍ) : (z : ℂ) ≠ 0 :=
mt (congr_arg Complex.im) z.im_ne_zero
/-- Define I := √-1 as an element on the upper half plane. -/
def I : ℍ := ⟨Complex.I, by simp⟩
@[simp]
lemma I_im : I.im = 1 := rfl
@[simp]
lemma I_re : I.re = 0 := rfl
@[simp, norm_cast]
lemma coe_I : I = Complex.I := rfl
end UpperHalfPlane
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
/-- Extension for the `positivity` tactic: `UpperHalfPlane.im`. -/
@[positivity UpperHalfPlane.im _]
def evalUpperHalfPlaneIm : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(UpperHalfPlane.im $a) =>
assertInstancesCommute
pure (.positive q(@UpperHalfPlane.im_pos $a))
| _, _, _ => throwError "not UpperHalfPlane.im"
/-- Extension for the `positivity` tactic: `UpperHalfPlane.coe`. -/
@[positivity UpperHalfPlane.coe _]
def evalUpperHalfPlaneCoe : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℂ), ~q(UpperHalfPlane.coe $a) =>
assertInstancesCommute
pure (.nonzero q(@UpperHalfPlane.ne_zero $a))
| _, _, _ => throwError "not UpperHalfPlane.coe"
end Mathlib.Meta.Positivity
namespace UpperHalfPlane
theorem normSq_pos (z : ℍ) : 0 < Complex.normSq (z : ℂ) := by
rw [Complex.normSq_pos]; exact z.ne_zero
theorem normSq_ne_zero (z : ℍ) : Complex.normSq (z : ℂ) ≠ 0 :=
(normSq_pos z).ne'
theorem im_inv_neg_coe_pos (z : ℍ) : 0 < (-z : ℂ)⁻¹.im := by
simpa [neg_div] using div_pos z.property (normSq_pos z)
lemma ne_nat (z : ℍ) : ∀ n : ℕ, z.1 ≠ n := by
intro n
have h1 := z.2
aesop
lemma ne_int (z : ℍ) : ∀ n : ℤ, z.1 ≠ n := by
intro n
have h1 := z.2
aesop
/-- Numerator of the formula for a fractional linear transformation -/
def num (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := g 0 0 * z + g 0 1
/-- Denominator of the formula for a fractional linear transformation -/
def denom (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := g 1 0 * z + g 1 1
theorem linear_ne_zero (cd : Fin 2 → ℝ) (z : ℍ) (h : cd ≠ 0) : (cd 0 : ℂ) * z + cd 1 ≠ 0 := by
contrapose! h
have : cd 0 = 0 := by
-- we will need this twice
apply_fun Complex.im at h
simpa only [z.im_ne_zero, Complex.add_im, add_zero, coe_im, zero_mul, or_false,
Complex.ofReal_im, Complex.zero_im, Complex.mul_im, mul_eq_zero] using h
simp only [this, zero_mul, Complex.ofReal_zero, zero_add, Complex.ofReal_eq_zero]
at h
ext i
fin_cases i <;> assumption
theorem denom_ne_zero (g : GL(2, ℝ)⁺) (z : ℍ) : denom g z ≠ 0 := by
intro H
have DET := (mem_glpos _).1 g.prop
simp only [GeneralLinearGroup.val_det_apply] at DET
obtain hg | hz : g 1 0 = 0 ∨ z.im = 0 := by simpa [num, denom] using congr_arg Complex.im H
· simp only [hg, Complex.ofReal_zero, denom, zero_mul, zero_add, Complex.ofReal_eq_zero] at H
simp only [Matrix.det_fin_two g.1.1, H, hg, mul_zero, sub_zero, lt_self_iff_false] at DET
· exact z.prop.ne' hz
theorem normSq_denom_pos (g : GL(2, ℝ)⁺) (z : ℍ) : 0 < Complex.normSq (denom g z) :=
Complex.normSq_pos.mpr (denom_ne_zero g z)
theorem normSq_denom_ne_zero (g : GL(2, ℝ)⁺) (z : ℍ) : Complex.normSq (denom g z) ≠ 0 :=
ne_of_gt (normSq_denom_pos g z)
/-- Fractional linear transformation, also known as the Moebius transformation -/
def smulAux' (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ :=
num g z / denom g z
theorem smulAux'_im (g : GL(2, ℝ)⁺) (z : ℍ) :
(smulAux' g z).im = det ↑ₘg * z.im / Complex.normSq (denom g z) := by
simp only [smulAux', num, denom, Complex.div_im, Complex.add_im, Complex.mul_im,
Complex.ofReal_re, coe_im, Complex.ofReal_im, coe_re, zero_mul, add_zero, Complex.add_re,
Complex.mul_re, sub_zero, ← sub_div, g.1.1.det_fin_two]
ring
/-- Fractional linear transformation, also known as the Moebius transformation -/
def smulAux (g : GL(2, ℝ)⁺) (z : ℍ) : ℍ :=
mk (smulAux' g z) <| by
rw [smulAux'_im]
convert mul_pos ((mem_glpos _).1 g.prop)
(div_pos z.im_pos (Complex.normSq_pos.mpr (denom_ne_zero g z))) using 1
simp only [GeneralLinearGroup.val_det_apply]
ring
theorem denom_cocycle (x y : GL(2, ℝ)⁺) (z : ℍ) :
denom (x * y) z = denom x (smulAux y z) * denom y z := by
change _ = (_ * (_ / _) + _) * _
field_simp [denom_ne_zero]
simp only [denom, Subgroup.coe_mul, Fin.isValue, Units.val_mul, mul_apply, Fin.sum_univ_succ,
Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton, Fin.succ_zero_eq_one,
Complex.ofReal_add, Complex.ofReal_mul, num]
ring
theorem mul_smul' (x y : GL(2, ℝ)⁺) (z : ℍ) : smulAux (x * y) z = smulAux x (smulAux y z) := by
ext1
change _ / _ = (_ * (_ / _) + _) / _
rw [denom_cocycle]
field_simp [denom_ne_zero]
simp only [num, Subgroup.coe_mul, Fin.isValue, Units.val_mul, mul_apply, Fin.sum_univ_succ,
Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton, Fin.succ_zero_eq_one,
Complex.ofReal_add, Complex.ofReal_mul, denom]
ring
/-- The action of `GLPos 2 ℝ` on the upper half-plane by fractional linear transformations. -/
instance : MulAction GL(2, ℝ)⁺ ℍ where
smul := smulAux
one_smul z := by
ext1
change _ / _ = _
simp [num, denom]
mul_smul := mul_smul'
instance SLAction {R : Type*} [CommRing R] [Algebra R ℝ] : MulAction SL(2, R) ℍ :=
MulAction.compHom ℍ <| SpecialLinearGroup.toGLPos.comp <| map (algebraMap R ℝ)
-- Porting note: in the statement, we used to have coercions `↑· : ℝ`
-- rather than `algebraMap R ℝ ·`.
theorem specialLinearGroup_apply {R : Type*} [CommRing R] [Algebra R ℝ] (g : SL(2, R)) (z : ℍ) :
g • z =
mk
| (((algebraMap R ℝ (g 0 0) : ℂ) * z + (algebraMap R ℝ (g 0 1) : ℂ)) /
((algebraMap R ℝ (g 1 0) : ℂ) * z + (algebraMap R ℝ (g 1 1) : ℂ)))
(g • z).property :=
rfl
variable (g : GL(2, ℝ)⁺) (z : ℍ)
@[simp]
theorem coe_smul : ↑(g • z) = num g z / denom g z :=
rfl
| Mathlib/Analysis/Complex/UpperHalfPlane/Basic.lean | 275 | 284 |
/-
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 | 625 | 631 |
/-
Copyright (c) 2024 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn,
Mario Carneiro
-/
import Mathlib.Data.List.Defs
import Mathlib.Data.Option.Basic
import Mathlib.Util.AssertExists
/-! # getD and getI
This file provides theorems for working with the `getD` and `getI` functions. These are used to
access an element of a list by numerical index, with a default value as a fallback when the index
is out of range.
-/
assert_not_imported Mathlib.Algebra.Order.Group.Nat
namespace List
universe u v
variable {α : Type u} {β : Type v} (l : List α) (x : α) (xs : List α) (n : ℕ)
section getD
variable (d : α)
theorem getD_eq_getElem {n : ℕ} (hn : n < l.length) : l.getD n d = l[n] := by
induction l generalizing n with
| nil => simp at hn
| cons head tail ih =>
cases n
· exact getD_cons_zero
· exact ih _
theorem getD_map {n : ℕ} (f : α → β) : (map f l).getD n (f d) = f (l.getD n d) := by simp
theorem getD_eq_default {n : ℕ} (hn : l.length ≤ n) : l.getD n d = d := by
induction l generalizing n with
| nil => exact getD_nil
| cons head tail ih =>
cases n
· simp at hn
| · exact ih (Nat.le_of_succ_le_succ hn)
| Mathlib/Data/List/GetD.lean | 46 | 46 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Peter Nelson
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.GeomSum
import Mathlib.LinearAlgebra.Matrix.Block
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.RingTheory.Localization.FractionRing
/-!
# Vandermonde matrix
This file defines the `vandermonde` matrix and gives its determinant.
For each `CommRing R`, and function `v : Fin n → R` the matrix `vandermonde v`
is defined to be `Fin n` by `Fin n` matrix `V` whose `i`th row is `[1, (v i), (v i)^2, ...]`.
This matrix has determinant equal to the product of `v i - v j` over all unordered pairs `i,j`,
and therefore is nonsingular if and only if `v` is injective.
`vandermonde v` is a special case of two more general matrices we also define.
For a type `α` and functions `v w : α → R`, we write `rectVandermonde v w n` for
the `α × Fin n` matrix with `i`th row `[(w i) ^ (n-1), (v i) * (w i)^(n-2), ..., (v i)^(n-1)]`.
`projVandermonde v w = rectVandermonde v w n` is the square matrix case, where `α = Fin n`.
The determinant of `projVandermonde v w` is the product of `v j * w i - v i * w j`,
taken over all pairs `i,j` with `i < j`, which gives a similar characterization of
when it it nonsingular. Since `vandermonde v w = projVandermonde v 1`,
we can derive most of the API for the former in terms of the latter.
These extensions of Vandermonde matrices arise in the study of complete arcs in finite geometry,
coding theory, and representations of uniform matroids over finite fields.
## Main definitions
* `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`.
* `rectVandermonde v w n`: an `α × Fin n` matrix whose
`i, j`-th entry is `(v i) ^ j * (w i) ^ (n-1-j)`.
* `projVandermonde v w`: a square matrix whose `i, j`-th entry is `(v i) ^ j * (w i) ^ (n-1-j)`.
## Main results
* `det_vandermonde`: `det (vandermonde v)` is the product of `v j - v i`, where
`(i, j)` ranges over the set of pairs with `i < j`.
* `det_projVandermonde`: `det (projVandermonde v w)` is the product of `v j * w i - v i * w j`,
taken over all pairs with `i < j`.
## Implementation notes
|
We derive the `det_vandermonde` formula from `det_projVandermonde`,
which is proved using an induction argument involving row operations and division.
To circumvent issues with non-invertible elements while still maintaining the generality of rings,
we first prove it for fields using the private lemma `det_projVandermonde_of_field`,
and then use an algebraic workaround to generalize to the ring case,
stating the strictly more general form as `det_projVandermonde`.
| Mathlib/LinearAlgebra/Vandermonde.lean | 49 | 56 |
/-
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 ↦ ?_
| Mathlib/MeasureTheory/Measure/Stieltjes.lean | 455 | 462 |
/-
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")]
| Mathlib/Topology/Order/DenselyOrdered.lean | 206 | 208 |
/-
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) :
| Mathlib/Algebra/Group/Indicator.lean | 223 | 227 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.